Index: /gsdl/trunk/build-src/Makefile.in
===================================================================
--- /gsdl/trunk/build-src/Makefile.in	(revision 16571)
+++ /gsdl/trunk/build-src/Makefile.in	(revision 16571)
@@ -0,0 +1,103 @@
+###########################################################################
+#
+# Makefile -- gsdl buildtime code
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+srcdir = @srcdir@
+
+PACKAGE = @PACKAGE@
+VERSION = @VERSION@
+
+@SET_MAKE@
+CC = @CC@
+CXX = @CXX@
+CFLAGS = @CFLAGS@
+CXXFLAGS = @CXXFLAGS@
+LIBS   = @LIBS@
+MDEFINES =
+
+GSDLOS = @gsdlos@
+
+COMPILE = $(CC) -c
+
+SOURCES = 
+
+OBJECTS = 
+
+ALLFILES = $(OBJECTS)
+
+# all directories should be compiled
+COMPILEDIRS = packages src/hashfile src/phind/generate 
+# a subset of the directories get installed
+INSTALLDIRS = packages src/hashfile src/phind/generate
+
+MODULEDIRS = @MODULEDIRS@
+
+
+all:
+	for odir in $(COMPILEDIRS) $(MODULEDIRS); do \
+	  echo making $@ in $$odir; \
+	  (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
+	done
+
+install: all
+	for idir in $(INSTALLDIRS); do \
+	  echo installing $$idir; \
+	  (cd $$idir && $(MAKE) install) || exit 1; \
+	done
+
+distclean: clean
+	rm -f Makefile config.cache config.h config.log stamp-h config.status
+	for subdir in $(COMPILEDIRS); do \
+	  echo cleaning $@ in $$subdir; \
+	  (cd $$subdir && $(MAKE) distclean) || exit 1; \
+	done
+
+clean:
+	for subdir in $(COMPILEDIRS); do \
+	  echo cleaning $@ in $$subdir; \
+	  (cd $$subdir && $(MAKE) clean) || exit 1; \
+	done
+
+# commented out - jrm21 Dec 2004 - can get confused by cvs timestamps
+# (and might run the wrong version of autoconf)
+#
+## For an explanation of the following Makefile rules, see node
+## `Automatic Remaking' in GNU Autoconf documentation.
+#Makefile: Makefile.in config.status
+#	CONFIG_FILES=$@ CONFIG_HEADERS= ./config.status
+#config.status: configure
+#	./config.status --recheck
+#configure: configure.in aclocal.m4
+#	cd $(srcdir) && autoconf
+#
+#config.h: stamp-h
+#stamp-h: config.h.in config.status
+#	CONFIG_FILES= CONFIG_HEADERS=config.h ./config.status
+#config.h.in: stamp-h.in
+#stamp-h.in: configure.in aclocal.m4 acconfig.h
+#	cd $(srcdir) && autoheader
+#	$(TOUCH) $(srcdir)/stamp-h.in
+
+
+
Index: /gsdl/trunk/build-src/aclocal.m4
===================================================================
--- /gsdl/trunk/build-src/aclocal.m4	(revision 16571)
+++ /gsdl/trunk/build-src/aclocal.m4	(revision 16571)
@@ -0,0 +1,140 @@
+# Local additions to Autoconf macros.
+# Copyright (C) 1992, 1994, 1995 Free Software Foundation, Inc.
+# François Pinard <pinard@iro.umontreal.ca>, 1992.
+
+# [TS:Aug/95] - chopped out the NLS stuff which I don't support
+
+## ------------------------------- ##
+## Check for function prototypes.  ##
+## ------------------------------- ##
+
+AC_DEFUN(fp_C_PROTOTYPES,
+[AC_REQUIRE([fp_PROG_CC_STDC])
+AC_MSG_CHECKING([for function prototypes])
+if test "$ac_cv_prog_cc_stdc" != no; then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(PROTOTYPES)
+  U= ANSI2KNR=
+else
+  AC_MSG_RESULT(no)
+  U=_ ANSI2KNR=ansi2knr
+fi
+AC_SUBST(U)dnl
+AC_SUBST(ANSI2KNR)dnl
+])
+
+## ----------------------------------------- ##
+## ANSIfy the C compiler whenever possible.  ##
+## ----------------------------------------- ##
+
+# @defmac AC_PROG_CC_STDC
+# @maindex PROG_CC_STDC
+# @ovindex CC
+# If the C compiler in not in ANSI C mode by default, try to add an option
+# to output variable @code{CC} to make it so.  This macro tries various
+# options that select ANSI C on some system or another.  It considers the
+# compiler to be in ANSI C mode if it defines @code{__STDC__} to 1 and
+# handles function prototypes correctly.
+#
+# If you use this macro, you should check after calling it whether the C
+# compiler has been set to accept ANSI C; if not, the shell variable
+# @code{ac_cv_prog_cc_stdc} is set to @samp{no}.  If you wrote your source
+# code in ANSI C, you can make an un-ANSIfied copy of it by using the
+# program @code{ansi2knr}, which comes with Ghostscript.
+# @end defmac
+
+AC_DEFUN(fp_PROG_CC_STDC,
+[AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C)
+AC_CACHE_VAL(ac_cv_prog_cc_stdc,
+[ac_cv_prog_cc_stdc=no
+ac_save_CFLAGS="$CFLAGS"
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX			-qlanglvl=ansi
+# Ultrix and OSF/1	-std1
+# HP-UX			-Aa -D_HPUX_SOURCE
+# SVR4			-Xc
+for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" -Xc
+do
+  CFLAGS="$ac_save_CFLAGS $ac_arg"
+  AC_TRY_COMPILE(
+[#if !defined(__STDC__) || __STDC__ != 1
+choke me
+#endif	
+], [int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};],
+[ac_cv_prog_cc_stdc="$ac_arg"; break])
+done
+CFLAGS="$ac_save_CFLAGS"
+])
+AC_MSG_RESULT($ac_cv_prog_cc_stdc)
+case "x$ac_cv_prog_cc_stdc" in
+  x|xno) ;;
+  *) CC="$CC $ac_cv_prog_cc_stdc" ;;
+esac
+])
+
+## --------------------------------------------------------- ##
+## Use AC_PROG_INSTALL, supplementing it with INSTALL_SCRIPT ##
+## substitution.					     ##
+## --------------------------------------------------------- ##
+
+AC_DEFUN(fp_PROG_INSTALL,
+[AC_PROG_INSTALL
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL} -m 755'
+AC_SUBST(INSTALL_SCRIPT)dnl
+])
+
+## ----------------------------------- ##
+## Check if --with-dmalloc was given.  ##
+## ----------------------------------- ##
+
+# I just checked, and GNU rx seems to work fine with a slightly
+# modified GNU m4.  So, I put out the test below in my aclocal.m4,
+# and will try to use it in my things.  The idea is to distribute
+# rx.[hc] and regex.[hc] together, for a while.  The WITH_REGEX symbol
+# (which should also be documented in acconfig.h) is used to decide
+# which of regex.h or rx.h should be included in the application.
+#
+# If `./configure --with-regex' is given, the package will use
+# the older regex.  Else, a check is made to see if rx is already
+# installed, as with newer Linux'es.  If not found, the package will
+# use the rx from the distribution.  If found, the package will use
+# the system's rx which, on Linux at least, will result in a smaller
+# executable file.
+
+AC_DEFUN(fp_WITH_DMALLOC,
+[AC_MSG_CHECKING(if malloc debugging is wanted)
+AC_ARG_WITH(dmalloc,
+[  --with-dmalloc          use dmalloc, as in
+                          ftp://ftp.letters.com/src/dmalloc/dmalloc.tar.gz],
+[if test "$withval" = yes; then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(WITH_DMALLOC)
+  LIBS="$LIBS -ldmalloc"
+  LDFLAGS="$LDFLAGS -g"
+else
+  AC_MSG_RESULT(no)
+fi], [AC_MSG_RESULT(no)])
+])
+
+## --------------------------------- ##
+## Check if --with-regex was given.  ##
+## --------------------------------- ##
+
+AC_DEFUN(fp_WITH_REGEX,
+[AC_MSG_CHECKING(which of rx or regex is wanted)
+AC_ARG_WITH(regex,
+[  --with-regex            use older regex in lieu of GNU rx for matching],
+[if test "$withval" = yes; then
+  ac_with_regex=1
+  AC_MSG_RESULT(regex)
+  AC_DEFINE(WITH_REGEX)
+  AC_LIBOBJ([regex])
+fi])
+if test -z "$ac_with_regex"; then
+  AC_MSG_RESULT(rx)
+  AC_CHECK_FUNC(re_rx_search, , [AC_LIBOBJ([rx])])
+fi
+])
Index: /gsdl/trunk/build-src/config.h.in
===================================================================
--- /gsdl/trunk/build-src/config.h.in	(revision 16571)
+++ /gsdl/trunk/build-src/config.h.in	(revision 16571)
@@ -0,0 +1,217 @@
+/* config.h.in.  Generated automatically from configure.in by autoheader.  */
+
+#ifndef _GSDL_CONFIG_H
+#define _GSDL_CONFIG_H
+
+/* Define if on AIX 3.
+   System headers sometimes define this.
+   We just want to avoid a redefinition error message.  */
+#ifndef _ALL_SOURCE
+#undef _ALL_SOURCE
+#endif
+
+/* Define if using alloca.c.  */
+#undef C_ALLOCA
+
+/* Define if big endian */
+#undef WORDS_BIGENDIAN
+
+/* Define to empty if the keyword does not work.  */
+#undef const
+
+/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems.
+   This function is required for alloca.c support on those systems.  */
+#undef CRAY_STACKSEG_END
+
+/* Define if you have alloca, as a function or macro.  */
+#undef HAVE_ALLOCA
+
+/* Define if you have <alloca.h> and it should be used (not on Ultrix).  */
+#undef HAVE_ALLOCA_H
+
+/* Define if you don't have vprintf but do have _doprnt.  */
+#undef HAVE_DOPRNT
+
+/* Define if you have the vprintf function.  */
+#undef HAVE_VPRINTF
+
+/* Define if on MINIX.  */
+#undef _MINIX
+
+/* Define to `long' if <sys/types.h> doesn't define.  */
+#undef off_t
+
+/* Define if the system does not provide POSIX.1 features except
+   with this defined.  */
+#undef _POSIX_1_SOURCE
+
+/* Define if you need to in order for stat and other things to work.  */
+#undef _POSIX_SOURCE
+
+/* Define as the return type of signal handlers (int or void).  */
+#undef RETSIGTYPE
+
+/* Define to `unsigned' if <sys/types.h> doesn't define.  */
+#undef size_t
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at run-time.
+ STACK_DIRECTION > 0 => grows toward higher addresses
+ STACK_DIRECTION < 0 => grows toward lower addresses
+ STACK_DIRECTION = 0 => direction of growth unknown
+ */
+#undef STACK_DIRECTION
+
+/* Define if you have the ANSI C header files.  */
+#undef STDC_HEADERS
+
+/* Define if you can safely include both <sys/time.h> and <time.h>.  */
+#undef TIME_WITH_SYS_TIME
+
+/* Define if your <sys/time.h> declares struct tm.  */
+#undef TM_IN_SYS_TIME
+
+/* Define to the name of the distribution.  */
+#undef PACKAGE
+
+/* Define to the version of the distribution.  */
+#undef VERSION
+
+/* Define to 1 if you have the valloc function.  */
+#undef HAVE_VALLOC
+
+/* Define to 1 if ANSI function prototypes are usable.  */
+#undef PROTOTYPES
+
+/* Define if you don't want to use long long's with GCC */
+#undef DISABLE_LONG_LONG
+ 
+/* Define to 1 for better use of the debugging malloc library.  See
+   site ftp.antaire.com in antaire/src, file dmalloc/dmalloc.tar.gz.  */
+#undef WITH_DMALLOC
+
+ 
+/* Define to 1 if GNU regex should be used instead of GNU rx.  */
+#undef WITH_REGEX
+
+/* Some braindead header files do not have the requ'd function declarations */
+#undef HAVE_FGETC_DECL
+#undef HAVE_FREAD_DECL
+
+/* See if have this field in the prstatus_t structure */
+/* It stores the size of the process heap */
+#undef HAVE_PR_BRKSIZE
+
+/* Define FASTCGI if needsbe */
+#undef USE_FASTCGI
+
+/* Define USE_CORBA if needsbe */
+#undef USE_CORBA
+
+/* Define MICO_DIR if needsbe */
+#undef MICO_DIR
+
+/* Define MICO_VERSION if required */
+#undef MICO_VERSION
+
+/* Define if you have the ftime function.  */
+#undef HAVE_FTIME
+
+/* Define if you have the ftruncate function.  */
+#undef HAVE_FTRUNCATE
+
+/* Define if you have the getpagesize function.  */
+#undef HAVE_GETPAGESIZE
+
+/* Define if you have the getrusage function.  */
+#undef HAVE_GETRUSAGE
+
+/* Define if you have the mallinfo function.  */
+#undef HAVE_MALLINFO
+
+/* Define if you have the select function.  */
+#undef HAVE_SELECT
+
+/* Define if you have the setbuffer function.  */
+#undef HAVE_SETBUFFER
+
+/* Define if you have the strcasecmp function.  */
+#undef HAVE_STRCASECMP
+
+/* Define if you have the strerror function.  */
+#undef HAVE_STRERROR
+
+/* Define if you have the strftime function.  */
+#undef HAVE_STRFTIME
+
+/* Define if you have the strstr function.  */
+#undef HAVE_STRSTR
+
+/* Define if you have the strtol function.  */
+#undef HAVE_STRTOL
+
+/* Define if you have the times function.  */
+#undef HAVE_TIMES
+
+/* Define if you have the valloc function.  */
+#undef HAVE_VALLOC
+
+/* Define if you have the <crypt.h> header file.  */
+#undef HAVE_CRYPT_H
+
+/* Define if you have the <dirent.h> header file.  */
+#undef HAVE_DIRENT_H
+
+/* Define if you have the <fcntl.h> header file.  */
+#undef HAVE_FCNTL_H
+
+/* Define if you have the <limits.h> header file.  */
+#undef HAVE_LIMITS_H
+
+/* Define if you have the <memory.h> header file.  */
+#undef HAVE_MEMORY_H
+
+/* Define if you have the <ndir.h> header file.  */
+#undef HAVE_NDIR_H
+
+/* Define if you have the <string.h> header file.  */
+#undef HAVE_STRING_H
+
+/* Define if you have the <sys/dir.h> header file.  */
+#undef HAVE_SYS_DIR_H
+
+/* Define if you have the <sys/ndir.h> header file.  */
+#undef HAVE_SYS_NDIR_H
+
+/* Define if you have the <sys/procfs.h> header file.  */
+#undef HAVE_SYS_PROCFS_H
+
+/* Define if you have the <sys/time.h> header file.  */
+#undef HAVE_SYS_TIME_H
+
+/* Define if you have the <unistd.h> header file.  */
+#undef HAVE_UNISTD_H
+
+/* Define if you have the crypt library (-lcrypt).  */
+#undef HAVE_LIBCRYPT
+
+/* Define if you have the g library (-lg).  */
+#undef HAVE_LIBG
+
+/* Define if you have the gdbm library (-lgdbm).  */
+#undef HAVE_LIBGDBM
+
+/* Define if you have the m library (-lm).  */
+#undef HAVE_LIBM
+
+/* Define if you have the stdc++ library (-lstdc++).  */
+#undef HAVE_LIBSTDC__
+
+/* Define if you have gettext (eg glibc) */
+#undef ENABLE_NLS
+
+/* Define if big endian */
+#undef WORDS_BIGENDIAN
+
+#endif /* _GSDL_CONFIG_H */
Index: /gsdl/trunk/build-src/configtest.pl
===================================================================
--- /gsdl/trunk/build-src/configtest.pl	(revision 16571)
+++ /gsdl/trunk/build-src/configtest.pl	(revision 16571)
@@ -0,0 +1,1 @@
+print $]
Index: /gsdl/trunk/build-src/configure
===================================================================
--- /gsdl/trunk/build-src/configure	(revision 16571)
+++ /gsdl/trunk/build-src/configure	(revision 16571)
@@ -0,0 +1,8793 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.59.
+#
+# Copyright (C) 2003 Free Software Foundation, Inc.
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+  set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+  LC_TELEPHONE LC_TIME
+do
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+    eval $as_var=C; export $as_var
+  else
+    $as_unset $as_var
+  fi
+done
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)$' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\/\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+
+
+# PATH needs CR, and LINENO needs CR and PATH.
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
+  # Find who we are.  Look in the path if we contain no path at all
+  # relative or not.
+  case $0 in
+    *[\\/]* ) as_myself=$0 ;;
+    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+
+       ;;
+  esac
+  # We did not find ourselves, most probably we were run as `sh COMMAND'
+  # in which case we are not to be found in the path.
+  if test "x$as_myself" = x; then
+    as_myself=$0
+  fi
+  if test ! -f "$as_myself"; then
+    { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2
+   { (exit 1); exit 1; }; }
+  fi
+  case $CONFIG_SHELL in
+  '')
+    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for as_base in sh bash ksh sh5; do
+	 case $as_dir in
+	 /*)
+	   if ("$as_dir/$as_base" -c '
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
+	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
+	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
+	     CONFIG_SHELL=$as_dir/$as_base
+	     export CONFIG_SHELL
+	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
+	   fi;;
+	 esac
+       done
+done
+;;
+  esac
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line before each line; the second 'sed' does the real
+  # work.  The second script uses 'N' to pair each line-number line
+  # with the numbered line, and appends trailing '-' during
+  # substitution so that $LINENO is not a special case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
+  sed '=' <$as_myself |
+    sed '
+      N
+      s,$,-,
+      : loop
+      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+      t loop
+      s,-$,,
+      s,^['$as_cr_digits']*\n,,
+    ' >$as_me.lineno &&
+  chmod +x $as_me.lineno ||
+    { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensible to this).
+  . ./$as_me.lineno
+  # Exit status is that of the last command.
+  exit
+}
+
+
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+  *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T='	' ;;
+  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+echo >conf$$.file
+if ln -s conf$$.file conf$$ 2>/dev/null; then
+  # We could just check for DJGPP; but this test a) works b) is more generic
+  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
+  if test -f conf$$.exe; then
+    # Don't use ln at all; we don't have any links
+    as_ln_s='cp -p'
+  else
+    as_ln_s='ln -s'
+  fi
+elif ln conf$$.file conf$$ 2>/dev/null; then
+  as_ln_s=ln
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.file
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p=:
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_executable_p="test -f"
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.
+as_nl='
+'
+IFS=" 	$as_nl"
+
+# CDPATH.
+$as_unset CDPATH
+
+
+# Name of the host.
+# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+exec 6>&1
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_config_libobj_dir=.
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+# Maximum number of lines to put in a shell here document.
+# This variable seems obsolete.  It should probably be removed, and
+# only ac_max_sed_lines should be used.
+: ${ac_max_here_lines=38}
+
+# Identity of this package.
+PACKAGE_NAME=
+PACKAGE_TARNAME=
+PACKAGE_VERSION=
+PACKAGE_STRING=
+PACKAGE_BUGREPORT=
+
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#if STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# if HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#if HAVE_STRING_H
+# if !STDC_HEADERS && HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#if HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#else
+# if HAVE_STDINT_H
+#  include <stdint.h>
+# endif
+#endif
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subdirs_all="$ac_subdirs_all packages"
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS PACKAGE VERSION USE_FASTCGI USE_LANGACTION USE_CORBA MICO_DIR USE_Z3950 USE_YAZ ENABLE_ACCENTFOLD USE_SQLITE LDFLAGS CFLAGS CC CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX AWK YACC build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S SET_MAKE RANLIB ac_ct_RANLIB COMPAT32BITFLAGS MICO_VER CPP EGREP U ANSI2KNR ALLOCA LIBOBJS STATIC GDBM_LIBPATH GDBM_INCLUDE gsdlos MODULEDIRS subdirs LTLIBOBJS'
+ac_subst_files=''
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datadir='${prefix}/share'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+libdir='${exec_prefix}/lib'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+infodir='${prefix}/info'
+mandir='${prefix}/man'
+
+ac_prev=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval "$ac_prev=\$ac_option"
+    ac_prev=
+    continue
+  fi
+
+  ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_option in
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+  | --da=*)
+    datadir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid feature name: $ac_feature" >&2
+   { (exit 1); exit 1; }; }
+    ac_feature=`echo $ac_feature | sed 's/-/_/g'`
+    eval "enable_$ac_feature=no" ;;
+
+  -enable-* | --enable-*)
+    ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid feature name: $ac_feature" >&2
+   { (exit 1); exit 1; }; }
+    ac_feature=`echo $ac_feature | sed 's/-/_/g'`
+    case $ac_option in
+      *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
+      *) ac_optarg=yes ;;
+    esac
+    eval "enable_$ac_feature='$ac_optarg'" ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst \
+  | --locals | --local | --loca | --loc | --lo)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+  | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid package name: $ac_package" >&2
+   { (exit 1); exit 1; }; }
+    ac_package=`echo $ac_package| sed 's/-/_/g'`
+    case $ac_option in
+      *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
+      *) ac_optarg=yes ;;
+    esac
+    eval "with_$ac_package='$ac_optarg'" ;;
+
+  -without-* | --without-*)
+    ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid package name: $ac_package" >&2
+   { (exit 1); exit 1; }; }
+    ac_package=`echo $ac_package | sed 's/-/_/g'`
+    eval "with_$ac_package=no" ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) { echo "$as_me: error: unrecognized option: $ac_option
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; }
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid variable name: $ac_envvar" >&2
+   { (exit 1); exit 1; }; }
+    ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
+    eval "$ac_envvar='$ac_optarg'"
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  { echo "$as_me: error: missing argument to $ac_option" >&2
+   { (exit 1); exit 1; }; }
+fi
+
+# Be sure to have absolute paths.
+for ac_var in exec_prefix prefix
+do
+  eval ac_val=$`echo $ac_var`
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* | NONE | '' ) ;;
+    *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# Be sure to have absolute paths.
+for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \
+	      localstatedir libdir includedir oldincludedir infodir mandir
+do
+  eval ac_val=$`echo $ac_var`
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* ) ;;
+    *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+    echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
+    If a cross compiler is detected then cross compile mode will be used." >&2
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then its parent.
+  ac_confdir=`(dirname "$0") 2>/dev/null ||
+$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$0" : 'X\(//\)[^/]' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$0" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r $srcdir/$ac_unique_file; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r $srcdir/$ac_unique_file; then
+  if test "$ac_srcdir_defaulted" = yes; then
+    { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2
+   { (exit 1); exit 1; }; }
+  else
+    { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
+   { (exit 1); exit 1; }; }
+  fi
+fi
+(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null ||
+  { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2
+   { (exit 1); exit 1; }; }
+srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'`
+ac_env_build_alias_set=${build_alias+set}
+ac_env_build_alias_value=$build_alias
+ac_cv_env_build_alias_set=${build_alias+set}
+ac_cv_env_build_alias_value=$build_alias
+ac_env_host_alias_set=${host_alias+set}
+ac_env_host_alias_value=$host_alias
+ac_cv_env_host_alias_set=${host_alias+set}
+ac_cv_env_host_alias_value=$host_alias
+ac_env_target_alias_set=${target_alias+set}
+ac_env_target_alias_value=$target_alias
+ac_cv_env_target_alias_set=${target_alias+set}
+ac_cv_env_target_alias_value=$target_alias
+ac_env_CC_set=${CC+set}
+ac_env_CC_value=$CC
+ac_cv_env_CC_set=${CC+set}
+ac_cv_env_CC_value=$CC
+ac_env_CFLAGS_set=${CFLAGS+set}
+ac_env_CFLAGS_value=$CFLAGS
+ac_cv_env_CFLAGS_set=${CFLAGS+set}
+ac_cv_env_CFLAGS_value=$CFLAGS
+ac_env_LDFLAGS_set=${LDFLAGS+set}
+ac_env_LDFLAGS_value=$LDFLAGS
+ac_cv_env_LDFLAGS_set=${LDFLAGS+set}
+ac_cv_env_LDFLAGS_value=$LDFLAGS
+ac_env_CPPFLAGS_set=${CPPFLAGS+set}
+ac_env_CPPFLAGS_value=$CPPFLAGS
+ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set}
+ac_cv_env_CPPFLAGS_value=$CPPFLAGS
+ac_env_CXX_set=${CXX+set}
+ac_env_CXX_value=$CXX
+ac_cv_env_CXX_set=${CXX+set}
+ac_cv_env_CXX_value=$CXX
+ac_env_CXXFLAGS_set=${CXXFLAGS+set}
+ac_env_CXXFLAGS_value=$CXXFLAGS
+ac_cv_env_CXXFLAGS_set=${CXXFLAGS+set}
+ac_cv_env_CXXFLAGS_value=$CXXFLAGS
+ac_env_CPP_set=${CPP+set}
+ac_env_CPP_value=$CPP
+ac_cv_env_CPP_set=${CPP+set}
+ac_cv_env_CPP_value=$CPP
+
+#
+# Report the --help message.
+#
+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 this package to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+_ACEOF
+
+  cat <<_ACEOF
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+			  [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+			  [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR           user executables [EPREFIX/bin]
+  --sbindir=DIR          system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR       program executables [EPREFIX/libexec]
+  --datadir=DIR          read-only architecture-independent data [PREFIX/share]
+  --sysconfdir=DIR       read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR   modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR    modifiable single-machine data [PREFIX/var]
+  --libdir=DIR           object code libraries [EPREFIX/lib]
+  --includedir=DIR       C header files [PREFIX/include]
+  --oldincludedir=DIR    C header files for non-gcc [/usr/include]
+  --infodir=DIR          info documentation [PREFIX/info]
+  --mandir=DIR           man documentation [PREFIX/man]
+_ACEOF
+
+  cat <<\_ACEOF
+
+System types:
+  --build=BUILD     configure for building on BUILD [guessed]
+  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
+  --target=TARGET   configure for building compilers for TARGET [HOST]
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+
+  cat <<\_ACEOF
+
+Optional Features:
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-corba          Enable CORBA support
+  --enable-z3950          Enable Z39.50 client support
+  --disable-yaz           Disable YAZ compilation
+  --disable-accentfold    Disable Accent Folding for MGPP
+  --disable-sqlite        Disable SQLite support
+
+Optional Packages:
+  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --with-micodir          Use installed MICO directory
+  --with-gdbm=dir         Use local gdbm library and headers
+  --with-dmalloc          use dmalloc, as in
+                          ftp://ftp.letters.com/src/dmalloc/dmalloc.tar.gz
+  --with-regex            use older regex in lieu of GNU rx for matching
+
+Some influential environment variables:
+  CC          C compiler command
+  CFLAGS      C compiler flags
+  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+              nonstandard directory <lib dir>
+  CPPFLAGS    C/C++ preprocessor flags, e.g. -I<include dir> if you have
+              headers in a nonstandard directory <include dir>
+  CXX         C++ compiler command
+  CXXFLAGS    C++ compiler flags
+  CPP         C preprocessor
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+_ACEOF
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  ac_popdir=`pwd`
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d $ac_dir || continue
+    ac_builddir=.
+
+if test "$ac_dir" != .; then
+  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  # A "../" for each directory in $ac_dir_suffix.
+  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+  ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+  .)  # No --srcdir option.  We are building in place.
+    ac_srcdir=.
+    if test -z "$ac_top_builddir"; then
+       ac_top_srcdir=.
+    else
+       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+    fi ;;
+  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir ;;
+  *) # Relative path.
+    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
+
+    cd $ac_dir
+    # Check for guested configure; otherwise get Cygnus style configure.
+    if test -f $ac_srcdir/configure.gnu; then
+      echo
+      $SHELL $ac_srcdir/configure.gnu  --help=recursive
+    elif test -f $ac_srcdir/configure; then
+      echo
+      $SHELL $ac_srcdir/configure  --help=recursive
+    elif test -f $ac_srcdir/configure.ac ||
+	   test -f $ac_srcdir/configure.in; then
+      echo
+      $ac_configure --help
+    else
+      echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi
+    cd $ac_popdir
+  done
+fi
+
+test -n "$ac_init_help" && exit 0
+if $ac_init_version; then
+  cat <<\_ACEOF
+
+Copyright (C) 2003 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit 0
+fi
+exec 5>config.log
+cat >&5 <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by $as_me, which was
+generated by GNU Autoconf 2.59.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+hostinfo               = `(hostinfo) 2>/dev/null               || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  echo "PATH: $as_dir"
+done
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_sep=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+      ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;;
+    2)
+      ac_configure_args1="$ac_configure_args1 '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+	ac_must_keep_next=false # Got value, back to normal.
+      else
+	case $ac_arg in
+	  *=* | --config-cache | -C | -disable-* | --disable-* \
+	  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+	  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+	  | -with-* | --with-* | -without-* | --without-* | --x)
+	    case "$ac_configure_args0 " in
+	      "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+	    esac
+	    ;;
+	  -* ) ac_must_keep_next=true ;;
+	esac
+      fi
+      ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'"
+      # Get rid of the leading space.
+      ac_sep=" "
+      ;;
+    esac
+  done
+done
+$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; }
+$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; }
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Be sure not to use single quotes in there, as some shells,
+# such as our DU 5.0 friend, will then `close' the trap.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    cat <<\_ASBOX
+## ---------------- ##
+## Cache variables. ##
+## ---------------- ##
+_ASBOX
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+{
+  (set) 2>&1 |
+    case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in
+    *ac_space=\ *)
+      sed -n \
+	"s/'"'"'/'"'"'\\\\'"'"''"'"'/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p"
+      ;;
+    *)
+      sed -n \
+	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+      ;;
+    esac;
+}
+    echo
+
+    cat <<\_ASBOX
+## ----------------- ##
+## Output variables. ##
+## ----------------- ##
+_ASBOX
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=$`echo $ac_var`
+      echo "$ac_var='"'"'$ac_val'"'"'"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      cat <<\_ASBOX
+## ------------- ##
+## Output files. ##
+## ------------- ##
+_ASBOX
+      echo
+      for ac_var in $ac_subst_files
+      do
+	eval ac_val=$`echo $ac_var`
+	echo "$ac_var='"'"'$ac_val'"'"'"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      cat <<\_ASBOX
+## ----------- ##
+## confdefs.h. ##
+## ----------- ##
+_ASBOX
+      echo
+      sed "/^$/d" confdefs.h | sort
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      echo "$as_me: caught signal $ac_signal"
+    echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core &&
+  rm -rf conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+     ' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -rf conftest* confdefs.h
+# AIX cpp loses on an empty file, so make sure it contains at least a newline.
+echo >confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer explicitly selected file to automatically selected ones.
+if test -z "$CONFIG_SITE"; then
+  if test "x$prefix" != xNONE; then
+    CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
+  else
+    CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
+  fi
+fi
+for ac_site_file in $CONFIG_SITE; do
+  if test -r "$ac_site_file"; then
+    { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5
+echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file"
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special
+  # files actually), so we avoid doing that.
+  if test -f "$cache_file"; then
+    { echo "$as_me:$LINENO: loading cache $cache_file" >&5
+echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . $cache_file;;
+      *)                      . ./$cache_file;;
+    esac
+  fi
+else
+  { echo "$as_me:$LINENO: creating cache $cache_file" >&5
+echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in `(set) 2>&1 |
+	       sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val="\$ac_cv_env_${ac_var}_value"
+  eval ac_new_val="\$ac_env_${ac_var}_value"
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5
+echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+	{ echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5
+echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+	{ echo "$as_me:$LINENO:   former value:  $ac_old_val" >&5
+echo "$as_me:   former value:  $ac_old_val" >&2;}
+	{ echo "$as_me:$LINENO:   current value: $ac_new_val" >&5
+echo "$as_me:   current value: $ac_new_val" >&2;}
+	ac_cache_corrupted=:
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+      ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5
+echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5
+echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+          ac_config_headers="$ac_config_headers config.h"
+
+
+
+PACKAGE=gsdl
+VERSION=2.82-svn
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE "$PACKAGE"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define VERSION "$VERSION"
+_ACEOF
+
+
+
+
+USE_FASTCGI=0
+if test USE_FASTCGI = 1; then
+cat >>confdefs.h <<\_ACEOF
+#define USE_FASTCGI 1
+_ACEOF
+
+
+fi
+
+if test USE_LANGACTION = 1; then
+cat >>confdefs.h <<\_ACEOF
+#define USE_LANGACTION 1
+_ACEOF
+
+
+fi
+
+# Check whether --enable-corba or --disable-corba was given.
+if test "${enable_corba+set}" = set; then
+  enableval="$enable_corba"
+  USE_CORBA=1
+else
+  USE_CORBA=0
+fi;
+cat >>confdefs.h <<_ACEOF
+#define USE_CORBA $USE_CORBA
+_ACEOF
+
+
+
+
+# Check whether --with-micodir or --without-micodir was given.
+if test "${with_micodir+set}" = set; then
+  withval="$with_micodir"
+  MICO_DIR=$enableval
+else
+  MICO_DIR="default"
+fi;
+cat >>confdefs.h <<_ACEOF
+#define MICO_DIR "$MICO_DIR"
+_ACEOF
+
+
+
+# Check whether --enable-z3950 or --disable-z3950 was given.
+if test "${enable_z3950+set}" = set; then
+  enableval="$enable_z3950"
+  USE_Z3950=1
+else
+  USE_Z3950=0
+fi;
+if test USE_Z3950 = 1; then
+cat >>confdefs.h <<\_ACEOF
+#define USE_Z3950 $USE_Z3950
+_ACEOF
+
+
+fi
+
+# Check whether --enable-yaz or --disable-yaz was given.
+if test "${enable_yaz+set}" = set; then
+  enableval="$enable_yaz"
+  USE_YAZ=0
+else
+  USE_YAZ=1
+fi;
+cat >>confdefs.h <<\_ACEOF
+#define USE_YAZ $USE_YAZ
+_ACEOF
+
+
+
+
+# Check whether --with-gdbm or --without-gdbm was given.
+if test "${with_gdbm+set}" = set; then
+  withval="$with_gdbm"
+  gdbmdir=$withval
+fi;
+
+# Check whether --enable-accentfold or --disable-accentfold was given.
+if test "${enable_accentfold+set}" = set; then
+  enableval="$enable_accentfold"
+  ENABLE_ACCENTFOLD=0
+else
+  ENABLE_ACCENTFOLD=1
+fi;
+cat >>confdefs.h <<\_ACEOF
+#define ENABLE_ACCENTFOLD $ENABLE_ACCENTFOLD
+_ACEOF
+
+
+
+# Check whether --enable-sqlite or --disable-sqlite was given.
+if test "${enable_sqlite+set}" = set; then
+  enableval="$enable_sqlite"
+  USE_SQLITE=0
+else
+  USE_SQLITE=1
+fi;
+cat >>confdefs.h <<\_ACEOF
+#define USE_SQLITE $USE_SQLITE
+_ACEOF
+
+
+
+LDFLAGS=$LDFLAGS
+
+if test -z "$CFLAGS"; then
+CFLAGS=-O2
+fi
+
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  CC=$ac_ct_CC
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="cc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  CC=$ac_ct_CC
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+fi
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  ac_prog_rejected=no
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+       ac_prog_rejected=yes
+       continue
+     fi
+    ac_cv_prog_CC="cc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# != 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+  fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in cl
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+    test -n "$CC" && break
+  done
+fi
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in cl
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$ac_ct_CC" && break
+done
+
+  CC=$ac_ct_CC
+fi
+
+fi
+
+
+test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&5
+echo "$as_me: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+
+# Provide some information about the compiler.
+echo "$as_me:$LINENO:" \
+     "checking for C compiler version" >&5
+ac_compiler=`set X $ac_compile; echo $2`
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
+  (eval $ac_compiler --version </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v </dev/null >&5\"") >&5
+  (eval $ac_compiler -v </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V </dev/null >&5\"") >&5
+  (eval $ac_compiler -V </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+echo "$as_me:$LINENO: checking for C compiler default output file name" >&5
+echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6
+ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5
+  (eval $ac_link_default) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # Find the output, starting from the most likely.  This scheme is
+# not robust to junk in `.', hence go to wildcards (a.*) only as a last
+# resort.
+
+# Be careful to initialize this variable, since it used to be cached.
+# Otherwise an old cache value of `no' led to `EXEEXT = no' in a Makefile.
+ac_cv_exeext=
+# b.out is created by i960 compilers.
+for ac_file in a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out
+do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj )
+	;;
+    conftest.$ac_ext )
+	# This is the source file.
+	;;
+    [ab].out )
+	# We found the default executable, but exeext='' is most
+	# certainly right.
+	break;;
+    *.* )
+	ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	# FIXME: I believe we export ac_cv_exeext for Libtool,
+	# but it would be cool to find out if it's true.  Does anybody
+	# maintain Libtool? --akim.
+	export ac_cv_exeext
+	break;;
+    * )
+	break;;
+  esac
+done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { echo "$as_me:$LINENO: error: C compiler cannot create executables
+See \`config.log' for more details." >&5
+echo "$as_me: error: C compiler cannot create executables
+See \`config.log' for more details." >&2;}
+   { (exit 77); exit 77; }; }
+fi
+
+ac_exeext=$ac_cv_exeext
+echo "$as_me:$LINENO: result: $ac_file" >&5
+echo "${ECHO_T}$ac_file" >&6
+
+# Check the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+echo "$as_me:$LINENO: checking whether the C compiler works" >&5
+echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6
+# FIXME: These cross compiler hacks should be removed for Autoconf 3.0
+# If not cross compiling, check that we can run a simple program.
+if test "$cross_compiling" != yes; then
+  if { ac_try='./$ac_file'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { echo "$as_me:$LINENO: error: cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+    fi
+  fi
+fi
+echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+
+rm -f a.out a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+# Check the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
+echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6
+echo "$as_me:$LINENO: result: $cross_compiling" >&5
+echo "${ECHO_T}$cross_compiling" >&6
+
+echo "$as_me:$LINENO: checking for suffix of executables" >&5
+echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;;
+    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	  export ac_cv_exeext
+	  break;;
+    * ) break;;
+  esac
+done
+else
+  { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+rm -f conftest$ac_cv_exeext
+echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5
+echo "${ECHO_T}$ac_cv_exeext" >&6
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+echo "$as_me:$LINENO: checking for suffix of object files" >&5
+echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6
+if test "${ac_cv_objext+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg ) ;;
+    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+       break;;
+  esac
+done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_objext" >&5
+echo "${ECHO_T}$ac_cv_objext" >&6
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5
+echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6
+if test "${ac_cv_c_compiler_gnu+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_compiler_gnu=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_compiler_gnu=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5
+echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6
+GCC=`test $ac_compiler_gnu = yes && echo yes`
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+CFLAGS="-g"
+echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5
+echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6
+if test "${ac_cv_prog_cc_g+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cc_g=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_prog_cc_g=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_g" >&6
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+echo "$as_me:$LINENO: checking for $CC option to accept ANSI C" >&5
+echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6
+if test "${ac_cv_prog_cc_stdc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_prog_cc_stdc=no
+ac_save_CC=$CC
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std1 is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std1.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+  ;
+  return 0;
+}
+_ACEOF
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX			-qlanglvl=ansi
+# Ultrix and OSF/1	-std1
+# HP-UX 10.20 and later	-Ae
+# HP-UX older versions	-Aa -D_HPUX_SOURCE
+# SVR4			-Xc -D__EXTENSIONS__
+for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cc_stdc=$ac_arg
+break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext
+done
+rm -f conftest.$ac_ext conftest.$ac_objext
+CC=$ac_save_CC
+
+fi
+
+case "x$ac_cv_prog_cc_stdc" in
+  x|xno)
+    echo "$as_me:$LINENO: result: none needed" >&5
+echo "${ECHO_T}none needed" >&6 ;;
+  *)
+    echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6
+    CC="$CC $ac_cv_prog_cc_stdc" ;;
+esac
+
+# Some people use a C++ compiler to compile C.  Since we use `exit',
+# in C++ we need to declare it.  In case someone uses the same compiler
+# for both compiling C and C++ we need to have the C++ compiler decide
+# the declaration of exit, since it's the most demanding environment.
+cat >conftest.$ac_ext <<_ACEOF
+#ifndef __cplusplus
+  choke me
+#endif
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  for ac_declaration in \
+   '' \
+   'extern "C" void std::exit (int) throw (); using std::exit;' \
+   'extern "C" void std::exit (int); using std::exit;' \
+   'extern "C" void exit (int) throw ();' \
+   'extern "C" void exit (int);' \
+   'void exit (int);'
+do
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+#include <stdlib.h>
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+continue
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+rm -f conftest*
+if test -n "$ac_declaration"; then
+  echo '#ifdef __cplusplus' >>confdefs.h
+  echo $ac_declaration      >>confdefs.h
+  echo '#endif'             >>confdefs.h
+fi
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ac_ext=cc
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  for ac_prog in $CCC g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CXX"; then
+  ac_cv_prog_CXX="$CXX" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CXX="$ac_tool_prefix$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CXX=$ac_cv_prog_CXX
+if test -n "$CXX"; then
+  echo "$as_me:$LINENO: result: $CXX" >&5
+echo "${ECHO_T}$CXX" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+    test -n "$CXX" && break
+  done
+fi
+if test -z "$CXX"; then
+  ac_ct_CXX=$CXX
+  for ac_prog in $CCC g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CXX"; then
+  ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CXX="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CXX=$ac_cv_prog_ac_ct_CXX
+if test -n "$ac_ct_CXX"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CXX" >&5
+echo "${ECHO_T}$ac_ct_CXX" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$ac_ct_CXX" && break
+done
+test -n "$ac_ct_CXX" || ac_ct_CXX="g++"
+
+  CXX=$ac_ct_CXX
+fi
+
+
+# Provide some information about the compiler.
+echo "$as_me:$LINENO:" \
+     "checking for C++ compiler version" >&5
+ac_compiler=`set X $ac_compile; echo $2`
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
+  (eval $ac_compiler --version </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v </dev/null >&5\"") >&5
+  (eval $ac_compiler -v </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V </dev/null >&5\"") >&5
+  (eval $ac_compiler -V </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+
+echo "$as_me:$LINENO: checking whether we are using the GNU C++ compiler" >&5
+echo $ECHO_N "checking whether we are using the GNU C++ compiler... $ECHO_C" >&6
+if test "${ac_cv_cxx_compiler_gnu+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_compiler_gnu=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_compiler_gnu=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_cxx_compiler_gnu=$ac_compiler_gnu
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_cxx_compiler_gnu" >&5
+echo "${ECHO_T}$ac_cv_cxx_compiler_gnu" >&6
+GXX=`test $ac_compiler_gnu = yes && echo yes`
+ac_test_CXXFLAGS=${CXXFLAGS+set}
+ac_save_CXXFLAGS=$CXXFLAGS
+CXXFLAGS="-g"
+echo "$as_me:$LINENO: checking whether $CXX accepts -g" >&5
+echo $ECHO_N "checking whether $CXX accepts -g... $ECHO_C" >&6
+if test "${ac_cv_prog_cxx_g+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cxx_g=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_prog_cxx_g=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_cxx_g" >&5
+echo "${ECHO_T}$ac_cv_prog_cxx_g" >&6
+if test "$ac_test_CXXFLAGS" = set; then
+  CXXFLAGS=$ac_save_CXXFLAGS
+elif test $ac_cv_prog_cxx_g = yes; then
+  if test "$GXX" = yes; then
+    CXXFLAGS="-g -O2"
+  else
+    CXXFLAGS="-g"
+  fi
+else
+  if test "$GXX" = yes; then
+    CXXFLAGS="-O2"
+  else
+    CXXFLAGS=
+  fi
+fi
+for ac_declaration in \
+   '' \
+   'extern "C" void std::exit (int) throw (); using std::exit;' \
+   'extern "C" void std::exit (int); using std::exit;' \
+   'extern "C" void exit (int) throw ();' \
+   'extern "C" void exit (int);' \
+   'void exit (int);'
+do
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+#include <stdlib.h>
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+continue
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+rm -f conftest*
+if test -n "$ac_declaration"; then
+  echo '#ifdef __cplusplus' >>confdefs.h
+  echo $ac_declaration      >>confdefs.h
+  echo '#endif'             >>confdefs.h
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+for ac_prog in gawk mawk nawk awk
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_AWK+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$AWK"; then
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_AWK="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+  echo "$as_me:$LINENO: result: $AWK" >&5
+echo "${ECHO_T}$AWK" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$AWK" && break
+done
+
+for ac_prog in 'bison -y' byacc
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_YACC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$YACC"; then
+  ac_cv_prog_YACC="$YACC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_YACC="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+YACC=$ac_cv_prog_YACC
+if test -n "$YACC"; then
+  echo "$as_me:$LINENO: result: $YACC" >&5
+echo "${ECHO_T}$YACC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$YACC" && break
+done
+test -n "$YACC" || YACC="yacc"
+
+ac_aux_dir=
+for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
+  if test -f $ac_dir/install-sh; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install-sh -c"
+    break
+  elif test -f $ac_dir/install.sh; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install.sh -c"
+    break
+  elif test -f $ac_dir/shtool; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/shtool install -c"
+    break
+  fi
+done
+if test -z "$ac_aux_dir"; then
+  { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5
+echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"
+ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure.
+
+# Make sure we can run config.sub.
+$ac_config_sub sun4 >/dev/null 2>&1 ||
+  { { echo "$as_me:$LINENO: error: cannot run $ac_config_sub" >&5
+echo "$as_me: error: cannot run $ac_config_sub" >&2;}
+   { (exit 1); exit 1; }; }
+
+echo "$as_me:$LINENO: checking build system type" >&5
+echo $ECHO_N "checking build system type... $ECHO_C" >&6
+if test "${ac_cv_build+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_build_alias=$build_alias
+test -z "$ac_cv_build_alias" &&
+  ac_cv_build_alias=`$ac_config_guess`
+test -z "$ac_cv_build_alias" &&
+  { { echo "$as_me:$LINENO: error: cannot guess build type; you must specify one" >&5
+echo "$as_me: error: cannot guess build type; you must specify one" >&2;}
+   { (exit 1); exit 1; }; }
+ac_cv_build=`$ac_config_sub $ac_cv_build_alias` ||
+  { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_build_alias failed" >&5
+echo "$as_me: error: $ac_config_sub $ac_cv_build_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_build" >&5
+echo "${ECHO_T}$ac_cv_build" >&6
+build=$ac_cv_build
+build_cpu=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+build_vendor=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+build_os=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+
+echo "$as_me:$LINENO: checking host system type" >&5
+echo $ECHO_N "checking host system type... $ECHO_C" >&6
+if test "${ac_cv_host+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_host_alias=$host_alias
+test -z "$ac_cv_host_alias" &&
+  ac_cv_host_alias=$ac_cv_build_alias
+ac_cv_host=`$ac_config_sub $ac_cv_host_alias` ||
+  { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_host_alias failed" >&5
+echo "$as_me: error: $ac_config_sub $ac_cv_host_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_host" >&5
+echo "${ECHO_T}$ac_cv_host" >&6
+host=$ac_cv_host
+host_cpu=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+host_vendor=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+host_os=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+
+echo "$as_me:$LINENO: checking target system type" >&5
+echo $ECHO_N "checking target system type... $ECHO_C" >&6
+if test "${ac_cv_target+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_target_alias=$target_alias
+test "x$ac_cv_target_alias" = "x" &&
+  ac_cv_target_alias=$ac_cv_host_alias
+ac_cv_target=`$ac_config_sub $ac_cv_target_alias` ||
+  { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_target_alias failed" >&5
+echo "$as_me: error: $ac_config_sub $ac_cv_target_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_target" >&5
+echo "${ECHO_T}$ac_cv_target" >&6
+target=$ac_cv_target
+target_cpu=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+target_vendor=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+target_os=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+
+# The aliases save the names the user supplied, while $host etc.
+# will get canonicalized.
+test -n "$target_alias" &&
+  test "$program_prefix$program_suffix$program_transform_name" = \
+    NONENONEs,x,x, &&
+  program_prefix=${target_alias}-
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5
+echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6
+if test -z "$INSTALL"; then
+if test "${ac_cv_path_install+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in
+  ./ | .// | /cC/* | \
+  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+  ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \
+  /usr/ucb/* ) ;;
+  *)
+    # OSF1 and SCO ODT 3.0 have their own names for install.
+    # Don't use installbsd from OSF since it installs stuff as root
+    # by default.
+    for ac_prog in ginstall scoinst install; do
+      for ac_exec_ext in '' $ac_executable_extensions; do
+	if $as_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
+	  if test $ac_prog = install &&
+	    grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # AIX install.  It has an incompatible calling convention.
+	    :
+	  elif test $ac_prog = install &&
+	    grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # program-specific install script used by HP pwplus--don't use.
+	    :
+	  else
+	    ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+	    break 3
+	  fi
+	fi
+      done
+    done
+    ;;
+esac
+done
+
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL=$ac_cv_path_install
+  else
+    # As a last resort, use the slow shell script.  We don't cache a
+    # path for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the path is relative.
+    INSTALL=$ac_install_sh
+  fi
+fi
+echo "$as_me:$LINENO: result: $INSTALL" >&5
+echo "${ECHO_T}$INSTALL" >&6
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+echo "$as_me:$LINENO: checking whether ln -s works" >&5
+echo $ECHO_N "checking whether ln -s works... $ECHO_C" >&6
+LN_S=$as_ln_s
+if test "$LN_S" = "ln -s"; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+  echo "$as_me:$LINENO: result: no, using $LN_S" >&5
+echo "${ECHO_T}no, using $LN_S" >&6
+fi
+
+echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5
+echo $ECHO_N "checking whether ${MAKE-make} sets \$(MAKE)... $ECHO_C" >&6
+set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,:./+-,___p_,'`
+if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.make <<\_ACEOF
+all:
+	@echo 'ac_maketemp="$(MAKE)"'
+_ACEOF
+# GNU make sometimes prints "make[1]: Entering...", which would confuse us.
+eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=`
+if test -n "$ac_maketemp"; then
+  eval ac_cv_prog_make_${ac_make}_set=yes
+else
+  eval ac_cv_prog_make_${ac_make}_set=no
+fi
+rm -f conftest.make
+fi
+if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  SET_MAKE=
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+  SET_MAKE="MAKE=${MAKE-make}"
+fi
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_RANLIB+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  echo "$as_me:$LINENO: result: $RANLIB" >&5
+echo "${ECHO_T}$RANLIB" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+  test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB=":"
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5
+echo "${ECHO_T}$ac_ct_RANLIB" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  RANLIB=$ac_ct_RANLIB
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+
+echo "$as_me:$LINENO: checking to see if architecture is 64-bit" >&5
+echo $ECHO_N "checking to see if architecture is 64-bit... $ECHO_C" >&6
+arch_64bit=no
+case "$host_cpu" in
+x86_64) arch_64bit=yes ;;
+esac
+
+if test "$arch_64bit" = yes; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  if test -z "$COMPAT32BITFLAGS" ; then
+    COMPAT32BITFLAGS="-m32"
+  fi
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+  if test -z "$COMPAT32BITFLAGS" ; then
+    COMPAT32BITFLAGS=
+  fi
+fi
+export COMPAT32BITFLAGS
+
+
+
+#moved CORBA MICO directory test to get version of MICO
+if test $USE_CORBA = 1; then
+
+if test $MICO_DIR = "default"; then
+#do something
+MICO_INC="-I packages/mico/mico/include"
+else
+#build the micotest program
+MICO_INC= ""
+if test $MICO_DIR != yes; then
+MICO_INC="-I $MICO_DIR"
+fi
+fi
+
+#get MICO_VER value
+sh -c "$CC -c micotest.cpp -o micotest.o $MICO_INC 2>&1" > /dev/null
+sh -c "$CC -o micotest micotest.o -lstdc++ 2>&1" > /dev/null
+MICO_VER=`./micotest` || MICO_VER=2.3.5
+sh -c "rm micotest"
+sh -c "rm micotest.o"
+
+#do test of MICO_VER
+if test MICO_VER != 0; then
+cat >>confdefs.h <<\_ACEOF
+#define MICO_VER 1
+_ACEOF
+
+
+fi
+#end USE_CORBA test
+fi
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5
+echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+  if test "${ac_cv_prog_CPP+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+      # Double quotes because CPP needs to be expanded
+    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether non-existent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  # Broken: success on invalid input.
+continue
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  break
+fi
+
+    done
+    ac_cv_prog_CPP=$CPP
+
+fi
+  CPP=$ac_cv_prog_CPP
+else
+  ac_cv_prog_CPP=$CPP
+fi
+echo "$as_me:$LINENO: result: $CPP" >&5
+echo "${ECHO_T}$CPP" >&6
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether non-existent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  # Broken: success on invalid input.
+continue
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  :
+else
+  { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&5
+echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+echo "$as_me:$LINENO: checking for egrep" >&5
+echo $ECHO_N "checking for egrep... $ECHO_C" >&6
+if test "${ac_cv_prog_egrep+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if echo a | (grep -E '(a|b)') >/dev/null 2>&1
+    then ac_cv_prog_egrep='grep -E'
+    else ac_cv_prog_egrep='egrep'
+    fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_egrep" >&5
+echo "${ECHO_T}$ac_cv_prog_egrep" >&6
+ EGREP=$ac_cv_prog_egrep
+
+
+
+echo "$as_me:$LINENO: checking for AIX" >&5
+echo $ECHO_N "checking for AIX... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef _AIX
+  yes
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "yes" >/dev/null 2>&1; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+cat >>confdefs.h <<\_ACEOF
+#define _ALL_SOURCE 1
+_ACEOF
+
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+rm -f conftest*
+
+
+echo "$as_me:$LINENO: checking for library containing strerror" >&5
+echo $ECHO_N "checking for library containing strerror... $ECHO_C" >&6
+if test "${ac_cv_search_strerror+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+ac_cv_search_strerror=no
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char strerror ();
+int
+main ()
+{
+strerror ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_strerror="none required"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+if test "$ac_cv_search_strerror" = no; then
+  for ac_lib in cposix; do
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char strerror ();
+int
+main ()
+{
+strerror ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_strerror="-l$ac_lib"
+break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+  done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_strerror" >&5
+echo "${ECHO_T}$ac_cv_search_strerror" >&6
+if test "$ac_cv_search_strerror" != no; then
+  test "$ac_cv_search_strerror" = "none required" || LIBS="$ac_cv_search_strerror $LIBS"
+
+fi
+
+echo "$as_me:$LINENO: checking for ANSI C header files" >&5
+echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6
+if test "${ac_cv_header_stdc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_header_stdc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_header_stdc=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then
+  :
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ctype.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      exit(2);
+  exit (0);
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_header_stdc=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
+echo "${ECHO_T}$ac_cv_header_stdc" >&6
+if test $ac_cv_header_stdc = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define STDC_HEADERS 1
+_ACEOF
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+
+
+
+
+
+
+
+
+
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+		  inttypes.h stdint.h unistd.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_Header=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_Header=no"
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+if test "${ac_cv_header_minix_config_h+set}" = set; then
+  echo "$as_me:$LINENO: checking for minix/config.h" >&5
+echo $ECHO_N "checking for minix/config.h... $ECHO_C" >&6
+if test "${ac_cv_header_minix_config_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_minix_config_h" >&5
+echo "${ECHO_T}$ac_cv_header_minix_config_h" >&6
+else
+  # Is the header compilable?
+echo "$as_me:$LINENO: checking minix/config.h usability" >&5
+echo $ECHO_N "checking minix/config.h usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <minix/config.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_header_compiler=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking minix/config.h presence" >&5
+echo $ECHO_N "checking minix/config.h presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <minix/config.h>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: minix/config.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: minix/config.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: present but cannot be compiled" >&5
+echo "$as_me: WARNING: minix/config.h: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: minix/config.h:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: minix/config.h: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: minix/config.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: minix/config.h: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: minix/config.h: in the future, the compiler will take precedence" >&2;}
+    (
+      cat <<\_ASBOX
+## ------------------------------------------ ##
+## Report this to the AC_PACKAGE_NAME lists.  ##
+## ------------------------------------------ ##
+_ASBOX
+    ) |
+      sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+echo "$as_me:$LINENO: checking for minix/config.h" >&5
+echo $ECHO_N "checking for minix/config.h... $ECHO_C" >&6
+if test "${ac_cv_header_minix_config_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_header_minix_config_h=$ac_header_preproc
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_minix_config_h" >&5
+echo "${ECHO_T}$ac_cv_header_minix_config_h" >&6
+
+fi
+if test $ac_cv_header_minix_config_h = yes; then
+  MINIX=yes
+else
+  MINIX=
+fi
+
+
+if test "$MINIX" = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define _POSIX_SOURCE 1
+_ACEOF
+
+
+cat >>confdefs.h <<\_ACEOF
+#define _POSIX_1_SOURCE 2
+_ACEOF
+
+
+cat >>confdefs.h <<\_ACEOF
+#define _MINIX 1
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking for ${CC-cc} option to accept ANSI C" >&5
+echo $ECHO_N "checking for ${CC-cc} option to accept ANSI C... $ECHO_C" >&6
+if test "${ac_cv_prog_cc_stdc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_prog_cc_stdc=no
+ac_save_CFLAGS="$CFLAGS"
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX			-qlanglvl=ansi
+# Ultrix and OSF/1	-std1
+# HP-UX			-Aa -D_HPUX_SOURCE
+# SVR4			-Xc
+for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" -Xc
+do
+  CFLAGS="$ac_save_CFLAGS $ac_arg"
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#if !defined(__STDC__) || __STDC__ != 1
+choke me
+#endif
+
+int
+main ()
+{
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cc_stdc="$ac_arg"; break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+CFLAGS="$ac_save_CFLAGS"
+
+fi
+
+echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6
+case "x$ac_cv_prog_cc_stdc" in
+  x|xno) ;;
+  *) CC="$CC $ac_cv_prog_cc_stdc" ;;
+esac
+
+
+echo "$as_me:$LINENO: checking for function prototypes" >&5
+echo $ECHO_N "checking for function prototypes... $ECHO_C" >&6
+if test "$ac_cv_prog_cc_stdc" != no; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  cat >>confdefs.h <<\_ACEOF
+#define PROTOTYPES 1
+_ACEOF
+
+  U= ANSI2KNR=
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+  U=_ ANSI2KNR=ansi2knr
+fi
+
+echo "$as_me:$LINENO: checking for an ANSI C-conforming const" >&5
+echo $ECHO_N "checking for an ANSI C-conforming const... $ECHO_C" >&6
+if test "${ac_cv_c_const+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+/* FIXME: Include the comments suggested by Paul. */
+#ifndef __cplusplus
+  /* Ultrix mips cc rejects this.  */
+  typedef int charset[2];
+  const charset x;
+  /* SunOS 4.1.1 cc rejects this.  */
+  char const *const *ccp;
+  char **p;
+  /* NEC SVR4.0.2 mips cc rejects this.  */
+  struct point {int x, y;};
+  static struct point const zero = {0,0};
+  /* AIX XL C 1.02.0.0 rejects this.
+     It does not let you subtract one const X* pointer from another in
+     an arm of an if-expression whose if-part is not a constant
+     expression */
+  const char *g = "string";
+  ccp = &g + (g ? g-g : 0);
+  /* HPUX 7.0 cc rejects these. */
+  ++ccp;
+  p = (char**) ccp;
+  ccp = (char const *const *) p;
+  { /* SCO 3.2v4 cc rejects this.  */
+    char *t;
+    char const *s = 0 ? (char *) 0 : (char const *) 0;
+
+    *t++ = 0;
+  }
+  { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
+    int x[] = {25, 17};
+    const int *foo = &x[0];
+    ++foo;
+  }
+  { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
+    typedef const int *iptr;
+    iptr p = 0;
+    ++p;
+  }
+  { /* AIX XL C 1.02.0.0 rejects this saying
+       "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
+    struct s { int j; const int *ap[3]; };
+    struct s *b; b->j = 5;
+  }
+  { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
+    const int foo = 10;
+  }
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_c_const=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_c_const=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_const" >&5
+echo "${ECHO_T}$ac_cv_c_const" >&6
+if test $ac_cv_c_const = no; then
+
+cat >>confdefs.h <<\_ACEOF
+#define const
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking for off_t" >&5
+echo $ECHO_N "checking for off_t... $ECHO_C" >&6
+if test "${ac_cv_type_off_t+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+if ((off_t *) 0)
+  return 0;
+if (sizeof (off_t))
+  return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type_off_t=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_off_t=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_off_t" >&5
+echo "${ECHO_T}$ac_cv_type_off_t" >&6
+if test $ac_cv_type_off_t = yes; then
+  :
+else
+
+cat >>confdefs.h <<_ACEOF
+#define off_t long
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking for size_t" >&5
+echo $ECHO_N "checking for size_t... $ECHO_C" >&6
+if test "${ac_cv_type_size_t+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+if ((size_t *) 0)
+  return 0;
+if (sizeof (size_t))
+  return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type_size_t=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_size_t=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_size_t" >&5
+echo "${ECHO_T}$ac_cv_type_size_t" >&6
+if test $ac_cv_type_size_t = yes; then
+  :
+else
+
+cat >>confdefs.h <<_ACEOF
+#define size_t unsigned
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking whether time.h and sys/time.h may both be included" >&5
+echo $ECHO_N "checking whether time.h and sys/time.h may both be included... $ECHO_C" >&6
+if test "${ac_cv_header_time+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
+
+int
+main ()
+{
+if ((struct tm *) 0)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_header_time=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_header_time=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_time" >&5
+echo "${ECHO_T}$ac_cv_header_time" >&6
+if test $ac_cv_header_time = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define TIME_WITH_SYS_TIME 1
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking whether struct tm is in sys/time.h or time.h" >&5
+echo $ECHO_N "checking whether struct tm is in sys/time.h or time.h... $ECHO_C" >&6
+if test "${ac_cv_struct_tm+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <time.h>
+
+int
+main ()
+{
+struct tm *tp; tp->tm_sec;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_struct_tm=time.h
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_struct_tm=sys/time.h
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_struct_tm" >&5
+echo "${ECHO_T}$ac_cv_struct_tm" >&6
+if test $ac_cv_struct_tm = sys/time.h; then
+
+cat >>confdefs.h <<\_ACEOF
+#define TM_IN_SYS_TIME 1
+_ACEOF
+
+fi
+
+
+if test "$ac_cv_prog_cc_stdc" = '-Xc'; then
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdio.h>
+
+int
+main ()
+{
+ FILE *rubbish = popen("yes", "r");
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+CC="`echo $CC | sed 's/-Xc/-Xa/'`"    ac_cv_prog_cc_stdc='-Xa'
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+
+echo "$as_me:$LINENO: checking for main in -lg" >&5
+echo $ECHO_N "checking for main in -lg... $ECHO_C" >&6
+if test "${ac_cv_lib_g_main+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lg  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+main ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_g_main=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_g_main=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_g_main" >&5
+echo "${ECHO_T}$ac_cv_lib_g_main" >&6
+if test $ac_cv_lib_g_main = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBG 1
+_ACEOF
+
+  LIBS="-lg $LIBS"
+
+fi
+ac_cv_lib_g=ac_cv_lib_g_main
+
+
+echo "$as_me:$LINENO: checking for main in -lm" >&5
+echo $ECHO_N "checking for main in -lm... $ECHO_C" >&6
+if test "${ac_cv_lib_m_main+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lm  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+main ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_m_main=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_m_main=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_m_main" >&5
+echo "${ECHO_T}$ac_cv_lib_m_main" >&6
+if test $ac_cv_lib_m_main = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBM 1
+_ACEOF
+
+  LIBS="-lm $LIBS"
+
+fi
+ac_cv_lib_m=ac_cv_lib_m_main
+
+
+echo "$as_me:$LINENO: checking for main in -lcrypt" >&5
+echo $ECHO_N "checking for main in -lcrypt... $ECHO_C" >&6
+if test "${ac_cv_lib_crypt_main+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lcrypt  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+main ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_crypt_main=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_crypt_main=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_crypt_main" >&5
+echo "${ECHO_T}$ac_cv_lib_crypt_main" >&6
+if test $ac_cv_lib_crypt_main = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBCRYPT 1
+_ACEOF
+
+  LIBS="-lcrypt $LIBS"
+
+fi
+ac_cv_lib_crypt=ac_cv_lib_crypt_main
+
+if test $ENABLE_ACCENTFOLD = 1; then
+
+echo "$as_me:$LINENO: checking for main in -liconv" >&5
+echo $ECHO_N "checking for main in -liconv... $ECHO_C" >&6
+if test "${ac_cv_lib_iconv_main+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-liconv  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+main ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_iconv_main=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_iconv_main=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_iconv_main" >&5
+echo "${ECHO_T}$ac_cv_lib_iconv_main" >&6
+if test $ac_cv_lib_iconv_main = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBICONV 1
+_ACEOF
+
+  LIBS="-liconv $LIBS"
+
+fi
+ac_cv_lib_iconv=ac_cv_lib_iconv_main
+
+fi
+
+
+
+
+
+
+ac_header_dirent=no
+for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
+  as_ac_Header=`echo "ac_cv_header_dirent_$ac_hdr" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_hdr that defines DIR" >&5
+echo $ECHO_N "checking for $ac_hdr that defines DIR... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <$ac_hdr>
+
+int
+main ()
+{
+if ((DIR *) 0)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_Header=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_Header=no"
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_hdr" | $as_tr_cpp` 1
+_ACEOF
+
+ac_header_dirent=$ac_hdr; break
+fi
+
+done
+# Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
+if test $ac_header_dirent = dirent.h; then
+  echo "$as_me:$LINENO: checking for library containing opendir" >&5
+echo $ECHO_N "checking for library containing opendir... $ECHO_C" >&6
+if test "${ac_cv_search_opendir+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+ac_cv_search_opendir=no
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char opendir ();
+int
+main ()
+{
+opendir ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_opendir="none required"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+if test "$ac_cv_search_opendir" = no; then
+  for ac_lib in dir; do
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char opendir ();
+int
+main ()
+{
+opendir ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_opendir="-l$ac_lib"
+break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+  done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_opendir" >&5
+echo "${ECHO_T}$ac_cv_search_opendir" >&6
+if test "$ac_cv_search_opendir" != no; then
+  test "$ac_cv_search_opendir" = "none required" || LIBS="$ac_cv_search_opendir $LIBS"
+
+fi
+
+else
+  echo "$as_me:$LINENO: checking for library containing opendir" >&5
+echo $ECHO_N "checking for library containing opendir... $ECHO_C" >&6
+if test "${ac_cv_search_opendir+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+ac_cv_search_opendir=no
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char opendir ();
+int
+main ()
+{
+opendir ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_opendir="none required"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+if test "$ac_cv_search_opendir" = no; then
+  for ac_lib in x; do
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char opendir ();
+int
+main ()
+{
+opendir ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_opendir="-l$ac_lib"
+break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+  done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_opendir" >&5
+echo "${ECHO_T}$ac_cv_search_opendir" >&6
+if test "$ac_cv_search_opendir" != no; then
+  test "$ac_cv_search_opendir" = "none required" || LIBS="$ac_cv_search_opendir $LIBS"
+
+fi
+
+fi
+
+echo "$as_me:$LINENO: checking for ANSI C header files" >&5
+echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6
+if test "${ac_cv_header_stdc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_header_stdc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_header_stdc=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then
+  :
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ctype.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      exit(2);
+  exit (0);
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_header_stdc=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
+echo "${ECHO_T}$ac_cv_header_stdc" >&6
+if test $ac_cv_header_stdc = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define STDC_HEADERS 1
+_ACEOF
+
+fi
+
+
+
+
+
+
+
+
+
+
+for ac_header in fcntl.h limits.h sys/time.h unistd.h crypt.h string.h memory.h sys/procfs.h sys/stat.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+else
+  # Is the header compilable?
+echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_header_compiler=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <$ac_header>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    (
+      cat <<\_ASBOX
+## ------------------------------------------ ##
+## Report this to the AC_PACKAGE_NAME lists.  ##
+## ------------------------------------------ ##
+_ASBOX
+    ) |
+      sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdio.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "fread" >/dev/null 2>&1; then
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_FREAD_DECL 1
+_ACEOF
+
+fi
+rm -f conftest*
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdio.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "fgetc" >/dev/null 2>&1; then
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_FGETC_DECL 1
+_ACEOF
+
+fi
+rm -f conftest*
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/procfs.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "pr_brksize" >/dev/null 2>&1; then
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_PR_BRKSIZE 1
+_ACEOF
+
+fi
+rm -f conftest*
+
+
+# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
+# for constant arguments.  Useless!
+echo "$as_me:$LINENO: checking for working alloca.h" >&5
+echo $ECHO_N "checking for working alloca.h... $ECHO_C" >&6
+if test "${ac_cv_working_alloca_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <alloca.h>
+int
+main ()
+{
+char *p = (char *) alloca (2 * sizeof (int));
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_working_alloca_h=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_working_alloca_h=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_working_alloca_h" >&5
+echo "${ECHO_T}$ac_cv_working_alloca_h" >&6
+if test $ac_cv_working_alloca_h = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ALLOCA_H 1
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking for alloca" >&5
+echo $ECHO_N "checking for alloca... $ECHO_C" >&6
+if test "${ac_cv_func_alloca_works+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __GNUC__
+# define alloca __builtin_alloca
+#else
+# ifdef _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
+# else
+#  if HAVE_ALLOCA_H
+#   include <alloca.h>
+#  else
+#   ifdef _AIX
+ #pragma alloca
+#   else
+#    ifndef alloca /* predefined by HP cc +Olibcalls */
+char *alloca ();
+#    endif
+#   endif
+#  endif
+# endif
+#endif
+
+int
+main ()
+{
+char *p = (char *) alloca (1);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_func_alloca_works=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_func_alloca_works=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func_alloca_works" >&5
+echo "${ECHO_T}$ac_cv_func_alloca_works" >&6
+
+if test $ac_cv_func_alloca_works = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ALLOCA 1
+_ACEOF
+
+else
+  # The SVR3 libPW and SVR4 libucb both contain incompatible functions
+# that cause trouble.  Some versions do not even contain alloca or
+# contain a buggy version.  If you still want to use their alloca,
+# use ar to extract alloca.o from them instead of compiling alloca.c.
+
+ALLOCA=alloca.$ac_objext
+
+cat >>confdefs.h <<\_ACEOF
+#define C_ALLOCA 1
+_ACEOF
+
+
+echo "$as_me:$LINENO: checking whether \`alloca.c' needs Cray hooks" >&5
+echo $ECHO_N "checking whether \`alloca.c' needs Cray hooks... $ECHO_C" >&6
+if test "${ac_cv_os_cray+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#if defined(CRAY) && ! defined(CRAY2)
+webecray
+#else
+wenotbecray
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "webecray" >/dev/null 2>&1; then
+  ac_cv_os_cray=yes
+else
+  ac_cv_os_cray=no
+fi
+rm -f conftest*
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_os_cray" >&5
+echo "${ECHO_T}$ac_cv_os_cray" >&6
+if test $ac_cv_os_cray = yes; then
+  for ac_func in _getb67 GETB67 getb67; do
+    as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define CRAY_STACKSEG_END $ac_func
+_ACEOF
+
+    break
+fi
+
+  done
+fi
+
+echo "$as_me:$LINENO: checking stack direction for C alloca" >&5
+echo $ECHO_N "checking stack direction for C alloca... $ECHO_C" >&6
+if test "${ac_cv_c_stack_direction+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  ac_cv_c_stack_direction=0
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+int
+find_stack_direction ()
+{
+  static char *addr = 0;
+  auto char dummy;
+  if (addr == 0)
+    {
+      addr = &dummy;
+      return find_stack_direction ();
+    }
+  else
+    return (&dummy > addr) ? 1 : -1;
+}
+
+int
+main ()
+{
+  exit (find_stack_direction () < 0);
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_c_stack_direction=1
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_c_stack_direction=-1
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_stack_direction" >&5
+echo "${ECHO_T}$ac_cv_c_stack_direction" >&6
+
+cat >>confdefs.h <<_ACEOF
+#define STACK_DIRECTION $ac_cv_c_stack_direction
+_ACEOF
+
+
+fi
+
+if test $ac_cv_c_compiler_gnu = yes; then
+    echo "$as_me:$LINENO: checking whether $CC needs -traditional" >&5
+echo $ECHO_N "checking whether $CC needs -traditional... $ECHO_C" >&6
+if test "${ac_cv_prog_gcc_traditional+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+    ac_pattern="Autoconf.*'x'"
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sgtty.h>
+Autoconf TIOCGETP
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "$ac_pattern" >/dev/null 2>&1; then
+  ac_cv_prog_gcc_traditional=yes
+else
+  ac_cv_prog_gcc_traditional=no
+fi
+rm -f conftest*
+
+
+  if test $ac_cv_prog_gcc_traditional = no; then
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <termio.h>
+Autoconf TCGETA
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "$ac_pattern" >/dev/null 2>&1; then
+  ac_cv_prog_gcc_traditional=yes
+fi
+rm -f conftest*
+
+  fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_gcc_traditional" >&5
+echo "${ECHO_T}$ac_cv_prog_gcc_traditional" >&6
+  if test $ac_cv_prog_gcc_traditional = yes; then
+    CC="$CC -traditional"
+  fi
+fi
+
+echo "$as_me:$LINENO: checking return type of signal handlers" >&5
+echo $ECHO_N "checking return type of signal handlers... $ECHO_C" >&6
+if test "${ac_cv_type_signal+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <signal.h>
+#ifdef signal
+# undef signal
+#endif
+#ifdef __cplusplus
+extern "C" void (*signal (int, void (*)(int)))(int);
+#else
+void (*signal ()) ();
+#endif
+
+int
+main ()
+{
+int i;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type_signal=void
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_signal=int
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_signal" >&5
+echo "${ECHO_T}$ac_cv_type_signal" >&6
+
+cat >>confdefs.h <<_ACEOF
+#define RETSIGTYPE $ac_cv_type_signal
+_ACEOF
+
+
+
+for ac_func in vprintf
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+echo "$as_me:$LINENO: checking for _doprnt" >&5
+echo $ECHO_N "checking for _doprnt... $ECHO_C" >&6
+if test "${ac_cv_func__doprnt+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define _doprnt to an innocuous variant, in case <limits.h> declares _doprnt.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define _doprnt innocuous__doprnt
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char _doprnt (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef _doprnt
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char _doprnt ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub__doprnt) || defined (__stub____doprnt)
+choke me
+#else
+char (*f) () = _doprnt;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != _doprnt;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_func__doprnt=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_func__doprnt=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func__doprnt" >&5
+echo "${ECHO_T}$ac_cv_func__doprnt" >&6
+if test $ac_cv_func__doprnt = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_DOPRNT 1
+_ACEOF
+
+fi
+
+fi
+done
+
+
+
+
+
+
+
+
+
+
+
+
+for ac_func in ftime select strftime strtol getrusage times mallinfo setbuffer getpagesize strerror
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+
+
+for ac_func in ftruncate strstr strcasecmp
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+else
+  case $LIBOBJS in
+    "$ac_func.$ac_objext"   | \
+  *" $ac_func.$ac_objext"   | \
+    "$ac_func.$ac_objext "* | \
+  *" $ac_func.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS $ac_func.$ac_objext" ;;
+esac
+
+fi
+done
+
+
+
+echo "$as_me:$LINENO: checking for textdomain" >&5
+echo $ECHO_N "checking for textdomain... $ECHO_C" >&6
+if test "${ac_cv_func_textdomain+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define textdomain to an innocuous variant, in case <limits.h> declares textdomain.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define textdomain innocuous_textdomain
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char textdomain (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef textdomain
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char textdomain ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_textdomain) || defined (__stub___textdomain)
+choke me
+#else
+char (*f) () = textdomain;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != textdomain;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_func_textdomain=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_func_textdomain=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func_textdomain" >&5
+echo "${ECHO_T}$ac_cv_func_textdomain" >&6
+if test $ac_cv_func_textdomain = yes; then
+  cat >>confdefs.h <<\_ACEOF
+#define ENABLE_NLS  1
+_ACEOF
+
+fi
+
+
+# *** Custom checking (based on GNU tar configure.in) ***
+# ---------------------------------------------------------------------------
+echo "$as_me:$LINENO: checking for HP-UX needing gmalloc" >&5
+echo $ECHO_N "checking for HP-UX needing gmalloc... $ECHO_C" >&6
+if test "`(uname -s) 2> /dev/null`" = 'HP-UX'; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  case $LIBOBJS in
+    "gmalloc.$ac_objext"   | \
+  *" gmalloc.$ac_objext"   | \
+    "gmalloc.$ac_objext "* | \
+  *" gmalloc.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS gmalloc.$ac_objext" ;;
+esac
+
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_VALLOC 1
+_ACEOF
+
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+for ac_func in valloc
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+fi
+
+# we cannot generate static libraries under Darwin
+echo "$as_me:$LINENO: checking for Apple MacOS X/Darwin" >&5
+echo $ECHO_N "checking for Apple MacOS X/Darwin... $ECHO_C" >&6
+if test "`(uname -s) 2> /dev/null`" = 'Darwin'; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  STATIC=""
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+  STATIC="-static "
+fi
+
+
+echo "$as_me:$LINENO: checking if malloc debugging is wanted" >&5
+echo $ECHO_N "checking if malloc debugging is wanted... $ECHO_C" >&6
+
+# Check whether --with-dmalloc or --without-dmalloc was given.
+if test "${with_dmalloc+set}" = set; then
+  withval="$with_dmalloc"
+  if test "$withval" = yes; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  cat >>confdefs.h <<\_ACEOF
+#define WITH_DMALLOC 1
+_ACEOF
+
+  LIBS="$LIBS -ldmalloc"
+  LDFLAGS="$LDFLAGS -g"
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi;
+
+echo "$as_me:$LINENO: checking which of rx or regex is wanted" >&5
+echo $ECHO_N "checking which of rx or regex is wanted... $ECHO_C" >&6
+
+# Check whether --with-regex or --without-regex was given.
+if test "${with_regex+set}" = set; then
+  withval="$with_regex"
+  if test "$withval" = yes; then
+  ac_with_regex=1
+  echo "$as_me:$LINENO: result: regex" >&5
+echo "${ECHO_T}regex" >&6
+  cat >>confdefs.h <<\_ACEOF
+#define WITH_REGEX 1
+_ACEOF
+
+  case $LIBOBJS in
+    "regex.$ac_objext"   | \
+  *" regex.$ac_objext"   | \
+    "regex.$ac_objext "* | \
+  *" regex.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS regex.$ac_objext" ;;
+esac
+
+fi
+fi;
+if test -z "$ac_with_regex"; then
+  echo "$as_me:$LINENO: result: rx" >&5
+echo "${ECHO_T}rx" >&6
+  echo "$as_me:$LINENO: checking for re_rx_search" >&5
+echo $ECHO_N "checking for re_rx_search... $ECHO_C" >&6
+if test "${ac_cv_func_re_rx_search+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define re_rx_search to an innocuous variant, in case <limits.h> declares re_rx_search.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define re_rx_search innocuous_re_rx_search
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char re_rx_search (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef re_rx_search
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char re_rx_search ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_re_rx_search) || defined (__stub___re_rx_search)
+choke me
+#else
+char (*f) () = re_rx_search;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != re_rx_search;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_func_re_rx_search=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_func_re_rx_search=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func_re_rx_search" >&5
+echo "${ECHO_T}$ac_cv_func_re_rx_search" >&6
+if test $ac_cv_func_re_rx_search = yes; then
+  :
+else
+  case $LIBOBJS in
+    "rx.$ac_objext"   | \
+  *" rx.$ac_objext"   | \
+    "rx.$ac_objext "* | \
+  *" rx.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS rx.$ac_objext" ;;
+esac
+
+fi
+
+fi
+
+
+# ---------------------------------------------------------------------------
+if test "$ac_cv_func_alloca" = 'no'; then
+  case $LIBOBJS in
+    "xmalloc.$ac_objext"   | \
+  *" xmalloc.$ac_objext"   | \
+    "xmalloc.$ac_objext "* | \
+  *" xmalloc.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS xmalloc.$ac_objext" ;;
+esac
+
+  case $LIBOBJS in
+    "error.$ac_objext"   | \
+  *" error.$ac_objext"   | \
+    "error.$ac_objext "* | \
+  *" error.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS error.$ac_objext" ;;
+esac
+
+fi
+
+
+# ---------------------------------------------------------------------------
+
+ac_ext=cc
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+
+
+echo "$as_me:$LINENO: checking that the GDBM library is available" >&5
+echo $ECHO_N "checking that the GDBM library is available... $ECHO_C" >&6
+if test ! -z "$gdbmdir" ; then
+  # look in given directory for header file
+  if test -r $gdbmdir/include/gdbm.h ; then
+    GDBM_INCLUDE="-I$gdbmdir/include" ;
+  elif test -r $gdbmdir/gdbm.h ; then
+    GDBM_INCLUDE="-I$gdbmdir" ;
+  fi
+
+  # look in given directory for library
+  if test -r $gdbmdir/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir" ;
+  elif test -r $gdbmdir/lib/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir/lib" ;
+  elif test -r $gdbmdir/.libs/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir/.libs" ;
+  fi
+
+  if test ! -z "$GDBM_LIBPATH" -a ! -z "$GDBM_INCLUDE" ; then
+    echo "$as_me:$LINENO: result: $gdbmdir" >&5
+echo "${ECHO_T}$gdbmdir" >&6 ;
+  else
+    echo "$as_me:$LINENO: result: can't find gdbm.h and libgdbm.a in $gdbmdir" >&5
+echo "${ECHO_T}can't find gdbm.h and libgdbm.a in $gdbmdir" >&6;
+    echo "$as_me:$LINENO: checking looking for GDBM library in default locations" >&5
+echo $ECHO_N "checking looking for GDBM library in default locations... $ECHO_C" >&6
+  fi
+fi
+
+# look in default path and in /usr/local
+if test -z "$GDBM_INCLUDE" ; then
+  # try in system directory
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <gdbm.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  success=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+success=no
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+  if test $success = "no"; then
+# last chance - look in /usr/local (eg FreeBSD)
+    GDBM_LIBPATH=-L/usr/local/lib
+    GDBM_INCLUDE=-I/usr/local/include
+    ac_save_CXXFLAGS="$CXXFLAGS"
+    ac_save_LIBS="$LIBS"
+      CXXFLAGS="$CXXFLAGS -I/usr/local/include"
+      LIBS="$LIBS -L/usr/local/lib -lgdbm"
+      cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <gdbm.h>
+#include <stdio.h>
+
+int
+main ()
+{
+printf("%s",gdbm_version);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  success=/usr/local
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+success=no
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+      CXXFLAGS=$ac_save_CXXFLAGS
+      LIBS=$ac_save_LIBS
+  fi
+
+  echo "$as_me:$LINENO: result: $success" >&5
+echo "${ECHO_T}$success" >&6
+  if test $success = "no"; then
+  { { echo "$as_me:$LINENO: error: GDBM Library not available - cannot install" >&5
+echo "$as_me: error: GDBM Library not available - cannot install" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+fi
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_LIBGDBM  1
+_ACEOF
+
+
+
+
+
+echo "$as_me:$LINENO: checking that Perl 5 is available" >&5
+echo $ECHO_N "checking that Perl 5 is available... $ECHO_C" >&6
+success="no"
+pl_path="$PATH"
+IFS="${IFS=   }"; pl_save_ifs="$IFS"; IFS=":"
+for pl_dir in $pl_path; do
+  test -z "$pl_dir" && pl_dir=.
+  if test -x $pl_dir/perl; then
+    success="yes"
+    break
+  fi
+done
+IFS="$pl_save_ifs"
+
+if test $success = "yes"; then
+try=`perl configtest.pl` || try="0"
+try=`expr $try \> 5.000`
+if test $try = "1"; then
+echo "$as_me:$LINENO: result: \"yes\"" >&5
+echo "${ECHO_T}\"yes\"" >&6
+else
+success="no"
+fi
+fi
+
+if test $success = "no"; then
+echo "$as_me:$LINENO: result: \"no\"" >&5
+echo "${ECHO_T}\"no\"" >&6
+{ { echo "$as_me:$LINENO: error: \"Perl 5 not available - cannot install\"" >&5
+echo "$as_me: error: \"Perl 5 not available - cannot install\"" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+success=no
+echo "$as_me:$LINENO: checking \"whether STL library has known faults\"" >&5
+echo $ECHO_N "checking \"whether STL library has known faults\"... $ECHO_C" >&6
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <vector>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  success=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $success = "no"; then
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <vector.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  success="yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+if test $success = "no"; then
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ospace\\std\\vector>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  success="yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+if test $success = yes; then
+echo "$as_me:$LINENO: result: \"no\"" >&5
+echo "${ECHO_T}\"no\"" >&6
+else
+echo "$as_me:$LINENO: result: \"yes\"" >&5
+echo "${ECHO_T}\"yes\"" >&6
+{ { echo "$as_me:$LINENO: error: \"STL Broken - Obtain newer version of GNU C Compiler\"" >&5
+echo "$as_me: error: \"STL Broken - Obtain newer version of GNU C Compiler\"" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+gsdlos=`uname | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
+# check for running bash under cygwin
+ if test "`echo $gsdlos | sed 's/cygwin//'`" != "$gsdlos" ;
+ then
+  gsdlos=windows
+ fi
+
+
+# check for endianness
+echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5
+echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6
+if test "${ac_cv_c_bigendian+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  # See if sys/param.h defines the BYTE_ORDER macro.
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/param.h>
+
+int
+main ()
+{
+#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
+ bogus endian macros
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  # It does; now see whether it defined to BIG_ENDIAN or not.
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/param.h>
+
+int
+main ()
+{
+#if BYTE_ORDER != BIG_ENDIAN
+ not big endian
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_c_bigendian=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_c_bigendian=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+# It does not; compile a test program.
+if test "$cross_compiling" = yes; then
+  # try to guess the endianness by grepping values into an object file
+  ac_cv_c_bigendian=unknown
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
+short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
+void _ascii () { char *s = (char *) ascii_mm; s = (char *) ascii_ii; }
+short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
+short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
+void _ebcdic () { char *s = (char *) ebcdic_mm; s = (char *) ebcdic_ii; }
+int
+main ()
+{
+ _ascii (); _ebcdic ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then
+  ac_cv_c_bigendian=yes
+fi
+if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
+  if test "$ac_cv_c_bigendian" = unknown; then
+    ac_cv_c_bigendian=no
+  else
+    # finding both strings is unlikely to happen, but who knows?
+    ac_cv_c_bigendian=unknown
+  fi
+fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+int
+main ()
+{
+  /* Are we little or big endian?  From Harbison&Steele.  */
+  union
+  {
+    long l;
+    char c[sizeof (long)];
+  } u;
+  u.l = 1;
+  exit (u.c[sizeof (long) - 1] == 1);
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_c_bigendian=no
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_c_bigendian=yes
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_bigendian" >&5
+echo "${ECHO_T}$ac_cv_c_bigendian" >&6
+case $ac_cv_c_bigendian in
+  yes)
+
+cat >>confdefs.h <<\_ACEOF
+#define WORDS_BIGENDIAN 1
+_ACEOF
+ ;;
+  no)
+     ;;
+  *)
+    { { echo "$as_me:$LINENO: error: unknown endianness
+presetting ac_cv_c_bigendian=no (or yes) will help" >&5
+echo "$as_me: error: unknown endianness
+presetting ac_cv_c_bigendian=no (or yes) will help" >&2;}
+   { (exit 1); exit 1; }; } ;;
+esac
+
+# ---------------------------------------------------------------------------
+if test "$ac_cv_func_alloca" = 'no'; then
+  case $LIBOBJS in
+    "xmalloc.o.$ac_objext"   | \
+  *" xmalloc.o.$ac_objext"   | \
+    "xmalloc.o.$ac_objext "* | \
+  *" xmalloc.o.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS xmalloc.o.$ac_objext" ;;
+esac
+
+  case $LIBOBJS in
+    "error.$ac_objext"   | \
+  *" error.$ac_objext"   | \
+    "error.$ac_objext "* | \
+  *" error.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS error.$ac_objext" ;;
+esac
+
+fi
+
+# ---------------------------------------------------------------------------
+
+moduleDirs=""
+MODULEDIRS=""
+if  -d modules  ; then
+  for x in `find modules -mindepth 1 -maxdepth 2`; do
+    if test -d "$x"; then
+      d="$x/Makefile.in"
+      if test -e "$d"; then
+          moduleDirs="$moduleDirs $x/Makefile"
+        MODULEDIRS="$MODULEDIRS $x"
+      fi
+    fi
+  done
+  echo "Making $moduleDirs in modules directory"
+
+fi
+
+
+# ---------------------------------------------------------------------------
+
+
+subdirs="$subdirs packages"
+
+
+# the list of folders in the src folder
+srclist="src/hashfile/Makefile \
+         src/phind/generate/Makefile"
+
+                                        ac_config_files="$ac_config_files packages/Makefile Makefile $srclist $moduleDirs"
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, don't put newlines in cache variables' values.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+{
+  (set) 2>&1 |
+    case `(ac_space=' '; set | grep ac_space) 2>&1` in
+    *ac_space=\ *)
+      # `set' does not quote correctly, so add quotes (double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \).
+      sed -n \
+	"s/'/'\\\\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;;
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n \
+	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+      ;;
+    esac;
+} |
+  sed '
+     t clear
+     : clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     : end' >>confcache
+if diff $cache_file confcache >/dev/null 2>&1; then :; else
+  if test -w $cache_file; then
+    test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file"
+    cat confcache >$cache_file
+  else
+    echo "not updating unwritable cache $cache_file"
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
+s/:*\$(srcdir):*/:/;
+s/:*\${srcdir}:*/:/;
+s/:*@srcdir@:*/:/;
+s/^\([^=]*=[	 ]*\):*/\1/;
+s/:*$//;
+s/^[^=]*=[	 ]*$//;
+}'
+fi
+
+DEFS=-DHAVE_CONFIG_H
+
+ac_libobjs=
+ac_ltlibobjs=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_i=`echo "$ac_i" |
+	 sed 's/\$U\././;s/\.o$//;s/\.obj$//'`
+  # 2. Add them.
+  ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext"
+  ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+
+: ${CONFIG_STATUS=./config.status}
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5
+echo "$as_me: creating $CONFIG_STATUS" >&6;}
+cat >$CONFIG_STATUS <<_ACEOF
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+SHELL=\${CONFIG_SHELL-$SHELL}
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+  set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+  LC_TELEPHONE LC_TIME
+do
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+    eval $as_var=C; export $as_var
+  else
+    $as_unset $as_var
+  fi
+done
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)$' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\/\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+
+
+# PATH needs CR, and LINENO needs CR and PATH.
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
+  # Find who we are.  Look in the path if we contain no path at all
+  # relative or not.
+  case $0 in
+    *[\\/]* ) as_myself=$0 ;;
+    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+
+       ;;
+  esac
+  # We did not find ourselves, most probably we were run as `sh COMMAND'
+  # in which case we are not to be found in the path.
+  if test "x$as_myself" = x; then
+    as_myself=$0
+  fi
+  if test ! -f "$as_myself"; then
+    { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5
+echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+  case $CONFIG_SHELL in
+  '')
+    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for as_base in sh bash ksh sh5; do
+	 case $as_dir in
+	 /*)
+	   if ("$as_dir/$as_base" -c '
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
+	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
+	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
+	     CONFIG_SHELL=$as_dir/$as_base
+	     export CONFIG_SHELL
+	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
+	   fi;;
+	 esac
+       done
+done
+;;
+  esac
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line before each line; the second 'sed' does the real
+  # work.  The second script uses 'N' to pair each line-number line
+  # with the numbered line, and appends trailing '-' during
+  # substitution so that $LINENO is not a special case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
+  sed '=' <$as_myself |
+    sed '
+      N
+      s,$,-,
+      : loop
+      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+      t loop
+      s,-$,,
+      s,^['$as_cr_digits']*\n,,
+    ' >$as_me.lineno &&
+  chmod +x $as_me.lineno ||
+    { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5
+echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;}
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensible to this).
+  . ./$as_me.lineno
+  # Exit status is that of the last command.
+  exit
+}
+
+
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+  *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T='	' ;;
+  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+echo >conf$$.file
+if ln -s conf$$.file conf$$ 2>/dev/null; then
+  # We could just check for DJGPP; but this test a) works b) is more generic
+  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
+  if test -f conf$$.exe; then
+    # Don't use ln at all; we don't have any links
+    as_ln_s='cp -p'
+  else
+    as_ln_s='ln -s'
+  fi
+elif ln conf$$.file conf$$ 2>/dev/null; then
+  as_ln_s=ln
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.file
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p=:
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_executable_p="test -f"
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.
+as_nl='
+'
+IFS=" 	$as_nl"
+
+# CDPATH.
+$as_unset CDPATH
+
+exec 6>&1
+
+# Open the log real soon, to keep \$[0] and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.  Logging --version etc. is OK.
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+} >&5
+cat >&5 <<_CSEOF
+
+This file was extended by $as_me, which was
+generated by GNU Autoconf 2.59.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+_CSEOF
+echo "on `(hostname || uname -n) 2>/dev/null | sed 1q`" >&5
+echo >&5
+_ACEOF
+
+# Files that config.status was made for.
+if test -n "$ac_config_files"; then
+  echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_headers"; then
+  echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_links"; then
+  echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_commands"; then
+  echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+ac_cs_usage="\
+\`$as_me' instantiates files from templates according to the
+current configuration.
+
+Usage: $0 [OPTIONS] [FILE]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number, then exit
+  -q, --quiet      do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+  --file=FILE[:TEMPLATE]
+		   instantiate the configuration file FILE
+  --header=FILE[:TEMPLATE]
+		   instantiate the configuration header FILE
+
+Configuration files:
+$config_files
+
+Configuration headers:
+$config_headers
+
+Report bugs to <bug-autoconf@gnu.org>."
+_ACEOF
+
+cat >>$CONFIG_STATUS <<_ACEOF
+ac_cs_version="\\
+config.status
+configured by $0, generated by GNU Autoconf 2.59,
+  with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
+
+Copyright (C) 2003 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+srcdir=$srcdir
+INSTALL="$INSTALL"
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+# If no file are specified by the user, then we need to provide default
+# value.  By we need to know if files were specified by the user.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=*)
+    ac_option=`expr "x$1" : 'x\([^=]*\)='`
+    ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  -*)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  *) # This is not an option, so the user has probably given explicit
+     # arguments.
+     ac_option=$1
+     ac_need_defaults=false;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --vers* | -V )
+    echo "$ac_cs_version"; exit 0 ;;
+  --he | --h)
+    # Conflict between --help and --header
+    { { echo "$as_me:$LINENO: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&5
+echo "$as_me: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&2;}
+   { (exit 1); exit 1; }; };;
+  --help | --hel | -h )
+    echo "$ac_cs_usage"; exit 0 ;;
+  --debug | --d* | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    CONFIG_FILES="$CONFIG_FILES $ac_optarg"
+    ac_need_defaults=false;;
+  --header | --heade | --head | --hea )
+    $ac_shift
+    CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg"
+    ac_need_defaults=false;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) { { echo "$as_me:$LINENO: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&5
+echo "$as_me: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&2;}
+   { (exit 1); exit 1; }; } ;;
+
+  *) ac_config_targets="$ac_config_targets $1" ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF
+if \$ac_cs_recheck; then
+  echo "running $SHELL $0 " $ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6
+  exec $SHELL $0 $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+fi
+
+_ACEOF
+
+
+
+
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+for ac_config_target in $ac_config_targets
+do
+  case "$ac_config_target" in
+  # Handling of arguments.
+  "packages/Makefile" ) CONFIG_FILES="$CONFIG_FILES packages/Makefile" ;;
+  "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+  "$srclist" ) CONFIG_FILES="$CONFIG_FILES $srclist" ;;
+  "$moduleDirs" ) CONFIG_FILES="$CONFIG_FILES $moduleDirs" ;;
+  "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
+  *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
+echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason to put it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Create a temporary directory, and hook for its removal unless debugging.
+$debug ||
+{
+  trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0
+  trap '{ (exit 1); exit 1; }' 1 2 13 15
+}
+
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
+  test -n "$tmp" && test -d "$tmp"
+}  ||
+{
+  tmp=./confstat$$-$RANDOM
+  (umask 077 && mkdir $tmp)
+} ||
+{
+   echo "$me: cannot create a temporary directory in ." >&2
+   { (exit 1); exit 1; }
+}
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<_ACEOF
+
+#
+# CONFIG_FILES section.
+#
+
+# No need to generate the scripts if there are no CONFIG_FILES.
+# This happens for instance when ./config.status config.h
+if test -n "\$CONFIG_FILES"; then
+  # Protect against being on the right side of a sed subst in config.status.
+  sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g;
+   s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF
+s,@SHELL@,$SHELL,;t t
+s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t
+s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t
+s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t
+s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t
+s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t
+s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t
+s,@exec_prefix@,$exec_prefix,;t t
+s,@prefix@,$prefix,;t t
+s,@program_transform_name@,$program_transform_name,;t t
+s,@bindir@,$bindir,;t t
+s,@sbindir@,$sbindir,;t t
+s,@libexecdir@,$libexecdir,;t t
+s,@datadir@,$datadir,;t t
+s,@sysconfdir@,$sysconfdir,;t t
+s,@sharedstatedir@,$sharedstatedir,;t t
+s,@localstatedir@,$localstatedir,;t t
+s,@libdir@,$libdir,;t t
+s,@includedir@,$includedir,;t t
+s,@oldincludedir@,$oldincludedir,;t t
+s,@infodir@,$infodir,;t t
+s,@mandir@,$mandir,;t t
+s,@build_alias@,$build_alias,;t t
+s,@host_alias@,$host_alias,;t t
+s,@target_alias@,$target_alias,;t t
+s,@DEFS@,$DEFS,;t t
+s,@ECHO_C@,$ECHO_C,;t t
+s,@ECHO_N@,$ECHO_N,;t t
+s,@ECHO_T@,$ECHO_T,;t t
+s,@LIBS@,$LIBS,;t t
+s,@PACKAGE@,$PACKAGE,;t t
+s,@VERSION@,$VERSION,;t t
+s,@USE_FASTCGI@,$USE_FASTCGI,;t t
+s,@USE_LANGACTION@,$USE_LANGACTION,;t t
+s,@USE_CORBA@,$USE_CORBA,;t t
+s,@MICO_DIR@,$MICO_DIR,;t t
+s,@USE_Z3950@,$USE_Z3950,;t t
+s,@USE_YAZ@,$USE_YAZ,;t t
+s,@ENABLE_ACCENTFOLD@,$ENABLE_ACCENTFOLD,;t t
+s,@USE_SQLITE@,$USE_SQLITE,;t t
+s,@LDFLAGS@,$LDFLAGS,;t t
+s,@CFLAGS@,$CFLAGS,;t t
+s,@CC@,$CC,;t t
+s,@CPPFLAGS@,$CPPFLAGS,;t t
+s,@ac_ct_CC@,$ac_ct_CC,;t t
+s,@EXEEXT@,$EXEEXT,;t t
+s,@OBJEXT@,$OBJEXT,;t t
+s,@CXX@,$CXX,;t t
+s,@CXXFLAGS@,$CXXFLAGS,;t t
+s,@ac_ct_CXX@,$ac_ct_CXX,;t t
+s,@AWK@,$AWK,;t t
+s,@YACC@,$YACC,;t t
+s,@build@,$build,;t t
+s,@build_cpu@,$build_cpu,;t t
+s,@build_vendor@,$build_vendor,;t t
+s,@build_os@,$build_os,;t t
+s,@host@,$host,;t t
+s,@host_cpu@,$host_cpu,;t t
+s,@host_vendor@,$host_vendor,;t t
+s,@host_os@,$host_os,;t t
+s,@target@,$target,;t t
+s,@target_cpu@,$target_cpu,;t t
+s,@target_vendor@,$target_vendor,;t t
+s,@target_os@,$target_os,;t t
+s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t
+s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t
+s,@INSTALL_DATA@,$INSTALL_DATA,;t t
+s,@LN_S@,$LN_S,;t t
+s,@SET_MAKE@,$SET_MAKE,;t t
+s,@RANLIB@,$RANLIB,;t t
+s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t
+s,@COMPAT32BITFLAGS@,$COMPAT32BITFLAGS,;t t
+s,@MICO_VER@,$MICO_VER,;t t
+s,@CPP@,$CPP,;t t
+s,@EGREP@,$EGREP,;t t
+s,@U@,$U,;t t
+s,@ANSI2KNR@,$ANSI2KNR,;t t
+s,@ALLOCA@,$ALLOCA,;t t
+s,@LIBOBJS@,$LIBOBJS,;t t
+s,@STATIC@,$STATIC,;t t
+s,@GDBM_LIBPATH@,$GDBM_LIBPATH,;t t
+s,@GDBM_INCLUDE@,$GDBM_INCLUDE,;t t
+s,@gsdlos@,$gsdlos,;t t
+s,@MODULEDIRS@,$MODULEDIRS,;t t
+s,@subdirs@,$subdirs,;t t
+s,@LTLIBOBJS@,$LTLIBOBJS,;t t
+CEOF
+
+_ACEOF
+
+  cat >>$CONFIG_STATUS <<\_ACEOF
+  # Split the substitutions into bite-sized pieces for seds with
+  # small command number limits, like on Digital OSF/1 and HP-UX.
+  ac_max_sed_lines=48
+  ac_sed_frag=1 # Number of current file.
+  ac_beg=1 # First line for current file.
+  ac_end=$ac_max_sed_lines # Line after last line for current file.
+  ac_more_lines=:
+  ac_sed_cmds=
+  while $ac_more_lines; do
+    if test $ac_beg -gt 1; then
+      sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
+    else
+      sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
+    fi
+    if test ! -s $tmp/subs.frag; then
+      ac_more_lines=false
+    else
+      # The purpose of the label and of the branching condition is to
+      # speed up the sed processing (if there are no `@' at all, there
+      # is no need to browse any of the substitutions).
+      # These are the two extra sed commands mentioned above.
+      (echo ':t
+  /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed
+      if test -z "$ac_sed_cmds"; then
+	ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed"
+      else
+	ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed"
+      fi
+      ac_sed_frag=`expr $ac_sed_frag + 1`
+      ac_beg=$ac_end
+      ac_end=`expr $ac_end + $ac_max_sed_lines`
+    fi
+  done
+  if test -z "$ac_sed_cmds"; then
+    ac_sed_cmds=cat
+  fi
+fi # test -n "$CONFIG_FILES"
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case $ac_file in
+  - | *:- | *:-:* ) # input from stdin
+	cat >$tmp/stdin
+	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  * )   ac_file_in=$ac_file.in ;;
+  esac
+
+  # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories.
+  ac_dir=`(dirname "$ac_file") 2>/dev/null ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+  { if $as_mkdir_p; then
+    mkdir -p "$ac_dir"
+  else
+    as_dir="$ac_dir"
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+   { (exit 1); exit 1; }; }; }
+
+  ac_builddir=.
+
+if test "$ac_dir" != .; then
+  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  # A "../" for each directory in $ac_dir_suffix.
+  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+  ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+  .)  # No --srcdir option.  We are building in place.
+    ac_srcdir=.
+    if test -z "$ac_top_builddir"; then
+       ac_top_srcdir=.
+    else
+       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+    fi ;;
+  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir ;;
+  *) # Relative path.
+    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
+
+
+  case $INSTALL in
+  [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+  *) ac_INSTALL=$ac_top_builddir$INSTALL ;;
+  esac
+
+  if test x"$ac_file" != x-; then
+    { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+    rm -f "$ac_file"
+  fi
+  # Let's still pretend it is `configure' which instantiates (i.e., don't
+  # use $as_me), people would be surprised to read:
+  #    /* config.h.  Generated by config.status.  */
+  if test x"$ac_file" = x-; then
+    configure_input=
+  else
+    configure_input="$ac_file.  "
+  fi
+  configure_input=$configure_input"Generated from `echo $ac_file_in |
+				     sed 's,.*/,,'` by configure."
+
+  # First look for the input files in the build tree, otherwise in the
+  # src tree.
+  ac_file_inputs=`IFS=:
+    for f in $ac_file_in; do
+      case $f in
+      -) echo $tmp/stdin ;;
+      [\\/$]*)
+	 # Absolute (can't be DOS-style, as IFS=:)
+	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 echo "$f";;
+      *) # Relative
+	 if test -f "$f"; then
+	   # Build tree
+	   echo "$f"
+	 elif test -f "$srcdir/$f"; then
+	   # Source tree
+	   echo "$srcdir/$f"
+	 else
+	   # /dev/null tree
+	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 fi;;
+      esac
+    done` || { (exit 1); exit 1; }
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF
+  sed "$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s,@configure_input@,$configure_input,;t t
+s,@srcdir@,$ac_srcdir,;t t
+s,@abs_srcdir@,$ac_abs_srcdir,;t t
+s,@top_srcdir@,$ac_top_srcdir,;t t
+s,@abs_top_srcdir@,$ac_abs_top_srcdir,;t t
+s,@builddir@,$ac_builddir,;t t
+s,@abs_builddir@,$ac_abs_builddir,;t t
+s,@top_builddir@,$ac_top_builddir,;t t
+s,@abs_top_builddir@,$ac_abs_top_builddir,;t t
+s,@INSTALL@,$ac_INSTALL,;t t
+" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out
+  rm -f $tmp/stdin
+  if test x"$ac_file" != x-; then
+    mv $tmp/out $ac_file
+  else
+    cat $tmp/out
+    rm -f $tmp/out
+  fi
+
+done
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+#
+# CONFIG_HEADER section.
+#
+
+# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where
+# NAME is the cpp macro being defined and VALUE is the value it is being given.
+#
+# ac_d sets the value in "#define NAME VALUE" lines.
+ac_dA='s,^\([	 ]*\)#\([	 ]*define[	 ][	 ]*\)'
+ac_dB='[	 ].*$,\1#\2'
+ac_dC=' '
+ac_dD=',;t'
+# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
+ac_uA='s,^\([	 ]*\)#\([	 ]*\)undef\([	 ][	 ]*\)'
+ac_uB='$,\1#\2define\3'
+ac_uC=' '
+ac_uD=',;t'
+
+for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case $ac_file in
+  - | *:- | *:-:* ) # input from stdin
+	cat >$tmp/stdin
+	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  * )   ac_file_in=$ac_file.in ;;
+  esac
+
+  test x"$ac_file" != x- && { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+
+  # First look for the input files in the build tree, otherwise in the
+  # src tree.
+  ac_file_inputs=`IFS=:
+    for f in $ac_file_in; do
+      case $f in
+      -) echo $tmp/stdin ;;
+      [\\/$]*)
+	 # Absolute (can't be DOS-style, as IFS=:)
+	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 # Do quote $f, to prevent DOS paths from being IFS'd.
+	 echo "$f";;
+      *) # Relative
+	 if test -f "$f"; then
+	   # Build tree
+	   echo "$f"
+	 elif test -f "$srcdir/$f"; then
+	   # Source tree
+	   echo "$srcdir/$f"
+	 else
+	   # /dev/null tree
+	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 fi;;
+      esac
+    done` || { (exit 1); exit 1; }
+  # Remove the trailing spaces.
+  sed 's/[	 ]*$//' $ac_file_inputs >$tmp/in
+
+_ACEOF
+
+# Transform confdefs.h into two sed scripts, `conftest.defines' and
+# `conftest.undefs', that substitutes the proper values into
+# config.h.in to produce config.h.  The first handles `#define'
+# templates, and the second `#undef' templates.
+# And first: Protect against being on the right side of a sed subst in
+# config.status.  Protect against being in an unquoted here document
+# in config.status.
+rm -f conftest.defines conftest.undefs
+# Using a here document instead of a string reduces the quoting nightmare.
+# Putting comments in sed scripts is not portable.
+#
+# `end' is used to avoid that the second main sed command (meant for
+# 0-ary CPP macros) applies to n-ary macro definitions.
+# See the Autoconf documentation for `clear'.
+cat >confdef2sed.sed <<\_ACEOF
+s/[\\&,]/\\&/g
+s,[\\$`],\\&,g
+t clear
+: clear
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*\)\(([^)]*)\)[	 ]*\(.*\)$,${ac_dA}\1${ac_dB}\1\2${ac_dC}\3${ac_dD},gp
+t end
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp
+: end
+_ACEOF
+# If some macros were called several times there might be several times
+# the same #defines, which is useless.  Nevertheless, we may not want to
+# sort them, since we want the *last* AC-DEFINE to be honored.
+uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines
+sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs
+rm -f confdef2sed.sed
+
+# This sed command replaces #undef with comments.  This is necessary, for
+# example, in the case of _POSIX_SOURCE, which is predefined and required
+# on some systems where configure will not decide to define it.
+cat >>conftest.undefs <<\_ACEOF
+s,^[	 ]*#[	 ]*undef[	 ][	 ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,
+_ACEOF
+
+# Break up conftest.defines because some shells have a limit on the size
+# of here documents, and old seds have small limits too (100 cmds).
+echo '  # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS
+echo '  if grep "^[	 ]*#[	 ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS
+echo '  # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS
+echo '  :' >>$CONFIG_STATUS
+rm -f conftest.tail
+while grep . conftest.defines >/dev/null
+do
+  # Write a limited-size here document to $tmp/defines.sed.
+  echo '  cat >$tmp/defines.sed <<CEOF' >>$CONFIG_STATUS
+  # Speed up: don't consider the non `#define' lines.
+  echo '/^[	 ]*#[	 ]*define/!b' >>$CONFIG_STATUS
+  # Work around the forget-to-reset-the-flag bug.
+  echo 't clr' >>$CONFIG_STATUS
+  echo ': clr' >>$CONFIG_STATUS
+  sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS
+  echo 'CEOF
+  sed -f $tmp/defines.sed $tmp/in >$tmp/out
+  rm -f $tmp/in
+  mv $tmp/out $tmp/in
+' >>$CONFIG_STATUS
+  sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail
+  rm -f conftest.defines
+  mv conftest.tail conftest.defines
+done
+rm -f conftest.defines
+echo '  fi # grep' >>$CONFIG_STATUS
+echo >>$CONFIG_STATUS
+
+# Break up conftest.undefs because some shells have a limit on the size
+# of here documents, and old seds have small limits too (100 cmds).
+echo '  # Handle all the #undef templates' >>$CONFIG_STATUS
+rm -f conftest.tail
+while grep . conftest.undefs >/dev/null
+do
+  # Write a limited-size here document to $tmp/undefs.sed.
+  echo '  cat >$tmp/undefs.sed <<CEOF' >>$CONFIG_STATUS
+  # Speed up: don't consider the non `#undef'
+  echo '/^[	 ]*#[	 ]*undef/!b' >>$CONFIG_STATUS
+  # Work around the forget-to-reset-the-flag bug.
+  echo 't clr' >>$CONFIG_STATUS
+  echo ': clr' >>$CONFIG_STATUS
+  sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS
+  echo 'CEOF
+  sed -f $tmp/undefs.sed $tmp/in >$tmp/out
+  rm -f $tmp/in
+  mv $tmp/out $tmp/in
+' >>$CONFIG_STATUS
+  sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail
+  rm -f conftest.undefs
+  mv conftest.tail conftest.undefs
+done
+rm -f conftest.undefs
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+  # Let's still pretend it is `configure' which instantiates (i.e., don't
+  # use $as_me), people would be surprised to read:
+  #    /* config.h.  Generated by config.status.  */
+  if test x"$ac_file" = x-; then
+    echo "/* Generated by configure.  */" >$tmp/config.h
+  else
+    echo "/* $ac_file.  Generated by configure.  */" >$tmp/config.h
+  fi
+  cat $tmp/in >>$tmp/config.h
+  rm -f $tmp/in
+  if test x"$ac_file" != x-; then
+    if diff $ac_file $tmp/config.h >/dev/null 2>&1; then
+      { echo "$as_me:$LINENO: $ac_file is unchanged" >&5
+echo "$as_me: $ac_file is unchanged" >&6;}
+    else
+      ac_dir=`(dirname "$ac_file") 2>/dev/null ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+      { if $as_mkdir_p; then
+    mkdir -p "$ac_dir"
+  else
+    as_dir="$ac_dir"
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+   { (exit 1); exit 1; }; }; }
+
+      rm -f $ac_file
+      mv $tmp/config.h $ac_file
+    fi
+  else
+    cat $tmp/config.h
+    rm -f $tmp/config.h
+  fi
+done
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+{ (exit 0); exit 0; }
+_ACEOF
+chmod +x $CONFIG_STATUS
+ac_clean_files=$ac_clean_files_save
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || { (exit 1); exit 1; }
+fi
+
+#
+# CONFIG_SUBDIRS section.
+#
+if test "$no_recursion" != yes; then
+
+  # Remove --cache-file and --srcdir arguments so they do not pile up.
+  ac_sub_configure_args=
+  ac_prev=
+  for ac_arg in $ac_configure_args; do
+    if test -n "$ac_prev"; then
+      ac_prev=
+      continue
+    fi
+    case $ac_arg in
+    -cache-file | --cache-file | --cache-fil | --cache-fi \
+    | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+      ac_prev=cache_file ;;
+    -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+    | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* \
+    | --c=*)
+      ;;
+    --config-cache | -C)
+      ;;
+    -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+      ac_prev=srcdir ;;
+    -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+      ;;
+    -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+      ac_prev=prefix ;;
+    -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+      ;;
+    *) ac_sub_configure_args="$ac_sub_configure_args $ac_arg" ;;
+    esac
+  done
+
+  # Always prepend --prefix to ensure using the same prefix
+  # in subdir configurations.
+  ac_sub_configure_args="--prefix=$prefix $ac_sub_configure_args"
+
+  ac_popdir=`pwd`
+  for ac_dir in : $subdirs; do test "x$ac_dir" = x: && continue
+
+    # Do not complain, so a configure script can configure whichever
+    # parts of a large source tree are present.
+    test -d $srcdir/$ac_dir || continue
+
+    { echo "$as_me:$LINENO: configuring in $ac_dir" >&5
+echo "$as_me: configuring in $ac_dir" >&6;}
+    { if $as_mkdir_p; then
+    mkdir -p "$ac_dir"
+  else
+    as_dir="$ac_dir"
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+   { (exit 1); exit 1; }; }; }
+
+    ac_builddir=.
+
+if test "$ac_dir" != .; then
+  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  # A "../" for each directory in $ac_dir_suffix.
+  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+  ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+  .)  # No --srcdir option.  We are building in place.
+    ac_srcdir=.
+    if test -z "$ac_top_builddir"; then
+       ac_top_srcdir=.
+    else
+       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+    fi ;;
+  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir ;;
+  *) # Relative path.
+    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
+
+
+    cd $ac_dir
+
+    # Check for guested configure; otherwise get Cygnus style configure.
+    if test -f $ac_srcdir/configure.gnu; then
+      ac_sub_configure="$SHELL '$ac_srcdir/configure.gnu'"
+    elif test -f $ac_srcdir/configure; then
+      ac_sub_configure="$SHELL '$ac_srcdir/configure'"
+    elif test -f $ac_srcdir/configure.in; then
+      ac_sub_configure=$ac_configure
+    else
+      { echo "$as_me:$LINENO: WARNING: no configuration information is in $ac_dir" >&5
+echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2;}
+      ac_sub_configure=
+    fi
+
+    # The recursion is here.
+    if test -n "$ac_sub_configure"; then
+      # Make the cache file name correct relative to the subdirectory.
+      case $cache_file in
+      [\\/]* | ?:[\\/]* ) ac_sub_cache_file=$cache_file ;;
+      *) # Relative path.
+	ac_sub_cache_file=$ac_top_builddir$cache_file ;;
+      esac
+
+      { echo "$as_me:$LINENO: running $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&5
+echo "$as_me: running $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&6;}
+      # The eval makes quoting arguments work.
+      eval $ac_sub_configure $ac_sub_configure_args \
+	   --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir ||
+	{ { echo "$as_me:$LINENO: error: $ac_sub_configure failed for $ac_dir" >&5
+echo "$as_me: error: $ac_sub_configure failed for $ac_dir" >&2;}
+   { (exit 1); exit 1; }; }
+    fi
+
+    cd $ac_popdir
+  done
+fi
+
+
+
Index: /gsdl/trunk/build-src/configure.in
===================================================================
--- /gsdl/trunk/build-src/configure.in	(revision 16571)
+++ /gsdl/trunk/build-src/configure.in	(revision 16571)
@@ -0,0 +1,458 @@
+dnl Process this file with autoconf to produce a configure script.
+dnl Use autoconf-2.59 or later... it might not work anymore with
+dnl the older 2.1x versions - jrm21 12/2004
+AC_INIT()
+AC_CONFIG_HEADER(config.h)
+
+
+PACKAGE=gsdl
+VERSION=2.82-svn
+AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
+AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
+AC_SUBST(PACKAGE)
+AC_SUBST(VERSION)
+
+dnl
+dnl Set use of fast cgi
+dnl
+USE_FASTCGI=0
+if test USE_FASTCGI = 1; then
+AC_DEFINE(USE_FASTCGI)
+AC_SUBST(USE_FASTCGI)
+fi
+
+dnl
+dnl Set use of langaction
+dnl
+dnl USE_LANGACTION=0
+if test USE_LANGACTION = 1; then
+AC_DEFINE(USE_LANGACTION)
+AC_SUBST(USE_LANGACTION)
+fi
+
+dnl
+dnl Set use of corba
+dnl
+AC_ARG_ENABLE(corba, [  --enable-corba          Enable CORBA support], USE_CORBA=1, USE_CORBA=0)
+AC_DEFINE_UNQUOTED(USE_CORBA, $USE_CORBA)
+AC_SUBST(USE_CORBA)
+
+AC_ARG_WITH(micodir, [  --with-micodir          Use installed MICO directory], MICO_DIR=$enableval, MICO_DIR="default")
+AC_DEFINE_UNQUOTED(MICO_DIR, "$MICO_DIR")
+AC_SUBST(MICO_DIR)
+
+dnl
+dnl Set use of z39.50
+dnl
+AC_ARG_ENABLE(z3950, [  --enable-z3950          Enable Z39.50 client support], USE_Z3950=1, USE_Z3950=0)
+if test USE_Z3950 = 1; then
+AC_DEFINE(USE_Z3950, $USE_Z3950)
+AC_SUBST(USE_Z3950)
+fi
+
+dnl
+dnl Set use of yaz - now compiled by default even when z3950 support not required
+dnl
+AC_ARG_ENABLE(yaz, [  --disable-yaz           Disable YAZ compilation], USE_YAZ=0, USE_YAZ=1)
+dnl if test USE_YAZ = 1; then
+AC_DEFINE(USE_YAZ, $USE_YAZ)
+AC_SUBST(USE_YAZ)
+dnl fi
+
+dnl
+dnl look for libgdbm if not in standard location
+dnl
+AC_ARG_WITH(gdbm, [  --with-gdbm=dir         Use local gdbm library and headers], gdbmdir=$withval)
+
+dnl 
+dnl disable compilation of accent folding stuff for mgpp (and one day mg)
+dnl
+AC_ARG_ENABLE(accentfold, [  --disable-accentfold    Disable Accent Folding for MGPP], ENABLE_ACCENTFOLD=0, ENABLE_ACCENTFOLD=1)
+AC_DEFINE(ENABLE_ACCENTFOLD, $ENABLE_ACCENTFOLD)
+AC_SUBST(ENABLE_ACCENTFOLD)
+
+dnl
+dnl Set use of SQLite (enabled by default)
+dnl
+AC_ARG_ENABLE(sqlite, [  --disable-sqlite        Disable SQLite support], USE_SQLITE=0, USE_SQLITE=1)
+AC_DEFINE(USE_SQLITE, $USE_SQLITE)
+AC_SUBST(USE_SQLITE)
+
+dnl Checks for programs.
+LDFLAGS=$LDFLAGS
+AC_SUBST(LDFLAGS)
+dnl only set CFLAGS if not already set in environment
+if test -z "$CFLAGS"; then
+CFLAGS=-O2
+fi
+AC_SUBST(CFLAGS)
+
+
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_AWK
+AC_PROG_YACC
+dnl get $target_cpu, $target_vendor, and $target_os
+dnl (as well as host_*)
+AC_CANONICAL_SYSTEM
+dnl do we actually want this? It adds a prefix based on host, system etc
+dnl AC_ARG_PROGRAM
+AC_PROG_INSTALL
+AC_PROG_LN_S
+AC_PROG_MAKE_SET
+AC_PROG_RANLIB
+
+AC_MSG_CHECKING(to see if architecture is 64-bit)
+arch_64bit=no
+case "$host_cpu" in
+x86_64) arch_64bit=yes ;;
+esac
+
+if test "$arch_64bit" = yes; then
+  AC_MSG_RESULT(yes)
+  if test -z "$COMPAT32BITFLAGS" ; then
+    COMPAT32BITFLAGS="-m32"
+  fi
+else
+  AC_MSG_RESULT(no)
+  if test -z "$COMPAT32BITFLAGS" ; then
+    COMPAT32BITFLAGS=
+  fi
+fi
+export COMPAT32BITFLAGS
+AC_SUBST(COMPAT32BITFLAGS)
+
+
+#moved CORBA MICO directory test to get version of MICO
+if test $USE_CORBA = 1; then
+
+if test $MICO_DIR = "default"; then
+#do something
+MICO_INC="-I packages/mico/mico/include"
+else
+#build the micotest program
+MICO_INC= ""
+if test $MICO_DIR != yes; then
+MICO_INC="-I $MICO_DIR"
+fi
+fi
+
+#get MICO_VER value
+sh -c "$CC -c micotest.cpp -o micotest.o $MICO_INC 2>&1" > /dev/null
+sh -c "$CC -o micotest micotest.o -lstdc++ 2>&1" > /dev/null
+MICO_VER=`./micotest` || MICO_VER=2.3.5
+sh -c "rm micotest"
+sh -c "rm micotest.o"
+
+#do test of MICO_VER
+if test MICO_VER != 0; then
+AC_DEFINE(MICO_VER)
+AC_SUBST(MICO_VER)
+fi
+#end USE_CORBA test
+fi
+
+dnl Checks for typedefs, structures, and compiler characteristics.
+AC_AIX
+AC_ISC_POSIX
+AC_MINIX
+fp_C_PROTOTYPES
+AC_C_CONST
+AC_TYPE_OFF_T
+AC_TYPE_SIZE_T
+AC_HEADER_TIME
+AC_STRUCT_TM
+
+dnl --- This should be in the stdc checking -----------------
+if test "$ac_cv_prog_cc_stdc" = '-Xc'; then
+dnl The Pyramids running SMP_DC.OSx on MIPS r3000 chips with
+dnl /usr/opt/cc3.11/bin/cc treat -Xc as full ANSI mode - no POSIX or
+dnl XOPEN extensions (like popen).
+dnl Unfortunately -D_{XOPEN,POSIX}_SOURCE can't provide all that mg
+dnl needs. So drop back to -Xa
+AC_TRY_COMPILE(
+[#include <stdio.h>
+], [ FILE *rubbish = popen("yes", "r"); ],,
+[CC="`echo $CC | sed 's/-Xc/-Xa/'`"    ac_cv_prog_cc_stdc='-Xa'])
+fi
+dnl ----------------------
+
+
+dnl Checks for libraries.
+dnl check for -lg:
+AC_HAVE_LIBRARY(g)
+dnl check for -lm:
+AC_HAVE_LIBRARY(m)
+dnl check for -lcrypt:
+AC_HAVE_LIBRARY(crypt)
+if test $ENABLE_ACCENTFOLD = 1; then
+AC_HAVE_LIBRARY(iconv)
+fi
+
+dnl Checks for header files.
+AC_HEADER_DIRENT
+AC_HEADER_STDC
+AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h crypt.h string.h memory.h sys/procfs.h sys/stat.h)
+AC_EGREP_HEADER(fread, stdio.h, AC_DEFINE(HAVE_FREAD_DECL))
+AC_EGREP_HEADER(fgetc, stdio.h, AC_DEFINE(HAVE_FGETC_DECL))
+AC_EGREP_HEADER(pr_brksize, sys/procfs.h, AC_DEFINE(HAVE_PR_BRKSIZE))
+
+dnl Checks for library functions.
+AC_FUNC_ALLOCA
+AC_PROG_GCC_TRADITIONAL
+AC_TYPE_SIGNAL
+AC_FUNC_VPRINTF
+AC_CHECK_FUNCS(ftime select strftime strtol getrusage times mallinfo setbuffer getpagesize strerror)
+AC_REPLACE_FUNCS(ftruncate strstr strcasecmp)
+
+dnl see if gettext is in libc. (try the textdomain() function).
+AC_CHECK_FUNC(textdomain, AC_DEFINE(ENABLE_NLS ,1) )
+
+# *** Custom checking (based on GNU tar configure.in) ***
+# ---------------------------------------------------------------------------
+AC_MSG_CHECKING(for HP-UX needing gmalloc)
+if test "`(uname -s) 2> /dev/null`" = 'HP-UX'; then
+  AC_MSG_RESULT(yes)
+  AC_LIBOBJ([gmalloc])
+  AC_DEFINE(HAVE_VALLOC)
+else
+  AC_MSG_RESULT(no)
+  AC_CHECK_FUNCS(valloc)
+fi
+
+# we cannot generate static libraries under Darwin
+AC_MSG_CHECKING(for Apple MacOS X/Darwin)
+if test "`(uname -s) 2> /dev/null`" = 'Darwin'; then
+  AC_MSG_RESULT(yes)
+  STATIC=""
+else
+  AC_MSG_RESULT(no)
+  STATIC="-static "
+fi
+AC_SUBST(STATIC)
+
+fp_WITH_DMALLOC
+fp_WITH_REGEX
+
+# ---------------------------------------------------------------------------
+if test "$ac_cv_func_alloca" = 'no'; then
+dnl    support functions for alloca.c
+  AC_LIBOBJ([xmalloc])
+  AC_LIBOBJ([error])
+fi
+
+
+# ---------------------------------------------------------------------------
+
+dnl
+dnl Switch into C++
+dnl
+AC_LANG_CPLUSPLUS
+
+dnl
+dnl Check that the GDBM library is available
+dnl
+dnl check libgdbm manually, in case it's not in the standard location.
+
+AC_MSG_CHECKING(that the GDBM library is available)
+if test ! -z "$gdbmdir" ; then
+  # look in given directory for header file
+  if test -r $gdbmdir/include/gdbm.h ; then
+    GDBM_INCLUDE="-I$gdbmdir/include" ;
+  elif test -r $gdbmdir/gdbm.h ; then
+    GDBM_INCLUDE="-I$gdbmdir" ;
+  fi
+
+  # look in given directory for library
+  if test -r $gdbmdir/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir" ;
+  elif test -r $gdbmdir/lib/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir/lib" ;
+  elif test -r $gdbmdir/.libs/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir/.libs" ;
+  fi
+
+  if test ! -z "$GDBM_LIBPATH" -a ! -z "$GDBM_INCLUDE" ; then
+    AC_MSG_RESULT($gdbmdir) ;
+  else
+    AC_MSG_RESULT(can't find gdbm.h and libgdbm.a in $gdbmdir);
+    AC_MSG_CHECKING(   looking for GDBM library in default locations)
+  fi
+fi
+
+# look in default path and in /usr/local
+if test -z "$GDBM_INCLUDE" ; then
+  # try in system directory 
+  AC_TRY_COMPILE(
+  [#include <gdbm.h>
+],
+  [],
+  success=yes,
+  success=no
+  )
+
+  if test $success = "no"; then
+# last chance - look in /usr/local (eg FreeBSD)
+    GDBM_LIBPATH=-L/usr/local/lib
+    GDBM_INCLUDE=-I/usr/local/include
+    ac_save_CXXFLAGS="$CXXFLAGS"
+    ac_save_LIBS="$LIBS"
+      CXXFLAGS="$CXXFLAGS -I/usr/local/include"
+      LIBS="$LIBS -L/usr/local/lib -lgdbm"
+      AC_TRY_LINK(
+  	[#include <gdbm.h>
+#include <stdio.h>
+	],
+  	[printf("%s",gdbm_version);],
+  	success=/usr/local,
+  	success=no
+      )
+      CXXFLAGS=$ac_save_CXXFLAGS
+      LIBS=$ac_save_LIBS
+  fi
+
+  AC_MSG_RESULT($success)
+  if test $success = "no"; then
+  AC_MSG_ERROR(GDBM Library not available - cannot install)
+  fi
+fi
+dnl I don't think anything actually checks this define, but...
+AC_DEFINE(HAVE_LIBGDBM , 1)
+
+AC_SUBST(GDBM_LIBPATH)
+AC_SUBST(GDBM_INCLUDE)
+
+dnl
+dnl Now check that Perl is actually around, and can be found
+dnl
+AC_MSG_CHECKING(that Perl 5 is available)
+success="no"
+pl_path="$PATH"
+IFS="${IFS=   }"; pl_save_ifs="$IFS"; IFS=":"
+for pl_dir in $pl_path; do
+  test -z "$pl_dir" && pl_dir=.
+  if test -x $pl_dir/perl; then
+    success="yes"
+    break
+  fi
+done
+IFS="$pl_save_ifs"
+
+dnl
+dnl Perl actually can be run; now we see if it is version 5 by
+dnl running a sample script (which returns a "clean" version number
+dnl and then tests the result using expr.  If perl errors in some
+dnl way (eg. broken Perl executable, missing script), we set a failure
+dnl value ("0") and then proceed as best we can
+dnl
+if test $success = "yes"; then
+try=`perl configtest.pl` || try="0"
+try=`expr $try \> 5.000`
+if test $try = "1"; then
+AC_MSG_RESULT("yes")
+else
+success="no"
+fi
+fi
+
+if test $success = "no"; then
+AC_MSG_RESULT("no")
+AC_MSG_ERROR("Perl 5 not available - cannot install")
+fi
+
+dnl
+dnl Check if the STL library has any known faults;
+dnl In GCC 2.7.2.x series, some STL library headers are missing
+dnl a file called "new" which is referred to by other headers
+dnl (eg. vector/vector.h); if this applies, then all use of the
+dnl STL will cause a compile fail, so we'd better let the user
+dnl know now, before things really go wrong!
+dnl
+success=no
+AC_MSG_CHECKING("whether STL library has known faults")
+
+dnl - first shot, try simple good old vector on its own
+AC_TRY_COMPILE(
+[#include <vector>
+], 
+[],
+success=yes,
+)
+
+dnl - try using the .h equivalent
+if test $success = "no"; then
+AC_TRY_COMPILE(
+[#include <vector.h>
+], 
+[],
+success="yes",
+)
+fi
+
+dnl - now try for the objectspace headers
+if test $success = "no"; then
+AC_TRY_COMPILE(
+[#include <ospace\\std\\vector>
+], 
+[],
+success="yes",
+)
+fi
+
+if test $success = yes; then
+AC_MSG_RESULT("no")
+else
+AC_MSG_RESULT("yes")
+AC_MSG_ERROR("STL Broken - Obtain newer version of GNU C Compiler")
+fi
+
+gsdlos=`uname | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
+# check for running bash under cygwin
+ if test "`echo $gsdlos | sed 's/cygwin//'`" != "$gsdlos" ;
+ then
+  gsdlos=windows
+ fi
+AC_SUBST(gsdlos)
+
+# check for endianness
+AC_C_BIGENDIAN
+# ---------------------------------------------------------------------------
+if test "$ac_cv_func_alloca" = 'no'; then
+dnl    support functions for alloca.c
+  AC_LIBOBJ([xmalloc.o])
+  AC_LIBOBJ([error])
+fi
+
+# ---------------------------------------------------------------------------
+
+dnl
+dnl Locate all children of the modules folder
+dnl
+moduleDirs=""
+MODULEDIRS=""
+if [ -d modules ] ; then
+  for x in `find modules -mindepth 1 -maxdepth 2`; do
+    if test -d "$x"; then
+      d="$x/Makefile.in"
+      if test -e "$d"; then
+  dnl      echo $d
+        moduleDirs="$moduleDirs $x/Makefile"
+        MODULEDIRS="$MODULEDIRS $x"
+      fi
+    fi
+  done
+  echo "Making $moduleDirs in modules directory"
+  AC_SUBST(MODULEDIRS)
+fi
+
+
+# ---------------------------------------------------------------------------
+AC_CONFIG_SUBDIRS(packages)
+
+# the list of folders in the src folder
+srclist="src/hashfile/Makefile \
+         src/phind/generate/Makefile"
+
+AC_OUTPUT(packages/Makefile Makefile $srclist $moduleDirs)
+
+
Index: /gsdl/trunk/build-src/packages/Makefile
===================================================================
--- /gsdl/trunk/build-src/packages/Makefile	(revision 16571)
+++ /gsdl/trunk/build-src/packages/Makefile	(revision 16571)
@@ -0,0 +1,58 @@
+###########################################################################
+#
+# Makefile -- Makefile for packages included with Greenstone buildtime
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 2000 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+
+# PACKAGEDIRS contains the packages that we want to make and install.  It
+# is assumed that each package will have at least four rules: all, install,
+# clean, and distclean.
+PACKAGEDIRS =	wv/wv-gs rtftohtml/rtftohtml_src pdftohtml/pdftohtml_gs \
+		wget/wget-1.11.4 cpan/XML-Parser-2.34 \
+		xlhtml/xlhtml-0.4.9.0 isis-gdl html-tidy/tidy
+
+
+all:
+	for odir in $(PACKAGEDIRS); do \
+          echo making $@ in $$odir; \
+          (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
+        done
+
+install:
+	for idir in $(PACKAGEDIRS); do \
+          echo installing $$idir; \
+          (cd $$idir && $(MAKE) install) || exit 1; \
+        done
+
+clean:
+	for subdir in $(PACKAGEDIRS); do \
+          echo cleaning $@ in $$subdir; \
+          (cd $$subdir && $(MAKE) clean || exit 0) ; \
+        done
+
+distclean:
+	for subdir in $(PACKAGEDIRS); do \
+          echo cleaning $@ in $$subdir; \
+          (cd $$subdir && $(MAKE) distclean || exit 0) ; \
+        done
Index: /gsdl/trunk/build-src/packages/Makefile.in
===================================================================
--- /gsdl/trunk/build-src/packages/Makefile.in	(revision 16571)
+++ /gsdl/trunk/build-src/packages/Makefile.in	(revision 16571)
@@ -0,0 +1,58 @@
+###########################################################################
+#
+# Makefile -- Makefile for packages included with Greenstone buildtime
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 2000 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+
+# PACKAGEDIRS contains the packages that we want to make and install.  It
+# is assumed that each package will have at least four rules: all, install,
+# clean, and distclean.
+PACKAGEDIRS =	wv/wv-gs rtftohtml/rtftohtml_src pdftohtml/pdftohtml_gs \
+		wget/wget-1.11.4 cpan/XML-Parser-2.34 \
+		xlhtml/xlhtml-0.4.9.0 isis-gdl html-tidy/tidy
+
+
+all:
+	for odir in $(PACKAGEDIRS); do \
+          echo making $@ in $$odir; \
+          (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
+        done
+
+install:
+	for idir in $(PACKAGEDIRS); do \
+          echo installing $$idir; \
+          (cd $$idir && $(MAKE) install) || exit 1; \
+        done
+
+clean:
+	for subdir in $(PACKAGEDIRS); do \
+          echo cleaning $@ in $$subdir; \
+          (cd $$subdir && $(MAKE) clean || exit 0) ; \
+        done
+
+distclean:
+	for subdir in $(PACKAGEDIRS); do \
+          echo cleaning $@ in $$subdir; \
+          (cd $$subdir && $(MAKE) distclean || exit 0) ; \
+        done
Index: /gsdl/trunk/build-src/packages/configure
===================================================================
--- /gsdl/trunk/build-src/packages/configure	(revision 16571)
+++ /gsdl/trunk/build-src/packages/configure	(revision 16571)
@@ -0,0 +1,206 @@
+#! /bin/sh
+
+PACKAGES=`pwd`
+cd ../..
+GSDLHOME=`pwd`
+cd $PACKAGES
+
+GSDLOS=`uname -s |tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+# check for running bash under cygwin
+if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ;
+then
+ GSDLOS=windows
+fi
+
+prefix=""
+bindir=""
+HOSTTARGETFLAGS=""
+
+# only some of the packages can take environment variables as options to 
+# configure 
+# format is VAR=value, e.g "LDFLAGS=-static"
+ENVIRONMENT=""
+
+# SQLite support enabled by default, can switch it off with --disable-sqlite
+USE_SQLITE=true
+# yaz compilation enabled by default, can switch it off with --disable-yaz
+USE_YAZ=true
+# z3950 server disabled by default, switch it on with --enable-z3950
+USE_Z3950=false
+# CORBA support disabled by default, switch it on with --enable-corba
+USE_CORBA=false
+MICO_DIR=default
+
+# parse any arguments given from toplevel configure
+while test $# -ne 0; do
+    case "$1" in
+	--cache-file=*)
+	    cache_filename=`echo $1 | sed s/--cache-file=//`
+	    # turn relative path into an absolute path
+	    cache_dir=`echo $cache_filename | sed 's@/[^/]*$@@'`
+	    cache_dir=`cd $cache_dir 2>/dev/null && pwd`
+
+	    cache_basefile=`echo $cache_filename | sed 's@.*/@@'`
+	    cache_file="$cache_dir/$cache_basefile"
+	    if test ! -f "$cache_file"; then
+		CACHE_FILE=""
+	    else
+		CACHE_FILE="--cache-file=$cache_file"
+	    fi
+	    ;;
+	--disable-sqlite)
+	    USE_SQLITE=false
+	    ;;
+	--disable-yaz)
+	    USE_YAZ=false
+	    ;;
+	--enable-z3950)
+	    USE_Z3950=true
+	    ;;
+	--enable-corba)
+	    USE_CORBA=true
+	    ;;
+	--with-micodir=*)
+	    if test $1 = ""; then
+	      $1 = "default"
+            fi
+	    MICO_DIR=$1
+	    ;;       
+	--prefix=*)
+	    prefix=`echo $1 | sed s/--prefix=//`
+	    ;;
+	--bindir=*)
+	    # where to install binaries to
+	    bindir=`echo $1 | sed s/--bindir=//`
+	    # turn relative path into an absolute path
+	    if test -d "$bindir" ; then
+	      bindir=`cd "$bindir" ; pwd `
+	      cd "$PACKAGES"
+	    elif test -z `echo $bindir | sed '/^\// p;D'` ; then
+	      rel_bindir="`echo $bindir | sed s@/.*@@`"
+	      cd "$rel_bindir"
+	      bindir="`pwd`/`echo $bindir | sed s@^[^/]*/@@`"
+	      cd "$PACKAGES"
+	    else
+	      # bindir doesn't exist, and isn't relative
+	      true
+	    fi
+	    ;;
+	--host=* | --target=*)
+	    HOSTTARGETFLAGS="$HOSTTARGETFLAGS $1"
+	    ;;
+	*)
+	    # ignore all other options for now
+	    ;;
+    esac
+    shift
+done
+
+# note! Our GSDL package currently always installs into it's source
+# directory, ignoring any --prefix given to configure.
+# When this is fixed, uncomment the relevant lines below...
+
+##if test -z "$prefix" ; then
+prefix="${GSDLHOME}"
+##fi
+
+##if test -z "$bindir" ; then
+bindir="${prefix}/bin/$GSDLOS"
+##fi
+
+# This loads the top configure's cache file, with variables already set.
+if test -f "$cache_file" ; then
+  . $cache_file
+fi
+
+# we assume that gzip and tar are on the search path.
+# non-GNU versions of tar don't take the -z option.
+
+
+# configure the wvWare Word document converter
+echo ""
+echo "Configuring wvWare"
+echo ""
+
+cd "$PACKAGES/wv"
+gzip -dc wv-0.7.1-gs.tar.gz | tar -xf -
+# datadir is for default location of wvHtml.xml config file
+cd wv-gs && \
+./configure $CACHE_FILE --prefix=$PACKAGES/wv --bindir="$bindir" --datadir="$prefix/etc/packages" $HOSTTARGETFLAGS
+
+# configure the pdftohtml converter
+echo ""
+echo "Configuring pdftohtml"
+echo ""
+
+cd "$PACKAGES/pdftohtml"
+gzip -dc pdftohtml_0_36_gs.tar.gz | tar -xf -
+cd pdftohtml_gs && \
+./configure $CACHE_FILE --prefix="$prefix" --bindir="$bindir" $HOSTTARGETFLAGS $ENVIRONMENT
+
+# rtftohtml converter
+echo ""
+echo "Configuring rtftohtml"
+echo ""
+
+cd "$PACKAGES/rtftohtml"
+gzip -dc rtftohtml-gs.tar.gz | tar -xf -
+cd rtftohtml_src && \
+./configure $CACHE_FILE --prefix="$prefix" --bindir="$bindir" $HOSTTARGETFLAGS
+
+
+
+# configure wget
+echo ""
+echo "Configuring wget"
+echo ""
+cd "$PACKAGES/wget"
+gzip -dc wget.tar.gz | tar -xf -
+cd "$PACKAGES/wget/wget-1.11.4" && \
+./configure $CACHE_FILE --prefix=$PACKAGES/wget --bindir="$bindir" $HOSTTARGETFLAGS
+
+
+# configure XML::Parser perl module
+echo ""
+echo "Configuring XML::Parser"
+echo ""
+cd "$PACKAGES/cpan"
+perl_dir=`echo 'my $vn = $]; $vn =~ s/5\.00(\d).*$/perl-5.$1/; print "$vn" ' | perl`
+gzip -dc XML-Parser-2.34.tar.gz | tar -xf -
+cd "$PACKAGES/cpan/XML-Parser-2.34" && \
+perl Makefile.PL \
+  PREFIX="$GSDLHOME/perllib/cpan/XML" \
+  INSTALLSITELIB="$GSDLHOME/perllib/cpan/$perl_dir" \
+  INSTALLSITEARCH="$GSDLHOME/perllib/cpan/$perl_dir" \
+  INSTALLMAN1DIR="$GSDLHOME/perllib/cpan/$perl_dir" \
+  INSTALLMAN3DIR="$GSDLHOME/perllib/cpan/$perl_dir" \
+  SITEPREFIX="$GSDLHOME/perllib/cpan" \
+  EXPATINCPATH="$GSDLHOME/packages/expat/include" \
+  EXPATLIBPATH="$GSDLHOME/packages/expat/lib" 
+
+# configure powerpoint converter
+echo ""
+echo "Configuring xlhtml (powerpoint & excel converter)"
+echo ""
+cd "$PACKAGES/xlhtml"
+gzip -dc xlhtml-0.4.9.0-gs.tar.gz | tar -xf -
+cd xlhtml-0.4.9.0 && \
+./configure $CACHE_FILE --prefix="$prefix" --bindir="$bindir" $HOSTTARGETFLAGS
+
+
+# configure IsisGdl program
+echo ""
+echo "Configuring IsisGdl (CDS/ISIS database reader)"
+echo ""
+cd "$PACKAGES/isis-gdl" && \
+./configure $CACHE_FILE --prefix="$prefix" --bindir="$bindir" $HOSTTARGETFLAGS $ENVIRONMENT
+
+# configure HTMLTidy program
+echo ""
+echo "Configuring HTMLTidy"
+echo ""
+cd "$PACKAGES/html-tidy"
+gzip -dc tidy.tgz | tar -xf -
+cd "$PACKAGES/html-tidy/tidy" && \
+./configure $CACHE_FILE --prefix="$prefix" --bindir="$bindir" $HOSTTARGETFLAGS $ENVIRONMENT
+
Index: /gsdl/trunk/build-src/packages/cpan/README
===================================================================
--- /gsdl/trunk/build-src/packages/cpan/README	(revision 16571)
+++ /gsdl/trunk/build-src/packages/cpan/README	(revision 16571)
@@ -0,0 +1,42 @@
+This directory contains perl modules from cpan for use with the Greenstone
+collection building code. After a "make install" these modules will be
+installed to the gsdl/perllib/cpan directory.
+
+Note that pure perl modules (i.e. those not containing any C code to
+compile) don't need building so they don't live in the packages directory
+tree (they live in perllib/cpan).
+
+
+The following modules are currently included:
+
+XML::Parser: Copyright (c) 1998-2000 Larry Wall and Clark Cooper
+ 
+ - Version 2.34
+
+  Originally, we used Version 2.27 cut down a bit for size, plus
+  a few modifications to Makefile.PL.  See below.
+
+
+HISTORY
+-------
+
+Mar 2005
+
+XML::Parser
+
+ - Version 2.34 and version 2.27
+added MAKEFILE_OLD => 'Makefile' to the Makefile.PL WriteMakeFile directive.
+previously, doing a make clean renamed the Makefile to Makefile.old, so then
+a make wouldn't work. Now Makefile gets renamed to Makefile. Hopefully this
+won't stuff anything else up.
+ 
+< Aug 2004
+
+XML::Parser: Copyright (c) 1998-2000 Larry Wall and Clark Cooper
+
+- Version 2.27 - as downloaded from cpan.org but with a few files removed
+  (to minimize the size of the tarball we distribute) and minor Greenstone
+  specific modifications to Makefile.PL. Originally used version 2.29 but
+  it appeared to be incompatible with perl 5.6.1.
+
+
Index: /gsdl/trunk/build-src/packages/html-tidy/readme-tidy.txt
===================================================================
--- /gsdl/trunk/build-src/packages/html-tidy/readme-tidy.txt	(revision 16571)
+++ /gsdl/trunk/build-src/packages/html-tidy/readme-tidy.txt	(revision 16571)
@@ -0,0 +1,10 @@
+This is HTML Tidy, which was based at:
+	http://www.w3.org/People/Raggett/tidy/
+
+It has now been maintained by Source Forge, and is currently based at:
+	http://tidy.sourceforge.net/
+
+We're currently using the source created at 4 August 2000 which is Dave Raggett's latest version of HTML Tidy.
+
+Veronica Liesaputra
+February 2007
Index: /gsdl/trunk/build-src/packages/isis-gdl/AbstractIsisDb.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/AbstractIsisDb.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/AbstractIsisDb.h	(revision 16571)
@@ -0,0 +1,171 @@
+/**********************************************************************
+ *
+ * AbstractIsisDb.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+///////////////////////////////////////////////////////////////////////////////////
+// AbstractIsisDb.h -- Abstract Base Class Definitions for an ISIS db
+//
+//
+// The objective is to provide an interface for creating families of Isis
+// db without specifying their concrete classes. 
+// ABSTRACT FACTORY PATTERN is used.
+//
+// Author: J-C Dauphin, UNESCO, August 2000
+///////////////////////////////////////////////////////////////////////////////////
+ 
+#ifndef __ABSTRACT_ISISDB_H__
+#define __ABSTRACT_ISISDB_H__
+
+#include <vector>
+#include "IsisDef.h"
+#include "mytchar.h"
+
+
+/////////////////////////////////////////////////////////////////////////////////// 
+//   Abstract Base Class, set the DB interface. All db concrete classes must be
+//   derived from this class.
+//
+// Note that this abstract base class can be extended by specifying abstract base
+// classes for class class MfFile, class XrfFile, class CFdtCWorksheet, 
+// class CDisplayFormat, class CFieldSelectTable, class CSortTable, 
+// class MfRecord and struct SMfHeader. Pure virtual methods would then be added
+// in the class AbstractIsisDbFactory:
+//
+// 	virtual AbstractMfFile* makeMfFile() = 0;
+//	virtual AbstractXrfFile* makeXrfFile() = 0;
+//  ................
+ 
+
+class MfFile;
+class XrfFile;
+class CFdt; // Forward 
+
+class CWorksheet;
+class CDisplayFormat;
+class CFieldSelectTable;
+class CSortTable;
+class MfRecord;
+struct SMfHeader;
+ 
+class AbstractIsisDb 
+{
+protected:
+	ustring    	name;
+
+    MfFile*   mf_;   // Has-a master file
+    XrfFile*  xf_;   // Has-a cross ref file
+    CFdt*     fdt_;  // Has-a FDT
+
+    std::vector<CWorksheet*>            apWS_;   // Worksheets
+    std::vector<CDisplayFormat*>        apDFMT_; // Display formats
+    std::vector<CFieldSelectTable*>     apFST_;  // Field Select Tables
+    std::vector<CSortTable*>            apST_;   // Sort Tables   
+    
+public:
+	AbstractIsisDb() { };                    // Trivial default C++ constructor
+	virtual ~AbstractIsisDb() { };           // Trivial C++ destructor
+
+// Opening the database
+   virtual int OpenDb(const TCHAR *fname, FileSystem::AccessMode mode =
+	                                          FileSystem::FILE_READWRITE) = 0; 
+// Creating the database
+   virtual int CreateDb(const TCHAR* fname) = 0;
+
+// Closing the database
+   virtual void CloseDb()   = 0;    // Close the db
+   virtual void ClearDb()   = 0;    // Clear the db
+   virtual void DestroyDb() = 0;    // Delete the db
+
+// Recovery
+   virtual bool IsDamaged() = 0;   // Test if the database is damaged
+   virtual bool Recover()   = 0;   // Recover the db
+
+// Transactions
+   virtual void BeginTransaction()     = 0;   // Begin a transaction
+   virtual void CommitTRansaction()    = 0;   // Commit a transaction
+   virtual void RollbackTransaction()  = 0;   // Rollback a transaction
+   virtual bool InTransaction()        = 0;   // Test if transaction is pending
+
+// (FDT)
+   virtual void SetFdt(CFdt *pFdt) { fdt_ = pFdt; }
+   virtual CFdt* GetFdt() { return fdt_; }
+
+//  worksheets (WORKSHEETS). 
+// (used to create/update the master records of the db)
+   virtual void SetWorksheetAt(int i, CWorksheet* pWS) { apWS_.insert(apWS_.begin()+i, pWS); }
+   virtual CWorksheet* GetWorksheetAt(int i)           { return apWS_[i]; }
+   virtual void RemoveWorksheetAt(int i)               { apWS_.erase(apWS_.begin()+i); }
+
+// display formats (DISPLAY FORMATS).
+// (used for specifying the formatting requirements for either on-line
+// display of records during searching or for the generation of printed
+// output documents.
+   virtual void SetDisplayFormatAt(int i, CDisplayFormat* pDFMT) { apDFMT_.insert(apDFMT_.begin()+i, pDFMT); }
+   virtual CDisplayFormat* GetDisplayFormatAt(int i)             { return apDFMT_[i]; }
+   virtual void RemoveDisplayFormatAt(int i)                     { apDFMT_.erase(apDFMT_.begin()+i); }
+
+// Field Select Table (FST).
+// One FST defines the fields of the database to be made searchable
+// through the inverted dile.
+   virtual void SetFieldSelectTableAt(int i, CFieldSelectTable* pFST) { apFST_.insert(apFST_.begin()+i, pFST); }
+   virtual CFieldSelectTable* GetFieldSelectTableAt(int i)            { return apFST_[i]; }
+   virtual void RemoveFieldSelectTableAt(int i)                       { apFST_.erase(apFST_.begin()+i); }
+
+   virtual void CreateIndex(int i) = 0;
+   virtual void DropIndex(int i)   = 0;
+
+// Sort Select Table (SST).
+// One FST defines the fields of the database to be made searchable
+// through the inverted dile.
+
+   virtual void SetSortTableAt(int i, CSortTable* pST) { apST_.insert(apST_.begin()+i, pST); }
+   virtual CSortTable* GetSortTableAt(int i)           { return apST_[i]; }
+   virtual void RemoveSortTableAt(int i)               { apST_.erase(apST_.begin()+i); }
+
+   virtual void  CreateDbRecord(MfRecord &m) = 0;
+   virtual void  UpdateDbRecord(MfRecord &m) = 0;
+   
+   virtual int   ReadDbRecord(long mfn, MfRecord &m) = 0;
+   virtual int   ReadNextDbRecord(MfRecord &m)       = 0;
+   
+   virtual bool  DeleteRecord(long mfn)              = 0;
+
+   virtual void  PrintDbRecord(MfRecord &m)          = 0;
+   virtual void  PrintDbHdr()                        = 0;
+
+   virtual long GetNextMfn() = 0;
+   virtual long GetNextActiveMfn(long mfn=-1) = 0;
+
+   virtual SMfHeader& GetSMfHeader() = 0;
+   virtual _TCHAR *GetIdxFileName()  = 0;
+ 
+
+};
+ 
+class AbstractIsisDbFactory
+{
+public:
+	virtual AbstractIsisDb* MakeIsisDb() = 0;
+};
+#endif   // __ABSTRACT_ISISDB_H__
Index: /gsdl/trunk/build-src/packages/isis-gdl/BlkFile.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/BlkFile.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/BlkFile.h	(revision 16571)
@@ -0,0 +1,155 @@
+/**********************************************************************
+ *
+ * BlkFile.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+//////////////////////////////////////////////////////////////////////
+//  BLKFILE.H
+//
+//  Class for accessing a file per blocks of blksize bytes, blocks
+//  are sequential from 1 to nblock.
+//                                                                       
+//////////////////////////////////////////////////////////////////////
+ 
+#ifndef _BLKFILE_H_
+#define _BLKFILE_H_
+#include "CacheMan.h"
+#include "File.h"
+ 
+//////////////////////////
+// Block I/O file class
+//
+ 
+ 
+ 
+class BlkFile : public CFileBase
+{
+public:
+   enum { blk_size = 512 };
+protected:
+   unsigned     blkSize_;      // Block Size
+   CacheManager cache_;
+public:
+   BlkFile(int bs=BlkFile::blk_size);
+   BlkFile(const _TCHAR *fname, int bs=BlkFile::blk_size);
+   virtual FileError Close();
+   virtual ~BlkFile();
+   virtual void ReadBlk(void* d, long b);
+   virtual void WriteBlk(void* d, long b);
+   virtual void ReadBlk(void* d);
+   virtual void WriteBlk(void* d);
+
+   void SetBlockSize(int blockSize) { blkSize_ = blockSize; }
+   int  GetBlockSize() { return blkSize_; }
+};
+ 
+////////////////////////////////////////
+ 
+inline BlkFile::BlkFile(int bs) :
+// Makes a Blocked File object that isn't connected to a file
+// Block size is bs
+CFileBase(), blkSize_(bs)
+{
+	cache_.Create(bs, 40);
+	cache_.Connect(this);
+   // Nothing more to do
+}
+ 
+ 
+////////////////////////////////////////
+ 
+inline BlkFile::BlkFile(const _TCHAR *fname, int bs) :
+// Makes a Blocked File object connected to a file
+// Block size is bs
+CFileBase(), blkSize_(bs), cache_(bs, 20)
+{
+	CFileBase::Open(fname, FileSystem::FILE_READWRITE);
+	cache_.Create(bs, 40);
+	cache_.Connect(this);
+   // Nothing more to do
+}
+ 
+////////////////////////////////////////
+ 
+inline BlkFile::~BlkFile()
+// Destructor  for BlkFile object
+{
+	cache_.Disconnect();
+   // Nothing more to do
+}
+ 
+////////////////////////////////////////////
+
+
+inline FileError BlkFile::Close()
+{
+	if (IsOpen())
+	    cache_.Invalidate();
+	return CFileBase::Close();
+}
+////////////////////////////////////////
+ 
+inline void BlkFile::ReadBlk(void* d, long b)
+// Reads block number b into d, b is in range [1:NBLOCK]
+{
+	ASSERT(d!=NULL && b>0);
+	//TRACE("\nBlkFile::ReadBlk -- %s Read Block %ld", file_name, b);
+    //CFileBase::Fetch(d, blkSize_, (b-1)*blkSize_);
+	cache_.Read((b-1)*blkSize_, d);
+}
+ 
+////////////////////////////////////////
+ 
+inline void BlkFile::WriteBlk(void* d, long b)
+// Writes blksize bytes from d at block number b
+{
+	ASSERT(d!=NULL && b>0);
+	//TRACE("\nBlkFile::WriteBlk -- %s Write Block %ld", file_name, b);
+    //CFileBase::Store(d, blkSize_, (b-1)*blkSize_);
+	cache_.Write((b-1)*blkSize_, d);
+}
+ 
+ 
+////////////////////////////////////////
+ 
+inline void BlkFile::ReadBlk(void* d)
+// Reads block at current address into d
+{
+	ASSERT(d!=NULL);
+    //CFileBase::Fetch(d, blkSize_);
+	long addr = CFileBase::FilePosition();
+	cache_.Read(addr, d);
+}
+ 
+////////////////////////////////////////
+ 
+inline void BlkFile::WriteBlk(void* d)
+// Writes blkSize_ bytes from d at current address
+{
+	ASSERT(d!=NULL);
+    //CFileBase::Store(d, blkSize_);
+	long addr = CFileBase::FilePosition();
+	cache_.Write(addr, d);
+}
+ 
+#endif
Index: /gsdl/trunk/build-src/packages/isis-gdl/CRC32.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/CRC32.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/CRC32.cpp	(revision 16571)
@@ -0,0 +1,170 @@
+/**********************************************************************
+ *
+ * CRC32.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////////////////////////////
+// CRC32.cpp --
+//  
+// The CRC32 functions (Cyclic Redundancy Check) are used to
+// calculate a sophisticated checksum based on the algebra of
+// polynomials. The Cyclic Redundancy Check, is a way to detect
+// bit errors that occur during data storage or transmission.
+// The CRC-32 algorithm operates on a block of data as a single
+// large numerical value. The algorithm divides this large value
+// by the CRC-32 polynomial or generator polynomial, leaving the
+// remainder 32-bit, which is the checksum. 
+//
+// #include "stdafx.h" 
+#include <iomanip>
+#include "CRC32.h"
+#include "CRCTab.h"
+
+unsigned long CalcCRC32(const char *buf, unsigned len)
+// Calculate a 32-bit CRC for a raw pattern of bytes.
+// Returns a 32-bit checksum.
+{
+ unsigned long CRC=0xffffffffL;
+ unsigned int n = len;
+
+ while(n--) 
+   CRC=crc32tab[(CRC ^ (*buf++)) & 0xFF] ^ ((CRC>>8) & 0x00ffffffL);
+
+ return CRC ^ 0xffffffffL;
+}
+
+unsigned long CalcCRC32(char *buf, unsigned len)
+// Calculate a 32-bit CRC for a raw pattern of bytes.
+// Returns a 32-bit checksum.
+{
+ unsigned long CRC=0xffffffffL;
+ unsigned int n = len;
+ char *p = (char *)buf;
+ while(n--) 
+   CRC=crc32tab[(CRC ^ (*p++)) & 0xFF] ^ ((CRC>>8) & 0x00ffffffL);
+
+ return CRC ^ 0xffffffffL;
+}
+
+unsigned long CalcCRC32(unsigned char c, unsigned long CRC)
+// Calculate a 32-bit CRC table value for a single byte.
+// NOTE: The initial CRC value must be set to 0xffffffffL
+// and the final 32-bit value that must be XOR'ed with
+// 0xffffffffL to obtain the checksum.
+{
+  unsigned int i;
+  i = (unsigned int)c;
+  i &= 0xFF; // Reset all the bits
+  CRC=crc32tab[(CRC ^ i) & 0xFF] ^ ((CRC>>8) & 0x00ffffffL);
+  return CRC;
+}
+
+unsigned long CalcCRC32(std::fstream &infile)
+// Calculate a 32-bit CRC for a file. Assumes the stream
+// is already open. Returns a 32-bit checksum.
+{
+ unsigned long CRC=0xffffffffL;
+#ifdef _WIN32
+ char c;
+#else
+ unsigned char c;
+#endif
+ unsigned int i;
+
+ // Rewind to the start of the stream
+ infile.clear(); 
+ infile.seekg(0, std::ios::beg);
+ infile.seekp(0, std::ios::beg);
+
+ while(!infile.eof()) {
+   c=infile.get();
+   i = (unsigned int)c;
+   i &= 0xFF; // Reset all the bits
+   if(infile.eof()) break;
+   CRC=crc32tab[(CRC ^ i) & 0xFF] ^ ((CRC>>8) & 0x00ffffffL);
+ }
+ return CRC ^ 0xffffffffL;
+}
+
+#ifdef __USE_CRC32_TABLE_FUNCTIONS__
+int MakeCRC32(ostream &stream)
+// Write a CRC 32 table for a byte-wise 32-bit CRC calculation
+// based on the Autodin/Ethernet/ADCCP polynomial of 0x4C11DB7:
+// 0000 0100 1100 0001 0001 1101 1011 0111 (binary) or a poly of
+// x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7 +x^5+x^4+x^2+x^1+x^0
+// In this representation the coefficient of x^0 is stored in the 
+// MSB of the 32-bit word and the coefficient of x^31 is stored in 
+// the LSB. Thus 0x4C11DB7 becomes 0xEDB88320:
+// 1110 1101 1011 1000 1000 0011 0010 0000 (binary)
+
+// Adding the polynomials is performed using an exclusive-or, and
+// multiplying a polynomial by x is a right shift by one. If the 
+// polynomial is called "p", and each byte is represented as polynomial
+// "q", with the lowest power in the most significant bit (so the byte
+// 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) 
+// mod "p", where "a" mod "b" means the remainder after dividing "a" by
+// "b". This calculation is done using the shift-register method of
+// multiplying and taking the remainder. The register is initialized
+// to zero, and for each incoming bit, x^32 is added mod "p" to the
+// register if the bit is a one (where x^32 mod p is p+x^32 = x^26+...+1),
+// and the register is multiplied mod "p" by "x" (which is shifting right
+// by one and adding x^32 mod "p" if the bit shifted out is a one.) This
+// algorithm starts with the highest power (least significant bit) of "q"
+// and repeats for all eight bits of "q".
+{
+  unsigned long c; // CRC shift register 
+  unsigned long e; // Polynomial exclusive-or pattern 
+  int i;           // Counter for all possible eight bit values 
+  int k;           // Byte being shifted into crc apparatus 
+
+  // Terms of polynomial defining this crc (except x^32): 
+  static const int p[14] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
+
+  // Make exclusive-or pattern from polynomial 
+  e = 0;
+  for (i = 0; i < sizeof(p)/sizeof(int); i++)
+    e |= 1L << (31 - p[i]);
+
+  // Compute and print table of CRC's, five per line 
+  stream << endl;
+  stream << "  0x00000000U";
+  for (i = 1; i < 256; i++)
+  {
+    c = 0;
+    for (k = i | 256; k != 1; k >>= 1)
+    {
+      c = c & 1 ? (c >> 1) ^ e : c >> 1;
+      if (k & 1)
+        c ^= e;
+    }
+
+    if(i % 5)
+      stream << ", 0x" << setfill('0') << setw(8) << hex << c << "U";
+    else
+      stream << "," << endl << "  0x" << setfill('0') << setw(8) << hex
+	     << c << "U";
+  }
+  stream << endl;
+  return 1;
+}
+#endif // __USE_CRC32_TABLE_FUNCTIONS__
Index: /gsdl/trunk/build-src/packages/isis-gdl/CRC32.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/CRC32.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/CRC32.h	(revision 16571)
@@ -0,0 +1,52 @@
+/**********************************************************************
+ *
+ * CRC32.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////////////////////////////
+// CRC32.H
+//
+// The CRC32 functions (Cyclic Redundancy Check) are used to
+// calculate a sophisticated checksum based on the algebra of
+// polynomials. The Cyclic Redundancy Check, is a way to detect
+// bit errors that occur during data storage or transmission.
+// The CRC-32 algorithm operates on a block of data as a single
+// large numerical value. The algorithm divides this large value
+// by the CRC-32 polynomial or generator polynomial, leaving the
+// remainder 32-bit, which is the checksum. 
+#ifndef __CRC32_H__
+#define __CRC32_H__
+
+#include <fstream>
+
+unsigned long CalcCRC32(char *buf, unsigned len);
+unsigned long CalcCRC32(const char *buf, unsigned len);
+unsigned long CalcCRC32(unsigned char c, unsigned long CRC);
+unsigned long CalcCRC32(std::fstream &infile);
+
+#ifdef __USE_CRC32_TABLE_FUNCTIONS__
+#include <iostream>
+int makeCRC32(std::ostream &stream);
+#endif
+
+#endif  // __CRC32_H__
Index: /gsdl/trunk/build-src/packages/isis-gdl/CRCTab.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/CRCTab.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/CRCTab.h	(revision 16571)
@@ -0,0 +1,100 @@
+/**********************************************************************
+ *
+ * CRCTab.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////////////////////////////
+// CRCTAB.H --
+
+// CRC 32 table of all possible single-byte values. The table is
+// the CRC of all possible eight bit values. This is all the info
+// needed to generate 32-bit CRC's on data one a byte at a time 
+// for all combinations of CRC register values and incoming bytes.   
+// This table was generated with the makeCRC32() function. It is
+// based on the Autodin/Ethernet/ADCCP polynomial of 0x4C11DB7:
+// 0000 0100 1100 0001 0001 1101 1011 0111 (binary) or a poly of
+// x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7 +x^5+x^4+x^2+x^1+x^0
+// In this representation the coefficient of x^0 is stored in the 
+// MSB of the 32-bit word and the coefficient of x^31 is stored in 
+// the LSB. Thus 0x4C11DB7 becomes 0xEDB88320:
+// 1110 1101 1011 1000 1000 0011 0010 0000 (binary)
+
+#ifndef __CRC32_TABLE_HPP__
+#define __CRC32_TABLE_HPP__
+
+const unsigned long crc32tab[256] = {
+  0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U,
+  0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U,
+  0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U,
+  0x90bf1d91U, 0x1db71064U, 0x6ab020f2U, 0xf3b97148U, 0x84be41deU,
+  0x1adad47dU, 0x6ddde4ebU, 0xf4d4b551U, 0x83d385c7U, 0x136c9856U,
+  0x646ba8c0U, 0xfd62f97aU, 0x8a65c9ecU, 0x14015c4fU, 0x63066cd9U,
+  0xfa0f3d63U, 0x8d080df5U, 0x3b6e20c8U, 0x4c69105eU, 0xd56041e4U,
+  0xa2677172U, 0x3c03e4d1U, 0x4b04d447U, 0xd20d85fdU, 0xa50ab56bU,
+  0x35b5a8faU, 0x42b2986cU, 0xdbbbc9d6U, 0xacbcf940U, 0x32d86ce3U,
+  0x45df5c75U, 0xdcd60dcfU, 0xabd13d59U, 0x26d930acU, 0x51de003aU,
+  0xc8d75180U, 0xbfd06116U, 0x21b4f4b5U, 0x56b3c423U, 0xcfba9599U,
+  0xb8bda50fU, 0x2802b89eU, 0x5f058808U, 0xc60cd9b2U, 0xb10be924U,
+  0x2f6f7c87U, 0x58684c11U, 0xc1611dabU, 0xb6662d3dU, 0x76dc4190U,
+  0x01db7106U, 0x98d220bcU, 0xefd5102aU, 0x71b18589U, 0x06b6b51fU,
+  0x9fbfe4a5U, 0xe8b8d433U, 0x7807c9a2U, 0x0f00f934U, 0x9609a88eU,
+  0xe10e9818U, 0x7f6a0dbbU, 0x086d3d2dU, 0x91646c97U, 0xe6635c01U,
+  0x6b6b51f4U, 0x1c6c6162U, 0x856530d8U, 0xf262004eU, 0x6c0695edU,
+  0x1b01a57bU, 0x8208f4c1U, 0xf50fc457U, 0x65b0d9c6U, 0x12b7e950U,
+  0x8bbeb8eaU, 0xfcb9887cU, 0x62dd1ddfU, 0x15da2d49U, 0x8cd37cf3U,
+  0xfbd44c65U, 0x4db26158U, 0x3ab551ceU, 0xa3bc0074U, 0xd4bb30e2U,
+  0x4adfa541U, 0x3dd895d7U, 0xa4d1c46dU, 0xd3d6f4fbU, 0x4369e96aU,
+  0x346ed9fcU, 0xad678846U, 0xda60b8d0U, 0x44042d73U, 0x33031de5U,
+  0xaa0a4c5fU, 0xdd0d7cc9U, 0x5005713cU, 0x270241aaU, 0xbe0b1010U,
+  0xc90c2086U, 0x5768b525U, 0x206f85b3U, 0xb966d409U, 0xce61e49fU,
+  0x5edef90eU, 0x29d9c998U, 0xb0d09822U, 0xc7d7a8b4U, 0x59b33d17U,
+  0x2eb40d81U, 0xb7bd5c3bU, 0xc0ba6cadU, 0xedb88320U, 0x9abfb3b6U,
+  0x03b6e20cU, 0x74b1d29aU, 0xead54739U, 0x9dd277afU, 0x04db2615U,
+  0x73dc1683U, 0xe3630b12U, 0x94643b84U, 0x0d6d6a3eU, 0x7a6a5aa8U,
+  0xe40ecf0bU, 0x9309ff9dU, 0x0a00ae27U, 0x7d079eb1U, 0xf00f9344U,
+  0x8708a3d2U, 0x1e01f268U, 0x6906c2feU, 0xf762575dU, 0x806567cbU,
+  0x196c3671U, 0x6e6b06e7U, 0xfed41b76U, 0x89d32be0U, 0x10da7a5aU,
+  0x67dd4accU, 0xf9b9df6fU, 0x8ebeeff9U, 0x17b7be43U, 0x60b08ed5U,
+  0xd6d6a3e8U, 0xa1d1937eU, 0x38d8c2c4U, 0x4fdff252U, 0xd1bb67f1U,
+  0xa6bc5767U, 0x3fb506ddU, 0x48b2364bU, 0xd80d2bdaU, 0xaf0a1b4cU,
+  0x36034af6U, 0x41047a60U, 0xdf60efc3U, 0xa867df55U, 0x316e8eefU,
+  0x4669be79U, 0xcb61b38cU, 0xbc66831aU, 0x256fd2a0U, 0x5268e236U,
+  0xcc0c7795U, 0xbb0b4703U, 0x220216b9U, 0x5505262fU, 0xc5ba3bbeU,
+  0xb2bd0b28U, 0x2bb45a92U, 0x5cb36a04U, 0xc2d7ffa7U, 0xb5d0cf31U,
+  0x2cd99e8bU, 0x5bdeae1dU, 0x9b64c2b0U, 0xec63f226U, 0x756aa39cU,
+  0x026d930aU, 0x9c0906a9U, 0xeb0e363fU, 0x72076785U, 0x05005713U,
+  0x95bf4a82U, 0xe2b87a14U, 0x7bb12baeU, 0x0cb61b38U, 0x92d28e9bU,
+  0xe5d5be0dU, 0x7cdcefb7U, 0x0bdbdf21U, 0x86d3d2d4U, 0xf1d4e242U,
+  0x68ddb3f8U, 0x1fda836eU, 0x81be16cdU, 0xf6b9265bU, 0x6fb077e1U,
+  0x18b74777U, 0x88085ae6U, 0xff0f6a70U, 0x66063bcaU, 0x11010b5cU,
+  0x8f659effU, 0xf862ae69U, 0x616bffd3U, 0x166ccf45U, 0xa00ae278U,
+  0xd70dd2eeU, 0x4e048354U, 0x3903b3c2U, 0xa7672661U, 0xd06016f7U,
+  0x4969474dU, 0x3e6e77dbU, 0xaed16a4aU, 0xd9d65adcU, 0x40df0b66U,
+  0x37d83bf0U, 0xa9bcae53U, 0xdebb9ec5U, 0x47b2cf7fU, 0x30b5ffe9U,
+  0xbdbdf21cU, 0xcabac28aU, 0x53b39330U, 0x24b4a3a6U, 0xbad03605U,
+  0xcdd70693U, 0x54de5729U, 0x23d967bfU, 0xb3667a2eU, 0xc4614ab8U,
+  0x5d681b02U, 0x2a6f2b94U, 0xb40bbe37U, 0xc30c8ea1U, 0x5a05df1bU,
+  0x2d02ef8dU
+};
+
+#endif // __CRC32_TABLE_HPP__
Index: /gsdl/trunk/build-src/packages/isis-gdl/CacheMan.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/CacheMan.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/CacheMan.cpp	(revision 16571)
@@ -0,0 +1,213 @@
+/**********************************************************************
+ *
+ * CacheMan.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#include "stdafx.h"
+#include "File.h"
+
+#include "CacheMan.h"
+
+
+CacheManager::CacheManager()
+{
+	maxblocks_ = 0;
+}
+CacheManager::CacheManager(unsigned blocksz, unsigned mxblks)
+{
+	PRECONDITION(maxblocks_ == 0);
+	maxblocks_ = mxblks;
+	nused_     = 0;
+	blocksize_ = blocksz;
+	buff_      = new char[blocksize_*maxblocks_];
+	diskAddrs_ = new FileSystem::FAU_t[maxblocks_];
+	useCounts_ = new unsigned[maxblocks_];
+	theFile_   = NULL;
+}
+/*
+ * Construct a cache manager for blocks of size blocksz and mxblks buffers
+ */
+void CacheManager::Create(unsigned blocksz, unsigned mxblks)
+{
+	PRECONDITION(maxblocks_ == 0);
+	maxblocks_ = mxblks;
+	nused_     = 0;
+	blocksize_ = blocksz;
+	buff_      = new char[blocksize_*maxblocks_];
+	diskAddrs_ = new FileSystem::FAU_t[maxblocks_];
+	useCounts_ = new unsigned[maxblocks_];
+	theFile_   = NULL;
+}
+
+//
+// Connect to a CFileBase
+//
+void CacheManager::Connect(CFileBase* file)
+{
+	PRECONDITION(nused_ == 0);
+	theFile_   = file;
+}
+//
+// Disconnect the cache from the CFileBase
+//
+void CacheManager::Disconnect()
+{
+	if (theFile_)
+	{
+		if (theFile_->IsOpen())
+		    Flush();
+	}
+	theFile_   = NULL;
+}
+
+void CacheManager::Erase()
+{
+	Disconnect();
+	delete[] useCounts_;
+	delete[] diskAddrs_;
+	delete[] buff_;
+	maxblocks_ = 0;
+}
+
+
+CacheManager::~CacheManager()
+{
+	Disconnect();
+	delete[] useCounts_;
+	delete[] diskAddrs_;
+	delete[] buff_;
+}
+
+bool CacheManager::Flush()
+{
+	PRECONDITION(theFile_ != NULL && theFile_->IsOpen());
+	// Because we use "write through", this is all that's necessary:
+	if (theFile_->Flush() == FILE_NO_ERROR)
+		return true;
+	return false;
+}
+
+void CacheManager::Invalidate()
+{
+	nused_ = 0;
+}
+
+bool CacheManager::Read(FileSystem::FAU_t locn, void* dat)
+{
+	PRECONDITION(dat != NULL);
+	size_t islot = AgeAndFindSlot(locn);
+	
+	if (islot == INVALID_NPOS)
+	{
+        // Not in buffer;  we'll have to read it in from disk.
+	    // Get a free slot.
+		if ((islot = GetFreeSlot()) == INVALID_NPOS)
+			return false;
+		diskAddrs_[islot] = locn;
+		if (!(theFile_->SeekTo(locn) == locn) || 
+			!(theFile_->Fetch(buff_ + islot*blocksize_, blocksize_) == FILE_NO_ERROR))
+			return false;
+	}
+	useCounts_[islot] = 0;
+	memcpy(dat, buff_ + islot*blocksize_, blocksize_);
+	return true;
+}
+
+bool CacheManager::Write(FileSystem::FAU_t locn, void* dat)
+{
+	PRECONDITION(dat != NULL);
+	PRECONDITION(theFile_->ReadyForWriting());
+	size_t islot = AgeAndFindSlot(locn);
+	
+	if (islot == INVALID_NPOS)
+	{
+        // Not in buffer; find a free slot.
+		if ((islot = GetFreeSlot()) == INVALID_NPOS)
+			return false;
+		diskAddrs_[islot] = locn;
+	}
+	
+	useCounts_[islot] = 0;
+	memcpy(buff_ + islot*blocksize_, dat, blocksize_);
+	if ((theFile_->SeekTo(locn) == locn) &&
+		(theFile_->Store(buff_ + islot*blocksize_, blocksize_) == FILE_NO_ERROR))
+		return true;
+	return false;
+}
+
+//////////////////////////////////////////////////////////////////////////////////
+// Private helper functions	
+
+size_t CacheManager::AgeAndFindSlot(FileSystem::FAU_t locn)
+{
+	size_t islot = INVALID_NPOS;
+	for (register unsigned i = 0; i < nused_; i++)
+	{
+		if (diskAddrs_[i] == locn)
+			islot = i;
+		useCounts_[i]++;		// Age the blocks
+	}
+	return islot;
+}
+
+bool CacheManager::Flush(unsigned)
+{
+	if (theFile_->Flush() == FILE_NO_ERROR)
+		return true;
+	return false;
+}
+
+size_t CacheManager::GetFreeSlot()
+{
+	size_t islot;
+	
+	if (nused_ < maxblocks_)
+	{
+		islot = nused_++;		// Found an unused slot.
+	}
+	else 
+	{
+		// No free slots; get the Least Recently Used block
+		islot = LRU();
+
+		if (theFile_->ReadyForWriting())
+			if (!Flush(islot))
+			    islot = INVALID_NPOS;
+	}
+	return islot;
+}
+
+size_t CacheManager::LRU() const
+{
+	size_t islot = 0;
+	unsigned maxCount = useCounts_[0];
+	for (register unsigned i = 1; i < nused_; i++)
+	{
+		if (useCounts_[i] > maxCount)
+		{
+			maxCount = useCounts_[islot = i]; 
+		}
+	}
+	return islot;
+}
Index: /gsdl/trunk/build-src/packages/isis-gdl/CacheMan.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/CacheMan.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/CacheMan.h	(revision 16571)
@@ -0,0 +1,71 @@
+/**********************************************************************
+ *
+ * CacheMan.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef __CACHEMAN_H__
+#define __CACHEMAN_H__
+
+
+#include "File.h"
+
+class CacheManager
+{
+private:
+	
+	CFileBase*	       theFile_;
+	unsigned		   maxblocks_;  // Max # blocks in buff_er
+	unsigned		   nused_;	    // Number being used.
+	unsigned		   blocksize_;  // Size of a block
+	FileSystem::FAU_t* diskAddrs_;  // Its disk address
+	unsigned*		   useCounts_;  // Use count for the block
+	char*			   buff_;	    // The set of blocks.
+	
+public:
+	
+	CacheManager();
+	CacheManager(unsigned blocksz, unsigned mxblks);
+
+	~CacheManager();
+	
+	void        Create(unsigned blocksz, unsigned mxblks = 10);
+	void        Erase();
+	
+	void        Connect(CFileBase* file);
+	void        Disconnect();
+	bool  		Flush();	        // Perform any pending writes.
+	void		Invalidate();	    // Invalidate the entire cache
+	bool  		Read (FileSystem::FAU_t locn, void* dat);
+	bool  		Write(FileSystem::FAU_t locn, void* dat);
+	
+private:
+	
+	CacheManager(const CacheManager&);          // Private to insure no copies
+	void		operator=(const CacheManager&); // Ditto
+	size_t		AgeAndFindSlot(FileSystem::FAU_t);
+	bool  		Flush(unsigned);
+	size_t		GetFreeSlot();
+	size_t		LRU() const; // Find least recently used block
+};
+
+#endif
Index: /gsdl/trunk/build-src/packages/isis-gdl/Checking.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Checking.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Checking.cpp	(revision 16571)
@@ -0,0 +1,65 @@
+/**********************************************************************
+ *
+ * Checking.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////
+// Checking -- 
+//               
+
+
+#include "stdafx.h"
+#include "File.h"
+#include "Master.h"
+#include "MFFile.h"
+#include "Checking.h"
+
+using namespace Checking;
+//---------------------------------------------------------------------
+// Checking::CheckMfHeader(const char *mfname, SMfHeader *mfh)
+//
+// Invariant to be respected by the mf header
+//---------------------------------------------------------------------
+void Checking::CheckMfHeader(const _TCHAR *mfname, SMfHeader &mfh)
+{
+	long size = FileSystem::FileSize(mfname);
+	TRACE(_T("\nsize=%ld "), size);
+	long mfSize = mfh.nxtmfb_ * MFBLKSIZE;
+	//ASSERT(size == mfSize);
+	ASSERT(mfh.nxtmfp_>0 && mfh.nxtmfp_<=MFBLKSIZE);
+	ASSERT(mfh.mftype_ == USERMST);
+	ASSERT(mfh.nxtmfn_>0);
+	ASSERT(mfh.ctlmfn_ == 0);
+	//assert(mfh.reccnt == 0);
+	//assert(mfh.mfcxx1 == 0);
+	//assert(mfh.mfcxx2 == 0);
+	//assert(mfh.mfcxx3 == 0);
+}
+
+void Checking::CheckMfRecordHeader(long addr)
+{
+
+}
+
+using namespace std;
Index: /gsdl/trunk/build-src/packages/isis-gdl/Checking.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Checking.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Checking.h	(revision 16571)
@@ -0,0 +1,34 @@
+/**********************************************************************
+ *
+ * Checking.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/////////////////////////////////////////////////////////////////////////////////
+// Checking.h --
+
+
+namespace Checking {
+   void CheckMfHeader(const _TCHAR *mfname, SMfHeader &mfh);
+   void CheckMfRecordHeader(long addr);
+
+}
Index: /gsdl/trunk/build-src/packages/isis-gdl/Compat.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Compat.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Compat.h	(revision 16571)
@@ -0,0 +1,140 @@
+/**********************************************************************
+ *
+ * Compat.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef _WIN32
+
+#include <string>
+#include <algorithm>
+#include <iostream>
+#include <sstream>
+#include <stdio.h>
+#include <sys/stat.h>
+
+#define TCHAR  char
+#define BOOL   bool
+#define WORD   unsigned short
+#define DWORD  unsigned long
+#define INT32  int
+#define UINT32 unsigned int
+#define LONG   long int
+#define TRUE   true
+#define FALSE  false
+
+#define _MAX_PATH 512
+// #define SHRT_MAX  32732
+
+/* Formatted i/o */
+
+#define _tprintf    printf
+#define _ftprintf   fprintf
+#define _stprintf   sprintf
+#define _sntprintf  _snprintf
+#define _vtprintf   vprintf
+#define _vftprintf  vfprintf
+#define _vstprintf  vsprintf
+#define _vsntprintf _vsnprintf
+#define _tscanf     scanf
+#define _ftscanf    fscanf
+#define _stscanf    sscanf
+/* String conversion functions */
+
+#define _tcstod     strtod
+#define _tcstol     strtol
+#define _tcstoul    strtoul
+
+#define _itot       _itoa
+#define _ltot       _ltoa
+#define _ultot      _ultoa
+#define _ttoi       atoi
+#define _ttol       atol
+
+#define _ttoi64     _atoi64
+#define _i64tot     _i64toa
+#define _ui64tot    _ui64toa
+/* String functions */
+
+/* Note that _mbscat, _mbscpy and _mbsdup are functionally equivalent to 
+   strcat, strcpy and strdup, respectively. */
+
+#define _tcscat     strcat
+#define _tcscpy     strcpy
+#define _tcsdup     _strdup
+
+#define _tcslen     strlen
+#define _tcsxfrm    strxfrm
+
+
+// #define assert
+#define ASSERT
+#define AssertFailed
+
+// #define _T(par) par
+#define LPCTSTR const char *
+#define LPTSTR char *
+#define FAR
+#define TRACE
+#define PRECONDITION
+#define SIZE_T size_t
+
+
+
+#endif
+#define MoveMemory memmove
+#define ZeroMemory(p,size) memset(p,0,size)
+
+
+inline void fix_endianness(short int& x)
+{
+#if !defined(LITTLE_ENDIAN)
+  if (x < 0) {
+    unsigned short int ux = (unsigned short int) x;
+    x = (ux>>8) | 
+        (ux<<8);
+  }
+  else {
+    x = (x>>8) | 
+        (x<<8);
+  }
+#endif
+}
+
+inline void fix_endianness(long int& x)
+{
+#if !defined(LITTLE_ENDIAN)
+  if (x < 0) {
+    unsigned long ux = (unsigned long) x;
+    x = (ux>>24) | 
+      ((ux<<8) & 0x00FF0000) |
+      ((ux>>8) & 0x0000FF00) |
+      (ux<<24);
+  }
+  else {
+    x = (x>>24) | 
+      ((x<<8) & 0x00FF0000) |
+      ((x>>8) & 0x0000FF00) |
+      (x<<24);
+  }
+#endif
+}
Index: /gsdl/trunk/build-src/packages/isis-gdl/DLLCode.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/DLLCode.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/DLLCode.h	(revision 16571)
@@ -0,0 +1,74 @@
+/**********************************************************************
+ *
+ * DLLCode.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/////////////////////////////////////////////////////////////////////////////
+// DLLCODE.H - include file used by all platforms to define macros required 
+//             to build static and dynamic libraries.
+//             The DLLCODE.H file is included in every include file extending
+//             the visibility of the macros defined here to the every source
+//             code file. 
+
+
+#ifndef __DLL_CODE_H__
+#define __DLL_CODE_H__
+
+#if defined (__MSVC_DLL__) // Defines the entry point for the DLL application
+//--------------------------------------------------------------------------
+// The following ifdef block is the standard way of creating macros which 
+// make exporting from a DLL simpler. All files within this DLL are compiled 
+// with the DLL_CODE_EXPORTS  symbol defined on the command line. This 
+// symbol should not be defined on any project that uses this DLL. This way 
+// any other project whose source files include this file see DLL_CODE_API 
+// functions as being imported from a DLL, whereas this DLL sees symbols
+// defined with this macro as being exported.
+//---------------------------------------------------------------------------
+#ifdef DLL_CODE_EXPORTS
+#define DLL_CODE_API __declspec(dllexport)
+#else
+#define DLL_CODE_API __declspec(dllimport)
+#endif
+#else // Macro used for non DLL code
+#define DLL_CODE_API
+#endif // __MSVC_DLL__
+
+// Force ANSI compatibility for Visual C++ .NET
+#if defined (__MSDEVNET__) && !defined (__USE_ANSI_CPP__)
+#define __USE_ANSI_CPP__
+#endif // __MSDEVNET__
+
+// Force ANSI compatibility for BCC32
+#if defined (__BCC32__) && !defined (__USE_ANSI_CPP__)
+#define __USE_ANSI_CPP__
+#endif // __BCC32__
+
+#if defined (__USE_ANSI_CPP__)
+// Macro used to define the std name space used by the ANSI 
+// Standard C++ library.
+#define GXSTD std
+#else // Use the old Standard C++ library by default  
+#define GXSTD
+#endif // __USE_ANSI_CPP__
+
+#endif // __DLL_CODE_H__
Index: /gsdl/trunk/build-src/packages/isis-gdl/Debug.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Debug.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Debug.cpp	(revision 16571)
@@ -0,0 +1,213 @@
+#include "stdafx.h"
+#include "Debug.h"
+
+//---------------------------------------------------------------
+//
+// AssertFailed
+//
+//---------------------------------------------------------------
+#if DEBUG || ASSERTS_THROW
+void AssertFailed(const char* expr, const char* file, int line)
+{
+	/*
+	_TCHAR mesg[512];							
+
+	const char* fileName = file + strlen(file);		// strip off path
+	while (fileName > file && fileName[-1] != '\\')
+		--fileName;
+
+	_stprintf(mesg, _T("ASSERT(%s) in '%s' at line %d failed."), expr, fileName, line);
+	
+	MSG msg;							// remove pending quit messages so the message box displays
+	bool quitting = (bool) ::PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE);
+
+	UINT32 flags = MB_OK +				// just an OK button
+				   MB_ICONERROR +		// display the icon for errors
+				   MB_DEFBUTTON1 +		// select the OK button
+				   MB_TASKMODAL +		// don't let the user do anything else in the app
+				   MB_SETFOREGROUND;	// bring the app to the front
+
+	(void) MessageBox(NULL, mesg, NULL, flags);
+//#if DEBUG
+//	if (gBreakOnAssert)
+//		BreakStrToDebugger(mesg);
+//#endif
+
+//#if ASSERTS_THROW
+	CString text = L"Internal (Assert) Error: ";
+	AfxThrowUserException( ); 
+//#endif
+*/
+}
+#endif	// DEBUG || ASSERTS_THROW
+
+
+//---------------------------------------------------------------
+//
+// RequireFailed
+//
+//---------------------------------------------------------------
+#if !DEBUG
+void RequireFailed(const char* expr, const char* file, int line)
+{
+	/*
+	char mesg[512];							
+
+	const char* fileName = file + strlen(file);		// strip off path
+	while (fileName > file && fileName[-1] != '\\')
+		--fileName;
+
+	sprintf(mesg, "There has been a fatal error in '%s' at line %d.", fileName, line);
+
+	MSG msg;							// remove pending quit messages so the message box displays
+	bool quitting = (bool) ::PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE);
+
+	UINT32 flags = MB_OK +				// just an OK button
+				   MB_ICONERROR +		// display the icon for errors
+				   MB_DEFBUTTON1 +		// select the OK button
+				   MB_TASKMODAL +		// don't let the user do anything else in the app
+				   MB_SETFOREGROUND;	// bring the app to the front
+
+	(void) MessageBox(NULL, mesg, NULL, flags);
+
+	abort();
+	*/
+}
+#endif // !DEBUG
+
+//---------------------------------------------------------------
+//
+// ToStr (bool)
+//
+//---------------------------------------------------------------
+std::wstring ToStr(bool value)
+{
+	return value ? L"true" : L"false";
+}
+
+
+//---------------------------------------------------------------
+//
+// ToStr (char)
+//
+//---------------------------------------------------------------
+std::wstring ToStr(char value)
+{
+	wchar_t str[32];							
+	::swprintf(str, L"%c", value);
+	
+	return str;
+}
+
+
+//---------------------------------------------------------------
+//
+// ToStr (int16, int32)
+//
+//---------------------------------------------------------------
+std::wstring ToStr(int16_t value, int32_t fieldWidth)
+{
+	wchar_t str[32];							
+	::swprintf(str, L"%*d", fieldWidth, value);
+	
+	return str;
+}
+
+
+//---------------------------------------------------------------
+//
+// ToStr (uint16, int32)
+//
+//---------------------------------------------------------------
+std::wstring ToStr(uint16_t value, int32_t fieldWidth)
+{
+	wchar_t str[32];							
+	::swprintf(str, L"%*d", fieldWidth, value);
+	
+	return str;
+}
+
+
+//---------------------------------------------------------------
+//
+// ToStr (int32, int32)
+//
+//---------------------------------------------------------------
+std::wstring ToStr(int32_t value, int32_t fieldWidth)
+{
+	wchar_t str[32];							
+	::swprintf(str, L"%*ld", fieldWidth, value);
+	
+	return str;
+}
+
+
+//---------------------------------------------------------------
+//
+// ToStr (uint32, int32)
+//
+//---------------------------------------------------------------
+std::wstring ToStr(uint32_t value, int32_t fieldWidth)
+{
+	wchar_t str[32];							
+	::swprintf(str, L"%*lu", fieldWidth, value);
+	
+	return str;
+}
+
+
+//---------------------------------------------------------------
+//
+// ToStr (float, int32)
+//
+//---------------------------------------------------------------
+std::wstring ToStr(float value, int32_t precision)
+{
+	wchar_t str[32];							
+	::swprintf(str, L"%.*f", precision, value);
+	
+	return str;
+}
+
+
+//---------------------------------------------------------------
+//
+// ToStr (double, int32)
+//
+//---------------------------------------------------------------
+std::wstring ToStr(double_t value, int32_t precision)
+{
+	wchar_t str[32];							
+	::swprintf(str, L"%.*f", precision, value);
+	
+	return str;
+}
+
+
+//---------------------------------------------------------------
+//
+// ToStr (const char*)
+//
+//---------------------------------------------------------------
+std::wstring ToStr(const char* value)
+{
+	wchar_t str[2048];							
+	::swprintf(str, L"%s", value);
+	
+	return str;
+}
+
+
+//---------------------------------------------------------------
+//
+// ToStr (std::string)
+//
+//---------------------------------------------------------------
+std::wstring ToStr(const std::string& value)
+{
+	wchar_t str[2048];							
+	::swprintf(str, L"%s", value.c_str());
+	
+	return str;
+}
+
Index: /gsdl/trunk/build-src/packages/isis-gdl/Debug.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Debug.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Debug.h	(revision 16571)
@@ -0,0 +1,161 @@
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
+
+//	Abstract:	This file provides the following macros:
+//
+//				ASSERT(p) - If p is false and DEBUG is true drops into the 
+//				debugger, if ASSERTS_THROW is true throws a XAssertException exception.
+//
+//				VERIFY(p) - Like ASSERT except that p is evaluated in release builds.
+//
+//				REQUIRE(p) - Like VERIFY except that it exits the app if the test fails
+//				(this is needed because the boot strap code can't safely throw).
+//
+//				COMPILE_CHECK(p) - An ASSERT that fires at compile time. This is useful
+//				for doing things like verifying the layout of items within a struct.
+//				Note that this check is also done in release builds.
+//
+//				DEBUGSTR(formatStr, n1, n2, ...) - Drops into the debugger and
+//				displays a string.
+//
+//				TRACE(formatStr, n1, n2, ...) - Writes a string to a debug window
+//				without suspending the program.
+//
+//				TRACEFLOW(category, formatStr, n1, n2, ...) - Like TRACE, but with 
+//				the addition of a category string. The category string allows users 
+//				to turn off entire categories of messages. Note that DEBUGSTR, TRACE, 
+//				and TRACEFLOW may be used with boolean expressions by tacking an _IF 
+//				on the end (eg DEBUGSTR_IF(x < 0, "Sqrt was passed a negative argument.")).
+//
+//				PRECONDITION(p)  - Used in conjunction with POSTCONDITION to verify 
+//				the integrity of an object: each public method should include one call to 
+//				PRECONDITION and another to POSTCONDITION. The idea here is to check to 
+//				see if the object stays in a valid state given valid arguments. Note that 
+//				these macros call a method named Invariant. This method should use ASSERT's 
+//				to check to see if the object is in a sane state. See ZInvariant.h for
+//				more details.
+//
+//				CHECK_INVARIANT() - Calls the Invariant. This is useful in ctors because
+//				PRECONDITION doesn't call the dtor (PRECONDITION constructs an object on
+//				the stack which calls the Invariant when the function exits).
+
+#pragma once      // Open only once per build
+
+#define RUNTIME_EXPORT 
+
+RUNTIME_EXPORT std::wstring ToStr(bool value);				// I originally used iostreams, but that caused a ridiculous amount of bloat in object files (but much less so in the exe)
+RUNTIME_EXPORT std::wstring ToStr(char value);
+inline 		   std::wstring ToStr(wchar_t value)						{return std::wstring(1, value);}
+RUNTIME_EXPORT std::wstring ToStr(int16_t value, int32_t fieldWidth = 1);
+RUNTIME_EXPORT std::wstring ToStr(uint16_t value, int32_t fieldWidth = 1);
+RUNTIME_EXPORT std::wstring ToStr(int32_t value, int32_t fieldWidth = 1);
+RUNTIME_EXPORT std::wstring ToStr(uint32_t value, int32_t fieldWidth = 1);
+RUNTIME_EXPORT std::wstring ToStr(float value, int32_t precision = 6);
+RUNTIME_EXPORT std::wstring ToStr(double_t value, int32_t precision = 6);
+RUNTIME_EXPORT std::wstring ToStr(const char* value);
+inline 		   std::wstring ToStr(const wchar_t* value)					{return value;}
+RUNTIME_EXPORT std::wstring ToStr(const std::string& value);
+inline 		   std::wstring ToStr(const std::wstring& value)			{return value;}
+
+
+#ifdef _DEBUG
+	#define	DEBUG					1
+#else		
+	#define	DEBUG					0
+	
+	#if	!defined(NDEBUG)
+		#define	NDEBUG							// used by <assert.h>
+	#endif
+#endif
+
+#ifndef ASSERTS_THROW
+#define ASSERTS_THROW				0			
+#endif
+// #define ASSERTS_THROW               1
+// Synch with ANSI definitions.
+#if DEBUG && defined(NDEBUG)
+	#error DEBUG and NDEBUG are out of sync!
+#endif
+
+#if !DEBUG && !defined(NDEBUG)
+	#error DEBUG and NDEBUG are out of sync!
+#endif
+
+// Synch with MSVC.
+#if _MSC_VER && DEBUG != defined(_DEBUG)
+	#error DEBUG and _DEBUG are out of sync!
+#endif
+
+#ifndef _lint
+	#define COMPILE_CHECK(p)	{struct _CC {char a[(p) ? 1 : -1];};} (void) 0
+#else
+	#define COMPILE_CHECK(p)					
+#endif
+
+#if DEBUG
+	
+	void AssertFailed(const char* expr, const char* file, int line);
+	
+	#undef assert
+
+	#define ASSERT(p)					do {if (!(p)) AssertFailed(#p, __FILE__, __LINE__);} while (false)
+
+	#define ASSERT_IF(p, x)				do {if ((p) && !(x)) AssertFailed(#x, __FILE__, __LINE__);} while (false)
+	#define assert(p) 					ASSERT(p)
+	#define VERIFY(p)					ASSERT(p)
+	#define REQUIRE(p)					ASSERT(p)
+
+	#define	PRECONDITION(p)				ASSERT(p)
+	#define	POSTCONDITION(p)			ASSERT(p)
+
+    #ifdef NO_NESTED_QUOTES
+          #define PRECONDITION2(a,b)	ASSERT(a)
+          #define POSTCONDITION2(a,b)	ASSERT(a)
+    #else
+          #define PRECONDITION2(a,b)	ASSERT((b, (a) !=0))
+          #define POSTCONDITION2(a,b)	ASSERT((b, (a) !=0))
+    #endif
+
+#else	// #if DEBUG
+
+
+	#if ASSERTS_THROW
+		void AssertFailed(const char*, const char*, int);
+
+		#define ASSERT(p)				do {if (!(p)) AssertFailed(#p, __FILE__, __LINE__);} while (false)
+
+		#define ASSERT_IF(p, x)			do {if ((p) && !(x)) AssertFailed(#x, __FILE__, __LINE__);} while (false)
+		#define VERIFY(p)				ASSERT(p)
+
+		#define	PRECONDITION(p)			ASSERT(p)
+		#define	POSTCONDITION(p)		ASSERT(p)
+
+        #define PRECONDITION2(a,b)	    ASSERT(a)
+        #define POSTCONDITION2(a,b)	    ASSERT(a)
+	#else
+		#define	ASSERT(p)				((void) 0)
+
+		#define	ASSERT_IF(p, x)			((void) 0)
+		#define VERIFY(p)				do {if (p) 0;} while (false)
+
+		#define	PRECONDITION(p)			((void) 0)
+		#define	POSTCONDITION(p)		((void) 0)
+
+        #define PRECONDITION2(a,b)
+        #define POSTCONDITION2(a,b)
+	#endif
+
+	void RequireFailed(const char*, const char*, int);
+	
+	#define REQUIRE(p)					do {if (!(p)) RequireFailed(#p, __FILE__, __LINE__);} while (false)
+
+
+#endif	// DEBUG
+
+#ifdef _CONSOLE
+#define TRACE
+#endif
+	
+
+
+#endif /* __DEBUG_H__ */
Index: /gsdl/trunk/build-src/packages/isis-gdl/Fdt.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Fdt.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Fdt.cpp	(revision 16571)
@@ -0,0 +1,536 @@
+/**********************************************************************
+ *
+ * Fdt.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+///////////////////////////////////////////////////////////////////////////
+//  fdt.cpp
+
+#include "stdafx.h"
+#include "Fdt.h"
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <sstream>
+#include <stdio.h>
+
+//////////////////////////////
+ 
+CFdt::CFdt()   
+// Constructor
+{
+   InitData();
+   InitFields();
+}
+
+//////////////////////////////
+
+CFdt::~CFdt()
+{
+	for (int i = 0; i < m_nFieldCount; i++)
+	{
+#ifndef _WIN32
+		CFieldDef* p = (CFieldDef*) m_fieldArray[i];
+#else
+		CFieldDef* p = (CFieldDef*) m_fieldArray.at(i);
+#endif
+    	delete p;
+	}
+	m_fieldArray.clear();
+
+	Close();
+}
+
+////////////////////////////
+
+bool CFdt::Open(const _TCHAR *szFileName, bool readOnly)
+{
+	if (!m_bIsEmpty)
+		Close();
+	m_sFileName = szFileName;
+	if (!Load(szFileName))
+	{
+		Close();
+		return false;
+	}
+
+	m_bReadOnly = readOnly;
+	return Seek(0);   // 
+}
+
+
+
+
+//////////////////////////////
+
+void CFdt::InitData()
+{
+   m_iCurrentRecord = -1;
+   m_sFileName.erase();
+   
+   m_bReadOnly = false;
+   m_bIsEmpty  = true;
+   m_fdtEntry.Clear();
+   m_bDirty    = false;
+   m_aFdt.clear();
+   m_asPrelude.clear();
+   // Suppose the fdt is empty and we are 
+   // going to append 
+   m_bAppend = true;
+}
+
+//////////////////////////////
+
+void CFdt::Close()
+{
+	if (!m_bIsEmpty)
+		DeleteContents();
+
+    InitData();        // Reset data members   
+	m_bIsEmpty = true;
+}
+
+////////////////////////////////////
+ 
+void CFdt::DeleteContents()
+// Delete the fdt data structures
+{
+    m_aFdt.clear();
+  
+}
+
+
+
+bool CFdt::Load(const _TCHAR *dbaseName)
+{
+	std::ifstream in((const char*)dbaseName);
+	if (!in)
+    {
+//#ifdef _WIN32
+//	   CString strMsg;
+//		strMsg.Format(_T("Error opening %s for reading. "), dbaseName);
+//		AfxMessageBox(strMsg, MB_OK | MB_ICONEXCLAMATION);
+//#else
+		std::cout << _T("Error opening") << dbaseName << _T("for reading") << std::endl;
+//#endif
+		return false;
+    }
+
+
+	std::string s;
+
+    while (std::getline(in,s) && s.substr(0,3) != "***")
+    {
+		m_asPrelude.push_back(s);
+    }
+
+    while (std::getline(in,s))
+    {
+        CFdtEntry e;
+        strncpy(e.name, s.c_str(), FDT_NAME_LENG);
+	    e.name[FDT_NAME_LENG] = _T('\0');
+	    for (int i=FDT_NAME_LENG-1; e.name[i]==_T(' '); e.name[i--]=_T('\0'))
+		   ;
+        if (s[FDT_NAME_LENG] == _T(' '))        //no subfield delimiters spec.
+		 	e.subfields[0] = _T('\0');
+	    else
+		{
+		 	strncpy(e.subfields, s.c_str()+FDT_NAME_LENG, FDT_SFLD_LENG);
+			e.subfields[FDT_SFLD_LENG] = _T('\0');
+			for (int i= FDT_SFLD_LENG-1; e.subfields[i]==_T(' '); e.subfields[i--]='\0')
+				 ;
+		}
+	    sscanf(s.c_str() + FDT_NAME_LENG + FDT_SFLD_LENG, "%d %d %d %d",
+										  &e.tag, &e.len, &e.type, &e.rep);
+	    m_aFdt.push_back(e);
+    }
+    in.close();
+    return true;
+}
+
+		
+		
+		
+
+
+// Define the fields used for the dictionary
+
+static CFieldDef fdtFields[7] =  { 
+   {"Name",       'C', 30, 30, 0, 0, 30},
+   {"Subfields",  'C', 20, 20, 0, 30, 20},
+   {"Tag",        'N', 4, 4, 0,50, 4},
+   {"Len",        'N', 4, 4, 0,54, 4},
+   {"Type",       'N', 1, 1, 0,58, 4},
+   {"Rep",        'C', 1, 1, 0,62, 4},
+   {0,             0, 0, 0, 0, 0, 0}
+}; 
+
+
+
+
+
+
+//+----------------------------------------------------------------
+//
+// Member:     Store(const char* fileName)
+//
+// Synopsis:   Store dictionary tables on a file
+//
+// Parameters: 
+//
+//     fileName -- Full path of dictionary file
+// 
+//-----------------------------------------------------------------   
+
+void FormatFdtEntry(CFdtEntry &e, ustring &s)
+{
+#ifdef _WIN32
+	ustringstream ost;
+
+	ost.setf(std::ios_base::left, std::ios_base::adjustfield);
+	ost << std::setw(30) << e.name << std::setw(20) << e.subfields;
+	ost.setf(std::ios_base::internal,std::ios_base::adjustfield);
+	ost << " " << e.tag << " " << e.len << " " << e.type << " " << e.rep;
+	s = ost.str();
+#endif
+}
+
+void CFdt::Store(const char* fileName)
+{
+	if (m_bDirty)
+	{
+		Flush();
+		m_bDirty = false;
+	}
+
+	std::ofstream out((const char *) fileName);
+	TRACE(_T("\n<CFdt::Store> fileName=%s"),fileName);
+	for (int i=0; i<m_asPrelude.size(); i++)
+		out << m_asPrelude[i] << std::endl;
+	
+	out << "***" << std::endl;
+
+	ustring s;
+#ifdef _WIN32
+	for (i=0; i< m_aFdt.size(); i++)
+#else
+	for (int i=0; i< m_aFdt.size(); i++)
+#endif
+	{
+		FormatFdtEntry(m_aFdt[i], s);
+		out << s << std::endl;
+	}
+    out.close();
+
+}
+
+//////////////////////////////
+
+int CFdt::InitFields ()
+{
+	m_nFieldCount = 0;
+
+	for (int i = 0; fdtFields[i].width != 0; i++)
+	{
+		CFieldDef* fld = (CFieldDef*) new CFieldDef();
+		//TRACE("\n<CFdt::InitFields>i=%d after new",i);
+		//TRACE("<CFdt::InitFields>After SetAtGrow");
+		strcpy(fld->name, fdtFields[i].name);
+		fld->type          = fdtFields[i].type;
+		fld->len           = fdtFields[i].len;
+		fld->width         = fdtFields[i].width;
+		fld->decimals      = fdtFields[i].decimals;
+		fld->offset        = fdtFields[i].offset;
+		fld->display_width = fdtFields[i].display_width;
+
+		int l = strlen(fld->name);
+		if (fld->width < l)
+			fld->width = static_cast<short>(l);
+
+		m_fieldArray.push_back(fld);
+		m_nFieldCount++;
+	}
+	//TRACE("\n<CFdt::InitFields>InitField After loop");
+	return 1;
+}
+
+////////////////////////////////////////////////////////////////////
+
+CFieldDef* CFdt::GetField(int n) const
+// Returns field info
+{
+	ASSERT(n >= 0 && n <= m_nFieldCount);
+#ifndef _WIN32
+	return (CFieldDef*) m_fieldArray[n];
+#else
+	return (CFieldDef*) m_fieldArray.at(n);
+#endif
+}
+
+/////////////////////////////////////////////////////////////////////
+// Methods for accessing and maintaining the list of CDictTRecords 
+// pointers
+
+////////////////////////////
+// First the List Accessors
+////////////////////////////
+
+CFdtEntry CFdt::GetAt(int i)
+{
+#ifndef _WIN32
+	return m_aFdt[i];
+#else
+	return m_aFdt.at(i);
+#endif
+
+}
+
+
+//////////////////////////
+
+const CFdtEntry CFdt::GetAt(int i) const
+{
+#ifndef _WIN32
+	return m_aFdt[i];
+#else
+	return m_aFdt.at(i);
+#endif
+}
+
+//////////////////////////
+// And now the modifiers
+//////////////////////////
+
+int CFdt::Append(CFdtEntry& e)
+{
+	int n = m_aFdt.size();
+	m_aFdt.push_back(e);
+    m_iCurrentRecord = -1;
+    m_bIsEmpty = false;
+
+    return m_aFdt.size();
+}
+
+
+/**-------------------------------------------------------------------
+ * RemoveAt(int i)
+ *
+ *--------------------------------------------------------------------
+ */
+void CFdt::RemoveAt(int i)
+{
+
+	m_aFdt.erase(m_aFdt.begin()+i);
+    m_iCurrentRecord = -1;
+}
+
+/**-------------------------------------------------------------------
+ * SetAt(int i, CFdtEntry& e)
+ *
+ *--------------------------------------------------------------------
+ */
+void CFdt::SetAt(int i, CFdtEntry& e)
+{
+
+	m_aFdt[i] = e;
+	// Force reloading
+    m_iCurrentRecord = -1;
+}
+
+/////////////////////////////////////////////////////////////////
+// 
+// We use a buffer "m_fdtEntry" to hold the content of the current
+// fdt entry. This buffer is filled by the "Seek" member function
+// as follow:
+//
+
+//////////////////////////////
+
+bool CFdt::Seek(long iRecord)
+{
+
+	// move to new record and flush changes of previous record
+	if (iRecord < 0 || iRecord > GetRecordCount())
+		return false;
+	else if (iRecord == m_iCurrentRecord)
+		return true;
+
+	if (m_iCurrentRecord != -1 &&  m_bDirty)
+		Flush();
+	if (m_bDirty)
+	   /*AfxMessageBox(_T("Seek Alert Modification not saved"))*/;
+	m_iCurrentRecord = iRecord;
+	
+	if (iRecord == GetRecordCount())
+	{
+		m_fdtEntry.Clear();
+        m_bAppend = true;
+	}
+	else
+	{
+		TRACE(_T("\n<CFdt::Seek> Load iRecord=%d GetRecordCount()=%d"), iRecord, GetRecordCount());
+		m_fdtEntry = GetAt(iRecord);
+		m_bAppend = false;
+	}
+    m_bDirty = false;
+	return true;
+}
+
+
+
+//+------------------------------------------------------------------
+//
+// Member:   Flush()
+//
+// Synopsis: Moves the changes made to the current record from
+//           the buffer to the dictionary data structure so that
+//           they are effective.
+//-------------------------------------------------------------------    
+
+void CFdt::Flush()
+{
+	if (m_iCurrentRecord == GetRecordCount())
+	{
+		Append(m_fdtEntry); 
+	}
+	else
+	{
+		SetAt(m_iCurrentRecord, m_fdtEntry);
+	}
+	m_bDirty = false;
+}
+
+//////////////////////////////////////////////////////////////
+// Get the value of field n for the current record
+//
+
+bool CFdt::GetValue(int n, std::string& result) 
+// Read value from buffer
+{
+	ASSERT(n >= 0 && n <= m_nFieldCount);
+    ASSERT(m_iCurrentRecord >= 0 && m_iCurrentRecord <= GetRecordCount());
+	
+	if (!(n >= 0 && n <= m_nFieldCount))
+		return false;
+
+	result.erase();
+
+	std::ostringstream os;
+    switch (n)
+	{
+	    case 0:       // Field Name
+			os << m_fdtEntry.name;
+			result = os.str();
+		    break;
+	    case 1:       // Subfields
+			os << m_fdtEntry.subfields;
+			result = os.str();
+		    break;
+	    case 2:       // Tag
+		  	if (m_fdtEntry.tag == 0)
+				result = "";
+			else
+			{
+			    os << m_fdtEntry.tag;
+			    result = os.str();
+			}
+		    break;
+	    case 3:       // length
+		  	if (m_fdtEntry.len == 0)
+				result = "";
+			else
+			{
+			    os << m_fdtEntry.len;
+			    result = os.str();
+			}
+		    break;
+	    case 4:       // type
+		  	if (m_fdtEntry.type == 0)
+				result = "";
+			else
+			{
+			    os << m_fdtEntry.type;
+			    result = os.str();
+			}
+		    break;
+	    case 5:       // Rep
+		  	if (m_fdtEntry.rep == 0)
+				result = "";
+			else
+			{
+			    os << m_fdtEntry.rep;
+			    result = os.str();
+			}
+		    break;
+	}
+	return true;
+}
+
+
+//////////////////////////////
+
+bool CFdt::SetValue(int n, const char* pszValue)
+// Write value to buffer
+{
+	ASSERT(n >= 0 && n <= m_nFieldCount);
+    ASSERT(m_iCurrentRecord >= 0 && m_iCurrentRecord <= GetRecordCount());
+
+	if (m_bReadOnly)
+		return false;
+
+	if (!(n >= 0 && n <= m_nFieldCount))
+		return false;
+
+    bool bEmpty = true;
+
+
+	switch (n) 
+	{
+	case 0:       // Name
+		strcpy(m_fdtEntry.name,(const char*)pszValue);
+	//	TRACE("\nvalue=%s num=%d",pszValue,m_tRecord.num);
+		break;
+	case 1:       // Subfields
+		strcpy(m_fdtEntry.subfields,(const char*)pszValue);
+	//	TRACE("\nvalue=%s name=%d",pszValue,m_tRecord.name);
+		break;
+	case 2:       // Tag
+		m_fdtEntry.tag = _ttoi(pszValue);
+	//	TRACE("\nvalue=%s loc=%d",pszValue,m_tRecord.loc);
+		break;
+	case 3:       // Len
+		m_fdtEntry.len = _ttoi(pszValue);
+	//	TRACE("\nvalue=%s wid=%d",pszValue,m_tRecord.wid);
+		break;
+	case 4:       // Type
+		m_fdtEntry.type = _ttoi(pszValue);
+		break;
+	case 5:       // Rep
+		m_fdtEntry.type = _ttoi(pszValue);
+		break;
+	}
+	m_bDirty = true;
+	
+	return true;
+}
+
Index: /gsdl/trunk/build-src/packages/isis-gdl/Fdt.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Fdt.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Fdt.h	(revision 16571)
@@ -0,0 +1,172 @@
+/**********************************************************************
+ *
+ * Fdt.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////////////////////////////
+// Fdt.h
+
+#ifndef __FDT_H__
+#define __FDT_H__
+
+#include <vector>
+#include "mytchar.h"
+
+#define FDT_NAME_LENG    30     // maximum name length in FDT_FILE
+#define FDT_SFLD_LENG    20    // maximum subfield length in FDT_FILE
+
+#ifndef __CFIELDDEF__
+#define __CFIELDDEF__
+
+class CFieldDef
+{
+public:
+	enum FieldType {
+		charField       = 'C',
+		dateField       = 'D',
+		numericField    = 'N',
+		logicalField    = 'L',
+		memoField       = 'M'
+	};
+
+	char  name[31];   // dbf field names are 10 chars long max.
+		// If this application is compiled with _UNICODE switch,
+		// the field name will be converted to wide chars
+		// when the column header is displayed in the grid.
+	char  type;
+	short len;
+	short width;
+	short decimals;
+	int   offset;
+	short display_width;
+};
+#endif // __CFIELDDEF__
+
+
+
+class CFdtEntry
+{
+public:
+	CFdtEntry() :  tag(0), len(0), type(0), rep(0) 
+	{ name[0] = '\0'; subfields[0] = '\0'; }
+    void Clear()
+	{
+		tag = len = type = rep = 0;
+        name[0] = '\0'; subfields[0] = '\0';
+	}
+    char    name[FDT_NAME_LENG+1];
+    char    subfields[FDT_SFLD_LENG+1];
+    int      tag;
+    int      len;
+    int      type;     //X=0
+    int      rep;      //repeatable 1, non rep. 0
+   CFdtEntry& operator=(const CFdtEntry& rhs)
+   {
+	   if (&name[0] != &rhs.name[0])
+	   {
+		   Copy(rhs);
+	   }
+	   return *this;
+   }
+
+   void Copy(const CFdtEntry &rhs)
+   {
+	   strcpy(name, rhs.name);
+	   strcpy(subfields, rhs.subfields);
+	   tag  = rhs.tag;
+	   len  = rhs.len;
+	   type = rhs.type;
+	   rep  = rhs.rep;
+   }
+};
+
+
+void FormatFdtEntry(CFdtEntry &e, ustring &s);
+
+
+
+class CFdt
+{
+protected:
+	std::vector<CFdtEntry>  m_aFdt;
+    int                     m_nFieldCount;       // Num. of fields
+	std::vector<CFieldDef*> m_fieldArray;        // Array with fields
+
+	long        m_iCurrentRecord;    // Current read record stored in
+	CFdtEntry   m_fdtEntry;
+	bool        m_bReadOnly;
+	bool        m_bIsEmpty;
+	bool        m_bDirty;            // True if m_fdtEntry modified 
+	bool        m_bAppend;
+public:
+	ustring  m_sFileName;              // Fdt full pathname
+	std::vector<std::string> m_asPrelude;  // What is bef ***
+public:
+	CFdt();          
+	virtual ~CFdt();
+
+	bool      Load(const _TCHAR *fname);
+	int       GetEntryCount() { return m_aFdt.size(); }
+
+	CFdtEntry GetEntryAt(int i) 
+	{ 
+      #ifdef _WIN32
+	     return m_aFdt.at(i); 
+      #else
+	     return m_aFdt[i];
+      #endif
+	}
+
+	int       GetFieldCount() { return  m_nFieldCount; }
+
+    bool      Open(const char* szFileName, bool readOnly=true);
+
+    void InitData();
+
+    void Close();
+ 
+    void DeleteContents();
+
+    void Store(const char* fileName);
+    int InitFields ();
+
+    CFieldDef* GetField(int n) const;
+
+    CFdtEntry GetAt(int i);
+
+    const CFdtEntry GetAt(int i) const;
+
+    int Append(CFdtEntry& e);
+
+    void RemoveAt(int i);
+    void SetAt(int i, CFdtEntry& e);
+
+    bool Seek(long iRecord);
+    void Flush();
+    bool GetValue(int n, std::string& result);
+    bool SetValue(int n, const char* pszValue);
+
+	int GetRecordCount() { return m_aFdt.size(); }
+};
+
+#endif
Index: /gsdl/trunk/build-src/packages/isis-gdl/File.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/File.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/File.cpp	(revision 16571)
@@ -0,0 +1,618 @@
+/**********************************************************************
+ *
+ * File.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////
+// File.cpp   File object methods
+////////////////////////////////////////////////////////////
+#include "stdafx.h"
+
+ 
+#include <assert.h>
+#include "CRC32.h"
+#include "File.h"
+
+
+
+
+static TCHAR closed_file_name[] = _T("closed-file");
+
+static const int MaxExceptionMessages = 34;
+static const TCHAR *fileExceptionMsg[MaxExceptionMessages] =
+{
+  _T("File exception: No exception reported"),               // FILE_NO_ERROR
+  _T("File exception: Checksum error"),                      // FILE_CHECKSUM_ERROR
+  _T("File exception: Error closing file"),                  // FILE_CLOSE_ERROR
+  _T("File exception: File is corrupted"),
+  _T("File exception: Error creating file"),                 // FILE_CREATION_ERROR
+  _T("File exception: File already exists"),                 // FILE_EXISTS
+  _T("File exception: Trying to use a closed file"),         // FILE_NOT_OPEN_ERROR
+  _T("File exception: File not ready for reading/writing"),  // FILE_NOT_READY
+  _T("File exception: Could not write to file"),             // FILE_NOT_WRITEABLE
+  _T("File exception: Error opening file"),                  // FILE_OPEN_ERROR
+  _T("File exception: Cannot obtain a file position"),       // FILE_POSITION_ERROR
+  _T("File exception: Error reading from file"),             // FILE_READ_ERROR
+  _T("File exception: Error seeking in file"),               // FILE_SEEK_ERROR
+  _T("File exception: Error writing to file"),               // FILE_WRITE_ERROR
+
+  _T("Fmgr exception: No database open"),                    // FMGR_NO_DATABASE_OPEN
+  _T("Fmgr exception: No such file exists"),                 // FMGR_NO_FILE_EXISTS
+  _T("Fmgr exception: No objects exist"),                    // FMGR_NO_OBJECTS_EXIST
+  _T("Fmgr exception: Accessing a null pointer"),            // FMGR_NULL_PTR
+  _T("Fmgr exception: Object already exists"),               // FMGR_OBJECT_EXISTS
+  _T("Fmgr exception: Another object is referencing this file"), // FMGR_OBJECT_EXISTS
+  _T("Fmgr exception: Math overflow error"),                 // FMGR_OVERFLOW
+  _T("Fmgr exception: Parse error"),                         // FMGR_PARSE_ERROR
+  _T("Fmgr exception: Invalid path"),                        // FMGR_PATH_ERROR
+  _T("Fmgr exception: Trying to write to a read-only file"), // FMGR_READ_ONLY_FILE
+  _T("Fmgr exception: Stack empty"),                         // FMGR_STACK_EMPTY
+  _T("Fmgr exception: Stack full"),                          // FMGR_STACK_FULL
+  _T("Fmgr exception: Synchronization Error"),               // FMGR_SYNC_ERROR    
+  _T("Fmgr exception: Math under-flow error"),               // FMGR_UNDERFLOW
+  _T("Fmgr exception: Wrong file type"),                     // FMGR_WRONG_FILE_TYPE
+  
+  // Persistent lock error messages
+  _T("Fmgr exception: Invalid lock type specified"),          // FMGR_INVALID_LOCK_TYPE
+  _T("Fmgr exception: Cannot access the file lock header"),   // FMGR_FILELOCK_ACCESS_ERROR
+  _T("Fmgr exception: Cannot lock the file"),                 // FMGR_FILELOCK_ERROR
+  _T("Fmgr exception: Cannot access the record lock header"), // FMGR_RECORDLOCK_ACCESS_ERROR
+  _T("Fmgr exception: Cannot lock the specified record")      // FMGR_RECORDLOCK_ERROR
+};
+ 
+//---------------------------------------------------------------------------
+// CFileBase::CFileBase()
+//
+// Default constructor, makes a File object that isn't attached to a file
+//--------------------------------------------------------------------------- 
+CFileBase::CFileBase()
+{
+    _tcscpy(file_name, closed_file_name); // Set the initial file name
+    fp = 0;
+
+    // Reset the last reported error and the file status members
+    file_error        = FILE_NO_ERROR;
+    is_open           = 0;
+    is_ok             = 0;
+    ready_for_reading = 0;
+    ready_for_writing = 0;
+}
+  
+//---------------------------------------------------------------------------
+// CFileBase::~CFileBase()
+//
+// Destructor for CFileBase file object
+//--------------------------------------------------------------------------- 
+CFileBase::~CFileBase()
+{
+	Close();
+}
+
+//---------------------------------------------------------------------------
+// const char* CFileBase::FileExceptionMessage()
+//
+// Returns a null terminated string that can / be used to log or print a
+// file exception.
+//---------------------------------------------------------------------------
+const TCHAR *CFileBase::FileExceptionMessage()
+{
+	assert(file_error<MaxExceptionMessages);
+    return fileExceptionMsg[file_error];
+}
+ 
+//--------------------------------------------------------------------------------
+// int Create(const char* fname)
+//
+// Creates a new file, truncate the file if it already exists. The file open for
+// Read/Write access. 
+// Returns a non-zero value to indicate an error condition or zero if successful.
+//--------------------------------------------------------------------------------
+FileError CFileBase::Create(const TCHAR *fname)
+{
+    // Close any open files 
+    if (Close() != FILE_NO_ERROR) 
+		return file_error;
+	
+    // Create and truncate existing files
+    fp = FileSystem::Create(fname);
+	
+    if (fp == 0)
+	{
+		is_ok             = 0;
+		is_open           = 0;
+		ready_for_writing = 0;
+		ready_for_reading = 0;
+		file_error        = FILE_CREATION_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+		throw CFileBaseException(file_error);
+#else
+		return file_error;
+#endif
+	}
+	else
+	{
+		is_open           = 1;
+		is_ok             = 1;
+		ready_for_writing = 1;
+		ready_for_reading = 1;
+		last_operation    = IO_READ;
+		_tcscpy(file_name, fname);
+	}
+	
+	// Returns 0 if the file was successfully created and opened.
+	return file_error = FILE_NO_ERROR; 
+}
+ 
+//----------------------------------------------------------------------------------------
+// FileError CFileBase::Open(const TCHAR *fname, FileSystem::AccessMode mode
+//                                               /* = FileSystem::FILE_READWRITE */ )
+//
+// Open an existing file. The "mode" variable determines if the file is opened for
+// read only or read/write access.  Returns a non-zero value to indicate an error
+// condition or zero if successful.
+// NOTE: This version of the open functions will only accept:
+// FILE_READONLY and FILE_READWRITE access modes.
+//---------------------------------------------------------------------------------------
+FileError CFileBase::Open(const TCHAR *fname, FileSystem::AccessMode mode /* = FileSystem::FILE_READWRITE */)
+{
+	// Close any open files
+	if (Close() != FILE_NO_ERROR) 
+		return file_error;
+	
+	if (mode == FileSystem::FILE_READONLY)
+	{   // Open with read only access
+		ready_for_reading = 1;
+		ready_for_writing = 0;
+		fp = FileSystem::Open(fname, FileSystem::FILE_READONLY);
+	}
+	else
+	{   // Open with read/write access
+		ready_for_reading = 1;
+		ready_for_writing = 1;
+		fp = FileSystem::Open(fname, FileSystem::FILE_READWRITE);
+	}
+    
+	if (fp == 0)
+	{
+		ready_for_reading = 0;
+		ready_for_writing = 0;
+		file_error        = FILE_OPEN_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+		throw CFileBaseException(file_error);
+#else
+		return file_error;
+#endif
+	}
+	else
+	{
+		is_open         = 1;
+		is_ok           = 1;
+		last_operation  = IO_WRITE;
+		_tcscpy(file_name, fname);
+	}
+	return file_error = FILE_NO_ERROR;
+}
+ 
+//--------------------------------------------------------------------------------
+// void CFileBase::Close()
+//
+// Close the open database file. Returns a non-zero value
+// to indicate an error condition or zero if successful.
+//--------------------------------------------------------------------------------
+FileError CFileBase::Close()
+{
+   if (IsOpen()) 
+   {
+       if (FileSystem::Close(fp) != 0) 
+	   {
+		   file_error = FILE_CLOSE_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+		   throw CFileBaseException(file_error);
+#else
+		   return file_error;
+#endif
+	   }
+       _tcscpy(file_name, closed_file_name); // Set the initial file name
+   }
+
+   is_open           = 0;
+   is_ok             = 0;
+   ready_for_reading = 0;
+   ready_for_writing = 0;
+   fp                = 0; // Reset the file pointer to zero after the file is closed
+
+   return file_error = FILE_NO_ERROR; 
+}
+
+//----------------------------------------------------------------------------------
+// FileError CFileBase::Seek(FAU offset, FileSystem::SeekMode mode)
+//
+// Seek to the specified offset starting at the beginning (SEEK_SET), end (SEEK_END)
+// or current offset (SEEK_CUR). Returns a non-zero value to indicate an error
+// condition or zero if successful.
+//----------------------------------------------------------------------------------
+FileError CFileBase::Seek(FileSystem::FAU_t offset, FileSystem::SeekMode mode)
+{
+	if (IsOK()) 
+	{
+		if (FileSystem::Seek(fp, offset, mode) == (isis::int32_t) - 1)
+		{
+			file_error = FILE_SEEK_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+			throw CFileBaseException(file_error);
+#else
+			return file_error;
+#endif
+		}
+		last_operation = IO_SEEK;
+	}
+	else 
+	{
+		file_error = FILE_NOT_READY;
+#ifdef __CPP_EXCEPTIONS__
+		throw CFileBaseException(file_error);
+#else
+		return file_error;
+#endif
+	}
+	return file_error = FILE_NO_ERROR;
+}
+
+//----------------------------------------------------------------------------------
+// FAU CFileBase::SeekTo(FileSystem::FAU_t file_address)
+//
+// Seek to the specified address, optimizing the seek operation by moving the 
+// file position indicator based on the current stream position. Returns the
+// current file position after performing the seek operation.
+//----------------------------------------------------------------------------------
+FileSystem::FAU_t CFileBase::SeekTo(FileSystem::FAU_t file_address)
+{
+	// Get the current stream position
+	FileSystem::StreamPos pos = FilePosition();
+	
+	if (file_address == CURRADDR) 
+	{   // Do not perform a seek operation
+		return pos;
+	}
+	else if (file_address > pos)
+	{   // Seek forward to the specified address
+		FileSystem::StreamPos offset = file_address - pos;
+		Seek(offset, FileSystem::FILE_SEEK_CUR);
+	}
+	else if (file_address < pos) 
+	{   // Seek backward to the specified address
+		Seek(file_address, FileSystem::FILE_SEEK_BEG);
+	}
+	else 
+	{  // Current file position equals the specified address
+		// Find current the position
+		Seek((FileSystem::FAU_t)0, FileSystem::FILE_SEEK_CUR);
+	}
+	
+	return FilePosition(); // Return current file position after seeking
+}
+
+//-------------------------------------------------------------------------------
+// FileError Store(const void* buf, isis::uint32_t nBytes,
+//                             FAU file_addres = CFileBase::CURRADDR,
+//			                   int flush = 1, int bit_test = 1);
+//
+// Write a specific number of bytes from a memory buffer to a specified file
+// offset. If the "flush" variable is true, the file buffers will be flushed to
+// disk with each write operation. If the bit_test variable if true, the CRC of 
+// the buffer will be compared to the CRC of the actual bytes written to disk.
+// Returns a non-zero value to indicate an error condition or zero if successful.
+//
+// void* buf         - Pointer to the user-supplied buffer that is to receive
+//                     the data read from the file.
+// isis::uint32_t nBytes - The maximum number of bytes to be read from the 
+//                     file.  Note that an CFileBase is always a binary file,
+//                     so a CR/LF pair will always be read or written as two bytes.
+// FAU file_address  - The file byte address. The address is always interpreted to 
+//                     be from the beginning of the file, unless dwAddr is equal 
+//                     to CURRADDR, which means from the current position.
+//------------------------------------------------------------------------------- 
+FileError CFileBase::Store(const void* buf, isis::uint32_t nBytes,
+						   FileSystem::FAU_t file_address /*= CURRADDR */, 
+						   int flush_flag /* = 1 */,
+						   int bit_test /* = 1 */)
+{
+    FileSystem::FAU_t buf_address;
+	
+    if (ReadyForWriting())
+	{
+        if (file_address == CURRADDR)
+		{
+			if (last_operation == IO_READ)
+			{
+				if (Seek(0, FileSystem::FILE_SEEK_CUR) != FILE_NO_ERROR)
+					return file_error;
+			}
+		}
+        else
+		{
+			if (Seek(file_address, FileSystem::FILE_SEEK_BEG) != FILE_NO_ERROR)
+				return file_error;
+		}
+		
+        buf_address = FilePosition(); 
+		
+        if (file_error != FILE_NO_ERROR)
+			return file_error;
+		
+        if (FileSystem::Write(fp, buf, nBytes) != nBytes)
+		{
+			file_error = FILE_WRITE_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+			throw CFileBaseException(file_error);
+#else
+			return file_error;
+#endif
+		}
+        last_operation = IO_WRITE;
+	}
+    else
+	{
+        file_error = FILE_NOT_WRITEABLE;
+#ifdef __CPP_EXCEPTIONS__
+        throw CFileBaseException(file_error);
+#else
+        return file_error;
+#endif
+	} 
+	
+    // Allow application to flush disk buffers after each write
+    // operation to ensure the file data stays in sync during multiple
+    // file access.
+    if (flush_flag)
+	{  
+		if (FileSystem::Flush(fp) != FILE_NO_ERROR)
+		{
+			file_error = FILE_WRITE_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+			throw CFileBaseException(file_error);
+#else
+			return file_error;
+#endif
+		}
+        if (Seek(0, FileSystem::FILE_SEEK_CUR) != FILE_NO_ERROR)
+			return file_error;
+	}
+	
+    if (bit_test) 
+	{
+        isis::uint32_t w_csum = CalcCRC32((char* ) buf, nBytes);
+        isis::uint32_t r_csum = CalcChecksum(nBytes, buf_address);
+		
+		// Check for file errors
+		
+		if (file_error != FILE_NO_ERROR)
+			return file_error;
+		
+		if (w_csum ^ r_csum)
+		{
+			file_error = FILE_CHECKSUM_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+			throw CFileBaseException(file_error);
+#else
+			return file_error;
+#endif
+		}
+	}
+	return file_error = FILE_NO_ERROR;	
+}
+ 
+//-------------------------------------------------------------------------------
+// FileError CFileBase::Fetch(void* buf, isis::uint32_t nBytes, FAU file_addres
+//                                                  /* = CFileBase::CURRADDR */)
+//
+// Read a specified number of bytes from the specified file offset into a memory
+// buffer. Returns a non-zero value to indicate an error condition or zero if
+// successful.
+// void* buf         - Pointer to the user-supplied buffer that is to receive
+//                     the data read from the file.
+// isis::uint32_t nBytes - The maximum number of bytes to be read from the file. 
+//                     Note that an CFileBase is always a binary file, so a 
+//                     CR/LF pair will always be read or written as two bytes.
+// FAU file_addres   - The file byte address. The address is always interpreted 
+//                     to be from the beginning of the file, unless dwAddr is 
+//                     equal to CURRADDR, which means from the current position.
+//------------------------------------------------------------------------------- 
+FileError CFileBase::Fetch(void* buf, isis::uint32_t nBytes, 
+						   FileSystem::FAU_t file_address /* = CFileBase::CURRADDR */)
+{
+    if (IsOK())
+	{
+        if (file_address == CURRADDR)
+		{
+            if (last_operation == IO_WRITE)
+			{
+	           if (Seek(0, FileSystem::FILE_SEEK_CUR) != FILE_NO_ERROR) 
+				   return file_error;
+			}
+		}
+        else
+		{
+            if (Seek(file_address, FileSystem::FILE_SEEK_BEG) != FILE_NO_ERROR)
+              	return file_error;
+		}
+
+		//TRACE("\nFetchfile_address=%ld nBytes=%u",file_address, nBytes);
+        if (FileSystem::Read(fp, buf, nBytes) != nBytes)
+		{
+            file_error = FILE_READ_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+            throw CFileBaseException(file_error);
+#else
+            return file_error;
+#endif
+		}
+        last_operation = IO_READ;
+	}
+    else 
+	{
+        file_error = FILE_NOT_READY;
+#ifdef __CPP_EXCEPTIONS__
+        throw CFileBaseException(file_error);
+#else
+        return file_error;
+#endif
+	}
+
+    return file_error = FILE_NO_ERROR;
+}
+//------------------------------------------------------------------------------- 
+// FileError Flush()
+//
+// Flush any open disk buffers. Returns a non-zero value to indicate an error
+// condition or zero if successful.
+//------------------------------------------------------------------------------- 
+FileError CFileBase::Flush()
+{
+	PRECONDITION(ReadyForWriting());
+	if (FileSystem::Flush(fp) != FILE_NO_ERROR)
+	{
+		file_error = FILE_WRITE_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+		throw CFileBaseException(file_error);
+#else
+		return file_error;
+#endif
+	}
+	Seek((FileSystem::FAU_t)0, FileSystem::FILE_SEEK_CUR);
+	return file_error = FILE_NO_ERROR;
+}
+
+
+//------------------------------------------------------------------------------- 
+// StreamPos CFileBase::FilePosition()
+//
+// Returns the current file position or -1 to indicate an error condition.
+//------------------------------------------------------------------------------- 
+FileSystem::StreamPos CFileBase::FilePosition()
+{
+   if (!IsOK())
+   {
+      file_error = FILE_NOT_READY;
+#ifdef __CPP_EXCEPTIONS__
+      throw CFileBase();
+#else
+      return (StreamPos) - 1;
+#endif
+   }
+
+   FileSystem::StreamPos pos = FileSystem::Tell(fp);
+   if (pos < 0)
+   {
+      file_error = FILE_POSITION_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+      throw CFileBaseException(file_error);
+#else
+      return (StreamPos) - 1;
+#endif
+   }
+   return pos;
+}
+
+//------------------------------------------------------------------------------- 
+// isis::uint32_t CFileBase::CalcChecksum(isis::uint32_t bytes, FAU file_address, 
+//                                                         int mem_alloc)
+//
+// Calculate a 32-bit CRC checksum for a given number of bytes starting at the
+// specified address. Returns a 32-bit CRC value. If the mem_alloc variable is
+// true, a buffer equal to the specified number of bytes will be created in
+// memory. If the mem_alloc variable is false or memory allocation fails, the CRC
+// will be calculated byte by byte starting at the specified address. 
+// NOTE: the calling function must check for disk file errors.
+// Returns the CRC value.
+//------------------------------------------------------------------------------- 
+
+isis::uint32_t CFileBase::CalcChecksum(isis::uint32_t bytes, FileSystem::FAU_t file_address, int mem_alloc)
+{
+   isis::uint32_t CRC;
+   isis::uint32_t len = bytes;
+   unsigned char data;
+   char *buf = 0;  
+
+   // Create a buffer equal to the object length
+   if (mem_alloc) 
+	   buf = new char[bytes]; 
+
+   if (buf)
+   {
+      if (IsOK())
+	  {
+         if (Fetch(buf, bytes, file_address) != FILE_NO_ERROR) return 0;
+         CRC = CalcCRC32(buf, bytes);
+         delete[] buf;
+	  }
+   }
+   else
+   {
+      if (IsOK())
+	  {
+          // Seek to the specified file address
+          SeekTo(file_address);
+          if (file_error != FILE_NO_ERROR) return 0; 
+          CRC = 0xffffffffL;
+          while (len--)
+		  {
+	         if (Fetch(&data, sizeof(data)) != FILE_NO_ERROR) return 0;
+	         CRC = CalcCRC32(data, CRC);
+		  }
+          CRC ^= 0xffffffffL;
+	  }
+   }
+
+   return CRC; 
+}
+///////////////////////////////////////////////////////////////////////////
+// General purpose file utilites 
+//
+int CFileBase::Exists(const TCHAR *fname)
+// Returns true if the file exists
+{
+	return FileSystem::Exists(fname);
+}
+
+FileSystem::FAU_t CFileBase::FileSize(const TCHAR *fname)
+// Returns the file size. Use after file has been closed
+// and re-opened to ensure that all the buffers are flushed
+// to disk. Returns -1 to indicate an error condition.
+{
+	return (FileSystem::FAU_t) FileSystem::FileSize(fname);
+}
+
+int CFileBase::CanOpenForWriting(const TCHAR *fname)
+// Returns true if the file is opened
+{
+	return 1;
+	//return FileSystem::CanOpenForWriting(fname);
+}
+
+int CFileBase::CanOpenReadOnly(const TCHAR *fname)
+// Returns true if the file is opened
+{
+	return 1;
+	//return FileSystem::CanOpenReadOnly(fname);
+}
Index: /gsdl/trunk/build-src/packages/isis-gdl/File.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/File.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/File.h	(revision 16571)
@@ -0,0 +1,188 @@
+/**********************************************************************
+ *
+ * File.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+//////////////////////////////////////////////////////////////////////////
+// File.h -- File Base class
+// 
+//////////////////////////////////////////////////////////////////////////
+ 
+
+ 
+#ifndef __FILE_BASE__
+#define __FILE_BASE__
+
+#include "FileSystem.h"
+# define __CPP_EXCEPTIONS__ 1
+
+// CRC-32 checksum used to detect bit errors
+typedef unsigned long Checksum;
+
+
+// Constants for file operations and stream position 
+const int MaxNameLength             = 512;        // Max length of names buffers
+const FileSystem::FAU_t StartOfFile = (FileSystem::FAU_t)0; // First byte in the file
+const FileSystem::FAU_t CURRADDR    = (FileSystem::FAU_t)-1;// Indicates current location
+const isis::uint32_t CheckWord      = 0xfefefefe;           // Default synchronization word
+const isis::int32_t  FSListCorrupt  = (FileSystem::FAU_t)-1;// Free space list is corrupt
+
+
+//------------------
+// File  error codes
+//------------------
+enum FileError { 
+  FILE_NO_ERROR = 0,   // No errors reported
+  FILE_CHECKSUM_ERROR, // Checksum Error
+  FILE_CLOSE_ERROR,    // Error closing file
+  FILE_CORRUPT,        // File corrupted
+  FILE_CREATION_ERROR, // Error creating file
+  FILE_EXISTS,         // File already exists
+  FILE_NOT_OPEN_ERROR, // Trying to use a closed file
+  FILE_NOT_READY,      // File not ready (failed or closed file)
+  FILE_NOT_WRITEABLE,  // Could not write to file 
+  FILE_OPEN_ERROR,     // Error opening file
+  FILE_POSITION_ERROR, // Cannot obtain the current file position
+  FILE_READ_ERROR,     // Error reading file  
+  FILE_SEEK_ERROR,     // Error seeking in file
+  FILE_WRITE_ERROR,    // Error writing to file
+
+  FMGR_NO_DATABASE_OPEN,    // No database open
+  FMGR_NO_FILE_EXISTS,      // No such file exists
+  FMGR_NO_OBJECTS_EXIST,    // No objects exist
+  FMGR_NULL_PTR,            // Accessing a null pointer 
+  FMGR_OBJECT_EXISTS,       // Object already exists
+  FMGR_OPEN_FILE_REFERENCE, // Another object is referencing this file
+  FMGR_OVERFLOW,            // Math overflow
+  FMGR_PARSE_ERROR,         // Parse error
+  FMGR_PATH_ERROR,          // Invalid path
+  FMGR_READ_ONLY_FILE,      // Trying to write to read-only file
+  FMGR_STACK_EMPTY,         // Stack empty
+  FMGR_STACK_FULL,          // Stack full
+  FMGR_SYNC_ERROR,          // Synchronization Error
+  FMGR_UNDERFLOW,           // Math under-flow
+  FMGR_WRONG_FILE_TYPE,     // Wrong file type
+
+  // Persistent lock error codes
+  FMGR_INVALID_LOCK_TYPE,        // Invalid lock type specified
+  FMGR_FILELOCK_ACCESS_ERROR,    // The file lock cannot be accessed
+  FMGR_FILELOCK_ERROR,           // Error locking the file
+  FMGR_RECORDLOCK_ACCESS_ERROR,  // The record lock cannot be accessed
+  FMGR_RECORDLOCK_ERROR          // Error locking a record};
+
+
+};
+
+
+
+
+class DLL_CODE_API CFileBase 
+{
+protected:
+    // File I/O operation codes
+  enum IO_Op { 
+     IO_READ,         // A read was performed
+     IO_WRITE,        // A write operation was performed
+     IO_REWIND,       // A rewind operation was performed
+     IO_NO_OPERATION, // No operation was performed
+     IO_SEEK          // A seek operation was preformed 
+  };
+
+  _TCHAR            file_name[MaxNameLength];  // Open file name
+  FileSystem::FPTR* fp;                        // Stream file handle
+  IO_Op             last_operation;            // Last I/O operation preformed
+  FileError         file_error;                // Last reported file error
+
+  // File status members
+  int is_ok;             // Used to signal a fatal error condition
+  int is_open;           // True if the file is open
+  int ready_for_reading; // True if the file is ready for reading
+  int ready_for_writing; // True if the file is ready for writing
+
+
+public:
+   CFileBase();
+   virtual ~CFileBase();
+
+public: // File functions
+   virtual FileError Create(const TCHAR *fname);
+   virtual FileError Open(const TCHAR *fname, FileSystem::AccessMode mode = FileSystem::FILE_READWRITE); 
+   virtual FileError Close();
+   
+   FileError         Seek(FileSystem::FAU_t offset, FileSystem::SeekMode mode = FileSystem::FILE_SEEK_BEG);
+ 
+   FileError         Fetch(void* buf, isis::uint32_t nBytes, FileSystem::FAU_t file_addres = CURRADDR);
+   FileError         Store(const void* buf, isis::uint32_t nBytes, FileSystem::FAU_t file_address = CURRADDR,
+			                int flush_flag = 1, int bit_test = 1);
+
+   FileSystem::FAU_t     SeekTo(FileSystem::FAU_t file_address);
+   FileSystem::StreamPos FilePosition();
+
+   FileError Flush();
+
+   _TCHAR *FileName() { return file_name; }
+
+public: // 32-bit CRC checksum routines 
+  isis::uint32_t CalcChecksum(isis::uint32_t bytes, FileSystem::FAU_t file_address, int mem_alloc = 1);
+
+public:  // File Status functions
+  int IsOK()                  { return ((is_ok == 1) && (is_open == 1)); }
+  int IsOK()            const { return ((is_ok == 1) && (is_open == 1)); }
+  int IsOpen()                { return ((is_ok == 1) && (is_open == 1)); }
+  int IsOpen()          const { return ((is_ok == 1) && (is_open == 1)); }
+  int ReadyForReading()       { return ready_for_reading == 1; }
+  int ReadyForReading() const { return ready_for_reading == 1; }
+  int ReadyForWriting()       { return ready_for_writing == 1; }
+  int ReadyForWriting() const { return ready_for_writing == 1; }
+
+public:  // Exception handling functions
+  FileError   GetFileError()              { return file_error; }
+  FileError   GetFileError() const        { return file_error; }
+  void        SetFileError(FileError err) { file_error = err; }
+  void        ResetFileError()            { file_error = FILE_NO_ERROR; }
+  const TCHAR *FileExceptionMessage();
+
+public: // General purpose file utilities
+  static int Exists(const TCHAR *fname);
+  static FileSystem::FAU_t FileSize(const TCHAR *fname);
+  static int CanOpenForWriting(const TCHAR *fname);
+  static int CanOpenReadOnly(const TCHAR *fname);
+  
+};
+
+
+#ifdef __CPP_EXCEPTIONS__
+// Class declarations for exceptions representing program errors. 
+// This implementation is provided for use C++'s built-in exception
+// handling routines.
+
+class CFileBaseException 
+{
+	int error_;
+public:
+	CFileBaseException(int error) { error_ = error; }
+};  
+
+#endif // __CPP_EXCEPTIONS__
+ 
+#endif   // __FILE_BASE__
Index: /gsdl/trunk/build-src/packages/isis-gdl/FileSystem.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/FileSystem.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/FileSystem.cpp	(revision 16571)
@@ -0,0 +1,482 @@
+/**********************************************************************
+ *
+ * FileSystem.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////////////////////////////
+//
+// FileSystem -- The generic file pointer routines are a collection of member
+//               functions used to wrap  the underlying file system.
+
+
+#include "errno.h"
+#include "stdafx.h"
+#include "FileSystem.h"
+
+
+using namespace FileSystem;
+//---------------------------------------------------------------------
+// FileSystem::FPTR *Create(const _TCHAR *fname)
+//
+// Create a new file and truncate existing files.
+// Returns a null value if the file cannot be
+// created.
+//---------------------------------------------------------------------
+DLL_CODE_API FileSystem::FPTR *FileSystem::Create(const char *fname)
+{
+#if defined(__64_BIT_FILE_SYSTEM__)
+	return FS64Create(fname);
+	
+#elif defined(__WIN32__) && defined(__NTFS__)
+	FPTR *stream = new FPTR;
+	if (!stream)
+		return 0;
+	stream->fptr = CreateFile(fname, 
+		GENERIC_READ | GENERIC_WRITE, 
+		FILE_SHARE_READ | FILE_SHARE_WRITE, 
+		NULL, // No security
+		CREATE_ALWAYS, 
+		FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
+		NULL // No attr. template 
+		);
+	
+	if (stream->fptr == INVALID_HANDLE_VALUE)
+	{
+		delete stream;
+		return 0;
+	}
+	return stream;
+	
+#else // Use the 32-bit stdio version by default
+	FPTR *stream = new FPTR;
+	if (!stream)
+		return 0;
+	stream->fptr = fopen(fname, "w+b");
+	if (stream->fptr == 0)
+	{
+		delete stream; // 01/30/2002: Prevent memory leak
+		return 0;
+	}
+	return stream;
+#endif
+}
+
+//---------------------------------------------------------------------
+// FileSystem::FPTR *Open(const _TCHAR *fname, FileSystemAccessMode mode)
+//
+// Open an existing file. The "mode" variable determines if the file
+// is opened for read only or read/write access. Returns a null value
+// if the specified file cannot be opened. NOTE: This version of the
+// open functions will only accept: FILE_READONLY and FILE_READWRITE
+// access modes.
+//---------------------------------------------------------------------
+DLL_CODE_API FileSystem::FPTR *FileSystem::Open(const char *fname, FileSystem::AccessMode mode)
+{
+#if defined(__64_BIT_FILE_SYSTEM__)
+	return FSOpen(fname, mode);
+	
+#elif defined(__WIN32__) && defined(__NTFS__)
+	FPTR *stream = new FPTR;
+	if (!stream)
+		return 0;
+	if (mode == FILE_READONLY)
+	{
+		// Open for read only access
+		stream->fptr = CreateFile(fname, 
+			GENERIC_READ,
+			FILE_SHARE_READ | FILE_SHARE_WRITE, 
+			NULL, // No security
+			OPEN_EXISTING, 
+			FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, 
+			NULL // No attr. template 
+			);
+		if (stream->fptr == INVALID_HANDLE_VALUE)
+		{
+			delete stream;
+			return 0;
+		}
+	}
+	else 
+	{ // Open for read/write access
+		stream->fptr = CreateFile(fname, 
+			GENERIC_READ | GENERIC_WRITE, 
+			FILE_SHARE_READ | FILE_SHARE_WRITE, 
+			NULL, // No security 
+			OPEN_EXISTING, 
+			FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, 
+			NULL // No attr. template 
+			);
+		
+		if (stream->fptr == INVALID_HANDLE_VALUE)
+		{
+			delete stream;
+			return 0;
+		}
+	}
+	return stream;
+	
+#else // Use the 32-bit stdio version by default
+	FPTR *stream = new FPTR;
+	if (!stream)
+		return 0;
+	
+	if (mode == FILE_READONLY)
+	{
+		// Open for read only access
+		stream->fptr = fopen(fname, "rb");
+		if (stream->fptr == 0)
+		{
+			delete stream; // 01/30/2002: Prevent memory leak
+			return 0;
+		}
+	}
+	else 
+	{ // Open for read/write access
+		stream->fptr = fopen(fname, "r+b");
+		if (stream->fptr == 0)
+		{
+			delete stream; // 01/30/2002: Prevent memory leak
+			return 0;
+		}
+	}
+	return stream;
+#endif
+}
+
+//---------------------------------------------------------------------
+// int Close(FileSystem::FPTR *stream)
+//
+// Close an open file. Returns a non-zero value to  indicate an error 
+// condition or zero if successful.
+//---------------------------------------------------------------------
+DLL_CODE_API int FileSystem::Close(FPTR *stream)
+{
+	if (!stream)
+		return 0; // The file stream is not open
+	
+#if defined(__64_BIT_FILE_SYSTEM__)
+	return FS64Close(stream);
+	
+#elif defined(__WIN32__) && defined(__NTFS__)
+	if (!CloseHandle(stream->fptr))
+		return 1;
+	delete stream;
+	stream = 0;
+	return 0;
+	
+#else // Use the 32-bit stdio version by default
+	if (fclose(stream->fptr) != 0)
+		return 1;
+	delete stream;
+	stream = 0; // 02/02/2002: Set pointer to zero after releasing it
+	return 0;
+#endif
+}
+
+//-----------------------------------------------------------------------------
+// int Flush(FileSystem::FPTR *stream)
+//
+// Flush the any open disk buffers. Returns a non-zero value to indicate
+// an error // condition or zero if successful. 
+//
+// ATTENTION: ****MS VC++*** YOU SHOULD LINK YOUR APPLICATION WITH COMMODE.OBJ 
+// file. COMMODE.OBJ changes the global commit flag such that 
+// calling fflush() or _flushall() commits the file buffer to disk.
+// The Windows NT operating system provides the WIN32 API FlushFileBuffers().
+// The _commit() function included with the Visual C++ 32-bit Edition 
+// CRT calls FlushFileBuffers to write buffered data to disk. 
+//-----------------------------------------------------------------------------
+DLL_CODE_API int FileSystem::Flush(FPTR *stream)
+{
+	if (!stream)
+		return 0; // The file stream is not open
+	
+#if defined(__64_BIT_FILE_SYSTEM__)
+	return FS64Flush(stream);
+	
+#elif defined(__WIN32__) && defined(__NTFS__)
+	if (!FlushFileBuffers(stream->fptr))
+		return 1;
+	return 0;
+	
+#else // Use the 32-bit stdio version by default
+	int ret = fflush(stream->fptr);
+	if (ret != 0)
+	{
+		TRACE("\nerrno=%d\n\n\n", errno);
+		return 1;       // Error
+	}
+	else
+		return 0;
+#endif
+}
+
+//---------------------------------------------------------------------
+// int Read(FileSystem::FPTR *stream, void *buf, isis::uint32_t bytes)
+//
+// Read a specified number of bytes from the current file position
+// into a memory buffer. Returns the total number if bytes read from the
+// file.
+//---------------------------------------------------------------------
+DLL_CODE_API isis::ulong32_t FileSystem::Read(FPTR *stream, void *buf, 
+											  isis::ulong32_t bytes)
+{
+	if (!stream)
+		return (isis::ulong32_t)0; // The file stream is not open
+	
+#if defined(__64_BIT_FILE_SYSTEM__)
+	return FS64Read(stream, buf, bytes);
+	
+#elif defined(__WIN32__) && defined(__NTFS__)
+	DWORD bytes_read; 
+	if (!ReadFile(stream->fptr, (LPVOID)buf, (DWORD)bytes, &bytes_read, NULL))
+	{
+		return (isis::ulong32_t)0;
+	}
+	return (isis::ulong32_t)bytes_read;
+	
+#else // Use the 32-bit stdio version by default
+	return (isis::ulong32_t)fread((unsigned char *)buf, 1, bytes, stream->fptr);
+#endif
+}
+//---------------------------------------------------------------------
+// int Write(FileSystem::FPTR *stream, const void *buf, isis::uint32_t bytes) 
+//
+// Write a specific number of bytes from a memory buffer to the
+// current file position. Returns the total number if bytes written
+// to the file.
+//---------------------------------------------------------------------
+DLL_CODE_API isis::ulong32_t FileSystem::Write(FPTR *stream, const void *buf, 
+				                   isis::ulong32_t bytes) 
+{
+	if (!stream)
+		return (isis::ulong32_t)0; // The file stream is not open
+	
+#if defined(__64_BIT_FILE_SYSTEM__)
+	return FS64Write(stream, buf, bytes);
+	
+#elif defined(__WIN32__) && defined(__NTFS__)
+	DWORD bytes_moved; 
+	if (!WriteFile(stream->fptr, (LPVOID)buf, (DWORD)bytes, &bytes_moved, NULL))
+	{
+		return (isis::ulong32_t)0;
+	}
+	return (isis::ulong32_t)bytes_moved;
+	
+#else // Use the 32-bit stdio version by default
+	return (isis::ulong32_t)fwrite((const unsigned char *)buf, 1, bytes, stream->fptr);
+#endif
+}
+//---------------------------------------------------------------------------
+// isis::int32_t Seek(FileSystem::FPTR *stream, isis::int32_t offset,  FileSystemSeekMode mode)
+//
+// Seek to the specified offset starting at the beginning (SEEK_SET),
+// end (SEEK_END) or current offset (SEEK_CUR). Returns a negative 1
+// to indicate an error condition or the current stream position if
+// successful.
+//----------------------------------------------------------------------------
+DLL_CODE_API FAU_t FileSystem::Seek(FPTR *stream, FAU_t offset, FileSystem::SeekMode mode)
+{
+	if (!stream)
+		return (FAU_t) - 1; // The file stream is not open
+	
+#if defined(__64_BIT_FILE_SYSTEM__)
+	return FS64Seek(stream, offset, mode);
+	
+#elif defined(__WIN32__) && defined(__NTFS__)
+	if (mode == FILE_SEEK_BEG)
+	{
+		return (FAU_t)SetFilePointer(stream->fptr, offset, NULL, FILE_BEGIN);
+	}
+	else if (mode == FILE_SEEK_CUR)
+	{
+		return (FAU_t)SetFilePointer(stream->fptr, offset, NULL, FILE_CURRENT);
+	}
+	else if (mode == FILE_SEEK_END)
+	{
+		return (FAU_t)SetFilePointer(stream->fptr, offset, NULL, FILE_END);
+	}
+	else 
+	{ // An invalid seek mode was specified
+		return (FAU_t) - 1;
+	}
+	
+#else // Use the 32-bit stdio version by default
+	if (mode == FILE_SEEK_BEG)
+	{
+		return fseek(stream->fptr, offset, SEEK_SET);
+	}
+	else if (mode == FILE_SEEK_CUR)
+	{
+		return fseek(stream->fptr, offset, SEEK_CUR);
+	}
+	else if (mode == FILE_SEEK_END)
+	{
+		return fseek(stream->fptr, offset, SEEK_CUR);
+	}
+	else 
+	{ // An invalid seek mode was specified
+		return (FAU_t) - 1;
+	}
+#endif
+}
+//----------------------------------------------------------------------------
+// isis::int32_t Tell(FileSystem::FPTR *stream)
+//
+//----------------------------------------------------------------------------
+DLL_CODE_API FAU_t FileSystem::Tell(FPTR *stream)
+{
+	if (!stream)
+		return (FAU_t) - 1; // The file stream is not open
+	
+#if defined(__64_BIT_FILE_SYSTEM__)
+	return FS64Tell(stream);
+	
+#elif defined(__WIN32__) && defined(__NTFS__)
+	return (__LWORD__)SetFilePointer(stream->fptr, 0, NULL, FILE_CURRENT);
+	
+#else // Use the 32-bit stdio version by default
+	return ftell(stream->fptr);
+#endif
+}
+
+//----------------------------------------------------------------------------
+// int Exists(const char *fname)
+//
+// Returns true if the specified file exists.
+//----------------------------------------------------------------------------
+DLL_CODE_API int FileSystem::Exists(const char *fname)
+// Returns true if the specified file exists.
+{
+#if defined(__64_BIT_FILE_SYSTEM__)
+	return FS64Exists(fname);
+	
+#elif defined(__WIN32__) && defined(__NTFS__)
+	HANDLE hFile = CreateFile(fname, 
+		GENERIC_READ,
+		FILE_SHARE_READ | FILE_SHARE_WRITE, 
+		NULL, // No security
+		OPEN_EXISTING, 
+		FILE_ATTRIBUTE_NORMAL, 
+		NULL // No attr. template
+		);
+	
+	if (hFile == INVALID_HANDLE_VALUE)
+	{
+		return 0;
+	}
+	
+	CloseHandle(hFile);
+	return 1;
+	
+#else // Use the 32-bit stdio version by default
+	struct stat buf;
+	return stat(fname, &buf) ==(FAU_t)0;
+#endif
+}
+
+
+
+//----------------------------------------------------------------------------
+// FAU_t FileSize(const _TCHAR *fname)
+//
+// Returns the length of the specified file or negative 1 to indicate an
+// error condition.
+//----------------------------------------------------------------------------
+DLL_CODE_API FAU_t FileSystem::FileSize(const char *fname)
+{
+#if defined(__64_BIT_FILE_SYSTEM__)
+	return FS64FileSize(fname);
+	
+#elif defined(__WIN32__) && defined(__NTFS__)
+	HANDLE hFile = CreateFile(fname, 
+		GENERIC_READ,
+		FILE_SHARE_READ | FILE_SHARE_WRITE, 
+		NULL, // No security
+		OPEN_EXISTING, 
+		FILE_ATTRIBUTE_NORMAL, 
+		NULL // No attr. template 
+		);
+	
+	// Could not open the specified file
+	if (hFile == INVALID_HANDLE_VALUE)
+	{
+		return (FAU_t) - 1;
+	}
+	
+	BY_HANDLE_FILE_INFORMATION info;
+	
+	if (GetFileInformationByHandle(hFile, &info) == 0)
+	{
+		return (FAU_t) - 1;
+	}
+	CloseHandle(hFile);
+	return (FAU_t)info.nFileSizeLow;;
+	
+#else // Use the 32-bit stdio version by default
+	struct stat buf;
+	int result = stat(fname, &buf);
+	if (result != 0)
+		return -1;
+	return buf.st_size;
+#endif
+}
+
+//  #include <io.h>
+//  #include <share.h>
+
+
+//  int FileSystem::CanOpenForWriting(const _TCHAR *fname)
+//  {
+//  	// Try to open for writing
+//  	int fd = _tsopen(fname, _O_WRONLY | O_BINARY, _SH_DENYWR);
+//  	if (fd == -1)
+//  		return 0;
+//  	_close(fd);
+//  	return 1;
+//  }
+
+//  int FileSystem::CanOpenReadOnly(const _TCHAR *fname)
+//  {
+//  	// Try to open for read only
+//  	int fd = _tsopen(fname, _O_RDONLY | O_BINARY, _SH_DENYNO);
+//  	if (fd == -1)
+//  		return 0;
+//  	_close(fd);
+//  	return 1;
+//  }
+
+//----------------------------------------------------------------------------
+// int IsReadOnly(const _TCHAR* fname)
+//
+// Returns true if the specified file is read only.
+//----------------------------------------------------------------------------
+//  int FileSystem::IsReadOnly(const _TCHAR *fname)
+//  {
+//  	struct _stat buf;
+//  	_tstat(fname, &buf);
+//  	if (buf.st_mode & S_IWRITE)
+//  		return 0;
+//  	return 1;
+//  }
+
Index: /gsdl/trunk/build-src/packages/isis-gdl/FileSystem.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/FileSystem.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/FileSystem.h	(revision 16571)
@@ -0,0 +1,121 @@
+/**********************************************************************
+ *
+ * FileSystem.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////////////////////////
+// FileSystem.h -- The generic file pointer routines are a collection of member
+//                 functions used to wrap  the underlying file system.
+
+//
+
+  
+#ifndef __FILE_SYSTEM__
+#define __FILE_SYSTEM__
+
+// Non-platform specific include files
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include "DLLCode.h"
+#include "IsisTypes.h"
+
+namespace FileSystem {
+	
+// ----------------
+// Type definitions 
+// ----------------
+// typedefs for 64-bit and 32-bit file operations and stream position
+#if defined (__64_BIT_FILE_SYSTEM__)
+    typedef isis::int64_t FAU;       // 64-bit File Address Unit, physical file address type
+    typedef isis::int64_t FAU_t;     // Native 64-bit FAU type
+    typedef isis::int64_t StreamPos; // 64-bit stream position
+#else // Use the 32-bit version by default
+	typedef isis::int32_t FAU;       // 32-bit File Address Unit, physical file address type
+	typedef isis::int32_t FAU_t;     // Native 32-bit FAU type
+	typedef isis::int32_t StreamPos; // 32-bit stream position
+#endif
+
+
+// Select the underlying file system 
+#if defined (__64_BIT_FILE_SYSTEM__)
+	#include "FS64.H"              // WIN32 will always use NTFS for large files
+	typedef  FPTR64 FPTR;
+
+
+#elif defined (__WIN32__) && defined (__NTFS__)
+	// WIN32 file I/O API
+	#include <windows.h>
+	#include <io.h>
+	#include <string.h>
+	#include <stdlib.h>
+	#include <fcntl.h>
+	#include <sys/types.h>
+	#include <sys/stat.h>
+	#include <stdio.h>
+	#include "gxdtypes.h"
+	#include "gxheader.h"
+
+	struct DLL_CODE_API FPTR { // Platform specific file pointer type
+		HANDLE fptr;
+	};
+
+#else // Use the stdio version by default. Common to all platforms.
+	// Non-platform specific stdio include files
+	#include <string.h>
+	#include <stdlib.h>
+	#include <fcntl.h>
+	#include <sys/types.h>
+	#include <sys/stat.h>
+	#include <stdio.h>
+	#include "IsisTypes.h"
+	//#include "gxheader.h"
+
+	struct DLL_CODE_API FPTR { // File pointer type
+		 FILE *fptr;
+	};
+#endif // File system type
+
+
+
+    // NOTE: Any underlying file system used must provide the basic
+    // functionallity defined here.
+    DLL_CODE_API FPTR            *Create(const char  *fname);
+    DLL_CODE_API FPTR            *Open(const char *fname, AccessMode mode);
+    DLL_CODE_API int             Close(FPTR *stream);
+    DLL_CODE_API int             Flush(FPTR *stream);
+    DLL_CODE_API isis::ulong32_t Read(FPTR *stream, void *buf, isis::ulong32_t bytes);
+    DLL_CODE_API isis::ulong32_t Write(FPTR *stream, const void *buf, isis::ulong32_t bytes);
+    DLL_CODE_API FAU_t           Seek(FPTR *stream, FAU_t, SeekMode mode);
+    DLL_CODE_API FAU_t           Tell(FPTR *stream);
+    DLL_CODE_API int             Exists(const _TCHAR *fname);
+    DLL_CODE_API FAU_t           FileSize(const _TCHAR *fname);
+    // DLL_CODE_API int             CanOpenForWriting(const _TCHAR *fname);
+    // DLL_CODE_API int             CanOpenReadOnly(const _TCHAR *fname);
+    // DLL_CODE_API int             IsReadOnly(const _TCHAR *fname);
+}
+
+#endif // __FILE_SYSTEM__
Index: /gsdl/trunk/build-src/packages/isis-gdl/IErrors.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/IErrors.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/IErrors.cpp	(revision 16571)
@@ -0,0 +1,113 @@
+/**********************************************************************
+ *
+ * IErrors.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////////////////////////////
+// Error.cpp
+
+// #include "stdafx.h"
+// The Error functions and classes are used to catch and/or
+// record database exceptions that occur during run-time. This
+// implementation can be used with or without C++ built-in exception
+// handling. If C++ exception handling is not enabled with the
+// __CPP_EXCEPTIONS__ macro, then the vbDatabaseError enumerated
+// constants can be used to record database errors.
+#include "IErrors.h"
+
+// NOTE: This array must contain the same number of exceptions as the
+// IsisError enumeration. 
+const int MaxExceptionMessages = 57;
+const char* isisExceptionMessages[MaxExceptionMessages] = {
+  "Database exception: No exception reported",               // None
+  "Database exception: Invalid error code reported",         // Invalid
+  "Database exception: Memory exhausted",
+  "Database exception: Error opening xrf file",
+  "Database exception: Error creating xrf file",
+  "Database exception: Error reading xrf file",
+  "Database exception: Error writing xrf file",
+  "Database exception: xrf file is corrupted",
+  "Database exception: xrf file, invalid block",
+  "Database exception: xrf file, invalid status",
+  "Database exception: Error creating an existing mf file",
+  "Database exception: Error opening mf file",
+  "Database exception: Error opening mf file",
+  "Database exception: Error creating mf file",
+  "Database exception: Error reading mf file",
+  "Database exception: Error writing mf file",
+  "Database exception: Access Violation",                    // AccessViolation
+  "Database exception: Assertion failed",                    // AssertError
+  "Database exception: Wrong object type",                   // BadClassID
+  "Database exception: Bad object address",                  // BadObjectAddress
+  "Database exception: Bad reference",                       // BadReference
+  "Database exception: Cache full",                          // CacheFull
+  "Database exception: Checksum error",                      // ChecksumError
+  "Database exception: Divide by zero error",                // DivideByZero
+  "Database exception: Unexpected end of file was reached",  // EOFError
+  "Database exception: Error closing file",                  // FileCloseError
+  "Database exception: File is corrupt",                     // FileCorrupt
+  "Database exception: Error creating file",                 // CreationError
+  "Database exception: File already exists",                 // FileExists
+  "Database exception: Trying to use a closed file",         // FileNotOpenError
+  "Database exception: File not ready for reading/writing",  // FileNotReady
+  "Database exception: Could not write to file",             // NotWriteable
+  "Database exception: Error opening file",                  // FileOpenError
+  "Database exception: Cannot obtain a file position",       // FilePostionError
+  "Database exception: Error reading from file",             // FileReadError
+  "Database exception: Error seeking in file",               // FileSeekError
+  "Database exception: Error writing to file",               // FileWriteError
+  "Database exception: No database open",                    // NoDatabaseOpen
+  "Database exception: No such file exists",                 // NoFileExists
+  "Database exception: No objects exist",                    // NoObjectsExist
+  "Database exception: Accessing a null pointer",            // NullPtr
+  "Database exception: Object already exists",               // ObjectExists
+  "Database exception: Another object is referencing this file", // Referenced
+  "Database exception: Math overflow error",                 // OverFlow
+  "Database exception: Parse error",                         // ParseError
+  "Database exception: Invalid path",                        // PathError
+  "Database exception: Trying to write to a read-only file", // ReadOnlyFile
+  "Database exception: Stack empty",                         // StackEmpty
+  "Database exception: Stack full",                          // StackFull
+  "Database exception: Synchronization Error",               // SyncError    
+  "Database exception: Math under-flow error",               // UnderFlow
+  "Database exception: Wrong file type",                     // WrongFileType
+
+  // Persistent lock error messages
+  "Database exception: Invalid lock type specified",          // LOCK_TYPE
+  "Database exception: Cannot access the file lock header",   // FLK_ACCESS
+  "Database exception: Cannot lock the file",                 // FLK_ERROR
+  "Database exception: Cannot access the record lock header", // RLK_ACCESS
+  "Database exception: Cannot lock the specified record"      // RLK_ERROR
+};
+
+const char *isisExceptionMessage(IsisError err)
+// Standalone function that returns a null terminated string that can
+// be use to log or print a database exception message.
+{
+  int error = (int)err;
+  if(error > MaxExceptionMessages) error = ISIS_INVALID_CODE;
+
+  // Find the corresponding message in the exception array
+  return isisExceptionMessages[error];
+}
+
Index: /gsdl/trunk/build-src/packages/isis-gdl/IErrors.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/IErrors.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/IErrors.h	(revision 16571)
@@ -0,0 +1,104 @@
+/**********************************************************************
+ *
+ * IErrors.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef __ISIS_ERROR_H__
+#define __ISIS_ERROR_H__
+
+enum IsisError { // Database error codes
+  ISIS_NO_ERROR = 0,        // No errors reported
+  ISIS_INVALID_CODE,
+  ISIS_BAD_ALLOC,
+  ISIS_XRF_OPEN_ERROR,      // Xrf open error
+  ISIS_XRF_CREATE_ERROR,    // Xrf creation error
+  ISIS_XRF_READ_ERROR,      // Xrf read error
+  ISIS_XRF_WRITE_ERROR,     // Xrf write error
+  ISIS_XRF_CORRUPT,         // Xrf corrupted
+  ISIS_XRF_INVALID_BLOCK,   // Xrf invalid block
+  ISIS_XRF_INVALID_STATUS,  // Xrf invalid status
+  ISIS_MF_ALREADY_EXIST_ERROR, // Attempt to create an existing mf
+  ISIS_MF_OPEN_ERROR,       // Mf open error
+  ISIS_MF_CREATE_ERROR,     // Mf creation error
+  ISIS_MF_READ_ERROR,       // Mf read error
+  ISIS_MF_WRITE_ERROR,      // Mf write error 
+  ISIS_ASSERT_ERROR,        // Assertion failed
+  ISIS_BAD_CLASS_ID,        // Wrong object type
+  ISIS_BAD_OBJECT_ADDRESS,  // Bad object address  ISIS_BAD_REFERENCE,       // Bad Reference
+  ISIS_CACHE_FULL,          // Cache full
+  ISIS_CHECKSUM_ERROR,      // Checksum Error
+  ISIS_DIVIDEBY_ZERO,       // Divide By Zero Error
+  ISIS_EOF_ERROR,           // Unexpected end of file
+  ISIS_FILE_CLOSE_ERROR,    // Error closing file
+  ISIS_FILE_CORRUPT,        // File corrupted
+  ISIS_FILE_CREATION_ERROR, // Error creating file
+  ISIS_FILE_EXISTS,         // File already exists
+  ISIS_FILE_NOT_OPEN_ERROR, // Trying to use a closed file
+  ISIS_FILE_NOT_READY,      // File not ready (failed or closed file)
+  ISIS_FILE_NOT_WRITEABLE,  // Could not write to file 
+  ISIS_FILE_OPEN_ERROR,     // Error opening file
+  ISIS_FILE_POSITION_ERROR, // Cannot obtain the current file position
+  ISIS_FILE_READ_ERROR,     // Error reading file  
+  ISIS_FILE_SEEK_ERROR,     // Error seeking in file
+  ISIS_FILE_WRITE_ERROR,    // Error writing to file
+  ISIS_NO_DATABASE_OPEN,    // No database open
+  ISIS_NO_FILE_EXISTS,      // No such file exists
+  ISIS_NO_OBJECTS_EXIST,    // No objects exist
+  ISIS_NULL_PTR,            // Accessing a null pointer 
+  ISIS_OBJECT_EXISTS,       // Object already exists
+  ISIS_OPEN_FILE_REFERENCE, // Another object is referencing this file
+  ISIS_OVERFLOW,            // Math overflow
+  ISIS_PARSE_ERROR,         // Parse error
+  ISIS_PATH_ERROR,          // Invalid path
+  ISIS_READ_ONLY_FILE,      // Trying to write to read-only file
+  ISIS_STACK_EMPTY,         // Stack empty
+  ISIS_STACK_FULL,          // Stack full
+  ISIS_SYNC_ERROR,          // Synchronization Error
+  ISIS_UNDERFLOW,           // Math under-flow
+  ISIS_WRONG_FILE_TYPE,     // Wrong file type
+
+  // Persistent lock error codes
+  ISIS_INVALID_LOCK_TYPE,        // Invalid lock type specified
+  ISIS_MFLOCK_ACCESS_ERROR,    // The file lock cannot be accessed
+  ISIS_MFLOCK_ERROR,           // Error locking the file
+  ISIS_RECORDLOCK_ACCESS_ERROR,  // The record lock cannot be accessed
+  ISIS_RECORDLOCK_ERROR          // Error locking a record
+};
+
+// Standalone functions use to report database errors
+const char *isisExceptionMessage(IsisError err);
+
+#ifdef __CPP_EXCEPTIONS__
+// Class declarations for exceptions representing program errors. 
+// This implementation is provided for use C++'s built-in exception
+// handling routines.
+
+// A fatal file error condition has been reached. All database engine
+// calls must catch this exception and evaluate it by testing the
+// vbDatabase or vbDatabase64 internal error variable.
+class CIsisException { };  
+
+#endif // __CPP_EXCEPTIONS__
+
+#endif // __ISIS_ERROR_H__
Index: /gsdl/trunk/build-src/packages/isis-gdl/IsisDb.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/IsisDb.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/IsisDb.cpp	(revision 16571)
@@ -0,0 +1,252 @@
+/**********************************************************************
+ *
+ * IsisDb.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////
+// ISISDB: Isis Master file methods
+////////////////////////////////////////////////////////////
+#include "stdafx.h"
+#include "IsisDb.h"
+#include "XRFFile.h"
+
+
+
+//-------------------------------------------------------------------------------- 
+// IsisDb::IsisDb()
+//
+// Constructor, Makes an ISIS Data Base object that isn't connected to a Master 
+// file, Cross Reference file and Fdt.
+//-------------------------------------------------------------------------------
+IsisDb::IsisDb()
+{
+	bReadOnly_ = false;
+	try
+	{
+        mf_  = new MfFile;
+	    xf_  = new XrfFile; 
+	    fdt_ = new CFdt;
+	}
+	catch(std::bad_alloc)
+	{
+		throw CIsisDbException(ISIS_BAD_ALLOC, __FILE__, __LINE__);
+	}
+}
+ 
+//////////////////////////////
+ 
+IsisDb::~IsisDb( )
+{
+   delete mf_; delete xf_; delete fdt_;
+}
+ 
+ 
+//////////////////////////////
+ 
+int IsisDb::CreateDb(const TCHAR *fname)
+{
+   name = fname;
+   MkNames();
+   int rc = ISIS_NO_ERROR;
+
+   // We should not try to create a mf_ which already exist!
+   if (CFileBase::Exists(mfname_))
+   {
+	   throw CIsisDbException(ISIS_MF_ALREADY_EXIST_ERROR, __FILE__, __LINE__);
+   }
+   else
+   {
+       try
+	   {
+           rc = mf_->CreateMf(mfname_, USERMST);   
+           rc = xf_->CreateXrf(xrfname_);
+           rc = fdt_->Load(fdtname_);
+	   }
+       catch(CIsisDbException)
+	   {
+    	   throw CIsisDbException(ISIS_MF_OPEN_ERROR, __FILE__, __LINE__);
+	   }
+   }
+   
+   return rc;
+}
+ 
+ 
+//////////////////////////////
+ 
+void IsisDb::CloseDb()
+{
+   mf_->CloseMf();
+   xf_->Close();
+}
+ 
+//////////////////////////////
+ 
+void IsisDb::MkNames()
+// Make file names
+{
+    const _TCHAR *s = name.c_str();
+	_TCHAR *ps = new _TCHAR[_tcslen(s)+1];
+	_tcscpy(ps, s);
+	_TCHAR * tmp = _tcsrchr(ps, _T('.'));
+	assert(tmp != NULL);
+    // Terminate the string at the last dot 
+    *tmp = _T('\0');
+
+   _tcscpy(mfname_,ps);
+   _tcscat(mfname_,_T(".mst"));
+   _tcscpy(xrfname_,ps);
+   _tcscat(xrfname_,_T(".xrf"));
+   _tcscpy(fdtname_,ps);
+   _tcscat(fdtname_,_T(".fdt"));
+   _tcscpy(idxname_,ps);
+   _tcscat(idxname_,_T(".idx"));
+   delete[] ps;
+}
+ 
+//////////////////////////////
+ 
+int IsisDb::OpenDb(const TCHAR *fname,  FileSystem::AccessMode mode
+				                              /* = FileSystem::FILE_READWRITE */)
+{
+   name = fname;
+   MkNames();
+   int rc;
+   try
+   {
+     // if (FileSystem::IsReadOnly(mfname_))
+     //	   mode = FileSystem::FILE_READONLY;
+       rc = mf_->OpenMf(mfname_, mode);
+       rc = xf_->OpenXrf(xrfname_, mode);
+       rc = fdt_->Load(fdtname_);
+   }
+   catch(CIsisDbException)
+   {
+	   throw CIsisDbException(ISIS_MF_OPEN_ERROR, __FILE__, __LINE__);
+   }
+
+   return rc;
+}
+ 
+//----------------------------------------------------------------------------------
+// int  IsisDb::ReadDbRecord(long mfn, MfRecord &m)
+//
+// This function reads Master File record with MFN "mfn" into m
+//
+// Returns the status of the record: 
+// Active=0, LogicalyDeleted=1, PhysicalyDeleted=2, EndOfFile=-1, NewRecord = 3
+//----------------------------------------------------------------------------------
+int  IsisDb::ReadDbRecord(long mfn, MfRecord &m)
+{
+   long mfb;
+   int mfp;
+   int status;
+   bool rc;
+
+   try
+   {
+       status = xf_->GetMfp(mfn, mfb, mfp);
+       if (status == Active || status == LogicalyDeleted)
+	       if (!mf_->ReadMfRecord(mfb, mfp, m))
+			   status = -1;    // Error in reading the record!
+   }
+   catch(CIsisDbException)
+   {
+	   throw CIsisDbException(ISIS_MF_OPEN_ERROR, __FILE__, __LINE__);
+   }
+   return status;
+}
+ 
+//--------------------------------------------------------------------------------
+// void CreateDbRecord(MfRecord &m)
+//
+// Create a new record at the end of the master file. The Master file address is
+// set into the pair mfb/mfp and the XRF file is updated.
+//---------------------------------------------------------------------------------
+ void IsisDb::CreateDbRecord(MfRecord &m)
+{
+ 
+}
+
+//--------------------------------------------------------------------------------
+// void CreateDbRecordWithMfn(MfRecord &m)
+//
+// Create a new record at the end of the master file. The Master file address is
+// set into the pair mfb/mfp and the XRF file is updated.
+//---------------------------------------------------------------------------------
+ void IsisDb::CreateDbRecordWithMfn(MfRecord &m)
+{
+ 
+}
+
+ 
+//----------------------------------------------------------------------------------
+// void  UpdateDbRecord(MfRecord &m)
+//
+// Update of existing records. Whenever a record is updated, the system writes
+// the record back to the master file. Where it is written depends on the status
+// of the record when it was initially read.
+//
+//----------------------------------------------------------------------------------
+ void  IsisDb::UpdateDbRecord(MfRecord &m)
+{
+}
+//----------------------------------------------------------------------------------
+// int  IsisDb::DeleteRecord(long mfn)
+//
+// This function logically deletes a Master File record with MFN "mfn".
+// On XRF, xrfmfb is negative and on MST, status is set to 1
+//
+// Returns true if successful 
+//----------------------------------------------------------------------------------
+bool  IsisDb::DeleteRecord(long mfn)
+{
+
+   return false;
+}
+
+long  IsisDb::GetNextActiveMfn(long mfn /* = -1 */)
+{
+	if (mfn == -1)
+		mfn = 1;
+	else
+		mfn++;
+	long  mfb;
+	int  mfp;
+	int iRet = xf_->GetMfp(mfn, mfb, mfp);
+	while (iRet != Active && iRet != EndOfFile)
+	{
+		mfn++;
+        iRet = xf_->GetMfp(mfn, mfb, mfp);
+	}
+	if (iRet == EndOfFile)
+		return 0;
+	else
+		return mfn;
+}
+	
+_TCHAR *IsisDb::GetIdxFileName()
+{
+	return idxname_;
+}
+
Index: /gsdl/trunk/build-src/packages/isis-gdl/IsisDb.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/IsisDb.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/IsisDb.h	(revision 16571)
@@ -0,0 +1,130 @@
+/**********************************************************************
+ *
+ * IsisDb.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////
+// Isisdb.h : Class Definition for an ISIS db
+////////////////////////////////////////////////////////////
+ 
+#ifndef __ISISDB_H__
+#define __ISISDB_H__
+
+#include "AbstractIsisDb.h"
+#include "IsisDef.h"
+#ifndef _MFFILE_H_
+#include "MFFile.h"
+#endif
+
+ 
+class IsisDb : public AbstractIsisDb
+{
+	friend class CDBaseFile;
+
+	bool  bReadOnly_;
+    TCHAR xrfname_[_MAX_PATH];
+    TCHAR mfname_[_MAX_PATH];
+    TCHAR fdtname_[_MAX_PATH];
+    TCHAR idxname_[_MAX_PATH];
+protected:
+   void MkNames();
+public:
+   IsisDb();
+   virtual ~IsisDb( );
+   int OpenDb(const TCHAR *fname, FileSystem::AccessMode mode =
+	                                          FileSystem::FILE_READWRITE);
+   int CreateDb(const TCHAR *fname);
+
+
+// Closing the database
+   virtual void CloseDb();       // Close the db
+
+   virtual void ClearDb()   { }    // Clear the db
+   virtual void DestroyDb() { }  // Delete the db
+
+// Recovery
+   virtual bool IsDamaged() { return false;}   // Test if the database is damaged
+   virtual bool Recover()   { return true; }   // Recover the db
+
+// Transactions
+   virtual void BeginTransaction()    { }  // Begin a transaction
+   virtual void CommitTRansaction()   { }  // Commit a transaction
+   virtual void RollbackTransaction() { }  // Rollback a transaction
+   virtual bool InTransaction()       { return false; }  // Test if transaction is pending
+
+   virtual void CreateIndex(int i) { }
+   virtual void DropIndex(int i)   { }
+
+   void  CreateDbRecord(MfRecord &m);
+   void  CreateDbRecordWithMfn(MfRecord &m);
+   void  UpdateDbRecord(MfRecord &m);
+   bool  DeleteRecord(long mfn);
+   int   ReadDbRecord(long mfn, MfRecord &m);
+   int   ReadNextDbRecord(MfRecord &m);
+   void  PrintDbRecord(MfRecord &m);
+   void  PrintDbHdr();
+
+   void SetNextMfn(long mfn) { mf_->setNextMfn(mfn); }
+   long GetNextMfn()        { return mf_->GetNextMfn(); }
+   long GetNextActiveMfn(long mfn=-1);
+
+   SMfHeader& GetSMfHeader() { return mf_->GetSMfHeader(); }
+   _TCHAR *GetIdxFileName();
+
+   bool IsReadOnly() { return bReadOnly_; }
+};
+ 
+//////////////////////////////
+ 
+inline int IsisDb::ReadNextDbRecord(MfRecord &m)
+{
+   return 1;
+}
+ 
+//////////////////////////////
+ 
+inline void  IsisDb::PrintDbRecord(MfRecord &m)
+{
+   mf_->PrintMfRecord(m);
+}
+ 
+//////////////////////////////
+ 
+inline void  IsisDb::PrintDbHdr()
+{
+   mf_->PrintMfHdr();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+class IsisDbFactory : public AbstractIsisDbFactory
+{
+public:
+	virtual AbstractIsisDb* MakeIsisDb() { return new IsisDb(); }
+};
+
+/////////////////////////////////////////////////////////////////////////////////
+
+
+
+#endif
Index: /gsdl/trunk/build-src/packages/isis-gdl/IsisDef.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/IsisDef.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/IsisDef.h	(revision 16571)
@@ -0,0 +1,138 @@
+/**********************************************************************
+ *
+ * IsisDef.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef __ISIS_DEFINITION_H__
+#define __ISIS_DEFINITION_H__
+
+// disable warning C4786: symbol greater than 255 character,
+// okay to ignore
+#pragma warning(disable: 4786)
+
+#ifndef __ISIS_TYPE_H__
+#include "IsisTypes.h"
+#endif
+
+#include <sstream>
+
+typedef std::string ustring;
+typedef std::string cstring;
+// typedef std::wstring awstring;
+typedef std::stringstream ustringstream;
+typedef std::stringstream cstringstream;
+typedef wchar_t WCHAR;
+
+
+const size_t INVALID_NPOS = ~(size_t)0;
+
+namespace FileSystem {
+    // Generic File access/open mode enumeration
+    enum AccessMode { 
+       FILE_READONLY,   // Open file with read access only
+       FILE_WRITEONLY,  // Open file with write access only
+       FILE_READWRITE,  // Open file with read and write access
+       FILE_CREATE,     // Create the file if it does not exist
+       FILE_NO_CREATE,  // Do not create the file if it does not exist
+       FILE_TRUNCATE,   // Truncate the file  
+       FILE_APPEND,     // Append to the file
+       FILE_SHARE,      // Enable file sharing  (Platform specific)
+       FILE_EXCLUSIVE   // Disable file sharing (Platform specific)
+	};
+
+
+    // Generic File seek mode enumeration
+    enum SeekMode { 
+      FILE_SEEK_BEG, // Seek starting from the beginning of the file
+      FILE_SEEK_CUR, // Seek starting from the current location
+      FILE_SEEK_END  // Seek starting from the end of the file
+    };
+};
+
+#ifndef __FILE_SYSTEM__
+#include "FileSystem.h"
+#endif
+
+#ifndef __FILE_BASE__
+#include "File.h"
+#endif
+
+#ifndef __ISIS_ERROR_H__
+#include "IErrors.h"
+#endif
+
+#ifdef _WIN32
+#ifndef __DEBUG_H__
+#define _DEBUG
+#define _CONSOLE
+#include "debug.h"
+#endif
+#endif
+
+#ifndef __ABSTRACT_ISISDB_H__
+#include "AbstractIsisDb.h"
+#endif
+
+#ifndef __ISISDB_H__
+#include "IsisDb.h"
+#endif
+
+
+#ifndef __MASTER_RECORD_H__
+#include "Master.h"
+#endif
+
+#ifndef __FDT_H__
+#include "Fdt.h"
+#endif
+
+
+enum { RecordDeleted=0, RecordUpdated=1, RecordCreated=2};
+enum { Active=0, LogicalyDeleted=1, PhysicalyDeleted=2,
+       EndOfFile=-1, NewRecord = 3 };
+
+
+
+
+// Class declarations for exceptions representing program errors. 
+// This implementation is provided for use C++'s built-in exception
+// handling routines.
+
+class CIsisDbException { 
+public:
+	int m_iError;
+	CIsisDbException(const int iError, const char* file_name, const long line_number) 
+	{
+		m_iError = iError;
+#ifdef _WIN32
+		AssertFailed(isisExceptionMessage((IsisError) m_iError), file_name, line_number);
+#else
+		std::cout << isisExceptionMessage((IsisError) m_iError) << file_name
+			      << " Line=" << line_number;
+#endif
+	}
+};  
+
+
+#endif // __ISIS_DEFINITION_H__
Index: /gsdl/trunk/build-src/packages/isis-gdl/IsisGdl.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/IsisGdl.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/IsisGdl.cpp	(revision 16571)
@@ -0,0 +1,135 @@
+/**********************************************************************
+ *
+ * IsisGdl.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+// IsisGdl.cpp : Defines the entry point for the console application.
+//
+
+#include "stdafx.h"
+#include "IsisDb.h"
+#include <iostream>
+
+void PausePrg()
+{
+	std::cout << "\n";
+	std::cout << "Press enter to continue..." << "\n";
+	std::cin.get();
+}
+
+void ClearInputStream(std::istream &s)
+// Used to clear istream
+{
+	char c;
+	s.clear();
+	while(s.get(c) && c != '\n') { ; }
+}
+
+// Should be called with the master file name as parameter
+// IsisGdl "full_path\master_file_name" 
+// IsisGdl C:\IsisGdl\cds.mst for ex
+
+
+int main(int argc, _TCHAR* argv[])
+{
+
+	if (argc < 2 || argc > 3)
+	{
+		std::cout << "usage: IsisGdl [-include_logically_deleted_records] master_file_full_name" << std::endl;
+		return 1;
+	}
+	// Instantiation of the IsisDb Object
+	IsisDb db;
+	try
+	{
+		// The file name should be prefixed with the full path
+		// and should be the master file name with extension ".mst"
+		// "C:\IsisGdl\cds.mst" for ex
+		db.OpenDb(argv[argc - 1]);
+	}
+	catch(CIsisDbException e)
+	{
+		std::string msg = "Cannot open isis db: ";
+		msg += argv[argc - 1];
+		msg += isisExceptionMessage((IsisError) e.m_iError);
+		std::cerr<< msg << std::endl;
+		return false;
+	}
+
+	// Create a Master File object without the Field Definition
+	// Information
+	MfRecord mfr(0); 
+
+	// Extract the number of the next master file number to
+	// assign
+	const long nextMfn = db.GetNextMfn();
+
+
+
+	// Browse the master file in increasing order of Master
+	// file numbers (MFN is the record ID)
+	for (long i=1; i<nextMfn; i++)
+	{
+
+		int status = db.ReadDbRecord(i, mfr);
+
+		if (status == Active || (strcmp(argv[1], "-include_logically_deleted_records") == 0 && status == LogicalyDeleted))
+		{
+			// If the record is physically on the master file
+			// then get the vector of field tags.
+			
+			// 1) Repetitive fields have the same tag and are stored in
+			//    a single field but are separated by the "%" char
+			// 2) Subfields are separated by "^"letter (^a ^b ^c ...)
+			//
+			// 3) Terms or Phrases between "<>" are terms/Phrases to 
+			//    index
+			std::vector<int> vf = mfr.GetFieldTags();
+			std::cout << "----------" << std::endl;
+			  //				      << "mfn=" << i  
+				// 	  << " nvf=" << vf.size() << std::endl;
+
+			for (int j=0; j<vf.size(); j++)
+			{
+				std::string stemp;
+				// Special case when tag is <=0
+				if (vf[j]<=0 || vf[j]>SHRT_MAX)
+					continue;
+				// Extract the field with tag contained into vf[j]
+				bool rc = mfr.GetField(vf[j], stemp);
+				if (rc)
+				{
+					std::cout << "tag=" << vf[j]
+					          << " data=" << stemp << std::endl;
+				}
+			}
+
+		}
+		else
+			continue;
+		// PausePrg();
+
+	}
+	return 0;
+}
+
Index: /gsdl/trunk/build-src/packages/isis-gdl/IsisTypes.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/IsisTypes.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/IsisTypes.h	(revision 16571)
@@ -0,0 +1,98 @@
+/**********************************************************************
+ *
+ * IsisTypes.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+///////////////////////////////////////////////////////////////////////////////
+//  isisType.h 
+
+
+#ifndef __ISIS_TYPE_H__
+#define __ISIS_TYPE_H__
+
+#include "DLLCode.h"
+
+#ifdef __USE_ISOC99 // get double_t type from math.h
+#include <math.h>
+#endif
+namespace isis
+{
+
+
+// ----------------------------------------
+// Type definitions common to all platforms
+// ----------------------------------------
+typedef char            int8_t;    // 8-bit signed value
+typedef unsigned char   uint8_t;   // 8-bit unsigned value
+typedef int             int32_t;   // Word size (4 bytes)
+typedef unsigned int    uint32_t;  // Unsigned word size (4 bytes)
+typedef long            long32_t;  // Long word (4 bytes)
+typedef unsigned long   ulong32_t; // Unsigned long word (4 bytes)
+typedef short           int16_t;   // short word (2 bytes)
+typedef unsigned short  uint16_t;  // Unsigned short word (2 bytes)
+#ifndef __USE_ISOC99 // gnu lic math.h has a double_t
+typedef double          double_t;  // Double precision floating point (8 bytes)
+#endif
+
+
+// --------------------------------------------------------------
+// Platform/compiler specific INT64 types
+// --------------------------------------------------------------
+#if defined (__64_BIT_FILE_SYSTEM__)
+#include "TYPES64.H" 
+#endif
+} // namespace isis
+
+namespace isis
+{
+    typedef  isis::int16_t  db_t;
+    typedef  isis::int16_t  server_t;
+    typedef  isis::int16_t  IsisClientId;
+    typedef  isis::uint32_t mfn_t;
+}
+// typedef char            int8_t;    // 8-bit signed value
+typedef unsigned char   uint8_t;   // 8-bit unsigned value
+typedef int             int32_t;   // Word size (4 bytes)
+typedef unsigned int    uint32_t;  // Unsigned word size (4 bytes)
+typedef long            long32_t;  // Long word (4 bytes)
+typedef unsigned long   ulong32_t; // Unsigned long word (4 bytes)
+typedef short           int16_t;   // short word (2 bytes)
+typedef unsigned short  uint16_t;  // Unsigned short word (2 bytes)
+#ifndef __USE_ISOC99 // gnu lic math.h has a double_t
+typedef double     double_t;  // Double precision floating point (8 bytes) // ****
+#endif
+
+typedef uint32_t        xrf_page_no_t;
+
+typedef uint32_t        mst_page_no_t;
+typedef uint16_t        mst_offset_t;
+typedef uint32_t        mfn_t;
+typedef uint32_t        mfrl_t;
+
+typedef isis::uint32_t file_size_t;
+
+
+#endif // __ISIS_TYPE_H__
+
+
+
Index: /gsdl/trunk/build-src/packages/isis-gdl/IsisUtil.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/IsisUtil.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/IsisUtil.cpp	(revision 16571)
@@ -0,0 +1,183 @@
+/**********************************************************************
+ *
+ * IsisUtil.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "stdafx.h"
+#include "IsisUtil.h" 
+#include <algorithm>
+
+
+//---------------------------------------------------------------------------------
+// bool RepFieldSep(TCHAR c)
+//
+// This function is a predicate that takes a TCHAR and returns a value that indicates
+// if that TCHAR is a repeteable field separator.
+//----------------------------------------------------------------------------------
+bool RepFieldSep(char c)
+{
+	return (c == SYSRSEP);
+}
+
+//--------------------------------------------------------------------------------
+// vector<string> SplitOccurences(const cstring& s)
+//
+// This function takes as input a string which contains a field and return a 
+// vector<string> which will contain an entry for each field occurence.
+//--------------------------------------------------------------------------------
+std::vector<cstring> SplitOccurences(const cstring& s)
+{
+	typedef cstring::const_iterator iter;
+	std::vector<cstring> ret;
+
+	iter i = s.begin();
+	//TRACE("\ni=%s",i);
+	while (i != s.end())
+	{
+		// find end of occurence
+		iter j = std::find_if(i,s.end(),RepFieldSep);
+
+		// copy the characters in [i, j]
+		ret.push_back(cstring(i, j));
+		//TRACE("\ni=%s j=%s string(i,j)=%s", i, j, string(i,j).c_str());
+
+		i = j;
+		if (j != s.end())
+		    i++;
+	}
+	return ret;
+}
+
+
+bool WSubFieldSep(WCHAR c)
+{
+	return (c == SUBFIELD_SEP);
+}
+
+//--------------------------------------------------------------------------------
+// vector<cstring> SplitSubfields(const cstring& s, TCHAR sc)
+//
+// This function takes as input a string which contains a field and return a 
+// vector<string> which will contain an entry for each subfield occurrence.
+//--------------------------------------------------------------------------------
+std::vector<cstring> SplitSubfields(const cstring& s, TCHAR sc/*=0*/)
+{
+	typedef cstring::const_iterator iter;
+	std::vector<cstring> ret;
+
+	iter i= s.begin();
+	iter j;
+	while (i < s.end())
+	{
+		// Look for subfield separator (^)
+		iter k =  std::find_if(i ,s.end(),WSubFieldSep);
+		if (k == s.end())
+		{
+			j = s.end(); // separator not found
+		}
+		else
+		{
+			// Special case when field is terminated by "^x" or "^"
+			if (k==s.end()-1 || k==s.end()-2)
+				break;
+			i = k + 2;  // separator found, skip next char
+			assert(i<s.end());
+			j = std::find_if(i ,s.end() ,WSubFieldSep);
+		}
+		ret.push_back(cstring(i, j));
+		i = j;
+	}
+	return ret;
+}
+
+
+//--------------------------------------------------------------------------------
+// vector<string> SplitOccurences(const awstring& s)
+//
+// This function takes as input a string which contains a field and return a 
+// vector<string> which will contain an entry for each field occurence.
+//--------------------------------------------------------------------------------
+//  std::vector<awstring> SplitOccurences(const awstring& s)
+//  {
+//  	typedef awstring::const_iterator iter;
+//  	std::vector<awstring> ret;
+
+//  	iter i = s.begin();
+//  	//TRACE("\ni=%s",i);
+//  	while (i != s.end())
+//  	{
+//  		// find end of occurence
+//  		iter j = std::find_if(i,s.end(),RepFieldSep);
+
+//  		// copy the characters in [i, j]
+//  		ret.push_back(awstring(i, j));
+//  		//TRACE("\ni=%s j=%s string(i,j)=%s", i, j, string(i,j).c_str());
+
+//  		i = j;
+//  		if (j != s.end())
+//  		    i++;
+//  	}
+//  	return ret;
+//  }
+
+
+bool SubFieldSep(TCHAR c)
+{
+	return (c == SUBFIELD_SEP);
+}
+
+//--------------------------------------------------------------------------------
+// vector<awstring> SplitSubfields(const awstring& s, TCHAR sc)
+//
+// This function takes as input a string which contains a field and return a 
+// vector<string> which will contain an entry for each subfield occurrence.
+//--------------------------------------------------------------------------------
+//  std::vector<awstring> SplitSubfields(const awstring& s, TCHAR sc/*=0*/)
+//  {
+//  	typedef awstring::const_iterator iter;
+//  	std::vector<awstring> ret;
+
+//  	iter i = s.begin();
+//  	//TRACE("\ni=%s",i);
+//  	bool found=false;
+//  	while (i != s.end())
+//  	{
+//  		// find index of subfield separator (^)
+//  		iter j = std::find_if(i,s.end(),SubFieldSep);
+//  		if (found && j<s.end()-1)
+//  		{
+//  		    // copy the characters in [i, j]
+//  			ret.push_back(awstring(i+1, j));
+//  		}
+//  		if (sc==0 || s.at(j-s.begin()+1)==sc)
+//  		    found = true;
+//  		else
+//  		    found = false;
+
+
+//  		i = j+1;
+//  		if (j != s.end())
+//  		    i++;
+//  	}
+//  	return ret;
+//  }
Index: /gsdl/trunk/build-src/packages/isis-gdl/IsisUtil.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/IsisUtil.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/IsisUtil.h	(revision 16571)
@@ -0,0 +1,35 @@
+/**********************************************************************
+ *
+ * IsisUtil.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef __ISIS_UTIL__
+#define __ISIS_UTIL__
+#include <vector>
+#include <string>
+std::vector<cstring> SplitOccurences(const cstring &s);
+// std::vector<awstring> SplitOccurences(const awstring &s);
+
+std::vector<cstring> SplitSubfields(const cstring &s, TCHAR sc=0);
+// std::vector<awstring> SplitSubfields(const awstring &s, TCHAR sc=0);
+#endif // __ISIS_UTIL_
Index: /gsdl/trunk/build-src/packages/isis-gdl/MFFile.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/MFFile.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/MFFile.cpp	(revision 16571)
@@ -0,0 +1,479 @@
+/**********************************************************************
+ *
+ * MFFile.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////
+// MfFile.cpp : Master file object methods using blocked I/O
+//
+////////////////////////////////////////////////////////////
+#include "stdafx.h"
+#include "IsisDb.h"
+#include "Checking.h"
+
+
+
+//---------------------------------------------------------------------------------- 
+// MfFile::MfFile() :
+//
+// Constructor, makes a Masterfile object that isn't connected to a file
+//---------------------------------------------------------------------------------- 
+MfFile::MfFile() : BlkFile(), hdr_created_(false), nextaddr_(MFCTLLEN)
+{
+    lastWrittenBlock_ = -1;
+}
+ 
+//----------------------------------------------------------------------------------
+// int MfFile::OpenMf(const TCHAR *fname, 
+//                    FileSystem::AccessMode mode /* = FileSystem::FILE_READWRITE */)
+//
+// Opens a Masterfile object
+//---------------------------------------------------------------------------------- 
+int MfFile::OpenMf(const TCHAR *fname, FileSystem::AccessMode mode
+				                              /* = FileSystem::FILE_READWRITE */)
+{
+  TCHAR mstFileName[_MAX_PATH];
+  _tcscpy(mstFileName, fname);
+
+  if (!CFileBase::Exists(mstFileName)) {
+    mstFileName[strlen(mstFileName) - 3] = 'M';
+    mstFileName[strlen(mstFileName) - 2] = 'S';
+    mstFileName[strlen(mstFileName) - 1] = 'T';
+  }
+
+	int rc;
+	try
+	{
+	    rc = CFileBase::Open(mstFileName, mode);
+		hdr_created_ = true;
+	    ReadMfHdr();
+		PrintMfHdr();
+		Checking::CheckMfHeader(mstFileName, mfh_);
+	}
+	catch (CFileBaseException e)
+	{
+        throw CIsisDbException(ISIS_MF_OPEN_ERROR, __FILE__, __LINE__);
+	}
+    return rc;
+}
+ 
+//----------------------------------------------------------------------------------
+// int MfFile::createMf(const TCHAR *fname, int  type)
+//
+// Creates a Masterfile object
+//---------------------------------------------------------------------------------- 
+int MfFile::CreateMf(const TCHAR *fname, int  type)
+{
+    return 0;
+}
+ 
+//////////////////////////////
+MfFile::~MfFile()
+{
+}
+ 
+//----------------------------------------------------------------------------------
+// void  MfFile::ReadMfRecord(long mfb, int mfp, MfRecord &m)
+//
+// Reads the master file record beginning at address (mfb,mfp) into m
+//----------------------------------------------------------------------------------
+bool  MfFile::ReadMfRecord(long mfb, int mfp, MfRecord &m)
+{
+	return m.Read(*this, mfb, mfp);
+}
+
+//-------------------------------------------------------------------------------
+//  void WriteMfRecord(long mfb, int mfp, MfRecord &m)
+//
+//  Helper protected method, which writes the Master file record m at address 
+//  (mfb, mfp)   mfb (1:MAXMFB),   mfp (0: MFBLKSIZE)
+//-------------------------------------------------------------------------------
+void  MfFile::WriteMfRecord(long mfb, int mfp, MfRecord &m)
+{
+	m.Write(*this, mfb, mfp);
+} 
+
+
+//--------------------------------------------------------------------------------
+// void CreateMfRecord(MfRecord &m, long &mfb, int &mfp)
+//
+//  Create a new record. The MFN to be assigned is obtained from the field nxtmfn_
+//  in the Master file header. Then addMfRecord is called for adding the record
+//  at the end of the master file, at the position indicated by the fields
+//  nxtmfb_/nxtmfb_. The next MFN to be assigned is updated.
+//
+//--------------------------------------------------------------------------------
+void  MfFile::CreateMfRecord(MfRecord &m, long &mfb, int &mfp)
+{
+}
+
+void  MfFile::AppendNewBlock()
+{
+}
+
+//--------------------------------------------------------------------------------
+// void AddMfRecord(MfRecord &m, long &mfb, int &mfp)
+//
+// Add the record at the end of the master file, at the position indicated by
+// the fields nxtmfb_/nxtmfp_. (nxtmfp_ is in range [1:MFBLKSIZE])
+// Return the address where the record was stored into mfb & mfp
+//--------------------------------------------------------------------------------
+void  MfFile::AddMfRecord(MfRecord &m, long &mfb, int &mfp)
+{
+}
+ 
+ 
+//--------------------------------------------------------------------------------
+// void UpdateMfRecord(MfRecord &m, long &mfb, int &mfp)
+//
+// Update a Master file record.If possible, i.e. if the record length was not
+// increased, the record is written back at its original location otherwise it is
+// written at the end of the file. In both cases, MFBWB/MFBWP are not changed.
+// 
+//--------------------------------------------------------------------------------
+void  MfFile::UpdateMfRecord(MfRecord &m, long &mfb, int &mfp)
+{
+}
+
+
+/////////////////////////////////////////////////////////////////////////////////////
+// methods for dumping file and record headers
+
+ 
+void MfFile::PrintMfHdr(SMfHeader &h)
+// Prints header record
+{
+}
+ 
+//////////////////////////////
+ 
+void MfFile::PrintMfRecord(MfRecord &m)
+// Print a master file record structure
+{
+	m.Dump();
+}
+
+/////////////////////////////////////////////////////////////////////////////////////
+// Methods for accessing records directly
+ 
+//----------------------------------------------------------------------------------
+// void MfFile::ReadMfRecord(long daddr, MfRecord &m)
+//
+// Reads a master file record into the master record object m.
+// Non blocked version
+//----------------------------------------------------------------------------------
+void MfFile::ReadMfRecord(long daddr, MfRecord &m)
+{
+	m.Clear();
+    ReadLeader(daddr, m);       // Read record leader (Leader is added to record)
+	m.ExtractSubLeader();
+    
+	//TRACE("\nReadMfRecord -- mfn=%ld mfrl=%d", m.GetMfn(), m.GetMfrl());
+	//assert(m.CheckIntegrity());
+	int mfrl = m.GetMfrl();
+	if (mfrl < 0) mfrl = -mfrl; 	// mfrl can be negative!!!!
+	char* p = new char[mfrl];
+    CFileBase::Fetch(p, mfrl, daddr);
+	m.AddToRecord(p+GetLeaderSize(), mfrl-GetLeaderSize());
+	delete[] p;
+    nextaddr_ += mfrl;
+ 	int mfb = nextaddr_ / MFBLKSIZE + 1;
+    int mfp = nextaddr_ % MFBLKSIZE;
+    if (mfp > MFBLKSIZE - GetMinLeaderSize())
+	{
+		mfb++;
+	    mfp = 0;
+	}
+	nextaddr_ = (mfb-1)*MFBLKSIZE + mfp;
+	m.DecomposeRecord();
+}
+
+//---------------------------------------------------------------------------------
+// void  MfFile::WriteMfRecord(long daddr, MfRecord &m)
+//
+// Stores Master record object m to disk address daddr
+// Non blocked version
+//---------------------------------------------------------------------------------
+void  MfFile::WriteMfRecord(long daddr, MfRecord &m)
+{
+}
+/////////////////////////////////////////////////////////////////////////////////////
+// Master file locking methods
+
+
+ 
+//-----------------------------------------------------------------------------------
+// void MfFile::InitFileLockHdr(SMfLockHeader &hdr)
+//
+// Initialize a the lock header for a newly constructed file lock header.
+//-----------------------------------------------------------------------------------
+void MfFile::InitFileLockHdr(SMfLockHeader &hdr)
+{
+	hdr.lockProtect_ = (uint32_t)0;
+	hdr.readLock_    = (uint32_t)0;
+	hdr.writeLock_   = (uint32_t)0;
+}
+
+//-----------------------------------------------------------------------------------
+// FileError MfFile::WriteFileLockHdr(const SMfLockHeader &hdr)
+//
+// Write the lock header to the file. 
+// Returns a non-zero value to indicate an error condition or zero if successful.
+//-----------------------------------------------------------------------------------
+FileError MfFile::WriteFileLockHdr(const SMfLockHeader &hdr)
+{
+	
+	return CFileBase::Store(&hdr, sizeof(SMfLockHeader), sizeof(SMfHeader));
+}
+
+//-----------------------------------------------------------------------------------
+// FileError MfFile::ReadFileLockHdr(SMfLockHeader &hdr)
+//
+// Read the lock header from the file.
+// Returns a non-zero value to indicate an error condition or zero if successful.
+//-----------------------------------------------------------------------------------
+FileError MfFile::ReadFileLockHdr(SMfLockHeader &hdr)
+{
+	
+	return CFileBase::Fetch(&hdr, sizeof(SMfLockHeader), sizeof(SMfHeader));
+}
+
+//-----------------------------------------------------------------------------------
+// int MfFile::LockFile(CFileMgrLockType l_type) 
+//
+// Lock the file and set the lock access mode to shared or exclusive.
+// Returns a non-zero value if the file cannot be locked or the lock variable cannot
+// be changed because it is exclusive or another thread is currently updating it. 
+//-----------------------------------------------------------------------------------
+int MfFile::LockFile(MfLockType l_type) 
+{
+	// Read the file lock to ensure that this file has a lock header
+	// and to keep the header in sync during multiple file access.
+	SMfLockHeader lock_header;
+	if (ReadFileLockHdr(lock_header) != FILE_NO_ERROR)
+		return fileError_;
+	
+	// Cannot modifiy this lock until the thread holding it releases the
+	// lock header.
+	if (lock_header.lockProtect_ != 0)
+	{
+		fileError_ = ISIS_MFLOCK_ACCESS_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+		throw CFileBaseException(fileError_);
+#else
+		return fileError_;
+#endif
+	}
+	
+	switch (l_type)
+	{
+		case MF_WRITE_LOCK :
+			// Cannot obtain an exclusive lock until all the threads in the
+			// read lock queue have finished
+			if ((lock_header.readLock_ != 0) || 
+				(lock_header.writeLock_ != 0))
+			{
+				fileError_ = ISIS_MFLOCK_ERROR;
+	#ifdef __CPP_EXCEPTIONS__
+				throw CFileBaseException(fileError_);
+	#else
+				return fileError_;
+	#endif
+			}
+			else 
+			{
+				lock_header.writeLock_ = 1;
+			}
+			
+			lock_header.lockProtect_ = 1;
+			if (CFileBase::Store(&lock_header.lockProtect_, sizeof(uint32_t),
+				sizeof(SMfHeader)) != FILE_NO_ERROR)
+				return fileError_;
+			
+			// Skip over the read lock member
+			SeekTo(sizeof(SMfHeader) + (sizeof(uint32_t) * 2));
+			if (CFileBase::Store(&lock_header.writeLock_, sizeof(uint32_t)) !=
+				FILE_NO_ERROR)
+				return fileError_;
+			
+			lock_header.lockProtect_ = (uint32_t)0;
+			if (CFileBase::Store(&lock_header.lockProtect_, sizeof(uint32_t),
+				sizeof(SMfHeader)) != FILE_NO_ERROR)
+				return fileError_;
+			break;
+			
+		case MF_READ_LOCK :
+			// This lock is exclusively owned and cannot be read locked
+			// until the thread holding this lock release the exclusive lock.
+			if (lock_header.writeLock_ == 1)
+			{
+				fileError_ = ISIS_MFLOCK_ERROR;
+	#ifdef __CPP_EXCEPTIONS__
+				throw CFileBaseException(fileError_);
+	#else
+				return fileError_;
+	#endif
+			}
+			
+			if (lock_header.readLock_ < 0xFFFFFFFF)
+			{
+				lock_header.readLock_++;
+			}
+			else 
+			{
+				fileError_ = ISIS_MFLOCK_ERROR;
+	#ifdef __CPP_EXCEPTIONS__
+				throw CFileBaseException(fileError_);
+	#else
+				return fileError_;
+	#endif
+			}
+			
+			lock_header.lockProtect_ = 1;
+			if (CFileBase::Store(&lock_header.lockProtect_, sizeof(uint32_t),
+				sizeof(SMfHeader)) != FILE_NO_ERROR)
+				return fileError_;
+			
+			if (CFileBase::Store(&lock_header.readLock_, sizeof(uint32_t)) !=
+				FILE_NO_ERROR)
+				return fileError_; 
+			
+			lock_header.lockProtect_ = (uint32_t)0;
+			if (CFileBase::Store(&lock_header.lockProtect_, sizeof(uint32_t),
+				sizeof(SMfHeader)) != FILE_NO_ERROR)
+				return fileError_;
+			break;
+			
+		default: // Invalid lock type specified
+			fileError_ =  ISIS_INVALID_LOCK_TYPE;
+	#ifdef __CPP_EXCEPTIONS__
+			throw CFileBaseException(fileError_);
+	#else
+			return fileError_;
+	#endif
+	}
+	
+	return fileError_ = fileError_ = FILE_NO_ERROR;
+}
+
+//-----------------------------------------------------------------------------------
+// int MfFile::UnlockFile(CFileMgrLockType l_type)
+//
+// Unlock the file. Returns a non-zero value if the file cannot be unlocked or the
+// lock variable cannot be changed because it is exclusive or another thread is
+// currently updating it. 
+//-----------------------------------------------------------------------------------
+int MfFile::UnlockFile(MfLockType l_type)
+{
+	
+	// Read the file lock to ensure that this file has a lock header
+	// and to keep the header in sync during multiple file access.
+	SMfLockHeader lock_header;
+	if (ReadFileLockHdr(lock_header) != FILE_NO_ERROR)
+		return fileError_;
+	
+	// Cannot modifiy this lock until the thread holding it releases the
+	// lock header.
+	if (lock_header.lockProtect_ != 0)
+	{
+		fileError_ = ISIS_MFLOCK_ACCESS_ERROR;
+#ifdef __CPP_EXCEPTIONS__
+		throw CFileBaseException(fileError_);
+#else
+		return fileError_;
+#endif
+	}
+	
+	switch (l_type)
+	{
+		case MF_WRITE_LOCK :
+			if (lock_header.writeLock_ == 0)
+				return FILE_NO_ERROR;
+			else
+				lock_header.writeLock_ = 0;
+			
+			lock_header.lockProtect_ = 1;
+			if (CFileBase::Store(&lock_header.lockProtect_, sizeof(uint32_t),
+				sizeof(SMfHeader)) != FILE_NO_ERROR)
+				return fileError_;
+			
+			// Skip over the read lock member
+			SeekTo(sizeof(SMfHeader) + (sizeof(uint32_t) * 2));
+			if (CFileBase::Store(&lock_header.writeLock_, sizeof(uint32_t)) !=
+				FILE_NO_ERROR)
+				return fileError_;
+			
+			lock_header.lockProtect_ = (uint32_t)0;
+			if (CFileBase::Store(&lock_header.lockProtect_, sizeof(uint32_t),
+				sizeof(SMfHeader)) != FILE_NO_ERROR)
+				return fileError_;
+			break;
+			
+		case MF_READ_LOCK :
+			if (lock_header.readLock_ == 0)      // This record is not locked
+				return fileError_ = FILE_NO_ERROR;
+			else if (lock_header.readLock_  > 0) // Prevent read lock rollover
+				lock_header.readLock_--;
+			else
+				lock_header.readLock_ = 0;
+			
+			lock_header.lockProtect_ = 1;
+			if (CFileBase::Store(&lock_header.lockProtect_, sizeof(uint32_t),
+				sizeof(SMfHeader)) != FILE_NO_ERROR)
+				return fileError_;
+			
+			if (CFileBase::Store(&lock_header.readLock_, sizeof(uint32_t)) !=
+				FILE_NO_ERROR)
+				return fileError_; 
+			
+			lock_header.lockProtect_ = (uint32_t)0;
+			if (CFileBase::Store(&lock_header.lockProtect_, sizeof(uint32_t),
+				sizeof(SMfHeader)) != FILE_NO_ERROR)
+				return fileError_;
+			break;
+			
+		default: // Invalid lock type specified
+			fileError_ =  FMGR_INVALID_LOCK_TYPE;
+	#ifdef __CPP_EXCEPTIONS__
+			throw CFileBaseException(fileError_);
+	#else
+			return fileError_;
+	#endif
+	}
+	
+	return fileError_ = fileError_ = FILE_NO_ERROR;
+}
+
+//-----------------------------------------------------------------------------------
+// FileError MfFile::ResetFileLock()
+//
+// Reset the file's lock header. This function will clear all the file lock fields
+// without testing the lock or the lock protect. Returns a non-zero value to indicate
+// an error condition or zero if successful.
+//-----------------------------------------------------------------------------------
+FileError MfFile::ResetFileLock()
+{
+	SMfLockHeader lock_header;
+	InitFileLockHdr(lock_header);
+	return WriteFileLockHdr(lock_header);
+}
Index: /gsdl/trunk/build-src/packages/isis-gdl/MFFile.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/MFFile.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/MFFile.h	(revision 16571)
@@ -0,0 +1,338 @@
+/**********************************************************************
+ *
+ * MFFile.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////
+// MFFILE.H: Class definition for blocked I/O on the master
+//           file
+////////////////////////////////////////////////////////////
+ 
+#ifndef _MFFILE_H_
+#define _MFFILE_H_
+#ifndef _MASTER_H_
+#include "Master.h"
+#endif
+#ifndef _BLKFILE_H_
+#include "BlkFile.h"
+#endif
+#include <string>
+
+enum MfLockType
+{
+	MF_READ_LOCK,
+	MF_WRITE_LOCK
+};
+
+struct SMfLockHeader
+{
+	long lockProtect_; // Serialize access to the file lock members
+	long readLock_;    // Shared (or read_only) file lock
+	long writeLock_;   // Exclusive (or write-only) file lock
+
+	SMfLockHeader() : lockProtect_(0), readLock_(0), writeLock_(0)
+	{}
+};
+
+enum  { USERMST=0, MSGMST=1 };
+//  binary  hex
+//  ------  ---
+//  0000    0
+//  0001    1
+//  0010    2
+//  0011    3
+
+class MfAddress
+{
+private:
+	long  m_mfb;
+	short m_mfp;
+	char  m_status;
+public:
+	MfAddress() { m_status = 0x00; }
+	MfAddress(long mfb, short mfp)
+	{ ASSERT(mfb>0); ASSERT(mfp>=0); m_mfb = mfb; m_mfp = mfp; m_status = 0x03; }
+
+	long getMfb()          { ASSERT(m_status & 0x01); return m_mfb; }
+	short getMfp()         { ASSERT(m_status & 0x02); return m_mfp; } 
+
+	void setMfb(long mfb)  { ASSERT(mfb>0);  m_mfb = mfb; m_status |= 0x01; }
+	void setMfp(short mfp) { ASSERT(mfp>=0); m_mfp = mfp; m_status |= 0x02; }
+	bool isValid()         { return (m_status == 0x03); }
+};
+ 
+/////////////////////////////////////////////////////////////////////////
+// Master File header record aggregate structure
+//
+struct  SMfHeader 
+{
+   ISIS_LONG   ctlmfn_;    // Always 0
+   ISIS_LONG   nxtmfn_;    // MFN to be assigned to next record created
+   ISIS_LONG   nxtmfb_;    // Last block number allocated (1st is 1)
+   ISIS_INT    nxtmfp_;    // Offset to next available position in last block (1:MFBLKSIZE)
+   ISIS_INT    mftype_;    // Type of master file (USERMST or MSGMST)
+   ISIS_LONG   reccnt_;
+   ISIS_LONG   mfcxx1_;
+   ISIS_LONG   mfcxx2_;
+   ISIS_LONG   mfcxx3_;
+public:
+   SMfHeader(const char *dbname="");
+   ~SMfHeader()                 { }
+};
+ 
+//--------------------------------------------------------------------------
+// SMfHeader::SMfHeader(const char *dbname /* ="" */)
+//
+// Default constructor, initializes the Master file header to default values
+//--------------------------------------------------------------------------
+inline SMfHeader::SMfHeader(const char *dbname /* ="" */)
+{
+   ctlmfn_ = 0;
+   nxtmfn_ = 1L;
+   nxtmfb_ = 1L;
+   nxtmfp_ = MFCTLLEN+1;
+   mftype_ = USERMST;
+   reccnt_ = mfcxx1_=mfcxx2_=mfcxx3_=0;
+}
+ 
+//////////////////////
+// Master file class
+//
+class MfFile : public BlkFile  
+{
+   friend class IsisDb;
+   friend class MfRecord;
+
+protected:
+   SMfHeader mfh_;            // Header structure
+   long nextaddr_;            // Address of next record
+   char buf_[MFBLKSIZE];      // Buffer to hold 1 Master File block
+   bool hdr_created_;         // True if 1st block exists
+   int  fileError_;
+   long lastWrittenBlock_;
+
+protected:  
+   void WriteMfRecord(long mfb, int mfp, MfRecord &r);
+   void AppendNewBlock();
+
+public:
+   void setNextMfn(long mfn)       // Set MFN to be assigned to next record created
+   { mfh_.nxtmfn_ = mfn; }
+
+protected:
+   void setNextMfb(long nxtmfb_)  // Set last block number allocated (1st is 1)
+   { mfh_.nxtmfb_ = nxtmfb_; }
+   void setNextMfp(int nxtmfp_)   // Set offset to next available position in last block
+   { mfh_.nxtmfp_ = nxtmfp_; }
+   int setm_mftype(int mftype_)     // Set type of master file (USERMST or MSGMST)
+   { mfh_.mftype_ = mftype_; }     
+   virtual void ReadBlk(void* d, long b)  { BlkFile::ReadBlk(d, b);  }
+   virtual void WriteBlk(void* d, long b) { BlkFile::WriteBlk(d, b); }
+   void ReadMfHdr(SMfHeader &h);
+   void ReadMfHdr();
+   void WriteMfHdr(SMfHeader &h);
+   void WriteMfHdr();
+   void SetLastWrittenBlock(long b) { lastWrittenBlock_ = b; }
+public:
+   MfFile();
+   virtual ~MfFile();
+
+   int  OpenMf(const TCHAR* name, FileSystem::AccessMode mode = FileSystem::FILE_READWRITE);
+   int  CreateMf(const TCHAR* name, int MSTtype = USERMST);
+   void CloseMf() { if (ReadyForWriting()) WriteMfHdr(); Close(); }
+
+   // Accessors for the Master File Header
+   long GetNextMfn()        // Get MFN to be assigned to next record created
+   { return mfh_.nxtmfn_; }
+   long GetNextMfb()        // Get last block number allocated (1st is 1)
+   { return mfh_.nxtmfb_; }
+   int GetNextMfp()         // Get offset to next available position in last block
+   { return mfh_.nxtmfp_; }
+   int GetMftype()          // Get type of master file (USERMST or MSGMST)
+   { return mfh_.mftype_; }   
+   SMfHeader& GetSMfHeader() { return mfh_; }
+
+
+   void CreateMfRecord(MfRecord &m, long &mfb, int &mfp);
+   void AddMfRecord(MfRecord &m, long &mfb, int &mfp);
+   void UpdateMfRecord(MfRecord &m, long &mfb, int &mfp);
+   bool ReadMfRecord(long mfb, int mfp, MfRecord &r);
+
+   void ReadMfRecord(long addr, MfRecord &r);
+   void WriteMfRecord(long addr, MfRecord &r);
+   void RewindMf();
+   bool ReadMfNext(MfRecord &r);
+   void WriteMfNext(MfRecord &r);
+   void ReadLeader(long daddr, MfRecord& m)
+   {
+	   m.ReadLeader(*this, daddr);
+   }
+
+
+   void LockMfHdr();
+   void UnlockMfHdr();
+   void LockMfr(long mfn);
+   void UnlockMfr(long mfn);
+
+public: // File lock functions
+	void InitFileLockHdr(SMfLockHeader &hdr);
+	FileError ResetFileLock();
+	FileError WriteFileLockHdr(const SMfLockHeader &hdr);
+	FileError ReadFileLockHdr(SMfLockHeader &hdr);
+	int LockFile(MfLockType l_type = MF_WRITE_LOCK);
+	int UnlockFile(MfLockType l_type = MF_WRITE_LOCK);
+
+
+   void PrintMfRecord(MfRecord &r);
+   void PrintMfHdr(SMfHeader &h);
+   void PrintMfHdr();
+};
+ 
+
+class CMfIterator
+{
+	const MfFile& m_mf;
+	long cur;
+public:
+	CMfIterator(const MfFile& mf) : m_mf(mf) { }
+
+	bool More() const;
+	void Advance();
+
+	MfRecord Current() 
+	{ 
+		MfRecord mfr(NULL);
+		
+		return mfr;
+	}
+};
+
+ 
+//////////////////////////////
+ 
+inline void  MfFile::LockMfHdr()
+//  Locks the master file header record
+{
+	double_t dwPos   = 0;
+	double_t dwCount = sizeof(SMfHeader);
+	//CFile::LockRange(dwPos, dwCount);
+}
+ 
+//////////////////////////////
+ 
+inline void MfFile::UnlockMfHdr()
+//  Unlocks the master file header record
+{
+	double_t dwPos   = 0;
+	double_t dwCount = sizeof(SMfHeader);
+	//CFile::UnlockRange(dwPos, dwCount);
+}
+ 
+//////////////////////////////
+
+inline void MfFile::ReadMfHdr()
+//  Reads the master file header record
+{
+   ReadBlk(buf_, 1L);
+   TRACE(_T("\nsizeof(SMfHeader)=%d"), sizeof(SMfHeader));
+   ::MoveMemory(&mfh_, buf_, sizeof(SMfHeader));
+
+   fix_endianness(mfh_.ctlmfn_);
+   fix_endianness(mfh_.nxtmfn_);
+   fix_endianness(mfh_.nxtmfb_);
+   fix_endianness(mfh_.nxtmfp_);
+   fix_endianness(mfh_.mftype_);
+   fix_endianness(mfh_.reccnt_);
+   fix_endianness(mfh_.mfcxx1_);
+   fix_endianness(mfh_.mfcxx2_);
+   fix_endianness(mfh_.mfcxx3_);
+}
+ 
+//////////////////////////////
+ 
+inline void MfFile::WriteMfHdr()
+//  Updates the master file header record
+{
+    if (hdr_created_) 
+	   ReadBlk(buf_, 1L);
+    TRACE(_T("\nsizeof(SMfHeader)=%d"), sizeof(SMfHeader));
+    ::MoveMemory(buf_, &mfh_, sizeof(SMfHeader));
+    WriteBlk(buf_, 1L);
+}
+ 
+ 
+//////////////////////////////
+ 
+inline void MfFile::ReadMfHdr(SMfHeader &h)
+//  Reads the master file header record
+{
+   ReadBlk(buf_, 1L);
+   ::MoveMemory(&h, buf_, sizeof(SMfHeader));
+
+   fix_endianness(h.ctlmfn_);
+   fix_endianness(h.nxtmfn_);
+   fix_endianness(h.nxtmfb_);
+   fix_endianness(h.nxtmfp_);
+   fix_endianness(h.mftype_);
+   fix_endianness(h.reccnt_);
+   fix_endianness(h.mfcxx1_);
+   fix_endianness(h.mfcxx2_);
+   fix_endianness(h.mfcxx3_);
+}
+ 
+//////////////////////////////
+ 
+inline void MfFile::WriteMfHdr(SMfHeader &h)
+//  Updates the master file header record
+{
+   if (hdr_created_)
+	   ReadBlk(buf_, 1L);
+   ::MoveMemory(buf_, &h, sizeof(SMfHeader));
+   WriteBlk(buf_, 1L);
+}
+ 
+ 
+inline void MfFile::PrintMfHdr()
+{
+   PrintMfHdr(mfh_);
+}
+ 
+//////////////////////////////
+ 
+inline bool MfFile::ReadMfNext(MfRecord &r)
+// Reads the next physically record
+{
+	if (nextaddr_ >= CFileBase::FileSize(file_name))
+	    return false;
+   ReadMfRecord(nextaddr_, r);
+   return true;
+}
+ 
+//////////////////////////////
+ 
+inline void MfFile::WriteMfNext(MfRecord &r)
+// Writes physically at next position
+{
+   WriteMfRecord(nextaddr_, r);
+}
+#endif
Index: /gsdl/trunk/build-src/packages/isis-gdl/Makefile.in
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Makefile.in	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Makefile.in	(revision 16571)
@@ -0,0 +1,33 @@
+prefix	    = @prefix@
+exec_prefix = @exec_prefix@
+bindir	    = @bindir@
+
+CXX	    = @CXX@
+CXXFLAGS    = @CXXFLAGS@
+EXEEXT	    = @EXEEXT@
+
+INSTALL     = @INSTALL@
+
+LDFLAGS     = @LDFLAGS@
+
+ISIS_OBJS   = IsisGdl.o CacheMan.o Checking.o CRC32.o Fdt.o File.o \
+              FileSystem.o IErrors.o IsisDb.o IsisUtil.o Master.o MFFile.o \
+              stdafx.o Unimarc.o XRFFile.o
+
+
+all: IsisGdl$(EXEEXT)
+
+IsisGdl$(EXEEXT): $(ISIS_OBJS)
+	$(CXX) -o IsisGdl$(EXEEXT) $(ISIS_OBJS) $(LDFLAGS)
+
+$(ISIS_OBJS) :%.o :%.cpp
+	$(CXX) -c $(CXXFLAGS) -o $@ $<
+
+install: all
+	$(INSTALL) IsisGdl$(EXEEXT) $(bindir)
+
+clean:
+	rm -f IsisGdl$(EXEEXT) $(ISIS_OBJS)
+
+distclean: clean
+	rm -f Makefile config.status config.cache config.log
Index: /gsdl/trunk/build-src/packages/isis-gdl/Master.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Master.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Master.cpp	(revision 16571)
@@ -0,0 +1,1084 @@
+/**********************************************************************
+ *
+ * Master.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////
+//  MASTER.CPP: Master file record object methods
+//                                                                        
+////////////////////////////////////////////////////////////
+#include "stdafx.h"
+#include <iomanip>
+#include "XRFFile.h"
+#include "IsisUtil.h" 
+#include "Master.h"
+#include "MFFile.h"
+#include "IsisDb.h"
+#include "Unimarc.h"
+#include <algorithm>
+
+
+using namespace std;
+
+   
+
+char MfRecord::m_buf[MFBLKSIZE];      // Buffer to hold 1 File block
+
+
+
+/////////////////////////////////////////////////////////////////////
+// LeaderAndDirectory methods
+
+int LeaderAndDirectory::GetFieldSize()
+{
+	int field_len = 0;
+	for (int i=0; i!=nvf_; ++i)
+		field_len  += dir_[i].len_;
+	return field_len;
+}
+
+bool LeaderAndDirectory::operator==(const LeaderAndDirectory& rhs) const
+{
+    if (mfn_ != rhs.mfn_)         // Master file number
+		return false;
+    if (mfrl_ != rhs.mfrl_)       // Record length
+		return false;
+	if (mfbwb_ != rhs.mfbwb_)     // Backward pointer block number
+		return false;
+    if (mfbwp_ != rhs.mfbwp_)     // Backward pointer offset
+		return false;
+    if (base_ != rhs.base_)       // Offset to begining of variable fields
+		return false;
+    if (nvf_ != rhs.nvf_)         // Number of directory entries
+		return false;
+    if (status_ != rhs.status_)   // 1 = DELETED
+		return false;
+	for(std::vector<DirEntry>::size_type i=0; i!=nvf_; i++) // Directory
+	{
+		if (dir_[i]!=rhs.dir_[i])
+		    return false;
+	}
+    return true;
+}
+
+bool LeaderAndDirectory::operator!=(const LeaderAndDirectory& rhs) const
+{
+    if (mfn_ != rhs.mfn_)         // Master file number
+		return true;
+    if (mfrl_ != rhs.mfrl_)       // Record length
+		return true;
+	if (mfbwb_ != rhs.mfbwb_)     // Backward pointer block number
+		return true;
+    if (mfbwp_ != rhs.mfbwp_)     // Backward pointer offset
+		return true;
+    if (base_ != rhs.base_)       // Offset to begining of variable fields
+		return true;
+    if (nvf_ != rhs.nvf_)         // Number of directory entries
+		return true;
+    if (status_ != rhs.status_)   // 1 = DELETED
+		return true;
+	for(std::vector<DirEntry>::size_type i=0; i!=nvf_; i++) // Directory
+	{
+		if (dir_[i]!=rhs.dir_[i])
+		    return true;
+	}
+    return false;
+}
+//-------------------------------------------------------------------------------
+// ostream& operator<<(ostream& s, const LeaderAndDirectory& leader_directory)
+//
+// Overloaded instance of the output operator for LeaderAndDirectory objects
+//---------------------------------------------------------------------------------
+cstringstream& operator<<(cstringstream& s, const LeaderAndDirectory& leader_directory)
+{
+	s.write((char *) &leader_directory.mfn_,    sizeof(ISIS_LONG));
+	s.write((char *) &leader_directory.mfrl_,   sizeof(ISIS_INT));
+	s.write((char *) &leader_directory.mfbwb_,  sizeof(ISIS_LONG));
+	s.write((char *) &leader_directory.mfbwp_,  sizeof(ISIS_INT));
+#ifdef UNIX_BIREME
+	ISIS_INT dummy = 0;
+	s.write((char *) &dummy,   sizeof(ISIS_INT));
+#endif
+
+	s.write((char *) &leader_directory.base_,   sizeof(ISIS_INT));
+	s.write((char *) &leader_directory.nvf_,    sizeof(ISIS_INT));
+	s.write((char *) &leader_directory.status_, sizeof(ISIS_INT));
+
+	int n = leader_directory.dir_.size();
+    assert(n==leader_directory.nvf_);	
+	for(vector<DirEntry>::size_type i=0; i!=leader_directory.dir_.size(); i++)
+	{
+	     assert(leader_directory.dir_[i].tag_>0 && leader_directory.dir_[i].tag_<SHRT_MAX);
+		 DirEntry de = leader_directory.dir_[i];
+         s.write((char *) &de, GetDirEntrySize());
+	}
+	
+	return s;
+}
+
+//----------------------------------------------------------------------------------
+// istream& operator>>(istream& s, LeaderAndDirectory& leader_directory)
+//
+// Overloaded instance of the input operator for LeaderAndDirectory objects
+//----------------------------------------------------------------------------------
+cstringstream& operator>>(cstringstream& s, LeaderAndDirectory& leader_directory)
+{
+	if (!s.good()) return s;
+
+	ios::iostate err = ios::goodbit;
+	try
+	{
+		s.read((char *) &leader_directory.mfn_,    sizeof(ISIS_LONG));
+	    s.read((char *) &leader_directory.mfrl_,   sizeof(ISIS_INT));
+	    s.read((char *) &leader_directory.mfbwb_,  sizeof(ISIS_LONG));
+	    s.read((char *) &leader_directory.mfbwp_,  sizeof(ISIS_INT));
+#ifdef UNIX_BIREME
+	    ISIS_INT dummy;
+	    s.read((char *) &dummy,   sizeof(ISIS_INT));
+#endif
+	    s.read((char *) &leader_directory.base_,   sizeof(ISIS_INT));
+	    s.read((char *) &leader_directory.nvf_,    sizeof(ISIS_INT));
+	    s.read((char *) &leader_directory.status_, sizeof(ISIS_INT));
+
+	    fix_endianness(leader_directory.mfn_);
+	    fix_endianness(leader_directory.mfrl_);
+	    fix_endianness(leader_directory.mfbwb_);
+	    fix_endianness(leader_directory.mfbwp_);
+	    fix_endianness(leader_directory.base_);
+	    fix_endianness(leader_directory.nvf_);
+	    fix_endianness(leader_directory.status_);
+
+		if (!leader_directory.dir_.empty())
+			leader_directory.dir_.clear();
+
+		// Try to recover if nvf_ = 0
+		if (leader_directory.nvf_==0)
+			leader_directory.nvf_ = (leader_directory.base_ - GetLeaderSize()) / GetDirEntrySize();
+
+		if (leader_directory.nvf_>0)
+		{
+			for(vector<DirEntry>::size_type i=0; i!=leader_directory.nvf_; i++)
+			{
+				DirEntry de;
+		        s.read((char *) &de, GetDirEntrySize());
+			    fix_endianness(de.tag_);
+			    fix_endianness(de.pos_);
+			    fix_endianness(de.len_);
+			    // Don't check integrity of directory entries here
+			    leader_directory.dir_.push_back(de);
+			}
+
+		}
+	}
+	catch(bad_alloc&)
+	{
+		err |= ios::badbit;
+		ios::iostate exception_mask = s.exceptions();
+		if (  (exception_mask & ios::failbit) &&
+			!(exception_mask & ios::badbit))
+		{
+			s.setstate(err);
+		}
+		else if (exception_mask & ios::badbit)
+		{
+		  s.setstate(err);
+		  // try { s.setstate(err); }
+		  // catch( ios::failure& ) { }
+			throw;
+		
+		}
+	}
+    catch(...)
+	{
+		err |= ios::failbit;
+		ios::iostate exception_mask = s.exceptions();
+		if ( (exception_mask & ios::badbit) &&
+			(err & ios::badbit))
+		{
+			s.setstate(err);
+		}
+		else if (exception_mask & ios::failbit)
+		{
+		  s.setstate(err);
+		  // try { s.setstate(err); }
+		  // catch( ios::failure& ) { }
+			throw;
+
+		}
+	}
+
+	if (err) s.setstate(err);
+	return s;
+}
+
+
+//////////////////////////////////////////////////////////////////////////////////
+//
+
+//  void MfRecord::Copy(UMfRecord& rhs)           
+//  {
+//  	Clear();
+//  	pFdt_      = rhs.pFdt_;
+//      state_     = Record_Created;
+	
+//  	// 1 - Prepare the LeaderAndDirectory, directory, end data part
+//  	int n   = 0;
+//  	int pos = 0;
+
+//  	cstring all_fields_mb;
+//      leader_directory_.dir_.clear();	
+//  	all_fields_mb.erase();
+//  	for (vector<int>::size_type i=0; i!=rhs.tags_.size(); ++i)
+//  	{
+//  		bool bRep = false;
+//  		if (rhs.pFdt_)
+//  		{
+//  			if (rhs.pFdt_->GetEntryAt(i).rep)
+//  			   bRep = true;
+//  		}
+//  		// Get the field, all occurences combined
+//  		int tag = rhs.tags_[i];
+//  	    awstring ws;
+//  		bool rc = rhs.GetField(tag, ws);
+//  		vector<awstring> occ;
+//  		if (bRep)
+//  			vector<awstring> occ = SplitOccurences(ws);
+//  		else
+//  			occ.push_back(ws);
+//          // one entry per occurence
+//  		int nocc = occ.size();
+//  		for (vector<awstring>::size_type j=0; j!= nocc; ++j)
+//  		{
+//  			DirEntry de;
+//  			de.tag_ = tag;
+//  			de.pos_ = pos;
+//  			cstring cs; // For storing the unicode string
+//  			de.len_ = UnicodeToCodePage(occ[j], cs);
+//              leader_directory_.dir_.push_back(de);
+//  			all_fields_mb += cs;
+//  			n++;
+//  			pos += occ[j].length();
+			
+//  		}
+//  	}
+
+//  	leader_directory_.nvf_  = n;
+//  	leader_directory_.base_ = GetLeaderSize() + leader_directory_.nvf_*GetDirEntrySize();
+//  	leader_directory_.mfrl_ = ComputeMfrl();
+
+//  	// 2   - Make record
+
+//  	record_.erase(); // Empty the record
+
+//  	// Prepare the binary part, note that this part must be  independent
+//  	// of the character set.
+
+//  	cstringstream ost(std::ios::out | std::ios::binary);   
+//  	ost << leader_directory_;   // Output the LeaderAndDirectory to a string
+
+	
+//  	AddToRecord(ost.str().c_str(), ost.str().length());
+
+//  	// Here comes the part which is dependent from the character set,
+//  	// the data itself.
+//  	AddToRecord((char*)all_fields_mb.c_str(), all_fields_mb.length());
+
+//  	DecomposeRecord();
+//  }
+
+//  MfRecord::MfRecord(const UMfRecord& rhs)     // Copy constructor
+//  { 
+//     Copy(rhs);
+//  }
+
+//  MfRecord& MfRecord::operator=(const UMfRecord& rhs) // Assignment
+//  {
+//     if (&leader_directory_ != &rhs.leader_directory_)
+//     {
+//     	   Copy(rhs);
+//     }
+//     return *this;
+//  }
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Accessors
+ 
+ 
+
+////////////////////////////////////////////////////////////////////////////////////////
+// Methods working on the in memory image of the record
+ 
+//-------------------------------------------------------------------------------
+// bool  MfRecord::GetField(int tag, string& s)
+//
+// This function takes as input a tag and will place the field into the string
+// s. It will return true if the field exists and false otherwise.
+//-------------------------------------------------------------------------------
+bool  MfRecord::GetField(int tag, ustring& s)
+{
+	PRECONDITION(tag>=0 && tag < SHRT_MAX);
+
+	map<int, ustring>::iterator it = fields_.find(tag);
+
+	bool ret = false;
+	if (it != fields_.end())
+	{
+		s   = it->second;
+		ret = true;
+	}
+	return ret;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// Modifiers, They synchronize the record structure with the internal structures
+
+
+//---------------------------------------------------------------------------------
+// AddField --- Add a field to the master record structure.
+//            
+//--------------------------------------------------------------------------------- 
+bool MfRecord::AddField(int tag, ustring& s)
+{
+	PRECONDITION(tag>=0 && tag < SHRT_MAX);
+
+	map<int, ustring>::iterator it = fields_.find(tag);
+
+	bool ret = false;
+	if (it == fields_.end())
+	{
+		fields_.insert(make_pair(tag, s));
+		tags_.push_back(tag);
+		sort(tags_.begin(), tags_.end());
+		ret = true;
+		ComposeRecord();
+	}
+	return ret;
+}
+//---------------------------------------------------------------------------------
+// AddOccurence --- Add an occurence to an existing field.
+//--------------------------------------------------------------------------------- 
+bool MfRecord::AddOccurence(int tag, ustring& o)
+{
+	PRECONDITION(tag>=0 && tag < SHRT_MAX);
+
+	map<int, ustring>::iterator it = fields_.find(tag);
+
+	bool ret = false;
+	if (it != fields_.end())
+	{
+	    it->second += SYSRSEP;
+		it->second += o;
+		ret = true;
+		ComposeRecord();
+	}
+	return ret;
+}
+
+//-----------------------------------------------------------------------------
+// bool  MfRecord::DeleteField(int tag)
+//
+//-----------------------------------------------------------------------------
+bool  MfRecord::DeleteField(int tag)
+{
+	PRECONDITION(tag>=0 && tag < SHRT_MAX);
+
+	map<int, ustring>::iterator it = fields_.find(tag);
+
+	bool ret = false;
+	if (it != fields_.end())
+	{
+		fields_.erase(it);
+		ret = true;
+		vector<int>::iterator j = find(tags_.begin(), tags_.end(), tag);
+		if (j != tags_.end())
+			tags_.erase(j);
+		ComposeRecord();
+	}
+	return ret;
+}
+
+//-------------------------------------------------------------------------------
+// bool ReplaceField(int tag, string& s)
+//
+//-------------------------------------------------------------------------------
+bool MfRecord::ReplaceField(int tag, ustring& s)
+{
+    
+	PRECONDITION(tag>=0 && tag < SHRT_MAX);
+
+	map<int, ustring>::iterator it = fields_.find(tag);
+
+	bool ret = false;
+	if (it != fields_.end())
+	{
+		it->second  = s;
+		ret         = true;
+	}
+	else
+		AddField(tag, s);
+	ComposeRecord();
+
+	return ret;
+}
+
+ustring MfRecord::GetAllFields()
+{
+	cstring all_fields; // As a string of ANSI characters
+	all_fields.erase();
+	all_fields = record_.substr(GetBase(), GetFieldSize());
+	return ustring(all_fields);
+}
+
+void MfRecord::ConvertToAnsi()
+{
+	/*
+	int mfrl = GetMfrl();
+	int size1 = record_.length();
+	if (GetFieldSize()==0)
+		return;
+	cstring s = record_.substr(GetBase(), GetFieldSize());
+	CString cs(s.c_str());
+	cs.OemToAnsi();
+	TRACE("\nbase=%d GetFieldSize=%d",GetBase(),GetFieldSize());
+	record_.replace(GetBase(),GetBase()+GetFieldSize(),
+		                                 cs.GetBuffer(GetFieldSize()));
+	int size2 = record_.length();
+	cs.ReleaseBuffer();
+	int padding = size1-size2;
+	for (int i=0; i<padding; i++)
+		record_ += " ";
+*/
+}
+
+long MfRecord::GetDirectorySize()
+{
+	return (GetNvf()*GetDirEntrySize());
+}
+
+long MfRecord::ComputeMfrl()
+{
+	return (GetLeaderSize() + GetDirectorySize() + GetFieldSize());
+}
+
+//--------------------------------------------------------------------------------------
+// void MfRecord::ComposeRecord()
+//
+// Build the record into continuous bytes for output
+//--------------------------------------------------------------------------------------
+void MfRecord::ComposeRecord()
+{
+	PRECONDITION(tags_.size() == fields_.size());
+	
+	// 1 - Prepare the LeaderAndDirectory, directory, end data part
+	int n   = 0;
+	int pos = 0;
+
+	ustring all_fields;
+    leader_directory_.dir_.clear();	
+	all_fields.erase();
+	for (vector<int>::size_type i=0; i!=tags_.size(); ++i)
+	{
+		int tag = tags_[i];
+		bool bRep = false;
+		if (pFdt_)
+		{
+			if (pFdt_->GetEntryAt(i).rep)
+			   bRep = true;
+		}
+		vector<ustring> occ;
+		if (bRep)
+			vector<ustring> occ = SplitOccurences(fields_[tags_[i]]);
+		else
+			occ.push_back(fields_[tags_[i]]);
+        // one entry per occurence
+		int nocc = occ.size();
+		for (vector<ustring>::size_type j=0; j!= nocc; ++j)
+		{
+			DirEntry de;
+			de.tag_ = tag;
+			de.pos_ = pos;
+			de.len_ = occ[j].length();
+            leader_directory_.dir_.push_back(de);
+			all_fields += occ[j];
+			n++;
+			pos += occ[j].length();
+			
+		}
+	}
+
+	leader_directory_.nvf_  = n;
+	leader_directory_.base_ = GetLeaderSize() + leader_directory_.nvf_*GetDirEntrySize();
+	leader_directory_.mfrl_ = ComputeMfrl();
+
+	// 2   - Make record
+
+	record_.erase(); // Empty the record
+
+	// Prepare the binary part, note that this part must be  independent
+	// of the character set.
+
+	cstringstream ost(std::ios::out | std::ios::binary);   
+	ost << leader_directory_;   // Output the LeaderAndDirectory to a string
+
+	
+	AddToRecord(ost.str().c_str(), ost.str().length());
+
+	// Here comes the part which is dependent from the character set,
+	// the data itself.
+	cstring all_fields_ansi(all_fields); 
+	AddToRecord(all_fields_ansi.c_str(), all_fields_ansi.length());
+	
+}
+
+//-------------------------------
+// Helper functions for decompose
+//-------------------------------
+
+bool MfRecord::CheckLeaderAndDirectory()
+{
+	if (GetMfrl() < 0)                  // Negative mfrl
+	{
+		//VLOG("DecomposeRecord -  Warning! Negative mfrl - mfn=%d", GetMfn());
+		SetMfrl(-GetMfrl());
+	}
+
+	if (GetMfrl()<=GetBase())
+	{
+		//VLOG("DecomposeRecord - Error! mfn=%d GetMfrl()=%d > GetBase()=%d", 
+		//	  GetMfn(),  GetMfrl(), GetBase());
+		return false;
+	}
+
+	
+
+	if (GetLeaderSize()>GetBase())
+	{
+		//VLOG("DecomposeRecord - Error! mfn=%d GetLeaderSize()=%d > GetBase()=%d", 
+		//	  GetMfn(),  GetLeaderSize(), GetBase());
+		return false;
+	}
+	if (GetNvf()==0) 
+	{
+	    // Null nvf      
+		//VLOG("DecomposeRecord -  Warning! mfn=%d nvf=0", GetMfn());
+		//SetNvf((GetBase() - GetLeaderSize()) / GetDirEntrySize());
+		return false;
+	}
+
+	if (GetMfn()<=0 || GetMfrl()<=0 || GetBase()<0 || GetNvf()<0 || GetStatus()< 0) 
+	{
+		//VLOG("DecomposeRecord - Error! mfn=%d GetMfrl()=%d GetLeaderSize()=%d GetBase()=%d GetNvf()=%d GetStatus()=%d", 
+		//      GetMfn(), GetMfrl(), GetLeaderSize(), GetBase(), GetNvf(), GetStatus());
+		return false;
+	}
+
+
+	int base = GetLeaderSize() + leader_directory_.nvf_*GetDirEntrySize();
+
+	if (record_.length() <= base)
+	{
+        //VLOG("DecomposeRecord - Error! mfn=%d record_.length()=%d < base=%d",
+		//	 GetMfn(), record_.length(), base);
+		return false;
+	}
+
+	int field_len = 0;
+	for (int i=0; i!=GetNvf(); ++i)
+	{
+		if (GetFieldTag(i)<0 || GetFieldTag(i)>SHRT_MAX ||
+			GetFieldPos(i)<0 || GetFieldPos(i)>SHRT_MAX ||
+			GetFieldLen(i)<0 || GetFieldLen(i)>SHRT_MAX)
+		{
+            //VLOG("DecomposeRecord - Error! mfn=%d Bad dir entry i=%d tag=%d pos=%d len=%d",
+			//    	GetMfn(), GetFieldTag(i), GetFieldPos(i), GetFieldLen(i));
+			return false;
+		}
+		field_len  += GetFieldLen(i);
+	}
+	
+    for (int j=0; j!=GetNvf(); ++j)
+	{
+		if (GetFieldPos(j)>=field_len || GetFieldPos(j)+GetFieldLen(j)>field_len)
+		{
+            //VLOG("DecomposeRecord - Error! mfn=%d Bad dir entry j=%d tag=%d pos=%d len=%d",
+			//    	GetMfn(), GetFieldTag(j), GetFieldPos(j), GetFieldLen(j));
+			return false;
+		}
+	}
+	// Check for bad values
+    if (GetBase() != base)	
+		SetBase(base);
+	
+	if (record_.length() < base + field_len)
+	{
+        //VLOG("DecomposeRecord - Error! mfn=%d record_.length()=%d < base=%d + field_len=%d",
+        //GetMfn(), record_.length(), base, field_len);  
+		return false;
+	}
+	return true;
+}
+
+void MfRecord::MakeTagToFieldMap()
+{
+	cstring all_fields_ansi;
+	all_fields_ansi.erase();
+	all_fields_ansi = record_.substr(leader_directory_.base_, GetFieldSize());
+	PRECONDITION(fields_.empty() && tags_.empty());
+
+
+	// Build the map from tags to fields
+	for (int i=0; i!=GetNvf(); ++i)
+	{
+		//int    all_len = all_fields.length();
+		//if (pos>all_len || pos+len>all_len)
+		//	return false;
+		cstring field_ansi = 
+			   all_fields_ansi.substr(GetFieldPos(i), GetFieldLen(i));
+		ustring field(field_ansi);
+	    map<int, ustring>::iterator it = fields_.find(GetFieldTag(i));
+	    if (it != fields_.end())
+		{
+			// Repeatable field, several occ
+		    it->second += SYSRSEP;
+			it->second += field;
+		}
+		else
+		{
+		    fields_.insert(make_pair(GetFieldTag(i), field));
+			
+		}
+		
+	}
+}
+void MfRecord::MakeTagVector()
+{
+	// Build a vector of tags
+	map<int, ustring>::const_iterator it;
+    for ( it = fields_.begin(); it != fields_.end(); ++it )
+		tags_.push_back(it->first);
+
+	// Sort in ascending order
+	sort(tags_.begin(), tags_.end());
+}
+
+
+//--------------------------------------------------------------------------------------
+// bool MfRecord::DecomposeRecord()
+//
+// Make a memory version of the record to facilitate manipulations.
+//--------------------------------------------------------------------------------------
+bool MfRecord::DecomposeRecord()
+{
+	PRECONDITION(!record_.empty());
+
+	if (record_.length() <= GetLeaderSize())
+	{
+		//VLOG("DecomposeRecord - Error! record_.length()=%d < GetLeaderSize()=%d",record_.length(), GetLeaderSize());
+		return false;
+	}
+
+	// Input the LeaderAndDirectory from a string
+    cstringstream ist(record_,cstringstream::in|cstringstream::binary);
+	if (!(ist >> leader_directory_))
+		return false;
+
+	if (!CheckLeaderAndDirectory())
+	{
+		//VLOG("Record rejected mfn=%ld", GetMfn());
+		return false;
+	}
+
+	//VLOG("Record accepted mfn=%ld", GetMfn());
+
+    MakeTagToFieldMap();
+    MakeTagVector();
+
+	return true;
+}
+
+
+
+void MfRecord::ExtractSubLeader()
+{
+	//PRECONDITION(!record_.empty() && record_.length()>=sizeof(leader_directory_.mfn_)+sizeof(leader_directory_.mfrl_));
+
+	leader_directory_.mfn_  = *(reinterpret_cast<ISIS_LONG*>((char *) record_.c_str()));
+	leader_directory_.mfrl_ = *(reinterpret_cast<ISIS_INT*> ((char *)(record_.c_str()+sizeof(ISIS_LONG))));
+	fix_endianness(leader_directory_.mfn_);
+	fix_endianness(leader_directory_.mfrl_);
+	if (leader_directory_.mfrl_ < 0) leader_directory_.mfrl_ = -leader_directory_.mfrl_; 	// mfrl can be negative!!!!
+
+	//POSTCONDITION(leader_directory_.mfn_>0 && leader_directory_.mfrl_>=0);
+}
+
+bool MfRecord::CheckLeader()
+{
+	int leader_size = GetLeaderSize();
+	if (leader_directory_.mfn_<=0)
+		return false;
+	if (abs(leader_directory_.mfrl_)<leader_size)
+		return false;
+	return true;
+}
+
+
+bool MfRecord::CheckIntegrity()
+{
+	int leader_size = GetLeaderSize();
+	if (leader_directory_.mfn_<=0)
+		return false;
+	if (abs(leader_directory_.mfrl_)<leader_size)
+		return false;
+	if (leader_directory_.nvf_<0)
+		return false;
+	//if (leader_directory_.base_ != leader_directory_size + leader_directory_.nvf_*sizeof(MAXDIRL))
+	//	return false;
+	if (leader_directory_.status_ == 1)
+		return true;
+	else if (leader_directory_.status_ == 0)
+		return true;
+	else
+		return false;
+
+	return true;
+}
+ 
+
+void  MfRecord::Dump()
+{
+
+	ustringstream os;
+    os.str("");
+
+
+    os <<  "\n================= entry in MfRecord::Dump==============";
+    os <<  "\n   MFN      " << GetMfn();
+    os <<  "\n   MFRL     " << GetMfrl();
+    os <<  "\n   MFBWB    " << GetMfbwb();
+    os <<  "\n   MFBWP    " << GetMfbwp();
+    os <<  "\n   BASE     " << GetBase();
+    os <<  "\n   NVF      " << GetNvf();
+    os <<  "\n   STATUS   " << GetStatus();
+ 	//TRACE(os.str().c_str());
+
+
+	for (int i=0; i<GetNvf(); i++)
+	{
+		  ustring stemp;
+		  bool rc = GetField(GetDirEntry(i).tag_, stemp);
+		  int len;
+		  if (rc)
+		  {
+		       len = 50;
+		       if (stemp.length()<len)
+			      len = stemp.length();
+		  }
+		  ustring fld = (rc==false) ? _T("Empty") : stemp.substr(0,len);
+	      os.str("");
+		  os << _T(" tag=") << ISIS_INT(GetDirEntry(i).tag_)
+             << _T(" pos=") << ISIS_INT(GetDirEntry(i).pos_)
+			 << _T(" len=") << ISIS_INT(GetDirEntry(i).len_)
+			 << _T(" ")     << fld.c_str() << std::endl; 
+          TRACE(_T("\n%s"),os.str().c_str());   
+	  }
+
+      TRACE("\n---------------- exit in MfRecord::Dump-------------");
+}
+
+
+
+
+bool MfRecord::CheckRecord()
+{
+	PRECONDITION(!record_.empty());
+
+	if (record_.length() < GetLeaderSize())
+	{
+		TRACE(_T("\nWrong LeaderAndDirectory in record!"));
+		return false;
+	}
+
+    cstringstream ist(record_,cstringstream::in|cstringstream::binary);
+
+	LeaderAndDirectory leader_directory;
+	ist >> leader_directory;
+
+	if (leader_directory.mfrl_ < 0)                  // Negative mfrl
+	{
+		//VLOG("CheckRecord -  Warning! Negative mfrl - mfn=%d", GetMfn());
+	}
+	
+	if (leader_directory.nvf_<=0) 
+	{
+		//VLOG("CheckRecord -  Warning! mfn=%d nvf=0", leader_directory.mfn_);
+	}
+
+	if (leader_directory.mfn_<=0 || leader_directory.mfrl_<=0 ||
+		leader_directory.base_<0 || leader_directory.nvf_ < 0 ||
+		leader_directory.status_ < 0) 
+	{
+		//VLOG("CheckRecord - Corrupted record! leader_directory.mfn_=%d leader_directory.mfrl_=%d leader_directory.base_=%d leader_directory.nvf_=%d leader_directory.status_=%d",
+        //      leader_directory.mfn_, leader_directory.mfrl_,
+		//	  leader_directory.base_, leader_directory.nvf_,
+		//	  leader_directory.status_);
+		return false;
+	}
+
+
+	int base = GetLeaderSize() + GetDirectorySize();
+
+	if (record_.length() < base)
+	{
+		//VLOG("CheckRecord - Corrupted record! mfn=%d record_.length()=%d base=%d",
+		//	  leader_directory.mfn_, record_.length(), base);
+		return false;
+	}
+
+	int field_len = 0;
+	for (int i=0; i!=leader_directory.nvf_; ++i)
+	{
+		DirEntry de = leader_directory.dir_[i];
+//  		if (de.tag_<0 || de.tag_>SHRT_MAX || de.pos_<0 || de.pos_>SHRT_MAX || de.len_<0 || de.len_>SHRT_MAX)
+//  		{
+//  		    //VLOG("CheckRecord - Corrupted record! mfn=%d tag=%d pos=%d len=%d",
+//  			//	  leader_directory.mfn_, de.tag_, de.pos_, de.len_);
+//  			return false;
+//  		}
+		if (i>0)
+		{
+			if(de.pos_ != leader_directory.dir_[i-1].pos_+leader_directory.dir_[i-1].len_)
+			{
+		    //VLOG("CheckRecord - Position not consistent - mfn=%d",
+			//	  leader_directory.mfn_);
+			return false;
+			}
+		}
+		field_len  += de.len_;
+	}
+	
+
+	// Check for bad values
+    if (leader_directory.base_ != base)	
+		leader_directory.base_ = base;
+	
+	if (record_.length() < base + field_len)
+	{
+		    //VLOG("CheckRecord - Corrupted record, record length < base+field_len  - mfn=%ld",
+			//	  leader_directory.mfn_);
+		return false;
+	}
+
+	return true;
+}
+
+void MfRecord::ReadLeader(MfFile& f, long daddr)
+{
+    int leader_size = GetLeaderSize();
+    char* buffer = new char[leader_size];
+    f.Fetch(buffer, leader_size, daddr);  // Read record leader
+    Clear();
+    AddToRecord(buffer, leader_size);
+    delete[] buffer;
+}
+
+bool  MfRecord::Read(MfFile& f, long mfb, int mfp)
+{
+    //TRACE("\nMfFile::ReadMfRecord -- mfb=%ld mfp=%d", mfb, mfp);
+	PRECONDITION(mfb>0 && mfb<=MAXMFB);
+    long  blk;
+    int   mfrr, offs, l;
+
+	try
+	{
+		Clear();
+	    // Save original mfb, mfp pair into m
+	    SetMfbRead(mfb);
+	    SetMfpRead(mfp);
+	    SetState(MfRecord::Record_Read);
+
+	    // Be sure that mfp is in range [0:MFBLKSIZE-1]
+	    mfp = mfp%MFBLKSIZE;
+		assert(mfp>=0 && mfp<MFBLKSIZE);
+        //TRACE("\nMfFile::ReadMfRecord - mfb=%ld mfp=%d", mfb, mfp);
+
+		// 1 - Read block where record starts 
+        f.ReadBlk(m_buf,mfb);                    
+
+        blk = mfb;
+		// 2 - Extract the record leader (Mfn+Mfrl) from the block buffer, the 
+		//     record leader cannot be split on two  consecutive blocks.
+        int len = GetSubLeaderSize(); // Mfn + Mfrl
+		ASSERT(mfp+len<MFBLKSIZE);
+
+        AddToRecord(m_buf+mfp, len); // Move 1st 6 bytes  (Mfn+Mfrl)
+		ExtractSubLeader();
+
+		// 3 - Continue to transfer data for building the MfRecord object
+        int mflen = GetMfrl();                // Get record length
+	    SetMflenRead(mflen);                  // Save it 
+        //TRACE("\nMfFile::readMfRecord - After reading leader mfn=%ld mflen=%d",GetMfn(), mflen);
+        mfrr = mflen - len;                     // Not yet moved
+        l = (mfrr > (f.GetBlockSize()-(mfp+len)))      // What remains to move
+            ? (f.GetBlockSize()-(mfp+len)) : mfrr;         // in this block
+        offs = len;
+        AddToRecord(m_buf+mfp+len, l); // Move-it
+        mfrr -= l;
+        while (mfrr>0)                        // Record continues on next block ?
+		{                
+            f.ReadBlk(m_buf,++blk);             // Yes read next block
+            offs += l;
+            l = (mfrr > f.GetBlockSize()) ? f.GetBlockSize() : mfrr;
+            AddToRecord(m_buf, l); // Move data
+            mfrr -= l;
+		}
+	    //TRACE("\nMfFile::ReadMfRecord -- mfb=%ld mfp=%d nvf=%d", mfb, mfp, GetNvf());
+	}
+	catch (CFileBaseException e)
+	{
+        throw CIsisDbException(ISIS_MF_READ_ERROR, __FILE__, __LINE__);
+	}
+
+	return DecomposeRecord();
+}
+
+
+void  MfRecord::Write(MfFile& f, long mfb, int mfp)
+{
+	TRACE(_T("\nMfFile::writeMfRecord - mfb=%ld mfp=%d"), mfb, mfp);
+	PRECONDITION(mfb>0 && mfb <= MAXMFB);
+	// Be sure that mfp is in range [0:MFBLKSIZE-1]
+	mfp = mfp%MFBLKSIZE;
+	
+    long hiblk = f.GetNextMfb(); // Highest block number in master file
+	
+    int s  = 0;              // Index in master file record [0:mfrl-1]
+    int d  = mfp;            // Index in block buffer [0:bsize-1]
+    long b = mfb;            // Starting block number
+	
+    // Adjust record length
+	int padding = GetMfrl() % MFALIGN;
+	if (padding>0)
+	{
+		SetMfrl(GetMfrl() + padding);
+		for (int i=0; i<padding;i++)
+			AddToRecord(" ", 1);
+	}
+	
+    int mfrl = GetMfrl();
+    TRACE(_T("\nMfFile::writeMfRecord - b=%ld d=%d mfrl=%ld hiblk=%ld"), b, d, mfrl, hiblk);
+    TRACE(_T("\nBefore writing->"));
+	do 
+    {
+		if (b <= hiblk)        
+			f.ReadBlk(m_buf, b);
+		else
+			::memset(m_buf, ' ', MFBLKSIZE);
+		
+		while (d < MFBLKSIZE && s < mfrl)
+			m_buf[d++] = record_.at(s++);
+		if (d >= MFBLKSIZE) 
+		{
+			TRACE(_T("MfFile::WriteMfRecord - Before WriteBlk b=%ld"), b);
+			f.SetLastWrittenBlock(b);
+			f.WriteBlk(m_buf, b++);
+			// Reset m_buf pos
+			d = 0;
+		}
+	} while (s < mfrl);
+	
+    // Write last block
+	if (d == 0)
+		::memset(m_buf, ' ', MFBLKSIZE); // Should be an empty block
+	
+	f.WriteBlk(m_buf, b);       
+	f.SetLastWrittenBlock(b);
+} 
+
+void IntToChar(int value, int width, std::string& s)
+{
+	std::ostringstream ost;
+
+#ifdef _WIN32
+	ost.setf(std::ios_base::right, std::ios_base::adjustfield);
+#endif
+	ost << std::setw(width) 
+		<< std::setfill('0') 
+		<< value;
+	s = ost.str();
+}
+//--------------------------------------------------------------------------------------
+// void MfRecord::MakeISORecord(std::string& s)
+//
+// Build the record into continuous bytes for output
+//--------------------------------------------------------------------------------------
+void MfRecord::MakeISORecord(std::string& s)
+{
+	std::string    tmp;
+
+	MarcLeader l;
+
+	// 1 - Complete the leader (base and record length), output the directory 
+	//     to a string and prepare a string with the data fields
+	int base = MARC_LEADER_LEN + GetNvf()*MARC_DIRENT_LEN + 1;
+	IntToChar(base, 5, tmp);
+	strncpy(l.base_ ,tmp.c_str(),5);
+
+	DirectoryEntry mde;
+	ustring    all_fields;
+	all_fields.erase();
+	ostringstream  osd;     // Output the directory to a string
+	int pos = 0; 
+	for (int i=0; i!=GetNvf(); ++i)
+	{
+		IntToChar(GetFieldTag(i), 3, tmp); 
+		strncpy(mde.tag_,tmp.c_str(),3);
+		int len = GetFieldLen(i)+1;  // Include space for separator
+		IntToChar(len, 4, tmp);
+		strncpy(mde.len_, tmp.c_str(), 4);
+		IntToChar(pos, 5, tmp);
+		strncpy(mde.scp_, tmp.c_str(), 5);
+		osd << mde; 
+		pos += len;
+
+		cstring field = record_.substr(GetBase()+GetFieldPos(i), GetFieldLen(i));
+		all_fields += ustring(field);
+		all_fields += FIELDTERM;
+	}
+	// (+2) ->Field sep at end of directory and record sep
+    int reclen =  MARC_LEADER_LEN + GetNvf()*MARC_DIRENT_LEN + pos +2;
+	IntToChar(reclen, 5, tmp);
+	strncpy(l.lreclen_,tmp.c_str(),5);
+
+
+	ostringstream osl;     // Output the Leader to a string
+	osl << l;
+
+	// 2   - Make record
+	s.erase();       // Empty the record
+    s += osl.str();  // Add the leader
+	s += osd.str();  // Add the directory
+	s += FIELDTERM;  // Separator
+	s += cstring(all_fields); // Data part
+	s += RECTERM;
+		
+}
Index: /gsdl/trunk/build-src/packages/isis-gdl/Master.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Master.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Master.h	(revision 16571)
@@ -0,0 +1,609 @@
+/**********************************************************************
+ *
+ * Master.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+///////////////////////////////////////                                   */
+//  Master.h: Master File Record object
+///////////////////////////////////////                                   */
+ 
+#ifndef __MASTER_RECORD_H__
+#define __MASTER_RECORD_H__
+
+#include "BlkFile.h"
+#include <vector>
+#include <map>
+#include <sstream>
+
+
+ 
+// Length in bytes of master file header 
+#define MFCTLLEN sizeof(SMfHeader)+sizeof(SMfHeader) // Length in bytes of master file header
+
+const int MFALIGN   =    2;   // Master file record alignment
+const int MFBLKSIZE =  512;   // Master file block size
+ 
+typedef short int ISIS_INT;
+typedef long  int ISIS_LONG;
+
+#ifdef UNIX_BIREME
+    //Length of Leader in master record
+	inline 	int GetLeaderSize()
+	{
+		return (2*sizeof(ISIS_LONG)+6*sizeof(ISIS_INT));
+	}
+    // Mini Leader length guaranteed to be in same block
+	inline 	int GetMinLeaderSize()
+	{ 
+		return (2*sizeof(ISIS_LONG)+4*sizeof(ISIS_INT));
+	}
+#else
+    //Length of Leader in master record
+	inline 	int GetLeaderSize() 
+	{
+		return (2*sizeof(ISIS_LONG)+5*sizeof(ISIS_INT)); 
+	}
+    // Mini Leader length guaranteed to be in same block
+	inline 	int GetMinLeaderSize()
+	{ 
+		return (2*sizeof(ISIS_LONG)+3*sizeof(ISIS_INT));
+	}
+#endif
+
+// Size of Mfn and Mfrl in the leader part
+inline int GetSubLeaderSize() { return sizeof(ISIS_LONG)+sizeof(ISIS_INT); }
+ 
+inline int GetDirEntrySize() { return (3*sizeof(ISIS_INT)); }
+ 
+ 
+const TCHAR SYSRSEP      =  TCHAR('%'); // Repeatable field separator
+const TCHAR SUBFIELD_SEP =  TCHAR('^'); // Subfield separator
+
+////////////////////////////////////////
+// Directory entry aggregate structure
+//
+struct DirEntry  
+{
+   ISIS_INT  tag_;
+   ISIS_INT  pos_;
+   ISIS_INT  len_;
+   DirEntry() 
+	   : tag_(0), pos_(0), len_ (0) {  }
+
+   DirEntry(ISIS_INT tag, ISIS_INT pos, ISIS_INT len)
+	   : tag_(tag), pos_(pos), len_ (len) {  }
+   bool operator==(const DirEntry& rhs) const
+   {
+	   if (tag_!=rhs.tag_ || pos_!=rhs.pos_ || len_!=rhs.len_)
+		   return false;
+	   return true;
+   }
+   bool operator!=(const DirEntry& rhs) const
+   {
+	   if (tag_!=rhs.tag_ || pos_!=rhs.pos_ || len_!=rhs.len_)
+		   return true;
+	   return false;
+   }
+
+};
+ 
+
+//////////////////////////////////////////////////////////////////////////
+// Data Master record aggregate structure
+//
+struct LeaderAndDirectory 
+{
+   ISIS_LONG        mfn_;            // Master file number
+   ISIS_INT         mfrl_;           // Record length
+   ISIS_LONG        mfbwb_;          // Backward pointer block number
+   ISIS_INT         mfbwp_;          // Backward pointer offset
+   ISIS_INT         base_;           // Offset to begining of variable fields
+   ISIS_INT         nvf_;            // Number of directory entries
+   ISIS_INT         status_;         // 1 = DELETED
+   std::vector<DirEntry> dir_;            // Directory
+
+   LeaderAndDirectory()
+   {
+	   Clear();
+   }
+   LeaderAndDirectory(const LeaderAndDirectory& src)
+   {
+	   Copy(src);
+   }
+
+   LeaderAndDirectory& operator=(const LeaderAndDirectory& rhs)
+   {
+	   if (&mfn_ != &rhs.mfn_)
+	   {
+		   Copy(rhs);
+	   }
+	   return *this;
+   }
+
+   void Copy(const LeaderAndDirectory& rhs)
+   {
+	   mfn_    = rhs.mfn_;
+	   mfrl_   = rhs.mfrl_;
+	   mfbwb_  = rhs.mfbwb_;
+	   mfbwp_  = rhs.mfbwp_;
+       base_   = rhs.base_;
+       nvf_    = rhs.nvf_;
+	   status_ = rhs.status_;
+	   dir_    = rhs.dir_;
+   }
+   void Clear()
+   {
+	   mfn_ = mfrl_ = mfbwb_ = mfbwp_ = base_ = nvf_ = status_ = 0;
+	   dir_.clear();
+   }
+
+   bool operator==(const LeaderAndDirectory& rhs) const;
+   bool operator!=(const LeaderAndDirectory& rhs) const;
+   int GetFieldSize();
+};
+
+cstringstream& operator<<(cstringstream& s, const LeaderAndDirectory& leader);
+cstringstream& operator>>(cstringstream& s, LeaderAndDirectory& leader);
+
+////////////////////////////////////////////////////////////
+//
+ 
+/////////////////////////////////
+// Data master file record class
+//
+
+typedef std::map<int, ustring> TAG2FIELD;
+class MfFile;
+class MstFile;
+class IsisDb;
+class ACE_InputCDR;
+class ACE_OutputCDR;
+class UMfRecord;
+
+
+class  MfRecord
+{
+	friend class MfFile;
+	friend class MstFile;
+	friend class IsisDb;
+	friend class UMfRecord;
+    friend int operator>>(ACE_InputCDR& cdr, MfRecord& mfr);
+    friend int operator<<(ACE_OutputCDR& cdr, MfRecord& mfr);
+protected:
+
+	CFdt*                pFdt_;        // Use a copy of the FDT
+	cstring              record_;      // Record in continuous storage
+	                                   // always as ANSI!
+	
+	LeaderAndDirectory           leader_directory_;
+	
+	TAG2FIELD        fields_;
+	std::vector<int> tags_;
+    static char      m_buf[MFBLKSIZE];      // Buffer to hold 1 File block
+
+protected: // Additional data
+	short int state_;         // Record state in memory
+	long      mfb_read_;      // Record was read at Block number [1...]
+	int       mfp_read_;      // Record was read at position in block
+	int       mflen_read_;    // Record length was when record read 
+
+protected:
+   void         Copy(const MfRecord& rhs); 
+   
+   void         AddToRecord(const char* p, int len);
+   int          AddDirEntry(const DirEntry& d);
+   int          AddDirEntry(int tag, int pos, int len);
+   int          DelDirEntry(int i);
+   void         SetMfrl(int mfrl);
+   void         SetMfbwb(long mfbwb);
+   void         SetMfbwp(int mfbwp);
+   void         SetBase(int base);
+   void         SetNvf(int nvf);
+   void         SetStatus(int s);
+   int          SetDirEntry(int i, int tag, int pos, int len);
+   int          SetDirEntry(int i, const DirEntry& d);
+   void         SetMfbRead(long b);
+   void         SetMfpRead(int pos);
+   void         SetMflenRead(int len);
+
+ 
+   void         SetSubLeaderAndDirectory(const char* p, int len);
+
+
+   void         MakeTagToFieldMap();
+   void         MakeTagVector();
+
+   long         ComputeMfrl();
+
+   void         Copy(UMfRecord& rhs);           
+public:
+	enum { Record_Empty, Record_Read, Record_Changed, Record_Created };
+
+public:
+   //-----------------
+   // Public Interface
+   //-----------------
+   MfRecord(CFdt* pFdt=NULL);                // Default constructor   
+   virtual ~MfRecord();                      // Destructor
+
+   MfRecord(const MfRecord& rhs);            // Copy constructor
+   MfRecord& operator=(const MfRecord& rhs); // Assignment
+ 
+   MfRecord(const UMfRecord& umfr);
+   MfRecord& operator=(const UMfRecord& rhs);
+
+   void Clear();
+   void ClearData();
+
+
+   void ReadLeader(MfFile& f, long daddr);
+   bool Read (MfFile& f, long mfb, int mfp);
+   void Write(MfFile& f, long mfb, int mfp);
+
+   void MakeISORecord(std::string& s);
+ 
+   long         GetMfn()           const; // Get MFN
+   int          GetMfrl()          const; // Get Master File Record Length
+   long         GetMfbwb()         const; // Get Master File Backward Block number
+   int          GetMfbwp()         const; // Get Master File Backward block position
+   int          GetBase()          const; // Get Variable fields starting byte
+   int          GetNvf()           const; // Get Number of entries in the directory
+   int          GetStatus()        const; // Get Record Status
+   DirEntry     GetDirEntry(int i) const; // Get a reference to the ieme directory entry
+   int          GetState()         const; // Get record state in memory
+   long         GetMfbRead()       const;
+   int          GetMfpRead()       const;
+   int          GetMflenRead()     const;
+
+   ustring     GetAllFields(); // ANSI or UNICODE
+   cstring     GetRecordAsString() { return record_; }
+   const char* GetRecord()         { return record_.c_str(); }
+   int         GetRecordLength()   { return record_.length(); }
+
+   void        ConvertToAnsi();
+
+
+   bool         GetField(int tag, std::string& s);  // Get field content for field with tag "tag" 
+   bool         AddField(int tag, std::string& s);
+   bool         DeleteField(int tag);
+   bool         ReplaceField(int tag, std::string& s);
+   bool         AddOccurence(int tag, std::string& o);
+
+   int          GetFieldTag(int i);
+   int          GetFieldPos(int i);
+   int          GetFieldLen(int i);
+ 
+   void         SetMfn(long mfn);
+   void         SetState(int s);
+
+   long         GetDirectorySize();
+   int          GetFieldSize()     { return leader_directory_.GetFieldSize(); }
+
+   std::vector<int>  GetFieldTags(); // Get tags of fields in increasing order,
+                                     // Occurences made only 1 field
+   void         ExtractSubLeader();
+   void         ExtractLeader();
+   bool         CheckIntegrity();
+   bool         CheckLeader();
+   bool         CheckLeaderAndDirectory(); 
+
+   bool operator==(const MfRecord& rhs) const
+   {
+	   return (record_ == rhs.record_); 
+   }
+   bool operator!=(const MfRecord& rhs) const
+   {
+	   return (record_ != rhs.record_); 
+   }
+
+   void         SetRecord(const char *s) { record_ = s;  DecomposeRecord();}
+   void         SetRecord(const cstring &s) 
+				{ record_ = s;  DecomposeRecord();}
+   void         ComposeRecord();
+   bool         DecomposeRecord();
+
+   bool         CheckRecord();
+   void         Dump();
+} ;
+ 
+//////////////////////////////
+ 
+
+
+
+inline void MfRecord::AddToRecord(const char* p, int len)
+{
+	record_ += cstring(p,len);
+} 
+
+/////////////////////////////
+
+inline MfRecord::MfRecord(CFdt* pFdt) 
+// Makes a Master file Record object
+{
+	Clear();
+	pFdt_ = pFdt;
+   // Nothing more to do
+}
+ 
+inline void MfRecord::Copy(const MfRecord& rhs)           
+{
+   record_     = rhs.record_;
+   leader_directory_     = rhs.leader_directory_;
+   fields_     = rhs.fields_;
+   state_      = rhs.state_;
+   mfb_read_   = rhs.mfb_read_;
+   mfp_read_   = rhs.mfp_read_;
+   mflen_read_ = rhs.mflen_read_;
+   tags_       = rhs.tags_;         
+	pFdt_      = rhs.pFdt_;
+}
+
+inline MfRecord::MfRecord(const MfRecord& rhs)     // Copy constructor
+{ 
+   Copy(rhs);
+}
+
+inline MfRecord& MfRecord::operator=(const MfRecord& rhs) // Assignment
+{
+   if (&leader_directory_ != &rhs.leader_directory_)
+   {
+   	   Copy(rhs);
+   }
+   return *this;
+}
+ 
+inline void MfRecord::Clear()
+{
+   tags_.clear();
+   record_.erase();
+   leader_directory_.Clear();
+   fields_.clear();
+   SetBase(GetLeaderSize());
+   SetMfrl(GetLeaderSize());
+   state_ = Record_Empty;
+   mfb_read_ = mfp_read_ = mflen_read_ = 0;
+   pFdt_ = NULL;
+}
+
+// Clear the data part but keep other info intact so that
+// it appears as an empty record
+inline void MfRecord::ClearData()
+{
+   tags_.clear();
+   record_.erase();
+   leader_directory_.Clear();
+   fields_.clear();
+   SetBase(GetLeaderSize());
+   SetMfrl(GetLeaderSize());
+}
+
+
+//////////////////////////////
+ 
+inline MfRecord::~MfRecord()
+{
+}
+ 
+//////////////////////////////
+ 
+inline long MfRecord::GetMfn() const
+// Returns Master file number
+{
+   return leader_directory_.mfn_;
+}
+ 
+//////////////////////////////
+ 
+inline int MfRecord::GetMfrl() const
+// Returns Master file record length
+{
+   return leader_directory_.mfrl_;
+}
+ 
+//////////////////////////////
+ 
+inline long MfRecord::GetMfbwb() const
+// Returns backward pointer block number
+{
+   return leader_directory_.mfbwb_;
+}
+ 
+//////////////////////////////
+ 
+inline int MfRecord::GetMfbwp() const
+// Returns backward pointer offset
+{
+   return leader_directory_.mfbwp_;
+}
+ 
+//////////////////////////////
+ 
+inline int MfRecord::GetBase() const
+// Returns base value to field data
+{
+    return leader_directory_.base_;
+}
+ 
+//////////////////////////////
+ 
+inline int MfRecord::GetNvf() const
+// Returns the number of directory entries
+// in the master file record
+{
+   return leader_directory_.nvf_;
+}
+
+//////////////////////////////
+ 
+inline int MfRecord::GetStatus() const
+// Returns the status of the record
+{
+   return leader_directory_.status_;
+}
+
+//////////////////////////////
+ 
+ 
+//////////////////////////////
+ 
+inline DirEntry MfRecord::GetDirEntry(int i) const
+// Returns the ith dir entry
+{
+   return leader_directory_.dir_[i];
+} 
+
+//////////////////////////////
+ 
+inline int MfRecord::GetState() const
+{
+   return state_;
+} 
+
+//////////////////////////////
+ 
+inline long MfRecord::GetMfbRead() const
+{
+   return mfb_read_;
+} 
+//////////////////////////////
+ 
+inline int MfRecord::GetMfpRead() const
+{
+   return mfp_read_;
+} 
+    
+//////////////////////////////
+ 
+// Get tags of fields in increasing order,
+inline std::vector<int> MfRecord::GetFieldTags()
+{
+	PRECONDITION(tags_.size() == fields_.size());
+	return tags_;
+}
+//////////////////////////////
+ 
+inline int MfRecord::GetMflenRead() const
+{
+   return mflen_read_;
+} 
+    
+///////////////////////////////////////////////////////////////////////////////
+ 
+inline void MfRecord::SetMfn(long mfn)
+// Set Master file number
+{
+	assert(mfn>0);
+    leader_directory_.mfn_ = mfn;
+}
+//////////////////////////////
+ 
+inline void MfRecord::SetMfrl(int mfrl)
+// Set Master file record length
+{
+	assert(mfrl>0);
+    leader_directory_.mfrl_ = mfrl;
+}
+//////////////////////////////
+ 
+inline void MfRecord::SetMfbwb(long mfbwb)
+// Sets backward pointer block number to mfbwb
+{
+	assert(mfbwb>=0);
+    leader_directory_.mfbwb_ = mfbwb;
+}
+
+//////////////////////////////
+ 
+inline void MfRecord::SetMfbwp(int mfbwp)
+// Sets backward pointer block offset to mfbwp
+{
+	assert(mfbwp>=0);
+    leader_directory_.mfbwp_ = mfbwp;
+}
+//////////////////////////////
+ 
+inline void  MfRecord::SetBase(int base)
+// Sets the base value in the record aggregate
+{
+	assert(base>=0);
+    leader_directory_.base_ = base;
+}
+
+//////////////////////////////
+ 
+inline void MfRecord::SetNvf(int nvf)
+// Sets the number of entries in the directory part
+{
+	assert(nvf>=0);
+    leader_directory_.nvf_ = nvf;
+}
+ 
+//////////////////////////////
+ 
+inline void MfRecord::SetStatus(int s)
+// Sets the status of the record
+{
+   leader_directory_.status_ = s;
+}
+ 
+//////////////////////////////
+ 
+inline void MfRecord::SetState(int s)
+// Sets the status of the record
+{
+	assert(s==MfRecord::Record_Empty || s==MfRecord::Record_Read 
+		|| s==MfRecord::Record_Changed || s==MfRecord::Record_Created);
+   state_ = s;
+}
+
+inline void MfRecord::SetMfbRead(long b)
+{
+	mfb_read_ = b;
+}
+
+inline void MfRecord::SetMfpRead(int pos)
+{
+	mfp_read_ = pos;
+}
+
+inline void MfRecord::SetMflenRead(int len)
+{
+	mflen_read_ = len;
+}
+
+inline int MfRecord::GetFieldTag(int i)
+{
+	return leader_directory_.dir_[i].tag_;
+}
+inline int MfRecord::GetFieldPos(int i)
+{
+	return leader_directory_.dir_[i].pos_;
+}
+
+inline int MfRecord::GetFieldLen(int i)
+{
+	return leader_directory_.dir_[i].len_;
+}
+
+#endif
Index: /gsdl/trunk/build-src/packages/isis-gdl/Unimarc.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Unimarc.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Unimarc.cpp	(revision 16571)
@@ -0,0 +1,620 @@
+/**********************************************************************
+ *
+ * Unimarc.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "stdafx.h"
+
+///////////////////////////////////////////////////////////////////////////////////
+// MarcRecord - This class can instantiate objects that represent a MARC
+//              bibilographic record and includes methods for manipulating the 
+//              record.
+//
+//             example:
+//
+//	#include "Unimarc.h"
+//
+//     // Create a MarcRecord object with a raw MARC record
+//     MarcRecord mr(buf,1)
+//     mr.PrettyFormat("The title is %245, which is the field with tag 245");
+#include <vector>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "Unimarc.h"
+
+//-------------------------------------------------------------------------------
+// ostream& operator<<(ostream& s, const MarcLeader& leader)
+//
+// Overloaded instance of the output operator for MarcLeader objects
+//---------------------------------------------------------------------------------
+std::ostream& operator<<(std::ostream& s, const MarcLeader& leader)
+{
+	s.write(leader.lreclen_, 5);	// Logical record length
+	s.write(&leader.status_, 1);	// Record status  
+	s.write(&leader.type_, 1);		// Type of record
+	s.write(&leader.bibLevel_, 1);	// Bibliographic level
+	s.write(&leader.ctrlType_, 1);	// Type of control
+	s.write(&leader.undPos_, 1);	// Undefined character position
+	s.write(&leader.indCount_, 1);	// Indicator count
+	s.write(&leader.scd_, 1);		// Subfield code count
+	s.write(leader.base_, 5);   	// Base address of data
+	s.write(&leader.encLevel_, 1);	// Encoding level
+	s.write(&leader.dcf_, 1);		// Descriptive cataloging form
+	s.write(&leader.lrr_, 1);		// Linked record requirement
+	  // Directory  entry map
+	s.write(&leader.llof_, 1);		// Length of the length-of-field portion
+	s.write(&leader.lscp_, 1);		// Length of starting-character-position portion
+	s.write(&leader.lidp_, 1);		// Length of implementation-defined portion
+	s.write(&leader.uep_, 1);		// Undefined entry map character position
+	return s;
+}
+
+//----------------------------------------------------------------------------------
+// istream& operator>>(istream& s, const MarcLeader& leader)
+//
+// Overloaded instance of the input operator for MarcLeader objects
+//----------------------------------------------------------------------------------
+std::istream& operator>>(std::istream& s, MarcLeader& leader)
+{
+	s.read(leader.lreclen_, 5);	    // Logical record length
+	s.read(&leader.status_, 1);	    // Record status  
+	s.read(&leader.type_, 1);		// Type of record
+	s.read(&leader.bibLevel_, 1);	// Bibliographic level
+	s.read(&leader.ctrlType_, 1);	// Type of control
+	s.read(&leader.undPos_, 1);	    // Undefined character position
+	s.read(&leader.indCount_, 1);	// Indicator count
+	s.read(&leader.scd_, 1);		// Subfield code count
+	s.read(leader.base_, 5);   	    // Base address of data
+	s.read(&leader.encLevel_, 1);	// Encoding level
+	s.read(&leader.dcf_, 1);		// Descriptive cataloging form
+	s.read(&leader.lrr_, 1);		// Linked record requirement
+	  // Directory  entry map
+	s.read(&leader.llof_, 1);		// Length of the length-of-field portion
+	s.read(&leader.lscp_, 1);		// Length of starting-character-position portion
+	s.read(&leader.lidp_, 1);		// Length of implementation-defined portion
+	s.read(&leader.uep_, 1);		// Undefined entry map character position
+	return s;
+}
+
+/************************************************************************
+Local prototypes
+ ***********************************************************************/
+static void Printx(FILE *fp, char *s, int x);
+
+//----------------------------------------------------------------------
+// MarcRecord::MarcRecord(char *data, int length, int copyData)
+// 
+// Constructor that creates a new MarcRecord object. 
+// data is raw marc record data for a single record.  If copyData is 1, 
+// data is encapsulated within this object.  If 0, does not copy data and 
+// responsibility falls to caller to maintain data pointer.
+//----------------------------------------------------------------------
+MarcRecord::MarcRecord(char* data, int length, int copyData)
+{
+	encapsulated_ = copyData;
+	
+	/* encapsulate or set pointer to data */
+	if (encapsulated_)
+	{
+		data_ = new char[length + 1]; 
+		memcpy(data_, data, length);
+		data_[length] = '\0';
+	}
+	else
+		data = data;
+	
+	// Lay leader overlay onto data
+	leader_ = *(MarcLeader *) (data_);
+	
+	// Parse the record.  sets dirCount_, directory_ 
+	if (!ParseMarcRecord()) 
+	{
+		// marcRecord_destroy(m);
+		// return NULL;
+	}
+}
+
+//----------------------------------------------------------------------
+// void MarcRecord::~MarcRecord()
+//
+// Destructor, destroys a MarcRecord object and all used resources.
+//----------------------------------------------------------------------
+MarcRecord::~MarcRecord()
+{
+	if ((encapsulated_) && (data_))
+		delete[] data_;
+
+	for (std::vector<MarcDirectoryEntry>::size_type i=0; i!=directory_.size(); ++i)
+		directory_[i].field_.erase(directory_[i].field_.begin(),directory_[i].field_.end());
+	directory_.erase(directory_.begin(),directory_.end());
+}
+
+#define MARC_STATE_IDLE 0
+#define MARC_STATE_TAG 1
+#define MARC_STATE_WIDTH 2
+//----------------------------------------------------------------------
+// int MarcRecord::PrettyFormat(char* format, char* buf, int maxlen)
+//
+//  Formats the contents of the marc record according to a format string.
+//  Useful for generating a buffer to pretty-print the record.
+//  format contains a format-specifier string.  The format-specifier string
+//  is kindof like printf's, except the only control character is '%'.
+//  Following the '%' should be the integer MARC field code as defined in 
+//  the (huge) list of available MARC fields from the library of congress
+//  (http://lcweb.loc.gov/marc/).  buf is a previously allocated 
+// buffer into which the pretty version will be copied.  maxlen is the max 
+// length to write into buf.  After call, buf contains pretty formatted text.
+//----------------------------------------------------------------------
+int MarcRecord::PrettyFormat(char* format, char* buf, int maxlen)
+{
+	char b[1024];
+	int bufpos = 0, fmtpos = 0;
+	
+	b[0] = '\0';
+	buf[0] = '\0';
+	
+	for (; format[fmtpos] != '\0'; )
+	{
+		switch (format[fmtpos])
+		{
+			case '%': 
+				{
+					char tag[4];
+					strncpy(tag, (char *)(format + fmtpos + 1), 3);
+					tag[3] = '\0';
+					GetSubField(tag, format[fmtpos + 4], b,	sizeof(b) - 1);
+					if (*b)
+					{
+						int l = strlen(b);
+						strncat(buf, b, maxlen - bufpos - 1);
+						bufpos += l;
+						if (bufpos >= maxlen)
+						{
+							buf[maxlen - 1] = '\0';
+							return maxlen;
+						}
+					}
+					fmtpos += 5;
+					break;
+				}
+			default:
+				buf[bufpos] = format[fmtpos];
+				bufpos++;
+				fmtpos++;
+				buf[bufpos] = '\0';
+				break;
+		}
+	}
+	return bufpos;
+}
+
+//----------------------------------------------------------------------
+// int MarcRecord::GetField(char* tag, char* buf, int maxlen)
+//
+// append all subfields in a field together. 
+//----------------------------------------------------------------------
+int MarcRecord::GetField(char* tag, char* buf, int maxlen)
+{
+	int remain = maxlen - 1;
+	
+	buf[0] = '\0';
+	
+	if ((tag == NULL) || (*tag == '\0'))
+		return 0;
+	
+	for (std::vector<MarcDirectoryEntry>::size_type i=0; i!=directory_.size(); ++i)
+	{
+		if (!strncmp(tag, directory_[i].tag_, strlen(tag)))
+		{
+			for (std::vector<MarcField>::size_type j=0; j!=directory_[i].field_.size(); ++j)
+			{
+				int flen = directory_[i].field_[j].len_;
+				if (flen > remain)
+				{
+					strncat(buf, directory_[i].field_[j].data_ + 1, remain);
+					buf[maxlen] = '\0';
+					return 1;
+				}
+				else 
+				{
+					strncat(buf, directory_[i].field_[j].data_ + 1, flen);
+					remain -= flen;
+				}
+			}
+			return 1;
+		}
+	}
+	return 0;
+}
+
+//----------------------------------------------------------------------
+// int MarcRecord::GetSubFields(char* tag, char subtag, char* buf, int maxlen)
+//
+// append all fields with a certain subfield together.
+//----------------------------------------------------------------------
+int MarcRecord::GetSubFields(char* tag, char subtag, char* buf, int maxlen)
+{
+	int remain = maxlen - 1;
+	
+	buf[0] = '\0';
+	
+	if ((tag == NULL) || (*tag == '\0'))
+		return 0;
+	
+	for (std::vector<MarcDirectoryEntry>::size_type i=0; i!=directory_.size(); ++i)
+	{
+		if (!strncmp(tag, directory_[i].tag_, strlen(tag)))
+		{
+			for (std::vector<MarcField>::size_type j=0; j!=directory_[i].field_.size(); ++j)
+			{
+				if (*(directory_[i].field_[j].data_) == subtag)
+				{
+					int flen = directory_[i].field_[j].len_;
+					if (flen > remain)
+					{
+						strncpy(buf, directory_[i].field_[j].data_ + 1, remain);
+						buf[maxlen] = '\0';
+						return 1;
+					}
+					else 
+					{
+						strcpy(buf, directory_[i].field_[j].data_ + 1);
+						remain -= flen;
+					}
+				}
+			}
+		}
+	}
+	return 0;
+}
+
+int MarcRecord::HasField(char* tag)
+{
+	
+	for (std::vector<MarcDirectoryEntry>::size_type i=0; i!=directory_.size(); ++i)
+		if (!strncmp(tag, directory_[i].tag_, strlen(tag)))
+			return 1;
+		
+		return 0;
+}
+
+int MarcRecord::HasSubField(char* tag, char subtag)
+{
+	
+	for (std::vector<MarcDirectoryEntry>::size_type i=0; i!=directory_.size(); ++i)
+		if (!strncmp(tag, directory_[i].tag_, strlen(tag)))
+			for (std::vector<MarcField>::size_type j=0; j!=directory_[i].field_.size(); ++j)
+				if (*directory_[i].field_[j].data_ == subtag)
+					return 1;
+				return 0;
+}
+
+int MarcRecord::GetSubField(char *tag, char subtag, char *buf, 	int maxlen)
+{
+	
+	buf[0] = '\0';
+	
+	if ((tag == NULL) || (*tag == '\0'))
+		return 0;
+	
+	for (std::vector<MarcDirectoryEntry>::size_type i=0; i!=directory_.size(); ++i)
+	{
+		if (!strncmp(tag, directory_[i].tag_, strlen(tag)))
+		{
+			for (std::vector<MarcField>::size_type j=0; j!=directory_[i].field_.size(); ++j)
+			{
+				if (*(directory_[i].field_[j].data_) == subtag)
+				{
+					int l = directory_[i].field_[j].len_ - 1 > maxlen ? maxlen : directory_[i].field_[j].len_ - 1;
+					strncpy(buf, directory_[i].field_[j].data_ + 1, l);
+					buf[l] = '\0';
+					return 1;
+				}
+			}
+		}
+	}
+	return 0;
+}
+
+
+int GetNum(char *s, int n)
+{
+	char nbuf[10]; /* no more than 9 digits */
+	
+	strncpy(&nbuf[0], s, n);
+	nbuf[n] = '\0';
+	return (atoi(nbuf));
+}
+
+void MarcRecord::Dump()
+{
+	int dc = 0, fc = 0;
+	
+	printf("tags: ");
+	for (std::vector<MarcDirectoryEntry>::size_type i=0; i!=directory_.size(); ++i)
+	{
+		Printx(stdout, directory_[i].tag_, 3);
+		dc++;
+		for (std::vector<MarcField>::size_type j=0; j!=directory_[i].field_.size(); ++j)
+		{
+			if (directory_[i].field_[j].data_)
+			{
+				putchar((unsigned long)directory_[i].field_[j].data_);
+			}
+			fc++;
+			/*
+			printx(stdout, (char*)f->data + 1, f->len);
+			printf("\n"); */
+		}
+		printf(",");
+	}
+	putchar('\n');
+}
+
+
+
+
+
+void MarcRecord::PrintDetailed(FILE *fp)
+{
+	int count, i;
+	
+	fprintf(fp, "RecordLength:\t\t%i\n", GetNum(leader_.lreclen_, 5));
+	fprintf(fp, "RecordStatus:\t\t%c\n", leader_.status_);
+	fprintf(fp, "RecordType:\t\t%c\n", leader_.type_);
+	fprintf(fp, "BibLevel:\t\t%c\n", leader_.bibLevel_);
+	fprintf(fp, "ControlType:\t\t%c\n", leader_.ctrlType_);
+	fprintf(fp, "UndefCharPos:\t\t%c\n", leader_.undPos_);
+	fprintf(fp, "IndCount:\t\t%i\n", GetNum(&leader_.indCount_, 1));
+	fprintf(fp, "SubCodeCount:\t\t%i\n", GetNum(&leader_.scd_, 1));
+	fprintf(fp, "DataBaseAddr:\t\t%i\n", GetNum(leader_.base_, 5));
+	fprintf(fp, "EncodingLevel:\t\t%c\n", leader_.encLevel_);
+	fprintf(fp, "DescCatForm:\t\t%c\n", leader_.dcf_);
+	fprintf(fp, "LinkedRecReq:\t\t%c\n", leader_.lrr_);
+	fprintf(fp, "LengthOf LengthOfField:\t%i\n", GetNum(&leader_.llof_, 1));
+	fprintf(fp, "LengthOf StartCharPos:\t%i\n", GetNum(&leader_.lscp_, 1));
+	fprintf(fp, "LengthOf ImpDefined:\t%i\n", GetNum(&leader_.lidp_, 1));
+	fprintf(fp, "UndefinedEntry:\t\t%i\n", GetNum(&leader_.uep_, 1));
+	
+	count = (GetNum(leader_.base_, 5) - MARC_LEADER_LEN) / MARC_DIRENT_LEN;
+	for (i = 0; i < count; i++)
+	{
+		DirectoryEntry dir = *(DirectoryEntry*)(data_+MARC_LEADER_LEN+(i*MARC_DIRENT_LEN));
+		fprintf(fp, "\n");
+		fprintf(fp, "Tag:\t\t");
+		Printx(fp, dir.tag_, 3);
+		fprintf(fp, "\nLength:\t\t%i\n", GetNum(dir.len_, 4));
+		fprintf(fp, "StartPos:\t%i\n", GetNum(dir.scp_, 5));
+		fprintf(fp, "Data:\t\t");
+		Printx(fp, (char *)(data_ + GetNum(leader_.base_, 5) + GetNum(dir.scp_, 5)), GetNum(dir.len_, 4));
+		fprintf(fp, "\n");
+	}
+}
+
+/*
+desc:		parses the marc record and builds appropriate data structures in m
+
+params:
+
+	m		newly created marcRecord
+	
+returns:
+
+	1 on success
+	0 on parse or memory failure
+*/
+int MarcRecord::ParseMarcRecord()
+{
+	dirCount_ = (GetNum(leader_.base_, 5) - MARC_LEADER_LEN) / MARC_DIRENT_LEN;
+	
+	// For each MarcDirectory entry, create list of subfields
+	MarcDirectoryEntry dir_entry;
+	for (int i = 0; i < dirCount_; i++)
+	{
+		char*  data;
+		// Extract the directory component
+		DirectoryEntry dir_entry = *(DirectoryEntry*)(data_+MARC_LEADER_LEN+(i*MARC_DIRENT_LEN));
+
+		MarcDirectoryEntry marc_dir_entry;
+		
+		// Get a pointer to the data for this MarcDirectory
+		data = (char *)(data_ + GetNum(leader_.base_, 5) + GetNum(dir_entry.scp_, 5));
+		
+		// set the tag for this MarcDirectory 
+		marc_dir_entry.tag_ = dir_entry.tag_;
+		
+		/* add the list of subfields for this MarcDirectory */
+		if (!AddSubFields(marc_dir_entry, data))
+			return 0;
+		directory_.push_back(marc_dir_entry);
+		
+	}
+	
+	return 1;
+}
+
+void Printx(FILE* fp, char* s, int x)
+{
+	int i;
+	for (i = 0; i < x; i++)
+		fprintf(fp, "%c", s[i]);
+}
+
+//----------------------------------------------------------------------
+// int MarcRecord::AddSubFields(MarcDirectory& d, char* b)
+//
+// Parses and adds subfields to MarcDirectory
+//
+// params:
+//
+//	d		MarcDirectory to which subfields are added
+//	b		buffer of data for d
+//
+// returns:
+//
+//	1 on success
+//	0 on parse or memory error
+//----------------------------------------------------------------------
+int MarcRecord::AddSubFields(MarcDirectoryEntry& d, char* b)
+{
+	char *p, *start;
+	int cont = 1, length = 0;
+	
+	/* create new field */
+	MarcField field;
+	
+	
+	start = b;
+	for (p = b; ((*p != '\0') && (cont == 1)); p = (char *)p + 1)
+	{
+		switch (*p)
+		{
+			case SUBFDELIM:
+				/* end of current subfield, but more exist */
+				
+				/* set length and pointer to data for this field */
+				field.len_  = length;
+				field.data_ = start;
+				d.field_.push_back(field);
+				/* by definition, there should be more subfields, but we'll
+				check for NULL just in case
+				*/
+				if (*p + 1)
+				{
+				}
+				else 
+				{
+					/* uh oh */
+					return 0;
+				}
+				length = 0;
+				start = (char *)p + 1;
+				break;
+			case FIELDTERM:
+				/* end of subfield list */
+				
+				/* set length and pointer to data for this field */
+				field.len_  = length;
+				field.data_ = start;
+				d.field_.push_back(field);
+				
+				/* break out of loop */
+				cont = 0;
+				break;
+			case RECTERM:
+				/* end of record */
+				cont = 0;
+				break;
+			default:
+				/* regular character */			
+				length++;
+				break;
+		}
+	}
+	return 1;
+}
+
+void MarcRecord::Format(char *buf, int maxlen, int format)
+{
+	char b[1024];
+	char date[24];
+	char title[128];
+	
+	b[0] = '\0';
+	buf[0] = '\0';
+	
+	/* FIXME: get rid of this debugging crap sometime */
+	Dump();
+	
+	switch (format)
+	{
+		case MARC_FMT_BRIEF: 
+			{
+				GetSubField("245", 'a', title, 	sizeof(title) - 1);
+				GetSubField("260", 'c', date, sizeof(date) - 1);
+				if ((strlen(date) + strlen(title) + 2) <=(size_t)maxlen)
+				{
+					sprintf(buf, "%s %s", date, title);
+				}
+				else 
+				{
+					/* FIXME: we're overflowing the buffer! */
+				}
+				break;
+			}
+		case MARC_FMT_FULL: 
+			{
+				int dc = 0, fc = 0;
+				int remain = maxlen;
+				
+	            for (std::vector<MarcDirectoryEntry>::size_type i=0; i!=directory_.size(); ++i)
+				{
+					dc++;
+		            for (std::vector<MarcField>::size_type j=0; j!=directory_[i].field_.size(); ++j)
+					{
+						fc++;
+						if ((directory_[i].field_[j].len_ + 2) > remain)
+						{
+							strncat(buf, (char *)directory_[i].field_[j].data_ + 1, remain - 2);
+							* (buf + remain - 2) = '\n';
+							* (buf + remain - 1) = '\0';
+							/* we're out of room in the buffer. */
+							return;
+						}
+						if (directory_[i].field_[j].len_ > 0)
+						{
+							strncat(buf, (char*)directory_[i].field_[j].data_ + 1, directory_[i].field_[j].len_);
+							strncat(buf, "\n\0", 2);
+							remain -=(directory_[i].field_[j].len_ + 2);
+						}
+					} 
+				}
+				/*
+				marcRecord_getSubField(m, "245", 'a', title, 
+				sizeof(title) - 1);
+				marcRecord_getSubField(m, "245", 'a', title, 
+				sizeof(title) - 1);
+				marcRecord_getSubField(m, "260", 'c', date, 
+				sizeof(date) - 1);
+				sprintf(buf, "%s %s", date, title);
+				*/
+				break;
+			}
+		default:
+			break;
+	}
+}
+
+int MarcRecord::RecordLength()
+{
+	register int l = 0;
+	
+	
+	for (std::vector<MarcDirectoryEntry>::size_type i=0; i!=directory_.size(); ++i)
+		for (std::vector<MarcField>::size_type j=0; j!=directory_[i].field_.size(); ++j)
+			l += directory_[i].field_[i].len_;
+		
+        return l;
+}
+
Index: /gsdl/trunk/build-src/packages/isis-gdl/Unimarc.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/Unimarc.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/Unimarc.h	(revision 16571)
@@ -0,0 +1,175 @@
+/**********************************************************************
+ *
+ * Unimarc.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef MARC_RECORD
+#define MARC_RECORD
+
+#define SUBFDELIM '\037'   // %
+#define FIELDTERM '\036'   // $
+#define RECTERM   '\035'   // # sharp
+
+#define MARC_LEADER_LEN 24
+#define MARC_DIRENT_LEN 12
+
+#define MARC_FMT_BRIEF 0
+#define MARC_FMT_FULL 1
+
+//---------------------
+// UNIMARC Record Label
+//---------------------
+struct  MarcLeader
+{
+	char	lreclen_[5];	/* logical record length */
+	char	status_;		/* record status_ */
+	char	type_;			/* type_ of record */
+	char	bibLevel_;	    /* bibliographic level */
+	char	ctrlType_;	    /* type_ of control */
+	char	undPos_;		/* undefined character position */
+	char	indCount_;	    /* indicator count */
+	char	scd_;			/* subfield code count */
+	char	base_[5];		/* base_ address of data */
+	char	encLevel_;	    /* encoding level */
+	char	dcf_;			/* descriptive cataloging form */
+	char	lrr_;			/* linked record requirement */
+	char	llof_;			/* length of the length-of-field portion */
+	char	lscp_;			/* length of starting-character-position portion */
+	char	lidp_;			/* length of implementation-defined portion */
+	char	uep_;			/* undefined entry map character position */
+
+	MarcLeader()
+	{
+		lreclen_[0]=' ';
+		lreclen_[1]=' ';
+		lreclen_[2]=' ';
+		lreclen_[3]=' ';
+		lreclen_[4]=' ';
+		status_   = '0';     // New record
+        type_     = '0';     // Language materials, printed
+	    bibLevel_ = '0';	     // Monographic
+	    ctrlType_ = '0';     // Hierarchical relationship undefined
+	    undPos_   = '0';     // Undefined, contains a blank
+	    indCount_ = '0';     // Invariably 2 in UNIMARC
+	    scd_      = '0';     // Invariably 2 in UNIMARC
+	    base_[0]  = ' ';     // Base_ address of data
+		base_[1]  = ' ';
+		base_[2]  = ' ';
+		base_[3]  = ' ';
+		base_[4]  = ' ';
+	    encLevel_ = '0';     // (Blank) full level
+	    dcf_      = '0';     // (Blank) record is in full ISBD form
+	    lrr_      = '0';     // Undefined, contains a blank
+	    llof_     = '4';     // Length of the length-of-field portion
+	    lscp_     = '5';     // Length of starting-character-position portion 
+	    lidp_     = '0';     // Length of implementation-defined portion
+	    uep_      = '0';     // Undefined, contains a blank
+	}
+
+   friend std::ostream& operator<<(std::ostream& s, const MarcLeader& leader);
+   friend std::istream& operator>>(std::istream& s, MarcLeader& leader);
+};
+
+//----------------
+// Directory entry
+//----------------
+struct DirectoryEntry
+{
+	char	tag_[3];		/* tag */
+	char	len_[4];		/* field length */
+	char	scp_[5];		/* starting character position */
+   friend std::ostream& operator<<(std::ostream& s, const DirectoryEntry& de);
+   friend std::istream& operator>>(std::istream& s, DirectoryEntry& leader);
+};
+inline std::istream& operator>>(std::istream& s, DirectoryEntry& de)
+{
+	s.read(de.tag_, 3);
+	s.read(de.len_, 4);
+	s.read(de.scp_, 5);
+	return s;
+}
+inline std::ostream& operator<<(std::ostream& s, const DirectoryEntry& de)
+{
+	s.write(de.tag_, 3);
+	s.write(de.len_, 4);
+	s.write(de.scp_, 5);
+	return s;
+}
+
+
+
+//------------------
+// Subfield item 
+//------------------
+struct MarcField
+{
+	int			len_;
+	char*       data_;
+};
+
+//-------------------
+// Directory entry
+//-------------------
+struct MarcDirectoryEntry
+{
+	char*                  tag_;
+	std::vector<MarcField> field_;
+};
+
+
+//---------------------------
+// UNIMARC record structure 
+//---------------------------
+
+class MarcRecord
+{
+protected:
+	MarcLeader      leader_;
+	char*           data_;
+	int			    length_;
+	int				dirCount_;
+	int				encapsulated_;
+	std::vector<MarcDirectoryEntry>   directory_;
+	
+    int ParseMarcRecord();
+    int AddSubFields(MarcDirectoryEntry& d, char* b);
+public:
+    MarcRecord(char* data, int length, int copyData);
+    ~MarcRecord();
+    void PrintDetailed(FILE* fp);
+    void Get(char* buf,int maxlen,int format);
+    int  GetSubField(char* tag, char subtag, char* buf, int maxlen);
+    int  GetField(char* tag, char* buf, int maxlen);
+    int  GetSubFields(char* tag, char subtag, char* buf, int maxlen);
+
+    int  HasField(char* tag);
+    int  HasSubField(char* tag, char subtag);
+
+    void Format(char* buf, int maxlen, int format);
+    int  RecordLength();
+    int  PrettyFormat(char* format, char* buf, int maxlen);
+
+    void Dump ();
+};
+#endif
Index: /gsdl/trunk/build-src/packages/isis-gdl/XRFFile.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/XRFFile.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/XRFFile.cpp	(revision 16571)
@@ -0,0 +1,305 @@
+/**********************************************************************
+ *
+ * XRFFile.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////
+// XrfFile.cpp: XrfFile object methods
+//
+////////////////////////////////////////////////////////////
+#include "stdafx.h"
+#include "XRFFile.h"
+
+
+
+//-----------------------------------------------------------------------------------
+// IsisError  XrfFile::OpenXrf(const _TCHAR *fname, FileSystem::AccessMode mode
+//				                              /* = FileSystem::FILE_READWRITE */)
+//
+// Open xrf_ file with file name fname 
+//-----------------------------------------------------------------------------------
+IsisError  XrfFile::OpenXrf(const _TCHAR *fname, FileSystem::AccessMode mode
+				                              /* = FileSystem::FILE_READWRITE */)
+{
+  TCHAR xrfFileName[_MAX_PATH];
+  _tcscpy(xrfFileName, fname);
+
+  if (!CFileBase::Exists(xrfFileName)) {
+    xrfFileName[strlen(xrfFileName) - 3] = 'X';
+    xrfFileName[strlen(xrfFileName) - 2] = 'R';
+    xrfFileName[strlen(xrfFileName) - 1] = 'F';
+  }
+
+    IsisError isis_error;
+    xrfa_->xrfpos_ = -1;   // No block into buffer
+	try {
+        FileError rc = CFileBase::Open(xrfFileName, mode);
+	}
+	catch(CFileBaseException)
+	{
+		isis_error = ISIS_XRF_OPEN_ERROR;
+        throw CIsisDbException(isis_error, __FILE__, __LINE__); 
+	}
+  	long file_size   = CFileBase::FileSize(file_name);
+	
+	last_block_  = file_size/XRFBLKSIZE;
+
+	if (last_block_<1 || last_block_*XRFBLKSIZE != file_size)
+	{
+		isis_error =  ISIS_XRF_CORRUPT;
+        throw CIsisDbException(isis_error, __FILE__, __LINE__); 
+	}
+
+	return ISIS_NO_ERROR;
+}
+ 
+//////////////////////////////
+ 
+ 
+IsisError  XrfFile::CreateXrf(const _TCHAR *fname)
+// Creates an xrf_ file
+{
+    IsisError isis_error;
+	try 
+	{
+        FileError rc = CFileBase::Create(fname);
+    	// Initialize an empty block and write-it
+		xrfa_->Init();
+        xrfa_->xrfpos_ = 1; // Block number
+		xrfa_->xrfeof_ = 1; // Last xrf_ block
+        last_block_    = 1;		
+        WriteXrf(1L);
+	}
+	catch(CFileBaseException)
+	{
+		isis_error = ISIS_XRF_CREATE_ERROR;
+        throw CIsisDbException(isis_error, __FILE__, __LINE__);
+	}
+	
+    return ISIS_NO_ERROR;
+}
+//-----------------------------------------------------------------------------------
+// IsisError  XrfFile::CreateXrf(const _TCHAR *fname, long nextMfn)
+//
+// Special xrf_ file creation for building xrf_ blocks of an existing mst
+//-----------------------------------------------------------------------------------
+IsisError  XrfFile::CreateXrf(const _TCHAR *fname, long nextMfn)
+// Creates an xrf_ file
+{
+    IsisError isis_error;
+    long nBlocks = (nextMfn-1)/MAXTIV + 1;       // Number of blocks to allocate
+	try 
+	{
+        FileError rc = CFileBase::Create(fname);
+		xrfa_->Init();
+    	// Initialize an empty block and write-it
+		for (int iBlock=1; iBlock<= nBlocks; iBlock++)
+		{
+			TRACE("\niBlock=%d", iBlock);
+			xrfa_->xrfpos_ = iBlock;
+			xrfa_->xrfeof_ = 0;
+			if (iBlock == nBlocks)
+			    xrfa_->xrfeof_ = 1;
+
+			WriteXrf(iBlock);
+		}
+	}
+	catch(CFileBaseException)
+	{
+		isis_error = ISIS_XRF_CREATE_ERROR;
+        throw CIsisDbException(isis_error, __FILE__, __LINE__);
+	}
+
+    last_block_ = nBlocks;	
+    return ISIS_NO_ERROR;
+}
+
+//------------------------------------------------------------------------------
+// void XrfFile::UnPack(void)
+//
+// Unpack addresses of master file records. The current packed XRF block 
+// contained in xrf_ structure will be unpacked in xrfa_ structure.
+//
+//  A master file address is packed as follow: addr = mfb*2048 + mfp
+//
+//  2048 = 2**11 e.g. mfp->[0:2047] and block number -> [1: 2**20]
+//  2**20 = 1 048 576
+//
+// As we can put 127 addresses per block, then the limit on number of records
+// is 127 * 1 048 576
+//------------------------------------------------------------------------------
+void XrfFile::UnPack(void)
+{
+   fix_endianness(xrf_->xrfpos_);
+
+   xrfa_->xrfpos_ = xrf_->xrfpos_;
+   if (xrfa_->xrfpos_ < 0)
+   {
+      xrfa_->xrfpos_ = - xrf_->xrfpos_;
+      xrfa_->xrfeof_ = 1;
+   }
+   else
+      xrfa_->xrfeof_ = 0;
+ 
+   for (int i=0; i<MAXTIV; i++)
+   {
+      long j = xrf_->xrftiv_[i];             // Packed value
+      fix_endianness(j);
+      bool b = (j < 0);
+      if (b)
+         j = - j;
+      xrfa_->xrftiv_[i].xrfmfb_ = int(j / 2048L);   // Unpack block number
+      if (b)
+         xrfa_->xrftiv_[i].xrfmfb_ = -xrfa_->xrftiv_[i].xrfmfb_;
+      xrfa_->xrftiv_[i].xrfmfp_ = int(j % 2048L);   // Unpack offset
+   }
+}
+ 
+//------------------------------------------------------------------------------
+// void XrfFile::Pack(void)
+//
+// Pack addresses of master file records. The current unpacked XRF block 
+// contained in xrfa_ will be packed in xrf_ structure.
+//------------------------------------------------------------------------------
+void XrfFile::Pack(void)
+{
+   long j = xrfa_->xrfpos_;
+   if (xrfa_->xrfeof_ != 0)
+      j = -j;
+   xrf_->xrfpos_ = j;
+
+ 
+   for (int i=0; i<MAXTIV; i++)
+   {
+      j = xrfa_->xrftiv_[i].xrfmfb_;    // Unpacked block number
+      int b = (j < 0);
+      if (b)
+         j = - j;
+      //-------------------------------------------
+      // pack block number and offset in a long int
+      //-------------------------------------------
+      j = j * 2048 + xrfa_->xrftiv_[i].xrfmfp_;
+      if (b) j = -j;
+      xrf_->xrftiv_[i] = j;     // Put value in xrf_
+   }
+}
+ 
+//------------------------------------------------------------------------------
+// int XrfFile::GetMfp(long mfn, long& mfb, int& mfp)
+//
+// Gets the address of master file data record with MFN "mfn" by accessing the 
+// xrf_ file). mfb is the master file block number [1:NBLK] and mfp is the offset
+// in the master file block where the record starts [0:BLKSIZE-1]
+//
+//  Returns   Active              = Record active
+//            LogicalyDeleted     = Record logically deleted
+//            PhysicalyDeleted    = Record physically deleted
+//            EndOfFile
+//  Note: mfp can be >=      than BLKSIZE if the inverted file
+//  wasn't updated, then true mfp is mfp%BLKSIZE
+//------------------------------------------------------------------------------
+int XrfFile::GetMfp(long mfn, long& mfb, int& mfp)
+{
+	PRECONDITION(mfn>0);
+	PRECONDITION(last_block_>0);
+    int  comp;
+    long comb;
+    int  rc;
+	
+    long psxrf=(mfn-1)/MAXTIV+1;       // Block number
+	if (psxrf > last_block_)
+	{
+        rc = EndOfFile;                // Inexistent record (eof)
+		return rc;
+		throw CIsisDbException(ISIS_XRF_INVALID_BLOCK, __FILE__, __LINE__);
+	}
+    if (psxrf != xrfa_->xrfpos_) 
+	{                                  // If current block in xrf_ different
+		try
+		{
+            ReadXrf(psxrf);            // then read the block
+		}
+		catch (CFileBaseException e)
+		{
+            throw CIsisDbException(ISIS_XRF_READ_ERROR, __FILE__, __LINE__);
+		}
+
+    }
+    int i = int((mfn-1) % MAXTIV);     // Index
+    comb = xrfa_->xrftiv_[i].xrfmfb_;     // Master file block #
+    comp = xrfa_->xrftiv_[i].xrfmfp_;     // Offset in block
+
+	if (comb > 0)
+        rc = Active;                   // Record active 
+    else if (comb < 0 && comp > 0)
+        rc = LogicalyDeleted;          // Record logicaly deleted 
+	else if (comb == -1 && comp == 0)
+        rc = PhysicalyDeleted;         // Record physically deleted 
+    else if (comb == 0 && comp == 0)
+        rc = EndOfFile;                // Inexistent record (eof)
+	else
+	{
+        throw CIsisDbException(ISIS_XRF_INVALID_STATUS, __FILE__, __LINE__); 
+	}
+    mfb = labs(comb);
+    mfp = comp;
+	if (rc == Active)
+	{
+	    ASSERT(mfb>0 && mfb <= MAXMFB);
+		ASSERT(mfp>=0 && mfp < 2048);
+	    int mfpTemp = mfp%XRFBLKSIZE;
+	    ASSERT(mfpTemp>=0 && mfpTemp<XRFBLKSIZE);
+	}
+    return(rc);
+}
+ 
+void XrfFile::Grow(long from_lastb, long to_lastb)
+{
+	for (long i=from_lastb+1; i<=to_lastb; i++)
+	{
+        //--------------------
+        // append empty blocks
+        //--------------------
+ 		xrfa_->Init();
+		xrfa_->xrfpos_ = i;
+		xrfa_->xrfeof_ = (i==to_lastb) ? 1 : 0; // Eof flag
+	    try
+		{
+           WriteXrf(i);           // Write xrf_ at block address xrfb
+		}
+		catch (CFileBaseException)
+		{
+			throw(ISIS_XRF_WRITE_ERROR);
+		}
+	}
+}
+ 
+//------------------------------------------------------------------------------
+// void XrfFile::PutMfp(long mfn, long mfb, int mfp, int status)
+//
+// Puts the address of a master file record (mfb,mfp) as the address for MFN 
+// "mfn" in xrf_ file
+//------------------------------------------------------------------------------
+void XrfFile::PutMfp(long mfn, long mfb, int mfp, int status)
+{
+}
Index: /gsdl/trunk/build-src/packages/isis-gdl/XRFFile.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/XRFFile.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/XRFFile.h	(revision 16571)
@@ -0,0 +1,151 @@
+/**********************************************************************
+ *
+ * XRFFile.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+////////////////////////////////////////////////////////////
+// XRFFILE.H : Cross Ref File object
+//
+////////////////////////////////////////////////////////////
+ 
+#ifndef _XRFFILE_H_
+#define _XRFFILE_H_
+#ifndef _BLKFILE_H_
+#include "blkfile.h"
+#endif
+#include <assert.h>
+#include "IErrors.h"
+ 
+const int MAXTIV     =     127; //  # of XRF entries per block
+const int XRFBLKSIZE =     512; //
+const int MAXMFB     = 1048576; 
+
+ 
+ 
+/////////////////////////////////////////
+// Cross reference file data structures
+//
+ 
+ 
+struct MSTA_ENTRY                 // Unpacked MST address
+{             
+   long       xrfmfb_;             // Master file block
+   short int  xrfmfp_;             // Offset
+} ;
+ 
+struct XRFA                       // To strore unpacked addresses
+{                
+   long          xrfpos_;          // Block number on xrf_ file or -1 if empty
+   short int     xrfeof_;          // 1 if last block of xrf_ file
+   MSTA_ENTRY xrftiv_[MAXTIV];     // MAXTIV unpacked MST addresses
+
+   XRFA() { Init(); }
+
+   void Init()
+   {
+	   xrfeof_ = 0;              // Not eof
+	   xrfpos_ = -1;             // empty   
+	   for (int i=0; i<MAXTIV; i++)
+	   {
+		   xrftiv_[i].xrfmfb_  = -1;
+	       xrftiv_[i].xrfmfp_  = 0;
+	   }
+   }
+
+
+} ;
+ 
+struct XRF                       // To store packed addresses
+{                                // for reading and wrting
+   long xrfpos_;                  // block number on xrf_ file
+   long xrftiv_[MAXTIV];          // MAXTIV packed MST addresses 
+} ;
+ 
+///////////////////
+// XrfFile class
+//
+
+ 
+class XrfFile : public BlkFile 
+{
+private:
+   XRF*  xrf_;             // Buffer to store packed addresses
+   XRFA* xrfa_;            // Buffer to store unpacked addresses
+   long  last_block_;      // Should always contain the last allocated block
+   
+   void ReadXrf(long b);
+   void WriteXrf(long b);
+   void UnPack();
+   void Pack();
+   void Grow(long from_lastb, long to_lastb);
+public:
+   XrfFile();
+   IsisError OpenXrf(const _TCHAR *fname,
+	                 FileSystem::AccessMode mode = FileSystem::FILE_READWRITE);
+   IsisError CreateXrf(const _TCHAR *fname);
+   IsisError CreateXrf(const _TCHAR *fname, long nextMfn);
+  ~XrfFile();
+   int  GetMfp(long mfn, long& mfb, int& mfp);
+   void PutMfp(long mfn, long mfb, int mfp, int status);
+};
+ 
+//////////////////////////////
+ 
+inline XrfFile::XrfFile()  :
+// Makes a XrfFile object that isn't connected to a file
+   xrf_(new XRF),
+   xrfa_(new XRFA)
+{
+   last_block_ = -1;   // Not yet initialize
+   // Nothing more to do
+}
+ 
+//////////////////////////////
+ 
+ 
+inline XrfFile::~XrfFile()
+{
+   if (xrf_)  delete xrf_;
+   if (xrfa_) delete xrfa_;
+}
+ 
+//////////////////////////////
+ 
+inline void XrfFile::ReadXrf(long b)
+// Reads block # b into xrf_ buffer
+{
+	assert(b>0);
+    ReadBlk(xrf_, b);
+    UnPack();
+}
+ 
+//////////////////////////////
+ 
+inline void XrfFile::WriteXrf(long b)
+// Writes the content of xrf_ buffer as block number b
+{
+	assert(b>0);
+    Pack();
+    WriteBlk(xrf_, b);
+}
+#endif
Index: /gsdl/trunk/build-src/packages/isis-gdl/configure
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/configure	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/configure	(revision 16571)
@@ -0,0 +1,2828 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.59.
+#
+# Copyright (C) 2003 Free Software Foundation, Inc.
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+  set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+  LC_TELEPHONE LC_TIME
+do
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+    eval $as_var=C; export $as_var
+  else
+    $as_unset $as_var
+  fi
+done
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)$' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\/\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+
+
+# PATH needs CR, and LINENO needs CR and PATH.
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
+  # Find who we are.  Look in the path if we contain no path at all
+  # relative or not.
+  case $0 in
+    *[\\/]* ) as_myself=$0 ;;
+    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+
+       ;;
+  esac
+  # We did not find ourselves, most probably we were run as `sh COMMAND'
+  # in which case we are not to be found in the path.
+  if test "x$as_myself" = x; then
+    as_myself=$0
+  fi
+  if test ! -f "$as_myself"; then
+    { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2
+   { (exit 1); exit 1; }; }
+  fi
+  case $CONFIG_SHELL in
+  '')
+    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for as_base in sh bash ksh sh5; do
+	 case $as_dir in
+	 /*)
+	   if ("$as_dir/$as_base" -c '
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
+	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
+	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
+	     CONFIG_SHELL=$as_dir/$as_base
+	     export CONFIG_SHELL
+	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
+	   fi;;
+	 esac
+       done
+done
+;;
+  esac
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line before each line; the second 'sed' does the real
+  # work.  The second script uses 'N' to pair each line-number line
+  # with the numbered line, and appends trailing '-' during
+  # substitution so that $LINENO is not a special case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
+  sed '=' <$as_myself |
+    sed '
+      N
+      s,$,-,
+      : loop
+      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+      t loop
+      s,-$,,
+      s,^['$as_cr_digits']*\n,,
+    ' >$as_me.lineno &&
+  chmod +x $as_me.lineno ||
+    { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensible to this).
+  . ./$as_me.lineno
+  # Exit status is that of the last command.
+  exit
+}
+
+
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+  *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T='	' ;;
+  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+echo >conf$$.file
+if ln -s conf$$.file conf$$ 2>/dev/null; then
+  # We could just check for DJGPP; but this test a) works b) is more generic
+  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
+  if test -f conf$$.exe; then
+    # Don't use ln at all; we don't have any links
+    as_ln_s='cp -p'
+  else
+    as_ln_s='ln -s'
+  fi
+elif ln conf$$.file conf$$ 2>/dev/null; then
+  as_ln_s=ln
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.file
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p=:
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_executable_p="test -f"
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.
+as_nl='
+'
+IFS=" 	$as_nl"
+
+# CDPATH.
+$as_unset CDPATH
+
+
+# Name of the host.
+# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+exec 6>&1
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_config_libobj_dir=.
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+# Maximum number of lines to put in a shell here document.
+# This variable seems obsolete.  It should probably be removed, and
+# only ac_max_sed_lines should be used.
+: ${ac_max_here_lines=38}
+
+# Identity of this package.
+PACKAGE_NAME=
+PACKAGE_TARNAME=
+PACKAGE_VERSION=
+PACKAGE_STRING=
+PACKAGE_BUGREPORT=
+
+ac_default_prefix=../../..
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CXX CXXFLAGS LDFLAGS CPPFLAGS ac_ct_CXX EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LIBOBJS LTLIBOBJS'
+ac_subst_files=''
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datadir='${prefix}/share'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+libdir='${exec_prefix}/lib'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+infodir='${prefix}/info'
+mandir='${prefix}/man'
+
+ac_prev=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval "$ac_prev=\$ac_option"
+    ac_prev=
+    continue
+  fi
+
+  ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_option in
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+  | --da=*)
+    datadir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid feature name: $ac_feature" >&2
+   { (exit 1); exit 1; }; }
+    ac_feature=`echo $ac_feature | sed 's/-/_/g'`
+    eval "enable_$ac_feature=no" ;;
+
+  -enable-* | --enable-*)
+    ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid feature name: $ac_feature" >&2
+   { (exit 1); exit 1; }; }
+    ac_feature=`echo $ac_feature | sed 's/-/_/g'`
+    case $ac_option in
+      *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
+      *) ac_optarg=yes ;;
+    esac
+    eval "enable_$ac_feature='$ac_optarg'" ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst \
+  | --locals | --local | --loca | --loc | --lo)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+  | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid package name: $ac_package" >&2
+   { (exit 1); exit 1; }; }
+    ac_package=`echo $ac_package| sed 's/-/_/g'`
+    case $ac_option in
+      *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
+      *) ac_optarg=yes ;;
+    esac
+    eval "with_$ac_package='$ac_optarg'" ;;
+
+  -without-* | --without-*)
+    ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid package name: $ac_package" >&2
+   { (exit 1); exit 1; }; }
+    ac_package=`echo $ac_package | sed 's/-/_/g'`
+    eval "with_$ac_package=no" ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) { echo "$as_me: error: unrecognized option: $ac_option
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; }
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid variable name: $ac_envvar" >&2
+   { (exit 1); exit 1; }; }
+    ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
+    eval "$ac_envvar='$ac_optarg'"
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  { echo "$as_me: error: missing argument to $ac_option" >&2
+   { (exit 1); exit 1; }; }
+fi
+
+# Be sure to have absolute paths.
+for ac_var in exec_prefix prefix
+do
+  eval ac_val=$`echo $ac_var`
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* | NONE | '' ) ;;
+    *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# Be sure to have absolute paths.
+for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \
+	      localstatedir libdir includedir oldincludedir infodir mandir
+do
+  eval ac_val=$`echo $ac_var`
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* ) ;;
+    *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+    echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
+    If a cross compiler is detected then cross compile mode will be used." >&2
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then its parent.
+  ac_confdir=`(dirname "$0") 2>/dev/null ||
+$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$0" : 'X\(//\)[^/]' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$0" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r $srcdir/$ac_unique_file; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r $srcdir/$ac_unique_file; then
+  if test "$ac_srcdir_defaulted" = yes; then
+    { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2
+   { (exit 1); exit 1; }; }
+  else
+    { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
+   { (exit 1); exit 1; }; }
+  fi
+fi
+(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null ||
+  { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2
+   { (exit 1); exit 1; }; }
+srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'`
+ac_env_build_alias_set=${build_alias+set}
+ac_env_build_alias_value=$build_alias
+ac_cv_env_build_alias_set=${build_alias+set}
+ac_cv_env_build_alias_value=$build_alias
+ac_env_host_alias_set=${host_alias+set}
+ac_env_host_alias_value=$host_alias
+ac_cv_env_host_alias_set=${host_alias+set}
+ac_cv_env_host_alias_value=$host_alias
+ac_env_target_alias_set=${target_alias+set}
+ac_env_target_alias_value=$target_alias
+ac_cv_env_target_alias_set=${target_alias+set}
+ac_cv_env_target_alias_value=$target_alias
+ac_env_CXX_set=${CXX+set}
+ac_env_CXX_value=$CXX
+ac_cv_env_CXX_set=${CXX+set}
+ac_cv_env_CXX_value=$CXX
+ac_env_CXXFLAGS_set=${CXXFLAGS+set}
+ac_env_CXXFLAGS_value=$CXXFLAGS
+ac_cv_env_CXXFLAGS_set=${CXXFLAGS+set}
+ac_cv_env_CXXFLAGS_value=$CXXFLAGS
+ac_env_LDFLAGS_set=${LDFLAGS+set}
+ac_env_LDFLAGS_value=$LDFLAGS
+ac_cv_env_LDFLAGS_set=${LDFLAGS+set}
+ac_cv_env_LDFLAGS_value=$LDFLAGS
+ac_env_CPPFLAGS_set=${CPPFLAGS+set}
+ac_env_CPPFLAGS_value=$CPPFLAGS
+ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set}
+ac_cv_env_CPPFLAGS_value=$CPPFLAGS
+
+#
+# Report the --help message.
+#
+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 this package to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+_ACEOF
+
+  cat <<_ACEOF
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+			  [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+			  [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR           user executables [EPREFIX/bin]
+  --sbindir=DIR          system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR       program executables [EPREFIX/libexec]
+  --datadir=DIR          read-only architecture-independent data [PREFIX/share]
+  --sysconfdir=DIR       read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR   modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR    modifiable single-machine data [PREFIX/var]
+  --libdir=DIR           object code libraries [EPREFIX/lib]
+  --includedir=DIR       C header files [PREFIX/include]
+  --oldincludedir=DIR    C header files for non-gcc [/usr/include]
+  --infodir=DIR          info documentation [PREFIX/info]
+  --mandir=DIR           man documentation [PREFIX/man]
+_ACEOF
+
+  cat <<\_ACEOF
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+
+  cat <<\_ACEOF
+
+Some influential environment variables:
+  CXX         C++ compiler command
+  CXXFLAGS    C++ compiler flags
+  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+              nonstandard directory <lib dir>
+  CPPFLAGS    C/C++ preprocessor flags, e.g. -I<include dir> if you have
+              headers in a nonstandard directory <include dir>
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+_ACEOF
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  ac_popdir=`pwd`
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d $ac_dir || continue
+    ac_builddir=.
+
+if test "$ac_dir" != .; then
+  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  # A "../" for each directory in $ac_dir_suffix.
+  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+  ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+  .)  # No --srcdir option.  We are building in place.
+    ac_srcdir=.
+    if test -z "$ac_top_builddir"; then
+       ac_top_srcdir=.
+    else
+       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+    fi ;;
+  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir ;;
+  *) # Relative path.
+    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
+
+    cd $ac_dir
+    # Check for guested configure; otherwise get Cygnus style configure.
+    if test -f $ac_srcdir/configure.gnu; then
+      echo
+      $SHELL $ac_srcdir/configure.gnu  --help=recursive
+    elif test -f $ac_srcdir/configure; then
+      echo
+      $SHELL $ac_srcdir/configure  --help=recursive
+    elif test -f $ac_srcdir/configure.ac ||
+	   test -f $ac_srcdir/configure.in; then
+      echo
+      $ac_configure --help
+    else
+      echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi
+    cd $ac_popdir
+  done
+fi
+
+test -n "$ac_init_help" && exit 0
+if $ac_init_version; then
+  cat <<\_ACEOF
+
+Copyright (C) 2003 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit 0
+fi
+exec 5>config.log
+cat >&5 <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by $as_me, which was
+generated by GNU Autoconf 2.59.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+hostinfo               = `(hostinfo) 2>/dev/null               || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  echo "PATH: $as_dir"
+done
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_sep=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+      ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;;
+    2)
+      ac_configure_args1="$ac_configure_args1 '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+	ac_must_keep_next=false # Got value, back to normal.
+      else
+	case $ac_arg in
+	  *=* | --config-cache | -C | -disable-* | --disable-* \
+	  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+	  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+	  | -with-* | --with-* | -without-* | --without-* | --x)
+	    case "$ac_configure_args0 " in
+	      "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+	    esac
+	    ;;
+	  -* ) ac_must_keep_next=true ;;
+	esac
+      fi
+      ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'"
+      # Get rid of the leading space.
+      ac_sep=" "
+      ;;
+    esac
+  done
+done
+$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; }
+$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; }
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Be sure not to use single quotes in there, as some shells,
+# such as our DU 5.0 friend, will then `close' the trap.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    cat <<\_ASBOX
+## ---------------- ##
+## Cache variables. ##
+## ---------------- ##
+_ASBOX
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+{
+  (set) 2>&1 |
+    case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in
+    *ac_space=\ *)
+      sed -n \
+	"s/'"'"'/'"'"'\\\\'"'"''"'"'/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p"
+      ;;
+    *)
+      sed -n \
+	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+      ;;
+    esac;
+}
+    echo
+
+    cat <<\_ASBOX
+## ----------------- ##
+## Output variables. ##
+## ----------------- ##
+_ASBOX
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=$`echo $ac_var`
+      echo "$ac_var='"'"'$ac_val'"'"'"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      cat <<\_ASBOX
+## ------------- ##
+## Output files. ##
+## ------------- ##
+_ASBOX
+      echo
+      for ac_var in $ac_subst_files
+      do
+	eval ac_val=$`echo $ac_var`
+	echo "$ac_var='"'"'$ac_val'"'"'"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      cat <<\_ASBOX
+## ----------- ##
+## confdefs.h. ##
+## ----------- ##
+_ASBOX
+      echo
+      sed "/^$/d" confdefs.h | sort
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      echo "$as_me: caught signal $ac_signal"
+    echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core &&
+  rm -rf conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+     ' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -rf conftest* confdefs.h
+# AIX cpp loses on an empty file, so make sure it contains at least a newline.
+echo >confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer explicitly selected file to automatically selected ones.
+if test -z "$CONFIG_SITE"; then
+  if test "x$prefix" != xNONE; then
+    CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
+  else
+    CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
+  fi
+fi
+for ac_site_file in $CONFIG_SITE; do
+  if test -r "$ac_site_file"; then
+    { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5
+echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file"
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special
+  # files actually), so we avoid doing that.
+  if test -f "$cache_file"; then
+    { echo "$as_me:$LINENO: loading cache $cache_file" >&5
+echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . $cache_file;;
+      *)                      . ./$cache_file;;
+    esac
+  fi
+else
+  { echo "$as_me:$LINENO: creating cache $cache_file" >&5
+echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in `(set) 2>&1 |
+	       sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val="\$ac_cv_env_${ac_var}_value"
+  eval ac_new_val="\$ac_env_${ac_var}_value"
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5
+echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+	{ echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5
+echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+	{ echo "$as_me:$LINENO:   former value:  $ac_old_val" >&5
+echo "$as_me:   former value:  $ac_old_val" >&2;}
+	{ echo "$as_me:$LINENO:   current value: $ac_new_val" >&5
+echo "$as_me:   current value: $ac_new_val" >&2;}
+	ac_cache_corrupted=:
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+      ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5
+echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5
+echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ac_aux_dir=
+for ac_dir in ../../.. $srcdir/../../..; do
+  if test -f $ac_dir/install-sh; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install-sh -c"
+    break
+  elif test -f $ac_dir/install.sh; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install.sh -c"
+    break
+  elif test -f $ac_dir/shtool; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/shtool install -c"
+    break
+  fi
+done
+if test -z "$ac_aux_dir"; then
+  { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in ../../.. $srcdir/../../.." >&5
+echo "$as_me: error: cannot find install-sh or install.sh in ../../.. $srcdir/../../.." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"
+ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure.
+
+
+ac_ext=cc
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  for ac_prog in $CCC g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CXX"; then
+  ac_cv_prog_CXX="$CXX" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CXX="$ac_tool_prefix$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CXX=$ac_cv_prog_CXX
+if test -n "$CXX"; then
+  echo "$as_me:$LINENO: result: $CXX" >&5
+echo "${ECHO_T}$CXX" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+    test -n "$CXX" && break
+  done
+fi
+if test -z "$CXX"; then
+  ac_ct_CXX=$CXX
+  for ac_prog in $CCC g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CXX"; then
+  ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CXX="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CXX=$ac_cv_prog_ac_ct_CXX
+if test -n "$ac_ct_CXX"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CXX" >&5
+echo "${ECHO_T}$ac_ct_CXX" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$ac_ct_CXX" && break
+done
+test -n "$ac_ct_CXX" || ac_ct_CXX="g++"
+
+  CXX=$ac_ct_CXX
+fi
+
+
+# Provide some information about the compiler.
+echo "$as_me:$LINENO:" \
+     "checking for C++ compiler version" >&5
+ac_compiler=`set X $ac_compile; echo $2`
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
+  (eval $ac_compiler --version </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v </dev/null >&5\"") >&5
+  (eval $ac_compiler -v </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V </dev/null >&5\"") >&5
+  (eval $ac_compiler -V </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+echo "$as_me:$LINENO: checking for C++ compiler default output file name" >&5
+echo $ECHO_N "checking for C++ compiler default output file name... $ECHO_C" >&6
+ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5
+  (eval $ac_link_default) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # Find the output, starting from the most likely.  This scheme is
+# not robust to junk in `.', hence go to wildcards (a.*) only as a last
+# resort.
+
+# Be careful to initialize this variable, since it used to be cached.
+# Otherwise an old cache value of `no' led to `EXEEXT = no' in a Makefile.
+ac_cv_exeext=
+# b.out is created by i960 compilers.
+for ac_file in a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out
+do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj )
+	;;
+    conftest.$ac_ext )
+	# This is the source file.
+	;;
+    [ab].out )
+	# We found the default executable, but exeext='' is most
+	# certainly right.
+	break;;
+    *.* )
+	ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	# FIXME: I believe we export ac_cv_exeext for Libtool,
+	# but it would be cool to find out if it's true.  Does anybody
+	# maintain Libtool? --akim.
+	export ac_cv_exeext
+	break;;
+    * )
+	break;;
+  esac
+done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { echo "$as_me:$LINENO: error: C++ compiler cannot create executables
+See \`config.log' for more details." >&5
+echo "$as_me: error: C++ compiler cannot create executables
+See \`config.log' for more details." >&2;}
+   { (exit 77); exit 77; }; }
+fi
+
+ac_exeext=$ac_cv_exeext
+echo "$as_me:$LINENO: result: $ac_file" >&5
+echo "${ECHO_T}$ac_file" >&6
+
+# Check the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+echo "$as_me:$LINENO: checking whether the C++ compiler works" >&5
+echo $ECHO_N "checking whether the C++ compiler works... $ECHO_C" >&6
+# FIXME: These cross compiler hacks should be removed for Autoconf 3.0
+# If not cross compiling, check that we can run a simple program.
+if test "$cross_compiling" != yes; then
+  if { ac_try='./$ac_file'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { echo "$as_me:$LINENO: error: cannot run C++ compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run C++ compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+    fi
+  fi
+fi
+echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+
+rm -f a.out a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+# Check the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
+echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6
+echo "$as_me:$LINENO: result: $cross_compiling" >&5
+echo "${ECHO_T}$cross_compiling" >&6
+
+echo "$as_me:$LINENO: checking for suffix of executables" >&5
+echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;;
+    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	  export ac_cv_exeext
+	  break;;
+    * ) break;;
+  esac
+done
+else
+  { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+rm -f conftest$ac_cv_exeext
+echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5
+echo "${ECHO_T}$ac_cv_exeext" >&6
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+echo "$as_me:$LINENO: checking for suffix of object files" >&5
+echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6
+if test "${ac_cv_objext+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg ) ;;
+    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+       break;;
+  esac
+done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_objext" >&5
+echo "${ECHO_T}$ac_cv_objext" >&6
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+echo "$as_me:$LINENO: checking whether we are using the GNU C++ compiler" >&5
+echo $ECHO_N "checking whether we are using the GNU C++ compiler... $ECHO_C" >&6
+if test "${ac_cv_cxx_compiler_gnu+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_compiler_gnu=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_compiler_gnu=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_cxx_compiler_gnu=$ac_compiler_gnu
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_cxx_compiler_gnu" >&5
+echo "${ECHO_T}$ac_cv_cxx_compiler_gnu" >&6
+GXX=`test $ac_compiler_gnu = yes && echo yes`
+ac_test_CXXFLAGS=${CXXFLAGS+set}
+ac_save_CXXFLAGS=$CXXFLAGS
+CXXFLAGS="-g"
+echo "$as_me:$LINENO: checking whether $CXX accepts -g" >&5
+echo $ECHO_N "checking whether $CXX accepts -g... $ECHO_C" >&6
+if test "${ac_cv_prog_cxx_g+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cxx_g=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_prog_cxx_g=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_cxx_g" >&5
+echo "${ECHO_T}$ac_cv_prog_cxx_g" >&6
+if test "$ac_test_CXXFLAGS" = set; then
+  CXXFLAGS=$ac_save_CXXFLAGS
+elif test $ac_cv_prog_cxx_g = yes; then
+  if test "$GXX" = yes; then
+    CXXFLAGS="-g -O2"
+  else
+    CXXFLAGS="-g"
+  fi
+else
+  if test "$GXX" = yes; then
+    CXXFLAGS="-O2"
+  else
+    CXXFLAGS=
+  fi
+fi
+for ac_declaration in \
+   '' \
+   'extern "C" void std::exit (int) throw (); using std::exit;' \
+   'extern "C" void std::exit (int); using std::exit;' \
+   'extern "C" void exit (int) throw ();' \
+   'extern "C" void exit (int);' \
+   'void exit (int);'
+do
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+#include <stdlib.h>
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+continue
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+rm -f conftest*
+if test -n "$ac_declaration"; then
+  echo '#ifdef __cplusplus' >>confdefs.h
+  echo $ac_declaration      >>confdefs.h
+  echo '#endif'             >>confdefs.h
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5
+echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6
+if test -z "$INSTALL"; then
+if test "${ac_cv_path_install+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in
+  ./ | .// | /cC/* | \
+  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+  ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \
+  /usr/ucb/* ) ;;
+  *)
+    # OSF1 and SCO ODT 3.0 have their own names for install.
+    # Don't use installbsd from OSF since it installs stuff as root
+    # by default.
+    for ac_prog in ginstall scoinst install; do
+      for ac_exec_ext in '' $ac_executable_extensions; do
+	if $as_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
+	  if test $ac_prog = install &&
+	    grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # AIX install.  It has an incompatible calling convention.
+	    :
+	  elif test $ac_prog = install &&
+	    grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # program-specific install script used by HP pwplus--don't use.
+	    :
+	  else
+	    ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+	    break 3
+	  fi
+	fi
+      done
+    done
+    ;;
+esac
+done
+
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL=$ac_cv_path_install
+  else
+    # As a last resort, use the slow shell script.  We don't cache a
+    # path for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the path is relative.
+    INSTALL=$ac_install_sh
+  fi
+fi
+echo "$as_me:$LINENO: result: $INSTALL" >&5
+echo "${ECHO_T}$INSTALL" >&6
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+
+          ac_config_files="$ac_config_files Makefile"
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, don't put newlines in cache variables' values.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+{
+  (set) 2>&1 |
+    case `(ac_space=' '; set | grep ac_space) 2>&1` in
+    *ac_space=\ *)
+      # `set' does not quote correctly, so add quotes (double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \).
+      sed -n \
+	"s/'/'\\\\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;;
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n \
+	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+      ;;
+    esac;
+} |
+  sed '
+     t clear
+     : clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     : end' >>confcache
+if diff $cache_file confcache >/dev/null 2>&1; then :; else
+  if test -w $cache_file; then
+    test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file"
+    cat confcache >$cache_file
+  else
+    echo "not updating unwritable cache $cache_file"
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
+s/:*\$(srcdir):*/:/;
+s/:*\${srcdir}:*/:/;
+s/:*@srcdir@:*/:/;
+s/^\([^=]*=[	 ]*\):*/\1/;
+s/:*$//;
+s/^[^=]*=[	 ]*$//;
+}'
+fi
+
+# Transform confdefs.h into DEFS.
+# Protect against shell expansion while executing Makefile rules.
+# Protect against Makefile macro expansion.
+#
+# If the first sed substitution is executed (which looks for macros that
+# take arguments), then we branch to the quote section.  Otherwise,
+# look for a macro that doesn't take arguments.
+cat >confdef2opt.sed <<\_ACEOF
+t clear
+: clear
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*([^)]*)\)[	 ]*\(.*\),-D\1=\2,g
+t quote
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\),-D\1=\2,g
+t quote
+d
+: quote
+s,[	 `~#$^&*(){}\\|;'"<>?],\\&,g
+s,\[,\\&,g
+s,\],\\&,g
+s,\$,$$,g
+p
+_ACEOF
+# We use echo to avoid assuming a particular line-breaking character.
+# The extra dot is to prevent the shell from consuming trailing
+# line-breaks from the sub-command output.  A line-break within
+# single-quotes doesn't work because, if this script is created in a
+# platform that uses two characters for line-breaks (e.g., DOS), tr
+# would break.
+ac_LF_and_DOT=`echo; echo .`
+DEFS=`sed -n -f confdef2opt.sed confdefs.h | tr "$ac_LF_and_DOT" ' .'`
+rm -f confdef2opt.sed
+
+
+ac_libobjs=
+ac_ltlibobjs=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_i=`echo "$ac_i" |
+	 sed 's/\$U\././;s/\.o$//;s/\.obj$//'`
+  # 2. Add them.
+  ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext"
+  ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+
+: ${CONFIG_STATUS=./config.status}
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5
+echo "$as_me: creating $CONFIG_STATUS" >&6;}
+cat >$CONFIG_STATUS <<_ACEOF
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+SHELL=\${CONFIG_SHELL-$SHELL}
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+  set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+  LC_TELEPHONE LC_TIME
+do
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+    eval $as_var=C; export $as_var
+  else
+    $as_unset $as_var
+  fi
+done
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)$' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\/\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+
+
+# PATH needs CR, and LINENO needs CR and PATH.
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
+  # Find who we are.  Look in the path if we contain no path at all
+  # relative or not.
+  case $0 in
+    *[\\/]* ) as_myself=$0 ;;
+    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+
+       ;;
+  esac
+  # We did not find ourselves, most probably we were run as `sh COMMAND'
+  # in which case we are not to be found in the path.
+  if test "x$as_myself" = x; then
+    as_myself=$0
+  fi
+  if test ! -f "$as_myself"; then
+    { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5
+echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+  case $CONFIG_SHELL in
+  '')
+    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for as_base in sh bash ksh sh5; do
+	 case $as_dir in
+	 /*)
+	   if ("$as_dir/$as_base" -c '
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
+	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
+	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
+	     CONFIG_SHELL=$as_dir/$as_base
+	     export CONFIG_SHELL
+	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
+	   fi;;
+	 esac
+       done
+done
+;;
+  esac
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line before each line; the second 'sed' does the real
+  # work.  The second script uses 'N' to pair each line-number line
+  # with the numbered line, and appends trailing '-' during
+  # substitution so that $LINENO is not a special case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
+  sed '=' <$as_myself |
+    sed '
+      N
+      s,$,-,
+      : loop
+      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+      t loop
+      s,-$,,
+      s,^['$as_cr_digits']*\n,,
+    ' >$as_me.lineno &&
+  chmod +x $as_me.lineno ||
+    { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5
+echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;}
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensible to this).
+  . ./$as_me.lineno
+  # Exit status is that of the last command.
+  exit
+}
+
+
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+  *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T='	' ;;
+  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+echo >conf$$.file
+if ln -s conf$$.file conf$$ 2>/dev/null; then
+  # We could just check for DJGPP; but this test a) works b) is more generic
+  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
+  if test -f conf$$.exe; then
+    # Don't use ln at all; we don't have any links
+    as_ln_s='cp -p'
+  else
+    as_ln_s='ln -s'
+  fi
+elif ln conf$$.file conf$$ 2>/dev/null; then
+  as_ln_s=ln
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.file
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p=:
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_executable_p="test -f"
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.
+as_nl='
+'
+IFS=" 	$as_nl"
+
+# CDPATH.
+$as_unset CDPATH
+
+exec 6>&1
+
+# Open the log real soon, to keep \$[0] and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.  Logging --version etc. is OK.
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+} >&5
+cat >&5 <<_CSEOF
+
+This file was extended by $as_me, which was
+generated by GNU Autoconf 2.59.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+_CSEOF
+echo "on `(hostname || uname -n) 2>/dev/null | sed 1q`" >&5
+echo >&5
+_ACEOF
+
+# Files that config.status was made for.
+if test -n "$ac_config_files"; then
+  echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_headers"; then
+  echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_links"; then
+  echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_commands"; then
+  echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+ac_cs_usage="\
+\`$as_me' instantiates files from templates according to the
+current configuration.
+
+Usage: $0 [OPTIONS] [FILE]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number, then exit
+  -q, --quiet      do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+  --file=FILE[:TEMPLATE]
+		   instantiate the configuration file FILE
+
+Configuration files:
+$config_files
+
+Report bugs to <bug-autoconf@gnu.org>."
+_ACEOF
+
+cat >>$CONFIG_STATUS <<_ACEOF
+ac_cs_version="\\
+config.status
+configured by $0, generated by GNU Autoconf 2.59,
+  with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
+
+Copyright (C) 2003 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+srcdir=$srcdir
+INSTALL="$INSTALL"
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+# If no file are specified by the user, then we need to provide default
+# value.  By we need to know if files were specified by the user.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=*)
+    ac_option=`expr "x$1" : 'x\([^=]*\)='`
+    ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  -*)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  *) # This is not an option, so the user has probably given explicit
+     # arguments.
+     ac_option=$1
+     ac_need_defaults=false;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --vers* | -V )
+    echo "$ac_cs_version"; exit 0 ;;
+  --he | --h)
+    # Conflict between --help and --header
+    { { echo "$as_me:$LINENO: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&5
+echo "$as_me: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&2;}
+   { (exit 1); exit 1; }; };;
+  --help | --hel | -h )
+    echo "$ac_cs_usage"; exit 0 ;;
+  --debug | --d* | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    CONFIG_FILES="$CONFIG_FILES $ac_optarg"
+    ac_need_defaults=false;;
+  --header | --heade | --head | --hea )
+    $ac_shift
+    CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg"
+    ac_need_defaults=false;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) { { echo "$as_me:$LINENO: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&5
+echo "$as_me: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&2;}
+   { (exit 1); exit 1; }; } ;;
+
+  *) ac_config_targets="$ac_config_targets $1" ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF
+if \$ac_cs_recheck; then
+  echo "running $SHELL $0 " $ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6
+  exec $SHELL $0 $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+fi
+
+_ACEOF
+
+
+
+
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+for ac_config_target in $ac_config_targets
+do
+  case "$ac_config_target" in
+  # Handling of arguments.
+  "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+  *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
+echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason to put it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Create a temporary directory, and hook for its removal unless debugging.
+$debug ||
+{
+  trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0
+  trap '{ (exit 1); exit 1; }' 1 2 13 15
+}
+
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
+  test -n "$tmp" && test -d "$tmp"
+}  ||
+{
+  tmp=./confstat$$-$RANDOM
+  (umask 077 && mkdir $tmp)
+} ||
+{
+   echo "$me: cannot create a temporary directory in ." >&2
+   { (exit 1); exit 1; }
+}
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<_ACEOF
+
+#
+# CONFIG_FILES section.
+#
+
+# No need to generate the scripts if there are no CONFIG_FILES.
+# This happens for instance when ./config.status config.h
+if test -n "\$CONFIG_FILES"; then
+  # Protect against being on the right side of a sed subst in config.status.
+  sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g;
+   s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF
+s,@SHELL@,$SHELL,;t t
+s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t
+s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t
+s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t
+s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t
+s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t
+s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t
+s,@exec_prefix@,$exec_prefix,;t t
+s,@prefix@,$prefix,;t t
+s,@program_transform_name@,$program_transform_name,;t t
+s,@bindir@,$bindir,;t t
+s,@sbindir@,$sbindir,;t t
+s,@libexecdir@,$libexecdir,;t t
+s,@datadir@,$datadir,;t t
+s,@sysconfdir@,$sysconfdir,;t t
+s,@sharedstatedir@,$sharedstatedir,;t t
+s,@localstatedir@,$localstatedir,;t t
+s,@libdir@,$libdir,;t t
+s,@includedir@,$includedir,;t t
+s,@oldincludedir@,$oldincludedir,;t t
+s,@infodir@,$infodir,;t t
+s,@mandir@,$mandir,;t t
+s,@build_alias@,$build_alias,;t t
+s,@host_alias@,$host_alias,;t t
+s,@target_alias@,$target_alias,;t t
+s,@DEFS@,$DEFS,;t t
+s,@ECHO_C@,$ECHO_C,;t t
+s,@ECHO_N@,$ECHO_N,;t t
+s,@ECHO_T@,$ECHO_T,;t t
+s,@LIBS@,$LIBS,;t t
+s,@CXX@,$CXX,;t t
+s,@CXXFLAGS@,$CXXFLAGS,;t t
+s,@LDFLAGS@,$LDFLAGS,;t t
+s,@CPPFLAGS@,$CPPFLAGS,;t t
+s,@ac_ct_CXX@,$ac_ct_CXX,;t t
+s,@EXEEXT@,$EXEEXT,;t t
+s,@OBJEXT@,$OBJEXT,;t t
+s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t
+s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t
+s,@INSTALL_DATA@,$INSTALL_DATA,;t t
+s,@LIBOBJS@,$LIBOBJS,;t t
+s,@LTLIBOBJS@,$LTLIBOBJS,;t t
+CEOF
+
+_ACEOF
+
+  cat >>$CONFIG_STATUS <<\_ACEOF
+  # Split the substitutions into bite-sized pieces for seds with
+  # small command number limits, like on Digital OSF/1 and HP-UX.
+  ac_max_sed_lines=48
+  ac_sed_frag=1 # Number of current file.
+  ac_beg=1 # First line for current file.
+  ac_end=$ac_max_sed_lines # Line after last line for current file.
+  ac_more_lines=:
+  ac_sed_cmds=
+  while $ac_more_lines; do
+    if test $ac_beg -gt 1; then
+      sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
+    else
+      sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
+    fi
+    if test ! -s $tmp/subs.frag; then
+      ac_more_lines=false
+    else
+      # The purpose of the label and of the branching condition is to
+      # speed up the sed processing (if there are no `@' at all, there
+      # is no need to browse any of the substitutions).
+      # These are the two extra sed commands mentioned above.
+      (echo ':t
+  /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed
+      if test -z "$ac_sed_cmds"; then
+	ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed"
+      else
+	ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed"
+      fi
+      ac_sed_frag=`expr $ac_sed_frag + 1`
+      ac_beg=$ac_end
+      ac_end=`expr $ac_end + $ac_max_sed_lines`
+    fi
+  done
+  if test -z "$ac_sed_cmds"; then
+    ac_sed_cmds=cat
+  fi
+fi # test -n "$CONFIG_FILES"
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case $ac_file in
+  - | *:- | *:-:* ) # input from stdin
+	cat >$tmp/stdin
+	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  * )   ac_file_in=$ac_file.in ;;
+  esac
+
+  # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories.
+  ac_dir=`(dirname "$ac_file") 2>/dev/null ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+  { if $as_mkdir_p; then
+    mkdir -p "$ac_dir"
+  else
+    as_dir="$ac_dir"
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+   { (exit 1); exit 1; }; }; }
+
+  ac_builddir=.
+
+if test "$ac_dir" != .; then
+  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  # A "../" for each directory in $ac_dir_suffix.
+  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+  ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+  .)  # No --srcdir option.  We are building in place.
+    ac_srcdir=.
+    if test -z "$ac_top_builddir"; then
+       ac_top_srcdir=.
+    else
+       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+    fi ;;
+  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir ;;
+  *) # Relative path.
+    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
+
+
+  case $INSTALL in
+  [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+  *) ac_INSTALL=$ac_top_builddir$INSTALL ;;
+  esac
+
+  if test x"$ac_file" != x-; then
+    { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+    rm -f "$ac_file"
+  fi
+  # Let's still pretend it is `configure' which instantiates (i.e., don't
+  # use $as_me), people would be surprised to read:
+  #    /* config.h.  Generated by config.status.  */
+  if test x"$ac_file" = x-; then
+    configure_input=
+  else
+    configure_input="$ac_file.  "
+  fi
+  configure_input=$configure_input"Generated from `echo $ac_file_in |
+				     sed 's,.*/,,'` by configure."
+
+  # First look for the input files in the build tree, otherwise in the
+  # src tree.
+  ac_file_inputs=`IFS=:
+    for f in $ac_file_in; do
+      case $f in
+      -) echo $tmp/stdin ;;
+      [\\/$]*)
+	 # Absolute (can't be DOS-style, as IFS=:)
+	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 echo "$f";;
+      *) # Relative
+	 if test -f "$f"; then
+	   # Build tree
+	   echo "$f"
+	 elif test -f "$srcdir/$f"; then
+	   # Source tree
+	   echo "$srcdir/$f"
+	 else
+	   # /dev/null tree
+	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 fi;;
+      esac
+    done` || { (exit 1); exit 1; }
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF
+  sed "$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s,@configure_input@,$configure_input,;t t
+s,@srcdir@,$ac_srcdir,;t t
+s,@abs_srcdir@,$ac_abs_srcdir,;t t
+s,@top_srcdir@,$ac_top_srcdir,;t t
+s,@abs_top_srcdir@,$ac_abs_top_srcdir,;t t
+s,@builddir@,$ac_builddir,;t t
+s,@abs_builddir@,$ac_abs_builddir,;t t
+s,@top_builddir@,$ac_top_builddir,;t t
+s,@abs_top_builddir@,$ac_abs_top_builddir,;t t
+s,@INSTALL@,$ac_INSTALL,;t t
+" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out
+  rm -f $tmp/stdin
+  if test x"$ac_file" != x-; then
+    mv $tmp/out $ac_file
+  else
+    cat $tmp/out
+    rm -f $tmp/out
+  fi
+
+done
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+{ (exit 0); exit 0; }
+_ACEOF
+chmod +x $CONFIG_STATUS
+ac_clean_files=$ac_clean_files_save
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || { (exit 1); exit 1; }
+fi
+
Index: /gsdl/trunk/build-src/packages/isis-gdl/configure.in
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/configure.in	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/configure.in	(revision 16571)
@@ -0,0 +1,19 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_INIT()
+
+dnl  default installation
+dnl will be overridden by command-line args from packages/configure
+AC_PREFIX_DEFAULT(../../..)
+
+dnl this uses the config.guess, config.sub and install-sh from gsdl.
+AC_CONFIG_AUX_DIR(../../..)
+
+dnl compiler - need c++
+AC_PROG_CXX
+
+dnl Windows extension
+AC_EXEEXT
+
+AC_PROG_INSTALL
+
+AC_OUTPUT(Makefile)
Index: /gsdl/trunk/build-src/packages/isis-gdl/mytchar.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/mytchar.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/mytchar.h	(revision 16571)
@@ -0,0 +1,35 @@
+/**********************************************************************
+ *
+ * mytchar.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef __MY_TCHAR__
+#define __MY_TCHAR__
+
+#include "tchar.h"
+
+#ifndef _WIN32
+typedef wchar_t TCHAR;
+#endif
+
+#endif
Index: /gsdl/trunk/build-src/packages/isis-gdl/stdafx.cpp
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/stdafx.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/stdafx.cpp	(revision 16571)
@@ -0,0 +1,33 @@
+/**********************************************************************
+ *
+ * stdafx.cpp
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+// stdafx.cpp : source file that includes just the standard includes
+// IsisGdl.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file
Index: /gsdl/trunk/build-src/packages/isis-gdl/stdafx.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/stdafx.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/stdafx.h	(revision 16571)
@@ -0,0 +1,40 @@
+/**********************************************************************
+ *
+ * stdafx.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+// #pragma once
+
+
+#include <iostream>
+#include <assert.h>
+#include "mytchar.h"
+#include "Compat.h"
+// TODO: reference additional headers your program requires here
+#include "IsisDef.h"
+
Index: /gsdl/trunk/build-src/packages/isis-gdl/tchar.h
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/tchar.h	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/tchar.h	(revision 16571)
@@ -0,0 +1,1046 @@
+/**********************************************************************
+ *
+ * tchar.h
+ * Copyright (C) 2003  UNESCO
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/***
+*tchar.h - definitions for generic international text functions
+*
+*       Copyright (c) 1991-1997, Microsoft Corporation. All rights reserved.
+*
+*Purpose:
+*       Definitions for generic international functions, mostly defines
+*       which map string/formatted-io/ctype functions to char, wchar_t, or
+*       MBCS versions.  To be used for compatibility between single-byte,
+*       multi-byte and Unicode text models.
+*
+*       [Public]
+*
+****/
+
+#if     _MSC_VER > 1000 /*IFSTRIP=IGN*/
+#pragma once
+#endif
+
+#ifndef _INC_TCHAR
+#define _INC_TCHAR
+
+#ifdef  _MSC_VER
+#pragma warning(disable:4514)       /* disable unwanted C++ /W4 warning */
+/* #pragma warning(default:4514) */ /* use this to reenable, if necessary */
+#endif  /* _MSC_VER */
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+
+/* Define __cdecl for non-Microsoft compilers */
+
+#if     ( !defined(_MSC_VER) && !defined(__cdecl) )
+#define __cdecl
+#endif
+
+
+/* Define _CRTIMP */
+
+#ifndef _CRTIMP
+#ifdef  CRTDLL
+#define _CRTIMP __declspec(dllexport)
+#else   /* ndef CRTDLL */
+#ifdef  _DLL
+#define _CRTIMP __declspec(dllimport)
+#else   /* ndef _DLL */
+#define _CRTIMP
+#endif  /* _DLL */
+#endif  /* CRTDLL */
+#endif  /* _CRTIMP */
+
+
+#define _ftcscat    _tcscat
+#define _ftcschr    _tcschr
+#define _ftcscpy    _tcscpy
+#define _ftcscspn   _tcscspn
+#define _ftcslen    _tcslen
+#define _ftcsncat   _tcsncat
+#define _ftcsncpy   _tcsncpy
+#define _ftcspbrk   _tcspbrk
+#define _ftcsrchr   _tcsrchr
+#define _ftcsspn    _tcsspn
+#define _ftcsstr    _tcsstr
+#define _ftcstok    _tcstok
+
+#define _ftcsdup    _tcsdup
+#define _ftcsnset   _tcsnset
+#define _ftcsrev    _tcsrev
+#define _ftcsset    _tcsset
+
+#define _ftcscmp      _tcscmp
+#define _ftcsicmp     _tcsicmp
+#define _ftcsnccmp    _tcsnccmp
+#define _ftcsncmp     _tcsncmp
+#define _ftcsncicmp   _tcsncicmp
+#define _ftcsnicmp    _tcsnicmp
+
+#define _ftcscoll     _tcscoll
+#define _ftcsicoll    _tcsicoll
+#define _ftcsnccoll   _tcsnccoll
+#define _ftcsncoll    _tcsncoll
+#define _ftcsncicoll  _tcsncicoll
+#define _ftcsnicoll   _tcsnicoll
+
+/* Redundant "logical-character" mappings */
+
+#define _ftcsclen   _tcsclen
+#define _ftcsnccat  _tcsnccat
+#define _ftcsnccpy  _tcsnccpy
+#define _ftcsncset  _tcsncset
+
+#define _ftcsdec    _tcsdec
+#define _ftcsinc    _tcsinc
+#define _ftcsnbcnt  _tcsnbcnt
+#define _ftcsnccnt  _tcsnccnt
+#define _ftcsnextc  _tcsnextc
+#define _ftcsninc   _tcsninc
+#define _ftcsspnp   _tcsspnp
+
+#define _ftcslwr    _tcslwr
+#define _ftcsupr    _tcsupr
+
+#define _ftclen     _tclen
+#define _ftccpy     _tccpy
+#define _ftccmp     _tccmp
+
+
+#ifdef  _UNICODE
+
+#ifdef  __cplusplus
+}   /* ... extern "C" */
+#endif
+
+/* ++++++++++++++++++++ UNICODE ++++++++++++++++++++ */
+
+#include <wchar.h>
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#ifndef _WCTYPE_T_DEFINED
+typedef wchar_t wint_t;
+typedef wchar_t wctype_t;
+#define _WCTYPE_T_DEFINED
+#endif
+
+#ifndef __TCHAR_DEFINED
+typedef wchar_t     _TCHAR;
+typedef wchar_t     _TSCHAR;
+typedef wchar_t     _TUCHAR;
+typedef wchar_t     _TXCHAR;
+typedef wint_t      _TINT;
+#define __TCHAR_DEFINED
+#endif
+
+#ifndef _TCHAR_DEFINED
+#if     !__STDC__
+typedef wchar_t     TCHAR;
+#endif
+#define _TCHAR_DEFINED
+#endif
+
+#define _TEOF       WEOF
+
+#define __T(x)      L ## x
+
+
+/* Program */
+
+#define _tmain      wmain
+#define _tWinMain   wWinMain
+#define _tenviron   _wenviron
+#define __targv     __wargv
+
+/* Formatted i/o */
+
+#define _tprintf    wprintf
+#define _ftprintf   fwprintf
+#define _stprintf   swprintf
+#define _sntprintf  _snwprintf
+#define _vtprintf   vwprintf
+#define _vftprintf  vfwprintf
+#define _vstprintf  vswprintf
+#define _vsntprintf _vsnwprintf
+#define _tscanf     wscanf
+#define _ftscanf    fwscanf
+#define _stscanf    swscanf
+
+
+/* Unformatted i/o */
+
+#define _fgettc     fgetwc
+#define _fgettchar  _fgetwchar
+#define _fgetts     fgetws
+#define _fputtc     fputwc
+#define _fputtchar  _fputwchar
+#define _fputts     fputws
+#define _gettc      getwc
+#define _gettchar   getwchar
+#define _getts      _getws
+#define _puttc      putwc
+#define _puttchar   putwchar
+#define _putts      _putws
+#define _ungettc    ungetwc
+
+
+/* String conversion functions */
+
+#define _tcstod     wcstod
+#define _tcstol     wcstol
+#define _tcstoul    wcstoul
+
+#define _itot       _itow
+#define _ltot       _ltow
+#define _ultot      _ultow
+#define _ttoi       _wtoi
+#define _ttol       _wtol
+
+#define _ttoi64     _wtoi64
+#define _i64tot     _i64tow
+#define _ui64tot    _ui64tow
+
+/* String functions */
+
+#define _tcscat     wcscat
+#define _tcschr     wcschr
+#define _tcscpy     wcscpy
+#define _tcscspn    wcscspn
+#define _tcslen     wcslen
+#define _tcsncat    wcsncat
+#define _tcsncpy    wcsncpy
+#define _tcspbrk    wcspbrk
+#define _tcsrchr    wcsrchr
+#define _tcsspn     wcsspn
+#define _tcsstr     wcsstr
+#define _tcstok     wcstok
+
+#define _tcsdup     _wcsdup
+#define _tcsnset    _wcsnset
+#define _tcsrev     _wcsrev
+#define _tcsset     _wcsset
+
+#define _tcscmp     wcscmp
+#define _tcsicmp    _wcsicmp
+#define _tcsnccmp   wcsncmp
+#define _tcsncmp    wcsncmp
+#define _tcsncicmp  _wcsnicmp
+#define _tcsnicmp   _wcsnicmp
+
+#define _tcscoll    wcscoll
+#define _tcsicoll   _wcsicoll
+#define _tcsnccoll  _wcsncoll
+#define _tcsncoll   _wcsncoll
+#define _tcsncicoll _wcsnicoll
+#define _tcsnicoll  _wcsnicoll
+
+
+/* Execute functions */
+
+#define _texecl     _wexecl
+#define _texecle    _wexecle
+#define _texeclp    _wexeclp
+#define _texeclpe   _wexeclpe
+#define _texecv     _wexecv
+#define _texecve    _wexecve
+#define _texecvp    _wexecvp
+#define _texecvpe   _wexecvpe
+
+#define _tspawnl    _wspawnl
+#define _tspawnle   _wspawnle
+#define _tspawnlp   _wspawnlp
+#define _tspawnlpe  _wspawnlpe
+#define _tspawnv    _wspawnv
+#define _tspawnve   _wspawnve
+#define _tspawnvp   _wspawnvp
+#define _tspawnvp   _wspawnvp
+#define _tspawnvpe  _wspawnvpe
+
+#define _tsystem    _wsystem
+
+
+/* Time functions */
+
+#define _tasctime   _wasctime
+#define _tctime     _wctime
+#define _tstrdate   _wstrdate
+#define _tstrtime   _wstrtime
+#define _tutime     _wutime
+#define _tcsftime   wcsftime
+
+
+/* Directory functions */
+
+#define _tchdir     _wchdir
+#define _tgetcwd    _wgetcwd
+#define _tgetdcwd   _wgetdcwd
+#define _tmkdir     _wmkdir
+#define _trmdir     _wrmdir
+
+
+/* Environment/Path functions */
+
+#define _tfullpath  _wfullpath
+#define _tgetenv    _wgetenv
+#define _tmakepath  _wmakepath
+#define _tputenv    _wputenv
+#define _tsearchenv _wsearchenv
+#define _tsplitpath _wsplitpath
+
+
+/* Stdio functions */
+
+#define _tfdopen    _wfdopen
+#define _tfsopen    _wfsopen
+#define _tfopen     _wfopen
+#define _tfreopen   _wfreopen
+#define _tperror    _wperror
+#define _tpopen     _wpopen
+#define _ttempnam   _wtempnam
+#define _ttmpnam    _wtmpnam
+
+
+/* Io functions */
+
+#define _taccess    _waccess
+#define _tchmod     _wchmod
+#define _tcreat     _wcreat
+#define _tfindfirst _wfindfirst
+#define _tfindfirsti64  _wfindfirsti64
+#define _tfindnext  _wfindnext
+#define _tfindnexti64   _wfindnexti64
+#define _tmktemp    _wmktemp
+#define _topen      _wopen
+#define _tremove    _wremove
+#define _trename    _wrename
+#define _tsopen     _wsopen
+#define _tunlink    _wunlink
+
+#define _tfinddata_t    _wfinddata_t
+#define _tfinddatai64_t _wfinddatai64_t
+
+
+/* Stat functions */
+
+#define _tstat      _wstat
+#define _tstati64   _wstati64
+
+
+/* Setlocale functions */
+
+#define _tsetlocale _wsetlocale
+
+
+/* Redundant "logical-character" mappings */
+
+#define _tcsclen    wcslen
+#define _tcsnccat   wcsncat
+#define _tcsnccpy   wcsncpy
+#define _tcsncset   _wcsnset
+
+#define _tcsdec     _wcsdec
+#define _tcsinc     _wcsinc
+#define _tcsnbcnt   _wcsncnt
+#define _tcsnccnt   _wcsncnt
+#define _tcsnextc   _wcsnextc
+#define _tcsninc    _wcsninc
+#define _tcsspnp    _wcsspnp
+
+#define _tcslwr     _wcslwr
+#define _tcsupr     _wcsupr
+#define _tcsxfrm    wcsxfrm
+
+
+#if     (__STDC__ || defined(_NO_INLINING)) && !defined(_M_M68K)
+#define _tclen(_pc) (1)
+#define _tccpy(_pc1,_cpc2) ((*(_pc1) = *(_cpc2)))
+#define _tccmp(_cpc1,_cpc2) ((*(_cpc1))-(*(_cpc2)))
+#else   /* __STDC__ */
+__inline size_t __cdecl _tclen(const wchar_t *_cpc) { return (_cpc,1); }
+__inline void __cdecl _tccpy(wchar_t *_pc1, const wchar_t *_cpc2) { *_pc1 = (wchar_t)*_cpc2; }
+__inline int __cdecl _tccmp(const wchar_t *_cpc1, const wchar_t *_cpc2) { return (int) ((*_cpc1)-(*_cpc2)); }
+#endif  /* __STDC__ */
+
+
+/* ctype functions */
+
+#define _istalnum   iswalnum
+#define _istalpha   iswalpha
+#define _istascii   iswascii
+#define _istcntrl   iswcntrl
+#define _istdigit   iswdigit
+#define _istgraph   iswgraph
+#define _istlower   iswlower
+#define _istprint   iswprint
+#define _istpunct   iswpunct
+#define _istspace   iswspace
+#define _istupper   iswupper
+#define _istxdigit  iswxdigit
+
+#define _totupper   towupper
+#define _totlower   towlower
+
+#define _istlegal(_c)   (1)
+#define _istlead(_c)    (0)
+#define _istleadbyte(_c)    (0)
+
+
+#if     (__STDC__ || defined(_NO_INLINING)) && !defined(_M_M68K)
+#define _wcsdec(_cpc1, _cpc2) ((_cpc1)>=(_cpc2) ? NULL : (_cpc2)-1)
+#define _wcsinc(_pc)    ((_pc)+1)
+#define _wcsnextc(_cpc) ((unsigned int) *(_cpc))
+#define _wcsninc(_pc, _sz) (((_pc)+(_sz)))
+#define _wcsncnt(_cpc, _sz) ((wcslen(_cpc)>_sz) ? _sz : wcslen(_cpc))
+#define _wcsspnp(_cpc1, _cpc2) ((*((_cpc1)+wcsspn(_cpc1,_cpc2))) ? ((_cpc1)+wcsspn(_cpc1,_cpc2)) : NULL)
+#else   /* __STDC__ */
+__inline wchar_t * __cdecl _wcsdec(const wchar_t * _cpc1, const wchar_t * _cpc2) { return (wchar_t *)((_cpc1)>=(_cpc2) ? NULL : ((_cpc2)-1)); }
+__inline wchar_t * __cdecl _wcsinc(const wchar_t * _pc) { return (wchar_t *)(_pc+1); }
+__inline unsigned int __cdecl _wcsnextc(const wchar_t * _cpc) { return (unsigned int)*_cpc; }
+__inline wchar_t * __cdecl _wcsninc(const wchar_t * _pc, size_t _sz) { return (wchar_t *)(_pc+_sz); }
+__inline size_t __cdecl _wcsncnt( const wchar_t * _cpc, size_t _sz) { size_t len; len = wcslen(_cpc); return (len>_sz) ? _sz : len; }
+__inline wchar_t * __cdecl _wcsspnp( const wchar_t * _cpc1, const wchar_t * _cpc2) { return (*(_cpc1 += wcsspn(_cpc1,_cpc2))!='\0') ? (wchar_t*)_cpc1 : NULL; }
+#endif  /* __STDC__ */
+
+
+#else   /* ndef _UNICODE */
+
+/* ++++++++++++++++++++ SBCS and MBCS ++++++++++++++++++++ */
+
+#ifdef  __cplusplus
+}   /* ... extern "C" */
+#endif
+
+#include <string.h>
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+
+#define _TEOF       EOF
+
+#define __T(x)      x
+
+
+/* Program */
+
+#define _tmain      main
+#define _tWinMain   WinMain
+#ifdef  _POSIX_
+#define _tenviron   environ
+#else
+#define _tenviron  _environ
+#endif
+#define __targv     __argv
+
+
+/* Formatted i/o */
+
+#define _tprintf    printf
+#define _ftprintf   fprintf
+#define _stprintf   sprintf
+#define _sntprintf  _snprintf
+#define _vtprintf   vprintf
+#define _vftprintf  vfprintf
+#define _vstprintf  vsprintf
+#define _vsntprintf _vsnprintf
+#define _tscanf     scanf
+#define _ftscanf    fscanf
+#define _stscanf    sscanf
+
+
+/* Unformatted i/o */
+
+#define _fgettc     fgetc
+#define _fgettchar  _fgetchar
+#define _fgetts     fgets
+#define _fputtc     fputc
+#define _fputtchar  _fputchar
+#define _fputts     fputs
+#define _gettc      getc
+#define _gettchar   getchar
+#define _getts      gets
+#define _puttc      putc
+#define _puttchar   putchar
+#define _putts      puts
+#define _ungettc    ungetc
+
+
+/* String conversion functions */
+
+#define _tcstod     strtod
+#define _tcstol     strtol
+#define _tcstoul    strtoul
+
+#define _itot       _itoa
+#define _ltot       _ltoa
+#define _ultot      _ultoa
+#define _ttoi       atoi
+#define _ttol       atol
+
+#define _ttoi64     _atoi64
+#define _i64tot     _i64toa
+#define _ui64tot    _ui64toa
+
+/* String functions */
+
+/* Note that _mbscat, _mbscpy and _mbsdup are functionally equivalent to 
+   strcat, strcpy and strdup, respectively. */
+
+#define _tcscat     strcat
+#define _tcscpy     strcpy
+#define _tcsdup     _strdup
+
+#define _tcslen     strlen
+#define _tcsxfrm    strxfrm
+
+
+/* Execute functions */
+
+#define _texecl     _execl
+#define _texecle    _execle
+#define _texeclp    _execlp
+#define _texeclpe   _execlpe
+#define _texecv     _execv
+#define _texecve    _execve
+#define _texecvp    _execvp
+#define _texecvpe   _execvpe
+
+#define _tspawnl    _spawnl
+#define _tspawnle   _spawnle
+#define _tspawnlp   _spawnlp
+#define _tspawnlpe  _spawnlpe
+#define _tspawnv    _spawnv
+#define _tspawnve   _spawnve
+#define _tspawnvp   _spawnvp
+#define _tspawnvpe  _spawnvpe
+
+#define _tsystem    system
+
+
+/* Time functions */
+
+#define _tasctime   asctime
+#define _tctime     ctime
+#define _tstrdate   _strdate
+#define _tstrtime   _strtime
+#define _tutime     _utime
+#define _tcsftime   strftime
+
+
+/* Directory functions */
+
+#define _tchdir     _chdir
+#define _tgetcwd    _getcwd
+#define _tgetdcwd   _getdcwd
+#define _tmkdir     _mkdir
+#define _trmdir     _rmdir
+
+
+/* Environment/Path functions */
+
+#define _tfullpath  _fullpath
+#define _tgetenv    getenv
+#define _tmakepath  _makepath
+#define _tputenv    _putenv
+#define _tsearchenv _searchenv
+#define _tsplitpath _splitpath
+
+
+/* Stdio functions */
+
+#ifdef  _POSIX_
+#define _tfdopen    fdopen
+#else
+#define _tfdopen    _fdopen
+#endif
+#define _tfsopen    _fsopen
+#define _tfopen     fopen
+#define _tfreopen   freopen
+#define _tperror    perror
+#define _tpopen     _popen
+#define _ttempnam   _tempnam
+#define _ttmpnam    tmpnam
+
+
+/* Io functions */
+
+#define _tchmod     _chmod
+#define _tcreat     _creat
+#define _tfindfirst _findfirst
+#define _tfindfirsti64  _findfirsti64
+#define _tfindnext  _findnext
+#define _tfindnexti64   _findnexti64
+#define _tmktemp    _mktemp
+
+#ifdef  _POSIX_
+#define _topen      open
+#define _taccess    access
+#else
+#define _topen      _open
+#define _taccess    _access
+#endif
+
+#define _tremove    remove
+#define _trename    rename
+#define _tsopen     _sopen
+#define _tunlink    _unlink
+
+#define _tfinddata_t    _finddata_t
+#define _tfinddatai64_t _finddatai64_t
+
+
+/* ctype functions */
+
+#define _istascii   isascii
+#define _istcntrl   iscntrl
+#define _istxdigit  isxdigit
+
+
+/* Stat functions */
+
+#define _tstat      _stat
+#define _tstati64   _stati64
+
+
+/* Setlocale functions */
+
+#define _tsetlocale setlocale
+
+
+#ifdef  _MBCS
+
+/* ++++++++++++++++++++ MBCS ++++++++++++++++++++ */
+
+#ifdef  __cplusplus
+}   /* ... extern "C" */
+#endif
+
+#include <mbstring.h>
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+
+#ifndef __TCHAR_DEFINED
+typedef char            _TCHAR;
+typedef signed char     _TSCHAR;
+typedef unsigned char   _TUCHAR;
+typedef unsigned char   _TXCHAR;
+typedef unsigned int    _TINT;
+#define __TCHAR_DEFINED
+#endif
+
+#ifndef _TCHAR_DEFINED
+#if     !__STDC__
+typedef char            TCHAR;
+#endif
+#define _TCHAR_DEFINED
+#endif
+
+
+#ifdef  _MB_MAP_DIRECT
+
+/* use mb functions directly - types must match */
+
+/* String functions */
+
+#define _tcschr     _mbschr
+#define _tcscspn    _mbscspn
+#define _tcsncat    _mbsnbcat
+#define _tcsncpy    _mbsnbcpy
+#define _tcspbrk    _mbspbrk
+#define _tcsrchr    _mbsrchr
+#define _tcsspn     _mbsspn
+#define _tcsstr     _mbsstr
+#define _tcstok     _mbstok
+
+#define _tcsnset    _mbsnbset
+#define _tcsrev     _mbsrev
+#define _tcsset     _mbsset
+
+#define _tcscmp     _mbscmp
+#define _tcsicmp    _mbsicmp
+#define _tcsnccmp   _mbsncmp
+#define _tcsncmp    _mbsnbcmp
+#define _tcsncicmp  _mbsnicmp
+#define _tcsnicmp   _mbsnbicmp
+
+#define _tcscoll    _mbscoll
+#define _tcsicoll   _mbsicoll
+#define _tcsnccoll  _mbsncoll
+#define _tcsncoll   _mbsnbcoll
+#define _tcsncicoll _mbsnicoll
+#define _tcsnicoll  _mbsnbicoll
+
+
+/* "logical-character" mappings */
+
+#define _tcsclen    _mbslen
+#define _tcsnccat   _mbsncat
+#define _tcsnccpy   _mbsncpy
+#define _tcsncset   _mbsnset
+
+
+/* MBCS-specific mappings */
+
+#define _tcsdec     _mbsdec
+#define _tcsinc     _mbsinc
+#define _tcsnbcnt   _mbsnbcnt
+#define _tcsnccnt   _mbsnccnt
+#define _tcsnextc   _mbsnextc
+#define _tcsninc    _mbsninc
+#define _tcsspnp    _mbsspnp
+
+#define _tcslwr     _mbslwr
+#define _tcsupr     _mbsupr
+
+#define _tclen      _mbclen
+#define _tccpy      _mbccpy
+
+#define _tccmp(_cpuc1,_cpuc2)   _tcsnccmp(_cpuc1,_cpuc2,1)
+
+
+#else /* _MB_MAP_DIRECT */
+
+#if     (__STDC__ || defined(_NO_INLINING)) && !defined(_M_M68K)
+
+/* use type-safe linked-in function thunks */
+
+/* String functions */
+
+_CRTIMP char * __cdecl _tcschr(const char *, unsigned int);
+_CRTIMP size_t __cdecl _tcscspn(const char *, const char *);
+_CRTIMP char * __cdecl _tcsncat(char *, const char *, size_t);
+_CRTIMP char * __cdecl _tcsncpy(char *, const char *, size_t);
+_CRTIMP char * __cdecl _tcspbrk(const char *, const char *);
+_CRTIMP char * __cdecl _tcsrchr(const char *, int);
+_CRTIMP size_t __cdecl _tcsspn(const char *, const char *);
+_CRTIMP char * __cdecl _tcsstr(const char *, const char *);
+_CRTIMP char * __cdecl _tcstok(char *, const char *);
+
+_CRTIMP char * __cdecl _tcsnset(char *, unsigned int, size_t);
+_CRTIMP char * __cdecl _tcsrev(char *);
+_CRTIMP char * __cdecl _tcsset(char *, unsigned int);
+
+_CRTIMP int __cdecl _tcscmp(const char *, const char *);
+_CRTIMP int __cdecl _tcsicmp(const char *, const char *);
+_CRTIMP int __cdecl _tcsnccmp(const char *, const char *, size_t);
+_CRTIMP int __cdecl _tcsncmp(const char *, const char *, size_t);
+_CRTIMP int __cdecl _tcsncicmp(const char *, const char *, size_t);
+_CRTIMP int __cdecl _tcsnicmp(const char *, const char *, size_t);
+
+_CRTIMP int __cdecl _tcscoll(const char *, const char *);
+_CRTIMP int __cdecl _tcsicoll(const char *, const char *);
+_CRTIMP int __cdecl _tcsnccoll(const char *, const char *, size_t);
+_CRTIMP int __cdecl _tcsncoll(const char *, const char *, size_t);
+_CRTIMP int __cdecl _tcsncicoll(const char *, const char *, size_t);
+_CRTIMP int __cdecl _tcsnicoll(const char *, const char *, size_t);
+
+
+/* "logical-character" mappings */
+
+_CRTIMP size_t __cdecl _tcsclen(const char *);
+_CRTIMP char * __cdecl _tcsnccat(char *, const char *, size_t);
+_CRTIMP char * __cdecl _tcsnccpy(char *, const char *, size_t);
+_CRTIMP char * __cdecl _tcsncset(char *, unsigned int, size_t);
+
+
+/* MBCS-specific mappings */
+
+_CRTIMP char * __cdecl _tcsdec(const char *, const char *);
+_CRTIMP char * __cdecl _tcsinc(const char *);
+_CRTIMP size_t __cdecl _tcsnbcnt(const char *, size_t);
+_CRTIMP size_t __cdecl _tcsnccnt(const char *, size_t);
+_CRTIMP unsigned int __cdecl _tcsnextc (const char *);
+_CRTIMP char * __cdecl _tcsninc(const char *, size_t);
+_CRTIMP char * __cdecl _tcsspnp(const char *, const char *);
+
+_CRTIMP char * __cdecl _tcslwr(char *);
+_CRTIMP char * __cdecl _tcsupr(char *);
+
+_CRTIMP size_t __cdecl _tclen(const char *);
+_CRTIMP void __cdecl _tccpy(char *, const char *);
+
+
+#else   /* __STDC__ */
+
+/* the default: use type-safe inline function thunks */
+
+#define _PUC    unsigned char *
+#define _CPUC   const unsigned char *
+#define _PC     char *
+#define _CPC    const char *
+#define _UI     unsigned int
+
+
+/* String functions */
+
+__inline _PC _tcschr(_CPC _s1,_UI _c) {return (_PC)_mbschr((_CPUC)_s1,_c);}
+__inline size_t _tcscspn(_CPC _s1,_CPC _s2) {return _mbscspn((_CPUC)_s1,(_CPUC)_s2);}
+__inline _PC _tcsncat(_PC _s1,_CPC _s2,size_t _n) {return (_PC)_mbsnbcat((_PUC)_s1,(_CPUC)_s2,_n);}
+__inline _PC _tcsncpy(_PC _s1,_CPC _s2,size_t _n) {return (_PC)_mbsnbcpy((_PUC)_s1,(_CPUC)_s2,_n);}
+__inline _PC _tcspbrk(_CPC _s1,_CPC _s2) {return (_PC)_mbspbrk((_CPUC)_s1,(_CPUC)_s2);}
+__inline _PC _tcsrchr(_CPC _s1,_UI _c) {return (_PC)_mbsrchr((_CPUC)_s1,_c);}
+__inline size_t _tcsspn(_CPC _s1,_CPC _s2) {return _mbsspn((_CPUC)_s1,(_CPUC)_s2);}
+__inline _PC _tcsstr(_CPC _s1,_CPC _s2) {return (_PC)_mbsstr((_CPUC)_s1,(_CPUC)_s2);}
+__inline _PC _tcstok(_PC _s1,_CPC _s2) {return (_PC)_mbstok((_PUC)_s1,(_CPUC)_s2);}
+
+__inline _PC _tcsnset(_PC _s1,_UI _c,size_t _n) {return (_PC)_mbsnbset((_PUC)_s1,_c,_n);}
+__inline _PC _tcsrev(_PC _s1) {return (_PC)_mbsrev((_PUC)_s1);}
+__inline _PC _tcsset(_PC _s1,_UI _c) {return (_PC)_mbsset((_PUC)_s1,_c);}
+
+__inline int _tcscmp(_CPC _s1,_CPC _s2) {return _mbscmp((_CPUC)_s1,(_CPUC)_s2);}
+__inline int _tcsicmp(_CPC _s1,_CPC _s2) {return _mbsicmp((_CPUC)_s1,(_CPUC)_s2);}
+__inline int _tcsnccmp(_CPC _s1,_CPC _s2,size_t _n) {return _mbsncmp((_CPUC)_s1,(_CPUC)_s2,_n);}
+__inline int _tcsncmp(_CPC _s1,_CPC _s2,size_t _n) {return _mbsnbcmp((_CPUC)_s1,(_CPUC)_s2,_n);}
+__inline int _tcsncicmp(_CPC _s1,_CPC _s2,size_t _n) {return _mbsnicmp((_CPUC)_s1,(_CPUC)_s2,_n);}
+__inline int _tcsnicmp(_CPC _s1,_CPC _s2,size_t _n) {return _mbsnbicmp((_CPUC)_s1,(_CPUC)_s2,_n);}
+
+__inline int _tcscoll(_CPC _s1,_CPC _s2) {return _mbscoll((_CPUC)_s1,(_CPUC)_s2);}
+__inline int _tcsicoll(_CPC _s1,_CPC _s2) {return _mbsicoll((_CPUC)_s1,(_CPUC)_s2);}
+__inline int _tcsnccoll(_CPC _s1,_CPC _s2,size_t _n) {return _mbsncoll((_CPUC)_s1,(_CPUC)_s2,_n);}
+__inline int _tcsncoll(_CPC _s1,_CPC _s2,size_t _n) {return _mbsnbcoll((_CPUC)_s1,(_CPUC)_s2,_n);}
+__inline int _tcsncicoll(_CPC _s1,_CPC _s2,size_t _n) {return _mbsnicoll((_CPUC)_s1,(_CPUC)_s2,_n);}
+__inline int _tcsnicoll(_CPC _s1,_CPC _s2,size_t _n) {return _mbsnbicoll((_CPUC)_s1,(_CPUC)_s2,_n);}
+
+
+/* "logical-character" mappings */
+
+__inline size_t _tcsclen(_CPC _s1) {return _mbslen((_CPUC)_s1);}
+__inline _PC _tcsnccat(_PC _s1,_CPC _s2,size_t _n) {return (_PC)_mbsncat((_PUC)_s1,(_CPUC)_s2,_n);}
+__inline _PC _tcsnccpy(_PC _s1,_CPC _s2,size_t _n) {return (_PC)_mbsncpy((_PUC)_s1,(_CPUC)_s2,_n);}
+__inline _PC _tcsncset(_PC _s1,_UI _c,size_t _n) {return (_PC)_mbsnset((_PUC)_s1,_c,_n);}
+
+
+/* MBCS-specific mappings */
+
+__inline _PC _tcsdec(_CPC _s1,_CPC _s2) {return (_PC)_mbsdec((_CPUC)_s1,(_CPUC)_s2);}
+__inline _PC _tcsinc(_CPC _s1) {return (_PC)_mbsinc((_CPUC)_s1);}
+__inline size_t _tcsnbcnt(_CPC _s1,size_t _n) {return _mbsnbcnt((_CPUC)_s1,_n);}
+__inline size_t _tcsnccnt(_CPC _s1,size_t _n) {return _mbsnccnt((_CPUC)_s1,_n);}
+__inline _PC _tcsninc(_CPC _s1,size_t _n) {return (_PC)_mbsninc((_CPUC)_s1,_n);}
+__inline _PC _tcsspnp(_CPC _s1,_CPC _s2) {return (_PC)_mbsspnp((_CPUC)_s1,(_CPUC)_s2);}
+__inline _PC _tcslwr(_PC _s1) {return (_PC)_mbslwr((_PUC)_s1);}
+__inline _PC _tcsupr(_PC _s1) {return (_PC)_mbsupr((_PUC)_s1);}
+
+__inline size_t _tclen(_CPC _s1) {return _mbclen((_CPUC)_s1);}
+__inline void _tccpy(_PC _s1,_CPC _s2) {_mbccpy((_PUC)_s1,(_CPUC)_s2); return;}
+
+
+/* inline helper */
+__inline _UI _tcsnextc(_CPC _s1) {_UI _n=0; if (_ismbblead((_UI)*(_PUC)_s1)) _n=((_UI)*_s1++)<<8; _n+=(_UI)*_s1; return(_n);}
+
+
+#endif  /* __STDC__ */
+
+#endif  /* _MB_MAP_DIRECT */
+
+
+/* MBCS-specific mappings */
+
+#define _tccmp(_cp1,_cp2)   _tcsnccmp(_cp1,_cp2,1)
+
+
+/* ctype functions */
+
+#define _istalnum   _ismbcalnum
+#define _istalpha   _ismbcalpha
+#define _istdigit   _ismbcdigit
+#define _istgraph   _ismbcgraph
+#define _istlegal   _ismbclegal
+#define _istlower   _ismbclower
+#define _istprint   _ismbcprint
+#define _istpunct   _ismbcpunct
+#define _istspace   _ismbcspace
+#define _istupper   _ismbcupper
+
+#define _totupper   _mbctoupper
+#define _totlower   _mbctolower
+
+#define _istlead    _ismbblead
+#define _istleadbyte    isleadbyte
+
+#else   /* !_MBCS */
+
+/* ++++++++++++++++++++ SBCS ++++++++++++++++++++ */
+
+
+#ifndef __TCHAR_DEFINED
+typedef char            _TCHAR;
+typedef signed char     _TSCHAR;
+typedef unsigned char   _TUCHAR;
+typedef char            _TXCHAR;
+typedef int             _TINT;
+#define __TCHAR_DEFINED
+#endif
+
+#ifndef _TCHAR_DEFINED
+#if     !__STDC__
+typedef char            TCHAR;
+#endif
+#define _TCHAR_DEFINED
+#endif
+
+
+/* String functions */
+
+#define _tcschr     strchr
+#define _tcscspn    strcspn
+#define _tcsncat    strncat
+#define _tcsncpy    strncpy
+#define _tcspbrk    strpbrk
+#define _tcsrchr    strrchr
+#define _tcsspn     strspn
+#define _tcsstr     strstr
+#define _tcstok     strtok
+
+#define _tcsnset    _strnset
+#define _tcsrev     _strrev
+#define _tcsset     _strset
+
+#define _tcscmp     strcmp
+#define _tcsicmp    _stricmp
+#define _tcsnccmp   strncmp
+#define _tcsncmp    strncmp
+#define _tcsncicmp  _strnicmp
+#define _tcsnicmp   _strnicmp
+
+#define _tcscoll    strcoll
+#define _tcsicoll   _stricoll
+#define _tcsnccoll  _strncoll
+#define _tcsncoll   _strncoll
+#define _tcsncicoll _strnicoll
+#define _tcsnicoll  _strnicoll
+
+
+/* "logical-character" mappings */
+
+#define _tcsclen    strlen
+#define _tcsnccat   strncat
+#define _tcsnccpy   strncpy
+#define _tcsncset   _strnset
+
+
+/* MBCS-specific functions */
+
+#define _tcsdec     _strdec
+#define _tcsinc     _strinc
+#define _tcsnbcnt   _strncnt
+#define _tcsnccnt   _strncnt
+#define _tcsnextc   _strnextc
+#define _tcsninc    _strninc
+#define _tcsspnp    _strspnp
+
+#define _tcslwr     _strlwr
+#define _tcsupr     _strupr
+#define _tcsxfrm    strxfrm
+
+#define _istlead(_c)    (0)
+#define _istleadbyte(_c)    (0)
+
+#if     (__STDC__ || defined(_NO_INLINING)) && !defined(_M_M68K)
+#define _tclen(_pc) (1)
+#define _tccpy(_pc1,_cpc2) (*(_pc1) = *(_cpc2))
+#define _tccmp(_cpc1,_cpc2) (((unsigned char)*(_cpc1))-((unsigned char)*(_cpc2)))
+#else   /* __STDC__ */
+__inline size_t __cdecl _tclen(const char *_cpc) { return (_cpc,1); }
+__inline void __cdecl _tccpy(char *_pc1, const char *_cpc2) { *_pc1 = *_cpc2; }
+__inline int __cdecl _tccmp(const char *_cpc1, const char *_cpc2) { return (int) (((unsigned char)*_cpc1)-((unsigned char)*_cpc2)); }
+#endif  /* __STDC__ */
+
+
+/* ctype-functions */
+
+#define _istalnum   isalnum
+#define _istalpha   isalpha
+#define _istdigit   isdigit
+#define _istgraph   isgraph
+#define _istlower   islower
+#define _istprint   isprint
+#define _istpunct   ispunct
+#define _istspace   isspace
+#define _istupper   isupper
+
+#define _totupper   toupper
+#define _totlower   tolower
+
+#define _istlegal(_c)   (1)
+
+
+/* the following is optional if functional versions are available */
+
+/* define NULL pointer value */
+
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL    0
+#else
+#define NULL    ((void *)0)
+#endif
+#endif
+
+
+#if     (__STDC__ || defined(_NO_INLINING)) && !defined(_M_M68K)
+#define _strdec(_cpc1, _cpc2) ((_cpc1)>=(_cpc2) ? NULL : (_cpc2)-1)
+#define _strinc(_pc)    ((_pc)+1)
+#define _strnextc(_cpc) ((unsigned int) *(_cpc))
+#define _strninc(_pc, _sz) (((_pc)+(_sz)))
+#define _strncnt(_cpc, _sz) ((strlen(_cpc)>_sz) ? _sz : strlen(_cpc))
+#define _strspnp(_cpc1, _cpc2) ((*((_cpc1)+strspn(_cpc1,_cpc2))) ? ((_cpc1)+strspn(_cpc1,_cpc2)) : NULL)
+#else   /* __STDC__ */
+__inline char * __cdecl _strdec(const char * _cpc1, const char * _cpc2) { return (char *)((_cpc1)>=(_cpc2) ? NULL : (_cpc2-1)); }
+__inline char * __cdecl _strinc(const char * _pc) { return (char *)(_pc+1); }
+__inline unsigned int __cdecl _strnextc(const char * _cpc) { return (unsigned int)*_cpc; }
+__inline char * __cdecl _strninc(const char * _pc, size_t _sz) { return (char *)(_pc+_sz); }
+__inline size_t __cdecl _strncnt( const char * _cpc, size_t _sz) { size_t len; len = strlen(_cpc); return (len>_sz) ? _sz : len; }
+__inline char * __cdecl _strspnp( const char * _cpc1, const char * _cpc2) { return (*(_cpc1 += strspn(_cpc1,_cpc2))!='\0') ? (char*)_cpc1 : NULL; }
+#endif  /* __STDC__ */
+
+
+#endif  /* _MBCS */
+
+#endif  /* _UNICODE */
+
+
+/* Generic text macros to be used with string literals and character constants.
+   Will also allow symbolic constants that resolve to same. */
+
+#define _T(x)       __T(x)
+#define _TEXT(x)    __T(x)
+
+
+#ifdef  __cplusplus
+}   /* ... extern "C" */
+#endif
+
+#endif  /* _INC_TCHAR */
Index: /gsdl/trunk/build-src/packages/isis-gdl/win32.mak
===================================================================
--- /gsdl/trunk/build-src/packages/isis-gdl/win32.mak	(revision 16571)
+++ /gsdl/trunk/build-src/packages/isis-gdl/win32.mak	(revision 16571)
@@ -0,0 +1,67 @@
+# ISIS-GDL
+
+GSDLHOME = ..\..
+
+CC = cl
+AR = lib
+
+DLL = 0
+DLLDEBUG = 0
+
+!IF $(GSDL_VC4)
+CPPFLAGS = -GX
+!ELSE
+CPPFLAGS = -EHsc
+!ENDIF
+
+!IF $(DLL)
+CPPFLAGS = $(CPPFLAGS) -MD 
+!ELSE
+!IF ($(DLLDEBUG))
+CPPFLAGS = $(CPPFLAGS) -MDd
+!ENDIF
+!ENDIF
+
+COMPILE = $(CC) -nologo -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+LINK = $(CC) -nologo $(LDFLAGS)
+
+.SUFFIXES:
+.SUFFIXES: .cpp .obj
+.cpp.obj:
+	$(COMPILE) $<
+
+ANSI2KNR = 
+o = .obj
+e = .exe
+
+HEADERS = AbstractIsisDb.h  CacheMan.h  Debug.h IErrors.h IsisUtil.h  \
+	XRFFile.h BlkFile.h Checking.h  Fdt.h IsisDb.h MFFile.h  mytchar.h \
+	CRC32.h Compat.h  File.h IsisDef.h  Master.h  stdafx.h \
+	CRCTab.h  DLLCode.h FileSystem.h  IsisTypes.h Unimarc.h  tchar.h
+
+
+SOURCES = CRC32.cpp Debug.cpp  FileSystem.cpp  IsisGdl.cpp Master.cpp  \
+	 stdafx.cpp CacheMan.cpp  Fdt.cpp  IErrors.cpp IsisUtil.cpp  \
+	 Unimarc.cpp Checking.cpp File.cpp IsisDb.cpp MFFile.cpp XRFFile.cpp
+
+OBJECTS = IsisGdl$o CacheMan$o Checking$o CRC32$o Fdt$o File$o Debug$o \
+	FileSystem$o IErrors$o IsisDb$o IsisUtil$o Master$o MFFile$o \
+	stdafx$o Unimarc$o XRFFile$o
+
+EXEC = IsisGdl$e
+
+DEFS = 
+
+all: $(EXEC)
+
+install: $(EXEC)
+	if NOT EXIST "$(GSDLHOME)\bin\windows" mkdir "$(GSDLHOME)\bin\windows"
+	copy $(EXEC) "$(GSDLHOME)\bin\windows"
+
+clean:
+	del *.obj
+	del $(EXEC)
+
+IsisGdl$e: $(OBJECTS) $(LIBS)
+	  $(LINK) $(OBJECTS) $(LIBS)
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/ACKNOWLEDGMENTS
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/ACKNOWLEDGMENTS	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/ACKNOWLEDGMENTS	(revision 16571)
@@ -0,0 +1,2 @@
+This product includes software developed by the
+Apache Software Foundation (http://www.apache.org/).
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/COPYING
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/COPYING	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/COPYING	(revision 16571)
@@ -0,0 +1,345 @@
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 		59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+
+	Appendix: How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) 19yy  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) 19yy name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/Counter.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/Counter.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/Counter.java	(revision 16571)
@@ -0,0 +1,73 @@
+/*
+ *    Counter.java
+ *    Copyright (C) 2000 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import java.io.*;
+
+/**
+ * Class that implements a simple counter.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public class Counter implements Serializable {
+  
+  /** Integer value stored */
+    private int m_val = 1;
+  
+  /**
+   * Initializes the counter to 1
+   */
+  public Counter() {
+    
+    m_val = 1;
+  }
+  
+  /**
+   * Initializes the counter to the given value
+   */
+  public Counter(int val) {
+    
+    m_val = val;
+  }
+  
+  /**
+   * Increments the counter.
+   */
+  public void increment() {
+    
+    m_val++;
+  }
+  
+  /**
+   * Gets the value.
+   * @return the value
+   */
+  public int value() {
+    
+    return m_val;
+  }
+  
+  /**
+   * Returns string containing value.
+   */
+  public String toString() {
+    
+    return String.valueOf(m_val);
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/GermanStemmer.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/GermanStemmer.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/GermanStemmer.java	(revision 16571)
@@ -0,0 +1,309 @@
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ *    "Apache Lucene" must not be used to endorse or promote products
+ *    derived from this software without prior written permission. For
+ *    written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    "Apache Lucene", nor may "Apache" appear in their name, without
+ *    prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
+ * ITS 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+/**
+ * A stemmer for German words. The algorithm is based on the report
+ * "A Fast and Simple Stemming Algorithm for German Words" by Jörg
+ * Caumanns (joerg.caumanns@isst.fhg.de).
+ *
+ * Changed stem() from protected to public.
+ * Changed coding for umlaute to unicode.
+ *
+ * @author    Gerhard Schwarz
+ * @version   $Id$
+ */
+public class GermanStemmer extends Stemmer
+{
+    /**
+     * Buffer for the terms while stemming them.
+     */
+    private StringBuffer sb = new StringBuffer();
+
+    /**
+     * Indicates if a term is handled as a noun.
+     */
+    private boolean uppercase = false;
+
+    /**
+     * Amount of characters that are removed with <tt>substitute()</tt> while stemming.
+     */
+    private int substCount = 0;
+
+    /**
+     * Stemms the given term to an unique <tt>discriminator</tt>.
+     *
+     * @param term  The term that should be stemmed.
+     * @return      Discriminator for <tt>term</tt>
+     */
+    public String stem( String term )
+    {
+	// Mark a possible noun.
+	uppercase = Character.isUpperCase( term.charAt( 0 ) );
+	// Use lowercase for medium stemming.
+	term = term.toLowerCase();
+	if ( !isStemmable( term ) )
+	    return term;
+	// Reset the StringBuffer.
+	sb.delete( 0, sb.length() );
+	sb.insert( 0, term );
+	// Stemming starts here...
+	substitute( sb );
+	strip( sb );
+	optimize( sb );
+	resubstitute( sb );
+	removeParticleDenotion( sb );
+	return sb.toString();
+    }
+
+    /**
+     * Checks if a term could be stemmed.
+     *
+     * @return  true if, and only if, the given term consists in letters.
+     */
+    private boolean isStemmable( String term )
+    {
+	for ( int c = 0; c < term.length(); c++ ) {
+	    if ( !Character.isLetter( term.charAt( c ) ) ) return false;
+	}
+	return true;
+    }
+
+    /**
+     * suffix stripping (stemming) on the current term. The stripping is reduced
+     * to the seven "base" suffixes "e", "s", "n", "t", "em", "er" and * "nd",
+     * from which all regular suffixes are build of. The simplification causes
+     * some overstemming, and way more irregular stems, but still provides unique.
+     * discriminators in the most of those cases.
+     * The algorithm is context free, except of the length restrictions.
+     */
+    private void strip( StringBuffer buffer )
+    {
+	boolean doMore = true;
+	while ( doMore && buffer.length() > 3 ) {
+	    if ( ( buffer.length() + substCount > 5 ) &&
+		buffer.substring( buffer.length() - 2, buffer.length() ).equals( "nd" ) )
+	    {
+		buffer.delete( buffer.length() - 2, buffer.length() );
+	    }
+	    else if ( ( buffer.length() + substCount > 4 ) &&
+		buffer.substring( buffer.length() - 2, buffer.length() ).equals( "em" ) ) {
+		buffer.delete( buffer.length() - 2, buffer.length() );
+	    }
+	    else if ( ( buffer.length() + substCount > 4 ) &&
+		buffer.substring( buffer.length() - 2, buffer.length() ).equals( "er" ) ) {
+		buffer.delete( buffer.length() - 2, buffer.length() );
+	    }
+	    else if ( buffer.charAt( buffer.length() - 1 ) == 'e' ) {
+		buffer.deleteCharAt( buffer.length() - 1 );
+	    }
+	    else if ( buffer.charAt( buffer.length() - 1 ) == 's' ) {
+		buffer.deleteCharAt( buffer.length() - 1 );
+	    }
+	    else if ( buffer.charAt( buffer.length() - 1 ) == 'n' ) {
+		buffer.deleteCharAt( buffer.length() - 1 );
+	    }
+	    // "t" occurs only as suffix of verbs.
+	    else if ( buffer.charAt( buffer.length() - 1 ) == 't' && !uppercase ) {
+		buffer.deleteCharAt( buffer.length() - 1 );
+	    }
+	    else {
+		doMore = false;
+	    }
+	}
+    }
+
+    /**
+     * Does some optimizations on the term. This optimisations are
+     * contextual.
+     */
+    private void optimize( StringBuffer buffer )
+    {
+	// Additional step for female plurals of professions and inhabitants.
+	if ( buffer.length() > 5 && buffer.substring( buffer.length() - 5, buffer.length() ).equals( "erin*" ) ) {
+	    buffer.deleteCharAt( buffer.length() -1 );
+	    strip( buffer );
+	}
+	// Additional step for irregular plural nouns like "Matrizen -> Matrix".
+	if ( buffer.charAt( buffer.length() - 1 ) == ( 'z' ) ) {
+	    buffer.setCharAt( buffer.length() - 1, 'x' );
+	}
+    }
+
+    /**
+     * Removes a particle denotion ("ge") from a term.
+     */
+    private void removeParticleDenotion( StringBuffer buffer )
+    {
+	if ( buffer.length() > 4 ) {
+	    for ( int c = 0; c < buffer.length() - 3; c++ ) {
+		if ( buffer.substring( c, c + 4 ).equals( "gege" ) ) {
+		    buffer.delete( c, c + 2 );
+		    return;
+		}
+	    }
+	}
+    }
+
+    /**
+     * Do some substitutions for the term to reduce overstemming:
+     *
+     * - Substitute Umlauts with their corresponding vowel: äöü -> aou,
+     *   "ß" is substituted by "ss"
+     * - Substitute a second char of a pair of equal characters with
+     *   an asterisk: ?? -> ?*
+     * - Substitute some common character combinations with a token:
+     *   sch/ch/ei/ie/ig/st -> $/§/%/&/#/!
+     */
+    private void substitute( StringBuffer buffer )
+    {
+	substCount = 0;
+	for ( int c = 0; c < buffer.length(); c++ ) {
+	    // Replace the second char of a pair of the equal characters with an asterisk
+	    if ( c > 0 && buffer.charAt( c ) == buffer.charAt ( c - 1 )  ) {
+		buffer.setCharAt( c, '*' );
+	    }
+	    // Substitute Umlauts.
+	    else if ( buffer.charAt( c ) == '\u00E4' ) {
+		buffer.setCharAt( c, 'a' );
+	    }
+	    else if ( buffer.charAt( c ) == '\u00F6' ) {
+		buffer.setCharAt( c, 'o' );
+	    }
+	    else if ( buffer.charAt( c ) == '\u00FC' ) {
+		buffer.setCharAt( c, 'u' );
+	    }
+	    // Take care that at least one character is left left side from the current one
+	    if ( c < buffer.length() - 1 ) {
+		if ( buffer.charAt( c ) == '\u00DF' ) {
+		    buffer.setCharAt( c, 's' );
+		    buffer.insert( c + 1, 's' );
+		    substCount++;
+		}
+		// Masking several common character combinations with an token
+		else if ( ( c < buffer.length() - 2 ) && buffer.charAt( c ) == 's' &&
+		    buffer.charAt( c + 1 ) == 'c' && buffer.charAt( c + 2 ) == 'h' )
+		{
+		    buffer.setCharAt( c, '$' );
+		    buffer.delete( c + 1, c + 3 );
+		    substCount =+ 2;
+		}
+		else if ( buffer.charAt( c ) == 'c' && buffer.charAt( c + 1 ) == 'h' ) {
+		    buffer.setCharAt( c, '§' );
+		    buffer.deleteCharAt( c + 1 );
+		    substCount++;
+		}
+		else if ( buffer.charAt( c ) == 'e' && buffer.charAt( c + 1 ) == 'i' ) {
+		    buffer.setCharAt( c, '%' );
+		    buffer.deleteCharAt( c + 1 );
+		    substCount++;
+		}
+		else if ( buffer.charAt( c ) == 'i' && buffer.charAt( c + 1 ) == 'e' ) {
+		    buffer.setCharAt( c, '&' );
+		    buffer.deleteCharAt( c + 1 );
+		    substCount++;
+		}
+		else if ( buffer.charAt( c ) == 'i' && buffer.charAt( c + 1 ) == 'g' ) {
+		    buffer.setCharAt( c, '#' );
+		    buffer.deleteCharAt( c + 1 );
+		    substCount++;
+		}
+		else if ( buffer.charAt( c ) == 's' && buffer.charAt( c + 1 ) == 't' ) {
+		    buffer.setCharAt( c, '!' );
+		    buffer.deleteCharAt( c + 1 );
+		    substCount++;
+		}
+	    }
+	}
+    }
+
+    /**
+     * Undoes the changes made by substitute(). That are character pairs and
+     * character combinations. Umlauts will remain as their corresponding vowel,
+     * as "ß" remains as "ss".
+     */
+    private void resubstitute( StringBuffer buffer )
+    {
+	for ( int c = 0; c < buffer.length(); c++ ) {
+	    if ( buffer.charAt( c ) == '*' ) {
+		char x = buffer.charAt( c - 1 );
+		buffer.setCharAt( c, x );
+	    }
+	    else if ( buffer.charAt( c ) == '$' ) {
+		buffer.setCharAt( c, 's' );
+		buffer.insert( c + 1, new char[]{'c', 'h'}, 0, 2 );
+	    }
+	    else if ( buffer.charAt( c ) == '§' ) {
+		buffer.setCharAt( c, 'c' );
+		buffer.insert( c + 1, 'h' );
+	    }
+	    else if ( buffer.charAt( c ) == '%' ) {
+		buffer.setCharAt( c, 'e' );
+		buffer.insert( c + 1, 'i' );
+	    }
+	    else if ( buffer.charAt( c ) == '&' ) {
+		buffer.setCharAt( c, 'i' );
+		buffer.insert( c + 1, 'e' );
+	    }
+	    else if ( buffer.charAt( c ) == '#' ) {
+		buffer.setCharAt( c, 'i' );
+		buffer.insert( c + 1, 'g' );
+	    }
+	    else if ( buffer.charAt( c ) == '!' ) {
+		buffer.setCharAt( c, 's' );
+		buffer.insert( c + 1, 't' );
+	    }
+	}
+    }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/IteratedLovinsStemmer.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/IteratedLovinsStemmer.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/IteratedLovinsStemmer.java	(revision 16571)
@@ -0,0 +1,76 @@
+/*
+ *    IteratedLovinsStemmer.java
+ *    Copyright (C) 2001 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import java.util.*;
+
+/**
+ * Implements the iterated version of the Lovins stemmer.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public class IteratedLovinsStemmer extends LovinsStemmer {
+
+  /**
+   * Iterated stemming of the given word.
+   */
+  public String stem(String str) {
+
+    if (str.length() <= 2) {
+      return str;
+    }
+    String stemmed = super.stem(str);
+    while (!stemmed.equals(str)) {
+      str = stemmed;
+      stemmed = super.stem(stemmed);
+    }
+    return stemmed;
+  }
+
+  /**
+   * Stems text coming into stdin and writes it to stdout.
+   */
+  public static void main(String[] ops) {
+
+    IteratedLovinsStemmer ls = new IteratedLovinsStemmer();
+
+    try {
+      int num;
+      StringBuffer wordBuffer = new StringBuffer();
+      while ((num = System.in.read()) != -1) {
+	char c = (char)num;
+	if (((num >= (int)'A') && (num <= (int)'Z')) ||
+	    ((num >= (int)'a') && (num <= (int)'z'))) {
+	  wordBuffer.append(c);
+	} else {
+	  if (wordBuffer.length() > 0) {
+	    System.out.print(ls.stem(wordBuffer.toString().
+				     toLowerCase()));
+	    wordBuffer = new StringBuffer();
+	  }
+	  System.out.print(c);
+	}
+      }
+    } catch (Exception e) {
+      System.err.println(e.getMessage());
+    }
+  }
+}
+    
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAFilter.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAFilter.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAFilter.java	(revision 16571)
@@ -0,0 +1,1496 @@
+/*
+ *    KEAFilter.java
+ *    Copyright (C) 2000, 2001 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import java.util.*;
+import java.io.*;
+
+import weka.core.*;
+import weka.filters.*;
+import weka.classifiers.*;
+
+/**
+ * This filter converts the incoming data into data appropriate for
+ * keyphrase classification. It assumes that the dataset contains two
+ * string attributes. The first attribute should contain the text of a
+ * document. The second attribute should contain the keyphrases
+ * associated with that document (if present). 
+ *
+ * The filter converts every instance (i.e. document) into a set of
+ * instances, one for each word-based n-gram in the document. The
+ * string attribute representing the document is replaced by some
+ * numeric features, the estimated probability of each n-gram being a
+ * keyphrase, and the rank of this phrase in the document according to
+ * the probability.  Each new instances also has a class value
+ * associated with it. The class is "true" if the n-gram is a true
+ * keyphrase, and "false" otherwise. Of course, if the input document
+ * doesn't come with author-assigned keyphrases, the class values for
+ * that document will be missing.  
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+  */
+public class KEAFilter extends Filter implements OptionHandler {
+
+  /** Index of attribute containing the documents */
+  private int m_DocumentAtt = 0;
+
+  /** Index of attribute containing the keyphrases */
+  private int m_KeyphrasesAtt = 1;
+
+  /** The maximum length of phrases */
+  private int m_MaxPhraseLength = 3;
+
+  /** The minimum length of phrases */
+  private int m_MinPhraseLength = 1;
+
+  /** Is keyphrase frequency attribute being used? */
+  private boolean m_KFused = false;
+
+  /** Flag for debugging mode */
+  private boolean m_Debug = false;
+
+  /** Determines whether internal periods are allowed */
+  private boolean m_DisallowInternalPeriods = false;
+
+  /** The minimum number of occurences of a phrase */
+  private int m_MinNumOccur = 2;
+
+  /** The number of features describing a phrase */
+  private int m_NumFeatures = 2;
+
+  /* Indices of attributes in m_ClassifierData */
+  private int m_TfidfIndex = 0;
+  private int m_FirstOccurIndex = 1;
+  private int m_KeyFreqIndex = 2;
+
+  /** The punctuation filter used by this filter */
+  private KEAPhraseFilter m_PunctFilter = null;
+
+  /** The numbers filter used by this filter */
+  private NumbersFilter m_NumbersFilter = null;
+ 
+  /** The actual classifier used to compute probabilities */
+  private DistributionClassifier m_Classifier = null;
+
+  /** The dictionary containing the document frequencies */
+  private HashMap m_Dictionary = null;
+
+  /** The dictionary containing the keyphrases */
+  private HashMap m_KeyphraseDictionary = null;
+
+  /** The number of documents in the global frequencies corpus */
+  private int m_NumDocs = 0;
+
+  /** Template for the classifier data */
+  private Instances m_ClassifierData = null;
+
+  /** The stemmer to be used */
+  private Stemmer m_Stemmer = new IteratedLovinsStemmer();
+
+  /** The list of stop words to be used */
+  private Stopwords m_Stopwords = new StopwordsEnglish();
+
+  /** Determines whether check for proper nouns is performed */
+  private boolean m_CheckForProperNouns = true;
+
+  /**
+   * Get the M_CheckProperNouns value.
+   * @return the M_CheckProperNouns value.
+   */
+  public boolean getCheckForProperNouns() {
+    return m_CheckForProperNouns;
+  }
+
+  /**
+   * Set the M_CheckProperNouns value.
+   * @param newM_CheckProperNouns The new M_CheckProperNouns value.
+   */
+  public void setCheckForProperNouns(boolean newM_CheckProperNouns) {
+    this.m_CheckForProperNouns = newM_CheckProperNouns;
+  }
+  
+  /**
+   * Get the M_Stopwords value.
+   * @return the M_Stopwords value.
+   */
+  public Stopwords getStopwords() {
+    return m_Stopwords;
+  }
+
+  /**
+   * Set the M_Stopwords value.
+   * @param newM_Stopwords The new M_Stopwords value.
+   */
+  public void setStopwords(Stopwords newM_Stopwords) {
+    this.m_Stopwords = newM_Stopwords;
+  }
+
+  
+  /**
+   * Get the Stemmer value.
+   * @return the Stemmer value.
+   */
+  public Stemmer getStemmer() {
+
+    return m_Stemmer;
+  }
+
+  /**
+   * Set the Stemmer value.
+   * @param newStemmer The new Stemmer value.
+   */
+  public void setStemmer(Stemmer newStemmer) {
+
+    this.m_Stemmer = newStemmer;
+  }
+
+  /**
+   * Get the value of MinNumOccur.
+   *
+   * @return Value of MinNumOccur.
+   */
+  public int getMinNumOccur() {
+    
+    return m_MinNumOccur;
+  }
+  
+  /**
+   * Set the value of MinNumOccur.
+   *
+   * @param newMinNumOccur Value to assign to MinNumOccur.
+   */
+  public void setMinNumOccur(int newMinNumOccur) {
+    
+    m_MinNumOccur = newMinNumOccur;
+  }
+  
+  /**
+   * Get the value of MaxPhraseLength.
+   *
+   * @return Value of MaxPhraseLength.
+   */
+  public int getMaxPhraseLength() {
+    
+    return m_MaxPhraseLength;
+  }
+  
+  /**
+   * Set the value of MaxPhraseLength.
+   *
+   * @param newMaxPhraseLength Value to assign to MaxPhraseLength.
+   */
+  public void setMaxPhraseLength(int newMaxPhraseLength) {
+    
+    m_MaxPhraseLength = newMaxPhraseLength;
+  }
+  
+  /**
+   * Get the value of MinPhraseLength.
+   *
+   * @return Value of MinPhraseLength.
+   */
+  public int getMinPhraseLength() {
+    
+    return m_MinPhraseLength;
+  }
+  
+  /**
+   * Set the value of MinPhraseLength.
+   *
+   * @param newMinPhraseLength Value to assign to MinPhraseLength.
+   */
+  public void setMinPhraseLength(int newMinPhraseLength) {
+    
+    m_MinPhraseLength = newMinPhraseLength;
+  }
+
+  /**
+   * Returns the index of the stemmed phrases in the output ARFF file.
+   */
+  public int getStemmedPhraseIndex() {
+
+    return m_DocumentAtt;
+  }
+
+  /**
+   * Returns the index of the unstemmed phrases in the output ARFF file.
+   */
+  public int getUnstemmedPhraseIndex() {
+
+    return m_DocumentAtt + 1;
+  }
+
+  /**
+   * Returns the index of the phrases' probabilities in the output ARFF file.
+   */
+  public int getProbabilityIndex() {
+
+    int index = m_DocumentAtt + 4;
+
+    if (m_Debug) {
+      if (m_KFused) {
+	index++;
+      }
+    }
+    return index;
+  }
+
+  /**
+   * Returns the index of the phrases' ranks in the output ARFF file.
+   */
+  public int getRankIndex() {
+
+    return getProbabilityIndex() + 1;
+  }
+
+  /**
+   * Get the value of DocumentAtt.
+   *
+   * @return Value of DocumentAtt.
+   */
+  public int getDocumentAtt() {
+    
+    return m_DocumentAtt;
+  }
+  
+  /**
+   * Set the value of DocumentAtt.
+   *
+   * @param newDocumentAtt Value to assign to DocumentAtt.
+   */
+  public void setDocumentAtt(int newDocumentAtt) {
+    
+    m_DocumentAtt = newDocumentAtt;
+  }
+  
+  /**
+   * Get the value of KeyphraseAtt.
+   *
+   * @return Value of KeyphraseAtt.
+   */
+  public int getKeyphrasesAtt() {
+    
+    return m_KeyphrasesAtt;
+  }
+  
+  /**
+   * Set the value of KeyphrasesAtt.
+   *
+   * @param newKeyphrasesAtt Value to assign to KeyphrasesAtt.
+   */
+  public void setKeyphrasesAtt(int newKeyphrasesAtt) {
+    
+    m_KeyphrasesAtt = newKeyphrasesAtt;
+  }
+  
+  
+  /**
+   * Get the value of Debug.
+   *
+   * @return Value of Debug.
+   */
+  public boolean getDebug() {
+    
+    return m_Debug;
+  }
+  
+  /**
+   * Set the value of Debug.
+   *
+   * @param newDebug Value to assign to Debug.
+   */
+  public void setDebug(boolean newDebug) {
+    
+    m_Debug = newDebug;
+  }
+
+  /**
+   * Sets whether keyphrase frequency attribute is used.
+   */
+  public void setKFused(boolean flag) {
+
+    m_KFused = flag;
+    if (flag) {
+      m_NumFeatures = 3;
+    } else {
+      m_NumFeatures = 2;
+    }
+  }
+
+  /**
+   * Gets whether keyphrase frequency attribute is used.
+   */
+  public boolean getKFused() {
+
+    return m_KFused;
+  }
+
+  /**
+   * Get whether the supplied columns are to be processed
+   *
+   * @return true if the supplied columns won't be processed
+   */
+  public boolean getDisallowInternalPeriods() {
+
+    return m_DisallowInternalPeriods;
+  }
+
+  /**
+   * Set whether selected columns should be processed. If true the 
+   * selected columns won't be processed.
+   *
+   * @param invert the new invert setting
+   */
+  public void setDisallowInternalPeriods(boolean disallow) {
+
+    m_DisallowInternalPeriods = disallow;
+  }
+
+  /**
+   * Parses a given list of options controlling the behaviour of this object.
+   * Valid options are:<p>
+   *
+   * -K<br>
+   * Specifies whether keyphrase frequency statistic is used.<p>
+   *
+   * -M length<br>
+   * Sets the maximum phrase length (default: 3).<p>
+   *
+   * -L length<br>
+   * Sets the minimum phrase length (default: 1).<p>
+   *
+   * -D<br>
+   * Turns debugging mode on.<p>
+   *
+   * -I index<br>
+   * Sets the index of the attribute containing the documents (default: 0).<p>
+   *
+   * -J index<br>
+   * Sets the index of the attribute containing the keyphrases (default: 1).<p>
+   *
+   * -P<br>
+   * Disallow internal periods <p>
+   *
+   * -O number<br>
+   * The minimum number of times a phrase needs to occur (default: 2). <p>
+   *
+   * @param options the list of options as an array of strings
+   * @exception Exception if an option is not supported
+   */
+  public void setOptions(String[] options) throws Exception {
+
+    setKFused(Utils.getFlag('K', options));
+    setDebug(Utils.getFlag('D', options));
+    String docAttIndexString = Utils.getOption('I', options);
+    if (docAttIndexString.length() > 0) {
+      setDocumentAtt(Integer.parseInt(docAttIndexString) - 1);
+    } else {
+      setDocumentAtt(0);
+    }
+    String keyphraseAttIndexString = Utils.getOption('J', options);
+    if (keyphraseAttIndexString.length() > 0) {
+      setKeyphrasesAtt(Integer.parseInt(keyphraseAttIndexString) - 1);
+    } else {
+      setKeyphrasesAtt(1);
+    }
+    String maxPhraseLengthString = Utils.getOption('M', options);
+    if (maxPhraseLengthString.length() > 0) {
+      setMaxPhraseLength(Integer.parseInt(maxPhraseLengthString));
+    } else {
+      setMaxPhraseLength(3);
+    }
+    String minPhraseLengthString = Utils.getOption('M', options);
+    if (minPhraseLengthString.length() > 0) {
+      setMinPhraseLength(Integer.parseInt(minPhraseLengthString));
+    } else {
+      setMinPhraseLength(1);
+    }
+    String minNumOccurString = Utils.getOption('O', options);
+    if (minNumOccurString.length() > 0) {
+      setMinNumOccur(Integer.parseInt(minNumOccurString));
+    } else {
+      setMinNumOccur(2);
+    }
+    setDisallowInternalPeriods(Utils.getFlag('P', options));
+   }
+
+  /**
+   * Gets the current settings of the filter.
+   *
+   * @return an array of strings suitable for passing to setOptions
+   */
+  public String [] getOptions() {
+
+    String [] options = new String [13];
+    int current = 0;
+
+    if (getKFused()) {
+      options[current++] = "-K";
+    }
+    if (getDebug()) {
+      options[current++] = "-D";
+    }
+    options[current++] = "-I"; 
+    options[current++] = "" + (getDocumentAtt() + 1);
+    options[current++] = "-J"; 
+    options[current++] = "" + (getKeyphrasesAtt() + 1);
+    options[current++] = "-M"; 
+    options[current++] = "" + (getMaxPhraseLength());
+    options[current++] = "-L"; 
+    options[current++] = "" + (getMinPhraseLength());
+    options[current++] = "-O"; 
+    options[current++] = "" + (getMinNumOccur());
+
+    if (getDisallowInternalPeriods()) {
+      options[current++] = "-P";
+    }
+
+    while (current < options.length) {
+      options[current++] = "";
+    }
+    return options;
+  }
+
+  /**
+   * Returns an enumeration describing the available options
+   *
+   * @return an enumeration of all the available options
+   */
+  public Enumeration listOptions() {
+
+    Vector newVector = new Vector(7);
+
+    newVector.addElement(new Option(
+	      "\tSpecifies whether keyphrase frequency statistic is used.",
+              "K", 0, "-K"));
+    newVector.addElement(new Option(
+	      "\tSets the maximum phrase length (default: 3).",
+              "M", 1, "-M <length>"));
+    newVector.addElement(new Option(
+	      "\tSets the minimum phrase length (default: 1).",
+              "L", 1, "-L <length>"));
+    newVector.addElement(new Option(
+	      "\tTurns debugging mode on.",
+              "D", 0, "-D"));
+    newVector.addElement(new Option(
+	      "\tSets the index of the document attribute (default: 0).",
+              "I", 1, "-I"));
+    newVector.addElement(new Option(
+	      "\tSets the index of the keyphrase attribute (default: 1).",
+              "J", 1, "-J"));
+    newVector.addElement(new Option(
+	      "\tDisallow internal periods.",
+              "P", 0, "-P"));
+    newVector.addElement(new Option(
+	      "\tSet the minimum number of occurences (default: 2).",
+              "O", 1, "-O"));
+
+    return newVector.elements();
+  }
+
+  /**
+   * Returns a string describing this filter
+   *
+   * @return a description of the filter suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String globalInfo() {
+    return "Converts incoming data into data appropriate for " +
+      "keyphrase classification.";
+  }
+
+  /**
+   * Sets the format of the input instances.
+   *
+   * @param instanceInfo an Instances object containing the input
+   * instance structure (any instances contained in the object are
+   * ignored - only the structure is required).
+   * @return true if the outputFormat may be collected immediately 
+   */
+  public boolean setInputFormat(Instances instanceInfo) throws Exception {
+
+    if (instanceInfo.classIndex() >= 0) {
+      throw new Exception("Don't know what do to if class index set!");
+    }
+    if (!instanceInfo.attribute(m_KeyphrasesAtt).isString() ||
+	!instanceInfo.attribute(m_DocumentAtt).isString()) {
+      throw new Exception("Keyphrase attribute and document attribute " +
+			  "need to be string attributes.");
+    }
+    m_PunctFilter = new KEAPhraseFilter();
+    int[] arr = new int[1];
+    arr[0] = m_DocumentAtt;
+    m_PunctFilter.setAttributeIndicesArray(arr);
+    m_PunctFilter.setInputFormat(instanceInfo);
+    m_PunctFilter.setDisallowInternalPeriods(getDisallowInternalPeriods());
+    m_NumbersFilter = new NumbersFilter();
+    m_NumbersFilter.setInputFormat(m_PunctFilter.getOutputFormat());
+    super.setInputFormat(m_NumbersFilter.getOutputFormat());
+    return false;
+  }
+
+  /**
+   * Input an instance for filtering. Ordinarily the instance is processed
+   * and made available for output immediately. Some filters require all
+   * instances be read before producing output.
+   *
+   * @param instance the input instance
+   * @return true if the filtered instance may now be
+   * collected with output().
+   * @exception Exception if the input instance was not of the correct 
+   * format or if there was a problem with the filtering.
+   */
+  public boolean input(Instance instance) throws Exception {
+
+    if (getInputFormat() == null) {
+      throw new Exception("No input instance format defined");
+    }
+    if (m_NewBatch) {
+      resetQueue();
+      m_NewBatch = false;
+    }
+
+    if (m_Debug) {
+      System.err.println("-- Reading instance");
+    }
+
+    m_PunctFilter.input(instance);
+    m_PunctFilter.batchFinished();
+    instance = m_PunctFilter.output();
+
+    m_NumbersFilter.input(instance);
+    m_NumbersFilter.batchFinished();
+    instance = m_NumbersFilter.output();
+    
+    if (m_Dictionary == null) {
+      bufferInput(instance);
+      return false;
+    } else {
+      FastVector vector = convertInstance(instance, false);
+      Enumeration enum = vector.elements();
+      while (enum.hasMoreElements()) {
+	Instance inst = (Instance)enum.nextElement();
+	push(inst);
+      }
+      return true;
+    }
+  }
+
+  /**
+   * Signify that this batch of input to the filter is finished. 
+   * If the filter requires all instances prior to filtering,
+   * output() may now be called to retrieve the filtered instances.
+   *
+   * @return true if there are instances pending output
+   * @exception Exception if no input structure has been defined
+   */
+  public boolean batchFinished() throws Exception {
+
+    if (getInputFormat() == null) {
+      throw new Exception("No input instance format defined");
+    }
+    if (m_Dictionary == null) {
+      buildGlobalDictionaries();
+      buildClassifier();
+      convertPendingInstances();
+    } 
+    flushInput();
+    m_NewBatch = true;
+    return (numPendingOutput() != 0);
+  }
+
+  /**
+   * Builds the global dictionaries.
+   */
+  private void buildGlobalDictionaries() throws Exception {
+
+    if (m_Debug) {
+      System.err.println("--- Building global dictionaries");
+    }
+    
+    // Build dictionary of n-grams with associated
+    // document frequencies
+    m_Dictionary = new HashMap();
+    for (int i = 0; i < getInputFormat().numInstances(); i++) {
+      String str = getInputFormat().instance(i).stringValue(m_DocumentAtt);
+      HashMap hash = getPhrasesForDictionary(str);
+      Iterator it = hash.keySet().iterator();
+      while (it.hasNext()) {
+	String phrase = (String)it.next();
+	Counter counter = (Counter)m_Dictionary.get(phrase);
+	if (counter == null) {
+	  m_Dictionary.put(phrase, new Counter());
+	} else {
+	  counter.increment();
+	}
+      }
+    }
+    
+    if (m_KFused) {
+      
+      // Build dictionary of n-grams that occur as keyphrases
+      // with associated keyphrase frequencies
+      m_KeyphraseDictionary = new HashMap();
+      for (int i = 0; i < getInputFormat().numInstances(); i++) {
+	String str = getInputFormat().instance(i).stringValue(m_KeyphrasesAtt);
+	HashMap hash = getGivenKeyphrases(str, false);
+	if (hash != null) {
+	  Iterator it = hash.keySet().iterator();
+	  while (it.hasNext()) {
+	    String phrase = (String)it.next();
+	    Counter counter = (Counter)m_KeyphraseDictionary.get(phrase);
+	    if (counter == null) {
+	      m_KeyphraseDictionary.put(phrase, new Counter());
+	    } else {
+	      counter.increment();
+	    }
+	  }
+	}
+      }
+    } else {
+      m_KeyphraseDictionary = null;
+    }
+    
+    // Set the number of documents in the global corpus
+    m_NumDocs = getInputFormat().numInstances();
+  }
+ 
+  /**
+   * Builds the classifier.
+   */
+  private void buildClassifier() throws Exception {
+    
+    // Generate input format for classifier
+    FastVector atts = new FastVector();
+    for (int i = 0; i < getInputFormat().numAttributes(); i++) {
+      if (i == m_DocumentAtt) {
+	atts.addElement(new Attribute("TFxIDF"));
+	atts.addElement(new Attribute("First_occurrence"));
+	if (m_KFused) {
+	  atts.addElement(new Attribute("Keyphrase_frequency"));
+	}
+      } else if (i == m_KeyphrasesAtt) {
+	FastVector vals = new FastVector(2);
+	vals.addElement("False");
+	vals.addElement("True");
+	atts.addElement(new Attribute("Keyphrase?", vals));
+      } 
+    }
+    m_ClassifierData = new Instances("ClassifierData", atts, 0);
+    m_ClassifierData.setClassIndex(m_NumFeatures);
+    
+    if (m_Debug) {
+      System.err.println("--- Converting instances for classifier");
+    }
+    
+    // Convert pending input instances into data for classifier
+    for(int i = 0; i < getInputFormat().numInstances(); i++) {
+      Instance current = getInputFormat().instance(i);
+
+      // Get the key phrases for the document
+      String keyphrases = current.stringValue(m_KeyphrasesAtt);
+      HashMap hashKeyphrases = getGivenKeyphrases(keyphrases, false);
+      HashMap hashKeysEval = getGivenKeyphrases(keyphrases, true);
+
+      // Get the phrases for the document
+      HashMap hash = new HashMap();
+      int length = getPhrases(hash, current.stringValue(m_DocumentAtt));
+
+      // Compute the feature values for each phrase and
+      // add the instance to the data for the classifier
+      Iterator it = hash.keySet().iterator();
+      while (it.hasNext()) {
+	String phrase = (String)it.next();
+	FastVector phraseInfo = (FastVector)hash.get(phrase);
+	double[] vals =  featVals(phrase, phraseInfo, true,
+				  hashKeysEval, hashKeyphrases, length);
+	Instance inst = new Instance(current.weight(), vals);
+	m_ClassifierData.add(inst);
+      }
+    }
+    
+    if (m_Debug) {
+      System.err.println("--- Building classifier");
+    }
+    
+    // Build classifier
+    FilteredClassifier fclass = new FilteredClassifier();
+    fclass.setClassifier(new weka.classifiers.NaiveBayesSimple());
+    fclass.setFilter(new DiscretizeFilter());
+    m_Classifier = fclass;
+    m_Classifier.buildClassifier(m_ClassifierData);
+
+    if (m_Debug) {
+      System.err.println(m_Classifier);
+    }
+
+    // Save space
+    m_ClassifierData = new Instances(m_ClassifierData, 0);
+  }
+
+  /** 
+   * Conmputes the feature values for a given phrase.
+   */
+  private double[] featVals(String phrase, FastVector phraseInfo, 
+			    boolean training, HashMap hashKeysEval,
+			    HashMap hashKeyphrases, int length) {
+
+    // Compute feature values
+    Counter counterLocal = (Counter)phraseInfo.elementAt(1);
+    double[] newInst = new double[m_NumFeatures + 1];
+	  
+    // Compute TFxIDF
+    Counter counterGlobal = (Counter)m_Dictionary.get(phrase);
+    double localVal = counterLocal.value(), globalVal = 0;
+    if (counterGlobal != null) {
+      globalVal = counterGlobal.value();
+      if (training) {
+	globalVal = globalVal - 1;
+      }
+    }
+    
+    // Just devide by length to get approximation of probability
+    // that phrase in document is our phrase
+    newInst[m_TfidfIndex] = (localVal / ((double)length)) *
+      (-Math.log((globalVal + 1)/ ((double)m_NumDocs + 1)));
+	  
+    // Compute first occurrence
+    Counter counterFirst = (Counter)phraseInfo.elementAt(0);
+    newInst[m_FirstOccurIndex] = (double)counterFirst.value() /
+      (double)length;
+    
+    // Is keyphrase frequency attribute being used?
+    if (m_KFused) {
+      Counter keyphraseC = (Counter)m_KeyphraseDictionary.get(phrase);
+      if ((training) && (hashKeyphrases != null) &&
+	  (hashKeyphrases.containsKey(phrase))) {
+	newInst[m_KeyFreqIndex] = keyphraseC.value() - 1;
+      } else {
+	if (keyphraseC != null) {
+	  newInst[m_KeyFreqIndex] = keyphraseC.value();
+	} else {
+	  newInst[m_KeyFreqIndex] = 0;
+	}
+      }
+    }
+
+    // Compute class value
+    String phraseInEvalFormat = evalFormat((String)phraseInfo.elementAt(2));
+    if (hashKeysEval == null) { // no author-assigned keyphrases
+      newInst[m_NumFeatures] = Instance.missingValue();
+    } else if (!hashKeysEval.containsKey(phraseInEvalFormat)) {
+      newInst[m_NumFeatures] = 0; // No keyphrase
+    } else {
+      hashKeysEval.remove(phraseInEvalFormat);
+      newInst[m_NumFeatures] = 1; // Keyphrase
+    }
+    return newInst;
+  }
+
+  /**
+   * Sets output format and converts pending input instances.
+   */
+  private void convertPendingInstances() throws Exception {
+
+    if (m_Debug) {
+      System.err.println("--- Converting pending instances");
+    }
+    
+    // Create output format for filter
+    FastVector atts = new FastVector();
+    for (int i = 0; i < getInputFormat().numAttributes(); i++) {
+      if (i == m_DocumentAtt) {
+	atts.addElement(new Attribute("N-gram", null));
+	atts.addElement(new Attribute("N-gram-original", null));
+	atts.addElement(new Attribute("TFxIDF"));
+	atts.addElement(new Attribute("First_occurrence"));
+	if (m_Debug) {
+	  if (m_KFused) {
+	    atts.addElement(new Attribute("Keyphrase_frequency"));
+	  }
+	}
+	atts.addElement(new Attribute("Probability"));
+	atts.addElement(new Attribute("Rank"));
+      } else if (i == m_KeyphrasesAtt) {
+	FastVector vals = new FastVector(2);
+	vals.addElement("False");
+	vals.addElement("True");
+	atts.addElement(new Attribute("Keyphrase?", vals));
+      } else {
+	atts.addElement(getInputFormat().attribute(i));
+      }
+    }
+    Instances outFormat = new Instances("KEAdata", atts, 0);
+    setOutputFormat(outFormat);
+    
+    // Convert pending input instances into output data
+    for(int i = 0; i < getInputFormat().numInstances(); i++) {
+      Instance current = getInputFormat().instance(i);
+      FastVector vector = convertInstance(current, true);
+      Enumeration enum = vector.elements();
+      while (enum.hasMoreElements()) {
+	Instance inst = (Instance)enum.nextElement();
+	push(inst);
+      }
+    }
+  } 
+
+  /**
+   * Converts an instance.
+   */
+  private FastVector convertInstance(Instance instance, boolean training) 
+    throws Exception {
+
+    FastVector vector = new FastVector();
+
+    if (m_Debug) {
+      System.err.println("-- Converting instance");
+    }
+
+    // Get the key phrases for the document
+    HashMap hashKeyphrases = null;
+    HashMap hashKeysEval = null;
+    if (!instance.isMissing(m_KeyphrasesAtt)) {
+      String keyphrases = instance.stringValue(m_KeyphrasesAtt);
+      hashKeyphrases = getGivenKeyphrases(keyphrases, false);
+      hashKeysEval = getGivenKeyphrases(keyphrases, true);
+    }
+
+    // Get the phrases for the document
+    HashMap hash = new HashMap();
+    int length = getPhrases(hash, instance.stringValue(m_DocumentAtt));
+
+    // Compute number of extra attributes
+    int numFeatures = 5;
+    if (m_Debug) {
+      if (m_KFused) {
+	numFeatures = numFeatures + 1;
+      }
+    } 
+
+    // Set indices of key attributes
+    int phraseAttIndex = m_DocumentAtt;
+    int tfidfAttIndex = m_DocumentAtt + 2;
+    int distAttIndex = m_DocumentAtt + 3;
+    int probsAttIndex = m_DocumentAtt + numFeatures - 1;
+
+    // Go through the phrases and convert them into instances
+    Iterator it = hash.keySet().iterator();
+    while (it.hasNext()) {
+      String phrase = (String)it.next();
+      FastVector phraseInfo = (FastVector)hash.get(phrase);
+      double[] vals =  featVals(phrase, phraseInfo, training,
+				hashKeysEval, hashKeyphrases, length);
+      Instance inst = new Instance(instance.weight(), vals);
+      inst.setDataset(m_ClassifierData);
+
+      // Get probability of phrase being key phrase
+      double[] probs = m_Classifier.distributionForInstance(inst);
+      double prob = probs[1];
+
+      // Compute attribute values for final instance
+      double[] newInst = 
+	new double[instance.numAttributes() + numFeatures];
+      int pos = 0;
+      for (int i = 0; i < instance.numAttributes(); i++) {
+	if (i == m_DocumentAtt) {
+	    
+	  // Add phrase
+	  int index = outputFormatPeek().attribute(pos).
+	    addStringValue(phrase);
+	  newInst[pos++] = index;
+	  
+	  // Add original version
+	  index = outputFormatPeek().attribute(pos).
+	    addStringValue((String)phraseInfo.elementAt(2));
+	  newInst[pos++] = index;
+
+	  // Add TFxIDF
+	  newInst[pos++] = inst.value(m_TfidfIndex);
+	    
+	  // Add distance
+	  newInst[pos++] = inst.value(m_FirstOccurIndex);
+
+	    // Add other features
+	  if (m_Debug) {
+	    if (m_KFused) {
+	      newInst[pos++] = inst.value(m_KeyFreqIndex);
+	    }
+	  }
+
+	  // Add probability 
+	  probsAttIndex = pos;
+	  newInst[pos++] = prob;
+
+	  // Set rank to missing (computed below)
+	  newInst[pos++] = Instance.missingValue();
+	} else if (i == m_KeyphrasesAtt) {
+	  newInst[pos++] = inst.classValue();
+	} else {
+	  newInst[pos++] = instance.value(i);
+	}
+      }
+      Instance ins = new Instance(instance.weight(), newInst);
+      ins.setDataset(outputFormatPeek());
+      vector.addElement(ins);
+    }
+
+    // Add dummy instances for keyphrases that don't occur
+    // in the document
+    if (hashKeysEval != null) {
+      Iterator phrases = hashKeysEval.keySet().iterator();
+      while (phrases.hasNext()) {
+	String phrase = (String)phrases.next();
+	double[] newInst = 
+	  new double[instance.numAttributes() + numFeatures];
+	int pos = 0;
+	for (int i = 0; i < instance.numAttributes(); i++) {
+	  if (i == m_DocumentAtt) {
+	    
+	    // Add phrase
+	    int index = outputFormatPeek().attribute(pos).
+	      addStringValue(phrase);
+	    newInst[pos++] = (double)index;
+	    
+	    // Add original version
+	    index = outputFormatPeek().attribute(pos).
+	      addStringValue((String)hashKeysEval.get(phrase));
+	    newInst[pos++] = (double)index;
+	    
+	    // Add TFxIDF
+	    newInst[pos++] = Instance.missingValue();
+	    
+	    // Add distance
+	    newInst[pos++] = Instance.missingValue();
+	      
+	    // Add other features
+	    if (m_Debug) {
+	      if (m_KFused) {
+		newInst[pos++] = Instance.missingValue();
+	      }
+	    }
+
+	    // Add probability and rank
+	    newInst[pos++] = -Double.MAX_VALUE;
+	    newInst[pos++] = Instance.missingValue();
+	  } else if (i == m_KeyphrasesAtt) {
+	    newInst[pos++] = 1; // Keyphrase
+	  } else {
+	    newInst[pos++] = instance.value(i);
+	  } 
+	}
+	Instance inst = new Instance(instance.weight(), newInst);
+	inst.setDataset(outputFormatPeek());
+	vector.addElement(inst);
+      }
+    }
+
+    // Sort phrases according to their distance (stable sort)
+    double[] vals = new double[vector.size()];
+    for (int i = 0; i < vals.length; i++) {
+      vals[i] = ((Instance)vector.elementAt(i)).value(distAttIndex);
+    }
+    FastVector newVector = new FastVector(vector.size());
+    int[] sortedIndices = Utils.stableSort(vals);
+    for (int i = 0; i < vals.length; i++) {
+      newVector.addElement(vector.elementAt(sortedIndices[i]));
+    }
+    vector = newVector;
+
+    // Sort phrases according to their tfxidf value (stable sort)
+    for (int i = 0; i < vals.length; i++) {
+      vals[i] = -((Instance)vector.elementAt(i)).value(tfidfAttIndex);
+    }
+    newVector = new FastVector(vector.size());
+    sortedIndices = Utils.stableSort(vals);
+    for (int i = 0; i < vals.length; i++) {
+      newVector.addElement(vector.elementAt(sortedIndices[i]));
+    }
+    vector = newVector;
+
+    // Sort phrases according to their probability (stable sort)
+    for (int i = 0; i < vals.length; i++) {
+      vals[i] = 1 - ((Instance)vector.elementAt(i)).value(probsAttIndex);
+    }
+    newVector = new FastVector(vector.size());
+    sortedIndices = Utils.stableSort(vals);
+    for (int i = 0; i < vals.length; i++) {
+      newVector.addElement(vector.elementAt(sortedIndices[i]));
+    }
+    vector = newVector;
+
+    // Compute rank of phrases. Check for subphrases that are ranked
+    // lower than superphrases and assign probability -1 and set the
+    // rank to Integer.MAX_VALUE
+    int rank = 1;
+    for (int i = 0; i < vals.length; i++) {
+      Instance currentInstance = (Instance)vector.elementAt(i);
+
+      // Short cut: if phrase very unlikely make rank very low and continue
+      if (Utils.grOrEq(vals[i], 1.0)) {
+	currentInstance.setValue(probsAttIndex + 1, Integer.MAX_VALUE);
+	continue;
+      }
+
+      // Otherwise look for super phrase starting with first phrase
+      // in list that has same probability, TFxIDF value, and distance as
+      // current phrase. We do this to catch all superphrases
+      // that have same probability, TFxIDF value and distance as current phrase.
+      int startInd = i;
+      while (startInd < vals.length) {
+	Instance inst = (Instance)vector.elementAt(startInd);
+	if ((inst.value(tfidfAttIndex) != 
+	     currentInstance.value(tfidfAttIndex)) ||
+	    (inst.value(probsAttIndex) != 
+	     currentInstance.value(probsAttIndex)) ||
+	    (inst.value(distAttIndex) !=
+	     currentInstance.value(distAttIndex))) {
+	  break;
+	}
+	startInd++;
+      }
+      String val = currentInstance.stringValue(phraseAttIndex);
+      boolean foundSuperphrase = false;
+      for (int j = startInd - 1; j >= 0; j--) {
+	if (j != i) {
+	  Instance candidate = (Instance)vector.elementAt(j);
+	  String potSuperphrase = candidate.stringValue(phraseAttIndex);
+	  if (val.length() <= potSuperphrase.length()) {
+	    if (KEAFilter.contains(val, potSuperphrase)) {
+	      foundSuperphrase = true;
+	      break;
+	    }
+	  }
+	}
+      }
+      if (foundSuperphrase) {
+	currentInstance.setValue(probsAttIndex + 1, Integer.MAX_VALUE);
+      } else {
+	currentInstance.setValue(probsAttIndex + 1, rank++);
+      }
+    }
+    return vector;
+  }
+    
+  /** 
+   * Checks whether one phrase is a subphrase of another phrase.
+   */
+  private static boolean contains(String sub, String sup) {
+
+    int i = 0;
+    while (i + sub.length() - 1 < sup.length()) {
+      int j;
+      for (j = 0; j < sub.length(); j++) {
+	if (sub.charAt(j) != sup.charAt(i + j)) {
+	  break;
+	}
+      }
+      if (j == sub.length()) {
+	if ((i + j) < sup.length()) {
+	  if (sup.charAt(i + j) == ' ') {
+	    return true;
+	  } else {
+	    return false;
+	  }
+	} else {
+	  return true;
+	}
+      }
+
+      // Skip forward to next space
+      do {
+	i++;
+      } while ((i < sup.length()) && (sup.charAt(i) != ' '));
+      i++;
+    }
+    return false;
+  }
+
+  /**
+   * Returns a hashtable. Fills the hashtable
+   * with the stemmed n-grams occuring in the given string
+   * (as keys) and the number of times it occurs.
+   */
+  private HashMap getPhrasesForDictionary(String str) {
+
+    String[] buffer = new String[m_MaxPhraseLength];
+    HashMap hash = new HashMap();
+
+    StringTokenizer tok = new StringTokenizer(str, "\n");
+    while (tok.hasMoreTokens()) {
+      String phrase = tok.nextToken();
+      int numSeen = 0;
+      StringTokenizer wordTok = new StringTokenizer(phrase, " ");
+      while (wordTok.hasMoreTokens()) {
+	String word = wordTok.nextToken();
+	
+	// Store word in buffer
+	for (int i = 0; i < m_MaxPhraseLength - 1; i++) {
+	  buffer[i] = buffer[i + 1];
+	}
+	buffer[m_MaxPhraseLength - 1] = word;
+	
+	// How many are buffered?
+	numSeen++;
+	if (numSeen > m_MaxPhraseLength) {
+	  numSeen = m_MaxPhraseLength;
+	}
+	
+	// Don't consider phrases that end with a stop word
+	if (m_Stopwords.isStopword(buffer[m_MaxPhraseLength - 1])) {
+	  continue;
+	}
+	
+	// Loop through buffer and add phrases to hashtable
+	StringBuffer phraseBuffer = new StringBuffer();
+	for (int i = 1; i <= numSeen; i++) {
+	  if (i > 1) {
+	    phraseBuffer.insert(0, ' ');
+	  }
+	  phraseBuffer.insert(0, buffer[m_MaxPhraseLength - i]);
+	  
+	  // Don't consider phrases that begin with a stop word
+	  if ((i > 1) && 
+	      (m_Stopwords.isStopword(buffer[m_MaxPhraseLength - i]))) {
+	    continue;
+	  }
+	  
+	  // Only consider phrases with minimum length
+	  if (i >= m_MinPhraseLength) {
+	    
+	    // Stem string
+	    String orig = phraseBuffer.toString();
+	    String internal = internalFormat(orig);
+	    Counter count = (Counter)hash.get(internal);
+	    if (count == null) {
+	      hash.put(internal, new Counter());
+	    } else {
+	      count.increment();
+	    }
+	    
+	    // Add components if phrase is single word before
+	    // conversion into internal format (i.e. error-correcting)
+	    /*if ((orig.indexOf(' ') == -1) &&
+	      (internal.indexOf(' ') != -1)) {
+	      StringTokenizer tokW = new StringTokenizer(internal, " ");
+	      while (tokW.hasMoreTokens()) {
+	      String comp = (String)tokW.nextToken();
+	      Counter countW = (Counter)hash.get(comp);
+	      if (countW == null) {
+	      hash.put(comp, new Counter());
+	      } else {
+	      countW.increment();
+	      }
+	      }
+	      }*/
+	  }
+	}
+      }
+    }
+    return hash;
+  }
+
+  /**
+   * Expects an empty hashtable. Fills the hashtable
+   * with the stemmed n-grams occuring in the given string
+   * (as keys). Stores the position, the number of occurences,
+   * and the most commonly occurring orgininal version of
+   * each n-gram.
+   *
+   * N-grams that occur less than m_MinNumOccur are not used.
+   *
+   * Returns the total number of words (!) in the string.
+   */
+  private int getPhrases(HashMap hash, String str) {
+
+    String[] buffer = new String[m_MaxPhraseLength];
+    
+    StringTokenizer tok = new StringTokenizer(str, "\n");
+    int pos = 1; 
+    while (tok.hasMoreTokens()) {
+      String phrase = tok.nextToken();
+      int numSeen = 0;
+      StringTokenizer wordTok = new StringTokenizer(phrase, " ");
+      while (wordTok.hasMoreTokens()) {
+	String word = wordTok.nextToken();
+	
+	// Store word in buffer
+	for (int i = 0; i < m_MaxPhraseLength - 1; i++) {
+	  buffer[i] = buffer[i + 1];
+	}
+	buffer[m_MaxPhraseLength - 1] = word;
+	
+	// How many are buffered?
+	numSeen++;
+	if (numSeen > m_MaxPhraseLength) {
+	  numSeen = m_MaxPhraseLength;
+	}
+	
+	// Don't consider phrases that end with a stop word
+	if (m_Stopwords.isStopword(buffer[m_MaxPhraseLength - 1])) {
+	  pos++;
+	  continue;
+	}
+	
+	// Loop through buffer and add phrases to hashtable
+	StringBuffer phraseBuffer = new StringBuffer();
+	for (int i = 1; i <= numSeen; i++) {
+	  if (i > 1) {
+	    phraseBuffer.insert(0, ' ');
+	  }
+	  phraseBuffer.insert(0, buffer[m_MaxPhraseLength - i]);
+	  
+	  // Don't consider phrases that begin with a stop word
+	  if ((i > 1) && 
+	      (m_Stopwords.isStopword(buffer[m_MaxPhraseLength - i]))) {
+	    continue;
+	  }
+	  
+	  // Only consider phrases with minimum length
+	  if (i >= m_MinPhraseLength) {
+	    
+	    // Stem string
+	    String phrStr = phraseBuffer.toString();
+	    String internal = internalFormat(phrStr);
+	    FastVector vec = (FastVector)hash.get(internal);
+	    if (vec == null) {
+	      vec = new FastVector(3);
+	      
+	      // HashMap for storing all versions
+	      HashMap secHash = new HashMap();
+	      secHash.put(phrStr, new Counter());
+	      
+	      // Update hashtable with all the info
+	      vec.addElement(new Counter(pos + 1 - i));
+	      vec.addElement(new Counter());
+	      vec.addElement(secHash);
+	      hash.put(internal, vec);
+	    } else {
+	      
+	      // Update number of occurrences
+	      ((Counter)((FastVector)vec).elementAt(1)).increment();
+	      
+	      // Update hashtable storing different versions
+	      HashMap secHash = (HashMap)vec.elementAt(2);
+	      Counter count = (Counter)secHash.get(phrStr);
+	      if (count == null) {
+		secHash.put(phrStr, new Counter());
+	      } else {
+		count.increment();
+	      }
+	    }
+	  }
+	}
+	pos++;
+      }
+    }
+    
+    // Replace secondary hashtables with most commonly occurring
+    // version of each phrase (canonical) form. Delete all words
+    // that are proper nouns.
+    Iterator phrases = hash.keySet().iterator();
+    while (phrases.hasNext()) {
+      String phrase = (String)phrases.next();
+      FastVector info = (FastVector)hash.get(phrase);
+
+      // Occurring less than m_MinNumOccur?
+      if (((Counter)((FastVector)info).elementAt(1)).value() < m_MinNumOccur) {
+	phrases.remove();
+	continue;
+      }
+
+      // Get canonical form
+      String canForm = canonicalForm((HashMap)info.elementAt(2));
+      if (canForm == null) {
+	phrases.remove();
+      } else {
+	info.setElementAt(canForm, 2);
+      }
+    }
+    return pos;
+  }
+
+  /**
+   * Create canonical form of phrase.
+   */
+  private String canonicalForm(HashMap secHash) {
+
+    int max = 0; String bestVersion = null;
+    boolean allFullyHyphenated = true;
+    int num = 0;
+    Iterator versions = secHash.keySet().iterator();
+    while (versions.hasNext()) {
+      num++;
+      String version = (String)versions.next();
+
+      // Are all the words joined up?
+      if (!isFullyHyphenated(version)) {
+	allFullyHyphenated = false;
+      }
+
+      // Check for how often this version occurs
+      Counter count = (Counter)secHash.get(version);
+      if (count.value() > max) {
+	max = count.value();
+	bestVersion = version;
+      }
+    }
+    if ((getCheckForProperNouns()) && (num == 1) && properNoun(bestVersion)) {
+    //if (allProperNouns) {
+      return null;
+    } else {
+      if (isFullyHyphenated(bestVersion) &&
+	  !allFullyHyphenated) {
+	bestVersion = bestVersion.replace('-', ' ');
+      }
+      return bestVersion;
+    }
+  }
+
+  /**
+   * Checks whether the given phrase is
+   * fully hyphenated.
+   */
+  private boolean isFullyHyphenated(String str) {
+    
+    return (str.indexOf(' ') == -1);
+  }
+
+  /**
+   * Checks whether the given string is a 
+   * proper noun.
+   *
+   * @return true if it is a potential proper noun
+   */
+  private static boolean properNoun(String str) {
+
+    // Is it more than one word?
+    if (str.indexOf(' ') != -1) {
+      return false;
+    }
+
+    // Does it start with an upper-case character?
+    if (Character.isLowerCase(str.charAt(0))) {
+      return false;
+    } 
+
+    // Is there at least one character that's
+    // not upper-case?
+    for (int i = 1; i < str.length(); i++) {
+      /*if (Character.isUpperCase(str.charAt(i))) {
+	return false;
+	}*/
+      if (!Character.isUpperCase(str.charAt(i))) {
+	return true;
+      }
+    }
+    //return true;
+    return false;
+  }
+
+  /**
+   * Generates the evaluation format of a phrase.
+   */
+  private String evalFormat(String str) {
+    
+    return m_Stemmer.stemString(str);
+  }
+
+  /** 
+   * Generates the internal format of a phrase.
+   */
+  private String internalFormat(String str) {
+
+    // Remove some non-alphanumeric characters
+    str = str.replace('-', ' ');
+    str = str.replace('/', ' ');
+    str = str.replace('&', ' ');
+
+    // Stem string
+    return m_Stemmer.stemString(str);
+  }
+
+  /**
+   * Gets all the phrases in the given string and puts them into the
+   * hashtable.  Also stores the original version of the stemmed
+   * phrase in the hash table.  
+   */
+  private HashMap getGivenKeyphrases(String str,
+				       boolean forEval) {
+
+    FastVector vector = new FastVector();
+    HashMap hash = new HashMap();
+    
+    StringTokenizer tok = new StringTokenizer(str, "\n");
+    while (tok.hasMoreTokens()) {
+      String orig = tok.nextToken();
+      orig = orig.trim();
+      if (orig.length() > 0) {
+	String modified;
+	if (!forEval) {
+	  modified = internalFormat(orig);
+	} else {
+	  modified = evalFormat(orig);
+	}
+	if (!hash.containsKey(modified)) {
+	  hash.put(modified, orig);
+	} else {
+	  if (forEval) {
+	    System.err.println("WARNING: stem of author-assigned keyphrase " +
+			       orig + " matches existing stem (skipping it)!");
+	  }
+	}
+      }
+    }
+    if (hash.size() == 0) {
+      return null;
+    } else {
+      return hash;
+    }
+  }
+
+  /**
+   * Main method for testing this class.
+   *
+   * @param argv should contain arguments to the filter: use -h for help
+   */
+  public static void main(String [] argv) {
+    
+    try {
+      if (Utils.getFlag('b', argv)) {
+	Filter.batchFilterFile(new KEAFilter(), argv);
+      } else {
+	Filter.filterFile(new KEAFilter(), argv);
+      }
+    } catch (Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+  }
+}
+
+
+
+
+
+
+
+
+
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAKeyphraseExtractor.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAKeyphraseExtractor.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAKeyphraseExtractor.java	(revision 16571)
@@ -0,0 +1,532 @@
+/*
+ *    KEAKeyphraseExtractor.java
+ *    Copyright (C) 2001 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+import java.io.*;
+import java.util.*;
+import weka.core.*;
+import weka.filters.*;
+
+/**
+ * Extracts keyphrases from the documents in a given directory.
+ * Assumes that the file names for the documents end with ".txt".
+ * Puts extracted keyphrases into corresponding files ending with
+ * ".key" (if those are not already present). Optionally an encoding
+ * for the documents/keyphrases can be defined (e.g. for Chinese
+ * text). Documents for which ".key" exists, are used for evaluation.
+ *
+ * Valid options are:<p>
+ *
+ * -l "directory name"<br>
+ * Specifies name of directory.<p>
+ *
+ * -m "model name"<br>
+ * Specifies name of model.<p>
+ *
+ * -e "encoding"<br>
+ * Specifies encoding.<p>
+ *
+ * -n <br>
+ * Specifies number of phrases to be output (default: 5).<p>
+ *
+ * -d<br>
+ * Turns debugging mode on.<p>
+ *
+ * -a<br>
+ * Also write stemmed phrase and score into ".key" file.<p>
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public class KEAKeyphraseExtractor implements OptionHandler {
+  
+  /** Name of directory */
+  String m_dirName = null;
+  
+  /** Name of model */
+  String m_modelName = null;
+
+  /** Encoding */
+  String m_encoding = "default";
+
+  /** Debugging mode? */
+  boolean m_debug = false;
+
+  /** The KEA filter object */
+  KEAFilter m_KEAFilter = null;
+  
+  /** The number of phrases to extract. */
+  int m_numPhrases = 5;
+
+  /** Also write stemmed phrase and score into .key file. */
+  boolean m_AdditionalInfo = false;
+  
+  /**
+   * Get the value of AdditionalInfo.
+   *
+   * @return Value of AdditionalInfo.
+   */
+  public boolean getAdditionalInfo() {
+    
+    return m_AdditionalInfo;
+  }
+  
+  /**
+   * Set the value of AdditionalInfo.
+   *
+   * @param newAdditionalInfo Value to assign to AdditionalInfo.
+   */
+  public void setAdditionalInfo(boolean newAdditionalInfo) {
+    
+    m_AdditionalInfo = newAdditionalInfo;
+  }
+  
+  /**
+   * Get the value of numPhrases.
+   *
+   * @return Value of numPhrases.
+   */
+  public int getNumPhrases() {
+    
+    return m_numPhrases;
+  }
+  
+  /**
+   * Set the value of numPhrases.
+   *
+   * @param newnumPhrases Value to assign to numPhrases.
+   */
+  public void setNumPhrases(int newnumPhrases) {
+    
+    m_numPhrases = newnumPhrases;
+  }
+  
+  /**
+   * Get the value of debug.
+   *
+   * @return Value of debug.
+   */
+  public boolean getDebug() {
+    
+    return m_debug;
+  }
+  
+  /**
+   * Set the value of debug.
+   *
+   * @param newdebug Value to assign to debug.
+   */
+  public void setDebug(boolean newdebug) {
+    
+    m_debug = newdebug;
+  }
+  
+  /**
+   * Get the value of encoding.
+   *
+   * @return Value of encoding.
+   */
+  public String getEncoding() {
+    
+    return m_encoding;
+  }
+  
+  /**
+   * Set the value of encoding.
+   *
+   * @param newencoding Value to assign to encoding.
+   */
+  public void setEncoding(String newencoding) {
+    
+    m_encoding = newencoding;
+  }
+  
+  /**
+   * Get the value of modelName.
+   *
+   * @return Value of modelName.
+   */
+  public String getModelName() {
+    
+    return m_modelName;
+  }
+  
+  /**
+   * Set the value of modelName.
+   *
+   * @param newmodelName Value to assign to modelName.
+   */
+  public void setModelName(String newmodelName) {
+    
+    m_modelName = newmodelName;
+  }
+  
+  /**
+   * Get the value of dirName.
+   *
+   * @return Value of dirName.
+   */
+  public String getDirName() {
+    
+    return m_dirName;
+  }
+  
+  /**
+   * Set the value of dirName.
+   *
+   * @param newdirName Value to assign to dirName.
+   */
+  public void setDirName(String newdirName) {
+    
+    m_dirName = newdirName;
+  }
+  
+  /**
+   * Parses a given list of options controlling the behaviour of this object.
+   * Valid options are:<p>
+   *
+   * -l "directory name"<br>
+   * Specifies name of directory.<p>
+   *
+   * -m "model name"<br>
+   * Specifies name of model.<p>
+   *
+   * -e "encoding"<br>
+   * Specifies encoding.<p>
+   *
+   * -n<br>
+   * Specifies number of phrases to be output (default: 5).<p>
+   *
+   * -d<br>
+   * Turns debugging mode on.<p>
+   *
+   * -a<br>
+   * Also write stemmed phrase and score into ".key" file.<p>
+   *
+   * @param options the list of options as an array of strings
+   * @exception Exception if an option is not supported
+   */
+  public void setOptions(String[] options) throws Exception {
+
+    String dirName = Utils.getOption('l', options);
+    if (dirName.length() > 0) {
+      setDirName(dirName);
+    } else {
+      setDirName(null);
+      throw new Exception("Name of directory required argument.");
+    }
+    String modelName = Utils.getOption('m', options);
+    if (modelName.length() > 0) {
+      setModelName(modelName);
+    } else {
+      setModelName(null);
+      throw new Exception("Name of model required argument.");
+    }
+    String encoding = Utils.getOption('e', options);
+    if (encoding.length() > 0) {
+      setEncoding(encoding);
+    } else {
+      setEncoding("default");
+    }
+    String numPhrases = Utils.getOption('n', options);
+    if (numPhrases.length() > 0) {
+      setNumPhrases(Integer.parseInt(numPhrases));
+    } else {
+      setNumPhrases(5);
+    }
+    setDebug(Utils.getFlag('d', options));
+    setAdditionalInfo(Utils.getFlag('a', options));
+    Utils.checkForRemainingOptions(options);
+   }
+
+  /**
+   * Gets the current option settings.
+   *
+   * @return an array of strings suitable for passing to setOptions
+   */
+  public String [] getOptions() {
+
+    String [] options = new String [10];
+    int current = 0;
+
+    options[current++] = "-l"; 
+    options[current++] = "" + (getDirName());
+    options[current++] = "-m"; 
+    options[current++] = "" + (getModelName());
+    options[current++] = "-e"; 
+    options[current++] = "" + (getEncoding());
+    options[current++] = "-n"; 
+    options[current++] = "" + (getNumPhrases());
+    if (getDebug()) {
+      options[current++] = "-d";
+    }
+    if (getAdditionalInfo()) {
+      options[current++] = "-a";
+    }
+
+    while (current < options.length) {
+      options[current++] = "";
+    }
+    return options;
+  }
+
+  /**
+   * Returns an enumeration describing the available options.
+   *
+   * @return an enumeration of all the available options
+   */
+  public Enumeration listOptions() {
+
+    Vector newVector = new Vector(6);
+
+    newVector.addElement(new Option(
+	      "\tSpecifies name of directory.",
+              "l", 1, "-l <directory name>"));
+    newVector.addElement(new Option(
+	      "\tSpecifies name of model.",
+              "m", 1, "-m <model name>"));
+    newVector.addElement(new Option(
+	      "\tSpecifies encoding.",
+              "e", 1, "-e <encoding>"));
+    newVector.addElement(new Option(
+	      "\tSpecifies number of phrases to be output (default: 5).",
+              "n", 1, "-n"));
+    newVector.addElement(new Option(
+	      "\tTurns debugging mode on.",
+              "d", 0, "-d"));
+    newVector.addElement(new Option(
+	      "\tAlso write stemmed phrase and score into \".key\" file.",
+              "a", 0, "-a"));
+
+    return newVector.elements();
+  }
+
+  /**
+   * Collects the stems of the file names.
+   */
+  public Hashtable collectStems() throws Exception {
+
+    Hashtable stems = new Hashtable();
+
+    try {
+      File dir = new File(m_dirName);
+      String[] files = dir.list();
+      for (int i = 0; i < files.length; i++) {
+	if (files[i].endsWith(".txt")) {
+	  String stem = files[i].substring(0, files[i].length() - 4);
+	  if (!stems.containsKey(stem)) {
+	    stems.put(stem, new Double(0));
+	  }
+	}
+      }
+    } catch (Exception e) {
+      throw new Exception("Problem opening directory " + m_dirName);
+    }
+    return stems;
+  }
+
+  /**
+   * Builds the model from the files
+   */
+  public void extractKeyphrases(Hashtable stems) throws Exception {
+    
+    Vector stats = new Vector();
+
+    // Check whether there is actually any data
+    if (stems.size() == 0) {
+      throw new Exception("Couldn't find any data!");
+    }
+
+    FastVector atts = new FastVector(2);
+    atts.addElement(new Attribute("doc", null));
+    atts.addElement(new Attribute("keyphrases", null));
+    Instances data = new Instances("keyphrase_training_data", atts, 0);
+
+    // Extract keyphrases
+    Enumeration elem = stems.keys();
+    while (elem.hasMoreElements()) {
+      String str = (String)elem.nextElement();
+      double[] newInst = new double[2];
+      try {
+	File txt = new File(m_dirName + "/" + str + ".txt");
+	InputStreamReader is;
+	if (!m_encoding.equals("default")) {
+	  is = new InputStreamReader(new FileInputStream(txt), m_encoding);
+	} else {
+	  is = new InputStreamReader(new FileInputStream(txt));
+	}
+	StringBuffer txtStr = new StringBuffer();
+	int c;
+	while ((c = is.read()) != -1) {
+	  txtStr.append((char)c);
+	}
+	newInst[0] = (double)data.attribute(0).addStringValue(txtStr.toString());
+      } catch (Exception e) {
+	if (m_debug) {
+	  System.err.println("Can't read document " + str + ".txt");
+	}
+	newInst[0] = Instance.missingValue();
+      }
+      try {
+	File key = new File(m_dirName + "/" + str + ".key");
+	InputStreamReader is; 
+	if (!m_encoding.equals("default")) {
+	  is = new InputStreamReader(new FileInputStream(key), m_encoding);
+	} else {
+	  is = new InputStreamReader(new FileInputStream(key));
+	}
+	StringBuffer keyStr = new StringBuffer();
+	int c;
+	while ((c = is.read()) != -1) {
+	  keyStr.append((char)c);
+	}      
+	newInst[1] = (double)data.attribute(1).addStringValue(keyStr.toString());
+      } catch (Exception e) {
+	if (m_debug) {
+	  System.err.println("No keyphrases for stem " + str + ".");
+	}
+	newInst[1] = Instance.missingValue();
+      }
+      data.add(new Instance(1.0, newInst));
+      m_KEAFilter.input(data.instance(0));
+      data = data.stringFreeStructure();
+      if (m_debug) {
+	System.err.println("-- Document: " + str);
+      }
+      Instance[] topRankedInstances = new Instance[m_numPhrases];
+      Instance inst;
+      while ((inst = m_KEAFilter.output()) != null) {
+	int index = (int)inst.value(m_KEAFilter.getRankIndex()) - 1;
+	if (index < m_numPhrases) {
+	  topRankedInstances[index] = inst;
+	}
+      }
+      if (m_debug) {
+	System.err.println("-- Keyphrases and feature values:");
+      }
+      FileOutputStream out = null;
+      PrintWriter printer = null; 
+      File key = new File(m_dirName + "/" + str + ".key");
+      if (!key.exists()) {
+	out = new FileOutputStream(m_dirName + "/" + str + ".key");
+	if (!m_encoding.equals("default")) {
+	  printer = new PrintWriter(new OutputStreamWriter(out, m_encoding));
+	} else {
+	  printer = new PrintWriter(out);
+	}
+      }
+      double numExtracted = 0, numCorrect = 0;
+      for (int i = 0; i < m_numPhrases; i++) {
+	if (topRankedInstances[i] != null) {
+	  if (!topRankedInstances[i].
+	      isMissing(topRankedInstances[i].numAttributes() - 1)) {
+	    numExtracted += 1.0;
+	  }
+	  if ((int)topRankedInstances[i].
+	      value(topRankedInstances[i].numAttributes() - 1) == 
+	      topRankedInstances[i].
+	      attribute(topRankedInstances[i].numAttributes() - 1).
+	      indexOfValue("True")) {
+	    numCorrect += 1.0;
+	  }
+	  if (printer != null) {
+	    printer.print(topRankedInstances[i].
+			  stringValue(m_KEAFilter.getUnstemmedPhraseIndex()));
+	    if (m_AdditionalInfo) {
+	      printer.print("\t");
+	      printer.print(topRankedInstances[i].
+			  stringValue(m_KEAFilter.getStemmedPhraseIndex()));
+	      printer.print("\t");
+	      printer.print(Utils.
+			    doubleToString(topRankedInstances[i].
+					   value(m_KEAFilter.
+						 getProbabilityIndex()), 4));
+	    }
+	    printer.println();
+	  }
+	  if (m_debug) {
+	    System.err.println(topRankedInstances[i]);
+	  }
+	}
+      }
+      if (numExtracted > 0) {
+	if (m_debug) {
+	  System.err.println("-- " + numCorrect + " correct");
+	}
+	stats.addElement(new Double(numCorrect));
+      }
+      if (printer != null) {
+	printer.flush();
+	printer.close();
+	out.close();
+      }
+    }
+    double[] st = new double[stats.size()];
+    for (int i = 0; i < stats.size(); i++) {
+      st[i] = ((Double)stats.elementAt(i)).doubleValue();
+    }
+    double avg = Utils.mean(st);
+    double stdDev = Math.sqrt(Utils.variance(st));
+    System.err.println("Avg. number of correct keyphrases: " +
+		       Utils.doubleToString(avg, 2) + " +/- " + 
+		       Utils.doubleToString(stdDev, 2));
+    System.err.println("Based on " + stats.size() + " documents");
+    m_KEAFilter.batchFinished();
+  }
+  
+  /** 
+   * Loads the extraction model from the file.
+   */
+  public void loadModel() throws Exception {
+    
+    BufferedInputStream inStream =
+      new BufferedInputStream(new FileInputStream(m_modelName));
+    ObjectInputStream in = new ObjectInputStream(inStream);
+    m_KEAFilter = (KEAFilter)in.readObject();
+    in.close();
+  }
+  
+  /**
+   * The main method.  
+   */
+  public static void main(String[] ops) {
+    
+    KEAKeyphraseExtractor kmb = new KEAKeyphraseExtractor();
+    try {
+      kmb.setOptions(ops);
+      System.err.print("Extracting keyphrases with options: ");
+      String[] optionSettings = kmb.getOptions();
+      for (int i = 0; i < optionSettings.length; i++) {
+	System.err.print(optionSettings[i] + " ");
+      }
+      System.err.println();
+      kmb.loadModel();
+      kmb.extractKeyphrases(kmb.collectStems());
+    } catch (Exception e) {
+      e.printStackTrace();
+      System.err.println(e.getMessage());
+      System.err.println("\nOptions:\n");
+      Enumeration enum = kmb.listOptions();
+      while (enum.hasMoreElements()) {
+	Option option = (Option) enum.nextElement();
+	System.err.println(option.synopsis());
+	System.err.println(option.description());
+      }
+    }
+  }
+}
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAModelBuilder.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAModelBuilder.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAModelBuilder.java	(revision 16571)
@@ -0,0 +1,689 @@
+/*
+ *    KEAModelBuilder.java
+ *    Copyright (C) 2001 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import java.io.*;
+import java.util.*;
+import weka.core.*;
+import weka.filters.*;
+
+/**
+ * Builds a keyphrase extraction model from the documents in a given
+ * directory.  Assumes that the file names for the documents end with
+ * ".txt".  Assumes that files containing corresponding
+ * author-assigned keyphrases end with ".key". Optionally an encoding
+ * for the documents/keyphrases can be defined (e.g. for Chinese
+ * text).
+ *
+ * Valid options are:<p>
+ *
+ * -l "directory name"<br>
+ * Specifies name of directory.<p>
+ *
+ * -m "model name"<br>
+ * Specifies name of model.<p>
+ *
+ * -e "encoding"<br>
+ * Specifies encoding.<p>
+ *
+ * -d<br>
+ * Turns debugging mode on.<p>
+ *
+ * -k<br>
+ * Use keyphrase frequency statistic.<p>
+ *
+ * -p<br>
+ * Disallow internal periods.<p>
+ *
+ * -x "length"<br>
+ * Sets maximum phrase length (default: 3).<p>
+ *
+ * -y "length"<br>
+ * Sets minimum phrase length (default: 1).<p>
+ *
+ * -o "number"<br>
+ * The minimum number of times a phrase needs to occur (default: 2). <p>
+ *
+ * -s "name of class implementing list of stop words"<br>
+ * Sets list of stop words to used (default: StopwordsEnglish).<p>
+ *
+ * -t "name of class implementing stemmer"<br>
+ * Sets stemmer to use (default: IteratedLovinsStemmer). <p>
+ *
+ * -n<br>
+ * Do not check for proper nouns. <p>
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public class KEAModelBuilder implements OptionHandler {
+  
+  /** Name of directory */
+  String m_dirName = null;
+  
+  /** Name of model */
+  String m_modelName = null;
+
+  /** Encoding */
+  String m_encoding = "default";
+
+  /** Debugging mode? */
+  boolean m_debug = false;
+
+  /** Use keyphrase frequency attribute? */
+  boolean m_useKFrequency = false;
+
+  /** Disallow internal periods? */
+  boolean m_disallowIPeriods = false;
+
+  /** The maximum length of phrases */
+  private int m_MaxPhraseLength = 3;
+
+  /** The minimum length of phrases */
+  private int m_MinPhraseLength = 1;
+
+  /** The minimum number of occurences of a phrase */
+  private int m_MinNumOccur = 2;
+
+  /** The KEA filter object */
+  KEAFilter m_KEAFilter = null;
+
+  /** The stemmer to be used */
+  private Stemmer m_Stemmer = new IteratedLovinsStemmer();
+
+  /** The list of stop words to be used */
+  private Stopwords m_Stopwords = new StopwordsEnglish();
+
+  /** Determines whether check for proper nouns is performed */
+  private boolean m_CheckForProperNouns = true;
+
+  /**
+   * Get the M_CheckProperNouns value.
+   * @return the M_CheckProperNouns value.
+   */
+  public boolean getCheckForProperNouns() {
+    return m_CheckForProperNouns;
+  }
+
+  /**
+   * Set the M_CheckProperNouns value.
+   * @param newM_CheckProperNouns The new M_CheckProperNouns value.
+   */
+  public void setCheckForProperNouns(boolean newM_CheckProperNouns) {
+    this.m_CheckForProperNouns = newM_CheckProperNouns;
+  }
+
+  /**
+   * Get the M_Stopwords value.
+   * @return the M_Stopwords value.
+   */
+  public Stopwords getStopwords() {
+
+    return m_Stopwords;
+  }
+
+  /**
+   * Set the M_Stopwords value.
+   * @param newM_Stopwords The new M_Stopwords value.
+   */
+  public void setStopwords(Stopwords newM_Stopwords) {
+
+    this.m_Stopwords = newM_Stopwords;
+  }
+
+  
+  /**
+   * Get the Stemmer value.
+   * @return the Stemmer value.
+   */
+  public Stemmer getStemmer() {
+
+    return m_Stemmer;
+  }
+
+  /**
+   * Set the Stemmer value.
+   * @param newStemmer The new Stemmer value.
+   */
+  public void setStemmer(Stemmer newStemmer) {
+
+    this.m_Stemmer = newStemmer;
+  }
+  
+  /**
+   * Get the value of MinNumOccur.
+   *
+   * @return Value of MinNumOccur.
+   */
+  public int getMinNumOccur() {
+    
+    return m_MinNumOccur;
+  }
+  
+  /**
+   * Set the value of MinNumOccur.
+   *
+   * @param newMinNumOccur Value to assign to MinNumOccur.
+   */
+  public void setMinNumOccur(int newMinNumOccur) {
+    
+    m_MinNumOccur = newMinNumOccur;
+  }
+  
+  /**
+   * Get the value of MaxPhraseLength.
+   *
+   * @return Value of MaxPhraseLength.
+   */
+  public int getMaxPhraseLength() {
+    
+    return m_MaxPhraseLength;
+  }
+  
+  /**
+   * Set the value of MaxPhraseLength.
+   *
+   * @param newMaxPhraseLength Value to assign to MaxPhraseLength.
+   */
+  public void setMaxPhraseLength(int newMaxPhraseLength) {
+    
+    m_MaxPhraseLength = newMaxPhraseLength;
+  }
+  
+  /**
+   * Get the value of MinPhraseLength.
+   *
+   * @return Value of MinPhraseLength.
+   */
+  public int getMinPhraseLength() {
+    
+    return m_MinPhraseLength;
+  }
+  
+  /**
+   * Set the value of MinPhraseLength.
+   *
+   * @param newMinPhraseLength Value to assign to MinPhraseLength.
+   */
+  public void setMinPhraseLength(int newMinPhraseLength) {
+    
+    m_MinPhraseLength = newMinPhraseLength;
+  }
+  
+  /**
+   * Get the value of disallowIPeriods.
+   *
+   * @return Value of disallowIPeriods.
+   */
+  public boolean getDisallowIPeriods() {
+    
+    return m_disallowIPeriods;
+  }
+  
+  /**
+   * Set the value of disallowIPeriods.
+   *
+   * @param newdisallowIPeriods Value to assign to disallowIPeriods.
+   */
+  public void setDisallowIPeriods(boolean newdisallowIPeriods) {
+    
+    m_disallowIPeriods = newdisallowIPeriods;
+  }
+  
+  /**
+   * Get the value of useKFrequency.
+   *
+   * @return Value of useKFrequency.
+   */
+  public boolean getUseKFrequency() {
+    
+    return m_useKFrequency;
+  }
+  
+  /**
+   * Set the value of useKFrequency.
+   *
+   * @param newuseKFrequency Value to assign to useKFrequency.
+   */
+  public void setUseKFrequency(boolean newuseKFrequency) {
+    
+    m_useKFrequency = newuseKFrequency;
+  }
+  
+  /**
+   * Get the value of debug.
+   *
+   * @return Value of debug.
+   */
+  public boolean getDebug() {
+    
+    return m_debug;
+  }
+  
+  /**
+   * Set the value of debug.
+   *
+   * @param newdebug Value to assign to debug.
+   */
+  public void setDebug(boolean newdebug) {
+    
+    m_debug = newdebug;
+  }
+  
+  /**
+   * Get the value of encoding.
+   *
+   * @return Value of encoding.
+   */
+  public String getEncoding() {
+    
+    return m_encoding;
+  }
+  
+  /**
+   * Set the value of encoding.
+   *
+   * @param newencoding Value to assign to encoding.
+   */
+  public void setEncoding(String newencoding) {
+    
+    m_encoding = newencoding;
+  }
+  
+  /**
+   * Get the value of modelName.
+   *
+   * @return Value of modelName.
+   */
+  public String getModelName() {
+    
+    return m_modelName;
+  }
+  
+  /**
+   * Set the value of modelName.
+   *
+   * @param newmodelName Value to assign to modelName.
+   */
+  public void setModelName(String newmodelName) {
+    
+    m_modelName = newmodelName;
+  }
+  
+  /**
+   * Get the value of dirName.
+   *
+   * @return Value of dirName.
+   */
+  public String getDirName() {
+    
+    return m_dirName;
+  }
+  
+  /**
+   * Set the value of dirName.
+   *
+   * @param newdirName Value to assign to dirName.
+   */
+  public void setDirName(String newdirName) {
+    
+    m_dirName = newdirName;
+  }
+  
+  /**
+   * Parses a given list of options controlling the behaviour of this object.
+   * Valid options are:<p>
+   *
+   * -l "directory name" <br>
+   * Specifies name of directory.<p>
+   *
+   * -m "model name" <br>
+   * Specifies name of model.<p>
+   *
+   * -e "encoding" <br>
+   * Specifies encoding.<p>
+   *
+   * -d<br>
+   * Turns debugging mode on.<p>
+   *
+   * -k<br>
+   * Use keyphrase frequency statistic.<p>
+   *
+   * -p<br>
+   * Disallow internal periods. <p>
+   *
+   * -x "length"<br>
+   * Sets maximum phrase length (default: 3).<p>
+   *
+   * -y "length"<br>
+   * Sets minimum phrase length (default: 3).<p>
+   *
+   * -o "number"<br>
+   * The minimum number of times a phrase needs to occur (default: 2). <p>
+   *
+   * -s "name of class implementing list of stop words"<br>
+   * Sets list of stop words to used (default: StopwordsEnglish).<p>
+   *
+   * -t "name of class implementing stemmer"<br>
+   * Sets stemmer to use (default: IteratedLovinsStemmer). <p>
+   *
+   * -n<br>
+   * Do not check for proper nouns. <p>
+   *
+   * @param options the list of options as an array of strings
+   * @exception Exception if an option is not supported
+   */
+  public void setOptions(String[] options) throws Exception {
+
+    String dirName = Utils.getOption('l', options);
+    if (dirName.length() > 0) {
+      setDirName(dirName);
+    } else {
+      setDirName(null);
+      throw new Exception("Name of directory required argument.");
+    }
+    String modelName = Utils.getOption('m', options);
+    if (modelName.length() > 0) {
+      setModelName(modelName);
+    } else {
+      setModelName(null);
+      throw new Exception("Name of model required argument.");
+    }
+    String encoding = Utils.getOption('e', options);
+    if (encoding.length() > 0) {
+      setEncoding(encoding);
+    } else {
+      setEncoding("default");
+    }
+    String maxPhraseLengthString = Utils.getOption('x', options);
+    if (maxPhraseLengthString.length() > 0) {
+      setMaxPhraseLength(Integer.parseInt(maxPhraseLengthString));
+    } else {
+      setMaxPhraseLength(3);
+    }
+    String minPhraseLengthString = Utils.getOption('y', options);
+    if (minPhraseLengthString.length() > 0) {
+      setMinPhraseLength(Integer.parseInt(minPhraseLengthString));
+    } else {
+      setMinPhraseLength(1);
+    }
+    String minNumOccurString = Utils.getOption('o', options);
+    if (minNumOccurString.length() > 0) {
+      setMinNumOccur(Integer.parseInt(minNumOccurString));
+    } else {
+      setMinNumOccur(2);
+    }
+    String stopwordsString = Utils.getOption('s', options);
+    if (stopwordsString.length() > 0) {
+      setStopwords((Stopwords)Class.forName(stopwordsString).newInstance());
+    }
+    String stemmerString = Utils.getOption('t', options);
+    if (stemmerString.length() > 0) {
+      setStemmer((Stemmer)Class.forName(stemmerString).newInstance());
+    }
+    setDebug(Utils.getFlag('d', options));
+    setUseKFrequency(Utils.getFlag('k', options));
+    setDisallowIPeriods(Utils.getFlag('p', options));
+    setCheckForProperNouns(!Utils.getFlag('n', options));
+    Utils.checkForRemainingOptions(options);
+   }
+
+  /**
+   * Gets the current option settings.
+   *
+   * @return an array of strings suitable for passing to setOptions
+   */
+  public String [] getOptions() {
+
+    String [] options = new String [20];
+    int current = 0;
+
+    options[current++] = "-l"; 
+    options[current++] = "" + (getDirName());
+    options[current++] = "-m"; 
+    options[current++] = "" + (getModelName());
+    options[current++] = "-e"; 
+    options[current++] = "" + (getEncoding());
+    if (getUseKFrequency()) {
+      options[current++] = "-k";
+    }
+    if (getDebug()) {
+      options[current++] = "-d";
+    }
+    if (getDisallowIPeriods()) {
+      options[current++] = "-p";
+    }
+    options[current++] = "-x"; 
+    options[current++] = "" + (getMaxPhraseLength());
+    options[current++] = "-y"; 
+    options[current++] = "" + (getMinPhraseLength());
+    options[current++] = "-o"; 
+    options[current++] = "" + (getMinNumOccur());
+    options[current++] = "-s"; 
+    options[current++] = "" + (getStopwords().getClass().getName());
+    options[current++] = "-t"; 
+    options[current++] = "" + (getStemmer().getClass().getName());
+    if (getCheckForProperNouns()) {
+      options[current++] = "-n";
+    }
+
+    while (current < options.length) {
+      options[current++] = "";
+    }
+    return options;
+  }
+
+  /**
+   * Returns an enumeration describing the available options.
+   *
+   * @return an enumeration of all the available options
+   */
+  public Enumeration listOptions() {
+
+    Vector newVector = new Vector(12);
+
+    newVector.addElement(new Option(
+	      "\tSpecifies name of directory.",
+              "l", 1, "-l <directory name>"));
+    newVector.addElement(new Option(
+	      "\tSpecifies name of model.",
+              "m", 1, "-m <model name>"));
+    newVector.addElement(new Option(
+	      "\tSpecifies encoding.",
+              "e", 1, "-e <encoding>"));
+    newVector.addElement(new Option(
+	      "\tTurns debugging mode on.",
+              "d", 0, "-d"));
+    newVector.addElement(new Option(
+	      "\tUse keyphrase frequency statistic.",
+              "k", 0, "-k"));
+    newVector.addElement(new Option(
+	      "\tDisallow internal periods.",
+              "p", 0, "-p"));
+    newVector.addElement(new Option(
+	      "\tSets the maximum phrase length (default: 3).",
+              "x", 1, "-x <length>"));
+    newVector.addElement(new Option(
+	      "\tSets the minimum phrase length (default: 1).",
+              "y", 1, "-y <length>"));
+    newVector.addElement(new Option(
+	      "\tSet the minimum number of occurences (default: 2).",
+              "o", 1, "-o"));
+    newVector.addElement(new Option(
+	      "\tSets the list of stopwords to use (default: StopwordsEnglish).",
+              "s", 1, "-s <name of stopwords class>"));
+    newVector.addElement(new Option(
+	      "\tSet the stemmer to use (default: IteratedLovinsStemmer).",
+              "t", 1, "-t <name of stemmer class>"));
+    newVector.addElement(new Option(
+	      "\tDo not check for proper nouns.",
+              "n", 0, "-n"));
+ 
+    return newVector.elements();
+  }
+
+  /**
+   * Collects the stems of the file names.
+   */
+  public Hashtable collectStems() throws Exception {
+
+    Hashtable stems = new Hashtable();
+
+    try {
+      File dir = new File(m_dirName);
+      String[] files = dir.list();
+      for (int i = 0; i < files.length; i++) {
+	if (files[i].endsWith(".key") ||
+	    files[i].endsWith(".txt")) {
+	  String stem = files[i].substring(0, files[i].length() - 4);
+	  if (!stems.containsKey(stem)) {
+	    stems.put(stem, new Double(0));
+	  }
+	}
+      }
+    } catch (Exception e) {
+      throw new Exception("Problem opening directory " + m_dirName);
+    }
+    return stems;
+  }
+
+  /**
+   * Builds the model from the files
+   */
+  public void buildModel(Hashtable stems) throws Exception {
+    
+    // Check whether there is actually any data
+    if (stems.size() == 0) {
+      throw new Exception("Couldn't find any data!");
+    }
+
+    FastVector atts = new FastVector(2);
+    atts.addElement(new Attribute("doc", null));
+    atts.addElement(new Attribute("keyphrases", null));
+    Instances data = new Instances("keyphrase_training_data", atts, 0);
+
+    // Build model
+    m_KEAFilter = new KEAFilter();
+    m_KEAFilter.setDebug(m_debug);
+    m_KEAFilter.setDisallowInternalPeriods(getDisallowIPeriods());
+    m_KEAFilter.setKFused(getUseKFrequency());
+    m_KEAFilter.setMaxPhraseLength(getMaxPhraseLength());
+    m_KEAFilter.setMinPhraseLength(getMinPhraseLength());
+    m_KEAFilter.setMinNumOccur(getMinNumOccur());
+    m_KEAFilter.setInputFormat(data);
+    m_KEAFilter.setStemmer(getStemmer());
+    m_KEAFilter.setStopwords(getStopwords());
+    m_KEAFilter.setCheckForProperNouns(getCheckForProperNouns());
+    Enumeration elem = stems.keys();
+    while (elem.hasMoreElements()) {
+      String str = (String)elem.nextElement();
+      double[] newInst = new double[2];
+      try {
+	File txt = new File(m_dirName + "/" + str + ".txt");
+	InputStreamReader is;
+	if (!m_encoding.equals("default")) {
+	  is = new InputStreamReader(new FileInputStream(txt), m_encoding);
+	} else {
+	  is = new InputStreamReader(new FileInputStream(txt));
+	}
+	StringBuffer txtStr = new StringBuffer();
+	int c;
+	while ((c = is.read()) != -1) {
+	  txtStr.append((char)c);
+	}
+	newInst[0] = (double)data.attribute(0).addStringValue(txtStr.toString());
+      } catch (Exception e) {
+	if (m_debug) {
+	  System.err.println("Can't find document for stem " + str + ".");
+	}
+	newInst[0] = Instance.missingValue();
+      }
+      try {
+	File key = new File(m_dirName + "/" + str + ".key");
+	InputStreamReader is; 
+	if (!m_encoding.equals("default")) {
+	  is = new InputStreamReader(new FileInputStream(key), m_encoding);
+	} else {
+	  is = new InputStreamReader(new FileInputStream(key));
+	}
+	StringBuffer keyStr = new StringBuffer();
+	int c;
+	while ((c = is.read()) != -1) {
+	  keyStr.append((char)c);
+	}      
+	newInst[1] = (double)data.attribute(1).addStringValue(keyStr.toString());
+      } catch (Exception e) {
+	if (m_debug) {
+	  System.err.println("Can't find keyphrases for stem " + str + ".");
+	}
+	newInst[1] = Instance.missingValue();
+      }
+      data.add(new Instance(1.0, newInst));
+      m_KEAFilter.input(data.instance(0));
+      data = data.stringFreeStructure();
+    }
+    m_KEAFilter.batchFinished();
+    
+    // Get rid of instances in filter
+    Instance dummy;
+    while ((dummy = m_KEAFilter.output()) != null) {};
+  }
+  
+  /** 
+   * Saves the extraction model to the file.
+   */
+  public void saveModel() throws Exception {
+    
+    BufferedOutputStream bufferedOut = 
+      new BufferedOutputStream(new FileOutputStream(m_modelName));
+    ObjectOutputStream out = new ObjectOutputStream(bufferedOut);
+    out.writeObject(m_KEAFilter);
+    out.flush();
+    out.close();
+  }
+  
+  /**
+   * The main method.  
+   */
+  public static void main(String[] ops) {
+    
+    KEAModelBuilder kmb = new KEAModelBuilder();
+    try {
+      kmb.setOptions(ops);
+      System.err.print("Building model with options: ");
+      String[] optionSettings = kmb.getOptions();
+      for (int i = 0; i < optionSettings.length; i++) {
+	System.err.print(optionSettings[i] + " ");
+      }
+      System.err.println();
+      kmb.buildModel(kmb.collectStems());
+      kmb.saveModel();
+    } catch (Exception e) {
+      e.printStackTrace();
+      System.err.println(e.getMessage());
+      System.err.println("\nOptions:\n");
+      Enumeration enum = kmb.listOptions();
+      while (enum.hasMoreElements()) {
+	Option option = (Option) enum.nextElement();
+	System.err.println(option.synopsis());
+	System.err.println(option.description());
+      }
+    }
+  }
+}
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAPhraseFilter.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAPhraseFilter.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/KEAPhraseFilter.java	(revision 16571)
@@ -0,0 +1,487 @@
+/*
+ *    KEAPhraseFilter.java
+ *    Copyright (C) 2001 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import java.util.*;
+
+import weka.core.*;
+import weka.filters.*;
+
+/**
+ * This filter splits the text in selected string
+ * attributes into phrases. The resulting
+ * string attributes contain these phrases
+ * separated by '\n' characters.
+ *
+ * Phrases are identified according to the
+ * following definitions:
+ * 
+ * A phrase is a sequence of words interrupted
+ * only by sequences of whitespace characters,
+ * where each sequence of whitespace characters
+ * contains at most one '\n'.
+ *
+ * A word is a sequence of letters or digits
+ * that contains at least one letter, with
+ * the following exceptions:
+ *
+ * a) '.', '@', '_', '&', '/', '-' are allowed
+ * if surrounded by letters or digits,
+ *
+ * b) '\'' is allowed if preceeded by a letter
+ * or digit,
+ * 
+ * c) '-', '/' are also allowed if succeeded by
+ * whitespace characters followed by another
+ * word. In that case the whitespace characters
+ * will be deleted.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public class KEAPhraseFilter extends Filter implements OptionHandler {
+
+  /** Stores which columns to select as a funky range */
+  protected Range m_SelectCols = new Range();
+
+  /** Determines whether internal periods are allowed */
+  protected boolean m_DisallowInternalPeriods = false;
+
+  /**
+   * Returns a string describing this filter
+   *
+   * @return a description of the filter suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String globalInfo() {
+    return "This filter splits the text contained " +
+      "by the selected string attributes into phrases.";
+  }
+
+  /**
+   * Returns an enumeration describing the available options
+   *
+   * @return an enumeration of all the available options
+   */
+  public Enumeration listOptions() {
+
+    Vector newVector = new Vector(3);
+
+    newVector.addElement(new Option(
+              "\tSpecify list of attributes to process. First and last are valid\n"
+	      +"\tindexes. (default none)",
+              "R", 1, "-R <index1,index2-index4,...>"));
+    newVector.addElement(new Option(
+	      "\tInvert matching sense",
+              "V", 0, "-V"));
+    newVector.addElement(new Option(
+	      "\tDisallow internal periods",
+              "P", 0, "-P"));
+
+    return newVector.elements();
+  }
+
+  /**
+   * Parses a given list of options controlling the behaviour of this object.
+   * Valid options are:<p>
+   *
+   * -R index1,index2-index4,...<br>
+   * Specify list of attributes to process. First and last are valid indexes.
+   * (default none)<p>
+   *
+   * -V<br>
+   * Invert matching sense <p>
+   *
+   * -P<br>
+   * Disallow internal periods <p>
+   *
+   * @param options the list of options as an array of strings
+   * @exception Exception if an option is not supported
+   */
+  public void setOptions(String[] options) throws Exception {
+
+    String list = Utils.getOption('R', options);
+    if (list.length() != 0) {
+      setAttributeIndices(list);
+    }
+    setInvertSelection(Utils.getFlag('V', options));
+
+    setDisallowInternalPeriods(Utils.getFlag('P', options));
+    
+    if (getInputFormat() != null) {
+      setInputFormat(getInputFormat());
+    }
+  }
+
+  /**
+   * Gets the current settings of the filter.
+   *
+   * @return an array of strings suitable for passing to setOptions
+   */
+  public String [] getOptions() {
+
+    String [] options = new String [4];
+    int current = 0;
+
+    if (getInvertSelection()) {
+      options[current++] = "-V";
+    }
+    if (getDisallowInternalPeriods()) {
+      options[current++] = "-P";
+    }
+    if (!getAttributeIndices().equals("")) {
+      options[current++] = "-R"; options[current++] = getAttributeIndices();
+    }
+
+    while (current < options.length) {
+      options[current++] = "";
+    }
+    return options;
+  }
+
+  /**
+   * Sets the format of the input instances.
+   *
+   * @param instanceInfo an Instances object containing the input
+   * instance structure (any instances contained in the object are
+   * ignored - only the structure is required).
+   * @return true if the outputFormat may be collected immediately 
+   */
+  public boolean setInputFormat(Instances instanceInfo) throws Exception {
+
+    super.setInputFormat(instanceInfo);
+    setOutputFormat(instanceInfo);
+    m_SelectCols.setUpper(instanceInfo.numAttributes() - 1);
+
+    return true;
+  }
+
+  /**
+   * Input an instance for filtering. Ordinarily the instance is processed
+   * and made available for output immediately. Some filters require all
+   * instances be read before producing output.
+   *
+   * @param instance the input instance
+   * @return true if the filtered instance may now be
+   * collected with output().
+   * @exception Exception if the input instance was not of the correct 
+   * format or if there was a problem with the filtering.
+   */
+  public boolean input(Instance instance) throws Exception {
+
+    if (getInputFormat() == null) {
+      throw new Exception("No input instance format defined");
+    }
+    if (m_NewBatch) {
+      resetQueue();
+      m_NewBatch = false;
+    }
+    convertInstance(instance);
+    return true;
+  }
+
+  /**
+   * Signify that this batch of input to the filter is finished. If
+   * the filter requires all instances prior to filtering, output()
+   * may now be called to retrieve the filtered instances. Any
+   * subsequent instances filtered should be filtered based on setting
+   * obtained from the first batch (unless the inputFormat has been
+   * re-assigned or new options have been set). This default
+   * implementation assumes all instance processing occurs during
+   * inputFormat() and input().
+   *
+   * @return true if there are instances pending output
+   * @exception NullPointerException if no input structure has been defined,
+   * @exception Exception if there was a problem finishing the batch.
+   */
+  public boolean batchFinished() throws Exception {
+
+    if (getInputFormat() == null) {
+      throw new NullPointerException("No input instance format defined");
+    }
+    m_NewBatch = true;
+    return (numPendingOutput() != 0);
+  }
+
+  /**
+   * Main method for testing this class.
+   *
+   * @param argv should contain arguments to the filter: use -h for help
+   */
+  public static void main(String [] argv) {
+    
+    try {
+      if (Utils.getFlag('b', argv)) {
+	Filter.batchFilterFile(new KEAPhraseFilter(), argv);
+      } else {
+	Filter.filterFile(new KEAPhraseFilter(), argv);
+      }
+    } catch (Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+  }
+ 
+  /** 
+   * Converts an instance by removing all non-alphanumeric characters
+   * from its string attribute values.
+   */
+  private void convertInstance(Instance instance) throws Exception {
+  
+    double[] instVals = new double[instance.numAttributes()];
+
+    for (int i = 0; i < instance.numAttributes(); i++) {
+      if (!instance.attribute(i).isString() || 
+	  instance.isMissing(i)) {
+	instVals[i] = instance.value(i);
+      } else {
+	if (!m_SelectCols.isInRange(i)) {
+	  int index = getOutputFormat().attribute(i).
+	    addStringValue(instance.stringValue(i));
+	  instVals[i] = (double)index;
+	  continue;
+	}
+	String str = instance.stringValue(i);
+	StringBuffer resultStr = new StringBuffer();
+	int j = 0;
+	boolean phraseStart = true;
+	boolean seenNewLine = false;
+	boolean haveSeenHyphen = false;
+	boolean haveSeenSlash = false;
+	while (j < str.length()) {
+	  boolean isWord = false;
+	  boolean potNumber = false;
+	  int startj = j;
+	  while (j < str.length()) {
+	    char ch = str.charAt(j);
+	    if (Character.isLetterOrDigit(ch)) {
+	      potNumber = true;
+	      if (Character.isLetter(ch)) {
+		isWord = true;
+	      }
+	      j++;
+	    } else if ((!m_DisallowInternalPeriods && (ch == '.')) ||
+		       (ch == '@') ||
+		       (ch == '_') ||
+		       (ch == '&') ||
+		       (ch == '/') ||
+		       (ch == '-')) {
+	      if ((j > 0) && (j  + 1 < str.length()) &&
+		  Character.isLetterOrDigit(str.charAt(j - 1)) &&
+		  Character.isLetterOrDigit(str.charAt(j + 1))) {
+		j++;
+	      } else {
+		break;
+	      }
+	    } else if (ch == '\'') {
+	      if ((j > 0) &&
+		  Character.isLetterOrDigit(str.charAt(j - 1))) {
+		j++;
+	      } else {
+		break;
+	      }
+	    } else {
+	      break;
+	    }
+	  }
+	  if (isWord == true) {
+	    if (!phraseStart) {
+	      if (haveSeenHyphen) {
+		resultStr.append('-');
+	      } else if (haveSeenSlash) {
+		resultStr.append('/');
+	      } else {
+		resultStr.append(' ');
+	      }
+	    }
+	    resultStr.append(str.substring(startj, j));
+	    if (j == str.length()) {
+	      break;
+	    }
+	    phraseStart = false;
+	    seenNewLine = false;
+	    haveSeenHyphen = false;
+	    haveSeenSlash = false;
+	    if (Character.isWhitespace(str.charAt(j))) {
+	      if (str.charAt(j) == '\n') {
+		seenNewLine = true;
+	      } 
+	    } else if (str.charAt(j) == '-') {
+	      haveSeenHyphen = true;
+	    } else if (str.charAt(j) == '/') {
+	      haveSeenSlash = true;
+	    } else {
+	      phraseStart = true;
+	      resultStr.append('\n');
+	    }
+	    j++;
+	  } else if (j == str.length()) {
+	    break;
+	  } else if (str.charAt(j) == '\n') {
+	    if (seenNewLine) {
+	      if (phraseStart == false) {
+		resultStr.append('\n');
+		phraseStart = true;
+	      }
+	    } else if (potNumber) {
+	      if (phraseStart == false) {
+		phraseStart = true;
+		resultStr.append('\n');
+	      }
+	    }
+	    seenNewLine = true;
+	    j++;
+	  } else if (Character.isWhitespace(str.charAt(j))) {
+	    if (potNumber) {
+	      if (phraseStart == false) {
+		phraseStart = true;
+		resultStr.append('\n');
+	      }
+	    }
+	    j++;
+	  } else {
+	    if (phraseStart == false) {
+	      resultStr.append('\n');
+	      phraseStart = true;
+	    }
+	    j++;
+	  }
+	}
+	int index = getOutputFormat().attribute(i).
+	  addStringValue(resultStr.toString());
+	instVals[i] = (double)index;
+      }
+    }
+    Instance inst = new Instance(instance.weight(), instVals);
+    inst.setDataset(getOutputFormat());
+    push(inst);
+  }
+
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String invertSelectionTipText() {
+
+    return "If set to false, the specified attributes will be processed;"
+      + " If set to true, specified attributes won't be processed.";
+  }
+
+  /**
+   * Get whether the supplied columns are to be processed
+   *
+   * @return true if the supplied columns won't be processed
+   */
+  public boolean getInvertSelection() {
+
+    return m_SelectCols.getInvert();
+  }
+
+  /**
+   * Set whether selected columns should be processed. If true the 
+   * selected columns won't be processed.
+   *
+   * @param invert the new invert setting
+   */
+  public void setInvertSelection(boolean invert) {
+
+    m_SelectCols.setInvert(invert);
+  }
+
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String disallowInternalPeriodsTipText() {
+
+    return "If set to false, internal periods are allowed.";
+  }
+
+  /**
+   * Get whether the supplied columns are to be processed
+   *
+   * @return true if the supplied columns won't be processed
+   */
+  public boolean getDisallowInternalPeriods() {
+
+    return m_DisallowInternalPeriods;
+  }
+
+  /**
+   * Set whether selected columns should be processed. If true the 
+   * selected columns won't be processed.
+   *
+   * @param invert the new invert setting
+   */
+  public void setDisallowInternalPeriods(boolean disallow) {
+
+    m_DisallowInternalPeriods = disallow;
+  }
+
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String attributeIndicesTipText() {
+
+    return "Specify range of attributes to act on."
+      + " This is a comma separated list of attribute indices, with"
+      + " \"first\" and \"last\" valid values. Specify an inclusive"
+      + " range with \"-\". E.g: \"first-3,5,6-10,last\".";
+  }
+
+  /**
+   * Get the current range selection.
+   *
+   * @return a string containing a comma separated list of ranges
+   */
+  public String getAttributeIndices() {
+
+    return m_SelectCols.getRanges();
+  }
+
+  /**
+   * Set which attributes are to be processed
+   *
+   * @param rangeList a string representing the list of attributes.  Since
+   * the string will typically come from a user, attributes are indexed from
+   * 1. <br>
+   * eg: first-3,5,6-last
+   */
+  public void setAttributeIndices(String rangeList) {
+
+    m_SelectCols.setRanges(rangeList);
+  }
+
+  /**
+   * Set which attributes are to be processed
+   *
+   * @param attributes an array containing indexes of attributes to select.
+   * Since the array will typically come from a program, attributes are indexed
+   * from 0.
+   */
+  public void setAttributeIndicesArray(int [] attributes) {
+    
+    setAttributeIndices(Range.indicesToRangeList(attributes));
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/LovinsStemmer.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/LovinsStemmer.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/LovinsStemmer.java	(revision 16571)
@@ -0,0 +1,890 @@
+/*
+ *    LovinsStemmer.java
+ *    Copyright (C) 2001 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import java.util.*;
+import java.io.*;
+
+/** 
+ * Implements the Lovins stemmer.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public class LovinsStemmer extends Stemmer implements Serializable {
+
+  /** C version compatibility mode (emulates bugs
+      in original C implementation) */
+  private static boolean m_CompMode = true;
+
+  /** The hash tables containing the list of endings. */
+  private static HashMap m_l11 = null;
+  private static HashMap m_l10 = null;
+  private static HashMap m_l9 = null;
+  private static HashMap m_l8 = null;
+  private static HashMap m_l7 = null;
+  private static HashMap m_l6 = null;
+  private static HashMap m_l5 = null;
+  private static HashMap m_l4 = null;
+  private static HashMap m_l3 = null;
+  private static HashMap m_l2 = null;
+  private static HashMap m_l1 = null;
+
+  static {
+
+    m_l11 = new HashMap();
+    m_l11.put("alistically", "B");
+    m_l11.put("arizability", "A");
+    m_l11.put("izationally", "B");
+    m_l10 = new HashMap();
+    m_l10.put("antialness", "A");
+    m_l10.put("arisations", "A");
+    m_l10.put("arizations", "A");
+    m_l10.put("entialness", "A");
+    m_l9 = new HashMap();
+    m_l9.put("allically", "C");
+    m_l9.put("antaneous", "A");
+    m_l9.put("antiality", "A");
+    m_l9.put("arisation", "A");
+    m_l9.put("arization", "A");
+    m_l9.put("ationally", "B");
+    m_l9.put("ativeness", "A");
+    m_l9.put("eableness", "E");
+    m_l9.put("entations", "A");
+    m_l9.put("entiality", "A");
+    m_l9.put("entialize", "A");
+    m_l9.put("entiation", "A");
+    m_l9.put("ionalness", "A");
+    m_l9.put("istically", "A");
+    m_l9.put("itousness", "A");
+    m_l9.put("izability", "A");
+    m_l9.put("izational", "A");
+    m_l8 = new HashMap();
+    m_l8.put("ableness", "A");
+    m_l8.put("arizable", "A");
+    m_l8.put("entation", "A");
+    m_l8.put("entially", "A");
+    m_l8.put("eousness", "A");
+    m_l8.put("ibleness", "A");
+    m_l8.put("icalness", "A");
+    m_l8.put("ionalism", "A");
+    m_l8.put("ionality", "A");
+    m_l8.put("ionalize", "A");
+    m_l8.put("iousness", "A");
+    m_l8.put("izations", "A");
+    m_l8.put("lessness", "A");
+    m_l7 = new HashMap();
+    m_l7.put("ability", "A");
+    m_l7.put("aically", "A");
+    m_l7.put("alistic", "B");
+    m_l7.put("alities", "A");
+    m_l7.put("ariness", "E");
+    m_l7.put("aristic", "A");
+    m_l7.put("arizing", "A");
+    m_l7.put("ateness", "A");
+    m_l7.put("atingly", "A");
+    m_l7.put("ational", "B");
+    m_l7.put("atively", "A");
+    m_l7.put("ativism", "A");
+    m_l7.put("elihood", "E");
+    m_l7.put("encible", "A");
+    m_l7.put("entally", "A");
+    m_l7.put("entials", "A");
+    m_l7.put("entiate", "A");
+    m_l7.put("entness", "A");
+    m_l7.put("fulness", "A");
+    m_l7.put("ibility", "A");
+    m_l7.put("icalism", "A");
+    m_l7.put("icalist", "A");
+    m_l7.put("icality", "A");
+    m_l7.put("icalize", "A");
+    m_l7.put("ication", "G");
+    m_l7.put("icianry", "A");
+    m_l7.put("ination", "A");
+    m_l7.put("ingness", "A");
+    m_l7.put("ionally", "A");
+    m_l7.put("isation", "A");
+    m_l7.put("ishness", "A");
+    m_l7.put("istical", "A");
+    m_l7.put("iteness", "A");
+    m_l7.put("iveness", "A");
+    m_l7.put("ivistic", "A");
+    m_l7.put("ivities", "A");
+    m_l7.put("ization", "F");
+    m_l7.put("izement", "A");
+    m_l7.put("oidally", "A");
+    m_l7.put("ousness", "A");
+    m_l6 = new HashMap();
+    m_l6.put("aceous", "A");
+    m_l6.put("acious", "B");
+    m_l6.put("action", "G");
+    m_l6.put("alness", "A");
+    m_l6.put("ancial", "A");
+    m_l6.put("ancies", "A");
+    m_l6.put("ancing", "B");
+    m_l6.put("ariser", "A");
+    m_l6.put("arized", "A");
+    m_l6.put("arizer", "A");
+    m_l6.put("atable", "A");
+    m_l6.put("ations", "B");
+    m_l6.put("atives", "A");
+    m_l6.put("eature", "Z");
+    m_l6.put("efully", "A");
+    m_l6.put("encies", "A");
+    m_l6.put("encing", "A");
+    m_l6.put("ential", "A");
+    m_l6.put("enting", "C");
+    m_l6.put("entist", "A");
+    m_l6.put("eously", "A");
+    m_l6.put("ialist", "A");
+    m_l6.put("iality", "A");
+    m_l6.put("ialize", "A");
+    m_l6.put("ically", "A");
+    m_l6.put("icance", "A");
+    m_l6.put("icians", "A");
+    m_l6.put("icists", "A");
+    m_l6.put("ifully", "A");
+    m_l6.put("ionals", "A");
+    m_l6.put("ionate", "D");
+    m_l6.put("ioning", "A");
+    m_l6.put("ionist", "A");
+    m_l6.put("iously", "A");
+    m_l6.put("istics", "A");
+    m_l6.put("izable", "E");
+    m_l6.put("lessly", "A");
+    m_l6.put("nesses", "A");
+    m_l6.put("oidism", "A");
+    m_l5 = new HashMap();
+    m_l5.put("acies", "A");
+    m_l5.put("acity", "A");
+    m_l5.put("aging", "B");
+    m_l5.put("aical", "A");
+    if (!m_CompMode) {
+      m_l5.put("alist", "A");
+    }
+    m_l5.put("alism", "B");
+    m_l5.put("ality", "A");
+    m_l5.put("alize", "A");
+    m_l5.put("allic", "b");
+    m_l5.put("anced", "B");
+    m_l5.put("ances", "B");
+    m_l5.put("antic", "C");
+    m_l5.put("arial", "A");
+    m_l5.put("aries", "A");
+    m_l5.put("arily", "A");
+    m_l5.put("arity", "B");
+    m_l5.put("arize", "A");
+    m_l5.put("aroid", "A");
+    m_l5.put("ately", "A");
+    m_l5.put("ating", "I");
+    m_l5.put("ation", "B");
+    m_l5.put("ative", "A");
+    m_l5.put("ators", "A");
+    m_l5.put("atory", "A");
+    m_l5.put("ature", "E");
+    m_l5.put("early", "Y");
+    m_l5.put("ehood", "A");
+    m_l5.put("eless", "A");
+    if (!m_CompMode) {
+      m_l5.put("elily", "A");
+    } else {
+      m_l5.put("elity", "A");
+    }
+    m_l5.put("ement", "A");
+    m_l5.put("enced", "A");
+    m_l5.put("ences", "A");
+    m_l5.put("eness", "E");
+    m_l5.put("ening", "E");
+    m_l5.put("ental", "A");
+    m_l5.put("ented", "C");
+    m_l5.put("ently", "A");
+    m_l5.put("fully", "A");
+    m_l5.put("ially", "A");
+    m_l5.put("icant", "A");
+    m_l5.put("ician", "A");
+    m_l5.put("icide", "A");
+    m_l5.put("icism", "A");
+    m_l5.put("icist", "A");
+    m_l5.put("icity", "A");
+    m_l5.put("idine", "I");
+    m_l5.put("iedly", "A");
+    m_l5.put("ihood", "A");
+    m_l5.put("inate", "A");
+    m_l5.put("iness", "A");
+    m_l5.put("ingly", "B");
+    m_l5.put("inism", "J");
+    m_l5.put("inity", "c");
+    m_l5.put("ional", "A");
+    m_l5.put("ioned", "A");
+    m_l5.put("ished", "A");
+    m_l5.put("istic", "A");
+    m_l5.put("ities", "A");
+    m_l5.put("itous", "A");
+    m_l5.put("ively", "A");
+    m_l5.put("ivity", "A");
+    m_l5.put("izers", "F");
+    m_l5.put("izing", "F");
+    m_l5.put("oidal", "A");
+    m_l5.put("oides", "A");
+    m_l5.put("otide", "A");
+    m_l5.put("ously", "A");
+    m_l4 = new HashMap();
+    m_l4.put("able", "A");
+    m_l4.put("ably", "A");
+    m_l4.put("ages", "B");
+    m_l4.put("ally", "B");
+    m_l4.put("ance", "B");
+    m_l4.put("ancy", "B");
+    m_l4.put("ants", "B");
+    m_l4.put("aric", "A");
+    m_l4.put("arly", "K");
+    m_l4.put("ated", "I");
+    m_l4.put("ates", "A");
+    m_l4.put("atic", "B");
+    m_l4.put("ator", "A");
+    m_l4.put("ealy", "Y");
+    m_l4.put("edly", "E");
+    m_l4.put("eful", "A");
+    m_l4.put("eity", "A");
+    m_l4.put("ence", "A");
+    m_l4.put("ency", "A");
+    m_l4.put("ened", "E");
+    m_l4.put("enly", "E");
+    m_l4.put("eous", "A");
+    m_l4.put("hood", "A");
+    m_l4.put("ials", "A");
+    m_l4.put("ians", "A");
+    m_l4.put("ible", "A");
+    m_l4.put("ibly", "A");
+    m_l4.put("ical", "A");
+    m_l4.put("ides", "L");
+    m_l4.put("iers", "A");
+    m_l4.put("iful", "A");
+    m_l4.put("ines", "M");
+    m_l4.put("ings", "N");
+    m_l4.put("ions", "B");
+    m_l4.put("ious", "A");
+    m_l4.put("isms", "B");
+    m_l4.put("ists", "A");
+    m_l4.put("itic", "H");
+    m_l4.put("ized", "F");
+    m_l4.put("izer", "F");
+    m_l4.put("less", "A");
+    m_l4.put("lily", "A");
+    m_l4.put("ness", "A");
+    m_l4.put("ogen", "A");
+    m_l4.put("ward", "A");
+    m_l4.put("wise", "A");
+    m_l4.put("ying", "B");
+    m_l4.put("yish", "A");
+    m_l3 = new HashMap();
+    m_l3.put("acy", "A");
+    m_l3.put("age", "B");
+    m_l3.put("aic", "A");
+    m_l3.put("als", "b");
+    m_l3.put("ant", "B");
+    m_l3.put("ars", "O");
+    m_l3.put("ary", "F");
+    m_l3.put("ata", "A");
+    m_l3.put("ate", "A");
+    m_l3.put("eal", "Y");
+    m_l3.put("ear", "Y");
+    m_l3.put("ely", "E");
+    m_l3.put("ene", "E");
+    m_l3.put("ent", "C");
+    m_l3.put("ery", "E");
+    m_l3.put("ese", "A");
+    m_l3.put("ful", "A");
+    m_l3.put("ial", "A");
+    m_l3.put("ian", "A");
+    m_l3.put("ics", "A");
+    m_l3.put("ide", "L");
+    m_l3.put("ied", "A");
+    m_l3.put("ier", "A");
+    m_l3.put("ies", "P");
+    m_l3.put("ily", "A");
+    m_l3.put("ine", "M");
+    m_l3.put("ing", "N");
+    m_l3.put("ion", "Q");
+    m_l3.put("ish", "C");
+    m_l3.put("ism", "B");
+    m_l3.put("ist", "A");
+    m_l3.put("ite", "a");
+    m_l3.put("ity", "A");
+    m_l3.put("ium", "A");
+    m_l3.put("ive", "A");
+    m_l3.put("ize", "F");
+    m_l3.put("oid", "A");
+    m_l3.put("one", "R");
+    m_l3.put("ous", "A");
+    m_l2 = new HashMap();
+    m_l2.put("ae", "A"); 
+    m_l2.put("al", "b");
+    m_l2.put("ar", "X");
+    m_l2.put("as", "B");
+    m_l2.put("ed", "E");
+    m_l2.put("en", "F");
+    m_l2.put("es", "E");
+    m_l2.put("ia", "A");
+    m_l2.put("ic", "A");
+    m_l2.put("is", "A");
+    m_l2.put("ly", "B");
+    m_l2.put("on", "S");
+    m_l2.put("or", "T");
+    m_l2.put("um", "U");
+    m_l2.put("us", "V");
+    m_l2.put("yl", "R");
+    m_l2.put("s\'", "A");
+    m_l2.put("\'s", "A");
+    m_l1 = new HashMap();
+    m_l1.put("a", "A");
+    m_l1.put("e", "A");
+    m_l1.put("i", "A");
+    m_l1.put("o", "A");
+    m_l1.put("s", "W");
+    m_l1.put("y", "B");	
+  }
+
+  /**
+   * Finds and removes ending from given word.
+   */
+  private String removeEnding(String word) {
+
+    int length = word.length();
+    int el = 11;
+
+    while (el > 0) {
+      if (length - el > 1) {
+	String ending = word.substring(length - el);
+	String conditionCode = null;
+	switch (el) {
+	case 11: conditionCode = (String)m_l11.get(ending);
+	  break;
+	case 10: conditionCode = (String)m_l10.get(ending);
+	  break; 
+	case 9: conditionCode = (String)m_l9.get(ending);
+	  break;
+	case 8: conditionCode = (String)m_l8.get(ending);
+	  break;   
+	case 7: conditionCode = (String)m_l7.get(ending);
+	  break;   
+	case 6: conditionCode = (String)m_l6.get(ending);
+	  break;   
+	case 5: conditionCode = (String)m_l5.get(ending);
+	  break;   
+	case 4: conditionCode = (String)m_l4.get(ending);
+	  break;   
+	case 3: conditionCode = (String)m_l3.get(ending);
+	  break;   
+	case 2: conditionCode = (String)m_l2.get(ending);
+	  break;   
+	case 1: conditionCode = (String)m_l1.get(ending);
+	  break;   
+	default:
+	}
+	if (conditionCode != null) {
+	  switch (conditionCode.charAt(0)) {
+	  case 'A':
+	    return word.substring(0, length - el);
+	  case 'B':
+	    if (length - el > 2) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'C':
+	    if (length - el > 3) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'D':
+	    if (length - el > 4) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'E':
+	    if (word.charAt(length - el - 1) != 'e') {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'F':
+	    if ((length - el > 2) &&
+		(word.charAt(length - el - 1) != 'e')) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'G':
+	    if ((length - el > 2) &&
+		(word.charAt(length - el - 1) == 'f')) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'H':
+	    if ((word.charAt(length - el - 1) == 't') ||
+		((word.charAt(length - el - 1) == 'l') &&
+		 (word.charAt(length - el - 2) == 'l'))) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'I':
+	    if ((word.charAt(length - el - 1) != 'o') &&
+		(word.charAt(length - el - 1) != 'e')) { 
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'J':
+	    if ((word.charAt(length - el - 1) != 'a') &&
+		(word.charAt(length - el - 1) != 'e')) { 
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'K':
+	    if ((length - el > 2) &&
+		((word.charAt(length - el - 1) == 'l') ||
+		 (word.charAt(length - el - 1) == 'i') ||
+		 ((word.charAt(length - el - 1) == 'e') &&
+		  (word.charAt(length - el - 3) == 'u')))) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'L':
+	    if ((word.charAt(length - el - 1) != 'u') &&
+		(word.charAt(length - el - 1) != 'x') &&
+		((word.charAt(length - el - 1) != 's') ||
+		 (word.charAt(length - el - 2) == 'o'))) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'M':
+	    if ((word.charAt(length - el - 1) != 'a') &&
+		(word.charAt(length - el - 1) != 'c') &&
+		(word.charAt(length - el - 1) != 'e') &&
+		(word.charAt(length - el - 1) != 'm')) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'N':
+	    if ((length - el > 3) || 
+		((length - el == 3) &&
+		 ((word.charAt(length - el - 3) != 's')))) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'O':
+	    if ((word.charAt(length - el - 1) == 'l') ||
+		(word.charAt(length - el - 1) == 'i')) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'P':
+	    if (word.charAt(length - el - 1) != 'c') {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'Q':
+	    if ((length - el > 2) &&
+		(word.charAt(length - el - 1) != 'l') &&
+		(word.charAt(length - el - 1) != 'n')) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'R':
+	    if ((word.charAt(length - el - 1) == 'n') ||
+		(word.charAt(length - el - 1) == 'r')) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'S':
+	    if (((word.charAt(length - el - 1) == 'r') &&
+		 (word.charAt(length - el - 2) == 'd')) ||
+		((word.charAt(length - el - 1) == 't') &&
+		 (word.charAt(length - el - 2) != 't'))) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'T':
+	    if ((word.charAt(length - el - 1) == 's') ||
+		((word.charAt(length - el - 1) == 't') &&
+		 (word.charAt(length - el - 2) != 'o'))) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'U':
+	    if ((word.charAt(length - el - 1) == 'l') ||
+		(word.charAt(length - el - 1) == 'm') ||
+		(word.charAt(length - el - 1) == 'n') ||
+		(word.charAt(length - el - 1) == 'r')) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'V':
+	    if (word.charAt(length - el - 1) == 'c') {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'W':
+	    if ((word.charAt(length - el - 1) != 's') &&
+		(word.charAt(length - el - 1) != 'u')) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'X':
+	    if ((word.charAt(length - el - 1) == 'l') ||
+		(word.charAt(length - el - 1) == 'i') ||
+		((length - el > 2) &&
+		 (word.charAt(length - el - 1) == 'e') &&
+		 (word.charAt(length - el - 3) == 'u'))) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'Y':
+	    if ((word.charAt(length - el - 1) == 'n') &&
+		(word.charAt(length - el - 2) == 'i')) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'Z':
+	    if (word.charAt(length - el - 1) != 'f') {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'a':
+	    if ((word.charAt(length - el - 1) == 'd') ||
+		(word.charAt(length - el - 1) == 'f') ||
+		(((word.charAt(length - el - 1) == 'h') &&
+		  (word.charAt(length - el - 2) == 'p'))) ||
+		(((word.charAt(length - el - 1) == 'h') &&
+		  (word.charAt(length - el - 2) == 't'))) ||
+		(word.charAt(length - el - 1) == 'l') ||
+		(((word.charAt(length - el - 1) == 'r') &&
+		  (word.charAt(length - el - 2) == 'e'))) ||
+		(((word.charAt(length - el - 1) == 'r') &&
+		  (word.charAt(length - el - 2) == 'o'))) ||
+		(((word.charAt(length - el - 1) == 's') &&
+		  (word.charAt(length - el - 2) == 'e'))) ||
+		(word.charAt(length - el - 1) == 't')) {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  case 'b':
+	    if (m_CompMode) {
+	      if (((length - el == 3 ) &&
+		   (!((word.charAt(length - el - 1) == 't') &&
+		      (word.charAt(length - el - 2) == 'e') &&
+		      (word.charAt(length - el - 3) == 'm')))) ||
+		  ((length - el > 3) &&
+		   (!((word.charAt(length - el - 1) == 't') &&
+		      (word.charAt(length - el - 2) == 's') &&
+		      (word.charAt(length - el - 3) == 'y') &&
+		      (word.charAt(length - el - 4) == 'r'))))) {
+		return word.substring(0, length - el);
+	      }
+	    } else {
+	      if ((length - el > 2) &&
+		  (!((word.charAt(length - el - 1) == 't') &&
+		     (word.charAt(length - el - 2) == 'e') &&
+		     (word.charAt(length - el - 3) == 'm'))) &&
+		  ((length - el < 4) ||
+		   (!((word.charAt(length - el - 1) == 't') &&
+		      (word.charAt(length - el - 2) == 's') &&
+		      (word.charAt(length - el - 3) == 'y') &&
+		      (word.charAt(length - el - 4) == 'r'))))) {
+		return word.substring(0, length - el);
+	      }
+	    } 
+	    break;
+	  case 'c':
+	    if (word.charAt(length - el - 1) == 'l') {
+	      return word.substring(0, length - el);
+	    }
+	    break;
+	  default:
+	    throw new IllegalArgumentException("Fatal error.");
+	  }
+	}
+      }
+      el--;
+    }
+    return word;
+  }
+
+  /**
+   * Recodes ending of given word.
+   */
+  private String recodeEnding(String word) {
+
+    int lastPos = word.length() - 1;
+
+    // Rule 1
+    if (word.endsWith("bb") ||
+	word.endsWith("dd") ||
+	word.endsWith("gg") ||
+	word.endsWith("ll") ||
+	word.endsWith("mm") ||
+	word.endsWith("nn") ||
+	word.endsWith("pp") ||
+	word.endsWith("rr") ||
+	word.endsWith("ss") ||
+	word.endsWith("tt")) {
+      word = word.substring(0, lastPos);
+      lastPos--;
+    }
+
+    // Rule 2
+    if (word.endsWith("iev")) {
+      word = word.substring(0, lastPos - 2).concat("ief");
+    }
+
+    // Rule 3
+    if (word.endsWith("uct")) {
+      word = word.substring(0, lastPos - 2).concat("uc");
+      lastPos--;
+    }
+
+    // Rule 4
+    if (word.endsWith("umpt")) {
+      word = word.substring(0, lastPos - 3).concat("um");
+      lastPos -= 2;
+    }
+
+    // Rule 5
+    if (word.endsWith("rpt")) {
+      word = word.substring(0, lastPos - 2).concat("rb");
+      lastPos--;
+    }
+
+    // Rule 6
+    if (word.endsWith("urs")) {
+      word = word.substring(0, lastPos - 2).concat("ur");
+      lastPos--;
+    }
+
+    // Rule 7
+    if (word.endsWith("istr")) {
+      word = word.substring(0, lastPos - 3).concat("ister");
+      lastPos++;
+    }
+ 
+    // Rule 7a
+    if (word.endsWith("metr")) {
+      word = word.substring(0, lastPos - 3).concat("meter");
+      lastPos++;
+    }
+
+    // Rule 8
+    if (word.endsWith("olv")) {
+      word = word.substring(0, lastPos - 2).concat("olut");
+      lastPos++;
+    }
+ 
+    // Rule 9
+    if (word.endsWith("ul")) {
+      if ((lastPos - 2 < 0) ||
+	  ((word.charAt(lastPos - 2) != 'a') &&
+	   (word.charAt(lastPos - 2) != 'i') &&
+	   (word.charAt(lastPos - 2) != 'o'))) {
+	word = word.substring(0, lastPos - 1).concat("l");
+	lastPos--;
+      }
+    }
+
+    // Rule 10
+    if (word.endsWith("bex")) {
+      word = word.substring(0, lastPos - 2).concat("bic");
+    }
+
+    // Rule 11
+    if (word.endsWith("dex")) {
+      word = word.substring(0, lastPos - 2).concat("dic");
+    }
+
+    // Rule 12
+    if (word.endsWith("pex")) {
+      word = word.substring(0, lastPos - 2).concat("pic");
+    }
+
+    // Rule 13
+    if (word.endsWith("tex")) {
+      word = word.substring(0, lastPos - 2).concat("tic");
+    }
+
+    // Rule 14
+    if (word.endsWith("ax")) {
+      word = word.substring(0, lastPos - 1).concat("ac");
+    }
+
+    // Rule 15
+    if (word.endsWith("ex")) {
+      word = word.substring(0, lastPos - 1).concat("ec");
+    }
+
+    // Rule 16
+    if (word.endsWith("ix")) {
+      word = word.substring(0, lastPos - 1).concat("ic");
+    }
+
+    // Rule 17
+    if (word.endsWith("lux")) {
+      word = word.substring(0, lastPos - 2).concat("luc");
+    }
+
+    // Rule 18
+    if (word.endsWith("uad")) {
+      word = word.substring(0, lastPos - 2).concat("uas");
+    }
+
+    // Rule 19
+    if (word.endsWith("vad")) {
+      word = word.substring(0, lastPos - 2).concat("vas");
+    }
+
+    // Rule 20
+    if (word.endsWith("cid")) {
+      word = word.substring(0, lastPos - 2).concat("cis");
+    }
+
+    // Rule 21
+    if (word.endsWith("lid")) {
+      word = word.substring(0, lastPos - 2).concat("lis");
+    }
+
+    // Rule 22
+    if (word.endsWith("erid")) {
+      word = word.substring(0, lastPos - 3).concat("eris");
+    }
+
+    // Rule 23
+    if (word.endsWith("pand")) {
+      word = word.substring(0, lastPos - 3).concat("pans");
+    }
+ 
+    // Rule 24
+    if (word.endsWith("end")) {
+      if ((lastPos - 3 < 0) ||
+	   (word.charAt(lastPos - 3) != 's')) {
+	word = word.substring(0, lastPos - 2).concat("ens");
+      }
+    }
+
+    // Rule 25
+    if (word.endsWith("ond")) {
+      word = word.substring(0, lastPos - 2).concat("ons");
+    }
+
+    // Rule 26
+    if (word.endsWith("lud")) {
+      word = word.substring(0, lastPos - 2).concat("lus");
+    }
+
+    // Rule 27
+    if (word.endsWith("rud")) {
+      word = word.substring(0, lastPos - 2).concat("rus");
+    }
+
+    // Rule 28
+    if (word.endsWith("her")) {
+      if ((lastPos - 3 < 0) ||
+	  ((word.charAt(lastPos - 3) != 'p') &&
+	   (word.charAt(lastPos - 3) != 't'))) {
+	word = word.substring(0, lastPos - 2).concat("hes");
+      }
+    }
+
+    // Rule 29
+    if (word.endsWith("mit")) {
+      word = word.substring(0, lastPos - 2).concat("mis");
+    }
+
+    // Rule 30
+    if (word.endsWith("end")) {
+      if ((lastPos - 3 < 0) ||
+	  (word.charAt(lastPos - 3) != 'm')) {
+	word = word.substring(0, lastPos - 2).concat("ens");
+      }
+    }
+
+    // Rule 31
+    if (word.endsWith("ert")) {
+      word = word.substring(0, lastPos - 2).concat("ers");
+    }
+
+    // Rule 32
+    if (word.endsWith("et")) {
+      if ((lastPos - 2 < 0) ||
+	  (word.charAt(lastPos - 2) != 'n')) {
+	word = word.substring(0, lastPos - 1).concat("es");
+      }
+    }
+
+    // Rule 33
+    if (word.endsWith("yt")) {
+      word = word.substring(0, lastPos - 1).concat("ys");
+    }
+
+    // Rule 34
+    if (word.endsWith("yz")) {
+      word = word.substring(0, lastPos - 1).concat("ys");
+    }
+
+    return word;
+  }
+
+  /**
+   * Returns the stemmed version of the given word.
+   * 
+   * @param word a string consisting of a single word
+   */
+  public String stem(String word) {
+
+    if (word.length() > 2) {
+      return recodeEnding(removeEnding(word.toLowerCase()));
+    } else {
+      return word.toLowerCase();
+    }
+  }
+
+  /**
+   * Stems text coming into stdin and writes it to stdout.
+   */
+  public static void main(String[] ops) {
+
+    LovinsStemmer ls = new LovinsStemmer();
+
+    try {
+      int num;
+      StringBuffer wordBuffer = new StringBuffer();
+      while ((num = System.in.read()) != -1) {
+	char c = (char)num;
+	if (((num >= (int)'A') && (num <= (int)'Z')) ||
+	    ((num >= (int)'a') && (num <= (int)'z'))) {
+	  wordBuffer.append(c);
+	} else {
+	  if (wordBuffer.length() > 0) {
+	    System.out.print(ls.stem(wordBuffer.toString().
+				     toLowerCase()));
+	    wordBuffer = new StringBuffer();
+	  }
+	  System.out.print(c);
+	}
+      }
+    } catch (Exception e) {
+      System.err.println(e.getMessage());
+    }
+  }
+}
+    
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/NumbersFilter.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/NumbersFilter.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/NumbersFilter.java	(revision 16571)
@@ -0,0 +1,182 @@
+/*
+ *    NumbersFilter.java
+ *    Copyright (C) 2000 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import weka.core.*;
+import weka.filters.*;
+
+import java.util.*;
+
+/**
+ * Removes all numbers from all the string attributes in the given
+ * dataset. Assumes that words are separated by whitespace.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public class NumbersFilter extends Filter {
+
+  /**
+   * Returns a string describing this filter
+   *
+   * @return a description of the filter suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String globalInfo() {
+      return "Removes all numbers from all the string attributes in " +
+      "the given dataset. Assumes that words are separated by whitespace.";
+  }
+
+  /**
+   * Signify that this batch of input to the filter is finished. If
+   * the filter requires all instances prior to filtering, output()
+   * may now be called to retrieve the filtered instances. Any
+   * subsequent instances filtered should be filtered based on setting
+   * obtained from the first batch (unless the inputFormat has been
+   * re-assigned or new options have been set). This default
+   * implementation assumes all instance processing occurs during
+   * inputFormat() and input().
+   *
+   * @return true if there are instances pending output
+   * @exception NullPointerException if no input structure has been defined,
+   * @exception Exception if there was a problem finishing the batch.
+   */
+  public boolean batchFinished() throws Exception {
+
+    if (getInputFormat() == null) {
+      throw new NullPointerException("No input instance format defined");
+    }
+    m_NewBatch = true;
+    return (numPendingOutput() != 0);
+  }
+
+  /**
+   * Sets the format of the input instances.
+   *
+   * @param instanceInfo an Instances object containing the input
+   * instance structure (any instances contained in the object are
+   * ignored - only the structure is required).
+   * @return true if the outputFormat may be collected immediately 
+   */
+  public boolean setInputFormat(Instances instanceInfo) throws Exception {
+
+    super.setInputFormat(instanceInfo);
+    setOutputFormat(instanceInfo);
+    return true;
+  }
+
+  /**
+   * Input an instance for filtering. Ordinarily the instance is processed
+   * and made available for output immediately. Some filters require all
+   * instances be read before producing output.
+   *
+   * @param instance the input instance
+   * @return true if the filtered instance may now be
+   * collected with output().
+   * @exception Exception if the input instance was not of the correct 
+   * format or if there was a problem with the filtering.
+   */
+  public boolean input(Instance instance) throws Exception {
+
+    if (getInputFormat() == null) {
+      throw new Exception("No input instance format defined");
+    }
+    if (m_NewBatch) {
+      resetQueue();
+      m_NewBatch = false;
+    }
+    convertInstance(instance);
+    return true;
+  }
+
+  /**
+   * Main method for testing this class.
+   *
+   * @param argv should contain arguments to the filter: use -h for help
+   */
+  public static void main(String [] argv) {
+    
+    try {
+      if (Utils.getFlag('b', argv)) {
+	Filter.batchFilterFile(new NumbersFilter(), argv);
+      } else {
+	Filter.filterFile(new NumbersFilter(), argv);
+      }
+    } catch (Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+  }
+ 
+  /** 
+   * Converts an instance. A phrase boundary is inserted where
+   * a number is found.
+   */
+  private void convertInstance(Instance instance) throws Exception {
+  
+    double[] instVals = new double[instance.numAttributes()];
+
+    for (int i = 0; i < instance.numAttributes(); i++) {
+      if ((!instance.attribute(i).isString()) || instance.isMissing(i)) {
+	instVals[i] = instance.value(i);
+      } else {
+	String str = instance.stringValue(i);
+	StringBuffer resultStr = new StringBuffer();
+	StringTokenizer tok = new StringTokenizer(str, " \t\n", true);
+	while (tok.hasMoreTokens()) {
+	  String token = tok.nextToken();
+
+	  // Everything that doesn't contain at least
+	  // one letter is considered to be a number
+	  boolean isNumber = true;
+	  for (int j = 0; j < token.length(); j++) {
+	    if (Character.isLetter(token.charAt(j))) {
+	      isNumber = false;
+	      break;
+	    }
+	  }
+	  if (!isNumber) {
+	    resultStr.append(token);
+	  } else {
+	    if (token.equals(" ") || token.equals("\t") ||
+		token.equals("\n")) {
+	      resultStr.append(token);
+	    } else {
+	      resultStr.append(" \n ");
+	    }
+	  }
+	}
+	int index = getOutputFormat().attribute(i).addStringValue(resultStr.toString());
+	instVals[i] = (double)index;
+      }
+    }
+    Instance inst = new Instance(instance.weight(), instVals);
+    inst.setDataset(getOutputFormat());
+    push(inst);
+  }
+}
+
+
+
+
+
+
+
+
+
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/README
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/README	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/README	(revision 16571)
@@ -0,0 +1,284 @@
+=====================================================================
+                                                                       
+                              ======                                   
+                              README                                   
+                              ======                                   
+                                                                       
+                             KEA 3.0
+                          18 March 2004
+                                                                       
+           Java Programs for Automatic Keyphrase Extraction
+                                                                       
+               Copyright (C) 2000, 2001, 2004  Eibe Frank
+
+                   email: eibe@cs.waikato.ac.nz            
+                                                                       
+=====================================================================
+
+Contents:
+---------
+
+1. Installation
+
+2. Getting started
+
+   - Building a keyphrase extraction model
+   - Extracting keyphrases
+   - Important comment
+
+3. Examples
+
+4. Other documentation
+
+5. Copyright
+
+----------------------------------------------------------------------
+
+NOTE:
+-----
+
+This distribution includes a cut-down version of WEKA, the GPL'ed
+machine learning workbench available from 
+
+  http://www.cs.waikato.ac.nz/ml/weka.
+
+----------------------------------------------------------------------
+
+1. Installation:
+----------------
+
+KEA is implemented as a set of Java classes (located in the same
+directory as this README file). To run KEA you need to tell the Java
+Virtual Machine where to look for KEA classes.  One possible way of
+doing this is to add the directory that contains this README file to
+the CLASSPATH environment variable that is used by the Java Virtual
+Machine.
+
+Under Linux you would do the following:
+
+a) Set KEAHOME to be the directory which contains this README.
+
+b) Add $KEAHOME to your CLASSPATH environment variable.
+
+The on-line documentation (generated from the source code) is located
+in the doc directory. You might want to do the following to have the
+documentation handy in you web browser:
+
+c) Bookmark $KEAHOME/doc/packages.html in your web browser.
+
+----------------------------------------------------------------------
+
+2. Getting started:
+-------------------
+
+Building a keyphrase extraction model
+=====================================
+
+To extract keyphrases for new documents, you first need to build a KEA
+keyphrase extraction model from a set of documents (preferably from
+the same domain) for which you have author- assigned keyphrases. To
+this end you have to go through the following steps:
+
+a) Create a directory, called, for example, "training_documents",
+   containing the documents that you want to use for training the
+   keyphrase extractor.
+
+b) Rename the document files in that directory so that they end with
+   the suffix ".txt".
+
+c) Delete the author-assigned keyphrases from those documents
+   and put them into separate ".key" files. For example, if
+   your document file is called doc1.txt, move the keyphrases
+   into a new file called "doc1.key". It is important that
+   you put each keyphrase on a separate line in the .key file!
+
+d) Build the keyphrase extraction model by running the
+   KEAModelBuilder:
+
+   java KEAModelBuilder -l <name_of_directory> -m <name_of_model>
+
+   This will use the documents in <name_of_directory> to build a
+   keyphrase extraction model and save it in <name_of_model>.
+
+KEAModelBuilder has a few other options that you can view if you run
+KEAModelBuilder without any arguments. Here is a list of all the
+options:
+
+-l <directory name>
+	Specifies name of directory.
+-m <model name>
+	Specifies name of model.
+-e <encoding>
+	Specifies encoding.
+-d
+	Turns debugging mode on.
+-k
+	Use keyphrase frequency statistic.
+-p
+	Disallow internal periods.
+-x <length>
+	Sets the maximum phrase length (default: 3).
+-y <length>
+	Sets the minimum phrase length (default: 1).
+-o <number>
+	The minimum number of times a phrase needs to occur 
+	(default: 2).
+-s <name of stopwords class>
+        Sets the list of stopwords to use (default: StopwordsEnglish).
+-t <name of stemmer class>
+        Set the stemmer to use (default: IteratedLovinsStemmer).
+-n
+        Do not check for proper nouns.
+   
+The -e option allows you to specify a different character encoding
+supported by Java. For example, to extract keyphrases from Chinese
+documents encoded using GBK, you would use specify "-e GBK" as an
+argument.
+
+The -d option generates some output that shows the progress of the
+model builder.
+
+If -k is set, the keyphrase frequency attribute is used in the
+model. For more info on this, have a look at the paper on
+"Domain-specific keyphrase extraction" listed below. Using this option
+improves accuracy if the domain of the documents for which you want to
+extract keyphrases is the same as the domain of the training
+documents. In other words, if you want to extract keyphrases from
+papers on radiology, and your training documents are about radiology,
+you should use this option.
+
+If -p is set, KEA does not consider phrases with internal periods as
+candidate keyphrases. It is important to use this if a full stop is
+not always followed by white space in the documents.
+
+Using -s and -t you can set different classes for stopword detection
+and stemming respectively (for languages other than English).
+
+Using -d you turn KEA's heuristic for detecting proper nouns off. This
+is important for languages like German, where all nouns start with an
+uppercase letter, not just proper nouns.
+
+Extracting keyphrases
+=====================
+
+To extract keyphrases for some documents, put them into an empty
+directory. Then rename them so that they end with the suffix ".txt".
+
+If you've previously built a keyphrase extraction model you can now
+apply keyphrases for these documents using:
+
+java KEAKeyphraseExtractor -l <name_of_directory> -m <name_of_model>
+
+This will create a ".key" file for each document in the
+directory. Each file will contain five extracted keyphrases for the
+corresponding document.
+
+If a ".key" file is already present it won't be overwritten.  Instead,
+the keyphrases present in that file will be used to evaluate the
+extraction model. The stemmed extracted phrases are compared to the
+stemmed versions of the phrases in the ".key"
+file. KEAKeyphraseExtractor reports the number of hits among the total
+number of extracted phrases for those documents that have associated
+".key" files in the directory.
+
+KEAKeyphraseExtractor has a few options. Here they are:
+
+-l <directory name>
+	Specifies name of directory.
+-m <model name>
+	Specifies name of model.
+-e <encoding>
+	Specifies encoding.
+-n
+	Specifies number of phrases to be output (default: 5).
+-d
+	Turns debugging mode on.
+-a
+	Also write stemmed phrase and score into ".key" file.
+
+Important comment
+-----------------
+
+To get good results, it is important that the input text for KEA is as
+"clean" as possible. That means html tags etc. in the input documents
+need to be deleted before the model is built and before keyphrases are
+extracted from new documents.
+
+----------------------------------------------------------------------
+
+3. Examples:
+------------
+
+The directory contains two example collections, each split up into a
+train and test directory. Note that these collections are only
+included to show how the system can be applied to actual documents.
+Due to the lack of data, the accuracy isn't very good on either
+example collection.
+
+Collection A
+------------
+
+A collection of abstracts taken from computer science technical
+reports:
+
+   CSTR_abstracts_train
+   CSTR_abstracts_test
+
+To build a model from the training data, try:
+
+   java KEAModelBuilder -l CSTR_abstracts_train -m CSTR_abstracts_model
+
+To evaluate that model on the test data, try:
+
+   java KEAKeyphraseExtractor -l CSTR_abstracts_test -m CSTR_abstracts_model
+
+Collection B
+------------
+
+A small collection of Chinese documents (in GBK encoding):
+
+   Journals_train
+   Journals_test
+
+To build a model from the training data, try:
+
+   java KEAModelBuilder -l Chinese_train -m Chinese_model -e GBK
+
+To evaluate that model on the test data, try:
+
+   java KEAKeyphraseExtractor -l Chinese_test -m Chinese_model -e GBK 
+
+----------------------------------------------------------------------
+
+4. Other documentation:
+-----------------------
+
+There are several papers on the KEA algorithm, listed below. Note that
+this implementation differs slightly from the version described in the
+papers, mainly in the pre-processing step (i.e. in the way candidate
+keyphrases are generated). For more info on the new method please
+consult the online documentation.
+
+Witten I.H., Paynter G.W., Frank E., Gutwin C. and Nevill-Manning
+C.G. (2000) "KEA: Practical automatic keyphrase extraction." Working
+Paper 00/5, Department of Computer Science, The University of Waikato.
+
+Witten I.H., Paynter G.W., Frank E., Gutwin C. and Nevill-Manning
+C.G. (1999) "KEA: Practical automatic keyphrase extraction." Proc. DL
+'99, pp. 254-256. (Poster presentation.)
+
+Frank E., Paynter G.W., Witten I.H., Gutwin C. and Nevill-Manning
+C.G. (1999) "Domain-specific keyphrase extraction" Proc. Sixteenth
+International Joint Conference on Artificial Intelligence, Morgan
+Kaufmann Publishers, San Francisco, CA, pp. 668-673.
+
+-----------------------------------------------------------------------
+
+5. Copyright:
+-------------
+
+KEA is distributed under the GNU public license. Please read the file
+COPYING.
+
+-----------------------------------------------------------------------
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/Stemmer.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/Stemmer.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/Stemmer.java	(revision 16571)
@@ -0,0 +1,68 @@
+/*
+ *    Stemmer.java
+ *    Copyright (C) 2001 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import java.util.*;
+import java.io.*;
+
+/**
+ * Abstract class for stemmers.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public abstract class Stemmer implements Serializable {
+
+  /**
+   * Iterated stemming of the given word.
+   */
+  public abstract String stem(String str);
+
+  /**
+   * Stems everything in the given string.
+   */
+  public String stemString(String str) {
+
+    StringBuffer result = new StringBuffer();
+    int start = -1;
+    for (int j = 0; j < str.length(); j++) {
+      char c = str.charAt(j);
+      if (Character.isLetterOrDigit(c)) {
+	if (start == -1) {
+	  start = j;
+	}
+      } else if (c == '\'') {
+	if (start == -1) {
+	  result.append(c);
+	}
+      } else {
+	if (start != -1) {
+	  result.append(stem(str.substring(start, j)));
+	  start = -1;
+	}
+	result.append(c);
+      }
+    }
+    if (start != -1) {
+      result.append(stem(str.substring(start, str.length())));
+    }
+    return result.toString();  
+  }
+}
+    
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/Stopwords.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/Stopwords.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/Stopwords.java	(revision 16571)
@@ -0,0 +1,38 @@
+/*
+ *    Stopwords.java
+ *    Copyright (C) 2001 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import java.util.*;
+import java.io.*;
+
+/**
+ * Class that can test whether a given string is a stop word.
+ * Lowercases all words before the test.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public abstract class Stopwords implements Serializable {
+  
+  /** 
+   * Returns true if the given string is a stop word.
+   */
+  public abstract boolean isStopword(String str);
+}
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/StopwordsEnglish.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/StopwordsEnglish.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/StopwordsEnglish.java	(revision 16571)
@@ -0,0 +1,504 @@
+/*
+ *    StopwordsEnglish.java
+ *    Copyright (C) 2001 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import java.util.*;
+
+/**
+ * Class that can test whether a given string is a stop word.
+ * Lowercases all words before the test.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public class StopwordsEnglish extends Stopwords {
+  
+  /** The hashtable containing the list of stopwords */
+  private static Hashtable m_Stopwords = null;
+
+  static {
+   
+    if (m_Stopwords == null) {
+      m_Stopwords = new Hashtable();
+      Double dummy = new Double(0);
+      
+      m_Stopwords.put("a", dummy);
+      m_Stopwords.put("abaft", dummy);
+      m_Stopwords.put("aboard", dummy);
+      m_Stopwords.put("about", dummy);
+      m_Stopwords.put("above", dummy);
+      m_Stopwords.put("across", dummy);
+      m_Stopwords.put("afore", dummy);
+      m_Stopwords.put("aforesaid", dummy);
+      m_Stopwords.put("after", dummy);
+      m_Stopwords.put("again", dummy);
+      m_Stopwords.put("against", dummy);
+      m_Stopwords.put("agin", dummy);
+      m_Stopwords.put("ago", dummy);
+      m_Stopwords.put("aint", dummy);
+      m_Stopwords.put("albeit", dummy);
+      m_Stopwords.put("all", dummy);
+      m_Stopwords.put("almost", dummy);
+      m_Stopwords.put("alone", dummy);
+      m_Stopwords.put("along", dummy);
+      m_Stopwords.put("alongside", dummy);
+      m_Stopwords.put("already", dummy);
+      m_Stopwords.put("also", dummy);
+      m_Stopwords.put("although", dummy);
+      m_Stopwords.put("always", dummy);
+      m_Stopwords.put("am", dummy);
+      m_Stopwords.put("american", dummy);
+      m_Stopwords.put("amid", dummy);
+      m_Stopwords.put("amidst", dummy);
+      m_Stopwords.put("among", dummy);
+      m_Stopwords.put("amongst", dummy);
+      m_Stopwords.put("an", dummy);
+      m_Stopwords.put("and", dummy);
+      m_Stopwords.put("anent", dummy);
+      m_Stopwords.put("another", dummy);
+      m_Stopwords.put("any", dummy);
+      m_Stopwords.put("anybody", dummy);
+      m_Stopwords.put("anyone", dummy);
+      m_Stopwords.put("anything", dummy);
+      m_Stopwords.put("are", dummy);
+      m_Stopwords.put("aren't", dummy);
+      m_Stopwords.put("around", dummy);
+      m_Stopwords.put("as", dummy);
+      m_Stopwords.put("aslant", dummy);
+      m_Stopwords.put("astride", dummy);
+      m_Stopwords.put("at", dummy);
+      m_Stopwords.put("athwart", dummy);
+      m_Stopwords.put("away", dummy);
+      m_Stopwords.put("b", dummy);
+      m_Stopwords.put("back", dummy);
+      m_Stopwords.put("bar", dummy);
+      m_Stopwords.put("barring", dummy);
+      m_Stopwords.put("be", dummy);
+      m_Stopwords.put("because", dummy);
+      m_Stopwords.put("been", dummy);
+      m_Stopwords.put("before", dummy);
+      m_Stopwords.put("behind", dummy);
+      m_Stopwords.put("being", dummy);
+      m_Stopwords.put("below", dummy);
+      m_Stopwords.put("beneath", dummy);
+      m_Stopwords.put("beside", dummy);
+      m_Stopwords.put("besides", dummy);
+      m_Stopwords.put("best", dummy);
+      m_Stopwords.put("better", dummy);
+      m_Stopwords.put("between", dummy);
+      m_Stopwords.put("betwixt", dummy);
+      m_Stopwords.put("beyond", dummy);
+      m_Stopwords.put("both", dummy);
+      m_Stopwords.put("but", dummy);
+      m_Stopwords.put("by", dummy);
+      m_Stopwords.put("c", dummy);
+      m_Stopwords.put("can", dummy);
+      m_Stopwords.put("cannot", dummy);
+      m_Stopwords.put("can't", dummy);
+      m_Stopwords.put("certain", dummy);
+      m_Stopwords.put("circa", dummy);
+      m_Stopwords.put("close", dummy);
+      m_Stopwords.put("concerning", dummy);
+      m_Stopwords.put("considering", dummy);
+      m_Stopwords.put("cos", dummy);
+      m_Stopwords.put("could", dummy);
+      m_Stopwords.put("couldn't", dummy);
+      m_Stopwords.put("couldst", dummy);
+      m_Stopwords.put("d", dummy);
+      m_Stopwords.put("dare", dummy);
+      m_Stopwords.put("dared", dummy);
+      m_Stopwords.put("daren't", dummy);
+      m_Stopwords.put("dares", dummy);
+      m_Stopwords.put("daring", dummy);
+      m_Stopwords.put("despite", dummy);
+      m_Stopwords.put("did", dummy);
+      m_Stopwords.put("didn't", dummy);
+      m_Stopwords.put("different", dummy);
+      m_Stopwords.put("directly", dummy);
+      m_Stopwords.put("do", dummy);
+      m_Stopwords.put("does", dummy);
+      m_Stopwords.put("doesn't", dummy);
+      m_Stopwords.put("doing", dummy);
+      m_Stopwords.put("done", dummy);
+      m_Stopwords.put("don't", dummy);
+      m_Stopwords.put("dost", dummy);
+      m_Stopwords.put("doth", dummy);
+      m_Stopwords.put("down", dummy);
+      m_Stopwords.put("during", dummy);
+      m_Stopwords.put("durst", dummy);
+      m_Stopwords.put("e", dummy);
+      m_Stopwords.put("each", dummy);
+      m_Stopwords.put("early", dummy);
+      m_Stopwords.put("either", dummy);
+      m_Stopwords.put("em", dummy);
+      m_Stopwords.put("english", dummy);
+      m_Stopwords.put("enough", dummy);
+      m_Stopwords.put("ere", dummy);
+      m_Stopwords.put("even", dummy);
+      m_Stopwords.put("ever", dummy);
+      m_Stopwords.put("every", dummy);
+      m_Stopwords.put("everybody", dummy);
+      m_Stopwords.put("everyone", dummy);
+      m_Stopwords.put("everything", dummy);
+      m_Stopwords.put("except", dummy);
+      m_Stopwords.put("excepting", dummy);
+      m_Stopwords.put("f", dummy);
+      m_Stopwords.put("failing", dummy);
+      m_Stopwords.put("far", dummy);
+      m_Stopwords.put("few", dummy);
+      m_Stopwords.put("first", dummy);
+      m_Stopwords.put("five", dummy);
+      m_Stopwords.put("following", dummy);
+      m_Stopwords.put("for", dummy);
+      m_Stopwords.put("four", dummy);
+      m_Stopwords.put("from", dummy);
+      m_Stopwords.put("g", dummy);
+      m_Stopwords.put("gonna", dummy);
+      m_Stopwords.put("gotta", dummy);
+      m_Stopwords.put("h", dummy);
+      m_Stopwords.put("had", dummy);
+      m_Stopwords.put("hadn't", dummy);
+      m_Stopwords.put("hard", dummy);
+      m_Stopwords.put("has", dummy);
+      m_Stopwords.put("hasn't", dummy);
+      m_Stopwords.put("hast", dummy);
+      m_Stopwords.put("hath", dummy);
+      m_Stopwords.put("have", dummy);
+      m_Stopwords.put("haven't", dummy);
+      m_Stopwords.put("having", dummy);
+      m_Stopwords.put("he", dummy);
+      m_Stopwords.put("he'd", dummy);
+      m_Stopwords.put("he'll", dummy);
+      m_Stopwords.put("her", dummy);
+      m_Stopwords.put("here", dummy);
+      m_Stopwords.put("here's", dummy);
+      m_Stopwords.put("hers", dummy);
+      m_Stopwords.put("herself", dummy);
+      m_Stopwords.put("he's", dummy);
+      m_Stopwords.put("high", dummy);
+      m_Stopwords.put("him", dummy);
+      m_Stopwords.put("himself", dummy);
+      m_Stopwords.put("his", dummy);
+      m_Stopwords.put("home", dummy);
+      m_Stopwords.put("how", dummy);
+      m_Stopwords.put("howbeit", dummy);
+      m_Stopwords.put("however", dummy);
+      m_Stopwords.put("how's", dummy);
+      m_Stopwords.put("i", dummy);
+      m_Stopwords.put("id", dummy);
+      m_Stopwords.put("if", dummy);
+      m_Stopwords.put("ill", dummy);
+      m_Stopwords.put("i'm", dummy);
+      m_Stopwords.put("immediately", dummy);
+      m_Stopwords.put("important", dummy);
+      m_Stopwords.put("in", dummy);
+      m_Stopwords.put("inside", dummy);
+      m_Stopwords.put("instantly", dummy);
+      m_Stopwords.put("into", dummy);
+      m_Stopwords.put("is", dummy);
+      m_Stopwords.put("isn't", dummy);
+      m_Stopwords.put("it", dummy);
+      m_Stopwords.put("it'll", dummy);
+      m_Stopwords.put("it's", dummy);
+      m_Stopwords.put("its", dummy);
+      m_Stopwords.put("itself", dummy);
+      m_Stopwords.put("i've", dummy);
+      m_Stopwords.put("j", dummy);
+      m_Stopwords.put("just", dummy);
+      m_Stopwords.put("k", dummy);
+      m_Stopwords.put("l", dummy);
+      m_Stopwords.put("large", dummy);
+      m_Stopwords.put("last", dummy);
+      m_Stopwords.put("later", dummy);
+      m_Stopwords.put("least", dummy);
+      m_Stopwords.put("left", dummy);
+      m_Stopwords.put("less", dummy);
+      m_Stopwords.put("lest", dummy);
+      m_Stopwords.put("let's", dummy);
+      m_Stopwords.put("like", dummy);
+      m_Stopwords.put("likewise", dummy);
+      m_Stopwords.put("little", dummy);
+      m_Stopwords.put("living", dummy);
+      m_Stopwords.put("long", dummy);
+      m_Stopwords.put("m", dummy);
+      m_Stopwords.put("many", dummy);
+      m_Stopwords.put("may", dummy);
+      m_Stopwords.put("mayn't", dummy);
+      m_Stopwords.put("me", dummy);
+      m_Stopwords.put("mid", dummy);
+      m_Stopwords.put("midst", dummy);
+      m_Stopwords.put("might", dummy);
+      m_Stopwords.put("mightn't", dummy);
+      m_Stopwords.put("mine", dummy);
+      m_Stopwords.put("minus", dummy);
+      m_Stopwords.put("more", dummy);
+      m_Stopwords.put("most", dummy);
+      m_Stopwords.put("much", dummy);
+      m_Stopwords.put("must", dummy);
+      m_Stopwords.put("mustn't", dummy);
+      m_Stopwords.put("my", dummy);
+      m_Stopwords.put("myself", dummy);
+      m_Stopwords.put("n", dummy);
+      m_Stopwords.put("near", dummy);
+      m_Stopwords.put("'neath", dummy);
+      m_Stopwords.put("need", dummy);
+      m_Stopwords.put("needed", dummy);
+      m_Stopwords.put("needing", dummy);
+      m_Stopwords.put("needn't", dummy);
+      m_Stopwords.put("needs", dummy);
+      m_Stopwords.put("neither", dummy);
+      m_Stopwords.put("never", dummy);
+      m_Stopwords.put("nevertheless", dummy);
+      m_Stopwords.put("new", dummy);
+      m_Stopwords.put("next", dummy);
+      m_Stopwords.put("nigh", dummy);
+      m_Stopwords.put("nigher", dummy);
+      m_Stopwords.put("nighest", dummy);
+      m_Stopwords.put("nisi", dummy);
+      m_Stopwords.put("no", dummy);
+      m_Stopwords.put("no-one", dummy);
+      m_Stopwords.put("nobody", dummy);
+      m_Stopwords.put("none", dummy);
+      m_Stopwords.put("nor", dummy);
+      m_Stopwords.put("not", dummy);
+      m_Stopwords.put("nothing", dummy);
+      m_Stopwords.put("notwithstanding", dummy);
+      m_Stopwords.put("now", dummy);
+      m_Stopwords.put("o", dummy);
+      m_Stopwords.put("o'er", dummy);
+      m_Stopwords.put("of", dummy);
+      m_Stopwords.put("off", dummy);
+      m_Stopwords.put("often", dummy);
+      m_Stopwords.put("on", dummy);
+      m_Stopwords.put("once", dummy);
+      m_Stopwords.put("one", dummy);
+      m_Stopwords.put("oneself", dummy);
+      m_Stopwords.put("only", dummy);
+      m_Stopwords.put("onto", dummy);
+      m_Stopwords.put("open", dummy);
+      m_Stopwords.put("or", dummy);
+      m_Stopwords.put("other", dummy);
+      m_Stopwords.put("otherwise", dummy);
+      m_Stopwords.put("ought", dummy);
+      m_Stopwords.put("oughtn't", dummy);
+      m_Stopwords.put("our", dummy);
+      m_Stopwords.put("ours", dummy);
+      m_Stopwords.put("ourselves", dummy);
+      m_Stopwords.put("out", dummy);
+      m_Stopwords.put("outside", dummy);
+      m_Stopwords.put("over", dummy);
+      m_Stopwords.put("own", dummy);
+      m_Stopwords.put("p", dummy);
+      m_Stopwords.put("past", dummy);
+      m_Stopwords.put("pending", dummy);
+      m_Stopwords.put("per", dummy);
+      m_Stopwords.put("perhaps", dummy);
+      m_Stopwords.put("plus", dummy);
+      m_Stopwords.put("possible", dummy);
+      m_Stopwords.put("present", dummy);
+      m_Stopwords.put("probably", dummy);
+      m_Stopwords.put("provided", dummy);
+      m_Stopwords.put("providing", dummy);
+      m_Stopwords.put("public", dummy);
+      m_Stopwords.put("q", dummy);
+      m_Stopwords.put("qua", dummy);
+      m_Stopwords.put("quite", dummy);
+      m_Stopwords.put("r", dummy);
+      m_Stopwords.put("rather", dummy);
+      m_Stopwords.put("re", dummy);
+      m_Stopwords.put("real", dummy);
+      m_Stopwords.put("really", dummy);
+      m_Stopwords.put("respecting", dummy);
+      m_Stopwords.put("right", dummy);
+      m_Stopwords.put("round", dummy);
+      m_Stopwords.put("s", dummy);
+      m_Stopwords.put("same", dummy);
+      m_Stopwords.put("sans", dummy);
+      m_Stopwords.put("save", dummy);
+      m_Stopwords.put("saving", dummy);
+      m_Stopwords.put("second", dummy);
+      m_Stopwords.put("several", dummy);
+      m_Stopwords.put("shall", dummy);
+      m_Stopwords.put("shalt", dummy);
+      m_Stopwords.put("shan't", dummy);
+      m_Stopwords.put("she", dummy);
+      m_Stopwords.put("shed", dummy);
+      m_Stopwords.put("shell", dummy);
+      m_Stopwords.put("she's", dummy);
+      m_Stopwords.put("short", dummy);
+      m_Stopwords.put("should", dummy);
+      m_Stopwords.put("shouldn't", dummy);
+      m_Stopwords.put("since", dummy);
+      m_Stopwords.put("six", dummy);
+      m_Stopwords.put("small", dummy);
+      m_Stopwords.put("so", dummy);
+      m_Stopwords.put("some", dummy);
+      m_Stopwords.put("somebody", dummy);
+      m_Stopwords.put("someone", dummy);
+      m_Stopwords.put("something", dummy);
+      m_Stopwords.put("sometimes", dummy);
+      m_Stopwords.put("soon", dummy);
+      m_Stopwords.put("special", dummy);
+      m_Stopwords.put("still", dummy);
+      m_Stopwords.put("such", dummy);
+      m_Stopwords.put("summat", dummy);
+      m_Stopwords.put("supposing", dummy);
+      m_Stopwords.put("sure", dummy);
+      m_Stopwords.put("t", dummy);
+      m_Stopwords.put("than", dummy);
+      m_Stopwords.put("that", dummy);
+      m_Stopwords.put("that'd", dummy);
+      m_Stopwords.put("that'll", dummy);
+      m_Stopwords.put("that's", dummy);
+      m_Stopwords.put("the", dummy);
+      m_Stopwords.put("thee", dummy);
+      m_Stopwords.put("their", dummy);
+      m_Stopwords.put("theirs", dummy);
+      m_Stopwords.put("their's", dummy);
+      m_Stopwords.put("them", dummy);
+      m_Stopwords.put("themselves", dummy);
+      m_Stopwords.put("then", dummy);
+      m_Stopwords.put("there", dummy);
+      m_Stopwords.put("there's", dummy);
+      m_Stopwords.put("these", dummy);
+      m_Stopwords.put("they", dummy);
+      m_Stopwords.put("they'd", dummy);
+      m_Stopwords.put("they'll", dummy);
+      m_Stopwords.put("they're", dummy);
+      m_Stopwords.put("they've", dummy);
+      m_Stopwords.put("thine", dummy);
+      m_Stopwords.put("this", dummy);
+      m_Stopwords.put("tho", dummy);
+      m_Stopwords.put("those", dummy);
+      m_Stopwords.put("thou", dummy);
+      m_Stopwords.put("though", dummy);
+      m_Stopwords.put("three", dummy);
+      m_Stopwords.put("thro'", dummy);
+      m_Stopwords.put("through", dummy);
+      m_Stopwords.put("throughout", dummy);
+      m_Stopwords.put("thru", dummy);
+      m_Stopwords.put("thyself", dummy);
+      m_Stopwords.put("till", dummy);
+      m_Stopwords.put("to", dummy);
+      m_Stopwords.put("today", dummy);
+      m_Stopwords.put("together", dummy);
+      m_Stopwords.put("too", dummy);
+      m_Stopwords.put("touching", dummy);
+      m_Stopwords.put("toward", dummy);
+      m_Stopwords.put("towards", dummy);
+      m_Stopwords.put("true", dummy);
+      m_Stopwords.put("'twas", dummy);
+      m_Stopwords.put("'tween", dummy);
+      m_Stopwords.put("'twere", dummy);
+      m_Stopwords.put("'twill", dummy);
+      m_Stopwords.put("'twixt", dummy);
+      m_Stopwords.put("two", dummy);
+      m_Stopwords.put("'twould", dummy);
+      m_Stopwords.put("u", dummy);
+      m_Stopwords.put("under", dummy);
+      m_Stopwords.put("underneath", dummy);
+      m_Stopwords.put("unless", dummy);
+      m_Stopwords.put("unlike", dummy);
+      m_Stopwords.put("until", dummy);
+      m_Stopwords.put("unto", dummy);
+      m_Stopwords.put("up", dummy);
+      m_Stopwords.put("upon", dummy);
+      m_Stopwords.put("us", dummy);
+      m_Stopwords.put("used", dummy);
+      m_Stopwords.put("usually", dummy);
+      m_Stopwords.put("v", dummy);
+      m_Stopwords.put("versus", dummy);
+      m_Stopwords.put("very", dummy);
+      m_Stopwords.put("via", dummy);
+      m_Stopwords.put("vice", dummy);
+      m_Stopwords.put("vis-a-vis", dummy);
+      m_Stopwords.put("w", dummy);
+      m_Stopwords.put("wanna", dummy);
+      m_Stopwords.put("wanting", dummy);
+      m_Stopwords.put("was", dummy);
+      m_Stopwords.put("wasn't", dummy);
+      m_Stopwords.put("way", dummy);
+      m_Stopwords.put("we", dummy);
+      m_Stopwords.put("we'd", dummy);
+      m_Stopwords.put("well", dummy);
+      m_Stopwords.put("were", dummy);
+      m_Stopwords.put("weren't", dummy);
+      m_Stopwords.put("wert", dummy);
+      m_Stopwords.put("we've", dummy);
+      m_Stopwords.put("what", dummy);
+      m_Stopwords.put("whatever", dummy);
+      m_Stopwords.put("what'll", dummy);
+      m_Stopwords.put("what's", dummy);
+      m_Stopwords.put("when", dummy);
+      m_Stopwords.put("whencesoever", dummy);
+      m_Stopwords.put("whenever", dummy);
+      m_Stopwords.put("when's", dummy);
+      m_Stopwords.put("whereas", dummy);
+      m_Stopwords.put("where's", dummy);
+      m_Stopwords.put("whether", dummy);
+      m_Stopwords.put("which", dummy);
+      m_Stopwords.put("whichever", dummy);
+      m_Stopwords.put("whichsoever", dummy);
+      m_Stopwords.put("while", dummy);
+      m_Stopwords.put("whilst", dummy);
+      m_Stopwords.put("who", dummy);
+      m_Stopwords.put("who'd", dummy);
+      m_Stopwords.put("whoever", dummy);
+      m_Stopwords.put("whole", dummy);
+      m_Stopwords.put("who'll", dummy);
+      m_Stopwords.put("whom", dummy);
+      m_Stopwords.put("whore", dummy);
+      m_Stopwords.put("who's", dummy);
+      m_Stopwords.put("whose", dummy);
+      m_Stopwords.put("whoso", dummy);
+      m_Stopwords.put("whosoever", dummy);
+      m_Stopwords.put("will", dummy);
+      m_Stopwords.put("with", dummy);
+      m_Stopwords.put("within", dummy);
+      m_Stopwords.put("without", dummy);
+      m_Stopwords.put("wont", dummy);
+      m_Stopwords.put("would", dummy);
+      m_Stopwords.put("wouldn't", dummy);
+      m_Stopwords.put("wouldst", dummy);
+      m_Stopwords.put("x", dummy);
+      m_Stopwords.put("y", dummy);
+      m_Stopwords.put("ye", dummy);
+      m_Stopwords.put("yet", dummy);
+      m_Stopwords.put("you", dummy);
+      m_Stopwords.put("you'd", dummy);
+      m_Stopwords.put("you'll", dummy);
+      m_Stopwords.put("your", dummy);
+      m_Stopwords.put("you're", dummy);
+      m_Stopwords.put("yours", dummy);
+      m_Stopwords.put("yourself", dummy);
+      m_Stopwords.put("yourselves", dummy);
+      m_Stopwords.put("you've", dummy);
+      m_Stopwords.put("z", dummy);
+    }
+  }
+  
+  /** 
+   * Returns true if the given string is a stop word.
+   */
+  public boolean isStopword(String str) {
+
+    return m_Stopwords.containsKey(str.toLowerCase());
+  }
+}
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/StopwordsGerman.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/StopwordsGerman.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/StopwordsGerman.java	(revision 16571)
@@ -0,0 +1,330 @@
+/*
+ *    StopwordsGerman.java
+ *    Copyright (C) 2001 Eibe Frank
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+import java.util.*;
+
+/**
+ * Class that can test whether a given string is a stop word.
+ * Lowercases all words before the test.
+ *
+ * This list of German stop words has been obtained from
+ * http://snowball.tartarus.org/german/stop.txt
+ *
+ * But I have deleted/changed some words that I haven't seen before.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version 1.0
+ */
+public class StopwordsGerman extends Stopwords {
+  
+  /** The hashtable containing the list of stopwords */
+  private static Hashtable m_Stopwords = null;
+
+  static {
+   
+    if (m_Stopwords == null) {
+      m_Stopwords = new Hashtable();
+      Double dummy = new Double(0);
+
+      m_Stopwords.put("aber", dummy);
+
+      m_Stopwords.put("alle", dummy);
+      m_Stopwords.put("allem", dummy);
+      m_Stopwords.put("allen", dummy);
+      m_Stopwords.put("aller", dummy);
+      m_Stopwords.put("alles", dummy);
+
+      m_Stopwords.put("als", dummy);
+      m_Stopwords.put("also", dummy);
+      m_Stopwords.put("am", dummy);
+      m_Stopwords.put("an", dummy);
+
+      m_Stopwords.put("ander", dummy);
+      m_Stopwords.put("andere", dummy);
+      m_Stopwords.put("anderem", dummy);
+      m_Stopwords.put("anderen", dummy);
+      m_Stopwords.put("anderer", dummy);
+      m_Stopwords.put("anderes", dummy);
+      m_Stopwords.put("anderm", dummy);
+      m_Stopwords.put("andern", dummy);
+      m_Stopwords.put("anders", dummy);
+
+      m_Stopwords.put("auch", dummy);
+      m_Stopwords.put("auf", dummy);
+      m_Stopwords.put("aus", dummy);
+      m_Stopwords.put("bei", dummy);
+      m_Stopwords.put("bin", dummy);
+      m_Stopwords.put("bis", dummy);
+      m_Stopwords.put("bist", dummy);
+      m_Stopwords.put("da", dummy);
+      m_Stopwords.put("damit", dummy);
+      m_Stopwords.put("dann", dummy);
+      
+      m_Stopwords.put("der", dummy);
+      m_Stopwords.put("den", dummy);
+      m_Stopwords.put("des", dummy);
+      m_Stopwords.put("dem", dummy);
+      m_Stopwords.put("die", dummy);
+      m_Stopwords.put("das", dummy);
+
+      m_Stopwords.put("da\u00df", dummy);
+
+      m_Stopwords.put("derselbe", dummy);
+      m_Stopwords.put("derselben", dummy);
+      m_Stopwords.put("denselben", dummy);
+      m_Stopwords.put("desselben", dummy);
+      m_Stopwords.put("demselben", dummy);
+      m_Stopwords.put("dieselbe", dummy);
+      m_Stopwords.put("dieselben", dummy);
+      m_Stopwords.put("dasselbe", dummy);
+
+      m_Stopwords.put("dazu", dummy);
+
+      m_Stopwords.put("dein", dummy);
+      m_Stopwords.put("deine", dummy);
+      m_Stopwords.put("deinem", dummy);
+      m_Stopwords.put("deinen", dummy);
+      m_Stopwords.put("deiner", dummy);
+      m_Stopwords.put("deines", dummy);
+
+      m_Stopwords.put("denn", dummy);
+      
+      m_Stopwords.put("derer", dummy);
+      m_Stopwords.put("dessen", dummy);
+      
+      m_Stopwords.put("dich", dummy);
+      m_Stopwords.put("dir", dummy);
+      m_Stopwords.put("du", dummy);
+
+      m_Stopwords.put("dies", dummy);
+      m_Stopwords.put("diese", dummy);
+      m_Stopwords.put("diesem", dummy);
+      m_Stopwords.put("diesen", dummy);
+      m_Stopwords.put("dieser", dummy);
+      m_Stopwords.put("dieses", dummy);
+
+      m_Stopwords.put("doch", dummy);
+      m_Stopwords.put("dort", dummy);
+
+      m_Stopwords.put("durch", dummy);
+
+      m_Stopwords.put("ein", dummy);
+      m_Stopwords.put("eine", dummy);
+      m_Stopwords.put("einem", dummy);
+      m_Stopwords.put("einen", dummy);
+      m_Stopwords.put("einer", dummy);
+      m_Stopwords.put("eines", dummy);
+
+      m_Stopwords.put("einig", dummy);
+      m_Stopwords.put("einige", dummy);
+      m_Stopwords.put("einigem", dummy);
+      m_Stopwords.put("einigen", dummy);
+      m_Stopwords.put("einiger", dummy);
+      m_Stopwords.put("einiges", dummy);
+
+      m_Stopwords.put("einmal", dummy);
+
+      m_Stopwords.put("er", dummy);
+      m_Stopwords.put("ihn", dummy);
+      m_Stopwords.put("ihm", dummy);
+
+      m_Stopwords.put("es", dummy);
+      m_Stopwords.put("etwas", dummy);
+
+      m_Stopwords.put("euer", dummy);
+      m_Stopwords.put("eure", dummy);
+      m_Stopwords.put("eurem", dummy);
+      m_Stopwords.put("euren", dummy);
+      m_Stopwords.put("eurer", dummy);
+      m_Stopwords.put("eures", dummy);
+
+      m_Stopwords.put("f\u00fcr", dummy);
+      m_Stopwords.put("gegen", dummy);
+      m_Stopwords.put("gewesen", dummy);
+      m_Stopwords.put("hab", dummy);
+      m_Stopwords.put("habe", dummy);
+      m_Stopwords.put("haben", dummy);
+      m_Stopwords.put("hat", dummy);
+      m_Stopwords.put("hatte", dummy);
+      m_Stopwords.put("hatten", dummy);
+      m_Stopwords.put("hier", dummy);
+      m_Stopwords.put("hin", dummy);
+      m_Stopwords.put("hinter", dummy);
+      
+      m_Stopwords.put("ich", dummy);
+      m_Stopwords.put("mich", dummy);
+      m_Stopwords.put("mir", dummy);
+
+      m_Stopwords.put("ihr", dummy);
+      m_Stopwords.put("ihre", dummy);
+      m_Stopwords.put("ihrem", dummy);
+      m_Stopwords.put("ihren", dummy);
+      m_Stopwords.put("ihrer", dummy);
+      m_Stopwords.put("ihres", dummy);
+      m_Stopwords.put("euch", dummy);
+
+      m_Stopwords.put("im", dummy);
+      m_Stopwords.put("in", dummy);
+      m_Stopwords.put("indem", dummy);
+      m_Stopwords.put("ins", dummy);
+      m_Stopwords.put("ist", dummy);
+
+      m_Stopwords.put("jede", dummy);
+      m_Stopwords.put("jedem", dummy);
+      m_Stopwords.put("jeden", dummy);
+      m_Stopwords.put("jeder", dummy);
+      m_Stopwords.put("jedes", dummy);
+
+      m_Stopwords.put("jene", dummy);
+      m_Stopwords.put("jenem", dummy);
+      m_Stopwords.put("jenen", dummy);
+      m_Stopwords.put("jener", dummy);
+      m_Stopwords.put("jenes", dummy);
+
+      m_Stopwords.put("jetzt", dummy);
+      m_Stopwords.put("kann", dummy);
+
+      m_Stopwords.put("kein", dummy);
+      m_Stopwords.put("keine", dummy);
+      m_Stopwords.put("keinem", dummy);
+      m_Stopwords.put("keinen", dummy);
+      m_Stopwords.put("keiner", dummy);
+      m_Stopwords.put("keines", dummy);
+
+      m_Stopwords.put("k\u00f6nnen", dummy);
+      m_Stopwords.put("k\u00f6nnte", dummy);
+      m_Stopwords.put("machen", dummy);
+      m_Stopwords.put("man", dummy);
+
+      m_Stopwords.put("manche", dummy);
+      m_Stopwords.put("manchem", dummy);
+      m_Stopwords.put("manchen", dummy);
+      m_Stopwords.put("mancher", dummy);
+      m_Stopwords.put("manches", dummy);
+
+      m_Stopwords.put("mein", dummy);
+      m_Stopwords.put("meine", dummy);
+      m_Stopwords.put("meinem", dummy);
+      m_Stopwords.put("meinen", dummy);
+      m_Stopwords.put("meiner", dummy);
+      m_Stopwords.put("meines", dummy);
+
+      m_Stopwords.put("mit", dummy);
+      m_Stopwords.put("muss", dummy);
+      m_Stopwords.put("musste", dummy);
+      m_Stopwords.put("nach", dummy);
+      m_Stopwords.put("nicht", dummy);
+      m_Stopwords.put("nichts", dummy);
+      m_Stopwords.put("noch", dummy);
+      m_Stopwords.put("nun", dummy);
+      m_Stopwords.put("nur", dummy);
+      m_Stopwords.put("ob", dummy);
+      m_Stopwords.put("oder", dummy);
+      m_Stopwords.put("ohne", dummy);
+      m_Stopwords.put("sehr", dummy);
+
+      m_Stopwords.put("sein", dummy);
+      m_Stopwords.put("seine", dummy);
+      m_Stopwords.put("seinem", dummy);
+      m_Stopwords.put("seinen", dummy);
+      m_Stopwords.put("seiner", dummy);
+      m_Stopwords.put("seines", dummy);
+
+      m_Stopwords.put("selbst", dummy);
+      m_Stopwords.put("sich", dummy);
+      
+      m_Stopwords.put("sie", dummy);
+      m_Stopwords.put("ihnen", dummy);
+
+      m_Stopwords.put("sind", dummy);
+      m_Stopwords.put("so", dummy);
+
+      m_Stopwords.put("solche", dummy);
+      m_Stopwords.put("solchem", dummy);
+      m_Stopwords.put("solchen", dummy);
+      m_Stopwords.put("solcher", dummy);
+      m_Stopwords.put("solches", dummy);
+
+      m_Stopwords.put("soll", dummy);
+      m_Stopwords.put("sollte", dummy);
+      m_Stopwords.put("sondern", dummy);
+      m_Stopwords.put("sonst", dummy);
+      m_Stopwords.put("\00fcber", dummy);
+      m_Stopwords.put("um", dummy);
+      m_Stopwords.put("und", dummy);
+
+      m_Stopwords.put("uns", dummy);
+      m_Stopwords.put("unser", dummy);
+      m_Stopwords.put("unserem", dummy);
+      m_Stopwords.put("unseren", dummy);
+      m_Stopwords.put("unsere", dummy);
+      m_Stopwords.put("unseres", dummy);
+
+      m_Stopwords.put("unter", dummy);
+      m_Stopwords.put("viel", dummy);
+      m_Stopwords.put("vom", dummy);
+      m_Stopwords.put("von", dummy);
+      m_Stopwords.put("vor", dummy);
+      m_Stopwords.put("w\u00e4hrend", dummy);
+      m_Stopwords.put("war", dummy);
+      m_Stopwords.put("waren", dummy);
+      m_Stopwords.put("warst", dummy);
+      m_Stopwords.put("was", dummy);
+      m_Stopwords.put("weg", dummy);
+      m_Stopwords.put("weil", dummy);
+      m_Stopwords.put("weiter", dummy);
+
+      m_Stopwords.put("welche", dummy);
+      m_Stopwords.put("welchem", dummy);
+      m_Stopwords.put("welchen", dummy);
+      m_Stopwords.put("welcher", dummy);
+      m_Stopwords.put("welches", dummy);
+
+      m_Stopwords.put("wenn", dummy);
+      m_Stopwords.put("werde", dummy);
+      m_Stopwords.put("werden", dummy);
+      m_Stopwords.put("wie", dummy);
+      m_Stopwords.put("wieder", dummy);
+      m_Stopwords.put("will", dummy);
+      m_Stopwords.put("wir", dummy);
+      m_Stopwords.put("wird", dummy);
+      m_Stopwords.put("wirst", dummy);
+      m_Stopwords.put("wo", dummy);
+      m_Stopwords.put("wollen", dummy);
+      m_Stopwords.put("wollte", dummy);
+      m_Stopwords.put("w\u00fcrde", dummy);
+      m_Stopwords.put("w\u00fcrden", dummy);
+      m_Stopwords.put("zu", dummy);
+      m_Stopwords.put("zum", dummy);
+      m_Stopwords.put("zur", dummy);
+      m_Stopwords.put("zwar", dummy);
+      m_Stopwords.put("zwischen", dummy);
+    }
+  }
+  
+  /** 
+   * Returns true if the given string is a stop word.
+   */
+  public boolean isStopword(String str) {
+
+    return m_Stopwords.containsKey(str.toLowerCase());
+  }
+}
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/Counter.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/Counter.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/Counter.html	(revision 16571)
@@ -0,0 +1,318 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:48 NZDT 2004 -->
+<TITLE>
+Counter
+</TITLE>
+<META NAME="keywords" CONTENT="Counter,Counter class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="Counter";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV CLASS&nbsp;
+&nbsp;<A HREF="GermanStemmer.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="Counter.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class Counter</H2>
+<PRE>
+java.lang.Object
+  |
+  +--<B>Counter</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>java.io.Serializable</DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>Counter</B><DT>extends java.lang.Object<DT>implements java.io.Serializable</DL>
+
+<P>
+Class that implements a simple counter.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="Counter">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="Counter.html#Counter()">Counter</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Initializes the counter to 1</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="Counter.html#Counter(int)">Counter</A></B>(int&nbsp;val)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Initializes the counter to the given value</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="Counter.html#increment()">increment</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Increments the counter.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="Counter.html#toString()">toString</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns string containing value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="Counter.html#value()">value</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gets the value.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="Counter()"><!-- --></A><H3>
+Counter</H3>
+<PRE>
+public <B>Counter</B>()</PRE>
+<DL>
+<DD>Initializes the counter to 1
+<P>
+</DL>
+<HR>
+
+<A NAME="Counter(int)"><!-- --></A><H3>
+Counter</H3>
+<PRE>
+public <B>Counter</B>(int&nbsp;val)</PRE>
+<DL>
+<DD>Initializes the counter to the given value
+<P>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="increment()"><!-- --></A><H3>
+increment</H3>
+<PRE>
+public void <B>increment</B>()</PRE>
+<DL>
+<DD>Increments the counter.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="value()"><!-- --></A><H3>
+value</H3>
+<PRE>
+public int <B>value</B>()</PRE>
+<DL>
+<DD>Gets the value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>the value</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="toString()"><!-- --></A><H3>
+toString</H3>
+<PRE>
+public java.lang.String <B>toString</B>()</PRE>
+<DL>
+<DD>Returns string containing value.
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE>toString</CODE> in class <CODE>java.lang.Object</CODE></DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV CLASS&nbsp;
+&nbsp;<A HREF="GermanStemmer.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="Counter.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/GermanStemmer.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/GermanStemmer.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/GermanStemmer.html	(revision 16571)
@@ -0,0 +1,268 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:49 NZDT 2004 -->
+<TITLE>
+GermanStemmer
+</TITLE>
+<META NAME="keywords" CONTENT="GermanStemmer,GermanStemmer class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="GermanStemmer";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="Counter.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="IteratedLovinsStemmer.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="GermanStemmer.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class GermanStemmer</H2>
+<PRE>
+java.lang.Object
+  |
+  +--<A HREF="Stemmer.html">Stemmer</A>
+        |
+        +--<B>GermanStemmer</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>java.io.Serializable</DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>GermanStemmer</B><DT>extends <A HREF="Stemmer.html">Stemmer</A></DL>
+
+<P>
+A stemmer for German words. The algorithm is based on the report
+ "A Fast and Simple Stemming Algorithm for German Words" by Jörg
+ Caumanns (joerg.caumanns@isst.fhg.de).
+
+ Changed stem() from protected to public.
+ Changed coding for umlaute to unicode.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="GermanStemmer">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="GermanStemmer.html#GermanStemmer()">GermanStemmer</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="GermanStemmer.html#stem(java.lang.String)">stem</A></B>(java.lang.String&nbsp;term)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stemms the given term to an unique <tt>discriminator</tt>.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_Stemmer"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class <A HREF="Stemmer.html">Stemmer</A></B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><A HREF="Stemmer.html#stemString(java.lang.String)">stemString</A></CODE></TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="GermanStemmer()"><!-- --></A><H3>
+GermanStemmer</H3>
+<PRE>
+public <B>GermanStemmer</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="stem(java.lang.String)"><!-- --></A><H3>
+stem</H3>
+<PRE>
+public java.lang.String <B>stem</B>(java.lang.String&nbsp;term)</PRE>
+<DL>
+<DD>Stemms the given term to an unique <tt>discriminator</tt>.
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE><A HREF="Stemmer.html#stem(java.lang.String)">stem</A></CODE> in class <CODE><A HREF="Stemmer.html">Stemmer</A></CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>term</CODE> - The term that should be stemmed.
+<DT><B>Returns:</B><DD>Discriminator for <tt>term</tt></DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="Counter.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="IteratedLovinsStemmer.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="GermanStemmer.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/IteratedLovinsStemmer.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/IteratedLovinsStemmer.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/IteratedLovinsStemmer.html	(revision 16571)
@@ -0,0 +1,285 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:49 NZDT 2004 -->
+<TITLE>
+IteratedLovinsStemmer
+</TITLE>
+<META NAME="keywords" CONTENT="IteratedLovinsStemmer,IteratedLovinsStemmer class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="IteratedLovinsStemmer";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="GermanStemmer.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="KEAFilter.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="IteratedLovinsStemmer.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class IteratedLovinsStemmer</H2>
+<PRE>
+java.lang.Object
+  |
+  +--<A HREF="Stemmer.html">Stemmer</A>
+        |
+        +--<A HREF="LovinsStemmer.html">LovinsStemmer</A>
+              |
+              +--<B>IteratedLovinsStemmer</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>java.io.Serializable</DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>IteratedLovinsStemmer</B><DT>extends <A HREF="LovinsStemmer.html">LovinsStemmer</A></DL>
+
+<P>
+Implements the iterated version of the Lovins stemmer.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="IteratedLovinsStemmer">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="IteratedLovinsStemmer.html#IteratedLovinsStemmer()">IteratedLovinsStemmer</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>static&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="IteratedLovinsStemmer.html#main(java.lang.String[])">main</A></B>(java.lang.String[]&nbsp;ops)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stems text coming into stdin and writes it to stdout.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="IteratedLovinsStemmer.html#stem(java.lang.String)">stem</A></B>(java.lang.String&nbsp;str)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Iterated stemming of the given word.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_Stemmer"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class <A HREF="Stemmer.html">Stemmer</A></B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><A HREF="Stemmer.html#stemString(java.lang.String)">stemString</A></CODE></TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="IteratedLovinsStemmer()"><!-- --></A><H3>
+IteratedLovinsStemmer</H3>
+<PRE>
+public <B>IteratedLovinsStemmer</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="stem(java.lang.String)"><!-- --></A><H3>
+stem</H3>
+<PRE>
+public java.lang.String <B>stem</B>(java.lang.String&nbsp;str)</PRE>
+<DL>
+<DD>Iterated stemming of the given word.
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE><A HREF="LovinsStemmer.html#stem(java.lang.String)">stem</A></CODE> in class <CODE><A HREF="LovinsStemmer.html">LovinsStemmer</A></CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>str</CODE> - a string consisting of a single word</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="main(java.lang.String[])"><!-- --></A><H3>
+main</H3>
+<PRE>
+public static void <B>main</B>(java.lang.String[]&nbsp;ops)</PRE>
+<DL>
+<DD>Stems text coming into stdin and writes it to stdout.
+<P>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="GermanStemmer.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="KEAFilter.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="IteratedLovinsStemmer.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAFilter.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAFilter.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAFilter.html	(revision 16571)
@@ -0,0 +1,1147 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:49 NZDT 2004 -->
+<TITLE>
+KEAFilter
+</TITLE>
+<META NAME="keywords" CONTENT="KEAFilter,KEAFilter class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="KEAFilter";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="IteratedLovinsStemmer.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="KEAKeyphraseExtractor.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="KEAFilter.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#fields_inherited_from_class_weka.filters.Filter">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class KEAFilter</H2>
+<PRE>
+java.lang.Object
+  |
+  +--weka.filters.Filter
+        |
+        +--<B>KEAFilter</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>weka.core.OptionHandler, java.io.Serializable</DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>KEAFilter</B><DT>extends weka.filters.Filter<DT>implements weka.core.OptionHandler</DL>
+
+<P>
+This filter converts the incoming data into data appropriate for
+ keyphrase classification. It assumes that the dataset contains two
+ string attributes. The first attribute should contain the text of a
+ document. The second attribute should contain the keyphrases
+ associated with that document (if present). 
+
+ The filter converts every instance (i.e. document) into a set of
+ instances, one for each word-based n-gram in the document. The
+ string attribute representing the document is replaced by some
+ numeric features, the estimated probability of each n-gram being a
+ keyphrase, and the rank of this phrase in the document according to
+ the probability.  Each new instances also has a class value
+ associated with it. The class is "true" if the n-gram is a true
+ keyphrase, and "false" otherwise. Of course, if the input document
+ doesn't come with author-assigned keyphrases, the class values for
+ that document will be missing.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="KEAFilter">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+<A NAME="field_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Field Summary</B></FONT></TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="fields_inherited_from_class_weka.filters.Filter"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Fields inherited from class weka.filters.Filter</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>m_NewBatch</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="KEAFilter.html#KEAFilter()">KEAFilter</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#batchFinished()">batchFinished</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Signify that this batch of input to the filter is finished.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getCheckForProperNouns()">getCheckForProperNouns</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the M_CheckProperNouns value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getDebug()">getDebug</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of Debug.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getDisallowInternalPeriods()">getDisallowInternalPeriods</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get whether the supplied columns are to be processed</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getDocumentAtt()">getDocumentAtt</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of DocumentAtt.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getKeyphrasesAtt()">getKeyphrasesAtt</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of KeyphraseAtt.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getKFused()">getKFused</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gets whether keyphrase frequency attribute is used.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getMaxPhraseLength()">getMaxPhraseLength</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of MaxPhraseLength.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getMinNumOccur()">getMinNumOccur</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of MinNumOccur.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getMinPhraseLength()">getMinPhraseLength</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of MinPhraseLength.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String[]</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getOptions()">getOptions</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gets the current settings of the filter.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getProbabilityIndex()">getProbabilityIndex</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the index of the phrases' probabilities in the output ARFF file.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getRankIndex()">getRankIndex</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the index of the phrases' ranks in the output ARFF file.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getStemmedPhraseIndex()">getStemmedPhraseIndex</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the index of the stemmed phrases in the output ARFF file.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;Stemmer</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getStemmer()">getStemmer</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the Stemmer value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;Stopwords</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getStopwords()">getStopwords</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the M_Stopwords value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#getUnstemmedPhraseIndex()">getUnstemmedPhraseIndex</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the index of the unstemmed phrases in the output ARFF file.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#globalInfo()">globalInfo</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a string describing this filter</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#input(weka.core.Instance)">input</A></B>(weka.core.Instance&nbsp;instance)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Input an instance for filtering.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.util.Enumeration</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#listOptions()">listOptions</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns an enumeration describing the available options</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>static&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#main(java.lang.String[])">main</A></B>(java.lang.String[]&nbsp;argv)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Main method for testing this class.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setCheckForProperNouns(boolean)">setCheckForProperNouns</A></B>(boolean&nbsp;newM_CheckProperNouns)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the M_CheckProperNouns value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setDebug(boolean)">setDebug</A></B>(boolean&nbsp;newDebug)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of Debug.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setDisallowInternalPeriods(boolean)">setDisallowInternalPeriods</A></B>(boolean&nbsp;disallow)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set whether selected columns should be processed.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setDocumentAtt(int)">setDocumentAtt</A></B>(int&nbsp;newDocumentAtt)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of DocumentAtt.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setInputFormat(weka.core.Instances)">setInputFormat</A></B>(weka.core.Instances&nbsp;instanceInfo)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets the format of the input instances.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setKeyphrasesAtt(int)">setKeyphrasesAtt</A></B>(int&nbsp;newKeyphrasesAtt)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of KeyphrasesAtt.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setKFused(boolean)">setKFused</A></B>(boolean&nbsp;flag)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets whether keyphrase frequency attribute is used.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setMaxPhraseLength(int)">setMaxPhraseLength</A></B>(int&nbsp;newMaxPhraseLength)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of MaxPhraseLength.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setMinNumOccur(int)">setMinNumOccur</A></B>(int&nbsp;newMinNumOccur)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of MinNumOccur.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setMinPhraseLength(int)">setMinPhraseLength</A></B>(int&nbsp;newMinPhraseLength)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of MinPhraseLength.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setOptions(java.lang.String[])">setOptions</A></B>(java.lang.String[]&nbsp;options)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parses a given list of options controlling the behaviour of this object.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setStemmer(Stemmer)">setStemmer</A></B>(Stemmer&nbsp;newStemmer)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the Stemmer value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAFilter.html#setStopwords(Stopwords)">setStopwords</A></B>(Stopwords&nbsp;newM_Stopwords)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the M_Stopwords value.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_weka.filters.Filter"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class weka.filters.Filter</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>batchFilterFile, bufferInput, copyStringValues, copyStringValues, filterFile, flushInput, getInputFormat, getInputStringIndex, getOutputFormat, getOutputStringIndex, getStringIndices, inputFormat, isOutputFormatDefined, numPendingOutput, output, outputFormat, outputFormatPeek, outputPeek, push, resetQueue, setOutputFormat, useFilter</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="KEAFilter()"><!-- --></A><H3>
+KEAFilter</H3>
+<PRE>
+public <B>KEAFilter</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="getCheckForProperNouns()"><!-- --></A><H3>
+getCheckForProperNouns</H3>
+<PRE>
+public boolean <B>getCheckForProperNouns</B>()</PRE>
+<DL>
+<DD>Get the M_CheckProperNouns value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>the M_CheckProperNouns value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setCheckForProperNouns(boolean)"><!-- --></A><H3>
+setCheckForProperNouns</H3>
+<PRE>
+public void <B>setCheckForProperNouns</B>(boolean&nbsp;newM_CheckProperNouns)</PRE>
+<DL>
+<DD>Set the M_CheckProperNouns value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newM_CheckProperNouns</CODE> - The new M_CheckProperNouns value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getStopwords()"><!-- --></A><H3>
+getStopwords</H3>
+<PRE>
+public Stopwords <B>getStopwords</B>()</PRE>
+<DL>
+<DD>Get the M_Stopwords value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>the M_Stopwords value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setStopwords(Stopwords)"><!-- --></A><H3>
+setStopwords</H3>
+<PRE>
+public void <B>setStopwords</B>(Stopwords&nbsp;newM_Stopwords)</PRE>
+<DL>
+<DD>Set the M_Stopwords value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newM_Stopwords</CODE> - The new M_Stopwords value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getStemmer()"><!-- --></A><H3>
+getStemmer</H3>
+<PRE>
+public Stemmer <B>getStemmer</B>()</PRE>
+<DL>
+<DD>Get the Stemmer value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>the Stemmer value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setStemmer(Stemmer)"><!-- --></A><H3>
+setStemmer</H3>
+<PRE>
+public void <B>setStemmer</B>(Stemmer&nbsp;newStemmer)</PRE>
+<DL>
+<DD>Set the Stemmer value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newStemmer</CODE> - The new Stemmer value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getMinNumOccur()"><!-- --></A><H3>
+getMinNumOccur</H3>
+<PRE>
+public int <B>getMinNumOccur</B>()</PRE>
+<DL>
+<DD>Get the value of MinNumOccur.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of MinNumOccur.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setMinNumOccur(int)"><!-- --></A><H3>
+setMinNumOccur</H3>
+<PRE>
+public void <B>setMinNumOccur</B>(int&nbsp;newMinNumOccur)</PRE>
+<DL>
+<DD>Set the value of MinNumOccur.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newMinNumOccur</CODE> - Value to assign to MinNumOccur.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getMaxPhraseLength()"><!-- --></A><H3>
+getMaxPhraseLength</H3>
+<PRE>
+public int <B>getMaxPhraseLength</B>()</PRE>
+<DL>
+<DD>Get the value of MaxPhraseLength.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of MaxPhraseLength.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setMaxPhraseLength(int)"><!-- --></A><H3>
+setMaxPhraseLength</H3>
+<PRE>
+public void <B>setMaxPhraseLength</B>(int&nbsp;newMaxPhraseLength)</PRE>
+<DL>
+<DD>Set the value of MaxPhraseLength.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newMaxPhraseLength</CODE> - Value to assign to MaxPhraseLength.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getMinPhraseLength()"><!-- --></A><H3>
+getMinPhraseLength</H3>
+<PRE>
+public int <B>getMinPhraseLength</B>()</PRE>
+<DL>
+<DD>Get the value of MinPhraseLength.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of MinPhraseLength.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setMinPhraseLength(int)"><!-- --></A><H3>
+setMinPhraseLength</H3>
+<PRE>
+public void <B>setMinPhraseLength</B>(int&nbsp;newMinPhraseLength)</PRE>
+<DL>
+<DD>Set the value of MinPhraseLength.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newMinPhraseLength</CODE> - Value to assign to MinPhraseLength.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getStemmedPhraseIndex()"><!-- --></A><H3>
+getStemmedPhraseIndex</H3>
+<PRE>
+public int <B>getStemmedPhraseIndex</B>()</PRE>
+<DL>
+<DD>Returns the index of the stemmed phrases in the output ARFF file.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getUnstemmedPhraseIndex()"><!-- --></A><H3>
+getUnstemmedPhraseIndex</H3>
+<PRE>
+public int <B>getUnstemmedPhraseIndex</B>()</PRE>
+<DL>
+<DD>Returns the index of the unstemmed phrases in the output ARFF file.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getProbabilityIndex()"><!-- --></A><H3>
+getProbabilityIndex</H3>
+<PRE>
+public int <B>getProbabilityIndex</B>()</PRE>
+<DL>
+<DD>Returns the index of the phrases' probabilities in the output ARFF file.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getRankIndex()"><!-- --></A><H3>
+getRankIndex</H3>
+<PRE>
+public int <B>getRankIndex</B>()</PRE>
+<DL>
+<DD>Returns the index of the phrases' ranks in the output ARFF file.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getDocumentAtt()"><!-- --></A><H3>
+getDocumentAtt</H3>
+<PRE>
+public int <B>getDocumentAtt</B>()</PRE>
+<DL>
+<DD>Get the value of DocumentAtt.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of DocumentAtt.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setDocumentAtt(int)"><!-- --></A><H3>
+setDocumentAtt</H3>
+<PRE>
+public void <B>setDocumentAtt</B>(int&nbsp;newDocumentAtt)</PRE>
+<DL>
+<DD>Set the value of DocumentAtt.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newDocumentAtt</CODE> - Value to assign to DocumentAtt.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getKeyphrasesAtt()"><!-- --></A><H3>
+getKeyphrasesAtt</H3>
+<PRE>
+public int <B>getKeyphrasesAtt</B>()</PRE>
+<DL>
+<DD>Get the value of KeyphraseAtt.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of KeyphraseAtt.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setKeyphrasesAtt(int)"><!-- --></A><H3>
+setKeyphrasesAtt</H3>
+<PRE>
+public void <B>setKeyphrasesAtt</B>(int&nbsp;newKeyphrasesAtt)</PRE>
+<DL>
+<DD>Set the value of KeyphrasesAtt.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newKeyphrasesAtt</CODE> - Value to assign to KeyphrasesAtt.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getDebug()"><!-- --></A><H3>
+getDebug</H3>
+<PRE>
+public boolean <B>getDebug</B>()</PRE>
+<DL>
+<DD>Get the value of Debug.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of Debug.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setDebug(boolean)"><!-- --></A><H3>
+setDebug</H3>
+<PRE>
+public void <B>setDebug</B>(boolean&nbsp;newDebug)</PRE>
+<DL>
+<DD>Set the value of Debug.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newDebug</CODE> - Value to assign to Debug.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setKFused(boolean)"><!-- --></A><H3>
+setKFused</H3>
+<PRE>
+public void <B>setKFused</B>(boolean&nbsp;flag)</PRE>
+<DL>
+<DD>Sets whether keyphrase frequency attribute is used.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getKFused()"><!-- --></A><H3>
+getKFused</H3>
+<PRE>
+public boolean <B>getKFused</B>()</PRE>
+<DL>
+<DD>Gets whether keyphrase frequency attribute is used.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getDisallowInternalPeriods()"><!-- --></A><H3>
+getDisallowInternalPeriods</H3>
+<PRE>
+public boolean <B>getDisallowInternalPeriods</B>()</PRE>
+<DL>
+<DD>Get whether the supplied columns are to be processed
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>true if the supplied columns won't be processed</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setDisallowInternalPeriods(boolean)"><!-- --></A><H3>
+setDisallowInternalPeriods</H3>
+<PRE>
+public void <B>setDisallowInternalPeriods</B>(boolean&nbsp;disallow)</PRE>
+<DL>
+<DD>Set whether selected columns should be processed. If true the 
+ selected columns won't be processed.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setOptions(java.lang.String[])"><!-- --></A><H3>
+setOptions</H3>
+<PRE>
+public void <B>setOptions</B>(java.lang.String[]&nbsp;options)
+                throws java.lang.Exception</PRE>
+<DL>
+<DD>Parses a given list of options controlling the behaviour of this object.
+ Valid options are:<p>
+
+ -K<br>
+ Specifies whether keyphrase frequency statistic is used.<p>
+
+ -M length<br>
+ Sets the maximum phrase length (default: 3).<p>
+
+ -L length<br>
+ Sets the minimum phrase length (default: 1).<p>
+
+ -D<br>
+ Turns debugging mode on.<p>
+
+ -I index<br>
+ Sets the index of the attribute containing the documents (default: 0).<p>
+
+ -J index<br>
+ Sets the index of the attribute containing the keyphrases (default: 1).<p>
+
+ -P<br>
+ Disallow internal periods <p>
+
+ -O number<br>
+ The minimum number of times a phrase needs to occur (default: 2). <p>
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>setOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>options</CODE> - the list of options as an array of strings
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.Exception</CODE> - if an option is not supported</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getOptions()"><!-- --></A><H3>
+getOptions</H3>
+<PRE>
+public java.lang.String[] <B>getOptions</B>()</PRE>
+<DL>
+<DD>Gets the current settings of the filter.
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>getOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>an array of strings suitable for passing to setOptions</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="listOptions()"><!-- --></A><H3>
+listOptions</H3>
+<PRE>
+public java.util.Enumeration <B>listOptions</B>()</PRE>
+<DL>
+<DD>Returns an enumeration describing the available options
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>listOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>an enumeration of all the available options</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="globalInfo()"><!-- --></A><H3>
+globalInfo</H3>
+<PRE>
+public java.lang.String <B>globalInfo</B>()</PRE>
+<DL>
+<DD>Returns a string describing this filter
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>a description of the filter suitable for
+ displaying in the explorer/experimenter gui</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setInputFormat(weka.core.Instances)"><!-- --></A><H3>
+setInputFormat</H3>
+<PRE>
+public boolean <B>setInputFormat</B>(weka.core.Instances&nbsp;instanceInfo)
+                       throws java.lang.Exception</PRE>
+<DL>
+<DD>Sets the format of the input instances.
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE>setInputFormat</CODE> in class <CODE>weka.filters.Filter</CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>instanceInfo</CODE> - an Instances object containing the input
+ instance structure (any instances contained in the object are
+ ignored - only the structure is required).
+<DT><B>Returns:</B><DD>true if the outputFormat may be collected immediately
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="input(weka.core.Instance)"><!-- --></A><H3>
+input</H3>
+<PRE>
+public boolean <B>input</B>(weka.core.Instance&nbsp;instance)
+              throws java.lang.Exception</PRE>
+<DL>
+<DD>Input an instance for filtering. Ordinarily the instance is processed
+ and made available for output immediately. Some filters require all
+ instances be read before producing output.
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE>input</CODE> in class <CODE>weka.filters.Filter</CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>instance</CODE> - the input instance
+<DT><B>Returns:</B><DD>true if the filtered instance may now be
+ collected with output().
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.Exception</CODE> - if the input instance was not of the correct 
+ format or if there was a problem with the filtering.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="batchFinished()"><!-- --></A><H3>
+batchFinished</H3>
+<PRE>
+public boolean <B>batchFinished</B>()
+                      throws java.lang.Exception</PRE>
+<DL>
+<DD>Signify that this batch of input to the filter is finished. 
+ If the filter requires all instances prior to filtering,
+ output() may now be called to retrieve the filtered instances.
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE>batchFinished</CODE> in class <CODE>weka.filters.Filter</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>true if there are instances pending output
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.Exception</CODE> - if no input structure has been defined</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="main(java.lang.String[])"><!-- --></A><H3>
+main</H3>
+<PRE>
+public static void <B>main</B>(java.lang.String[]&nbsp;argv)</PRE>
+<DL>
+<DD>Main method for testing this class.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>argv</CODE> - should contain arguments to the filter: use -h for help</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="IteratedLovinsStemmer.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="KEAKeyphraseExtractor.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="KEAFilter.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#fields_inherited_from_class_weka.filters.Filter">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAKeyphraseExtractor.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAKeyphraseExtractor.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAKeyphraseExtractor.html	(revision 16571)
@@ -0,0 +1,742 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:49 NZDT 2004 -->
+<TITLE>
+KEAKeyphraseExtractor
+</TITLE>
+<META NAME="keywords" CONTENT="KEAKeyphraseExtractor,KEAKeyphraseExtractor class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="KEAKeyphraseExtractor";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="KEAFilter.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="KEAModelBuilder.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="KEAKeyphraseExtractor.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class KEAKeyphraseExtractor</H2>
+<PRE>
+java.lang.Object
+  |
+  +--<B>KEAKeyphraseExtractor</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>weka.core.OptionHandler</DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>KEAKeyphraseExtractor</B><DT>extends java.lang.Object<DT>implements weka.core.OptionHandler</DL>
+
+<P>
+Extracts keyphrases from the documents in a given directory.
+ Assumes that the file names for the documents end with ".txt".
+ Puts extracted keyphrases into corresponding files ending with
+ ".key" (if those are not already present). Optionally an encoding
+ for the documents/keyphrases can be defined (e.g. for Chinese
+ text). Documents for which ".key" exists, are used for evaluation.
+
+ Valid options are:<p>
+
+ -l "directory name"<br>
+ Specifies name of directory.<p>
+
+ -m "model name"<br>
+ Specifies name of model.<p>
+
+ -e "encoding"<br>
+ Specifies encoding.<p>
+
+ -n <br>
+ Specifies number of phrases to be output (default: 5).<p>
+
+ -d<br>
+ Turns debugging mode on.<p>
+
+ -a<br>
+ Also write stemmed phrase and score into ".key" file.<p>
+<P>
+
+<P>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#KEAKeyphraseExtractor()">KEAKeyphraseExtractor</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.util.Hashtable</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#collectStems()">collectStems</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Collects the stems of the file names.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#extractKeyphrases(java.util.Hashtable)">extractKeyphrases</A></B>(java.util.Hashtable&nbsp;stems)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Builds the model from the files</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#getAdditionalInfo()">getAdditionalInfo</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of AdditionalInfo.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#getDebug()">getDebug</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of debug.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#getDirName()">getDirName</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of dirName.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#getEncoding()">getEncoding</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of encoding.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#getModelName()">getModelName</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of modelName.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#getNumPhrases()">getNumPhrases</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of numPhrases.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String[]</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#getOptions()">getOptions</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gets the current option settings.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.util.Enumeration</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#listOptions()">listOptions</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns an enumeration describing the available options.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#loadModel()">loadModel</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Loads the extraction model from the file.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>static&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#main(java.lang.String[])">main</A></B>(java.lang.String[]&nbsp;ops)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The main method.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#setAdditionalInfo(boolean)">setAdditionalInfo</A></B>(boolean&nbsp;newAdditionalInfo)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of AdditionalInfo.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#setDebug(boolean)">setDebug</A></B>(boolean&nbsp;newdebug)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of debug.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#setDirName(java.lang.String)">setDirName</A></B>(java.lang.String&nbsp;newdirName)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of dirName.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#setEncoding(java.lang.String)">setEncoding</A></B>(java.lang.String&nbsp;newencoding)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of encoding.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#setModelName(java.lang.String)">setModelName</A></B>(java.lang.String&nbsp;newmodelName)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of modelName.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#setNumPhrases(int)">setNumPhrases</A></B>(int&nbsp;newnumPhrases)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of numPhrases.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAKeyphraseExtractor.html#setOptions(java.lang.String[])">setOptions</A></B>(java.lang.String[]&nbsp;options)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parses a given list of options controlling the behaviour of this object.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="KEAKeyphraseExtractor()"><!-- --></A><H3>
+KEAKeyphraseExtractor</H3>
+<PRE>
+public <B>KEAKeyphraseExtractor</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="getAdditionalInfo()"><!-- --></A><H3>
+getAdditionalInfo</H3>
+<PRE>
+public boolean <B>getAdditionalInfo</B>()</PRE>
+<DL>
+<DD>Get the value of AdditionalInfo.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of AdditionalInfo.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setAdditionalInfo(boolean)"><!-- --></A><H3>
+setAdditionalInfo</H3>
+<PRE>
+public void <B>setAdditionalInfo</B>(boolean&nbsp;newAdditionalInfo)</PRE>
+<DL>
+<DD>Set the value of AdditionalInfo.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newAdditionalInfo</CODE> - Value to assign to AdditionalInfo.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getNumPhrases()"><!-- --></A><H3>
+getNumPhrases</H3>
+<PRE>
+public int <B>getNumPhrases</B>()</PRE>
+<DL>
+<DD>Get the value of numPhrases.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of numPhrases.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setNumPhrases(int)"><!-- --></A><H3>
+setNumPhrases</H3>
+<PRE>
+public void <B>setNumPhrases</B>(int&nbsp;newnumPhrases)</PRE>
+<DL>
+<DD>Set the value of numPhrases.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newnumPhrases</CODE> - Value to assign to numPhrases.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getDebug()"><!-- --></A><H3>
+getDebug</H3>
+<PRE>
+public boolean <B>getDebug</B>()</PRE>
+<DL>
+<DD>Get the value of debug.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of debug.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setDebug(boolean)"><!-- --></A><H3>
+setDebug</H3>
+<PRE>
+public void <B>setDebug</B>(boolean&nbsp;newdebug)</PRE>
+<DL>
+<DD>Set the value of debug.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newdebug</CODE> - Value to assign to debug.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getEncoding()"><!-- --></A><H3>
+getEncoding</H3>
+<PRE>
+public java.lang.String <B>getEncoding</B>()</PRE>
+<DL>
+<DD>Get the value of encoding.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of encoding.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setEncoding(java.lang.String)"><!-- --></A><H3>
+setEncoding</H3>
+<PRE>
+public void <B>setEncoding</B>(java.lang.String&nbsp;newencoding)</PRE>
+<DL>
+<DD>Set the value of encoding.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newencoding</CODE> - Value to assign to encoding.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getModelName()"><!-- --></A><H3>
+getModelName</H3>
+<PRE>
+public java.lang.String <B>getModelName</B>()</PRE>
+<DL>
+<DD>Get the value of modelName.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of modelName.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setModelName(java.lang.String)"><!-- --></A><H3>
+setModelName</H3>
+<PRE>
+public void <B>setModelName</B>(java.lang.String&nbsp;newmodelName)</PRE>
+<DL>
+<DD>Set the value of modelName.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newmodelName</CODE> - Value to assign to modelName.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getDirName()"><!-- --></A><H3>
+getDirName</H3>
+<PRE>
+public java.lang.String <B>getDirName</B>()</PRE>
+<DL>
+<DD>Get the value of dirName.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of dirName.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setDirName(java.lang.String)"><!-- --></A><H3>
+setDirName</H3>
+<PRE>
+public void <B>setDirName</B>(java.lang.String&nbsp;newdirName)</PRE>
+<DL>
+<DD>Set the value of dirName.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newdirName</CODE> - Value to assign to dirName.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setOptions(java.lang.String[])"><!-- --></A><H3>
+setOptions</H3>
+<PRE>
+public void <B>setOptions</B>(java.lang.String[]&nbsp;options)
+                throws java.lang.Exception</PRE>
+<DL>
+<DD>Parses a given list of options controlling the behaviour of this object.
+ Valid options are:<p>
+
+ -l "directory name"<br>
+ Specifies name of directory.<p>
+
+ -m "model name"<br>
+ Specifies name of model.<p>
+
+ -e "encoding"<br>
+ Specifies encoding.<p>
+
+ -n<br>
+ Specifies number of phrases to be output (default: 5).<p>
+
+ -d<br>
+ Turns debugging mode on.<p>
+
+ -a<br>
+ Also write stemmed phrase and score into ".key" file.<p>
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>setOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>options</CODE> - the list of options as an array of strings
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.Exception</CODE> - if an option is not supported</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getOptions()"><!-- --></A><H3>
+getOptions</H3>
+<PRE>
+public java.lang.String[] <B>getOptions</B>()</PRE>
+<DL>
+<DD>Gets the current option settings.
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>getOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>an array of strings suitable for passing to setOptions</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="listOptions()"><!-- --></A><H3>
+listOptions</H3>
+<PRE>
+public java.util.Enumeration <B>listOptions</B>()</PRE>
+<DL>
+<DD>Returns an enumeration describing the available options.
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>listOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>an enumeration of all the available options</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="collectStems()"><!-- --></A><H3>
+collectStems</H3>
+<PRE>
+public java.util.Hashtable <B>collectStems</B>()
+                                 throws java.lang.Exception</PRE>
+<DL>
+<DD>Collects the stems of the file names.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="extractKeyphrases(java.util.Hashtable)"><!-- --></A><H3>
+extractKeyphrases</H3>
+<PRE>
+public void <B>extractKeyphrases</B>(java.util.Hashtable&nbsp;stems)
+                       throws java.lang.Exception</PRE>
+<DL>
+<DD>Builds the model from the files
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="loadModel()"><!-- --></A><H3>
+loadModel</H3>
+<PRE>
+public void <B>loadModel</B>()
+               throws java.lang.Exception</PRE>
+<DL>
+<DD>Loads the extraction model from the file.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="main(java.lang.String[])"><!-- --></A><H3>
+main</H3>
+<PRE>
+public static void <B>main</B>(java.lang.String[]&nbsp;ops)</PRE>
+<DL>
+<DD>The main method.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="KEAFilter.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="KEAModelBuilder.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="KEAKeyphraseExtractor.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAModelBuilder.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAModelBuilder.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAModelBuilder.html	(revision 16571)
@@ -0,0 +1,1072 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:49 NZDT 2004 -->
+<TITLE>
+KEAModelBuilder
+</TITLE>
+<META NAME="keywords" CONTENT="KEAModelBuilder,KEAModelBuilder class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="KEAModelBuilder";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="KEAKeyphraseExtractor.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="KEAPhraseFilter.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="KEAModelBuilder.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class KEAModelBuilder</H2>
+<PRE>
+java.lang.Object
+  |
+  +--<B>KEAModelBuilder</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>weka.core.OptionHandler</DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>KEAModelBuilder</B><DT>extends java.lang.Object<DT>implements weka.core.OptionHandler</DL>
+
+<P>
+Builds a keyphrase extraction model from the documents in a given
+ directory.  Assumes that the file names for the documents end with
+ ".txt".  Assumes that files containing corresponding
+ author-assigned keyphrases end with ".key". Optionally an encoding
+ for the documents/keyphrases can be defined (e.g. for Chinese
+ text).
+
+ Valid options are:<p>
+
+ -l "directory name"<br>
+ Specifies name of directory.<p>
+
+ -m "model name"<br>
+ Specifies name of model.<p>
+
+ -e "encoding"<br>
+ Specifies encoding.<p>
+
+ -d<br>
+ Turns debugging mode on.<p>
+
+ -k<br>
+ Use keyphrase frequency statistic.<p>
+
+ -p<br>
+ Disallow internal periods.<p>
+
+ -x "length"<br>
+ Sets maximum phrase length (default: 3).<p>
+
+ -y "length"<br>
+ Sets minimum phrase length (default: 1).<p>
+
+ -o "number"<br>
+ The minimum number of times a phrase needs to occur (default: 2). <p>
+
+ -s "name of class implementing list of stop words"<br>
+ Sets list of stop words to used (default: StopwordsEnglish).<p>
+
+ -t "name of class implementing stemmer"<br>
+ Sets stemmer to use (default: IteratedLovinsStemmer). <p>
+
+ -n<br>
+ Do not check for proper nouns. <p>
+<P>
+
+<P>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="KEAModelBuilder.html#KEAModelBuilder()">KEAModelBuilder</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#buildModel(java.util.Hashtable)">buildModel</A></B>(java.util.Hashtable&nbsp;stems)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Builds the model from the files</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.util.Hashtable</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#collectStems()">collectStems</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Collects the stems of the file names.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getCheckForProperNouns()">getCheckForProperNouns</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the M_CheckProperNouns value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getDebug()">getDebug</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of debug.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getDirName()">getDirName</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of dirName.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getDisallowIPeriods()">getDisallowIPeriods</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of disallowIPeriods.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getEncoding()">getEncoding</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of encoding.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getMaxPhraseLength()">getMaxPhraseLength</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of MaxPhraseLength.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getMinNumOccur()">getMinNumOccur</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of MinNumOccur.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;int</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getMinPhraseLength()">getMinPhraseLength</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of MinPhraseLength.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getModelName()">getModelName</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of modelName.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String[]</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getOptions()">getOptions</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gets the current option settings.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;Stemmer</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getStemmer()">getStemmer</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the Stemmer value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;Stopwords</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getStopwords()">getStopwords</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the M_Stopwords value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#getUseKFrequency()">getUseKFrequency</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the value of useKFrequency.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.util.Enumeration</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#listOptions()">listOptions</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns an enumeration describing the available options.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>static&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#main(java.lang.String[])">main</A></B>(java.lang.String[]&nbsp;ops)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The main method.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#saveModel()">saveModel</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Saves the extraction model to the file.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setCheckForProperNouns(boolean)">setCheckForProperNouns</A></B>(boolean&nbsp;newM_CheckProperNouns)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the M_CheckProperNouns value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setDebug(boolean)">setDebug</A></B>(boolean&nbsp;newdebug)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of debug.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setDirName(java.lang.String)">setDirName</A></B>(java.lang.String&nbsp;newdirName)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of dirName.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setDisallowIPeriods(boolean)">setDisallowIPeriods</A></B>(boolean&nbsp;newdisallowIPeriods)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of disallowIPeriods.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setEncoding(java.lang.String)">setEncoding</A></B>(java.lang.String&nbsp;newencoding)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of encoding.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setMaxPhraseLength(int)">setMaxPhraseLength</A></B>(int&nbsp;newMaxPhraseLength)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of MaxPhraseLength.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setMinNumOccur(int)">setMinNumOccur</A></B>(int&nbsp;newMinNumOccur)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of MinNumOccur.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setMinPhraseLength(int)">setMinPhraseLength</A></B>(int&nbsp;newMinPhraseLength)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of MinPhraseLength.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setModelName(java.lang.String)">setModelName</A></B>(java.lang.String&nbsp;newmodelName)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of modelName.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setOptions(java.lang.String[])">setOptions</A></B>(java.lang.String[]&nbsp;options)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parses a given list of options controlling the behaviour of this object.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setStemmer(Stemmer)">setStemmer</A></B>(Stemmer&nbsp;newStemmer)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the Stemmer value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setStopwords(Stopwords)">setStopwords</A></B>(Stopwords&nbsp;newM_Stopwords)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the M_Stopwords value.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAModelBuilder.html#setUseKFrequency(boolean)">setUseKFrequency</A></B>(boolean&nbsp;newuseKFrequency)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of useKFrequency.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="KEAModelBuilder()"><!-- --></A><H3>
+KEAModelBuilder</H3>
+<PRE>
+public <B>KEAModelBuilder</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="getCheckForProperNouns()"><!-- --></A><H3>
+getCheckForProperNouns</H3>
+<PRE>
+public boolean <B>getCheckForProperNouns</B>()</PRE>
+<DL>
+<DD>Get the M_CheckProperNouns value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>the M_CheckProperNouns value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setCheckForProperNouns(boolean)"><!-- --></A><H3>
+setCheckForProperNouns</H3>
+<PRE>
+public void <B>setCheckForProperNouns</B>(boolean&nbsp;newM_CheckProperNouns)</PRE>
+<DL>
+<DD>Set the M_CheckProperNouns value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newM_CheckProperNouns</CODE> - The new M_CheckProperNouns value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getStopwords()"><!-- --></A><H3>
+getStopwords</H3>
+<PRE>
+public Stopwords <B>getStopwords</B>()</PRE>
+<DL>
+<DD>Get the M_Stopwords value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>the M_Stopwords value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setStopwords(Stopwords)"><!-- --></A><H3>
+setStopwords</H3>
+<PRE>
+public void <B>setStopwords</B>(Stopwords&nbsp;newM_Stopwords)</PRE>
+<DL>
+<DD>Set the M_Stopwords value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newM_Stopwords</CODE> - The new M_Stopwords value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getStemmer()"><!-- --></A><H3>
+getStemmer</H3>
+<PRE>
+public Stemmer <B>getStemmer</B>()</PRE>
+<DL>
+<DD>Get the Stemmer value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>the Stemmer value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setStemmer(Stemmer)"><!-- --></A><H3>
+setStemmer</H3>
+<PRE>
+public void <B>setStemmer</B>(Stemmer&nbsp;newStemmer)</PRE>
+<DL>
+<DD>Set the Stemmer value.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newStemmer</CODE> - The new Stemmer value.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getMinNumOccur()"><!-- --></A><H3>
+getMinNumOccur</H3>
+<PRE>
+public int <B>getMinNumOccur</B>()</PRE>
+<DL>
+<DD>Get the value of MinNumOccur.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of MinNumOccur.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setMinNumOccur(int)"><!-- --></A><H3>
+setMinNumOccur</H3>
+<PRE>
+public void <B>setMinNumOccur</B>(int&nbsp;newMinNumOccur)</PRE>
+<DL>
+<DD>Set the value of MinNumOccur.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newMinNumOccur</CODE> - Value to assign to MinNumOccur.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getMaxPhraseLength()"><!-- --></A><H3>
+getMaxPhraseLength</H3>
+<PRE>
+public int <B>getMaxPhraseLength</B>()</PRE>
+<DL>
+<DD>Get the value of MaxPhraseLength.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of MaxPhraseLength.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setMaxPhraseLength(int)"><!-- --></A><H3>
+setMaxPhraseLength</H3>
+<PRE>
+public void <B>setMaxPhraseLength</B>(int&nbsp;newMaxPhraseLength)</PRE>
+<DL>
+<DD>Set the value of MaxPhraseLength.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newMaxPhraseLength</CODE> - Value to assign to MaxPhraseLength.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getMinPhraseLength()"><!-- --></A><H3>
+getMinPhraseLength</H3>
+<PRE>
+public int <B>getMinPhraseLength</B>()</PRE>
+<DL>
+<DD>Get the value of MinPhraseLength.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of MinPhraseLength.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setMinPhraseLength(int)"><!-- --></A><H3>
+setMinPhraseLength</H3>
+<PRE>
+public void <B>setMinPhraseLength</B>(int&nbsp;newMinPhraseLength)</PRE>
+<DL>
+<DD>Set the value of MinPhraseLength.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newMinPhraseLength</CODE> - Value to assign to MinPhraseLength.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getDisallowIPeriods()"><!-- --></A><H3>
+getDisallowIPeriods</H3>
+<PRE>
+public boolean <B>getDisallowIPeriods</B>()</PRE>
+<DL>
+<DD>Get the value of disallowIPeriods.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of disallowIPeriods.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setDisallowIPeriods(boolean)"><!-- --></A><H3>
+setDisallowIPeriods</H3>
+<PRE>
+public void <B>setDisallowIPeriods</B>(boolean&nbsp;newdisallowIPeriods)</PRE>
+<DL>
+<DD>Set the value of disallowIPeriods.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newdisallowIPeriods</CODE> - Value to assign to disallowIPeriods.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getUseKFrequency()"><!-- --></A><H3>
+getUseKFrequency</H3>
+<PRE>
+public boolean <B>getUseKFrequency</B>()</PRE>
+<DL>
+<DD>Get the value of useKFrequency.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of useKFrequency.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setUseKFrequency(boolean)"><!-- --></A><H3>
+setUseKFrequency</H3>
+<PRE>
+public void <B>setUseKFrequency</B>(boolean&nbsp;newuseKFrequency)</PRE>
+<DL>
+<DD>Set the value of useKFrequency.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newuseKFrequency</CODE> - Value to assign to useKFrequency.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getDebug()"><!-- --></A><H3>
+getDebug</H3>
+<PRE>
+public boolean <B>getDebug</B>()</PRE>
+<DL>
+<DD>Get the value of debug.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of debug.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setDebug(boolean)"><!-- --></A><H3>
+setDebug</H3>
+<PRE>
+public void <B>setDebug</B>(boolean&nbsp;newdebug)</PRE>
+<DL>
+<DD>Set the value of debug.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newdebug</CODE> - Value to assign to debug.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getEncoding()"><!-- --></A><H3>
+getEncoding</H3>
+<PRE>
+public java.lang.String <B>getEncoding</B>()</PRE>
+<DL>
+<DD>Get the value of encoding.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of encoding.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setEncoding(java.lang.String)"><!-- --></A><H3>
+setEncoding</H3>
+<PRE>
+public void <B>setEncoding</B>(java.lang.String&nbsp;newencoding)</PRE>
+<DL>
+<DD>Set the value of encoding.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newencoding</CODE> - Value to assign to encoding.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getModelName()"><!-- --></A><H3>
+getModelName</H3>
+<PRE>
+public java.lang.String <B>getModelName</B>()</PRE>
+<DL>
+<DD>Get the value of modelName.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of modelName.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setModelName(java.lang.String)"><!-- --></A><H3>
+setModelName</H3>
+<PRE>
+public void <B>setModelName</B>(java.lang.String&nbsp;newmodelName)</PRE>
+<DL>
+<DD>Set the value of modelName.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newmodelName</CODE> - Value to assign to modelName.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getDirName()"><!-- --></A><H3>
+getDirName</H3>
+<PRE>
+public java.lang.String <B>getDirName</B>()</PRE>
+<DL>
+<DD>Get the value of dirName.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>Value of dirName.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setDirName(java.lang.String)"><!-- --></A><H3>
+setDirName</H3>
+<PRE>
+public void <B>setDirName</B>(java.lang.String&nbsp;newdirName)</PRE>
+<DL>
+<DD>Set the value of dirName.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>newdirName</CODE> - Value to assign to dirName.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setOptions(java.lang.String[])"><!-- --></A><H3>
+setOptions</H3>
+<PRE>
+public void <B>setOptions</B>(java.lang.String[]&nbsp;options)
+                throws java.lang.Exception</PRE>
+<DL>
+<DD>Parses a given list of options controlling the behaviour of this object.
+ Valid options are:<p>
+
+ -l "directory name" <br>
+ Specifies name of directory.<p>
+
+ -m "model name" <br>
+ Specifies name of model.<p>
+
+ -e "encoding" <br>
+ Specifies encoding.<p>
+
+ -d<br>
+ Turns debugging mode on.<p>
+
+ -k<br>
+ Use keyphrase frequency statistic.<p>
+
+ -p<br>
+ Disallow internal periods. <p>
+
+ -x "length"<br>
+ Sets maximum phrase length (default: 3).<p>
+
+ -y "length"<br>
+ Sets minimum phrase length (default: 3).<p>
+
+ -o "number"<br>
+ The minimum number of times a phrase needs to occur (default: 2). <p>
+
+ -s "name of class implementing list of stop words"<br>
+ Sets list of stop words to used (default: StopwordsEnglish).<p>
+
+ -t "name of class implementing stemmer"<br>
+ Sets stemmer to use (default: IteratedLovinsStemmer). <p>
+
+ -n<br>
+ Do not check for proper nouns. <p>
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>setOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>options</CODE> - the list of options as an array of strings
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.Exception</CODE> - if an option is not supported</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getOptions()"><!-- --></A><H3>
+getOptions</H3>
+<PRE>
+public java.lang.String[] <B>getOptions</B>()</PRE>
+<DL>
+<DD>Gets the current option settings.
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>getOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>an array of strings suitable for passing to setOptions</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="listOptions()"><!-- --></A><H3>
+listOptions</H3>
+<PRE>
+public java.util.Enumeration <B>listOptions</B>()</PRE>
+<DL>
+<DD>Returns an enumeration describing the available options.
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>listOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>an enumeration of all the available options</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="collectStems()"><!-- --></A><H3>
+collectStems</H3>
+<PRE>
+public java.util.Hashtable <B>collectStems</B>()
+                                 throws java.lang.Exception</PRE>
+<DL>
+<DD>Collects the stems of the file names.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="buildModel(java.util.Hashtable)"><!-- --></A><H3>
+buildModel</H3>
+<PRE>
+public void <B>buildModel</B>(java.util.Hashtable&nbsp;stems)
+                throws java.lang.Exception</PRE>
+<DL>
+<DD>Builds the model from the files
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="saveModel()"><!-- --></A><H3>
+saveModel</H3>
+<PRE>
+public void <B>saveModel</B>()
+               throws java.lang.Exception</PRE>
+<DL>
+<DD>Saves the extraction model to the file.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="main(java.lang.String[])"><!-- --></A><H3>
+main</H3>
+<PRE>
+public static void <B>main</B>(java.lang.String[]&nbsp;ops)</PRE>
+<DL>
+<DD>The main method.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="KEAKeyphraseExtractor.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="KEAPhraseFilter.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="KEAModelBuilder.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAPhraseFilter.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAPhraseFilter.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/KEAPhraseFilter.html	(revision 16571)
@@ -0,0 +1,817 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:49 NZDT 2004 -->
+<TITLE>
+KEAPhraseFilter
+</TITLE>
+<META NAME="keywords" CONTENT="KEAPhraseFilter,KEAPhraseFilter class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="KEAPhraseFilter";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="KEAModelBuilder.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="LovinsStemmer.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="KEAPhraseFilter.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class KEAPhraseFilter</H2>
+<PRE>
+java.lang.Object
+  |
+  +--weka.filters.Filter
+        |
+        +--<B>KEAPhraseFilter</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>weka.core.OptionHandler, java.io.Serializable</DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>KEAPhraseFilter</B><DT>extends weka.filters.Filter<DT>implements weka.core.OptionHandler</DL>
+
+<P>
+This filter splits the text in selected string
+ attributes into phrases. The resulting
+ string attributes contain these phrases
+ separated by '\n' characters.
+
+ Phrases are identified according to the
+ following definitions:
+ 
+ A phrase is a sequence of words interrupted
+ only by sequences of whitespace characters,
+ where each sequence of whitespace characters
+ contains at most one '\n'.
+
+ A word is a sequence of letters or digits
+ that contains at least one letter, with
+ the following exceptions:
+
+ a) '.', '@', '_', '&', '/', '-' are allowed
+ if surrounded by letters or digits,
+
+ b) '\'' is allowed if preceeded by a letter
+ or digit,
+ 
+ c) '-', '/' are also allowed if succeeded by
+ whitespace characters followed by another
+ word. In that case the whitespace characters
+ will be deleted.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="KEAPhraseFilter">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+<A NAME="field_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Field Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>protected &nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#m_DisallowInternalPeriods">m_DisallowInternalPeriods</A></B></CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Determines whether internal periods are allowed</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>protected &nbsp;weka.core.Range</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#m_SelectCols">m_SelectCols</A></B></CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stores which columns to select as a funky range</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="fields_inherited_from_class_weka.filters.Filter"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Fields inherited from class weka.filters.Filter</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>m_NewBatch</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#KEAPhraseFilter()">KEAPhraseFilter</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#attributeIndicesTipText()">attributeIndicesTipText</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the tip text for this property</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#batchFinished()">batchFinished</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Signify that this batch of input to the filter is finished.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#disallowInternalPeriodsTipText()">disallowInternalPeriodsTipText</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the tip text for this property</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#getAttributeIndices()">getAttributeIndices</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get the current range selection.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#getDisallowInternalPeriods()">getDisallowInternalPeriods</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get whether the supplied columns are to be processed</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#getInvertSelection()">getInvertSelection</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get whether the supplied columns are to be processed</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String[]</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#getOptions()">getOptions</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gets the current settings of the filter.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#globalInfo()">globalInfo</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a string describing this filter</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#input(weka.core.Instance)">input</A></B>(weka.core.Instance&nbsp;instance)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Input an instance for filtering.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#invertSelectionTipText()">invertSelectionTipText</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the tip text for this property</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.util.Enumeration</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#listOptions()">listOptions</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns an enumeration describing the available options</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>static&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#main(java.lang.String[])">main</A></B>(java.lang.String[]&nbsp;argv)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Main method for testing this class.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#setAttributeIndices(java.lang.String)">setAttributeIndices</A></B>(java.lang.String&nbsp;rangeList)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set which attributes are to be processed</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#setAttributeIndicesArray(int[])">setAttributeIndicesArray</A></B>(int[]&nbsp;attributes)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set which attributes are to be processed</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#setDisallowInternalPeriods(boolean)">setDisallowInternalPeriods</A></B>(boolean&nbsp;disallow)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set whether selected columns should be processed.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#setInputFormat(weka.core.Instances)">setInputFormat</A></B>(weka.core.Instances&nbsp;instanceInfo)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets the format of the input instances.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#setInvertSelection(boolean)">setInvertSelection</A></B>(boolean&nbsp;invert)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set whether selected columns should be processed.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="KEAPhraseFilter.html#setOptions(java.lang.String[])">setOptions</A></B>(java.lang.String[]&nbsp;options)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parses a given list of options controlling the behaviour of this object.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_weka.filters.Filter"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class weka.filters.Filter</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>batchFilterFile, bufferInput, copyStringValues, copyStringValues, filterFile, flushInput, getInputFormat, getInputStringIndex, getOutputFormat, getOutputStringIndex, getStringIndices, inputFormat, isOutputFormatDefined, numPendingOutput, output, outputFormat, outputFormatPeek, outputPeek, push, resetQueue, setOutputFormat, useFilter</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+<A NAME="field_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Field Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="m_SelectCols"><!-- --></A><H3>
+m_SelectCols</H3>
+<PRE>
+protected weka.core.Range <B>m_SelectCols</B></PRE>
+<DL>
+<DD>Stores which columns to select as a funky range
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<A NAME="m_DisallowInternalPeriods"><!-- --></A><H3>
+m_DisallowInternalPeriods</H3>
+<PRE>
+protected boolean <B>m_DisallowInternalPeriods</B></PRE>
+<DL>
+<DD>Determines whether internal periods are allowed
+<P>
+<DL>
+</DL>
+</DL>
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="KEAPhraseFilter()"><!-- --></A><H3>
+KEAPhraseFilter</H3>
+<PRE>
+public <B>KEAPhraseFilter</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="globalInfo()"><!-- --></A><H3>
+globalInfo</H3>
+<PRE>
+public java.lang.String <B>globalInfo</B>()</PRE>
+<DL>
+<DD>Returns a string describing this filter
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>a description of the filter suitable for
+ displaying in the explorer/experimenter gui</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="listOptions()"><!-- --></A><H3>
+listOptions</H3>
+<PRE>
+public java.util.Enumeration <B>listOptions</B>()</PRE>
+<DL>
+<DD>Returns an enumeration describing the available options
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>listOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>an enumeration of all the available options</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setOptions(java.lang.String[])"><!-- --></A><H3>
+setOptions</H3>
+<PRE>
+public void <B>setOptions</B>(java.lang.String[]&nbsp;options)
+                throws java.lang.Exception</PRE>
+<DL>
+<DD>Parses a given list of options controlling the behaviour of this object.
+ Valid options are:<p>
+
+ -R index1,index2-index4,...<br>
+ Specify list of attributes to process. First and last are valid indexes.
+ (default none)<p>
+
+ -V<br>
+ Invert matching sense <p>
+
+ -P<br>
+ Disallow internal periods <p>
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>setOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>options</CODE> - the list of options as an array of strings
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.Exception</CODE> - if an option is not supported</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getOptions()"><!-- --></A><H3>
+getOptions</H3>
+<PRE>
+public java.lang.String[] <B>getOptions</B>()</PRE>
+<DL>
+<DD>Gets the current settings of the filter.
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE>getOptions</CODE> in interface <CODE>weka.core.OptionHandler</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>an array of strings suitable for passing to setOptions</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setInputFormat(weka.core.Instances)"><!-- --></A><H3>
+setInputFormat</H3>
+<PRE>
+public boolean <B>setInputFormat</B>(weka.core.Instances&nbsp;instanceInfo)
+                       throws java.lang.Exception</PRE>
+<DL>
+<DD>Sets the format of the input instances.
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE>setInputFormat</CODE> in class <CODE>weka.filters.Filter</CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>instanceInfo</CODE> - an Instances object containing the input
+ instance structure (any instances contained in the object are
+ ignored - only the structure is required).
+<DT><B>Returns:</B><DD>true if the outputFormat may be collected immediately
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="input(weka.core.Instance)"><!-- --></A><H3>
+input</H3>
+<PRE>
+public boolean <B>input</B>(weka.core.Instance&nbsp;instance)
+              throws java.lang.Exception</PRE>
+<DL>
+<DD>Input an instance for filtering. Ordinarily the instance is processed
+ and made available for output immediately. Some filters require all
+ instances be read before producing output.
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE>input</CODE> in class <CODE>weka.filters.Filter</CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>instance</CODE> - the input instance
+<DT><B>Returns:</B><DD>true if the filtered instance may now be
+ collected with output().
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.Exception</CODE> - if the input instance was not of the correct 
+ format or if there was a problem with the filtering.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="batchFinished()"><!-- --></A><H3>
+batchFinished</H3>
+<PRE>
+public boolean <B>batchFinished</B>()
+                      throws java.lang.Exception</PRE>
+<DL>
+<DD>Signify that this batch of input to the filter is finished. If
+ the filter requires all instances prior to filtering, output()
+ may now be called to retrieve the filtered instances. Any
+ subsequent instances filtered should be filtered based on setting
+ obtained from the first batch (unless the inputFormat has been
+ re-assigned or new options have been set). This default
+ implementation assumes all instance processing occurs during
+ inputFormat() and input().
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE>batchFinished</CODE> in class <CODE>weka.filters.Filter</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>true if there are instances pending output
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.NullPointerException</CODE> - if no input structure has been defined,
+<DD><CODE>java.lang.Exception</CODE> - if there was a problem finishing the batch.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="main(java.lang.String[])"><!-- --></A><H3>
+main</H3>
+<PRE>
+public static void <B>main</B>(java.lang.String[]&nbsp;argv)</PRE>
+<DL>
+<DD>Main method for testing this class.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>argv</CODE> - should contain arguments to the filter: use -h for help</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="invertSelectionTipText()"><!-- --></A><H3>
+invertSelectionTipText</H3>
+<PRE>
+public java.lang.String <B>invertSelectionTipText</B>()</PRE>
+<DL>
+<DD>Returns the tip text for this property
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>tip text for this property suitable for
+ displaying in the explorer/experimenter gui</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getInvertSelection()"><!-- --></A><H3>
+getInvertSelection</H3>
+<PRE>
+public boolean <B>getInvertSelection</B>()</PRE>
+<DL>
+<DD>Get whether the supplied columns are to be processed
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>true if the supplied columns won't be processed</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setInvertSelection(boolean)"><!-- --></A><H3>
+setInvertSelection</H3>
+<PRE>
+public void <B>setInvertSelection</B>(boolean&nbsp;invert)</PRE>
+<DL>
+<DD>Set whether selected columns should be processed. If true the 
+ selected columns won't be processed.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>invert</CODE> - the new invert setting</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="disallowInternalPeriodsTipText()"><!-- --></A><H3>
+disallowInternalPeriodsTipText</H3>
+<PRE>
+public java.lang.String <B>disallowInternalPeriodsTipText</B>()</PRE>
+<DL>
+<DD>Returns the tip text for this property
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>tip text for this property suitable for
+ displaying in the explorer/experimenter gui</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getDisallowInternalPeriods()"><!-- --></A><H3>
+getDisallowInternalPeriods</H3>
+<PRE>
+public boolean <B>getDisallowInternalPeriods</B>()</PRE>
+<DL>
+<DD>Get whether the supplied columns are to be processed
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>true if the supplied columns won't be processed</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setDisallowInternalPeriods(boolean)"><!-- --></A><H3>
+setDisallowInternalPeriods</H3>
+<PRE>
+public void <B>setDisallowInternalPeriods</B>(boolean&nbsp;disallow)</PRE>
+<DL>
+<DD>Set whether selected columns should be processed. If true the 
+ selected columns won't be processed.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="attributeIndicesTipText()"><!-- --></A><H3>
+attributeIndicesTipText</H3>
+<PRE>
+public java.lang.String <B>attributeIndicesTipText</B>()</PRE>
+<DL>
+<DD>Returns the tip text for this property
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>tip text for this property suitable for
+ displaying in the explorer/experimenter gui</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="getAttributeIndices()"><!-- --></A><H3>
+getAttributeIndices</H3>
+<PRE>
+public java.lang.String <B>getAttributeIndices</B>()</PRE>
+<DL>
+<DD>Get the current range selection.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>a string containing a comma separated list of ranges</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setAttributeIndices(java.lang.String)"><!-- --></A><H3>
+setAttributeIndices</H3>
+<PRE>
+public void <B>setAttributeIndices</B>(java.lang.String&nbsp;rangeList)</PRE>
+<DL>
+<DD>Set which attributes are to be processed
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>rangeList</CODE> - a string representing the list of attributes.  Since
+ the string will typically come from a user, attributes are indexed from
+ 1. <br>
+ eg: first-3,5,6-last</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setAttributeIndicesArray(int[])"><!-- --></A><H3>
+setAttributeIndicesArray</H3>
+<PRE>
+public void <B>setAttributeIndicesArray</B>(int[]&nbsp;attributes)</PRE>
+<DL>
+<DD>Set which attributes are to be processed
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>attributes</CODE> - an array containing indexes of attributes to select.
+ Since the array will typically come from a program, attributes are indexed
+ from 0.</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="KEAModelBuilder.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="LovinsStemmer.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="KEAPhraseFilter.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/LovinsStemmer.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/LovinsStemmer.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/LovinsStemmer.html	(revision 16571)
@@ -0,0 +1,289 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:50 NZDT 2004 -->
+<TITLE>
+LovinsStemmer
+</TITLE>
+<META NAME="keywords" CONTENT="LovinsStemmer,LovinsStemmer class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="LovinsStemmer";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="KEAPhraseFilter.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="NumbersFilter.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="LovinsStemmer.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class LovinsStemmer</H2>
+<PRE>
+java.lang.Object
+  |
+  +--<A HREF="Stemmer.html">Stemmer</A>
+        |
+        +--<B>LovinsStemmer</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>java.io.Serializable</DD>
+</DL>
+<DL>
+<DT><B>Direct Known Subclasses:</B> <DD><A HREF="IteratedLovinsStemmer.html">IteratedLovinsStemmer</A></DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>LovinsStemmer</B><DT>extends <A HREF="Stemmer.html">Stemmer</A><DT>implements java.io.Serializable</DL>
+
+<P>
+Implements the Lovins stemmer.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="LovinsStemmer">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="LovinsStemmer.html#LovinsStemmer()">LovinsStemmer</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>static&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="LovinsStemmer.html#main(java.lang.String[])">main</A></B>(java.lang.String[]&nbsp;ops)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stems text coming into stdin and writes it to stdout.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="LovinsStemmer.html#stem(java.lang.String)">stem</A></B>(java.lang.String&nbsp;word)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns the stemmed version of the given word.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_Stemmer"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class <A HREF="Stemmer.html">Stemmer</A></B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><A HREF="Stemmer.html#stemString(java.lang.String)">stemString</A></CODE></TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="LovinsStemmer()"><!-- --></A><H3>
+LovinsStemmer</H3>
+<PRE>
+public <B>LovinsStemmer</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="stem(java.lang.String)"><!-- --></A><H3>
+stem</H3>
+<PRE>
+public java.lang.String <B>stem</B>(java.lang.String&nbsp;word)</PRE>
+<DL>
+<DD>Returns the stemmed version of the given word.
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE><A HREF="Stemmer.html#stem(java.lang.String)">stem</A></CODE> in class <CODE><A HREF="Stemmer.html">Stemmer</A></CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>word</CODE> - a string consisting of a single word</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="main(java.lang.String[])"><!-- --></A><H3>
+main</H3>
+<PRE>
+public static void <B>main</B>(java.lang.String[]&nbsp;ops)</PRE>
+<DL>
+<DD>Stems text coming into stdin and writes it to stdout.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="KEAPhraseFilter.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="NumbersFilter.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="LovinsStemmer.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/NumbersFilter.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/NumbersFilter.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/NumbersFilter.html	(revision 16571)
@@ -0,0 +1,396 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:50 NZDT 2004 -->
+<TITLE>
+NumbersFilter
+</TITLE>
+<META NAME="keywords" CONTENT="NumbersFilter,NumbersFilter class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="NumbersFilter";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="LovinsStemmer.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="Stemmer.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="NumbersFilter.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#fields_inherited_from_class_weka.filters.Filter">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class NumbersFilter</H2>
+<PRE>
+java.lang.Object
+  |
+  +--weka.filters.Filter
+        |
+        +--<B>NumbersFilter</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>java.io.Serializable</DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>NumbersFilter</B><DT>extends weka.filters.Filter</DL>
+
+<P>
+Removes all numbers from all the string attributes in the given
+ dataset. Assumes that words are separated by whitespace.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="NumbersFilter">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+<A NAME="field_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Field Summary</B></FONT></TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="fields_inherited_from_class_weka.filters.Filter"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Fields inherited from class weka.filters.Filter</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>m_NewBatch</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="NumbersFilter.html#NumbersFilter()">NumbersFilter</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="NumbersFilter.html#batchFinished()">batchFinished</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Signify that this batch of input to the filter is finished.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="NumbersFilter.html#globalInfo()">globalInfo</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a string describing this filter</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="NumbersFilter.html#input(weka.core.Instance)">input</A></B>(weka.core.Instance&nbsp;instance)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Input an instance for filtering.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>static&nbsp;void</CODE></FONT></TD>
+<TD><CODE><B><A HREF="NumbersFilter.html#main(java.lang.String[])">main</A></B>(java.lang.String[]&nbsp;argv)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Main method for testing this class.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="NumbersFilter.html#setInputFormat(weka.core.Instances)">setInputFormat</A></B>(weka.core.Instances&nbsp;instanceInfo)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sets the format of the input instances.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_weka.filters.Filter"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class weka.filters.Filter</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>batchFilterFile, bufferInput, copyStringValues, copyStringValues, filterFile, flushInput, getInputFormat, getInputStringIndex, getOutputFormat, getOutputStringIndex, getStringIndices, inputFormat, isOutputFormatDefined, numPendingOutput, output, outputFormat, outputFormatPeek, outputPeek, push, resetQueue, setOutputFormat, useFilter</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="NumbersFilter()"><!-- --></A><H3>
+NumbersFilter</H3>
+<PRE>
+public <B>NumbersFilter</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="globalInfo()"><!-- --></A><H3>
+globalInfo</H3>
+<PRE>
+public java.lang.String <B>globalInfo</B>()</PRE>
+<DL>
+<DD>Returns a string describing this filter
+<P>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>a description of the filter suitable for
+ displaying in the explorer/experimenter gui</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="batchFinished()"><!-- --></A><H3>
+batchFinished</H3>
+<PRE>
+public boolean <B>batchFinished</B>()
+                      throws java.lang.Exception</PRE>
+<DL>
+<DD>Signify that this batch of input to the filter is finished. If
+ the filter requires all instances prior to filtering, output()
+ may now be called to retrieve the filtered instances. Any
+ subsequent instances filtered should be filtered based on setting
+ obtained from the first batch (unless the inputFormat has been
+ re-assigned or new options have been set). This default
+ implementation assumes all instance processing occurs during
+ inputFormat() and input().
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE>batchFinished</CODE> in class <CODE>weka.filters.Filter</CODE></DL>
+</DD>
+<DD><DL>
+
+<DT><B>Returns:</B><DD>true if there are instances pending output
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.NullPointerException</CODE> - if no input structure has been defined,
+<DD><CODE>java.lang.Exception</CODE> - if there was a problem finishing the batch.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="setInputFormat(weka.core.Instances)"><!-- --></A><H3>
+setInputFormat</H3>
+<PRE>
+public boolean <B>setInputFormat</B>(weka.core.Instances&nbsp;instanceInfo)
+                       throws java.lang.Exception</PRE>
+<DL>
+<DD>Sets the format of the input instances.
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE>setInputFormat</CODE> in class <CODE>weka.filters.Filter</CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>instanceInfo</CODE> - an Instances object containing the input
+ instance structure (any instances contained in the object are
+ ignored - only the structure is required).
+<DT><B>Returns:</B><DD>true if the outputFormat may be collected immediately
+<DD><CODE>java.lang.Exception</CODE></DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="input(weka.core.Instance)"><!-- --></A><H3>
+input</H3>
+<PRE>
+public boolean <B>input</B>(weka.core.Instance&nbsp;instance)
+              throws java.lang.Exception</PRE>
+<DL>
+<DD>Input an instance for filtering. Ordinarily the instance is processed
+ and made available for output immediately. Some filters require all
+ instances be read before producing output.
+<P>
+<DD><DL>
+<DT><B>Overrides:</B><DD><CODE>input</CODE> in class <CODE>weka.filters.Filter</CODE></DL>
+</DD>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>instance</CODE> - the input instance
+<DT><B>Returns:</B><DD>true if the filtered instance may now be
+ collected with output().
+<DT><B>Throws:</B>
+<DD><CODE>java.lang.Exception</CODE> - if the input instance was not of the correct 
+ format or if there was a problem with the filtering.</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="main(java.lang.String[])"><!-- --></A><H3>
+main</H3>
+<PRE>
+public static void <B>main</B>(java.lang.String[]&nbsp;argv)</PRE>
+<DL>
+<DD>Main method for testing this class.
+<P>
+<DD><DL>
+<DT><B>Parameters:</B><DD><CODE>argv</CODE> - should contain arguments to the filter: use -h for help</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="LovinsStemmer.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="Stemmer.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="NumbersFilter.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;<A HREF="#fields_inherited_from_class_weka.filters.Filter">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/Stemmer.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/Stemmer.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/Stemmer.html	(revision 16571)
@@ -0,0 +1,278 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:50 NZDT 2004 -->
+<TITLE>
+Stemmer
+</TITLE>
+<META NAME="keywords" CONTENT="Stemmer,Stemmer class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="Stemmer";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="NumbersFilter.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="Stopwords.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="Stemmer.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class Stemmer</H2>
+<PRE>
+java.lang.Object
+  |
+  +--<B>Stemmer</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>java.io.Serializable</DD>
+</DL>
+<DL>
+<DT><B>Direct Known Subclasses:</B> <DD><A HREF="GermanStemmer.html">GermanStemmer</A>, <A HREF="LovinsStemmer.html">LovinsStemmer</A></DD>
+</DL>
+<HR>
+<DL>
+<DT>public abstract class <B>Stemmer</B><DT>extends java.lang.Object<DT>implements java.io.Serializable</DL>
+
+<P>
+Abstract class for stemmers.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="Stemmer">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="Stemmer.html#Stemmer()">Stemmer</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>abstract &nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="Stemmer.html#stem(java.lang.String)">stem</A></B>(java.lang.String&nbsp;str)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Iterated stemming of the given word.</TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;java.lang.String</CODE></FONT></TD>
+<TD><CODE><B><A HREF="Stemmer.html#stemString(java.lang.String)">stemString</A></B>(java.lang.String&nbsp;str)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stems everything in the given string.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="Stemmer()"><!-- --></A><H3>
+Stemmer</H3>
+<PRE>
+public <B>Stemmer</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="stem(java.lang.String)"><!-- --></A><H3>
+stem</H3>
+<PRE>
+public abstract java.lang.String <B>stem</B>(java.lang.String&nbsp;str)</PRE>
+<DL>
+<DD>Iterated stemming of the given word.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<HR>
+
+<A NAME="stemString(java.lang.String)"><!-- --></A><H3>
+stemString</H3>
+<PRE>
+public java.lang.String <B>stemString</B>(java.lang.String&nbsp;str)</PRE>
+<DL>
+<DD>Stems everything in the given string.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="NumbersFilter.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="Stopwords.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="Stemmer.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/Stopwords.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/Stopwords.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/Stopwords.html	(revision 16571)
@@ -0,0 +1,255 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:50 NZDT 2004 -->
+<TITLE>
+Stopwords
+</TITLE>
+<META NAME="keywords" CONTENT="Stopwords,Stopwords class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="Stopwords";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="Stemmer.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="StopwordsEnglish.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="Stopwords.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class Stopwords</H2>
+<PRE>
+java.lang.Object
+  |
+  +--<B>Stopwords</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>java.io.Serializable</DD>
+</DL>
+<DL>
+<DT><B>Direct Known Subclasses:</B> <DD><A HREF="StopwordsEnglish.html">StopwordsEnglish</A>, <A HREF="StopwordsGerman.html">StopwordsGerman</A></DD>
+</DL>
+<HR>
+<DL>
+<DT>public abstract class <B>Stopwords</B><DT>extends java.lang.Object<DT>implements java.io.Serializable</DL>
+
+<P>
+Class that can test whether a given string is a stop word.
+ Lowercases all words before the test.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="Stopwords">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="Stopwords.html#Stopwords()">Stopwords</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>abstract &nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="Stopwords.html#isStopword(java.lang.String)">isStopword</A></B>(java.lang.String&nbsp;str)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns true if the given string is a stop word.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="Stopwords()"><!-- --></A><H3>
+Stopwords</H3>
+<PRE>
+public <B>Stopwords</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="isStopword(java.lang.String)"><!-- --></A><H3>
+isStopword</H3>
+<PRE>
+public abstract boolean <B>isStopword</B>(java.lang.String&nbsp;str)</PRE>
+<DL>
+<DD>Returns true if the given string is a stop word.
+<P>
+<DD><DL>
+</DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="Stemmer.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="StopwordsEnglish.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="Stopwords.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/StopwordsEnglish.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/StopwordsEnglish.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/StopwordsEnglish.html	(revision 16571)
@@ -0,0 +1,254 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:50 NZDT 2004 -->
+<TITLE>
+StopwordsEnglish
+</TITLE>
+<META NAME="keywords" CONTENT="StopwordsEnglish,StopwordsEnglish class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="StopwordsEnglish";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="Stopwords.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="StopwordsGerman.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="StopwordsEnglish.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class StopwordsEnglish</H2>
+<PRE>
+java.lang.Object
+  |
+  +--<A HREF="Stopwords.html">Stopwords</A>
+        |
+        +--<B>StopwordsEnglish</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>java.io.Serializable</DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>StopwordsEnglish</B><DT>extends <A HREF="Stopwords.html">Stopwords</A></DL>
+
+<P>
+Class that can test whether a given string is a stop word.
+ Lowercases all words before the test.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="StopwordsEnglish">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="StopwordsEnglish.html#StopwordsEnglish()">StopwordsEnglish</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="StopwordsEnglish.html#isStopword(java.lang.String)">isStopword</A></B>(java.lang.String&nbsp;str)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns true if the given string is a stop word.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="StopwordsEnglish()"><!-- --></A><H3>
+StopwordsEnglish</H3>
+<PRE>
+public <B>StopwordsEnglish</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="isStopword(java.lang.String)"><!-- --></A><H3>
+isStopword</H3>
+<PRE>
+public boolean <B>isStopword</B>(java.lang.String&nbsp;str)</PRE>
+<DL>
+<DD>Returns true if the given string is a stop word.
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE><A HREF="Stopwords.html#isStopword(java.lang.String)">isStopword</A></CODE> in class <CODE><A HREF="Stopwords.html">Stopwords</A></CODE></DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="Stopwords.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;<A HREF="StopwordsGerman.html"><B>NEXT CLASS</B></A></FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="StopwordsEnglish.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/StopwordsGerman.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/StopwordsGerman.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/StopwordsGerman.html	(revision 16571)
@@ -0,0 +1,259 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:50 NZDT 2004 -->
+<TITLE>
+StopwordsGerman
+</TITLE>
+<META NAME="keywords" CONTENT="StopwordsGerman,StopwordsGerman class">
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="StopwordsGerman";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="StopwordsEnglish.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;NEXT CLASS</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="StopwordsGerman.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<!-- ======== START OF CLASS DATA ======== -->
+<H2>
+Class StopwordsGerman</H2>
+<PRE>
+java.lang.Object
+  |
+  +--<A HREF="Stopwords.html">Stopwords</A>
+        |
+        +--<B>StopwordsGerman</B>
+</PRE>
+<DL>
+<DT><B>All Implemented Interfaces:</B> <DD>java.io.Serializable</DD>
+</DL>
+<HR>
+<DL>
+<DT>public class <B>StopwordsGerman</B><DT>extends <A HREF="Stopwords.html">Stopwords</A></DL>
+
+<P>
+Class that can test whether a given string is a stop word.
+ Lowercases all words before the test.
+
+ This list of German stop words has been obtained from
+ http://snowball.tartarus.org/german/stop.txt
+
+ But I have deleted/changed some words that I haven't seen before.
+<P>
+
+<P>
+<DL>
+<DT><B>See Also:</B><DD><A HREF="serialized-form.html" TARGET="StopwordsGerman">Serialized Form</A></DL>
+<HR>
+
+<P>
+<!-- ======== NESTED CLASS SUMMARY ======== -->
+
+
+<!-- =========== FIELD SUMMARY =========== -->
+
+
+<!-- ======== CONSTRUCTOR SUMMARY ======== -->
+
+<A NAME="constructor_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Constructor Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE><B><A HREF="StopwordsGerman.html#StopwordsGerman()">StopwordsGerman</A></B>()</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
+</TR>
+</TABLE>
+&nbsp;
+<!-- ========== METHOD SUMMARY =========== -->
+
+<A NAME="method_summary"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Method Summary</B></FONT></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
+<CODE>&nbsp;boolean</CODE></FONT></TD>
+<TD><CODE><B><A HREF="StopwordsGerman.html#isStopword(java.lang.String)">isStopword</A></B>(java.lang.String&nbsp;str)</CODE>
+
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns true if the given string is a stop word.</TD>
+</TR>
+</TABLE>
+&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
+<TD><B>Methods inherited from class java.lang.Object</B></TD>
+</TR>
+<TR BGCOLOR="white" CLASS="TableRowColor">
+<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
+</TR>
+</TABLE>
+&nbsp;
+<P>
+
+<!-- ============ FIELD DETAIL =========== -->
+
+
+<!-- ========= CONSTRUCTOR DETAIL ======== -->
+
+<A NAME="constructor_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Constructor Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="StopwordsGerman()"><!-- --></A><H3>
+StopwordsGerman</H3>
+<PRE>
+public <B>StopwordsGerman</B>()</PRE>
+<DL>
+</DL>
+
+<!-- ============ METHOD DETAIL ========== -->
+
+<A NAME="method_detail"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Method Detail</B></FONT></TD>
+</TR>
+</TABLE>
+
+<A NAME="isStopword(java.lang.String)"><!-- --></A><H3>
+isStopword</H3>
+<PRE>
+public boolean <B>isStopword</B>(java.lang.String&nbsp;str)</PRE>
+<DL>
+<DD>Returns true if the given string is a stop word.
+<P>
+<DD><DL>
+<DT><B>Specified by:</B><DD><CODE><A HREF="Stopwords.html#isStopword(java.lang.String)">isStopword</A></CODE> in class <CODE><A HREF="Stopwords.html">Stopwords</A></CODE></DL>
+</DD>
+<DD><DL>
+</DL>
+</DD>
+</DL>
+<!-- ========= END OF CLASS DATA ========= -->
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;<A HREF="StopwordsEnglish.html"><B>PREV CLASS</B></A>&nbsp;
+&nbsp;NEXT CLASS</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="StopwordsGerman.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+<TR>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
+<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
+DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/allclasses-frame.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/allclasses-frame.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/allclasses-frame.html	(revision 16571)
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:48 NZDT 2004 -->
+<TITLE>
+All Classes
+</TITLE>
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="All Classes";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+<FONT size="+1" CLASS="FrameHeadingFont">
+<B>All Classes</B></FONT>
+<BR>
+
+<TABLE BORDER="0" WIDTH="100%">
+<TR>
+<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="Counter.html" TARGET="classFrame">Counter</A>
+<BR>
+<A HREF="GermanStemmer.html" TARGET="classFrame">GermanStemmer</A>
+<BR>
+<A HREF="IteratedLovinsStemmer.html" TARGET="classFrame">IteratedLovinsStemmer</A>
+<BR>
+<A HREF="KEAFilter.html" TARGET="classFrame">KEAFilter</A>
+<BR>
+<A HREF="KEAKeyphraseExtractor.html" TARGET="classFrame">KEAKeyphraseExtractor</A>
+<BR>
+<A HREF="KEAModelBuilder.html" TARGET="classFrame">KEAModelBuilder</A>
+<BR>
+<A HREF="KEAPhraseFilter.html" TARGET="classFrame">KEAPhraseFilter</A>
+<BR>
+<A HREF="LovinsStemmer.html" TARGET="classFrame">LovinsStemmer</A>
+<BR>
+<A HREF="NumbersFilter.html" TARGET="classFrame">NumbersFilter</A>
+<BR>
+<A HREF="Stemmer.html" TARGET="classFrame">Stemmer</A>
+<BR>
+<A HREF="Stopwords.html" TARGET="classFrame">Stopwords</A>
+<BR>
+<A HREF="StopwordsEnglish.html" TARGET="classFrame">StopwordsEnglish</A>
+<BR>
+<A HREF="StopwordsGerman.html" TARGET="classFrame">StopwordsGerman</A>
+<BR>
+</FONT></TD>
+</TR>
+</TABLE>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/allclasses-noframe.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/allclasses-noframe.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/allclasses-noframe.html	(revision 16571)
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:48 NZDT 2004 -->
+<TITLE>
+All Classes
+</TITLE>
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="All Classes";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+<FONT size="+1" CLASS="FrameHeadingFont">
+<B>All Classes</B></FONT>
+<BR>
+
+<TABLE BORDER="0" WIDTH="100%">
+<TR>
+<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="Counter.html" TARGET="">Counter</A>
+<BR>
+<A HREF="GermanStemmer.html" TARGET="">GermanStemmer</A>
+<BR>
+<A HREF="IteratedLovinsStemmer.html" TARGET="">IteratedLovinsStemmer</A>
+<BR>
+<A HREF="KEAFilter.html" TARGET="">KEAFilter</A>
+<BR>
+<A HREF="KEAKeyphraseExtractor.html" TARGET="">KEAKeyphraseExtractor</A>
+<BR>
+<A HREF="KEAModelBuilder.html" TARGET="">KEAModelBuilder</A>
+<BR>
+<A HREF="KEAPhraseFilter.html" TARGET="">KEAPhraseFilter</A>
+<BR>
+<A HREF="LovinsStemmer.html" TARGET="">LovinsStemmer</A>
+<BR>
+<A HREF="NumbersFilter.html" TARGET="">NumbersFilter</A>
+<BR>
+<A HREF="Stemmer.html" TARGET="">Stemmer</A>
+<BR>
+<A HREF="Stopwords.html" TARGET="">Stopwords</A>
+<BR>
+<A HREF="StopwordsEnglish.html" TARGET="">StopwordsEnglish</A>
+<BR>
+<A HREF="StopwordsGerman.html" TARGET="">StopwordsGerman</A>
+<BR>
+</FONT></TD>
+</TR>
+</TABLE>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/constant-values.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/constant-values.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/constant-values.html	(revision 16571)
@@ -0,0 +1,123 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:47 NZDT 2004 -->
+<TITLE>
+Constant Field Values
+</TITLE>
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="Constant Field Values";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="constant-values.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<CENTER>
+<H1>
+Constant Field Values</H1>
+</CENTER>
+<HR SIZE="4" NOSHADE>
+<B>Contents</B><UL>
+</UL>
+
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="constant-values.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/deprecated-list.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/deprecated-list.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/deprecated-list.html	(revision 16571)
@@ -0,0 +1,119 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:48 NZDT 2004 -->
+<TITLE>
+Deprecated List
+</TITLE>
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="Deprecated List";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Deprecated</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="deprecated-list.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<CENTER>
+<H2>
+<B>Deprecated API</B></H2>
+</CENTER>
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Deprecated</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="deprecated-list.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/help-doc.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/help-doc.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/help-doc.html	(revision 16571)
@@ -0,0 +1,168 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:50 NZDT 2004 -->
+<TITLE>
+API Help
+</TITLE>
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="API Help";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Help</B></FONT>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="help-doc.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<CENTER>
+<H1>
+How This API Document Is Organized</H1>
+</CENTER>
+This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.<H3>
+Package</H3>
+<BLOCKQUOTE>
+
+<P>
+Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:<UL>
+<LI>Interfaces (italic)<LI>Classes<LI>Exceptions<LI>Errors</UL>
+</BLOCKQUOTE>
+<H3>
+Class/Interface</H3>
+<BLOCKQUOTE>
+
+<P>
+Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:<UL>
+<LI>Class inheritance diagram<LI>Direct Subclasses<LI>All Known Subinterfaces<LI>All Known Implementing Classes<LI>Class/interface declaration<LI>Class/interface description
+<P>
+<LI>Nested Class Summary<LI>Field Summary<LI>Constructor Summary<LI>Method Summary
+<P>
+<LI>Field Detail<LI>Constructor Detail<LI>Method Detail</UL>
+Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.</BLOCKQUOTE>
+<H3>
+Tree (Class Hierarchy)</H3>
+<BLOCKQUOTE>
+There is a <A HREF="overview-tree.html">Class Hierarchy</A> page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with <code>java.lang.Object</code>. The interfaces do not inherit from <code>java.lang.Object</code>.<UL>
+<LI>When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.<LI>When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.</UL>
+</BLOCKQUOTE>
+<H3>
+Deprecated API</H3>
+<BLOCKQUOTE>
+The <A HREF="deprecated-list.html">Deprecated API</A> page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.</BLOCKQUOTE>
+<H3>
+Index</H3>
+<BLOCKQUOTE>
+The <A HREF="index-all.html">Index</A> contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.</BLOCKQUOTE>
+<H3>
+Prev/Next</H3>
+These links take you to the next or previous class, interface, package, or related page.<H3>
+Frames/No Frames</H3>
+These links show and hide the HTML frames.  All pages are available with or without frames.
+<P>
+<H3>
+Serialized Form</H3>
+Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.
+<P>
+<FONT SIZE="-1">
+<EM>
+This help file applies to API documentation generated using the standard doclet.</EM>
+</FONT>
+<BR>
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Help</B></FONT>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="help-doc.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/index-all.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/index-all.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/index-all.html	(revision 16571)
@@ -0,0 +1,596 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:48 NZDT 2004 -->
+<TITLE>
+Index
+</TITLE>
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="Index";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Index</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="index-all.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<A HREF="#_A_">A</A> <A HREF="#_B_">B</A> <A HREF="#_C_">C</A> <A HREF="#_D_">D</A> <A HREF="#_E_">E</A> <A HREF="#_G_">G</A> <A HREF="#_I_">I</A> <A HREF="#_K_">K</A> <A HREF="#_L_">L</A> <A HREF="#_M_">M</A> <A HREF="#_N_">N</A> <A HREF="#_S_">S</A> <A HREF="#_T_">T</A> <A HREF="#_V_">V</A> <HR>
+<A NAME="_A_"><!-- --></A><H2>
+<B>A</B></H2>
+<DL>
+<DT><A HREF="KEAPhraseFilter.html#attributeIndicesTipText()"><B>attributeIndicesTipText()</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Returns the tip text for this property
+</DL>
+<HR>
+<A NAME="_B_"><!-- --></A><H2>
+<B>B</B></H2>
+<DL>
+<DT><A HREF="KEAFilter.html#batchFinished()"><B>batchFinished()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Signify that this batch of input to the filter is finished.
+<DT><A HREF="KEAPhraseFilter.html#batchFinished()"><B>batchFinished()</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Signify that this batch of input to the filter is finished.
+<DT><A HREF="NumbersFilter.html#batchFinished()"><B>batchFinished()</B></A> - 
+Method in class <A HREF="NumbersFilter.html">NumbersFilter</A>
+<DD>Signify that this batch of input to the filter is finished.
+<DT><A HREF="KEAModelBuilder.html#buildModel(java.util.Hashtable)"><B>buildModel(Hashtable)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Builds the model from the files
+</DL>
+<HR>
+<A NAME="_C_"><!-- --></A><H2>
+<B>C</B></H2>
+<DL>
+<DT><A HREF="KEAKeyphraseExtractor.html#collectStems()"><B>collectStems()</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Collects the stems of the file names.
+<DT><A HREF="KEAModelBuilder.html#collectStems()"><B>collectStems()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Collects the stems of the file names.
+<DT><A HREF="Counter.html"><B>Counter</B></A> - class <A HREF="Counter.html">Counter</A>.<DD>Class that implements a simple counter.<DT><A HREF="Counter.html#Counter()"><B>Counter()</B></A> - 
+Constructor for class <A HREF="Counter.html">Counter</A>
+<DD>Initializes the counter to 1
+<DT><A HREF="Counter.html#Counter(int)"><B>Counter(int)</B></A> - 
+Constructor for class <A HREF="Counter.html">Counter</A>
+<DD>Initializes the counter to the given value
+</DL>
+<HR>
+<A NAME="_D_"><!-- --></A><H2>
+<B>D</B></H2>
+<DL>
+<DT><A HREF="KEAPhraseFilter.html#disallowInternalPeriodsTipText()"><B>disallowInternalPeriodsTipText()</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Returns the tip text for this property
+</DL>
+<HR>
+<A NAME="_E_"><!-- --></A><H2>
+<B>E</B></H2>
+<DL>
+<DT><A HREF="KEAKeyphraseExtractor.html#extractKeyphrases(java.util.Hashtable)"><B>extractKeyphrases(Hashtable)</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Builds the model from the files
+</DL>
+<HR>
+<A NAME="_G_"><!-- --></A><H2>
+<B>G</B></H2>
+<DL>
+<DT><A HREF="GermanStemmer.html"><B>GermanStemmer</B></A> - class <A HREF="GermanStemmer.html">GermanStemmer</A>.<DD>A stemmer for German words.<DT><A HREF="GermanStemmer.html#GermanStemmer()"><B>GermanStemmer()</B></A> - 
+Constructor for class <A HREF="GermanStemmer.html">GermanStemmer</A>
+<DD>&nbsp;
+<DT><A HREF="KEAKeyphraseExtractor.html#getAdditionalInfo()"><B>getAdditionalInfo()</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Get the value of AdditionalInfo.
+<DT><A HREF="KEAPhraseFilter.html#getAttributeIndices()"><B>getAttributeIndices()</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Get the current range selection.
+<DT><A HREF="KEAFilter.html#getCheckForProperNouns()"><B>getCheckForProperNouns()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Get the M_CheckProperNouns value.
+<DT><A HREF="KEAModelBuilder.html#getCheckForProperNouns()"><B>getCheckForProperNouns()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the M_CheckProperNouns value.
+<DT><A HREF="KEAFilter.html#getDebug()"><B>getDebug()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Get the value of Debug.
+<DT><A HREF="KEAKeyphraseExtractor.html#getDebug()"><B>getDebug()</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Get the value of debug.
+<DT><A HREF="KEAModelBuilder.html#getDebug()"><B>getDebug()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the value of debug.
+<DT><A HREF="KEAKeyphraseExtractor.html#getDirName()"><B>getDirName()</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Get the value of dirName.
+<DT><A HREF="KEAModelBuilder.html#getDirName()"><B>getDirName()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the value of dirName.
+<DT><A HREF="KEAFilter.html#getDisallowInternalPeriods()"><B>getDisallowInternalPeriods()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Get whether the supplied columns are to be processed
+<DT><A HREF="KEAPhraseFilter.html#getDisallowInternalPeriods()"><B>getDisallowInternalPeriods()</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Get whether the supplied columns are to be processed
+<DT><A HREF="KEAModelBuilder.html#getDisallowIPeriods()"><B>getDisallowIPeriods()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the value of disallowIPeriods.
+<DT><A HREF="KEAFilter.html#getDocumentAtt()"><B>getDocumentAtt()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Get the value of DocumentAtt.
+<DT><A HREF="KEAKeyphraseExtractor.html#getEncoding()"><B>getEncoding()</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Get the value of encoding.
+<DT><A HREF="KEAModelBuilder.html#getEncoding()"><B>getEncoding()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the value of encoding.
+<DT><A HREF="KEAPhraseFilter.html#getInvertSelection()"><B>getInvertSelection()</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Get whether the supplied columns are to be processed
+<DT><A HREF="KEAFilter.html#getKeyphrasesAtt()"><B>getKeyphrasesAtt()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Get the value of KeyphraseAtt.
+<DT><A HREF="KEAFilter.html#getKFused()"><B>getKFused()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Gets whether keyphrase frequency attribute is used.
+<DT><A HREF="KEAFilter.html#getMaxPhraseLength()"><B>getMaxPhraseLength()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Get the value of MaxPhraseLength.
+<DT><A HREF="KEAModelBuilder.html#getMaxPhraseLength()"><B>getMaxPhraseLength()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the value of MaxPhraseLength.
+<DT><A HREF="KEAFilter.html#getMinNumOccur()"><B>getMinNumOccur()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Get the value of MinNumOccur.
+<DT><A HREF="KEAModelBuilder.html#getMinNumOccur()"><B>getMinNumOccur()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the value of MinNumOccur.
+<DT><A HREF="KEAFilter.html#getMinPhraseLength()"><B>getMinPhraseLength()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Get the value of MinPhraseLength.
+<DT><A HREF="KEAModelBuilder.html#getMinPhraseLength()"><B>getMinPhraseLength()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the value of MinPhraseLength.
+<DT><A HREF="KEAKeyphraseExtractor.html#getModelName()"><B>getModelName()</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Get the value of modelName.
+<DT><A HREF="KEAModelBuilder.html#getModelName()"><B>getModelName()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the value of modelName.
+<DT><A HREF="KEAKeyphraseExtractor.html#getNumPhrases()"><B>getNumPhrases()</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Get the value of numPhrases.
+<DT><A HREF="KEAFilter.html#getOptions()"><B>getOptions()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Gets the current settings of the filter.
+<DT><A HREF="KEAKeyphraseExtractor.html#getOptions()"><B>getOptions()</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Gets the current option settings.
+<DT><A HREF="KEAModelBuilder.html#getOptions()"><B>getOptions()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Gets the current option settings.
+<DT><A HREF="KEAPhraseFilter.html#getOptions()"><B>getOptions()</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Gets the current settings of the filter.
+<DT><A HREF="KEAFilter.html#getProbabilityIndex()"><B>getProbabilityIndex()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Returns the index of the phrases' probabilities in the output ARFF file.
+<DT><A HREF="KEAFilter.html#getRankIndex()"><B>getRankIndex()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Returns the index of the phrases' ranks in the output ARFF file.
+<DT><A HREF="KEAFilter.html#getStemmedPhraseIndex()"><B>getStemmedPhraseIndex()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Returns the index of the stemmed phrases in the output ARFF file.
+<DT><A HREF="KEAFilter.html#getStemmer()"><B>getStemmer()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Get the Stemmer value.
+<DT><A HREF="KEAModelBuilder.html#getStemmer()"><B>getStemmer()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the Stemmer value.
+<DT><A HREF="KEAFilter.html#getStopwords()"><B>getStopwords()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Get the M_Stopwords value.
+<DT><A HREF="KEAModelBuilder.html#getStopwords()"><B>getStopwords()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the M_Stopwords value.
+<DT><A HREF="KEAFilter.html#getUnstemmedPhraseIndex()"><B>getUnstemmedPhraseIndex()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Returns the index of the unstemmed phrases in the output ARFF file.
+<DT><A HREF="KEAModelBuilder.html#getUseKFrequency()"><B>getUseKFrequency()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Get the value of useKFrequency.
+<DT><A HREF="KEAFilter.html#globalInfo()"><B>globalInfo()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Returns a string describing this filter
+<DT><A HREF="KEAPhraseFilter.html#globalInfo()"><B>globalInfo()</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Returns a string describing this filter
+<DT><A HREF="NumbersFilter.html#globalInfo()"><B>globalInfo()</B></A> - 
+Method in class <A HREF="NumbersFilter.html">NumbersFilter</A>
+<DD>Returns a string describing this filter
+</DL>
+<HR>
+<A NAME="_I_"><!-- --></A><H2>
+<B>I</B></H2>
+<DL>
+<DT><A HREF="Counter.html#increment()"><B>increment()</B></A> - 
+Method in class <A HREF="Counter.html">Counter</A>
+<DD>Increments the counter.
+<DT><A HREF="KEAFilter.html#input(weka.core.Instance)"><B>input(Instance)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Input an instance for filtering.
+<DT><A HREF="KEAPhraseFilter.html#input(weka.core.Instance)"><B>input(Instance)</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Input an instance for filtering.
+<DT><A HREF="NumbersFilter.html#input(weka.core.Instance)"><B>input(Instance)</B></A> - 
+Method in class <A HREF="NumbersFilter.html">NumbersFilter</A>
+<DD>Input an instance for filtering.
+<DT><A HREF="KEAPhraseFilter.html#invertSelectionTipText()"><B>invertSelectionTipText()</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Returns the tip text for this property
+<DT><A HREF="Stopwords.html#isStopword(java.lang.String)"><B>isStopword(String)</B></A> - 
+Method in class <A HREF="Stopwords.html">Stopwords</A>
+<DD>Returns true if the given string is a stop word.
+<DT><A HREF="StopwordsEnglish.html#isStopword(java.lang.String)"><B>isStopword(String)</B></A> - 
+Method in class <A HREF="StopwordsEnglish.html">StopwordsEnglish</A>
+<DD>Returns true if the given string is a stop word.
+<DT><A HREF="StopwordsGerman.html#isStopword(java.lang.String)"><B>isStopword(String)</B></A> - 
+Method in class <A HREF="StopwordsGerman.html">StopwordsGerman</A>
+<DD>Returns true if the given string is a stop word.
+<DT><A HREF="IteratedLovinsStemmer.html"><B>IteratedLovinsStemmer</B></A> - class <A HREF="IteratedLovinsStemmer.html">IteratedLovinsStemmer</A>.<DD>Implements the iterated version of the Lovins stemmer.<DT><A HREF="IteratedLovinsStemmer.html#IteratedLovinsStemmer()"><B>IteratedLovinsStemmer()</B></A> - 
+Constructor for class <A HREF="IteratedLovinsStemmer.html">IteratedLovinsStemmer</A>
+<DD>&nbsp;
+</DL>
+<HR>
+<A NAME="_K_"><!-- --></A><H2>
+<B>K</B></H2>
+<DL>
+<DT><A HREF="KEAFilter.html"><B>KEAFilter</B></A> - class <A HREF="KEAFilter.html">KEAFilter</A>.<DD>This filter converts the incoming data into data appropriate for
+ keyphrase classification.<DT><A HREF="KEAFilter.html#KEAFilter()"><B>KEAFilter()</B></A> - 
+Constructor for class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>&nbsp;
+<DT><A HREF="KEAKeyphraseExtractor.html"><B>KEAKeyphraseExtractor</B></A> - class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>.<DD>Extracts keyphrases from the documents in a given directory.<DT><A HREF="KEAKeyphraseExtractor.html#KEAKeyphraseExtractor()"><B>KEAKeyphraseExtractor()</B></A> - 
+Constructor for class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>&nbsp;
+<DT><A HREF="KEAModelBuilder.html"><B>KEAModelBuilder</B></A> - class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>.<DD>Builds a keyphrase extraction model from the documents in a given
+ directory.<DT><A HREF="KEAModelBuilder.html#KEAModelBuilder()"><B>KEAModelBuilder()</B></A> - 
+Constructor for class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>&nbsp;
+<DT><A HREF="KEAPhraseFilter.html"><B>KEAPhraseFilter</B></A> - class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>.<DD>This filter splits the text in selected string
+ attributes into phrases.<DT><A HREF="KEAPhraseFilter.html#KEAPhraseFilter()"><B>KEAPhraseFilter()</B></A> - 
+Constructor for class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>&nbsp;
+</DL>
+<HR>
+<A NAME="_L_"><!-- --></A><H2>
+<B>L</B></H2>
+<DL>
+<DT><A HREF="KEAFilter.html#listOptions()"><B>listOptions()</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Returns an enumeration describing the available options
+<DT><A HREF="KEAKeyphraseExtractor.html#listOptions()"><B>listOptions()</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Returns an enumeration describing the available options.
+<DT><A HREF="KEAModelBuilder.html#listOptions()"><B>listOptions()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Returns an enumeration describing the available options.
+<DT><A HREF="KEAPhraseFilter.html#listOptions()"><B>listOptions()</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Returns an enumeration describing the available options
+<DT><A HREF="KEAKeyphraseExtractor.html#loadModel()"><B>loadModel()</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Loads the extraction model from the file.
+<DT><A HREF="LovinsStemmer.html"><B>LovinsStemmer</B></A> - class <A HREF="LovinsStemmer.html">LovinsStemmer</A>.<DD>Implements the Lovins stemmer.<DT><A HREF="LovinsStemmer.html#LovinsStemmer()"><B>LovinsStemmer()</B></A> - 
+Constructor for class <A HREF="LovinsStemmer.html">LovinsStemmer</A>
+<DD>&nbsp;
+</DL>
+<HR>
+<A NAME="_M_"><!-- --></A><H2>
+<B>M</B></H2>
+<DL>
+<DT><A HREF="KEAPhraseFilter.html#m_DisallowInternalPeriods"><B>m_DisallowInternalPeriods</B></A> - 
+Variable in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Determines whether internal periods are allowed
+<DT><A HREF="KEAPhraseFilter.html#m_SelectCols"><B>m_SelectCols</B></A> - 
+Variable in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Stores which columns to select as a funky range
+<DT><A HREF="IteratedLovinsStemmer.html#main(java.lang.String[])"><B>main(String[])</B></A> - 
+Static method in class <A HREF="IteratedLovinsStemmer.html">IteratedLovinsStemmer</A>
+<DD>Stems text coming into stdin and writes it to stdout.
+<DT><A HREF="KEAFilter.html#main(java.lang.String[])"><B>main(String[])</B></A> - 
+Static method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Main method for testing this class.
+<DT><A HREF="KEAKeyphraseExtractor.html#main(java.lang.String[])"><B>main(String[])</B></A> - 
+Static method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>The main method.
+<DT><A HREF="KEAModelBuilder.html#main(java.lang.String[])"><B>main(String[])</B></A> - 
+Static method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>The main method.
+<DT><A HREF="KEAPhraseFilter.html#main(java.lang.String[])"><B>main(String[])</B></A> - 
+Static method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Main method for testing this class.
+<DT><A HREF="LovinsStemmer.html#main(java.lang.String[])"><B>main(String[])</B></A> - 
+Static method in class <A HREF="LovinsStemmer.html">LovinsStemmer</A>
+<DD>Stems text coming into stdin and writes it to stdout.
+<DT><A HREF="NumbersFilter.html#main(java.lang.String[])"><B>main(String[])</B></A> - 
+Static method in class <A HREF="NumbersFilter.html">NumbersFilter</A>
+<DD>Main method for testing this class.
+</DL>
+<HR>
+<A NAME="_N_"><!-- --></A><H2>
+<B>N</B></H2>
+<DL>
+<DT><A HREF="NumbersFilter.html"><B>NumbersFilter</B></A> - class <A HREF="NumbersFilter.html">NumbersFilter</A>.<DD>Removes all numbers from all the string attributes in the given
+ dataset.<DT><A HREF="NumbersFilter.html#NumbersFilter()"><B>NumbersFilter()</B></A> - 
+Constructor for class <A HREF="NumbersFilter.html">NumbersFilter</A>
+<DD>&nbsp;
+</DL>
+<HR>
+<A NAME="_S_"><!-- --></A><H2>
+<B>S</B></H2>
+<DL>
+<DT><A HREF="KEAModelBuilder.html#saveModel()"><B>saveModel()</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Saves the extraction model to the file.
+<DT><A HREF="KEAKeyphraseExtractor.html#setAdditionalInfo(boolean)"><B>setAdditionalInfo(boolean)</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Set the value of AdditionalInfo.
+<DT><A HREF="KEAPhraseFilter.html#setAttributeIndices(java.lang.String)"><B>setAttributeIndices(String)</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Set which attributes are to be processed
+<DT><A HREF="KEAPhraseFilter.html#setAttributeIndicesArray(int[])"><B>setAttributeIndicesArray(int[])</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Set which attributes are to be processed
+<DT><A HREF="KEAFilter.html#setCheckForProperNouns(boolean)"><B>setCheckForProperNouns(boolean)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Set the M_CheckProperNouns value.
+<DT><A HREF="KEAModelBuilder.html#setCheckForProperNouns(boolean)"><B>setCheckForProperNouns(boolean)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the M_CheckProperNouns value.
+<DT><A HREF="KEAFilter.html#setDebug(boolean)"><B>setDebug(boolean)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Set the value of Debug.
+<DT><A HREF="KEAKeyphraseExtractor.html#setDebug(boolean)"><B>setDebug(boolean)</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Set the value of debug.
+<DT><A HREF="KEAModelBuilder.html#setDebug(boolean)"><B>setDebug(boolean)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the value of debug.
+<DT><A HREF="KEAKeyphraseExtractor.html#setDirName(java.lang.String)"><B>setDirName(String)</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Set the value of dirName.
+<DT><A HREF="KEAModelBuilder.html#setDirName(java.lang.String)"><B>setDirName(String)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the value of dirName.
+<DT><A HREF="KEAFilter.html#setDisallowInternalPeriods(boolean)"><B>setDisallowInternalPeriods(boolean)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Set whether selected columns should be processed.
+<DT><A HREF="KEAPhraseFilter.html#setDisallowInternalPeriods(boolean)"><B>setDisallowInternalPeriods(boolean)</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Set whether selected columns should be processed.
+<DT><A HREF="KEAModelBuilder.html#setDisallowIPeriods(boolean)"><B>setDisallowIPeriods(boolean)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the value of disallowIPeriods.
+<DT><A HREF="KEAFilter.html#setDocumentAtt(int)"><B>setDocumentAtt(int)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Set the value of DocumentAtt.
+<DT><A HREF="KEAKeyphraseExtractor.html#setEncoding(java.lang.String)"><B>setEncoding(String)</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Set the value of encoding.
+<DT><A HREF="KEAModelBuilder.html#setEncoding(java.lang.String)"><B>setEncoding(String)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the value of encoding.
+<DT><A HREF="KEAFilter.html#setInputFormat(weka.core.Instances)"><B>setInputFormat(Instances)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Sets the format of the input instances.
+<DT><A HREF="KEAPhraseFilter.html#setInputFormat(weka.core.Instances)"><B>setInputFormat(Instances)</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Sets the format of the input instances.
+<DT><A HREF="NumbersFilter.html#setInputFormat(weka.core.Instances)"><B>setInputFormat(Instances)</B></A> - 
+Method in class <A HREF="NumbersFilter.html">NumbersFilter</A>
+<DD>Sets the format of the input instances.
+<DT><A HREF="KEAPhraseFilter.html#setInvertSelection(boolean)"><B>setInvertSelection(boolean)</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Set whether selected columns should be processed.
+<DT><A HREF="KEAFilter.html#setKeyphrasesAtt(int)"><B>setKeyphrasesAtt(int)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Set the value of KeyphrasesAtt.
+<DT><A HREF="KEAFilter.html#setKFused(boolean)"><B>setKFused(boolean)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Sets whether keyphrase frequency attribute is used.
+<DT><A HREF="KEAFilter.html#setMaxPhraseLength(int)"><B>setMaxPhraseLength(int)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Set the value of MaxPhraseLength.
+<DT><A HREF="KEAModelBuilder.html#setMaxPhraseLength(int)"><B>setMaxPhraseLength(int)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the value of MaxPhraseLength.
+<DT><A HREF="KEAFilter.html#setMinNumOccur(int)"><B>setMinNumOccur(int)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Set the value of MinNumOccur.
+<DT><A HREF="KEAModelBuilder.html#setMinNumOccur(int)"><B>setMinNumOccur(int)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the value of MinNumOccur.
+<DT><A HREF="KEAFilter.html#setMinPhraseLength(int)"><B>setMinPhraseLength(int)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Set the value of MinPhraseLength.
+<DT><A HREF="KEAModelBuilder.html#setMinPhraseLength(int)"><B>setMinPhraseLength(int)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the value of MinPhraseLength.
+<DT><A HREF="KEAKeyphraseExtractor.html#setModelName(java.lang.String)"><B>setModelName(String)</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Set the value of modelName.
+<DT><A HREF="KEAModelBuilder.html#setModelName(java.lang.String)"><B>setModelName(String)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the value of modelName.
+<DT><A HREF="KEAKeyphraseExtractor.html#setNumPhrases(int)"><B>setNumPhrases(int)</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Set the value of numPhrases.
+<DT><A HREF="KEAFilter.html#setOptions(java.lang.String[])"><B>setOptions(String[])</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Parses a given list of options controlling the behaviour of this object.
+<DT><A HREF="KEAKeyphraseExtractor.html#setOptions(java.lang.String[])"><B>setOptions(String[])</B></A> - 
+Method in class <A HREF="KEAKeyphraseExtractor.html">KEAKeyphraseExtractor</A>
+<DD>Parses a given list of options controlling the behaviour of this object.
+<DT><A HREF="KEAModelBuilder.html#setOptions(java.lang.String[])"><B>setOptions(String[])</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Parses a given list of options controlling the behaviour of this object.
+<DT><A HREF="KEAPhraseFilter.html#setOptions(java.lang.String[])"><B>setOptions(String[])</B></A> - 
+Method in class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A>
+<DD>Parses a given list of options controlling the behaviour of this object.
+<DT><A HREF="KEAFilter.html#setStemmer(Stemmer)"><B>setStemmer(Stemmer)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Set the Stemmer value.
+<DT><A HREF="KEAModelBuilder.html#setStemmer(Stemmer)"><B>setStemmer(Stemmer)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the Stemmer value.
+<DT><A HREF="KEAFilter.html#setStopwords(Stopwords)"><B>setStopwords(Stopwords)</B></A> - 
+Method in class <A HREF="KEAFilter.html">KEAFilter</A>
+<DD>Set the M_Stopwords value.
+<DT><A HREF="KEAModelBuilder.html#setStopwords(Stopwords)"><B>setStopwords(Stopwords)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the M_Stopwords value.
+<DT><A HREF="KEAModelBuilder.html#setUseKFrequency(boolean)"><B>setUseKFrequency(boolean)</B></A> - 
+Method in class <A HREF="KEAModelBuilder.html">KEAModelBuilder</A>
+<DD>Set the value of useKFrequency.
+<DT><A HREF="GermanStemmer.html#stem(java.lang.String)"><B>stem(String)</B></A> - 
+Method in class <A HREF="GermanStemmer.html">GermanStemmer</A>
+<DD>Stemms the given term to an unique <tt>discriminator</tt>.
+<DT><A HREF="IteratedLovinsStemmer.html#stem(java.lang.String)"><B>stem(String)</B></A> - 
+Method in class <A HREF="IteratedLovinsStemmer.html">IteratedLovinsStemmer</A>
+<DD>Iterated stemming of the given word.
+<DT><A HREF="LovinsStemmer.html#stem(java.lang.String)"><B>stem(String)</B></A> - 
+Method in class <A HREF="LovinsStemmer.html">LovinsStemmer</A>
+<DD>Returns the stemmed version of the given word.
+<DT><A HREF="Stemmer.html#stem(java.lang.String)"><B>stem(String)</B></A> - 
+Method in class <A HREF="Stemmer.html">Stemmer</A>
+<DD>Iterated stemming of the given word.
+<DT><A HREF="Stemmer.html"><B>Stemmer</B></A> - class <A HREF="Stemmer.html">Stemmer</A>.<DD>Abstract class for stemmers.<DT><A HREF="Stemmer.html#Stemmer()"><B>Stemmer()</B></A> - 
+Constructor for class <A HREF="Stemmer.html">Stemmer</A>
+<DD>&nbsp;
+<DT><A HREF="Stemmer.html#stemString(java.lang.String)"><B>stemString(String)</B></A> - 
+Method in class <A HREF="Stemmer.html">Stemmer</A>
+<DD>Stems everything in the given string.
+<DT><A HREF="Stopwords.html"><B>Stopwords</B></A> - class <A HREF="Stopwords.html">Stopwords</A>.<DD>Class that can test whether a given string is a stop word.<DT><A HREF="Stopwords.html#Stopwords()"><B>Stopwords()</B></A> - 
+Constructor for class <A HREF="Stopwords.html">Stopwords</A>
+<DD>&nbsp;
+<DT><A HREF="StopwordsEnglish.html"><B>StopwordsEnglish</B></A> - class <A HREF="StopwordsEnglish.html">StopwordsEnglish</A>.<DD>Class that can test whether a given string is a stop word.<DT><A HREF="StopwordsEnglish.html#StopwordsEnglish()"><B>StopwordsEnglish()</B></A> - 
+Constructor for class <A HREF="StopwordsEnglish.html">StopwordsEnglish</A>
+<DD>&nbsp;
+<DT><A HREF="StopwordsGerman.html"><B>StopwordsGerman</B></A> - class <A HREF="StopwordsGerman.html">StopwordsGerman</A>.<DD>Class that can test whether a given string is a stop word.<DT><A HREF="StopwordsGerman.html#StopwordsGerman()"><B>StopwordsGerman()</B></A> - 
+Constructor for class <A HREF="StopwordsGerman.html">StopwordsGerman</A>
+<DD>&nbsp;
+</DL>
+<HR>
+<A NAME="_T_"><!-- --></A><H2>
+<B>T</B></H2>
+<DL>
+<DT><A HREF="Counter.html#toString()"><B>toString()</B></A> - 
+Method in class <A HREF="Counter.html">Counter</A>
+<DD>Returns string containing value.
+</DL>
+<HR>
+<A NAME="_V_"><!-- --></A><H2>
+<B>V</B></H2>
+<DL>
+<DT><A HREF="Counter.html#value()"><B>value()</B></A> - 
+Method in class <A HREF="Counter.html">Counter</A>
+<DD>Gets the value.
+</DL>
+<HR>
+<A HREF="#_A_">A</A> <A HREF="#_B_">B</A> <A HREF="#_C_">C</A> <A HREF="#_D_">D</A> <A HREF="#_E_">E</A> <A HREF="#_G_">G</A> <A HREF="#_I_">I</A> <A HREF="#_K_">K</A> <A HREF="#_L_">L</A> <A HREF="#_M_">M</A> <A HREF="#_N_">N</A> <A HREF="#_S_">S</A> <A HREF="#_T_">T</A> <A HREF="#_V_">V</A> 
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Index</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="index-all.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/index.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/index.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/index.html	(revision 16571)
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:48 NZDT 2004-->
+<TITLE>
+Generated Documentation (Untitled)
+</TITLE>
+</HEAD>
+<FRAMESET cols="20%,80%">
+<FRAME src="allclasses-frame.html" name="packageFrame">
+<FRAME src="Counter.html" name="classFrame">
+</FRAMESET>
+<NOFRAMES>
+<H2>
+Frame Alert</H2>
+
+<P>
+This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client.
+<BR>
+Link to<A HREF="Counter.html">Non-frame version.</A></NOFRAMES>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/overview-tree.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/overview-tree.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/overview-tree.html	(revision 16571)
@@ -0,0 +1,143 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:48 NZDT 2004 -->
+<TITLE>
+Class Hierarchy
+</TITLE>
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="Class Hierarchy";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Tree</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="overview-tree.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<CENTER>
+<H2>
+Hierarchy For All Packages</H2>
+</CENTER>
+<H2>
+Class Hierarchy
+</H2>
+<UL>
+<LI TYPE="circle">class java.lang.Object<UL>
+<LI TYPE="circle">class <A HREF="Counter.html"><B>Counter</B></A> (implements java.io.Serializable)
+<LI TYPE="circle">class weka.filters.Filter (implements java.io.Serializable)
+<UL>
+<LI TYPE="circle">class <A HREF="KEAFilter.html"><B>KEAFilter</B></A> (implements weka.core.OptionHandler)
+<LI TYPE="circle">class <A HREF="KEAPhraseFilter.html"><B>KEAPhraseFilter</B></A> (implements weka.core.OptionHandler)
+<LI TYPE="circle">class <A HREF="NumbersFilter.html"><B>NumbersFilter</B></A></UL>
+<LI TYPE="circle">class <A HREF="KEAKeyphraseExtractor.html"><B>KEAKeyphraseExtractor</B></A> (implements weka.core.OptionHandler)
+<LI TYPE="circle">class <A HREF="KEAModelBuilder.html"><B>KEAModelBuilder</B></A> (implements weka.core.OptionHandler)
+<LI TYPE="circle">class <A HREF="Stemmer.html"><B>Stemmer</B></A> (implements java.io.Serializable)
+<UL>
+<LI TYPE="circle">class <A HREF="GermanStemmer.html"><B>GermanStemmer</B></A><LI TYPE="circle">class <A HREF="LovinsStemmer.html"><B>LovinsStemmer</B></A> (implements java.io.Serializable)
+<UL>
+<LI TYPE="circle">class <A HREF="IteratedLovinsStemmer.html"><B>IteratedLovinsStemmer</B></A></UL>
+</UL>
+<LI TYPE="circle">class <A HREF="Stopwords.html"><B>Stopwords</B></A> (implements java.io.Serializable)
+<UL>
+<LI TYPE="circle">class <A HREF="StopwordsEnglish.html"><B>StopwordsEnglish</B></A><LI TYPE="circle">class <A HREF="StopwordsGerman.html"><B>StopwordsGerman</B></A></UL>
+</UL>
+</UL>
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Tree</B></FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="overview-tree.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/package-list
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/package-list	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/package-list	(revision 16571)
@@ -0,0 +1,1 @@
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/packages.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/packages.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/packages.html	(revision 16571)
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:48 NZDT 2004 -->
+<TITLE>
+
+</TITLE>
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<BODY BGCOLOR="white">
+
+<BR>
+
+<BR>
+
+<BR>
+<CENTER>
+The front page has been relocated.Please see:
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="index.html">Frame version</A>
+<BR>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="Counter.html">Non-frame version.</A></CENTER>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/serialized-form.html
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/serialized-form.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/serialized-form.html	(revision 16571)
@@ -0,0 +1,604 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc on Fri Mar 19 17:50:50 NZDT 2004 -->
+<TITLE>
+Serialized Form
+</TITLE>
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+</HEAD>
+<SCRIPT>
+function asd()
+{
+parent.document.title="Serialized Form";
+}
+</SCRIPT>
+<BODY BGCOLOR="white" onload="asd();">
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_top"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="serialized-form.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+<CENTER>
+<H1>
+Serialized Form</H1>
+</CENTER>
+<A NAME="Counter"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="Counter.html">Counter</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+<A NAME="serializedForm"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Serialized Fields</B></FONT></TD>
+</TR>
+</TABLE>
+
+<H3>
+m_val</H3>
+<PRE>
+int <B>m_val</B></PRE>
+<DL>
+<DD>Integer value stored
+<P>
+<DL>
+</DL>
+</DL>
+
+<P>
+<HR SIZE="4" NOSHADE>
+<A NAME="GermanStemmer"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="GermanStemmer.html">GermanStemmer</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+<A NAME="serializedForm"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Serialized Fields</B></FONT></TD>
+</TR>
+</TABLE>
+
+<H3>
+sb</H3>
+<PRE>
+java.lang.StringBuffer <B>sb</B></PRE>
+<DL>
+<DD>Buffer for the terms while stemming them.
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+uppercase</H3>
+<PRE>
+boolean <B>uppercase</B></PRE>
+<DL>
+<DD>Indicates if a term is handled as a noun.
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+substCount</H3>
+<PRE>
+int <B>substCount</B></PRE>
+<DL>
+<DD>Amount of characters that are removed with <tt>substitute()</tt> while stemming.
+<P>
+<DL>
+</DL>
+</DL>
+
+<P>
+<HR SIZE="4" NOSHADE>
+<A NAME="IteratedLovinsStemmer"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="IteratedLovinsStemmer.html">IteratedLovinsStemmer</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+
+<P>
+<HR SIZE="4" NOSHADE>
+<A NAME="KEAFilter"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="KEAFilter.html">KEAFilter</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+<A NAME="serializedForm"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Serialized Fields</B></FONT></TD>
+</TR>
+</TABLE>
+
+<H3>
+m_DocumentAtt</H3>
+<PRE>
+int <B>m_DocumentAtt</B></PRE>
+<DL>
+<DD>Index of attribute containing the documents
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_KeyphrasesAtt</H3>
+<PRE>
+int <B>m_KeyphrasesAtt</B></PRE>
+<DL>
+<DD>Index of attribute containing the keyphrases
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_MaxPhraseLength</H3>
+<PRE>
+int <B>m_MaxPhraseLength</B></PRE>
+<DL>
+<DD>The maximum length of phrases
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_MinPhraseLength</H3>
+<PRE>
+int <B>m_MinPhraseLength</B></PRE>
+<DL>
+<DD>The minimum length of phrases
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_KFused</H3>
+<PRE>
+boolean <B>m_KFused</B></PRE>
+<DL>
+<DD>Is keyphrase frequency attribute being used?
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_Debug</H3>
+<PRE>
+boolean <B>m_Debug</B></PRE>
+<DL>
+<DD>Flag for debugging mode
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_DisallowInternalPeriods</H3>
+<PRE>
+boolean <B>m_DisallowInternalPeriods</B></PRE>
+<DL>
+<DD>Determines whether internal periods are allowed
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_MinNumOccur</H3>
+<PRE>
+int <B>m_MinNumOccur</B></PRE>
+<DL>
+<DD>The minimum number of occurences of a phrase
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_NumFeatures</H3>
+<PRE>
+int <B>m_NumFeatures</B></PRE>
+<DL>
+<DD>The number of features describing a phrase
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_TfidfIndex</H3>
+<PRE>
+int <B>m_TfidfIndex</B></PRE>
+<DL>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_FirstOccurIndex</H3>
+<PRE>
+int <B>m_FirstOccurIndex</B></PRE>
+<DL>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_KeyFreqIndex</H3>
+<PRE>
+int <B>m_KeyFreqIndex</B></PRE>
+<DL>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_PunctFilter</H3>
+<PRE>
+KEAPhraseFilter <B>m_PunctFilter</B></PRE>
+<DL>
+<DD>The punctuation filter used by this filter
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_NumbersFilter</H3>
+<PRE>
+NumbersFilter <B>m_NumbersFilter</B></PRE>
+<DL>
+<DD>The numbers filter used by this filter
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_Classifier</H3>
+<PRE>
+weka.classifiers.DistributionClassifier <B>m_Classifier</B></PRE>
+<DL>
+<DD>The actual classifier used to compute probabilities
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_Dictionary</H3>
+<PRE>
+java.util.HashMap <B>m_Dictionary</B></PRE>
+<DL>
+<DD>The dictionary containing the document frequencies
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_KeyphraseDictionary</H3>
+<PRE>
+java.util.HashMap <B>m_KeyphraseDictionary</B></PRE>
+<DL>
+<DD>The dictionary containing the keyphrases
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_NumDocs</H3>
+<PRE>
+int <B>m_NumDocs</B></PRE>
+<DL>
+<DD>The number of documents in the global frequencies corpus
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_ClassifierData</H3>
+<PRE>
+weka.core.Instances <B>m_ClassifierData</B></PRE>
+<DL>
+<DD>Template for the classifier data
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_Stemmer</H3>
+<PRE>
+Stemmer <B>m_Stemmer</B></PRE>
+<DL>
+<DD>The stemmer to be used
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_Stopwords</H3>
+<PRE>
+Stopwords <B>m_Stopwords</B></PRE>
+<DL>
+<DD>The list of stop words to be used
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_CheckForProperNouns</H3>
+<PRE>
+boolean <B>m_CheckForProperNouns</B></PRE>
+<DL>
+<DD>Determines whether check for proper nouns is performed
+<P>
+<DL>
+</DL>
+</DL>
+
+<P>
+<HR SIZE="4" NOSHADE>
+<A NAME="KEAPhraseFilter"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="KEAPhraseFilter.html">KEAPhraseFilter</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+<A NAME="serializedForm"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
+<TD COLSPAN=1><FONT SIZE="+2">
+<B>Serialized Fields</B></FONT></TD>
+</TR>
+</TABLE>
+
+<H3>
+m_SelectCols</H3>
+<PRE>
+weka.core.Range <B>m_SelectCols</B></PRE>
+<DL>
+<DD>Stores which columns to select as a funky range
+<P>
+<DL>
+</DL>
+</DL>
+<HR>
+
+<H3>
+m_DisallowInternalPeriods</H3>
+<PRE>
+boolean <B>m_DisallowInternalPeriods</B></PRE>
+<DL>
+<DD>Determines whether internal periods are allowed
+<P>
+<DL>
+</DL>
+</DL>
+
+<P>
+<HR SIZE="4" NOSHADE>
+<A NAME="LovinsStemmer"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="LovinsStemmer.html">LovinsStemmer</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+
+<P>
+<HR SIZE="4" NOSHADE>
+<A NAME="NumbersFilter"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="NumbersFilter.html">NumbersFilter</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+
+<P>
+<HR SIZE="4" NOSHADE>
+<A NAME="Stemmer"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="Stemmer.html">Stemmer</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+
+<P>
+<HR SIZE="4" NOSHADE>
+<A NAME="Stopwords"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="Stopwords.html">Stopwords</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+
+<P>
+<HR SIZE="4" NOSHADE>
+<A NAME="StopwordsEnglish"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="StopwordsEnglish.html">StopwordsEnglish</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+
+<P>
+<HR SIZE="4" NOSHADE>
+<A NAME="StopwordsGerman"><!-- --></A>
+<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
+<TR BGCOLOR="#CCCCFF" CLASS="TableSubHeadingColor">
+<TD COLSPAN=2><FONT SIZE="+2">
+<B>Class <A HREF="StopwordsGerman.html">StopwordsGerman</A> implements Serializable</B></FONT></TD>
+</TR>
+</TABLE>
+
+<P>
+
+<P>
+<HR>
+
+<!-- ========== START OF NAVBAR ========== -->
+<A NAME="navbar_bottom"><!-- --></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
+<TR>
+<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_bottom_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Package</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+  <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
+&nbsp;<A HREF="serialized-form.html" TARGET="_top"><B>NO FRAMES</B></A>  &nbsp;
+&nbsp;
+<SCRIPT>
+  <!--
+  if(window==top) {
+    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
+  }
+  //-->
+</SCRIPT>
+<NOSCRIPT>
+<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>
+</NOSCRIPT>
+</FONT></TD>
+</TR>
+</TABLE>
+<!-- =========== END OF NAVBAR =========== -->
+
+<HR>
+
+</BODY>
+</HTML>
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/stylesheet.css
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/stylesheet.css	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/doc/stylesheet.css	(revision 16571)
@@ -0,0 +1,29 @@
+/* Javadoc style sheet */
+
+/* Define colors, fonts and other style attributes here to override the defaults */
+
+/* Page background color */
+body { background-color: #FFFFFF }
+
+/* Table colors */
+.TableHeadingColor     { background: #CCCCFF } /* Dark mauve */
+.TableSubHeadingColor  { background: #EEEEFF } /* Light mauve */
+.TableRowColor         { background: #FFFFFF } /* White */
+
+/* Font used in left-hand frame lists */
+.FrameTitleFont   { font-size: 10pts; font-family: Helvetica, Arial, san-serif }
+.FrameHeadingFont { font-size: 10pts; font-family: Helvetica, Arial, san-serif }
+.FrameItemFont    { font-size: 10pts; font-family: Helvetica, Arial, san-serif }
+
+/* Example of smaller, sans-serif font in frames */
+/* .FrameItemFont  { font-size: 10pt; font-family: Helvetica, Arial, sans-serif } */
+
+/* Navigation bar fonts and colors */
+.NavBarCell1    { background-color:#EEEEFF;}/* Light mauve */
+.NavBarCell1Rev { background-color:#00008B;}/* Dark Blue */
+.NavBarFont1    { font-family: Arial, Helvetica, sans-serif; color:#000000;}
+.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;}
+
+.NavBarCell2    { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;}
+.NavBarCell3    { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;}
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/Classifier.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/Classifier.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/Classifier.java	(revision 16571)
@@ -0,0 +1,115 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Classifier.java
+ *    Copyright (C) 1999 Eibe Frank, Len Trigg
+ *
+ */
+
+package weka.classifiers;
+
+import java.io.Serializable;
+import weka.core.Instance;
+import weka.core.Instances;
+import weka.core.SerializedObject;
+import weka.core.Utils;
+
+
+/** 
+ * Abstract classifier. All schemes for numeric or nominal prediction in
+ * Weka extend this class.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @author Len Trigg (trigg@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public abstract class Classifier implements Cloneable, Serializable {
+ 
+  /**
+   * Generates a classifier. Must initialize all fields of the classifier
+   * that are not being set via options (ie. multiple calls of buildClassifier
+   * must always lead to the same result). Must not change the dataset
+   * in any way.
+   *
+   * @param data set of instances serving as training data 
+   * @exception Exception if the classifier has not been 
+   * generated successfully
+   */
+  public abstract void buildClassifier(Instances data) throws Exception;
+
+  /**
+   * Classifies a given instance.
+   *
+   * @param instance the instance to be classified
+   * @return index of the predicted class as a double
+   * if the class is nominal, otherwise the predicted value
+   * @exception Exception if instance could not be classified
+   * successfully
+   */
+  public abstract double classifyInstance(Instance instance) throws Exception; 
+
+
+  
+  /**
+   * Creates a new instance of a classifier given it's class name and
+   * (optional) arguments to pass to it's setOptions method. If the
+   * classifier implements OptionHandler and the options parameter is
+   * non-null, the classifier will have it's options set.
+   *
+   * @param classifierName the fully qualified class name of the classifier
+   * @param options an array of options suitable for passing to setOptions. May
+   * be null.
+   * @return the newly created classifier, ready for use.
+   * @exception Exception if the classifier name is invalid, or the options
+   * supplied are not acceptable to the classifier
+   */
+  public static Classifier forName(String classifierName,
+				   String [] options) throws Exception {
+
+    return (Classifier)Utils.forName(Classifier.class,
+				     classifierName,
+				     options);
+  }
+
+  /**
+   * Creates copies of the current classifier, which can then
+   * be used for boosting etc. Note that this method now uses
+   * Serialization to perform a deep copy, so the Classifier
+   * object must be fully Serializable. Any currently built model
+   * will now be copied as well.
+   *
+   * @param model an example classifier to copy
+   * @param num the number of classifiers copies to create.
+   * @return an array of classifiers.
+   * @exception Exception if an error occurs
+   */
+  public static Classifier [] makeCopies(Classifier model,
+					 int num) throws Exception {
+
+    if (model == null) {
+      throw new Exception("No model classifier set");
+    }
+    Classifier [] classifiers = new Classifier [num];
+    SerializedObject so = new SerializedObject(model);
+    for(int i = 0; i < classifiers.length; i++) {
+      classifiers[i] = (Classifier) so.getObject();
+    }
+    return classifiers;
+  }
+
+}
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/DistributionClassifier.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/DistributionClassifier.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/DistributionClassifier.java	(revision 16571)
@@ -0,0 +1,92 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    DistributionClassifier.java
+ *    Copyright (C) 1999 Eibe Frank, Len Trigg
+ *
+ */
+
+package weka.classifiers;
+
+import weka.core.*;
+
+/** 
+ * Abstract classification model that produces (for each test instance)
+ * an estimate of the membership in each class 
+ * (ie. a probability distribution).
+ *
+ * @author   Eibe Frank (trigg@cs.waikato.ac.nz)
+ * @author   Len Trigg (trigg@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public abstract class DistributionClassifier extends Classifier {
+
+  /**
+   * Predicts the class memberships for a given instance. If
+   * an instance is unclassified, the returned array elements
+   * must be all zero. If the class is numeric, the array
+   * must consist of only one element, which contains the
+   * predicted value.
+   *
+   * @param instance the instance to be classified
+   * @return an array containing the estimated membership 
+   * probabilities of the test instance in each class (this 
+   * should sum to at most 1)
+   * @exception Exception if distribution could not be 
+   * computed successfully
+   */
+  public abstract double[] distributionForInstance(Instance instance) 
+       throws Exception;
+
+  /**
+   * Classifies the given test instance. The instance has to belong to a
+   * dataset when it's being classified.
+   *
+   * @param instance the instance to be classified
+   * @return the predicted most likely class for the instance or 
+   * Instance.missingValue() if no prediction is made
+   * @exception Exception if an error occurred during the prediction
+   */
+  public double classifyInstance(Instance instance) throws Exception {
+
+    double [] dist = distributionForInstance(instance);
+    if (dist == null) {
+      throw new Exception("Null distribution predicted");
+    }
+    switch (instance.classAttribute().type()) {
+    case Attribute.NOMINAL:
+      double max = 0;
+      int maxIndex = 0;
+      
+      for (int i = 0; i < dist.length; i++) {
+	if (dist[i] > max) {
+	  maxIndex = i;
+	  max = dist[i];
+	}
+      }
+      if (max > 0) {
+	return maxIndex;
+      } else {
+	return Instance.missingValue();
+      }
+    case Attribute.NUMERIC:
+      return dist[0];
+    default:
+      return Instance.missingValue();
+    }
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/FilteredClassifier.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/FilteredClassifier.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/FilteredClassifier.java	(revision 16571)
@@ -0,0 +1,374 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    FilteredClassifier.java
+ *    Copyright (C) 1999 Len Trigg
+ *
+ */
+
+package weka.classifiers;
+
+import java.util.Enumeration;
+import java.util.Vector;
+import weka.core.Instance;
+import weka.core.Instances;
+import weka.core.Option;
+import weka.core.OptionHandler;
+import weka.core.Utils;
+import weka.filters.Filter;
+import weka.core.Attribute;
+
+
+/**
+ * Class for running an arbitrary classifier on data that has been passed
+ * through an arbitrary filter.<p>
+ *
+ * Valid options from the command line are:<p>
+ *
+ * -B classifierstring <br>
+ * Classifierstring should contain the full class name of a classifier
+ * followed by options to the classifier.
+ * (required).<p>
+ *
+ * -F filterstring <br>
+ * Filterstring should contain the full class name of a filter
+ * followed by options to the filter.
+ * (required).<p>
+ *
+ * @author Len Trigg (trigg@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public class FilteredClassifier extends DistributionClassifier
+  implements OptionHandler {
+
+  /** The classifier */
+  protected Classifier m_Classifier = new weka.classifiers.NaiveBayesSimple();
+
+  /** The filter */
+  protected Filter m_Filter = new weka.filters.DiscretizeFilter();
+
+  /** The instance structure of the filtered instances */
+  protected Instances m_FilteredInstances;
+  
+  /**
+   * Default constructor specifying NaiveBayesSimple as the classifier and
+   * DiscretizeFilter as the filter. Both of these are just placeholders
+   * for more useful selections.
+   */
+  public FilteredClassifier() {
+
+    this(new weka.classifiers.NaiveBayesSimple(), 
+	 new weka.filters.DiscretizeFilter());
+  }
+
+  /**
+   * Constructor that specifies the subclassifier and filter to use.
+   *
+   * @param classifier the Classifier to receive filtered instances.
+   * @param filter the Filter that will process instances before
+   * passing to the Classifier.
+   */
+  public FilteredClassifier(Classifier classifier, Filter filter) {
+
+    m_Classifier = classifier;
+    m_Filter = filter;
+  }
+
+  /**
+   * Returns an enumeration describing the available options
+   *
+   * @return an enumeration of all the available options
+   */
+  public Enumeration listOptions() {
+
+    Vector newVector = new Vector(2);
+
+    newVector.addElement(new Option(
+	      "\tFull class name of classifier to use, followed\n"
+	      + "\tby scheme options. (required)\n"
+	      + "\teg: \"weka.classifiers.NaiveBayes -D\"",
+	      "B", 1, "-B <classifier specification>"));
+    newVector.addElement(new Option(
+	      "\tFull class name of filter to use, followed\n"
+	      + "\tby filter options. (required)\n"
+	      + "\teg: \"weka.filters.AttributeFilter -V -R 1,2\"",
+	      "F", 1, "-F <filter specification>"));
+    return newVector.elements();
+  }
+
+  /**
+   * Parses a given list of options. Valid options are:<p>
+   *
+   * -B classifierstring <br>
+   * Classifierstring should contain the full class name of a classifier
+   * followed by options to the classifier.
+   * (required).<p>
+   *
+   * -F filterstring <br>
+   * Filterstring should contain the full class name of a filter
+   * followed by options to the filter.
+   * (required).<p>
+   *
+   * @param options the list of options as an array of strings
+   * @exception Exception if an option is not supported
+   */
+  public void setOptions(String[] options) throws Exception {
+
+    String classifierString = Utils.getOption('B', options);
+    if (classifierString.length() == 0) {
+      throw new Exception("A classifier must be specified"
+			  + " with the -B option.");
+    }
+    String [] classifierSpec = Utils.splitOptions(classifierString);
+    if (classifierSpec.length == 0) {
+      throw new Exception("Invalid classifier specification string");
+    }
+    String classifierName = classifierSpec[0];
+    classifierSpec[0] = "";
+    setClassifier(Classifier.forName(classifierName, classifierSpec));
+    
+    // Same for filter
+    String filterString = Utils.getOption('F', options);
+    if (filterString.length() == 0) {
+      throw new Exception("A filter must be specified"
+			  + " with the -F option.");
+    }
+    String [] filterSpec = Utils.splitOptions(filterString);
+    if (filterSpec.length == 0) {
+      throw new Exception("Invalid filter specification string");
+    }
+    String filterName = filterSpec[0];
+    filterSpec[0] = "";
+    setFilter((Filter) Utils.forName(Filter.class, filterName, filterSpec));
+  }
+
+  /**
+   * Gets the current settings of the Classifier.
+   *
+   * @return an array of strings suitable for passing to setOptions
+   */
+  public String [] getOptions() {
+
+    String [] options = new String [4];
+    int current = 0;
+
+    options[current++] = "-B";
+    options[current++] = "" + getClassifierSpec();
+
+    // Same for filter
+    options[current++] = "-F";
+    options[current++] = "" + getFilterSpec();
+    
+    while (current < options.length) {
+      options[current++] = "";
+    }
+    return options;
+  }
+
+  /**
+   * Sets the classifier
+   *
+   * @param classifier the classifier with all options set.
+   */
+  public void setClassifier(Classifier classifier) {
+
+    m_Classifier = classifier;
+  }
+
+  /**
+   * Gets the classifier used.
+   *
+   * @return the classifier
+   */
+  public Classifier getClassifier() {
+
+    return m_Classifier;
+  }
+  
+  /**
+   * Gets the classifier specification string, which contains the class name of
+   * the classifier and any options to the classifier
+   *
+   * @return the classifier string.
+   */
+  protected String getClassifierSpec() {
+    
+    Classifier c = getClassifier();
+    if (c instanceof OptionHandler) {
+      return c.getClass().getName() + " "
+	+ Utils.joinOptions(((OptionHandler)c).getOptions());
+    }
+    return c.getClass().getName();
+  }
+
+  /**
+   * Sets the filter
+   *
+   * @param filter the filter with all options set.
+   */
+  public void setFilter(Filter filter) {
+
+    m_Filter = filter;
+  }
+
+  /**
+   * Gets the filter used.
+   *
+   * @return the filter
+   */
+  public Filter getFilter() {
+
+    return m_Filter;
+  }
+  
+  /**
+   * Gets the filter specification string, which contains the class name of
+   * the filter and any options to the filter
+   *
+   * @return the filter string.
+   */
+  protected String getFilterSpec() {
+    
+    Filter c = getFilter();
+    if (c instanceof OptionHandler) {
+      return c.getClass().getName() + " "
+	+ Utils.joinOptions(((OptionHandler)c).getOptions());
+    }
+    return c.getClass().getName();
+  }
+
+  /**
+   * Build the classifier on the filtered data.
+   *
+   * @param data the training data
+   * @exception Exception if the classifier could not be built successfully
+   */
+  public void buildClassifier(Instances data) throws Exception {
+
+    if (m_Classifier == null) {
+      throw new Exception("No base classifiers have been set!");
+    }
+    /*
+    String fname = m_Filter.getClass().getName();
+    fname = fname.substring(fname.lastIndexOf('.') + 1);
+    util.Timer t = util.Timer.getTimer("FilteredClassifier::" + fname);
+    t.start();
+    */
+    m_Filter.setInputFormat(data);
+    data = Filter.useFilter(data, m_Filter);
+    //t.stop();
+    m_FilteredInstances = data.stringFreeStructure();
+    m_Classifier.buildClassifier(data);
+  }
+
+  /**
+   * Classifies a given instance after filtering.
+   *
+   * @param instance the instance to be classified
+   * @exception Exception if instance could not be classified
+   * successfully
+   */
+  public double [] distributionForInstance(Instance instance)
+    throws Exception {
+
+    /*
+      System.err.println("FilteredClassifier:: " 
+                         + m_Filter.getClass().getName()
+                         + " in: " + instance);
+    */
+    if (m_Filter.numPendingOutput() > 0) {
+      throw new Exception("Filter output queue not empty!");
+    }
+    /*
+    String fname = m_Filter.getClass().getName();
+    fname = fname.substring(fname.lastIndexOf('.') + 1);
+    util.Timer t = util.Timer.getTimer("FilteredClassifier::" + fname);
+    t.start();
+    */
+    if (!m_Filter.input(instance)) {
+      throw new Exception("Filter didn't make the test instance"
+			  + " immediately available!");
+    }
+    m_Filter.batchFinished();
+    Instance newInstance = m_Filter.output();
+    //t.stop();
+    /*
+    System.err.println("FilteredClassifier:: " 
+                       + m_Filter.getClass().getName()
+                       + " out: " + newInstance);
+    */
+    if (m_Classifier instanceof DistributionClassifier) {
+      return ((DistributionClassifier)m_Classifier)
+	.distributionForInstance(newInstance);
+    }
+    double pred = m_Classifier.classifyInstance(newInstance);
+    double [] result = new double [m_FilteredInstances.numClasses()];
+    if (Instance.isMissingValue(pred)) {
+      return result;
+    }
+    switch (instance.classAttribute().type()) {
+    case Attribute.NOMINAL:
+      result[(int) pred] = 1.0;
+      break;
+    case Attribute.NUMERIC:
+      result[0] = pred;
+      break;
+    default:
+      throw new Exception("Unknown class type");
+    }
+    return result;
+  }
+
+  /**
+   * Output a representation of this classifier
+   */
+  public String toString() {
+
+    if (m_FilteredInstances == null) {
+      return "FilteredClassifier: No model built yet.";
+    }
+
+    String result = "FilteredClassifier using "
+      + getClassifierSpec()
+      + " on data filtered through "
+      + getFilterSpec()
+      + "\n\nFiltered Header\n"
+      + m_FilteredInstances.toString()
+      + "\n\nClassifier Model\n"
+      + m_Classifier.toString();
+    return result;
+  }
+
+
+  /**
+   * Main method for testing this class.
+   *
+   * @param argv should contain the following arguments:
+   * -t training file [-T test file] [-c class index]
+   */
+  public static void main(String [] argv) {
+
+    try {
+      System.out.println("Evaluation disabled!");
+      //System.out.println(Evaluation.evaluateModel(new FilteredClassifier(),
+      //					  argv));
+    } catch (Exception e) {
+      System.err.println(e.getMessage());
+    }
+  }
+
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/NaiveBayesSimple.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/NaiveBayesSimple.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/classifiers/NaiveBayesSimple.java	(revision 16571)
@@ -0,0 +1,331 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    NaiveBayesSimple.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.classifiers;
+
+import java.io.*;
+import java.util.*;
+import weka.core.*;
+
+/**
+ * Class for building and using a simple Naive Bayes classifier.
+ * Numeric attributes are modelled by a normal distribution. For more
+ * information, see<p>
+ *
+ * Richard Duda and Peter Hart (1973).<i>Pattern
+ * Classification and Scene Analysis</i>. Wiley, New York.
+
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$ 
+*/
+public class NaiveBayesSimple extends DistributionClassifier {
+
+  /** All the counts for nominal attributes. */
+  private double [][][] m_Counts;
+  
+  /** The means for numeric attributes. */
+  private double [][] m_Means;
+
+  /** The standard deviations for numeric attributes. */
+  private double [][] m_Devs;
+
+  /** The prior probabilities of the classes. */
+  private double [] m_Priors;
+
+  /** The instances used for training. */
+  private Instances m_Instances;
+
+  /** Constant for normal distribution. */
+  private static double NORM_CONST = Math.sqrt(2 * Math.PI);
+
+  /**
+   * Generates the classifier.
+   *
+   * @param instances set of instances serving as training data 
+   * @exception Exception if the classifier has not been generated successfully
+   */
+  public void buildClassifier(Instances instances) throws Exception {
+
+    int attIndex = 0;
+    double sum;
+    
+    if (instances.checkForStringAttributes()) {
+      throw new Exception("Can't handle string attributes!");
+    }
+    if (instances.classAttribute().isNumeric()) {
+      throw new Exception("Naive Bayes: Class is numeric!");
+    }
+    
+    m_Instances = new Instances(instances, 0);
+    
+    // Reserve space
+    m_Counts = new double[instances.numClasses()]
+      [instances.numAttributes() - 1][0];
+    m_Means = new double[instances.numClasses()]
+      [instances.numAttributes() - 1];
+    m_Devs = new double[instances.numClasses()]
+      [instances.numAttributes() - 1];
+    m_Priors = new double[instances.numClasses()];
+    Enumeration enum = instances.enumerateAttributes();
+    while (enum.hasMoreElements()) {
+      Attribute attribute = (Attribute) enum.nextElement();
+      if (attribute.isNominal()) {
+	for (int j = 0; j < instances.numClasses(); j++) {
+	  m_Counts[j][attIndex] = new double[attribute.numValues()];
+	}
+      } else {
+	for (int j = 0; j < instances.numClasses(); j++) {
+	  m_Counts[j][attIndex] = new double[1];
+	}
+      }
+      attIndex++;
+    }
+    
+    // Compute counts and sums
+    Enumeration enumInsts = instances.enumerateInstances();
+    while (enumInsts.hasMoreElements()) {
+      Instance instance = (Instance) enumInsts.nextElement();
+      if (!instance.classIsMissing()) {
+	Enumeration enumAtts = instances.enumerateAttributes();
+	attIndex = 0;
+	while (enumAtts.hasMoreElements()) {
+	  Attribute attribute = (Attribute) enumAtts.nextElement();
+	  if (!instance.isMissing(attribute)) {
+	    if (attribute.isNominal()) {
+	      m_Counts[(int)instance.classValue()][attIndex]
+		[(int)instance.value(attribute)]++;
+	    } else {
+	      m_Means[(int)instance.classValue()][attIndex] +=
+		instance.value(attribute);
+	      m_Counts[(int)instance.classValue()][attIndex][0]++;
+	    }
+	  }
+	  attIndex++;
+	}
+	m_Priors[(int)instance.classValue()]++;
+      }
+    }
+    
+    // Compute means
+    Enumeration enumAtts = instances.enumerateAttributes();
+    attIndex = 0;
+    while (enumAtts.hasMoreElements()) {
+      Attribute attribute = (Attribute) enumAtts.nextElement();
+      if (attribute.isNumeric()) {
+	for (int j = 0; j < instances.numClasses(); j++) {
+	  if (m_Counts[j][attIndex][0] < 2) {
+	    throw new Exception("attribute " + attribute.name() +
+				": less than two values for class " +
+				instances.classAttribute().value(j));
+	  }
+	  m_Means[j][attIndex] /= m_Counts[j][attIndex][0];
+	}
+      }
+      attIndex++;
+    }    
+    
+    // Compute standard deviations
+    enumInsts = instances.enumerateInstances();
+    while (enumInsts.hasMoreElements()) {
+      Instance instance = 
+	(Instance) enumInsts.nextElement();
+      if (!instance.classIsMissing()) {
+	enumAtts = instances.enumerateAttributes();
+	attIndex = 0;
+	while (enumAtts.hasMoreElements()) {
+	  Attribute attribute = (Attribute) enumAtts.nextElement();
+	  if (!instance.isMissing(attribute)) {
+	    if (attribute.isNumeric()) {
+	      m_Devs[(int)instance.classValue()][attIndex] +=
+		(m_Means[(int)instance.classValue()][attIndex]-
+		 instance.value(attribute))*
+		(m_Means[(int)instance.classValue()][attIndex]-
+		 instance.value(attribute));
+	    }
+	  }
+	  attIndex++;
+	}
+      }
+    }
+    enumAtts = instances.enumerateAttributes();
+    attIndex = 0;
+    while (enumAtts.hasMoreElements()) {
+      Attribute attribute = (Attribute) enumAtts.nextElement();
+      if (attribute.isNumeric()) {
+	for (int j = 0; j < instances.numClasses(); j++) {
+	  if (m_Devs[j][attIndex] <= 0) {
+	    throw new Exception("attribute " + attribute.name() +
+				": standard deviation is 0 for class " +
+				instances.classAttribute().value(j));
+	  }
+	  else {
+	    m_Devs[j][attIndex] /= m_Counts[j][attIndex][0] - 1;
+	    m_Devs[j][attIndex] = Math.sqrt(m_Devs[j][attIndex]);
+	  }
+	}
+      }
+      attIndex++;
+    } 
+    
+    // Normalize counts
+    enumAtts = instances.enumerateAttributes();
+    attIndex = 0;
+    while (enumAtts.hasMoreElements()) {
+      Attribute attribute = (Attribute) enumAtts.nextElement();
+      if (attribute.isNominal()) {
+	for (int j = 0; j < instances.numClasses(); j++) {
+	  sum = Utils.sum(m_Counts[j][attIndex]);
+	  for (int i = 0; i < attribute.numValues(); i++) {
+	    m_Counts[j][attIndex][i] =
+	      (m_Counts[j][attIndex][i] + 1) 
+	      / (sum + (double)attribute.numValues());
+	  }
+	}
+      }
+      attIndex++;
+    }
+    
+    // Normalize priors
+    sum = Utils.sum(m_Priors);
+    for (int j = 0; j < instances.numClasses(); j++)
+      m_Priors[j] = (m_Priors[j] + 1) 
+	/ (sum + (double)instances.numClasses());
+  }
+
+  /**
+   * Calculates the class membership probabilities for the given test instance.
+   *
+   * @param instance the instance to be classified
+   * @return predicted class probability distribution
+   * @exception Exception if distribution can't be computed
+   */
+  public double[] distributionForInstance(Instance instance) throws Exception {
+    
+    double [] probs = new double[instance.numClasses()];
+    int attIndex;
+    
+    for (int j = 0; j < instance.numClasses(); j++) {
+      probs[j] = 1;
+      Enumeration enumAtts = instance.enumerateAttributes();
+      attIndex = 0;
+      while (enumAtts.hasMoreElements()) {
+	Attribute attribute = (Attribute) enumAtts.nextElement();
+	if (!instance.isMissing(attribute)) {
+	  if (attribute.isNominal()) {
+	    probs[j] *= m_Counts[j][attIndex][(int)instance.value(attribute)];
+	  } else {
+	    probs[j] *= normalDens(instance.value(attribute),
+				   m_Means[j][attIndex],
+				   m_Devs[j][attIndex]);}
+	}
+	attIndex++;
+      }
+      probs[j] *= m_Priors[j];
+    }
+    
+    // Normalize probabilities
+    Utils.normalize(probs);
+
+    return probs;
+  }
+
+  /**
+   * Returns a description of the classifier.
+   *
+   * @return a description of the classifier as a string.
+   */
+  public String toString() {
+
+    if (m_Instances == null) {
+      return "Naive Bayes (simple): No model built yet.";
+    }
+    try {
+      StringBuffer text = new StringBuffer("Naive Bayes (simple)");
+      int attIndex;
+      
+      for (int i = 0; i < m_Instances.numClasses(); i++) {
+	text.append("\n\nClass " + m_Instances.classAttribute().value(i) 
+		    + ": P(C) = " 
+		    + Utils.doubleToString(m_Priors[i], 10, 8)
+		    + "\n\n");
+	Enumeration enumAtts = m_Instances.enumerateAttributes();
+	attIndex = 0;
+	while (enumAtts.hasMoreElements()) {
+	  Attribute attribute = (Attribute) enumAtts.nextElement();
+	  text.append("Attribute " + attribute.name() + "\n");
+	  if (attribute.isNominal()) {
+	    for (int j = 0; j < attribute.numValues(); j++) {
+	      text.append(attribute.value(j) + "\t");
+	    }
+	    text.append("\n");
+	    for (int j = 0; j < attribute.numValues(); j++)
+	      text.append(Utils.
+			  doubleToString(m_Counts[i][attIndex][j], 10, 8)
+			  + "\t");
+	  } else {
+	    text.append("Mean: " + Utils.
+			doubleToString(m_Means[i][attIndex], 10, 8) + "\t");
+	    text.append("Standard Deviation: " 
+			+ Utils.doubleToString(m_Devs[i][attIndex], 10, 8));
+	  }
+	  text.append("\n\n");
+	  attIndex++;
+	}
+      }
+      
+      return text.toString();
+    } catch (Exception e) {
+      return "Can't print Naive Bayes classifier!";
+    }
+  }
+
+  /**
+   * Density function of normal distribution.
+   */
+  private double normalDens(double x, double mean, double stdDev) {
+    
+    double diff = x - mean;
+    
+    return (1 / (NORM_CONST * stdDev)) 
+      * Math.exp(-(diff * diff / (2 * stdDev * stdDev)));
+  }
+
+  /**
+   * Main method for testing this class.
+   *
+   * @param argv the options
+   */
+  public static void main(String [] argv) {
+
+    Classifier scheme;
+
+    try {
+      scheme = new NaiveBayesSimple();
+      System.out.println("Evaluation disabled!");
+      //System.out.println(Evaluation.evaluateModel(scheme, argv));
+    } catch (Exception e) {
+      System.err.println(e.getMessage());
+    }
+  }
+}
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Attribute.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Attribute.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Attribute.java	(revision 16571)
@@ -0,0 +1,682 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Attribute.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+import java.io.*;
+import java.util.*;
+
+/** 
+ * Class for handling an attribute. Once an attribute has been created,
+ * it can't be changed. <p>
+ *
+ * Three attribute types are supported:
+ * <ul>
+ *    <li> numeric: <ul>
+ *         This type of attribute represents a floating-point number.
+ *    </ul>
+ *    <li> nominal: <ul>
+ *         This type of attribute represents a fixed set of nominal values.
+ *    </ul>
+ *    <li> string: <ul>
+ *         This type of attribute represents a dynamically expanding set of
+ *         nominal values. String attributes are not used by the learning
+ *         schemes in Weka. They can be used, for example,  to store an 
+ *         identifier with each instance in a dataset.
+ *    </ul>
+ * </ul>
+ * Typical usage (code from the main() method of this class): <p>
+ *
+ * <code>
+ * ... <br>
+ *
+ * // Create numeric attributes "length" and "weight" <br>
+ * Attribute length = new Attribute("length"); <br>
+ * Attribute weight = new Attribute("weight"); <br><br>
+ * 
+ * // Create vector to hold nominal values "first", "second", "third" <br>
+ * FastVector my_nominal_values = new FastVector(3); <br>
+ * my_nominal_values.addElement("first"); <br>
+ * my_nominal_values.addElement("second"); <br>
+ * my_nominal_values.addElement("third"); <br><br>
+ *
+ * // Create nominal attribute "position" <br>
+ * Attribute position = new Attribute("position", my_nominal_values);<br>
+ *
+ * ... <br>
+ * </code><p>
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public class Attribute implements Copyable, Serializable {
+
+  /** Constant set for numeric attributes. */
+  public final static int NUMERIC = 0;
+
+  /** Constant set for nominal attributes. */
+  public final static int NOMINAL = 1;
+
+  /** Constant set for attributes with string values. */
+  public final static int STRING = 2;
+
+  /** Strings longer than this will be stored compressed. */
+  private final static int STRING_COMPRESS_THRESHOLD = 200;
+  //private final static int STRING_COMPRESS_THRESHOLD = Integer.MAX_VALUE;
+
+  /** The attribute's name. */
+  private String m_Name;
+
+  /** The attribute's type. */
+  private int m_Type;
+
+  /** The attribute's values (if nominal or string). */
+  private FastVector m_Values;
+
+  /** Mapping of values to indices (if nominal or string). */
+  private Hashtable m_Hashtable;
+
+  /** The attribute's index. */
+  private int m_Index;
+
+  /**
+   * Constructor for a numeric attribute.
+   *
+   * @param attributeName the name for the attribute
+   */
+  public Attribute(String attributeName) {
+
+    m_Name = attributeName;
+    m_Index = -1;
+    m_Values = null;
+    m_Hashtable = null;
+    m_Type = NUMERIC;
+  }
+
+  /**
+   * Constructor for nominal attributes and string attributes.
+   * If a null vector of attribute values is passed to the method,
+   * the attribute is assumed to be a string.
+   *
+   * @param attributeName the name for the attribute
+   * @param attributeValues a vector of strings denoting the 
+   * attribute values. Null if the attribute is a string attribute.
+   */
+  public Attribute(String attributeName, 
+		   FastVector attributeValues) {
+
+    m_Name = attributeName;
+    m_Index = -1;
+    if (attributeValues == null) {
+      m_Values = new FastVector();
+      m_Hashtable = new Hashtable();
+      m_Type = STRING;
+    } else {
+      m_Values = (FastVector) attributeValues.copy();
+      m_Hashtable = new Hashtable(m_Values.size());
+      for (int i = 0; i < m_Values.size(); i++) {
+	m_Hashtable.put(m_Values.elementAt(i), new Integer(i));
+      }
+      m_Type = NOMINAL;
+    }
+  }
+
+  /**
+   * Produces a shallow copy of this attribute.
+   *
+   * @return a copy of this attribute with the same index
+   */
+  public Object copy() {
+
+    Attribute copy = new Attribute(m_Name);
+
+    copy.m_Index = m_Index;
+    if (!isNominal() && !isString())
+      return copy;
+    copy.m_Type = m_Type;
+    copy.m_Values = m_Values;
+    copy.m_Hashtable = m_Hashtable;
+ 
+    return copy;
+  }
+
+  /**
+   * Returns an enumeration of all the attribute's values if
+   * the attribute is nominal or a string, null otherwise. 
+   *
+   * @return enumeration of all the attribute's values
+   */
+  public final Enumeration enumerateValues() {
+
+    if (isNominal() || isString()) {
+      final Enumeration ee = m_Values.elements();
+      return new Enumeration () {
+          public boolean hasMoreElements() {
+            return ee.hasMoreElements();
+          }
+          public Object nextElement() {
+            Object oo = ee.nextElement();
+            if (oo instanceof SerializedObject) {
+              return ((SerializedObject)oo).getObject();
+            } else {
+              return oo;
+            }
+          }
+        };
+    }
+    return null;
+  }
+
+  /**
+   * Tests if given attribute is equal to this attribute.
+   *
+   * @param other the Object to be compared to this attribute
+   * @return true if the given attribute is equal to this attribute
+   */
+  public final boolean equals(Object other) {
+
+    if ((other == null) || !(other.getClass().equals(this.getClass()))) {
+      return false;
+    }
+    Attribute att = (Attribute) other;
+    if (!m_Name.equals(att.m_Name)) {
+      return false;
+    }
+    if (isNumeric() && att.isNumeric()) {
+      return true;
+    }
+    if (isNumeric() || att.isNumeric()) {
+      return false;
+    }
+    if (m_Values.size() != att.m_Values.size()) {
+      return false;
+    }
+    for (int i = 0; i < m_Values.size(); i++) {
+      if (!m_Values.elementAt(i).equals(att.m_Values.elementAt(i))) {
+	return false;
+      }
+    }
+    return true;
+  }
+
+  /**
+   * Returns the index of this attribute.
+   *
+   * @return the index of this attribute
+   */
+  public final int index() {
+
+    return m_Index;
+  }
+
+  /**
+   * Returns the index of a given attribute value. (The index of
+   * the first occurence of this value.)
+   *
+   * @param value the value for which the index is to be returned
+   * @return the index of the given attribute value if attribute
+   * is nominal or a string, -1 if it is numeric or the value 
+   * can't be found
+   */
+  public final int indexOfValue(String value) {
+
+    if (!isNominal() && !isString())
+      return -1;
+    Object store = value;
+    if (value.length() > STRING_COMPRESS_THRESHOLD) {
+      try {
+        store = new SerializedObject(value, true);
+      } catch (Exception ex) {
+        System.err.println("Couldn't compress string attribute value -"
+                           + " searching uncompressed.");
+      }
+    }
+    Integer val = (Integer)m_Hashtable.get(store);
+    if (val == null) {
+      throw new IllegalArgumentException("Value \"" + value + 
+					 "\" not found in attribute " +
+					 "declaration!");
+    } else {
+      return val.intValue();
+    }
+  }
+
+  /**
+   * Test if the attribute is nominal.
+   *
+   * @return true if the attribute is nominal
+   */
+  public final boolean isNominal() {
+
+    return (m_Type == NOMINAL);
+  }
+
+  /**
+   * Tests if the attribute is numeric.
+   *
+   * @return true if the attribute is numeric
+   */
+  public final boolean isNumeric() {
+
+    return (m_Type == NUMERIC);
+  }
+
+  /**
+   * Tests if the attribute is a string.
+   *
+   * @return true if the attribute is a string
+   */
+  public final boolean isString() {
+
+    return (m_Type == STRING);
+  }
+
+  /**
+   * Returns the attribute's name.
+   *
+   * @return the attribute's name as a string
+   */
+  public final String name() {
+
+    return m_Name;
+  }
+  
+  /**
+   * Returns the number of attribute values. Returns 0 for numeric attributes.
+   *
+   * @return the number of attribute values
+   */
+  public final int numValues() {
+
+    if (!isNominal() && !isString()) {
+      return 0;
+    } else {
+      return m_Values.size();
+    }
+  }
+
+  /**
+   * Returns a description of this attribute in ARFF format. Quotes
+   * strings if they contain whitespace characters, or if they
+   * are a question mark.
+   *
+   * @return a description of this attribute as a string
+   */
+  public final String toString() {
+    
+    StringBuffer text = new StringBuffer();
+    
+    text.append("@attribute " + Utils.quote(m_Name) + " ");
+    if (isNominal()) {
+      text.append('{');
+      Enumeration enum = enumerateValues();
+      while (enum.hasMoreElements()) {
+	text.append(Utils.quote((String) enum.nextElement()));
+	if (enum.hasMoreElements())
+	  text.append(',');
+      }
+      text.append('}');
+    } else {
+      if (isNumeric()) {
+	text.append("numeric");
+      } else {
+	text.append("string");
+      }
+    }
+    return text.toString();
+  }
+
+  /**
+   * Returns the attribute's type as an integer.
+   *
+   * @returns the attribute's type.
+   */
+  public final int type() {
+
+    return m_Type;
+  }
+
+  /**
+   * Returns a value of a nominal or string attribute. 
+   * Returns an empty string if the attribute is neither
+   * nominal nor a string attribute.
+   *
+   * @param valIndex the value's index
+   * @return the attribute's value as a string
+   */
+  public final String value(int valIndex) {
+    
+    if (!isNominal() && !isString()) {
+      return "";
+    } else {
+      Object val = m_Values.elementAt(valIndex);
+      
+      // If we're storing strings compressed, uncompress it.
+      if (val instanceof SerializedObject) {
+        val = ((SerializedObject)val).getObject();
+      }
+      return (String) val;
+    }
+  }
+
+  /**
+   * Constructor for a numeric attribute with a particular index.
+   *
+   * @param attributeName the name for the attribute
+   * @param index the attribute's index
+   */
+  Attribute(String attributeName, int index) {
+
+    this(attributeName);
+
+    m_Index = index;
+  }
+
+  /**
+   * Constructor for nominal attributes and string attributes with
+   * a particular index.
+   * If a null vector of attribute values is passed to the method,
+   * the attribute is assumed to be a string.
+   *
+   * @param attributeName the name for the attribute
+   * @param attributeValues a vector of strings denoting the attribute values.
+   * Null if the attribute is a string attribute.
+   * @param index the attribute's index
+   */
+  Attribute(String attributeName, FastVector attributeValues, 
+	    int index) {
+
+    this(attributeName, attributeValues);
+
+    m_Index = index;
+  }
+
+  /**
+   * Adds a string value to the list of valid strings for attributes
+   * of type STRING and returns the index of the string.
+   *
+   * @param value The string value to add
+   * @return the index assigned to the string, or -1 if the attribute is not
+   * of type Attribute.STRING 
+   */
+  public int addStringValue(String value) {
+
+    if (!isString()) {
+      return -1;
+    }
+    Object store = value;
+
+    if (value.length() > STRING_COMPRESS_THRESHOLD) {
+      try {
+        store = new SerializedObject(value, true);
+      } catch (Exception ex) {
+        System.err.println("Couldn't compress string attribute value -"
+                           + " storing uncompressed.");
+      }
+    }
+    Integer index = (Integer)m_Hashtable.get(store);
+    if (index != null) {
+      return index.intValue();
+    } else {
+      int intIndex = m_Values.size();
+      m_Values.addElement(store);
+      m_Hashtable.put(store, new Integer(intIndex));
+      return intIndex;
+    }
+  }
+
+  /**
+   * Adds a string value to the list of valid strings for attributes
+   * of type STRING and returns the index of the string. This method is
+   * more efficient than addStringValue(String) for long strings.
+   *
+   * @param src The Attribute containing the string value to add.
+   * @param int index the index of the string value in the source attribute.
+   * @return the index assigned to the string, or -1 if the attribute is not
+   * of type Attribute.STRING 
+   */
+  public int addStringValue(Attribute src, int index) {
+
+    if (!isString()) {
+      return -1;
+    }
+    Object store = src.m_Values.elementAt(index);
+    Integer oldIndex = (Integer)m_Hashtable.get(store);
+    if (oldIndex != null) {
+      return oldIndex.intValue();
+    } else {
+      int intIndex = m_Values.size();
+      m_Values.addElement(store);
+      m_Hashtable.put(store, new Integer(intIndex));
+      return intIndex;
+    }
+  }
+
+  /**
+   * Adds an attribute value. Creates a fresh list of attribute
+   * values before adding it.
+   *
+   * @param value the attribute value
+   */
+  final void addValue(String value) {
+
+    m_Values = (FastVector)m_Values.copy();
+    m_Hashtable = (Hashtable)m_Hashtable.clone();
+    forceAddValue(value);
+  }
+
+  /**
+   * Produces a shallow copy of this attribute with a new name.
+   *
+   * @param newName the name of the new attribute
+   * @return a copy of this attribute with the same index
+   */
+  final Attribute copy(String newName) {
+
+    Attribute copy = new Attribute(newName);
+
+    copy.m_Index = m_Index;
+    if (!isNominal() && !isString())
+      return copy;
+    copy.m_Type = m_Type;
+    copy.m_Values = m_Values;
+    copy.m_Hashtable = m_Hashtable;
+ 
+    return copy;
+  }
+
+  /**
+   * Removes a value of a nominal or string attribute. Creates a 
+   * fresh list of attribute values before removing it.
+   *
+   * @param index the value's index
+   * @exception IllegalArgumentException if the attribute is not nominal
+   */
+  final void delete(int index) {
+    
+    if (!isNominal() && !isString()) 
+      throw new IllegalArgumentException("Can only remove value of" +
+                                         "nominal or string attribute!");
+    else {
+      m_Values = (FastVector)m_Values.copy();
+      m_Values.removeElementAt(index);
+      Hashtable hash = new Hashtable(m_Hashtable.size());
+      Enumeration enum = hash.keys();
+      while (enum.hasMoreElements()) {
+	String string = (String)enum.nextElement();
+	Integer valIndexObject = (Integer)m_Hashtable.get(string);
+	int valIndex = valIndexObject.intValue();
+	if (valIndex > index) {
+	  hash.put(string, new Integer(valIndex - 1));
+	} else if (valIndex < index) {
+	  hash.put(string, valIndexObject);
+	}
+      }
+      m_Hashtable = hash;
+    }
+  }
+
+  /**
+   * Adds an attribute value.
+   *
+   * @param value the attribute value
+   */
+  final void forceAddValue(String value) {
+
+    Object store = value;
+    if (value.length() > STRING_COMPRESS_THRESHOLD) {
+      try {
+        store = new SerializedObject(value, true);
+      } catch (Exception ex) {
+        System.err.println("Couldn't compress string attribute value -"
+                           + " storing uncompressed.");
+      }
+    }
+    m_Values.addElement(store);
+    m_Hashtable.put(store, new Integer(m_Values.size() - 1));
+  }
+
+  /**
+   * Sets the index of this attribute.
+   *
+   * @param the index of this attribute
+   */
+  final void setIndex(int index) {
+
+    m_Index = index;
+  }
+
+  /**
+   * Sets a value of a nominal attribute or string attribute.
+   * Creates a fresh list of attribute values before it is set.
+   *
+   * @param index the value's index
+   * @param string the value
+   * @exception IllegalArgumentException if the attribute is not nominal or 
+   * string.
+   */
+  final void setValue(int index, String string) {
+
+    if (!isNominal() && !isString()) {
+      throw new IllegalArgumentException("Can only set value of nominal"+
+                                         "or string attribute!");
+    } else {
+      m_Values = (FastVector)m_Values.copy();
+      m_Hashtable = (Hashtable)m_Hashtable.clone();
+      Object store = string;
+      if (string.length() > STRING_COMPRESS_THRESHOLD) {
+        try {
+          store = new SerializedObject(string, true);
+        } catch (Exception ex) {
+          System.err.println("Couldn't compress string attribute value -"
+                             + " storing uncompressed.");
+        }
+      }
+      m_Hashtable.remove(m_Values.elementAt(index));
+      m_Values.setElementAt(store, index);
+      m_Hashtable.put(store, new Integer(index));
+    }
+  }
+
+  /**
+   * Simple main method for testing this class.
+   */
+  public static void main(String[] ops) {
+
+    try {
+      
+      // Create numeric attributes "length" and "weight"
+      Attribute length = new Attribute("length");
+      Attribute weight = new Attribute("weight");
+      
+      // Create vector to hold nominal values "first", "second", "third" 
+      FastVector my_nominal_values = new FastVector(3); 
+      my_nominal_values.addElement("first"); 
+      my_nominal_values.addElement("second"); 
+      my_nominal_values.addElement("third"); 
+      
+      // Create nominal attribute "position" 
+      Attribute position = new Attribute("position", my_nominal_values);
+
+      // Print the name of "position"
+      System.out.println("Name of \"position\": " + position.name());
+
+      // Print the values of "position"
+      Enumeration attValues = position.enumerateValues();
+      while (attValues.hasMoreElements()) {
+	String string = (String)attValues.nextElement();
+	System.out.println("Value of \"position\": " + string);
+      }
+
+      // Shallow copy attribute "position"
+      Attribute copy = (Attribute) position.copy();
+
+      // Test if attributes are the same
+      System.out.println("Copy is the same as original: " + copy.equals(position));
+
+      // Print index of attribute "weight" (should be unset: -1)
+      System.out.println("Index of attribute \"weight\" (should be -1): " + 
+			 weight.index());
+
+      // Print index of value "first" of attribute "position"
+      System.out.println("Index of value \"first\" of \"position\" (should be 0): " +
+			 position.indexOfValue("first"));
+
+      // Tests type of attribute "position"
+      System.out.println("\"position\" is numeric: " + position.isNumeric());
+      System.out.println("\"position\" is nominal: " + position.isNominal());
+      System.out.println("\"position\" is string: " + position.isString());
+
+      // Prints name of attribute "position"
+      System.out.println("Name of \"position\": " + position.name());
+    
+      // Prints number of values of attribute "position"
+      System.out.println("Number of values for \"position\": " + position.numValues());
+
+      // Prints the values (againg)
+      for (int i = 0; i < position.numValues(); i++) {
+	System.out.println("Value " + i + ": " + position.value(i));
+      }
+
+      // Prints the attribute "position" in ARFF format
+      System.out.println(position);
+
+      // Checks type of attribute "position" using constants
+      switch (position.type()) {
+      case Attribute.NUMERIC:
+	System.out.println("\"position\" is numeric");
+	break;
+      case Attribute.NOMINAL:
+	System.out.println("\"position\" is nominal");
+	break;
+      case Attribute.STRING:
+	System.out.println("\"position\" is string");
+	break;
+      default:
+	System.out.println("\"position\" has unknown type");
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+}
+  
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/AttributeStats.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/AttributeStats.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/AttributeStats.java	(revision 16571)
@@ -0,0 +1,136 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    AttributeStats.java
+ *    Copyright (C) 1999 Len Trigg
+ *
+ */
+
+package weka.core;
+
+/**
+ * A Utility class that contains summary information on an
+ * the values that appear in a dataset for a particular attribute.
+ *
+ * @author <a href="mailto:len@webmind.com">Len Trigg</a>
+ * @version $Revision$
+ */
+public class AttributeStats {    
+  
+  /** The number of int-like values */
+  public int intCount = 0;
+  
+  /** The number of real-like values (i.e. have a fractional part) */
+  public int realCount = 0;
+  
+  /** The number of missing values */
+  public int missingCount = 0;
+  
+  /** The number of distinct values */
+  public int distinctCount = 0;
+  
+  /** The number of values that only appear once */
+  public int uniqueCount = 0;
+  
+  /** The total number of values (i.e. number of instances) */
+  public int totalCount = 0;
+  
+  /** Stats on numeric value distributions */
+  // perhaps Stats should be moved from weka.experiment to weka.core
+  public weka.experiment.Stats numericStats;
+  
+  /** Counts of each nominal value */
+  public int [] nominalCounts;
+    
+  /**
+   * Updates the counters for one more observed distinct value.
+   *
+   * @param value the value that has just been seen
+   * @param count the number of times the value appeared
+   */
+  protected void addDistinct(double value, int count) {
+    
+    if (count > 0) {
+      if (count == 1) {
+	uniqueCount++;
+	}
+      if (Utils.eq(value, (double)((int)value))) {
+	intCount += count;
+      } else {
+	realCount += count;
+      }
+      if (nominalCounts != null) {
+	nominalCounts[(int)value] = count;
+      }
+      if (numericStats != null) {
+	  numericStats.add(value, count);
+	  numericStats.calculateDerived();
+      }
+    }
+    distinctCount++;
+  }
+
+  /**
+   * Returns a human readable representation of this AttributeStats instance.
+   *
+   * @return a String represtinging these AttributeStats.
+   */
+  public String toString() {
+
+    StringBuffer sb = new StringBuffer();
+    sb.append(Utils.padLeft("Type", 4)).append(Utils.padLeft("Nom", 5));
+    sb.append(Utils.padLeft("Int", 5)).append(Utils.padLeft("Real", 5));
+    sb.append(Utils.padLeft("Missing", 12));
+    sb.append(Utils.padLeft("Unique", 12));
+    sb.append(Utils.padLeft("Dist", 6));
+    if (nominalCounts != null) {
+      sb.append(' ');
+      for (int i = 0; i < nominalCounts.length; i++) {
+        sb.append(Utils.padLeft("C[" + i + "]", 5));
+      }
+    }
+    sb.append('\n');
+
+    long percent;
+    percent = Math.round(100.0 * intCount / totalCount);
+    if (nominalCounts != null) {
+      sb.append(Utils.padLeft("Nom", 4)).append(' ');
+      sb.append(Utils.padLeft("" + percent, 3)).append("% ");
+      sb.append(Utils.padLeft("" + 0, 3)).append("% ");
+    } else {
+      sb.append(Utils.padLeft("Num", 4)).append(' ');
+      sb.append(Utils.padLeft("" + 0, 3)).append("% ");
+      sb.append(Utils.padLeft("" + percent, 3)).append("% ");
+    }
+    percent = Math.round(100.0 * realCount / totalCount);
+    sb.append(Utils.padLeft("" + percent, 3)).append("% ");
+    sb.append(Utils.padLeft("" + missingCount, 5)).append(" /");
+    percent = Math.round(100.0 * missingCount / totalCount);
+    sb.append(Utils.padLeft("" + percent, 3)).append("% ");
+    sb.append(Utils.padLeft("" + uniqueCount, 5)).append(" /");
+    percent = Math.round(100.0 * uniqueCount / totalCount);
+    sb.append(Utils.padLeft("" + percent, 3)).append("% ");
+    sb.append(Utils.padLeft("" + distinctCount, 5)).append(' ');
+    if (nominalCounts != null) {
+      for (int i = 0; i < nominalCounts.length; i++) {
+        sb.append(Utils.padLeft("" + nominalCounts[i], 5));
+      }
+    }
+    sb.append('\n');
+    return sb.toString();
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/ContingencyTables.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/ContingencyTables.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/ContingencyTables.java	(revision 16571)
@@ -0,0 +1,635 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    ContingencyTables.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+/**
+ * Class implementing some statistical routines for contingency tables.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public class ContingencyTables {
+
+  /** The natural logarithm of 2 */
+  private static double log2 = Math.log(2);
+
+  /**
+   * Returns chi-squared probability for a given matrix.
+   *
+   * @param matrix the contigency table
+   * @param yates is Yates' correction to be used?
+   * @return the chi-squared probability
+   */
+
+  public static double chiSquared(double [][] matrix, boolean yates) {
+
+    int df = (matrix.length - 1) * (matrix[0].length - 1);
+
+    return Statistics.chiSquaredProbability(chiVal(matrix, yates), df);
+  }
+
+  /**
+   * Computes chi-squared statistic for a contingency table.
+   *
+   * @param matrix the contigency table
+   * @param yates is Yates' correction to be used?
+   * @return the value of the chi-squared statistic
+   */
+  public static double chiVal(double [][] matrix, boolean useYates) {
+    
+    int df, nrows, ncols, row, col;
+    double[] rtotal, ctotal;
+    double expect = 0, chival = 0, n = 0;
+    boolean yates = true;
+    
+    nrows = matrix.length;
+    ncols = matrix[0].length;
+    rtotal = new double [nrows];
+    ctotal = new double [ncols];
+    for (row = 0; row < nrows; row++) {
+      for (col = 0; col < ncols; col++) {
+	rtotal[row] += matrix[row][col];
+	ctotal[col] += matrix[row][col];
+	n += matrix[row][col];
+      }
+    }
+    df = (nrows - 1)*(ncols - 1);
+    if ((df > 1) || (!useYates)) {
+      yates = false;
+    } else if (df <= 0) {
+      return 0;
+    }
+    chival = 0.0;
+    for (row = 0; row < nrows; row++) {
+      if (Utils.gr(rtotal[row], 0)) {
+	for (col = 0; col < ncols; col++) {
+	  if (Utils.gr(ctotal[col], 0)) {
+	    expect = (ctotal[col] * rtotal[row]) / n;
+	    chival += chiCell (matrix[row][col], expect, yates);
+	  }
+	}
+      }
+    }
+    return chival;
+  }
+
+  /**
+   * Tests if Cochran's criterion is fullfilled for the given
+   * contingency table. Rows and columns with all zeros are not considered
+   * relevant.
+   *
+   * @param matrix the contigency table to be tested
+   * @return true if contingency table is ok, false if not
+   */
+  public static boolean cochransCriterion(double[][] matrix) {
+
+    double[] rtotal, ctotal;
+    double n = 0, expect, smallfreq = 5;
+    int smallcount = 0, nonZeroRows = 0, nonZeroColumns = 0, nrows, ncols, 
+      row, col;
+
+    nrows = matrix.length;
+    ncols = matrix[0].length;
+
+    rtotal = new double [nrows];
+    ctotal = new double [ncols];
+    for (row = 0; row < nrows; row++) {
+      for (col = 0; col < ncols; col++) {
+	rtotal[row] += matrix[row][col];
+	ctotal[col] += matrix[row][col];
+	n += matrix[row][col];
+      }
+    }
+    for (row = 0; row < nrows; row++) {
+      if (Utils.gr(rtotal[row], 0)) {
+	nonZeroRows++;
+      }
+    }
+    for (col = 0; col < ncols; col++) {
+      if (Utils.gr(ctotal[col], 0)) {
+	nonZeroColumns++;
+      }
+    }
+    for (row = 0; row < nrows; row++) {
+      if (Utils.gr(rtotal[row], 0)) {
+	for (col = 0; col < ncols; col++) {
+	  if (Utils.gr(ctotal[col], 0)) {
+	    expect = (ctotal[col] * rtotal[row]) / n;
+	    if (Utils.sm(expect, smallfreq)) {
+	      if (Utils.sm(expect, 1)) {
+		return false;
+	      } else {
+		smallcount++;
+		if (smallcount > (nonZeroRows * nonZeroColumns) / smallfreq) {
+		  return false;
+		}
+	      }
+	    }
+	  }
+	}
+      }
+    }
+    return true;
+  }
+
+  /**
+   * Computes Cramer's V for a contingency table.
+   *
+   * @param matrix the contingency table
+   * @return Cramer's V
+   */
+  public static double CramersV(double [][] matrix) {
+
+    int row, col, nrows,ncols, min;
+    double n = 0;
+    
+    nrows = matrix.length;
+    ncols = matrix[0].length;
+    for (row = 0; row < nrows; row++) {
+      for (col = 0; col < ncols; col++) {
+	n += matrix[row][col];
+      }
+    }
+    min = nrows < ncols ? nrows-1 : ncols-1;
+    if ((min == 0) || Utils.eq(n, 0))
+      return 0;
+    return Math.sqrt(chiVal(matrix, false) / (n * (double)min)); 
+  } 
+
+  /**
+   * Computes the entropy of the given array.
+   *
+   * @param array the array
+   * @return the entropy
+   */
+  public static double entropy(double[] array) {
+
+    double returnValue = 0, sum = 0;
+
+    for (int i = 0; i < array.length; i++) {
+      returnValue -= lnFunc(array[i]);
+      sum += array[i];
+    }
+    if (Utils.eq(sum, 0)) {
+      return 0;
+    } else {
+      return (returnValue + lnFunc(sum)) / (sum * log2);
+    }
+  }
+
+  /**
+   * Computes conditional entropy of the rows given
+   * the columns.
+   *
+   * @param matrix the contingency table
+   * @return the conditional entropy of the rows given the columns
+   */
+  public static double entropyConditionedOnColumns(double[][] matrix) {
+    
+    double returnValue = 0, sumForColumn, total = 0;
+
+    for (int j = 0; j < matrix[0].length; j++) {
+      sumForColumn = 0;
+      for (int i = 0; i < matrix.length; i++) {
+	returnValue = returnValue + lnFunc(matrix[i][j]);
+	sumForColumn += matrix[i][j];
+      }
+      returnValue = returnValue - lnFunc(sumForColumn);
+      total += sumForColumn;
+    }
+    if (Utils.eq(total, 0)) {
+      return 0;
+    }
+    return -returnValue / (total * log2);
+  }
+
+  /**
+   * Computes conditional entropy of the columns given
+   * the rows.
+   *
+   * @param matrix the contingency table
+   * @return the conditional entropy of the columns given the rows
+   */
+  public static double entropyConditionedOnRows(double[][] matrix) {
+    
+    double returnValue = 0, sumForRow, total = 0;
+
+    for (int i = 0; i < matrix.length; i++) {
+      sumForRow = 0;
+      for (int j = 0; j < matrix[0].length; j++) {
+	returnValue = returnValue + lnFunc(matrix[i][j]);
+	sumForRow += matrix[i][j];
+      }
+      returnValue = returnValue - lnFunc(sumForRow);
+      total += sumForRow;
+    }
+    if (Utils.eq(total, 0)) {
+      return 0;
+    }
+    return -returnValue / (total * log2);
+  }
+
+  /**
+   * Computes conditional entropy of the columns given the rows
+   * of the test matrix with respect to the train matrix. Uses a
+   * Laplace prior. Does NOT normalize the entropy.
+   *
+   * @param train the train matrix 
+   * @param test the test matrix
+   * @param the number of symbols for Laplace
+   * @return the entropy
+   */
+  public static double entropyConditionedOnRows(double[][] train, 
+						double[][] test,
+						double numClasses) {
+    
+    double returnValue = 0, trainSumForRow, testSumForRow, testSum = 0;
+
+    for (int i = 0; i < test.length; i++) {
+      trainSumForRow = 0;
+      testSumForRow = 0;
+      for (int j = 0; j < test[0].length; j++) {
+	returnValue -= test[i][j] * Math.log(train[i][j] + 1);
+	trainSumForRow += train[i][j];
+	testSumForRow += test[i][j];
+      }
+      testSum = testSumForRow;
+      returnValue += testSumForRow * Math.log(trainSumForRow + 
+					     numClasses);
+    }
+    return returnValue / (testSum * log2);
+  }
+
+  /**
+   * Computes the rows' entropy for the given contingency table.
+   *
+   * @param matrix the contingency table
+   * @return the rows' entropy
+   */
+  public static double entropyOverRows(double[][] matrix) {
+    
+    double returnValue = 0, sumForRow, total = 0;
+
+    for (int i = 0; i < matrix.length; i++) {
+      sumForRow = 0;
+      for (int j = 0; j < matrix[0].length; j++) {
+	sumForRow += matrix[i][j];
+      }
+      returnValue = returnValue - lnFunc(sumForRow);
+      total += sumForRow;
+    }
+    if (Utils.eq(total, 0)) {
+      return 0;
+    }
+    return (returnValue + lnFunc(total)) / (total * log2);
+  }
+
+  /**
+   * Computes the columns' entropy for the given contingency table.
+   *
+   * @param matrix the contingency table
+   * @return the columns' entropy
+   */
+  public static double entropyOverColumns(double[][] matrix){
+    
+    double returnValue = 0, sumForColumn, total = 0;
+
+    for (int j = 0; j < matrix[0].length; j++){
+      sumForColumn = 0;
+      for (int i = 0; i < matrix.length; i++) {
+	sumForColumn += matrix[i][j];
+      }
+      returnValue = returnValue - lnFunc(sumForColumn);
+      total += sumForColumn;
+    }
+    if (Utils.eq(total, 0)) {
+      return 0;
+    }
+    return (returnValue + lnFunc(total)) / (total * log2);
+  }
+
+  /**
+   * Computes gain ratio for contingency table (split on rows).
+   * Returns Double.MAX_VALUE if the split entropy is 0.
+   *
+   * @param matrix the contingency table
+   * @return the gain ratio
+   */
+  public static double gainRatio(double[][] matrix){
+    
+    double preSplit = 0, postSplit = 0, splitEnt = 0,
+      sumForRow, sumForColumn, total = 0, infoGain;
+
+    // Compute entropy before split
+    for (int i = 0; i < matrix[0].length; i++) {
+      sumForColumn = 0;
+      for (int j = 0; j < matrix.length; j++) 
+	sumForColumn += matrix[j][i];
+      preSplit += lnFunc(sumForColumn);
+      total += sumForColumn;
+    }
+    preSplit -= lnFunc(total);
+
+    // Compute entropy after split and split entropy
+    for (int i = 0; i < matrix.length; i++) {
+      sumForRow = 0;
+      for (int j = 0; j < matrix[0].length; j++) {
+	postSplit += lnFunc(matrix[i][j]);
+	sumForRow += matrix[i][j];
+      }
+      splitEnt += lnFunc(sumForRow);
+    }
+    postSplit -= splitEnt;
+    splitEnt -= lnFunc(total);
+
+    infoGain = preSplit - postSplit;
+    if (Utils.eq(splitEnt, 0))
+      return 0;
+    return infoGain / splitEnt;
+  }
+
+  /**
+   * Returns negative base 2 logarithm of multiple hypergeometric
+   * probability for a contingency table.
+   *
+   * @param matrix the contingency table
+   * @return the log of the hypergeometric probability of the contingency table 
+   */
+  public static double log2MultipleHypergeometric(double[][] matrix) {
+
+    double sum = 0, sumForRow, sumForColumn, total = 0;
+
+    for (int i = 0; i < matrix.length; i++) {
+      sumForRow = 0;
+      for (int j = 0; j < matrix[i].length; j++) {
+	sumForRow += matrix[i][j];
+      }
+      sum += SpecialFunctions.lnFactorial(sumForRow);
+      total += sumForRow;
+    }
+    for (int j = 0; j < matrix[0].length; j++) {
+      sumForColumn = 0;
+      for (int i = 0; i < matrix.length; i++) {
+	sumForColumn += matrix [i][j];
+      }
+      sum += SpecialFunctions.lnFactorial(sumForColumn);
+    }
+    for (int i = 0; i < matrix.length; i++) {
+      for (int j = 0; j < matrix[i].length; j++) {
+	sum -= SpecialFunctions.lnFactorial(matrix[i][j]);
+      }
+    }
+    sum -= SpecialFunctions.lnFactorial(total);
+    return -sum / log2;
+  }
+
+  /**
+   * Reduces a matrix by deleting all zero rows and columns.
+   *
+   * @param matrix the matrix to be reduced
+   * @param the matrix with all zero rows and columns deleted
+   */
+  public static double[][] reduceMatrix(double[][] matrix) {
+
+    int row, col, currCol, currRow, nrows, ncols, 
+      nonZeroRows = 0, nonZeroColumns = 0;
+    double[] rtotal, ctotal;
+    double[][] newMatrix;
+
+    nrows = matrix.length;
+    ncols = matrix[0].length;
+    rtotal = new double [nrows];
+    ctotal = new double [ncols];
+    for (row = 0; row < nrows; row++) {
+      for (col = 0; col < ncols; col++) {
+	rtotal[row] += matrix[row][col];
+	ctotal[col] += matrix[row][col];
+      }
+    }
+    for (row = 0; row < nrows; row++) {
+      if (Utils.gr(rtotal[row],0)) {
+	nonZeroRows++;
+      }
+    }
+    for (col = 0; col < ncols; col++) {
+      if (Utils.gr(ctotal[col],0)) {
+	nonZeroColumns++;
+      }
+    }
+    newMatrix = new double[nonZeroRows][nonZeroColumns];
+    currRow = 0;
+    for (row = 0; row < nrows; row++) {
+      if (Utils.gr(rtotal[row],0)) {
+	currCol = 0;
+	for (col = 0; col < ncols; col++) {
+	  if (Utils.gr(ctotal[col],0)) {
+	    newMatrix[currRow][currCol] = matrix[row][col];
+	    currCol++;
+	  }
+	}
+	currRow++;
+      }
+    }
+    return newMatrix;
+  }
+    
+   /**
+    * Calculates the symmetrical uncertainty for base 2.
+    *
+    * @param matrix the contingency table
+    * @return the calculated symmetrical uncertainty
+    *
+    */
+  public static double symmetricalUncertainty(double matrix[][]) {
+
+    double sumForColumn, sumForRow, total = 0, columnEntropy = 0, 
+      rowEntropy = 0, entropyConditionedOnRows = 0, infoGain = 0;
+
+    // Compute entropy for columns
+    for (int i = 0; i < matrix[0].length; i++) {
+      sumForColumn = 0;
+      for (int j = 0; j < matrix.length; j++) {
+	sumForColumn += matrix[j][i];
+      }
+      columnEntropy += lnFunc(sumForColumn);
+      total += sumForColumn;
+    }
+    columnEntropy -= lnFunc(total);
+
+    // Compute entropy for rows and conditional entropy
+    for (int i = 0; i < matrix.length; i++) {
+      sumForRow = 0;
+      for (int j = 0; j < matrix[0].length; j++) { 
+	sumForRow += matrix[i][j];
+	entropyConditionedOnRows += lnFunc(matrix[i][j]);
+      }
+      rowEntropy += lnFunc(sumForRow);
+    }
+    entropyConditionedOnRows -= rowEntropy;
+    rowEntropy -= lnFunc(total);
+    infoGain = columnEntropy - entropyConditionedOnRows;
+    if (Utils.eq(columnEntropy, 0) || Utils.eq(rowEntropy, 0))
+      return 0;
+    return 2.0 * (infoGain / (columnEntropy + rowEntropy));
+  }
+
+  /**
+   * Computes Goodman and Kruskal's tau-value for a contingency table.
+   *
+   * @param matrix the contingency table
+   * @param Goodman and Kruskal's tau-value
+   */
+  public static double tauVal(double[][] matrix) {
+    
+    int nrows, ncols, row, col;
+    double [] ctotal;
+    double maxcol = 0, max, maxtotal = 0, n = 0;
+    
+    nrows = matrix.length;
+    ncols = matrix[0].length;
+    ctotal = new double [ncols];
+    for (row = 0; row < nrows; row++) {
+      max = 0;
+      for (col = 0; col < ncols; col++) {
+	if (Utils.gr(matrix[row][col], max)) 
+	  max = matrix[row][col];
+	ctotal[col] += matrix[row][col];
+	n += matrix[row][col];
+      }
+      maxtotal += max;
+    }
+    if (Utils.eq(n, 0)) {
+      return 0;
+    }
+    maxcol = ctotal[Utils.maxIndex(ctotal)];
+    return (maxtotal - maxcol)/(n - maxcol);
+  }
+
+  /**
+   * Help method for computing entropy.
+   */
+  private static double lnFunc(double num){
+    
+    // Constant hard coded for efficiency reasons
+    if (num < 1e-6) {
+      return 0;
+    } else {
+      return num * Math.log(num);
+    }
+  }
+  
+  /**
+   * Computes chi-value for one cell in matrix.
+   * From Gary Perlman's unixstat.
+   */
+  private static double chiCell(double freq, double expect, boolean yates){
+
+    double  diff = freq - expect;
+       
+    if (yates) {
+      diff = Math.abs (diff) - 0.5;
+      if (diff < 0.0) { // over-correction
+	diff = 0.0;
+      }
+    }
+    if (Math.abs(expect) < 10e-10) {
+      return (0.0);
+    } else {
+      return (diff * diff / expect);
+    }
+  }
+
+  /**
+   * Main method for testing this class.
+   */
+  public static void main(String[] ops) {
+
+    double[] firstRow = {10, 5, 20};
+    double[] secondRow = {2, 10, 6};
+    double[] thirdRow = {5, 10, 10};
+    double[][] matrix = new double[3][0];
+
+    matrix[0] = firstRow; matrix[1] = secondRow; matrix[2] = thirdRow;
+    for (int i = 0; i < matrix.length; i++) {
+      for (int j = 0; j < matrix[i].length; j++) {
+	System.out.print(matrix[i][j] + " ");
+      }
+      System.out.println();
+    }
+    System.out.println("Chi-squared probability: " +
+		       ContingencyTables.chiSquared(matrix, false));
+    System.out.println("Chi-squared value: " +
+		       ContingencyTables.chiVal(matrix, false));
+    System.out.println("Cochran's criterion fullfilled: " +
+		       ContingencyTables.cochransCriterion(matrix));
+    System.out.println("Cramer's V: " +
+		       ContingencyTables.CramersV(matrix));
+    System.out.println("Entropy of first row: " +
+		       ContingencyTables.entropy(firstRow));
+    System.out.println("Entropy conditioned on columns: " +
+		       ContingencyTables.entropyConditionedOnColumns(matrix));
+    System.out.println("Entropy conditioned on rows: " +
+		       ContingencyTables.entropyConditionedOnRows(matrix));
+    System.out.println("Entropy conditioned on rows (with Laplace): " +
+		       ContingencyTables.entropyConditionedOnRows(matrix, matrix, 3));
+    System.out.println("Entropy of rows: " +
+		       ContingencyTables.entropyOverRows(matrix));
+    System.out.println("Entropy of columns: " +
+		       ContingencyTables.entropyOverColumns(matrix));
+    System.out.println("Gain ratio: " +
+		       ContingencyTables.gainRatio(matrix));
+    System.out.println("Negative log2 of multiple hypergeometric probability: " +
+		       ContingencyTables.log2MultipleHypergeometric(matrix));
+    System.out.println("Symmetrical uncertainty: " +
+		       ContingencyTables.symmetricalUncertainty(matrix));
+    System.out.println("Tau value: " +
+		       ContingencyTables.tauVal(matrix));
+    double[][] newMatrix = new double[3][3];
+    newMatrix[0][0] = 1; newMatrix[0][1] = 0; newMatrix[0][2] = 1;
+    newMatrix[1][0] = 0; newMatrix[1][1] = 0; newMatrix[1][2] = 0;
+    newMatrix[2][0] = 1; newMatrix[2][1] = 0; newMatrix[2][2] = 1;
+    System.out.println("Matrix with empty row and column: ");
+    for (int i = 0; i < newMatrix.length; i++) {
+      for (int j = 0; j < newMatrix[i].length; j++) {
+	System.out.print(newMatrix[i][j] + " ");
+      }
+      System.out.println();
+    }
+    System.out.println("Reduced matrix: ");
+    newMatrix = ContingencyTables.reduceMatrix(newMatrix);
+    for (int i = 0; i < newMatrix.length; i++) {
+      for (int j = 0; j < newMatrix[i].length; j++) {
+	System.out.print(newMatrix[i][j] + " ");
+      }
+      System.out.println();
+    }
+  }
+}
+
+
+
+
+
+
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Copyable.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Copyable.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Copyable.java	(revision 16571)
@@ -0,0 +1,41 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Copyable.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+/**
+ * Interface implemented by classes that can produce "shallow" copies
+ * of their objects. (As opposed to clone(), which is supposed to
+ * produce a "deep" copy.)
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public interface Copyable {
+
+  /**
+   * This method produces a shallow copy of an object.
+   * It does the same as the clone() method in Object, which also produces
+   * a shallow copy.
+   */
+  public Object copy();
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/FastVector.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/FastVector.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/FastVector.java	(revision 16571)
@@ -0,0 +1,432 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    FastVector.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+import java.util.*;
+import java.io.*;
+
+/**
+ * Implements a fast vector class without synchronized
+ * methods. Replaces java.util.Vector. (Synchronized methods tend to
+ * be slow.)
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$ */
+public class FastVector implements Copyable, Serializable {
+
+  /**
+   * Class for enumerating the vector's elements.
+   */
+  public class FastVectorEnumeration implements Enumeration {
+
+    /** The counter. */
+    private int m_Counter;
+
+    /** The vector. */
+    private FastVector m_Vector;
+
+    /** Special element. Skipped during enumeration. */
+    private int m_SpecialElement;
+
+    /**
+     * Constructs an enumeration.
+     *
+     * @param vector the vector which is to be enumerated
+     */
+    public FastVectorEnumeration(FastVector vector) {
+
+      m_Counter = 0;
+      m_Vector = vector;
+      m_SpecialElement = -1;
+    }
+
+    /**
+     * Constructs an enumeration with a special element.
+     * The special element is skipped during the enumeration.
+     *
+     * @param vector the vector which is to be enumerated
+     * @param special the index of the special element
+     */
+    public FastVectorEnumeration(FastVector vector, int special) {
+
+      m_Vector = vector;
+      m_SpecialElement = special;
+      if (special == 0) {
+	m_Counter = 1;
+      } else {
+	m_Counter = 0;
+      }
+    }
+
+
+    /**
+     * Tests if there are any more elements to enumerate.
+     *
+     * @return true if there are some elements left
+     */
+    public final boolean hasMoreElements() {
+
+      if (m_Counter < m_Vector.size()) {
+	return true;
+      }
+      return false;
+    }
+
+    /**
+     * Returns the next element.
+     *
+     * @return the next element to be enumerated
+     */
+    public final Object nextElement() {
+  
+      Object result = m_Vector.elementAt(m_Counter);
+
+      m_Counter++;
+      if (m_Counter == m_SpecialElement) {
+	m_Counter++;
+      }
+      return result;
+    }
+  }
+
+  /** The array of objects. */
+  private Object[] m_Objects;
+
+  /** The current size; */
+  private int m_Size;
+
+  /** The capacity increment */
+  private int m_CapacityIncrement;
+  
+  /** The capacity multiplier. */
+  private double m_CapacityMultiplier;
+
+  /**
+   * Constructs an empty vector with initial
+   * capacity zero.
+   */
+  public FastVector() {
+  
+    m_Objects = new Object[0];
+    m_Size = 0;
+    m_CapacityIncrement = 1;
+    m_CapacityMultiplier = 2;
+  }
+
+  /**
+   * Constructs a vector with the given capacity.
+   *
+   * @param capacity the vector's initial capacity
+   */
+  public FastVector(int capacity) {
+
+    m_Objects = new Object[capacity];
+    m_Size = 0;
+    m_CapacityIncrement = 1;
+    m_CapacityMultiplier = 2;
+  }
+
+  /**
+   * Constructs a vector with the given capacity, capacity 
+   * increment and capacity mulitplier.
+   *
+   * @param capacity the vector's initial capacity
+   */
+  public FastVector(int capacity, int capIncrement, 
+		    double capMultiplier) {
+
+    m_Objects = new Object[capacity];
+    m_Size = 0;
+    m_CapacityIncrement = capIncrement;
+    m_CapacityMultiplier = capMultiplier;
+  }
+
+  /**
+   * Adds an element to this vector. Increases its
+   * capacity if its not large enough.
+   *
+   * @param element the element to add
+   */
+  public final void addElement(Object element) {
+
+    Object[] newObjects;
+
+    if (m_Size == m_Objects.length) {
+      newObjects = new Object[(int)m_CapacityMultiplier *
+			     (m_Objects.length +
+			      m_CapacityIncrement)];
+      System.arraycopy(m_Objects, 0, newObjects, 0, m_Size);
+      m_Objects = newObjects;
+    }
+    m_Objects[m_Size] = element;
+    m_Size++;
+  }
+
+  /**
+   * Returns the capacity of the vector.
+   *
+   * @return the capacity of the vector
+   */
+  public final int capacity() {
+  
+    return m_Objects.length;
+  }
+
+  /**
+   * Produces a shallow copy of this vector.
+   *
+   * @return the new vector
+   */
+  public final Object copy() {
+
+    FastVector copy = new FastVector(m_Objects.length, 
+				     m_CapacityIncrement,
+				     m_CapacityMultiplier);
+    copy.m_Size = m_Size;
+    System.arraycopy(m_Objects, 0, copy.m_Objects, 0, m_Size);
+    return copy;
+  }
+
+  /**
+   * Clones the vector and shallow copies all its elements.
+   * The elements have to implement the Copyable interface.
+   * 
+   * @return the new vector
+   */
+  public final Object copyElements() {
+
+    FastVector copy = new FastVector(m_Objects.length, 
+				     m_CapacityIncrement,
+				     m_CapacityMultiplier);
+    copy.m_Size = m_Size;
+    for (int i = 0; i < m_Size; i++) {
+      copy.m_Objects[i] = ((Copyable)m_Objects[i]).copy();
+    }
+    return copy;
+  }
+
+  /**
+   * Returns the element at the given position.
+   *
+   * @param index the element's index
+   * @return the element with the given index
+   */
+  public final Object elementAt(int index) {
+
+    return m_Objects[index];
+  }
+
+  /**
+   * Returns an enumeration of this vector.
+   *
+   * @return an enumeration of this vector
+   */
+  public final Enumeration elements() {
+  
+    return new FastVectorEnumeration(this);
+  }
+
+  /**
+   * Returns an enumeration of this vector, skipping the
+   * element with the given index.
+   *
+   * @param index the element to skip
+   * @return an enumeration of this vector
+   */
+  public final Enumeration elements(int index) {
+  
+    return new FastVectorEnumeration(this, index);
+  }
+
+  /**
+   * Returns the first element of the vector.
+   *
+   * @return the first element of the vector
+   */
+  public final Object firstElement() {
+
+    return m_Objects[0];
+  }
+
+  /**
+   * Searches for the first occurence of the given argument, 
+   * testing for equality using the equals method. 
+   *
+   * @param element the element to be found
+   * @return the index of the first occurrence of the argument 
+   * in this vector; returns -1 if the object is not found
+   */
+  public final int indexOf(Object element) {
+
+    for (int i = 0; i < m_Size; i++) {
+      if (element.equals(m_Objects[i])) {
+	return i;
+      }
+    }
+    return -1;
+  }
+
+  /**
+   * Inserts an element at the given position.
+   *
+   * @param element the element to be inserted
+   * @param index the element's index
+   */
+  public final void insertElementAt(Object element, int index) {
+
+    Object[] newObjects;
+
+    if (m_Size < m_Objects.length) {
+      System.arraycopy(m_Objects, index, m_Objects, index + 1, 
+                       m_Size - index);
+      m_Objects[index] = element;
+    } else {
+      newObjects = new Object[(int)m_CapacityMultiplier *
+			     (m_Objects.length +
+			      m_CapacityIncrement)];
+      System.arraycopy(m_Objects, 0, newObjects, 0, index);
+      newObjects[index] = element;
+      System.arraycopy(m_Objects, index, newObjects, index + 1,
+		       m_Size - index);
+      m_Objects = newObjects;
+    }
+    m_Size++;
+  }
+
+  /**
+   * Returns the last element of the vector.
+   *
+   * @return the last element of the vector
+   */
+  public final Object lastElement() {
+
+    return m_Objects[m_Size - 1];
+  }
+
+  /**
+   * Deletes an element from this vector.
+   *
+   * @param index the index of the element to be deleted
+   */
+  public final void removeElementAt(int index) {
+
+    System.arraycopy(m_Objects, index + 1, m_Objects, index, 
+                     m_Size - index - 1);
+    m_Size--;
+  }
+
+  /**
+   * Removes all components from this vector and sets its 
+   * size to zero. 
+   */
+  public final void removeAllElements() {
+
+    m_Objects = new Object[m_Objects.length];
+    m_Size = 0;
+  }
+
+  /**
+   * Appends all elements of the supplied vector to this vector.
+   *
+   * @param toAppend the FastVector containing elements to append.
+   */
+  public final void appendElements(FastVector toAppend) {
+
+    setCapacity(size() + toAppend.size());
+    System.arraycopy(toAppend.m_Objects, 0, m_Objects, size(), toAppend.size());
+    m_Size = m_Objects.length;
+  }
+
+  /** 
+   * Returns all the elements of this vector as an array
+   *
+   * @param an array containing all the elements of this vector
+   */
+  public final Object [] toArray() {
+
+    Object [] newObjects = new Object[size()];
+    System.arraycopy(m_Objects, 0, newObjects, 0, size());
+    return newObjects;
+  }
+
+  /**
+   * Sets the vector's capacity to the given value.
+   *
+   * @param capacity the new capacity
+   */
+  public final void setCapacity(int capacity) {
+
+    Object[] newObjects = new Object[capacity];
+   
+    System.arraycopy(m_Objects, 0, newObjects, 0, Math.min(capacity, m_Size));
+    m_Objects = newObjects;
+    if (m_Objects.length < m_Size)
+      m_Size = m_Objects.length;
+  }
+
+  /**
+   * Sets the element at the given index.
+   *
+   * @param element the element to be put into the vector
+   * @param index the index at which the element is to be placed
+   */
+  public final void setElementAt(Object element, int index) {
+
+    m_Objects[index] = element;
+  }
+
+  /**
+   * Returns the vector's current size.
+   *
+   * @return the vector's current size
+   */
+  public final int size() {
+
+    return m_Size;
+  }
+
+  /**
+   * Swaps two elements in the vector.
+   *
+   * @param first index of the first element
+   * @param second index of the second element
+   */
+  public final void swap(int first, int second) {
+
+    Object help = m_Objects[first];
+
+    m_Objects[first] = m_Objects[second];
+    m_Objects[second] = help;
+  }
+
+  /**
+   * Sets the vector's capacity to its size.
+   */
+  public final void trimToSize() {
+
+    Object[] newObjects = new Object[m_Size];
+    
+    System.arraycopy(m_Objects, 0, newObjects, 0, m_Size);
+    m_Objects = newObjects;
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Instance.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Instance.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Instance.java	(revision 16571)
@@ -0,0 +1,1064 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Instance.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+import java.util.*;
+import java.io.*;
+
+/**
+ * Class for handling an instance. All values (numeric, nominal, or
+ * string) are internally stored as floating-point numbers. If an
+ * attribute is nominal (or a string), the stored value is the index
+ * of the corresponding nominal (or string) value in the attribute's
+ * definition. We have chosen this approach in favor of a more elegant
+ * object-oriented approach because it is much faster. <p>
+ *
+ * Typical usage (code from the main() method of this class): <p>
+ *
+ * <code>
+ * ... <br>
+ *      
+ * // Create empty instance with three attribute values <br>
+ * Instance inst = new Instance(3); <br><br>
+ *     
+ * // Set instance's values for the attributes "length", "weight", and "position"<br>
+ * inst.setValue(length, 5.3); <br>
+ * inst.setValue(weight, 300); <br>
+ * inst.setValue(position, "first"); <br><br>
+ *   
+ * // Set instance's dataset to be the dataset "race" <br>
+ * inst.setDataset(race); <br><br>
+ *   
+ * // Print the instance <br>
+ * System.out.println("The instance: " + inst); <br>
+ *
+ * ... <br>
+ * </code><p>
+ *
+ * All methods that change an instance are safe, ie. a change of an
+ * instance does not affect any other instances. All methods that
+ * change an instance's attribute values clone the attribute value
+ * vector before it is changed. If your application heavily modifies
+ * instance values, it may be faster to create a new instance from scratch.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$ 
+ */
+public class Instance implements Copyable, Serializable {
+  
+  /** Constant representing a missing value. */
+  protected final static double MISSING_VALUE = Double.NaN;
+
+  /** 
+   * The dataset the instance has access to.  Null if the instance
+   * doesn't have access to any dataset.  Only if an instance has
+   * access to a dataset, it knows about the actual attribute types.  
+   */
+  protected Instances m_Dataset;
+
+  /** The instance's attribute values. */
+  protected double[] m_AttValues;
+
+  /** The instance's weight. */
+  protected double m_Weight;
+
+  /**
+   * Constructor that copies the attribute values and the weight from
+   * the given instance. Reference to the dataset is set to null.
+   * (ie. the instance doesn't have access to information about the
+   * attribute types)
+   *
+   * @param instance the instance from which the attribute
+   * values and the weight are to be copied 
+   */
+  public Instance(Instance instance) {
+    
+    m_AttValues = instance.m_AttValues;
+    m_Weight = instance.m_Weight;
+    m_Dataset = null;
+  }
+
+  /**
+   * Constructor that inititalizes instance variable with given
+   * values. Reference to the dataset is set to null. (ie. the instance
+   * doesn't have access to information about the attribute types)
+   *
+   * @param weight the instance's weight
+   * @param attValues a vector of attribute values 
+   */
+  public Instance(double weight, double[] attValues){
+    
+    m_AttValues = attValues;
+    m_Weight = weight;
+    m_Dataset = null;
+  }
+
+  /**
+   * Constructor of an instance that sets weight to one, all values to
+   * be missing, and the reference to the dataset to null. (ie. the instance
+   * doesn't have access to information about the attribute types)
+   *
+   * @param numAttributes the size of the instance 
+   */
+  public Instance(int numAttributes) {
+    
+    m_AttValues = new double[numAttributes];
+    for (int i = 0; i < m_AttValues.length; i++) {
+      m_AttValues[i] = MISSING_VALUE;
+    }
+    m_Weight = 1;
+    m_Dataset = null;
+  }
+
+  /**
+   * Returns the attribute with the given index.
+   *
+   * @param index the attribute's index
+   * @return the attribute at the given position
+   * @exception UnassignedDatasetException if instance doesn't have access to a
+   * dataset
+   */ 
+  public Attribute attribute(int index) {
+   
+    if (m_Dataset == null) {
+      throw new UnassignedDatasetException("Instance doesn't have access to a dataset!");
+    }
+    return m_Dataset.attribute(index);
+  }
+
+  /**
+   * Returns the attribute with the given index. Does the same
+   * thing as attribute().
+   *
+   * @param indexOfIndex the index of the attribute's index 
+   * @return the attribute at the given position
+   * @exception UnassignedDatasetException if instance doesn't have access to a
+   * dataset
+   */ 
+  public Attribute attributeSparse(int indexOfIndex) {
+   
+    if (m_Dataset == null) {
+      throw new UnassignedDatasetException("Instance doesn't have access to a dataset!");
+    }
+    return m_Dataset.attribute(indexOfIndex);
+  }
+
+  /**
+   * Returns class attribute.
+   *
+   * @return the class attribute
+   * @exception UnassignedDatasetException if the class is not set or the
+   * instance doesn't have access to a dataset
+   */
+  public Attribute classAttribute() {
+
+    if (m_Dataset == null) {
+      throw new UnassignedDatasetException("Instance doesn't have access to a dataset!");
+    }
+    return m_Dataset.classAttribute();
+  }
+
+  /**
+   * Returns the class attribute's index.
+   *
+   * @return the class index as an integer 
+   * @exception UnassignedDatasetException if instance doesn't have access to a dataset 
+   */
+  public int classIndex() {
+    
+    if (m_Dataset == null) {
+      throw new UnassignedDatasetException("Instance doesn't have access to a dataset!");
+    }
+    return m_Dataset.classIndex();
+  }
+
+  /**
+   * Tests if an instance's class is missing.
+   *
+   * @return true if the instance's class is missing
+   * @exception UnassignedClassException if the class is not set or the instance doesn't
+   * have access to a dataset
+   */
+  public boolean classIsMissing() {
+
+    if (classIndex() < 0) {
+      throw new UnassignedClassException("Class is not set!");
+    }
+    return isMissing(classIndex());
+  }
+
+  /**
+   * Returns an instance's class value in internal format. (ie. as a
+   * floating-point number)
+   *
+   * @return the corresponding value as a double (If the 
+   * corresponding attribute is nominal (or a string) then it returns the 
+   * value's index as a double).
+   * @exception UnassignedClassException if the class is not set or the instance doesn't
+   * have access to a dataset 
+   */
+  public double classValue() {
+    
+    if (classIndex() < 0) {
+      throw new UnassignedClassException("Class is not set!");
+    }
+    return value(classIndex());
+  }
+
+  /**
+   * Produces a shallow copy of this instance. The copy has
+   * access to the same dataset. (if you want to make a copy
+   * that doesn't have access to the dataset, use 
+   * <code>new Instance(instance)</code>
+   *
+   * @return the shallow copy
+   */
+  public Object copy() {
+
+    Instance result = new Instance(this);
+    result.m_Dataset = m_Dataset;
+    return result;
+  }
+
+  /**
+   * Returns the dataset this instance has access to. (ie. obtains
+   * information about attribute types from) Null if the instance
+   * doesn't have access to a dataset.
+   *
+   * @return the dataset the instance has accesss to
+   */
+  public Instances dataset() {
+
+    return m_Dataset;
+  }
+
+  /**
+   * Deletes an attribute at the given position (0 to 
+   * numAttributes() - 1). Only succeeds if the instance does not
+   * have access to any dataset because otherwise inconsistencies
+   * could be introduced.
+   *
+   * @param pos the attribute's position
+   * @exception RuntimeException if the instance has access to a
+   * dataset 
+   */
+  public void deleteAttributeAt(int position) {
+
+    if (m_Dataset != null) {
+      throw new RuntimeException("Instance has access to a dataset!");
+    }
+    forceDeleteAttributeAt(position);
+  }
+
+  /**
+   * Returns an enumeration of all the attributes.
+   *
+   * @return enumeration of all the attributes
+   * @exception UnassignedDatasetException if the instance doesn't
+   * have access to a dataset 
+   */
+  public Enumeration enumerateAttributes() {
+
+    if (m_Dataset == null) {
+      throw new UnassignedDatasetException("Instance doesn't have access to a dataset!");
+    }
+    return m_Dataset.enumerateAttributes();
+  }
+
+  /**
+   * Tests if the headers of two instances are equivalent.
+   *
+   * @param instance another instance
+   * @return true if the header of the given instance is 
+   * equivalent to this instance's header
+   * @exception UnassignedDatasetException if instance doesn't have access to any
+   * dataset
+   */
+  public boolean equalHeaders(Instance inst) {
+
+    if (m_Dataset == null) {
+      throw new UnassignedDatasetException("Instance doesn't have access to a dataset!");
+    }
+    return m_Dataset.equalHeaders(inst.m_Dataset);
+  }
+
+  /**
+   * Returns the index of the attribute stored at the given position.
+   * Just returns the given value.
+   *
+   * @param position the position 
+   * @return the index of the attribute stored at the given position
+   */
+  public int index(int position) {
+
+    return position;
+  }
+
+  /**
+   * Inserts an attribute at the given position (0 to 
+   * numAttributes()). Only succeeds if the instance does not
+   * have access to any dataset because otherwise inconsistencies
+   * could be introduced.
+   *
+   * @param pos the attribute's position
+   * @exception RuntimeException if the instance has accesss to a
+   * dataset
+   * @exception IllegalArgumentException if the position is out of range
+   */
+  public void insertAttributeAt(int position) {
+
+    if (m_Dataset != null) {
+      throw new RuntimeException("Instance has accesss to a dataset!");
+    }
+    if ((position < 0) ||
+	(position > numAttributes())) {
+      throw new IllegalArgumentException("Can't insert attribute: index out "+
+                                         "of range");
+    }
+    forceInsertAttributeAt(position);
+  }
+
+  /**
+   * Tests if a specific value is "missing".
+   *
+   * @param attIndex the attribute's index
+   */
+  public boolean isMissing(int attIndex) {
+
+    if (Double.isNaN(m_AttValues[attIndex])) {
+      return true;
+    }
+    return false;
+  }
+
+  /**
+   * Tests if a specific value is "missing". Does
+   * the same thing as isMissing() if applied to an Instance.
+   *
+   * @param indexOfIndex the index of the attribute's index 
+   */
+  public boolean isMissingSparse(int indexOfIndex) {
+
+    if (Double.isNaN(m_AttValues[indexOfIndex])) {
+      return true;
+    }
+    return false;
+  }
+
+  /**
+   * Tests if a specific value is "missing".
+   * The given attribute has to belong to a dataset.
+   *
+   * @param att the attribute
+   */
+  public boolean isMissing(Attribute att) {
+
+    return isMissing(att.index());
+  }
+
+  /**
+   * Tests if the given value codes "missing".
+   *
+   * @param val the value to be tested
+   * @return true if val codes "missing"
+   */
+  public static boolean isMissingValue(double val) {
+
+    return Double.isNaN(val);
+  }
+
+  /**
+   * Merges this instance with the given instance and returns
+   * the result. Dataset is set to null.
+   *
+   * @param inst the instance to be merged with this one
+   * @return the merged instances
+   */
+  public Instance mergeInstance(Instance inst) {
+
+    int m = 0;
+    double [] newVals = new double[numAttributes() + inst.numAttributes()];
+    for (int j = 0; j < numAttributes(); j++, m++) {
+      newVals[m] = value(j);
+    }
+    for (int j = 0; j < inst.numAttributes(); j++, m++) {
+      newVals[m] = inst.value(j);
+    }
+    return new Instance(1.0, newVals);
+  }
+
+  /**
+   * Returns the double that codes "missing".
+   *
+   * @return the double that codes "missing"
+   */
+  public static double missingValue() {
+
+    return MISSING_VALUE;
+  }
+
+  /**
+   * Returns the number of attributes.
+   *
+   * @return the number of attributes as an integer
+   */
+  public int numAttributes() {
+
+    return m_AttValues.length;
+  }
+
+  /**
+   * Returns the number of class labels.
+   *
+   * @return the number of class labels as an integer if the 
+   * class attribute is nominal, 1 otherwise.
+   * @exception UnassignedDatasetException if instance doesn't have access to any
+   * dataset
+   */
+  public int numClasses() {
+    
+    if (m_Dataset == null) {
+      throw new UnassignedDatasetException("Instance doesn't have access to a dataset!");
+    }
+    return m_Dataset.numClasses();
+  }
+
+  /**
+   * Returns the number of values present. Always the same as numAttributes().
+   *
+   * @return the number of values
+   */
+  public int numValues() {
+
+    return m_AttValues.length;
+  }
+
+  /** 
+   * Replaces all missing values in the instance with the
+   * values contained in the given array. A deep copy of
+   * the vector of attribute values is performed before the
+   * values are replaced.
+   *
+   * @param array containing the means and modes
+   * @exception IllegalArgumentException if numbers of attributes are unequal
+   */
+  public void replaceMissingValues(double[] array) {
+	 
+    if ((array == null) || 
+	(array.length != m_AttValues.length)) {
+      throw new IllegalArgumentException("Unequal number of attributes!");
+    }
+    freshAttributeVector();
+    for (int i = 0; i < m_AttValues.length; i++) {
+      if (isMissing(i)) {
+	m_AttValues[i] = array[i];
+      }
+    }
+  }
+
+  /**
+   * Sets the class value of an instance to be "missing". A deep copy of
+   * the vector of attribute values is performed before the
+   * value is set to be missing.
+   *
+   * @exception UnassignedClassException if the class is not set
+   * @exception UnassignedDatasetException if the instance doesn't
+   * have access to a dataset
+   */
+  public void setClassMissing() {
+
+    if (classIndex() < 0) {
+      throw new UnassignedClassException("Class is not set!");
+    }
+    setMissing(classIndex());
+  }
+
+  /**
+   * Sets the class value of an instance to the given value (internal
+   * floating-point format).  A deep copy of the vector of attribute
+   * values is performed before the value is set.
+   *
+   * @param value the new attribute value (If the corresponding
+   * attribute is nominal (or a string) then this is the new value's
+   * index as a double).  
+   * @exception UnassignedClassException if the class is not set
+   * @exception UnaddignedDatasetException if the instance doesn't
+   * have access to a dataset 
+   */
+  public void setClassValue(double value) {
+
+    if (classIndex() < 0) {
+      throw new UnassignedClassException("Class is not set!");
+    }
+    setValue(classIndex(), value);
+  }
+
+  /**
+   * Sets the class value of an instance to the given value. A deep
+   * copy of the vector of attribute values is performed before the
+   * value is set.
+   *
+   * @param value the new class value (If the class
+   * is a string attribute and the value can't be found,
+   * the value is added to the attribute).
+   * @exception UnassignedClassException if the class is not set
+   * @exception UnassignedDatasetException if the dataset is not set
+   * @exception IllegalArgumentException if the attribute is not
+   * nominal or a string, or the value couldn't be found for a nominal
+   * attribute 
+   */
+  public final void setClassValue(String value) {
+
+    if (classIndex() < 0) {
+      throw new UnassignedClassException("Class is not set!");
+    }
+    setValue(classIndex(), value);
+  }
+
+  /**
+   * Sets the reference to the dataset. Does not check if the instance
+   * is compatible with the dataset. Note: the dataset does not know
+   * about this instance. If the structure of the dataset's header
+   * gets changed, this instance will not be adjusted automatically.
+   *
+   * @param instances the reference to the dataset 
+   */
+  public final void setDataset(Instances instances) {
+    
+    m_Dataset = instances;
+  }
+
+  /**
+   * Sets a specific value to be "missing". Performs a deep copy
+   * of the vector of attribute values before the value is set to
+   * be missing.
+   *
+   * @param attIndex the attribute's index
+   */
+  public final void setMissing(int attIndex) {
+
+    setValue(attIndex, MISSING_VALUE);
+  }
+
+  /**
+   * Sets a specific value to be "missing". Performs a deep copy
+   * of the vector of attribute values before the value is set to
+   * be missing. The given attribute has to belong to a dataset.
+   *
+   * @param att the attribute
+   */
+  public final void setMissing(Attribute att) {
+
+    setMissing(att.index());
+  }
+
+  /**
+   * Sets a specific value in the instance to the given value 
+   * (internal floating-point format). Performs a deep copy
+   * of the vector of attribute values before the value is set.
+   *
+   * @param attIndex the attribute's index 
+   * @param value the new attribute value (If the corresponding
+   * attribute is nominal (or a string) then this is the new value's
+   * index as a double).  
+   */
+  public void setValue(int attIndex, double value) {
+    
+    freshAttributeVector();
+    m_AttValues[attIndex] = value;
+  }
+
+  /**
+   * Sets a specific value in the instance to the given value 
+   * (internal floating-point format). Performs a deep copy
+   * of the vector of attribute values before the value is set.
+   * Does exactly the same thing as setValue().
+   *
+   * @param indexOfIndex the index of the attribute's index 
+   * @param value the new attribute value (If the corresponding
+   * attribute is nominal (or a string) then this is the new value's
+   * index as a double).  
+   */
+  public void setValueSparse(int indexOfIndex, double value) {
+    
+    freshAttributeVector();
+    m_AttValues[indexOfIndex] = value;
+  }
+
+  /**
+   * Sets a value of a nominal or string attribute to the given
+   * value. Performs a deep copy of the vector of attribute values
+   * before the value is set.
+   *
+   * @param attIndex the attribute's index
+   * @param value the new attribute value (If the attribute
+   * is a string attribute and the value can't be found,
+   * the value is added to the attribute).
+   * @exception UnassignedDatasetException if the dataset is not set
+   * @exception IllegalArgumentException if the selected
+   * attribute is not nominal or a string, or the supplied value couldn't 
+   * be found for a nominal attribute 
+   */
+  public final void setValue(int attIndex, String value) {
+    
+    int valIndex;
+
+    if (m_Dataset == null) {
+      throw new UnassignedDatasetException("Instance doesn't have access to a dataset!");
+    }
+    if (!attribute(attIndex).isNominal() &&
+	!attribute(attIndex).isString()) {
+      throw new IllegalArgumentException("Attribute neither nominal nor string!");
+    }
+    valIndex = attribute(attIndex).indexOfValue(value);
+    if (valIndex == -1) {
+      if (attribute(attIndex).isNominal()) {
+	throw new IllegalArgumentException("Value not defined for given nominal attribute!");
+      } else {
+	attribute(attIndex).forceAddValue(value);
+	valIndex = attribute(attIndex).indexOfValue(value);
+      }
+    }
+    setValue(attIndex, (double)valIndex); 
+  }
+
+  /**
+   * Sets a specific value in the instance to the given value
+   * (internal floating-point format). Performs a deep copy of the
+   * vector of attribute values before the value is set, so if you are
+   * planning on calling setValue many times it may be faster to
+   * create a new instance using toDoubleArray.  The given attribute
+   * has to belong to a dataset.
+   *
+   * @param att the attribute 
+   * @param value the new attribute value (If the corresponding
+   * attribute is nominal (or a string) then this is the new value's
+   * index as a double).  
+   */
+  public final void setValue(Attribute att, double value) {
+
+    setValue(att.index(), value);
+  }
+
+  /**
+   * Sets a value of an nominal or string attribute to the given
+   * value. Performs a deep copy of the vector of attribute values
+   * before the value is set, so if you are planning on calling setValue many
+   * times it may be faster to create a new instance using toDoubleArray.
+   * The given attribute has to belong to a dataset.
+   *
+   * @param att the attribute
+   * @param value the new attribute value (If the attribute
+   * is a string attribute and the value can't be found,
+   * the value is added to the attribute).
+   * @exception IllegalArgumentException if the the attribute is not
+   * nominal or a string, or the value couldn't be found for a nominal
+   * attribute 
+   */
+  public final void setValue(Attribute att, String value) {
+
+    if (!att.isNominal() &&
+	!att.isString()) {
+      throw new IllegalArgumentException("Attribute neither nominal nor string!");
+    }
+    int valIndex = att.indexOfValue(value);
+    if (valIndex == -1) {
+      if (att.isNominal()) {
+	throw new IllegalArgumentException("Value not defined for given nominal attribute!");
+      } else {
+	att.forceAddValue(value);
+	valIndex = att.indexOfValue(value);
+      }
+    }
+    setValue(att.index(), (double)valIndex);
+  }
+
+  /**
+   * Sets the weight of an instance.
+   *
+   * @param weight the weight
+   */
+  public final void setWeight(double weight) {
+
+    m_Weight = weight;
+  }
+
+  /** 
+   * Returns the value of a nominal (or string) attribute
+   * for the instance.
+   *
+   * @param attIndex the attribute's index
+   * @return the value as a string
+   * @exception IllegalArgumentException if the attribute is not a nominal
+   * (or string) attribute.
+   * @exception UnassignedDatasetException if the instance doesn't belong
+   * to a dataset.
+   */
+  public final String stringValue(int attIndex) {
+
+    if (m_Dataset == null) {
+      throw new UnassignedDatasetException("Instance doesn't have access to a dataset!");
+    } 
+    if (!m_Dataset.attribute(attIndex).isNominal() &&
+	!m_Dataset.attribute(attIndex).isString()) {
+      throw new IllegalArgumentException("Attribute neither nominal nor string!");
+    }
+    return m_Dataset.attribute(attIndex).
+      value((int) value(attIndex));
+  }
+
+  /** 
+   * Returns the value of a nominal (or string) attribute
+   * for the instance.
+   *
+   * @param att the attribute
+   * @return the value as a string
+   * @exception IllegalArgumentException if the attribute is not a nominal
+   * (or string) attribute.
+   * @exception UnassignedDatasetException if the instance doesn't belong
+   * to a dataset.
+   */
+  public final String stringValue(Attribute att) {
+
+    return stringValue(att.index());
+  }
+
+  /**
+   * Returns the values of each attribute as an array of doubles.
+   *
+   * @return an array containing all the instance attribute values
+   */
+  public double[] toDoubleArray() {
+
+    double[] newValues = new double[m_AttValues.length];
+    System.arraycopy(m_AttValues, 0, newValues, 0, 
+		     m_AttValues.length);
+    return newValues;
+  }
+
+  /**
+   * Returns the description of one instance. If the instance
+   * doesn't have access to a dataset, it returns the internal
+   * floating-point values. Quotes string
+   * values that contain whitespace characters.
+   *
+   * @return the instance's description as a string
+   */
+  public String toString() {
+
+    StringBuffer text = new StringBuffer();
+    
+    for (int i = 0; i < m_AttValues.length; i++) {
+      if (i > 0) text.append(",");
+      text.append(toString(i));
+    }
+
+    return text.toString();
+  }
+
+  /**
+   * Returns the description of one value of the instance as a 
+   * string. If the instance doesn't have access to a dataset, it 
+   * returns the internal floating-point value. Quotes string
+   * values that contain whitespace characters, or if they
+   * are a question mark.
+   *
+   * @param attIndex the attribute's index
+   * @return the value's description as a string
+   */
+  public final String toString(int attIndex) {
+
+   StringBuffer text = new StringBuffer();
+   
+   if (isMissing(attIndex)) {
+     text.append("?");
+   } else {
+     if (m_Dataset == null) {
+       text.append(Utils.doubleToString(m_AttValues[attIndex],6));
+     } else {
+       if (m_Dataset.attribute(attIndex).isNominal() || 
+	   m_Dataset.attribute(attIndex).isString()) {
+         text.append(Utils.quote(stringValue(attIndex)));
+       } else {
+	 text.append(Utils.doubleToString(value(attIndex),6));
+       }
+     }
+   }
+   return text.toString();
+  }
+
+  /**
+   * Returns the description of one value of the instance as a 
+   * string. If the instance doesn't have access to a dataset it 
+   * returns the internal floating-point value. Quotes string
+   * values that contain whitespace characters, or if they
+   * are a question mark.
+   * The given attribute has to belong to a dataset.
+   *
+   * @param att the attribute
+   * @return the value's description as a string
+   */
+  public final String toString(Attribute att) {
+   
+   return toString(att.index());
+  }
+
+  /**
+   * Returns an instance's attribute value in internal format.
+   *
+   * @param attIndex the attribute's index
+   * @return the specified value as a double (If the corresponding
+   * attribute is nominal (or a string) then it returns the value's index as a 
+   * double).
+   */
+  public double value(int attIndex) {
+
+    return m_AttValues[attIndex];
+  }
+
+  /**
+   * Returns an instance's attribute value in internal format.
+   * Does exactly the same thing as value() if applied to an Instance.
+   *
+   * @param indexOfIndex the index of the attribute's index
+   * @return the specified value as a double (If the corresponding
+   * attribute is nominal (or a string) then it returns the value's index as a 
+   * double).
+   */
+  public double valueSparse(int indexOfIndex) {
+
+    return m_AttValues[indexOfIndex];
+  }  
+
+  /**
+   * Returns an instance's attribute value in internal format.
+   * The given attribute has to belong to a dataset.
+   *
+   * @param att the attribute
+   * @return the specified value as a double (If the corresponding
+   * attribute is nominal (or a string) then it returns the value's index as a
+   * double).
+   */
+  public double value(Attribute att) {
+
+    return value(att.index());
+  }
+
+  /**
+   * Returns the instance's weight.
+   *
+   * @return the instance's weight as a double
+   */
+  public final double weight() {
+
+    return m_Weight;
+  }
+
+  /**
+   * Deletes an attribute at the given position (0 to 
+   * numAttributes() - 1).
+   *
+   * @param pos the attribute's position
+   */
+
+  void forceDeleteAttributeAt(int position) {
+
+    double[] newValues = new double[m_AttValues.length - 1];
+
+    System.arraycopy(m_AttValues, 0, newValues, 0, position);
+    if (position < m_AttValues.length - 1) {
+      System.arraycopy(m_AttValues, position + 1, 
+		       newValues, position, 
+		       m_AttValues.length - (position + 1));
+    }
+    m_AttValues = newValues;
+  }
+
+  /**
+   * Inserts an attribute at the given position
+   * (0 to numAttributes()) and sets its value to be missing. 
+   *
+   * @param pos the attribute's position
+   */
+  void forceInsertAttributeAt(int position)  {
+
+    double[] newValues = new double[m_AttValues.length + 1];
+
+    System.arraycopy(m_AttValues, 0, newValues, 0, position);
+    newValues[position] = MISSING_VALUE;
+    System.arraycopy(m_AttValues, position, newValues, 
+		     position + 1, m_AttValues.length - position);
+    m_AttValues = newValues;
+  }
+
+  /**
+   * Private constructor for subclasses. Does nothing.
+   */
+  protected Instance() {
+  }
+
+  /**
+   * Clones the attribute vector of the instance and
+   * overwrites it with the clone.
+   */
+  private void freshAttributeVector() {
+
+    m_AttValues = toDoubleArray();
+  }
+
+  /**
+   * Main method for testing this class.
+   */
+  public static void main(String[] options) {
+
+    try {
+
+      // Create numeric attributes "length" and "weight"
+      Attribute length = new Attribute("length");
+      Attribute weight = new Attribute("weight");
+      
+      // Create vector to hold nominal values "first", "second", "third" 
+      FastVector my_nominal_values = new FastVector(3); 
+      my_nominal_values.addElement("first"); 
+      my_nominal_values.addElement("second"); 
+      my_nominal_values.addElement("third"); 
+      
+      // Create nominal attribute "position" 
+      Attribute position = new Attribute("position", my_nominal_values);
+      
+      // Create vector of the above attributes 
+      FastVector attributes = new FastVector(3);
+      attributes.addElement(length);
+      attributes.addElement(weight);
+      attributes.addElement(position);
+      
+      // Create the empty dataset "race" with above attributes
+      Instances race = new Instances("race", attributes, 0);
+      
+      // Make position the class attribute
+      race.setClassIndex(position.index());
+      
+      // Create empty instance with three attribute values
+      Instance inst = new Instance(3);
+      
+      // Set instance's values for the attributes "length", "weight", and "position"
+      inst.setValue(length, 5.3);
+      inst.setValue(weight, 300);
+      inst.setValue(position, "first");
+      
+      // Set instance's dataset to be the dataset "race"
+      inst.setDataset(race);
+      
+      // Print the instance
+      System.out.println("The instance: " + inst);
+      
+      // Print the first attribute
+      System.out.println("First attribute: " + inst.attribute(0));
+      
+      // Print the class attribute
+      System.out.println("Class attribute: " + inst.classAttribute());
+      
+      // Print the class index
+      System.out.println("Class index: " + inst.classIndex());
+      
+      // Say if class is missing
+      System.out.println("Class is missing: " + inst.classIsMissing());
+      
+      // Print the instance's class value in internal format
+      System.out.println("Class value (internal format): " + inst.classValue());
+      
+      // Print a shallow copy of this instance
+      Instance copy = (Instance) inst.copy();
+      System.out.println("Shallow copy: " + copy);
+      
+      // Set dataset for shallow copy
+      copy.setDataset(inst.dataset());
+      System.out.println("Shallow copy with dataset set: " + copy);
+      
+      // Unset dataset for copy, delete first attribute, and insert it again
+      copy.setDataset(null);
+      copy.deleteAttributeAt(0);
+      copy.insertAttributeAt(0);
+      copy.setDataset(inst.dataset());
+      System.out.println("Copy with first attribute deleted and inserted: " + copy); 
+      
+      // Enumerate attributes (leaving out the class attribute)
+      System.out.println("Enumerating attributes (leaving out class):");
+      Enumeration enum = inst.enumerateAttributes();
+      while (enum.hasMoreElements()) {
+	Attribute att = (Attribute) enum.nextElement();
+	System.out.println(att);
+      }
+      
+      // Headers are equivalent?
+      System.out.println("Header of original and copy equivalent: " +
+			 inst.equalHeaders(copy));
+
+      // Test for missing values
+      System.out.println("Length of copy missing: " + copy.isMissing(length));
+      System.out.println("Weight of copy missing: " + copy.isMissing(weight.index()));
+      System.out.println("Length of copy missing: " + 
+			 Instance.isMissingValue(copy.value(length)));
+      System.out.println("Missing value coded as: " + Instance.missingValue());
+
+      // Prints number of attributes and classes
+      System.out.println("Number of attributes: " + copy.numAttributes());
+      System.out.println("Number of classes: " + copy.numClasses());
+
+      // Replace missing values
+      double[] meansAndModes = {2, 3, 0};
+      copy.replaceMissingValues(meansAndModes);
+      System.out.println("Copy with missing value replaced: " + copy);
+
+      // Setting and getting values and weights
+      copy.setClassMissing();
+      System.out.println("Copy with missing class: " + copy);
+      copy.setClassValue(0);
+      System.out.println("Copy with class value set to first value: " + copy);
+      copy.setClassValue("third");
+      System.out.println("Copy with class value set to \"third\": " + copy);
+      copy.setMissing(1);
+      System.out.println("Copy with second attribute set to be missing: " + copy);
+      copy.setMissing(length);
+      System.out.println("Copy with length set to be missing: " + copy);
+      copy.setValue(0, 0);
+      System.out.println("Copy with first attribute set to 0: " + copy);
+      copy.setValue(weight, 1);
+      System.out.println("Copy with weight attribute set to 1: " + copy);
+      copy.setValue(position, "second");
+      System.out.println("Copy with position set to \"second\": " + copy);
+      copy.setValue(2, "first");
+      System.out.println("Copy with last attribute set to \"first\": " + copy);
+      System.out.println("Current weight of instance copy: " + copy.weight());
+      copy.setWeight(2);
+      System.out.println("Current weight of instance copy (set to 2): " + copy.weight());
+      System.out.println("Last value of copy: " + copy.toString(2));
+      System.out.println("Value of position for copy: " + copy.toString(position));
+      System.out.println("Last value of copy (internal format): " + copy.value(2));
+      System.out.println("Value of position for copy (internal format): " + 
+			 copy.value(position));
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Instances.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Instances.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Instances.java	(revision 16571)
@@ -0,0 +1,2150 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Instances.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Class for handling an ordered set of weighted instances. <p>
+ *
+ * Typical usage (code from the main() method of this class): <p>
+ *
+ * <code>
+ * ... <br>
+ * 
+ * // Read all the instances in the file <br>
+ * reader = new FileReader(filename); <br>
+ * instances = new Instances(reader); <br><br>
+ *
+ * // Make the last attribute be the class <br>
+ * instances.setClassIndex(instances.numAttributes() - 1); <br><br>
+ * 
+ * // Print header and instances. <br>
+ * System.out.println("\nDataset:\n"); <br> 
+ * System.out.println(instances); <br><br>
+ *
+ * ... <br>
+ * </code><p>
+ *
+ * All methods that change a set of instances are safe, ie. a change
+ * of a set of instances does not affect any other sets of
+ * instances. All methods that change a datasets's attribute
+ * information clone the dataset before it is changed.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @author Len Trigg (trigg@cs.waikato.ac.nz)
+ * @version $Revision$ 
+ */
+public class Instances implements Serializable {
+ 
+  /** The filename extension that should be used for arff files */
+  public static String FILE_EXTENSION = ".arff";
+
+  /** The dataset's name. */
+  protected String m_RelationName;         
+
+  /** The attribute information. */
+  protected FastVector m_Attributes;
+
+  /** The instances. */
+  protected FastVector m_Instances;
+
+  /** The class attribute's index */
+  protected int m_ClassIndex;
+
+  /** Buffer of values for sparse instance */
+  protected double[] m_ValueBuffer;
+
+  /** Buffer of indices for sparse instance */
+  protected int[] m_IndicesBuffer;
+
+  /**
+   * Reads an ARFF file from a reader, and assigns a weight of
+   * one to each instance. Lets the index of the class 
+   * attribute be undefined (negative).
+   *
+   * @param reader the reader
+   * @exception IOException if the ARFF file is not read 
+   * successfully
+   */
+  public Instances(Reader reader) throws IOException {
+
+    StreamTokenizer tokenizer;
+
+    tokenizer = new StreamTokenizer(reader);
+    initTokenizer(tokenizer);
+    readHeader(tokenizer);
+    m_ClassIndex = -1;
+    m_Instances = new FastVector(1000);
+    while (getInstance(tokenizer, true)) {};
+    compactify();
+  }
+ 
+  /**
+   * Reads the header of an ARFF file from a reader and 
+   * reserves space for the given number of instances. Lets
+   * the class index be undefined (negative).
+   *
+   * @param reader the reader
+   * @param capacity the capacity
+   * @exception IllegalArgumentException if the header is not read successfully
+   * or the capacity is negative.
+   * @exception IOException if there is a problem with the reader.
+   */
+   public Instances(Reader reader, int capacity) throws IOException {
+
+    StreamTokenizer tokenizer;
+
+    if (capacity < 0) {
+      throw new IllegalArgumentException("Capacity has to be positive!");
+    }
+    tokenizer = new StreamTokenizer(reader); 
+    initTokenizer(tokenizer);
+    readHeader(tokenizer);
+    m_ClassIndex = -1;
+    m_Instances = new FastVector(capacity);
+  }
+
+  /**
+   * Constructor copying all instances and references to
+   * the header information from the given set of instances.
+   *
+   * @param instances the set to be copied
+   */
+  public Instances(Instances dataset) {
+
+    this(dataset, dataset.numInstances());
+
+    dataset.copyInstances(0, this, dataset.numInstances());
+  }
+
+  /**
+   * Constructor creating an empty set of instances. Copies references
+   * to the header information from the given set of instances. Sets
+   * the capacity of the set of instances to 0 if its negative.
+   *
+   * @param instances the instances from which the header 
+   * information is to be taken
+   * @param capacity the capacity of the new dataset 
+   */
+  public Instances(Instances dataset, int capacity) {
+    
+    if (capacity < 0) {
+      capacity = 0;
+    }
+    
+    // Strings only have to be "shallow" copied because
+    // they can't be modified.
+    m_ClassIndex = dataset.m_ClassIndex;
+    m_RelationName = dataset.m_RelationName;
+    m_Attributes = dataset.m_Attributes;
+    m_Instances = new FastVector(capacity);
+  }
+
+  /**
+   * Creates a new set of instances by copying a 
+   * subset of another set.
+   *
+   * @param source the set of instances from which a subset 
+   * is to be created
+   * @param first the index of the first instance to be copied
+   * @param toCopy the number of instances to be copied
+   * @exception IllegalArgumentException if first and toCopy are out of range
+   */
+  public Instances(Instances source, int first, int toCopy) {
+    
+    this(source, toCopy);
+
+    if ((first < 0) || ((first + toCopy) > source.numInstances())) {
+      throw new IllegalArgumentException("Parameters first and/or toCopy out "+
+                                         "of range");
+    }
+    source.copyInstances(first, this, toCopy);
+  }
+
+  /**
+   * Creates an empty set of instances. Uses the given
+   * attribute information. Sets the capacity of the set of 
+   * instances to 0 if its negative. Given attribute information
+   * must not be changed after this constructor has been used.
+   *
+   * @param name the name of the relation
+   * @param attInfo the attribute information
+   * @param capacity the capacity of the set
+   */
+  public Instances(String name, FastVector attInfo, int capacity) {
+
+    m_RelationName = name;
+    m_ClassIndex = -1;
+    m_Attributes = attInfo;
+    for (int i = 0; i < numAttributes(); i++) {
+      attribute(i).setIndex(i);
+    }
+    m_Instances = new FastVector(capacity);
+  }
+ 
+  /**
+   * Create a copy of the structure, but "cleanse" string types (i.e.
+   * doesn't contain references to the strings seen in the past).
+   *
+   * @return a copy of the instance structure.
+   */
+  public Instances stringFreeStructure() {
+
+    FastVector atts = (FastVector)m_Attributes.copy();
+    for (int i = 0 ; i < atts.size(); i++) {
+      Attribute att = (Attribute)atts.elementAt(i);
+      if (att.type() == Attribute.STRING) {
+        atts.setElementAt(new Attribute(att.name(), null), i);
+      }
+    }
+    Instances result = new Instances(relationName(), atts, 0);
+    result.m_ClassIndex = m_ClassIndex;
+    return result;
+  }
+
+  /**
+   * Adds one instance to the end of the set. 
+   * Shallow copies instance before it is added. Increases the
+   * size of the dataset if it is not large enough. Does not
+   * check if the instance is compatible with the dataset.
+   *
+   * @param instance the instance to be added
+   */
+  public final void add(Instance instance) {
+
+    Instance newInstance = (Instance)instance.copy();
+
+    newInstance.setDataset(this);
+    m_Instances.addElement(newInstance);
+  }
+
+  /**
+   * Returns an attribute.
+   *
+   * @param index the attribute's index
+   * @return the attribute at the given position
+   */ 
+  public final Attribute attribute(int index) {
+    
+    return (Attribute) m_Attributes.elementAt(index);
+  }
+
+  /**
+   * Returns an attribute given its name. If there is more than
+   * one attribute with the same name, it returns the first one.
+   * Returns null if the attribute can't be found.
+   *
+   * @param name the attribute's name
+   * @return the attribute with the given name, null if the
+   * attribute can't be found
+   */ 
+  public final Attribute attribute(String name) {
+    
+    for (int i = 0; i < numAttributes(); i++) {
+      if (attribute(i).name().equals(name)) {
+	return attribute(i);
+      }
+    }
+    return null;
+  }
+
+  /**
+   * Checks for string attributes in the dataset
+   *
+   * @return true if string attributes are present, false otherwise
+   */
+  public boolean checkForStringAttributes() {
+
+    int i = 0;
+   
+    while (i < m_Attributes.size()) {
+      if (attribute(i++).isString()) {
+	return true;
+      }
+    }
+    return false;
+  }
+
+  /**
+   * Checks if the given instance is compatible
+   * with this dataset. Only looks at the size of
+   * the instance and the ranges of the values for 
+   * nominal and string attributes.
+   *
+   * @return true if the instance is compatible with the dataset 
+   */
+  public final boolean checkInstance(Instance instance) {
+
+    if (instance.numAttributes() != numAttributes()) {
+      return false;
+    }
+    for (int i = 0; i < numAttributes(); i++) {
+      if (instance.isMissing(i)) {
+	continue;
+      } else if (attribute(i).isNominal() ||
+		 attribute(i).isString()) {
+	if (!(Utils.eq(instance.value(i),
+		       (double)(int)instance.value(i)))) {
+	  return false;
+	} else if (Utils.sm(instance.value(i), 0) ||
+		   Utils.gr(instance.value(i),
+			    attribute(i).numValues())) {
+	  return false;
+	}
+      }
+    }
+    return true;
+  }
+	
+  /**
+   * Returns the class attribute.
+   *
+   * @return the class attribute
+   * @exception UnassignedClassException if the class is not set
+   */
+  public final Attribute classAttribute() {
+
+    if (m_ClassIndex < 0) {
+      throw new UnassignedClassException("Class index is negative (not set)!");
+    }
+    return attribute(m_ClassIndex);
+  }
+
+  /**
+   * Returns the class attribute's index. Returns negative number
+   * if it's undefined.
+   *
+   * @return the class index as an integer
+   */
+  public final int classIndex() {
+    
+    return m_ClassIndex;
+  }
+ 
+  /**
+   * Compactifies the set of instances. Decreases the capacity of
+   * the set so that it matches the number of instances in the set.
+   */
+  public final void compactify() {
+
+    m_Instances.trimToSize();
+  }
+
+  /**
+   * Removes all instances from the set.
+   */
+  public final void delete() {
+    
+    m_Instances = new FastVector();
+  }
+
+  /**
+   * Removes an instance at the given position from the set.
+   *
+   * @param index the instance's position
+   */
+  public final void delete(int index) {
+    
+    m_Instances.removeElementAt(index);
+  }
+
+  /**
+   * Deletes an attribute at the given position 
+   * (0 to numAttributes() - 1). A deep copy of the attribute
+   * information is performed before the attribute is deleted.
+   *
+   * @param pos the attribute's position
+   * @exception IllegalArgumentException if the given index is out of range or the
+   * class attribute is being deleted
+   */
+  public void deleteAttributeAt(int position) {
+	 
+    if ((position < 0) || (position >= m_Attributes.size())) {
+      throw new IllegalArgumentException("Index out of range");
+    }
+    if (position == m_ClassIndex) {
+      throw new IllegalArgumentException("Can't delete class attribute");
+    }
+    freshAttributeInfo();
+    if (m_ClassIndex > position) {
+      m_ClassIndex--;
+    }
+    m_Attributes.removeElementAt(position);
+    for (int i = position; i < m_Attributes.size(); i++) {
+      Attribute current = (Attribute)m_Attributes.elementAt(i);
+      current.setIndex(current.index() - 1);
+    }
+    for (int i = 0; i < numInstances(); i++) {
+      instance(i).forceDeleteAttributeAt(position); 
+    }
+  }
+
+  /**
+   * Deletes all string attributes in the dataset. A deep copy of the attribute
+   * information is performed before an attribute is deleted.
+   *
+   * @exception IllegalArgumentException if string attribute couldn't be 
+   * successfully deleted (probably because it is the class attribute).
+   */
+  public void deleteStringAttributes() {
+
+    int i = 0;
+    while (i < m_Attributes.size()) {
+      if (attribute(i).isString()) {
+	deleteAttributeAt(i);
+      } else {
+	i++;
+      }
+    }
+  }
+
+  /**
+   * Removes all instances with missing values for a particular
+   * attribute from the dataset.
+   *
+   * @param attIndex the attribute's index
+   */
+  public final void deleteWithMissing(int attIndex) {
+
+    FastVector newInstances = new FastVector(numInstances());
+
+    for (int i = 0; i < numInstances(); i++) {
+      if (!instance(i).isMissing(attIndex)) {
+	newInstances.addElement(instance(i));
+      }
+    }
+    m_Instances = newInstances;
+  }
+
+  /**
+   * Removes all instances with missing values for a particular
+   * attribute from the dataset.
+   *
+   * @param att the attribute
+   */
+  public final void deleteWithMissing(Attribute att) {
+
+    deleteWithMissing(att.index());
+  }
+
+  /**
+   * Removes all instances with a missing class value
+   * from the dataset.
+   *
+   * @exception UnassignedClassException if class is not set
+   */
+  public final void deleteWithMissingClass() {
+
+    if (m_ClassIndex < 0) {
+      throw new UnassignedClassException("Class index is negative (not set)!");
+    }
+    deleteWithMissing(m_ClassIndex);
+  }
+
+  /**
+   * Returns an enumeration of all the attributes.
+   *
+   * @return enumeration of all the attributes.
+   */
+  public Enumeration enumerateAttributes() {
+
+    return m_Attributes.elements(m_ClassIndex);
+  }
+
+  /**
+   * Returns an enumeration of all instances in the dataset.
+   *
+   * @return enumeration of all instances in the dataset
+   */
+  public final Enumeration enumerateInstances() {
+
+    return m_Instances.elements();
+  }
+
+  /**
+   * Checks if two headers are equivalent.
+   *
+   * @param dataset another dataset
+   * @return true if the header of the given dataset is equivalent 
+   * to this header
+   */
+  public final boolean equalHeaders(Instances dataset){
+
+    // Check class and all attributes
+    if (m_ClassIndex != dataset.m_ClassIndex) {
+      return false;
+    }
+    if (m_Attributes.size() != dataset.m_Attributes.size()) {
+      return false;
+    }
+    for (int i = 0; i < m_Attributes.size(); i++) {
+      if (!(attribute(i).equals(dataset.attribute(i)))) {
+	return false;
+      }
+    }
+    return true;
+  }
+ 
+  /**
+   * Returns the first instance in the set.
+   *
+   * @return the first instance in the set
+   */
+  public final Instance firstInstance() {
+    
+    return (Instance)m_Instances.firstElement();
+  }
+ 
+  /**
+   * Inserts an attribute at the given position (0 to 
+   * numAttributes()) and sets all values to be missing.
+   * Shallow copies the attribute before it is inserted, and performs
+   * a deep copy of the existing attribute information.
+   *
+   * @param att the attribute to be inserted
+   * @param pos the attribute's position
+   * @exception IllegalArgumentException if the given index is out of range
+   */
+  public void insertAttributeAt(Attribute att, int position) {
+	 
+    if ((position < 0) ||
+	(position > m_Attributes.size())) {
+      throw new IllegalArgumentException("Index out of range");
+    }
+    att = (Attribute)att.copy();
+    freshAttributeInfo();
+    att.setIndex(position);
+    m_Attributes.insertElementAt(att, position);
+    for (int i = position + 1; i < m_Attributes.size(); i++) {
+      Attribute current = (Attribute)m_Attributes.elementAt(i);
+      current.setIndex(current.index() + 1);
+    }
+    for (int i = 0; i < numInstances(); i++) {
+      instance(i).forceInsertAttributeAt(position);
+    }
+    if (m_ClassIndex >= position) {
+      m_ClassIndex++;
+    }
+  }
+
+  /**
+   * Returns the instance at the given position.
+   *
+   * @param index the instance's index
+   * @return the instance at the given position
+   */
+  public final Instance instance(int index) {
+
+    return (Instance)m_Instances.elementAt(index);
+  }
+
+  /**
+   * Returns the last instance in the set.
+   *
+   * @return the last instance in the set
+   */
+  public final Instance lastInstance() {
+    
+    return (Instance)m_Instances.lastElement();
+  }
+
+  /**
+   * Returns the mean (mode) for a numeric (nominal) attribute as
+   * a floating-point value. Returns 0 if the attribute is neither nominal nor 
+   * numeric. If all values are missing it returns zero.
+   *
+   * @param attIndex the attribute's index
+   * @return the mean or the mode
+   */
+  public final double meanOrMode(int attIndex) {
+
+    double result, found;
+    int [] counts;
+
+    if (attribute(attIndex).isNumeric()) {
+      result = found = 0;
+      for (int j = 0; j < numInstances(); j++) {
+	if (!instance(j).isMissing(attIndex)) {
+	  found += instance(j).weight();
+	  result += instance(j).weight()*instance(j).value(attIndex);
+	}
+      }
+      if (Utils.eq(found, 0)) {
+	return 0;
+      } else {
+	return result / found;
+      }
+    } else if (attribute(attIndex).isNominal()) {
+      counts = new int[attribute(attIndex).numValues()];
+      for (int j = 0; j < numInstances(); j++) {
+	if (!instance(j).isMissing(attIndex)) {
+	  counts[(int) instance(j).value(attIndex)] += instance(j).weight();
+	}
+      }
+      return (double)Utils.maxIndex(counts);
+    } else {
+      return 0;
+    }
+  }
+
+  /**
+   * Returns the mean (mode) for a numeric (nominal) attribute as a
+   * floating-point value.  Returns 0 if the attribute is neither
+   * nominal nor numeric.  If all values are missing it returns zero.
+   *
+   * @param att the attribute
+   * @return the mean or the mode 
+   */
+  public final double meanOrMode(Attribute att) {
+
+    return meanOrMode(att.index());
+  }
+
+  /**
+   * Returns the number of attributes.
+   *
+   * @return the number of attributes as an integer
+   */
+  public final int numAttributes() {
+
+    return m_Attributes.size();
+  }
+
+  /**
+   * Returns the number of class labels.
+   *
+   * @return the number of class labels as an integer if the class 
+   * attribute is nominal, 1 otherwise.
+   * @exception UnassignedClassException if the class is not set
+   */
+  public final int numClasses() {
+    
+    if (m_ClassIndex < 0) {
+      throw new UnassignedClassException("Class index is negative (not set)!");
+    }
+    if (!classAttribute().isNominal()) {
+      return 1;
+    } else {
+      return classAttribute().numValues();
+    }
+  }
+
+  /**
+   * Returns the number of distinct values of a given attribute.
+   * Returns the number of instances if the attribute is a
+   * string attribute. The value 'missing' is not counted.
+   *
+   * @param attIndex the attribute
+   * @return the number of distinct values of a given attribute
+   */
+  public final int numDistinctValues(int attIndex) {
+
+    if (attribute(attIndex).isNumeric()) {
+      double [] attVals = attributeToDoubleArray(attIndex);
+      int [] sorted = Utils.sort(attVals);
+      double prev = 0;
+      int counter = 0;
+      for (int i = 0; i < sorted.length; i++) {
+	Instance current = instance(sorted[i]);
+	if (current.isMissing(attIndex)) {
+	  break;
+	}
+	if ((i == 0) || 
+	    Utils.gr(current.value(attIndex), prev)) {
+	  prev = current.value(attIndex);
+	  counter++;
+	}
+      }
+      return counter;
+    } else {
+      return attribute(attIndex).numValues();
+    }
+  }
+
+  /**
+   * Returns the number of distinct values of a given attribute.
+   * Returns the number of instances if the attribute is a
+   * string attribute. The value 'missing' is not counted.
+   *
+   * @param att the attribute
+   * @return the number of distinct values of a given attribute
+   */
+  public final int numDistinctValues(Attribute att) {
+
+    return numDistinctValues(att.index());
+  }
+  
+  /**
+   * Returns the number of instances in the dataset.
+   *
+   * @return the number of instances in the dataset as an integer
+   */
+  public final int numInstances() {
+
+    return m_Instances.size();
+  }
+
+  /**
+   * Shuffles the instances in the set so that they are ordered 
+   * randomly.
+   *
+   * @param random a random number generator
+   */
+  public final void randomize(Random random) {
+
+    for (int j = numInstances() - 1; j > 0; j--)
+      swap(j,(int)(random.nextDouble()*(double)j));
+  }
+
+  /**
+   * Reads a single instance from the reader and appends it
+   * to the dataset.  Automatically expands the dataset if it
+   * is not large enough to hold the instance. This method does
+   * not check for carriage return at the end of the line.
+   *
+   * @param reader the reader 
+   * @return false if end of file has been reached
+   * @exception IOException if the information is not read 
+   * successfully
+   */ 
+  public final boolean readInstance(Reader reader) 
+       throws IOException {
+
+    StreamTokenizer tokenizer = new StreamTokenizer(reader);
+    
+    initTokenizer(tokenizer);
+    return getInstance(tokenizer, false);
+  }    
+
+  /**
+   * Returns the relation's name.
+   *
+   * @return the relation's name as a string
+   */
+  public final String relationName() {
+
+    return m_RelationName;
+  }
+
+  /**
+   * Renames an attribute. This change only affects this
+   * dataset.
+   *
+   * @param att the attribute's index
+   * @param name the new name
+   */
+  public final void renameAttribute(int att, String name) {
+
+    Attribute newAtt = attribute(att).copy(name);
+    FastVector newVec = new FastVector(numAttributes());
+
+    for (int i = 0; i < numAttributes(); i++) {
+      if (i == att) {
+	newVec.addElement(newAtt);
+      } else {
+	newVec.addElement(attribute(i));
+      }
+    }
+    m_Attributes = newVec;
+  }
+
+  /**
+   * Renames an attribute. This change only affects this
+   * dataset.
+   *
+   * @param att the attribute
+   * @param name the new name
+   */
+  public final void renameAttribute(Attribute att, String name) {
+
+    renameAttribute(att.index(), name);
+  }
+
+  /**
+   * Renames the value of a nominal (or string) attribute value. This
+   * change only affects this dataset.
+   *
+   * @param att the attribute's index
+   * @param val the value's index
+   * @param name the new name 
+   */
+  public final void renameAttributeValue(int att, int val, String name) {
+
+    Attribute newAtt = (Attribute)attribute(att).copy();
+    FastVector newVec = new FastVector(numAttributes());
+
+    newAtt.setValue(val, name);
+    for (int i = 0; i < numAttributes(); i++) {
+      if (i == att) {
+	newVec.addElement(newAtt);
+      } else {
+	newVec.addElement(attribute(i));
+      }
+    }
+    m_Attributes = newVec;
+  }
+
+  /**
+   * Renames the value of a nominal (or string) attribute value. This
+   * change only affects this dataset.
+   *
+   * @param att the attribute
+   * @param val the value
+   * @param name the new name
+   */
+  public final void renameAttributeValue(Attribute att, String val, 
+                                         String name) {
+
+    renameAttributeValue(att.index(), att.indexOfValue(val), name);
+  }
+
+  /**
+   * Creates a new dataset of the same size using random sampling
+   * with replacement.
+   *
+   * @param random a random number generator
+   * @return the new dataset
+   */
+  public final Instances resample(Random random) {
+
+    Instances newData = new Instances(this, numInstances());
+    while (newData.numInstances() < numInstances()) {
+      int i = (int) (random.nextDouble() * (double) numInstances());
+      newData.add(instance(i));
+    }
+    return newData;
+  }
+
+  /**
+   * Creates a new dataset of the same size using random sampling
+   * with replacement according to the current instance weights. The
+   * weights of the instances in the new dataset are set to one.
+   *
+   * @param random a random number generator
+   * @return the new dataset
+   */
+  public final Instances resampleWithWeights(Random random) {
+
+    double [] weights = new double[numInstances()];
+    boolean foundOne = false;
+    for (int i = 0; i < weights.length; i++) {
+      weights[i] = instance(i).weight();
+      if (!Utils.eq(weights[i], weights[0])) {
+        foundOne = true;
+      }
+    }
+    if (foundOne) {
+      return resampleWithWeights(random, weights);
+    } else {
+      return new Instances(this);
+    }
+  }
+
+
+  /**
+   * Creates a new dataset of the same size using random sampling
+   * with replacement according to the given weight vector. The
+   * weights of the instances in the new dataset are set to one.
+   * The length of the weight vector has to be the same as the
+   * number of instances in the dataset, and all weights have to
+   * be positive.
+   *
+   * @param random a random number generator
+   * @param weights the weight vector
+   * @return the new dataset
+   * @exception IllegalArgumentException if the weights array is of the wrong
+   * length or contains negative weights.
+   */
+  public final Instances resampleWithWeights(Random random, 
+					     double[] weights) {
+
+    if (weights.length != numInstances()) {
+      throw new IllegalArgumentException("weights.length != numInstances.");
+    }
+    Instances newData = new Instances(this, numInstances());
+    double[] probabilities = new double[numInstances()];
+    double sumProbs = 0, sumOfWeights = Utils.sum(weights);
+    for (int i = 0; i < numInstances(); i++) {
+      sumProbs += random.nextDouble();
+      probabilities[i] = sumProbs;
+    }
+    Utils.normalize(probabilities, sumProbs / sumOfWeights);
+
+    // Make sure that rounding errors don't mess things up
+    probabilities[numInstances() - 1] = sumOfWeights;
+    int k = 0; int l = 0;
+    sumProbs = 0;
+    while ((k < numInstances() && (l < numInstances()))) {
+      if (weights[l] < 0) {
+	throw new IllegalArgumentException("Weights have to be positive.");
+      }
+      sumProbs += weights[l];
+      while ((k < numInstances()) &&
+	     (probabilities[k] <= sumProbs)) { 
+	newData.add(instance(l));
+	newData.instance(k).setWeight(1);
+	k++;
+      }
+      l++;
+    }
+    return newData;
+  }
+
+  /** 
+   * Sets the class attribute.
+   *
+   * @param att attribute to be the class
+   */
+  public final void setClass(Attribute att) {
+
+    m_ClassIndex = att.index();
+  }
+
+  /** 
+   * Sets the class index of the set.
+   * If the class index is negative there is assumed to be no class.
+   * (ie. it is undefined)
+   *
+   * @param classIndex the new class index
+   * @exception IllegalArgumentException if the class index is too big or < 0
+   */
+  public final void setClassIndex(int classIndex) {
+
+    if (classIndex >= numAttributes()) {
+      throw new IllegalArgumentException("Invalid class index: " + classIndex);
+    }
+    m_ClassIndex = classIndex;
+  }
+
+  /**
+   * Sets the relation's name.
+   *
+   * @param newName the new relation name.
+   */
+  public final void setRelationName(String newName) {
+    
+    m_RelationName = newName;
+  }
+
+  /**
+   * Sorts the instances based on an attribute. For numeric attributes, 
+   * instances are sorted in ascending order. For nominal attributes, 
+   * instances are sorted based on the attribute label ordering 
+   * specified in the header. Instances with missing values for the 
+   * attribute are placed at the end of the dataset.
+   *
+   * @param attIndex the attribute's index
+   */
+  public final void sort(int attIndex) {
+
+    int i,j;
+
+    // move all instances with missing values to end
+    j = numInstances() - 1;
+    i = 0;
+    while (i <= j) {
+      if (instance(j).isMissing(attIndex)) {
+	j--;
+      } else {
+	if (instance(i).isMissing(attIndex)) {
+	  swap(i,j);
+	  j--;
+	}
+	i++;
+      }
+    }
+    quickSort(attIndex, 0, j);
+  }
+
+  /**
+   * Sorts the instances based on an attribute. For numeric attributes, 
+   * instances are sorted into ascending order. For nominal attributes, 
+   * instances are sorted based on the attribute label ordering 
+   * specified in the header. Instances with missing values for the 
+   * attribute are placed at the end of the dataset.
+   *
+   * @param att the attribute
+   */
+  public final void sort(Attribute att) {
+
+    sort(att.index());
+  }
+
+  /**
+   * Stratifies a set of instances according to its class values 
+   * if the class attribute is nominal (so that afterwards a 
+   * stratified cross-validation can be performed).
+   *
+   * @param numFolds the number of folds in the cross-validation
+   * @exception UnassignedClassException if the class is not set
+   */
+  public final void stratify(int numFolds) {
+    
+    if (numFolds <= 0) {
+      throw new IllegalArgumentException("Number of folds must be greater than 1");
+    }
+    if (m_ClassIndex < 0) {
+      throw new UnassignedClassException("Class index is negative (not set)!");
+    }
+    if (classAttribute().isNominal()) {
+
+      // sort by class
+      int index = 1;
+      while (index < numInstances()) {
+	Instance instance1 = instance(index - 1);
+	for (int j = index; j < numInstances(); j++) {
+	  Instance instance2 = instance(j);
+	  if ((instance1.classValue() == instance2.classValue()) ||
+	      (instance1.classIsMissing() && 
+	       instance2.classIsMissing())) {
+	    swap(index,j);
+	    index++;
+	  }
+	}
+	index++;
+      }
+      stratStep(numFolds);
+    }
+  }
+ 
+  /**
+   * Computes the sum of all the instances' weights.
+   *
+   * @return the sum of all the instances' weights as a double
+   */
+  public final double sumOfWeights() {
+    
+    double sum = 0;
+
+    for (int i = 0; i < numInstances(); i++) {
+      sum += instance(i).weight();
+    }
+    return sum;
+  }
+
+  /**
+   * Creates the test set for one fold of a cross-validation on 
+   * the dataset.
+   *
+   * @param numFolds the number of folds in the cross-validation. Must
+   * be greater than 1.
+   * @param numFold 0 for the first fold, 1 for the second, ...
+   * @return the test set as a set of weighted instances
+   * @exception IllegalArgumentException if the number of folds is less than 2
+   * or greater than the number of instances.
+   */
+  public Instances testCV(int numFolds, int numFold) {
+
+    int numInstForFold, first, offset;
+    Instances test;
+    
+    if (numFolds < 2) {
+      throw new IllegalArgumentException("Number of folds must be at least 2!");
+    }
+    if (numFolds > numInstances()) {
+      throw new IllegalArgumentException("Can't have more folds than instances!");
+    }
+    numInstForFold = numInstances() / numFolds;
+    if (numFold < numInstances() % numFolds){
+      numInstForFold++;
+      offset = numFold;
+    }else
+      offset = numInstances() % numFolds;
+    test = new Instances(this, numInstForFold);
+    first = numFold * (numInstances() / numFolds) + offset;
+    copyInstances(first, test, numInstForFold);
+    return test;
+  }
+ 
+  /**
+   * Returns the dataset as a string in ARFF format. Strings
+   * are quoted if they contain whitespace characters, or if they
+   * are a question mark.
+   *
+   * @return the dataset in ARFF format as a string
+   */
+  public final String toString() {
+    
+    StringBuffer text = new StringBuffer();
+    
+    text.append("@relation " + Utils.quote(m_RelationName) + "\n\n");
+    for (int i = 0; i < numAttributes(); i++) {
+      text.append(attribute(i) + "\n");
+    }
+    text.append("\n@data\n");
+    for (int i = 0; i < numInstances(); i++) {
+      text.append(instance(i));
+      if (i < numInstances() - 1) {
+	text.append('\n');
+      }
+    }
+    return text.toString();
+  }
+
+  /**
+   * Creates the training set for one fold of a cross-validation 
+   * on the dataset.
+   *
+   * @param numFolds the number of folds in the cross-validation. Must
+   * be greater than 1.
+   * @param numFold 0 for the first fold, 1 for the second, ...
+   * @return the training set as a set of weighted 
+   * instances
+   * @exception IllegalArgumentException if the number of folds is less than 2
+   * or greater than the number of instances.
+   */
+  public Instances trainCV(int numFolds, int numFold) {
+
+    int numInstForFold, first, offset;
+    Instances train;
+ 
+    if (numFolds < 2) {
+      throw new IllegalArgumentException("Number of folds must be at least 2!");
+    }
+    if (numFolds > numInstances()) {
+      throw new IllegalArgumentException("Can't have more folds than instances!");
+    }
+    numInstForFold = numInstances() / numFolds;
+    if (numFold < numInstances() % numFolds) {
+      numInstForFold++;
+      offset = numFold;
+    }else
+      offset = numInstances() % numFolds;
+    train = new Instances(this, numInstances() - numInstForFold);
+    first = numFold * (numInstances() / numFolds) + offset;
+    copyInstances(0, train, first);
+    copyInstances(first + numInstForFold, train,
+		  numInstances() - first - numInstForFold);
+
+    return train;
+  }
+
+  /**
+   * Computes the variance for a numeric attribute.
+   *
+   * @param attIndex the numeric attribute
+   * @return the variance if the attribute is numeric
+   * @exception IllegalArgumentException if the attribute is not numeric
+   */
+  public final double variance(int attIndex) {
+  
+    double sum = 0, sumSquared = 0, sumOfWeights = 0;
+
+    if (!attribute(attIndex).isNumeric()) {
+      throw new IllegalArgumentException("Can't compute variance because attribute is " +
+			  "not numeric!");
+    }
+    for (int i = 0; i < numInstances(); i++) {
+      if (!instance(i).isMissing(attIndex)) {
+	sum += instance(i).weight() * 
+	  instance(i).value(attIndex);
+	sumSquared += instance(i).weight() * 
+	  instance(i).value(attIndex) *
+	  instance(i).value(attIndex);
+	sumOfWeights += instance(i).weight();
+      }
+    }
+    if (Utils.smOrEq(sumOfWeights, 1)) {
+      return 0;
+    }
+    return (sumSquared - (sum * sum / sumOfWeights)) / 
+      (sumOfWeights - 1);
+  }
+
+  /**
+   * Computes the variance for a numeric attribute.
+   *
+   * @param att the numeric attribute
+   * @return the variance if the attribute is numeric
+   * @exception IllegalArgumentException if the attribute is not numeric
+   */
+  public final double variance(Attribute att) {
+    
+    return variance(att.index());
+  }
+  
+  /**
+   * Calculates summary statistics on the values that appear in this
+   * set of instances for a specified attribute.
+   *
+   * @param index the index of the attribute to summarize.
+   * @return an AttributeStats object with it's fields calculated.
+   */
+  public AttributeStats attributeStats(int index) {
+
+    AttributeStats result = new AttributeStats();
+    if (attribute(index).isNominal()) {
+      result.nominalCounts = new int [attribute(index).numValues()];
+    }
+    if (attribute(index).isNumeric()) {
+      result.numericStats = new weka.experiment.Stats();
+    }
+    result.totalCount = numInstances();
+
+    double [] attVals = attributeToDoubleArray(index);
+    int [] sorted = Utils.sort(attVals);
+    int currentCount = 0;
+    double prev = Instance.missingValue();
+    for (int j = 0; j < numInstances(); j++) {
+      Instance current = instance(sorted[j]);
+      if (current.isMissing(index)) {
+	result.missingCount = numInstances() - j;
+	break;
+      }
+      if (Utils.eq(current.value(index), prev)) {
+	currentCount++;
+      } else {
+	result.addDistinct(prev, currentCount);
+	currentCount = 1;
+	prev = current.value(index);
+      }
+    }
+    result.addDistinct(prev, currentCount);
+    result.distinctCount--; // So we don't count "missing" as a value 
+    return result;
+  }
+  
+  /**
+   * Gets the value of all instances in this dataset for a particular
+   * attribute. Useful in conjunction with Utils.sort to allow iterating
+   * through the dataset in sorted order for some attribute.
+   *
+   * @param index the index of the attribute.
+   * @return an array containing the value of the desired attribute for
+   * each instance in the dataset. 
+   */
+  public double [] attributeToDoubleArray(int index) {
+
+    double [] result = new double[numInstances()];
+    for (int i = 0; i < result.length; i++) {
+      result[i] = instance(i).value(index);
+    }
+    return result;
+  }
+
+  /**
+   * Generates a string summarizing the set of instances. Gives a breakdown
+   * for each attribute indicating the number of missing/discrete/unique
+   * values and other information.
+   *
+   * @return a string summarizing the dataset
+   */
+  public String toSummaryString() {
+
+    StringBuffer result = new StringBuffer();
+    result.append("Relation Name:  ").append(relationName()).append('\n');
+    result.append("Num Instances:  ").append(numInstances()).append('\n');
+    result.append("Num Attributes: ").append(numAttributes()).append('\n');
+    result.append('\n');
+
+    result.append(Utils.padLeft("", 5)).append(Utils.padRight("Name", 25));
+    result.append(Utils.padLeft("Type", 5)).append(Utils.padLeft("Nom", 5));
+    result.append(Utils.padLeft("Int", 5)).append(Utils.padLeft("Real", 5));
+    result.append(Utils.padLeft("Missing", 12));
+    result.append(Utils.padLeft("Unique", 12));
+    result.append(Utils.padLeft("Dist", 6)).append('\n');
+    for (int i = 0; i < numAttributes(); i++) {
+      Attribute a = attribute(i);
+      AttributeStats as = attributeStats(i);
+      result.append(Utils.padLeft("" + (i + 1), 4)).append(' ');
+      result.append(Utils.padRight(a.name(), 25)).append(' ');
+      long percent;
+      switch (a.type()) {
+      case Attribute.NOMINAL:
+	result.append(Utils.padLeft("Nom", 4)).append(' ');
+	percent = Math.round(100.0 * as.intCount / as.totalCount);
+	result.append(Utils.padLeft("" + percent, 3)).append("% ");
+	result.append(Utils.padLeft("" + 0, 3)).append("% ");
+	percent = Math.round(100.0 * as.realCount / as.totalCount);
+	result.append(Utils.padLeft("" + percent, 3)).append("% ");
+	break;
+      case Attribute.NUMERIC:
+	result.append(Utils.padLeft("Num", 4)).append(' ');
+	result.append(Utils.padLeft("" + 0, 3)).append("% ");
+	percent = Math.round(100.0 * as.intCount / as.totalCount);
+	result.append(Utils.padLeft("" + percent, 3)).append("% ");
+	percent = Math.round(100.0 * as.realCount / as.totalCount);
+	result.append(Utils.padLeft("" + percent, 3)).append("% ");
+	break;
+      case Attribute.STRING:
+	result.append(Utils.padLeft("Str", 4)).append(' ');
+	percent = Math.round(100.0 * as.intCount / as.totalCount);
+	result.append(Utils.padLeft("" + percent, 3)).append("% ");
+	result.append(Utils.padLeft("" + 0, 3)).append("% ");
+	percent = Math.round(100.0 * as.realCount / as.totalCount);
+	result.append(Utils.padLeft("" + percent, 3)).append("% ");
+	break;
+      default:
+	result.append(Utils.padLeft("???", 4)).append(' ');
+	result.append(Utils.padLeft("" + 0, 3)).append("% ");
+	percent = Math.round(100.0 * as.intCount / as.totalCount);
+	result.append(Utils.padLeft("" + percent, 3)).append("% ");
+	percent = Math.round(100.0 * as.realCount / as.totalCount);
+	result.append(Utils.padLeft("" + percent, 3)).append("% ");
+	break;
+      }
+      result.append(Utils.padLeft("" + as.missingCount, 5)).append(" /");
+      percent = Math.round(100.0 * as.missingCount / as.totalCount);
+      result.append(Utils.padLeft("" + percent, 3)).append("% ");
+      result.append(Utils.padLeft("" + as.uniqueCount, 5)).append(" /");
+      percent = Math.round(100.0 * as.uniqueCount / as.totalCount);
+      result.append(Utils.padLeft("" + percent, 3)).append("% ");
+      result.append(Utils.padLeft("" + as.distinctCount, 5)).append(' ');
+      result.append('\n');
+    }
+    return result.toString();
+  }
+  
+  /**
+   * Reads a single instance using the tokenizer and appends it
+   * to the dataset. Automatically expands the dataset if it
+   * is not large enough to hold the instance.
+   *
+   * @param tokenizer the tokenizer to be used
+   * @param flag if method should test for carriage return after 
+   * each instance
+   * @return false if end of file has been reached
+   * @exception IOException if the information is not read 
+   * successfully
+   */ 
+  protected boolean getInstance(StreamTokenizer tokenizer, 
+				boolean flag) 
+       throws IOException {
+    
+    // Check if any attributes have been declared.
+    if (m_Attributes.size() == 0) {
+      errms(tokenizer,"no header information available");
+    }
+
+    // Check if end of file reached.
+    getFirstToken(tokenizer);
+    if (tokenizer.ttype == StreamTokenizer.TT_EOF) {
+      return false;
+    }
+    
+    // Parse instance
+    if (tokenizer.ttype == '{') {
+      return getInstanceSparse(tokenizer, flag);
+    } else {
+      return getInstanceFull(tokenizer, flag);
+    }
+  }
+
+  /**
+   * Reads a single instance using the tokenizer and appends it
+   * to the dataset. Automatically expands the dataset if it
+   * is not large enough to hold the instance.
+   *
+   * @param tokenizer the tokenizer to be used
+   * @param flag if method should test for carriage return after 
+   * each instance
+   * @return false if end of file has been reached
+   * @exception IOException if the information is not read 
+   * successfully
+   */ 
+  protected boolean getInstanceSparse(StreamTokenizer tokenizer, 
+				      boolean flag) 
+       throws IOException {
+
+    int valIndex, numValues = 0, maxIndex = -1;
+    
+    // Get values
+    do {
+      
+      // Get index
+      getIndex(tokenizer);
+      if (tokenizer.ttype == '}') {
+	break;
+      }
+       
+      // Is index valid?
+      try{
+	m_IndicesBuffer[numValues] = Integer.valueOf(tokenizer.sval).intValue();
+      } catch (NumberFormatException e) {
+	errms(tokenizer,"index number expected");
+      }
+      if (m_IndicesBuffer[numValues] <= maxIndex) {
+	errms(tokenizer,"indices have to be ordered");
+      }
+      if ((m_IndicesBuffer[numValues] < 0) || 
+	  (m_IndicesBuffer[numValues] >= numAttributes())) {
+	errms(tokenizer,"index out of bounds");
+      }
+      maxIndex = m_IndicesBuffer[numValues];
+
+      // Get value;
+      getNextToken(tokenizer);
+
+      // Check if value is missing.
+      if  (tokenizer.ttype == '?') {
+	m_ValueBuffer[numValues] = Instance.missingValue();
+      } else {
+
+	// Check if token is valid.
+	if (tokenizer.ttype != StreamTokenizer.TT_WORD) {
+	  errms(tokenizer,"not a valid value");
+	}
+	if (attribute(m_IndicesBuffer[numValues]).isNominal()) {
+	  
+	  // Check if value appears in header.
+	  valIndex = 
+	    attribute(m_IndicesBuffer[numValues]).indexOfValue(tokenizer.sval);
+	  if (valIndex == -1) {
+	    errms(tokenizer,"nominal value not declared in header");
+	  }
+	  m_ValueBuffer[numValues] = (double)valIndex;
+	} else if (attribute(m_IndicesBuffer[numValues]).isNumeric()) {
+	  
+	  // Check if value is really a number.
+	  try{
+	    m_ValueBuffer[numValues] = Double.valueOf(tokenizer.sval).
+	      doubleValue();
+	  } catch (NumberFormatException e) {
+	    errms(tokenizer,"number expected");
+	  }
+	} else { 
+	  m_ValueBuffer[numValues] = 
+	    attribute(m_IndicesBuffer[numValues]).addStringValue(tokenizer.sval);
+	}
+      }
+      numValues++;
+    } while (true);
+    if (flag) {
+      getLastToken(tokenizer,true);
+    }
+      
+    // Add instance to dataset
+    double[] tempValues = new double[numValues];
+    int[] tempIndices = new int[numValues];
+    System.arraycopy(m_ValueBuffer, 0, tempValues, 0, numValues);
+    System.arraycopy(m_IndicesBuffer, 0, tempIndices, 0, numValues);
+    add(new SparseInstance(1, tempValues, tempIndices, numAttributes()));
+    return true;
+  }
+
+  /**
+   * Reads a single instance using the tokenizer and appends it
+   * to the dataset. Automatically expands the dataset if it
+   * is not large enough to hold the instance.
+   *
+   * @param tokenizer the tokenizer to be used
+   * @param flag if method should test for carriage return after 
+   * each instance
+   * @return false if end of file has been reached
+   * @exception IOException if the information is not read 
+   * successfully
+   */ 
+  protected boolean getInstanceFull(StreamTokenizer tokenizer, 
+				    boolean flag) 
+       throws IOException {
+
+    double[] instance = new double[numAttributes()];
+    int index;
+    
+    // Get values for all attributes.
+    for (int i = 0; i < numAttributes(); i++){
+      
+      // Get next token
+      if (i > 0) {
+	getNextToken(tokenizer);
+      }
+            
+      // Check if value is missing.
+      if  (tokenizer.ttype == '?') {
+	instance[i] = Instance.missingValue();
+      } else {
+
+	// Check if token is valid.
+	if (tokenizer.ttype != StreamTokenizer.TT_WORD) {
+	  errms(tokenizer,"not a valid value");
+	}
+	if (attribute(i).isNominal()) {
+	  
+	  // Check if value appears in header.
+	  index = attribute(i).indexOfValue(tokenizer.sval);
+	  if (index == -1) {
+	    errms(tokenizer,"nominal value not declared in header");
+	  }
+	  instance[i] = (double)index;
+	} else if (attribute(i).isNumeric()) {
+	  
+	  // Check if value is really a number.
+	  try{
+	    instance[i] = Double.valueOf(tokenizer.sval).
+	      doubleValue();
+	  } catch (NumberFormatException e) {
+	    errms(tokenizer,"number expected");
+	  }
+	} else { 
+	  instance[i] = attribute(i).addStringValue(tokenizer.sval);
+	}
+      }
+    }
+    if (flag) {
+      getLastToken(tokenizer,true);
+    }
+      
+    // Add instance to dataset
+    add(new Instance(1, instance));
+    return true;
+  }
+
+  /**
+   * Reads and stores header of an ARFF file.
+   *
+   * @param tokenizer the stream tokenizer
+   * @exception IOException if the information is not read 
+   * successfully
+   */ 
+  protected void readHeader(StreamTokenizer tokenizer) 
+     throws IOException{
+    
+    String attributeName;
+    FastVector attributeValues;
+    int i;
+
+    // Get name of relation.
+    getFirstToken(tokenizer);
+    if (tokenizer.ttype == StreamTokenizer.TT_EOF) {
+      errms(tokenizer,"premature end of file");
+    }
+    if (tokenizer.sval.equalsIgnoreCase("@relation")){
+      getNextToken(tokenizer);
+      m_RelationName = tokenizer.sval;
+      getLastToken(tokenizer,false);
+    } else {
+      errms(tokenizer,"keyword @relation expected");
+    }
+
+    // Create vectors to hold information temporarily.
+    m_Attributes = new FastVector();
+ 
+    // Get attribute declarations.
+    getFirstToken(tokenizer);
+    if (tokenizer.ttype == StreamTokenizer.TT_EOF) {
+      errms(tokenizer,"premature end of file");
+    }
+    while (tokenizer.sval.equalsIgnoreCase("@attribute")) {
+
+      // Get attribute name.
+      getNextToken(tokenizer);
+      attributeName = tokenizer.sval;
+      getNextToken(tokenizer);
+
+      // Check if attribute is nominal.
+      if (tokenizer.ttype == StreamTokenizer.TT_WORD) {
+
+	// Attribute is real, integer, or string.
+	if (tokenizer.sval.equalsIgnoreCase("real") ||
+	    tokenizer.sval.equalsIgnoreCase("integer") ||
+	    tokenizer.sval.equalsIgnoreCase("numeric")) {
+	  m_Attributes.addElement(new Attribute(attributeName,
+						 numAttributes()));
+	  readTillEOL(tokenizer);
+	} else if (tokenizer.sval.equalsIgnoreCase("string")) {
+	  m_Attributes.
+	    addElement(new Attribute(attributeName, null,
+				     numAttributes()));
+	  readTillEOL(tokenizer);
+	} else {
+	  errms(tokenizer,"no valid attribute type or invalid "+
+		"enumeration");
+	}
+      } else {
+
+	// Attribute is nominal.
+	attributeValues = new FastVector();
+	tokenizer.pushBack();
+	
+	// Get values for nominal attribute.
+	if (tokenizer.nextToken() != '{') {
+	  errms(tokenizer,"{ expected at beginning of enumeration");
+	}
+	while (tokenizer.nextToken() != '}') {
+	  if (tokenizer.ttype == StreamTokenizer.TT_EOL) {
+	    errms(tokenizer,"} expected at end of enumeration");
+	  } else {
+	    attributeValues.addElement(tokenizer.sval);
+	  }
+	}
+	if (attributeValues.size() == 0) {
+	  errms(tokenizer,"no nominal values found");
+	}
+	m_Attributes.
+	  addElement(new Attribute(attributeName, attributeValues,
+				   numAttributes()));
+      }
+      getLastToken(tokenizer,false);
+      getFirstToken(tokenizer);
+      if (tokenizer.ttype == StreamTokenizer.TT_EOF)
+	errms(tokenizer,"premature end of file");
+    }
+
+    // Check if data part follows. We can't easily check for EOL.
+    if (!tokenizer.sval.equalsIgnoreCase("@data")) {
+      errms(tokenizer,"keyword @data expected");
+    }
+    
+    // Check if any attributes have been declared.
+    if (m_Attributes.size() == 0) {
+      errms(tokenizer,"no attributes declared");
+    }
+
+    // Allocate buffers in case sparse instances have to be read
+    m_ValueBuffer = new double[numAttributes()];
+    m_IndicesBuffer = new int[numAttributes()];
+  }
+
+  /**
+   * Copies instances from one set to the end of another 
+   * one.
+   *
+   * @param source the source of the instances
+   * @param from the position of the first instance to be copied
+   * @param dest the destination for the instances
+   * @param num the number of instances to be copied
+   */
+  private void copyInstances(int from, Instances dest, int num) {
+    
+    for (int i = 0; i < num; i++) {
+      dest.add(instance(from + i));
+    }
+  }
+  
+  /**
+   * Throws error message with line number and last token read.
+   *
+   * @param theMsg the error message to be thrown
+   * @param tokenizer the stream tokenizer
+   * @throws IOExcpetion containing the error message
+   */
+  private void errms(StreamTokenizer tokenizer, String theMsg) 
+       throws IOException {
+    
+    throw new IOException(theMsg + ", read " + tokenizer.toString());
+  }
+  
+  /**
+   * Replaces the attribute information by a clone of
+   * itself.
+   */
+  private void freshAttributeInfo() {
+
+    m_Attributes = (FastVector) m_Attributes.copyElements();
+  }
+
+  /**
+   * Gets next token, skipping empty lines.
+   *
+   * @param tokenizer the stream tokenizer
+   * @exception IOException if reading the next token fails
+   */
+  private void getFirstToken(StreamTokenizer tokenizer) 
+    throws IOException{
+    
+    while (tokenizer.nextToken() == StreamTokenizer.TT_EOL){};
+    if ((tokenizer.ttype == '\'') ||
+	(tokenizer.ttype == '"')) {
+      tokenizer.ttype = StreamTokenizer.TT_WORD;
+    } else if ((tokenizer.ttype == StreamTokenizer.TT_WORD) &&
+	       (tokenizer.sval.equals("?"))){
+      tokenizer.ttype = '?';
+    }
+  }
+
+  /**
+   * Gets index, checking for a premature and of line.
+   *
+   * @param tokenizer the stream tokenizer
+   * @exception IOException if it finds a premature end of line
+   */
+  private void getIndex(StreamTokenizer tokenizer) throws IOException{
+    
+    if (tokenizer.nextToken() == StreamTokenizer.TT_EOL) {
+      errms(tokenizer,"premature end of line");
+    }
+    if (tokenizer.ttype == StreamTokenizer.TT_EOF) {
+      errms(tokenizer,"premature end of file");
+    }
+  }
+  
+  /**
+   * Gets token and checks if its end of line.
+   *
+   * @param tokenizer the stream tokenizer
+   * @exception IOException if it doesn't find an end of line
+   */
+  private void getLastToken(StreamTokenizer tokenizer, boolean endOfFileOk) 
+       throws IOException{
+
+    if ((tokenizer.nextToken() != StreamTokenizer.TT_EOL) &&
+	((tokenizer.nextToken() != StreamTokenizer.TT_EOF) || !endOfFileOk)) {
+      errms(tokenizer,"end of line expected");
+    }
+  }
+
+  /**
+   * Gets next token, checking for a premature and of line.
+   *
+   * @param tokenizer the stream tokenizer
+   * @exception IOException if it finds a premature end of line
+   */
+  private void getNextToken(StreamTokenizer tokenizer) 
+       throws IOException{
+    
+    if (tokenizer.nextToken() == StreamTokenizer.TT_EOL) {
+      errms(tokenizer,"premature end of line");
+    }
+    if (tokenizer.ttype == StreamTokenizer.TT_EOF) {
+      errms(tokenizer,"premature end of file");
+    } else if ((tokenizer.ttype == '\'') ||
+	       (tokenizer.ttype == '"')) {
+      tokenizer.ttype = StreamTokenizer.TT_WORD;
+    } else if ((tokenizer.ttype == StreamTokenizer.TT_WORD) &&
+	       (tokenizer.sval.equals("?"))){
+      tokenizer.ttype = '?';
+    }
+  }
+	
+  /**
+   * Initializes the StreamTokenizer used for reading the ARFF file.
+   *
+   * @param tokenizer the stream tokenizer
+   */
+  private void initTokenizer(StreamTokenizer tokenizer){
+
+    tokenizer.resetSyntax();         
+    tokenizer.whitespaceChars(0, ' ');    
+    tokenizer.wordChars(' '+1,'\u00FF');
+    tokenizer.whitespaceChars(',',',');
+    tokenizer.commentChar('%');
+    tokenizer.quoteChar('"');
+    tokenizer.quoteChar('\'');
+    tokenizer.ordinaryChar('{');
+    tokenizer.ordinaryChar('}');
+    tokenizer.eolIsSignificant(true);
+  }
+ 
+  /**
+   * Returns string including all instances, their weights and
+   * their indices in the original dataset.
+   *
+   * @return description of instance and its weight as a string
+   */
+  private String instancesAndWeights(){
+
+    StringBuffer text = new StringBuffer();
+
+    for (int i = 0; i < numInstances(); i++) {
+      text.append(instance(i) + " " + instance(i).weight());
+      if (i < numInstances() - 1) {
+	text.append("\n");
+      }
+    }
+    return text.toString();
+  }
+  
+  /**
+   * Implements quicksort.
+   *
+   * @param attIndex the attribute's index
+   * @param lo0 the first index of the subset to be sorted
+   * @param hi0 the last index of the subset to be sorted
+   */
+  private void quickSort(int attIndex, int lo0, int hi0) {
+    
+    int lo = lo0, hi = hi0;
+    double mid, midPlus, midMinus;
+    
+    if (hi0 > lo0) {
+      
+      // Arbitrarily establishing partition element as the 
+      // midpoint of the array.
+      mid = instance((lo0 + hi0) / 2).value(attIndex);
+      midPlus = mid + 1e-6;
+      midMinus = mid - 1e-6;
+
+      // loop through the array until indices cross
+      while(lo <= hi) {
+	
+	// find the first element that is greater than or equal to 
+	// the partition element starting from the left Index.
+	while ((instance(lo).value(attIndex) < 
+		midMinus) && (lo < hi0)) {
+	  ++lo;
+	}
+	
+	// find an element that is smaller than or equal to
+	// the partition element starting from the right Index.
+	while ((instance(hi).value(attIndex)  > 
+		midPlus) && (hi > lo0)) {
+	  --hi;
+	}
+	
+	// if the indexes have not crossed, swap
+	if(lo <= hi) {
+	  swap(lo,hi);
+	  ++lo;
+	  --hi;
+	}
+      }
+      
+      // If the right index has not reached the left side of array
+      // must now sort the left partition.
+      if(lo0 < hi) {
+	quickSort(attIndex,lo0,hi);
+      }
+      
+      // If the left index has not reached the right side of array
+      // must now sort the right partition.
+      if(lo < hi0) {
+	quickSort(attIndex,lo,hi0);
+      }
+    }
+  }
+
+  /**
+   * Reads and skips all tokens before next end of line token.
+   *
+   * @param tokenizer the stream tokenizer
+   */
+  private void readTillEOL(StreamTokenizer tokenizer) 
+       throws IOException{
+    
+    while (tokenizer.nextToken() != StreamTokenizer.TT_EOL) {};
+    tokenizer.pushBack();
+  }
+
+  /**
+   * Help function needed for stratification of set.
+   *
+   * @param numFolds the number of folds for the stratification
+   */
+  private void stratStep (int numFolds){
+    
+    FastVector newVec = new FastVector(m_Instances.capacity());
+    int start = 0, j;
+
+    // create stratified batch
+    while (newVec.size() < numInstances()) {
+      j = start;
+      while (j < numInstances()) {
+	newVec.addElement(instance(j));
+	j = j + numFolds;
+      }
+      start++;
+    }
+    m_Instances = newVec;
+  }
+  
+  /**
+   * Swaps two instances in the set.
+   *
+   * @param i the first instance's index
+   * @param j the second instance's index
+   */
+  private void swap(int i, int j){
+    
+    m_Instances.swap(i, j);
+  }
+
+  /**
+   * Merges two sets of Instances together. The resulting set will have
+   * all the attributes of the first set plus all the attributes of the 
+   * second set. The number of instances in both sets must be the same.
+   *
+   * @param first the first set of Instances
+   * @param second the second set of Instances
+   * @return the merged set of Instances
+   * @exception IllegalArgumentException if the datasets are not the same size
+   */
+  public static Instances mergeInstances(Instances first, Instances second) {
+
+    if (first.numInstances() != second.numInstances()) {
+      throw new IllegalArgumentException("Instance sets must be of the same size");
+    }
+
+    // Create the vector of merged attributes
+    FastVector newAttributes = new FastVector();
+    for (int i = 0; i < first.numAttributes(); i++) {
+      newAttributes.addElement(first.attribute(i));
+    }
+    for (int i = 0; i < second.numAttributes(); i++) {
+      newAttributes.addElement(second.attribute(i));
+    }
+    
+    // Create the set of Instances
+    Instances merged = new Instances(first.relationName() + '_'
+				     + second.relationName(), 
+				     newAttributes, 
+				     first.numInstances());
+    // Merge each instance
+    for (int i = 0; i < first.numInstances(); i++) {
+      merged.add(first.instance(i).mergeInstance(second.instance(i)));
+    }
+    return merged;
+  }
+
+  /**
+   * Method for testing this class.
+   *
+   * @param argv should contain one element: the name of an ARFF file
+   */
+  public static void test(String [] argv) {
+
+    Instances instances, secondInstances, train, test, transformed, empty;
+    Instance instance;
+    Random random = new Random(2);
+    Reader reader;
+    int start, num;
+    double newWeight;
+    FastVector testAtts, testVals;
+    int i,j;
+    
+    try{
+      if (argv.length > 1) {
+	throw (new Exception("Usage: Instances [<filename>]"));
+      }
+      
+      // Creating set of instances from scratch
+      testVals = new FastVector(2);
+      testVals.addElement("first_value");
+      testVals.addElement("second_value");
+      testAtts = new FastVector(2);
+      testAtts.addElement(new Attribute("nominal_attribute", testVals));
+      testAtts.addElement(new Attribute("numeric_attribute"));
+      instances = new Instances("test_set", testAtts, 10);
+      instances.add(new Instance(instances.numAttributes()));
+      instances.add(new Instance(instances.numAttributes()));
+      instances.add(new Instance(instances.numAttributes()));
+      instances.setClassIndex(0);
+      System.out.println("\nSet of instances created from scratch:\n");
+      System.out.println(instances);
+      
+      if (argv.length == 1) {
+	String filename = argv[0];
+	reader = new FileReader(filename);
+	
+	// Read first five instances and print them
+	System.out.println("\nFirst five instances from file:\n");
+	instances = new Instances(reader, 1);
+	instances.setClassIndex(instances.numAttributes() - 1);
+	i = 0;
+	while ((i < 5) && (instances.readInstance(reader))) {
+	  i++;
+	}
+	System.out.println(instances);
+
+	// Read all the instances in the file
+	reader = new FileReader(filename);
+	instances = new Instances(reader);
+
+	// Make the last attribute be the class 
+	instances.setClassIndex(instances.numAttributes() - 1);
+	
+	// Print header and instances.
+	System.out.println("\nDataset:\n");
+	System.out.println(instances);
+	System.out.println("\nClass index: "+instances.classIndex());
+      }
+      
+      // Test basic methods based on class index.
+      System.out.println("\nClass name: "+instances.classAttribute().name());
+      System.out.println("\nClass index: "+instances.classIndex());
+      System.out.println("\nClass is nominal: " +
+			 instances.classAttribute().isNominal());
+      System.out.println("\nClass is numeric: " +
+			 instances.classAttribute().isNumeric());
+      System.out.println("\nClasses:\n");
+      for (i = 0; i < instances.numClasses(); i++) {
+	System.out.println(instances.classAttribute().value(i));
+      }
+      System.out.println("\nClass values and labels of instances:\n");
+      for (i = 0; i < instances.numInstances(); i++) {
+	Instance inst = instances.instance(i);
+	System.out.print(inst.classValue() + "\t");
+	System.out.print(inst.toString(inst.classIndex()));
+	if (instances.instance(i).classIsMissing()) {
+	  System.out.println("\tis missing");
+	} else {
+	  System.out.println();
+	}
+      }
+      
+      // Create random weights.
+      System.out.println("\nCreating random weights for instances.");
+      for (i = 0; i < instances.numInstances(); i++) {
+	instances.instance(i).setWeight(random.nextDouble()); 
+      }
+      
+      // Print all instances and their weights (and the sum of weights).
+      System.out.println("\nInstances and their weights:\n");
+      System.out.println(instances.instancesAndWeights());
+      System.out.print("\nSum of weights: ");
+      System.out.println(instances.sumOfWeights());
+      
+      // Insert an attribute
+      secondInstances = new Instances(instances);
+      Attribute testAtt = new Attribute("Inserted");
+      secondInstances.insertAttributeAt(testAtt, 0);
+      System.out.println("\nSet with inserted attribute:\n");
+      System.out.println(secondInstances);
+      System.out.println("\nClass name: "
+			 + secondInstances.classAttribute().name());
+      
+      // Delete the attribute
+      secondInstances.deleteAttributeAt(0);
+      System.out.println("\nSet with attribute deleted:\n");
+      System.out.println(secondInstances);
+      System.out.println("\nClass name: "
+			 + secondInstances.classAttribute().name());
+      
+      // Test if headers are equal
+      System.out.println("\nHeaders equal: "+
+			 instances.equalHeaders(secondInstances) + "\n");
+      
+      // Print data in internal format.
+      System.out.println("\nData (internal values):\n");
+      for (i = 0; i < instances.numInstances(); i++) {
+	for (j = 0; j < instances.numAttributes(); j++) {
+	  if (instances.instance(i).isMissing(j)) {
+	    System.out.print("? ");
+	  } else {
+	    System.out.print(instances.instance(i).value(j) + " ");
+	  }
+	}
+	System.out.println();
+      }
+      
+      // Just print header
+      System.out.println("\nEmpty dataset:\n");
+      empty = new Instances(instances, 0);
+      System.out.println(empty);
+      System.out.println("\nClass name: "+empty.classAttribute().name());
+
+      // Create copy and rename an attribute and a value (if possible)
+      if (empty.classAttribute().isNominal()) {
+	Instances copy = new Instances(empty, 0);
+	copy.renameAttribute(copy.classAttribute(), "new_name");
+	copy.renameAttributeValue(copy.classAttribute(), 
+				  copy.classAttribute().value(0), 
+				  "new_val_name");
+	System.out.println("\nDataset with names changed:\n" + copy);
+	System.out.println("\nOriginal dataset:\n" + empty);
+      }
+
+      // Create and prints subset of instances.
+      start = instances.numInstances() / 4;
+      num = instances.numInstances() / 2;
+      System.out.print("\nSubset of dataset: ");
+      System.out.println(num + " instances from " + (start + 1) 
+			 + ". instance");
+      secondInstances = new Instances(instances, start, num);
+      System.out.println("\nClass name: "
+			 + secondInstances.classAttribute().name());
+
+      // Print all instances and their weights (and the sum of weights).
+      System.out.println("\nInstances and their weights:\n");
+      System.out.println(secondInstances.instancesAndWeights());
+      System.out.print("\nSum of weights: ");
+      System.out.println(secondInstances.sumOfWeights());
+      
+      // Create and print training and test sets for 3-fold
+      // cross-validation.
+      System.out.println("\nTrain and test folds for 3-fold CV:");
+      if (instances.classAttribute().isNominal()) {
+	instances.stratify(3);
+      }
+      for (j = 0; j < 3; j++) {
+        train = instances.trainCV(3,j);
+	test = instances.testCV(3,j);
+                      
+	// Print all instances and their weights (and the sum of weights).
+	System.out.println("\nTrain: ");
+	System.out.println("\nInstances and their weights:\n");
+	System.out.println(train.instancesAndWeights());
+	System.out.print("\nSum of weights: ");
+	System.out.println(train.sumOfWeights());
+	System.out.println("\nClass name: "+train.classAttribute().name());
+	System.out.println("\nTest: ");
+	System.out.println("\nInstances and their weights:\n");
+	System.out.println(test.instancesAndWeights());
+	System.out.print("\nSum of weights: ");
+	System.out.println(test.sumOfWeights());
+	System.out.println("\nClass name: "+test.classAttribute().name());
+      }
+
+      // Randomize instances and print them.
+      System.out.println("\nRandomized dataset:");
+      instances.randomize(random);
+      
+      // Print all instances and their weights (and the sum of weights).
+      System.out.println("\nInstances and their weights:\n");
+      System.out.println(instances.instancesAndWeights());
+      System.out.print("\nSum of weights: ");
+      System.out.println(instances.sumOfWeights());
+
+      // Sort instances according to first attribute and
+      // print them.
+      System.out.print("\nInstances sorted according to first attribute:\n ");
+      instances.sort(0);
+        
+      // Print all instances and their weights (and the sum of weights).
+      System.out.println("\nInstances and their weights:\n");
+      System.out.println(instances.instancesAndWeights());
+      System.out.print("\nSum of weights: ");
+      System.out.println(instances.sumOfWeights());
+    } catch (Exception e) {
+      e.printStackTrace(); 
+    }
+  }
+
+  /**
+   * Main method for this class -- just prints a summary of a set
+   * of instances.
+   *
+   * @param argv should contain one element: the name of an ARFF file
+   */
+  public static void main(String [] args) {
+
+    try {
+      Reader r = null;
+      if (args.length > 1) {
+	throw (new Exception("Usage: Instances <filename>"));
+      } else if (args.length == 0) {
+        r = new BufferedReader(new InputStreamReader(System.in));
+      } else {
+        r = new BufferedReader(new FileReader(args[0]));
+      }
+      Instances i = new Instances(r);
+      System.out.println(i.toSummaryString());
+    } catch (Exception ex) {
+      System.err.println(ex.getMessage());
+    }
+  }
+}
+
+     
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Option.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Option.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Option.java	(revision 16571)
@@ -0,0 +1,105 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Option.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+/** 
+ * Class to store information about an option. <p>
+ *
+ * Typical usage: <p>
+ *
+ * <code>Option myOption = new Option("Uses extended mode.", "E", 0, "-E")); </code><p>
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public class Option {
+
+  /** What does this option do? */
+  private String m_Description;
+
+  /** The synopsis. */
+  private String m_Synopsis;
+
+  /** What's the option's name? */
+  private String m_Name;
+
+  /** How many arguments does it take? */
+  private int m_NumArguments;
+
+  /**
+   * Creates new option with the given parameters.
+   *
+   * @String description the option's description
+   * @String name the option's name
+   * @String numArguments the number of arguments
+   */
+  public Option(String description, String name, 
+		int numArguments, String synopsis) {
+  
+    m_Description = description;
+    m_Name = name;
+    m_NumArguments = numArguments;
+    m_Synopsis = synopsis;
+  }
+
+  /**
+   * Returns the option's description.
+   *
+   * @return the option's description
+   */
+  public String description() {
+  
+    return m_Description;
+  }
+
+  /**
+   * Returns the option's name.
+   *
+   * @return the option's name
+   */
+  public String name() {
+
+    return m_Name;
+  }
+
+  /**
+   * Returns the option's number of arguments.
+   *
+   * @return the option's number of arguments
+   */
+  public int numArguments() {
+  
+    return m_NumArguments;
+  }
+
+  /**
+   * Returns the option's synopsis.
+   *
+   * @return the option's synopsis
+   */
+  public String synopsis() {
+  
+    return m_Synopsis;
+  }
+}
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/OptionHandler.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/OptionHandler.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/OptionHandler.java	(revision 16571)
@@ -0,0 +1,67 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    OptionHandler.java
+ *    Copyright (C) 1999 Eibe Frank,Len Trigg
+ *
+ */
+
+package weka.core;
+
+import java.util.*;
+
+/** 
+ * Interface to something that understands options.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @author Len Trigg (trigg@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public interface OptionHandler {
+
+  /**
+   * Returns an enumeration of all the available options.
+   *
+   * @return an enumeration of all available options
+   */
+  public Enumeration listOptions();
+
+  /**
+   * Sets the OptionHandler's options using the given list. All options
+   * will be set (or reset) during this call (i.e. incremental setting
+   * of options is not possible).
+   *
+   * @param options the list of options as an array of strings
+   * @exception Exception if an option is not supported
+   */
+  public void setOptions(String[] options) throws Exception;
+
+  /**
+   * Gets the current option settings for the OptionHandler.
+   *
+   * @return the list of current option settings as an array of strings
+   */
+  public String[] getOptions();
+}
+
+
+
+
+
+
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Queue.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Queue.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Queue.java	(revision 16571)
@@ -0,0 +1,229 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Queue.java
+ *    Copyright (C) 1999 Len Trigg
+ *
+ */
+
+package weka.core;
+
+import java.io.*;
+
+/** 
+ * Class representing a FIFO queue.
+ *
+ * @author Len Trigg (trigg@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public class Queue extends Object implements Serializable {
+
+  /**
+   * Represents one node in the queue.
+   */
+  protected class QueueNode implements Serializable {
+
+    /** The next node in the queue */
+    protected QueueNode m_Next;
+
+    /** The nodes contents */
+    protected Object m_Contents;
+
+    /** 
+     * Creates a queue node with the given contents 
+     */
+    public QueueNode(Object contents) {
+
+      m_Contents = contents;
+      next(null);
+    }
+
+    /**
+     * Sets the next node in the queue, and returns it.
+     */
+    public QueueNode next(QueueNode next) {
+
+      return m_Next = next;
+    }
+
+    /**
+     * Gets the next node in the queue. 
+     */
+    public QueueNode next() {
+
+      return m_Next;
+    }
+
+    /**
+     * Sets the contents of the node.
+     */
+    public Object contents(Object contents) {
+
+      return m_Contents = contents;
+    }
+
+    /**
+     * Returns the contents in the node.
+     */
+    public Object contents() {
+
+      return m_Contents;
+    }
+  }
+
+  /** Store a reference to the head of the queue */
+  protected QueueNode m_Head = null;
+
+  /** Store a reference to the tail of the queue */
+  protected QueueNode m_Tail = null;
+
+  /** Store the current number of elements in the queue */
+  protected int m_Size = 0;
+
+  /**
+   * Removes all objects from the queue.
+   */
+  public final synchronized void removeAllElements() {
+
+    m_Size = 0;
+    m_Head = null;
+    m_Tail = null;
+  }
+
+  /**
+   * Appends an object to the back of the queue.
+   *
+   * @param item the object to be appended
+   * @return the object appended
+   */
+  public synchronized Object push(Object item) {
+
+    QueueNode newNode = new QueueNode(item);
+    if (m_Head == null) {
+      m_Head = m_Tail = newNode;
+    } else {
+      m_Tail = m_Tail.next(newNode);
+    }
+    m_Size++;
+    return item;
+  }
+
+  /**
+   * Pops an object from the front of the queue.
+   *
+   * @return the object at the front of the queue
+   * @exception RuntimeException if the queue is empty
+   */
+  public synchronized Object pop() {
+
+    if (m_Head == null) {
+      throw new RuntimeException("Queue is empty");
+    }
+    Object retval = m_Head.contents();
+    m_Size--;
+    m_Head = m_Head.next();
+    if (m_Head == null) {
+      m_Tail = null;
+    }
+    return retval;
+  }
+
+  /**
+   * Gets object from the front of the queue.
+   *
+   * @return the object at the front of the queue
+   * @exception RuntimeException if the queue is empty
+   */
+  public synchronized Object peek() {
+    
+    if (m_Head == null) {
+      throw new RuntimeException("Queue is empty");
+    }
+    return m_Head.contents();
+  }
+
+  /**
+   * Checks if queue is empty.
+   * 
+   * @return true if queue is empty
+   */
+  public boolean empty() {
+
+    return (m_Head == null);
+  }
+
+  /** 
+   * Gets queue's size.
+   *
+   * @return size of queue
+   */
+  public int size() {
+
+    return m_Size;
+  }
+
+  /**
+   * Produces textual description of queue.
+   *
+   * @return textual description of queue
+   */
+  public String toString() {
+
+    String retval = "Queue Contents "+m_Size+" elements\n";
+    QueueNode current = m_Head;
+    if (current == null) {
+      return retval + "Empty\n";
+    } else {
+      while (current != null) {
+	retval += current.contents().toString()+"\n";
+	current = current.next();
+      }
+    }
+    return retval;
+  }
+
+  /**
+   * Main method for testing this class.
+   *
+   * @param argv a set of strings that are pushed on a test queue
+   */
+  public static void main(String [] argv) {
+
+    try {
+      Queue queue = new Queue();
+      for(int i = 0; i < argv.length; i++) {
+	queue.push(argv[i]);
+      }
+      System.out.println("After Pushing");
+      System.out.println(queue.toString());
+      System.out.println("Popping...");
+      while (!queue.empty()) {
+	System.out.println(queue.pop().toString());
+      }
+    } catch (Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+  }
+}
+
+
+
+
+
+
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Range.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Range.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Range.java	(revision 16571)
@@ -0,0 +1,439 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Range.java
+ *    Copyright (C) 1999 Len Trigg
+ *
+ */
+
+package weka.core;
+
+import java.io.*;
+import java.util.*;
+
+/** 
+ * Class representing a range of cardinal numbers. The range is set by a 
+ * string representation such as: <P>
+ *
+ * <code>
+ *   all
+ *   first-last
+ *   1,2,3,4
+ * </code> <P>
+ * or combinations thereof. The range is internally converted from
+ * 1-based to 0-based (so methods that set or get numbers not in string
+ * format should use 0-based numbers).
+ *
+ * @author Len Trigg (trigg@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public class Range implements Serializable {
+
+  /** Record the string representations of the columns to delete */
+  Vector m_RangeStrings = new Vector();
+
+  /** Whether matching should be inverted */
+  boolean m_Invert;
+
+  /** The array of flags for whether an column is selected */
+  boolean [] m_SelectFlags;
+
+  /** Store the maximum value permitted in the range. -1 indicates that
+      no upper value has been set */
+  int m_Upper = -1;
+
+  /** Default constructor. */
+  public Range() {
+  }
+
+  /**
+   * Constructor to set initial range.
+   *
+   * @param rangeList the initial range
+   * @exception IllegalArgumentException if the range list is invalid
+   */
+  public Range(String rangeList) {
+
+    setRanges(rangeList);
+  }
+
+  /**
+   * Sets the value of "last".
+   *
+   * @param newUpper the value of "last"
+   */
+  public void setUpper(int newUpper) {
+
+    if (newUpper >= 0) {
+      m_Upper = newUpper;
+      setFlags();
+    }
+  }
+  
+  /**
+   * Gets whether the range sense is inverted, i.e. all <i>except</i>
+   * the values included by the range string are selected.
+   * 
+   * @return whether the matching sense is inverted
+   */
+  public boolean getInvert() {
+
+    return m_Invert;
+  }
+
+  /**
+   * Sets whether the range sense is inverted, i.e. all <i>except</i>
+   * the values included by the range string are selected.
+   * 
+   * @param newSetting true if the matching sense is inverted
+   */
+  public void setInvert(boolean newSetting) {
+
+    m_Invert = newSetting;
+  }
+
+  /**
+   * Gets the string representing the selected range of values
+   *
+   * @return the range selection string
+   */
+  public String getRanges() {
+
+    String result = null;
+    Enumeration enum = m_RangeStrings.elements();
+    while (enum.hasMoreElements()) {
+      if (result == null) {
+	result = (String)enum.nextElement();
+      } else {
+	result += ',' + (String)enum.nextElement();
+      }
+    }
+    return (result == null) ? "" : result;
+  }
+
+  /**
+   * Sets the ranges from a string representation.
+   *
+   * @param rangeList the comma separated list of ranges. The empty
+   * string sets the range to empty.
+   * @exception IllegalArgumentException if the rangeList was not well formed
+   */
+  public void setRanges(String rangeList) {
+
+    Vector ranges = new Vector (10);
+
+    // Split the rangeList up into the vector
+    while (!rangeList.equals("")) {
+      String range = rangeList.trim();
+      int commaLoc = rangeList.indexOf(',');
+      if (commaLoc != -1) {
+	range = rangeList.substring(0, commaLoc).trim();
+	rangeList = rangeList.substring(commaLoc + 1).trim();
+      } else {
+	rangeList = "";
+      }
+      if (!range.equals("")) {
+	if (isValidRange(range)) {
+	  ranges.addElement(range);
+	} else {
+	  throw new IllegalArgumentException("Invalid range list at " + range
+                                             + rangeList);
+	}
+      }
+    }
+    m_RangeStrings = ranges;
+    
+    if (m_Upper >= 0) {
+      setFlags();
+    }
+  }
+
+  /**
+   * Gets whether the supplied cardinal number is included in the current
+   * range.
+   *
+   * @param index the number of interest
+   * @return true if index is in the current range
+   * @exception RuntimeException if the upper limit of the range hasn't been defined
+   */
+  public boolean isInRange(int index) {
+
+    if (m_Upper == -1) {
+      throw new RuntimeException("No upper limit has been specified for range");
+    }
+    if (m_Invert) {
+      return !m_SelectFlags[index];
+    } else {
+      return m_SelectFlags[index];
+    }
+  }
+
+  /**
+   * Constructs a representation of the current range. Being a string
+   * representation, the numbers are based from 1.
+   * 
+   * @return the string representation of the current range
+   */
+  public String toString() {
+
+    if (m_RangeStrings.size() == 0) {
+      return "Empty";
+    }
+    String result ="Strings: ";
+    Enumeration enum = m_RangeStrings.elements();
+    while (enum.hasMoreElements()) {
+      result += (String)enum.nextElement() + " ";
+    }
+    result += "\n";
+
+    result += "Invert: " + m_Invert + "\n";
+
+    try {
+      if (m_Upper == -1) {
+	throw new RuntimeException("Upper limit has not been specified");
+      }
+      String cols = null;
+      for (int i = 0; i < m_SelectFlags.length; i++) {
+	if (isInRange(i)) {
+	  if (cols == null) {
+	    cols = "Cols: " + (i + 1);
+	  } else {
+	    cols += "," + (i + 1);
+	  }
+	}
+      }
+      if (cols != null) {
+	result += cols + "\n";
+      }
+    } catch (Exception ex) {
+      result += ex.getMessage();
+    }
+    return result;
+  }
+
+  /**
+   * Gets an array containing all the selected values, in the order
+   * that they were selected (or ascending order if range inversion is on)
+   *
+   * @return the array of selected values
+   * @exception RuntimeException if the upper limit of the range hasn't been defined
+   */
+  public int [] getSelection() {
+
+    if (m_Upper == -1) {
+      throw new RuntimeException("No upper limit has been specified for range");
+    }
+    int [] selectIndices = new int [m_Upper + 1];
+    int numSelected = 0;
+    if (m_Invert)
+    {
+      for (int i = 0; i <= m_Upper; i++) {
+	if (!m_SelectFlags[i]) {
+	  selectIndices[numSelected++] = i;
+	}
+      }
+    }
+    else
+    {
+      Enumeration enum = m_RangeStrings.elements();
+      while (enum.hasMoreElements()) {
+	String currentRange = (String)enum.nextElement();
+	int start = rangeLower(currentRange);
+	int end = rangeUpper(currentRange);
+	for (int i = start; (i <= m_Upper) && (i <= end); i++) {
+	  if (m_SelectFlags[i]) {
+	    selectIndices[numSelected++] = i;
+	  }
+	}
+      }
+    }
+    int [] result = new int [numSelected];
+    System.arraycopy(selectIndices, 0, result, 0, numSelected);
+    return result;
+  }
+
+  /**
+   * Creates a string representation of the indices in the supplied array.
+   *
+   * @param indices an array containing indices to select.
+   * Since the array will typically come from a program, indices are assumed
+   * from 0, and thus will have 1 added in the String representation.
+   */
+  public static String indicesToRangeList(int []indices) {
+
+    StringBuffer rl = new StringBuffer();
+    int last = -2;
+    boolean range = false;
+    for(int i = 0; i < indices.length; i++) {
+      if (i == 0) {
+	rl.append(indices[i] + 1);
+      } else if (indices[i] == last) {
+        range = true;
+      } else {
+        if (range) {
+          rl.append('-').append(last);
+          range = false;
+        }
+	rl.append(',').append(indices[i] + 1);
+      }
+      last = indices[i] + 1;
+    }
+    if (range) {
+      rl.append('-').append(last);
+    }
+    return rl.toString();
+  }
+
+  /** Sets the flags array. */
+  protected void setFlags() {
+
+    m_SelectFlags = new boolean [m_Upper + 1];
+    Enumeration enum = m_RangeStrings.elements();
+    while (enum.hasMoreElements()) {
+      String currentRange = (String)enum.nextElement();
+      int start = rangeLower(currentRange);
+      int end = rangeUpper(currentRange);
+      for (int i = start; (i <= m_Upper) && (i <= end); i++) {
+	m_SelectFlags[i] = true;
+      }
+    }
+  }
+
+
+  /**
+   * Translates a single string selection into it's internal 0-based equivalent
+   *
+   * @param single the string representing the selection (eg: 1 first last)
+   * @return the number corresponding to the selected value
+   */
+  protected int rangeSingle(String single) {
+
+    if (single.toLowerCase().equals("first")) {
+      return 0;
+    }
+    if (single.toLowerCase().equals("last")) {
+      return m_Upper;
+    }
+    int index = Integer.parseInt(single) - 1;
+    if (index < 0) {
+      index = 0;
+    }
+    if (index > m_Upper) {
+      index = m_Upper;
+    }
+    return index;
+  }
+
+  /**
+   * Translates a range into it's lower index.
+   *
+   * @param range the string representation of the range
+   * @return the lower index of the range
+   */
+  protected int rangeLower(String range) {
+
+    int hyphenIndex;
+    if ((hyphenIndex = range.indexOf('-')) >= 0) {
+      return Math.min(rangeLower(range.substring(0, hyphenIndex)),
+		       rangeLower(range.substring(hyphenIndex + 1)));
+    }
+    return rangeSingle(range);
+  }
+
+  /**
+   * Translates a range into it's upper index. Must only be called once
+   * setUpper has been called.
+   *
+   * @param range the string representation of the range
+   * @return the upper index of the range
+   */
+  protected int rangeUpper(String range) {
+
+    int hyphenIndex;
+    if ((hyphenIndex = range.indexOf('-')) >= 0) {
+      return Math.max(rangeUpper(range.substring(0, hyphenIndex)),
+		       rangeUpper(range.substring(hyphenIndex + 1)));
+    }
+    return rangeSingle(range);
+  }
+
+  /**
+   * Determines if a string represents a valid index or simple range.
+   * Examples: <code>first  last   2   first-last  first-4  4-last</code>
+   * Doesn't check that a < b for a-b
+   *
+   * @param range
+   * @return true if the range is valid
+   */
+  protected boolean isValidRange(String range) {
+
+    if (range == null) {
+      return false;
+    }
+    int hyphenIndex;
+    if ((hyphenIndex = range.indexOf('-')) >= 0) {
+      if (isValidRange(range.substring(0, hyphenIndex)) &&
+	  isValidRange(range.substring(hyphenIndex + 1))) {
+	return true;
+      }
+      return false;
+    }
+    if (range.toLowerCase().equals("first")) {
+      return true;
+    }
+    if (range.toLowerCase().equals("last")) {
+      return true;
+    }
+    try {
+      int index = Integer.parseInt(range);
+      if (index > 0) {
+	return true;
+      }
+      return false;
+    } catch (NumberFormatException ex) {
+      return false;
+    }
+  }
+
+  /**
+   * Main method for testing this class.
+   *
+   * @param argv one parameter: a test range specification
+   */
+  public static void main(String [] argv) {
+
+    try {
+      if (argv.length == 0) {
+	throw new Exception("Usage: Range <rangespec>");
+      }
+      Range range = new Range();
+      range.setRanges(argv[0]);
+      range.setUpper(9);
+      range.setInvert(false);
+      System.out.println("Input: " + argv[0] + "\n"
+			 + range.toString());
+      int [] rangeIndices = range.getSelection();
+      for (int i = 0; i < rangeIndices.length; i++)
+	System.out.print(" " + (rangeIndices[i] + 1));
+      System.out.println("");
+    } catch (Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+  }
+}
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/SerializedObject.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/SerializedObject.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/SerializedObject.java	(revision 16571)
@@ -0,0 +1,249 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    SerializedObject.java
+ *    Copyright (C) 2000 Webmind Inc.
+ *
+ */
+
+package weka.core;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+/**
+ * This class stores an object serialized in memory. It allows compression,
+ * to be used to conserve memory (for example, when storing large strings
+ * in memory), or can be used as a mechanism for deep copying objects.
+ *
+ * @author Len Trigg (len@intelligenesis.net)
+ * @version $Revision$
+ */
+public class SerializedObject implements Serializable {
+
+  /** Stores the serialized object */
+  private byte [] m_Serialized;
+
+  /** True if the object has been compressed during storage */
+  private boolean m_Compressed;
+
+  /**
+   * Serializes the supplied object into a byte array without compression.
+   *
+   * @param obj the Object to serialize.
+   * @exception Exception if the object is not Serializable.
+   */
+  public SerializedObject(Object obj) throws Exception {
+
+    this(obj, false);
+  }
+
+  /**
+   * Serializes the supplied object into a byte array.
+   *
+   * @param obj the Object to serialize.
+   * @param compress true if the object should be stored compressed.
+   * @exception Exception if the object is not Serializable.
+   */
+  public SerializedObject(Object obj, boolean compress) throws Exception {
+
+    //System.err.print("."); System.err.flush();
+    m_Compressed = compress;
+    m_Serialized = toByteArray(obj, m_Compressed);
+  }
+
+  /**
+   * Serializes the supplied object to a byte array.
+   *
+   * @param obj the Object to serialize
+   * @param compress true if the object should be compressed.
+   * @return the byte array containing the serialized object.
+   * @exception Exception if the object is not Serializable.
+   */
+  protected static byte [] toByteArray(Object obj, boolean compress) 
+    throws Exception {
+
+    ByteArrayOutputStream bo = new ByteArrayOutputStream();
+    OutputStream os = bo;
+    if (compress) {
+      os = new GZIPOutputStream(os);
+    }
+    os = new BufferedOutputStream(os);
+    ObjectOutputStream oo = new ObjectOutputStream(os);
+    oo.writeObject(obj);
+    oo.close();
+    return bo.toByteArray();
+  }
+
+  /**
+   * Gets the object stored in this SerializedObject. The object returned
+   * will be a deep copy of the original stored object.
+   *
+   * @return the deserialized Object.
+   */
+  public Object getObject() {
+    try {
+      InputStream is = new ByteArrayInputStream(m_Serialized);
+      if (m_Compressed) {
+        is = new GZIPInputStream(is);
+      }
+      is = new BufferedInputStream(is);
+      ObjectInputStream oi = new ObjectInputStream(is);
+      Object result = oi.readObject();
+      oi.close();
+      return result;
+    } catch (Exception ex) {
+      ex.printStackTrace();
+    }
+    return null;
+  }
+
+  /**
+   * Compares this object with another for equality.
+   *
+   * @param other the other Object.
+   * @return true if the objects are equal.
+   */
+  public final boolean equals(Object other) {
+
+    // Check class type
+    if ((other == null) || !(other.getClass().equals(this.getClass()))) {
+      return false;
+    }
+    // Check serialized length
+    byte [] os = ((SerializedObject)other).m_Serialized;
+    if (os.length != m_Serialized.length) {
+      return false;
+    }
+    // Check serialized contents
+    for (int i = 0; i < m_Serialized.length; i++) {
+      if (m_Serialized[i] != os[i]) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  /**
+   * Returns a hashcode for this object.
+   *
+   * @return the hashcode for this object.
+   */
+  public final int hashCode() {
+    
+    return m_Serialized.length;
+  }
+
+  /**
+   * Returns a text representation of the state of this object.
+   *
+   * @return a String representing this object.
+   */
+  public String toString() {
+    
+    return (m_Compressed ? "Compressed object: " : "Uncompressed object: ")
+      + m_Serialized.length + " bytes";
+  }
+
+  /**
+   * Test routine, reads text from stdin and measures memory usage
+   */
+  public static void main2(String []args) {
+
+    try {
+      Runtime r = Runtime.getRuntime();
+      r.gc();
+      java.io.LineNumberReader lnr = new java.io.LineNumberReader(new java.io.InputStreamReader(System.in));
+      StringBuffer sb = new StringBuffer();
+      String line;
+      while ((line = lnr.readLine()) != null) {
+        sb.append(line).append('\n');
+      }
+      String text = sb.toString();
+      //System.err.println("TEXT:");
+      //System.err.println(text);
+      r.gc();
+
+      System.err.print("TOTAL: " + r.totalMemory());
+      System.err.println("\tFREE: " + r.freeMemory());
+      long used = r.totalMemory() - r.freeMemory();
+      
+      // convert to a compressedobject
+      SerializedObject co = new SerializedObject(text, true);
+
+      System.err.print("TOTAL: " + r.totalMemory());
+      System.err.println("\tFREE: " + r.freeMemory());
+      r.gc();
+      long used1 = r.totalMemory() - r.freeMemory();
+      long csize = used1 - used;
+      System.err.println("CompressedSize = " + csize);
+
+      String newstr = (String)co.getObject();
+      r.gc();
+      System.err.print("TOTAL: " + r.totalMemory());
+      System.err.println("\tFREE: " + r.freeMemory());
+      long used2 = r.totalMemory() - r.freeMemory();
+      long usize = used2 - used1;
+      System.err.println("UncompressedSize = " + usize);
+
+      // A couple of references to the original objects
+      // so they don't get freed prematurely and muck up the
+      // measurements.
+      newstr = newstr.toLowerCase();
+      text = text.toLowerCase();
+      System.err.println("Byte array: " + co.toString());
+      System.err.println("Length of text: " + text.length());
+    } catch (Exception ex) {
+      ex.printStackTrace();
+    }
+  }
+
+
+  /**
+   * Test routine, reads an arff file from stdin and measures memory usage
+   * (the arff file should have long string attribute values)
+   */
+  public static void main(String []args) {
+
+    try {
+      Runtime r = Runtime.getRuntime();
+      r.gc();
+      System.err.print("TOTAL: " + r.totalMemory());
+      System.err.println("\tFREE: " + r.freeMemory());
+      long used = r.totalMemory() - r.freeMemory();
+      Instances inst = new Instances(new java.io.BufferedReader(new java.io.InputStreamReader(System.in)));
+      r.gc();
+      long used1 = r.totalMemory() - r.freeMemory();
+      long csize = used1 - used;
+      System.err.print("\nTOTAL: " + r.totalMemory());
+      System.err.println("\tFREE: " + r.freeMemory());
+      System.err.println("size = " + csize);
+      int blah = inst.numAttributes();
+    } catch (Exception ex) {
+      ex.printStackTrace();
+    }
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/SparseInstance.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/SparseInstance.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/SparseInstance.java	(revision 16571)
@@ -0,0 +1,773 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    SparseInstance.java
+ *    Copyright (C) 2000 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+import java.util.*;
+import java.io.*;
+
+/**
+ * Class for storing an instance as a sparse vector. A sparse instance
+ * only requires storage for those attribute values that are non-zero.
+ * Since the objective is to reduce storage requirements for datasets
+ * with large numbers of default values, this also includes nominal
+ * attributes -- the first nominal value (i.e. that which has index 0)
+ * will not require explicit storage, so rearrange your nominal attribute
+ * value orderings if necessary. Missing values will be stored
+ * explicitly.
+ */
+public class SparseInstance extends Instance {
+
+  /** The index of the attribute associated with each stored value. */
+  protected int[] m_Indices;
+
+  /** The maximum number of values that can be stored. */
+  protected int m_NumAttributes;
+
+  protected SparseInstance() {
+
+  }
+
+  /**
+   * Constructor that generates a sparse instance from the given
+   * instance. Reference to the dataset is set to null.
+   * (ie. the instance doesn't have access to information about the
+   * attribute types)
+   *
+   * @param instance the instance from which the attribute values
+   * and the weight are to be copied
+   */
+  public SparseInstance(Instance instance) {
+    
+    m_Weight = instance.m_Weight;
+    m_Dataset = null;
+    m_NumAttributes = instance.numAttributes();
+    if (instance instanceof SparseInstance) {
+      m_AttValues = ((SparseInstance)instance).m_AttValues;
+      m_Indices = ((SparseInstance)instance).m_Indices;
+    } else {
+      double[] tempValues = new double[instance.numAttributes()];
+      int[] tempIndices = new int[instance.numAttributes()];
+      int vals = 0;
+      for (int i = 0; i < instance.numAttributes(); i++) {
+	if (instance.value(i) != 0) {
+	  tempValues[vals] = instance.value(i);
+	  tempIndices[vals] = i;
+	  vals++;
+	}
+      }
+      m_AttValues = new double[vals];
+      m_Indices = new int[vals];
+      System.arraycopy(tempValues, 0, m_AttValues, 0, vals);
+      System.arraycopy(tempIndices, 0, m_Indices, 0, vals);
+    }
+  }
+
+  /**
+   * Constructor that copies the info from the given instance. 
+   * Reference to the dataset is set to null.
+   * (ie. the instance doesn't have access to information about the
+   * attribute types)
+   *
+   * @param instance the instance from which the attribute
+   * info is to be copied 
+   */
+  public SparseInstance(SparseInstance instance) {
+    
+    m_AttValues = instance.m_AttValues;
+    m_Indices = instance.m_Indices;
+    m_Weight = instance.m_Weight;
+    m_NumAttributes = instance.m_NumAttributes;
+    m_Dataset = null;
+  }
+
+  /**
+   * Constructor that generates a sparse instance from the given
+   * parameters. Reference to the dataset is set to null.
+   * (ie. the instance doesn't have access to information about the
+   * attribute types)
+   *
+   * @param weight the instance's weight
+   * @param attValues a vector of attribute values 
+   */
+  public SparseInstance(double weight, double[] attValues) {
+    
+    m_Weight = weight;
+    m_Dataset = null;
+    m_NumAttributes = attValues.length;
+    double[] tempValues = new double[m_NumAttributes];
+    int[] tempIndices = new int[m_NumAttributes];
+    int vals = 0;
+    for (int i = 0; i < m_NumAttributes; i++) {
+      if (attValues[i] != 0) {
+	tempValues[vals] = attValues[i];
+	tempIndices[vals] = i;
+	vals++;
+      }
+    }
+    m_AttValues = new double[vals];
+    m_Indices = new int[vals];
+    System.arraycopy(tempValues, 0, m_AttValues, 0, vals);
+    System.arraycopy(tempIndices, 0, m_Indices, 0, vals);
+  }
+  
+  /**
+   * Constructor that inititalizes instance variable with given
+   * values. Reference to the dataset is set to null. (ie. the instance
+   * doesn't have access to information about the attribute types)
+   *
+   * @param weight the instance's weight
+   * @param attValues a vector of attribute values (just the ones to be stored)
+   * @param indices the indices of the given values in the full vector
+   * @param maxNumValues the maximium number of values that can be stored
+   */
+  public SparseInstance(double weight, double[] attValues,
+			int[] indices, int maxNumValues){
+    
+    int vals = 0; 
+    m_AttValues = new double [attValues.length];
+    m_Indices = new int [indices.length];
+    for (int i = 0; i < attValues.length; i++) {
+      if (attValues[i] != 0) {
+        m_AttValues[vals] = attValues[i];
+        m_Indices[vals] = indices[i];
+        vals++;
+      }
+    }
+    if (vals != attValues.length) {
+      // Need to truncate.
+      double [] newVals = new double[vals];
+      System.arraycopy(m_AttValues, 0, newVals, 0, vals);
+      m_AttValues = newVals;
+      int [] newIndices = new int[vals];
+      System.arraycopy(m_Indices, 0, newIndices, 0, vals);
+      m_Indices = newIndices;
+    }
+    m_Weight = weight;
+    m_NumAttributes = maxNumValues;
+    m_Dataset = null;
+  }
+
+  /**
+   * Constructor of an instance that sets weight to one, all values to
+   * be missing, and the reference to the dataset to null. (ie. the instance
+   * doesn't have access to information about the attribute types)
+   *
+   * @param numAttributes the size of the instance 
+   */
+  public SparseInstance(int numAttributes) {
+    
+    m_AttValues = new double[numAttributes];
+    m_NumAttributes = numAttributes;
+    m_Indices = new int[numAttributes];
+    for (int i = 0; i < m_AttValues.length; i++) {
+      m_AttValues[i] = MISSING_VALUE;
+      m_Indices[i] = i;
+    }
+    m_Weight = 1;
+    m_Dataset = null;
+  }
+
+  /**
+   * Returns the attribute associated with the internal index. 
+   *
+   * @param indexOfIndex the index of the attribute's index 
+   * @return the attribute at the given position
+   * @exception UnassignedDatasetException if instance doesn't have access to a
+   * dataset
+   */ 
+  public Attribute attributeSparse(int indexOfIndex) {
+   
+    if (m_Dataset == null) {
+      throw new UnassignedDatasetException("Instance doesn't have access to a dataset!");
+    }
+    return m_Dataset.attribute(m_Indices[indexOfIndex]);
+  }
+
+  /**
+   * Produces a shallow copy of this instance. The copy has
+   * access to the same dataset. (if you want to make a copy
+   * that doesn't have access to the dataset, use 
+   * <code>new SparseInstance(instance)</code>
+   *
+   * @return the shallow copy
+   */
+  public Object copy() {
+
+    Instance result = new SparseInstance(this);
+    result.m_Dataset = m_Dataset;
+    return result;
+  }
+
+  /**
+   * Returns the index of the attribute stored at the given position.
+   *
+   * @param position the position 
+   * @return the index of the attribute stored at the given position
+   */
+  public int index(int position) {
+
+    return m_Indices[position];
+  }
+
+  /**
+   * Tests if a specific value is "missing".
+   *
+   * @param attIndex the attribute's index
+   */
+  public boolean isMissing(int attIndex) {
+
+    if (Double.isNaN(value(attIndex))) {
+      return true;
+    }
+    return false;
+  }
+
+  /**
+   * Locates the greatest index that is not greater than the
+   * given index.
+   *
+   * @return the internal index of the attribute index. Returns
+   * -1 if no index with this property couldn't be found
+   */
+  public int locateIndex(int index) {
+
+    int min = 0, max = m_Indices.length - 1;
+
+    // Binary search
+    while (max >= min) {
+      int current = (max + min) / 2;
+      if (m_Indices[current] > index) {
+	max = current - 1;
+      } else if (m_Indices[current] < index) {
+	min = current + 1;
+      } else {
+	return current;
+      }
+    }
+    return max;
+  }
+
+  /**
+   * Merges this instance with the given instance and returns
+   * the result. Dataset is set to null.
+   *
+   * @param inst the instance to be merged with this one
+   * @return the merged instances
+   */
+  public Instance mergeInstance(Instance inst) {
+
+    double[] values = new double[numValues() + inst.numValues()];
+    int[] indices = new int[numValues() + inst.numValues()];
+
+    int m = 0;
+    for (int j = 0; j < numValues(); j++, m++) {
+      values[m] = valueSparse(j);
+      indices[m] = index(j);
+    }
+    for (int j = 0; j < inst.numValues(); j++, m++) {
+      values[m] = inst.valueSparse(j);
+      indices[m] = inst.index(j) + inst.numAttributes();
+    }
+    
+    return new SparseInstance(1.0, values, indices, numAttributes() +
+			      inst.numAttributes());
+  }
+
+  /**
+   * Returns the number of attributes.
+   *
+   * @return the number of attributes as an integer
+   */
+  public int numAttributes() {
+
+    return m_NumAttributes;
+  }
+
+  /**
+   * Returns the number of values in the sparse vector.
+   *
+   * @return the number of values
+   */
+  public int numValues() {
+
+    return m_Indices.length;
+  }
+
+  /** 
+   * Replaces all missing values in the instance with the 
+   * values contained in the given array. A deep copy of
+   * the vector of attribute values is performed before the
+   * values are replaced.
+   *
+   * @param array containing the means and modes
+   * @exception IllegalArgumentException if numbers of attributes are unequal
+   */
+  public void replaceMissingValues(double[] array) {
+	 
+    if ((array == null) || (array.length != m_NumAttributes)) {
+      throw new IllegalArgumentException("Unequal number of attributes!");
+    }
+    double[] tempValues = new double[m_AttValues.length];
+    int[] tempIndices = new int[m_AttValues.length];
+    int vals = 0;
+    for (int i = 0; i < m_AttValues.length; i++) {
+      if (isMissingValue(m_AttValues[i])) {
+	if (array[m_Indices[i]] != 0) {
+	  tempValues[vals] = array[m_Indices[i]];
+	  tempIndices[vals] = m_Indices[i];
+	  vals++;
+	} 
+      } else {
+	tempValues[vals] = m_AttValues[i];
+	tempIndices[vals] = m_Indices[i];
+	vals++;
+      }
+    }
+    m_AttValues = new double[vals];
+    m_Indices = new int[vals];
+    System.arraycopy(tempValues, 0, m_AttValues, 0, vals);
+    System.arraycopy(tempIndices, 0, m_Indices, 0, vals);
+  }
+
+  /**
+   * Sets a specific value in the instance to the given value 
+   * (internal floating-point format). Performs a deep copy
+   * of the vector of attribute values before the value is set.
+   *
+   * @param attIndex the attribute's index 
+   * @param value the new attribute value (If the corresponding
+   * attribute is nominal (or a string) then this is the new value's
+   * index as a double).  
+   */
+  public void setValue(int attIndex, double value) {
+
+    int index = locateIndex(attIndex);
+    
+    if ((index >= 0) && (m_Indices[index] == attIndex)) {
+      if (value != 0) {
+	double[] tempValues = new double[m_AttValues.length];
+	System.arraycopy(m_AttValues, 0, tempValues, 0, m_AttValues.length);
+	tempValues[index] = value;
+	m_AttValues = tempValues;
+      } else {
+	double[] tempValues = new double[m_AttValues.length - 1];
+	int[] tempIndices = new int[m_Indices.length - 1];
+	System.arraycopy(m_AttValues, 0, tempValues, 0, index);
+	System.arraycopy(m_Indices, 0, tempIndices, 0, index);
+	System.arraycopy(m_AttValues, index + 1, tempValues, index, 
+			 m_AttValues.length - index - 1);
+	System.arraycopy(m_Indices, index + 1, tempIndices, index, 
+			 m_Indices.length - index - 1);
+	m_AttValues = tempValues;
+	m_Indices = tempIndices;
+      }
+    } else {
+      if (value != 0) {
+	double[] tempValues = new double[m_AttValues.length + 1];
+	int[] tempIndices = new int[m_Indices.length + 1];
+	System.arraycopy(m_AttValues, 0, tempValues, 0, index + 1);
+	System.arraycopy(m_Indices, 0, tempIndices, 0, index + 1);
+	tempIndices[index + 1] = attIndex;
+	tempValues[index + 1] = value;
+	System.arraycopy(m_AttValues, index + 1, tempValues, index + 2, 
+			 m_AttValues.length - index - 1);
+	System.arraycopy(m_Indices, index + 1, tempIndices, index + 2, 
+			 m_Indices.length - index - 1);
+	m_AttValues = tempValues;
+	m_Indices = tempIndices;
+      }
+    }
+  }
+
+  /**
+   * Sets a specific value in the instance to the given value 
+   * (internal floating-point format). Performs a deep copy
+   * of the vector of attribute values before the value is set.
+   *
+   * @param indexOfIndex the index of the attribute's index 
+   * @param value the new attribute value (If the corresponding
+   * attribute is nominal (or a string) then this is the new value's
+   * index as a double).  
+   */
+  public void setValueSparse(int indexOfIndex, double value) {
+
+    if (value != 0) {
+      double[] tempValues = new double[m_AttValues.length];
+      System.arraycopy(m_AttValues, 0, tempValues, 0, m_AttValues.length);
+      m_AttValues = tempValues;
+      m_AttValues[indexOfIndex] = value;
+    } else {
+      double[] tempValues = new double[m_AttValues.length - 1];
+      int[] tempIndices = new int[m_Indices.length - 1];
+      System.arraycopy(m_AttValues, 0, tempValues, 0, indexOfIndex);
+      System.arraycopy(m_Indices, 0, tempIndices, 0, indexOfIndex);
+      System.arraycopy(m_AttValues, indexOfIndex + 1, tempValues, indexOfIndex, 
+		       m_AttValues.length - indexOfIndex - 1);
+      System.arraycopy(m_Indices, indexOfIndex + 1, tempIndices, indexOfIndex, 
+		       m_Indices.length - indexOfIndex - 1);
+      m_AttValues = tempValues;
+      m_Indices = tempIndices;
+    }
+  }
+
+  /**
+   * Returns the values of each attribute as an array of doubles.
+   *
+   * @return an array containing all the instance attribute values
+   */
+  public double[] toDoubleArray() {
+
+    double[] newValues = new double[m_NumAttributes];
+    for (int i = 0; i < m_AttValues.length; i++) {
+      newValues[m_Indices[i]] = m_AttValues[i];
+    }
+    return newValues;
+  }
+
+  /**
+   * Returns the description of one instance in sparse format. 
+   * If the instance doesn't have access to a dataset, it returns the 
+   * internal floating-point values. Quotes string values that contain 
+   * whitespace characters.
+   *
+   * @return the instance's description as a string
+   */
+  public String toString() {
+
+    StringBuffer text = new StringBuffer();
+    
+    text.append('{');
+    for (int i = 0; i < m_Indices.length; i++) {
+      if (i > 0) text.append(",");
+      if (isMissingValue(m_AttValues[i])) {
+	text.append(m_Indices[i] + " ?");
+      } else {
+	if (m_Dataset == null) {
+	  text.append(m_Indices[i] + " " + 
+		      Utils.doubleToString(m_AttValues[i],6));
+	} else {
+	  if (m_Dataset.attribute(m_Indices[i]).isNominal() || 
+	      m_Dataset.attribute(m_Indices[i]).isString()) {
+	    try {
+	      text.append(m_Indices[i] + " " +
+			  Utils.quote(m_Dataset.attribute(m_Indices[i]).
+				      value((int)valueSparse(i))));
+	    } catch (Exception e) {
+              e.printStackTrace();
+              System.err.println(new Instances(m_Dataset, 0));
+              System.err.println("Att:" + m_Indices[i] + " Val:" + valueSparse(i));
+	      throw new Error("This should never happen!");
+	    }
+	  } else {
+	    text.append(m_Indices[i] + " " +
+			Utils.doubleToString(m_AttValues[i],6));
+	  }
+	}
+      }
+    }
+    text.append('}');
+    return text.toString();
+  }
+
+  /**
+   * Returns an instance's attribute value in internal format.
+   *
+   * @param attIndex the attribute's index
+   * @return the specified value as a double (If the corresponding
+   * attribute is nominal (or a string) then it returns the value's index as a 
+   * double).
+   */
+  public double value(int attIndex) {
+
+    int index = locateIndex(attIndex);
+    if ((index >= 0) && (m_Indices[index] == attIndex)) {
+      return m_AttValues[index];
+    } else {
+      return 0.0;
+    }
+  }  
+
+  /**
+   * Deletes an attribute at the given position (0 to 
+   * numAttributes() - 1).
+   *
+   * @param pos the attribute's position
+   */
+  void forceDeleteAttributeAt(int position) {
+
+    int index = locateIndex(position);
+
+    m_NumAttributes--;
+    if ((index >= 0) && (m_Indices[index] == position)) {
+      int[] tempIndices = new int[m_Indices.length - 1];
+      double[] tempValues = new double[m_AttValues.length - 1];
+      System.arraycopy(m_Indices, 0, tempIndices, 0, index);
+      System.arraycopy(m_AttValues, 0, tempValues, 0, index);
+      for (int i = index; i < m_Indices.length - 1; i++) {
+	tempIndices[i] = m_Indices[i + 1] - 1;
+	tempValues[i] = m_AttValues[i + 1];
+      }
+      m_Indices = tempIndices;
+      m_AttValues = tempValues;
+    } else {
+      int[] tempIndices = new int[m_Indices.length];
+      double[] tempValues = new double[m_AttValues.length];
+      System.arraycopy(m_Indices, 0, tempIndices, 0, index + 1);
+      System.arraycopy(m_AttValues, 0, tempValues, 0, index + 1);
+      for (int i = index + 1; i < m_Indices.length - 1; i++) {
+	tempIndices[i] = m_Indices[i] - 1;
+	tempValues[i] = m_AttValues[i];
+      }
+      m_Indices = tempIndices;
+      m_AttValues = tempValues;
+    }
+  }
+
+  /**
+   * Inserts an attribute at the given position
+   * (0 to numAttributes()) and sets its value to be missing. 
+   *
+   * @param pos the attribute's position
+   */
+  void forceInsertAttributeAt(int position)  {
+
+    int index = locateIndex(position);
+
+    m_NumAttributes++;
+    if ((index >= 0) && (m_Indices[index] == position)) {
+      int[] tempIndices = new int[m_Indices.length + 1];
+      double[] tempValues = new double[m_AttValues.length + 1];
+      System.arraycopy(m_Indices, 0, tempIndices, 0, index);
+      System.arraycopy(m_AttValues, 0, tempValues, 0, index);
+      tempIndices[index] = position;
+      tempValues[index] = MISSING_VALUE;
+      for (int i = index; i < m_Indices.length; i++) {
+	tempIndices[i + 1] = m_Indices[i] + 1;
+	tempValues[i + 1] = m_AttValues[i];
+      }
+      m_Indices = tempIndices;
+      m_AttValues = tempValues;
+    } else {
+      int[] tempIndices = new int[m_Indices.length + 1];
+      double[] tempValues = new double[m_AttValues.length + 1];
+      System.arraycopy(m_Indices, 0, tempIndices, 0, index + 1);
+      System.arraycopy(m_AttValues, 0, tempValues, 0, index + 1);
+      tempIndices[index + 1] = position;
+      tempValues[index + 1] = MISSING_VALUE;
+      for (int i = index + 1; i < m_Indices.length; i++) {
+	tempIndices[i + 1] = m_Indices[i] + 1;
+	tempValues[i + 1] = m_AttValues[i];
+      }
+      m_Indices = tempIndices;
+      m_AttValues = tempValues;
+    }
+  }
+
+  /**
+   * Main method for testing this class.
+   */
+  public static void main(String[] options) {
+
+    try {
+
+      // Create numeric attributes "length" and "weight"
+      Attribute length = new Attribute("length");
+      Attribute weight = new Attribute("weight");
+      
+      // Create vector to hold nominal values "first", "second", "third" 
+      FastVector my_nominal_values = new FastVector(3); 
+      my_nominal_values.addElement("first"); 
+      my_nominal_values.addElement("second"); 
+      my_nominal_values.addElement("third"); 
+      
+      // Create nominal attribute "position" 
+      Attribute position = new Attribute("position", my_nominal_values);
+      
+      // Create vector of the above attributes 
+      FastVector attributes = new FastVector(3);
+      attributes.addElement(length);
+      attributes.addElement(weight);
+      attributes.addElement(position);
+      
+      // Create the empty dataset "race" with above attributes
+      Instances race = new Instances("race", attributes, 0);
+      
+      // Make position the class attribute
+      race.setClassIndex(position.index());
+      
+      // Create empty instance with three attribute values
+      SparseInstance inst = new SparseInstance(3);
+      
+      // Set instance's values for the attributes "length", "weight", and "position"
+      inst.setValue(length, 5.3);
+      inst.setValue(weight, 300);
+      inst.setValue(position, "first");
+      
+      // Set instance's dataset to be the dataset "race"
+      inst.setDataset(race);
+      
+      // Print the instance
+      System.out.println("The instance: " + inst);
+      
+      // Print the first attribute
+      System.out.println("First attribute: " + inst.attribute(0));
+      
+      // Print the class attribute
+      System.out.println("Class attribute: " + inst.classAttribute());
+      
+      // Print the class index
+      System.out.println("Class index: " + inst.classIndex());
+      
+      // Say if class is missing
+      System.out.println("Class is missing: " + inst.classIsMissing());
+      
+      // Print the instance's class value in internal format
+      System.out.println("Class value (internal format): " + inst.classValue());
+      
+      // Print a shallow copy of this instance
+      SparseInstance copy = (SparseInstance) inst.copy();
+      System.out.println("Shallow copy: " + copy);
+      
+      // Set dataset for shallow copy
+      copy.setDataset(inst.dataset());
+      System.out.println("Shallow copy with dataset set: " + copy);
+
+      // Print out all values in internal format
+      System.out.print("All stored values in internal format: ");
+      for (int i = 0; i < inst.numValues(); i++) {
+	if (i > 0) {
+	  System.out.print(",");
+	}
+	System.out.print(inst.valueSparse(i));
+      }
+      System.out.println();
+
+      // Set all values to zero
+      System.out.print("All values set to zero: ");
+      while (inst.numValues() > 0) {
+	inst.setValueSparse(0, 0);
+      }
+      for (int i = 0; i < inst.numValues(); i++) {
+	if (i > 0) {
+	  System.out.print(",");
+	}
+	System.out.print(inst.valueSparse(i));
+      }
+      System.out.println();
+
+      // Set all values to one
+      System.out.print("All values set to one: ");
+      for (int i = 0; i < inst.numAttributes(); i++) {
+	inst.setValue(i, 1);
+      }
+      for (int i = 0; i < inst.numValues(); i++) {
+	if (i > 0) {
+	  System.out.print(",");
+	}
+	System.out.print(inst.valueSparse(i));
+      }
+      System.out.println();
+
+      // Unset dataset for copy, delete first attribute, and insert it again
+      copy.setDataset(null);
+      copy.deleteAttributeAt(0);
+      copy.insertAttributeAt(0);
+      copy.setDataset(inst.dataset());
+      System.out.println("Copy with first attribute deleted and inserted: " + copy); 
+
+      // Same for second attribute
+      copy.setDataset(null);
+      copy.deleteAttributeAt(1);
+      copy.insertAttributeAt(1);
+      copy.setDataset(inst.dataset());
+      System.out.println("Copy with second attribute deleted and inserted: " + copy); 
+
+      // Same for last attribute
+      copy.setDataset(null);
+      copy.deleteAttributeAt(2);
+      copy.insertAttributeAt(2);
+      copy.setDataset(inst.dataset());
+      System.out.println("Copy with third attribute deleted and inserted: " + copy); 
+      
+      // Enumerate attributes (leaving out the class attribute)
+      System.out.println("Enumerating attributes (leaving out class):");
+      Enumeration enum = inst.enumerateAttributes();
+      while (enum.hasMoreElements()) {
+	Attribute att = (Attribute) enum.nextElement();
+	System.out.println(att);
+      }
+      
+      // Headers are equivalent?
+      System.out.println("Header of original and copy equivalent: " +
+			 inst.equalHeaders(copy));
+
+      // Test for missing values
+      System.out.println("Length of copy missing: " + copy.isMissing(length));
+      System.out.println("Weight of copy missing: " + copy.isMissing(weight.index()));
+      System.out.println("Length of copy missing: " + 
+			 Instance.isMissingValue(copy.value(length)));
+      System.out.println("Missing value coded as: " + Instance.missingValue());
+
+      // Prints number of attributes and classes
+      System.out.println("Number of attributes: " + copy.numAttributes());
+      System.out.println("Number of classes: " + copy.numClasses());
+
+      // Replace missing values
+      double[] meansAndModes = {2, 3, 0};
+      copy.replaceMissingValues(meansAndModes);
+      System.out.println("Copy with missing value replaced: " + copy);
+
+      // Setting and getting values and weights
+      copy.setClassMissing();
+      System.out.println("Copy with missing class: " + copy);
+      copy.setClassValue(0);
+      System.out.println("Copy with class value set to first value: " + copy);
+      copy.setClassValue("third");
+      System.out.println("Copy with class value set to \"third\": " + copy);
+      copy.setMissing(1);
+      System.out.println("Copy with second attribute set to be missing: " + copy);
+      copy.setMissing(length);
+      System.out.println("Copy with length set to be missing: " + copy);
+      copy.setValue(0, 0);
+      System.out.println("Copy with first attribute set to 0: " + copy);
+      copy.setValue(weight, 1);
+      System.out.println("Copy with weight attribute set to 1: " + copy);
+      copy.setValue(position, "second");
+      System.out.println("Copy with position set to \"second\": " + copy);
+      copy.setValue(2, "first");
+      System.out.println("Copy with last attribute set to \"first\": " + copy);
+      System.out.println("Current weight of instance copy: " + copy.weight());
+      copy.setWeight(2);
+      System.out.println("Current weight of instance copy (set to 2): " + copy.weight());
+      System.out.println("Last value of copy: " + copy.toString(2));
+      System.out.println("Value of position for copy: " + copy.toString(position));
+      System.out.println("Last value of copy (internal format): " + copy.value(2));
+      System.out.println("Value of position for copy (internal format): " + 
+			 copy.value(position));
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+}
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/SpecialFunctions.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/SpecialFunctions.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/SpecialFunctions.java	(revision 16571)
@@ -0,0 +1,127 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    SpecialFunctions.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+import java.lang.Math;
+
+/**
+ * Class implementing some mathematical functions.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public final class SpecialFunctions {
+
+  /** Some constants */
+  private static double log2 = Math.log(2);
+  private static double[] cofLogGamma = {76.18009172947146,-86.50532032941677,
+					 24.01409824083091,-1.231739572450155,
+					 0.1208650973866179e-2,-0.5395239384953e-5};
+
+  /**
+   * Returns natural logarithm of factorial using gamma function.
+   *
+   * @param x the value
+   * @return natural logarithm of factorial
+   */
+  public static double lnFactorial(double x){
+
+    return lnGamma(x+1);
+  }
+
+  /**
+   * Returns natural logarithm of gamma function. Converted to java
+   * from Numerical Recipes in C.
+   *
+   * @param x the value
+   * @return natural logarithm of gamma function
+   */
+  public static double lnGamma(double x){
+    
+    double y,tmp,ser;
+    int j;
+    
+    y=x;
+    tmp=x+5.5;
+    tmp -= (x+0.5)*Math.log(tmp);
+    ser=1.000000000190015;
+    for (j=0;j<=5;j++) {
+      ser += cofLogGamma[j]/++y;
+    }
+    return -tmp+Math.log(2.5066282746310005*ser/x);
+  }
+
+  /**
+   * Returns base 2 logarithm of binomial coefficient using gamma function.
+   *
+   * @param a upper part of binomial coefficient
+   * @param b lower part
+   * @return the base 2 logarithm of the binominal coefficient a over b
+   */
+  public static double log2Binomial(double a, double b) throws ArithmeticException{
+    
+    if (Utils.gr(b,a)) {
+      throw new ArithmeticException("Can't compute binomial coefficient.");
+    }
+    return (lnFactorial(a)-lnFactorial(b)-lnFactorial(a-b))/log2;
+  }
+
+  /**
+   * Returns base 2 logarithm of multinomial using gamma function.
+   *
+   * @param a upper part of multinomial coefficient
+   * @param bs lower part
+   * @return multinomial coefficient of a over the bs
+   */
+  public static double log2Multinomial(double a, double[] bs)
+       throws ArithmeticException{
+    
+    double sum = 0;
+    int i;
+    
+    for (i=0;i<bs.length;i++) {
+      if (Utils.gr(bs[i],a)) {
+	throw 
+	  new ArithmeticException("Can't compute multinomial coefficient.");
+      } else {
+	sum = sum+lnFactorial(bs[i]);
+      }
+    }
+    return (lnFactorial(a)-sum)/log2;
+  }
+
+  /**
+   * Main method for testing this class.
+   */
+  public static void main(String[] ops) {
+
+    double[] doubles = {1, 2, 3};
+
+    System.out.println("6!: " + Math.exp(SpecialFunctions.lnFactorial(6)));
+    System.out.println("lnGamma(6): "+ SpecialFunctions.lnGamma(6));
+    System.out.println("Binomial 6 over 2: " +
+		       Math.pow(2, SpecialFunctions.log2Binomial(6, 2)));
+    System.out.println("Multinomial 6 over 1, 2, 3: " +
+		       Math.pow(2, SpecialFunctions.log2Multinomial(6, doubles)));
+  }    
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Statistics.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Statistics.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Statistics.java	(revision 16571)
@@ -0,0 +1,280 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Statistics.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+/**
+ * Class implementing some distributions, tests, etc. Most of the
+ * code is adapted from Gary Perlman's unixstat.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public class Statistics {
+
+  /** Some constants */
+  private static double logSqrtPi = Math.log(Math.sqrt(Math.PI));
+  private static double rezSqrtPi = 1/Math.sqrt(Math.PI);
+  private static double bigx = 20.0;
+
+  /**
+   * Computes standard error for observed values of a binomial
+   * random variable.
+   *
+   * @param p the probability of success
+   * @param n the size of the sample
+   * @return the standard error
+   */
+  public static double binomialStandardError(double p, int n) {
+
+    if (n == 0) {
+      return 0; 
+    }
+    return Math.sqrt((p*(1-p))/(double) n);
+  }
+
+  /**
+   * Returns chi-squared probability for given value and degrees
+   * of freedom. (The probability that the chi-squared variate
+   * will be greater than x for the given degrees of freedom.)
+   * Adapted from unixstat by Gary Perlman.
+   *
+   * @param x the value
+   * @param df the number of degrees of freedom
+   */
+  public static double chiSquaredProbability(double x, int df) {
+
+    double a, y = 0, s, e, c, z, val;
+    boolean even;
+   
+    if (x <= 0 || df < 1)
+      return (1);
+    a = 0.5 * x;
+    even = (((int)(2*(df/2))) == df);
+    if (df > 1)
+      y = Math.exp(-a); //((-a < -bigx) ? 0.0 : Math.exp (-a));
+    s = (even ? y : (2.0 * normalProbability(-Math.sqrt (x))));
+    if (df > 2){
+      x = 0.5 * (df - 1.0);
+      z = (even ? 1.0 : 0.5);
+      if (a > bigx){
+	e = (even ? 0.0 : logSqrtPi);
+	c = Math.log (a);
+	while (z <= x){
+	  e = Math.log (z) + e;
+	  val = c*z-a-e;
+	  s += Math.exp (val); //((val < -bigx) ? 0.0 : Math.exp (val));
+	  z += 1.0;
+	}
+	return (s);
+      }else{
+	e = (even ? 1.0 : (rezSqrtPi / Math.sqrt (a)));
+	c = 0.0;
+	while (z <= x){
+	  e = e * (a / z);
+	  c = c + e;
+	  z += 1.0;
+	}
+	return (c * y + s);
+      }
+    }else{
+      return (s);
+    }
+  }
+
+  /**
+   * Critical value for given probability of F-distribution.
+   * Adapted from unixstat by Gary Perlman.
+   *
+   * @param p the probability
+   * @param df1 the first number of degrees of freedom
+   * @param df2 the second number of degrees of freedom
+   * @return the critical value for the given probability
+   */
+  public static double FCriticalValue(double p, int df1, int df2) {
+
+    double  fval;
+    double  maxf = 99999.0;     /* maximum possible F ratio */
+    double  minf = .000001;     /* minimum possible F ratio */
+    
+    if (p <= 0.0 || p >= 1.0)
+      return (0.0);
+    
+    fval = 1.0 / p; /* the smaller the p, the larger the F */
+    
+    while (Math.abs (maxf - minf) > .000001) {
+      if (FProbability(fval, df1, df2) < p) /* F too large */
+	maxf = fval;
+      else /* F too small */
+	minf = fval;
+      fval = (maxf + minf) * 0.5;
+    }
+    
+    return (fval);
+  }
+
+  /**
+   * Computes probability of F-ratio.
+   * Adapted from unixstat by Gary Perlman.
+   * Collected Algorithms of the CACM 
+   * Algorithm 322
+   * Egon Dorrer
+   *
+   * @param F the F-ratio
+   * @param df1 the first number of degrees of freedom
+   * @param df2 the second number of degrees of freedom
+   * @return the probability of the F-ratio.
+   */
+  public static double FProbability(double F, int df1, int df2) {
+
+    int     i, j;
+    int     a, b;
+    double  w, y, z, d, p;
+
+    if ((Math.abs(F) < 10e-10) || df1 <= 0 || df2 <= 0)
+      return (1.0);
+    a = (df1%2 == 1) ? 1 : 2;
+    b = (df2%2 == 1) ? 1 : 2;
+    w = (F * df1) / df2;
+    z = 1.0 / (1.0 + w);
+    if (a == 1)
+      if (b == 1) {
+	p = Math.sqrt (w);
+	y = 1/Math.PI; /* 1 / 3.14159 */
+	d = y * z / p;
+	p = 2.0 * y * Math.atan (p);
+      } else {
+	p = Math.sqrt (w * z);
+	d = 0.5 * p * z / w;
+      } else if (b == 1) {
+	p = Math.sqrt (z);
+	d = 0.5 * z * p;
+	p = 1.0 - p;
+      } else {
+	d = z * z;
+	p = w * z;
+      }
+    y = 2.0 * w / z;
+    for (j = b + 2; j <= df2; j += 2) {
+      d *= (1.0 + a / (j - 2.0)) * z;
+      p = (a == 1 ? p + d * y / (j - 1.0) : (p + w) * z);
+    }
+    y = w * z;
+    z = 2.0 / z;
+    b = df2 - 2;
+    for (i = a + 2; i <= df1; i += 2) {
+      j = i + b;
+      d *= y * j / (i - 2.0);
+      p -= z * d / j;
+    }
+    
+    // correction for approximation errors suggested in certification
+    if (p < 0.0)
+      p = 0.0;
+    else if (p > 1.0)
+      p = 1.0;
+    return (1.0-p);
+  }
+  
+  /**
+   * Returns probability that the standardized normal variate Z (mean = 0, standard
+   * deviation = 1) is less than z.
+   * Adapted from unixstat by Gary Perlman.
+   *
+   * @param the z-value
+   * @return the probability of the z value according to the normal pdf
+   */
+  public static double normalProbability(double z) {
+
+    double  y, x, w;
+    
+    if (z == 0.0)
+      x = 0.0;
+    else{
+      y = 0.5 * Math.abs (z);
+      if (y >= 3.0)
+	x = 1.0;
+      else if (y < 1.0){
+	w = y*y;
+	x = ((((((((0.000124818987 * w
+                   -0.001075204047) * w +0.005198775019) * w
+                   -0.019198292004) * w +0.059054035642) * w
+                   -0.151968751364) * w +0.319152932694) * w
+                   -0.531923007300) * w +0.797884560593) * y * 2.0;
+      }else{
+	y -= 2.0;
+	x = (((((((((((((-0.000045255659 * y
+                         +0.000152529290) * y -0.000019538132) * y
+                         -0.000676904986) * y +0.001390604284) * y
+                         -0.000794620820) * y -0.002034254874) * y
+                         +0.006549791214) * y -0.010557625006) * y
+                         +0.011630447319) * y -0.009279453341) * y
+                         +0.005353579108) * y -0.002141268741) * y
+                         +0.000535310849) * y +0.999936657524;
+      }
+    }
+  
+    return (z > 0.0 ? ((x + 1.0) / 2.0) : ((1.0 - x) / 2.0));
+  }
+
+  /**
+   * Computes absolute size of half of a student-t confidence interval 
+   * for given degrees of freedom, probability, and observed value.
+   *
+   * @param df the number of degrees of freedom
+   * @param p the probability
+   * @param se the observed value
+   * @return absolute size of half of a student-t confidence interval
+   */
+  public static double studentTConfidenceInterval(int df, double p,
+						  double se) {
+
+    return Math.sqrt(FCriticalValue(p, 1, df))*se;
+  }
+
+  /**
+   * Main method for testing this class.
+   */
+  public static void main(String[] ops) {
+
+    System.out.println("Binomial standard error (0.5, 100): " + 
+		       Statistics.binomialStandardError(0.5, 100));
+    System.out.println("Chi-squared probability (2.558, 10): " +
+		       Statistics.chiSquaredProbability(2.558, 10));
+    System.out.println("Normal probability (0.2): " +
+		       Statistics.normalProbability(0.2));
+    System.out.println("F critical value (0.05, 4, 5): " +
+		       Statistics.FCriticalValue(0.05, 4, 5));
+    System.out.println("F probability (5.1922, 4, 5): " +
+		       Statistics.FProbability(5.1922, 4, 5));
+    System.out.println("Student-t confidence interval (9, 0.01, 2): " +
+		       Statistics.studentTConfidenceInterval(9, 0.01, 2));
+  }
+}
+
+
+
+
+
+
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/UnassignedClassException.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/UnassignedClassException.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/UnassignedClassException.java	(revision 16571)
@@ -0,0 +1,52 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    UnassignedClassException.java
+ *    Copyright (C) 2001 Webmind Corp.
+ */
+
+package weka.core;
+
+/**
+ * <code>UnassignedClassException</code> is used when
+ * a method requires access to the Attribute designated as 
+ * the class attribute in a set of Instances, but the Instances does not
+ * have any class attribute assigned (such as by setClassIndex()).
+ *
+ * @author <a href="mailto:len@webmind.com">Len Trigg</a>
+ * @version $Revision$
+ */
+public class UnassignedClassException extends RuntimeException {
+
+  /**
+   * Creates a new <code>UnassignedClassException</code> instance
+   * with no detail message.
+   */
+  public UnassignedClassException() { 
+    super(); 
+  }
+
+  /**
+   * Creates a new <code>UnassignedClassException</code> instance
+   * with a specified message.
+   *
+   * @param messagae a <code>String</code> containing the message.
+   */
+  public UnassignedClassException(String message) { 
+    super(message); 
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/UnassignedDatasetException.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/UnassignedDatasetException.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/UnassignedDatasetException.java	(revision 16571)
@@ -0,0 +1,53 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    UnassignedDatasetException.java
+ *    Copyright (C) 2001 Webmind Corp.
+ */
+
+package weka.core;
+
+/**
+ * <code>UnassignedDatasetException</code> is used when
+ * a method of an Instance is called that requires access to
+ * the Instance structure, but that the Instance does not contain
+ * a reference to any Instances (as set by Instance.setDataset(), or when
+ * an Instance is added to a set of Instances)).
+ *
+ * @author <a href="mailto:len@webmind.com">Len Trigg</a>
+ * @version $Revision$
+ */
+public class UnassignedDatasetException extends RuntimeException {
+
+  /**
+   * Creates a new <code>UnassignedDatasetException</code> instance
+   * with no detail message.
+   */
+  public UnassignedDatasetException() { 
+    super(); 
+  }
+
+  /**
+   * Creates a new <code>UnassignedDatasetException</code> instance
+   * with a specified message.
+   *
+   * @param messagae a <code>String</code> containing the message.
+   */
+  public UnassignedDatasetException(String message) { 
+    super(message); 
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/UnsupportedClassTypeException.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/UnsupportedClassTypeException.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/UnsupportedClassTypeException.java	(revision 16571)
@@ -0,0 +1,51 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    UnsupportedClassTypeException.java
+ *    Copyright (C) 2001 Webmind Corp.
+ */
+
+package weka.core;
+
+/**
+ * <code>UnsupportedClassTypeException</code> is used in situations
+ * where the throwing object is not able to accept Instances with the
+ * supplied structure, because the class Attribute is of the wrong type.
+ *
+ * @author <a href="mailto:len@webmind.com">Len Trigg</a>
+ * @version $Revision$
+ */
+public class UnsupportedClassTypeException extends WekaException {
+
+  /**
+   * Creates a new <code>UnsupportedClassTypeException</code> instance
+   * with no detail message.
+   */
+  public UnsupportedClassTypeException() { 
+    super(); 
+  }
+
+  /**
+   * Creates a new <code>UnsupportedClassTypeException</code> instance
+   * with a specified message.
+   *
+   * @param messagae a <code>String</code> containing the message.
+   */
+  public UnsupportedClassTypeException(String message) { 
+    super(message); 
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Utils.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Utils.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/Utils.java	(revision 16571)
@@ -0,0 +1,1384 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Utils.java
+ *    Copyright (C) 1999 Eibe Frank,Len Trigg,Yong Wang
+ *
+ */
+
+package weka.core;
+
+import java.lang.Math;
+import java.util.StringTokenizer;
+import java.util.Properties;
+import java.io.File;
+import java.io.FileInputStream;
+
+/**
+ * Class implementing some simple utility methods.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @author Yong Wang (yongwang@cs.waikato.ac.nz)
+ * @author Len Trigg (trigg@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public final class Utils {
+
+  /** The natural logarithm of 2. */
+  public static double log2 = Math.log(2);
+
+  /** The small deviation allowed in double comparisons */
+  public static double SMALL = 1e-6;
+
+  
+  /**
+   * Reads properties that inherit from three locations. Properties
+   * are first defined in the system resource location (i.e. in the
+   * CLASSPATH).  These default properties must exist. Properties
+   * defined in the users home directory (optional) override default
+   * settings. Properties defined in the current directory (optional)
+   * override all these settings.
+   *
+   * @param resourceName the location of the resource that should be
+   * loaded.  e.g.: "weka/core/Utils.props". (The use of hardcoded
+   * forward slashes here is OK - see
+   * jdk1.1/docs/guide/misc/resources.html) This routine will also
+   * look for the file (in this case) "Utils.props" in the users home
+   * directory and the current directory.
+   * @return the Properties
+   * @exception Exception if no default properties are defined, or if
+   * an error occurs reading the properties files.  
+   */
+  public static Properties readProperties(String resourceName)
+    throws Exception{
+
+    Properties defaultProps = new Properties();
+    try {
+      // Apparently hardcoded slashes are OK here
+      // jdk1.1/docs/guide/misc/resources.html
+      defaultProps.load(ClassLoader.getSystemResourceAsStream(resourceName));
+    } catch (Exception ex) {
+/*      throw new Exception("Problem reading default properties: "
+	+ ex.getMessage()); */
+      System.err.println("Warning, unable to load properties file from "
+			 +"system resource (Utils.java)");
+    }
+
+    // Hardcoded slash is OK here
+    // eg: see jdk1.1/docs/guide/misc/resources.html
+    int slInd = resourceName.lastIndexOf('/');
+    if (slInd != -1) {
+      resourceName = resourceName.substring(slInd + 1);
+    }
+
+    // Allow a properties file in the home directory to override
+    Properties userProps = new Properties(defaultProps);    
+    File propFile = new File(System.getProperties().getProperty("user.home")
+                             + File.separatorChar
+                             + resourceName);
+    if (propFile.exists()) {
+      try {
+        userProps.load(new FileInputStream(propFile));
+      } catch (Exception ex) {
+        throw new Exception("Problem reading user properties: " + propFile);
+      }
+    }
+
+    // Allow a properties file in the current directory to override
+    Properties localProps = new Properties(userProps);
+    propFile = new File(resourceName);
+    if (propFile.exists()) {
+      try {
+        localProps.load(new FileInputStream(propFile));
+      } catch (Exception ex) {
+        throw new Exception("Problem reading local properties: " + propFile);
+      }
+    }
+    
+    return localProps;
+  }
+
+  /**
+   * Returns the correlation coefficient of two double vectors.
+   *
+   * @param y1 double vector 1
+   * @param y2 double vector 2
+   * @param n the length of two double vectors
+   * @return the correlation coefficient
+   */
+  public final static double correlation(double y1[],double y2[],int n) {
+
+    int i;
+    double av1 = 0.0, av2 = 0.0, y11 = 0.0, y22 = 0.0, y12 = 0.0, c;
+    
+    if (n <= 1) {
+      return 1.0;
+    }
+    for (i = 0; i < n; i++) {
+      av1 += y1[i];
+      av2 += y2[i];
+    }
+    av1 /= (double) n;
+    av2 /= (double) n;
+    for (i = 0; i < n; i++) {
+      y11 += (y1[i] - av1) * (y1[i] - av1);
+      y22 += (y2[i] - av2) * (y2[i] - av2);
+      y12 += (y1[i] - av1) * (y2[i] - av2);
+    }
+    if (y11 * y22 == 0.0) {
+      c=1.0;
+    } else {
+      c = y12 / Math.sqrt(Math.abs(y11 * y22));
+    }
+    
+    return c;
+  }
+
+  /**
+   * Removes all occurrences of a string from another string.
+   *
+   * @param inString the string to remove substrings from.
+   * @param substring the substring to remove.
+   * @return the input string with occurrences of substring removed.
+   */
+  public static String removeSubstring(String inString, String substring) {
+
+    StringBuffer result = new StringBuffer();
+    int oldLoc = 0, loc = 0;
+    while ((loc = inString.indexOf(substring, oldLoc))!= -1) {
+      result.append(inString.substring(oldLoc, loc));
+      oldLoc = loc + substring.length();
+    }
+    result.append(inString.substring(oldLoc));
+    return result.toString();
+  }
+
+  /**
+   * Replaces with a new string, all occurrences of a string from 
+   * another string.
+   *
+   * @param inString the string to replace substrings in.
+   * @param substring the substring to replace.
+   * @param replaceString the replacement substring
+   * @return the input string with occurrences of substring replaced.
+   */
+  public static String replaceSubstring(String inString, String subString,
+					String replaceString) {
+
+    StringBuffer result = new StringBuffer();
+    int oldLoc = 0, loc = 0;
+    while ((loc = inString.indexOf(subString, oldLoc))!= -1) {
+      result.append(inString.substring(oldLoc, loc));
+      result.append(replaceString);
+      oldLoc = loc + subString.length();
+    }
+    result.append(inString.substring(oldLoc));
+    return result.toString();
+  }
+
+
+  /**
+   * Pads a string to a specified length, inserting spaces on the left
+   * as required. If the string is too long, characters are removed (from
+   * the right).
+   *
+   * @param inString the input string
+   * @param length the desired length of the output string
+   * @return the output string
+   */
+  public static String padLeft(String inString, int length) {
+
+    return fixStringLength(inString, length, false);
+  }
+  
+  /**
+   * Pads a string to a specified length, inserting spaces on the right
+   * as required. If the string is too long, characters are removed (from
+   * the right).
+   *
+   * @param inString the input string
+   * @param length the desired length of the output string
+   * @return the output string
+   */
+  public static String padRight(String inString, int length) {
+
+    return fixStringLength(inString, length, true);
+  }
+  
+  /**
+   * Pads a string to a specified length, inserting spaces as
+   * required. If the string is too long, characters are removed (from
+   * the right).
+   *
+   * @param inString the input string
+   * @param length the desired length of the output string
+   * @param right true if inserted spaces should be added to the right
+   * @return the output string
+   */
+  private static String fixStringLength(String inString, int length,
+					boolean right) {
+
+    if (inString.length() < length) {
+      while (inString.length() < length) {
+	inString = (right ? inString.concat(" ") : " ".concat(inString));
+      }
+    } else if (inString.length() > length) {
+      inString = inString.substring(0, length);
+    }
+    return inString;
+  }
+ 
+  /**
+   * Rounds a double and converts it into String.
+   *
+   * @param value the double value
+   * @param afterDecimalPoint the (maximum) number of digits permitted
+   * after the decimal point
+   * @return the double as a formatted string
+   */
+  public static String doubleToString(double value, int afterDecimalPoint) {
+    
+    StringBuffer stringBuffer;
+    double temp;
+    int i,dotPosition;
+    long precisionValue;
+    
+    temp = value * Math.pow(10.0, afterDecimalPoint);
+    if (Math.abs(temp) < Long.MAX_VALUE) {
+      precisionValue = 	(temp > 0) ? (long)(temp + 0.5) 
+                                   : -(long)(Math.abs(temp) + 0.5);
+      if (precisionValue == 0) {
+	stringBuffer = new StringBuffer(String.valueOf(0));
+      } else {
+	stringBuffer = new StringBuffer(String.valueOf(precisionValue));
+      }
+      if (afterDecimalPoint == 0) {
+	return stringBuffer.toString();
+      }
+      dotPosition = stringBuffer.length() - afterDecimalPoint;
+      while (((precisionValue < 0) && (dotPosition < 1)) ||
+	     (dotPosition < 0)) {
+	if (precisionValue < 0) {
+	  stringBuffer.insert(1, 0);
+	} else {
+	  stringBuffer.insert(0, 0);
+	}
+	dotPosition++;
+      }
+      stringBuffer.insert(dotPosition, '.');
+      if ((precisionValue < 0) && (stringBuffer.charAt(1) == '.')) {
+	stringBuffer.insert(1, 0);
+      } else if (stringBuffer.charAt(0) == '.') {
+	stringBuffer.insert(0, 0);
+      }
+      int currentPos = stringBuffer.length() - 1;
+      while ((currentPos > dotPosition) &&
+	     (stringBuffer.charAt(currentPos) == '0')) {
+	stringBuffer.setCharAt(currentPos--, ' ');
+      }
+      if (stringBuffer.charAt(currentPos) == '.') {
+	stringBuffer.setCharAt(currentPos, ' ');
+      }
+      
+      return stringBuffer.toString().trim();
+    }
+    return new String("" + value);
+  }
+
+  /**
+   * Rounds a double and converts it into a formatted decimal-justified String.
+   * Trailing 0's are replaced with spaces.
+   *
+   * @param value the double value
+   * @param width the width of the string
+   * @param afterDecimalPoint the number of digits after the decimal point
+   * @return the double as a formatted string
+   */
+  public static String doubleToString(double value, int width,
+				      int afterDecimalPoint) {
+    
+    String tempString = doubleToString(value, afterDecimalPoint);
+    char[] result;
+    int dotPosition;
+
+    if ((afterDecimalPoint >= width) 
+        || (tempString.indexOf('E') != -1)) { // Protects sci notation
+      return tempString;
+    }
+
+    // Initialize result
+    result = new char[width];
+    for (int i = 0; i < result.length; i++) {
+      result[i] = ' ';
+    }
+
+    if (afterDecimalPoint > 0) {
+      // Get position of decimal point and insert decimal point
+      dotPosition = tempString.indexOf('.');
+      if (dotPosition == -1) {
+	dotPosition = tempString.length();
+      } else {
+	result[width - afterDecimalPoint - 1] = '.';
+      }
+    } else {
+      dotPosition = tempString.length();
+    }
+    
+
+    int offset = width - afterDecimalPoint - dotPosition;
+    if (afterDecimalPoint > 0) {
+      offset--;
+    }
+
+    // Not enough room to decimal align within the supplied width
+    if (offset < 0) {
+      return tempString;
+    }
+
+    // Copy characters before decimal point
+    for (int i = 0; i < dotPosition; i++) {
+      result[offset + i] = tempString.charAt(i);
+    }
+
+    // Copy characters after decimal point
+    for (int i = dotPosition + 1; i < tempString.length(); i++) {
+      result[offset + i] = tempString.charAt(i);
+    }
+
+    return new String(result);
+  }
+
+  /**
+   * Tests if a is equal to b.
+   *
+   * @param a a double
+   * @param b a double
+   */
+  public static boolean eq(double a, double b){
+    
+    return (a - b < SMALL) && (b - a < SMALL); 
+  }
+
+  /**
+   * Checks if the given array contains any non-empty options.
+   *
+   * @param strings an array of strings
+   * @exception Exception if there are any non-empty options
+   */
+  public static void checkForRemainingOptions(String [] options) 
+    throws Exception {
+    
+    int illegalOptionsFound = 0;
+    StringBuffer text = new StringBuffer();
+
+    if (options == null) {
+      return;
+    }
+    for (int i = 0; i < options.length; i++) {
+      if (options[i].length() > 0) {
+	illegalOptionsFound++;
+	text.append(options[i] + ' ');
+      }
+    }
+    if (illegalOptionsFound > 0) {
+      throw new Exception("Illegal options: " + text);
+    }
+  }
+  
+  /**
+   * Checks if the given array contains the flag "-Char". Stops
+   * searching at the first marker "--". If the flag is found,
+   * it is replaced with the empty string.
+   *
+   * @param flag the character indicating the flag.
+   * @param strings the array of strings containing all the options.
+   * @return true if the flag was found
+   * @exception Exception if an illegal option was found
+   */
+
+  public static boolean getFlag(char flag, String [] options) 
+    throws Exception {
+
+    if (options == null) {
+      return false;
+    }
+    for (int i = 0; i < options.length; i++) {
+      if ((options[i].length() > 1) && (options[i].charAt(0) == '-')) {
+	try {
+	  Double dummy = Double.valueOf(options[i]);
+	} catch (NumberFormatException e) {
+	  if (options[i].length() > 2) {
+	    throw new Exception("Illegal option: " + options[i]);
+	  }
+	  if (options[i].charAt(1) == flag) {
+	    options[i] = "";
+	    return true;
+	  }
+	  if (options[i].charAt(1) == '-') {
+	    return false;
+	  }
+	}
+      }
+    }
+    return false;
+  }
+
+  /**
+   * Gets an option indicated by a flag "-Char" from the given array
+   * of strings. Stops searching at the first marker "--". Replaces 
+   * flag and option with empty strings.
+   *
+   * @param flag the character indicating the option.
+   * @param options the array of strings containing all the options.
+   * @return the indicated option or an empty string
+   * @exception Exception if the option indicated by the flag can't be found
+   */
+  public static String getOption(char flag, String [] options) 
+    throws Exception {
+
+    String newString;
+
+    if (options == null)
+      return "";
+    for (int i = 0; i < options.length; i++) {
+      if ((options[i].length() > 0) && (options[i].charAt(0) == '-')) {
+	
+	// Check if it is a negative number
+	try {
+	  Double dummy = Double.valueOf(options[i]);
+	} catch (NumberFormatException e) {
+	  if (options[i].length() > 2) {
+	    throw new Exception("Illegal option: " + options[i]);
+	  }
+	  if (options[i].charAt(1) == flag) {
+	    if (i + 1 == options.length) {
+	      throw new Exception("No value given for -" + flag + " option.");
+	    }
+	    options[i] = "";
+	    newString = new String(options[i + 1]);
+	    options[i + 1] = "";
+	    return newString;
+	  }
+	  if (options[i].charAt(1) == '-') {
+	    return "";
+	  }
+	}
+      }
+    }
+    return "";
+  }
+
+  /**
+   * Quotes a string if it contains special characters.
+   * 
+   * The following rules are applied:
+   *
+   * A character is backquoted version of it is one 
+   * of <tt>" ' % \ \n \r \t</tt>.
+   *
+   * A string is enclosed within single quotes if a character has been
+   * backquoted using the previous rule above or contains 
+   * <tt>{ }</tt> or is exactly equal to the strings 
+   * <tt>, ? space or ""</tt> (empty string).
+   *
+   * A quoted question mark distinguishes it from the missing value which
+   * is represented as an unquoted question mark in arff files.
+   *
+   * @param string the string to be quoted
+   * @return the string (possibly quoted)
+   */
+  public static String quote(String string) {
+      boolean quote = false;
+
+      // backquote the following characters 
+      if ((string.indexOf('\n') != -1) || (string.indexOf('\r') != -1) || 
+	  (string.indexOf('\'') != -1) || (string.indexOf('"') != -1) || 
+	  (string.indexOf('\\') != -1) || 
+	  (string.indexOf('\t') != -1) || (string.indexOf('%') != -1)) {
+	  string = backQuoteChars(string);
+	  quote = true;
+      }
+
+      // Enclose the string in 's if the string contains a recently added
+      // backquote or contains one of the following characters.
+      if((quote == true) || 
+	 (string.indexOf('{') != -1) || (string.indexOf('}') != -1) ||
+	 (string.indexOf(',') != -1) || (string.equals("?")) ||
+	 (string.indexOf(' ') != -1) || (string.equals(""))) {
+	  string = ("'".concat(string)).concat("'");
+      }
+
+      return string;
+  }
+
+  /**
+   * Converts carriage returns and new lines in a string into \r and \n.
+   * Backquotes the following characters: ` " \ \t and %
+   * @param string the string
+   * @return the converted string
+   */
+  public static String backQuoteChars(String string) {
+
+    int index;
+    StringBuffer newStringBuffer;
+
+    // replace each of the following characters with the backquoted version
+    char   charsFind[] =    {'\\',   '\'',  '\t',  '"',    '%'};
+    String charsReplace[] = {"\\\\", "\\'", "\\t", "\\\"", "\\%"};
+    for(int i = 0; i < charsFind.length; i++) {
+	if (string.indexOf(charsFind[i]) != -1 ) {
+	    newStringBuffer = new StringBuffer();
+	    while ((index = string.indexOf(charsFind[i])) != -1) {
+		if (index > 0) {
+		    newStringBuffer.append(string.substring(0, index));
+		}
+		newStringBuffer.append(charsReplace[i]);
+		if ((index + 1) < string.length()) {
+		    string = string.substring(index + 1);
+		} else {
+		    string = "";
+		}
+	    }
+	    newStringBuffer.append(string);
+	    string = newStringBuffer.toString();
+	}
+    }
+
+    return Utils.convertNewLines(string);
+  }
+
+  /**
+   * Converts carriage returns and new lines in a string into \r and \n.
+   * @param string the string
+   * @return the converted string
+   */
+  public static String convertNewLines(String string) {
+    
+    int index;
+
+    // Replace with \n
+    StringBuffer newStringBuffer = new StringBuffer();
+    while ((index = string.indexOf('\n')) != -1) {
+      if (index > 0) {
+	newStringBuffer.append(string.substring(0, index));
+      }
+      newStringBuffer.append('\\');
+      newStringBuffer.append('n');
+      if ((index + 1) < string.length()) {
+	string = string.substring(index + 1);
+      } else {
+	string = "";
+      }
+    }
+    newStringBuffer.append(string);
+    string = newStringBuffer.toString();
+
+    // Replace with \r
+    newStringBuffer = new StringBuffer();
+    while ((index = string.indexOf('\r')) != -1) {
+      if (index > 0) {
+	newStringBuffer.append(string.substring(0, index));
+      }
+      newStringBuffer.append('\\');
+      newStringBuffer.append('r');
+      if ((index + 1) < string.length()){
+	string = string.substring(index + 1);
+      } else {
+	string = "";
+      }
+    }
+    newStringBuffer.append(string);
+    return newStringBuffer.toString();
+  }
+    
+
+  /**
+   * Returns the secondary set of options (if any) contained in
+   * the supplied options array. The secondary set is defined to
+   * be any options after the first "--". These options are removed from
+   * the original options array.
+   *
+   * @param options the input array of options
+   * @return the array of secondary options
+   */
+  public static String [] partitionOptions(String [] options) {
+
+    for (int i = 0; i < options.length; i++) {
+      if (options[i].equals("--")) {
+	options[i++] = "";
+	String [] result = new String [options.length - i];
+	for (int j = i; j < options.length; j++) {
+	  result[j - i] = options[j];
+	  options[j] = "";
+	}
+	return result;
+      }
+    }
+    return new String [0];
+  }
+
+  /**
+   * Split up a string containing options into an array of strings,
+   * one for each option.
+   *
+   * @param optionString the string containing the options
+   * @return the array of options
+   */
+  public static String [] splitOptions(String optionString) {
+
+    FastVector optionsVec = new FastVector();
+    StringTokenizer st = new StringTokenizer(optionString);
+    while (st.hasMoreTokens())
+      optionsVec.addElement(st.nextToken());
+
+    String [] options = new String[optionsVec.size()];
+    for (int i = 0; i < optionsVec.size(); i++) {
+      options[i] = (String)optionsVec.elementAt(i);
+    }
+    return options;
+  }
+
+  /**
+   * Joins all the options in an option array into a single string,
+   * as might be used on the command line.
+   *
+   * @param optionArray the array of options
+   * @return the string containing all options.
+   */
+  public static String joinOptions(String [] optionArray) {
+
+    String optionString = "";
+    for (int i = 0; i < optionArray.length; i++) {
+      if (optionArray[i].equals("")) {
+	continue;
+      }
+      if (optionArray[i].indexOf(' ') != -1) {
+	optionString += '"' + optionArray[i] + '"';
+      } else {
+	optionString += optionArray[i];
+      }
+      optionString += " ";
+    }
+    return optionString.trim();
+  }
+  
+  /**
+   * Creates a new instance of an object given it's class name and
+   * (optional) arguments to pass to it's setOptions method. If the
+   * object implements OptionHandler and the options parameter is
+   * non-null, the object will have it's options set. Example use:<p>
+   *
+   * <code> <pre>
+   * String classifierName = Utils.getOption('W', options);
+   * Classifier c = (Classifier)Utils.forName(Classifier.class,
+   *                                          classifierName,
+   *                                          options);
+   * setClassifier(c);
+   * </pre></code>
+   *
+   * @param classType the class that the instantiated object should
+   * be assignable to -- an exception is thrown if this is not the case
+   * @param className the fully qualified class name of the object
+   * @param options an array of options suitable for passing to setOptions. May
+   * be null. Any options accepted by the object will be removed from the
+   * array.
+   * @return the newly created object, ready for use.
+   * @exception Exception if the class name is invalid, or if the
+   * class is not assignable to the desired class type, or the options
+   * supplied are not acceptable to the object
+   */
+  public static Object forName(Class classType,
+			       String className,
+			       String [] options) throws Exception {
+
+    Class c = null;
+    try {
+      c = Class.forName(className);
+    } catch (Exception ex) {
+      throw new Exception("Can't find class called: " + className);
+    }
+    if (!classType.isAssignableFrom(c)) {
+      throw new Exception(classType.getName() + " is not assignable from "
+			  + className);
+    }
+    Object o = c.newInstance();
+    if ((o instanceof OptionHandler)
+	&& (options != null)) {
+      ((OptionHandler)o).setOptions(options);
+      Utils.checkForRemainingOptions(options);
+    }
+    return o;
+  }
+
+  /**
+   * Computes entropy for an array of integers.
+   *
+   * @param counts array of counts
+   * @returns - a log2 a - b log2 b - c log2 c + (a+b+c) log2 (a+b+c)
+   * when given array [a b c]
+   */
+  public static double info(int counts[]) {
+    
+    int total = 0; int c;
+    double x = 0;
+    for (int j = 0; j < counts.length; j++) {
+      x -= xlogx(counts[j]);
+      total += counts[j];
+    }
+    return x + xlogx(total);
+  }
+
+  /**
+   * Tests if a is smaller or equal to b.
+   *
+   * @param a a double
+   * @param b a double
+   */
+  public static boolean smOrEq(double a,double b) {
+    
+    return (a-b < SMALL);
+  }
+
+  /**
+   * Tests if a is greater or equal to b.
+   *
+   * @param a a double
+   * @param b a double
+   */
+  public static boolean grOrEq(double a,double b) {
+    
+    return (b-a < SMALL);
+  }
+  
+  /**
+   * Tests if a is smaller than b.
+   *
+   * @param a a double
+   * @param b a double
+   */
+  public static boolean sm(double a,double b) {
+    
+    return (b-a > SMALL);
+  }
+
+  /**
+   * Tests if a is smaller than b.
+   *
+   * @param a a double
+   * @param b a double 
+   */
+  public static boolean gr(double a,double b) {
+    
+    return (a-b > SMALL);
+  }
+
+  /**
+   * Returns the logarithm of a for base 2.
+   *
+   * @param a a double
+   */
+  public static double log2(double a) {
+    
+    return Math.log(a) / log2;
+  }
+
+  /**
+   * Returns index of maximum element in a given
+   * array of doubles. First maximum is returned.
+   *
+   * @param doubles the array of doubles
+   * @return the index of the maximum element
+   */
+  public static int maxIndex(double [] doubles) {
+
+    double maximum = 0;
+    int maxIndex = 0;
+
+    for (int i = 0; i < doubles.length; i++) {
+      if ((i == 0) || (doubles[i] > maximum)) {
+	maxIndex = i;
+	maximum = doubles[i];
+      }
+    }
+
+    return maxIndex;
+  }
+
+  /**
+   * Returns index of maximum element in a given
+   * array of integers. First maximum is returned.
+   *
+   * @param ints the array of integers
+   * @return the index of the maximum element
+   */
+  public static int maxIndex(int [] ints) {
+
+    int maximum = 0;
+    int maxIndex = 0;
+
+    for (int i = 0; i < ints.length; i++) {
+      if ((i == 0) || (ints[i] > maximum)) {
+	maxIndex = i;
+	maximum = ints[i];
+      }
+    }
+
+    return maxIndex;
+  }
+
+  /**
+   * Computes the mean for an array of doubles.
+   *
+   * @param vector the array
+   * @return the mean
+   */
+  public static double mean(double[] vector) {
+  
+    double sum = 0;
+
+    if (vector.length == 0) {
+      return 0;
+    }
+    for (int i = 0; i < vector.length; i++) {
+      sum += vector[i];
+    }
+    return sum / (double) vector.length;
+  }
+
+  /**
+   * Returns index of minimum element in a given
+   * array of integers. First minimum is returned.
+   *
+   * @param ints the array of integers
+   * @return the index of the minimum element
+   */
+  public static int minIndex(int [] ints) {
+
+    int minimum = 0;
+    int minIndex = 0;
+
+    for (int i = 0; i < ints.length; i++) {
+      if ((i == 0) || (ints[i] < minimum)) {
+	minIndex = i;
+	minimum = ints[i];
+      }
+    }
+
+    return minIndex;
+  }
+
+  /**
+   * Returns index of minimum element in a given
+   * array of doubles. First minimum is returned.
+   *
+   * @param doubles the array of doubles
+   * @return the index of the minimum element
+   */
+  public static int minIndex(double [] doubles) {
+
+    double minimum = 0;
+    int minIndex = 0;
+
+    for (int i = 0; i < doubles.length; i++) {
+      if ((i == 0) || (doubles[i] < minimum)) {
+	minIndex = i;
+	minimum = doubles[i];
+      }
+    }
+
+    return minIndex;
+  }
+
+  /**
+   * Normalizes the doubles in the array by their sum.
+   *
+   * @param doubles the array of double
+   * @exception IllegalArgumentException if sum is Zero or NaN
+   */
+  public static void normalize(double[] doubles) {
+
+    double sum = 0;
+    for (int i = 0; i < doubles.length; i++) {
+      sum += doubles[i];
+    }
+    normalize(doubles, sum);
+  }
+
+  /**
+   * Normalizes the doubles in the array using the given value.
+   *
+   * @param doubles the array of double
+   * @param sum the value by which the doubles are to be normalized
+   * @exception IllegalArgumentException if sum is zero or NaN
+   */
+  public static void normalize(double[] doubles, double sum) {
+
+    if (Double.isNaN(sum)) {
+      throw new IllegalArgumentException("Can't normalize array. Sum is NaN.");
+    }
+    if (sum == 0) {
+      // Maybe this should just be a return.
+      throw new IllegalArgumentException("Can't normalize array. Sum is zero.");
+    }
+    for (int i = 0; i < doubles.length; i++) {
+      doubles[i] /= sum;
+    }
+  }
+
+  /**
+   * Rounds a double to the next nearest integer value. The JDK version
+   * of it doesn't work properly.
+   *
+   * @param value the double value
+   * @return the resulting integer value
+   */
+  public static int round(double value) {
+
+    int roundedValue = value > 0
+      ? (int)(value + 0.5)
+      : -(int)(Math.abs(value) + 0.5);
+    
+    return roundedValue;
+  }
+
+  /**
+   * Rounds a double to the given number of decimal places.
+   *
+   * @param value the double value
+   * @param afterDecimalPoint the number of digits after the decimal point
+   * @return the double rounded to the given precision
+   */
+  public static double roundDouble(double value,int afterDecimalPoint) {
+
+    double mask = Math.pow(10.0, (double)afterDecimalPoint);
+
+    return (double)(Math.round(value * mask)) / mask;
+  }
+
+  /**
+   * Sorts a given array of integers in ascending order and returns an 
+   * array of integers with the positions of the elements of the original 
+   * array in the sorted array. The sort is stable. (Equal elements remain
+   * in their original order.)
+   *
+   * @param array this array is not changed by the method!
+   * @return an array of integers with the positions in the sorted
+   * array.
+   */
+  public static int[] sort(int [] array) {
+
+    int [] index = new int[array.length];
+    int [] newIndex = new int[array.length];
+    int [] helpIndex;
+    int numEqual;
+    
+    for (int i = 0; i < index.length; i++) {
+      index[i] = i;
+    }
+    quickSort(array, index, 0, array.length - 1);
+
+    // Make sort stable
+    int i = 0;
+    while (i < index.length) {
+      numEqual = 1;
+      for (int j = i + 1; ((j < index.length)
+			   && (array[index[i]] == array[index[j]]));
+	   j++) {
+	numEqual++;
+      }
+      if (numEqual > 1) {
+	helpIndex = new int[numEqual];
+	for (int j = 0; j < numEqual; j++) {
+	  helpIndex[j] = i + j;
+	}
+	quickSort(index, helpIndex, 0, numEqual - 1);
+	for (int j = 0; j < numEqual; j++) {
+	  newIndex[i + j] = index[helpIndex[j]];
+	}
+	i += numEqual;
+      } else {
+	newIndex[i] = index[i];
+	i++;
+      }
+    }
+    return newIndex;
+  }
+
+  /**
+   * Sorts a given array of doubles in ascending order and returns an
+   * array of integers with the positions of the elements of the
+   * original array in the sorted array. NOTE THESE CHANGES: the sort
+   * is no longer stable and it doesn't use safe floating-point
+   * comparisons anymore. Occurrences of Double.NaN are treated as 
+   * Double.MAX_VALUE
+   *
+   * @param array this array is not changed by the method!
+   * @return an array of integers with the positions in the sorted
+   * array.  
+   */
+  public static int[] sort(double [] array) {
+
+    int [] index = new int[array.length];
+    array = (double [])array.clone();
+    for (int i = 0; i < index.length; i++) {
+      index[i] = i;
+      if (Double.isNaN(array[i])) {
+        array[i] = Double.MAX_VALUE;
+      }
+    }
+    quickSort(array, index, 0, array.length - 1);
+    return index;
+  }
+
+  /**
+   * Sorts a given array of doubles in ascending order and returns an 
+   * array of integers with the positions of the elements of the original 
+   * array in the sorted array. The sort is stable (Equal elements remain
+   * in their original order.) Occurrences of Double.NaN are treated as 
+   * Double.MAX_VALUE
+   *
+   * @param array this array is not changed by the method!
+   * @return an array of integers with the positions in the sorted
+   * array.
+   */
+  public static int[] stableSort(double [] array){
+
+    int [] index = new int[array.length];
+    int [] newIndex = new int[array.length];
+    int [] helpIndex;
+    int numEqual;
+    
+    array = (double [])array.clone();
+    for (int i = 0; i < index.length; i++) {
+      index[i] = i;
+      if (Double.isNaN(array[i])) {
+        array[i] = Double.MAX_VALUE;
+      }
+    }
+    quickSort(array,index,0,array.length-1);
+
+    // Make sort stable
+
+    int i = 0;
+    while (i < index.length) {
+      numEqual = 1;
+      for (int j = i+1; ((j < index.length) && Utils.eq(array[index[i]],
+							array[index[j]])); j++)
+	numEqual++;
+      if (numEqual > 1) {
+	helpIndex = new int[numEqual];
+	for (int j = 0; j < numEqual; j++)
+	  helpIndex[j] = i+j;
+	quickSort(index, helpIndex, 0, numEqual-1);
+	for (int j = 0; j < numEqual; j++) 
+	  newIndex[i+j] = index[helpIndex[j]];
+	i += numEqual;
+      } else {
+	newIndex[i] = index[i];
+	i++;
+      }
+    }
+
+    return newIndex;
+  }
+
+  /**
+   * Computes the variance for an array of doubles.
+   *
+   * @param vector the array
+   * @return the variance
+   */
+  public static double variance(double[] vector) {
+  
+    double sum = 0, sumSquared = 0;
+
+    if (vector.length <= 1) {
+      return 0;
+    }
+    for (int i = 0; i < vector.length; i++) {
+      sum += vector[i];
+      sumSquared += (vector[i] * vector[i]);
+    }
+    return (sumSquared - (sum * sum / (double) vector.length)) / 
+      (double) (vector.length - 1);
+  }
+
+  /**
+   * Computes the sum of the elements of an array of doubles.
+   *
+   * @param doubles the array of double
+   * @returns the sum of the elements
+   */
+  public static double sum(double[] doubles) {
+
+    double sum = 0;
+
+    for (int i = 0; i < doubles.length; i++) {
+      sum += doubles[i];
+    }
+    return sum;
+  }
+
+  /**
+   * Computes the sum of the elements of an array of integers.
+   *
+   * @param ints the array of integers
+   * @returns the sum of the elements
+   */
+  public static int sum(int[] ints) {
+
+    int sum = 0;
+
+    for (int i = 0; i < ints.length; i++) {
+      sum += ints[i];
+    }
+    return sum;
+  }
+
+  /**
+   * Returns c*log2(c) for a given integer value c.
+   *
+   * @param c an integer value
+   * @returns c*log2(c) (but is careful to return 0 if c is 0)
+   */
+  public static double xlogx(int c) {
+    
+    if (c == 0) {
+      return 0.0;
+    }
+    return c * Utils.log2((double) c);
+  }
+
+  /**
+   * Implements quicksort for an array of indices.
+   *
+   * @param array the array of integers to be sorted
+   * @param index the index which should contain the positions in the
+   * sorted array
+   * @param lo0 the first index of the subset to be sorted
+   * @param hi0 the last index of the subset to be sorted
+   */
+  private static void quickSort(int [] array, int [] index,
+				int lo0, int hi0) {
+
+    int lo = lo0;
+    int hi = hi0;
+    int mid;
+    int help;
+    
+    if (hi0 > lo0) {
+      
+      // Arbitrarily establishing partition element as the midpoint of
+      // the array.
+      mid = array[index[(lo0 + hi0) / 2]];
+
+      // loop through the array until indices cross
+      while (lo <= hi) {
+	
+	// find the first element that is greater than or equal to  
+	// the partition element starting from the left Index.
+	while ((array[index[lo]] < mid) && (lo < hi0)) {
+	  ++lo;
+	}
+	
+	// find an element that is smaller than or equal to 
+	// the partition element starting from the right Index.
+	while ((array[index[hi]] > mid) && (hi > lo0)) {
+	  --hi;
+	}
+	
+	// if the indexes have not crossed, swap
+	if (lo <= hi) {
+	  help = index[lo];
+	  index[lo] = index[hi];
+	  index[hi] = help;
+	  ++lo;
+	  --hi;
+	}
+      }
+      
+      // If the right index has not reached the left side of array
+      // must now sort the left partition.
+      if (lo0 < hi) {
+	quickSort(array, index, lo0, hi);
+      }
+      
+      // If the left index has not reached the right side of array
+      // must now sort the right partition.
+      if (lo < hi0) {
+	quickSort(array, index, lo, hi0);
+      }
+    }
+  }
+
+  /**
+   * Implements unsafe quicksort for an array of indices.
+   *
+   * @param array the array of doubles to be sorted
+   * @param index the index which should contain the positions in the
+   * sorted array
+   * @param lo0 the first index of the subset to be sorted
+   * @param hi0 the last index of the subset to be sorted
+   */
+  private static void quickSort(double [] array, int [] index, int lo0, int hi0) {
+
+    int lo = lo0;
+    int hi = hi0;
+    double mid;
+    int help;
+    
+    if (hi0 > lo0) {
+      
+      // Arbitrarily establishing partition element as the midpoint of
+      // the array.
+      mid = array[index[(lo0 + hi0) / 2]];
+
+      // loop through the array until indices cross
+      while (lo <= hi) {
+	
+	// find the first element that is greater than or equal to  
+	// the partition element starting from the left Index.
+	while ((array[index[lo]] < mid) && (lo < hi0)) {
+	  ++lo;
+	}
+	
+	// find an element that is smaller than or equal to 
+	// the partition element starting from the right Index.
+	while ((array[index[hi]] > mid) && (hi > lo0)) {
+	  --hi;
+	}
+	
+	// if the indexes have not crossed, swap
+	if (lo <= hi) {
+	  help = index[lo];
+	  index[lo] = index[hi];
+	  index[hi] = help;
+	  ++lo;
+	  --hi;
+	}
+      }
+      
+      // If the right index has not reached the left side of array
+      // must now sort the left partition.
+      if (lo0 < hi) {
+	quickSort(array, index, lo0, hi);
+      }
+      
+      // If the left index has not reached the right side of array
+      // must now sort the right partition.
+      if (lo < hi0) {
+	quickSort(array, index, lo, hi0);
+      }
+    }
+  }
+
+  /**
+   * Main method for testing this class.
+   *
+   * @param ops some dummy options
+   */
+  public static void main(String[] ops) {
+
+    double[] doubles = {4.5, 6.7, Double.NaN, 3.4, 4.8, 1.2, 3.4};
+    int[] ints = {12, 6, 2, 18, 16, 6, 7, 5};
+
+    try {
+
+      // Option handling
+      System.out.println("First option split up:");
+      if (ops.length > 0) {
+	String[] firstOptionSplitUp = Utils.splitOptions(ops[0]);
+	for (int i = 0; i < firstOptionSplitUp.length; i ++) {
+	  System.out.println(firstOptionSplitUp[i]);
+	}
+      }					       
+      System.out.println("Partitioned options: ");
+      String[] partitionedOptions = Utils.partitionOptions(ops);
+      for (int i  = 0; i < partitionedOptions.length; i++) {
+	System.out.println(partitionedOptions[i]);
+      }
+      System.out.println("Get flag -f: " + Utils.getFlag('f', ops));
+      System.out.println("Get option -o: " + Utils.getOption('o', ops));
+      System.out.println("Checking for remaining options... ");
+      Utils.checkForRemainingOptions(ops);
+      
+      // Statistics
+      System.out.println("Original array (doubles): ");
+      for (int i = 0; i < doubles.length; i++) {
+	System.out.print(doubles[i] + " ");
+      }
+      System.out.println();
+      System.out.println("Original array (ints): ");
+      for (int i = 0; i < ints.length; i++) {
+	System.out.print(ints[i] + " ");
+      }
+      System.out.println();
+      System.out.println("Correlation: " + Utils.correlation(doubles, doubles, 
+							     doubles.length));
+      System.out.println("Mean: " + Utils.mean(doubles));
+      System.out.println("Variance: " + Utils.variance(doubles));
+      System.out.println("Sum (doubles): " + Utils.sum(doubles));
+      System.out.println("Sum (ints): " + Utils.sum(ints));
+      System.out.println("Max index (doubles): " + Utils.maxIndex(doubles));
+      System.out.println("Max index (ints): " + Utils.maxIndex(ints));
+      System.out.println("Min index (doubles): " + Utils.minIndex(doubles));
+      System.out.println("Min index (ints): " + Utils.minIndex(ints));
+      
+      // Sorting and normalizing
+      System.out.println("Sorted array (doubles): ");
+      int[] sorted = Utils.sort(doubles);
+      for (int i = 0; i < doubles.length; i++) {
+	System.out.print(doubles[sorted[i]] + " ");
+      }
+      System.out.println();
+      System.out.println("Normalized array (doubles): ");
+      Utils.normalize(doubles);
+      for (int i = 0; i < doubles.length; i++) {
+	System.out.print(doubles[i] + " ");
+      }
+      System.out.println();
+      System.out.println("Normalized again (doubles): ");
+      Utils.normalize(doubles, Utils.sum(doubles));
+      for (int i = 0; i < doubles.length; i++) {
+	System.out.print(doubles[i] + " ");
+      }
+      System.out.println();
+      
+      // Pretty-printing
+      System.out.println("-4.58: " + Utils.doubleToString(-4.57826535, 2));
+      System.out.println("-6.78: " + Utils.doubleToString(-6.78214234, 6,2));
+      
+      // Comparisons
+      System.out.println("5.70001 == 5.7 ? " + Utils.eq(5.70001, 5.7));
+      System.out.println("5.70001 > 5.7 ? " + Utils.gr(5.70001, 5.7));
+      System.out.println("5.70001 >= 5.7 ? " + Utils.grOrEq(5.70001, 5.7));
+      System.out.println("5.7 < 5.70001 ? " + Utils.sm(5.7, 5.70001));
+      System.out.println("5.7 <= 5.70001 ? " + Utils.smOrEq(5.7, 5.70001));
+      
+      // Math
+      System.out.println("Info (ints): " + Utils.info(ints));
+      System.out.println("log2(4.6): " + Utils.log2(4.6));
+      System.out.println("5 * log(5): " + Utils.xlogx(5));
+      System.out.println("5.5 rounded: " + Utils.round(5.5));
+      System.out.println("5.55555 rounded to 2 decimal places: " + 
+			 Utils.roundDouble(5.55555, 2));
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+}
+  
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/WeightedInstancesHandler.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/WeightedInstancesHandler.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/WeightedInstancesHandler.java	(revision 16571)
@@ -0,0 +1,43 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    WeightedInstancesHandler.java
+ *    Copyright (C) 1999 Eibe Frank
+ *
+ */
+
+package weka.core;
+
+/** 
+ * Interface to something that makes use of the information provided
+ * by instance weights.
+ *
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$ 
+*/
+public interface WeightedInstancesHandler {
+
+  // Nothing in here, because the class is just used as an indicator
+}
+
+
+
+
+
+
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/WekaException.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/WekaException.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/core/WekaException.java	(revision 16571)
@@ -0,0 +1,50 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    WekaException.java
+ *    Copyright (C) 2001 Webmind Corp.
+ */
+
+package weka.core;
+
+/**
+ * <code>WekaException</code> is used when some Weka-specific
+ * checked exception must be raised.
+ *
+ * @author <a href="mailto:len@webmind.com">Len Trigg</a>
+ * @version $Revision$
+ */
+public class WekaException extends Exception {
+
+  /**
+   * Creates a new <code>WekaException</code> instance
+   * with no detail message.
+   */
+  public WekaException() { 
+    super(); 
+  }
+
+  /**
+   * Creates a new <code>WekaException</code> instance
+   * with a specified message.
+   *
+   * @param messagae a <code>String</code> containing the message.
+   */
+  public WekaException(String message) { 
+    super(message); 
+  }
+}
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/experiment/Stats.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/experiment/Stats.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/experiment/Stats.java	(revision 16571)
@@ -0,0 +1,188 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    Stats.java
+ *    Copyright (C) 1999 Len Trigg
+ *
+ */
+
+
+package weka.experiment;
+import weka.core.Utils;
+
+/**
+ * A class to store simple statistics
+ *
+ * @author Len Trigg (trigg@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public class Stats {
+  
+  /** The number of values seen */
+  public double count = 0;
+
+  /** The sum of values seen */
+  public double sum = 0;
+
+  /** The sum of values squared seen */
+  public double sumSq = 0;
+
+  /** The std deviation of values at the last calculateDerived() call */    
+  public double stdDev = Double.NaN;
+
+  /** The mean of values at the last calculateDerived() call */    
+  public double mean = Double.NaN;
+
+  /** The minimum value seen, or Double.NaN if no values seen */
+  public double min = Double.NaN;
+
+  /** The maximum value seen, or Double.NaN if no values seen */
+  public double max = Double.NaN;
+    
+  /**
+   * Adds a value to the observed values
+   *
+   * @param value the observed value
+   */
+  public void add(double value) {
+
+    add(value, 1);
+  }
+
+  /**
+   * Adds a value that has been seen n times to the observed values
+   *
+   * @param value the observed value
+   * @param n the number of times to add value
+   */
+  public void add(double value, double n) {
+
+    sum += value * n;
+    sumSq += value * value * n;
+    count += n;
+    if (Double.isNaN(min)) {
+      min = max = value;
+    } else if (value < min) {
+      min = value;
+    } else if (value > max) {
+      max = value;
+    }
+  }
+
+  /**
+   * Removes a value to the observed values (no checking is done
+   * that the value being removed was actually added). 
+   *
+   * @param value the observed value
+   */
+  public void subtract(double value) {
+
+    sum -= value;
+    sumSq -= value * value;
+    count --;
+  }
+
+  /**
+   * Tells the object to calculate any statistics that don't have their
+   * values automatically updated during add. Currently updates the mean
+   * and standard deviation.
+   */
+  public void calculateDerived() {
+
+    mean = Double.NaN;
+    stdDev = Double.NaN;
+    if (count > 0) {
+      mean = sum / count;
+      stdDev = Double.POSITIVE_INFINITY;
+      if (count > 1) {
+	stdDev = sumSq - (sum * sum) / count;
+	stdDev /= (count - 1);
+        if (stdDev < 0) {
+          System.err.println("Warning: stdDev value = " + stdDev 
+                             + " -- rounded to zero.");
+          stdDev = 0;
+        }
+	stdDev = Math.sqrt(stdDev);
+      }
+    }
+  }
+    
+  /**
+   * Returns a string summarising the stats so far.
+   *
+   * @return the summary string
+   */
+  public String toString() {
+
+    calculateDerived();
+    return
+      "Count   " + Utils.doubleToString(count, 8) + '\n'
+      + "Min     " + Utils.doubleToString(min, 8) + '\n'
+      + "Max     " + Utils.doubleToString(max, 8) + '\n'
+      + "Sum     " + Utils.doubleToString(sum, 8) + '\n'
+      + "SumSq   " + Utils.doubleToString(sumSq, 8) + '\n'
+      + "Mean    " + Utils.doubleToString(mean, 8) + '\n'
+      + "StdDev  " + Utils.doubleToString(stdDev, 8) + '\n';
+  }
+
+  /**
+   * Tests the paired stats object from the command line.
+   * reads line from stdin, expecting two values per line.
+   *
+   * @param args ignored.
+   */
+  public static void main(String [] args) {
+
+    try {
+      Stats ps = new Stats();
+      java.io.LineNumberReader r = new java.io.LineNumberReader(
+				   new java.io.InputStreamReader(System.in));
+      String line;
+      while ((line = r.readLine()) != null) {
+        line = line.trim();
+        if (line.equals("") || line.startsWith("@") || line.startsWith("%")) {
+          continue;
+        }
+	java.util.StringTokenizer s 
+          = new java.util.StringTokenizer(line, " ,\t\n\r\f");
+	int count = 0;
+	double v1 = 0;
+	while (s.hasMoreTokens()) {
+	  double val = (new Double(s.nextToken())).doubleValue();
+	  if (count == 0) {
+	    v1 = val;
+	  } else {
+            System.err.println("MSG: Too many values in line \"" 
+                               + line + "\", skipped.");
+	    break;
+	  }
+	  count++;
+	}
+        if (count == 1) {
+          ps.add(v1);
+        }
+      }
+      ps.calculateDerived();
+      System.err.println(ps);
+    } catch (Exception ex) {
+      ex.printStackTrace();
+      System.err.println(ex.getMessage());
+    }
+  }
+
+} // Stats
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/filters/DiscretizeFilter.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/filters/DiscretizeFilter.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/filters/DiscretizeFilter.java	(revision 16571)
@@ -0,0 +1,1292 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ *    DiscretizeFilter.java
+ *    Copyright (C) 1999 Eibe Frank,Len Trigg
+ *
+ */
+
+
+package weka.filters;
+
+import java.io.*;
+import java.util.*;
+import weka.core.*;
+
+/** 
+ * An instance filter that discretizes a range of numeric attributes in 
+ * the dataset into nominal attributes. Discretization can be either by 
+ * simple binning, or by Fayyad & Irani's MDL method (the default).<p>
+ *
+ * Valid filter-specific options are: <p>
+ *
+ * -B num <br>
+ * Specifies the (maximum) number of bins to divide numeric attributes into.
+ * (default: class-based discretisation).<p>
+ *
+ * -F <br>
+ * Use equal-frequency instead of equal-width discretization if 
+ * class-based discretisation is turned off.<p>
+ *
+ * -O <br>
+ * Optimize the number of bins using a leave-one-out estimate of the 
+ * entropy (for equal-width binning).<p>
+ *
+ * -R col1,col2-col4,... <br>
+ * Specifies list of columns to Discretize. First
+ * and last are valid indexes. (default: none) <p>
+ *
+ * -V <br>
+ * Invert matching sense.<p>
+ *
+ * -D <br>
+ * Make binary nominal attributes. <p>
+ *
+ * -E <br>
+ * Use better encoding of split point for MDL. <p>
+ *   
+ * -K <br>
+ * Use Kononeko's MDL criterion. <p>
+ * 
+ * @author Len Trigg (trigg@cs.waikato.ac.nz)
+ * @author Eibe Frank (eibe@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public class DiscretizeFilter extends Filter 
+  implements OptionHandler, WeightedInstancesHandler {
+
+  /** Stores which columns to Discretize */
+  protected Range m_DiscretizeCols = new Range();
+
+  /** The number of bins to divide the attribute into */
+  protected int m_NumBins = 10;
+
+  /** Store the current cutpoints */
+  protected double [][] m_CutPoints = null;
+
+  /** True if discretisation will be done by MDL rather than binning */
+  protected boolean m_UseMDL = true;
+
+  /** Output binary attributes for discretized attributes. */
+  protected boolean m_MakeBinary = false;
+
+  /** Use better encoding of split point for MDL. */
+  protected boolean m_UseBetterEncoding = false;
+
+  /** Use Kononenko's MDL criterion instead of Fayyad et al.'s */
+  protected boolean m_UseKononenko = false;
+
+  /** Find the number of bins using cross-validated entropy. */
+  protected boolean m_FindNumBins = false;
+
+  /** Use equal-frequency binning if unsupervised discretization turned on */
+  protected boolean m_UseEqualFrequency = false;
+
+  /** Constructor - initialises the filter */
+  public DiscretizeFilter() {
+
+    setAttributeIndices("first-last");
+  }
+
+
+  /**
+   * Gets an enumeration describing the available options
+   *
+   * @return an enumeration of all the available options
+   */
+  public Enumeration listOptions() {
+
+    Vector newVector = new Vector(7);
+
+    newVector.addElement(new Option(
+              "\tSpecifies the (maximum) number of bins to divide numeric"
+	      + " attributes into.\n"
+	      + "\t(default class-based discretization)",
+              "B", 1, "-B <num>"));
+
+    newVector.addElement(new Option(
+              "\tUse equal-frequency instead of equal-width with\n"+
+	      "\tunsupervised discretization.",
+              "F", 0, "-F"));
+
+    newVector.addElement(new Option(
+              "\tOptimize number of bins using leave-one-out estimate\n"+
+	      "\tof estimated entropy (for equal-width discretization).",
+              "O", 0, "-O"));
+
+    /* If we decide to implement loading and saving cutfiles like 
+     * the C Discretizer (which is probably not necessary)
+    newVector.addElement(new Option(
+              "\tSpecify that the cutpoints should be loaded from a file.",
+              "L", 1, "-L <file>"));
+    newVector.addElement(new Option(
+              "\tSpecify that the chosen cutpoints should be saved to a file.",
+              "S", 1, "-S <file>"));
+    */
+
+    newVector.addElement(new Option(
+              "\tSpecifies list of columns to Discretize. First"
+	      + " and last are valid indexes.\n"
+	      + "\t(default none)",
+              "R", 1, "-R <col1,col2-col4,...>"));
+
+    newVector.addElement(new Option(
+              "\tInvert matching sense of column indexes.",
+              "V", 0, "-V"));
+
+    newVector.addElement(new Option(
+              "\tOutput binary attributes for discretized attributes.",
+              "D", 0, "-D"));
+
+    newVector.addElement(new Option(
+              "\tUse better encoding of split point for MDL.",
+              "E", 0, "-E"));
+
+    newVector.addElement(new Option(
+              "\tUse Kononenko's MDL criterion.",
+              "K", 0, "-K"));
+
+    return newVector.elements();
+  }
+
+
+  /**
+   * Parses the options for this object. Valid options are: <p>
+   *
+   * -B num <br>
+   * Specifies the (maximum) number of bins to divide numeric attributes into.
+   * (default class-based discretisation).<p>
+   *
+   * -F <br>
+   * Use equal-frequency instead of equal-width discretization if 
+   * class-based discretisation is turned off.<p>
+   *
+   * -O <br>
+   * Optimize the number of bins using a leave-one-out estimate of the 
+   * entropy (for equal-width binning).<p>
+   *
+   * -R col1,col2-col4,... <br>
+   * Specifies list of columns to Discretize. First
+   * and last are valid indexes. (default none) <p>
+   *
+   * -V <br>
+   * Invert matching sense.<p>
+   *
+   * -D <br>
+   * Make binary nominal attributes. <p>
+   *
+   * -E <br>
+   * Use better encoding of split point for MDL. <p>
+   *   
+   * -K <br>
+   * Use Kononeko's MDL criterion. <p>
+   * 
+   * @param options the list of options as an array of strings
+   * @exception Exception if an option is not supported
+   */
+  public void setOptions(String[] options) throws Exception {
+
+    setMakeBinary(Utils.getFlag('D', options));
+    setUseEqualFrequency(Utils.getFlag('F', options));
+    setUseBetterEncoding(Utils.getFlag('E', options));
+    setUseKononenko(Utils.getFlag('K', options));
+    setFindNumBins(Utils.getFlag('O', options));
+    setInvertSelection(Utils.getFlag('V', options));
+    setUseMDL(true);
+
+    String numBins = Utils.getOption('B', options);
+    if (numBins.length() != 0) {
+      setBins(Integer.parseInt(numBins));
+      setUseMDL(false);
+    } else {
+      setBins(10);
+    }
+    
+    String convertList = Utils.getOption('R', options);
+    if (convertList.length() != 0) {
+      setAttributeIndices(convertList);
+    } else {
+      setAttributeIndices("first-last");
+    }
+
+    if (getInputFormat() != null) {
+      setInputFormat(getInputFormat());
+    }
+  }
+  /**
+   * Gets the current settings of the filter.
+   *
+   * @return an array of strings suitable for passing to setOptions
+   */
+  public String [] getOptions() {
+
+    String [] options = new String [12];
+    int current = 0;
+
+    if (getMakeBinary()) {
+      options[current++] = "-D";
+    }
+    if (getUseEqualFrequency()) {
+      options[current++] = "-F";
+    }
+    if (getUseBetterEncoding()) {
+      options[current++] = "-E";
+    }
+    if (getUseKononenko()) {
+      options[current++] = "-K";
+    }
+    if (getFindNumBins()) {
+      options[current++] = "-O";
+    }
+    if (getInvertSelection()) {
+      options[current++] = "-V";
+    }
+    if (!getUseMDL()) {
+      options[current++] = "-B"; options[current++] = "" + getBins();
+    }
+    if (!getAttributeIndices().equals("")) {
+      options[current++] = "-R"; options[current++] = getAttributeIndices();
+    }
+    while (current < options.length) {
+      options[current++] = "";
+    }
+    return options;
+  }
+
+
+  /**
+   * Sets the format of the input instances.
+   *
+   * @param instanceInfo an Instances object containing the input instance
+   * structure (any instances contained in the object are ignored - only the
+   * structure is required).
+   * @return true if the outputFormat may be collected immediately
+   * @exception Exception if the input format can't be set successfully
+   */
+  public boolean setInputFormat(Instances instanceInfo) throws Exception {
+
+    super.setInputFormat(instanceInfo);
+
+    m_DiscretizeCols.setUpper(instanceInfo.numAttributes() - 1);
+    m_CutPoints = null;
+    if (m_UseMDL) {
+      if (instanceInfo.classIndex() < 0) {
+	throw new UnassignedClassException("Cannot use class-based discretization: "
+                                           + "no class assigned to the dataset");
+      }
+      if (!instanceInfo.classAttribute().isNominal()) {
+	throw new UnsupportedClassTypeException("Supervised discretization not possible:"
+                                                + " class is not nominal!");
+      }
+    } else {
+      if (getFindNumBins() && getUseEqualFrequency()) {
+	throw new IllegalArgumentException("Bin number optimization in conjunction "+
+					   "with equal-frequency binning not implemented.");
+      }
+    }
+
+    // If we implement loading cutfiles, then load 
+    //them here and set the output format
+    return false;
+  }
+
+  
+
+  /**
+   * Input an instance for filtering. Ordinarily the instance is processed
+   * and made available for output immediately. Some filters require all
+   * instances be read before producing output.
+   *
+   * @param instance the input instance
+   * @return true if the filtered instance may now be
+   * collected with output().
+   * @exception IllegalStateException if no input format has been defined.
+   */
+  public boolean input(Instance instance) {
+
+    if (getInputFormat() == null) {
+      throw new IllegalStateException("No input instance format defined");
+    }
+    if (m_NewBatch) {
+      resetQueue();
+      m_NewBatch = false;
+    }
+    
+    if (m_CutPoints != null) {
+      convertInstance(instance);
+      return true;
+    }
+
+    bufferInput(instance);
+    return false;
+  }
+
+
+  /**
+   * Signifies that this batch of input to the filter is finished. If the 
+   * filter requires all instances prior to filtering, output() may now 
+   * be called to retrieve the filtered instances.
+   *
+   * @return true if there are instances pending output
+   * @exception IllegalStateException if no input structure has been defined
+   */
+  public boolean batchFinished() {
+
+    if (getInputFormat() == null) {
+      throw new IllegalStateException("No input instance format defined");
+    }
+    if (m_CutPoints == null) {
+      calculateCutPoints();
+
+      setOutputFormat();
+
+      // If we implement saving cutfiles, save the cuts here
+
+      // Convert pending input instances
+      for(int i = 0; i < getInputFormat().numInstances(); i++) {
+	convertInstance(getInputFormat().instance(i));
+      }
+    } 
+    flushInput();
+
+    m_NewBatch = true;
+    return (numPendingOutput() != 0);
+  }
+
+  /**
+   * Returns a string describing this filter
+   *
+   * @return a description of the filter suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String globalInfo() {
+
+    return "An instance filter that discretizes a range of numeric"
+      + " attributes in the dataset into nominal attributes."
+      + " Discretization can be either by simple binning, or by"
+      + " Fayyad & Irani's MDL method (the default).";
+  }
+  
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String findNumBinsTipText() {
+
+    return "Optimize number of equal-width bins using leave-one-out.";
+  }
+
+  /**
+   * Get the value of FindNumBins.
+   *
+   * @return Value of FindNumBins.
+   */
+  public boolean getFindNumBins() {
+    
+    return m_FindNumBins;
+  }
+  
+  /**
+   * Set the value of FindNumBins.
+   *
+   * @param newFindNumBins Value to assign to FindNumBins.
+   */
+  public void setFindNumBins(boolean newFindNumBins) {
+    
+    m_FindNumBins = newFindNumBins;
+  }
+  
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String makeBinaryTipText() {
+
+    return "Make resulting attributes binary.";
+  }
+
+  /**
+   * Gets whether binary attributes should be made for discretized ones.
+   *
+   * @return true if attributes will be binarized
+   */
+  public boolean getMakeBinary() {
+
+    return m_MakeBinary;
+  }
+
+  /** 
+   * Sets whether binary attributes should be made for discretized ones.
+   *
+   * @param makeBinary if binary attributes are to be made
+   */
+  public void setMakeBinary(boolean makeBinary) {
+
+    m_MakeBinary = makeBinary;
+  }
+
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String useMDLTipText() {
+
+    return "Use class-based discretization. If set to false, does"
+      + " not require a class attribute, and uses a fixed number"
+      + " of bins (according to bins setting).";
+  }
+
+  /**
+   * Gets whether MDL will be used as the discretisation method.
+   *
+   * @return true if so, false if fixed bins should be used.
+   */
+  public boolean getUseMDL() {
+
+    return m_UseMDL;
+  }
+
+  /** 
+   * Sets whether MDL will be used as the discretisation method.
+   *
+   * @param useMDL true if MDL should be used, false if fixed bins should
+   * be used.
+   */
+  public void setUseMDL(boolean useMDL) {
+
+    m_UseMDL = useMDL;
+  }
+
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String useKononenkoTipText() {
+
+    return "Use Kononenko's MDL criterion. If set to false"
+      + " uses the Fayyad & Irani criterion.";
+  }
+  
+  /**
+   * Get the value of UseEqualFrequency.
+   *
+   * @return Value of UseEqualFrequency.
+   */
+  public boolean getUseEqualFrequency() {
+    
+    return m_UseEqualFrequency;
+  }
+  
+  /**
+   * Set the value of UseEqualFrequency.
+   *
+   * @param newUseEqualFrequency Value to assign to UseEqualFrequency.
+   */
+  public void setUseEqualFrequency(boolean newUseEqualFrequency) {
+    
+    m_UseEqualFrequency = newUseEqualFrequency;
+  }
+  
+  /**
+   * Gets whether Kononenko's MDL criterion is to be used.
+   *
+   * @return true if Kononenko's criterion will be used.
+   */
+  public boolean getUseKononenko() {
+
+    return m_UseKononenko;
+  }
+
+  /** 
+   * Sets whether Kononenko's MDL criterion is to be used.
+   *
+   * @param useKon true if Kononenko's one is to be used
+   */
+  public void setUseKononenko(boolean useKon) {
+
+    m_UseKononenko = useKon;
+  }
+
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String useBetterEncodingTipText() {
+
+    return "Uses a more efficient split point encoding.";
+  }
+
+  /**
+   * Gets whether better encoding is to be used for MDL.
+   *
+   * @return true if the better MDL encoding will be used
+   */
+  public boolean getUseBetterEncoding() {
+
+    return m_UseBetterEncoding;
+  }
+
+  /** 
+   * Sets whether better encoding is to be used for MDL.
+   *
+   * @param useBetterEncoding true if better encoding to be used.
+   */
+  public void setUseBetterEncoding(boolean useBetterEncoding) {
+
+    m_UseBetterEncoding = useBetterEncoding;
+  }
+
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String binsTipText() {
+
+    return "Number of bins for class-blind discretisation. This"
+      + " setting is ignored if MDL-based discretisation is used.";
+  }
+
+  /**
+   * Gets the number of bins numeric attributes will be divided into
+   *
+   * @return the number of bins.
+   */
+  public int getBins() {
+
+    return m_NumBins;
+  }
+
+  /**
+   * Sets the number of bins to divide each selected numeric attribute into
+   *
+   * @param numBins the number of bins
+   */
+  public void setBins(int numBins) {
+
+    m_NumBins = numBins;
+  }
+
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String invertSelectionTipText() {
+
+    return "Set attribute selection mode. If false, only selected"
+      + " (numeric) attributes in the range will be discretized; if"
+      + " true, only non-selected attributes will be discretized.";
+  }
+
+  /**
+   * Gets whether the supplied columns are to be removed or kept
+   *
+   * @return true if the supplied columns will be kept
+   */
+  public boolean getInvertSelection() {
+
+    return m_DiscretizeCols.getInvert();
+  }
+
+  /**
+   * Sets whether selected columns should be removed or kept. If true the 
+   * selected columns are kept and unselected columns are deleted. If false
+   * selected columns are deleted and unselected columns are kept.
+   *
+   * @param invert the new invert setting
+   */
+  public void setInvertSelection(boolean invert) {
+
+    m_DiscretizeCols.setInvert(invert);
+  }
+
+  /**
+   * Returns the tip text for this property
+   *
+   * @return tip text for this property suitable for
+   * displaying in the explorer/experimenter gui
+   */
+  public String attributeIndicesTipText() {
+    return "Specify range of attributes to act on."
+      + " This is a comma separated list of attribute indices, with"
+      + " \"first\" and \"last\" valid values. Specify an inclusive"
+      + " range with \"-\". E.g: \"first-3,5,6-10,last\".";
+  }
+
+  /**
+   * Gets the current range selection
+   *
+   * @return a string containing a comma separated list of ranges
+   */
+  public String getAttributeIndices() {
+
+    return m_DiscretizeCols.getRanges();
+  }
+
+  /**
+   * Sets which attributes are to be Discretized (only numeric
+   * attributes among the selection will be Discretized).
+   *
+   * @param rangeList a string representing the list of attributes. Since
+   * the string will typically come from a user, attributes are indexed from
+   * 1. <br>
+   * eg: first-3,5,6-last
+   * @exception IllegalArgumentException if an invalid range list is supplied 
+   */
+  public void setAttributeIndices(String rangeList) {
+
+    m_DiscretizeCols.setRanges(rangeList);
+  }
+
+  /**
+   * Sets which attributes are to be Discretized (only numeric
+   * attributes among the selection will be Discretized).
+   *
+   * @param attributes an array containing indexes of attributes to Discretize.
+   * Since the array will typically come from a program, attributes are indexed
+   * from 0.
+   * @exception IllegalArgumentException if an invalid set of ranges
+   * is supplied 
+   */
+  public void setAttributeIndicesArray(int [] attributes) {
+
+    setAttributeIndices(Range.indicesToRangeList(attributes));
+  }
+
+  /**
+   * Gets the cut points for an attribute
+   *
+   * @param the index (from 0) of the attribute to get the cut points of
+   * @return an array containing the cutpoints (or null if the
+   * attribute requested isn't being Discretized
+   */
+  public double [] getCutPoints(int attributeIndex) {
+
+    if (m_CutPoints == null) {
+      return null;
+    }
+    return m_CutPoints[attributeIndex];
+  }
+
+  /** Generate the cutpoints for each attribute */
+  protected void calculateCutPoints() {
+
+    Instances copy = null;
+
+    m_CutPoints = new double [getInputFormat().numAttributes()] [];
+    for(int i = getInputFormat().numAttributes() - 1; i >= 0; i--) {
+      if ((m_DiscretizeCols.isInRange(i)) && 
+	  (getInputFormat().attribute(i).isNumeric())) {
+	if (m_UseMDL) {
+
+	  // Use copy to preserve order
+	  if (copy == null) {
+	    copy = new Instances(getInputFormat());
+	  }
+	  calculateCutPointsByMDL(i, copy);
+	} else {
+	  if (m_FindNumBins) {
+	    findNumBins(i);
+	  } else if (!m_UseEqualFrequency) {
+	    calculateCutPointsByEqualWidthBinning(i);
+	  } else {
+	    calculateCutPointsByEqualFrequencyBinning(i);
+	  }
+	}
+      }
+    }
+  }
+
+  /**
+   * Set cutpoints for a single attribute using MDL.
+   *
+   * @param index the index of the attribute to set cutpoints for
+   */
+  protected void calculateCutPointsByMDL(int index,
+					 Instances data) {
+
+    // Sort instances
+    data.sort(data.attribute(index));
+
+    // Find first instances that's missing
+    int firstMissing = data.numInstances();
+    for (int i = 0; i < data.numInstances(); i++) {
+      if (data.instance(i).isMissing(index)) {
+        firstMissing = i;
+        break;
+      }
+    }
+    m_CutPoints[index] = cutPointsForSubset(data, index, 0, firstMissing);
+  }
+
+  /** Test using Kononenko's MDL criterion. */
+  private boolean KononenkosMDL(double[] priorCounts,
+				double[][] bestCounts,
+				double numInstances,
+				int numCutPoints) {
+
+    double distPrior, instPrior, distAfter = 0, sum, instAfter = 0;
+    double before, after;
+    int numClassesTotal;
+
+    // Number of classes occuring in the set
+    numClassesTotal = 0;
+    for (int i = 0; i < priorCounts.length; i++) {
+      if (priorCounts[i] > 0) {
+	numClassesTotal++;
+      }
+    }
+
+    // Encode distribution prior to split
+    distPrior = SpecialFunctions.log2Binomial(numInstances 
+					      + numClassesTotal - 1,
+					      numClassesTotal - 1);
+
+    // Encode instances prior to split.
+    instPrior = SpecialFunctions.log2Multinomial(numInstances,
+						 priorCounts);
+
+    before = instPrior + distPrior;
+
+    // Encode distributions and instances after split.
+    for (int i = 0; i < bestCounts.length; i++) {
+      sum = Utils.sum(bestCounts[i]);
+      distAfter += SpecialFunctions.log2Binomial(sum + numClassesTotal - 1,
+						 numClassesTotal - 1);
+      instAfter += SpecialFunctions.log2Multinomial(sum,
+						    bestCounts[i]);
+    }
+
+    // Coding cost after split
+    after = Utils.log2(numCutPoints) + distAfter + instAfter;
+
+    // Check if split is to be accepted
+    return (Utils.gr(before, after));
+  }
+
+
+  /** Test using Fayyad and Irani's MDL criterion. */
+  private boolean FayyadAndIranisMDL(double[] priorCounts,
+				     double[][] bestCounts,
+				     double numInstances,
+				     int numCutPoints) {
+
+    double priorEntropy, entropy, gain; 
+    double entropyLeft, entropyRight, delta;
+    int numClassesTotal, numClassesRight, numClassesLeft;
+
+    // Compute entropy before split.
+    priorEntropy = ContingencyTables.entropy(priorCounts);
+
+    // Compute entropy after split.
+    entropy = ContingencyTables.entropyConditionedOnRows(bestCounts);
+
+    // Compute information gain.
+    gain = priorEntropy - entropy;
+
+    // Number of classes occuring in the set
+    numClassesTotal = 0;
+    for (int i = 0; i < priorCounts.length; i++) {
+      if (priorCounts[i] > 0) {
+	numClassesTotal++;
+      }
+    }
+
+    // Number of classes occuring in the left subset
+    numClassesLeft = 0;
+    for (int i = 0; i < bestCounts[0].length; i++) {
+      if (bestCounts[0][i] > 0) {
+	numClassesLeft++;
+      }
+    }
+
+    // Number of classes occuring in the right subset
+    numClassesRight = 0;
+    for (int i = 0; i < bestCounts[1].length; i++) {
+      if (bestCounts[1][i] > 0) {
+	numClassesRight++;
+      }
+    }
+
+    // Entropy of the left and the right subsets
+    entropyLeft = ContingencyTables.entropy(bestCounts[0]);
+    entropyRight = ContingencyTables.entropy(bestCounts[1]);
+
+    // Compute terms for MDL formula
+    delta = Utils.log2(Math.pow(3, numClassesTotal) - 2) - 
+      (((double) numClassesTotal * priorEntropy) - 
+       (numClassesRight * entropyRight) - 
+       (numClassesLeft * entropyLeft));
+
+    // Check if split is to be accepted
+    return (Utils.gr(gain, (Utils.log2(numCutPoints) + delta) /
+		     (double)numInstances));
+  }
+    
+
+  /** Selects cutpoints for sorted subset. */
+  private double[] cutPointsForSubset(Instances instances, int attIndex, 
+				      int first, int lastPlusOne) { 
+
+    double[][] counts, bestCounts;
+    double[] priorCounts, left, right, cutPoints;
+    double currentCutPoint = -Double.MAX_VALUE, bestCutPoint = -1, 
+      currentEntropy, bestEntropy, priorEntropy, gain;
+    int bestIndex = -1, numInstances = 0, numCutPoints = 0;
+
+    // Compute number of instances in set
+    if ((lastPlusOne - first) < 2) {
+      return null;
+    }
+
+    // Compute class counts.
+    counts = new double[2][instances.numClasses()];
+    for (int i = first; i < lastPlusOne; i++) {
+      numInstances += instances.instance(i).weight();
+      counts[1][(int)instances.instance(i).classValue()] +=
+	instances.instance(i).weight();
+    }
+
+    // Save prior counts
+    priorCounts = new double[instances.numClasses()];
+    System.arraycopy(counts[1], 0, priorCounts, 0, 
+		     instances.numClasses());
+
+    // Entropy of the full set
+    priorEntropy = ContingencyTables.entropy(priorCounts);
+    bestEntropy = priorEntropy;
+    
+    // Find best entropy.
+    bestCounts = new double[2][instances.numClasses()];
+    for (int i = first; i < (lastPlusOne - 1); i++) {
+      counts[0][(int)instances.instance(i).classValue()] +=
+	instances.instance(i).weight();
+      counts[1][(int)instances.instance(i).classValue()] -=
+	instances.instance(i).weight();
+      if (Utils.sm(instances.instance(i).value(attIndex), 
+		   instances.instance(i + 1).value(attIndex))) {
+	currentCutPoint = instances.instance(i).value(attIndex); //+ 
+	//instances.instance(i + 1).value(attIndex)) / 2.0;
+	currentEntropy = ContingencyTables.entropyConditionedOnRows(counts);
+	if (Utils.sm(currentEntropy, bestEntropy)) {
+	  bestCutPoint = currentCutPoint;
+	  bestEntropy = currentEntropy;
+	  bestIndex = i;
+	  System.arraycopy(counts[0], 0, 
+			   bestCounts[0], 0, instances.numClasses());
+	  System.arraycopy(counts[1], 0, 
+			   bestCounts[1], 0, instances.numClasses()); 
+	}
+	numCutPoints++;
+      }
+    }
+
+    // Use worse encoding?
+    if (!m_UseBetterEncoding) {
+      numCutPoints = (lastPlusOne - first) - 1;
+    }
+
+    // Checks if gain is zero
+    gain = priorEntropy - bestEntropy;
+    if (Utils.eq(gain, 0)) {
+      return null;
+    }
+
+    // Check if split is to be accepted
+    if ((m_UseKononenko && KononenkosMDL(priorCounts, bestCounts,
+					 numInstances, numCutPoints)) ||
+	(!m_UseKononenko && FayyadAndIranisMDL(priorCounts, bestCounts,
+					       numInstances, numCutPoints))) {
+      
+      // Select split points for the left and right subsets
+      left = cutPointsForSubset(instances, attIndex, first, bestIndex + 1);
+      right = cutPointsForSubset(instances, attIndex, 
+				 bestIndex + 1, lastPlusOne);
+      
+      // Merge cutpoints and return them
+      if ((left == null) && (right) == null) {
+	cutPoints = new double[1];
+	cutPoints[0] = bestCutPoint;
+      } else if (right == null) {
+	cutPoints = new double[left.length + 1];
+	System.arraycopy(left, 0, cutPoints, 0, left.length);
+	cutPoints[left.length] = bestCutPoint;
+      } else if (left == null) {
+	cutPoints = new double[1 + right.length];
+	cutPoints[0] = bestCutPoint;
+	System.arraycopy(right, 0, cutPoints, 1, right.length);
+      } else {
+	cutPoints =  new double[left.length + right.length + 1];
+	cutPoints = new double[left.length + right.length + 1];
+	System.arraycopy(left, 0, cutPoints, 0, left.length);
+	cutPoints[left.length] = bestCutPoint;
+	System.arraycopy(right, 0, cutPoints, left.length + 1, right.length);
+      }
+      
+      return cutPoints;
+    } else
+      return null;
+  }
+ 
+  /**
+   * Set cutpoints for a single attribute.
+   *
+   * @param index the index of the attribute to set cutpoints for
+   */
+  protected void calculateCutPointsByEqualWidthBinning(int index) {
+
+    // Scan for max and min values
+    double max = 0, min = 1, currentVal;
+    Instance currentInstance;
+    for(int i = 0; i < getInputFormat().numInstances(); i++) {
+      currentInstance = getInputFormat().instance(i);
+      if (!currentInstance.isMissing(index)) {
+	currentVal = currentInstance.value(index);
+	if (max < min) {
+	  max = min = currentVal;
+	}
+	if (currentVal > max) {
+	  max = currentVal;
+	}
+	if (currentVal < min) {
+	  min = currentVal;
+	}
+      }
+    }
+    double binWidth = (max - min) / m_NumBins;
+    double [] cutPoints = null;
+    if ((m_NumBins > 1) && (binWidth > 0)) {
+      cutPoints = new double [m_NumBins - 1];
+      for(int i = 1; i < m_NumBins; i++) {
+	cutPoints[i - 1] = min + binWidth * i;
+      }
+    }
+    m_CutPoints[index] = cutPoints;
+  }
+ 
+  /**
+   * Set cutpoints for a single attribute.
+   *
+   * @param index the index of the attribute to set cutpoints for
+   */
+  protected void calculateCutPointsByEqualFrequencyBinning(int index) {
+
+    // Copy data so that it can be sorted
+    Instances data = new Instances(getInputFormat());
+
+    // Sort input data
+    data.sort(index);
+
+    // Compute weight of instances without missing values
+    double sumOfWeights = 0;
+    for (int i = 0; i < data.numInstances(); i++) {
+      if (data.instance(i).isMissing(index)) {
+	break;
+      } else {
+	sumOfWeights += data.instance(i).weight();
+      }
+    }
+    double freq = sumOfWeights / m_NumBins;
+
+    // Compute break points
+    double[] cutPoints = new double[m_NumBins - 1];
+    double counter = 0;
+    int cpindex = 0;
+    for (int i = 0; i < data.numInstances() - 1; i++) {
+
+      // Stop if value missing
+      if (data.instance(i).isMissing(index)) {
+	break;
+      }
+      counter += data.instance(i).weight();
+
+      // Do we have a potential breakpoint?
+      if (data.instance(i).value(index) < 
+	  data.instance(i + 1).value(index)) {
+	if (counter >= freq) {
+	  cutPoints[cpindex] = (data.instance(i).value(index) +
+				data.instance(i + 1).value(index)) / 2;
+	  cpindex++;
+	  counter = counter - freq;
+	}
+      }
+    }
+
+    // Did we find any cutpoints?
+    if (cpindex == 0) {
+      m_CutPoints[index] = null;
+    } else {
+      double[] cp = new double[cpindex];
+      for (int i = 0; i < cpindex; i++) {
+	cp[i] = cutPoints[i];
+      }
+      m_CutPoints[index] = cp;
+    }
+  }
+
+  /**
+   * Optimizes the number of bins using leave-one-out cross-validation.
+   *
+   * @param index the attribute index
+   */
+  protected void findNumBins(int index) {
+
+    double min = Double.MAX_VALUE, max = -Double.MIN_VALUE, binWidth = 0, 
+      entropy, bestEntropy = Double.MAX_VALUE, currentVal;
+    double[] distribution;
+    int bestNumBins  = 1;
+    Instance currentInstance;
+
+    // Find minimum and maximum
+    for (int i = 0; i < getInputFormat().numInstances(); i++) {
+      currentInstance = getInputFormat().instance(i);
+      if (!currentInstance.isMissing(index)) {
+	currentVal = currentInstance.value(index);
+	if (currentVal > max) {
+	  max = currentVal;
+	}
+	if (currentVal < min) {
+	  min = currentVal;
+	}
+      }
+    }
+
+    // Find best number of bins
+    for (int i = 0; i < m_NumBins; i++) {
+      distribution = new double[i + 1];
+      binWidth = (max - min) / (i + 1);
+
+      // Compute distribution
+      for (int j = 0; j < getInputFormat().numInstances(); j++) {
+	currentInstance = getInputFormat().instance(j);
+	if (!currentInstance.isMissing(index)) {
+	  for (int k = 0; k < i + 1; k++) {
+	    if (currentInstance.value(index) <= 
+		(min + (((double)k + 1) * binWidth))) {
+	      distribution[k] += currentInstance.weight();
+	      break;
+	    }
+	  }
+	}
+      }
+
+      // Compute cross-validated entropy
+      entropy = 0;
+      for (int k = 0; k < i + 1; k++) {
+	if (distribution[k] < 2) {
+	  entropy = Double.MAX_VALUE;
+	  break;
+	}
+	entropy -= distribution[k] * Math.log((distribution[k] - 1) / 
+					      binWidth);
+      }
+
+      // Best entropy so far?
+      if (entropy < bestEntropy) {
+	bestEntropy = entropy;
+	bestNumBins = i + 1;
+      }
+    }
+
+    // Compute cut points
+    double [] cutPoints = null;
+    if ((bestNumBins > 1) && (binWidth > 0)) {
+      cutPoints = new double [bestNumBins - 1];
+      for(int i = 1; i < bestNumBins; i++) {
+	cutPoints[i - 1] = min + binWidth * i;
+      }
+    }
+    m_CutPoints[index] = cutPoints;
+   }
+
+  /**
+   * Set the output format. Takes the currently defined cutpoints and 
+   * m_InputFormat and calls setOutputFormat(Instances) appropriately.
+   */
+  protected void setOutputFormat() {
+
+    if (m_CutPoints == null) {
+      setOutputFormat(null);
+      return;
+    }
+    FastVector attributes = new FastVector(getInputFormat().numAttributes());
+    int classIndex = getInputFormat().classIndex();
+    for(int i = 0; i < getInputFormat().numAttributes(); i++) {
+      if ((m_DiscretizeCols.isInRange(i)) 
+	  && (getInputFormat().attribute(i).isNumeric())) {
+	if (!m_MakeBinary) {
+	  FastVector attribValues = new FastVector(1);
+	  if (m_CutPoints[i] == null) {
+	    attribValues.addElement("'All'");
+	  } else {
+	    for(int j = 0; j <= m_CutPoints[i].length; j++) {
+	      if (j == 0) {
+		attribValues.addElement("'(-inf-"
+			+ Utils.doubleToString(m_CutPoints[i][j], 6) + "]'");
+	      } else if (j == m_CutPoints[i].length) {
+		attribValues.addElement("'("
+			+ Utils.doubleToString(m_CutPoints[i][j - 1], 6) 
+					+ "-inf)'");
+	      } else {
+		attribValues.addElement("'("
+			+ Utils.doubleToString(m_CutPoints[i][j - 1], 6) + "-"
+			+ Utils.doubleToString(m_CutPoints[i][j], 6) + "]'");
+	      }
+	    }
+	  }
+	  attributes.addElement(new Attribute(getInputFormat().
+					      attribute(i).name(),
+					      attribValues));
+	} else {
+	  if (m_CutPoints[i] == null) {
+	    FastVector attribValues = new FastVector(1);
+	    attribValues.addElement("'All'");
+	    attributes.addElement(new Attribute(getInputFormat().
+						attribute(i).name(),
+						attribValues));
+	  } else {
+	    if (i < getInputFormat().classIndex()) {
+	      classIndex += m_CutPoints[i].length - 1;
+	    }
+	    for(int j = 0; j < m_CutPoints[i].length; j++) {
+	      FastVector attribValues = new FastVector(2);
+	      attribValues.addElement("'(-inf-"
+		      + Utils.doubleToString(m_CutPoints[i][j], 6) + "]'");
+	      attribValues.addElement("'("
+		      + Utils.doubleToString(m_CutPoints[i][j], 6) + "-inf)'");
+	      attributes.addElement(new Attribute(getInputFormat().
+						  attribute(i).name(),
+						  attribValues));
+	    }
+	  }
+	}
+      } else {
+	attributes.addElement(getInputFormat().attribute(i).copy());
+      }
+    }
+    Instances outputFormat = 
+      new Instances(getInputFormat().relationName(), attributes, 0);
+    outputFormat.setClassIndex(classIndex);
+    setOutputFormat(outputFormat);
+  }
+
+  /**
+   * Convert a single instance over. The converted instance is added to 
+   * the end of the output queue.
+   *
+   * @param instance the instance to convert
+   */
+  protected void convertInstance(Instance instance) {
+
+    int index = 0;
+    double [] vals = new double [outputFormatPeek().numAttributes()];
+    // Copy and convert the values
+    for(int i = 0; i < getInputFormat().numAttributes(); i++) {
+      if (m_DiscretizeCols.isInRange(i) && 
+	  getInputFormat().attribute(i).isNumeric()) {
+	int j;
+	double currentVal = instance.value(i);
+	if (m_CutPoints[i] == null) {
+	  if (instance.isMissing(i)) {
+	    vals[index] = Instance.missingValue();
+	  } else {
+	    vals[index] = 0;
+	  }
+	  index++;
+	} else {
+	  if (!m_MakeBinary) {
+	    if (instance.isMissing(i)) {
+	      vals[index] = Instance.missingValue();
+	    } else {
+	      for (j = 0; j < m_CutPoints[i].length; j++) {
+		if (currentVal <= m_CutPoints[i][j]) {
+		  break;
+		}
+	      }
+              vals[index] = j;
+	    }
+	    index++;
+	  } else {
+	    for (j = 0; j < m_CutPoints[i].length; j++) {
+	      if (instance.isMissing(i)) {
+                vals[index] = Instance.missingValue();
+	      } else if (currentVal <= m_CutPoints[i][j]) {
+                vals[index] = 0;
+	      } else {
+                vals[index] = 1;
+	      }
+	      index++;
+	    }
+	  }   
+	}
+      } else {
+        vals[index] = instance.value(i);
+	index++;
+      }
+    }
+    
+    Instance inst = null;
+    if (instance instanceof SparseInstance) {
+      inst = new SparseInstance(instance.weight(), vals);
+    } else {
+      inst = new Instance(instance.weight(), vals);
+    }
+    copyStringValues(inst, false, instance.dataset(), getInputStringIndex(),
+                     getOutputFormat(), getOutputStringIndex());
+    inst.setDataset(getOutputFormat());
+    push(inst);
+  }
+
+  /**
+   * Main method for testing this class.
+   *
+   * @param argv should contain arguments to the filter: use -h for help
+   */
+  public static void main(String [] argv) {
+
+    try {
+      if (Utils.getFlag('b', argv)) {
+ 	Filter.batchFilterFile(new DiscretizeFilter(), argv);
+      } else {
+	Filter.filterFile(new DiscretizeFilter(), argv);
+      }
+    } catch (Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+  }
+}
+
+
+
+
+
+
+
+
Index: /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/filters/Filter.java
===================================================================
--- /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/filters/Filter.java	(revision 16571)
+++ /gsdl/trunk/build-src/packages/kea/kea-3.0/weka/filters/Filter.java	(revision 16571)
@@ -0,0 +1,934 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+/*
+ *    Filter.java
+ *    Copyright (C) 1999 Len Trigg
+ *
+ */
+
+
+package weka.filters;
+
+import java.io.BufferedReader;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.Serializable;
+import java.util.Enumeration;
+import weka.core.Attribute;
+import weka.core.Instance;
+import weka.core.Instances;
+import weka.core.Option;
+import weka.core.OptionHandler;
+import weka.core.Queue;
+import weka.core.Utils;
+
+/** 
+ * An abstract class for instance filters: objects that take instances
+ * as input, carry out some transformation on the instance and then
+ * output the instance. The method implementations in this class
+ * assume that most of the work will be done in the methods overridden
+ * by subclasses.<p>
+ *
+ * A simple example of filter use. This example doesn't remove
+ * instances from the output queue until all instances have been
+ * input, so has higher memory consumption than an approach that
+ * uses output instances as they are made available:<p>
+ *
+ * <code> <pre>
+ *  Filter filter = ..some type of filter..
+ *  Instances instances = ..some instances..
+ *  for (int i = 0; i < data.numInstances(); i++) {
+ *    filter.input(data.instance(i));
+ *  }
+ *  filter.batchFinished();
+ *  Instances newData = filter.outputFormat();
+ *  Instance processed;
+ *  while ((processed = filter.output()) != null) {
+ *    newData.add(processed);
+ *  }
+ *  ..do something with newData..
+ * </pre> </code>
+ *
+ * @author Len Trigg (trigg@cs.waikato.ac.nz)
+ * @version $Revision$
+ */
+public abstract class Filter implements Serializable {
+
+  /*
+   * Filter refactoring TODO:
+   *
+   * - Update all filters to use getOutputFormat and setInputFormat
+   * instead of outputFormat, outputFormatPeek and inputFormat.
+   * - Update users of filters to use getOutputFormat and setInputFormat
+   * - remove outputFormat, outputFormatPeek and inputFormat
+   *
+   */
+
+  /** Debugging mode */
+  private boolean m_Debug = false;
+
+  /** The output format for instances */
+  private Instances m_OutputFormat = null;
+
+  /** The output instance queue */
+  private Queue m_OutputQueue = null;
+
+  /** Indices of string attributes in the output format */
+  private int [] m_OutputStringAtts = null;
+
+  /** Indices of string attributes in the input format */
+  private int [] m_InputStringAtts = null;
+
+  /** The input format for instances */
+  private Instances m_InputFormat = null;
+
+  /** Record whether the filter is at the start of a batch */
+  protected boolean m_NewBatch = true;
+
+  /**
+   * Sets the format of output instances. The derived class should use this
+   * method once it has determined the outputformat. The 
+   * output queue is cleared.
+   *
+   * @param outputFormat the new output format
+   */
+  protected void setOutputFormat(Instances outputFormat) {
+
+    if (outputFormat != null) {
+      m_OutputFormat = outputFormat.stringFreeStructure();
+      m_OutputStringAtts = getStringIndices(m_OutputFormat);
+
+      // Rename the attribute
+      String relationName = outputFormat.relationName() 
+        + "-" + this.getClass().getName();
+      if (this instanceof OptionHandler) {
+        String [] options = ((OptionHandler)this).getOptions();
+        for (int i = 0; i < options.length; i++) {
+          relationName += options[i].trim();
+        }
+      }
+      m_OutputFormat.setRelationName(relationName);
+    } else {
+      m_OutputFormat = null;
+    }
+    m_OutputQueue = new Queue();
+  }
+
+  /**
+   * Gets the currently set inputformat instances. This dataset may contain
+   * buffered instances.
+   *
+   * @return the input Instances.
+   */
+  protected Instances getInputFormat() {
+
+    return m_InputFormat;
+  }
+
+  /**
+   * Returns a reference to the current output format without
+   * copying it.
+   *
+   * @return a reference to the current output format
+   */
+  protected Instances outputFormatPeek() {
+
+    return m_OutputFormat;
+  }
+
+  /**
+   * Adds an output instance to the queue. The derived class should use this
+   * method for each output instance it makes available. 
+   *
+   * @param instance the instance to be added to the queue
+   */
+  protected void push(Instance instance) {
+
+    if (instance != null) {
+      copyStringValues(instance, m_OutputFormat, m_OutputStringAtts);
+      instance.setDataset(m_OutputFormat);
+      m_OutputQueue.push(instance);
+    }
+  }
+
+  /**
+   * Clears the output queue.
+   */
+  protected void resetQueue() {
+
+    m_OutputQueue = new Queue();
+  }
+
+  /**
+   * Adds the supplied input instance to the inputformat dataset for
+   * later processing.  Use this method rather than
+   * getInputFormat().add(instance). Or else.
+   *
+   * @param instance the <code>Instance</code> to buffer.  
+   */
+  protected void bufferInput(Instance instance) {
+
+    if (instance != null) {
+      copyStringValues(instance, m_InputFormat, m_InputStringAtts);
+      instance.setDataset(m_InputFormat);
+      m_InputFormat.add(instance);
+    }
+  }
+
+  /**
+   * Returns an array containing the indices of all string attributes in the
+   * input format. This index is created during setInputFormat()
+   *
+   * @return an array containing the indices of string attributes in the 
+   * input dataset.
+   */
+  protected int [] getInputStringIndex() {
+
+    return m_InputStringAtts;
+  }
+
+  /**
+   * Returns an array containing the indices of all string attributes in the
+   * output format. This index is created during setOutputFormat()
+   *
+   * @return an array containing the indices of string attributes in the 
+   * output dataset.
+   */
+  protected int [] getOutputStringIndex() {
+
+    return m_OutputStringAtts;
+  }
+
+  /**
+   * Copies string values contained in the instance copied to a new
+   * dataset. The Instance must already be assigned to a dataset. This
+   * dataset and the destination dataset must have the same structure.
+   *
+   * @param instance the Instance containing the string values to copy.
+   * @param destDataset the destination set of Instances
+   * @param strAtts an array containing the indices of any string attributes
+   * in the dataset.  
+   */
+  private void copyStringValues(Instance inst, Instances destDataset, 
+                                int []strAtts) {
+
+    if (strAtts.length == 0) {
+      return;
+    }
+    if (inst.dataset() == null) {
+      throw new IllegalArgumentException("Instance has no dataset assigned!!");
+    } else if (inst.dataset().numAttributes() != destDataset.numAttributes()) {
+      throw new IllegalArgumentException("Src and Dest differ in # of attributes!!");
+    } 
+    copyStringValues(inst, true, inst.dataset(), strAtts,
+                     destDataset, strAtts);
+  }
+
+  /**
+   * Takes string values referenced by an Instance and copies them from a
+   * source dataset to a destination dataset. The instance references are
+   * updated to be valid for the destination dataset. The instance may have the 
+   * structure (i.e. number and attribute position) of either dataset (this
+   * affects where references are obtained from). The source dataset must
+   * have the same structure as the filter input format and the destination
+   * must have the same structure as the filter output format.
+   *
+   * @param instance the instance containing references to strings in the source
+   * dataset that will have references updated to be valid for the destination
+   * dataset.
+   * @param instSrcCompat true if the instance structure is the same as the
+   * source, or false if it is the same as the destination
+   * @param srcDataset the dataset for which the current instance string
+   * references are valid (after any position mapping if needed)
+   * @param destDataset the dataset for which the current instance string
+   * references need to be inserted (after any position mapping if needed)
+   */
+  protected void copyStringValues(Instance instance, boolean instSrcCompat,
+                                  Instances srcDataset, Instances destDataset) {
+
+    copyStringValues(instance, instSrcCompat, srcDataset, m_InputStringAtts,
+                     destDataset, m_OutputStringAtts);
+  }
+
+  /**
+   * Takes string values referenced by an Instance and copies them from a
+   * source dataset to a destination dataset. The instance references are
+   * updated to be valid for the destination dataset. The instance may have the 
+   * structure (i.e. number and attribute position) of either dataset (this
+   * affects where references are obtained from). Only works if the number
+   * of string attributes is the same in both indices (implicitly these string
+   * attributes should be semantically same but just with shifted positions).
+   *
+   * @param instance the instance containing references to strings in the source
+   * dataset that will have references updated to be valid for the destination
+   * dataset.
+   * @param instSrcCompat true if the instance structure is the same as the
+   * source, or false if it is the same as the destination (i.e. which of the
+   * string attribute indices contains the correct locations for this instance).
+   * @param srcDataset the dataset for which the current instance string
+   * references are valid (after any position mapping if needed)
+   * @param srcStrAtts an array containing the indices of string attributes
+   * in the source datset.
+   * @param destDataset the dataset for which the current instance string
+   * references need to be inserted (after any position mapping if needed)
+   * @param destStrAtts an array containing the indices of string attributes
+   * in the destination datset.
+   */
+  protected void copyStringValues(Instance instance, boolean instSrcCompat,
+                                  Instances srcDataset, int []srcStrAtts,
+                                  Instances destDataset, int []destStrAtts) {
+    if (srcDataset == destDataset) {
+      return;
+    }
+    if (srcStrAtts.length != destStrAtts.length) {
+      throw new IllegalArgumentException("Src and Dest string indices differ in length!!");
+    }
+    for (int i = 0; i < srcStrAtts.length; i++) {
+      int instIndex = instSrcCompat ? srcStrAtts[i] : destStrAtts[i];
+      Attribute src = srcDataset.attribute(srcStrAtts[i]);
+      Attribute dest = destDataset.attribute(destStrAtts[i]);
+      if (!instance.isMissing(instIndex)) {
+        //System.err.println(instance.value(srcIndex) 
+        //                   + " " + src.numValues()
+        //                   + " " + dest.numValues());
+        int valIndex = dest.addStringValue(src, (int)instance.value(instIndex));
+        // setValue here shouldn't be too slow here unless your dataset has
+        // squillions of string attributes
+        instance.setValue(instIndex, (double)valIndex);
+      }
+    }
+  }
+
+  /**
+   * This will remove all buffered instances from the inputformat dataset.
+   * Use this method rather than getInputFormat().delete();
+   */
+  protected void flushInput() {
+
+    if (m_InputStringAtts.length > 0) {
+      m_InputFormat = m_InputFormat.stringFreeStructure();
+    } else {
+      // This more efficient than new Instances(m_InputFormat, 0);
+      m_InputFormat.delete();
+    }
+  }
+
+  /**
+   * @deprecated use <code>setInputFormat(Instances)</code> instead.
+   */
+  public boolean inputFormat(Instances instanceInfo) throws Exception {
+
+    return setInputFormat(instanceInfo);
+  }
+
+  /**
+   * Sets the format of the input instances. If the filter is able to
+   * determine the output format before seeing any input instances, it
+   * does so here. This default implementation clears the output format
+   * and output queue, and the new batch flag is set. Overriders should
+   * call <code>super.setInputFormat(Instances)</code>
+   *
+   * @param instanceInfo an Instances object containing the input instance
+   * structure (any instances contained in the object are ignored - only the
+   * structure is required).
+   * @return true if the outputFormat may be collected immediately
+   * @exception Exception if the inputFormat can't be set successfully 
+   */
+  public boolean setInputFormat(Instances instanceInfo) throws Exception {
+
+    m_InputFormat = instanceInfo.stringFreeStructure();
+    m_InputStringAtts = getStringIndices(instanceInfo);
+    m_OutputFormat = null;
+    m_OutputQueue = new Queue();
+    m_NewBatch = true;
+    return false;
+  }
+
+  /**
+   * @deprecated use <code>getOutputFormat()</code> instead.
+   */
+  public final Instances outputFormat() {
+
+    return getOutputFormat();
+  }
+
+  /**
+   * Gets the format of the output instances. This should only be called
+   * after input() or batchFinished() has returned true. The relation
+   * name of the output instances should be changed to reflect the
+   * action of the filter (eg: add the filter name and options).
+   *
+   * @return an Instances object containing the output instance
+   * structure only.
+   * @exception NullPointerException if no input structure has been
+   * defined (or the output format hasn't been determined yet) 
+   */
+  public final Instances getOutputFormat() {
+
+    if (m_OutputFormat == null) {
+      throw new NullPointerException("No output format defined.");
+    }
+    return new Instances(m_OutputFormat, 0);
+  }
+
+  /**
+   * Input an instance for filtering. Ordinarily the instance is
+   * processed and made available for output immediately. Some filters
+   * require all instances be read before producing output, in which
+   * case output instances should be collected after calling
+   * batchFinished(). If the input marks the start of a new batch, the
+   * output queue is cleared. This default implementation assumes all
+   * instance conversion will occur when batchFinished() is called.
+   *
+   * @param instance the input instance
+   * @return true if the filtered instance may now be
+   * collected with output().
+   * @exception NullPointerException if the input format has not been
+   * defined.
+   * @exception Exception if the input instance was not of the correct 
+   * format or if there was a problem with the filtering.  
+   */
+  public boolean input(Instance instance) throws Exception {
+
+    if (m_InputFormat == null) {
+      throw new NullPointerException("No input instance format defined");
+    }
+    if (m_NewBatch) {
+      m_OutputQueue = new Queue();
+      m_NewBatch = false;
+    }
+    bufferInput(instance);
+    return false;
+  }
+
+  /**
+   * Signify that this batch of input to the filter is finished. If
+   * the filter requires all instances prior to filtering, output()
+   * may now be called to retrieve the filtered instances. Any
+   * subsequent instances filtered should be filtered based on setting
+   * obtained from the first batch (unless the inputFormat has been
+   * re-assigned or new options have been set). This default
+   * implementation assumes all instance processing occurs during
+   * inputFormat() and input().
+   *
+   * @return true if there are instances pending output
+   * @exception NullPointerException if no input structure has been defined,
+   * @exception Exception if there was a problem finishing the batch.
+   */
+  public boolean batchFinished() throws Exception {
+
+    if (m_InputFormat == null) {
+      throw new NullPointerException("No input instance format defined");
+    }
+    flushInput();
+    m_NewBatch = true;
+    return (numPendingOutput() != 0);
+  }
+
+
+  /**
+   * Output an instance after filtering and remove from the output queue.
+   *
+   * @return the instance that has most recently been filtered (or null if
+   * the queue is empty).
+   * @exception NullPointerException if no output structure has been defined
+   */
+  public Instance output() {
+
+    if (m_OutputFormat == null) {
+      throw new NullPointerException("No output instance format defined");
+    }
+    if (m_OutputQueue.empty()) {
+      return null;
+    }
+    Instance result = (Instance)m_OutputQueue.pop();
+    // Clear out references to old strings occasionally
+    if (m_OutputQueue.empty() && m_NewBatch) {
+      if (m_OutputStringAtts.length > 0) {
+        m_OutputFormat = m_OutputFormat.stringFreeStructure();
+      }
+    }
+    return result;
+  }
+  
+  /**
+   * Output an instance after filtering but do not remove from the
+   * output queue.
+   *
+   * @return the instance that has most recently been filtered (or null if
+   * the queue is empty).
+   * @exception NullPointerException if no input structure has been defined 
+   */
+  public Instance outputPeek() {
+
+    if (m_OutputFormat == null) {
+      throw new NullPointerException("No output instance format defined");
+    }
+    if (m_OutputQueue.empty()) {
+      return null;
+    }
+    Instance result = (Instance)m_OutputQueue.peek();
+    return result;
+  }
+
+  /**
+   * Returns the number of instances pending output
+   *
+   * @return the number of instances  pending output
+   * @exception NullPointerException if no input structure has been defined
+   */
+  public int numPendingOutput() {
+
+    if (m_OutputFormat == null) {
+      throw new NullPointerException("No output instance format defined");
+    }
+    return m_OutputQueue.size();
+  }
+
+  /**
+   * Returns whether the output format is ready to be collected
+   *
+   * @return true if the output format is set
+   */
+  public boolean isOutputFormatDefined() {
+
+    return (m_OutputFormat != null);
+  }
+
+  /**
+   * Gets an array containing the indices of all string attributes.
+   *
+   * @param insts the Instances to scan for string attributes. 
+   * @return an array containing the indices of string attributes in
+   * the input structure. Will be zero-length if there are no
+   * string attributes
+   */
+  protected int [] getStringIndices(Instances insts) {
+    
+    // Scan through getting the indices of String attributes
+    int [] index = new int [insts.numAttributes()];
+    int indexSize = 0;
+    for (int i = 0; i < insts.numAttributes(); i++) {
+      if (insts.attribute(i).type() == Attribute.STRING) {
+        index[indexSize++] = i;
+      }
+    }
+    int [] result = new int [indexSize];
+    System.arraycopy(index, 0, result, 0, indexSize);
+    return result;
+  }
+  
+  /**
+   * Filters an entire set of instances through a filter and returns
+   * the new set. 
+   *
+   * @param data the data to be filtered
+   * @param filter the filter to be used
+   * @return the filtered set of data
+   * @exception Exception if the filter can't be used successfully
+   */
+  public static Instances useFilter(Instances data,
+				    Filter filter) throws Exception {
+    /*
+    System.err.println(filter.getClass().getName() 
+                       + " in:" + data.numInstances());
+    */
+    for (int i = 0; i < data.numInstances(); i++) {
+      filter.input(data.instance(i));
+    }
+    filter.batchFinished();
+    Instances newData = filter.getOutputFormat();
+    Instance processed;
+    while ((processed = filter.output()) != null) {
+      newData.add(processed);
+    }
+
+    /*
+    System.err.println(filter.getClass().getName() 
+                       + " out:" + newData.numInstances());
+    */
+    return newData;
+  }
+
+  /**
+   * Method for testing filters.
+   *
+   * @param argv should contain the following arguments: <br>
+   * -i input_file <br>
+   * -o output_file <br>
+   * -c class_index <br>
+   * or -h for help on options
+   * @exception Exception if something goes wrong or the user requests help on
+   * command options
+   */
+  public static void filterFile(Filter filter, String [] options) 
+    throws Exception {
+
+    boolean debug = false;
+    Instances data = null;
+    Reader input = null;
+    PrintWriter output = null;
+    boolean helpRequest;
+
+    try {
+       helpRequest = Utils.getFlag('h', options);
+
+      if (Utils.getFlag('d', options)) {
+	debug = true;
+      }
+      String infileName = Utils.getOption('i', options);
+      String outfileName = Utils.getOption('o', options); 
+      String classIndex = Utils.getOption('c', options);
+      
+      if (filter instanceof OptionHandler) {
+	((OptionHandler)filter).setOptions(options);
+      }
+
+      Utils.checkForRemainingOptions(options);
+      if (helpRequest) {
+	throw new Exception("Help requested.\n");
+      }
+      if (infileName.length() != 0) {
+	input = new BufferedReader(new FileReader(infileName));
+      } else {
+	input = new BufferedReader(new InputStreamReader(System.in));
+      }
+      if (outfileName.length() != 0) {
+	output = new PrintWriter(new FileOutputStream(outfileName));
+      } else { 
+	output = new PrintWriter(System.out);
+      }
+
+      data = new Instances(input, 1);
+      if (classIndex.length() != 0) {
+	if (classIndex.equals("first")) {
+	  data.setClassIndex(0);
+	} else if (classIndex.equals("last")) {
+	  data.setClassIndex(data.numAttributes() - 1);
+	} else {
+	  data.setClassIndex(Integer.parseInt(classIndex) - 1);
+	}
+      }
+    } catch (Exception ex) {
+      String filterOptions = "";
+      // Output the error and also the valid options
+      if (filter instanceof OptionHandler) {
+	filterOptions += "\nFilter options:\n\n";
+	Enumeration enum = ((OptionHandler)filter).listOptions();
+	while (enum.hasMoreElements()) {
+	  Option option = (Option) enum.nextElement();
+	  filterOptions += option.synopsis() + '\n'
+	    + option.description() + "\n";
+	}
+      }
+
+      String genericOptions = "\nGeneral options:\n\n"
+	+ "-h\n"
+	+ "\tGet help on available options.\n"
+	+ "\t(use -b -h for help on batch mode.)\n"
+	+ "-i <file>\n"
+	+ "\tThe name of the file containing input instances.\n"
+	+ "\tIf not supplied then instances will be read from stdin.\n"
+	+ "-o <file>\n"
+	+ "\tThe name of the file output instances will be written to.\n"
+	+ "\tIf not supplied then instances will be written to stdout.\n"
+	+ "-c <class index>\n"
+	+ "\tThe number of the attribute to use as the class.\n"
+	+ "\t\"first\" and \"last\" are also valid entries.\n"
+	+ "\tIf not supplied then no class is assigned.\n";
+
+      throw new Exception('\n' + ex.getMessage()
+			  + filterOptions+genericOptions);
+    }
+    
+    if (debug) {
+      System.err.println("Setting input format");
+    }
+    boolean printedHeader = false;
+    if (filter.setInputFormat(data)) {
+      if (debug) {
+	System.err.println("Getting output format");
+      }
+      output.println(filter.getOutputFormat().toString());
+      printedHeader = true;
+    }
+    
+    // Pass all the instances to the filter
+    while (data.readInstance(input)) {
+      if (debug) {
+	System.err.println("Input instance to filter");
+      }
+      if (filter.input(data.instance(0))) {
+	if (debug) {
+	  System.err.println("Filter said collect immediately");
+	}
+	if (!printedHeader) {
+	  throw new Error("Filter didn't return true from setInputFormat() "
+			  + "earlier!");
+	}
+	if (debug) {
+	  System.err.println("Getting output instance");
+	}
+	output.println(filter.output().toString());
+      }
+      data.delete(0);
+    }
+    
+    // Say that input has finished, and print any pending output instances
+    if (debug) {
+      System.err.println("Setting end of batch");
+    }
+    if (filter.batchFinished()) {
+      if (debug) {
+	System.err.println("Filter said collect output");
+      }
+      if (!printedHeader) {
+	if (debug) {
+	  System.err.println("Getting output format");
+	}
+	output.println(filter.getOutputFormat().toString());
+      }
+      if (debug) {
+	System.err.println("Getting output instance");
+      }
+      while (filter.numPendingOutput() > 0) {
+	output.println(filter.output().toString());
+	if (debug){
+	  System.err.println("Getting output instance");
+	}
+      }
+    }
+    if (debug) {
+      System.err.println("Done");
+    }
+    
+    if (output != null) {
+      output.close();
+    }
+  }
+
+  /**
+   * Method for testing filters ability to process multiple batches.
+   *
+   * @param argv should contain the following arguments:<br>
+   * -i (first) input file <br>
+   * -o (first) output file <br>
+   * -r (second) input file <br>
+   * -s (second) output file <br>
+   * -c class_index <br>
+   * or -h for help on options
+   * @exception Exception if something goes wrong or the user requests help on
+   * command options
+   */
+  public static void batchFilterFile(Filter filter, String [] options) 
+    throws Exception {
+
+    Instances firstData = null;
+    Instances secondData = null;
+    Reader firstInput = null;
+    Reader secondInput = null;
+    PrintWriter firstOutput = null;
+    PrintWriter secondOutput = null;
+    boolean helpRequest;
+    try {
+      helpRequest = Utils.getFlag('h', options);
+
+      String fileName = Utils.getOption('i', options); 
+      if (fileName.length() != 0) {
+	firstInput = new BufferedReader(new FileReader(fileName));
+      } else {
+	throw new Exception("No first input file given.\n");
+      }
+
+      fileName = Utils.getOption('r', options); 
+      if (fileName.length() != 0) {
+	secondInput = new BufferedReader(new FileReader(fileName));
+      } else {
+	throw new Exception("No second input file given.\n");
+      }
+
+      fileName = Utils.getOption('o', options); 
+      if (fileName.length() != 0) {
+	firstOutput = new PrintWriter(new FileOutputStream(fileName));
+      } else {
+	firstOutput = new PrintWriter(System.out);
+      }
+      
+      fileName = Utils.getOption('s', options); 
+      if (fileName.length() != 0) {
+	secondOutput = new PrintWriter(new FileOutputStream(fileName));
+      } else {
+	secondOutput = new PrintWriter(System.out);
+      }
+      String classIndex = Utils.getOption('c', options);
+
+      if (filter instanceof OptionHandler) {
+	((OptionHandler)filter).setOptions(options);
+      }
+      Utils.checkForRemainingOptions(options);
+      
+      if (helpRequest) {
+	throw new Exception("Help requested.\n");
+      }
+      firstData = new Instances(firstInput, 1);
+      secondData = new Instances(secondInput, 1);
+      if (!secondData.equalHeaders(firstData)) {
+	throw new Exception("Input file formats differ.\n");
+      }
+      if (classIndex.length() != 0) {
+	if (classIndex.equals("first")) {
+	  firstData.setClassIndex(0);
+	  secondData.setClassIndex(0);
+	} else if (classIndex.equals("last")) {
+	  firstData.setClassIndex(firstData.numAttributes() - 1);
+	  secondData.setClassIndex(secondData.numAttributes() - 1);
+	} else {
+	  firstData.setClassIndex(Integer.parseInt(classIndex) - 1);
+	  secondData.setClassIndex(Integer.parseInt(classIndex) - 1);
+	}
+      }
+    } catch (Exception ex) {
+      String filterOptions = "";
+      // Output the error and also the valid options
+      if (filter instanceof OptionHandler) {
+	filterOptions += "\nFilter options:\n\n";
+	Enumeration enum = ((OptionHandler)filter).listOptions();
+	while (enum.hasMoreElements()) {
+	  Option option = (Option) enum.nextElement();
+	  filterOptions += option.synopsis() + '\n'
+	    + option.description() + "\n";
+	}
+      }
+
+      String genericOptions = "\nGeneral options:\n\n"
+	+ "-h\n"
+	+ "\tGet help on available options.\n"
+	+ "-i <filename>\n"
+	+ "\tThe file containing first input instances.\n"
+	+ "-o <filename>\n"
+	+ "\tThe file first output instances will be written to.\n"
+	+ "-r <filename>\n"
+	+ "\tThe file containing second input instances.\n"
+	+ "-s <filename>\n"
+	+ "\tThe file second output instances will be written to.\n"
+	+ "-c <class index>\n"
+	+ "\tThe number of the attribute to use as the class.\n"
+	+ "\t\"first\" and \"last\" are also valid entries.\n"
+	+ "\tIf not supplied then no class is assigned.\n";
+
+      throw new Exception('\n' + ex.getMessage()
+			  + filterOptions+genericOptions);
+    }
+    boolean printedHeader = false;
+    if (filter.setInputFormat(firstData)) {
+      firstOutput.println(filter.getOutputFormat().toString());
+      printedHeader = true;
+    }
+    
+    // Pass all the instances to the filter
+    while (firstData.readInstance(firstInput)) {
+      if (filter.input(firstData.instance(0))) {
+	if (!printedHeader) {
+	  throw new Error("Filter didn't return true from setInputFormat() "
+			  + "earlier!");
+	}
+	firstOutput.println(filter.output().toString());
+      }
+      firstData.delete(0);
+    }
+    
+    // Say that input has finished, and print any pending output instances
+    if (filter.batchFinished()) {
+      if (!printedHeader) {
+	firstOutput.println(filter.getOutputFormat().toString());
+      }
+      while (filter.numPendingOutput() > 0) {
+	firstOutput.println(filter.output().toString());
+      }
+    }
+    
+    if (firstOutput != null) {
+      firstOutput.close();
+    }    
+    printedHeader = false;
+    if (filter.isOutputFormatDefined()) {
+      secondOutput.println(filter.getOutputFormat().toString());
+      printedHeader = true;
+    }
+    // Pass all the second instances to the filter
+    while (secondData.readInstance(secondInput)) {
+      if (filter.input(secondData.instance(0))) {
+	if (!printedHeader) {
+	  throw new Error("Filter didn't return true from"
+			  + " isOutputFormatDefined() earlier!");
+	}
+	secondOutput.println(filter.output().toString());
+      }
+      secondData.delete(0);
+    }
+    
+    // Say that input has finished, and print any pending output instances
+    if (filter.batchFinished()) {
+      if (!printedHeader) {
+	secondOutput.println(filter.getOutputFormat().toString());
+      }
+      while (filter.numPendingOutput() > 0) {
+	secondOutput.println(filter.output().toString());
+      }
+    }
+    if (secondOutput != null) {
+      secondOutput.close();
+    }
+  }
+
+  /**
+   * Main method for testing this class.
+   *
+   * @param argv should contain arguments to the filter: use -h for help
+   */
+  public static void main(String [] args) {
+    
+    try {
+      if (args.length == 0) {
+        throw new Exception("First argument must be the class name of a Filter");
+      }
+      String fname = args[0];
+      Filter f = (Filter)Class.forName(fname).newInstance();
+      args[0] = "";
+      if (Utils.getFlag('b', args)) {
+	Filter.batchFilterFile(f, args);
+      } else {
+	Filter.filterFile(f, args);
+      }
+    } catch (Exception ex) {
+      ex.printStackTrace();
+      System.out.println(ex.getMessage());
+    }
+  }
+}
+
+
+
+
+
+
+
+
Index: /gsdl/trunk/build-src/packages/pdftohtml/readme-gs.txt
===================================================================
--- /gsdl/trunk/build-src/packages/pdftohtml/readme-gs.txt	(revision 16571)
+++ /gsdl/trunk/build-src/packages/pdftohtml/readme-gs.txt	(revision 16571)
@@ -0,0 +1,16 @@
+This is pdftohtml, which was based at:
+     http://www.ra.informatik.uni-stuttgart.de/~gosho/pdftohtml/
+
+It has recently been picked up again, and is currently based at:
+    http://pdftohtml.sourceforge.net/
+
+We're currently using version 0.34 as downloaded from
+http://pdftohtml.sourceforge.net. The only alterations made to the source
+package were to remove some "CVS" directories and tidy up the makefiles
+slightly (to use ./configure as with the rest of Greenstone).
+
+Also, the #pragma statements were removed to work around a compiler bug
+on Mac OS X.
+
+Stefan Boddie
+December 2002
Index: /gsdl/trunk/build-src/packages/rtftohtml/rtftohtml-gs.txt
===================================================================
--- /gsdl/trunk/build-src/packages/rtftohtml/rtftohtml-gs.txt	(revision 16571)
+++ /gsdl/trunk/build-src/packages/rtftohtml/rtftohtml-gs.txt	(revision 16571)
@@ -0,0 +1,56 @@
+RTF TO HTML
+-----------
+
+This is based on version 2.7.5 of rtftohtml, which was last modified in
+November, 1994.
+It contains the text:
+###
+Initial Implementation by Chris Hector (cjh@cray.com)
+(c) 1994 by Chris Hector
+May be freely distributed.
+This translator was based on rtfskel.
+###
+The last known email address I can find for him is <cjh@cray.com>.
+I think that <chris@sunpack.com> might reach him, but I'm not sure.
+
+
+Versions 3.0 of rtftohtml and up are released under a shareware license,
+and available from http://www.logictran.com (although it now has a new
+name). You can download a free binary version of the software for most
+platforms from this site.
+
+
+
+
+rtftohtml is based on RTF Tools, which is (c) April 1994 by Paul DuBois
+<dubois@primate.wisc.edu>
+
+RTF Tools has the notice:
+##
+Distribution Availability
+This software may be redistributed without restriction and used for any
+purpose whatsoever.
+##
+
+The supplied version understands RTF version 1.2, while the
+latest version of the specification is RTF 1.6 (May 1999).
+
+I have added some of the newer rtf codes that were preventing some files from
+being parsed properly, but they are not acted on. Most of them do not
+actually affect the content anyway. Depending on how the rtf was created,
+there might be tags that cause us to trip up and fail. If you have
+rtf files that Greenstone is not extracting text from, please send me
+some email (jrm21@cs.waikato.ac.nz).
+
+Note - we extract but do not convert Windows Metafile Format (.wmf) images.
+On unix systems, these can be converted with newer versions of ImageMagick
+(ie "convert" version 4.2.9 or newer).
+Also, libwmf (for unix and windows) is available for conversion at:
+http://wvware.sourceforge.net/projects/libwmf.html
+but we do not include it here due to its dependencies
+(eg libttf for truetype fonts).
+
+Embedded images such as jpegs and pngs are extracted fine, though.
+
+John McPherson (jrm21@cs.waikato.ac.nz)
+June 2001.
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Base64.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Base64.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Base64.pm	(revision 16571)
@@ -0,0 +1,198 @@
+#
+# $Id$
+
+package MIME::Base64;
+
+=head1 NAME
+
+MIME::Base64 - Encoding and decoding of base64 strings
+
+=head1 SYNOPSIS
+
+ use MIME::Base64;
+
+ $encoded = encode_base64('Aladdin:open sesame');
+ $decoded = decode_base64($encoded);
+
+=head1 DESCRIPTION
+
+This module provides functions to encode and decode strings into the
+Base64 encoding specified in RFC 2045 - I<MIME (Multipurpose Internet
+Mail Extensions)>. The Base64 encoding is designed to represent
+arbitrary sequences of octets in a form that need not be humanly
+readable. A 65-character subset ([A-Za-z0-9+/=]) of US-ASCII is used,
+enabling 6 bits to be represented per printable character.
+
+The following functions are provided:
+
+=over 4
+
+=item encode_base64($str, [$eol])
+
+Encode data by calling the encode_base64() function.  The first
+argument is the string to encode.  The second argument is the line
+ending sequence to use (it is optional and defaults to C<"\n">).  The
+returned encoded string is broken into lines of no more than 76
+characters each and it will end with $eol unless it is empty.  Pass an
+empty string as second argument if you do not want the encoded string
+broken into lines.
+
+=item decode_base64($str)
+
+Decode a base64 string by calling the decode_base64() function.  This
+function takes a single argument which is the string to decode and
+returns the decoded data.
+
+Any character not part of the 65-character base64 subset set is
+silently ignored.  Characters occuring after a '=' padding character
+are never decoded.
+
+If the length of the string to decode (after ignoring
+non-base64 chars) is not a multiple of 4 or padding occurs too ealy,
+then a warning is generated if perl is running under C<-w>.
+
+=back
+
+If you prefer not to import these routines into your namespace you can
+call them as:
+
+    use MIME::Base64 ();
+    $encoded = MIME::Base64::encode($decoded);
+    $decoded = MIME::Base64::decode($encoded);
+
+=head1 DIAGNOSTICS
+
+The following warnings might be generated if perl is invoked with the
+C<-w> switch:
+
+=over 4
+
+=item Premature end of base64 data
+
+The number of characters to decode is not a multiple of 4.  Legal
+base64 data should be padded with one or two "=" characters to make
+its length a multiple of 4.  The decoded result will anyway be as if
+the padding was there.
+
+=item Premature padding of base64 data
+
+The '=' padding character occurs as the first or second character
+in a base64 quartet.
+
+=back
+
+=head1 EXAMPLES
+
+If you want to encode a large file, you should encode it in chunks
+that are a multiple of 57 bytes.  This ensures that the base64 lines
+line up and that you do not end up with padding in the middle. 57
+bytes of data fills one complete base64 line (76 == 57*4/3):
+
+   use MIME::Base64 qw(encode_base64);
+
+   open(FILE, "/var/log/wtmp") or die "$!";
+   while (read(FILE, $buf, 60*57)) {
+       print encode_base64($buf);
+   }
+
+or if you know you have enough memory
+
+   use MIME::Base64 qw(encode_base64);
+   local($/) = undef;  # slurp
+   print encode_base64(<STDIN>);
+
+=head1 COPYRIGHT
+
+Copyright 1995-1999 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+Distantly based on LWP::Base64 written by Martijn Koster
+<m.koster@nexor.co.uk> and Joerg Reichelt <j.reichelt@nexor.co.uk> and
+code posted to comp.lang.perl <3pd2lp$6gf@wsinti07.win.tue.nl> by Hans
+Mulder <hansm@wsinti07.win.tue.nl>
+
+The XS implementation use code from metamail.  Copyright 1991 Bell
+Communications Research, Inc. (Bellcore)
+
+=cut
+
+use strict;
+use vars qw(@ISA @EXPORT $VERSION $OLD_CODE);
+
+require Exporter;
+require DynaLoader;
+@ISA = qw(Exporter DynaLoader);
+@EXPORT = qw(encode_base64 decode_base64);
+
+$VERSION = '2.11';
+
+eval { bootstrap MIME::Base64 $VERSION; };
+if ($@) {
+    # can't bootstrap XS implementation, use perl implementation
+    *encode_base64 = \&old_encode_base64;
+    *decode_base64 = \&old_decode_base64;
+
+    $OLD_CODE = $@;
+    #warn $@ if $^W;
+}
+
+# Historically this module has been implemented as pure perl code.
+# The XS implementation runs about 20 times faster, but the Perl
+# code might be more portable, so it is still here.
+
+use integer;
+
+sub old_encode_base64 ($;$)
+{
+    my $res = "";
+    my $eol = $_[1];
+    $eol = "\n" unless defined $eol;
+    pos($_[0]) = 0;                          # ensure start at the beginning
+    while ($_[0] =~ /(.{1,45})/gs) {
+	$res .= substr(pack('u', $1), 1);
+	chop($res);
+    }
+    $res =~ tr|` -_|AA-Za-z0-9+/|;               # `# help emacs
+    # fix padding at the end
+    my $padding = (3 - length($_[0]) % 3) % 3;
+    $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
+    # break encoded string into lines of no more than 76 characters each
+    if (length $eol) {
+	$res =~ s/(.{1,76})/$1$eol/g;
+    }
+    $res;
+}
+
+
+sub old_decode_base64 ($)
+{
+    local($^W) = 0; # unpack("u",...) gives bogus warning in 5.00[123]
+
+    my $str = shift;
+    my $res = "";
+
+    $str =~ tr|A-Za-z0-9+=/||cd;            # remove non-base64 chars
+    if (length($str) % 4) {
+	require Carp;
+	Carp::carp("Length of base64 data not a multiple of 4")
+    }
+    $str =~ s/=+$//;                        # remove padding
+    $str =~ tr|A-Za-z0-9+/| -_|;            # convert to uuencoded format
+    while ($str =~ /(.{1,60})/gs) {
+	my $len = chr(32 + length($1)*3/4); # compute length byte
+	$res .= unpack("u", $len . $1 );    # uudecode
+    }
+    $res;
+}
+
+# Set up aliases so that these functions also can be called as
+#
+#    MIME::Base64::encode();
+#    MIME::Base64::decode();
+
+*encode = \&encode_base64;
+*decode = \&decode_base64;
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Base64.xs
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Base64.xs	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Base64.xs	(revision 16571)
@@ -0,0 +1,215 @@
+/* $Id$
+
+Copyright 1997-1998 Gisle Aas
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+
+The tables and some of the code that used to be here was borrowed from
+metamail, which comes with this message:
+
+  Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
+
+  Permission to use, copy, modify, and distribute this material 
+  for any purpose and without fee is hereby granted, provided 
+  that the above copyright notice and this permission notice 
+  appear in all copies, and that the name of Bellcore not be 
+  used in advertising or publicity pertaining to this 
+  material without the specific, prior written permission 
+  of an authorized representative of Bellcore.	BELLCORE 
+  MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
+  OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
+  WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
+
+*/
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+#ifdef __cplusplus
+}
+#endif
+
+#include "patchlevel.h"
+#if PATCHLEVEL <= 4 && !defined(PL_dowarn)
+   #define PL_dowarn dowarn
+#endif
+
+#define MAX_LINE  76 /* size of encoded lines */
+
+static char basis_64[] =
+   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+#define XX      255	/* illegal base64 char */
+#define EQ      254	/* padding */
+#define INVALID XX
+
+static unsigned char index_64[256] = {
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,62, XX,XX,XX,63,
+    52,53,54,55, 56,57,58,59, 60,61,XX,XX, XX,EQ,XX,XX,
+    XX, 0, 1, 2,  3, 4, 5, 6,  7, 8, 9,10, 11,12,13,14,
+    15,16,17,18, 19,20,21,22, 23,24,25,XX, XX,XX,XX,XX,
+    XX,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
+    41,42,43,44, 45,46,47,48, 49,50,51,XX, XX,XX,XX,XX,
+
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
+    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
+};
+
+
+
+MODULE = MIME::Base64		PACKAGE = MIME::Base64
+
+SV*
+encode_base64(sv,...)
+	SV* sv
+	PROTOTYPE: $;$
+
+	PREINIT:
+	char *str;     /* string to encode */
+	SSize_t len;   /* length of the string */
+	char *eol;     /* the end-of-line sequence to use */
+	STRLEN eollen; /* length of the EOL sequence */
+	char *r;       /* result string */
+	STRLEN rlen;   /* length of result string */
+	unsigned char c1, c2, c3;
+	int chunk;
+
+	CODE:
+	str = SvPV(sv, rlen); /* SvPV(sv, len) gives warning for signed len */
+	len = (SSize_t)rlen;
+
+	/* set up EOL from the second argument if present, default to "\n" */
+	if (items > 1 && SvOK(ST(1))) {
+	    eol = SvPV(ST(1), eollen);
+	} else {
+	    eol = "\n";
+	    eollen = 1;
+	}
+
+	/* calculate the length of the result */
+	rlen = (len+2) / 3 * 4;	 /* encoded bytes */
+	if (rlen) {
+	    /* add space for EOL */
+	    rlen += ((rlen-1) / MAX_LINE + 1) * eollen;
+	}
+
+	/* allocate a result buffer */
+	RETVAL = newSV(rlen ? rlen : 1);
+	SvPOK_on(RETVAL);	
+	SvCUR_set(RETVAL, rlen);
+	r = SvPVX(RETVAL);
+
+	/* encode */
+	for (chunk=0; len > 0; len -= 3, chunk++) {
+	    if (chunk == (MAX_LINE/4)) {
+		char *c = eol;
+		char *e = eol + eollen;
+		while (c < e)
+		    *r++ = *c++;
+		chunk = 0;
+	    }
+	    c1 = *str++;
+	    c2 = *str++;
+	    *r++ = basis_64[c1>>2];
+	    *r++ = basis_64[((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)];
+	    if (len > 2) {
+		c3 = *str++;
+		*r++ = basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)];
+		*r++ = basis_64[c3 & 0x3F];
+	    } else if (len == 2) {
+		*r++ = basis_64[(c2 & 0xF) << 2];
+		*r++ = '=';
+	    } else { /* len == 1 */
+		*r++ = '=';
+		*r++ = '=';
+	    }
+	}
+	if (rlen) {
+	    /* append eol to the result string */
+	    char *c = eol;
+	    char *e = eol + eollen;
+	    while (c < e)
+		*r++ = *c++;
+	}
+	*r = '\0';  /* every SV in perl should be NUL-terminated */
+
+	OUTPUT:
+	RETVAL
+
+SV*
+decode_base64(sv)
+	SV* sv
+	PROTOTYPE: $
+
+	PREINIT:
+	STRLEN len;
+	register unsigned char *str = (unsigned char*)SvPV(sv, len);
+	unsigned char const* end = str + len;
+	char *r;
+	unsigned char c[4];
+
+	CODE:
+	{
+	    /* always enough, but might be too much */
+	    STRLEN rlen = len * 3 / 4;
+	    RETVAL = newSV(rlen ? rlen : 1);
+	}
+        SvPOK_on(RETVAL);
+        r = SvPVX(RETVAL);
+
+	while (str < end) {
+	    int i = 0;
+            do {
+		unsigned char uc = index_64[*str++];
+		if (uc != INVALID)
+		    c[i++] = uc;
+
+		if (str == end) {
+		    if (i < 4) {
+			if (i && PL_dowarn)
+			    warn("Premature end of base64 data");
+			if (i < 2) goto thats_it;
+			if (i == 2) c[2] = EQ;
+			c[3] = EQ;
+		    }
+		    break;
+		}
+            } while (i < 4);
+	    
+	    if (c[0] == EQ || c[1] == EQ) {
+		if (PL_dowarn) warn("Premature padding of base64 data");
+		break;
+            }
+	    /* printf("c0=%d,c1=%d,c2=%d,c3=%d\n", c[0],c[1],c[2],c[3]);/**/
+
+	    *r++ = (c[0] << 2) | ((c[1] & 0x30) >> 4);
+
+	    if (c[2] == EQ)
+		break;
+	    *r++ = ((c[1] & 0x0F) << 4) | ((c[2] & 0x3C) >> 2);
+
+	    if (c[3] == EQ)
+		break;
+	    *r++ = ((c[2] & 0x03) << 6) | c[3];
+	}
+
+      thats_it:
+	SvCUR_set(RETVAL, r - SvPVX(RETVAL));
+	*r = '\0';
+
+	OUTPUT:
+	RETVAL
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Changes
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Changes	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Changes	(revision 16571)
@@ -0,0 +1,119 @@
+1998-02-27   Gisle Aas <gisle@aas.no>
+
+   Release 2.11
+
+   Fixed bogues "Premature end of base64 data" warning.  Bug spotted
+   by Dwayne Jacques Fontenot.
+
+   Workaround for Redhat shipping trial releases of perl.
+
+
+
+1998-12-18   Gisle Aas <aas@sn.no>
+
+   Release 2.10
+
+   A tweak that should make compilation with some old perl5.00[23]
+   perls better.
+
+   A cast that make some compilers more happy.
+
+
+
+1998-11-13   Gisle Aas <aas@sn.no>
+
+   Release 2.09
+
+   The 2.08 release did not compile with perl5.005_53, because
+   all simple globals now need to be prefixed with "PL_".
+
+
+
+1998-10-22   Gisle Aas <aas@sn.no>
+
+   Release 2.08
+
+   Found another tweak to speed up decode_base64() with another 3%.
+
+   Improved MIME::Base64 documentation a little.
+
+
+
+1998-10-21   Gisle Aas <aas@sn.no>
+
+   Release 2.07
+
+   Faster and smarter C implementation of the decode_base64()
+   function.  The new decode_base64() was 25% faster when tested
+   on Linux, i586, gcc -O2.
+
+
+
+1998-07-15   Gisle Aas <aas@sn.no>
+
+   Release 2.06
+
+   The decode_base64() implemented in pure perl will only carp
+   (not croak) if length of data to decode is not a multiple 4.  This
+   actually made 'make test' fail after 'rm Base64.xs'.
+
+
+
+1998-01-27   Gisle Aas <aas@sn.no>
+
+   Release 2.05
+
+   The decode_base64() would previously allocate a too short buffer for the
+   result string when the trailing "==" padding was missing in the string to
+   be decoded.
+
+   The encode_base64() now allocate one byte less space in the result
+   strings returned.
+
+
+
+1997-12-02   Gisle Aas <aas@sn.no>
+
+   Release 2.04
+
+   Documentation expanded a bit.
+
+
+
+1997-07-10   Gisle Aas <aas@sn.no>
+
+   Release 2.03
+
+   Decode_base64() doesn't croak on premature ended data any more.
+   A warning is generated instead if running under -w.
+   
+
+
+1997-06-27   Gisle Aas <aas@sn.no>
+
+   Release 2.02
+
+   QuotedPrint fix by Roderick Schertler <roderick@argon.org>:
+
+      - Long lines were not broken unless they're at the beginning
+        of the text
+
+      - Lines near but not over 76 chars were broken when they
+        shouldn't be
+
+
+
+1997-06-13   Gisle Aas <aas@sn.no>
+
+   Release 2.01
+
+   Base64.xs: Avoid type convertion warnings with some compilers
+
+   Minor documentation updates
+
+
+
+1997-04-24   Gisle Aas <aas@sn.no>
+
+   Release 2.00, based on libwww-perl-5.08.
+
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/INSTALL.w3mir
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/INSTALL.w3mir	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/INSTALL.w3mir	(revision 16571)
@@ -0,0 +1,27 @@
+- You also have to get the MIME-Base64 package
+  (http://www.perl.com/CPAN/modules/by-module/MIME/)
+
+- Unpack it:
+
+    gzip -dc MIME-Base64-*.tar.gz | tar xvBf -
+
+- Install it:
+
+    cd MIME-Base64-*
+
+  Then, as above, either
+
+    perl Makefile.PL
+
+  or
+
+    perl Makefile.PL PREFIX=/some/dir
+
+  Continue:
+
+    make
+    make test      (it should print 'All tests successful.')
+    make install
+
+  Now MIME-Base64 should be installed and working.
+
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/MANIFEST
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/MANIFEST	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/MANIFEST	(revision 16571)
@@ -0,0 +1,9 @@
+Base64.pm	Bootstrap and perl implementation of MIME::Base64
+Base64.xs	Encoder and decoder written in C
+Changes		What's new
+MANIFEST	This file
+Makefile.PL	Writes the Makefile
+QuotedPrint.pm  MIME::QuotedPrint module, encoder and decoder
+README		Please do!
+t/base64.t	Test that it works
+t/quoted-print.t
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Makefile.PL
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Makefile.PL	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/Makefile.PL	(revision 16571)
@@ -0,0 +1,8 @@
+require 5.002;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME	 => 'MIME::Base64',
+    VERSION_FROM => 'Base64.pm',
+    dist         => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+);
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/QuotedPrint.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/QuotedPrint.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/QuotedPrint.pm	(revision 16571)
@@ -0,0 +1,115 @@
+#
+# $Id$
+
+package MIME::QuotedPrint;
+
+=head1 NAME
+
+MIME::QuotedPrint - Encoding and decoding of quoted-printable strings
+
+=head1 SYNOPSIS
+
+ use MIME::QuotedPrint;
+
+ $encoded = encode_qp($decoded);
+ $decoded = decode_qp($encoded);
+
+=head1 DESCRIPTION
+
+This module provides functions to encode and decode strings into the
+Quoted-Printable encoding specified in RFC 2045 - I<MIME (Multipurpose
+Internet Mail Extensions)>.  The Quoted-Printable encoding is intended
+to represent data that largely consists of bytes that correspond to
+printable characters in the ASCII character set.  Non-printable
+characters (as defined by english americans) are represented by a
+triplet consisting of the character "=" followed by two hexadecimal
+digits.
+
+The following functions are provided:
+
+=over 4
+
+=item encode_qp($str)
+
+This function will return an encoded version of the string given as
+argument.
+
+Note that encode_qp() does not change newlines C<"\n"> to the CRLF
+sequence even though this might be considered the right thing to do
+(RFC 2045 (Q-P Rule #4)).
+
+=item decode_qp($str);
+
+This function will return the plain text version of the string given
+as argument.
+
+=back
+
+
+If you prefer not to import these routines into your namespace you can
+call them as:
+
+  use MIME::QuotedPrint ();
+  $encoded = MIME::QuotedPrint::encode($decoded);
+  $decoded = MIME::QuotedPrint::decode($encoded);
+
+=head1 COPYRIGHT
+
+Copyright 1995-1997 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
+
+use strict;
+use vars qw(@ISA @EXPORT $VERSION);
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT = qw(encode_qp decode_qp);
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+
+sub encode_qp ($)
+{
+    my $res = shift;
+    $res =~ s/([^ \t\n!-<>-~])/sprintf("=%02X", ord($1))/eg;  # rule #2,#3
+    $res =~ s/([ \t]+)$/
+      join('', map { sprintf("=%02X", ord($_)) }
+		   split('', $1)
+      )/egm;                        # rule #3 (encode whitespace at eol)
+
+    # rule #5 (lines must be shorter than 76 chars, but we are not allowed
+    # to break =XX escapes.  This makes things complicated :-( )
+    my $brokenlines = "";
+    $brokenlines .= "$1=\n"
+	while $res =~ s/(.*?^[^\n]{73} (?:
+		 [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n
+		|[^=\n]    (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n
+		|          (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n
+	    ))//xsm;
+
+    "$brokenlines$res";
+}
+
+
+sub decode_qp ($)
+{
+    my $res = shift;
+    $res =~ s/[ \t]+?(\r?\n)/$1/g;  # rule #3 (trailing space must be deleted)
+    $res =~ s/=\r?\n//g;            # rule #5 (soft line breaks)
+    $res =~ s/=([\da-fA-F]{2})/pack("C", hex($1))/ge;
+    $res;
+}
+
+# Set up aliases so that these functions also can be called as
+#
+# MIME::QuotedPrint::encode();
+# MIME::QuotedPrint::decode();
+
+*encode = \&encode_qp;
+*decode = \&decode_qp;
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/README
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/README	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/README	(revision 16571)
@@ -0,0 +1,38 @@
+This package contains a base64 encoder/decoder and a quoted-printable
+encoder/decoder.  These encoding methods are specified in RFC 2045 -
+MIME (Multipurpose Internet Mail Extensions).
+
+The Base64 encoding is designed to represent arbitrary sequences of
+octets in a form that need not be humanly readable. A 65-character
+subset ([A-Za-z0-9+/=]) of US-ASCII is used, enabling 6 bits to be
+represented per printable character.
+
+The quoted-printable encoding is intended to represent data that
+largely consists of bytes that correspond to printable characters in
+the ASCII character set.  Non-printable characters are represented by
+a triplet consisting of the character "=" followed by two hexadecimal
+digits.
+
+The MIME::Base64 and MIME::QuotedPrint modules used to be part of
+libwww-perl package.  They are now distributed separately (as this
+package).  The main improvement is that the base64 encoder/decoder is
+implemented by XS functions.  This makes it about 20 times faster than
+the old implementation as pure Perl.
+
+In order to install and use this package you will need Perl version
+5.002 or better.  Installation as usual:
+
+   perl Makefile.PL
+   make
+   make test
+   make install
+
+The library can also be installed without XS support (for instance because
+you don't have a working C compiler installed).  Simply remove the Base64.xs
+file before running 'perl Makefile.PL' and everything should work the same,
+although encoding and decoding will be much slower.
+
+Copyright 1995-1999 Gisle Aas <gisle@aas.no>
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/install.sh
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/install.sh	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/install.sh	(revision 16571)
@@ -0,0 +1,10 @@
+#!/bin/sh -v
+
+export PERL5LIB=$GSDLHOME/perllib/cpan/lib:$PERL5LIB
+export PATH=$GSDLHOME/perllib/cpan/bin:$PATH
+
+perl Makefile.PL PREFIX=$GSDLHOME/perllib/cpan
+
+make
+make test
+make install
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/t/base64.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/t/base64.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/t/base64.t	(revision 16571)
@@ -0,0 +1,362 @@
+use MIME::Base64;
+
+print "1..282\n";
+
+print "Testing MIME::Base64-", $MIME::Base64::VERSION, "\n";
+
+$testno = 1;
+
+encodeTest();
+decodeTest();
+
+# This used to generate a warning
+print "not " unless decode_base64(encode_base64("foo")) eq "foo";
+print "ok ", $testno++, "\n";
+
+sub encodeTest
+{
+    print "encode test\n";
+
+    my @encode_tests = (
+        [''    => ''],
+	['a'   => 'YQ=='],
+	['aa'  => 'YWE='],
+	['aaa' => 'YWFh'],
+
+	['aaa' => 'YWFh'],
+	['aaa' => 'YWFh'],
+	['aaa' => 'YWFh'],
+
+	["\000\377" => "AP8="],
+	["\377\000" => "/wA="],
+	["\000\000\000" => "AAAA"],
+
+	# from HTTP spec
+	['Aladdin:open sesame' => 'QWxhZGRpbjpvcGVuIHNlc2FtZQ=='],
+
+	['a' x 100 => 'YWFh' x 33 . 'YQ=='],
+
+	['Multipurpose Internet Mail Extensions: The Base64 Content-Transfer-Encoding is designed to represent sequences of octets in a form that is not humanly readable. '
+	=> "TXVsdGlwdXJwb3NlIEludGVybmV0IE1haWwgRXh0ZW5zaW9uczogVGhlIEJhc2U2NCBDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nIGlzIGRlc2lnbmVkIHRvIHJlcHJlc2VudCBzZXF1ZW5jZXMgb2Ygb2N0ZXRzIGluIGEgZm9ybSB0aGF0IGlzIG5vdCBodW1hbmx5IHJlYWRhYmxlLiA="],
+
+	# All values
+	["\000" => "AA=="],
+	["\001" => "AQ=="],
+	["\002" => "Ag=="],
+	["\003" => "Aw=="],
+	["\004" => "BA=="],
+	["\005" => "BQ=="],
+	["\006" => "Bg=="],
+	["\007" => "Bw=="],
+	["\010" => "CA=="],
+	["\011" => "CQ=="],
+	["\012" => "Cg=="],
+	["\013" => "Cw=="],
+	["\014" => "DA=="],
+	["\015" => "DQ=="],
+	["\016" => "Dg=="],
+	["\017" => "Dw=="],
+	["\020" => "EA=="],
+	["\021" => "EQ=="],
+	["\022" => "Eg=="],
+	["\023" => "Ew=="],
+	["\024" => "FA=="],
+	["\025" => "FQ=="],
+	["\026" => "Fg=="],
+	["\027" => "Fw=="],
+	["\030" => "GA=="],
+	["\031" => "GQ=="],
+	["\032" => "Gg=="],
+	["\033" => "Gw=="],
+	["\034" => "HA=="],
+	["\035" => "HQ=="],
+	["\036" => "Hg=="],
+	["\037" => "Hw=="],
+	["\040" => "IA=="],
+	["\041" => "IQ=="],
+	["\042" => "Ig=="],
+	["\043" => "Iw=="],
+	["\044" => "JA=="],
+	["\045" => "JQ=="],
+	["\046" => "Jg=="],
+	["\047" => "Jw=="],
+	["\050" => "KA=="],
+	["\051" => "KQ=="],
+	["\052" => "Kg=="],
+	["\053" => "Kw=="],
+	["\054" => "LA=="],
+	["\055" => "LQ=="],
+	["\056" => "Lg=="],
+	["\057" => "Lw=="],
+	["\060" => "MA=="],
+	["\061" => "MQ=="],
+	["\062" => "Mg=="],
+	["\063" => "Mw=="],
+	["\064" => "NA=="],
+	["\065" => "NQ=="],
+	["\066" => "Ng=="],
+	["\067" => "Nw=="],
+	["\070" => "OA=="],
+	["\071" => "OQ=="],
+	["\072" => "Og=="],
+	["\073" => "Ow=="],
+	["\074" => "PA=="],
+	["\075" => "PQ=="],
+	["\076" => "Pg=="],
+	["\077" => "Pw=="],
+	["\100" => "QA=="],
+	["\101" => "QQ=="],
+	["\102" => "Qg=="],
+	["\103" => "Qw=="],
+	["\104" => "RA=="],
+	["\105" => "RQ=="],
+	["\106" => "Rg=="],
+	["\107" => "Rw=="],
+	["\110" => "SA=="],
+	["\111" => "SQ=="],
+	["\112" => "Sg=="],
+	["\113" => "Sw=="],
+	["\114" => "TA=="],
+	["\115" => "TQ=="],
+	["\116" => "Tg=="],
+	["\117" => "Tw=="],
+	["\120" => "UA=="],
+	["\121" => "UQ=="],
+	["\122" => "Ug=="],
+	["\123" => "Uw=="],
+	["\124" => "VA=="],
+	["\125" => "VQ=="],
+	["\126" => "Vg=="],
+	["\127" => "Vw=="],
+	["\130" => "WA=="],
+	["\131" => "WQ=="],
+	["\132" => "Wg=="],
+	["\133" => "Ww=="],
+	["\134" => "XA=="],
+	["\135" => "XQ=="],
+	["\136" => "Xg=="],
+	["\137" => "Xw=="],
+	["\140" => "YA=="],
+	["\141" => "YQ=="],
+	["\142" => "Yg=="],
+	["\143" => "Yw=="],
+	["\144" => "ZA=="],
+	["\145" => "ZQ=="],
+	["\146" => "Zg=="],
+	["\147" => "Zw=="],
+	["\150" => "aA=="],
+	["\151" => "aQ=="],
+	["\152" => "ag=="],
+	["\153" => "aw=="],
+	["\154" => "bA=="],
+	["\155" => "bQ=="],
+	["\156" => "bg=="],
+	["\157" => "bw=="],
+	["\160" => "cA=="],
+	["\161" => "cQ=="],
+	["\162" => "cg=="],
+	["\163" => "cw=="],
+	["\164" => "dA=="],
+	["\165" => "dQ=="],
+	["\166" => "dg=="],
+	["\167" => "dw=="],
+	["\170" => "eA=="],
+	["\171" => "eQ=="],
+	["\172" => "eg=="],
+	["\173" => "ew=="],
+	["\174" => "fA=="],
+	["\175" => "fQ=="],
+	["\176" => "fg=="],
+	["\177" => "fw=="],
+	["\200" => "gA=="],
+	["\201" => "gQ=="],
+	["\202" => "gg=="],
+	["\203" => "gw=="],
+	["\204" => "hA=="],
+	["\205" => "hQ=="],
+	["\206" => "hg=="],
+	["\207" => "hw=="],
+	["\210" => "iA=="],
+	["\211" => "iQ=="],
+	["\212" => "ig=="],
+	["\213" => "iw=="],
+	["\214" => "jA=="],
+	["\215" => "jQ=="],
+	["\216" => "jg=="],
+	["\217" => "jw=="],
+	["\220" => "kA=="],
+	["\221" => "kQ=="],
+	["\222" => "kg=="],
+	["\223" => "kw=="],
+	["\224" => "lA=="],
+	["\225" => "lQ=="],
+	["\226" => "lg=="],
+	["\227" => "lw=="],
+	["\230" => "mA=="],
+	["\231" => "mQ=="],
+	["\232" => "mg=="],
+	["\233" => "mw=="],
+	["\234" => "nA=="],
+	["\235" => "nQ=="],
+	["\236" => "ng=="],
+	["\237" => "nw=="],
+	["\240" => "oA=="],
+	["\241" => "oQ=="],
+	["\242" => "og=="],
+	["\243" => "ow=="],
+	["\244" => "pA=="],
+	["\245" => "pQ=="],
+	["\246" => "pg=="],
+	["\247" => "pw=="],
+	["\250" => "qA=="],
+	["\251" => "qQ=="],
+	["\252" => "qg=="],
+	["\253" => "qw=="],
+	["\254" => "rA=="],
+	["\255" => "rQ=="],
+	["\256" => "rg=="],
+	["\257" => "rw=="],
+	["\260" => "sA=="],
+	["\261" => "sQ=="],
+	["\262" => "sg=="],
+	["\263" => "sw=="],
+	["\264" => "tA=="],
+	["\265" => "tQ=="],
+	["\266" => "tg=="],
+	["\267" => "tw=="],
+	["\270" => "uA=="],
+	["\271" => "uQ=="],
+	["\272" => "ug=="],
+	["\273" => "uw=="],
+	["\274" => "vA=="],
+	["\275" => "vQ=="],
+	["\276" => "vg=="],
+	["\277" => "vw=="],
+	["\300" => "wA=="],
+	["\301" => "wQ=="],
+	["\302" => "wg=="],
+	["\303" => "ww=="],
+	["\304" => "xA=="],
+	["\305" => "xQ=="],
+	["\306" => "xg=="],
+	["\307" => "xw=="],
+	["\310" => "yA=="],
+	["\311" => "yQ=="],
+	["\312" => "yg=="],
+	["\313" => "yw=="],
+	["\314" => "zA=="],
+	["\315" => "zQ=="],
+	["\316" => "zg=="],
+	["\317" => "zw=="],
+	["\320" => "0A=="],
+	["\321" => "0Q=="],
+	["\322" => "0g=="],
+	["\323" => "0w=="],
+	["\324" => "1A=="],
+	["\325" => "1Q=="],
+	["\326" => "1g=="],
+	["\327" => "1w=="],
+	["\330" => "2A=="],
+	["\331" => "2Q=="],
+	["\332" => "2g=="],
+	["\333" => "2w=="],
+	["\334" => "3A=="],
+	["\335" => "3Q=="],
+	["\336" => "3g=="],
+	["\337" => "3w=="],
+	["\340" => "4A=="],
+	["\341" => "4Q=="],
+	["\342" => "4g=="],
+	["\343" => "4w=="],
+	["\344" => "5A=="],
+	["\345" => "5Q=="],
+	["\346" => "5g=="],
+	["\347" => "5w=="],
+	["\350" => "6A=="],
+	["\351" => "6Q=="],
+	["\352" => "6g=="],
+	["\353" => "6w=="],
+	["\354" => "7A=="],
+	["\355" => "7Q=="],
+	["\356" => "7g=="],
+	["\357" => "7w=="],
+	["\360" => "8A=="],
+	["\361" => "8Q=="],
+	["\362" => "8g=="],
+	["\363" => "8w=="],
+	["\364" => "9A=="],
+	["\365" => "9Q=="],
+	["\366" => "9g=="],
+	["\367" => "9w=="],
+	["\370" => "+A=="],
+	["\371" => "+Q=="],
+	["\372" => "+g=="],
+	["\373" => "+w=="],
+	["\374" => "/A=="],
+	["\375" => "/Q=="],
+	["\376" => "/g=="],
+	["\377" => "/w=="],
+    );
+
+    for $test (@encode_tests) {
+	my($plain, $expected) = ($$test[0], $$test[1]);
+
+	my $encoded = encode_base64($plain, '');
+	if ($encoded ne $expected) {
+	    print "test $testno ($plain): expected $expected, got $encoded\n";
+            print "not ";
+	}
+	my $decoded = decode_base64($encoded);
+	if ($decoded ne $plain) {
+	    print "test $testno ($plain): expected $expected, got $encoded\n";
+            print "not ";
+	}
+
+	# Try the old C versions too
+	if ($encoded ne MIME::Base64::old_encode_base64($plain, '')) {
+	    print "old_encode_base64 give different result.\n";
+	    print "not ";
+        }
+	if ($plain ne MIME::Base64::old_decode_base64($encoded)) {
+	    print "old_decode_base64 give different result.\n";
+	    print "not ";
+        }
+		
+	print "ok $testno\n";
+	$testno++;
+    }
+}
+
+sub decodeTest
+{
+    print "decode test:\n";
+    local $SIG{__WARN__} = sub { print $_[0] };  # avoid warnings on stderr
+
+    my @decode_tests = (
+	['YWE='   => 'aa'],
+	[' YWE='  => 'aa'],
+	['Y WE='  => 'aa'],
+	['YWE= '  => 'aa'],
+	["Y\nW\r\nE=" => 'aa'],
+
+	# These will generate some warnings
+        ['YWE=====' => 'aa'],    # extra padding
+	['YWE'      => 'aa'],    # missing padding
+        ['YWFh====' => 'aaa'],
+        ['YQ'       => 'a'],
+        ['Y'        => ''],
+        [''         => ''],
+        [undef()    => ''],
+    );
+
+    for $test (@decode_tests) {
+	my($encoded, $expected) = ($$test[0], $$test[1]);
+
+	my $decoded = decode_base64($encoded);
+	if ($decoded ne $expected) {
+	    die "test $testno ($encoded): expected $expected, got $decoded\n";
+	}
+	print "ok $testno\n";
+	$testno++;
+    }
+}
Index: /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/t/quoted-print.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/t/quoted-print.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/MIME-Base64-2.11/t/quoted-print.t	(revision 16571)
@@ -0,0 +1,106 @@
+#!/local/bin/perl -w
+
+use MIME::QuotedPrint;
+
+$x70 = "x" x 70;
+
+@tests =
+  (
+   # plain ascii should not be encoded
+   ["quoted printable"  =>
+    "quoted printable"],
+
+   # 8-bit chars should be encoded
+   ["våre kjære norske tegn bør æres" =>
+    "v=E5re kj=E6re norske tegn b=F8r =E6res"],
+
+   # trailing space should be encoded
+   ["  " => "=20=20"],
+   ["\tt\t" => "\tt=09"],
+   ["test  \ntest\n\t \t \n" => "test=20=20\ntest\n=09=20=09=20\n"],
+
+   # "=" is special an should be decoded
+   ["=\n" => "=3D\n"],
+   ["\0\xff" => "=00=FF"],
+
+   # Very long lines should be broken (not more than 76 chars
+   ["The Quoted-Printable encoding is intended to represent data that largly consists of octets that correspond to printable characters in the ASCII character set." =>
+    "The Quoted-Printable encoding is intended to represent data that largly con=
+sists of octets that correspond to printable characters in the ASCII charac=
+ter set."
+    ],
+
+   # Long lines after short lines were broken through 2.01.
+   ["short line
+In America, any boy may become president and I suppose that's just one of the risks he takes. -- Adlai Stevenson" =>
+    "short line
+In America, any boy may become president and I suppose that's just one of t=
+he risks he takes. -- Adlai Stevenson"],
+
+   # My (roderick@argon.org) first crack at fixing that bug failed for
+   # multiple long lines.
+   ["College football is a game which would be much more interesting if the faculty played instead of the students, and even more interesting if the
+trustees played.  There would be a great increase in broken arms, legs, and necks, and simultaneously an appreciable diminution in the loss to humanity. -- H. L. Mencken" =>
+    "College football is a game which would be much more interesting if the facu=
+lty played instead of the students, and even more interesting if the
+trustees played.  There would be a great increase in broken arms, legs, and=
+ necks, and simultaneously an appreciable diminution in the loss to humanit=
+y. -- H. L. Mencken"],
+
+   # Don't break a line that's near but not over 76 chars.
+   ["$x70!23"		=> "$x70!23"],
+   ["$x70!234"		=> "$x70!234"],
+   ["$x70!2345"		=> "$x70!2345"],
+   ["$x70!23456"	=> "$x70!23456"],
+   ["$x70!23\n"		=> "$x70!23\n"],
+   ["$x70!234\n"	=> "$x70!234\n"],
+   ["$x70!2345\n"	=> "$x70!2345\n"],
+   ["$x70!23456\n"	=> "$x70!23456\n"],
+
+   # Not allowed to break =XX escapes using soft line break
+   ["$x70===xxxx" => "$x70=3D=\n=3D=3Dxxxx"],
+   ["$x70!===xxx" => "$x70!=3D=\n=3D=3Dxxx"],
+   ["$x70!!===xx" => "$x70!!=3D=\n=3D=3Dxx"],
+   ["$x70!!!===x" => "$x70!!!=\n=3D=3D=3Dx"],
+   #                            ^
+   #                    70123456|
+   #                           max
+   #                        line width
+);
+
+$notests = @tests + 2;
+print "1..$notests\n";
+
+$testno = 0;
+for (@tests) {
+    $testno++;
+    ($plain, $encoded) = @$_;
+    $x = encode_qp($plain);
+    if ($x ne $encoded) {
+	print "Encode test failed\n";
+	print "Got:      '$x'\n";
+	print "Expected: '$encoded'\n";
+	print "not ok $testno\n";
+	next;
+    }
+    $x = decode_qp($encoded);
+    if ($x ne $plain) {
+	print "Decode test failed\n";
+	print "Got:      '$x'\n";
+	print "Expected: '$plain'\n";
+	print "not ok $testno\n";
+	next;
+    }
+    print "ok $testno\n";
+}
+
+# Some extra testing for a case that was wrong until libwww-perl-5.09
+print "not " unless decode_qp("foo  \n\nfoo =\n\nfoo=20\n\n") eq
+                                "foo\n\nfoo \nfoo \n\n";
+$testno++; print "ok $testno\n";
+
+# Same test but with "\r\n" terminated lines
+print "not " unless decode_qp("foo  \r\n\r\nfoo =\r\n\r\nfoo=20\r\n\r\n") eq
+                                "foo\r\n\r\nfoo \r\nfoo \r\n\r\n";
+$testno++; print "ok $testno\n";
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/ChangeLog
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/ChangeLog	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/ChangeLog	(revision 16571)
@@ -0,0 +1,1535 @@
+Tue Aug  4 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.36
+
+ o  The lwp-download script will call $ua->env_proxy now.
+
+ o  The lwp-request script allows content types (specified with the -c
+    option) with optional parameters like: multipart/mixed; boundary="--".
+
+ o  LWP::UserAgent will lowercase all authentication parameter names
+    before passing it to the authentication module.  Previous releases
+    ignored parameters like; Realm="Foo" (bacause Realm contained
+    upper case letters).
+
+ o  LWP::Protocol::ftp test for If-Modified-Since was wrong.
+
+ o  How the $url->abs method works can now be configured with the global
+    variables $URI::URL::ABS_ALLOW_RELATIVE_SCHEME and
+    $URI::URL::ABS_REMOTE_LEADING_DOTS.
+
+ o  The anonymous password guesser for ftp URLs will now call the external
+    `whoami` program any more.  Patch by Charles C. Fu <ccwf@bacchus.com>.
+
+ o  LWP::Protocol::http now allow dynamic requests without any
+    Content-Length specified when Content-Type is multipart/*
+
+ o  HTTP::Request::Common can now upload infinite files.
+    (Controlled by the $DYNAMIC_FILE_UPLOAD configuration variable.)
+
+
+
+Fri Jul 10 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.35
+
+ o  More lwp-rget patches from David D. Kilzer <ddkilzer@madison.dseg.ti.com>.
+    Adds the following new options: --iis, --keepext, --tolower
+
+ o  LWP::MediaTypes patches from MacEachern <dougm@pobox.com>.  Adds new
+    functions: add_type(), add_encoding(), read_media_types()
+
+
+
+Tue Jul  7 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.34
+
+ o  LWP::Protocol::ftp now try to use the MDTM command to support
+    the Last-Modified response header as well as
+    If-Modified-Since in requests.  Original and final patch by
+    Charles C. Fu <ccwf@bacchus.com>
+
+ o  $url->path_components will not escape "." any more.
+
+ o  WWW::RobotRules will now work for Mac text files too (lines delimited
+    by CR only).  Patch by Olly Betts <olly@muscat.co.uk>
+
+ o  lwp-rget support <area ..> links too.
+
+
+
+Thu May  7 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.33
+
+ o  LWP::Simple::get() did try to handle too many of the 3xx
+    codes as redirect when it bypasses full LWP.
+
+ o  LWP::UserAgent->mirror will now use utime(2) to set the
+    file modification time corresponding to the Last-Modified
+    header.
+
+ o  LWP::Protocol::http will not modify the HTTP::Request that
+    it is processing.  This avoids sticky Host header for
+    redirects.
+
+ o  URI::Heuristic and lwp-download documentation update.
+
+
+
+Wed Apr 15 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.32
+
+ o  Much improved HTTP::Daemon class. We now support persistent
+    connections.  Changes include:
+       - $c->get_request can be told to return after reading and
+         parsing headers only.
+       - $c->reason (new method)
+       - $c->read_buffer (new method)
+       - $c->proto_ge (new method)
+       - $c->force_last_request (new method)
+       - $c->send_response now support CODE reference content
+         and will use chunked transfer encoding for HTTP/1.1 clients.
+       - expanded the documentation.
+
+
+
+Fri Apr 10 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.31
+
+ o  Makefile.PL now checks that HTML::HeadParser is present.
+
+ o  Updated HTTP::Cookies according to draft-ietf-http-state-man-mec-08.txt
+    It now supports the .local domain and value less 'port' attribute in
+    the Set-Cookie2 header.
+
+ o  HTTP::Headers update:
+       - $h->content_type now always return a defined value
+       - $h->header($field) will now concatenate multi-valued header
+         fields with "," as separator in scalar context.
+
+ o  HTTP::Request::Common update:
+       - used to destroy the content of the  hash/array arguments
+         passed to its constructor functions.
+       - allow a hash reference to specify form-data content.
+       - you can override Content-Disposition for form-data now.
+       - set content-encoding for files if applicable
+       - default boundary string is now always "--000"
+
+ o  LWP::UserAgent will not follow more than 13 redirects
+    automatically.
+
+
+
+Wed Apr  1 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.30
+
+ o  Unbundled the following modules:
+
+       * HTML-Parser  (HTML::Parser, HTML::Entites, HTML::LinkExtor,...)
+       * HTML-Tree    (HTML::Element, HTML::TreeBuilder,...)
+       * Font-AFM     (Font::AFM, Font::Metrics::*)
+       * File-CounterFile
+
+ o  Simplified internal structure of HTML::Headers.  Hopefully,
+    nobody will notice.
+
+ o  New modules HTTP::Headers::Auth,  HTTP::Headers::ETag that adds
+    additional convenience methods to the HTTP::Headers class.
+
+ o  Removed split_etag_list() from HTTP::Headers::Util, in the hope
+    that nobody had starting using it.
+
+
+
+Tue Mar 24 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.22
+
+ o  HTTP::Cookies made more compatible with Netscape cookies.  Allow
+    the domain to match host, allow dots in the part of the hostname
+    not covered by domain.  Don't quote the cookie value even when it
+    contains non-token chars.  Based on patch from Kartik Subbarao
+    <subbarao@computer.org>.
+
+ o  Updated HTTP::Status to reflect <draft-ietf-http-v11-spec-rev-03>.
+    RC_MOVED_TEMPORARILY renamed to RC_FOUND.  Added codes
+    RC_TEMPORARY_REDIRECT (307) and RC_EXPECTATION_FAILED (417).
+    Slightly more documentation too.
+
+ o  The split_header_words() function HTTP::Headers::Util could go
+    into infinite loop on some header values.  Implemented split_etag_list()
+    too.  Added more documentation and test script for this module.
+
+ o  LWP::Simple now switch to full LWP implementation even for systems
+    that force all environment keys to be upper case.  Modification
+    suggested by Dale Couch <dcouch@training.orl.lmco.com>.
+
+ o  LWP::UserAgent allows redirects to a relative URL with scheme to be
+    made.  Suggested by Chris W. Unger <cunger@cas.org>.
+
+ o  Applied dtd2pm.pl patches from <peterm@zeta.org.au>.  It can now
+    extract information from the HTML40.dtd
+
+
+
+Thu Mar 12 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.21
+
+ o  lwp-rget patches from David D. Kilzer <ddkilzer@madison.dseg.ti.com>
+    (modified by Gisle).  Support the --hier  and the --auth options
+    and <frame>s.
+
+ o  File::CounterFile protect against bad $/ and $\ as suggested
+    by Frank Hoehne.
+ 
+ o  File::Listing used "next" when return was more appropriate.
+    Patch by erik@mediator.uni-c.dk.
+
+ o  HTML::Element support for multiple boolean attributes for a single
+    element.  Patch by Philip Guenther.
+
+ o  Can set $HTTP::Headers::TRANSLATE_UNDERSCORE to FALSE value to
+    suppress tr/_/-/ of header keys.
+
+ o  LWP::Protocol::http will not initialize the Host header if it is
+    already set. Patch by Ed Jordan.
+
+ o  LWP::Protocol::http did not handle responses with no header lines
+    correctly.  Patch by Daniel Buenzli <buenzli@rzu.unizh.ch>
+
+ o  $url->rel() handles path segments without leading "/" better.
+
+
+
+Fri Feb 13 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.20
+
+ o  Fixed the "500 Offset outside string" bug that affected perl
+    5.004_03 and older version of Perl.
+
+ o  Fixed a documentation typo spotted by Michael Quaranta
+    <quaranta@vnet.IBM.COM>
+
+ o  HTTP::Date: Protect against croaking from timegm/timelocal.
+
+
+
+Mon Jan 26 1998   Gisle Aas <aas@sn.no>
+
+ o  Release 5.19
+
+ o  HTML::Parser does not call $self->text() callback for empty text
+    any more.
+
+ o  LWP::Protocol::https was noisy when connections failed and the
+    script was running with '-w' (noise inherited from IO::Socket::INET)
+
+ o  $ua->use_alarm(BOOL) now gives a warning if running with -w
+
+
+
+Tue Jan 20 1998   Gisle Aas <aas@sn.no>
+
+ o  Developer release 5.18_05
+
+ o  HTTPS support based on my Crypt-SSLeay module.  The Net-SSLeay module
+    is not supported any more.
+
+ o  lwp-request documentation typo spotted Martijn Koster.
+
+ o  Removed superfluous \\ in the URI::Escape regex. This was also
+    spotted by Martijn.
+
+ o  File::Listing now handles timezones correctly.
+
+ o  Added $VERSION to modules that was missing it.
+
+ o  Added 'use strict' to several modules that was missing it.
+
+ o  LWP::Protocol::http now adds the Client-Peer header to responses and
+    has hooks for more callbacks.
+
+ o  LWP::Protocol::https adds Client-SSL-Cipher, Client-SSL-Cert-Subject
+    and Client-SSL-Cert-Issuer headers to the response.  The requests can
+    also be made conditional based on the peer certificate using the
+    If-SSL-Cert-Subject header in requests.
+
+ o  HTML::Parse is back.  (It was even used in lwpcook.pod)
+
+
+
+Wed Dec 17 1997   Gisle Aas <aas@sn.no>
+
+ o  Developer release 5.18_04
+
+ o  Makefile.PL fix based on report from Pon Hwa Lin <koala@fragment.com>
+
+ o  lwp-request will now print the response code message with -s and -S
+    options.
+
+ o  Hide IO::Socket::INET noise when running under -w
+
+ o  Don't set 'Content-Length: 0' in HTTP requests.
+
+ o  LWP::Protocol::http now calls LWP::Debug::conns again
+
+
+
+Tue Dec 16 1997   Gisle Aas <aas@sn.no>
+
+ o  Developer release 5.18_03
+
+ o  Got rid of alarms() and replaced LWP::Socket with IO::Socket::INET.
+    New protocol implementations for http, https, gopher, nntp.
+    $ua->use_alarm() is now a noop.
+
+ o  LWP::Protocol::ftp patch from  Tony Finch <fanf@demon.net>.
+
+ o  Removed depreciated modules from the distibution; HTML::Parse,
+    LWP::Socket, LWP::SecureSocket, LWP::IO, LWP::TkIO.
+
+
+
+Fri Dec 12 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.18
+
+ o  HTTP authorization patches from Tony Finch <fanf@demon.net>.
+    Allows "user:pass@" in HTTP URLs.
+
+ o  HTML::Parser patch by Brian McCauley <B.A.McCauley@bham.ac.uk>.
+    Pass original text to end() method.
+
+ o  The HTML::Parser->netscape_buggy_comment method is depreciated.
+    Use HTML::Parser->strict_comment instead.  The default value
+    has changed with the name.
+
+ o  Some HTML::Parser optimization tweaks.
+
+ o  New module named HTML::Filter
+
+ o  Updated HTTP::Headers to the latest HTTP spec.  Added knowledge
+    about the "Trailer", "Expect", "TE", "Accept-Range" headers.
+    "Public" header is gone.
+
+ o  Added some more header convenience methods: if_unmodified_since,
+    content_language, and proxy_authorization methods.
+
+ o  HTTP::{Request,Response}->clone can handle subclasses now.
+
+ o  HTTP::Request->url() can now undefine the URL.
+
+ o  HTTP::{Request,Response}->as_string format looks more like
+    the HTTP protocol formatting now.  Dashed lines above and
+    below is gone.
+
+ o  Documented HTTP::Response->status_line method
+
+ o  Compressed HTML::Response->error_as_HTML output
+
+ o  HTTP::Status updated to latest HTTP spec.  Added 
+    RC_REQUEST_RANGE_NOT_SATISFIABLE (416)
+
+
+
+Tue Dec  2 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.17
+
+ o  All authentication handling moved out of LWP::UserAgent and into
+    LWP::Authen::Basic and LWP::Authen::Digest.  We now also support
+    PROXY_AUTHENTICATION_REQUIRED responses.
+
+ o  HTML::Formatter will always add a blank line for <br>.
+
+ o  Avoid use of uninitialized value in HTTP::Daemon.
+
+ o  HTTP::Date allows seconds when recognizing 'ls -l' dates.  This
+    allows us to parse syslog time stamps.
+
+ o  HTTP::Request::Common::POST allows a hash reference as second
+    argument (in addition to an array reference).
+
+ o  LWP::Simple will initialize the $ua if it is exported.
+
+ o  Various documentation updates.
+
+
+
+Fri Nov 21 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.16
+
+ o  LWP::Simple::head() would die in array context because str2time
+    was not imported any more.
+
+ o  HTTP::Daemon->accept now takes an optional package argument like
+    IO::Socket->accept does.
+
+ o  Made HTTP::Request and HTTP::Response subclassable.
+
+ o  Added Proxy-Authorization example to lwpcook.
+
+
+
+Thu Nov  6 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.15
+
+ o  New module URI::Heuristic
+
+ o  The lwp-request script now use URI::Heuristic for it's URL arguments.
+    It means that 'lwp-request perl' will not get a file called "./perl"
+    but will fetch the page "http://www.perl.com" or something similar.
+    If you want to get the file you have to prefix it with "./".  Full
+    URLs are never affected by this.
+
+ o  LWP::Simple::get() will bypass LWP for simple HTTP requests.  This
+    should make it somewhat faster.
+
+ o  LWP::RobotUA has a new method called $ua->use_sleep() that
+    controls how niceness towards the servers are enforced.
+    Previously $ua->use_alarm() used to control this, but this did
+    not work well on Win32 systems.
+
+ o  URI::URL::rel() will handle URLs to a fragment within the same
+    document better. Initial patch from Nicolai Langfeldt
+    <janl@math.uio.no>.
+
+ o  HTML::Element don't consider </th>, </tr> and </td> optional any
+    more.  I wonder how Netscape managed to not implement this
+    correctly all this time.
+
+ o  Added lots of modern tags to HTML::AsSubs.
+
+ o  HTTP::Request::Common will read uploaded files in binmode().
+    This should be better for Win32 systems.  Contributed by
+    <Steve_Kilbane@cegelecproj.co.uk>.
+
+
+
+Sun Oct 12 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.14
+
+ o  HTML::Formatter patches from Andreas Gustafsson <gson@araneus.fi>.
+    The formatters handling of whitespace is much better now.  Thanks!
+
+ o  HTML::FormatText: can specify margins in the constructor.
+
+ o  URI::URL: the base will be absolutized internally now.
+
+ o  URI::URL will take advantage of void context provided by perl5.004.
+    This means that using $u->path and $u->query should be safer now.
+
+ o  URI::URL->print_on defaults to STDERR now (used to be STDOUT).
+
+ o  URI::URL: removed version 3 compatibility stuff ($COMPAT_VER_3).
+
+ o  $ua->mirror should work better on dosish systems (can not
+    rename when target file exists).
+
+ o  Typo in lwp-download prevented it from compiling.
+
+ o  Some minor documentations typos corrected.
+
+
+
+Sat Sep 20 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.13
+
+ o  Brand new module called HTTP::Cookies.  It stores cookies
+    (Set-Cookie and Set-Cookie2 headers) from responses and can
+    create appropriate Cookie headers for requests.  It can also
+    share cookie files with Netscape.
+
+ o  LWP::UserAgent now support the cookie_jar() attribute.  When
+    set to an HTTP::Cookies object, it will automatically manage
+    the cookies sent to the servers.  Off by default.
+
+ o  New header utility functions in HTTP::Headers::Util.
+
+ o  Win32 and OS/2 patches for the lwp-xxx utilities.  Turn on
+    binary mode by default (option to turn it off), avoid modifying $0,
+    and don't be confused about suffixes in the script names.
+    Contributed by Ben Coleman <bcoleman@mindspring.com>
+
+ o  OpenVMS patch for Font:AFM by Brad Hughes <brad@tmc.naecker.com>
+
+
+
+Fri Sep  5 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.12
+
+ o  decode_entities() would sometimes introduce ";" after
+    things that looked like they were entities.
+
+ o  HTML::LinkExtor knows about <applet code="...">
+
+ o  Patch from Gary Shea <shea@gtsdesign.com> that makes the
+    tests work even if perl is not called "perl"
+
+ o  HTTP::Date handles 12:00PM correctly now. Patch from
+    William York <william@mathworks.com>
+
+ o  HTTP::Request::Common don't quote the boundary string for
+    multipart/form-data messages any more.
+
+ o  Font::AFM works for encodings where .notdef is defined to
+    have some size.  Documentation and efficiency update.
+
+
+
+Wed Aug  6 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.11
+
+ o  Perl version 5.004 is now required for libwww-perl.
+
+ o  Win32 patches from Gurusamy Sarathy <gsar@engin.umich.edu>.
+    Now passes all tests on that platform.
+
+ o  HTTPS support contributed by Josh Kronengold <mneme@mcny.com>
+
+ o  Support hex entities &#xFF;  HTML::Entities::(en|de)code only
+    modify their argument in void context.
+
+ o  Fixed formatter bug with <font> tags which did not specify size.
+
+ o  Better HTML::HeadParser documentation
+
+ o  Fixed HTML::LinkExtor documentation typo spotted by Martijn.
+
+ o  HTTP::Request::Common now use CRLF for multipart/form-data
+
+
+
+Fri Jun 20 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.10
+
+ o  Make '+' a reserved URL character.  Decode unescaped '+' as
+    space in $url->query_form().
+
+ o  Use $Config{d_alarm} to determine default for $ua->use_alarm()
+
+
+
+Tue Jun 10 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.09
+
+ o  Removed the MIME modules from the distribution.  They are distributed
+    separately now.
+
+ o  Added a new module called HTTP::Request::Common
+
+ o  Improved HTTP::Status documentation.  It is now also possible
+    to import the is_client_error/is_server_error functions.
+
+ o  LWP::MediaTypes::guess_media_type() can now take an optional
+    HTTP::Header parameter.
+
+ o  LWP::Protocol ensures that scheme is legal as module name.
+
+ o  LWP::Protocol::http is not as strict when trying to verify the
+    method name.  It now also accepts responses without a message
+    on the status line.
+
+ o  WWW::RobotRules::AnyDBM_File: Some DBMs fail to allow multiple
+    opens of the same file.  Patch from Mark James <jamesm@skate.org>
+
+ o  Created Bundle::LWP
+
+
+
+Sat Apr  5 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.08
+
+ o  Made libwww-perl warning compatible with upcoming perl5.004beta2
+    (aka 5.003_98)
+
+ o  encode_base64() did not work properly if pos() of the string to
+    encode was different from 0.
+
+ o  HTML::Parser was confused about "</" when it did not start an end tag.
+
+ o  HTML::FormatPS will provide ISOLatin1Encoding in its output.
+
+ o  Calling HTML::LinkExtor->links will clear out old links.
+
+ o  url()->rel($base) would ignore the $base argument.
+
+ o  Don't croak() when setting url()->path().
+
+
+
+Tue Feb 11 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.07
+
+ o  Can limit the size of the response content with $ua->max_size()
+
+ o  Added time2iso() functions to HTTP::Date.
+
+ o  Made LWP::Protocol::http more portable to the MacPerl. /./ match
+    different things on MacPerl.
+
+
+
+Mon Jan 27 1997   Gisle Aas <aas@sn.no>
+
+ o  Release 5.06
+
+ o  URI::URL is now compatible with perl5.004 overloading.
+
+ o  HTML::HeadParser makes X-Meta-Name headers for <meta> elements
+    that does not specify an 'http-equiv' attribute.
+
+ o  URI::URL::ftp does not die if Net::Domain is not installed and
+    you ask for an anonymous username or password.
+
+ o  WWW::RobotRules:  The robots.txt parser did not ignore comment lines
+    as it should.
+
+ o  LWP::Protocol::http is more forgiving towards servers that return
+    bad responses.
+
+ o  Allow "?" before search string in gopher URLs.
+
+ o  LWP::Protocol::file did not escape funny filenames when generating
+    HTML directory listings.
+
+ o  LWP::Protocol::ftp now gets the Content-Encoding correct. 'CODE'
+    content in PUT requests also work now.
+
+ o  Relative locations in redirects did not work with URI::URL::strict.
+
+ o  OS/2 portability patches from Ilya Zakharevich
+
+ o  LWP::Authen::* patch from Doug MacEachern
+
+ o  Support experimental data:- URLs
+
+ o  Some tests (those using HTTP::Daemon) now die more gracefully if
+    IO::* modules is not installed.
+
+
+
+Wed Dec  4 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5.05
+
+ o  LWP::UserAgent::simple_request: local($SIG{__DIE__}) protects us
+    against user defined die handlers.
+ 	
+ o  Use Net::Domain (instead of Sys::Hostname) to determine FQDN.  It
+    is used by URI::URL when it determines anonymous ftp login address.
+	
+ o  lwp-download: New program in the bin directory
+
+ o  HTML::Parser: Allow '_' in attribute names.  This makes it possible
+    to parse Netscape's bookmarks.html file.
+
+ o  HTTP::Daemon: Fixed chunked transfer encoding and multipart content
+    in get_request().  Support HTTP/0.9 clients.
+
+ o  Don't clobber regex variables when HTTP::Message delegates methods
+    to the header.
+
+ o  Base64::decode_base64 now checks that the length input string to
+    decode is a multiple of 4.
+
+ o  t/robot/rules-dbm.t clean up better and will use AnyDBM for dumping
+
+ o  File::CounterFile: $/ strikes again by Andreas König
+
+ o  File::Listing updates from William York <william@mathworks.com>. We
+    can now parse the MS-Windows ftp server listings.
+
+ o  HTTP::Date now supports the MS-Windows 'dir' date format.  Patch by
+    William York.
+
+ o  LWP::MediaTypes::media_suffix will return first type in scalar context.
+
+
+
+Tue Oct 22 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5.04
+
+ o  Added HTTP::Daemon.  This is a HTTP/1.1 server class.  This means
+    that libwww-perl no longer is a client library only.  The HTTP::Daemon
+    is also used in the new test suite.
+
+ o  HTTP::Message support the protocol() method.  Used by HTTP::Daemon.
+
+ o  HTTP::Response can be constructed with a header and content as
+    argument.
+
+ o  Typo corrections in the documentation.
+
+ o  File::Listing::parse_dir accepts "GMT" as timezone now.
+
+ o  HTML::Parser will call the start() method with two new parameters;
+    $attrseq, $origtext.
+
+ o  Integrated HTML::FormatPS patches from
+    Jim Stern <jstern@world.northgrum.com>
+
+ o  Class modules don't inherit from AutoLoader any more.  They just
+    import the AUTOLOAD method.
+
+ o  LWP::Protocol will untaints scheme before loading protocol module.
+
+ o  Digest does not send "opaque" if it was not present in the request.
+    The "Extension" header is not returned any more.
+
+ o  New method: $url->crack that will return a list of the various
+    elements in a URI::URL.
+
+ o  WWW::RobotRules did not use the agent() method when determining
+    who we are.  This affected WWW::RobotRules::AnyDBM_File parsing
+    for robots.txt.  Visit count did not increment for
+    WWW::RobotRules::InCore.
+
+
+
+Tue Oct  1 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5.03
+
+ o  Hakan Ardo's persistent robot rules is now part of the standard
+    distribution.  This is still experimental and might change in the
+    future.  It includes the new WWW::RobotRules::AnyDBM_File class
+    and updates to LWP::RobotUA.
+
+ o  HTML::Parser now supports buggy Netscape comment parsing.  Enable
+    it by calling $p->netscape_buggy_comment(1).  The previous version
+    of the parser could also (under very unlucky and unlikely
+    circumstances) call the $self->comment() method several times for
+    the same comment text.
+
+ o  HTML::Parser: Use new $p->eof to signal end of document instead of
+    $p->parse(undef).
+
+ o  HTML::Element::starttag() is now smarter about which quotes it
+    use around attribute values.
+
+ o  New HTTP::Response methods: current_age(), freshness_lifetime(),
+    is_fresh(), fresh_until().
+
+ o  HTTP::Message:  New method ($mess->content_ref) which will return
+    a reference to the current content.
+
+ o  URI::URL:  New method ($url->rel) which does the opposite of abs().
+    Example: url("http://host/a/b/c", "http://host/c/d/e")->rel would
+    return url("../../a/b/c", "http://host/c/d/e").  This was
+    suggested by Nicolai Langfeldt <janl@ifi.uio.no>
+
+ o  URI::URL:  $url->query_form can now take array references as value
+    specification.  For instance: $url->query_form(foo => ['bar', 'baz']
+
+ o  Avoid '"my" variable $var masks earlier declaration in same scope'
+    warnings in perl5.003_05.
+
+
+
+Wed Sep 11 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5.02
+
+ o  lwp-rget:  Initialize proxy settings from envirionment
+
+ o  HTML::Entities::encode_entities: Don't encode $ and %
+
+ o  HTML::LinkExtor::links: Now works when no links were found.
+
+ o  HTTP::Headers::as_string: Allow \n in header value
+
+
+
+Tue Aug  1 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5.01.
+
+ o  Updated ftp protocol module to be compatible with Net::FTP 
+    version 2.00 (the version found in libnet-1.00)
+
+ o  New HTML parser module called HTML::LinkExtor
+
+ o  Various documentation typo corrections.  Most of these contributed
+    by Bob Dalgleish.
+
+ o  HTML::HeadParser updates 'Content-Base' instead of 'Base'.  It also
+    updates the 'Link' header based on <link ...>
+
+ o  HTTP::Headers and HTTP::Status updated according to
+    draft-ietf-http-v11-spec-06
+
+ o  HTTP::Headers can now use "_" as alternative to "-" in field names.
+
+ o  HTTP::Response::base now looks for 'Content-Base',
+    'Content-Location' and 'Base' headers.
+
+ o  Avoid warning in LWP::MediaTypes if $ENV{HOME} is not defined.
+
+ o  The new $ua->parse_head() method can be used to turn off
+    automatic initialization of response headers from the <HEAD>
+    section of HTML documents.
+
+ o  Added eq() method for URI::URL objects
+
+ o  The HTML::Formatter recovers even if a handle method is not defined
+    for all tags found during traversal
+
+
+
+Sun May 26 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5.00.
+
+ o  LWP::Simple::head() now return something useful in scalar context.
+
+ o  Rewritten the HTML::Parse stuff.  Introduced the HTML::Parser class
+    that will tokenize a HTML document.  The rest of the old
+    HTML::Parse functionality has moved to HTML::TreeBuilder class.
+    Note, that the HTML stuff is still alpha.
+
+ o  Implemented HTML::HeadParser.  This is a lightweight parser for
+    the <HEAD> section of a HTML document.
+
+ o  HTML::Element had problem with presenting things like <foo
+    bar="bar">.
+
+ o  HTML::Entities: Included additional ISO-8859/1 entities listed in
+    RFC1866.
+
+ o  HTML::AsSubs exported 'header' instead of 'head'
+
+ o  We know about a few more of the HTML 3.2 element.
+
+ o  HTTP::Date had problems with years before 1970, because Time::Local
+    went into an infinite loop.  Check for this.
+
+ o  Added $header->title method.
+
+ o  Made $header->authorization_basic return "uname:passwd" in scalar
+    context
+
+ o  LWP::Protocol::collect() will let the HTML::HeadParser look at the
+    document content as it arrives.  This will initialize headers from
+    elements like <base href="...">, <title>...</title> and <meta
+    http-equiv="..." ...>.
+
+ o  Simplified $response->base implementation, because we don't have
+    to look into the content any more.
+
+ o  Added -quiet option to lwp-rget
+
+ o  Typo fixes and some documentation additions.
+
+
+
+Thu May  9 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5b13
+
+ o  Made URI::URL::strict(0) the default.  I got tired of all this
+    eval { } stuff just to recover.  The URI::URL::strict'ness also
+    determine if calling some standard method that happens to be
+    illegal for some protocol scheme will croak or just be ignored.
+
+ o  Ensure correct $INPUT_RECORD_SEPARATOR and $OUTPUT_RECORD_SEPARATOR
+    at places where we <> or print.
+
+ o  Always localize $_ before any 'while(<FILE>) {}'-loops
+
+ o  Implemented $protocol->collect_once() and simplified several
+    of the protocol implementations by using it.
+
+ o  The HTML parser used to get it wrong if you were unlucky about the
+    breakup of the text. An example of broken behaviour was this:
+
+        $html = parse_html "<!-- A comment -";
+        $html = parse_html "-> and some text.";
+
+ o  The HTML parser does not ignore whitespace-only text any more.
+
+ o  HTML::Parse warnings are now optional and turned off by default.
+
+ o  New start for $html->as_HTML().
+
+ o  Fixed some typos
+
+
+
+Wed Apr 24 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5b12
+
+ o  New utility program called 'lwp-rget'.
+
+ o  $response->base was broken for HTML documents
+
+ o  New fancy LWP::Debug import() method.  Can now turn on debugging with
+    "use LWP::Debug '+';"
+
+ o  Trap exceptions (die) from the response callback routine
+
+ o  The RobotUA now requires an e-mail address of the person reponsible
+    for the robot.
+
+ o  New $ua->from() method.
+
+ o  Support for gopher Index-Search (gopher type '7' requests).
+    Contributed by Harry Bochner <bochner@das.harvard.edu>
+
+ o  Cleaned up white-space usage in the source.
+
+
+
+Wed Apr  3 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5b11
+
+ o  Implemented a NNTP protocol module.  The library can now fetch and
+    post news articles.
+
+ o  More documentation
+
+ o  Don't look at the URI header for redirects
+
+ o  New $res->base() method for HTTP::Responses
+
+ o  Graham Barr's patch to File::Listing to make it more OO internally
+
+ o  content_type() return value is canonicalized
+
+ o  $ua->request() does not die on bad URLs any more
+
+ o  LWP::MediaTypes merge all media.types files that if finds
+
+ o  FTP request with content to file or callback did not work
+
+ o  The value of HTTP Host: header is now $url->netloc;
+
+ o  The URI::URL constructor now accept URLs wrapped up in "<>"
+
+ o  $url->abs() now has a second optional argument that makes it accept
+    that relative URLs can have scheme, i.e. treat "http:img.gif" as a
+    relative URL.
+
+ o  Added prototypes to the HTTP::Status::is_xxx() functions
+
+ o  Added prototypes to the MIME:: encoding/decoding functions
+
+ o  Always return scheme for mailto and news URLs (as_string)
+
+ o  RobotRules patches from Henry A Rowley.
+
+ o  More tests
+
+ o  <SMALL> and <BIG> again
+
+
+
+Thu Mar 14 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5b10
+
+ o  GET ftp://host/doc was never successful for normal files.
+
+ o  LWP::Socket: read_until() did not notice EOF condidtion.  I.e. if
+    a HTTP server closed the connection before any output was generated,
+    the we continued to read 0 bytes in a busy loop until the alarm()
+    killed us.
+
+ o  Added support for Digest Access Authentication.  Contributed by
+    Doug MacEachern <dougm@osf.org>.
+
+ o  Makefile.PL: check for MD5 library
+
+ o  No longer print message content in HTTP::Response::error_as_HTML()
+
+ o  Access to "file:/path" gave warning when the envirionment variable
+    no_proxy was set.
+
+ o  The http-post test sends a Content-Type header.  Some servers hang
+    if this header is missing.
+
+ o  HTML::Parse:
+     -   allow <SMALL> and <BIG> tags
+     -   allow empty attribute values
+
+
+
+Tue Mar  5 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5b9
+
+ o  Started to write on the libwww-perl cookbook (lwpcook.pod)
+
+ o  The URI::URL module now exports the function url().  This is an
+    alternative (easy to use) constructor function.
+
+ o  Expanding relative file URLs starting with "#" did not work.
+
+ o  Fixed autoloaded DESTROY problem by adding empty DESTROY routine
+    to URI::URL.
+
+ o  Does not try generate password for ftp-URLs unless the username is
+    "anonymous" or "ftp"
+
+ o  The LWP::Simple user agent proxy settings are intialized from
+    the proxy environment variables. 
+
+ o  LWP::Protocol::ftp: Use the Net::FTP library to access ftp servers.
+    Convert directories to HTML on request (Accept: text/html).
+
+ o  New module HTTP::Negotiate
+
+ o  New module File::Listing
+
+ o  HTTP::Date::str2time can parse a few more formats, like the 'ls -l'
+    format and ISO 8601.  The function now also takes an optional second
+    parameter which specify a default time zone.
+
+ o  Added prototypes to the HTTP::Date functions.
+
+ o  The library adds a timestamp to responses ("Client-Date")
+
+ o  HTTP::Status:  Updated to proposed HTTP/1.1
+
+ o  HTTP::Headers: Updated to proposed HTTP/1.1
+
+ o  LWP::Protocol::http:  Updated to HTTP/1.1 methods
+
+ o  Took out stringify overloading in HTML::Element.
+
+
+
+Mon Feb 26 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5b8
+
+ o  Renamed functions using thisStyleOfNames to this_style_of_names.
+    Provided a script called 'update_from_5b7'
+
+ o  Renamed the 'request' and 'mirror' scripts to 'lwp-request' and
+    'lwp-mirror'.  The GET, POST, HEAD aliases for 'lwp-request' are
+    the same.
+
+ o  Implemented LWP::RobotUA
+
+ o  Class name for RobotRules did not match the file name
+
+ o  URI::URL
+      - perl5.002gamma is required (because use vars).
+      - The leading slash in now part of the path if it is present.
+      - More documentation
+      - Use AutoLoader to speed things up.
+      - New class URI::URL::_login and made telnet, rlogin, tn3270
+        subclasses from this one.
+      - URI::URL::wais is better supported.
+      - URI::URL::news is better supported.
+      - New URI::URL::mailto methods: user/host
+
+ o  HTTP::Date::time2str now works correctly with '0' as argument
+
+ o  HTTP::Message delegates unknown methods to the headers.
+
+ o  HTTP::Request::uri is an alias for HTTP::Request::url.  Can set
+    the URL to undef.
+
+ o  Added convenience methods to HTTP::Headers for easy access to
+    frequently used headers.
+
+ o  Simplified LWP::Debug
+
+ o  Use standard AutoLoader for LWP::IO functions.
+
+ o  Played with the profiler (Devel::DProf) and made some things
+    go quicker.
+
+ o  Included the File::CounterFile module.  Excluded Mail::Cap module
+    as it is also part of the MailTools package.
+
+
+
+Mon Feb  5 1996   Gisle Aas <aas@sn.no>
+
+ o  Release 5b7
+
+ o  Perl5.002 is required now
+
+ o  Rewrite of the URI::URL module (version 4.00)
+      - escaping/unsafe stuff redone (and removed)
+      - URI::URL::_generic moved out of URL.pm
+      - netloc, path, params, query is now stored internally in escaped form
+      - new methods for URI::URL::_generic are:
+           epath
+           eparams
+           equery
+	   path_components
+           absolute_path
+      - new methods for URI::URL::http are:
+           keywords
+           query_form
+      - new methods for URI::URL::file are:
+           newlocal
+           local_path
+           unix_path
+           dos_path
+           mac_path
+           vms_path
+
+ o  URI::Escape now semi-compile regular expressions (by evaling an
+    anonymous sub).  Same techinque is also used in HTML::Entities.
+
+ o  HTTP::Date parser rewritten using regular expressions.
+
+ o  HTTP::Headers->as_string() now croaks if any field values
+    contain newline.
+
+ o  HTTP::Status constants use empty prototype.
+
+ o  Font metrics moved to a new subdirectory (lib/Font/Metrics)
+
+ o  Don't use the VERSION script any more (even if it was very clever)
+
+ o  HTML::Entities will now export the names decode_entities() and
+    encode_entities().
+
+ o  Andreas Koenig's black patch to HTML::Element.
+
+ o  The HTML::Formatter now knows about <menu> and <dir> tags
+
+ o  The construct "defined ref($arg)" did not work on perl5.002
+    becase ref now always return something defined.
+
+ o  LWP::UserAgent sends by default an 'User-Agent' header.
+
+ o  LWP::Simple sends 'User-Agent' header to servers.
+
+ o  Updated the LWP::Socket module to use the new Socket.pm interface.
+
+ o  LWP::Protocol::http sends the new HTTP/1.1 'Host' header.
+
+ o  LWP::Protocol::file use $url->local_path to get a file to open.
+    It also inserts a <BASE> tag in directories instead of a redirect.
+
+ o  MIME::Base64 routines can be called as MIME::Base64::encode() and
+    MIME::Base64::decode().  Same kind of thing for QuotedPrint.
+
+
+
+Mon Nov  6 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Release 5b6
+
+ o  Installation should work better for those that still runs
+    perl4 as 'perl'.  The mirror script is not installed by
+    default.
+
+ o  LWP::Socket::_getaddress() Numerical IP adresses did not work.
+
+ o  LWP::Socket::pushback() did not work.  This also avoids the bad
+    pp_select() core dump from perl.
+
+ o  LWP::IO now also selects on socket exceptions.
+
+ o  HTML::Parse:  Ignore <!DOCTYPE ...> regardless for case.  Some
+    bad insertElement() calls made infinite loops.
+
+ o  The uri.t test works better for places where /tmp is a sym-link.
+
+
+
+Sat Sep 16 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Release 5b5
+
+ o  newlocal URI::URL does not put "//localhost" into the URLs any
+    longer.
+
+ o  The request program: New -o option to reformat the HTML code
+    New -C option to provide credentials on the command line.
+    The -b option never worked.
+
+ o  LWP::Protocol::file now returns redirect for access to directories
+    where the trailing slash is missing.
+
+
+
+Thu Sep 14 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Speedups and bug fixes in the HTML parser.  The parser now
+    understands some more depreciated tags (like <xmp> and <listing>).
+
+ o  HTML::Elements are now stingified using perl overloading.
+    The interface to the traverse() callback has changed.
+
+ o  Implemented HTML formatters for plain text and Postscript.
+
+ o  Added lib/Font stuff to support the Postscript formatter.
+
+ o  Inspired by Tim Bunce, I implemented the HTML::AsSubs module.
+    Don't know if it is really useful.
+
+ o  The local/get test does not use /etc/passwd any more.
+
+
+
+Thu Sep  7 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Changed package name to libwww-perl-5xx
+
+ o  Made LWP::Protocol::ftp actually transfer data
+
+ o  Implemented methods for LWP::Socket to act as a server:
+    bind(), listen(), accept(), getsockname(), host(), port()
+
+
+
+Wed Sep  6 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Release 0.04
+
+ o  Implemented modules to parse HTML.
+
+
+
+Mon Sep  4 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Implemented Mail::Cap which will become part of the MailTools
+    package.
+
+ o  Moved Base64 to MIME::Base64.  Reimplemented MIME::Base64 by using
+    [un]pack("u",...)   Implemented LWP::MIME::QuotedPrint for
+    completness sake.  Routine names has changed as suggested by Tim
+    Bunce.
+
+ o  LWP::MediaType reads default types from media.types file.
+    guessMediaType() now also returns encodings.  New function mediaSuffix()
+
+ o  Pass $url to $ua->getBasicCredentials().  This also fixes security
+    hole with the old implementation of getBasicCredentials().
+
+ o  LWP::Protocol::file now sets Content-Encoding headers
+
+ o  Allow request content to be provided by a callback routine.
+
+ o  Fix bug that prevented response callback to work.  The first parameter
+    (data) is no longer a reference, because $_[0] is already a reference.
+    Don't callback unless successful response.  Callbacks during redirects
+    was confusing.
+
+ o  URI::URL.  Remove port from netloc if it is the default port.
+    Don't use anything, just require.
+
+ o  HTTP::Message->addContent() does not need a reference parameter.
+
+ o  LWP::Socket->open() has been renamed top LWP::Socket->connect()
+    LWP::Socket->close has gone.  Implemented new method LWP::Socket->read()
+    that returns as fast as it has some data to offer.  Implemented
+    LWP::Socket->pushback().
+
+ o  Does not die in LWP::UserAgent->request()
+
+ o  LWP::Socket now use LWP::IO for low level IO
+
+ o  Implemented LWP::TkIO as a replacement module for LWP::IO when using Tk.
+
+
+
+Thu Aug 17 1995   Gisle Aas <aas@oslonett.no>
+
+ o  $ua->redirectOK() for checking redirects
+
+ o  reorganized tests in the "t" directory.
+
+
+
+Fri Aug 11 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Release 0.03
+
+ o  Included RobotRules.pm from Martijn Koster
+
+
+
+Thu Aug 10 1995   Gisle Aas <aas@oslonett.no>
+
+ o  New module URI::Escape (URI::URL use this module for default
+    escaping) that provide the uri_escape() and uri_unescape()
+    functions.
+
+ o  Setting $url->scheme now changes the class of the object.
+
+ o  Made $httpurl->user() and $httpurl->password() illegal.
+    Likewise for other URL schemes.
+
+
+
+
+Wed Aug  9 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Reorganisation as discussed on <libwww-perl@ics.uci.edu>
+       LWP::Date       --> HTTP::Date
+       LWP::MIMEheader --> HTTP::Headers
+       LWP::StatusCode --> HTTP::Status
+       LWP::Message    --> HTTP::Message
+       LWP::Request    --> HTTP::Request
+       LWP::Response   --> HTTP::Response
+       LWP::MIMEtypes  --> LWP::MediaTypes
+
+ o  HTTP::Date parses ctime format with missing timezone as suggested
+    by Roy Fielding <fielding@beach.w3.org>
+
+ o  HTTP::Status and LWP::MediaTypes exports their functions by default.
+
+ o  Splitted up the URI::URL module.  Schemes are implemented by separate
+    files that are autoloaded when used.  Self test moved to "t/uri.t".
+
+
+       
+Mon Aug  7 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Applied patch from Marc Hedlund <hedlund@best.com>
+       - Update the @header_order according to the August 3rd draft.
+       - Added Response Header fields: 'Location', 'Public', 'Retry-After',
+         'Server', and 'WWW-Authenticate'.
+       - Moved 'unknown header' handling from &scan to &header. The old
+         implementation was forcing all unknown header-words to begin with
+	 an uppercase (as it should be), but disallowed other uppercase
+	 letters.
+       - updates the status code messages under the August
+         3rd HTTP/1.0 draft.  '203' became 'Non-Authoritative Information',
+	 '303' became 'See Other', and a new code,
+	 '411 Authorization Refused', was added.
+
+ o  Can remove multiple headers with single removeHeader() call in MIMEheader.
+
+ o  Can assign multiple field/value pairs in header() method of MIMEheader.
+
+ o  A field with multiple values is printed as separate values in
+    MIMEheader::as_string().
+
+ o  LWP::Response contain new attributes: previous() and request().  These
+    attributes are updated by the UserAgent.
+
+ o  Appended \n to some die statements in Socket so that line numbers are
+    suppressed in error messages.
+
+ o  Made UserAgent::clone work for reference members
+
+ o  Check for redirect loops and multiple authorization failures by
+    examination of the response chain.
+
+ o  Use "\015\012" instead of "\r\n" in protocol modules.  Some systems
+    define \r and \n differently.
+
+ o  request program can now handle documents that needs autorization by
+    prompting the user for username/password. Added new -S option to print
+    request/response chain.
+
+
+  
+Tue Jul 25 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Release 0.02
+
+ o  Included URI::URL in the release
+
+
+
+Mon Jul 24 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Incorporated Makemake.PL and VERSION from Andreas Koenig <koenig@mind.de>
+    As a result of this the following things have changed:
+       - programs in "bin" are extracted from .PL-files
+       - reintroduced "lib"
+       - "test" has been renamed as "t"
+       - test programs in "t" has been made Test::Harness compatible
+       - we now have a MANIFEST file
+       - no more need fro update_version, make-dist, lwp-install
+
+ o  Renamed bin/get to bin/request.  Links to it are now all upper case.
+
+ o  Proxy support in bin/request (provided by Martijn Koster)
+
+ o  UserAgent can now load proxy settings from environment
+
+ o  LWP::Protocol::ftp is under way but not really finished
+
+
+
+Tue Jul 18 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Implemented LWP::Protocol::gopher
+
+ o  Implemented LWP::Protocol::mailto
+
+ o  Fixed proxy typo
+
+
+
+Mon Jul 17 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Made release 0.01
+
+
+
+Mon Jul 17 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Don't loose first line of HTTP/0.9 requests
+
+ o  LWP::Socket use syswrite() for writing
+
+ o  Added RC_* documentation to LWP::StatusCode
+
+ o  LWP::Date now use hash to look up month numbers
+
+ o  Added -f option to "get"
+
+ o  Untabify
+
+ o  Added a "TODO" list
+
+ o  Fixed various typos
+
+
+
+Fri Jul 14 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Reorganized directories.  Moved LWP.pm up.  Moved file.pm and http.pm
+    into the LWP::Protocol direcotory.  Moved LWP out of the lib directory
+    and removed lib.
+
+ o  Implemented the "get" and "mirror" scripts in the "bin" directory.
+
+ o  Implemented "install-lwp", "update_version" and "make-dist".  The library
+    version number is found in the VERSION file.
+
+ o  Always adds 1900 to the year in LWP::Date
+
+ o  In LWP::MIMEheader:  Implemented clone(), removeHeader() and scan() 
+    methods.  Reimplemented asString.  Removed asMIME().  Moved "Good
+    Practice" into this file, and reimplemented it.
+
+ o  Moved "header" and "content" into LWP::Message class.  This change made
+    LWP::Request and LWP::Response much simpler.  Made clone() method
+    actually work.
+
+ o  LWP::Protocol::implementor does not die if it cannot load package.
+
+ o  Moved UserAgent convenience methods into LWP::Simple.  Made LWP::Simple
+    export LWP::StatusCode symbols and functions.
+
+ o  Implemented $ua->isProtocolSupported($scheme) method.
+
+ o  Nicer directory listing in LWP::Protocol::file.pm
+
+ o  Rely on URI::URL 3.00 behaviour for $url->full_path
+
+ o  Library version number now in LWP.pm.  You should be able to say
+    "use LWP 1.0;" if you need at least this version.
+
+ o  Various cleanups and arranging layout as I like it.  Use fooBar-style
+    (as opposed to foo_bar stype) everywhere.  This means that as_string()
+    now is called asString().
+
+ o  Added more documentation.
+
+
+
+Wed Jun 14 1995   Gisle Aas <aas@oslonett.no>
+
+ o  Removed lot of rendundant & before function calls.
+
+ o  $this --> $self
+
+ o  &collector passes content as a reference, don't want to copy so much
+
+ o  parameterlist to collect callback has been rearranged
+
+ o  Response::addContent gets a reference to the data
+
+ o  Added some callback documentation to UserAgent.pm
+
+ o  Protocol::file now uses the collector
+
+ o  Introduced LWP::Simple
+
+
+
+Sun Jun 11 1995   Martijn Koster <m.koster@nexor.co.uk>
+
+ o  Added basic authentication support
+
+ o  Added mirroring of single documents
+
+ o  Change Protocol construction from whacky URL.pm (constructor returns
+    subclass) to more normal C++'ish way.
+
+
+
+Wed June 7 1995   Martijn Koster <m.koster@nexor.co.uk>
+
+ o  Minor cleanups from printed code inspection
+
+
+
+Wed May 24 1995   Martijn Koster <m.koster@nexor.co.uk>
+
+ o  Added redirection resolution
+
+ o  Added optional autoloading of protocols
+
+
+
+Tue May 23 1995   Martijn Koster <m.koster@nexor.co.uk>
+
+ o  Separated socket stuff into separate module
+
+ o  Added HTTP proxy support
+
+ o  Made alarm handling optional
+
+ o  Added a LWP::Message for completeness sake
+
+ o  Added LWP::MemberMixin to reduce code duplication
+
+ o  Cosmetic changes to LWP::Date
+
+ o  Renamed LWP::Error to LWP::StatusCode
+
+ o  Renamed LWP::MIME to LWP::MIMEtype
+
+ o  Changed the tests to cope with all this
+
+It's getting there...
+
+
+
+Mon May 22 1995   Martijn Koster <m.koster@nexor.co.uk>
+
+ o  Changed the socket reading to use sysread.  This will have to go
+    into a module of its own.
+
+
+
+Thu 18 May 1995   Martijn Koster <m.koster@nexor.co.uk>
+
+ o  Mentioned on libwww-perl that I had changed the classes around lots.
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/INSTALL.w3mir
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/INSTALL.w3mir	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/INSTALL.w3mir	(revision 16571)
@@ -0,0 +1,48 @@
+
+- Get libwww-perl from CPAN 
+  (http://www.perl.com/CPAN/modules/by-module/WWW/).  W3mir does not work
+  with LWP 5.40 and later versions.  Please get an earlier version.
+  It also does not work with the new URI package.  Use the URI package
+  enclosed in the older LWP.
+
+- Unpack it:
+
+    gzip -dc libwww-perl-*.tar.gz | tar xvBf -
+
+- Install it.  W3mir does not require the whole libwww-perl package and
+  all the packages that goes with it to work so you may follow these
+  install instructions instead of the libwww-perl install instructions
+  to get an easier install which will work with w3mir.
+
+    cd libwww-perl-*
+
+  Are you going to install it in the standard perl place (you need to
+  be the system administrator to do this)? If so:
+
+    perl Makefile.PL
+
+  If not (if you are a user):
+
+    perl Makefile.PL PREFIX=/some/dir
+
+  /some/dir could be ~ (as in your home directory).
+
+  IF you are installing an old LWP just for w3mir you can install both
+  the old LWP, the Base64 module and w3mir in a special PREFIX
+  separate from your usual install PREFIX.  This ensures that w3mir will
+  access the older version of LWP and that other software will access
+  the newer version.  If you do this make sure you install all of LWP,
+  Base64 and w3mir with the same PREFIX.
+
+  This step might produce some complaints;  A standard perl
+  installation will typically get messages about missing these
+  modules: IO::Socket, NET::FTP and MD5.  None of these need be
+  installed to run w3mir and so any error messages about these may
+  safely be ignored.
+
+    make
+    make test      (robot/ua and local/http might fail, that's OK)
+    make install
+
+  Now libwww-perl should be installed and working.
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/MANIFEST
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/MANIFEST	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/MANIFEST	(revision 16571)
@@ -0,0 +1,106 @@
+ChangeLog			History of this package
+MANIFEST			This file
+Makefile.PL			Makefile generator
+README				Get you started with this package
+TODO				The To-Do list for the library
+bin/lwp-download.PL             Writes bin/lwp-download script
+bin/lwp-mirror.PL		Writes bin/lwp-mirror script
+bin/lwp-request.PL		Writes bin/lwp-request script
+bin/lwp-rget.PL			Writes bin/lwp-rget script
+lwpcook.pod			Libwww-perl examples
+lib/Bundle/LWP.pm               Defines prereq modules
+lib/File/Listing.pm		Parse directory listings
+lib/HTTP/Cookies.pm             Cookie storage and management
+lib/HTTP/Daemon.pm		A simple httpd
+lib/HTTP/Date.pm		Date conversion routines
+lib/HTTP/Headers.pm		Class encapsulating HTTP Message headers
+lib/HTTP/Headers/Auth.pm	Some methods that deal with authorization.
+lib/HTTP/Headers/ETag.pm	Some methods that deal with entity tags
+lib/HTTP/Headers/Util.pm        Some utility functions for header values.
+lib/HTTP/Message.pm		Class encapsulating HTTP messages
+lib/HTTP/Negotiate.pm		Evaluate HTTP content negotiation algoritm
+lib/HTTP/Request.pm		Class encapsulating HTTP Requests
+lib/HTTP/Request/Common.pm      Generate common requests
+lib/HTTP/Response.pm		Class encapsulating HTTP Responses
+lib/HTTP/Status.pm		HTTP Status code processing
+lib/LWP.pm			Includes what you need
+lib/LWP/Authen/Basic.pm		Basic authentication scheme
+lib/LWP/Authen/Digest.pm	Digest authentication scheme
+lib/LWP/Debug.pm		Debugging support
+lib/LWP/MediaTypes.pm		Library for guessing media types
+lib/LWP/MemberMixin.pm		Helps you access %$self
+lib/LWP/Protocol.pm		Virtual base class for LWP protocols
+lib/LWP/Protocol/data.pm        Access to data URLs
+lib/LWP/Protocol/file.pm	Access local files
+lib/LWP/Protocol/ftp.pm		Access with the FTP protocol
+lib/LWP/Protocol/gopher.pm	Access with the Gopher protocol
+lib/LWP/Protocol/http.pm	Access with HTTP protocol
+lib/LWP/Protocol/https.pm	Access with HTTP protocol over SSL
+lib/LWP/Protocol/mailto.pm	Allows you to POST mail using sendmail
+lib/LWP/Protocol/nntp.pm	Handles access to news: and nntp: URLs
+lib/LWP/RobotUA.pm		Easy creation of conforming robots
+lib/LWP/Simple.pm		Procedural LWP interface
+lib/LWP/UserAgent.pm		A WWW UserAgent class
+lib/LWP/media.types		Mapping from file extentions media types
+lib/URI/Escape.pm		General URI escaping functions
+lib/URI/Heuristic.pm            User friendly URLs
+lib/URI/URL.pm			Class encapsulating URLs
+lib/URI/URL/_generic.pm		Implements generic hierarchical RL (RFC 1808)
+lib/URI/URL/_login.pm		Base class for telnet, tn3270 and rlogin
+lib/URI/URL/data.pm             Implements data URLs
+lib/URI/URL/file.pm		Implements file URLs
+lib/URI/URL/finger.pm		Implements finger URLs
+lib/URI/URL/ftp.pm		Implements ftp URLs
+lib/URI/URL/gopher.pm		Implements gopher URLs
+lib/URI/URL/http.pm		Implements http URLs
+lib/URI/URL/https.pm		Implements https URLs
+lib/URI/URL/mailto.pm		Implements mailto URLs
+lib/URI/URL/news.pm		Implements news URLs
+lib/URI/URL/nntp.pm		Implements nntp URLs
+lib/URI/URL/prospero.pm		Implements prospero URLs
+lib/URI/URL/rlogin.pm		Implements rlogin URLs
+lib/URI/URL/telnet.pm		Implements telnet URLs
+lib/URI/URL/tn3270.pm		Implements tn3270 URLs
+lib/URI/URL/wais.pm		Implements wais URLs
+lib/URI/URL/webster.pm		Implements webster URLs
+lib/URI/URL/whois.pm		Implements whois URLs
+lib/WWW/RobotRules.pm		Parse robot.txt files
+lib/WWW/RobotRules/AnyDBM_File.pm	Persistent robot rules
+t/README			How to run and set up tests
+t/TEST				Run tests
+t/base/common-req.t		Test HTTP::Request::Common module
+t/base/cookies.t                Test HTTP::Cookies module
+t/base/date.t			Test HTTP::Date module
+t/base/headers.t		Test HTTP::Headers module
+t/base/headers-auth.t		Test HTTP::Headers::Auth module
+t/base/headers-etag.t		Test HTTP::Headers::ETag module
+t/base/headers-util.t		Test HTTP::Headers::Util module
+t/base/listing.t		Test File::Listing module
+t/base/mediatypes.t		Test LWP::MediaTypes module
+t/base/message.t		Test HTTP::Request/HTTP::Response
+t/base/negotiate.t		Test HTTP::Negotiation module
+t/base/response.t		Test additional HTTP::Response methods
+t/base/status.t			Test HTTP::Status module
+t/local/autoload.t		Test autoloading of LWP::Protocol modules
+t/local/get.t			Try to get a local file
+t/local/http.t			Test http to local server
+t/local/protosub.t              Test with other protocol module
+t/net/cgi-bin/moved
+t/net/cgi-bin/nph-slowdata
+t/net/cgi-bin/slowread
+t/net/cgi-bin/test
+t/net/cgi-bin/timeout
+t/net/config.pl.dist		Suggested configuration for net tests
+t/net/http-get.t
+t/net/http-post.t
+t/net/http-timeout.t
+t/net/mirror.t
+t/net/moved.t
+t/net/proxy.t
+t/robot/rules-dbm.t		Test WWW::RobotRules::AnyDBM_File
+t/robot/rules.t			Test WWW::RobotRules
+t/robot/ua.t			Test LWP::RobotUA
+t/uri/abs-config.t              Test URI::URL configuration variables
+t/uri/base.t			Test URI::URL module
+t/uri/rel-base.t		Test URI::URL module some more
+t/uri/heuristic.t               Test URI::Heuristic module
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/Makefile.PL
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/Makefile.PL	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/Makefile.PL	(revision 16571)
@@ -0,0 +1,184 @@
+# This -*- perl -*- script writes the Makefile for libwww-perl
+# $Id$
+
+require 5.004;
+use strict;
+
+#--- Configuration section ---
+
+my @programs_to_install = qw(lwp-request lwp-mirror lwp-rget lwp-download);
+my @request_aliases     = qw(GET HEAD POST);
+
+#--- End Configuration - You should not have to change anything below this line
+
+
+# Allow us to suppress all program installation with the -n (library only)
+# option.  This is for those that don't want to mess with the configuration
+# section of this file.
+use Getopt::Std;
+use vars qw($opt_n);
+unless (getopts("n")) {
+    die "Usage: $0 [-n]\n";
+}
+@programs_to_install = () if $opt_n;
+
+
+# Check for non-standard modules that are used by this library.
+$| = 1;
+my $missing_modules = 0;
+
+print "Checking for HTML::Parser..";
+eval {
+    require HTML::HeadParser;
+};
+if ($@) {
+    print " failed\n";
+    $missing_modules++;
+    print <<EOT;
+$@
+The HTML::Parser is needed to extract correct <BASE> information from
+HTML so that we can resolv relative links correctly.
+
+EOT
+    sleep(2);  # Don't hurry too much
+} else {
+    print " ok\n";
+}
+
+print "Checking for MIME::Base64..";
+eval {
+    require MIME::Base64;
+    #MIME::Base64->require_version('2.00');
+};
+if ($@) {
+    print " failed\n";
+    $missing_modules++;
+    print <<EOT;
+$@
+The Base64 encoding is used in authentication headers in HTTP.
+
+EOT
+    sleep(2);  # Don't hurry too much
+} else {
+    print " ok\n";
+}
+
+print "Checking for Net::FTP......";
+eval {
+    require Net::FTP;
+    Net::FTP->require_version('2.00');
+};
+if ($@) {
+    print " failed\n";
+    $missing_modules++;
+    print <<EOT;
+$@
+The libwww-perl library normally use the Net::FTP module when
+accessing ftp servers.  You would have to install this package or
+configure your application to use a proxy server for making ftp
+requests work.  Net::FTP is part of the 'libnet' distribution.
+
+EOT
+    sleep(2);  # Don't hurry too much
+} else {
+    print " ok\n";
+}
+
+print "Checking for MD5 ..........";
+eval {
+    require MD5;
+};
+if ($@) {
+    print " failed\n";
+    $missing_modules++;
+    print <<EOT;
+$@
+The MD5 library is needed if you want to be able use the experimental
+"Digest Access Authentication" scheme.  Since very few servers
+implement this authentication scheme, you should normally not worry
+too much about this.
+
+EOT
+} else {
+    print " ok\n";
+}
+
+print <<EOT if $missing_modules;
+The missing modules can be obtained from CPAN.  Visit
+<URL:http://www.perl.com/CPAN/> to find a CPAN site near you.
+
+EOT
+
+
+# Ok, now it is time to really generate the Makefile
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+   NAME          => 'libwww-perl',
+   VERSION_FROM  => 'lib/LWP.pm',
+   PL_FILES      => { map {("bin/$_.PL" => "bin/$_")} @programs_to_install },
+   EXE_FILES     => [ map {"bin/$_"} @programs_to_install ],
+   'clean'       => { FILES => '$(EXE_FILES)' },
+   'dist'        => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+);
+
+
+
+package MY;
+
+sub postamble
+{
+    my @m;
+    if (@request_aliases && grep($_ eq 'lwp-request', @programs_to_install)) {
+	push @m, "all ::\n";
+	if ($^O eq 'MSWin32') {
+	    push @m, "\t\$(FULLPERL) -e \"use Config; chdir q[\$(INST_EXE)]; "
+		    ."foreach (qw(@request_aliases)) { \" \\\n";
+	    push @m, <<'EOT';
+	-e "unlink \"$$_\"; " \
+	-e "system(\"copy lwp-request $$_\") && die; }"
+EOT
+	} else {
+	    push @m, "\t\$(FULLPERL) -e 'use Config; chdir q{\$(INST_EXE)}; "
+		    ."foreach (qw(@request_aliases)) {' \\\n";
+	    push @m, <<'EOT';
+	-e 'unlink "$$_";' \
+	-e 'system("$$Config{\"lns\"} lwp-request $$_") && die; }'
+EOT
+	}
+    }
+    join "", @m;
+}
+
+# What happens when we say 'make test'
+sub test
+{
+    q(
+TEST_VERBOSE=0
+
+test: all
+	$(FULLPERL) t/TEST $(TEST_VERBOSE)
+
+);
+}
+
+
+# Determine things that should *not* be installed
+sub libscan
+{
+    my($self, $path) = @_;
+    return '' if $path =~ m/.(pl|dtd|sgml)$/;
+    return '' if $path =~ m:\bCVS/:;
+    return '' if $path =~ m/~$/;
+    $path;
+}
+
+# Pass libwww-perl version number to pod2man
+sub manifypods
+{
+    my $self = shift;
+    my $ver = $self->{VERSION} || "";
+    local($_) = $self->SUPER::manifypods(@_);
+    s/pod2man\s*$/pod2man --release libwww-perl-$ver/m;
+    $_;
+}
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/README
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/README	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/README	(revision 16571)
@@ -0,0 +1,124 @@
+                     L I B W W W - P E R L - 5
+                   -----------------------------
+
+Libwww-perl is a collection of Perl modules which provides a simple
+and consistent programming interface (API) to the World-Wide Web.  The
+main focus of the library is to provide classes and functions that
+allow you to write WWW clients, thus libwww-perl said to be a WWW
+client library. The library also contain modules that are of more
+general use and even classes that helps you implement simple HTTP
+servers.
+
+There are actually two versions of libwww-perl: one for Perl4, and one
+for Perl5. Both have a similar architecture, loosely based on the CERN
+Library of Common Code (nowadays known as 'w3c-libwww').
+
+The Perl4 version is still(?) maintained by Roy Fielding, and was the
+basis for tools such as MOMSpider. The perl4 version of libwww-perl
+and much more information about its libraries can be found at:
+http://www.ics.uci.edu/pub/websoft/libwww-perl/
+
+The Perl5 version (this package) is a complete rewrite for Perl5: the
+code is organized in Modules, provides an Object Oriented API, is
+updated for the latest HTTP and URL specification, and offers some
+extended functionality.
+
+Full HTTP/1.1 support is on its way.  Alpha releases of the LWPng
+package is currently available from CPAN.
+
+
+PREREQUISITES
+
+In order to install and use this package you will need Perl version
+5.004 or better.  Some modules within this package depend on other
+packages that are distributed separately from Perl.  We recommend that
+you have the following packages installed before you install
+libwww-perl:
+
+  MIME-Base64
+  HTML-Parser
+  libnet
+  MD5
+
+These packages should be available on CPAN.
+
+If you want to access sites using the https protocol, then you need to
+install the Crypt-SSLeay modules first.  (The Net::SSLeay module is not
+supported any more.)
+
+
+INSTALLATION
+
+You install libwww-perl, as you would install any perl module library,
+by running these commands:
+
+   perl Makefile.PL
+   make
+   make test
+   make install
+
+You can edit the configuration section of Makefile.PL to select which
+programs to install in addition to the library itself.  If you don't
+want to install any programs (only the library files) and don't want
+to mess with the Makefile.PL then pass the '-n' option to Makefile.PL:
+
+   perl Makefile.PL -n
+
+If you want to install a private copy of libwww-perl in your home
+directory, then you should try to produce the initial Makefile with
+something like this command:
+
+  perl Makefile.PL LIB=~/perl
+
+The Makefile.PL program will start out by checking your perl
+installation for a few packages that are recommended to be installed
+together with libwww-perl.
+
+Optional network tests are _not_ enabled automatically when you unpack
+this package.  Consult the t/README file for instructions on how to
+enable these tests.
+
+
+DOCUMENTATION
+
+See lib/LWP.pm for an overview of the library. See ChangeLog for
+recent changes.  POD style documentation is included in all modules
+and scripts.  These are normally converted to manual pages and
+installed as part of the "make install" process.  You should also be
+able to use the 'perldoc' utility to extract and read documentation
+from the module files directly.
+
+
+SUPPORT
+
+Question about how to use this library should be directed to the
+comp.lang.perl.modules USENET Newsgroup.  Bug reports and suggestions
+for improvements can be sendt to the <libwww-perl@ics.uci.edu> mailing
+list.  This mailing list is also the place for general discussions and
+development of the libwww-perl package.
+
+You can join the mailing list by sending a message to
+<libwww-perl-request@ics.uci.edu> with "Subscribe" as subject.
+            ^^^^^^^^
+
+AVAILABILITY
+
+The latest version of libwww-perl should always be available from:
+
+     http://www.linpro.no/lwp/
+
+The library is also available from the Comprehensive Perl Archive
+Network (CPAN).  Visit <URL:http://www.perl.com/CPAN/> to find a CPAN
+site near you.
+
+
+COPYRIGHT
+
+  © 1995-1998 Gisle Aas. All rights reserved.
+  © 1995 Martijn Koster. All rights reserved.
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+
+Enjoy!
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/TODO
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/TODO	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/TODO	(revision 16571)
@@ -0,0 +1,46 @@
+                                            $Date$
+
+This is a list over things that we plan to implement in libwww-perl-5.
+The order of items does not reflect priority.
+
+  o  HTTP/1.1 support is on its way.  This also includes support of
+     multiple parallel connections.  Take a look at LWPng (aka
+     libwww-perl-6).
+
+  o  Provide initial credentials so that we don't always have to get a
+     401 response first.  Both for Basic and Digest authentication.  This
+     is in fact implemented for LWPng.
+
+  o  HTTP::Request::Common::POST() should be able to create large
+     file upload requests by making a closure content.
+
+  o  Support PICS??
+
+  o  Cache previous ftp connections.  "Keep-Alive"?
+
+  o  Support MOVE, DELETE method for ftp.
+
+  o  Support If-Modified-Since for ftp.
+
+  o  Use Mail::Send to implement LWP::Protocol::mailto.  Today we just
+     invoke sendmail directly, which is not very portable.
+
+  o  The lwp-request -o processing should check for Content-Encoding as
+     well as Content-Type.
+
+  o  The lwp-request script should optionally consult Mail::Cap for
+     handling of media types.
+
+  o  The lwp-request script should use the callback interface so that it
+     prints data as it is received.
+
+  o  The lwp-mirror script should be able to work recursively.
+
+  o  Include more useful programs
+
+  o  More documentation
+
+  o  More tests
+
+  o  Fix bugs, if there are any...
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-download.PL
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-download.PL	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-download.PL	(revision 16571)
@@ -0,0 +1,248 @@
+use Config;
+use File::Basename qw(basename dirname);
+chdir(dirname($0));
+($file = basename($0)) =~ s/\.PL$//;
+$file =~ s/\.pl$//
+	if ($Config{'osname'} eq 'VMS' or
+	    $Config{'osname'} eq 'OS2');  # "case-forgiving"
+open OUT,">$file" or die "Can't create $file: $!";
+chmod(0755, $file);
+print "Extracting $file (with variable substitutions)\n";
+
+print OUT <<"!GROK!THIS!";
+$Config{'startperl'} -w
+
+!GROK!THIS!
+
+print OUT <<'!NO!SUBS!';
+# $Id$
+
+=head1 NAME
+
+lwp-download - fetch large files from the net
+
+=head1 SYNOPSIS
+
+ lwp-download [-a] <url> [<local file>]
+
+=head1 DESCRIPTION
+
+The I<lwp-download> program will down load the document specified by the URL
+given as the first command line argument to a local file.  The local
+filename used to save the document is guessed from the URL unless
+specified as the second command line argument.
+
+The I<lwp-download> program is implemented using the I<libwww-perl>
+library.  It is better suited to down load big files than the
+I<lwp-request> program because it does not store the file in memory.
+Another benefit is that it will keep you updated about its progress
+and that you don't have much options to worry about.
+
+Use the C<-a> option to save the file in text (ascii) mode.  Might make a
+difference on dosish systems.
+
+=head1 EXAMPLE
+
+Fetch the newest and greatest perl version:
+
+ $ lwp-download http://www.perl.com/CPAN/src/latest.tar.gz
+ Saving to 'latest.tar.gz'...
+ 1.47 MB received in 22 seconds (68.7 KB/sec)
+
+=head1 AUTHOR
+
+Gisle Aas <gisle@aas.no>
+
+=cut
+
+use LWP::UserAgent;
+use LWP::MediaTypes;
+use URI::URL;
+use strict;
+
+my $progname = $0;
+$progname =~ s,.*/,,;    # only basename left in progname
+$progname =~ s/\.\w*$//; # strip extension if any
+
+#parse option
+use Getopt::Std;
+my %opts;
+unless (getopts('a', \%opts)) {
+    usage();
+}
+my $opt_a = $opts{a}; # save in binary mode
+
+my $url = url(shift || usage());
+my $argfile = shift;
+
+my $ua = new LWP::UserAgent;
+
+$ua->agent("lwp-download/0.1 " . $ua->agent);
+$ua->env_proxy;
+
+my $req = new HTTP::Request GET => $url;
+
+my $file;      # name of file we download into
+my $length;    # total number of bytes to download
+my $flength;   # formatted length
+my $size = 0;  # number of bytes received
+my $start_t;   # start time of download
+my $last_dur;  # time of last callback
+
+my $shown = 0; # have we called the show() function yet
+
+$SIG{INT} = sub { die "Interrupted\n"; };
+
+$| = 1;  # autoflush
+
+my $res = $ua->request($req,
+  sub {
+      unless($file) {
+	  my $res = $_[1];
+	  unless ($argfile) {
+	      # must find a suitable name to use.  First thing
+	      # to do is to look for the "Content-Disposition"
+	      # header defined by RFC1806.  This is also supported
+	      # by Netscape
+	      my $cd = $res->header("Content-Disposition");
+	      if ($cd && $cd =~ /\bfilename\s*=\s*(\S+)/) {
+		  $file = $1;
+		  $file =~ s/;$//;
+		  $file =~ s/^([\"\'])(.*)\1$/$2/;
+	      }
+		
+	      # if this fails we try to make something from the URL
+	      unless ($file) {
+		  my $req = $res->request;  # now always there
+		  my $rurl = $req ? $req->url : $url;
+		  
+		  $file = ($rurl->path_components)[-1];
+		  unless (length $file) {
+		      $file = "index";
+		      my $suffix = media_suffix($res->content_type);
+		      $file .= ".$suffix" if $suffix;
+		  } elsif ($rurl->scheme eq 'ftp' ||
+			   $file =~ /\.tgz$/      ||
+			   $file =~ /\.tar(\.(Z|gz))?$/
+			  ) {
+		      # leave the filename as it was
+		  } else {
+		      my $ct = guess_media_type($file);
+		      unless ($ct eq $res->content_type) {
+			  # need a better suffix for this type
+			  my $suffix = media_suffix($res->content_type);
+			  $file .= ".$suffix" if $suffix;
+		      }
+		  }
+	      }
+
+	      # Check if the file is already present
+	      if (-f $file && -t) {
+		  print "Overwrite $file? [y] ";
+		  my $ans = <STDIN>;
+		  exit if !defined($ans) || !($ans =~ /^y?\n/);
+	      } else {
+		  print "Saving to '$file'...\n";
+	      }
+	  } else {
+	      $file = $argfile;
+	  }
+	  open(FILE, ">$file") || die "Can't open $file: $!";
+          binmode FILE unless $opt_a;
+	  $length = $res->content_length;
+	  $flength = fbytes($length) if defined $length;
+	  $start_t = time;
+	  $last_dur = 0;
+      }
+      $size += length($_[0]);
+      print FILE $_[0];
+      if (defined $length) {
+	  my $dur  = time - $start_t;
+	  if ($dur != $last_dur) {  # don't update too often
+	      $last_dur = $dur;
+	      my $perc = $size / $length;
+	      my $speed;
+	      $speed = fbytes($size/$dur) . "/sec" if $dur > 3;
+	      my $secs_left = fduration($dur/$perc - $dur);
+	      $perc = int($perc*100);
+	      my $show = "$perc% of $flength";
+	      $show .= " (at $speed, $secs_left remaining)" if $speed;
+	      show($show);
+	  }
+      } else {
+	  show( fbytes($size) . " received");
+      }
+  }
+);
+
+if ($res->is_success || $res->message =~ /^Interrupted/) {
+    show("");  # clear text
+    print "\r";
+    print fbytes($size);
+    print " of ", fbytes($length) if defined($length) && $length != $size;
+    print " received";
+    my $dur = time - $start_t;
+    if ($dur) {
+	my $speed = fbytes($size/$dur) . "/sec";
+	print " in ", fduration($dur), " ($speed)";
+    }
+    print "\n";
+    my $died = $res->header("X-Died");
+    if ($died || !$res->is_success) {
+	if (-t) {
+	    print "Transfer aborted.  Delete $file? [n] ";
+	    my $ans = <STDIN>;
+	    unlink($file) if defined($ans) && $ans =~ /^y\n/;
+	} else {
+	    print "Transfer aborted, $file kept\n";
+	}
+    }
+} else {
+    print "\n" if $shown;
+    print "$progname: Can't download: ", $res->code, " ", $res->message, "\n";
+    exit 1;
+}
+
+
+sub fbytes
+{
+    my $n = int(shift);
+    if ($n >= 1024 * 1024) {
+	return sprintf "%.3g MB", $n / (1024.0 * 1024);
+    } elsif ($n >= 1024) {
+	return sprintf "%.3g KB", $n / 1024.0;
+    } else {
+	return "$n bytes";
+    }
+}
+
+sub fduration
+{
+    use integer;
+    my $secs = int(shift);
+    my $hours = $secs / (60*60);
+    $secs -= $hours * 60*60;
+    my $mins = $secs / 60;
+    $secs %= 60;
+    if ($hours) {
+	return "$hours hours $mins minutes";
+    } elsif ($mins >= 2) {
+	return "$mins minutes";
+    } else {
+	$secs += $mins * 60;
+	return "$secs seconds";
+    }
+}
+
+sub show
+{
+    my $mess = shift;
+    print "\r$mess", (" " x (75 - length $mess));
+    $shown++;
+}
+
+sub usage
+{
+    die "Usage: $progname [-a] <url> [<lpath>]\n";
+}
+!NO!SUBS!
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-mirror.PL
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-mirror.PL	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-mirror.PL	(revision 16571)
@@ -0,0 +1,120 @@
+use Config;
+use File::Basename qw(basename dirname);
+chdir(dirname($0));
+($file = basename($0)) =~ s/\.PL$//;
+$file =~ s/\.pl$//
+	if ($Config{'osname'} eq 'VMS' or
+	    $Config{'osname'} eq 'OS2');  # "case-forgiving"
+open OUT,">$file" or die "Can't create $file: $!";
+chmod(0755, $file);
+print "Extracting $file (with variable substitutions)\n";
+
+print OUT <<"!GROK!THIS!";
+$Config{'startperl'} -w
+
+!GROK!THIS!
+
+print OUT <<'!NO!SUBS!';
+# $Id$
+#
+# Simple mirror utility using LWP
+
+=head1 NAME
+
+lwp-mirror - Simple mirror utility for WWW
+
+=head1 SYNOPSIS
+
+ lwp-mirror [-v] [-t timeout] <url> <local file>
+
+=head1 DESCRIPTION
+
+This program can be used to mirror a document from a WWW server.  The
+document is only transfered if the remote copy is newer than the local
+copy.  If the local copy is newer nothing happens.
+
+Use the C<-v> option to print the version number of this program.
+
+The timeout value specified with the C<-t> option.  The timeout value
+is the time that the program will wait for response from the remote
+server before it fails.  The default unit for the timeout value is
+seconds.  You might append "m" or "h" to the timeout value to make it
+minutes or hours, repectively.
+
+Because this program is implemented using the LWP library, it only
+supports the protocols that LWP supports.
+
+=head1 SEE ALSO
+
+L<lwp-request>, L<LWP>
+
+=head1 AUTHOR
+
+Gisle Aas <aas@a.sn.no>
+
+=cut
+
+
+use LWP::Simple;
+use Getopt::Std;
+
+$progname = $0;
+$progname =~ s,.*/,,;  # use basename only
+$progname =~ s/\.\w*$//; #strip extension if any
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+$opt_h = undef;  # print usage
+$opt_v = undef;  # print version
+$opt_t = undef;  # timeout
+
+unless (getopts("hvt:")) {
+    usage();
+}
+
+if ($opt_v) {
+    require LWP;
+    my $DISTNAME = 'libwww-perl-' . LWP::Version();
+    die <<"EOT";
+This is lwp-mirror version $VERSION ($DISTNAME)
+
+Copyright 1995-1996, Gisle Aas.
+
+This program is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+EOT
+}
+
+$url  = shift or usage();
+$file = shift or usage();
+usage() if $opt_h or @ARGV;
+
+if (defined $opt_t) {
+    $opt_t =~ /^(\d+)([smh])?/;
+    die "$progname: Illegal timeout value!\n" unless defined $1;
+    $timeout = $1;
+    $timeout *= 60   if ($2 eq "m");
+    $timeout *= 3600 if ($2 eq "h");
+    $LWP::Simple::ua->timeout($timeout);
+}
+
+$rc = mirror($url, $file);
+
+if ($rc == 304) {
+    print STDERR "$progname: $file is up to date\n"
+} elsif (!is_success($rc)) {
+    print STDERR "$progname: $rc ", status_message($rc), "   ($url)\n";
+    exit 1;
+}
+exit;
+
+
+sub usage
+{
+    die <<"EOT";
+Usage: $progname [-options] <url> <file>
+    -v           print version number of program
+    -t <timeout> Set timeout value
+EOT
+}
+!NO!SUBS!
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-request.PL
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-request.PL	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-request.PL	(revision 16571)
@@ -0,0 +1,521 @@
+use Config;
+use File::Basename qw(basename dirname);
+chdir(dirname($0));
+($file = basename($0)) =~ s/\.PL$//;
+$file =~ s/\.pl$//
+	if ($Config{'osname'} eq 'VMS' or
+	    $Config{'osname'} eq 'OS2');  # "case-forgiving"
+open OUT,">$file" or die "Can't create $file: $!";
+chmod(0755, $file);
+print "Extracting $file (with variable substitutions)\n";
+
+print OUT <<"!GROK!THIS!";
+$Config{'startperl'} -w
+
+!GROK!THIS!
+
+print OUT <<'!NO!SUBS!';
+# $Id$
+#
+# Simple user agent using LWP library.
+
+=head1 NAME
+
+lwp-request, GET, HEAD, POST - Simple WWW user agent
+
+=head1 SYNOPSIS
+
+ lwp-request [-aeEdvhx] [-m method] [-b <base URL>] [-t <timeout>]
+             [-i <if-modified-since>] [-c <content-type>] [-C <credentials>]
+             [-p <proxy-url>] [-o <format>] <url>...
+
+=head1 DESCRIPTION
+
+This program can be used to send requests to WWW servers and your
+local file system. The request content for POST, PUT and CHECKIN
+methods is read from stdin.  The content of the response is printed on
+stdout.  Error messages are printed on stderr.  The program returns a
+status value indicating the number of URLs that failed.
+
+The options are:
+
+=over 4
+
+=item -m <method>
+
+Set which method to use for the request.  If this option is not used,
+then the method is derived from the name of the program.
+
+=item -f
+
+Force request through, even if the program believes that the method is
+illegal.  The server will probably reject the request.
+
+=item -b <url>
+
+This URL will be used as the base URL for the URLs that the method is
+applied to.  The base URL only takes effect for relative URLs.  If you
+do not provide this option and the URLs are relative, then they will
+be treated as files in the local file system.
+
+=item -t <timeout>
+
+Set the timeout value for the requests.  The timeout is the amount of
+time that the program will wait for a response from the remote server
+before it fails.  The default unit for the timeout value is seconds.
+You might append "m" or "h" to the timeout value to make it minutes or
+hours, respectively.  The default timeout is '3m', i.e. 3 minutes.
+
+=item -i <time>
+
+Set the If-Modified-Since header in the request. If I<time> it the
+name of a file, use the modification timestamp for this file. If
+I<time> is not a file, it is parsed as a literal date. Take a look at
+L<HTTP::Date> for recogniced formats.
+
+=item -c <content-type>
+
+Set the Content-Type for the request.  This option is only allowed for
+requests that take a content, i.e. POST, PUT and CHECKIN.  You can
+force methods to take content by using the C<-f> option together with
+C<-c>.  The default Content-Type for POST is
+C<application/x-www-form-urlencoded>.  The default Content-type for
+the others is C<text/plain>.
+
+=item -p <proxy-url>
+
+Set the proxy to be used for the requests.  The program also loads
+proxy settings from the environment.  You can disable this with the
+C<-P> option.
+
+=item -C <username>:<password>
+
+Provide credentials for documents that are protected by Basic
+Authentication.  If the document is protected and you did not specify
+the username and password with this option, then you will be prompted
+to provide these values.
+
+=back
+
+The following options controls what is displayed by the program:
+
+=over 4
+
+=item -u
+
+Print request method and absolute URL as requests are made.
+
+=item -U
+
+Print request headers in addition to request method and absolute URL.
+
+=item -s
+
+Print response status code.  This option is always on for HEAD requests.
+
+=item -S
+
+Print response status chain. This shows redirect and autorization
+requests that are handled by the library.
+
+=item -e
+
+Print response headers.  This option is always on for HEAD requests.
+
+=item -d
+
+Do B<not> print the content of the response.
+
+=item -o <format>
+
+Process HTML content in various ways before printing it.  If the
+content type of the response is not HTML, then this option has no
+effect.  The legal format values are; I<text>, I<ps>, I<links>,
+I<html> and I<dump>.
+
+If you specify the I<text> format then the HTML will be formatted as
+plain latin1 text.  If you specify the I<ps> format then it will be
+formatted as Postscript.
+
+The I<links> format will output all links found in the HTML document.
+Relative links will be expanded to absolute ones.
+
+The I<html> format will reformat the HTML code and the I<dump> format
+will just dump the HTML syntax tree.
+
+=item -v
+
+Print the version number of the program and quit.
+
+=item -h
+
+Print usage message and quit.
+
+=item -x
+
+Extra debugging output.
+
+=item -a
+
+Set text(ascii) mode for content input and output.  If this option is not 
+used, content input and output is done in binary mode.
+
+=back
+
+Because this program is implemented using the LWP library, it will
+only support the protocols that LWP supports.
+
+=head1 SEE ALSO
+
+L<lwp-mirror>, L<LWP>
+
+=head1 COPYRIGHT
+
+Copyright 1995-1997 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=head1 AUTHOR
+
+Gisle Aas <aas@sn.no>
+
+=cut
+
+$progname = $0;
+$progname =~ s,.*/,,;  # use basename only
+$progname =~ s/\.\w*$//; # strip extension, if any
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+
+require LWP;
+require LWP::Debug;
+require URI::URL;
+
+use URI::Heuristic qw(uf_url);
+
+use HTTP::Status qw(status_message);
+use HTTP::Date qw(time2str str2time);
+
+
+# This table lists the methods that are allowed.  It should really be
+# a superset for all methods supported for every scheme that may be
+# supported by the library.  Currently it might be a bit too HTTP
+# specific.  You might use the -f option to force a method through.
+#
+# "" = No content in request, "C" = Needs content in request
+#
+%allowed_methods = (
+    GET        => "",
+    HEAD       => "",
+    POST       => "C",
+    PUT        => "C",
+    DELETE     => "",
+    TRACE      => "",
+    OPTIONS    => "",
+);
+
+
+# We make our own specialization of LWP::UserAgent that asks for
+# user/password if document is protected.
+{
+    package RequestAgent;
+    @ISA = qw(LWP::UserAgent);
+
+    sub new
+    { 
+	my $self = LWP::UserAgent::new(@_);
+	$self->agent("lwp-request/$main::VERSION");
+	$self;
+    }
+
+    sub get_basic_credentials
+    {
+	my($self, $realm, $uri) = @_;
+	if ($main::opt_C) {
+	    return split(':', $main::opt_C, 2);
+	} elsif (-t) {
+	    my $netloc = $uri->netloc;
+	    print "Enter username for $realm at $netloc: ";
+	    my $user = <STDIN>;
+	    chomp($user);
+	    return (undef, undef) unless length $user;
+	    print "Password: ";
+	    system("stty -echo");
+	    my $password = <STDIN>;
+	    system("stty echo");
+	    print "\n";  # because we disabled echo
+	    chomp($password);
+	    return ($user, $password);
+	} else {
+	    return (undef, undef)
+	}
+    }
+}
+
+$method = uc(lc($progname) eq "lwp-request" ? "GET" : $progname);
+
+# Parse command line
+use Getopt::Std;
+
+$opt_a = undef;  # content i/o in text(ascii) mode
+$opt_m = undef;  # set method
+$opt_f = undef;  # make request even if method is not in %allowed_methods
+$opt_b = undef;  # base url
+$opt_t = undef;  # timeout
+$opt_i = undef;  # if-modified-since
+$opt_c = undef;  # content type for POST
+$opt_C = undef;  # credidentials for basic authorization
+
+$opt_u = undef;  # display method, URL and headers of request
+$opt_U = undef;  # display request headers also
+$opt_s = undef;  # display status code
+$opt_S = undef;  # display whole chain of status codes
+$opt_e = undef;  # display response headers (default for HEAD)
+$opt_d = undef;  # don't display content
+
+$opt_h = undef;  # print usage
+$opt_v = undef;  # print version
+
+$opt_x = undef;  # extra debugging info
+$opt_p = undef;  # proxy URL
+$opt_P = undef;  # don't load proxy setting from environment
+
+$opt_o = undef;  # output format
+
+unless (getopts("axhvuUsSedPp:b:t:i:c:C:m:fo:")) {
+    usage();
+}
+
+if ($opt_v) {
+    require LWP;
+    my $DISTNAME = 'libwww-perl-' . LWP::Version();
+    die <<"EOT";
+This is lwp-request version $VERSION ($DISTNAME)
+
+Copyright 1995-1997, Gisle Aas.
+
+This program is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+EOT
+}
+
+usage() if $opt_h || !@ARGV;
+
+LWP::Debug::level('+') if $opt_x;
+
+# Create the user agent object
+$ua = new RequestAgent;
+
+# Load proxy settings from *_proxy environment variables.
+$ua->env_proxy unless $opt_P;
+
+$method = uc($opt_m) if defined $opt_m;
+
+if ($opt_f) {
+    if ($opt_c) {
+        $allowed_methods{$method} = "C";  # force content
+    } else {
+        $allowed_methods{$method} = "";
+    }
+} elsif (!defined $allowed_methods{$method}) {
+    die "$progname: $method is not an allowed method\n";
+}
+
+if ($method eq "HEAD") {
+    $opt_s = 1;
+    $opt_e = 1 unless $opt_d;
+    $opt_d = 1;
+}
+
+if (defined $opt_t) {
+    $opt_t =~ /^(\d+)([smh])?/;
+    die "$progname: Illegal timeout value!\n" unless defined $1;
+    $timeout = $1;
+    $timeout *= 60   if ($2 eq "m");
+    $timeout *= 3600 if ($2 eq "h");
+    $ua->timeout($timeout);
+}
+
+if (defined $opt_i) {
+    if (-e $opt_i) {
+        $time = (stat _)[9];
+    } else {
+        $time = str2time($opt_i);
+        die "$progname: Illegal time syntax for -i option\n"
+            unless defined $time;
+    }
+    $opt_i = time2str($time);
+}
+
+$content = undef;
+if ($allowed_methods{$method} eq "C") {
+    # This request needs some content
+    unless (defined $opt_c) {
+        # set default content type
+        $opt_c = ($method eq "POST") ?
+              "application/x-www-form-urlencoded"
+            : "text/plain";
+    } else {
+        die "$progname: Illegal Content-type format\n"
+            unless $opt_c =~ m,^[\w\-]+/[\w\-]+(?:\s*;.*)?$,
+    }
+    print "Please enter content ($opt_c) to be ${method}ed:\n"
+        if -t;
+    binmode STDIN unless -t or $opt_a;
+    $content = join("", <STDIN>);
+} else {
+    die "$progname: Can't set Content-type for $method requests\n"
+        if defined $opt_c;
+}
+
+# Set up a request.  We will use the same request object for all URLs.
+$request = new HTTP::Request $method;
+$request->header('If-Modified-Since', $opt_i) if defined $opt_i;
+#$request->header('Accept', '*/*');
+if ($opt_c) { # will always be set for request that wants content
+    $request->header('Content-Type', $opt_c);
+    $request->header('Content-Length', length $content);  # Not really needed
+    $request->content($content);
+}
+
+
+$errors = 0;
+
+# Ok, now we perform the requests, one URL at a time
+while ($url = shift) {
+    # Create the URL object, but protect us against bad URLs
+    eval {
+	if ($url =~ /^\w+:/ || $opt_b) {  # is there any scheme specification
+	    $url = URI::URL->new($url, $opt_b);
+	} else {
+	    $url = uf_url($url);
+        }
+    };
+    if ($@) {
+	$@ =~ s/at\s+\S+\s+line\s\d+//;
+	print STDERR $@;
+	$errors++;
+	next;
+    }
+
+    $ua->proxy($url->scheme, $opt_p) if $opt_p;
+
+    # Send the request and get a response back from the server
+    $request->url($url);
+    $response = $ua->request($request);
+
+    if ($opt_u || $opt_U) {
+        my $url = $response->request->url->as_string;
+        print "$method $url\n";
+        print $response->request->headers_as_string, "\n" if $opt_U;
+    }
+
+    if ($opt_S) {
+	printResponseChain($response);
+    } elsif ($opt_s) {
+        print $response->status_line, "\n";
+    }
+
+    if ($opt_e) {
+        # Display headers
+        print $response->headers_as_string;
+        print "\n";  # separate headers and content
+    }
+
+    if ($response->is_success) {
+	unless ($opt_d) {
+	    if ($opt_o &&
+		$response->content_type eq 'text/html') {
+		require HTML::Parse;
+		my $html = HTML::Parse::parse_html($response->content);
+		{
+		    $opt_o eq 'ps' && do {
+			require HTML::FormatPS;
+			my $f = new HTML::FormatPS;
+			print $f->format($html);
+			last;
+		    };
+		    $opt_o eq 'text' && do {
+			require HTML::FormatText;
+			my $f = new HTML::FormatText;
+			print $f->format($html);
+			last;
+		    };
+		    $opt_o eq 'html' && do {
+			print $html->as_HTML;
+			last;
+		    };
+		    $opt_o eq 'links' && do {
+			my $base = $response->base;
+			for ( @{ $html->extract_links } ) {
+			    my($link, $elem) = @$_;
+			    my $tag = uc $elem->tag;
+			    $link = new URI::URL $link, $base;
+			    print "$tag\t", $link->abs->as_string, "\n";
+			}
+			last;
+		    };
+		    $opt_o eq 'dump' && do {
+			$html->dump;
+			last;
+		    };
+		    # It is bad to not notice this before now :-(
+		    die "Illegal -o option value ($opt_o)\n";
+		}
+	    } else {
+                binmode STDOUT unless $opt_a;
+		print $response->content;
+	    }
+	}
+    } else {
+        print STDERR $response->error_as_HTML unless $opt_d;
+        $errors++;
+    }
+}
+
+exit $errors;
+
+
+sub printResponseChain
+{
+    my($response) = @_;
+    return unless defined $response;
+    printResponseChain($response->previous);
+    my $method = $response->request->method;
+    my $url = $response->request->url->as_string;
+    my $code = $response->code;
+    print "$method $url --> ", $response->status_line, "\n";
+}
+
+
+sub usage
+{
+    die <<"EOT";
+Usage: $progname [-options] <url>...
+    -m <method>   use method for the request (default is '$method')
+    -f            make request even if $progname believes method is illegal
+    -b <base>     Use the specified URL as base
+    -t <timeout>  Set timeout value
+    -i <time>     Set the If-Modified-Since header on the request
+    -c <conttype> use this content-type for POST, PUT, CHECKIN
+    -a            Use text mode for content I/O
+    -p <proxyurl> use this as a proxy
+    -P            don't load proxy settings from environment
+
+    -u            Display method and URL before any response
+    -U            Display request headers (implies -u)
+    -s            Display response status code
+    -S            Display response status chain
+    -e            Display response headers
+    -d            Do not display content
+    -o <format>   Process HTML content in various ways
+
+    -v            Show program version
+    -h            Print this message
+
+    -x            Extra debugging output
+EOT
+}
+!NO!SUBS!
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-rget.PL
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-rget.PL	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/bin/lwp-rget.PL	(revision 16571)
@@ -0,0 +1,600 @@
+use Config;
+use File::Basename qw(basename dirname);
+chdir(dirname($0));
+($file = basename($0)) =~ s/\.PL$//;
+$file =~ s/\.pl$//
+	if ($Config{'osname'} eq 'VMS' or
+	    $Config{'osname'} eq 'OS2');  # "case-forgiving"
+open OUT,">$file" or die "Can't create $file: $!";
+chmod(0755, $file);
+print "Extracting $file (with variable substitutions)\n";
+
+print OUT <<"!GROK!THIS!";
+$Config{'startperl'} -w
+
+!GROK!THIS!
+
+print OUT <<'!NO!SUBS!';
+#line 18
+
+=head1 NAME
+
+lwp-rget - Retrieve WWW documents recursively
+
+=head1 SYNOPSIS
+
+ lwp-rget [--verbose] [--auth=USER:PASS] [--depth=N] [--hier] [--iis]
+	  [--keepext=mime/type[,mime/type]] [--limit=N] [--nospace]
+	  [--prefix=URL] [--sleep=N] [--tolower] <URL>
+ lwp-rget --version
+
+=head1 DESCRIPTION
+
+This program will retrieve a document and store it in a local file.  It
+will follow any links found in the document and store these documents
+as well, patching links so that they refer to these local copies.
+This process continues until there are no more unvisited links or the
+process is stopped by the one or more of the limits which can be
+controlled by the command line arguments.
+
+This program is useful if you want to make a local copy of a
+collection of documents or want to do web reading off-line.
+
+All documents are stored as plain files in the current directory. The
+file names chosen are derived from the last component of URL paths.
+
+The options are:
+
+=over 3
+
+=item --auth=USER:PASS<n>
+
+Set the authentication credentials to user "USER" and password "PASS" if
+any restricted parts of the web site are hit.  If there are restricted
+parts of the web site and authentication credentials are not available,
+those pages will not be downloaded.
+
+=item --depth=I<n>
+
+Limit the recursive level. Embedded images are always loaded, even if
+they fall outside the I<--depth>. This means that one can use
+I<--depth=0> in order to fetch a single document together with all
+inline graphics.
+
+The default depth is 5.
+
+=item --hier
+
+Download files into a hierarchy that mimics the web site structure.
+The default is to put all files in the current directory.
+
+=item --iis
+
+Sends an "Accept: */*" on all URL requests as a workaround for a bug in
+IIS 2.0.  If no Accept MIME header is present, IIS 2.0 returns with a
+"406 No acceptable objects were found" error.  Also converts any back
+slashes (\\) in URLs to forward slashes (/).
+
+=item --keepext=I<mime/type[,mime/type]>
+
+Keeps the current extension for the list MIME types.  Useful when
+downloading text/plain documents that shouldn't all be translated to
+*.txt files.
+
+=item --limit=I<n>
+
+Limit the number of documents to get.  The default limit is 50.
+
+=item --nospace
+
+Changes spaces in all URLs to underscore characters (_).  Useful when
+downloading files from sites serving URLs with spaces in them.	Does not
+remove spaces from fragments, e.g., "file.html#somewhere in here".
+
+=item --prefix=I<url_prefix>
+
+Limit the links to follow. Only URLs that start the prefix string are
+followed.
+
+The default prefix is set as the "directory" of the initial URL to
+follow.	 For instance if we start lwp-rget with the URL
+C<http://www.sn.no/foo/bar.html>, then prefix will be set to
+C<http://www.sn.no/foo/>.
+
+Use C<--prefix=''> if you don't want the fetching to be limited by any
+prefix.
+
+=item --sleep=I<n>
+
+Sleep I<n> seconds before retrieving each document. This options allows
+you to go slowly, not loading the server you visiting too much.
+
+=item --tolower
+
+Translates all links to lowercase.  Useful when downloading files from
+IIS since it does not serve files in a case sensitive manner.
+
+=item --verbose
+
+Make more noise while running.
+
+=item --quiet
+
+Don't make any noise.
+
+=item --version
+
+Print program version number and quit.
+
+=item --help
+
+Print the usage message and quit.
+
+=back
+
+Before the program exits the name of the file, where the initial URL
+is stored, is printed on stdout.  All used filenames are also printed
+on stderr as they are loaded.  This printing can be suppressed with
+the I<--quiet> option.
+
+=head1 SEE ALSO
+
+L<lwp-request>, L<LWP>
+
+=head1 AUTHOR
+
+Gisle Aas <aas@sn.no>
+
+=cut
+
+use strict;
+
+use Getopt::Long    qw(GetOptions);
+use URI::URL	    qw(url);
+use LWP::MediaTypes qw(media_suffix);
+
+use vars qw($VERSION);
+use vars qw($MAX_DEPTH $MAX_DOCS $PREFIX $VERBOSE $QUIET $SLEEP $HIER $AUTH $IIS $TOLOWER $NOSPACE %KEEPEXT);
+
+my $progname = $0;
+$progname =~ s|.*/||;  # only basename left
+$progname =~ s/\.\w*$//; #strip extension if any
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+#$Getopt::Long::debug = 1;
+#$Getopt::Long::ignorecase = 0;
+
+# Defaults
+$MAX_DEPTH = 5;
+$MAX_DOCS  = 50;
+
+GetOptions('version'  => \&print_version,
+	   'help'     => \&usage,
+	   'depth=i'  => \$MAX_DEPTH,
+	   'limit=i'  => \$MAX_DOCS,
+	   'verbose!' => \$VERBOSE,
+	   'quiet!'   => \$QUIET,
+	   'sleep=i'  => \$SLEEP,
+	   'prefix:s' => \$PREFIX,
+	   'hier'     => \$HIER,
+	   'auth=s'   => \$AUTH,
+	   'iis'      => \$IIS,
+	   'tolower'  => \$TOLOWER,
+	   'nospace'  => \$NOSPACE,
+	   'keepext=s' => \$KEEPEXT{'OPT'},
+	  ) || usage();
+
+sub print_version {
+    require LWP;
+    my $DISTNAME = 'libwww-perl-' . LWP::Version();
+    print <<"EOT";
+This is lwp-rget version $VERSION ($DISTNAME)
+
+Copyright 1996-1998, Gisle Aas.
+
+This program is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+EOT
+    exit 0;
+}
+
+my $start_url = shift || usage();
+usage() if @ARGV;
+
+require LWP::UserAgent;
+my $ua = new LWP::UserAgent;
+$ua->agent("$progname/$VERSION " . $ua->agent);
+$ua->env_proxy;
+
+unless (defined $PREFIX) {
+    $PREFIX = url($start_url);	 # limit to URLs below this one
+    eval {
+	$PREFIX->eparams(undef);
+	$PREFIX->equery(undef);
+    };
+
+    $_ = $PREFIX->epath;
+    s|[^/]+$||;
+    $PREFIX->epath($_);
+    $PREFIX = $PREFIX->as_string;
+}
+
+%KEEPEXT = map { lc($_) => 1 } split(/\s*,\s*/, $KEEPEXT{'OPT'});
+
+print <<"" if $VERBOSE;
+START	  = $start_url
+MAX_DEPTH = $MAX_DEPTH
+MAX_DOCS  = $MAX_DOCS
+PREFIX	  = $PREFIX
+
+
+my $no_docs = 0;
+my %seen = ();	   # mapping from URL => local_file
+
+my $filename = fetch($start_url);
+print "$filename\n" unless $QUIET;
+
+sub fetch
+{
+    my($url, $type, $depth) = @_;
+
+    # Fix http://sitename.com/../blah/blah.html to
+    #	  http://sitename.com/blah/blah.html
+    $url = $url->as_string if (ref($url));
+    while ($url =~ s#(https?://[^/]+/)\.\.\/#$1#) {}
+
+    # Fix backslashes (\) in URL if $IIS defined
+    $url = fix_backslashes($url) if (defined $IIS);
+
+    $url = url($url) unless ref($url);
+    $type  ||= 'a';
+    # Might be the background attribute
+    $type = 'img' if ($type eq 'body' || $type eq 'td');
+    $depth ||= 0;
+
+    # Print the URL before we start checking...
+    my $out = (" " x $depth) . $url . " ";
+    $out .= "." x (60 - length($out));
+    print STDERR $out . " " if $VERBOSE;
+
+    # Can't get mailto things
+    if ($url->scheme eq 'mailto') {
+	print STDERR "*skipping mailto*\n" if $VERBOSE;
+	return $url->as_string;
+    }
+
+    # The $plain_url is a URL without the fragment part
+    my $plain_url = $url->clone;
+    $plain_url->frag(undef);
+
+    # Check PREFIX, but not for <IMG ...> links
+    if ($type ne 'img' and  $url->as_string !~ /^\Q$PREFIX/o) {
+	print STDERR "*outsider*\n" if $VERBOSE;
+	return $url->as_string;
+    }
+
+    # Translate URL to lowercase if $TOLOWER defined
+    $plain_url = to_lower($plain_url) if (defined $TOLOWER);
+
+    # If we already have it, then there is nothing to be done
+    my $seen = $seen{$plain_url->as_string};
+    if ($seen) {
+	my $frag = $url->frag;
+	$seen .= "#$frag" if defined($frag);
+	$seen = protect_frag_spaces($seen);
+	print STDERR "$seen (again)\n" if $VERBOSE;
+	return $seen;
+    }
+
+    # Too much or too deep
+    if ($depth > $MAX_DEPTH and $type ne 'img') {
+	print STDERR "*too deep*\n" if $VERBOSE;
+	return $url;
+    }
+    if ($no_docs > $MAX_DOCS) {
+	print STDERR "*too many*\n" if $VERBOSE;
+	return $url;
+    }
+
+    # Fetch document 
+    $no_docs++;
+    sleep($SLEEP) if $SLEEP;
+    my $req = HTTP::Request->new(GET => $url);
+    # See: http://ftp.sunet.se/pub/NT/mirror-microsoft/kb/Q163/7/74.TXT
+    $req->header ('Accept', '*/*') if (defined $IIS);  # GIF/JPG from IIS 2.0
+    $req->authorization_basic(split (/:/, $AUTH)) if (defined $AUTH);
+    my $res = $ua->request($req);
+
+    # Check outcome
+    if ($res->is_success) {
+	my $doc = $res->content;
+	my $ct = $res->content_type;
+	my $name = find_name($res->request->url, $ct);
+	print STDERR "$name\n" unless $QUIET;
+	$seen{$plain_url->as_string} = $name;
+
+	# If the file is HTML, then we look for internal links
+	if ($ct eq "text/html") {
+	    # Save an unprosessed version of the HTML document.	 This
+	    # both reserves the name used, and it also ensures that we
+	    # don't loose everything if this program is killed before
+	    # we finish.
+	    save($name, $doc);
+	    my $base = $res->base;
+
+	    # Follow and substitute links...
+	    $doc =~
+s/
+  (
+    <(img|a|body|area|frame|td)\b   # some interesting tag
+    [^>]+			    # still inside tag (not strictly correct)
+    \b(?:src|href|background)	    # some link attribute
+    \s*=\s*			    # =
+  )
+    (?:				    # scope of OR-ing
+	 (")([^"]*)"	|	    # value in double quotes  OR
+	 (')([^']*)'	|	    # value in single quotes  OR
+	    ([^\s>]+)		    # quoteless value
+    )
+/
+  new_link($1, lc($2), $3||$5, $4||$6||$7, $base, $name, $depth+1)
+/giex;
+	   # XXX
+	   # The regular expression above is not strictly correct.
+	   # It is not really possible to parse HTML with a single
+	   # regular expression, but it is faster.  Tags that might
+	   # confuse us include:
+	   #	<a alt="href" href=link.html>
+	   #	<a alt=">" href="link.html">
+	   #
+	}
+	save($name, $doc);
+	return $name;
+    } else {
+	print STDERR $res->code . " " . $res->message . "\n" if $VERBOSE;
+	$seen{$plain_url->as_string} = $url->as_string;
+	return $url->as_string;
+    }
+}
+
+sub new_link
+{
+    my($pre, $type, $quote, $url, $base, $localbase, $depth) = @_;
+
+    $url = protect_frag_spaces($url);
+
+    $url = fetch(url($url, $base)->abs, $type, $depth);
+    $url = url("file:$url", "file:$localbase")->rel
+	unless $url =~ /^[.+\-\w]+:/;
+
+    $url = unprotect_frag_spaces($url);
+
+    return $pre . $quote . $url . $quote;
+}
+
+
+sub protect_frag_spaces
+{
+    my ($url) = @_;
+
+    $url = $url->as_string if (ref($url));
+
+    if ($url =~ m/^([^#]*#)(.+)$/)
+    {
+      my ($base, $frag) = ($1, $2);
+      $frag =~ s/ /%20/g;
+      $url = $base . $frag;
+    }
+
+    return $url;
+}
+
+
+sub unprotect_frag_spaces
+{
+    my ($url) = @_;
+
+    $url = $url->as_string if (ref($url));
+
+    if ($url =~ m/^([^#]*#)(.+)$/)
+    {
+      my ($base, $frag) = ($1, $2);
+      $frag =~ s/%20/ /g;
+      $url = $base . $frag;
+    }
+
+    return $url;
+}
+
+
+sub fix_backslashes
+{
+    my ($url) = @_;
+    my ($base, $frag);
+
+    $url = $url->as_string if (ref($url));
+
+    if ($url =~ m/([^#]+)(#.*)/)
+    {
+      ($base, $frag) = ($1, $2);
+    }
+    else
+    {
+      $base = $url;
+      $frag = "";
+    }
+
+    $base =~ tr/\\/\//;
+    $base =~ s/%5[cC]/\//g;	# URL-encoded back slash is %5C
+
+    return $base . $frag;
+}
+
+
+sub to_lower
+{
+    my ($url) = @_;
+    my $was_object = 0;
+
+    if (ref($url))
+    {
+      $url = $url->as_string;
+      $was_object = 1;
+    }
+
+    if ($url =~ m/([^#]+)(#.*)/)
+    {
+      $url = lc($1) . $2;
+    }
+    else
+    {
+      $url = lc($url);
+    }
+
+    if ($was_object == 1)
+    {
+      return url($url);
+    }
+    else
+    {
+      return $url;
+    }
+}
+
+
+sub translate_spaces
+{
+    my ($url) = @_;
+    my ($base, $frag);
+
+    $url = $url->as_string if (ref($url));
+
+    if ($url =~ m/([^#]+)(#.*)/)
+    {
+      ($base, $frag) = ($1, $2);
+    }
+    else
+    {
+      $base = $url;
+      $frag = "";
+    }
+
+    $base =~ s/^ *//;	# Remove initial spaces from base
+    $base =~ s/ *$//;	# Remove trailing spaces from base
+
+    $base =~ tr/ /_/;
+    $base =~ s/%20/_/g; # URL-encoded space is %20
+
+    return $base . $frag;
+}
+
+
+sub mkdirp
+{
+    my($directory, $mode) = @_;
+    my @dirs = split(/\//, $directory);
+    my $path = shift(@dirs);   # build it as we go
+    my $result = 1;   # assume it will work
+
+    unless (-d $path) {
+	$result &&= mkdir($path, $mode);
+    }
+
+    foreach (@dirs) {
+	$path .= "/$_";
+	if ( ! -d $path) {
+	    $result &&= mkdir($path, $mode);
+	}
+    }
+
+    return $result;
+}
+
+
+sub find_name
+{
+    my($url, $type) = @_;
+    #print "find_name($url, $type)\n";
+
+    # Translate spaces in URL to underscores (_) if $NOSPACE defined
+    $url = translate_spaces($url) if (defined $NOSPACE);
+
+    # Translate URL to lowercase if $TOLOWER defined
+    $url = to_lower($url) if (defined $TOLOWER);
+
+    $url = url($url) unless ref($url);
+
+    my $path = $url->path;
+
+    # trim path until only the basename is left
+    $path =~ s|(.*/)||;
+    my $dirname = ".$1";
+    if (!$HIER) {
+	$dirname = "";
+    } elsif (! -d $dirname) {
+	mkdirp($dirname, 0775);
+    }
+
+    my $extra = "";  # something to make the name unique
+    my $suffix;
+
+    if ($KEEPEXT{lc($type)}) {
+        $suffix = ($path =~ m/\.(.*)/) ? $1 : "";
+    } else {
+        $suffix = media_suffix($type);
+    }
+
+    $path =~ s|\..*||;	# trim suffix
+    $path = "index" unless length $path;
+
+    while (1) {
+	# Construct a new file name
+	my $file = $dirname . $path . $extra;
+	$file .= ".$suffix" if $suffix;
+	# Check if it is unique
+	return $file unless -f $file;
+
+	# Try something extra
+	unless ($extra) {
+	    $extra = "001";
+	    next;
+	}
+	$extra++;
+    }
+}
+
+
+sub save
+{
+    my $name = shift;
+    #print "save($name,...)\n";
+    open(FILE, ">$name") || die "Can't save $name: $!";
+    binmode FILE;
+    print FILE $_[0];
+    close(FILE);
+}
+
+
+sub usage
+{
+    die <<"";
+Usage: $progname [options] <URL>
+Allowed options are:
+  --auth=USER:PASS  Set authentication credentials for web site
+  --depth=N	    Maximum depth to traverse (default is $MAX_DEPTH)
+  --hier	    Download into hierarchy (not all files into cwd)
+  --iis		    Workaround IIS 2.0 bug by sending "Accept: */*" MIME
+		    header; translates backslashes (\\) to forward slashes (/)
+  --keepext=type    Keep file extension for MIME types (comma-separated list)
+  --limit=N	    A limit on the number documents to get (default is $MAX_DOCS)
+  --nospace	    Translate spaces URLs (not #fragments) to underscores (_)
+  --version	    Print version number and quit
+  --verbose	    More output
+  --quiet	    No output
+  --sleep=SECS	    Sleep between gets, ie. go slowly
+  --prefix=PREFIX   Limit URLs to follow to those which begin with PREFIX
+  --tolower	    Translate all URLs to lowercase (useful with IIS servers)
+
+}
+!NO!SUBS!
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/install.sh
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/install.sh	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/install.sh	(revision 16571)
@@ -0,0 +1,10 @@
+#!/bin/sh -v
+
+export PERL5LIB=$GSDLHOME/perllib/cpan/lib:$PERL5LIB
+export PATH=$GSDLHOME/perllib/cpan/bin:$PATH
+
+perl Makefile.PL PREFIX=$GSDLHOME/perllib/cpan
+
+make
+make test
+make install
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/Bundle/LWP.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/Bundle/LWP.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/Bundle/LWP.pm	(revision 16571)
@@ -0,0 +1,38 @@
+package Bundle::LWP;
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+1;
+
+__END__
+
+=head1 NAME
+
+Bundle::LWP - A bundle to install all libwww-perl related modules
+
+=head1 SYNOPSIS
+
+ perl -MCPAN -e 'install Bundle::LWP'
+
+=head1 CONTENTS
+
+Net::FTP 2.00      - If you want ftp://-support
+
+MIME::Base64       - Used in authentication headers
+
+MD5                - Needed to do Digest authentication
+
+HTML::HeadParser   - To get the correct $res->base
+
+LWP                - The reason why you need the modules above
+
+=head1 DESCRIPTION
+
+This bundle defines all reqreq modules for libwww-perl.
+
+
+=head1 AUTHOR
+
+Gisle Aas E<lt>aas@sn.no>
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/File/Listing.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/File/Listing.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/File/Listing.pm	(revision 16571)
@@ -0,0 +1,314 @@
+#
+# $Id$
+
+package File::Listing;
+
+sub Version { $VERSION; }
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+=head1 NAME
+
+parse_dir - parse directory listing
+
+=head1 SYNOPSIS
+
+ use File::Listing;
+ for (parse_dir(`ls -l`)) {
+     ($name, $type, $size, $mtime, $mode) = @$_;
+     next if $type ne 'f'; # plain file
+     #...
+ }
+
+ # directory listing can also be read from a file
+ open(LISTING, "zcat ls-lR.gz|");
+ $dir = parse_dir(\*LISTING, '+0000');
+
+=head1 DESCRIPTION
+
+The parse_dir() routine can be used to parse directory
+listings. Currently it only understand Unix C<'ls -l'> and C<'ls -lR'>
+format.  It should eventually be able to most things you might get
+back from a ftp server file listing (LIST command), i.e. VMS listings,
+NT listings, DOS listings,...
+
+The first parameter to parse_dir() is the directory listing to parse.
+It can be a scalar, a reference to an array of directory lines or a
+glob representing a filehandle to read the directory listing from.
+
+The second parameter is the time zone to use when parsing time stamps
+in the listing. If this value is undefined, then the local time zone is
+assumed.
+
+The third parameter is the type of listing to assume.  The values will
+be strings like 'unix', 'vms', 'dos'.  Currently only 'unix' is
+implemented and this is also the default value.  Ideally, the listing
+type should be determined automatically.
+
+The fourth parameter specify how unparseable lines should be treated.
+Values can be 'ignore', 'warn' or a code reference.  Warn means that
+the perl warn() function will be called.  If a code reference is
+passed, then this routine will be called and the return value from it
+will be incorporated in the listing.  The default is 'ignore'.
+
+Only the first parameter is mandatory.  The parse_dir() prototype is
+($;$$$).
+
+The return value from parse_dir() is a list of directory entries.  In
+scalar context the return value is a reference to the list.  The
+directory entries are represented by an array consisting of [
+$filename, $filetype, $filesize, $filetime, $filemode ].  The
+$filetype value is one of the letters 'f', 'd', 'l' or '?'.  The
+$filetime value is converted to seconds since Jan 1, 1970.  The
+$filemode is a bitmask like the mode returned by stat().
+
+=head1 CREDITS
+
+Based on lsparse.pl (from Lee McLoughlin's ftp mirror package) and
+Net::FTP's parse_dir (Graham Barr).
+
+=cut
+
+require Exporter;
+@ISA = qw(Exporter);
+
+@EXPORT = qw(parse_dir);
+
+use strict;
+
+use Carp ();
+use HTTP::Date qw(str2time);
+
+sub parse_dir ($;$$$)
+{
+   my($dir, $tz, $fstype, $error) = @_;
+
+   $fstype ||= 'unix';
+   $fstype = "File::Listing::" . lc $fstype;
+
+   my @args = $_[0];
+   push(@args, $tz) if(@_ >= 2);
+   push(@args, $error) if(@_ >= 4);
+
+   $fstype->parse(@args);
+}
+
+sub line { Carp::croak("Not implemented yet"); }
+sub init { } # Dummy sub
+
+sub file_mode ($)
+{
+    # This routine was originally borrowed from Graham Barr's
+    # Net::FTP package.
+
+    local $_ = shift;
+    my $mode = 0;
+    my($type,$ch);
+
+    s/^(.)// and $type = $1;
+
+    while (/(.)/g) {
+	$mode <<= 1;
+	$mode |= 1 if $1 ne "-" &&
+		      $1 ne 'S' &&
+		      $1 ne 't' &&
+		      $1 ne 'T';
+    }
+
+    $type eq "d" and $mode |= 0040000 or	# Directory
+      $type eq "l" and $mode |= 0120000 or	# Symbolic Link
+	$mode |= 0100000;			# Regular File
+
+    $mode |= 0004000 if /^...s....../i;
+    $mode |= 0002000 if /^......s.../i;
+    $mode |= 0001000 if /^.........t/i;
+
+    $mode;
+}
+
+sub parse
+{
+   my($pkg, $dir, $tz, $error) = @_;
+
+   # First let's try to determine what kind of dir parameter we have
+   # received.  We allow both listings, reference to arrays and
+   # file handles to read from.
+
+   if (ref($dir) eq 'ARRAY') {
+       # Already splitted up
+   } elsif (ref($dir) eq 'GLOB') {
+       # A file handle
+   } elsif (ref($dir)) {
+      Carp::croak("Illegal argument to parse_dir()");
+   } elsif ($dir =~ /^\*\w+(::\w+)+$/) {
+      # This scalar looks like a file handle, so we assume it is
+   } else {
+      # A normal scalar listing
+      $dir = [ split(/\n/, $dir) ];
+   }
+
+   $pkg->init();
+
+   my @files = ();
+   if (ref($dir) eq 'ARRAY') {
+       for (@$dir) {
+	   push(@files, $pkg->line($_, $tz, $error));
+       }
+   } else {
+       local($_);
+       while (<$dir>) {
+	   chomp;
+	   push(@files, $pkg->line($_, $tz, $error));
+       }
+   }
+   wantarray ? @files : \@files;
+}
+
+
+package File::Listing::unix;
+
+use HTTP::Date qw(str2time);
+
+# A place to remember current directory from last line parsed.
+use vars qw($curdir);
+no strict qw(vars);
+
+@ISA = qw(File::Listing);
+
+
+sub init
+{
+    $curdir = '';
+}
+
+sub line
+{
+    shift; # package name
+    local($_) = shift;
+    my($tz, $error) = @_;
+
+    s/\015//g;
+    #study;
+
+    my ($kind, $size, $date, $name);
+    if (($kind, $size, $date, $name) =
+	/^([\-FlrwxsStTdD]{10})                   # Type and permission bits
+	 .*                                       # Graps
+	 \D(\d+)                                  # File size
+	 \s+                                      # Some space
+	 (\w{3}\s+\d+\s+(?:\d{1,2}:\d{2}|\d{4}))  # Date
+	 \s+                                      # Some more space
+	 (.*)$                                    # File name
+	/x )
+
+    {
+	return if $name eq '.' || $name eq '..';
+	$name = "$curdir/$name" if length $curdir;
+	my $type = '?';
+	if ($kind =~ /^l/ && $name =~ /(.*) -> (.*)/ ) {
+	    $name = $1;
+	    $type = "l $2";
+	} elsif ($kind =~ /^[\-F]/) { # (hopefully) a regular file
+	    $type = 'f';
+	} elsif ($kind =~ /^[dD]/) {
+	    $type = 'd';
+	    $size = undef;  # Don't believe the reported size
+	}
+	return [$name, $type, $size, str2time($date, $tz), 
+              File::Listing::file_mode($kind)];
+
+    } elsif (/^(.+):$/ && !/^[dcbsp].*\s.*\s.*:$/ ) {
+	my $dir = $1;
+	return () if $dir eq '.';
+	$curdir = $dir;
+	return ();
+    } elsif (/^[Tt]otal\s+(\d+)$/ || /^\s*$/) {
+	return ();
+    } elsif (/not found/    || # OSF1, HPUX, and SunOS return
+             # "$file not found"
+             /No such file/ || # IRIX returns
+             # "UX:ls: ERROR: Cannot access $file: No such file or directory"
+                               # Solaris returns
+             # "$file: No such file or directory"
+             /cannot find/     # Windows NT returns
+             # "The system cannot find the path specified."
+             ) {
+	return () unless defined $error;
+	&$error($_) if ref($error) eq 'CODE';
+	warn "Error: $_\n" if $error eq 'warn';
+	return ();
+    } elsif ($_ eq '') {       # AIX, and Linux return nothing
+	return () unless defined $error;
+	&$error("No such file or directory") if ref($error) eq 'CODE';
+	warn "Warning: No such file or directory\n" if $error eq 'warn';
+	return ();
+    } else {
+        # parse failed, check if the dosftp parse understands it
+        return(File::Listing::dosftp->line($_,$tz,$error));
+    }
+
+}
+
+package File::Listing::dosftp;
+
+use HTTP::Date qw(str2time);
+
+# A place to remember current directory from last line parsed.
+use vars qw($curdir);
+no strict qw(vars);
+
+@ISA = qw(File::Listing);
+
+sub init
+{
+    $curdir = '';
+}
+
+sub line
+{
+    shift; # package name
+    local($_) = shift;
+    my($tz, $error) = @_;
+
+    s/\015//g;
+
+    my ($kind, $size, $date, $name);
+
+    # 02-05-96  10:48AM                 1415 src.slf
+    # 09-10-96  09:18AM       <DIR>          sl_util
+    if (($date,$size_or_dir,$name) =
+        /^(\d\d-\d\d-\d\d\s+\d\d:\d\d\wM)         # Date and time info
+         \s+                                      # Some space
+         (<\w{3}>|\d+)                            # Dir or Size
+         \s+                                      # Some more space
+         (.+)$                                    # File name
+        /x )
+    {
+	return if $name eq '.' || $name eq '..';
+	$name = "$curdir/$name" if length $curdir;
+	my $type = '?';
+	if ($size_or_dir eq '<DIR>') {
+	    $type = "d";
+            $size = ""; # directories have no size in the pc listing
+        } else {
+	    $type = 'f';
+            $size = $size_or_dir;
+	}
+	return [$name, $type, $size, str2time($date, $tz),
+              File::Listing::file_mode($kind)];
+
+    } else {
+	return () unless defined $error;
+	&$error($_) if ref($error) eq 'CODE';
+	warn "Can't parse: $_\n" if $error eq 'warn';
+	return ();
+    }
+
+}
+
+package File::Listing::vms;
+@File::Listing::unix::ISA = qw(File::Listing);
+
+package File::Listing::netware;
+@File::Listing::unix::ISA = qw(File::Listing);
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Cookies.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Cookies.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Cookies.pm	(revision 16571)
@@ -0,0 +1,725 @@
+package HTTP::Cookies;
+
+# Based on draft-ietf-http-state-man-mec-08.txt and
+# http://www.netscape.com/newsref/std/cookie_spec.html
+
+use strict;
+use HTTP::Date qw(str2time time2str);
+use HTTP::Headers::Util qw(split_header_words join_header_words);
+use LWP::Debug ();
+
+use vars qw($VERSION);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+=head1 NAME
+
+HTTP::Cookies - Cookie storage and management
+
+=head1 SYNOPSIS
+
+ use HTTP::Cookies;
+ $cookie_jar = HTTP::Cookies->new;
+
+ $cookie_jar->add_cookie_header($request);
+ $cookie_jar->extract_cookies($response);
+
+=head1 DESCRIPTION
+
+Cookies are a general mechanism which server side connections can use
+to both store and retrieve information on the client side of the
+connection.  For more information about cookies referrer to
+<URL:http://www.netscape.com/newsref/std/cookie_spec.html> and
+<URL:http://www.cookiecentral.com/>.  This module also implements the
+new style cookies as described in I<draft-ietf-http-state-man-mec-08.txt>.
+The two variants of cookies is supposed to be able to coexist happily.
+
+Instances of the class I<HTTP::Cookies> are able to store a collection
+of Set-Cookie2: and Set-Cookie:-headers and is able to use this
+information to initialize Cookie-headers in I<HTTP::Request> objects.
+The state of the I<HTTP::Cookies> can be saved and restored from
+files.
+
+=head1 METHODS
+
+The following methods are provided:
+
+=over 4
+
+=cut
+
+# A HTTP::Cookies object is a hash.  The main attribute is the
+# COOKIES 3 level hash:  $self->{COOKIES}{$domain}{$path}{$key}.
+
+
+=item $cookie_jar = HTTP::Cookies->new;
+
+The constructor.  Takes hash style parameters.  The following
+parameters are recognized:
+
+  file:            name of the file to restore and save cookies to
+  autosave:        should we save during destruction (bool)
+  ignore_discard:  save even cookies that are requested to be discarded (bool)
+
+Future parameters might include (not yet implemented):
+
+  max_cookies               300
+  max_cookies_per_domain    20
+  max_cookie_size           4096
+
+  no_cookies   list of domain names that we never return cookies to
+
+=cut
+
+sub new
+{
+    my $class = shift;
+    my $self = bless {
+	COOKIES => {},
+    }, $class;
+    my %cnf = @_;
+    for (keys %cnf) {
+	$self->{lc($_)} = $cnf{$_};
+    }
+    $self->load;
+    $self;
+}
+
+
+=item $cookie_jar->add_cookie_header($request);
+
+The add_cookie_header() method will set the appropriate Cookie:-header
+for the I<HTTP::Request> object given as argument.  The $request must
+have a valid url() attribute before this method is called.
+
+=cut
+
+sub add_cookie_header
+{
+    my $self = shift;
+    my $request = shift || return;
+    my $url = $request->url;
+    my $domain = $url->host;
+    $domain = "$domain.local" unless $domain =~ /\./;
+    my $secure_request = ($url->scheme eq "https");
+    my $req_path = $url->epath;
+    my $req_port = $url->port;
+    my $now = time();
+    $self->_normalize_path($req_path) if $req_path =~ /%/;
+
+    my @cval;    # cookie values for the "Cookie" header
+    my $set_ver;
+
+    while (($domain =~ tr/././) >= 2 || # must be at least 2 dots
+           $domain =~ /\.local$/)
+    {
+
+        LWP::Debug::debug("Checking $domain for cookies");
+	my $cookies = $self->{COOKIES}{$domain};
+	next unless $cookies;
+
+	# Want to add cookies corresponding to the most specific paths
+	# first (i.e. longest path first)
+	my $path;
+	for $path (sort {length($b) <=> length($a) } keys %$cookies) {
+            LWP::Debug::debug("- checking cookie path=$path");
+	    if (index($req_path, $path) != 0) {
+	        LWP::Debug::debug("  path $path:$req_path does not fit");
+		next;
+	    }
+
+	    my($key,$array);
+	    while (($key,$array) = each %{$cookies->{$path}}) {
+		my($version,$val,$port,$path_spec,$secure,$expires) = @$array;
+	        LWP::Debug::debug(" - checking cookie $key=$val");
+		if ($secure && !$secure_request) {
+		    LWP::Debug::debug("   not a secure requests");
+		    next;
+		}
+		if ($expires && $expires < $now) {
+		    LWP::Debug::debug("   expired");
+		    next;
+		}
+		if ($port) {
+		    my $found;
+		    if ($port =~ s/^_//) {
+			# The correponding Set-Cookie attribute was empty
+			$found++ if $port eq $req_port;
+			$port = "";
+		    } else {
+			my $p;
+			for $p (split(/,/, $port)) {
+			    $found++, last if $p eq $req_port;
+			}
+		    }
+		    unless ($found) {
+		        LWP::Debug::debug("   port $port:$req_port does not fit");
+			next;
+		    }
+		}
+	        LWP::Debug::debug("   it's a match");
+
+		# set version number of cookie header.
+	        # XXX: What should it be if multiple matching
+                #      Set-Cookie headers have different versions themselves
+		if (!$set_ver++) {
+		    if ($version >= 1) {
+			push(@cval, "\$Version=$version");
+		    } else {
+			$request->header(Cookie2 => "\$Version=1");
+		    }
+		}
+
+		# do we need to quote the value
+		if ($val =~ /\W/ && $version) {
+		    $val =~ s/([\\\"])/\\$1/g;
+		    $val = qq("$val");
+		}
+
+		# and finally remember this cookie
+		push(@cval, "$key=$val");
+		if ($version >= 1) {
+		    push(@cval, qq(\$Path="$path"))     if $path_spec;
+		    push(@cval, qq(\$Domain="$domain")) if $domain =~ /^\./;
+		    if (defined $port) {
+			my $p = '$Port';
+			$p .= qq(="$port") if length $port;
+			push(@cval, $p);
+		    }
+		}
+
+	    }
+        }
+
+    } continue {
+	# Try with a more general domain:  www.sol.no ==> .sol.no
+	$domain =~ s/^\.?[^.]*//;
+    }
+
+    $request->header(Cookie => join("; ", @cval)) if @cval;
+
+    $request;
+}
+
+
+=item $cookie_jar->extract_cookies($response);
+
+The extract_cookies() method will look for Set-Cookie: and
+Set-Cookie2:-headers in the I<HTTP::Response> object passed as
+argument.  If some of these headers are found they are used to update
+the state of the $cookie_jar.
+
+=cut
+
+sub extract_cookies
+{
+    my $self = shift;
+    my $response = shift || return;
+    my @set = split_header_words($response->_header("Set-Cookie2"));
+    my $netscape_cookies;
+    unless (@set) {
+	@set = $response->_header("Set-Cookie");
+	return $response unless @set;
+	$netscape_cookies++;
+    }
+
+    my $url = $response->request->url;
+    my $req_host = $url->host;
+    $req_host = "$req_host.local" unless $req_host =~ /\./;
+    my $req_port = $url->port;
+    my $req_path = $url->epath;
+    $self->_normalize_path($req_path) if $req_path =~ /%/;
+    
+    if ($netscape_cookies) {
+	# The old Netscape cookie format for Set-Cookie
+        # http://www.netscape.com/newsref/std/cookie_spec.html
+	# can for instance contain an unquoted "," in the expires
+	# field, so we have to use this ad-hoc parser.
+	my $now = time();
+	my @old = @set;
+	@set = ();
+	my $set;
+	for $set (@old) {
+	    my @cur;
+	    my $param;
+	    my $expires;
+	    for $param (split(/\s*;\s*/, $set)) {
+		my($k,$v) = split(/\s*=\s*/, $param, 2);
+		#print "$k => $v\n";
+		my $lc = lc($k);
+		if ($lc eq "expires") {
+		    push(@cur, "Max-Age" => str2time($v) - $now);
+		    $expires++;
+		} else {
+		    push(@cur, $k => $v);
+		}
+	    }
+	    push(@cur, "Port" => $req_port);
+	    push(@cur, "Discard" => undef) unless $expires;
+	    push(@cur, "Version" => 0);
+	    push(@set, \@cur);
+	}
+    }
+
+  SET_COOKIE:
+    for my $set (@set) {
+	next unless @$set >= 2;
+
+	my $key = shift @$set;
+	my $val = shift @$set;
+
+        LWP::Debug::debug("Set cookie $key => $val");
+
+	my %hash;
+	while (@$set) {
+	    my $k = shift @$set;
+	    my $v = shift @$set;
+	    my $lc = lc($k);
+	    # don't loose case distinction for unknown fields
+	    $k = $lc if $lc =~ /^(?:discard|domain|max-age|
+                                    path|port|secure|version)$/x;
+	    if ($k eq "discard" || $k eq "secure") {
+		$v = 1 unless defined $v;
+	    }
+	    next if exists $hash{$k};  # only first value is signigicant
+	    $hash{$k} = $v;
+	};
+
+	my %orig_hash = %hash;
+	my $version   = delete $hash{version};
+	$version = 1 unless defined($version);
+	my $discard   = delete $hash{discard};
+	my $secure    = delete $hash{secure};
+	my $maxage    = delete $hash{'max-age'};
+
+	# Check domain
+	my $domain  = delete $hash{domain};
+	if (defined($domain) && $domain ne $req_host) {
+	    if ($domain !~ /\./ && $domain ne "local") {
+	        LWP::Debug::debug("Domain $domain contains no dot");
+		next SET_COOKIE;
+	    }
+	    $domain = ".$domain" unless $domain =~ /^\./;
+	    if ($domain =~ /\.\d+$/) {
+	        LWP::Debug::debug("IP-address $domain illeagal as domain");
+		next SET_COOKIE;
+	    }
+	    my $len = length($domain);
+	    unless (substr($req_host, -$len) eq $domain) {
+	        LWP::Debug::debug("Domain $domain does not match host $req_host");
+		next SET_COOKIE;
+	    }
+	    my $hostpre = substr($req_host, 0, length($req_host) - $len);
+	    if ($hostpre =~ /\./ && !$netscape_cookies) {
+	        LWP::Debug::debug("Host prefix contain a dot: $hostpre => $domain");
+		next SET_COOKIE;
+	    }
+	} else {
+	    $domain = $req_host;
+	}
+
+	my $path = delete $hash{path};
+	my $path_spec;
+	if (defined $path) {
+	    $path_spec++;
+	    $self->_normalize_path($path) if $path =~ /%/;
+	    if (!$netscape_cookies &&
+                substr($req_path, 0, length($path)) ne $path) {
+	        LWP::Debug::debug("Path $path is not a prefix of $req_path");
+		next SET_COOKIE;
+	    }
+	} else {
+	    $path = $req_path;
+	    $path =~ s,/[^/]*$,,;
+	    $path = "/" unless length($path);
+	}
+
+	my $port;
+	if (exists $hash{port}) {
+	    $port = delete $hash{port};
+	    if (defined $port) {
+		$port =~ s/\s+//g;
+		my $found;
+		for my $p (split(/,/, $port)) {
+		    unless ($p =~ /^\d+$/) {
+		      LWP::Debug::debug("Bad port $port (not numeric)");
+			next SET_COOKIE;
+		    }
+		    $found++ if $p eq $req_port;
+		}
+		unless ($found) {
+		    LWP::Debug::debug("Request port ($req_port) not found in $port");
+		    next SET_COOKIE;
+		}
+	    } else {
+		$port = "_$req_port";
+	    }
+	}
+	$self->set_cookie($version,$key,$val,$path,$domain,$port,$path_spec,$secure,$maxage,$discard, \%hash)
+	    if $self->set_cookie_ok(\%orig_hash);
+    }
+
+    $response;
+}
+
+sub set_cookie_ok { 1 };
+
+=item $cookie_jar->set_cookie($version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard, \%rest)
+
+The set_cookie() method updates the state of the $cookie_jar.  The
+$key, $val, $domain, $port and $path arguments are strings.  The
+$path_spec, $secure, $discard arguments are boolean values. The $maxage
+value is a number indicating number of seconds that this cookie will
+live.  A value <= 0 will delete this cookie.  The %rest are a place
+for various other attributes like "Comment" and "CommentURL".
+
+=cut
+
+sub set_cookie
+{
+    my $self = shift;
+    my($version,
+       $key, $val, $path, $domain, $port,
+       $path_spec, $secure, $maxage, $discard, $rest) = @_;
+
+    # there must always be at least 2 dots in a domain
+    return $self if ($domain =~ tr/././) < 2 &&
+                     $domain !~ /\.local$/;
+
+    # path and key can not be empty (key can't start with '$')
+    return $self if !defined($path) || $path !~ m,^/, ||
+	            !defined($key)  || $key  !~ m,[^\$],;
+
+    # ensure legal port
+    if (defined $port) {
+	return $self unless $port =~ /^_?\d+(?:,\d+)*$/;
+    }
+
+    my $expires;
+    if (defined $maxage) {
+	if ($maxage <= 0) {
+	    delete $self->{COOKIES}{$domain}{$path}{$key};
+	    return $self;
+	}
+	$expires = time() + $maxage;
+    }
+    $version = 0 unless defined $version;
+
+    my @array = ($version, $val,$port,
+		 $path_spec,
+		 $secure, $expires, $discard);
+    push(@array, {%$rest}) if defined($rest) && %$rest;
+    # trim off undefined values at end
+    pop(@array) while !defined $array[-1];
+
+    $self->{COOKIES}{$domain}{$path}{$key} = \@array;
+    $self;
+}
+
+=item $cookie_jar->save( [$file] );
+
+Calling this method file save the state of the $cookie_jar to a file.
+The state can then be restored later using the load() method.  If a
+filename is not specified we will use the name specified during
+construction.  If the attribute I<ignore_discared> is set, then we
+will even save cookies that are marked to be discarded.
+
+The default is to save a sequence of "Set-Cookie3" lines.  The
+"Set-Cookie3" is a proprietary LWP format, not known to be compatible
+with any other browser.  The I<HTTP::Cookies::Netscape> sub-class can
+be used to save in a format compatible with Netscape.
+
+=cut
+
+sub save
+{
+    my $self = shift;
+    my $file = shift || $self->{'file'} || return;
+    local(*FILE);
+    open(FILE, ">$file") or die "Can't open $file: $!";
+    print FILE "#LWP-Cookies-1.0\n";
+    print FILE $self->as_string(!$self->{ignore_discard});
+    close(FILE);
+    1;
+}
+
+=item $cookie_jar->load( [$file] );
+
+This method will read the cookies from the file and add them to the
+$cookie_jar.  The file must be in the format written by the save()
+method.
+
+=cut
+
+sub load
+{
+    my $self = shift;
+    my $file = shift || $self->{'file'} || return;
+    local(*FILE, $_);
+    open(FILE, $file) or return;
+    my $magic = <FILE>;
+    unless ($magic =~ /^\#LWP-Cookies-(\d+\.\d+)/) {
+	warn "$file does not seem to contain cookies";
+	return;
+    }
+    while (<FILE>) {
+	next unless s/^Set-Cookie3:\s*//;
+	chomp;
+	my $cookie;
+	for $cookie (split_header_words($_)) {
+	    my($key,$val) = splice(@$cookie, 0, 2);
+	    my %hash;
+	    while (@$cookie) {
+		my $k = shift @$cookie;
+		my $v = shift @$cookie;
+		$hash{$k} = $v;
+	    }
+	    my $version   = delete $hash{version};
+	    my $path      = delete $hash{path};
+	    my $domain    = delete $hash{domain};
+	    my $port      = delete $hash{port};
+	    my $expires   = str2time(delete $hash{expires});
+
+	    my $path_spec = exists $hash{path_spec}; delete $hash{path_spec};
+	    my $secure    = exists $hash{secure};    delete $hash{secure};
+	    my $discard   = exists $hash{discard};   delete $hash{discard};
+
+	    my @array =	($version,$val,$port,
+			 $path_spec,$secure,$expires,$discard);
+	    push(@array, \%hash) if %hash;
+	    $self->{COOKIES}{$domain}{$path}{$key} = \@array;
+	}
+    }
+    close(FILE);
+    1;
+}
+
+=item $cookie_jar->revert;
+
+Will revert to the state of last save.
+
+=cut
+
+sub revert
+{
+    my $self = shift;
+    $self->clear->load;
+    $self;
+}
+
+=item $cookie_jar->clear( [$domain, [$path, [$key] ] ]);
+
+Invoking this method without arguments will empty the whole
+$cookie_jar.  If given a single argument only cookies belonging to
+that domain will be removed.  If given two arguments, cookies
+belonging to the specified path within that domain is removed.  If
+given three arguments, then the cookie with the specified key, path
+and domain is removed.
+
+=cut
+
+sub clear
+{
+    my $self = shift;
+    if (@_ == 0) {
+	$self->{COOKIES} = {};
+    } elsif (@_ == 1) {
+	delete $self->{COOKIES}{$_[0]};
+    } elsif (@_ == 2) {
+	delete $self->{COOKIES}{$_[0]}{$_[1]};
+    } elsif (@_ == 3) {
+	delete $self->{COOKIES}{$_[0]}{$_[1]}{$_[2]};
+    } else {
+	require Carp;
+        Carp::carp('Usage: $c->clear([domain [,path [,key]]])');
+    }
+    $self;
+}
+
+sub DESTROY
+{
+    my $self = shift;
+    $self->save if $self->{'autosave'};
+}
+
+
+=item $cookie_jar->scan( \&callback );
+
+The argument is a subroutine that will be invoked for each cookie
+stored within the $cookie_jar.  The subroutine will be invoked with
+the following arguments:
+
+  0  version
+  1  key
+  2  val
+  3  path
+  4  domain
+  5  port
+  6  path_spec
+  7  secure
+  8  expires
+  9  discard
+ 10  hash
+
+=cut
+
+sub scan
+{
+    my($self, $cb) = @_;
+    my($domain,$path,$key);
+    for $domain (sort keys %{$self->{COOKIES}}) {
+	for $path (sort keys %{$self->{COOKIES}{$domain}}) {
+	    for $key (sort keys %{$self->{COOKIES}{$domain}{$path}}) {
+		my($version,$val,$port,$path_spec,
+		   $secure,$expires,$discard,$rest) =
+		       @{$self->{COOKIES}{$domain}{$path}{$key}};
+		$rest = {} unless defined($rest);
+		&$cb($version,$key,$val,$path,$domain,$port,
+		     $path_spec,$secure,$expires,$discard,$rest);
+	    }
+	}
+    }
+}
+
+=item $cookie_jar->as_string( [$skip_discard] );
+
+The as_string() method will return the state of the $cookie_jar
+represented as a sequence of "Set-Cookie3" header lines separated by
+"\n".  If given a argument that is TRUE, it will not return lines for
+cookies with the I<Discard> attribute.
+
+=cut
+
+sub as_string
+{
+    my($self, $skip_discard) = @_;
+    my @res;
+    $self->scan(sub {
+	my($version,$key,$val,$path,$domain,$port,
+	   $path_spec,$secure,$expires,$discard,$rest) = @_;
+	return if $discard && $skip_discard;
+	my @h = ($key, $val);
+	push(@h, "path", $path);
+	push(@h, "domain" => $domain);
+	push(@h, "port" => $port) if defined $port;
+	push(@h, "path_spec" => undef) if $path_spec;
+	push(@h, "secure" => undef) if $secure;
+	push(@h, "expires" => HTTP::Date::time2isoz($expires)) if $expires;
+	push(@h, "discard" => undef) if $discard;
+	my $k;
+	for $k (sort keys %$rest) {
+	    push(@h, $k, $rest->{$k});
+	}
+	push(@h, "version" => $version);
+	push(@res, "Set-Cookie3: " . join_header_words(\@h));
+    });
+    join("\n", @res, "");
+}
+
+
+sub _normalize_path  # so that plain string compare can be used
+{
+    shift;  # $self
+    my $x;
+    $_[0] =~ s/%([0-9a-fA-F][0-9a-fA-F])/
+	         $x = uc($1);
+                 $x eq "2F" || $x eq "25" ? "%$x" :
+                                            pack("c", hex($x));
+              /eg;
+    $_[0] =~ s/([\0-\x20\x7f-\xff])/sprintf("%%%02X",ord($1))/eg;
+}
+
+
+
+=back
+
+=head1 SUB CLASSES
+
+We also provide a subclass called I<HTTP::Cookies::Netscape> which make
+cookie loading and saving compatible with Netscape cookie files.  You
+should be able to have LWP share Netscape's cookies by constructing
+your $cookie_jar like this:
+
+ $cookie_jar = HTTP::Cookies::Netscape->new(
+                   File     => "$ENV{HOME}/.netscape/cookies",
+                   AutoSave => 1,
+               );
+
+Please note that the Netscape cookie file format is not able to store
+all the information available in the Set-Cookie2 headers, so you will
+probably loose some information if you save using this format.
+
+=cut
+
+package HTTP::Cookies::Netscape;
+
+use vars qw(@ISA);
+@ISA=qw(HTTP::Cookies);
+
+sub load
+{
+    my($self, $file) = @_;
+    $file ||= $self->{'file'} || return;
+    local(*FILE, $_);
+    my @cookies;
+    open(FILE, $file) || return;
+    my $magic = <FILE>;
+    unless ($magic =~ /^\# Netscape HTTP Cookie File/) {
+	warn "$file does not look like a netscape cookies file" if $^W;
+	close(FILE);
+	return;
+    }
+    my $now = time();
+    while (<FILE>) {
+	next if /^\s*\#/;
+	next if /^\s*$/;
+	chomp;
+	my($domain,$bool1,$path,$secure, $expires,$key,$val) = split(/\t/, $_);
+	$secure = ($secure eq "TRUE");
+	$self->set_cookie(undef,$key,$val,$path,$domain,undef,
+			  0,$secure,$expires-$now, 0);
+    }
+    close(FILE);
+    1;
+}
+
+sub save
+{
+    my($self, $file) = @_;
+    $file ||= $self->{'file'} || return;
+    local(*FILE, $_);
+    open(FILE, ">$file") || return;
+
+    print FILE <<EOT;
+# Netscape HTTP Cookie File
+# http://www.netscape.com/newsref/std/cookie_spec.html
+# This is a generated file!  Do not edit.
+
+EOT
+
+    my $now = time;
+    $self->scan(sub {
+	my($version,$key,$val,$path,$domain,$port,
+	   $path_spec,$secure,$expires,$discard,$rest) = @_;
+	return if $discard && !$self->{ignore_discard};
+	$expires ||= 0;
+	return if $now > $expires;
+	$secure = $secure ? "TRUE" : "FALSE";
+	my $bool = $domain =~ /^\./ ? "TRUE" : "FALSE";
+	print FILE join("\t", $domain, $bool, $path, $secure, $expires, $key, $val), "\n";
+    });
+    close(FILE);
+    1;
+}
+
+1;
+
+__END__
+
+=head1 COPYRIGHT
+
+Copyright 1997, Gisle Aas
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Daemon.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Daemon.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Daemon.pm	(revision 16571)
@@ -0,0 +1,805 @@
+# $Id$
+#
+
+use strict;
+
+package HTTP::Daemon;
+
+=head1 NAME
+
+HTTP::Daemon - a simple http server class
+
+=head1 SYNOPSIS
+
+  use HTTP::Daemon;
+  use HTTP::Status;
+
+  my $d = new HTTP::Daemon;
+  print "Please contact me at: <URL:", $d->url, ">\n";
+  while (my $c = $d->accept) {
+      while (my $r = $c->get_request) {
+	  if ($r->method eq 'GET' and $r->url->path eq "/xyzzy") {
+              # remember, this is *not* recommened practice :-)
+	      $c->send_file_response("/etc/passwd");
+	  } else {
+	      $c->send_error(RC_FORBIDDEN)
+	  }
+      }
+      $c->close;
+      undef($c);
+  }
+
+=head1 DESCRIPTION
+
+Instances of the I<HTTP::Daemon> class are HTTP/1.1 servers that
+listens on a socket for incoming requests. The I<HTTP::Daemon> is a
+sub-class of I<IO::Socket::INET>, so you can do socket operations
+directly on it too.
+
+The accept() method will return when a connection from a client is
+available. The returned value will be a reference to a object of the
+I<HTTP::Daemon::ClientConn> class which is another I<IO::Socket::INET>
+subclass. Calling the get_request() method on this object will read
+data from the client and return an I<HTTP::Request> object reference.
+
+This HTTP daemon does not fork(2) for you.  Your application, i.e. the
+user of the I<HTTP::Daemon> is reponsible for forking if that is
+desirable.  Also note that the user is responsible for generating
+responses that conforms to the HTTP/1.1 protocol.  The
+I<HTTP::Daemon::ClientConn> provide some methods that make this easier.
+
+=head1 METHODS
+
+The following is a list of methods that are new (or enhanced) relative
+to the I<IO::Socket::INET> base class.
+
+=over 4
+
+=cut
+
+
+use vars qw($VERSION @ISA $PROTO $DEBUG);
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+use IO::Socket ();
+@ISA=qw(IO::Socket::INET);
+
+$PROTO = "HTTP/1.1";
+
+=item $d = new HTTP::Daemon
+
+The object constructor takes the same parameters as the
+I<IO::Socket::INET> constructor.  It can be called without specifying
+any parameters. The daemon will then set up a listen queue of 5
+connections and allocate some random port number.  A server that want
+to bind to some specific address on the standard HTTP port will be
+constructed like this:
+
+  $d = new HTTP::Daemon
+        LocalAddr => 'www.someplace.com',
+        LocalPort => 80;
+
+=cut
+
+sub new
+{
+    my($class, %args) = @_;
+    $args{Listen} ||= 5;
+    $args{Proto}  ||= 'tcp';
+    my $self = $class->SUPER::new(%args);
+    return undef unless $self;
+
+    my $host = $args{LocalAddr};
+    unless ($host) {
+	require Sys::Hostname;
+	$host = Sys::Hostname::hostname();
+    }
+    ${*$self}{'httpd_server_name'} = $host;
+    $self;
+}
+
+
+=item $c = $d->accept([$pkg])
+
+Same as I<IO::Socket::accept> but will return an
+I<HTTP::Daemon::ClientConn> reference by default.  It will return
+undef if you have specified a timeout and no connection is made within
+that time.
+
+=cut
+
+sub accept
+{
+    my $self = shift;
+    my $pkg = shift || "HTTP::Daemon::ClientConn";
+    my $sock = $self->SUPER::accept($pkg);
+    ${*$sock}{'httpd_daemon'} = $self if $sock;
+    $sock;
+}
+
+
+=item $d->url
+
+Returns a URL string that can be used to access the server root.
+
+=cut
+
+sub url
+{
+    my $self = shift;
+    my $url = "http://";
+    $url .= ${*$self}{'httpd_server_name'};
+    my $port = $self->sockport;
+    $url .= ":$port" if $port != 80;
+    $url .= "/";
+    $url;
+}
+
+
+=item $d->product_tokens
+
+Returns the name that this server will use to identify itself.  This
+is the string that is sent with the I<Server> response header.  The
+main reason to have this method is that subclasses can override it if
+they want to use another product name.
+
+=cut
+
+sub product_tokens
+{
+    "libwww-perl-daemon/$HTTP::Daemon::VERSION";
+}
+
+
+package HTTP::Daemon::ClientConn;
+
+use vars qw(@ISA $DEBUG);
+use IO::Socket ();
+@ISA=qw(IO::Socket::INET);
+*DEBUG = \$HTTP::Daemon::DEBUG;
+
+use HTTP::Request  ();
+use HTTP::Response ();
+use HTTP::Status;
+use HTTP::Date qw(time2str);
+use URI::URL qw(url);
+use LWP::MediaTypes qw(guess_media_type);
+use Carp ();
+
+my $CRLF = "\015\012";   # "\r\n" is not portable
+my $HTTP_1_0 = _http_version("HTTP/1.0");
+my $HTTP_1_1 = _http_version("HTTP/1.1");
+
+=back
+
+The I<HTTP::Daemon::ClientConn> is also a I<IO::Socket::INET>
+subclass. Instances of this class are returned by the accept() method
+of the I<HTTP::Daemon>.  The following additional methods are
+provided:
+
+=over 4
+
+=item $c->get_request([$headers_only])
+
+This method will read data from the client and turn it into a
+I<HTTP::Request> object which is then returned.  It returns C<undef>
+if reading of the request fails.  If it fails, then the
+I<HTTP::Daemon::ClientConn> object ($c) should be discarded, and you
+should not call this method again.  The $c->reason method might give
+you some information on why $c->get_request returned C<undef>.
+
+The $c->get_request method support HTTP/1.1 request content bodies,
+including I<chunked> transfer encoding with footer and self delimiting
+I<multipart/*> content types.
+
+The $c->get_request method will normally not return until the whole
+request has been received from the client.  This might not be what you
+want if the request is an upload of a multi-mega-byte file (and with
+chunked transfer encoding HTTP can even support infinite request
+messages - uploading live audio for instance).  If you pass a TRUE
+value as the $headers_only argument, then $c->get_request will return
+immediately after parsing the request headers and you are responsible
+for reading the rest of the request content (and if you are going to
+call $c->get_request again on the same connection you better read the
+correct number of bytes).
+
+=cut
+
+sub get_request
+{
+    my($self, $only_headers) = @_;
+    if (${*$self}{'httpd_nomore'}) {
+        $self->reason("No more requests from this connection");
+	return;
+    }
+
+    $self->reason("");
+    my $buf = ${*$self}{'httpd_rbuf'};
+    $buf = "" unless defined $buf;
+    
+    my $timeout = $ {*$self}{'io_socket_timeout'};
+    my $fdset = "";
+    vec($fdset, $self->fileno, 1) = 1;
+    local($_);
+
+  READ_HEADER:
+    while (1) {
+	# loop until we have the whole header in $buf
+	$buf =~ s/^(?:\015?\012)+//;  # ignore leading blank lines
+	if ($buf =~ /\012/) {  # potential, has at least one line
+	    if ($buf =~ /^\w+[^\012]+HTTP\/\d+\.\d+\015?\012/) {
+		if ($buf =~ /\015?\012\015?\012/) {
+		    last READ_HEADER;  # we have it
+		} elsif (length($buf) > 16*1024) {
+		    $self->send_error(413); # REQUEST_ENTITY_TOO_LARGE
+		    $self->reason("Very long header");
+		    return;
+		}
+	    } else {
+		last READ_HEADER;  # HTTP/0.9 client
+	    }
+	} elsif (length($buf) > 16*1024) {
+	    $self->send_error(414); # REQUEST_URI_TOO_LARGE
+	    $self->reason("Very long first line");
+	    return;
+	}
+	print STDERR "Need more data for complete header\n" if $DEBUG;
+	return unless $self->_need_more($buf, $timeout, $fdset);
+    }
+    if ($buf !~ s/^(\w+)[ \t]+(\S+)(?:[ \t]+(HTTP\/\d+\.\d+))?[^\012]*\012//) {
+	$self->send_error(400);  # BAD_REQUEST
+	$self->reason("Bad request line");
+	return;
+    }
+    my $proto = $3 || "HTTP/0.9";
+    my $r = HTTP::Request->new($1, url($2, $self->daemon->url));
+    $r->protocol($proto);
+    ${*$self}{'httpd_client_proto'} = $proto = _http_version($proto);
+
+    if ($proto >= $HTTP_1_0) {
+	# we expect to find some headers
+	my($key, $val);
+      HEADER:
+	while ($buf =~ s/^([^\012]*)\012//) {
+	    $_ = $1;
+	    s/\015$//;
+	    if (/^([\w\-]+)\s*:\s*(.*)/) {
+		$r->push_header($key, $val) if $key;
+		($key, $val) = ($1, $2);
+	    } elsif (/^\s+(.*)/) {
+		$val .= " $1";
+	    } else {
+		last HEADER;
+	    }
+	}
+	$r->push_header($key, $val) if $key;
+    }
+
+    my $conn = $r->header('Connection');
+    if ($proto >= $HTTP_1_1) {
+	${*$self}{'httpd_nomore'}++ if $conn && lc($conn) =~ /\bclose\b/;
+    } else {
+	${*$self}{'httpd_nomore'}++ unless $conn &&
+                                           lc($conn) =~ /\bkeep-alive\b/;
+    }
+
+    if ($only_headers) {
+	${*$self}{'httpd_rbuf'} = $buf;
+        return $r;
+    }
+
+    # Find out how much content to read
+    my $te  = $r->header('Transfer-Encoding');
+    my $ct  = $r->header('Content-Type');
+    my $len = $r->header('Content-Length');
+
+    if ($te && lc($te) eq 'chunked') {
+	# Handle chunked transfer encoding
+	my $body = "";
+      CHUNK:
+	while (1) {
+	    print STDERR "Chunked\n" if $DEBUG;
+	    if ($buf =~ s/^([^\012]*)\012//) {
+		my $chunk_head = $1;
+		unless ($chunk_head =~ /^([0-9A-Fa-f]+)/) {
+		    $self->send_error(400);
+		    $self->reason("Bad chunk header $chunk_head");
+		    return;
+		}
+		my $size = hex($1);
+		last CHUNK if $size == 0;
+
+		my $missing = $size - length($buf) + 2; # 2=CRLF at chunk end
+		# must read until we have a complete chunk
+		while ($missing > 0) {
+		    print STDERR "Need $missing more bytes\n" if $DEBUG;
+		    my $n = $self->_need_more($buf, $timeout, $fdset);
+		    return unless $n;
+		    $missing -= $n;
+		}
+		$body .= substr($buf, 0, $size);
+		substr($buf, 0, $size+2) = '';
+
+	    } else {
+		# need more data in order to have a complete chunk header
+		return unless $self->_need_more($buf, $timeout, $fdset);
+	    }
+	}
+	$r->content($body);
+
+	# pretend it was a normal entity body
+	$r->remove_header('Transfer-Encoding');
+	$r->header('Content-Length', length($body));
+
+	my($key, $val);
+      FOOTER:
+	while (1) {
+	    if ($buf !~ /\012/) {
+		# need at least one line to look at
+		return unless $self->_need_more($buf, $timeout, $fdset);
+	    } else {
+		$buf =~ s/^([^\012]*)\012//;
+		$_ = $1;
+		s/\015$//;
+		if (/^([\w\-]+)\s*:\s*(.*)/) {
+		    $r->push_header($key, $val) if $key;
+		    ($key, $val) = ($1, $2);
+		} elsif (/^\s+(.*)/) {
+		    $val .= " $1";
+		} elsif (!length) {
+		    last FOOTER;
+		} else {
+		    $self->reason("Bad footer syntax");
+		    return;
+		}
+	    }
+	}
+	$r->push_header($key, $val) if $key;
+
+    } elsif ($te) {
+	$self->send_error(501); 	# Unknown transfer encoding
+	$self->reason("Unknown transfer encoding '$te'");
+	return;
+
+    } elsif ($ct && lc($ct) =~ m/^multipart\/\w+\s*;.*boundary\s*=\s*(\w+)/) {
+	# Handle multipart content type
+	my $boundary = "$CRLF--$1--$CRLF";
+	my $index;
+	while (1) {
+	    $index = index($buf, $boundary);
+	    last if $index >= 0;
+	    # end marker not yet found
+	    return unless $self->_need_more($buf, $timeout, $fdset);
+	}
+	$index += length($boundary);
+	$r->content(substr($buf, 0, $index));
+	substr($buf, 0, $index) = '';
+
+    } elsif ($len) {
+	# Plain body specified by "Content-Length"
+	my $missing = $len - length($buf);
+	while ($missing > 0) {
+	    print "Need $missing more bytes of content\n" if $DEBUG;
+	    my $n = $self->_need_more($buf, $timeout, $fdset);
+	    return unless $n;
+	    $missing -= $n;
+	}
+	if (length($buf) > $len) {
+	    $r->content(substr($buf,0,$len));
+	    substr($buf, 0, $len) = '';
+	} else {
+	    $r->content($buf);
+	    $buf='';
+	}
+    }
+    ${*$self}{'httpd_rbuf'} = $buf;
+
+    $r;
+}
+
+sub _need_more
+{
+    my $self = shift;
+    #my($buf,$timeout,$fdset) = @_;
+    if ($_[1]) {
+	my($timeout, $fdset) = @_[1,2];
+	print STDERR "select(,,,$timeout)\n" if $DEBUG;
+	my $n = select($fdset,undef,undef,$timeout);
+	unless ($n) {
+	    $self->reason(defined($n) ? "Timeout" : "select: $!");
+	    return;
+	}
+    }
+    print STDERR "sysread()\n" if $DEBUG;
+    my $n = sysread($self, $_[0], 2048, length($_[0]));
+    $self->reason(defined($n) ? "Client closed" : "sysread: $!") unless $n;
+    $n;
+}
+
+=item $c->read_buffer([$new_value])
+
+Bytes read by $c->get_request, but not used are placed in the I<read
+buffer>.  The next time $c->get_request is called it will consume the
+bytes in this buffer before reading more data from the network
+connection itself.  The read buffer is invalid after $c->get_request
+has returned an undefined value.
+
+If you handle the reading of the request content yourself you need to
+empty this buffer before you read more and you need to place
+unconsumed bytes here.  You also need this buffer if you implement
+services like I<101 Switching Protocols>.
+
+This method always return the old buffer content and can optionally
+update the buffer content if you pass it an argument.
+
+=cut
+
+sub read_buffer
+{
+    my $self = shift;
+    my $old = ${*$self}{'httpd_rbuf'};
+    if (@_) {
+	${*$self}{'httpd_rbuf'} = shift;
+    }
+    $old;
+}
+
+
+=item $c->reason
+
+When $c->get_request returns C<undef> you can obtain a short string
+describing why it happened by calling $c->reason.
+
+=cut
+
+sub reason
+{
+    my $self = shift;
+    my $old = ${*$self}{'httpd_reason'};
+    if (@_) {
+        ${*$self}{'httpd_reason'} = shift;
+    }
+    $old;
+}
+
+
+=item $c->proto_ge($proto)
+
+Returns TRUE if the client announced a protocol with version number
+greater or equal to the given argument.  The $proto argument can be a
+string like "HTTP/1.1" or just "1.1".
+
+=cut
+
+sub proto_ge
+{
+    my $self = shift;
+    ${*$self}{'httpd_client_proto'} >= _http_version(shift);
+}
+
+sub _http_version
+{
+    local($_) = shift;
+    return 0 unless m,^(?:HTTP/)?(\d+)\.(\d+)$,i;
+    $1 * 1000 + $2;
+}
+
+=item $c->antique_client
+
+Returns TRUE if the client speaks the HTTP/0.9 protocol.  No status
+code and no headers should be returned to such a client.  This should
+be the same as !$c->proto_ge("HTTP/1.0").
+
+=cut
+
+sub antique_client
+{
+    my $self = shift;
+    ${*$self}{'httpd_client_proto'} < $HTTP_1_0;
+}
+
+
+=item $c->force_last_request
+
+Make sure that $c->get_request will not try to read more requests off
+this connection.  If you generate a response that is not self
+delimiting, then you should signal this fact by calling this method.
+
+This attribute is turned on automatically if the client announce
+protocol HTTP/1.0 or worse and does not include a "Connection:
+Keep-Alive" header.  It is also turned on automatically when HTTP/1.1
+or better clients send the "Connection: close" request header.
+
+=cut
+
+sub force_last_request
+{
+    my $self = shift;
+    ${*$self}{'httpd_nomore'}++;
+}
+
+
+=item $c->send_status_line( [$code, [$mess, [$proto]]] )
+
+Sends the status line back to the client.  If $code is omitted 200 is
+assumed.  If $mess is omitted, then a message corresponding to $code
+is inserted.  If $proto is missing the content of the
+$HTTP::Daemon::PROTO variable is used.
+
+=cut
+
+sub send_status_line
+{
+    my($self, $status, $message, $proto) = @_;
+    return if $self->antique_client;
+    $status  ||= RC_OK;
+    $message ||= status_message($status) || "";
+    $proto   ||= $HTTP::Daemon::PROTO || "HTTP/1.1";
+    print $self "$proto $status $message$CRLF";
+}
+
+=item $c->send_crlf
+
+Send the CRLF sequence to the client.
+
+=cut
+
+
+sub send_crlf
+{
+    my $self = shift;
+    print $self $CRLF;
+}
+
+
+=item $c->send_basic_header( [$code, [$mess, [$proto]]] )
+
+Sends the status line and the "Date:" and "Server:" headers back to
+the client.  This header is assumed to be continued and does not end
+with an empty CRLF line.
+
+=cut
+
+sub send_basic_header
+{
+    my $self = shift;
+    return if $self->antique_client;
+    $self->send_status_line(@_);
+    print $self "Date: ", time2str(time), $CRLF;
+    my $product = $self->daemon->product_tokens;
+    print $self "Server: $product$CRLF" if $product;
+}
+
+
+=item $c->send_response( [$res] )
+
+Takes a I<HTTP::Response> object as parameter and write it back to the
+client as the response.  We try hard to make sure that the response is
+self delimiting so that the connection can stay persistent for further
+request/response exchanges.
+
+The content attribute of the I<HTTP::Response> object can be a normal
+string or a subroutine reference.  If it is a subroutine, then
+whatever this callback routine returns will be written back to the
+client as the response content.  The routine will be called until it
+return an undefined or empty value.  If the client is HTTP/1.1 aware
+then we will use the chunked transfer encoding for the response.
+
+=cut
+
+sub send_response
+{
+    my $self = shift;
+    my $res = shift;
+    if (!ref $res) {
+	$res ||= RC_OK;
+	$res = HTTP::Response->new($res, @_);
+    }
+    my $content = $res->content;
+    my $chunked;
+    unless ($self->antique_client) {
+	my $code = $res->code;
+	$self->send_basic_header($code, $res->message, $res->protocol);
+	if ($code =~ /^(1\d\d|[23]04)$/) {
+	    # make sure content is empty
+	    $res->remove_header("Content-Length");
+	    $content = "";
+	} elsif ($res->request && $res->request->method eq "HEAD") {
+	    # probably OK
+	} elsif (ref($content) eq "CODE") {
+	    if ($self->proto_ge("HTTP/1.1")) {
+		$res->push_header("Transfer-Encoding" => "chunked");
+		$chunked++;
+	    } else {
+		$self->force_last_request;
+	    }
+	} elsif (length($content)) {
+	    $res->header("Content-Length" => length($content));
+	} else {
+	    $self->force_last_request;
+	}
+	print $self $res->headers_as_string($CRLF);
+	print $self $CRLF;  # separates headers and content
+    }
+    if (ref($content) eq "CODE") {
+	while (1) {
+	    my $chunk = &$content();
+	    last unless defined($chunk) && length($chunk);
+	    if ($chunked) {
+		printf $self "%x%s%s%s", length($chunk), $CRLF, $chunk, $CRLF;
+	    } else {
+		print $self $chunk;
+	    }
+	}
+	print $self "0$CRLF$CRLF" if $chunked;  # no trailers either
+    } elsif (length $content) {
+	print $self $content;
+    }
+}
+
+
+=item $c->send_redirect( $loc, [$code, [$entity_body]] )
+
+Sends a redirect response back to the client.  The location ($loc) can
+be an absolute or a relative URL. The $code must be one the redirect
+status codes, and it defaults to "301 Moved Permanently"
+
+=cut
+
+sub send_redirect
+{
+    my($self, $loc, $status, $content) = @_;
+    $status ||= RC_MOVED_PERMANENTLY;
+    Carp::croak("Status '$status' is not redirect") unless is_redirect($status);
+    $self->send_basic_header($status);
+    $loc = url($loc, $self->daemon->url) unless ref($loc);
+    $loc = $loc->abs;
+    print $self "Location: $loc$CRLF";
+    if ($content) {
+	my $ct = $content =~ /^\s*</ ? "text/html" : "text/plain";
+	print $self "Content-Type: $ct$CRLF";
+    }
+    print $self $CRLF;
+    print $self $content if $content;
+    $self->force_last_request;  # no use keeping the connection open
+}
+
+
+=item $c->send_error( [$code, [$error_message]] )
+
+Send an error response back to the client.  If the $code is missing a
+"Bad Request" error is reported.  The $error_message is a string that
+is incorporated in the body of the HTML entity body.
+
+=cut
+
+sub send_error
+{
+    my($self, $status, $error) = @_;
+    $status ||= RC_BAD_REQUEST;
+    Carp::croak("Status '$status' is not an error") unless is_error($status);
+    my $mess = status_message($status);
+    $error  ||= "";
+    $mess = <<EOT;
+<title>$status $mess</title>
+<h1>$status $mess</h1>
+$error
+EOT
+    unless ($self->antique_client) {
+        $self->send_basic_header($status);
+        print $self "Content-Type: text/html$CRLF";
+	print $self "Content-Length: " . length($mess) . $CRLF;
+        print $self $CRLF;
+    }
+    print $self $mess;
+    $status;
+}
+
+
+=item $c->send_file_response($filename)
+
+Send back a response with the specified $filename as content.  If the
+file happen to be a directory we will try to generate an HTML index
+of it.
+
+=cut
+
+sub send_file_response
+{
+    my($self, $file) = @_;
+    if (-d $file) {
+	$self->send_dir($file);
+    } elsif (-f _) {
+	# plain file
+	local(*F);
+	sysopen(F, $file, 0) or 
+	  return $self->send_error(RC_FORBIDDEN);
+	my($ct,$ce) = guess_media_type($file);
+	my($size,$mtime) = (stat _)[7,9];
+	unless ($self->antique_client) {
+	    $self->send_basic_header;
+	    print $self "Content-Type: $ct$CRLF";
+	    print $self "Content-Encoding: $ce$CRLF" if $ce;
+	    print $self "Content-Length: $size$CRLF" if $size;
+	    print $self "Last-Modified: ", time2str($mtime), "$CRLF" if $mtime;
+	    print $self $CRLF;
+	}
+	$self->send_file(\*F);
+	return RC_OK;
+    } else {
+	$self->send_error(RC_NOT_FOUND);
+    }
+}
+
+
+sub send_dir
+{
+    my($self, $dir) = @_;
+    $self->send_error(RC_NOT_FOUND) unless -d $dir;
+    $self->send_error(RC_NOT_IMPLEMENTED);
+}
+
+
+=item $c->send_file($fd);
+
+Copies the file back to the client.  The file can be a string (which
+will be interpreted as a filename) or a reference to an I<IO::Handle>
+or glob.
+
+=cut
+
+sub send_file
+{
+    my($self, $file) = @_;
+    my $opened = 0;
+    if (!ref($file)) {
+	local(*F);
+	open(F, $file) || return undef;
+	binmode(F);
+	$file = \*F;
+	$opened++;
+    }
+    my $cnt = 0;
+    my $buf = "";
+    my $n;
+    while ($n = sysread($file, $buf, 8*1024)) {
+	last if !$n;
+	$cnt += $n;
+	print $self $buf;
+    }
+    close($file) if $opened;
+    $cnt;
+}
+
+
+=item $c->daemon
+
+Return a reference to the corresponding I<HTTP::Daemon> object.
+
+=cut
+
+sub daemon
+{
+    my $self = shift;
+    ${*$self}{'httpd_daemon'};
+}
+
+=back
+
+=head1 SEE ALSO
+
+RFC 2068
+
+L<IO::Socket>, L<Apache>
+
+=head1 COPYRIGHT
+
+Copyright 1996-1998, Gisle Aas
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Date.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Date.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Date.pm	(revision 16571)
@@ -0,0 +1,330 @@
+# $Id$
+#
+package HTTP::Date;
+
+=head1 NAME
+
+HTTP::Date - date conversion routines
+
+=head1 SYNOPSIS
+
+ use HTTP::Date;
+
+ $string = time2str($time);    # Format as GMT ASCII time
+ $time = str2time($string);    # convert ASCII date to machine time
+
+=head1 DESCRIPTION
+
+This module provides two functions that deal with the HTTP date
+format.  The following functions are provided:
+
+=over 4
+
+=item time2str([$time])
+
+The time2str() function converts a machine time (seconds since epoch)
+to a string.  If the function is called without an argument, it will
+use the current time.
+
+The string returned is in the format defined by the HTTP/1.0
+specification.  This is a fixed length subset of the format defined by
+RFC 1123, represented in Universal Time (GMT).  An example of this
+format is:
+
+   Thu, 03 Feb 1994 17:09:00 GMT
+
+=item str2time($str [, $zone])
+
+The str2time() function converts a string to machine time.  It returns
+C<undef> if the format is unrecognized, or the year is not between 1970
+and 2038.  The function is able to parse the following formats:
+
+ "Wed, 09 Feb 1994 22:23:32 GMT"       -- HTTP format
+ "Thu Feb  3 17:03:55 GMT 1994"        -- ctime(3) format
+ "Thu Feb  3 00:00:00 1994",           -- ANSI C asctime() format
+ "Tuesday, 08-Feb-94 14:15:29 GMT"     -- old rfc850 HTTP format
+ "Tuesday, 08-Feb-1994 14:15:29 GMT"   -- broken rfc850 HTTP format
+
+ "03/Feb/1994:17:03:55 -0700"   -- common logfile format
+ "09 Feb 1994 22:23:32 GMT"     -- HTTP format (no weekday)
+ "08-Feb-94 14:15:29 GMT"       -- rfc850 format (no weekday)
+ "08-Feb-1994 14:15:29 GMT"     -- broken rfc850 format (no weekday)
+
+ "1994-02-03 14:15:29 -0100"    -- ISO 8601 format
+ "1994-02-03 14:15:29"          -- zone is optional
+ "1994-02-03"                   -- only date
+ "1994-02-03T14:15:29"          -- Use T as separator
+ "19940203T141529Z"             -- ISO 8601 compact format
+ "19940203"                     -- only date
+
+ "08-Feb-94"         -- old rfc850 HTTP format    (no weekday, no time)
+ "08-Feb-1994"       -- broken rfc850 HTTP format (no weekday, no time)
+ "09 Feb 1994"       -- proposed new HTTP format  (no weekday, no time)
+ "03/Feb/1994"       -- common logfile format     (no time, no offset)
+
+ "Feb  3  1994"      -- Unix 'ls -l' format
+ "Feb  3 17:03"      -- Unix 'ls -l' format
+
+ "11-15-96  03:52PM" -- Windows 'dir' format
+
+The parser ignores leading and trailing whitespace.  It also allow the
+seconds to be missing and the month to be numerical in most formats.
+
+The str2time() function takes an optional second argument that
+specifies the default time zone to use when converting the date.  This
+zone specification should be numerical (like "-0800" or "+0100") or
+"GMT".  This parameter is ignored if the zone is specified in the date
+string itself.  It this parameter is missing, and the date string
+format does not contain any zone specification then the local time
+zone is assumed.
+
+If the year is missing, then we assume that the date is the first
+matching date I<before> current time.
+
+=back
+
+=head1 BUGS
+
+Non-numerical time zones (like MET, PST) are all treated like GMT.
+Do not use them.  HTTP does not use them.
+
+The str2time() function has been told how to parse far too many
+formats.  This makes the module name misleading. To be sure it is
+really misleading you can also import the time2iso() and time2isoz()
+functions.  They work like time2str() but produce ISO-8601 formated
+strings (YYYY-MM-DD hh:mm:ss).
+
+=head1 COPYRIGHT
+
+Copyright 1995-1997, Gisle Aas
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
+
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+sub Version { $VERSION; }
+
+require 5.002;
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT = qw(time2str str2time);
+@EXPORT_OK = qw(time2iso time2isoz);
+
+use Time::Local ();
+
+use strict;
+use vars qw(@DoW @MoY %MoY);
+
+#@DoW = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
+@DoW = qw(Sun Mon Tue Wed Thu Fri Sat);
+@MoY = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
+# Build %MoY hash
+my $i = 0;
+foreach(@MoY) {
+   $MoY{lc $_} = $i++;
+}
+
+my($current_month, $current_year) = (localtime)[4, 5];
+
+
+
+
+sub time2str (;$)
+{
+   my $time = shift;
+   $time = time unless defined $time;
+   my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($time);
+   sprintf("%s, %02d %s %04d %02d:%02d:%02d GMT",
+	   $DoW[$wday],
+	   $mday, $MoY[$mon], $year+1900,
+	   $hour, $min, $sec);
+}
+
+
+
+sub str2time ($;$)
+{
+   local($_) = shift;
+   return undef unless defined;
+   my($default_zone) = @_;
+
+   # Remove useless weekday, if it exists
+   s/^\s*(?:sun|mon|tue|wed|thu|fri|sat)\w*,?\s*//i;
+
+   my($day, $mon, $yr, $hr, $min, $sec, $tz, $aorp);
+   my $offset = 0;  # used when compensating for timezone
+
+ PARSEDATE: {
+      # Then we are able to check for most of the formats with this regexp
+      ($day,$mon,$yr,$hr,$min,$sec,$tz) =
+	/^\s*
+	 (\d\d?)               # day
+	    (?:\s+|[-\/])
+	 (\w+)                 # month
+	    (?:\s+|[-\/])
+	 (\d+)                 # year
+	 (?:
+	       (?:\s+|:)       # separator before clock
+	    (\d\d?):(\d\d)     # hour:min
+	    (?::(\d\d))?       # optional seconds
+	 )?                    # optional clock
+	    \s*
+	 ([-+]?\d{2,4}|GMT|gmt)? # timezone
+	    \s*$
+	/x
+	  and last PARSEDATE;
+
+      # Try the ctime and asctime format
+      ($mon, $day, $hr, $min, $sec, $tz, $yr) =
+	/^\s*                  # allow intial whitespace
+	 (\w{1,3})             # month
+	    \s+
+	 (\d\d?)               # day
+	    \s+
+	 (\d\d?):(\d\d)        # hour:min
+	 (?::(\d\d))?          # optional seconds
+	    \s+
+	 (?:(GMT|gmt)\s+)?     # optional GMT timezone
+	 (\d+)                 # year
+	    \s*$               # allow trailing whitespace
+	/x
+	  and last PARSEDATE;
+
+      # Then the Unix 'ls -l' date format
+      ($mon, $day, $yr, $hr, $min, $sec) =
+	/^\s*
+	 (\w{3})               # month
+	    \s+
+	 (\d\d?)               # day
+	    \s+
+	 (?:
+	    (\d\d\d\d) |       # year
+	    (\d{1,2}):(\d{2})  # hour:min
+            (?::(\d\d))?       # optional seconds
+	 )
+	 \s*$
+       /x
+	 and last PARSEDATE;
+
+      # ISO 8601 format '1996-02-29 12:00:00 -0100' and variants
+      ($yr, $mon, $day, $hr, $min, $sec, $tz) =
+	/^\s*
+	  (\d{4})              # year
+	     [-\/]?
+	  (\d\d?)              # numerical month
+	     [-\/]?
+	  (\d\d?)              # day
+	 (?:
+	       (?:\s+|:|T|-)   # separator before clock
+	    (\d\d?):?(\d\d)    # hour:min
+	    (?::?(\d\d))?      # optional seconds
+	 )?                    # optional clock
+	    \s*
+	 ([-+]?\d\d?:?(:?\d\d)?
+	  |Z|z)?               # timezone  (Z is "zero meridian", i.e. GMT)
+	    \s*$
+	/x
+	  and last PARSEDATE;
+
+      # Windows 'dir' 11-12-96  03:52PM
+      ($mon, $day, $yr, $hr, $min, $aorp) =
+        /^\s*
+          (\d{2})                # numerical month
+             -
+          (\d{2})                # day
+             -
+          (\d{2})                # year
+             \s+
+          (\d\d?):(\d\d)([apAP][mM])  # hour:min AM or PM
+             \s*$
+        /x
+          and last PARSEDATE;
+
+      # If it is not recognized by now we give up
+      return undef;
+   }
+
+   # Translate month name to number
+   if ($mon =~ /^\d+$/) {
+     # numeric month
+     return undef if $mon < 1 || $mon > 12;
+     $mon--;
+   } else {
+     $mon = lc $mon;
+     return undef unless exists $MoY{$mon};
+     $mon = $MoY{$mon};
+   }
+
+   # If the year is missing, we assume some date before the current,
+   # because these date are mostly present on "ls -l" listings.
+   unless (defined $yr) {
+	$yr = $current_year;
+	$yr-- if $mon > $current_month;
+    }
+
+   # Then we check if the year is acceptable
+   return undef if $yr > 99 && $yr < 1900;  # We ignore these years
+   $yr += 100 if $yr < 50;  # a stupid thing to do???
+   $yr -= 1900 if $yr >= 1900;
+   # The $yr is now relative to 1900 (as expected by timelocal())
+
+   # timelocal() seems to go into an infinite loop if it is given out
+   # of range parameters.  Let's check the year at least.
+
+   # Epoch counter maxes out in year 2038, assuming "time_t" is 32 bit
+   return undef if $yr > 138;
+   return undef if $yr <  70;  # 1970 is Unix epoch
+
+   # Compensate for AM/PM
+   if ($aorp) {
+       $aorp = uc $aorp;
+       $hr = 0 if $hr == 12 && $aorp eq 'AM';
+       $hr += 12 if $aorp eq 'PM' && $hr != 12;
+   }
+
+   # Make sure things are defined
+   for ($sec, $min, $hr) {  $_ = 0 unless defined   }
+
+   # Should we compensate for the timezone?
+   $tz = $default_zone unless defined $tz;
+   return eval {Time::Local::timelocal($sec, $min, $hr, $day, $mon, $yr)}
+     unless defined $tz;
+
+   # We can calculate offset for numerical time zones
+   if ($tz =~ /^([-+])?(\d\d?):?(\d\d)?$/) {
+       $offset = 3600 * $2;
+       $offset += 60 * $3 if $3;
+       $offset *= -1 if $1 && $1 ne '-';
+   }
+   eval{Time::Local::timegm($sec, $min, $hr, $day, $mon, $yr) + $offset};
+}
+
+
+
+# And then some bloat because I happen to like the ISO 8601 time
+# format.
+
+sub time2iso (;$)
+{
+   my $time = shift;
+   $time = time unless defined $time;
+   my($sec,$min,$hour,$mday,$mon,$year) = localtime($time);
+   sprintf("%04d-%02d-%02d %02d:%02d:%02d",
+	   $year+1900, $mon+1, $mday, $hour, $min, $sec);
+}
+
+
+sub time2isoz (;$)
+{
+    my $time = shift;
+    $time = time unless defined $time;
+    my($sec,$min,$hour,$mday,$mon,$year) = gmtime($time);
+    sprintf("%04d-%02d-%02d %02d:%02d:%02dZ",
+            $year+1900, $mon+1, $mday, $hour, $min, $sec);
+}
+
+1;
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers.pm	(revision 16571)
@@ -0,0 +1,540 @@
+#
+# $Id$
+
+package HTTP::Headers;
+
+=head1 NAME
+
+HTTP::Headers - Class encapsulating HTTP Message headers
+
+=head1 SYNOPSIS
+
+ require HTTP::Headers;
+ $h = new HTTP::Headers;
+
+=head1 DESCRIPTION
+
+The C<HTTP::Headers> class encapsulates HTTP-style message headers.
+The headers consist of attribute-value pairs, which may be repeated,
+and which are printed in a particular order.
+
+Instances of this class are usually created as member variables of the
+C<HTTP::Request> and C<HTTP::Response> classes, internal to the
+library.
+
+The following methods are available:
+
+=over 4
+
+=cut
+
+use strict;
+use vars qw($VERSION $TRANSLATE_UNDERSCORE);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+use Carp ();
+
+# Could not use the AutoLoader becase several of the method names are
+# not unique in the first 8 characters.
+#use SelfLoader;
+
+
+# "Good Practice" order of HTTP message headers:
+#    - General-Headers
+#    - Request-Headers
+#    - Response-Headers
+#    - Entity-Headers
+# (From draft-ietf-http-v11-spec-rev-01, Nov 21, 1997)
+
+my @header_order = qw(
+   Cache-Control Connection Date Pragma Transfer-Encoding Upgrade Trailer Via
+
+   Accept Accept-Charset Accept-Encoding Accept-Language
+   Authorization Expect From Host
+   If-Modified-Since If-Match If-None-Match If-Range If-Unmodified-Since
+   Max-Forwards Proxy-Authorization Range Referer TE User-Agent
+
+   Accept-Ranges Age Location Proxy-Authenticate Retry-After Server Vary
+   Warning WWW-Authenticate
+
+   Allow Content-Base Content-Encoding Content-Language Content-Length
+   Content-Location Content-MD5 Content-Range Content-Type
+   ETag Expires Last-Modified
+);
+
+# Make alternative representations of @header_order.  This is used
+# for sorting and case matching.
+my $i = 0;
+my %header_order;
+my %standard_case;
+for (@header_order) {
+    my $lc = lc $_;
+    $header_order{$lc} = $i++;
+    $standard_case{$lc} = $_;
+}
+
+$TRANSLATE_UNDERSCORE = 1 unless defined $TRANSLATE_UNDERSCORE;
+
+
+
+=item $h = new HTTP::Headers
+
+Constructs a new C<HTTP::Headers> object.  You might pass some initial
+attribute-value pairs as parameters to the constructor.  I<E.g.>:
+
+ $h = new HTTP::Headers
+     Date         => 'Thu, 03 Feb 1994 00:00:00 GMT',
+     Content_Type => 'text/html; version=3.2',
+     Content_Base => 'http://www.sn.no/';
+
+=cut
+
+sub new
+{
+    my($class) = shift;
+    my $self = bless {}, $class;
+    $self->header(@_); # set up initial headers
+    $self;
+}
+
+
+=item $h->header($field [=> $value],...)
+
+Get or set the value of a header.  The header field name is not case
+sensitive.  To make the life easier for perl users who wants to avoid
+quoting before the => operator, you can use '_' as a synonym for '-'
+in header names (this behaviour can be suppressed by setting
+$HTTP::Headers::TRANSLATE_UNDERSCORE to a FALSE value).
+
+The header() method accepts multiple ($field => $value) pairs, so you
+can update several fields with a single invocation.
+
+The optional $value argument may be a scalar or a reference to a list
+of scalars. If the $value argument is undefined or not given, then the
+header is not modified.
+
+The old value of the last of the $field values is returned.
+Multi-valued fields will be concatenated with "," as separator in
+scalar context.
+
+ $header->header(MIME_Version => '1.0',
+		 User_Agent   => 'My-Web-Client/0.01');
+ $header->header(Accept => "text/html, text/plain, image/*");
+ $header->header(Accept => [qw(text/html text/plain image/*)]);
+ @accepts = $header->header('Accept');
+
+=cut
+
+sub header
+{
+    my $self = shift;
+    my($field, $val, @old);
+    while (($field, $val) = splice(@_, 0, 2)) {
+	@old = $self->_header($field, $val);
+    }
+    return @old if wantarray;
+    return $old[0] if @old <= 1;
+    join(", ", @old);
+}
+
+sub _header
+{
+    my($self, $field, $val, $push) = @_;
+    $field =~ tr/_/-/ if $TRANSLATE_UNDERSCORE;
+
+    # $push is only used interally sub push_header
+    Carp::croak('Need a field name') unless length($field);
+
+    my $lc_field = lc $field;
+    unless(defined $standard_case{$lc_field}) {
+	# generate a %stadard_case entry for this field
+	$field =~ s/\b(\w)/\u$1/g;
+	$standard_case{$lc_field} = $field;
+    }
+
+    my $h = $self->{$lc_field};
+    my @old = ref($h) ? @$h : (defined($h) ? ($h) : ());
+
+    if (defined $val) {
+	my @new = $push ? @old : ();
+	if (!ref($val)) {
+	    push(@new, $val);
+	} elsif (ref($val) eq 'ARRAY') {
+	    push(@new, @$val);
+	} else {
+	    Carp::croak("Unexpected field value $val");
+	}
+	$self->{$lc_field} = @new > 1 ? \@new : $new[0];
+    }
+    @old;
+}
+
+
+# Compare function which makes it easy to sort headers in the
+# recommended "Good Practice" order.
+sub _header_cmp
+{
+    # Unknown headers are assign a large value so that they are
+    # sorted last.  This also helps avoiding a warning from -w
+    # about comparing undefined values.
+    $header_order{$a} = 999 unless defined $header_order{$a};
+    $header_order{$b} = 999 unless defined $header_order{$b};
+
+    $header_order{$a} <=> $header_order{$b} || $a cmp $b;
+}
+
+
+=item $h->scan(\&doit)
+
+Apply a subroutine to each header in turn.  The callback routine is
+called with two parameters; the name of the field and a single value.
+If the header has more than one value, then the routine is called once
+for each value.  The field name passed to the callback routine has
+case as suggested by HTTP Spec, and the headers will be visited in the
+recommended "Good Practice" order.
+
+=cut
+
+sub scan
+{
+    my($self, $sub) = @_;
+    my $key;
+    foreach $key (sort _header_cmp keys %$self) {
+        next if $key =~ /^_/;
+	my $vals = $self->{$key};
+	if (ref($vals)) {
+	    my $val;
+	    for $val (@$vals) {
+		&$sub($standard_case{$key} || $key, $val);
+	    }
+	} else {
+	    &$sub($standard_case{$key} || $key, $vals);
+	}
+    }
+}
+
+
+=item $h->as_string([$endl])
+
+Return the header fields as a formatted MIME header.  Since it
+internally uses the C<scan()> method to build the string, the result
+will use case as suggested by HTTP Spec, and it will follow
+recommended "Good Practice" of ordering the header fieds.  Long header
+values are not folded. 
+
+The optional parameter specifies the line ending sequence to use.  The
+default is C<"\n">.  Embedded "\n" characters in the header will be
+substitued with this line ending sequence.
+
+=cut
+
+sub as_string
+{
+    my($self, $endl) = @_;
+    $endl = "\n" unless defined $endl;
+
+    my @result = ();
+    $self->scan(sub {
+	my($field, $val) = @_;
+	if ($val =~ /\n/) {
+	    # must handle header values with embedded newlines with care
+	    $val =~ s/\s+$//;          # trailing newlines and space must go
+	    $val =~ s/\n\n+/\n/g;      # no empty lines
+	    $val =~ s/\n([^\040\t])/\n $1/g;  # intial space for continuation
+	    $val =~ s/\n/$endl/g;      # substitute with requested line ending
+	}
+	push(@result, "$field: $val");
+    });
+
+    join($endl, @result, '');
+}
+
+
+# The remaining functions should autoloaded only when needed
+
+# A bug in 5.002gamma makes it risky to have POD text inside the
+# autoloaded section of the code, so we keep the documentation before
+# the __DATA__ token.
+
+=item $h->push_header($field, $val)
+
+Add a new field value of the specified header.  The header field name
+is not case sensitive.  The field need not already have a
+value. Previous values for the same field are retained.  The argument
+may be a scalar or a reference to a list of scalars.
+
+ $header->push_header(Accept => 'image/jpeg');
+
+=item $h->remove_header($field,...)
+
+This function removes the headers with the specified names.
+
+=item $h->clone
+
+Returns a copy of this HTTP::Headers object.
+
+=back
+
+=head1 CONVENIENCE METHODS
+
+The most frequently used headers can also be accessed through the
+following convenience methods.  These methods can both be used to read
+and to set the value of a header.  The header value is set if you pass
+an argument to the method.  The old header value is always returned.
+
+Methods that deal with dates/times always convert their value to system
+time (seconds since Jan 1, 1970) and they also expect this kind of
+value when the header value is set.
+
+=over 4
+
+=item $h->date
+
+This header represents the date and time at which the message was
+originated. I<E.g.>:
+
+  $h->date(time);  # set current date
+
+=item $h->expires
+
+This header gives the date and time after which the entity should be
+considered stale.
+
+=item $h->if_modified_since
+
+=item $h->if_unmodified_since
+
+This header is used to make a request conditional.  If the requested
+resource has (not) been modified since the time specified in this field,
+then the server will return a C<"304 Not Modified"> response instead of
+the document itself.
+
+=item $h->last_modified
+
+This header indicates the date and time at which the resource was last
+modified. I<E.g.>:
+
+  # check if document is more than 1 hour old
+  if ($h->last_modified < time - 60*60) {
+	...
+  }
+
+=item $h->content_type
+
+The Content-Type header field indicates the media type of the message
+content. I<E.g.>:
+
+  $h->content_type('text/html');
+
+The value returned will be converted to lower case, and potential
+parameters will be chopped off and returned as a separate value if in
+an array context.  This makes it safe to do the following:
+
+  if ($h->content_type eq 'text/html') {
+     # we enter this place even if the real header value happens to
+     # be 'TEXT/HTML; version=3.0'
+     ...
+  }
+
+=item $h->content_encoding
+
+The Content-Encoding header field is used as a modifier to the
+media type.  When present, its value indicates what additional
+encoding mechanism has been applied to the resource.
+
+=item $h->content_length
+
+A decimal number indicating the size in bytes of the message content.
+
+=item $h->content_language
+
+The natural language(s) of the intended audience for the message
+content.  The value is one or more language tags as defined by RFC
+1766.  Eg. "no" for Norwegian and "en-US" for US-English.
+
+=item $h->title
+
+The title of the document.  In libwww-perl this header will be
+initialized automatically from the E<lt>TITLE>...E<lt>/TITLE> element
+of HTML documents.  I<This header is no longer part of the HTTP
+standard.>
+
+=item $h->user_agent
+
+This header field is used in request messages and contains information
+about the user agent originating the request.  I<E.g.>:
+
+  $h->user_agent('Mozilla/1.2');
+
+=item $h->server
+
+The server header field contains information about the software being
+used by the originating server program handling the request.
+
+=item $h->from
+
+This header should contain an Internet e-mail address for the human
+user who controls the requesting user agent.  The address should be
+machine-usable, as defined by RFC822.  E.g.:
+
+  $h->from('Gisle Aas <aas@sn.no>');
+
+=item $h->referer
+
+Used to specify the address (URI) of the document from which the
+requested resouce address was obtained.
+
+=item $h->www_authenticate
+
+This header must be included as part of a "401 Unauthorized" response.
+The field value consist of a challenge that indicates the
+authentication scheme and parameters applicable to the requested URI.
+
+=item $h->proxy_authenticate
+
+This header must be included in a "407 Proxy Authentication Required"
+response.
+
+=item $h->authorization
+
+=item $h->proxy_authorization
+
+A user agent that wishes to authenticate itself with a server or a
+proxy, may do so by including these headers.
+
+=item $h->authorization_basic
+
+This method is used to get or set an authorization header that use the
+"Basic Authentication Scheme".  In array context it will return two
+values; the user name and the password.  In scalar context it will
+return I<"uname:password"> as a single string value.
+
+When used to set the header value, it expects two arguments.  I<E.g.>:
+
+  $h->authorization_basic($uname, $password);
+
+The method will croak if the $uname contains a colon ':'.
+
+=item $h->proxy_authorization_basic
+
+Same as authorization_basic() but will set the "Proxy-Authorization"
+header instead.
+
+=back
+
+=head1 COPYRIGHT
+
+Copyright 1995-1998 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
+
+1;
+
+#__DATA__
+
+sub clone
+{
+    my $self = shift;
+    my $clone = new HTTP::Headers;
+    $self->scan(sub { $clone->push_header(@_);} );
+    $clone;
+}
+
+sub push_header
+{
+    Carp::croak('Usage: $h->push_header($field, $val)') if @_ != 3;
+    shift->_header(@_, 'PUSH');
+}
+
+
+sub remove_header
+{
+    my($self, @fields) = @_;
+    my $field;
+    foreach $field (@fields) {
+	$field =~ tr/_/-/ if $TRANSLATE_UNDERSCORE;
+	delete $self->{lc $field};
+    }
+}
+
+# Convenience access functions
+
+sub _date_header
+{
+    require HTTP::Date;
+    my($self, $header, $time) = @_;
+    my($old) = $self->_header($header);
+    if (defined $time) {
+	$self->_header($header, HTTP::Date::time2str($time));
+    }
+    HTTP::Date::str2time($old);
+}
+
+sub date                { shift->_date_header('Date',                @_); }
+sub expires             { shift->_date_header('Expires',             @_); }
+sub if_modified_since   { shift->_date_header('If-Modified-Since',   @_); }
+sub if_unmodified_since { shift->_date_header('If-Unmodified-Since', @_); }
+sub last_modified       { shift->_date_header('Last-Modified',       @_); }
+
+# This is used as a private LWP extention.  The Client-Date header is
+# added as a timestamp to a response when it has been received.
+sub client_date         { shift->_date_header('Client-Date',         @_); }
+
+# The retry_after field is dual format (can also be a expressed as
+# number of seconds from now), so we don't provide an easy way to
+# access it until we have know how both these interfaces can be
+# addressed.  One possibility is to return a negative value for
+# relative seconds and a positive value for epoch based time values.
+#sub retry_after       { shift->_date_header('Retry-After',       @_); }
+
+sub content_type      {
+  my $ct = (shift->_header('Content-Type', @_))[0];
+  return '' unless defined($ct) && length($ct);
+  my @ct = split(/\s*;\s*/, lc($ct));
+  wantarray ? @ct : $ct[0];
+}
+
+sub title             { (shift->_header('Title',            @_))[0] }
+sub content_encoding  { (shift->_header('Content-Encoding', @_))[0] }
+sub content_language  { (shift->_header('Content-Language', @_))[0] }
+sub content_length    { (shift->_header('Content-Length',   @_))[0] }
+
+sub user_agent        { (shift->_header('User-Agent',       @_))[0] }
+sub server            { (shift->_header('Server',           @_))[0] }
+
+sub from              { (shift->_header('From',             @_))[0] }
+sub referer           { (shift->_header('Referer',          @_))[0] }
+sub warning           { (shift->_header('Warning',          @_))[0] }
+
+sub www_authenticate  { (shift->_header('WWW-Authenticate', @_))[0] }
+sub authorization     { (shift->_header('Authorization',    @_))[0] }
+
+sub proxy_authenticate  { (shift->_header('Proxy-Authenticate',  @_))[0] }
+sub proxy_authorization { (shift->_header('Proxy-Authorization', @_))[0] }
+
+sub authorization_basic       { shift->_basic_auth("Authorization",       @_) }
+sub proxy_authorization_basic { shift->_basic_auth("Proxy-Authorization", @_) }
+
+sub _basic_auth {
+    require MIME::Base64;
+    my($self, $h, $user, $passwd) = @_;
+    my($old) = $self->_header($h);
+    if (defined $user) {
+	Carp::croak("Basic authorization user name can't contain ':'")
+	  if $user =~ /:/;
+	$passwd = '' unless defined $passwd;
+	$self->_header($h => 'Basic ' .
+                             MIME::Base64::encode("$user:$passwd", ''));
+    }
+    if (defined $old && $old =~ s/^\s*Basic\s+//) {
+	my $val = MIME::Base64::decode($old);
+	return $val unless wantarray;
+	return split(/:/, $val, 2);
+    }
+    return;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers/Auth.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers/Auth.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers/Auth.pm	(revision 16571)
@@ -0,0 +1,94 @@
+package HTTP::Headers::Auth;
+
+use strict;
+use vars qw($VERSION);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+require HTTP::Headers;
+package HTTP::Headers;
+
+BEGIN {
+    # we provide a new (and better) implementations below
+    undef(&www_authenticate);
+    undef(&proxy_authenticate);
+}
+
+require HTTP::Headers::Util;
+
+sub _parse_authenticate
+{
+    my @ret;
+    for (HTTP::Headers::Util::split_header_words(@_)) {
+	if (!defined($_->[1])) {
+	    # this is a new auth scheme
+	    push(@ret, lc(shift @$_) => {});
+	    shift @$_;
+	}
+	if (@ret) {
+	    # this a new parameter pair for the last auth scheme
+	    while (@$_) {
+		my $k = lc(shift @$_);
+		my $v = shift @$_;
+	        $ret[-1]{$k} = $v;
+	    }
+	} else {
+	    # something wrong, parameter pair without any scheme seen
+	    # IGNORE
+	}
+    }
+    @ret;
+}
+
+sub _authenticate
+{
+    my $self = shift;
+    my $header = shift;
+    my @old = $self->_header($header);
+    if (@_) {
+	$self->remove_header($header);
+	my @new = @_;
+	while (@new) {
+	    my $a_scheme = shift(@new);
+	    if ($a_scheme =~ /\s/) {
+		# assume complete valid value, pass it through
+		$self->push_header($header, $a_scheme);
+	    } else {
+		my @param;
+		if (@new) {
+		    my $p = $new[0];
+		    if (ref($p) eq "ARRAY") {
+			@param = @$p;
+			shift(@new);
+		    } elsif (ref($p) eq "HASH") {
+			@param = %$p;
+			shift(@new);
+		    }
+		}
+		my $val = ucfirst(lc($a_scheme));
+		if (@param) {
+		    my $sep = " ";
+		    while (@param) {
+			my $k = shift @param;
+			my $v = shift @param;
+			if ($v =~ /[^0-9a-zA-Z]/ || lc($k) eq "realm") {
+			    # must quote the value
+			    $v =~ s,([\\\"]),\\$1,g;
+			    $v = qq("$v");
+			}
+			$val .= "$sep$k=$v";
+			$sep = ", ";
+		    }
+		}
+		$self->push_header($header, $val);
+	    }
+	}
+    }
+    return unless defined wantarray;
+    wantarray ? _parse_authenticate(@old) : join(", ", @old);
+}
+
+
+sub www_authenticate    { shift->_authenticate("WWW-Authenticate", @_)   }
+sub proxy_authenticate  { shift->_authenticate("Proxy-Authenticate", @_) }
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers/ETag.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers/ETag.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers/ETag.pm	(revision 16571)
@@ -0,0 +1,88 @@
+package HTTP::Header::ETag;
+
+use strict;
+use vars qw($VERSION);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+require HTTP::Date;
+
+require HTTP::Headers;
+package HTTP::Headers;
+
+sub _etags
+{
+    my $self = shift;
+    my $header = shift;
+    my @old = _split_etag_list($self->_header($header));
+    if (@_) {
+	$self->_header($header => join(", ", _split_etag_list(@_)));
+    }
+    wantarray ? @old : join(", ", @old);
+}
+
+sub etag          { shift->_etags("ETag", @_); }
+sub if_match      { shift->_etags("If-Match", @_); }
+sub if_none_match { shift->_etags("If-None-Match", @_); }
+
+sub if_range {
+    # Either a date or an entity-tag
+    my $self = shift;
+    my @old = $self->_header("If-Range");
+    if (@_) {
+	my $new = shift;
+	if (!defined $new) {
+	    $self->remove_header("If-Range");
+	} elsif ($new =~ /^\d+$/) {
+	    $self->_date_header("If-Range", $new);
+	} else {
+	    $self->_etags("If-Range", $new);
+	}
+    }
+    return unless defined(wantarray);
+    for (@old) {
+	my $t = HTTP::Date::str2time($_);
+	$_ = $t if $t;
+    }
+    wantarray ? @old : join(", ", @old);
+}
+
+
+# Split a list of entity tag values.  The return value is a list
+# consisting of one element per entity tag.  Suitable for parsing
+# headers like C<If-Match>, C<If-None-Match>.  You might even want to
+# use it on C<ETag> and C<If-Range> entity tag values, because it will
+# normalize them to the common form.
+#
+#  entity-tag	  = [ weak ] opaque-tag
+#  weak		  = "W/"
+#  opaque-tag	  = quoted-string
+
+
+sub _split_etag_list
+{
+    my(@val) = @_;
+    my @res;
+    for (@val) {
+        while (length) {
+            my $weak = "";
+	    $weak = "W/" if s,^\s*[wW]/,,;
+            my $etag = "";
+	    if (s/^\s*(\"[^\"\\]*(?:\\.[^\"\\]*)*\")//) {
+		push(@res, "$weak$1");
+            } elsif (s/^\s*,//) {
+                push(@res, qq(W/"")) if $weak;
+            } elsif (s/^\s*([^,\s]+)//) {
+                $etag = $1;
+		$etag =~ s/([\"\\])/\\$1/g;
+	        push(@res, qq($weak"$etag"));
+            } elsif (s/^\s+// || !length) {
+                push(@res, qq(W/"")) if $weak;
+            } else {
+	 	die "This should not happen: '$_'";
+            }
+        }
+   }
+   @res;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers/Util.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers/Util.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Headers/Util.pm	(revision 16571)
@@ -0,0 +1,180 @@
+package HTTP::Headers::Util;
+
+use strict;
+use vars qw($VERSION @ISA @EXPORT_OK);
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+require Exporter;
+@ISA=qw(Exporter);
+
+@EXPORT_OK=qw(split_header_words join_header_words);
+
+=head1 NAME
+
+HTTP::Headers::Util - Header value parsing utility functions
+
+=head1 SYNOPSIS
+
+  use HTTP::Headers::Util qw(split_header_words);
+  @values = split_header_words($h->header("Content-Type"));
+
+=head1 DESCRIPTION
+
+This module provide a few functions that helps parsing and
+construction of valid HTTP header values.  None of the functions are
+exported by default.
+
+The following functions are provided:
+
+=over 4
+
+
+=item split_header_words( @header_values )
+
+This function will parse the header values given as argument into a
+list of anonymous arrays containing key/value pairs.  The function
+know how to deal with ",", ";" and "=" as well as quoted values after
+"=".  A list of space separated tokens are parsed as if they were
+separated by ";".
+
+If the @header_values passed as argument contains multiple values,
+then they are treated as if they were a single value separated by
+comma ",".
+
+This means that this function is useful to parse header fields that
+follow this syntax (BNF as from the HTTP/1.1 specification, but we relax
+the requirement for tokens).
+
+  headers           = #header
+  header            = (token | parameter) *( [";"] (token | parameter))
+
+  token             = 1*<any CHAR except CTLs or separators>
+  separators        = "(" | ")" | "<" | ">" | "@"
+                    | "," | ";" | ":" | "\" | <">
+                    | "/" | "[" | "]" | "?" | "="
+                    | "{" | "}" | SP | HT
+
+  quoted-string     = ( <"> *(qdtext | quoted-pair ) <"> )
+  qdtext            = <any TEXT except <">>
+  quoted-pair       = "\" CHAR
+
+  parameter         = attribute "=" value
+  attribute         = token
+  value             = token | quoted-string
+
+Each I<header> is represented by an anonymous array of key/value
+pairs.  If a token is recognized then the value will be C<undef>.
+Syntactically incorrect headers will not necessary be parsed as you
+would want.
+
+This is easier to describe with some examples:
+
+   split_header_words('foo="bar"; port="80,81"; discard, bar=baz')
+   split_header_words('text/html; charset="iso-8859-1");
+   split_header_words('Basic realm="\"foo\\bar\""');
+
+will return
+
+   [foo=>'bar', port=>'80,81', discard=> undef], [bar=>'baz' ]
+   ['text/html' => undef, charset => 'iso-8859-1']
+   [Basic => undef, realm => '"foo\bar"']
+
+=cut
+
+
+sub split_header_words
+{
+    my(@val) = @_;
+    my @res;
+    for (@val) {
+	my @cur;
+	while (length) {
+	    if (s/^\s*(=*[^\s=;,]+)//) {  # 'token' or parameter 'attribute'
+		push(@cur, $1);
+		# a quoted value
+		if (s/^\s*=\s*\"([^\"\\]*(?:\\.[^\"\\]*)*)\"//) {
+		    my $val = $1;
+		    $val =~ s/\\(.)/$1/g;
+		    push(@cur, $val);
+		# some unquoted value
+		} elsif (s/^\s*=\s*([^;,\s]*)//) {
+		    my $val = $1;
+		    $val =~ s/\s+$//;
+		    push(@cur, $val);
+		# no value, a lone token
+		} else {
+		    push(@cur, undef);
+		}
+	    } elsif (s/^\s*,//) {
+		push(@res, [@cur]) if @cur;
+		@cur = ();
+	    } elsif (s/^\s*;// || s/^\s+//) {
+		# continue
+	    } else {
+		die "This should not happen: '$_'";
+	    }
+	}
+	push(@res, \@cur) if @cur;
+    }
+    @res;
+}
+
+
+=item join_header_words( @arrays )
+
+This will do the opposite convertion of what split_header_words()
+does.  It takes a list of anonymous arrays as argument (or a list of
+key/value pairs) and produce a single header value.  Attribute values
+are quoted if needed.
+
+Example:
+
+   join_header_words(["text/plain" => undef, charset => "iso-8859/1"]);
+   join_header_words(""text/plain" => undef, charset => "iso-8859/1");
+
+will both return the string:
+
+   text/plain; charset="iso-8859/1"
+
+=cut
+
+sub join_header_words
+{
+    @_ = ([@_]) if @_ && !ref($_[0]);
+    my @res;
+    for (@_) {
+	my @cur = @$_;
+	my @attr;
+	while (@cur) {
+	    my $k = shift @cur;
+	    my $v = shift @cur;
+	    if (defined $v) {
+		if ($v =~ /^\w+$/) {
+		    $k .= "=$v";
+		} else {
+		    $v =~ s/([\"\\])/\\$1/g;  # escape " and \
+		    $k .= qq(="$v");
+		}
+	    }
+	    push(@attr, $k);
+	}
+	push(@res, join("; ", @attr)) if @attr;
+    }
+    join(", ", @res);
+}
+
+1;
+
+__END__
+
+=back
+
+=head1 COPYRIGHT
+
+Copyright 1997-1998, Gisle Aas
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Message.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Message.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Message.pm	(revision 16571)
@@ -0,0 +1,208 @@
+#
+# $Id$
+
+package HTTP::Message;
+
+=head1 NAME
+
+HTTP::Message - Class encapsulating HTTP messages
+
+=head1 SYNOPSIS
+
+ package HTTP::Request;  # or HTTP::Response
+ require HTTP::Message;
+ @ISA=qw(HTTP::Message);
+
+=head1 DESCRIPTION
+
+A C<HTTP::Message> object contains some headers and a content (body).
+The class is abstract, i.e. it only used as a base class for
+C<HTTP::Request> and C<HTTP::Response> and should never instantiated
+as itself.
+
+The following methods are available:
+
+=over 4
+
+=cut
+
+#####################################################################
+
+require HTTP::Headers;
+require Carp;
+use strict;
+use vars qw($VERSION $AUTOLOAD);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+=item $mess = new HTTP::Message;
+
+This is the object constructor.  It should only be called internally
+by this library.  External code should construct C<HTTP::Request> or
+C<HTTP::Response> objects.
+
+=cut
+
+sub new
+{
+    my($class, $header, $content) = @_;
+    if (defined $header) {
+	Carp::croak("Bad header argument") unless ref $header;
+	$header = $header->clone;
+    } else {
+	$header = HTTP::Headers->new;
+    }
+    $content = '' unless defined $content;
+    bless {
+	'_headers' => $header,
+	'_content' => $content,
+    }, $class;
+}
+
+
+=item $mess->clone()
+
+Returns a copy of the object.
+
+=cut
+
+sub clone
+{
+    my $self  = shift;
+    my $clone = HTTP::Message->new($self->{'_headers'}, $self->{'_content'});
+    $clone;
+}
+
+=item $mess->protocol([$proto])
+
+Sets the HTTP protocol used for the message.  The protocol() is a string
+like "HTTP/1.0" or "HTTP/1.1".
+
+=cut
+
+sub protocol { shift->_elem('_protocol',  @_); }
+
+=item $mess->content([$content])
+
+The content() method sets the content if an argument is given.  If no
+argument is given the content is not touched.  In either case the
+previous content is returned.
+
+=item $mess->add_content($data)
+
+The add_content() methods appends more data to the end of the previous
+content.
+
+=cut
+
+sub content   { shift->_elem('_content',  @_); }
+
+sub add_content
+{
+    my $self = shift;
+    if (ref($_[0])) {
+	$self->{'_content'} .= ${$_[0]};  # for backwards compatability
+    } else {
+	$self->{'_content'} .= $_[0];
+    }
+}
+
+=item $mess->content_ref
+
+The content_ref() method will return a reference to content string.
+It can be more efficient to access the content this way if the content
+is huge, and it can be used for direct manipulation of the content,
+for instance:
+
+  ${$res->content_ref} =~ s/\bfoo\b/bar/g;
+
+=cut
+
+sub content_ref
+{
+    my $self = shift;
+    \$self->{'_content'};
+}
+
+sub as_string
+{
+    "";  # To be overridden in subclasses
+}
+
+=item $mess->headers;
+
+Return the embedded HTTP::Headers object.
+
+=item $mess->headers_as_string([$endl])
+
+Call the HTTP::Headers->as_string() method for the headers in the
+message.
+
+=cut
+
+sub headers            { shift->{'_headers'};                }
+sub headers_as_string  { shift->{'_headers'}->as_string(@_); }
+
+=back
+
+All unknown C<HTTP::Message> methods are delegated to the
+C<HTTP::Headers> object that is part of every message.  This allows
+convenient access to these methods.  Refer to L<HTTP::Headers> for
+details of these methods:
+
+  $mess->header($field => $val);
+  $mess->scan(\&doit);
+  $mess->push_header($field => $val);
+  $mess->remove_header($field);
+
+  $mess->date;
+  $mess->expires;
+  $mess->if_modified_since;
+  $mess->if_unmodified_since;
+  $mess->last_modified;
+  $mess->content_type;
+  $mess->content_encoding;
+  $mess->content_length;
+  $mess->content_language
+  $mess->title;
+  $mess->user_agent;
+  $mess->server;
+  $mess->from;
+  $mess->referer;
+  $mess->www_authenticate;
+  $mess->authorization;
+  $mess->proxy_authorization;
+  $mess->authorization_basic;
+  $mess->proxy_authorization_basic;
+
+=cut
+
+
+# delegate all other method calls the the _headers object.
+sub AUTOLOAD
+{
+    my $self = shift;
+    my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2);
+    return if $method eq "DESTROY";
+    $self->{'_headers'}->$method(@_);
+}
+
+# Private method to access members in %$self
+sub _elem
+{
+    my $self = shift;
+    my $elem = shift;
+    my $old = $self->{$elem};
+    $self->{$elem} = $_[0] if @_;
+    return $old;
+}
+
+1;
+
+=head1 COPYRIGHT
+
+Copyright 1995-1997 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Negotiate.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Negotiate.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Negotiate.pm	(revision 16571)
@@ -0,0 +1,505 @@
+# $Id$
+#
+
+package HTTP::Negotiate;
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+sub Version { $VERSION; }
+
+require 5.002;
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT = qw(choose);
+
+require HTTP::Headers;
+
+$DEBUG = 0;
+
+sub choose ($;$)
+{
+    my($variants, $request) = @_;
+    my(%accept);
+
+    unless (defined $request) {
+	# Create a request object from the CGI envirionment variables
+	$request = new HTTP::Headers;
+	$request->header('Accept', $ENV{HTTP_ACCEPT})
+	  if $ENV{HTTP_ACCEPT};
+	$request->header('Accept-Charset', $ENV{HTTP_ACCEPT_CHARSET})
+	  if $ENV{HTTP_ACCEPT_CHARSET};
+	$request->header('Accept-Encoding', $ENV{HTTP_ACCEPT_ENCODING})
+	  if $ENV{HTTP_ACCEPT_ENCODING};
+	$request->header('Accept-Language', $ENV{HTTP_ACCEPT_LANGUAGE})
+	  if $ENV{HTTP_ACCEPT_LANGUAGE};
+    }
+
+    # Get all Accept values from the request.  Build a hash initialized
+    # like this:
+    #
+    #   %accept = ( type =>     { 'audio/*'     => { q => 0.2, mbx => 20000 },
+    #                             'audio/basic' => { q => 1 },
+    #                           },
+    #               language => { 'no'          => { q => 1 },
+    #                           }
+    #             );
+
+    $request->scan(sub {
+	my($key, $val) = @_;
+	return unless $key =~ s/^Accept-?//;
+	my $type = lc $key;
+	$type = "type" unless length $key;
+	$val =~ s/\s+//g;
+	my $name;
+	for $name (split(/,/, $val)) {
+	    my(%param, $param);
+	    if ($name =~ s/;(.*)//) {
+		for $param (split(/;/, $1)) {
+		    my ($pk, $pv) = split(/=/, $param, 2);
+		    $param{$pk} = $pv;
+		}
+	    }
+	    $name = lc $name;
+	    if (defined $param{'q'}) {
+		$param{'q'} = 1 if $param{'q'} > 1;
+		$param{'q'} = 0 if $param{'q'} < 0;
+	    } else {
+		$param{'q'} = 1;
+	    }
+
+	    $param{'q'} = 1 unless defined $param{'q'};
+	    $accept{$type}{$name} = \%param;
+	}
+    });
+
+    # Check if any of the variants specify a language.  We do this
+    # because it influence how we treat those without (they default to
+    # 0.5 instead of 1).
+    my $any_lang = 0;
+    for $var (@$variants) {
+	if ($var->[5]) {
+	    $any_lang = 1;
+	    last;
+	}
+    }
+
+    if ($DEBUG) {
+	print "Netgotiantion parameters in the request\n";
+	for $type (keys %accept) {
+	    print " $type:\n";
+	    for $name (keys %{$accept{$type}}) {
+		print "    $name\n";
+		for $pv (keys %{$accept{$type}{$name}}) {
+		    print "      $pv = $accept{$type}{$name}{$pv}\n";
+		}
+	    }
+	}
+    }
+
+    my @Q = ();  # This is where we collect the results of the
+		 # quality calcualtions
+
+    # Calculate quality for all the variant's that are available.
+    for (@$variants) {
+	my($id, $qs, $ct, $enc, $cs, $lang, $bs) = @$_;
+	$qs = 1 unless defined $qs;
+	$bs = 0 unless defined $bs;
+	if ($DEBUG) {
+	    print "\nEvaluating $id ($ct)\n";
+	    printf "  qs   = %.3f\n", $qs;
+	    print  "  enc  = $enc\n"  if $enc && !ref($enc);
+	    print  "  enc  = @$enc\n" if $enc && ref($enc);
+	    print  "  cs   = $cs\n"   if $cs;
+	    print  "  lang = $lang\n" if $lang;
+	    print  "  bs   = $bs\n"   if $bs;
+	}
+
+	# Calculate encoding quality
+	my $qe = 1;
+	# If the variant has no assignes Content-Encoding, or if no
+	# Accept-Encoding field is present, then the value assigned
+	# is "qe=1".  If *all* of the variant's content encoddings
+	# are listed in the Accept-Encoding field, then the value
+	# assigned is "qw=1".  If *any* of the variant's content
+	# encodings are not listed in the provided Accept-Encoding
+	# field, then the value assigned is "qe=0"
+	if (exists $accept{'encoding'} && $enc) {
+	    my @enc = ref($enc) ? @$enc : ($enc);
+	    for (@enc) {
+		print "Is encoding $_ accepted? " if $DEBUG;
+		unless(exists $accept{'encoding'}{$_}) {
+		    print "no\n" if $DEBUG;
+		    $qe = 0;
+		    last;
+		} else {
+		    print "yes\n" if $DEBUG;
+		}
+	    }
+	}
+
+	# Calculate charset quality
+	my $qc  = 1;
+	# If the variant's media-type has not charset parameter,
+	# or the variant's charset is US-ASCII, or if no Accept-Charset
+	# field is present, then the value assigned is "qc=1".  If the
+	# variantæs charset is listed in the Accept-Charset field,
+	# then the value assigned is "qc=1.  Otherwise, if the variant's
+	# charset is not listed in the provided Accept-Encoding field,
+	# then the value assigned is "qc=0".
+	if (exists $accept{'charset'} && $cs && $cs ne 'us-ascii' ) {
+	    $qc = 0 unless $accept{'charset'}{$cs};
+	}
+
+	# Calculate language quality
+	my $ql  = 1;
+	if ($lang && exists $accept{'language'}) {
+	    my @lang = ref($lang) ? @$lang : ($lang);
+	    # If any of the variant's content languages are listed
+	    # in the Accept-Language field, the the value assigned is
+	    # the maximus of the "q" paramet values for thos language
+	    # tags.
+	    my $q = undef;
+	    for (@lang) {
+		next unless exists $accept{'language'}{$_};
+		my $this_q = $accept{'language'}{$_}{'q'};
+		$q = $this_q unless defined $q;
+		$q = $this_q if $this_q > $q;
+	    }
+	    unless (defined $q) {
+		# If there was no exact match and at least one of
+		# the Accept-Language field values is a complete
+		# subtag prefix of the content language tag(s), then
+		# the "q" parameter value of the largest matching
+		# prefix is used.
+		my $selected = undef;
+		for $al (keys %{ $accept{'language'} }) {
+		    if (substr($lang, 0, length($al)) eq $al) {
+			$selected = $al unless defined $selected;
+			$selected = $al if length($al) > length($selected);
+		    }
+		}
+		$q = $accept{'language'}{$selected}{'q'} if $selected;
+
+		# If none of the variant's content language tags or
+		# tag prefixes are listed in the provided
+		# Accept-Language field, then the value assigned
+		# is "ql=0.001"
+		$q = 0.001 unless defined $q;
+	    }
+	    $ql = $q;
+	} else {
+	    $ql = 0.5 if $any_lang && exists $accept{'language'};
+	}
+
+	my $q   = 1;
+	my $mbx = undef;
+	# If no Accept field is given, then the value assigned is "q=1".
+	# If at least one listed media range matches the variant's media
+	# type, then the "q" parameter value assigned to the most specific
+	# of those matched is used (e.g. "text/html;version=3.0" is more
+	# specific than "text/html", which is more specific than "text/*",
+	# which in turn is more specific than "*/*"). If not media range
+	# in the provided Accept field matches the variant's media type,
+	# then the value assigned is "q=0".
+	if (exists $accept{'type'} && $ct) {
+	    # First we clean up our content-type
+	    $ct =~ s/\s+//g;
+	    my $params = "";
+	    $params = $1 if $ct =~ s/;(.*)//;
+	    my($type, $subtype) = split("/", $ct, 2);
+	    my %param = ();
+	    for $param (split(/;/, $params)) {
+		my($pk,$pv) = split(/=/, $param, 2);
+		$param{$pk} = $pv;
+	    }
+
+	    my $sel_q = undef;
+	    my $sel_mbx = undef;
+	    my $sel_specificness = 0;
+
+	    ACCEPT_TYPE:
+	    for $at (keys %{ $accept{'type'} }) {
+		print "Consider $at...\n" if $DEBUG;
+		my($at_type, $at_subtype) = split("/", $at, 2);
+		# Is it a match on the type
+		next if $at_type    ne '*' && $at_type    ne $type;
+		next if $at_subtype ne '*' && $at_subtype ne $subtype;
+		my $specificness = 0;
+		$specificness++ if $at_type ne '*';
+		$specificness++ if $at_subtype ne '*';
+		# Let's see if content-type parameters also match
+		while (($pk, $pv) = each %param) {
+		    print "Check if $pk = $pv is true\n" if $DEBUG;
+		    next unless exists $accept{'type'}{$at}{$pk};
+		    next ACCEPT_TYPE
+		      unless $accept{'type'}{$at}{$pk} eq $pv;
+		    print "yes it is!!\n" if $DEBUG;
+		    $specificness++;
+		}
+		print "Hurray, type match with specificness = $specificness\n"
+		  if $DEBUG;
+
+		if (!defined($sel_q) || $sel_specificness < $specificness) {
+		    $sel_q   = $accept{'type'}{$at}{'q'};
+		    $sel_mbx = $accept{'type'}{$at}{'mbx'};
+		    $sel_specificness = $specificness;
+		}
+	    }
+	    $q   = $sel_q || 0;
+	    $mbx = $sel_mbx;
+	}
+
+	my $Q;
+	if (!defined($mbx) || $mbx >= $bs) {
+	    $Q = $qs * $qe * $qc * $ql * $q;
+	} else {
+	    $Q = 0;
+	    print "Variant's size is too large ==> Q=0\n" if $DEBUG;
+	}
+
+	if ($DEBUG) {
+	    $mbx = "undef" unless defined $mbx;
+	    printf "Q=%.3f", $Q;
+	    print "  (q=$q, mbx=$mbx, qe=$qe, qc=$qc, ql=$ql, qs=$qs)\n";
+	}
+
+	push(@Q, [$id, $Q, $bs]);
+    }
+
+
+    @Q = sort { $b->[1] <=> $a->[1] || $a->[2] <=> $b->[2] } @Q;
+
+    return @Q if wantarray;
+    return undef unless @Q;
+    return undef if $Q[0][1] == 0;
+    $Q[0][0];
+}
+
+1;
+
+__END__
+
+
+=head1 NAME
+
+choose - choose a variant of a document to serve (HTTP content negotiation)
+
+=head1 SYNOPSIS
+
+ use HTTP::Negotiate;
+
+ #  ID       QS     Content-Type   Encoding Char-Set        Lang   Size
+ $variants =
+  [['var1',  1.000, 'text/html',   undef,   'iso-8859-1',   'en',   3000],
+   ['var2',  0.950, 'text/plain',  'gzip',  'us-ascii',     'no',    400],
+   ['var3',  0.3,   'image/gif',   undef,   undef,          undef, 43555],
+  ];
+
+ @prefered = choose($variants, $request_headers);
+ $the_one  = choose($variants);
+
+=head1 DESCRIPTION
+
+This module provide a complete implementation of the HTTP content
+negotiation algorithm specified in F<draft-ietf-http-v11-spec-00.ps>
+chapter 12.  Content negotiation allows for the selection of a
+preferred content representation based upon attributes of the
+negotiable variants and the value of the various Accept* header fields
+in the request.
+
+The variants are ordered by preference by calling the function
+choose().
+
+The first parameter is a description of the variants that we can
+choose among.  The variants are described by a reference to an array.
+Each element in this array is an array with the values [$id, $qs,
+$content_type, $content_encoding, $charset, $content_language,
+$content_length].  The meaning of these values are described
+below. The $content_encoding and $content_language can be either a
+single scalar value or an array reference if there are several values.
+
+The second optional parameter is a reference to the request headers.
+This is used to look for "Accept*" headers.  You can pass a reference
+to either a HTTP::Request or a HTTP::Headers object.  If this
+parameter is missing, then the accept specification is initialized
+from the CGI environment variables HTTP_ACCEPT, HTTP_ACCEPT_CHARSET,
+HTTP_ACCEPT_ENCODING and HTTP_ACCEPT_LANGUAGE.
+
+In array context, choose() returns a list of variant
+identifier/calculated quality pairs.  The values are sorted by
+quality, highest quality first.  If the calculated quality is the same
+for two variants, then they are sorted by size (smallest first). I<E.g.>:
+
+  (['var1' => 1], ['var2', 0.3], ['var3' => 0]);
+
+Note that also zero quality variants are included in the return list
+even if these should never be served to the client.
+
+In scalar context, it returns the identifier of the variant with the
+highest score or C<undef> if none have non-zero quality.
+
+If the $HTTP::Negotiate::DEBUG variable is set to TRUE, then a lot of
+noise is generated on STDOUT during evaluation of choose().
+
+=head1 VARIANTS
+
+A variant is described by a list of the following values.  If the
+attribute does not make sense or is unknown for a variant, then use
+C<undef> instead.
+
+=over 3
+
+=item identifier
+
+This is just some string that you use as a name for the variant.  The
+identifier of the preferred variant is returned by choose().
+
+=item qs
+
+This is a number between 0.000 and 1.000 that describes the "source
+quality".  This is what F<draft-ietf-http-v11-spec-00.ps> says about this
+value:
+
+Source quality is measured by the content provider as representing the
+amount of degradation from the original source.  For example, a
+picture in JPEG form would have a lower qs when translated to the XBM
+format, and much lower qs when translated to an ASCII-art
+representation.  Note, however, that this is a function of the source
+- an original piece of ASCII-art may degrade in quality if it is
+captured in JPEG form.  The qs values should be assigned to each
+variant by the content provider; if no qs value has been assigned, the
+default is generally "qs=1".
+
+=item content-type
+
+This is the media type of the variant.  The media type does not
+include a charset attribute, but might contain other parameters.
+Examples are:
+
+  text/html
+  text/html;version=2.0
+  text/plain
+  image/gif
+  image/jpg
+
+=item content-encoding
+
+This is one or more content encodings that has been applied to the
+variant.  The content encoding is generally used as a modifier to the
+content media type.  The most common content encodings are:
+
+  gzip
+  compress
+
+=item content-charset
+
+This is the character set used when the variant contains textual
+content.  The charset value should generally be C<undef> or one of these:
+
+  us-ascii
+  iso-8859-1 ... iso-8859-9
+  iso-2022-jp
+  iso-2022-jp-2
+  iso-2022-kr
+  unicode-1-1
+  unicode-1-1-utf-7
+  unicode-1-1-utf-8
+
+=item content-language
+
+This describes one or more languages that are used in the variant.
+Language is described like this in F<draft-ietf-http-v11-spec-00.ps>: A
+language is in this context a natural language spoken, written, or
+otherwise conveyed by human beings for communication of information to
+other human beings.  Computer languages are explicitly excluded.
+
+The language tags are the same as those defined by RFC-1766.  Examples
+are:
+
+  no               Norwegian
+  en               International English
+  en-US            US English
+  en-cockney
+
+=item content-length
+
+This is the number of bytes used to represent the content.
+
+=back
+
+=head1 ACCEPT HEADERS
+
+The following Accept* headers can be used for describing content
+preferences in a request (This description is an edited extract from
+F<draft-ietf-http-v11-spec-00.ps>):
+
+=over 3
+
+=item Accept
+
+This header can be used to indicate a list of media ranges which are
+acceptable as a reponse to the request.  The "*" character is used to
+group media types into ranges, with "*/*" indicating all media types
+and "type/*" indicating all subtypes of that type.
+
+The parameter q is used to indicate the quality factor, which
+represents the user's preference for that range of media types.  The
+parameter mbx gives the maximum acceptable size of the response
+content. The default values are: q=1 and mbx=infinity. If no Accept
+header is present, then the client accepts all media types with q=1.
+
+For example:
+
+  Accept: audio/*;q=0.2;mbx=200000, audio/basic
+
+would mean: "I prefer audio/basic (of any size), but send me any audio
+type if it is the best available after an 80% mark-down in quality and
+its size is less than 200000 bytes"
+
+
+=item Accept-Charset
+
+Used to indicate what character sets are acceptable for the response.
+The "us-ascii" character set is assumed to be acceptable for all user
+agents.  If no Accept-Charset field is given, the default is that any
+charset is acceptable.  Example:
+
+  Accept-Charset: iso-8859-1, unicode-1-1
+
+
+=item Accept-Encoding
+
+Restricts the Content-Encoding values which are acceptable in the
+response.  If no Accept-Encoding field is present, the server may
+assume that the client will accept any content encoding.  An empty
+Accept-Encoding means that no content encoding is acceptable.  Example:
+
+  Accept-Encoding: compress, gzip
+
+
+=item Accept-Language
+
+This field is similar to Accept, but restrict the set of natural
+languages that are preferred as a response.  Each language may be
+given an associated quality value which represents an estimate of the
+user's comprehension of that language.  For example:
+
+  Accept-Language: no, en-gb;q=0.8, de;q=0.55
+
+would mean: "I prefer Norwegian, but will accept British English (with
+80% comprehension) or German (with 55% comprehension).
+
+=back
+
+
+=head1 COPYRIGHT
+
+Copyright 1996, Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=head1 AUTHOR
+
+Gisle Aas <aas@sn.no>
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Request.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Request.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Request.pm	(revision 16571)
@@ -0,0 +1,160 @@
+#
+# $Id$
+
+package HTTP::Request;
+
+=head1 NAME
+
+HTTP::Request - Class encapsulating HTTP Requests
+
+=head1 SYNOPSIS
+
+ require HTTP::Request;
+ $request = HTTP::Request->new(GET => 'http://www.oslonett.no/');
+
+=head1 DESCRIPTION
+
+C<HTTP::Request> is a class encapsulating HTTP style requests,
+consisting of a request line, some headers, and some (potentially empty)
+content. Note that the LWP library also uses this HTTP style requests
+for non-HTTP protocols.
+
+Instances of this class are usually passed to the C<request()> method
+of an C<LWP::UserAgent> object:
+
+ $ua = LWP::UserAgent->new;
+ $request = HTTP::Request->new(GET => 'http://www.oslonett.no/');
+ $response = $ua->request($request);
+
+C<HTTP::Request> is a subclass of C<HTTP::Message> and therefore
+inherits its methods.  The inherited methods often used are header(),
+push_header(), remove_header(), headers_as_string() and content().
+See L<HTTP::Message> for details.
+
+The following additional methods are available:
+
+=over 4
+
+=cut
+
+require HTTP::Message;
+@ISA = qw(HTTP::Message);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+use URI::URL ();
+use strict;
+
+=item $r = HTTP::Request->new($method, $url, [$header, [$content]])
+
+Constructs a new C<HTTP::Request> object describing a request on the
+object C<$url> using method C<$method>.  The C<$url> argument can be
+either a string, or a reference to a C<URI::URL> object.  The $header
+argument should be a reference to an C<HTTP::Headers> object.
+
+=cut
+
+sub new
+{
+    my($class, $method, $url, $header, $content) = @_;
+    my $self = $class->SUPER::new($header, $content);
+    $self->method($method);
+    $self->url($url);
+    $self;
+}
+
+
+sub clone
+{
+    my $self = shift;
+    my $clone = bless $self->SUPER::clone, ref($self);
+    $clone->method($self->method);
+    $clone->url($self->url);
+    $clone;
+}
+
+
+=item $r->method([$val])
+
+=item $r->url([$val])
+
+These methods provide public access to the member variables containing
+respectively the method of the request and the URL object of the
+request.
+
+If an argument is given the member variable is given that as its new
+value. If no argument is given the value is not touched. In either
+case the previous value is returned.
+
+The url() method accept both a reference to a URI::URL object and a
+string as its argument.  If a string is given, then it should be
+parseable as an absolute URL.
+
+=cut
+
+sub method  { shift->_elem('_method', @_); }
+
+sub url
+{
+    my $self = shift;
+    my $old = $self->{'_url'};
+    if (@_) {
+	my $url = shift;
+	if (!defined $url) {
+	    # that's ok
+	} elsif (ref $url) {
+	    $url = $url->abs;
+	} else {
+	    $url = eval { URI::URL->new($url) };
+	}
+	$self->{'_url'} = $url;
+    }
+    $old;
+}
+
+*uri = \&url;  # this is the same for now
+
+=item $r->as_string()
+
+Method returning a textual representation of the request.
+Mainly useful for debugging purposes. It takes no arguments.
+
+=cut
+
+sub as_string
+{
+    my $self = shift;
+    my @result;
+    #push(@result, "---- $self -----");
+    my $req_line = $self->method || "[NO METHOD]";
+    my $url = $self->url;
+    $url = (defined $url) ? $url->as_string : "[NO URL]";
+    $req_line .= " $url";
+    my $proto = $self->protocol;
+    $req_line .= " $proto" if $proto;
+
+    push(@result, $req_line);
+    push(@result, $self->headers_as_string);
+    my $content = $self->content;
+    if (defined $content) {
+	push(@result, $content);
+    }
+    #push(@result, ("-" x 40));
+    join("\n", @result, "");
+}
+
+1;
+
+=back
+
+=head1 SEE ALSO
+
+L<HTTP::Headers>, L<HTTP::Message>, L<HTTP::Request::Common>
+
+=head1 COPYRIGHT
+
+Copyright 1995-1998 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Request/Common.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Request/Common.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Request/Common.pm	(revision 16571)
@@ -0,0 +1,389 @@
+# $Id$
+#
+package HTTP::Request::Common;
+
+use strict;
+use vars qw(@EXPORT @EXPORT_OK $VERSION $DYNAMIC_FILE_UPLOAD);
+
+$DYNAMIC_FILE_UPLOAD ||= 0;  # make it defined (don't know why)
+
+require Exporter;
+*import = \&Exporter::import;
+@EXPORT =qw(GET HEAD PUT POST);
+@EXPORT_OK = qw($DYNAMIC_FILE_UPLOAD);
+
+require HTTP::Request;
+use Carp();
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+my $CRLF = "\015\012";   # "\r\n" is not portable
+
+sub GET  { _simple_req('GET',  @_); }
+sub HEAD { _simple_req('HEAD', @_); }
+sub PUT  { _simple_req('PUT' , @_); }
+
+sub POST
+{
+    my $url = shift;
+    my $req = HTTP::Request->new(POST => $url);
+    my $content;
+    $content = shift if @_ and ref $_[0];
+    my($k, $v);
+    while (($k,$v) = splice(@_, 0, 2)) {
+	if (lc($k) eq 'content') {
+	    $content = $v;
+	} else {
+	    $req->push_header($k, $v);
+	}
+    }
+    my $ct = $req->header('Content-Type');
+    unless ($ct) {
+	$ct = 'application/x-www-form-urlencoded';
+    } elsif ($ct eq 'form-data') {
+	$ct = 'multipart/form-data';
+    }
+
+    if (ref $content) {
+	if (lc($ct) eq 'multipart/form-data') {    #XXX: boundary="..."
+	    my $boundary;
+	    ($content, $boundary) = form_data($content, $boundary);
+	    $boundary = qq("$boundary") if $boundary =~ /\W/;
+	    $ct = qq(multipart/form-data; boundary=$boundary);
+	} else {
+	    # We use a temporary URI::URL object to format
+	    # the application/x-www-form-urlencoded content.
+	    require URI::URL;
+	    my $url = URI::URL->new('http:');
+	    $url->query_form(ref($content) eq "HASH" ? %$content : @$content);
+	    $content = $url->equery;
+	}
+    }
+
+    $req->header('Content-Type' => $ct);  # might be redundant
+    if (defined($content)) {
+	$req->header('Content-Length' =>
+		     length($content)) unless ref($content);
+	$req->content($content);
+    }
+    $req;
+}
+
+
+sub _simple_req
+{
+    my($method, $url) = splice(@_, 0, 2);
+    my $req = HTTP::Request->new($method => $url);
+    my($k, $v);
+    while (($k,$v) = splice(@_, 0, 2)) {
+	if (lc($k) eq 'content') {
+	    $req->add_content($v);
+	} else {
+	    $req->push_header($k, $v);
+	}
+    }
+    $req;
+}
+
+
+sub form_data   # RFC1867
+{
+    my($data, $boundary) = @_;
+    my @data = ref($data) eq "HASH" ? %$data : @$data;  # copy
+    my $fhparts;
+    my @parts;
+    my($k,$v);
+    while (($k,$v) = splice(@data, 0, 2)) {
+	if (!ref($v)) {
+	    $k =~ s/([\\\"])/\\$1/g;  # escape quotes and backslashes
+	    push(@parts,
+		 qq(Content-Disposition: form-data; name="$k"$CRLF$CRLF$v));
+	} else {
+	    my($file, $usename, @headers) = @$v;
+	    unless (defined $usename) {
+		$usename = $file;
+		$usename =~ s,.*/,, if defined($usename);
+	    }
+	    my $disp = qq(form-data; name="$k");
+	    $disp .= qq(; filename="$usename") if $usename;
+	    my $content = "";
+	    my $h = HTTP::Headers->new(@headers);
+	    my $ct = $h->header("Content-Type");
+	    if ($file) {
+		require Symbol;
+		my $fh = Symbol::gensym();
+		open($fh, $file) or Carp::croak("Can't open file $file: $!");
+		binmode($fh);
+		if ($DYNAMIC_FILE_UPLOAD) {
+		    # will read file later
+		    $content = $fh;
+		} else {
+		    local($/) = undef; # slurp files
+		    $content = <$fh>;
+		    close($fh);
+		    $h->header("Content-Length" => length($content));
+		}
+		unless ($ct) {
+		    require LWP::MediaTypes;
+		    $ct = LWP::MediaTypes::guess_media_type($file, $h);
+		}
+	    }
+	    if ($h->header("Content-Disposition")) {
+		# just to get it sorted first
+		$disp = $h->header("Content-Disposition");
+		$h->remove_header("Content-Disposition");
+	    }
+	    if ($h->header("Content")) {
+		$content = $h->header("Content");
+		$h->remove_header("Content");
+	    }
+	    my $head = join($CRLF, "Content-Disposition: $disp",
+			           $h->as_string($CRLF),
+			           "");
+	    if (ref $content) {
+		push(@parts, [$head, $content]);
+		$fhparts++;
+	    } else {
+		push(@parts, $head . $content);
+	    }
+	}
+    }
+    return "" unless @parts;
+
+    my $content;
+    if ($fhparts) {
+	$boundary = boundary(10) # hopefully enough randomness
+	    unless $boundary;
+
+	# add the boundaries to the @parts array
+	for (1..@parts-1) {
+	    splice(@parts, $_*2-1, 0, "$CRLF--$boundary$CRLF");
+	}
+	unshift(@parts, "--$boundary$CRLF");
+	push(@parts, "$CRLF--$boundary--$CRLF");
+
+	# set up a closure that will return content piecemeal
+	$content = sub {
+	    for (;;) {
+		return unless @parts;
+		my $p = shift @parts;
+		unless (ref $p) {
+		    $p .= shift @parts while @parts && !ref($parts[0]);
+		    return $p;
+		}
+		my($buf, $fh) = @$p;
+		my $n = read($fh, $buf, 2048, length($buf));
+		if ($n) {
+		    unshift(@parts, ["", $fh]);
+		} else {
+		    close($fh);
+		}
+		return $buf if length $buf;
+	    }
+	};
+
+    } else {
+	$boundary = boundary() unless $boundary;
+
+	my $bno = 0;
+      CHECK_BOUNDARY:
+	{
+	    for (@parts) {
+		if (index($_, "--$boundary") >= 0) {
+		    # must have a better boundary
+		    #warn "Need something better that '$boundary' as boundary\n";
+		    $boundary = boundary(++$bno);
+		    redo CHECK_BOUNDARY;
+		}
+	    }
+	    last;
+	}
+	$content = "--$boundary$CRLF" .
+	           join("$CRLF--$boundary$CRLF", @parts) .
+		   "$CRLF--$boundary--$CRLF";
+    }
+
+    wantarray ? ($content, $boundary) : $content;
+}
+
+
+sub boundary
+{
+    my $size = shift || return "000";
+    require MIME::Base64;
+    my $b = MIME::Base64::encode(join("", map chr(rand(256)), 1..$size*3), "");
+    $b =~ s/[\W]/X/g;  # ensure alnum only
+    $b;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+HTTP::Request::Common - Construct common HTTP::Request objects
+
+=head1 SYNOPSIS
+
+  use HTTP::Request::Common;
+  $ua = LWP::UserAgent->new;
+  $ua->request(GET 'http://www.sn.no/');
+  $ua->request(POST 'http://somewhere/foo', [foo => bar, bar => foo]);
+
+=head1 DESCRIPTION
+
+This module provide functions that return newly created HTTP::Request
+objects.  These functions are usually more convenient to use than the
+standard HTTP::Request constructor for these common requests.  The
+following functions are provided.
+
+=over 4
+
+=item GET $url, Header => Value,...
+
+The GET() function returns a HTTP::Request object initialized with the
+GET method and the specified URL.  Without additional arguments it
+is exactly equivalent to the following call
+
+  HTTP::Request->new(GET => $url)
+
+but is less clutter.  It also reads better when used together with the
+LWP::UserAgent->request() method:
+
+  my $ua = new LWP::UserAgent;
+  my $res = $ua->request(GET 'http://www.sn.no')
+  if ($res->is_success) { ...
+
+You can also initialize the header values in the request by specifying
+some key/value pairs as optional arguments.  For instance:
+
+  $ua->request(GET 'http://www.sn.no',
+	           If_Match => 'foo',
+                   From     => 'gisle@aas.no',
+              );
+
+A header key called 'Content' is special and when seen the value will
+initialize the content part of the request instead of setting a header.
+
+=item HEAD $url, [Header => Value,...]
+
+Like GET() but the method in the request is HEAD.
+
+=item PUT $url, [Header => Value,...]
+
+Like GET() but the method in the request is PUT.
+
+=item POST $url, [$form_ref], [Header => Value,...]
+
+This works mostly like GET() with POST as method, but this function
+also takes a second optional array or hash reference parameter
+($form_ref).  This argument can be used to pass key/value pairs for
+the form content.  By default we will initialize a request using the
+C<application/x-www-form-urlencoded> content type.  This means that
+you can emulate a HTML E<lt>form> POSTing like this:
+
+  POST 'http://www.perl.org/survey.cgi',
+       [ name   => 'Gisle Aas',
+         email  => 'gisle@aas.no',
+         gender => 'M',
+         born   => '1964',
+         perc   => '3%',
+       ];
+
+This will create a HTTP::Request object that looks like this:
+
+  POST http://www.perl.org/survey.cgi
+  Content-Length: 66
+  Content-Type: application/x-www-form-urlencoded
+
+  name=Gisle%20Aas&email=gisle%40aas.no&gender=M&born=1964&perc=3%25
+
+The POST method also supports the C<multipart/form-data> content used
+for I<Form-based File Upload> as specified in RFC 1867.  You trigger
+this content format by specifying a content type of C<'form-data'> as
+one of the request headers.  If one of the values in the $form_ref is
+an array reference, then it is treated as a file part specification
+with the following interpretation:
+
+  [ $file, $filename, Header => Value... ]
+
+The first value in the array ($file) is the name of a file to open.
+This file will be read an its content placed in the request.  The
+routine will croak if the file can't be opened.  Use an C<undef> as $file
+value if you want to specify the content directly.  The $filename is
+the filename to report in the request.  If this value is undefined,
+then the basename of the $file will be used.  You can specify an empty
+string as $filename if you don't want any filename in the request.
+
+Sending my F<~/.profile> to the survey used as example above can be
+achieved by this:
+
+  POST 'http://www.perl.org/survey.cgi',
+       Content_Type => 'form-data',
+       Content      => [ name  => 'Gisle Aas',
+                         email => 'gisle@aas.no',
+                         gender => 'M',
+                         born   => '1964',
+                         init   => ["$ENV{HOME}/.profile"],
+                       ]
+
+This will create a HTTP::Request object that almost looks this (the
+boundary and the content of your F<~/.profile> is likely to be
+different):
+
+  POST http://www.perl.org/survey.cgi
+  Content-Length: 388
+  Content-Type: multipart/form-data; boundary="6G+f"
+
+  --6G+f
+  Content-Disposition: form-data; name="name"
+  
+  Gisle Aas
+  --6G+f
+  Content-Disposition: form-data; name="email"
+  
+  gisle@aas.no
+  --6G+f
+  Content-Disposition: form-data; name="gender"
+  
+  M
+  --6G+f
+  Content-Disposition: form-data; name="born"
+  
+  1964
+  --6G+f
+  Content-Disposition: form-data; name="init"; filename=".profile"
+  Content-Type: text/plain
+  
+  PATH=/local/perl/bin:$PATH
+  export PATH
+
+  --6G+f--
+
+If you set the $DYNAMIC_FILE_UPLOAD variable (exportable) to some TRUE
+value, then you get back a request object with a subroutine closure as
+the content attribute.  This subroutine will read the content of any
+files on demand and return it in suitable chunks.  This allow you to
+upload arbitrary big files without using lots of memory.  You can even
+upload infinite files like F</dev/audio> if you wish.  Another
+difference is that there will be no Content-Length header defined for
+the request if you use this feature.  Not all servers (or server
+applications) like this.
+
+=back
+
+=head1 SEE ALSO
+
+L<HTTP::Request>, L<LWP::UserAgent>
+
+
+=head1 COPYRIGHT
+
+Copyright 1997-1998, Gisle Aas
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Response.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Response.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Response.pm	(revision 16571)
@@ -0,0 +1,396 @@
+#
+# $Id$
+
+package HTTP::Response;
+
+
+=head1 NAME
+
+HTTP::Response - Class encapsulating HTTP Responses
+
+=head1 SYNOPSIS
+
+ require HTTP::Response;
+
+=head1 DESCRIPTION
+
+The C<HTTP::Response> class encapsulate HTTP style responses.  A
+response consist of a response line, some headers, and a (potential
+empty) content. Note that the LWP library will use HTTP style
+responses also for non-HTTP protocol schemes.
+
+Instances of this class are usually created and returned by the
+C<request()> method of an C<LWP::UserAgent> object:
+
+ #...
+ $response = $ua->request($request)
+ if ($response->is_success) {
+     print $response->content;
+ } else {
+     print $response->error_as_HTML;
+ }
+
+C<HTTP::Response> is a subclass of C<HTTP::Message> and therefore
+inherits its methods.  The inherited methods often used are header(),
+push_header(), remove_header(), headers_as_string(), and content().
+The header convenience methods are also available.  See
+L<HTTP::Message> for details.
+
+The following additional methods are available:
+
+=over 4
+
+=cut
+
+
+require HTTP::Message;
+@ISA = qw(HTTP::Message);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+use HTTP::Status ();
+use URI::URL ();
+use strict;
+
+
+=item $r = HTTP::Response->new($rc, [$msg, [$header, [$content]]])
+
+Constructs a new C<HTTP::Response> object describing a response with
+response code C<$rc> and optional message C<$msg>.  The message is a
+short human readable single line string that explains the response
+code.
+
+=cut
+
+sub new
+{
+    my($class, $rc, $msg, $header, $content) = @_;
+    my $self = $class->SUPER::new($header, $content);
+    $self->code($rc);
+    $self->message($msg);
+    $self;
+}
+
+
+sub clone
+{
+    my $self = shift;
+    my $clone = bless $self->SUPER::clone, ref($self);
+    $clone->code($self->code);
+    $clone->message($self->message);
+    $clone->request($self->request->clone) if $self->request;
+    # we don't clone previous
+    $clone;
+}
+
+=item $r->code([$code])
+
+=item $r->message([$message])
+
+=item $r->request([$request])
+
+=item $r->previous([$previousResponse])
+
+These methods provide public access to the member variables.  The
+first two containing respectively the response code and the message
+of the response.
+
+The request attribute is a reference the request that gave this
+response.  It does not have to be the same request as passed to the
+$ua->request() method, because there might have been redirects and
+authorization retries in between.
+
+The previous attribute is used to link together chains of responses.
+You get chains of responses if the first response is redirect or
+unauthorized.
+
+=cut
+
+sub code      { shift->_elem('_rc',      @_); }
+sub message   { shift->_elem('_msg',     @_); }
+sub previous  { shift->_elem('_previous',@_); }
+sub request   { shift->_elem('_request', @_); }
+
+=item $r->status_line
+
+Returns the string "E<lt>code> E<lt>message>".  If the message attribute
+is not set then the official name of E<lt>code> (see L<HTTP::Status>)
+is substituted.
+
+=cut
+
+sub status_line
+{
+    my $self = shift;
+    my $code = $self->{'_rc'}  || "000";
+    my $mess = $self->{'_msg'} || HTTP::Status::status_message($code) || "?";
+    return "$code $mess";
+}
+
+=item $r->base
+
+Returns the base URL for this response.  The return value will be a
+reference to a URI::URL object.
+
+The base URL is obtained from one the following sources (in priority
+order):
+
+=over 4
+
+=item 1.
+
+Embedded in the document content, for instance <BASE HREF="...">
+in HTML documents.
+
+=item 2.
+
+A "Content-Base:" or a "Content-Location:" header in the response.
+
+For backwards compatability with older HTTP implementations we will
+also look for the "Base:" header.
+
+
+=item 3.
+
+The URL used to request this response. This might not be the original
+URL that was passed to $ua->request() method, because we might have
+received some redirect responses first.
+
+=back
+
+When the LWP protocol modules produce the HTTP::Response object, then
+any base URL embedded in the document (step 1) will already have
+initialized the "Content-Base:" header. This means that this method
+only perform the last 2 steps (the content is not always available
+either).
+
+=cut
+
+sub base
+{
+    my $self = shift;
+    my $base = $self->header('Content-Base')     ||  # HTTP/1.1
+               $self->header('Content-Location') ||  # HTTP/1.1
+               $self->header('Base')             ||  # backwards compatability HTTP/1.0
+               $self->request->url;
+    $base = URI::URL->new($base) unless ref $base;
+    $base;
+}
+
+
+=item $r->as_string
+
+Method returning a textual representation of the response.  Mainly
+useful for debugging purposes. It takes no arguments.
+
+=cut
+
+sub as_string
+{
+    require HTTP::Status;
+    my $self = shift;
+    my @result;
+    #push(@result, "---- $self ----");
+    my $code = $self->code;
+    my $status_message = HTTP::Status::status_message($code) || "Unknown code";
+    my $message = $self->message || "";
+
+    my $status_line = "$code";
+    my $proto = $self->protocol;
+    $status_line = "$proto $status_line" if $proto;
+    $status_line .= " ($status_message)" if $status_message ne $message;
+    $status_line .= " $message";
+    push(@result, $status_line);
+    push(@result, $self->headers_as_string);
+    my $content = $self->content;
+    if (defined $content) {
+	push(@result, $content);
+    }
+    #push(@result, ("-" x 40));
+    join("\n", @result, "");
+}
+
+=item $r->is_info
+
+=item $r->is_success
+
+=item $r->is_redirect
+
+=item $r->is_error
+
+These methods indicate if the response was informational, sucessful, a
+redirection, or an error.
+
+=cut
+
+sub is_info     { HTTP::Status::is_info     (shift->{'_rc'}); }
+sub is_success  { HTTP::Status::is_success  (shift->{'_rc'}); }
+sub is_redirect { HTTP::Status::is_redirect (shift->{'_rc'}); }
+sub is_error    { HTTP::Status::is_error    (shift->{'_rc'}); }
+
+
+=item $r->error_as_HTML()
+
+Return a string containing a complete HTML document indicating what
+error occurred.  This method should only be called when $r->is_error
+is TRUE.
+
+=cut
+
+sub error_as_HTML
+{
+    my $self = shift;
+    my $title = 'An Error Occurred';
+    my $body  = $self->status_line;
+    return <<EOM;
+<HTML>
+<HEAD><TITLE>$title</TITLE></HEAD>
+<BODY>
+<H1>$title</h1>
+$body
+</BODY>
+</HTML>
+EOM
+}
+
+
+=item $r->current_age
+
+This function will calculate the "current age" of the response as
+specified by E<lt>draft-ietf-http-v11-spec-07> section 13.2.3.  The
+age of a response is the time since it was sent by the origin server.
+The returned value is a number representing the age in seconds.
+
+=cut
+
+sub current_age
+{
+    my $self = shift;
+    # Implementation of <draft-ietf-http-v11-spec-07> section 13.2.3
+    # (age calculations)
+    my $response_time = $self->client_date;
+    my $date = $self->date;
+
+    my $age = 0;
+    if ($response_time && $date) {
+	$age = $response_time - $date;  # apparent_age
+	$age = 0 if $age < 0;
+    }
+
+    my $age_v = $self->header('Age');
+    if ($age_v && $age_v > $age) {
+	$age = $age_v;   # corrected_received_age
+    }
+
+    my $request = $self->request;
+    if ($request) {
+	my $request_time = $request->date;
+	if ($request_time) {
+	    # Add response_delay to age to get 'corrected_initial_age'
+	    $age += $response_time - $request_time;
+	}
+    }
+    if ($response_time) {
+	$age += time - $response_time;
+    }
+    return $age;
+}
+
+
+=item $r->freshness_lifetime
+
+This function will calculate the "freshness lifetime" of the response
+as specified by E<lt>draft-ietf-http-v11-spec-07> section 13.2.4.  The
+"freshness lifetime" is the length of time between the generation of a
+response and its expiration time.  The returned value is a number
+representing the freshness lifetime in seconds.
+
+If the response does not contain an "Expires" or a "Cache-Control"
+header, then this function will apply some simple heuristic based on
+'Last-Modified' to determine a suitable lifetime.
+
+=cut
+
+sub freshness_lifetime
+{
+    my $self = shift;
+
+    # First look for the Cache-Control: max-age=n header
+    my @cc = $self->header('Cache-Control');
+    if (@cc) {
+	my $cc;
+	for $cc (@cc) {
+	    my $cc_dir;
+	    for $cc_dir (split(/\s*,\s*/, $cc)) {
+		if ($cc_dir =~ /max-age\s*=\s*(\d+)/i) {
+		    return $1;
+		}
+	    }
+	}
+    }
+
+    # Next possibility is to look at the "Expires" header
+    my $date = $self->date || $self->client_date || time;      
+    my $expires = $self->expires;
+    unless ($expires) {
+	# Must apply heuristic expiration
+	my $last_modified = $self->last_modified;
+	if ($last_modified) {
+	    my $h_exp = ($date - $last_modified) * 0.10;  # 10% since last-mod
+	    if ($h_exp < 60) {
+		return 60;  # minimum
+	    } elsif ($h_exp > 24 * 3600) {
+		# Should give a warning if more than 24 hours according to
+		# <draft-ietf-http-v11-spec-07> section 13.2.4, but I don't
+		# know how to do it from this function interface, so I just
+		# make this the maximum value.
+		return 24 * 3600;
+	    }
+	    return $h_exp;
+	} else {
+	    return 3600;  # 1 hour is fallback when all else fails
+	}
+    }
+    return $expires - $date;
+}
+
+
+=item $r->is_fresh
+
+Returns TRUE if the response is fresh, based on the values of
+freshness_lifetime() and current_age().  If the response is not longer
+fresh, then it has to be refetched or revalidated by the origin
+server.
+
+=cut
+
+sub is_fresh
+{
+    my $self = shift;
+    $self->freshness_lifetime > $self->current_age;
+}
+
+
+=item $r->fresh_until
+
+Returns the time when this entiy is no longer fresh.
+
+=cut
+
+sub fresh_until
+{
+    my $self = shift;
+    return $self->freshness_lifetime - $self->current_age + time;
+}
+
+1;
+
+=back 
+
+=head1 COPYRIGHT
+
+Copyright 1995-1997 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Status.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Status.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/HTTP/Status.pm	(revision 16571)
@@ -0,0 +1,233 @@
+#
+# $Id$
+
+package HTTP::Status;
+
+use strict;
+require 5.002;   # becase we use prototypes
+
+=head1 NAME
+
+HTTP::Status - HTTP Status code processing
+
+=head1 SYNOPSIS
+
+ use HTTP::Status;
+
+ if ($rc != RC_OK) {
+     print status_message($rc), "\n";
+ }
+
+ if (is_success($rc)) { ... }
+ if (is_error($rc)) { ... }
+ if (is_redirect($rc)) { ... }
+
+=head1 DESCRIPTION
+
+I<HTTP::Status> is a library of routines for defining and
+classification of HTTP status codes for libwww-perl.  Status codes are
+used to encode the overall outcome of a HTTP response message.  Codes
+correspond to those defined in F<draft-ietf-http-v11-spec-rev-03> (an
+update to RFC 2068).
+
+=head1 CONSTANTS
+
+The following constant functions can be used as mnemonic status code
+names:
+
+   RC_CONTINUE				(100)
+   RC_SWITCHING_PROTOCOLS		(101)
+
+   RC_OK				(200)
+   RC_CREATED				(201)
+   RC_ACCEPTED				(202)
+   RC_NON_AUTHORITATIVE_INFORMATION	(203)
+   RC_NO_CONTENT			(204)
+   RC_RESET_CONTENT			(205)
+   RC_PARTIAL_CONTENT			(206)
+
+   RC_MULTIPLE_CHOICES			(300)
+   RC_MOVED_PERMANENTLY			(301)
+   RC_FOUND				(302)
+   RC_SEE_OTHER				(303)
+   RC_NOT_MODIFIED			(304)
+   RC_USE_PROXY				(305)
+   RC_TEMPORARY_REDIRECT		(307)
+
+   RC_BAD_REQUEST			(400)
+   RC_UNAUTHORIZED			(401)
+   RC_PAYMENT_REQUIRED			(402)
+   RC_FORBIDDEN				(403)
+   RC_NOT_FOUND				(404)
+   RC_METHOD_NOT_ALLOWED		(405)
+   RC_NOT_ACCEPTABLE			(406)
+   RC_PROXY_AUTHENTICATION_REQUIRED	(407)
+   RC_REQUEST_TIMEOUT			(408)
+   RC_CONFLICT				(409)
+   RC_GONE				(410)
+   RC_LENGTH_REQUIRED			(411)
+   RC_PRECONDITION_FAILED		(412)
+   RC_REQUEST_ENTITY_TOO_LARGE		(413)
+   RC_REQUEST_URI_TOO_LARGE		(414)
+   RC_UNSUPPORTED_MEDIA_TYPE		(415)
+   RC_REQUEST_RANGE_NOT_SATISFIABLE     (416)
+   RC_EXPECTATION_FAILED		(417)
+
+   RC_INTERNAL_SERVER_ERROR		(500)
+   RC_NOT_IMPLEMENTED			(501)
+   RC_BAD_GATEWAY			(502)
+   RC_SERVICE_UNAVAILABLE		(503)
+   RC_GATEWAY_TIMEOUT			(504)
+   RC_HTTP_VERSION_NOT_SUPPORTED	(505)
+
+=cut
+
+#####################################################################
+
+use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT = qw(is_info is_success is_redirect is_error status_message);
+@EXPORT_OK = qw(is_client_error is_server_error);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+# Note also addition of mnemonics to @EXPORT below
+
+my %StatusCode = (
+    100 => 'Continue',
+    101 => 'Switching Protocols',
+    200 => 'OK',
+    201 => 'Created',
+    202 => 'Accepted',
+    203 => 'Non-Authoritative Information',
+    204 => 'No Content',
+    205 => 'Reset Content',
+    206 => 'Partial Content',
+    300 => 'Multiple Choices',
+    301 => 'Moved Permanently',
+    302 => 'Found',
+    303 => 'See Other',
+    304 => 'Not Modified',
+    305 => 'Use Proxy',
+    307 => 'Temporary Redirect',
+    400 => 'Bad Request',
+    401 => 'Unauthorized',
+    402 => 'Payment Required',
+    403 => 'Forbidden',
+    404 => 'Not Found',
+    405 => 'Method Not Allowed',
+    406 => 'Not Acceptable',
+    407 => 'Proxy Authentication Required',
+    408 => 'Request Timeout',
+    409 => 'Conflict',
+    410 => 'Gone',
+    411 => 'Length Required',
+    412 => 'Precondition Failed',
+    413 => 'Request Entity Too Large',
+    414 => 'Request-URI Too Large',
+    415 => 'Unsupported Media Type',
+    416 => 'Request Range Not Satisfiable',
+    417 => 'Expectation Failed',
+    500 => 'Internal Server Error',
+    501 => 'Not Implemented',
+    502 => 'Bad Gateway',
+    503 => 'Service Unavailable',
+    504 => 'Gateway Timeout',
+    505 => 'HTTP Version Not Supported',
+);
+
+my $mnemonicCode = '';
+my ($code, $message);
+while (($code, $message) = each %StatusCode) {
+    # create mnemonic subroutines
+    $message =~ tr/a-z \-/A-Z__/;
+    $mnemonicCode .= "sub RC_$message () { $code }\t";
+    # make them exportable
+    $mnemonicCode .= "push(\@EXPORT, 'RC_$message');\n";
+}
+# warn $mnemonicCode; # for development
+eval $mnemonicCode; # only one eval for speed
+die if $@;
+
+# backwards compatibility
+*RC_MOVED_TEMPORARILY = \&RC_FOUND;  # 302 was renamed in the standard
+push(@EXPORT, "RC_MOVED_TEMPORARILY");
+
+
+=head1 FUNCTIONS
+
+The following additional functions are provided.  Most of them are
+exported by default.
+
+=over 4
+
+=item status_message($code)
+
+The status_message() function will translate status codes to human
+readable strings. The string is the same as found in the constant
+names above.  If the $code is unknown, then C<undef> is returned.
+
+=cut
+
+sub status_message ($)
+{
+    $StatusCode{$_[0]};
+}
+
+=item is_info($code)
+
+Return TRUE if C<$code> is an I<Informational> status code.  This
+class of status code indicates a provisional response which can't have
+any content.
+
+=item is_success($code)
+
+Return TRUE if C<$code> is a I<Successful> status code.
+
+=item is_redirect($code)
+
+Return TRUE if C<$code> is a I<Redirection> status code. This class of
+status code indicates that further action needs to be taken by the
+user agent in order to fulfill the request.
+
+=item is_error($code)
+
+Return TRUE if C<$code> is an I<Error> status code.  The function
+return TRUE for both client error or a server error status codes.
+
+=item is_client_error($code)
+
+Return TRUE if C<$code> is an I<Client Error> status code. This class
+of status code is intended for cases in which the client seems to have
+erred.
+
+This function is B<not> exported by default.
+
+=item is_server_error($code)
+
+Return TRUE if C<$code> is an I<Server Error> status code. This class
+of status codes is intended for cases in which the server is aware
+that it has erred or is incapable of performing the request.
+
+This function is B<not> exported by default.
+
+=back
+
+=cut
+
+sub is_info         ($) { $_[0] >= 100 && $_[0] < 200; }
+sub is_success      ($) { $_[0] >= 200 && $_[0] < 300; }
+sub is_redirect     ($) { $_[0] >= 300 && $_[0] < 400; }
+sub is_error        ($) { $_[0] >= 400 && $_[0] < 600; }
+sub is_client_error ($) { $_[0] >= 400 && $_[0] < 500; }
+sub is_server_error ($) { $_[0] >= 500 && $_[0] < 600; }
+
+1;
+
+=head1 BUGS
+
+Wished @EXPORT_OK had been used instead of @EXPORT in the beginning.
+Now too much is exported by default.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP.pm	(revision 16571)
@@ -0,0 +1,593 @@
+#
+# $Id$
+
+package LWP;
+
+$VERSION = "5.36";
+sub Version { $VERSION; }
+
+require 5.004;
+require LWP::UserAgent;  # this should load everything you need
+
+1;
+
+__END__
+
+=head1 NAME
+
+LWP - Library for WWW access in Perl
+
+=head1 SYNOPSIS
+
+  use LWP;
+  print "This is libwww-perl-$LWP::VERSION\n";
+
+
+=head1 DESCRIPTION
+
+Libwww-perl is a collection of Perl modules which provides a simple
+and consistent programming interface (API) to the World-Wide Web.  The
+main focus of the library is to provide classes and functions that
+allow you to write WWW clients, thus libwww-perl said to be a WWW
+client library. The library also contain modules that are of more
+general use.
+
+Most modules in this library are object oriented.  The user
+agent, requests sent and responses received from the WWW server are
+all represented by objects.  This makes a simple and powerful
+interface to these services.  The interface should be easy to extend
+and customize for your needs.
+
+The main features of the library are:
+
+=over 3
+
+=item *
+
+Contains various reusable components (modules) that can be
+used separately or together.
+
+=item *
+
+Provides an object oriented model of HTTP-style communication.  Within
+this framework we currently support access to http, https, gopher, ftp, news,
+file, and mailto resources.
+
+=item *
+
+The library be used through the full object oriented interface or
+through a very simple procedural interface.
+
+=item *
+
+Support the basic and digest authorization schemes.
+
+=item *
+
+Transparent redirect handling.
+
+=item *
+
+Supports access through proxy servers.
+
+=item *
+
+URL handling (both absolute and relative URLs are supported).
+
+=item *
+
+A parser for F<robots.txt> files and a framework for constructing robots.
+
+=item *
+
+The library can cooperate with Tk.  A simple Tk-based GUI browser
+called 'tkweb' is distributed with the Tk extension for perl.
+
+=item *
+
+An implementation of the HTTP content negotiation algorithm that can
+be used both in protocol modules and in server scripts (like CGI
+scripts).
+
+=item *
+
+It can deal with HTTP cookies.
+
+=item *
+
+A simple command line client application called C<lwp-request>.
+
+=back
+
+
+=head1 HTTP STYLE COMMUNICATION
+
+
+The libwww-perl library is based on HTTP style communication. This
+section try to describe what that means.
+
+Let us start with this quote from the HTTP specification document
+<URL:http://www.w3.org/pub/WWW/Protocols/>:
+
+=over 3
+
+=item
+
+The HTTP protocol is based on a request/response paradigm. A client
+establishes a connection with a server and sends a request to the
+server in the form of a request method, URI, and protocol version,
+followed by a MIME-like message containing request modifiers, client
+information, and possible body content. The server responds with a
+status line, including the message's protocol version and a success or
+error code, followed by a MIME-like message containing server
+information, entity meta-information, and possible body content.
+
+=back
+
+What this means to libwww-perl is that communication always take place
+through these steps: First a I<request> object is created and
+configured. This object is then passed to a server and we get a
+I<response> object in return that we can examine. A request is always
+independent of any previous requests, i.e. the service is stateless.
+The same simple model is used for any kind of service we want to
+access.
+
+For example, if we want to fetch a document from a remote file server,
+then we send it a request that contains a name for that document and
+the response will contain the document itself.  If we access a search
+engine, then the content of the request will contain the query
+parameters and the response will contain the query result.  If we want
+to send a mail message to somebody then we send a request object which
+contains our message to the mail server and the response object will
+contain an acknowledgment that tells us that the message has been
+accepted and will be forwarded to the recipient(s).
+
+It is as simple as that!
+
+
+=head2 The Request Object
+
+The request object has the class name C<HTTP::Request> in
+libwww-perl. The fact that the class name use C<HTTP::> as a name
+prefix only implies that we use the HTTP model of communication. It
+does not limit the kind of services we can try to pass this I<request>
+to.  For instance, we will send C<HTTP::Request>s both to ftp and
+gopher servers, as well as to the local file system.
+
+The main attributes of the request objects are:
+
+=over 3
+
+=item *
+
+The B<method> is a short string that tells what kind of
+request this is.  The most used methods are B<GET>, B<PUT>,
+B<POST> and B<HEAD>.
+
+=item *
+
+The B<url> is a string denoting the protocol, server and
+the name of the "document" we want to access.  The B<url> might
+also encode various other parameters.
+
+=item *
+
+The B<headers> contain additional information about the
+request and can also used to describe the content.  The headers
+is a set of keyword/value pairs.
+
+=item *
+
+The B<content> is an arbitrary amount of data.
+
+=back
+
+=head2 The Response Object
+
+The response object has the class name C<HTTP::Response> in
+libwww-perl.  The main attributes of objects of this class are:
+
+=over 3
+
+=item *
+
+The B<code> is a numerical value that encode the overall
+outcome of the request.
+
+=item *
+
+The B<message> is a short (human readable) string that
+corresponds to the I<code>.
+
+=item *
+
+The B<headers> contain additional information about the
+response and they also describe the content.
+
+=item *
+
+The B<content> is an arbitrary amount of data.
+
+=back
+
+Since we don't want to handle all possible I<code> values directly in
+our programs, the libwww-perl response object have methods that can be
+used to query what kind of response this is.  The most commonly used
+response classification methods are:
+
+=over 3
+
+=item is_success()
+
+The request was was successfully received, understood or accepted.
+
+=item is_error()
+
+The request failed.  The server or the resource might not be
+available, access to the resource might be denied or other things might
+have failed for some reason.
+
+=back
+
+=head2 The User Agent
+
+Let us assume that we have created a I<request> object. What do we
+actually do with it in order to receive a I<response>?
+
+The answer is that you pass it on to a I<user agent> object and this
+object will take care of all the things that need to be done
+(low-level communication and error handling). The user agent will give
+you back a I<response> object. The user agent represents your
+application on the network and it provides you with an interface that
+can accept I<requests> and will return I<responses>.
+
+You should think about the user agent as an interface layer between
+your application code and the network.  Through this interface you are
+able to access the various servers on the network.
+
+The libwww-perl class name for the user agent is
+C<LWP::UserAgent>. Every libwww-perl application that wants to
+communicate should create at least one object of this kind. The main
+method provided by this object is request(). This method takes an
+C<HTTP::Request> object as argument and will (eventually) return a
+C<HTTP::Response> object.
+
+The user agent has many other attributes that lets you
+configure how it will interact with the network and with your
+application code.
+
+=over 3
+
+=item *
+
+The B<timeout> specify how much time we give remote servers in
+creating responses before the library disconnect and creates an
+internal I<timeout> response.
+
+=item *
+
+The B<agent> specify the name that your application should use when it
+presents itself on the network.
+
+=item *
+
+The B<from> attribute can be set to the e-mail address of the person
+responsible for running the application.  If this is set, then the
+address will be sent to the servers with every request.
+
+=item *
+
+The B<parse_head> specify whether we should initialize response
+headers from the E<lt>head> section of HTML documents.
+
+=item *
+
+The B<proxy> and B<no_proxy> specify if and when communication should
+go through a proxy server. <URL:http://www.w3.org/pub/WWW/Proxies/>
+
+=item *
+
+The B<credentials> provide a way to set up user names and
+passwords that is needed to access certain services.
+
+=back
+
+Many applications would want even more control over how they interact
+with the network and they get this by specializing the
+C<LWP::UserAgent> by sub-classing.  The library provide a
+specialization called C<LWP::RobotUA> that is used by robot
+applications.
+
+=head2 An Example
+
+This example shows how the user agent, a request and a response are
+represented in actual perl code:
+
+  # Create a user agent object
+  use LWP::UserAgent;
+  $ua = new LWP::UserAgent;
+  $ua->agent("AgentName/0.1 " . $ua->agent);
+
+  # Create a request
+  my $req = new HTTP::Request POST => 'http://www.perl.com/cgi-bin/BugGlimpse';
+  $req->content_type('application/x-www-form-urlencoded');
+  $req->content('match=www&errors=0');
+
+  # Pass request to the user agent and get a response back
+  my $res = $ua->request($req);
+
+  # Check the outcome of the response
+  if ($res->is_success) {
+      print $res->content;
+  } else {
+      print "Bad luck this time\n";
+  }
+
+The $ua is created once when the application starts up.  New request
+objects are normally created for each request sent.
+
+
+=head1 NETWORK SUPPORT
+
+This section goes through the various protocol schemes and describe
+the HTTP style methods that are supported and the headers that might
+have any effect.
+
+For all requests, a "User-Agent" header is added and initialized from
+the $ua->agent value before the request is handed to the network
+layer.  In the same way, a "From" header is initialized from the
+$ua->from value.
+
+For all responses, the library will add a header called "Client-Date".
+This header will encode the time when the response was received by
+your application.  This format and semantics of the header is just
+like the server created "Date" header.  You can also encounter other
+"Client-XXX" headers.  They are all generated by the library
+internally and not something really passed on from the servers.
+
+=head2 HTTP Requests
+
+HTTP request are really just handed off to an HTTP server and it will
+decide what happens.  Few servers implement methods beside the usual
+"GET", "HEAD", "POST" and "PUT" but CGI-scripts can really implement
+any method they like.
+
+If the server is not available then the library will generate an
+internal error response.
+
+The library automatically adds a "Host" and a "Content-Length" header
+to the HTTP request before it is sent over the network.
+
+For GET request you might want to add the "If-Modified-Since" header
+to make the request conditional.
+
+For POST request you should add the "Content-Type" header.  When you
+try to emulate HTML E<lt>FORM> handling you should usually let the value
+of the "Content-Type" header be "application/x-www-form-urlencoded".
+See L<lwpcook> for examples of this.
+
+The libwww-perl HTTP implementation currently support the HTTP/1.0
+protocol.  HTTP/0.9 servers are also handled correctly.
+
+The library allows you to access proxy server through HTTP.  This
+means that you can set up the library to forward all types of request
+through the HTTP protocol module.  See L<LWP::UserAgent> for
+documentation of this.
+
+
+=head2 HTTPS Requests
+
+HTTPS requests are HTTP requests over an encrypted network connection
+using the SSL protocol developed by Netscape.  Everything about HTTP
+requests above also hold for HTTPS requests.  In addition the library
+will add the headers "Client-SSL-Cipher", "Client-SSL-Cert-Subject" and
+"Client-SSL-Cert-Issuer" to the response.  These headers denote the
+encryption method used and the name of the server owner.
+
+The request can contain the header "If-SSL-Cert-Subject" in order to
+make the request conditional on the content of the server certificate.
+If the certificate subject does not match, no request is sent to the
+server and an internally generated error response is returned.  The
+value of the "If-SSL-Cert-Subject" header is interpreted as a Perl
+regular expression.
+
+
+=head2 FTP Requests
+
+The library currently support GET, HEAD and PUT requests.  GET will
+retrieve a file or a directory listing from an FTP server.  PUT will
+store a file on a ftp server.
+
+You can specify a ftp account for servers that want this in addition
+user name and password.  This is specified by passing an "Account"
+header in the request.
+
+User name/password can be specified using basic authorization or be
+encoded in the URL.  Bad logins return an UNAUTHORIZED response with
+"WWW-Authenticate: Basic" and can be treated as basic authorization
+for HTTP.
+
+The library support ftp ASCII transfer mode by specifying the "type=a"
+parameter in the URL.
+
+Directory listings are by default returned unprocessed (as returned
+from the ftp server) with the content media type reported to be
+"text/ftp-dir-listing". The C<File::Listing> module provide functionality
+for parsing of these directory listing.
+
+The ftp module is also able to convert directory listings to HTML and
+this can be requested via the standard HTTP content negotiation
+mechanisms (add an "Accept: text/html" header in the request if you
+want this).
+
+The normal file retrievals, the "Content-Type" is guessed based on the
+file name suffix. See L<LWP::MediaTypes>.
+
+The "If-Modified-Since" request header works for servers that implement
+the MDTM command.  It will probably not work for directory listings though.
+
+Example:
+
+  $req = HTTP::Request->new(GET => 'ftp://me:passwd@ftp.some.where.com/');
+  $req->header(Accept => "text/html, */*;q=0.1");
+
+=head2 News Requests
+
+Access to the USENET News system is implemented through the NNTP
+protocol.  The name of the news server is obtained from the
+NNTP_SERVER environment variable and defaults to "news".  It is not
+possible to specify the hostname of the NNTP server in the news:-URLs.
+
+The library support GET and HEAD to retrieve news articles through the
+NNTP protocol.  You can also post articles to newsgroups by using
+(surprise!) the POST method.
+
+GET on newsgroups is not implemented yet.
+
+Examples:
+
+  $req = HTTP::Request->new(GET => 'news:abc1234@a.sn.no');
+
+  $req = HTTP::Request->new(POST => 'news:comp.lang.perl.test');
+  $req->header(Subject => 'This is a test',
+               From    => 'me@some.where.org');
+  $req->content(<<EOT);
+  This is the content of the message that we are sending to
+  the world.
+  EOT
+
+
+=head2 Gopher Request
+
+The library supports the GET and HEAD method for gopher request.  All
+request header values are ignored.  HEAD cheats and will return a
+response without even talking to server.
+
+Gopher menus are always converted to HTML.
+
+The response "Content-Type" is generated from the document type
+encoded (as the first letter) in the request URL path itself.
+
+Example:
+
+  $req = HTTP::Request->new(GET => 'gopher://gopher.sn.no/');
+
+
+
+=head2 File Request
+
+The library supports GET and HEAD methods for file requests.  The
+"If-Modified-Since" header is supported.  All other headers are
+ignored.  The I<host> component of the file URL must be empty or set
+to "localhost".  Any other I<host> value will be treated as an error.
+
+Directories are always converted to an HTML document.  For normal
+files, the "Content-Type" and "Content-Encoding" in the response are
+guessed based on the file suffix.
+
+Example:
+
+  $req = HTTP::Request->new(GET => 'file:/etc/passwd');
+
+
+=head2 Mailto Request
+
+You can send (aka "POST") mail messages using the library.  All
+headers specified for the request are passed on to the mail system.
+The "To" header is initialized from the mail address in the URL.
+
+Example:
+
+  $req = HTTP::Request->new(POST => 'mailto:libwww-perl-request@ics.uci.edu');
+  $req->header(Subject => "subscribe");
+  $req->content("Please subscribe me to the libwww-perl mailing list!\n");
+
+
+=head1 OVERVIEW OF CLASSES AND PACKAGES
+
+This table should give you a quick overview of the classes provided by the
+library. Indentation shows class inheritance.
+
+ LWP::MemberMixin   -- Access to member variables of Perl5 classes
+   LWP::UserAgent   -- WWW user agent class
+     LWP::RobotUA   -- When developing a robot applications
+   LWP::Protocol          -- Interface to various protocol schemes
+     LWP::Protocol::http  -- http:// access
+     LWP::Protocol::file  -- file:// access
+     LWP::Protocol::ftp   -- ftp:// access
+     ...
+
+ LWP::Authen::Basic -- Handle 401 and 407 responses
+ LWP::Authen::Digest
+
+ HTTP::Headers      -- MIME/RFC822 style header (used by HTTP::Message)
+ HTTP::Message      -- HTTP style message
+   HTTP::Request    -- HTTP request
+   HTTP::Response   -- HTTP response
+ HTTP::Daemon       -- A HTTP server class
+
+ URI::URL           -- Uniform Resource Locators
+
+ WWW::RobotRules    -- Parse robots.txt files
+   WWW::RobotRules::AnyDBM_File -- Persistent RobotRules
+
+The following modules provide various functions and definitions.
+
+ LWP                -- This file.  Library version number and documentation.
+ LWP::MediaTypes    -- MIME types configuration (text/html etc.)
+ LWP::Debug         -- Debug logging module
+ LWP::Simple        -- Simplified procedural interface for common functions
+ HTTP::Status       -- HTTP status code (200 OK etc)
+ HTTP::Date         -- Date parsing module for HTTP date formats
+ HTTP::Negotiate    -- HTTP content negotiation calculation
+ File::Listing      -- Parse directory listings
+
+
+=head1 MORE DOCUMENTATION
+
+All modules contain detailed information on the interfaces they
+provide.  The I<lwpcook> manpage is the libwww-perl cookbook that contain
+examples of typical usage of the library.  You might want to take a
+look at how the scripts C<lwp-request>, C<lwp-rget> and C<lwp-mirror>
+are implemented.
+
+=head1 BUGS
+
+The library can not handle multiple simultaneous requests yet.  Also,
+check out what's left in the TODO file.
+
+=head1 ACKNOWLEDGEMENTS
+
+This package owes a lot in motivation, design, and code, to the
+libwww-perl library for Perl 4, maintained by Roy Fielding
+E<lt>fielding@ics.uci.edu>.
+
+That package used work from Alberto Accomazzi, James Casey, Brooks
+Cutter, Martijn Koster, Oscar Nierstrasz, Mel Melchner, Gertjan van
+Oosten, Jared Rhine, Jack Shirazi, Gene Spafford, Marc VanHeyningen,
+Steven E. Brenner, Marion Hakanson, Waldemar Kebsch, Tony Sanders, and
+Larry Wall; see the libwww-perl-0.40 library for details.
+
+The primary architect for this Perl 5 library is Martijn Koster and
+Gisle Aas, with lots of help from Graham Barr, Tim Bunce, Andreas
+Koenig, Jared Rhine, and Jack Shirazi.
+
+
+=head1 COPYRIGHT
+
+  Copyright 1995-1998, Gisle Aas
+  Copyright 1995, Martijn Koster
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=head1 AVAILABILITY
+
+The latest version of this library is likely to be available from:
+
+ http://www.sn.no/libwww-perl/
+
+The best place to discuss this code is on the
+<libwww-perl@ics.uci.edu> mailing list.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Authen/Basic.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Authen/Basic.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Authen/Basic.pm	(revision 16571)
@@ -0,0 +1,36 @@
+package LWP::Authen::Basic;
+use strict;
+
+require MIME::Base64;
+
+sub authenticate
+{
+    my($class, $ua, $proxy, $auth_param, $response,
+       $request, $arg, $size) = @_;
+
+    my($user, $pass) = $ua->get_basic_credentials($auth_param->{realm},
+                                                  $request->url, $proxy);
+    return $response unless defined $user and defined $pass;
+
+    my $auth_header = $proxy ? "Proxy-Authorization" : "Authorization";
+    my $auth_value = "Basic " . MIME::Base64::encode("$user:$pass", "");
+
+    # Need to check this isn't a repeated fail!
+    my $r = $response;
+    while ($r) {
+	my $auth = $r->request->header($auth_header);
+	if ($auth && $auth eq $auth_value) {
+	    # here we know this failed before
+	    $response->header("Client-Warning" =>
+			      "Credentials for '$user' failed before");
+	    return $response;
+	}
+	$r = $r->previous;
+    }
+
+    my $referral = $request->clone;
+    $referral->header($auth_header => $auth_value);
+    return $ua->request($referral, $arg, $size, $response);
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Authen/Digest.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Authen/Digest.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Authen/Digest.pm	(revision 16571)
@@ -0,0 +1,73 @@
+package LWP::Authen::Digest;
+use strict;
+
+require MD5;
+
+sub authenticate
+{
+    my($class, $ua, $proxy, $auth_param, $response,
+       $request, $arg, $size) = @_;
+
+    my($user, $pass) = $ua->get_basic_credentials($auth_param->{realm},
+                                                  $request->url, $proxy);
+    return $response unless defined $user and defined $pass;
+
+    my $md5 = new MD5;
+
+    my(@digest);
+    $md5->add(join(":", $user, $auth_param->{realm}, $pass));
+    push(@digest, $md5->hexdigest);
+    $md5->reset;
+
+    push(@digest, $auth_param->{nonce});
+
+    $md5->add(join(":", $request->method, $request->url->path));
+    push(@digest, $md5->hexdigest);
+    $md5->reset;
+
+    $md5->add(join(":", @digest));
+    my($digest) = $md5->hexdigest;
+    $md5->reset;
+
+    my %resp = map { $_ => $auth_param->{$_} } qw(realm nonce opaque);
+    @resp{qw(username uri response)} = ($user, $request->url->path, $digest);
+
+    my(@order) = qw(username realm nonce uri response);
+    if($request->method =~ /^(?:POST|PUT)$/) {
+	$md5->add($request->content);
+	my $content = $md5->hexdigest;
+	$md5->reset;
+	$md5->add(join(":", @digest[0..1], $content));
+	$md5->reset;
+	$resp{"message-digest"} = $md5->hexdigest;
+	push(@order, "message-digest");
+    }
+    push(@order, "opaque");
+    my @pairs;
+    for (@order) {
+	next unless defined $resp{$_};
+	push(@pairs, "$_=" . qq("$resp{$_}"));
+    }
+
+    my $auth_header = $proxy ? "Proxy-Authorization" : "Authorization";
+    my $auth_value  = "Digest " . join(", ", @pairs);
+    
+    # Need to check this isn't a repeated fail!
+    my $r = $response;
+    while ($r) {
+	my $auth = $r->request->header($auth_header);
+	if ($auth && $auth eq $auth_value) {
+	    # here we know this failed before
+	    $response->header("Client-Warning" =>
+			      "Credentials for '$user' failed before");
+	    return $response;
+	}
+	$r = $r->previous;
+    }
+
+    my $referral = $request->clone;
+    $referral->header($auth_header => $auth_value);
+    return $ua->request($referral, $arg, $size, $response);
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Debug.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Debug.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Debug.pm	(revision 16571)
@@ -0,0 +1,129 @@
+#!/usr/local/bin/perl -w
+#
+# $Id$
+#
+package LWP::Debug;
+
+=head1 NAME
+
+LWP::Debug - debug routines for the libwww-perl library
+
+=head1 SYNOPSIS
+
+ use LWP::Debug qw(+ -conns);
+
+ # Used internally in the library
+ LWP::Debug::trace('send()');
+ LWP::Debug::debug('url ok');
+ LWP::Debug::conns("read $n bytes: $data");
+
+=head1 DESCRIPTION
+
+LWP::Debug provides tracing facilities. The trace(), debug() and
+conns() function are called within the library and they log
+information at increasing levels of detail. Which level of detail is
+actually printed is controlled with the C<level()> function.
+
+The following functions are available:
+
+=over 4
+
+=item level(...)
+
+The C<level()> function controls the level of detail being
+logged. Passing '+' or '-' indicates full and no logging
+respectively. Inidividual levels can switched on and of by passing the
+name of the level with a '+' or '-' prepended.  The levels are:
+
+  trace   : trace function calls
+  debug   : print debug messages
+  conns   : show all data transfered over the connections
+
+The LWP::Debug module provide a special import() method that allows
+you to pass the level() arguments with initial use statement.  If a
+use argument start with '+' or '-' then it is passed to the level
+function, else the name is exported as usual.  The following two
+statements are thus equivalent (if you ignore that the second pollutes
+your namespace):
+
+  use LWP::Debug qw(+);
+  use LWP::Debug qw(level); level('+');
+
+=item trace($msg)
+
+The C<trace()> function is used for tracing function
+calls. The package and calling subroutine name is
+printed along with the passed argument. This should
+be called at the start of every major function.
+
+=item debug($msg)
+
+The C<debug()> function is used for high-granularity
+reporting of state in functions.
+
+=item conns($msg)
+
+The C<conns()> function is used to show data being
+transferred over the connections. This may generate
+considerable output.
+
+=back
+
+=cut
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(level trace debug conns);
+
+use Carp ();
+
+my @levels = qw(trace debug conns);
+%current_level = ();
+
+sub import
+{
+    my $pack = shift;
+    my $callpkg = caller(0);
+    my @symbols = ();
+    my @levels = ();
+    for (@_) {
+	if (/^[-+]/) {
+	    push(@levels, $_);
+	} else {
+	    push(@symbols, $_);
+	}
+    }
+    Exporter::export($pack, $callpkg, @symbols);
+    level(@levels);
+}
+
+sub level
+{
+    for (@_) {
+	if ($_ eq '+') {              # all on
+	    # switch on all levels
+	    %current_level = map { $_ => 1 } @levels;
+	} elsif ($_ eq '-') {           # all off
+	    %current_level = ();
+	} elsif (/^([-+])(\w+)$/) {
+	    $current_level{$2} = $1 eq '+';
+	} else {
+	    Carp::croak("Illegal level format $_");
+	}
+    }
+}
+
+sub trace  { _log(@_) if $current_level{'trace'}; }
+sub debug  { _log(@_) if $current_level{'debug'}; }
+sub conns  { _log(@_) if $current_level{'conns'}; }
+
+sub _log
+{
+    my $msg = shift;
+    $msg .= "\n" unless $msg =~ /\n$/;  # ensure trailing "\n"
+
+    my($package,$filename,$line,$sub) = caller(2);
+    print STDERR "$sub: $msg";
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/MediaTypes.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/MediaTypes.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/MediaTypes.pm	(revision 16571)
@@ -0,0 +1,298 @@
+#
+# $Id$
+
+package LWP::MediaTypes;
+
+=head1 NAME
+
+LWP::MediaTypes - guess media type for a file or a URL
+
+=head1 SYNOPSIS
+
+ use LWP::MediaTypes qw(guess_media_type);
+ $type = guess_media_type("/tmp/foo.gif");
+
+=head1 DESCRIPTION
+
+This module provides functions for handling of media (also known as
+MIME) types and encodings.  The mapping from file extentions to media
+types is defined by the F<media.types> file.  If the F<~/.media.types>
+file exist it is used as a replacement.
+For backwards compatability we will also look for F<~/.mime.types>.
+
+The following functions are exported by default:
+
+=over 4
+
+=cut
+
+####################################################################
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT = qw(guess_media_type media_suffix);
+@EXPORT_OK = qw(add_type add_encoding);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+require LWP::Debug;
+use strict;
+
+# note: These hashes will also be filled with the entries found in
+# the 'media.types' file.
+
+my %suffixType = (
+    'txt'   => 'text/plain',
+    'html'  => 'text/html',
+    'gif'   => 'image/gif',
+    'jpg'   => 'image/jpeg',
+);
+
+my %suffixExt = (
+    'text/plain' => 'txt',
+    'text/html'  => 'h',
+    'image/gif'  => 'gif',
+    'image/jpeg' => 'jpg',
+);
+
+#XXX: there should be some way to define this in the media.types files.
+my %suffixEncoding = (
+    'Z'   => 'compress',
+    'gz'  => 'gzip',
+    'hqx' => 'x-hqx',
+    'uu'  => 'x-uuencode',
+    'z'   => 'x-pack'
+);
+
+sub _dump {
+    require Data::Dumper;
+    Data::Dumper->new([\%suffixType, \%suffixExt, \%suffixEncoding],
+		      [qw(*suffixType *suffixExt *suffixEncoding)])->Dump;
+}
+
+read_media_types();
+
+
+
+=item guess_media_type($filename_or_url, [$header_to_modify])
+
+This function tries to guess media type and encoding for given file.
+It returns the content-type, which is a string like C<"text/html">.
+In array context it also returns any content-encodings applied (in the
+order used to encode the file).  You can pass a URI::URL object
+reference, instead of the file name, as the first parameter too.
+
+If the type can not be deduced from looking at the file name only,
+then guess_media_type() will let the C<-T> Perl operator take a look.
+If this works (and C<-T> returns a TRUE value) then we return
+I<text/plain> as the type, otherwise we return
+I<application/octet-stream> as the type.
+
+The optional second argument should be a reference to a HTTP::Headers
+object (or any object that implement the $obj->header method in a
+similar way).  When present we will set the values of the
+'Content-Type' and 'Content-Encoding' for this header.
+
+=cut
+
+sub guess_media_type
+{
+    my($file, $header) = @_;
+    return undef unless defined $file;
+
+    my $fullname;
+    if (ref($file)) {
+	# assume URI::URL object
+	$file = $file->path;
+	#XXX should handle non http:, file: or ftp: URLs differently
+    } else {
+	$fullname = $file;  # enable peek at actual file
+    }
+
+    my @encoding = ();
+    my $ct = undef;
+    for (file_exts($file)) {
+	# first check this dot part as encoding spec
+	if (exists $suffixEncoding{$_}) {
+	    unshift(@encoding, $suffixEncoding{$_});
+	    next;
+	}
+	if (exists $suffixEncoding{lc $_}) {
+	    unshift(@encoding, $suffixEncoding{lc $_});
+	    next;
+	}
+
+	# check content-type
+	if (exists $suffixType{$_}) {
+	    $ct = $suffixType{$_};
+	    last;
+	}
+	if (exists $suffixType{lc $_}) {
+	    $ct = $suffixType{lc $_};
+	    last;
+	}
+
+	# don't know nothing about this dot part, bail out
+	last;
+    }
+    unless (defined $ct) {
+	# Take a look at the file
+	if (defined $fullname) {
+	    $ct = (-T $fullname) ? "text/plain" : "application/octet-stream";
+	} else {
+	    $ct = "application/octet-stream";
+	}
+    }
+
+    if ($header) {
+	$header->header('Content-Type' => $ct);
+	$header->header('Content-Encoding' => \@encoding) if @encoding;
+    }
+
+    wantarray ? ($ct, @encoding) : $ct;
+}
+
+
+=item media_suffix($type,...)
+
+This function will return all suffixes that can be used to denote the
+specified media type(s).  Wildcard types can be used.  In scalar
+context it will return the first suffix found.
+
+Examples:
+
+  @suffixes = media_suffix('image/*', 'audio/basic');
+  $suffix = media_suffix('text/html');
+
+=cut
+
+sub media_suffix {
+    if (!wantarray && @_ == 1 && $_[0] !~ /\*/) {
+	return $suffixExt{$_[0]};
+    }
+    my(@type) = @_;
+    my(@suffix, $ext, $type);
+    foreach (@type) {
+	if (s/\*/.*/) {
+	    while(($ext,$type) = each(%suffixType)) {
+		push(@suffix, $ext) if $type =~ /^$_$/;
+	    }
+	} else {
+	    while(($ext,$type) = each(%suffixType)) {
+		push(@suffix, $ext) if $type eq $_;
+	    }
+	}
+    }
+    wantarray ? @suffix : $suffix[0];
+}
+
+
+sub file_exts 
+{
+    my($file) = @_;
+    $file =~ s,.*/,,;   # only basename left
+    my @parts = reverse split(/\./, $file);
+    pop(@parts);        # never concider first part
+    @parts;
+}
+
+
+=back
+
+The following functions are only exported by explict request:
+
+=over 4
+
+=item add_type($type, @exts)
+
+Associate a list of file extensions with the given media type.
+
+Example:
+
+    add_type("x-world/x-vrml" => qw(wrl vrml));
+
+=cut
+
+sub add_type 
+{
+    my($type, @exts) = @_;
+    for my $ext (@exts) {
+	$ext =~ s/^\.//;
+	$suffixType{$ext} = $type;
+    }
+    $suffixExt{$type} = $exts[0] if @exts;
+}
+
+
+=item add_encoding($type, @ext)
+
+Associate a list of file extensions with and encoding type.
+
+Example:
+
+ add_encoding("x-gzip" => "gz");
+
+=cut
+
+sub add_encoding
+{
+    my($type, @exts) = @_;
+    for my $ext (@exts) {
+	$ext =~ s/^\.//;
+	$suffixEncoding{$ext} = $type;
+    }
+}
+
+
+=item read_media_types(@files)
+
+Parse a media types file from disk and add the type mappings found there.
+
+Example:
+
+    read_media_types("conf/mime.types");
+
+=cut
+
+sub read_media_types 
+{
+    my(@files) = @_;
+
+    local($/, $_) = ("\n", undef);  # ensure correct $INPUT_RECORD_SEPARATOR
+
+    my @priv_files = ();
+    push(@priv_files, "$ENV{HOME}/.media.types", "$ENV{HOME}/.mime.types")
+	if defined $ENV{HOME};  # Some doesn't have a home (for instance Win32)
+
+    # Try to locate "media.types" file, and initialize %suffixType from it
+    my $typefile;
+    unless (@files) {
+	@files = map {"$_/LWP/media.types"} @INC;
+	push @files, @priv_files;
+    }
+    for $typefile (@files) {
+	local(*TYPE);
+	open(TYPE, $typefile) || next;
+        LWP::Debug::debug("Reading media types from $typefile");
+	while (<TYPE>) {
+	    next if /^\s*#/; # comment line
+	    next if /^\s*$/; # blank line
+	    s/#.*//;         # remove end-of-line comments
+	    my($type, @exts) = split(' ', $_);
+	    add_type($type, @exts);
+	}
+	close(TYPE);
+    }
+}
+
+1;
+
+=back 
+
+=head1 COPYRIGHT
+
+Copyright 1995-1998 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/MemberMixin.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/MemberMixin.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/MemberMixin.pm	(revision 16571)
@@ -0,0 +1,46 @@
+#
+# $Id$
+
+package LWP::MemberMixin;
+
+=head1 NAME
+
+LWP::MemberMixin - Member access mixin class
+
+=head1 SYNOPSIS
+
+ package Foo;
+ require LWP::MemberMixin;
+ @ISA=qw(LWP::MemberMixin);
+
+=head1 DESCRIPTION
+
+A mixin class to get methods that provide easy access to member
+variables in the %$self.
+Ideally there should be better Perl langauge support for this.
+
+There is only one method provided:
+
+=over 4
+
+=item _elem($elem [, $val])
+
+Internal method to get/set the value of member variable
+C<$elem>. If C<$val> is defined it is used as the new value
+for the member variable.  If it is undefined the current
+value is not touched. In both cases the previous value of
+the member variable is returned.
+
+=back
+
+=cut
+
+sub _elem
+{
+    my($self, $elem, $val) = @_;
+    my $old = $self->{$elem};
+    $self->{$elem} = $val if defined $val;
+    return $old;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol.pm	(revision 16571)
@@ -0,0 +1,303 @@
+# $Id$
+
+package LWP::Protocol;
+
+=head1 NAME
+
+LWP::Protocol - Base class for LWP protocols
+
+=head1 SYNOPSIS
+
+ package LWP::Protocol::foo;
+ require LWP::Protocol;
+ @ISA=qw(LWP::Protocol);
+
+=head1 DESCRIPTION
+
+This class is used a the base class for all protocol implementations
+supported by the LWP library.
+
+When creating an instance of this class using
+C<LWP::Protocol::create($url)>, and you get an initialised subclass
+appropriate for that access method. In other words, the
+LWP::Protocol::create() function calls the constructor for one of its
+subclasses.
+
+All derived LWP::Protocol classes need to override the request()
+method which is used to service a request. The overridden method can
+make use of the collect() function to collect together chunks of data
+as it is received.
+
+The following methods and functions are provided:
+
+=over 4
+
+=cut
+
+#####################################################################
+
+require LWP::MemberMixin;
+@ISA = qw(LWP::MemberMixin);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+use strict;
+use Carp ();
+use HTTP::Status 'RC_INTERNAL_SERVER_ERROR';
+require HTML::HeadParser;
+
+my %ImplementedBy = (); # scheme => classname
+
+
+=item $prot = new HTTP::Protocol;
+
+The LWP::Protocol constructor is inherited by subclasses. As this is a
+virtual base class this method should B<not> be called directly.
+
+=cut
+
+sub new
+{
+    my($class) = @_;
+
+    my $self = bless {
+	'timeout' => 0,
+	'parse_head' => 1,
+    }, $class;
+    $self;
+}
+
+
+=item $prot = LWP::Protocol::create($url)
+
+Create an object of the class implementing the protocol to handle the
+given scheme. This is a function, not a method. It is more an object
+factory than a constructor. This is the function user agents should
+use to access protocols.
+
+=cut
+
+sub create
+{
+    my $scheme = shift;
+    my $impclass = LWP::Protocol::implementor($scheme) or
+	Carp::croak("Protocol scheme '$scheme' is not supported");
+
+    # hand-off to scheme specific implementation sub-class
+    return $impclass->new($scheme);
+}
+
+
+=item $class = LWP::Protocol::implementor($scheme, [$class])
+
+Get and/or set implementor class for a scheme.  Returns '' if the
+specified scheme is not supported.
+
+=cut
+
+sub implementor
+{
+    my($scheme, $impclass) = @_;
+
+    if ($impclass) {
+	$ImplementedBy{$scheme} = $impclass;
+    }
+    my $ic = $ImplementedBy{$scheme};
+    return $ic if $ic;
+
+    return '' unless $scheme =~ /^([.+\-\w]+)$/;  # check valid URL schemes
+    $scheme = $1; # untaint
+    $scheme =~ s/[.+\-]/_/g;  # make it a legal module name
+
+    # scheme not yet known, look for a 'use'd implementation
+    $ic = "LWP::Protocol::$scheme";  # default location
+    $ic = "LWP::Protocol::nntp" if $scheme eq 'news'; #XXX ugly hack
+    no strict 'refs';
+    # check we actually have one for the scheme:
+    unless (defined @{"${ic}::ISA"}) {
+	# try to autoload it
+	eval "require $ic";
+	if ($@) {
+	    if ($@ =~ /^Can't locate/) { #' #emacs get confused by '
+		$ic = '';
+	    } else {
+		die "$@\n";
+	    }
+	}
+    }
+    $ImplementedBy{$scheme} = $ic if $ic;
+    $ic;
+}
+
+
+=item $prot->request(...)
+
+ $response = $protocol->request($request, $proxy, undef);
+ $response = $protocol->request($request, $proxy, '/tmp/sss');
+ $response = $protocol->request($request, $proxy, \&callback, 1024);
+
+Dispactches a request over the protocol, and returns a response
+object. This method needs to be overridden in subclasses.  Referer to
+L<LWP::UserAgent> for description of the arguments.
+
+=cut
+
+sub request
+{
+    my($self, $request, $proxy, $arg, $size, $timeout) = @_;
+    Carp::croak('LWP::Protocol::request() needs to be overridden in subclasses');
+}
+
+
+=item $prot->timeout($seconds)
+
+Get and set the timeout value in seconds
+
+
+=item $prot->parse_head($yesno)
+
+Should we initialize response headers from the <head> section of HTML
+documents.
+
+=cut
+
+sub timeout    { shift->_elem('timeout',    @_); }
+sub parse_head { shift->_elem('parse_head', @_); }
+sub max_size   { shift->_elem('max_size',   @_); }
+
+
+=item $prot->collect($arg, $response, $collector)
+
+Called to collect the content of a request, and process it
+appropriately into a scalar, file, or by calling a callback.  If $arg
+is undefined, then the content is stored within the $response.  If
+$arg is a simple scalar, then $arg is interpreted as a file name and
+the content is written to this file.  If $arg is a reference to a
+routine, then content is passed to this routine.
+
+The $collector is a routine that will be called and which is
+reponsible for returning pieces (as ref to scalar) of the content to
+process.  The $collector signals EOF by returning a reference to an
+empty sting.
+
+The return value from collect() is the $response object reference.
+
+B<Note:> We will only use the callback or file argument if
+$response->is_success().  This avoids sendig content data for
+redirects and authentization responses to the callback which would be
+confusing.
+
+=cut
+
+sub collect
+{
+    my ($self, $arg, $response, $collector) = @_;
+    my $content;
+    my($parse_head, $timeout, $max_size) =
+      @{$self}{qw(parse_head timeout max_size)};
+
+    my $parser;
+    if ($parse_head && $response->content_type eq 'text/html') {
+	$parser = HTML::HeadParser->new($response->{'_headers'});
+    }
+    my $content_size = 0;
+
+    if (!defined($arg) || !$response->is_success) {
+	# scalar
+	while ($content = &$collector, length $$content) {
+	    if ($parser) {
+		$parser->parse($$content) or undef($parser);
+	    }
+	    LWP::Debug::debug("read " . length($$content) . " bytes");
+	    $response->add_content($$content);
+	    $content_size += length($$content);
+	    if ($max_size && $content_size > $max_size) {
+		LWP::Debug::debug("Aborting because size limit exceeded");
+		my $tot = $response->header("Content-Length") || 0;
+		$response->header("X-Content-Range", "bytes 0-$content_size/$tot");
+		last;
+	    }
+	}
+    }
+    elsif (!ref($arg)) {
+	# filename
+	open(OUT, ">$arg") or
+	    return new HTTP::Response RC_INTERNAL_SERVER_ERROR,
+			  "Cannot write to '$arg': $!";
+        binmode(OUT);
+        local($\) = ""; # ensure standard $OUTPUT_RECORD_SEPARATOR
+	while ($content = &$collector, length $$content) {
+	    if ($parser) {
+		$parser->parse($$content) or undef($parser);
+	    }
+	    LWP::Debug::debug("read " . length($$content) . " bytes");
+	    print OUT $$content;
+	    $content_size += length($$content);
+	    if ($max_size && $content_size > $max_size) {
+		LWP::Debug::debug("Aborting because size limit exceeded");
+		my $tot = $response->header("Content-Length") || 0;
+		$response->header("X-Content-Range", "bytes 0-$content_size/$tot");
+		last;
+	    }
+	}
+	close(OUT);
+    }
+    elsif (ref($arg) eq 'CODE') {
+	# read into callback
+	while ($content = &$collector, length $$content) {
+	    if ($parser) {
+		$parser->parse($$content) or undef($parser);
+	    }
+	    LWP::Debug::debug("read " . length($$content) . " bytes");
+            eval {
+		&$arg($$content, $response, $self);
+	    };
+	    if ($@) {
+	        chomp($@);
+		$response->header('X-Died' => $@);
+		last;
+	    }
+	}
+    }
+    else {
+	return new HTTP::Response RC_INTERNAL_SERVER_ERROR,
+				  "Unexpected collect argument  '$arg'";
+    }
+    $response;
+}
+
+
+=item $prot->collect_once($arg, $response, $content)
+
+Can be called when the whole response content is available as
+$content.  This will invoke collect() with a collector callback that
+returns a reference to $content the first time and an empty string the
+next.
+
+=cut
+
+sub collect_once
+{
+    my($self, $arg, $response) = @_;
+    my $content = \ $_[3];
+    my $first = 1;
+    $self->collect($arg, $response, sub {
+	return $content if $first--;
+	return \ "";
+    });
+}
+
+1;
+
+=head1 SEE ALSO
+
+Inspect the F<LWP/Protocol/file.pm> and F<LWP/Protocol/http.pm> files
+for examples of usage.
+
+=head1 COPYRIGHT
+
+Copyright 1995-1997 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/data.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/data.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/data.pm	(revision 16571)
@@ -0,0 +1,53 @@
+#
+# $Id$
+#
+# Implements access to data:-URLs as specified in
+# draft-masinter-url-data-02.txt
+
+package LWP::Protocol::data;
+
+require HTTP::Response;
+require HTTP::Status;
+
+require LWP::Protocol;
+@ISA = qw(LWP::Protocol);
+
+use HTTP::Date qw(time2str);
+require LWP;  # needs version number
+
+sub request
+{
+    my($self, $request, $proxy, $arg, $size) = @_;
+
+    # check proxy
+    if (defined $proxy)
+    {
+	return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
+				  'You can not proxy with data';
+    }
+
+    # check method
+    if ($request->method ne 'GET') {
+	return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
+				  'Library does not allow method ' .
+				  "$method for 'data:' URLs";
+    }
+
+    my $url = $request->url;
+    my $response = new HTTP::Response &HTTP::Status::RC_OK, "Document follows";
+
+    my($media_type, $params) = $url->media_type;
+    $media_type .= ";$params" if $params;
+
+    my $data = $url->data;
+    $response->header('Content-Type'   => $media_type,
+		      'Content-Length' => length($data),
+		      'Date'           => time2str(time),
+		      'Server'         => "libwww-perl-internal/$LWP::VERSION"
+		     );
+    $response->content($data);
+
+    return $response;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/file.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/file.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/file.pm	(revision 16571)
@@ -0,0 +1,154 @@
+#
+# $Id$
+
+package LWP::Protocol::file;
+
+require LWP::Protocol;
+require LWP::MediaTypes;
+require HTTP::Request;
+require HTTP::Response;
+require HTTP::Status;
+require HTTP::Date;
+
+require URI::Escape;
+require HTML::Entities;
+
+use Carp;
+
+@ISA = qw(LWP::Protocol);
+
+
+sub request
+{
+    my($self, $request, $proxy, $arg, $size) = @_;
+
+    LWP::Debug::trace('()');
+
+    $size = 4096 unless defined $size and $size > 0;
+
+    # check proxy
+    if (defined $proxy)
+    {
+	return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
+				  'You can not proxy through the filesystem';
+    }
+
+    # check method
+    $method = $request->method;
+
+    unless ($method eq 'GET' || $method eq 'HEAD') {
+	return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
+				  'Library does not allow method ' .
+				  "$method for 'file:' URLs";
+    }
+
+    # check url
+    my $url = $request->url;
+
+    my $scheme = $url->scheme;
+    if ($scheme ne 'file') {
+	return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+				  "LWP::file::request called for '$scheme'";
+    }
+
+    my $host = $url->host;
+    if ($host and $host !~ /^localhost$/i) {
+	return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST_CLIENT,
+				  'Only file://localhost/ allowed';
+    }
+
+    # URL OK, look at file
+    my $path  = $url->local_path;
+
+    # test file exists and is readable
+    unless (-e $path) {
+	return new HTTP::Response &HTTP::Status::RC_NOT_FOUND,
+				  "File `$path' does not exist";
+    }
+    unless (-r _) {
+	return new HTTP::Response &HTTP::Status::RC_FORBIDDEN,
+				  'User does not have read permission';
+    }
+
+    # looks like file exists
+    my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$filesize,
+       $atime,$mtime,$ctime,$blksize,$blocks)
+	    = stat(_);
+
+    # XXX should check Accept headers?
+
+    # check if-modified-since
+    my $ims = $request->header('If-Modified-Since');
+    if (defined $ims) {
+	my $time = HTTP::Date::str2time($ims);
+	if (defined $time and $time >= $mtime) {
+	    return new HTTP::Response &HTTP::Status::RC_NOT_MODIFIED,
+				      "$method $path";
+	}
+    }
+
+    # Ok, should be an OK response by now...
+    $response = new HTTP::Response &HTTP::Status::RC_OK;
+
+    # fill in response headers
+    $response->header('Last-Modified', HTTP::Date::time2str($mtime));
+
+    if (-d _) {         # If the path is a directory, process it
+	# generate the HTML for directory
+	opendir(D, $path) or
+	   return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+				     "Cannot read directory '$path': $!";
+	my(@files) = sort readdir(D);
+	closedir(D);
+
+	# Make directory listing
+	for (@files) {
+	    $_ .= "/" if -d "$path/$_";
+	    my $furl = URI::Escape::uri_escape($_);
+	    my $desc = HTML::Entities::encode($_);
+	    $_ = qq{<LI><A HREF="$furl">$desc</A>};
+	}
+	# Ensure that the base URL is "/" terminated
+	my $base = $url->clone;
+	unless ($base->epath =~ m|/$|) {
+	    $base->epath($base->epath . "/");
+	}
+	my $html = join("\n",
+			"<HTML>\n<HEAD>",
+			"<TITLE>Directory $path</TITLE>",
+			"<BASE HREF=\"$base\">",
+			"</HEAD>\n<BODY>",
+			"<H1>Directory listing of $path</H1>",
+			"<UL>", @files, "</UL>",
+			"</BODY>\n</HTML>\n");
+
+	$response->header('Content-Type',   'text/html');
+	$response->header('Content-Length', length $html);
+
+	return $self->collect_once($arg, $response, $html);
+
+    } else {            # path is a regular file
+	my($type, @enc) = LWP::MediaTypes::guess_media_type($path);
+	$response->header('Content-Type',   $type) if $type;
+	$response->header('Content-Length', $filesize);
+	for (@enc) {
+	    $response->push_header('Content-Encoding', $_);
+	}
+
+	# read the file
+	open(F, $path) or return new
+	   HTTP::Response(&HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+			  "Cannot read file '$path': $!");
+	$response =  $self->collect($arg, $response, sub {
+	    my $content = "";
+	    my $bytes = sysread(F, $content, $size);
+	    return \$content if $bytes > 0;
+	    return \ "";
+	});
+	close(F);
+    }
+
+    $response;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/ftp.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/ftp.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/ftp.pm	(revision 16571)
@@ -0,0 +1,396 @@
+#
+# $Id$
+
+# Implementation of the ftp protocol (RFC 959). We let the Net::FTP
+# package do all the dirty work.
+
+package LWP::Protocol::ftp;
+
+use Carp ();
+
+use HTTP::Status ();
+use HTTP::Negotiate ();
+use HTTP::Response ();
+use LWP::MediaTypes ();
+use File::Listing ();
+
+require LWP::Protocol;
+@ISA = qw(LWP::Protocol);
+
+use strict;
+eval {
+    require Net::FTP;
+    Net::FTP->require_version(2.00);
+};
+my $init_failed = $@;
+
+
+sub request
+{
+    my($self, $request, $proxy, $arg, $size, $timeout) = @_;
+
+    $size = 4096 unless $size;
+
+    LWP::Debug::trace('()');
+
+    # check proxy
+    if (defined $proxy)
+    {
+	return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+				   'You can not proxy through the ftp');
+    }
+
+    my $url = $request->url;
+    if ($url->scheme ne 'ftp') {
+	my $scheme = $url->scheme;
+	return HTTP::Response->new(&HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+		       "LWP::Protocol::ftp::request called for '$scheme'");
+    }
+
+    # check method
+    my $method = $request->method;
+
+    unless ($method eq 'GET' || $method eq 'HEAD' || $method eq 'PUT') {
+	return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+				   'Library does not allow method ' .
+				   "$method for 'ftp:' URLs");
+    }
+
+    if ($init_failed) {
+	return HTTP::Response->new(&HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+				   $init_failed);
+    }
+
+    my $host     = $url->host;
+    my $port     = $url->port;
+    my $user     = $url->user;
+    my $password = $url->password;
+
+    # If a basic autorization header is present than we prefer these over
+    # the username/password specified in the URL.
+    {
+	my($u,$p) = $request->authorization_basic;
+	if (defined $u) {
+	    $user = $u;
+	    $password = $p;
+	}
+    }
+
+    # We allow the account to be specified in the "Account" header
+    my $acct     = $request->header('Account');
+
+    # try to make a connection
+    my $ftp = Net::FTP->new($host, Port => $port);
+    unless ($ftp) {
+       $@ =~ s/^Net::FTP: //;
+       return HTTP::Response->new(&HTTP::Status::RC_INTERNAL_SERVER_ERROR, $@);
+    }
+
+    # Create an initial response object
+    my $response = HTTP::Response->new(&HTTP::Status::RC_OK,
+				       "Document follows");
+    $response->request($request);
+
+    my $mess = $ftp->message;  # welcome message
+    LWP::Debug::debug($mess);
+    $mess =~ s|\n.*||s; # only first line left
+    $mess =~ s|\s*ready\.?$||;
+    # Make the version number more HTTP like
+    $mess =~ s|\s*\(Version\s*|/| and $mess =~ s|\)$||;
+    $response->header("Server", $mess);
+
+    $ftp->timeout($timeout) if $timeout;
+
+    LWP::Debug::debug("Logging in as $user (password $password)...");
+    unless ($ftp->login($user, $password, $acct)) {
+	# Unauthorized.  Let's fake a RC_UNAUTHORIZED response
+	my $res =  HTTP::Response->new(&HTTP::Status::RC_UNAUTHORIZED,
+				       scalar($ftp->message));
+	$res->header("WWW-Authenticate", qq(Basic Realm="FTP login"));
+	return $res;
+    }
+    LWP::Debug::debug($ftp->message);
+
+    # Get & fix the path
+    my @path =  $url->path_components;
+    shift(@path);  # There will always be an empty first component
+    pop(@path) while @path && $path[-1] eq '';  # remove empty tailing comps
+    my $remote_file = pop(@path);
+    $remote_file = '' unless defined $remote_file;
+
+    my $params = $url->params;
+    if (defined($params) && $params eq 'type=a') {
+	$ftp->ascii;
+    } else {
+	$ftp->binary;
+    }
+
+    for (@path) {
+	LWP::Debug::debug("CWD $_");
+	unless ($ftp->cwd($_)) {
+	    return HTTP::Response->new(&HTTP::Status::RC_NOT_FOUND,
+				       "Can't chdir to $_");
+	}
+    }
+
+    if ($method eq 'GET' || $method eq 'HEAD') {
+	LWP::Debug::debug("MDTM");
+	if (my $mod_time = $ftp->mdtm($remote_file)) {
+	    $response->last_modified($mod_time);
+	    if (my $ims = $request->if_modified_since) {
+		if ($mod_time <= $ims) {
+		    $response->code(&HTTP::Status::RC_NOT_MODIFIED);
+		    $response->message("Not modified");
+		    return $response;
+		}
+	    }
+	}
+
+	my $data;  # the data handle
+	LWP::Debug::debug("retrieve file?");
+	if (length($remote_file) and $data = $ftp->retr($remote_file)) {
+	    my($type, @enc) = LWP::MediaTypes::guess_media_type($remote_file);
+	    $response->header('Content-Type',   $type) if $type;
+	    for (@enc) {
+		$response->push_header('Content-Encoding', $_);
+	    }
+	    my $mess = $ftp->message;
+	    LWP::Debug::debug($mess);
+	    if ($mess =~ /\((\d+)\s+bytes\)/) {
+		$response->header('Content-Length', "$1");
+	    }
+
+	    if ($method ne 'HEAD') {
+		# Read data from server
+		$response = $self->collect($arg, $response, sub {
+		    my $content = '';
+		    my $result = $data->read($content, $size);
+		    return \$content;
+		} );
+	    }
+	    unless ($data->close) {
+		# Something did not work too well
+		if ($method ne 'HEAD') {
+		    $response->code(&HTTP::Status::RC_INTERNAL_SERVER_ERROR);
+		    $response->message("FTP close response: " . $ftp->code .
+				       " " . $ftp->message);
+		}
+	    }
+	} elsif (!length($remote_file) || $ftp->code == 550) {
+	    # 550 not a plain file, try to list instead
+	    if (length($remote_file) && !$ftp->cwd($remote_file)) {
+		LWP::Debug::debug("chdir before listing failed");
+		return HTTP::Response->new(&HTTP::Status::RC_NOT_FOUND,
+					   "File '$remote_file' not found");
+	    }
+
+	    # It should now be safe to try to list the directory
+	    LWP::Debug::debug("dir");
+	    my @lsl = $ftp->dir;
+
+	    # Try to figure out if the user want us to convert the
+	    # directory listing to HTML.
+	    my @variants =
+	      (
+	       ['html',  0.60, 'text/html'            ],
+	       ['dir',   1.00, 'text/ftp-dir-listing' ]
+	      );
+	    #$HTTP::Negotiate::DEBUG=1;
+	    my $prefer = HTTP::Negotiate::choose(\@variants, $request);
+
+	    my $content = '';
+
+	    if (!defined($prefer)) {
+		return HTTP::Response->new(&HTTP::Status::RC_NOT_ACCEPTABLE,
+			       "Neither HTML nor directory listing wanted");
+	    } elsif ($prefer eq 'html') {
+		$response->header('Content-Type' => 'text/html');
+		$content = "<HEAD><TITLE>File Listing</TITLE>\n";
+		my $base = $request->url->clone;
+		my $path = $base->epath;
+		$base->epath("$path/") unless $path =~ m|/$|;
+		$content .= qq(<BASE HREF="$base">\n</HEAD>\n);
+		$content .= "<BODY>\n<UL>\n";
+		for (File::Listing::parse_dir(\@lsl, 'GMT')) {
+		    my($name, $type, $size, $mtime, $mode) = @$_;
+		    $content .= qq(  <LI> <a href="$name">$name</a>);
+		    $content .= " $size bytes" if $type eq 'f';
+		    $content .= "\n";
+		}
+		$content .= "</UL></body>\n";
+	    } else {
+		$response->header('Content-Type', 'text/ftp-dir-listing');
+		$content = join("\n", @lsl, '');
+	    }
+
+	    $response->header('Content-Length', length($content));
+
+	    if ($method ne 'HEAD') {
+		$response = $self->collect_once($arg, $response, $content);
+	    }
+	} else {
+	    my $res = HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+			  "FTP return code " . $ftp->code);
+	    $res->content_type("text/plain");
+	    $res->content($ftp->message);
+	    return $res;
+	}
+    } elsif ($method eq 'PUT') {
+	# method must be PUT
+	unless (length($remote_file)) {
+	    return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+				       "Must have a file name to PUT to");
+	}
+	my $data;
+	if ($data = $ftp->stor($remote_file)) {
+	    LWP::Debug::debug($ftp->message);
+	    LWP::Debug::debug("$data");
+	    my $content = $request->content;
+	    my $bytes = 0;
+	    if (defined $content) {
+		if (ref($content) eq 'SCALAR') {
+		    $bytes = $data->write($$content, length($$content));
+		} elsif (ref($content) eq 'CODE') {
+		    my($buf, $n);
+		    while (length($buf = &$content)) {
+			$n = $data->write($buf, length($buf));
+			last unless $n;
+			$bytes += $n;
+		    }
+		} elsif (!ref($content)) {
+		    if (defined $content && length($content)) {
+			$bytes = $data->write($content, length($content));
+		    }
+		} else {
+		    die "Bad content";
+		}
+	    }
+	    $data->close;
+	    LWP::Debug::debug($ftp->message);
+
+	    $response->code(&HTTP::Status::RC_CREATED);
+	    $response->header('Content-Type', 'text/plain');
+	    $response->content("$bytes bytes stored as $remote_file on $host\n")
+
+	} else {
+	    my $res = HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+					  "FTP return code " . $ftp->code);
+	    $res->content_type("text/plain");
+	    $res->content($ftp->message);
+	    return $res;
+	}
+    } else {
+	return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+				   "Illegal method $method");
+    }
+
+    $response;
+}
+
+1;
+
+__END__
+
+# This is what RFC 1738 has to say about FTP access:
+# --------------------------------------------------
+#
+# 3.2. FTP
+#
+#    The FTP URL scheme is used to designate files and directories on
+#    Internet hosts accessible using the FTP protocol (RFC959).
+#
+#    A FTP URL follow the syntax described in Section 3.1.  If :<port> is
+#    omitted, the port defaults to 21.
+#
+# 3.2.1. FTP Name and Password
+#
+#    A user name and password may be supplied; they are used in the ftp
+#    "USER" and "PASS" commands after first making the connection to the
+#    FTP server.  If no user name or password is supplied and one is
+#    requested by the FTP server, the conventions for "anonymous" FTP are
+#    to be used, as follows:
+#
+#         The user name "anonymous" is supplied.
+#
+#         The password is supplied as the Internet e-mail address
+#         of the end user accessing the resource.
+#
+#    If the URL supplies a user name but no password, and the remote
+#    server requests a password, the program interpreting the FTP URL
+#    should request one from the user.
+#
+# 3.2.2. FTP url-path
+#
+#    The url-path of a FTP URL has the following syntax:
+#
+#         <cwd1>/<cwd2>/.../<cwdN>/<name>;type=<typecode>
+#
+#    Where <cwd1> through <cwdN> and <name> are (possibly encoded) strings
+#    and <typecode> is one of the characters "a", "i", or "d".  The part
+#    ";type=<typecode>" may be omitted. The <cwdx> and <name> parts may be
+#    empty. The whole url-path may be omitted, including the "/"
+#    delimiting it from the prefix containing user, password, host, and
+#    port.
+#
+#    The url-path is interpreted as a series of FTP commands as follows:
+#
+#       Each of the <cwd> elements is to be supplied, sequentially, as the
+#       argument to a CWD (change working directory) command.
+#
+#       If the typecode is "d", perform a NLST (name list) command with
+#       <name> as the argument, and interpret the results as a file
+#       directory listing.
+#
+#       Otherwise, perform a TYPE command with <typecode> as the argument,
+#       and then access the file whose name is <name> (for example, using
+#       the RETR command.)
+#
+#    Within a name or CWD component, the characters "/" and ";" are
+#    reserved and must be encoded. The components are decoded prior to
+#    their use in the FTP protocol.  In particular, if the appropriate FTP
+#    sequence to access a particular file requires supplying a string
+#    containing a "/" as an argument to a CWD or RETR command, it is
+#    necessary to encode each "/".
+#
+#    For example, the URL <URL:ftp://myname@host.dom/%2Fetc/motd> is
+#    interpreted by FTP-ing to "host.dom", logging in as "myname"
+#    (prompting for a password if it is asked for), and then executing
+#    "CWD /etc" and then "RETR motd". This has a different meaning from
+#    <URL:ftp://myname@host.dom/etc/motd> which would "CWD etc" and then
+#    "RETR motd"; the initial "CWD" might be executed relative to the
+#    default directory for "myname". On the other hand,
+#    <URL:ftp://myname@host.dom//etc/motd>, would "CWD " with a null
+#    argument, then "CWD etc", and then "RETR motd".
+#
+#    FTP URLs may also be used for other operations; for example, it is
+#    possible to update a file on a remote file server, or infer
+#    information about it from the directory listings. The mechanism for
+#    doing so is not spelled out here.
+#
+# 3.2.3. FTP Typecode is Optional
+#
+#    The entire ;type=<typecode> part of a FTP URL is optional. If it is
+#    omitted, the client program interpreting the URL must guess the
+#    appropriate mode to use. In general, the data content type of a file
+#    can only be guessed from the name, e.g., from the suffix of the name;
+#    the appropriate type code to be used for transfer of the file can
+#    then be deduced from the data content of the file.
+#
+# 3.2.4 Hierarchy
+#
+#    For some file systems, the "/" used to denote the hierarchical
+#    structure of the URL corresponds to the delimiter used to construct a
+#    file name hierarchy, and thus, the filename will look similar to the
+#    URL path. This does NOT mean that the URL is a Unix filename.
+#
+# 3.2.5. Optimization
+#
+#    Clients accessing resources via FTP may employ additional heuristics
+#    to optimize the interaction. For some FTP servers, for example, it
+#    may be reasonable to keep the control connection open while accessing
+#    multiple URLs from the same server. However, there is no common
+#    hierarchical model to the FTP protocol, so if a directory change
+#    command has been given, it is impossible in general to deduce what
+#    sequence should be given to navigate to another directory for a
+#    second retrieval, if the paths are different.  The only reliable
+#    algorithm is to disconnect and reestablish the control connection.
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/gopher.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/gopher.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/gopher.pm	(revision 16571)
@@ -0,0 +1,215 @@
+#
+# $Id$
+
+# Implementation of the gopher protocol (RFC 1436)
+#
+# This code is based on 'wwwgopher.pl,v 0.10 1994/10/17 18:12:34 shelden'
+# which in turn is a vastly modified version of Oscar's http'get()
+# dated 28/3/94 in <ftp://cui.unige.ch/PUBLIC/oscar/scripts/http.pl>
+# including contributions from Marc van Heyningen and Martijn Koster.
+#
+
+package LWP::Protocol::gopher;
+
+use strict;
+use vars qw(@ISA);
+
+require HTTP::Response;
+require HTTP::Status;
+require IO::Socket;
+require IO::Select;
+
+require LWP::Protocol;
+@ISA = qw(LWP::Protocol);
+
+
+my %gopher2mimetype = (
+    '0' => 'text/plain',                # 0 file
+    '1' => 'text/html',                 # 1 menu
+					# 2 CSO phone-book server
+					# 3 Error
+    '4' => 'application/mac-binhex40',  # 4 BinHexed Macintosh file
+    '5' => 'application/zip',           # 5 DOS binary archive of some sort
+    '6' => 'application/octet-stream',  # 6 UNIX uuencoded file.
+    '7' => 'text/html',                 # 7 Index-Search server
+					# 8 telnet session
+    '9' => 'application/octet-stream',  # 9 binary file
+    'h' => 'text/html',                 # html
+    'g' => 'image/gif',                 # gif
+    'I' => 'image/*',                   # some kind of image
+);
+
+my %gopher2encoding = (
+    '6' => 'x_uuencode',                # 6 UNIX uuencoded file.
+);
+
+sub request
+{
+    my($self, $request, $proxy, $arg, $size, $timeout) = @_;
+
+    LWP::Debug::trace('()');
+
+    $size = 4096 unless $size;
+
+    # check proxy
+    if (defined $proxy) {
+	return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+				   'You can not proxy through the gopher');
+    }
+
+    my $url = $request->url;
+    die "bad scheme" if $url->scheme ne 'gopher';
+
+
+    my $method = $request->method;
+    unless ($method eq 'GET' || $method eq 'HEAD') {
+	return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+				   'Library does not allow method ' .
+				   "$method for 'gopher:' URLs");
+    }
+
+    my $gophertype = $url->gtype;
+    unless (exists $gopher2mimetype{$gophertype}) {
+	return HTTP::Response->new(&HTTP::Status::RC_NOT_IMPLEMENTED,
+				   'Library does not support gophertype ' .
+				   $gophertype);
+    }
+
+    my $response = HTTP::Response->new(&HTTP::Status::RC_OK, "OK");
+    $response->header('Content-type' => $gopher2mimetype{$gophertype}
+					|| 'text/plain');
+    $response->header('Content-Encoding' => $gopher2encoding{$gophertype})
+	if exists $gopher2encoding{$gophertype};
+
+    if ($method eq 'HEAD') {
+	# XXX: don't even try it so we set this header
+	$response->header('Client-Warning' => 'Client answer only');
+	return $response;
+    }
+    
+    if ($gophertype eq '7' && ! $url->search) {
+      # the url is the prompt for a gopher search; supply boiler-plate
+      return $self->collect_once($arg, $response, <<"EOT");
+<HEAD>
+<TITLE>Gopher Index</TITLE>
+<ISINDEX>
+</HEAD>
+<BODY>
+<H1>$url<BR>Gopher Search</H1>
+This is a searchable Gopher index.
+Use the search function of your browser to enter search terms.
+</BODY>
+EOT
+    }
+
+    my $host = $url->host;
+    my $port = $url->port;
+
+    my $requestLine = "";
+
+    my $selector = $url->selector;
+    if (defined $selector) {
+	$requestLine .= $selector;
+	my $search = $url->search;
+	if (defined $search) {
+	    $requestLine .= "\t$search";
+	    my $string = $url->string;
+	    if (defined $string) {
+		$requestLine .= "\t$string";
+	    }
+	}
+    }
+    $requestLine .= "\015\012";
+
+    # potential request headers are just ignored
+
+    # Ok, lets make the request
+    my $socket = IO::Socket::INET->new(PeerAddr => $host,
+				       PeerPort => $port,
+				       Timeout  => $timeout);
+    die "Can't connect to $host:$port" unless $socket;
+    my $sel = IO::Select->new($socket);
+
+    {
+	die "write timeout" if $timeout && !$sel->can_write($timeout);
+	my $n = syswrite($socket, $requestLine, length($requestLine));
+	die $! unless defined($n);
+	die "short write" if $n != length($requestLine);
+    }
+
+    my $user_arg = $arg;
+
+    # must handle menus in a special way since they are to be
+    # converted to HTML.  Undefing $arg ensures that the user does
+    # not see the data before we get a change to convert it.
+    $arg = undef if $gophertype eq '1' || $gophertype eq '7';
+
+    # collect response
+    my $buf = '';
+    $response = $self->collect($arg, $response, sub {
+	die "read timeout" if $timeout && !$sel->can_read($timeout);
+        my $n = sysread($socket, $buf, $size);
+	die $! unless defined($n);
+	return \$buf;
+      } );
+
+    # Convert menu to HTML and return data to user.
+    if ($gophertype eq '1' || $gophertype eq '7') {
+	my $content = menu2html($response->content);
+	if (defined $user_arg) {
+	    $response = $self->collect_once($user_arg, $response, $content);
+	} else {
+	    $response->content($content);
+	}
+    }
+
+    $response;
+}
+
+
+sub gopher2url
+{
+    my($gophertype, $path, $host, $port) = @_;
+
+    my $url;
+
+    if ($gophertype eq '8' || $gophertype eq 'T') {
+	# telnet session
+	$url = URI::URL->new($gophertype eq '8' ? 'telnet:' : 'tn3270:');
+	$url->user($path) if defined $path;
+    } else {
+	$path = URI::Escape::uri_escape($path);
+	$url = URI::URL->new("gopher:/$gophertype$path");
+    }
+    $url->host($host);
+    $url->port($port);
+    $url;
+}
+
+sub menu2html {
+    my($menu) = @_;
+
+    $menu =~ s/\015//g;  # remove carriage return
+    my $tmp = <<"EOT";
+<HTML>
+<HEAD>
+   <TITLE>Gopher menu</TITLE>
+</HEAD>
+<BODY>
+<H1>Gopher menu</H1>
+EOT
+    for (split("\n", $menu)) {
+	last if /^\./;
+	my($pretty, $path, $host, $port) = split("\t");
+
+	$pretty =~ s/^(.)//;
+	my $type = $1;
+
+	my $url = gopher2url($type, $path, $host, $port)->as_string;
+	$tmp .= qq{<A HREF="$url">$pretty</A><BR>\n};
+    }
+    $tmp .= "</BODY>\n</HTML>\n";
+    $tmp;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/http.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/http.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/http.pm	(revision 16571)
@@ -0,0 +1,252 @@
+#
+# $Id$
+
+package LWP::Protocol::http;
+
+require LWP::Debug;
+require HTTP::Response;
+require HTTP::Status;
+require IO::Socket;
+require IO::Select;
+
+require LWP::Protocol;
+@ISA = qw(LWP::Protocol);
+
+use strict;
+my $CRLF         = "\015\012";     # how lines should be terminated;
+				   # "\r\n" is not correct on all systems, for
+				   # instance MacPerl defines it to "\012\015"
+
+sub _new_socket
+{
+    my($self, $host, $port, $timeout) = @_;
+
+    local($^W) = 0;  # IO::Socket::INET can be noisy
+    my $sock = IO::Socket::INET->new(PeerAddr => $host,
+				     PeerPort => $port,
+				     Proto    => 'tcp',
+				     Timeout  => $timeout,
+				    );
+    unless ($sock) {
+	# IO::Socket::INET leaves additional error messages in $@
+	$@ =~ s/^.*?: //;
+	die "Can't connect to $host:$port ($@)";
+    }
+    $sock;
+}
+
+
+sub _check_sock
+{
+    #my($self, $req, $sock) = @_;
+}
+
+sub _get_sock_info
+{
+    my($self, $res, $sock) = @_;
+    $res->header("Client-Peer" =>
+		 $sock->peerhost . ":" . $sock->peerport);
+}
+
+
+sub request
+{
+    my($self, $request, $proxy, $arg, $size, $timeout) = @_;
+    LWP::Debug::trace('()');
+
+    $size ||= 4096;
+
+    # check method
+    my $method = $request->method;
+    unless ($method =~ /^[A-Za-z0-9_!\#\$%&\'*+\-.^\`|~]+$/) {  # HTTP token
+	return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
+				  'Library does not allow method ' .
+				  "$method for 'http:' URLs";
+    }
+
+    my $url = $request->url;
+    my($host, $port, $fullpath);
+
+    # Check if we're proxy'ing
+    if (defined $proxy) {
+	# $proxy is an URL to an HTTP server which will proxy this request
+	$host = $proxy->host;
+	$port = $proxy->port;
+	$fullpath = $url->as_string;
+    }
+    else {
+	$host = $url->host;
+	$port = $url->port;
+	$fullpath = $url->full_path;
+    }
+
+    # connect to remote site
+    my $socket = $self->_new_socket($host, $port, $timeout);
+    $self->_check_sock($request, $socket);
+	    
+    my $sel = IO::Select->new($socket) if $timeout;
+
+    my $request_line = "$method $fullpath HTTP/1.0$CRLF";
+
+    my $h = $request->headers->clone;
+    my $cont_ref = $request->content_ref;
+    $cont_ref = $$cont_ref if ref($$cont_ref);
+    my $ctype = ref($cont_ref);
+
+    # If we're sending content we *have* to specify a content length
+    # otherwise the server won't know a messagebody is coming.
+    if ($ctype eq 'CODE') {
+	die 'No Content-Length header for request with dynamic content'
+	    unless defined($h->header('Content-Length')) ||
+		   $h->content_type =~ /^multipart\//;
+	# For HTTP/1.1 we could have used chunked transfer encoding...
+    } else {
+	$h->header('Content-Length' => length $$cont_ref)
+	        if defined($$cont_ref) && length($$cont_ref);
+    }
+    
+    # HTTP/1.1 will require us to send the 'Host' header, so we might
+    # as well start now.
+    my $hhost = $url->netloc;
+    $hhost =~ s/^([^\@]*)\@//;  # get rid of potential "user:pass@"
+    $h->header('Host' => $hhost) unless defined $h->header('Host');
+
+    # add authorization header if we need them.  HTTP URLs do
+    # not really support specification of user and password, but
+    # we allow it.
+    if (defined($1) && not $h->header('Authorization')) {
+	$h->authorization_basic($url->user, $url->password);
+    }
+
+    my $buf = $request_line . $h->as_string($CRLF) . $CRLF;
+    my $n;  # used for return value from syswrite/sysread
+
+    die "write timeout" if $timeout && !$sel->can_write($timeout);
+    $n = $socket->syswrite($buf, length($buf));
+    die $! unless defined($n);
+    die "short write" unless $n == length($buf);
+    LWP::Debug::conns($buf);
+
+    if ($ctype eq 'CODE') {
+	while ( ($buf = &$cont_ref()), defined($buf) && length($buf)) {
+	    die "write timeout" if $timeout && !$sel->can_write($timeout);
+	    $n = $socket->syswrite($buf, length($buf));
+	    die $! unless defined($n);
+	    die "short write" unless $n == length($buf);
+	    LWP::Debug::conns($buf);
+	}
+    } elsif (defined($$cont_ref) && length($$cont_ref)) {
+	die "write timeout" if $timeout && !$sel->can_write($timeout);
+	$n = $socket->syswrite($$cont_ref, length($$cont_ref));
+	die $! unless defined($n);
+	die "short write" unless $n == length($$cont_ref);
+	LWP::Debug::conns($buf);
+    }
+    
+    # read response line from server
+    LWP::Debug::debug('reading response');
+
+    my $response;
+    $buf = '';
+
+    # Inside this loop we will read the response line and all headers
+    # found in the response.
+    while (1) {
+	{
+	    die "read timeout" if $timeout && !$sel->can_read($timeout);
+	    $n = $socket->sysread($buf, $size, length($buf));
+	    die $! unless defined($n);
+	    die "unexpected EOF before status line seen" unless $n;
+	    LWP::Debug::conns($buf);
+	}
+	if ($buf =~ s/^(HTTP\/\d+\.\d+)[ \t]+(\d+)[ \t]*([^\012]*)\012//) {
+	    # HTTP/1.0 response or better
+	    my($ver,$code,$msg) = ($1, $2, $3);
+	    $msg =~ s/\015$//;
+	    LWP::Debug::debug("$ver $code $msg");
+	    $response = HTTP::Response->new($code, $msg);
+	    $response->protocol($ver);
+
+	    # ensure that we have read all headers.  The headers will be
+	    # terminated by two blank lines
+	    until ($buf =~ /^\015?\012/ || $buf =~ /\015?\012\015?\012/) {
+		# must read more if we can...
+		LWP::Debug::debug("need more header data");
+		die "read timeout" if $timeout && !$sel->can_read($timeout);
+		$n = $socket->sysread($buf, $size, length($buf));
+		die $! unless defined($n);
+		die "unexpected EOF before all headers seen" unless $n;
+		#LWP::Debug::conns($buf);
+	    }
+
+	    # now we start parsing the headers.  The strategy is to
+	    # remove one line at a time from the beginning of the header
+	    # buffer ($res).
+	    my($key, $val);
+	    while ($buf =~ s/([^\012]*)\012//) {
+		my $line = $1;
+
+		# if we need to restore as content when illegal headers
+		# are found.
+		my $save = "$line\012"; 
+
+		$line =~ s/\015$//;
+		last unless length $line;
+
+		if ($line =~ /^([a-zA-Z0-9_\-]+)\s*:\s*(.*)/) {
+		    $response->push_header($key, $val) if $key;
+		    ($key, $val) = ($1, $2);
+		} elsif ($line =~ /^\s+(.*)/) {
+		    unless ($key) {
+			$response->header("Client-Warning" =>
+					 => "Illegal continuation header");
+			$buf = "$save$buf";
+			last;
+		    }
+		    $val .= " $1";
+		} else {
+		    $response->header("Client-Warning" =>
+				      "Illegal header '$line'");
+		    $buf = "$save$buf";
+		    last;
+		}
+	    }
+	    $response->push_header($key, $val) if $key;
+	    last;
+
+	} elsif ((length($buf) >= 5 and $buf !~ /^HTTP\//) or
+		 $buf =~ /\012/ ) {
+	    # HTTP/0.9 or worse
+	    LWP::Debug::debug("HTTP/0.9 assume OK");
+	    $response = HTTP::Response->new(&HTTP::Status::RC_OK, "OK");
+	    $response->protocol('HTTP/0.9');
+	    last;
+
+	} else {
+	    # need more data
+	    LWP::Debug::debug("need more status line data");
+	}
+    };
+    $response->request($request);
+    $self->_get_sock_info($response, $socket);
+
+
+    my $usebuf = length($buf) > 0;
+    $response = $self->collect($arg, $response, sub {
+        if ($usebuf) {
+	    $usebuf = 0;
+	    return \$buf;
+	}
+	die "read timeout" if $timeout && !$sel->can_read($timeout);
+	my $n = $socket->sysread($buf, $size);
+	die $! unless defined($n);
+	#LWP::Debug::conns($buf);
+	return \$buf;
+	} );
+
+    $socket->close;
+
+    $response;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/https.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/https.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/https.pm	(revision 16571)
@@ -0,0 +1,59 @@
+#
+# $Id$
+
+use strict;
+
+package LWP::Protocol::https;
+require Net::SSL;  # from Crypt-SSLeay
+
+use vars qw(@ISA);
+
+require LWP::Protocol::http;
+@ISA=qw(LWP::Protocol::http);
+
+sub _new_socket
+{
+    my($self, $host, $port, $timeout) = @_;
+    local($^W) = 0;  # IO::Socket::INET can be noisy
+    my $sock = Net::SSL->new(PeerAddr => $host,
+			     PeerPort => $port,
+			     Proto    => 'tcp',
+			     Timeout  => $timeout,
+			    );
+    unless ($sock) {
+	# IO::Socket::INET leaves additional error messages in $@
+	$@ =~ s/^.*?: //;
+	die "Can't connect to $host:$port ($@)";
+    }
+    $sock;
+}
+
+sub _check_sock
+{
+    my($self, $req, $sock) = @_;
+    my $check = $req->header("If-SSL-Cert-Subject");
+    if (defined $check) {
+	my $cert = $sock->get_peer_certificate ||
+	    die "Missing SSL certificate";
+	my $subject = $cert->subject_name;
+	die "Bad SSL certificate subject: '$subject' !~ /$check/"
+	    unless $subject =~ /$check/;
+	$req->remove_header("If-SSL-Cert-Subject");  # don't pass it on
+    }
+}
+
+sub _get_sock_info
+{
+    my $self = shift;
+    $self->SUPER::_get_sock_info(@_);
+    my($res, $sock) = @_;
+    $res->header("Client-SSL-Cipher" => $sock->get_cipher);
+    my $cert = $sock->get_peer_certificate;
+    if ($cert) {
+	$res->header("Client-SSL-Cert-Subject" => $cert->subject_name);
+	$res->header("Client-SSL-Cert-Issuer" => $cert->issuer_name);
+    }
+    $res->header("Client-SSL-Warning" => "Peer certificate not verified");
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/mailto.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/mailto.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/mailto.pm	(revision 16571)
@@ -0,0 +1,87 @@
+#
+# $Id$
+#
+# This module implements the mailto protocol.  It is just a simple
+# frontend to the Unix sendmail program.  In the long run this module
+# will built using the Mail::Send module.
+
+package LWP::Protocol::mailto;
+
+require LWP::Protocol;
+require HTTP::Request;
+require HTTP::Response;
+require HTTP::Status;
+
+use Carp;
+
+@ISA = qw(LWP::Protocol);
+
+$SENDMAIL = "/usr/lib/sendmail";
+
+
+sub request
+{
+    my($self, $request, $proxy, $arg, $size) = @_;
+
+    # check proxy
+    if (defined $proxy)
+    {
+	return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
+				  'You can not proxy with mail';
+    }
+
+    # check method
+    $method = $request->method;
+
+    if ($method ne 'POST') {
+	return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
+				  'Library does not allow method ' .
+				  "$method for 'mailto:' URLs";
+    }
+
+    # check url
+    my $url = $request->url;
+
+    my $scheme = $url->scheme;
+    if ($scheme ne 'mailto') {
+	return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+				  "LWP::file::request called for '$scheme'";
+    }
+    unless (-x $SENDMAIL) {
+	return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+				  "You don't have $SENDMAIL";
+    }
+
+    open(SENDMAIL, "| $SENDMAIL -oi -t") or
+	return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+				  "Can't run $SENDMAIL: $!";
+
+    my $addr = $url->encoded822addr;
+
+    $request->header('To', $addr);
+    print SENDMAIL $request->headers_as_string;
+    print SENDMAIL "\n";
+    my $content = $request->content;
+    if (defined $content) {
+	my $contRef = ref($content) ? $content : \$content;
+	if (ref($contRef) eq 'SCALAR') {
+	    print SENDMAIL $$contRef;
+	} elsif (ref($contRef) eq 'CODE') {
+	    # Callback provides data
+	    my $d;
+	    while (length($d = &$contRef)) {
+		print SENDMAIL $d;
+	    }
+	}
+    }
+    close(SENDMAIL);
+
+    my $response = new HTTP::Response &HTTP::Status::RC_ACCEPTED,
+				     'Mail accepted by sendmail';
+    $response->header('Content-Type', 'text/plain');
+    $response->content("Mail sent to <$addr>\n");
+
+    return $response;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/nntp.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/nntp.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Protocol/nntp.pm	(revision 16571)
@@ -0,0 +1,142 @@
+#
+# $Id$
+
+# Implementation of the Network News Transfer Protocol (RFC 977)
+#
+
+package LWP::Protocol::nntp;
+
+require LWP::Protocol;
+@ISA = qw(LWP::Protocol);
+
+require LWP::Debug;
+require HTTP::Response;
+require HTTP::Status;
+require Net::NNTP;
+
+use strict;
+
+
+sub request
+{
+    my($self, $request, $proxy, $arg, $size, $timeout) = @_;
+
+    LWP::Debug::trace('()');
+
+    $size = 4096 unless $size;
+
+    # Check for proxy
+    if (defined $proxy) {
+	return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+				   'You can not proxy through NNTP');
+    }
+
+    # Check that the scheme is as expected
+    my $url = $request->url;
+    my $scheme = $url->scheme;
+    unless ($scheme eq 'news') {
+	return HTTP::Response->new(&HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+				   "LWP::Protocol::nntp::request called for '$scheme'");
+    }
+
+    # check for a valid method
+    my $method = $request->method;
+    unless ($method eq 'GET' || $method eq 'HEAD' || $method eq 'POST') {
+	return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+				   'Library does not allow method ' .
+				   "$method for 'news:' URLs");
+    }
+
+    # extract the identifier and check against posting to an article
+    my $groupart = $url->groupart;
+    my $is_art = $groupart =~ /@/;
+
+    if ($is_art && $method eq 'POST') {
+	return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
+				   "Can't post to an article <$groupart>");
+    }
+
+    my $nntp = Net::NNTP->new(undef,
+			      #Port    => 18574,
+			      Timeout => $timeout,
+			      #Debug   => 1,
+			     );
+    die "Can't connect to nntp server" unless $nntp;
+
+    # Check the initial welcome message from the NNTP server
+    if ($nntp->status != 2) {
+	return HTTP::Response->new(&HTTP::Status::RC_SERVICE_UNAVAILABLE,
+				   $nntp->message);
+    }
+    my $response = HTTP::Response->new(&HTTP::Status::RC_OK, "OK");
+
+    my $mess = $nntp->message;
+    LWP::Debug::debug($mess);
+
+    # Try to extract server name from greating message.
+    # Don't know if this works well for a large class of servers, but
+    # this works for our server.
+    $mess =~ s/\s+ready\b.*//;
+    $mess =~ s/^\S+\s+//;
+    $response->header(Server => $mess);
+
+
+    # First we handle posting of articles
+    if ($method eq 'POST') {
+	return HTTP::Response->new(&HTTP::Status::RC_NOT_IMPLEMENTED,
+				   "POST not implemented yet");
+    }
+
+    # The method must be "GET" or "HEAD" by now
+    if (!$is_art) {
+	if (!$nntp->group($groupart)) {
+	    return HTTP::Response->new(&HTTP::Status::RC_NOT_FOUND,
+				       $nntp->message);
+	}
+	return HTTP::Response->new(&HTTP::Status::RC_NOT_IMPLEMENTED,
+				   "GET newsgroup not implemented yet");
+    }
+
+    # Send command to server to retrieve an article (or just the headers)
+    my $get = $method eq 'HEAD' ? "head" : "article";
+    my $art = $nntp->$get("<$groupart>");
+    unless ($art) {
+	return HTTP::Response->new(&HTTP::Status::RC_NOT_FOUND,
+				   $nntp->message);
+    }
+    LWP::Debug::debug($nntp->message);
+    
+    # Parse headers
+    my($key, $val);
+    while ($_ = shift @$art) {
+	if (/^\s+$/) {
+	    last;  # end of headers
+	} elsif (/^(\S+):\s*(.*)/) {
+	    $response->push_header($key, $val) if $key;
+	    ($key, $val) = ($1, $2);
+	} elsif (/^\s+(.*)/) {
+	    next unless $key;
+	    $val .= $1;
+	} else {
+	    unshift(@$art, $_);
+	    last;
+	}
+    }
+    $response->push_header($key, $val) if $key;
+
+    # Ensure that there is a Content-Type header
+    $response->header("Content-Type", "text/plain")
+	unless $response->header("Content-Type");
+
+    # Collect the body
+    $response = $self->collect_once($arg, $response, join("", @$art))
+      if @$art;
+
+    # Say godbye to the server
+    $nntp->quit;
+    $nntp = undef;
+
+    $response;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/RobotUA.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/RobotUA.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/RobotUA.pm	(revision 16571)
@@ -0,0 +1,285 @@
+# $Id$
+
+package LWP::RobotUA;
+
+require LWP::UserAgent;
+@ISA = qw(LWP::UserAgent);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+require WWW::RobotRules;
+require HTTP::Request;
+require HTTP::Response;
+
+use Carp ();
+use LWP::Debug ();
+use HTTP::Status ();
+use HTTP::Date qw(time2str);
+use strict;
+
+=head1 NAME
+
+LWP::RobotUA - A class for Web Robots
+
+=head1 SYNOPSIS
+
+  require LWP::RobotUA;
+  $ua = new LWP::RobotUA 'my-robot/0.1', 'me@foo.com';
+  $ua->delay(10);  # be very nice, go slowly
+  ...
+  # just use it just like a normal LWP::UserAgent
+  $res = $ua->request($req);
+
+=head1 DESCRIPTION
+
+This class implements a user agent that is suitable for robot
+applications.  Robots should be nice to the servers they visit.  They
+should consult the F<robots.txt> file to ensure that they are welcomed
+and they should not send too frequent requests.
+
+But, before you consider writing a robot take a look at
+<URL:http://info.webcrawler.com/mak/projects/robots/robots.html>.
+
+When you use a I<LWP::RobotUA> as your user agent, then you do not
+really have to think about these things yourself.  Just send requests
+as you do when you are using a normal I<LWP::UserAgent> and this
+special agent will make sure you are nice.
+
+=head1 METHODS
+
+The LWP::RobotUA is a sub-class of LWP::UserAgent and implements the
+same methods. In addition the following methods are provided:
+
+=over 4
+
+=cut
+
+
+#
+# Additional attributes in addition to those found in LWP::UserAgent:
+#
+# $self->{'delay'}    Required delay between request to the same
+#                     server in minutes.
+#
+# $self->{'rules'}     A WWW::RobotRules object
+#
+
+
+=item $ua = LWP::RobotUA->new($agent_name, $from, [$rules])
+
+Your robot's name and the mail address of the human responsible for
+the robot (i.e. you) is required by the constructor.
+
+Optionally it allows you to specify the I<WWW::RobotRules> object to
+use.
+
+=cut
+
+sub new
+{
+    my($class,$name,$from,$rules) = @_;
+
+    Carp::croak('LWP::RobotUA name required') unless $name;
+    Carp::croak('LWP::RobotUA from address required') unless $from;
+
+    my $self = new LWP::UserAgent;
+    $self = bless $self, $class;
+
+    $self->{'delay'} = 1;   # minutes
+    $self->{'agent'} = $name;
+    $self->{'from'}  = $from;
+    $self->{'use_sleep'} = 1;
+
+    if ($rules) {
+	$rules->agent($name);
+	$self->{'rules'} = $rules;
+    } else {
+	$self->{'rules'} = new WWW::RobotRules $name;
+    }
+
+    $self;
+}
+
+
+=item $ua->delay([$minutes])
+
+Set the minimum delay between requests to the same server.  The
+default is 1 minute.
+
+=item $ua->use_sleep([$boolean])
+
+Get/set a value indicating wether the UA should sleep() if request
+arrive to fast (before $ua->delay minutes has passed).  The default is
+TRUE.  If this value is FALSE then an internal SERVICE_UNAVAILABLE
+response will be generated.  It will have an Retry-After header that
+indicate when it is OK to send another request to this server.
+
+=cut
+
+sub delay     { shift->_elem('delay',     @_); }
+sub use_sleep { shift->_elem('use_sleep', @_); }
+
+sub agent
+{
+    my $self = shift;
+    my $old = $self->SUPER::agent(@_);
+    if (@_) {
+	# Changing our name means to start fresh
+	$self->{'rules'}->agent($self->{'agent'}); 
+    }
+    $old;
+}
+
+
+=item $ua->rules([$rules])
+
+Set/get which I<WWW::RobotRules> object to use. 
+
+=cut
+
+sub rules {
+    my $self = shift;
+    my $old = $self->_elem('rules', @_);
+    $self->{'rules'}->agent($self->{'agent'}) if @_;
+    $old;
+}
+
+
+=item $ua->no_visits($netloc)
+
+Returns the number of documents fetched from this server host. Yes I
+know, this method should probably have been named num_visits() or
+something like that :-(
+
+=cut
+
+sub no_visits
+{
+    my($self, $netloc) = @_;
+    $self->{'rules'}->no_visits($netloc);
+}
+
+*host_count = \&no_visits;  # backwards compatibility with LWP-5.02
+
+
+=item $ua->host_wait($netloc)
+
+Returns the number of seconds (from now) you must wait before you can
+make a new request to this host.
+
+=cut
+
+sub host_wait
+{
+    my($self, $netloc) = @_;
+    return undef unless defined $netloc;
+    my $last = $self->{'rules'}->last_visit($netloc);
+    if ($last) {
+	my $wait = int($self->{'delay'} * 60 - (time - $last));
+	$wait = 0 if $wait < 0;
+	return $wait;
+    }
+    return 0;
+}
+
+
+sub simple_request
+{
+    my($self, $request, $arg, $size) = @_;
+
+    LWP::Debug::trace('()');
+
+    # Do we try to access a new server?
+    my $allowed = $self->{'rules'}->allowed($request->url);
+
+    if ($allowed < 0) {
+	LWP::Debug::debug("Host is not visited before, or robots.txt expired.");
+	# fetch "robots.txt"
+	my $robot_url = $request->url->clone;
+	$robot_url->path("robots.txt");
+	$robot_url->params(undef);
+	$robot_url->query(undef);
+	LWP::Debug::debug("Requesting $robot_url");
+
+	# make access to robot.txt legal since this will be a recursive call
+	$self->{'rules'}->parse($robot_url, ""); 
+
+	my $robot_req = new HTTP::Request 'GET', $robot_url;
+	my $robot_res = $self->request($robot_req);
+	my $fresh_until = $robot_res->fresh_until;
+	if ($robot_res->is_success) {
+	    LWP::Debug::debug("Parsing robot rules");
+	    $self->{'rules'}->parse($robot_url, $robot_res->content, 
+				    $fresh_until);
+	} else {
+	    LWP::Debug::debug("No robots.txt file found");
+	    $self->{'rules'}->parse($robot_url, "", $fresh_until);
+	}
+
+	# recalculate allowed...
+	$allowed = $self->{'rules'}->allowed($request->url);
+    }
+
+    # Check rules
+    unless ($allowed) {
+	return new HTTP::Response
+	  &HTTP::Status::RC_FORBIDDEN, 'Forbidden by robots.txt';
+    }
+
+    my $netloc = $request->url->netloc;
+    my $wait = $self->host_wait($netloc);
+
+    if ($wait) {
+	LWP::Debug::debug("Must wait $wait seconds");
+	if ($self->{'use_sleep'}) {
+	    sleep($wait)
+	} else {
+	    my $res = new HTTP::Response
+	      &HTTP::Status::RC_SERVICE_UNAVAILABLE, 'Please, slow down';
+	    $res->header('Retry-After', time2str(time + $wait));
+	    return $res;
+	}
+    }
+
+    # Perform the request
+    my $res = $self->SUPER::simple_request($request, $arg, $size);
+
+    $self->{'rules'}->visit($netloc);
+
+    $res;
+}
+
+
+=item $ua->as_string
+
+Returns a text that describe the state of the UA.
+Mainly useful for debugging.
+
+=cut
+
+sub as_string
+{
+    my $self = shift;
+    my @s;
+    push(@s, "Robot: $self->{'agent'} operated by $self->{'from'}  [$self]");
+    push(@s, "    Minimum delay: " . int($self->{'delay'}*60) . "s");
+    push(@s, "    Will sleep if too early") if $self->{'use_sleep'};
+    push(@s, "    Rules = $self->{'rules'}");
+    join("\n", @s, '');
+}
+
+1;
+
+=back
+
+=head1 SEE ALSO
+
+L<LWP::UserAgent>, L<WWW::RobotRules>
+
+=head1 COPYRIGHT
+
+Copyright 1996-1997 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Simple.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Simple.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/Simple.pm	(revision 16571)
@@ -0,0 +1,329 @@
+#
+# $Id$
+
+=head1 NAME
+
+get, head, getprint, getstore, mirror - Procedural LWP interface
+
+=head1 SYNOPSIS
+
+ perl -MLWP::Simple -e 'getprint "http://www.sn.no"'
+
+ use LWP::Simple;
+ $content = get("http://www.sn.no/")
+ if (mirror("http://www.sn.no/", "foo") == RC_NOT_MODIFIED) {
+     ...
+ }
+
+ if (is_success(getprint("http://www.sn.no/"))) {
+     ...
+ }
+
+=head1 DESCRIPTION
+
+This interface is intended for those who want a simplified view of the
+libwww-perl library.  It should also be suitable for one-liners.  If
+you need more control or access to the header fields in the requests
+sent and responses received you should use the full object oriented
+interface provided by the C<LWP::UserAgent> module.
+
+The following functions are provided (and exported) by this module:
+
+=over 3
+
+=item get($url)
+
+The get() function will fetch the document identified by the given URL
+and return it.  It returns C<undef> if it fails.  The $url argument can
+be either a simple string or a reference to a URI::URL object.
+
+You will not be able to examine the response code or response headers
+(like 'Content-Type') when you are accessing the web using this
+function.  If you need this information you should use the full OO
+interface (see L<LWP::UserAgent>).
+
+=item head($url)
+
+Get document headers. Returns the following 5 values if successful:
+($content_type, $document_length, $modified_time, $expires, $server)
+
+Returns an empty list if it fails.  In scalar context returns TRUE if
+successful.
+
+=item getprint($url)
+
+Get and print a document identified by a URL. The document is printed
+on STDOUT as data is received from the network.  If the request fails,
+then the status code and message is printed on STDERR.  The return
+value is the HTTP response code.
+
+=item getstore($url, $file)
+
+Gets a document identified by a URL and stores it in the file. The
+return value is the HTTP response code.
+
+=item mirror($url, $file)
+
+Get and store a document identified by a URL, using
+I<If-modified-since>, and checking of the I<Content-Length>.  Returns
+the HTTP response code.
+
+=back
+
+This module also exports the HTTP::Status constants and procedures.
+These can be used when you check the response code from getprint(),
+getstore() and mirror().  The constants are:
+
+   RC_CONTINUE
+   RC_SWITCHING_PROTOCOLS
+   RC_OK
+   RC_CREATED
+   RC_ACCEPTED
+   RC_NON_AUTHORITATIVE_INFORMATION
+   RC_NO_CONTENT
+   RC_RESET_CONTENT
+   RC_PARTIAL_CONTENT
+   RC_MULTIPLE_CHOICES
+   RC_MOVED_PERMANENTLY
+   RC_MOVED_TEMPORARILY
+   RC_SEE_OTHER
+   RC_NOT_MODIFIED
+   RC_USE_PROXY
+   RC_BAD_REQUEST
+   RC_UNAUTHORIZED
+   RC_PAYMENT_REQUIRED
+   RC_FORBIDDEN
+   RC_NOT_FOUND
+   RC_METHOD_NOT_ALLOWED
+   RC_NOT_ACCEPTABLE
+   RC_PROXY_AUTHENTICATION_REQUIRED
+   RC_REQUEST_TIMEOUT
+   RC_CONFLICT
+   RC_GONE
+   RC_LENGTH_REQUIRED
+   RC_PRECONDITION_FAILED
+   RC_REQUEST_ENTITY_TOO_LARGE
+   RC_REQUEST_URI_TOO_LARGE
+   RC_UNSUPPORTED_MEDIA_TYPE
+   RC_INTERNAL_SERVER_ERROR
+   RC_NOT_IMPLEMENTED
+   RC_BAD_GATEWAY
+   RC_SERVICE_UNAVAILABLE
+   RC_GATEWAY_TIMEOUT
+   RC_HTTP_VERSION_NOT_SUPPORTED
+
+The HTTP::Status classification functions are:
+
+=over 3
+
+=item is_success($rc)
+
+Check if response code indicated successfull request.
+
+=item is_error($rc)
+
+Check if response code indicated that an error occured.
+
+=back
+
+The module will also export the LWP::UserAgent object as C<$ua> if you
+ask for it explicitly.
+
+The user agent created by this module will identify itself as
+"LWP::Simple/#.##" (where "#.##" is the libwww-perl version number)
+and will initialize its proxy defaults from the environment (by
+calling $ua->env_proxy).
+
+=head1 SEE ALSO
+
+L<LWP>, L<LWP::UserAgent>, L<HTTP::Status>, L<lwp-request>,
+L<lwp-mirror>
+
+=cut
+
+
+package LWP::Simple;
+
+use strict;
+use vars qw($ua %loop_check $FULL_LWP @EXPORT @EXPORT_OK $VERSION);
+
+require Exporter;
+
+@EXPORT = qw(get head getprint getstore mirror);
+@EXPORT_OK = qw($ua);
+
+# I really hate this.  I was a bad idea to do it in the first place.
+# Wonder how to get rid of it???  (It even makes LWP::Simple 7% slower
+# for trivial tests)
+use HTTP::Status;
+push(@EXPORT, @HTTP::Status::EXPORT);
+
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+$FULL_LWP++ if grep {lc($_) eq "http_proxy"} keys %ENV;
+
+
+sub import
+{
+    my $pkg = shift;
+    my $callpkg = caller;
+    if (grep $_ eq '$ua', @_) {
+	$FULL_LWP++;
+	_init_ua();
+    }
+    Exporter::export($pkg, $callpkg, @_);
+}
+
+
+sub _init_ua
+{
+    require LWP;
+    require LWP::UserAgent;
+    require HTTP::Status;
+    require HTTP::Date;
+    $ua = new LWP::UserAgent;  # we create a global UserAgent object
+    my $ver = $LWP::VERSION = $LWP::VERSION;  # avoid warning
+    $ua->agent("LWP::Simple/$LWP::VERSION");
+    $ua->env_proxy;
+}
+
+
+sub get ($)
+{
+    %loop_check = ();
+    goto \&_get;
+}
+
+
+sub get_old ($)
+{
+    my($url) = @_;
+    _init_ua() unless $ua;
+
+    my $request = HTTP::Request->new(GET => $url);
+    my $response = $ua->request($request);
+
+    return $response->content if $response->is_success;
+    return undef;
+}
+
+
+sub head ($)
+{
+    my($url) = @_;
+    _init_ua() unless $ua;
+
+    my $request = HTTP::Request->new(HEAD => $url);
+    my $response = $ua->request($request);
+
+    if ($response->is_success) {
+	return $response unless wantarray;
+	return ($response->header('Content-Type'),
+		$response->header('Content-Length'),
+		HTTP::Date::str2time($response->header('Last-Modified')),
+		HTTP::Date::str2time($response->header('Expires')),
+		$response->header('Server'),
+	       );
+    }
+    return;
+}
+
+
+sub getprint ($)
+{
+    my($url) = @_;
+    _init_ua() unless $ua;
+
+    my $request = HTTP::Request->new(GET => $url);
+    local($\) = ""; # ensure standard $OUTPUT_RECORD_SEPARATOR
+    my $response = $ua->request($request, sub { print $_[0] });
+    unless ($response->is_success) {
+	print STDERR $response->status_line, " <URL:$url>\n";
+    }
+    $response->code;
+}
+
+
+sub getstore ($$)
+{
+    my($url, $file) = @_;
+    _init_ua() unless $ua;
+
+    my $request = HTTP::Request->new(GET => $url);
+    my $response = $ua->request($request, $file);
+
+    $response->code;
+}
+
+
+sub mirror ($$)
+{
+    my($url, $file) = @_;
+    _init_ua() unless $ua;
+    my $response = $ua->mirror($url, $file);
+    $response->code;
+}
+
+
+sub _get
+{
+    my $url = shift;
+    my $ret;
+    if (!$FULL_LWP && $url =~ m,^http://([^/:]+)(?::(\d+))?(/\S*)?$,) {
+	my $host = $1;
+	my $port = $2 || 80;
+	my $path = $3;
+	$path = "/" unless defined($path);
+	return _trivial_http_get($host, $port, $path);
+    } else {
+        _init_ua() unless $ua;
+	my $request = HTTP::Request->new(GET => $url);
+	my $response = $ua->request($request);
+	return $response->is_success ? $response->content : undef;
+    }
+}
+
+
+sub _trivial_http_get
+{
+   my($host, $port, $path) = @_;
+   #print "HOST=$host, PORT=$port, PATH=$path\n";
+
+   require IO::Socket;
+   local($^W) = 0;
+   my $sock = IO::Socket::INET->new(PeerAddr => $host,
+                                    PeerPort => $port,
+                                    Proto    => 'tcp',
+                                    Timeout  => 60) || return;
+   $sock->autoflush;
+   my $netloc = $host;
+   $netloc .= ":$port" if $port != 80;
+   print $sock join("\015\012" =>
+                    "GET $path HTTP/1.0",
+                    "Host: $netloc",
+                    "User-Agent: lwp-trivial/$VERSION",
+                    "", "");
+
+   my $buf = "";
+   my $n;
+   1 while $n = sysread($sock, $buf, 8*1024, length($buf));
+   return undef unless defined($n);
+
+   if ($buf =~ m,^HTTP/\d+\.\d+\s+(\d+)[^\012]*\012,) {
+       my $code = $1;
+       #print "CODE=$code\n$buf\n";
+       if ($code =~ /^30[1237]/ && $buf =~ /\012Location:\s*(\S+)/) {
+           # redirect
+           my $url = $1;
+           return undef if $loop_check{$url}++;
+           return _get($url);
+       }
+       return undef unless $code =~ /^2/;
+       $buf =~ s/.+?\015?\012\015?\012//s;  # zap header
+   }
+
+   return $buf;
+}
+
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/UserAgent.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/UserAgent.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/UserAgent.pm	(revision 16571)
@@ -0,0 +1,732 @@
+# $Id$
+
+package LWP::UserAgent;
+use strict;
+
+=head1 NAME
+
+LWP::UserAgent - A WWW UserAgent class
+
+=head1 SYNOPSIS
+
+ require LWP::UserAgent;
+ $ua = new LWP::UserAgent;
+
+ $request = new HTTP::Request('GET', 'file://localhost/etc/motd');
+
+ $response = $ua->request($request); # or
+ $response = $ua->request($request, '/tmp/sss'); # or
+ $response = $ua->request($request, \&callback, 4096);
+
+ sub callback { my($data, $response, $protocol) = @_; .... }
+
+=head1 DESCRIPTION
+
+The C<LWP::UserAgent> is a class implementing a simple World-Wide Web
+user agent in Perl. It brings together the HTTP::Request,
+HTTP::Response and the LWP::Protocol classes that form the rest of the
+core of libwww-perl library. For simple uses this class can be used
+directly to dispatch WWW requests, alternatively it can be subclassed
+for application-specific behaviour.
+
+In normal usage the application creates a UserAgent object, and then
+configures it with values for timeouts proxies, name, etc. The next
+step is to create an instance of C<HTTP::Request> for the request that
+needs to be performed. This request is then passed to the UserAgent
+request() method, which dispatches it using the relevant protocol,
+and returns a C<HTTP::Response> object.
+
+The basic approach of the library is to use HTTP style communication
+for all protocol schemes, i.e. you will receive an C<HTTP::Response>
+object also for gopher or ftp requests.  In order to achieve even more
+similarities with HTTP style communications, gopher menus and file
+directories will be converted to HTML documents.
+
+The request() method can process the content of the response in one of
+three ways: in core, into a file, or into repeated calls of a
+subroutine.  You choose which one by the kind of value passed as the
+second argument to request().
+
+The in core variant simply returns the content in a scalar attribute
+called content() of the response object, and is suitable for small
+HTML replies that might need further parsing.  This variant is used if
+the second argument is missing (or is undef).
+
+The filename variant requires a scalar containing a filename as the
+second argument to request(), and is suitable for large WWW objects
+which need to be written directly to the file, without requiring large
+amounts of memory. In this case the response object returned from
+request() will have empty content().  If the request fails, then the
+content() might not be empty, and the file will be untouched.
+
+The subroutine variant requires a reference to callback routine as the
+second argument to request() and it can also take an optional chuck
+size as third argument.  This variant can be used to construct
+"pipe-lined" processing, where processing of received chuncks can
+begin before the complete data has arrived.  The callback function is
+called with 3 arguments: the data received this time, a reference to
+the response object and a reference to the protocol object.  The
+response object returned from request() will have empty content().  If
+the request fails, then the the callback routine will not have been
+called, and the response->content() might not be empty.
+
+The request can be aborted by calling die() within the callback
+routine.  The die message will be available as the "X-Died" special
+response header field.
+
+The library also accepts that you put a subroutine reference as
+content in the request object.  This subroutine should return the
+content (possibly in pieces) when called.  It should return an empty
+string when there is no more content.
+
+=head1 METHODS
+
+The following methods are available:
+
+=over 4
+
+=cut
+
+
+use vars qw(@ISA $VERSION);
+
+require LWP::MemberMixin;
+@ISA = qw(LWP::MemberMixin);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+
+require URI::URL;
+require HTTP::Request;
+require HTTP::Response;
+
+use HTTP::Date ();
+
+use LWP ();
+use LWP::Debug ();
+use LWP::Protocol ();
+
+use Carp ();
+
+use AutoLoader ();
+*AUTOLOAD = \&AutoLoader::AUTOLOAD;  # import the AUTOLOAD method
+
+
+=item $ua = new LWP::UserAgent;
+
+Constructor for the UserAgent.  Returns a reference to a
+LWP::UserAgent object.
+
+=cut
+
+sub new
+{
+    my($class, $init) = @_;
+    LWP::Debug::trace('()');
+
+    my $self;
+    if (ref $init) {
+	$self = $init->clone;
+    } else {
+	$self = bless {
+		'agent'       => "libwww-perl/$LWP::VERSION",
+		'from'        => undef,
+		'timeout'     => 3*60,
+		'proxy'       => undef,
+		'cookie_jar'  => undef,
+		'use_eval'    => 1,
+                'parse_head'  => 1,
+                'max_size'    => undef,
+		'no_proxy'    => [],
+	}, $class;
+    }
+}
+
+
+=item $ua->simple_request($request, [$arg [, $size]])
+
+This method dispatches a single WWW request on behalf of a user, and
+returns the response received.  The C<$request> should be a reference
+to a C<HTTP::Request> object with values defined for at least the
+method() and url() attributes.
+
+If C<$arg> is a scalar it is taken as a filename where the content of
+the response is stored.
+
+If C<$arg> is a reference to a subroutine, then this routine is called
+as chunks of the content is received.  An optional C<$size> argument
+is taken as a hint for an appropriate chunk size.
+
+If C<$arg> is omitted, then the content is stored in the response
+object itself.
+
+=cut
+
+sub simple_request
+{
+    my($self, $request, $arg, $size) = @_;
+    local($SIG{__DIE__});  # protect agains user defined die handlers
+
+    my($method, $url) = ($request->method, $request->url);
+
+    # Check that we have a METHOD and a URL first
+    return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST, "Method missing")
+	unless $method;
+    return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST, "URL missing")
+	unless $url;
+
+    LWP::Debug::trace("$method $url");
+
+    # Locate protocol to use
+    my $scheme = '';
+    my $proxy = $self->_need_proxy($url);
+    if (defined $proxy) {
+	$scheme = $proxy->scheme;
+    } else {
+	$scheme = $url->scheme;
+    }
+    my $protocol;
+    eval {
+	$protocol = LWP::Protocol::create($scheme);
+    };
+    if ($@) {
+	$@ =~ s/\s+at\s+\S+\s+line\s+\d+\.?\s*//;  # remove file/line number
+	return HTTP::Response->new(&HTTP::Status::RC_NOT_IMPLEMENTED, $@)
+    }
+
+    # Extract fields that will be used below
+    my ($agent, $from, $timeout, $cookie_jar,
+        $use_eval, $parse_head, $max_size) =
+      @{$self}{qw(agent from timeout cookie_jar
+                  use_eval parse_head max_size)};
+
+    # Set User-Agent and From headers if they are defined
+    $request->header('User-Agent' => $agent) if $agent;
+    $request->header('From' => $from) if $from;
+    $cookie_jar->add_cookie_header($request) if $cookie_jar;
+
+    # Transfer some attributes to the protocol object
+    $protocol->parse_head($parse_head);
+    $protocol->max_size($max_size);
+    
+    my $response;
+    if ($use_eval) {
+	# we eval, and turn dies into responses below
+	eval {
+	    $response = $protocol->request($request, $proxy,
+					   $arg, $size, $timeout);
+	};
+	if ($@) {
+	    $@ =~ s/\s+at\s+\S+\s+line\s+\d+\.?\s*//;
+	    $response =
+	      HTTP::Response->new(&HTTP::Status::RC_INTERNAL_SERVER_ERROR,
+				  $@);
+	}
+    } else {
+	$response = $protocol->request($request, $proxy,
+				       $arg, $size, $timeout);
+	# XXX: Should we die unless $response->is_success ???
+    }
+
+    $response->request($request);  # record request for reference
+    $cookie_jar->extract_cookies($response) if $cookie_jar;
+    $response->header("Client-Date" => HTTP::Date::time2str(time));
+    return $response;
+}
+
+
+=item $ua->request($request, $arg [, $size])
+
+Process a request, including redirects and security.  This method may
+actually send several different simple reqeusts.
+
+The arguments are the same as for C<simple_request()>.
+
+=cut
+
+sub request
+{
+    my($self, $request, $arg, $size, $previous) = @_;
+
+    LWP::Debug::trace('()');
+
+    my $response = $self->simple_request($request, $arg, $size);
+
+    my $code = $response->code;
+    $response->previous($previous) if defined $previous;
+
+    LWP::Debug::debug('Simple result: ' . HTTP::Status::status_message($code));
+
+    if ($code == &HTTP::Status::RC_MOVED_PERMANENTLY or
+	$code == &HTTP::Status::RC_MOVED_TEMPORARILY) {
+
+	# Make a copy of the request and initialize it with the new URI
+	my $referral = $request->clone;
+
+	# And then we update the URL based on the Location:-header.
+	# Some servers erroneously return a relative URL for redirects,
+	# so make it absolute if it not already is.
+	my $referral_uri = (URI::URL->new($response->header('Location'),
+					  $response->base))->abs(undef,1);
+
+	$referral->url($referral_uri);
+
+	return $response unless $self->redirect_ok($referral);
+
+	# Check for loop in the redirects
+	my $count = 0;
+	my $r = $response;
+	while ($r) {
+	    if (++$count > 13 ||
+                $r->request->url->as_string eq $referral_uri->as_string) {
+		$response->header("Client-Warning" =>
+				  "Redirect loop detected");
+		return $response;
+	    }
+	    $r = $r->previous;
+	}
+
+	return $self->request($referral, $arg, $size, $response);
+
+    } elsif ($code == &HTTP::Status::RC_UNAUTHORIZED ||
+	     $code == &HTTP::Status::RC_PROXY_AUTHENTICATION_REQUIRED
+	    )
+    {
+	my $proxy = ($code == &HTTP::Status::RC_PROXY_AUTHENTICATION_REQUIRED);
+	my $ch_header = $proxy ?  "Proxy-Authenticate" : "WWW-Authenticate";
+	my $challenge = $response->header($ch_header);
+	unless (defined $challenge) {
+	    $response->header("Client-Warning" => 
+			      "Missing Authenticate header");
+	    return $response;
+	}
+
+	require HTTP::Headers::Util;
+	$challenge =~ tr/,/;/;  # "," is used to separate auth-params!!
+	($challenge) = HTTP::Headers::Util::split_header_words($challenge);
+	my $scheme = lc(shift(@$challenge));
+	shift(@$challenge); # no value
+	$challenge = { @$challenge };  # make rest into a hash
+	for (keys %$challenge) {       # make sure all keys are lower case
+	    $challenge->{lc $_} = delete $challenge->{$_};
+	}
+
+	unless ($scheme =~ /^([a-z]+(?:-[a-z]+)*)$/) {
+	    $response->header("Client-Warning" => 
+			      "Bad authentication scheme '$scheme'");
+	    return $response;
+	}
+	$scheme = $1;  # untainted now
+	my $class = "LWP::Authen::\u$scheme";
+	$class =~ s/-/_/g;
+	
+	no strict 'refs';
+	unless (defined %{"$class\::"}) {
+	    # try to load it
+	    eval "require $class";
+	    if ($@) {
+		if ($@ =~ /^Can\'t locate/) {
+		    $response->header("Client-Warning" =>
+				      "Unsupport authentication scheme '$scheme'");
+		} else {
+		    $response->header("Client-Warning" => $@);
+		}
+		return $response;
+	    }
+	}
+	return $class->authenticate($self, $proxy, $challenge, $response,
+				    $request, $arg, $size);
+    }
+    return $response;
+}
+
+
+=item $ua->redirect_ok
+
+This method is called by request() before it tries to do any
+redirects.  It should return a true value if the redirect is allowed
+to be performed. Subclasses might want to override this.
+
+The default implementation will return FALSE for POST request and TRUE
+for all others.
+
+=cut
+
+sub redirect_ok
+{
+    # draft-ietf-http-v10-spec-02.ps from www.ics.uci.edu, specify:
+    #
+    # If the 30[12] status code is received in response to a request using
+    # the POST method, the user agent must not automatically redirect the
+    # request unless it can be confirmed by the user, since this might change
+    # the conditions under which the request was issued.
+
+    my($self, $request) = @_;
+    return 0 if $request->method eq "POST";
+    1;
+}
+
+
+=item $ua->credentials($netloc, $realm, $uname, $pass)
+
+Set the user name and password to be used for a realm.  It is often more
+useful to specialize the get_basic_credentials() method instead.
+
+=cut
+
+sub credentials
+{
+    my($self, $netloc, $realm, $uid, $pass) = @_;
+    @{ $self->{'basic_authentication'}{$netloc}{$realm} } = ($uid, $pass);
+}
+
+
+=item $ua->get_basic_credentials($realm, $uri, [$proxy])
+
+This is called by request() to retrieve credentials for a Realm
+protected by Basic Authentication or Digest Authentication.
+
+Should return username and password in a list.  Return undef to abort
+the authentication resolution atempts.
+
+This implementation simply checks a set of pre-stored member
+variables. Subclasses can override this method to e.g. ask the user
+for a username/password.  An example of this can be found in
+C<lwp-request> program distributed with this library.
+
+=cut
+
+sub get_basic_credentials
+{
+    my($self, $realm, $uri, $proxy) = @_;
+    return if $proxy;
+
+    my $netloc = $uri->netloc;
+    if (exists $self->{'basic_authentication'}{$netloc}{$realm}) {
+	return @{ $self->{'basic_authentication'}{$netloc}{$realm} };
+    }
+
+    return (undef, undef);
+}
+
+
+=item $ua->agent([$product_id])
+
+Get/set the product token that is used to identify the user agent on
+the network.  The agent value is sent as the "User-Agent" header in
+the requests. The default agent name is "libwww-perl/#.##", where
+"#.##" is substitued with the version numer of this library.
+
+The user agent string should be one or more simple product identifiers
+with an optional version number separated by the "/" character.
+Examples are:
+
+  $ua->agent('Checkbot/0.4 ' . $ua->agent);
+  $ua->agent('Mozilla/5.0');
+
+=item $ua->from([$email_address])
+
+Get/set the Internet e-mail address for the human user who controls
+the requesting user agent.  The address should be machine-usable, as
+defined in RFC 822.  The from value is send as the "From" header in
+the requests.  There is no default.  Example:
+
+  $ua->from('aas@sn.no');
+
+=item $ua->timeout([$secs])
+
+Get/set the timeout value in seconds. The default timeout() value is
+180 seconds, i.e. 3 minutes.
+
+=item $ua->cookie_jar([$cookies])
+
+Get/set the I<HTTP::Cookies> object to use.  The default is to have no
+cookie_jar, i.e. never automatically add "Cookie" headers to the
+requests.
+
+=item $ua->parse_head([$boolean])
+
+Get/set a value indicating wether we should initialize response
+headers from the E<lt>head> section of HTML documents. The default is
+TRUE.  Do not turn this off, unless you know what you are doing.
+
+=item $ua->max_size([$bytes])
+
+Get/set the size limit for response content.  The default is undef,
+which means that there is not limit.  If the returned response content
+is only partial, because the size limit was exceeded, then a
+"X-Content-Range" header will be added to the response.
+
+=cut
+
+sub timeout    { shift->_elem('timeout',   @_); }
+sub agent      { shift->_elem('agent',     @_); }
+sub from       { shift->_elem('from',      @_); }
+sub cookie_jar { shift->_elem('cookie_jar',@_); }
+sub parse_head { shift->_elem('parse_head',@_); }
+sub max_size   { shift->_elem('max_size',  @_); }
+
+# depreciated
+sub use_eval   { shift->_elem('use_eval',  @_); }
+sub use_alarm
+{
+    Carp::carp("LWP::UserAgent->use_alarm(BOOL) is a no-op")
+	if @_ > 1 && $^W;
+    "";
+}
+
+
+# Declarations of AutoLoaded methods
+sub clone;
+sub is_protocol_supported;
+sub mirror;
+sub proxy;
+sub env_proxy;
+sub no_proxy;
+sub _need_proxy;
+
+
+1;
+__END__
+
+
+=item $ua->clone;
+
+Returns a copy of the LWP::UserAgent object
+
+=cut
+
+
+sub clone
+{
+    my $self = shift;
+    my $copy = bless { %$self }, ref $self;  # copy most fields
+
+    # elements that are references must be handled in a special way
+    $copy->{'no_proxy'} = [ @{$self->{'no_proxy'}} ];  # copy array
+
+    $copy;
+}
+
+
+=item $ua->is_protocol_supported($scheme)
+
+You can use this method to query if the library currently support the
+specified C<scheme>.  The C<scheme> might be a string (like 'http' or
+'ftp') or it might be an URI::URL object reference.
+
+=cut
+
+sub is_protocol_supported
+{
+    my($self, $scheme) = @_;
+    if (ref $scheme) {
+	# assume we got a reference to an URI::URL object
+	$scheme = $scheme->abs->scheme;
+    } else {
+	Carp::croak("Illeal scheme '$scheme' passed to is_protocol_supported")
+	    if $scheme =~ /\W/;
+	$scheme = lc $scheme;
+    }
+    return LWP::Protocol::implementor($scheme);
+}
+
+
+=item $ua->mirror($url, $file)
+
+Get and store a document identified by a URL, using If-Modified-Since,
+and checking of the Content-Length.  Returns a reference to the
+response object.
+
+=cut
+
+sub mirror
+{
+    my($self, $url, $file) = @_;
+
+    LWP::Debug::trace('()');
+    my $request = new HTTP::Request('GET', $url);
+
+    if (-e $file) {
+	my($mtime) = (stat($file))[9];
+	if($mtime) {
+	    $request->header('If-Modified-Since' =>
+			     HTTP::Date::time2str($mtime));
+	}
+    }
+    my $tmpfile = "$file-$$";
+
+    my $response = $self->request($request, $tmpfile);
+    if ($response->is_success) {
+
+	my $file_length = (stat($tmpfile))[7];
+	my($content_length) = $response->header('Content-length');
+
+	if (defined $content_length and $file_length < $content_length) {
+	    unlink($tmpfile);
+	    die "Transfer truncated: " .
+		"only $file_length out of $content_length bytes received\n";
+	} elsif (defined $content_length and $file_length > $content_length) {
+	    unlink($tmpfile);
+	    die "Content-length mismatch: " .
+		"expected $content_length bytes, got $file_length\n";
+	} else {
+	    # OK
+	    if (-e $file) {
+		# Some dosish systems fail to rename if the target exists
+		chmod 0777, $file;
+		unlink $file;
+	    }
+	    rename($tmpfile, $file) or
+		die "Cannot rename '$tmpfile' to '$file': $!\n";
+
+	    if (my $lm = $response->last_modified) {
+		# make sure the file has the same last modification time
+		utime $lm, $lm, $file;
+	    }
+	}
+    } else {
+	unlink($tmpfile);
+    }
+    return $response;
+}
+
+=item $ua->proxy(...)
+
+Set/retrieve proxy URL for a scheme:
+
+ $ua->proxy(['http', 'ftp'], 'http://proxy.sn.no:8001/');
+ $ua->proxy('gopher', 'http://proxy.sn.no:8001/');
+
+The first form specifies that the URL is to be used for proxying of
+access methods listed in the list in the first method argument,
+i.e. 'http' and 'ftp'.
+
+The second form shows a shorthand form for specifying
+proxy URL for a single access scheme.
+
+=cut
+
+sub proxy
+{
+    my($self, $key, $proxy) = @_;
+
+    LWP::Debug::trace("$key, $proxy");
+
+    if (!ref($key)) {   # single scalar passed
+	my $old = $self->{'proxy'}{$key};
+	$self->{'proxy'}{$key} = $proxy;
+	return $old;
+    } elsif (ref($key) eq 'ARRAY') {
+	for(@$key) {    # array passed
+	    $self->{'proxy'}{$_} = $proxy;
+	}
+    }
+    return undef;
+}
+
+=item $ua->env_proxy()
+
+Load proxy settings from *_proxy environment variables.  You might
+specify proxies like this (sh-syntax):
+
+  gopher_proxy=http://proxy.my.place/
+  wais_proxy=http://proxy.my.place/
+  no_proxy="my.place"
+  export gopher_proxy wais_proxy no_proxy
+
+Csh or tcsh users should use the C<setenv> command to define these
+envirionment variables.
+
+=cut
+
+sub env_proxy {
+    my ($self) = @_;
+    my($k,$v);
+    while(($k, $v) = each %ENV) {
+	$k = lc($k);
+	next unless $k =~ /^(.*)_proxy$/;
+	$k = $1;
+	if ($k eq 'no') {
+	    $self->no_proxy(split(/\s*,\s*/, $v));
+	}
+	else {
+	    $self->proxy($k, $v);
+	}
+    }
+}
+
+=item $ua->no_proxy($domain,...)
+
+Do not proxy requests to the given domains.  Calling no_proxy without
+any domains clears the list of domains. Eg:
+
+ $ua->no_proxy('localhost', 'no', ...);
+
+=cut
+
+sub no_proxy {
+    my($self, @no) = @_;
+    if (@no) {
+	push(@{ $self->{'no_proxy'} }, @no);
+    }
+    else {
+	$self->{'no_proxy'} = [];
+    }
+}
+
+
+# Private method which returns the URL of the Proxy configured for this
+# URL, or undefined if none is configured.
+sub _need_proxy
+{
+    my($self, $url) = @_;
+
+    $url = new URI::URL($url) unless ref $url;
+
+    LWP::Debug::trace("($url)");
+
+    # check the list of noproxies
+
+    if (@{ $self->{'no_proxy'} }) {
+	my $host = $url->host;
+	return undef unless defined $host;
+	my $domain;
+	for $domain (@{ $self->{'no_proxy'} }) {
+	    if ($host =~ /$domain$/) {
+		LWP::Debug::trace("no_proxy configured");
+		return undef;
+	    }
+	}
+    }
+
+    # Currently configured per scheme.
+    # Eventually want finer granularity
+
+    my $scheme = $url->scheme;
+    if (exists $self->{'proxy'}{$scheme}) {
+
+	LWP::Debug::debug('Proxied');
+	return new URI::URL($self->{'proxy'}{$scheme});
+    }
+
+    LWP::Debug::debug('Not proxied');
+    undef;
+}
+
+1;
+
+=back
+
+=head1 SEE ALSO
+
+See L<LWP> for a complete overview of libwww-perl5.  See F<lwp-request> and
+F<lwp-mirror> for examples of usage.
+
+=head1 COPYRIGHT
+
+Copyright 1995-1997 Gisle Aas.
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/media.types
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/media.types	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/LWP/media.types	(revision 16571)
@@ -0,0 +1,120 @@
+# $Id$
+#
+# This file defines the mapping from file name extentions to media types.
+# Media types where the subtype does not have the "x-" prefix should be
+# registered by IANA:
+#
+#   ftp://www.isi.edu/in-notes/iana/assignments/media-types/
+#
+# See also: RFC-1590
+
+# Text formats
+text/html			html htm
+text/plain			txt text pm el c h cc hh cxx hxx f90
+text/richtext			rtx
+text/tab-separated-values	tsv
+
+text/x-setext			etx
+text/x-pod			pod			# Perl documentation
+
+# Image formats
+image/png			png
+image/gif			gif			# Compuserve
+image/ief			ief
+image/jpeg			jpeg jpg jpe jfif
+image/tiff			tiff tif
+
+image/x-cmu-raster		ras
+image/x-portable-anymap		pnm
+image/x-portable-bitmap		pbm
+image/x-portable-graymap	pgm
+image/x-portable-pixmap		ppm
+image/x-rgb			rgb			# SGI IRIS
+image/x-xbitmap			xbm			# X Windows
+image/x-xpixmap			xpm			# X Windows
+image/x-xwindowdump		xwd			# X Windows
+image/x-bmp			bmp			# MS Windows
+image/x-targa			tga
+image/x-fits			fts
+
+
+# Audio formats
+audio/basic			au snd
+audio/x-aiff			aif aiff aifc
+audio/x-wav			wav			# MS Windows
+audio/x-mpeg-2			mp2			# MPEG layer 2 audio
+
+# Video formats
+video/mpeg			mpeg mpg mpe
+video/quicktime			qt
+video/x-msvideo			avi
+video/x-sgi-movie		mov
+
+# Message
+message/rfc822			mail
+message/partial
+message/external-body
+message/news			art
+
+# Applications
+application/octet-stream	bin
+application/postscript		ai eps ps
+application/oda			oda
+application/atomicmail
+application/andrew-insert
+application/slate
+application/wita
+application/dec-dx
+application/dca-rtf
+application/activemessage
+application/rtf			rft			# MS Word
+application/applefile
+application/mac-binhex40	hqx
+application/news-message-id
+application/news-transmission
+application/wordperfect5.1
+application/pdf			pdf
+application/zip			zip
+application/macwriteii
+application/msword
+application/remote-printing
+application/mathematica
+application/cybercash
+application/commonground
+application/iges
+application/riscos
+application/eshop
+
+application/x-mif		mif			# FrameMaker
+application/x-maker		fm
+application/x-csh		csh
+application/x-dvi		dvi
+application/x-hdf		hdf
+application/x-latex		latex
+application/x-netcdf		nc cdf
+application/x-sh		sh
+application/x-tcl		tcl
+application/x-perl		pl
+application/x-tex		tex
+application/x-texinfo		texinfo texi
+application/x-troff		t tr roff
+application/x-troff-man		man 1 2 3 4 5 6 7 8
+application/x-troff-me		me
+application/x-troff-ms		ms
+application/x-wais-source	src
+application/x-bcpio		bcpio
+application/x-cpio		cpio
+application/x-gtar		gtar			# GNU tar
+application/x-shar		shar
+application/x-sv4cpio		sv4cpio
+application/x-sv4crc		sv4crc
+application/x-tar		tar
+application/x-ustar		ustar
+
+# Multipart
+multipart/mixed
+multipart/alternative
+multipart/digest
+multipart/parallel
+multipart/appledouble
+multipart/header-set
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/Escape.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/Escape.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/Escape.pm	(revision 16571)
@@ -0,0 +1,119 @@
+#
+# $Id$
+#
+
+package URI::Escape;
+use strict;
+
+=head1 NAME
+
+URI::Escape - Escape and unescape unsafe characters
+
+=head1 SYNOPSIS
+
+ use URI::Escape;
+ $safe = uri_escape("10% is enough\n");
+ $verysafe = uri_escape("foo", "\0-\377");
+ $str  = uri_unescape($safe);
+
+=head1 DESCRIPTION
+
+This module provide functions to escape and unescape URI strings.
+Some characters are regarded as "unsafe" and must be escaped in
+accordance with RFC 1738.  Escaped characters are represented by a
+triplet consisting of the character "%" followed by two hexadecimal
+digits.  The following functions are provided (and exported by
+default):
+
+=over 4
+
+=item uri_escape($string, [$unsafe])
+
+This function replaces all unsafe characters in the $string with their
+escape sequence and return the result.
+
+The uri_escape() function takes an optional second argument that
+overrides the set of characters that are to be escaped.  The set is
+specified as a string that can be used in a regular expression
+character class (between [ ]).  E.g.:
+
+  \x00-\x1f\x7f-\xff          # all control and hi-bit characters
+  a-z                         # all lower case characters
+  ^A-Za-z                     # everything not a letter
+
+The default set of characters to be escaped is:
+
+  \x00-\x20"#%;<>?{}|\\^~`\[\]\x7F-\xFF
+
+=item uri_unescape($string)
+
+Returns a string with all %XX sequences replaced with the actual
+character.
+
+=back
+
+The module can also export the %escapes hash which contains the
+mapping from all characters to the corresponding escape code.
+
+=head1 SEE ALSO
+
+L<URI::URL>
+
+
+=head1 COPYRIGHT
+
+Copyright 1995-1997 Gisle Aas.
+
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
+use vars qw(%escapes);
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT = qw(uri_escape uri_unescape);
+@EXPORT_OK = qw(%escapes);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+use Carp ();
+
+# Build a char->hex map
+for (0..255) {
+    $escapes{chr($_)} = sprintf("%%%02X", $_);
+}
+
+my %subst;  # compiled patternes
+
+sub uri_escape
+{
+    my($text, $patn) = @_;
+    return undef unless defined $text;
+    if (defined $patn){
+	unless (exists  $subst{$patn}) {
+	    # Because we can't compile regex we fake it with a cached sub
+	    $subst{$patn} =
+	      eval "sub {\$_[0] =~ s/([$patn])/\$escapes{\$1}/g; }";
+	    Carp::croak("uri_escape: $@") if $@;
+	}
+	&{$subst{$patn}}($text);
+    } else {
+	# Default unsafe characters. (RFC1738 section 2.2)
+	$text =~ s/([\x00-\x20\"#%;<>?{}|\\^~`\[\]\x7F-\xFF])/$escapes{$1}/g;
+    }
+    $text;
+}
+
+sub uri_unescape
+{
+    # Note from RFC1630:  "Sequences which start with a percent sign
+    # but are not followed by two hexadecimal characters are reserved
+    # for future extension"
+    my @copy = @_;
+    for (@copy) { s/%([\dA-Fa-f]{2})/chr(hex($1))/eg; }
+    wantarray ? @copy : $copy[0];
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/Heuristic.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/Heuristic.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/Heuristic.pm	(revision 16571)
@@ -0,0 +1,191 @@
+package URI::Heuristic;
+
+# $Id$
+
+=head1 NAME
+
+uf_urlstr - Expand URL using heuristics
+
+=head1 SYNOPSIS
+
+ use URI::Heuristic qw(uf_urlstr);
+ $url = uf_urlstr("perl");             # http://www.perl.com
+ $url = uf_urlstr("www.sol.no/sol");   # http://www.sol.no/sol
+ $url = uf_urlstr("aas");              # http://www.aas.no
+ $url = uf_urlstr("ftp.funet.fi");     # ftp://ftp.funet.fi
+ $url = uf_urlstr("/etc/passwd");      # file:/etc/passwd
+
+=head1 DESCRIPTION
+
+This module provide functions that expand strings into real absolute
+URLs using some builtin heuristics.  Strings that already represent
+absolute URLs (i.e. start with a C<scheme:> part) are never modified
+and are returned unchanged.  The main use of these functions are to
+allow abbreviated URLs similar to what many web browsers allow for URLs
+typed in by the user.
+
+The following functions are provided:
+
+=over 4
+
+=item uf_urlstr($str)
+
+The uf_urlstr() function will try to make the string passed as
+argument into a proper absolute URL string.  The "uf_" prefix stands
+for "User Friendly".
+
+=item uf_url($str)
+
+This functions work the same way as uf_urlstr() but it will
+return a C<URI::URL> object.
+
+=back
+
+=head1 ENVIRONMENT
+
+If the hostname portion of a URL does not contain any dots, then
+certain qualified guesses will be made.  These guesses are governed be
+the following two environment variables.
+
+=over 10
+
+=item COUNTRY
+
+This is the two letter country code (ISO 3166) for your location.  If
+the domain name of your host ends with two letters, then it is taken
+to be the default country. See also L<Locale::Country>.
+
+=item URL_GUESS_PATTERN
+
+Contain a space separated list of URL patterns to try.  The string
+"ACME" is for some reason used as a placeholder for the host name in
+the URL provided.  Example:
+
+ URL_GUESS_PATTERN="www.ACME.no www.ACME.se www.ACME.com"
+ export URL_GUESS_PATTERN
+
+Specifying URL_GUESS_PATTERN disables any guessing rules based on
+country.  An empty URL_GUESS_PATTERN disables any guessing that
+involves host name lookups.
+
+=back
+
+=head1 COPYRIGHT
+
+Copyright 1997-1998, Gisle Aas
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+=cut
+
+use strict;
+
+use vars qw(@EXPORT_OK $VERSION $MY_COUNTRY %LOCAL_GUESSING $DEBUG);
+
+require Exporter;
+*import = \&Exporter::import;
+@EXPORT_OK = qw(uf_url uf_urlstr);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+eval {
+    require Net::Domain;
+    my $fqdn = Net::Domain::hostfqdn();
+    $MY_COUNTRY = lc($1) if $fqdn =~ /\.([a-zA-Z]{2})$/;
+
+    # Some other heuristics to guess country?  Perhaps looking
+    # at some environment variable (LANG, LC_ALL, ???)
+    $MY_COUNTRY = $ENV{COUNTRY} if exists $ENV{COUNTRY};
+};
+
+%LOCAL_GUESSING =
+(
+ 'us' => [qw(www.ACME.gov www.ACME.mil)],
+ 'uk' => [qw(www.ACME.co.uk www.ACME.org.uk www.ACME.ac.uk)],
+ 'au' => [qw(www.ACME.com.au www.ACME.org.au www.ACME.edu.au)],
+ 'il' => [qw(www.ACME.co.il www.ACME.org.il www.ACME.net.il)],
+ # send corrections and new entries to <aas@sn.no>
+);
+
+
+sub uf_url ($)
+{
+    require URI::URL;
+    URI::URL->new(uf_urlstr($_[0]));
+}
+
+
+sub uf_urlstr ($)
+{
+    local($_) = @_;
+    print STDERR "uf_urlstr: resolving $_\n" if $DEBUG;
+    return unless defined;
+
+    s/^\s+//;
+    s/\s+$//;
+
+    if (/^(www|web|home)\./) {
+	$_ = "http://$_";
+
+    } elsif (/^(ftp|gopher|news|wais|http|https)\./) {
+	$_ = "$1://$_";
+
+    } elsif (m,^/,      ||          # absolute file name
+	     m,^\.\.?/, ||          # relative file name
+	     m,^[a-zA-Z]:[/\\],)    # dosish file name
+    {
+	$_ = "file:$_";
+
+    } elsif (/^\w+([\.\-]\w+)*\@(\w+\.)+\w{2,3}$/) {
+	$_ = "mailto:$_";
+
+    } elsif (!/^[.+\-\w]+:/) {      # no scheme specified
+	if (s/^(\w+(?:\.\w+)*)([\/:\?\#]|$)/$2/) {
+	    my $host = $1;
+
+	    if ($host !~ /\./ && $host ne "localhost") {
+		my @guess;
+		if (exists $ENV{URL_GUESS_PATTERN}) {
+		    @guess = map { s/\bACME\b/$host/; $_ }
+		             split(' ', $ENV{URL_GUESS_PATTERN});
+		} else {
+		    if ($MY_COUNTRY) {
+			my $special = $LOCAL_GUESSING{$MY_COUNTRY};
+			if ($special) {
+			    my @special = @$special;
+			    push(@guess, map { s/\bACME\b/$host/; $_ }
+                                               @special);
+			} else {
+			    push(@guess, "www.$host.$MY_COUNTRY");
+			}
+		    }
+		    push(@guess, map "www.$host.$_",
+			             "com", "org", "net", "edu", "int");
+		}
+
+
+		my $guess;
+		for $guess (@guess) {
+		    print STDERR "uf_urlstr: gethostbyname('$guess')..."
+		      if $DEBUG;
+		    if (gethostbyname($guess)) {
+			print STDERR "yes\n" if $DEBUG;
+			$host = $guess;
+			last;
+		    }
+		    print STDERR "no\n" if $DEBUG;
+		}
+	    }
+	    $_ = "http://$host$_";
+
+	} else {
+	    # pure junk, just return it unchanged...
+
+	}
+    }
+    print STDERR "uf_urlstr: ==> $_\n" if $DEBUG;
+
+    $_;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL.pm	(revision 16571)
@@ -0,0 +1,949 @@
+package URI::URL;
+
+$VERSION = "4.15";   # $Date$
+sub Version { $VERSION; }
+
+require 5.004;
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT = qw(url);
+
+require AutoLoader;
+*AUTOLOAD = \&AutoLoader::AUTOLOAD;
+
+use Carp ();
+
+# Basic lexical elements, taken from RFC 1738:
+#
+#  safe         = "$" | "-" | "_" | "." | "+"
+#  extra        = "!" | "*" | "'" | "(" | ")" | ","
+#  national     = "{" | "}" | "|" | "\" | "^" | "~" | "[" | "]" | "`"
+#  punctuation  = "<" | ">" | "#" | "%" | <">
+#  reserved     = ";" | "/" | "?" | ":" | "@" | "&" | "="
+#  escape       = "%" hex hex
+#  unreserved   = alpha | digit | safe | extra
+#  uchar        = unreserved | escape
+#  xchar        = unreserved | reserved | escape
+
+# draft-fielding-url-syntax-05.txt adds '+' to the reserved chars and
+# takes '~' out
+
+use strict;
+use vars qw($reserved $reserved_no_slash $reserved_no_form $unsafe
+	    $Debug $Strict_URL
+	   );
+
+$reserved          = ";\\/?:\\@&=+#%"; # RFC 1738 reserved pluss '#' and '%'
+$reserved_no_slash = ";?:\\@&=+#%";    # used when escaping path
+$reserved_no_form  = ";\\/?:\\@#%";    # used when escaping params and query
+
+# This is the unsafe characters (excluding those reserved)
+$unsafe   = "\x00-\x20{}|\\\\^\\[\\]`<>\"\x7F-\xFF";
+#$unsafe .= "~";  # according to RFC1738 but not to common practice
+
+$Debug         = 0;     # set to 1 to print URLs on creation
+$Strict_URL    = 0;     # see new()
+
+use overload ( '""' => 'as_string', 'fallback' => 1 );
+
+my %Implementor = (); # mapping from scheme to implementation class
+
+
+# Easy to use constructor
+sub url ($;$)
+{
+    URI::URL->new(@_);
+}
+
+
+# URI::URL objects are implemented as blessed hashes:
+#
+# Each of the URL components (scheme, netloc, user, password, host,
+# port, path, params, query, fragment) are stored under their
+# name. The netloc, path, params and query is stored in quoted
+# (escaped) form.  The others is stored unquoted (unescaped).
+#
+# Netloc is special since it is rendundant (same as
+# "user:password@host:port") and must be kept in sync with those.
+#
+# The '_str' key stores a cached stringified version of the URL
+# (by definition in quoted form).
+# The '_base' key stores the optional base of a relative URL.
+#
+# The '_orig_url' is used while debugging is on.
+#
+# Subclasses may add their own keys but must take great care to
+# avoid names which might be used in later verions of this module.
+
+sub new
+{
+    my($class, $init, $base) = @_;
+
+    my $self;
+    if (ref $init) {
+	$self = $init->clone;
+	$self->base($base) if $base;
+    } else {
+	$init = "" unless defined $init;
+	# RFC 1738 appendix suggest that we just ignore extra whitespace
+	$init =~ s/\s+//g;
+	# Also get rid of any <URL: > wrapper
+	$init =~ s/^<(?:URL:)?(.*)>$/$1/;
+
+	# We need a scheme to determine which class to use
+	my($scheme) = $init =~ m/^([.+\-\w]+):/;
+	if (!$scheme and $base){ # get scheme from base
+	    if (ref $base){ # may be object or just a string
+		$scheme = $base->scheme;
+	    } else {
+		$scheme = $1 if $base =~ m/^([.+\-\w]+):/;
+	    }
+	}
+	unless($scheme){
+	    Carp::croak("Unable to determine scheme for '$init'")
+		if $Strict_URL;
+	    $scheme = 'http';
+	}
+	my $impclass = URI::URL::implementor($scheme);
+	unless ($impclass) {
+	    Carp::croak("URI::URL scheme '$scheme' is not supported")
+		if $Strict_URL;
+	    # use generic as fallback
+	    require URI::URL::_generic;
+	    URI::URL::implementor($scheme, 'URI::URL::_generic');
+	    $impclass = 'URI::URL::_generic';
+	}
+
+	# hand-off to scheme specific implementation sub-class
+	$self->{'_orig_url'} = $init if $Debug;
+	$self = $impclass->new($init, $base);
+    }
+    $self->print_on('STDERR') if $Debug;
+    return $self;
+}
+
+
+sub clone
+{
+    my $self = shift;
+    # this work as long as none of the components are references themselves
+    bless { %$self }, ref $self;
+}
+
+
+sub implementor
+{
+    my($scheme, $impclass) = @_;
+    unless (defined $scheme) {
+	require URI::URL::_generic;
+	return 'URI::URL::_generic';
+    }
+
+    $scheme = lc($scheme);
+    if ($impclass) {
+	$impclass->_init_implementor($scheme);
+	my $old = $Implementor{$scheme};
+	$Implementor{$scheme} = $impclass;
+	return $old;
+    }
+
+    my $ic = $Implementor{$scheme};
+    return $ic if $ic;
+
+    # scheme not yet known, look for internal or
+    # preloaded (with 'use') implementation
+    $ic = "URI::URL::$scheme";  # default location
+    no strict 'refs';
+    # check we actually have one for the scheme:
+    unless (defined @{"${ic}::ISA"}) {
+	# Try to load it
+	eval { require "URI/URL/$scheme.pm"; };
+	die $@ if $@ && $@ !~ /Can\'t locate/;
+	$ic = '' unless defined @{"${ic}::ISA"};
+    }
+    if ($ic) {
+	$ic->_init_implementor($scheme);
+	$Implementor{$scheme} = $ic;
+    }
+    $ic;
+}
+
+
+sub _init_implementor
+{
+    my($class, $scheme) = @_;
+    # Remember that one implementor class may actually
+    # serve to implement several URL schemes.
+
+    if ($] < 5.003_17) {
+	no strict qw(refs);
+	# Setup overloading inheritace - experimental
+	%{"${class}::OVERLOAD"} = %URI::URL::OVERLOAD
+	    unless defined %{"${class}::OVERLOAD"};
+    }
+}
+
+
+# This private method help us implement access to the elements in the
+# URI::URL object hash (%$self).  You can set up access to an element
+# with a routine similar to this one:
+#
+#  sub component { shift->_elem('component', @_); }
+
+sub _elem
+{
+    my $self = shift;
+    my $elem = shift;
+    my $old = $self->{$elem};
+    if (@_) {
+	$self->{$elem} = shift;
+	$self->{'_str'} = '';        # void cached string
+    }
+    $old;
+}
+
+
+# Make all standard methods available to all kinds of URLs.  This allow
+# us to call these without to much worry when URI::URL::strict(0);
+
+sub bad_method;
+
+*netloc       = \&bad_method;
+*user         = \&bad_method;
+*password     = \&bad_method;
+*host         = \&bad_method;
+*port         = \&bad_method;
+*default_port = \&bad_method;
+
+*full_path    = \&bad_method;
+*epath        = \&bad_method;
+*eparams      = \&bad_method;
+*equery       = \&bad_method;
+
+*path         = \&bad_method;
+*path_components = \&bad_method;
+*params       = \&bad_method;
+*query        = \&bad_method;
+*frag         = \&bad_method;
+
+
+#
+# A U T O  L O A D I N G
+#
+# The rest of the methods are autoloaded because they should be less
+# frequently used.  We define stubs here so that inheritance works as
+# it should.
+sub newlocal;
+sub strict;
+sub base;
+sub scheme;
+sub crack;
+sub abs;
+sub rel;
+sub as_string;
+sub eq;
+sub print_on;
+
+# Don't need DESTROY but avoid trying to AUTOLOAD it.
+sub DESTROY { }
+
+1;
+__END__
+
+sub newlocal
+{
+    require URI::URL::file;
+    my $class = shift;
+    URI::URL::file->newlocal(@_);  # pass it on the the file class
+}
+
+sub strict
+{
+    return $Strict_URL unless @_;
+    my $old = $Strict_URL;
+    $Strict_URL = $_[0];
+    $old;
+}
+
+# Access some attributes of a URL object:
+sub base {
+    my $self = shift;
+    my $base  = $self->{'_base'};
+
+    if (@_) { # set
+	my $new_base = shift;
+	$new_base = $new_base->abs if ref($new_base);  # unsure absoluteness
+	$self->{_base} = $new_base;
+    }
+    return unless defined wantarray;
+
+    # The base attribute supports 'lazy' conversion from URL strings
+    # to URL objects. Strings may be stored but when a string is
+    # fetched it will automatically be converted to a URL object.
+    # The main benefit is to make it much cheaper to say:
+    #   new URI::URL $random_url_string, 'http:'
+    if (defined($base) && !ref($base)) {
+	$base = new URI::URL $base;
+	$self->_elem('_base', $base); # set new object
+    }
+    $base;
+}
+
+sub scheme {
+    my $self = shift;
+    my $old = $self->{'scheme'};
+    if (@_) {
+	my $new_scheme = shift;
+	if (defined($new_scheme) && length($new_scheme)) {
+	    # reparse URL with new scheme
+	    my $str = $self->as_string;
+	    $str =~ s/^[\w+\-.]+://;
+	    my $newself = new URI::URL "$new_scheme:$str";
+	    %$self = %$newself;
+	    bless $self, ref($newself);
+	} else {
+	    $self->{'scheme'} = undef;
+	}
+    }
+    $old;
+}
+
+sub crack
+{
+    # should be overridden by subclasses
+    my $self = shift;
+    ($self->scheme,  # 0: scheme
+     undef,          # 1: user
+     undef,          # 2: passwd
+     undef,          # 3: host
+     undef,          # 4: port
+     undef,          # 5: path
+     undef,          # 6: params
+     undef,          # 7: query
+     undef           # 8: fragment
+    )
+}
+
+# These are overridden by _generic (this is just a noop for those schemes that
+# do not wish to be a subclass of URI::URL::_generic)
+sub abs { shift->clone; }
+sub rel { shift->clone; }
+
+# This method should always be overridden in subclasses
+sub as_string {
+    "<URL>";
+}
+
+# Compare two URLs, subclasses will provide a more correct implementation
+sub eq {
+    my($self, $other) = @_;
+    $other = URI::URL->new($other, $self) unless ref $other;
+    ref($self) eq ref($other) &&
+      $self->scheme eq $other->scheme &&
+      $self->as_string eq $other->as_string;  # Case-sensitive
+}
+
+# This is set up as an alias for various methods
+sub bad_method {
+    my $self = shift;
+    my $scheme = $self->scheme;
+    Carp::croak("Illegal method called for $scheme: URL")
+	if $Strict_URL;
+    # Carp::carp("Illegal method called for $scheme: URL")
+    #     if $^W;
+    undef;
+}
+
+sub print_on
+{
+    no strict qw(refs);  # because we use strings as filehandles
+    my $self = shift;
+    my $fh = shift || 'STDERR';
+    my($k, $v);
+    print $fh "Dump of URI::URL $self...\n";
+    foreach $k (sort keys %$self){
+	$v = $self->{$k};
+	$v = 'UNDEF' unless defined $v;
+	print $fh "  $k\t'$v'\n";
+    }
+}
+
+1;
+
+
+#########################################################################
+#### D O C U M E N T A T I O N
+#########################################################################
+
+=head1 NAME
+
+URI::URL - Uniform Resource Locators (absolute and relative)
+
+=head1 SYNOPSIS
+
+ use URI::URL;
+
+ # Constructors
+ $url1 = new URI::URL 'http://www.perl.com/%7Euser/gisle.gif';
+ $url2 = new URI::URL 'gisle.gif', 'http://www.com/%7Euser';
+ $url3 = url 'http://www.sn.no/'; # handy constructor
+ $url4 = $url2->abs;       # get absolute url using base
+ $url5 = $url2->abs('http:/other/path');
+ $url6 = newlocal URI::URL 'test';
+
+ # Stringify URL
+ $str1 = $url->as_string;  # complete escaped URL string
+ $str2 = $url->full_path;  # escaped path+params+query
+ $str3 = "$url";           # use operator overloading
+
+ # Retrieving Generic-RL components:
+ $scheme   = $url->scheme;
+ $netloc   = $url->netloc; # see user,password,host,port below
+ $path     = $url->path;
+ $params   = $url->params;
+ $query    = $url->query;
+ $frag     = $url->frag;
+
+ # Accessing elements in their escaped form
+ $path     = $url->epath;
+ $params   = $url->eparams;
+ $query    = $url->equery;
+
+ # Retrieving Network location (netloc) components:
+ $user     = $url->user;
+ $password = $url->password;
+ $host     = $url->host;
+ $port     = $url->port;   # returns default if not defined
+
+ # Retrieve escaped path components as an array
+ @path     = $url->path_components;
+
+ # HTTP query-string access methods
+ @keywords = $url->keywords;
+ @form     = $url->query_form;
+
+ # All methods above can set the field values, e.g:
+ $url->scheme('http');
+ $url->host('www.w3.org');
+ $url->port($url->default_port);
+ $url->base($url5);                      # use string or object
+ $url->keywords(qw(dog bones));
+
+ # File methods
+ $url = new URI::URL "file:/foo/bar";
+ open(F, $url->local_path) or die;
+
+ # Compare URLs
+ if ($url->eq("http://www.sn.no")) or die;
+
+=head1 DESCRIPTION
+
+This module implements the URI::URL class representing Uniform
+Resource Locators (URL). URLs provide a compact string representation
+for resources available via the Internet. Both absolute (RFC 1738) and
+relative (RFC 1808) URLs are supported.
+
+URI::URL objects are created by calling new(), which takes as argument
+a string representation of the URL or an existing URL object reference
+to be cloned. Specific individual elements can then be accessed via
+the scheme(), user(), password(), host(), port(), path(), params(),
+query() and frag() methods.  In addition escaped versions of the path,
+params and query can be accessed with the epath(), eparams() and
+equery() methods.  Note that some URL schemes will support all these
+methods.
+
+The object constructor new() must be able to determine the scheme for
+the URL.  If a scheme is not specified in the URL itself, it will use
+the scheme specified by the base URL. If no base URL scheme is defined
+then new() will croak if URI::URL::strict(1) has been invoked,
+otherwise I<http> is silently assumed.  Once the scheme has been
+determined new() then uses the implementor() function to determine
+which class implements that scheme.  If no implementor class is
+defined for the scheme then new() will croak if URI::URL::strict(1)
+has been invoked, otherwise the internal generic URL class is assumed.
+
+Internally defined schemes are implemented by the
+URI::URL::I<scheme_name> module.  The URI::URL::implementor() function
+can be used to explicitly set the class used to implement a scheme if
+you want to override this.
+
+
+=head1 HOW AND WHEN TO ESCAPE
+
+
+=over 3
+
+=item This is an edited extract from a URI specification:
+
+The printability requirement has been met by specifying a safe set of
+characters, and a general escaping scheme for encoding "unsafe"
+characters. This "safe" set is suitable, for example, for use in
+electronic mail.  This is the canonical form of a URI.
+
+There is a conflict between the need to be able to represent many
+characters including spaces within a URI directly, and the need to be
+able to use a URI in environments which have limited character sets
+or in which certain characters are prone to corruption. This conflict
+has been resolved by use of an hexadecimal escaping method which may
+be applied to any characters forbidden in a given context. When URLs
+are moved between contexts, the set of characters escaped may be
+enlarged or reduced unambiguously.  The canonical form for URIs has
+all white spaces encoded.
+
+=item Notes:
+
+A URL string I<must>, by definition, consist of escaped
+components. Complete URLs are always escaped.
+
+The components of a URL string must be I<individually> escaped.  Each
+component of a URL may have a separate requirements regarding what
+must be escaped, and those requirements are also dependent on the URL
+scheme.
+
+Never escape an already escaped component string.
+
+=back
+
+This implementation expects an escaped URL string to be passed to
+new() and will return a fully escaped URL string from as_string()
+and full_path().
+
+Individual components can be manipulated in unescaped or escaped
+form. The following methods return/accept unescaped strings:
+
+    scheme                  path
+    user                    params
+    password                query
+    host                    frag
+    port
+
+The following methods return/accept partial I<escaped> strings:
+
+    netloc                  eparams
+    epath                   equery
+
+I<Partial escaped> means that only reserved characters
+(i.e. ':', '@', '/', ';', '?', '=', '&' in addition to '%', '.' and '#')
+needs to be escaped when they are to be treated as normal characters.
+I<Fully escaped> means that all unsafe characters are escaped. Unsafe
+characters are all all control characters (%00-%1F and %7F), all 8-bit
+characters (%80-%FF) as well
+as '{', '}', '|', '\', '^', '[', ']' '`', '"', '<' and '>'.
+Note that the character '~' is B<not> considered
+unsafe by this library as it is common practice to use it to reference
+personal home pages, but it is still unsafe according to RFC 1738.
+
+=head1 ADDING NEW URL SCHEMES
+
+New URL schemes or alternative implementations for existing schemes
+can be added to your own code. To create a new scheme class use code
+like:
+
+   package MYURL::foo;
+   @ISA = (URI::URL::implementor());   # inherit from generic scheme
+
+The 'URI::URL::implementor()' function call with no parameters returns
+the name of the class which implements the generic URL scheme
+behaviour (typically C<URI::URL::_generic>). All hierarchical schemes
+should be derived from this class.
+
+Your class can then define overriding methods (e.g., new(), _parse()
+as required).
+
+To register your new class as the implementor for a specific scheme
+use code like:
+
+   URI::URL::implementor('x-foo', 'MYURL::foo');
+
+Any new URL created for scheme 'x-foo' will be implemented by your
+C<MYURL::foo> class. Existing URLs will not be affected.
+
+
+=head1 FUNCTIONS
+
+=over 3
+
+=item $url = URI::URL->new( $url_string [, $base_url] )
+
+This is the object constructor.  It will create a new URI::URL object,
+initialized from the URL string.
+
+=item $url = URI::URL->newlocal($path);
+
+Returns an URL object that denotes a path within the local filesystem.
+Paths not starting with '/' are interpreted relative to the current
+working directory.  This constructor always return an absolute 'file'
+URL.
+
+=item $url = url($url_string, [, $base_url])
+
+Alternative constructor function.  The url() function is exported by
+the URI::URL module and is easier both to type and read than calling
+C<URI::URL->new> directly.  Useful for constructs like this:
+
+   $h = url($str)->host;
+
+This function is just a wrapper for URI::URL->new.
+
+=item URI::URL::strict($bool)
+
+If strict is true then we croak on errors.  The function returns the
+previous value.
+
+=item URI::URL::implementor([$scheme, [$class]])
+
+Use this function to get or set implementor class for a scheme.
+Returns '' if specified scheme is not supported.  Returns generic URL
+class if no scheme specified.
+
+=back
+
+=head1 METHODS
+
+This section describes the methods available for an URI::URL object.
+Note that some URL schemes will disallow some of these methods and
+will croak if they are used.  Some URL schemes add additional methods
+that are described in the sections to follow.
+
+Attribute access methods marked with (*) can take an optional argument
+to set the value of the attribute, and they always return the old
+value.
+
+=over 3
+
+=item $url->abs([$base])
+
+The abs() method attempts to return a new absolute URI::URL object
+for a given URL.  In order to convert a relative URL into an absolute
+one, a I<base> URL is required. You can associate a default base with a
+URL either by passing a I<base> to the new() constructor when a
+URI::URL is created or using the base() method on the object later.
+Alternatively you can specify a one-off base as a parameter to the
+abs() method.
+
+The rel() method will do the opposite transformation.
+
+Some older parsers used to allow the scheme name to be present in the
+relative URL if it was the same as the base URL scheme.  RFC1808 says
+that this should be avoided, but you can enable this old behaviour by
+setting the $URI::URL::ABS_ALLOW_RELATIVE_SCHEME variable to a TRUE
+value.  The difference is demonstrated by the following examples:
+
+  url("http:foo")->abs("http://host/a/b")     ==>  "http:foo"
+
+  local $URI::URL::ABS_ALLOW_RELATIVE_SCHEME = 1;
+  url("http:foo")->abs("http://host/a/b")     ==>  "http:/host/a/foo"
+
+You can also have the abs() method ignore if there is too many ".."
+segments in the relative URL by setting
+$URI::URL::ABS_REMOTE_LEADING_DOTS to a TRUE value.  The difference is
+demonstrated by the following examples:
+
+  url("../../../foo")->abs("http://host/a/b")   ==> "http://host/../../foo"
+
+  local $URI::URL::ABS_REMOTE_LEADING_DOTS = 1;
+  url("../../../foo")->abs("http://host/a/b")   ==> "http://host/foo"
+
+
+=item $url->as_string
+
+Returns a string representing the URL in its canonical form.  All
+unsafe characters will be escaped.  This method is overloaded as the
+perl "stringify" operator, which means that URLs can be used as
+strings in many contexts.
+
+=item $url->base (*)
+
+Get/set the base URL associated with the current URI::URL object.  The
+base URL matters when you call the abs() method.
+
+=item $url->clone
+
+Returns a copy of the current URI::URL object.
+
+=item $url->crack
+
+Return a 9 element array with the following content:
+
+   0: $url->scheme *)
+   1: $url->user
+   2: $url->password
+   3: $url->host
+   4: $url->port
+   5: $url->epath
+   6: $url->eparams
+   7: $url->equery
+   8: $url->frag
+
+All elements except I<scheme> will be undefined if the corresponding
+URL part is not available.
+
+B<Note:> The scheme (first element) returned by crack will aways be
+defined.  This is different from what the $url->scheme returns, since
+it will return I<undef> for relative URLs.
+
+=item $url->default_port
+
+Returns the default port number for the URL scheme that the URI::URL
+belongs too.
+
+=item $url->eparams (*)
+
+Get/set the URL parameters in escaped form.
+
+=item $url->epath (*)
+
+Get/set the URL path in escaped form.
+
+=item $url->eq($other_url)
+
+Compare two URLs to decide if they match or not.  The rules for how
+comparison is made varies for different parts of the URLs; scheme and
+netloc comparison is case-insensitive, and escaped chars match their
+%XX encoding unless they are "reserved" or "unsafe".
+
+=item $url->equery (*)
+
+Get/set the URL query string in escaped form.
+
+=item $url->full_path
+
+Returns the string "/path;params?query".  This is the string that is
+passed to a remote server in order to access the document.
+
+=item $url->frag (*)
+
+Get/set the fragment (unescaped)
+
+=item $url->host (*)
+
+Get/set the host (unescaped)
+
+=item $url->netloc (*)
+
+Get/set the network location in escaped form.  Setting the network
+location will affect 'user', 'password', 'host' and 'port'.
+
+=item $url->params (*)
+
+Get/set the URL parameters (unescaped)
+
+=item $url->password (*)
+
+Get/set the password (unescaped)
+
+=item $url->path (*)
+
+Get/set the path (unescaped).  This method will croak if any of the
+path components in the return value contain the "/" character.  You
+should use the epath() method to be safe.
+
+=item $url->path_components (*)
+
+Get/set the path using a list of unescaped path components.  The
+return value will loose the distinction beween '.' and '%2E'.  When
+setting a value, a '.' is converted to be a literal '.' and is
+therefore encoded as '%2E'.
+
+=item $url->port (*)
+
+Get/set the network port (unescaped)
+
+=item $url->rel([$base])
+
+Return a relative URL if possible.  This is the opposite of what the
+abs() method does.  For instance:
+
+   url("http://www.math.uio.no/doc/mail/top.html",
+       "http://www.math.uio.no/doc/linux/")->rel
+
+will return a relative URL with path set to "../mail/top.html" and
+with the same base as the original URL.
+
+If the original URL already is relative or the scheme or netloc does
+not match the base, then a copy of the original URL is returned.
+
+
+=item $url->print_on(*FILEHANDLE);
+
+Prints a verbose presentation of the contents of the URL object to
+the specified file handle (default STDERR).  Mainly useful for
+debugging.
+
+=item $url->scheme (*)
+
+Get/set the scheme for the URL.
+
+=item $url->query (*)
+
+Get/set the query string (unescaped).  This method will croak if the
+string returned contains both '+' and '%2B' or '=' together with '%3D'
+or '%26'.  You should use the equery() method to be safe.
+
+=item $url->user (*)
+
+Get/set the URL user name (unescaped)
+
+=back
+
+=head1 HTTP METHODS
+
+For I<http> URLs you may also access the query string using the
+keywords() and the query_form() methods.  Both will croak if the query
+is not of the correct format.  The encodings look like this:
+
+  word1+word2+word3..        # keywords
+  key1=val1&key2=val2...     # query_form
+
+Note: These functions does not return the old value when they are used
+to set a value of the query string.
+
+=over 3
+
+=item $url->keywords (*)
+
+The keywords() method returns a list of unescaped strings.  The method
+can also be used to set the query string by passing in the keywords as
+individual arguments to the method.
+
+=item $url->query_form (*)
+
+The query_form() method return a list of unescaped key/value pairs.
+If you assign the return value to a hash you might loose some values
+if the key is repeated (which it is allowed to do).
+
+This method can also be used to set the query sting of the URL like this:
+
+  $url->query_form(foo => 'bar', foo => 'baz', equal => '=');
+
+If the value part of a key/value pair is a reference to an array, then
+it will be converted to separate key/value pairs for each value.  This
+means that these two calls are equal:
+
+  $url->query_form(foo => 'bar', foo => 'baz');
+  $url->query_form(foo => ['bar', 'baz']);
+
+=back
+
+=head1 FILE METHODS
+
+The I<file> URLs implement the local_path() method that returns a path
+suitable for access to files within the current filesystem.  These
+methods can B<not> be used to set the path of the URL.
+
+=over 3
+
+=item $url->local_path
+
+This method is really just an alias for one of the methods below
+depending on what system you run on.
+
+=item $url->unix_path
+
+Returns a path suitable for use on a Unix system.  This method will
+croak if any of the path segments contains a "/" or a NULL character.
+
+=item $url->dos_path
+
+Returns a path suitable for use on a MS-DOS or MS-Windows system.
+
+=item $url->mac_path
+
+Returns a path suitable for use on a Macintosh system.
+
+=item $url->vms_path
+
+Returns a path suitable for use on a VMS system.  VMS is a trademark
+of Digital.
+
+=back
+
+=head1 GOPHER METHODS
+
+The methods access the parts that are specific for the gopher URLs.
+These methods access different parts of the $url->path.
+
+=over 3
+
+=item $url->gtype (*)
+
+=item $url->selector (*)
+
+=item $url->search (*)
+
+=item $url->string (*)
+
+=back
+
+=head1 NEWS METHODS
+
+=over 3
+
+=item $url->group (*)
+
+=item $url->article (*)
+
+=back
+
+=head1 WAIS METHODS
+
+The methods access the parts that are specific for the wais URLs.
+These methods access different parts of the $url->path.
+
+=over 3
+
+=item $url->database (*)
+
+=item $url->wtype (*)
+
+=item $url->wpath (*)
+
+=back
+
+=head1 MAILTO METHODS
+
+=over 3
+
+=item $url->address (*)
+
+The mail address can also be accessed with the netloc() method.
+
+=back
+
+
+=head1 WHAT A URL IS NOT
+
+URL objects do not, and should not, know how to 'get' or 'put' the
+resources they specify locations for, anymore than a postal address
+'knows' anything about the postal system. The actual access/transfer
+should be achieved by some form of transport agent class (see
+L<LWP::UserAgent>). The agent class can use the URL class, but should
+not be a subclass of it.
+
+=head1 AUTHORS / ACKNOWLEDGMENTS
+
+This module is (distantly) based on the C<wwwurl.pl> code in the
+libwww-perl distribution developed by Roy Fielding
+<fielding@ics.uci.edu>, as part of the Arcadia project at the
+University of California, Irvine, with contributions from Brooks
+Cutter.
+
+Gisle Aas <aas@sn.no>, Tim Bunce <Tim.Bunce@ig.co.uk>, Roy Fielding
+<fielding@ics.uci.edu> and Martijn Koster <m.koster@webcrawler.com>
+(in English alphabetical order) have collaborated on the complete
+rewrite for Perl 5, with input from other people on the libwww-perl
+mailing list.
+
+If you have any suggestions, bug reports, fixes, or enhancements, send
+them to the libwww-perl mailing list at <libwww-perl@ics.uci.edu>.
+
+=head1 COPYRIGHT
+
+Copyright 1995-1997 Gisle Aas.
+Copyright 1995 Martijn Koster.
+
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/_generic.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/_generic.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/_generic.pm	(revision 16571)
@@ -0,0 +1,514 @@
+#####################################################################
+#
+#       Internal pre-defined generic scheme support
+#
+# In this implementation all schemes are subclassed from
+# URI::URL::_generic. This turns out to have reasonable mileage.
+# See also draft-ietf-uri-relative-url-06.txt
+
+package URI::URL::_generic;           # base support for generic-RL's
+require URI::URL;
+@ISA = qw(URI::URL);
+
+use URI::Escape qw(uri_escape uri_unescape %escapes);
+
+
+sub new {                               # inherited by subclasses
+    my($class, $init, $base) = @_;
+    my $url = bless { }, $class;        # create empty object
+    $url->_parse($init);                # parse $init into components
+    $url->base($base) if $base;
+    $url;
+}
+
+
+# Generic-RL parser
+# See draft-ietf-uri-relative-url-06.txt Section 2
+
+sub _parse {
+    my($self, $u, @comps) = @_;
+    return unless defined $u;
+
+    # Deside which components to parse (scheme & path is manatory)
+    @comps = qw(netloc query params frag) unless (@comps);
+    my %parse = map {$_ => 1} @comps;
+
+    # This parsing code is based on
+    #   draft-ietf-uri-relative-url-06.txt Section 2.4
+
+    # 2.4.1
+    $self->{'frag'} = uri_unescape($1)
+      if $parse{'frag'} && $u =~ s/#(.*)$//;
+    # 2.4.2
+    $self->{'scheme'} = lc($1) if $u =~ s/^\s*([\w\+\.\-]+)://;
+    # 2.4.3
+    $self->netloc("$1")	# passing $1 directly fails if netloc is autoloaded
+      if $parse{'netloc'} && $u =~ s!^//([^/]*)!!;
+    # 2.4.4
+    $self->{'query'} = $1
+      if $parse{'query'} && $u =~ s/\?(.*)//;
+    # 2.4.5
+    $self->{'params'} = $1
+      if $parse{'params'} && $u =~ s/;(.*)//;
+
+    # 2.4.6
+    #
+    # RFC 1738 says:
+    #
+    #     Note that the "/" between the host (or port) and the
+    #     url-path is NOT part of the url-path.
+    #
+    # however, RFC 1808, 2.4.6. says:
+    #
+    #    Even though the initial slash is not part of the URL path,
+    #    the parser must remember whether or not it was present so
+    #    that later processes can differentiate between relative
+    #    and absolute paths.  Often this is done by simply storing
+    #    he preceding slash along with the path.
+    #
+    # In version < 4.01 of URI::URL we used to strip the leading
+    # "/" when asked for $self->path().  This created problems for
+    # the consitency of the interface, so now we just consider the
+    # slash to be part of the path and we also make an empty path
+    # default to "/".
+
+    # we don't test for $parse{path} becase it is mandatory
+    $self->{'path'} = $u;
+}
+
+
+# Generic-RL stringify
+#
+sub as_string
+{
+    my $self = shift;
+    return $self->{'_str'} if $self->{'_str'};
+
+    my($scheme, $netloc, $frag) = @{$self}{qw(scheme netloc frag)};
+
+    my $u = $self->full_path(1);  # path+params+query
+
+    # rfc 1808 says:
+    #    Note that the fragment identifier (and the "#" that precedes
+    #    it) is not considered part of the URL.  However, since it is
+    #    commonly used within the same string context as a URL, a parser
+    #    must be able to recognize the fragment when it is present and
+    #    set it aside as part of the parsing process.
+    $u .= "#" . uri_escape($frag, $URI::URL::unsafe) if defined $frag;
+
+    $u = "//$netloc$u" if defined $netloc;
+    $u = "$scheme:$u" if $scheme;
+    # Inline: uri_escape($u, $URI::URL::unsafe);
+    $u =~ s/([$URI::URL::unsafe])/$escapes{$1}/go;
+    $self->{'_str'} = $u;  # set cache and return
+}
+
+# Generic-RL stringify full path "path;params?query"
+#
+sub full_path
+{
+    my($self, $dont_escape)  = @_;
+    my($path, $params, $query) = @{$self}{'path', 'params', 'query'};
+    my $p = '';
+    $p .= $path if defined $path;
+    # see comment in _parse 2.4.6 about the next line
+    $p = "/$p" if defined($self->{netloc}) && $p !~ m:^/:;
+    $p .= ";$params" if defined $params;
+    $p .= "?$query"  if defined $query;
+    return $p if $dont_escape;
+    # Inline: URI::Escape::uri_escape($p, $URI::URL::unsafe);
+    $p =~ s/([$URI::URL::unsafe])/$escapes{$1}/go;
+    $p;
+}
+
+# default_port()
+#
+# subclasses will usually want to override this
+#
+sub default_port { undef; }
+
+
+#####################################################################
+#
+# Methods to handle URL's elements
+
+# These methods always return the current value,
+# so you can use $url->path to read the current value.
+# If a new value is passed, e.g. $url->path('foo'),
+# it also sets the new value, and returns the previous value.
+# Use $url->path(undef) to set the value to undefined.
+
+sub netloc {
+    my $self = shift;
+    my $old = $self->_elem('netloc', @_);
+    return $old unless @_;
+
+    # update fields derived from netloc
+    my $nl = $self->{'netloc'} || '';
+    if ($nl =~ s/^([^:@]*):?(.*?)@//){
+	$self->{'user'}     = uri_unescape($1);
+	$self->{'password'} = uri_unescape($2) if $2 ne '';
+    }
+    if ($nl =~ /^([^:]*):?(\d*)$/){
+	my $port = $2;
+	# Since this happes so frequently, we inline this call:
+	#    my $host = uri_unescape($1);
+	my $host = $1;
+	$host =~ s/%([\dA-Fa-f]{2})/chr(hex($1))/eg;
+	$self->{'host'} = $host;
+	if ($port ne '') {
+	    $self->{'port'} = $port;
+	    if ($self->default_port == $port) {
+		$self->{'netloc'} =~ s/:\d+//;
+	    }
+	} elsif (defined $self->{'netloc'}) {
+	    $self->{'netloc'} =~ s/:$//;  # handle empty port spec
+	}
+    }
+    $self->{'_str'} = '';
+    $old;
+}
+
+
+# A U T O  L O A D E R
+# Don't remove this comment, it keeps AutoSplit happy!!
+# @ISA = qw(AutoLoader)
+#
+# The rest of the methods are only loaded on demand.  Stubs are neccesary
+# for inheritance to work.
+
+#sub netloc;  # because netloc is used by the _parse()
+sub user;
+sub password;
+sub host;
+sub port;
+sub _netloc_elem;
+sub epath;
+sub path;
+sub path_components;
+sub eparams;
+sub params;
+sub equery;
+sub query;
+sub frag;
+sub crack;
+sub abs;
+sub rel;
+sub eq;
+
+1;
+__END__
+
+
+# Fields derived from generic netloc:
+sub user     { shift->_netloc_elem('user',    @_); }
+sub password { shift->_netloc_elem('password',@_); }
+sub host     { shift->_netloc_elem('host',    @_); }
+
+sub port {
+    my $self = shift;
+    my $old = $self->_netloc_elem('port', @_);
+    defined($old) ? $old : $self->default_port;
+}
+
+sub _netloc_elem {
+    my($self, $elem, @val) = @_;
+    my $old = $self->_elem($elem, @val);
+    return $old unless @val;
+
+    # update the 'netloc' element
+    my $nl = '';
+    my $host = $self->{'host'};
+    if (defined $host) {  # can't be any netloc without any host
+	my $user = $self->{'user'};
+	$nl .= uri_escape($user, $URI::URL::reserved) if defined $user;
+	$nl .= ":" . uri_escape($self->{'password'}, $URI::URL::reserved)
+	  if defined($user) and defined($self->{'password'});
+	$nl .= '@' if length $nl;
+	$nl .= uri_escape($host, $URI::URL::reserved);
+	my $port = $self->{'port'};
+	$nl .= ":$port" if defined($port) && $port != $self->default_port;
+    }
+    $self->{'netloc'} = $nl;
+    $self->{'_str'} = '';
+    $old;
+}
+
+sub epath {
+     my $self = shift;
+     my $old = $self->_elem('path', @_);
+     return '/' if !defined($old) || !length($old);
+     return "/$old" if $old !~ m|^/| && defined $self->{'netloc'};
+     $old;
+}
+
+sub path {
+    my $self = shift;
+    my $old = $self->_elem('path',
+		      map uri_escape($_, $URI::URL::reserved_no_slash), @_);
+    return unless defined wantarray;
+    return '/' if !defined($old) || !length($old);
+    Carp::croak("Path components contain '/' (you must call epath)")
+	if $old =~ /%2[fF]/ and !@_;
+    $old = "/$old" if $old !~ m|^/| && defined $self->{'netloc'};
+    return uri_unescape($old);
+}
+
+sub path_components {
+    my $self = shift;
+    my $old = $self->{'path'};
+    $old = '' unless defined $old;
+    $old = "/$old" if $old !~ m|^/| && defined $self->{'netloc'};
+    if (@_) {
+	$self->_elem('path',
+		     join("/", map {uri_escape($_, $URI::URL::reserved)} @_));
+    }
+    map { uri_unescape($_) } split("/", $old, -1);
+}
+
+sub eparams  { shift->_elem('params',  @_); }
+
+sub params {
+    my $self = shift;
+    my $old = $self->_elem('params', map {uri_escape($_,$URI::URL::reserved_no_form)} @_);
+    return uri_unescape($old) if defined $old;
+    undef;
+}
+
+sub equery   { shift->_elem('query',   @_); }
+
+sub query {
+    my $self = shift;
+    my $old = $self->_elem('query', map { uri_escape($_, $URI::URL::reserved_no_form) } @_);
+    if (defined(wantarray) && defined($old)) {
+	if ($old =~ /%(?:26|2[bB]|3[dD])/) {  # contains escaped '=' '&' or '+'
+	    my $mess;
+	    for ($old) {
+		$mess = "Query contains both '+' and '%2B'"
+		  if /\+/ && /%2[bB]/;
+		$mess = "Form query contains escaped '=' or '&'"
+		  if /=/  && /%(?:3[dD]|26)/;
+	    }
+	    if ($mess) {
+		Carp::croak("$mess (you must call equery)");
+	    }
+	}
+	# Now it should be safe to unescape the string without loosing
+	# information
+	return uri_unescape($old);
+    }
+    undef;
+
+}
+
+# No efrag method because the fragment is always stored unescaped
+sub frag     { shift->_elem('frag', @_); }
+
+sub crack
+{
+    my $self = shift;
+    return $self unless wantarray;
+    my @c = @{$self}{qw(scheme user password host port path params query frag)};
+    if (!$c[0]) {
+	# try to determine scheme
+	my $base = $self->base;
+	$c[0] = $base->scheme if $base;
+	$c[0] ||= 'http';  # last resort, default in URI::URL::new
+    }
+    $c[4] ||= $self->default_port;
+    @c;
+}
+
+# Generic-RL: Resolving Relative URL into an Absolute URL
+#
+# Based on RFC1808 section 4
+#
+sub abs
+{
+    my($self, $base, $allow_relative_scheme) = @_;
+    $allow_relative_scheme = $URI::URL::ABS_ALLOW_RELATIVE_SCHEME if @_ < 3;
+    my $embed = $self->clone;
+
+    $base = $self->base unless $base;      # default to default base
+    return $embed unless $base;            # we have no base (step1)
+
+    $base = new URI::URL $base unless ref $base; # make obj if needed
+
+    my($scheme, $host, $path, $params, $query, $frag) =
+	@{$embed}{qw(scheme host path params query frag)};
+
+    # just use base if we are empty             (2a)
+    return $base->clone
+      unless grep(defined($_) && $_ ne '',
+		  $scheme,$host,$port,$path,$params,$query,$frag);
+
+    # if we have a scheme we must already be absolute   (2b),
+    #
+    # but sec. 5.2 also says: Some older parsers allow the scheme name
+    # to be present in a relative URL if it is the same as the base
+    # URL scheme.  This is considered to be a loophole in prior
+    # specifications of the partial URLs and should be avoided by
+    # future parsers.
+    #
+    # The old behavoir can be enabled by passing a TRUE value to the
+    # $allow_relative_scheme parameter.
+    return $embed if $scheme &&
+      (!$allow_relative_scheme || $scheme ne $base->{'scheme'});
+
+    $embed->{'_str'} = '';                      # void cached string
+    $embed->{'scheme'} = $base->{'scheme'};     # (2c)
+
+    return $embed if $embed->{'netloc'};        # (3)
+    $embed->netloc($base->{'netloc'});          # (3)
+
+    return $embed if $path =~ m:^/:;            # (4)
+
+    if ($path eq '') {                          # (5)
+	$embed->{'path'} = $base->{'path'};     # (5)
+
+	return $embed if defined $embed->{'params'}; # (5a)
+	$embed->{'params'} = $base->{'params'};      # (5a)
+
+	return $embed if defined $embed->{'query'};  # (5b)
+	$embed->{'query'} = $base->{'query'};        # (5b)
+
+	return $embed;
+    }
+
+    # (Step 6)  # draft 6 suggests stack based approach
+
+    my $basepath = $base->{'path'};
+    my $relpath  = $embed->{'path'};
+
+    $basepath =~ s!^/!!;
+    $basepath =~ s!/$!/.!;                # prevent empty segment
+    my @path = split('/', $basepath);     # base path into segments
+    pop(@path);                           # remove last segment
+
+    $relpath =~ s!/$!/.!;                 # prevent empty segment
+
+    push(@path, split('/', $relpath));    # append relative segments
+
+    my @newpath = ();
+    my $isdir = 0;
+    my $segment;
+
+    foreach $segment (@path) {            # left to right
+	if ($segment eq '.') {            # ignore "same" directory
+	    $isdir = 1;
+	}
+	elsif ($segment eq '..') {
+	    $isdir = 1;
+	    my $last = pop(@newpath);
+	    if (!defined $last) {         # nothing to pop
+		push(@newpath, $segment); # so must append
+	    }
+	    elsif ($last eq '..') {       # '..' cannot match '..'
+		# so put back again, and append
+		push(@newpath, $last, $segment);
+	    }
+	    #else
+		# it was a component,
+		# keep popped
+	} else {
+	    $isdir = 0;
+	    push(@newpath, $segment);
+	}
+    }
+
+    if ($URI::URL::ABS_REMOTE_LEADING_DOTS) {
+	shift @newpath while @newpath && $newpath[0] =~ /^\.\.?$/;
+    }
+
+    $embed->{'path'} = '/' . join('/', @newpath) .
+	($isdir && @newpath ? '/' : '');
+
+    $embed;
+}
+
+# The oposite of $url->abs.  Return a URL as much relative as possible
+sub rel {
+    my($self, $base) = @_;
+    my $rel = $self->clone;
+    $base = $self->base unless $base;
+    return $rel unless $base;
+    $base = new URI::URL $base unless ref $base;
+    $rel->base($base);
+
+    my($scheme, $netloc, $path) = @{$rel}{qw(scheme netloc path)};
+    if (!defined($scheme) && !defined($netloc)) {
+	# it is already relative
+	return $rel;
+    }
+
+    my($bscheme, $bnetloc, $bpath) = @{$base}{qw(scheme netloc path)};
+    for ($bscheme, $bnetloc, $netloc) { $_ = '' unless defined }
+
+    unless ($scheme eq $bscheme && $netloc eq $bnetloc) {
+	# different location, can't make it relative
+	return $rel;
+    }
+
+    for ($path, $bpath) {  $_ = "/$_" unless m,^/,; }
+
+    # Make it relative by eliminating scheme and netloc
+    $rel->{'scheme'} = undef;
+    $rel->netloc(undef);
+
+    # This loop is based on code from Nicolai Langfeldt <janl@ifi.uio.no>.
+    # First we calculate common initial path components length ($li).
+    my $li = 1;
+    while (1) {
+	my $i = index($path, '/', $li);
+	last if $i < 0 ||
+                $i != index($bpath, '/', $li) ||
+	        substr($path,$li,$i-$li) ne substr($bpath,$li,$i-$li);
+	$li=$i+1;
+    }
+    # then we nuke it from both paths
+    substr($path, 0,$li) = '';
+    substr($bpath,0,$li) = '';
+
+    if ($path eq $bpath && defined($rel->frag) && !defined($rel->equery)) {
+        $rel->epath('');
+    } else {
+        # Add one "../" for each path component left in the base path
+        $path = ('../' x $bpath =~ tr|/|/|) . $path;
+	$path = "./" if $path eq "";
+        $rel->epath($path);
+    }
+
+    $rel;
+}
+
+
+# Compare two URLs
+sub eq {
+    my($self, $other) = @_;
+    local($^W) = 0; # avoid warnings if we compare undef values
+    $other = URI::URL->new($other, $self) unless ref $other;
+
+    # Compare scheme and netloc
+    return 0 if ref($self) ne ref($other);                # must be same class
+    return 0 if $self->scheme ne $other->scheme;          # Always lower case
+    return 0 if lc($self->netloc) ne lc($other->netloc);  # Case-insensitive
+
+    # Compare full_path:
+    # According to <draft-ietf-http-v11-spec-05>:
+    # Characters other than those in the "reserved" and "unsafe" sets
+    # are equivalent to their %XX encodings.
+    my $fp1 = $self->full_path;
+    my $fp2 = $other->full_path;
+    for ($fp1, $fp2) {
+	s,%([\dA-Fa-f]{2}),
+	  my $x = $1;
+	  my $c = chr(hex($x));
+	  $c =~ /^[;\/?:\@&=+\"\#%<>\0-\040\177]/ ? "%\L$x" : $c;
+	,eg;
+    }
+    return 0 if $fp1 ne $fp2;
+    return 0 if $self->frag ne $other->frag;
+    1;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/_login.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/_login.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/_login.pm	(revision 16571)
@@ -0,0 +1,25 @@
+package URI::URL::_login;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+
+# Generic terminal logins.  This is used as a base class for 'telnet',
+# 'tn3270', and 'rlogin' URL schemes.
+
+
+sub _parse {
+    my($self, $init) = @_;
+    # All we want from _generic is the 'netloc' handling.
+    $self->URI::URL::_generic::_parse($init, 'netloc');
+}
+
+
+*path      = \&URI::URL::bad_method;
+*epath     = \&URI::URL::bad_method;
+*query     = \&URI::URL::bad_method;
+*equery    = \&URI::URL::bad_method;
+*params    = \&URI::URL::bad_method;
+*eparams   = \&URI::URL::bad_method;
+*frag      = \&URI::URL::bad_method;
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/data.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/data.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/data.pm	(revision 16571)
@@ -0,0 +1,160 @@
+package URI::URL::data;
+
+# Implements data:-URLs as specified in draft-masinter-url-data-02.txt
+#
+# Abstract
+#
+# A new URL scheme, "data", is defined. It allows inclusion of small
+# data items as "immediate" data, as if it had been included externally.
+#
+# Description
+#
+# Some applications that use URLs also have a need to embed (small)
+# media type data directly inline. This document defines a new URL
+# scheme that would work like 'immediate addressing'. The URLs are of
+# the form:
+#
+#        data:[<mediatype>][;base64],<data>
+#
+
+require URI::URL;
+@ISA = qw(URI::URL);
+
+use URI::Escape;
+use MIME::Base64 ();
+
+# as defined in rfc1522.txt
+my $tspecial  = qq(()<>@,;:/[]?.=);
+my $tokenchar = qq([^\\s\000-\037\177-\377\Q$tspecial\E]);
+
+
+sub new {
+    my($class, $init, $base) = @_;
+
+    my $self = bless { }, $class;
+
+    $self->{'scheme'} = lc($1) if $init =~ s/^\s*([\w\+\.\-]+)://;
+    $self->{'frag'} = $1 if $init =~ s/\#(.*)$//;
+
+    my $type = "";
+    if ($init =~ s/^($tokenchar+\/$tokenchar+)//o) {
+	$type = $1;
+    }
+    while ($init =~ s/^;($tokenchar+)=([^,;]*)//o) {
+	# XXX should we unescape the parst
+	$type .= ";$1=$2";
+    }
+
+    $self->{'media_type'} = $type;
+
+    my $base64;
+    if ($init =~ s/^;base64//i) {
+	$base64 = 1;
+    }
+    
+    $init =~ s/^,//;
+    if ($base64) {
+	$self->{'base64'} = uri_unescape($init);
+    } else {
+	$self->{'data'} = uri_unescape($init);
+    }
+    $self->base($base) if $base;
+    $self;
+}
+
+sub media_type
+{
+    my $self = shift;
+    my $old = $self->{'media_type'};
+    if (@_) {
+	$self->{'media_type'} = shift || "";
+	delete $self->{'_str'};
+    }
+    my($type, $param) = split(/;/, $old, 2);
+    if ($type) {
+	$type = lc $type;
+    } else {
+	$type = "text/plain";
+	$param = "charset=US-ASCII" unless $param;
+    }
+    if (wantarray) {
+	return ($type, $param);
+    } else {
+	return $type;
+    }
+}
+
+sub data
+{
+    my $self = shift;
+    my $old_data;
+    my $old_base64;
+    $old_data = $self->{'data'};
+    $old_base64 = $self->{'base64'};
+    if (@_) {
+	if ($_[1]) { # base64 flag
+	    $self->{'base64'} = $_[0];
+	    delete $self->{'data'};
+	} else {
+	    $self->{'data'} = $_[0];
+	    delete $self->{'base64'};
+	}
+	delete $self->{'_str'};
+    }
+    unless (defined $old_data) {
+	$old_data = MIME::Base64::decode($old_base64);
+	$self->{'data'} = $old_data unless @_;
+    }
+    $old_data;
+}
+
+
+sub crack
+{
+    my $self = shift;
+    ($self->{'scheme'}
+     || 'data',          # scheme
+     undef,              # user
+     undef,              # passwd
+     undef,              # host
+     undef,              # port
+     $self->data,        # path
+     $self->{'media_type'},  # params
+     undef,              # query
+     $self->{'frag'}     # fragment
+    )
+}
+
+sub as_string {
+    my $self = shift;
+    return $self->{'_str'} if $self->{'_str'};
+    my $str = ($self->{'scheme'} || 'data') . ":";
+    $str .= $self->{'media_type'};
+    if (defined $self->{'base64'}) {
+	$str .= ";base64,$self->{'base64'}";
+    } else {
+	my $urlenc = uri_escape($self->{'data'});
+	my $base64 = MIME::Base64::encode($self->{'data'});
+	if (length($base64) + 7 < length($urlenc)) {
+	    $str .= ";base64,$base64";
+	    $self->{'base64'} = $base64;
+	} else {
+	    $str .= ",$urlenc";
+	}
+    }
+    $self->{'_str'} = $str;
+}
+
+sub eq {
+    my($self, $other) = @_;
+    return 0 if ref($self) ne ref($other);
+    return 0 if $self->scheme ne $other->scheme;
+
+    my $mt1 = join(";", $self->media_type);
+    my $mt2 = join(";", $other->media_type);
+    return 0 if $mt1 ne $mt2;
+
+    $self->data eq $other->data;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/file.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/file.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/file.pm	(revision 16571)
@@ -0,0 +1,165 @@
+package URI::URL::file;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+require Carp;
+require Config;
+
+# First we try to determine what kind of system we run on
+my $os = $Config::Config{'osname'};
+OS: {
+    $ostype = 'vms', last if $os eq 'VMS';
+    $ostype = 'dos', last if $os =~ /^(?:os2|mswin32|msdos)$/i;
+    $ostype = 'mac', last if $os eq "Mac";
+    $ostype = 'unix';  # The default
+}
+# NOTE: If you add more types to this list, remember to add a xxx_path
+# method as well.
+
+# This is the BNF found in RFC 1738:
+#
+# fileurl        = "file://" [ host | "localhost" ] "/" fpath
+# fpath          = fsegment *[ "/" fsegment ]
+# fsegment       = *[ uchar | "?" | ":" | "@" | "&" | "=" ]
+# Note that fsegment can contain '?' (query) but not ';' (param)
+
+sub _parse {
+    my($self, $init) = @_;
+    # The file URL can't have query
+    $self->URI::URL::_generic::_parse($init, qw(netloc path params frag));
+}
+
+# sub local_path { ... }
+#
+# Returns a path suitable for use on the local system (we just
+# set up an alias (derived from $ostype) to one of the path methods
+# defined below)
+*local_path = \&{$ostype . "_path"};
+
+*query  = \&URI::URL::bad_method;
+*equery = \&URI::URL::bad_method;
+
+# A U T O  L O A D E R
+# Don't remove this comment, it keeps AutoSplit happy!!
+# @ISA = qw(AutoLoader)
+#
+# These methods are autoloaded as needed
+sub newlocal;
+sub unix_path;
+sub dos_path ;
+sub mac_path ;
+sub vms_path ;
+1;
+__END__
+
+sub newlocal {
+    my($class, $path) = @_;
+
+    Carp::croak("Only implemented for Unix and OS/2 file systems")
+      unless $ostype eq "unix" or $^O =~ /os2|mswin32/i;
+    # XXX: Should implement the same thing for other systems
+
+    my $url = new URI::URL "file:";
+    unless (defined $path and
+    	    ($path =~ m:^/: or 
+	     ($^O eq 'os2' and Cwd::sys_is_absolute($path)) or
+	     ($^O eq 'MSWin32' and $path =~ m<^[A-Za-z]:[\\/]|^[\\/]{2}>))) {
+	require Cwd;
+	my $cwd = Cwd::fastcwd();
+	$cwd =~ s:/?$:/:; # force trailing slash on dir
+	$path = (defined $path) ? $cwd . $path : $cwd;
+    }
+    $url->path($path);
+    $url;
+}
+
+sub unix_path
+{
+    my $self = shift;
+    my @p;
+    for ($self->path_components) {
+	Carp::croak("Path component contains '/' or '\0'") if m|[\0/]|;
+	if (@p) {
+	    next unless length $_;   # skip empty path segments
+	    next if $_ eq '.';       # skip these too
+	    if ($_ eq '..' && $p[-1] ne '..') {  # go up one level
+		pop(@p) if $p[-1] ne '';
+		next;
+	    }
+	}
+	push(@p, $_);
+    }
+    shift(@p) if @p > 1 && $p[0] eq '.';   # './' rendundant if there is more
+    return '/' if !@p || (@p == 1 && $p[0] eq '');
+    join('/', @p);
+}
+
+sub dos_path
+{
+    my $self = shift;
+    my @p;
+    for ($self->path_components) {
+	Carp::croak("Path component contains '/' or '\\'") if m|[/\\]|;
+	push(@p, uc $_);
+    }
+    my $p = join("\\", @p);
+    $p =~ s/^\\([A-Z]:)/$1/;  # Fix drive letter specification
+    $p;
+}
+
+sub mac_path
+{
+    my $self = shift;
+    my @p;
+    for ($self->path_components) {
+	Carp::croak("Path component contains ':'") if /:/;
+	# XXX: Should probably want to do something about ".." and "."
+	# path segments.  I don't know how these are represented in
+	# the Machintosh file system.  If these are valid file names
+	# then we should split the path ourself, as $u->path_components
+	# loose the distinction between '.' and '%2E'.
+	push(@p, $_);
+    }
+    if (@p && $p[0] eq '') {
+	shift @p;
+    } else {
+	unshift(@p, '');
+    }
+    join(':', @p);
+}
+
+sub vms_path
+{
+    # ????? Can some VMS people please redo this function ??????
+
+    # This is implemented based on what RFC1738 (sec 3.10) says in the
+    # VMS file example:
+    #
+    #  DISK$USER:[MY.NOTES]NOTE123456.TXT
+    #
+    #      that might become
+    #
+    #  file:/disk$user/my/notes/note12345.txt
+    #
+    # BEWARE: I don't have a VMS machine myself so this is pure guesswork!!!
+
+    my $self = shift;
+    my @p = $self->path_components;
+    my $abs = 0;
+    if (@p && $p[0] eq '') {
+	shift @p;
+	$abs = 1;
+    }
+    # First I assume there must be a dollar in a disk spesification
+    my $p = '';
+    $p = uc(shift(@p)) . ":"  if @p && $p[0] =~ /\$/;
+    my $file = pop(@p);
+    $p .= "[" . join(".", map{uc($_)} @p) . "]" if @p;
+    $p .= uc $file;
+    # XXX: How is an absolute path different from a relative one??
+    $p =~ s/\[/[./ unless $abs;
+    # XXX: How is a directory denoted??
+    $p;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/finger.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/finger.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/finger.pm	(revision 16571)
@@ -0,0 +1,6 @@
+package URI::URL::finger;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+sub default_port { 79 }
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/ftp.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/ftp.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/ftp.pm	(revision 16571)
@@ -0,0 +1,76 @@
+package URI::URL::ftp;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+sub default_port { 21 }
+
+sub _parse {
+    my($self, $init) = @_;
+    # The ftp URLs can't have any query string
+    $self->URI::URL::_generic::_parse($init, qw(netloc path params frag));
+    1;
+}
+
+
+sub user
+{
+    my($self, @val) = @_;
+    my $old = $self->SUPER::user(@val);
+    defined $old ? $old : "anonymous";
+}
+
+BEGIN {
+    $whoami = undef;
+    $fqdn   = undef;
+}
+
+sub password
+{
+    my($self, @val) = @_;
+    my $old = $self->SUPER::password(@val);
+    unless (defined $old) {
+	my $user = $self->user;
+	if ($user eq 'anonymous' || $user eq 'ftp') {
+	    # anonymous ftp login password
+	    unless (defined $fqdn) {
+		eval {
+		    require Net::Domain;
+		    $fqdn = Net::Domain::hostfqdn();
+		};
+		if ($@) {
+		    $fqdn = '';
+		}
+	    }
+	    unless (defined $whoami) {
+		$whoami = $ENV{USER} || $ENV{LOGNAME} || $ENV{USERNAME};
+		unless ($whoami) {
+		    if ($^O eq 'MSWin32') { $whoami = Win32::LoginName() }
+		    else {
+		        $whoami = getlogin || getpwuid($<) || 'unknown';
+		    }
+		}
+	    }
+	    $old = "$whoami\@$fqdn";
+	} else {
+	    $old = "";
+	}
+    }
+    $old;
+}
+
+sub crack
+{
+    my $self = shift;
+    my @c = $self->SUPER::crack;
+    if ($c[3] && !$c[1]) {
+	# hostname defined, but user is undefined
+	$c[1] = $self->user;
+	$c[2] = $self->password;
+    }
+    @c;
+}
+
+*query  = \&URI::URL::bad_method;
+*equery = \&URI::URL::bad_method;
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/gopher.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/gopher.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/gopher.pm	(revision 16571)
@@ -0,0 +1,82 @@
+package URI::URL::gopher;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+use URI::Escape qw(uri_unescape);
+
+sub default_port { 70 }
+
+sub _parse {
+    my($self, $init)   = @_;
+    $self->URI::URL::_generic::_parse($init, qw(netloc path));
+    $self->_parse_gopherpath;
+}
+
+sub path {
+    my $self = shift;
+    my $old = $self->URI::URL::_generic::path(@_);
+    return $old unless @_;
+    $self->_parse_gopherpath;
+    $old;
+}
+
+sub epath {
+    my $self = shift;
+    my $old = $self->URI::URL::_generic::epath(@_);
+    return $old unless @_;
+    $self->_parse_gopherpath;
+    $old;
+}
+
+sub _parse_gopherpath {
+    my $self = shift;
+    my $p = $self->{'path'};
+    # not according to RFC1738, but many popular browsers accept
+    # gopher URLs with a '?' before the search string.
+    $p =~ s/\?/\t/;
+    $p = uri_unescape($p);
+
+    if (defined($p) && $p ne '/' && $p =~ s!^/?(.)!!) {
+	$self->{'gtype'} = $1;
+    } else {
+	$self->{'gtype'} = "1";
+	$p = "";
+    }
+
+    delete $self->{'selector'};
+    delete $self->{'search'};
+    delete $self->{'string'};
+
+    my @parts = split(/\t/, $p, 3);
+    $self->{'selector'} = shift @parts if @parts;
+    $self->{'search'}   = shift @parts if @parts;
+    $self->{'string'}   = shift @parts if @parts;
+}
+
+
+sub gtype    { shift->_path_elem('gtype',    @_); }
+sub selector { shift->_path_elem('selector', @_); }
+sub search   { shift->_path_elem('search',   @_); }
+sub string   { shift->_path_elem('string',   @_); }
+
+sub _path_elem {
+    my($self, $elem, @val) = @_;
+    my $old = $self->_elem($elem, @val);
+    return $old unless @val;
+
+    # construct new path based on elements
+    my $path = "/$self->{'gtype'}";
+    $path .= "$self->{'selector'}" if defined $self->{'selector'};
+    $path .= "\t$self->{'search'}" if defined $self->{'search'};
+    $path .= "\t$self->{'string'}" if defined $self->{'string'};
+    $self->{'path'} = $path;
+
+    $old;
+}
+
+*params  = \&URI::URL::bad_method;
+*qparams = \&URI::URL::bad_method;
+*query   = \&URI::URL::bad_method;
+*equery  = \&URI::URL::bad_method;
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/http.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/http.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/http.pm	(revision 16571)
@@ -0,0 +1,57 @@
+package URI::URL::http;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+sub default_port { 80 }
+
+require Carp;
+
+# @ISA = qw(AutoLoader)      # This comment is needed by AutoSplit.
+sub keywords;
+sub query_form;
+1;
+__END__
+
+# Handle ...?dog+bones type of query
+sub keywords {
+    my $self = shift;
+    $old = $self->{'query'};
+    if (@_) {
+	# Try to set query string
+	$self->equery(join('+', map { URI::Escape::uri_escape($_, $URI::URL::reserved) } @_));
+    }
+    return if !defined($old) || !defined(wantarray);
+
+    Carp::croak("Query is not keywords") if $old =~ /=/;
+    map { URI::Escape::uri_unescape($_) } split(/\+/, $old);
+}
+
+# Handle ...?foo=bar&bar=foo type of query
+sub query_form {
+    my $self = shift;
+    $old = $self->{'query'};
+    if (@_) {
+	# Try to set query string
+	my @query;
+	my($key,$vals);
+        my $esc = $URI::URL::reserved . $URI::URL::unsafe;
+	while (($key,$vals) = splice(@_, 0, 2)) {
+	    $key = '' unless defined $key;
+	    $key =  URI::Escape::uri_escape($key, $esc);
+	    $vals = [$vals] unless ref($vals) eq 'ARRAY';
+	    my $val;
+	    for $val (@$vals) {
+		$val = '' unless defined $val;
+		$val = URI::Escape::uri_escape($val, $esc);
+		push(@query, "$key=$val");
+	    }
+	}
+	$self->equery(join('&', @query));
+    }
+    return if !defined($old) || length($old) == 0 || !defined(wantarray);
+    Carp::croak("Query is not a form") unless $old =~ /=/;
+    map { s/\+/ /g; URI::Escape::uri_unescape($_) }
+	 map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/&/, $old);
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/https.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/https.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/https.pm	(revision 16571)
@@ -0,0 +1,6 @@
+package URI::URL::https;
+require URI::URL::http;
+@ISA = qw(URI::URL::http);
+
+sub default_port { 443 }
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/mailto.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/mailto.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/mailto.pm	(revision 16571)
@@ -0,0 +1,78 @@
+package URI::URL::mailto;
+require URI::URL;
+@ISA = qw(URI::URL);
+
+use URI::Escape;
+
+sub new {
+    my($class, $init, $base) = @_;
+
+    my $self = bless { }, $class;
+    $self->{'scheme'} = lc($1) if $init =~ s/^\s*([\w\+\.\-]+)://;
+    $self->{'address'} = uri_unescape($init);
+    $self->base($base) if $base;
+    $self;
+}
+
+sub address { shift->_elem('address', @_); }
+
+# can use these as aliases
+*encoded822addr = \&address;   # URI::URL v3 compatibility
+*netloc         = \&address;
+
+sub user {
+    my $self = shift;
+    $old = $self->{'address'};
+    if (@_) {
+	my $new = $old;
+	$new =~ s/.*\@?/$_[0]\@/;
+	$self->{'address'} = $new;
+    }
+    $old =~ s/\@.*//;
+    $old;
+}
+
+sub host {
+    my $self = shift;
+    $old = $self->{'address'};
+    if (@_) {
+	my $new = $old;
+	$new =~ s/\@.*/\@$_[0]/;
+	$self->{'address'} = $new;
+    }
+    $old =~ s/.*\@//;
+    $old;
+}
+
+sub crack
+{
+    my $self = shift;
+    ('mailto',           # scheme
+     $self->user,        # user
+     undef,              # passwd
+     $self->host,        # host
+     undef,              # port
+     $self->{'address'}, # path
+     undef,              # params
+     undef,              # query
+     undef               # fragment
+    )
+}
+
+sub as_string {
+    my $self = shift;
+    my $str = ($self->{'scheme'} || "mailto") . ":";
+    $str .= uri_escape($self->{'address'}) if defined $self->{'address'};
+    $str;
+}
+
+sub eq {
+    my($self, $other) = @_;
+    $other = URI::URL->new($other) unless ref $other;
+
+    # Mail adresses are case-insensitive
+    $self->scheme eq $other->scheme &&
+      lc($self->{'address'}) eq lc($other->{'address'});
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/news.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/news.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/news.pm	(revision 16571)
@@ -0,0 +1,73 @@
+package URI::URL::news;
+require URI::URL;
+@ISA = qw(URI::URL);
+
+use URI::Escape;
+
+sub new {
+    my($class, $init, $base) = @_;
+    my $self = bless { }, $class;
+    $self->{'scheme'}  = lc($1) if $init =~ s/^\s*([\w\+\.\-]+)://;
+    $self->groupart(uri_unescape($init));
+    $self->base($base) if $base;
+    $self;
+}
+
+sub groupart {
+    my $self = shift;
+    my $old = $self->{'path'};
+    if (@_) {
+	my $p = shift;
+	if (defined $p && $p =~ /\@/) {
+	    # it is an message id
+	    $p =~ s/^<(.*)>$/$1/;  # "<" and ">" should not be part of it
+	}
+	$self->{'path'} = $p;
+    }
+    $old;
+}
+
+*path = \&groupart;
+
+sub article   {
+    my $self = shift;
+    Carp::croak("Illegal article id name (does not contain '\@')")
+      if @_ && $_[0] !~ /\@/;
+    my $old = $self->groupart(@_);
+    return undef if $old !~ /\@/;
+    $old;
+}
+
+
+sub group {
+    my $self = shift;
+    Carp::croak("Illegal group name (contains '\@')")
+      if @_ && $_[0] =~ /\@/;
+    my $old = $self->groupart(@_);
+    return undef if $old =~ /\@/;
+    $old;
+}
+
+sub crack
+{
+    my $self = shift;
+    ('news',             # scheme
+     undef,              # user
+     undef,              # passwd
+     undef,              # host
+     undef,              # port
+     $self->{'path'},    # path
+     undef,              # params
+     undef,              # query
+     undef               # fragment
+    )
+}
+
+
+sub as_string {
+    my $self = shift;
+    my $scheme = $self->{'scheme'} || "news";
+    "$scheme:" . uri_escape($self->{'path'});
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/nntp.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/nntp.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/nntp.pm	(revision 16571)
@@ -0,0 +1,44 @@
+package URI::URL::nntp;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+use URI::Escape;
+
+sub default_port { 119 }
+
+sub _parse {
+    my($self, $init) = @_;
+    $self->URI::URL::_generic::_parse($init, qw(netloc path frag));
+
+    my @parts = $self->path_components;
+    shift @parts if @parts && $parts[0] eq '';
+
+    $self->{'group'} = uri_unescape($parts[0]);
+    $self->{'digits'}= uri_unescape($parts[1]);
+}
+
+sub group   { shift->_elem('group',  @_); }
+sub digits  { shift->_elem('digits', @_); }
+sub article { shift->_elem('digits', @_); }
+
+sub as_string {
+    my $self = shift;
+    my $str = "$self->{'scheme'}:";
+    $str .= "//$self->{'netloc'}" if defined $self->{'netloc'};
+    $str .= "/" . uri_escape($self->{'group'}) . "/" .
+		  uri_escape($self->{'digits'});
+    $str;
+}
+
+# Standard methods are not legal for nntp URLs
+*path      = \&URI::URL::bad_method;
+*epath     = \&URI::URL::bad_method;
+*query     = \&URI::URL::bad_method;
+*equery    = \&URI::URL::bad_method;
+*params    = \&URI::URL::bad_method;
+*eparams   = \&URI::URL::bad_method;
+*frag      = \&URI::URL::bad_method;
+*user      = \&URI::URL::bad_method;
+*password  = \&URI::URL::bad_method;
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/prospero.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/prospero.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/prospero.pm	(revision 16571)
@@ -0,0 +1,27 @@
+package URI::URL::prospero;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+# RFC 1738 says:
+#
+#   A prospero URLs takes the form:
+#
+#      prospero://<host>:<port>/<hsoname>;<field>=<value>
+#
+#   where <host> and <port> are as described in Section 3.1. If :<port>
+#   is omitted, the port defaults to 1525. No username or password is
+#   allowed.
+#
+#   The <hsoname> is the host-specific object name in the Prospero
+#   protocol, suitably encoded.  This name is opaque and interpreted by
+#   the Prospero server.  The semicolon ";" is reserved and may not
+#   appear without quoting in the <hsoname>.
+
+sub default_port { 1525 }       # says rfc1738, section 3.11
+
+sub _parse {
+    my($self, $init) = @_;
+    $self->URI::URL::_generic::_parse($init, qw(netloc path params frag));
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/rlogin.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/rlogin.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/rlogin.pm	(revision 16571)
@@ -0,0 +1,7 @@
+package URI::URL::rlogin;
+require URI::URL::_login;
+@ISA = qw(URI::URL::_login);
+
+sub default_port { 513 }
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/telnet.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/telnet.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/telnet.pm	(revision 16571)
@@ -0,0 +1,7 @@
+package URI::URL::telnet;
+require URI::URL::_login;
+@ISA = qw(URI::URL::_login);
+
+sub default_port { 23 }
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/tn3270.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/tn3270.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/tn3270.pm	(revision 16571)
@@ -0,0 +1,7 @@
+package URI::URL::tn3270;
+require URI::URL::_login;
+@ISA = qw(URI::URL::_login);
+
+# sub default_port { 0 }
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/wais.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/wais.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/wais.pm	(revision 16571)
@@ -0,0 +1,50 @@
+package URI::URL::wais;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+use URI::Escape;
+
+# RFC 1738 says:
+#
+#   A WAIS URL takes one of the following forms:
+#
+#     wais://<host>:<port>/<database>
+#     wais://<host>:<port>/<database>?<search>
+#     wais://<host>:<port>/<database>/<wtype>/<wpath>
+#
+#   where <host> and <port> are as described in Section 3.1. If :<port>
+#   is omitted, the port defaults to 210.  The first form designates a
+#   WAIS database that is available for searching. The second form
+#   designates a particular search.  <database> is the name of the WAIS
+#   database being queried.
+
+
+sub default_port { 210 }
+
+sub _parse {
+    my($self, $init) = @_;
+    $self->URI::URL::_generic::_parse($init, qw(netloc path query frag));
+}
+
+# Set the path component with the specified number
+sub _path_comp
+{
+    my $self = shift;
+    my $no   = shift;
+    my @p = $self->path_components;
+    shift(@p) if @p && $p[0] eq '';
+    my $old = $p[$no];
+    if (@_) {
+	$p[$no] = $_[0];
+	$self->path_components(@p);
+    }
+    $old;
+}
+
+sub database { shift->_path_comp(0, @_); }
+sub wtype    { shift->_path_comp(1, @_); }
+sub wpath    { shift->_path_comp(2, @_); }
+
+*params   = \&URI::URL::bad_method;
+*eparams  = \&URI::URL::bad_method;
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/webster.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/webster.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/webster.pm	(revision 16571)
@@ -0,0 +1,6 @@
+package URI::URL::webster;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+sub default_port { 765 }
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/whois.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/whois.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/URI/URL/whois.pm	(revision 16571)
@@ -0,0 +1,6 @@
+package URI::URL::whois;
+require URI::URL::_generic;
+@ISA = qw(URI::URL::_generic);
+
+sub default_port { 43 }
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/WWW/RobotRules.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/WWW/RobotRules.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/WWW/RobotRules.pm	(revision 16571)
@@ -0,0 +1,364 @@
+# $Id$
+
+package WWW::RobotRules;
+
+=head1 NAME
+
+WWW::RobotsRules - Parse robots.txt files
+
+=head1 SYNOPSIS
+
+ require WWW::RobotRules;
+ my $robotsrules = new WWW::RobotRules 'MOMspider/1.0';
+
+ use LWP::Simple qw(get);
+
+ $url = "http://some.place/robots.txt";
+ my $robots_txt = get $url;
+ $robotsrules->parse($url, $robots_txt);
+
+ $url = "http://some.other.place/robots.txt";
+ my $robots_txt = get $url;
+ $robotsrules->parse($url, $robots_txt);
+
+ # Now we are able to check if a URL is valid for those servers that
+ # we have obtained and parsed "robots.txt" files for.
+ if($robotsrules->allowed($url)) {
+     $c = get $url;
+     ...
+ }
+
+=head1 DESCRIPTION
+
+This module parses a F<robots.txt> file as specified in
+"A Standard for Robot Exclusion", described in
+<URL:http://info.webcrawler.com/mak/projects/robots/norobots.html>
+Webmasters can use the F<robots.txt> file to disallow conforming
+robots access to parts of their WWW server.
+
+The parsed file is kept in the WWW::RobotRules object, and this object
+provide methods to check if access to a given URL is prohibited.  The
+same WWW::RobotRules object can parse multiple F<robots.txt> files.
+
+The following methods are provided:
+
+=over 4
+
+=cut
+
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+sub Version { $VERSION; }
+
+
+use URI::URL ();
+use strict;
+
+
+=item $rules = new WWW::RobotRules 'MOMspider/1.0'
+
+This is the constructor for WWW::RobotRules objects.  The first 
+argument given to new() is the name of the robot. 
+
+=cut
+
+sub new {
+    my($class, $ua) = @_;
+
+    # This ugly hack is needed to ensure backwards compatability.
+    # The "WWW::RobotRules" class is now really abstract.
+    $class = "WWW::RobotRules::InCore" if $class eq "WWW::RobotRules";
+
+    my $self = bless { }, $class;
+    $self->agent($ua);
+    $self;
+}
+
+
+=item $rules->parse($url, $content, $fresh_until)
+
+The parse() method takes as arguments the URL that was used to
+retrieve the F</robots.txt> file, and the contents of the file.
+
+=cut
+
+sub parse {
+    my($self, $url, $txt, $fresh_until) = @_;
+
+    $url = new URI::URL $url unless ref($url);	# make it URL
+    my $netloc = $url->netloc;
+
+    $self->clear_rules($netloc);
+    $self->fresh_until($netloc, $fresh_until || (time + 365*24*3600));
+
+    my $ua;
+    my $is_me = 0;		# 1 iff this record is for me
+    my $is_anon = 0;		# 1 iff this record is for *
+    my @me_disallowed = ();	# rules disallowed for me
+    my @anon_disallowed = ();	# rules disallowed for *
+
+    # blank lines are significant, so turn CRLF into LF to avoid generating
+    # false ones
+    $txt =~ s/\015\012/\012/g;
+
+    # split at \012 (LF) or \015 (CR) (Mac text files have just CR for EOL)
+    for(split(/[\012\015]/, $txt)) {
+
+	# Lines containing only a comment are discarded completely, and
+        # therefore do not indicate a record boundary.
+	next if /^\s*\#/;
+
+	s/\s*\#.*//;        # remove comments at end-of-line
+
+	if (/^\s*$/) {	    # blank line
+	    last if $is_me; # That was our record. No need to read the rest.
+	    $is_anon = 0;
+	}
+        elsif (/^User-Agent:\s*(.*)/i) {
+	    $ua = $1;
+	    $ua =~ s/\s+$//;
+	    if ($is_me) {
+		# This record already had a User-agent that
+		# we matched, so just continue.
+	    }
+	    elsif ($ua eq '*') {
+		$is_anon = 1;
+	    }
+	    elsif($self->is_me($ua)) {
+		$is_me = 1;
+	    }
+	}
+	elsif (/^Disallow:\s*(.*)/i) {
+	    unless (defined $ua) {
+		warn "RobotRules: Disallow without preceding User-agent\n";
+		$is_anon = 1;  # assume that User-agent: * was intended
+	    }
+	    my $disallow = $1;
+	    $disallow =~ s/\s+$//;
+	    if (length $disallow) {
+		$disallow = URI::URL->new($disallow, $url)->full_path;
+	    }
+
+	    if ($is_me) {
+		push(@me_disallowed, $disallow);
+	    }
+	    elsif ($is_anon) {
+		push(@anon_disallowed, $disallow);
+	    }
+	}
+	else {
+	    warn "RobotRules: Unexpected line: $_\n";
+	}
+    }
+
+    if ($is_me) {
+	$self->push_rules($netloc, @me_disallowed);
+    } else {
+	$self->push_rules($netloc, @anon_disallowed);
+    }
+}
+
+# is_me()
+#
+# Returns TRUE if the given name matches the
+# name of this robot
+#
+sub is_me {
+    my($self, $ua) = @_;
+    my $me = $self->agent;
+    return index(lc($ua), lc($me)) >= 0;
+}
+
+=item $rules->allowed($url)
+
+Returns TRUE if this robot is allowed to retrieve this URL.
+
+=cut
+
+sub allowed {
+    my($self, $url) = @_;
+    $url = URI::URL->new($url) unless ref $url;	# make it URL
+
+    my $netloc = $url->netloc;
+
+    my $fresh_until = $self->fresh_until($netloc);
+    return -1 if !defined($fresh_until) || $fresh_until < time;
+
+    my $str = $url->full_path;
+    my $rule;
+    for $rule ($self->rules($netloc)) {
+	return 1 unless length $rule;
+	return 0 if index($str, $rule) == 0;
+    }
+    return 1;
+}
+
+# The following methods must be provided by the subclass.
+sub agent;
+sub visit;
+sub no_visits;
+sub last_visits;
+sub fresh_until;
+sub push_rules;
+sub clear_rules;
+sub rules;
+sub dump;
+
+package WWW::RobotRules::InCore;
+
+use vars qw(@ISA);
+@ISA = qw(WWW::RobotRules);
+
+=item $rules->agent([$name])
+
+Get/set the agent name. NOTE: Changing the agent name will clear the robots.txt
+rules and expire times out of the cache.
+
+=cut
+
+sub agent {
+    my ($self, $name) = @_;
+    my $old = $self->{'ua'};
+    if ($name) {
+	delete $self->{'loc'};   # all old info is now stale
+	$name =~ s!/?\s*\d+.\d+\s*$!!;  # loose version
+	$self->{'ua'}=$name;
+    }
+    $old;
+}
+
+sub visit {
+    my($self, $netloc, $time) = @_;
+    $time ||= time;
+    $self->{'loc'}{$netloc}{'last'} = $time;
+    
+    my $count = \$self->{'loc'}{$netloc}{'count'};
+    if (!defined $$count) {
+	$$count = 1;
+    } else {
+	$$count++;
+    }
+}
+
+sub no_visits {
+    my ($self, $netloc) = @_;
+    $self->{'loc'}{$netloc}{'count'};
+}
+
+sub last_visit {
+    my ($self, $netloc) = @_;
+    $self->{'loc'}{$netloc}{'last'};
+}
+
+sub fresh_until {
+    my ($self, $netloc, $fresh_until) = @_;
+    my $old = $self->{'loc'}{$netloc}{'fresh'};
+    if (defined $fresh_until) {
+	$self->{'loc'}{$netloc}{'fresh'} = $fresh_until;
+    }
+    $old;
+}
+
+sub push_rules {
+    my($self, $netloc, @rules) = @_;
+    push (@{$self->{'loc'}{$netloc}{'rules'}}, @rules);
+}
+
+sub clear_rules {
+    my($self, $netloc) = @_;
+    delete $self->{'loc'}{$netloc}{'rules'};
+}
+
+sub rules {
+    my($self, $netloc) = @_;
+    if (defined $self->{'loc'}{$netloc}{'rules'}) {
+	return @{$self->{'loc'}{$netloc}{'rules'}};
+    } else {
+	return ();
+    }
+}
+
+sub dump
+{
+    my $self = shift;
+    for (keys %$self) {
+	next if $_ eq 'loc';
+	print "$_ = $self->{$_}\n";
+    }
+    for (keys %{$self->{'loc'}}) {
+	my @rules = $self->rules($_);
+	print "$_: ", join("; ", @rules), "\n";
+	
+    }
+}
+
+1;
+
+__END__
+
+=back
+
+=head1 ROBOTS.TXT
+
+The format and semantics of the "/robots.txt" file are as follows
+(this is an edited abstract of
+<URL:http://info.webcrawler.com/mak/projects/robots/norobots.html>):
+
+The file consists of one or more records separated by one or more
+blank lines. Each record contains lines of the form
+
+  <field-name>: <value>
+
+The field name is case insensitive.  Text after the '#' character on a
+line is ignored during parsing.  This is used for comments.  The
+following <field-names> can be used:
+
+=over 3
+
+=item User-Agent
+
+The value of this field is the name of the robot the record is
+describing access policy for.  If more than one I<User-Agent> field is
+present the record describes an identical access policy for more than
+one robot. At least one field needs to be present per record.  If the
+value is '*', the record describes the default access policy for any
+robot that has not not matched any of the other records.
+
+=item Disallow
+
+The value of this field specifies a partial URL that is not to be
+visited. This can be a full path, or a partial path; any URL that
+starts with this value will not be retrieved
+
+=back
+
+=head1 ROBOTS.TXT EXAMPLES
+
+The following example "/robots.txt" file specifies that no robots
+should visit any URL starting with "/cyberworld/map/" or "/tmp/":
+
+  User-agent: *
+  Disallow: /cyberworld/map/ # This is an infinite virtual URL space
+  Disallow: /tmp/ # these will soon disappear
+
+This example "/robots.txt" file specifies that no robots should visit
+any URL starting with "/cyberworld/map/", except the robot called
+"cybermapper":
+
+  User-agent: *
+  Disallow: /cyberworld/map/ # This is an infinite virtual URL space
+
+  # Cybermapper knows where to go.
+  User-agent: cybermapper
+  Disallow:
+
+This example indicates that no robots should visit this site further:
+
+  # go away
+  User-agent: *
+  Disallow: /
+
+=head1 SEE ALSO
+
+L<LWP::RobotUA>, L<WWW::RobotRules::AnyDBM_File>
+
+=cut
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/WWW/RobotRules/AnyDBM_File.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/WWW/RobotRules/AnyDBM_File.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lib/WWW/RobotRules/AnyDBM_File.pm	(revision 16571)
@@ -0,0 +1,170 @@
+# $Id$
+
+package WWW::RobotRules::AnyDBM_File;
+
+require  WWW::RobotRules;
+@ISA = qw(WWW::RobotRules);
+$VERSION = sprintf("%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/);
+
+use Carp ();
+use AnyDBM_File;
+use Fcntl;
+use strict;
+
+=head1 NAME
+
+WWW::RobotRules::AnyDBM_File - Persistent RobotRules
+
+=head1 SYNOPSIS
+
+ require WWW::RobotRules::AnyDBM_File;
+ require LWP::RobotUA;
+
+ # Create a robot useragent that uses a diskcaching RobotRules
+ my $rules = new WWW::RobotRules::AnyDBM_File 'my-robot/1.0', 'cachefile';
+ my $ua = new WWW::RobotUA 'my-robot/1.0', 'me@foo.com', $rules;
+
+ # Then just use $ua as usual
+ $res = $ua->request($req);
+
+=head1 DESCRIPTION
+
+This is a subclass of I<WWW::RobotRules> that uses the AnyDBM_File
+package to implement persistent diskcaching of F<robots.txt> and host
+visit information.
+
+The constructor (the new() method) takes an extra argument specifying
+the name of the DBM file to use.  If the DBM file already exists, then
+you can specify undef as agent name as the name can be obtained from
+the DBM database.
+
+=cut
+
+sub new 
+{ 
+  my ($class, $ua, $file) = @_;
+  Carp::croak('WWW::RobotRules::AnyDBM_File filename required') unless $file;
+
+  my $self = bless { }, $class;
+  $self->{'filename'} = $file;
+  tie %{$self->{'dbm'}}, 'AnyDBM_File', $file, O_CREAT|O_RDWR, 0640
+    or Carp::croak("Can't open $file: $!");
+  
+  if ($ua) {
+      $self->agent($ua);
+  } else {
+      # Try to obtain name from DBM file
+      $ua = $self->{'dbm'}{"|ua-name|"};
+      Carp::croak("No agent name specified") unless $ua;
+  }
+
+  $self;
+}
+
+sub agent {
+    my($self, $newname) = @_;
+    my $old = $self->{'dbm'}{"|ua-name|"};
+    if (defined $newname) {
+	$newname =~ s!/?\s*\d+.\d+\s*$!!;  # loose version
+	unless ($old && $old eq $newname) {
+	# Old info is now stale.
+	    my $file = $self->{'filename'};
+	    untie %{$self->{'dbm'}};
+	    tie %{$self->{'dbm'}}, 'AnyDBM_File', $file, O_TRUNC|O_RDWR, 0640;
+	    $self->{'dbm'}{"|ua-name|"} = $newname;
+	}
+    }
+    $old;
+}
+
+sub no_visits {
+    my ($self, $netloc) = @_;
+    my $t = $self->{'dbm'}{"$netloc|vis"};
+    return 0 unless $t;
+    (split(/;\s*/, $t))[0];
+}
+
+sub last_visit {
+    my ($self, $netloc) = @_;
+    my $t = $self->{'dbm'}{"$netloc|vis"};
+    return undef unless $t;
+    (split(/;\s*/, $t))[1];
+}
+
+sub fresh_until {
+    my ($self, $netloc, $fresh) = @_;
+    my $old = $self->{'dbm'}{"$netloc|exp"};
+    if ($old) {
+	$old =~ s/;.*//;  # remove cleartext
+    }
+    if (defined $fresh) {
+	$fresh .= "; " . localtime($fresh);
+	$self->{'dbm'}{"$netloc|exp"} = $fresh;
+    }
+    $old;
+}
+
+sub visit {
+    my($self, $netloc, $time) = @_;
+    $time ||= time;
+
+    my $count = 0;
+    my $old = $self->{'dbm'}{"$netloc|vis"};
+    if ($old) {
+	my $last;
+	($count,$last) = split(/;\s*/, $old);
+	$time = $last if $last > $time;
+    }
+    $count++;
+    $self->{'dbm'}{"$netloc|vis"} = "$count; $time; " . localtime($time);
+}
+
+sub push_rules {
+    my($self, $netloc, @rules) = @_;
+    my $cnt = 1;
+    $cnt++ while $self->{'dbm'}{"$netloc|r$cnt"};
+
+    foreach (@rules) {
+	$self->{'dbm'}{"$netloc|r$cnt"} = $_;
+	$cnt++;
+    }
+}
+
+sub clear_rules {
+    my($self, $netloc) = @_;
+    my $cnt = 1;
+    while ($self->{'dbm'}{"$netloc|r$cnt"}) {
+	delete $self->{'dbm'}{"$netloc|r$cnt"};
+	$cnt++;
+    }
+}
+
+sub rules {
+    my($self, $netloc) = @_;
+    my @rules = ();
+    my $cnt = 1;
+    while (1) {
+	my $rule = $self->{'dbm'}{"$netloc|r$cnt"};
+	last unless $rule;
+	push(@rules, $rule);
+	$cnt++;
+    }
+    @rules;
+}
+
+sub dump
+{
+}
+
+1;
+
+=head1 SEE ALSO
+
+L<WWW::RobotRules>, L<LWP::RobotUA>
+
+=head1 AUTHORS
+
+Hakan Ardo E<lt>hakan@munin.ub2.lu.se>, Gisle Aas E<lt>aas@sn.no>
+
+=cut
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lwpcook.pod
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lwpcook.pod	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/lwpcook.pod	(revision 16571)
@@ -0,0 +1,343 @@
+=head1 NAME
+
+lwpcook - libwww-perl cookbook
+
+=head1 DESCRIPTION
+
+This document contain some examples that show typical usage of the
+libwww-perl library.  You should consult the documentation for the
+individual modules for more detail.
+
+All examples should be runnable programs. You can, in most cases, test
+the code sections by piping the program text directly to perl.
+
+
+
+=head1 GET
+
+It is very easy to use this library to just fetch documents from the
+net.  The LWP::Simple module provides the get() function that return
+the document specified by its URL argument:
+
+  use LWP::Simple;
+  $doc = get 'http://www.sn.no/libwww-perl/';
+
+or, as a perl one-liner using the getprint() function:
+
+  perl -MLWP::Simple -e 'getprint "http://www.sn.no/libwww-perl/"'
+
+or, how about fetching the latest perl by running this command:
+
+  perl -MLWP::Simple -e '
+    getstore "ftp://ftp.sunet.se/pub/lang/perl/CPAN/src/latest.tar.gz",
+             "perl.tar.gz"'
+
+You will probably first want to find a CPAN site closer to you by
+running something like the following command:
+
+  perl -MLWP::Simple -e 'getprint "http://www.perl.com/perl/CPAN/CPAN.html"'
+
+Enough of this simple stuff!  The LWP object oriented interface gives
+you more control over the request sent to the server.  Using this
+interface you have full control over headers sent and how you want to
+handle the response returned.
+
+  use LWP::UserAgent;
+  $ua = new LWP::UserAgent;
+  $ua->agent("$0/0.1 " . $ua->agent);
+  # $ua->agent("Mozilla/8.0") # pretend we are very capable browser
+
+  $req = new HTTP::Request 'GET' => 'http://www.sn.no/libwww-perl';
+  $req->header('Accept' => 'text/html');
+
+  # send request
+  $res = $ua->request($req);
+
+  # check the outcome
+  if ($res->is_success) {
+     print $res->content;
+  } else {
+     print "Error: " . $res->status_line . "\n";
+  }
+
+The lwp-request program (alias GET) that is distributed with the
+library can also be used to fetch documents from WWW servers.
+  
+
+
+=head1 HEAD
+
+If you just want to check if a document is present (i.e. the URL is
+valid) try to run code that looks like this:
+
+  use LWP::Simple;
+
+  if (head($url)) {
+     # ok document exists
+  }
+
+The head() function really returns a list of meta-information about
+the document.  The first three values of the list returned are the
+document type, the size of the document, and the age of the document.
+
+More control over the request or access to all header values returned
+require that you use the object oriented interface described for GET
+above.  Just s/GET/HEAD/g.
+
+
+=head1 POST
+
+There is no simple procedural interface for posting data to a WWW server.  You
+must use the object oriented interface for this. The most common POST
+operation is to access a WWW form application:
+
+  use LWP::UserAgent;
+  $ua = new LWP::UserAgent;
+
+  my $req = new HTTP::Request 'POST','http://www.perl.com/cgi-bin/BugGlimpse';
+  $req->content_type('application/x-www-form-urlencoded');
+  $req->content('match=www&errors=0');
+
+  my $res = $ua->request($req);
+  print $res->as_string;
+
+Lazy people use the HTTP::Request::Common module to set up a suitable
+POST request message (it handles all the escaping issues) and has a
+suitable default for the content_type:
+
+  use HTTP::Request::Common qw(POST);
+  use LWP::UserAgent;
+  $ua = new LWP::UserAgent;
+
+  my $req = POST 'http://www.perl.com/cgi-bin/BugGlimpse',
+                [ search => 'www', errors => 0 ];
+
+  print $ua->request($req)->as_string;
+
+The lwp-request program (alias POST) that is distributed with the
+library can also be used for posting data.
+
+
+
+=head1 PROXIES
+
+Some sites use proxies to go through fire wall machines, or just as
+cache in order to improve performance.  Proxies can also be used for
+accessing resources through protocols not supported directly (or
+supported badly :-) by the libwww-perl library.
+
+You should initialize your proxy setting before you start sending
+requests:
+
+  use LWP::UserAgent;
+  $ua = new LWP::UserAgent;
+  $ua->env_proxy; # initialize from environment variables
+  # or
+  $ua->proxy(ftp  => 'http://proxy.myorg.com');
+  $ua->proxy(wais => 'http://proxy.myorg.com');
+  $ua->no_proxy(qw(no se fi));
+
+  my $req = new HTTP::Request 'wais://xxx.com/';
+  print $ua->request($req)->as_string;
+
+The LWP::Simple interface will call env_proxy() for you automatically.
+Applications that use the $ua->env_proxy() method will normally not
+use the $ua->proxy() and $ua->no_proxy() methods.
+
+Some proxies also require that you send it a username/password in
+order to let requests through.  You should be able to add the
+required header, with something like this:
+
+ use LWP::UserAgent;
+
+ $ua = new LWP::UserAgent;
+ $ua->proxy(['http', 'ftp'] => 'http://proxy.myorg.com');
+
+ $req = new HTTP::Request 'GET',"http://www.perl.com";
+ $req->proxy_authorization_basic("proxy_user", "proxy_password");
+
+ $res = $ua->request($req);
+ print $res->content if $res->is_success;
+
+Replace C<proxy.myorg.com>, C<proxy_user> and
+C<proxy_password> with something suitable for your site.
+
+
+=head1 ACCESS TO PROTECTED DOCUMENTS
+
+Documents protected by basic authorization can easily be accessed
+like this:
+
+  use LWP::UserAgent;
+  $ua = new LWP::UserAgent;
+  $req = new HTTP::Request GET => 'http://www.sn.no/secret/';
+  $req->authorization_basic('aas', 'mypassword');
+  print $ua->request($req)->as_string;
+
+The other alternative is to provide a subclass of I<LWP::UserAgent> that
+overrides the get_basic_credentials() method. Study the I<lwp-request>
+program for an example of this.
+
+
+=head1 MIRRORING
+
+If you want to mirror documents from a WWW server, then try to run
+code similar to this at regular intervals:
+
+  use LWP::Simple;
+
+  %mirrors = (
+     'http://www.sn.no/'             => 'sn.html',
+     'http://www.perl.com/'          => 'perl.html',
+     'http://www.sn.no/libwww-perl/' => 'lwp.html',
+     'gopher://gopher.sn.no/'        => 'gopher.html',
+  );
+
+  while (($url, $localfile) = each(%mirrors)) {
+     mirror($url, $localfile);
+  }
+
+Or, as a perl one-liner:
+
+  perl -MLWP::Simple -e 'mirror("http://www.perl.com/", "perl.html")';
+
+The document will not be transfered unless it has been updated.
+
+
+
+=head1 LARGE DOCUMENTS
+
+If the document you want to fetch is too large to be kept in memory,
+then you have two alternatives.  You can instruct the library to write
+the document content to a file (second $ua->request() argument is a file
+name):
+
+  use LWP::UserAgent;
+  $ua = new LWP::UserAgent;
+
+  my $req = new HTTP::Request 'GET',
+                'http://www.sn.no/~aas/perl/www/libwww-perl-5.00.tar.gz';
+  $res = $ua->request($req, "libwww-perl.tar.gz");
+  if ($res->is_success) {
+     print "ok\n";
+  }
+
+Or you can process the document as it arrives (second $ua->request()
+argument is a code reference):
+
+  use LWP::UserAgent;
+  $ua = new LWP::UserAgent;
+  $URL = 'ftp://ftp.unit.no/pub/rfc/rfc-index.txt';
+
+  my $expected_length;
+  my $bytes_received = 0;
+  $ua->request(HTTP::Request->new('GET', $URL),
+               sub {
+                   my($chunk, $res) = @_;
+                   $bytes_received += length($chunk);
+	           unless (defined $expected_length) {
+	              $expected_length = $res->content_length || 0;
+                   }
+		   if ($expected_length) {
+		        printf STDERR "%d%% - ",
+	                          100 * $bytes_received / $expected_length;
+                   }
+	           print STDERR "$bytes_received bytes received\n";
+
+                   # XXX Should really do something with the chunk itself
+	           # print $chunk;
+               });
+
+
+
+=head1 HTML FORMATTING
+
+It is easy to convert HTML code to "readable" text.
+
+  use LWP::Simple;
+  use HTML::Parse;
+  print parse_html(get 'http://www.sn.no/libwww-perl/')->format;
+
+
+
+=head1 PARSE URLS
+
+To access individual elements of a URL, try this:
+
+  use URI::URL;
+  $host = url("http://www.sn.no/")->host;
+
+or
+
+  use URI::URL;
+  $u = url("ftp://ftp.sn.no/test/aas;type=i");
+  print "Protocol scheme is ", $u->scheme, "\n";
+  print "Host is ", $u->host, " at port ", $u->port, "\n";
+
+or even
+
+  use URI::URL;
+  my($host,$port) = (url("ftp://ftp.sn.no/test/aas;type=i")->crack)[3,4];
+
+
+=head1 EXPAND RELATIVE URLS
+
+This code reads URLs and print expanded version.
+
+  use URI::URL;
+  $BASE = "http://www.sn.no/some/place?query";
+  while (<>) {
+     print url($_, $BASE)->abs->as_string, "\n";
+  }
+
+We can expand URLs in an HTML document by using the parser to build a
+tree that we then traverse:
+
+  %link_elements =
+  (
+   'a'    => 'href',
+   'img'  => 'src',
+   'form' => 'action',
+   'link' => 'href',
+  );
+
+  use HTML::Parse;
+  use URI::URL;
+
+  $BASE = "http://somewhere/root/";
+  $h = parse_htmlfile("xxx.html");
+  $h->traverse(\&expand_urls, 1);
+
+  print $h->as_HTML;
+
+  sub expand_urls
+  {
+     my($e, $start) = @_;
+     return 1 unless $start;
+     my $attr = $link_elements{$e->tag};
+     return 1 unless defined $attr;
+     my $url = $e->attr($attr);
+     return 1 unless defined $url;
+     $e->attr($attr, url($url, $BASE)->abs->as_string);
+  }
+
+
+
+=head1 BASE URL
+
+If you want to resolve relative links in a page you will have to
+determine which base URL to use.  The HTTP::Response objects now has a
+base() method.
+
+  $BASE = $res->base;
+
+
+
+=head1 COPYRIGHT
+
+Copyright 1996-1997, Gisle Aas
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/README
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/README	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/README	(revision 16571)
@@ -0,0 +1,24 @@
+Self test suite for the libwww-perl library
+-------------------------------------------
+
+Tests are invoked by running the ./TEST script, but usually you run
+the tests with "make test" at the top libwww-perl directory.  Use -v
+option for verbose tests.  You might run an individual test like this:
+
+  ./TEST -v base/date
+
+or all tests in a directory like this
+
+  ./TEST base
+
+You enable network tests by creating the "net/config.pl" file.  A good
+start is to make a copy of the "net/config.pl.dist" file.  For network
+tests you should also make a link from the cgi-bin directory of your
+http server to the "net/cgi-bin" directory.  You might also have to
+check that the interpreter line (#!.../perl) in the scripts is ok for
+your system.  The following setup works for my site:
+
+  ln -s `pwd`/net/cgi-bin ~www/cgi-bin/lwp
+  cp net/config.pl.dist net/config.pl
+  emacs net/config.pl                        # fix if necessary
+  ./TEST net
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/TEST
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/TEST	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/TEST	(revision 16571)
@@ -0,0 +1,39 @@
+#!/usr/local/bin/perl
+
+# This script is run Test::Harness on the tests found under the
+# "t" directory.
+
+# First we check if we already are within the "t" directory
+unless (-d "base") {
+    # try to move into test directory
+    chdir "t" or die "Can't chdir: $!";
+
+    # fix all relative library locations
+    foreach (@INC) {
+	$_ = "../$_" unless m,^/,;
+    }
+}
+# Pick up the library files from the ../blib directory
+unshift(@INC, "../blib/lib", "../blib/arch");
+#print "@INC\n";
+
+
+use Test::Harness;
+$Test::Harness::verbose = shift
+  if $ARGV[0] =~ /^\d+$/ || $ARGV[0] eq "-v";
+
+if (@ARGV) {
+    for (@ARGV) {
+	if (-d $_) {
+	    push(@tests, <$_/*.t>);
+	} else {
+            $_ .= ".t" unless /\.t$/;
+	    push(@tests, $_);
+	}
+    }
+} else {
+    @tests = (<base/*.t>, <uri/*.t>, <robot/*.t>, <local/*.t>);
+    push(@tests, <net/*.t>) if -f "net/config.pl";
+}
+
+runtests @tests;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/common-req.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/common-req.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/common-req.t	(revision 16571)
@@ -0,0 +1,193 @@
+print "1..19\n";
+
+use HTTP::Request::Common;
+
+$r = GET 'http://www.sn.no/';
+print $r->as_string;
+
+print "not " unless $r->method eq "GET" and $r->url eq "http://www.sn.no/";
+print "ok 1\n";
+
+$r = HEAD "http://www.sn.no/",
+     If_Match => 'abc',
+     From => 'aas@sn.no';
+print $r->as_string;
+
+print "not " unless $r->method eq "HEAD" and $r->url->eq("http://www.sn.no");
+print "ok 2\n";
+
+print "not " unless $r->header('If-Match') eq "abc" and $r->header("from") eq "aas\@sn.no";
+print "ok 3\n";
+
+$r = PUT "http://www.sn.no",
+     Content => 'foo';
+print $r->as_string;
+
+print "not " unless $r->method eq "PUT" and $r->url->netloc eq "www.sn.no";
+print "ok 4\n";
+
+print "not " if defined($r->header("Content"));
+print "ok 5\n";
+
+print "not " unless ${$r->content_ref} eq "foo" and
+                    $r->content eq "foo";
+print "ok 6\n";
+
+#--- Test POST requests ---
+
+$r = POST "http://www.sn.no", [foo => 'bar',
+                               baz => [qw(a b c)],
+                               foo => 'zoo=&',
+                               "space " => " + ",
+                              ],
+                              bar => 'foo';
+print $r->as_string;
+
+print "not " unless $r->method eq "POST" and
+                    $r->content_type eq "application/x-www-form-urlencoded" and
+                    $r->content_length == 58 and
+                    $r->header("bar") eq "foo";
+print "ok 7\n";
+
+print "not " unless $r->content eq "foo=bar&baz=a&baz=b&baz=c&foo=zoo%3D%26&space%20=%20%2B%20";
+print "ok 8\n";
+
+$r = POST "mailto:gisle\@aas.no",
+     Subject => "Heisan",
+     Content_Type => "text/plain",
+     Content => "Howdy\n";
+print $r->as_string;
+
+print "not " unless $r->method eq "POST" and
+                    $r->header("Subject") eq "Heisan" and
+                    $r->content eq "Howdy\n" and
+	            $r->content_type eq "text/plain";
+print "ok 9\n";
+
+#
+# POST for File upload
+#
+$file = "test-$$";
+open(FILE, ">$file") or die "Can't create $file: $!";
+print FILE "foo\nbar\nbaz\n";
+close(FILE);
+
+$r = POST 'http://www.perl.org/survey.cgi',
+       Content_Type => 'form-data',
+       Content      => [ name  => 'Gisle Aas',
+                         email => 'gisle@aas.no',
+                         gender => 'm',
+                         born   => '1964',
+                         file   => [$file],
+                       ];
+print $r->as_string;
+
+unlink($file) or warn "Can't unlink $file: $!";
+
+print "not " unless $r->method eq "POST" and
+	            $r->url->path eq "/survey.cgi" and
+                    $r->content_type eq "multipart/form-data" and
+	            $r->header(Content_type) =~ /boundary="?([^"]+)"?/;
+print "ok 10\n";
+$boundary = $1;
+
+$c = $r->content;
+$c =~ s/\r//g;
+@c = split(/--\Q$boundary/, $c);
+print "$c[5]\n";
+
+print "not " unless @c == 7 and $c[6] =~ /^--\n/;  # 5 parts + header & trailer
+print "ok 11\n";
+
+print "not " unless $c[2] =~ /^Content-Disposition:\s*form-data;\s*name="email"/m and
+                    $c[2] =~ /^gisle\@aas.no$/m;
+print "ok 12\n";
+
+print "not " unless $c[5] =~ /^Content-Disposition:\s*form-data;\s*name="file";\s*filename="$file"/m and
+	            $c[5] =~ /^Content-Type:\s*text\/plain$/m and
+	            $c[5] =~ /^foo\nbar\nbaz/m;
+print "ok 13\n";
+
+$r = POST 'http://www.perl.org/survey.cgi',
+      [ file => [ undef, "xxx", Content_type => "text/html", Content => "<h1>Hello, world!</h1>" ]],
+      Content_type => 'multipart/form-data';
+print $r->as_string;
+
+print "not " unless $r->content =~ /^--\S+\015\012Content-Disposition:\s*form-data;\s*name="file";\s*filename="xxx"/m and
+	            $r->content =~ /^Content-Type: text\/html/m and
+	            $r->content =~ /^<h1>Hello, world/m;
+print "ok 14\n";
+
+
+$r = POST 'http://www.perl.org/survey.cgi',
+      Content_type => 'multipart/form-data',
+      Content => [ file => [ undef, undef, Content => "foo"]];
+print $r->as_string;
+
+print "not " if $r->content =~ /filename=/;
+print "ok 15\n";
+
+
+# The POST routine can now also take a hash reference.
+my %hash = (foo => 42, bar => 24);
+$r = POST 'http://www.perl.org/survey.cgi', \%hash;
+print $r->as_string;
+print "not " unless $r->content =~ /foo=42/ &&
+                    $r->content =~ /bar=24/ &&
+                    $r->content_type eq "application/x-www-form-urlencoded" &&
+                    $r->content_length == 13;
+print "ok 16\n";
+
+ 
+#
+# POST for File upload
+#
+use HTTP::Request::Common qw($DYNAMIC_FILE_UPLOAD);
+
+$file = "test-$$";
+open(FILE, ">$file") or die "Can't create $file: $!";
+for (1..1000) {
+   print FILE "a" .. "z";
+}
+close(FILE);
+
+$DYNAMIC_FILE_UPLOAD++;
+$r = POST 'http://www.perl.org/survey.cgi',
+       Content_Type => 'form-data',
+       Content      => [ name  => 'Gisle Aas',
+                         email => 'gisle@aas.no',
+                         gender => 'm',
+                         born   => '1964',
+                         file   => [$file],
+                       ];
+print $r->as_string;
+
+print "not " unless $r->method eq "POST" and
+	            $r->url->path eq "/survey.cgi" and
+                    $r->content_type eq "multipart/form-data" and
+	            $r->header(Content_type) =~ /boundary="?([^"]+)"?/ and
+		    ref($r->content) eq "CODE";
+print "ok 17\n";
+$boundary = $1;
+
+print "not " unless length($boundary) > 10;
+print "ok 18\n";
+
+$code = $r->content;
+my $chunk;
+my @chunks;
+while (defined($chunk = &$code) && length $chunk) {
+   push(@chunks, $chunk);
+}
+
+unlink($file) or warn "Can't unlink $file: $!";
+
+$_ = join("", @chunks);
+
+print int(@chunks), " chunks, total size is ", length($_), " bytes\n";
+
+# should be close to expected size and number of chunks
+print "not " unless abs(@chunks - 15 < 3) and
+                    abs(length($_) - 26589) < 20;
+print "ok 19\n";
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/cookies.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/cookies.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/cookies.t	(revision 16571)
@@ -0,0 +1,515 @@
+print "1..32\n";
+
+#use LWP::Debug '+';
+
+use HTTP::Cookies;
+use HTTP::Request;
+use HTTP::Response;
+
+#-------------------------------------------------------------------
+# First we check that it works for the original example at
+# http://www.netscape.com/newsref/std/cookie_spec.html
+
+# Client requests a document, and receives in the response:
+# 
+#       Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT
+# 
+# When client requests a URL in path "/" on this server, it sends:
+# 
+#       Cookie: CUSTOMER=WILE_E_COYOTE
+# 
+# Client requests a document, and receives in the response:
+# 
+#       Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/
+# 
+# When client requests a URL in path "/" on this server, it sends:
+# 
+#       Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001
+# 
+# Client receives:
+# 
+#       Set-Cookie: SHIPPING=FEDEX; path=/fo
+# 
+# When client requests a URL in path "/" on this server, it sends:
+# 
+#       Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001
+# 
+# When client requests a URL in path "/foo" on this server, it sends:
+# 
+#       Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001; SHIPPING=FEDEX
+# 
+# The last Cookie is buggy, because both specifications says that the
+# most specific cookie must be sent first.  SHIPPING=FEDEX is the
+# most specific and should thus be first.
+
+$c = HTTP::Cookies->new;
+
+$req = HTTP::Request->new(GET => "http://www.acme.com/");
+
+$res = HTTP::Response->new(200, "OK");
+$res->request($req);
+$res->header("Set-Cookie" => "CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT");
+$c->extract_cookies($res);
+
+$req = HTTP::Request->new(GET => "http://www.acme.com/");
+$c->add_cookie_header($req);
+
+print "not " unless $req->header("Cookie") eq "CUSTOMER=WILE_E_COYOTE" &&
+                    $req->header("Cookie2") eq "\$Version=1";
+print "ok 1\n";
+
+$res->request($req);
+$res->header("Set-Cookie" => "PART_NUMBER=ROCKET_LAUNCHER_0001; path=/");
+$c->extract_cookies($res);
+
+$req = HTTP::Request->new(GET => "http://www.acme.com/foo/bar");
+$c->add_cookie_header($req);
+
+$h = $req->header("Cookie");
+print "not " unless $h =~ /PART_NUMBER=ROCKET_LAUNCHER_0001/ &&
+                    $h =~ /CUSTOMER=WILE_E_COYOTE/;
+print "ok 2\n";
+
+$res->request($req);
+$res->header("Set-Cookie", "SHIPPING=FEDEX; path=/foo");
+$c->extract_cookies($res);
+
+$req = HTTP::Request->new(GET => "http://www.acme.com/");
+$c->add_cookie_header($req);
+
+$h = $req->header("Cookie");
+print "not " unless $h =~ /PART_NUMBER=ROCKET_LAUNCHER_0001/ &&
+	            $h =~ /CUSTOMER=WILE_E_COYOTE/ &&
+	            $h !~ /SHIPPING=FEDEX/;
+print "ok 3\n";
+
+
+$req = HTTP::Request->new(GET => "http://www.acme.com/foo/");
+$c->add_cookie_header($req);
+
+$h = $req->header("Cookie");
+print "not " unless $h =~ /PART_NUMBER=ROCKET_LAUNCHER_0001/ &&
+	            $h =~ /CUSTOMER=WILE_E_COYOTE/ &&
+		    $h =~ /^SHIPPING=FEDEX;/;
+print "ok 4\n";
+
+print $c->as_string;
+
+
+# Second Example transaction sequence:
+# 
+# Assume all mappings from above have been cleared.
+# 
+# Client receives:
+# 
+#       Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/
+# 
+# When client requests a URL in path "/" on this server, it sends:
+# 
+#       Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001
+# 
+# Client receives:
+# 
+#       Set-Cookie: PART_NUMBER=RIDING_ROCKET_0023; path=/ammo
+# 
+# When client requests a URL in path "/ammo" on this server, it sends:
+# 
+#       Cookie: PART_NUMBER=RIDING_ROCKET_0023; PART_NUMBER=ROCKET_LAUNCHER_0001
+# 
+#       NOTE: There are two name/value pairs named "PART_NUMBER" due to
+#       the inheritance of the "/" mapping in addition to the "/ammo" mapping. 
+
+$c = HTTP::Cookies->new;  # clear it
+
+$req = HTTP::Request->new(GET => "http://www.acme.com/");
+$res = HTTP::Response->new(200, "OK");
+$res->request($req);
+$res->header("Set-Cookie", "PART_NUMBER=ROCKET_LAUNCHER_0001; path=/");
+
+$c->extract_cookies($res);
+
+$req = HTTP::Request->new(GET => "http://www.acme.com/");
+$c->add_cookie_header($req);
+
+print "not " unless $req->header("Cookie") eq "PART_NUMBER=ROCKET_LAUNCHER_0001";
+print "ok 5\n";
+
+$res->request($req);
+$res->header("Set-Cookie", "PART_NUMBER=RIDING_ROCKET_0023; path=/ammo");
+$c->extract_cookies($res);
+
+$req = HTTP::Request->new(GET => "http://www.acme.com/ammo");
+$c->add_cookie_header($req);
+
+print "not " unless $req->header("Cookie") =~
+       /^PART_NUMBER=RIDING_ROCKET_0023;\s*PART_NUMBER=ROCKET_LAUNCHER_0001/;
+print "ok 6\n";
+
+print $c->as_string;
+undef($c);
+
+
+#-------------------------------------------------------------------
+# When there are no "Set-Cookie" header, then even responses
+# without any request URLs connected should be allowed.
+
+$c = HTTP::Cookies->new;
+$c->extract_cookies(HTTP::Response->new("200", "OK"));
+print "not " if count_cookies($c) != 0;
+print "ok 7\n";
+
+
+#-------------------------------------------------------------------
+# Then we test with the examples from draft-ietf-http-state-man-mec-03.txt
+#
+# 5.  EXAMPLES
+
+$c = HTTP::Cookies->new;
+
+# 
+# 5.1  Example 1
+# 
+# Most detail of request and response headers has been omitted.  Assume
+# the user agent has no stored cookies.
+# 
+#   1.  User Agent -> Server
+# 
+#       POST /acme/login HTTP/1.1
+#       [form data]
+# 
+#       User identifies self via a form.
+# 
+#   2.  Server -> User Agent
+# 
+#       HTTP/1.1 200 OK
+#       Set-Cookie2: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"
+# 
+#       Cookie reflects user's identity.
+
+$cookie = interact($c, 'http://www.acme.com/acme/login',
+                       'Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"');
+print "not " if $cookie;
+print "ok 8\n";
+
+# 
+#   3.  User Agent -> Server
+# 
+#       POST /acme/pickitem HTTP/1.1
+#       Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme"
+#       [form data]
+# 
+#       User selects an item for ``shopping basket.''
+# 
+#   4.  Server -> User Agent
+# 
+#       HTTP/1.1 200 OK
+#       Set-Cookie2: Part_Number="Rocket_Launcher_0001"; Version="1";
+#               Path="/acme"
+# 
+#       Shopping basket contains an item.
+
+$cookie = interact($c, 'http://www.acme.com/acme/pickitem',
+		       'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"');
+print "not " unless $cookie =~ m(^\$Version="?1"?; Customer="?WILE_E_COYOTE"?; \$Path="/acme"$);
+print "ok 9\n";
+
+# 
+#   5.  User Agent -> Server
+# 
+#       POST /acme/shipping HTTP/1.1
+#       Cookie: $Version="1";
+#               Customer="WILE_E_COYOTE"; $Path="/acme";
+#               Part_Number="Rocket_Launcher_0001"; $Path="/acme"
+#       [form data]
+# 
+#       User selects shipping method from form.
+# 
+#   6.  Server -> User Agent
+# 
+#       HTTP/1.1 200 OK
+#       Set-Cookie2: Shipping="FedEx"; Version="1"; Path="/acme"
+# 
+#       New cookie reflects shipping method.
+
+$cookie = interact($c, "http://www.acme.com/acme/shipping",
+		   'Shipping="FedEx"; Version="1"; Path="/acme"');
+
+print "not " unless $cookie =~ /^\$Version="?1"?;/ &&
+     $cookie =~ /Part_Number="?Rocket_Launcher_0001"?;\s*\$Path="\/acme"/ &&
+     $cookie =~ /Customer="?WILE_E_COYOTE"?;\s*\$Path="\/acme"/;
+print "ok 10\n";
+
+# 
+#   7.  User Agent -> Server
+# 
+#       POST /acme/process HTTP/1.1
+#       Cookie: $Version="1";
+#               Customer="WILE_E_COYOTE"; $Path="/acme";
+#               Part_Number="Rocket_Launcher_0001"; $Path="/acme";
+#               Shipping="FedEx"; $Path="/acme"
+#       [form data]
+# 
+#       User chooses to process order.
+# 
+#   8.  Server -> User Agent
+# 
+#       HTTP/1.1 200 OK
+# 
+#       Transaction is complete.
+
+$cookie = interact($c, "http://www.acme.com/acme/process");
+print "FINAL COOKIE: $cookie\n";
+print "not " unless $cookie =~ /Shipping="?FedEx"?;\s*\$Path="\/acme"/ &&
+                    $cookie =~ /WILE_E_COYOTE/;
+print "ok 11\n";
+
+# 
+# The user agent makes a series of requests on the origin server, after
+# each of which it receives a new cookie.  All the cookies have the same
+# Path attribute and (default) domain.  Because the request URLs all have
+# /acme as a prefix, and that matches the Path attribute, each request
+# contains all the cookies received so far.
+
+print $c->as_string;
+
+
+# 5.2  Example 2
+# 
+# This example illustrates the effect of the Path attribute.  All detail
+# of request and response headers has been omitted.  Assume the user agent
+# has no stored cookies.
+
+$c = HTTP::Cookies->new;
+
+# Imagine the user agent has received, in response to earlier requests,
+# the response headers
+# 
+# Set-Cookie2: Part_Number="Rocket_Launcher_0001"; Version="1";
+#         Path="/acme"
+# 
+# and
+# 
+# Set-Cookie2: Part_Number="Riding_Rocket_0023"; Version="1";
+#         Path="/acme/ammo"
+
+interact($c, "http://www.acme.com/acme/ammo/specific",
+             'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"',
+             'Part_Number="Riding_Rocket_0023"; Version="1"; Path="/acme/ammo"');
+
+# A subsequent request by the user agent to the (same) server for URLs of
+# the form /acme/ammo/...  would include the following request header:
+# 
+# Cookie: $Version="1";
+#         Part_Number="Riding_Rocket_0023"; $Path="/acme/ammo";
+#         Part_Number="Rocket_Launcher_0001"; $Path="/acme"
+# 
+# Note that the NAME=VALUE pair for the cookie with the more specific Path
+# attribute, /acme/ammo, comes before the one with the less specific Path
+# attribute, /acme.  Further note that the same cookie name appears more
+# than once.
+
+$cookie = interact($c, "http://www.acme.com/acme/ammo/...");
+print "not " unless $cookie =~ /Riding_Rocket_0023.*Rocket_Launcher_0001/;
+print "ok 12\n";
+
+# A subsequent request by the user agent to the (same) server for a URL of
+# the form /acme/parts/ would include the following request header:
+# 
+# Cookie: $Version="1"; Part_Number="Rocket_Launcher_0001"; $Path="/acme"
+# 
+# Here, the second cookie's Path attribute /acme/ammo is not a prefix of
+# the request URL, /acme/parts/, so the cookie does not get forwarded to
+# the server.
+
+$cookie = interact($c, "http://www.acme.com/acme/parts/");
+print "not " unless $cookie =~ /Rocket_Launcher_0001/ &&
+		    $cookie !~ /Riding_Rocket_0023/;
+print "ok 13\n";
+
+print $c->as_string;
+
+#-----------------------------------------------------------------------
+
+# Test rejection of Set-Cookie2 responses based on domain, path or port
+
+$c = HTTP::Cookies->new;
+
+# illegal domain (no embedded dots)
+$cookie = interact($c, "http://www.acme.com", 'foo=bar; domain=".com"');
+print "not " if count_cookies($c) > 0;
+print "ok 14\n";
+
+# legal domain
+$cookie = interact($c, "http://www.acme.com", 'foo=bar; domain="acme.com"');
+print "not " if count_cookies($c) != 1;
+print "ok 15\n";
+
+# illegal domain (host prefix "www.a" contains a dot)
+$cookie = interact($c, "http://www.a.acme.com", 'foo=bar; domain="acme.com"');
+print "not " if count_cookies($c) != 1;
+print "ok 16\n";
+
+# legal domain
+$cookie = interact($c, "http://www.a.acme.com", 'foo=bar; domain=".a.acme.com"');
+print "not " if count_cookies($c) != 2;
+print "ok 17\n";
+
+# can't use a IP-address as domain
+$cookie = interact($c, "http://125.125.125.125", 'foo=bar; domain="125.125.125"');
+print "not " if count_cookies($c) != 2;
+print "ok 18\n";
+
+# illegal path (must be prefix of request path)
+$cookie = interact($c, "http://www.sol.no", 'foo=bar; domain=".sol.no"; path="/foo"');
+print "not " if count_cookies($c) != 2;
+print "ok 19\n";
+
+# legal path
+$cookie = interact($c, "http://www.sol.no/foo/bar", 'foo=bar; domain=".sol.no"; path="/foo"');
+print "not " if count_cookies($c) != 3;
+print "ok 20\n";
+
+# illegal port (request-port not in list)
+$cookie = interact($c, "http://www.sol.no", 'foo=bar; domain=".sol.no"; port="90,100"');
+print "not " if count_cookies($c) != 3;
+print "ok 21\n";
+
+# legal port
+$cookie = interact($c, "http://www.sol.no", 'foo=bar; domain=".sol.no"; port="90,100, 80,8080"; max-age=100; Comment = "Just kidding! (\"|\\\\) "');
+print "not " if count_cookies($c) != 4;
+print "ok 22\n";
+
+# port attribute without any value (current port)
+$cookie = interact($c, "http://www.sol.no", 'foo9=bar; domain=".sol.no"; port; max-age=100;');
+print "not " if count_cookies($c) != 5;
+print "ok 23\n";
+
+# encoded path
+$cookie = interact($c, "http://www.sol.no/foo/", 'foo8=bar; path="/%66oo"');
+print "not " if count_cookies($c) != 6;
+print "ok 24\n";
+
+my $file = "lwp-cookies-$$.txt";
+$c->save($file);
+$old = $c->as_string;
+undef($c);
+
+$c = HTTP::Cookies->new;
+$c->load($file);
+unlink($file) || warn "Can't unlink $file: $!";
+
+print "not " unless $old eq $c->as_string;
+print "ok 25\n";
+
+undef($c);
+
+#
+# Try some URL encodings of the PATHs
+#
+$c = HTTP::Cookies->new;
+interact($c, "http://www.acme.com/foo%2f%25/%40%40%0Anew%E5/%E5", 'foo  =   bar; version    =   1');
+print $c->as_string;
+
+$cookie = interact($c, "http://www.acme.com/foo%2f%25/@@%0anewå/æøå", "bar=baz; path=\"/foo/\"; version=1");
+print "not " unless $cookie =~ /foo=bar/ && $cookie =~ /^\$version=\"?1\"?/i;
+print "ok 26\n";
+
+$cookie = interact($c, "http://www.acme.com/foo/%25/@@%0anewå/æøå");
+print "not " if $cookie;
+print "ok 27\n";
+
+undef($c);
+
+#
+# Try to use the Netscape cookie file format for saving
+#
+$file = "cookies-$$.txt";
+$c = HTTP::Cookies::Netscape->new(file => $file);
+interact($c, "http://www.acme.com/", "foo1=bar; max-age=100");
+interact($c, "http://www.acme.com/", "foo2=bar; port=\"80\"; max-age=100; Discard; Version=1");
+interact($c, "http://www.acme.com/", "foo3=bar; secure; Version=1");
+$c->save;
+undef($c);
+
+$c = HTTP::Cookies::Netscape->new(file => $file);
+print "not " unless count_cookies($c) == 1;     # 2 of them discarded on save
+print "ok 28\n";
+
+print "not " unless $c->as_string =~ /foo1=bar/;
+print "ok 29\n";
+undef($c);
+unlink($file);
+
+
+#
+# Some additional Netscape cookies test
+#
+$c = HTTP::Cookies->new;
+$req = HTTP::Request->new(POST => "http://foo.bar.acme.com/foo");
+
+# Netscape allows a host part that contains dots
+$res = HTTP::Response->new(200, "OK");
+$res->header(set_cookie => 'Customer=WILE_E_COYOTE; domain=.acme.com');
+$res->request($req);
+$c->extract_cookies($res);
+
+# and that the domain is the same as the host without adding a leading
+# dot to the domain.  Should not quote even if strange chars are used
+# in the cookie value.
+$res = HTTP::Response->new(200, "OK");
+$res->header(set_cookie => 'PART_NUMBER=3,4; domain=foo.bar.acme.com');
+$res->request($req);
+$c->extract_cookies($res);
+
+print $c->as_string;
+
+$req = HTTP::Request->new(POST => "http://foo.bar.acme.com/foo");
+$c->add_cookie_header($req);
+#print $req->as_string;
+print "not " unless $req->header("Cookie") =~ /PART_NUMBER=3,4/ &&
+	            $req->header("Cookie") =~ /Customer=WILE_E_COYOTE/;
+print "ok 30\n";
+
+
+
+# Test handling of local intranet hostnames without a dot
+$c->clear;
+print "---\n";
+#require LWP::Debug;
+#LWP::Debug::level('+');
+
+interact($c, "http://example/", "foo1=bar; PORT; Discard;");
+$_=interact($c, "http://example/", 'foo2=bar; domain=".local"');
+print "not " unless /foo1=bar/;
+print "ok 31\n";
+
+$_=interact($c, "http://example/", 'foo3=bar');
+$_=interact($c, "http://example/");
+print "Cookie: $_\n";
+print "not " unless /foo2=bar/ && count_cookies($c) == 3;
+print "ok 32\n";
+print $c->as_string;
+
+#-------------------------------------------------------------------
+
+sub interact
+{
+    my $c = shift;
+    my $url = shift;
+    my $req = HTTP::Request->new(POST => $url);
+    $c->add_cookie_header($req);
+    my $cookie = $req->header("Cookie");
+    my $res = HTTP::Response->new(200, "OK");
+    $res->request($req);
+    for (@_) { $res->push_header("Set-Cookie2" => $_) }
+    $c->extract_cookies($res);
+    return $cookie;
+}
+
+sub count_cookies
+{
+    my $c = shift;
+    my $no = 0;
+    $c->scan(sub { $no++ });
+    $no;
+}
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/date.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/date.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/date.t	(revision 16571)
@@ -0,0 +1,165 @@
+use HTTP::Date;
+
+print "1..59\n";
+
+$no = 1;
+$| = 1;
+sub ok {
+   print "not " if $_[0];
+   print "ok $no\n";
+   $no++;
+}
+
+# test str2time for supported dates
+my(@tests) =
+(
+ 'Thu Feb  3 00:00:00 GMT 1994',        # ctime format
+ 'Thu Feb  3 00:00:00 1994',            # same as ctime, except no TZ
+
+ 'Thu, 03 Feb 1994 00:00:00 GMT',       # proposed new HTTP format
+ 'Thursday, 03-Feb-94 00:00:00 GMT',    # old rfc850 HTTP format
+ 'Thursday, 03-Feb-1994 00:00:00 GMT',  # broken rfc850 HTTP format
+
+ '03/Feb/1994:00:00:00 0000',   # common logfile format
+ '03/Feb/1994:01:00:00 +0100',  # common logfile format
+ '02/Feb/1994:23:00:00 -0100',  # common logfile format
+
+ '03 Feb 1994 00:00:00 GMT',    # HTTP format (no weekday)
+ '03-Feb-94 00:00:00 GMT',      # old rfc850 (no weekday)
+ '03-Feb-1994 00:00:00 GMT',    # broken rfc850 (no weekday)
+ '03-Feb-1994 00:00 GMT',       # broken rfc850 (no weekday, no seconds)
+ '03-Feb-1994 00:00',           # VMS dir listing format
+
+ '03-Feb-94',    # old rfc850 HTTP format    (no weekday, no time)
+ '03-Feb-1994',  # broken rfc850 HTTP format (no weekday, no time)
+ '03 Feb 1994',  # proposed new HTTP format  (no weekday, no time)
+ '03/Feb/1994',  # common logfile format     (no time, no offset)
+
+ #'Feb  3 00:00',     # Unix 'ls -l' format (can't really test it here)
+ 'Feb  3 1994',       # Unix 'ls -l' format
+
+ "02-03-94  12:00AM", # Windows 'dir' format
+
+ # ISO 8601 formats
+ '1994-02-03 00:00:00 +0000',
+ '1994-02-03',
+ '19940203',
+ '1994-02-03T00:00:00+0000',
+ '1994-02-02T23:00:00-0100',
+ '1994-02-02T23:00:00-01:00',
+ '1994-02-03T00:00:00 Z',
+ '19940203T000000Z',
+ '199402030000',
+
+ # A few tests with extra space at various places
+ '  03/Feb/1994      ',
+ '  03   Feb   1994  0:00  ',
+);
+
+my $time = 760233600;  # assume broken POSIX counting of seconds
+for (@tests) {
+    if (/GMT/i) {
+	$t = str2time($_);
+    } else {
+	$t = str2time($_, "GMT");
+    }
+    $t = "UNDEF" unless defined $t;
+    print "'$_'  =>  $t\n";
+    print $@ if $@;
+    print "not " if $t eq 'UNDEF' || $t != $time;
+    ok;
+}
+
+# test time2str
+die "time2str failed"
+    unless time2str($time) eq 'Thu, 03 Feb 1994 00:00:00 GMT';
+
+# test the 'ls -l' format with missing year$
+# round to nearest minute 3 days ago.
+$time = int((time - 3 * 24*60*60) /60)*60;
+($min, $hr, $mday, $mon) = (localtime $time)[1,2,3,4];
+$mon = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
+$str = sprintf("$mon %02d %02d:%02d", $mday, $hr, $min);
+$t = str2time($str);
+$t = "UNDEF" unless defined $t;
+print "'$str'  =>  $t ($time)\n";
+print "not " if $t != $time;
+ok;
+
+# try some out of bounds date and some garbage.
+for ('03-Feb-1969', '03-Feb-2039',
+     undef, '', 'Garbage',
+     'Mandag 16. September 1996',
+     'Thu Feb  3 00:00:00 CET 1994',
+     'Thu, 03 Feb 1994 00:00:00 CET',
+     'Wednesday, 31-Dec-69 23:59:59 GMT',
+
+     '1980-00-01',
+     '1980-13-01',
+     '1980-01-00',
+     '1980-01-32',
+     '1980-01-01 25:00:00',
+     '1980-01-01 00:61:00',
+     '1980-01-01 00:00:61',
+    )
+{
+    my $bad = 0;
+    eval {
+	if (defined str2time $_) {
+	    print "str2time($_) is not undefined\n";
+	    $bad++;
+	}
+    };
+    print defined($_) ? "'$_'\n" : "undef\n";
+    print $@ if $@;
+    print "not " if $bad;
+    ok;
+}
+
+print "Testing AM/PM gruff...\n";
+
+$t = time2iso(str2time("11-12-96  0:00AM"));print "$t\n";
+ok($t ne "1996-11-12 00:00:00");
+
+$t = time2iso(str2time("11-12-96 12:00AM"));print "$t\n";
+ok($t ne "1996-11-12 00:00:00");
+
+$t = time2iso(str2time("11-12-96  0:00PM"));print "$t\n";
+ok($t ne "1996-11-12 12:00:00");
+
+$t = time2iso(str2time("11-12-96 12:00PM"));print "$t\n";
+ok($t ne "1996-11-12 12:00:00");
+
+
+$t = time2iso(str2time("11-12-96  1:05AM"));print "$t\n";
+ok($t ne "1996-11-12 01:05:00");
+
+$t = time2iso(str2time("11-12-96 12:05AM"));print "$t\n";
+ok($t ne "1996-11-12 00:05:00");
+
+$t = time2iso(str2time("11-12-96  1:05PM"));print "$t\n";
+ok($t ne "1996-11-12 13:05:00");
+
+$t = time2iso(str2time("11-12-96 12:05PM"));print "$t\n";
+ok($t ne "1996-11-12 12:05:00");
+
+
+
+# Test the str2iso routines
+use HTTP::Date qw(time2iso time2isoz);
+
+print "Testing time2iso functions\n";
+
+$a = time2iso;
+$b = time2iso(500000);
+print "LOCAL $a  $b\n";
+$az = time2isoz;
+$bz = time2isoz(500000);
+print "GMT   $az $bz\n";
+
+for ($a,  $b)  { ok if /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/;  }
+for ($az, $bz) { ok if /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$/; }
+
+
+
+print "HTTP::Date $HTTP::Date::VERSION tested ok\n";
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers-auth.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers-auth.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers-auth.t	(revision 16571)
@@ -0,0 +1,40 @@
+print "1..4\n";
+
+use HTTP::Response;
+use HTTP::Headers::Auth;
+
+$res = HTTP::Response->new(401);
+$res->push_header(WWW_Authenticate => qq(Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2"));
+$res->push_header(WWW_Authenticate => qq(Basic Realm="WallyWorld", foo=bar, bar=baz));
+
+print $res->as_string;
+
+%auth = $res->www_authenticate;
+
+print "not " unless keys(%auth) == 3;
+print "ok 1\n";
+
+print "not " unless $auth{basic}{realm} eq "WallyWorld" &&
+                    $auth{bar}{realm} eq "WallyWorld2";
+print "ok 2\n";
+
+$a = $res->www_authenticate;
+print "not " unless $a eq 'Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2", Basic Realm="WallyWorld", foo=bar, bar=baz';
+print "ok 3\n";
+
+$res->www_authenticate("Basic realm=foo1");
+print $res->as_string;
+
+$res->www_authenticate(Basic => {realm => foo2});
+print $res->as_string;
+
+$res->www_authenticate(Basic => [realm => foo3, foo=>33],
+Digest => {nonce=>"bar", foo=>'foo'});
+print $res->as_string;
+
+$_ = $res->as_string;
+
+print "not " unless /WWW-Authenticate: Basic realm="foo3", foo=33/ &&
+                    /WWW-Authenticate: Digest nonce=bar, foo=foo/;
+print "ok 4\n";
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers-etag.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers-etag.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers-etag.t	(revision 16571)
@@ -0,0 +1,28 @@
+print "1..4\n";
+
+require HTTP::Headers::ETag;
+
+$h = HTTP::Headers->new;
+$h->etag("tag1");
+print "not " unless $h->etag eq qq("tag1");
+print "ok 1\n";
+
+$h->etag("w/tag2");
+print "not " unless $h->etag eq qq(W/"tag2");
+print "ok 2\n";
+
+$h->if_match(qq(W/"foo", bar, baz), "bar");
+$h->if_none_match(333);
+
+$h->if_range("tag3");
+print "not " unless $h->if_range eq qq("tag3");
+print "ok 3\n";
+
+$t = time;
+$h->if_range($t);
+print "not " unless $h->if_range == $t;
+print "ok 4\n";
+
+
+print $h->as_string;
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers-util.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers-util.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers-util.t	(revision 16571)
@@ -0,0 +1,61 @@
+use strict;
+use HTTP::Headers::Util qw(split_header_words join_header_words);
+
+my $extra_tests = 2;
+
+my @s_tests = (
+
+   ["foo"                     => "foo"],
+   ["foo=bar"                 => "foo=bar"],
+   ["   foo   "               => "foo"],
+   ["foo="                    => 'foo=""'],
+   ["foo=bar bar=baz"         => "foo=bar; bar=baz"],
+   ["foo=bar;bar=baz"         => "foo=bar; bar=baz"],
+   ['foo bar baz'             => "foo; bar; baz"],
+   ['foo="\"" bar="\\\\"'     => 'foo="\""; bar="\\\\"'],
+   ['foo,,,bar'               => 'foo, bar'],
+   ['foo=bar,bar=baz'         => 'foo=bar, bar=baz'],
+
+   ['text/html; charset=iso-8859-1' =>
+    'text/html; charset="iso-8859-1"'],
+
+   ['foo="bar"; port="80,81"; discard, bar=baz' =>
+    'foo=bar; port="80,81"; discard, bar=baz'],
+
+   ['Basic realm="\"foo\\\\bar\""' =>
+    'Basic; realm="\"foo\\\\bar\""'],
+);
+
+print "1..", @s_tests + $extra_tests, "\n";
+
+my $testno = 1;
+
+print "split_header_words() tests\n";
+for (@s_tests) {
+   my($arg, $expect) = @$_;
+   my @arg = ref($arg) ? @$arg : $arg;
+
+   my $res = join_header_words(split_header_words(@arg));
+   if ($res ne $expect) {
+       print "\nUnexpected result: '$res'\n";
+       print "         Expected: '$expect'\n";
+       print "  when parsing '", join(", ", @arg), "'\n";
+       eval {
+	   require Data::Dumper;
+           my @p = split_header_words(@arg);
+           print Data::Dumper::Dumper(\@p);
+       };
+       print "not ";
+   }
+   print "ok ", $testno++, "\n";
+}
+
+
+print "Extra tests\n";
+# some extra tests
+print "not " unless join_header_words("foo" => undef, "bar" => "baz")
+                    eq "foo; bar=baz";
+print "ok ", $testno++, "\n";
+
+print "not " unless join_header_words() eq "";
+print "ok ", $testno++, "\n";
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/headers.t	(revision 16571)
@@ -0,0 +1,128 @@
+require HTTP::Headers;
+
+print "1..11\n";
+
+$h = new HTTP::Headers
+	mime_version  => "1.0",
+	content_type  => "text/html";
+
+$h->header(URI => "http://www.oslonett.no/");
+
+if ($h->header("MIME-Version") eq "1.0") {
+    print "ok 1\n";
+} else {
+    print "not ok 1\n";
+}
+
+if ($h->header('Uri') =~ /^http:/) {
+    print "ok 2\n";
+} else {
+    print "not ok 2\n";
+}
+
+
+$h->header("MY-header" => "foo",
+	   "Date" => "somedate",
+	   "Accept" => ["text/plain", "image/*"],
+	  );
+$h->push_header("accept" => "audio/basic");
+
+if ($h->header("date") eq "somedate") {
+     print "ok 3\n";
+}
+
+@accept = $h->header("accept");
+if (@accept == 3) {
+    print "ok 4\n";
+}
+
+$h->remove_header("uri", "date");
+
+
+$str = $h->as_string;
+print "\nHeader looks like this now:\n$str\n";
+
+$lines = ($str =~ tr/\n/\n/);
+
+if ($lines == 6) {
+    print "ok 5\n";
+} else {
+    print "Header has $lines lines\n";
+    print "not ok 5\n";
+}
+
+$h2 = $h->clone;
+
+$h->header("accept", "*/*");
+$h->remove_header("my-header");
+
+@accept = $h2->header("accept");
+if (@accept == 3) {
+    print "ok 6\n";
+}
+
+@accept = $h->header("accept");
+if (@accept == 1) {
+    print "ok 7\n";
+}
+
+# Check order of headers, but first remove this one
+$h2->remove_header('mime_version');
+
+# and add this general header
+$h2->header(Connection => 'close');
+
+@x = ();
+$h2->scan(sub {push(@x, shift);});
+
+$str = join(";", @x);
+$expected = "Connection;Accept;Accept;Accept;Content-Type;MY-Header";
+
+if ($str eq $expected) {
+    print "ok 8\n";
+} else {
+    print "Headers are '$str',\nexpected    '$expected'\n";
+    print "not ok 8\n";
+}
+
+# Check headers with embedded newlines:
+
+$h = new HTTP::Headers
+	a => "foo\n\n",
+	b => "foo\nbar",
+	c => "foo\n\nbar\n\n",
+	d => "foo\n\tbar";
+$str = $h->as_string("<<\n");
+print "-----\n$str------\n";
+
+print "not " unless $str =~ /^A:\s*foo<<\n
+                              B:\s*foo<<\n
+	                        \s+bar<<\n
+                              C:\s*foo<<\n
+                                \s+bar<<\n
+	                      D:\s*foo<<\n
+                                \t bar<<\n
+                             $/x;
+print "ok 9\n";
+
+
+# Check with FALSE $HTML::Headers::TRANSLATE_UNDERSCORE
+
+local($HTTP::Headers::TRANSLATE_UNDERSCORE);
+$HTTP::Headers::TRANSLATE_UNDERSCORE = undef;  # avoid -w warning
+
+$h = HTTP::Headers->new;
+
+$h->header(abc_abc   => "foo");
+$h->header("abc-abc" => "bar");
+
+#print $h->as_string;
+
+print "not " unless $h->header("ABC_ABC") eq "foo" &&
+                    $h->header("ABC-ABC") eq "bar";
+print "ok 10\n";
+
+$h->remove_header("Abc_Abc");
+print "not " unless !defined($h->header("abc_abc")) &&
+                    $h->header("ABC-ABC") eq "bar";
+print "ok 11\n";
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/listing.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/listing.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/listing.t	(revision 16571)
@@ -0,0 +1,86 @@
+print "1..6\n";
+
+
+use File::Listing;
+
+$dir = <<'EOL';
+total 68
+drwxr-xr-x   4 aas      users        1024 Mar 16 15:47 .
+drwxr-xr-x  11 aas      users        1024 Mar 15 19:22 ..
+drwxr-xr-x   2 aas      users        1024 Mar 16 15:47 CVS
+-rw-r--r--   1 aas      users        2384 Feb 26 21:14 Debug.pm
+-rw-r--r--   1 aas      users        2145 Feb 26 20:09 IO.pm
+-rw-r--r--   1 aas      users        3960 Mar 15 18:05 MediaTypes.pm
+-rw-r--r--   1 aas      users         792 Feb 26 20:12 MemberMixin.pm
+drwxr-xr-x   3 aas      users        1024 Mar 15 18:05 Protocol
+-rw-r--r--   1 aas      users        5613 Feb 26 20:16 Protocol.pm
+-rw-r--r--   1 aas      users        5963 Feb 26 21:27 RobotUA.pm
+-rw-r--r--   1 aas      users        5071 Mar 16 12:25 Simple.pm
+-rw-r--r--   1 aas      users        8817 Mar 15 18:05 Socket.pm
+-rw-r--r--   1 aas      users        2121 Feb  5 14:22 TkIO.pm
+-rw-r--r--   1 aas      users       19628 Mar 15 18:05 UserAgent.pm
+-rw-r--r--   1 aas      users        2841 Feb  5 19:06 media.types
+
+CVS:
+total 5
+drwxr-xr-x   2 aas      users        1024 Mar 16 15:47 .
+drwxr-xr-x   4 aas      users        1024 Mar 16 15:47 ..
+-rw-r--r--   1 aas      users         545 Mar 16 15:47 Entries
+-rw-r--r--   1 aas      users          39 Mar 10 09:05 Repository
+-rw-r--r--   1 aas      users          19 Mar 10 09:05 Root
+
+Protocol:
+total 37
+drwxr-xr-x   3 aas      users        1024 Mar 15 18:05 .
+drwxr-xr-x   4 aas      users        1024 Mar 16 15:47 ..
+drwxr-xr-x   2 aas      users        1024 Mar 15 18:05 CVS
+-rw-r--r--   1 aas      users        4646 Feb 26 20:13 file.pm
+-rw-r--r--   1 aas      users       13006 Mar 15 18:05 ftp.pm
+-rw-r--r--   1 aas      users        5935 Mar  6 10:29 gopher.pm
+-rw-r--r--   1 aas      users        5453 Mar  6 10:29 http.pm
+-rw-r--r--   1 aas      users        2365 Feb 26 20:13 mailto.pm
+
+Protocol/CVS:
+total 5
+drwxr-xr-x   2 aas      users        1024 Mar 15 18:05 .
+drwxr-xr-x   3 aas      users        1024 Mar 15 18:05 ..
+-rw-r--r--   1 aas      users         238 Mar 15 18:05 Entries
+-rw-r--r--   1 aas      users          48 Mar 10 09:05 Repository
+-rw-r--r--   1 aas      users          19 Mar 10 09:05 Root
+EOL
+
+@dir = parse_dir($dir, undef, 'unix');
+
+print int(@dir) ." lines found\n";
+@dir != 25 && print "not ";
+print "ok 1\n";
+
+for (@dir) {
+   ($name, $type, $size, $mtime, $mode) = @$_;
+   $size ||= 0;  # ensure that it is defined
+   printf "%-25s $type %6d  ", $name, $size;
+   print scalar(localtime($mtime));
+   printf "  %06o", $mode;
+   print "\n";
+}
+
+# Pick out the Socket.pm line as the sample we check carefully
+($name, $type, $size, $mtime, $mode) = @{$dir[9]};
+
+$name eq "Socket.pm" || print "not ";
+print "ok 2\n";
+
+$type eq "f" || print "not ";
+print "ok 3\n";
+
+$size == 8817 || print "not ";
+print "ok 4\n";
+
+# Must be careful when checking the time stamps because we don't know
+# which year if this script lives for a long time.
+$timestring = scalar(localtime($mtime));
+$timestring =~ /Mar\s+15\s+18:05/ or print "not ";
+print "ok 5\n";
+
+$mode == 0100644 || print "not ";
+print "ok 6\n";
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/mediatypes.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/mediatypes.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/mediatypes.t	(revision 16571)
@@ -0,0 +1,87 @@
+use LWP::MediaTypes;
+
+require URI::URL;
+
+$url1 = new URI::URL 'http://www/foo/test.gif?search+x#frag';
+$url2 = new URI::URL 'http:test';
+
+$file = "/etc/passwd";
+-r $file or $file = "./README";
+
+@tests =
+(
+ ["/this.dir/file.html" => "text/html",],
+ ["test.gif.htm"        => "text/html",],
+ ["test.txt.gz"         => "text/plain", "gzip"],
+ ["gif.foo"             => "application/octet-stream",],
+ ["lwp-0.03.tar.Z"      => "application/x-tar", "compress"],
+ [$file		        => "text/plain",],
+ ["/random/file"        => "application/octet-stream",],
+ ["/dev/null"	        => "text/plain",],
+ [$url1	        	=> "image/gif",],
+ [$url2	        	=> "application/octet-stream",],
+ ["x.ppm.Z.UU"		=> "image/x-portable-pixmap","compress","x-uuencode",],
+);
+
+$notests = @tests + 3;
+print "1..$notests\n";
+
+if (-f "$ENV{HOME}/.mime.types") {
+   warn "
+The MediaTypes test might fail because you have a private ~/.mime.types file
+If you get a failed test, try to move it away while testing.
+";
+}
+
+
+$testno = 1;
+for (@tests) {
+    ($file, $expectedtype, @expectedEnc) = @$_;
+    $type1 = guess_media_type($file);
+    ($type, @enc) = guess_media_type($file);
+    if ($type1 ne $type) {
+       print "guess_media_type does not return same content-type in scalar and array conext.\n";
+	next;
+    }
+    $type = "undef" unless defined $type;
+    if ($type eq $expectedtype and "@enc" eq "@expectedEnc") {
+	print "ok $testno\n";
+    } else {
+	print "expected '$expectedtype' for '$file', got '$type'\n";
+	print "encoding: expected: '@expectedEnc', got '@enc'\n"
+	  if @expectedEnc || @enc;
+	print "nok ok $testno\n";
+    }
+    $testno++;
+}
+
+@imgSuffix = media_suffix('image/*');
+print "Image suffixes: @imgSuffix\n";
+
+print "\n";
+require HTTP::Response;
+$r = new HTTP::Response 200, "Document follows";
+$r->title("file.tar.gz.uu");
+guess_media_type($r->title, $r);
+print $r->as_string;
+
+print "not " unless $r->content_type eq "application/x-tar";
+print "ok $testno\n"; $testno++;
+
+@enc = $r->header("Content-Encoding");
+print "not " unless "@enc" eq "gzip x-uuencode";
+print "ok $testno\n"; $testno++;
+
+#
+use LWP::MediaTypes qw(add_type add_encoding);
+add_type("x-world/x-vrml", qw(wrl vrml));
+add_encoding("x-gzip" => "gz");
+add_encoding(rot13 => "r13");
+
+@x = guess_media_type("foo.vrml.r13.gz");
+#print "@x\n";
+print "not " unless "@x" eq "x-world/x-vrml rot13 x-gzip";
+print "ok $testno\n"; $testno++;
+
+#print LWP::MediaTypes::_dump();
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/message.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/message.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/message.t	(revision 16571)
@@ -0,0 +1,104 @@
+print "1..15\n";
+
+require HTTP::Request;
+require HTTP::Response;
+
+$req = new HTTP::Request 'GET', "http://www.sn.no/";
+$req->header(
+	"if-modified-since" => "Thu, 03 Feb 1994 00:00:00 GMT",
+	"mime-version"      => "1.0");
+
+$str = $req->as_string;
+
+print $str;
+
+$str =~ /^GET/m || print "not ";
+print "ok 1\n";
+
+$req->header("MIME-Version") eq "1.0" || print "not ";
+print "ok 2\n";
+
+$req->content("gisle");
+$req->add_content(" aas");
+$req->add_content(\ " old interface is depreciated");
+
+${$req->content_ref} =~ s/\s+is\s+depreciated//;
+
+print "Content is: ", $req->content, "\n";
+
+$req->content eq "gisle aas old interface" || print "not ";
+print "ok 3\n";
+
+$req->if_modified_since == 760233600 || print "not ";
+print "ok 4\n";
+
+$time = time;
+
+$req->date($time);
+$timestr = gmtime($time);
+($month) = ($timestr =~ /^\S+\s+(\S+)/);  # extract month;
+
+print "These should represent the same time:\n\t", $req->header('Date'), "\n\t$timestr\n";
+
+$req->header('Date') =~ /\Q$month/ || print "not ";
+print "ok 5\n";
+
+$req->authorization_basic("gisle", "passwd");
+$auth = $req->header("Authorization");
+
+print "$auth\n";
+$auth =~ /Z2lzbGU6cGFzc3dk/ || print "not ";
+print "ok 6\n";
+
+($user, $pass) = $req->authorization_basic;
+($user eq "gisle" && $pass eq "passwd") || print "not ";
+print "ok 7\n";
+
+# Check the response
+$res = new HTTP::Response 200, "This message";
+
+$html = $res->error_as_HTML;
+print $html;
+
+($html =~ /<head>/i && $html =~ /This message/) || print "not ";
+print "ok 8\n";
+
+$res->is_success || print "not ";
+print "ok 9\n";
+
+$res->content_type("text/html;version=3.0");
+$res->content("<html>...</html>\n");
+
+$res2 = $res->clone;
+
+print $res2->as_string;
+
+$res2->header("cOntent-TYPE") eq "text/html;version=3.0" || print "not ";
+print "ok 10\n";
+
+$res2->code == 200 || print "not ";
+print "ok 11\n";
+
+$res2->content =~ />\.\.\.</ || print "not ";
+print "ok 12\n";
+
+# Check the base method:
+
+$res = new HTTP::Response 200, "This message";
+$res->request($req);
+$res->content_type("image/gif");
+
+$res->base eq "http://www.sn.no/" || print "not ";
+print "ok 13\n";
+
+$res->header('Base', 'http://www.sn.no/xxx/');
+
+$res->base eq "http://www.sn.no/xxx/" || print "not ";
+print "ok 14\n";
+
+# Check the AUTLOAD delegate method with regular expressions
+"This string contains text/html" =~ /(\w+\/\w+)/;
+$res->content_type($1);
+
+$res->content_type eq "text/html" || print "not ";
+print "ok 15\n";
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/negotiate.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/negotiate.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/negotiate.t	(revision 16571)
@@ -0,0 +1,105 @@
+print "1..3\n";
+
+use HTTP::Request;
+use HTTP::Negotiate;
+
+
+$no = 1;
+sub ok
+{
+    print "ok " . $no++ . "\n";
+}
+
+sub not_ok
+{
+    print "not ";
+    ok;
+}
+
+
+ #  ID       QS     Content-Type             Encoding     Char-Set      Lang    Size
+ $variants =
+  [
+   ['var1',  0.950, 'text/plain',           ['uuencode',
+					     'compress'], 'iso-8859-2', 'se',    400],
+   ['var2',  1.000, 'text/html;version=2.0', 'gzip',      'iso-8859-1', 'en',   3000],
+   ['var3',  0.333, 'image/gif',            undef,        undef,        undef, 43555],
+ ];
+
+
+# First we try a request with not accept headers
+$request = new HTTP::Request 'GET', 'http://localhost/';
+@a = choose($variants, $request);
+show_res(@a);
+expect(\@a, [['var2' => 1],
+	     ['var1' => 0.95],
+	     ['var3' => 0.333]
+	    ]
+);
+
+
+$a = choose($variants, $request);
+print "The chosen one is '$a'\n";
+if ($a eq 'var2') {
+    ok;
+} else {
+    not_ok;
+}
+
+#------------------
+
+$request = new HTTP::Request 'GET', 'http://localhost/';
+$request->header('Accept', 'text/plain; q=0.55, image/gif; mbx=10000');
+$request->push_header('Accept', 'text/*; q=0.25');
+$request->header('Accept-Language', 'no, en');
+$request->header('Accept-Charset', 'iso-8859-1');
+$request->header('Accept-Encoding', 'gzip');
+
+@a = choose($variants, $request);
+show_res(@a);
+expect(\@a, [['var2' => 0.25],
+	     ['var1' => 0],
+	     ['var3' => 0]
+	    ]
+);
+
+
+
+
+#------------------
+
+sub expect
+{
+    my($res, $exp) = @_;
+    do {
+	$a = shift @$res;
+	$b = shift @$exp;
+	last if defined($a) ne defined($b);
+	if (defined($a)) {
+	    ($va, $qa) = @$a;
+	    ($vb, $qb) = @$b;
+	    if ($va ne $vb) {
+		print "$va == $vb ?\n";
+		not_ok;
+		return;
+	    }
+	    if (abs($qa - $qb) > 0.002) {
+		print "$qa ~= $qb ?\n";
+		not_ok;
+		return;
+	    }
+	}
+
+    } until (!defined($a) || !defined($b));
+    return not_ok if defined($a) ne defined($b);
+    ok;
+}
+
+sub show_res
+{
+    print "-------------\n";
+    for (@_) {
+	printf "%-6s %.3f\n", @$_;
+    }
+    print "-------------\n";
+}
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/response.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/response.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/response.t	(revision 16571)
@@ -0,0 +1,86 @@
+
+# Test extra HTTP::Response methods.  Basic operation is tested in the
+# message.t test suite.
+
+
+print "1..7\n";
+
+
+use HTTP::Date;
+use HTTP::Request;
+use HTTP::Response;
+
+my $time = time;
+
+$req = HTTP::Request->new(GET => 'http://www.sn.no');
+$req->date($time - 30);
+
+$r = new HTTP::Response 200, "OK";
+$r->client_date($time - 20);
+$r->date($time - 25);
+$r->last_modified($time - 5000000);
+$r->request($req);
+
+print $r->as_string;
+
+$current_age = $r->current_age;
+
+if ($current_age < 35  || $current_age > 40) {
+    print "not ";
+}
+print "ok 1\n";
+
+$freshness_lifetime = $r->freshness_lifetime;
+if ($freshness_lifetime < 12 * 3600) {
+    print "not ";
+}
+print "ok 2\n";
+
+$is_fresh = $r->is_fresh;
+
+print "not " unless $is_fresh;
+print "ok 3\n";
+
+print "current_age        = $current_age\n";
+print "freshness_lifetime = $freshness_lifetime\n";
+print "response is ";
+print "not " unless $is_fresh;
+print "fresh\n";
+
+
+print "it will be fresh is ";
+print $freshness_lifetime - $current_age;
+print " more seconds\n";
+
+# OK, now we add an Expires header
+$r->expires($time);
+print $r->as_string;
+
+$freshness_lifetime = $r->freshness_lifetime;
+print "freshness_lifetime = $freshness_lifetime\n";
+print "not " unless $freshness_lifetime == 25;
+print "ok 4\n";
+$r->remove_header('expires');
+
+# Now we try the 'Age' header and the Cache-Contol:
+
+$r->header('Age', 300);
+$r->push_header('Cache-Control', 'junk');
+$r->push_header(Cache_Control => 'max-age = 10');
+
+print $r->as_string;
+
+$current_age = $r->current_age;
+$freshness_lifetime = $r->freshness_lifetime;
+
+print "current_age        = $current_age\n";
+print "freshness_lifetime = $freshness_lifetime\n";
+
+print "not " if $current_age < 300;
+print "ok 5\n";
+
+print "not " if $freshness_lifetime != 10;
+print "ok 6\n";
+
+print "not " unless $r->fresh_until;  # should return something
+print "ok 7\n";
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/status.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/status.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/base/status.t	(revision 16571)
@@ -0,0 +1,32 @@
+use HTTP::Status;
+
+print "1..8\n";
+
+200 == RC_OK || print "not ";
+print "ok 1\n";
+
+is_success(RC_ACCEPTED) || print "not ";
+print "ok 2\n";
+
+is_error(RC_BAD_REQUEST) || print "not ";
+print "ok 3\n";
+
+is_redirect(RC_MOVED_PERMANENTLY) || print "not ";
+print "ok 4\n";
+
+is_success(RC_NOT_FOUND) && print "not ";
+print "ok 5\n";
+
+$mess = status_message(0);
+
+defined $mess && print "not ";
+print "ok 6\n";
+
+$mess = status_message(200);
+
+if ($mess =~ /ok/i) {
+    print "ok 7\n";
+}
+
+is_info(RC_CONTINUE) || print "not ";
+print "ok 8\n";
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/autoload.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/autoload.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/autoload.t	(revision 16571)
@@ -0,0 +1,30 @@
+#
+# See if autoloading of protocol schemes work
+#
+
+print "1..1\n";
+
+require LWP::UserAgent;
+# note no LWP::Protocol::file;
+
+# localhost will not work on win32 (when networking is disabled)
+$url = $^O eq 'MSWin32' ? 'file:.' : 'file://localhost/';
+
+print "Trying to fetch " . (new URI::URL $url)->local_path . " ...\n";
+
+my $ua = new LWP::UserAgent;    # create a useragent to test
+
+$ua->timeout(30);               # timeout in seconds
+#$ua->use_alarm(0);               # don't use alarms
+#$ua->use_eval(0);                # don't eval, just die when thing go wrong
+				# (easier to read while debugging)
+
+my $request = new HTTP::Request('GET', $url);
+
+my $response = $ua->request($request, undef, undef);
+if ($response->is_success) {
+    print "ok 1\n";
+} else {
+    print $response->error_as_HTML;
+    print "not ok 1\n";
+}
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/get.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/get.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/get.t	(revision 16571)
@@ -0,0 +1,85 @@
+#
+# Test retrieving a file with a 'file://' URL,
+#
+
+# First locate some suitable tmp-dir.  We need an absolute path.
+$TMPDIR = undef;
+for ("/tmp/", "/var/tmp", "/usr/tmp", "/local/tmp") {
+    if (open(TEST, ">$_/test-$$")) {
+        close(TEST);
+	unlink("$_/test-$$");
+	$TMPDIR = $_;
+	last;
+    }
+}
+$TMPDIR ||= $ENV{TEMP} if $^O eq 'MSWin32';
+unless ($TMPDIR) {
+   # Can't run any tests
+   print "1..0\n";
+   print "ok 1\n";
+   exit;
+}
+$TMPDIR =~ tr|\\|/|;
+print "1..2\n";
+
+use LWP::Simple;
+require LWP::Protocol::file;
+
+my $orig = "$TMPDIR/lwp-orig-$$";          # local file
+my $copy = "$TMPDIR/lwp-copy-$$"; 	    # downloaded copy
+
+# First we create the original
+open(OUT, ">$orig") or die "Cannot open $orig: $!";
+for (1..100) {
+    print OUT "This is line $_ of $orig\n";
+}
+close(OUT);
+
+
+# Then we make a test using getprint(), so we need to capture stdout
+open (OUT, ">$copy") or die "Cannot open $copy: $!";
+select(OUT);
+
+# do the retrieval
+getprint("file://localhost" . ($orig =~ m|^/| ? $orig : "/$orig"));
+
+close(OUT);
+select(STDOUT);
+
+# read and compare the files
+open(IN, $orig) or die "Cannot open '$orig': $!";
+undef($/);
+$origtext = <IN>;
+close(IN);
+open(IN, $copy) or die "Cannot open '$copy': $!";
+undef($/);
+$copytext = <IN>;
+close(IN);
+
+unlink($copy);
+
+if ($origtext eq $copytext) {
+    print "ok 1\n";
+} else {
+    print "not ok 1\n";
+}
+
+
+# Test getstore() function
+
+getstore("file:$orig", $copy);
+
+# Take a look at the new copy
+open(IN, $copy) or die "Cannot open '$copy': $!";
+undef($/);
+$copytext = <IN>;
+close(IN);
+
+unlink($orig);
+unlink($copy);
+
+if ($origtext eq $copytext) {
+    print "ok 2\n";
+} else {
+    print "not ok 2\n";
+}
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/http.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/http.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/http.t	(revision 16571)
@@ -0,0 +1,319 @@
+$| = 1; # autoflush
+
+require IO::Socket;  # make sure this work before we try to make a HTTP::Daemon
+
+# First we make ourself a daemon in another process
+my $D = shift || '';
+if ($D eq 'daemon') {
+
+    require HTTP::Daemon;
+
+    my $d = new HTTP::Daemon Timeout => 10;
+
+    print "Please to meet you at: <URL:", $d->url, ">\n";
+    open(STDOUT, ">/dev/null");
+
+    while ($c = $d->accept) {
+	$r = $c->get_request;
+	if ($r) {
+	    my $p = ($r->url->path_components)[1];
+	    my $func = lc("httpd_" . $r->method . "_$p");
+	    if (defined &$func) {
+		&$func($c, $r);
+	    } else {
+		$c->send_error(404);
+	    }
+	}
+	$c = undef;  # close connection
+    }
+    print STDERR "HTTP Server terminated\n";
+    exit;
+}
+else {
+    use Config;
+    open(DAEMON, "$Config{'perlpath'} local/http.t daemon |") or die "Can't exec daemon: $!";
+}
+
+print "1..18\n";
+
+
+my $greeting = <DAEMON>;
+$greeting =~ /(<[^>]+>)/;
+
+require URI::URL;
+URI::URL->import;
+my $base = new URI::URL $1;
+
+print "Will access HTTP server at $base\n";
+
+require LWP::UserAgent;
+require HTTP::Request;
+$ua = new LWP::UserAgent;
+$ua->agent("Mozilla/0.01 " . $ua->agent);
+$ua->from('gisle@aas.no');
+
+#----------------------------------------------------------------
+print "Bad request...\n";
+$req = new HTTP::Request GET => url("/not_found", $base);
+$req->header(X_Foo => "Bar");
+$res = $ua->request($req);
+
+print "not " unless $res->is_error
+                and $res->code == 404
+                and $res->message =~ /not\s+found/i;
+print "ok 1\n";
+# we also expect a few headers
+print "not " if !$res->server and !$res->date;
+print "ok 2\n";
+
+#----------------------------------------------------------------
+print "Simple echo...\n";
+sub httpd_get_echo
+{
+    my($c, $req) = @_;
+    $c->send_basic_header(200);
+    print $c "Content-Type: text/plain\015\012";
+    $c->send_crlf;
+    print $c $req->as_string;
+}
+
+$req = new HTTP::Request GET => url("/echo/path_info?query", $base);
+$req->push_header(Accept => 'text/html');
+$req->push_header(Accept => 'text/plain; q=0.9');
+$req->push_header(Accept => 'image/*');
+$req->if_modified_since(time - 300);
+$req->header(Long_text => 'This is a very long header line
+which is broken between
+more than one line.');
+$req->header(X_Foo => "Bar");
+
+$res = $ua->request($req);
+#print $res->as_string;
+
+print "not " unless $res->is_success
+               and  $res->code == 200 && $res->message eq "OK";
+print "ok 3\n";
+
+$_ = $res->content;
+@accept = /^Accept:\s*(.*)/mg;
+
+print "not " unless /^From:\s*gisle\@aas\.no$/m
+                and /^Host:/m
+                and @accept == 3
+	        and /^Accept:\s*text\/html/m
+	        and /^Accept:\s*text\/plain/m
+	        and /^Accept:\s*image\/\*/m
+		and /^If-Modified-Since:\s*\w{3},\s+\d+/m
+                and /^Long-Text:\s*This.*broken between/m
+		and /^X-Foo:\s*Bar$/m
+		and /^User-Agent:\s*Mozilla\/0.01/m;
+print "ok 4\n";
+
+#----------------------------------------------------------------
+print "Send file...\n";
+
+my $file = "test-$$.html";
+open(FILE, ">$file") or die "Can't create $file: $!";
+binmode FILE or die "Can't binmode $file: $!";
+print FILE <<EOT;
+<html><title>En prøve</title>
+<h1>Dette er en testfil</h1>
+Jeg vet ikke hvor stor fila behøver å være heller, men dette
+er sikkert nok i massevis.
+EOT
+close(FILE);
+
+sub httpd_get_file
+{
+    my($c, $r) = @_;
+    my %form = $r->url->query_form;
+    my $file = $form{'name'};
+    $c->send_file_response($file);
+    unlink($file);
+}
+
+$req = new HTTP::Request GET => url("/file?name=$file", $base);
+$res = $ua->request($req);
+#print $res->as_string;
+
+print "not " unless $res->is_success
+                and $res->content_type eq 'text/html'
+		and $res->content_length == 147
+		and $res->title eq 'En prøve'
+		and $res->content =~ /å være/;
+print "ok 5\n";		
+
+
+# A second try on the same file, should fail because we unlink it
+$res = $ua->request($req);
+#print $res->as_string;
+print "not " unless $res->is_error
+                and $res->code == 404;   # not found
+print "ok 6\n";
+		
+# Then try to list current directory
+$req = new HTTP::Request GET => url("/file?name=.", $base);
+$res = $ua->request($req);
+#print $res->as_string;
+print "not " unless $res->code == 501;   # NYI
+print "ok 7\n";
+
+
+#----------------------------------------------------------------
+print "Check redirect...\n";
+sub httpd_get_redirect
+{
+   my($c) = @_;
+   $c->send_redirect("/echo/redirect");
+}
+
+$req = new HTTP::Request GET => url("/redirect/foo", $base);
+$res = $ua->request($req);
+#print $res->as_string;
+
+print "not " unless $res->is_success
+                and $res->content =~ m|/echo/redirect|;
+print "ok 8\n";
+print "not " unless $res->previous->is_redirect
+                and $res->previous->code == 301;
+print "ok 9\n";
+
+# Let's test a redirect loop too
+sub httpd_get_redirect2 { shift->send_redirect("/redirect3/") }
+sub httpd_get_redirect3 { shift->send_redirect("/redirect4/") }
+sub httpd_get_redirect4 { shift->send_redirect("/redirect5/") }
+sub httpd_get_redirect5 { shift->send_redirect("/redirect6/") }
+sub httpd_get_redirect6 { shift->send_redirect("/redirect2/") }
+
+$req->url(url("/redirect2", $base));
+$res = $ua->request($req);
+#print $res->as_string;
+print "not " unless $res->is_redirect
+                and $res->header("Client-Warning") =~ /loop detected/i;
+print "ok 10\n";
+$i = 1;
+while ($res->previous) {
+   $i++;
+   $res = $res->previous;
+}
+print "not " unless $i == 6;
+print "ok 11\n";
+
+#----------------------------------------------------------------
+print "Check basic authorization...\n";
+sub httpd_get_basic
+{
+    my($c, $r) = @_;
+    #print STDERR $r->as_string;
+    my($u,$p) = $r->authorization_basic;
+    if (defined($u) && $u eq 'ok 12' && $p eq 'xyzzy') {
+        $c->send_basic_header(200);
+	print $c "Content-Type: text/plain";
+	$c->send_crlf;
+	$c->send_crlf;
+	$c->print("$u\n");
+    } else {
+        $c->send_basic_header(401);
+	$c->print("WWW-Authenticate: Basic realm=\"libwww-perl\"\015\012");
+	$c->send_crlf;
+    }
+}
+
+{
+   package MyUA; @ISA=qw(LWP::UserAgent);
+   sub get_basic_credentials {
+      my($self, $realm, $uri, $proxy) = @_;
+      my $x =  $uri->rel($base);
+      if ($realm eq "libwww-perl" && $uri->rel($base) eq "basic") {
+	  return ("ok 12", "xyzzy");
+      } else {
+          return undef;
+      }
+   }
+}
+$req = new HTTP::Request GET => url("/basic", $base);
+$res = MyUA->new->request($req);
+#print $res->as_string;
+
+print "not " unless $res->is_success;
+print $res->content;
+
+# Let's try with a $ua that does not pass out credentials
+$res = $ua->request($req);
+print "not " unless $res->code == 401;
+print "ok 13\n";
+
+# Let's try to set credentials for this realm
+$ua->credentials($req->url->netloc, "libwww-perl", "ok 12", "xyzzy");
+$res = $ua->request($req);
+print "not " unless $res->is_success;
+print "ok 14\n";
+
+# Then illegal credentials
+$ua->credentials($req->url->netloc, "libwww-perl", "user", "passwd");
+$res = $ua->request($req);
+print "not " unless $res->code == 401;
+print "ok 15\n";
+
+
+#----------------------------------------------------------------
+print "Check proxy...\n";
+sub httpd_get_proxy
+{
+   my($c,$r) = @_;
+   if ($r->method eq "GET" and
+       $r->url->scheme eq "ftp") {
+       $c->send_basic_header(200);
+       $c->send_crlf;
+   } else {
+       $c->send_error;
+   }
+}
+
+$ua->proxy(ftp => $base);
+$req = new HTTP::Request GET => "ftp://ftp.perl.com/proxy";
+$res = $ua->request($req);
+#print $res->as_string;
+print "not " unless $res->is_success;
+print "ok 16\n";
+
+#----------------------------------------------------------------
+print "Check POSTing...\n";
+sub httpd_post_echo
+{
+   my($c,$r) = @_;
+   $c->send_basic_header;
+   $c->print("Content-Type: text/plain");
+   $c->send_crlf;
+   $c->send_crlf;
+   $c->print($r->as_string);
+}
+
+$req = new HTTP::Request POST => url("/echo/foo", $base);
+$req->content_type("application/x-www-form-urlencoded");
+$req->content("foo=bar&bar=test");
+$res = $ua->request($req);
+#print $res->as_string;
+
+$_ = $res->content;
+print "not " unless $res->is_success
+                and /^Content-Length:\s*16$/mi
+		and /^Content-Type:\s*application\/x-www-form-urlencoded$/mi
+		and /^foo=bar&bar=test/m;
+print "ok 17\n";		
+
+#----------------------------------------------------------------
+print "Terminating server...\n";
+sub httpd_get_quit
+{
+    my($c) = @_;
+    $c->send_error(503, "Bye, bye");
+    exit;  # terminate HTTP server
+}
+
+$req = new HTTP::Request GET => url("/quit", $base);
+$res = $ua->request($req);
+
+print "not " unless $res->code == 503 and $res->content =~ /Bye, bye/;
+print "ok 18\n";
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/protosub.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/protosub.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/local/protosub.t	(revision 16571)
@@ -0,0 +1,73 @@
+#!perl
+
+print "1..6\n";
+
+# This test tries to make a custom protocol implementation by
+# subclassing of LWP::Protocol.
+
+
+use LWP::UserAgent ();
+use LWP::Protocol ();
+
+LWP::Protocol::implementor(http => 'myhttp');
+
+$ua = LWP::UserAgent->new;
+$ua->proxy('ftp' => "http://www.sn.no/");
+
+$req = HTTP::Request->new(GET => 'ftp://foo/');
+$req->header(Cookie => "perl=cool");
+
+$res = $ua->request($req);
+
+print $res->as_string;
+
+print "not " unless $res->code == 200;
+print "ok 5\n";
+print "not " unless $res->content eq "Howdy\n";
+print "ok 6\n";
+exit;
+
+
+#----------------------------------
+package myhttp;
+
+BEGIN {
+   @ISA=qw(LWP::Protocol);
+}
+
+sub new
+{
+    my $class = shift;
+    print "CTOR: $class->new(@_)\n";
+    my($prot) = @_;
+    print "not " unless $prot eq "http";
+    print "ok 1\n";
+    my $self = $class->SUPER::new(@_);
+    for (keys %$self) {
+	print "$_: $self->{$_}\n";
+    }
+    $self;
+}
+
+sub request
+{
+    my $self = shift;
+    print "REQUEST: $self->request(",
+       join(",", (map defined($_)? $_ : "UNDEF", @_)), ")\n";
+
+    my($request, $proxy, $arg, $size, $timeout) = @_;
+    print $request->as_string;
+
+    print "not " unless $proxy eq "http://www.sn.no/";
+    print "ok 2\n";
+    print "not " unless $request->url eq "ftp://foo/";
+    print "ok 3\n";
+    print "not " unless $request->header("cookie") eq "perl=cool";
+    print "ok 4\n";
+
+    my $res = HTTP::Response->new(200 => "OK");
+    $res->content_type("text/plain");
+    $res->date(time);
+    $self->collect_once($arg, $res, "Howdy\n");
+    $res;
+}
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/moved
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/moved	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/moved	(revision 16571)
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+echo "Location: http://$SERVER_NAME:$SERVER_PORT/"
+echo
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/nph-slowdata
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/nph-slowdata	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/nph-slowdata	(revision 16571)
@@ -0,0 +1,26 @@
+#!/usr/local/bin/perl
+
+# This script outputs some data slowly. It can be used to check that
+# pipelined processing of response content really works.  We use syswrite
+# so that the script will notice when the connection is broken.
+
+out("HTTP/1.0 200 OK\r
+Content-Type: text/plain\r
+\r
+");
+
+for (1..5) {
+    out("The number is now $_\n");
+    sleep(1);
+}
+exit;
+
+
+sub out
+{
+    my $data = shift;
+    my $l = length $data;
+    if (syswrite(STDOUT, $data, $l) != $l) {
+	exit 1;
+    }
+}
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/slowread
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/slowread	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/slowread	(revision 16571)
@@ -0,0 +1,31 @@
+#!/usr/local/bin/perl
+
+# You might post large amount of data to this script.  It will read
+# it slowly.
+
+{ local($!) = 1; print "Content-Type: text/plain\n\n"; }
+
+$len = $ENV{CONTENT_LENGTH};
+
+unless ($len) {
+    system "env";
+    exit;
+}
+
+$size = 20;  # chunk size
+
+$content = '';
+$bytes = 0;
+
+sleep(1);
+while ($len > 0) {
+    $n = sysread(STDIN, $b, $size);
+    last if $n <= 0;
+    $len -= $n;
+    $bytes += $n;
+    $content .= $b;
+    sleep(1);
+}
+print "$bytes bytes read\n";
+
+	
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/test
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/test	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/test	(revision 16571)
@@ -0,0 +1,28 @@
+#!/usr/local/bin/perl
+
+$| = 1;
+print "Content-type: text/plain
+
+";
+
+if (@ARGV) {
+    print "ARGS: ";
+    print join(", ", map { $_ = qq{"$_"} } @ARGV);
+    print "\n\n";
+} else {
+    print "No command line arguments passed to script\n\n";
+}
+
+while (($key,$val) = each %ENV) {
+   print "$key=$val\n";
+}
+
+if ($ENV{CONTENT_LENGTH}) {
+    $len = $ENV{CONTENT_LENGTH};
+    while ($len) {
+	$n = sysread(STDIN, $content, $len, length $content);
+	last unless defined $n;
+	$len -= $n;
+    }
+    print "\nContent\n-------\n$content";
+}
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/timeout
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/timeout	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/cgi-bin/timeout	(revision 16571)
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+sleep 20;
+
+echo "Content-type: text/plain"
+echo
+echo "Test"
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/config.pl.dist
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/config.pl.dist	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/config.pl.dist	(revision 16571)
@@ -0,0 +1,10 @@
+package net;
+
+# Configure these for you local system
+$httpserver  = "localhost:80";
+$cgidir      = "/cgi-bin/lwp";
+
+# Used for proxy test
+$ftp_proxy = "http://localhost/";
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/http-get.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/http-get.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/http-get.t	(revision 16571)
@@ -0,0 +1,43 @@
+#!/usr/local/bin/perl -w
+#
+# Check GET via HTTP.
+#
+
+print "1..2\n";
+
+require "net/config.pl";
+require LWP::Protocol::http;
+require LWP::UserAgent;
+
+my $ua = new LWP::UserAgent;    # create a useragent to test
+
+$netloc = $net::httpserver;
+$script = $net::cgidir . "/test";
+
+$url = new URI::URL("http://$netloc$script?query");
+
+my $request = new HTTP::Request('GET', $url);
+
+print "GET $url\n\n";
+
+my $response = $ua->request($request, undef, undef);
+
+my $str = $response->as_string;
+
+print "$str\n";
+
+if ($response->is_success and $str =~ /^REQUEST_METHOD=GET$/m) {
+    print "ok 1\n";
+} else {
+    print "not ok 1\n";
+}
+
+if ($str =~ /^QUERY_STRING=query$/m) {
+    print "ok 2\n";
+} else {
+    print "not ok 2\n";
+}
+
+# avoid -w warning
+$dummy = $net::httpserver;
+$dummy = $net::cgidir;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/http-post.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/http-post.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/http-post.t	(revision 16571)
@@ -0,0 +1,44 @@
+#!/usr/local/bin/perl -w
+#
+# Check POST via HTTP.
+#
+
+print "1..2\n";
+
+require "net/config.pl";
+require LWP::Protocol::http;
+require LWP::UserAgent;
+
+$netloc = $net::httpserver;
+$script = $net::cgidir . "/test";
+
+my $ua = new LWP::UserAgent;    # create a useragent to test
+
+$url = new URI::URL("http://$netloc$script");
+
+my $form = 'searchtype=Substring';
+
+my $request = new HTTP::Request('POST', $url, undef, $form);
+$request->header('Content-Type', 'application/x-www-form-urlencoded');
+
+my $response = $ua->request($request, undef, undef);
+
+my $str = $response->as_string;
+
+print "$str\n";
+
+if ($response->is_success and $str =~ /^REQUEST_METHOD=POST$/m) {
+    print "ok 1\n";
+} else {
+    print "not ok 1\n";
+}
+
+if ($str =~ /^CONTENT_LENGTH=(\d+)$/m && $1 == length($form)) {
+    print "ok 2\n";
+} else {
+    print "not ok 2\n";
+}
+
+# avoid -w warning
+$dummy = $net::httpserver;
+$dummy = $net::cgidir;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/http-timeout.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/http-timeout.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/http-timeout.t	(revision 16571)
@@ -0,0 +1,41 @@
+#
+# Check timeouts via HTTP.
+#
+
+print "1..1\n";
+
+require "net/config.pl";
+require HTTP::Status;
+require LWP::Protocol::http;
+require LWP::UserAgent;
+
+my $ua = new LWP::UserAgent;    # create a useragent to test
+
+$ua->timeout(4);
+
+$netloc = $net::httpserver;
+$script = $net::cgidir . "/timeout";
+
+$url = new URI::URL("http://$netloc$script");
+
+my $request = new HTTP::Request('GET', $url);
+
+print $request->as_string;
+
+my $response = $ua->request($request, undef);
+
+my $str = $response->as_string;
+
+print "$str\n";
+
+if ($response->is_error and
+    $str =~ /timeout/) {
+    print "ok 1\n";
+}
+else {
+    print "nok ok 1\n";
+}
+
+# avoid -w warning
+$dummy = $net::httpserver;
+$dummy = $net::cgidir;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/mirror.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/mirror.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/mirror.t	(revision 16571)
@@ -0,0 +1,34 @@
+#
+# Test mirroring a file
+#
+
+require "net/config.pl";
+require LWP::Protocol::http;
+require LWP::UserAgent;
+require HTTP::Status;
+
+print "1..2\n";
+
+my $ua = new LWP::UserAgent;    # create a useragent to test
+
+my $url = "http://$net::httpserver/";
+my $copy = "lwp-test-$$"; # downloaded copy
+
+my $response = $ua->mirror($url, $copy);
+
+if ($response->code == &HTTP::Status::RC_OK) {
+    print "ok 1\n";
+} else {
+    print "not ok 1\n";
+}
+
+# OK, so now do it again, should get Not-Modified
+$response = $ua->mirror($url, $copy);
+if ($response->code == &HTTP::Status::RC_NOT_MODIFIED) {
+    print "ok 2\n";
+} else {
+    print "nok ok 2\n";
+}
+unlink($copy);
+
+$net::httpserver = $net::httpserver;  # avoid -w warning
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/moved.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/moved.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/moved.t	(revision 16571)
@@ -0,0 +1,34 @@
+#!/usr/local/bin/perl -w
+#
+
+print "1..1\n";
+
+require "net/config.pl";
+require LWP::Debug;
+require LWP::UserAgent;
+
+$url = "http://$net::httpserver$net::cgidir/moved";
+
+#LWP::Debug::level('+trace');
+
+my $ua = new LWP::UserAgent;    # create a useragent to test
+$ua->timeout(30);               # timeout in seconds
+
+my $request = new HTTP::Request('GET', $url);
+
+print $request->as_string;
+
+my $response = $ua->request($request, undef, undef);
+
+print $response->as_string, "\n";
+
+if ($response->is_success) {
+    print "ok 1\n";
+} else {
+    print "not ok 1\n";
+}
+
+
+# avoid -w warning
+$dummy = $net::httpserver;
+$dummy = $net::cgidir;
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/proxy.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/proxy.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/net/proxy.t	(revision 16571)
@@ -0,0 +1,36 @@
+#!/usr/local/bin/perl -w
+#
+# Test retrieving a file with a 'ftp://' URL,
+# via a HTTP proxy.
+#
+
+print "1..1\n";
+
+require "net/config.pl";
+unless (defined $net::ftp_proxy) {
+    print "not ok 1\n";
+    exit 0;
+}
+
+require LWP::Debug;
+require LWP::UserAgent;
+
+#LWP::Debug::level('+');
+
+my $ua = new LWP::UserAgent;    # create a useragent to test
+
+$ua->proxy('ftp', $net::ftp_proxy);
+
+my $url = new URI::URL('ftp://ftp.uninett.no/');
+
+my $request = new HTTP::Request('GET', $url);
+
+my $response = $ua->request($request, undef, undef);
+
+my $str = $response->as_string;
+
+if ($response->is_success) {
+    print "ok 1\n";
+} else {
+    print "not ok 1\n";
+}
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/robot/rules-dbm.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/robot/rules-dbm.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/robot/rules-dbm.t	(revision 16571)
@@ -0,0 +1,128 @@
+
+print "1..13\n";
+
+
+use WWW::RobotRules::AnyDBM_File;
+
+$file = "test-$$";
+
+$r = new WWW::RobotRules::AnyDBM_File "myrobot/2.0", $file;
+
+$r->parse("http://www.aas.no/robots.txt", "");
+
+$r->visit("www.aas.no");
+
+print "not " if $r->no_visits("www.aas.no") != 1;
+print "ok 1\n";
+
+
+$r->push_rules("www.sn.no", "/aas", "/per");
+$r->push_rules("www.sn.no", "/god", "/old");
+
+@r = $r->rules("www.sn.no");
+print "Rules: @r\n";
+
+print "not " if "@r" ne "/aas /per /god /old";
+print "ok 2\n";
+
+$r->clear_rules("per");
+$r->clear_rules("www.sn.no");
+
+@r = $r->rules("www.sn.no");
+print "Rules: @r\n";
+
+print "not " if "@r" ne "";
+print "ok 3\n";
+
+$r->visit("www.aas.no", time+10);
+$r->visit("www.sn.no");
+
+print "No visits: ", $r->no_visits("www.aas.no"), "\n";
+print "Last visit: ", $r->last_visit("www.aas.no"), "\n";
+print "Fresh until: ", $r->fresh_until("www.aas.no"), "\n";
+
+print "not " if $r->no_visits("www.aas.no") != 2;
+print "ok 4\n";
+
+print "not " if abs($r->last_visit("www.sn.no") - time) > 2;
+print "ok 5\n";
+
+$r = undef;
+
+# Try to reopen the database without a name specified
+$r = new WWW::RobotRules::AnyDBM_File undef, $file;
+$r->visit("www.aas.no");
+
+print "not " if $r->no_visits("www.aas.no") != 3;
+print "ok 6\n";
+
+print "Agent-Name: ", $r->agent, "\n";
+print "not " if $r->agent ne "myrobot";
+print "ok 7\n";
+
+$r = undef;
+
+print "*** Dump of database ***\n";
+tie(%cat, AnyDBM_File, $file, 0, 0644) or die "Can't tie: $!";
+while (($key,$val) = each(%cat)) {
+    print "$key\t$val\n";
+}
+print "******\n";
+
+untie %cat;
+
+# Try to open database with a different agent name
+$r = new WWW::RobotRules::AnyDBM_File "MOMSpider/2.0", $file;
+
+print "not " if $r->no_visits("www.sn.no");
+print "ok 8\n";
+
+# Try parsing
+$r->parse("http://www.sn.no:8080/robots.txt", <<EOT, (time + 3));
+
+User-Agent: *
+Disallow: /
+
+User-Agent: Momspider
+Disallow: /foo
+Disallow: /bar
+
+EOT
+
+@r = $r->rules("www.sn.no:8080");
+print "not " if "@r" ne "/foo /bar";
+print "ok 9\n";
+
+print "not " if $r->allowed("http://www.sn.no") >= 0;
+print "ok 10\n";
+
+print "not " if $r->allowed("http://www.sn.no:8080/foo/gisle");
+print "ok 11\n";
+
+sleep(5);  # wait until file has expired
+print "not " if $r->allowed("http://www.sn.no:8080/foo/gisle") >= 0;
+print "ok 12\n";
+
+
+$r = undef;
+
+print "*** Dump of database ***\n";
+tie(%cat, AnyDBM_File, $file, 0, 0644) or die "Can't tie: $!";
+while (($key,$val) = each(%cat)) {
+    print "$key\t$val\n";
+}
+print "******\n";
+
+untie %cat;			# Otherwise the next line fails on DOSish
+
+unlink "$file", "$file.pag", "$file.dir", "$file.db";
+
+# Try open a an emty database without specifying a name
+eval { 
+   $r = new WWW::RobotRules::AnyDBM_File undef, $file;
+};
+print $@;
+print "not " unless $@;  # should fail
+print "ok 13\n";
+
+unlink "$file", "$file.pag", "$file.dir", "$file.db";
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/robot/rules.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/robot/rules.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/robot/rules.t	(revision 16571)
@@ -0,0 +1,138 @@
+#!/local/bin/perl
+
+=head1 NAME
+
+robot-rules.t
+
+=head1 DESCRIPTION
+
+Test a number of different A</robots.txt> files against a number
+of different User-agents.
+
+=cut
+
+require WWW::RobotRules;
+use Carp;
+use strict;
+
+print "1..26\n"; # for Test::Harness
+
+# We test a number of different /robots.txt files,
+#
+
+my $content1 = <<EOM;
+# http://foo/robots.txt
+User-agent: *
+Disallow: /private
+Disallow: http://foo/also_private
+
+User-agent: MOMspider
+Disallow:
+EOM
+
+my $content2 = <<EOM;
+# http://foo/robots.txt
+User-agent: MOMspider
+ # comment which should be ignored
+Disallow: /private
+EOM
+
+my $content3 = <<EOM;
+# http://foo/robots.txt
+EOM
+
+my $content4 = <<EOM;
+# http://foo/robots.txt
+User-agent: *
+Disallow: /private
+
+User-agent: MOMspider
+Disallow: /this
+
+User-agent: Another
+Disallow: /that
+EOM
+
+# and a number of different robots:
+
+my @tests1 = (
+	   [$content1, 'MOMspider' =>
+	    1 => 'http://foo/private' => 1,
+	    2 => 'http://foo/also_private' => 1,
+	   ],
+
+	   [$content1, 'Wubble' =>
+	    3 => 'http://foo/private' => 0,
+	    4 => 'http://foo/also_private' => 0,
+	    5 => 'http://foo/other' => 1,
+	   ],
+
+	   [$content2, 'MOMspider' =>
+	    6 => 'http://foo/private' => 0,
+	    7 => 'http://foo/other' => 1,
+	   ],
+
+	   [$content2, 'Wubble' =>
+	    8  => 'http://foo/private' => 1,
+	    9  => 'http://foo/also_private' => 1,
+	    10 => 'http://foo/other' => 1,
+	   ],
+
+	   [$content3, 'MOMspider' =>
+	    11 => 'http://foo/private' => 1,
+	    12 => 'http://foo/other' => 1,
+	   ],
+
+	   [$content3, 'Wubble' =>
+	    13 => 'http://foo/private' => 1,
+	    14 => 'http://foo/other' => 1,
+	   ],
+
+	   [$content4, 'MOMspider' =>
+	    15 => 'http://foo/private' => 1,
+	    16 => 'http://foo/this' => 0,
+	    17 => 'http://foo/that' => 1,
+	   ],
+
+	   [$content4, 'Another' =>
+	    18 => 'http://foo/private' => 1,
+	    19 => 'http://foo/this' => 1,
+	    20 => 'http://foo/that' => 0,
+	   ],
+
+	   [$content4, 'Wubble' =>
+	    21 => 'http://foo/private' => 0,
+	    22 => 'http://foo/this' => 1,
+	    23 => 'http://foo/that' => 1,
+	   ],
+
+	   [$content4, 'Another/1.0' =>
+	    24 => 'http://foo/private' => 1,
+	    25 => 'http://foo/this' => 1,
+	    26 => 'http://foo/that' => 0,
+	   ],
+
+	   # when adding tests, remember to increase
+	   # the maximum at the top
+
+	  );
+
+my $t;
+
+for $t (@tests1) {
+    my ($content, $ua) = splice(@$t, 0, 2);
+
+    my $robotsrules = new WWW::RobotRules($ua);
+    $robotsrules->parse('http://foo/robots.txt', $content);
+
+    my ($num, $path, $expected);
+    while(($num, $path, $expected) = splice(@$t, 0, 3)) {
+	my $allowed = $robotsrules->allowed($path);
+	$allowed = 1 if $allowed;
+	if($allowed != $expected) {
+	    $robotsrules->dump;
+	    confess "Test Failed: $ua => $path ($allowed != $expected)";
+	}
+	print "ok $num\n";
+    }
+}
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/robot/ua.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/robot/ua.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/robot/ua.t	(revision 16571)
@@ -0,0 +1,135 @@
+$| = 1; # autoflush
+
+require IO::Socket;  # make sure this work before we try to make a HTTP::Daemon
+
+# First we make ourself a daemon in another process
+my $D = shift || '';
+if ($D eq 'daemon') {
+
+    require HTTP::Daemon;
+
+    my $d = new HTTP::Daemon Timeout => 10;
+
+    print "Please to meet you at: <URL:", $d->url, ">\n";
+    open(STDOUT, $^O eq 'MSWin32' ? ">nul" : ">/dev/null");
+
+    while ($c = $d->accept) {
+	$r = $c->get_request;
+	if ($r) {
+	    my $p = ($r->url->path_components)[1];
+	    $p =~ s/\W//g;
+	    my $func = lc("httpd_" . $r->method . "_$p");
+	    #print STDERR "Calling $func...\n";
+            if (defined &$func) {
+		&$func($c, $r);
+	    } else {
+		$c->send_error(404);
+	    }
+	}
+	$c = undef;  # close connection
+    }
+    print STDERR "HTTP Server terminated\n";
+    exit;
+}
+else {
+    use Config;
+    open(DAEMON , "$Config{'perlpath'} robot/ua.t daemon |") or die "Can't exec daemon: $!";
+}
+
+print "1..7\n";
+
+
+$greating = <DAEMON>;
+$greating =~ /(<[^>]+>)/;
+
+require URI::URL;
+URI::URL->import;
+my $base = new URI::URL $1;
+
+print "Will access HTTP server at $base\n";
+
+require LWP::RobotUA;
+require HTTP::Request;
+$ua = new LWP::RobotUA 'lwp-spider/0.1', 'gisle@aas.no';
+$ua->delay(0.05);  # rather quick robot
+
+#----------------------------------------------------------------
+sub httpd_get_robotstxt
+{
+   my($c,$r) = @_;
+   $c->send_basic_header;
+   $c->print("Content-Type: text/plain");
+   $c->send_crlf;
+   $c->send_crlf;
+   $c->print("User-Agent: *
+Disallow: /private
+
+");
+}
+
+sub httpd_get_someplace
+{
+   my($c,$r) = @_;
+   $c->send_basic_header;
+   $c->print("Content-Type: text/plain");
+   $c->send_crlf;
+   $c->send_crlf;
+   $c->print("Okidok\n");
+}
+
+$req = new HTTP::Request GET => url("/someplace", $base);
+$res = $ua->request($req);
+#print $res->as_string;
+print "not " unless $res->is_success;
+print "ok 1\n";
+
+$req = new HTTP::Request GET => url("/private/place", $base);
+$res = $ua->request($req);
+#print $res->as_string;
+print "not " unless $res->code == 403
+                and $res->message =~ /robots.txt/;
+print "ok 2\n";
+
+$req = new HTTP::Request GET => url("/foo", $base);
+$res = $ua->request($req);
+#print $res->as_string;
+print "not " unless $res->code == 404;  # not found
+print "ok 3\n";
+
+# Let the robotua generate "Service unavailable/Retry After response";
+$ua->delay(1);
+$ua->use_sleep(0);
+$req = new HTTP::Request GET => url("/foo", $base);
+$res = $ua->request($req);
+#print $res->as_string;
+print "not " unless $res->code == 503   # Unavailable
+                and $res->header("Retry-After");
+print "ok 4\n";
+
+#----------------------------------------------------------------
+print "Terminating server...\n";
+sub httpd_get_quit
+{
+    my($c) = @_;
+    $c->send_error(503, "Bye, bye");
+    exit;  # terminate HTTP server
+}
+
+$ua->delay(0);
+$req = new HTTP::Request GET => url("/quit", $base);
+$res = $ua->request($req);
+
+print "not " unless $res->code == 503 and $res->content =~ /Bye, bye/;
+print "ok 5\n";
+
+#---------------------------------------------------------------
+$ua->delay(1);
+
+# host_wait() should be around 60s now
+print "not " unless abs($ua->host_wait($base->netloc) - 60) < 5;
+print "ok 6\n";
+
+# Number of visits to this place should be 
+print "not " unless $ua->no_visits($base->netloc) == 4;
+print "ok 7\n";
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/abs-config.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/abs-config.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/abs-config.t	(revision 16571)
@@ -0,0 +1,35 @@
+print "1..6\n";
+
+use URI::URL qw(url);
+
+# Test configuration via some global variables.
+
+$URI::URL::ABS_REMOTE_LEADING_DOTS = 1;
+$URI::URL::ABS_ALLOW_RELATIVE_SCHEME = 1;
+
+$u1 = url("../../../../abc", "http://web/a/b");
+
+print "not " unless $u1->abs->as_string eq "http://web/abc";
+print "ok 1\n";
+
+{
+    local $URI::URL::ABS_REMOTE_LEADING_DOTS;
+    print "not " unless $u1->abs->as_string eq "http://web/../../../abc";
+    print "ok 2\n";
+}
+
+
+$u1 = url("http:../../../../abc", "http://web/a/b");
+print "not " unless $u1->abs->as_string eq "http://web/abc";
+print "ok 3\n";
+
+{
+   local $URI::URL::ABS_ALLOW_RELATIVE_SCHEME;
+   print "not " unless $u1->abs->as_string eq "http:../../../../abc";
+   print "ok 4\n";
+   print "not " unless $u1->abs(undef,1)->as_string eq "http://web/abc";
+   print "ok 5\n";
+}
+
+print "not " unless $u1->abs(undef,0)->as_string eq "http:../../../../abc";
+print "ok 6\n";
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/base.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/base.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/base.t	(revision 16571)
@@ -0,0 +1,955 @@
+#!/local/bin/perl -w
+
+use URI::URL qw(url);
+use URI::Escape qw(uri_escape uri_unescape);
+
+use Carp;
+
+# _expect()
+#
+# Handy low-level object method tester which we insert as a method
+# in the URI::URL class
+#
+sub URI::URL::_expect {
+    my($self, $method, $expect, @args) = @_;
+    my $result = $self->$method(@args);
+    $expect = 'UNDEF' unless defined $expect;
+    $result = 'UNDEF' unless defined $result;
+    return 1 if $expect eq $result;
+    warn "'$self'->$method(@args) = '$result' " .
+		"(expected '$expect')\n";
+    $self->print_on('STDERR');
+    confess "Test Failed";
+}
+
+package main;
+
+# Must ensure that there is no relative paths in @INC because we will
+# chdir in the newlocal tests.
+chomp($pwd = ($^O =~ /mswin32/i ? `cd` : `pwd`));
+for (@INC) {
+    next if m|^/| or $^O =~ /os2|mswin32/i and m|^\w:[\\/]|;
+    print "Turn lib path $_ into $pwd/$_\n";
+    $_ = "$pwd/$_";
+
+}
+
+$| = 1;
+
+print "1..8\n";  # for Test::Harness
+
+# Do basic tests first.
+# Dies if an error has been detected, prints "ok" otherwise.
+
+print "Self tests for URI::URL version $URI::URL::VERSION...\n";
+
+scheme_parse_test();
+print "ok 1\n";
+
+parts_test();
+print "ok 2\n";
+
+escape_test();
+print "ok 3\n";
+
+newlocal_test();
+print "ok 4\n";
+
+absolute_test();
+print "ok 5\n";
+
+eq_test();
+print "ok 6\n";
+
+# Let's test makeing our own things
+URI::URL::strict(0);
+# This should work after URI::URL::strict(0)
+$url = new URI::URL "x-myscheme:something";
+# Since no implementor is registered for 'x-myscheme' then it will
+# be handeled by the URI::URL::_generic class
+$url->_expect('as_string' => 'x-myscheme:something');
+$url->_expect('path' => 'something');
+URI::URL::strict(1);
+
+# Let's try to make our URL subclass
+{
+    package MyURL;
+    @ISA = URI::URL::implementor();
+
+    sub _parse {
+	my($self, $init) = @_;
+	$self->URI::URL::_generic::_parse($init, qw(netloc path));
+    }
+
+    sub foo {
+	my $self = shift;
+	print ref($self)."->foo called for $self\n";
+    }
+}
+# Let's say that it implements the 'x-a+b.c' scheme (alias 'x-foo')
+URI::URL::implementor('x-a+b.c', 'MyURL');
+URI::URL::implementor('x-foo', 'MyURL');
+
+# Now we are ready to try our new URL scheme
+$url = new URI::URL 'x-a+b.c://foo/bar;a?b';
+$url->_expect('as_string', 'x-a+b.c://foo/bar;a?b');
+$url->_expect('path', '/bar;a?b');
+$url->foo;
+$newurl = new URI::URL 'xxx', $url;
+$newurl->foo;
+$url = new URI::URL 'yyy', 'x-foo:';
+$url->foo;
+
+print "ok 7\n";
+
+# Test the new wash&go constructor
+print "not " if url("../foo.html", "http://www.sn.no/a/b")->abs->as_string
+		ne 'http://www.sn.no/foo.html';
+print "ok 8\n";
+
+print "URI::URL version $URI::URL::VERSION ok\n";
+
+exit 0;
+
+
+
+
+#####################################################################
+#
+# scheme_parse_test()
+#
+# test parsing and retrieval methods
+
+sub scheme_parse_test {
+
+    print "scheme_parse_test:\n";
+
+    $tests = {
+	'hTTp://web1.net/a/b/c/welcome#intro'
+	=> {    'scheme'=>'http', 'host'=>'web1.net', 'port'=>80,
+		'path'=>'/a/b/c/welcome', 'frag'=>'intro','query'=>undef,
+		'epath'=>'/a/b/c/welcome', 'equery'=>undef,
+		'params'=>undef, 'eparams'=>undef,
+		'as_string'=>'http://web1.net/a/b/c/welcome#intro',
+		'full_path' => '/a/b/c/welcome' },
+
+	'http://web:1/a?query+text'
+	=> {    'scheme'=>'http', 'host'=>'web', 'port'=>1,
+		'path'=>'/a', 'frag'=>undef, 'query'=>'query+text' },
+
+	'http://web.net/'
+	=> {    'scheme'=>'http', 'host'=>'web.net', 'port'=>80,
+		'path'=>'/', 'frag'=>undef, 'query'=>undef,
+		'full_path' => '/',
+		'as_string' => 'http://web.net/' },
+
+	'http://web.net'
+	=> {    'scheme'=>'http', 'host'=>'web.net', 'port'=>80,
+		'path'=>'/', 'frag'=>undef, 'query'=>undef,
+		'full_path' => '/',
+		'as_string' => 'http://web.net/' },
+
+	'http:0'
+	 => {   'scheme'=>'http', 'path'=>'0', 'query'=>undef,
+		'as_string'=>'http:0', 'full_path'=>'0', },
+
+	'http:/0?0'
+	 => {   'scheme'=>'http', 'path'=>'/0', 'query'=>'0',
+		'as_string'=>'http:/0?0', 'full_path'=>'/0?0', },
+
+	'http://0:0/0/0;0?0#0'
+	 => {   'scheme'=>'http', 'host'=>'0', 'port'=>'0',
+		'path' => '/0/0', 'query'=>'0', 'params'=>'0',
+		'netloc'=>'0:0',
+		'frag'=>0, 'as_string'=>'http://0:0/0/0;0?0#0' },
+
+	'ftp://0%3A:%40@h:0/0?0'
+	=>  {   'scheme'=>'ftp', 'user'=>'0:', 'password'=>'@',
+		'host'=>'h', 'port'=>'0', 'path'=>'/0?0',
+		'query'=>undef, params=>undef,
+		'netloc'=>'0%3A:%40@h:0',
+		'as_string'=>'ftp://0%3A:%40@h:0/0?0' },
+
+	'ftp://usr:pswd@web:1234/a/b;type=i'
+	=> {    'host'=>'web', 'port'=>1234, 'path'=>'/a/b',
+		'user'=>'usr', 'password'=>'pswd',
+		'params'=>'type=i',
+		'as_string'=>'ftp://usr:pswd@web:1234/a/b;type=i' },
+
+	'ftp://host/a/b'
+	=> {    'host'=>'host', 'port'=>21, 'path'=>'/a/b',
+		'user'=>'anonymous',
+		'as_string'=>'ftp://host/a/b' },
+
+	'file://host/fseg/fs?g/fseg'
+	# don't escape ? for file: scheme
+	=> {    'host'=>'host', 'path'=>'/fseg/fs?g/fseg',
+		'as_string'=>'file://host/fseg/fs?g/fseg' },
+
+	'gopher://host'
+	=> {     'gtype'=>'1', 'as_string' => 'gopher://host/', },
+
+	'gopher://host/'
+	=> {     'gtype'=>'1', 'as_string' => 'gopher://host/', },
+
+	'gopher://gopher/2a_selector'
+	=> {    'gtype'=>'2', 'selector'=>'a_selector',
+		'as_string' => 'gopher://gopher/2a_selector', },
+
+	'mailto:libwww-perl@ics.uci.edu'
+	=> {    'address'       => 'libwww-perl@ics.uci.edu',
+		'encoded822addr'=> 'libwww-perl@ics.uci.edu',
+		'user'          => 'libwww-perl',
+		'host'          => 'ics.uci.edu',
+		'as_string'     => 'mailto:libwww-perl@ics.uci.edu', },
+
+	'news:*'
+	=> {    'groupart'=>'*', 'group'=>'*', as_string=>'news:*' },
+	'news:comp.lang.perl'
+	=> {    'group'=>'comp.lang.perl' },
+	'news:perl-faq/module-list-1-794455075@ig.co.uk'
+	=> {    'article'=>
+		    'perl-faq/module-list-1-794455075@ig.co.uk' },
+
+	'nntp://news.com/comp.lang.perl/42'
+	=> {    'group'=>'comp.lang.perl', 'digits'=>42 },
+
+	'telnet://usr:pswd@web:12345/'
+	=> {    'user'=>'usr', 'password'=>'pswd', 'host'=>'web' },
+	'rlogin://aas@a.sn.no'
+	=> {    'user'=>'aas', 'host'=>'a.sn.no' },
+	'tn3270://aas@ibm'
+	=> {    'user'=>'aas', 'host'=>'ibm',
+		'as_string'=>'tn3270://aas@ibm/'},
+
+	'wais://web.net/db'
+	=> { 'database'=>'db' },
+	'wais://web.net/db?query'
+	=> { 'database'=>'db', 'query'=>'query' },
+	'wais://usr:pswd@web.net/db/wt/wp'
+	=> {    'database'=>'db', 'wtype'=>'wt', 'wpath'=>'wp',
+		'password'=>'pswd' },
+    };
+
+    foreach $url_str (sort keys %$tests ){
+	print "Testing '$url_str'\n";
+	my $url = new URI::URL $url_str;
+	my $tests = $tests->{$url_str};
+	while( ($method, $exp) = each %$tests ){
+	    $exp = 'UNDEF' unless defined $exp;
+	    $url->_expect($method, $exp);
+	}
+    }
+}
+
+
+#####################################################################
+#
+# parts_test()          (calls netloc_test test)
+#
+# Test individual component part access functions
+#
+sub parts_test {
+    print "parts_test:\n";
+
+    # test storage part access/edit methods (netloc, user, password,
+    # host and port are tested by &netloc_test)
+
+    $url = new URI::URL 'file://web/orig/path';
+    $url->scheme('http');
+    $url->path('1info');
+    $url->query('key words');
+    $url->frag('this');
+    $url->_expect('as_string' => 'http://web/1info?key%20words#this');
+
+    $url->epath('%2f/%2f');
+    $url->equery('a=%26');
+    $url->_expect('full_path' => '/%2f/%2f?a=%26');
+
+    # At this point it should be impossible to access the members path()
+    # and query() without complaints.
+    eval { my $p = $url->path; print "Path is $p\n"; };
+    die "Path exception failed" unless $@;
+    eval { my $p = $url->query; print "Query is $p\n"; };
+    die "Query exception failed" unless $@;
+
+    # but we should still be able to set it 
+    $url->path("howdy");
+    $url->_expect('as_string' => 'http://web/howdy?a=%26#this');
+
+    # Test the path_components function
+    $url = new URI::URL 'file:%2f/%2f';
+    my $p;
+    $p = join('-', $url->path_components);
+    die "\$url->path_components returns '$p', expected '/-/'"
+      unless $p eq "/-/";
+    $url->host("localhost");
+    $p = join('-', $url->path_components);
+    die "\$url->path_components returns '$p', expected '-/-/'"
+      unless $p eq "-/-/";
+    $url->epath("/foo/bar/");
+    $p = join('-', $url->path_components);
+    die "\$url->path_components returns '$p', expected '-foo-bar-'"
+      unless $p eq "-foo-bar-";
+    $url->path_components("", "/etc", "\0", "..", "øse", "");
+    $url->_expect('full_path' => '/%2Fetc/%00/../%F8se/');
+
+    # Setting undef
+    $url = new URI::URL 'http://web/p;p?q#f';
+    $url->epath(undef);
+    $url->equery(undef);
+    $url->eparams(undef);
+    $url->frag(undef);
+    $url->_expect('as_string' => 'http://web/');
+
+    # Test http query access methods
+    $url->keywords('dog');
+    $url->_expect('as_string' => 'http://web/?dog');
+    $url->keywords(qw(dog bones));
+    $url->_expect('as_string' => 'http://web/?dog+bones');
+    $url->keywords(0,0);
+    $url->_expect('as_string' => 'http://web/?0+0');
+    $url->keywords('dog', 'bones', '#+=');
+    $url->_expect('as_string' => 'http://web/?dog+bones+%23%2B%3D');
+    $a = join(":", $url->keywords);
+    die "\$url->keywords did not work (returned '$a')" unless $a eq 'dog:bones:#+=';
+    # calling query_form is an error
+    eval { my $foo = $url->query_form; };
+    die "\$url->query_form should croak since query contains keywords not a form."
+      unless $@;
+
+    $url->query_form(a => 'foo', b => 'bar');
+    $url->_expect('as_string' => 'http://web/?a=foo&b=bar');
+    my %a = $url->query_form;
+    die "\$url->query_form did not work"
+      unless $a{a} eq 'foo' && $a{b} eq 'bar';
+
+    $url->query_form(a => undef, a => 'foo', '&=' => '&=+');
+    $url->_expect('as_string' => 'http://web/?a=&a=foo&%26%3D=%26%3D%2B');
+
+    my @a = $url->query_form;
+    die "Wrong length" unless @a == 6;
+    die "Bad keys from query_form"
+      unless $a[0] eq 'a' && $a[2] eq 'a' && $a[4] eq '&=';
+    die "Bad values from query_form"
+      unless $a[1] eq '' && $a[3] eq 'foo' && $a[5] eq '&=+';
+
+    # calling keywords is an error
+    eval { my $foo = $url->keywords; };
+    die "\$url->keywords should croak when query is a form"
+      unless $@;
+    # Try this odd one
+    $url->equery('&=&=b&a=&a&a=b=c&&a=b');
+    @a = $url->query_form;
+    #print join(":", @a), "\n";
+    die "Wrong length" unless @a == 16;
+    die "Wrong sequence" unless $a[4]  eq ""  && $a[5]  eq "b" &&
+                                $a[10] eq "a" && $a[11] eq "b=c";
+
+    # Try array ref values in the key value pairs
+    $url->query_form(a => ['foo', 'bar'], b => 'foo', c => ['bar', 'foo']);
+    $url->_expect('as_string', 'http://web/?a=foo&a=bar&b=foo&c=bar&c=foo');
+
+
+    netloc_test();
+    port_test();
+
+    $url->query(undef);
+    $url->_expect('query', undef);
+
+    $url = new URI::URL 'gopher://gopher/';
+    $url->port(33);
+    $url->gtype("3");
+    $url->selector("S");
+    $url->search("query");
+    $url->_expect('as_string', 'gopher://gopher:33/3S%09query');
+
+    $url->epath("45%09a");
+    $url->_expect('gtype' => '4');
+    $url->_expect('selector' => '5');
+    $url->_expect('search' => 'a');
+    $url->_expect('string' => undef);
+    $url->_expect('path' => "/45\ta");
+    $url->path("00\t%09gisle");
+    $url->_expect('search', '%09gisle');
+
+    # Let's test som other URL schemes
+    $url = new URI::URL 'news:';
+    $url->group("comp.lang.perl.misc");
+    $url->_expect('as_string' => 'news:comp.lang.perl.misc');
+    $url->article('<1234@a.sn.no>');
+    $url->_expect('as_string' => 'news:1234@a.sn.no'); # "<" and ">" are gone
+    # This one should be illegal
+    eval { $url->article("no.perl"); };
+    die "This one should really complain" unless $@;
+
+    $url = new URI::URL 'mailto:';
+    $url->user("aas");
+    $url->host("a.sn.no");
+    $url->_expect("as_string" => 'mailto:aas@a.sn.no');
+    $url->address('foo@bar');
+    $url->_expect("host" => 'bar');
+    $url->_expect("user" => 'foo');
+
+    $url = new URI::URL 'wais://host/database/wt/wpath';
+    $url->database('foo');
+    $url->_expect('as_string' => 'wais://host/foo/wt/wpath');
+    $url->wtype('bar');
+    $url->_expect('as_string' => 'wais://host/foo/bar/wpath');
+
+    # Test crack method for various URLs
+    my(@crack, $crack);
+    @crack = URI::URL->new("http://host/path;param?query#frag")->crack;
+    die "Cracked result should be 9 elements" unless @crack == 9;
+    $crack = join("*", map { defined($_) ? $_ : "UNDEF" } @crack);
+    print "Cracked result: $crack\n";
+    die "Bad crack result" unless
+      $crack eq "http*UNDEF*UNDEF*host*80*/path*param*query*frag";
+
+    @crack = URI::URL->new("foo/bar", "ftp://aas\@ftp.sn.no/")->crack;
+    die "Cracked result should be 9 elements" unless @crack == 9;
+    $crack = join("*", map { defined($_) ? $_ : "UNDEF" } @crack);
+    print "Cracked result: $crack\n";
+    die "Bad crack result" unless
+      $crack eq "ftp*UNDEF*UNDEF*UNDEF*21*foo/bar*UNDEF*UNDEF*UNDEF";
+
+    @crack = URI::URL->new('ftp://u:p@host/q?path')->crack;
+    die "Cracked result should be 9 elements" unless @crack == 9;
+    $crack = join("*", map { defined($_) ? $_ : "UNDEF" } @crack);
+    print "Cracked result: $crack\n";
+    die "Bad crack result" unless
+      $crack eq "ftp*u*p*host*21*/q?path*UNDEF*UNDEF*UNDEF";
+
+    @crack = URI::URL->new("ftp://ftp.sn.no/pub")->crack;    # Test anon ftp
+    die "Cracked result should be 9 elements" unless @crack == 9;
+    die "No passwd in anonymous crack" unless $crack[2];
+    $crack[2] = 'passwd';  # easier to test when we know what it is
+    $crack = join("*", map { defined($_) ? $_ : "UNDEF" } @crack);
+    print "Cracked result: $crack\n";
+    die "Bad crack result" unless
+      $crack eq "ftp*anonymous*passwd*ftp.sn.no*21*/pub*UNDEF*UNDEF*UNDEF";
+
+    @crack = URI::URL->new('mailto:aas@sn.no')->crack;
+    die "Cracked result should be 9 elements" unless @crack == 9;
+    $crack = join("*", map { defined($_) ? $_ : "UNDEF" } @crack);
+    print "Cracked result: $crack\n";
+    die "Bad crack result" unless
+      $crack eq "mailto*aas*UNDEF*sn.no*UNDEF*aas\@sn.no*UNDEF*UNDEF*UNDEF";
+
+    @crack = URI::URL->new('news:comp.lang.perl.misc')->crack;
+    die "Cracked result should be 9 elements" unless @crack == 9;
+    $crack = join("*", map { defined($_) ? $_ : "UNDEF" } @crack);
+    print "Cracked result: $crack\n";
+    die "Bad crack result" unless
+      $crack eq "news*UNDEF*UNDEF*UNDEF*UNDEF*comp.lang.perl.misc*UNDEF*UNDEF*UNDEF";
+}
+
+#
+# netloc_test()
+#
+# Test automatic netloc synchronisation
+#
+sub netloc_test {
+    print "netloc_test:\n";
+
+    my $url = new URI::URL 'ftp://anonymous:p%61ss@håst:12345';
+    $url->_expect('user', 'anonymous');
+    $url->_expect('password', 'pass');
+    $url->_expect('host', 'håst');
+    $url->_expect('port', 12345);
+    # Can't really know how netloc is represented since it is partially escaped
+    #$url->_expect('netloc', 'anonymous:pass@hst:12345');
+    $url->_expect('as_string' => 'ftp://anonymous:p%61ss@h%E5st:12345/');
+
+    # The '0' is sometimes tricky to get right
+    $url->user(0);
+    $url->password(0);
+    $url->host(0);
+    $url->port(0);
+    $url->_expect('netloc' => '0:0@0:0');
+    $url->host(undef);
+    $url->_expect('netloc' => '');
+    $url->host('h');
+    $url->user(undef);
+    $url->_expect('netloc' => 'h:0');
+    $url->user('');
+    $url->_expect('netloc' => ':0@h:0');
+    $url->password('');
+    $url->_expect('netloc' => ':@h:0');
+    $url->user('foo');
+    $url->_expect('netloc' => 'foo:@h:0');
+
+    # Let's try a simple one
+    $url->user('nemo');
+    $url->password('p2');
+    $url->host('hst2');
+    $url->port(2);
+    $url->_expect('netloc' => 'nemo:p2@hst2:2');
+
+    $url->user(undef);
+    $url->password(undef);
+    $url->port(undef);
+    $url->_expect('netloc' => 'hst2');
+    $url->_expect('port' => '21');  # the default ftp port
+
+    $url->port(21);
+    $url->_expect('netloc' => 'hst2');
+
+    # Let's try some reserved chars
+    $url->user("@");
+    $url->password(":-#-;-/-?");
+    $url->_expect('as_string' => 'ftp://%40:%3A-%23-%3B-%2F-%3F@hst2/');
+
+}
+
+#
+# port_test()
+#
+# Test port behaviour
+#
+sub port_test {
+    print "port_test:\n";
+
+    $url = URI::URL->new('http://foo/root/dir/');
+    my $port = $url->port;
+    die "Port undefined" unless defined $port;
+    die "Wrong port $port" unless $port == 80;
+    die "Wrong string" unless $url->as_string eq
+	'http://foo/root/dir/';
+
+    $url->port(8001);
+    $port = $url->port;
+    die "Port undefined" unless defined $port;
+    die "Wrong port $port" unless $port == 8001;
+    die "Wrong string" unless $url->as_string eq
+	'http://foo:8001/root/dir/';
+
+    $url->port(80);
+    $port = $url->port;
+    die "Port undefined" unless defined $port;
+    die "Wrong port $port" unless $port == 80;
+    die "Wrong string" unless $url->as_string eq
+	'http://foo/root/dir/';
+
+    $url->port(8001);
+    $url->port(undef);
+    $port = $url->port;
+    die "Port undefined" unless defined $port;
+    die "Wrong port $port" unless $port == 80;
+    die "Wrong string" unless $url->as_string eq
+	'http://foo/root/dir/';
+}
+
+
+#####################################################################
+#
+# escape_test()
+#
+# escaping functions
+
+sub escape_test {
+    print "escape_test:\n";
+
+    # supply escaped URL
+    $url = new URI::URL 'http://web/this%20has%20spaces';
+    # check component is unescaped
+    $url->_expect('path', '/this has spaces');
+
+    # modify the unescaped form
+    $url->path('this ALSO has spaces');
+    # check whole url is escaped
+    $url->_expect('as_string',
+		  'http://web/this%20ALSO%20has%20spaces');
+
+    $url = new URI::URL uri_escape('http://web/try %?#" those');
+    $url->_expect('as_string',
+		  'http://web/try%20%25%3F%23%22%20those');
+
+    my $all = pack('c*',0..255);
+    my $esc = uri_escape($all);
+    my $new = uri_unescape($esc);
+    die "uri_escape->uri_unescape mismatch" unless $all eq $new;
+    $url->path($all);
+    $url->_expect('full_path' => '/%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22%23$%25%26\'()*%2B,-./0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF');
+
+    # test escaping uses uppercase (preferred by rfc1837)
+    $url = new URI::URL 'file://h/';
+    $url->path(chr(0x7F));
+    $url->_expect('as_string', 'file://h/%7F');
+
+    # reserved characters differ per scheme
+
+    ## XXX is this '?' allowed to be unescaped
+    $url = new URI::URL 'file://h/test?ing';
+    $url->_expect('path', '/test?ing');
+
+    $url = new URI::URL 'file://h/';
+    $url->epath('question?mark');
+    $url->_expect('as_string', 'file://h/question?mark');
+    # XXX Why should this be any different???
+    #     Perhaps we should not expect too much :-)
+    $url->path('question?mark');
+    $url->_expect('as_string', 'file://h/question%3Fmark');
+
+    # See what happens when set different elements to this ugly sting
+    my $reserved = ';/?:@&=#%';
+    $url->path($reserved . "foo");
+    $url->_expect('as_string', 'file://h/%3B/%3F%3A%40%26%3D%23%25foo');
+
+    $url->scheme('http');
+    $url->path('');
+    $url->_expect('as_string', 'http://h/');
+    $url->query($reserved);
+    $url->params($reserved);
+    $url->frag($reserved);
+    $url->_expect('as_string', 'http://h/;%3B%2F%3F%3A%40&=%23%25?%3B%2F%3F%3A%40&=%23%25#;/?:@&=#%');
+
+    $str = $url->as_string;
+    $url = new URI::URL $str;
+    die "URL changed" if $str ne $url->as_string;
+
+    $url = new URI::URL 'ftp:foo';
+    $url->user($reserved);
+    $url->host($reserved);
+    $url->_expect('as_string', 'ftp://%3B%2F%3F%3A%40%26%3D%23%25@%3B%2F%3F%3A%40%26%3D%23%25/foo');
+
+}
+
+
+#####################################################################
+#
+# newlocal_test()
+#
+
+sub newlocal_test {
+    print "newlocal_test:\n";
+    my $pwd = ($^O eq 'MSWin32' ? 'cd' : (-e '/bin/pwd' ? '/bin/pwd' : 'pwd'));
+    my $tmpdir = ($^O eq 'MSWin32' ? $ENV{TEMP} : '/tmp');
+    $tmpdir =~ tr|\\|/|;
+
+    my $savedir = `$pwd`;     # we don't use Cwd.pm because we want to check
+			      # that it get require'd corretly by URL.pm
+    chomp $savedir;
+
+    # cwd
+    chdir($tmpdir) or die $!;
+    my $dir = `$pwd`; $dir =~ tr|\\|/|;
+    chomp $dir; $dir = uri_escape($dir, ':');
+    $url = newlocal URI::URL;
+    $url->_expect('as_string', URI::URL->new("file:$dir/")->as_string);
+
+    print "Local directory is ". $url->local_path . "\n";
+
+    # absolute dir
+    chdir('/') or die $!;
+    $url = newlocal URI::URL '/usr/';
+    $url->_expect('as_string', 'file:/usr/');
+
+    # absolute file
+    $url = newlocal URI::URL '/vmunix';
+    $url->_expect('as_string', 'file:/vmunix');
+
+    # relative file
+    chdir($tmpdir) or die $!;
+    $dir = `$pwd`; $dir =~ tr|\\|/|;
+    chomp $dir; $dir = uri_escape($dir, ':');
+    $url = newlocal URI::URL 'foo';
+    $url->_expect('as_string', "file:$dir/foo");
+
+    # relative dir
+    chdir($tmpdir) or die $!;
+    $dir = `$pwd`; $dir =~ tr|\\|/|;
+    chomp $dir; $dir = uri_escape($dir, ':');
+    $url = newlocal URI::URL 'bar/';
+    $url->_expect('as_string', "file:$dir/bar/");
+
+    # 0
+    chdir('/') or die $!;
+    $dir = `$pwd`; $dir =~ tr|\\|/|;
+    chomp $dir; $dir = uri_escape($dir, ':');
+    $url = newlocal URI::URL '0';
+    $url->_expect('as_string', "file:${dir}0");
+
+    # Test access methods for file URLs
+    $url = new URI::URL 'file:/c:/dos';
+    $url->_expect('dos_path', 'C:\\DOS');
+    $url->_expect('unix_path', '/c:/dos');
+    $url->_expect('vms_path', '[C:]DOS');
+    eval { $url->mac_path; };  # This is not allowed since we have ':' in path
+    die "Mac_path generated when it should fail." unless $@;
+    $url = new URI::URL 'file:/foo/bar';
+    $url->_expect('unix_path', '/foo/bar');
+    $url->_expect('mac_path', 'foo:bar');
+
+    # Some edge cases
+    $url = new URI::URL 'file:';
+    $url->_expect('unix_path', '/');
+    $url = new URI::URL 'file:/';
+    $url->_expect('unix_path', '/');
+    $url = new URI::URL 'file:.';
+    $url->_expect('unix_path', '.');
+    $url = new URI::URL 'file:./foo';
+    $url->_expect('unix_path', 'foo');
+    $url = new URI::URL 'file:0';
+    $url->_expect('unix_path', '0');
+    $url = new URI::URL 'file:../../foo';
+    $url->_expect('unix_path', '../../foo');
+    $url = new URI::URL 'file:foo/../bar';
+    $url->_expect('unix_path', 'bar');
+
+    # Relative files
+    $url = new URI::URL 'file:foo/b%61r/Note.txt';
+    $url->_expect('unix_path', 'foo/bar/Note.txt');
+    $url->_expect('mac_path', ':foo:bar:Note.txt');
+    $url->_expect('dos_path', 'FOO\\BAR\\NOTE.TXT');
+    $url->_expect('vms_path', '[.FOO.BAR]NOTE.TXT');
+
+    # The VMS path found in RFC 1738 (section 3.10)
+    $url = new URI::URL 'file://vms.host.edu/disk$user/my/notes/note12345.txt';
+    $url->_expect('vms_path', 'DISK$USER:[MY.NOTES]NOTE12345.TXT');
+    $url->_expect('mac_path', 'disk$user:my:notes:note12345.txt');
+
+    chdir($savedir) or die $!;
+}
+
+
+#####################################################################
+#
+# absolute_test()
+#
+sub absolute_test {
+
+    print "Test relative/absolute URI::URL parsing:\n";
+
+    # Tests from draft-ietf-uri-relative-url-06.txt
+    # Copied verbatim from the draft, parsed below
+
+    @URI::URL::g::ISA = qw(URI::URL::_generic); # for these tests
+
+    my $base = 'http://a/b/c/d;p?q#f';
+
+    $absolute_tests = <<EOM;
+5.1.  Normal Examples
+
+      g:h        = <URL:g:h>
+      g          = <URL:http://a/b/c/g>
+      ./g        = <URL:http://a/b/c/g>
+      g/         = <URL:http://a/b/c/g/>
+      /g         = <URL:http://a/g>
+      //g        = <URL:http://g>
+      ?y         = <URL:http://a/b/c/d;p?y>
+      g?y        = <URL:http://a/b/c/g?y>
+      g?y/./x    = <URL:http://a/b/c/g?y/./x>
+      #s         = <URL:http://a/b/c/d;p?q#s>
+      g#s        = <URL:http://a/b/c/g#s>
+      g#s/./x    = <URL:http://a/b/c/g#s/./x>
+      g?y#s      = <URL:http://a/b/c/g?y#s>
+      ;x         = <URL:http://a/b/c/d;x>
+      g;x        = <URL:http://a/b/c/g;x>
+      g;x?y#s    = <URL:http://a/b/c/g;x?y#s>
+      .          = <URL:http://a/b/c/>
+      ./         = <URL:http://a/b/c/>
+      ..         = <URL:http://a/b/>
+      ../        = <URL:http://a/b/>
+      ../g       = <URL:http://a/b/g>
+      ../..      = <URL:http://a/>
+      ../../     = <URL:http://a/>
+      ../../g    = <URL:http://a/g>
+
+5.2.  Abnormal Examples
+
+   Although the following abnormal examples are unlikely to occur
+   in normal practice, all URL parsers should be capable of resolving
+   them consistently.  Each example uses the same base as above.
+
+   An empty reference resolves to the complete base URL:
+
+      <>         = <URL:http://a/b/c/d;p?q#f>
+
+   Parsers must be careful in handling the case where there are more
+   relative path ".." segments than there are hierarchical levels in
+   the base URL's path.  Note that the ".." syntax cannot be used to
+   change the <net_loc> of a URL.
+
+     ../../../g = <URL:http://a/../g>
+     ../../../../g = <URL:http://a/../../g>
+
+   Similarly, parsers must avoid treating "." and ".." as special
+   when they are not complete components of a relative path.
+
+      /./g       = <URL:http://a/./g>
+      /../g      = <URL:http://a/../g>
+      g.         = <URL:http://a/b/c/g.>
+      .g         = <URL:http://a/b/c/.g>
+      g..        = <URL:http://a/b/c/g..>
+      ..g        = <URL:http://a/b/c/..g>
+
+   Less likely are cases where the relative URL uses unnecessary or
+   nonsensical forms of the "." and ".." complete path segments.
+
+      ./../g     = <URL:http://a/b/g>
+      ./g/.      = <URL:http://a/b/c/g/>
+      g/./h      = <URL:http://a/b/c/g/h>
+      g/../h     = <URL:http://a/b/c/h>
+
+   Finally, some older parsers allow the scheme name to be present in
+   a relative URL if it is the same as the base URL scheme.  This is
+   considered to be a loophole in prior specifications of partial
+   URLs [1] and should be avoided by future parsers.
+
+      http:g     = <URL:http:g>
+      http:      = <URL:http:>
+EOM
+    # convert text to list like
+    # @absolute_tests = ( ['g:h' => 'g:h'], ...)
+
+    for $line (split("\n", $absolute_tests)) {
+	next unless $line =~ /^\s{6}/;
+	if ($line =~ /^\s+(\S+)\s*=\s*<URL:([^>]*)>/) {
+	    my($rel, $abs) = ($1, $2);
+	    $rel = '' if $rel eq '<>';
+	    push(@absolute_tests, [$rel, $abs]);
+	}
+	else {
+	    warn "illegal line '$line'";
+	}
+    }
+
+    # add some extra ones for good measure
+
+    push(@absolute_tests, ['x/y//../z' => 'http://a/b/c/x/y/z'],
+			  ['1'         => 'http://a/b/c/1'    ],
+			  ['0'         => 'http://a/b/c/0'    ],
+			  ['/0'        => 'http://a/0'        ],
+			  ['%2e/a'     => 'http://a/b/c/%2e/a'],  # %2e is '.'
+			  ['%2e%2e/a'  => 'http://a/b/c/%2e%2e/a'],
+	);
+
+    print "  Relative    +  Base  =>  Expected Absolute URL\n";
+    print "================================================\n";
+    for $test (@absolute_tests) {
+	my($rel, $abs) = @$test;
+	my $abs_url = new URI::URL $abs;
+	my $abs_str = $abs_url->as_string;
+
+	printf("  %-10s  +  $base  =>  %s\n", $rel, $abs);
+	my $u   = new URI::URL $rel, $base;
+	my $got = $u->abs;
+	$got->_expect('as_string', $abs_str);
+    }
+
+    # bug found and fixed in 1.9 by "J.E. Fritz" <FRITZ@gems.vcu.edu>
+    $base = new URI::URL 'http://host/directory/file';
+    my $relative = new URI::URL 'file', $base;
+    my $result = $relative->abs;
+
+    my ($a, $b) = ($base->path, $result->path);
+	die "'$a' and '$b' should be the same" unless $a eq $b;
+
+    # Counter the expectation of least surprise,
+    # section 6 of the draft says the URL should
+    # be canonicalised, rather than making a simple
+    # substitution of the last component.
+    # Better doublecheck someone hasn't "fixed this bug" :-)
+    $base = new URI::URL 'http://host/dir1/../dir2/file';
+    $relative = new URI::URL 'file', $base;
+    $result = $relative->abs;
+    die 'URL not canonicalised' unless $result eq 'http://host/dir2/file';
+
+    print "--------\n";
+    # Test various other kinds of URLs and how they like to be absolutized
+    for (["http://abc/", "news:45664545", "http://abc/"],
+	 ["news:abc",    "http://abc/",   "news:abc"],
+	 ["abc",         "file:/test?aas", "file:/abc"],
+	 ["gopher:",     "",               "gopher:"],
+	 ["?foo",        "http://abc/a",   "http://abc/a?foo"],
+	 ["?foo",        "file:/abc",      "file:/?foo"],
+	 ["#foo",        "http://abc/a",   "http://abc/a#foo"],
+	 ["#foo",        "file:a",         "file:a#foo"],
+	 ["#foo",        "file:/a",         "file:/a#foo"],
+	 ["#foo",        "file:/a",         "file:/a#foo"],
+	 ["#foo",        "file://localhost/a", "file://localhost/a#foo"],
+	 ['123@sn.no',   "news:comp.lang.perl.misc", 'news:123@sn.no'],
+	 ['no.perl',     'news:123@sn.no',           'news:no.perl'],
+	 ['mailto:aas@a.sn.no', "http://www.sn.no/", 'mailto:aas@a.sn.no'],
+
+	 # Test absolutizing with old behaviour.
+	 ['http:foo',     'http://h/a/b',   'http://h/a/foo'],
+	 ['http:/foo',    'http://h/a/b',   'http://h/foo'],
+	 ['http:?foo',    'http://h/a/b',   'http://h/a/b?foo'],
+	 ['http:#foo',    'http://h/a/b',   'http://h/a/b#foo'],
+	 ['http:?foo#bar','http://h/a/b',   'http://h/a/b?foo#bar'],
+	 ['file:/foo',    'http://h/a/b',   'file:/foo'],
+
+	)
+    {
+	my($url, $base, $expected_abs) = @$_;
+	my $rel = new URI::URL $url, $base;
+	my $abs = $rel->abs($base, 1);
+	printf("  %-12s+  $base  =>  %s\n", $rel, $abs);
+	$abs->_expect('as_string', $expected_abs);
+    }
+    print "absolute test ok\n";
+
+    # Test relative function
+    for (
+	 ["http://abc/a",   "http://abc",        "a"],
+	 ["http://abc/a",   "http://abc/b",      "a"],
+	 ["http://abc/a?q", "http://abc/b",      "a?q"],
+	 ["http://abc/a;p", "http://abc/b",      "a;p"],
+	 ["http://abc/a",   "http://abc/a/b/c/", "../../../a"],
+         ["http://abc/a/",  "http://abc/a/",     "./"],
+         ["http://abc/a#f", "http://abc/a",      "#f"],
+
+	 ["file:/etc/motd", "file:/",            "etc/motd"],
+	 ["file:/etc/motd", "file:/etc/passwd",  "motd"],
+	 ["file:/etc/motd", "file:/etc/rc2.d/",  "../motd"],
+	 ["file:/etc/motd", "file:/usr/lib/doc", "../../etc/motd"],
+         ["file:",          "file:/etc/",        "../"],
+         ["file:foo",       "file:/etc/",        "../foo"],
+
+	 ["mailto:aas",     "http://abc",        "mailto:aas"],
+
+	 # Nicolai Langfeldt's original example
+	 ["http://www.math.uio.no/doc/mail/top.html",
+	  "http://www.math.uio.no/doc/linux/", "../mail/top.html"],
+        )
+    {
+	my($abs, $base, $expect) = @$_;
+	printf "url('$abs', '$base')->rel eq '$expect'\n";
+	my $rel = URI::URL->new($abs, $base)->rel;
+	$rel->_expect('as_string', $expect);
+    }
+    print "relative test ok\n";
+}
+
+
+sub eq_test
+{
+    my $u1 = new URI::URL 'http://abc.com:80/~smith/home.html';
+    my $u2 = new URI::URL 'http://ABC.com/%7Esmith/home.html';
+    my $u3 = new URI::URL 'http://ABC.com:/%7esmith/home.html';
+
+    # Test all permutations of these tree
+    $u1->eq($u2) or die "1: $u1 ne $u2";
+    $u1->eq($u3) or die "2: $u1 ne $u3";
+    $u2->eq($u1) or die "3: $u2 ne $u1";
+    $u2->eq($u3) or die "4: $u2 ne $u3";
+    $u3->eq($u1) or die "5: $u3 ne $u1";
+    $u3->eq($u2) or die "6: $u3 ne $u2";
+
+    # Test empty path
+    my $u4 = new URI::URL 'http://www.sn.no';
+    $u4->eq("HTTP://WWW.SN.NO:80/") or die "7: $u4";
+    $u4->eq("http://www.sn.no:81") and die "8: $u4";
+
+    # Test mailto
+    my $u5 = new URI::URL 'mailto:AAS@SN.no';
+    $u5->eq('mailto:aas@sn.no') or die "9: $u5";
+
+    # Test reserved char
+    my $u6 = new URI::URL 'ftp://ftp/%2Fetc';
+    $u6->eq("ftp://ftp/%2fetc") or die "10: $u6";
+    $u6->eq("ftp://ftp://etc") and die "11: $u6";
+}
+
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/heuristic.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/heuristic.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/heuristic.t	(revision 16571)
@@ -0,0 +1,61 @@
+print "1..14\n";
+
+use URI::Heuristic qw(uf_urlstr uf_url);
+$URI::Heuristic::DEBUG++;
+open(STDERR, ">&STDOUT");  # redirect STDERR
+
+print "not " unless uf_urlstr("http://www.sn.no/") eq "http://www.sn.no/";
+print "ok 1\n";
+
+print "not " unless uf_urlstr("/etc/passwd") eq "file:/etc/passwd";
+print "ok 2\n";
+
+print "not " unless uf_urlstr("./foo.txt") eq "file:./foo.txt";
+print "ok 3\n";
+
+print "not " unless uf_urlstr("ftp.aas.no/lwp.tar.gz") eq "ftp://ftp.aas.no/lwp.tar.gz";
+print "ok 4\n";
+
+print "not " unless uf_urlstr("C:\\CONFIG.SYS") eq "file:C:\\CONFIG.SYS";
+print "ok 5\n";
+
+if (gethostbyname("www.netscape.com")) {
+    # DNS probably work, lets run test 6..8
+
+    $URI::Heuristic::MY_COUNTRY = "no";
+    print "not " unless uf_urlstr("perl/camel.gif") eq "http://www.perl.com/camel.gif";
+    print "ok 6\n";
+
+    $URI::Heuristic::MY_COUNTRY = "uk";
+    print "not " unless uf_urlstr("perl/camel.gif") eq "http://www.perl.co.uk/camel.gif";
+    print "ok 7\n";
+   
+    $ENV{URL_GUESS_PATTERN} = "www.ACME.org www.ACME.com";
+    print "not " unless uf_urlstr("perl") eq "http://www.perl.org";
+    print "ok 8\n";
+
+} else {
+    # don't make the inocent worry
+    print "Skipping test 6-8 because DNS does not work\n";
+    for (6..8) { print "ok $_\n"; }
+
+}
+
+$ENV{URL_GUESS_PATTERN} = "";
+print "not " unless uf_urlstr("perl") eq "http://perl";
+print "ok 9\n";
+
+print "not " unless uf_urlstr("http:80") eq "http:80";
+print "ok 10\n";
+
+print "not " unless uf_urlstr("mailto:gisle\@aas.no") eq "mailto:gisle\@aas.no";
+print "ok 11\n";
+
+print "not " unless uf_urlstr("gisle\@aas.no") eq "mailto:gisle\@aas.no";
+print "ok 12\n";
+
+print "not " unless uf_urlstr("Gisle.Aas\@aas.perl.org") eq "mailto:Gisle.Aas\@aas.perl.org";
+print "ok 13\n";
+
+print "not " unless uf_url("gopher.sn.no")->scheme eq "gopher";
+print "ok 14\n";
Index: /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/rel-base.t
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/rel-base.t	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/libwww-perl-5.36/t/uri/rel-base.t	(revision 16571)
@@ -0,0 +1,24 @@
+print "1..3\n";
+
+use URI::URL;
+
+# We used to have problems with URLs that used a base that was
+# not absolute itself.
+
+$u1 = url("/foo/bar", "http://www.acme.com/");
+$u2 = url("../foo/", $u1);
+$u3 = url("zoo/foo", $u2);
+
+$a1 = $u1->abs->as_string;
+$a2 = $u2->abs->as_string;
+$a3 = $u3->abs->as_string;
+
+print "$a1\n$a2\n$a3\n";
+
+print "not " unless $a1 eq "http://www.acme.com/foo/bar";
+print "ok 1\n";
+print "not " unless $a2 eq "http://www.acme.com/foo/";
+print "ok 2\n";
+print "not " unless $a3 eq "http://www.acme.com/foo/zoo/foo";
+print "ok 3\n";
+
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/Artistic
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/Artistic	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/Artistic	(revision 16571)
@@ -0,0 +1,131 @@
+
+
+
+
+			 The "Artistic License"
+
+				Preamble
+
+The intent of this document is to state the conditions under which a
+Package may be copied, such that the Copyright Holder maintains some
+semblance of artistic control over the development of the package,
+while giving the users of the package the right to use and distribute
+the Package in a more-or-less customary fashion, plus the right to make
+reasonable modifications.
+
+Definitions:
+
+	"Package" refers to the collection of files distributed by the
+	Copyright Holder, and derivatives of that collection of files
+	created through textual modification.
+
+	"Standard Version" refers to such a Package if it has not been
+	modified, or has been modified in accordance with the wishes
+	of the Copyright Holder as specified below.
+
+	"Copyright Holder" is whoever is named in the copyright or
+	copyrights for the package.
+
+	"You" is you, if you're thinking about copying or distributing
+	this Package.
+
+	"Reasonable copying fee" is whatever you can justify on the
+	basis of media cost, duplication charges, time of people involved,
+	and so on.  (You will not be required to justify it to the
+	Copyright Holder, but only to the computing community at large
+	as a market that must bear the fee.)
+
+	"Freely Available" means that no fee is charged for the item
+	itself, though there may be fees involved in handling the item.
+	It also means that recipients of the item may redistribute it
+	under the same conditions they received it.
+
+1. You may make and give away verbatim copies of the source form of the
+Standard Version of this Package without restriction, provided that you
+duplicate all of the original copyright notices and associated disclaimers.
+
+2. You may apply bug fixes, portability fixes and other modifications
+derived from the Public Domain or from the Copyright Holder.  A Package
+modified in such a way shall still be considered the Standard Version.
+
+3. You may otherwise modify your copy of this Package in any way, provided
+that you insert a prominent notice in each changed file stating how and
+when you changed that file, and provided that you do at least ONE of the
+following:
+
+    a) place your modifications in the Public Domain or otherwise make them
+    Freely Available, such as by posting said modifications to Usenet or
+    an equivalent medium, or placing the modifications on a major archive
+    site such as uunet.uu.net, or by allowing the Copyright Holder to include
+    your modifications in the Standard Version of the Package.
+
+    b) use the modified Package only within your corporation or organization.
+
+    c) rename any non-standard executables so the names do not conflict
+    with standard executables, which must also be provided, and provide
+    a separate manual page for each non-standard executable that clearly
+    documents how it differs from the Standard Version.
+
+    d) make other distribution arrangements with the Copyright Holder.
+
+4. You may distribute the programs of this Package in object code or
+executable form, provided that you do at least ONE of the following:
+
+    a) distribute a Standard Version of the executables and library files,
+    together with instructions (in the manual page or equivalent) on where
+    to get the Standard Version.
+
+    b) accompany the distribution with the machine-readable source of
+    the Package with your modifications.
+
+    c) give non-standard executables non-standard names, and clearly
+    document the differences in manual pages (or equivalent), together
+    with instructions on where to get the Standard Version.
+
+    d) make other distribution arrangements with the Copyright Holder.
+
+5. You may charge a reasonable copying fee for any distribution of this
+Package.  You may charge any fee you choose for support of this
+Package.  You may not charge a fee for this Package itself.  However,
+you may distribute this Package in aggregate with other (possibly
+commercial) programs as part of a larger (possibly commercial) software
+distribution provided that you do not advertise this Package as a
+product of your own.  You may embed this Package's interpreter within
+an executable of yours (by linking); this shall be construed as a mere
+form of aggregation, provided that the complete Standard Version of the
+interpreter is so embedded.
+
+6. The scripts and library files supplied as input to or produced as
+output from the programs of this Package do not automatically fall
+under the copyright of this Package, but belong to whomever generated
+them, and may be sold commercially, and may be aggregated with this
+Package.  If such scripts or library files are aggregated with this
+Package via the so-called "undump" or "unexec" methods of producing a
+binary executable image, then distribution of such an image shall
+neither be construed as a distribution of this Package nor shall it
+fall under the restrictions of Paragraphs 3 and 4, provided that you do
+not represent such an executable image as a Standard Version of this
+Package.
+
+7. C subroutines (or comparably compiled subroutines in other
+languages) supplied by you and linked into this Package in order to
+emulate subroutines and variables of the language defined by this
+Package shall not be considered part of this Package, but are the
+equivalent of input as in Paragraph 6, provided these subroutines do
+not change the language in any way that would cause it to fail the
+regression tests for the language.
+
+8. Aggregation of this Package with a commercial distribution is always
+permitted provided that the use of this Package is embedded; that is,
+when no overt attempt is made to make this Package's interfaces visible
+to the end user of the commercial distribution.  Such use shall not be
+construed as a distribution of this Package.
+
+9. The name of the Copyright Holder may not be used to endorse or promote
+products derived from this software without specific prior written permission.
+
+10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+
+				The End
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/Changes
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/Changes	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/Changes	(revision 16571)
@@ -0,0 +1,51 @@
+Fixes in 1.0.6:
+- -f works with binary files
+- w3mir will no longer use 'Referer: (commandline)' when a URL is derived
+  from the commandline/config file.
+- More errormessage fixes
+- Fixed install instructions to warn against LWP 5.40.
+
+Fixes in 1.0.5: 
+- Better error-messaged in -quiet mode 
+- Fixed quoting. Both " and ' quotes in documents are accepted. 
+- Fixed timeout handling. 
+- Fixed broken connection handling. Incomplete documents are 
+  deleted and retried.
+- Fixed URL mangling problem. In 1.0.3 URLs like ``foo.html#bar'' would
+  be rewritten to ``#bar''. This is quite bad and makes a lot of mirrors
+  un-useable. 
+- -v now prints LWPs version as well as w3mirs version
+
+Features/bugs in 1.0.5 
+- As earlier, w3mir does not support cookies. I have received a patch for
+  basic cookie support but have not yet incorporated it due to
+  time-restraints.
+- There actually exists web servers that break the HTTP standard rather
+  thoroughly by not sending a Content-type header (this is mandatory in
+  the standard). W3mir will not discover that a HTML file is HTML in this
+  case and will not extract URLs from it.
+- If you rewrite the ending filename URLs with Apply rules (as in 
+  index.htm -> index.html) and there are links to index.htm#foo the link
+  will be incorrect after mirroring. The solution is to avoid those
+  kinds of rules. This was meant to be fixed in 1.0.3 (which broke it as
+  described above), I will fix it when I get more time. The fix is to
+  remove the #fragment part of URLs when they pass thru the apply
+  machinery. Patches accepted. 
+
+Fixes in 1.0.3: 
+- The -R/remove option to remove files is no longer more destructive
+  than intended.
+- Files with 'unsafe' characters in their filename is now saved as
+  "foo bar" instead of "foo%20bar" 
+- The -B switch works once again. 
+
+Fixes in 1.0.2: 
+- W3mir now only newline converts HTML files, all other files are handled
+  as binary. This should ensure file-integrety even when working with
+   mis-configured servers. 
+
+Fixes in 1.0.1: 
+-fa option and corresponding configuration file directive works again. 
+- Added -nnc option and a corresponding configuration file directive. It
+  disables newline conversions, which could corrupt files the Webserver
+  mis-declares. The HOWTO explains the uses of -nnc 
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/INSTALL
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/INSTALL	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/INSTALL	(revision 16571)
@@ -0,0 +1,117 @@
+This is how you install w3mir on a Unix system. Please see the file
+INSTALL.w32 for install instructions for win32 systems.
+
+INSTALLING PREREQUISITES:
+
+The prerequisites are the perl packages libwww-perl, and MIME-Base64.
+The w3mir install procedure will check for their presence and complain
+if they are not there, so if you are unsure what you have you might
+skip this part for now.
+
+- Get libwww-perl from CPAN 
+  (http://www.perl.com/CPAN/modules/by-module/WWW/).  W3mir does not work
+  with LWP 5.40 and later versions.  Please get an earlier version.
+  It also does not work with the new URI package.  Use the URI package
+  enclosed in the older LWP.
+
+- Unpack it:
+
+    gzip -dc libwww-perl-*.tar.gz | tar xvBf -
+
+- Install it.  W3mir does not require the whole libwww-perl package and
+  all the packages that goes with it to work so you may follow these
+  install instructions instead of the libwww-perl install instructions
+  to get an easier install which will work with w3mir.
+
+    cd libwww-perl-*
+
+  Are you going to install it in the standard perl place (you need to
+  be the system administrator to do this)? If so:
+
+    perl Makefile.PL
+
+  If not (if you are a user):
+
+    perl Makefile.PL PREFIX=/some/dir
+
+  /some/dir could be ~ (as in your home directory).
+
+  IF you are installing an old LWP just for w3mir you can install both
+  the old LWP, the Base64 module and w3mir in a special PREFIX
+  separate from your usual install PREFIX.  This ensures that w3mir will
+  access the older version of LWP and that other software will access
+  the newer version.  If you do this make sure you install all of LWP,
+  Base64 and w3mir with the same PREFIX.
+
+  This step might produce some complaints;  A standard perl
+  installation will typically get messages about missing these
+  modules: IO::Socket, NET::FTP and MD5.  None of these need be
+  installed to run w3mir and so any error messages about these may
+  safely be ignored.
+
+    make
+    make test      (robot/ua and local/http might fail, that's OK)
+    make install
+
+  Now libwww-perl should be installed and working.
+
+- You also have to get the MIME-Base64 package
+  (http://www.perl.com/CPAN/modules/by-module/MIME/)
+
+- Unpack it:
+
+    gzip -dc MIME-Base64-*.tar.gz | tar xvBf -
+
+- Install it:
+
+    cd MIME-Base64-*
+
+  Then, as above, either
+
+    perl Makefile.PL
+
+  or
+
+    perl Makefile.PL PREFIX=/some/dir
+
+  Continue:
+
+    make
+    make test      (it should print 'All tests successful.')
+    make install
+
+  Now MIME-Base64 should be installed and working.
+
+INSTALLING W3MIR:
+
+- Get w3mir (http://www.math.uio.no/~janl/w3mir/ or from CPAN)
+
+- Unpack it:
+
+     gzip -dc w3mir-*.tar.gz | tar xvBf -
+
+- Install it:
+
+     cd w3mir-*
+
+  Are you going to install it in the standard perl place? (You
+  probably need to be the system administrator to do this.)  If so:
+
+    perl Makefile.PL
+
+  If not (if you're a user):
+
+    perl Makefile.PL PREFIX=/some/dir
+
+  /some/dir could be ~ (as in your home directory).
+
+  then
+
+     make
+     make install
+
+w3mir should now be installed correctly.  And if it's installed in
+your path you can even run it.  If you use csh or tcsh you want to run
+'rehash' before the shell will find it.
+
+1999/04/14 - Nicolai Langfeldt
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/INSTALL.w32
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/INSTALL.w32	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/INSTALL.w32	(revision 16571)
@@ -0,0 +1,92 @@
+This file contains installation instructions for two different ports
+of Perl to win32.  One port is known as the 'ActivePerl' port, the
+other is known as 'the GS port'.
+
+********************************* ActivePerl **********************************
+
+This was written and submitted by Roland Bauer.  Thanks.  I have
+edited them slightly.
+
+How to install w3mir on Win95/AS-port (April 1999):
+===================================================
+
++ get and install winzip from http://www.winzip.com/
++ get and install ActivePerl (now Build 509) from http://www.activestate.com/
++ get nmake.exe from 
+  ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exe
+  (or set switch make=nmake to make=dmake in Config.pm
+  and get dmake from GS port)
+
++ perl makefile.pl
++ nmake
++ nmake install
+
++ perl w3mir -h
++ perl w3mir http://xx.zz.zz/dir/
+
+
+Caveats:
+========
+
++ archive 1.0.6 from CPAN seems to be corrupted
+
++ &mkdir does not seem to work with dos-paths
+like 'D:/DIR1/DIR2'
+(so it is not possible to save to another harddisk)
+
+*********************************** GS Perl ***********************************
+
+These win32 installation instructions were written by Paul Hsiao and
+slightly edited by me. My thanks to Paul. It was current as of
+22-May-1998.
+
+
+WINZIP DOWNLOAD INSTRUCTIONS
+
+    The WinZip program can be accessed from the "Start" button, if the
+    program came with your system.  This software can be obtained from:
+ 
+                http://www.winzip.com/
+ 
+    Follow the installation instructions for the WinZip software as needed.
+
+ 
+PERL DOWNLOAD INSTRUCTIONS
+ 
+    The w3mir code will need access to version 5.003 or higher of the 
+    Perl interpreter and LWP library extensions in order for it to run. 
+    This software can be obtained from:
+ 
+                ftp://sunsite.uio.no/pub/languages/perl/CPAN/ports/win32/Standard
+ 
+    From this URL, select perl5.00402-bindist04-bc.tar.gz and download
+    to your PC into a folder of your choice.  In the folder, run WinZip
+    on this file.  For MS Windows 95, you need to update the registration: 
+    open C:\autoexec.bat  and add a line
+
+                path %path%;C:\Perl\bin;       
+    (C:\Perl\ is the path of the perl folder)  
+
+
+W3MIR DOWNLOAD AND INSTALLATION INSTRUCTIONS
+
+    You already have w3mir. Right? Unpack the .tar.gz file with
+    winzip.
+ 
+    Open a DOS prompt screen and go to the w3mir folder:
+ 
+        cd C:\w3mir-1.0.3
+ 
+    Type the install command for w3mir:
+ 
+        perl.exe Makefile.PL
+        make
+        make install
+ 
+    To test w3mir, type:
+ 
+    perl w3mir -h
+ 
+    If the screen displays all options (about 25 options), then 
+    w3mir is installed correctly.
+
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/MANIFEST
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/MANIFEST	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/MANIFEST	(revision 16571)
@@ -0,0 +1,15 @@
+Artistic
+Changes
+INSTALL
+INSTALL.w32
+MANIFEST
+Makefile.PL
+README
+example.cfg
+multiscope.cfg
+w3mir.PL
+w3mir-HOWTO.html
+w3mfix.PL
+htmlop.pm
+w3http.pm
+w3pdfuri.pm
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/Makefile.PL
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/Makefile.PL	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/Makefile.PL	(revision 16571)
@@ -0,0 +1,116 @@
+# -*-perl-*-
+# Makefile.PL for w3mir.
+# Note that the file 'MANIFEST' is quite significant in this context
+#
+# Notes:  Should unpack any tar.gz files in current directory and install
+#   them with identical arguments to Makefile.PL to this invocation.
+#   This is especially for making installation of w3mir easy 
+#   by installing libwww-perl and mime-base64 for the user before
+#   installing w3mir.  Cool eh?  That would require some changes.
+#
+# - janl 18/4/1997
+#
+# 19/04/99 janl: Added 'clean' target on tip from  Lupe Christoph
+#	and LWP max-version check to the LWP detection.
+# 
+
+# First just write the Makefile
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME	=> 'w3mir',
+    VERSION_FROM => 'w3mir.PL', # finds $VERSION
+    EXE_FILES => [ 'w3mir', 'w3mfix' ],
+    clean => { FILES => 'w3mir w3mfix' },
+    dist => { COMPRESS => 'gzip -f9', SUFFIX => 'gz' },
+);
+
+print "\n";
+
+# Find value of INSTALLSITELIB
+
+&read_makefile;
+$islib = resolve_make_var('INSTALLSITELIB');
+
+# Check for prerequisites
+
+$| = 1;
+my $missing_modules = 0;
+
+# libwww-perl
+print "Checking for libwww-perl:";
+
+eval "use lib '$islib'; require LWP;";
+
+if (!defined($LWP::VERSION)) {
+  print ' failed
+
+libwww seems to be missing.
+
+';
+  $missing_modules++;
+  sleep(2);
+} elsif ($LWP::VERSION<5.08 or $LWP::VERSION>=5.40) {
+  print ' failed
+
+libwww is version ',$LWP::VERSION,', I need version 5.08 to 5.39.
+Please see the INSTALL file.
+
+';
+  $missing_modules++;
+  sleep(2);
+} else {  
+  print " ok\n\n";
+}
+
+# MIME::Base64
+print "Checking for MIME::Base64:";
+
+eval "use lib '$islib'; require MIME::Base64;";
+
+if (!defined(&MIME::Base64::encode)) {
+  print ' failed
+
+MIME::Base64 seems to be missing.
+
+';
+  $missing_modules++;
+  sleep(2);
+} else {
+  print " ok\n\n";
+}
+
+
+print 'Please see the INSTALL file for instructions on how to get the
+missing/too old modules.
+
+' if $missing_modules;
+
+
+sub resolve_make_var ($) {
+
+  my($var) = shift @_;
+  my($val) = $make{$var};
+
+#  print "Resolving: ",$var,"=",$val,"\n";
+  
+  while ($val =~ s~\$\((\S+)\)~$make{$1}~g) {}
+#  print "Resolved: $var: $make{$var} -> $val\n";
+  $val;
+}
+
+
+sub read_makefile {
+
+  open(MAKEFILE, 'Makefile') || 
+    die "Could not open Makefile for reading: $!\n";
+
+  while (<MAKEFILE>) {
+    chomp;
+    next unless m/^([A-Z]+)\s*=\s*(\S+)$/;
+    $make{$1}=$2;
+#    print "Makevar: $1 = $2\n";
+  }
+
+  close(MAKEFILE)
+}
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/README
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/README	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/README	(revision 16571)
@@ -0,0 +1,133 @@
+PROPAGANDA:
+
+See http://www.math.uio.no/~janl/w3mir/ for propaganda.
+
+--------------------------------------------------------------------------
+Q: Where can I get a new version of w3mir?
+A: The w3mir homepage is at http://www.math.uio.no/~janl/w3mir/.
+   W3mir is also distributed on CPAN: http://www.perl.com/
+
+Q: Are there any mailing lists?
+A: Yes, see below.
+
+Q: Should I subscribe to any of the mailinglists?
+A: Yes, if you use w3mir at all you should subscribe to 
+   w3mir-info@usit.uio.no, send e-mail to janl@math.uio.no to be
+   subscribed.
+
+Q: I found a bug!
+A: See below.
+
+Q: How do it...
+A: There is a w3mir-HOWTO.html file in the distribution.  Read it.
+
+--------------------------------------------------------------------------
+BUGS:
+
+- -lc switch does not work too well.
+
+Please see below for how to report bugs.
+
+--------------------------------------------------------------------------
+FEATURES (NOT bugs):
+
+- URLs with two /es ('//') in the path component does not work
+  as some might expect.  According to my reading of the http/url spec.
+  it is an illegal construct, which is a Good Thing, because I don't
+  know how to handle it if it's legal.
+- If you start at http://foo/bar/ then index.html might be gotten twice.
+- Some documents point to a point above the server root, i.e.,
+  http://some.server/../stuff.html.  Netscape, and other browsers, in
+  defiance of the URL standard documents will change the URL to
+  http://some.server/stuff.html.  W3mir will not.
+
+--------------------------------------------------------------------------
+MAIL LISTS, REPORTING BUGS:
+
+Please send ideas (see todo lists further down please) and bug reports
+to w3mir-core@usit.uio.no, please include URL and command line/config
+file that triggered the bug. w3mir-info@usit.uio.no is mainly used for
+announcing new versions or bugs to w3mir users. You will get more
+information following that list than anywhere else. And it's very low
+volume. To subscribe to these lists email janl@math.uio.no. The
+w3mir-core list is intended for w3mir hackers only.
+
+--------------------------------------------------------------------------
+COPYRIGTHS:
+
+w3mir, w3http.pm, w3pdfuri.pm and htmlop.pm are free but it is
+Copyrighted by the various involved hackers.  If you want to copy,
+hack or distribte w3mir you can do that providing you comply with the
+'Artistic License' enclosed in the w3mir distribution in the file
+named Artistic.
+
+--------------------------------------------------------------------------
+CREDITS:
+
+- Oscar Nierstrasz: Wrote htget
+- Gorm Haug Eriksen: Started w3mir on the foundations of htget,
+	contributed code later.
+- Nicolai Langfeldt: Learning from Oscar and Gorms mistakes, rewrote
+  everything.
+- Chris Szurgot: Adapting to win32, good ideas and code contribs, 
+  Debugging.  And criticism.
+- Rik Faith: Uses w3mir extensively, not shy about complaining and
+  commenting and suggesting.  
+- The libwww-perl author(s) that made adding some new featres
+  ridicolously easy.
+
+--------------------------------------------------------------------------
+TODO LIST:
+
+* TODO, version 1.1:
+
+Some of these are speculative, some others are very useful.
+
+- CSS parsing/support at the same level as HTML
+- Full support for APPLETS/OBJECT tags.
+- Alias rules.  These would enable w3mir to map ukoln.bath.ac.uk and 
+  bubl.bath.ac.uk to www.ukoln.ac.uk and know that the objects contained
+  in these are all the same.  Another use would be to mirror from a mirror
+  instead of the _real_ site, since the original site to which you have
+  references are on a slow link while the mirror is on a fast link.
+- FTP support (easy if through a http style ftp proxy, but is that what
+  we want?)
+- SHTTP/SSL support
+- Add a 3rd argument to URL/Also that denotes the depth of documents to
+  be retrived under each, this would autimatically generate fetch/ignore
+  rules.  How well these work would be dependent on the order of the
+  URL/Also directives though.  Must be documented.
+- Retrive recursively until N-th order links are reached.  This
+  differs siginificantly from directory recursion which we do now.  When
+  this is done w3mir should also know the difference between inline and
+  external links, inline links should always be retrived.  Trivia question:
+  What order is needed to reach every findable document on the web from
+  Yahoo?
+- Integrate with cvs or rcs (or other version controll system) to make
+  retriver able to reproduce mirrored site for any given date.
+- Some text processing:  Adding and removing text/sgml comments when suitable
+  options and tags are found.
+- Put retrival date-stamps as comments in html files, to document the when
+  and how of how this document was retrived.
+- Example: If you're mirroring a site primarily to get to the papers, but
+  the site has n versions of each paper: foo.ps.gz, foo.ps.Z, foo.dvi.gz
+  foo.dvi.Z, foo.tar.gz, foo.zip and you only need one version.  Implement
+  a way to get only one version of documents provided in multipele versions,
+  something like multi axis preference list to get only the most attractive
+  version of the doc.
+- Logging of retrivals to file, need to change every print to a functioncall.
+- Your suggestion here.
+
+* TODO, http related
+- Use Keep-alive.  Then we should probably stop using 30 second pauses
+  between document retrivals.
+- HTTP/1.1?  HTTP/1.1 servers should do keep-alive even with 1.0 requests.
+- Separate quenes for each server, interleave requests.
+- Authentication is only done if challenged now.  If a document in a
+  directory needs authentication it is very likely that all other documents
+  in that directory and subdirectories require authentication.
+
+* If perl gets threads:
+- Make the retrival and analysis engines separate threads, and have each
+  one retrival thread pr. method/server/port and do paralell retrivals.
+- This makes http/1.1 easier too.
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/example.cfg
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/example.cfg	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/example.cfg	(revision 16571)
@@ -0,0 +1,120 @@
+# This is a example w3mir config file.  The file and options are fully
+# documented in the w3mir man page, and a lot is spelled out in the 
+# w3mir-HOWTO.  This file might not be completely updated, but the man
+# page should be.
+#
+# Comment lines start with '#'.  Comments are not allowed at end of
+# lines.  The keywords are not casesensitive, but some settings are,
+# notably fetch/ignore/apply settings, as well as the urls given.
+#
+# Available options: recurse, no-date-check, only-nonexistent, list-urls,
+# lowercase.  It is not default to recurse.  Options must be the
+# first directive to appear in the config file.
+# The options directive needs to be the first directive in the config file
+# and there can only be one.
+Options: recurse
+# Multipele options:
+# Options: recurse, only-nonexistent
+# This directive was previously named 'Fetch-options'
+#
+# Start here:
+URL: http://www.stud.ifi.uio.no/~janl/
+#
+#
+# How much noise to make, one of quiet, brief or chatty.  Default is brief
+#Verbosity: brief
+#
+# Initial referer.  Some servers are very picky....
+#Initial-Referer: http://foo.bar/
+#
+# Headers to disable for anonymitys sake: 
+#Disable-headers: referer, user
+#
+# Nicenes, robotrules can be true or false
+#Robot-Rules: true
+# Default pause between http connections is now 0 seconds 
+# Pause: 0
+# Pause between retries, in seconds.  If w3mir runs as a once-a-day thing
+# this can and should be high.  I suggest at least one hour (3600 seconds).
+#Retry-Pause: 600
+# How many times a failed retrival is retried.
+#Retries: 3
+#
+# URL selection.  Order is significant, first Fetch/Ignore rule overrides
+# later rules.  Supply as many as you want.  If not matched by ignore rules
+# a doc is gotten.  
+#Fetch: *.html
+#
+# Ignore urls we can't copy anyway.  Actually w3mir can copy
+# many cgi things with no problems.  But not always.
+Ignore: *.cgi
+Ignore: *-cgi
+Ignore: *.map
+#
+# RE variants are full perl REs.  Mix freely with the others.  These
+# must be legal perl REs, including the starting m and any
+# options you want, like 'i'.
+#
+#Fetch-RE: m/jpeg/
+#Ignore-RE: m/\.gif$/
+#
+# URL manipulation.  _All_ rules are applied in order.  If lowercasing
+# options is given that is done first.  This must be a legal perl
+# substitution RE.  Including the starting s and any options you want,
+# like 'g' and 'i'.
+#
+# This changes the name of all .gif files to .fif
+#Apply: s/\.gif$/.fif/
+#
+# HTTP Proxy server:
+#HTTP-Proxy: www-cache.uio.no:3128
+#
+# HTTP Proxy options: 
+# - 'revalidate': Force proxy to revalidate cached documents.
+# - 'refresh': Force proxy to get cached documents from server _again_.
+# - 'no-store': Use if the contents of the documents is sensitive.
+# - 'no-pragma': Force use of HTTP/1.1 'Cache-Control:' header.
+# If only 'refresh' is specified the default is to use the 'Pragma: no-cache'
+# HTTP/1.0 header, this can be overruled with the 'no-pragma' option.
+# You can be fairly sure any proxy will understand 'refresh', ONLY HTTP/1.1
+# proxies will understand 'revalidate' and 'no-store'.
+#proxy-options: refresh
+#
+# HTTP Proxy authentication.  The mechanism  is simpleminded, we either need
+# to authenticate ourselves with the proxy or not, and there can only be
+# one user/password tuple, domain/realm information is ignored...
+# HTTP-Proxy-user: foo
+# HTTP-Proxy-passwd: bar
+#
+# What to do with files, one of save, stdout or forget.
+#File-disposition: save
+#
+# Debug level
+#Debug: 0|1|2
+#
+# Umask, if not the default
+#Umask: 077
+#
+# HTML document editing options
+#Header: Mirrored from http://www.ifi.uio.no/~janl/ts/
+#Remove-nomirror: true
+#
+# Authentication:
+#Auth-domain: server:port/realm
+#Auth-user: me
+#Auth-passwd: my_password
+#
+# You can use '*' in place of server:port and/or realm:
+#Auth-domain: */*
+#Auth-user: otherme
+#Auth-passwd: otherpassword
+#
+
+# 'Fixup' is done by the external w3mfix program.  If you want a
+# mirror that's browseable in a filesystem (as opposed to via a http
+# server) just put this in:
+Fixup: run
+
+# Related is this, what is the name of the file the http server serves
+# when a directory URL is requested?  w3mir default is index.html.
+#Index-name: welcome.html
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/htmlop.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/htmlop.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/htmlop.pm	(revision 16571)
@@ -0,0 +1,656 @@
+# -*-perl-*-
+# htmlop.pl: Do operations on html documents.
+$VERSION=0.2.4;
+#
+# Original source from Bjørn Borud, without it I would not have atempted
+# this. In this incarnation it bears no resemblance to Bjørns code.
+# - Nicolai Langfeldt 18/11/95.
+# 
+# htmlop.pl does operations on html files, possebly many at a time.
+# Operations:
+# - Absolitify urls
+# - Relativify urls
+# - Gather list of urls
+# - Callback with url
+# - Canonify document w.r.t. SGML.
+#
+# Authors:
+# - Nicolai Langfeldt (janl@ifi.uio.no)
+# - Chris Szurgot (szurgot@itribe.net)
+#
+# Changes:
+# janl    18/11/95 - Initial version
+# szurgot 09/02/96 - Code in htmlop'process to remove <BASE> Tag if we are 
+#                    returning the form. An unchanged base destroys local 
+#                    fragments.
+# janl    22/02/96 - Added URLSUB functions.  <BASE> will only be removed from
+#		     the returned doc, never from the origninal doc.
+# janl    16/05/96 - Removed I* options and added single NODOC option/modifier
+#		     to replace them.
+# janl	  09/09/96 - Added URLPROC and NREL opcodes, for a better URL
+#		     processing model. -> 0.1.7
+# janl    24/09/96 - Various cosmetics, no longer inserting a !SGML tag,
+#		     only !DOCTYPE and HTML tags. -> 0.1.8
+# janl    11/10/96 - URLs in HTML 3.2 tags are now found.
+# janl     6/11/96 - Added netscape SCRIPT tag.
+# janl    20/11/96 - 'BORDER' is different from 'BORDER=0' -> 0.1.10
+# janl    06/11/96 - Added userdata argument to URLPROC.
+#   			Added SAVEURLS and USESAVED opcodes. -> 0.1.11
+# janl    11/04/97 - Changed to URI::URL and got into strict harness
+# janl	  13/04/97 - Fixed comment processing, extended it to processing
+#			directives. Bug reported by Chris Johnson. -> 0.1.12
+# janl    08/04/97 - Made ISMAP into ISMAP=, bad! -> 0.1.13
+# janl	  23/05/97 - Treating <script> and <style> as verbatim -> 0.1.14
+# janl	  06/06/97 - Canonify: <!SGML tag confused it and !DOCTYPE was mangled
+#			-> 0.1.15
+# janl	  30/07/97 - Now supporting <BASE> tag.
+#		   - Added TAGCALLBACK opcode -> 0.1.16
+# janl    16/10/97 - Empty string must be quoted, reported by Bart Barenburg
+#			-> 0.1.17
+# janl	  01/12/97 - More HTML URL tags/attributes recognized (Greg Lindhorst) 
+# janl	  13/12/97 - Can't delete the whole <BASE> tag.  Netscape has
+#		     extended it for frame use.  So only delete the HREF
+#		     attr -> 0.1.18
+# janl    01/01/98 - Realized applet/object support can't work and changed
+#		     so it's able to work, if conditions are right.
+# janl    04/01/98 - Added html 4.0 tags and attributes.
+# janl    08/02/98 - Hacked for speed.  Went from 43s to 9s on a 170K
+#		     document -> 0.2.  Thanks to Rune Frøysa who taunted me.
+# janl	  09/04/98 - More tolerant about what constitutes a newline -> 0.2.1
+# janl	  09/05/98 - Export %isdir -> 0.2.2
+# janl    13/04/99 - Remove leading /../ sequences in path component in
+#		     ABS code. -> 0.2.3
+# janl    28/05/99 - The code was buggy, now it's not. -> 0.2.4
+
+package htmlop;
+
+use URI::URL;
+
+use strict;
+# Global variables
+use vars qw($ABS $REL $LIST $CANON $URLSUB $NODOC $URLPROC $NREL);
+use vars qw($SAVEURL $USESAVED $TAGCALLBACK $debug %isdir);
+
+# These are for the smartrel routines
+my $url_origin;
+my $doc_top;
+my $doc_top_re;
+my $choped_url_or;
+
+# HTML operation codes for process_html.  The first argument is the
+# html document to do operations on.  It will not be changed.  If
+# NODOC is not passed a new document edited as specified will be
+# returned.  No more than one document will be returned by one
+# invocation of htmlop.
+
+$ABS = 1;			# Absolutify urls. Arg: Origin. The
+                                # ABS function absolutifies URLS,
+                                # assuming they are relative to the
+                                # argument.
+				# If a <BASE> tag is found the origin
+				# given by it will be used instead of
+				# the arguemnt given.
+
+$REL = 2;			# Relativize all urls. Arg: Origin.
+                                # The REL function simply removes the
+                                # argument string from any urls
+                                # matching it.  For this reason the
+                                # origin string is interprated as a
+                                # RE, which may have unexpected
+                                # results, unless RE specials are
+                                # escaped, which they should be.
+
+$LIST = 3;			# List all urls, Ret: urls
+
+$CANON = 4;			# See that missing opening (and
+                                # ending) SGML tags are injected.
+
+$URLSUB = 5;			# Do regular expression substitution
+                                # on urls.  Arg: RE, substitute.
+
+$NODOC = 6;			# Do not return a rebuilt document.
+                                # Saves memory, and time
+
+# NOTE: I SUSPECT URLPROC IS BROKEN IF A BASE TAG APPEARS IN THE TEXT.
+# THE URL PROCESSOR NEEDS TO BE PASSED htmlop::process' IDEA OF WHAT THE
+# BASE URL IS.
+
+$URLPROC = 7;			# Apply function on urls (process
+                                # urls).  Arg: Pointer to function to
+				# apply, userdata.  The function will
+				# be passed the url, modified by any
+				# previous operations and the
+				# userdata.  The function must return
+				# the new url.
+
+$NREL = 8;			# New relativisation function, works
+                                # much better than the old one. Arg:
+                                # Origin, Top.
+
+$SAVEURL = 9;			# Save urls in tag with modified name.
+				# Arg: attribute prefix.
+				# Example: <a href=foo> becomes
+				# <a href=foo w3mir-href=foo> if no other
+				# processing of the url is done.
+
+$USESAVED = 10;			# Use saved urls. Arg: attribute prefix
+
+$TAGCALLBACK = 11;		# Procedure to call for each Tag.
+				# Args: procedure, userdata (one item)
+
+				# Args to procedure: userdata, Base
+				# URL, tag name, reference to array of
+				# URL attributes, reference to hash of
+				# all attributes.  The base url is
+				# derived from the one used in ABS or
+				# the BASE tag.
+
+$debug=0;			# Debugging level in this package
+
+# process_html returns a array.  The first component of the array is
+# the new html document. The rest of the array is the urls.  If a
+# document is not to be returned a empty string is returned. If a url
+# list is not to be returned a empty array is returned.
+
+# HERE BE DRAGONS:
+
+# Where to find URLs in various tags.  The second compoent is a array
+# reference.
+
+my(%urls) = (
+	HEAD    => [ 'PROFILE' ],
+        BLOCKQUOTE => [ 'CITE' ],
+        Q 	=> [ 'CITE' ],
+        INS	=> [ 'CITE' ],
+	DEL	=> [ 'CITE' ],
+	A	=> [ 'HREF' ] ,
+	IMG	=> [ 'SRC' ,'LOWSRC' ,'USEMAP', 'LONGDESC' ] ,
+	EMBED	=> [ 'SRC' ],
+	FRAME	=> [ 'SRC', 'LONGDESC' ],
+        IFRAME  => [ 'SRC', 'LONGDESC' ],
+	BODY	=> [ 'BACKGROUND' ],
+	AREA	=> [ 'HREF' ],
+	LINK	=> [ 'HREF' ],
+
+	# The APPLET and OBJECT tags do not fit into my model for URL
+	# manipulation.  Just looking at CODEBASE might work, if the
+	# URL it names is a browseable directory...
+	APPLET	=> [ 'CODEBASE' ],  # If the codebase dir is browseable
+	OBJECT  => [ 'CODEBASE' ],  # Ditto.  Can't handle DATA attribute now
+
+	INPUT	=> [ 'SRC', 'USEMAP' ],
+	MAP	=> [ 'HREF' ],
+	SCRIPT	=> [ 'SRC', 'FOR' ],# 'FOR's semantics is not defined, the
+				    # attribute is just reserved for possible
+				    # future use...
+	BGSOUND => [ 'SRC' ],
+	FORM	=> [ 'ACTION' ],    # Is this asking for trouble?
+				    # Maybe it should just be absolutized...
+	     			    # On the other hand: It's CGI...
+	);
+
+my(%relative) = (
+	# Identify URL attributes containing urls that are relative to
+	# the named URL attribute.   When processing these they should
+        # be absolitized and then relativized relative to the BASE attribute.
+        # This is just window dressing for now; it is not used for anything.
+
+	# ARCHIVE is really a URI _list_.
+	CODEBASE => [ 'CLASSID', 'DATA', 'CODE', 'ARCHIVE' ],
+        );
+
+%isdir = (
+	# These tags refer to directories:
+	CODEBASE => 1
+	);
+
+# Tags that enclose bits we want to leave absolutely alone because they
+# are not very like HTML, or some such.
+
+# The material between the start and end tags is copied with no
+# processing at all.  The end tag is left to be processed.
+# The endtag match is case insensitive.
+my(%verbatim) = (
+        SCRIPT	=> quotemeta('</SCRIPT>'),	# Embeded scripts
+	STYLE	=> quotemeta('</STYLE>'),	# Embeded stylesheet
+	);
+
+# These are the functions that pick the HTML to pieces.  It will not
+# work esp. good on a random SGML document since the HTML application
+# of SGML has simpler quoting than it might.
+
+sub gettoken {
+  # Get one token from the argument, removing it from the argument.
+  # BUG: There should be whitespace at the end of the examined string.
+  my($c,$token,$i);
+  
+  # Skip whitespace and newlines
+  return '' unless defined(@_) && defined($_[0]);
+  $_[0] =~ s/^[\r\n\s]*//;
+  
+  return '' if ($_[0] eq '');
+  
+  $c = substr($_[0],0,1);
+  substr($_[0],0,1)='';
+  
+  if ($c eq '"' || $c eq "\'") { # Quoted material
+    $i=index($_[0],$c);
+    # End-quote missing, just gobble the rest of the doc
+    $i=length($_[0]) if $i == -1;
+    # Extract and remove token
+    $token=substr($_[0],0,$i);
+    substr($_[0],0,$i+1)='';
+  } elsif ($c eq '=') {
+    $token='=';
+  } else {			# Non-quoted material, ends in whitespace or =
+    $_[0] =~ m/[=\s\n\r]/;
+    $_[0] = $&.$';
+    $token=$c.$`;
+  }
+  # print "Token: '$token'\t\tRest: '",$_[0],"'\n";
+  return $token;
+}
+
+
+sub tagtoken {
+  # Pick the tag to pieces (also knonw as tokens). Return an
+  # associative array of attributes.  The attribute-names are changed
+  # to uppercase.  The attribute-values are left as is.
+  my($tok,$lasttok,%tokens);
+  # Append a space, gettoken needs it - silly? Yes! 
+  # Change it to test on boundrary things rather than ...?
+  $_[0].=' ';
+
+  $lasttok='';
+  while (1) {
+    last if (($tok=uc &gettoken($_[0])) eq '');
+
+    if ($tok eq '=') {
+#      print STDERR " -bad html-" if ($lasttok eq '');
+      $tokens{$lasttok}.=&gettoken($_[0]);
+      print STDERR "STORED: $lasttok = ",$tokens{$lasttok},"\n" if $debug;
+    } else {
+      $tokens{$tok}=undef;
+      $lasttok=$tok;
+    }
+  }
+  return %tokens;
+}
+
+
+sub gettag {
+  # Pick out the following things from the remaining html doc:
+  # Everything leading up to the first tag.  The first tag, and its
+  # contents.  Modify @_ directly to reduce number of copies of
+  # possebly huge documents kept in memory at once.  Return the body,
+  # the tag name, and the attributes (associative array)
+  my(%attr,$tagn,$tagc,$body,$tag,$doc);
+
+  $doc=\$_[0];
+
+  my($start,$end,$length);
+  
+  $start=index($$doc,'<');
+
+  if ($start<$[) {
+    # EOF
+    $body=$$doc;
+    $$doc='';
+    return ($body,'',());
+  }
+
+  $end=index($$doc,'>',$start+1);
+  
+  if ($end<$[) {
+    # This sucks, found no end of the tag...
+    $body=$$doc;
+    $$doc='';
+    return ($body,'',());
+  }
+
+  $length=$end-$start-1;
+
+  $body=substr($$doc,0,$start);
+  $tag=substr($$doc,$start+1,$length);
+
+  # This shortens the string in each itteration, some kind of mechanism
+  # to do it once in a while would speed things up further.  HOWEVER, when
+  # I tried to code this all I got was a _nasty_ memory leak.
+  substr($$doc,0,$end+1)='';
+
+#  print STDERR "------\n";
+  
+#  print STDERR "BODY: /$body/\n";
+  print STDERR "COMPLETE TAG: /$tag/\n" if $debug;
+#  print STDERR "REST: /",substr($$doc,0,20),"/\n";
+
+#  print STDERR "------\n";
+
+  # Examine tag contents
+  if ($tag =~ /^([!?]--)/ || $tag =~ /^(!\w+)/) {
+    # Comment or processing dicective, handle specially
+    $tagn=$&;
+    $tagc=$';
+    return ($body,$tagn,("$tagc",undef));
+  }
+
+  # Everything else
+  ($tagn,$tagc) = split(/[\s\n\r]+/,$tag,2);
+  $tagn="\U$tagn";
+
+  return ($body,$tagn,()) if !defined($tagc);
+  
+  return ($body,$tagn,&tagtoken($tagc));
+}
+
+
+# This is meant for general consumption:
+
+sub process {
+  # Process a html file.  Into one end you put a html file.  Out
+  # of the other end you get something dependent on the operations
+  # you specified.
+  # I cannot gobble my arguments. I need to examine them several times.
+  
+  my($arg,$doc,$i,$retdoc,$canon,$newdoc,@urllist,$Q,$cont);
+  my($origin,$baseurl);
+  
+  $origin=$baseurl='';
+
+  $retdoc=$canon=0;
+  
+  # Get the document from the argument list
+  $doc=shift(@_);
+  
+  $retdoc=1;
+  $i=0;
+  # Argument checking
+  while (defined($arg=$_[$i++])) {
+    if (! ($arg =~ /^\d+$/)) {
+      print STDERR "ERROR IN HTMLOP::process:\n";
+      print STDERR "Args: ",join(',',@_),"\n";
+      print STDERR "ARG: $arg is not a opcode.\n";
+      exit(1);
+    }
+    if ($arg == $ABS) {
+      $baseurl=$origin=$_[$i++];
+    } elsif ($arg == $REL || $arg == $SAVEURL || $arg == $USESAVED) {
+      $i++; # Skip one arg
+    } elsif ($arg == $URLSUB || $arg == $NREL || $arg == $URLPROC ||
+	     $arg == $TAGCALLBACK ) {
+      $i += 2; # Skip two args
+    } elsif ($arg == $LIST) { 
+      # do nothing
+    } elsif ($arg == $CANON) {
+      $canon=1;
+    } elsif ($arg == $NODOC) {
+      $retdoc=0;
+    } else {
+      die "htmlop: Incorrect invocation of html_process\n";
+    }
+  }
+  
+  my($endhtml)=0;	# Have we seen </html>?
+  my($SGML)=1;		# 1: !DOCTYPE not seen, 2: !DOCTYPE seen, -1: it's OK
+
+  # These are used to store the tag components
+  my($textpart);
+  my($tagname);
+  my(%attrval);
+
+  my($wholetag);	# The whole tag, put together again
+  my($moretag);		# TMP storage of tag attributes
+  my($attr);		# Looping thru attributes, misnomer.
+  my($RE);
+  my($subst);
+  my($prefix);
+  my($fun);		# Function to apply to url
+  my($verbatim)='';
+  my($url_o,$path);		# URL object Used in ABS to remove leading ..
+
+  # Welcome to the machine
+
+  $newdoc='';
+  while ($doc ne '') {
+    ($textpart,$tagname,%attrval)=&gettag($doc);
+    
+    # Process the tag
+    { # Need a way to get out of this, last is my friend
+      # 'Canonize'
+      if ($canon) {
+	$endhtml=1 if ($tagname eq '/HTML');
+	if ($SGML!=-1 && $canon && $tagname ne '!--' && $tagname ne '!SGML') {
+	  $wholetag=$tagname;
+	  $moretag=join('',keys %attrval);
+	  $wholetag.=' '.$moretag if ($moretag ne '');
+	  if ($SGML==1) {
+	    $SGML=2;
+	    if ($tagname eq '!DOCTYPE') {
+	      $tagname=$wholetag;
+	      %attrval=();
+	      last;
+	    }
+
+	    # We have no idea what DTD this doc follows so we put in
+	    # something kinda non-comitting
+	    $newdoc.='<!DOCTYPE HTML PUBLIC "html.dtd">'."\n";
+	  }
+	  if ($SGML==2) {
+	    $SGML=-1;
+	    if ($tagname eq 'HTML') {
+	      $tagname=$wholetag;
+	      %attrval=();
+	      last;
+	    }
+	    $newdoc.='<HTML>'."\n";
+	  }
+	}			# sgml!=-1
+      }				#canon
+
+      # Tack on text part before I bail out, if wanted
+      $newdoc.=$textpart if $retdoc;
+
+      if ($tagname eq 'BASE') {
+	if (exists($attrval{'HREF'})) {
+	  if ($origin) {
+	    $baseurl=(url($attrval{'HREF'})->abs($origin,1))->as_string;
+	  } else {
+	    $baseurl=$attrval{'HREF'};
+	  }
+	  # Get rid of the HREF attribute.  Netscape 4.0 puts (other) stuff
+	  # into BASE that is not found in the HTML 4.0 spec.
+	  delete $attrval{'HREF'};
+	  print STDERR "\nBase tag: $baseurl\n" if $debug;
+	}
+      }
+
+      # URL processing
+      $i=0;
+      while (defined($arg=$_[$i])) {
+	if (! ($arg =~ /^\d+$/)) {
+	  print STDERR "Args: ",join(',',@_),"\n";
+	  print STDERR "ARG: $arg ($i) is not a opcode.\n";
+	  exit(1);
+	}
+	$i++;
+	if ($arg == $ABS) {
+	  $origin=$baseurl || $_[$i++];
+	  $i++;
+	  # Want it to be a URL object
+	  $origin=url $origin unless ref $origin;
+	  print STDERR 'ABS: ',$origin->as_string,"\n" if $debug;
+	  next unless defined($urls{$tagname});
+	  foreach $attr (@{$urls{$tagname}}) {
+	    if (defined($attrval{$attr})) {
+	      # Ugly: Remove leading /../ sequences in path component
+	      $url_o=url($attrval{$attr})->abs($origin,1);
+	      if (defined($path=$url_o->path)) {
+		# mailto: URLs does not have path components
+		$path =~ s~/\.\.(?=/)~~g;
+		$url_o->path($path);
+	      }
+	      $attrval{$attr}=$url_o->as_string;
+	    }
+	  }
+	} elsif ($arg == $REL) {
+	  $origin=$_[$i++];
+	  # Want it to be a string
+	  $origin=$origin->as_string if ref $origin;
+	  print STDERR 'REL: ',$origin,"\n" if $debug;
+	  next unless defined($urls{$tagname});
+	  foreach $attr (@{$urls{$tagname}}) {
+	    $attrval{$attr} =~ s/^$origin//
+	      if defined($attrval{$attr});
+	  }
+	} elsif ($arg == $URLSUB) {
+	  $RE=$_[$i++];
+	  $subst=$_[$i++];
+	  warn "URLSUB: $RE -> $subst\n" if $debug;
+	  next unless defined($urls{$tagname});
+	  foreach $attr (@{$urls{$tagname}}) {
+	    $attrval{$attr} =~ s/$RE/$subst/
+	      if defined($attrval{$attr});
+	  }
+	} elsif ($arg == $LIST) {
+	  warn "LIST;\n" if $debug;
+	  next unless exists($urls{$tagname});
+	  foreach $attr (@{$urls{$tagname}}) {
+	    if (exists($attrval{$attr})) {
+	      $attrval{$attr}.='/'
+		if $isdir{$attr} && $attrval{$attr} =~ m~[^/]$~;
+	      push(@urllist,$attrval{$attr});
+	    }
+	  }
+	} elsif ($arg == $SAVEURL) {
+	  warn "SAVEURL;\n" if $debug;
+	  $prefix=$_[$i++];
+	  next unless exists($urls{$tagname});
+	  foreach $attr (@{$urls{$tagname}}) {
+	    $attrval{"$prefix$attr"}=$attrval{$attr}
+	      if defined($attrval{$attr});
+	  }
+	} elsif ($arg == $USESAVED) {
+	  warn "USESAVED;\n" if $debug;
+	  $prefix=$_[$i++];
+	  next unless exists($urls{$tagname});
+	  foreach $attr (@{$urls{$tagname}}) {
+	    $attrval{$attr}=$attrval{"$prefix$attr"}
+	      if (defined($attrval{"$prefix$attr"}));
+	    # bug compatability, drop sometime after w3mir 1.0
+	    $attrval{$attr}=$attrval{"$prefix-$attr"}
+	      if (defined($attrval{"$prefix-$attr"}));
+	  }
+	} elsif ($arg == $NODOC) {
+	  warn "NODOC;\n" if $debug;
+	} elsif ($arg == $CANON) {
+	  warn "CANON;\n" if $debug;
+	} elsif ($arg == $URLPROC || $arg == $NREL) {
+	  # Apply a function to all urls.
+	  # NREL = Special case of $URLPROC, apply internal function.
+	  if ($arg == $URLPROC) {
+	    warn "URLPROC;\n" if $debug;
+	    $fun=$_[$i++];
+	    $arg=$_[$i++];
+	  } else {
+	    $fun=\&smartrel;
+	    $arg=undef;
+	    $url_origin=$_[$i++];
+	    $doc_top=$_[$i++];
+	    $doc_top_re=quotemeta $doc_top;
+	    ($choped_url_or=$url_origin) =~ s/^$doc_top_re//;
+	    warn "NREL $url_origin $doc_top\n" if $debug;
+	  }
+
+	  next unless (defined($urls{$tagname}));
+
+	  foreach $attr (@{$urls{$tagname}}) {
+	    $attrval{$attr}=&$fun($attrval{$attr},$arg)
+	      if defined($attrval{$attr});
+	  }
+	} elsif ($arg == $TAGCALLBACK) {
+	  $fun=$_[$i++];
+	  $arg=$_[$i++];
+	  warn "TAGCALLBACK($tagname);\n" if $debug;
+	  &$fun($arg,$baseurl,$tagname, 
+		(defined($urls{$tagname})?($urls{$tagname}):undef),
+		\%attrval);
+	} else {
+	  print STDERR "Internal error. opcode: $arg, i: $i, args: ",
+	  join(',',@_),"\n";
+	}
+      }
+      last;
+    }
+
+    # That ends URL processing
+
+    # Was this a verbatim leadin tag?  If yes, atempt to fish out text
+    # between here and the end tag, (minimal match) and substitute it
+    # with nothing.  The end tag is kept.  And the fished out text is
+    # re-inserted in the result with no changes.
+
+    $verbatim=$1 
+      if defined($verbatim{$tagname}) &&
+	($doc =~ s/^(.*?)($verbatim{$tagname})/$2/is);
+    
+    # Tack on the tag, if wanted.
+    if ($retdoc) {
+      if ($tagname) {
+	$newdoc.='<'.$tagname;
+	foreach $attr (keys %attrval) {
+	  $newdoc.=' '.$attr;
+	  if (defined($cont=$attrval{$attr})) {
+	    $Q='"';
+	    $Q="'" if $cont =~ m/\"/;
+	    $newdoc.='='.$Q.$cont.$Q;
+	  }
+	}
+	$newdoc.='>'.$verbatim;
+	$verbatim='';
+      }
+    }
+    print STDERR "NEW: $newdoc\n" if $debug > 2;
+  }
+  $newdoc.="</HTML>\n" if ($canon && !$endhtml);
+  return ($newdoc,@urllist);
+}
+
+
+sub smartrel {
+  # 'smart' relativisation function, uses .. to refer to things up to
+  # $doc_top level.  Outside that scope it stays absolute.
+  #
+  # The rel function itself is now in libwww-perl
+  
+  my($url_o)=@_;
+
+  return if (!(defined($url_o) && $url_o));
+  
+  $url_o=url $url_o unless ref $url_o;
+
+#  print STDERR "\nsmartrel: $url_o->as_string\n",
+#                 "    from: $url_origin\n",
+#                 "  within: $doc_top\n";
+  
+  # Check if within scope of our doc
+  $url_o = $url_o->rel($url_origin)
+    if $url_o->as_string =~ m/^$doc_top_re/;
+
+  return $url_o->as_string;
+}
+
+
+sub smart_setup {
+  # Setup routine for smartrel.
+
+  ($url_origin,$doc_top) = @_;
+
+  $url_origin=$url_origin->as_string if ref $url_origin;
+  $doc_top=$doc_top->as_string if ref $doc_top;
+
+  $doc_top_re=quotemeta $doc_top;
+
+  ($choped_url_or=$url_origin) =~ s/^$doc_top_re//;
+}
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/install.sh
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/install.sh	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/install.sh	(revision 16571)
@@ -0,0 +1,9 @@
+#!/bin/sh -v
+
+export PERL5LIB=$GSDLHOME/perllib/cpan/lib:$PERL5LIB
+export PATH=$GSDLHOME/perllib/cpan/bin:$PATH
+
+perl Makefile.PL PREFIX=$GSDLHOME/perllib/cpan
+
+make
+make install
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/multiscope.cfg
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/multiscope.cfg	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/multiscope.cfg	(revision 16571)
@@ -0,0 +1,46 @@
+# This file is meant to illustrate multiscope retrival.
+#
+# Available options: recurse, no-date-check, only-nonexistent, list-urls,
+# lowercase.  It is not default to recurse.  options must be the 
+# first directive in the the config file.
+Options: recurse
+# This directive was previously known as 'Fetch-options'
+#
+# This is the two argument form of URL:.  It fetches the first into the second
+URL: http://www.math.uio.no/~janl/ math/janl
+#
+# These says that any documents refered to that lives under these places
+# should be gotten too.  Into the named directories.  Two arguments are
+# required for 'Also:'.
+Also: http://www.math.uio.no/drift/personer/ math/drift
+Also: http://www.stud.ifi.uio.no/~janl/ ifi/janl
+Also: http://www.mi.uib.no/~nicolai/ math-uib/nicolai
+#
+# A more typical use would perhaps be:
+#   URL: http://www.math.uio.no/~janl/ janl
+#   Also: http://www.math.uio.no/images/ images
+# which would retrive the images refered to under
+# http://www.math.uio.no/~janl/ into a directory called images
+#
+# CD here before doing any work
+#cd: janlhomes
+#
+# Default pause is now 0.
+#Pause: 0
+#
+# Ignore urls we can't copy anyway.  Actually w3mir can copy
+# many cgi things with no problems.  But not always.
+Ignore: *.cgi
+Ignore: *-cgi
+Ignore: *.map
+#
+# Run fixup to get a filesystem browseable mirror
+Fixup: run
+# The options above will result in this directory hierarchy under
+# where you started w3mir:
+#
+# w3mir/math/janl		files from http://www.math.uio.no/~janl
+# w3mir/math/drift		from http://www.math.uio.no/drift/personer/
+# w3mir/ifi/janl		from http://www.stud.ifi.uio.no/~janl/
+# w3mir/math-uib/nicolai	from http://www.mi.uib.no/~nicolai/
+#
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3http.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3http.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3http.pm	(revision 16571)
@@ -0,0 +1,765 @@
+# -*- perl -*-
+# w3http.pm	--- send http requests, janl's 12" mix for w3mir
+#
+$VERSION=1.0.22;
+#
+# This implements http/1.0 requests.  We'll have problems with http/0.9
+# This is in no way specific to w3mir.
+#
+# IMPORTANT: The caller should initialize the C locale for some of the
+#   things here to work correctly (specifically the strftime function).
+#
+# This is a rewrite of http.pl by Oscar Nierstrasz; I copied the code he he
+# copied from the camel book.  Some functions written by Gorm Haug Eriksen
+# (gorm@usit.uio.no) has been used as is.
+#
+# Contributors:
+#   Nicolai Langfeldt, janl@ifi.uio.no
+#   Gorm Haug Eriksen, gorm@usit.uio.no
+#   Chris Szurgot, szurgot@itribe.net
+#   Bernhard Weisshuh, bkw@weisshuhn.de
+# Copying and modification is governed by the "Artistic License" enclosed in
+# the w3mir distribution
+#
+# gorm :
+# &w3http::get_last_modified  return the last modified stamp on a file in
+#                         the right format for use with http
+#
+# janl:
+# &http::query: Send a http query.  A completely general function to send a
+#   http query.  Will extract header values, http response code and, optionaly,
+#   convert text files to local linefeed format.
+#
+# Variables to examine after a query
+# $w3http::document: The document returned by the query, if any.
+# $w3http::doclen: The length of the document
+# $w3http::result: The numerical http result code.  It may take these values:
+# - Normal HTTP reply codes
+# -  98: OS error, permanent, errormessage in $!
+# -  99: Other permanent error: see $restext.
+# - 100: Transient error: Timeout/connection broken
+# $w3http::restext: The english(?) HTTP result or w3http generated message
+# $w3http::header: The http header returned.
+# $w3http::plaintexthtml: 1 if this doc is non-content-encoded text/html
+#	(as opposed to content-encoding: compressed content-type: text/html
+#       which needs decompression before we can inspect the html) 
+#	The tests are somewhat longwinded so I do it just once here.
+# %w3http::headval: Associative array of header values
+# $w3http::headval{'CONTENT-TYPE'}: Derived content type, stripped of charset
+#		qualifiers and other distractions.
+# $w3http::xfbytes: Transfered bytes, cumulative.  Document part only.
+# $w3http::headbytes: Bytes of headers received, cumulative.
+#
+# Variables that change http's behaviour/requests:
+# $w3http::agent: User agent, default is basename of $0
+# $w3http::from: Request is from, default is user@host
+# $w3http::version: The http version to use, only 1.0 is known to me.
+# $w3http::timeout: How long to wait for new data to arrive, default is 600sec
+# $w3http::buflen: Network read buffer size, default is 4096.  It might give a
+#	speedup to tune this for specific servers' so it matches their send
+#	size.  This size can be detected if we want to, I think.
+# $w3http::debug: 1 debuging output, 2, more, 3 queries and replies
+# $w3http::verbose: 0: say nothing, 1: print progress info
+# $w3http::convert: Convert text/* documents to local newline convention?
+#	The default is to do it.
+# $w3http::proxyserver: The name of the proxyserver to use.
+# $w3http::proxyport: The port of the proxyserver to use. 0 if no proxyserver.
+# $w3http::proxyuser: If this is set proxy authentication will be used.
+# $w3http::proxypasswd: The password for proxy authentication
+#
+# Things gotten from main:
+# - $main::win32: 1 if win32 restrictions apply to this system
+# - $main::nulldevice: Bit sink file/device on this system.
+#
+# History (european date format dd/mm/yy):
+#     janl ??/??/95 -- Rewrite finished
+#  szurgot ??/??/95 -- Win32 compatability
+#     janl 16/05/96 -- Added SAVEBIN option, based on idea by szurgot
+#  szurgot 03/05/96 -- Corrected typo in check for content-length against
+#                      retreive document length. Added test for zero-length
+#		       documents (Not retreived because not-modified)
+#  szurgot 19/05/96 -- Win32 adaptions, fixes.
+#     janl 19/05/96 -- Chris won an argument, and janl simplified http 
+#		       retrival loop (-> version 1.0.4)
+#     janl 09/09/96 -- Incorporated a patch submited by Michael Kriby -> 1.0.5
+#     janl 16/09/96 -- Support for authorization. -> 1.0.6
+#     janl 27/09/96 -- Support for Accept header, lack pointed out by
+# 			charles@ermine.ox.ac.uk: ... HTTP/1.1 (§14.1) says 
+#			``If no Accept header field is present, then it is
+#			assumed that the client accepts all media types,
+#			earlier versions of the protocol suggest that only
+#			text/plain and text/html will be offered by default.''
+#			This contradicts my memory of a http/1.0 draft.
+#			Also added $ACCEPT option.
+#     janl 20/10/96 -- Now uses HTTP::Date to produce HTTP timestamps -> 1.0.7
+#     janl 27/10/96 -- Didn't use to check if gethostbyname worked -> 1.0.8
+#     janl 02/12/96 -- Forgot a unlink when renaming temporary files.
+#     janl 21/02/97 -- Multipele $ACCEPT options work. -> 1.0.9
+#     janl 19/03/97 -- Now issues Host: header -> 1.0.10
+#     janl 10/04/97 -- Changed from wwwurl to URI::URL, and various related
+#                      changes. -> 1.0.11
+#     janl 09/05/97 -- Microsoft ISS servers are _so_ broken -> 1.0.12
+#                      (don't close the write end of the HTTP socket after
+#			sending a query to them)
+#     janl 12/05/97 -- New version of perl caught some typos, fixed
+#			longstanding bug in the newline conversion bit.
+#			-> 1.0.13
+#     janl 06/06/97 -- Demand Loading of MIME::BASE64 -> 1.0.14
+#     janl 01/12/97 -- FAT filesystems drops LSB of modtime.  Patch from
+#			Greg Lindhorst (gregli@microsoft.com)
+#                   -- whoami does not exist on win32, hardwire a default
+#			value (unknown) (also Greg L.) -> 1.0.15
+#     janl 01/22/98 -- Proxy authentication as outlined by Christian Geuer
+#     janl 02/20/98 -- Complex 'content-type' headers handled. -> 1.0.17
+#     janl 04/20/98 -- Only newline convert text/html, everything else is
+#			handled as binary. -> 1.0.18
+#     janl 12/05/98 -- Store tmpfile in its final destination directory
+#			avoiding asking movefile move it across filesystems.
+#			-> 1.0.19
+#     janl 01/08/98 -- Timeout fix from Michael Gusev, also flag short doc
+#			as error.
+#     janl 24/09/98 -- Better error handling -> 1.0.20
+#     bkw  17/12/98 -- Fixed problem with tempfile-generation when
+#                      running in forget-mode (-f)
+#     janl 05/01/99 -- Referer: dropped if argument not true -> 1.0.21
+#     janl 13/04/99 -- Added workaround for broken win32 perl resolving.
+
+package w3http;
+
+require 5.002;
+use Socket;
+use HTTP::Date;
+use Sys::Hostname;
+use URI::URL;
+
+# Suplementary libwww-perl:
+sub URI::URL::_generic::basename {
+  my $self = shift;
+  my @p = $self->path_components;
+  my $old = $p[-1];
+  if (@_) {
+    splice(@p, -1, 1, shift);
+    $self->path_components(@p)
+  }
+  $old;
+}
+
+
+END { 
+  # Remove tmp file and such in here.  That means that main:: gotta catch
+  # interrupt signals and exit on them, so ENDs are executed.
+}
+
+use strict;
+# Global variables, we want to share them:
+use vars qw($GET $HEAD $GETURL $HEADURL $IFMOD $IFMODF $AUTHORIZ $REFERER);
+use vars qw($SAVEBIN $ACCEPT $NOUSER $FREEHEAD $agent $version $timeout);
+use vars qw($debug $convert $proxyserver $proxyport $xfbytes $headbytes);
+use vars qw($verbose $result $restext $header $document);
+use vars qw($plaintexthtml %headval $progress $doclen $proxyuser);
+use vars qw($proxypasswd);
+
+my $hasAlarm;   # Win32 does not have any alarm
+my $chime;	# Has the alarm gone off yet?
+my %address;	# My own DNS cache
+my $savALRM;	# Saved ALRM handler
+my $savPIPE;	# Saved PIPE handler
+
+# The main:: program should detect if we're running on win32 or not,
+# somehow
+if ($main::win32) {
+  warn "win32\n";
+  # Compensate for lacks of win32 perl. 
+  $hasAlarm=0;
+  # Seems to be unavailable in win32/perl5.001.  It has to be in 5.003!
+#  eval "sub sockaddr_in {
+#	($port, $thataddr) = @_;
+#	$sockaddr = 'S n a4 x8';
+#	return pack($sockaddr, &AF_INET, $port, $thataddr);
+#    }";
+} else {
+  $hasAlarm=1;
+}
+
+
+# Find out some things
+my $thishost = hostname();
+my $proto = getprotobyname("tcp");
+
+(my $name, undef) = gethostbyname($thishost);
+chomp(my $user = $ENV{'LOGNAME'} || $ENV{'USER'} || `whoami` || 'unknown');
+my $from   = "$user\@$name";
+
+my $nl = "\r\n";
+# Default values, change by assignment in using-program.
+$agent  = $0; $agent =~ s~.*/~~; # Basename 
+$version= "1.0";
+$timeout= 600;			# Timeout while waiting for data/connection
+my $buflen = 4096;		# recv buffer length
+$debug = 0;			# Debuging output?
+$convert = 1;			# Convert newlines of text docs to local format
+$proxyserver='';		# Proxy server.
+$proxyport=0;			# Proxy server port. 0 if no proxy.
+$proxyuser='';			# Username for proxy authentication
+$proxypasswd='';		# Password for proxy authentication
+$xfbytes=0;			# 0 bytes transfered, cumulative
+$headbytes=0;			# 0 bytes of headers, cumulative
+$doclen=0;			# 0 bytes in doc, pr. document
+my $tmpfile="w3mir$$.tmp";	# Temporary filename
+$verbose=0;			# Verbosenes, 0: silent, 1: progress info
+
+# Query opcodes
+$GET = 1;			# GET query. Arg: host,port,path
+$HEAD = 2;			# HEAD query. Arg: host,port,path
+$GETURL = 3;			# GET query. Arg: url
+$HEADURL = 4;			# HEAD query. Arg: url
+# Here we lack PUT, which is not implemented
+# Modify query thus:
+$IFMOD = 101;			# If-modified after: Arg: HTTP-date-str
+$IFMODF = 102;			# If-modified after file: Arg: local-file-name
+$AUTHORIZ= 103;			# Basic authorization. Arg: 'user:password'
+$REFERER = 104;			# Referer: Arg: Referer 
+$SAVEBIN = 105;			# Write binary files to disk. Arg: File name
+				# If this opcode is used then main must provide
+				# a &main::movefile(oldname,newname) procedure
+				# that handles moving the tmp file to the
+				# final name/location.
+$ACCEPT  = 106;			# Accept header value: Arg: value
+$NOUSER  = 107;			# Don't insert user header.  Arg: none
+$FREEHEAD= 999;			# Freeform header, one line.  Arg: header
+
+sub query {
+  # Build and send a HTTP query.  And also receive response - janl 95/09/18
+  #
+  # Return codes: 0 if it didn't work.  1 if it did work.
+  # HTTP style result code in w3http::$result and message in w3http::$restext
+  
+  # We do next to no argument type checking btw.
+  
+  my($host,$port,$request,$query,$method,$inp,$linp,$saveto,$save,$arg);
+  my($start,$wantbytes,$thataddr,$err,$headb,$tmpf,$ldoc,$nouser,$q,$accept);
+  my($origreq,$req_o,$plaintext);
+  
+  # Something ought to be said
+  $result=99;
+  $restext='w3http: internal error';
+  $nouser=0;
+  
+  if ($version ne '1.0') {
+    warn "Unknown HTTP version $version, no request sent\n";
+    return 0;
+  }
+  
+  $accept=$saveto=$query='';
+  
+  # Find out what to ask for
+  
+  while (defined($arg=shift)) {
+    if ($arg == $GET) {
+      $host=shift;
+      $port=shift;
+      $request=shift;
+      $req_o=url 'http://'.$host.':'.$port.$request;
+      if ($proxyport) {
+	$query.='GET http://'.$req_o->as_string;
+      } else {
+	$query.='GET '.$req_o->epath;
+      }
+      $query.=' HTTP/'.$version.$nl;
+    } elsif ($arg == $HEAD) {
+      $host=shift;
+      $port=shift;
+      $request=shift;
+      $req_o=url 'http://'.$host.':'.$port.$request;
+      if ($proxyport) {
+	$query.='HEAD '.$req_o->as_string;
+      } else {
+	$query.='HEAD '.$req_o->epath;
+      }
+      $query.=' HTTP/'.$version.$nl;
+    } elsif ($arg == $GETURL) {
+      $req_o=shift;
+      $req_o=url $req_o unless ref $req_o;
+      ($method,undef,undef,$host,$port,$request,undef,$q) = $req_o->crack;
+      if ($proxyport) {
+	$query.='GET '.$req_o->as_string;
+      } else {
+	$q=$req_o->equery;
+	$query.='GET '.$request.($q?"?$q":'');
+      }
+      $query.=' HTTP/'.$version.$nl;
+    } elsif ($arg == $HEADURL) {
+      $req_o=shift;
+      $req_o=url $req_o unless ref $req_o;
+      if ($proxyport) {
+	$query.='HEAD '.$req_o->as_string;
+      } else {
+	$q=$req_o->equery;
+	$query.='HEAD '.$req_o->epath.($q?"?$q":'');
+      }
+      $query.=' HTTP/'.$version.$nl;
+    } elsif ($arg == $IFMOD) {
+      $query.='If-Modified-Since: '.(shift).$nl;
+    } elsif ($arg == $IFMODF) {
+      $query.='If-Modified-Since: '.&last_modified(shift).$nl;
+    } elsif ($arg == $AUTHORIZ) {
+      # Demand-load MIME::Base64
+      if (!defined(&MIME::Base64::encode)) {
+	eval "use MIME::Base64;";
+	die "w3http: Could not load MIME::Base64 module necessary for authentication\n"
+	  unless defined(&MIME::Base64::encode);
+      }
+      $query.='Authorization: Basic '.MIME::Base64::encode(shift,'').$nl;
+    } elsif ($arg == $REFERER) {
+      my($referer)=shift;
+      $query.='Referer: '.$referer.$nl if $referer;
+    } elsif ($arg == $SAVEBIN) {
+      $saveto=shift;
+    } elsif ($arg == $ACCEPT) {
+      $accept.='Accept: '.(shift).$nl;
+    } elsif ($arg == $NOUSER) {
+      $nouser=1;
+    } elsif ($arg == $FREEHEAD) {
+      $query.=(shift).$nl;
+    } else {
+      warn "Unknown http query opcode: $arg\n";
+    } 
+    # Insert the last parts of the query:
+  }
+  
+  $query.='Host: '.$req_o->netloc.$nl;
+  $query.='From: '.$from.$nl unless $nouser;
+
+  $accept='Accept: */*'.$nl unless $accept;
+
+  if ($proxyport) {
+    # Use proxy instead of originserver
+    $host=$proxyserver;
+    $port=$proxyport;
+
+    # Add authentication stuff to query
+    if ($proxyuser) {
+      # Demand-load MIME::Base64
+      if (!defined(&MIME::Base64::encode)) {
+	eval "use MIME::Base64;";
+	die "w3http: Could not load MIME::Base64 module necessary for authentication\n"
+	  unless defined(&MIME::Base64::encode);
+      }
+      
+      $query.='Proxy-Authorization: Basic '.
+	MIME::Base64::encode($proxyuser.':'.$proxypasswd);
+
+      print STDERR "\nProxyuser: [$proxyuser]\nProxypasswd: [$proxypasswd]\n"
+	if $debug>=2;
+    }
+  }
+  
+  $query.='User-Agent: '.$agent.$nl.$accept.$nl;
+  
+  # If we're using proxy then set up things...
+  print STDERR "\nQUERY:\n",$query,"---\n" if $debug>=2;
+
+  # win32 fix: this should be added in case of troubles with
+  # gethostbyname. possible reason: nameserver down?
+  if ($host =~ /^\d+(\.\d+){3}$/) {
+    # in case gethostbyname will not work ... ;-)
+    $address{$host} = pack 'C4', (split /\./, $host);
+  }
+  
+  # Find out who to ask, check if we know already
+  if (exists($address{$host})) {
+    # We know
+    $thataddr=$address{$host};
+  } else {
+    # Cache miss, get and remember.
+    (my $fqdn, undef, undef, undef, $thataddr) = gethostbyname($host);
+    # Hostname lookup failure?  Cache even misses.
+    if (defined($fqdn)) {
+      print STDERR "Lookup of $host:\nFQDN: $fqdn\n"
+	if $debug;
+      $address{$host}=$thataddr;
+      $address{$fqdn}=$thataddr if $fqdn ne $host;
+    } else {
+      $thataddr=$address{$host}=undef;
+    }
+  }    
+
+  # Check if lookup failure, return
+  if (!defined($thataddr)) {
+    $restext='Host lookup failure';
+    return;
+  }
+
+  $port=80 unless defined($port) && $port;
+
+  # When connected we might receive SIGPIPE.  I'm not sure if the
+  # default behaviour of dying is beneficial in that case.  If we get
+  # alarm a timeout has expired.
+  $savPIPE = $SIG{'PIPE'};
+  $savALRM = $SIG{'ALRM'};
+
+  $chime=0;			# There has been no alarm yet
+  $SIG{'ALRM'} = \&timeout;
+  $SIG{'PIPE'} = \&ignore;
+
+  # Close the socket, just in case, and ignore error returns
+  close(FS);
+  
+  socket(FS, AF_INET, SOCK_STREAM, $proto) or return &oserror;
+  warn "Got my socks on\n" if $debug;
+  
+  my $paddr = sockaddr_in($port, $thataddr);
+  connect(FS, $paddr) or return &oserror;
+  warn "Connected\n" if $debug;
+  
+  # Arrange timeout
+  alarm($timeout) if $hasAlarm;
+  
+  # We have, in fact, received SIGPIPE on this line:
+  send(FS,$query,0) or return &oserror;
+
+  if ($chime) {
+    $result=100;
+    $restext='timeout sending query';
+    return &resetsign;
+  }
+  
+  $header='';
+  $document='';
+  $inp=' 'x$buflen;
+  $doclen=$chime=$plaintext=$plaintexthtml=$save=0;
+
+  # Breaks some M$ ISS servers:
+  # shutdown(FS,1);  # Half-close socket, sending now not allowed
+  
+  print STDERR ", receiving header" if $verbose>0;
+  
+  # Retrive HTTP response HEADER.  Why do I use recv and not <FS>?
+  # Because then the timeout can work correctly!
+  while (1) {
+    # Set up alarm to ensure recv returns within a reasonable timeframe
+    alarm($timeout) if $hasAlarm;
+    $err = recv(FS,$inp,$buflen,0);
+    # recv returned, cancel alarm.
+    alarm(0) if $hasAlarm;
+    
+    # If there has been a timeout, then we quit now.  The recv man page
+    # does not seem to allow recv to return the bytes received up to
+    # the timeout.
+    if ($chime) {
+      $result=100;  
+      $restext='timeout fetching document';
+      $!=0;
+      if ($save) {
+	unlink($tmpf) || 
+	  warn "Could not unlink $tmpf: $!\n";
+      }
+      return &resetsign;
+    }
+    
+    # recv returnes the undefined value on error
+    if (!defined($err)) {
+      warn "Error in recv: $!\n";
+      last;
+    }
+    
+    $linp=length($inp);
+    
+    # If the returned input was 0 in length then we've gotten to the 
+    # end of the response.
+    last unless $linp;
+    
+    # Accounting
+    $xfbytes += $linp;
+    $doclen += $linp;
+    
+    # Accumulate input
+    $header.=$inp;
+
+    # eof(SOCKET) has strange semantics it seems
+    # last if eof(FS);
+    
+    # Check if header is complete
+    last if ($header =~ m/(\r?\n\r?\n)/);
+  }
+  
+  if (length($header)==0) {
+    $restext='the HTTP reply header is empty!';
+    return &resetsign;
+  }
+  
+  if ($header =~ m/(\r?\n\r?\n)/) {
+    $header=$`;
+    $document=$';
+  } else {
+    $header=$document;
+  }
+  
+  # Adjust accounting
+  $headb = length($header)+length($1);
+  $headbytes += $headb;
+  $xfbytes -= $headb;
+  $doclen -= $headb;
+  
+  # Pick headers to pieces
+  ($result,$restext,%headval)=&analyze_header($header);
+
+  print STDERR "REPLY:\n",$header,"\n---\n" if $debug>=2;
+
+  # Check if the document is a non-encoded text document. The contents
+  # could be (x-)?compress or (x-)gzip coded (compressed in other
+  # words).
+  
+  $plaintext=defined($headval{'CONTENT-TYPE'}) &&
+    (substr($headval{'CONTENT-TYPE'},0,5) eq 'text/' || 0) &&
+      !defined($headval{'content-encoding'});
+  $plaintexthtml=$plaintext && 
+    ($headval{'CONTENT-TYPE'} eq 'text/html');
+  
+  if ($result==200) {
+    
+    # Save this to a file, or not?  Never save html files.
+    if ($saveto && !$plaintexthtml) {
+      # We're going to save this document directly into a file.  This
+      # stresses the VM less when getting the large binares so often
+      # found at cool sites.
+      $save=1;
+
+      # Find a temporary filename
+      $tmpf=url "file:$saveto";
+      $tmpf->basename($tmpfile);
+      $tmpf=$tmpf->unix_path;
+      
+      # Find suitable final filename, one with no URL escapes
+      $saveto=(url "file:$saveto")->unix_path;
+
+      # If output to stdout then send it directly there rather than
+      # using disk unnecesarily.
+      $tmpf='-' if ($saveto eq '-');
+
+      # If output is nulldevice (running -f), use it also for tmpfile,
+      # since it would otherwise try to create it in /dev under unix.
+      $tmpf=$main::nulldevice if ($saveto eq $main::nulldevice);
+      
+      warn "USING TMPFILE: $tmpf\n" if $debug;
+      
+      open(SAVE,">$tmpf") || 
+	die "Could not open tmp file: $tmpf: $!\n";
+      binmode SAVE;		# It's a binary file...
+    }
+    
+    if ($verbose>0) {
+      print STDERR ", document";
+      print STDERR "->disk" if $save;
+    }
+    
+    # Now retrive document itself.  Se comments in header loop
+    $start=time;
+    $wantbytes = defined($headval{'content-length'})?
+      $headval{'content-length'}:0;
+    
+    $ldoc=length($document);
+    
+    while (1) {
+      alarm($timeout) if $hasAlarm;
+      recv(FS,$inp,$buflen,0);
+      alarm(0) if $hasAlarm;
+      
+      if ($chime) {
+	$result=100;
+	$restext='timeout fetching document';
+	$!=0;
+	if ($save) {
+	  unlink($tmpf) || 
+	    warn "Could not unlink $tmpf: $!\n";
+	}
+	return &resetsign;
+      }
+      
+      $linp=length($inp);
+      
+      last unless $linp || $ldoc;
+      $ldoc = 0;
+      
+      $xfbytes += $linp;
+      $doclen += $linp;
+      
+      if ($verbose>0 && time-$start>5) {
+	# Write progress info ... 
+	if ($wantbytes) {
+	  $progress = sprintf " %3d%%", $doclen/$wantbytes*100;
+	} else {
+	  $progress = sprintf " %d", $doclen;
+	}
+	print STDERR $progress, "\ch"x(length($progress));
+	# ...every 5 seconds
+	$start=time;
+      }
+      
+      $document.=$inp;
+      
+      if ($save) {
+	$err = print SAVE $document;
+	die "Error writing $tmpf: $!\n" unless $err;
+	$document='';
+      }
+
+      # The eof test seems to work very oddly for sockets.
+      # last if eof(FS);
+    }
+
+    close(FS);  # Close socket completely
+    
+    print STDERR "DOCUMENT:\n----\n",$document,"\n----\n" if $debug>=255;
+  
+    if ($wantbytes &&
+	$wantbytes != $doclen) {
+      $result=100;
+      $restext='transfer error; too many bytes in document';
+      $restext='document was incomplete' if ($wantbytes > $doclen) ;
+      print STDERR "SHORT DOCUMENT" if $debug>=16;
+      if ($save) {
+	unlink($tmpf) || warn "Could not unlink $tmpf: $!\n";
+      }
+      return &resetsign;
+    }
+    
+    # warn "XFB: $xfbytes, DL: $doclen\n";
+    if ($save) {
+      close(SAVE);
+      &main::movefile($tmpf,$saveto);
+    }
+    
+    # If this is a non-encoded text file and we're supposed to convert
+    # foreign newlines then we do it. It would be faster to do this
+    # with each chunk of input in the input loop, but this gives us
+    # two problems:
+    # - A \r\n newline could be split into two chunks.  Thus escaping
+    #   newline conversion.
+    # - It messes up the received bytes accounting rather badly.
+    #
+    # This used to be a test for $plaintext, the problem is that too
+    # many documents were typed as text/plain and so we corrupted
+    # binary files. This is bad. So now we're more paranoid about it:
+    # Only HTML gets converted.
+    if ($convert && $plaintexthtml) {
+      # Change non unix newlines to unix newlines. bare \r is known
+      # from macintosh (they hadta be different didn't they?), \r\n is
+      # known as 'network format' and from numerous systems, among
+      # them ms-dos.
+      $document =~ s~\r~\n~g unless $document =~ s~\r\n~\n~g;
+      warn "Newlines converted(?)\n" if $debug;
+    }
+    
+  }				# if $result == 200
+  
+  &resetsign;
+  return 1;
+}
+
+
+sub analyze_header {
+  my($header)=@_;
+  my($result,$restext,%headval,$hdln,$key,$value);
+  
+  # Summary of the http spec on headers (with my comments):
+  # - Each header line ends in CRLF (or just LF, or maybe even just CR,
+  #   anyways, it's easier if all is LF).
+  $header =~ s/\r/\n/mg unless $header =~ s/\r\n/\n/mg;
+  # - If a line starts with space then it's a continuation of the previous
+  #   line (these I fold into one line).
+  $header =~ s/\n\s/ /mg;
+  # - The header field names are case insensitive (so I convert them to
+  #   lowercase)
+  # - A field may appear twice, that is equivalent to listing the values
+  #   in a comma separated list (so I fold them into a comma separated list)n
+  # - The field name and the field value are separated by ': '
+  ($result,$restext) = $header =~ m~^HTTP/\d\.\d (\d\d\d) (.*)~;
+  # Shave off http result code from the header
+  $header =~ s~^.*\n~~;
+  
+  warn "Header:\n$header\n---\n" if $debug>=3;
+  
+  warn "Result: $result, Text: $restext\n" if $debug>=2;
+  
+  %headval=();
+  
+  foreach $hdln (split(/\r?\n/m,$header)) {
+    ($key,$value)=split(': ',$hdln,2);
+    $key="\L$key";
+    # Strip leading&trailing space off the reply, some servers use
+    # copious space after.
+    $value =~ s/^\s+|\s+$//g;
+    print STDERR "K: '$key', V: '$value'\n" if $debug>=2;
+    if (defined($headval{$key})) {
+      $headval{$key}.=", ".$value;
+    } else {
+      $headval{$key}=$value;
+    }
+  }
+
+  # See if there are any type parameters in the content-type header
+  # and if so remove them.
+  if (defined($headval{'content-type'})) {
+    my $val=$headval{'content-type'};
+    ($val,undef)=split(';',$val,2) if ($val =~ /;/);
+    $headval{'CONTENT-TYPE'}=$val;
+  }
+  
+  return ($result,$restext,%headval);
+}
+
+
+sub last_modified {
+  # will return the last modified time for a local file as a HTTP
+  # timestamp.
+  
+  my(@tmp) = stat($_[0]);	# file doesn't exist ok to fetch
+
+  # FAT file systems strip the LSB of the file time.  Add it back in
+  # here before asking the server about a modified file.  The only way
+  # this can fail is if the newer server file was saved one second
+  # after the first version (very unlikely).  This isn't needed for
+  # NTFS file systems, but there is no good portable Perl way to
+  # determine the file system type.
+  $tmp[9] = $tmp[9] | 1 if ( $main::win32 );
+
+  # now we got the last modified in a 32 bit integer.  time to convert
+  # it and return
+  return time2str($tmp[9]);
+}
+
+
+sub timeout {
+  # Set timeout flag.  The using procedure has to set other result codes.
+  $chime=1;			# When this is 1 then the alarm has gone off
+  print STDERR "TIMEOUT!!!!\n" if $debug>=16;
+}
+
+
+sub ignore {
+  warn "I got SIGPIPE, ignoring it...\n";
+}
+
+
+sub resetsign {
+  return 0 if !defined($savALRM);
+  $SIG{'ALRM'}=$savALRM;
+  undef $savALRM;
+#  $SIG{'PIPE'}=$savPIPE;
+  return 0;
+}
+
+
+sub oserror {
+  
+  resetsign;
+
+  $result=98;
+  $restext='w3http: OS error';
+  return 0;
+
+}
+
+
+1;
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3mfix.PL
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3mfix.PL	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3mfix.PL	(revision 16571)
@@ -0,0 +1,1070 @@
+# -*-perl-*-
+
+use Config;
+
+&read_makefile;
+$fullperl = resolve_make_var('FULLPERL') || $Config{'perlpath'};
+$islib = resolve_make_var('INSTALLSITELIB');
+
+$name = $0;
+$name =~ s~^.*/~~;
+$name =~ s~.PL$~~;
+
+open(OUT,"> $name") || 
+  die "Could open $name for writing: $!\n";
+
+print "writing $name\n";
+
+while (<DATA>) {
+  if (m~^\#!/.*/perl.*$~o) {
+    # This substitutes the path perl was installed at on this system
+    # _and_ removed any (-w) options.
+    print OUT "#!",$fullperl,$1,"\n";
+    next;
+  }
+  if (/^use lib/o) {
+    # This substitutes the actuall library install path
+    print OUT "use lib '$islib';\n";
+    next;
+  }
+  print OUT;
+}
+
+close(OUT);
+
+# Make it executable too, and writeable
+chmod 0755, $name;
+
+#### The library
+
+sub resolve_make_var ($) {
+
+  my($var) = shift @_;
+  my($val) = $make{$var};
+
+#  print "Resolving: ",$var,"=",$val,"\n";
+  
+  while ($val =~ s~\$\((\S+)\)~$make{$1}~g) {}
+#  print "Resolved: $var: $make{$var} -> $val\n";
+  $val;
+}
+
+
+sub read_makefile {
+
+  open(MAKEFILE, 'Makefile') || 
+    die "Could not open Makefile for reading: $!\n";
+
+  while (<MAKEFILE>) {
+    chomp;
+    next unless m/^([A-Z]+)\s*=\s*(\S+)$/;
+    $make{$1}=$2;
+#    print "Makevar: $1 = $2\n";
+  }
+
+  close(MAKEFILE)
+}
+
+__END__
+#!/local/bin/perl5 -w
+# Perl 5.002 or later.  w3mir is mostly tested with perl 5.004
+#
+# You might want to change or comment out this:
+use lib '/hom/janl/lib/perl';
+#
+# Can perform the following fixes:
+# - Rewrite redirected to URLs
+# - change .../ into .../index.html (or .../Welcome.html)
+# - change external links to point to some helpfull .html file ---- NOT IMPLEMENTED
+# - change links to documents not retrived to point to some helpfull
+#   .html file --- NOT IMPLEMENTED
+# - After adding a 'Also' directive we can edit the urls pointing to within
+#   the new space of the retrival scope, making the pointers consistent.
+
+# Method: 
+# 1 Gather list of all URLs to be rewritten:
+#   - Redirects: Just read the .redirs file
+#   - .../ into .../index.html: All can be found in the .referers file
+#     Remember to rewrite missing / redirects too...
+#   - external links: in the .referers file too
+#   - non-retrived documents: What files should be here (according to
+#	.referers file) but are not?
+# 2 Gather list of all documents needing editing
+# 3 Edit them
+#
+# 09/05/98 janl		- Only rewrite .../ to .../$indexname if the attribute
+#			  does not refer to a directory. -> 0.6.2
+# 12/05/98 janl		- Use ->local_path to determine filename -> 0.6.3
+# 22/05/98 janl		- .../#foo was not being rewritten to 
+#			  .../$indexname#foo -> 0.6.4
+#
+require 5.002;
+
+use vars qw($win32);
+
+# To figure out what kind of system this is
+BEGIN {
+  use Config;
+  $win32 = ( $Config{'osname'} eq 'MSWin32' ); 
+}
+
+use Carp;
+use htmlop;
+use URI::URL;
+use URI::Escape;
+
+use strict;
+
+my $VERSION;
+$VERSION='0.6.5';
+
+my $debug=0;			# Not debugging
+my $verbose=0;
+
+my $indexname='index.html';
+my $chdirto='';			# Place to chdir to after reading
+                                # config file
+
+my $infoloss=0;			# 1 if any URL translations (which
+                                # cause information loss) are in
+                                # effect.  If this is true we use the
+                                # SAVEURL operation.  What to get, and
+                                # not.  Text of user supplied
+                                # fetch/ignore rules
+
+my $doindex=1;			# append $indexname to /$ ?
+
+my $editthis='';		# Edit references matching this expression.
+
+my $files=0;			# How many files have I edited?
+my $rc='';
+
+my $rule_text="# User defined fetch/ignore rules\n";
+# Code ref to the rule procedure
+my $rule_code;
+
+# Code to prefix and postfix the generated code.  Prefix should make
+# $_ contain the url to match.  Postfix should return 1, the default
+# is to get the url/file.
+my $rule_prefix='$rule_code = sub { local($_) = shift;'."\n";
+my $rule_postfix=' return 1; } ';
+
+# Scope tests generated by URL/Also directives in cfg. The scope code
+# is just like the rule code, but used for program generated
+# fetch/ignore rules related to multiscope retrival.
+my $scope_fetch="# Automatic fetch rules for multiscope retrival\n";
+my $scope_ignore="# Automatic ignore rules for multiscope retrival\n";
+my $scope_code;
+
+my $scope_prefix='$scope_code = sub { local($_) = shift;'."\n";
+my $scope_postfix=' return 0; } ';
+
+# Function to apply to urls, se rule comments.
+my $user_apply_code;	# User specified apply code
+my $apply_code;		# w3mirs apply code
+my $apply_prefix='$apply_code = sub { local($_) = @_;'."\n";
+my $apply_lc=' $_ = lc $_; ';
+my $apply_postfix=' return $_; } ';
+my @user_apply;		# List of users apply rules.
+my @internal_apply;	# List of w3mirs apply rules.
+
+
+my $iinline='';			# inline RE code to make RE caseinsensitive 
+my $ipost='';			# RE postfix to make it caseinsensitive
+my $lc=0;			# Convert urls/filenames to lowercase?
+my $abs=0;			# Absolutify URLs?
+my $fixrc='';			# Name of w3mfix config file
+my $fixup=0;			# Do things needed to run fixup
+my $r=0;			# Recurse? no recursion = absolutify links
+my %rum_referers=();		# Array of referers, key: rum_url
+my %rum_redirected=();		# Array of redirected url: key: original url
+my %lf_edited=();		# Edited this file yet?
+my $list;			# List url on STDOUT?
+
+my %stat=();			# stat($lf_url): 'd' for dir, 'f' for others
+
+# ######################### Libwww-perl addons:
+
+sub URI::URL::_generic::unix_path {
+  my $self = (shift)->clone;
+
+  $self->frag(undef);
+  $self->scheme("file");
+  $self->unix_path;
+}
+
+
+sub URI::URL::_generic::basename {
+  my $self = shift;
+  my @p = $self->path_components;
+  my $old = $p[-1];
+  if (@_) {
+    splice(@p, -1, 1, shift);
+    $self->path_components(@p)
+  }
+  $old;
+}
+
+
+sub URI::URL::_generic::path_components {
+    my $self = shift;
+    my $old = $self->{'path'};
+    $old = '' unless defined $old;
+    $old = "/$old" if $old !~ m|^/| && defined $self->{'netloc'};
+    if (@_) {
+	$self->_elem('path',
+		     join("/", map { uri_escape($_,$URI::URL::reserved)
+				   } @_));
+    }
+    map { uri_unescape($_) } split("/", $old, -1);
+}
+
+
+# ######################### Configuration/argument parsing
+
+sub parse_args {
+  my $f;
+  my $i;
+
+  $i=0;
+
+  while ($f=shift) {
+    $i++;
+    # This is a demonstration against Getopts::Long.
+    if ($f =~ s/^-+//) {
+      $verbose=-1,next if $f eq 'q'; 		# Quiet
+      $verbose=1,next if $f eq 'c';		# Chatty
+      die "w3mfix version $VERSION\n" if $f eq 'v';	# Version
+      die "rtfm\n" if ($f eq 'help' || $f eq 'h' || $f eq '?');
+
+      if ($f eq 'editref') {
+	die "Sorry, can only have one -editref pr. run\n"
+	  if $editthis;
+	$editthis=quotemeta(shift);
+	next;
+      }
+
+      if ($f eq 'd') {	# Debugging level
+	$f=shift;
+	unless (($debug = $f) > 0) {
+	  die "w3mfix: debug level must be a number greater than zero.\n";
+	}
+	next;
+      }
+
+      # Those were all the options...
+      warn "w3mfix: Unknown option: -$f.  Use -h for usage info.\n";
+      exit(1);
+    } else {
+      # If we get this far then ... it's a configuration file name:
+      $rc = $f;
+      die "w3mfix: Got a non-option argument that wasn't the name of a\n".
+	"(configuration) file either\n"
+	  unless -f $f;
+    }
+  }
+}
+
+
+sub parse_cfg_file {
+  # Read the configuration file.  Aborts on errors.
+  # Ignores w3mir options w3mfix does not need itself.
+
+  my ( $file ) = @_ ;
+  my ($key, $value, $authserver,$authrealm,$authuser,$authpasswd);
+  my $i;
+
+  die "w3mfix: config file $file is not a file.\n" unless -f $file;
+  open(CFGF, $file) || die "Could not open config file $file: $!\n";
+
+  # print STDERR "Reading $file\n";
+
+  $i=0;
+
+  while (<CFGF>) {
+    # Trim off various junk
+    chomp;
+    s/^#.*//;
+    s/^\s+|\s$//g;
+    # Anything left?
+    next if $_ eq '';
+    # Examine remains
+    $i++;
+    ($key, $value) = split(/\s*:\s*/,$_,2);
+    $key = lc $key;
+
+    # These are no-ops in w3mfix
+    next if ( $key eq 'initial-referer' );
+    next if ( $key eq 'header' );
+    next if ( $key eq 'pause' );
+    next if ( $key eq 'retry-pause' );
+    next if ( $key eq 'retries' );
+    next if ( $key eq 'robot-rules' );
+    next if ( $key eq 'remove-nomirror' );
+    next if ( $key eq 'file-disposition' );
+    next if ( $key eq 'http-proxy' );
+    next if ( $key eq 'proxy-options' );
+    next if ( $key eq 'auth-domain' );
+    next if ( $key eq 'auth-user' );
+    next if ( $key eq 'auth-passwd' );
+    next if ( $key eq 'disable-headers' );
+    next if ( $key eq 'agent' );
+
+    $debug=numeric($value),next if ( $key eq 'debug' );
+    umask(numeric($value)),next if ( $key eq 'umask' );
+    $indexname=$value,next if ($key eq 'index-name');
+    $verbose=nway($value,'quiet','brief','chatty')-1,next
+      if ( $key eq 'verbosity' );
+
+    if ( $key eq 'cd' ) {
+      $chdirto=$value;
+      next;
+    }
+
+    if ($key eq 'url') {
+      my ($rum_url_o,$lf_dir,$rum_reurl,$rum_rebase);
+
+      # A two argument URL: line?
+      if ($value =~ m/^(.+)\s+(.+)/i) {
+	# Two arguments.
+	$rum_url_o=url $1;
+	# The last is a directory, it must end in /
+	$lf_dir=$2;
+	$lf_dir.='/' unless $lf_dir =~ m~/$~;
+
+	# The first is a URL, make it more canonical, find the base.
+	# The namespace confusion in this section is correct.(??)
+	$rum_rebase = quotemeta( ($rum_url_o->as_string =~ m~^(.*/)~)[0] );
+
+	# print "URL: ",$rum_url_o->as_string,"\n";
+	# print "Base: $rum_rebase\n";
+
+	# Translate from rum space to lf space:
+	push(@internal_apply,"s/^".$rum_rebase."/".quotemeta($lf_dir)."/");
+
+	# That translation could lead to information loss.
+	$infoloss=1;
+
+	# Fetch rules tests the rum_url_o->as_string.  Fetch whatever
+	# matches the base.
+	$scope_fetch.="return 1 if m/^".$rum_rebase."/".$ipost.";\n";
+
+	# Ignore whatever did not match the base.
+	$scope_ignore.="return 0 if m/^".
+	  quotemeta("http://".$rum_url_o->netloc."/")."/".$ipost.";\n";
+
+      } else {
+	# $rum_url_o=root_quene($value);
+
+	$rum_url_o=url $value;
+
+	$rum_rebase = quotemeta( ($rum_url_o->as_string =~ m~^(.*/)~)[0] );
+
+	# Translate from rum space to lf space:
+	push(@internal_apply,"s/^".$rum_rebase."//");
+
+	$scope_fetch.="return 1 if m/^".$rum_rebase."/".$ipost.";\n";
+	$scope_ignore.="return 0 if m/^".
+	  quotemeta("http://".$rum_url_o->netloc."/")."/".$ipost.";\n";
+      }
+      next;
+    }
+
+    if ($key eq 'also' || $key eq 'also-quene') {
+      if ($value =~ m/^(.+)\s+(.+)/i) {
+	my ($rum_url_o,$lf_dir,$rum_reurl,$rum_rebase);
+	# Two arguments.
+	$rum_url_o=url $1;
+	$rum_url_o->host(lc $rum_url_o->host);
+	# The last is a directory, it must end in /
+	$lf_dir=$2;
+	$lf_dir.='/' unless $lf_dir =~ m~/$~;
+
+	# The first is a URL, find the base
+	$rum_rebase = quotemeta( ($rum_url_o->as_string =~ m~^(.*/)~)[0] );
+
+	# Ok, now we can transform and select stuff the right way
+	push(@internal_apply,"s/^".$rum_rebase."/".quotemeta($lf_dir)."/");
+	$infoloss=1;
+
+	# Fetch rules tests the rum_url_o->as_string.  Fetch whatever
+	# matches the base.
+	$scope_fetch.="return 1 if m/^".$rum_rebase."/".$ipost.";\n";
+
+	# Ignore whatever did not match the base.  This cures problem
+	# with '..' from base in in rum space pointing within the the
+	# scope in ra space.  We introduced a extra level (or more) of
+	# directories with the apply above.  Must do same with 'Also:'
+	# directives.
+	$scope_ignore.="return 0 if m/^".
+	  quotemeta("http://".$rum_url_o->netloc."/")."/".$ipost.";\n";
+      } else {
+	die "Also: requires 2 arguments\n";
+      }
+      next;
+    }
+
+    if ($key eq 'quene') {
+      # root_quene($value);
+      next;
+    }
+
+    if ($key eq 'ignore-re' || $key eq 'fetch-re') {
+      # Check that it's a re, better that I am strict than for perl to
+      # make compilation errors.
+      unless ($value =~ /^m(.).*\1[gimosx]*$/) {
+	print STDERR "w3mfix: $value is not a recognized regular expression\n";
+	exit 1;
+      }
+    }
+
+    if ($key eq 'fetch' || $key eq 'fetch-re') {
+      my $expr=$value;
+      $expr = wild_re($expr).$ipost if ($key eq 'fetch');
+      $rule_text.=' return 1 if '.$expr.";\n";
+      next;
+    }
+
+    if ($key eq 'ignore' || $key eq 'ignore-re') {
+      my $expr=$value;
+      $expr = wild_re($expr).$ipost if ($key eq 'ignore');
+      $rule_text.=' return 0 if '.$expr.";\n";
+      next;
+    }
+
+
+    if ($key eq 'apply') {
+      unless ($value =~ /^s(.).*\1.*\1[gimosxe]*$/) {
+	print STDERR
+	  "w3mfix: '$value' is not a recognized regular expression\n";
+	exit 1;
+      }
+      push(@user_apply,$value) ;
+      $infoloss=1;
+      next;
+    }
+
+    if ($key eq 'options') {
+      
+      my($val,$nval);
+      foreach $val (split(/\s*,\s*/,lc $value)) {
+	if ($i==1) {
+	  $nval=nway($val,'recurse','no-date-check','only-nonexistent',
+		     'list-urls','lowercase','remove','batch','read-urls',
+		     'abs');
+	  $r=1,next if $nval==0;
+	  next if $nval==1;
+	  next if $nval==2;
+	  $list=1,next if $nval==3;
+	  if ($nval==4) {
+	    $lc=1;
+	    $iinline=($lc?"(?i)":"");
+	    $ipost=($lc?"i":"");
+	    next ;
+	  }
+	  next if $nval==5;
+	  next if $nval==6;
+	  next if $nval==7;
+	  $abs=1,next if $nval==8;
+        } else {
+	  die "w3mfix: options must be the first directive in the config file.\n";
+	}
+      }
+    }
+
+    if ($key eq 'fixup') {
+
+#      chomp($fixrc=`pwd` || '.');
+#      $fixrc.="/$file";
+#      warn "Fixrc: $fixrc\n";
+#      $fixup=1;
+
+      my($val,$nval);
+      foreach $val (split(/\s*,\s*/,lc $value)) {
+	$nval=nway($val,'on','run','noindex');
+	next if $nval==0;
+	next if $nval==1;
+	$doindex=0 if $nval==2;
+	# Ignore everyting else
+      }
+    }
+
+  }
+  close(CFGF);
+}
+
+sub wild_re {
+  # Here we translate unix wildcard subset to to perlre
+  local($_) = shift;
+  s#\*#\.\*#;
+  s#\?#\.#;
+  s#([\/\(\)\\\|\{\}\+)\$\^])#\\$1#g;
+  return $_ = '/'.$_.'/';
+}
+
+
+sub numeric {
+  # Check if argument is numeric?
+  my ( $number ) = @_ ;
+  return oct($number) if ($number =~ /\d+/ || $number =~ /\d+.\d+/);
+  die "Expected a number, got \"$number\"\n";
+}
+
+
+sub boolean {
+  my ( $boolean ) = @_ ;
+
+  $boolean = lc $boolean;
+
+  return 0 if ($boolean eq 'false' || $boolean eq 'off' || $boolean eq '0');
+  return 1 if ($boolean eq 'true' || $boolean eq 'on' || $boolean eq '1');
+  die "Expected a boolean, got \"$boolean\"\n";
+}
+
+
+sub nway {
+  my ( $value ) = shift;
+  my ( @values ) = @_;
+  my ( $val ) = 0;
+
+  $value = lc $value;
+  while (@_) {
+    return $val if $value eq shift;
+    $val++;
+  }
+  die "Expected one of ".join(", ",@values).", got \"$value\"\n";
+}
+
+
+sub stat {
+
+  my $file = shift;
+
+  if (exists($stat{$file})) {
+    print STDERR "++Cache hit: $file\n" if $debug;
+  } else {
+    stat($file);
+    if (-e _) {
+      $stat{$file}=(-d _)?'d':'f';
+    } else {
+      $stat{$file}='n';
+    }
+    print STDERR "--Cache miss: $file\n" if $debug;
+  }
+  return $stat{$file};
+}
+
+# ######################## Read 'state' files ##############################
+
+sub read_state {
+
+  my $reffile='.referers';
+  my $refered;
+  my @referers;
+
+  $reffile="referers" if $win32;
+
+  print STDERR "reading $reffile\n" if $verbose>0;
+  open(REFERERS,"< $reffile") ||
+    die "Could not open $reffile for reading: $!\n";
+
+  while (<REFERERS>) {
+    chomp;
+    ($refered,undef,@referers) = split(/\s+/);
+    $rum_referers{$refered}= [ @referers ];
+    # print STDERR $refered," <- ",join(' and ',@referers),"\n";
+  }
+
+  close(REFERERS);
+
+
+  # Read redirection report
+
+  my $redirfile='.redirs';
+  my $wrong;
+  my $right;
+  my $tmp;
+
+  $redirfile="redirs" if $win32;
+
+  print STDERR "reading $redirfile\n" if $verbose>0;
+  open(REDIRS,"< $redirfile") ||
+    die "Could not open $redirfile for reading: $!\n";
+
+  while (<REDIRS>) {
+    chomp;
+    ($wrong,undef,$right) = split(/\s+/);
+
+    $rum_redirected{$wrong}=$right;
+  }
+
+  close(REDIRS);
+}
+
+# ######################### Process every single tag ########################
+
+sub process_tag {
+  # Process a tag in html file
+  my $lf_referer = shift;
+  my $base_url = shift;
+  my $tag_name = shift;
+  my $url_attrs = shift;
+
+  # Retrun quickly if no URL attributes
+  return unless defined($url_attrs);
+
+  my $attrs = shift;
+
+  # Information loss through apply or processing in this procedure?
+  my $il = $infoloss; 
+  my $redirs;
+  my $stat;
+
+  my $rum_url;	# The absolute URL
+  my $lf_url;	# The local filesystem url
+  my $lf_url_o; # ... and it's object
+  my $key;
+  my $orig_rum_url;
+#  my $debug = 1;
+
+#  print STDERR "\nProcess Tag: $tag_name, URL attributes: ", join(', ',@{$url_attrs}),"\nOrigin:",$base_url,"\n"; # if $debug>2;
+
+  substr($lf_referer,0,0)='./' unless substr($lf_referer,0,1) eq '/';
+
+  foreach $key (@{$url_attrs}) {
+    if (defined($$attrs{$key})) {
+      $orig_rum_url=$rum_url=$$attrs{$key};
+
+      print STDERR "\n$key = $rum_url\n" if $debug;
+
+      # Apply redirects:
+      $redirs=0;
+      if (exists($rum_redirected{$rum_url})) {
+	$il=1;
+	while (exists($rum_redirected{$rum_url})) {
+	  die "Too many redirects in a row\n" if $redirs++>32;
+	  print STDERR "$rum_url -> ".$rum_redirected{$rum_url}."\n"
+	    if $debug;
+	  $rum_url=$rum_redirected{$rum_url};
+	}
+      }
+
+      # Apply program/user apply rules
+      $lf_url=apply($rum_url);
+
+      if (defined($lf_url)) {
+	# Apply directory/file check here
+	$stat=&stat($lf_url);
+
+	if ($stat eq 'f' && $lf_url =~ m~/$~) {
+	  # It's a file, remove trailing /
+	  print STDERR "****** File / fixup of $lf_url\n" if $debug;
+	  $il=1;
+	  substr($lf_url,length($lf_url)) = '';
+	} elsif ($stat eq 'd' && !($lf_url =~ m~/$~) ) {
+	  # It's a directory, add a trailing /
+	  print STDERR "****** Directory / fixup of $lf_url\n" if $debug;
+	  $il=1;
+	  $lf_url .= '/';
+	}
+
+	substr($lf_url,0,0)='./' unless substr($lf_url,0,1) eq '/';
+
+	$lf_url_o=url $lf_url;
+	my $tmp=$lf_url_o->clone;
+	$tmp->basename($indexname);
+
+	if ( $doindex && $lf_url_o->basename eq "" && 
+	     &stat($tmp->unix_path) eq 'f' &&
+	     !$htmlop::isdir{$key}) {
+	  $lf_url_o=$tmp;
+	  $il=1;
+	  print STDERR "indexname adjusted to ",$lf_url_o->as_string,"\n"
+	    if $debug;
+	}
+		 
+	# Save new value in the hash, make it a file url to get 'rel' working
+	$lf_url_o->scheme('file');
+	$$attrs{$key} = ($lf_url_o->rel("file:".$lf_referer))->as_string;
+
+	printf STDERR "Saved ".$$attrs{$key}."\n" if $debug;
+
+	# If there is potential information loss save the old value too
+	$$attrs{"W3MIR".$key}=$orig_rum_url if $il;
+
+      } elsif ($redirs>0) {
+	$$attrs{$key}=$rum_url;
+	print STDERR "Saved ".$$attrs{$key}."\n" if $debug;
+	$$attrs{"W3MIR".$key}=$orig_rum_url;
+      }
+    }
+  }
+}
+
+
+# ###################### Edit the URLs in one file... ########################
+
+sub edit_html_file {
+  # Check if it's a html file.  I know this tag is in all html
+  # files, because w3mir put it there.
+
+  my($lf_url)=shift;
+  my($rum_url)=shift;
+
+  # Figure out the filename for our local filesystem.
+  $lf_url.=$indexname if $lf_url =~ m~/$~ || $lf_url eq '';
+
+  # Stuff in need of unquoting?
+  $lf_url = (url "file:$lf_url")->local_path if $lf_url =~ /\%\d\d/;
+
+  if (exists($lf_edited{$lf_url})) {
+    print STDERR "Already edited $lf_url\n" if $debug;
+    return ;
+  }
+
+  $lf_edited{$lf_url}=1;
+
+  my $page;
+  my $newpage;
+  my $read;
+  my $atime;
+  my $mtime;
+
+  # dev  uno   mode  nlink uid   gid   rdev  size  atime mtime
+  (undef,undef,undef,undef,undef,undef,undef,undef,$atime,$mtime)
+    = stat($lf_url);
+
+  if (!open(TMPF,"< $lf_url\n")) {
+    warn "Cannot read $lf_url: $!\n" if $verbose>=0;
+    return;
+  }
+
+  $read=sysread(TMPF,$page,10240,0);
+  close(TMPF);
+
+  if (! $page =~ /<HTML/i) {
+    print STDERR "$lf_url is not html\n" if $verbose>0;
+    return ;
+  }
+
+  $files++;
+
+  print STDERR "w3mfix: $lf_url" if $verbose>=0;
+  
+  print STDERR "$lf_url is a html file\n" if $debug;
+
+  print STDERR " reading" if $verbose>0;
+  
+  open(TMPF,$lf_url) || 
+    die "Could not open $lf_url for reading: $!\n";
+  # read the whole file.
+  {
+    local($/)=undef;
+    $page = <TMPF>;
+  }
+  close(TMPF);
+
+  print STDERR " ",length($page)," bytes" if $verbose>0;
+
+  # It's a html document
+
+  print STDERR ", editing" if $verbose>0;
+
+  ($newpage,undef) = 
+    &htmlop::process($page, # $htmlop::NODOC,
+		     $htmlop::ABS,$rum_url,
+		     $htmlop::USESAVED,'W3MIR',
+		     $htmlop::TAGCALLBACK,\&process_tag,$lf_url);
+
+  open(TMPF,">$lf_url") ||
+    die "\nCould not open $lf_url for writing: $!\n";
+  
+  print STDERR ", saving" if $verbose>0;
+
+  if (length($newpage)) {
+    # This is ODD: close does not seem to flush the buffers.  So we
+    # force the issue.
+    local($|)=1;
+    print TMPF $newpage || 
+      die "\nCould not write to $lf_url (disk full?): $!\n";
+  }
+
+  close(TMPF) || 
+    die "\nCould not close $lf_url after writing: $!\n";
+
+  # Set times back to what they were.
+  utime $atime,$mtime,$lf_url;
+
+  print STDERR ".\n" if $verbose>=0;
+}
+
+# ############################### Scope test
+
+sub want_this {
+  # Find out if we want the url passed.  Just pass it on to the
+  # generated functions.
+  my($rum_url)=shift;
+
+  # Does scope rule want this?
+  return &$scope_code($rum_url) &&
+    # Does user rule want this too?
+    &$rule_code($rum_url) 
+  
+}
+
+# ############################### Apply the apply rules
+
+sub user_apply {
+  # Apply the user apply rules
+  return &$user_apply_code(shift);
+}
+
+
+sub internal_apply {
+  # Apply the w3mir generated apply rules
+  return &$apply_code(shift);
+}
+
+
+sub apply {
+  # Apply the user apply rules.  Then if URL is wanted return result of
+  # w3mir apply rules.  Return the undefined value otherwise.
+
+  my $url = user_apply(shift);
+
+  return undef unless want_this($url);
+
+  internal_apply($url);
+}
+
+# ############################### Decide what URLs to edit
+
+sub edit_as_needed {
+  my $rum_redirected;
+  my $rum_url;
+  my $o_rum_url;
+  my $rum_referer;
+  my $lf_url;
+  my $foo;
+  my $redirs;
+
+  if ($editthis) {
+
+    # Find the URLs that match $edithis
+    foreach $o_rum_url (keys %rum_referers) {
+      # Work on them if they (now) fall within the scope of retrival
+      $redirs=0;
+      $rum_url=$o_rum_url;
+      if (exists($rum_redirected{$o_rum_url})) {
+	while (exists($rum_redirected{$rum_url})) {
+	  die "Too many redirects in a row\n" if $redirs++>32;
+	  print STDERR "$rum_url -> ".$rum_redirected{$rum_url}."\n"
+	    if $debug;
+	  $rum_url=$rum_redirected{$rum_url};
+	}
+      }
+      next unless $rum_url =~ /$editthis/io;
+      next unless want_this($rum_url);
+      # Find and edit the documents containing references to $o_rum_url
+      foreach $rum_referer (@{$rum_referers{$o_rum_url}}) {
+	next if $rum_referer eq '(commandline)';
+	$lf_url=apply($rum_referer);
+	next unless defined($lf_url);
+	edit_html_file($lf_url,$rum_referer);
+      }
+    }
+    
+    # Don't do anything else when invoked thus
+    return;
+  }
+
+  if ($doindex) {
+    # Edit everything that refers anything with trailing /
+    foreach $rum_url (grep(/\/$/,keys %rum_referers)) {
+      foreach $rum_referer (@{$rum_referers{$rum_url}}) {
+	next if $rum_referer eq '(commandline)';
+	$lf_url=apply($rum_referer);
+	next unless defined($lf_url);
+	edit_html_file($lf_url,$rum_referer);
+      }
+    }
+  }
+
+  # Edit only redirected stuff
+  foreach $rum_redirected (keys %rum_redirected) {
+    # print "Redirected $rum_redirected\n";
+    foreach $rum_url (@{$rum_referers{$rum_redirected}}) {
+      # print "- Found in $rum_url\n";
+      $lf_url=apply($rum_url);
+      next unless defined($lf_url);
+      edit_html_file($lf_url,$rum_url);
+    }
+  }
+}
+
+# ############################### 'main'
+
+&parse_args(@ARGV);
+
+if (!$rc) {
+  $rc='.w3mirc';
+  $rc='w3mir.ini' if $win32;
+}
+
+print STDERR "w3mfix: rc file: $rc\n" if $verbose>0;
+
+&parse_cfg_file($rc);
+
+# $chdirto is ignored, w3mir already did it
+
+# Compile second order code
+
+# - The rum scope tests
+my $full_rules=$scope_prefix.$scope_fetch.$scope_ignore.$scope_postfix;
+eval $full_rules;
+
+# warn "Scope rules:\n-------------\n$full_rules\n---------------\n";
+
+die "Program generated rules did not compile.  The code is:\n----\n".
+  $full_rules."\n----\n"
+  if !defined($scope_code);
+
+$full_rules=$rule_prefix.$rule_text.$rule_postfix;
+eval $full_rules;
+
+# warn "User rules:\n-------------\n$full_rules\n---------------\n";
+
+# - The user specified rum tests
+die "Ignore/Fetch rules did not compile.  The code is:\n----\n".
+  $full_rules."\n----\n"
+  if !defined($rule_code);
+
+# - The user specified apply rules
+
+my $full_apply=$apply_prefix.($lc?$apply_lc:'').
+  join($ipost.";\n",@user_apply).(($#user_apply>=0)?$ipost:"").";\n".
+  $apply_postfix;
+eval $full_apply;
+
+die "User apply rules did not compile. The code is:
+----
+".$full_apply."
+----\n" if !defined($apply_code);
+
+$user_apply_code=$apply_code;
+
+# - The w3mir generated apply rules
+
+$full_apply=$apply_prefix.($lc?$apply_lc:'').
+  join($ipost.";\n",@internal_apply).(($#internal_apply>=0)?$ipost:"").";\n".
+  $apply_postfix;
+eval $full_apply;
+
+die "Internal apply rules did not compile.  The code is:
+----
+".$full_apply."
+----\n" if !defined($apply_code);
+
+&read_state;
+
+&edit_as_needed;
+
+exit 0;
+__END__
+# -*- perl -*-  There must be a blank line here:
+
+=head1 NAME
+
+w3mfix - fixup program for w3mir
+
+=head1 SYNOPSIS
+
+B<w3mfix> [B<options>] [B<configuration-file>]
+
+=head1 DESCRIPTION
+
+B<w3mfix> is the companion program to L<w3mir>.  It can be used for
+several URL editing operations usefull in different situations.  
+
+When starting B<w3mfix> will read it's configuration file.  It's name is 
+either .w3mirc (w3mir.ini on win32) or specified on the commandline.
+
+B<w3mfix> is controlled by the 'Fixup' directive of the configuration
+file (described in the L<w3mir> documentation).  B<w3mfix> is also
+affected by 'Index-name' and the one special commandline option it
+knows, as well as the directives/options controlling verbosity and
+debugging information.
+
+=head1 DESCRIPTION
+
+B<w3mfix> can rewrite URLs in these ways:
+
+=over 4
+
+=item * Rewrite URLs that resutled in redirects to point to the place
+redirected to.  This is needed in all cases and will always be fixed
+by B<w3mfix>.
+
+=item * Change URLs ending in .../ into .../index.html (or
+.../Welcome.html).  This is, probably, not needed when the mirror is
+meant do be used with a web-server.  It is usefull for browsing
+directly from disk or CDROM, but in this case it's, most often,
+required.  To disable this specify the I<noindex> option with the
+'Fixup' directive.
+
+The default is to transform URLs ending in .../ into .../index.html.
+
+To controll the name of the index file use the I<Index-name> directive
+as documented in L<w3mir>
+
+=item * Change URL links to documents outside the mirror to point to
+some local document.  Could be usefull if the mirror is destined for a
+CDROM to be used on a unconnected machine.
+
+THIS IS NOT YET IMPLEMENTED
+
+=item * Change URL links to documents that L<w3mir> was
+unable/forbidden to retrive to point to some local document.  Pointing
+these to a nice informative document is probably better than random
+error messages from the browser.
+
+THIS IS NOT YET IMPLEMENTED
+
+=item * And, least, but far from last, B<w3mfix> can be used to
+prepare an established mirror for enlargement.
+
+This feature is used thus: Add the new site or subsite to be mirrored
+on the configuration file (by adding B<Also:> and B<Also-quene:>
+directives).  Then run B<w3mfix> with the B<-editref> option.  When
+the B<-editref> option is specified B<w3mfix> will not perform any
+other editing tasks.
+
+E.g.; To add I<http://www.yahoo.com/Science/Artificial_Life/> to your
+mirror add something like
+
+	  Also: http://www.yahoo.com/Science/Artificial_Life/ yahoo
+
+to the configuration file, then run w3mfix:
+
+	  w3mfix -editref www.yahoo.com/Science/Artificial_Life
+
+This will cause all references to
+I<www.yahoo.com/Science/Artificial_Life> (and under) to be edited so they
+point to within the mirror.  After B<w3mfix> has finished you can run
+L<w3mir> in the normal manner.
+
+=back
+
+=head1 BUGS
+
+Naah.
+
+=head1 SEE ALSO
+
+L<w3mir>
+
+=head1 AUTHORS
+
+B<w3mir>s authors can be reached at I<w3mir-core@usit.uio.no>.
+B<w3mir>s home page is at http://www.math.uio.no/~janl/w3mir/
+
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3mir-HOWTO.html
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3mir-HOWTO.html	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3mir-HOWTO.html	(revision 16571)
@@ -0,0 +1,943 @@
+<!doctype html public "-//W3C//DTD HTML 4.0//EN">
+<html>
+<head>
+<title>W3MIR HOWTO</title>
+<style type="text/css">
+<!--
+  body { background-color: white }
+  h1, h2, h3, b { font-family: sans-serif }
+  .red { color: red }
+-->
+</style>
+<body>
+<h1>W3MIR HOWTO</h1>
+
+<p><b>Corresponding to w3mir version 1.0.2 and above</b>
+
+<p>W3mir is an all purpose WWW copying and mirroring program.  Its
+main focus is copying complete directory structures keeping your copy
+browseable through a web server, or directly off a disk or CDROM if
+you want.  W3mir will fix URLs that are redirected and everything else
+that needs to be fixed to make your copy browseable.  But it also does
+odd jobs, retrieving single documents, batch getting several documents
+and more.  You may tell w3mir not to change anything in the retrieved
+documents.  W3mir has been in development quite a long time so you
+find options to do a lot of things needed when copying things off the
+web.
+
+<p>With w3mir you may copy the entire contents a web server.  Or just
+a directory hierarchy, or several related hierarchies off as many
+servers as you like.  They don't even have to be related.
+
+<p>W3mir supports HTML4, and has partial support for CSS, Java,
+ActiveX and Adobe Acrobat (PDF) files.  And it works on Win32
+machines.
+
+<p><b>Warning:</b> W3mir enables you to copy a lot of things off the
+Web, but remember, the things you retrieve might be copyrighted and
+the copy you make with w3mir might in fact be illegal to make and
+posses.
+
+<hr>
+
+<h2><a name="contents">Contents</a></h2>
+
+<p><a href="#intro">README</a> (You want to read this!  <b
+class="red">Really!</b>)
+
+<p><b>How do I...</b>
+<ol>
+  <li><p><a href="#copy">copy a file?</a>
+  <li><p><a href="#recurse">copy a directory hierarchy?</a>
+  <li><p><a href="#resources">copy the needed resource files from another
+    directory hierarchy?</a>
+  <li><p><a href="#ignore">avoid copying files I don't want or copy only
+    files I want?</a>
+  <li><p><a href="#rm">remove the files that are no longer on the
+    original site from the mirror?</a>
+  <li><p><a href="#depth">limit how deep w3mir will recurse?</a>
+  <li><p><a href="#memory">limit w3mirs memory usage?</a>
+  <li><p><a href="#multi">copy files from multiple sites?</a>
+  <li><p><a href="#alias">copy files from one server with several names?</a>
+  <li><p><a href="#aborted">restart a mirror process after stopping it
+    prematurely?</a>
+  <li><p><a href="#enlarge">enlarge or prune an established mirror?</a>
+  <li><p><a href="#cat">'cat' a file?</a>
+  <li><p><a href="#list">list URLs in a document?</a>
+  <li><p><a href="#robots">disable robots.txt obedience?</a>
+  <li><p><a href="#corrupt">stop w3mir from corrupting binary files?</a>
+  <li><p><a href="#auth">copy a site that wants user-name and password?</a>
+  <li><p><a href="#mauth">access a site that wants several different
+    user-names and passwords?</a>
+  <li><p><a href="#proxy">use a proxy server?</a>
+  <li><p><a href="#pauth">authenticate myself to a proxy server?</a>
+  <li><p><a href="#proxytweak">ensure that the proxy server ...?</a>
+  <li><p><a href="#batchget">batch get files with w3mir?</a>
+  <li><p><a href="#cgi">handle CGI?</a>
+  <li><p><a href="#imap">handle server side image-maps?</a>
+  <li><p><a href="#java">handle Java and ActiveX?</a>
+  <li><p><a href="#script">handle java-script and other script languages?</a>
+  <li><p><a href="#css">handle the other things with 'partial support'?</a>
+  <li><p><a href="#anon">keep my identity secret?</a>
+  <li><p><a href="#ns">pretend that I'm using Netscape, Internet
+    Explorer or Lynx?</a>
+  <li><p><a href="#other">do other things?</a>
+</ol>
+
+<hr>
+
+<h2><a name="intro">README</a></h2>
+
+<p>W3mir may be used in two, main, ways:
+
+<ul>
+  <li><p>To copy something random once.
+  <li><p>To keep a local mirror of some remote site
+</ul>
+
+<p>To copy something random once there is a high likeliness you can
+just start w3mir with some simple options and it will do the job you
+want it to.  Providing that the remote site is not too complex and
+your expectations of the copy aren't high :-) This is what wget, the
+gnu w3 mirroring program, does and is good at.
+
+<h3>Configuration file</h3>
+
+<p>Once you want to keep a copy of a remote site up-to-date over time,
+mirror something with server side image-maps, redirects or
+authentication you have to write a configuration file for w3mir.  This
+is what w3mir is good at, compared to wget.  Writing the file is not
+hard, and there are two example files in the w3mir distribution.  It
+will also be explained here.  The configuration file is typically
+called <tt>.w3mirc</tt> (<tt>w3mir.ini</tt> on win32 machines), and
+can be written with a simple text editor.  It is kept in the top
+directory of the mirror, where w3mir will find it when it starts.
+Please refer to the <a href="#contents">contents</a> for how to handle
+a specific problem with a configuration file.
+
+<hr>
+
+<h2>The answers:</h2>
+
+<hr>
+
+<h3><a name="copy">How do I copy a file?</a></h3>
+
+<p>To copy the top page off www.starwars.com:
+
+<p><tt>w3mir http://www.starwars.com/</tt>
+
+<p><b>Note:</b> it is <em>important</em> that you give the trailing
+slash for server names and directories.
+
+<hr>
+
+<h3><a name="recurse">How to I copy a directory hierarchy?</a></h3>
+
+<p>To copy the entire stuff about episode I from www.starwars.com
+which is stored in <tt>http://www.starwars.com/episode-i/</tt> (I don't
+recommend this, it's quite a lot of data):
+
+<p><tt>w3mir -r http://www.starwars.com/episode-i/</tt>
+
+<p>The corresponding configuration file is simple:
+
+<pre>
+Options: recurse
+URL: http://www.starwars.com/episode-i/
+Fixup: run
+</pre>
+
+<p>The <tt>-r</tt> option makes w3mir recurse down from the starting
+point.  It will only copy all the documents under
+http://www.starwars.com/episode-i/ that it sees referenced from those
+same documents.  W3mir will <em>not</em> retrieve documents from
+http://www.starwars.com/ because it is considered to be 'over' the
+starting point.
+
+<p>The command-line will get you a copy that is definitely browseable
+via a WEB server, and possibly browseable directly from a CDROM or
+hard-disk.  To ensure that it is browseable from CDROM and disk you
+need to use a configuration file with the <tt>Fixup: run</tt> line in.
+It causes w3mir to edit anything that needs editing after the mirror
+has completed, including fixing URLs that caused redirects.  The dirty
+work is done by w3mirs helper program w3mfix.  The directive will
+cause w3mfix to be run each time w3mir completes the mirror.
+
+<p><b>Note:</b> it is <em>important</em> that you give the trailing
+slash after the directory name.  Specifying
+<tt>http://www.starwars.com/episode-i</tt> and
+<tt>http://www.starwars.com/episode-i/</tt> is quite different in
+w3mirs eyes.  In the former case episode-i is considered to be a
+document within the / (top) directory of www.starwars.com and w3mir
+will recurse from /, which is a lot more than you wanted.  In the
+latter case w3mir understands that episode-i is a directory and will
+consider that directory to be the staring point, which is what you
+wanted.
+
+<hr>
+
+<h3><a name="resources">How do I copy the needed resource files from
+another directory hierarchy?</a></h3>
+
+<p>Some sites store their documents in one place, and puts their
+banners, icons and such in a separate directory called
+<tt>/images</tt>, <tt>/banners</tt>, <tt>/icons</tt>,
+<tt>/resources</tt> or some such.  Unless you retrieve these as well as
+the documents things will probably not be too colorful.  So, imagine
+that the starwars site stored all the images in one holding directory
+called <tt>/imagery</tt> and you want to copy all the stuff in it that
+the episode-i pages need.  Then you do this:
+
+<pre>
+Options: recurse
+URL: http://www.starwars.com/episode-i/ episode-i
+Also: http://www.starwars.com/imagery/ imagery
+Fixup: run
+</pre>
+
+<p>There are two changes here compared to the simpler file we started
+with: There is an extra argument at the end of the URL directive.  It
+tells w3mir to store everything gotten from
+<tt>http://www.starwars.com/episode-i/</tt> in the subdirectory
+<tt>episode-i</tt>.  The directory can be omitted, but I think its
+neater this way.  Then the new directive 'Also:'.  It tells w3mir that
+you also want whatever the documents under
+<tt>http://www.starwars.com/episode-i/</tt> references under
+<tt>http://www.starwars.com/imagery/</tt>.
+
+<p><b>Note:</b> this will only get stuff that was used by the
+documents under <tt>http://www.starwars.com/episode-i/</tt>, anything
+stored under <tt>http://www.starwars.com/imagery/</tt> which is not
+used will not be retrieved. If you want everything under
+<tt>imagery</tt> to be retrived use the <tt>Also-quene:</tt>
+directive.
+
+<hr>
+
+<h3><a name="ignore">How do I avoid copying files I don't want or copy
+only files I want?</a></h3>
+
+<p>To control what files w3mir copies you can use the
+<tt>Ignore:</tt>, <tt>Fetch:</tt>, <tt>Ignore-RE:</tt> and
+<tt>Fetch-RE:</tt> directives in the configuration file.  The embeded
+references to any file you chose to ignore, i.e., not copy, will point
+at the original site, <em>not</em> to the mirror.  This means that the
+mirror user may still get ahold of the file from the original source
+by simply clicking if she so desires.
+
+<p>If a site contains huge .wav audio files that you are not
+interested in you put
+
+<pre>
+Ignore: *.wav
+</pre>
+
+<p>in the configuration file.  You may ignore as many different
+filename patterns as you want.  If you are mirroring a site you want
+very few, specific files from, say all HTML (named
+<em>something</em><tt>.html</tt>) and all Mpeg video files (named
+<em>something</em><tt>.mpg</tt>) you can write this:
+
+<pre>
+Fetch: *.html
+Fetch: *.mpg
+Ignore: *
+</pre>
+
+<p>W3mir will test each filename against each Fetch/Ignore rule in
+sequence.  A html file will match the first line and be fetched.  Any
+mpg file will match the second line and be fetched.  All other files
+will match the third line, and be ignored.  This last line is needed
+because the default is to get any files which are not ignored.  By
+arranging fetch and ignore rules carefully you may retrieve exactly
+the filename patterns you want and not retrieve anything else.
+
+<p>If you decide you also want all Mpeg Layer 3 audio files
+(<em>something.</em><tt>mp3</tt>) from the site, after the mirror has
+been established.  Then you add this:
+
+<pre>
+Fetch: *.mp3
+</pre>
+
+<p>as the third line, making the <tt>Ignore: *</tt> line the forth and
+last.  Then you must fix all references to .mp3 files within the
+mirror by running w3mfix thus:
+
+<pre>
+w3mfix -editref .mp3
+</pre>
+
+<p>which will edit all references to .mp3 files, pointing them the
+right place, on your disk. Ditto when you remove a fetch rule, or add
+or remove an ignore rule. See the answer about <a
+href="#enlarge">enlarging and pruning</a> mirrors for more examples of
+using <tt>w3mfix -editme ...</tt>
+
+<p><b>Note:</b> when retrieving only a very limited set of files, as
+in the example above, you <em>must</em> retrieve the html files,
+because how else will w3mir find URLs of files to retrieve? Only html
+files contain links to other files.
+
+<p>Similarly, you may chose to not mirror whole branches of the
+original site.  If you for example mirror my home-pages, and you decide
+not to mirror the comics pages you can put
+
+<pre>
+Ignore: /ts/
+</pre>
+
+<p>or more precisely
+
+<pre>
+Ignore: http://www.ifi.uio.no/~janl/ts/
+</pre>
+
+<p>in the configuration file.  If you do this after having established
+the mirror you use w3mfix to fix the references:
+
+<pre>
+w3mfix -editref /ts/
+</pre>
+
+<p><tt>Fetch:</tt> and <tt>Ignore:</tt> rules can only use a very
+limited subset of the Unix wild-cards.  w3mir understands only '?',
+'*', and '[a-z]' ranges.
+
+<p><tt>Ignore-RE:</tt> and <tt>Fetch-RE:</tt> are the same as
+<tt>Fetch:</tt> and <tt>Ignore:</tt> except that they give you access
+to the full power of Regular Expressions to make rules for that to get
+or not to get. They support perls superset of the normal Unix regular
+expression syntax.  They must be completely specified, including the
+prefixed m, a delimiter of your choice (except the paired delimiters:
+parenthesis, brackets and braces), and any of the RE modifiers. I.e.,
+
+<pre>
+Ignore-RE: m/.gif$/i
+</pre>
+
+<p>or
+
+<pre>
+Ignore-RE: m~/.*/.*/.*/~
+</pre>
+
+<p>and so on.  "#" cannot be used as delimiter as it is the comment
+character in the configuration file.
+
+<p>There are some traps when using <tt>Ignore-RE</tt> and
+<tt>Fetch-RE</tt>, please see their documentation in <tt>mandoc
+w3mir</tt> for a more complete explanation.
+
+<hr>
+
+<h3><a name="depth">How do I limit how deep w3mir will recurse?</a></h3>
+
+<p>W3mir has no explicit mechanism to limit the depth of recursion,
+but the same result can be achieved with a simple <tt>Ignore</tt> rule:
+
+<pre>
+Ignore: /*/*/*/*/*/*/
+</pre>
+
+<p>This will ignore any URLs that contain at least 7 slashes ("/").
+Note that a URL contains three slashes that does not have anything to
+do with depth:
+
+<pre>
+http://www.ifi.uio.no/
+</pre>
+
+<p>so only the surplus slashes are used for depth in this match.  In the
+example above the limit is 4 levels from the top.  The
+<tt>Ignore:</tt> rule that is used to limit recursion depth must be
+listed before any <tt>Fetch:</tt> rules to be effective.
+
+<hr>
+
+<h3><a name="memory">How do I limit w3mirs memory usage?</a></h3>
+
+<p>In a mirror consisting of <em>many</em> files, such as a archive of
+an active mailinglist w3mir will build a very large referer table, in
+part for w3mir to use in the <tt>Referer:</tt> header and in part for
+w3mfix to use in fixing references.
+
+<p>If you disable both the <tt>Referer:</tt> header and don't use
+w3mfix w3mir will not build a referer table.  You do this in the
+configuration file:
+
+<pre>
+Disable-headers: referer
+Fixup: off
+</pre>
+
+<p>Please note the potential problems of turning off fixup described
+earlier in this howto.  There are normaly no problems associated with
+simple sites, but if there are redirects fixup <em>is</em> needed for
+a consistent mirror.
+
+<hr>
+
+<h3><a name="rm">How do I remove the files are no longer on the
+original site from the mirror?</a></h3>
+
+<p>Over time the site you mirror will add files, and quite possibly
+remove files.  Or you might introduce new <tt>Ignore:</tt> rules after
+establishing the mirror that reduces the files wanted in the mirror.
+
+<p>By default w3mir will not delete such old files, some people might
+want to keep the files even if they are removed from the original
+site.  To remove the old/unwanted files you add 'remove' to the
+<tt>Options:</tt> line.
+
+<hr>
+
+<h3><a name="multi">How do I copy files from multiple sites?</a></h3>
+
+<p>In the answer to the previous question we see how to mirror several
+related sites.  For example, say you want to mirror all my home-pages
+into one mirror:
+
+<pre>
+Option: recurse
+URL: http://www.math.uio.no/~janl/ math/janl
+Also: http://www.math.uio.no/drift/personer/ math/drift
+Also: http://www.ifi.uio.no/~janl/ ifi/janl
+Also: http://www.mi.uib.no/~nicolai/ math-uib/nicolai
+</pre>
+
+<p>As in the previous example this will only get documents that are
+referenced.  Any documents that are stored at these location but to
+which w3mir finds no references will not be retrieved.  So this will
+fail if the sites are not in any way related, or if you wanted
+<em>everything</em> stored at each site.
+
+<p>To mirror unrelated sites, or get it all you may specify that the
+given URL should be considered a starting-point as well:
+
+<pre>
+Also-quene: http://www.math.uio.no/drift/personer/ math/drift
+</pre>
+
+<p>and, if you want to add an additional starting-point within a already
+named site:
+
+<pre>
+Quene: http://www.math.uio.no/drift/personer/foo.html
+</pre>
+
+<p>Armed with that you should be able to get pretty much anything you
+like.
+
+<hr>
+
+<h3><a name="alias">How do I copy files from one server with several
+names?</a></h3>
+
+<p>Simple, the same way you mirror several servers with different
+names. The math department at University of Oslo has a web server
+known under two names: math-www.uio.no and www.math.uio.no, and both
+names are used in documents stored on it. To copy the whole server,
+one time only, give these URL and Also lines:
+
+<pre>
+URL: http://www.math.uio.no/ .
+Also: http://math-www.uio.no/ .
+</pre>
+
+<p>Note the period/dot (.) at the end of each line.  It means that
+w3mir will store the files in the current directory, i.e. documents
+from both servers will be stored in the same place.  But since w3mir
+asks to only get documents that are newer than the ones it already has
+any document gotten from the server under the www.math.uio.no name
+will not be gotten from the math-www.uio.no name as well.  ... w3mir
+will ask for the document, but the server will tell w3mir that its
+copy is current and there will be no additional transfer of the
+document.
+
+<hr>
+
+<h3><a name="enlarge">How do I enlarge or prune an established
+mirror?</a></h3>
+
+<p>This only works if you use a configuration file.
+
+<p>If you want to add a site or directory to a mirror you simply add
+the needed <tt>Also:</tt> or <tt>Also-Quene:</tt> to the configuration
+file and then you run w3mfix manually, with the -editref option.  If,
+you for example have established a mirror of my home-pages, but want to
+add my wife's home-page you add this
+
+<pre>
+Also: http://www.ifi.uio.no/~annen/ ifi/annen
+</pre>
+
+<p>to the configuration shown earlier.  Then you run w3mfix, and you want
+it to fix all URLs referencing her home-page, the distinguishing
+characteristic is the name 'annen':
+
+<pre>
+w3mfix -editref annen
+</pre>
+
+<p>but 
+
+<pre>
+w3mirx -editref http://www.ifi.uio.no/~annen/
+</pre>
+
+<p>would work too, but it's a lot more to type.  This fixes all the
+references to her home-page so that they point to the mirror instead of
+the original pages.
+
+<p>To prune (cut out something) a mirror you do the same.  Make the
+change in the configuration file and run 'w3mfix -editme ...' to fix
+the references to that which you removed.
+
+<hr>
+
+<h3><a name="cat">How do I 'cat' a file?</a></h3>
+
+<p>W3mir will output the fetched document to its standard output
+(normally your screen/window) if you specify the '-s' command line
+option.  The corresponding configuration file directive is 
+
+<pre>
+File-Disposition: stdout
+</pre>
+
+<hr>
+
+<h3><a name="list">How do I list URLs in a document?</a></h3>
+
+<p>To list the URLs in http://www.math.uio.no/:
+
+<pre>
+w3mir -q -f -l http://www.math.uio.no/
+</pre>
+
+<p>The <tt>-q</tt> switch causes w3mir to produce no other output
+which would disturb the URL listing.  The <tt>-f</tt> switch tells
+w3mir to forget the document once it has been analyzed, i.e., not save
+it on disk.  And finally, the <tt>-l</tt> switch makes w3mir list the
+URLs in the document.  You may combine <tt>-l</tt> with <tt>-r</tt>
+and you need not use it with <tt>-f</tt>.
+
+<p>In the configuration file you put <tt>list</tt> on the
+<tt>Options:</tt> line.
+
+<hr>
+
+<h3><a name="aborted">How to I restart a mirror process after stopping
+it prematurely?</a></h3>
+
+<p>You may just rerun the same command once more.  But that makes
+w3mir request all the documents you have already once more to see if a
+more recent version is available on the server.  You can save time by
+using the <tt>-fs</tt> (Fetch Some) option.  This makes w3mir only
+request documents it does not find on your disk.  E.g.:
+
+<p><tt>w3mir -fs -r http://www.starwars.com/</tt>
+
+<p>This is not something you would normally put in the configuration
+file, but you can, by adding 'only-nonexistent' on the 'Options:' line.
+
+<hr>
+
+<h3><a name="robots">How do I disable robots.txt obedience?</a></h3>
+
+<p>Normally w3mir will read and obey each sites robots.txt file,
+because w3mir wants to be a nice tool. However robots.txt was designed
+with something slightly different than the normal use of w3mir in
+mind, so if you want w3mir to disregard the robot rules you can use
+<tt>-drr</tt> (Disable Robot Rules) on the command-line, or the line
+
+<pre>
+Robot-Rules: off
+</pre>
+
+<p>in the configuration file.  The robot exclusion standard is
+described in <a
+href="http://info.webcrawler.com/mak/projects/robots/norobots.html">http://info.webcrawler.com/mak/projects/robots/norobots.htm</a>.
+
+<hr>
+
+<h3><a name="corrupt">How do I stop w3mir from corrupting binary
+files?</a></h3>
+     
+<p>During the normal course of events w3mir converts the newline
+format of fetched HTML documents to your systems native newline
+format. On Unix a newline consists of a single ASCII LF character, on
+Macintoshes it's a single ASCII CR character and on Dos/Windows it's a
+ASCII CR/LF pair. W3mir understands all these and all HTML files are
+saved in the format your operating system prefers.
+
+<p>If, and this is very unlikely, a web server identifies a binary
+file as HTML w3mir will very likely corrupt the file. If you discover
+a file which is obviously ruined in the mirror, but is not ruined when
+you view it on the original site do this:
+
+<ol>
+
+<li>Notify the webmaster on the original site that the file has the
+wrong MIME type
+
+<li>Use the <tt>-nnc</tt> (No Newline Conversion) option on the
+command line, or
+
+<pre>
+Options: no-newline-conv
+</pre>
+
+in the configuration file.
+
+<li>Remove the corrupt file(s).
+
+<li>Run "<tt>w3mir -fs</tt>...", to fetch only the deleted file(s)
+again.
+
+</ol>
+
+<hr>
+
+<h3><a name="auth">How do I copy a site that wants user-name and
+password?</a></h3>
+
+<p>This can only be done with a configuration file.  Being able to
+give this on the command-line would give the user-name and password away
+to other users of the system, so the ability to give authentication
+information that way has not been put in w3mir.
+
+<p>In the configuration file you put:
+
+<pre>
+Auth-domain: */*
+Auth-user: me
+Auth-passwd: my-password
+</pre>
+
+<p>This will cause w3mir to give the user-name and password each time
+the server asks.  There is no way to make w3mir give the user-name and
+password each time no matter if the server asks or not.
+
+<hr>
+
+<h3><a name="mauth">How do I access a site that wants several
+different user-names and passwords?</a></h3>
+
+<p>If you have several user-names and passwords across
+the server(s) that are copied you need a slightly more advanced
+version of this that associates each user-name/password with a
+authentication "domain".  "Domain" is a HTTP concept.  It is simply a
+grouping of files and documents within a "realm".  One file or a whole
+directory hierarchy can belong to a realm.  One server may have many
+realms.  A user may have separate passwords for each realm, or the
+same password for all the realms the user has access to.  A
+combination of a server name, server port and a realm is called a
+domain.
+
+<pre>
+Auth-domain: theserver:theport/therealm
+Auth-user: me
+Auth-passwd: my-password
+
+Auth-domain: theserver:theport/otherrealm
+Auth-user: other-me
+Auth-password: other-password
+</pre>
+
+W3mir will tell you what the name of the realm is if it is unable to
+authenticate itself with the server. You may also use '*' as the realm
+name if you only copy documents from one realm on that server.
+
+<hr>
+
+<h3><a name="proxy">How do I use a proxy server?</a></h3>
+
+<p>On some secured sites you have to access the Internet through proxy
+servers to get out of the internal network.
+
+<p>A proxy server has a host name, and a port you must use. On the
+command line you simply specify <tt>-P proxy-host-name:proxy-port</tt>. In
+the configuration file you put this:
+
+<pre>
+HTTP-Proxy: proxy-host-name:proxyport
+</pre>
+
+<p>The main advantage of working through proxy servers other than
+security is that you take advantage of any caching the proxy server
+which can speed up retrievals enormously.
+
+<p>Another use of the proxy option is to "prime" the proxy servers
+cache.  I.e. you can use w3mir to fetch the documents through the proxy
+server to ensure that the documents are cached there later when you
+want to read them with your browser.  If you also specify 
+
+<pre>
+File-Disposition: forget
+</pre>
+
+<p>it won't even use any space on your disk, w3mir will just process
+the documents looking for URLs and then <em>not</em> save them.
+
+<hr>
+
+<h3><a name="pauth">How do I authenticate myself to a proxy
+server?</a></h3>
+
+<p>Some proxy servers demands a user-name and password to let you use
+them.  W3mir does not support the domain concept in connection with
+proxy authentication because the author cannot imagine that it will be
+needed.  You need to put this in your configuration file:
+
+<pre>
+HTTP-Proxy-user: proxy-username
+HTTP-Proxy-passwd: proxy-password
+</pre>
+
+<hr>
+
+<h3><a name="proxytweak">How do I ensure that the proxy server
+...?</a></h3>
+
+<p>HTTP/1.0 proxy servers may be told to not use its current copy of
+a document if you specify the <tt>-pflush</tt> command-line option.  Or 
+
+<pre>
+Proxy-Options: refresh
+</pre>
+
+<p>in the configuration file.  This is useful if the proxy has an old
+copy of some document and does not realize that a newer version exists
+on the origin site.  W3mir uses the HTTP/1.0 version of this command
+by default.  You can force w3mir to use the HTTP/1.1 version by adding
+<tt>no-pragma</tt> to the line.  If you do this it will not work at
+all as you want unless the server knows the HTTP/1.1 protocol.
+
+
+<p>HTTP/1.1 proxy servers can be manipulated in a few more ways.  The
+configuration file <tt>Proxy-Options:</tt> directive also takes
+<tt>revalidate</tt> and <tt>no-store</tt> options.  The former tells
+the proxy server to check if there is any newer version available.
+This is, in principle, more network friendly than the <tt>refresh</tt>
+option since it will only cause a copy if there is a newer file
+available.  The <tt>no-store</tt> option tells the proxy server to not
+store the documents you transfer.  This might be useful if the
+documents are 'sensitive' or something like that, but if the proxy
+server does not understand HTTP/1.1 it will not obey this option, and
+it might store the document anyway because the functionality is not
+implemented, so you should not count on this to work.
+
+<hr>
+
+<h3><a name="batchget">How do I batch get files with w3mir?</a></h3>
+
+<p>Normally when fetching files w3mir will process each html (and PDF)
+file to find URLs in them for further retrievals.  This is
+time-consuming, and not always wanted.  Sometimes you simply want to
+get a file, or more, and save it, untouched:
+
+<pre>
+w3mir -B http://www.starwars.com/ http://www.ifi.uio.no/~janl/
+</pre>
+
+<p>There is a companion switch for <tt>-B</tt>, namely <tt>-I</tt>, it
+makes w3mir read URLs from its standard input, one pr. line.  Thus you
+can use w3mir in a pipe to batch get several files whose URLs you find
+in some way.  This is a stupid example:
+
+<pre>
+w3mir -q -l -f http://www.ifi.uio.no/ | w3mir -I -B
+</pre>
+
+<p><tt>-B</tt> may also be used with <tt>-r</tt>, but the only effect
+it will have then is to save the html files unchanged on disk, because
+to recurse w3mir <em>has</em> to examine all the html the documents
+for URLs.
+
+<p><b>Please note</b> that using <tt>-B</tt> combined with <tt>-r</tt>
+for mirroring will probably lead to a unstable mirror, because w3mir
+does not get a chance to manipulate the URLs in the documents as it
+needs to be able to maintain a mirror later, and most important of
+all, w3mir needs all html files to contain a &lt;HTML&gt; tag to be
+able to recognize a HTML file as a HTML file. When running with the
+<tt>-B</tt> switch w3mir will not ensure the presence of this and thus
+we must rely on the original documents author to be nice. This is a
+bad bet. In other words, <b>don't use <tt>-B</tt> for recursive
+mirroring</b>, only for batch copying/mirroring of single documents.
+
+<hr>
+
+<h3><a name="cgi">How do I handle CGI?</a></h3>
+
+<p>There is no way w3mir can duplicate the process that happens on the
+Web server when it comes to CGI.  For some CGI programs w3mir can
+simply copy the output and store on disk.  For other CGI programs this
+is not possible, and the only way out is to make w3mir not get the
+involved files using Ignore rules in the configuration file.  These
+will avoid a lot of cgi programs:
+
+<pre>
+Ignore: *.cgi
+Ignore: *-cgi
+</pre>
+
+<p>You might have to add other/more rules for some sites if they have
+other naming conventions or if it's simply impossible to tell from the
+file-name if it's a CGI or not.
+
+<p>When you add ignore rules this causes two things:
+
+<ol>
+<li><p>W3mir will not retrieve documents matching the rules
+<li><p>W3mir will make all references to matching documents point to
+  the site you mirrored from instead of pointing to a non-existent
+  file in the mirror.
+</ol>
+
+<hr>
+
+<h3><a name="imap">How do I handle server side image-maps?</a></h3>
+
+<p>Server side image-maps is yet another thing it's impossible for
+w3mir to relate to.  w3mir simply cannot handle them.  Put ignore
+rules in the configuration file:
+
+<pre>
+Ignore: *.map
+</pre>
+
+<p>W3mir has full support for client side image-maps though.
+
+<hr>
+
+<h3><a name="java">How do I handle Java and ActiveX?</a></h3>
+
+<p>Java and Active X objects are are included in html pages with a
+<tt>&lt;OBJECT&gt;</tt> or <tt>&lt;APPLET&gt;</tt> tag.  W3mir can
+handle these on one condition: The CODEBASE attribute names the
+directory where the program stores its resources (such as
+subprograms, graphic files, sound, text, and so on) and w3mir must
+have read access to this directory.  Otherwise w3mir is without hope,
+it's impossible to extract the name of the resources the program needs
+in any reliable way.
+
+<p>HTML4 supports a attribute that enumerates the resources the
+program needs, w3mir is not able to use this yet.
+
+<hr>
+
+<h3><a name="script">How do I handle java-script and other script
+languages?</a></h3>
+
+<p>W3mir does its best to pass scripts (java-script, perl-script,
+etc...) embedded in the HTML undamaged.  It cannot, however, extract
+any URLs the script generates and the browser would cause the document
+to refer to or embed in a page. 
+
+<p>It will however work if the script generates relative references
+and there is some other way for w3mir to access the referenced file in
+some other manner.  Or if the script generates absolute references and
+the person browsing the mirror has access to the site named, then the
+user will be able to browse the referenced documents via that other
+server.
+
+<hr>
+
+<h3><a name="css">How to I handle the other things with 'partial
+support'</a></h3>
+
+<p>W3mir has partial support for CSS.  This means that
+<tt>&lt;style&gt</tt> tags and the enclosed style data are passed
+undamaged by w3mir.  W3mir will also retrieve the external CSSes named
+in HTML documents.  But w3mir will <em>not</em> (yet) analyze the
+CSSes data to find URLs of other resources (such as fonts) named in
+these.
+
+<p>W3mir also has partial support for Adobe Acrobat (PDF) files.  This
+means that w3mir can extract URLs from PDF files, and get the named
+documents if you want them.  But w3mir cannot edit those URLs so that
+the PDF files point to the mirror instead of wherever on the original
+site they were pointing.  If the PDF files contain absolute URLs they
+will continue pointing to where they were pointing before.  However,
+if the PDF files contain relative references things will work out.
+
+<p>The reason that URLs in PDF files cannot be edited is that they are
+binary and contain byte pointers.  If the URLs length is changed the
+byte pointers will point to the wrong place in the document.  Writing
+code to correct these pointers would be quite complex.  But if you
+write it I will use it.
+
+<hr>
+
+<h3><a name="anon">How do I keep my identity secret?</a></h3>
+
+<p>The HTTP protocol has a header, <tt>User:</tt> which is recommended
+to use by robots, such as w3mir.  Another way to track you is looking
+at the 'Referer:' header w3mir gives in HTTP requests.  Both can be
+disabled:
+
+<pre>
+Disable-headers: referer, user
+</pre>
+
+<p>If you in addition use a proxy server that many other users use
+there is little probability you can be tracked (easily) by the server
+you are copying things from.  You are however much easier to track
+from the logs in the proxy server.  And a court order is quite likely
+to get you tracked in spite of any precautions you take.  
+
+<p>W3mir does not support cookies and thus you cannot be tracked with
+the help of that mechanism.
+
+<hr>
+
+<h3><a name="ns">How do I pretend that I'm using Netscape, Internet
+Explorer or Lynx?</a></h3>
+
+<p>Some web sites give you different documents when you ask for a
+specific URL based on what browser you use, or even what OS you appear
+to be using.  w3mir identifies itself with a string that looks like
+this:
+
+<p><tt>w3mir/<em>version</em>-<em>release-date</em></tt>
+
+<p>Netscape identifies itself with strings that look something like
+this:
+
+<p><tt>Mozilla/3.01 (X11; I; Linux 2.0.30 i586)</tt>
+
+<p>and Internet Explorer says it's something like this:
+
+<p><tt>Mozilla/2.0 (compatible; MSIE 3.02; Windows NT)</tt>
+
+<p>and Lynx says something like this
+
+<p><tt>Lynx/2.6  libwww-FM/2.14</tt>
+
+<p>You can change w3mirs identification with <tt>-agent 'string'</tt>
+on the command line.  In the configuration file you put
+
+<pre>
+Agent: Mozilla/3.01 (X11; I; Linux 2.0.30 i586)
+</pre>
+
+<p>to pretend w3mir is netscape 3.01.
+
+<hr>
+
+<h3><a name="other">How do I do other things?</a></h3>
+
+<p>This document is by no means a complete list of the things you can
+do with w3mir.  The w3mir man page (<tt>man w3mir</tt> or <tt>perldoc
+w3mir</tt> lists more things, and goes into more detail of how things
+work so you can use the knowledge to do neat things.  There are
+several things mentioned only in the man-page that helps you with
+tricky multi-server mirroring, and gives you better control of what to
+get and not to get and under what name to save it on disk.  And a
+couple of other things...
+
+<hr>
+<address>Nicolai Langfeldt 9/7/1998</address>
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3mir.PL
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3mir.PL	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3mir.PL	(revision 16571)
@@ -0,0 +1,3291 @@
+# -*-perl-*-
+
+use Config;
+
+&read_makefile;
+$fullperl = resolve_make_var('FULLPERL') || $Config{'perlpath'};
+$islib = resolve_make_var('INSTALLSITELIB');
+
+$name = $0;
+$name =~ s~^.*/~~;
+$name =~ s~.PL$~~;
+
+open(OUT,"> $name") || 
+  die "Could open $name for writing: $!\n";
+
+print "writing $name\n";
+
+while (<DATA>) {
+  if (m~^\#!/.*/perl.*$~o) {
+    # This substitutes the path perl was installed at on this system
+    # _and_ removed any (-w) options.
+    print OUT "#!",$fullperl,$1,"\n";
+    next;
+  }
+  if (/^use lib/o) {
+    # This substitutes the actuall library install path
+    print OUT "use lib '$islib';\n";
+    next;
+  }
+  print OUT;
+}
+
+close(OUT);
+
+# Make it executable too, and writeable
+chmod 0755, $name;
+
+#### The library
+
+sub resolve_make_var ($) {
+
+  my($var) = shift @_;
+  my($val) = $make{$var};
+
+#  print "Resolving: ",$var,"=",$val,"\n";
+  
+  while ($val =~ s~\$\((\S+)\)~$make{$1}~g) {}
+#  print "Resolved: $var: $make{$var} -> $val\n";
+  $val;
+}
+
+
+sub read_makefile {
+
+  open(MAKEFILE, 'Makefile') || 
+    die "Could not open Makefile for reading: $!\n";
+
+  while (<MAKEFILE>) {
+    chomp;
+    next unless m/^([A-Z]+)\s*=\s*(\S+)$/;
+    $make{$1}=$2;
+#    print "Makevar: $1 = $2\n";
+  }
+
+  close(MAKEFILE)
+}
+
+__END__
+#!/local/bin/perl5 -w
+# Perl 5.002 or later.  w3mir is mostly tested with perl 5.004
+#
+# You might want to change or comment out this:
+use lib '/hom/janl/lib/perl';
+#
+# Once upon a long time ago this was Oscar Nierstrasz's
+# <oscar@cui.unige.ch> htget script.
+#
+# Retrieves HTML pages, creating local copies in the _current_ 
+# directory. The script will check for the last-modified stamp on the
+# document, and will not fetch it if the document isn't changed.
+#
+# Bug list is in w3mir-README.
+#
+# Test cases for janl to use:
+#   w3mir -r -fs http://www.eff.org/ - infinite recursion!
+#     --- but cursory examination seems to indicate confused server...
+#   http://java.sun.com/progGuide/index.html check out the img things.
+#
+# Copyright Holders:
+#   Nicolai Langfeldt, janl@ifi.uio.no
+#   Gorm Haug Eriksen, gorm@usit.uio.no
+#   Chris Szurgot, szurgot@itribe.net
+#   Ed Jordan, ed@olympus.itl.net
+#   Alex Knowles, aknowles@avs.com aka ark.
+# Copying and modification is governed by the "Artistic License" enclosed in
+# the w3mir distribution
+#
+# History (European format date: dd/mm/yy):
+#  oscar 25/03/94 -- added -s option to send output to stdout
+#  oscar 28/03/94 -- made HTTP 1.0 the default
+#  oscar 30/05/94 -- special handling of directory URLs missing a trailing "/"
+#   gorm 20/02/95 -- added mirror capacity + fixed a couple of bugs
+#   janl 28/03/95 -- added a working commandline parser.
+#   janl 18/09/95 -- Changed to use a net http library.  Removed dependency of
+#		     url.pl.
+#   janl 19/09/95 -- Extensive rewrite. Simplified a lot, works better. 
+#		     HTML files are now saved in a new and improved manner,
+#		     which means they can be recognized as such w/o fancy
+#		     filename extention type rules.
+# szurgot 27/01/96-- Added "Plaintextmode" wrapper to binmode PAGE. 
+#                    binmode page is required under Win32, but broke modified
+#                    checking
+#                 -- Minor change added ; to "# '" strings for Emacs cperl-mode
+# szurgot 07/02/96-- When reading in local file for checking of URLs changed
+#                    local ($/) =0; to equal undef;
+#   janl 08/02/96 -- Added szurgot's changes and changed them :-)
+# szurgot 09/02/96-- Added code to strip /#.*$/ from urls when reading from 
+#                    local file
+#                 -- Added hasAlarm variable to w3http.pl. Set to 1 if you have
+#                    alarm(). 0 otherwise.
+#                 -- Moved code setting up the valid extensions list into the
+#                    args processing where it belonged
+#   janl 20/02/96 -- Added szurgot changes again.
+#		  -- Make timeout code work.
+#   		  -- and made another win32 test.
+#   janl 19/03/96 -- Worked through the code for handling not-modified 
+#    		     documents, it was a bit shabby after htmlop was intro'ed.
+#   janl 20/03/96 -- -l fix
+#   janl 23/04/96 -- Added -fs by request (by Rik Faith)
+#   janl 16/05/96 -- Made -R mandatory, added use and support for
+#			w3http::SAVEBIN
+# szurgot 19/05/96-- Win95 adaptions.
+#   janl 19/05/96 -- -C did not exactly work as expected.  Thanks to Petr
+#		     Novak for bug descriptions.
+#   janl 19/05/96 -- Changed logic for @didntget, @got and so on to use
+#		     @queue and %urlstat.
+#   janl 09/09/96 -- Removed -R switch.
+#   janl 14/09/96 -- Added ir (initial referer) switch
+#   janl 21/09/96 -- Made retry code saner.  There probably needs to be a
+#                    sleep before retry comencing switch.  When no tty is
+#                    present it should be fairly long.
+#   gorm 15/09/96 -- Added cr (check robot) switch. Default to 1 (on)
+#   janl 22/09/96 -- Modified gorms patch to use WWW::RobotRules.  Changed
+#		     robot switch to be consistent with current w3mir
+#                    practice.
+#   janl 27/09/96 -- Spelling corrections from charles.curran@ox.ac.uk
+#                 -- Folded in manual diffs from ark.
+#    ark 24/09/96 -- Simple facilities to edit the incomming file(s)
+#   janl 27/09/96 -- Added switch to enable <!--NOMIRROR--> editing and
+#		     foolproofed ark's patch a bit.
+#   janl 02/10/96 -- Added -umask switch.
+#		  -- Redirected documents did not have a meaningful referer
+#		     value (it was undefined).
+#		  -- Got w3mir into strict discipline, found some typos...
+#   janl 20/10/96 -- Mtime is preserved
+#   janl 21/10/96 -- -lc switch added.  Mtime preservation works better.
+#   janl 06/11/96 -- Treat 301 like 302.
+#   janl 02/12/96 -- Added config file code, fetch/ignore rules, apply
+#   janl 04/12/96 -- Better checking of config input.
+#   janl 06/12/96 -- Putting together the URL selection/editing brains.
+#   janl 07/12/96 -- Checking out some bugs.  Adding multiscope options.
+#   janl 12/12/96 -- Adding to and defeaturing the multiscope options.
+#   janl 13/12/96 -- Continuing work in multiscope stuff
+#                 -- Unreferenced file and empty directory removal works.
+#   janl 19/02/97 -- Can extract urls from adobe acrobat pdf files :-)
+#		     Important: It does _not_ edit urls, so they still
+#		     point at the original site(s).
+#   janl 21/02/97 -- Fix -lc bug related to case and the apply things.
+#		  -- only use SAVEURL if needed
+#   janl 11/03/97 -- Finish work on SAVEURL conditional.
+#		  -- Fixed directory removal code.
+#                 -- parse_args did not abort when unknown option/argument
+#		     was specified.
+#   janl 12/03/97 -- Made test case for -lc.  Didn't work.  Fixed it.  I think.
+#		     Realized we have bug w.r.t. hostname caseing.
+#   janl 13/03/97 -- All redirected to URLs within scope are now queued.  
+#		     That should make the mirror more complete, but it won't
+#		     help browsability when it comes to the redirected doc.
+#		  -- Moved robot retrival to the inside of the mirror loop
+#		     since we now possebly mirror several sites.
+#		  -- Changed 'fetch-options' to 'options'.
+#                 -- Added 'proxy-options'/-pflush to controll proxy server(s).
+#   janl 09/04/97 -- Started using URI::URL.
+#   janl 11/04/97 -- Debugging and using URI::URL more correctly various places
+#   janl 09/05/97 -- Added --agent switch
+#   janl 12/05/97 -- Simplified scope checks for root URL, changed URL 'apply'
+#		     processing.
+#		  -- Small output formating fix in the robot rules code.
+#		  -- Version is now 0.99
+#   janl 14/05/97 -- htmpop no-longer puts '<!DOCTYPE...' into doc, so check 
+#		     for '<HTML' instead
+#   janl 11/06/97 -- Made :port optional in server part of auth-domain.
+#			Always removing :80 from server part to match netloc.
+#   janl 22/07/97 -- More debugging of rewrite for new features -B, -I.
+#   janl 01/08/97 -- Fixed bug in RE quoting for Ignore/Fetch
+#   janl 04/08/97 -- s/writepage/write_page/g
+#   janl 07/09/97 -- 0.99b1 is released
+#   janl 19/09/97 -- Kaj Hejer discovers omissions in non-html-url-mining code.
+#                 -- 0.99b2 is released
+#   janl 24/09/97 -- Matt Chapman found bug in realm-name extraction.
+#   janl 10/10/97 -- Referer: header supression supressed User: header instead
+#		  -- Added fixup handling, writes .redirs and .referers
+#		     (no dot in win32)
+#  		  -- Read .w3mirc (w3mir.ini on win32) if present
+#		  -- Stop file removal code from removing these files
+#   janl 16/10/97 -- process_tag was mangling url attributes in tags with more
+#		     than one of them.  Problem found by Robert L. Binkley
+#   janl 04/12/97 -- Fixed problem with authentication, misplaced +
+#		  -- default inter-docuent pause is 0.  I figure it's better
+#		     to keep one httpd occupied in a steady stream than to
+#		     wait for it to die before we talk to it again.
+#   janl 13/12/97 -- The arguments to index.html in the form of index.html/foo
+#		     handling code was incomplete.  To make it complete would
+#		     have been hard, so it was removed.
+#		  -- If a URL changes from file to directory or vice versa
+#		     this is now handled.
+#   janl 11/01/98 -- PDF files with no URLs does not cause warnings now.
+#		  -- Close REFERERS and REDIRECTS before calling w3mfix
+#   janl 22/01/98 -- Proxy authentication as outlined by Christian Geuer
+#   janl 04/02/98 -- Version 1pre1
+#   janl 18/02/98 -- Fixed wild_re after tip by Prentiss Riddle.
+#		  -- Version 1pre2
+#   janl 20/02/98 -- w3http updated to handle complex content-types.
+#		  -- Fix wild_re more, bug noted by James Dumser
+#		  -- 1.0pre3
+#   janl 18/03/98 -- Version 1.0 is released
+#   janl 09/04/98 -- Added feature so user can disable newline conversion.
+#   janl 20/04/98 -- Only convert newlines in HTML files. -> 1.0.2
+#   janl 09/05/98 -- More carefull clean_disk code.
+#		  -- Check if the redirected URL was a root url, if so
+#		     issue a warning and exit.
+#   janl 12/05/98 -- use ->unix_path instead of ->as_string to derive local
+#		     filename.
+#   janl 25/05/98 -- -B didn't work too well.
+#   janl 09/07/98 -- Redirect to fragment broke us, less broken now -> 1.0.4
+#   janl 24/09/98 -- Better errormessages on errors -> 1.0.5
+#   janl 21/11/98 -- Fix errormessages better.
+#   janl 05/01/99 -- Drop 'Referer: (commandline)'
+#   janl 13/04/99 -- Add initial referer to root urls in batch mode.
+#
+# Variable name discipline:
+# - remote, umodified URL.  Variables prefixed 'rum_'
+# - local, filesystem.  Variables prefixed 'lf_'.
+# Use these prefixes so we know what we're working with at all times.
+# Also, URL objects are postfixed _o
+#
+# The apply rules and scope rules work this way:
+# - First apply the user rules to the remote url.
+# - Check if document is within scope after this.
+# - Then apply w3mir's rules to the result.  This results is the local,
+#   filesystem, name.
+#
+# We use features introduced in 5.002.
+require 5.002;
+
+# win32 and $nulldevice need to be globals, other modules use them.
+use vars qw($win32 $nulldevice);
+
+# To figure out what kind of system this is
+BEGIN {
+  use Config;
+  $win32 = ( $Config{'osname'} eq 'MSWin32' ); 
+}
+# More ways to die:
+use Carp;
+# Http module:
+use w3http;
+# html url extraction and manupulation:
+use htmlop;
+# Extract urls from adobe acrobat pdf files:
+use w3pdfuri;
+# Date computer:
+use HTTP::Date;
+# URLs:
+use URI::URL;
+# For flush method
+use FileHandle;
+
+# Full discipline:
+use strict;
+
+# Set params in the http package, HTTP protocol version:
+$w3http::version="1.0";
+
+# The defaults should be for a robotic http agent on good behaviour.
+my $debug=0;			# Debug level
+my $verbose=0;			# Verbosity level, -1 = quiet, 0 = normal, 1...
+my $pause=0;			# Pause between http requests
+my $retryPause=600;		# Pause between retries. 10 minutes.
+my $retry=3;			# Max 3 stabs pr. url.
+my $r=0;			# Recurse? no recursion = absolutify links
+my $remove=0;			# Remove files that are not there?
+my $s=0;			# 0: save on disk 1: stdout 2: just forget 'em
+my $useauth=0;			# Use authorization
+my %authdata;			# Authorization data
+my $check_robottxt = 1;		# Check robots.txt
+my $do_referer = 1;		# Send referers header
+my $do_user = 1;		# Send user header
+my $cache_header = '';		# The cache-control/pragma: no-cache header
+my $using_proxy = 0;		# Using proxy server or not?
+my $batch=0;			# Batch get URLs?
+my $read_urls=0;		# Get urls from STDIN?
+my $abs=0;			# Absolutify URLs?
+my $immediate_redir=0;		# Immediately follow a redirect?
+my @root_urls;			# This is where we start, the root documents
+my @root_dirs;			# The corresponding directories.  for remove
+my $chdirto='';			# Place to chdir to after reading config file
+my %nodelete=();		# Files that should not be deleted
+my $numarg=0;			# Number of arguments accepted.
+
+# Fixup related things
+my $fixrc='';			# Name of w3mfix config file
+my $fixup=1;			# Do things needed to run fixup
+my $runfix=0;			# Run w3mfix for user?
+my $fixopen=0;			# Fixup files open?
+
+my $indexname='index.html';
+
+my $VERSION;
+$VERSION='1.0.8';
+$w3http::agent = my $w3mir_agent = "w3mir/$VERSION-1999-05-28";
+my $iref='';			# Initial referer.  Must evaluate to false
+
+# Derived settings	
+my $mine_urls=0;		# Mine URLs from documents?
+my $process_urls=0;		# Perform (URL) processing of documents?
+
+# Queue of urls to get.
+my @rum_queue = ();
+my @urls = ();
+# URL status map.
+my %rum_urlstat = ();
+# Status codes:
+my $QUEUED   = 0;		# Queued but not gotten yet.
+my $TERROR   = 100;		# Transient error, retry later
+my $HLERR    = 101;		# Permanent error, give up
+my $GOTIT    = 200;		# Gotten. Note similarity to http result code
+my $NOTMOD   = 304;		# Not modified.
+# Negative codes for nonexistent files, easier to check.
+my $NEVERMIND= -1;		# Don't want it
+my $REDIR    = -302;		# Does not exist, redirected
+my $ENOTFND  = -404;		# Does not exist.
+my $OTHERERR = -600;		# Some other error happened
+my $FROBOTS  = -601;		# Forbidden by robots.txt rule
+
+# Directory/files survey:
+my %lf_file;		# What files are present in FS?  Disposition?  One of:
+my $FILEDEL=0;		# Delete file
+my $FILEHERE=1;		# File present in filesystem only
+my $FILETHERE=2;	# File present on server too.
+my %lf_dir;		# Number of files/dirs in dir.  If 0 dir is 
+			# eligible for deletion.
+
+my %fiddled=();		# If a file becomes a directory or a directory
+                        # becomes a file it is considered fiddled and
+                        # w3mir will not fiddle with it again in this
+                        # run.
+
+# Bitbucket device, very OS dependent.
+$nulldevice='/dev/null';
+$nulldevice='nul:' if ($win32);
+
+# What to get, and not.
+# Text of user supplied fetch/ignore rules
+my $rule_text=" # User defined fetch/ignore rules\n";
+# Code ref to the rule procedure
+my $rule_code;
+
+# Code to prefix and postfix the generated code.  Prefix should make
+# $_ contain the url to match.  Postfix should return 1, the default
+# is to get the url/file.
+my $rule_prefix='$rule_code = sub { local($_) = shift;'."\n";
+my $rule_postfix=" return 1;\n}";
+
+# Scope tests generated by URL/Also directives in cfg. The scope code
+# is just like the rule code, but used for program generated
+# fetch/ignore rules related to multiscope retrival.
+my $scope_fetch=" # Automatic fetch rules for multiscope retrival\n";
+my $scope_ignore=" # Automatic ignore rules for multiscope retrival\n";
+my $scope_code;
+
+my $scope_prefix='$scope_code = sub { local($_) = shift;'."\n";
+my $scope_postfix=" return 0;\n}";
+
+# Function to apply to urls, se rule comments.
+my $user_apply_code;	# User specified apply code
+my $apply_code;		# w3mirs apply code
+my $apply_prefix='$apply_code = sub { local($_) = @_;'."\n";
+my $apply_lc=' $_ = lc $_; ';
+my $apply_postfix='  return $_;'."\n}";
+my @user_apply;		# List of users apply rules.
+my @internal_apply;	# List of w3mirs apply rules.
+
+my $infoloss=0;		# 1 if any URL translations (which cause
+                        # information loss) are in effect.  If this is
+                        # true we use the SAVEURL operation.
+my $list;		# List url on STDOUT?
+my $edit;		# Edit doc? Remove <!--NOMIRROR>...<!--/NOMIRROR-->
+my $header;		# Text to insert in header
+my $lc=0;		# Convert urls/filenames to lowercase?
+my $fetch=0;		# What to fetch: -1: Some, 0: not modified 1: all
+my $convertnl=1;	# Convert newlines?
+
+# Non text/html formats we can extract urls from.  Function must take one
+# argument: the filename.
+my %knownformats = ( 'application/pdf', \&w3pdfuri::list,
+		     'application/x-pdf', \&w3pdfuri::list,
+		   );
+
+# Known 'magic numbers' of the known formats.  The value is used as
+# key in %knownformats.  the key part is a exact match for the
+# following <string> beginning at the first byte of the file.
+# This should probably be made more flexible, but not until we need it.
+
+my %knownmagic = ( '%PDF-', 'application/pdf' );
+
+my $iinline='';	# inline RE code to make RE caseinsensitive 
+my $ipost='';	# RE postfix to make it caseinsensitive
+
+usage() unless parse_args(@ARGV);
+
+{
+  my $w3mirc='.w3mirc';
+  
+  $w3mirc='w3mir.ini' if $win32;
+  
+  if (-f $w3mirc) {
+    parse_cfg_file($w3mirc);
+    $nodelete{$w3mirc}=1;
+  }
+}
+
+# Check arguments and options
+if ($#root_urls>=0) {
+  # OK
+} else {
+  print "URLs: $#rum_queue\n";
+  usage("No URLs given");
+}
+
+# Are we converting newlines today?
+$w3http::convert=0 unless $convertnl;
+
+if ($chdirto) {
+  &mkdir($chdirto.'/this-is-not-created-odd-or-what');
+  chdir($chdirto) || 
+    die "w3mir: Can't change working directory to '$chdirto': $!\n";
+}
+
+$SIG{'INT'}=sub { print STDERR "\nCaught SIGINT!\n"; exit 1; };
+$SIG{'QUIT'}=sub { print STDERR "\nCaught SIGQUIT!\n"; exit 1; };
+$SIG{'HUP'}=sub { print STDERR "\nCaught SIGHUP!\n"; exit 1; };
+
+&open_fixup if $fixup;
+
+# Derive how much document processing we should do.
+$mine_urls=( $r || $list );
+$process_urls=(!$batch && !$edit && !$header);
+# $abs can be set explicitly with -abs, and implicitly if not recursing
+$abs = 1 unless $r;
+print "Absolute references\n" if $abs && $debug;
+
+# Cache_controll specified but proxy not in use?
+die "w3mir: If you want to control a cache, use a proxy server!\n"
+  if ($cache_header && !$using_proxy);
+
+# Compile the second order code
+
+# - The rum scope tests
+my $full_rules=$scope_prefix.$scope_fetch.$scope_ignore.$scope_postfix;
+# warn "Scope rules:\n-------------\n$full_rules\n---------------\n";
+eval $full_rules;
+
+die "w3mir: Program generated rules did not compile.\nPlease report to w3mir-core\@usit.uio.no.  The code is:\n----\n".
+  $full_rules."\n----\n"
+  if !defined($scope_code);
+
+$full_rules=$rule_prefix.$rule_text.$rule_postfix;
+# warn "Fetch rules:\n-------------\n$full_rules\n---------------\n";
+eval $full_rules;
+
+# - The user specified rum tests
+die "w3mir: Ignore/Fetch rules did not compile.\nPlease report to w3mir-core\@usit.uio.no.  The code is:\n----\n".
+  $full_rules."\n----\n"
+  if !defined($rule_code);
+
+# - The user specified apply rules
+
+my $full_apply=$apply_prefix.($lc?$apply_lc:'').
+  join($ipost.";\n",@user_apply).(($#user_apply>=0)?$ipost:"").";\n".
+  $apply_postfix;
+eval $full_apply;
+
+die "w3mir: User apply rules did not compile.\nPlease report to w3mir-core\@usit.uio.no. The code is:
+----
+".$full_apply."
+----\n" if !defined($apply_code);
+
+$user_apply_code=$apply_code;
+
+# - The w3mir generated apply rules
+
+$full_apply=$apply_prefix.($lc?$apply_lc:'').
+  join($ipost.";\n",@internal_apply).(($#internal_apply>=0)?$ipost:"").";\n".
+  $apply_postfix;
+eval $full_apply;
+
+die "Internal apply rules did not compile.  The code is:
+----
+".$full_apply."
+----\n" if !defined($apply_code);
+
+# - Information loss via -lc?  There are other sources as well.
+$infoloss=1 if $lc;
+
+warn "Infoloss is $infoloss\n" if $debug;
+
+# More setup:
+
+$w3http::debug=$debug;
+
+$w3http::verbose=$verbose;
+
+my %rum_referers=();	# Array of referers, key: rum_url
+my $Robot_Blob;		# WWW::RobotsRules object, decides if rum_url is 
+			# forbidden to access for us.
+my $rum_url_o;		# rum url, mostly the current, the one we're getting
+my %gotrobots;		# Did I get robots.txt from site? key: url->netloc
+my($authuser,$authpass);# Username and password for authentication with server
+my @rum_newurls;	# List of rum_urls in document
+
+if ($check_robottxt) {
+  # Eval is only way to defer loading of module until we know it's needed?
+  eval 'use WWW::RobotRules;';
+
+  die "Could not load WWW::RobotRules, try -drr switch\n"
+    unless defined(&WWW::RobotRules::parse);
+
+  $Robot_Blob = new WWW::RobotRules $w3mir_agent;
+}
+
+# We have several main-modes of operation.  Here we select one
+if ($r) {
+
+  die "w3mir: No URLs?  Try 'w3mir -h' for help.\n"
+    if $#root_urls==-1;
+
+  warn "Recursive retrival comencing\n" if $debug;
+
+  die "w3mir: Sorry, you cannot combine -r/recurse with -I/read_urls\n"
+    if $read_urls;
+
+  # Recursive
+  my $url;
+  foreach $url (@root_urls) {
+    warn "Root url dequeued: $url\n" if $debug;
+    if (want_this($url)) {
+      queue($url);
+      &add_referer($url,$iref);
+    } else {
+      die "w3mir: Inconsistent configuration: Specified $url is not inside retrival scope\n";
+    }
+  }
+  mirror();
+
+} else {
+  if ($batch) {
+    warn "Batch retrival commencing\n" if $debug;
+    # Batch get
+    if ($read_urls) { 
+      # Get URLs from <STDIN>
+      while (<STDIN>) {
+	chomp;
+	&add_referer($_,$iref);
+	batch_get($_);
+      }
+    } else {
+      # Get URLs from commandline
+      my $url;
+      foreach $url (@root_urls) {
+	&add_referer($url,$iref);
+      }
+      foreach $url (@root_urls) {
+	batch_get($url);
+      }
+    }
+  } else {
+    warn "Single url retrival commencing\n" if $debug;
+
+    # A single URL, with all processing on
+    die "w3mir: You specified several URLs and not -B/batch\n"
+      if $#root_urls>0;
+    queue($root_urls[0]);
+    &add_referer($root_urls[0],$iref);
+    mirror();
+  }
+}
+
+&close_fixup if $fixup;
+
+# This should clean up files:
+&clean_disk if $remove;
+
+warn "w3mir: That's all (".$w3http::xfbytes.'+',$w3http::headbytes.
+  " bytes of it).\n" unless $verbose<0;
+
+if ($runfix) {
+  eval 'use Config;';
+  warn "Running w3mfix\n";
+  if ($win32) {
+    system($Config{'perlpath'}." w3mfix $fixrc");
+  } else {
+    system("w3mfix $fixrc");
+  }
+}
+
+exit 0;
+
+sub get_document {
+  # Get one document by HTTP ($1/rum_url_o).  Save in given filename ($2).
+  # Possebly returning references found in the document.  Caller must
+  # set up referer array, check wantedness and everything else.  We
+  # handle authentication here though.
+
+  my($rum_url_o)=shift;
+  my($lf_url)=shift;
+  croak("\$rum_url_o is empty") if !defined($rum_url_o) || !$rum_url_o;
+  croak("$lf_url is empty") if !defined($lf_url) || !$lf_url;
+
+  # Make sure it's an object
+  $rum_url_o = url $rum_url_o 
+    unless ref $rum_url_o;
+  
+  # Derive a filename from the url, the filename contains no URL-quoting
+  my($lf_name) = (url "file:$lf_url")->unix_path;
+
+  # Make all intermediate directories
+  &mkdir($lf_name) if $s==0;
+
+  my($rum_as_string) = $rum_url_o->as_string;
+
+  print STDERR "GET_DOCUMENT: '",$rum_as_string,"' -> '",$lf_name,"'\n"
+    if $debug;
+
+  my $hostport;
+  my $www_auth='';	# Value of that http reply header
+  my $page_ref;
+  my @rum_newurls;	# List of URLs extracted
+  my $url_extractor;
+  my $do_query;		# Do query or not?
+
+  if (defined($rum_urlstat{$rum_as_string}) && 
+      $rum_urlstat{$rum_as_string}>0) {
+    warn "w3mir: Internal error, ".$rum_as_string.
+      " queued several times\n";
+    next;
+  }
+
+  # Goto here if we want to retry b/c of authentication
+  try_again:
+
+  # Start building the extra http::query arguments again
+  my @EXTRASTUFF=();
+
+  # We'll start by assuming that we're doing the query.
+  $do_query=1;
+    
+  # If we're not checking the timestamp, or the file does not exist
+  # then we get the file unconditionally.  Otherwise we only want it
+  # if it's updated.
+
+  if ($fetch==1) {
+    # Nothing do do?
+  } else {
+    if (-f $lf_name) {
+      if ($fetch==-1) {
+	print STDERR "w3mir: ".($infoloss?$rum_as_string:$lf_name).
+	  ", already have it" if $verbose>=0;
+	if (!$mine_urls) {
+	  # If -fs and the file exists and we don't need to mine URLs
+	  # we're finished!
+	  warn "Already have it, no mining, returning!\n" if $debug;
+	  print STDERR "\n" if $verbose>=0;
+	  return;
+	}
+	$w3http::result=1304;	# Pretend it was 'not modified'
+	$do_query=0;
+      } else {
+	push(@EXTRASTUFF,$w3http::IFMODF,$lf_name);
+      }
+    }
+  }
+
+  if ($do_query) {
+
+    # Does the server want authorization for this file?  $www_auth is
+    # only set if authentication was requested the first time around.
+
+    # For testing:
+    # $www_auth='Basic realm="foo"';
+
+    if ($www_auth) {
+      my($authdata,$method,$realm);
+
+      ($method,$realm)= $www_auth =~ m/^(\S+)\s+realm=\"([^\"]+)\"/i;
+      $method=lc $method;
+      $realm=lc $realm;
+      die "w3mir: '$method' authentication needed, don't know that.\n"
+	if ($method ne 'basic');
+      
+      $hostport = $rum_url_o->netloc;
+      $authdata=$authdata{$hostport}{$realm} || $authdata{$hostport}{'*'} ||
+	$authdata{'*'}{$realm} || $authdata{'*'}{'*'};
+
+      if ($authdata) {
+	push(@EXTRASTUFF,$w3http::AUTHORIZ,$authdata);
+      } else {
+	print STDERR "w3mir: No authorization data for $hostport/$realm\n";
+	$rum_urlstat{$rum_as_string}=$NEVERMIND;
+	next;
+      }
+    }
+    
+    push(@EXTRASTUFF,$w3http::FREEHEAD,$cache_header)
+      if ($cache_header);
+
+    # Insert referer header data if at all
+    push(@EXTRASTUFF,$w3http::REFERER,$rum_referers{$rum_as_string}[0])
+      if ($do_referer && exists($rum_referers{$rum_as_string}));
+
+    push(@EXTRASTUFF,$w3http::NOUSER)
+      unless ($do_user);
+
+    # YES, $lf_url is right, w3http::query handles this like an url so
+    # the quoting must all be in place.
+    my $binfile=$lf_url;
+    $binfile='-' if $s==1;
+    $binfile=$nulldevice if $s==2;
+
+    if ($pause) {
+      print STDERR "w3mir: sleeping\n" if $verbose>0;
+      sleep($pause);
+    }
+
+    print STDERR "w3mir: ".($infoloss?$rum_as_string:$lf_name) 
+      unless $verbose<0;
+    print STDERR "\nFile: $lf_name\n" if $debug;
+
+    &w3http::query($w3http::GETURL,$rum_as_string,
+		   $w3http::SAVEBIN,$binfile,
+		   @EXTRASTUFF);
+
+    print STDERR "w3http::result: '",$w3http::result,
+    "' doc size: ", length($w3http::document),
+    " doc type: -",$w3http::headval{'CONTENT-TYPE'},
+    "- plaintexthtml: ",$w3http::plaintexthtml,"\n"
+      if $debug;
+
+    print "Result: ",$w3http::result," Recurse: $r, html: ",
+    $w3http::plaintexthtml,"\n" 
+      if $debug;
+
+  } # if $do_query
+    
+  if ($w3http::result==200) { # 200 OK 
+    $rum_urlstat{$rum_as_string}=$GOTIT;
+
+    if ($mine_urls || $process_urls) {
+
+      if ($w3http::plaintexthtml) {
+	# Only do URL manipulations if this is a html document with no
+	# special content-encoding.  We do not handle encodings, yet.
+
+	my $page;
+
+	print STDERR ($process_urls)?", processing":", url mining"
+	  if $verbose>0;
+	  
+	print STDERR "\nurl:'$lf_url'\n" 
+	  if $debug;
+
+	print "\nMining URLs: $mine_urls, Process: $process_urls\n" 
+	  if $debug;
+	    
+	($page,@rum_newurls) = 
+	  &htmlop::process($w3http::document,
+			   # Only get a new document if wanted
+			   $process_urls?():($htmlop::NODOC),
+			   $htmlop::CANON,
+			   $htmlop::ABS,$rum_url_o,
+			   # Only list urls if wanted
+			   $mine_urls?($htmlop::LIST):(),
+
+			   # If user wants absolute URLs do not
+			   # relativize them
+
+			   $abs?
+			   ():
+			   (
+			    $htmlop::TAGCALLBACK,\&process_tag,$lf_url,
+			    )
+			  );
+
+#	print "URL: ",join("\nURL: ",@rum_newurls),"\n";
+
+	if ($process_urls) {
+	  $page_ref=\$page;
+	  $w3http::document='';
+	} else {
+	  $page_ref=\$w3http::document;
+	}
+
+      } elsif ($s == 0 &&
+	       ($url_extractor = 
+		$knownformats{$w3http::headval{'CONTENT-TYPE'}})) {
+
+	# The knownformats extractors only work on disk files so write
+	# doc to disk if not there already (non-html text will not be)
+	write_page($lf_name,$w3http::document,1);
+
+	# Now we try our hand at fetching URIs from non-html files.
+	print STDERR ", mining URLs" if $verbose>=1;
+	@rum_newurls = &$url_extractor($lf_name);
+	# warn "URLs from PDF: ",join(', ',@rum_newurls),"\n";
+      }
+      
+      
+    } # if ($mine_urls || $process_urls)
+
+#    print "page_ref defined: ",defined($page_ref),"\n";
+#    print "plaintext: ",$w3http::plaintext,"\n";
+
+    $page_ref=\$w3http::document 
+      if !defined($page_ref) && $w3http::plaintexthtml;
+
+    if ($w3http::plaintexthtml) {
+      # ark: this is where I want to do my changes to the page strip
+      # out the <!--NOMIRROR-->...<!--/NOMIRROR--> Stuff.
+      $$page_ref=~ s/<(!--)?\s*NO\s*MIRROR\s*(--)?>[^\000]*?<(!--)?\s*\/NO\s*MIRROR\s*(--)?>//g 
+	if $edit;
+	  
+      if ($header) {
+	# ark: insert a header string at the start of the page
+	my $mirrorstr=$header;
+	$mirrorstr =~ s/\$url/$rum_as_string/g;
+	insert_at_start( $mirrorstr, $page_ref );
+      }
+    }
+
+    write_page($lf_name,$page_ref,0);
+
+    # print "New urls: ",join("\n",@rum_newurls),"\n";
+
+    return @rum_newurls;
+  }
+
+  if ($w3http::result==304 || #  304 Not modified
+      $w3http::result==1304) { # 1304 Have it
+
+    { 
+      # last = out of nesting
+
+      my $rum_urlstat;
+      my $rum_newurls;
+      
+      @rum_newurls=();
+      
+      print STDERR ", not modified"
+	if $verbose>=0 && $w3http::result==304;
+      
+      $rum_urlstat{$rum_as_string}=$NOTMOD;
+
+      last unless $mine_urls;
+      
+      $rum_newurls=get_references($lf_name);
+
+      # print "New urls: ",ref($rum_newurls),"\n";
+      
+      if (!ref($rum_newurls)) {
+	last;
+      } elsif (ref($rum_newurls) eq 'SCALAR') {
+	$page_ref=$rum_newurls;
+      } elsif (ref($rum_newurls) eq 'ARRAY') {
+	@rum_newurls=@$rum_newurls;
+	last;
+      } else {
+	die "\nw3mir: internal error: Unknown return type from get_references\n";
+      }
+      
+      # Check if it's a html file.  I know this tag is in all html
+      # files, because I put it there as I pull them in.
+      last unless $$page_ref =~ /<HTML/i;
+      
+      warn "$lf_name is a html file\n" if $debug;
+      
+      # It's a html document
+      print STDERR ", mining URLs" if $verbose>=1;
+      
+      # This will give us a list of absolute urls
+      (undef,@rum_newurls) = 
+	&htmlop::process($$page_ref,$htmlop::NODOC,
+			 $htmlop::ABS,$rum_as_string,
+			 $htmlop::USESAVED,'W3MIR',
+			 $htmlop::LIST);
+    }
+
+    print STDERR "\n" if $verbose>=0;
+    return @rum_newurls;
+  }
+	
+  if ($w3http::result==302 || $w3http::result==301) { # Redirect
+    # Cern and NCSA httpd sends 302 'redirect' if a ending / is
+    # forgotten on a url.  More recent httpds send 301 'permanent
+    # redirect' in this case.  Here we check if the difference in URLs
+    # is just a / and if so push the url again with the / added.  This
+    # code only works if the http server has the right idea about its
+    # own name.
+    #
+    # 18/3/97: Added code to queue redirected-to-URLs that are within
+    # the scope of the retrival.
+    my $new_rum_url;
+
+    $rum_urlstat{$rum_as_string}=$REDIR;
+
+    # Absolutify the new url, it might be relative to the requested
+    # document.  That's a ugly wart on some servers/admins.
+    $new_rum_url=url $w3http::headval{'location'};
+    $new_rum_url=$new_rum_url->abs($rum_url_o);
+
+    print REDIRS $rum_as_string,' -> ',$new_rum_url->as_string,"\n"
+      if $fixup;
+
+    if ($immediate_redir) {
+      print STDERR " =>> ",$new_rum_url->as_string,", getting that instead\n";
+      return get_document($new_rum_url,$lf_url);
+    }
+
+    # Some redirect to a fragment of another doc...
+    $new_rum_url->frag(undef);
+    $new_rum_url=$new_rum_url->as_string;
+
+    if ($rum_as_string.'/' eq $new_rum_url) {
+      if (grep { $rum_as_string eq $_; } @root_urls) {
+	print STDERR "\nw3mir: missing / in a start URL detected.  Please fix commandline/config file.\n";
+	exit(1);
+      }
+      print STDERR ", missing /\n";
+      queue($new_rum_url);
+      # Initialize referer to something meaningful
+      $rum_referers{$new_rum_url}=$rum_referers{$rum_as_string};
+    } else {
+      print STDERR " =>> $new_rum_url";
+      if (want_this($new_rum_url)) {
+	print STDERR ", getting that\n";
+	queue($new_rum_url);
+	$rum_referers{$new_rum_url}=$rum_referers{$rum_as_string};
+      } else {
+	print STDERR ", don't want it\n";
+      }
+    }
+    return ();
+  }
+
+  if ($w3http::result==403 || # Forbidden
+      $w3http::result==404 || # Not found
+      $w3http::result==406 || # Not Acceptable, hmm, belongs here?
+      $w3http::result==410) { # Gone - no forwarding address known
+
+    $rum_urlstat{$rum_as_string}=$ENOTFND;
+    &handleerror;
+    print STDERR "Was refered from: ",
+      join(',',@{$rum_referers{$rum_as_string}}),
+      "\n" if defined(@{$rum_referers{$rum_as_string}});
+    return ();
+  }
+
+  if ($w3http::result==407) {
+    # Proxy authentication requested
+    die "Proxy server requests authentication but failed to return the\n".
+      "REQUIRED Proxy-Authenticate header for this condition\n"
+	unless exists($w3http::headval{'proxy-authenticate'});
+
+    die "Proxy authentication is required for ".$w3http::headval{'proxy-authenticate'}."\n";
+  }
+
+  if ($w3http::result==401) {
+    # A www-authenticate reply header should acompany a 401 message.
+    if (!exists($w3http::headval{'www-authenticate'})) {
+      warn "w3mir: Server indicated authentication failure but gave no www-authenticate reply\n";
+      $rum_urlstat{$rum_as_string}=$NEVERMIND;
+    } else {
+      # Unauthorized
+      if ($www_auth) {
+	# Failed when authorization data was supplied.
+	$rum_urlstat{$rum_as_string}=$NEVERMIND;
+	print STDERR ", authorization failed data needed for ",
+	$w3http::headval{'www-authenticate'},"\n"
+	  if ($verbose>=0);
+      } else {
+	if ($useauth) {
+	  # First time failure, send back and retry at once with some known
+	  # user/passwd.
+	  $www_auth=$w3http::headval{'www-authenticate'};
+	  print STDERR ", retrying with authorization\n" unless $verbose<0;
+	  goto try_again;
+	} else {
+	  print ", authorization needed: ",
+	    $w3http::headval{'www-authenticate'},"\n";
+	  $rum_urlstat{$rum_as_string}=$NEVERMIND;
+	}
+      }
+    }
+    return ();
+  }
+   
+  # Something else.  
+  &handleerror;
+}
+
+
+sub robot_check {
+  # Check if URL is allowed by robots.txt, if we respect it at all
+  # that is.  Return 1 it allowed, 0 otherwise.
+
+  my($rum_url_o)=shift;
+  my $hostport;
+
+  if ($check_robottxt) {
+    
+    $hostport = $rum_url_o->netloc;
+    if (!exists($gotrobots{$hostport})) {
+      # Get robots.txt from the server
+      $gotrobots{$hostport}=1;
+      my $robourl="http://$hostport/robots.txt";
+      print STDERR "w3mir: $robourl" if ($verbose>=0);
+      &w3http::query($w3http::GETURL,$robourl);
+      $w3http::document='' if ($w3http::result != 200);
+      print STDERR ", processing" if $verbose>=1;
+      print STDERR "\n" if ($verbose>=0);
+      $Robot_Blob->parse($robourl,$w3http::document);
+    }
+
+    if (!$Robot_Blob->allowed($rum_url_o->as_string)) {
+      # It is forbidden
+      $rum_urlstat{$rum_url_o->as_string}=$FROBOTS;
+      warn "w3mir: ",$rum_url_o->as_string,": forbidden by robots.txt\n";
+      return 0;
+    }
+  }
+  return 1;
+}
+
+
+
+sub batch_get {
+  # Batch get _one_ document.
+  my $rum_url=shift;
+  my $lf_url;
+
+  $rum_url_o = url $rum_url;
+
+  return unless robot_check($rum_url_o);
+
+  ($lf_url=$rum_url) =~ s~.*/~~;
+  if (!defined($lf_url) || $lf_url eq '') {
+    ($lf_url=$rum_url) =~ s~/$~~;
+    $lf_url =~ s~.*/~~;
+    $lf_url .= "-$indexname";
+  }
+
+  warn "Batch get: $rum_url -> $lf_url\n" if $debug;
+
+  $immediate_redir=1; # Do follow redirects immediately
+
+  get_document($rum_url,$lf_url);
+}
+
+
+
+sub mirror {
+  # Mirror (or get) the requested url(s). Possibly recursively.
+  # Working from whatever cwd is at invocation we'll retrieve all
+  # files under it in the file hierarchy.
+  
+  my $rum_url;	# URL of the document we're getting now, defined at main level
+  my $lf_url;	# rum_url after apply - and 
+  my $new_lf_url;
+  my @new_rum_urls;
+  my $rum_ref;
+  
+  while (defined($rum_url = pop(@rum_queue))) {
+
+    warn "mirror: Poped $rum_url from queue\n" if $debug;
+
+    # Unwanted URLs should not be queued
+    die "Found url $rum_url that I don't want in queue!\n" 
+      unless defined($lf_url=apply($rum_url));
+
+    $rum_url_o = url $rum_url;
+
+    next unless robot_check($rum_url_o);
+
+    # Figure out the filename for our local filesystem.
+    $lf_url.=$indexname if $lf_url =~ m~/$~ || $lf_url eq '';
+
+    @new_rum_urls = get_document($rum_url_o,$lf_url);
+
+    print join("\n",@new_rum_urls),"\n" if ($list);
+
+    if ($r) {
+      foreach $rum_ref (@new_rum_urls) {
+	# warn "Recursive url: $rum_ref\n";
+	$new_lf_url=apply($rum_ref);
+	next unless $new_lf_url;
+
+	# warn "Want it\n";
+	$rum_ref =~ s/\#.*$//s;		# Clip off section marks
+	
+	add_referer($rum_ref,$rum_url_o->as_string);
+	queue($rum_ref);
+      }
+    }
+
+    @new_rum_urls=();
+
+    # Is the URL queue empty? Are there outstanding retries?  Refill
+    # the queue from the retry list.
+    if ($#rum_queue<0 && $retry-->0) {
+      foreach $rum_url_o (keys %rum_urlstat) {
+	$rum_url_o = url $rum_url_o;
+	if ($rum_urlstat{$rum_url_o->as_string}==100) {
+	  push(@rum_queue,$rum_url_o->as_string);
+	  $rum_urlstat{$rum_url_o->as_string}=0;
+	}
+      }
+      if ($#rum_queue>=0) {
+	warn "w3mir: Sleeping before retrying.  $retry more times left\n"
+	  if $verbose>=0;
+	sleep($retryPause);
+      }
+    }
+
+  }
+}
+
+
+sub get_references {
+  # Get references from a non-html-on-disk file.  Return references if
+  # we know how to find them.  Return reference do the complete page
+  # if it's html.  Return single numerical 0 if unknown format.
+
+  my($lf_url)=shift;
+  my($urlextractor)=shift;
+
+  my $read; # Buffer of stuff read from file to check filetype
+  my $magic;
+  my $url_extractor;
+  my $rum_ref;
+  my $page;
+
+  warn "w3mir: Looking at local $lf_url\n" if $debug;
+	
+  # Open file and read the first 10kilobytes for file-type-test
+  # purposes.
+  if (!open(TMPF,$lf_url)) {
+    warn "Unable to open $lf_url for reading: $!\n";
+    last;
+  }
+	
+  $page=' 'x10240;
+  $read=sysread(TMPF,$page,length($page),0);
+  close(TMPF);
+	
+  die "Error reading $lf_url: $!\n" if (!defined($read));
+
+  if (!defined($url_extractor)) {
+    $url_extractor=0;
+
+    # Check file against list of magic numbers.
+    foreach $magic (keys %knownmagic) {
+      if (substr($page,0,length($magic)) eq $magic) {
+	$url_extractor = $knownformats{$knownmagic{$magic}};
+	last;
+      }
+    }
+  }
+
+  # Found a extraction method, apply.
+  if ($url_extractor) {
+    print STDERR ", mining URLs" if $verbose>=1;
+    return [&$url_extractor($lf_url)];
+  }
+
+  if ($page =~ /<HTML/i) {
+    open(TMPF,$lf_url) || 
+      die "Could not open $lf_url for reading: $!\n";
+    # read the whole file.
+    local($/)=undef;
+    $page = <TMPF>;
+    close(TMPF);
+    return \$page;
+  }
+
+  return 0;
+}
+
+
+sub open_fixup {
+  # Open the referers and redirects files
+
+  my $reffile='.referers';
+  my $redirfile='.redirs';
+
+  if ($win32) {
+    $reffile="referers";
+    $redirfile="redirs";
+  }
+
+  $nodelete{$reffile} = $nodelete{$redirfile} = 1;
+
+  open(REDIRS,"> $redirfile") || 
+    die "Could not open $redirfile for writing: $!\n";
+
+  autoflush REDIRS 1;
+
+  open(REFERERS,"> $reffile") ||
+    die "Could not open $reffile for writing: $!\n";
+
+  $fixopen=1;
+  eval 'END { close_fixup; 0; }';
+}
+
+
+sub close_fixup {
+  # Close the fixup data files.  In the case of the referer file also
+  # write the entire content
+
+  return unless $fixopen;
+
+  my $referer;
+
+  foreach $referer (keys %rum_referers) {
+    print REFERERS $referer," <- ",join(' ',@{$rum_referers{$referer}}),"\n";
+  }
+
+  close(REFERERS) || warn "Error closing referers file: $!\n";
+  close(REDIRS) || warn "Error closing redirects file: $!\n";
+  $fixopen=0;
+}
+
+
+sub clean_disk {
+  # This procedure removes files that are not present on the server(s)
+  # anymore.
+  
+  # - To avoid removing files that were not fetched due to network
+  #   problems we only do blanket removal IFF all documents were
+  #   fetched w/o problems, eventually.  
+  # - In any case we can remove files the server said were not found
+
+  # The strategy has three main parts:
+  # 1. Find all files we have
+  # 2. Find what files we ought to have
+  # 3. Remove the difference
+  
+  my $complete_retrival=1;	# Flag saying IFF all documents were fetched
+  my $urlstat;			# Tmp storage
+  my $rum_url;
+  my $lf_url;
+  my $lf_dir;
+  my $dirs_to_remove;
+
+  # For fileremoval code
+  eval "use File::Find;" unless defined(&find);
+
+  die "w3mir: Could not load File::Find module.  Don't use -R switch.\n"
+    unless defined(&find);
+  
+  # This to shut up -w
+  $lf_dir=$File::Find::dir;
+
+  # ***** 1. Find out what files we have *****
+  #
+  # This does two things:  For each file or directory found:
+  # - Increases entry count for the container directory
+  # - If it's a file: $lf_file{relative_path}=$FILEHERE;
+
+  chop(@root_dirs);
+  print STDERR "Looking in: ",join(", ",@root_dirs),"\n" if $debug;
+
+  find(\&find_files,@root_dirs);
+
+  # ***** 2. Find out what files we ought to have *****
+  #
+  # First we loop over %rum_urlstat to determine what files are not
+  # present on the server(s).
+  foreach $rum_url (keys %rum_urlstat) {
+    # Figure out name of local file from rum_url
+    next unless defined($lf_url=apply($rum_url));
+
+    $lf_url.=$indexname if $lf_url =~ m~/$~ || $lf_url eq '';
+
+    # find prefixes ./, we must too.
+    $lf_url="./".$lf_url unless substr($lf_url,0,1) eq '/';
+
+    # Ignore if file does not exist here.
+    next unless exists($lf_file{$lf_url});
+    
+    # The apply rules can map several remote files to same local
+    # file.  If we decided to keep file already we stay with that.
+    next if $lf_file{$lf_url}==$FILETHERE;
+    
+    $urlstat=$rum_urlstat{$rum_url};
+
+    # Figure out the status code.
+    if ($urlstat==$GOTIT || $urlstat==$NOTMOD) {
+      # Present on server.  Keep.
+      $lf_file{$lf_url}=$FILETHERE;
+      next;
+    } elsif ($urlstat==$ENOTFND || $urlstat==$NEVERMIND ) {
+      # One of: not on server, can't get, don't want, access forbiden:
+      # Schedule for removal.
+      $lf_file{$lf_url}=$FILEDEL if exists($lf_file{$lf_url});
+      next;
+    } elsif ($urlstat==$OTHERERR || $urlstat==$TERROR) {
+      # Some error occured transfering.
+      $complete_retrival=0;	# The retrival was not complete. Delete less
+    } elsif ($urlstat==$QUEUED) {
+      warn "w3mir: Internal inconsistency, $rum_url marked as queued after retrival terminated\n";
+      $complete_retrival=0;	# Fishy. Be conservative about removing
+    } else {
+      $complete_retrival=0;
+      warn "w3mir: Warning: $rum_url is marked as $urlstat.\n".
+	"w3mir: Please report to w3mir-core\@usit.uio.no.\n";
+    }
+  }				# foreach %rum_urlstat
+
+  # ***** 3. Remove the difference *****
+
+  # Loop over all found files:
+  # - Should we have this file?
+  # - If not: Remove file and decrease directory entry count
+  # Loop as long as there are directories with 0 entry count:
+  # - Loop over all directories with 0 entry count:
+  #   - Remove directory
+  #   - Decrease entry count of parent
+  
+  warn "w3mir: Some error occured, conservative file removal\n"
+    if !$complete_retrival && $verbose>=0;
+
+  # Remove all files we don't want removed from list of files present:
+  foreach $lf_url (keys %nodelete) {
+    print STDERR "Not deleting: $lf_url\n" if $verbose>=1;
+    delete $lf_file{$lf_url} || delete $lf_file{'./'.$lf_url};
+  }
+  
+  # Remove files
+  foreach $lf_url (keys %lf_file) {
+    if (($complete_retrival && $lf_file{$lf_url}==$FILEHERE) ||
+	($lf_file{$lf_url} == $FILEDEL)) {
+      if (unlink $lf_url) {
+	($lf_dir)= $lf_url =~ m~^(.+)/~;
+	$lf_dir{$lf_dir}--;
+	$dirs_to_remove=1 if ($lf_dir{$lf_dir}==0);
+	warn "w3mir: removed file $lf_url\n" if $verbose>=0;
+      } else {
+	warn "w3mir: removal of file $lf_url failed: $!\n";
+      }
+    }
+  }
+  
+  # Remove empty directories
+  while ($dirs_to_remove) {
+    $dirs_to_remove=0;
+    foreach $lf_url (keys %lf_dir) {
+      next if $lf_url eq '.';
+      if ($lf_dir{$lf_url}==0) {
+	if (rmdir($lf_url)) {
+	  warn "w3mir: removed directory $lf_dir\n" if $verbose>=0;
+	  delete $lf_dir{$lf_url};
+	  ($lf_dir)= $lf_url =~ m~^(.+)/~;
+	  $lf_dir{$lf_dir}--;
+	  $dirs_to_remove=1 if ($lf_dir{$lf_dir}==0);
+	} else {
+	  warn "w3mir: removal of directory $lf_dir failed: $!\n";
+	}
+      }
+    }
+  }
+}
+
+
+sub find_files {
+  # This is called by the find procedure for every file/dir found.
+  
+  # This builds two hashes:
+  # lf_file{<file>}: 1: file exists
+  # lf_dir{<dir>): Number of files in directory.
+  
+  lstat($_);
+
+  $lf_dir{$File::Find::dir}++;
+
+  if (-f _) {
+    $lf_file{$File::Find::name}=$FILEHERE;
+  } elsif (-d _) {
+    # null
+    # Bug: If an empty directory exists it will not be removed
+  } else {
+    warn "w3mir: File $File::Find::name has unknown type.  Ignoring.\n";
+  }
+  return 0;
+  
+}
+
+
+sub handleerror {
+  # Handle error status of last http connection, will set the rum_urlstat
+  # appropriately and print a error message.
+
+  my $msg;
+  
+  if ($verbose<0) {
+    $msg="w3mir: ".$rum_url_o->as_string.": ";
+  } else {
+    $msg=": ";
+  }
+
+  if ($w3http::result == 98) {
+    # OS/Network error
+    $msg .= "$!";
+    $rum_urlstat{$rum_url_o->as_string}=$OTHERERR;
+  } elsif ($w3http::result == 100) {
+    # Some kind of error connecting or sending request
+    $msg .= $w3http::restext || "Timeout";
+    $rum_urlstat{$rum_url_o->as_string}=$TERROR;
+  } else {
+    # Other HTTP error
+    $rum_urlstat{$rum_url_o->as_string}=$OTHERERR;
+    $msg .= " ".$w3http::result." ".$w3http::restext;
+    $msg .= " =>> ".$w3http::headval{'location'}
+    if (defined($w3http::headval{'location'}));
+  }
+  print STDERR "$msg\n";
+}
+
+
+sub queue {
+  # Queue given url if appropriate and create a status entry for it
+  my($rum_url_o)=url $_[0];
+
+  croak("BUG: undefined \$rum_url_o")
+    if !defined($rum_url_o);
+
+  croak("BUG: undefined \$rum_url_o->as_string")
+    if !defined($rum_url_o->as_string);
+
+  croak("BUG: ".$rum_url_o->as_string." (fragnent) queued")
+    if $rum_url_o->as_string =~ /\#/;
+  
+  return if exists($rum_urlstat{$rum_url_o->as_string});
+  return unless want_this($rum_url_o->as_string);
+
+  warn "QUEUED: ",$rum_url_o->as_string,"\n" if $debug;
+  
+  # Note lack of scope checks.
+  $rum_urlstat{$rum_url_o->as_string}=$QUEUED;
+  push(@rum_queue,$rum_url_o->as_string);
+}
+
+
+sub root_queue {
+  # Queue function for root urls and directories.  One or the other might
+  # be boolean false, in that case, don't queue it.
+
+  my $root_url_o;
+
+  my($root_url)=shift;
+  my($root_dir)=shift;
+
+  die "w3mir: No fragments in start URLs :".$root_url."\n"
+    if $root_url =~ /\#/;
+
+  if ($root_dir) {
+    print "Root dir: $root_dir\n" if $debug;
+    $root_dir="./$root_dir" unless substr($root_dir,0,1) eq '/' or
+      substr($root_dir,0,2) eq './';
+    push(@root_dirs,$root_dir);
+  }
+
+
+  if ($root_url) {
+    $root_url_o=url $root_url;
+
+    # URL canonification, or what we do of it at least.
+    $root_url_o->host($root_url_o->host);
+
+    warn "Root queue: ".$root_url_o->as_string."\n" if $debug;
+
+    push(@root_urls,$root_url_o->as_string); 
+
+    return $root_url_o;
+ }
+
+}
+
+
+sub write_page {
+  # write a retrieved page to wherever it's supposed to be written.
+  # Added difficulty: all files but plaintext files have already been
+  # written to disk in w3http.
+  
+  # $s == 0 save to disk
+  # $s == 1 dump to stdout
+  # $s == 2 forget
+
+  my($lf_name,$page_ref,$silent) = @_;
+  my($verb);
+
+  if ($silent) {
+    $verb=-1;
+  } else {
+    $verb=$verbose;
+  }
+
+#  confess("\n\$page_ref undefined") if !defined($page_ref);
+  
+  if ($w3http::plaintexthtml) {
+    # I have it in memory
+    if ($s==0) {
+      print STDERR ", saving" if $verb>0;
+
+      while (-d $lf_name) {
+	# This will run once, maybe twice, $fiddled will be canged the
+	# first time
+	if (exists($fiddled{$lf_name})) {
+	  warn "Cannot save $lf_name, there is a directory in the way\n";
+	  return;
+	}
+
+	$fiddled{$lf_name}=1;
+
+	rm_rf($lf_name);
+	print STDERR "w3mir: $lf_name" if $verbose>=0;
+      }
+
+      if (!open(PAGE,">$lf_name")) {
+	warn "\nw3mir: can't open $lf_name for writing: $!\n";
+	return;
+      }
+      if (!$convertnl) {
+	binmode PAGE;
+	warn "BINMODE\n" if $debug;
+      }
+      if ($$page_ref ne '') {
+	print PAGE $$page_ref || die "w3mir: Error writing $lf_name: $!\n";
+      }
+      close(PAGE) || die "w3mir: Error closing $lf_name: $!\n";
+      print STDERR ": ", length($$page_ref), " bytes\n"
+	if $verb>=0;
+      setmtime($lf_name,$w3http::headval{'last-modified'})
+	if exists($w3http::headval{'last-modified'});
+    } elsif ($s==1) {
+      print $$page_ref ;
+    } elsif ($s==2) {
+      print STDERR ", got and forgot it.\n" unless $verb<0;
+    }
+  } else {
+    # Already written by http module, just emit a message if wanted
+    if ($s==0) {
+      print STDERR ": ",$w3http::doclen," bytes\n"
+	if $verb>=0;
+      setmtime($lf_name,$w3http::headval{'last-modified'})
+	  if exists($w3http::headval{'last-modified'});
+    } elsif ($s==2) {
+      print STDERR ", got and forgot it.\n" if $verb>=0;
+    }
+  }
+}
+
+
+sub setmtime {
+  # Set mtime of the given file
+  my($file,$time)=@_;
+  my($tm_sec,$tm_min,$tm_hour,$tm_mday,$tm_mon,$tm_year,$tm_wday,$tm_yday,
+     $tm_isdst,$tics);
+
+  $tm_isdst=0;
+  $tm_yday=-1;
+
+  carp("\$time is undefined"),return if !defined($time);
+
+  $tics=str2time($time);
+  utime(time, $tics, $file) || 
+      warn "Could not change mtime of $file: $!\n";
+}
+
+
+sub movefile {
+  # Rename a file.  Note that copy is not a good alternative, since
+  # copying over NFS is something we want to Avoid.
+
+  # Returns 0 if failure and 1 in case of sucess.
+
+  (my $old,my $new) = @_;
+
+  # Remove anything that might have the name already.
+  if (-d $new) {
+    print STDERR "\n" if $verbose>=0;
+    rm_rf($new);
+    $fiddled{$new}=1;
+    print STDERR "w3mir: $new" if $verbose>=0;
+  } elsif (-e $new) {
+    $fiddled{$new}=1;
+    if (unlink($new)) {
+      print STDERR "\nw3mir: removed $new\nw3mir: $new"
+	if $verbose>=0;
+    } else {
+      return 0;
+    }
+
+  }
+
+  if ($new ne '-' && $new ne $nulldevice) {
+    warn "MOVING $old -> $new\n" if $debug;
+    rename($old,$new) || 
+      warn "Could not rename $old to $new: $!\n",return 0;
+  }
+  return 1;
+}
+
+
+sub mkdir {
+  # Make all intermediate directories needed for a file, the file name
+  # is expected to be included in the argument!
+
+  # Reasons for not using File::Path::mkpath:
+  # - I already wrote this.
+  # - I get to be able to produce as good and precise errormessages as
+  #   unix and perl will allow me.  mkpath will not.
+  # - It's easier to find out if it worked or not.
+  
+  my($file) = @_;
+  my(@dirs) = split("/",$file);
+  my $path;
+  my $dir;
+  my $moved=0;
+
+  if (!$dirs[0]) {
+    shift @dirs;
+    $path='';
+  } else {
+    $path = '.';
+  }
+
+  # This removes the last element of the array, it's meant to shave
+  # off the file name leaving only the directory name, as a
+  # convenience, for the caller.
+  pop @dirs;
+  foreach $dir (@dirs) {
+    $path .= "/$dir";
+    stat($path);
+    # only make if it isn't already there
+    next if -d _;
+
+    while (!-d _) {
+      if (exists($fiddled{$path})) {
+	warn "Cannot make directory $path, there is a file in the way.\n";
+	return;
+      }
+
+      $fiddled{$path}=1;
+
+      if (!-e _) {
+	mkdir($path,0777);
+	last;
+      }
+
+      if (unlink($path)) {
+	warn "w3mir: removed file $path\n" if $verbose>=0;
+      } else {
+	warn "Unable to remove $path: $!\n";
+	next;
+      }
+    
+      warn "mkdir $path\n" if $debug;
+      mkdir($path,0777) ||
+	warn "Unable to create directory $path: $!\n";
+
+      stat($path);
+    }
+  }
+}
+
+
+sub add_referer {
+  # Add a referer to the list of referers of a document.  Unless it's
+  # already there.
+  # Don't mail me if you (only) think this is a bit like a toungetwiser:
+
+  # Don't remember referers if BOTH fixup and referer header is disabled.
+  return if $fixup==0 && $do_referer==0;
+
+  my($rum_referee,$rum_referer) = @_ ;
+  my $re_rum_referer;
+
+  if (exists($rum_referers{$rum_referee})) {
+    $re_rum_referer=quotemeta $rum_referer;
+    if (!grep(m/^$re_rum_referer$/,@{$rum_referers{$rum_referee}})) {
+      push(@{$rum_referers{$rum_referee}},$rum_referer);
+      # warn "$rum_referee <- $rum_referer pushed\n";
+    } else {
+      # warn "$rum_referee <- $rum_referer NOT pushed\n";
+    }
+  } else {
+    $rum_referers{$rum_referee}=[$rum_referer];
+    # warn "$rum_referee <- $rum_referer pushed\n";
+  }
+}
+
+
+sub user_apply {
+  # Apply the user apply rules
+
+  return &$user_apply_code(shift);
+
+# Debug version:
+#  my ($foo,$bar);
+#  $foo=shift;
+#  $bar=&$apply_code($foo);
+#  print STDERR "Apply: $foo -> $bar\n";
+#  return $bar;
+}
+
+sub internal_apply {
+  # Apply the w3mir generated apply rules
+
+  return &$apply_code(shift);
+}
+
+
+sub apply {
+  # Apply the user apply rules.  Then if URL is wanted return result of
+  # w3mir apply rules.  Return the undefined value otherwise.
+
+  my $url = user_apply(shift);
+
+  return undef unless want_this($url);
+
+  internal_apply($url);
+}
+
+
+sub want_this {
+  # Find out if we want the url passed.  Just pass it on to the
+  # generated functions.
+  my($rum_url)=shift;
+
+  # What about robot rules?
+
+  # Does scope rule want this?
+  return &$scope_code($rum_url) &&
+    # Does user rule want this too?
+    &$rule_code($rum_url) 
+  
+}
+
+
+sub process_tag {
+  # Process a tag in html file
+  my $lf_referer = shift;	# User argument
+  my $base_url = shift;		# Not used... why not?
+  my $tag_name = shift;
+  my $url_attrs = shift;
+
+  # Retrun quickly if no URL attributes
+  return unless defined($url_attrs);
+
+  my $attrs = shift;
+
+  my $rum_url;	# The absolute URL
+  my $lf_url;	# The local filesystem url
+  my $lf_url_o; # ... and it's object
+  my $key;
+
+  print STDERR "\nProcess Tag: $tag_name, URL attributes: ", 
+  join(', ',@{$url_attrs}),"\nbase_url: ",$base_url,"\nlf_referer: ",
+  $lf_referer,"\n" 
+    if $debug>2;
+
+  $lf_referer =~ s~^/~~;
+  $lf_referer = "file:/$lf_referer";
+
+  foreach $key (@{$url_attrs}) {
+    if (defined($$attrs{$key})) {
+      $rum_url=$$attrs{$key};
+      printf STDERR "$key = $rum_url\n" if $debug;
+      $lf_url=apply($rum_url);
+      if (defined($lf_url)) {
+
+	printf STDERR "Transformed to $lf_url\n" if $debug>2;
+
+	$lf_url =~ s~^/~~;  # Remove leading / to avoid doubeling
+	$lf_url_o=url "file:/$lf_url";
+
+	# Save new value in the hash
+	$$attrs{$key}=($lf_url_o->rel($lf_referer))->as_string;
+	print STDERR "New value: ",$$attrs{$key},"\n" if $debug>2;
+
+	# If there is potential information loss save the old value too
+	$$attrs{"W3MIR".$key}=$rum_url if $infoloss;
+      }
+    }
+  }
+}
+
+
+sub version {
+  eval 'require LWP;';
+  print $w3mir_agent,"\n";
+  print "LWP version ",$LWP::VERSION,"\n" if defined $LWP::VERSION;
+  print "Perl version: ",$],"\n";
+  exit(0);
+}
+
+
+sub parse_args {
+  my $f;
+  my $i;
+
+  $i=0;
+
+  while ($f=shift) {
+    $i++;
+    $numarg++;
+    # This is a demonstration against Getopts::Long.
+    if ($f =~ s/^-+//) {
+      $s=1,next if $f eq 's';			# Stdout
+      $r=1,next if $f eq 'r';			# Recurse
+      $fetch=1,next if $f eq 'fa';		# Fetch all, no date test
+      $fetch=-1,next if $f eq 'fs';	# Fetch those we don't already have.
+      $verbose=-1,next if $f eq 'q'; 		# Quiet
+      $verbose=1,next if $f eq 'c';		# Chatty
+      &version,next if $f eq 'v';		# Version
+      $pause=shift,next if $f eq 'p';		# Pause between requests
+      $retryPause=shift,next if $f eq 'rp';	# Pause between retries.
+      $s=2,$convertnl=0,next if $f eq 'f';	# Forget
+      $retry=shift,next if $f eq 't';		# reTry
+      $list=1,next if $f eq 'l';		# List urls
+      $iref=shift,next if $f eq 'ir';		# Initial referer
+      $check_robottxt = 0,next if $f eq 'drr';	# Disable robots.txt rules.
+      umask(oct(shift)),next if $f eq 'umask';
+      parse_cfg_file(shift),next if $f eq 'cfgfile';
+      usage(),exit 0 if ($f eq 'help' || $f eq 'h' || $f eq '?');
+      $remove=1,next if $f eq 'R';
+      $cache_header = 'Pragma: no-cache',next if $f eq 'pflush';
+      $w3http::agent=$w3mir_agent=shift,next if $f eq 'agent';
+      $abs=1,next if $f eq 'abs';
+      $convertnl=0,$batch=1,next if $f eq 'B';
+      $read_urls = 1,next if $f eq 'I';
+      $convertnl=0,next if $f eq 'nnc';
+
+      if ($f eq 'lc') {
+	if ($i == 1) {
+	  $lc=1;
+	  $iinline=($lc?"(?i)":"");
+	  $ipost=($lc?"i":"");
+	  next;
+	} else {
+	  die "w3mir: -lc must be the first argument on the commandline.\n";
+	}
+      }
+
+      if ($f eq 'P') {				# Proxy
+	($w3http::proxyserver,$w3http::proxyport)= 
+	  shift =~ /([^:]+):?(\d+)?/;
+	$w3http::proxyport=80 unless $w3http::proxyport;
+	$using_proxy=1;
+	next;
+      }
+    
+      if ($f eq 'd') {		# Debugging level
+	$f=shift;
+	unless (($debug = $f) > 0) {
+	  die "w3mir: debug level must be a number greater than zero.\n";
+	}
+	next;
+      }
+
+      # Those were all the options...
+      warn "w3mir: Unknown option: -$f.  Use -h for usage info.\n";
+      exit(1);
+      
+    } elsif ($f =~ /^http:/) {
+      my ($rum_url_o,$rum_reurl,$rum_rebase,$server);
+
+      $rum_url_o=root_queue($f,'./');
+
+      $rum_rebase = quotemeta( ($rum_url_o->as_string =~ m~^(.*/)~)[0] );
+
+      push(@internal_apply,"s/^".$rum_rebase."//");
+      $scope_fetch.="return 1 if m/^".$rum_rebase."/".$ipost.";\n";
+      $scope_ignore.="return 0 if m/^".
+	quotemeta("http://".$rum_url_o->netloc."/")."/".$ipost.";\n";
+
+    } else {
+      # If we get this far then the commandline is broken
+      warn "Unknown commandline argument: $f.  Use -h for usage info.\n";
+      $numarg--;
+      exit(1);
+    }
+  }
+  return 1;
+}
+
+
+sub parse_cfg_file {
+  # Read the configuration file.  Aborts on errors.  Not good to
+  # mirror something using the wrong config.
+
+  my ( $file ) = @_ ;
+  my ($key, $value, $authserver,$authrealm,$authuser,$authpasswd);
+  my $i;
+
+  die "w3mir: config file $file is not a file.\n" unless -f $file;
+  open(CFGF, $file) || die "Could not open config file $file: $!\n";
+
+  $i=0;
+
+  while (<CFGF>) {
+    # Trim off various junk
+    chomp;
+    s/^#.*//;
+    s/^\s+|\s$//g;
+    # Anything left?
+    next if $_ eq '';
+    # Examine remains
+    $i++;
+    $numarg++;
+
+    ($key, $value) = split(/\s*:\s*/,$_,2);
+    $key = lc $key;
+
+    $iref=$value,next if ( $key eq 'initial-referer' );
+    $header=$value,next if ( $key eq 'header' );
+    $pause=numeric($value),next if ( $key eq 'pause' );
+    $retryPause=numeric($value),next if ( $key eq 'retry-pause' );
+    $debug=numeric($value),next if ( $key eq 'debug' );
+    $retry=numeric($value),next if ( $key eq 'retries' );
+    umask(numeric($value)),next if ( $key eq 'umask' );
+    $check_robottxt=boolean($value),next if ( $key eq 'robot-rules' );
+    $edit=boolean($value),next if ($key eq 'remove-nomirror');
+    $indexname=$value,next if ($key eq 'index-name');
+    $s=nway($value,'save','stdout','forget'),next 
+      if ( $key eq 'file-disposition' );
+    $verbose=nway($value,'quiet','brief','chatty')-1,next
+      if ( $key eq 'verbosity' );
+    $w3http::proxyuser=$value,next if $key eq 'http-proxy-user';
+    $w3http::proxypasswd=$value,next if $key eq 'http-proxy-passwd';
+
+    if ( $key eq 'cd' ) {
+      $chdirto=$value;
+      warn "Use of 'cd' is discouraged\n" unless $verbose==-1;
+      next;
+    }
+    
+    if ($key eq 'http-proxy') {
+      ($w3http::proxyserver,$w3http::proxyport)= 
+	$value =~ /([^:]+):?(\d+)?/;
+      $w3http::proxyport=80 unless $w3http::proxyport;
+      $using_proxy=1;
+      next;
+    }
+
+    if ($key eq 'proxy-options') {
+      my($val,$nval,@popts,$pragma);
+      $pragma=1;
+      foreach $val (split(/\s*,\*/,lc $value)) {
+	$nval=nway($val,'no-pragma','revalidate','refresh','no-store',);
+	# Force use of Cache-control: header
+	$pragma=0 if ($nval==0);
+	# use to force proxy to revalidate
+	$pragma=0,push(@popts,'max-age=0') if ($nval==1);
+	# use to force proxy to refresh
+	push(@popts,'no-cache') if ($nval==2);
+	# use if information transfered is sensitive
+	$pragma=0,push(@popts,'no-store') if ($nval==3);
+      }
+      $cache_header=($pragma?'Pragma: ':'Cache-control: ').join(', ',@popts);
+      next;
+    }
+
+
+    if ($key eq 'url') {
+      my ($rum_url_o,$lf_dir,$rum_reurl,$rum_rebase);
+
+      # A two argument URL: line?
+      if ($value =~ m/^(.+)\s+(.+)/i) {
+	# Two arguments.
+	# The last is a directory, it must end in /
+	$lf_dir=$2;
+	$lf_dir.='/' unless $lf_dir =~ m~/$~;
+
+	$rum_url_o=root_queue($1,$lf_dir);
+
+	# The first is a URL, make it more canonical, find the base.
+	# The namespace confusion in this section is correct.(??)
+	$rum_rebase = quotemeta( ($rum_url_o->as_string =~ m~^(.*/)~)[0] );
+
+	# print "URL: ",$rum_url_o->as_string,"\n";
+	# print "Base: $rum_rebase\n";
+
+	# Translate from rum space to lf space:
+	push(@internal_apply,"s/^".$rum_rebase."/".quotemeta($lf_dir)."/");
+
+	# That translation could lead to information loss.
+	$infoloss=1;
+
+	# Fetch rules tests the rum_url_o->as_string.  Fetch whatever
+	# matches the base.
+	$scope_fetch.="return 1 if m/^".$rum_rebase."/".$ipost.";\n";
+
+	# Ignore whatever did not match the base.
+	$scope_ignore.="return 0 if m/^".
+	  quotemeta("http://".$rum_url_o->netloc."/")."/".$ipost.";\n";
+
+      } else {
+	$rum_url_o=root_queue($value,'./');
+
+	$rum_rebase = quotemeta( ($rum_url_o->as_string =~ m~^(.*/)~)[0] );
+
+	# Translate from rum space to lf space:
+	push(@internal_apply,"s/^".$rum_rebase."//");
+
+	$scope_fetch.="return 1 if m/^".$rum_rebase."/".$ipost.";\n";
+	$scope_ignore.="return 0 if m/^".
+	  quotemeta("http://".$rum_url_o->netloc."/")."/".$ipost.";\n";
+      }
+      next;
+    }
+
+    if ($key eq 'also-quene') {
+      print STDERR 
+	"Found 'also-quene' keyword, please replace with 'also-queue'\n";
+      $key='also-queue';
+    }
+
+    if ($key eq 'also' || $key eq 'also-queue') {
+      if ($value =~ m/^(.+)\s+(.+)/i) {
+	my ($rum_url_o,$lf_dir,$rum_reurl,$rum_rebase);
+	# Two arguments.
+	# The last is a directory, it must end in /
+	# print STDERR "URL ",$1," DIR ",$2,"\n";
+	$lf_dir=$2;
+	$lf_dir.='/' unless $lf_dir =~ m~/$~;
+
+	if ($key eq 'also-queue') {
+	  $rum_url_o=root_queue($1,$lf_dir);
+	} else {
+	  root_queue("",$lf_dir);
+	  $rum_url_o=url $1;
+	  $rum_url_o->host(lc $rum_url_o->host);
+	}
+
+	# The first is a URL, find the base
+	$rum_rebase = quotemeta( ($rum_url_o->as_string =~ m~^(.*/)~)[0] );
+
+#	print "URL: $rum_url_o->as_string\n";
+#	print "Base: $rum_rebase\n";
+#	print "Server: $server\n";
+
+	# Ok, now we can transform and select stuff the right way
+	push(@internal_apply,"s/^".$rum_rebase."/".quotemeta($lf_dir)."/");
+	$infoloss=1;
+
+	# Fetch rules tests the rum_url_o->as_string.  Fetch whatever
+	# matches the base.
+	$scope_fetch.="return 1 if m/^".$rum_rebase."/".$ipost.";\n";
+
+	# Ignore whatever did not match the base.  This cures problem
+	# with '..' from base in in rum space pointing within the the
+	# scope in ra space.  We introduced a extra level (or more) of
+	# directories with the apply above.  Must do same with 'Also:'
+	# directives.
+	$scope_ignore.="return 0 if m/^".
+	  quotemeta("http://".$rum_url_o->netloc."/")."/".$ipost.";\n";
+      } else {
+	die "Also: requires 2 arguments\n";
+      }
+      next;
+    }
+
+    if ($key eq 'quene') {
+      print STDERR "Found 'quene' keyword, please replace with 'queue'\n";
+      $key='queue';
+    }
+
+    if ($key eq 'queue') {
+      root_queue($value,"");
+      next;
+    }
+
+    if ($key eq 'ignore-re' || $key eq 'fetch-re') {
+      # Check that it's a re, better that I am strict than for perl to
+      # make compilation errors.
+      unless ($value =~ /^m(.).*\1[gimosx]*$/) {
+	print STDERR "w3mir: $value is not a recognized regular expression\n";
+	exit 1;
+      }
+      # Fall-through to next cases!
+    }
+
+    if ($key eq 'fetch' || $key eq 'fetch-re') {
+      my $expr=$value;
+      $expr = wild_re($expr).$ipost if ($key eq 'fetch');
+      $rule_text.=' return 1 if '.$expr.";\n";
+      next;
+    }
+
+    if ($key eq 'ignore' || $key eq 'ignore-re') {
+      my $expr=$value;
+      $expr = wild_re($expr).$ipost if ($key eq 'ignore');
+      # print STDERR "Ignore expression: $expr\n";
+      $rule_text.=' return 0 if '.$expr.";\n";
+      next;
+    }
+
+
+    if ($key eq 'apply') {
+      unless ($value =~ /^s(.).*\1.*\1[gimosxe]*$/) {
+	print STDERR
+	  "w3mir: '$value' is not a recognized regular expression\n";
+	exit 1;
+      }
+      push(@user_apply,$value) ;
+      $infoloss=1;
+      next;
+    }
+
+    if ($key eq 'agent') {
+      $w3http::agent=$w3mir_agent=$value;
+      next;
+    }
+
+    # The authorization stuff:
+    if ($key eq 'auth-domain') {
+      $useauth=1;
+      ($authserver, $authrealm) = split('/',$value,2);
+      die "w3mir: server part of auth-domain has format server[:port]\n"
+	unless $authserver =~ /^(\S+(:\d+)?)$|^\*$/;
+      $authserver =~ s/:80$//;
+      die "w3mir: auth-domain '$value' is not valid\n"
+	if !defined($authserver) || !defined($authrealm);
+      $authrealm=lc $authrealm;
+    }
+
+    $authuser=$value if ($key eq 'auth-user');
+    $authpasswd=$value if ($key eq 'auth-passwd');
+
+    # Got a full authentication spec?
+    if ($authserver && $authrealm && $authuser && $authpasswd) {
+      $authdata{$authserver}{$authrealm}=$authuser.":".$authpasswd;
+      print "Authentication for $authserver/$authrealm is ".
+	"$authuser/$authpasswd\n" if $verbose>=0;
+      # exit;
+      # Invalidate tmp vars
+      $authserver=$authrealm=$authuser=$authpasswd=undef;
+      next;
+    }
+
+    next if $key eq 'auth-user' || $key eq 'auth-passwd' || 
+      $key eq 'auth-domain';
+
+    if ($key eq 'fetch-options') {
+      warn "w3mir: The 'fetch-options' directive has been renamed to 'options'\nw3mir: Please change your configuration file.\n";
+      $key='options';
+      # Fall through to 'options'!
+    }
+
+    if ($key eq 'options') {
+      
+      my($val,$nval);
+      foreach $val (split(/\s*,\s*/,lc $value)) {
+	if ($i==1) {
+	  $nval=nway($val,'recurse','no-date-check','only-nonexistent',
+		     'list-urls','lowercase','remove','batch','read-urls',
+		     'abs','no-newline-conv');
+	  $r=1,next if $nval==0;
+	  $fetch=1,next if $nval==1;
+	  $fetch=-1,next if $nval==2;
+	  $list=1,next if $nval==3;
+	  if ($nval==4) {
+	    $lc=1;
+	    $iinline=($lc?"(?i)":"");
+	    $ipost=($lc?"i":"");
+	    next ;
+	  }
+	  $remove=1,next if $nval==5;
+	  $convertnl=0,$batch=1,next if $nval==6;
+	  $read_urls=1,next if $nval==7;
+	  $abs=1,next if $nval==8;
+	  $convertnl=0,next if $nval==9;
+        } else {
+	    die "w3mir: options must be the first directive in the config file.\n";
+	}
+      }
+      next;
+    }
+
+    if ($key eq 'disable-headers') {
+      my($val,$nval);
+      foreach $val (split(/\s*,\s*/,lc $value)) {
+	$nval=nway($val,'referer','user');
+	$do_referer=0,next if $nval==0;
+	$do_user=0,next if $nval==1;
+      }
+      next;
+    }
+
+
+    if ($key eq 'fixup') {
+
+      $fixrc="$file";
+      # warn "Fixrc: $fixrc\n";
+
+      my($val,$nval);
+      foreach $val (split(/\s*,\s*/,lc $value)) {
+	$nval=nway($val,'on','run','noindex','off');
+	$runfix=1,next if $nval==1;
+	# Disable fixup
+	$fixup=0,next if $nval==3;
+	# Ignore everyting else
+      }
+      next;
+    }
+
+    die "w3mir: Unrecognized directive ('$key') in config file $file at line $.\n";
+
+  }
+  close(CFGF);
+
+  if (defined($w3http::proxypasswd) && $w3http::proxyuser) {
+    warn "Proxy authentication: ".$w3http::proxyuser.":".
+      $w3http::proxypasswd."\n" if $verbose>=0;
+  }
+
+}
+
+
+sub wild_re {
+  # Here we translate unix wildcard subset to to perlre
+  local($_) = shift;
+
+  # Quote anything that's RE and not wildcard: / ( ) \ | { } + $ ^
+  s~([\/\(\)\\\|\{\}\+)\$\^])~\\$1~g;
+  # . -> \.
+  s~\.~\\.~g;
+  # * -> .*
+  s~\*~\.\*~g;
+  # ? -> .
+  s~\?~\.~g;
+
+  # print STDERR "wild_re: $_\n";
+
+  return $_ = '/'.$_.'/';
+}
+
+
+sub numeric {
+  # Check if argument is numeric?
+  my ( $number ) = @_ ;
+  return oct($number) if ($number =~ /\d+/ || $number =~ /\d+.\d+/);
+  die "Expected a number, got \"$number\"\n";
+}
+
+
+sub boolean {
+  my ( $boolean ) = @_ ;
+
+  $boolean = lc $boolean;
+
+  return 0 if ($boolean eq 'false' || $boolean eq 'off' || $boolean eq '0');
+  return 1 if ($boolean eq 'true' || $boolean eq 'on' || $boolean eq '1');
+  die "Expected a boolean, got \"$boolean\"\n";
+}
+
+
+sub nway {
+  my ( $value ) = shift;
+  my ( @values ) = @_;
+  my ( $val ) = 0;
+
+  $value = lc $value;
+  while (@_) {
+    return $val if $value eq shift;
+    $val++;
+  }
+  die "Expected one of ".join(", ",@values).", got \"$value\"\n";
+}
+
+
+sub insert_at_start {
+  # ark: inserts the first arg at the top of the html in the second arg
+  # janl: The second arg must be a reference to a scalar.
+  my( $str, $text_ref ) = @_;
+  my( @possible ) =("<BODY.*?>", "</HEAD.*?>", "</TITLE.*?>", "<HTML.*?>" );
+  my( $f, $done );
+  
+  $done=0;
+  @_=@possible;
+  
+  while( $done!=1 && ($f=shift) ){
+    print "Searching for: $f\n";
+    if( $$text_ref =~ /$f/i ){
+      print "found it!\n";
+      $$text_ref =~ s/($f)/$1\n$str/i;
+      $done=1;
+    }
+  }
+}
+
+
+
+sub rm_rf {
+  # Recursively remove directories and other files
+  # File::Path::rmtree does a similar thing but the messages are wrong
+
+  my($remove)=shift;
+
+  eval "use File::Find;" unless defined(&finddepth);
+
+  die "w3mir: Could not load File::Find module when trying to remove $remove\n"
+    unless defined(&find);
+
+  finddepth(\&remove_everything,$remove);
+
+  if (rmdir($remove)) {
+    print STDERR "\nw3mir: removed directory $remove\n" if $verbose>=0;
+  } else {
+    print STDERR "w3mir: could not remove $remove: $!\n";
+  }
+}
+
+
+sub remove_everything {
+  # This does the removal
+  ((-d && rmdir($_)) || unlink($_)) && $verbose>=0 &&
+    print STDERR "w3mir: removed $File::Find::name\n";
+}
+
+
+
+sub usage {
+  my($message)=shift @_;
+
+  print STDERR "w3mir: $message\n" if $message;
+  
+  die 'w3mir: usage: w3mir [options] <single-http-url>
+          or: w3mir -B [-I] [options] [<http-urls>]
+
+    Options :
+	-agent <agent>	- Set the agent name.  Default is w3mir
+	-abs		- Force all URLs to be absolute.
+	-B		- Batch-get documents.
+	-I		- The URLs to get are read from standard input.
+	-c		- be more Chatty.
+	-cfgfile <file> - Read config from file
+	-d <debug-level>- set debug level to 1 or 2
+	-drr		- Disable robots.txt rules.
+	-f		- Forget all files, nothing is saved to disk.
+	-fa		- Fetch All, will not check timestamps.
+	-fs		- Fetch Some, do not fetch the files we already have.
+	-ir <referer>	- Initial referer.  For picky servers.
+	-l		- List URLs in the documents retrived.
+	-lc		- Convert all URLs (and filenames) to lowercase.
+				This does not work reliably.
+	-p <n>		- Pause n seconds before retriving each doc.
+	-q		- Quiet, error-messages only
+        -rp <n>		- Retry Pause in seconds.
+	-P <server:port>- Use host/port for proxy http requests
+        -pflush		- Flush proxy server.
+	-r		- Recursive mirroring.
+        -R		- Remove files not referenced or not present on server.
+	-s		- Send output to stdout instead of file
+	-t <n>		- How many times to (re)try getting a failed doc?
+        -umask <umask>  - Set umask for mirroring, must be usual octal format.
+	-nnc		- No Newline Conversion.  Disable newline conversions.
+	-v		- Show w3mir version.
+';
+}
+__END__
+# -*- perl -*- There must be a blank line here
+
+=head1 NAME
+
+w3mir - all purpose HTTP-copying and mirroring tool
+
+=head1 SYNOPSIS
+
+B<w3mir> [B<options>] [I<HTTP-URL>]
+
+B<w3mir> B<-B> [B<options>] <I<HTTP-URLS>>
+
+B<w3mir> is a all purpose HTTP copying and mirroring tool.  The
+main focus of B<w3mir> is to create and maintain a browsable copy of
+one, or several, remote WWW site(s).
+
+Used to the max w3mir can retrive the contents of several related
+sites and leave the mirror browseable via a local web server, or from
+a filesystem, such as directly from a CDROM.  
+
+B<w3mir> has options for all operations that are simple enough for
+options.  For authentication and passwords, multiple site retrievals
+and such you will have to resort to a L</CONFIGURATION-FILE>.  If
+browsing from a filesystem references ending in '/' needs to be
+rewritten to end in '/index.html', and in any case, if there are URLs
+that are redirected will need to be changed to make the mirror
+browseable, see the documentation of B<Fixup> in the
+L</CONFIGURATION-FILE> secton.
+
+B<w3mir>s default behavior is to do as little as possible and to be as
+nice as possible to the server(s) it is getting documents from.  You
+will need to read through the options list to make B<w3mir> do more
+complex, and, useful things.  Most of the things B<w3mir> can do is
+also documented in the w3mir-HOWTO which is available at the B<w3mir>
+home-page (F<http://www.math.uio.no/~janl/w3mir/>) as well as in the
+w3mir distribution bundle.
+
+=head1 DESCRIPTION
+
+You may specify many options and one HTTP-URL on the w3mir
+command line.
+
+A single HTTP URL I<must> be specified either on the command line or
+in a B<URL> directive in a configuration file.  If the URL refers to a
+directory it I<must> end with a "/", otherwise you might get surprised
+at what gets retrieved (e.g. rather more than you expect).
+
+Options must be prefixed with at least one - as shown below, you can
+use more if you want to. B<-cfgfile> is equivalent to B<--cfgfile> or
+even B<------cfgfile>.  Options cannot be I<clustered>, i.e., B<-r -R>
+is not equivalent to B<-rR>.
+
+=over 4
+
+=item B<-h> | B<-help> | B<-?>
+
+prints a brief summary of all command line options and exits.
+
+=item B<-cfgfile> F<file>
+
+Makes B<w3mir> read the given configuration file.  See the next section
+for how to write such a file.
+
+=item B<-r>
+
+Puts B<w3mir> into recursive mode.  The default is to fetch only one
+document and then quit.  'I<recursive>' mode means that all the
+documents linked to the given document that are fetched, and all they
+link to in turn and so on.  But only I<Iff> they are in the same
+directory or under the same directory as the start document.  Any
+document that is in or under the starting documents directory is said
+to be within the I<scope of retrieval>.
+
+=item B<-fa>
+
+Fetch All.  Normally B<w3mir> will only get the document if it has been
+updated since the last time it was fetched.  This switch turns that
+check off.
+
+=item B<-fs>
+
+Fetch Some.  Not the opposite of B<-fa>, but rather, fetch the ones we
+don't have already.  This is handy to restart copying of a site
+incompletely copied by earlier, interrupted, runs of B<w3mir>.
+
+=item B<-p> I<n>
+
+Pause for I<n> seconds between getting each document.  The default is
+30 seconds.
+
+=item B<-rp> I<n>
+
+Retry Pause, in seconds.  When B<w3mir> fails to get a document for some
+technical reason (timeout mainly) the document will be queued for a
+later retry.  The retry pause is how long B<w3mir> waits between
+finishing a mirror pass before starting a new one to get the still
+missing documents.  This should be a long time, so network conditions
+have a chance to get better.  The default is 600 seconds (10 minutes),
+which might be a bit too short, for batch running B<w3mir> I would
+suggest an hour (3600 seconds) or more.
+
+=item B<-t> I<n>
+
+Number of reTries.  If B<w3mir> cannot get all the documents by the
+I<n>th retry B<w3mir> gives up.  The default is 3.
+
+=item B<-drr>
+
+Disable Robot Rules.  The robot exclusion standard is described in
+http://info.webcrawler.com/mak/projects/robots/norobots.html.  By
+default B<w3mir> honors this standard.  This option causes B<w3mir> to
+ignore it.
+
+=item B<-nnc>
+
+No Newline Conversion.  Normally w3mir converts the newline format of
+all files that the web server says is a text file.  However, not all
+web servers are reliable, and so binary files may become corrupted due
+to the newline conversion w3mir performs.  Use this option to stop
+w3mir from converting newlines.  This also causes the file to be
+regarded as binary when written to disk, to disable the implicit
+newline conversion when saving text files on most non-Unix systems.
+
+This will probably be on by default in version 1.1 of w3mir, but not
+in version 1.0.
+
+=item B<-R>
+
+Remove files.  Normally B<w3mir> will not remove files that are no
+longer on the server/part of the retrieved web of files.  When this
+option is specified all files no longer needed or found on the servers
+will be removed.  If B<w3mir> fails to get a document for I<any> other
+reason the file will not be removed.
+
+=item B<-B>
+
+Batch fetch documents whose URLs are given on the commandline.
+
+In combination with the B<-r> and/or B<-l> switch all HTML and PDF
+documents will be mined for URLs, but the documents will be saved on
+disk unchanged.  When used with the B<-r> switch only one single URL
+is allowed.  When not used with the B<-r> switch no HTML/URL
+processing will be performed at all.  When the B<-B> switch is used
+with B<-r> w3mir will not do repeated mirrorings reliably since the
+changes w3mir needs to do, in the documents, to work reliably are not
+done.  In any case it's best not to use B<-R> in combination with
+B<-B> since that can result in deleting rather more documents than
+expected.  Hwowever, if the person writing the documents being copied
+is good about making references relative and placing the <HTML> tag at
+the beginning of documents there is a fair chance that things will
+work even so.  But I wouln't bet on it.  It will, however, work
+reliably for repeated mirroring if the B<-r> switch is not used.
+
+When the B<-B> switch is specified redirects for a given document will
+be followed no matter where they point.  The redirected-to document
+will be retrieved in the place of the original document.  This is a
+potential weakness, since w3mir can be directed to fetch any document
+anywhere on the web.
+
+Unless used with B<-r> all retrived files will be stored in one
+directory using the remote filename as the local filename.  I.e.,
+F<http://foo/bar/gazonk.html> will be saved as F<gazonk.html>.
+F<http://foo/bar/> will be saved as F<bar-index.html> so as to avoid
+name colitions for the common case of URLs ending in /.
+
+=item B<-I>
+
+This switch can only be used with the B<-B> switch, and only after it
+on the commandline or configuration file.  When given w3mir will get
+URLs from standard input (i.e., w3mir can be used as the end of a pipe
+that produces URLs.)  There should only be one URL pr. line of input.
+
+=item B<-q>
+
+Quiet.  Turns off all informational messages, only errors will be
+output.
+
+=item B<-c>
+
+Chatty.  B<w3mir> will output more progress information.  This can be
+used if you're watching B<w3mir> work.
+
+=item B<-v>
+
+Version.  Output B<w3mir>s version.
+
+=item B<-s>
+
+Copy the given document(s) to STDOUT.
+
+=item B<-f>
+
+Forget.  The retrieved documents are not saved on disk, they are just
+forgotten.  This can be used to prime the cache in proxy servers, or
+not save documents you just want to list the URLs in (see B<-l>).
+
+=item B<-l>
+
+List the URLs referred to in the retrieved document(s) on STDOUT.
+
+=item B<-umask> I<n>
+
+Sets the umask, i.e., the permission bits of all retrieved files.  The
+number is taken as octal unless it starts with a 0x, in which case
+it's taken as hexadecimal.  No matter what you set this to make sure
+you get write as well as read access to created files and directories.
+
+Typical values are: 
+
+=over 8
+
+=item 022
+
+let everyone read the files (and directories), only you can change
+them. 
+
+=item 027
+
+you and everyone in the same file-group as you can read, only you can
+change them.
+
+=item 077
+
+only you can read the files, only you can change them.
+
+=item 0
+
+everyone can read, write and change everything.
+
+=back
+
+The default is whatever was set when B<w3mir> was invoked.  022 is a
+reasonable value.
+
+This option has no meaning, or effect, on Win32 platforms.
+
+=item B<-P> I<server:port>
+
+Use the given server and port is a HTTP proxy server.  If no port is
+given port 80 is assumed (this is the normal HTTP port).  This is
+useful if you are inside a firewall, or use a proxy server to save
+bandwidth.
+
+=item B<-pflush>
+
+Proxy flush, force the proxy server to flush it's cache and re-get the
+document from the source.  The I<Pragma: no-cache> HTTP/1.0 header is
+used to implement this.
+
+=item B<-ir> I<referrer>
+
+Initial Referrer.  Set the referrer of the first retrieved document.
+Some servers are reluctant to serve certain documents unless this is
+set right.
+
+=item B<-agent> I<agent>
+
+Set the HTTP User-Agent fields value.  Some servers will serve
+different documents according to the WWW browsers capabilities.
+B<w3mir> normally has B<w3mir>/I<version> in this header field.
+Netscape uses things like B<Mozilla/3.01 (X11; I; Linux 2.0.30 i586)>
+and MSIE uses things like B<Mozilla/2.0 (compatible; MSIE 3.02;
+Windows NT)> (remember to enclose agent strings with spaces in with
+double quotes ("))
+
+=item B<-lc>
+
+Lower Case URLs. Some OSes, like W95 and NT, are not case sensitive
+when it comes to filenames.  Thus web masters using such OSes can case
+filenames differently in different places (apps.html, Apps.html,
+APPS.HTML).  If you mirror to a Unix machine this can result in one
+file on the server becoming many in the mirror.  This option
+lowercases all filenames so the mirror corresponds better with the
+server.
+
+If given it must be the first option on the command line.
+
+This option does not work perfectly.  Most especially for mixed case
+host-names.
+
+=item B<-d> I<n>
+
+Set the debug level.  A debug level higher than 0 will produce lots of
+extra output for debugging purposes.
+
+=item B<-abs>
+
+Force all URLs to be absolute.  If you retrive
+F<http://www.ifi.uio.no/~janl/index.html> and it references foo.html
+the referense is absolutified into
+F<http://www.ifi.uio.no/~janl/foo.html>.  In other words, you get
+absolute references to the origin site if you use this option.
+
+=back
+
+=head1 CONFIGURATION-FILE
+
+Most things can be mirrored with a (long) command line.  But multi
+server mirroring, authentication and some other things are only
+available through a configuration file.  A configuration file can
+either be specified with the B<-cfgfile> switch, but w3mir also looks
+for .w3mirc (w3mir.ini on Win32 platforms) in the directory where
+w3mir is started from.
+
+The configuration file consists of lines of comments and directives.
+A directive consists of a keyword followed by a colon (:) and then one
+or several arguments.
+
+ # This is a comment.  And the next line is a directive:
+ Options: recurse, remove
+
+A comment can only start at the beginning of a line.  The directive
+keywords are not case-sensitive, but the arguments I<might> be.
+
+=over 4
+
+=item Options: I<recurse> | I<no-date-check> | I<only-nonexistent> | I<list-urls> | I<lowercase> | I<remove> | I<batch> | I<input-urls> | I<no-newline-conv>
+
+This must be the first directive in a configuration file.  
+
+=over 8
+
+=item I<recurse>
+
+see B<-r> switch.
+
+=item I<no-date-check>
+
+see B<-fa> switch.
+
+=item I<only-nonexistent>
+
+see B<-fs> switch.
+
+=item I<list-urls>
+
+see B<-l> option.
+
+=item I<lowercase>
+
+see B<-lc> option. 
+
+=item I<remove>
+
+see B<-R> option.
+
+=item I<batch>
+
+see B<-B> option.
+
+=item I<input-urls>
+
+see B<-I> option.
+
+=item I<no-newline-conv>
+
+see B<-nnc> option.
+
+=back
+
+=item URL: I<HTTP-URL> [I<target-directory>]
+
+The URL directive may only appear once in any configuration file.
+
+Without the optional target directory argument it corresponds directly
+to the I<single-HTTP-URL> argument on the command line.  
+
+If the optional target directory is given all documents from under the
+given URL will be stored in that directory, and under.  The target
+directory is most likely only specified if the B<Also> directive is
+also specified.
+
+If the URL given refers to a directory it I<must> end in a "/",
+otherwise you might get quite surprised at what gets retrieved.
+
+Either one URL: directive or the single-HTTP-URL at the command-line
+I<must> be given.
+
+=item Also: I<HTTP-URL directory>
+
+This directive is only meaningful if the I<recurse> (or B<-r>)
+option is given.
+
+The directive enlarges the scope of a recursive retrieval to contain
+the given HTTP-URL and all documents in the same directory or under.
+Any documents retrieved because of this directive will be stored in the
+given directory of the mirror.
+
+In practice this means that if the documents to be retrieved are stored
+on several servers, or in several hierarchies on one server or any
+combination of those.  Then the B<Also> directive ensures that we get
+everything into one single mirror.
+
+This also means that if you're retrieving
+
+  URL: http://www.foo.org/gazonk/
+
+but it has inline icons or images stored in http://www.foo.org/icons/
+which you will also want to get, then that will be retrieved as well by
+entering
+
+  Also: http://www.foo.org/icons/ icons
+
+As with the URL directive, if the URL refers to a directory it I<must>
+end in a "/".
+
+Another use for it is when mirroring sites that have several names
+that all refer to the same (logical) server:
+
+  URL: http://www.midifest.com/
+  Also: http://midifest.com/ .
+
+At this point in time B<w3mir> has no mechanism to easily enlarge the
+scope of a mirror after it has been established.  That means that you
+should survey the documents you are going to retrieve to find out what
+icons, graphics and other things they refer to that you want.  And
+what other sites you might like to retrieve.  If you find out that
+something is missing you will have to delete the whole mirror, add the
+needed B<Also> directives and then reestablish the mirror.  This lack
+of flexibility in what to retrieve will be addressed at a later date.
+
+See also the B<Also-quene> directive.
+
+=item Also-quene: I<HTTP-URL directory>
+
+This is like Also, except that the URL itself is also quened.  The
+Also directive will not cause any documents to be retrived UNLESS they
+are referenced by some other document w3mir has already retrived.
+
+=item Quene: I<HTTP-URL>
+
+This is quenes the URL for retrival, but does not enlarge the scope of
+the retrival.  If the URL is outside the scope of retrival it will not
+be retrived anyway.
+
+The observant reader will see that B<Also-quene> is like B<Also>
+combined with B<Quene>.
+
+=item Initial-referer: I<referer>
+
+see B<-ir> option.
+
+=item Ignore: F<wildcard>
+
+=item Fetch: F<wildcard>
+
+=item Ignore-RE: F<regular-expression>
+
+=item Fetch-RE: F<regular-expression>
+
+These four are used to set up rules about which documents, within the
+scope of retrieval, should be gotten and which not.  The default is to
+get I<anything> that is within the scope of retrieval.  That may not
+be practical though.  This goes for CGI scripts, and especially server
+side image maps and other things that are executed/evaluated on the
+server.  There might be other things you want unfetched as well.
+
+B<w3mir> stores the I<Ignore>/I<Fetch> rules in a list.  When a
+document is considered for retrieval the URL is checked against the
+list in the same order that the rules appeared in the configuration
+file.  If the URL matches any rule the search stops at once.  If it
+matched a I<Ignore> rule the document is not fetched and any URLs in
+other documents pointing to it will point to the document at the
+original server (not inside the mirror).  If it matched a I<Fetch>
+rule the document is gotten.  If not matched by any ruøes the document
+is gotten.
+
+The F<wildcard>s are a very limited subset of Unix-wildcards.
+B<w3mir> understands only 'I<?>', 'I<*>', and 'I<[x-y]>' ranges.
+
+The F<perl-regular-expression> is perls superset of the normal Unix
+regular expression syntax.  They must be completely specified,
+including the prefixed m, a delimiter of your choice (except the
+paired delimiters: parenthesis, brackets and braces), and any of the
+RE modifiers. E.g.,
+
+  Ignore-RE: m/.gif$/i
+
+or
+
+  Ignore-RE: m~/.*/.*/.*/~
+
+and so on.  "#" cannot be used as delimiter as it is the comment
+character in the configuration file.  This also has the bad
+side-effect of making you unable to match fragment names (#foobar)
+directly.  Fortunately perl allows writing ``#'' as ``\043''.
+
+You must be very carefull of using the RE anchors (``^'' and ``$''
+with the RE versions of these and the I<Apply> directive. Given the
+rules:
+
+  Fetch-RE: m/foobar.cgi$/
+  Ignore: *.cgi
+
+the all files called ``foobar.cgi'' will be fetched. However, if the
+file is referenced as ``foobar.cgi?query=mp3'' it will I<not> be
+fetched since the ``$'' anchor will prevent it from matching the
+I<Fetch-RE> directive and then it will match the I<Ignore> directive
+instead. If you want to match ``foobar.cgi'' but not ``foobar.cgifu''
+you can use perls ``\b'' character class which matches a word
+boundrary:
+
+  Fetch-RE: m/foobar.cgi\b/
+  Ignore: *.cgi
+
+which will get ``foobar.cgi'' as well as ``foobar.cgi?query=mp3'' but
+not ``foobar.cgifu''. BUT, you must keep in mind that a lot of
+diffetent characters make a word boundrary, maybe something more
+subtle is needed.
+
+=item Apply: I<regular-expression>
+
+This is used to change a URL into another URL.  It is a potentially
+I<very> powerful feature, and it also provides ample chance for you to
+shoot your own foot. The whole aparatus is somewhat tenative, if you
+find there is a need for changes in how Apply rules work please
+E-mail. If you are going to use this feature please read the
+documentation for I<Fetch-RE> and I<Ignore-RE> first.
+
+The B<Apply> expressions are applied, in sequence, to the URLs in
+their absolute form. I.e., with the whole
+http://host:port/dir/ec/tory/file URL. It is only after this B<w3mir>
+checks if a document is within the scope of retrieval or not. That
+means that B<Apply> rules can be used to change certain URLs to fall
+inside the scope of retrieval, and vice versa.
+
+The I<regular-expression> is perls superset of the usual Unix regular
+expressions for substitution.  As with I<Fetch> and I<Ignore> rules it
+must be specified fully, with the I<s> and delimiting character.  It
+has the same restrictions with regards to delimiters. E.g.,
+
+  Apply: s~/foo/~/bar/~i
+
+to translate the path element I<foo> to I<bar> in all URLs.
+
+"#" cannot be used as delimiter as it is the comment character in the
+configuration file.
+
+Please note that w3mir expects that URLs identifying 'directories'
+keep idenfifying directories after application of Apply rules.  Ditto
+for files.
+
+=item Agent: I<agent>
+
+see B<-agent> option.
+
+=item Pause: I<n>
+
+see B<-p> option.
+
+=item Retry-Pause: I<n>
+
+see B<-rp> option.
+
+=item Retries: I<n>
+
+see B<-t> option.
+
+=item debug: I<n>
+
+see B<-d> option.
+
+=item umask I<n>
+
+see B<-umask> option.
+
+=item Robot-Rules: I<on> | I<off>
+
+Turn robot rules on of off.  See B<-drr> option.
+
+=item Remove-Nomirror: I<on> | I<off>
+
+If this is enabled sections between two consecutive
+
+  <!--NO MIRROR-->
+
+comments in a mirrored document will be removed.  This editing is
+performed even if batch getting is specified.
+
+=item Header: I<html/text>
+
+Insert this I<complete> html/text into the start of the document.
+This will be done even if batch is specified.
+
+=item File-Disposition: I<save> | I<stdout> | I<forget>
+
+What to do with a retrieved file.  The I<save> alternative is default.
+The two others correspond to the B<-s> and B<-f> options.  Only one
+may be specified.
+
+=item Verbosity: I<quiet> | I<brief> | I<chatty>
+
+How much B<w3mir> informs you of it's progress.  I<Brief> is the
+default.  The two others correspond to the B<-q> and B<-c> switches.
+
+=item Cd: I<directory>
+
+Change to given directory before starting work.  If it does not exist
+it will be quietly created.  Using this option breaks the 'fixup'
+code so consider not using it, ever.
+
+=item HTTP-Proxy: I<server:port>
+
+see the B<-P> switch.
+
+=item HTTP-Proxy-user: I<username>
+
+=item HTTP-Proxy-passwd: I<password>
+
+These two are is used to activate authentication with the proxy
+server.  L<w3mir> only supports I<basic> proxy autentication, and is
+quite simpleminded about it, if proxy authentication is on L<w3mir>
+will always give it to the proxy.  The domain concept is not supported
+with proxy-authentication.
+
+=item Proxy-Options: I<no-pragma> | I<revalidate> | I<refresh> | I<no-store>
+
+Set proxy options.  There are two ways to pass proxy options, HTTP/1.0
+compatible and HTTP/1.1 compatible.  Newer proxy-servers will
+understand the 1.1 way as well as 1.0.  With old proxy-servers only
+the 1.0 way will work.  L<w3mir> will prefer the 1.0 way.
+
+The only 1.0 compatible proxy-option is I<refresh>, it corresponds to
+the B<-pflush> option and forces the proxy server to pass the request
+to a upstream server to retrieve a I<fresh> copy of the document. 
+
+The I<no-pragma> option forces w3mir to use the HTTP/1.1 proxy
+control header, use this only with servers you know to be new,
+otherwise it won't work at all.  Use of any option but I<refresh> will
+also cause HTTP/1.1 to be used.  
+
+I<revalidate> forces the proxy server to contact the upstream server
+to validate that it has a fresh copy of the document.  This is nicer
+to the net than I<refresh> option which forces re-get of the document
+no matter if the server has a fresh copy already.
+
+I<no-store> forbids the proxy from storing the document in other than
+in transient storage.  This can be used when transferring sensitive
+documents, but is by no means any warranty that the document can't be
+found on any storage device on the proxy-server after the transfer.
+Cryptography, if legal in your contry, is the solution if you want the
+contents to be secret.
+
+I<refresh> corresponds to the HTTP/1.0 header I<Pragma: no-cache> or
+the identical HTTP/1.1 I<Cache-control> option.  I<revalidate> and
+I<no-store> corresponds to I<max-age=0> and I<no-store> respectively.
+
+=item Authorization
+
+B<w3mir> supports only the I<basic> authentication of HTTP/1.0.  This
+method can assign a password to a given user/server/I<realm>.  The
+"user" is your user-name on the server.  The "server" is the server.
+The I<realm> is a HTTP concept.  It is simply a grouping of files and
+documents.  One file or a whole directory hierarchy can belong to a
+realm.  One server may have many realms.  A user may have separate
+passwords for each realm, or the same password for all the realms the
+user has access to.  A combination of a server and a realm is called a
+I<domain>.
+
+=over 8
+
+=item Auth-Domain: I<server:port/realm>
+
+Give the server and port, and the belonging realm (making a domain)
+that the following authentication data holds for.  You may specify "*"
+wildcard for either of I<server:port> and I<realm>, this will work
+well if you only have one usernme and password on all the servers
+mirrored.
+
+=item Auth-User: I<user>
+
+Your user-name.
+
+=item Auth-Passwd: I<password>
+
+Your password.
+
+=back
+
+These three directives may be repeated, in clusters, as many times as
+needed to give the necessary authentication information
+
+=item Disable-Headers: I<referer> | I<user>
+
+Stop B<w3mir> from sending the given headers.  This can be used for
+anonymity, making your retrievals harder to track.  It will be even
+harder if you specify a generic B<Agent>, like Netscape.
+
+=item Fixup: I<...>
+
+This directive controls some aspects of the separate program w3mfix.
+w3mfix uses the same configuration file as w3mir since it needs a lot
+of the information in the B<w3mir> configuration file to do it's work
+correctly.  B<w3mfix> is used to make mirrors more browseable on
+filesystems (disk or CDROM), and to fix redirected URLs and some other
+URL editing.  If you want a mirror to be browseable of disk or CDROM
+you almost certainly need to run w3mfix.  In many cases it is not
+necessary when you run a mirror to be used through a WWW server.
+
+To make B<w3mir> write the data files B<w3mfix> needs, and do nothing
+else, simply put
+
+=over 8
+
+  Fixup: on
+
+=back
+
+in the configuration file.  To make B<w3mir> run B<w3mfix>
+automatically after each time B<w3mir> has completed a mirror run
+specify
+
+=over 8
+
+  Fixup: run
+
+=back
+
+L<w3mfix> is documented in a separate man page in a effort to not
+prolong I<this> manpage unnecessarily.
+
+=item Index-name: I<name-of-index-file>
+
+When retriving URLs ending in '/' w3mir needs to append a filename to
+store it localy.  The default value for this is 'index.html' (this is
+the most used, its use originated in the NCSA HTTPD as far as I know).
+Some WWW servers use the filename 'Welcome.html' or 'welcome.html'
+instead (this was the default in the old CERN HTTPD).  And servers
+running on limited OSes frequently use 'index.htm'.  To keep things
+consistent and sane w3mir and the server should use the same name.
+Put
+
+  Index-name: welcome.html
+
+when mirroring from a site that uses that convention.
+
+When doing a multiserver retrival where the servers use two or more
+different names for this you should use B<Apply> rules to make the
+names consistent within the mirror.
+
+When making a mirror for use with a WWW server, the mirror should use
+the same name as the new server for this, to acomplish that
+B<Index-name> should be combined with B<Apply>.
+
+Here is an example of use in the to latter cases when Welcome.html is
+the prefered I<index> name:
+
+  Index-name: Welcome.html
+  Apply: s~/index.html$~/Welcome.html~
+
+Similarly, if index.html is the prefered I<index> name.
+
+  Apply: s~/Welcome.html~/index.html~
+
+I<Index-name> is not needed since index.html is the default index name.
+
+=back
+
+=head1 EXAMPLES
+
+=over 4
+
+=item * Just get the latest Dr-Fun if it has been changed since the last
+time
+
+ w3mir http://sunsite.unc.edu/Dave/Dr-Fun/latest.jpg
+
+=item * Recursively fetch everything on the Star Wars site, remove
+what is no longer at the server from the mirror:
+
+ w3mir -R -r http://www.starwars.com/
+
+=item * Fetch the contents of the Sega site through a proxy, pausing
+for 30 seconds between each document
+
+ w3mir -r -p 30 -P www.foo.org:4321 http://www.sega.com/
+
+=item * Do everything according to F<w3mir.cfg>
+
+ w3mir -cfgfile w3mir.cfg
+
+=item * A simple configuration file
+
+ # Remember, options first, as many as you like, comma separated
+ Options: recurse, remove
+ #
+ # Start here:
+ URL: http://www.starwars.com/
+ #
+ # Speed things up
+ Pause: 0
+ #
+ # Don't get junk
+ Ignore: *.cgi
+ Ignore: *-cgi
+ Ignore: *.map
+ #
+ # Proxy:
+ HTTP-Proxy: www.foo.org:4321
+ #
+ # You _should_ cd away from the directory where the config file is.
+ cd: starwars
+ #
+ # Authentication:
+ Auth-domain: server:port/realm
+ Auth-user: me
+ Auth-passwd: my_password
+ #
+ # You can use '*' in place of server:port and/or realm:
+ Auth-domain: */*
+ Auth-user: otherme
+ Auth-user: otherpassword
+
+=item Also:
+
+ # Retrive all of janl's home pages:
+ Options: recurse
+ #
+ # This is the two argument form of URL:.  It fetches the first into the second
+ URL: http://www.math.uio.no/~janl/ math/janl
+ #
+ # These says that any documents refered to that lives under these places
+ # should be gotten too.  Into the named directories.  Two arguments are
+ # required for 'Also:'.
+ Also: http://www.math.uio.no/drift/personer/ math/drift
+ Also: http://www.ifi.uio.no/~janl/ ifi/janl
+ Also: http://www.mi.uib.no/~nicolai/ math-uib/nicolai
+ #
+ # The options above will result in this directory hierarchy under
+ # where you started w3mir:
+ # w3mir/math/janl		files from http://www.math.uio.no/~janl
+ # w3mir/math/drift		from http://www.math.uio.no/drift/personer/
+ # w3mir/ifi/janl		from http://www.ifi.uio.no/~janl/
+ # w3mir/math-uib/nicolai	from http://www.mi.uib.no/~nicolai/
+
+=item Ignore-RE and Fetch-RE
+
+ # Get only jpeg/jpg files, no gifs
+ Fetch-RE: m/\.jp(e)?g$/
+ Ignore-RE: m/\.gif$/
+
+=item Apply
+
+As I said earlier, B<Apply> has not been used for Real Work yet, that
+I know of.  But B<Apply> I<could>, be used to map all web servers at
+the university of Oslo inside the scope of retrieval very easily:
+
+  # Start at the main server
+  URL: http://www.uio.no/
+  # Change http://*.uio.no and http://129.240.* to be a subdirectory
+  # of http://www.uio.no/.
+  Apply: s~^http://(.*\.uio\.no(?:\d+)?)/~http://www.uio.no/$1/~i
+  Apply: s~^http://(129\.240\.[^:]*(?:\d+)?)/~http://www.uio.no/$1/~i
+
+
+=back
+
+There are two rather extensive example files in the B<w3mir> distribution.
+
+=head1 BUGS
+
+=over 4
+
+=item The -lc switch does not work too well.
+
+=back
+
+=head1 FEATURES
+
+These are not bugs.
+
+=over 4
+
+=item URLs with two /es ('//') in the path component does not work as
+some might expect.  According to my reading of the URL spec. it is an
+illegal construct, which is a Good Thing, because I don't know how to
+handle it if it's legal.
+
+=item If you start at http://foo/bar/ then index.html might be gotten
+twice.
+
+=item Some documents point to a point above the server root, i.e.,
+http://some.server/../stuff.html.  Netscape, and other browsers, in
+defiance of the URL standard documents will change the URL to
+http://some.server/stuff.html.  W3mir will not.
+
+=item Authentication is I<only> tried if the server requests it.  This
+might lead to a lot of extra connections going up and down, but that's
+the way it's gotta work for now.
+
+=back
+
+=head1 SEE ALSO
+
+L<w3mfix>
+
+=head1 AUTHORS
+
+B<w3mir>s authors can be reached at I<w3mir-core@usit.uio.no>.
+B<w3mir>s home page is at http://www.math.uio.no/~janl/w3mir/
Index: /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3pdfuri.pm
===================================================================
--- /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3pdfuri.pm	(revision 16571)
+++ /gsdl/trunk/build-src/packages/w3mir/w3mir-1.0.8/w3pdfuri.pm	(revision 16571)
@@ -0,0 +1,64 @@
+# -*- perl -*-
+#
+# w3pdfuri.pm -- extract uris from a adobe acrobat pdf file.
+#     version 0.1
+$VERSION=0.1;
+#
+# Assumptions:
+# - File starts with %PDF
+# - All URLS match this RE: ^\/URI\s+\(([^)]*)\)\s*$  (found by inspection of
+#   one (1) pdf file (the reader.pdf in the acrobat distribution).
+# - pdf files are potentially very large, so we read it from disk
+#   record by record.
+# - Record separator is ^M
+#
+# History:
+# - 19/02/97 janl: Version 0.1, seems to work with PDF-1.2
+#
+
+package w3pdfuri;
+
+use strict;
+
+sub list ($) {
+  my ($file) = @_;
+
+  my @urls=();
+  local($/)="\r";
+
+  unless (open(PDF,"< $file")) {
+    warn "Could not open $file for input: $!\n";
+    return;
+  }
+
+  $_ = <PDF>;
+  unless (/^%PDF-/) {
+    warn "$file is not a PDF file.\n";
+    close(PDF);
+    return;
+  }
+  
+  while (<PDF>) {
+    chomp;
+    push(@urls,$1) if (m~^/URI\s+\(([^)]*)\)\s*$~);
+  }
+
+  close(PDF);
+
+  return @urls;
+}
+
+1;
+
+__END__
+
+# Test code
+print "reader.pdf: ",
+  join(",",list("/local/lib/acrobat/Reader/help/reader.pdf")),"\n";
+print "Acrobat.pdf: ",
+  join(",",list("/local/lib/acrobat/Reader/Acrobat.pdf")),"\n";
+print "License.pdf: ",
+  join(",",list("/local/lib/acrobat/Reader/License.pdf")),"\n";
+print "MapTypes.pdf: ",
+  join(",",list("/local/lib/acrobat/Reader/MapTypes.pdf")),"\n";
+list("/etc/services");
Index: /gsdl/trunk/build-src/packages/wget/README
===================================================================
--- /gsdl/trunk/build-src/packages/wget/README	(revision 16571)
+++ /gsdl/trunk/build-src/packages/wget/README	(revision 16571)
@@ -0,0 +1,35 @@
+wget - web site mirroring software
+
+This directory contains a version of the GNU wget program that was written by
+Hrvoje Niksic and others and distributed under the GNU General Public Licence
+
+The GNU wget homepage is http://www.cg.tuwien.ac.at/~prikryl/wget.html
+
+A couple of very small changes were made to this package by Stefan Boddie
+(sjboddie@cs.waikato.ac.nz). The USE_STDARG preprocessor definition was
+added to the VC++ makefile as it appeared to need it to compile on either
+VC++ 4.2 or VC++ 6.0. A change was also made to prevent backslashes from
+mistakenly being converted to "@5c" on windows.
+
+2003/11/27 - sjboddie@cs.waikato.ac.nz made a few more small changes to fix
+h_errno bug preventing code from compiling on latest versions of GCC.
+
+2004/06/30 - kjdon@cs.waikato.ac.nz replaced version 1.5.3 with version 1.9.
+It compiled as is under Windows XP, using VC++ 6.0, under Linux using GCC 3.2.3
+and GCC 2.95.3. So I haven't made any changes. 
+Under Windows, I haven't compiled it with openssl, so it doesn't support
+https://. OpenSSL comes with a warning about it being illegal in some countries
+to distribute cryptographic technology, so I haven't used it. Look at
+wget-1.9/windows/README for Windows compiling instructions if you want to add
+it in.
+
+2008/07/03 - oranfry@cs.waikato.ac.nz replaced version 1.9 with version 1.11.4.
+Version 1.9 didn't compile statically with the new libraries which come with
+fedora, so upgrading. Had to apply the patch at
+http://marc.info/?l=wget&m=115131792408685&w=2 to get it to compile under
+windows(VC++ 6.0), and those changes are in the tar.gz file in the repository.
+Again, no ssl in windows wget. The packages/configure and packages/Makefile
+files perform the same operations on wget as before, just the directory name
+has changed from wget/wget-1.9 to wget/wget-1.11.4.
+
+
Index: /gsdl/trunk/build-src/packages/wv/README
===================================================================
--- /gsdl/trunk/build-src/packages/wv/README	(revision 16571)
+++ /gsdl/trunk/build-src/packages/wv/README	(revision 16571)
@@ -0,0 +1,16 @@
+wv - Microsoft Word converter
+
+This directory contains a version of the wv program.  It was originally
+written by Caolan McNamara and distributed under the GNU General Public
+License.  wv is now maintained by Dom Lachowicz and Martin Vermeer.  wv
+incorporates code from a variety of GPL programs from other sources.
+Thank you all.
+
+The wv homepage is http://wvware.sourceforge.net/
+
+We have included the source code here.  It is a slimmed-down version
+of wv version 0.7.1. It should handle documents created with Word 2 up
+to Word 2000. We have tested it on Linux (slackware 7), darwin (OS X
+10.1.3), cygwin, and solaris 2.8 (via sourceforge's compile farm).
+
+John McPherson -- Apr 2002
Index: /gsdl/trunk/build-src/packages/xlhtml/README.txt
===================================================================
--- /gsdl/trunk/build-src/packages/xlhtml/README.txt	(revision 16571)
+++ /gsdl/trunk/build-src/packages/xlhtml/README.txt	(revision 16571)
@@ -0,0 +1,19 @@
+This package contains two programs:
+* ppthtml, which converts Microsoft PowerPoint 95 and 97 files
+into html or xml, and
+* xlhtml, which converts Microsoft Excel 95 and 97 files.
+
+It has been slightly modified for greenstone use as we only want the
+ppt to html program and the xls to html program, and none of the other
+programs (summary/diagnostics, man pages, etc).
+
+This version (0.4.9.0) was the latest development snapshot at the
+time of writing.
+
+See http://www.xlhtml.org/ for newer versions or more info.
+
+xlhtml is released under the GNU GPL.
+
+20 Feb 2002
+John McPherson
+NZDL.
Index: /gsdl/trunk/build-src/src/hashfile/Makefile.in
===================================================================
--- /gsdl/trunk/build-src/src/hashfile/Makefile.in	(revision 16571)
+++ /gsdl/trunk/build-src/src/hashfile/Makefile.in	(revision 16571)
@@ -0,0 +1,79 @@
+###########################################################################
+#
+# Makefile -- src/hashfile
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ../..
+
+
+CXX = @CXX@
+CXXFLAGS = @CXXFLAGS@ @COMPAT32BITFLAGS@
+DEFS = @DEFS@
+GSDLOS = @gsdlos@
+INCLUDES = 
+INSTALL = @INSTALL@
+LDFLAGS = @LDFLAGS@ @COMPAT32BITFLAGS@
+LIBS = @LIBS@
+
+
+CXXCOMPILE = $(CXX) -c $(CXXFLAGS) $(DEFS) $(INCLUDES)
+CXXLINK = $(CXX) $(LDFLAGS) -o $@
+
+
+.SUFFIXES:
+.SUFFIXES: .cpp .o
+.cpp.o:
+	$(CXXCOMPILE) $< 
+
+
+SOURCES = \
+	hashfile.cpp
+
+OBJECTS = \
+	hashfile.o
+
+EXECUTABLE_OBJECTS = \
+	$(OBJECTS)
+
+EXECUTABLE = hashfile
+
+
+# Default target: make the hashfile executable
+all: $(EXECUTABLE)
+
+hashfile: $(EXECUTABLE_OBJECTS)
+	$(CXXLINK) $(EXECUTABLE_OBJECTS) $(LIBS)
+
+install: $(EXECUTABLE)
+	$(INSTALL) -d $(GSDL_DIR)/bin/$(GSDLOS)
+	$(INSTALL) -m 755 -s $(EXECUTABLE) $(GSDL_DIR)/bin/$(GSDLOS)
+
+clean:
+	rm -f $(OBJECTS) $(EXECUTABLE)
+
+distclean:
+	rm -f $(OBJECTS) $(EXECUTABLE) Makefile
+
+depend:
+	makedepend -Y -- $(DEFS) $(INCLUDES) $(CXXFLAGS) -- $(SOURCES)
Index: /gsdl/trunk/build-src/src/hashfile/hashfile.cpp
===================================================================
--- /gsdl/trunk/build-src/src/hashfile/hashfile.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/src/hashfile/hashfile.cpp	(revision 16571)
@@ -0,0 +1,263 @@
+/**********************************************************************
+ *
+ * hashfile.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include <stdio.h>
+
+#define MAXNUMLEN  100   // bytes
+
+
+// The number class is used to store very long unsigned integers.
+// The least significant of each number is stored first. Numbers can 
+// be no longer than MAXNUMLEN bytes long. A number with length=0
+// is considered to be equal to 0. There should be no extra zeros
+// at the front of the number.
+
+struct number {
+  unsigned int len;
+  unsigned char num[MAXNUMLEN];
+
+  number () {len = 0;}
+};
+
+
+// evaluates a = a + b
+// a and b can be the same number
+void my_inc (number &a, number &b) {
+  unsigned int carry = 0;
+  unsigned int num = 0;
+  unsigned int i = 0;
+
+  while ((carry || (i < a.len) || (i < b.len)) && (i < MAXNUMLEN)) {
+    num = carry;
+    if (i < a.len) num += a.num[i];
+    if (i < b.len) num += b.num[i];
+
+    if (num >= 256) {
+      num -= 256; // assumes that each number in the list < 256
+      carry = 1;
+    } else {
+      carry = 0;
+    }
+    a.num[i] = (unsigned char)num;
+
+    ++i;
+  }
+
+  a.len = i;
+}
+
+
+// evaluates a = a - b if a >= b
+// returns true if the subtraction was possible
+int my_ifpos_dec (number &a, number &b) {
+  int carry = 0;
+  int num = 0;
+  int i = 0;
+  unsigned int len = 0; // the last non-zero digit
+
+  // make sure a >= b
+  if (b.len > a.len) return 0;
+  if (b.len == a.len) {
+    i = a.len - 1;
+    while (i >= 0) {
+      if (a.num[i] > b.num[i]) break;
+      if (a.num[i] < b.num[i]) return 0;
+      --i;
+    }
+  }
+
+  unsigned int j = 0;
+  len = 0;
+  while ((j < a.len) || (j < b.len)) {
+    num = -carry;
+    if (j < a.len) num += a.num[j];
+    if (j < b.len) num -= b.num[j];
+
+    if (num < 0) {
+      num += 256; // assumes each number in the list < 256
+      carry = 1;
+    } else {
+      carry = 0;
+    }
+
+    a.num[j] = (unsigned char) num;
+    
+    ++j;
+    if (num != 0) len = j;
+  }
+
+  a.len = len;
+
+  if (carry) {
+    // panic, this should NOT happen
+    fprintf (stderr, "panic: error in my_ifpos_dec\n");
+  }
+
+  return 1;
+}
+
+
+char *my_convert_num (number &a) {
+  char *result = new char[(a.len*2)+1];
+  int i,len;
+  char convert[16] = {'0','1','2','3','4','5','6','7',
+		      '8','9','a','b','c','d','e','f'};
+
+  // zero might be a special case
+  if (a.len == 0) {
+    result[0] = '0';
+    result[1] = '\0';
+    return result;
+  }
+
+  for (i=a.len-1, len=0; i >= 0; --i) {
+    result[len++] = convert[a.num[i]/16];
+    result[len++] = convert[a.num[i]%16];
+  }
+  result[len] = '\0';
+
+  return result;
+}
+
+
+
+// create a hash string from the contents of a file.
+//
+// The file is treated as a large base 256 number (each char is a digit),
+// and the hash value is the remainder when this number is divided by a
+// very large prime.
+//
+// PROBLEM: This is a flawed hash function because the rightmost (highest)
+// value in remainder is more likely to be a "1" than it is to be any other
+// number.  
+//
+// EVIDENCE: About 50% of the files in any GSDL directory have a hash code
+// that starts with 01* which implies (based on the my_convert_num function)
+// that the rightmost "digit" of the remainder = z such that (z % 16 = 0)
+// and (z / 16 = 1) which means (z = 1).
+//
+// MAJOR REASON: suppose our prime number was 19.  Then, if we have a 
+// reasonably random distribution of numbers for which we are going to 
+// calculate (N % 19), we expect to get a roughly uniform distribution
+// of remainders where the possible values are 0, 1, 2, 3... 18.  The
+// problem is that 9 out of the 19 possible values (10,11... 18) start
+// with the digit 1.  Thus our hascode will start with "01".
+//
+// ANOTHER PROBLEM: Characters in the file are read one at a time; after each 
+// one is read it is prepended to the remainder, then the remainder is
+// recalculated on the string thus far seen.  I am sure the math here 
+// is wrong - if I try calculating (111 mod 7) by the same algorithm, it
+// simply does nor work.
+//
+// ANOTHER POSSIBLE PROLEM: Each character from the file is read into 
+// remainder at the most significant end, and when that character
+// is a zero you get a number like "01" which would be considered 
+// larger than a number like "8" because it is longer (two  digits
+// instead of 1).  
+//
+// These comments added by Gordon Paynter (gwp@cs.waikato.ac.nz) in
+// June 2000.  I didn't write any code, however.
+
+char *hashfile (char *filename) {
+  FILE *infile = (FILE *)NULL;
+  int i;
+
+  number primepow[8];
+  number pow;
+  number remainder;
+  unsigned char c;
+
+  // our prime number (618970019642690137449562111)
+  pow.num[0] = 255;  pow.num[1] = 255;
+  pow.num[2] = 255;  pow.num[3] = 255;
+  pow.num[4] = 255;  pow.num[5] = 255;
+  pow.num[6] = 255;  pow.num[7] = 255;
+  pow.num[8] = 255;  pow.num[9] = 255;
+  pow.num[10] = 255; pow.num[11] = 1;
+  pow.len = 12;
+
+  // calculate 8 multiples of the prime number.
+  // These are used to find the remainder using only subtraction operations
+  for (i=0; i<8; ++i) {
+    primepow[i] = pow;
+    my_inc (pow, pow);
+  }
+
+  // The "remainder" after division by the prime.  Our result.
+  remainder.len = 0;
+
+  // open the file
+  infile = fopen (filename, "rb");
+  if (infile == NULL) {
+    return (char *)NULL;
+  }
+  c = (unsigned char)fgetc(infile);
+  
+  while (!feof (infile)) {
+
+    // make sure the remainder has not grown too large
+    if (remainder.len == MAXNUMLEN-1) {
+      fprintf (stderr, "ERROR - number overflow\n");
+      return (char *)NULL;
+    }
+
+    // remainder = remainder * 256 + c
+    for (i=remainder.len; i>0; --i) {
+      remainder.num[i] = remainder.num[i-1];
+    }
+    remainder.num[0] = c;
+    if (remainder.len > 0 || c != 0) remainder.len = remainder.len+1;
+    
+    // remainder = (remainder % large-prime-number)
+    for (i=7; i>=0; --i) {
+      my_ifpos_dec (remainder, primepow[i]);
+    }
+
+    // read a new character from the file
+    c = (unsigned char)fgetc(infile);
+  }
+
+  fclose (infile);
+
+  return my_convert_num (remainder);
+}
+
+
+int main (int argc, char *argv[]) {
+  int i;
+  char *result;
+
+  for (i = 1; i < argc; ++i) {
+    result = hashfile (argv[i]);
+    if (result == NULL) {
+      printf ("ERROR - could not process %s\n", argv[i]);
+    } else {
+      printf ("%s: %s\n", argv[i], result);
+      delete [] result;
+    }
+  }
+
+  return 0;
+}
Index: /gsdl/trunk/build-src/src/hashfile/win32.mak
===================================================================
--- /gsdl/trunk/build-src/src/hashfile/win32.mak	(revision 16571)
+++ /gsdl/trunk/build-src/src/hashfile/win32.mak	(revision 16571)
@@ -0,0 +1,76 @@
+###########################################################################
+#
+# win32 makefile -- hashfile
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+ 
+GSDLHOME = ..\..
+GSDL_VC4 = 0
+
+AR = lib
+CC = cl
+
+!IF $(GSDL_VC4)
+CPPFLAGS = -GX
+!ELSE
+CPPFLAGS = -EHsc
+!ENDIF
+
+DEFS = -DHAVE_CONFIG_H -D__WIN32__ -D_CRT_SECURE_NO_DEPRECATE
+INCLUDES = -I"$(GSDLHOME)\src\hashfile"
+LIBS =
+
+COMPILE = $(CC) -nologo -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+LINK = $(CC) -nologo $(LDFLAGS)
+
+.SUFFIXES:
+.SUFFIXES: .cpp .obj
+.cpp.obj:
+	$(COMPILE) $<
+
+ANSI2KNR = 
+o = .obj
+e = .exe
+ 
+HEADERS = 
+
+SOURCES = hashfile.cpp
+
+OBJECTS = hashfile$o
+
+EXEC = hashfile$e
+ 
+all : $(EXEC)
+
+install: $(EXEC)
+	if NOT EXIST "$(GSDLHOME)\bin\windows" mkdir "$(GSDLHOME)\bin\windows"
+	copy $(EXEC) "$(GSDLHOME)\bin\windows"
+
+clean:
+	del *$o
+	del $(EXEC)
+
+HASHFILE_OBJS = hashfile$o
+
+hashfile$e: $(HASHFILE_OBJS) $(LIBS)
+	    $(LINK) $(HASHFILE_OBJS) $(LIBS)
Index: /gsdl/trunk/build-src/src/java/org/nzdl/gsdl/ApplyXSLT.java
===================================================================
--- /gsdl/trunk/build-src/src/java/org/nzdl/gsdl/ApplyXSLT.java	(revision 16571)
+++ /gsdl/trunk/build-src/src/java/org/nzdl/gsdl/ApplyXSLT.java	(revision 16571)
@@ -0,0 +1,373 @@
+package org.nzdl.gsdl;
+
+import java.io.*;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import javax.xml.parsers.*;
+import javax.xml.transform.dom.*;
+import org.w3c.dom.*;
+
+
+
+/**
+ *  Use the TraX interface to perform a transformation in the simplest manner possible
+ *  (3 statements).
+ */
+public class ApplyXSLT
+{
+
+    public static final String DOC_START = new String ("<?DocStart?>"); 
+    public static final String DOC_END = new String ("<?DocEnd?>"); 
+    public static final String INPUT_END = new String ("<?Done?>"); 
+
+    private static final String RECORD_ELEMENT = "record";
+    private static final String CONTROLFIELD_ELEMENT = "controlfield";
+    private static final String SUBFIELD_ELEMENT = "subfield";
+    private static final String LEADER_ELEMENT = "leader";
+
+    private final int BEFORE_READING = 0;
+    private final int IS_READING = 1;
+    private String xsl_file;
+    private String mapping_file;
+
+    public ApplyXSLT(){}
+   
+    public ApplyXSLT(String xsl_file)
+    {
+	this.xsl_file = xsl_file; 
+    }
+
+    public ApplyXSLT(String xsl_file,String mapping_file){
+	this.xsl_file = xsl_file; 
+	this.mapping_file = mapping_file;
+    }
+
+    private boolean process()
+    {
+	try{
+
+	// Use System InputStream to receive piped data from the perl program
+	InputStreamReader ir = new InputStreamReader(System.in, "UTF8");
+	BufferedReader br = new BufferedReader(ir);
+	
+	int system_status = BEFORE_READING;
+ 	String a_doc = new String();
+	String output_file = new String();
+
+
+	    while (br.ready()) {
+		                   
+		String this_line = br.readLine();
+		if(system_status == BEFORE_READING){
+		    if(this_line.compareTo(DOC_START) == 0){
+			output_file = br.readLine(); // read the next line as the output file name
+			system_status = IS_READING;
+			a_doc = "";
+		    }
+		    else if(this_line.compareTo(INPUT_END) == 0){
+			return true;
+		    }
+		    else{
+			System.err.println("Undefined process status:" + this_line);
+			system_status = BEFORE_READING;
+		    }
+		    
+		}
+		else if(system_status == IS_READING){
+		    if(this_line.compareTo(DOC_END) == 0){
+			boolean result = false;
+			if (mapping_file !=null && !mapping_file.equals("")){
+			    result = translateXMLWithMapping(a_doc,output_file);			    
+			}
+			else{
+			    result = translateXML(a_doc,output_file); 
+			}
+			
+			if (!result){
+			    System.err.println("Translation Failed!!");
+			    return false;
+			}
+			
+			system_status = BEFORE_READING;
+			
+		    }
+		    else{
+			a_doc = a_doc + this_line + "\n";
+			
+		    }
+		}
+		else{		  
+		    System.err.println ("Undefined system status in ApplyXSLT.java main().");
+		    System.exit(-1);
+		    }
+		
+	    }
+	}catch (Exception e)
+	    {
+		System.err.println("Receiving piped data error!" + e.toString());
+	    }
+				
+	return false;
+    }
+    
+    
+    private boolean translateXML(String full_doc, String output_file) 
+	throws IOException,TransformerException, TransformerConfigurationException, FileNotFoundException
+    {
+	
+ 	StringReader str = new StringReader(full_doc) ;
+	
+	TransformerFactory tFactory = TransformerFactory.newInstance();
+   	Transformer transformer = tFactory.newTransformer(new StreamSource(xsl_file));
+   	transformer.transform(new StreamSource(str), new StreamResult(new FileOutputStream(output_file)));
+	return true;
+    }
+
+    private boolean translateXMLWithMapping(String full_doc, String output_file) 
+	throws IOException,TransformerException, TransformerConfigurationException, FileNotFoundException
+    {	
+	StringReader str = new StringReader(full_doc) ;
+
+	try{
+	    TransformerFactory tFactory = TransformerFactory.newInstance();
+	    Transformer transformer = tFactory.newTransformer(new StreamSource(xsl_file));
+	    
+	    Document mapping_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mapping_file);
+	    Element mapping =mapping_doc.getDocumentElement(); 
+	    
+	    transformer.setParameter("mapping",mapping);
+	    
+	    Document output_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+	    
+	    transformer.transform(new StreamSource(str), new DOMResult(output_doc));
+	    
+	    calculateRecordsLength(output_doc);
+	   
+	    transformer = tFactory.newTransformer();
+	   
+	    transformer.transform(new DOMSource(output_doc), new StreamResult(new FileOutputStream(output_file)));
+
+	}
+	catch(Exception e){
+	    e.printStackTrace();
+	    return false;
+	}
+
+	return true;
+    }
+
+    private void calculateRecordsLength(Document output_doc){
+	NodeList records = output_doc.getDocumentElement().getElementsByTagName(RECORD_ELEMENT);
+
+	for(int i=0;i<records.getLength();i++){
+	    Element record = (Element)records.item(i);
+	    calculateRecordLength(record);
+	}
+    }
+
+    private void calculateRecordLength(Element record){
+	int total_length =0;	
+	NodeList controlfileds = record.getElementsByTagName(CONTROLFIELD_ELEMENT);
+	for(int i=0;i<controlfileds.getLength();i++){
+	    Element controlfiled = (Element)controlfileds.item(i);
+	    total_length +=getElementTextValue(controlfiled).length();
+	}
+	
+	NodeList subfileds = record.getElementsByTagName(SUBFIELD_ELEMENT);
+	for(int i=0;i<subfileds.getLength();i++){
+	    Element subfiled = (Element)subfileds.item(i);
+	    total_length +=getElementTextValue(subfiled).length();
+	}
+
+	String record_length = total_length+"";
+	//fill in a extra digit as record length needs to be five characters long
+	if (total_length < 10000){
+	    record_length = "0"+record_length;
+	    if (total_length < 1000){
+		record_length = "0"+record_length;	
+	    }
+	    if (total_length < 100){
+		record_length = "0"+record_length;	
+	    }
+	    if (total_length < 10){
+		 record_length = "0"+record_length;	
+	    }
+	   
+	}
+
+	NodeList leaders = record.getElementsByTagName(LEADER_ELEMENT);	
+	
+	//only one leader element
+        if (leaders.getLength() >0){
+	    Element leader_element = (Element)leaders.item(0);
+	    removeFirstTextNode(leader_element);
+	    leader_element.insertBefore(leader_element.getOwnerDocument().createTextNode(record_length),leader_element.getFirstChild()); 
+	}
+
+    }
+
+    private void removeFirstTextNode(Element element){
+	//remove the first text node
+	NodeList children_nodelist = element.getChildNodes();
+	for (int i = 0; i < children_nodelist.getLength(); i++) {
+	    Node child_node = children_nodelist.item(i);
+	    if (child_node.getNodeType() == Node.TEXT_NODE) {
+		element.removeChild(child_node);
+		return;
+	    }
+	}
+
+    }
+
+    private String getElementTextValue(Element element)
+    {
+	String text ="";	
+
+	// Find the node child
+	NodeList children_nodelist = element.getChildNodes();
+	for (int i = 0; i < children_nodelist.getLength(); i++) {
+	    Node child_node = children_nodelist.item(i);
+	    if (child_node.getNodeType() == Node.TEXT_NODE) {
+		text +=child_node.getNodeValue();
+	    }
+	}
+
+       	return text;
+    }
+ 
+
+    private void setMappingVariable(Document style_doc){
+	Node child = style_doc.getDocumentElement().getFirstChild();
+	while(child != null) {
+	    String name = child.getNodeName();
+	    if (name.equals("xsl:variable")) {
+		Element variable_element = (Element)child;
+		if ( variable_element.getAttribute("name").trim().equals("mapping")){
+		    variable_element.setAttribute("select","document('"+mapping_file+"')/Mapping");
+		}
+	    }
+	    child = child.getNextSibling();
+	}
+	
+    } 
+
+
+    private void translate(String xml_file, String xsl_file, String output_file)throws IOException,TransformerException, TransformerConfigurationException, FileNotFoundException, IOException{             
+         
+      	TransformerFactory tFactory = TransformerFactory.newInstance();
+   	Transformer transformer = tFactory.newTransformer(new StreamSource(xsl_file));
+           
+	OutputStreamWriter output = null;  
+	if (output_file.equals("")) {
+             output = new OutputStreamWriter(System.out, "UTF-8");
+	}
+	else{
+            output = new OutputStreamWriter(new FileOutputStream(output_file), "UTF-8"); 
+	}
+       
+        transformer.transform(new StreamSource(new File(xml_file)),new StreamResult(output));
+        
+    }
+
+     static public String replaceAll(String source_string, String match_regexp, String replace_string)
+    {
+	return source_string.replaceAll(match_regexp, replace_string);
+    }
+
+
+    public static void main(String[] args) 
+    { 
+
+        String xml_file="";
+        String xsl_file="";
+        String mapping_file="";
+        String output_file="";
+      
+	// Checking Arguments
+	if(args.length < 1)
+	    {
+	       printUsage(); 
+	    }           
+
+	for (int i=0;i<args.length;i++){
+	    if (args[i].equals("-m") && i+1 < args.length && !args[i+1].startsWith("-")){
+		 mapping_file = args[++i];
+         	 checkFile(mapping_file.replaceAll("file:///",""));
+	    }
+	    else if (args[i].equals("-x") && i+1 < args.length && !args[i+1].startsWith("-")){
+               xml_file = args[++i]; 
+               checkFile(xml_file.replaceAll("file:///",""));
+	    }
+	    else if(args[i].equals("-t") && i+1 < args.length && !args[i+1].startsWith("-")){
+                xsl_file = args[++i];
+	         checkFile( xsl_file.replaceAll("file:///","")); 
+	    }
+            else if(args[i].equals("-o") && i+1 < args.length && !args[i+1].startsWith("-")){
+                output_file = args[++i];
+	    
+	    }
+	    else if(args[i].equals("-h")){
+                printUsage();
+	    }
+	    else{
+                printUsage();
+	    }
+		  
+	}
+
+         
+	ApplyXSLT core = null;
+	
+ 	if (xml_file.equals("") && !xsl_file.equals("")){//read from pipe line
+	    if (mapping_file.equals("")){ 
+           	 core = new ApplyXSLT(xsl_file);
+	    }
+	    else{
+                core = new ApplyXSLT(xsl_file,mapping_file);  
+	    }
+            
+	    if (core != null){
+		core.process();
+	    }
+	    else{
+		printUsage(); 
+	    }
+ 	}
+ 	else if(!xml_file.equals("") && !xsl_file.equals("")){
+	    core = new ApplyXSLT();
+            try {
+		core.translate(xml_file,xsl_file,output_file); 
+	    }  
+	    catch(Exception e){e.printStackTrace();}
+ 	} 
+	else{
+	    printUsage();    
+	}
+	
+    }
+
+    private static void checkFile(String filename){
+         File file = new File(filename);
+	 if (!file.exists()){
+	     System.out.println("Error: "+filename+" doesn't exist!");
+	     System.exit(-1);
+	 }
+    }
+  
+    private  static void printUsage(){
+	System.out.println("Usage:ApplyXSLT  -x File -t File [-m File] [-o File]");
+        System.out.println("\t-x spacifies the xml file (Note: optional for piped xml data)");
+        System.out.println("\t-t spacifies the xsl file");
+    	System.out.println("\t-m specifies the mapping file (for MARCXMLPlugout.pm only)");
+        System.out.println("\t-o specifies the output file name (output to screen if this option is absent)");
+        System.exit(-1);
+    }
+}
+
+
Index: /gsdl/trunk/build-src/src/java/org/nzdl/gsdl/ApplyXSLTUtil.java
===================================================================
--- /gsdl/trunk/build-src/src/java/org/nzdl/gsdl/ApplyXSLTUtil.java	(revision 16571)
+++ /gsdl/trunk/build-src/src/java/org/nzdl/gsdl/ApplyXSLTUtil.java	(revision 16571)
@@ -0,0 +1,8 @@
+package org.nzdl.gsdl;
+
+public class ApplyXSLTUtil {
+    
+    public static String toLowerCase(String value){
+	return value.toLowerCase();
+    } 
+}
Index: /gsdl/trunk/build-src/src/phind/generate/.cvsignore
===================================================================
--- /gsdl/trunk/build-src/src/phind/generate/.cvsignore	(revision 16571)
+++ /gsdl/trunk/build-src/src/phind/generate/.cvsignore	(revision 16571)
@@ -0,0 +1,4 @@
+Makefile
+suffix
+suffix2
+*.o
Index: /gsdl/trunk/build-src/src/phind/generate/Makefile.in
===================================================================
--- /gsdl/trunk/build-src/src/phind/generate/Makefile.in	(revision 16571)
+++ /gsdl/trunk/build-src/src/phind/generate/Makefile.in	(revision 16571)
@@ -0,0 +1,82 @@
+###########################################################################
+#
+# Makefile -- src/phind/generate
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ../../..
+
+
+CXX = @CXX@
+CXXFLAGS = @CXXFLAGS@ @COMPAT32BITFLAGS@
+DEFS = @DEFS@
+GSDLOS = @gsdlos@
+INCLUDES = 
+INSTALL = @INSTALL@
+LDFLAGS = @LDFLAGS@ @COMPAT32BITFLAGS@
+LIBS = @LIBS@
+
+
+CXXCOMPILE = $(CXX) -c $(CXXFLAGS) $(DEFS) $(INCLUDES)
+CXXLINK = $(CXX) $(LDFLAGS) -o $@
+
+
+.SUFFIXES:
+.SUFFIXES: .cpp .o
+.cpp.o:
+	$(CXXCOMPILE) $< 
+
+
+SOURCES = \
+	phrase.cpp \
+	suffix.cpp
+
+OBJECTS = \
+	phrase.o \
+	suffix.o
+
+EXECUTABLE_OBJECTS = \
+	$(OBJECTS)
+
+EXECUTABLE = suffix
+
+
+# Default target: make the suffix executable
+all: $(EXECUTABLE)
+
+suffix: $(EXECUTABLE_OBJECTS)
+	$(CXXLINK) $(EXECUTABLE_OBJECTS) $(LIBS)
+
+install: $(EXECUTABLE)
+	$(INSTALL) -d $(GSDL_DIR)/bin/$(GSDLOS)
+	$(INSTALL) -m 755 -s $(EXECUTABLE) $(GSDL_DIR)/bin/$(GSDLOS)
+
+clean:
+	rm -f $(OBJECTS) $(EXECUTABLE)
+
+distclean:
+	rm -f $(OBJECTS) $(EXECUTABLE) Makefile
+
+depend:
+	makedepend -Y -- $(DEFS) $(INCLUDES) $(CXXFLAGS) -- $(SOURCES)
Index: /gsdl/trunk/build-src/src/phind/generate/check.h
===================================================================
--- /gsdl/trunk/build-src/src/phind/generate/check.h	(revision 16571)
+++ /gsdl/trunk/build-src/src/phind/generate/check.h	(revision 16571)
@@ -0,0 +1,130 @@
+// check.h -- manipulate the suffixCheck array
+//
+// The suffixCheck array is used to prevent a phrase being added to
+// the results of getExpansions.  It works by declaring an array that
+// has one bit for each entry in the suffix array, which is cleared at
+// the start of getExpansions.  As getExpansions adds each phrase to
+// the result set, we set the bits in the suffixCheck array that
+// correspond to the positions of of the phrase in the suffixArray.
+
+// (The point is that getExpansions can later check whether a phrase
+// or its prefix has been seen before by looking up the bit
+// corresponding to its first occurence in the suffixCheck array: if
+// the bit is set, a subphrase of this phrase is already in the
+// results already, and the current phrase can be ignored.)
+
+#include "suffix.h"
+
+// The suffixCheck array
+#if defined (__WIN32__)
+typedef unsigned char check;
+#else
+#include <inttypes.h>
+typedef uint8_t check;
+#endif
+
+check *suffixCheck;
+
+// The length of the suffixCheck array
+cellcount checkLength;
+
+// Some useful bitmask constants 
+const check ALLBITS        = 255;
+const check LEFTMOSTBIT    = static_cast<check>(ALLBITS << 7);
+const check LEFTMOSTBITS[] = {static_cast<check>(ALLBITS << 8), 
+			      static_cast<check>(ALLBITS << 7), 
+			      static_cast<check>(ALLBITS << 6), 
+			      static_cast<check>(ALLBITS << 5), 
+			      static_cast<check>(ALLBITS << 4),
+			      static_cast<check>(ALLBITS << 3), 
+			      static_cast<check>(ALLBITS << 2), 
+			      static_cast<check>(ALLBITS << 1),  
+			      static_cast<check>(ALLBITS << 0)};
+
+
+// Allocate the initial memory for suffixCheck
+inline void allocateSuffixCheck(cellcount number_of_symbols) 
+{
+  checkLength = number_of_symbols / (sizeof(check) * 8) + 1;
+  suffixCheck = new check[checkLength];
+  if (suffixCheck == NULL) {
+    cerr << "Suffix error: out of memory allocating suffixCheck array" << endl; 
+    exit(2);
+  }
+  memset(suffixCheck, 0, sizeof(check) * checkLength);
+}
+
+
+// Set all bits in suffixCheck to 0
+inline void clearSuffixCheck() 
+{
+  memset(suffixCheck, 0, sizeof(check) * checkLength);
+}
+
+
+// Get the value of a particular bit in suffixCheck
+inline int getSuffixCheck(cellindex position) 
+{
+  cellindex cell = position >> 3;
+  check remainder = position & 0x07; // the last 3 bits
+  if (suffixCheck[cell] & (LEFTMOSTBIT >> remainder)) {
+    return 1;
+  }
+  return 0;
+}                                                                               
+
+// Set the value of a bit in suffixCheck to 1
+inline void setSuffixCheck(cellindex suff) 
+{
+  cellindex cell = suff >> 3;
+  check remainder = suff & 0x07u; // the last 3 bits
+  suffixCheck[cell] |= (LEFTMOSTBIT >> remainder);
+}  
+
+
+// Set the bits in a cell in the suffixArray.
+// Bits are indexed 0-7.
+inline void setCellBits(cellindex cell_offset, unsigned first_bit, unsigned last_bit) 
+{
+  unsigned number_of_bits = last_bit - first_bit + 1;
+  check mask = (LEFTMOSTBITS[number_of_bits] >> first_bit);
+  suffixCheck[cell_offset] |= mask;
+}
+
+
+inline void setSuffixCheck(cellindex first, cellindex last) 
+{
+  // Find the first and last cells in which bits are set
+  cellindex first_cell = first >> 3;
+  cellindex last_cell = last >> 3;
+
+  // If all the values are in the same cell, set them
+  if (first_cell == last_cell) {
+    setCellBits(first_cell, (first & 0x07u), (last & 0x07u));
+    return;
+  }
+
+  // Set the bits in the first and last cells
+  setCellBits(first_cell, (first & 0x07u), 7);
+  setCellBits(last_cell, 0, (last & 0x07u));
+
+  // Set the bits in the intermediate cells
+  ++first_cell;
+  if(last_cell > first_cell)
+    memset(suffixCheck + first_cell, ALLBITS, 
+	   (last_cell - first_cell) * sizeof(check));
+}
+
+
+// Print the suffixCheck array (for debugging)
+void printSuffixCheck() 
+{
+  for (cellcount i = 0; i < checkLength; ++i) {
+    cout << "cell " << i << "  \t";
+    cout << "(" << (i * 8) << "-" << (i * 8 + 7) << ")    \t";
+    for (cellindex j = 0; j < 8; ++j)
+      cout << getSuffixCheck(i * 8 + j);
+    cout << " (" << (unsigned int) suffixCheck[i] << ")\n";
+  }
+}
+
Index: /gsdl/trunk/build-src/src/phind/generate/phrase.cpp
===================================================================
--- /gsdl/trunk/build-src/src/phind/generate/phrase.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/src/phind/generate/phrase.cpp	(revision 16571)
@@ -0,0 +1,853 @@
+/**********************************************************************
+ *
+ * phrase.cpp -- implementation of the phrase object used by suffix.cpp
+ *
+ * Copyright 2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#if defined(GSDL_USE_STL_H)
+#  include <vector.h>
+#else
+#  include <vector>
+#endif
+
+#if defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+#endif
+
+#include "suffix.h"
+#include "phrase.h"
+
+
+// Phrase constructor functions
+
+Phrase::Phrase(symbol *words, cellcount size, int direction) {
+  empty();
+  length = size;
+
+  if (direction == SUFFIX) {
+     forward = words;
+     back = forward + size - 1;
+  } else {
+    back = words;
+    forward = back - size + 1;
+  }
+}
+
+
+Phrase::Phrase() {
+  empty();
+}
+
+
+Phrase::Phrase(const Phrase &p) {
+  forward = p.forward;
+  back = p.back;
+  length = p.length;
+
+  suffixFound = p.suffixFound;
+  prefixFound = p.prefixFound;
+
+  firstSuffix = p.firstSuffix;
+  lastSuffix  = p.lastSuffix;
+  firstSuffixIndex = p.firstSuffixIndex;
+  lastSuffixIndex  = p.lastSuffixIndex;
+  suffixFrequency  = p.suffixFrequency;
+
+  firstPrefix = p.firstPrefix;
+  lastPrefix  = p.lastPrefix;
+  firstPrefixIndex = p.firstPrefixIndex;
+  lastPrefixIndex  = p.lastPrefixIndex;
+  prefixFrequency  = p.prefixFrequency;
+
+  uniqueSuffixExtension = p.uniqueSuffixExtension;
+  uniquePrefixExtension = p.uniquePrefixExtension;
+}
+
+
+// Empty the contents of a phrase
+
+int Phrase::empty() {
+
+  forward = back = NULL;
+  length = 0;
+
+  suffixFound = prefixFound = 0;
+  firstSuffix = firstPrefix = NULL;
+  lastSuffix = lastPrefix = NULL;
+
+  firstSuffixIndex = lastSuffixIndex = suffixFrequency = 0;
+  firstPrefixIndex = lastPrefixIndex = prefixFrequency = 0;
+
+  uniqueSuffixExtension = uniquePrefixExtension = -1;
+
+  return 0;
+}
+
+// Remove the details of the location where a suffix/prefix
+// is found in the array.
+
+int Phrase::clearSuffix() {
+  suffixFound = 0;
+  firstSuffix = lastSuffix = NULL;
+  firstSuffixIndex = lastSuffixIndex = suffixFrequency = 0;
+  uniqueSuffixExtension = -1;
+  return 0;
+}
+
+int Phrase::clearPrefix() {
+  prefixFound = 0;
+  firstPrefix = lastPrefix = NULL;
+  firstPrefixIndex = lastPrefixIndex = prefixFrequency = 0;
+  uniquePrefixExtension = -1;
+  return 0;
+}
+
+// Increase the length of s phrase
+//
+// We increase the length of a string "in place".  When we expand
+// the suffix, however, we invalidate the prefix data, and vice-versa.
+
+int Phrase::increaseSuffixLength(cellcount l) {
+  length = l;
+  clearPrefix();
+  back = forward + l - 1;
+  return 0;
+}
+
+int Phrase::increasePrefixLength(cellcount l) {
+  length = l;
+  clearSuffix();
+  forward = back - l + 1;
+  return 0;
+}
+
+// Shorten a phrase by one symbol
+int Phrase::shortenByOneAtSuffix() {
+  --length;
+  --back;
+  if (phraseMode==STOPWORDS) {
+    while (*back >=firstStopSymbol && *back <= lastStopSymbol) {
+      --length;
+      --back;
+    }
+  }  
+  clearSuffix();
+  clearPrefix();
+  return 0;
+}
+
+int Phrase::shortenByOneAtPrefix() {
+  --length;
+  ++forward;
+  if (phraseMode==STOPWORDS) {
+    while (*forward >=firstStopSymbol && *forward <= lastStopSymbol) {
+      --length;
+      ++forward;
+    }
+  }
+  clearSuffix();
+  clearPrefix();
+  return 0;
+}
+
+
+// Output a phrase to a stream
+ostream &operator<<(ostream &stream, const Phrase &phrase)
+{
+  assert(phrase.forward);
+  symbol *s = phrase.forward;
+
+  stream << "s" << *s++;
+  for (cellcount i = 1; i < phrase.length; ++i)
+    stream << " s" << *s++;
+
+  return stream;
+}
+
+
+// Convert the phrase to a string
+// Note thgat you have to delete the memory yourself.
+char *Phrase::toString() 
+{
+  assert(forward);
+
+  char *str;
+  str = new char[length*20];
+  symbol *s = forward;
+  sprintf(str, "s%d", *s++);
+
+  for (cellcount i = 1; i < length; ++i) {
+    sprintf(str, "%s s%d", str, *s++);
+  }
+
+  return str;
+}
+
+
+// Compare a phrase to an another array of symbols
+//
+// Given an array of words with a specified length, 
+// compare those words to this phrase.
+//
+// Return 0 if the two phrases are the same over length length
+// Return 1 if the phrase is "greater" than tyhe words, or
+// Return -1 if the phrase is less.
+
+int Phrase::compareSuffix(symbol *words, cellcount length) {
+  assert(forward);
+  symbol *p = forward;
+  
+  for (cellcount i = 0; i < length; ++i) {
+    if (*p > *words) {
+      return 1;
+    } else if (*p < *words) {
+      return -1;
+    } else {
+      *p++;
+      *words++;
+    }
+  }
+
+  return 0;
+
+}
+
+int Phrase::comparePrefix(symbol *words, cellcount length) {
+  
+  assert(back);
+  symbol *p = back;
+  
+  for (cellcount i = 0; i < length; ++i) {
+    if (*p > *words) {
+      return -1;
+    } else if (*p < *words) {
+      return 1;
+    } else {
+      *p--;
+      *words--;
+    }
+  }
+
+  return 0;
+
+}
+
+
+// Does the phrase have a unique suffix/prefix extension?
+//
+// For suffix:
+//   If uniqueSuffixExtensions is 1, then phrase has some unique expansion. 
+//   If it is 0 then it does not.  If it is -1 then we don't know, and have
+//   to calculate it from the suffix array.  Same goes for prefixes.
+
+int Phrase::hasUniqueSuffixExtension() {
+
+  // if we don't know, then work it out
+  if (uniqueSuffixExtension == -1) {
+
+    ensureSuffixFound();
+
+    // pointers to the phrase's first and last occurances in te suffixArray
+    symbol *fst = firstSuffix + length;
+    symbol *lst = lastSuffix + length;
+
+    // in ANYPHRASE mode, simply check the next symbol
+    if (phraseMode == ANYPHRASE) {
+      if ((*fst == *lst) && (*fst > LASTDELIMITER)) {
+	uniqueSuffixExtension = 1;
+      } else {
+	uniqueSuffixExtension = 0;
+      }
+    }
+    // in STOPWORDS mode, make sure there is a unique next content symbol
+    else {
+      uniqueSuffixExtension = 0;
+      while ((*fst == *lst) && (*fst > LASTDELIMITER)) {
+	if (*fst >= firstContentSymbol) {
+	  uniqueSuffixExtension = 1;
+	  break;
+	}
+	++fst;
+	++lst;
+      }
+    }
+  }
+
+  return uniqueSuffixExtension;
+}
+
+int Phrase::hasUniquePrefixExtension() {
+
+  // if we don't know, then work it out
+  if (uniquePrefixExtension == -1) {
+
+    ensurePrefixFound();
+
+    // pointers to the phrase's first and last occurances in the prefixArray
+    symbol *fst = firstPrefix - length;
+    symbol *lst = lastPrefix - length;
+
+    // in ANYPHRASE mode, simply check the next symbol
+    if (phraseMode == ANYPHRASE) {
+      if ((*fst == *lst) && (*fst > LASTDELIMITER)) {
+	uniquePrefixExtension = 1;
+      } else {
+	uniquePrefixExtension = 0;
+      }
+    }
+    // in STOPWORDS mode, make sure there is a unique next content symbol
+    else {
+      uniquePrefixExtension = 0;
+      while ((*fst == *lst) && (*fst > LASTDELIMITER)) {
+	if (*fst >= firstContentSymbol) {
+	  uniquePrefixExtension = 1;
+	  break;
+	}
+	--fst;
+	--lst;
+      }
+    }
+  }
+
+  return uniquePrefixExtension;
+}
+
+
+// Expand a phrase with a unique suffix/prefix by 1 symbol
+//
+// Note that in STOPWORDS mode a "unique extension" means a unique
+// extension that ends on a content symbol.  Although we may extend 
+// such a phrase by 2 or more symbols, we will only extend it by a
+// single content symbol.
+
+int Phrase::expandUniqueSuffixExtensionByOne() {
+  assert(suffixFound);
+  assert(uniqueSuffixExtension == 1);
+
+  // in ANYPHRASE mode, expand the phrase by one symbol
+  if (phraseMode == ANYPHRASE) {
+    increaseSuffixLength(length + 1);
+  }
+  // in STOPWORDS mode, expand the phrase up to the next content symbol
+  else {
+    symbol *next = firstSuffix + length;
+    cellcount newlength = length + 1;
+
+    while (*next < firstContentSymbol) {
+      ++next;
+      ++newlength;
+    }
+    increaseSuffixLength(newlength);
+  }
+
+  uniqueSuffixExtension = -1;
+  return 0;
+}
+
+int Phrase::expandUniquePrefixExtensionByOne() {
+  assert(prefixFound);
+  assert(uniquePrefixExtension == 1);
+
+  // in ANYPHRASE mode, expand the phrase by one symbol
+  if (phraseMode == ANYPHRASE) {
+    increasePrefixLength(length + 1);
+  }
+  // in STOPWORDS mode, expand the phrase to the next content symbol
+  else {
+    symbol *next = firstPrefix - length;
+    cellcount newlength = length + 1;
+    while (*next < firstContentSymbol) {
+      --next;
+      ++newlength;
+    }
+    increasePrefixLength(newlength);
+
+  }
+
+  uniquePrefixExtension = -1;
+  return 0;
+}
+
+
+// Find the phrase in a suffixArray
+//
+// Given a suffix array, find the first and last occurances of the phrase.
+// The begin and end parameters identify which cells to search (inclusive). 
+
+int Phrase::findFirstAndLastSuffix() {
+  
+  return findFirstAndLastSuffix(0, inputLength-1);
+}
+
+int Phrase::findFirstAndLastSuffix(cellindex begin, cellindex end) {
+
+  // First find *any* occurance of the phrase
+  assert(begin <= end);
+
+  // if we're only searching one cell, it is very easy
+  if (begin == end) {
+    assert(compareSuffix(suffixArray[begin], length) == 0);
+    firstSuffix = lastSuffix = suffixArray[begin];
+    firstSuffixIndex = lastSuffixIndex = begin;
+    suffixFrequency = 1;
+    suffixFound = 1;
+    return 0;
+  }
+
+  cellindex c;
+  int cmp;
+
+  do {
+    c = (end + begin) / 2;
+    cmp = compareSuffix(suffixArray[c], length);
+    if (cmp == 1) {
+      // target phrase is lower than phrase at suffixArray[c]
+      begin = c + 1;
+    } else if (cmp == -1) {
+      // target phrase is higher than phrase at suffixArray[c]
+      end = c - 1;
+    }
+  } while (cmp != 0);
+    
+  cellindex lastbegin = c;
+  cellindex lastend = end;
+
+  // Next find the first occurance of the phrase.
+  // We know that the first occurance must be between the 
+  // current value of begin and the current value of c.
+  end = c;
+
+  do {
+    if (begin == end) {
+      c = begin;
+      cmp = 0;
+    } else {
+      c = (begin + end) / 2;
+      cmp = compareSuffix(suffixArray[c], length);
+      if (cmp == 1) {
+	// target phrase is lower than phrase at suffixArray[c]
+	begin = c + 1;
+      } else {
+	assert(cmp == 0);
+	// target phrase is the same as the phrase at suffixArray[c].  However,
+	// to find the first occurance, suffixArray[c] must be the same as the 
+	// phrase, but suffixArray[c-1] must be different.
+	if (c>0) {
+	  cmp = compareSuffix(suffixArray[c-1], length);
+	  if (cmp == 0) {
+	    end = c - 1;
+	    assert(end >= begin);
+	    cmp = 1;
+	  } else {
+	    cmp = 0;
+	  }
+	}
+      }
+    }
+  } while (cmp != 0);
+
+  // we have found the first location
+  firstSuffixIndex = c;
+  firstSuffix = suffixArray[c];
+  
+  // Next find the last occurance of the phrase.
+  // We previously stored some bounds for its loccation.
+  begin = lastbegin;
+  end = lastend;
+  
+  do {
+    if (begin == end) {
+      c = begin;
+      cmp = 0;
+    } else {
+      c = (begin + end) / 2;
+      cmp = compareSuffix(suffixArray[c], length);
+      if (cmp == -1) {
+	// target phrase is greater than phrase at suffixArray[c]
+	end = c - 1;
+      } else {
+	assert(cmp == 0);
+	// target phrase is the same as the phrase at suffixArray[c].  However,
+	// to find the last occurance, one of two additional condiditons must be met:
+	// either c must be the very last cell in the array, or
+	// suffixArray[c+1] must be different from phrase
+	if (c < inputLength-1) {
+	  cmp = compareSuffix(suffixArray[c+1], length);
+	  if (cmp == 0) {
+	    begin = c + 1;
+	    cmp = -1;
+	  } else {
+	    cmp = 0;
+	  }
+	} 
+      }
+    }
+  } while (cmp != 0);
+  
+  lastSuffixIndex = c;
+  lastSuffix = suffixArray[c];
+  suffixFrequency = lastSuffixIndex - firstSuffixIndex + 1;
+  suffixFound = 1;
+
+  return 0;
+}
+
+
+// Find the phrase in a prefix array
+//
+// Given a prefix array, find the first and last occurances of the phrase.
+// The begin and end parameters identify which cells to search (inclusive). 
+
+int Phrase::findFirstAndLastPrefix() {
+  return findFirstAndLastPrefix(0, inputLength-1);
+}
+
+int Phrase::findFirstAndLastPrefix(cellindex begin, cellindex end) {
+
+  // First find *any* occurance of the phrase
+  assert(begin <= end);
+
+  // if we're only searching one cell, it is very easy
+  if (begin == end) {
+    assert(comparePrefix(prefixArray[begin], length) == 0);
+    firstPrefix = lastPrefix = prefixArray[begin];
+    firstPrefixIndex = lastPrefixIndex = begin;
+    prefixFrequency = 1;
+    prefixFound = 1;
+    return 0;
+  }
+
+  cellindex c;
+  int cmp;
+
+  do {
+    c = (end + begin) / 2;
+    cmp = comparePrefix(prefixArray[c], length);
+    if (cmp == 1) {
+      begin = c + 1;
+    } else if (cmp == -1) {
+      end = c - 1;
+    }
+  } while (cmp != 0);
+    
+  cellindex lastbegin = c;
+  cellindex lastend = end;
+
+  // Next find the first occurance of the phrase.
+  // We know that the first occurance must be between the 
+  // current value of begin and the cureent value of c.
+  end = c;
+
+  do {
+    if (begin == end) {
+      c = begin;
+      cmp = 0;
+    } else {
+      c = (begin + end) / 2;
+      cmp = comparePrefix(prefixArray[c], length);
+      if (cmp == 1) {
+	// target phrase is lower than phrase at prefixArray[c]
+	begin = c + 1;
+      } else {
+	assert(cmp == 0);
+	// target phrase is the same as the phrase at prefixArray[c].  However, to
+	// find the first occurance, one of two additional condiditons must be met:
+	// either  c == the first cell in prefix array
+	// or      prefixArray[c-1] != phrase.
+	if (c > 0) {
+	  cmp = comparePrefix(prefixArray[c-1], length);
+	  if (cmp == 0) {
+	    end = c - 1;
+	    assert(end >= begin);
+	    cmp = 1;
+	  } else {
+	    cmp = 0;
+	  }
+	}
+      }
+    }
+  } while (cmp != 0);
+
+  // we have found the first location
+  firstPrefixIndex = c;
+  firstPrefix = prefixArray[c];
+
+  // Next find the last occurance of the phrase.
+  // We previously stored some bounds for its loccation.
+  begin = lastbegin;
+  end = lastend;
+  
+  do {
+    if (begin == end) {
+      c = begin;
+      cmp = 0;
+    } else {
+      c = (begin + end) / 2;
+      cmp = comparePrefix(prefixArray[c], length);
+      if (cmp == -1) {
+	// target phrase is greater than phrase at prefixArray[c]
+	end = c - 1;
+      } else {
+	assert(cmp == 0);
+	// target phrase is the same as the phrase at prefixArray[c].  However,
+	// to find the last occurance, prefixArray[c] must be the same as the 
+	// phrase, but prefixArray[c+1] must be different.
+	cmp = comparePrefix(prefixArray[c+1], length);
+	if (cmp == 0) {
+	  begin = c + 1;
+	  cmp = -1;
+	} else {
+	  cmp = 0;
+	}
+      } 
+    }
+  } while (cmp != 0);
+  
+  lastPrefixIndex = c;
+  lastPrefix = prefixArray[c];
+  prefixFrequency = lastPrefixIndex - firstPrefixIndex + 1;
+  prefixFound = 1;
+
+  return 0;
+}
+
+
+// Calculate a set of initial suffix/prefix candidates
+//
+// Expand the phrase to find the initial 
+// set of candidates that may be extensions of that phrase,
+// and add them to the end of the results vector
+
+void Phrase::initialSuffixCandidates(vector<Phrase> &results) {
+
+  ensureSuffixFound();
+  Phrase next;
+  cellindex i = firstSuffixIndex;
+
+  // Find all the expansions of Phrase p
+  while (i <= lastSuffixIndex) {
+
+    // create new phrase exactly one longer than the current one
+    next = newPhraseShortestSuffixExpansion(i);
+
+    // If the expansion occurs more than once and is not delimited, expand it
+    if ((*(next.back) > LASTDELIMITER) && (next.suffixFrequency >= minOccurs)) {
+      next.expandWhileUniqueSuffixExtension();
+      results.push_back(next);
+    }
+    
+    // Move onto the next expansion
+    i = next.lastSuffixIndex + 1;
+  }
+}
+
+
+void Phrase::initialPrefixCandidates(vector<Phrase> &results) {
+
+  ensurePrefixFound();
+  Phrase next;
+  cellindex i = firstPrefixIndex;
+
+  // Find all the expansions of Phrase p
+  while (i <= lastPrefixIndex) {
+
+    // create new phrase exactly one longer than the current one
+    next = newPhraseShortestPrefixExpansion(i);
+
+    // If the expansion occurs more than once and is not delimited, expand it
+    if ((*(next.forward) > LASTDELIMITER) && (next.prefixFrequency >= minOccurs)) {
+      next.expandWhileUniquePrefixExtension();
+      results.push_back(next);
+    }
+    
+    // Move onto the next expansion
+    i = next.lastPrefixIndex + 1;
+  }
+}
+
+
+// Create a new phrase that is longer then the current one, but as short
+// as possible.  In ANYPHRASE mode this means the new phrase is exactly
+// one symbol longer than the current one, but in STOPWORD mode the expansion
+// must introduce a new content symbol
+//
+// Note that we never expand across delimiters; if we encounter a delimiter
+// then this becomes the "end" symbol of the phrase.  The calling function 
+// should check for this condition.
+
+Phrase Phrase::newPhraseShortestSuffixExpansion(cellindex i) {
+  
+  // create a new phrase exactly one symbol longer than the current one
+  Phrase p(suffixArray[i], length + 1, SUFFIX);
+
+  if (phraseMode == STOPWORDS) {
+    // in STOPWORDS mode we must introduce a new content symbol
+    while ((*(p.back) >= firstStopSymbol) &&
+	   (*(p.back) <= lastStopSymbol)) {
+      p.increaseSuffixLength(p.length + 1);
+    }
+  }
+
+  p.findFirstAndLastSuffix(i, lastSuffixIndex);
+  return p;
+}
+
+Phrase Phrase::newPhraseShortestPrefixExpansion(cellindex i) {
+  
+  // create a new phrase exactly one symbol longer than the current one
+  Phrase p(prefixArray[i], length + 1, PREFIX);
+
+  if (phraseMode == STOPWORDS) {
+    // in STOPWORDS mode we must introduce a new content symbol
+    while ((*(p.forward) >= firstStopSymbol) &&
+	   (*(p.forward) <= lastStopSymbol)) {
+      p.increasePrefixLength(p.length + 1);
+    }
+  }
+
+  p.findFirstAndLastPrefix(i, lastPrefixIndex);
+  return p;
+}
+
+
+// Expand a phrase until it no longer has a unique suffix extension
+// 
+// If the phrase only occurs once in the suffix array, do nothing.
+//
+// If we are in stopwords mode then we expand if there is a unique 
+// suffix expansion and this expansion is a content word.  We do this
+// with the content_len variable, which holds the length of the longest
+// phrase ending in a content word. 
+
+int Phrase::expandWhileUniqueSuffixExtension() {
+  ensureSuffixFound();
+
+  // if the phrase occurs only once, do nothing
+  if (suffixFrequency < minOccurs)
+    return 0;
+
+  // if we already know there's no unique suffix extension, do nothing
+  if (uniqueSuffixExtension == 0)
+    return 0;
+
+  // count the length over which the cells are the same
+  // and no delimiter is crossed.
+  symbol *fst = firstSuffix;
+  symbol *lst = lastSuffix;
+  cellindex len = 0;
+  cellindex content_len = 0;
+
+  // Calculate the length over which the phrases match
+  while((*fst == *lst) && (*fst > LASTDELIMITER)) {
+    ++len;
+    if (*fst > lastStopSymbol) content_len = len;
+    ++fst;
+    ++lst;
+  }
+
+  // in ANYPHRASE mode, expand the phrase for as long as possible
+  if (phraseMode == ANYPHRASE) {
+    if (len > length) {
+      increaseSuffixLength(len);
+    }
+  } 
+  // in STOPWORDS mode, expand only as far as the last contentword
+  else {
+    if (content_len > length) {
+      increaseSuffixLength(content_len);
+    }
+  }
+
+  uniqueSuffixExtension = 0;
+  return 0;
+}
+
+int Phrase::expandWhileUniquePrefixExtension() {
+  ensurePrefixFound();
+
+  // if the phrase occurs only once, do nothing
+  if (prefixFrequency < minOccurs)
+    return 0;
+
+  // if we already know there's no unique extension, do nothing
+  if (uniquePrefixExtension == 0)
+    return 0;
+
+  // count the length over which the cells are the same
+  // and no delimiter is crossed.
+  symbol *fst = firstPrefix;
+  symbol *lst = lastPrefix;
+  cellindex len = 0;
+  cellindex content_len = 0;
+
+  // Calculate the length over which the phrases match
+  while((*fst == *lst) && (*fst > LASTDELIMITER)) {
+    ++len;
+    if (*fst > lastStopSymbol) content_len = len;
+    --fst;
+    --lst;
+  }
+
+  // in ANYPHRASE mode, expand the phrase for as long as possible
+  if (phraseMode == ANYPHRASE) {
+    if (len > length) {
+      increasePrefixLength(len);
+    }
+  }
+  // in STOPWORDS mode, expand only as far as the last contentword
+  else {
+    if (content_len > length) {
+      increasePrefixLength(content_len);
+    }
+  }
+
+  uniquePrefixExtension = 0;
+  return 0;
+}
+
+// Compare the length of two phrases
+//
+// Given two phrases, return true if the first is shorter/longer,
+// otherwise return false.  For use in various sort functions.
+
+bool isShorter(Phrase p1, Phrase p2) {
+  if (p1.length < p2.length) {
+    return true;
+  }
+  return false;
+}
+
+bool isLonger(Phrase p1, Phrase p2) {
+  if (p1.length > p2.length) {
+    return true;
+  }
+  return false;
+}
+
+
Index: /gsdl/trunk/build-src/src/phind/generate/phrase.h
===================================================================
--- /gsdl/trunk/build-src/src/phind/generate/phrase.h	(revision 16571)
+++ /gsdl/trunk/build-src/src/phind/generate/phrase.h	(revision 16571)
@@ -0,0 +1,162 @@
+/**********************************************************************
+ *
+ * phrase.h -- definition of the phrase object used by suffix.cpp
+ *
+ * Copyright 2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef PHRASE_H
+#define PHRASE_H
+
+// use the standard namespace
+#if !defined (GSDL_NAMESPACE_BROKEN)
+#if defined(GSDL_USE_OBJECTSPACE)
+using namespace ospace::std;
+#else
+using namespace std;
+#endif
+#endif
+
+#if defined(GSDL_USE_STL_H)
+#  include <vector.h>
+#else
+#  include <vector>
+#endif
+
+#include "suffix.h"
+
+class Phrase {
+
+public:
+
+  // The phrase itself is stored with two pointers: forward points to
+  // its first cell, back points to its last.  The length is always
+  // stored in length.  If one of these is set, all must be set, and
+  // it must be true that (forward + length - 1) = back.
+  symbol *forward;
+  symbol *back;
+  cellcount length;
+  
+  // Phrase location in the suffix array
+  int suffixFound;
+  symbol *firstSuffix;
+  symbol *lastSuffix;
+  cellindex firstSuffixIndex;
+  cellindex lastSuffixIndex;
+  cellcount suffixFrequency;
+
+  // Phrase location in the prefix array
+  int prefixFound;
+  symbol* firstPrefix;
+  symbol* lastPrefix;
+  cellindex firstPrefixIndex;
+  cellindex lastPrefixIndex;
+  cellcount prefixFrequency;
+
+  // Constructor functions
+  Phrase();
+  Phrase(const Phrase &p);
+
+  // A "partial" constructor: the first argument is an array of words,
+  // second is its length, third is the direction (SUFFIX or PREFIX)
+  // in which the words should be read (defaults to SUFFIX).
+  Phrase(symbol *words, cellcount size, int direction);
+
+  // Represent the phrase as an arracy of characters
+  // You will have to call "delete []" on the array returned. 
+  char *toString();
+
+  // Find an initial set of candidate phrases in the suffix/prefix array
+  void initialSuffixCandidates(vector<Phrase> &results);
+  void initialPrefixCandidates(vector<Phrase> &results);
+  
+  // Does the phrase have a unique extension?
+  int hasUniqueSuffixExtension();
+  int hasUniquePrefixExtension();
+  
+  // Extend a phrase by exactly one symbol
+  int expandUniquePrefixExtensionByOne();
+  int expandUniqueSuffixExtensionByOne();
+
+  // Extend a phrase until it no longer has a unique extanesion
+  int expandWhileUniqueSuffixExtension();
+  int expandWhileUniquePrefixExtension();
+
+  // Shorten a phrase by one symbol
+  int shortenByOneAtSuffix();
+  int shortenByOneAtPrefix();
+
+  // Find the phrase in the suffix/prefix array
+  int findFirstAndLastSuffix();
+  int findFirstAndLastPrefix();
+  int findFirstAndLastSuffix(cellindex begin, cellindex end);
+  int findFirstAndLastPrefix(cellindex begin, cellindex end);
+
+  // Make sure the phrase location in the suffix/prefix array is known
+  inline void ensureSuffixFound() {
+    if (!suffixFound)
+      findFirstAndLastSuffix();
+  }
+  inline void ensurePrefixFound() {
+    if (!prefixFound)
+      findFirstAndLastPrefix();
+  }
+
+  // Output a phrase to a stream
+  friend ostream &operator<<(ostream &stream, const Phrase &phrase);
+
+  int uniqueSuffixExtension;
+  int uniquePrefixExtension;
+
+private:
+
+  // Does the phrase have a unique suffix/prefix extension?
+  // if yes, then 1; if no then 0; if unknown then -1;
+
+  // reset a phrase
+  int empty();
+
+  // reset phrase information relating to location in suffix/prefix array
+  int clearSuffix();
+  int clearPrefix();
+
+  // increase the length of a phrase "in place"
+  int increaseSuffixLength(cellcount l);
+  int increasePrefixLength(cellcount l);
+    
+  // Compare the phrase to a given array of symbols
+  int compareSuffix(symbol *words, cellcount length);
+  int comparePrefix(symbol *words, cellcount length);
+
+  // Create a new phrase that is longer than this one, yet as short as possible.
+  Phrase newPhraseShortestSuffixExpansion(cellindex i);
+  Phrase newPhraseShortestPrefixExpansion(cellindex i);
+
+};
+
+
+bool isShorter(Phrase p1, Phrase p2);
+bool isLonger(Phrase p1, Phrase p2);
+
+#endif
+
Index: /gsdl/trunk/build-src/src/phind/generate/suffix.cpp
===================================================================
--- /gsdl/trunk/build-src/src/phind/generate/suffix.cpp	(revision 16571)
+++ /gsdl/trunk/build-src/src/phind/generate/suffix.cpp	(revision 16571)
@@ -0,0 +1,1094 @@
+/**********************************************************************
+ *
+ * Suffix.cpp -- Extract the repeated phrases in the input with suffix
+ *               and prefix arrays (cgn & gwp's simpler algorithm,
+ *               and kjm's improvements).
+ *
+ * Copyright 2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software from the 
+ * New Zealand Digital Library Project at the University of Waikato, 
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(GSDL_USE_IOS_H)
+#  include <fstream.h>
+#  include <iostream.h>
+#else
+#  include <fstream>
+#  include <iostream>
+#endif
+
+#if defined(GSDL_USE_STL_H)
+#  if defined(GSDL_USE_ALGO_H)
+#    include <algo.h>
+#  else
+#    include <algorithm.h>
+#  endif
+#  include <vector.h>
+#else
+#  include <algorithm>
+#  include <vector>
+#endif
+
+#include "suffix.h"
+#include "phrase.h"
+#include "check.h"
+
+// Global variables declared in suffix.h
+cellcount inputLength;
+
+symbol   *symbols;
+symbol  **suffixArray;
+symbol  **prefixArray;
+
+// How many documents are in this collection?
+cellcount numberOfDocuments;
+symbol  **documentArray;
+
+
+// Do we accept any phrase, or do we eliminate those ending with stopwords ?
+int phraseMode = ANYPHRASE; //STOPWORDS;
+// What is the minimum phrase frequency for a phrase to be included in the hierarchy
+int minOccurs = 2;
+
+// The filestem of the collection's phindex directory
+char collection[FILENAME_MAX];
+
+
+// The ranges of the stopword and content-word symbols for the collection
+symbol firstStopSymbol = 0;
+symbol lastStopSymbol = 0;
+symbol firstContentSymbol = 0;
+symbol lastContentSymbol = 0;
+
+
+// Some useful comparison functions, defined below.
+int suffixCompare(const void *, const void *);
+int prefixCompare(const void *, const void *);
+int pointerCompare(const void *, const void *);
+
+                                           
+// Functions for implementing "phrase memory".  These let us "remember"
+// each phrase that we've expanded without using too much memory.
+void initialisePhraseMemory();
+void rememberThisPhrase(cellindex index, cellcount length);
+bool isPhraseStored(cellindex index, cellcount length);
+void deletePhraseMemory();
+
+
+// how much output do we want?
+int verbosity = 1;
+
+
+// Get a phrase's expansions
+//
+// Get the set of "minimal", "maximal", non-unique expansions of a
+// phrase p, using the simpler algorithm that Craig and Gordon came up
+// with at Google.
+//
+// Returns a vector of Expansions.
+
+void getExpansions(Phrase &p, vector<Phrase> &results) {
+
+  // 1. Get the initial candidates
+  vector<Phrase> candidates;
+  p.initialSuffixCandidates(candidates);
+  int suffcands = candidates.size();
+  p.initialPrefixCandidates(candidates);
+
+  if (candidates.size() == 0)
+    return;
+
+  vector<Phrase>::iterator i;
+  for (i = candidates.begin(); i != candidates.end(), suffcands>0; ++i, --suffcands) {
+    i->expandWhileUniquePrefixExtension();
+    i->ensureSuffixFound();
+  }
+  for (i; i != candidates.end(); ++i) {
+    i->expandWhileUniqueSuffixExtension();
+  }
+
+  // 3. Ensure minimality: ignore phrases whose subphrases are also found
+  results.clear();
+
+  // Initialise the candidates, check array, and various variables.
+  sort(candidates.begin(), candidates.end(), isShorter);
+  unsigned minimum_length = candidates.begin()->length;
+  clearSuffixCheck();
+  
+  // Try to add each candidate to the results set, ignoring the non-minimal
+  for (vector<Phrase>::iterator candidate = candidates.begin(); 
+       candidate != candidates.end(); ++candidate) {
+
+    // Make a copy of candidate to mutilate while performing sub-phrase checks
+    Phrase temp_phrase(*candidate);
+    bool shorter_found = false;
+    
+    // Check for shorter and shorter versions of the temporary phrase
+    while (temp_phrase.length >= minimum_length && !shorter_found) {
+      temp_phrase.ensureSuffixFound();
+      if (getSuffixCheck(temp_phrase.firstSuffixIndex)==0)
+	temp_phrase.shortenByOneAtPrefix();
+      else
+	shorter_found = true;
+
+      // Possible efficiency here: we can finish if the prefix of c
+      // and temp_phrase are the same for candidate->length symbols.
+    }
+      
+    // If no shorter phrase is found, use this one
+    if (!shorter_found) {
+      results.push_back(*candidate);
+      candidate->ensureSuffixFound();
+      setSuffixCheck(candidate->firstSuffixIndex, candidate->lastSuffixIndex);
+    }
+  }
+}
+
+
+// suffixCompare
+//
+// Compare two pointers into a suffix array.  We use this in the 
+// qsort function, so the input are pointers to pointers.  
+//
+// Return -1 if (a < b), otherwise (a > b) so return +1, 
+
+int suffixCompare(const void *cpa, const void *cpb) {
+
+  // Cast then dereference pointers to suffix array elements
+  symbol *pa = (symbol *) cpa;
+  symbol *pb = (symbol *) cpb;
+  pa = (symbol *) *pa;
+  pb = (symbol *) *pb;
+
+  // If the two elements are the same, examine the next one
+  while (*pa == *pb) {
+    *pa++;
+    *pb++;
+  }
+
+  // Make the copmparison and return
+  if ( *pa < *pb) {
+    return -1;
+  } else {
+    return +1;
+  }
+}
+
+
+// prefixCompare
+//
+// Compare two pointers into a prefix array.  We use this in the 
+// qsort function, so the input are pointers to pointers.  
+//
+// Return -1 if (a > b), otherwise (a < b) so return +1, 
+
+int prefixCompare(const void *cpa, const void *cpb) {
+
+  // Cast then dereference pointers to prefix array elements
+  symbol *pa = (symbol *) cpa;
+  symbol *pb = (symbol *) cpb;
+  pa = (symbol *) *pa;
+  pb = (symbol *) *pb;
+
+  // If the two elements are the same, examine the next one
+  while (*pa == *pb) {
+    *pa--;
+    *pb--;
+  }
+
+  // Make the copmparison and return
+  if ( *pa > *pb) {
+    return -1;
+  } else {
+    return +1;
+  }
+}
+
+// simpleCompare
+//
+// Compare two pointers based on the memory location they point to.
+
+int pointerCompare( const void *pa, const void *pb ) {
+
+  symbol **a = (symbol **) pa;
+  symbol **b = (symbol **) pb;
+
+  if (*a < *b) {
+    return  -1;
+  } else if (*a > *b) {
+    return 1;
+  } else {
+    return 0;
+  }
+}
+
+
+// Read the clauses.numbers file into the "symbols" array.
+//
+// Each number in the file is a symbol number; it is essential that 
+// the first symbol (and no others) be COLLECTIONSTART and the last
+// symbol (and no others) be COLLECTIONEND.
+//
+// Return the number of numbers in the array.
+
+int readNumbers() {
+
+  char filename[FILENAME_MAX];
+  sprintf(filename, "%s/clauses.numbers", collection);
+  if (verbosity) {
+    cout << "Reading numbers file: " << filename << endl;
+  }
+
+  // Open the numbers file
+  ifstream inFile1(filename, ios::in);
+  if (!inFile1) {
+    cerr << "File " << filename << " could not be opened\n";
+    exit(1);
+  }
+
+  // Count the number of symbols
+  inputLength = 0;
+  symbol word;
+  while (inFile1 >> word) {
+    ++inputLength;
+  }
+  inFile1.close();
+
+  // Allocate the symbbols array
+  if (verbosity > 1) {
+    cout << "Allocating symbol arrays for " << inputLength << " symbols" << endl;
+  }
+  symbols = new symbol[inputLength];
+  if (symbols == NULL) {
+    cerr << "Suffix error: not enough memory to hold " << inputLength
+	 << " symbols." << endl;
+    exit(2);
+  }
+
+  // Read the numbers file into the numbers array
+  if (verbosity > 2) {
+    cout << "Reading the numbers" << endl;
+  }
+
+  ifstream inFile2(filename, ios::in);
+  if (!inFile2) {
+    cerr << "File " << filename << " could not be opened\n";
+    exit(1);
+  }
+  cellcount next = 0;
+  numberOfDocuments = 0;
+  while (inFile2 >> word) {
+    symbols[next++] = word;
+    if (word == DOCUMENTSTART) {
+      ++numberOfDocuments;
+    }
+  }
+  inFile2.close();
+  
+  // Make sure the numbers file is intact
+  assert(symbols[0] == COLLECTIONSTART);
+  assert(symbols[next-1] == COLLECTIONEND);
+
+  return inputLength;
+}
+
+
+
+// Get Document Occurrance statistics
+//
+// Given a phrase, what documents does it occur in?
+
+cellcount getDocumentOccurrances(const Phrase &p, cellcount *frequency) {
+
+  // cout << "searching for \""<< p << "\" in documents " 
+  //      << 0 << "-" << numberOfDocuments - 1 << endl;
+
+  // The number of documents in which this phrase occurs
+  cellcount df = 0;
+
+  // Initialise the document frequency array
+  //  for (cellindex i = 0; i < numberOfDocuments; ++i) {
+  // frequency[i] = 0;
+  //}
+  memset(frequency, 0, sizeof(cellcount)*numberOfDocuments);
+
+  // variables used to facilitate the search
+  cellindex begin;
+  cellindex end;
+  cellindex d;
+  symbol *target;
+  bool found;
+
+  // search for the document in which each occurence of the phrase is found
+  for (cellcount j = p.firstSuffixIndex; j <= p.lastSuffixIndex; ++j) {
+    
+    // cout << "looking for phrase at suffixArray[" << j << "]\n";
+    
+    target = suffixArray[j];
+    begin = 0;
+    end = numberOfDocuments - 1;
+    found = false;
+
+    // Search for the occurence of a document delimiter that target
+    // occurs immediately after.  
+    // We do this by performing a binary chop search on documentArray.
+    while (!found) {
+
+      // cout << "searching for " << (cellindex) target << " in "
+      //      << begin << " - " << end << endl;
+
+      assert (begin <= end);
+
+      // If the beginning and end of the interval are the same,
+      // then we've found the correct document
+      if (begin == end) {
+	if (frequency[begin] == 0) {
+	  ++df;
+	}
+	++frequency[begin];
+	found = true;
+      }
+
+      // Otherwise, examine a new document midway through the begin-end
+      // interval and see if it is the one.
+      else {
+	d = (begin + end) / 2;
+	if (target > documentArray[d]) {
+	  // If target addrss is greater than this, but thisi sthe last document,
+	  // then this must be the one we want.  Or, if target is greater than
+	  // this one but less then the next, this must be the one we wnat.
+	  if ((d == numberOfDocuments - 1) || (target < documentArray[d+1])) {
+	    if (frequency[d] == 0) {
+	      ++df;
+	    }
+	    ++frequency[d];
+	    found = true;
+	  } else {	
+	    // otherwise we know to search later in the document set
+	    begin = d + 1;
+	  }
+	} else {
+	  // search earlier in the document set
+	  end = d - 1;
+	}
+      }
+    }
+  }
+  return df;
+}
+
+
+
+
+
+
+// phraseExpansionMemory : Which phrases have we expanded?
+//
+// A set of utilities for keeping track of which phrases we have expanded.
+// We don't want to expand a phrase more than once, after all.
+//
+// This REALLY ought to be in its own class, but it works so that's okay.
+//
+// Phrases are identified by their firstSuffixPosition and length.
+//
+// Functions provided are:
+//       void initialisePhraseMemory()
+//       void rememberThisPhrase(index, length)
+//       bool isPhraseStored(index, length)
+//       void deletePhraseMemory()
+//
+// Internally, we will have two separate cases:
+//
+// Phrases of length 1-8: 
+//       unsigned char phraseMemory[inputLength]
+// is an array where each cell "remembers" the corresponding index in the 
+// suffixArray, and each of the 8 bits of the cell correspond to the phrases 
+// of length 1, 2... 8.  
+// Eventually, we will make this disk-based (i.e. store the array in a file).
+//
+// Phrases of length 9+:
+//       file hashTableFile
+//       file listOfEntries
+// The first file is a hash table; each phrase maps to one of its cells, which
+// contains either 0 (empty, no occurence) or a number which is an entry number 
+// in the second file.  This file contains a "list" of entries.  Each consists of 
+// three numbers: the suffixArray index of the phrase, the length of the phrase,
+// and the entry number of the next phrase with the same hash.
+//
+
+
+unsigned char *phraseMemory;
+
+void initialiseLongPhraseMemory();
+void rememberThisLongPhrase(cellindex index, cellcount length);
+bool isLongPhraseStored(cellindex index, cellcount length);
+void deleteLongPhraseMemory();
+
+
+void initialisePhraseMemory() {
+
+  phraseMemory = new unsigned char[inputLength];
+
+  // to begin with, everything is empty
+  //  for (cellcount i = 0; i < inputLength; ++i) {
+  // phraseMemory[i] = 0;
+  //}
+  memset(phraseMemory, 0, sizeof(char)*inputLength);
+  
+  // intialise the hashTable of long phrases
+  initialiseLongPhraseMemory();
+
+}
+
+void rememberThisPhrase(cellindex index, cellcount length) {
+
+  // if the phrase is very long, use the file-based system
+  if (length > 8) {
+    rememberThisLongPhrase(index, length);
+    return;
+  }
+
+  // create a char with just the bit corresponding to length set
+  unsigned char newbit = 1;
+  for (cellcount i = 1; i < length; ++i) {
+    newbit <<= 1;
+  }
+
+  // set that bit in the memory array at position index
+  phraseMemory[index] |= newbit;
+}
+
+
+bool isPhraseStored(cellindex index, cellcount length) {
+
+  // if the phrase is very long, use the file-based system
+  if (length > 8) {
+    return isLongPhraseStored(index, length);
+  }
+
+  // create a char with just the bit corresponding to length set
+  unsigned char newbit = 1;
+  for (cellcount i = 1; i < length; ++i) {
+    newbit <<= 1;
+  }
+
+  // retrurn true if that bit is set in memory arrayat position index
+  return (phraseMemory[index] & newbit);
+}
+
+void deletePhraseMemory() {
+  delete []phraseMemory;
+  deleteLongPhraseMemory();
+}
+
+
+
+// Files etc used to store "long" equavlents of the above
+
+fstream hashTableFile;
+char    hashTableFileName[FILENAME_MAX];
+fstream listOfEntries;
+char    listOfEntriesName[FILENAME_MAX];
+cellindex nextEntryNumber;
+
+const cellcount bigPrime = 7919;
+
+
+void initialiseLongPhraseMemory() {
+
+  cellindex example = 0;
+
+  sprintf(hashTableFileName, "%s/hashTable", collection);
+  sprintf(listOfEntriesName, "%s/hashLists", collection);
+
+
+  // create the new hashtable
+  if (verbosity > 1) {
+    cout << "Initialising hashTable: " << hashTableFileName << endl;
+  }
+  hashTableFile.open(hashTableFileName, ios::in | ios::out);
+  for (cellcount i = 0; i < bigPrime; ++i) {
+    hashTableFile.write((char *) &example, sizeof(example));
+  }
+
+  // create the list of phrases
+  if (verbosity > 1) {
+    cout << "Initialising list of hashtable entries: " << listOfEntriesName << endl;
+  }
+  listOfEntries.open(listOfEntriesName, ios::in | ios::out);
+  listOfEntries.write((char *) &example, sizeof(example));
+  listOfEntries.write((char *) &example, sizeof(example));
+  listOfEntries.write((char *) &example, sizeof(example));
+  nextEntryNumber = 1;
+}
+
+
+void rememberThisLongPhrase(cellindex index, cellcount length) {
+
+  // cout << "rememberThisLongPhrase(" << index << ", " << length << ")\n";
+
+  cellindex hashOffset = ((index + length) % bigPrime) * sizeof(cellindex);
+  cellindex pointer;
+  cellindex zero = 0;
+  cellindex readp = 0;
+  cellindex readi = 0;
+  cellindex readl = 0;
+
+  hashTableFile.seekg(hashOffset);
+  hashTableFile.read((char *) &pointer, sizeof(cellindex));
+
+  if (pointer == 0) {
+    // There is no entry at all in the hash table for this entry
+    // so create one
+
+    pointer = nextEntryNumber++;
+    hashTableFile.seekg(hashOffset);
+    hashTableFile.write((char *) &pointer, sizeof(cellindex));
+        
+    listOfEntries.seekp(pointer * sizeof(cellindex) * 3);
+    listOfEntries.write((char *) &zero, sizeof(cellindex));
+    listOfEntries.write((char *) &index, sizeof(cellindex));
+    listOfEntries.write((char *) &length, sizeof(cellindex));
+
+  } else {
+    // There is a list starting at this hash value, so the phrase may
+    // be already remembered, or it might need to be appended
+    
+    while (pointer != 0) {
+      // Read the entry pointed to by pointer
+      listOfEntries.seekg(pointer * sizeof(cellindex) * 3);
+      listOfEntries.read((char *) &readp, sizeof(cellindex));
+      listOfEntries.read((char *) &readi, sizeof(cellindex));
+      listOfEntries.read((char *) &readl, sizeof(cellindex));
+
+      // cout << "read " << pointer << ", " << readp << ", " << readi << ", " << readl << endl;
+
+      if ((readi == index) && (readl = length)) {
+	// we've found that we've already stored it
+	return;
+      } else if (readp == 0) {
+	// we're reached the end of the list.  Add a new entry.
+	listOfEntries.seekp(pointer * sizeof(cellindex) * 3);
+	listOfEntries.write((char *) &nextEntryNumber, sizeof(cellindex));
+	pointer = nextEntryNumber++;
+
+	listOfEntries.seekp(pointer * sizeof(cellindex) * 3);
+	listOfEntries.write((char *) &zero, sizeof(cellindex));
+	listOfEntries.write((char *) &index, sizeof(cellindex));
+	listOfEntries.write((char *) &length, sizeof(cellindex));
+	return;
+      } else {
+	// go on to the next node
+	pointer = readp;
+      }
+    }
+  }
+
+
+}
+
+
+bool isLongPhraseStored(cellindex index, cellcount length) {
+
+  // cout << "isLongPhraseExpanded(" << index << ", " << length << ")\n";
+
+  cellindex hashOffset = ((index + length) % bigPrime) * sizeof(cellindex);
+  cellindex pointer;
+  cellindex readp = 0;
+  cellindex readi = 0;
+  cellindex readl = 0;
+
+  // Find the phrase in the hashFile
+  hashTableFile.seekg(hashOffset);
+  hashTableFile.read((char *) &pointer, sizeof(cellindex));
+
+  if (pointer == 0) {
+    // There is no entry at all in the hash table for this entry
+    // so nothing is stored
+    return false;
+
+  } else {
+    // There is a list starting at this hash value, so the phrase may
+    // be already remembered in that list
+    while (pointer != 0) {
+      // Read the entry pointed to by pointer
+      listOfEntries.seekg(pointer * sizeof(cellindex) * 3);
+      listOfEntries.read((char *) &readp, sizeof(cellindex));
+      listOfEntries.read((char *) &readi, sizeof(cellindex));
+      listOfEntries.read((char *) &readl, sizeof(cellindex));
+
+      if ((readi == index) && (readl = length)) {
+	// we've found the phrase stored here
+	return true;
+      } else {
+	// go on to the next node
+	pointer = readp;
+      }
+    }
+  }
+  return false;
+}
+
+
+void deleteLongPhraseMemory() {
+  // remove the hash & other files
+
+  hashTableFile.close();
+  listOfEntries.close();
+  remove(hashTableFileName);
+  remove(listOfEntriesName);
+
+}
+
+
+// Read the collection statistics file
+//
+void readStatistics() {
+
+  // open the statistics file
+  char filename[FILENAME_MAX];
+  sprintf(filename, "%s/clauses.stats", collection);
+
+  // Open the file
+  ifstream inFile(filename, ios::in);
+  if (!inFile) {
+    cerr << "File " << filename << " could not be opened\n";
+    exit(1);
+  }
+
+  // Read the numbers file into the numbers array
+  char key[1000];
+  symbol value;
+  while (inFile >> key >> value){
+    if (strcmp(key, "first_stopword") == 0) {
+      firstStopSymbol = value;
+    } else if (strcmp(key, "last_stopword") == 0) {
+      lastStopSymbol = value;
+    } else if (strcmp(key, "first_contentword") == 0) {
+      firstContentSymbol = value;
+    } else if (strcmp(key, "last_contentword") == 0) {
+      lastContentSymbol = value;
+    }
+  }
+  inFile.close();
+
+  // Make sure we have the information we need
+  if (!(firstStopSymbol && lastStopSymbol && firstContentSymbol && lastContentSymbol)) {
+    cerr << "Statistics file incomplete" << endl;
+    exit(1);
+  }
+}
+
+cellcount getContentCount(symbol firstContent) {
+
+  cellcount content=0;
+  for (cellcount i=0; i<inputLength; ++i) {
+    if (symbols[i]>=firstContent) ++content;
+  }
+
+  return content;
+}
+
+
+int main (int argc, char * argv[]) {
+
+  // Command-line arguments
+  // argv[1] is the phindex directory
+  // argv[2] is the mode, where 1 is stopword mode 
+  // argv[3] is the min_occurs, - minimum occurrence frequency for a phrase to be included in the hierarchy
+  // argv[4] is opitonal verbosity
+  if (argc < 4) {
+    cerr << "Usage: " << argv[0] << " phind-directory mode min-phrase-freq [verbosity]" << endl;
+    exit(1);
+  }
+
+  // collection directory
+  strcpy(collection, argv[1]);
+
+  // mode parameter
+  phraseMode = atoi(argv[2]);
+  assert((phraseMode == STOPWORDS) || (phraseMode == ANYPHRASE));
+
+  minOccurs = atoi(argv[3]);
+  assert((minOccurs > 0));
+
+  // optional verbosity parameter
+  if (argc == 5) {
+    verbosity = atoi(argv[4]);
+    assert (verbosity >= 0);
+  }
+
+  if (verbosity) {
+    cout << "suffix: the phrase extraction program" << endl;
+  }
+  if (verbosity > 1) {
+    if (phraseMode == STOPWORDS) {
+      cout << "Stopwords mode: no phrase may begin or end with a stopword" << endl;
+    } else {
+      cout << "AllPhrase mode: extract every phrase that occurs more than once" << endl;
+    }
+  }
+
+  // Read the statistics file 
+  readStatistics();
+  // Read the numbers file
+  readNumbers();
+  
+  if (numberOfDocuments == 0) {
+    cerr << "There are no documents in this collection!" << endl;
+    exit(0); // not necessarily an error...
+  }
+
+  symbol firstContent;
+  if (phraseMode==STOPWORDS) firstContent=firstContentSymbol;
+  else firstContent = firstStopSymbol;
+
+  // Allocate memory for the suffix & prefix arrays
+  cellcount contentLength = 0;
+  contentLength = getContentCount(firstContent);
+  suffixArray = new symbol *[contentLength];
+  prefixArray = new symbol *[contentLength];
+  if (prefixArray == NULL) {
+    cerr << "Suffix: not enough memory to hold " << inputLength << " symbols." << endl;
+    exit(2);
+  }
+  allocateSuffixCheck(contentLength);
+  // Initialise prefix and suffix arrays, only use the needed suffixes
+  for (cellcount j = 0, here = 0; j < inputLength; ++j) {
+    if (symbols[j]>=firstContent) {
+      suffixArray[here] = &symbols[j];
+      prefixArray[here] = &symbols[j];
+      ++here;
+    }    
+  }
+  qsort(suffixArray, contentLength, sizeof(symbol *), suffixCompare);
+  qsort(prefixArray, contentLength, sizeof(symbol *), prefixCompare);
+  // Create the document arrays
+  if (verbosity > 1) {
+    cout << "Allocating document arrays for " << numberOfDocuments << " documents" << endl;
+  }
+
+  // The document frequecy array is used to count the number of times
+  // each phrase occurs in each document.  The number of documents in
+  // which a phrase occurs is stored in df.
+  frequency *documentFrequency = new frequency[numberOfDocuments];
+  frequency df;
+
+  // documentArray will be searched in order to discover which document
+  // each phrase occurs in.
+  documentArray = new symbol *[numberOfDocuments];  
+  if (documentArray == NULL) {
+    cerr << "Suffix: out of memory allocating document arrays." << endl;
+    exit(2);
+  }  
+
+  // just scan through the input text to find the doc starts
+  cellindex d = 0;
+  for (cellindex i=0; i<inputLength; ++i) {
+    if (symbols[i] == DOCUMENTSTART) {
+      documentArray[d] = &symbols[i];
+      ++d;
+    }
+  }
+
+  // the phrases stuff is expecting inputLength to be the length of the
+  // suffix array, so change it.
+  inputLength = contentLength;
+
+  // Extract phrases
+  //
+  // We will make several passesover the data, in each case considering
+  // a set of input phrases and generating a set of output phrases, which
+  // we will expancd in later passes.
+  //
+  // The input phrases in the first pass will be the vocabulary.
+  // In later passes, the input phrases will be the output phrases of the
+  // previous pass.
+  //
+  // In each pass we will consider each input phrase in turn.  If we
+  // have seen it before, we will ignore it.  Otherwise, we will expand
+  // it and add its expansions to the set of output phrases.
+
+  cout <<"\ngenerating the phrase hierarchy\n\n";
+  
+  // Store the phrase data in the phrases file
+  char phraseDataName[FILENAME_MAX];
+  sprintf(phraseDataName, "%s/phrases", collection);
+  ofstream phraseData(phraseDataName, ios::out);
+  if (!phraseData) {
+    cout << "File " << phraseDataName << " could not be opened\n";
+    exit(1);
+  }
+
+  // Count the number of phrases output
+  unsigned long int phraseCounter = 0;
+
+  // Set up the phrase expansion memory.
+  // We need this so that we don't expand a phrase more than once
+  initialisePhraseMemory();
+
+  // The current pass numebr
+  int phrasePass = 1;
+
+
+  // PASS NUMBER 1
+  if (verbosity > 1) {
+    cout << "Starting pass " << phrasePass << endl;
+  }
+
+  ofstream outPhrase;
+  char     outPhraseName[FILENAME_MAX];
+  unsigned long int outPhraseCounter = 0;
+
+  // On the first pass, simply work through the vocabulary
+  sprintf(outPhraseName, "%s/outPhrase.1", collection);
+  outPhrase.open(outPhraseName, ios::out);
+  if (!outPhrase) {
+    cerr << "File " << outPhraseName << " could not be opened\n";
+    exit(1);
+  }
+
+  // Iterate over the different symbols by working through the suffix array
+  vector<Phrase> result;
+  cellindex ij = 0;
+  char *tmpString;
+
+  Phrase p;
+  while (ij < inputLength) {
+
+    // make a new phrase of length 1
+    p = Phrase(suffixArray[ij], 1, SUFFIX);
+    p.findFirstAndLastSuffix(ij, inputLength-1);
+
+    // We ignore this symbol if it occurs only once, if it is a delimiter,
+    // of if we are in stopwords mode and it is a stopword
+    // - in this new version, only need to check freq
+    // We could imagine a new mode/command-line option, which is like 
+    // STOPWORDS but without this restrictrion.  This would let you browse
+    // from "the" to "the AGRIS" for example, but not from "AGRIS" to
+    // "the AGRIS" (where the is a stopword and AGRIS a content word).
+    // The system used to work like this; it is easy to implement, but
+    // it explodes the size of the indexes.  So: would it be useful?  
+    if (p.suffixFrequency >= minOccurs) {
+      // Get minimal expansions of the phrase
+      getExpansions(p, result);
+      
+      if (!result.empty()) {
+	
+	// Remember that we have expanded this phrase
+	rememberThisPhrase(ij, 1);
+
+	// write the phrase text
+	phraseData << ij << "-1:" << p << ":" << p.suffixFrequency << ":"
+		   << result.size() << ":";
+
+	// write the results
+	for (cellcount k = 0; k < result.size(); ++k) {
+	  if (k) {
+	    phraseData << ",";
+	  }
+	  phraseData << result[k].firstSuffixIndex << "-" << result[k].length;
+	  outPhrase << result[k].firstSuffixIndex << " " << result[k].length << endl;
+	  ++outPhraseCounter;
+	}
+	result.clear();
+	
+	// Write the documents in which this phrase occurs
+	df = getDocumentOccurrances(p, documentFrequency);
+	phraseData << ":" << df << ":";
+
+	// write the documents
+	for (cellcount m = 0, first = 1; m < numberOfDocuments; ++m) {
+	  if (documentFrequency[m]) {
+	    if (first) {
+	      first = 0;
+	    } else {
+	      phraseData << ";";
+	    }
+	    // Output the document number.  Note that here we've numbered the 
+	    // N documents from 0 to N-1, but later they'll be 1-N.  Thus we
+	    // add 1 to the document id when we output it.
+	    phraseData << "d" << (m+1);
+	    // Next, output the frequency with which the document occurs, but
+	    // only if it is > 1.
+	    if (documentFrequency[m] > 1) {
+	      phraseData << "," << documentFrequency[m];
+	    }
+	  }
+	}
+
+	phraseData << endl;
+	++phraseCounter;
+
+	// feedback 
+	if (verbosity) {
+	  if (phraseCounter % 1000 == 0) {
+	    cout << "phrase " << phraseCounter << ": "
+		 << "cell " << p.firstSuffixIndex << " - " << p << endl;
+	  }
+	}
+      }
+    }
+   ij = p.lastSuffixIndex + 1;
+  }
+  outPhrase.close();
+
+  // REMAINING PASSES
+  // The previous outPhrase file forms the input to each new pass
+  cellcount start, length;
+  while (outPhraseCounter > 0) {
+
+    // Start a new pass
+    ++phrasePass;
+    if (verbosity) {
+      cout << "Starting pass " << phrasePass << endl;
+    }
+
+    // Open the input file
+    char inPhraseName[FILENAME_MAX];
+    sprintf(inPhraseName, "%s/outPhrase.%d", collection, phrasePass - 1);
+    ifstream inPhrase (inPhraseName, ios::in);
+    if (!inPhrase) {
+      cerr << "File " << inPhraseName << " could not be opened\n";
+      exit(1);
+    }
+
+    // Open the output file
+    sprintf(outPhraseName, "%s/outPhrase.%d", collection, phrasePass);
+    outPhrase.open(outPhraseName, ios::out);
+    if (!outPhrase) {
+      cerr << "File " << outPhraseName << " could not be opened\n";
+      exit(1);
+    }
+    outPhraseCounter = 0;
+
+    // Process each phrase
+    while(inPhrase >> start >> length) {
+
+      // Ignore the phrase if we have expanded it before
+      if (isPhraseStored(start, length))
+	continue;
+
+      // Remember that we have examined this phrase
+      rememberThisPhrase(start, length);
+
+      // Find the phrase in the suffixarray
+      p = Phrase(suffixArray[start], length, SUFFIX);
+      p.findFirstAndLastSuffix(start, inputLength-1);
+
+      // Ignore the phrase if it only occurs once
+      if (p.suffixFrequency < minOccurs)
+	continue;
+
+      // Write the phrase text;
+      phraseData << start << "-" << length << ":" << p << ":" << p.suffixFrequency << ":";
+	
+      // Expand the phrase, if it is fewer than 8 words long
+      if (length <= 8) {
+
+	// Get the minimal expansions for this phrase
+	getExpansions(p, result);
+      
+	// write the results
+	phraseData << result.size() << ":";
+
+	for (cellcount i = 0; i < result.size(); ++i) {
+	  if (i) {
+	    phraseData << ",";
+	  }
+	  phraseData << result[i].firstSuffixIndex << "-" << result[i].length;
+	  outPhrase << result[i].firstSuffixIndex << " " << result[i].length << endl;
+	  ++outPhraseCounter;
+	}
+	result.clear();
+	
+      } else {
+	// phrase is too long to expand further
+	phraseData << "0:";
+      }
+
+      // Write the documents in which this phrase occurs
+      df = getDocumentOccurrances(p, documentFrequency);
+      phraseData << ":" << df << ":";
+
+      // write the documents
+      for (cellcount i = 0, first = 1; i < numberOfDocuments; ++i) {
+	if (documentFrequency[i]) {
+	  if (first) {
+	    first = 0;
+	  } else {
+	    phraseData << ";";
+	  }
+	  // Output the document number.  Note that here we've numbered the 
+	  // N documents from 0 to N-1, but later they'll be 1-N.  Thus we
+	  // add 1 to the document id when we output it.
+	  phraseData << "d" << (i+1);
+	  // Next, output the frequency with which the document occurs, but
+	  // only if it is > 1.
+	  if (documentFrequency[i] > 1) {
+	    phraseData << "," << documentFrequency[i];
+	  }
+	}
+      }
+      
+      phraseData << endl;
+      ++phraseCounter;
+
+      // feedback 
+      if (verbosity) {
+	if (phraseCounter % 1000 == 0) {
+	  cout << "phrase " << phraseCounter << ": "<< "start " << start 
+	       << ", length " << length << " - " << p << endl;
+	}
+      }
+
+    }
+
+    inPhrase.close();
+    outPhrase.close();
+  }
+    
+  phraseData.close();
+  deletePhraseMemory();
+
+  delete [] documentFrequency;
+  delete [] symbols;
+  delete [] suffixArray;
+  delete [] prefixArray;
+  delete [] suffixCheck;
+  delete [] documentArray;
+
+
+  
+  cout << endl << "Done: " << phraseCounter << " phrases in " << phraseDataName << endl;
+  return 0;
+}
+
+
+
+
+
Index: /gsdl/trunk/build-src/src/phind/generate/suffix.h
===================================================================
--- /gsdl/trunk/build-src/src/phind/generate/suffix.h	(revision 16571)
+++ /gsdl/trunk/build-src/src/phind/generate/suffix.h	(revision 16571)
@@ -0,0 +1,89 @@
+/**********************************************************************
+ *
+ * suffix.h -- definitions used in suffix.cpp
+ *
+ * Copyright 2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef SUFFIX_H
+#define SUFFIX_H
+
+// Types
+
+// The input words stored as an array of type symbol.
+// Required range: 0 - vocabulary size (typically hundreds of thousands)
+typedef unsigned int symbol;
+
+// The cellindex and cellcount types are used when we store indexes
+// to and ranges of cells in large arrays.
+// Required Range: 0 - length of input (typically millions)
+typedef unsigned int cellindex;
+typedef unsigned int cellcount;
+
+// The frequency type is used when we want to store the frequency with 
+// which a phrase (or some other thing) occurs
+// Required range: 0 - frequency of most common symbol (often "the")
+typedef unsigned int frequency;
+
+// Global variables 
+
+// The symbol array holds the input words
+extern cellcount symbol_array_length;
+extern symbol   *symbols;
+
+// The number of words read is storesd in inputLength.
+extern cellcount inputLength;
+
+// Suffix and prefix arrays are used to extract phrases
+extern symbol  **suffixArray;
+extern symbol  **prefixArray;
+
+// Collection-specific information about the first stopword/content symbols
+extern symbol firstStopSymbol;
+extern symbol lastStopSymbol;
+extern symbol firstContentSymbol;
+extern symbol lastContentSymbol;
+
+
+// Are we allowed to terminate a phrase on a stopword?
+extern int phraseMode;
+extern int minOccurs;
+
+#define ANYPHRASE 0
+#define STOPWORDS 1
+
+
+// Direction values
+#define SUFFIX 0
+#define PREFIX 1
+
+
+// Special symbol values
+#define COLLECTIONSTART 1
+#define COLLECTIONEND 2
+#define DOCUMENTSTART 3
+#define PHRASELIMIT 4
+
+#define LASTDELIMITER 4
+
+#endif
Index: /gsdl/trunk/build-src/src/phind/generate/symbol-names.pl
===================================================================
--- /gsdl/trunk/build-src/src/phind/generate/symbol-names.pl	(revision 16571)
+++ /gsdl/trunk/build-src/src/phind/generate/symbol-names.pl	(revision 16571)
@@ -0,0 +1,57 @@
+#! /usr/bin/perl -w
+
+###########################################################################
+#
+# symbol-names.pl -- Diagnostic tool that substitutes symbols names for 
+#                    symbol numbers in the output of the suffix program. 
+#
+# Copyright (C) 2000 Gordon Paynter
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+$collection = shift(@ARGV);;
+die "Usage: symbol-names.pl collection [file]\n" unless ($collection);
+
+$vocab = $ENV{'GSDLHOME'} . "/collect/$collection/index/phind1/clauses.vocab";
+if (-e "$vocab") {
+    print "Using vocabulary from: $vocab\n";
+} else {
+    $vocab = $ENV{'GSDLHOME'} . "/collect/$collection/building/phind1/clauses.vocab";
+    if (-e "$vocab") {
+	print "Using vocabulary from: $vocab\n";
+    } else {
+	die "Usage: symbol-names.pl collection [file]\n" unless (-e "$vocab");
+    }
+}
+
+open(V, "<$vocab");
+my $n = 1;
+
+while(<V>) {
+    chomp;
+    $symbol[$n++] = $_;
+}
+
+while(<>) {
+    s/s(\d+)/$symbol[$1]/g;
+    print;
+}
+
Index: /gsdl/trunk/build-src/src/phind/generate/win32.mak
===================================================================
--- /gsdl/trunk/build-src/src/phind/generate/win32.mak	(revision 16571)
+++ /gsdl/trunk/build-src/src/phind/generate/win32.mak	(revision 16571)
@@ -0,0 +1,76 @@
+###########################################################################
+#
+# win32 makefile -- src/phind/generate
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 2001  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDLHOME = ..\..\..
+GSDL_VC4 = 0
+STLPATH = "$(GSDLHOME)\packages\windows\stlport\stlport"
+
+AR = lib
+CC = cl
+
+!IF $(GSDL_VC4)
+CPPFLAGS = -GX
+!ELSE
+CPPFLAGS = -EHsc
+!ENDIF
+
+LDFLAGS =
+DEFS = -D__WIN32__
+INCLUDES =
+!IF $(GSDL_VC4)
+DEFS = $(DEFS) -DGSDL_NAMESPACE_BROKEN -DGSDL_USE_IOS_H -D__STL_NO_NEW_IOSTREAMS -D_CRT_SECURE_NO_DEPRECATE
+INCLUDES = $(INCLUDES) -I$(STLPATH)
+!ENDIF
+LIBS=
+
+COMPILE = $(CC) -nologo -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+LINK = $(CC) -nologo $(LDFLAGS)
+
+.SUFFIXES:
+.SUFFIXES: .c .obj
+.c.obj:
+	$(COMPILE) $<
+
+.SUFFIXES: .cpp .obj
+.cpp.obj:
+	$(COMPILE) $< 
+
+HEADERS = suffix.h phrase.h
+SOURCES = suffix.cpp phrase.cpp
+OBJECTS = suffix.obj phrase.obj
+EXEC    = suffix.exe
+
+all: $(EXEC)
+
+install:
+	copy $(EXEC) "$(GSDLHOME)\bin\windows"
+
+clean:
+	del *.obj
+	del $(EXEC)
+
+suffix.exe: $(OBJECTS)
+	    $(LINK) $(OBJECTS) $(LIBS) 
Index: /gsdl/trunk/runtime-src/Makefile.in
===================================================================
--- /gsdl/trunk/runtime-src/Makefile.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/Makefile.in	(revision 16571)
@@ -0,0 +1,105 @@
+###########################################################################
+#
+# Makefile -- gsdl runtime code
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+srcdir = @srcdir@
+
+PACKAGE = @PACKAGE@
+VERSION = @VERSION@
+
+@SET_MAKE@
+CC = @CC@
+CXX = @CXX@
+CFLAGS = @CFLAGS@
+CXXFLAGS = @CXXFLAGS@
+LIBS   = @LIBS@
+MDEFINES =
+
+GSDLOS = @gsdlos@
+
+COMPILE = $(CC) -c
+
+SOURCES = 
+
+OBJECTS = 
+
+ALLFILES = $(OBJECTS)
+
+
+# all directories should be compiled
+COMPILEDIRS = packages src/colservr src/protocol src/z3950 src/recpt src/corba src/oaiservr
+
+# a subset of the directories get installed
+INSTALLDIRS = packages src/z3950 src/recpt src/corba src/oaiservr
+
+MODULEDIRS = @MODULEDIRS@
+
+
+all:
+	for odir in $(COMPILEDIRS) $(MODULEDIRS); do \
+	  echo making $@ in $$odir; \
+	  (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
+	done
+
+install: all
+	for idir in $(INSTALLDIRS); do \
+	  echo installing $$idir; \
+	  (cd $$idir && $(MAKE) install) || exit 1; \
+	done
+
+distclean: clean
+	rm -f Makefile config.cache config.h config.log stamp-h config.status
+	for subdir in $(COMPILEDIRS); do \
+	  echo cleaning $@ in $$subdir; \
+	  (cd $$subdir && $(MAKE) distclean) || exit 1; \
+	done
+
+clean:
+	for subdir in $(COMPILEDIRS); do \
+	  echo cleaning $@ in $$subdir; \
+	  (cd $$subdir && $(MAKE) clean) || exit 1; \
+	done
+
+# commented out - jrm21 Dec 2004 - can get confused by cvs timestamps
+# (and might run the wrong version of autoconf)
+#
+## For an explanation of the following Makefile rules, see node
+## `Automatic Remaking' in GNU Autoconf documentation.
+#Makefile: Makefile.in config.status
+#	CONFIG_FILES=$@ CONFIG_HEADERS= ./config.status
+#config.status: configure
+#	./config.status --recheck
+#configure: configure.in aclocal.m4
+#	cd $(srcdir) && autoconf
+#
+#config.h: stamp-h
+#stamp-h: config.h.in config.status
+#	CONFIG_FILES= CONFIG_HEADERS=config.h ./config.status
+#config.h.in: stamp-h.in
+#stamp-h.in: configure.in aclocal.m4 acconfig.h
+#	cd $(srcdir) && autoheader
+#	$(TOUCH) $(srcdir)/stamp-h.in
+
+
+
Index: /gsdl/trunk/runtime-src/aclocal.m4
===================================================================
--- /gsdl/trunk/runtime-src/aclocal.m4	(revision 16571)
+++ /gsdl/trunk/runtime-src/aclocal.m4	(revision 16571)
@@ -0,0 +1,140 @@
+# Local additions to Autoconf macros.
+# Copyright (C) 1992, 1994, 1995 Free Software Foundation, Inc.
+# François Pinard <pinard@iro.umontreal.ca>, 1992.
+
+# [TS:Aug/95] - chopped out the NLS stuff which I don't support
+
+## ------------------------------- ##
+## Check for function prototypes.  ##
+## ------------------------------- ##
+
+AC_DEFUN(fp_C_PROTOTYPES,
+[AC_REQUIRE([fp_PROG_CC_STDC])
+AC_MSG_CHECKING([for function prototypes])
+if test "$ac_cv_prog_cc_stdc" != no; then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(PROTOTYPES)
+  U= ANSI2KNR=
+else
+  AC_MSG_RESULT(no)
+  U=_ ANSI2KNR=ansi2knr
+fi
+AC_SUBST(U)dnl
+AC_SUBST(ANSI2KNR)dnl
+])
+
+## ----------------------------------------- ##
+## ANSIfy the C compiler whenever possible.  ##
+## ----------------------------------------- ##
+
+# @defmac AC_PROG_CC_STDC
+# @maindex PROG_CC_STDC
+# @ovindex CC
+# If the C compiler in not in ANSI C mode by default, try to add an option
+# to output variable @code{CC} to make it so.  This macro tries various
+# options that select ANSI C on some system or another.  It considers the
+# compiler to be in ANSI C mode if it defines @code{__STDC__} to 1 and
+# handles function prototypes correctly.
+#
+# If you use this macro, you should check after calling it whether the C
+# compiler has been set to accept ANSI C; if not, the shell variable
+# @code{ac_cv_prog_cc_stdc} is set to @samp{no}.  If you wrote your source
+# code in ANSI C, you can make an un-ANSIfied copy of it by using the
+# program @code{ansi2knr}, which comes with Ghostscript.
+# @end defmac
+
+AC_DEFUN(fp_PROG_CC_STDC,
+[AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C)
+AC_CACHE_VAL(ac_cv_prog_cc_stdc,
+[ac_cv_prog_cc_stdc=no
+ac_save_CFLAGS="$CFLAGS"
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX			-qlanglvl=ansi
+# Ultrix and OSF/1	-std1
+# HP-UX			-Aa -D_HPUX_SOURCE
+# SVR4			-Xc
+for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" -Xc
+do
+  CFLAGS="$ac_save_CFLAGS $ac_arg"
+  AC_TRY_COMPILE(
+[#if !defined(__STDC__) || __STDC__ != 1
+choke me
+#endif	
+], [int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};],
+[ac_cv_prog_cc_stdc="$ac_arg"; break])
+done
+CFLAGS="$ac_save_CFLAGS"
+])
+AC_MSG_RESULT($ac_cv_prog_cc_stdc)
+case "x$ac_cv_prog_cc_stdc" in
+  x|xno) ;;
+  *) CC="$CC $ac_cv_prog_cc_stdc" ;;
+esac
+])
+
+## --------------------------------------------------------- ##
+## Use AC_PROG_INSTALL, supplementing it with INSTALL_SCRIPT ##
+## substitution.					     ##
+## --------------------------------------------------------- ##
+
+AC_DEFUN(fp_PROG_INSTALL,
+[AC_PROG_INSTALL
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL} -m 755'
+AC_SUBST(INSTALL_SCRIPT)dnl
+])
+
+## ----------------------------------- ##
+## Check if --with-dmalloc was given.  ##
+## ----------------------------------- ##
+
+# I just checked, and GNU rx seems to work fine with a slightly
+# modified GNU m4.  So, I put out the test below in my aclocal.m4,
+# and will try to use it in my things.  The idea is to distribute
+# rx.[hc] and regex.[hc] together, for a while.  The WITH_REGEX symbol
+# (which should also be documented in acconfig.h) is used to decide
+# which of regex.h or rx.h should be included in the application.
+#
+# If `./configure --with-regex' is given, the package will use
+# the older regex.  Else, a check is made to see if rx is already
+# installed, as with newer Linux'es.  If not found, the package will
+# use the rx from the distribution.  If found, the package will use
+# the system's rx which, on Linux at least, will result in a smaller
+# executable file.
+
+AC_DEFUN(fp_WITH_DMALLOC,
+[AC_MSG_CHECKING(if malloc debugging is wanted)
+AC_ARG_WITH(dmalloc,
+[  --with-dmalloc          use dmalloc, as in
+                          ftp://ftp.letters.com/src/dmalloc/dmalloc.tar.gz],
+[if test "$withval" = yes; then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(WITH_DMALLOC)
+  LIBS="$LIBS -ldmalloc"
+  LDFLAGS="$LDFLAGS -g"
+else
+  AC_MSG_RESULT(no)
+fi], [AC_MSG_RESULT(no)])
+])
+
+## --------------------------------- ##
+## Check if --with-regex was given.  ##
+## --------------------------------- ##
+
+AC_DEFUN(fp_WITH_REGEX,
+[AC_MSG_CHECKING(which of rx or regex is wanted)
+AC_ARG_WITH(regex,
+[  --with-regex            use older regex in lieu of GNU rx for matching],
+[if test "$withval" = yes; then
+  ac_with_regex=1
+  AC_MSG_RESULT(regex)
+  AC_DEFINE(WITH_REGEX)
+  AC_LIBOBJ([regex])
+fi])
+if test -z "$ac_with_regex"; then
+  AC_MSG_RESULT(rx)
+  AC_CHECK_FUNC(re_rx_search, , [AC_LIBOBJ([rx])])
+fi
+])
Index: /gsdl/trunk/runtime-src/config.h.in
===================================================================
--- /gsdl/trunk/runtime-src/config.h.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/config.h.in	(revision 16571)
@@ -0,0 +1,217 @@
+/* config.h.in.  Generated automatically from configure.in by autoheader.  */
+
+#ifndef _GSDL_CONFIG_H
+#define _GSDL_CONFIG_H
+
+/* Define if on AIX 3.
+   System headers sometimes define this.
+   We just want to avoid a redefinition error message.  */
+#ifndef _ALL_SOURCE
+#undef _ALL_SOURCE
+#endif
+
+/* Define if using alloca.c.  */
+#undef C_ALLOCA
+
+/* Define if big endian */
+#undef WORDS_BIGENDIAN
+
+/* Define to empty if the keyword does not work.  */
+#undef const
+
+/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems.
+   This function is required for alloca.c support on those systems.  */
+#undef CRAY_STACKSEG_END
+
+/* Define if you have alloca, as a function or macro.  */
+#undef HAVE_ALLOCA
+
+/* Define if you have <alloca.h> and it should be used (not on Ultrix).  */
+#undef HAVE_ALLOCA_H
+
+/* Define if you don't have vprintf but do have _doprnt.  */
+#undef HAVE_DOPRNT
+
+/* Define if you have the vprintf function.  */
+#undef HAVE_VPRINTF
+
+/* Define if on MINIX.  */
+#undef _MINIX
+
+/* Define to `long' if <sys/types.h> doesn't define.  */
+#undef off_t
+
+/* Define if the system does not provide POSIX.1 features except
+   with this defined.  */
+#undef _POSIX_1_SOURCE
+
+/* Define if you need to in order for stat and other things to work.  */
+#undef _POSIX_SOURCE
+
+/* Define as the return type of signal handlers (int or void).  */
+#undef RETSIGTYPE
+
+/* Define to `unsigned' if <sys/types.h> doesn't define.  */
+#undef size_t
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at run-time.
+ STACK_DIRECTION > 0 => grows toward higher addresses
+ STACK_DIRECTION < 0 => grows toward lower addresses
+ STACK_DIRECTION = 0 => direction of growth unknown
+ */
+#undef STACK_DIRECTION
+
+/* Define if you have the ANSI C header files.  */
+#undef STDC_HEADERS
+
+/* Define if you can safely include both <sys/time.h> and <time.h>.  */
+#undef TIME_WITH_SYS_TIME
+
+/* Define if your <sys/time.h> declares struct tm.  */
+#undef TM_IN_SYS_TIME
+
+/* Define to the name of the distribution.  */
+#undef PACKAGE
+
+/* Define to the version of the distribution.  */
+#undef VERSION
+
+/* Define to 1 if you have the valloc function.  */
+#undef HAVE_VALLOC
+
+/* Define to 1 if ANSI function prototypes are usable.  */
+#undef PROTOTYPES
+
+/* Define if you don't want to use long long's with GCC */
+#undef DISABLE_LONG_LONG
+ 
+/* Define to 1 for better use of the debugging malloc library.  See
+   site ftp.antaire.com in antaire/src, file dmalloc/dmalloc.tar.gz.  */
+#undef WITH_DMALLOC
+
+ 
+/* Define to 1 if GNU regex should be used instead of GNU rx.  */
+#undef WITH_REGEX
+
+/* Some braindead header files do not have the requ'd function declarations */
+#undef HAVE_FGETC_DECL
+#undef HAVE_FREAD_DECL
+
+/* See if have this field in the prstatus_t structure */
+/* It stores the size of the process heap */
+#undef HAVE_PR_BRKSIZE
+
+/* Define FASTCGI if needsbe */
+#undef USE_FASTCGI
+
+/* Define USE_CORBA if needsbe */
+#undef USE_CORBA
+
+/* Define MICO_DIR if needsbe */
+#undef MICO_DIR
+
+/* Define MICO_VERSION if required */
+#undef MICO_VERSION
+
+/* Define if you have the ftime function.  */
+#undef HAVE_FTIME
+
+/* Define if you have the ftruncate function.  */
+#undef HAVE_FTRUNCATE
+
+/* Define if you have the getpagesize function.  */
+#undef HAVE_GETPAGESIZE
+
+/* Define if you have the getrusage function.  */
+#undef HAVE_GETRUSAGE
+
+/* Define if you have the mallinfo function.  */
+#undef HAVE_MALLINFO
+
+/* Define if you have the select function.  */
+#undef HAVE_SELECT
+
+/* Define if you have the setbuffer function.  */
+#undef HAVE_SETBUFFER
+
+/* Define if you have the strcasecmp function.  */
+#undef HAVE_STRCASECMP
+
+/* Define if you have the strerror function.  */
+#undef HAVE_STRERROR
+
+/* Define if you have the strftime function.  */
+#undef HAVE_STRFTIME
+
+/* Define if you have the strstr function.  */
+#undef HAVE_STRSTR
+
+/* Define if you have the strtol function.  */
+#undef HAVE_STRTOL
+
+/* Define if you have the times function.  */
+#undef HAVE_TIMES
+
+/* Define if you have the valloc function.  */
+#undef HAVE_VALLOC
+
+/* Define if you have the <crypt.h> header file.  */
+#undef HAVE_CRYPT_H
+
+/* Define if you have the <dirent.h> header file.  */
+#undef HAVE_DIRENT_H
+
+/* Define if you have the <fcntl.h> header file.  */
+#undef HAVE_FCNTL_H
+
+/* Define if you have the <limits.h> header file.  */
+#undef HAVE_LIMITS_H
+
+/* Define if you have the <memory.h> header file.  */
+#undef HAVE_MEMORY_H
+
+/* Define if you have the <ndir.h> header file.  */
+#undef HAVE_NDIR_H
+
+/* Define if you have the <string.h> header file.  */
+#undef HAVE_STRING_H
+
+/* Define if you have the <sys/dir.h> header file.  */
+#undef HAVE_SYS_DIR_H
+
+/* Define if you have the <sys/ndir.h> header file.  */
+#undef HAVE_SYS_NDIR_H
+
+/* Define if you have the <sys/procfs.h> header file.  */
+#undef HAVE_SYS_PROCFS_H
+
+/* Define if you have the <sys/time.h> header file.  */
+#undef HAVE_SYS_TIME_H
+
+/* Define if you have the <unistd.h> header file.  */
+#undef HAVE_UNISTD_H
+
+/* Define if you have the crypt library (-lcrypt).  */
+#undef HAVE_LIBCRYPT
+
+/* Define if you have the g library (-lg).  */
+#undef HAVE_LIBG
+
+/* Define if you have the gdbm library (-lgdbm).  */
+#undef HAVE_LIBGDBM
+
+/* Define if you have the m library (-lm).  */
+#undef HAVE_LIBM
+
+/* Define if you have the stdc++ library (-lstdc++).  */
+#undef HAVE_LIBSTDC__
+
+/* Define if you have gettext (eg glibc) */
+#undef ENABLE_NLS
+
+/* Define if big endian */
+#undef WORDS_BIGENDIAN
+
+#endif /* _GSDL_CONFIG_H */
Index: /gsdl/trunk/runtime-src/configure
===================================================================
--- /gsdl/trunk/runtime-src/configure	(revision 16571)
+++ /gsdl/trunk/runtime-src/configure	(revision 16571)
@@ -0,0 +1,8798 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.59.
+#
+# Copyright (C) 2003 Free Software Foundation, Inc.
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+  set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+  LC_TELEPHONE LC_TIME
+do
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+    eval $as_var=C; export $as_var
+  else
+    $as_unset $as_var
+  fi
+done
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)$' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\/\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+
+
+# PATH needs CR, and LINENO needs CR and PATH.
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
+  # Find who we are.  Look in the path if we contain no path at all
+  # relative or not.
+  case $0 in
+    *[\\/]* ) as_myself=$0 ;;
+    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+
+       ;;
+  esac
+  # We did not find ourselves, most probably we were run as `sh COMMAND'
+  # in which case we are not to be found in the path.
+  if test "x$as_myself" = x; then
+    as_myself=$0
+  fi
+  if test ! -f "$as_myself"; then
+    { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2
+   { (exit 1); exit 1; }; }
+  fi
+  case $CONFIG_SHELL in
+  '')
+    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for as_base in sh bash ksh sh5; do
+	 case $as_dir in
+	 /*)
+	   if ("$as_dir/$as_base" -c '
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
+	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
+	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
+	     CONFIG_SHELL=$as_dir/$as_base
+	     export CONFIG_SHELL
+	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
+	   fi;;
+	 esac
+       done
+done
+;;
+  esac
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line before each line; the second 'sed' does the real
+  # work.  The second script uses 'N' to pair each line-number line
+  # with the numbered line, and appends trailing '-' during
+  # substitution so that $LINENO is not a special case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
+  sed '=' <$as_myself |
+    sed '
+      N
+      s,$,-,
+      : loop
+      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+      t loop
+      s,-$,,
+      s,^['$as_cr_digits']*\n,,
+    ' >$as_me.lineno &&
+  chmod +x $as_me.lineno ||
+    { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensible to this).
+  . ./$as_me.lineno
+  # Exit status is that of the last command.
+  exit
+}
+
+
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+  *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T='	' ;;
+  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+echo >conf$$.file
+if ln -s conf$$.file conf$$ 2>/dev/null; then
+  # We could just check for DJGPP; but this test a) works b) is more generic
+  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
+  if test -f conf$$.exe; then
+    # Don't use ln at all; we don't have any links
+    as_ln_s='cp -p'
+  else
+    as_ln_s='ln -s'
+  fi
+elif ln conf$$.file conf$$ 2>/dev/null; then
+  as_ln_s=ln
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.file
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p=:
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_executable_p="test -f"
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.
+as_nl='
+'
+IFS=" 	$as_nl"
+
+# CDPATH.
+$as_unset CDPATH
+
+
+# Name of the host.
+# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+exec 6>&1
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_config_libobj_dir=.
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+# Maximum number of lines to put in a shell here document.
+# This variable seems obsolete.  It should probably be removed, and
+# only ac_max_sed_lines should be used.
+: ${ac_max_here_lines=38}
+
+# Identity of this package.
+PACKAGE_NAME=
+PACKAGE_TARNAME=
+PACKAGE_VERSION=
+PACKAGE_STRING=
+PACKAGE_BUGREPORT=
+
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#if STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# if HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#if HAVE_STRING_H
+# if !STDC_HEADERS && HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#if HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#else
+# if HAVE_STDINT_H
+#  include <stdint.h>
+# endif
+#endif
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subdirs_all="$ac_subdirs_all packages"
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS PACKAGE VERSION USE_FASTCGI USE_LANGACTION USE_CORBA MICO_DIR USE_Z3950 USE_YAZ ENABLE_ACCENTFOLD USE_SQLITE LDFLAGS CFLAGS CC CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX AWK YACC build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S SET_MAKE RANLIB ac_ct_RANLIB COMPAT32BITFLAGS MICO_VER CPP EGREP U ANSI2KNR ALLOCA LIBOBJS STATIC GDBM_LIBPATH GDBM_INCLUDE gsdlos MODULEDIRS subdirs LTLIBOBJS'
+ac_subst_files=''
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datadir='${prefix}/share'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+libdir='${exec_prefix}/lib'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+infodir='${prefix}/info'
+mandir='${prefix}/man'
+
+ac_prev=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval "$ac_prev=\$ac_option"
+    ac_prev=
+    continue
+  fi
+
+  ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_option in
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+  | --da=*)
+    datadir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid feature name: $ac_feature" >&2
+   { (exit 1); exit 1; }; }
+    ac_feature=`echo $ac_feature | sed 's/-/_/g'`
+    eval "enable_$ac_feature=no" ;;
+
+  -enable-* | --enable-*)
+    ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid feature name: $ac_feature" >&2
+   { (exit 1); exit 1; }; }
+    ac_feature=`echo $ac_feature | sed 's/-/_/g'`
+    case $ac_option in
+      *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
+      *) ac_optarg=yes ;;
+    esac
+    eval "enable_$ac_feature='$ac_optarg'" ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst \
+  | --locals | --local | --loca | --loc | --lo)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+  | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid package name: $ac_package" >&2
+   { (exit 1); exit 1; }; }
+    ac_package=`echo $ac_package| sed 's/-/_/g'`
+    case $ac_option in
+      *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
+      *) ac_optarg=yes ;;
+    esac
+    eval "with_$ac_package='$ac_optarg'" ;;
+
+  -without-* | --without-*)
+    ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid package name: $ac_package" >&2
+   { (exit 1); exit 1; }; }
+    ac_package=`echo $ac_package | sed 's/-/_/g'`
+    eval "with_$ac_package=no" ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) { echo "$as_me: error: unrecognized option: $ac_option
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; }
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid variable name: $ac_envvar" >&2
+   { (exit 1); exit 1; }; }
+    ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
+    eval "$ac_envvar='$ac_optarg'"
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  { echo "$as_me: error: missing argument to $ac_option" >&2
+   { (exit 1); exit 1; }; }
+fi
+
+# Be sure to have absolute paths.
+for ac_var in exec_prefix prefix
+do
+  eval ac_val=$`echo $ac_var`
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* | NONE | '' ) ;;
+    *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# Be sure to have absolute paths.
+for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \
+	      localstatedir libdir includedir oldincludedir infodir mandir
+do
+  eval ac_val=$`echo $ac_var`
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* ) ;;
+    *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+    echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
+    If a cross compiler is detected then cross compile mode will be used." >&2
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then its parent.
+  ac_confdir=`(dirname "$0") 2>/dev/null ||
+$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$0" : 'X\(//\)[^/]' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$0" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r $srcdir/$ac_unique_file; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r $srcdir/$ac_unique_file; then
+  if test "$ac_srcdir_defaulted" = yes; then
+    { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2
+   { (exit 1); exit 1; }; }
+  else
+    { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
+   { (exit 1); exit 1; }; }
+  fi
+fi
+(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null ||
+  { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2
+   { (exit 1); exit 1; }; }
+srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'`
+ac_env_build_alias_set=${build_alias+set}
+ac_env_build_alias_value=$build_alias
+ac_cv_env_build_alias_set=${build_alias+set}
+ac_cv_env_build_alias_value=$build_alias
+ac_env_host_alias_set=${host_alias+set}
+ac_env_host_alias_value=$host_alias
+ac_cv_env_host_alias_set=${host_alias+set}
+ac_cv_env_host_alias_value=$host_alias
+ac_env_target_alias_set=${target_alias+set}
+ac_env_target_alias_value=$target_alias
+ac_cv_env_target_alias_set=${target_alias+set}
+ac_cv_env_target_alias_value=$target_alias
+ac_env_CC_set=${CC+set}
+ac_env_CC_value=$CC
+ac_cv_env_CC_set=${CC+set}
+ac_cv_env_CC_value=$CC
+ac_env_CFLAGS_set=${CFLAGS+set}
+ac_env_CFLAGS_value=$CFLAGS
+ac_cv_env_CFLAGS_set=${CFLAGS+set}
+ac_cv_env_CFLAGS_value=$CFLAGS
+ac_env_LDFLAGS_set=${LDFLAGS+set}
+ac_env_LDFLAGS_value=$LDFLAGS
+ac_cv_env_LDFLAGS_set=${LDFLAGS+set}
+ac_cv_env_LDFLAGS_value=$LDFLAGS
+ac_env_CPPFLAGS_set=${CPPFLAGS+set}
+ac_env_CPPFLAGS_value=$CPPFLAGS
+ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set}
+ac_cv_env_CPPFLAGS_value=$CPPFLAGS
+ac_env_CXX_set=${CXX+set}
+ac_env_CXX_value=$CXX
+ac_cv_env_CXX_set=${CXX+set}
+ac_cv_env_CXX_value=$CXX
+ac_env_CXXFLAGS_set=${CXXFLAGS+set}
+ac_env_CXXFLAGS_value=$CXXFLAGS
+ac_cv_env_CXXFLAGS_set=${CXXFLAGS+set}
+ac_cv_env_CXXFLAGS_value=$CXXFLAGS
+ac_env_CPP_set=${CPP+set}
+ac_env_CPP_value=$CPP
+ac_cv_env_CPP_set=${CPP+set}
+ac_cv_env_CPP_value=$CPP
+
+#
+# Report the --help message.
+#
+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 this package to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+_ACEOF
+
+  cat <<_ACEOF
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+			  [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+			  [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR           user executables [EPREFIX/bin]
+  --sbindir=DIR          system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR       program executables [EPREFIX/libexec]
+  --datadir=DIR          read-only architecture-independent data [PREFIX/share]
+  --sysconfdir=DIR       read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR   modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR    modifiable single-machine data [PREFIX/var]
+  --libdir=DIR           object code libraries [EPREFIX/lib]
+  --includedir=DIR       C header files [PREFIX/include]
+  --oldincludedir=DIR    C header files for non-gcc [/usr/include]
+  --infodir=DIR          info documentation [PREFIX/info]
+  --mandir=DIR           man documentation [PREFIX/man]
+_ACEOF
+
+  cat <<\_ACEOF
+
+System types:
+  --build=BUILD     configure for building on BUILD [guessed]
+  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
+  --target=TARGET   configure for building compilers for TARGET [HOST]
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+
+  cat <<\_ACEOF
+
+Optional Features:
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-corba          Enable CORBA support
+  --enable-z3950          Enable Z39.50 client support
+  --disable-yaz           Disable YAZ compilation
+  --disable-accentfold    Disable Accent Folding for MGPP
+  --disable-sqlite        Disable SQLite support
+
+Optional Packages:
+  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --with-micodir          Use installed MICO directory
+  --with-gdbm=dir         Use local gdbm library and headers
+  --with-dmalloc          use dmalloc, as in
+                          ftp://ftp.letters.com/src/dmalloc/dmalloc.tar.gz
+  --with-regex            use older regex in lieu of GNU rx for matching
+
+Some influential environment variables:
+  CC          C compiler command
+  CFLAGS      C compiler flags
+  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+              nonstandard directory <lib dir>
+  CPPFLAGS    C/C++ preprocessor flags, e.g. -I<include dir> if you have
+              headers in a nonstandard directory <include dir>
+  CXX         C++ compiler command
+  CXXFLAGS    C++ compiler flags
+  CPP         C preprocessor
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+_ACEOF
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  ac_popdir=`pwd`
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d $ac_dir || continue
+    ac_builddir=.
+
+if test "$ac_dir" != .; then
+  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  # A "../" for each directory in $ac_dir_suffix.
+  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+  ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+  .)  # No --srcdir option.  We are building in place.
+    ac_srcdir=.
+    if test -z "$ac_top_builddir"; then
+       ac_top_srcdir=.
+    else
+       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+    fi ;;
+  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir ;;
+  *) # Relative path.
+    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
+
+    cd $ac_dir
+    # Check for guested configure; otherwise get Cygnus style configure.
+    if test -f $ac_srcdir/configure.gnu; then
+      echo
+      $SHELL $ac_srcdir/configure.gnu  --help=recursive
+    elif test -f $ac_srcdir/configure; then
+      echo
+      $SHELL $ac_srcdir/configure  --help=recursive
+    elif test -f $ac_srcdir/configure.ac ||
+	   test -f $ac_srcdir/configure.in; then
+      echo
+      $ac_configure --help
+    else
+      echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi
+    cd $ac_popdir
+  done
+fi
+
+test -n "$ac_init_help" && exit 0
+if $ac_init_version; then
+  cat <<\_ACEOF
+
+Copyright (C) 2003 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit 0
+fi
+exec 5>config.log
+cat >&5 <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by $as_me, which was
+generated by GNU Autoconf 2.59.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+hostinfo               = `(hostinfo) 2>/dev/null               || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  echo "PATH: $as_dir"
+done
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_sep=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+      ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;;
+    2)
+      ac_configure_args1="$ac_configure_args1 '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+	ac_must_keep_next=false # Got value, back to normal.
+      else
+	case $ac_arg in
+	  *=* | --config-cache | -C | -disable-* | --disable-* \
+	  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+	  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+	  | -with-* | --with-* | -without-* | --without-* | --x)
+	    case "$ac_configure_args0 " in
+	      "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+	    esac
+	    ;;
+	  -* ) ac_must_keep_next=true ;;
+	esac
+      fi
+      ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'"
+      # Get rid of the leading space.
+      ac_sep=" "
+      ;;
+    esac
+  done
+done
+$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; }
+$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; }
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Be sure not to use single quotes in there, as some shells,
+# such as our DU 5.0 friend, will then `close' the trap.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    cat <<\_ASBOX
+## ---------------- ##
+## Cache variables. ##
+## ---------------- ##
+_ASBOX
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+{
+  (set) 2>&1 |
+    case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in
+    *ac_space=\ *)
+      sed -n \
+	"s/'"'"'/'"'"'\\\\'"'"''"'"'/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p"
+      ;;
+    *)
+      sed -n \
+	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+      ;;
+    esac;
+}
+    echo
+
+    cat <<\_ASBOX
+## ----------------- ##
+## Output variables. ##
+## ----------------- ##
+_ASBOX
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=$`echo $ac_var`
+      echo "$ac_var='"'"'$ac_val'"'"'"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      cat <<\_ASBOX
+## ------------- ##
+## Output files. ##
+## ------------- ##
+_ASBOX
+      echo
+      for ac_var in $ac_subst_files
+      do
+	eval ac_val=$`echo $ac_var`
+	echo "$ac_var='"'"'$ac_val'"'"'"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      cat <<\_ASBOX
+## ----------- ##
+## confdefs.h. ##
+## ----------- ##
+_ASBOX
+      echo
+      sed "/^$/d" confdefs.h | sort
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      echo "$as_me: caught signal $ac_signal"
+    echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core &&
+  rm -rf conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+     ' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -rf conftest* confdefs.h
+# AIX cpp loses on an empty file, so make sure it contains at least a newline.
+echo >confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer explicitly selected file to automatically selected ones.
+if test -z "$CONFIG_SITE"; then
+  if test "x$prefix" != xNONE; then
+    CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
+  else
+    CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
+  fi
+fi
+for ac_site_file in $CONFIG_SITE; do
+  if test -r "$ac_site_file"; then
+    { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5
+echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file"
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special
+  # files actually), so we avoid doing that.
+  if test -f "$cache_file"; then
+    { echo "$as_me:$LINENO: loading cache $cache_file" >&5
+echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . $cache_file;;
+      *)                      . ./$cache_file;;
+    esac
+  fi
+else
+  { echo "$as_me:$LINENO: creating cache $cache_file" >&5
+echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in `(set) 2>&1 |
+	       sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val="\$ac_cv_env_${ac_var}_value"
+  eval ac_new_val="\$ac_env_${ac_var}_value"
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5
+echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+	{ echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5
+echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+	{ echo "$as_me:$LINENO:   former value:  $ac_old_val" >&5
+echo "$as_me:   former value:  $ac_old_val" >&2;}
+	{ echo "$as_me:$LINENO:   current value: $ac_new_val" >&5
+echo "$as_me:   current value: $ac_new_val" >&2;}
+	ac_cache_corrupted=:
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+      ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5
+echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5
+echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+          ac_config_headers="$ac_config_headers config.h"
+
+
+
+
+PACKAGE=gsdl
+VERSION=2.82-svn
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE "$PACKAGE"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define VERSION "$VERSION"
+_ACEOF
+
+
+
+
+USE_FASTCGI=0
+if test USE_FASTCGI = 1; then
+cat >>confdefs.h <<\_ACEOF
+#define USE_FASTCGI 1
+_ACEOF
+
+
+fi
+
+if test USE_LANGACTION = 1; then
+cat >>confdefs.h <<\_ACEOF
+#define USE_LANGACTION 1
+_ACEOF
+
+
+fi
+
+# Check whether --enable-corba or --disable-corba was given.
+if test "${enable_corba+set}" = set; then
+  enableval="$enable_corba"
+  USE_CORBA=1
+else
+  USE_CORBA=0
+fi;
+cat >>confdefs.h <<_ACEOF
+#define USE_CORBA $USE_CORBA
+_ACEOF
+
+
+
+
+# Check whether --with-micodir or --without-micodir was given.
+if test "${with_micodir+set}" = set; then
+  withval="$with_micodir"
+  MICO_DIR=$enableval
+else
+  MICO_DIR="default"
+fi;
+cat >>confdefs.h <<_ACEOF
+#define MICO_DIR "$MICO_DIR"
+_ACEOF
+
+
+
+# Check whether --enable-z3950 or --disable-z3950 was given.
+if test "${enable_z3950+set}" = set; then
+  enableval="$enable_z3950"
+  USE_Z3950=1
+else
+  USE_Z3950=0
+fi;
+if test USE_Z3950 = 1; then
+cat >>confdefs.h <<\_ACEOF
+#define USE_Z3950 $USE_Z3950
+_ACEOF
+
+
+fi
+
+# Check whether --enable-yaz or --disable-yaz was given.
+if test "${enable_yaz+set}" = set; then
+  enableval="$enable_yaz"
+  USE_YAZ=0
+else
+  USE_YAZ=1
+fi;
+cat >>confdefs.h <<\_ACEOF
+#define USE_YAZ $USE_YAZ
+_ACEOF
+
+
+
+
+# Check whether --with-gdbm or --without-gdbm was given.
+if test "${with_gdbm+set}" = set; then
+  withval="$with_gdbm"
+  gdbmdir=$withval
+fi;
+
+# Check whether --enable-accentfold or --disable-accentfold was given.
+if test "${enable_accentfold+set}" = set; then
+  enableval="$enable_accentfold"
+  ENABLE_ACCENTFOLD=0
+else
+  ENABLE_ACCENTFOLD=1
+fi;
+cat >>confdefs.h <<\_ACEOF
+#define ENABLE_ACCENTFOLD $ENABLE_ACCENTFOLD
+_ACEOF
+
+
+
+# Check whether --enable-sqlite or --disable-sqlite was given.
+if test "${enable_sqlite+set}" = set; then
+  enableval="$enable_sqlite"
+  USE_SQLITE=0
+else
+  USE_SQLITE=1
+fi;
+cat >>confdefs.h <<\_ACEOF
+#define USE_SQLITE $USE_SQLITE
+_ACEOF
+
+
+
+LDFLAGS=$LDFLAGS
+
+if test -z "$CFLAGS"; then
+CFLAGS=-O2
+fi
+
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  CC=$ac_ct_CC
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="cc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  CC=$ac_ct_CC
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+fi
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  ac_prog_rejected=no
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+       ac_prog_rejected=yes
+       continue
+     fi
+    ac_cv_prog_CC="cc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# != 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+  fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in cl
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+    test -n "$CC" && break
+  done
+fi
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in cl
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$ac_ct_CC" && break
+done
+
+  CC=$ac_ct_CC
+fi
+
+fi
+
+
+test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&5
+echo "$as_me: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+
+# Provide some information about the compiler.
+echo "$as_me:$LINENO:" \
+     "checking for C compiler version" >&5
+ac_compiler=`set X $ac_compile; echo $2`
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
+  (eval $ac_compiler --version </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v </dev/null >&5\"") >&5
+  (eval $ac_compiler -v </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V </dev/null >&5\"") >&5
+  (eval $ac_compiler -V </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+echo "$as_me:$LINENO: checking for C compiler default output file name" >&5
+echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6
+ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5
+  (eval $ac_link_default) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # Find the output, starting from the most likely.  This scheme is
+# not robust to junk in `.', hence go to wildcards (a.*) only as a last
+# resort.
+
+# Be careful to initialize this variable, since it used to be cached.
+# Otherwise an old cache value of `no' led to `EXEEXT = no' in a Makefile.
+ac_cv_exeext=
+# b.out is created by i960 compilers.
+for ac_file in a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out
+do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj )
+	;;
+    conftest.$ac_ext )
+	# This is the source file.
+	;;
+    [ab].out )
+	# We found the default executable, but exeext='' is most
+	# certainly right.
+	break;;
+    *.* )
+	ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	# FIXME: I believe we export ac_cv_exeext for Libtool,
+	# but it would be cool to find out if it's true.  Does anybody
+	# maintain Libtool? --akim.
+	export ac_cv_exeext
+	break;;
+    * )
+	break;;
+  esac
+done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { echo "$as_me:$LINENO: error: C compiler cannot create executables
+See \`config.log' for more details." >&5
+echo "$as_me: error: C compiler cannot create executables
+See \`config.log' for more details." >&2;}
+   { (exit 77); exit 77; }; }
+fi
+
+ac_exeext=$ac_cv_exeext
+echo "$as_me:$LINENO: result: $ac_file" >&5
+echo "${ECHO_T}$ac_file" >&6
+
+# Check the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+echo "$as_me:$LINENO: checking whether the C compiler works" >&5
+echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6
+# FIXME: These cross compiler hacks should be removed for Autoconf 3.0
+# If not cross compiling, check that we can run a simple program.
+if test "$cross_compiling" != yes; then
+  if { ac_try='./$ac_file'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { echo "$as_me:$LINENO: error: cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+    fi
+  fi
+fi
+echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+
+rm -f a.out a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+# Check the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
+echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6
+echo "$as_me:$LINENO: result: $cross_compiling" >&5
+echo "${ECHO_T}$cross_compiling" >&6
+
+echo "$as_me:$LINENO: checking for suffix of executables" >&5
+echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;;
+    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	  export ac_cv_exeext
+	  break;;
+    * ) break;;
+  esac
+done
+else
+  { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+rm -f conftest$ac_cv_exeext
+echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5
+echo "${ECHO_T}$ac_cv_exeext" >&6
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+echo "$as_me:$LINENO: checking for suffix of object files" >&5
+echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6
+if test "${ac_cv_objext+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg ) ;;
+    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+       break;;
+  esac
+done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_objext" >&5
+echo "${ECHO_T}$ac_cv_objext" >&6
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5
+echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6
+if test "${ac_cv_c_compiler_gnu+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_compiler_gnu=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_compiler_gnu=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5
+echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6
+GCC=`test $ac_compiler_gnu = yes && echo yes`
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+CFLAGS="-g"
+echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5
+echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6
+if test "${ac_cv_prog_cc_g+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cc_g=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_prog_cc_g=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_g" >&6
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+echo "$as_me:$LINENO: checking for $CC option to accept ANSI C" >&5
+echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6
+if test "${ac_cv_prog_cc_stdc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_prog_cc_stdc=no
+ac_save_CC=$CC
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std1 is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std1.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+  ;
+  return 0;
+}
+_ACEOF
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX			-qlanglvl=ansi
+# Ultrix and OSF/1	-std1
+# HP-UX 10.20 and later	-Ae
+# HP-UX older versions	-Aa -D_HPUX_SOURCE
+# SVR4			-Xc -D__EXTENSIONS__
+for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cc_stdc=$ac_arg
+break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext
+done
+rm -f conftest.$ac_ext conftest.$ac_objext
+CC=$ac_save_CC
+
+fi
+
+case "x$ac_cv_prog_cc_stdc" in
+  x|xno)
+    echo "$as_me:$LINENO: result: none needed" >&5
+echo "${ECHO_T}none needed" >&6 ;;
+  *)
+    echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6
+    CC="$CC $ac_cv_prog_cc_stdc" ;;
+esac
+
+# Some people use a C++ compiler to compile C.  Since we use `exit',
+# in C++ we need to declare it.  In case someone uses the same compiler
+# for both compiling C and C++ we need to have the C++ compiler decide
+# the declaration of exit, since it's the most demanding environment.
+cat >conftest.$ac_ext <<_ACEOF
+#ifndef __cplusplus
+  choke me
+#endif
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  for ac_declaration in \
+   '' \
+   'extern "C" void std::exit (int) throw (); using std::exit;' \
+   'extern "C" void std::exit (int); using std::exit;' \
+   'extern "C" void exit (int) throw ();' \
+   'extern "C" void exit (int);' \
+   'void exit (int);'
+do
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+#include <stdlib.h>
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+continue
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+rm -f conftest*
+if test -n "$ac_declaration"; then
+  echo '#ifdef __cplusplus' >>confdefs.h
+  echo $ac_declaration      >>confdefs.h
+  echo '#endif'             >>confdefs.h
+fi
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ac_ext=cc
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  for ac_prog in $CCC g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CXX"; then
+  ac_cv_prog_CXX="$CXX" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CXX="$ac_tool_prefix$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CXX=$ac_cv_prog_CXX
+if test -n "$CXX"; then
+  echo "$as_me:$LINENO: result: $CXX" >&5
+echo "${ECHO_T}$CXX" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+    test -n "$CXX" && break
+  done
+fi
+if test -z "$CXX"; then
+  ac_ct_CXX=$CXX
+  for ac_prog in $CCC g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CXX"; then
+  ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CXX="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CXX=$ac_cv_prog_ac_ct_CXX
+if test -n "$ac_ct_CXX"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CXX" >&5
+echo "${ECHO_T}$ac_ct_CXX" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$ac_ct_CXX" && break
+done
+test -n "$ac_ct_CXX" || ac_ct_CXX="g++"
+
+  CXX=$ac_ct_CXX
+fi
+
+
+# Provide some information about the compiler.
+echo "$as_me:$LINENO:" \
+     "checking for C++ compiler version" >&5
+ac_compiler=`set X $ac_compile; echo $2`
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
+  (eval $ac_compiler --version </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v </dev/null >&5\"") >&5
+  (eval $ac_compiler -v </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V </dev/null >&5\"") >&5
+  (eval $ac_compiler -V </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+
+echo "$as_me:$LINENO: checking whether we are using the GNU C++ compiler" >&5
+echo $ECHO_N "checking whether we are using the GNU C++ compiler... $ECHO_C" >&6
+if test "${ac_cv_cxx_compiler_gnu+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_compiler_gnu=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_compiler_gnu=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_cxx_compiler_gnu=$ac_compiler_gnu
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_cxx_compiler_gnu" >&5
+echo "${ECHO_T}$ac_cv_cxx_compiler_gnu" >&6
+GXX=`test $ac_compiler_gnu = yes && echo yes`
+ac_test_CXXFLAGS=${CXXFLAGS+set}
+ac_save_CXXFLAGS=$CXXFLAGS
+CXXFLAGS="-g"
+echo "$as_me:$LINENO: checking whether $CXX accepts -g" >&5
+echo $ECHO_N "checking whether $CXX accepts -g... $ECHO_C" >&6
+if test "${ac_cv_prog_cxx_g+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cxx_g=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_prog_cxx_g=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_cxx_g" >&5
+echo "${ECHO_T}$ac_cv_prog_cxx_g" >&6
+if test "$ac_test_CXXFLAGS" = set; then
+  CXXFLAGS=$ac_save_CXXFLAGS
+elif test $ac_cv_prog_cxx_g = yes; then
+  if test "$GXX" = yes; then
+    CXXFLAGS="-g -O2"
+  else
+    CXXFLAGS="-g"
+  fi
+else
+  if test "$GXX" = yes; then
+    CXXFLAGS="-O2"
+  else
+    CXXFLAGS=
+  fi
+fi
+for ac_declaration in \
+   '' \
+   'extern "C" void std::exit (int) throw (); using std::exit;' \
+   'extern "C" void std::exit (int); using std::exit;' \
+   'extern "C" void exit (int) throw ();' \
+   'extern "C" void exit (int);' \
+   'void exit (int);'
+do
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+#include <stdlib.h>
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+continue
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+rm -f conftest*
+if test -n "$ac_declaration"; then
+  echo '#ifdef __cplusplus' >>confdefs.h
+  echo $ac_declaration      >>confdefs.h
+  echo '#endif'             >>confdefs.h
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+for ac_prog in gawk mawk nawk awk
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_AWK+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$AWK"; then
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_AWK="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+AWK=$ac_cv_prog_AWK
+if test -n "$AWK"; then
+  echo "$as_me:$LINENO: result: $AWK" >&5
+echo "${ECHO_T}$AWK" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$AWK" && break
+done
+
+for ac_prog in 'bison -y' byacc
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_YACC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$YACC"; then
+  ac_cv_prog_YACC="$YACC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_YACC="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+YACC=$ac_cv_prog_YACC
+if test -n "$YACC"; then
+  echo "$as_me:$LINENO: result: $YACC" >&5
+echo "${ECHO_T}$YACC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$YACC" && break
+done
+test -n "$YACC" || YACC="yacc"
+
+ac_aux_dir=
+for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
+  if test -f $ac_dir/install-sh; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install-sh -c"
+    break
+  elif test -f $ac_dir/install.sh; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install.sh -c"
+    break
+  elif test -f $ac_dir/shtool; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/shtool install -c"
+    break
+  fi
+done
+if test -z "$ac_aux_dir"; then
+  { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&5
+echo "$as_me: error: cannot find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"
+ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure.
+
+# Make sure we can run config.sub.
+$ac_config_sub sun4 >/dev/null 2>&1 ||
+  { { echo "$as_me:$LINENO: error: cannot run $ac_config_sub" >&5
+echo "$as_me: error: cannot run $ac_config_sub" >&2;}
+   { (exit 1); exit 1; }; }
+
+echo "$as_me:$LINENO: checking build system type" >&5
+echo $ECHO_N "checking build system type... $ECHO_C" >&6
+if test "${ac_cv_build+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_build_alias=$build_alias
+test -z "$ac_cv_build_alias" &&
+  ac_cv_build_alias=`$ac_config_guess`
+test -z "$ac_cv_build_alias" &&
+  { { echo "$as_me:$LINENO: error: cannot guess build type; you must specify one" >&5
+echo "$as_me: error: cannot guess build type; you must specify one" >&2;}
+   { (exit 1); exit 1; }; }
+ac_cv_build=`$ac_config_sub $ac_cv_build_alias` ||
+  { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_build_alias failed" >&5
+echo "$as_me: error: $ac_config_sub $ac_cv_build_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_build" >&5
+echo "${ECHO_T}$ac_cv_build" >&6
+build=$ac_cv_build
+build_cpu=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+build_vendor=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+build_os=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+
+echo "$as_me:$LINENO: checking host system type" >&5
+echo $ECHO_N "checking host system type... $ECHO_C" >&6
+if test "${ac_cv_host+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_host_alias=$host_alias
+test -z "$ac_cv_host_alias" &&
+  ac_cv_host_alias=$ac_cv_build_alias
+ac_cv_host=`$ac_config_sub $ac_cv_host_alias` ||
+  { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_host_alias failed" >&5
+echo "$as_me: error: $ac_config_sub $ac_cv_host_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_host" >&5
+echo "${ECHO_T}$ac_cv_host" >&6
+host=$ac_cv_host
+host_cpu=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+host_vendor=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+host_os=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+
+echo "$as_me:$LINENO: checking target system type" >&5
+echo $ECHO_N "checking target system type... $ECHO_C" >&6
+if test "${ac_cv_target+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_target_alias=$target_alias
+test "x$ac_cv_target_alias" = "x" &&
+  ac_cv_target_alias=$ac_cv_host_alias
+ac_cv_target=`$ac_config_sub $ac_cv_target_alias` ||
+  { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_target_alias failed" >&5
+echo "$as_me: error: $ac_config_sub $ac_cv_target_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_target" >&5
+echo "${ECHO_T}$ac_cv_target" >&6
+target=$ac_cv_target
+target_cpu=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+target_vendor=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+target_os=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+
+# The aliases save the names the user supplied, while $host etc.
+# will get canonicalized.
+test -n "$target_alias" &&
+  test "$program_prefix$program_suffix$program_transform_name" = \
+    NONENONEs,x,x, &&
+  program_prefix=${target_alias}-
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5
+echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6
+if test -z "$INSTALL"; then
+if test "${ac_cv_path_install+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in
+  ./ | .// | /cC/* | \
+  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+  ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \
+  /usr/ucb/* ) ;;
+  *)
+    # OSF1 and SCO ODT 3.0 have their own names for install.
+    # Don't use installbsd from OSF since it installs stuff as root
+    # by default.
+    for ac_prog in ginstall scoinst install; do
+      for ac_exec_ext in '' $ac_executable_extensions; do
+	if $as_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
+	  if test $ac_prog = install &&
+	    grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # AIX install.  It has an incompatible calling convention.
+	    :
+	  elif test $ac_prog = install &&
+	    grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # program-specific install script used by HP pwplus--don't use.
+	    :
+	  else
+	    ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+	    break 3
+	  fi
+	fi
+      done
+    done
+    ;;
+esac
+done
+
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL=$ac_cv_path_install
+  else
+    # As a last resort, use the slow shell script.  We don't cache a
+    # path for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the path is relative.
+    INSTALL=$ac_install_sh
+  fi
+fi
+echo "$as_me:$LINENO: result: $INSTALL" >&5
+echo "${ECHO_T}$INSTALL" >&6
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+echo "$as_me:$LINENO: checking whether ln -s works" >&5
+echo $ECHO_N "checking whether ln -s works... $ECHO_C" >&6
+LN_S=$as_ln_s
+if test "$LN_S" = "ln -s"; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+  echo "$as_me:$LINENO: result: no, using $LN_S" >&5
+echo "${ECHO_T}no, using $LN_S" >&6
+fi
+
+echo "$as_me:$LINENO: checking whether ${MAKE-make} sets \$(MAKE)" >&5
+echo $ECHO_N "checking whether ${MAKE-make} sets \$(MAKE)... $ECHO_C" >&6
+set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y,:./+-,___p_,'`
+if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.make <<\_ACEOF
+all:
+	@echo 'ac_maketemp="$(MAKE)"'
+_ACEOF
+# GNU make sometimes prints "make[1]: Entering...", which would confuse us.
+eval `${MAKE-make} -f conftest.make 2>/dev/null | grep temp=`
+if test -n "$ac_maketemp"; then
+  eval ac_cv_prog_make_${ac_make}_set=yes
+else
+  eval ac_cv_prog_make_${ac_make}_set=no
+fi
+rm -f conftest.make
+fi
+if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  SET_MAKE=
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+  SET_MAKE="MAKE=${MAKE-make}"
+fi
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_RANLIB+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  echo "$as_me:$LINENO: result: $RANLIB" >&5
+echo "${ECHO_T}$RANLIB" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+  test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB=":"
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5
+echo "${ECHO_T}$ac_ct_RANLIB" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  RANLIB=$ac_ct_RANLIB
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+
+echo "$as_me:$LINENO: checking to see if architecture is 64-bit" >&5
+echo $ECHO_N "checking to see if architecture is 64-bit... $ECHO_C" >&6
+arch_64bit=no
+case "$host_cpu" in
+x86_64) arch_64bit=yes ;;
+esac
+
+if test "$arch_64bit" = yes; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  if test -z "$COMPAT32BITFLAGS" ; then
+    COMPAT32BITFLAGS="-m32"
+  fi
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+  if test -z "$COMPAT32BITFLAGS" ; then
+    COMPAT32BITFLAGS=
+  fi
+fi
+export COMPAT32BITFLAGS
+
+
+
+#moved CORBA MICO directory test to get version of MICO
+if test $USE_CORBA = 1; then
+
+if test $MICO_DIR = "default"; then
+#do something
+MICO_INC="-I packages/mico/mico/include"
+else
+#build the micotest program
+MICO_INC= ""
+if test $MICO_DIR != yes; then
+MICO_INC="-I $MICO_DIR"
+fi
+fi
+
+#get MICO_VER value
+sh -c "$CC -c micotest.cpp -o micotest.o $MICO_INC 2>&1" > /dev/null
+sh -c "$CC -o micotest micotest.o -lstdc++ 2>&1" > /dev/null
+MICO_VER=`./micotest` || MICO_VER=2.3.5
+sh -c "rm micotest"
+sh -c "rm micotest.o"
+
+#do test of MICO_VER
+if test MICO_VER != 0; then
+cat >>confdefs.h <<\_ACEOF
+#define MICO_VER 1
+_ACEOF
+
+
+fi
+#end USE_CORBA test
+fi
+
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5
+echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+  if test "${ac_cv_prog_CPP+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+      # Double quotes because CPP needs to be expanded
+    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether non-existent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  # Broken: success on invalid input.
+continue
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  break
+fi
+
+    done
+    ac_cv_prog_CPP=$CPP
+
+fi
+  CPP=$ac_cv_prog_CPP
+else
+  ac_cv_prog_CPP=$CPP
+fi
+echo "$as_me:$LINENO: result: $CPP" >&5
+echo "${ECHO_T}$CPP" >&6
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether non-existent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  # Broken: success on invalid input.
+continue
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  :
+else
+  { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&5
+echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+echo "$as_me:$LINENO: checking for egrep" >&5
+echo $ECHO_N "checking for egrep... $ECHO_C" >&6
+if test "${ac_cv_prog_egrep+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if echo a | (grep -E '(a|b)') >/dev/null 2>&1
+    then ac_cv_prog_egrep='grep -E'
+    else ac_cv_prog_egrep='egrep'
+    fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_egrep" >&5
+echo "${ECHO_T}$ac_cv_prog_egrep" >&6
+ EGREP=$ac_cv_prog_egrep
+
+
+
+echo "$as_me:$LINENO: checking for AIX" >&5
+echo $ECHO_N "checking for AIX... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef _AIX
+  yes
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "yes" >/dev/null 2>&1; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+cat >>confdefs.h <<\_ACEOF
+#define _ALL_SOURCE 1
+_ACEOF
+
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+rm -f conftest*
+
+
+echo "$as_me:$LINENO: checking for library containing strerror" >&5
+echo $ECHO_N "checking for library containing strerror... $ECHO_C" >&6
+if test "${ac_cv_search_strerror+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+ac_cv_search_strerror=no
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char strerror ();
+int
+main ()
+{
+strerror ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_strerror="none required"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+if test "$ac_cv_search_strerror" = no; then
+  for ac_lib in cposix; do
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char strerror ();
+int
+main ()
+{
+strerror ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_strerror="-l$ac_lib"
+break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+  done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_strerror" >&5
+echo "${ECHO_T}$ac_cv_search_strerror" >&6
+if test "$ac_cv_search_strerror" != no; then
+  test "$ac_cv_search_strerror" = "none required" || LIBS="$ac_cv_search_strerror $LIBS"
+
+fi
+
+echo "$as_me:$LINENO: checking for ANSI C header files" >&5
+echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6
+if test "${ac_cv_header_stdc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_header_stdc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_header_stdc=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then
+  :
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ctype.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      exit(2);
+  exit (0);
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_header_stdc=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
+echo "${ECHO_T}$ac_cv_header_stdc" >&6
+if test $ac_cv_header_stdc = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define STDC_HEADERS 1
+_ACEOF
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+
+
+
+
+
+
+
+
+
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+		  inttypes.h stdint.h unistd.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_Header=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_Header=no"
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+if test "${ac_cv_header_minix_config_h+set}" = set; then
+  echo "$as_me:$LINENO: checking for minix/config.h" >&5
+echo $ECHO_N "checking for minix/config.h... $ECHO_C" >&6
+if test "${ac_cv_header_minix_config_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_minix_config_h" >&5
+echo "${ECHO_T}$ac_cv_header_minix_config_h" >&6
+else
+  # Is the header compilable?
+echo "$as_me:$LINENO: checking minix/config.h usability" >&5
+echo $ECHO_N "checking minix/config.h usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <minix/config.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_header_compiler=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking minix/config.h presence" >&5
+echo $ECHO_N "checking minix/config.h presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <minix/config.h>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: minix/config.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: minix/config.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: present but cannot be compiled" >&5
+echo "$as_me: WARNING: minix/config.h: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: minix/config.h:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: minix/config.h: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: minix/config.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: minix/config.h: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: minix/config.h: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: minix/config.h: in the future, the compiler will take precedence" >&2;}
+    (
+      cat <<\_ASBOX
+## ------------------------------------------ ##
+## Report this to the AC_PACKAGE_NAME lists.  ##
+## ------------------------------------------ ##
+_ASBOX
+    ) |
+      sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+echo "$as_me:$LINENO: checking for minix/config.h" >&5
+echo $ECHO_N "checking for minix/config.h... $ECHO_C" >&6
+if test "${ac_cv_header_minix_config_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_header_minix_config_h=$ac_header_preproc
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_minix_config_h" >&5
+echo "${ECHO_T}$ac_cv_header_minix_config_h" >&6
+
+fi
+if test $ac_cv_header_minix_config_h = yes; then
+  MINIX=yes
+else
+  MINIX=
+fi
+
+
+if test "$MINIX" = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define _POSIX_SOURCE 1
+_ACEOF
+
+
+cat >>confdefs.h <<\_ACEOF
+#define _POSIX_1_SOURCE 2
+_ACEOF
+
+
+cat >>confdefs.h <<\_ACEOF
+#define _MINIX 1
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking for ${CC-cc} option to accept ANSI C" >&5
+echo $ECHO_N "checking for ${CC-cc} option to accept ANSI C... $ECHO_C" >&6
+if test "${ac_cv_prog_cc_stdc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_prog_cc_stdc=no
+ac_save_CFLAGS="$CFLAGS"
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX			-qlanglvl=ansi
+# Ultrix and OSF/1	-std1
+# HP-UX			-Aa -D_HPUX_SOURCE
+# SVR4			-Xc
+for ac_arg in "" -qlanglvl=ansi -std1 "-Aa -D_HPUX_SOURCE" -Xc
+do
+  CFLAGS="$ac_save_CFLAGS $ac_arg"
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#if !defined(__STDC__) || __STDC__ != 1
+choke me
+#endif
+
+int
+main ()
+{
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cc_stdc="$ac_arg"; break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+CFLAGS="$ac_save_CFLAGS"
+
+fi
+
+echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6
+case "x$ac_cv_prog_cc_stdc" in
+  x|xno) ;;
+  *) CC="$CC $ac_cv_prog_cc_stdc" ;;
+esac
+
+
+echo "$as_me:$LINENO: checking for function prototypes" >&5
+echo $ECHO_N "checking for function prototypes... $ECHO_C" >&6
+if test "$ac_cv_prog_cc_stdc" != no; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  cat >>confdefs.h <<\_ACEOF
+#define PROTOTYPES 1
+_ACEOF
+
+  U= ANSI2KNR=
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+  U=_ ANSI2KNR=ansi2knr
+fi
+
+echo "$as_me:$LINENO: checking for an ANSI C-conforming const" >&5
+echo $ECHO_N "checking for an ANSI C-conforming const... $ECHO_C" >&6
+if test "${ac_cv_c_const+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+/* FIXME: Include the comments suggested by Paul. */
+#ifndef __cplusplus
+  /* Ultrix mips cc rejects this.  */
+  typedef int charset[2];
+  const charset x;
+  /* SunOS 4.1.1 cc rejects this.  */
+  char const *const *ccp;
+  char **p;
+  /* NEC SVR4.0.2 mips cc rejects this.  */
+  struct point {int x, y;};
+  static struct point const zero = {0,0};
+  /* AIX XL C 1.02.0.0 rejects this.
+     It does not let you subtract one const X* pointer from another in
+     an arm of an if-expression whose if-part is not a constant
+     expression */
+  const char *g = "string";
+  ccp = &g + (g ? g-g : 0);
+  /* HPUX 7.0 cc rejects these. */
+  ++ccp;
+  p = (char**) ccp;
+  ccp = (char const *const *) p;
+  { /* SCO 3.2v4 cc rejects this.  */
+    char *t;
+    char const *s = 0 ? (char *) 0 : (char const *) 0;
+
+    *t++ = 0;
+  }
+  { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
+    int x[] = {25, 17};
+    const int *foo = &x[0];
+    ++foo;
+  }
+  { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
+    typedef const int *iptr;
+    iptr p = 0;
+    ++p;
+  }
+  { /* AIX XL C 1.02.0.0 rejects this saying
+       "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
+    struct s { int j; const int *ap[3]; };
+    struct s *b; b->j = 5;
+  }
+  { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
+    const int foo = 10;
+  }
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_c_const=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_c_const=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_const" >&5
+echo "${ECHO_T}$ac_cv_c_const" >&6
+if test $ac_cv_c_const = no; then
+
+cat >>confdefs.h <<\_ACEOF
+#define const
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking for off_t" >&5
+echo $ECHO_N "checking for off_t... $ECHO_C" >&6
+if test "${ac_cv_type_off_t+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+if ((off_t *) 0)
+  return 0;
+if (sizeof (off_t))
+  return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type_off_t=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_off_t=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_off_t" >&5
+echo "${ECHO_T}$ac_cv_type_off_t" >&6
+if test $ac_cv_type_off_t = yes; then
+  :
+else
+
+cat >>confdefs.h <<_ACEOF
+#define off_t long
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking for size_t" >&5
+echo $ECHO_N "checking for size_t... $ECHO_C" >&6
+if test "${ac_cv_type_size_t+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+if ((size_t *) 0)
+  return 0;
+if (sizeof (size_t))
+  return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type_size_t=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_size_t=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_size_t" >&5
+echo "${ECHO_T}$ac_cv_type_size_t" >&6
+if test $ac_cv_type_size_t = yes; then
+  :
+else
+
+cat >>confdefs.h <<_ACEOF
+#define size_t unsigned
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking whether time.h and sys/time.h may both be included" >&5
+echo $ECHO_N "checking whether time.h and sys/time.h may both be included... $ECHO_C" >&6
+if test "${ac_cv_header_time+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
+
+int
+main ()
+{
+if ((struct tm *) 0)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_header_time=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_header_time=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_time" >&5
+echo "${ECHO_T}$ac_cv_header_time" >&6
+if test $ac_cv_header_time = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define TIME_WITH_SYS_TIME 1
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking whether struct tm is in sys/time.h or time.h" >&5
+echo $ECHO_N "checking whether struct tm is in sys/time.h or time.h... $ECHO_C" >&6
+if test "${ac_cv_struct_tm+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <time.h>
+
+int
+main ()
+{
+struct tm *tp; tp->tm_sec;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_struct_tm=time.h
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_struct_tm=sys/time.h
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_struct_tm" >&5
+echo "${ECHO_T}$ac_cv_struct_tm" >&6
+if test $ac_cv_struct_tm = sys/time.h; then
+
+cat >>confdefs.h <<\_ACEOF
+#define TM_IN_SYS_TIME 1
+_ACEOF
+
+fi
+
+
+if test "$ac_cv_prog_cc_stdc" = '-Xc'; then
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdio.h>
+
+int
+main ()
+{
+ FILE *rubbish = popen("yes", "r");
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+CC="`echo $CC | sed 's/-Xc/-Xa/'`"    ac_cv_prog_cc_stdc='-Xa'
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+
+echo "$as_me:$LINENO: checking for main in -lg" >&5
+echo $ECHO_N "checking for main in -lg... $ECHO_C" >&6
+if test "${ac_cv_lib_g_main+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lg  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+main ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_g_main=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_g_main=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_g_main" >&5
+echo "${ECHO_T}$ac_cv_lib_g_main" >&6
+if test $ac_cv_lib_g_main = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBG 1
+_ACEOF
+
+  LIBS="-lg $LIBS"
+
+fi
+ac_cv_lib_g=ac_cv_lib_g_main
+
+
+echo "$as_me:$LINENO: checking for main in -lm" >&5
+echo $ECHO_N "checking for main in -lm... $ECHO_C" >&6
+if test "${ac_cv_lib_m_main+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lm  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+main ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_m_main=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_m_main=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_m_main" >&5
+echo "${ECHO_T}$ac_cv_lib_m_main" >&6
+if test $ac_cv_lib_m_main = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBM 1
+_ACEOF
+
+  LIBS="-lm $LIBS"
+
+fi
+ac_cv_lib_m=ac_cv_lib_m_main
+
+
+echo "$as_me:$LINENO: checking for main in -lcrypt" >&5
+echo $ECHO_N "checking for main in -lcrypt... $ECHO_C" >&6
+if test "${ac_cv_lib_crypt_main+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lcrypt  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+main ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_crypt_main=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_crypt_main=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_crypt_main" >&5
+echo "${ECHO_T}$ac_cv_lib_crypt_main" >&6
+if test $ac_cv_lib_crypt_main = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBCRYPT 1
+_ACEOF
+
+  LIBS="-lcrypt $LIBS"
+
+fi
+ac_cv_lib_crypt=ac_cv_lib_crypt_main
+
+if test $ENABLE_ACCENTFOLD = 1; then
+
+echo "$as_me:$LINENO: checking for main in -liconv" >&5
+echo $ECHO_N "checking for main in -liconv... $ECHO_C" >&6
+if test "${ac_cv_lib_iconv_main+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-liconv  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+main ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_iconv_main=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_iconv_main=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_iconv_main" >&5
+echo "${ECHO_T}$ac_cv_lib_iconv_main" >&6
+if test $ac_cv_lib_iconv_main = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBICONV 1
+_ACEOF
+
+  LIBS="-liconv $LIBS"
+
+fi
+ac_cv_lib_iconv=ac_cv_lib_iconv_main
+
+fi
+
+
+
+
+
+
+ac_header_dirent=no
+for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do
+  as_ac_Header=`echo "ac_cv_header_dirent_$ac_hdr" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_hdr that defines DIR" >&5
+echo $ECHO_N "checking for $ac_hdr that defines DIR... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <$ac_hdr>
+
+int
+main ()
+{
+if ((DIR *) 0)
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_Header=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_Header=no"
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_hdr" | $as_tr_cpp` 1
+_ACEOF
+
+ac_header_dirent=$ac_hdr; break
+fi
+
+done
+# Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
+if test $ac_header_dirent = dirent.h; then
+  echo "$as_me:$LINENO: checking for library containing opendir" >&5
+echo $ECHO_N "checking for library containing opendir... $ECHO_C" >&6
+if test "${ac_cv_search_opendir+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+ac_cv_search_opendir=no
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char opendir ();
+int
+main ()
+{
+opendir ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_opendir="none required"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+if test "$ac_cv_search_opendir" = no; then
+  for ac_lib in dir; do
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char opendir ();
+int
+main ()
+{
+opendir ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_opendir="-l$ac_lib"
+break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+  done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_opendir" >&5
+echo "${ECHO_T}$ac_cv_search_opendir" >&6
+if test "$ac_cv_search_opendir" != no; then
+  test "$ac_cv_search_opendir" = "none required" || LIBS="$ac_cv_search_opendir $LIBS"
+
+fi
+
+else
+  echo "$as_me:$LINENO: checking for library containing opendir" >&5
+echo $ECHO_N "checking for library containing opendir... $ECHO_C" >&6
+if test "${ac_cv_search_opendir+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+ac_cv_search_opendir=no
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char opendir ();
+int
+main ()
+{
+opendir ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_opendir="none required"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+if test "$ac_cv_search_opendir" = no; then
+  for ac_lib in x; do
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char opendir ();
+int
+main ()
+{
+opendir ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_search_opendir="-l$ac_lib"
+break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+  done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_opendir" >&5
+echo "${ECHO_T}$ac_cv_search_opendir" >&6
+if test "$ac_cv_search_opendir" != no; then
+  test "$ac_cv_search_opendir" = "none required" || LIBS="$ac_cv_search_opendir $LIBS"
+
+fi
+
+fi
+
+echo "$as_me:$LINENO: checking for ANSI C header files" >&5
+echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6
+if test "${ac_cv_header_stdc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_header_stdc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_header_stdc=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then
+  :
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ctype.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      exit(2);
+  exit (0);
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_header_stdc=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
+echo "${ECHO_T}$ac_cv_header_stdc" >&6
+if test $ac_cv_header_stdc = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define STDC_HEADERS 1
+_ACEOF
+
+fi
+
+
+
+
+
+
+
+
+
+
+for ac_header in fcntl.h limits.h sys/time.h unistd.h crypt.h string.h memory.h sys/procfs.h sys/stat.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+else
+  # Is the header compilable?
+echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_header_compiler=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <$ac_header>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    (
+      cat <<\_ASBOX
+## ------------------------------------------ ##
+## Report this to the AC_PACKAGE_NAME lists.  ##
+## ------------------------------------------ ##
+_ASBOX
+    ) |
+      sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdio.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "fread" >/dev/null 2>&1; then
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_FREAD_DECL 1
+_ACEOF
+
+fi
+rm -f conftest*
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdio.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "fgetc" >/dev/null 2>&1; then
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_FGETC_DECL 1
+_ACEOF
+
+fi
+rm -f conftest*
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/procfs.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "pr_brksize" >/dev/null 2>&1; then
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_PR_BRKSIZE 1
+_ACEOF
+
+fi
+rm -f conftest*
+
+
+# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
+# for constant arguments.  Useless!
+echo "$as_me:$LINENO: checking for working alloca.h" >&5
+echo $ECHO_N "checking for working alloca.h... $ECHO_C" >&6
+if test "${ac_cv_working_alloca_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <alloca.h>
+int
+main ()
+{
+char *p = (char *) alloca (2 * sizeof (int));
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_working_alloca_h=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_working_alloca_h=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_working_alloca_h" >&5
+echo "${ECHO_T}$ac_cv_working_alloca_h" >&6
+if test $ac_cv_working_alloca_h = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ALLOCA_H 1
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking for alloca" >&5
+echo $ECHO_N "checking for alloca... $ECHO_C" >&6
+if test "${ac_cv_func_alloca_works+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __GNUC__
+# define alloca __builtin_alloca
+#else
+# ifdef _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
+# else
+#  if HAVE_ALLOCA_H
+#   include <alloca.h>
+#  else
+#   ifdef _AIX
+ #pragma alloca
+#   else
+#    ifndef alloca /* predefined by HP cc +Olibcalls */
+char *alloca ();
+#    endif
+#   endif
+#  endif
+# endif
+#endif
+
+int
+main ()
+{
+char *p = (char *) alloca (1);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_func_alloca_works=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_func_alloca_works=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func_alloca_works" >&5
+echo "${ECHO_T}$ac_cv_func_alloca_works" >&6
+
+if test $ac_cv_func_alloca_works = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ALLOCA 1
+_ACEOF
+
+else
+  # The SVR3 libPW and SVR4 libucb both contain incompatible functions
+# that cause trouble.  Some versions do not even contain alloca or
+# contain a buggy version.  If you still want to use their alloca,
+# use ar to extract alloca.o from them instead of compiling alloca.c.
+
+ALLOCA=alloca.$ac_objext
+
+cat >>confdefs.h <<\_ACEOF
+#define C_ALLOCA 1
+_ACEOF
+
+
+echo "$as_me:$LINENO: checking whether \`alloca.c' needs Cray hooks" >&5
+echo $ECHO_N "checking whether \`alloca.c' needs Cray hooks... $ECHO_C" >&6
+if test "${ac_cv_os_cray+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#if defined(CRAY) && ! defined(CRAY2)
+webecray
+#else
+wenotbecray
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "webecray" >/dev/null 2>&1; then
+  ac_cv_os_cray=yes
+else
+  ac_cv_os_cray=no
+fi
+rm -f conftest*
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_os_cray" >&5
+echo "${ECHO_T}$ac_cv_os_cray" >&6
+if test $ac_cv_os_cray = yes; then
+  for ac_func in _getb67 GETB67 getb67; do
+    as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define CRAY_STACKSEG_END $ac_func
+_ACEOF
+
+    break
+fi
+
+  done
+fi
+
+echo "$as_me:$LINENO: checking stack direction for C alloca" >&5
+echo $ECHO_N "checking stack direction for C alloca... $ECHO_C" >&6
+if test "${ac_cv_c_stack_direction+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  ac_cv_c_stack_direction=0
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+int
+find_stack_direction ()
+{
+  static char *addr = 0;
+  auto char dummy;
+  if (addr == 0)
+    {
+      addr = &dummy;
+      return find_stack_direction ();
+    }
+  else
+    return (&dummy > addr) ? 1 : -1;
+}
+
+int
+main ()
+{
+  exit (find_stack_direction () < 0);
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_c_stack_direction=1
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_c_stack_direction=-1
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_stack_direction" >&5
+echo "${ECHO_T}$ac_cv_c_stack_direction" >&6
+
+cat >>confdefs.h <<_ACEOF
+#define STACK_DIRECTION $ac_cv_c_stack_direction
+_ACEOF
+
+
+fi
+
+if test $ac_cv_c_compiler_gnu = yes; then
+    echo "$as_me:$LINENO: checking whether $CC needs -traditional" >&5
+echo $ECHO_N "checking whether $CC needs -traditional... $ECHO_C" >&6
+if test "${ac_cv_prog_gcc_traditional+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+    ac_pattern="Autoconf.*'x'"
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sgtty.h>
+Autoconf TIOCGETP
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "$ac_pattern" >/dev/null 2>&1; then
+  ac_cv_prog_gcc_traditional=yes
+else
+  ac_cv_prog_gcc_traditional=no
+fi
+rm -f conftest*
+
+
+  if test $ac_cv_prog_gcc_traditional = no; then
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <termio.h>
+Autoconf TCGETA
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "$ac_pattern" >/dev/null 2>&1; then
+  ac_cv_prog_gcc_traditional=yes
+fi
+rm -f conftest*
+
+  fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_gcc_traditional" >&5
+echo "${ECHO_T}$ac_cv_prog_gcc_traditional" >&6
+  if test $ac_cv_prog_gcc_traditional = yes; then
+    CC="$CC -traditional"
+  fi
+fi
+
+echo "$as_me:$LINENO: checking return type of signal handlers" >&5
+echo $ECHO_N "checking return type of signal handlers... $ECHO_C" >&6
+if test "${ac_cv_type_signal+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <signal.h>
+#ifdef signal
+# undef signal
+#endif
+#ifdef __cplusplus
+extern "C" void (*signal (int, void (*)(int)))(int);
+#else
+void (*signal ()) ();
+#endif
+
+int
+main ()
+{
+int i;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type_signal=void
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_signal=int
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_signal" >&5
+echo "${ECHO_T}$ac_cv_type_signal" >&6
+
+cat >>confdefs.h <<_ACEOF
+#define RETSIGTYPE $ac_cv_type_signal
+_ACEOF
+
+
+
+for ac_func in vprintf
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+echo "$as_me:$LINENO: checking for _doprnt" >&5
+echo $ECHO_N "checking for _doprnt... $ECHO_C" >&6
+if test "${ac_cv_func__doprnt+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define _doprnt to an innocuous variant, in case <limits.h> declares _doprnt.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define _doprnt innocuous__doprnt
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char _doprnt (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef _doprnt
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char _doprnt ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub__doprnt) || defined (__stub____doprnt)
+choke me
+#else
+char (*f) () = _doprnt;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != _doprnt;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_func__doprnt=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_func__doprnt=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func__doprnt" >&5
+echo "${ECHO_T}$ac_cv_func__doprnt" >&6
+if test $ac_cv_func__doprnt = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_DOPRNT 1
+_ACEOF
+
+fi
+
+fi
+done
+
+
+
+
+
+
+
+
+
+
+
+
+for ac_func in ftime select strftime strtol getrusage times mallinfo setbuffer getpagesize strerror
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+
+
+for ac_func in ftruncate strstr strcasecmp
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+else
+  case $LIBOBJS in
+    "$ac_func.$ac_objext"   | \
+  *" $ac_func.$ac_objext"   | \
+    "$ac_func.$ac_objext "* | \
+  *" $ac_func.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS $ac_func.$ac_objext" ;;
+esac
+
+fi
+done
+
+
+
+echo "$as_me:$LINENO: checking for textdomain" >&5
+echo $ECHO_N "checking for textdomain... $ECHO_C" >&6
+if test "${ac_cv_func_textdomain+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define textdomain to an innocuous variant, in case <limits.h> declares textdomain.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define textdomain innocuous_textdomain
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char textdomain (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef textdomain
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char textdomain ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_textdomain) || defined (__stub___textdomain)
+choke me
+#else
+char (*f) () = textdomain;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != textdomain;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_func_textdomain=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_func_textdomain=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func_textdomain" >&5
+echo "${ECHO_T}$ac_cv_func_textdomain" >&6
+if test $ac_cv_func_textdomain = yes; then
+  cat >>confdefs.h <<\_ACEOF
+#define ENABLE_NLS  1
+_ACEOF
+
+fi
+
+
+# *** Custom checking (based on GNU tar configure.in) ***
+# ---------------------------------------------------------------------------
+echo "$as_me:$LINENO: checking for HP-UX needing gmalloc" >&5
+echo $ECHO_N "checking for HP-UX needing gmalloc... $ECHO_C" >&6
+if test "`(uname -s) 2> /dev/null`" = 'HP-UX'; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  case $LIBOBJS in
+    "gmalloc.$ac_objext"   | \
+  *" gmalloc.$ac_objext"   | \
+    "gmalloc.$ac_objext "* | \
+  *" gmalloc.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS gmalloc.$ac_objext" ;;
+esac
+
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_VALLOC 1
+_ACEOF
+
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+for ac_func in valloc
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+fi
+
+# we cannot generate static libraries under Darwin
+echo "$as_me:$LINENO: checking for Apple MacOS X/Darwin" >&5
+echo $ECHO_N "checking for Apple MacOS X/Darwin... $ECHO_C" >&6
+if test "`(uname -s) 2> /dev/null`" = 'Darwin'; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  STATIC=""
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+  STATIC="-static "
+fi
+
+
+echo "$as_me:$LINENO: checking if malloc debugging is wanted" >&5
+echo $ECHO_N "checking if malloc debugging is wanted... $ECHO_C" >&6
+
+# Check whether --with-dmalloc or --without-dmalloc was given.
+if test "${with_dmalloc+set}" = set; then
+  withval="$with_dmalloc"
+  if test "$withval" = yes; then
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+  cat >>confdefs.h <<\_ACEOF
+#define WITH_DMALLOC 1
+_ACEOF
+
+  LIBS="$LIBS -ldmalloc"
+  LDFLAGS="$LDFLAGS -g"
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi;
+
+echo "$as_me:$LINENO: checking which of rx or regex is wanted" >&5
+echo $ECHO_N "checking which of rx or regex is wanted... $ECHO_C" >&6
+
+# Check whether --with-regex or --without-regex was given.
+if test "${with_regex+set}" = set; then
+  withval="$with_regex"
+  if test "$withval" = yes; then
+  ac_with_regex=1
+  echo "$as_me:$LINENO: result: regex" >&5
+echo "${ECHO_T}regex" >&6
+  cat >>confdefs.h <<\_ACEOF
+#define WITH_REGEX 1
+_ACEOF
+
+  case $LIBOBJS in
+    "regex.$ac_objext"   | \
+  *" regex.$ac_objext"   | \
+    "regex.$ac_objext "* | \
+  *" regex.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS regex.$ac_objext" ;;
+esac
+
+fi
+fi;
+if test -z "$ac_with_regex"; then
+  echo "$as_me:$LINENO: result: rx" >&5
+echo "${ECHO_T}rx" >&6
+  echo "$as_me:$LINENO: checking for re_rx_search" >&5
+echo $ECHO_N "checking for re_rx_search... $ECHO_C" >&6
+if test "${ac_cv_func_re_rx_search+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define re_rx_search to an innocuous variant, in case <limits.h> declares re_rx_search.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define re_rx_search innocuous_re_rx_search
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char re_rx_search (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef re_rx_search
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char re_rx_search ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_re_rx_search) || defined (__stub___re_rx_search)
+choke me
+#else
+char (*f) () = re_rx_search;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != re_rx_search;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_func_re_rx_search=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_func_re_rx_search=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func_re_rx_search" >&5
+echo "${ECHO_T}$ac_cv_func_re_rx_search" >&6
+if test $ac_cv_func_re_rx_search = yes; then
+  :
+else
+  case $LIBOBJS in
+    "rx.$ac_objext"   | \
+  *" rx.$ac_objext"   | \
+    "rx.$ac_objext "* | \
+  *" rx.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS rx.$ac_objext" ;;
+esac
+
+fi
+
+fi
+
+
+# ---------------------------------------------------------------------------
+if test "$ac_cv_func_alloca" = 'no'; then
+  case $LIBOBJS in
+    "xmalloc.$ac_objext"   | \
+  *" xmalloc.$ac_objext"   | \
+    "xmalloc.$ac_objext "* | \
+  *" xmalloc.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS xmalloc.$ac_objext" ;;
+esac
+
+  case $LIBOBJS in
+    "error.$ac_objext"   | \
+  *" error.$ac_objext"   | \
+    "error.$ac_objext "* | \
+  *" error.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS error.$ac_objext" ;;
+esac
+
+fi
+
+
+# ---------------------------------------------------------------------------
+
+ac_ext=cc
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+
+
+echo "$as_me:$LINENO: checking that the GDBM library is available" >&5
+echo $ECHO_N "checking that the GDBM library is available... $ECHO_C" >&6
+if test ! -z "$gdbmdir" ; then
+  # look in given directory for header file
+  if test -r $gdbmdir/include/gdbm.h ; then
+    GDBM_INCLUDE="-I$gdbmdir/include" ;
+  elif test -r $gdbmdir/gdbm.h ; then
+    GDBM_INCLUDE="-I$gdbmdir" ;
+  fi
+
+  # look in given directory for library
+  if test -r $gdbmdir/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir" ;
+  elif test -r $gdbmdir/lib/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir/lib" ;
+  elif test -r $gdbmdir/.libs/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir/.libs" ;
+  fi
+
+  if test ! -z "$GDBM_LIBPATH" -a ! -z "$GDBM_INCLUDE" ; then
+    echo "$as_me:$LINENO: result: $gdbmdir" >&5
+echo "${ECHO_T}$gdbmdir" >&6 ;
+  else
+    echo "$as_me:$LINENO: result: can't find gdbm.h and libgdbm.a in $gdbmdir" >&5
+echo "${ECHO_T}can't find gdbm.h and libgdbm.a in $gdbmdir" >&6;
+    echo "$as_me:$LINENO: checking looking for GDBM library in default locations" >&5
+echo $ECHO_N "checking looking for GDBM library in default locations... $ECHO_C" >&6
+  fi
+fi
+
+# look in default path and in /usr/local
+if test -z "$GDBM_INCLUDE" ; then
+  # try in system directory
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <gdbm.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  success=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+success=no
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+  if test $success = "no"; then
+# last chance - look in /usr/local (eg FreeBSD)
+    GDBM_LIBPATH=-L/usr/local/lib
+    GDBM_INCLUDE=-I/usr/local/include
+    ac_save_CXXFLAGS="$CXXFLAGS"
+    ac_save_LIBS="$LIBS"
+      CXXFLAGS="$CXXFLAGS -I/usr/local/include"
+      LIBS="$LIBS -L/usr/local/lib -lgdbm"
+      cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <gdbm.h>
+#include <stdio.h>
+
+int
+main ()
+{
+printf("%s",gdbm_version);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  success=/usr/local
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+success=no
+
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+      CXXFLAGS=$ac_save_CXXFLAGS
+      LIBS=$ac_save_LIBS
+  fi
+
+  echo "$as_me:$LINENO: result: $success" >&5
+echo "${ECHO_T}$success" >&6
+  if test $success = "no"; then
+  { { echo "$as_me:$LINENO: error: GDBM Library not available - cannot install" >&5
+echo "$as_me: error: GDBM Library not available - cannot install" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+fi
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_LIBGDBM  1
+_ACEOF
+
+
+
+
+
+echo "$as_me:$LINENO: checking that Perl 5 is available" >&5
+echo $ECHO_N "checking that Perl 5 is available... $ECHO_C" >&6
+success="no"
+pl_path="$PATH"
+IFS="${IFS=   }"; pl_save_ifs="$IFS"; IFS=":"
+for pl_dir in $pl_path; do
+  test -z "$pl_dir" && pl_dir=.
+  if test -x $pl_dir/perl; then
+    success="yes"
+    break
+  fi
+done
+IFS="$pl_save_ifs"
+
+if test $success = "yes"; then
+try=`perl configtest.pl` || try="0"
+try=`expr $try \> 5.000`
+if test $try = "1"; then
+echo "$as_me:$LINENO: result: \"yes\"" >&5
+echo "${ECHO_T}\"yes\"" >&6
+else
+success="no"
+fi
+fi
+
+if test $success = "no"; then
+echo "$as_me:$LINENO: result: \"no\"" >&5
+echo "${ECHO_T}\"no\"" >&6
+{ { echo "$as_me:$LINENO: error: \"Perl 5 not available - cannot install\"" >&5
+echo "$as_me: error: \"Perl 5 not available - cannot install\"" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+success=no
+echo "$as_me:$LINENO: checking \"whether STL library has known faults\"" >&5
+echo $ECHO_N "checking \"whether STL library has known faults\"... $ECHO_C" >&6
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <vector>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  success=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $success = "no"; then
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <vector.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  success="yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+if test $success = "no"; then
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ospace\\std\\vector>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  success="yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+if test $success = yes; then
+echo "$as_me:$LINENO: result: \"no\"" >&5
+echo "${ECHO_T}\"no\"" >&6
+else
+echo "$as_me:$LINENO: result: \"yes\"" >&5
+echo "${ECHO_T}\"yes\"" >&6
+{ { echo "$as_me:$LINENO: error: \"STL Broken - Obtain newer version of GNU C Compiler\"" >&5
+echo "$as_me: error: \"STL Broken - Obtain newer version of GNU C Compiler\"" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+gsdlos=`uname | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
+# check for running bash under cygwin
+ if test "`echo $gsdlos | sed 's/cygwin//'`" != "$gsdlos" ;
+ then
+  gsdlos=windows
+ fi
+
+
+# check for endianness
+echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5
+echo $ECHO_N "checking whether byte ordering is bigendian... $ECHO_C" >&6
+if test "${ac_cv_c_bigendian+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  # See if sys/param.h defines the BYTE_ORDER macro.
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/param.h>
+
+int
+main ()
+{
+#if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
+ bogus endian macros
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  # It does; now see whether it defined to BIG_ENDIAN or not.
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/param.h>
+
+int
+main ()
+{
+#if BYTE_ORDER != BIG_ENDIAN
+ not big endian
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_c_bigendian=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_c_bigendian=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+# It does not; compile a test program.
+if test "$cross_compiling" = yes; then
+  # try to guess the endianness by grepping values into an object file
+  ac_cv_c_bigendian=unknown
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+short ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
+short ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
+void _ascii () { char *s = (char *) ascii_mm; s = (char *) ascii_ii; }
+short ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
+short ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
+void _ebcdic () { char *s = (char *) ebcdic_mm; s = (char *) ebcdic_ii; }
+int
+main ()
+{
+ _ascii (); _ebcdic ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_cxx_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  if grep BIGenDianSyS conftest.$ac_objext >/dev/null ; then
+  ac_cv_c_bigendian=yes
+fi
+if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
+  if test "$ac_cv_c_bigendian" = unknown; then
+    ac_cv_c_bigendian=no
+  else
+    # finding both strings is unlikely to happen, but who knows?
+    ac_cv_c_bigendian=unknown
+  fi
+fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+int
+main ()
+{
+  /* Are we little or big endian?  From Harbison&Steele.  */
+  union
+  {
+    long l;
+    char c[sizeof (long)];
+  } u;
+  u.l = 1;
+  exit (u.c[sizeof (long) - 1] == 1);
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_c_bigendian=no
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_c_bigendian=yes
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_bigendian" >&5
+echo "${ECHO_T}$ac_cv_c_bigendian" >&6
+case $ac_cv_c_bigendian in
+  yes)
+
+cat >>confdefs.h <<\_ACEOF
+#define WORDS_BIGENDIAN 1
+_ACEOF
+ ;;
+  no)
+     ;;
+  *)
+    { { echo "$as_me:$LINENO: error: unknown endianness
+presetting ac_cv_c_bigendian=no (or yes) will help" >&5
+echo "$as_me: error: unknown endianness
+presetting ac_cv_c_bigendian=no (or yes) will help" >&2;}
+   { (exit 1); exit 1; }; } ;;
+esac
+
+# ---------------------------------------------------------------------------
+if test "$ac_cv_func_alloca" = 'no'; then
+  case $LIBOBJS in
+    "xmalloc.o.$ac_objext"   | \
+  *" xmalloc.o.$ac_objext"   | \
+    "xmalloc.o.$ac_objext "* | \
+  *" xmalloc.o.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS xmalloc.o.$ac_objext" ;;
+esac
+
+  case $LIBOBJS in
+    "error.$ac_objext"   | \
+  *" error.$ac_objext"   | \
+    "error.$ac_objext "* | \
+  *" error.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS error.$ac_objext" ;;
+esac
+
+fi
+
+# ---------------------------------------------------------------------------
+
+
+moduleDirs=""
+MODULEDIRS=""
+if  -d modules  ; then
+  for x in `find modules -mindepth 1 -maxdepth 2`; do
+    if test -d "$x"; then
+      d="$x/Makefile.in"
+      if test -e "$d"; then
+          moduleDirs="$moduleDirs $x/Makefile"
+        MODULEDIRS="$MODULEDIRS $x"
+      fi
+    fi
+  done
+  echo "Making $moduleDirs in modules directory"
+
+fi
+
+
+
+
+subdirs="$subdirs packages"
+
+
+# the list of folders in the src folder
+srclist="src/colservr/Makefile \
+         src/corba/Makefile \
+         src/protocol/Makefile \
+         src/recpt/Makefile \
+         src/oaiservr/Makefile \
+         src/z3950/Makefile"
+
+                                        ac_config_files="$ac_config_files packages/Makefile Makefile $srclist $moduleDirs"
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, don't put newlines in cache variables' values.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+{
+  (set) 2>&1 |
+    case `(ac_space=' '; set | grep ac_space) 2>&1` in
+    *ac_space=\ *)
+      # `set' does not quote correctly, so add quotes (double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \).
+      sed -n \
+	"s/'/'\\\\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;;
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n \
+	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+      ;;
+    esac;
+} |
+  sed '
+     t clear
+     : clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     : end' >>confcache
+if diff $cache_file confcache >/dev/null 2>&1; then :; else
+  if test -w $cache_file; then
+    test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file"
+    cat confcache >$cache_file
+  else
+    echo "not updating unwritable cache $cache_file"
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
+s/:*\$(srcdir):*/:/;
+s/:*\${srcdir}:*/:/;
+s/:*@srcdir@:*/:/;
+s/^\([^=]*=[	 ]*\):*/\1/;
+s/:*$//;
+s/^[^=]*=[	 ]*$//;
+}'
+fi
+
+DEFS=-DHAVE_CONFIG_H
+
+ac_libobjs=
+ac_ltlibobjs=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_i=`echo "$ac_i" |
+	 sed 's/\$U\././;s/\.o$//;s/\.obj$//'`
+  # 2. Add them.
+  ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext"
+  ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+
+: ${CONFIG_STATUS=./config.status}
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5
+echo "$as_me: creating $CONFIG_STATUS" >&6;}
+cat >$CONFIG_STATUS <<_ACEOF
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+SHELL=\${CONFIG_SHELL-$SHELL}
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+  set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+  LC_TELEPHONE LC_TIME
+do
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+    eval $as_var=C; export $as_var
+  else
+    $as_unset $as_var
+  fi
+done
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)$' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\/\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+
+
+# PATH needs CR, and LINENO needs CR and PATH.
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
+  # Find who we are.  Look in the path if we contain no path at all
+  # relative or not.
+  case $0 in
+    *[\\/]* ) as_myself=$0 ;;
+    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+
+       ;;
+  esac
+  # We did not find ourselves, most probably we were run as `sh COMMAND'
+  # in which case we are not to be found in the path.
+  if test "x$as_myself" = x; then
+    as_myself=$0
+  fi
+  if test ! -f "$as_myself"; then
+    { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5
+echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+  case $CONFIG_SHELL in
+  '')
+    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for as_base in sh bash ksh sh5; do
+	 case $as_dir in
+	 /*)
+	   if ("$as_dir/$as_base" -c '
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
+	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
+	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
+	     CONFIG_SHELL=$as_dir/$as_base
+	     export CONFIG_SHELL
+	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
+	   fi;;
+	 esac
+       done
+done
+;;
+  esac
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line before each line; the second 'sed' does the real
+  # work.  The second script uses 'N' to pair each line-number line
+  # with the numbered line, and appends trailing '-' during
+  # substitution so that $LINENO is not a special case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
+  sed '=' <$as_myself |
+    sed '
+      N
+      s,$,-,
+      : loop
+      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+      t loop
+      s,-$,,
+      s,^['$as_cr_digits']*\n,,
+    ' >$as_me.lineno &&
+  chmod +x $as_me.lineno ||
+    { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5
+echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;}
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensible to this).
+  . ./$as_me.lineno
+  # Exit status is that of the last command.
+  exit
+}
+
+
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+  *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T='	' ;;
+  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+echo >conf$$.file
+if ln -s conf$$.file conf$$ 2>/dev/null; then
+  # We could just check for DJGPP; but this test a) works b) is more generic
+  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
+  if test -f conf$$.exe; then
+    # Don't use ln at all; we don't have any links
+    as_ln_s='cp -p'
+  else
+    as_ln_s='ln -s'
+  fi
+elif ln conf$$.file conf$$ 2>/dev/null; then
+  as_ln_s=ln
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.file
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p=:
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_executable_p="test -f"
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.
+as_nl='
+'
+IFS=" 	$as_nl"
+
+# CDPATH.
+$as_unset CDPATH
+
+exec 6>&1
+
+# Open the log real soon, to keep \$[0] and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.  Logging --version etc. is OK.
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+} >&5
+cat >&5 <<_CSEOF
+
+This file was extended by $as_me, which was
+generated by GNU Autoconf 2.59.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+_CSEOF
+echo "on `(hostname || uname -n) 2>/dev/null | sed 1q`" >&5
+echo >&5
+_ACEOF
+
+# Files that config.status was made for.
+if test -n "$ac_config_files"; then
+  echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_headers"; then
+  echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_links"; then
+  echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_commands"; then
+  echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+ac_cs_usage="\
+\`$as_me' instantiates files from templates according to the
+current configuration.
+
+Usage: $0 [OPTIONS] [FILE]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number, then exit
+  -q, --quiet      do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+  --file=FILE[:TEMPLATE]
+		   instantiate the configuration file FILE
+  --header=FILE[:TEMPLATE]
+		   instantiate the configuration header FILE
+
+Configuration files:
+$config_files
+
+Configuration headers:
+$config_headers
+
+Report bugs to <bug-autoconf@gnu.org>."
+_ACEOF
+
+cat >>$CONFIG_STATUS <<_ACEOF
+ac_cs_version="\\
+config.status
+configured by $0, generated by GNU Autoconf 2.59,
+  with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
+
+Copyright (C) 2003 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+srcdir=$srcdir
+INSTALL="$INSTALL"
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+# If no file are specified by the user, then we need to provide default
+# value.  By we need to know if files were specified by the user.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=*)
+    ac_option=`expr "x$1" : 'x\([^=]*\)='`
+    ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  -*)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  *) # This is not an option, so the user has probably given explicit
+     # arguments.
+     ac_option=$1
+     ac_need_defaults=false;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --vers* | -V )
+    echo "$ac_cs_version"; exit 0 ;;
+  --he | --h)
+    # Conflict between --help and --header
+    { { echo "$as_me:$LINENO: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&5
+echo "$as_me: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&2;}
+   { (exit 1); exit 1; }; };;
+  --help | --hel | -h )
+    echo "$ac_cs_usage"; exit 0 ;;
+  --debug | --d* | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    CONFIG_FILES="$CONFIG_FILES $ac_optarg"
+    ac_need_defaults=false;;
+  --header | --heade | --head | --hea )
+    $ac_shift
+    CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg"
+    ac_need_defaults=false;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) { { echo "$as_me:$LINENO: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&5
+echo "$as_me: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&2;}
+   { (exit 1); exit 1; }; } ;;
+
+  *) ac_config_targets="$ac_config_targets $1" ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF
+if \$ac_cs_recheck; then
+  echo "running $SHELL $0 " $ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6
+  exec $SHELL $0 $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+fi
+
+_ACEOF
+
+
+
+
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+for ac_config_target in $ac_config_targets
+do
+  case "$ac_config_target" in
+  # Handling of arguments.
+  "packages/Makefile" ) CONFIG_FILES="$CONFIG_FILES packages/Makefile" ;;
+  "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+  "$srclist" ) CONFIG_FILES="$CONFIG_FILES $srclist" ;;
+  "$moduleDirs" ) CONFIG_FILES="$CONFIG_FILES $moduleDirs" ;;
+  "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
+  *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
+echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason to put it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Create a temporary directory, and hook for its removal unless debugging.
+$debug ||
+{
+  trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0
+  trap '{ (exit 1); exit 1; }' 1 2 13 15
+}
+
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
+  test -n "$tmp" && test -d "$tmp"
+}  ||
+{
+  tmp=./confstat$$-$RANDOM
+  (umask 077 && mkdir $tmp)
+} ||
+{
+   echo "$me: cannot create a temporary directory in ." >&2
+   { (exit 1); exit 1; }
+}
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<_ACEOF
+
+#
+# CONFIG_FILES section.
+#
+
+# No need to generate the scripts if there are no CONFIG_FILES.
+# This happens for instance when ./config.status config.h
+if test -n "\$CONFIG_FILES"; then
+  # Protect against being on the right side of a sed subst in config.status.
+  sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g;
+   s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF
+s,@SHELL@,$SHELL,;t t
+s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t
+s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t
+s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t
+s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t
+s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t
+s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t
+s,@exec_prefix@,$exec_prefix,;t t
+s,@prefix@,$prefix,;t t
+s,@program_transform_name@,$program_transform_name,;t t
+s,@bindir@,$bindir,;t t
+s,@sbindir@,$sbindir,;t t
+s,@libexecdir@,$libexecdir,;t t
+s,@datadir@,$datadir,;t t
+s,@sysconfdir@,$sysconfdir,;t t
+s,@sharedstatedir@,$sharedstatedir,;t t
+s,@localstatedir@,$localstatedir,;t t
+s,@libdir@,$libdir,;t t
+s,@includedir@,$includedir,;t t
+s,@oldincludedir@,$oldincludedir,;t t
+s,@infodir@,$infodir,;t t
+s,@mandir@,$mandir,;t t
+s,@build_alias@,$build_alias,;t t
+s,@host_alias@,$host_alias,;t t
+s,@target_alias@,$target_alias,;t t
+s,@DEFS@,$DEFS,;t t
+s,@ECHO_C@,$ECHO_C,;t t
+s,@ECHO_N@,$ECHO_N,;t t
+s,@ECHO_T@,$ECHO_T,;t t
+s,@LIBS@,$LIBS,;t t
+s,@PACKAGE@,$PACKAGE,;t t
+s,@VERSION@,$VERSION,;t t
+s,@USE_FASTCGI@,$USE_FASTCGI,;t t
+s,@USE_LANGACTION@,$USE_LANGACTION,;t t
+s,@USE_CORBA@,$USE_CORBA,;t t
+s,@MICO_DIR@,$MICO_DIR,;t t
+s,@USE_Z3950@,$USE_Z3950,;t t
+s,@USE_YAZ@,$USE_YAZ,;t t
+s,@ENABLE_ACCENTFOLD@,$ENABLE_ACCENTFOLD,;t t
+s,@USE_SQLITE@,$USE_SQLITE,;t t
+s,@LDFLAGS@,$LDFLAGS,;t t
+s,@CFLAGS@,$CFLAGS,;t t
+s,@CC@,$CC,;t t
+s,@CPPFLAGS@,$CPPFLAGS,;t t
+s,@ac_ct_CC@,$ac_ct_CC,;t t
+s,@EXEEXT@,$EXEEXT,;t t
+s,@OBJEXT@,$OBJEXT,;t t
+s,@CXX@,$CXX,;t t
+s,@CXXFLAGS@,$CXXFLAGS,;t t
+s,@ac_ct_CXX@,$ac_ct_CXX,;t t
+s,@AWK@,$AWK,;t t
+s,@YACC@,$YACC,;t t
+s,@build@,$build,;t t
+s,@build_cpu@,$build_cpu,;t t
+s,@build_vendor@,$build_vendor,;t t
+s,@build_os@,$build_os,;t t
+s,@host@,$host,;t t
+s,@host_cpu@,$host_cpu,;t t
+s,@host_vendor@,$host_vendor,;t t
+s,@host_os@,$host_os,;t t
+s,@target@,$target,;t t
+s,@target_cpu@,$target_cpu,;t t
+s,@target_vendor@,$target_vendor,;t t
+s,@target_os@,$target_os,;t t
+s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t
+s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t
+s,@INSTALL_DATA@,$INSTALL_DATA,;t t
+s,@LN_S@,$LN_S,;t t
+s,@SET_MAKE@,$SET_MAKE,;t t
+s,@RANLIB@,$RANLIB,;t t
+s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t
+s,@COMPAT32BITFLAGS@,$COMPAT32BITFLAGS,;t t
+s,@MICO_VER@,$MICO_VER,;t t
+s,@CPP@,$CPP,;t t
+s,@EGREP@,$EGREP,;t t
+s,@U@,$U,;t t
+s,@ANSI2KNR@,$ANSI2KNR,;t t
+s,@ALLOCA@,$ALLOCA,;t t
+s,@LIBOBJS@,$LIBOBJS,;t t
+s,@STATIC@,$STATIC,;t t
+s,@GDBM_LIBPATH@,$GDBM_LIBPATH,;t t
+s,@GDBM_INCLUDE@,$GDBM_INCLUDE,;t t
+s,@gsdlos@,$gsdlos,;t t
+s,@MODULEDIRS@,$MODULEDIRS,;t t
+s,@subdirs@,$subdirs,;t t
+s,@LTLIBOBJS@,$LTLIBOBJS,;t t
+CEOF
+
+_ACEOF
+
+  cat >>$CONFIG_STATUS <<\_ACEOF
+  # Split the substitutions into bite-sized pieces for seds with
+  # small command number limits, like on Digital OSF/1 and HP-UX.
+  ac_max_sed_lines=48
+  ac_sed_frag=1 # Number of current file.
+  ac_beg=1 # First line for current file.
+  ac_end=$ac_max_sed_lines # Line after last line for current file.
+  ac_more_lines=:
+  ac_sed_cmds=
+  while $ac_more_lines; do
+    if test $ac_beg -gt 1; then
+      sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
+    else
+      sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
+    fi
+    if test ! -s $tmp/subs.frag; then
+      ac_more_lines=false
+    else
+      # The purpose of the label and of the branching condition is to
+      # speed up the sed processing (if there are no `@' at all, there
+      # is no need to browse any of the substitutions).
+      # These are the two extra sed commands mentioned above.
+      (echo ':t
+  /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed
+      if test -z "$ac_sed_cmds"; then
+	ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed"
+      else
+	ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed"
+      fi
+      ac_sed_frag=`expr $ac_sed_frag + 1`
+      ac_beg=$ac_end
+      ac_end=`expr $ac_end + $ac_max_sed_lines`
+    fi
+  done
+  if test -z "$ac_sed_cmds"; then
+    ac_sed_cmds=cat
+  fi
+fi # test -n "$CONFIG_FILES"
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case $ac_file in
+  - | *:- | *:-:* ) # input from stdin
+	cat >$tmp/stdin
+	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  * )   ac_file_in=$ac_file.in ;;
+  esac
+
+  # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories.
+  ac_dir=`(dirname "$ac_file") 2>/dev/null ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+  { if $as_mkdir_p; then
+    mkdir -p "$ac_dir"
+  else
+    as_dir="$ac_dir"
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+   { (exit 1); exit 1; }; }; }
+
+  ac_builddir=.
+
+if test "$ac_dir" != .; then
+  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  # A "../" for each directory in $ac_dir_suffix.
+  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+  ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+  .)  # No --srcdir option.  We are building in place.
+    ac_srcdir=.
+    if test -z "$ac_top_builddir"; then
+       ac_top_srcdir=.
+    else
+       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+    fi ;;
+  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir ;;
+  *) # Relative path.
+    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
+
+
+  case $INSTALL in
+  [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+  *) ac_INSTALL=$ac_top_builddir$INSTALL ;;
+  esac
+
+  if test x"$ac_file" != x-; then
+    { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+    rm -f "$ac_file"
+  fi
+  # Let's still pretend it is `configure' which instantiates (i.e., don't
+  # use $as_me), people would be surprised to read:
+  #    /* config.h.  Generated by config.status.  */
+  if test x"$ac_file" = x-; then
+    configure_input=
+  else
+    configure_input="$ac_file.  "
+  fi
+  configure_input=$configure_input"Generated from `echo $ac_file_in |
+				     sed 's,.*/,,'` by configure."
+
+  # First look for the input files in the build tree, otherwise in the
+  # src tree.
+  ac_file_inputs=`IFS=:
+    for f in $ac_file_in; do
+      case $f in
+      -) echo $tmp/stdin ;;
+      [\\/$]*)
+	 # Absolute (can't be DOS-style, as IFS=:)
+	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 echo "$f";;
+      *) # Relative
+	 if test -f "$f"; then
+	   # Build tree
+	   echo "$f"
+	 elif test -f "$srcdir/$f"; then
+	   # Source tree
+	   echo "$srcdir/$f"
+	 else
+	   # /dev/null tree
+	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 fi;;
+      esac
+    done` || { (exit 1); exit 1; }
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF
+  sed "$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s,@configure_input@,$configure_input,;t t
+s,@srcdir@,$ac_srcdir,;t t
+s,@abs_srcdir@,$ac_abs_srcdir,;t t
+s,@top_srcdir@,$ac_top_srcdir,;t t
+s,@abs_top_srcdir@,$ac_abs_top_srcdir,;t t
+s,@builddir@,$ac_builddir,;t t
+s,@abs_builddir@,$ac_abs_builddir,;t t
+s,@top_builddir@,$ac_top_builddir,;t t
+s,@abs_top_builddir@,$ac_abs_top_builddir,;t t
+s,@INSTALL@,$ac_INSTALL,;t t
+" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out
+  rm -f $tmp/stdin
+  if test x"$ac_file" != x-; then
+    mv $tmp/out $ac_file
+  else
+    cat $tmp/out
+    rm -f $tmp/out
+  fi
+
+done
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+#
+# CONFIG_HEADER section.
+#
+
+# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where
+# NAME is the cpp macro being defined and VALUE is the value it is being given.
+#
+# ac_d sets the value in "#define NAME VALUE" lines.
+ac_dA='s,^\([	 ]*\)#\([	 ]*define[	 ][	 ]*\)'
+ac_dB='[	 ].*$,\1#\2'
+ac_dC=' '
+ac_dD=',;t'
+# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
+ac_uA='s,^\([	 ]*\)#\([	 ]*\)undef\([	 ][	 ]*\)'
+ac_uB='$,\1#\2define\3'
+ac_uC=' '
+ac_uD=',;t'
+
+for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case $ac_file in
+  - | *:- | *:-:* ) # input from stdin
+	cat >$tmp/stdin
+	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  * )   ac_file_in=$ac_file.in ;;
+  esac
+
+  test x"$ac_file" != x- && { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+
+  # First look for the input files in the build tree, otherwise in the
+  # src tree.
+  ac_file_inputs=`IFS=:
+    for f in $ac_file_in; do
+      case $f in
+      -) echo $tmp/stdin ;;
+      [\\/$]*)
+	 # Absolute (can't be DOS-style, as IFS=:)
+	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 # Do quote $f, to prevent DOS paths from being IFS'd.
+	 echo "$f";;
+      *) # Relative
+	 if test -f "$f"; then
+	   # Build tree
+	   echo "$f"
+	 elif test -f "$srcdir/$f"; then
+	   # Source tree
+	   echo "$srcdir/$f"
+	 else
+	   # /dev/null tree
+	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 fi;;
+      esac
+    done` || { (exit 1); exit 1; }
+  # Remove the trailing spaces.
+  sed 's/[	 ]*$//' $ac_file_inputs >$tmp/in
+
+_ACEOF
+
+# Transform confdefs.h into two sed scripts, `conftest.defines' and
+# `conftest.undefs', that substitutes the proper values into
+# config.h.in to produce config.h.  The first handles `#define'
+# templates, and the second `#undef' templates.
+# And first: Protect against being on the right side of a sed subst in
+# config.status.  Protect against being in an unquoted here document
+# in config.status.
+rm -f conftest.defines conftest.undefs
+# Using a here document instead of a string reduces the quoting nightmare.
+# Putting comments in sed scripts is not portable.
+#
+# `end' is used to avoid that the second main sed command (meant for
+# 0-ary CPP macros) applies to n-ary macro definitions.
+# See the Autoconf documentation for `clear'.
+cat >confdef2sed.sed <<\_ACEOF
+s/[\\&,]/\\&/g
+s,[\\$`],\\&,g
+t clear
+: clear
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*\)\(([^)]*)\)[	 ]*\(.*\)$,${ac_dA}\1${ac_dB}\1\2${ac_dC}\3${ac_dD},gp
+t end
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp
+: end
+_ACEOF
+# If some macros were called several times there might be several times
+# the same #defines, which is useless.  Nevertheless, we may not want to
+# sort them, since we want the *last* AC-DEFINE to be honored.
+uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines
+sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs
+rm -f confdef2sed.sed
+
+# This sed command replaces #undef with comments.  This is necessary, for
+# example, in the case of _POSIX_SOURCE, which is predefined and required
+# on some systems where configure will not decide to define it.
+cat >>conftest.undefs <<\_ACEOF
+s,^[	 ]*#[	 ]*undef[	 ][	 ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,
+_ACEOF
+
+# Break up conftest.defines because some shells have a limit on the size
+# of here documents, and old seds have small limits too (100 cmds).
+echo '  # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS
+echo '  if grep "^[	 ]*#[	 ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS
+echo '  # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS
+echo '  :' >>$CONFIG_STATUS
+rm -f conftest.tail
+while grep . conftest.defines >/dev/null
+do
+  # Write a limited-size here document to $tmp/defines.sed.
+  echo '  cat >$tmp/defines.sed <<CEOF' >>$CONFIG_STATUS
+  # Speed up: don't consider the non `#define' lines.
+  echo '/^[	 ]*#[	 ]*define/!b' >>$CONFIG_STATUS
+  # Work around the forget-to-reset-the-flag bug.
+  echo 't clr' >>$CONFIG_STATUS
+  echo ': clr' >>$CONFIG_STATUS
+  sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS
+  echo 'CEOF
+  sed -f $tmp/defines.sed $tmp/in >$tmp/out
+  rm -f $tmp/in
+  mv $tmp/out $tmp/in
+' >>$CONFIG_STATUS
+  sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail
+  rm -f conftest.defines
+  mv conftest.tail conftest.defines
+done
+rm -f conftest.defines
+echo '  fi # grep' >>$CONFIG_STATUS
+echo >>$CONFIG_STATUS
+
+# Break up conftest.undefs because some shells have a limit on the size
+# of here documents, and old seds have small limits too (100 cmds).
+echo '  # Handle all the #undef templates' >>$CONFIG_STATUS
+rm -f conftest.tail
+while grep . conftest.undefs >/dev/null
+do
+  # Write a limited-size here document to $tmp/undefs.sed.
+  echo '  cat >$tmp/undefs.sed <<CEOF' >>$CONFIG_STATUS
+  # Speed up: don't consider the non `#undef'
+  echo '/^[	 ]*#[	 ]*undef/!b' >>$CONFIG_STATUS
+  # Work around the forget-to-reset-the-flag bug.
+  echo 't clr' >>$CONFIG_STATUS
+  echo ': clr' >>$CONFIG_STATUS
+  sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS
+  echo 'CEOF
+  sed -f $tmp/undefs.sed $tmp/in >$tmp/out
+  rm -f $tmp/in
+  mv $tmp/out $tmp/in
+' >>$CONFIG_STATUS
+  sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail
+  rm -f conftest.undefs
+  mv conftest.tail conftest.undefs
+done
+rm -f conftest.undefs
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+  # Let's still pretend it is `configure' which instantiates (i.e., don't
+  # use $as_me), people would be surprised to read:
+  #    /* config.h.  Generated by config.status.  */
+  if test x"$ac_file" = x-; then
+    echo "/* Generated by configure.  */" >$tmp/config.h
+  else
+    echo "/* $ac_file.  Generated by configure.  */" >$tmp/config.h
+  fi
+  cat $tmp/in >>$tmp/config.h
+  rm -f $tmp/in
+  if test x"$ac_file" != x-; then
+    if diff $ac_file $tmp/config.h >/dev/null 2>&1; then
+      { echo "$as_me:$LINENO: $ac_file is unchanged" >&5
+echo "$as_me: $ac_file is unchanged" >&6;}
+    else
+      ac_dir=`(dirname "$ac_file") 2>/dev/null ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+      { if $as_mkdir_p; then
+    mkdir -p "$ac_dir"
+  else
+    as_dir="$ac_dir"
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+   { (exit 1); exit 1; }; }; }
+
+      rm -f $ac_file
+      mv $tmp/config.h $ac_file
+    fi
+  else
+    cat $tmp/config.h
+    rm -f $tmp/config.h
+  fi
+done
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+{ (exit 0); exit 0; }
+_ACEOF
+chmod +x $CONFIG_STATUS
+ac_clean_files=$ac_clean_files_save
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || { (exit 1); exit 1; }
+fi
+
+#
+# CONFIG_SUBDIRS section.
+#
+if test "$no_recursion" != yes; then
+
+  # Remove --cache-file and --srcdir arguments so they do not pile up.
+  ac_sub_configure_args=
+  ac_prev=
+  for ac_arg in $ac_configure_args; do
+    if test -n "$ac_prev"; then
+      ac_prev=
+      continue
+    fi
+    case $ac_arg in
+    -cache-file | --cache-file | --cache-fil | --cache-fi \
+    | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+      ac_prev=cache_file ;;
+    -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+    | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* \
+    | --c=*)
+      ;;
+    --config-cache | -C)
+      ;;
+    -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+      ac_prev=srcdir ;;
+    -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+      ;;
+    -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+      ac_prev=prefix ;;
+    -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+      ;;
+    *) ac_sub_configure_args="$ac_sub_configure_args $ac_arg" ;;
+    esac
+  done
+
+  # Always prepend --prefix to ensure using the same prefix
+  # in subdir configurations.
+  ac_sub_configure_args="--prefix=$prefix $ac_sub_configure_args"
+
+  ac_popdir=`pwd`
+  for ac_dir in : $subdirs; do test "x$ac_dir" = x: && continue
+
+    # Do not complain, so a configure script can configure whichever
+    # parts of a large source tree are present.
+    test -d $srcdir/$ac_dir || continue
+
+    { echo "$as_me:$LINENO: configuring in $ac_dir" >&5
+echo "$as_me: configuring in $ac_dir" >&6;}
+    { if $as_mkdir_p; then
+    mkdir -p "$ac_dir"
+  else
+    as_dir="$ac_dir"
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+   { (exit 1); exit 1; }; }; }
+
+    ac_builddir=.
+
+if test "$ac_dir" != .; then
+  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  # A "../" for each directory in $ac_dir_suffix.
+  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+  ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+  .)  # No --srcdir option.  We are building in place.
+    ac_srcdir=.
+    if test -z "$ac_top_builddir"; then
+       ac_top_srcdir=.
+    else
+       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+    fi ;;
+  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir ;;
+  *) # Relative path.
+    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
+
+
+    cd $ac_dir
+
+    # Check for guested configure; otherwise get Cygnus style configure.
+    if test -f $ac_srcdir/configure.gnu; then
+      ac_sub_configure="$SHELL '$ac_srcdir/configure.gnu'"
+    elif test -f $ac_srcdir/configure; then
+      ac_sub_configure="$SHELL '$ac_srcdir/configure'"
+    elif test -f $ac_srcdir/configure.in; then
+      ac_sub_configure=$ac_configure
+    else
+      { echo "$as_me:$LINENO: WARNING: no configuration information is in $ac_dir" >&5
+echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2;}
+      ac_sub_configure=
+    fi
+
+    # The recursion is here.
+    if test -n "$ac_sub_configure"; then
+      # Make the cache file name correct relative to the subdirectory.
+      case $cache_file in
+      [\\/]* | ?:[\\/]* ) ac_sub_cache_file=$cache_file ;;
+      *) # Relative path.
+	ac_sub_cache_file=$ac_top_builddir$cache_file ;;
+      esac
+
+      { echo "$as_me:$LINENO: running $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&5
+echo "$as_me: running $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&6;}
+      # The eval makes quoting arguments work.
+      eval $ac_sub_configure $ac_sub_configure_args \
+	   --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir ||
+	{ { echo "$as_me:$LINENO: error: $ac_sub_configure failed for $ac_dir" >&5
+echo "$as_me: error: $ac_sub_configure failed for $ac_dir" >&2;}
+   { (exit 1); exit 1; }; }
+    fi
+
+    cd $ac_popdir
+  done
+fi
+
+
+
Index: /gsdl/trunk/runtime-src/configure.in
===================================================================
--- /gsdl/trunk/runtime-src/configure.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/configure.in	(revision 16571)
@@ -0,0 +1,441 @@
+dnl Process this file with autoconf to produce a configure script.
+dnl Use autoconf-2.59 or later... it might not work anymore with
+dnl the older 2.1x versions - jrm21 12/2004
+AC_INIT()
+AC_CONFIG_HEADER(config.h)
+
+
+
+PACKAGE=gsdl
+VERSION=2.82-svn
+AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
+AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
+AC_SUBST(PACKAGE)
+AC_SUBST(VERSION)
+
+dnl
+dnl Set use of fast cgi
+dnl
+USE_FASTCGI=0
+if test USE_FASTCGI = 1; then
+AC_DEFINE(USE_FASTCGI)
+AC_SUBST(USE_FASTCGI)
+fi
+
+dnl
+dnl Set use of langaction
+dnl
+dnl USE_LANGACTION=0
+if test USE_LANGACTION = 1; then
+AC_DEFINE(USE_LANGACTION)
+AC_SUBST(USE_LANGACTION)
+fi
+
+dnl
+dnl Set use of corba
+dnl
+AC_ARG_ENABLE(corba, [  --enable-corba          Enable CORBA support], USE_CORBA=1, USE_CORBA=0)
+AC_DEFINE_UNQUOTED(USE_CORBA, $USE_CORBA)
+AC_SUBST(USE_CORBA)
+
+AC_ARG_WITH(micodir, [  --with-micodir          Use installed MICO directory], MICO_DIR=$enableval, MICO_DIR="default")
+AC_DEFINE_UNQUOTED(MICO_DIR, "$MICO_DIR")
+AC_SUBST(MICO_DIR)
+
+dnl
+dnl Set use of z39.50
+dnl
+AC_ARG_ENABLE(z3950, [  --enable-z3950          Enable Z39.50 client support], USE_Z3950=1, USE_Z3950=0)
+if test USE_Z3950 = 1; then
+AC_DEFINE(USE_Z3950, $USE_Z3950)
+AC_SUBST(USE_Z3950)
+fi
+
+dnl
+dnl Set use of yaz - now compiled by default even when z3950 support not required
+dnl
+AC_ARG_ENABLE(yaz, [  --disable-yaz           Disable YAZ compilation], USE_YAZ=0, USE_YAZ=1)
+dnl if test USE_YAZ = 1; then
+AC_DEFINE(USE_YAZ, $USE_YAZ)
+AC_SUBST(USE_YAZ)
+dnl fi
+
+dnl
+dnl look for libgdbm if not in standard location
+dnl
+AC_ARG_WITH(gdbm, [  --with-gdbm=dir         Use local gdbm library and headers], gdbmdir=$withval)
+
+dnl 
+dnl disable compilation of accent folding stuff for mgpp (and one day mg)
+dnl
+AC_ARG_ENABLE(accentfold, [  --disable-accentfold    Disable Accent Folding for MGPP], ENABLE_ACCENTFOLD=0, ENABLE_ACCENTFOLD=1)
+AC_DEFINE(ENABLE_ACCENTFOLD, $ENABLE_ACCENTFOLD)
+AC_SUBST(ENABLE_ACCENTFOLD)
+
+dnl
+dnl Set use of SQLite (enabled by default)
+dnl
+AC_ARG_ENABLE(sqlite, [  --disable-sqlite        Disable SQLite support], USE_SQLITE=0, USE_SQLITE=1)
+AC_DEFINE(USE_SQLITE, $USE_SQLITE)
+AC_SUBST(USE_SQLITE)
+
+dnl Checks for programs.
+LDFLAGS=$LDFLAGS
+AC_SUBST(LDFLAGS)
+dnl only set CFLAGS if not already set in environment
+if test -z "$CFLAGS"; then
+CFLAGS=-O2
+fi
+AC_SUBST(CFLAGS)
+
+
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_AWK
+AC_PROG_YACC
+dnl get $target_cpu, $target_vendor, and $target_os
+dnl (as well as host_*)
+AC_CANONICAL_SYSTEM
+dnl do we actually want this? It adds a prefix based on host, system etc
+dnl AC_ARG_PROGRAM
+AC_PROG_INSTALL
+AC_PROG_LN_S
+AC_PROG_MAKE_SET
+AC_PROG_RANLIB
+
+AC_MSG_CHECKING(to see if architecture is 64-bit)
+arch_64bit=no
+case "$host_cpu" in
+x86_64) arch_64bit=yes ;;
+esac
+
+if test "$arch_64bit" = yes; then
+  AC_MSG_RESULT(yes)
+  if test -z "$COMPAT32BITFLAGS" ; then
+    COMPAT32BITFLAGS="-m32"
+  fi
+else
+  AC_MSG_RESULT(no)
+  if test -z "$COMPAT32BITFLAGS" ; then
+    COMPAT32BITFLAGS=
+  fi
+fi
+export COMPAT32BITFLAGS
+AC_SUBST(COMPAT32BITFLAGS)
+
+
+#moved CORBA MICO directory test to get version of MICO
+if test $USE_CORBA = 1; then
+
+if test $MICO_DIR = "default"; then
+#do something
+MICO_INC="-I packages/mico/mico/include"
+else
+#build the micotest program
+MICO_INC= ""
+if test $MICO_DIR != yes; then
+MICO_INC="-I $MICO_DIR"
+fi
+fi
+
+#get MICO_VER value
+sh -c "$CC -c micotest.cpp -o micotest.o $MICO_INC 2>&1" > /dev/null
+sh -c "$CC -o micotest micotest.o -lstdc++ 2>&1" > /dev/null
+MICO_VER=`./micotest` || MICO_VER=2.3.5
+sh -c "rm micotest"
+sh -c "rm micotest.o"
+
+#do test of MICO_VER
+if test MICO_VER != 0; then
+AC_DEFINE(MICO_VER)
+AC_SUBST(MICO_VER)
+fi
+#end USE_CORBA test
+fi
+
+dnl Checks for typedefs, structures, and compiler characteristics.
+AC_AIX
+AC_ISC_POSIX
+AC_MINIX
+fp_C_PROTOTYPES
+AC_C_CONST
+AC_TYPE_OFF_T
+AC_TYPE_SIZE_T
+AC_HEADER_TIME
+AC_STRUCT_TM
+
+dnl --- This should be in the stdc checking -----------------
+if test "$ac_cv_prog_cc_stdc" = '-Xc'; then
+dnl The Pyramids running SMP_DC.OSx on MIPS r3000 chips with
+dnl /usr/opt/cc3.11/bin/cc treat -Xc as full ANSI mode - no POSIX or
+dnl XOPEN extensions (like popen).
+dnl Unfortunately -D_{XOPEN,POSIX}_SOURCE can't provide all that mg
+dnl needs. So drop back to -Xa
+AC_TRY_COMPILE(
+[#include <stdio.h>
+], [ FILE *rubbish = popen("yes", "r"); ],,
+[CC="`echo $CC | sed 's/-Xc/-Xa/'`"    ac_cv_prog_cc_stdc='-Xa'])
+fi
+dnl ----------------------
+
+
+dnl Checks for libraries.
+dnl check for -lg:
+AC_HAVE_LIBRARY(g)
+dnl check for -lm:
+AC_HAVE_LIBRARY(m)
+dnl check for -lcrypt:
+AC_HAVE_LIBRARY(crypt)
+if test $ENABLE_ACCENTFOLD = 1; then
+AC_HAVE_LIBRARY(iconv)
+fi
+
+dnl Checks for header files.
+AC_HEADER_DIRENT
+AC_HEADER_STDC
+AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h crypt.h string.h memory.h sys/procfs.h sys/stat.h)
+AC_EGREP_HEADER(fread, stdio.h, AC_DEFINE(HAVE_FREAD_DECL))
+AC_EGREP_HEADER(fgetc, stdio.h, AC_DEFINE(HAVE_FGETC_DECL))
+AC_EGREP_HEADER(pr_brksize, sys/procfs.h, AC_DEFINE(HAVE_PR_BRKSIZE))
+
+dnl Checks for library functions.
+AC_FUNC_ALLOCA
+AC_PROG_GCC_TRADITIONAL
+AC_TYPE_SIGNAL
+AC_FUNC_VPRINTF
+AC_CHECK_FUNCS(ftime select strftime strtol getrusage times mallinfo setbuffer getpagesize strerror)
+AC_REPLACE_FUNCS(ftruncate strstr strcasecmp)
+
+dnl see if gettext is in libc. (try the textdomain() function).
+AC_CHECK_FUNC(textdomain, AC_DEFINE(ENABLE_NLS ,1) )
+
+# *** Custom checking (based on GNU tar configure.in) ***
+# ---------------------------------------------------------------------------
+AC_MSG_CHECKING(for HP-UX needing gmalloc)
+if test "`(uname -s) 2> /dev/null`" = 'HP-UX'; then
+  AC_MSG_RESULT(yes)
+  AC_LIBOBJ([gmalloc])
+  AC_DEFINE(HAVE_VALLOC)
+else
+  AC_MSG_RESULT(no)
+  AC_CHECK_FUNCS(valloc)
+fi
+
+# we cannot generate static libraries under Darwin
+AC_MSG_CHECKING(for Apple MacOS X/Darwin)
+if test "`(uname -s) 2> /dev/null`" = 'Darwin'; then
+  AC_MSG_RESULT(yes)
+  STATIC=""
+else
+  AC_MSG_RESULT(no)
+  STATIC="-static "
+fi
+AC_SUBST(STATIC)
+
+fp_WITH_DMALLOC
+fp_WITH_REGEX
+
+# ---------------------------------------------------------------------------
+if test "$ac_cv_func_alloca" = 'no'; then
+dnl    support functions for alloca.c
+  AC_LIBOBJ([xmalloc])
+  AC_LIBOBJ([error])
+fi
+
+
+# ---------------------------------------------------------------------------
+
+dnl
+dnl Switch into C++
+dnl
+AC_LANG_CPLUSPLUS
+
+dnl
+dnl Check that the GDBM library is available
+dnl
+dnl check libgdbm manually, in case it's not in the standard location.
+
+AC_MSG_CHECKING(that the GDBM library is available)
+if test ! -z "$gdbmdir" ; then
+  # look in given directory for header file
+  if test -r $gdbmdir/include/gdbm.h ; then
+    GDBM_INCLUDE="-I$gdbmdir/include" ;
+  elif test -r $gdbmdir/gdbm.h ; then
+    GDBM_INCLUDE="-I$gdbmdir" ;
+  fi
+
+  # look in given directory for library
+  if test -r $gdbmdir/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir" ;
+  elif test -r $gdbmdir/lib/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir/lib" ;
+  elif test -r $gdbmdir/.libs/libgdbm.a ; then
+    GDBM_LIBPATH="-L$gdbmdir/.libs" ;
+  fi
+
+  if test ! -z "$GDBM_LIBPATH" -a ! -z "$GDBM_INCLUDE" ; then
+    AC_MSG_RESULT($gdbmdir) ;
+  else
+    AC_MSG_RESULT(can't find gdbm.h and libgdbm.a in $gdbmdir);
+    AC_MSG_CHECKING(   looking for GDBM library in default locations)
+  fi
+fi
+
+# look in default path and in /usr/local
+if test -z "$GDBM_INCLUDE" ; then
+  # try in system directory 
+  AC_TRY_COMPILE(
+  [#include <gdbm.h>
+],
+  [],
+  success=yes,
+  success=no
+  )
+
+  if test $success = "no"; then
+# last chance - look in /usr/local (eg FreeBSD)
+    GDBM_LIBPATH=-L/usr/local/lib
+    GDBM_INCLUDE=-I/usr/local/include
+    ac_save_CXXFLAGS="$CXXFLAGS"
+    ac_save_LIBS="$LIBS"
+      CXXFLAGS="$CXXFLAGS -I/usr/local/include"
+      LIBS="$LIBS -L/usr/local/lib -lgdbm"
+      AC_TRY_LINK(
+  	[#include <gdbm.h>
+#include <stdio.h>
+	],
+  	[printf("%s",gdbm_version);],
+  	success=/usr/local,
+  	success=no
+      )
+      CXXFLAGS=$ac_save_CXXFLAGS
+      LIBS=$ac_save_LIBS
+  fi
+
+  AC_MSG_RESULT($success)
+  if test $success = "no"; then
+  AC_MSG_ERROR(GDBM Library not available - cannot install)
+  fi
+fi
+dnl I don't think anything actually checks this define, but...
+AC_DEFINE(HAVE_LIBGDBM , 1)
+
+AC_SUBST(GDBM_LIBPATH)
+AC_SUBST(GDBM_INCLUDE)
+
+dnl
+dnl Now check that Perl is actually around, and can be found
+dnl
+AC_MSG_CHECKING(that Perl 5 is available)
+success="no"
+pl_path="$PATH"
+IFS="${IFS=   }"; pl_save_ifs="$IFS"; IFS=":"
+for pl_dir in $pl_path; do
+  test -z "$pl_dir" && pl_dir=.
+  if test -x $pl_dir/perl; then
+    success="yes"
+    break
+  fi
+done
+IFS="$pl_save_ifs"
+
+dnl
+dnl Check if the STL library has any known faults;
+dnl In GCC 2.7.2.x series, some STL library headers are missing
+dnl a file called "new" which is referred to by other headers
+dnl (eg. vector/vector.h); if this applies, then all use of the
+dnl STL will cause a compile fail, so we'd better let the user
+dnl know now, before things really go wrong!
+dnl
+success=no
+AC_MSG_CHECKING("whether STL library has known faults")
+
+dnl - first shot, try simple good old vector on its own
+AC_TRY_COMPILE(
+[#include <vector>
+], 
+[],
+success=yes,
+)
+
+dnl - try using the .h equivalent
+if test $success = "no"; then
+AC_TRY_COMPILE(
+[#include <vector.h>
+], 
+[],
+success="yes",
+)
+fi
+
+dnl - now try for the objectspace headers
+if test $success = "no"; then
+AC_TRY_COMPILE(
+[#include <ospace\\std\\vector>
+], 
+[],
+success="yes",
+)
+fi
+
+if test $success = yes; then
+AC_MSG_RESULT("no")
+else
+AC_MSG_RESULT("yes")
+AC_MSG_ERROR("STL Broken - Obtain newer version of GNU C Compiler")
+fi
+
+gsdlos=`uname | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
+# check for running bash under cygwin
+ if test "`echo $gsdlos | sed 's/cygwin//'`" != "$gsdlos" ;
+ then
+  gsdlos=windows
+ fi
+AC_SUBST(gsdlos)
+
+# check for endianness
+AC_C_BIGENDIAN
+# ---------------------------------------------------------------------------
+if test "$ac_cv_func_alloca" = 'no'; then
+dnl    support functions for alloca.c
+  AC_LIBOBJ([xmalloc.o])
+  AC_LIBOBJ([error])
+fi
+
+# ---------------------------------------------------------------------------
+
+
+dnl
+dnl Locate all children of the modules folder
+dnl
+moduleDirs=""
+MODULEDIRS=""
+if [ -d modules ] ; then
+  for x in `find modules -mindepth 1 -maxdepth 2`; do
+    if test -d "$x"; then
+      d="$x/Makefile.in"
+      if test -e "$d"; then
+  dnl      echo $d
+        moduleDirs="$moduleDirs $x/Makefile"
+        MODULEDIRS="$MODULEDIRS $x"
+      fi
+    fi
+  done
+  echo "Making $moduleDirs in modules directory"
+  AC_SUBST(MODULEDIRS)
+fi
+
+
+AC_CONFIG_SUBDIRS(packages)
+
+# the list of folders in the src folder
+srclist="src/colservr/Makefile \
+         src/corba/Makefile \
+         src/protocol/Makefile \
+         src/recpt/Makefile \
+         src/oaiservr/Makefile \
+         src/z3950/Makefile"
+
+AC_OUTPUT(packages/Makefile Makefile $srclist $moduleDirs)
+
+
Index: /gsdl/trunk/runtime-src/packages/Makefile
===================================================================
--- /gsdl/trunk/runtime-src/packages/Makefile	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/Makefile	(revision 16571)
@@ -0,0 +1,104 @@
+###########################################################################
+#
+# Makefile -- Makefile for packages included with Greenstone runtime
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 2000 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+
+USE_Z3950=0
+USE_YAZ=1
+
+ifeq ($(USE_Z3950), 1)
+# make sure USE_YAZ is set
+USE_YAZ=1
+D2M=d2m
+else
+D2M=
+endif
+
+ifeq ($(USE_YAZ), 1)
+# we only compile the src and client dirs for now.
+YAZ=yaz/yaz-2.1.4/src yaz/yaz-2.1.4/client 
+else
+YAZ=
+endif
+
+
+USE_CORBA=0
+MICO_DIR=default
+ifeq ($(USE_CORBA), 1)
+ifeq ($(MICO_DIR), default)
+CORBA="mico/mico"
+else
+CORBA=
+endif
+else
+CORBA=
+endif
+
+# PACKAGEDIRS contains the packages that we want to make and install.  It
+# is assumed that each package will have at least four rules: all, install,
+# clean, and distclean.
+PACKAGEDIRS =	$(YAZ) $(D2M) $(CORBA) 
+
+
+all:
+	for odir in $(PACKAGEDIRS); do \
+          echo making $@ in $$odir; \
+          (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
+        done
+ifeq ($(CORBA), "mico/mico")
+	cd mico/mico; $(MAKE)  $(MDEFINES) install
+	mkdir -p ../bin/linux
+	mkdir -p ../lib
+	mkdir -p ../include
+	mkdir -p ../man
+	cp -f mico/bin/* ../bin/linux
+	cp -f mico/lib/* ../lib/
+	cp -fr mico/include/* ../include
+	cp -fr mico/man ../man
+endif
+ifeq ($(USE_YAZ), 1)
+# need to do make install in include and src dirs to get the header files and
+# lib file into the right place
+	cd yaz/yaz-2.1.4/include; $(MAKE)  $(MDEFINES) install
+	cd yaz/yaz-2.1.4/src; $(MAKE)  $(MDEFINES) install
+endif
+
+install:
+	for idir in $(PACKAGEDIRS); do \
+          echo installing $$idir; \
+          (cd $$idir && $(MAKE) install) || exit 1; \
+        done
+
+clean:
+	for subdir in $(PACKAGEDIRS); do \
+          echo cleaning $@ in $$subdir; \
+          (cd $$subdir && $(MAKE) clean || exit 0) ; \
+        done
+
+distclean:
+	for subdir in $(PACKAGEDIRS); do \
+          echo cleaning $@ in $$subdir; \
+          (cd $$subdir && $(MAKE) distclean || exit 0) ; \
+        done
Index: /gsdl/trunk/runtime-src/packages/Makefile.in
===================================================================
--- /gsdl/trunk/runtime-src/packages/Makefile.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/Makefile.in	(revision 16571)
@@ -0,0 +1,104 @@
+###########################################################################
+#
+# Makefile -- Makefile for packages included with Greenstone runtime
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 2000 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+
+USE_Z3950=@USE_Z3950@
+USE_YAZ=@USE_YAZ@
+
+ifeq ($(USE_Z3950), 1)
+# make sure USE_YAZ is set
+USE_YAZ=1
+D2M=d2m
+else
+D2M=
+endif
+
+ifeq ($(USE_YAZ), 1)
+# we only compile the src and client dirs for now.
+YAZ=yaz/yaz-2.1.4/src yaz/yaz-2.1.4/client 
+else
+YAZ=
+endif
+
+
+USE_CORBA=@USE_CORBA@
+MICO_DIR=@MICO_DIR@
+ifeq ($(USE_CORBA), 1)
+ifeq ($(MICO_DIR), default)
+CORBA="mico/mico"
+else
+CORBA=
+endif
+else
+CORBA=
+endif
+
+# PACKAGEDIRS contains the packages that we want to make and install.  It
+# is assumed that each package will have at least four rules: all, install,
+# clean, and distclean.
+PACKAGEDIRS =	$(YAZ) $(D2M) $(CORBA) 
+
+
+all:
+	for odir in $(PACKAGEDIRS); do \
+          echo making $@ in $$odir; \
+          (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
+        done
+ifeq ($(CORBA), "mico/mico")
+	cd mico/mico; $(MAKE)  $(MDEFINES) install
+	mkdir -p ../bin/linux
+	mkdir -p ../lib
+	mkdir -p ../include
+	mkdir -p ../man
+	cp -f mico/bin/* ../bin/linux
+	cp -f mico/lib/* ../lib/
+	cp -fr mico/include/* ../include
+	cp -fr mico/man ../man
+endif
+ifeq ($(USE_YAZ), 1)
+# need to do make install in include and src dirs to get the header files and
+# lib file into the right place
+	cd yaz/yaz-2.1.4/include; $(MAKE)  $(MDEFINES) install
+	cd yaz/yaz-2.1.4/src; $(MAKE)  $(MDEFINES) install
+endif
+
+install:
+	for idir in $(PACKAGEDIRS); do \
+          echo installing $$idir; \
+          (cd $$idir && $(MAKE) install) || exit 1; \
+        done
+
+clean:
+	for subdir in $(PACKAGEDIRS); do \
+          echo cleaning $@ in $$subdir; \
+          (cd $$subdir && $(MAKE) clean || exit 0) ; \
+        done
+
+distclean:
+	for subdir in $(PACKAGEDIRS); do \
+          echo cleaning $@ in $$subdir; \
+          (cd $$subdir && $(MAKE) distclean || exit 0) ; \
+        done
Index: /gsdl/trunk/runtime-src/packages/configure
===================================================================
--- /gsdl/trunk/runtime-src/packages/configure	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/configure	(revision 16571)
@@ -0,0 +1,177 @@
+#! /bin/sh
+
+PACKAGES=`pwd`
+cd ../..
+GSDLHOME=`pwd`
+cd $PACKAGES
+
+GSDLOS=`uname -s |tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+# check for running bash under cygwin
+if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ;
+then
+ GSDLOS=windows
+fi
+
+prefix=""
+bindir=""
+HOSTTARGETFLAGS=""
+
+# only some of the packages can take environment variables as options to 
+# configure 
+# format is VAR=value, e.g "LDFLAGS=-static"
+ENVIRONMENT=""
+
+# SQLite support enabled by default, can switch it off with --disable-sqlite
+USE_SQLITE=true
+# yaz compilation enabled by default, can switch it off with --disable-yaz
+USE_YAZ=true
+# z3950 server disabled by default, switch it on with --enable-z3950
+USE_Z3950=false
+# CORBA support disabled by default, switch it on with --enable-corba
+USE_CORBA=false
+MICO_DIR=default
+
+# parse any arguments given from toplevel configure
+while test $# -ne 0; do
+    case "$1" in
+	--cache-file=*)
+	    cache_filename=`echo $1 | sed s/--cache-file=//`
+	    # turn relative path into an absolute path
+	    cache_dir=`echo $cache_filename | sed 's@/[^/]*$@@'`
+	    cache_dir=`cd $cache_dir 2>/dev/null && pwd`
+
+	    cache_basefile=`echo $cache_filename | sed 's@.*/@@'`
+	    cache_file="$cache_dir/$cache_basefile"
+	    if test ! -f "$cache_file"; then
+		CACHE_FILE=""
+	    else
+		CACHE_FILE="--cache-file=$cache_file"
+	    fi
+	    ;;
+	--disable-sqlite)
+	    USE_SQLITE=false
+	    ;;
+	--disable-yaz)
+	    USE_YAZ=false
+	    ;;
+	--enable-z3950)
+	    USE_Z3950=true
+	    ;;
+	--enable-corba)
+	    USE_CORBA=true
+	    ;;
+	--with-micodir=*)
+	    if test $1 = ""; then
+	      $1 = "default"
+            fi
+	    MICO_DIR=$1
+	    ;;       
+	--prefix=*)
+	    prefix=`echo $1 | sed s/--prefix=//`
+	    ;;
+	--bindir=*)
+	    # where to install binaries to
+	    bindir=`echo $1 | sed s/--bindir=//`
+	    # turn relative path into an absolute path
+	    if test -d "$bindir" ; then
+	      bindir=`cd "$bindir" ; pwd `
+	      cd "$PACKAGES"
+	    elif test -z `echo $bindir | sed '/^\// p;D'` ; then
+	      rel_bindir="`echo $bindir | sed s@/.*@@`"
+	      cd "$rel_bindir"
+	      bindir="`pwd`/`echo $bindir | sed s@^[^/]*/@@`"
+	      cd "$PACKAGES"
+	    else
+	      # bindir doesn't exist, and isn't relative
+	      true
+	    fi
+	    ;;
+	--host=* | --target=*)
+	    HOSTTARGETFLAGS="$HOSTTARGETFLAGS $1"
+	    ;;
+	*)
+	    # ignore all other options for now
+	    ;;
+    esac
+    shift
+done
+
+# note! Our GSDL package currently always installs into it's source
+# directory, ignoring any --prefix given to configure.
+# When this is fixed, uncomment the relevant lines below...
+
+##if test -z "$prefix" ; then
+prefix="${GSDLHOME}"
+##fi
+
+##if test -z "$bindir" ; then
+bindir="${prefix}/bin/$GSDLOS"
+##fi
+
+# This loads the top configure's cache file, with variables already set.
+if test -f "$cache_file" ; then
+  . $cache_file
+fi
+
+# we assume that gzip and tar are on the search path.
+# non-GNU versions of tar don't take the -z option.
+
+if test $USE_CORBA = true ; then
+  if test $MICO_DIR = default; then
+    # configure the MICO CORBA ORB
+    echo ""
+    echo "Configuring MICO CORBA"
+    echo ""
+
+    cd "$PACKAGES/mico"
+    gzip -dc mico-2.3.5.tar.gz | tar -xf -
+    cd mico && \
+    ./configure $CACHE_FILE    --prefix=$PACKAGES/mico/  --disable-coss --disable-naming --disable-relship --disable-events --disable-streams --disable-property --disable-trader --disable-time --disable-debug --enable-optimize --enable-final --enable-speed-tune
+    sed 's/tools//'  $PACKAGES/mico/mico/Makefile | sed 's/ldconfig//' >$PACKAGES/mico/mico/Makefile.out
+    mv $PACKAGES/mico/mico/Makefile.out $PACKAGES/mico/mico/Makefile
+  else
+    #MICO is on the system path
+    echo ""
+    echo "Taking MICO from system paths"
+    echo ""
+  fi
+else
+  echo "corba support disabled - mico compiler not required."
+  echo "  add '--enable-corba' to the configure command to include corba support."
+  echo ""
+fi
+
+
+
+# D2M stuff needed for z3950server
+echo ""
+echo "Configuring D2M"
+if test x$USE_Z3950 = xtrue ; 
+then
+  USE_YAZ=true
+  echo ""
+  cd "$PACKAGES/d2m"
+  ./configure $CACHE_FILE --prefix="$PACKAGES/d2m" $HOSTTARGETFLAGS
+else
+  echo "Z39.50 support disabled - D2M library not required."
+  echo "  add '--enable-z3950' to the configure command to include z39.50 support."
+  echo ""
+fi
+   
+# YAZ Z39.50 toolkit
+echo ""
+echo "Configuring YAZ"
+if test x$USE_YAZ = xtrue ; 
+then
+  echo "YAZ library support enabled"
+  echo "add --disable-yaz to the configure command to disable this"
+  echo ""
+  cd "$PACKAGES/yaz" 
+  gzip -dc yaz-2.1.4.tar.gz | tar -xf -
+  cd yaz-2.1.4 && \
+    ./configure $CACHE_FILE --prefix="$PACKAGES/yaz" --bindir="$bindir" $HOSTTARGETFLAGS
+else
+  echo "YAZ support disabled"
+  echo ""
+fi
+
Index: /gsdl/trunk/runtime-src/packages/d2m/D2Mcgi.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/D2Mcgi.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/D2Mcgi.c	(revision 16571)
@@ -0,0 +1,326 @@
+/* ------------------------------------------------------------------- */
+/* D2Mcgi.c  : CGI program for DC -> MARC conversion                   */
+/* Author    : Ole Husby                                               */
+/* Updated   : 1998-09-30                                              */
+/* ------------------------------------------------------------------- */
+
+/* -------------------------------------------------------------------
+D2MCgi() will take metadata input from a parameter, or fetch an
+HTML file using HTTP.
+
+DC metadata will be converted into MARC, and presented in one of
+several formats.
+
+The program will look for the following QUERY_STRING:
+
+url=xxx&fmt=xxx&prs=xxx&txt=xxx&par=xxx 
+
+where: 
+
+  url
+      xxx = the URL for the file containing the metadata
+  fmt
+      The MARC format. xxx =
+      DANMARC | FINMARC | ISMARC | NORMARC (default) | SWEMARC | USMARC.
+  prs
+      The presentation format. xxx =
+      plain (default) | html | 2709 | binary.
+
+  txt
+      If present, this field will be parsed for metadata, and the only 
+      use of the URL (if entered) will be used to produce the 856 field 
+      of the MARC record. 
+
+  par
+      If xxx = on, the program will additionally display the tags as
+      they are recognized. Will only work together with the html format.
+   ------------------------------------------------------------------- */
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <malloc.h>
+#include <ctype.h>
+#include <unistd.h>
+#include "d2m.h"
+
+
+
+
+/* ------------------------------------------------------------------- */
+/* main() program                                                      */
+/* ------------------------------------------------------------------- */
+
+int main ()
+{
+  int rc, i, source, textarea, f2709, tracing, mformat, marcfile;
+  int linel, llen, slen;
+  int *meta;
+
+  FILE *df, *of;
+  char contype[64], dfilename[64], tfilename[64], line[50000];
+  char *pq, *p, *q, pre[16], *l, *u;
+  char marcformat[256], url[1000], method[32];
+  char *buffer[50000];
+  char syntax[64];
+
+  char recstatus = 'n';
+  char rectype   = 'm';
+  char biblevel  = ' ';
+
+/* Initializing  */
+
+  of = stdout;
+  *url = 0;
+  marcfile = 0;
+
+  strcpy(marcformat, D2M_DEFAULT_FORMAT);
+  strcpy(syntax, D2M_DEFAULT_SYNTAX);
+  sprintf(dfilename, "%s.%d", D2M_TEMPFILE, getpid());
+
+  textarea = tracing = f2709 = 0;
+  *line = 0;
+
+
+/* Decide parameters for line format formating   */
+
+  linel = D2M_LINELEN;
+  if (!linel)
+    linel = 80;
+
+  if (linel > 200)
+    linel = 200;
+
+  llen = linel - 9;
+  slen = linel - 30;
+  if (slen < 10)
+    slen = 10;
+
+
+/* Check request method (POST or GET)  */
+
+  strcpy(method, getenv("REQUEST_METHOD"));
+
+  if (strcmp(method, "GET") == 0)
+  {
+    strcpy(line, getenv("QUERY_STRING"));
+    pq = (char *) strdup(line);
+  }
+  
+  else if (strcmp(method, "POST") == 0)
+    pq = poq();
+
+  else
+    pq = (char *) NULL;           /* Error exit is missing here ! */
+
+
+/* Parse parameters  */
+  
+  if (pq)
+  {
+    strcpy(line, pq);
+    free(pq);
+
+    l = (char *) line;
+
+    u = strtok(l, "&");
+    while (u)
+    {
+      unescape(u);
+      if (strncasecmp(u, "url=", 4) == 0)
+        strcpy(url, u + 4); 
+      else if (strncasecmp(u, "fmt=", 4) == 0)
+        strcpy(marcformat, u + 4); 
+      else if (strncasecmp(u, "prs=", 4) == 0)
+        strcpy(syntax, u + 4); 
+      else if (strncasecmp(u, "par=", 4) == 0)
+      {
+        if (strcmp(u + 4, "on") == 0) 
+          tracing = 1;
+      }
+      else if (strncasecmp(u, "txt=", 4) == 0)
+      {
+        if (strlen(u + 4))
+        {
+          if ( df = fopen(dfilename, "w"))
+          {
+            fprintf(df, "%s", u + 4);
+            textarea = 1;
+            fclose(df);
+          }
+        }
+      }
+      u = strtok(NULL, "&");
+    }
+  }
+
+
+
+/* Check the syntax */
+
+  if (strcmp(syntax, "2709") == 0)
+  {
+    strcpy(contype, "text/plain");
+    tracing = 0;
+    f2709 = 1;
+  }
+
+  else if (strcmp(syntax, "binary") == 0)
+  {
+    strcpy(contype, "application/marc");
+    tracing = 0;
+    f2709 = 1;
+  }
+
+  else if (strcmp(syntax, "html") == 0)
+  {
+    strcpy(contype, "text/html");
+  }
+
+  else if (strcmp(syntax, "plain") == 0)
+  {
+    strcpy(contype, "text/plain");
+    tracing = 0;
+  }
+
+
+/* Write HTTP header and HTML <HEAD>: */
+
+  printf("Content-type: %s\n\n", contype);
+  if (strcmp(syntax, "html") == 0)
+  {
+    printf("<html><head><title>\n");
+    printf("%s\n", HTML_TITLE);
+    printf("</title></head>\n\n<body bgcolor=\"#ffffbb\">\n");
+  }
+
+
+
+/* Check if metadata in input (source = TEXTAREA) or in URL   */
+
+  if (!textarea && !*url)
+  {
+    printf("1: ");
+    printf("Error: Insufficient input\n");
+    exit(0);
+  }
+
+  else if (textarea)
+    source = TEXTAREA;
+
+  else
+    source = URL;
+
+  if (!textarea && !*url)
+  {
+    printf("2: ");
+    printf("Error: Insufficient input\n");
+    exit(0);
+  }
+
+
+/* Check the marcformat   */
+
+  if (strncasecmp(marcformat, "DAN", 3) == 0)
+    mformat = DANMARC;
+  else if (strncasecmp(marcformat, "FIN", 3) == 0)
+    mformat = FINMARC;
+  else if (strncasecmp(marcformat, "IS", 2) == 0)
+    mformat = ISMARC;
+  else if (strncasecmp(marcformat, "US", 2) == 0)
+    mformat = USMARC;
+  else if (strncasecmp(marcformat, "NOR", 3) == 0)
+    mformat = NORMARC;
+  else if (strncasecmp(marcformat, "SWE", 3) == 0)
+    mformat = SWEMARC;
+  else
+  {
+    printf("Error: This MARC format is not supported!\n");
+    exit(0);
+  }
+
+
+/* Fetch URL if necessary    */
+
+  if (source == URL)
+  {
+    if (strcmp(url, "test") == 0)
+      strcpy(url, D2M_DEFAULT_URL);
+    rc = wfetch(&url, &dfilename);
+    if (!rc)
+    {
+      printf("Error %d: Unable to fetch file %s\n", rc, url);
+      exit(0);
+    }
+    if (rc == 2)
+      marcfile = 1;
+  }
+
+  if (*url && !textarea && ( strcmp(syntax, "html") == 0 ) )
+  {
+    printf("<h2><a href=\"%s\">%s</a></h2>\n", url, url);
+    printf("<h3>%s record:</h3><hr>\n", marcformat);
+  }
+
+   if (strcmp(syntax, "html") == 0)
+     printf("<pre>\n");
+
+   if (tracing)
+     strcpy(tfilename, D2M_TRACEFILE);
+   else
+     *tfilename = 0;
+
+/* Convert to MARC                                                    */
+/* NOTE: M2Mconv() will even convert from MARC 2709 to line format    */
+
+   if (marcfile)
+     rc = M2Mconv((char *) dfilename, (char *) buffer,
+                 (char *) tfilename, mformat);
+   else            
+     rc = D2Mconv((char *) dfilename, (char *) buffer,
+                 (char *) tfilename, (char *) url, mformat);
+
+   remove(dfilename);
+
+
+/* Produce output                                                      */
+
+   if (!rc)
+     printf("Error: Unable to parse data\n");
+
+   else
+   {
+     if (f2709)
+       printf("%s", 
+         (char *) MARC2709(buffer, 0, 6, recstatus, rectype, biblevel));
+     else
+  
+     {
+       l = strtok((char *) buffer, "\n");
+  
+       while (l)
+       {
+         write_field(l, of, linel, llen, slen);
+         l = strtok(NULL, "\n");
+       }
+     }
+   }
+
+   if (*url && !textarea && ( strcmp(syntax, "html") == 0 ) )
+     printf("<hr>\n");
+
+   if (tracing)
+   {
+     printf("</pre>\n");
+     printf("<h3>Parsed DC metadata:</h3>\n");
+     printf("<pre>\n");
+     write_trace(tfilename, of);
+   }
+
+   if (strcmp(syntax, "html") == 0)
+   {
+     printf("</pre>\n");
+     printf("</body></html>\n");
+   }
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/D2Mconv.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/D2Mconv.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/D2Mconv.c	(revision 16571)
@@ -0,0 +1,265 @@
+/* ------------------------------------------------------------------- */
+/* D2Mconv   : Converts metadata present in a file to MARC             */
+/*             Writes MARC record in "line format"                     */
+/*                                                                     */
+/* Syntax    : Arguments:                                              */
+/*                                                                     */
+/*       char *dfile : input file                                      */
+/*                     DC metadata must be present in HTML 2.0         */
+/*                     or HTML 4.0 syntax                              */
+/*       char *buffer: output record in line format                    */
+/*                     Must be allocated in calling program!           */
+/*       char *tfile : tracefile                                       */
+/*                     No trace if NULL                                */
+/*       char *url   : URL for use in case no URL in DC.Identifier     */
+/*                                                                     */
+/*       char *format: MARC format (see d2m.h)                         */
+/*                                                                     */
+/* Author    : Ole Husby, BIBSYS                                       */
+/* Updated   : 1998-09-30                                              */
+/* ------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <malloc.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <time.h>
+#include "d2m.h"
+
+
+
+
+/* ------------------------------------------------------------------- */
+/* Checks a new line                                                   */
+/* ------------------------------------------------------------------- */
+/*
+   This is where starting and ending of a meta tag is parsed.
+   The whole metatag (resulting from one ore more lines) is put
+   into the buffer.
+
+   Note: This function is called recursively!
+*/
+
+int mline(char *l, char *buf, int *meta, 
+          struct marcrec *mrec, FILE *tf, int format)
+{
+  char *p, *q, rc;
+  int diff;
+
+  struct metatag *mtag;
+ 
+  if (!l || !*l) return 1;
+
+  q = l;
+
+
+/* Looks for the end of an already started metatag buffer              */
+/* The end is normally '">'                                            */
+
+  if (*meta)
+  {
+     p = strstr(l, "\">");
+
+     if (p) 
+     {
+        if ( (char *) p != (char *) l)
+        {
+           diff = (int)(p - l);
+           if (*buf)
+             strcat(buf, " ");
+           strncat(buf, l, diff);
+        }
+
+/* Parsing the buffer for metadata                                  */
+
+        mtag = dc_parse(buf);
+
+        if (mtag)
+        {
+          if (tf)
+          {
+            fprintf(tf, "Name  : %s\n", mtag->name   );
+            fprintf(tf, "Type  : %s\n", mtag->type   );
+            fprintf(tf, "Scheme: %s\n", mtag->scheme );
+            fprintf(tf, "Value : %s\n", mtag->value  );
+            fprintf(tf, "\n");
+          }
+
+/*        Convert to MARC                                           */
+
+          MARCmake(mtag, mrec, format);
+        }
+        free(mtag);
+
+        *buf = 0;
+        *meta = FALSE;
+        q = p + 2;
+     }
+     else
+     {
+        strcat(buf, l);
+        q = NULL;
+     }
+  }
+
+
+  if (!q) return 1;
+
+  p = (char *) cstr(q, "<meta ");
+
+  if (p)
+  {
+    *meta = TRUE;
+    mline(p + 6, buf, meta, mrec, tf, format);
+  }
+
+  return 1;
+}
+
+
+
+int D2Mconv(char *dfile, char *buffer, char *tfile, char *url, int format)
+{
+  struct marcrec *mrec;
+  struct metatag *mtag;
+  char line[50000], today[32];
+  char *l, *p;
+  time_t d;
+  struct tm *time_struct;
+
+  FILE *df, *tf;
+  int *meta;
+
+  putenv("TZ=NFT-1DFT");
+  d = time(NULL);
+  time_struct = localtime(&d);
+  strftime(today, 16, "%y%m%d", time_struct);
+
+  mrec = malloc(sizeof(*mrec));
+
+  mrec->marcline = malloc(100000);
+  mrec->partitle = malloc(10000);
+  mrec->subtitle = malloc(10000);
+  mrec->year     = malloc(1000);
+  mrec->url      = malloc(1000);
+  mrec->fmat     = malloc(1000);
+  mrec->s008     = malloc(41);
+
+  mrec->ncreators = 0;
+  mrec->ntitles   = 0;
+  *mrec->marcline = 0;
+  *mrec->subtitle = 0;
+  *mrec->partitle = 0;
+  *mrec->year     = 0;
+  *mrec->url      = 0;
+  *mrec->fmat     = 0;
+  strcpy(mrec->s008, "                                        ");
+
+  meta = malloc(sizeof(int));
+
+  tf = (FILE *) NULL;
+
+
+/* Open inputfile */
+
+  df = fopen(dfile, "r");
+  if (!df)
+    return 0;                            /* Error: Unable to read data */
+
+
+
+/* Open tracefile */
+
+   if (*tfile)
+   {
+     tf = fopen(tfile, "w");
+     if (!tf)
+     {
+       fclose(df);
+       return 0;                         /* Error: Unable to create trace */
+     }
+   }
+
+   *meta = FALSE;
+
+
+/* Reads the file */ 
+
+
+   while (l = fgets(line, 9999, df))
+   {
+
+/*   Remove trailing LF and / or CR     */
+
+     while ( (l[strlen(l) - 1] == '\n') || (l[strlen(l) - 1] == '\r') )
+       l[strlen(l) -1] = '\0';
+
+
+/*   printf("... main  %s\n",l);                             */ 
+
+/*   Stops reading file if "</head" or "<body" is encountered  */
+
+     p = cstr(l, (char *) "</head");
+     if (p) break;
+
+     p = cstr(l, (char *) "<body");
+     if (p) break;
+
+     mline(l, (char *) buffer, (int *) meta, mrec, tf, format);
+   }
+
+
+
+/* Check if remaining data in buffer */
+  
+   mtag = dc_parse((char *) buffer);
+
+   if (mtag) 
+   {
+     if (tf)
+     {
+       fprintf(tf, "Name  : %s\n", mtag->name   );
+       fprintf(tf, "Type  : %s\n", mtag->type   );
+       fprintf(tf, "Scheme: %s\n", mtag->scheme );
+       fprintf(tf, "Value : %s\n", mtag->value  );
+       fprintf(tf, "\n");
+     }
+     MARCmake(mtag, mrec, format);
+   }
+   free(mtag);
+
+
+/* Close files */ 
+
+   fclose(df);
+
+   if (tf)
+     fclose(tf);
+
+/* Put URL into mrec (if not present)  */
+
+   if (!*mrec->url)
+     strcpy(mrec->url, url);
+
+/* Put date into 008 */
+
+   put008(mrec->s008, today, F008_DATE_ENTERED);
+   put008(mrec->s008, "s", F008_TYPE_OF_DATE);
+
+   switch (format)
+   {
+     case ISMARC  :
+     {
+       put008(mrec->s008, "k", F008_FORM_OF_PUBLICATION);
+       break;
+     }
+   }
+
+/* Tidy up the MARC buffer                                               */
+
+   MARCtidy(mrec, buffer, format);
+
+   return 1;
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/D2Mmain.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/D2Mmain.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/D2Mmain.c	(revision 16571)
@@ -0,0 +1,246 @@
+/* ------------------------------------------------------------------- */
+/* D2Mmain   : standalone program for DC -> MARC conversion            */
+/*                                                                     */
+/* Syntax    : d2main [File] [Options]                                 */
+/*                                                                     */
+/* File      : This may be a local filename, or a URL (which is        */
+/*             recognized by the "http://" prefix). When a URL,        */
+/*             the remote file will be fetched using the builtin       */
+/*             HTTP "client".                                          */
+/*                                                                     */
+/* Options   : -l                       : Format = line format         */
+/*                                        (Default is ISO 2709)        */
+/* Options   : -f [filename]            : Outputfile                   */
+/*                                        (Default is stdout)          */
+/* Options   : -m [marcformat]          : Marcformat (upper case)      */
+/*                                        (Default is NORMARC)         */
+/* Options   : -t [filename]            : Tracefile                    */
+/*                                        (Default is no trace)        */
+/*                                                                     */
+/* Return    : 0 : OK                                                  */
+/*             1 : Syntax error (no parms != 2)                        */
+/*             2 : Illegal MARC format                                 */
+/*             3 : Cannot open output file                             */
+/*             8 : Error in MARC conversion                            */
+/*             9 : URL not found                                       */
+/*                                                                     */
+/* Author    : Ole Husby                                               */
+/* Updated   : 1998-09-30                                              */
+/* ------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <unistd.h>
+#include "d2m.h"
+
+
+
+
+
+/* ------------------------------------------------------------------- */
+/* main() program                                                      */
+/* ------------------------------------------------------------------- */
+
+int main (int argc, char **argv)
+{
+  int rc, i, f2709, tracing, argtype, mformat, marcfile;
+  int linel, llen, slen;
+
+  FILE *df, *of;
+  char dfilename[64], tfilename[64], ofilename[64], line[50000];
+  char *pq, *p, *q, pre[16], *l, *u;
+  char marcformat[64], url[1000];
+  char buffer[50000];
+
+  char recstatus = 'n';
+  char rectype   = 'm';
+  char biblevel  = ' ';
+
+  enum options {OPT_NONE, OPT_FILE, OPT_TRAC, OPT_MARC};
+
+
+/* Initialize */
+
+  of = stdout;
+  *url = *ofilename = 0;
+  strcpy(marcformat, "NORMARC");
+
+  tracing = FALSE;
+  *tfilename = 0;
+  f2709 = TRUE;
+  marcfile = 0;
+
+  *line = 0;
+
+  linel = D2M_LINELEN;
+  if (!linel)
+    linel = 80;
+
+  if (linel > 200)
+    linel = 200;
+
+  llen = linel - 9;
+  slen = linel - 30;
+  if (slen < 10)
+    slen = 10;
+
+
+/* Read command line arguments */
+
+  if (argc < 2)
+  { 
+    printf(" Syntax    : d2main [File] [Options]\n\n");
+    printf(" File      : This may be a local filename, or a URL (which is\n");
+    printf("             recognized by the \"http://\" prefix). When a URL,\n");
+    printf("             the remote file will be fetched using the builtin\n");
+    printf("             HTTP \"client\".\n\n");
+    printf(" Options   : -l                       : Format = line format\n");
+    printf("                                        (Default is ISO 2709)\n");
+    printf(" Options   : -f [filename]            : Outputfile\n");
+    printf("                                        (Default is stdout)\n");
+    printf(" Options   : -m [marcformat]          : Marcformat (upper case)\n");
+    printf("                                        (Default is NORMARC)\n");
+    printf(" Options   : -t [filename]            : Tracefile\n");
+    printf("                                        (Default is no trace)\n\n");
+    printf(" Return    : 0 : OK\n");
+    printf("             1 : Syntax error\n");
+    printf("             2 : Illegal MARC format\n");
+    printf("             3 : Cannot open output file\n");
+    printf("             8 : Error in MARC conversion\n");
+    printf("             9 : URL not found\n");
+    exit(1);
+  }
+
+  strcpy(dfilename, argv[1]);
+
+
+/* Get options                                                         */
+
+  if (argc > 2)
+  {
+    argtype = OPT_NONE;
+
+    for (i = 1; i < argc; i++)
+    {
+      if (argtype == OPT_FILE)
+      {
+        strcpy(ofilename, argv[i]);
+        argtype = OPT_NONE;
+      }
+      else if (argtype == OPT_TRAC)
+      {
+        strcpy(tfilename, argv[i]);
+        tracing = TRUE;
+        argtype = OPT_NONE;
+      }
+      else if (argtype == OPT_MARC)
+      {
+        strcpy(marcformat, argv[i]);
+        argtype = OPT_NONE;
+      }
+      else if (strcmp(argv[i], "-l") == 0)
+      {
+        f2709 = FALSE;
+        argtype = OPT_NONE;
+      }
+      else if (strcmp(argv[i], "-m") == 0)
+         argtype = OPT_MARC;
+      else if (strcmp(argv[i], "-f") == 0)
+         argtype = OPT_FILE;
+      else if (strcmp(argv[i], "-t") == 0)
+         argtype = OPT_TRAC;
+      else
+        argtype = OPT_NONE;
+    }
+  }
+
+/* Verify MARC format */
+
+  if (strncasecmp(marcformat, "US", 2) == 0)
+    mformat = USMARC;
+  else if (strncasecmp(marcformat, "DAN", 3) == 0)
+    mformat = DANMARC;
+  else if (strncasecmp(marcformat, "FIN", 3) == 0)
+    mformat = FINMARC;
+  else if (strncasecmp(marcformat, "IS", 2) == 0)
+    mformat = ISMARC;
+  else if (strncasecmp(marcformat, "NOR", 3) == 0)
+    mformat = NORMARC;
+  else if (strncasecmp(marcformat, "SWE", 3) == 0)
+    mformat = SWEMARC;
+  else 
+    exit(2);
+
+
+/* Fetch URL if remote file  */
+
+  if (strncmp(dfilename, "http://", 7) == 0)
+  {
+    strcpy(url, dfilename);
+    sprintf(dfilename, "%s.%d", D2M_TEMPFILE, getpid());
+    rc = wfetch(&url, &dfilename);
+    if (!rc)
+    {
+      remove(dfilename);
+      exit(9);
+    }
+    if (rc == 2)
+      marcfile = 1;
+  }
+
+
+
+
+/* Convert into buffer (line format)  */
+
+  if (marcfile)
+    rc = M2Mconv((char *) dfilename, (char *) buffer,
+                (char *) tfilename, mformat);
+  else
+    rc = D2Mconv((char *) dfilename, (char *) buffer,
+                (char *) tfilename, (char *) url, mformat);
+
+  if (!rc)
+  {
+    fclose(df);
+    exit(8);
+  }
+
+  if (*url)
+    remove(dfilename);
+
+
+/* Prepare for output      */
+
+   if (*ofilename)
+   {
+     of = fopen(ofilename, "w");
+     if (!of)
+       exit(3);
+   }
+   else
+     of = stdout;
+
+
+/* Write output, if necessary converted to ISO 27809   */
+
+   if (f2709)
+     fprintf(of, "%s", 
+       (char *) MARC2709(buffer, 0, 6, recstatus, rectype, biblevel));
+
+   else
+   {
+     l = strtok((char *) buffer, "\n");
+
+     while (l)
+     {
+       write_field(l, of, linel, llen, slen);
+       l = strtok(NULL, "\n");
+     }
+   }
+
+   if (*ofilename)
+     fclose(of);
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/M2Mconv.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/M2Mconv.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/M2Mconv.c	(revision 16571)
@@ -0,0 +1,84 @@
+/* ------------------------------------------------------------------- */
+/* M2Mconv   : Convert an ISO 2709 record into MARC format             */
+/* Author    : Ole Husby, BIBSYS                                       */
+/* Updated   : 1998-09-30                                              */
+/* ------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <unistd.h>
+
+
+
+
+int M2Mconv(char *dfile, char *buffer, char *tfile, int format)
+{
+  char mtype[16], line[50000];
+  char *l, *p, *bf;
+  int lines;
+  FILE *df, *tf;
+
+  tf = (FILE *) NULL;
+  strcpy(mtype, "bibsys");
+
+
+/* Open inputfile */
+
+  df = fopen(dfile, "r");
+  if (!df)
+    return 0;                            /* Error: Unable to read data */
+
+
+
+/* Open tracefile */
+
+   if (*tfile)
+   {
+     tf = fopen(tfile, "w");
+     if (!tf)
+     {
+       fclose(df);
+       return 0;                         /* Error: Unable to create trace */
+     }
+   }
+
+
+/* Reads the file */ 
+
+   lines = 0;
+
+   while (l = fgets(line, 49999, df))
+   {
+/*   Remove trailing lf or cr     */
+
+     while ( (l[strlen(l) - 1] == '\n') || (l[strlen(l) - 1] == '\r') )
+       l[strlen(l) -1] = '\0';
+
+     lines++;
+     if (lines > 1)
+       break;                            /* Error: Not a 2709 file       */
+     p = l;
+   }
+
+
+/* Close files */ 
+
+  fclose(df);
+
+  if (tf)
+    fclose(tf);
+
+  if ( lines > 1 )
+    return 0;
+
+
+/* Convert to line format */
+
+  bf = (char *) marc2line(p, mtype);
+
+  strcpy(buffer, bf);
+
+  return 1;
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/MARC2709.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/MARC2709.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/MARC2709.c	(revision 16571)
@@ -0,0 +1,495 @@
+/* ------------------------------------------------------------------- */
+/* MARC2709  : Converts a "line format MARC record" into ISO 2709      */
+/*                                                                     */
+/*             Input string requirements:                              */
+/*             1. New MARC tag is indicated by MARC tag in pos 1-3     */
+/*                (may be preceded by *). Indicator follows in next 2  */
+/*                bytes.                                               */
+/*             2. Continuation line is indicated by blank in col 1     */
+/*             3. End-of-record (^) may or may not be present          */
+/*                                                                     */
+/* author    : Ole Husby                                               */
+/* updated   : 1998-09-30                                              */
+/* ------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#define NORMARC                                12
+
+#define SUBFIELD_CODE                          "\x1f"
+#define FIELD_TERMINATOR                       "\x1e"
+#define RECORD_TERMINATOR                      "\x1d"
+
+#define INDICATOR_COUNT                        '2'
+#define SUBFIELD_CODE_COUNT                    '2'
+#define LENGTH_OF_LENGTH_OF_FIELD              '4'
+#define LENGTH_OF_STARTING_CHARACTER_POSITION  '5'
+#define UNUSED                                 "   "
+#define TAG001                                 "001"
+#define TAG008                                 "008"
+#define SKIP                                     41
+
+static char out_record[10240],
+	      leader[24+1],
+	      directory[10240],
+	      field_001[32], 
+	      field_008[40+2],
+	      data_field[10240];
+
+
+static char logline[128];
+static char rstr[6], dollar, dollarstring[2];
+static int skip;
+
+static char direlem[300][12+1];
+static int dircntr;
+
+union LDR   {
+   char ldr_string[24+1];
+   struct {
+      char record_length[5],
+      record_status,
+      record_type,
+      bibliographic_level,
+      unused1[2],
+      indicator_count,
+      subfield_code_count,
+      base_adress[5],
+      unused2[3],
+      entry1,
+      entry2,
+      entry3,
+      entry4;
+   } ltab;
+ } ldr;
+
+static int startet = 0;
+
+
+
+/* ------------------------------------------------------------------- */
+/* Compare function for qsort                                          */
+/* ------------------------------------------------------------------- */
+
+int cmp(const void *a, const void *b)
+{
+   return strcmp((char*)a, (char*)b);
+}
+
+
+
+
+/* ------------------------------------------------------------------- */
+/* Convert integer to string of fixed length. Right justified padded   */
+/* with zeros. Returns NULL if error                                   */
+/* ------------------------------------------------------------------- */
+
+char *itoal(int n, int len)
+{
+   char *r;
+   r = (char *) rstr;
+
+   switch (len)
+   {
+      case  4 : sprintf(r, "%04d", n); break;
+      case  5 : sprintf(r, "%05d", n); break;
+      default : return NULL;                       
+   }
+
+   r[len] = '\0';
+
+   return r;
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* One 001 subfield is put into field_001                              */
+/* ------------------------------------------------------------------- */
+
+static int make_001(char *data, char subfield)
+{
+   int len;
+
+   startet = 0;
+   switch (subfield)
+   {
+      case ' ' : break;
+      case 'a' : break;
+      default  : return 1;
+   }
+
+   while (data[0] == ' ') data++;
+   strcpy(field_001, data);
+
+   len = strlen(data) + 1;
+   skip = SKIP + len;
+
+   sprintf(directory, "00100%2d000000080041000%2d", len, len);
+   return 1;
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* One subfield string is appended to data_field                       */
+/* ------------------------------------------------------------------- */
+
+static int out_subfield(char *data, char *ftag, char subfield, char nextsubfield)
+{
+   int len, subint;
+   char subreplace, *p, *up;
+
+   while (data[strlen(data) -1] == ' ') 
+          data[strlen(data) -1] = '\0';            /* strip trailing blanks */
+
+   if (subfield == '3')                            /* always discard $3     */
+      return 1;
+
+   if (strcmp(ftag, TAG001) == 0)                  /* 001 data treatment     */
+   {
+      make_001(data, subfield);
+      return 1;
+   }
+   
+   if (strcmp(ftag, TAG008) == 0)                  /* 008 data treatment     */
+   {
+      strncpy(field_008, data, strlen(data)); 
+      return 1;
+   }
+   
+   if (subfield != ' ')                             /* handle subfield code  */
+   {
+      strcat(data_field, SUBFIELD_CODE);
+      len = strlen(data_field);
+      data_field[len] = subfield;
+      data_field[len + 1] = '\0';
+   }
+
+   while(data[0] == ' ') data++;                   /* strip leading blanks   */
+   if (!data) return 0;
+
+   strcat(data_field, data);                       /* append data            */
+   
+   return 1;
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* One MARC field is split into subfields and given to output          */
+/* ------------------------------------------------------------------- */
+
+static int out_field(char *data, char *ftag, char *find)
+{
+   char lnumber[5], snumber[6];
+   int fStart, fLen, moresubs;
+   char subfield[5120], *sub, subcode, *nextsub, nextsubcode;
+   char *v, subfield_v[32];
+
+   if (!startet) return 1;
+
+   if ((strncmp(ftag, "00", 2) == 0) &&
+       (strcmp(ftag, TAG001) != 0) &&
+       (strcmp(ftag, TAG008) != 0))
+      return 1;
+
+   fStart = strlen(data_field);
+   
+   if (strncmp(data, "  $", 3) == 0) data +=2;   /* possible if 008         */
+
+   if (data[0] != dollar)                        /* Dollar sign missing     */
+   {
+      if (strncmp(ftag,"00",2) != 0) return 0;   /* only allowed if tag=00x */
+	 
+      if (strcmp(ftag, TAG001) == 0)             /* 001: skip leading blanks */
+         while (data[0] == ' ') 
+            data++;  
+
+      subcode = ' ';
+      nextsubcode = ' ';
+
+      if (!out_subfield(data, ftag, subcode, nextsubcode)) 
+	 return 0;
+      return 1;
+   }
+
+   else
+   {
+      data++;
+
+      if (!data) return 0;
+
+      if (strncmp(ftag,"00",2) != 0)             /* append indicators       */
+         strcat(data_field, find);
+      
+      sub = strtok(data, dollarstring);          /* first subfield          */
+      if (!sub)
+         return 0;
+
+/*    printf("--- %s\n", sub); */
+
+      subcode = sub[0];
+      sub++;
+
+      moresubs = 1;
+
+      while (moresubs)                           /* loop while more subflds */
+      {  
+         nextsub = strtok(NULL, dollarstring);   /* next subfld             */
+         if (nextsub) 
+         {
+/*          printf("--- %s\n", nextsub); */
+	    nextsubcode = nextsub[0];
+	    nextsub++;
+         }
+         else
+            nextsubcode = ' ';
+
+         if (sub)
+         {
+	    if (!out_subfield(sub, ftag, subcode, nextsubcode)) 
+	       return 0;
+/*          printf("Denne |%c| Neste |%c|\n", subcode, nextsubcode);  */
+         }
+
+         if (nextsub)
+         {
+            subcode = nextsubcode;
+            sub = nextsub;
+         }
+         else
+            moresubs = 0;
+      }
+   }
+
+   if (strcmp(ftag,TAG001) == 0 || strcmp(ftag,TAG008) == 0)              
+      return 1;                                  /* directory ready         */
+
+   strcat(data_field, FIELD_TERMINATOR);         /* terminate data field   */
+   fLen = strlen(data_field) - fStart;           /* length of field        */
+
+   strcpy(lnumber,itoal(fLen,4));                /* convert to 4digit str  */
+   if (!lnumber) return 0;
+   strcpy(snumber,itoal(fStart + skip,5));       /* convert start          */
+   if (!snumber) return 0;
+
+   strcpy(direlem[dircntr], ftag);               /* start direlem with tag */
+   strcat(direlem[dircntr], lnumber);            /* append length to dir   */
+   strcat(direlem[dircntr], snumber);            /* append start to dir    */
+   dircntr++;
+
+   return 1;
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* Main program                                                        */
+/* ------------------------------------------------------------------- */
+
+char *MARC2709(char *record, int last, int first, char recstatus, 
+  char rectype, char biblevel)          
+{
+   static char buffer[10240], field_data[5120], tag[4], ind[3];
+   char        alen[3], *cp, *buf = buffer, *cq, logline[128];
+   int                  prelen, ii; 
+   int                  lastchar, Last, First, x, more;
+   int			SOF, digits, newField;
+
+   char test[6];
+
+   strcpy(buf, record);
+
+   Last = First = 0;                        /* initialize             */
+   if (last > 0)                            /* Last : linelength if   */
+   {                                        /*        fixed           */
+      Last = last;                          /* First: starting col    */
+      First = first;                        /*        for cont. line  */
+   }
+  
+   prelen = 5;
+   dollar = '$';
+   strcpy(dollarstring, "$");
+
+   data_field[0] = '\0';
+   directory[0]  = '\0';
+   strcpy(field_001, "         ");
+   strcpy(field_008, "                                        ");
+   out_record[0] = '\0';
+   dircntr       = 0;
+   startet       = 0;
+
+   /* initialize directory  with 9 bytes for 001 */
+
+   sprintf(directory, "001001000000008004100010", alen, alen);
+   skip = SKIP + 10;
+
+   more = 1; 
+   while (more)                                       /* loop until EOR  */ 
+   {
+      x = 0;                                          /* x counts bytes  */
+
+      for (cp = buf; *cp && *cp != '\n'; cp++) x++;   /* read until LF   */
+
+      if (!*cp)                                       /* EOR             */
+        more = 0; 
+      else
+        cp++;
+
+      SOF = 0;
+
+      if (buf[0] == '^') break;                       /* "EOR-line"      */
+      if (buf[0] == '*')                              /* skip leading *  */
+      {
+	 buf++;
+	 x--;
+         SOF = 1;
+      }
+
+      if (x == 0) continue;                           /* empty line     */
+
+      digits = 1;                                     /* test if first 3     */ 
+      for (ii = 0; ii < 3; ii++)                      /* bytes are digits    */
+         if (!isdigit(buf[ii]))
+         {
+            digits = 0;
+            break;
+         }
+         
+      newField = 0;     
+
+      if (SOF)
+      {
+	if (!digits) continue;                      /* illegal line        */
+        else newField = 1;
+      } 
+      else
+	 if (digits) newField = 1;
+
+
+      if (newField)                                  /* start of new field   */
+      {
+	 if (!out_field(field_data, tag, ind))       /* output prev. field   */
+	    return NULL;
+
+	 startet = 1;
+	 field_data[0] = '\0';                       /* reset field buffer   */
+	 strncpy(tag, buf, 3);                       /* keep MARC tag        */
+	 buf += 3;
+	 x -=3;
+     
+         if (strncmp(tag, "00", 2) != 0) 
+         {
+            strncpy(ind, buf, 2);                 /* keep indicator       */
+            buf += 2;                             /* if not control field */
+            x -= 2;
+         }
+
+	 strncat(field_data, buf, x);             /* keep data               */
+        
+	   					/* strip trailing blanks   */
+	 while (field_data[strlen(field_data) -1] == ' ')
+	 {
+	    field_data[strlen(field_data) -1] = '\0';
+	    x--;
+	 }
+
+	 if (Last && x == (Last - prelen))           /* full line            */
+            lastchar = 1;
+         else 
+            lastchar = 0;
+      }
+
+      else                                     /* continuation line     */
+      {
+	if (Last)
+	{
+	   cq  = buf + First - 1;              /* skip fixed nmbr chars */
+	   x -= (First - 1); 
+	   if (!lastchar && cq[0] != ' '       /* and insert one blank  */
+	       && cq[0] != dollar)
+	      strcat(field_data, " ");         /* if needed             */
+	}
+	else
+	{
+	   for (cq = buf; *cq == ' '; cq++) x--;  /* skip leading blanks   */
+	   strcat(field_data, " ");               /* insert one blank      */
+	}
+
+	strncat(field_data, cq, x);            /* append data           */
+                                               /* strip trail. blanks   */
+        while (field_data[strlen(field_data) -1] == ' ')
+        {
+	   field_data[strlen(field_data) -1] = '\0';
+	   x--;
+	}
+
+	if (Last && x == (Last - 5))           /* full line            */
+	   lastchar = 1;
+        else lastchar = 0;
+        
+      }
+
+      while (field_data[strlen(field_data) -1] == ' ')
+         field_data[strlen(field_data) - 1] = '\0'; /* rm trailing blanks */
+      buf = cp;
+   }
+
+   if (!out_field(field_data, tag, ind))       /* output last field     */
+      return NULL;
+
+                                               /* terminate field_001   */
+   strcat(field_001, FIELD_TERMINATOR); 
+
+   field_008[40] = '\0';                       /* terminate field_008   */
+   strcat(field_008, FIELD_TERMINATOR); 
+
+					       /* sort directory elem.  */
+   qsort ((void *) direlem, dircntr, sizeof(direlem[0]), cmp); 
+   for (ii = 0; ii < dircntr; ii++)
+      strcat(directory, direlem[ii]);          /* append to directory   */
+
+   strcat(directory, FIELD_TERMINATOR);        /* terminate dictionary  */ 
+   
+   strcat(data_field, RECORD_TERMINATOR);      /* terminate data        */
+
+   x = 24 + strlen(directory);                 /* construct leader      */
+   
+   strcpy(test, itoal(x,5));
+
+   strncpy(ldr.ltab.base_adress, test, 5);
+
+   x += (strlen(data_field)
+       + strlen(field_001)
+       + strlen(field_008));
+
+   strcpy(test, itoal(x,5));
+   
+   strncpy(ldr.ltab.record_length, test, 5);
+   
+   ldr.ltab.record_status = recstatus;
+   ldr.ltab.record_type = rectype;
+   ldr.ltab.bibliographic_level = biblevel;
+   ldr.ltab.indicator_count = INDICATOR_COUNT;
+   ldr.ltab.subfield_code_count = SUBFIELD_CODE_COUNT;
+   strncpy(ldr.ltab.unused1,UNUSED,2);
+   strncpy(ldr.ltab.unused2,UNUSED,3);
+   ldr.ltab.entry1 = LENGTH_OF_LENGTH_OF_FIELD;
+   ldr.ltab.entry2 = LENGTH_OF_STARTING_CHARACTER_POSITION;
+   ldr.ltab.entry3 = '0';     
+   ldr.ltab.entry4 = '0';     
+
+   ldr.ldr_string[24] = '\0';
+
+   strcpy(out_record, ldr.ldr_string);          /* put together record  */
+   strcat(out_record, directory);
+   strcat(out_record, field_001);
+   strcat(out_record, field_008);
+   strcat(out_record, data_field);
+ 
+   return out_record; 
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/MARCmake.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/MARCmake.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/MARCmake.c	(revision 16571)
@@ -0,0 +1,33 @@
+/* ------------------------------------------------------------------- */
+/* MARCmake  : Convert a metatag struct to MARC and add it to the      */
+/*             marcrecord struct.                                      */
+/*                                                                     */
+/*             This is where the format-dependent conversion           */
+/*             program is selected.                                    */
+/*                                                                     */
+/* Author    : Ole Husby                                               */
+/* Updated   : 1998-09-30                                              */
+/* ------------------------------------------------------------------- */
+
+#include <stdio.h>
+#include "d2m.h" 
+
+
+
+int MARCmake(struct metatag *mt, struct marcrec *mr, int format)
+{
+  char pre[64], creator_tag[4];
+
+  if (format == DANMARC)
+    return danMARC(mt, mr);
+  else if (format == FINMARC)
+    return finMARC(mt, mr);
+  else if (format == ISMARC)
+    return isMARC(mt, mr);
+  else if (format == USMARC)
+    return usMARC(mt, mr);
+  else if (format == SWEMARC)
+    return sweMARC(mt, mr);
+  else
+    return norMARC(mt, mr);
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/MARCtidy.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/MARCtidy.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/MARCtidy.c	(revision 16571)
@@ -0,0 +1,147 @@
+/* ------------------------------------------------------------------- */
+/* MARCtidy  : Tidying up of MARC record, building the line format     */
+/*             record.                                                 */
+/*                                                                     */
+/* Syntax    : MARCtidy(marcrec *mrec, char *buf, int format)          */
+/*                                                                     */
+/*             The preliminary MARC data are converted from the        */
+/*             mrec struct to the buf line format buffer.              */
+/*                                                                     */
+/*             The main data is in mrec->marcline, while some          */
+/*             additional data (year, URL ...) are kept in separat     */
+/*             variables to be added in.                               */
+/*                                                                     */
+/* NOTE      : The behaviour of this program i sto some extent         */
+/*             depending on the format argument!                       */
+/*                                                                     */
+/* Author    : Ole Husby, BIBSYS                                       */
+/* Updated   : 1998-09-30                                              */
+/* ------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include "d2m.h"
+
+
+
+void  nline(char *p, char *l, char *buf)
+{
+   strcat(buf, p);
+   if (strncmp(p, "00", 2) != 0)
+     strcat(buf, " ");
+   strcat(buf, l);
+   strcat(buf, "\n");
+}
+
+
+
+void MARCtidy(struct marcrec *mrec, char *buf, int format)
+{
+
+   char *p, *u, *l;
+   char pre[64], line[10000];
+
+   p = (char *) &pre;
+   l = (char *) &line;
+
+   *buf = 0;
+
+   strcpy(p, "008");
+   strcpy(l, mrec->s008);
+   nline(p, l, buf);
+
+   u = strtok(mrec->marcline, "\n");
+   while (u && *u)
+   {
+      if (strlen(u) > 7)
+      {
+        *p = 0;
+        strncat(p, u, 7);
+        strcpy(l, u + 8);
+        nline(p, l, buf);
+
+
+/*      Add 245 subfields after $a */
+
+        if ( (strncmp(p, "245", 3) == 0) && (strncmp(p + 5, "$a", 2) == 0) )
+        {
+          if ( ( format == NORMARC ) && ( *mrec->subtitle) )
+          {
+            strcpy(p, "     $b");
+            strcpy(l, mrec->subtitle);
+            nline(p, l, buf);
+          }
+          if ( *mrec->partitle )
+          {
+            if ( format == FINMARC || format == DANMARC ) 
+            {
+              strcpy(p, "    ");
+              strcpy(l, mrec->partitle);
+              nline(p, l, buf);
+            }
+            if ( format == ISMARC ) 
+            {
+              strcpy(l, mrec->partitle);
+              nline(p, l, buf);
+            }
+          }
+        } 
+
+/*      Add year as 260 $c after $b                                    */
+
+        if ( (strncmp(p, "260", 3) == 0) && (strncmp(p + 5, "$b", 2) == 0) )
+        {
+          if (*mrec->year)
+          {
+            strcpy(p, "     $c");
+            strcpy(l, mrec->year);
+            nline(p, l, buf);
+            *mrec->year = 0;
+          }
+        } 
+      }
+      u = strtok(NULL, "\n");
+   }
+
+/* Add year as 260 $c if not aleady done                               */
+
+   if (*mrec->year)
+   {
+     strcpy(p, "260  $c");
+     strcpy(l, mrec->year);
+     nline(p, l, buf);
+   }
+
+/* Add parallel title in spearate field  */
+
+   if ( *mrec->partitle && ( format == ISMARC ) ) 
+   {
+     strcpy(p, "24630$c");
+     strcpy(l, mrec->partitle);
+     nline(p, l, buf);
+   }
+
+
+/* Add URL as 856 $u                                                 */
+
+   if (*mrec->url)
+   {
+     strcpy(p, "856  $u");
+     strcpy(l, mrec->url);
+     nline(p, l, buf);
+
+/* Add format as $q                                                    */
+
+     if (*mrec->fmat)
+     {
+       strcpy(p, "     $q");
+       strcpy(l, mrec->fmat);
+       nline(p, l, buf);
+     }
+   }
+
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/Makefile.in
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/Makefile.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/Makefile.in	(revision 16571)
@@ -0,0 +1,45 @@
+# ///////////////// d2m : Dublin Core to MARC converter /////////////////////
+#
+#
+# Modified for Greenstone kjdon May 2005.
+# Used by z3950server
+
+CC = @CC@
+AR = ar
+RANLIB = @RANLIB@
+
+o = .@U@o
+
+# This may have to uncomment this on solaris ???
+# LIBS = -lsocket -lnsl
+
+LIB_OBJS = MARC2709.o MARCtidy.o usMARC.o util.o
+
+all: libd2m.a
+
+libd2m.a: $(LIB_OBJS)
+	rm -f libd2m.a
+	$(AR) cru libd2m.a $(LIB_OBJS)
+	$(RANLIB) libd2m.a
+
+
+MARCtidy.o: MARCtidy.c d2m.h
+	$(CC) -c MARCtidy.c
+
+MARC2709.o: MARC2709.c d2m.h
+	$(CC) -c MARC2709.c
+
+util.o: util.c d2m.h
+	$(CC) -c util.c 
+
+usMARC.o: usMARC.c d2m.h
+	$(CC) -c usMARC.c
+
+install:
+
+clean:
+	rm -f *.o libd2m.a
+
+distclean: clean
+	rm -f Makefile config.h
+
Index: /gsdl/trunk/runtime-src/packages/d2m/Makefile.orig
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/Makefile.orig	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/Makefile.orig	(revision 16571)
@@ -0,0 +1,111 @@
+# ///////////////// d2m : Dublin Core to MARC converter /////////////////////
+#
+# The basic conversion (reading a file and producing a MARC record)
+# is performed by D2Mconv.c
+#
+# On top of D2Mconv.c is built 2 applications:
+#
+# d2m   : A CGI version
+#         (See documentation in main program D2Mcgi.c)
+# d2main: A command line (standalone version)
+#         (See documentation in main program D2Mmain.c)
+#
+# Both applications are capable of reading from a local file or a
+# remote file using builtin HTTP client services. 
+#
+# (You can compile a version of d2main without HTTP ability by
+#   make d2main-nosock 
+# )
+#
+# Both applications has the added ability to read a 2709 MARC record
+# instead of DC metadata, using M2Mconv.c to perform the conversion.
+# (This is not a MARC converter with the ability to convert between
+# MARC formats, just between "presentation syntaxes".
+#
+# 1998-10-15 Ole Husby
+#
+
+CC = cc 
+
+# This may have to uncomment this on solaris:
+# LIBS = -lsocket -lnsl
+
+OBJ = D2Mconv.o M2Mconv.o marc2line.o util.o MARC2709.o MARCmake.o MARCtidy.o dc_parse.o
+OBJ_MARC = danMARC.o finMARC.o isMARC.o norMARC.o sweMARC.o usMARC.o
+OBJ_SOCK = wfetch.o htget.o
+OBJ_NOSOCK = wfetch-l.o
+
+all: d2m d2main
+
+d2m: D2Mcgi.o $(OBJ) $(OBJ_MARC) $(OBJ_SOCK) 
+	@echo "------------------- Compiling d2m -------------------------------" 
+	$(CC) D2Mcgi.o $(OBJ) $(OBJ_MARC) $(OBJ_SOCK) -o d2m $(LIBS) 
+
+d2main: D2Mmain.o $(OBJ) $(OBJ_MARC) $(OBJ_SOCK) 
+	@echo "------------------- Compiling d2main ----------------------------" 
+	$(CC) D2Mmain.o $(OBJ) $(OBJ_MARC) $(OBJ_SOCK) -o d2main $(LIBS) 
+
+d2main-nosock: D2Mmain.o $(OBJ) $(OBJ_MARC) $(OBJ_NOSOCK) 
+	@echo "------------------- Compiling d2main (no sockets) ---------------" 
+	$(CC) D2Mmain.o $(OBJ) $(OBJ_MARC) $(OBJ_NOSOCK) -o d2main $(LIBS) 
+
+
+D2Mcgi.o: D2Mcgi.c d2m.h
+	$(CC) -c D2Mcgi.c
+
+D2Mmain.o: D2Mmain.c d2m.h
+	$(CC) -c D2Mmain.c
+
+D2Mconv.o: D2Mconv.c d2m.h
+	$(CC) -c D2Mconv.c
+
+M2Mconv.o: M2Mconv.c
+	$(CC) -c M2Mconv.c
+
+marc2line.o: marc2line.c 
+	$(CC) -c marc2line.c
+
+MARCmake.o: MARCmake.c d2m.h
+	$(CC) -c MARCmake.c
+
+MARCtidy.o: MARCtidy.c d2m.h
+	$(CC) -c MARCtidy.c
+
+MARC2709.o: MARC2709.c d2m.h
+	$(CC) -c MARC2709.c
+
+dc_parse.o: dc_parse.c d2m.h
+	$(CC) -c dc_parse.c
+
+util.o: util.c d2m.h
+	$(CC) -c util.c 
+
+danMARC.o: danMARC.c d2m.h
+	$(CC) -c danMARC.c
+
+finMARC.o: finMARC.c d2m.h
+	$(CC) -c finMARC.c
+
+isMARC.o: isMARC.c d2m.h
+	$(CC) -c isMARC.c
+
+norMARC.o: norMARC.c d2m.h
+	$(CC) -c norMARC.c
+
+sweMARC.o: sweMARC.c d2m.h
+	$(CC) -c sweMARC.c
+
+usMARC.o: usMARC.c d2m.h
+	$(CC) -c usMARC.c
+
+wfetch.o: wfetch.c
+	$(CC) -c wfetch.c
+
+wfetch-l.o: wfetch-l.c
+	$(CC) -c wfetch-l.c
+
+htget.o: htget.c 
+	$(CC) -c htget.c 
+
+clean:
+	rm -f *.o d2m d2main
Index: /gsdl/trunk/runtime-src/packages/d2m/README.html
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/README.html	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/README.html	(revision 16571)
@@ -0,0 +1,159 @@
+<html><head><title>
+d2m v0.2
+</title>
+</head>
+
+<body bgcolor="#ffffcc">
+
+<font face="Comic Sans MS">
+<h1 align=center>d2m : A Dublin Core to MARC converter</h1>
+
+<div align=center>
+
+version 0.2<br>
+1998-10-14<br>
+Ole Husby<br>
+BIBSYS<br>
+ole.husby@bibsys.no
+</div>
+</font>
+
+
+<h2>1. Introduction</h2>
+
+This software is part of the results from the Nordic Metadata project.
+(See <a href="http://linnea.helsinki.fi/meta/">
+http://linnea.helsinki.fi/meta/</a>).
+
+<p>
+ 
+This version is a "pre-release". It is not really ready for distribution.
+All the customary disclaimers apply!
+The programs have been compiled on Solaris, AIX and Linux.
+
+
+
+<h2>2. Contents</h2>
+
+The distribution includes the following files:
+
+<table>
+<tr><td><b>README.html </b></td><td>This file</td></tr>
+<tr><td><b>Makefile    </b></td><td>Also includes some documentation</td></tr>
+<tr><td><b>d2m.h       </b></td><td>Common include file</td></tr>
+<tr><td><b>D2Mcgi.c    </b></td><td>Main program for the CGI version</td></tr>
+<tr><td><b>D2Mmain.c   </b></td><td>Main program for the standalone version</td></tr>
+<tr><td><b>D2Mconv.c   </b></td><td>Inputs file with DC metadata, outputs line MARC record</td></tr>
+<tr><td><b>M2Mconv.c   </b></td><td>Inputs file with ISO 2709 MARC record, outputs line MARC record</td></tr>
+<tr><td><b>MARC2709.c  </b></td><td>Converts from line MARC format to ISO 2709 MARC format</td></tr>
+<tr><td><b>MARCmake.c  </b></td><td>Builds a MARC struct from a DC struct. Selects one of the following :</td></tr>
+<tr><td><b>danMARC.c   </b></td><td>&nbsp;</td></tr>
+<tr><td><b>finMARC.c   </b></td><td>&nbsp;</td></tr>
+<tr><td><b>isMARC.c    </b></td><td>&nbsp;</td></tr>
+<tr><td><b>norMARC.c   </b></td><td>&nbsp;</td></tr>
+<tr><td><b>sweMARC.c   </b></td><td>&nbsp;</td></tr>
+<tr><td><b>usMARC.c    </b></td><td>&nbsp;</td></tr>
+<tr><td><b>MARCtidy.c  </b></td><td>Finishes the line MARC record from the MARC struct</td></tr>
+<tr><td><b>marc2line.c </b></td><td>Converts from ISO 2709 MARC format to line MARC format</td></tr>
+<tr><td><b>htget.c     </b></td><td>Fetches a remote file using HTTP</td></tr>
+<tr><td><b>dc_parse.c  </b></td><td>Parses an HTML <META> tag</td></tr>
+<tr><td><b>util.c      </b></td><td>Some utilities</td></tr>
+<tr><td><b>wfetch.c    </b></td><td>Small program on top of htget()</td></tr>
+<tr><td><b>wfetch-l.c  </b></td><td>Dummy version of wfetch.c, does nothing except return 0</td></tr>
+<tr><td><b>test.data   </b></td><td>A simple test file with a <meta> tag.</td></tr>
+</table>
+
+<h2>3. Compilation</h2>
+
+Unpack the d2m-v02.tar file. It will produce a directory <b>d2m-v02/</b>
+with the contents listed above.
+
+<p>
+
+Check the Makefile.
+
+<p>
+
+Type
+
+<pre>
+
+  <b>make all</b>
+
+</pre>
+
+This should produce the programs <b>d2m</b> and <b>d2main</b> . 
+
+<p>
+
+If you do not need access to remote files, or have problems compiling
+socket libraries, try to compile
+  
+<pre>
+
+  <b>make d2main-nosock</b>
+
+</pre>
+
+
+<h2>4. Use of d2main</h2>
+
+<b>d2main</b> should be ready to execute from the command line. No configuration
+or environment variables are needed.
+
+<p>
+
+If you do not enter any arguments, a short instruction will be printed.
+
+<p>
+
+The first test could be 
+
+<pre>
+
+  <b>d2main test.data -l</b>
+
+</pre>
+
+The next test could be (if d2main is not compiled using Makefile-l)
+
+<pre>
+
+  <b>d2main http://linnea.helsinki.fi/meta/ -l -m FINMARC</b>
+
+</pre>
+
+<h2>5. Use of d2m</h2>
+
+<b>d2m</b> should be used as a CGI program.
+
+<p>
+  
+A simple users guide is in D2Mcgi.c
+
+<p>
+
+See an example of use in <a href="http://www.bibsys.no/meta/d2m">
+http://www.bibsys.no/meta/d2m</a>
+
+
+
+<h2>6. Tailoring</h2>
+
+This version is not table-driven. The different MARC formats are
+treated by customized functions (norMARC.c, isMARC.c etc.). The
+selection of conversion program is performed by MARKmake.c .
+
+<p>
+
+The program MARCtidy.c is also to some degree depending of the
+MARC format. In addition there is a small sequence in D2Mconv.c
+with a special treatment for ISMARC. (It should really not be
+done there ...). Apart from this, all programs are independent on
+MARC format.
+
+<p>
+
+The supported formats are introduced in d2m.h .
+
+</body></html>
Index: /gsdl/trunk/runtime-src/packages/d2m/README_GS
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/README_GS	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/README_GS	(revision 16571)
@@ -0,0 +1,14 @@
+d2m : Dublin Core to MARC converter
+Software distribution: Prerelease version
+version 0.2
+1998-10-14
+Ole Husby
+BIBSYS
+ole.husby@bibsys.no
+
+http://www.bibsys.no/meta/d2m/distr/
+
+The original Makefile that comes with d2m has been saved as Makefile.orig, and a new Makefile.in and some configure scripts have been generated for use with Greenstone.
+
+We no longer compile up the two executables, instead just compile the source into a library: libd2m.a.
+
Index: /gsdl/trunk/runtime-src/packages/d2m/config.h.in
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/config.h.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/config.h.in	(revision 16571)
@@ -0,0 +1,107 @@
+/* config.h.in.  Generated from configure.in by autoheader.  */
+
+/* Define to 1 if you have the `alarm' function. */
+#undef HAVE_ALARM
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#undef HAVE_FCNTL_H
+
+/* Define to 1 if you have the `gethostbyname' function. */
+#undef HAVE_GETHOSTBYNAME
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+   to 0 otherwise. */
+#undef HAVE_MALLOC
+
+/* Define to 1 if you have the <malloc.h> header file. */
+#undef HAVE_MALLOC_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#undef HAVE_NETDB_H
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#undef HAVE_NETINET_IN_H
+
+/* Define to 1 if you have the `putenv' function. */
+#undef HAVE_PUTENV
+
+/* Define to 1 if you have the `socket' function. */
+#undef HAVE_SOCKET
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the `strcasecmp' function. */
+#undef HAVE_STRCASECMP
+
+/* Define to 1 if you have the `strdup' function. */
+#undef HAVE_STRDUP
+
+/* Define to 1 if you have the `strftime' function. */
+#undef HAVE_STRFTIME
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the `strncasecmp' function. */
+#undef HAVE_STRNCASECMP
+
+/* Define to 1 if you have the `strstr' function. */
+#undef HAVE_STRSTR
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#undef HAVE_SYS_SOCKET_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#undef RETSIGTYPE
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Define to 1 if your <sys/time.h> declares `struct tm'. */
+#undef TM_IN_SYS_TIME
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
+
+/* Define to rpl_malloc if the replacement function should be used. */
+#undef malloc
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+#undef size_t
Index: /gsdl/trunk/runtime-src/packages/d2m/configure
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/configure	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/configure	(revision 16571)
@@ -0,0 +1,4903 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.59 for FULL-PACKAGE-NAME VERSION.
+#
+# Report bugs to <BUG-REPORT-ADDRESS>.
+#
+# Copyright (C) 2003 Free Software Foundation, Inc.
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+  set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+  LC_TELEPHONE LC_TIME
+do
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+    eval $as_var=C; export $as_var
+  else
+    $as_unset $as_var
+  fi
+done
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)$' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\/\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+
+
+# PATH needs CR, and LINENO needs CR and PATH.
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
+  # Find who we are.  Look in the path if we contain no path at all
+  # relative or not.
+  case $0 in
+    *[\\/]* ) as_myself=$0 ;;
+    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+
+       ;;
+  esac
+  # We did not find ourselves, most probably we were run as `sh COMMAND'
+  # in which case we are not to be found in the path.
+  if test "x$as_myself" = x; then
+    as_myself=$0
+  fi
+  if test ! -f "$as_myself"; then
+    { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2
+   { (exit 1); exit 1; }; }
+  fi
+  case $CONFIG_SHELL in
+  '')
+    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for as_base in sh bash ksh sh5; do
+	 case $as_dir in
+	 /*)
+	   if ("$as_dir/$as_base" -c '
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
+	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
+	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
+	     CONFIG_SHELL=$as_dir/$as_base
+	     export CONFIG_SHELL
+	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
+	   fi;;
+	 esac
+       done
+done
+;;
+  esac
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line before each line; the second 'sed' does the real
+  # work.  The second script uses 'N' to pair each line-number line
+  # with the numbered line, and appends trailing '-' during
+  # substitution so that $LINENO is not a special case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
+  sed '=' <$as_myself |
+    sed '
+      N
+      s,$,-,
+      : loop
+      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+      t loop
+      s,-$,,
+      s,^['$as_cr_digits']*\n,,
+    ' >$as_me.lineno &&
+  chmod +x $as_me.lineno ||
+    { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensible to this).
+  . ./$as_me.lineno
+  # Exit status is that of the last command.
+  exit
+}
+
+
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+  *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T='	' ;;
+  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+echo >conf$$.file
+if ln -s conf$$.file conf$$ 2>/dev/null; then
+  # We could just check for DJGPP; but this test a) works b) is more generic
+  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
+  if test -f conf$$.exe; then
+    # Don't use ln at all; we don't have any links
+    as_ln_s='cp -p'
+  else
+    as_ln_s='ln -s'
+  fi
+elif ln conf$$.file conf$$ 2>/dev/null; then
+  as_ln_s=ln
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.file
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p=:
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_executable_p="test -f"
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.
+as_nl='
+'
+IFS=" 	$as_nl"
+
+# CDPATH.
+$as_unset CDPATH
+
+
+# Name of the host.
+# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+exec 6>&1
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_config_libobj_dir=.
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+# Maximum number of lines to put in a shell here document.
+# This variable seems obsolete.  It should probably be removed, and
+# only ac_max_sed_lines should be used.
+: ${ac_max_here_lines=38}
+
+# Identity of this package.
+PACKAGE_NAME='FULL-PACKAGE-NAME'
+PACKAGE_TARNAME='full-package-name'
+PACKAGE_VERSION='VERSION'
+PACKAGE_STRING='FULL-PACKAGE-NAME VERSION'
+PACKAGE_BUGREPORT='BUG-REPORT-ADDRESS'
+
+ac_unique_file="danMARC.c"
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#if STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# if HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#if HAVE_STRING_H
+# if !STDC_HEADERS && HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#if HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#else
+# if HAVE_STDINT_H
+#  include <stdint.h>
+# endif
+#endif
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT RANLIB ac_ct_RANLIB CPP EGREP LIBOBJS LTLIBOBJS'
+ac_subst_files=''
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datadir='${prefix}/share'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+libdir='${exec_prefix}/lib'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+infodir='${prefix}/info'
+mandir='${prefix}/man'
+
+ac_prev=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval "$ac_prev=\$ac_option"
+    ac_prev=
+    continue
+  fi
+
+  ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_option in
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+  | --da=*)
+    datadir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid feature name: $ac_feature" >&2
+   { (exit 1); exit 1; }; }
+    ac_feature=`echo $ac_feature | sed 's/-/_/g'`
+    eval "enable_$ac_feature=no" ;;
+
+  -enable-* | --enable-*)
+    ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid feature name: $ac_feature" >&2
+   { (exit 1); exit 1; }; }
+    ac_feature=`echo $ac_feature | sed 's/-/_/g'`
+    case $ac_option in
+      *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
+      *) ac_optarg=yes ;;
+    esac
+    eval "enable_$ac_feature='$ac_optarg'" ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst \
+  | --locals | --local | --loca | --loc | --lo)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+  | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid package name: $ac_package" >&2
+   { (exit 1); exit 1; }; }
+    ac_package=`echo $ac_package| sed 's/-/_/g'`
+    case $ac_option in
+      *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
+      *) ac_optarg=yes ;;
+    esac
+    eval "with_$ac_package='$ac_optarg'" ;;
+
+  -without-* | --without-*)
+    ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid package name: $ac_package" >&2
+   { (exit 1); exit 1; }; }
+    ac_package=`echo $ac_package | sed 's/-/_/g'`
+    eval "with_$ac_package=no" ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) { echo "$as_me: error: unrecognized option: $ac_option
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; }
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
+      { echo "$as_me: error: invalid variable name: $ac_envvar" >&2
+   { (exit 1); exit 1; }; }
+    ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
+    eval "$ac_envvar='$ac_optarg'"
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  { echo "$as_me: error: missing argument to $ac_option" >&2
+   { (exit 1); exit 1; }; }
+fi
+
+# Be sure to have absolute paths.
+for ac_var in exec_prefix prefix
+do
+  eval ac_val=$`echo $ac_var`
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* | NONE | '' ) ;;
+    *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# Be sure to have absolute paths.
+for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \
+	      localstatedir libdir includedir oldincludedir infodir mandir
+do
+  eval ac_val=$`echo $ac_var`
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* ) ;;
+    *)  { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+    echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
+    If a cross compiler is detected then cross compile mode will be used." >&2
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then its parent.
+  ac_confdir=`(dirname "$0") 2>/dev/null ||
+$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$0" : 'X\(//\)[^/]' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$0" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r $srcdir/$ac_unique_file; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r $srcdir/$ac_unique_file; then
+  if test "$ac_srcdir_defaulted" = yes; then
+    { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2
+   { (exit 1); exit 1; }; }
+  else
+    { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
+   { (exit 1); exit 1; }; }
+  fi
+fi
+(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null ||
+  { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2
+   { (exit 1); exit 1; }; }
+srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'`
+ac_env_build_alias_set=${build_alias+set}
+ac_env_build_alias_value=$build_alias
+ac_cv_env_build_alias_set=${build_alias+set}
+ac_cv_env_build_alias_value=$build_alias
+ac_env_host_alias_set=${host_alias+set}
+ac_env_host_alias_value=$host_alias
+ac_cv_env_host_alias_set=${host_alias+set}
+ac_cv_env_host_alias_value=$host_alias
+ac_env_target_alias_set=${target_alias+set}
+ac_env_target_alias_value=$target_alias
+ac_cv_env_target_alias_set=${target_alias+set}
+ac_cv_env_target_alias_value=$target_alias
+ac_env_CC_set=${CC+set}
+ac_env_CC_value=$CC
+ac_cv_env_CC_set=${CC+set}
+ac_cv_env_CC_value=$CC
+ac_env_CFLAGS_set=${CFLAGS+set}
+ac_env_CFLAGS_value=$CFLAGS
+ac_cv_env_CFLAGS_set=${CFLAGS+set}
+ac_cv_env_CFLAGS_value=$CFLAGS
+ac_env_LDFLAGS_set=${LDFLAGS+set}
+ac_env_LDFLAGS_value=$LDFLAGS
+ac_cv_env_LDFLAGS_set=${LDFLAGS+set}
+ac_cv_env_LDFLAGS_value=$LDFLAGS
+ac_env_CPPFLAGS_set=${CPPFLAGS+set}
+ac_env_CPPFLAGS_value=$CPPFLAGS
+ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set}
+ac_cv_env_CPPFLAGS_value=$CPPFLAGS
+ac_env_CPP_set=${CPP+set}
+ac_env_CPP_value=$CPP
+ac_cv_env_CPP_set=${CPP+set}
+ac_cv_env_CPP_value=$CPP
+
+#
+# Report the --help message.
+#
+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 FULL-PACKAGE-NAME VERSION to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+_ACEOF
+
+  cat <<_ACEOF
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+			  [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+			  [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR           user executables [EPREFIX/bin]
+  --sbindir=DIR          system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR       program executables [EPREFIX/libexec]
+  --datadir=DIR          read-only architecture-independent data [PREFIX/share]
+  --sysconfdir=DIR       read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR   modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR    modifiable single-machine data [PREFIX/var]
+  --libdir=DIR           object code libraries [EPREFIX/lib]
+  --includedir=DIR       C header files [PREFIX/include]
+  --oldincludedir=DIR    C header files for non-gcc [/usr/include]
+  --infodir=DIR          info documentation [PREFIX/info]
+  --mandir=DIR           man documentation [PREFIX/man]
+_ACEOF
+
+  cat <<\_ACEOF
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+  case $ac_init_help in
+     short | recursive ) echo "Configuration of FULL-PACKAGE-NAME VERSION:";;
+   esac
+  cat <<\_ACEOF
+
+Some influential environment variables:
+  CC          C compiler command
+  CFLAGS      C compiler flags
+  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+              nonstandard directory <lib dir>
+  CPPFLAGS    C/C++ preprocessor flags, e.g. -I<include dir> if you have
+              headers in a nonstandard directory <include dir>
+  CPP         C preprocessor
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to <BUG-REPORT-ADDRESS>.
+_ACEOF
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  ac_popdir=`pwd`
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d $ac_dir || continue
+    ac_builddir=.
+
+if test "$ac_dir" != .; then
+  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  # A "../" for each directory in $ac_dir_suffix.
+  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+  ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+  .)  # No --srcdir option.  We are building in place.
+    ac_srcdir=.
+    if test -z "$ac_top_builddir"; then
+       ac_top_srcdir=.
+    else
+       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+    fi ;;
+  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir ;;
+  *) # Relative path.
+    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
+
+    cd $ac_dir
+    # Check for guested configure; otherwise get Cygnus style configure.
+    if test -f $ac_srcdir/configure.gnu; then
+      echo
+      $SHELL $ac_srcdir/configure.gnu  --help=recursive
+    elif test -f $ac_srcdir/configure; then
+      echo
+      $SHELL $ac_srcdir/configure  --help=recursive
+    elif test -f $ac_srcdir/configure.ac ||
+	   test -f $ac_srcdir/configure.in; then
+      echo
+      $ac_configure --help
+    else
+      echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi
+    cd $ac_popdir
+  done
+fi
+
+test -n "$ac_init_help" && exit 0
+if $ac_init_version; then
+  cat <<\_ACEOF
+FULL-PACKAGE-NAME configure VERSION
+generated by GNU Autoconf 2.59
+
+Copyright (C) 2003 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit 0
+fi
+exec 5>config.log
+cat >&5 <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by FULL-PACKAGE-NAME $as_me VERSION, which was
+generated by GNU Autoconf 2.59.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+hostinfo               = `(hostinfo) 2>/dev/null               || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  echo "PATH: $as_dir"
+done
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_sep=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+      ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;;
+    2)
+      ac_configure_args1="$ac_configure_args1 '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+	ac_must_keep_next=false # Got value, back to normal.
+      else
+	case $ac_arg in
+	  *=* | --config-cache | -C | -disable-* | --disable-* \
+	  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+	  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+	  | -with-* | --with-* | -without-* | --without-* | --x)
+	    case "$ac_configure_args0 " in
+	      "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+	    esac
+	    ;;
+	  -* ) ac_must_keep_next=true ;;
+	esac
+      fi
+      ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'"
+      # Get rid of the leading space.
+      ac_sep=" "
+      ;;
+    esac
+  done
+done
+$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; }
+$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; }
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Be sure not to use single quotes in there, as some shells,
+# such as our DU 5.0 friend, will then `close' the trap.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    cat <<\_ASBOX
+## ---------------- ##
+## Cache variables. ##
+## ---------------- ##
+_ASBOX
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+{
+  (set) 2>&1 |
+    case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in
+    *ac_space=\ *)
+      sed -n \
+	"s/'"'"'/'"'"'\\\\'"'"''"'"'/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p"
+      ;;
+    *)
+      sed -n \
+	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+      ;;
+    esac;
+}
+    echo
+
+    cat <<\_ASBOX
+## ----------------- ##
+## Output variables. ##
+## ----------------- ##
+_ASBOX
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=$`echo $ac_var`
+      echo "$ac_var='"'"'$ac_val'"'"'"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      cat <<\_ASBOX
+## ------------- ##
+## Output files. ##
+## ------------- ##
+_ASBOX
+      echo
+      for ac_var in $ac_subst_files
+      do
+	eval ac_val=$`echo $ac_var`
+	echo "$ac_var='"'"'$ac_val'"'"'"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      cat <<\_ASBOX
+## ----------- ##
+## confdefs.h. ##
+## ----------- ##
+_ASBOX
+      echo
+      sed "/^$/d" confdefs.h | sort
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      echo "$as_me: caught signal $ac_signal"
+    echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core &&
+  rm -rf conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+     ' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -rf conftest* confdefs.h
+# AIX cpp loses on an empty file, so make sure it contains at least a newline.
+echo >confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer explicitly selected file to automatically selected ones.
+if test -z "$CONFIG_SITE"; then
+  if test "x$prefix" != xNONE; then
+    CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
+  else
+    CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
+  fi
+fi
+for ac_site_file in $CONFIG_SITE; do
+  if test -r "$ac_site_file"; then
+    { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5
+echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file"
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special
+  # files actually), so we avoid doing that.
+  if test -f "$cache_file"; then
+    { echo "$as_me:$LINENO: loading cache $cache_file" >&5
+echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . $cache_file;;
+      *)                      . ./$cache_file;;
+    esac
+  fi
+else
+  { echo "$as_me:$LINENO: creating cache $cache_file" >&5
+echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in `(set) 2>&1 |
+	       sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val="\$ac_cv_env_${ac_var}_value"
+  eval ac_new_val="\$ac_env_${ac_var}_value"
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5
+echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+	{ echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5
+echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+	{ echo "$as_me:$LINENO:   former value:  $ac_old_val" >&5
+echo "$as_me:   former value:  $ac_old_val" >&2;}
+	{ echo "$as_me:$LINENO:   current value: $ac_new_val" >&5
+echo "$as_me:   current value: $ac_new_val" >&2;}
+	ac_cache_corrupted=:
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+      ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5
+echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5
+echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+          ac_config_headers="$ac_config_headers config.h"
+
+
+# Checks for programs.
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  CC=$ac_ct_CC
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="cc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  CC=$ac_ct_CC
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+fi
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  ac_prog_rejected=no
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+       ac_prog_rejected=yes
+       continue
+     fi
+    ac_cv_prog_CC="cc"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# != 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+  fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in cl
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+    test -n "$CC" && break
+  done
+fi
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in cl
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="$ac_prog"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$ac_ct_CC" && break
+done
+
+  CC=$ac_ct_CC
+fi
+
+fi
+
+
+test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&5
+echo "$as_me: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+
+# Provide some information about the compiler.
+echo "$as_me:$LINENO:" \
+     "checking for C compiler version" >&5
+ac_compiler=`set X $ac_compile; echo $2`
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
+  (eval $ac_compiler --version </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v </dev/null >&5\"") >&5
+  (eval $ac_compiler -v </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V </dev/null >&5\"") >&5
+  (eval $ac_compiler -V </dev/null >&5) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+echo "$as_me:$LINENO: checking for C compiler default output file name" >&5
+echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6
+ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5
+  (eval $ac_link_default) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # Find the output, starting from the most likely.  This scheme is
+# not robust to junk in `.', hence go to wildcards (a.*) only as a last
+# resort.
+
+# Be careful to initialize this variable, since it used to be cached.
+# Otherwise an old cache value of `no' led to `EXEEXT = no' in a Makefile.
+ac_cv_exeext=
+# b.out is created by i960 compilers.
+for ac_file in a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out
+do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj )
+	;;
+    conftest.$ac_ext )
+	# This is the source file.
+	;;
+    [ab].out )
+	# We found the default executable, but exeext='' is most
+	# certainly right.
+	break;;
+    *.* )
+	ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	# FIXME: I believe we export ac_cv_exeext for Libtool,
+	# but it would be cool to find out if it's true.  Does anybody
+	# maintain Libtool? --akim.
+	export ac_cv_exeext
+	break;;
+    * )
+	break;;
+  esac
+done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { echo "$as_me:$LINENO: error: C compiler cannot create executables
+See \`config.log' for more details." >&5
+echo "$as_me: error: C compiler cannot create executables
+See \`config.log' for more details." >&2;}
+   { (exit 77); exit 77; }; }
+fi
+
+ac_exeext=$ac_cv_exeext
+echo "$as_me:$LINENO: result: $ac_file" >&5
+echo "${ECHO_T}$ac_file" >&6
+
+# Check the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+echo "$as_me:$LINENO: checking whether the C compiler works" >&5
+echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6
+# FIXME: These cross compiler hacks should be removed for Autoconf 3.0
+# If not cross compiling, check that we can run a simple program.
+if test "$cross_compiling" != yes; then
+  if { ac_try='./$ac_file'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { echo "$as_me:$LINENO: error: cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+    fi
+  fi
+fi
+echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+
+rm -f a.out a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+# Check the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
+echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6
+echo "$as_me:$LINENO: result: $cross_compiling" >&5
+echo "${ECHO_T}$cross_compiling" >&6
+
+echo "$as_me:$LINENO: checking for suffix of executables" >&5
+echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;;
+    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	  export ac_cv_exeext
+	  break;;
+    * ) break;;
+  esac
+done
+else
+  { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+rm -f conftest$ac_cv_exeext
+echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5
+echo "${ECHO_T}$ac_cv_exeext" >&6
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+echo "$as_me:$LINENO: checking for suffix of object files" >&5
+echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6
+if test "${ac_cv_objext+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
+  for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg ) ;;
+    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+       break;;
+  esac
+done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_objext" >&5
+echo "${ECHO_T}$ac_cv_objext" >&6
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5
+echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6
+if test "${ac_cv_c_compiler_gnu+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_compiler_gnu=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_compiler_gnu=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5
+echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6
+GCC=`test $ac_compiler_gnu = yes && echo yes`
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+CFLAGS="-g"
+echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5
+echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6
+if test "${ac_cv_prog_cc_g+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cc_g=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_prog_cc_g=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_g" >&6
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+echo "$as_me:$LINENO: checking for $CC option to accept ANSI C" >&5
+echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6
+if test "${ac_cv_prog_cc_stdc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_prog_cc_stdc=no
+ac_save_CC=$CC
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std1 is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std1.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+  ;
+  return 0;
+}
+_ACEOF
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX			-qlanglvl=ansi
+# Ultrix and OSF/1	-std1
+# HP-UX 10.20 and later	-Ae
+# HP-UX older versions	-Aa -D_HPUX_SOURCE
+# SVR4			-Xc -D__EXTENSIONS__
+for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_prog_cc_stdc=$ac_arg
+break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext
+done
+rm -f conftest.$ac_ext conftest.$ac_objext
+CC=$ac_save_CC
+
+fi
+
+case "x$ac_cv_prog_cc_stdc" in
+  x|xno)
+    echo "$as_me:$LINENO: result: none needed" >&5
+echo "${ECHO_T}none needed" >&6 ;;
+  *)
+    echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6
+    CC="$CC $ac_cv_prog_cc_stdc" ;;
+esac
+
+# Some people use a C++ compiler to compile C.  Since we use `exit',
+# in C++ we need to declare it.  In case someone uses the same compiler
+# for both compiling C and C++ we need to have the C++ compiler decide
+# the declaration of exit, since it's the most demanding environment.
+cat >conftest.$ac_ext <<_ACEOF
+#ifndef __cplusplus
+  choke me
+#endif
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  for ac_declaration in \
+   '' \
+   'extern "C" void std::exit (int) throw (); using std::exit;' \
+   'extern "C" void std::exit (int); using std::exit;' \
+   'extern "C" void exit (int) throw ();' \
+   'extern "C" void exit (int);' \
+   'void exit (int);'
+do
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+#include <stdlib.h>
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+continue
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_declaration
+int
+main ()
+{
+exit (42);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+rm -f conftest*
+if test -n "$ac_declaration"; then
+  echo '#ifdef __cplusplus' >>confdefs.h
+  echo $ac_declaration      >>confdefs.h
+  echo '#endif'             >>confdefs.h
+fi
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_RANLIB+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  echo "$as_me:$LINENO: result: $RANLIB" >&5
+echo "${ECHO_T}$RANLIB" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+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_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+  test -z "$ac_cv_prog_ac_ct_RANLIB" && ac_cv_prog_ac_ct_RANLIB=":"
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5
+echo "${ECHO_T}$ac_ct_RANLIB" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  RANLIB=$ac_ct_RANLIB
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+
+# Checks for libraries.
+
+# Checks for header files.
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5
+echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+  if test "${ac_cv_prog_CPP+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+      # Double quotes because CPP needs to be expanded
+    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether non-existent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  # Broken: success on invalid input.
+continue
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  break
+fi
+
+    done
+    ac_cv_prog_CPP=$CPP
+
+fi
+  CPP=$ac_cv_prog_CPP
+else
+  ac_cv_prog_CPP=$CPP
+fi
+echo "$as_me:$LINENO: result: $CPP" >&5
+echo "${ECHO_T}$CPP" >&6
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether non-existent headers
+  # can be detected and how.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  # Broken: success on invalid input.
+continue
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
+  :
+else
+  { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&5
+echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+echo "$as_me:$LINENO: checking for egrep" >&5
+echo $ECHO_N "checking for egrep... $ECHO_C" >&6
+if test "${ac_cv_prog_egrep+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if echo a | (grep -E '(a|b)') >/dev/null 2>&1
+    then ac_cv_prog_egrep='grep -E'
+    else ac_cv_prog_egrep='egrep'
+    fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_egrep" >&5
+echo "${ECHO_T}$ac_cv_prog_egrep" >&6
+ EGREP=$ac_cv_prog_egrep
+
+
+echo "$as_me:$LINENO: checking for ANSI C header files" >&5
+echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6
+if test "${ac_cv_header_stdc+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_header_stdc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_header_stdc=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then
+  :
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then
+  :
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <ctype.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      exit(2);
+  exit (0);
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_header_stdc=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5
+echo "${ECHO_T}$ac_cv_header_stdc" >&6
+if test $ac_cv_header_stdc = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define STDC_HEADERS 1
+_ACEOF
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+
+
+
+
+
+
+
+
+
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+		  inttypes.h stdint.h unistd.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_Header=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_Header=no"
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+
+
+
+
+
+
+
+
+for ac_header in fcntl.h malloc.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+else
+  # Is the header compilable?
+echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_header_compiler=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <$ac_header>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    (
+      cat <<\_ASBOX
+## --------------------------------- ##
+## Report this to BUG-REPORT-ADDRESS ##
+## --------------------------------- ##
+_ASBOX
+    ) |
+      sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+# Checks for typedefs, structures, and compiler characteristics.
+echo "$as_me:$LINENO: checking for an ANSI C-conforming const" >&5
+echo $ECHO_N "checking for an ANSI C-conforming const... $ECHO_C" >&6
+if test "${ac_cv_c_const+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+/* FIXME: Include the comments suggested by Paul. */
+#ifndef __cplusplus
+  /* Ultrix mips cc rejects this.  */
+  typedef int charset[2];
+  const charset x;
+  /* SunOS 4.1.1 cc rejects this.  */
+  char const *const *ccp;
+  char **p;
+  /* NEC SVR4.0.2 mips cc rejects this.  */
+  struct point {int x, y;};
+  static struct point const zero = {0,0};
+  /* AIX XL C 1.02.0.0 rejects this.
+     It does not let you subtract one const X* pointer from another in
+     an arm of an if-expression whose if-part is not a constant
+     expression */
+  const char *g = "string";
+  ccp = &g + (g ? g-g : 0);
+  /* HPUX 7.0 cc rejects these. */
+  ++ccp;
+  p = (char**) ccp;
+  ccp = (char const *const *) p;
+  { /* SCO 3.2v4 cc rejects this.  */
+    char *t;
+    char const *s = 0 ? (char *) 0 : (char const *) 0;
+
+    *t++ = 0;
+  }
+  { /* Someone thinks the Sun supposedly-ANSI compiler will reject this.  */
+    int x[] = {25, 17};
+    const int *foo = &x[0];
+    ++foo;
+  }
+  { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
+    typedef const int *iptr;
+    iptr p = 0;
+    ++p;
+  }
+  { /* AIX XL C 1.02.0.0 rejects this saying
+       "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
+    struct s { int j; const int *ap[3]; };
+    struct s *b; b->j = 5;
+  }
+  { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
+    const int foo = 10;
+  }
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_c_const=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_c_const=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_const" >&5
+echo "${ECHO_T}$ac_cv_c_const" >&6
+if test $ac_cv_c_const = no; then
+
+cat >>confdefs.h <<\_ACEOF
+#define const
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking for size_t" >&5
+echo $ECHO_N "checking for size_t... $ECHO_C" >&6
+if test "${ac_cv_type_size_t+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+if ((size_t *) 0)
+  return 0;
+if (sizeof (size_t))
+  return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type_size_t=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_size_t=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_size_t" >&5
+echo "${ECHO_T}$ac_cv_type_size_t" >&6
+if test $ac_cv_type_size_t = yes; then
+  :
+else
+
+cat >>confdefs.h <<_ACEOF
+#define size_t unsigned
+_ACEOF
+
+fi
+
+echo "$as_me:$LINENO: checking whether struct tm is in sys/time.h or time.h" >&5
+echo $ECHO_N "checking whether struct tm is in sys/time.h or time.h... $ECHO_C" >&6
+if test "${ac_cv_struct_tm+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <time.h>
+
+int
+main ()
+{
+struct tm *tp; tp->tm_sec;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_struct_tm=time.h
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_struct_tm=sys/time.h
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_struct_tm" >&5
+echo "${ECHO_T}$ac_cv_struct_tm" >&6
+if test $ac_cv_struct_tm = sys/time.h; then
+
+cat >>confdefs.h <<\_ACEOF
+#define TM_IN_SYS_TIME 1
+_ACEOF
+
+fi
+
+
+# Checks for library functions.
+
+for ac_header in stdlib.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+else
+  # Is the header compilable?
+echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_header_compiler=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <$ac_header>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    (
+      cat <<\_ASBOX
+## --------------------------------- ##
+## Report this to BUG-REPORT-ADDRESS ##
+## --------------------------------- ##
+_ASBOX
+    ) |
+      sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+echo "$as_me:$LINENO: checking for GNU libc compatible malloc" >&5
+echo $ECHO_N "checking for GNU libc compatible malloc... $ECHO_C" >&6
+if test "${ac_cv_func_malloc_0_nonnull+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  ac_cv_func_malloc_0_nonnull=no
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#if STDC_HEADERS || HAVE_STDLIB_H
+# include <stdlib.h>
+#else
+char *malloc ();
+#endif
+
+int
+main ()
+{
+exit (malloc (0) ? 0 : 1);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_func_malloc_0_nonnull=yes
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_func_malloc_0_nonnull=no
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_func_malloc_0_nonnull" >&5
+echo "${ECHO_T}$ac_cv_func_malloc_0_nonnull" >&6
+if test $ac_cv_func_malloc_0_nonnull = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_MALLOC 1
+_ACEOF
+
+else
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_MALLOC 0
+_ACEOF
+
+   case $LIBOBJS in
+    "malloc.$ac_objext"   | \
+  *" malloc.$ac_objext"   | \
+    "malloc.$ac_objext "* | \
+  *" malloc.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS malloc.$ac_objext" ;;
+esac
+
+
+cat >>confdefs.h <<\_ACEOF
+#define malloc rpl_malloc
+_ACEOF
+
+fi
+
+
+
+echo "$as_me:$LINENO: checking return type of signal handlers" >&5
+echo $ECHO_N "checking return type of signal handlers... $ECHO_C" >&6
+if test "${ac_cv_type_signal+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <signal.h>
+#ifdef signal
+# undef signal
+#endif
+#ifdef __cplusplus
+extern "C" void (*signal (int, void (*)(int)))(int);
+#else
+void (*signal ()) ();
+#endif
+
+int
+main ()
+{
+int i;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type_signal=void
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type_signal=int
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_signal" >&5
+echo "${ECHO_T}$ac_cv_type_signal" >&6
+
+cat >>confdefs.h <<_ACEOF
+#define RETSIGTYPE $ac_cv_type_signal
+_ACEOF
+
+
+
+for ac_func in strftime
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+else
+  # strftime is in -lintl on SCO UNIX.
+echo "$as_me:$LINENO: checking for strftime in -lintl" >&5
+echo $ECHO_N "checking for strftime in -lintl... $ECHO_C" >&6
+if test "${ac_cv_lib_intl_strftime+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lintl  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char strftime ();
+int
+main ()
+{
+strftime ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_intl_strftime=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_intl_strftime=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_intl_strftime" >&5
+echo "${ECHO_T}$ac_cv_lib_intl_strftime" >&6
+if test $ac_cv_lib_intl_strftime = yes; then
+  cat >>confdefs.h <<\_ACEOF
+#define HAVE_STRFTIME 1
+_ACEOF
+
+LIBS="-lintl $LIBS"
+fi
+
+fi
+done
+
+
+
+
+
+
+
+
+
+for ac_func in alarm gethostbyname putenv socket strcasecmp strdup strncasecmp strstr
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
+          ac_config_files="$ac_config_files Makefile"
+
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, don't put newlines in cache variables' values.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+{
+  (set) 2>&1 |
+    case `(ac_space=' '; set | grep ac_space) 2>&1` in
+    *ac_space=\ *)
+      # `set' does not quote correctly, so add quotes (double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \).
+      sed -n \
+	"s/'/'\\\\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;;
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n \
+	"s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+      ;;
+    esac;
+} |
+  sed '
+     t clear
+     : clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     : end' >>confcache
+if diff $cache_file confcache >/dev/null 2>&1; then :; else
+  if test -w $cache_file; then
+    test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file"
+    cat confcache >$cache_file
+  else
+    echo "not updating unwritable cache $cache_file"
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
+s/:*\$(srcdir):*/:/;
+s/:*\${srcdir}:*/:/;
+s/:*@srcdir@:*/:/;
+s/^\([^=]*=[	 ]*\):*/\1/;
+s/:*$//;
+s/^[^=]*=[	 ]*$//;
+}'
+fi
+
+DEFS=-DHAVE_CONFIG_H
+
+ac_libobjs=
+ac_ltlibobjs=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_i=`echo "$ac_i" |
+	 sed 's/\$U\././;s/\.o$//;s/\.obj$//'`
+  # 2. Add them.
+  ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext"
+  ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+
+: ${CONFIG_STATUS=./config.status}
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5
+echo "$as_me: creating $CONFIG_STATUS" >&6;}
+cat >$CONFIG_STATUS <<_ACEOF
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+SHELL=\${CONFIG_SHELL-$SHELL}
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+  set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+  LC_TELEPHONE LC_TIME
+do
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+    eval $as_var=C; export $as_var
+  else
+    $as_unset $as_var
+  fi
+done
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)$' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\/\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+
+
+# PATH needs CR, and LINENO needs CR and PATH.
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  echo "#! /bin/sh" >conf$$.sh
+  echo  "exit 0"   >>conf$$.sh
+  chmod +x conf$$.sh
+  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+    PATH_SEPARATOR=';'
+  else
+    PATH_SEPARATOR=:
+  fi
+  rm -f conf$$.sh
+fi
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
+  # Find who we are.  Look in the path if we contain no path at all
+  # relative or not.
+  case $0 in
+    *[\\/]* ) as_myself=$0 ;;
+    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+
+       ;;
+  esac
+  # We did not find ourselves, most probably we were run as `sh COMMAND'
+  # in which case we are not to be found in the path.
+  if test "x$as_myself" = x; then
+    as_myself=$0
+  fi
+  if test ! -f "$as_myself"; then
+    { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5
+echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+  case $CONFIG_SHELL in
+  '')
+    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for as_base in sh bash ksh sh5; do
+	 case $as_dir in
+	 /*)
+	   if ("$as_dir/$as_base" -c '
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
+	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
+	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
+	     CONFIG_SHELL=$as_dir/$as_base
+	     export CONFIG_SHELL
+	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
+	   fi;;
+	 esac
+       done
+done
+;;
+  esac
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line before each line; the second 'sed' does the real
+  # work.  The second script uses 'N' to pair each line-number line
+  # with the numbered line, and appends trailing '-' during
+  # substitution so that $LINENO is not a special case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
+  sed '=' <$as_myself |
+    sed '
+      N
+      s,$,-,
+      : loop
+      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+      t loop
+      s,-$,,
+      s,^['$as_cr_digits']*\n,,
+    ' >$as_me.lineno &&
+  chmod +x $as_me.lineno ||
+    { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5
+echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;}
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensible to this).
+  . ./$as_me.lineno
+  # Exit status is that of the last command.
+  exit
+}
+
+
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+  *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T='	' ;;
+  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+echo >conf$$.file
+if ln -s conf$$.file conf$$ 2>/dev/null; then
+  # We could just check for DJGPP; but this test a) works b) is more generic
+  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
+  if test -f conf$$.exe; then
+    # Don't use ln at all; we don't have any links
+    as_ln_s='cp -p'
+  else
+    as_ln_s='ln -s'
+  fi
+elif ln conf$$.file conf$$ 2>/dev/null; then
+  as_ln_s=ln
+else
+  as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.file
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p=:
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_executable_p="test -f"
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.
+as_nl='
+'
+IFS=" 	$as_nl"
+
+# CDPATH.
+$as_unset CDPATH
+
+exec 6>&1
+
+# Open the log real soon, to keep \$[0] and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.  Logging --version etc. is OK.
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+} >&5
+cat >&5 <<_CSEOF
+
+This file was extended by FULL-PACKAGE-NAME $as_me VERSION, which was
+generated by GNU Autoconf 2.59.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+_CSEOF
+echo "on `(hostname || uname -n) 2>/dev/null | sed 1q`" >&5
+echo >&5
+_ACEOF
+
+# Files that config.status was made for.
+if test -n "$ac_config_files"; then
+  echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_headers"; then
+  echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_links"; then
+  echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_commands"; then
+  echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+ac_cs_usage="\
+\`$as_me' instantiates files from templates according to the
+current configuration.
+
+Usage: $0 [OPTIONS] [FILE]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number, then exit
+  -q, --quiet      do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+  --file=FILE[:TEMPLATE]
+		   instantiate the configuration file FILE
+  --header=FILE[:TEMPLATE]
+		   instantiate the configuration header FILE
+
+Configuration files:
+$config_files
+
+Configuration headers:
+$config_headers
+
+Report bugs to <bug-autoconf@gnu.org>."
+_ACEOF
+
+cat >>$CONFIG_STATUS <<_ACEOF
+ac_cs_version="\\
+FULL-PACKAGE-NAME config.status VERSION
+configured by $0, generated by GNU Autoconf 2.59,
+  with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
+
+Copyright (C) 2003 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+srcdir=$srcdir
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+# If no file are specified by the user, then we need to provide default
+# value.  By we need to know if files were specified by the user.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=*)
+    ac_option=`expr "x$1" : 'x\([^=]*\)='`
+    ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  -*)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  *) # This is not an option, so the user has probably given explicit
+     # arguments.
+     ac_option=$1
+     ac_need_defaults=false;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --vers* | -V )
+    echo "$ac_cs_version"; exit 0 ;;
+  --he | --h)
+    # Conflict between --help and --header
+    { { echo "$as_me:$LINENO: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&5
+echo "$as_me: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&2;}
+   { (exit 1); exit 1; }; };;
+  --help | --hel | -h )
+    echo "$ac_cs_usage"; exit 0 ;;
+  --debug | --d* | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    CONFIG_FILES="$CONFIG_FILES $ac_optarg"
+    ac_need_defaults=false;;
+  --header | --heade | --head | --hea )
+    $ac_shift
+    CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg"
+    ac_need_defaults=false;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) { { echo "$as_me:$LINENO: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&5
+echo "$as_me: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&2;}
+   { (exit 1); exit 1; }; } ;;
+
+  *) ac_config_targets="$ac_config_targets $1" ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF
+if \$ac_cs_recheck; then
+  echo "running $SHELL $0 " $ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6
+  exec $SHELL $0 $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+fi
+
+_ACEOF
+
+
+
+
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+for ac_config_target in $ac_config_targets
+do
+  case "$ac_config_target" in
+  # Handling of arguments.
+  "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
+  "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
+  *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
+echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
+   { (exit 1); exit 1; }; };;
+  esac
+done
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason to put it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Create a temporary directory, and hook for its removal unless debugging.
+$debug ||
+{
+  trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0
+  trap '{ (exit 1); exit 1; }' 1 2 13 15
+}
+
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
+  test -n "$tmp" && test -d "$tmp"
+}  ||
+{
+  tmp=./confstat$$-$RANDOM
+  (umask 077 && mkdir $tmp)
+} ||
+{
+   echo "$me: cannot create a temporary directory in ." >&2
+   { (exit 1); exit 1; }
+}
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<_ACEOF
+
+#
+# CONFIG_FILES section.
+#
+
+# No need to generate the scripts if there are no CONFIG_FILES.
+# This happens for instance when ./config.status config.h
+if test -n "\$CONFIG_FILES"; then
+  # Protect against being on the right side of a sed subst in config.status.
+  sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g;
+   s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF
+s,@SHELL@,$SHELL,;t t
+s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t
+s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t
+s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t
+s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t
+s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t
+s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t
+s,@exec_prefix@,$exec_prefix,;t t
+s,@prefix@,$prefix,;t t
+s,@program_transform_name@,$program_transform_name,;t t
+s,@bindir@,$bindir,;t t
+s,@sbindir@,$sbindir,;t t
+s,@libexecdir@,$libexecdir,;t t
+s,@datadir@,$datadir,;t t
+s,@sysconfdir@,$sysconfdir,;t t
+s,@sharedstatedir@,$sharedstatedir,;t t
+s,@localstatedir@,$localstatedir,;t t
+s,@libdir@,$libdir,;t t
+s,@includedir@,$includedir,;t t
+s,@oldincludedir@,$oldincludedir,;t t
+s,@infodir@,$infodir,;t t
+s,@mandir@,$mandir,;t t
+s,@build_alias@,$build_alias,;t t
+s,@host_alias@,$host_alias,;t t
+s,@target_alias@,$target_alias,;t t
+s,@DEFS@,$DEFS,;t t
+s,@ECHO_C@,$ECHO_C,;t t
+s,@ECHO_N@,$ECHO_N,;t t
+s,@ECHO_T@,$ECHO_T,;t t
+s,@LIBS@,$LIBS,;t t
+s,@CC@,$CC,;t t
+s,@CFLAGS@,$CFLAGS,;t t
+s,@LDFLAGS@,$LDFLAGS,;t t
+s,@CPPFLAGS@,$CPPFLAGS,;t t
+s,@ac_ct_CC@,$ac_ct_CC,;t t
+s,@EXEEXT@,$EXEEXT,;t t
+s,@OBJEXT@,$OBJEXT,;t t
+s,@RANLIB@,$RANLIB,;t t
+s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t
+s,@CPP@,$CPP,;t t
+s,@EGREP@,$EGREP,;t t
+s,@LIBOBJS@,$LIBOBJS,;t t
+s,@LTLIBOBJS@,$LTLIBOBJS,;t t
+CEOF
+
+_ACEOF
+
+  cat >>$CONFIG_STATUS <<\_ACEOF
+  # Split the substitutions into bite-sized pieces for seds with
+  # small command number limits, like on Digital OSF/1 and HP-UX.
+  ac_max_sed_lines=48
+  ac_sed_frag=1 # Number of current file.
+  ac_beg=1 # First line for current file.
+  ac_end=$ac_max_sed_lines # Line after last line for current file.
+  ac_more_lines=:
+  ac_sed_cmds=
+  while $ac_more_lines; do
+    if test $ac_beg -gt 1; then
+      sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
+    else
+      sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
+    fi
+    if test ! -s $tmp/subs.frag; then
+      ac_more_lines=false
+    else
+      # The purpose of the label and of the branching condition is to
+      # speed up the sed processing (if there are no `@' at all, there
+      # is no need to browse any of the substitutions).
+      # These are the two extra sed commands mentioned above.
+      (echo ':t
+  /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed
+      if test -z "$ac_sed_cmds"; then
+	ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed"
+      else
+	ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed"
+      fi
+      ac_sed_frag=`expr $ac_sed_frag + 1`
+      ac_beg=$ac_end
+      ac_end=`expr $ac_end + $ac_max_sed_lines`
+    fi
+  done
+  if test -z "$ac_sed_cmds"; then
+    ac_sed_cmds=cat
+  fi
+fi # test -n "$CONFIG_FILES"
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case $ac_file in
+  - | *:- | *:-:* ) # input from stdin
+	cat >$tmp/stdin
+	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  * )   ac_file_in=$ac_file.in ;;
+  esac
+
+  # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories.
+  ac_dir=`(dirname "$ac_file") 2>/dev/null ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+  { if $as_mkdir_p; then
+    mkdir -p "$ac_dir"
+  else
+    as_dir="$ac_dir"
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+   { (exit 1); exit 1; }; }; }
+
+  ac_builddir=.
+
+if test "$ac_dir" != .; then
+  ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+  # A "../" for each directory in $ac_dir_suffix.
+  ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+  ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+  .)  # No --srcdir option.  We are building in place.
+    ac_srcdir=.
+    if test -z "$ac_top_builddir"; then
+       ac_top_srcdir=.
+    else
+       ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+    fi ;;
+  [\\/]* | ?:[\\/]* )  # Absolute path.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir ;;
+  *) # Relative path.
+    ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+  case "$ac_dir" in
+  .) ac_abs_builddir=`pwd`;;
+  [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+  *) ac_abs_builddir=`pwd`/"$ac_dir";;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+  case ${ac_top_builddir}. in
+  .) ac_abs_top_builddir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+  *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+  case $ac_srcdir in
+  .) ac_abs_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+  *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+  esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+  case $ac_top_srcdir in
+  .) ac_abs_top_srcdir=$ac_abs_builddir;;
+  [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+  *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+  esac;;
+esac
+
+
+
+  if test x"$ac_file" != x-; then
+    { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+    rm -f "$ac_file"
+  fi
+  # Let's still pretend it is `configure' which instantiates (i.e., don't
+  # use $as_me), people would be surprised to read:
+  #    /* config.h.  Generated by config.status.  */
+  if test x"$ac_file" = x-; then
+    configure_input=
+  else
+    configure_input="$ac_file.  "
+  fi
+  configure_input=$configure_input"Generated from `echo $ac_file_in |
+				     sed 's,.*/,,'` by configure."
+
+  # First look for the input files in the build tree, otherwise in the
+  # src tree.
+  ac_file_inputs=`IFS=:
+    for f in $ac_file_in; do
+      case $f in
+      -) echo $tmp/stdin ;;
+      [\\/$]*)
+	 # Absolute (can't be DOS-style, as IFS=:)
+	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 echo "$f";;
+      *) # Relative
+	 if test -f "$f"; then
+	   # Build tree
+	   echo "$f"
+	 elif test -f "$srcdir/$f"; then
+	   # Source tree
+	   echo "$srcdir/$f"
+	 else
+	   # /dev/null tree
+	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 fi;;
+      esac
+    done` || { (exit 1); exit 1; }
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF
+  sed "$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s,@configure_input@,$configure_input,;t t
+s,@srcdir@,$ac_srcdir,;t t
+s,@abs_srcdir@,$ac_abs_srcdir,;t t
+s,@top_srcdir@,$ac_top_srcdir,;t t
+s,@abs_top_srcdir@,$ac_abs_top_srcdir,;t t
+s,@builddir@,$ac_builddir,;t t
+s,@abs_builddir@,$ac_abs_builddir,;t t
+s,@top_builddir@,$ac_top_builddir,;t t
+s,@abs_top_builddir@,$ac_abs_top_builddir,;t t
+" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out
+  rm -f $tmp/stdin
+  if test x"$ac_file" != x-; then
+    mv $tmp/out $ac_file
+  else
+    cat $tmp/out
+    rm -f $tmp/out
+  fi
+
+done
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+#
+# CONFIG_HEADER section.
+#
+
+# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where
+# NAME is the cpp macro being defined and VALUE is the value it is being given.
+#
+# ac_d sets the value in "#define NAME VALUE" lines.
+ac_dA='s,^\([	 ]*\)#\([	 ]*define[	 ][	 ]*\)'
+ac_dB='[	 ].*$,\1#\2'
+ac_dC=' '
+ac_dD=',;t'
+# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
+ac_uA='s,^\([	 ]*\)#\([	 ]*\)undef\([	 ][	 ]*\)'
+ac_uB='$,\1#\2define\3'
+ac_uC=' '
+ac_uD=',;t'
+
+for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case $ac_file in
+  - | *:- | *:-:* ) # input from stdin
+	cat >$tmp/stdin
+	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  * )   ac_file_in=$ac_file.in ;;
+  esac
+
+  test x"$ac_file" != x- && { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+
+  # First look for the input files in the build tree, otherwise in the
+  # src tree.
+  ac_file_inputs=`IFS=:
+    for f in $ac_file_in; do
+      case $f in
+      -) echo $tmp/stdin ;;
+      [\\/$]*)
+	 # Absolute (can't be DOS-style, as IFS=:)
+	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 # Do quote $f, to prevent DOS paths from being IFS'd.
+	 echo "$f";;
+      *) # Relative
+	 if test -f "$f"; then
+	   # Build tree
+	   echo "$f"
+	 elif test -f "$srcdir/$f"; then
+	   # Source tree
+	   echo "$srcdir/$f"
+	 else
+	   # /dev/null tree
+	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 fi;;
+      esac
+    done` || { (exit 1); exit 1; }
+  # Remove the trailing spaces.
+  sed 's/[	 ]*$//' $ac_file_inputs >$tmp/in
+
+_ACEOF
+
+# Transform confdefs.h into two sed scripts, `conftest.defines' and
+# `conftest.undefs', that substitutes the proper values into
+# config.h.in to produce config.h.  The first handles `#define'
+# templates, and the second `#undef' templates.
+# And first: Protect against being on the right side of a sed subst in
+# config.status.  Protect against being in an unquoted here document
+# in config.status.
+rm -f conftest.defines conftest.undefs
+# Using a here document instead of a string reduces the quoting nightmare.
+# Putting comments in sed scripts is not portable.
+#
+# `end' is used to avoid that the second main sed command (meant for
+# 0-ary CPP macros) applies to n-ary macro definitions.
+# See the Autoconf documentation for `clear'.
+cat >confdef2sed.sed <<\_ACEOF
+s/[\\&,]/\\&/g
+s,[\\$`],\\&,g
+t clear
+: clear
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*\)\(([^)]*)\)[	 ]*\(.*\)$,${ac_dA}\1${ac_dB}\1\2${ac_dC}\3${ac_dD},gp
+t end
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp
+: end
+_ACEOF
+# If some macros were called several times there might be several times
+# the same #defines, which is useless.  Nevertheless, we may not want to
+# sort them, since we want the *last* AC-DEFINE to be honored.
+uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines
+sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs
+rm -f confdef2sed.sed
+
+# This sed command replaces #undef with comments.  This is necessary, for
+# example, in the case of _POSIX_SOURCE, which is predefined and required
+# on some systems where configure will not decide to define it.
+cat >>conftest.undefs <<\_ACEOF
+s,^[	 ]*#[	 ]*undef[	 ][	 ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,
+_ACEOF
+
+# Break up conftest.defines because some shells have a limit on the size
+# of here documents, and old seds have small limits too (100 cmds).
+echo '  # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS
+echo '  if grep "^[	 ]*#[	 ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS
+echo '  # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS
+echo '  :' >>$CONFIG_STATUS
+rm -f conftest.tail
+while grep . conftest.defines >/dev/null
+do
+  # Write a limited-size here document to $tmp/defines.sed.
+  echo '  cat >$tmp/defines.sed <<CEOF' >>$CONFIG_STATUS
+  # Speed up: don't consider the non `#define' lines.
+  echo '/^[	 ]*#[	 ]*define/!b' >>$CONFIG_STATUS
+  # Work around the forget-to-reset-the-flag bug.
+  echo 't clr' >>$CONFIG_STATUS
+  echo ': clr' >>$CONFIG_STATUS
+  sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS
+  echo 'CEOF
+  sed -f $tmp/defines.sed $tmp/in >$tmp/out
+  rm -f $tmp/in
+  mv $tmp/out $tmp/in
+' >>$CONFIG_STATUS
+  sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail
+  rm -f conftest.defines
+  mv conftest.tail conftest.defines
+done
+rm -f conftest.defines
+echo '  fi # grep' >>$CONFIG_STATUS
+echo >>$CONFIG_STATUS
+
+# Break up conftest.undefs because some shells have a limit on the size
+# of here documents, and old seds have small limits too (100 cmds).
+echo '  # Handle all the #undef templates' >>$CONFIG_STATUS
+rm -f conftest.tail
+while grep . conftest.undefs >/dev/null
+do
+  # Write a limited-size here document to $tmp/undefs.sed.
+  echo '  cat >$tmp/undefs.sed <<CEOF' >>$CONFIG_STATUS
+  # Speed up: don't consider the non `#undef'
+  echo '/^[	 ]*#[	 ]*undef/!b' >>$CONFIG_STATUS
+  # Work around the forget-to-reset-the-flag bug.
+  echo 't clr' >>$CONFIG_STATUS
+  echo ': clr' >>$CONFIG_STATUS
+  sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS
+  echo 'CEOF
+  sed -f $tmp/undefs.sed $tmp/in >$tmp/out
+  rm -f $tmp/in
+  mv $tmp/out $tmp/in
+' >>$CONFIG_STATUS
+  sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail
+  rm -f conftest.undefs
+  mv conftest.tail conftest.undefs
+done
+rm -f conftest.undefs
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+  # Let's still pretend it is `configure' which instantiates (i.e., don't
+  # use $as_me), people would be surprised to read:
+  #    /* config.h.  Generated by config.status.  */
+  if test x"$ac_file" = x-; then
+    echo "/* Generated by configure.  */" >$tmp/config.h
+  else
+    echo "/* $ac_file.  Generated by configure.  */" >$tmp/config.h
+  fi
+  cat $tmp/in >>$tmp/config.h
+  rm -f $tmp/in
+  if test x"$ac_file" != x-; then
+    if diff $ac_file $tmp/config.h >/dev/null 2>&1; then
+      { echo "$as_me:$LINENO: $ac_file is unchanged" >&5
+echo "$as_me: $ac_file is unchanged" >&6;}
+    else
+      ac_dir=`(dirname "$ac_file") 2>/dev/null ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+      { if $as_mkdir_p; then
+    mkdir -p "$ac_dir"
+  else
+    as_dir="$ac_dir"
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+   { (exit 1); exit 1; }; }; }
+
+      rm -f $ac_file
+      mv $tmp/config.h $ac_file
+    fi
+  else
+    cat $tmp/config.h
+    rm -f $tmp/config.h
+  fi
+done
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+{ (exit 0); exit 0; }
+_ACEOF
+chmod +x $CONFIG_STATUS
+ac_clean_files=$ac_clean_files_save
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || { (exit 1); exit 1; }
+fi
+
Index: /gsdl/trunk/runtime-src/packages/d2m/configure.in
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/configure.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/configure.in	(revision 16571)
@@ -0,0 +1,30 @@
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ(2.59)
+AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
+AC_CONFIG_SRCDIR([danMARC.c])
+AC_CONFIG_HEADER([config.h])
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_RANLIB
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([fcntl.h malloc.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_TYPE_SIZE_T
+AC_STRUCT_TM
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_TYPE_SIGNAL
+AC_FUNC_STRFTIME
+AC_CHECK_FUNCS([alarm gethostbyname putenv socket strcasecmp strdup strncasecmp strstr])
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
Index: /gsdl/trunk/runtime-src/packages/d2m/d2m.h
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/d2m.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/d2m.h	(revision 16571)
@@ -0,0 +1,76 @@
+#ifndef D2MH
+#define D2MH
+
+#include <stdio.h>
+
+#define  TRUE    1
+#define  FALSE   0
+
+#define  HTML_TITLE           "d2m: Dublin Core to MARC conversion"
+
+#define  D2M_LINELEN          80
+#define  D2M_TEMPFILE         "/tmp/d2m.data"
+#define  D2M_TRACEFILE        "/tmp/d2m.trace"
+#define  D2M_DEFAULT_SYNTAX   "plain"
+#define  D2M_DEFAULT_FORMAT   "NORMARC"        
+#define  D2M_DEFAULT_URL      "http://www.bibsys.no/meta/test.html"
+
+struct metatag {
+   char    *name;
+   char    *type;
+   char    *scheme;
+   char    *value;
+               };
+
+struct marcrec {
+   int     ntitles;
+   int     ncreators;
+   char    *marcline;
+   char    *partitle;
+   char    *subtitle;
+   char    *year;
+   char    *url;
+   char    *fmat;
+   char    *s008;
+               };
+
+enum mformats {
+   USMARC,
+   DANMARC,
+   FINMARC,
+   ISMARC,
+   NORMARC,
+   SWEMARC    };
+
+enum SOURCES { TEXTAREA, URL };
+
+enum fields_in_008 {
+   F008_DATE_ENTERED,
+   F008_TYPE_OF_DATE,
+   F008_DATE1,
+   F008_LANGUAGE,
+   F008_FORM_OF_PUBLICATION };
+              
+enum levels {
+  LNAME,
+  LTYPE,
+  LSCHEME,
+  LOCC,
+  LTAG,
+  LIND,
+  LSUBF,
+  LRULE
+            };
+
+extern void write_field(char *i, FILE *of, int l, int n, int s);
+extern int write_trace(char *n, FILE *of);
+extern struct metatag *dc_parse(char *b); 
+extern char *cstr(char *h, char *n);
+extern void unescape(char *n);
+extern char *poq();
+extern int  put008(char *n, char *s, int p);
+extern int  find_year(char *n);
+extern int  split_name(char *n);
+extern int  split_subj(char *n);
+
+#endif
Index: /gsdl/trunk/runtime-src/packages/d2m/d2m4gs.h
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/d2m4gs.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/d2m4gs.h	(revision 16571)
@@ -0,0 +1,22 @@
+#ifndef D2M4GSH
+#define D2M4GSH
+
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#include "d2m.h"
+
+void MARCtidy(struct marcrec *mrec, char *buf, int format);
+void usMARC(struct metatag *mt, struct marcrec *mr);
+char *MARC2709(char *record, int last, int first, char recstatus, 
+	       char rectype, char biblevel);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: /gsdl/trunk/runtime-src/packages/d2m/danMARC.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/danMARC.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/danMARC.c	(revision 16571)
@@ -0,0 +1,239 @@
+/* ------------------------------------------------------------------- */
+/* danMARC    : Convert a metatag struct to DANMARC2                   */
+/*                                                                     */
+/* Specs      : http://www.bibsys.no/meta/d2m/dancross.html            */
+/*                                                                     */
+/* Author     : Ole Husby                                              */
+/* Last update: 1998-09-30                                             */
+/* ------------------------------------------------------------------- */
+
+#include <stdio.h>
+#include <string.h>
+#include "d2m.h" 
+
+
+
+/* Splits subject heading on ":". First occurence go into $a, second into $v */ 
+
+int split_dk5(char *str)
+{
+  char *p, *q, subtag[5];
+
+  if (!strstr(str, ":"))
+    return 1;
+
+  p = (char *) malloc(strlen(str) + 50);
+  *p = 0;
+  *subtag = 0;
+
+  q = strtok(str, ":");
+  if (q)
+  {
+    while ( ( q[0] == ' ' ) && ( strlen(q) ) )
+      q++;
+
+    while( ( q[strlen(q) - 1] == ' ' ) && ( strlen(q) ) )
+      q[strlen(q) - 1] = '\0';
+
+    if (*q)
+    {
+      strcat(p, subtag);
+      strcat(p, q);
+      strcpy(subtag, " $v ");
+    }
+  }
+
+  strcpy(str, p);
+  free(p);
+
+  return 1;
+}
+
+
+
+
+int danMARC(struct metatag *mt, struct marcrec *mr)
+{
+  char pre[64], type_tag[4];
+  int i;
+
+  *pre = 0;
+
+  if (strcasecmp(mt->name, "title") == 0)
+  {
+    if ( (!*mt->type)
+         | (strcasecmp(mt->type, "main") == 0)
+         | (strcasecmp(mt->type, "long") == 0) )
+    {
+      if (mr->ntitles)
+      {
+        strcat(mr->partitle, "$a ");
+        strcat(mr->partitle, mt->value);
+
+      }
+      else
+      {
+        mr->ntitles++;
+        strcpy(pre, "245  $a");
+      }
+    }
+  }
+
+  else if (strcasecmp(mt->name, "creator") == 0)
+  {
+    if ( strcasecmp(mt->type, "personal") == 0) 
+    {
+      strcpy(pre, "700  $a");
+      split_name(mt->value);
+    }
+    else if (strcasecmp(mt->type, "corporate") == 0)
+      strcpy(pre, "710  $a");
+  }
+
+
+  else if (strcasecmp(mt->name, "publisher") == 0)
+    strcpy(pre, "260  $b");
+
+  else if (strcasecmp(mt->name, "description") == 0)
+    strcpy(pre, "504  $a");
+
+  else if (strncasecmp(mt->name, "contributor", 11) == 0)   
+  {
+    if ( strcasecmp(mt->type, "personal") == 0 )
+    {
+      strcpy(pre, "700  $a");
+      split_name(mt->value);
+    }
+    else if (strcasecmp(mt->type, "corporate") == 0)
+      strcpy(pre, "710  $a");
+  }
+
+  else if (strcasecmp(mt->name, "coverage") == 0)
+  {
+    if (!*mt->type)
+      strcpy(pre, "559  $a");
+    else if (strcasecmp(mt->type , "spatial") == 0)
+    {
+      strcpy(pre, "633  $a");
+      split_subj(mt->value);
+    }
+    else if (strcasecmp(mt->type,  "temporal") == 0)
+    {
+      strcpy(pre, "334  $b");
+      for (i = 0; i < strlen(mt->value); i++)
+      {
+        if (!isdigit(mt->value[i]))
+        {
+          strcpy(pre, "334  $a");
+        }
+      } 
+    }
+  }
+
+  else if (strcasecmp(mt->name, "source") == 0)
+    strcpy(pre, "523  $a");
+
+  else if (strcasecmp(mt->name, "rights") == 0)
+  {
+    if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(pre, "856  $3 rights $u");
+    else
+      strcpy(pre, "518  $a");
+  }
+
+  else if (strcasecmp(mt->name, "identifier") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "urn") == 0)
+      strcpy(pre, "856  $g urn:");
+    else if (strcasecmp(mt->scheme, "isbn") == 0)
+      strcpy(pre, "021  $a");
+    else if (strcasecmp(mt->scheme, "issn") == 0)
+      strcpy(pre, "022  $a");
+    else if (strcasecmp(mt->scheme, "isrc") == 0)
+      strcpy(pre, "024  $a");
+    else if (strcasecmp(mt->scheme, "ismn") == 0)
+      strcpy(pre, "028  $a");
+    else if (strcasecmp(mt->scheme, "isrn") == 0)
+      strcpy(pre, "027  $a");
+  }
+
+  else if (strcasecmp(mt->name, "type") == 0)
+    strcpy(pre, "505  $a");
+
+  else if (strcasecmp(mt->name, "relation") == 0)
+    strcpy(pre, "559  $a");
+
+  else if (strcasecmp(mt->name, "language") == 0)  /* Only if repeated ! */
+  {
+    if (strcasecmp(mt->scheme, "z39.53") == 0)
+    {
+      strcpy(pre, "041  $a");
+      put008(mr->s008, mt->value, F008_LANGUAGE);
+    }
+  }
+
+  else if (strcasecmp(mt->name, "format") == 0)
+  {
+    if ( (!*mt->scheme)
+      || (strcasecmp(mt->scheme, "imt") == 0)
+      || (strcasecmp(mt->scheme, "mime") == 0) )
+      strcpy(mr->fmat, mt->value); 
+  }
+
+  else if (strcasecmp(mt->name, "subject") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "631  $a");
+    else if (strcasecmp(mt->scheme, "udc") == 0)
+      strcpy(pre, "080  $a");
+    else if (strcasecmp(mt->scheme, "lccs") == 0)
+      strcpy(pre, "050  $a");
+    else if (strcasecmp(mt->scheme, "lcsh") == 0)
+      strcpy(pre, "650  $a");
+    else if (strcasecmp(mt->scheme, "ddc") == 0)
+      strcpy(pre, "082  $a");
+    else if (strcasecmp(mt->scheme, "nlm") == 0)
+      strcpy(pre, "060  $a");
+    else if (strcasecmp(mt->scheme, "agr") == 0)
+      strcpy(pre, "662  $a");
+    else if (strcasecmp(mt->scheme, "eudised") == 0)
+      strcpy(pre, "661  $b");
+    else if (strcasecmp(mt->scheme, "dbc") == 0)
+      strcpy(pre, "666  $f");
+    else if (strcasecmp(mt->scheme, "mesh") == 0)
+      strcpy(pre, "690  $a");
+    else if (strcasecmp(mt->scheme, "dk5") == 0)
+    {
+      strcpy(pre, "652  $m");
+      split_dk5(mt->value);
+    }
+  }
+
+  else if (strcasecmp(mt->name, "date") == 0)
+  {
+    if ( (!*mt->type) || ( strcasecmp(mt->type, "current") == 0) )
+    {
+      if ( (strncasecmp(mt->scheme, "ans", 3) == 0) 
+         || (strncasecmp(mt->scheme, "iso", 3) == 0) )
+      {
+        if (find_year(mt->value))
+        {
+          strcpy(mr->year, mt->value);
+          put008(mr->s008, mt->value, F008_DATE1);
+        }
+      }
+    }
+  }
+
+  if (*pre)
+  {
+    strcat(mr->marcline, pre);
+    strcat(mr->marcline, " ");
+    strcat(mr->marcline, mt->value);
+    strcat(mr->marcline, "\n");
+  }
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/dc_parse.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/dc_parse.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/dc_parse.c	(revision 16571)
@@ -0,0 +1,216 @@
+/* ------------------------------------------------------------------- */
+/* dc_parse   : parse the meta tag, build a metatag struct             */
+/* Author     : Ole Husby                                              */
+/* Updated    : 1998-09-30                                             */
+/*                                                                     */
+/* Syntax     : #include "d2m.h"                                       */
+/*              dc_parse(char * string)                                */
+/*                                                                     */
+/*              Returns pointer to struct metatag                      */
+/*                                                                     */
+/*              Memory for the struct is allocated in the program!     */
+/*                                                                     */
+/*              String includes a meta tag, after the initial          */
+/*              "<meta " and the ending ">" are stripped away.         */
+/*                                                                     */
+/*              The program accepts the tag if name starts with "dc."  */
+/*              (case insensitive), else NULL is returned.             */
+/*                                                                     */
+/*              The parsing looks for the HTML attributes "name",      */
+/*              "scheme", and "content" only. Other attributes are     */
+/*              ignored.                                               */
+/*                                                                     */
+/*              The DC "type" will be recognized if suffixed           */
+/*              "name" by "dot notation", or contained within          */
+/*              parentheses within "content" (old notation).           */
+/*              (type = subelement)                                    */
+/*                                                                     */
+/*              The DC "scheme" will be recognized if                  */
+/*              present in "scheme" attribute (HTML 4.0), or if        */
+/*              contained within aprentheses in "content" (HTML 2.0)   */
+/*                                                                     */
+/*              Examples:                                              */
+/*                                                                     */
+/*              meta name="DC.Creator.Personalname"                    */
+/*                content="Smith, John"                                */
+/*                                                                     */
+/*              meta name="dc.Creator"                                 */
+/*                content="(type=Personalname) Smith, John">           */
+/*                                                                     */
+/*              meta name="DC.Subject" scheme="LCSH"                   */
+/*                content="Cataloguing"                                */
+/*                                                                     */
+/*              meta name="DC.Subject"                                 */
+/*                content="(scheme=LCSH) Cataloguing"                  */
+/*                                                                     */
+/*              The values of the DC attributes are NOT validated!     */
+/*                                                                     */
+/* ------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+#include "d2m.h"
+
+
+
+
+struct metatag *dc_parse(char *buf)
+{
+  int more;
+  char *p, *q;
+  struct metatag *mtag;
+  int strict = TRUE;       /* Indicates that DC. prefix is mandatory */
+  char attrname[16];
+
+/* Allocates and initializes metatag struct */
+
+  mtag = malloc(sizeof(*mtag));
+
+  mtag->name   = malloc(256);
+  mtag->type   = malloc(256);
+  mtag->scheme = malloc(256);
+  mtag->value  = malloc(10000);
+
+  *mtag->name   = 0;
+  *mtag->type   = 0;
+  *mtag->scheme = 0;
+  *mtag->value  = 0;
+
+
+
+
+/* Parse attribute name/value pairs: */ 
+ 
+  if (!buf || !*buf) return NULL;
+
+  p = strtok(buf, "\"");
+
+
+
+  while (p)
+  {
+/*  Look for attribute name  */
+
+    *attrname = 0;
+
+    while (*p && ( p[strlen(p) - 1] == ' ' || p[strlen(p) - 1] == '=')) 
+      p[strlen(p) - 1] = '\0'; 
+
+    if (*p && strlen(p) < 10)
+      strcpy(attrname, p);
+
+/*  Look for attribute value */
+
+    p = strtok(NULL, "\"");
+
+    while(*p && p[0] == ' ')
+      p++;
+
+    if (!p || !*p)
+      break;
+
+    if (strncasecmp(attrname, "name", 4) == 0)
+      strcpy(mtag->name, p);
+    else if (strncasecmp(attrname, "scheme", 6) == 0)
+      strcpy(mtag->scheme, p);
+    else if (strncasecmp(attrname, "content", 7) == 0)
+      strcpy(mtag->value, p);
+    p = strtok(NULL, "\"");
+
+    if (p)
+    {
+      while (*p && p[0] == ' ')
+        p++;
+      if (!*p) p = NULL;      
+    }
+  }
+
+
+
+/* Check the name attribute value */
+
+  p = mtag->name;
+  
+  if (!p || !*p)
+    return NULL;
+
+/* Check for leading "dc." and suffixed type */
+
+  if (strncasecmp(p, "dc.", 3) == 0)
+  {
+    p += 3;
+    q = strstr(p, ".");
+    if (q)
+    {
+      strcpy(mtag->type, q + 1);
+      *q = 0;
+    }
+    mtag->name = p;
+  }
+  else
+  {
+    if (strict)
+      return NULL;
+  }
+
+
+/* Check the content attribute value */
+/* Extracting type and scheme        */
+ 
+
+  p = mtag->value;
+ 
+  more = 1;
+     
+  while (more)
+  {
+    if (strncasecmp(p, "(type=", 6) == 0)
+    {
+       p += 6;
+       q = strtok(p, ")");
+       if (!q)
+         return NULL;
+       else
+       {
+          if (!*mtag->type)
+            strcpy(mtag->type, q);
+          q = strtok(NULL, "\0");
+          p = q;
+          while (p && *p && p[0] == ' ') p++;
+
+       }
+    }
+
+    else if (strncasecmp(p, "(scheme=", 8) == 0)
+    {
+       p += 8;
+       q = strtok(p, ")");
+       if (!q)
+         return NULL;
+       else
+       {
+          if (!*mtag->scheme)
+            strcpy(mtag->scheme, q);
+          q = strtok(NULL, "\0");
+          p = q;
+          while (p && *p && p[0] == ' ') p++;
+       }
+    }
+
+    else
+    {
+      mtag->value = p;
+      more = 0; 
+    }
+
+  }
+
+/* Finished */
+
+  if (!*mtag->value)
+    mtag = (struct metatag *) NULL;
+
+  return mtag;
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/finMARC.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/finMARC.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/finMARC.c	(revision 16571)
@@ -0,0 +1,275 @@
+/* ------------------------------------------------------------------- */
+/* finMARC    : Convert a metatag struct to FINMARC                    */
+/*                                                                     */
+/* Author     : Ole Husby                                              */
+/* Last update: 1998-09-30                                             */
+/* ------------------------------------------------------------------- */
+
+#include <stdio.h>
+#include <string.h>
+#include "d2m.h" 
+
+
+/* Decides tag for format                                                    */
+
+int parse_format(char *str, char *format)
+{
+   if (strcasecmp(str, "text/html") == 0)
+     strcpy(format, "HTML"); 
+
+   return 1;
+}
+
+
+/* Decides tag for type                                                      */
+
+int parse_type(char *str, char *tag)
+{
+   strcpy(tag, "500");
+
+   if ( (strcasecmp(str, "diss."             ) == 0) 
+     || (strcasecmp(str, "dissertation"      ) == 0) 
+     || (strcasecmp(str, "phd thesis"        ) == 0) 
+     || (strcasecmp(str, "väitöskirja"       ) == 0) 
+     || (strcasecmp(str, "väitösk."          ) == 0) 
+     || (strcasecmp(str, "avhandling"        ) == 0) ) 
+     strcpy(tag, "502");
+
+   else
+   if ( (strcasecmp(str, "masters thesis"    ) == 0) 
+     || (strcasecmp(str, "honours thesis"    ) == 0) 
+     || (strcasecmp(str, "opinnäyte"         ) == 0) 
+     || (strcasecmp(str, "opinn."            ) == 0) ) 
+     strcpy(tag, "509");
+
+   return 1;
+}
+
+
+int finMARC(struct metatag *mt, struct marcrec *mr)
+{
+  char pre[64], type_tag[4];
+
+  *pre = 0;
+
+  if (strcasecmp(mt->name, "title") == 0)
+  {
+    if ( (!*mt->type)
+         | (strcasecmp(mt->type, "main") == 0)
+         | (strcasecmp(mt->type, "long") == 0) )
+    {
+      if (mr->ntitles)
+      {
+        strcat(mr->partitle, "$r ");
+        strcat(mr->partitle, mt->value);
+
+      }
+      else
+      {
+        mr->ntitles++;
+        strcpy(pre, "245  $a");
+      }
+    }
+  }
+
+  else if (strcasecmp(mt->name, "creator") == 0)
+  {
+    if (!*mt->type)
+    {
+      strcpy(pre, "720  $a");
+      split_name(mt->value);
+    }
+    else if ( (strcasecmp(mt->type, "name") == 0) 
+            || (strcasecmp(mt->type, "personal") == 0) )
+    {
+      strcpy(pre, "100  $a");
+      split_name(mt->value);
+    }
+    else if (strcasecmp(mt->type, "corporate") == 0)
+      strcpy(pre, "110  $a");
+  }
+
+  else if (strcasecmp(mt->name, "publisher") == 0)
+  {
+    if (!*mt->type)
+      strcpy(pre, "260  $b");
+    else if (strcasecmp(mt->type, "name") == 0)
+      strcpy(pre, "260  $b");
+  }
+
+  else if (strcasecmp(mt->name, "description") == 0)
+    strcpy(pre, "519  $a");
+
+  else if (strncasecmp(mt->name, "contributor", 11) == 0)     /* Note both pl and sgl allowed */
+  {
+    if (!*mt->type)
+    {
+      strcpy(pre, "720  $a");
+      split_name(mt->value);
+    }
+    else if ( (strcasecmp(mt->type, "name") == 0) 
+            || (strcasecmp(mt->type, "personal") == 0) )
+    {
+      strcpy(pre, "700  $a");
+      split_name(mt->value);
+    }
+    else if (strcasecmp(mt->type, "corporate") == 0)
+      strcpy(pre, "710  $a");
+  }
+
+  else if (strcasecmp(mt->name, "coverage") == 0)
+  {
+    if (!*mt->type)
+      strcpy(pre, "500  $a");
+    else if (strcasecmp(mt->type , "spatial") == 0)
+    {
+      strcpy(pre, "655  $a");
+      split_subj(mt->value);
+    }
+    else if (strcasecmp(mt->type,  "temporal") == 0)
+    {
+      strcpy(pre, "652  $a");
+      split_subj(mt->value);
+    }
+  }
+
+  else if (strcasecmp(mt->name, "source") == 0)
+    strcpy(pre, "501  $a");
+
+  else if (strcasecmp(mt->name, "rights") == 0)
+  {
+    if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(pre, "856  $u");
+  }
+
+  else if (strcasecmp(mt->name, "identifier") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "urn") == 0)
+      strcpy(pre, "856  $g");
+    else if (strcasecmp(mt->scheme, "isbn") == 0)
+      strcpy(pre, "021  $a");
+    else if (strcasecmp(mt->scheme, "issn") == 0)
+      strcpy(pre, "022  $a");
+    else if (strcasecmp(mt->scheme, "nbn") == 0)
+      strcpy(pre, "015  $a");
+    else if (strcasecmp(mt->scheme, "isrc") == 0)
+      strcpy(pre, "015  $a");
+    else if (strcasecmp(mt->scheme, "ismn") == 0)
+      strcpy(pre, "024  $a");
+    else if (strcasecmp(mt->scheme, "isrn") == 0)
+      strcpy(pre, "027  $a");
+  }
+
+  else if (strcasecmp(mt->name, "type") == 0)
+  {
+    parse_type(mt->value, (char *) type_tag);
+    sprintf(pre, "%s  $a", type_tag);
+  }
+
+  else if (strcasecmp(mt->name, "language") == 0)
+  {
+    if (strcasecmp(mt->scheme, "z39.53") == 0)
+    {
+      strcpy(pre, "041  $a");
+      if (strlen(mt->value) == 3)
+        put008(mr->s008, mt->value, F008_LANGUAGE);
+    }
+  }
+
+  else if (strcasecmp(mt->name, "format") == 0)
+  {
+    if ( (!*mt->scheme)
+      || (strcasecmp(mt->scheme, "imt") == 0)
+      || (strcasecmp(mt->scheme, "mime") == 0) )
+      parse_format(mt->value, (char *) mr->fmat);
+  }
+
+  else if (strcasecmp(mt->name, "subject") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "692  $a");
+    else if (strcasecmp(mt->scheme, "udc") == 0)
+      strcpy(pre, "080  $a");
+    else if (strcasecmp(mt->scheme, "lcsh") == 0)
+      strcpy(pre, "650  $a");
+    else if (strcasecmp(mt->scheme, "ddc") == 0)
+      strcpy(pre, "082  $a");
+    else if (strcasecmp(mt->scheme, "mesh") == 0)
+      strcpy(pre, "690  $a");
+    else if (strcasecmp(mt->scheme, "ykl") == 0)
+      strcpy(pre, "098  $a");
+    else if (strcasecmp(mt->scheme, "ysa") == 0)
+    {
+      strcpy(pre, "652  $a");
+      split_subj(mt->value);
+    }
+    else if (strcasecmp(mt->scheme, "fimu") == 0)
+    {
+      strcpy(pre, "653  $a");
+      split_subj(mt->value);
+    }
+    else if (strcasecmp(mt->scheme, "fige") == 0)
+    {
+      strcpy(pre, "655  $a");
+      split_subj(mt->value);
+    }
+    else if (strcasecmp(mt->scheme, "file") == 0)
+    {
+      strcpy(pre, "665  $a");
+      split_subj(mt->value);
+    }
+    else if (strcasecmp(mt->scheme, "fiso") == 0)
+    {
+      strcpy(pre, "670  $a");
+      split_subj(mt->value);
+    }
+    else if (strcasecmp(mt->scheme, "fire") == 0)
+    {
+      strcpy(pre, "680  $a");
+      split_subj(mt->value);
+    }
+    else if (strcasecmp(mt->scheme, "fifo") == 0)
+    {
+      strcpy(pre, "685  $a");
+      split_subj(mt->value);
+    }
+    else if (strcasecmp(mt->scheme, "fiag") == 0)
+    {
+      strcpy(pre, "686  $a");
+      split_subj(mt->value);
+    }
+    else if (strcasecmp(mt->scheme, "fiep") == 0)
+    {
+      strcpy(pre, "660  $a");
+      split_subj(mt->value);
+    }
+  }
+
+  else if (strcasecmp(mt->name, "date") == 0)
+  {
+    if ( (!*mt->type) || ( strcasecmp(mt->type, "current") == 0) )
+    {
+      if ( (strncasecmp(mt->scheme, "ans", 3) == 0) 
+         || (strncasecmp(mt->scheme, "iso", 3) == 0) )
+      {
+        if (find_year(mt->value))
+        {
+          strcpy(mr->year, mt->value);
+          put008(mr->s008, mt->value, F008_DATE1);
+        }
+      }
+    }
+  }
+
+  if (*pre)
+  {
+    strcat(mr->marcline, pre);
+    strcat(mr->marcline, " ");
+    strcat(mr->marcline, mt->value);
+    strcat(mr->marcline, "\n");
+  }
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/htget.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/htget.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/htget.c	(revision 16571)
@@ -0,0 +1,545 @@
+/* ------------------------------------------------------------------- */
+/* htget     : Fetch a file using HTTP protocol                        */
+/*                                                                     */
+/* Author    : Ole Husby, BIBSYS                                       */
+/* Updated   : 1998-09-30                                              */
+/*                                                                     */
+/* ------------------------------------------------------------------- */
+/*                                                                     */
+/* htget(url, type, timeout_seconds, outfile, content_type, location)  */
+/*                                                                     */
+/*   Returns: HTTP statuscode, with additional private:                */
+/*                 0 : OK ( = 200)                                     */
+/*               900 : Error, possible timeout                         */
+/*               901 : Syntax error in url                             */
+/*               902 : Unknown host                                    */
+/*               903 : No response from server (no connection)         */
+/*               904 : File is not text/html                           */
+/*               905 : Statusline > 255 bytes                          */
+/*               906 : Statusline < 4 bytes                            */
+/*               907 : Statusline not starting with "HTTP"             */
+/*               908 : Statuscode not numeric                          */
+/*               909 : Size of header > BUFSIZE                        */
+/*               910 : Unable to open output file                      */
+/*               999 : Unspecified TCP/IP error                        */
+/*                                                                     */
+/*   Writes to outfile, depending on type, if statuscode = 0 | 200 :   */
+/*                                                                     */
+/*   type = 0  : Nothing                                               */
+/*   type = 1  : HTTP header                                           */
+/*   type = 2  : HTTP header + entitybody                              */
+/*   type = 3  : HTTP entitybody                                       */
+/*   type = 4  : HTTP entitybody if text/html                          */
+/*   type = 5  : HTTP <HEAD> part of entitybody if text/html           */
+/*   type = 6  : HTTP <HEAD> part of entitybody if text/html           */
+/*               HTTP entitybody if application/marc                   */
+/*                                                                     */
+/* ------------------------------------------------------------------- */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <signal.h>
+
+#define FALSE               0
+#define TRUE                1
+#define BUFSIZE             10000
+#define TYPE_NONE           0     
+#define TYPE_HTTPHEAD       1     
+#define TYPE_HTTPALL        2     
+#define TYPE_HTTPBODY       3     
+#define TYPE_HTMLALL        4     
+#define TYPE_HTMLHEAD       5     
+#define TYPE_MARC           6     
+
+#define TRACE               0
+
+#define AGENT               "BIBSYS_htget v1.1"
+
+char conType[128];
+int htmlonly, marcrecord;
+
+
+
+void thandler(int i)
+{
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* geteoHEAD: Look for </HEAD> or <BODY                                */
+/*                                                                     */
+/* returns: 0 if not found                                             */
+/*          1 if found. Terminates buf immediately after </HEAD> or    */
+/*            immediately before <BODY                                 */
+/* ------------------------------------------------------------------- */
+
+int geteoHEAD(char *buf)
+{
+  char *p;
+  int i;
+
+  p = (char *) cstr(buf, "<BODY");
+  if (p)
+  {
+    i = p - buf;
+
+    buf[i] = '\n';
+    buf[i+1] = '\0';
+    return 1;
+  }
+
+  p = (char *) cstr(buf, "</HEAD>");
+  if (p)
+  {
+    i = p - buf + 7;
+
+    buf[i] = '\n';
+    buf[i+1] = '\0';
+    return 1;
+  }
+
+  return 0;
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* writeRequest: send request to server                                */
+/*                                                                     */
+/* returns: Number of bytes written                                    */
+/* ------------------------------------------------------------------- */
+
+int writeRequest(char *req, int server)
+{
+   if (TRACE)
+      printf("*** send(): %s\n", req);
+
+   return write(server, req, strlen(req));
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* getBody : Read the Entity-body into the file filename               */
+/*                                                                     */
+/* Open the given file for writing, read data from the                 */
+/* socket until a terminating '\0' is found, write to                  */
+/* the file. Returns 0 if ok, positive if an error results             */
+/* in errno being set, or -1 if other error.                           */
+
+/* Single read()'s blocking for more than TIMEOUT_SECONDS will         */
+/* be interrupted. The read() then returns a negative value, and       */
+/* errno will be set appropriately (EINTR).                            */
+/*                                                                     */
+/* Returns   0 if ok                                                   */
+/*         900 if read error                                           */
+/*                                                                     */
+/* ------------------------------------------------------------------- */
+
+int getBody(int server, int timeout, int fd, char *filename)
+{
+   int i, ef;
+   unsigned char *bf, buf[BUFSIZE + 1];
+   int  bytecount;
+   int  found_end;
+   
+   if (TRACE)
+     printf("*** Read entitybody\n");
+
+/* Loop until the endmark is found                                     */
+
+   found_end = FALSE;
+
+
+   while (!found_end) 
+   {
+      alarm (timeout);
+      bytecount = read (server, buf, BUFSIZE);
+      alarm (0);
+
+      if (bytecount < 0) 
+        return 900;                                 /* error in read() */
+
+      else if (bytecount == 0)
+        break;                                 /* server closed socket */
+
+
+      else
+      {
+       if (buf[bytecount-1] == '\0') 
+         {
+            bytecount--;              /* do not write the '\0' to file */
+            found_end = TRUE;                    /* terminate the loop */
+	 }
+
+/*       Write to file                                                 */
+
+         if (bytecount > 0) 
+         {
+            bf = (unsigned char *) buf;
+            bf[bytecount] = '\0';
+            if ( htmlonly )
+            {
+              ef = geteoHEAD(bf);
+              bytecount = strlen(bf);
+            }
+            else
+              ef = 0;
+            write (fd, bf, bytecount);
+            if (ef)
+              break;
+         }
+      }
+   }
+
+   return 0; 
+}
+      
+
+
+/* ------------------------------------------------------------------- */
+/* getHeader : Access file and read HTTP header                        */
+/*                                                                     */
+/* Returns   0 if ok                                                   */
+/*         904 if Content-type not "text/html"                         */
+/*         905 if Statusline > 255 bytes                               */
+/*         906 if Statusline < 4 bytes                                 */
+/*         907 if Statusline not starting with "HTTP"                  */
+/*         908 if Statuscode not numeric                               */
+/*         909 if size of header > BUFSIZE                             */
+/*         HTTP statuscode if <> 200                                   */
+/*                                                                     */
+/* ------------------------------------------------------------------- */
+
+int getHeader(int server, int timeout, int type, int fd, char *reason, char *loc)
+{
+   char buf[BUFSIZE+1], dummy[8];
+   unsigned char *p,  *cp = buf, *d = dummy;
+   int i, rc, statuscode, plf, rlen = 0;
+
+   reason = (char *) NULL;
+   *conType = 0;
+
+   if (TRACE)
+     printf("*** Read statusline\n");
+
+
+/* Read HTTP statusline (until LF or 0, max 256 byte)                 */
+
+   for ( cp = buf, *buf = 0; 1; cp++ )
+   {
+      alarm (timeout);
+      rc = read ( server, cp, 1 );
+      alarm (0);
+
+      if ( rc < 0 )
+	 return 900;
+
+      if ( *cp == '\r')
+      {
+        cp--;
+        continue;
+      }
+
+      rlen++;
+
+      if (TRACE)
+        printf("%c", *cp);
+
+      if ( *cp == 0 || rlen > 255)
+	 return 905;
+      if ( *cp == '\n')
+      {
+         *cp = 0;
+	 break;
+      }
+   }
+
+/*  Write statusline                                                 */
+
+   if ( ( type == TYPE_HTTPHEAD ) || ( type == TYPE_HTTPALL ) )
+   {
+     write(fd, buf, strlen(buf));
+     write(fd, "\n\n", 2);
+   }
+
+   if (TRACE)
+      printf("*** read() : (%d) %s\n", rlen, buf);
+
+
+/* Parse statusline                                                   */
+
+   if (rlen < 4)
+     return 906;
+
+   if (strncmp(buf, "HTTP", 4) != 0)
+     return 907;
+
+   p = strtok(buf, " ");
+   p = strtok(NULL, " ");
+
+   if (!*p)
+     statuscode = 200;
+   else
+   {
+     for (i = 0; i < strlen(p); i++)
+       if (!isdigit(p[i]))
+         return 908;
+   }
+   statuscode = atoi(p);
+
+   p = strtok(NULL, "\0");
+   if (p)
+     reason = p;
+
+   if (statuscode == 200)
+     statuscode = 0;
+
+   if (!type)
+     return statuscode;
+
+
+/* Read HTTP response header (until 0 or empty line, max BUFSIZE bytes  */
+
+   rlen = 0;
+   plf = FALSE;
+
+   if (TRACE)
+     printf("*** Read responseheader\n");
+
+   for ( cp = buf, *buf = 0; 1; cp++ )
+   {
+      alarm (timeout);
+      rc = read ( server, cp, 1 ); 
+      alarm (0);
+
+      if ( rc < 0 )
+	 return 900;
+
+      if ( *cp == '\r')
+      {
+        cp--;
+        continue;
+      }
+
+      rlen++;
+
+      if ( *cp == 0 || rlen > BUFSIZE)
+	 return 909;
+      else if ( *cp == '\n')
+      {
+         if (plf)
+         {
+           *cp = 0;
+	   break;
+         }
+         else
+           plf = TRUE;
+      }
+      else
+        plf = FALSE;
+   }
+
+/*  Write rest of HTTP header                                         */
+
+   if ( ( type == TYPE_HTTPHEAD ) || ( type == TYPE_HTTPALL ) )
+   {
+     write(fd, buf, strlen(buf));
+     write(fd, "\n", 1);
+   }
+
+   if (TRACE)
+      printf("*** read() : (%d) %s\n", rlen, buf);
+
+
+/* Parse header for Content-Type and Loaction                         */
+
+   rc = 904;
+
+   p = strtok(buf, "\n");
+   while (p)
+   {
+     if (strncasecmp(p, "Content-Type:", 13) == 0)
+     {
+       p += 13;
+       while (p[0] == ' ')
+         p++;
+       strcpy(conType, p);
+
+       if (strncasecmp(p, "text/html", 7) == 0)
+       {
+         if ( ( type == TYPE_HTMLHEAD) || (type == TYPE_MARC ) )
+           htmlonly = 1;
+         rc = 0;
+       }
+
+       else if (strncasecmp(p, "application/marc", 16) == 0)
+       {
+         if ( type == TYPE_MARC )
+         {
+           marcrecord = 1; 
+           rc = 0;
+         }
+       }
+     }
+
+     else if (strncasecmp(p, "Location:", 9) == 0)
+     {
+       p += 9;
+       while (p[0] == ' ')
+         p++;
+       strcpy(loc, p);
+     }
+     p = strtok(NULL, "\n");
+   }
+
+
+/* All OK. Socket is positioned at start of HTTP Entity-Body          */
+
+   if (rc)
+     return rc;
+   else
+     return statuscode;
+}
+
+
+
+
+
+/* ------------------------------------------------------------------- */
+/* htget  : Fetch a URL                                                */
+/* ------------------------------------------------------------------- */
+
+int htget(char *iurl, int type, int timeout, char *outfile, char *h_contype, char *h_location)
+{
+   int i, rc, fd, soc, port;
+   struct sockaddr_in addr; 
+   struct hostent *hp, *gethostbyname();
+   char	uurl[1024], *url = uurl, hostname[256], cport[64], req[1024];
+   char *h, *p, *q, *r;
+   char tfile[256], blank[2];
+
+   *blank = *h_contype = *h_location = 0; 
+   htmlonly = marcrecord = 0;
+
+   strcpy(tfile, "/tmp/geturl.tmp");
+   if (!*outfile)
+     outfile = (char *) tfile;
+
+   if (!*iurl || ( strlen(iurl) > 1023 ) )
+     return 901;
+
+   strcpy(url, iurl);
+
+/* Parse and validate URL                                             */
+
+   if (strncmp(url, "http://", 7) != 0)
+     return 901;
+
+   url += 7;
+
+   q = strtok(url, "/");
+   if (!q)
+     return 901;
+
+   r = strtok(NULL, "\0");
+   if (!r)
+     r = (char *) blank;
+
+   h = strtok(q, ":");
+   if (!*h)
+     return 901;
+
+   strcpy(hostname, h);
+
+   p = strtok(NULL, "\0");
+
+   if (!p || !*p)
+     port = 80;
+   else
+   {
+     for (i = 0; i < strlen(p); i++)
+       if (!isdigit(p[i]))
+         return 901;
+     port = atoi(p);
+   }
+   sprintf(req, "GET /%s HTTP/1.0\r\nUser_Agent: %s\n\n", r, AGENT);
+  
+
+/* Establish handler for the alarm-signal                              */
+
+   signal (SIGALRM, thandler);
+
+
+/* Get IP address                                                      */
+ 
+   hp = gethostbyname(hostname);
+   if (!hp)
+     return 902;
+
+/* Get socket and connect                                              */
+ 
+   soc = socket(AF_INET, SOCK_STREAM, 0);
+ 
+   addr.sin_family = AF_INET;
+   
+   memcpy( &addr.sin_addr.s_addr, hp->h_addr, (size_t) hp->h_length );
+
+   addr.sin_port = htons(port);
+   if (connect(soc, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) < 0)
+      return 903;
+
+
+/* Open the destination file                                           */
+ 
+   if (type)
+   {
+     fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC , 0666);
+     if (fd < 0)  
+     {
+        close(soc);
+        return 910;
+     }
+   }
+
+
+
+
+/* Write HTTP-request                                               */
+ 
+   if (!writeRequest(req, soc))
+   {
+     close(soc);
+     if (type)
+       close(fd);
+     return 999;
+   }
+
+
+/* Read header part of response                                     */
+
+   rc = getHeader(soc, timeout, type, fd, r, h_location);
+   
+   if ( ( rc == 904 ) && (type < 4 ) )
+     rc = 0;
+
+   if ( ( rc == 0 ) && ( type > 1 ) )
+     rc = getBody(soc, timeout, fd, outfile);
+ 
+   close(soc);
+   if (type)
+     close(fd);
+   strcpy(h_contype, conType);
+
+   return rc;
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/isMARC.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/isMARC.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/isMARC.c	(revision 16571)
@@ -0,0 +1,333 @@
+/* ------------------------------------------------------------------- */
+/* isMARC     : Convert a metatag struct to ISMARC                     */
+/*              (i.e. UKMARC as used in the National and University    */
+/*              Library of Island).                                    */
+/*                                                                     */
+/* Specs      : http://www.bibsys.no/meta/d2m/iscross.txt              */
+/*                                                                     */
+/* Author     : Ole Husby                                              */
+/* Last update: 1998-09-30                                             */
+/* ------------------------------------------------------------------- */
+
+#include <stdio.h>
+#include <string.h>
+#include "d2m.h" 
+
+
+
+
+/* ------------------------------------------------------------------- */
+/* Splits Icelandig name without a comma                               */
+/* ------------------------------------------------------------------- */
+
+int split_ice2(char *str)
+{
+  char *q, *temp, *suba, *subi, *subb;
+
+  if (!strstr(str, " "))
+    return 1;
+
+  suba = (char *) malloc(strlen(str) + 50);
+  subi = (char *) malloc(strlen(str) + 50);
+  subb = (char *) malloc(strlen(str) + 50);
+  temp = (char *) malloc(strlen(str) + 50);
+
+  *suba = *subi = *subb = *temp = 0;
+
+  q = strtok(str, " ");
+  while (q)
+  {
+    while ( ( q[0] == ' ' ) && ( strlen(q) ) )
+      q++;
+
+    while( ( q[strlen(q) - 1] == ' ' ) && ( strlen(q) ) )
+      q[strlen(q) - 1] = '\0';
+
+    if (*q)
+    {
+      if (!*suba)
+        strcpy(suba, q);
+      else
+      {
+        if (*temp)
+        {
+          if (*subi)
+            strcat(subi, " ");
+          strcat(subi, temp);
+        }
+        strcpy(temp, q);
+      }
+    }
+    q = strtok(NULL, " ");
+  }
+
+  *str = 0;
+
+  if (*temp)
+  {
+    if (*subi)
+      strcpy(subb, temp);
+    else
+      strcpy(subi, temp);
+  }
+
+  if (*suba)
+  {
+    strcpy(str, suba);
+    if (*subi)
+    {
+      strcat(str, " $i ");
+      strcat(str, subi); 
+    }
+    if (*subb)
+    {
+      strcat(str, " $b ");
+      strcat(str, subb); 
+    }
+  }
+
+  free(suba);
+  free(subi);
+  free(subb);
+  free(temp);
+
+  return 40;
+}
+
+
+
+
+
+/* ------------------------------------------------------------------- */
+/* Splits Icelandig name                                               */
+/* ------------------------------------------------------------------- */
+
+int split_icename(char *str, int i2)
+{
+  char *p, *q, subtag[5];
+
+  if (!strstr(str, ","))
+  {
+    if (i2)
+      return split_ice2(str);
+    else
+      return 1;
+  }
+
+  p = (char *) malloc(strlen(str) + 50);
+  *p = 0;
+  *subtag = 0;
+
+  q = strtok(str, ",");
+  if (q)
+  {
+    strcpy(p, q);
+    q = strtok(NULL, "\0");
+    if (q)
+    {
+      while ( ( q[0] == ' ' ) && ( strlen(q) ) )
+        q++;
+      strcat(p, " $h ");
+      strcat(p, q);
+    }
+    strcpy(str, p);
+  }
+
+  free(p);
+
+  return 10;
+}
+
+
+int isMARC(struct metatag *mt, struct marcrec *mr)
+{
+  char pre[64], type_tag[4], creator_tag[4], title_tag[6];
+  int i, ind, ice2;
+
+  *pre = 0;
+
+  if (strcasecmp(mt->name, "title") == 0)
+  {
+    if ( (!*mt->type)
+         | (strcasecmp(mt->type, "main") == 0)
+         | (strcasecmp(mt->type, "long") == 0) )
+    {
+      if (mr->ntitles)
+        strcpy(title_tag, "24630");
+      else
+        strcpy(title_tag, "24510");
+
+      mr->ntitles++;
+
+      sprintf(pre, "%s$a", title_tag);
+    }
+  }
+
+  else if (strcasecmp(mt->name, "creator") == 0)
+  {
+    if ( strcasecmp(mt->type, "personal") == 0) 
+    {
+      if (!mr->ncreators)
+        strcpy(creator_tag, "100");
+      else 
+        strcpy(creator_tag, "700");
+
+      ice2 = 1; 
+      ind = split_icename(mt->value, ice2);
+      sprintf(pre, "%s%2d$a", creator_tag, ind);
+    }
+    else if (strcasecmp(mt->type, "corporate") == 0)
+    {
+      if (!mr->ncreators)
+        strcpy(creator_tag, "110");
+      else 
+        strcpy(creator_tag, "710");
+      sprintf(pre, "%s20$a", creator_tag);
+    }
+    else
+    {
+      ice2 = 0;
+      strcpy(pre, "720  $a");
+      ind = split_icename(mt->value, ice2);
+    }
+    mr->ncreators++;
+  }
+
+  else if (strncasecmp(mt->name, "contributor", 11) == 0)
+  {
+    if ( strcasecmp(mt->type, "personal") == 0) 
+    {
+      ice2 = 1; 
+      ind = split_icename(mt->value, ice2);
+      sprintf(pre, "700%2d$a", ind);
+    }
+    else if (strcasecmp(mt->type, "corporate") == 0)
+    {
+      strcpy(pre, "71020$a");
+    }
+    else
+    {
+      ice2 = 0;
+      strcpy(pre, "720  $a");
+      ind = split_icename(mt->value, ice2);
+    }
+    mr->ncreators++;
+  }
+
+
+  else if (strcasecmp(mt->name, "publisher") == 0)
+    strcpy(pre, "260  $b");
+
+  else if (strcasecmp(mt->name, "description") == 0)
+    strcpy(pre, "513  $a");
+
+  else if (strcasecmp(mt->name, "coverage") == 0)
+  {
+    if (strcasecmp(mt->type , "spatial") == 0)
+    {
+      strcpy(pre, "651  $a");
+      split_subj(mt->value);
+    }
+    else
+      strcpy(pre, "500  $a");
+  }
+
+  else if (strcasecmp(mt->name, "source") == 0)
+    strcpy(pre, "787  $a");
+
+  else if (strcasecmp(mt->name, "rights") == 0)
+  {
+    if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(pre, "856  $3 rights $u");
+    else
+      strcpy(pre, "500  $a");
+  }
+
+  else if (strcasecmp(mt->name, "identifier") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "urn") == 0)
+      strcpy(pre, "8567 $u urn:");
+    else if (strcasecmp(mt->scheme, "nbn") == 0)
+      strcpy(pre, "015  $a");
+    else if (strcasecmp(mt->scheme, "isbn") == 0)
+      strcpy(pre, "021  $a");
+    else if (strcasecmp(mt->scheme, "issn") == 0)
+      strcpy(pre, "022  $a");
+    else if (strcasecmp(mt->scheme, "isrc") == 0)
+      strcpy(pre, "024  $a");
+    else if (strcasecmp(mt->scheme, "ismn") == 0)
+      strcpy(pre, "025  $a");
+    else if (strcasecmp(mt->scheme, "isrn") == 0)
+      strcpy(pre, "027  $a");
+  }
+
+  else if (strcasecmp(mt->name, "type") == 0)
+    strcpy(pre, "655  $a");
+
+  else if (strcasecmp(mt->name, "relation") == 0)
+    strcpy(pre, "787  $a");
+
+  else if (strcasecmp(mt->name, "language") == 0)
+  {
+    if (strcasecmp(mt->scheme, "z39.53") == 0)
+    {
+      strcpy(pre, "04109$a");
+      if (strlen(mt->value) == 3) 
+        put008(mr->s008, mt->value, F008_LANGUAGE);
+    }
+    else if (strcasecmp(mt->scheme, "usmarc") == 0)
+      strcpy(pre, "04109$a");
+    else
+      strcpy(pre, "546  $a");
+  }
+
+  else if (strcasecmp(mt->name, "format") == 0)
+    strcpy(mr->fmat, mt->value); 
+
+  else if (strcasecmp(mt->name, "subject") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "680  $a");
+    else if (strcasecmp(mt->scheme, "udc") == 0)
+      strcpy(pre, "080  $a");
+    else if (strcasecmp(mt->scheme, "lcc") == 0)
+      strcpy(pre, "050  $a");
+    else if (strcasecmp(mt->scheme, "lcsh") == 0)
+      strcpy(pre, "650  $a");
+    else if (strcasecmp(mt->scheme, "ddc") == 0)
+      strcpy(pre, "082  $a");
+    else if (strcasecmp(mt->scheme, "nlm") == 0)
+      strcpy(pre, "060  $a");
+    else if (strcasecmp(mt->scheme, "landslyk") == 0)
+      strcpy(pre, "659  $a");
+    else if (strcasecmp(mt->scheme, "kerfefn") == 0)
+      strcpy(pre, "659  $a");
+    else if (strcasecmp(mt->scheme, "dbc") == 0)
+      strcpy(pre, "65002$a");
+    else if (strcasecmp(mt->scheme, "mesh") == 0)
+      strcpy(pre, "690  $a");
+    else
+      strcpy(pre, "65004$a");
+  }
+
+  else if (strcasecmp(mt->name, "date") == 0)
+  {
+    if (find_year(mt->value))
+    {
+      strcpy(mr->year, mt->value);
+      put008(mr->s008, mt->value, F008_DATE1);
+    }
+  }
+
+  if (*pre)
+  {
+    strcat(mr->marcline, pre);
+    strcat(mr->marcline, " ");
+    strcat(mr->marcline, mt->value);
+    strcat(mr->marcline, "\n");
+  }
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/marc2line.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/marc2line.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/marc2line.c	(revision 16571)
@@ -0,0 +1,243 @@
+/* ------------------------------------------------------------------- */
+/* marc2line : Reads an ISO 2709 MARC record, converts to MARC         */
+/*             "Line format"                                           */
+/*                                                                     */
+/* author    : Ole Husby, BIBSYS                                       */
+/* updated   : 1998-09-30                                              */
+/* ------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#define DIRL                                   3600
+
+#define LINEL                                  72 
+#define SUBFIELD_CODE                          '\x1f'
+#define SUBFIELD_STR                           "\x1f" 
+#define FIELD_TERMINATOR                       '\x1e'
+#define RECORD_TERMINATOR                      '\x1d'
+
+#define BIBSYS_TYPE                            0
+#define NORMARC_TYPE                           1
+
+union LDR   {
+   char ldr_string[24+1];
+   struct {
+      char record_length[5],
+      record_status,
+      record_type,
+      bibliographic_level,
+      unused1[2],
+      indicator_count,
+      subfield_code_count,
+      base_adress[5],
+      unused2[3],
+      entry1,
+      entry2,
+      entry3,
+      entry4;
+   } ltab;
+} ldr; 
+
+static char out_record[10240];
+static int out_type;
+
+
+
+/* ------------------------------------------------------------------- */
+/* One subfield string is split into output lines                      */
+/* ------------------------------------------------------------------- */
+
+static void out_subfield(data, prefix, slen)
+char *data, *prefix;
+int slen;
+
+{
+   char lineprefix[7], subprefix[4], *spre;
+   int i, more, len, max;
+
+   if (out_type == BIBSYS_TYPE)
+      strcpy(lineprefix, prefix);
+   else
+   {
+      if (prefix[0] == ' ') strcpy(lineprefix, " ");
+      else                  strcpy(lineprefix, "*");
+      strcat(lineprefix, prefix);
+   }
+
+   max = LINEL;
+
+   if (slen)
+   {
+      spre = (char *) subprefix;
+      strcpy(spre, "$");                       /* Construct subfield    */
+      strncat(spre, data, 1);                  /* prefix                */
+      if (out_type == BIBSYS_TYPE) 
+	 strcat(spre, " ");
+      data++;
+      max = LINEL - 2; 
+      if (out_type == BIBSYS_TYPE) 
+	 max--;
+   }
+   else spre = NULL;  
+
+   more = 1;
+
+   while (more)
+   {
+      if (slen)
+         while (data[0] == ' ') data++;    /* skip leading blanks    */
+
+      strcat(out_record, lineprefix);      /* Start with prefix      */
+      strcpy(lineprefix, "     ");
+      if (out_type == NORMARC_TYPE) 
+	 strcat(lineprefix, " ");
+
+      len = strlen(data);
+      if (len > max)                       /* Must fit into one line */
+      {
+	 len = max;
+	 for (i = max; i > max - 15; i--)
+	 {
+	    if (data[i] == ' ')
+	    {
+	       len = i;
+	       break;
+	    }
+	 }
+      }
+      else more = 0;
+
+      if (spre)
+      {
+	 strcat(out_record, spre);         /* subfield pref needed  */
+	 spre = NULL;                      /* only first line       */
+	 max = LINEL;
+      }
+
+      strncat(out_record, data, len);      /* append data           */
+      if (more) data += len;
+      strcat(out_record, "\n");
+   }
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* One MARC field is split into subfields and given to output          */
+/* ------------------------------------------------------------------- */
+
+static int out_field(data, ftag, find)
+char *data, *ftag, *find;
+
+{
+   char prefix[5];
+   char subfield[5120], *sub = subfield;
+   int subcode = 0;
+
+   strcpy(prefix, ftag);
+
+   if (!find)                                 /* output entire field   */ 
+   {
+      out_subfield(data, prefix, subcode);
+      return 1;
+   }
+
+   strcat(prefix, find);
+
+   if (data[0] != SUBFIELD_CODE) return 0;    /* requires subf code in */
+   data++;                                    /*   first byte          */
+
+   sub = strtok(data, SUBFIELD_STR);          /* find first subfield   */
+   if (!sub) return 0;
+
+   subcode = 1;
+   out_subfield(sub, prefix, subcode);        /* output subfield       */
+   strcpy(prefix, "     ");                   /* reset prefix          */
+
+   while (sub = strtok(NULL, SUBFIELD_STR))   /* find and output rest  */
+      out_subfield(sub, prefix, subcode);     /* of the subfields      */
+
+   return 1;
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* Main program                                                        */
+/* ------------------------------------------------------------------- */
+
+char *marc2line(record, type)          
+char *record, *type;
+{
+   char buffer[10240], tag[4], indicators[3];
+   char *cp, *fld, *buf = buffer, *cq;
+   char directory[DIRL+1], *dir = directory, *ind;
+   char sBase[6], fLen[5], fStart[6];
+   int           dlen, base, x = 0, more = 1, len, start;
+
+   if (!record || !*record)
+     return (char *) NULL;
+
+   strcpy(buf, record);
+   *out_record = 0;                                 /* reset out area     */
+
+   if (strcmp(type, "bibsys") == 0) out_type = BIBSYS_TYPE;
+   else out_type = NORMARC_TYPE;
+
+   strncpy(ldr.ldr_string, buf, 24);                 /* get leader         */
+   ldr.ldr_string[24] = '\0';
+   buf += 24;
+  
+   strncpy(sBase, ldr.ltab.base_adress, 5);
+   sBase[5] = '\0';
+   base = atoi(sBase);
+
+   dlen = base - 24;                                 /* get directory      */
+   strncpy(dir, buf, dlen);
+   dir[dlen] = '\0';
+   buf += dlen;
+
+   cp = dir;
+
+   while (more)                                      /* loop until EOdir   */ 
+   {
+      if (*cp == FIELD_TERMINATOR)  break;
+      if (strlen(cp) < 13) return (char *) NULL;
+
+      strncpy(tag, cp, 3);                           /* get tag            */
+      tag[3] = '\0';
+      cp +=3;
+
+      strncpy(fLen, cp, 4);                         /* get length          */
+      fLen[4] = '\0';
+      len = atoi(fLen) -1;                          /* discard field term. */
+      cp += 4;
+
+      strncpy(fStart, cp, 5);                       /* get start of field  */
+      fStart[5] = '\0';
+      start = atoi(fStart);
+      cp += 5;
+
+      fld = buf + start;                            /* get field           */ 
+      fld[len] = '\0';
+      
+      if (strncmp(tag, "00", 2) != 0)               /* get indicators      */
+      {
+	 indicators[0] = '\0';
+	 strncat(indicators, fld, 2);
+	 ind = (char *) indicators;
+	 fld += 2;
+      }
+      else ind = NULL;
+
+      if (!out_field(fld, tag, ind))                /* output field         */
+	 return (char *) NULL;
+
+   }
+
+   return (char *) out_record;
+
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/norMARC.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/norMARC.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/norMARC.c	(revision 16571)
@@ -0,0 +1,194 @@
+/* ------------------------------------------------------------------- */
+/* norMARC   : Convert a metatag struct to NORMARC                     */
+/*                                                                     */
+/* 1998-09-30: Ole Husby                                               */
+/* ------------------------------------------------------------------- */
+
+#include <stdio.h>
+#include <string.h>
+#include "d2m.h" 
+
+
+
+int norMARC(struct metatag *mt, struct marcrec *mr)
+{
+  char pre[64], creator_tag[4], title_tag[4];
+
+  *pre = 0;
+
+  if (strcasecmp(mt->name, "title") == 0)
+  {
+    if ( (!*mt->type)
+         | (strcasecmp(mt->type, "main") == 0)
+         | (strcasecmp(mt->type, "long") == 0) )
+    {
+      if (mr->ntitles)
+        strcpy(title_tag, "246");
+      else
+        strcpy(title_tag, "245");
+
+      mr->ntitles++;
+
+      sprintf(pre, "%s  $a", title_tag);
+    }
+    else if (strcasecmp(mt->type, "subtitle") == 0)
+    {
+      if (mr->ntitles < 2)
+        strcpy(mr->subtitle, mt->value);
+    }
+  }
+
+  else if (strcasecmp(mt->name, "creator") == 0)
+  {
+    if ( (!*mt->type) || (strcasecmp(mt->type, "name") == 0) 
+      || (strcasecmp(mt->type, "personalname") == 0) )
+    {
+      if (mr->ncreators)
+        strcpy(creator_tag, "700");
+      else
+        strcpy(creator_tag, "100");
+
+      mr->ncreators++;
+
+      sprintf(pre, "%s  $a", creator_tag);
+    }
+
+    else if (strcasecmp(mt->type, "corporatename") == 0) 
+    {
+      if (mr->ncreators)
+        strcpy(creator_tag, "710");
+      else
+        strcpy(creator_tag, "110");
+
+      mr->ncreators++;
+
+      sprintf(pre, "%s  $a", creator_tag);
+    }
+  }
+
+  else if (strcasecmp(mt->name, "publisher") == 0)
+  {
+    if (!*mt->type)
+      strcpy(pre, "260  $b");
+    else if (strcasecmp(mt->type, "name") == 0)
+      strcpy(pre, "260  $b");
+  }
+
+  else if (strcasecmp(mt->name, "contributor") == 0)
+  {
+    if ( (!*mt->type)|| (strcasecmp(mt->type, "name") == 0)
+      || (strcasecmp(mt->type, "personalname") == 0) )
+      strcpy(pre, "700  $a");
+    else if (strcasecmp(mt->type, "corporatename") == 0)
+      strcpy(pre, "710  $a");
+  }
+
+  else if (strcasecmp(mt->name, "coverage") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "500  $a");
+    else if (strcasecmp(mt->scheme, "freetext") == 0)
+      strcpy(pre, "500  $a");
+  }
+
+  else if (strcasecmp(mt->name, "source") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "500  $a Kilde:");
+    else if (strcasecmp(mt->scheme, "freetext") == 0)
+      strcpy(pre, "500  $a Kilde:");
+    else if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(pre, "500  $a Kilde: URL:");
+    else if (strcasecmp(mt->scheme, "urn") == 0)
+      strcpy(pre, "500  $a Kilde: URN:");
+    else if (strcasecmp(mt->scheme, "isbn") == 0)
+      strcpy(pre, "500  $a Kilde: ISBN:");
+    else if (strcasecmp(mt->scheme, "issn") == 0)
+      strcpy(pre, "500  $a Kilde: ISSN:");
+  }
+
+  else if (strcasecmp(mt->name, "rights") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "500  $a Copyright:");
+    else if (strcasecmp(mt->scheme, "freetext") == 0)
+      strcpy(pre, "500  $a Copyright:");
+  }
+
+  else if (strcasecmp(mt->name, "identifier") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "urn") == 0)
+      strcpy(pre, "856  $u urn:");
+    else if (strcasecmp(mt->scheme, "isbn") == 0)
+      strcpy(pre, "020  $a");
+    else if (strcasecmp(mt->scheme, "issn") == 0)
+      strcpy(pre, "022  $a");
+  }
+
+  else if (strcasecmp(mt->name, "language") == 0)
+  {
+    if (strcasecmp(mt->scheme, "z39.53") == 0)
+    {
+      if (strlen(mt->value) == 3)
+        put008(mr->s008, mt->value, F008_LANGUAGE);
+    }
+  }
+
+  else if (strcasecmp(mt->name, "format") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(mr->fmat, mt->value);
+    else if (strcasecmp(mt->scheme, "imt") == 0)
+      strcpy(mr->fmat, mt->value);
+    else if (strcasecmp(mt->scheme, "mime") == 0)
+      strcpy(mr->fmat, mt->value);
+  }
+
+  else if (strcasecmp(mt->name, "subject") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "691  $a");
+    else if (strcasecmp(mt->scheme, "internal") == 0)
+      strcpy(pre, "691  $a");
+    else if (strcasecmp(mt->scheme, "udc") == 0)
+      strcpy(pre, "080  $a");
+    else if (strcasecmp(mt->scheme, "lcsh") == 0)
+      strcpy(pre, "650  $a");
+    else if (strcasecmp(mt->scheme, "ddc") == 0)
+      strcpy(pre, "082  $a");
+    else if (strcasecmp(mt->scheme, "mesh") == 0)
+      strcpy(pre, "660  $a");
+    else if (strcasecmp(mt->scheme, "humord") == 0)
+      strcpy(pre, "698  $a");
+    else if (strcasecmp(mt->scheme, "ntub") == 0)
+      strcpy(pre, "699  $a");
+  }
+
+  else if (strcasecmp(mt->name, "date") == 0)
+  {
+    if ( (strncasecmp(mt->scheme, "ans", 3) == 0) ||
+         (strncasecmp(mt->scheme, "iso", 3) == 0) )
+    {
+      if ( (!*mt->type) || ( strcasecmp(mt->type, "current") == 0) )
+      {
+        if (find_year(mt->value))
+        {
+          strcpy(mr->year, mt->value);
+          put008(mr->s008, mt->value, F008_DATE1);
+        }
+      }
+    }
+  }
+
+  if (*pre)
+  {
+    strcat(mr->marcline, pre);
+    strcat(mr->marcline, " ");
+    strcat(mr->marcline, mt->value);
+    strcat(mr->marcline, "\n");
+  }
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/strcasecmp.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/strcasecmp.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/strcasecmp.c	(revision 16571)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of California at Berkeley. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific written prior permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)strcasecmp.c	5.5 (Berkeley) 11/24/87";
+#endif /* LIBC_SCCS and not lint */
+
+/*
+ * This array is designed for mapping upper and lower case letter
+ * together for a case independent comparison.  The mappings are
+ * based upon ascii character sequences.
+ */
+static unsigned char charmap[] = {
+	'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
+	'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
+	'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
+	'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
+	'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
+	'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
+	'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
+	'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
+	'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
+	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
+	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
+	'\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
+	'\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
+	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
+	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
+	'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
+	'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
+	'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
+	'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
+	'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
+	'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
+	'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
+	'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
+	'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
+	'\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
+	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
+	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
+	'\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337',
+	'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
+	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
+	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
+	'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
+};
+
+int
+strcasecmp(s1, s2)
+    char *s1, *s2;
+{
+    register unsigned char u1, u2;
+
+    for (;;) {
+	u1 = (unsigned char) *s1++;
+	u2 = (unsigned char) *s2++;
+	if (charmap[u1] != charmap[u2]) {
+	    return charmap[u1] - charmap[u2];
+	}
+	if (u1 == '\0') {
+	    return 0;
+	}
+    }
+}
+int
+strncasecmp(s1, s2, n)
+    char *s1, *s2;
+    int n;
+{
+    register unsigned char u1, u2;
+    int i;
+    for (i=0;i<n;i++) {
+	u1 = (unsigned char) *s1++;
+	u2 = (unsigned char) *s2++;
+	if (charmap[u1] != charmap[u2]) {
+	    return charmap[u1] - charmap[u2];
+	}
+	if (u1 == '\0') {
+	    return 0;
+	}
+    }
+    return 0;
+}
+
+
+
+
Index: /gsdl/trunk/runtime-src/packages/d2m/sweMARC.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/sweMARC.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/sweMARC.c	(revision 16571)
@@ -0,0 +1,259 @@
+/* ------------------------------------------------------------------- */
+/* sweMARC    : Convert a metatag struct to LIBRISMARC                 */
+/*                                                                     */
+/* Author     : Ole Husby                                              */
+/* Last update: 1998-09-30                                             */
+/* ------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "d2m.h" 
+
+
+
+
+/* ---------------------------------------------------------------------- */
+/* Decides on first indicator for personal name                           */
+/*                                                                        */
+/* f : no comma                                                           */
+/* e : comma, with only one word preceeding                               */
+/* s : comma, with more than one word preceeding (delimiter blank or "-") */
+/* ---------------------------------------------------------------------- */
+
+int personal_indicator(char *pname)
+{
+  char *comma, *blank, *hyphen;
+
+  comma = strstr(pname, ",");
+  if (!comma)
+    return (int) 'f';
+
+  blank = strstr(pname, " ");
+  hyphen = strstr(pname, "-");
+
+  if ( (blank && blank < comma) || (hyphen && hyphen < comma) )
+    return (int) 's';
+  else
+    return (int) 'e';
+}
+
+
+
+/* ---------------------------------------------------------------------- */
+/* Decides tag for type                                                   */
+/* ---------------------------------------------------------------------- */
+
+int parse_swetype(char *str, char *tag)
+{
+   if ( (strcasecmp(str, "diss."             ) == 0) 
+     || (strcasecmp(str, "dissertation"      ) == 0) 
+     || (strcasecmp(str, "thesis"            ) == 0) 
+     || (strcasecmp(str, "domkap.avh."       ) == 0) 
+     || (strcasecmp(str, "hab.-schr"         ) == 0) 
+     || (strcasecmp(str, "prästmösteavh."    ) == 0)
+     || (strcasecmp(str, "avhandling"        ) == 0) ) 
+     strcpy(tag, "502");
+   else
+     strcpy(tag, "500");
+
+   return 1;
+}
+
+
+/* ---------------------------------------------------------------------- */
+/* sweMARC()                                                              */
+/* ---------------------------------------------------------------------- */
+
+int sweMARC(struct metatag *mt, struct marcrec *mr)
+{
+  char pre[64], creator_tag[4], type_tag[4];
+  int ind1;
+
+  *pre = 0;
+
+  if (strcasecmp(mt->name, "title") == 0)
+  {
+    if ( (!*mt->type)
+         | (strcasecmp(mt->type, "main") == 0)
+         | (strcasecmp(mt->type, "long") == 0) )
+    {
+      if (mr->ntitles)
+        strcpy(pre, "740  $a");
+      else
+      {
+        mr->ntitles++;
+        strcpy(pre, "245  $a");
+      }
+    }
+  }
+
+
+  else if (strcasecmp(mt->name, "creator") == 0)
+  {
+    if (!*mt->type)
+      strcpy(pre, "720  $a");
+    else if (strcasecmp(mt->type, "personal") == 0) 
+    {
+      ind1 = personal_indicator(mt->value);
+      if (mr->ncreators)
+        strcpy(creator_tag, "700");
+      else
+      {
+        strcpy(creator_tag, "100");
+        mr-> ncreators++;
+      }
+      sprintf(pre, "%s%c $a", creator_tag, ind1);
+    }
+    else if (strcasecmp(mt->type, "corporate") == 0)
+    {
+      if (mr->ncreators)
+        strcpy(creator_tag, "710");
+      else
+      {
+        strcpy(creator_tag, "110");
+        mr-> ncreators++;
+      }
+      sprintf(pre, "%sc $a", creator_tag);
+    }
+  }
+
+
+  else if (strncasecmp(mt->name, "contributor", 11) == 0)     /* Note both pl and sgl allowed */
+  {
+    if (!*mt->type)
+      strcpy(pre, "720  $a");
+    else if (strcasecmp(mt->type, "personal") == 0) 
+    {
+      ind1 = personal_indicator(mt->value);
+      sprintf(pre, "700%cm$a", ind1);
+    }
+    else if (strcasecmp(mt->type, "corporate") == 0)
+      strcpy(pre, "710  $a");
+  }
+
+
+  else if (strcasecmp(mt->name, "publisher") == 0)          /* Note both should go to same tag! */
+  {
+    if (!*mt->type)
+      strcpy(pre, "260  $b");
+    else if (strcasecmp(mt->type, "email") == 0)
+      strcpy(pre, "260  $d");
+  }
+
+
+
+  else if (strcasecmp(mt->name, "description") == 0)
+    strcpy(pre, "520  $a");
+
+
+
+  else if (strcasecmp(mt->name, "coverage") == 0)
+  {
+    if (!*mt->type)
+      strcpy(pre, "500  $a");
+    else if (strcasecmp(mt->type , "spatial") == 0)
+      strcpy(pre, "651  $a");
+    else if (strcasecmp(mt->type,  "temporal") == 0)
+      strcpy(pre, "650  $a");
+  }
+
+  else if (strcasecmp(mt->name, "source") == 0)
+    strcpy(pre, "786  $a");
+
+
+  else if (strcasecmp(mt->name, "relation") == 0)
+    strcpy(pre, "787  $a");
+
+
+  else if (strcasecmp(mt->name, "rights") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "500  $a");
+    if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(pre, "856  $u");
+    if (strcasecmp(mt->scheme, "urn") == 0)
+      strcpy(pre, "856  $g");
+  }
+
+  else if (strcasecmp(mt->name, "identifier") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "urn") == 0)
+      strcpy(pre, "856  $g");
+    else if (strcasecmp(mt->scheme, "ismn") == 0)
+      strcpy(pre, "538  $a ISMN $b");
+    else if (strcasecmp(mt->scheme, "sici") == 0)
+      strcpy(pre, "538  $a SICI $b");
+    else 
+      sprintf(pre, "538  $a %s $b", mt->scheme);
+  }
+
+  else if (strcasecmp(mt->name, "type") == 0)
+  {
+    parse_swetype(mt->value, (char *) type_tag);
+    sprintf(pre, "%s  $a", type_tag);
+  }
+
+  else if (strcasecmp(mt->name, "language") == 0)
+  {
+    strcpy(pre, "506  $a");
+    if (strcasecmp(mt->scheme, "z39.53") == 0)
+      put008(mr->s008, mt->value, F008_LANGUAGE);
+  }
+
+  else if (strcasecmp(mt->name, "format") == 0)
+  {
+    if ( (!*mt->scheme)
+      || (strcasecmp(mt->scheme, "imt") == 0)
+      || (strcasecmp(mt->scheme, "mime") == 0) )
+      strcpy(pre, "856  $q");
+  }
+
+  else if (strcasecmp(mt->name, "subject") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "697  $a");
+    else if (strcasecmp(mt->scheme, "udc") == 0)
+      strcpy(pre, "080  $a");
+    else if (strcasecmp(mt->scheme, "lcsh") == 0)
+      strcpy(pre, "650  $a");
+    else if (strcasecmp(mt->scheme, "ddc") == 0)
+      strcpy(pre, "082  $a");
+    else if (strcasecmp(mt->scheme, "lcc") == 0)
+      strcpy(pre, "087  $a");
+    else if (strcasecmp(mt->scheme, "sab") == 0)
+      strcpy(pre, "081  $a");
+    else if (strcasecmp(mt->scheme, "mesh") == 0)
+      strcpy(pre, "660  $a");
+    else
+      strcpy(pre, "650  $a");
+  }
+
+  else if (strcasecmp(mt->name, "date") == 0)
+  {
+    if ( (!*mt->type) || ( strcasecmp(mt->type, "current") == 0) )
+    {
+      if ( (strncasecmp(mt->scheme, "ans", 3) == 0) 
+         || (strncasecmp(mt->scheme, "iso", 3) == 0) )
+      {
+        if (find_year(mt->value))
+        {
+          strcpy(mr->year, mt->value);
+          put008(mr->s008, mt->value, F008_DATE1);
+        }
+      }
+    }
+  }
+
+  if (*pre)
+  {
+    strcat(mr->marcline, pre);
+    strcat(mr->marcline, " ");
+    strcat(mr->marcline, mt->value);
+    strcat(mr->marcline, "\n");
+  }
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/test.data
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/test.data	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/test.data	(revision 16571)
@@ -0,0 +1,1 @@
+<meta name="DC.title" content="Test file for d2m">
Index: /gsdl/trunk/runtime-src/packages/d2m/usMARC.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/usMARC.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/usMARC.c	(revision 16571)
@@ -0,0 +1,165 @@
+/* ------------------------------------------------------------------- */
+/* usMARC   : Convert a metatag struct to USMARC                       */
+/*                                                                     */
+/* 1998-09-30: Ole Husby                                               */
+/* ------------------------------------------------------------------- */
+
+#include <stdio.h>
+#include <string.h>
+#include "d2m.h" 
+
+
+
+void usMARC(struct metatag *mt, struct marcrec *mr)
+{
+  char pre[64], title_tag[4];
+
+  *pre = 0;
+
+  if (strcasecmp(mt->name, "title") == 0)
+  {
+    if ( (!*mt->type)
+         | (strcasecmp(mt->type, "main") == 0)
+         | (strcasecmp(mt->type, "long") == 0) )
+    {
+      if (mr->ntitles)
+        strcpy(title_tag, "2460");
+      else
+        strcpy(title_tag, "245 ");
+
+      mr->ntitles++;
+
+      sprintf(pre, "%s $a", title_tag);
+    }
+  }
+
+  else if (strcasecmp(mt->name, "creator") == 0) 
+  {
+    if (!*mt->type)
+      strcpy(pre, "720  $a");
+    else if ( (strcasecmp(mt->type, "name") == 0)
+            || (strcasecmp(mt->type, "personal") == 0) )
+      strcpy(pre, "700  $a");
+    else if (strcasecmp(mt->type, "corporate") == 0)
+      strcpy(pre, "710  $a");
+  }
+
+
+  else if (strcasecmp(mt->name, "publisher") == 0)
+  {
+    if (!*mt->type)
+      strcpy(pre, "260  $b");
+    else if (strcasecmp(mt->type, "name") == 0)
+      strcpy(pre, "260  $b");
+  }
+
+  else if (strncasecmp(mt->name, "contributor", 11) == 0)     /* Note both pl and sgl allowed */
+  {
+    if (!*mt->type)
+      strcpy(pre, "720  $a");
+    else if ( (strcasecmp(mt->type, "name") == 0)
+            || (strcasecmp(mt->type, "personal") == 0) )
+      strcpy(pre, "700  $a");
+    else if (strcasecmp(mt->type, "corporate") == 0)
+      strcpy(pre, "710  $a");
+  }
+
+
+  else if (strcasecmp(mt->name, "coverage") == 0)
+  {
+    if (!*mt->type)
+      strcpy(pre, "500  $a");
+    else if (strcasecmp(mt->type , "spatial") == 0)
+      strcpy(pre, "255  $c");
+    else if (strcasecmp(mt->type,  "temporal") == 0)
+      strcpy(pre, "513  $b");
+  }
+
+
+  else if (strcasecmp(mt->name, "source") == 0)
+    strcpy(pre, "7860 $n");
+
+  else if (strcasecmp(mt->name, "rights") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "540  $a");
+    else if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(pre, "856  $3 rights $a");
+  }
+
+  else if (strcasecmp(mt->name, "identifier") == 0)
+
+/* Not supported: Indicator for urn! (See crosswalk)            */
+
+  {
+    if (!*mt->scheme)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "url") == 0)
+      strcpy(mr->url, mt->value);
+    else if (strcasecmp(mt->scheme, "urn") == 0)
+      strcpy(pre, "856  $u urn:");
+    else if (strcasecmp(mt->scheme, "isbn") == 0)
+      strcpy(pre, "020  $a");
+    else if (strcasecmp(mt->scheme, "issn") == 0)
+      strcpy(pre, "022  $a");
+    else
+      strcpy(pre, "0248 $a");
+  }
+
+  else if (strcasecmp(mt->name, "format") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(mr->fmat, mt->value);
+    else if (strcasecmp(mt->scheme, "imt") == 0)
+      strcpy(mr->fmat, mt->value);
+    else if (strcasecmp(mt->scheme, "mime") == 0)
+      strcpy(mr->fmat, mt->value);
+  }
+
+  else if (strcasecmp(mt->name, "subject") == 0)
+  {
+    if (!*mt->scheme)
+      strcpy(pre, "653  $a");
+    else if (strcasecmp(mt->scheme, "lcc") == 0)
+      strcpy(pre, "050  $a");
+    else if (strcasecmp(mt->scheme, "lcsh") == 0)
+      strcpy(pre, "650  $a");
+    else if (strcasecmp(mt->scheme, "ddc") == 0)
+      strcpy(pre, "082  $a");
+  }
+
+
+  else if (strcasecmp(mt->name, "language") == 0)
+  {
+    if (strcasecmp(mt->scheme, "z39.53") == 0)
+    {
+      if (strlen(mt->value) == 3)
+        put008(mr->s008, mt->value, F008_LANGUAGE);
+    }
+  }
+
+
+  else if (strcasecmp(mt->name, "date") == 0)
+  {
+    if ( (strncasecmp(mt->scheme, "ans", 3) == 0) ||
+         (strncasecmp(mt->scheme, "iso", 3) == 0) )
+    {
+      if ( (!*mt->type) || ( strcasecmp(mt->type, "current") == 0) )
+      {
+        if (find_year(mt->value))
+        {
+          strcpy(mr->year, mt->value);
+          put008(mr->s008, mt->value, F008_DATE1);
+        }
+      }
+    }
+  }
+
+  if (*pre)
+  {
+    strcat(mr->marcline, pre);
+    strcat(mr->marcline, " ");
+    strcat(mr->marcline, mt->value);
+    strcat(mr->marcline, "\n");
+  }
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/util.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/util.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/util.c	(revision 16571)
@@ -0,0 +1,472 @@
+/* ------------------------------------------------------------------- */
+/* util      : Several utilities for the d2m converter                 */
+/*                                                                     */
+/* Author    : Ole Husby                                               */
+/* Updated   : 1998-09-30                                              */
+/* ------------------------------------------------------------------- */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include "d2m.h"
+
+
+
+
+/* ------------------------------------------------------------------- */
+/* Produce MARC line-format output                                     */
+/* ------------------------------------------------------------------- */
+
+void write_field(char *l, FILE *of, int linel, int llen, int slen)
+{
+  char pre[64], line[256], *p, *q, *n;
+  int more, i, spos, compact, ctr;
+
+  ctr = 0;
+  *pre = *line = 0;
+  p = strdup(l);
+  q = p;
+
+  more = TRUE;
+  compact = FALSE;  
+
+  while (more)
+  {
+
+    ctr++;
+    if (ctr > 20) more = FALSE;
+
+    if (strlen(q) <= linel - 8)           /* String fits into 1 line  */
+    {
+      if (compact)
+      {
+        fprintf(of, "%s%s\n", pre, q);
+        more = FALSE;
+      }
+      else
+      {
+        n = strstr(q + 6, "$");
+
+        if ( (n - q ) > 5)
+        {
+          spos = (n - q);
+          strncat(line, q, spos);
+          q = n;
+          fprintf(of, "%s%s\n", pre, line);
+          strcpy(pre, "     ");
+          *line = 0;
+        }
+        else
+        {
+          fprintf(of, "%s%s\n", pre, q);
+          more = FALSE;
+        }
+      }
+    }
+
+    else                                  /* Look for splitting point */
+    {
+      spos = 0;
+
+      if (!compact)
+      {
+        for (i = 6; i < linel - 8; i++)
+        {
+          if (q[i] == '$')
+          {
+            spos = i + 1;
+            break;
+          }
+        } 
+      }
+
+ 
+      if (!spos)
+      {
+        for (i = linel - 9; i > slen; i--)
+        {
+          if ( !compact && (q[i] == '$'))
+          {
+            spos = i + 1;
+            break;
+          }
+          else if (q[i] == ' ')
+          {
+            spos = i;
+            break;
+          }
+        }
+      }
+
+      if (spos)
+      {
+         strncat(line, q, spos);
+         q +=  spos + 1;
+      }
+      else
+      {
+         strncat(line, q, llen);
+         strcat(line, "-");
+         q += llen;
+      }
+
+      fprintf(of, "%s%s\n", pre, line);
+      strcpy(pre, "     ");
+      *line = 0;
+    }
+  }
+  free(p);
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* Fetching HTTP POST data                                             */
+/* ------------------------------------------------------------------- */
+
+char *poq() 
+{
+    int m=0, c, cl;
+    char *rec;
+
+    if(strcmp(getenv("REQUEST_METHOD"),"POST"))
+      return NULL;
+
+    cl = atoi(getenv("CONTENT_LENGTH"));
+
+    if (cl)
+      rec = (char*) malloc(cl + 1);
+    else
+      return NULL;
+    
+    while (c = fgetc(stdin))
+    {
+      rec[m] = c;
+      m++;
+      if (m >= cl) break;
+    }
+
+    rec[m] = 0;
+
+    return rec;
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* ------------------------------------------------------------------- */
+
+int unesc (char h, char l)
+{
+   char buf[3];
+   int i;
+
+   buf[0]=h;
+   buf[1]=l;
+   buf[2]='\0';
+   sscanf(buf,"%x",&i);
+   return (i);
+}
+
+
+/* ------------------------------------------------------------------- */
+/* Replace '+' with space and unescape hex coded characters.           */
+/* ------------------------------------------------------------------- */
+
+void unescape (char *s)
+{
+   char *rp, *wp;  /* read position and write position in string */
+   rp=wp=s;
+   while (*rp != '\0') {
+      if (*rp=='+') {
+         *(wp++)=' ';
+         rp++;
+      }
+      else if (*rp=='%') {
+         int a,b;
+         rp++;   /* skip the '%' */
+         a = (unsigned char) *(rp++);
+         b = (unsigned char) *(rp++);
+         *(wp++)=unesc (a,b);
+      } else
+         *(wp++)=*(rp++);
+    }
+    *wp = '\0';
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* Case independent string search.                                     */
+/*                                                                     */
+/* Call syntax like strstr()                                           */
+/* ------------------------------------------------------------------- */
+
+char *cstr(char *h, char *n)
+{
+  char *nn;
+  char *hh;
+  char *p, *s;
+  long i;
+
+
+/* Returns NULL if either of strings are NULL                     */
+
+  if (!*h || !*n)
+    return (char *) NULL;
+
+
+/* Make a copy hh of h and nn of n                                */
+
+  hh = (char *) strdup(h);
+  nn = (char *) strdup(n);
+
+/* Converts hh and nn to lower                                    */
+
+  for (i = 0; i < strlen(nn); i++)
+    nn[i] = tolower(n[i]);
+
+  for (i = 0; i < strlen(hh); i++)
+    hh[i] = tolower(h[i]);
+
+/* Searches for nn in hh using strstr                             */
+
+  p = (char *) strstr(hh, nn);
+
+/* If found, calculates corresponding pointer into h              */
+
+  if (!p)
+    s = (char *) NULL;
+  else
+  {
+    i = strlen(hh) - strlen(p);
+    s = h + i;
+  }
+
+/* Frees string copies and returns                                */
+
+  free(hh);
+  free(nn);
+
+  return s; 
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* Write and remove tracefile                                          */
+/* ------------------------------------------------------------------- */
+
+int write_trace(char *tracefile, FILE *of)
+{
+  char line[10000], *l;
+  FILE *tf;
+
+  tf = fopen(tracefile, "r");
+  if (!tf)
+    return 0;
+
+  while (l = fgets(line, 9999, tf))
+    fprintf(of, "%s", l);
+
+  fclose(tf);
+  remove(tracefile);  
+  return 1;
+}
+
+
+/* ------------------------------------------------------------------- */
+/* Insert field into 008                                               */
+/* ------------------------------------------------------------------- */
+
+int put008(char *s8, char *str, int f8)
+{
+   int i, len, pos, nlen, npos, append=0;
+
+   if (strlen(s8) != 40)
+     return 0;
+
+   switch (f8)
+   {
+     case (F008_DATE_ENTERED) :
+     {
+       pos = 0;
+       len = 6;
+       break;
+     }
+     case (F008_TYPE_OF_DATE) :
+     {
+       pos = 6;
+       len = 1;
+       break;
+     }
+     case (F008_DATE1) :
+     {
+       pos = 7;
+       len = 4;
+       break;
+     }
+     case (F008_FORM_OF_PUBLICATION) :
+     {
+       pos = 24;
+       len = 4;
+       append = 1;
+       break;
+     }
+     case (F008_LANGUAGE) :
+     {
+       pos = 35;
+       len = 3;
+       break;
+     }
+     default :
+       return 0;
+   }
+
+
+   npos = pos;
+   nlen = strlen(str);
+   if (nlen > len)
+     return 0;
+
+   if (nlen < len)
+   {
+     if (append)
+     {
+       npos = 0;
+       for (i = pos; i < pos + len; i++)
+       {
+         if ( s8[i] == ' ' )
+         {
+           npos = i;
+           break; 
+         }
+       }
+       if (npos == 0)
+         return 0;
+       if (npos >= pos + len)
+         return 0;
+       if (npos + nlen > pos + len)
+         return 0;
+     }
+     else
+       return 0;
+   }
+/* printf
+     ("pos %d len %d npos %d nlen %d str %s\n", 
+     pos, len, npos, nlen, str);
+*/
+
+   for (i = 0; i < nlen; i++)
+     s8[npos+i] = str[i];
+
+   return 1;
+}
+
+
+/* ------------------------------------------------------------------- */
+/* Converts date to YYYY                                               */
+/* ------------------------------------------------------------------- */
+
+int find_year(char *str)
+{
+  int i;
+
+  if (strlen(str) < 4)
+    return 0;
+
+  str[4] = 0;
+
+  for (i = 0; i < 4; i++)
+  {
+    if (!isdigit(str[i]))
+      return 0;
+  }
+ 
+  return 1;
+}
+
+
+
+
+/* ------------------------------------------------------------------- */
+/* Splits personal name at first "," into $a and $h                    */
+/* ------------------------------------------------------------------- */
+
+int split_name(char *str)
+{
+  char *p, *q, subtag[5];
+
+  if (!strstr(str, ","))
+    return 1;
+
+  p = (char *) malloc(strlen(str) + 50);
+  *p = 0;
+  *subtag = 0;
+
+  q = strtok(str, ",");
+  if (q)
+  {
+    strcpy(p, q);
+    q = strtok(NULL, "\0");
+    if (q)
+    {
+      while ( ( q[0] == ' ' ) && ( strlen(q) ) )
+        q++;
+      strcat(p, " $h ");
+      strcat(p, q);
+    }
+    strcpy(str, p);
+  }
+
+  free(p);
+
+  return 1;
+}
+
+
+
+/* ------------------------------------------------------------------- */
+/* Splits subject heading on "-". First occurence go into $a, second   */ 
+/* into $b, all the rest into $x                                       */
+/* ------------------------------------------------------------------- */
+
+int split_subj(char *str)
+{
+  char *p, *q, subtag[5];
+
+  if (!strstr(str, "-"))
+    return 1;
+
+  p = (char *) malloc(strlen(str) + 50);
+  *p = 0;
+  *subtag = 0;
+
+  q = strtok(str, "-");
+  while (q)
+  {
+    while ( ( q[0] == ' ' ) && ( strlen(q) ) )
+      q++;
+
+    while( ( q[strlen(q) - 1] == ' ' ) && ( strlen(q) ) )
+      q[strlen(q) - 1] = '\0';
+
+    if (*q)
+    {
+      strcat(p, subtag);
+      strcat(p, q);
+      if (!*subtag)
+        strcpy(subtag, " $b ");
+      else
+        strcpy(subtag, " $x ");
+    }
+    q = strtok(NULL, "-");
+  }
+
+  strcpy(str, p);
+  free(p);
+
+  return 1;
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/wfetch-l.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/wfetch-l.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/wfetch-l.c	(revision 16571)
@@ -0,0 +1,19 @@
+/* ------------------------------------------------------------------- */
+/* wfetch    : Fetch a remote file using the htget() "HTTP client"     */
+/*                                                                     */
+/* syntax    : wfatch(char *url, char *filename)                       */
+/*                                                                     */
+/* Returns   : 0 ALWAYS!                                               */
+/*                                                                     */
+/* Author    : Ole Husby, BIBSYS                                       */
+/* Updated   : 1998-10-04                                              */
+/* ------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+int wfetch(char *url, char *filename)
+{
+  return 0;
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/wfetch.c
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/wfetch.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/wfetch.c	(revision 16571)
@@ -0,0 +1,53 @@
+/* ------------------------------------------------------------------- */
+/* wfetch    : Fetch a remote file using the htget() "HTTP client"     */
+/*                                                                     */
+/* syntax    : wfatch(char *url, char *filename)                       */
+/*                                                                     */
+/*             The file will be written to "filename"                  */
+/*                                                                     */
+/* Returns   : 0 if fail                                               */
+/*           : 1 if HTML file (text/html)                              */
+/*           : 2 if MARC file (application/marc)                       */
+/*                                                                     */
+/* NOTE      : Timeout period (HTTP) is set here.                      */
+/*                                                                     */
+/* Author    : Ole Husby, BIBSYS                                       */
+/* Updated   : 1998-08-11                                              */
+/* ------------------------------------------------------------------- */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define  TIMEOUT_SECONDS       10
+
+int wfetch(char *url, char *filename)
+{
+  int i, type, argtype, timeout, rc, retc;
+  char iurl[1024], content_type[128], location[128];
+
+  retc = 1;
+
+  strcpy(iurl, url);
+  timeout = TIMEOUT_SECONDS;
+
+  type = 6;                           /* Fetch HTML HEAD or MARC      */
+
+  rc = htget(iurl, type, timeout, filename, content_type, location);
+
+
+/* Try again if redirect                                              */
+
+  if ( ( ( rc == 301 ) || ( rc == 302 ) ) && *location )
+  {
+    strcpy(iurl, location);
+    rc = htget(iurl, type, timeout, filename, content_type, location);
+  }
+
+  if (rc)
+    retc = 0;
+  else if (strcmp(content_type, "application/marc") == 0)
+    retc = 2;
+
+  return retc;
+}
Index: /gsdl/trunk/runtime-src/packages/d2m/win32.mak
===================================================================
--- /gsdl/trunk/runtime-src/packages/d2m/win32.mak	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/d2m/win32.mak	(revision 16571)
@@ -0,0 +1,51 @@
+# ///////////////// d2m : Dublin Core to MARC converter /////////////////////
+#
+#
+# Generated for Greenstone kjdon May 2005.
+# Used by z3950server
+
+GSDLHOME = ..\..
+GSDL_VC4 = 0
+CC = cl
+AR = lib
+
+DLL = 0
+DLLDEBUG = 0
+
+!IF $(GSDL_VC4)
+CPPFLAGS = -GX
+!ELSE
+CPPFLAGS = -EHsc
+!ENDIF
+
+!IF $(DLL)
+CPPFLAGS = $(CPPFLAGS) -MD 
+!ELSE
+!IF ($(DLLDEBUG))
+CPPFLAGS = $(CPPFLAGS) -MDd
+!ENDIF
+!ENDIF
+
+o = .obj
+
+DEFS=-DHAVE_CONFIG_H -D__WIN32__ -D_CRT_SECURE_NO_DEPRECATE
+INCLUDES= -I"$(GSDLHOME)"
+COMPILE = $(CC) -nologo -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+
+LIB_OBJS = MARC2709$o MARCtidy$o usMARC$o util$o strcasecmp$o
+
+all: libd2m.lib
+
+libd2m.lib: $(LIB_OBJS)
+	if EXIST libd2m.lib del libd2m.lib
+	$(AR) -nologo /out:libd2m.lib $(LIB_OBJS)
+
+install:
+
+clean:
+	del *$o 
+	del libd2m.lib
+
+distclean: clean
+	rm -f Makefile config.h
+
Index: /gsdl/trunk/runtime-src/packages/yaz/GSDL_USAGE.html
===================================================================
--- /gsdl/trunk/runtime-src/packages/yaz/GSDL_USAGE.html	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/yaz/GSDL_USAGE.html	(revision 16571)
@@ -0,0 +1,124 @@
+<html>
+<head>
+<title>Using the Z39.50 Client in Greenstone</title>
+</head>
+
+<body>
+<a name=top>
+<h1>Using the Z39.50 Client in Greenstone</h1>
+</a>
+<b>Table of Contents</b><br>
+<a href="#whatis">About: What is Z39.50?</a><br>
+<a href="#config">Configuring Greenstone - Adding Servers</a><br>
+<a href="#todo">Currently known problems, and TODO list</a><br>
+<a href="#contact">Contacting Us</a><br>
+
+
+
+<a name=whatis>
+<h2>What is Z39.50?</h2>
+</a>
+Z39.50 is an international client/server protocol for searching bibliographic
+data. It can use the Internet Protocol (TCP/IP), which makes the databases
+on a server available from almost anywhere around the globe. It is widely
+used, for example, in on-line library catalogues. It allows a user to search
+one or more databases and retrieve the results of the query.
+
+<p>
+Our implementation uses the YAZ z39.50 toolkit, written by
+<a href="http://www.indexdata.dk">Index Data</a>.
+
+
+
+<a name=config>
+<h2>Adding Servers</h2>
+</a>
+The file z3950.cfg in the etc/packages directory contains entries for
+each server. By default, no servers are set up, although the config file
+comes with two (commented out) example Z39.50 servers, both for servers
+of the United States' <b>Library of Congress</b>.
+<p>
+Each entry consists of:
+<ul>
+<li>A unique "short name" for internal use by Greenstone.</li>
+<li>The internet name or address of the server, and optionally the
+port that the server is running on if not the default port 210.</li>
+<li>The name of the database to search on that server.</li>
+<li>A string that provides a meaningful name for the "collection".</li>
+<li>An optional "About" string, providing some information about the database
+and/or server.</li>
+<li>Optional icon fields, which are displayed instead of the text on the
+front page.</li>
+</ul>
+The entries need only be separated by whitespace, but for the purposes of
+clarity the sample entry uses newlines and tabs.
+<p>
+The sample Library of Congress entry looks like this:
+<pre>
+LOC
+        z3950.loc.gov:7090
+        Voyager
+        "Library of Congress z39.50 server"
+        About  en  "This is the z39.50 interface to the US LoC catalogue
+           system. It contains approximately 12 million bibliographic records.
+           For server capabilities, look at
+	   &lt;a href=\"http://lcweb.loc.gov/z3950/lcserver.html\"&gt;their web pages&lt;/a&gt;."
+</pre>
+There is a list at the Library Of Congress website containing some 
+<a href="http://lcweb.loc.gov/z3950/agency/resources/testport.html">servers 
+publicly available for testing</a>.
+
+
+<a name=todo>
+<h2>Known Problems/Issues list</h2>
+</a>
+<ul>
+<li>Because of the open nature of the standard, our client may not work with
+some servers. Please notify the author (contact details below) of any
+such problems.</li>
+<li>Because of the large number of Marc fields, only the most frequently
+used fields have been given explicit names in the results. Furthermore,
+these are currently hard-coded to correspond to the USMARC field names.</li>
+<li><b>The z39.50 client will not work when fast-cgi is used!</b>. Currently,
+the use of the fast-cgi package (off by default) will disable the
+use of the z39.50 client code for Greenstone.</li>
+<li>There are spurious &lt;B&gt; tags in the title of the window when
+viewing an individual record.</li>
+<li>Greenstone will claim there are no collections if there are no
+sub-directories in the "collect" directory, even if there are configured
+z39.50 servers, although it will work if there are unbuilt collections.</li>
+</ul>
+
+<b>History</b><br>
+Jul 2001 - finally tracked down and fixed an annoying bug that caused
+greenstone to segfault when retrieving documents for some queries.<br>
+Jun 2001 - decided to drop href for field 856, as some examples have 
+explanatory text in the field as well as the URI.<br>
+Oct 2000 - cache results from server, so cut down the number of connections for
+a single query/document. Also added href for MARC field 856.<br>
+Aug 2000 - Various bug fixes and minor modifications.<br>
+Fri Aug 4 2000 - The z39.50 code is now "stable" in the main source code (in CVS).<br>
+Tue 1 Aug 2000 - selecting a field from the drop-down box now actually works. 
+This results in both quicker replies and more accurate results.<br>
+Mon 24 Jul 2000 - queries are now "AND"ed - for example, the query "computer 
+science" will now only return records that contain both words.<br>
+May-June 2000 - Code written.<br>
+
+<a name=contact>
+<h2>Contact Details</h2>
+</a>
+For general comments about Greenstone, or suggestions for improvements, send
+email to
+<a href="mailto:greenstone@cs.waikato.ac.nz?subject=z39.50 client in Greenstone">greenstone@cs.waikato.ac.nz</a><br>
+<br>
+For bug reports or questions about the z39.50 code itself, send email to
+the author, John McPherson -
+<a href="mailto:jrm21@cs.waikato.ac.nz?subject=z39.50 client in Greenstone"
+>jrm21@cs.waikato.ac.nz</a>.
+
+<p>
+<a href="#top">Back to top</a>
+<p>
+<address>Last modified: July 12, 2001 by John McPherson</address>
+</body>
+</html>
Index: /gsdl/trunk/runtime-src/packages/yaz/README.gsdl
===================================================================
--- /gsdl/trunk/runtime-src/packages/yaz/README.gsdl	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/yaz/README.gsdl	(revision 16571)
@@ -0,0 +1,24 @@
+The YAZ toolkit is used by the GSDL receptionist
+when acting as a z39.50 client.
+
+June 2005, kjdon:
+Changed to use yaz version 2.1.4. This is also used by the new z3950server.
+The original yaz download has been added to cvs - this is unzipped and untared by the configure script, then only the src and client directories are compiled.
+Greenstone uses the libyaz.a library. yaz_zclient.o is modified from the sample client.o, and now lives in the colservr directory.
+
+Two files are linked against: 
+ client/yaz_client.o, which was modified from Index Data's sample 
+	client code, and
+
+ lib/libyaz.a, which contains all the z39.50 and MARC formatting code.
+	There is probably a lot of stuff in this library that does
+	not need to be there for our purposes, but for now it is,
+	merely wasting some disk space and some compile-time CPU.
+
+John McPherson
+3 August 2000
+
+yaz version 1.6
+
+September 2000:
+removed "ill" "server" "ztest" and "retrieval" subdirs.
Index: /gsdl/trunk/runtime-src/packages/yaz/config.status
===================================================================
--- /gsdl/trunk/runtime-src/packages/yaz/config.status	(revision 16571)
+++ /gsdl/trunk/runtime-src/packages/yaz/config.status	(revision 16571)
@@ -0,0 +1,159 @@
+#! /bin/sh
+# Generated automatically by configure.
+# Run this file to recreate the current configuration.
+# This directory was configured as follows,
+# on host ickenham.mdx.ac.uk:
+#
+# ./configure  --cache-file=/home/George/corbanormal/gsdl/config.cache
+#
+# Compiler output produced by configure, useful for debugging
+# configure, is in ./config.log if it exists.
+
+ac_cs_usage="Usage: ./config.status [--recheck] [--version] [--help]"
+for ac_option
+do
+  case "$ac_option" in
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    echo "running ${CONFIG_SHELL-/bin/sh} ./configure  --cache-file=/home/George/corbanormal/gsdl/config.cache --no-create --no-recursion"
+    exec ${CONFIG_SHELL-/bin/sh} ./configure  --cache-file=/home/George/corbanormal/gsdl/config.cache --no-create --no-recursion ;;
+  -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
+    echo "./config.status generated by autoconf version 2.13"
+    exit 0 ;;
+  -help | --help | --hel | --he | --h)
+    echo "$ac_cs_usage"; exit 0 ;;
+  *) echo "$ac_cs_usage"; exit 1 ;;
+  esac
+done
+
+ac_given_srcdir=.
+
+trap 'rm -fr Makefile util/Makefile odr/Makefile z39.50/Makefile asn/Makefile zutil/Makefile comstack/Makefile ccl/Makefile tab/Makefile include/Makefile include/yaz/Makefile lib/Makefile client/Makefile doc/Makefile conftest*; exit 1' 1 2 15
+
+# Protect against being on the right side of a sed subst in config.status.
+sed 's/%@/@@/; s/@%/@@/; s/%g$/@g/; /@g$/s/[\\&%]/\\&/g;
+ s/@@/%@/; s/@@/@%/; s/@g$/%g/' > conftest.subs <<\CEOF
+/^[ 	]*VPATH[ 	]*=[^:]*$/d
+
+s%@SHELL@%/bin/sh%g
+s%@CFLAGS@%-g -O2%g
+s%@CPPFLAGS@%%g
+s%@CXXFLAGS@%%g
+s%@FFLAGS@%%g
+s%@DEFS@% -DHAVE_READLINE_READLINE_H=1 -DHAVE_READLINE_HISTORY_H=1 -DSTDC_HEADERS=1 %g
+s%@LDFLAGS@%%g
+s%@LIBS@% -lreadline -lhistory%g
+s%@exec_prefix@%${prefix}%g
+s%@prefix@%/usr/local%g
+s%@program_transform_name@%s,x,x,%g
+s%@bindir@%${exec_prefix}/bin%g
+s%@sbindir@%${exec_prefix}/sbin%g
+s%@libexecdir@%${exec_prefix}/libexec%g
+s%@datadir@%${prefix}/share%g
+s%@sysconfdir@%${prefix}/etc%g
+s%@sharedstatedir@%${prefix}/com%g
+s%@localstatedir@%${prefix}/var%g
+s%@libdir@%${exec_prefix}/lib%g
+s%@includedir@%${prefix}/include%g
+s%@oldincludedir@%/usr/include%g
+s%@infodir@%${prefix}/info%g
+s%@mandir@%${prefix}/man%g
+s%@CC@%gcc%g
+s%@CPP@%gcc -E%g
+s%@RANLIB@%ranlib%g
+s%@have_sgml2txt@%no%g
+s%@have_sgml2latex@%no%g
+s%@have_sgml2html@%no%g
+s%@ASNMODULE@%z39.50%g
+s%@ILLMODULE@%ill%g
+s%@ILLLIB@%../ill/libill.a%g
+s%@SUBDIRS_VAR@%util odr z39.50 zutil comstack ccl tab include lib client %g
+
+CEOF
+
+# Split the substitutions into bite-sized pieces for seds with
+# small command number limits, like on Digital OSF/1 and HP-UX.
+ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script.
+ac_file=1 # Number of current file.
+ac_beg=1 # First line for current file.
+ac_end=$ac_max_sed_cmds # Line after last line for current file.
+ac_more_lines=:
+ac_sed_cmds=""
+while $ac_more_lines; do
+  if test $ac_beg -gt 1; then
+    sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file
+  else
+    sed "${ac_end}q" conftest.subs > conftest.s$ac_file
+  fi
+  if test ! -s conftest.s$ac_file; then
+    ac_more_lines=false
+    rm -f conftest.s$ac_file
+  else
+    if test -z "$ac_sed_cmds"; then
+      ac_sed_cmds="sed -f conftest.s$ac_file"
+    else
+      ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file"
+    fi
+    ac_file=`expr $ac_file + 1`
+    ac_beg=$ac_end
+    ac_end=`expr $ac_end + $ac_max_sed_cmds`
+  fi
+done
+if test -z "$ac_sed_cmds"; then
+  ac_sed_cmds=cat
+fi
+
+CONFIG_FILES=${CONFIG_FILES-"Makefile util/Makefile odr/Makefile z39.50/Makefile asn/Makefile zutil/Makefile comstack/Makefile ccl/Makefile tab/Makefile include/Makefile include/yaz/Makefile lib/Makefile client/Makefile doc/Makefile"}
+for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case "$ac_file" in
+  *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'`
+       ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;;
+  *) ac_file_in="${ac_file}.in" ;;
+  esac
+
+  # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories.
+
+  # Remove last slash and all that follows it.  Not all systems have dirname.
+  ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'`
+  if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then
+    # The file is in a subdirectory.
+    test ! -d "$ac_dir" && mkdir "$ac_dir"
+    ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`"
+    # A "../" for each directory in $ac_dir_suffix.
+    ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'`
+  else
+    ac_dir_suffix= ac_dots=
+  fi
+
+  case "$ac_given_srcdir" in
+  .)  srcdir=.
+      if test -z "$ac_dots"; then top_srcdir=.
+      else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;;
+  /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;;
+  *) # Relative path.
+    srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix"
+    top_srcdir="$ac_dots$ac_given_srcdir" ;;
+  esac
+
+
+  echo creating "$ac_file"
+  rm -f "$ac_file"
+  configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure."
+  case "$ac_file" in
+  *Makefile*) ac_comsub="1i\\
+# $configure_input" ;;
+  *) ac_comsub= ;;
+  esac
+
+  ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"`
+  sed -e "$ac_comsub
+s%@configure_input@%$configure_input%g
+s%@srcdir@%$srcdir%g
+s%@top_srcdir@%$top_srcdir%g
+" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file
+fi; done
+rm -f conftest.s*
+
+
+
+exit 0
Index: /gsdl/trunk/runtime-src/src/colservr/Makefile.in
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/Makefile.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/Makefile.in	(revision 16571)
@@ -0,0 +1,148 @@
+###########################################################################
+#
+# Makefile -- src/colservr
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ../../..
+COMMON_DIR = $(GSDL_DIR)/gs2common
+
+INDEXERS_DIR = $(COMMON_DIR)/indexers
+PACKAGES_DIR = $(GSDL_DIR)/gs2runtime/packages
+
+
+USE_SQLITE = @USE_SQLITE@
+ifeq ($(USE_SQLITE), 1)
+SQLITE_DEFINES = -DUSE_SQLITE
+SQLITE_INCLUDES = -I$(PACKAGES_DIR)/sqlite/include
+else
+SQLITE_DEFINES = 
+SQLITE_INCLUDES = 
+endif
+
+
+AR = ar
+CC = @CC@
+CXX = @CXX@
+CFLAGS = @CFLAGS@ @COMPAT32BITFLAGS@
+CXXFLAGS = @CXXFLAGS@ @COMPAT32BITFLAGS@
+DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DGSDLSERVER $(SQLITE_DEFINES)
+# Do NOT add the "recpt" directory here: the colserver should be independent of the receptionist!
+INCLUDES = @GDBM_INCLUDE@ -I. -I$(GSDL_DIR) -I$(COMMON_DIR)/src/lib \
+	-I$(INDEXERS_DIR)/mg -I$(INDEXERS_DIR)/mg/lib -I$(INDEXERS_DIR)/mg/src/text \
+	-I$(INDEXERS_DIR)/mgpp/lib -I$(INDEXERS_DIR)/mgpp/text \
+	-I$(PACKAGES_DIR)/expat/include $(SQLITE_INCLUDES)
+RANLIB = @RANLIB@
+
+
+COMPILE = $(CC) -c $(CFLAGS) $(DEFS) $(INCLUDES)
+CXXCOMPILE = $(CXX) -c $(CXXFLAGS) $(DEFS) $(INCLUDES)
+
+
+.SUFFIXES:
+.SUFFIXES: .c .o
+.c.o:
+	$(COMPILE) $<
+
+.SUFFIXES: .cpp .o
+.cpp.o:
+	$(CXXCOMPILE) $< 
+
+
+SOURCES = \
+        browsefilter.cpp \
+	collectserver.cpp \
+	collectset.cpp \
+        colservrconfig.cpp \
+	comtypes.cpp \
+	expat_document.cpp \
+	expat_resultset.cpp \
+	filter.cpp \
+	lucenequeryfilter.cpp \
+	lucenesearch.cpp \
+	lucenesource.cpp \
+	maptools.cpp \
+	mgq.c \
+	mgqueryfilter.cpp \
+	mgsearch.cpp \
+	mgsource.cpp \
+	mgppqueryfilter.cpp \
+	mgppsearch.cpp \
+	phrasequeryfilter.cpp \
+	phrasesearch.cpp \
+	querycache.cpp \
+	queryfilter.cpp \
+	queryinfo.cpp \
+	search.cpp \
+	source.cpp \
+	sqlbrowsefilter.cpp
+
+OBJECTS = \
+        browsefilter.o \
+	collectserver.o \
+	collectset.o \
+        colservrconfig.o \
+	comtypes.o \
+	expat_document.o \
+	expat_resultset.o \
+	filter.o \
+	lucenequeryfilter.o \
+	lucenesearch.o \
+	lucenesource.o \
+	maptools.o \
+	mgq.o \
+	mgqueryfilter.o \
+	mgsearch.o \
+	mgsource.o \
+	mgppqueryfilter.o \
+	mgppsearch.o \
+	phrasequeryfilter.o \
+	phrasesearch.o \
+	querycache.o \
+	queryfilter.o \
+	queryinfo.o \
+	search.o \
+	source.o \
+	sqlbrowsefilter.o
+
+LIBRARY = gsdlcolservr.a
+
+
+# Default target: make gsdlcolservr.a
+all: $(LIBRARY)
+
+gsdlcolservr.a: $(OBJECTS)
+	rm -f $(LIBRARY)
+	$(AR) cru $(LIBRARY) $(OBJECTS)
+	$(RANLIB) $(LIBRARY)
+
+install:
+
+clean:
+	rm -f $(OBJECTS) $(LIBRARY)
+
+distclean:
+	rm -f $(OBJECTS) $(LIBRARY) Makefile
+
+depend:
+	makedepend -Y -- $(DEFS) $(INCLUDES) $(CXXFLAGS) -- $(SOURCES)
Index: /gsdl/trunk/runtime-src/src/colservr/browsefilter.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/browsefilter.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/browsefilter.cpp	(revision 16571)
@@ -0,0 +1,309 @@
+/**********************************************************************
+ *
+ * browsefilter.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "browsefilter.h"
+#include "fileutil.h"
+
+
+browsefilterclass::browsefilterclass () {
+  db_ptr = NULL;
+
+  // -- onePerQuery StartResults   integer
+  FilterOption_t filtopt;
+  filtopt.name = "StartResults";
+  filtopt.type = FilterOption_t::integert;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "1";
+  filtopt.validValues.push_back("1");
+  filtopt.validValues.push_back("10000");
+  filterOptions["StartResults"] = filtopt;
+
+  // -- onePerQuery EndResults     integer
+  filtopt.clear();
+  filtopt.name = "EndResults";
+  filtopt.type = FilterOption_t::integert;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "-1";
+  filtopt.validValues.push_back("-1");
+  filtopt.validValues.push_back("10000");
+  filterOptions["EndResults"] = filtopt;
+
+  // -- onePerQuery ParentNode     string ("" will return the browsing available)
+  filtopt.clear();
+  filtopt.name = "ParentNode";
+  filtopt.type = FilterOption_t::stringt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = g_EmptyText;
+  filterOptions["ParentNode"] = filtopt;
+}
+
+browsefilterclass::~browsefilterclass () {
+}
+
+void browsefilterclass::configure (const text_t &key, const text_tarray &cfgline) {
+  filterclass::configure (key, cfgline);
+  if (key == "indexstem") {
+    indexstem = cfgline[0];
+  }
+}
+
+bool browsefilterclass::init (ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  if (!filterclass::init(logout)) return false;
+
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: browsefilter contains a null dbclass\n\n";
+    return false;
+  }
+
+  if (indexstem.empty()) {
+    indexstem = collection;
+  }
+
+  db_filename = resolve_db_filename(indexstem,db_ptr->getfileextension());
+  if (!file_exists(db_filename)) {
+    logout << text_t2ascii
+	   << "warning: database \"" << db_filename << "\" does not exist\n\n";
+    //    return false;
+  }
+
+  return true;
+}
+
+void browsefilterclass::filter (const FilterRequest_t &request,
+				FilterResponse_t &response,
+				comerror_t &err, ostream &logout) {
+  int numDocs = 0;
+  outconvertclass text_t2ascii;
+
+  response.clear ();
+  err = noError;
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: browsefilter contains a null dbclass\n\n";
+    err = configurationError;
+    return;
+  }
+
+  // open the database
+  db_ptr->setlogout(&logout);
+  if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {
+    // most likely a system problem (we have already checked that the database exists)
+    logout << text_t2ascii
+	   << "system problem: open on database \""
+	   << db_filename << "\" failed\n\n";
+    err = systemProblem;
+    return;
+  }
+
+  // get the browse parameters
+  int startresults = filterOptions["StartResults"].defaultValue.getint();
+  int endresults = filterOptions["EndResults"].defaultValue.getint();
+  text_t parentnode = filterOptions["ParentNode"].defaultValue;
+  OptionValue_tarray::const_iterator options_here = request.filterOptions.begin();
+  OptionValue_tarray::const_iterator options_end = request.filterOptions.end();
+  while (options_here != options_end) {
+    if ((*options_here).name == "StartResults") 
+      startresults = (*options_here).value.getint();
+    else if ((*options_here).name == "EndResults")
+      endresults = (*options_here).value.getint();
+    else if ((*options_here).name == "ParentNode")
+      parentnode = (*options_here).value;
+    else {
+      logout << text_t2ascii
+	     << "warning: unknown browsefilter option \""
+	     << (*options_here).name
+	     << "\" ignored.\n\n";
+    }
+
+    ++options_here;
+  }
+
+  infodbclass info;
+
+  // translate any ".fc", ".pr" etc. stuff in the parentnode
+  parentnode = db_ptr->translate_OID (parentnode, info);
+
+  // adjust topmost browsing node
+  if (parentnode.empty()) parentnode = "browse";
+
+  // get the node
+  if ((request.filterResultOptions & FROID) ||
+      (request.filterResultOptions & FRmetadata)) {
+    if (!db_ptr->getinfo(parentnode, info)) {
+      // didn't find the node
+      logout << text_t2ascii
+	     << "warning: lookup for node \"" << parentnode 
+	     << "\" failed for browsefilter.\n\n";
+    } else {
+      // found the node
+
+      // replace " with the parent node name and split the contains string
+      // into the result set
+      text_tarray resultset;
+      text_t tmptext;
+      text_t &contains = info["contains"];
+      text_t::iterator contains_here = contains.begin();
+      text_t::iterator contains_end = contains.end();
+      while (contains_here != contains_end) {
+	if (*contains_here == '"') tmptext += parentnode;
+	else if (*contains_here == ';') {
+	  if (!tmptext.empty()) resultset.push_back (tmptext);
+	  tmptext.clear();
+	} else tmptext.push_back(*contains_here);
+	
+	++contains_here;
+      }
+      // insert the last result in the set
+      if (!tmptext.empty()) resultset.push_back (tmptext);
+
+      text_tarray offset_resultset;
+      text_t &md_type = info["mdtype"];
+      if (!md_type.empty())
+	{
+	  text_t &md_offset = info["mdoffset"];
+	  if (!md_offset.empty())
+	    {
+	      text_t offsettext;
+
+	      text_t::iterator offset_here = md_offset.begin();
+	      text_t::iterator offset_end = md_offset.end();
+	      while (offset_here != offset_end) 
+		{
+		  if (*offset_here == ';')
+		    {
+		      if (offsettext.empty())
+			{
+			  offset_resultset.push_back ("0");
+			}
+		      else
+			{
+			  offset_resultset.push_back (offsettext);
+			}
+		      offsettext.clear();
+		    } 
+		  else 
+		    {
+		      offsettext.push_back(*offset_here);
+		    }
+		  
+		  ++offset_here;
+		}
+	      // insert the last result in the set
+	      if (offsettext.empty())
+		{
+		  offset_resultset.push_back ("0");
+		}
+	      else
+		{
+		  offset_resultset.push_back (offsettext);
+		}
+	    }
+	  else
+	    {
+	      // add 0 offset for each 'contains' entry
+	      text_tarray::iterator result_here = resultset.begin();
+	      text_tarray::iterator result_end = resultset.end();
+	      while (result_here != result_end) {
+		offset_resultset.push_back("0");
+		++result_here;
+	      }
+	    }
+
+	  // do an intersection with the input set
+	  if (!request.docSet.empty()) {
+
+	    text_tarray intersect_resultset;
+	    text_tarray intersect_offset_resultset;
+	    
+	    text_tarray::const_iterator resultset_here = resultset.begin();
+	    text_tarray::const_iterator resultset_end = resultset.end();
+	    text_tarray::const_iterator offset_resultset_here = offset_resultset.begin();
+	    
+	    while (resultset_here != resultset_end) {
+	      if (in_set (request.docSet, *resultset_here))
+		{
+		  intersect_resultset.push_back (*resultset_here);
+		  intersect_offset_resultset.push_back (*offset_resultset_here);
+		}
+	      ++resultset_here;
+	      ++offset_resultset_here;
+	    }
+	    resultset = intersect_resultset;
+	    offset_resultset = intersect_offset_resultset;
+	  }
+	}
+      else
+	{
+	  // do an intersection with the input set
+	  if (!request.docSet.empty()) {
+	    intersect (resultset, request.docSet);
+	  }
+
+	  // add 0 offset for each 'contains' entry
+	  text_tarray::iterator result_here = resultset.begin();
+	  text_tarray::iterator result_end = resultset.end();
+	  while (result_here != result_end) {
+	    offset_resultset.push_back("0");
+	    ++result_here;
+	  }
+	}
+
+      // create the response
+      numDocs = resultset.size();
+      int resultnum = 1;
+      ResultDocInfo_t resultdoc;
+      text_tarray::iterator result_here = resultset.begin();
+      text_tarray::iterator result_end = resultset.end();
+      text_tarray::iterator offset_result_here = offset_resultset.begin();
+
+      while (result_here != result_end) {
+	// if endresults is -1 get all results
+	if ((endresults != -1) && (resultnum > endresults)) break;
+	if (resultnum >= startresults) {
+	  resultdoc.OID = (*result_here);
+	  if (!md_type.empty())
+	    {
+	      resultdoc.classifier_metadata_type = md_type;
+	      resultdoc.classifier_metadata_offset = offset_result_here->getint();
+	    }
+	  response.docInfo.push_back(resultdoc);
+	}
+
+	++resultnum;
+	++result_here;
+	if (!md_type.empty()) ++offset_result_here;
+      }
+    }
+  }
+
+  db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+  response.numDocs = numDocs;
+  response.isApprox = Exact;
+}
Index: /gsdl/trunk/runtime-src/src/colservr/browsefilter.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/browsefilter.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/browsefilter.h	(revision 16571)
@@ -0,0 +1,64 @@
+/**********************************************************************
+ *
+ * browsefilter.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef BROWSEFILTER_H
+#define BROWSEFILTER_H
+
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "comtypes.h"
+#include "filter.h"
+#include "dbclass.h"
+
+
+class browsefilterclass : public filterclass {
+protected:
+  text_t db_filename;
+  text_t indexstem;
+  dbclass *db_ptr;
+
+public:
+  browsefilterclass ();
+  virtual ~browsefilterclass ();
+
+  // configure should be called once for each configuration line
+  // default configures the default filter options
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+
+  // the db ptr remains the responsability of the calling code and
+  // should be destroyed after this browsefilter is destroyed
+  void set_db_ptr (dbclass *db_ptr_arg) { db_ptr = db_ptr_arg; }
+
+  bool init (ostream &logout);
+  text_t get_filter_name () {return "BrowseFilter";}
+  void filter (const FilterRequest_t &request,
+	       FilterResponse_t &response,
+	       comerror_t &err, ostream &logout);
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/collectserver.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/collectserver.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/collectserver.cpp	(revision 16571)
@@ -0,0 +1,538 @@
+
+/**********************************************************************
+ *
+ * collectserver.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "collectserver.h"
+#include "OIDtools.h"
+#include <assert.h>
+#include "display.h"
+
+
+collectserver::collectserver () {
+  configinfo.collection = "null";
+}
+
+collectserver::~collectserver () {
+
+  // clean up the sources
+  sourcelistclass::iterator source_here = sources.begin();
+  sourcelistclass::iterator source_end = sources.end();
+  while (source_here != source_end) {
+    if ((*source_here).s != NULL)
+      delete (*source_here).s;
+    ++source_here;
+  }
+  sources.clear();
+
+  // clean up the filters
+  filtermapclass::iterator filter_here = filters.begin();
+  filtermapclass::iterator filter_end = filters.end();
+  while (filter_here != filter_end) {
+    if ((*filter_here).second.f != NULL) 
+      delete (*filter_here).second.f;
+    ++filter_here;
+  }
+  filters.clear();
+}
+
+// configure should be called for each line in the
+// configuration files to configure the collection server and everything
+// it contains. The configuration should take place just before initialisationhttps://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%3Fui%3Dhtml%26zy%3Dl&ltmpl=ca_tlsosm_video&ltmplcache=2&hl=en.
+void collectserver::configure (const text_t &key, const text_tarray &cfgline) {
+  if (cfgline.size() >= 1) {
+    const text_t &value = cfgline[0];
+    if (key == "plugin")
+    {
+    	//get the plugin name
+	const text_t &name = cfgline[0];
+	
+	if (name == "HTMLPlug")
+	{
+		for (int hI = 1; hI < cfgline.size(); hI++)
+		{
+			const text_t &plugOption = cfgline[hI];
+			
+			if (plugOption == "-tidy_html") 
+			{
+				collectinfo.useBook = true;
+				break;
+			}
+		}
+	}
+    }
+    else if (key == "gsdlhome") configinfo.gsdlhome = value;
+    else if (key == "gdbmhome") configinfo.dbhome = value;
+    else if (key == "collecthome") configinfo.collecthome = value;
+    else if (key == "collection") {
+      configinfo.collection = value;
+      collectinfo.shortInfo.name = value;
+    } 
+    else if (key == "collectdir") configinfo.collectdir = value;
+    else if (key == "host") collectinfo.shortInfo.host = value;
+    else if (key == "port") collectinfo.shortInfo.port = value.getint();
+    else if (key == "public") {
+      if (value == "true") collectinfo.isPublic = true;
+      else collectinfo.isPublic = false;
+    } else if (key == "beta") {
+      if (value == "true") collectinfo.isBeta = true;
+      else collectinfo.isBeta = false;
+    } else if (key == "collectgroup") {
+      if (value == "true") collectinfo.isCollectGroup = true;
+      else collectinfo.isCollectGroup = false;
+    } else if ((key == "ccscols") || (key == "supercollection")) collectinfo.ccsCols = cfgline;
+    else if (key == "supercollectionoptions") {
+      text_tarray::const_iterator begin = cfgline.begin();
+      text_tarray::const_iterator end = cfgline.end();
+      while(begin != end) {
+	
+	if (*begin == "uniform_search_results_formatting") {
+	  collectinfo.ccsOptions |= CCSUniformSearchResultsFormatting;
+	}
+	begin++;
+      }
+    }
+    else if (key == "builddate") collectinfo.buildDate = value.getint();
+    else if (key == "languages") collectinfo.languages = cfgline;
+    else if (key == "numdocs") collectinfo.numDocs = value.getint();
+    else if (key == "numsections") collectinfo.numSections = value.getint();
+    else if (key == "numwords") collectinfo.numWords = value.getint();
+    else if (key == "numbytes") collectinfo.numBytes = value.getint();
+    else if (key == "stemindexes") collectinfo.stemIndexes = value.getint();
+    else if (key == "collectionmeta") {
+      // genuine collmeta get added as collectionmeta and collection_macros
+      // .collmeta just get added as collection_macros
+      text_t params;
+      if (cfgline.size() == 3) {
+	// get the params for later
+	text_t::const_iterator first=cfgline[1].begin()+1;
+	text_t::const_iterator last=cfgline[1].end()-1;
+	params=substr(first, last);
+      }
+      
+      text_t meta_name = cfgline[0];
+      if (*(meta_name.begin())=='.') {
+	// a .xxx collectionmeta. strip off the . and
+	// look it up in the indexmap to get the actual value
+	
+	text_t name = substr(cfgline[0].begin()+1,cfgline[0].end());
+	text_t new_name;
+	if (indexmap.from2to(name, new_name)) {
+	  meta_name = new_name;
+	} 
+      } else {
+	// add them to collectionmeta
+	text_tmap lang_map = collectinfo.collectionmeta[cfgline[0]];
+	if (cfgline.size() == 2) {
+	  lang_map[g_EmptyText] = cfgline[1];
+	} else if (cfgline.size() == 3 ) {
+	  // get the lang out of params
+	  paramhashtype params_hash;
+	  splitparams(params, params_hash);
+	  
+	  text_t lang = params_hash["l"];
+	  lang_map[lang] = cfgline[2];
+	  if (lang_map[g_EmptyText].empty()) {
+	    // want the first one as the default if no default specified
+	    lang_map[g_EmptyText] = cfgline[2];
+	  }
+	}
+	collectinfo.collectionmeta[cfgline[0]] = lang_map;
+	
+      }
+      
+      // add all collectionmeta to macro list
+      text_tmap params_map = collectinfo.collection_macros[meta_name];
+      
+      if (cfgline.size() == 2) {// no params for this macrohttp://uk.sports.yahoo.com/13032007/13/news-brief.html
+	params_map[g_EmptyText] = cfgline[1];
+      }
+      else if (cfgline.size() == 3) {// has params
+	params_map[params] = cfgline[2];
+	if (params_map[g_EmptyText].empty()) {
+	  params_map[g_EmptyText] = cfgline[2];
+	}
+      }
+      collectinfo.collection_macros[meta_name] = params_map;
+    }
+    else if (key == "collectionmacro") {
+      text_t nobrackets;
+      text_tmap params_map = collectinfo.collection_macros[cfgline[0]];
+      // add all to macro list
+      if (cfgline.size() == 2) { // no params for this macro
+	params_map[g_EmptyText] = cfgline[1];
+      }
+      else if (cfgline.size() == 3) {// has params
+	// strip [ ] brackets from params
+	text_t::const_iterator first=cfgline[1].begin()+1;
+	text_t::const_iterator last=cfgline[1].end()-1;
+	nobrackets=substr(first, last);
+	params_map[nobrackets] = cfgline[2];
+      }
+      collectinfo.collection_macros[cfgline[0]] = params_map;
+      
+    } else if (key == "format" && cfgline.size() == 2)
+      collectinfo.format[cfgline[0]] = cfgline[1];
+    else if (key == "building" && cfgline.size() == 2)
+      collectinfo.building[cfgline[0]] = cfgline[1];
+    else if (key == "httpdomain") collectinfo.httpdomain = value;
+    else if (key == "httpprefix") collectinfo.httpprefix = value;
+    else if (key == "receptionist") collectinfo.receptionist = value;
+    else if (key == "buildtype") collectinfo.buildType = value;
+    // backwards compatibility - searchytpes is now a format statement
+    else if (key == "searchtype") { // means buildtype is mgpp
+      if (collectinfo.buildType.empty()) {
+	collectinfo.buildType = "mgpp";
+      }
+      joinchar(cfgline, ',', collectinfo.format["SearchTypes"]);
+      //collectinfo.searchTypes = cfgline;
+    }
+    else if (key == "separate_cjk") {
+      if (value == "true") collectinfo.isSegmented = true;
+      else collectinfo.isSegmented = false;
+    }
+    // What have we set in our collect.cfg file :  document or collection ?
+    else if (key == "authenticate") collectinfo.authenticate = value;
+
+    // What have we set for our group list
+    else if (key == "auth_group") joinchar(cfgline,',',collectinfo.auth_group);
+
+    // store all the mappings for use when collection meta is read later
+    // (build.cfg read before collect.cfg)
+    else if (key == "indexmap" || key == "indexfieldmap" || key == "subcollectionmap" || key == "languagemap" || key == "levelmap") {
+      indexmap.importmap (cfgline, true);
+      
+    } 
+    // In the map the key-value pair contain the same
+    // data i.e key == data, if key is 2 then data is 2
+    
+    // What have we set for our public_documents ACL
+    else if (key == "public_documents")
+       {
+	  text_tarray::const_iterator begin = cfgline.begin();
+	  text_tarray::const_iterator end = cfgline.end();
+	  while(begin != end)
+	     {
+		// key = data i.e if key is 2 then data is 2
+		// collectinfo.public_documents[*begin] is the key
+		// *begin is the data value
+
+		collectinfo.public_documents[*begin] = *begin;
+		++begin;
+	     }
+       }
+    
+    // What have we set for our private_documents ACL
+    else if (key == "private_documents")
+       {
+	  text_tarray::const_iterator begin = cfgline.begin();
+	  text_tarray::const_iterator end = cfgline.end();
+	  while(begin != end)
+	     {
+		// key = data i.e if key is 2 then data is 2
+		// collectinfo.public_documents[*begin] is the key
+		// *begin is the data value
+		
+		collectinfo.private_documents[*begin] = *begin;
+		++begin;
+	     }
+       }
+
+    // dynamic_classifier <UniqueID> "<Options>"
+    else if (key == "dynamic_classifier")
+    {
+      collectinfo.dynamic_classifiers[cfgline[0]] = cfgline[1];
+    }
+  }
+  
+  // configure the filters
+  filtermapclass::iterator filter_here = filters.begin();
+  filtermapclass::iterator filter_end = filters.end();
+  while (filter_here != filter_end) {
+    assert ((*filter_here).second.f != NULL);
+    if ((*filter_here).second.f != NULL) 
+      (*filter_here).second.f->configure(key, cfgline);
+
+    ++filter_here;
+  }
+
+  // configure the sources
+  sourcelistclass::iterator source_here = sources.begin();
+  sourcelistclass::iterator source_end = sources.end();
+  while (source_here != source_end) {
+    assert ((*source_here).s != NULL);
+    if ((*source_here).s != NULL)
+      (*source_here).s->configure(key, cfgline);
+    
+    ++source_here;
+  }
+}
+
+
+void collectserver::configure (const text_t &key, const text_t &value) {
+  text_tarray cfgline;
+  cfgline.push_back (value);
+  configure(key, cfgline);
+}
+
+void collectserver::ping (bool &wasSuccess, comerror_t &error, ostream &logout) {
+  // if we've not been properly configured, then it is a foregone
+  // conclusion that we cannot be active
+  if (this->configinfo.collection == "null")
+    {
+      wasSuccess = false;
+    }
+  // if no build date exists, then the collection was probably not built;
+  // ditto if the number of documents is zero, then something is pretty
+  // wrong
+  else if (this->collectinfo.buildDate == 0 ||
+      this->collectinfo.numDocs == 0)
+    {
+      wasSuccess =  false;
+    }
+  // it is probably okay
+  else
+    wasSuccess = true;
+}
+
+
+bool collectserver::init (ostream &logout) {
+  // delete the indexmap
+  indexmap.clear();
+
+  // init the filters
+  filtermapclass::iterator filter_here = filters.begin();
+  filtermapclass::iterator filter_end = filters.end();
+  while (filter_here != filter_end) {
+    assert ((*filter_here).second.f != NULL);
+    if (((*filter_here).second.f != NULL) &&
+	!(*filter_here).second.f->init(logout)) return false;
+    
+    ++filter_here;
+  }
+
+  // init the sources
+  sourcelistclass::iterator source_here = sources.begin();
+  sourcelistclass::iterator source_end = sources.end();
+  while (source_here != source_end) {
+    assert ((*source_here).s != NULL);
+    if (((*source_here).s != NULL) &&
+	!(*source_here).s->init(logout)) return false;
+    
+    ++source_here;
+  }
+
+  return true;
+}
+
+
+void collectserver::get_collectinfo (ColInfoResponse_t &reponse,
+		      comerror_t &err, ostream &/*logout*/) {
+  reponse = collectinfo; 
+  err = noError;
+}
+
+void collectserver::get_filterinfo (InfoFiltersResponse_t &response,
+				    comerror_t &err, ostream &/*logout*/) {
+  response.clear ();
+
+  // get a list of filter names
+  filtermapclass::iterator filter_here = filters.begin();
+  filtermapclass::iterator filter_end = filters.end();
+  while (filter_here != filter_end) {
+    response.filterNames.insert ((*filter_here).first);
+    ++filter_here;
+  }
+
+  err = noError;
+}
+
+void collectserver::get_filteroptions (const InfoFilterOptionsRequest_t &request,
+				       InfoFilterOptionsResponse_t &response, 
+				       comerror_t &err, ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  filterclass *thisfilter = filters.getfilter(request.filterName);
+  if (thisfilter != NULL) {
+    thisfilter->get_filteroptions (response, err, logout);
+  } else {
+    response.clear ();
+    err = protocolError;
+    logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
+	   << "filter \"" << request.filterName << "\".\n\n";
+  }
+}
+
+void collectserver::filter (FilterRequest_t &request,
+			    FilterResponse_t &response,
+			    comerror_t &err, ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  // translate any ".fc", ".pr" etc. stuff in the docSet
+  text_t translatedOID;
+  text_tarray translatedOIDs;
+  text_tarray::iterator doc_here = request.docSet.begin();
+  text_tarray::iterator doc_end = request.docSet.end();
+  while (doc_here != doc_end) {
+    if (needs_translating (*doc_here)) {
+      sourcelistclass::iterator source_here = sources.begin();
+      sourcelistclass::iterator source_end = sources.end();
+      while (source_here != source_end) {
+	assert ((*source_here).s != NULL);
+	if (((*source_here).s != NULL) &&
+	    ((*source_here).s->translate_OID (*doc_here, translatedOID, err, logout))) {
+	  if (err != noError) return;
+	  break;
+	}
+	++source_here;
+      }
+      translatedOIDs.push_back (translatedOID);
+    } else {
+      translatedOIDs.push_back (*doc_here);
+    }
+    ++doc_here;
+  }
+  request.docSet = translatedOIDs;
+
+  response.clear();
+
+  filterclass *thisfilter = filters.getfilter(request.filterName);
+  if (thisfilter != NULL) {
+    // filter the data
+    thisfilter->filter (request, response, err, logout);
+    if (err != noError) return;
+    // fill in the metadata for each of the OIDs (if it is requested)
+    if (request.filterResultOptions & FRmetadata) {
+      bool processed = false;
+      ResultDocInfo_tarray::iterator resultdoc_here = response.docInfo.begin();
+      ResultDocInfo_tarray::iterator resultdoc_end = response.docInfo.end();
+      while (resultdoc_here != resultdoc_end) {
+	// try each of the sources in turn
+	sourcelistclass::iterator source_here = sources.begin();
+	sourcelistclass::iterator source_end = sources.end();
+	while (source_here != source_end) {
+	  assert ((*source_here).s != NULL);
+	  if (((*source_here).s != NULL) &&
+	      ((*source_here).s->get_metadata(request.requestParams, request.refParams,
+					      request.getParents, request.fields, 
+					      (*resultdoc_here).OID, (*resultdoc_here).metadata, 
+					      err, logout))) {
+	    if (err != noError) return;
+	    processed = true;
+	    break;
+	  }
+	  ++source_here;
+	}
+	if (!processed) {
+
+	  logout << text_t2ascii << "Protocol Error: nothing processed for "
+	   << "filter \"" << request.filterName << "\".\n\n";
+
+	  err = protocolError;
+	  return;
+	}
+	++resultdoc_here;
+      }
+    }  
+  
+    err = noError;
+  }
+  else
+  {
+    response.clear ();
+    err = protocolError;
+    logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
+	   << "filter \"" << request.filterName << "\".\n\n";
+  }
+}
+
+void collectserver::get_document (const DocumentRequest_t &request,
+				  DocumentResponse_t &response,
+				  comerror_t &err, ostream &logout) {
+
+  sourcelistclass::iterator source_here = sources.begin();
+  sourcelistclass::iterator source_end = sources.end();
+  while (source_here != source_end) {
+    assert ((*source_here).s != NULL);
+    if (((*source_here).s != NULL) &&
+	((*source_here).s->get_document (request.OID, response.doc, err, logout))) {
+      if (err != noError) return;
+      break;
+    }
+    ++source_here;
+  }
+}
+
+void collectserver::is_searchable (bool &issearchable, comerror_t &err,
+				   ostream &logout) {
+
+  sourcelistclass::iterator source_here = sources.begin();
+  sourcelistclass::iterator source_end = sources.end();
+  while (source_here != source_end) {
+    assert ((*source_here).s != NULL);
+    if (((*source_here).s != NULL) &&
+	((*source_here).s->is_searchable (issearchable, err, logout))) {
+      if (err != noError) return;
+      break;
+    }
+    ++source_here;
+  }
+}
+
+
+bool operator==(const collectserverptr &x, const collectserverptr &y) {
+  return (x.c == y.c);
+}
+
+bool operator<(const collectserverptr &x, const collectserverptr &y) {
+  return (x.c < y.c);
+}
+
+
+// thecollectserver remains the property of the calling code but
+// should not be deleted until it is removed from this list.
+void collectservermapclass::addcollectserver (collectserver *thecollectserver) {
+  // can't add a null collection server
+  assert (thecollectserver != NULL);
+  if (thecollectserver == NULL) return;
+  
+  // can't add an collection server with no collection name
+  assert (!(thecollectserver->get_collection_name()).empty());
+  if ((thecollectserver->get_collection_name()).empty()) return;
+
+  collectserverptr cptr;
+  cptr.c = thecollectserver;
+  collectserverptrs[thecollectserver->get_collection_name()] = cptr;
+}
+
+// getcollectserver will return NULL if the collectserver could not be found
+collectserver *collectservermapclass::getcollectserver (const text_t &collection) {
+  // can't find a collection with no name
+  if (collection.empty()) return NULL;
+
+  iterator here = collectserverptrs.find (collection);
+  if (here == collectserverptrs.end()) return NULL;
+  
+  return (*here).second.c;
+}
Index: /gsdl/trunk/runtime-src/src/colservr/collectserver.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/collectserver.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/collectserver.h	(revision 16571)
@@ -0,0 +1,201 @@
+/**********************************************************************
+ *
+ * collectserver.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+
+#ifndef COLLECTSERVER_H
+#define COLLECTSERVER_H
+
+// Library header files
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "comtypes.h"
+#include "filter.h"
+#include "source.h"
+#include "cfgread.h"
+#include "cnfgable.h" 
+#include "maptools.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+#endif
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\map>
+#elif defined(GSDL_USE_STL_H)
+#  include <map.h>
+#else
+#  include <map>
+#endif
+
+
+struct colservrconf {
+  text_t gsdlhome;
+  text_t collecthome;
+  text_t dbhome;
+  text_t collection;
+  text_t collectdir;
+};
+
+
+class collectserver : public configurable {
+protected:
+  colservrconf configinfo;
+  ColInfoResponse_t collectinfo;
+
+  filtermapclass filters;
+  sourcelistclass sources;
+
+  // some stuff to remember while we are configuring
+  stringmap indexmap;
+
+public:
+  collectserver ();
+  virtual ~collectserver ();
+
+  // add_filter makes another filter available to the collection server
+  // the filter remains the property of the calling code and that
+  // code should destroy the filter after the collection server has been
+  // destroyed.
+  void add_filter (filterclass *thefilter) {filters.addfilter(thefilter);}
+  filtermapclass *get_filtermap_ptr () {return &filters;}
+
+  // add_source makes another source available to the collection server
+  // the source remains the property of the calling code and that
+  // code should destroy the source after the collection server has been
+  // destroyed.
+  void add_source (sourceclass *thesource) {sources.addsource(thesource);}
+  sourcelistclass *get_sourcelist_ptr () {return &sources;}
+
+  // configure should be called for each line in the
+  // configuration files to configure the collection server and everything
+  // it contains. The configuration should take place just before initialisation.
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+  void configure (const text_t &key, const text_t &value);
+  const colservrconf &get_configinfo () {return configinfo;}
+  text_t get_collection_name () {return configinfo.collection;}
+  bool is_collection_group () {return collectinfo.isCollectGroup;}
+
+
+  // ping indicates whether the collection has appropriate data structures
+  // to be active or not
+  void ping(bool &wasSuccess, comerror_t &err, ostream &logout);
+
+  // init should be called after the collection name has been set and
+  // all initialisation is done. init returns true if the initialisation
+  // was successful, if false is returned then no other functions
+  // should be called (without producing meaningless output).
+  virtual bool init (ostream &logout);
+
+  void get_collectinfo (ColInfoResponse_t &reponse,
+			comerror_t &err, ostream &logout);
+
+  virtual void get_filterinfo (InfoFiltersResponse_t &response,
+			       comerror_t &err, ostream &logout);
+
+  virtual void get_filteroptions (const InfoFilterOptionsRequest_t &request,
+				  InfoFilterOptionsResponse_t &response, 
+				  comerror_t &err, ostream &logout);
+
+  virtual void filter (FilterRequest_t &request,
+		       FilterResponse_t &response,
+		       comerror_t &err, ostream &logout);
+
+
+  virtual void get_document (const DocumentRequest_t &request,
+			     DocumentResponse_t &response,
+			     comerror_t &err, ostream &logout);
+
+  virtual void is_searchable (bool &issearchable, comerror_t &err,
+			      ostream &logout);
+
+};
+
+
+// The collectserverptr function does not 'own' the collectserver. The
+// collectserver should be deleted by the code which created it.
+class collectserverptr {
+public:
+  collectserver *c;
+
+  collectserverptr () {c=NULL;}
+  ~collectserverptr () {}
+};
+
+bool operator==(const collectserverptr &x, const collectserverptr &y);
+bool operator<(const collectserverptr &x, const collectserverptr &y);
+
+typedef map<text_t, collectserverptr, lttext_t> collectserverptrmap;
+
+// contains a list of collectservers indexed by their name
+class collectservermapclass {
+protected:
+  collectserverptrmap collectserverptrs;
+
+public:
+  // type support for collectserverptrmap
+  typedef collectserverptrmap::iterator iterator;
+  typedef collectserverptrmap::const_iterator const_iterator;
+  typedef collectserverptrmap::reference reference;
+  typedef collectserverptrmap::const_reference const_reference;
+  typedef collectserverptrmap::size_type size_type;
+
+  typedef collectserverptrmap::difference_type difference_type;
+  typedef collectserverptrmap::const_reverse_iterator const_reverse_iterator;
+  typedef collectserverptrmap::reverse_iterator reverse_iterator;
+  
+  // basic container support
+  iterator begin () {return collectserverptrs.begin();}
+  const_iterator begin () const {return collectserverptrs.begin();}
+  iterator end () {return collectserverptrs.end();}
+  const_iterator end () const {return collectserverptrs.end();}
+
+  void erase(iterator pos) {collectserverptrs.erase(pos);}
+  void erase(iterator first, iterator last) {collectserverptrs.erase(first, last);}
+  collectservermapclass &operator=(const collectservermapclass &x) 
+    {collectserverptrs=x.collectserverptrs;return *this;}
+
+  bool empty () const {return collectserverptrs.empty();}
+  size_type size() const {return collectserverptrs.size();}
+
+
+  // added functionality
+  void clear () {collectserverptrs.erase(collectserverptrs.begin(),collectserverptrs.end());}
+
+  // thecollectserver remains the property of the calling code but
+  // should not be deleted until it is removed from this list.
+  void addcollectserver (collectserver *thecollectserver);
+
+  // getcollectserver will return NULL if the collectserver could not be found
+  collectserver *getcollectserver (const text_t &collection);
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/collectset.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/collectset.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/collectset.cpp	(revision 16571)
@@ -0,0 +1,499 @@
+/**********************************************************************
+ *
+ * collectset.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#include "collectset.h"
+#include "collectserver.h"
+#include "colservrconfig.h"
+#include "gsdlsitecfg.h"
+#include "gdbmclass.h"
+#include "fileutil.h"
+#include "filter.h"
+#include "browsefilter.h"
+#include "sqlbrowsefilter.h"
+#include "queryfilter.h"
+#include "mgqueryfilter.h"
+#include "mgppqueryfilter.h"
+#include "mgsource.h"
+#include "lucenequeryfilter.h"
+#include "lucenesource.h"
+
+#include <assert.h>
+
+#ifdef USE_SQLITE
+#include "sqlitedbclass.h"
+#endif
+
+collectset::collectset (text_t& gsdlhome, text_t& collecthome) 
+{
+  // gsdlhome and collecthome will be set as a result of calling this function
+  // collecthome will default to "<gsdlhome>/collect" if not explicitly
+  // specified in config file
+
+  text_tarray collections;
+
+  // get gsdlhome (if we fail the error will be picked up later -- in
+  // cgiwrapper)
+
+  if (site_cfg_read (gsdlhome, collecthome, httpdomain, httpprefix)) {
+    if (!gsdlhome.empty() && directory_exists(gsdlhome)) {
+      if (read_dir (collecthome, collections)) {
+    
+	text_tarray::const_iterator thiscol = collections.begin();
+	text_tarray::const_iterator endcol = collections.end();
+
+	while (thiscol != endcol) {
+	  // ignore the modelcol
+	  if (*thiscol == "modelcol") {
+	    ++thiscol;
+	    continue;
+	  }
+
+	  this->add_collection (*thiscol, gsdlhome, collecthome);
+
+	  ++thiscol;
+	}
+
+	this->add_all_collection_groups(gsdlhome, collecthome);
+      }
+    }
+  }
+}
+
+collectset::~collectset () {
+  collectservermapclass::iterator here = cservers.begin();
+  collectservermapclass::iterator end = cservers.end();
+
+  while (here != end) {
+    if ((*here).second.c != NULL) {
+      delete (*here).second.c;
+    }
+    ++here;
+  }
+  cservers.clear();
+}
+
+bool collectset::init (ostream &logout) {
+  collectservermapclass::iterator here = cservers.begin();
+  collectservermapclass::iterator end = cservers.end();
+
+  while (here != end) {
+    assert ((*here).second.c != NULL);
+    if ((*here).second.c != NULL) {
+      const colservrconf &configinfo = (*here).second.c->get_configinfo ();
+
+      // configure this collection server
+
+      // note that we read build.cfg before collect.cfg so that the indexmaps
+      // are available to decode defaultindex, defaultsubcollection, and
+      // defaultlanguage
+
+      bool failed_build_cfg = false;
+      if (!build_cfg_read (*((*here).second.c), configinfo.gsdlhome,
+			   configinfo.collecthome, configinfo.collection)) {
+	failed_build_cfg = true;
+
+	outconvertclass text_t2ascii;
+	logout << text_t2ascii 
+	       << "Warning: couldn't read build.cfg file for collection \"" 
+	       << configinfo.collection << "\""
+	       << "  gsdlhome=\"" << configinfo.gsdlhome << "\"\n"
+	       << "  collecthome=\"" << configinfo.collecthome << "\"\n";
+      }
+
+      bool failed_collect_cfg = false;
+      if (!collect_cfg_read (*((*here).second.c), configinfo.gsdlhome,
+			     configinfo.collecthome, configinfo.collection)) {
+	failed_collect_cfg = true;
+	outconvertclass text_t2ascii;
+	logout << text_t2ascii 
+	       << "Warning: couldn't read collect.cfg file for collection \""
+	       << configinfo.collection << "\""
+	       << "  gsdlhome=\"" << configinfo.gsdlhome << "\"\n"
+	       << "  collecthome=\"" << configinfo.collecthome << "\"\n";
+      }
+
+      
+      bool is_colgroup = (*here).second.c->is_collection_group();
+
+      if (failed_collect_cfg) {
+	++here;
+	continue;
+      }
+
+      if (failed_build_cfg && (!is_colgroup)) {
+	++here;
+	continue;
+      }
+      // let a failed build.cfg through if its 'collect.cfg' marks it as 'collectgroup true'
+
+      if (!(*here).second.c->init (logout)) return false;
+
+      (*here).second.c->configure("httpdomain",httpdomain);
+      (*here).second.c->configure("httpprefix",httpprefix);
+    }
+    ++here;
+  }
+
+  return true;
+}
+
+collectservermapclass collectset::servers()
+{ return cservers;
+}
+
+
+void collectset::add_all_collections(const text_t &gsdlhome, 
+				     const text_t& collecthome) 
+{
+  text_tarray collections;
+
+  if (read_dir(collecthome, collections)) {
+
+    text_tarray::const_iterator thiscol = collections.begin();
+    text_tarray::const_iterator endcol = collections.end();
+
+    while (thiscol != endcol) {
+    
+      // ignore the modelcol
+      if (*thiscol == "modelcol") {
+	++thiscol;
+	continue;
+      }
+    
+      // create collection server for this collection
+      this->add_collection (*thiscol, gsdlhome, collecthome);
+    
+      ++thiscol;
+    }
+
+    this->add_all_collection_groups(gsdlhome,collecthome);
+  }
+}
+
+// add_collection sets up the collectionserver and calls
+// add_collectserver
+void collectset::add_collection (const text_t& collection, 
+				 const text_t& gsdlhome,
+				 const text_t& collecthome) 
+{
+
+  this->remove_collection(collection);
+  
+  // read config file to see if built with mg, mgpp, or lucene
+  text_t buildtype = "mg"; // mg is default
+  text_t infodbtype = "gdbm"; // gdbm is default
+
+  text_tarray cfgline;
+  text_t key;
+
+  text_t build_cfg = filename_cat(collecthome, collection, "index", "build.cfg");
+  char *build_cfgc = build_cfg.getcstr();
+  ifstream confin(build_cfgc);
+
+  if (confin) {
+    while (read_cfg_line(confin, cfgline) >= 0) {
+      if (cfgline.size() == 2) {
+	key = cfgline[0];
+	cfgline.erase(cfgline.begin());
+	if (key == "buildtype") {
+	  buildtype = cfgline[0];
+	}
+	if (key == "infodbtype") {
+	  infodbtype = cfgline[0];
+	}
+      }
+    }
+    confin.close();
+  }
+  delete []build_cfgc;
+
+  collectserver *cserver = new collectserver();
+
+  // Create a dbclass of the correct type
+  dbclass *db_ptr = NULL;
+
+#ifdef USE_SQLITE
+  if (infodbtype == "sqlite")
+  {
+    sqlitedbclass *sql_db_ptr = new sqlitedbclass();
+    db_ptr = sql_db_ptr;
+
+    // add a sql browse filter
+    sqlbrowsefilterclass *sqlbrowsefilter = new sqlbrowsefilterclass();
+    sqlbrowsefilter->set_sql_db_ptr(sql_db_ptr);
+    cserver->add_filter (sqlbrowsefilter);  
+  }
+#endif
+
+  // Use GDBM if the infodb type is empty or not one of the values above
+  if (db_ptr == NULL)
+  {
+    db_ptr = new gdbmclass();
+  }
+
+  // add a null filter
+  filterclass *filter = new filterclass ();
+  cserver->add_filter (filter);
+      
+  // add a browse filter
+  browsefilterclass *browsefilter = new browsefilterclass();
+  browsefilter->set_db_ptr(db_ptr);
+  cserver->add_filter (browsefilter);  
+ 
+  if (buildtype == "mg") {
+    mgsearch = new mgsearchclass();
+ 
+    // add a query filter
+    mgqueryfilterclass *queryfilter = new mgqueryfilterclass();
+    queryfilter->set_db_ptr(db_ptr);
+    queryfilter->set_textsearchptr (mgsearch);
+    cserver->add_filter (queryfilter);
+    
+    // add a mg source
+    mgsourceclass *mgsource = new mgsourceclass ();
+    mgsource->set_db_ptr(db_ptr);
+    mgsource->set_textsearchptr (mgsearch);
+    cserver->add_source (mgsource);
+  }
+  else if (buildtype == "mgpp") {
+    mgppsearch = new mgppsearchclass();
+
+    // add a query filter
+    mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass();
+    queryfilter->set_db_ptr(db_ptr);
+    queryfilter->set_textsearchptr (mgppsearch);
+    cserver->add_filter (queryfilter);
+      
+    // add a mg source
+    mgsourceclass *mgsource = new mgsourceclass ();
+    mgsource->set_db_ptr(db_ptr);
+    mgsource->set_textsearchptr (mgppsearch);
+    cserver->add_source (mgsource);
+  }
+  else if (buildtype == "lucene") {
+    lucenesearch = new lucenesearchclass();
+    lucenesearch->set_gsdlhome(gsdlhome); 
+
+    // add a query filter
+    lucenequeryfilterclass *queryfilter = new lucenequeryfilterclass();
+    queryfilter->set_db_ptr(db_ptr);
+    queryfilter->set_textsearchptr (lucenesearch);
+    cserver->add_filter (queryfilter);
+      
+    // add a lucene source
+    lucenesourceclass *lucenesource = new lucenesourceclass ();
+    lucenesource->set_db_ptr(db_ptr);
+    lucenesource->set_textsearchptr (lucenesearch);
+    cserver->add_source (lucenesource);
+  }
+
+  // inform collection server and everything it contains about its
+  // collection name
+  cserver->configure ("collection", collection);
+  cserver->configure ("gsdlhome", gsdlhome);
+  cserver->configure ("collecthome", collecthome); 
+  cservers.addcollectserver (cserver);
+}
+
+void collectset::remove_all_collections () {
+
+  // first unload any cached mg databases
+  if (mgsearch != NULL) {
+    mgsearch->unload_database();
+  }
+
+  // now delete the collection server objects
+  collectservermapclass::iterator here = cservers.begin();
+  collectservermapclass::iterator end = cservers.end();
+
+  while (here != end) {
+    if ((*here).second.c != NULL) {
+      delete (*here).second.c;
+    }
+    ++here;
+  }
+  cservers.clear();
+}
+
+void collectset::add_collection_group(const text_t& collection, 
+				      const text_t& gsdlhome,
+				      const text_t& collecthome)
+{
+  text_tarray group;
+
+  text_t collect_group_dir = filename_cat (collecthome, collection);
+
+  // need to read collect.cfg for 'collectgroup' as class hasn't been initialised through 'init' yet
+  text_t is_collect_group;
+  text_tarray cfgline;
+  text_t key;
+  text_t build_cfg = filename_cat(collect_group_dir, "etc", "collect.cfg");
+  char *collect_cfgc = build_cfg.getcstr();
+  ifstream confin(collect_cfgc);
+
+  if (confin) {
+    while (read_cfg_line(confin, cfgline) >= 0) {
+      if (cfgline.size() == 2) {
+	key = cfgline[0];
+	cfgline.erase(cfgline.begin());
+	if (key == "collectgroup") {
+	  is_collect_group = cfgline[0];
+	  break;
+	}
+      }
+    }
+    confin.close();
+  }
+  delete []collect_cfgc;
+
+  if (is_collect_group == "true") {
+
+    if (read_dir (collect_group_dir, group)) {
+      
+      text_tarray::const_iterator thiscol = group.begin();
+      text_tarray::const_iterator endcol = group.end();
+      
+      while (thiscol != endcol) {
+	// ignore the modelcol
+	if (*thiscol == "etc") {
+	  ++thiscol;
+	  continue;
+	}
+	
+	text_t group_col = filename_cat(collection,*thiscol);
+	this->add_collection (group_col, gsdlhome, collecthome);
+	
+	++thiscol;
+      }
+    }
+  }
+}
+
+void collectset::add_all_collection_groups (const text_t& gsdlhome,
+					    const text_t& collecthome) 
+
+{
+  collectservermapclass::iterator here = cservers.begin();
+  collectservermapclass::iterator end = cservers.end();
+  
+  while (here != end) {
+    text_t collection = (*here).second.c->get_collection_name();
+    this->add_collection_group(collection,gsdlhome,collecthome);
+
+    ++here;
+  }
+}
+
+
+// remove_collection deletes the collection server of collection.
+// This only needs to be called if a collectionserver is to be
+// removed while the library is running. The destructor function
+// cleans up all collectservers when the program exits.
+void collectset::remove_collection (const text_t &collection) {
+
+  // do nothing if no collection server exists for this collection 
+  if (cservers.getcollectserver(collection) == NULL) return;
+
+  // first unload any cached mg databases - we may need to do something
+  // similar to this for mgpp and lucene too
+  if (mgsearch != NULL) {
+    mgsearch->unload_database();
+  }
+
+  // now delete the collection server object
+  collectservermapclass::iterator here = cservers.begin();
+  collectservermapclass::iterator end = cservers.end();
+
+  while (here != end) {
+    if ((*here).second.c != NULL && (*here).first == collection) {
+      delete (*here).second.c;
+      cservers.erase (here);
+      return;
+    }
+    ++here;
+  }
+}
+
+
+// remove_collection deletes the collection server of collection.
+// This only needs to be called if a collectionserver is to be
+// removed while the library is running. The destructor function
+// cleans up all collectservers when the program exits.
+void collectset::remove_collection (const text_t &collection, ostream &logout) {
+
+  remove_collection(collection);
+
+  outconvertclass text_t2ascii;
+  logout << text_t2ascii << "collectset::remove_collection: failed to remove collectserver for "
+	 << collection << "\n";
+}
+
+void collectset::configure(const text_t &key, const text_tarray &cfgline)
+{
+  if ((key == "collection") || (key == "collectdir")) return;
+
+  collectservermapclass::iterator here = cservers.begin();
+  collectservermapclass::iterator end = cservers.end();
+
+  while (here != end) {
+    assert ((*here).second.c != NULL);
+    if ((*here).second.c != NULL) {
+      if (key == "collectinfo") {
+	if ((*here).first == cfgline[0]) {
+	  if (cfgline.size()==3) {
+	    (*here).second.c->configure ("gsdlhome", cfgline[1]);
+	    (*here).second.c->configure ("gdbmhome", cfgline[2]);
+	  }
+	  else {
+	    (*here).second.c->configure ("gsdlhome", cfgline[1]);
+	    (*here).second.c->configure ("collecthome", cfgline[2]);
+	    (*here).second.c->configure ("gdbmhome", cfgline[3]);
+	  }
+	}
+      } else {
+	(*here).second.c->configure (key, cfgline);
+      }
+    }
+
+    ++here;
+  }
+}
+
+void collectset::getCollectionList (text_tarray &collist) 
+{
+  collist.erase(collist.begin(),collist.end());
+
+  collectservermapclass::iterator here = cservers.begin();
+  collectservermapclass::iterator end = cservers.end();
+  while (here != end) {
+    assert ((*here).second.c != NULL);
+    if ((*here).second.c != NULL) {
+      collist.push_back ((*here).second.c->get_collection_name());
+    }
+    ++here;
+  }
+}
+
Index: /gsdl/trunk/runtime-src/src/colservr/collectset.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/collectset.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/collectset.h	(revision 16571)
@@ -0,0 +1,73 @@
+/************************************************************
+ * 
+ * Collection set
+ *
+ ************************************************************/
+
+#ifndef COLLECTSET_H
+#define COLLECTSET_H
+
+#include "collectserver.h"
+#include "cnfgable.h"
+#include "mgsearch.h"
+#include "mgppsearch.h"
+#include "lucenesearch.h"
+
+class collectset : public configurable
+{
+ protected:
+  collectservermapclass cservers;
+  mgsearchclass         *mgsearch;
+  mgppsearchclass       *mgppsearch;
+  lucenesearchclass     *lucenesearch;
+  int                   noofservers;
+  text_t                httpdomain;
+  text_t                httpprefix;
+
+ public:
+  collectset(text_t& gsdlhome, text_t& collecthome);
+  // this constructor is used by the local library
+  collectset() {}
+
+  ~collectset();
+
+  // initialise the collections
+  bool init(ostream &logout);
+
+  // configure all the servers as supplied
+  void configure (const text_t &key, const text_tarray &cfgline);
+
+  // Add/remove collections
+  void add_all_collections (const text_t &gsdlhome, const text_t& collecthome);
+  void remove_all_collections ();
+ 
+  void remove_collection (const text_t &collection);
+  void remove_collection (const text_t &collection, ostream& logout);
+
+  void add_collection (const text_t &collection, 
+		       const text_t &gsdlhome, 
+		       const text_t& collecthome);
+
+  void add_collection_group(const text_t& collection, 
+			    const text_t& gsdlhome, 
+			    const text_t& collecthome);
+
+  void add_all_collection_groups (const text_t& gsdlhome, 
+				  const text_t& collecthome);
+
+  // return the total number of servers in the set
+  int size();
+
+  void getCollectionList(text_tarray &collist);
+
+  // return the component map
+  collectservermapclass servers();
+
+  // return an individual collection server
+  collectserver *getCollectServer(const text_t &collection)
+    {
+      return cservers.getcollectserver(collection);
+    }
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/colservrconfig.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/colservrconfig.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/colservrconfig.cpp	(revision 16571)
@@ -0,0 +1,78 @@
+/**********************************************************************
+ *
+ * colservrconfig.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+#include "colservrconfig.h"
+#include "fileutil.h"
+#include "cfgread.h"
+
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace/std/iostream>
+#  include <ospace/std/fstream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#  include <fstream.h>
+#else
+#  include <iostream>
+#  include <fstream>
+#endif
+
+// collect_cfg_read reads collect.cfg returning true on success.
+bool collect_cfg_read (collectserver &cserver, const text_t &gsdlhome,
+		       const text_t& collecthome,
+		       const text_t &collection) 
+{
+  text_t filename = filename_cat (collecthome, collection);
+  filename = filename_cat (filename, "custom",collection,"etc","custom.cfg");
+
+  if (!file_exists (filename)) {
+    filename = filename_cat (collecthome, collection, "etc", "collect.cfg");
+
+    if (!file_exists (filename)) {
+      filename = filename_cat (gsdlhome, "etc", "collect.cfg");
+      if (!file_exists (filename)) return false;
+    }
+  }
+
+  return cserver.read_configfile(filename);
+}
+
+
+// build_cfg_read reads build.cfg and returns true on success.
+bool build_cfg_read (collectserver &cserver, const text_t &gsdlhome,
+		     const text_t& collecthome,
+		     const text_t &collection) {
+  text_t filename = filename_cat (collecthome, collection,"index","build.cfg");
+
+  if (!file_exists (filename)) {
+    filename = filename_cat (gsdlhome, "index", "build.cfg");
+    if (!file_exists (filename)) return false;
+  }
+
+  return cserver.read_configfile(filename);
+
+}
Index: /gsdl/trunk/runtime-src/src/colservr/colservrconfig.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/colservrconfig.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/colservrconfig.h	(revision 16571)
@@ -0,0 +1,45 @@
+/**********************************************************************
+ *
+ * colservrconfig.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef COLSERVRCONFIG_H
+#define COLSERVRCONFIG_H
+
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "collectserver.h"
+
+
+// collect_cfg_read reads collect.cfg returning true on success.
+bool collect_cfg_read (collectserver &cserver, const text_t &gsdlhome,
+		       const text_t& collecthome, const text_t &collection);
+
+// build_cfg_read reads build.cfg and returns true on success.
+bool build_cfg_read (collectserver &cserver, const text_t &gsdlhome,
+		     const text_t& collecthome, const text_t &collection);
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/comtypes.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/comtypes.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/comtypes.cpp	(revision 16571)
@@ -0,0 +1,294 @@
+/**********************************************************************
+ *
+ * comtypes.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "comtypes.h"
+
+
+text_t get_comerror_string (comerror_t err) {
+  if (err == noError) return "no error";
+  else if (err == authenticationFailure) return "authentication failure";
+  else if (err == protocolError) return "protocol error";
+  else if (err == configurationError) return "configuration error";
+  else if (err == systemProblem) return "system problem";
+  else if (err == syntaxError) return "query syntax error";
+  return "unknown problem";
+}
+
+
+void ShortColInfo_t::clear() {
+  name.clear();
+  host.clear();
+  port = 0;
+}
+
+/*
+   isPublic now defaults to true  most values are default          
+   similar to a constructor in a class to make some initializations
+*/
+
+void ColInfoResponse_t::clear () {
+  shortInfo.clear();
+  useBook=false;
+  isPublic=true;
+  isBeta=false;
+  isSegmented=false;
+  isCollectGroup=false;
+  languages.erase(languages.begin(), languages.end());
+  ccsCols.erase(ccsCols.begin(), ccsCols.end());
+  ccsOptions = 0;
+  stemIndexes = 3; // old default was both provided
+  buildDate=0;
+  buildType.clear();
+  numDocs=0;
+  numSections=0;
+  numWords=0;
+  numBytes=0;
+  format.erase(format.begin(), format.end());
+  building.erase(building.begin(), building.end());
+  httpdomain.clear();
+  httpprefix.clear();
+  receptionist.clear();
+
+  // Setting some authentication parameters use with
+  // various parts of the code.
+  
+  authenticate.clear();         // turned off by default, individual collection authentication
+  auth_group.clear();              // turned off by default, authentication by groups method
+  public_documents.clear();          // turned off by default, allow access to these documents <list>
+  private_documents.clear();           // turned off by default, disallow access to these documents <list>
+    
+}
+
+text_t ColInfoResponse_t::get_collectionmeta(text_t name, text_t lang) {
+  text_t value = collectionmeta[name][lang];
+  if (value.empty()) {
+    value = collectionmeta[name][g_EmptyText];
+  }
+  return value;
+
+}
+
+void InfoFiltersResponse_t::clear () {
+  filterNames.erase(filterNames.begin(), filterNames.end());
+}
+
+
+void InfoFilterOptionsRequest_t::clear () {
+  filterName.clear();
+}
+
+
+void FilterOption_t::clear () {
+  name.clear();
+  type = booleant;
+  repeatable = onePerQuery;
+  defaultValue.clear();
+  validValues.erase(validValues.begin(), validValues.end());
+}
+
+void FilterOption_t::check_defaultValue () {
+  text_tarray::iterator here, end;
+
+  // how the default is interpreted depends on the option type
+  switch (type) {
+  case booleant: 
+  case enumeratedt: // has to be one of the validValues
+    here = validValues.begin ();
+    end = validValues.end ();
+    while (here != end) {
+      if (*here == defaultValue) return;
+      ++here;
+    }
+    
+    break;
+
+  case integert: // has to be in the validValues range
+    if ((validValues.size() >= 2) &&
+	(validValues[0].getint() <= defaultValue.getint()) &&
+	(validValues[1].getint() >= defaultValue.getint()))
+      return;
+    break;
+
+  case stringt: // any value is valid
+    return; 
+  }
+
+  // did not find the defaultValue
+  if (validValues.empty()) defaultValue.clear();
+  else defaultValue = validValues[0];
+}
+
+
+bool operator==(const FilterOption_t &x, const FilterOption_t &y) {
+  return ((x.name == y.name) &&
+	  (x.type == y.type) &&
+	  (x.repeatable == y.repeatable) &&
+	  (x.defaultValue == y.defaultValue) &&
+	  (x.validValues == y.validValues));
+}
+
+bool operator<(const FilterOption_t &x, const FilterOption_t &y) {
+  return ((x.name < y.name) ||
+	  ((x.name == y.name) &&
+	   ((x.type < y.type) ||
+	    ((x.type == y.type) &&
+	     ((x.repeatable < y.repeatable) ||
+	      ((x.repeatable == y.repeatable) &&
+	       ((x.defaultValue < y.defaultValue) ||
+		((x.defaultValue == y.defaultValue) &&
+		 (x.validValues < y.validValues)))))))));
+}
+
+
+
+void InfoFilterOptionsResponse_t::clear () {
+  filterOptions.erase(filterOptions.begin(), filterOptions.end());
+}
+
+
+void OptionValue_t::clear () {
+  name.clear();
+  value.clear();
+}
+
+
+void FilterRequest_t::clear () {
+  filterName.clear();
+  filterLang.clear();
+  filterOptions.erase(filterOptions.begin(), filterOptions.end());
+  docSet.erase(docSet.begin(), docSet.end());
+  filterResultOptions = 0;
+  requestParams.clear();
+  refParams.clear();
+  fields.erase(fields.begin(), fields.end());
+  getParents = false;
+}
+
+
+void TermInfo_t::clear () {
+  term.clear();
+  freq = 0;
+  matchTerms.erase (matchTerms.begin(), matchTerms.end());
+}
+
+
+void MetadataInfo_t::clear () {
+  params.clear();
+  isRef = false;
+  values.erase(values.begin(), values.end());
+  if (parent != NULL) {
+    delete parent;
+    parent = NULL;
+  }
+}
+
+MetadataInfo_t::MetadataInfo_t () {parent=NULL;clear();}
+
+// copy constructor
+MetadataInfo_t::MetadataInfo_t (const MetadataInfo_t &x) {
+  params = x.params;
+  isRef = x.isRef;
+  values = x.values;
+  if (x.parent == NULL) parent = NULL;
+  else {
+    parent = new MetadataInfo_t ();
+    *parent = *(x.parent);
+  }
+}
+
+MetadataInfo_t::~MetadataInfo_t () {
+  if (parent != NULL) {
+    delete parent;
+    parent = NULL;
+  }
+}
+
+MetadataInfo_t &MetadataInfo_t::operator=(const MetadataInfo_t &x) {
+  if (&x != this) {
+    params = x.params;
+    isRef = x.isRef;
+    values = x.values;
+    if (x.parent == NULL) parent = NULL;
+    else {
+      parent = new MetadataInfo_t ();
+      *parent = *(x.parent);
+    }
+  }
+  return *this;
+}
+
+void ResultDocInfo_t::clear () {
+  OID.clear ();
+  ranking = 0;
+  result_num = 0;
+  num_terms_matched = 0;
+  num_phrase_match = 0;
+  docFreq.erase(docFreq.begin(), docFreq.end());
+  metadata.erase(metadata.begin(), metadata.end());
+  classifier_metadata_type.erase(classifier_metadata_type.begin(), 
+				 classifier_metadata_type.end());
+  classifier_metadata_offset = 0;
+  
+}
+
+ResultDocInfo_t &ResultDocInfo_t::operator=(const ResultDocInfo_t &x) {
+  OID = x.OID; 
+  ranking = x.ranking;
+  result_num = x.result_num;
+  num_terms_matched = x.num_terms_matched;
+  num_phrase_match = x.num_phrase_match;
+  docFreq = x.docFreq; 
+  metadata = x.metadata;
+  return *this;
+}
+
+void FilterResponse_t::clear () {
+  error_message = g_EmptyText;
+  numDocs = 0;
+  isApprox = Exact;
+  termInfo.erase (termInfo.begin(), termInfo.end());
+  docInfo.erase (docInfo.begin(), docInfo.end());
+  stopwords.clear();
+}
+
+FilterResponse_t &FilterResponse_t::operator=(const FilterResponse_t &x) {
+  error_message = x.error_message;
+  numDocs = x.numDocs;
+  isApprox = x.isApprox;
+  termInfo = x.termInfo;
+  docInfo = x.docInfo;
+  stopwords = x.stopwords;
+  return *this;
+}
+
+void DocumentRequest_t::clear () {
+  OID.clear();
+  docType.clear();
+  docFormat.clear();
+}
+
+void DocumentResponse_t::clear () {
+  doc.clear();
+}
Index: /gsdl/trunk/runtime-src/src/colservr/comtypes.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/comtypes.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/comtypes.h	(revision 16571)
@@ -0,0 +1,378 @@
+/**********************************************************************
+ *
+ * comtypes.h -- 
+ * Copyright (C) 1999,2004  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef COMTYPES_H
+#define COMTYPES_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\vector>
+#  include <ospace\std\list>
+#  include <ospace\std\memory> // for pair
+#  include <ospace\std\map>
+#elif defined(GSDL_USE_STL_H)
+#  include <vector.h>
+#  include <list.h>
+#  include <memory.h> // for pair
+#  include <map.h>
+#else
+#  include <vector>
+#  include <list>
+#  include <memory> // for pair
+#  include <map>
+#endif
+
+
+enum comerror_t {noError, authenticationFailure, protocolError, 
+		 configurationError, systemProblem, syntaxError};
+text_t get_comerror_string (comerror_t err);
+
+
+// ShortColInfo ::= SEQUENCE {
+//   name GeneralString,
+//   host GeneralString,
+//   port INTEGER
+// }
+struct ShortColInfo_t {
+  void clear ();
+  ShortColInfo_t () {clear();}
+
+  text_t name;
+  text_t host;
+  int port;
+};
+
+// for collection metadata: metadata name -> lang -> value
+// for collection macros: macro name -> params -> value
+typedef map<text_t, text_tmap, lttext_t> collectionmeta_map; 
+
+#define CCSUniformSearchResultsFormatting 1
+
+#define SIcasefold 1
+#define SIstem 2
+#define SIaccentfold 4
+
+struct ColInfoResponse_t {
+  void clear ();
+  ColInfoResponse_t () {clear();} 
+  text_t get_collectionmeta(text_t name, text_t lang);
+  
+  ShortColInfo_t shortInfo;
+  bool useBook;	//whether we want to display the book
+  bool isPublic;
+  bool isBeta;
+  bool isSegmented;
+  bool isCollectGroup; // used to group a set of collections as one item on the home page
+  unsigned long buildDate;
+  text_tarray ccsCols;    // empty if collection does not use cross-collection searching
+  int ccsOptions; // uses CCS #defines from above
+  int stemIndexes; // uses SI #defines from above
+  text_tarray languages;
+  unsigned long numDocs;     // 0 if not known
+  unsigned long numSections; // 0 if not known
+  unsigned long numWords;    // 0 if not known
+  unsigned long numBytes;    // 0 if not known
+  collectionmeta_map  collectionmeta;
+  text_tmap      format;
+  collectionmeta_map	 collection_macros; // for collectionmacro config directive (> gsdl 2.53)
+  text_tmap      building;
+  text_t         httpdomain;      // GRB: could these two http items need removing
+  text_t         httpprefix;
+  text_t         receptionist;
+  text_t         buildType;           // 'mg' or 'mgpp' or 'lucene'
+  text_t         authenticate;      // 'document' or 'collection'
+  text_t         auth_group;          // 'mygroup' 'yourgroup'
+  text_tmap      public_documents;    // the acl to allow access to listed documents
+  text_tmap      private_documents;   // the acl to disallow access to listed documents
+  text_tmap      dynamic_classifiers;
+};
+
+
+// -- filter options which might be supported for the QueryFilter
+// --
+// -- onePerQuery StartResults   integer
+// -- onePerQuery EndResults     integer
+// -- onePerQuery QueryType      enumerated (boolean, ranked)
+// -- onePerTerm  Term           string ???
+// -- onePerTerm  Casefold       boolean
+// -- onePerTerm  Stem           boolean
+// -- onePerTerm  Index          enumerated
+// -- onePerTerm  Subcollection  enumerated
+// --
+// -- filter options which might be supported for the BrowseFilter
+// --
+// -- onePerQuery StartResults   integer
+// -- onePerQuery EndResults     integer
+// -- onePerQuery ParentNode     string ("" will return the browsing available)
+// --
+// -- The NullFilter always returns the set it was given, it doesn't have
+// -- any options
+
+// InfoFiltersResponse ::= SEQUENCE {
+//   filterNames StringSet
+// }
+struct InfoFiltersResponse_t {
+  void clear ();
+
+  text_tset filterNames;
+};
+
+// InfoFilterOptionsRequest ::= SEQUENCE {
+//   filterName GeneralString
+// }
+struct InfoFilterOptionsRequest_t {
+  void clear ();
+
+  text_t filterName;
+};
+
+// FilterOption ::= SEQUENCE {
+//   name         GeneralString,
+//   type         ENUMERATED {booleant(0), integert(1), enumeratedt(2), stringt(3)},
+//   repeatable   ENUMERATED {onePerQuery(0), onePerTerm(1), nPerTerm(2)},
+//   defaultValue GeneralString,
+//   -- the interpretation of the validValues depends on the type
+//   -- for boolean: the first value is the false value, the second is true value
+//   -- for integer: the first value is the minimum, the second the maximum
+//   -- for enumerated: all values a listed
+//   -- for string: this value is ignored
+//   validValues  StringSequence
+// }
+struct FilterOption_t {
+  void clear ();
+  void check_defaultValue ();
+  FilterOption_t () {clear();}
+
+  text_t name;
+
+  enum type_t {booleant=0, integert=1, enumeratedt=2, stringt=3};
+  type_t type;
+
+  enum repeatable_t {onePerQuery=0, onePerTerm=1, nPerTerm=2};
+  repeatable_t repeatable;
+
+  text_t defaultValue;
+  text_tarray validValues;
+};
+
+bool operator==(const FilterOption_t &x, const FilterOption_t &y);
+bool operator<(const FilterOption_t &x, const FilterOption_t &y);
+
+
+typedef map<text_t, FilterOption_t, lttext_t> FilterOption_tmap;
+
+
+// InfoFilterOptionsResponse ::= SEQUENCE {
+//   filterOptions SET OF FilterOption
+// }
+struct InfoFilterOptionsResponse_t {
+  void clear ();
+
+  FilterOption_tmap filterOptions;
+};
+
+
+// OptionValue ::= SEQUENCE {
+//   name  GeneralString,
+//   value GeneralString
+// }
+struct OptionValue_t {
+  void clear ();
+
+  text_t name;
+  text_t value;
+};
+
+typedef vector<OptionValue_t> OptionValue_tarray;
+
+
+// -- Terms are presented in the same order that they are requested,
+// -- any information relating to the terms is in reference to the
+// -- index specified for that term.
+//
+// FilterRequest ::= SEQUENCE {
+//   filterName          [0] GeneralString,
+//   filterOptions       [1] IMPLICIT SEQUENCE OF OptionValue,
+//   docSet              [2] IMPLICIT StringSequence, -- the OID "" represents everything
+//   filterResultOptions [3] IMPLICIT BIT STRING {termFreq(0), matchTerms(1), OID(2), 
+//                                                subCol(3), ranking(4), docFreq(5), 
+//                                                metadata(6)}
+// 
+//   -- the next set of options are for the metadata request, 
+//   -- they can be left blank if metadata is not wanted
+//   requestParams       [4] IMPLICIT GeneralString, -- used to negotiate the metadata content
+//   refParams           [5] IMPLICIT GeneralString, -- used to decide whether to return a 
+//                                                   -- reference to the data or the actual data
+//   fields              [6] IMPLICIT StringSet
+//   getParents          [7] IMPLICIT BOOLEAN        -- gets metadata of all parents too
+// }
+#define FRtermFreq   1
+#define FRmatchTerms 2
+#define FROID        4
+#define FRsubCol     8
+#define FRranking    16
+#define FRdocFreq    32
+#define FRmetadata   64
+// used to indicate a full text browse query for mgpp
+#define FRfullTextBrowse  128
+
+struct FilterRequest_t {
+  void clear ();
+  FilterRequest_t () {clear();}
+
+  text_t filterName;
+  text_t filterLang; // non empty if we want info to be retrived in language specific
+  OptionValue_tarray filterOptions;
+  text_tarray docSet;        // empty if not used
+  int filterResultOptions; // use the FR* defines above
+
+  text_t requestParams; // empty if not used
+  text_t refParams;     // empty if not used
+  text_tset fields;   // empty if not used
+  bool getParents;      // defaults to false
+};
+
+
+// TermInfo ::= SEQUENCE {
+//   term       [0] GeneralString,
+//   freq       [1] IMPLICIT INTEGER,       -- 0 if not requested
+//   matchTerms [2] IMPLICIT StringSequence -- empty if not requested
+// }
+struct TermInfo_t {
+  void clear ();
+  TermInfo_t () {clear();}
+
+  text_t term;
+  int freq; // 0 if not requested
+  text_tarray matchTerms; // empty if not requested
+};
+
+typedef vector<TermInfo_t> TermInfo_tarray;
+
+
+// MetadataInfo ::= SEQUENCE {
+//   params  [0] IMPLICIT GeneralString,
+//   isRef   [1] IMPLICIT BOOLEAN,
+//   values  [3] IMPLICIT SEQUENCE OF GeneralString,
+//   name    [4] IMPLICIT GeneralString
+// }
+struct MetadataInfo_t {
+  text_t params;
+  bool isRef;
+  text_tarray values;
+  MetadataInfo_t *parent;
+
+  void clear ();
+  MetadataInfo_t ();
+  MetadataInfo_t (const MetadataInfo_t &x); // copy constructor
+  ~MetadataInfo_t ();
+  MetadataInfo_t &operator=(const MetadataInfo_t &x);
+};
+
+typedef map<text_t, MetadataInfo_t, lttext_t> MetadataInfo_tmap;
+
+// ResultDocInfo ::= SEQUENCE {
+//   OID      [0] IMPLICIT GeneralString,
+//   ranking  [1] IMPLICIT INTEGER,             -- 0 if not requested, range 0-10000
+//   docFreq  [2] IMPLICIT SEQUENCE OF INTEGER, -- empty if not requested
+//   metadata [3] IMPLICIT SEQUENCE OF MetadataInfo, -- no longer a SEQUENCE (SET maybe??)
+//   classifier_metadata_type   [4] IMPLICIT GeneralString,       -- empty if not requested
+//   classifier_metadata_offset [5] IMPLICIT INTEGER,             -- 0 if not requested
+// }
+struct ResultDocInfo_t {
+  void clear ();
+  ResultDocInfo_t () {clear();}
+
+  text_t OID;
+  int result_num;          // place in results list
+  int ranking;             // 0 if not requested (real ranking*10000)
+  int num_terms_matched;   // not available on all versions of mg
+  int num_phrase_match;    // not available on all versions of mg
+  vector<int> docFreq;           // empty if not requested
+  MetadataInfo_tmap metadata;    // empty if not requested
+  text_t classifier_metadata_type;        // empty if not requested
+  int    classifier_metadata_offset;      // 0 if not requested
+  ResultDocInfo_t &operator=(const ResultDocInfo_t &x);
+};
+
+typedef vector<ResultDocInfo_t> ResultDocInfo_tarray;
+
+
+// FilterResponse ::= SEQUENCE {
+//   numDocs   [0] IMPLICIT INTEGER,
+//   isApprox  [1] ENUMERATED {Exact(0), Approximate(1), MoreThan(2)}, -- whether numDocs is approximate
+//   termInfo  [2] IMPLICIT SEQUENCE OF TermInfo,                      -- empty if not required
+//   docInfo   [3] IMPLICIT SEQUENCE OF ResultDocInfo                  -- empty if not required
+// }
+
+enum isapprox {Exact=0, Approximate=1, MoreThan=2};
+
+struct FilterResponse_t {
+  void clear ();
+  FilterResponse_t () {clear();}
+
+  text_t error_message;  // Currently only used by Lucene
+  int numDocs;
+  isapprox isApprox;
+  TermInfo_tarray termInfo; // empty if not requested
+  ResultDocInfo_tarray docInfo; // empty if not requested
+  text_tset stopwords;
+
+  FilterResponse_t &operator=(const FilterResponse_t &x);
+};
+
+
+// DocumentRequest ::= SEQUENCE {
+//   OID       GeneralString,
+//   docType   GeneralString,
+//   docFormat GeneralString
+// }
+struct DocumentRequest_t {
+  void clear ();
+  DocumentRequest_t () {clear();}
+
+  text_t OID;
+  text_t docType;
+  text_t docFormat;
+};
+
+
+// DocumentResponse ::= SEQUENCE {
+//   doc OCTET STRING
+// }
+
+struct DocumentResponse_t {
+  void clear ();
+  DocumentResponse_t () {clear();}
+
+  text_t doc;
+};
+
+
+#endif
+
Index: /gsdl/trunk/runtime-src/src/colservr/expat_document.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/expat_document.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/expat_document.cpp	(revision 16571)
@@ -0,0 +1,101 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <expat.h>
+#include "gsdlunicode.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+using namespace std;
+#endif
+
+#include "queryinfo.h"
+
+#include "expat_document.h"
+
+#include "text_t.h"
+#include "fileutil.h"
+#include "expat_resultset.h"
+
+struct resultpack {
+  text_t *current_text;
+  text_t *section_num;
+  text_t *section_level;
+  bool store_text;
+};
+
+static void XMLCALL 
+startElement(void *userData, const char *name, const char **attributes)
+{
+  resultpack * rpack_ptr = (resultpack*)userData;
+  text_t element_name = (char*)name;
+  if (element_name == *(rpack_ptr->section_level)) {
+    text_t id_att = (char *)get_attribute(attributes,"gs2:id");
+    if (id_att == *(rpack_ptr->section_num)) {
+      rpack_ptr->store_text = true;
+    }
+    
+  }
+}
+
+static void XMLCALL
+endElement(void *userData, const char *name)
+{
+  resultpack * rpack_ptr = (resultpack*)userData;
+  text_t element_name = (char*)name;
+  if (element_name == *(rpack_ptr->section_level)) {
+    if (rpack_ptr->store_text == true) {
+      // we have finished now, can we quit this??
+      rpack_ptr->store_text = false;
+    }
+  }
+  
+}
+
+static void XMLCALL
+characterData(void *userData, const char * text, int len) {
+  resultpack * rpack_ptr = (resultpack*)userData;
+  if  (rpack_ptr->store_text) {
+    rpack_ptr->current_text->appendcarr(text, len);
+  }
+}
+
+
+int expat_document(const text_t &filename, const text_t &sec_level, const text_t &sec_num, text_t & doc_content)
+{
+  text_t current_text;
+  current_text.clear();
+  text_t section_num = sec_num;
+  text_t section_level = sec_level;
+
+  resultpack rpack = { &current_text, &section_num, &section_level, false};
+  //cerr << "sec num = "<<sec_num<<", sec level="<<sec_level<<", filename="<<filename<<endl;
+  text_t doc_text;
+  read_file(filename, doc_text);
+
+  char* c_doc_text = doc_text.getcstr();
+  XML_Parser parser = XML_ParserCreate(NULL);
+  
+  XML_SetUserData(parser, &rpack);
+  XML_SetElementHandler(parser, startElement, endElement);
+  XML_SetCharacterDataHandler(parser, characterData);
+  int return_status = 0;
+  const int parse_status 
+    = XML_Parse(parser, c_doc_text, strlen(c_doc_text), XML_TRUE);
+
+  if (parse_status == XML_STATUS_ERROR) {
+    cerr << "Error: " << XML_ErrorString(XML_GetErrorCode(parser)) << " at line " << XML_GetCurrentLineNumber(parser) << endl;
+    return_status = 1;
+  }
+  
+  XML_ParserFree(parser);
+  free(c_doc_text);
+  doc_content = to_uni(current_text);  // Vital for non-ASCII documents
+  return return_status;
+}
+
+
Index: /gsdl/trunk/runtime-src/src/colservr/expat_document.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/expat_document.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/expat_document.h	(revision 16571)
@@ -0,0 +1,9 @@
+#ifndef gs_expat_document_h
+#define gs_expat_document_h
+
+class text_t;
+
+int expat_document(const text_t &filename, const text_t & section_level,
+		   const text_t &section_num, text_t & doc_content);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/expat_resultset.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/expat_resultset.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/expat_resultset.cpp	(revision 16571)
@@ -0,0 +1,147 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <expat.h>
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+using namespace std;
+#endif
+
+#include "text_t.h"
+#include "queryinfo.h"
+#include "gsdlunicode.h"
+
+struct queryresultpack {
+  queryresultsclass* queryresult_ptr;
+  int match_count;
+};
+
+char* get_attribute(const char** attr, char* att_name)
+{
+  char* att_val = NULL;
+
+  for (int i = 0; attr[i]; i += 2) {
+    if (strcmp(attr[i],att_name)==0) {
+      att_val = strdup(attr[i+1]);
+    }
+  }
+
+  return att_val;
+}
+
+static void XMLCALL 
+startElement(void *userData, const char *name, const char **attributes)
+{
+  queryresultpack* qrpack_ptr = (queryresultpack*)userData;
+  queryresultsclass* queryresult_ptr = qrpack_ptr->queryresult_ptr;
+
+  text_t element_name = (char*)name;
+
+  if (element_name == "ResultSet") {
+    char* cached_attribute_str = get_attribute(attributes, "cached");
+    if (cached_attribute_str != NULL) {
+      cerr << "Cached: " << cached_attribute_str << endl;
+    }
+  }
+
+  if (element_name == "Error") {
+    char* error_type_str = get_attribute(attributes, "type");
+    queryresult_ptr->error_message = error_type_str;
+    if ((text_t) error_type_str == "PARSE_EXCEPTION") {
+      queryresult_ptr->syntax_error = true;
+    }
+  }
+
+  if (element_name == "Term") {
+    char* term_value_str = get_attribute(attributes, "value");
+    char* term_frequency_str = get_attribute(attributes, "freq");
+
+    termfreqclass termfreqobj;
+    termfreqobj.termstr = to_uni(term_value_str);
+
+    termfreqobj.termfreq = atoi(term_frequency_str);
+    queryresult_ptr->orgterms.push_back(termfreqobj);
+  }
+
+  if (element_name == "StopWord") {
+    char* stop_word_value_str = get_attribute(attributes, "value");
+    queryresult_ptr->stopwords.insert((text_t) stop_word_value_str);
+  }
+
+  if (element_name=="MatchingDocsInfo") {
+    char* num_match_docs_str = get_attribute(attributes,"num");
+    if (num_match_docs_str != NULL) {
+      int num_match_docs = atoi(num_match_docs_str);
+
+      queryresult_ptr->docs_matched = num_match_docs;
+      free(num_match_docs_str);
+    }
+    else {
+      queryresult_ptr->docs_matched = 0;
+    }
+  }
+
+
+  if (element_name=="Match") {
+
+    char* id = get_attribute(attributes,"id");
+    if (id!=NULL) {
+      int id_num = atoi(id);
+    
+      docresultclass doc;
+      doc.clear();
+      doc.docnum = id_num;
+      doc.docweight = qrpack_ptr->match_count;
+      queryresult_ptr->docs.docset[doc.docnum] = doc;
+      queryresult_ptr->docs.docorder.push_back(doc.docnum);
+      ++qrpack_ptr->match_count;
+
+      free(id);
+    }
+    
+  }
+}
+
+static void XMLCALL
+endElement(void *userData, const char *name)
+{
+  // no need to do anything
+}
+
+
+
+
+int expat_resultset(text_t& xml_text, queryresultsclass& queryresult)
+{
+  queryresult.clear();
+  queryresultpack qrpack = { &queryresult, 0 };
+
+  char * xml_text_cstr = xml_text.getcstr();
+  
+  XML_Parser parser = XML_ParserCreate(NULL);
+  
+  XML_SetUserData(parser, &qrpack);
+  XML_SetElementHandler(parser, startElement, endElement);
+  
+  int return_status = 0;
+  const int parse_status 
+    = XML_Parse(parser, xml_text_cstr, strlen(xml_text_cstr), XML_TRUE);
+  
+  if (parse_status == XML_STATUS_ERROR) {
+    fprintf(stderr,
+	    "%s at line %d\n",
+	    XML_ErrorString(XML_GetErrorCode(parser)),
+	    XML_GetCurrentLineNumber(parser));
+    return_status = 1;
+  }
+  
+  XML_ParserFree(parser);
+  free(xml_text_cstr);
+  
+  return return_status;
+}
Index: /gsdl/trunk/runtime-src/src/colservr/expat_resultset.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/expat_resultset.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/expat_resultset.h	(revision 16571)
@@ -0,0 +1,11 @@
+#ifndef gs_expat_resultset_h
+#define gs_expat_resultset_h
+
+class text_t;
+class queryresultsclass;
+
+char* get_attribute(const char** attr, char* att_name);
+int expat_resultset(text_t& xml_text, queryresultsclass& queryresult);
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/filter.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/filter.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/filter.cpp	(revision 16571)
@@ -0,0 +1,338 @@
+/**********************************************************************
+ *
+ * filter.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "filter.h"
+#include "fileutil.h"
+#include <assert.h>
+
+#include <iostream>
+using namespace std;
+
+
+// default constructor does nothing
+filterclass::filterclass () {
+}
+
+// default destructor does nothing
+filterclass::~filterclass () {
+}
+
+// configure should be called once for each configuration line
+// default configures the default filter options
+void filterclass::configure (const text_t &key, const text_tarray &cfgline) {
+  if (cfgline.size() >= 1) {
+    const text_t &value = cfgline[0];
+
+    if (key == "collection") collection = value;
+    else if (key == "collectdir") collectdir = value;
+    else if (key == "gsdlhome") gsdlhome = value;
+    else if (key == "collecthome") collecthome = value;
+    else if (key == "gdbmhome") dbhome = value;
+    else if ((key == "filteroptdefault") && (cfgline.size() == 2)) {
+      // see if this filter has an option with this name
+      FilterOption_tmap::iterator thisfilteroption = 
+	filterOptions.find(cfgline[0]);
+      if (thisfilteroption != filterOptions.end())
+	(*thisfilteroption).second.defaultValue = cfgline[1];
+    }
+  }
+}
+
+text_t filterclass::resolve_db_filename(const text_t& idx,
+					const text_t& file_ext)
+{
+  text_t resolved_filename;
+
+  if (gsdlhome==dbhome) {
+    // dbhome has defaulted to gsdlhome which we take to means the 
+    // database has been specifically moved out of gsdlhome area.
+    // => it should be whereever collecthome is set to
+    resolved_filename = filename_cat(collecthome, collection, "index", "text", idx);
+  }
+  else {
+    // dbhome is explicitly set to something other than gsdlhome
+    // => use dbhome
+    resolved_filename = filename_cat(dbhome, "collect", collection, "index", "text", idx);
+  }
+
+  resolved_filename += file_ext;
+
+  return resolved_filename;
+}
+
+
+// init should be called after all the configuration is done but
+// before any other methods are called
+// default checks all the filter option defaults
+bool filterclass::init (ostream &/*logout*/) {
+  // check all the filter defaults
+  FilterOption_tmap::iterator filteroption_here = filterOptions.begin();
+  FilterOption_tmap::iterator filteroption_end = filterOptions.end();
+  while (filteroption_here != filteroption_end) {
+    (*filteroption_here).second.check_defaultValue ();
+    
+    ++filteroption_here;
+  }
+
+  if (collecthome.empty()) collecthome = filename_cat(gsdlhome,"collect");
+  if (dbhome.empty()) dbhome = gsdlhome;
+  
+  // get the collection directory name
+  if (collectdir.empty()) {
+    collectdir = filename_cat (collecthome, collection);
+  }
+  
+  return true;
+}
+
+// returns the name of this filter
+// default returns "NullFilter"
+text_t filterclass::get_filter_name () {
+  return "NullFilter";
+}
+
+// returns the current filter options
+void filterclass::get_filteroptions (InfoFilterOptionsResponse_t &response,
+				     comerror_t &err, ostream &/*logout*/) {
+  response.clear();
+  response.filterOptions = filterOptions;
+  err = noError;
+}
+
+// default returns nothing
+void filterclass::filter (const FilterRequest_t &request,
+			  FilterResponse_t &response,
+			  comerror_t &err, ostream &/*logout*/) {
+  ResultDocInfo_t resultdoc;
+
+  response.clear();
+
+  if ((request.filterResultOptions & FROID) ||
+      (request.filterResultOptions & FRmetadata)) {
+    // copy the OIDs from the request to the response
+    text_tarray::const_iterator here = request.docSet.begin();
+    text_tarray::const_iterator end = request.docSet.end();
+    while (here != end) {
+      resultdoc.OID = (*here);
+      response.docInfo.push_back(resultdoc);
+
+      ++here;
+    }
+  }
+
+  response.numDocs = response.docInfo.size();
+  response.isApprox = Exact;
+  err = noError;
+}
+
+
+bool operator==(const filterptr &x, const filterptr &y) {
+  return (x.f == y.f);
+}
+
+bool operator<(const filterptr &x, const filterptr &y) {
+  return (x.f < y.f);
+}
+
+
+// thefilter remains the property of the calling code but
+// should not be deleted until it is removed from this list.
+void filtermapclass::addfilter (filterclass *thefilter) {
+  // can't add a null filter
+  assert (thefilter != NULL);
+  if (thefilter == NULL) return;
+  
+  // can't add an filter with no name
+  assert (!(thefilter->get_filter_name()).empty());
+  if ((thefilter->get_filter_name()).empty()) return;
+
+  filterptr fptr;
+  fptr.f = thefilter;
+  filterptrs[thefilter->get_filter_name()] = fptr;
+}
+
+// getfilter will return NULL if the filter could not be found
+filterclass *filtermapclass::getfilter (const text_t &key) {
+  // can't find an filter with no name
+  assert (!key.empty());
+  if (key.empty()) return NULL;
+
+  iterator here = filterptrs.find (key);
+  if (here == filterptrs.end()) return NULL;
+  
+  return (*here).second.f;
+}
+
+
+
+
+// some useful functions for dealing with document sets
+
+// returns -1 if t1 is a child of t2
+// returns 0  if t1 and t2 are not parent-child related
+// returns 1  if t1 is a parent of t2
+int child_compare (const text_t &t1, const text_t &t2) {
+  text_t::const_iterator t1_here = t1.begin();
+  text_t::const_iterator t1_end = t1.end();
+  text_t::const_iterator t2_here = t2.begin();
+  text_t::const_iterator t2_end = t2.end();
+
+  while ((t1_here != t1_end) && (t2_here != t2_end)) {
+    if (*t1_here != *t2_here) return 0; // unrelated
+    ++t1_here;
+    ++t2_here;
+  }
+
+  if ((t1_here == t1_end) && (t2_here == t2_end)) return 0; // equal
+  if (t1_here != t1_end) {
+    if (*t1_here == '.') return -1; // t1 is child
+    else return 0; // unrelated
+  }
+
+  if (t2_here != t2_end) {
+    if (*t2_here == '.') return 1; // t2 is child
+    else return 0; // unrelated
+  }
+
+  return 0; // shouldn't get here...
+}
+
+// intersect places the result in set1
+void intersect (text_tset &set1, const text_tset &set2) {
+  text_tset resultset;
+  int childcomp = 0;
+
+  text_tset::const_iterator set1_here = set1.begin();
+  text_tset::const_iterator set1_end = set1.end();
+  text_tset::const_iterator set2_here = set2.begin();
+  text_tset::const_iterator set2_end = set2.end();
+  while ((set1_here != set1_end) && (set2_here != set2_end)) {
+    if (*set1_here == *set2_here) {
+      // equal
+      resultset.insert (*set1_here);
+      ++set1_here;
+      ++set2_here;
+
+    } else if ((childcomp=child_compare(*set1_here, *set2_here)) != 0) {
+      if (childcomp < 0) {
+	// set1_here is child
+	resultset.insert (*set1_here);
+	++set1_here;
+      } else {
+	// set2_here is child
+	resultset.insert (*set2_here);
+	++set2_here;
+      }
+
+    } else if (*set1_here < *set2_here) {
+      // set1 is less
+      ++set1_here;
+
+    } else {
+      // set2 is less
+      ++set2_here;
+    }
+  }
+
+  set1 = resultset;
+}
+
+void intersect (text_tarray &set1, const text_tset &set2) {
+  text_tarray resultset;
+
+  text_tarray::const_iterator set1_here = set1.begin();
+  text_tarray::const_iterator set1_end = set1.end();
+
+  while (set1_here != set1_end) {
+    if (in_set (set2, *set1_here))
+      resultset.push_back (*set1_here);
+    ++set1_here;
+  }
+  set1 = resultset;
+}
+
+void intersect (text_tarray &set1, const text_tarray &set2) {
+  text_tarray resultset;
+
+  text_tarray::const_iterator set1_here = set1.begin();
+  text_tarray::const_iterator set1_end = set1.end();
+
+  while (set1_here != set1_end) {
+    if (in_set (set2, *set1_here))
+      resultset.push_back (*set1_here);
+    ++set1_here;
+  }
+  set1 = resultset;
+}
+
+// tests to see if el is in set
+bool in_set (const text_tset &set1, const text_t &el) {
+  text_t::const_iterator here = el.begin();
+  text_t::const_iterator end = el.end();
+  text_t tryel, tryel_add;
+  bool first = true;
+
+  // the element is in the set if any of its parents are
+  // in the set
+  do {
+    // get next possible element to try
+    here = getdelimitstr (here, end, '.', tryel_add);
+    if (!first) tryel += ".";
+    first = false;
+    tryel += tryel_add;
+
+    // see if this element is in the set
+    if (set1.find(tryel) != set1.end()) return true;
+  } while (here != end);
+
+  return false;
+}
+
+bool in_set (const text_tarray &set1, const text_t &el) {
+  text_t::const_iterator here = el.begin();
+  text_t::const_iterator end = el.end();
+  text_t tryel, tryel_add;
+  bool first = true;
+
+  // the element is in the set if any of its parents are
+  // in the set
+  do {
+    // get next possible element to try
+    here = getdelimitstr (here, end, '.', tryel_add);
+    if (!first) tryel += ".";
+    first = false;
+    tryel += tryel_add;
+
+    // see if this element is in the set
+    text_tarray::const_iterator h = set1.begin();
+    text_tarray::const_iterator e = set1.end();
+    while (h != e) {
+      if (*h == tryel) return true;
+      ++h;
+    }
+  } while (here != end);
+
+  return false;
+}
Index: /gsdl/trunk/runtime-src/src/colservr/filter.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/filter.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/filter.h	(revision 16571)
@@ -0,0 +1,147 @@
+/**********************************************************************
+ *
+ * filter.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef FILTER_H
+#define FILTER_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "comtypes.h"
+
+
+class filterclass {
+protected:
+  text_t gsdlhome;
+  text_t collecthome;
+  text_t dbhome;
+  text_t collection;
+  text_t collectdir;
+
+  FilterOption_tmap filterOptions;
+
+public:
+  filterclass ();
+  virtual ~filterclass ();
+
+  // configure should be called once for each configuration line
+  // default configures the default filter options
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+
+  // init should be called after all the configuration is done but
+  // before any other methods are called
+  // default checks all the filter option defaults
+  virtual bool init (ostream &logout);
+
+  // returns the name of this filter
+  virtual text_t get_filter_name ();
+
+  // returns the current filter options
+  virtual void get_filteroptions (InfoFilterOptionsResponse_t &response,
+				  comerror_t &err, ostream &logout);
+
+  virtual void filter (const FilterRequest_t &request,
+		       FilterResponse_t &response,
+		       comerror_t &err, ostream &logout);
+
+ protected:
+  text_t resolve_db_filename(const text_t& idx,const text_t& file_ext);
+
+
+};
+
+
+// The filterptr class does not 'own' the filter. The 
+// filter should be deleted by the code which created it.
+class filterptr {
+public:
+  filterclass *f;
+
+  filterptr () {f=NULL;}
+  ~filterptr () {}
+};
+
+bool operator==(const filterptr &x, const filterptr &y);
+bool operator<(const filterptr &x, const filterptr &y);
+
+
+typedef map<text_t, filterptr, lttext_t> filterptrmap;
+
+// contains a list of filters indexed by their name
+class filtermapclass {
+protected:
+  filterptrmap filterptrs;
+
+public:
+  // type support for filterptrmap
+  typedef filterptrmap::iterator iterator;
+  typedef filterptrmap::const_iterator const_iterator;
+  typedef filterptrmap::reference reference;
+  typedef filterptrmap::const_reference const_reference;
+  typedef filterptrmap::size_type size_type;
+
+  typedef filterptrmap::difference_type difference_type;
+  typedef filterptrmap::const_reverse_iterator const_reverse_iterator;
+  typedef filterptrmap::reverse_iterator reverse_iterator;
+  
+  // basic container support
+  iterator begin () {return filterptrs.begin();}
+  const_iterator begin () const {return filterptrs.begin();}
+  iterator end () {return filterptrs.end();}
+  const_iterator end () const {return filterptrs.end();}
+
+  void erase(iterator pos) {filterptrs.erase(pos);}
+  void erase(iterator first, iterator last) {filterptrs.erase(first, last);}
+  filtermapclass &operator=(const filtermapclass &x) {filterptrs=x.filterptrs;return *this;}
+
+  bool empty () const {return filterptrs.empty();}
+  size_type size() const {return filterptrs.size();}
+
+
+  // added functionality
+  void clear () {filterptrs.erase(filterptrs.begin(),filterptrs.end());}
+
+  // thefilter remains the property of the calling code but
+  // should not be deleted until it is removed from this list.
+  void addfilter (filterclass *thefilter);
+
+  // getfilter will return NULL if the filter could not be found
+  filterclass *getfilter (const text_t &key);
+};
+
+
+
+// some useful functions for dealing with document sets
+
+// intersect places the result in set1
+void intersect (text_tset &set1, const text_tset &set2);
+void intersect (text_tarray &set1, const text_tset &set2);
+void intersect (text_tarray &set1, const text_tarray &set2);
+
+// tests to see if el is in set
+bool in_set (const text_tset &set1, const text_t &el);
+bool in_set (const text_tarray &set1, const text_t &el);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/lucenequeryfilter.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/lucenequeryfilter.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/lucenequeryfilter.cpp	(revision 16571)
@@ -0,0 +1,405 @@
+/**********************************************************************
+ *
+ * lucenequeryfilter.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "lucenequeryfilter.h"
+#include "fileutil.h"
+#include "lucenesearch.h"
+
+/////////////////////////////////
+// functions for queryfilterclass
+/////////////////////////////////
+
+
+lucenequeryfilterclass::lucenequeryfilterclass () 
+  : queryfilterclass() {
+
+  
+  FilterOption_t filtopt;
+  
+  // -- onePerTerm  Level          enumerated
+  // likely to be Doc, Sec, Para, but we dont assume anything now
+  filtopt.clear();
+  filtopt.name = "Level";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filterOptions["Level"] = filtopt;
+
+  // --  IndexField, enumerated, used to list available fields
+  filtopt.clear();
+  filtopt.name = "IndexField";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["IndexField"] = filtopt;
+
+}
+
+lucenequeryfilterclass::~lucenequeryfilterclass () {
+}
+
+
+//whether a query is a full text browse
+bool lucenequeryfilterclass::full_text_browse (int filterRequestOptions) {
+  return (filterRequestOptions & FRfullTextBrowse);
+}
+
+void lucenequeryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
+  queryfilterclass::configure(key, cfgline);
+
+  if (key == "indexfieldmap") {
+    indexfieldmap.importmap (cfgline);
+    
+    // update the list of indexes in the filter information
+    text_tarray options;
+    indexfieldmap.gettoarray (options);
+
+    text_tarray::const_iterator here = options.begin();
+    text_tarray::const_iterator end = options.end();
+    bool start = true;
+    while (here !=end) {
+      if (!(*here).empty()) {
+	filterOptions["IndexField"].validValues.push_back(*here);
+	if (start) {
+	  filterOptions["IndexField"].defaultValue = *here;
+	  start = false;
+	}
+      }
+      ++here;
+    }
+  } else if (key == "indexlevels") {
+    text_tarray::const_iterator here = cfgline.begin();
+    text_tarray::const_iterator end = cfgline.end();
+    bool first=true;
+    while (here != end) {
+      if (!(*here).empty()) {
+	if (first) {
+	  first = false;
+	  // the default is the first value
+	  filterOptions["Level"].defaultValue = *here;
+	}
+	filterOptions["Level"].validValues.push_back(*here);
+      }
+      ++here;
+    }
+  } else if (key == "textlevel") {
+      ((lucenesearchclass *)textsearchptr)->set_text_level(cfgline[0]);
+  }
+  
+}
+
+
+void lucenequeryfilterclass::filter(const FilterRequest_t &request,
+				  FilterResponse_t &response,
+				  comerror_t &err, ostream &logout) {  
+
+  outconvertclass text_t2ascii;
+
+  response.clear ();
+  err = noError;
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: queryfilter contains a null dbclass\n\n";
+    err = configurationError;
+    return;
+  }
+  if (textsearchptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: queryfilter contains a null textsearchclass (lucene)\n\n";
+    err = configurationError;
+    return;
+  }
+  if (full_text_browse(request.filterResultOptions)) {
+    browsefilter(request, response, err, logout);
+    return;
+  }
+  // open the database
+  db_ptr->setlogout(&logout);
+  if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {
+    // most likely a system problem (we have already checked that the database exists)
+    logout << text_t2ascii
+	   << "system problem: open on database \"" << db_filename << "\" failed\n\n";
+    err = systemProblem;
+    return;
+  }
+
+
+  // get the query parameters
+  int startresults, endresults;
+  text_t phrasematch; // not used here any more
+  vector<queryparamclass> queryfilterparams;
+  parse_query_params (request, queryfilterparams, startresults, 
+		      endresults, phrasematch, logout);  
+ 
+   
+  // do query
+  queryresultsclass queryresults;
+  do_multi_query (request, queryfilterparams, queryresults, err, logout);
+  response.error_message = queryresults.error_message;
+  if (err != noError) return;
+
+  // assemble document results
+  if (need_matching_docs (request.filterResultOptions)) {
+    
+    int resultnum = 1;
+    ResultDocInfo_t resultdoc;
+    text_t trans_OID;
+    vector<text_t>::iterator docorder_here = queryresults.docs.docorder.begin();
+    vector<text_t>::iterator docorder_end = queryresults.docs.docorder.end();
+
+    // Now handled by Lucene directly
+    //if (endresults == -1) endresults = MAXNUMDOCS;
+
+    while (docorder_here != docorder_end)
+      {
+        // Now handled by Lucene directly
+        //if (resultnum > endresults) break;
+      
+        // translate the document number
+        if (!translate(db_ptr, *docorder_here, trans_OID))
+          {
+            logout << text_t2ascii
+                   << "warning: could not translate lucene document number \""
+                   << *docorder_here << "\" to OID.\n\n";
+            
+          } 
+        else 
+          {
+            docresultmap::iterator docset_here = queryresults.docs.docset.find (*docorder_here);
+
+            // see if there is a result for this number,
+            // if it is in the request set (or the request set is empty)
+            if (docset_here != queryresults.docs.docset.end() && (request.docSet.empty() || in_set(request.docSet, trans_OID)))
+              {
+                // Now handled by Lucene directly
+                //if (resultnum >= startresults) {
+
+                // add this document
+                resultdoc.OID = trans_OID;
+                resultdoc.result_num = resultnum;
+                resultdoc.ranking = (int)((*docset_here).second.docweight * 10000.0 + 0.5);
+                
+                response.docInfo.push_back (resultdoc);
+                //}
+                ++resultnum;
+              }
+          } // else
+        
+        ++docorder_here;
+      }
+  } // if need matching docs
+  
+  // assemble the term results
+  if (need_term_info(request.filterResultOptions)) {
+    // note: the terms have already been sorted and uniqued - ?? have they??
+
+    TermInfo_t terminfo;
+    bool terms_first = true;
+
+    termfreqclassarray::iterator terms_here = queryresults.terms.begin();
+    termfreqclassarray::iterator terms_end = queryresults.terms.end();
+
+    while (terms_here != terms_end) {
+      terminfo.clear();
+      terminfo.term = (*terms_here).termstr;
+      terminfo.freq = (*terms_here).termfreq;
+      // lucene doesn't return any termvariants at this stage, 
+      // so make sure the original term is set
+      terminfo.matchTerms.push_back(terminfo.term);
+      
+      // this bit gets the matchTerms ie the equivalent (stem/casefold) terms
+      if (terms_first) {
+	text_tset::iterator termvariants_here = queryresults.termvariants.begin();
+	text_tset::iterator termvariants_end = queryresults.termvariants.end();
+	while (termvariants_here != termvariants_end) {
+	  terminfo.matchTerms.push_back (*termvariants_here);
+	  ++termvariants_here;
+	}
+      }
+      terms_first = false;
+      
+      response.termInfo.push_back (terminfo);
+
+      ++terms_here;
+    }
+
+    // add the stop words
+    text_tset::iterator stopwords_here = queryresults.stopwords.begin();
+    text_tset::iterator stopwords_end = queryresults.stopwords.end();
+    while (stopwords_here != stopwords_end) {
+      response.stopwords.insert(*stopwords_here);
+      ++stopwords_here;
+    }
+  }
+
+  db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+  response.numDocs = queryresults.docs_matched;
+  response.isApprox = queryresults.is_approx;
+}
+
+void lucenequeryfilterclass::browsefilter(const FilterRequest_t &request,
+					FilterResponse_t &response,
+					comerror_t &err, ostream &logout) {  
+
+  outconvertclass text_t2ascii;
+
+  // get the query parameters
+  int startresults, endresults;
+  text_t phrasematch; // not used here any more, just have it so can use
+                      // parse_query_params function
+  
+  vector<queryparamclass> queryfilterparams;
+  parse_query_params (request, queryfilterparams, startresults, 
+		      endresults, phrasematch, logout);  
+
+    vector<queryparamclass>::const_iterator query_here = queryfilterparams.begin();
+   
+  // do query
+  queryresultsclass queryresults;
+  queryresults.clear();
+  
+  int numDocs = endresults-startresults;
+  textsearchptr->setcollectdir (collectdir);
+
+  if (!((lucenesearchclass*)textsearchptr)->browse_search((*query_here), startresults, numDocs, queryresults)) {
+    // most likely a system problem
+    logout << text_t2ascii
+	   << "system problem: could not do full text browse with lucene for index \""
+	   << (*query_here).index << (*query_here).subcollection
+	   << (*query_here).language << "\".\n\n";
+    err = systemProblem;
+    return;
+  }
+
+  // assemble the term results
+  TermInfo_t terminfo;
+  
+  termfreqclassarray::iterator terms_here = queryresults.terms.begin();
+  termfreqclassarray::iterator terms_end = queryresults.terms.end();
+
+  while (terms_here != terms_end) {
+    terminfo.clear();
+    terminfo.term = (*terms_here).termstr;
+    terminfo.freq = (*terms_here).termfreq;
+    
+    response.termInfo.push_back (terminfo);
+
+    ++terms_here;
+  }
+  
+
+}
+
+// lucenesearchptr and db_ptr are assumed to be valid
+void lucenequeryfilterclass::do_multi_query (const FilterRequest_t &request,
+					   const vector<queryparamclass> &query_params,
+					   queryresultsclass &multiresults,
+					   comerror_t &err, ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  err = noError;
+  textsearchptr->setcollectdir (collectdir);
+  multiresults.clear();
+  
+  vector<queryparamclass>::const_iterator query_here = query_params.begin();
+  vector<queryparamclass>::const_iterator query_end = query_params.end();
+  while (query_here != query_end) {
+    queryresultsclass thisqueryresults;
+    if (!textsearchptr->search((*query_here), thisqueryresults)) {
+      // most likely a system problem
+      logout << text_t2ascii
+	     << "system problem: could not do search with lucene for index \""
+	     << (*query_here).index << (*query_here).level 
+	     << (*query_here).subcollection
+	     << (*query_here).language << "\".\n\n";
+      err = systemProblem;
+      return;
+    }
+
+    // check for syntax error
+    if (thisqueryresults.syntax_error==true) {
+      logout << text_t2ascii
+	     << "syntax problem: invalid query string \""
+	     << (*query_here).querystring<<"\".\n";
+      err = syntaxError;
+      return;
+    }
+    // combine the results
+    if (need_matching_docs (request.filterResultOptions)) {
+            
+      if (query_params.size() == 1) {
+	multiresults.error_message = thisqueryresults.error_message;
+	multiresults.docs = thisqueryresults.docs; // just one set of results
+	multiresults.docs_matched = thisqueryresults.docs_matched;
+	multiresults.is_approx = thisqueryresults.is_approx;
+	
+      } else {
+	if ((*query_here).combinequery == "and") {
+	  multiresults.docs.combine_and (thisqueryresults.docs);
+	} else if ((*query_here).combinequery == "or") {
+	  multiresults.docs.combine_or (thisqueryresults.docs);
+	} else if ((*query_here).combinequery == "not") {
+	  multiresults.docs.combine_not (thisqueryresults.docs);
+	}
+	multiresults.docs_matched = multiresults.docs.docset.size();
+	multiresults.is_approx = Exact;
+      }
+    }
+
+    // combine the term information 
+    if (need_term_info (request.filterResultOptions)) {
+      // append the terms
+      multiresults.orgterms.insert(multiresults.orgterms.end(),
+				   thisqueryresults.orgterms.begin(),
+				   thisqueryresults.orgterms.end());
+
+      
+      // add the term variants - 
+      text_tset::iterator termvar_here = thisqueryresults.termvariants.begin();
+      text_tset::iterator termvar_end = thisqueryresults.termvariants.end();
+      while (termvar_here != termvar_end) {
+	multiresults.termvariants.insert(*termvar_here);
+	++termvar_here;
+      }
+
+      // add the stop words
+      text_tset::iterator stopwords_here = thisqueryresults.stopwords.begin();
+      text_tset::iterator stopwords_end = thisqueryresults.stopwords.end();
+      while (stopwords_here != stopwords_end) {
+	multiresults.stopwords.insert(*stopwords_here);
+	++stopwords_here;
+      }
+    }
+   
+    ++query_here;
+  }
+
+  // sort and unique the query terms
+  multiresults.sortuniqqueryterms ();
+}
+
+
+
Index: /gsdl/trunk/runtime-src/src/colservr/lucenequeryfilter.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/lucenequeryfilter.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/lucenequeryfilter.h	(revision 16571)
@@ -0,0 +1,67 @@
+/**********************************************************************
+ *
+ * lucenequeryfilter.h -- new queryfilter to use lucene 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+
+#ifndef LUCENEQUERYFILTER_H
+#define LUCENEQUERYFILTER_H
+
+#include "queryfilter.h"
+
+class lucenequeryfilterclass : public queryfilterclass {
+protected:
+
+  stringmap indexfieldmap;
+  bool full_text_browse (int filterRequestOptions);
+
+  // mgsearchptr and db_ptr are assumed to be valid
+  void do_multi_query (const FilterRequest_t &request,
+		       const vector<queryparamclass> &query_params,
+		       queryresultsclass &multiresults,
+		       comerror_t &err, ostream &logout);
+
+
+public:
+  lucenequeryfilterclass ();
+  virtual ~lucenequeryfilterclass ();
+
+  void configure (const text_t &key, const text_tarray &cfgline);
+
+  void filter (const FilterRequest_t &request,
+		       FilterResponse_t &response,
+		       comerror_t &err, ostream &logout);
+  
+  void browsefilter(const FilterRequest_t &request,
+		    FilterResponse_t &response,
+		    comerror_t &err, ostream &logout);  
+
+
+};
+
+#endif
+
+
+
Index: /gsdl/trunk/runtime-src/src/colservr/lucenesearch.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/lucenesearch.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/lucenesearch.cpp	(revision 16571)
@@ -0,0 +1,242 @@
+/**********************************************************************
+ *
+ * lucenesearch.cpp -- 
+ * Copyright (C) 1999-2002  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+#endif
+
+#include <stdio.h>
+#include <time.h>
+
+#include "gsdlconf.h"
+#include "gsdltools.h"
+#include "lucenesearch.h"
+#include "fileutil.h"
+#include "queryinfo.h"
+#include "gsdlunicode.h"
+
+#include "expat_resultset.h"
+
+text_t lucenesearchclass::getindexsuffix(const queryparamclass &qp) {
+  text_t indexsuffix = "index";
+  // get the first char of the level to be the start of the index name
+  text_t suffix = substr(qp.level.begin(), qp.level.begin()+1);
+  lc(suffix);
+  text_t ind = qp.index;
+  text_t sub = qp.subcollection;
+  text_t lang = qp.language;
+   
+  // collection name not added for Lucene
+  indexsuffix = filename_cat(indexsuffix, suffix +ind + sub + lang);
+  return indexsuffix;
+
+}
+
+////////////////////
+// lucenesearch class //
+////////////////////
+
+lucenesearchclass::lucenesearchclass ()
+  : searchclass() {
+
+  textlevel = "Doc";
+}
+
+lucenesearchclass::~lucenesearchclass () 
+{
+  if (cache != NULL) 
+    {
+      delete cache;
+      cache = NULL;
+    }
+}
+
+void lucenesearchclass::set_text_level(const text_t &textlevel_arg)
+{
+  textlevel = textlevel_arg;
+}
+
+
+bool lucenesearchclass::search(const queryparamclass &queryparams, 
+			       queryresultsclass &queryresult) {
+ 
+#ifdef __WIN32__
+  char basepath[]="";
+#else
+  char basepath[] = "/";
+#endif
+ 
+  char *indexname = (filename_cat(collectdir, getindexsuffix(queryparams))).getcstr(); 
+
+  // set default stem method from values originally set on prefs page
+  int defaultStemMethod = 0;
+  if (queryparams.casefolding) {
+    defaultStemMethod |= 1;
+  }
+  if (queryparams.stemming) {
+    defaultStemMethod |= 2;
+  }
+
+  text_t utf8querystring = to_utf8(queryparams.querystring);
+
+  text_t escaped_utf8querystring = "";
+  text_t::const_iterator here = utf8querystring.begin();
+  while (here != utf8querystring.end()) {
+    if (*here == '"') escaped_utf8querystring.push_back('\\');
+    escaped_utf8querystring.push_back(*here);
+    ++here;
+  }
+
+  // Use this to skip lucene_query.pl and access GS2LuceneQuery directly (Java must be on path)
+  // text_t cmd = "java -classpath \"" + filename_cat(gsdlhome, "bin", "java", "LuceneWrapper.jar") + "\" org.greenstone.LuceneWrapper.GS2LuceneQuery ";
+  text_t cmd = "\"" + filename_cat(gsdlhome, "bin", "script", "lucene_query.pl") + "\"";
+  cmd += (text_t)" \""+indexname + (text_t)"\" \"" + escaped_utf8querystring + (text_t)"\""; 
+
+  if (!queryparams.filterstring.empty()) {
+    cmd += " -filter \"" + queryparams.filterstring + "\"";
+  }
+  if (!queryparams.sortfield.empty()) {
+    cmd += " -sort \"" + queryparams.sortfield + "\"";
+  }
+  if (!queryparams.fuzziness.empty()) {
+    cmd += " -fuzziness " + queryparams.fuzziness;
+  }
+
+  // New code to support configuration of the default conjuction operator
+  // set default Boolean combiner from all/some setting
+  // if match_mode == 1, ie all, default=1 ie AND
+  // if match_mode == 0, ie some, default=0, ie OR
+  if (queryparams.match_mode)
+    {
+      cmd += " -dco AND";
+    }
+
+  // New code to allow Lucene to do paging of search results. This should
+  // substantially improve performance as we don't have to return all 12000
+  // hits if we only need the first 20!
+  if (queryparams.startresults && queryparams.endresults)
+    {
+      cmd += (text_t)" -startresults " + queryparams.startresults;
+      cmd += (text_t)" -endresults " + queryparams.endresults;
+    }
+
+  text_t xml_text = "";
+
+  // I don't want to do this, but I have to.
+  text_t gsdlhome_env = "GSDLHOME=" + gsdlhome;
+  putenv(gsdlhome_env.getcstr());
+
+#ifdef __WIN32__
+  putenv("GSDLOS=windows");
+
+  //FILE *PIN = _popen(cmd.getcstr(), "r"); // didn't seem to work
+  cmd = (text_t)"perl -S "+cmd;
+  // we write the result to a file
+  clock_t this_time = clock();
+  text_t filename = "luc";
+  filename.append(this_time);
+  filename.append(".txt");
+ 
+  text_t out_file = filename_cat(collectdir, filename);
+  cmd += " -out \"" + out_file + "\"";
+  int rv = gsdl_system(cmd, true, cerr);
+  if (rv != 0) {
+    cerr << "tried to run command \""<<cmd<<"\", but it failed\n";
+  } else {
+    read_file(out_file, xml_text);
+    remove(out_file.getcstr()); // now delete it
+  }
+#else
+  putenv("GSDLOS=linux");
+
+  FILE *PIN = popen(cmd.getcstr(), "r");
+
+  if (PIN==NULL) {
+    perror("PIPE");
+    cerr << "Error: unable to open pipe to " << cmd << endl;
+    
+    return false;
+  }
+  while (!feof(PIN)) {
+    char buffer[256];
+    int num_bytes = fread(buffer,1,256,PIN);
+    xml_text.appendcarr(buffer,num_bytes);
+  }
+
+#endif
+
+  expat_resultset(xml_text,queryresult);
+  
+#ifdef __WIN32__
+  //  _pclose(PIN);
+#else
+  pclose(PIN);
+#endif
+
+  return true;
+}
+
+
+bool lucenesearchclass::browse_search(const queryparamclass &queryparams, 
+				      int start, int numDocs,
+				      queryresultsclass &queryresult) {
+
+  cerr << "**** Not sure what this function does!" << endl;
+  return false;
+}
+
+// the document text for 'docnum' is placed in 'output'
+// docTargetDocument returns 'true' if it was able to
+// try to get a document
+// collection is needed to see if an index from the 
+// collection is loaded. THe default index bits are just there cos
+// the mg version needs them
+
+bool lucenesearchclass::docTargetDocument(const text_t &/*defaultindex*/,
+					const text_t &/*defaultsubcollection*/,
+					const text_t &/*defaultlanguage*/,
+					const text_t &collection,
+					int docnum,
+					text_t &output) {
+
+  // we now get the document directly by lucenesource, so don't use this 
+  // method
+  return false;
+}
+
+// used to clear any cached databases for persistent versions of 
+// Greenstone like the Windows local library
+void lucenesearchclass::unload_database () {
+}
+
+void lucenesearchclass::set_gsdlhome (const text_t &gh)
+{
+  gsdlhome = gh;
+}
Index: /gsdl/trunk/runtime-src/src/colservr/lucenesearch.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/lucenesearch.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/lucenesearch.h	(revision 16571)
@@ -0,0 +1,96 @@
+/**********************************************************************
+ *
+ * lucenesearch.h -- implementation of search class for lucene
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * 
+ *
+ *********************************************************************/
+
+
+#ifndef LUCENESEARCH_H
+#define LUCENESEARCH_H
+
+#include "search.h"
+
+class lucenesearchclass : public searchclass {
+public:
+  lucenesearchclass ();
+  virtual ~lucenesearchclass ();
+
+  virtual text_t get_textindex_type() {return "lucene";}
+
+  // the search results are returned in queryresults
+  // search returns 'true' if it was able to do a search
+  virtual bool search(const queryparamclass &queryparams, 
+		      queryresultsclass &queryresults);
+  
+  // this returns a list of terms in queryresults - no document info is returned
+  // returns a list of numTerms terms, starting from the query string term (in queryparams)
+  // + start. used for full text browsing
+  virtual bool browse_search(const queryparamclass &queryparams, int start, int numTerms,
+			     queryresultsclass &queryresults);
+
+  // the document text for 'docnum' is placed in 'output'
+  // docTargetDocument returns 'true' if it was able to
+  // try to get a document
+  // collection is needed to see if an index from the 
+  // collection is loaded. If no index has been loaded
+  // defaultindex is needed to load one
+  virtual bool docTargetDocument(const text_t &defaultindex,
+			 const text_t &defaultsubcollection,
+			 const text_t &defaultlanguage,
+			 const text_t &collection,
+			 int docnum,
+			 text_t &output);
+
+  /*  // same as docTargetDocument except the document is returned
+  // in its raw form. UDoc remains the property of mg and may
+  // be destroyed on the next call to mg.
+  // not implemented for lucene
+  virtual bool mgdocument (const text_t &defaultindex,
+		   const text_t &defaultsubcollection,
+		   const text_t &defaultlanguage,
+		   const text_t &collection,
+		   int docnum,
+		   char *&UDoc, int &ULen);
+  */
+
+  void set_text_level(const text_t &textlevel_arg);
+  text_t textlevel;
+
+  // used to clear any cached databases for persistent versions of 
+  // Greenstone like the Windows local library
+  void unload_database ();
+
+  void set_gsdlhome (const text_t &gh);
+
+ protected:
+  text_t getindexsuffix(const queryparamclass &qp);
+
+ private:
+  text_t gsdlhome;
+
+};
+
+
+#endif
+
Index: /gsdl/trunk/runtime-src/src/colservr/lucenesource.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/lucenesource.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/lucenesource.cpp	(revision 16571)
@@ -0,0 +1,94 @@
+/**********************************************************************
+ *
+ * lucenesource.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "lucenesource.h"
+#include "fileutil.h"
+#include "OIDtools.h"
+#include "expat_document.h"
+#include "lucenesearch.h"
+
+lucenesourceclass::lucenesourceclass () 
+  : sourceclass()
+{
+  classname = "lucenesource";
+}
+
+lucenesourceclass::~lucenesourceclass () {
+}
+
+bool lucenesourceclass::get_document (const text_t &OID, text_t &doc, 
+				      comerror_t &err, ostream &logout) {
+
+  outconvertclass text_t2ascii;
+  err = noError;
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: lucenesource contains a null dbclass\n\n";
+    err = configurationError;
+    return true;
+  }
+
+  // open the database
+  db_ptr->setlogout(&logout);
+  if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {
+    // most likely a system problem (we have already checked that the database exists)
+    logout << text_t2ascii
+	   << "system problem: open on database \"" << db_filename << "\" failed\n\n";
+    err = systemProblem;
+    return true;
+  }
+
+  text_t tOID = OID;
+  if (needs_translating (OID)) 
+    translate_OID (OID, tOID, err, logout);
+  infodbclass info;
+  if (!db_ptr->getinfo(tOID, info)) {
+    db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+    return false;
+  }
+
+  if (info["hastxt"].getint() == 0) { // there is no text for this section
+    return false; // true??
+  }
+  int docnum = info["docnum"].getint();
+
+  // get the parent id
+  text_t parent_OID;
+  get_top(tOID, parent_OID);
+  
+  if (!db_ptr->getinfo(parent_OID, info)) {
+    db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+    return false;
+  }
+
+  text_t archive_dir = info["archivedir"];
+  text_t full_path_to_doc = filename_cat(collectdir, "index", "text", archive_dir, "doc.xml");
+  
+  doc.clear();
+  db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+  expat_document(full_path_to_doc, ((lucenesearchclass*)textsearchptr)->textlevel, text_t(docnum), doc);
+  return true;
+}
Index: /gsdl/trunk/runtime-src/src/colservr/lucenesource.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/lucenesource.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/lucenesource.h	(revision 16571)
@@ -0,0 +1,50 @@
+/**********************************************************************
+ *
+ * lucenesource.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef LUCENESOURCE_H
+#define LUCENESOURCE_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "comtypes.h"
+#include "maptools.h"
+#include "search.h"
+#include "source.h"
+
+
+class lucenesourceclass : public sourceclass {
+public:
+  lucenesourceclass ();
+  virtual ~lucenesourceclass ();
+
+  bool get_document (const text_t &OID, text_t &doc, 
+		     comerror_t &err, ostream &logout);
+
+};
+
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/maptools.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/maptools.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/maptools.cpp	(revision 16571)
@@ -0,0 +1,183 @@
+/**********************************************************************
+ *
+ * maptools.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "maptools.h"
+
+
+
+void stringmap::clear () {
+  fromorder.erase (fromorder.begin(), fromorder.end());
+  mapfrom.erase (mapfrom.begin(), mapfrom.end());
+}
+
+void stringmap::importmap (const text_tarray &maparray) {
+  importmap(maparray, false);
+}
+
+void stringmap::importmap (const text_tarray &maparray, bool keepold) {
+  if (!keepold) {
+    clear ();
+  }
+  
+  text_tarray::const_iterator here = maparray.begin();
+  text_tarray::const_iterator end = maparray.end();
+  text_t from;
+  text_t to;
+
+  while (here != end) {
+    splitmapentry (*here, from, to);
+    fromorder.push_back (from);
+    mapfrom[from] = to;
+    ++here;
+  }
+}
+
+void stringmap::exportmap (text_tarray &maparray) const {
+  maparray.erase (maparray.begin(), maparray.end());
+
+  text_tarray::const_iterator here = fromorder.begin();
+  text_tarray::const_iterator end = fromorder.end();
+  text_tmap::const_iterator toptr;
+  text_t tempmap;
+
+  while (here != end) {
+    toptr = mapfrom.find (*here);
+    if (toptr != mapfrom.end()) {
+      joinmapentry ((*toptr).first, (*toptr).second, tempmap);
+      maparray.push_back (tempmap);
+    }
+
+    ++here;
+  }
+}
+
+void stringmap::getfromarray (text_tarray &fromarray) const {
+  fromarray = fromorder;
+}
+
+void stringmap::gettoarray (text_tarray &toarray) const {
+  toarray.erase(toarray.begin(), toarray.end());
+
+  text_tarray::const_iterator here = fromorder.begin();
+  text_tarray::const_iterator end = fromorder.end();
+  text_tmap::const_iterator toptr;
+
+  while (here != end) {
+    toptr = mapfrom.find (*here);
+    if (toptr != mapfrom.end()) {
+      toarray.push_back((*toptr).second);
+    }
+    ++here;
+  }
+}
+
+bool stringmap::fromexists (const text_t &from) const {
+  return (mapfrom.find (from) != mapfrom.end ());
+}
+
+bool stringmap::toexists (const text_t &to) const {
+  text_tarray::const_iterator here = fromorder.begin();
+  text_tarray::const_iterator end = fromorder.end();
+  text_tmap::const_iterator toptr;
+
+  while (here != end) {
+    toptr = mapfrom.find (*here);
+    if (toptr != mapfrom.end() && (*toptr).second == to) return true;
+    ++here;
+  }
+  
+  // it was not found
+  return false;
+}
+
+bool stringmap::from2to (const text_t &from, text_t &to) const {
+  text_tmap::const_iterator toptr = mapfrom.find (from);
+  if (toptr == mapfrom.end()) {
+    to.clear();
+    return false;
+  }
+
+  to = (*toptr).second;
+  return true;
+}
+
+bool stringmap::to2from (const text_t &to, text_t &from) const {
+  text_tarray::const_iterator here = fromorder.begin();
+  text_tarray::const_iterator end = fromorder.end();
+  text_tmap::const_iterator toptr;
+
+  while (here != end) {
+    toptr = mapfrom.find (*here);
+    if (toptr != mapfrom.end() && (*toptr).second == to) {
+      from = (*toptr).first;
+      return true;
+    }
+    ++here;
+  }
+  
+  // it was not found
+  from.clear();
+  return false;
+}
+
+
+
+void splitmapentry (const text_t &mapentry, text_t &from, text_t &to) {
+  from.clear ();
+  to.clear();
+
+  text_t::const_iterator here = mapentry.begin();
+  text_t::const_iterator end = mapentry.end();
+
+  // get the "from" part of the map
+  while (here != end) {
+    if (*here == '-') {
+      ++here;
+      if (here != end && *here == '>') {
+	++here;
+	break; // found "->"
+      }
+
+      // didn't find "->"
+      from.push_back('-');
+
+    } else {
+      from.push_back(*here);
+      ++here;
+    }
+  }
+
+  // get the "to" part of the map
+  while (here != end) {
+    to.push_back(*here);
+    ++here;
+  }
+}
+
+void joinmapentry (const text_t &from, const text_t &to, text_t &mapentry) {
+  mapentry = from;
+  mapentry += "->";
+  mapentry += to;
+}
Index: /gsdl/trunk/runtime-src/src/colservr/maptools.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/maptools.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/maptools.h	(revision 16571)
@@ -0,0 +1,66 @@
+/**********************************************************************
+ *
+ * maptools.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef MAPTOOLS_H
+#define MAPTOOLS_H
+
+
+#include "gsdlconf.h"
+#include "text_t.h"
+
+// stringmap is a mapping which remembers the original order 
+// of the map, but is very fast to look up.
+class stringmap {
+protected:
+  text_tarray fromorder;
+  text_tmap mapfrom;
+
+public:
+  void clear ();
+
+  void importmap (const text_tarray &maparray);
+  void importmap (const text_tarray &maparray, bool keepold);
+  void exportmap (text_tarray &maparray) const;
+
+  void getfromarray (text_tarray &fromarray) const;
+  void gettoarray (text_tarray &toarray) const;
+  
+  bool fromexists (const text_t &from) const;
+  bool toexists (const text_t &to) const;
+
+  // from2to and to2from return false if the key (the "from"
+  // field or the "to" field) cannot be found
+  bool from2to (const text_t &from, text_t &to) const;
+  bool to2from (const text_t &to, text_t &from) const;
+};
+
+
+// a few useful functions used by stringmap
+void splitmapentry (const text_t &mapentry, text_t &from, text_t &to);
+void joinmapentry (const text_t &from, const text_t &to, text_t &mapentry);
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/mgppqueryfilter.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgppqueryfilter.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgppqueryfilter.cpp	(revision 16571)
@@ -0,0 +1,385 @@
+/**********************************************************************
+ *
+ * queryfilter.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "mgppqueryfilter.h"
+#include "fileutil.h"
+#include "mgppsearch.h"
+
+/////////////////////////////////
+// functions for queryfilterclass
+/////////////////////////////////
+
+
+mgppqueryfilterclass::mgppqueryfilterclass () 
+  : queryfilterclass() {
+
+  
+  FilterOption_t filtopt;
+  
+  // -- onePerTerm  Level          enumerated
+  // likely to be Doc, Sec, Para, but we dont assume anything now
+  filtopt.clear();
+  filtopt.name = "Level";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filterOptions["Level"] = filtopt;
+
+  // --  IndexField, enumerated, used to list available fields
+  filtopt.clear();
+  filtopt.name = "IndexField";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["IndexField"] = filtopt;
+
+}
+
+mgppqueryfilterclass::~mgppqueryfilterclass () {
+}
+
+
+//whether a query is a full text browse
+bool mgppqueryfilterclass::full_text_browse (int filterRequestOptions) {
+  return (filterRequestOptions & FRfullTextBrowse);
+}
+
+void mgppqueryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
+  queryfilterclass::configure(key, cfgline);
+
+  if (key == "indexfieldmap") {
+    indexfieldmap.importmap (cfgline);
+    
+    // update the list of indexes in the filter information
+    text_tarray options;
+    indexfieldmap.gettoarray (options);
+    filterOptions["IndexField"].validValues = options;
+    
+  } else if (key == "indexlevels") {
+    text_tarray::const_iterator here = cfgline.begin();
+    text_tarray::const_iterator end = cfgline.end();
+    bool first=true;
+    filterOptions["Level"].validValues.erase(filterOptions["Level"].validValues.begin(), filterOptions["Level"].validValues.end());
+    while (here != end) {
+      if (!(*here).empty()) {
+	if (first) {
+	  first = false;
+	  // the default is the first value
+	  filterOptions["Level"].defaultValue = *here;
+	}
+	filterOptions["Level"].validValues.push_back(*here);
+      }
+      ++here;
+    }
+  } else if (key == "textlevel") {
+      ((mgppsearchclass *)textsearchptr)->set_text_level(cfgline[0]);
+  } else if (key == "indexstem") {
+    ((mgppsearchclass *)textsearchptr)->set_indexstem (cfgline[0]);
+  } else if (key == "defaultindex") { // used for fields in mgpp
+    indexfieldmap.from2to (cfgline[0], filterOptions["IndexField"].defaultValue);
+  }
+  
+}
+
+bool mgppqueryfilterclass::init (ostream &logout) {
+  
+  if (!queryfilterclass::init(logout)) {
+    return false;
+  }
+  
+  if (filterOptions["IndexField"].defaultValue.empty()) {
+    // use first index in map as default if no default is set explicitly
+    text_tarray fromarray;
+    indexfieldmap.getfromarray(fromarray);
+    if (fromarray.size()) {
+      filterOptions["IndexField"].defaultValue = fromarray[0];
+    }
+  }
+  return true;
+}
+
+void mgppqueryfilterclass::filter(const FilterRequest_t &request,
+				  FilterResponse_t &response,
+				  comerror_t &err, ostream &logout) {  
+
+
+  outconvertclass text_t2ascii;
+
+  response.clear ();
+  err = noError;
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: queryfilter contains a null dbclass\n\n";
+    err = configurationError;
+    return;
+  }
+  if (textsearchptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: queryfilter contains a null textsearchclass for mgpp\n\n";
+    err = configurationError;
+    return;
+  }
+  if (full_text_browse(request.filterResultOptions)) {
+    browsefilter(request, response, err, logout);
+    return;
+  }
+  // open the database
+  db_ptr->setlogout(&logout);
+  if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {
+    // most likely a system problem (we have already checked that the database exists)
+    logout << text_t2ascii
+	   << "system problem: open on database \"" << db_filename << "\" failed\n\n";
+    err = systemProblem;
+    return;
+  }
+
+
+  // get the query parameters
+  int startresults, endresults;
+  text_t phrasematch; // not used here any more
+  vector<queryparamclass> queryfilterparams;
+  parse_query_params (request, queryfilterparams, startresults, 
+		      endresults, phrasematch, logout);  
+ 
+   
+  // do query
+  queryresultsclass queryresults;
+  do_multi_query (request, queryfilterparams, queryresults, err, logout);
+  if (err != noError) return;
+  // assemble document results
+  if (need_matching_docs (request.filterResultOptions)) {
+    
+    int resultnum = 1;
+    ResultDocInfo_t resultdoc;
+    text_t trans_OID;
+    vector<text_t>::iterator docorder_here = queryresults.docs.docorder.begin();
+    vector<text_t>::iterator docorder_end = queryresults.docs.docorder.end();
+
+    if (endresults == -1) endresults = MAXNUMDOCS;
+    while (docorder_here != docorder_end) {
+      if (resultnum > endresults) break;
+      
+      // translate the document number
+      if (!translate(db_ptr, *docorder_here, trans_OID)) {
+	logout << text_t2ascii
+	       << "warning: could not translate mgpp document number \""
+	       << *docorder_here << "\"to OID.\n\n";
+	
+      } else {
+	docresultmap::iterator docset_here = queryresults.docs.docset.find (*docorder_here);
+
+	// see if there is a result for this number,
+	// if it is in the request set (or the request set is empty)
+	if (docset_here != queryresults.docs.docset.end() &&
+	    (request.docSet.empty() || in_set(request.docSet, trans_OID))) {
+	  if (resultnum >= startresults) {
+	    // add this document
+	    resultdoc.OID = trans_OID;
+	    resultdoc.result_num = resultnum;
+	    resultdoc.ranking = (int)((*docset_here).second.docweight * 10000.0 + 0.5);
+
+	    response.docInfo.push_back (resultdoc);
+	  }
+	  
+	  ++resultnum;
+	}
+      } // else
+      
+      ++docorder_here;
+    }
+  } // if need matching docs
+
+  // assemble the term results
+  if (need_term_info(request.filterResultOptions)) {
+    // note: the terms have already been sorted and uniqued - ?? have they??
+
+    TermInfo_t terminfo;
+    bool terms_first = true;
+
+    termfreqclassarray::iterator terms_here = queryresults.terms.begin();
+    termfreqclassarray::iterator terms_end = queryresults.terms.end();
+
+    while (terms_here != terms_end) {
+      terminfo.clear();
+      terminfo.term = (*terms_here).termstr;
+      terminfo.freq = (*terms_here).termfreq;
+
+      // this bit gets the matchTerms ie the equivalent (stem/casefold) terms
+      if (terms_first) {
+	text_tset::iterator termvariants_here = queryresults.termvariants.begin();
+	text_tset::iterator termvariants_end = queryresults.termvariants.end();
+	while (termvariants_here != termvariants_end) {
+	  terminfo.matchTerms.push_back (*termvariants_here);
+	  ++termvariants_here;
+	}
+      }
+      terms_first = false;
+      
+      response.termInfo.push_back (terminfo);
+
+      ++terms_here;
+    }
+  }
+
+  db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+  response.numDocs = queryresults.docs_matched;
+  response.isApprox = queryresults.is_approx;
+}
+
+void mgppqueryfilterclass::browsefilter(const FilterRequest_t &request,
+					FilterResponse_t &response,
+					comerror_t &err, ostream &logout) {  
+
+  outconvertclass text_t2ascii;
+
+  // get the query parameters
+  int startresults, endresults;
+  text_t phrasematch; // not used here any more, just have it so can use
+                      // parse_query_params function
+  
+  vector<queryparamclass> queryfilterparams;
+  parse_query_params (request, queryfilterparams, startresults, 
+		      endresults, phrasematch, logout);  
+
+    vector<queryparamclass>::const_iterator query_here = queryfilterparams.begin();
+   
+  // do query
+  queryresultsclass queryresults;
+  queryresults.clear();
+  
+  int numDocs = endresults-startresults;
+  textsearchptr->setcollectdir (collectdir);
+
+  if (!((mgppsearchclass*)textsearchptr)->browse_search((*query_here), startresults, numDocs, queryresults)) {
+    // most likely a system problem
+    logout << text_t2ascii
+	   << "system problem: could not do full text browse with mgpp for index \""
+	   << (*query_here).index << (*query_here).subcollection
+	   << (*query_here).language << "\".\n\n";
+    err = systemProblem;
+    return;
+  }
+
+  // assemble the term results
+  TermInfo_t terminfo;
+  
+  termfreqclassarray::iterator terms_here = queryresults.terms.begin();
+  termfreqclassarray::iterator terms_end = queryresults.terms.end();
+
+  while (terms_here != terms_end) {
+    terminfo.clear();
+    terminfo.term = (*terms_here).termstr;
+    terminfo.freq = (*terms_here).termfreq;
+    
+    response.termInfo.push_back (terminfo);
+
+    ++terms_here;
+  }
+  
+
+}
+
+// textsearchptr and db_ptr are assumed to be valid
+void mgppqueryfilterclass::do_multi_query (const FilterRequest_t &request,
+					   const vector<queryparamclass> &query_params,
+					   queryresultsclass &multiresults,
+					   comerror_t &err, ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  err = noError;
+  textsearchptr->setcollectdir (collectdir);
+  multiresults.clear();
+  
+  vector<queryparamclass>::const_iterator query_here = query_params.begin();
+  vector<queryparamclass>::const_iterator query_end = query_params.end();
+  while (query_here != query_end) {
+    queryresultsclass thisqueryresults;
+    text_t indx((*query_here).index);
+    if (!textsearchptr->search((*query_here), thisqueryresults)) {
+      // most likely a system problem
+      logout << text_t2ascii
+	     << "system problem: could not do search with mgpp for index \""
+	     << (*query_here).index << (*query_here).subcollection
+	     << (*query_here).language << "\".\n\n";
+      err = systemProblem;
+      return;
+    }
+
+    // check for syntax error
+    if (thisqueryresults.syntax_error==true) {
+      logout << text_t2ascii
+	     << "syntax problem: invalid query string \""
+	     << (*query_here).querystring<<"\".\n";
+      err = syntaxError;
+      return;
+    }
+    // combine the results
+    if (need_matching_docs (request.filterResultOptions)) {
+            
+      if (query_params.size() == 1) {
+	multiresults.docs = thisqueryresults.docs; // just one set of results
+	multiresults.docs_matched = thisqueryresults.docs_matched;
+	multiresults.is_approx = thisqueryresults.is_approx;
+	
+      } else {
+	if ((*query_here).combinequery == "and") {
+	  multiresults.docs.combine_and (thisqueryresults.docs);
+	} else if ((*query_here).combinequery == "or") {
+	  multiresults.docs.combine_or (thisqueryresults.docs);
+	} else if ((*query_here).combinequery == "not") {
+	  multiresults.docs.combine_not (thisqueryresults.docs);
+	}
+	multiresults.docs_matched = multiresults.docs.docset.size();
+	multiresults.is_approx = Exact;
+      }
+    }
+
+    // combine the term information 
+    if (need_term_info (request.filterResultOptions)) {
+      // append the terms
+      multiresults.orgterms.insert(multiresults.orgterms.end(),
+				   thisqueryresults.orgterms.begin(),
+				   thisqueryresults.orgterms.end());
+
+      
+      // add the term variants - 
+      text_tset::iterator termvar_here = thisqueryresults.termvariants.begin();
+      text_tset::iterator termvar_end = thisqueryresults.termvariants.end();
+      while (termvar_here != termvar_end) {
+	multiresults.termvariants.insert(*termvar_here);
+	++termvar_here;
+      }
+    }
+   
+    ++query_here;
+  }
+
+  // sort and unique the query terms
+  multiresults.sortuniqqueryterms ();
+}
+
+
+
Index: /gsdl/trunk/runtime-src/src/colservr/mgppqueryfilter.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgppqueryfilter.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgppqueryfilter.h	(revision 16571)
@@ -0,0 +1,63 @@
+/**********************************************************************
+ *
+ * mgppqueryfilter.h -- new queryfilter to use mgpp 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+#ifndef MGPPQUERYFILTER_H
+#define MGPPQUERYFILTER_H
+
+#include "queryfilter.h"
+
+
+class mgppqueryfilterclass : public queryfilterclass {
+protected:
+
+  stringmap indexfieldmap;
+  bool full_text_browse (int filterRequestOptions);
+
+  // textsearchptr and db_ptr are assumed to be valid
+  void do_multi_query (const FilterRequest_t &request,
+		       const vector<queryparamclass> &query_params,
+		       queryresultsclass &multiresults,
+		       comerror_t &err, ostream &logout);
+
+
+public:
+  mgppqueryfilterclass ();
+  virtual ~mgppqueryfilterclass ();
+
+  void configure (const text_t &key, const text_tarray &cfgline);
+  bool init (ostream &logout);
+  void filter (const FilterRequest_t &request,
+		       FilterResponse_t &response,
+		       comerror_t &err, ostream &logout);
+  
+  void browsefilter(const FilterRequest_t &request,
+		    FilterResponse_t &response,
+		    comerror_t &err, ostream &logout);  
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/mgppsearch.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgppsearch.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgppsearch.cpp	(revision 16571)
@@ -0,0 +1,346 @@
+/**********************************************************************
+ *
+ * mgppsearch.cpp -- 
+ * Copyright (C) 1999-2002  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#include "gsdlconf.h"
+#include "mgppsearch.h"
+#include "fileutil.h"
+#include "GSDLQueryParser.h"
+#include "MGQuery.h"
+#include "TextGet.h"
+#include "queryinfo.h"
+#include "gsdlunicode.h"
+
+
+text_t mgppsearchclass::getindexsuffix(const queryparamclass &qp) {
+  return getindexsuffix(qp.collection, qp.index+qp.subcollection+qp.language);
+
+}
+
+text_t mgppsearchclass::getindexsuffix (const text_t &collection, 
+			      const text_t &index) {
+
+  text_t indexsuffix = "index";  
+  indexsuffix = filename_cat (indexsuffix, index);
+  if (indexstem.empty()) {
+    // no index stem, use the coll name
+    indexsuffix = filename_cat (indexsuffix, collection);
+  } else {
+    indexsuffix = filename_cat (indexsuffix, indexstem);
+  }
+  return indexsuffix;
+}
+
+////////////////////
+// mgppsearch class //
+////////////////////
+
+mgppsearchclass::mgppsearchclass ()
+  : searchclass() {
+
+  textlevel = "Doc";
+  indexData = NULL;
+}
+
+mgppsearchclass::~mgppsearchclass () 
+{
+  if (cache != NULL) 
+    {
+      delete cache;
+      cache = NULL;
+    }
+
+  if (indexData !=NULL) {
+    indexData->UnloadData();
+    delete indexData;
+    indexData = NULL;
+  }
+  
+}
+
+void mgppsearchclass::set_text_level(const text_t &textlevel_arg)
+{
+  textlevel = textlevel_arg;
+}
+
+void mgppsearchclass::set_indexstem(const text_t &stem)
+{
+  indexstem = stem;
+}
+
+
+bool mgppsearchclass::search(const queryparamclass &queryparams, 
+			     queryresultsclass &queryresult) {
+ 
+#ifdef __WIN32__
+  char basepath[]="";
+#else
+  char basepath[] = "/";
+#endif
+ 
+  char *indexname = (filename_cat(collectdir, getindexsuffix(queryparams))).getcstr(); 
+
+ // load index data
+  if (indexData == NULL) {
+    indexData = new IndexData();
+  }
+  if (!indexData->LoadData (basepath, indexname)) {
+    cerr<<"couldn't load index data\n"<<endl;
+    return false;
+  }
+
+  // set default stem method from values originally set on prefs page
+  int defaultStemMethod = 0;
+  if (queryparams.casefolding) {
+    defaultStemMethod |= STEM_CaseFolding;
+  }
+  if (queryparams.stemming) {
+    defaultStemMethod |= STEM_Stemming;
+  }
+  if (queryparams.accentfolding) {
+    defaultStemMethod |= STEM_AccentFolding;
+  }  	
+  
+  // set default Boolean combiner from all/some setting
+  // if match_mode == 1, ie all, default=1 ie AND
+  // if match_mode == 0, ie some, default=0, ie OR
+  int defaultBoolCombine = 0;
+  if (queryparams.match_mode){
+    defaultBoolCombine = 1;
+  }
+
+  // use default query info settings - change to reflect user preferences??
+  QueryInfo queryInfo;
+  
+  SetCStr (queryInfo.docLevel, (queryparams.level.getcstr())); 
+  queryInfo.maxDocs = (unsigned long)queryparams.maxdocs;
+  queryInfo.sortByRank = (queryparams.search_type == 1);
+  queryInfo.exactWeights = false;
+  queryInfo.needRankInfo = true; // used for overall term freq as well as ranking
+  queryInfo.needTermFreqs = true;
+  
+  ExtQueryResult queryResult;
+  
+  UCArray queryArray;
+  // greenstone gives us the query encoded in unicode. We want utf8.
+  char* utf8querystring=to_utf8(queryparams.querystring).getcstr();
+  SetCStr(queryArray, utf8querystring);
+  delete []utf8querystring;
+
+  // create the mgpp query tree
+  QueryNode *queryTree = NULL;
+  queryTree = ParseQuery(queryArray, defaultBoolCombine, defaultStemMethod, queryparams.maxnumeric);
+  if (queryTree == NULL) { // syntax error
+    queryresult.syntax_error = true;
+    return true; // should we return true or false?
+  }
+  UCArray level;
+  UCArrayClear(level);
+  
+  //set the level for results
+  SetCStr(level, textlevel.getcstr());
+
+  
+  // do the query
+  MGQuery(*indexData, queryInfo, queryTree, queryResult, level);
+  
+ 
+  // convert ExtQueryResult to queryresultclass
+  
+  queryresult.docs_matched = (int)queryResult.docs.size();
+
+  if (queryresult.docs_matched == (int)queryResult.actualNumDocs) {
+    queryresult.is_approx = Exact; 
+  }
+  else if (queryresult.docs_matched < (int)queryResult.actualNumDocs) {
+    queryresult.is_approx = MoreThan;
+  }
+  else {
+    queryresult.is_approx = Approximate;
+  }
+
+  docresultclass doc;
+  for (int i=0; i<(int)queryResult.docs.size(); ++i) {
+    doc.clear();
+    doc.docnum = (int)queryResult.levels[i];
+    doc.docweight = queryResult.ranks[i];
+    queryresult.docs.docset[doc.docnum] = doc;
+    queryresult.docs.docorder.push_back(doc.docnum);
+
+  }
+
+  // term info
+  termfreqclass term;
+  for (int k=0; k<(int)queryResult.termFreqs.size(); ++k) {
+    term.clear();
+    char* termfreq_cstr=GetCStr(queryResult.termFreqs[k].term);
+    term.termstr = to_uni(termfreq_cstr);
+    delete []termfreq_cstr;
+    term.termstemstr = term.termstr;
+    // we don't set term.utf8equivterms ?? - jrm21
+    term.termfreq = queryResult.termFreqs[k].termFreq;
+    queryresult.terms.push_back(term);
+    queryresult.orgterms.push_back(term); // should this change??
+    
+    for (int j=0; j<(int)queryResult.termFreqs[k].equivTerms.size(); ++j) {
+      char* equivterm_cstr=GetCStr(queryResult.termFreqs[k].equivTerms[j]);
+      queryresult.termvariants.insert(to_uni(equivterm_cstr));
+      delete []equivterm_cstr;
+    }
+
+  }
+  // clean up
+  unload_database();  // Important that local library doesn't leave any files open
+  delete []indexname;
+  return true;
+
+}
+
+
+bool mgppsearchclass::browse_search(const queryparamclass &queryparams, int start, int numDocs,
+				    queryresultsclass &queryresult) {
+
+#ifdef __WIN32__
+  char basepath[]="";
+#else
+  char basepath[] = "/";
+#endif
+
+  char *indexname = (filename_cat(collectdir, getindexsuffix(queryparams))).getcstr();
+ 
+  if (indexData == NULL) {
+    indexData = new IndexData();
+  }
+  if (!indexData->LoadData (basepath, indexname)) {
+    cerr<<"couldn't load index data\n"<<endl;
+    return false;
+  }
+
+  UCArray level;
+  UCArrayClear(level);
+  
+  //browse always at top level
+  SetCStr(level, "Doc"); // this name may change.
+  
+
+  BrowseQueryNode browseNode;
+  browseNode.startPosition = start;
+  browseNode.numTerms = numDocs;
+
+  BrowseQueryResult browseResult;
+
+  UCArrayClear(browseNode.term);
+  // greenstone gives us the query encoded in unicode. We want utf8.
+  char* utf8querystring=to_utf8(queryparams.querystring).getcstr();
+  SetCStr(browseNode.term, utf8querystring);
+  delete []utf8querystring;
+
+  // do the actual query
+  MGBrowseQuery(*indexData, level, browseNode, browseResult);
+
+  // load results into term info
+  termfreqclass term;
+  for (int i=0; i<(int)browseResult.termFreqs.size(); ++i) {
+    term.clear();
+    char* term_cstr = GetCStr(browseResult.termFreqs[i].term);
+    term.termstr = to_uni(term_cstr);
+    delete []term_cstr;
+    term.termstemstr = term.termstr;
+    term.termfreq = browseResult.termFreqs[i].termFreq;
+    queryresult.terms.push_back(term);
+    queryresult.orgterms.push_back(term);
+  }
+
+  // clean up
+  unload_database();  // Important that local library doesn't leave any files open
+  delete []indexname;
+
+  return true;
+}
+
+// the document text for 'docnum' is placed in 'output'
+// docTargetDocument returns 'true' if it was able to
+// try to get a document
+// collection is needed to see if an index from the 
+// collection is loaded. THe default index bits are just there cos
+// the mg version needs them
+
+bool mgppsearchclass::docTargetDocument(const text_t &/*defaultindex*/,
+					const text_t &/*defaultsubcollection*/,
+					const text_t &/*defaultlanguage*/,
+					const text_t &collection,
+					int docnum,
+					text_t &output) {
+  
+#ifdef __WIN32__
+  char basepath[]="";
+#else
+  char basepath[] = "/";
+#endif
+  char *textname = (filename_cat(collectdir, getindexsuffix(collection, "text"))).getcstr();
+ 
+  TextData textdata;
+  if(!textdata.LoadData(basepath, textname)) {
+    cout<<"couldn't load text data\n"<<endl;
+    return false;
+  }
+  UCArray doctext;
+  UCArray level;
+  SetCStr(level, textlevel.getcstr());
+  if (!GetDocText(textdata, level, (unsigned long)docnum, doctext)) {
+    cout<<"couldn't retrieve document text\n";
+    return false;
+  }
+
+  // convert UCArray to text_t
+  output.clear();
+  char* doctext_cstr = GetCStr(doctext);
+  output = to_uni(doctext_cstr); // convert from utf-8 to unicode
+  delete []doctext_cstr;
+
+  // here need to remove the <Document>, <Section>, <Paragraph> tags
+
+  
+  //clean up
+  textdata.UnloadData ();
+  delete []textname;
+
+  return true;
+
+}
+
+// used to clear any cached databases for persistent versions of 
+// Greenstone like the Windows local library
+void mgppsearchclass::unload_database () {
+
+  if (indexData !=NULL) {
+    indexData->UnloadData();
+  }
+}
+
+
+
+
+
Index: /gsdl/trunk/runtime-src/src/colservr/mgppsearch.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgppsearch.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgppsearch.h	(revision 16571)
@@ -0,0 +1,100 @@
+/**********************************************************************
+ *
+ * mgppsearch.h -- implementation of search class for mgpp
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * 
+ *
+ *********************************************************************/
+
+
+#ifndef MGPPSEARCH_H
+#define MGPPSEARCH_H
+
+#include "search.h"
+#include "IndexData.h"
+
+class mgppsearchclass : public searchclass {
+public:
+  mgppsearchclass ();
+  virtual ~mgppsearchclass ();
+
+  virtual text_t get_textindex_type() {return "mgpp";}
+
+  // the search results are returned in queryresults
+  // search returns 'true' if it was able to do a search
+  virtual bool search(const queryparamclass &queryparams, 
+	      queryresultsclass &queryresults);
+  
+  // this returns a list of terms in queryresults - no document info is returned
+  // returns a list of numTerms terms, starting from the query string term (in queryparams)
+  // + start. used for full text browsing
+  virtual bool browse_search(const queryparamclass &queryparams, int start, int numTerms,
+			     queryresultsclass &queryresults);
+
+  // the document text for 'docnum' is placed in 'output'
+  // docTargetDocument returns 'true' if it was able to
+  // try to get a document
+  // collection is needed to see if an index from the 
+  // collection is loaded. If no index has been loaded
+  // defaultindex is needed to load one
+  virtual bool docTargetDocument(const text_t &defaultindex,
+			 const text_t &defaultsubcollection,
+			 const text_t &defaultlanguage,
+			 const text_t &collection,
+			 int docnum,
+			 text_t &output);
+
+  /*  // same as docTargetDocument except the document is returned
+  // in its raw form. UDoc remains the property of mg and may
+  // be destroyed on the next call to mg.
+  // not implemented for mgpp
+  virtual bool mgdocument (const text_t &defaultindex,
+		   const text_t &defaultsubcollection,
+		   const text_t &defaultlanguage,
+		   const text_t &collection,
+		   int docnum,
+		   char *&UDoc, int &ULen);
+  */
+  
+  void set_text_level(const text_t &textlevel_arg);
+  
+  void set_indexstem(const text_t &indexstem);
+
+  // used to clear any cached databases for persistent versions of 
+  // Greenstone like the Windows local library
+  void unload_database ();
+
+ protected:
+  
+  text_t textlevel;
+  text_t indexstem; // the stem of the index file names
+  IndexData *indexData; // the index data structure needed for MGQuery - keep
+  // as a cache
+  
+  text_t getindexsuffix(const queryparamclass &qp);
+  text_t getindexsuffix (const text_t &collection, const text_t &index);
+
+};
+
+
+#endif
+
Index: /gsdl/trunk/runtime-src/src/colservr/mgq.c
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgq.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgq.c	(revision 16571)
@@ -0,0 +1,731 @@
+/**********************************************************************
+ *
+ * mgq.c -- cut-dowm version of mgquery
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "mgq.h"
+
+
+#include <stdio.h>
+#include <string.h>
+/* #include <io.h> */
+#include <fcntl.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+  
+#include "sysfuncs.h"
+  
+#include "messages.h"
+#include "memlib.h"
+  
+#include "invf.h"
+#include "text.h"
+#include "lists.h"
+#include "backend.h"
+#include "environment.h"
+#include "globals.h"
+#include "mg_errors.h"
+#include "commands.h"
+#include "text_get.h"
+#include "term_lists.h"
+#include "local_strings.h"
+
+#include "words.h"
+#include "stemmer.h"
+#include "stem_search.h"
+  
+#ifdef __cplusplus
+}
+#endif
+
+
+#include "mgq.h"
+
+/* get a reasonable database cache size */
+#ifndef MAXNUMDATABASEINFO
+#  ifdef GSDLSERVER
+#    define MAXNUMDATABASEINFO 10
+#  else
+#    define MAXNUMDATABASEINFO 2
+#  endif
+#endif
+
+#define MAXCOLLECTIONLEN  16
+#define MAXMGDIRLEN       256
+#define MAXGENSUFFIXLEN   256
+#define MAXTEXTSUFFIXLEN  256
+
+typedef struct DatabaseInfo {
+  int accessnum; /* -1 = invalid record */
+  char collection[MAXCOLLECTIONLEN];
+  char mgdir[MAXMGDIRLEN];
+  char gensuffix[MAXGENSUFFIXLEN];
+  char textsuffix[MAXTEXTSUFFIXLEN];
+  query_data *qd;
+} DatabaseInfo;
+
+
+/* globals needed by some vague part of mg... */
+FILE *OutFile = NULL, *InFile = NULL;
+int OutPipe = 0, InPipe = 0;
+int Quitting = 0;
+
+/* globals needed to handle loading of databases */
+static int cur_cachenum = -1;
+
+/* globals needed by the database cache */
+static DatabaseInfo dbcache[MAXNUMDATABASEINFO];
+static int cache_nextaccessnum = 0;
+static int cache_numloaded = 0;
+
+
+
+#if defined(PARADOCNUM) ||  defined(NZDL)
+static int GetDocNumFromParaNum(query_data *qd, int paranum) {
+  int Documents = qd->td->cth.num_of_docs;
+  int *Paragraph = qd->paragraph;
+  int low = 1, high = Documents;
+  int mid = (low+high)/2;
+
+  while ((mid = (low+high)/2) >=1 && mid <= Documents)
+    {
+      if (paranum > Paragraph[mid])
+        low = mid+1;
+      else if (paranum <= Paragraph[mid-1])
+        high = mid-1;
+      else
+        return mid;
+    }
+  FatalError(1, "Bad paragraph number.\n");
+  return 0;
+}
+
+static int GetParaNumFromDocNum(query_data *qd, int docnum) {
+  int Documents = qd->td->cth.num_of_docs;
+  int *Paragraph = qd->paragraph;
+
+  if (docnum > 0 && docnum <= Documents)
+    return Paragraph[docnum-1]+1;
+  return 0;
+}
+#endif
+
+
+/*****************************************************************************/
+
+static void MGQError(char *emsg)
+{
+  fprintf(stderr,"Fatal error: %s\n", emsg);
+  exit(1);
+}
+
+static int ProcessDocs (query_data * qd, int skip, int howmany, 
+			enum result_kinds kind, 
+			int (*sender)(char *,int,int,float,void *), void *ptr) {
+  int max_buf = 0, output_failure = 0;
+  int DocCount = 0;
+  int need_text = (kind == result_docs);
+
+  /* skip the requested number of documents */
+  while (skip > 0) {
+    if (!NextDoc(qd)) return 0;
+    skip--;
+  }
+
+  /* find out the maximum size for the text buffer */
+  if (need_text) max_buf = atoi (GetDefEnv ("buffer", "1048576"));
+
+  /* process each document */
+  do {
+    u_char *UDoc = NULL;
+    unsigned long ULen=0;
+
+#if defined(PARADOCNUM) ||  defined(NZDL)
+    /* adjust the document number for paragraph level result_docs */
+    /* this is a bit of a hack ... */
+    if (kind==result_docs && qd->id->ifh.InvfLevel == 3 &&
+	qd->DL != NULL && (int)qd->doc_pos < (int)qd->DL->num)
+      qd->DL->DE[qd->doc_pos].DocNum = GetParaNumFromDocNum(qd, qd->DL->DE[qd->doc_pos].DocNum);
+#endif
+    
+    if (need_text) {
+      /* load the compressed text */
+      if (LoadCompressedText (qd, max_buf))
+	MGQError("Unable to load compressed text(memory?).");
+
+      /* uncompress the loaded text */
+      UDoc = GetDocText (qd, &ULen);
+      if (UDoc == NULL) MGQError("UDoc is unexpectedly NULL");
+    }
+      
+    if (UDoc != NULL  ||  kind == result_docnums) {
+      int docnum = GetDocNum(qd);
+#if defined(PARADOCNUM) ||  defined(NZDL)
+      if (qd->id->ifh.InvfLevel == 3) docnum = GetDocNumFromParaNum(qd, docnum);
+#endif
+      switch (kind) {
+      case result_docnums:
+	if (sender != NULL)
+	  output_failure = (*sender)("",0,docnum,GetDocWeight(qd),ptr);
+	break;
+      case result_docs:
+	if (sender != NULL)
+	  output_failure = (*sender)((char *)UDoc,ULen,docnum,GetDocWeight(qd),ptr);
+	break;
+      default:
+	break;
+      }
+    }
+    DocCount++;
+      
+  } while (NextDoc (qd) && output_failure == 0 && --howmany > 0);
+  
+  /*  if (need_text) FreeTextBuffer (qd);*/
+  
+  return (DocCount);
+}
+
+
+static void send_query_term_freqs(QueryTermList *qtl,
+				  int (*sender)(char *,int,int,float,void *), void *ptr)
+{
+  int i = 0;
+  for (i = 0; i < qtl->num; i++)
+    if (sender != NULL) {
+      /*      word = word2str(qtl->QTE[i].Term); 
+	      (* sender)(word, strlen(word), qtl->QTE[i].Count, (float)0.0, ptr); */
+      (* sender)((char *)(qtl->QTE[i].Term+1), qtl->QTE[i].Term[0], 
+		 qtl->QTE[i].Count, (float)0.0, ptr);
+    }
+}
+
+
+static void send_terms (TermList * qtl, 
+			int (*sender)(char *,int,int,float,void *), void *ptr)
+{
+  int i = 0;
+  if (sender == NULL) return;
+  for (i = 0; i < qtl->num; i++)
+    {
+      /*      word = word2str(qtl->TE[i].Word);
+	      (* sender)(word, strlen(word), qtl->TE[i].Count, (float)0.0, ptr);*/
+      (* sender)((char *)(qtl->TE[i].Word+1), qtl->TE[i].Word[0], 
+		 qtl->TE[i].Count, (float)0.0, ptr);
+    }
+}
+
+
+/* MoreDocs () */
+/* Displays all documents in list  DocList. */
+/* Documents are fetched, then decompressed and displayed according to the */
+/* format implied in  FormString(). */
+
+static void
+MoreDocs (query_data * qd, enum result_kinds kind, 
+	  int skip, int howmany,
+	  int (*sender)(char *,int,int,float,void *), void *ptr)
+{
+  qd->num_of_ans = qd->DL->num;
+  switch (kind) {
+  case result_docs:
+  case result_docnums:
+    if (qd->num_of_ans > 0)
+      ProcessDocs (qd, skip, howmany, kind, sender, ptr);
+    break;
+  case result_termfreqs:
+    send_query_term_freqs(qd->QTL, sender, ptr);
+    break;
+  case result_terms:
+    send_terms(qd->TL, sender, ptr);
+    break;
+  }
+}
+
+
+
+
+
+
+/******************************************
+ * functions to handle the database cache *
+ ******************************************/
+
+/* init_dbcache should be called at the start of each */
+/* function which deals with the database cache */
+static void init_dbcache (void) {
+  static int dbcacheinited = 0;
+  int i = 0;
+
+  if (dbcacheinited) return;
+
+  cache_numloaded = 0;
+
+  for (i=0; i<MAXNUMDATABASEINFO; i++) {
+    dbcache[i].accessnum = -1;
+    dbcache[i].collection[0] = '\0';
+    dbcache[i].mgdir[0] = '\0';
+    dbcache[i].gensuffix[0] = '\0';
+    dbcache[i].textsuffix[0] = '\0';
+    dbcache[i].qd = NULL;
+  }
+
+  dbcacheinited = 1;
+}
+
+/* returns the next cache access number and increments it */
+static int get_next_accessnum (void) {
+  return cache_nextaccessnum++;
+}
+
+/* get_free_dbcache returns the cache number which */
+/* was used the longest time ago */
+/* init_dbcache should be called before this function */
+static int get_free_dbcache (void) {
+  int i = 0;
+  int minaccessnum = cache_nextaccessnum; /* the current max */
+  int minpos = 0;
+
+  for (i=0; i<MAXNUMDATABASEINFO; i++) {
+    if (dbcache[i].accessnum < minaccessnum) {
+      minaccessnum = dbcache[i].accessnum;
+      minpos = i;
+    }
+  }
+  
+  return minpos;
+}
+
+/* search_collect will search for an index which */
+/* belongs to a certain collection It returns -1 if none could be found. */
+/* init_dbcache should be called before this function */
+static int search_collect (char *collection) {
+  int i = 0;
+
+  for (i=0; i<MAXNUMDATABASEINFO; i++) {
+    if ((dbcache[i].accessnum >= 0) &&
+	(dbcache[i].qd != NULL) &&
+	(strcmp (collection, dbcache[i].collection) == 0)
+	/* && (dbcache[i].qd->id->ifh.InvfLevel == 2)*/
+	) {
+      dbcache[i].accessnum = get_next_accessnum ();
+      return i;
+    }
+  }
+
+  return -1;
+}
+
+/* search_gensuffix will search for an index which */
+/* has a certain gensuffix. It returns -1 if none could be found. */
+/* init_dbcache should be called before this function */
+static int search_gensuffix (char *gensuffix) {
+  int i = 0;
+
+  for (i=0; i<MAXNUMDATABASEINFO; i++) {
+    if ((dbcache[i].accessnum >= 0) &&
+	(dbcache[i].qd != NULL) &&
+	(strcmp (gensuffix, dbcache[i].gensuffix) == 0)) {
+      dbcache[i].accessnum = get_next_accessnum ();
+      return i;
+    }
+  }
+
+  return -1;
+}
+
+/* unload_database will unload a certain entry within */
+/* the database cache, clearing it for furture use. */
+static void unload_database (int i) {
+  /* check to see if it contains anything */
+  if (dbcache[i].accessnum < 0 || dbcache[i].qd == NULL) 
+    return;
+
+  /* unload all the query information  */
+  FinishQuerySystem(dbcache[i].qd);
+  
+  /* reset all the db info */
+  dbcache[i].accessnum = -1;
+  dbcache[i].collection[0] = '\0';
+  dbcache[i].mgdir[0] = '\0';
+  dbcache[i].gensuffix[0] = '\0';
+  dbcache[i].textsuffix[0] = '\0';
+  dbcache[i].qd = NULL;
+
+  cache_numloaded--;
+  if (cache_numloaded < 0) cache_numloaded = 0;
+}
+
+/* cache_database will store the information about */
+/* a database in the database cache. */
+static void cache_database (int i, char *collection, char *mgdir, char *gensuffix,
+			    char *textsuffix, query_data *qd) {
+  /* make sure this entry has been unloaded first */
+  if (dbcache[i].accessnum >= 0 && dbcache[i].qd != NULL) 
+    unload_database (i);
+
+  /* store the db info */
+  dbcache[i].accessnum = get_next_accessnum ();
+  strcpy (dbcache[i].collection, collection);
+  strcpy (dbcache[i].mgdir, mgdir);
+  strcpy (dbcache[i].gensuffix, gensuffix);
+  strcpy (dbcache[i].textsuffix, textsuffix);
+  dbcache[i].qd = qd;
+
+  cache_numloaded++;
+}
+
+static void make_current (int i) {
+  /* see if it is the current index */
+  if (i == cur_cachenum) return;
+ 
+  /* unload the old index */
+  if (cur_cachenum >= 0) UninitEnv ();
+  cur_cachenum = -1;
+
+  /* make sure the new one is ok */
+  if (i < 0 || dbcache[i].accessnum < 0 || dbcache[i].qd == NULL)
+    return;
+
+  /* load the new one */
+
+  /* Initialise the environment with default values */
+  InitEnv ();
+  
+  SetEnv("mgdir",dbcache[i].mgdir,NULL);
+  SetEnv("mgname",dbcache[i].gensuffix,NULL);
+  SetEnv("textname",dbcache[i].textsuffix,NULL);
+  
+  PushEnv ();
+  
+  cur_cachenum = i;
+}
+
+
+
+/********************
+ * public functions *
+ ********************/
+
+int mgq_ask(char *line)
+{
+  query_data *qd = (query_data *)NULL;
+  char QueryType = QUERY_BOOLEAN;
+  char OutputType = QUERY_DOCNUMS;
+  char *LinePtr = (char *)NULL;
+
+  if (cur_cachenum == -1) return 0;
+  qd = dbcache[cur_cachenum].qd;
+  if (qd == NULL) return 0;
+  
+  ResetFileStats (qd);
+  qd->max_mem_in_use = qd->mem_in_use = 0;
+  qd->tot_hops_taken += qd->hops_taken;
+  qd->tot_num_of_ptrs += qd->num_of_ptrs;
+  qd->tot_num_of_accum += qd->num_of_accum;
+  qd->tot_num_of_terms += qd->num_of_terms;
+  qd->tot_num_of_ans += qd->num_of_ans;
+  qd->tot_text_idx_lookups += qd->text_idx_lookups;
+  qd->hops_taken = qd->num_of_ptrs = 0;
+  qd->num_of_accum = qd->num_of_ans = qd->num_of_terms = 0;
+  qd->text_idx_lookups = 0;
+  
+  LinePtr = ProcessCommands (line, qd);
+  if (CommandsErrorStr) {
+    fprintf (stderr, "%s\n", CommandsErrorStr);
+    return 0;
+  }
+  if (*LinePtr == '\0') return 1;
+  
+  FreeQueryDocs (qd);
+  
+  QueryType = get_query_type ();
+  OutputType = get_output_type ();
+  /* No point in hiliting words on a docnum query */
+  if (OutputType == OUTPUT_HILITE && QueryType == QUERY_DOCNUMS)
+    OutputType = OUTPUT_TEXT;
+  
+  switch (QueryType)
+    {
+    case QUERY_BOOLEAN:
+      {
+	char *maxdocs = (char *)NULL;
+	BooleanQueryInfo bqi;
+	maxdocs = GetDefEnv ("maxdocs", "all");
+	bqi.MaxDocsToRetrieve = strcmp (maxdocs, "all") ? atoi (maxdocs) : -1;
+        if (qd->sd->sdh.indexed)
+	  BooleanQuery (qd, line, &bqi, (BooleanEnv (GetEnv ("casefold"), 0) |
+					 (BooleanEnv (GetEnv ("stem"), 0) << 1)));
+	else
+	  BooleanQuery (qd, line, &bqi, qd->sd->sdh.stem_method);
+	/*	if (qd->sd->sdh.indexed) BooleanQuery (qd, line, &bqi, 3);
+	else BooleanQuery (qd, line, &bqi, qd->sd->sdh.stem_method); */
+	break;
+      }
+    case QUERY_APPROX:
+    case QUERY_RANKED:
+      {
+	char *maxdocs = (char *)NULL;
+	char *maxterms = (char *)NULL;
+	char *maxaccum = (char *)NULL;
+	RankedQueryInfo rqi;
+	maxdocs = GetDefEnv ("maxdocs", "all");
+	maxterms = GetDefEnv ("max_terms", "all");
+	maxaccum = GetDefEnv ("max_accumulators", "all");
+	rqi.Sort = BooleanEnv (GetEnv ("sorted_terms"), 0);
+	rqi.QueryFreqs = BooleanEnv (GetEnv ("qfreq"), 1);
+	rqi.Exact = QueryType == QUERY_RANKED;
+	rqi.MaxDocsToRetrieve = strcmp (maxdocs, "all") ? atoi (maxdocs) : -1;
+	rqi.MaxTerms = strcmp (maxterms, "all") ? atoi (maxterms) : -1;
+	rqi.MaxParasToRetrieve = rqi.MaxDocsToRetrieve;
+	if (qd->id->ifh.InvfLevel == 3 && GetEnv ("maxparas"))
+	  rqi.MaxParasToRetrieve = atoi (GetEnv ("maxparas"));
+	rqi.AccumMethod = toupper (*GetDefEnv ("accumulator_method", "A"));
+	rqi.MaxAccums = strcmp (maxaccum, "all") ? atoi (maxaccum) : -1;
+	rqi.HashTblSize = IntEnv (GetEnv ("hash_tbl_size"), 1000);
+	rqi.StopAtMaxAccum = BooleanEnv (GetEnv ("stop_at_max_accum"), 0);
+	rqi.skip_dump = GetEnv ("skip_dump");
+	RankedQuery (qd, line, &rqi);
+	break;
+      }
+    case QUERY_DOCNUMS:
+      {
+	DocnumsQuery (qd, line);
+	break;
+      }
+    }
+
+  return 1;
+}
+
+int mgq_numdocs(void)
+{
+  query_data *qd = NULL;
+  if (cur_cachenum == -1) return 0;
+  qd = dbcache[cur_cachenum].qd;
+  if (qd == NULL) return 0;
+
+  if (qd->DL) return qd->DL->num;
+  else return 0;
+}
+
+int mgq_numterms(void)
+{
+  query_data *qd = NULL;
+  if (cur_cachenum == -1) return 0;
+  qd = dbcache[cur_cachenum].qd;
+  if (qd == NULL) return 0;
+
+  if (qd->QTL) return qd->QTL->num;
+  else return 0;
+}
+
+int mgq_results(enum result_kinds kind,int skip,int howmany, int (*sender)(char *, int, int, float, void *), void *ptr)
+{
+  query_data *qd = NULL;
+  if (cur_cachenum == -1) return 0;
+  qd = dbcache[cur_cachenum].qd;
+  if (qd == NULL) return 0;
+
+  if (qd->DL) {
+    qd->doc_pos = 0;
+    MoreDocs(qd, kind, skip, howmany, sender, ptr);
+  }
+  return 0;
+}
+
+/* get all the terms that match wordstem using the current stemmer and */
+/* stemming method. The callback is the same style used by mgq_results */
+int mgq_equivterms (unsigned char *wordstem, int (*sender)(char *, int, int, float, void *),
+		    void *ptr) {
+  int stem_method = 0;
+  query_data *qd = NULL;
+  TermList *equivterms = NULL;  /* used for equivalent terms */
+
+  if (cur_cachenum == -1) return 0;
+  qd = dbcache[cur_cachenum].qd;
+  if (qd == NULL || wordstem == NULL || sender == NULL) return 0;
+
+  if (qd->sd->sdh.indexed) {
+    stem_method = BooleanEnv(GetEnv("casefold"),0) | (BooleanEnv(GetEnv("stem"),0) << 1);
+  } else {
+    stem_method = qd->sd->sdh.stem_method;
+  }
+
+  /* make the term list */
+  equivterms = MakeTermList (0);
+  
+  /* expand out this word */
+  if (FindWords (qd->sd, wordstem, stem_method, &equivterms) > 0) {
+    int i;
+    for (i=0; i < equivterms->num; i++) {
+      (* sender)((char *)(equivterms->TE[i].Word+1), equivterms->TE[i].Word[0], 
+		 equivterms->TE[i].Count, (float)0.0, ptr);
+    }
+  }
+
+  /* free the term list */
+  if (equivterms != NULL) FreeTermList (&equivterms);
+
+  return 0;
+}
+
+/* gets the total number of documents retrieved. If this is not available */
+/* it will set total_retrieved to 0 (even when it obviously isn't) */
+int mgq_docsretrieved (int *total_retrieved, int *is_approx) {
+  query_data *qd = NULL;
+
+  if (cur_cachenum == -1) return 0;
+  qd = dbcache[cur_cachenum].qd;
+  if (qd == NULL || total_retrieved == NULL || is_approx == NULL) return 0;
+
+  /* set default values */
+  *total_retrieved = 0;
+  *is_approx = 0;
+
+  if (qd->DL == NULL) return 0;
+
+  *total_retrieved = qd->DL->total_retrieved;
+  *is_approx = qd->DL->is_approx;
+
+  return 0;
+}
+
+
+/* use mgq_getmaxstemlen to determine the length of the word stems to pass */
+/* to mgq_stemword */
+int mgq_getmaxstemlen () {
+  return MAXSTEMLEN;
+}
+
+/* note: the stemming method and the stemmer come from the last query */
+/* "word" should be at least maxstemlen+1 long and it is a string that */
+/* starts with the string length */
+void mgq_stemword (unsigned char *word) {
+  int stem_method = 0;
+  query_data *qd = NULL;
+
+  if (cur_cachenum == -1) return;
+  qd = dbcache[cur_cachenum].qd;
+  if (qd == NULL || word == NULL) return;
+
+  if (qd->sd->sdh.indexed) {
+    stem_method = BooleanEnv(GetEnv("casefold"),0) | (BooleanEnv(GetEnv("stem"),0) << 1);
+  } else {
+    stem_method = qd->sd->sdh.stem_method;
+  }
+
+  stemmer (stem_method, qd->sd->sdh.stemmer_num, word);
+}
+
+
+
+int is_dbcache_full (void) {
+  init_dbcache ();
+  if (cache_numloaded >= MAXNUMDATABASEINFO) return 1;
+  return 0;
+}
+
+int load_database (char *collection, char *mgdir, 
+		   char *gensuffix, char *textsuffix) {
+  int i = 0;
+  query_data *qd = NULL;
+  /*  FILE *deb = NULL; */
+  init_dbcache ();
+
+  /* print out some debug information */
+/*  deb = fopen ("/home/rjmcnab/gsdl/etc/deb.txt", "a");
+  fprintf (deb, "\ncache_nextaccessnum: %i\n", cache_nextaccessnum);
+  fprintf (deb, "cache_numloaded: %i\n", cache_numloaded);
+  fprintf (deb, "cur_cachenum: %i\n", cur_cachenum);
+  fprintf (deb, "MAXNUMDATABASEINFO: %i\n\n", MAXNUMDATABASEINFO);
+  for (i=0; i<MAXNUMDATABASEINFO; i++) {
+    fprintf (deb, "Entry %i\n", i);
+    fprintf (deb, "  accessnum: %i\n", dbcache[i].accessnum);
+    fprintf (deb, "  collection: %s\n", dbcache[i].collection);
+    fprintf (deb, "  mgdir: %s\n", dbcache[i].mgdir);
+    fprintf (deb, "  gensuffix: %s\n", dbcache[i].gensuffix);
+    fprintf (deb, "  textsuffix: %s\n", dbcache[i].textsuffix);
+    fprintf (deb, "  qd: %x\n", (int)(dbcache[i].qd));
+  }
+  fclose (deb); */
+
+  /* search for the index */
+  i = search_gensuffix (gensuffix);
+  if (i >= 0) {
+    make_current (i);
+    return 1;
+  }
+
+  /* if there was a current database then the */
+  /* environment needs uninitialising */
+  make_current (-1);
+
+  /* get a free cache number */
+  i = get_free_dbcache ();
+  unload_database (i);
+
+  /* load the index */
+  qd = InitQuerySystem (mgdir, gensuffix, textsuffix, NULL);
+  if (qd == NULL) return 0;
+
+  /* cache this index */
+  cache_database (i, collection, mgdir, gensuffix, textsuffix, qd);
+
+  /* make this index current */
+  make_current (i);
+
+  return 1;
+}
+
+/* load_text_database tries to make an index of the */
+/* specified collection current */
+int load_text_database (char *collection) {
+  int i = 0;
+  init_dbcache ();
+
+  /* search for the index */
+  i = search_collect (collection);
+
+  /* return if none were found */
+  if (i < 0) return 0;
+  
+  /* make this index current */
+  make_current (i);
+  return 1;
+}
+
+void close_all_databases (void) {
+  int i = 0;
+  init_dbcache ();
+  
+  /* unload all active databases */
+  for (i=0; i<MAXNUMDATABASEINFO; i++) {
+    unload_database (i);
+  }
+
+  /* if there was a current database then the */
+  /* environment needs uninitialising */
+  make_current (-1);
+}
Index: /gsdl/trunk/runtime-src/src/colservr/mgq.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgq.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgq.h	(revision 16571)
@@ -0,0 +1,78 @@
+/**********************************************************************
+ *
+ * mgq.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef MGQ_H
+#define MGQ_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+  
+enum result_kinds {
+  result_docs,      /* Return the documents found in last search */
+  result_docnums,   /* Return document id numbers and weights */
+  result_termfreqs, /* Return terms and frequencies */
+  result_terms      /* Return matching query terms */
+};
+
+int mgq_ask(char *line);
+int mgq_results(enum result_kinds kind, int skip, int howmany,
+		int (*sender)(char *, int, int, float, void *), void *ptr);
+int mgq_numdocs(void);
+int mgq_numterms(void);
+
+/* get all the terms that match wordstem using the current stemmer and */
+/* stemming method. The callback is the same style used by mgq_results */
+int mgq_equivterms (unsigned char *wordstem, int (*sender)(char *, int, int, float, void *),
+		    void *ptr);
+
+/* gets the total number of documents retrieved. If this is not available */
+/* it will set total_retrieved to 0 (even when it obviously isn't) */
+int mgq_docsretrieved (int *total_retrieved, int *is_approx);
+  
+/* use mgq_getmaxstemlen to determine the length of the word stems to pass */
+/* to mgq_stemword */
+int mgq_getmaxstemlen ();
+
+/* note: the stemming method and the stemmer come from the last query */
+/* "word" should be at least maxstemlen+1 long and it is a string that */
+/* starts with the string length */
+void mgq_stemword (unsigned char *word);
+
+  
+int is_dbcache_full (void);
+int load_database (char *collection, char *mgdir, char *gensuffix, char *textsuffix);
+int load_text_database (char *collection);
+void close_all_databases (void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/mgqueryfilter.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgqueryfilter.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgqueryfilter.cpp	(revision 16571)
@@ -0,0 +1,533 @@
+/**********************************************************************
+ *
+ * mgqueryfilter.cpp -- implementation of queryfilter for old mg 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "mgqueryfilter.h"
+#include "fileutil.h"
+#include "phrasesearch.h"
+#include "mgsearch.h"
+#include "phrases.h"
+
+///////////////////////////////
+// methods for resultsorderer_t
+///////////////////////////////
+
+resultsorderer_t::resultsorderer_t() {
+  clear ();
+}
+
+void resultsorderer_t::clear() {
+  compare_phrase_match = false;
+  compare_terms_match = false;
+  compare_doc_weight = true;
+
+  docset = NULL;
+}
+
+bool resultsorderer_t::operator()(const text_t &t1, const text_t &t2) const {
+  if (docset == NULL) return t1>t2;
+
+  docresultmap::iterator t1_here = docset->find(t1);
+  docresultmap::iterator t2_here = docset->find(t2);
+  docresultmap::iterator end = docset->end();
+
+  // sort all the document numbers not in the document set to
+  // the end of the list
+  if (t1_here == end) {
+    if (t2_here == end) return t1>t2;
+    else return true;
+  } else if (t2_here == end) return false;
+  
+  if (compare_phrase_match) {
+    if ((*t1_here).second.num_phrase_match > (*t2_here).second.num_phrase_match) return true;
+    if ((*t1_here).second.num_phrase_match < (*t2_here).second.num_phrase_match) return false;
+  }
+
+  if (compare_terms_match) {
+    if ((*t1_here).second.num_query_terms_matched > (*t2_here).second.num_query_terms_matched) return true;
+    if ((*t1_here).second.num_query_terms_matched < (*t2_here).second.num_query_terms_matched) return false;
+  }
+
+  if (compare_doc_weight) {
+    if ((*t1_here).second.docweight > (*t2_here).second.docweight) return true;
+    if ((*t1_here).second.docweight < (*t2_here).second.docweight) return false;
+  }
+
+  return t1>t2;
+}
+
+
+
+
+/////////////////////////////////
+// functions for mgqueryfilterclass
+/////////////////////////////////
+
+
+void mgqueryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
+  queryfilterclass::configure (key, cfgline);
+
+  if (key == "indexstem") {
+    ((mgsearchclass *)textsearchptr)->set_indexstem (cfgline[0]);
+  }
+  
+}
+
+// loads up phrases data structure with any phrases (that's the quoted bits)
+// occuring in the querystring
+void mgqueryfilterclass::get_phrase_terms (const text_t &querystring, 
+					 const termfreqclassarray &orgterms,
+					 vector<termfreqclassarray> &phrases) {
+
+  text_t::const_iterator here = querystring.begin();
+  text_t::const_iterator end = querystring.end();
+
+  termfreqclassarray tmpterms;
+
+  int termcount = 0;
+  bool foundquote = false;
+  bool foundbreak = false;
+  bool start = true;
+  while (here != end) {
+    if (*here == '\"') {
+      if (foundquote) {
+	if (!foundbreak && !start) {
+	  tmpterms.push_back (orgterms[termcount]);
+	  ++termcount;
+	}
+	if (tmpterms.size() > 1) {
+	  phrases.push_back (tmpterms);
+	}
+	tmpterms.erase (tmpterms.begin(), tmpterms.end());
+	
+	foundquote = false;
+	foundbreak = true;
+      } else foundquote = true;
+    } else if (!is_unicode_letdig(*here)) {
+      // found a break between terms
+      if (!foundbreak && !start) {
+	if (foundquote) {
+	  tmpterms.push_back (orgterms[termcount]);
+	}
+	++termcount;
+      }
+      foundbreak = true;
+    } else {
+      start = false;
+      foundbreak = false;
+    }      
+    ++here;
+  }
+}
+
+// do aditional query processing
+void mgqueryfilterclass::post_process (const queryparamclass &queryparams, 
+				     queryresultsclass &queryresults) {
+
+  // post-process the results if needed
+  if (queryresults.orgterms.size() > 1 && !queryresults.docs.docset.empty()) {
+
+    // get the terms between quotes (if any)
+    vector<termfreqclassarray> phrases;
+    get_phrase_terms (queryparams.querystring, queryresults.orgterms, phrases);
+
+    num_phrases = phrases.size();
+    if (num_phrases > 0) {
+
+      // get the long version of the index
+      text_t longindex;
+      indexmap.to2from (queryparams.index, longindex);
+      
+      vector<termfreqclassarray>::const_iterator this_phrase = phrases.begin();
+      vector<termfreqclassarray>::const_iterator end_phrase = phrases.end();
+
+      while (this_phrase != end_phrase) {
+
+	// process each of the matched documents
+	docresultmap::iterator docs_here = queryresults.docs.docset.begin();
+	docresultmap::iterator docs_end = queryresults.docs.docset.end();
+	while (docs_here != docs_end) {
+	  if (OID_phrase_search (*((mgsearchclass*)textsearchptr), *db_ptr, queryparams.index,
+				 queryparams.subcollection, queryparams.language, 
+				 longindex, queryparams.collection, *this_phrase,
+				 (*docs_here).second.docnum)) {
+	    ++docs_here->second.num_phrase_match;
+	  }
+	
+	  ++docs_here;
+	}
+	++this_phrase;
+      }
+    }
+  }
+}
+
+
+// do query that might involve multiple sub queries
+// textsearchptr and db_ptr are assumed to be valid
+void mgqueryfilterclass::do_multi_query (const FilterRequest_t &request,
+				       const vector<queryparamclass> &query_params,
+				       queryresultsclass &multiresults,
+				       comerror_t &err, ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  err = noError;
+  textsearchptr->setcollectdir (collectdir);
+
+  multiresults.clear();
+  
+  vector<queryparamclass>::const_iterator query_here = query_params.begin();
+  vector<queryparamclass>::const_iterator query_end = query_params.end();
+  while (query_here != query_end) {
+    queryresultsclass thisqueryresults;
+
+    if (!textsearchptr->search(*query_here, thisqueryresults)) {
+      // most likely a system problem
+      logout << text_t2ascii
+	     << "system problem: could not do search with mg for index \""
+	     << (*query_here).index << (*query_here).subcollection
+	     << (*query_here).language << "\".\n\n";
+      err = systemProblem;
+      return;
+    }
+
+    // combine the results
+    if (need_matching_docs (request.filterResultOptions)) {
+      // post-process the results if needed
+      if (!thisqueryresults.postprocessed && thisqueryresults.orgterms.size() > 1 &&
+	  !thisqueryresults.docs.docset.empty()) {
+	post_process (*query_here, thisqueryresults);
+	thisqueryresults.postprocessed = true;
+	multiresults.postprocessed = true;
+      } else {
+	num_phrases = 0;
+      }
+      
+      if (query_params.size() == 1) {
+	multiresults.docs = thisqueryresults.docs; // just one set of results
+	multiresults.docs_matched = thisqueryresults.docs_matched;
+	multiresults.is_approx = thisqueryresults.is_approx;
+	
+      } else {
+	if ((*query_here).combinequery == "and") {
+	  multiresults.docs.combine_and (thisqueryresults.docs);
+	} else if ((*query_here).combinequery == "or") {
+	  multiresults.docs.combine_or (thisqueryresults.docs);
+	} else if ((*query_here).combinequery == "not") {
+	  multiresults.docs.combine_not (thisqueryresults.docs);
+	}
+	multiresults.docs_matched = multiresults.docs.docset.size();
+	multiresults.is_approx = Exact;
+      }
+    }
+
+    // combine the term information 
+    if (need_term_info (request.filterResultOptions)) {
+      // append the terms
+      multiresults.orgterms.insert(multiresults.orgterms.end(),
+				   thisqueryresults.orgterms.begin(),
+				   thisqueryresults.orgterms.end());
+
+      // add the term variants
+      text_tset::iterator termvar_here = thisqueryresults.termvariants.begin();
+      text_tset::iterator termvar_end = thisqueryresults.termvariants.end();
+      while (termvar_here != termvar_end) {
+	multiresults.termvariants.insert(*termvar_here);
+	++termvar_here;
+      }
+    }
+   
+    ++query_here;
+  }
+
+  // sort and unique the query terms
+  multiresults.sortuniqqueryterms ();
+}
+
+
+void mgqueryfilterclass::sort_doc_results (const FilterRequest_t &/*request*/,
+					 docresultsclass &docs) {
+  resultsorderer_t resultsorderer;
+  resultsorderer.compare_phrase_match = true;
+  resultsorderer.docset = &(docs.docset);
+
+  // first get a list of document numbers
+  docs.docnum_order();
+
+  sort (docs.docorder.begin(), docs.docorder.end(), resultsorderer);
+}
+
+
+
+mgqueryfilterclass::mgqueryfilterclass () 
+  :queryfilterclass() {
+
+  num_phrases = 0;
+}
+
+mgqueryfilterclass::~mgqueryfilterclass () {
+}
+
+void mgqueryfilterclass::filter (const FilterRequest_t &request,
+			       FilterResponse_t &response,
+			       comerror_t &err, ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  response.clear ();
+  err = noError;
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: mgqueryfilter contains a null dbclass\n\n";
+    err = configurationError;
+    return;
+  }
+  if (textsearchptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: mgqueryfilter contains a null textsearchclass (mg)\n\n";
+    err = configurationError;
+    return;
+  }
+
+  // open the database
+  db_ptr->setlogout(&logout);
+  if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {
+    // most likely a system problem (we have already checked that the database exists)
+    logout << text_t2ascii
+	   << "system problem: open on database \"" << db_filename << "\" failed\n\n";
+    err = systemProblem;
+    return;
+  }
+
+  // get the query parameters
+  int startresults = filterOptions["StartResults"].defaultValue.getint();
+  int endresults = filterOptions["EndResults"].defaultValue.getint();
+  text_t phrasematch = filterOptions["PhraseMatch"].defaultValue;
+
+  vector<queryparamclass> queryfilterparams;
+  parse_query_params (request, queryfilterparams, startresults, 
+		      endresults, phrasematch, logout);
+  // do any mg specific diddling with query parameters that may be required
+  mg_parse_query_params (request, queryfilterparams, startresults, 
+			 endresults, phrasematch, logout);
+
+
+  // do query
+  queryresultsclass queryresults;
+  do_multi_query (request, queryfilterparams, queryresults, err, logout);
+  if (err != noError) return;
+  
+  // assemble document results
+  if (need_matching_docs (request.filterResultOptions)) {
+    // sort the query results
+    // only want to sort the docs if we have done a ranked search or there were phrases
+    if (num_phrases > 0 || (request.filterResultOptions & FRranking)) {
+      sort_doc_results (request, queryresults.docs);
+    }
+    int resultnum = 1;
+    ResultDocInfo_t resultdoc;
+    text_t trans_OID;
+    vector<text_t>::iterator docorder_here = queryresults.docs.docorder.begin();
+    vector<text_t>::iterator docorder_end = queryresults.docs.docorder.end();
+
+    // documents containing matching phrases will be sorted to the top so
+    // we can break out once we're past those that match the PhraseMatch
+    // option -- "all_phrases" = return only those documents containing all
+    //	                     phrases in query string
+    //           "some_phrases" = return only those documents containing 
+    //                            at least 1 of the phrases in the document
+    //           "all_docs" = return all documents regardless
+    if (num_phrases > 0) {
+      int numdocs = 0;
+      while (docorder_here != docorder_end) {
+	docresultmap::iterator docset_here = queryresults.docs.docset.find (*docorder_here);
+	
+	if (((phrasematch == "all_phrases") && ((*docset_here).second.num_phrase_match < num_phrases)) ||
+	    ((phrasematch == "some_phrases") && ((*docset_here).second.num_phrase_match < 1))) {
+	  queryresults.docs_matched = numdocs;
+	  break;
+	}
+	++numdocs;
+	++docorder_here;
+      }
+    }
+
+    if (endresults == -1) endresults = MAXNUMDOCS;
+    docorder_here = queryresults.docs.docorder.begin();
+    while (docorder_here != docorder_end) {
+      if (resultnum > endresults || resultnum > queryresults.docs_matched) break;
+      
+      // translate the document number
+      if (!translate(db_ptr, *docorder_here, trans_OID)) {
+	logout << text_t2ascii
+	       << "warning: could not translate mg document number \""
+	       << *docorder_here << "\"to OID.\n\n";
+	
+      } else {
+	docresultmap::iterator docset_here = queryresults.docs.docset.find (*docorder_here);
+
+	// see if there is a result for this number,
+	// if it is in the request set (or the request set is empty)
+	if (docset_here != queryresults.docs.docset.end() &&
+	    (request.docSet.empty() || in_set(request.docSet, trans_OID))) {
+	  if (resultnum >= startresults) {
+	    // add this document
+	    resultdoc.OID = trans_OID;
+	    resultdoc.result_num = resultnum;
+	    resultdoc.ranking = (int)((*docset_here).second.docweight * 10000.0 + 0.5);
+
+	    // these next two are not available on all versions of mg
+	    resultdoc.num_terms_matched = (*docset_here).second.num_query_terms_matched; 
+	    resultdoc.num_phrase_match = (*docset_here).second.num_phrase_match;
+	    
+	    response.docInfo.push_back (resultdoc);
+	  }
+	  
+	  ++resultnum;
+	}
+      }
+      
+      ++docorder_here;
+    }
+  }
+
+  // assemble the term results
+  if (need_term_info(request.filterResultOptions)) {
+    // note: the terms have already been sorted and uniqued
+
+    TermInfo_t terminfo;
+    bool terms_first = true;
+    termfreqclassarray::iterator terms_here = queryresults.terms.begin();
+    termfreqclassarray::iterator terms_end = queryresults.terms.end();
+
+    while (terms_here != terms_end) {
+      terminfo.clear();
+      terminfo.term = (*terms_here).termstr;
+      terminfo.freq = (*terms_here).termfreq;
+      if (terms_first) {
+	text_tset::iterator termvariants_here = queryresults.termvariants.begin();
+	text_tset::iterator termvariants_end = queryresults.termvariants.end();
+	while (termvariants_here != termvariants_end) {
+	  terminfo.matchTerms.push_back (*termvariants_here);
+	  ++termvariants_here;
+	}
+      }
+      terms_first = false;
+
+      response.termInfo.push_back (terminfo);
+
+      ++terms_here;
+    }
+  }
+
+  db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+  response.numDocs = queryresults.docs_matched;
+  response.isApprox = queryresults.is_approx;
+}
+
+void mgqueryfilterclass::mg_parse_query_params (const FilterRequest_t &/*request*/,
+						vector<queryparamclass> &query_params,
+						int &/*startresults*/, int &/*endresults*/,
+						text_t &/*phrasematch*/, ostream &/*logout*/) {
+
+  //  outconvertclass text_t2ascii;
+  
+  vector<queryparamclass>::iterator query_here = query_params.begin();
+  vector<queryparamclass>::iterator query_end = query_params.end();
+  while (query_here != query_end) {
+
+    // if we're doing a phrase search we want to maximise hits by making it
+    // a boolean search on the index with the finest granularity - we'll
+    // also set maxdocs to "all" (realizing that this will cause searches
+    // like "and the" on a large collection to take a very very long time).
+
+    // we're deciding it's a phrase search based on if the querystring 
+    // contains at least 2 double quotes (not very scientific but 
+    // then neither is the rest of the mg phrase searching functionality :-)
+      //if (countchar ((*query_here).querystring.begin(), (*query_here).querystring.end(), '"') > 1) {
+
+    // [kjdon 12/2005] we don't want to do a phrase search if the only phrases are single words, so we'll parse out the phrases properly here
+    text_tarray phrases;
+    get_phrases((*query_here).querystring, phrases);
+
+    if (phrases.size() > 0) {
+      (*query_here).search_type = 0;
+
+      // set maxdocs to "all"
+      (*query_here).maxdocs = -1;
+
+      // Get the long version of the index and test to see if any indexes with
+      // finer granularity exist. Indexes must be the same type (i.e. same metadata
+      // or "text").
+      text_t longindex; text_tarray splitindex;
+      indexmap.to2from ((*query_here).index, longindex);
+      splitchar (longindex.begin(), longindex.end(), ':', splitindex);
+      text_t &granularity = splitindex[0];
+      text_t &indextype = splitindex[1];
+      bool found = false;
+      // currently supported granularity options are "document", "section" and "paragraph"
+      if (granularity == "document" || granularity == "section") {
+	text_t shortindex;
+	if (indexmap.fromexists ("paragraph:" + indextype)) {
+	  indexmap.from2to ("paragraph:" + indextype, shortindex);
+	  (*query_here).index = shortindex;
+	  found = true;
+	}
+	if (!found && granularity == "document" && indexmap.fromexists ("section:" + indextype)) {
+	  indexmap.from2to ("section:" + indextype, shortindex);
+	  (*query_here).index = shortindex;
+	}
+      }
+    }
+
+#ifdef GSDL_BBC_COLLECTION
+    // This is a special hack for the BBC collection's ProgNumber and zzabn
+    // indexes (they're built this way to prevent mg_perf_hash_build from
+    // dying at build time)
+
+    // if we're searching the ProgNumber index we want to
+    // remove all non-alphanumeric characters from the query string
+    text_t longindex; text_tarray splitindex;
+    indexmap.to2from ((*query_here).index, longindex);
+    splitchar (longindex.begin(), longindex.end(), ':', splitindex);
+    text_t &indextype = splitindex[1];
+    if (indextype == "ProgNumber") {
+      text_t new_querystring;
+      text_t::const_iterator here = (*query_here).querystring.begin();
+      text_t::const_iterator end = (*query_here).querystring.end();
+      while (here != end) {
+        if ((*here >= 'a' && *here <= 'z') || (*here >= 'A' && *here <= 'Z') ||
+            (*here >= '0' && *here <= '9')) {
+          new_querystring.push_back (*here);
+        }
+        ++here;
+      }
+      (*query_here).querystring = new_querystring;
+    }
+#endif
+    ++query_here;
+  }
+}
+    
Index: /gsdl/trunk/runtime-src/src/colservr/mgqueryfilter.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgqueryfilter.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgqueryfilter.h	(revision 16571)
@@ -0,0 +1,89 @@
+/**********************************************************************
+ *
+ * mgqueryfilter.h -- queryfilter for old mg
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+#ifndef MGQUERYFILTER_H
+#define MGQUERYFILTER_H
+
+#include "queryfilter.h"
+
+
+// resultsorderer_t is used to sort the query results
+struct resultsorderer_t {
+  bool compare_phrase_match;
+  bool compare_terms_match;
+  bool compare_doc_weight;
+  docresultmap *docset;
+
+  resultsorderer_t();
+  void clear();
+  bool operator()(const text_t &t1, const text_t &t2) const;
+};
+
+
+
+class mgqueryfilterclass : public queryfilterclass {
+protected:
+  
+  int num_phrases;
+
+  void get_phrase_terms (const text_t &querystring, 
+			 const termfreqclassarray &orgterms,
+			 vector<termfreqclassarray> &phrases);
+
+  // do aditional query processing
+  virtual void post_process (const queryparamclass &queryparams,
+			     queryresultsclass &queryresults);
+
+  // do query that might involve multiple sub queries
+  // mgsearchptr and db_ptr are assumed to be valid
+  void do_multi_query (const FilterRequest_t &request,
+		       const vector<queryparamclass> &query_params,
+		       queryresultsclass &multiresults,
+		       comerror_t &err, ostream &logout);
+
+  virtual void sort_doc_results (const FilterRequest_t &request,
+				 docresultsclass &docs);
+
+  virtual void mg_parse_query_params (const FilterRequest_t &request,
+				      vector<queryparamclass> &query_params,
+				      int &startresults, int &endresults,
+				      text_t &phrasematch, ostream &logout);
+
+  
+public:
+  mgqueryfilterclass ();
+  virtual ~mgqueryfilterclass ();
+
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+
+  void filter (const FilterRequest_t &request,
+	       FilterResponse_t &response,
+	       comerror_t &err, ostream &logout);
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/mgsearch.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgsearch.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgsearch.cpp	(revision 16571)
@@ -0,0 +1,569 @@
+/**********************************************************************
+ *
+ * mgsearch.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdlconf.h"
+#include "mgsearch.h"
+#include "fileutil.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+#endif
+
+  
+#include <assert.h>
+
+#include "mgq.h"
+// #include "locateinfo.h"
+#include "gsdlunicode.h"
+#include "unitool.h"
+
+
+/////////////
+// globals //
+/////////////
+
+static char *tempdoc = NULL;
+static int templen = 0;
+
+
+//////////////////////
+// useful functions //
+//////////////////////
+
+
+// input and output are in utf8
+text_t mgsearch_stemword (const text_t &word) {
+  // allocate working stem space
+  int maxstemlen = mgq_getmaxstemlen ();
+  unsigned char *word_stem = new unsigned char [maxstemlen + 2];
+  if (word_stem == NULL) return "";
+
+  // copy word to word_stem
+  int len = 0;
+  text_t::const_iterator here = word.begin();
+  text_t::const_iterator end = word.end();
+  while (len < maxstemlen && here != end) {
+    word_stem[len+1] = (unsigned char)(*here);
+    ++len; ++here;
+  }
+  word_stem[len+1] = '\0';
+  word_stem[0] = len;
+
+  mgq_stemword (word_stem);
+
+  // copy word_stem back to tempstr
+  text_t tempstr;
+  tempstr.setcarr((char *)(&word_stem[1]), word_stem[0]);
+
+  delete [] word_stem;
+  
+  return tempstr;
+}
+
+
+
+////////////////////////
+// callback functions //
+////////////////////////
+
+// This routine is called for each document found in a search
+// it assumes that cache_num is set up correctly to point to
+// a suitable result cache
+int ourquerycallback(char * /*UDoc*/, int /*ULen*/, int DocNum, 
+		     float Weight, void *info) {
+
+  
+  queryresultsclass *queryresults = (queryresultsclass * )info;
+
+  // append this entry to the document results
+  docresultclass docresult;
+  docresult.docnum = DocNum;
+  docresult.num_query_terms_matched = (int)(Weight/100.0); // will always be 0 on some versions of mg...
+  docresult.docweight = Weight - docresult.num_query_terms_matched*100;
+  
+  queryresults->docs.docset[DocNum] = docresult;
+  queryresults->docs.docorder.push_back(DocNum);
+  
+  return 0;
+}
+
+int termequivcallback(char *Word, int ULen,  int /*Freq*/, 
+		      float /*Weight*/,  void *info) {
+  text_tset *equivterms = (text_tset *)info;
+  if (equivterms == NULL) return 0;
+
+  text_t thisterm;
+  thisterm.setcarr(Word, ULen);
+
+  equivterms->insert(thisterm);
+  
+  return 0;
+}
+
+
+void mgsearch_equivterms (const text_t &word, text_tset &equivterms) {
+  // allocate working stem space
+  int maxstemlen = mgq_getmaxstemlen ();
+  unsigned char *word_stem = new unsigned char [maxstemlen + 2];
+  if (word_stem == NULL) return;
+
+  // copy word to word_stem
+  int len = 0;
+  text_t::const_iterator here = word.begin();
+  text_t::const_iterator end = word.end();
+  while (len < maxstemlen && here != end) {
+    word_stem[len+1] = (unsigned char)(*here);
+    ++len; ++here;
+  }
+  word_stem[len+1] = '\0';
+  word_stem[0] = len;
+
+  // get the equivalent terms
+  mgq_equivterms (word_stem, termequivcallback, (void *)(&equivterms));
+  
+  delete [] word_stem;
+
+  return;
+}
+
+  text_tset utf8equivterms; // kept as utf8 string for fast matching
+
+
+// This callback is called once for each term in the query
+int termfreqcallback(char *Word, int ULen,  int Freq, 
+		     float /*Weight*/,  void *info) {
+  queryresultsclass *queryresults = (queryresultsclass *)info;
+  if (queryresults == NULL) return 0;
+
+  text_t term;
+  term.setcarr(Word, ULen);
+  termfreqclass termfreq;
+
+  termfreq.termstr = to_uni(term);
+  text_t utf8termstem = mgsearch_stemword (term);
+  termfreq.termstemstr = to_uni (utf8termstem);
+
+  mgsearch_equivterms (utf8termstem, termfreq.utf8equivterms);
+  
+  termfreq.termfreq = Freq;
+  queryresults->orgterms.push_back(termfreq);
+  
+  return 0;
+}
+
+// this callback is called once for each variation of each term
+int termvariantscallback(char *Word, int ULen, int /*Freq*/,
+			 float /*Weight*/, void *info) {
+
+  text_t term;
+  term.setcarr(Word, ULen);
+  queryresultsclass *queryresults = (queryresultsclass *)info;
+  queryresults->termvariants.insert(to_uni(term));
+
+  return 0;
+}
+
+// This callback is for getting document text
+int doctextcallback(char *Doc, int ULen,  int /*Freq*/, 
+		    float /*Weight*/,  void * /*info*/) {
+  if (Doc != NULL) {
+    // Make a copy of this string so we can unload the database without losing it
+    tempdoc = new char[ULen + 1];
+    strcpy(tempdoc, Doc);
+  }
+  templen = ULen;
+  
+  return 0;
+}
+
+
+text_t mgsearchclass::getindexsuffix (const text_t &collection, 
+			      const text_t &index) {
+
+  text_t indexsuffix = "index";  
+  indexsuffix = filename_cat (indexsuffix, index);
+  if (indexstem.empty()) {
+    // no index stem, use the coll name
+    indexsuffix = filename_cat (indexsuffix, collection);
+  } else {
+    indexsuffix = filename_cat (indexsuffix, indexstem);
+  }
+  return indexsuffix;
+}
+
+
+
+
+////////////////////
+// mgsearch class //
+////////////////////
+
+mgsearchclass::mgsearchclass ()
+  : searchclass() {
+ 
+}
+
+mgsearchclass::~mgsearchclass () 
+{
+  if (cache != NULL) 
+    {
+      delete cache;
+      cache = NULL;
+    }
+}
+
+void mgsearchclass::set_indexstem(const text_t &stem) {
+  indexstem = stem;
+  
+}
+
+// you only need to use this function before doing any stemming
+// casefolding and stemming will be set if values for them are
+// provided (0 or 1).
+// makeindexcurrent returns true if it was able to load the database
+bool mgsearchclass::makeindexcurrent (const text_t &index,
+				      const text_t &subcollection,
+				      const text_t &language,
+				      const text_t &collection,
+				      int casefolding,
+				      int stemming) {
+  bool databaseloaded = true;
+
+  // get the names of the collection, index and text suffixes
+  char *ccollection = collection.getcstr();
+  assert (ccollection != NULL);
+  char *idxsuffix = (getindexsuffix (collection, (index+subcollection+language))).getcstr();
+  assert (idxsuffix != NULL);
+  char *txtsuffix = (getindexsuffix (collection, "text")).getcstr();
+  assert (txtsuffix != NULL);
+#ifdef __WIN32__
+  char *ccollectdir = (collectdir+"\\").getcstr(); assert (ccollectdir != NULL);
+#else
+  char *ccollectdir = collectdir.getcstr(); assert (ccollectdir != NULL);
+#endif
+
+  if (load_database(ccollection, ccollectdir, idxsuffix, txtsuffix)) {
+    if (casefolding == 0) mgq_ask(".set casefold off");
+    else if (casefolding > 0) mgq_ask(".set casefold on");
+    if (stemming == 0) mgq_ask(".set stem off");
+    else if (stemming > 0) mgq_ask(".set stem on");
+    
+  } else databaseloaded = false;
+
+  // free up the c strings
+  delete []ccollection;
+  delete []idxsuffix;
+  delete []txtsuffix;
+  delete []ccollectdir;
+
+  return databaseloaded;
+}
+
+
+// stem word uses the values set in the last call to makeindexcurrent
+// to stem the word. It is assumed that word is in unicode
+text_t mgsearchclass::stemword (const text_t &word) {
+  return to_uni (mgsearch_stemword (to_utf8 (word)));
+}
+
+text_t mgsearchclass::stemword (text_t::const_iterator here, text_t::const_iterator end) {
+  return to_uni (mgsearch_stemword (to_utf8 (here, end)));
+}
+
+/**
+ * search directs the whole execution of the search; a number of other
+ * functions in this class are called as a result, and precondition
+ * checks are also made
+ */
+bool mgsearchclass::search(const queryparamclass &queryparams, 
+			   queryresultsclass &queryresults) {
+  //  assert (cache != NULL);
+
+  // clear any previous results
+  queryresults.clear();
+  // first check the cache
+  if (cache != NULL) {
+    if (cache->find(queryparams, queryresults)) return true;
+  }
+  // make sure there is a query to be processed
+  if (!has_unicode_letdig(queryparams.querystring)) return true;
+
+  if (makeindexcurrent (queryparams.index, queryparams.subcollection,
+			queryparams.language, queryparams.collection)) {
+    // initialise the form of results
+    setsearchmode (queryparams);
+
+    // execute the query
+    submitquery (queryparams);
+
+    // retrieve the results
+    getresults (queryparams, queryresults);
+    unload_database();  // Important that local library doesn't leave any files open
+    return true;
+  }
+
+  return false;
+}
+
+/* accumulator_method has been changed to use array rather than list.
+list appears to be broken somewhat - for some ranked queries, it returned 
+fewer results than it should have (eg 45 instead of 50). The three other
+methods (array, splay_tree, hash_table) all return the same number of 
+documents, in the same order, with the same ranks. list returns what 
+appears to be the same documents (but less of them), but with different ranks,
+and in a different order. Minimal time tests dont show any speed improvement
+of list over array (maybe because its broken??).  [02/2001, kjm18]
+
+... [sjboddie, also 02/2001] turns out that changing the accumulator_method
+introduced a more serious bug than it fixed (i.e. occasionally when doing a
+ranked search for a very common word you get no results at all). I've
+changed it back to list for now, one day we should play with other
+accumulator_methods but for now I don't have time and don't want to risk
+introducing bugs (better the devil you know ;)
+*/
+void mgsearchclass::setsearchmode (const queryparamclass &queryparams)
+{
+  mgq_ask(".set expert true");
+  mgq_ask(".set sorted_terms true");
+  mgq_ask(".set accumulator_method list");
+  mgq_ask(".set max_accumulators 500000");
+  mgq_ask(".set maxparas 500000");
+  mgq_ask(".set verbatim true");
+  mgq_ask(".unset skip_dump");
+  mgq_ask(".set mode docnums");
+
+  switch (queryparams.search_type) 
+    {
+    case 0: mgq_ask(".set query boolean");  break;
+    case 1:  mgq_ask(".set query ranked"); break;
+    }
+  switch (queryparams.casefolding) 
+    {
+    case 1: mgq_ask(".set casefold on");  break;
+    case 0: mgq_ask(".set casefold off"); break;
+    }
+  switch (queryparams.stemming) 
+    {
+    case 1: mgq_ask(".set stem on");  break;
+    case 0: mgq_ask(".set stem off"); break;
+    }
+  mgq_ask(".set heads_length 150");
+  
+  if (queryparams.maxdocs == -1) {
+    mgq_ask(".set maxdocs all");
+  } else {
+    char maxdocstr[32];
+    sprintf(maxdocstr, ".set maxdocs %i", queryparams.maxdocs);
+    mgq_ask(maxdocstr);
+  }
+
+  char maxnumericstr[32];
+  sprintf(maxnumericstr, ".set maxnumeric %i", queryparams.maxnumeric);
+  mgq_ask(maxnumericstr);
+  
+}
+
+/**
+ * submitquery constructs the query string (into UTF8 encoding)
+ * and submits it using mgq_ask to the mg search engine.  Most
+ * of the processing will be done inside Greenstone
+ */
+void mgsearchclass::submitquery (const queryparamclass &queryparams)
+{
+  // sort out the query string; copy it, remove all special characters
+  // and then convert it to a string in UTF8 format
+  text_t ttquerystring = queryparams.querystring;
+  filterquery (ttquerystring);
+  char *querystring = to_utf8(ttquerystring).getcstr();
+
+  // submit the query
+  mgq_ask(querystring);
+
+  // destroy the temporary character array
+  delete []querystring;
+}
+
+/**
+ * getrults is called to retrieve the required data on the docs
+ * which responded to the query submitted in submitquery above.
+ *
+ * It calls the local mgquery (mgq) interface to MG several times,
+ * to obtain the document numbers, term frequencies, term variants
+ * etc.  All processing of the query will be done by Greenstone
+ * thereafter
+ */
+void mgsearchclass::getresults (const queryparamclass &queryparams,
+				queryresultsclass &queryresults) {
+  // get the configuration for the maximum number of documents to
+  // retrieve
+  int howmany = queryparams.maxdocs;
+  if (howmany == -1) howmany = MAXNUMDOCS;
+  mgq_results(result_docnums, 0, howmany, 
+	      ourquerycallback, (void *)(&queryresults));
+  
+  // get the term frequencies
+  mgq_results(result_termfreqs, 0, MAXNUMTERMS, 
+	      termfreqcallback, (void *)(&queryresults));
+  queryresults.sortuniqqueryterms();
+
+  // get term variants 
+  mgq_results(result_terms, 0, MAXNUMTERMS,
+              termvariantscallback, (void *)(&queryresults));
+
+  // get the number of documents retrieved
+  int total_retrieved = 0, is_approx = 0;
+  mgq_docsretrieved (&total_retrieved, &is_approx);
+
+  if (total_retrieved == 0) {
+    // not available (or really was zero)
+    queryresults.docs_matched = queryresults.docs.docset.size();
+    if ((queryparams.maxdocs == -1) ||
+	(queryresults.docs_matched < queryparams.maxdocs))
+      queryresults.is_approx = Exact;
+    else
+      queryresults.is_approx = MoreThan;
+  } else {
+    queryresults.docs_matched = total_retrieved;
+    if (is_approx) queryresults.is_approx = Approximate;
+    else queryresults.is_approx = Exact;
+  }
+}
+
+/**
+ * Tidies the given querystring, removing special characters
+ */
+void mgsearchclass::filterquery (text_t &ttquerystring) {
+  text_t::iterator ithere = ttquerystring.begin ();
+  text_t::iterator itend = ttquerystring.end ();
+  
+  // remove all non alphanumeric characters (except
+  // boolean operators
+  while (ithere != itend) {
+    if ((!is_unicode_letdig(*ithere)) && (*ithere != '!') &&
+	(*ithere != '&') && (*ithere != '|') && (*ithere != '(') &&
+	(*ithere != ')')) (*ithere) = ' ';
+    ++ithere;
+  }
+}
+
+
+// the document text for 'docnum' is placed in 'output'
+// docTargetDocument returns 'true' if it was able to
+// try to get a document
+// collection is needed to see if an index from the 
+// collection is loaded. If no index has been loaded
+// defaultindex is needed to load one
+bool mgsearchclass::docTargetDocument(const text_t &defaultindex,
+				      const text_t &defaultsubcollection,
+				      const text_t &defaultlanguage,
+				      const text_t &collection,
+				      int docnum,
+				      text_t &output) {
+  output.clear();
+
+  // get the mg version of the document
+  char *mgdoc = NULL;
+  int doclen = 0;
+  if (!mgdocument (defaultindex, defaultsubcollection, defaultlanguage,
+		   collection, docnum, mgdoc, doclen)) return false;
+  if (mgdoc == NULL) return false;
+
+  // replace all control-Cs with spaces
+  char *mgdoc_here = mgdoc;
+  char *mgdoc_end = mgdoc + doclen;
+  while (mgdoc_here < mgdoc_end) {
+    if (*mgdoc_here == '\x3') *mgdoc_here = ' ';
+    ++mgdoc_here;
+  }
+
+  // convert this document to unicode
+  utf8inconvertclass inconvert;
+  convertclass::status_t status;
+  inconvert.reset ();
+  inconvert.setinput (mgdoc, doclen);
+  inconvert.convert (output, status);
+
+  delete[] mgdoc;
+  return true;
+}
+
+
+bool mgsearchclass::mgdocument (const text_t &defaultindex, 
+				const text_t &defaultsubcollection,
+				const text_t &defaultlanguage,
+				const text_t &collection,
+				int docnum,
+				char *&UDoc, int &ULen) {
+  int databaseloaded = 0;
+
+  UDoc = NULL; ULen = 0;
+  
+  // see if we can make an appropriate database current
+//    char *ccollection = collection.getcstr();
+//    assert (ccollection != NULL);
+//    databaseloaded = load_text_database (ccollection);
+//    delete []ccollection;
+  
+  // try and load the database
+//    if (!databaseloaded)
+  databaseloaded = makeindexcurrent (defaultindex, defaultsubcollection,
+				     defaultlanguage, collection);
+  
+  if (databaseloaded) {
+    // retrieve the document from mg
+    char docstr[32];
+    sprintf(docstr, "%i", docnum);
+    
+    mgq_ask(".set mode text");
+    mgq_ask(".set query docnums");
+    mgq_ask(docstr);
+
+    tempdoc = NULL;
+    templen = 0;
+    mgq_results (result_docs, 0, 1, doctextcallback, (void *)NULL);
+    UDoc = tempdoc;
+    ULen = templen;
+  }
+
+  unload_database();  // Important that local library doesn't leave any files open
+  return (bool)databaseloaded;
+}
+
+// unload_database simply calls mgq's close_all_databases function to clear
+// any cached databases - this is useful when attempting to completely
+// remove all trace of a collectionserver at runtime (when using a
+// persistent version of Greenstone like the windows local library)
+void mgsearchclass::unload_database () {
+  close_all_databases();
+}
Index: /gsdl/trunk/runtime-src/src/colservr/mgsearch.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgsearch.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgsearch.h	(revision 16571)
@@ -0,0 +1,101 @@
+/**********************************************************************
+ *
+ * mgsearch.h --  implementation of search for old versions of mg
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef MGSEARCH_H
+#define MGSEARCH_H
+
+
+#include "search.h"
+
+class mgsearchclass : public searchclass {
+public:
+  mgsearchclass ();
+  virtual ~mgsearchclass ();
+
+  virtual text_t get_textindex_type() {return "mg";}
+
+  // you only need to use this function before doing any stemming
+  // casefolding and stemming will be set if values for them are
+  // provided (0 or 1).
+  // makeindexcurrent returns true if it was able to load the database
+  bool makeindexcurrent (const text_t &index, const text_t &subcollection,
+			 const text_t &language, const text_t &collection,
+			 int casefolding = -1, int stemming = -1);
+
+  // stem word uses the values set in the last call to makeindexcurrent
+  // to stem the word. It is assumed that word is in unicode
+  text_t stemword (const text_t &word);
+  text_t stemword (text_t::const_iterator here, text_t::const_iterator end);
+  
+  // the search results are returned in queryresults
+  // search returns 'true' if it was able to do a search
+  bool search(const queryparamclass &queryparams, 
+	      queryresultsclass &queryresults);
+  
+  // the document text for 'docnum' is placed in 'output'
+  // docTargetDocument returns 'true' if it was able to
+  // try to get a document
+  // collection is needed to see if an index from the 
+  // collection is loaded. If no index has been loaded
+  // defaultindex is needed to load one
+  bool docTargetDocument(const text_t &defaultindex,
+			 const text_t &defaultsubcollection,
+			 const text_t &defaultlanguage,
+			 const text_t &collection,
+			 int docnum,
+			 text_t &output);
+
+  // same as docTargetDocument except the document is returned
+  // in its raw form. UDoc remains the property of mg and may
+  // be destroyed on the next call to mg.
+  bool mgdocument (const text_t &defaultindex,
+		   const text_t &defaultsubcollection,
+		   const text_t &defaultlanguage,
+		   const text_t &collection,
+		   int docnum,
+		   char *&UDoc, int &ULen);
+
+  // unload_database simply calls mgq's close_all_databases function to
+  // clear any cached databases - this is useful when attempting to
+  // completely remove all trace of a collectionserver at runtime (when
+  // using a persistent version of Greenstone like the windows local
+  // library)
+  void unload_database ();
+
+  void set_indexstem(const text_t &indexstem);
+
+protected:
+
+  text_t indexstem; // the stem of the index files - defaults to the collectionname
+  void setsearchmode (const queryparamclass &queryparams);
+  void submitquery (const queryparamclass &queryparams);
+  void getresults (const queryparamclass &queryparams, queryresultsclass &queryresults);
+  text_t getindexsuffix (const text_t &collection, const text_t &index);
+  virtual void filterquery (text_t &ttquerystring);
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/mgsource.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgsource.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgsource.cpp	(revision 16571)
@@ -0,0 +1,38 @@
+/**********************************************************************
+ *
+ * mgsource.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "mgsource.h"
+
+
+mgsourceclass::mgsourceclass () 
+  : sourceclass()
+{
+  classname = "mgsource";
+}
+
+mgsourceclass::~mgsourceclass () 
+{
+}
+
Index: /gsdl/trunk/runtime-src/src/colservr/mgsource.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/mgsource.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/mgsource.h	(revision 16571)
@@ -0,0 +1,41 @@
+/**********************************************************************
+ *
+ * mgsource.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef MGSOURCE_H
+#define MGSOURCE_H
+
+#include "source.h"
+
+
+class mgsourceclass : public sourceclass {
+public:
+  mgsourceclass ();
+  virtual ~mgsourceclass ();
+
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/phrasequeryfilter.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/phrasequeryfilter.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/phrasequeryfilter.cpp	(revision 16571)
@@ -0,0 +1,84 @@
+/**********************************************************************
+ *
+ * phrasequeryfilter.cpp -- 
+ * Copyright (C) 1999  DigiLib Systems Limited, New Zealand
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "phrasequeryfilter.h"
+#include "queryinfo.h"
+
+#include "phrasesearch.h"
+
+
+
+// do aditional query processing
+void phrasequeryfilterclass::post_process (const queryparamclass &queryparams,
+					   queryresultsclass &queryresults) {
+  bool results_shrunk = false;
+
+  // post-process the results if needed
+  if (queryresults.orgterms.size() > 1 && !queryresults.docs.docset.empty()) {
+    // get the long version of the index
+    text_t longindex;
+    indexmap.to2from (queryparams.index, longindex);
+      
+    // process each of the matched documents
+    docresultmap::iterator docs_here = queryresults.docs.docset.begin();
+    docresultmap::iterator docs_end = queryresults.docs.docset.end();
+    while (docs_here != docs_end) {
+      if ((*docs_here).second.num_query_terms_matched == queryresults.orgterms.size() &&
+	  OID_phrase_search (*(mgsearchclass *)textsearchptr, *db_ptr, queryparams.index,
+			     queryparams.subcollection, queryparams.language, 
+			     longindex, queryparams.collection, queryresults.orgterms,
+			     (*docs_here).second.docnum)) {
+	++docs_here->second.num_phrase_match;
+	++docs_here;
+
+      } else {
+	docresultmap::iterator this_doc_here = docs_here;
+	++docs_here;
+	if (queryparams.match_mode == 1) {
+	  // need to delete this element, there was no exact match
+	  queryresults.docs.docset.erase(this_doc_here);
+	  results_shrunk = true;
+	}
+      }
+    }
+  }
+
+  if (results_shrunk) queryresults.docs_matched = queryresults.docs.docset.size();
+}
+
+
+void phrasequeryfilterclass::sort_doc_results (const FilterRequest_t &/*request*/,
+					 docresultsclass &docs) {
+  resultsorderer_t resultsorderer;
+  resultsorderer.compare_phrase_match = true;
+  resultsorderer.compare_terms_match = true;
+  resultsorderer.compare_doc_weight = true;
+  resultsorderer.docset = &(docs.docset);
+
+  // first get a list of document numbers
+  docs.docnum_order();
+
+  sort (docs.docorder.begin(), docs.docorder.end(), resultsorderer);
+}
Index: /gsdl/trunk/runtime-src/src/colservr/phrasequeryfilter.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/phrasequeryfilter.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/phrasequeryfilter.h	(revision 16571)
@@ -0,0 +1,43 @@
+/**********************************************************************
+ *
+ * phrasequeryfilter.h -- 
+ * Copyright (C) 1999  DigiLib Systems Limited, New Zealand
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef PHRASEQUERYFILTER_H
+#define PHRASEQUERYFILTER_H
+
+#include "mgqueryfilter.h"
+
+
+class phrasequeryfilterclass : public mgqueryfilterclass {
+protected:
+  void post_process (const queryparamclass &queryparams,
+		     queryresultsclass &queryresults);
+  void sort_doc_results (const FilterRequest_t &request,
+			 docresultsclass &docs);
+public:
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/phrasesearch.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/phrasesearch.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/phrasesearch.cpp	(revision 16571)
@@ -0,0 +1,259 @@
+/**********************************************************************
+ *
+ * phrasesearch.cpp -- tools to search for a phrase in a larger text
+ * Copyright (C) 1999  DigiLib Systems Limited
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "phrasesearch.h"
+#include "gsdlunicode.h"
+
+inline unsigned char *parse_nonword_word (unsigned char *here, unsigned char *end,
+					  text_t &word) {
+  int c_len = 0;
+  unsigned short c = 0;
+
+  word.clear();
+
+  // parse non word
+  while (here <= end) {
+    c_len = parse_utf8_char (here, end, &c);
+    if (c == '(') {
+      // found a note, look for '}'
+      while (here <= end && c != ')') {
+	c_len = parse_utf8_char (here, end, &c);
+	here += c_len;
+      }
+    }
+    if (c == '{') {
+      // found a composite character, look for '}'
+      while (here <= end && c != '}') {
+	c_len = parse_utf8_char (here, end, &c);
+	here += c_len;
+      }
+    }
+    if (is_unicode_letdig(c)) {
+      while (c_len > 0) {
+	// this is in a word
+	word.push_back(*here);
+	++here; --c_len;
+      }
+      break;
+    }
+    here += c_len;
+  }
+
+  // parse word
+  while (here <= end) {
+    c_len = parse_utf8_char (here, end, &c);
+    if (!is_unicode_letdig(c)) {
+      here += c_len;  // it is ok to skip a nonword character
+      break;
+    }
+    while (c_len > 0) {
+      word.push_back(*here);
+      ++here; --c_len;
+    }
+  }
+
+  return here;
+}
+
+static void get_all_docnums (dbclass &db, text_t OID, vector<int> &docnum_list) {
+
+  infodbclass OID_info;
+  
+  // get OID
+  if (!db.getinfo (OID, OID_info)) return;
+  if (OID_info["hastxt"] == "1" && !OID_info["docnum"].empty()) {
+    docnum_list.push_back (OID_info["docnum"].getint());
+  }
+
+  // get contents set
+  if (OID_info["contains"].empty()) return;
+  text_tarray contains; text_t tmptext;
+  text_t::iterator contains_here = OID_info["contains"].begin();
+  text_t::iterator contains_end = OID_info["contains"].end();
+  while (contains_here != contains_end) {
+    if (*contains_here == '"') tmptext += OID;
+    else if (*contains_here == ';') {
+      if (!tmptext.empty()) contains.push_back (tmptext);
+      tmptext.clear();
+    } else tmptext.push_back(*contains_here);
+    ++contains_here;
+  }
+  if (!tmptext.empty()) contains.push_back (tmptext);
+
+  text_tarray::const_iterator here = contains.begin();
+  text_tarray::const_iterator end = contains.end();
+  while (here != end) {
+    get_all_docnums (db, *here, docnum_list);
+    ++here;
+  }
+}
+
+bool doc_phrase_search (unsigned char *doc, int doclen,
+			const termfreqclassarray &phrase) {
+  // note: this uses the most braindead search routine :-)
+  // however its not so bad as there shouldn't be many partial
+  // matches
+
+  // a null phrase matches anything
+  if (phrase.empty()) return true;
+
+  // if there is nothing then there can't be a match
+  if (doc == NULL || doclen == 0) return false;
+  
+  text_t doc_word;
+  doc_word.reserve (16);
+
+  bool first = true;
+
+  unsigned char *doc_here = doc;
+  unsigned char *doc_herefirstword = doc;
+  unsigned char *doc_end = doc+doclen-1; // unitool conventions :-/
+
+  while (doc_here <= doc_end) {
+    first = true;
+
+    // there will be at least one member of phrase (see above)
+    termfreqclassarray::const_iterator phrase_here = phrase.begin();
+    termfreqclassarray::const_iterator phrase_end = phrase.end();
+    do {
+      // get the next non-word ... and ignore it, then get the next word
+      doc_here = parse_nonword_word (doc_here, doc_end, doc_word);
+      if (first) {doc_herefirstword = doc_here; first = false;}
+
+      // break if this word is not the next in the phrase
+      if ((*phrase_here).utf8equivterms.find (doc_word) ==
+	  (*phrase_here).utf8equivterms.end()) break;
+
+      ++phrase_here;
+    } while (doc_here <= doc_end && phrase_here != phrase_end);
+
+    // see if we found a phrase
+    if (phrase_here == phrase_end) return true;
+    
+    doc_here = doc_herefirstword; // set the counter back
+  }
+
+  return false;
+}
+
+// looks for the stemmed phrase in the metadata or text associated with
+// an OID. This function has not been coded with all situations in mind
+bool OID_phrase_search (mgsearchclass &mgsearch,
+			dbclass &db,
+			const text_t &index,
+			const text_t &subcollection,
+			const text_t &language,
+			const text_t &longindex,
+			const text_t &collection,
+			const termfreqclassarray &phrase,
+			int docnum) {
+
+  // get OID
+  infodbclass docnum_info;
+  if (!db.getinfo (docnum, docnum_info)) return false;
+  text_t &OID = docnum_info["section"];
+  if (OID.empty()) return false;
+
+  // disect the long index to find out where the text should come from
+  text_t gran, type;
+  text_t::const_iterator longindex_here = longindex.begin();
+  text_t::const_iterator longindex_end = longindex.end();
+  longindex_here = getdelimitstr (longindex_here, longindex_end, ':', gran);
+  longindex_here = getdelimitstr (longindex_here, longindex_end, ':', type);
+
+  if (gran.empty()) return false;
+  
+  // note that we're treating indexes of type 'all' (i.e. text,Title,Creator)
+  // or other composite indexes that contain "text" as if they were simply 'text' indexes
+  if ((type == "text") || (type == "all") || (findword(type.begin(),type.end(),"text") != type.end())) {
+    char *doc = NULL;
+    int doclen = 0;
+  
+    // get text from mg.
+    if (gran == "document") {
+
+      // if this is a document level index (which should only happen if
+      // there are no matching indexes with a finer granularity -- see
+      // mgqueryfilterclass::mg_parse_query_params) then we must do the
+      // phrase search on the entire document (i.e. all the sections)
+      // -- this is going to make a slow process even slower
+      vector<int> docnum_list; text_t fulldoc;
+      get_all_docnums (db, OID, docnum_list);
+      vector<int>::const_iterator this_docnum = docnum_list.begin();
+      vector<int>::const_iterator end_docnum = docnum_list.end();
+      while (this_docnum != end_docnum) {
+	if (mgsearch.mgdocument (index, subcollection, language, collection,
+				 *this_docnum, doc, doclen)) {
+	  fulldoc.appendcstr (doc);
+	}
+	++this_docnum;
+      }
+      doc = fulldoc.getcstr();
+      doclen = fulldoc.size();
+      bool rv = doc_phrase_search ((unsigned char *)doc, doclen, phrase);
+      delete []doc;
+      return rv;
+
+    } else {
+
+      if (!mgsearch.mgdocument (index, subcollection, language, collection,
+				docnum, doc, doclen)) return false;
+      return doc_phrase_search ((unsigned char *)doc, doclen, phrase);
+    } 
+  }
+
+  char *metadata = NULL;
+  text_t::size_type metadata_len = 0;
+  infodbclass OID_info;
+  
+  // get field
+  if (!db.getinfo (OID, OID_info)) return false;
+
+  bool result = false;
+
+  // need to look through all the metadata values in the index
+  text_tarray keys;
+  splitchar(type.begin(), type.end(), ',', keys);
+
+  text_tarray::const_iterator keyhere = keys.begin();
+  text_tarray::const_iterator keyend = keys.end();
+  while (keyhere != keyend) {
+    text_tarray *tarr_ptr = OID_info.getmultinfo (*keyhere);
+    if (tarr_ptr != NULL ) {
+      text_tarray::const_iterator subvalue_here = (*tarr_ptr).begin();
+      text_tarray::const_iterator subvalue_end = (*tarr_ptr).end();
+      while (subvalue_here != subvalue_end) {
+	metadata = (to_utf8(*subvalue_here)).getcarr(metadata_len);
+	result = doc_phrase_search ((unsigned char *)metadata, metadata_len, phrase);
+	delete [] metadata;
+	
+	if (result) return true;
+	++subvalue_here;
+      }
+    }
+    ++keyhere;
+  }
+  return result;
+}
Index: /gsdl/trunk/runtime-src/src/colservr/phrasesearch.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/phrasesearch.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/phrasesearch.h	(revision 16571)
@@ -0,0 +1,50 @@
+/**********************************************************************
+ *
+ * phrasesearch.h -- tools to search for a phrase in a larger text
+ * Copyright (C) 1999  DigiLib Systems Limited
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef PHRASESEARCH_H
+#define PHRASESEARCH_H
+
+
+#include "text_t.h"
+#include "unitool.h"
+#include "mgsearch.h"
+#include "dbclass.h"
+
+
+// looks for the phrase in the metadata or text associated with
+// a document number. This function has not been coded with all
+// situations in mind and expects mgsearch and db set up ready to go
+bool OID_phrase_search (mgsearchclass &mgsearch,
+			dbclass &db,
+			const text_t &index,
+			const text_t &subcollection,
+			const text_t &language,
+			const text_t &longindex,
+			const text_t &collection,
+			const termfreqclassarray &phrase,
+			int docnum);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/querycache.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/querycache.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/querycache.cpp	(revision 16571)
@@ -0,0 +1,104 @@
+/**********************************************************************
+ *
+ * querycache.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "querycache.h"
+
+
+
+
+resultcacheel::resultcacheel () 
+{
+  accessnum = -1;
+}
+
+
+
+querycache::querycache (int themaxcachesize)
+{
+  if (themaxcachesize < 1) themaxcachesize = 1;
+  
+  resultcache = new resultcacheel[themaxcachesize];
+
+  maxcachesize = themaxcachesize;
+  nextaccessnum = 1;
+}
+
+querycache::~querycache ()
+{
+  delete [] resultcache;
+}
+
+// returns true if the query was found in the cache
+// if the query was found then queryresults contains
+// the results
+bool querycache::find (const queryparamclass &queryparams, 
+		       queryresultsclass &queryresults)
+{
+  int i;
+
+  for (i=0; i < maxcachesize; ++i)
+    {
+      if (resultcache[i].queryparameters == queryparams)
+	{
+	  queryresults = resultcache[i].queryresults;
+	  resultcache[i].accessnum = getnextaccessnum ();
+	  return true;
+	}
+    }
+
+  return false;
+}
+
+
+void querycache::cache (const queryparamclass &queryparams,
+	  const queryresultsclass &queryresults)
+{
+  int i = getfreecachenum();
+  resultcache[i].queryparameters = queryparams;
+  resultcache[i].queryresults = queryresults;
+  resultcache[i].accessnum = getnextaccessnum ();
+}
+
+int querycache::getnextaccessnum ()
+{
+  return nextaccessnum++;
+}
+
+int querycache::getfreecachenum ()
+{
+  int i;
+  int minaccessnum = 0;
+  int minaccessi = 0;
+  
+  for (i=0; i < maxcachesize; ++i)
+    {
+      if (resultcache[i].accessnum < minaccessnum) {
+	minaccessnum = resultcache[i].accessnum;
+	minaccessi = i;
+      }
+    }
+
+  return minaccessi;
+}
Index: /gsdl/trunk/runtime-src/src/colservr/querycache.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/querycache.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/querycache.h	(revision 16571)
@@ -0,0 +1,70 @@
+/**********************************************************************
+ *
+ * querycache.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef QUERYCACHE_H
+#define QUERYCACHE_H
+
+
+#include "text_t.h"
+#include "queryinfo.h"
+
+class resultcacheel
+{
+public:
+  resultcacheel ();
+
+  int accessnum;
+  queryparamclass queryparameters;
+  queryresultsclass queryresults;
+};
+
+
+class querycache {
+public:
+  querycache (int themaxcachesize);
+  ~querycache ();
+
+  // returns true if the query was found in the cache
+  // if the query was found then queryresults contains
+  // the results
+  bool find (const queryparamclass &queryparams, 
+	     queryresultsclass &queryresults);
+
+  void cache (const queryparamclass &queryparams,
+	    const queryresultsclass &queryresults);
+
+protected:
+  resultcacheel *resultcache;
+
+  int maxcachesize;
+  int nextaccessnum;
+  
+  int getnextaccessnum ();
+  int getfreecachenum ();
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/queryfilter.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/queryfilter.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/queryfilter.cpp	(revision 16571)
@@ -0,0 +1,424 @@
+/**********************************************************************
+ *
+ * queryfilter.cpp -- base class for queryfilters
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "queryfilter.h"
+#include "fileutil.h"
+
+
+// translate will return true if successful
+bool queryfilterclass::translate (dbclass *db_ptr, text_t& docnum, text_t &trans_OID) {
+  infodbclass info;
+
+  trans_OID.clear();
+
+  // get the info
+  if (db_ptr == NULL) return false;
+  if (!db_ptr->getinfo(docnum, info)) return false;
+
+  // translate
+  if (info["section"].empty()) return false;
+
+  trans_OID = info["section"];
+  return true;
+}
+
+
+// whether document results are needed
+bool queryfilterclass::need_matching_docs (int filterResultOptions) {
+  return ((filterResultOptions & FROID) || (filterResultOptions & FRranking) ||
+	  (filterResultOptions & FRmetadata));
+}
+
+// whether term information is needed
+bool queryfilterclass::need_term_info (int filterResultOptions) {
+  return ((filterResultOptions & FRtermFreq) || (filterResultOptions & FRmatchTerms));
+}
+
+/////////////////////////////////
+// functions for queryfilterclass
+/////////////////////////////////
+
+// get the query parameters
+void queryfilterclass::parse_query_params (const FilterRequest_t &request,
+					   vector<queryparamclass> &query_params,
+					   int &startresults, int &endresults,
+					   text_t &phrasematch, ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  // set defaults for the return parameters
+  query_params.erase(query_params.begin(), query_params.end());
+  startresults = filterOptions["StartResults"].defaultValue.getint();
+  endresults = filterOptions["EndResults"].defaultValue.getint();
+  phrasematch = filterOptions["PhraseMatch"].defaultValue;
+
+  // set defaults for query parameters
+  queryparamclass query;
+  query.combinequery = "or"; // first one must be "or"
+  query.collection = collection;
+  query.index = filterOptions["Index"].defaultValue;
+  query.subcollection = filterOptions["Subcollection"].defaultValue;
+  query.language = filterOptions["Language"].defaultValue;
+  query.querystring.clear();
+  query.search_type = (filterOptions["QueryType"].defaultValue == "ranked");
+  query.match_mode = (filterOptions["MatchMode"].defaultValue == "all");
+  query.casefolding = (filterOptions["Casefold"].defaultValue == "true");
+  query.stemming = (filterOptions["Stem"].defaultValue == "true");
+  query.accentfolding = (filterOptions["AccentFold"].defaultValue == "true");
+  query.maxdocs = filterOptions["Maxdocs"].defaultValue.getint();
+  query.level = filterOptions["Level"].defaultValue;
+  query.filterstring = filterOptions["FilterString"].defaultValue;  // Lucene specific
+  query.sortfield = filterOptions["SortField"].defaultValue;  // Lucene specific
+  query.fuzziness = filterOptions["Fuzziness"].defaultValue;  // Lucene specific
+  query.maxnumeric = maxnumeric;
+  OptionValue_tarray::const_iterator options_here = request.filterOptions.begin();
+  OptionValue_tarray::const_iterator options_end = request.filterOptions.end();
+  while (options_here != options_end) {
+    if ((*options_here).name == "CombineQuery") {
+      // add this query
+      
+      // "all", needed when combining queries where the document results are needed
+      if (need_matching_docs (request.filterResultOptions)) query.maxdocs = -1; 
+      query_params.push_back (query);
+
+      // start on next query
+      query.clear();
+      query.combinequery = (*options_here).value;
+
+      // set defaults for query parameters
+      query.collection = collection;
+      query.index = filterOptions["Index"].defaultValue;
+      query.subcollection = filterOptions["Subcollection"].defaultValue;
+      query.language = filterOptions["Language"].defaultValue;
+      query.querystring.clear();
+      query.search_type = (filterOptions["QueryType"].defaultValue == "ranked");
+      query.match_mode = (filterOptions["MatchMode"].defaultValue == "all");
+      query.casefolding = (filterOptions["Casefold"].defaultValue == "true");
+      query.stemming = (filterOptions["Stem"].defaultValue == "true");
+      query.accentfolding = (filterOptions["AccentFold"].defaultValue == "true");
+      query.level = filterOptions["Level"].defaultValue;
+      query.filterstring = filterOptions["FilterString"].defaultValue;  // Lucene specific
+      query.sortfield = filterOptions["SortField"].defaultValue;  // Lucene specific
+      query.fuzziness = filterOptions["Fuzziness"].defaultValue;  // Lucene specific
+      query.maxnumeric = maxnumeric;
+      // "all", needed when combining queries where the document results are needed
+      if (need_matching_docs (request.filterResultOptions)) query.maxdocs = -1; 
+      else query.maxdocs = filterOptions["Maxdocs"].defaultValue.getint();
+      
+    } else if ((*options_here).name == "StartResults") {
+      startresults = (*options_here).value.getint();
+    } else if ((*options_here).name == "EndResults") {
+      endresults = (*options_here).value.getint();
+    } else if ((*options_here).name == "QueryType") {
+      query.search_type = ((*options_here).value == "ranked");
+    } else if ((*options_here).name == "MatchMode") {
+      query.match_mode = ((*options_here).value == "all");
+      if (query.match_mode == 1) query.maxdocs = -1;
+    } else if ((*options_here).name == "Term") {
+      query.querystring = (*options_here).value;
+    } else if ((*options_here).name == "Casefold") {
+      query.casefolding = ((*options_here).value == "true");
+    } else if ((*options_here).name == "Stem") {
+      query.stemming = ((*options_here).value == "true");
+    } else if ((*options_here).name == "AccentFold") {
+      query.accentfolding = ((*options_here).value == "true");
+    } else if ((*options_here).name == "Index"&& (*options_here).value !="") {
+      query.index = (*options_here).value;
+    } else if ((*options_here).name == "Subcollection") {
+      query.subcollection = (*options_here).value;
+    } else if ((*options_here).name == "Language") {
+      query.language = (*options_here).value;
+    } else if ((*options_here).name == "Maxdocs") {
+      query.maxdocs = (*options_here).value.getint();
+    } else if ((*options_here).name == "PhraseMatch") {
+      phrasematch = (*options_here).value;
+    } else if ((*options_here).name == "Level") {
+      query.level = (*options_here).value;
+    } else if ((*options_here).name == "FilterString") {
+      query.filterstring = (*options_here).value;
+    } else if ((*options_here).name == "SortField") {
+      query.sortfield = (*options_here).value;
+    } else if ((*options_here).name == "Fuzziness") {
+      query.fuzziness = (*options_here).value;
+    } else {
+      logout << text_t2ascii
+	     << "warning: unknown queryfilter option \""
+	     << (*options_here).name
+	     << "\" ignored.\n\n";
+    }
+
+    ++options_here;
+  }
+
+  // Store the start and end results in the query too, as lucene now needs to
+  // pass them through to the Java
+  query.startresults = startresults;
+  query.endresults = endresults;
+
+  // add the last query
+  query_params.push_back (query);
+}
+
+
+
+
+queryfilterclass::queryfilterclass () {
+  db_ptr = NULL;
+  textsearchptr = NULL;
+  maxnumeric = 4;
+
+  FilterOption_t filtopt;
+  filtopt.name = "CombineQuery";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "and";
+  filtopt.validValues.push_back("and");
+  filtopt.validValues.push_back("or");
+  filtopt.validValues.push_back("not");
+  filterOptions["CombineQuery"] = filtopt;
+
+  // -- onePerQuery StartResults   integer
+  filtopt.clear();
+  filtopt.name = "StartResults";
+  filtopt.type = FilterOption_t::integert;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "1";
+  filtopt.validValues.push_back("1");
+  filtopt.validValues.push_back("1000");
+  filterOptions["StartResults"] = filtopt;
+
+  // -- onePerQuery EndResults     integer
+  filtopt.clear();
+  filtopt.name = "EndResults";
+  filtopt.type = FilterOption_t::integert;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "10";
+  filtopt.validValues.push_back("-1");
+  filtopt.validValues.push_back("1000");
+  filterOptions["EndResults"] = filtopt;
+
+  // -- onePerQuery QueryType      enumerated (boolean, ranked)
+  filtopt.clear();
+  filtopt.name = "QueryType";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "ranked";
+  filtopt.validValues.push_back("boolean");
+  filtopt.validValues.push_back("ranked");
+  filterOptions["QueryType"] = filtopt;
+
+  // -- onePerQuery MatchMode      enumerated (some, all)
+  filtopt.clear();
+  filtopt.name = "MatchMode";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "some";
+  filtopt.validValues.push_back("some");
+  filtopt.validValues.push_back("all");
+  filterOptions["MatchMode"] = filtopt;
+
+  // -- onePerTerm  Term           string ???
+  filtopt.clear();
+  filtopt.name = "Term";
+  filtopt.type = FilterOption_t::stringt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["Term"] = filtopt;
+
+  // -- onePerTerm  Casefold       boolean
+  filtopt.clear();
+  filtopt.name = "Casefold";
+  filtopt.type = FilterOption_t::booleant;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "true";
+  filtopt.validValues.push_back("false");
+  filtopt.validValues.push_back("true");
+  filterOptions["Casefold"] = filtopt;
+
+  // -- onePerTerm  Stem           boolean
+  filtopt.clear();
+  filtopt.name = "Stem";
+  filtopt.type = FilterOption_t::booleant;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "false";
+  filtopt.validValues.push_back("false");
+  filtopt.validValues.push_back("true");
+  filterOptions["Stem"] = filtopt;
+
+  // -- onePerTerm  AccentFold           boolean
+  filtopt.clear();
+  filtopt.name = "AccentFold";
+  filtopt.type = FilterOption_t::booleant;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "false";
+  filtopt.validValues.push_back("false");
+  filtopt.validValues.push_back("true");
+  filterOptions["AccentFold"] = filtopt;
+  
+  // -- onePerTerm  Index          enumerated
+  filtopt.clear();
+  filtopt.name = "Index";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["Index"] = filtopt;
+
+  // -- onePerTerm  Subcollection  enumerated
+  filtopt.clear();
+  filtopt.name = "Subcollection";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["Subcollection"] = filtopt;
+
+  // -- onePerTerm  Language  enumerated
+  filtopt.clear();
+  filtopt.name = "Language";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["Language"] = filtopt;
+
+  // -- onePerQuery  Maxdocs  integer
+  filtopt.clear();
+  filtopt.name = "Maxdocs";
+  filtopt.type = FilterOption_t::integert;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "200";
+  filtopt.validValues.push_back("-1");
+  filtopt.validValues.push_back("1000");
+  filterOptions["Maxdocs"] = filtopt;
+
+  // -- onePerQuery  PhraseMatch  enumerated
+  filtopt.clear();
+  filtopt.name = "PhraseMatch";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "some_phrases";
+  filtopt.validValues.push_back ("all_phrases");
+  filtopt.validValues.push_back ("some_phrases");
+  filtopt.validValues.push_back ("all_docs");
+  filterOptions["PhraseMatch"] = filtopt;
+}
+
+queryfilterclass::~queryfilterclass () {
+  // don't delete db_ptr or textsearchptr here, they'll be cleaned up by the source
+}
+
+void queryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
+  filterclass::configure (key, cfgline);
+
+  if (key == "indexmap") {
+    indexmap.importmap (cfgline);
+    
+    // update the list of indexes in the filter information
+    text_tarray options;
+    indexmap.gettoarray (options);
+    filterOptions["Index"].validValues = options;
+
+  } else if (key == "defaultindex") {
+    indexmap.from2to (cfgline[0], filterOptions["Index"].defaultValue);
+
+  } else if (key == "subcollectionmap") {
+    subcollectionmap.importmap (cfgline);
+
+    // update the list of subcollections in the filter information
+    text_tarray options;
+    subcollectionmap.gettoarray (options);
+    filterOptions["Subcollection"].validValues = options;
+
+  } else if (key == "defaultsubcollection") {
+    subcollectionmap.from2to (cfgline[0], filterOptions["Subcollection"].defaultValue);
+
+  } else if (key == "languagemap") {
+    languagemap.importmap (cfgline);
+
+    // update the list of languages in the filter information
+    text_tarray options;
+    languagemap.gettoarray (options);
+    filterOptions["Language"].validValues = options;
+
+  } else if (key == "defaultlanguage") {
+    languagemap.from2to (cfgline[0], filterOptions["Language"].defaultValue);
+  } else if (key == "indexstem") {
+    indexstem = cfgline[0];
+  } else if (key == "maxnumeric") {
+    maxnumeric = cfgline[0].getint();
+  }
+  
+}
+
+bool queryfilterclass::init (ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  if (!filterclass::init(logout)) return false;
+
+  if (filterOptions["Index"].defaultValue.empty()) {
+    // use first index in map as default if no default is set explicitly
+    text_tarray fromarray;
+    indexmap.getfromarray(fromarray);
+    if (fromarray.size()) {
+      filterOptions["Index"].defaultValue = fromarray[0];
+    }
+  }
+
+  if (filterOptions["Subcollection"].defaultValue.empty()) {
+    // use first subcollection in map as default if no default is set explicitly
+    text_tarray fromarray;
+    subcollectionmap.getfromarray(fromarray);
+    if (fromarray.size()) {
+      filterOptions["Subcollection"].defaultValue = fromarray[0];
+    }
+  }
+
+  if (filterOptions["Language"].defaultValue.empty()) {
+    // use first language in map as default if no default is set explicitly
+    text_tarray fromarray;
+    languagemap.getfromarray(fromarray);
+    if (fromarray.size()) {
+      filterOptions["Language"].defaultValue = fromarray[0];
+    }
+  }
+
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: queryfilter contains a null dbclass\n\n";
+    return false;
+  }
+
+  // get the filename for the database and make sure it exists
+  if (indexstem.empty()) {
+    indexstem = collection;
+  }
+  db_filename = resolve_db_filename(indexstem,db_ptr->getfileextension());
+  if (!file_exists(db_filename)) {
+    logout << text_t2ascii
+	   << "warning: database \"" << db_filename << "\" does not exist\n\n";
+    //return false;
+  }
+
+  return true;
+}
+
Index: /gsdl/trunk/runtime-src/src/colservr/queryfilter.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/queryfilter.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/queryfilter.h	(revision 16571)
@@ -0,0 +1,100 @@
+/**********************************************************************
+ *
+ * queryfilter.h -- abstract base class for queryfilters
+ *          mgqueryfilter, mgppqueryfilter and lucenequeryfilter 
+ *          implement this
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef QUERYFILTER_H
+#define QUERYFILTER_H
+
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "comtypes.h"
+#include "filter.h"
+#include "dbclass.h"
+#include "maptools.h"
+#include "search.h"
+#include "queryinfo.h"
+
+
+class queryfilterclass : public filterclass {
+protected:
+
+  stringmap indexmap;
+  stringmap subcollectionmap;
+  stringmap languagemap;
+
+  text_t db_filename;
+  text_t indexstem;
+  dbclass *db_ptr;
+  
+  searchclass *textsearchptr;
+
+  int maxnumeric;
+
+   // get the query parameters
+  void parse_query_params (const FilterRequest_t &request,
+			   vector<queryparamclass> &query_params,
+			   int &startresults, int &endresults,
+			   text_t &phrasematch, ostream &logout);
+
+  // do query that might involve multiple sub queries
+  // textsearchptr and db_ptr are assumed to be valid
+  virtual void do_multi_query (const FilterRequest_t &request,
+		       const vector<queryparamclass> &query_params,
+		       queryresultsclass &multiresults,
+		       comerror_t &err, ostream &logout)=0;
+
+public:
+  queryfilterclass ();
+  virtual ~queryfilterclass ();
+
+  // the db_ptr remains the responsibility of the calling code
+  void set_db_ptr (dbclass *db_ptr_arg) { db_ptr = db_ptr_arg; }
+
+  // the testsearchptr remains the responsability of the calling code
+  void set_textsearchptr (searchclass *thetextsearchptr) {textsearchptr=thetextsearchptr;}
+
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+  virtual bool init (ostream &logout);
+
+  text_t get_filter_name () {return "QueryFilter";}
+  bool translate(dbclass *db_ptr, text_t& docnum, text_t &trans_OID);
+  bool need_matching_docs (int filterResultOptions);
+  bool need_term_info (int filterResultOptions);
+
+
+  virtual void filter (const FilterRequest_t &request,
+	       FilterResponse_t &response,
+	       comerror_t &err, ostream &logout)=0;
+
+
+
+};
+
+
+#endif
+
Index: /gsdl/trunk/runtime-src/src/colservr/queryinfo.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/queryinfo.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/queryinfo.cpp	(revision 16571)
@@ -0,0 +1,427 @@
+/**********************************************************************
+ *
+ * queryinfo.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "queryinfo.h"
+
+
+// query parameters
+
+queryparamclass::queryparamclass () {
+  clear ();
+}
+
+void queryparamclass::clear () {
+  combinequery.clear();
+  collection.clear();
+  index.clear();
+  subcollection.clear();
+  language.clear();
+  level.clear();
+  querystring.clear();
+  search_type = 0; // 0 = boolean, 1 = ranked
+  match_mode = 0; // 0 = some, 1 = all
+  casefolding = 0;
+  stemming = 0;
+  accentfolding = 0;
+  maxdocs = -1;    // all
+  maxnumeric = 4;  // must default to the same value as mg_passes
+  filterstring.clear();
+  sortfield.clear();
+  fuzziness.clear();
+  startresults = 1; // all
+  endresults = 10; // all
+}
+
+
+queryparamclass &queryparamclass::operator=(const queryparamclass &q) {
+  combinequery = q.combinequery;
+  collection = q.collection;
+  index = q.index;
+  subcollection = q.subcollection;
+  language = q.language;
+  level = q.level;
+  querystring = q.querystring;
+  search_type = q.search_type;
+  match_mode = q.match_mode;
+  casefolding = q.casefolding;
+  stemming = q.stemming;
+  accentfolding = q.accentfolding;
+  maxdocs = q.maxdocs;
+  maxnumeric = q.maxnumeric;
+  filterstring = q.filterstring;
+  sortfield = q.sortfield;
+  fuzziness = q.fuzziness;
+  startresults = q.startresults;
+  endresults = q.endresults;
+  return *this;
+}
+
+
+bool operator==(const queryparamclass &x, const queryparamclass &y) {
+  return ((x.combinequery == y.combinequery) &&
+	  (x.collection == y.collection) &&
+	  (x.index == y.index) &&
+	  (x.subcollection == y.subcollection) &&
+	  (x.language == y.language) &&
+	  (x.level == y.level) &&
+	  (x.querystring == y.querystring) &&
+	  (x.search_type == y.search_type) &&
+	  (x.match_mode == y.match_mode) &&
+	  (x.casefolding == y.casefolding) &&
+	  (x.stemming == y.stemming) &&
+	  (x.accentfolding == y.accentfolding) &&
+	  (x.maxdocs == y.maxdocs) &&
+	  (x.maxnumeric == y.maxnumeric) &&
+	  (x.filterstring == y.filterstring) &&
+          (x.sortfield == y.sortfield) &&
+          (x.fuzziness == y.fuzziness) &&
+          (x.startresults == y.startresults) &&
+          (x.startresults == y.startresults));
+}
+
+bool operator!=(const queryparamclass &x, const queryparamclass &y) {
+  return !(x == y);
+}
+
+
+ostream &operator<< (ostream &outs, queryparamclass &q) {
+  outconvertclass text_t2ascii;
+
+  outs << "*** queryparamclass\n";
+  outs << text_t2ascii << " combinequery = \"" << q.combinequery << "\"\n";
+  outs << text_t2ascii << " collection = \"" << q.collection << "\"\n";
+  outs << text_t2ascii << " index = \"" << q.index << "\"\n";
+  outs << text_t2ascii << " level = \"" << q.level << "\"\n";
+  outs << text_t2ascii << " subcollection = \"" << q.subcollection << "\"\n";
+  outs << text_t2ascii << " language = \"" << q.language << "\"\n";
+  outs << text_t2ascii << " querystring = \"" << q.querystring << "\"\n";
+  outs << " search_type = \"" << q.search_type << "\"\n";
+  outs << " match_mode = \"" << q.match_mode << "\"\n";
+  outs << " casefolding = \"" << q.casefolding << "\"\n";
+  outs << " stemming = \"" << q.stemming << "\"\n";
+  outs << " accentfolding = \"" << q.accentfolding << "\"\n";
+  outs << " maxdocs = \"" << q.maxdocs << "\"\n";
+  outs << " maxnumeric = \"" << q.maxnumeric << "\"\n";
+  outs << " filterstring = \"" << q.filterstring << "\"\n";
+  outs << " sortfield = \"" << q.sortfield << "\"\n";
+  outs << " fuzziness = \"" << q.fuzziness << "\"\n";
+  outs << " startresults = \"" << q.startresults << "\"\n";
+  outs << " endresults = \"" << q.endresults << "\"\n";
+  outs << "\n";
+
+  return outs;
+}
+
+
+
+
+// term frequencies
+
+termfreqclass::termfreqclass () {
+  clear();
+}
+
+void termfreqclass::clear() {
+  termstr.clear();
+  termstemstr.clear();
+  utf8equivterms.erase(utf8equivterms.begin(), utf8equivterms.end());
+  termfreq = 0;
+}
+
+termfreqclass &termfreqclass::operator=(const termfreqclass &t)  {
+  termstr = t.termstr;
+  termstemstr = t.termstemstr;
+  utf8equivterms = t.utf8equivterms;
+  termfreq = t.termfreq;
+
+  return *this;
+}
+	
+bool operator==(const termfreqclass &x, const termfreqclass &y) {
+  return ((x.termstr == y.termstr) &&
+	  (x.termstemstr == y.termstemstr) &&
+	  (x.termfreq == y.termfreq));
+}
+
+bool operator!=(const termfreqclass &x, const termfreqclass &y) {
+  return !(x == y);
+}
+
+// ordered by termfreq and then by termstr
+bool operator<(const termfreqclass &x, const termfreqclass &y) {
+  return ((x.termfreq < y.termfreq) ||
+	  ((x.termfreq == y.termfreq) && (x.termstemstr < y.termstemstr)) ||
+	  ((x.termfreq == y.termfreq) && (x.termstemstr == y.termstemstr) && (x.termstr < y.termstr)));
+}
+
+bool operator>(const termfreqclass &x, const termfreqclass &y) {
+  return ((x.termfreq > y.termfreq) ||
+	  ((x.termfreq == y.termfreq) && (x.termstemstr > y.termstemstr)) ||
+	  ((x.termfreq == y.termfreq) && (x.termstemstr == y.termstemstr) && (x.termstr > y.termstr)));
+}
+
+// stream output for debugging purposes
+ostream &operator<< (ostream &outs, termfreqclass &t) {
+  outconvertclass text_t2ascii;
+
+  outs << text_t2ascii << " t:\"" << t.termstr << "\"";
+  outs << text_t2ascii << " s:\"" << t.termstemstr << "\"";
+  outs << " f:" << t.termfreq << "\n";
+
+  return outs;
+}
+
+
+
+// one query result
+
+docresultclass::docresultclass() {
+  clear ();
+}
+
+void docresultclass::clear () {
+  docnum=-1;
+  docweight=0.0;
+  num_query_terms_matched=0;
+  num_phrase_match=0;
+}
+
+// merges two result classes relating to a single docnum
+docresultclass &docresultclass::combine(const docresultclass &d) {
+  docweight += d.docweight; // budget!
+  num_query_terms_matched += d.num_query_terms_matched;
+  num_phrase_match += d.num_phrase_match;
+
+  return *this;
+}
+
+docresultclass &docresultclass::operator=(const docresultclass &d) {
+  docnum = d.docnum;
+  docweight = d.docweight;
+  num_query_terms_matched = d.num_query_terms_matched;
+  num_phrase_match = d.num_phrase_match;
+
+  return *this;
+}
+
+
+bool operator==(const docresultclass &x, const docresultclass &y) {
+  return ((x.docnum == y.docnum) && (x.docweight == y.docweight) &&
+	  (x.num_query_terms_matched == y.num_query_terms_matched) &&
+	  (x.num_phrase_match == y.num_phrase_match));
+}
+
+bool operator<(const docresultclass &x, const docresultclass &y) {
+  return ((x.docnum < y.docnum) ||
+	  ((x.docnum == y.docnum) &&
+	   ((x.docweight < y.docweight) ||
+	    ((x.docweight == y.docweight) &&
+	     ((x.num_query_terms_matched < y.num_query_terms_matched) ||
+	      ((x.num_query_terms_matched == y.num_query_terms_matched) &&
+	       ((x.num_phrase_match < y.num_phrase_match))))))));
+}
+
+
+// stream output for debugging purposes
+ostream &operator<< (ostream &outs, docresultclass &a) {
+  outs << " d:" << a.docnum << " w:" << a.docweight << "\n";
+  return outs;
+}
+
+
+
+// many document results
+
+docresultsclass::docresultsclass () {
+  clear ();
+}
+
+void docresultsclass::clear () {
+  docset.erase(docset.begin(), docset.end());
+  docorder.erase(docorder.begin(), docorder.end());
+}
+
+void docresultsclass::docnum_order() {
+  docorder.erase(docorder.begin(), docorder.end());
+  
+  docresultmap::iterator here = docset.begin();
+  docresultmap::iterator end = docset.end();
+  while (here != end) {
+    docorder.push_back ((*here).first);
+    ++here;
+  }
+}
+
+void docresultsclass::combine_and (const docresultsclass &d) {
+  docorder.erase(docorder.begin(), docorder.end());
+
+  // put the resulting set in tempresults
+  docresultmap tempresults;
+  
+  docresultmap::const_iterator d_here = d.docset.begin();
+  docresultmap::const_iterator d_end = d.docset.end();
+  docresultmap::iterator found = docset.end();
+  while (d_here != d_end) {
+    found = docset.find((*d_here).first);
+    if (found != docset.end()) {
+      (*found).second.combine ((*d_here).second);
+      tempresults[(*found).first] = (*found).second;
+    }
+    ++d_here;
+  }
+
+  // then copy it back to docset
+  docset = tempresults;
+}
+
+void docresultsclass::combine_or (const docresultsclass &d) {
+  docorder.erase(docorder.begin(), docorder.end());
+    
+  docresultmap::const_iterator d_here = d.docset.begin();
+  docresultmap::const_iterator d_end = d.docset.end();
+  docresultmap::iterator found = docset.end();
+  while (d_here != d_end) {
+    found = docset.find((*d_here).first);
+    if (found != docset.end()) {
+      (*found).second.combine ((*d_here).second);
+    } else {
+      docset[(*d_here).first] = (*d_here).second;
+    }
+    ++d_here;
+  }
+}
+
+void docresultsclass::combine_not (const docresultsclass &d) {
+  docorder.erase(docorder.begin(), docorder.end());
+
+ docresultmap::const_iterator d_here = d.docset.begin();
+ docresultmap::const_iterator d_end = d.docset.end();
+ docresultmap::iterator found = docset.end();
+ while (d_here != d_end) {
+   found = docset.find((*d_here).first);
+   if (found != docset.end()) docset.erase (found);
+   ++d_here;
+ }
+}
+
+docresultsclass &docresultsclass::operator=(const docresultsclass &d) {
+  docset = d.docset;
+  docorder = d.docorder;
+
+  return *this;
+}
+
+
+
+
+// query results
+
+void queryresultsclass::clear () {
+  error_message = g_EmptyText;
+  docs_matched = 0;
+  is_approx = Exact;
+  syntax_error = false;
+  postprocessed = false;
+
+  docs.clear();
+  orgterms.erase(orgterms.begin(),orgterms.end());
+  terms.erase(terms.begin(),terms.end());
+}
+
+queryresultsclass &queryresultsclass::operator=(const queryresultsclass &q) {
+  error_message = q.error_message;
+  docs_matched = q.docs_matched;
+  is_approx = q.is_approx;
+  syntax_error = q.syntax_error;
+  postprocessed = q.postprocessed;
+
+  docs = q.docs;
+  terms = q.terms;
+  termvariants = q.termvariants;
+
+  return *this;
+}
+
+void queryresultsclass::sortuniqqueryterms() {
+  termfreqclassarray tempterms = orgterms;
+  text_tset seenterms;
+  terms.erase(terms.begin(), terms.end());
+
+  // sort the terms to get the frequencies in ascending order
+  sort (tempterms.begin(), tempterms.end());
+
+  // insert first occurance of each term (maximum)
+  termfreqclassarray::reverse_iterator here = tempterms.rbegin();
+  termfreqclassarray::reverse_iterator end = tempterms.rend();
+  while (here != end) {
+    if (seenterms.find((*here).termstr) == seenterms.end()) {
+      // the termstemstr and utf8equivterms might be different for
+      // different occurances of the term
+      (*here).termstemstr.clear();
+      (*here).utf8equivterms.erase((*here).utf8equivterms.begin(),
+				   (*here).utf8equivterms.end());
+      terms.push_back(*here);
+      seenterms.insert((*here).termstr);
+    }
+    ++here;
+  }
+
+  // now re-sort in ascending order
+  sort (terms.begin(), terms.end());
+}
+
+
+// stream output for debugging purposes
+ostream &operator<< (ostream &outs, queryresultsclass &q) {
+  outs << "*** queryresultsclass\n";
+  outs << "docs\n";
+
+  docresultmap::iterator docshere = q.docs.docset.begin();
+  docresultmap::iterator docsend = q.docs.docset.end();
+  while (docshere != docsend) {
+    outs << (*docshere).second;
+    ++docshere;
+  }
+
+  outs << "orgterms\n";
+  termfreqclassarray::iterator orgtermshere = q.orgterms.begin();
+  termfreqclassarray::iterator orgtermsend = q.orgterms.end();
+  while (orgtermshere != orgtermsend) {
+    outs << (*orgtermshere);
+    ++orgtermshere;
+  }
+
+  outs << "terms\n";
+  termfreqclassarray::iterator termshere = q.terms.begin();
+  termfreqclassarray::iterator termsend = q.terms.end();
+  while (termshere != termsend) {
+    outs << (*termshere);
+    ++termshere;
+  }
+
+  outs << "\n";
+
+  return outs;
+}
Index: /gsdl/trunk/runtime-src/src/colservr/queryinfo.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/queryinfo.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/queryinfo.h	(revision 16571)
@@ -0,0 +1,197 @@
+/**********************************************************************
+ *
+ * queryinfo.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef QUERYINFO_H
+#define QUERYINFO_H
+
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "comtypes.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\vector>
+#  include <ospace\std\algorithm>
+#elif defined(GSDL_USE_STL_H)
+#  include <vector.h>
+#  if defined(GSDL_USE_ALGO_H)
+#    include <algo.h>
+#  else
+#    include <algorithm.h>
+#  endif
+#else
+#  include <vector>
+#  include <algorithm>
+#endif
+
+// query parameters
+
+struct queryparamclass {
+  text_t combinequery;
+  text_t collection;
+
+  // search_index = index+subcollection+language
+  text_t index;
+  text_t subcollection;
+  text_t language;
+  text_t level; // for new mg stuff
+  text_t querystring;
+  int search_type; // 0 = boolean, 1 = ranked
+  int match_mode; // 0 = some, 1 = all
+  int casefolding;
+  int stemming;
+  int accentfolding;
+  int maxdocs;
+  int maxnumeric;
+  text_t filterstring; // Filter specified (currently only used by Lucene)
+  text_t sortfield; // Field to use for sorting result set (currently used by lucene)
+  text_t fuzziness; // Search fuzziness amount between 0.0 and 1.0 (only used by Lucene)
+
+  int startresults;
+  int endresults;
+
+  queryparamclass ();
+  void clear ();
+  queryparamclass &operator=(const queryparamclass &q);
+};
+
+bool operator==(const queryparamclass &x, const queryparamclass &y);
+bool operator!=(const queryparamclass &x, const queryparamclass &y);
+
+// stream output for debugging purposes
+ostream &operator<< (ostream &outs, queryparamclass &q);
+
+
+
+// term frequencies
+
+struct termfreqclass {
+  text_t termstr;
+  text_t termstemstr;
+  text_tset utf8equivterms; // kept as utf8 string for fast matching
+  unsigned int termfreq;
+
+  termfreqclass ();
+  void clear();
+  termfreqclass &operator=(const termfreqclass &t);
+};
+
+typedef vector<termfreqclass> termfreqclassarray;
+
+bool operator==(const termfreqclass &x, const termfreqclass &y);
+bool operator!=(const termfreqclass &x, const termfreqclass &y);
+bool operator<(const termfreqclass &x, const termfreqclass &y);
+bool operator>(const termfreqclass &x, const termfreqclass &y);
+
+// stream output for debugging purposes
+ostream &operator<< (ostream &outs, termfreqclass &q);
+
+
+
+// one query result
+
+struct docresultclass {
+  int docnum;
+  float docweight;
+  unsigned int num_query_terms_matched;  // not available on all versions of mg
+  int num_phrase_match;                  // not available on all versions of mg
+
+  docresultclass();
+  ~docresultclass() {}
+  void clear ();
+  
+  // merges two result classes relating to a single docnum
+  docresultclass &combine(const docresultclass &d);
+
+  docresultclass &operator=(const docresultclass &d);
+};
+
+bool operator==(const docresultclass &x, const docresultclass &y);
+bool operator<(const docresultclass &x, const docresultclass &y);
+
+
+// stream output for debugging purposes
+ostream &operator<< (ostream &outs, docresultclass &a);
+
+
+struct ltint {
+  bool operator()(const int &t1, const int &t2) const
+  { return t1 < t2; }
+};
+
+typedef map<text_t, docresultclass, lttext_t> docresultmap;
+
+
+
+// many document results
+
+struct docresultsclass {
+  docresultmap docset;
+  vector<text_t> docorder;
+
+  docresultsclass ();
+  void clear ();
+  void docnum_order();
+
+  void combine_and (const docresultsclass &d);
+  void combine_or (const docresultsclass &d);
+  void combine_not (const docresultsclass &d);
+  
+  docresultsclass &operator=(const docresultsclass &d);
+};
+
+
+
+
+// query results
+
+struct queryresultsclass {
+  queryresultsclass () {clear();}
+
+  text_t error_message;  // Currently only used by Lucene
+  int docs_matched; // not available on all versions of mg
+  isapprox is_approx;
+  //  bool is_approx;   // not available on all versions of mg
+  bool syntax_error; // whether the query string was invalid
+  bool postprocessed; // whether this record has been post-processed
+  
+  docresultsclass docs;
+  termfreqclassarray orgterms; // terms before they are sorted and uniqued
+  termfreqclassarray terms;
+  text_tset termvariants;
+  text_tset stopwords;
+
+  void clear ();
+  queryresultsclass &operator=(const queryresultsclass &q);
+  
+  void sortuniqqueryterms();
+};
+
+// stream output for debugging purposes
+ostream &operator<< (ostream &outs, queryresultsclass &q);
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/search.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/search.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/search.cpp	(revision 16571)
@@ -0,0 +1,53 @@
+/**********************************************************************
+ *
+ * search.cpp -- abstract search class for mg
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "search.h"
+
+////////////////////
+// search class //
+////////////////////
+
+searchclass::searchclass ()
+{
+  cache = new querycache (RESULTCACHESIZE);
+ 
+}
+
+searchclass::~searchclass () 
+{
+  if (cache != NULL) 
+    {
+      delete cache;
+      cache = NULL;
+    }
+}
+
+
+void searchclass::setcollectdir (const text_t &thecollectdir)
+{
+  collectdir = thecollectdir;
+}
+
+
Index: /gsdl/trunk/runtime-src/src/colservr/search.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/search.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/search.h	(revision 16571)
@@ -0,0 +1,80 @@
+/**********************************************************************
+ *
+ * search.h -- abstract search class for mg systems
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef SEARCH_H
+#define SEARCH_H
+
+#include "text_t.h"
+#include "querycache.h"
+
+#define RESULTCACHESIZE 10
+#define MAXNUMDOCS      1000000
+#define MAXNUMTERMS     100
+
+class searchclass {
+public:
+  searchclass ();
+  virtual ~searchclass ();
+
+  // in subclass, should be over-rided to return "mg" or "mgpp"
+  virtual text_t get_textindex_type()=0;
+  // the index directory must be set before any searching
+  // is done
+  virtual void setcollectdir (const text_t &thecollectdir);
+  
+  // the search results are returned in queryresults
+  // search returns 'true' if it was able to do a search
+   virtual bool search(const queryparamclass &queryparams, 
+	      queryresultsclass &queryresults)=0;
+  
+  // the document text for 'docnum' is placed in 'output'
+  // docTargetDocument returns 'true' if it was able to
+  // try to get a document
+  // collection is needed to see if an index from the 
+  // collection is loaded. If no index has been loaded
+  // defaultindex is needed to load one
+  virtual bool docTargetDocument(const text_t &defaultindex,
+			 const text_t &defaultsubcollection,
+			 const text_t &defaultlanguage,
+			 const text_t &collection,
+			 int docnum,
+			 text_t &output)=0;
+
+  // unload_database clears any cached databases - 
+  // this is useful when attempting to
+  // completely remove all trace of a collectionserver at runtime (when
+  // using a persistent version of Greenstone like the windows local
+  // library)
+  virtual void unload_database ()=0;
+
+protected:
+  querycache *cache;
+  text_t collectdir; // the collection directory
+
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/source.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/source.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/source.cpp	(revision 16571)
@@ -0,0 +1,456 @@
+/**********************************************************************
+ *
+ * source.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "source.h"
+#include "fileutil.h"
+#include "OIDtools.h"
+#include <assert.h>
+
+
+sourceclass::sourceclass ()
+{
+  db_ptr = NULL;
+  textsearchptr = NULL;
+  classname = "source";
+}
+
+sourceclass::~sourceclass ()
+{
+  if (db_ptr != NULL) delete db_ptr;
+  if (textsearchptr != NULL) delete textsearchptr;
+}
+
+// configure should be called once for each configuration line
+void sourceclass::configure (const text_t &key, const text_tarray &cfgline)
+{
+  if (cfgline.size() >= 1) {
+    const text_t &value = cfgline[0];
+
+    if (key == "collection") collection = value;
+    else if (key == "collectdir") collectdir = value;
+    else if (key == "gsdlhome") gsdlhome = value;
+    else if (key == "collecthome") collecthome = value;
+    else if (key == "gdbmhome") dbhome = value;
+  }
+
+  if (key == "indexmap") {
+    indexmap.importmap (cfgline);
+
+  } else if (key == "defaultindex") {
+    indexmap.from2to (cfgline[0], defaultindex);
+
+  } else if (key == "subcollectionmap") {
+    subcollectionmap.importmap (cfgline);
+
+  } else if (key == "defaultsubcollection") {
+    subcollectionmap.from2to (cfgline[0], defaultsubcollection);
+
+  } else if (key == "languagemap") {
+    languagemap.importmap (cfgline);
+
+  } else if (key == "defaultlanguage") {
+    languagemap.from2to (cfgline[0], defaultlanguage);
+  } else if (key == "indexstem") {
+    indexstem = cfgline[0];
+  }
+}
+
+text_t sourceclass::resolve_db_filename(const text_t& idx,
+					const text_t& file_ext)
+{
+  // This is an exact copy of the method (of the same name) in filterclass
+  // Makes sense to merge them, in which either gsdlhome, collecthome,
+  // dbhome, and collection need to also be passed in as parameters,
+  // or else there is some notion of a shared base class that both
+  // filter and source inherit from
+
+  // NB: there is an even greater opportunity to share more code in this
+  // function if sql_db_ptr/db_ptr and db_filename and sql_db_filename
+  // are also drawn from one object
+
+  text_t resolved_filename;
+
+  if (gsdlhome==dbhome) {
+    // dbhome has defaulted to gsdlhome which we take to means the 
+    // database has been specifically moved out of gsdlhome area.
+    // => it should be whereever collecthome is set to
+
+    resolved_filename = filename_cat(collecthome, collection, "index", "text", idx);
+  }
+  else {
+    // dbhome is explicitly set to something other than gsdlhome
+    // => use dbhome
+    resolved_filename = filename_cat(dbhome, "collect", collection, "index", "text", idx);
+  }
+
+  resolved_filename += file_ext;
+
+  return resolved_filename;
+}
+
+
+
+// init should be called after all the configuration is done but
+// before any other methods are called
+bool sourceclass::init (ostream &logout)
+{
+  outconvertclass text_t2ascii;
+  
+  if (collecthome.empty()) collecthome = filename_cat(gsdlhome,"collect");
+  if (dbhome.empty()) dbhome = gsdlhome;
+
+  if (defaultindex.empty()) {
+    // use first index in map as default if no default is set explicitly
+    text_tarray toarray;
+    indexmap.gettoarray(toarray);
+    if (toarray.size()) {
+      defaultindex = toarray[0];
+    }
+  }
+
+  if (defaultsubcollection.empty()) {
+    // use first subcollection in map as default if no default is set explicitly
+    text_tarray toarray;
+    subcollectionmap.gettoarray(toarray);
+    if (toarray.size()) {
+      defaultsubcollection = toarray[0];
+    }
+  }
+
+  if (defaultlanguage.empty()) {
+    // use first language in map as default if no default is set explicitly
+    text_tarray toarray;
+    languagemap.gettoarray(toarray);
+    if (toarray.size()) {
+      defaultlanguage = toarray[0];
+    }
+  }
+  
+  // get the collection directory name
+  if (collectdir.empty()) {
+    collectdir = filename_cat (collecthome, collection);
+  }
+
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: queryfilter contains a null dbclass\n\n";
+    return false;
+  }
+
+  // get the filename for the database and make sure it exists
+  if (indexstem.empty()) {
+    indexstem = collection;
+  }
+  db_filename = resolve_db_filename(indexstem, db_ptr->getfileextension());
+  if (!file_exists(db_filename)) {
+    logout << text_t2ascii
+	   << "warning: database \"" << db_filename << "\" does not exist\n\n";
+    // return false;
+  }
+  
+  return true;
+}
+
+
+// translate_OID translates OIDs using ".pr", ."fc" etc.
+bool sourceclass::translate_OID (const text_t &OIDin, text_t &OIDout, 
+				 comerror_t &err, ostream &logout)
+{
+  outconvertclass text_t2ascii;
+
+  err = noError;
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: " << classname << " contains a null dbclass\n\n";
+    err = configurationError;
+    return true;
+  }
+
+  // open the database
+  db_ptr->setlogout(&logout);
+  if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {
+    // most likely a system problem (we have already checked that the database exists)
+    logout << text_t2ascii
+	   << "system problem: open on database \"" << db_filename << "\" failed\n\n";
+    err = systemProblem;
+    return true;
+  }
+
+  infodbclass info;
+  OIDout = db_ptr->translate_OID (OIDin, info);
+  db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+  return true;
+}
+
+
+// get_metadata fills out the metadata if possible, if it is not responsable
+// for the given OID then it will return false.
+bool sourceclass::get_metadata (const text_t &requestParams, const text_t &refParams, 
+				bool getParents, const text_tset &fields, 
+				const text_t &OID, MetadataInfo_tmap &metadata, 
+				comerror_t &err, ostream &logout)
+{
+  outconvertclass text_t2ascii;
+
+  metadata.erase(metadata.begin(), metadata.end());
+
+  err = noError;
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: " << classname <<" contains a null dbclass\n\n";
+    err = configurationError;
+    return true;
+  }
+
+  // open the database
+  db_ptr->setlogout(&logout);
+  if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {
+    // most likely a system problem (we have already checked that the database exists)
+    logout << text_t2ascii
+	   << "system problem: open on database \"" << db_filename << "\" failed\n\n";
+    err = systemProblem;
+    return true;
+  }
+
+  // get the metadata - if getParents is set we need to get 
+  // info for all parents of OID as well as OID
+  vector<infodbclass> info_array;
+  text_tarray OIDs;
+  if (getParents) get_parents_array (OID, OIDs);
+  OIDs.push_back (OID);
+
+  text_tarray::const_iterator this_OID = OIDs.begin();
+  text_tarray::const_iterator end_OID = OIDs.end();
+
+  while (this_OID != end_OID) {
+    infodbclass info;
+    if (!db_ptr->getinfo(*this_OID, info)) return false;
+
+    // adjust the metadata
+    text_t &contains = info["contains"];
+    if (contains.empty()) info["haschildren"] = 0;
+    else info["haschildren"] = 1;
+    //contains.clear();
+
+    info_array.push_back(info);
+    ++this_OID;
+  }
+
+  // if fields set is empty we want to get all available metadata
+  text_tset tfields = fields;
+  if (tfields.empty() && !info_array.empty()) {
+    infodbclass::iterator t_info = info_array[0].begin(); 
+    infodbclass::iterator e_info = info_array[0].end(); 
+    while (t_info != e_info) {
+      if ((*t_info).first != "contains")
+	tfields.insert ((*t_info).first);
+      ++t_info;
+    }
+    tfields.insert ("hasnext");
+    tfields.insert ("hasprevious");
+  }
+    
+  // collect together the metadata
+  bool donenextprevtest = false;
+  bool hasnext=false, hasprevious=false;
+  MetadataInfo_t this_metadata;
+  text_tarray *pos_metadata;
+  text_tset::const_iterator fields_here = tfields.begin();
+  text_tset::const_iterator fields_end = tfields.end();
+
+  while (fields_here != fields_end) {
+    this_metadata.clear();
+    this_metadata.isRef = false;
+
+    vector<infodbclass>::reverse_iterator this_info = info_array.rbegin(); 
+    vector<infodbclass>::reverse_iterator end_info = info_array.rend(); 
+    MetadataInfo_t *tmetaptr = &this_metadata;
+    while (this_info != end_info) {
+
+      pos_metadata = (*this_info).getmultinfo(*fields_here);
+      if ((*fields_here == "hasnext" || *fields_here == "hasprevious")) {
+	
+	// collect metadata
+	if (!donenextprevtest) {
+	  donenextprevtest = true;
+	  
+	  // cache parent contents array
+	  text_t thisparent = get_parent (OID);
+	  if (!thisparent.empty()) {
+	    if (thisparent != parentOID) {
+	      parentOID = thisparent;
+	      parentcontents.erase(parentcontents.begin(), parentcontents.end());
+	      if (db_ptr->getinfo(parentOID, parentinfo)) {
+		text_t &parentinfocontains = parentinfo["contains"];
+		if (!parentinfocontains.empty())
+		  splitchar (parentinfocontains.begin(), parentinfocontains.end(), 
+			     ';', parentcontents);
+	      }
+	    }
+	    
+	    // do tests
+	    text_tarray::const_iterator parentcontents_here = parentcontents.begin();
+	    text_tarray::const_iterator parentcontents_end = parentcontents.end();
+	    text_t shrunk_OID = OID;
+	    shrink_parent (shrunk_OID);
+	    while (parentcontents_here != parentcontents_end) {
+	      if (*parentcontents_here == shrunk_OID) {
+		if (parentcontents_here == parentcontents.begin()) hasprevious = false;
+		else hasprevious = true;
+		
+		++parentcontents_here;
+		
+		if (parentcontents_here == parentcontents.end()) hasnext = false;
+		else hasnext = true;
+		
+		break;
+	      }  
+	      
+	      ++parentcontents_here;
+	    }
+	 
+	    // fill in metadata
+	    if ((*fields_here == "hasnext" && hasnext) ||
+		(*fields_here == "hasprevious" && hasprevious))
+	      tmetaptr->values.push_back("1");
+	    else
+	      tmetaptr->values.push_back("0");
+	  } else
+	    tmetaptr->values.push_back("0");
+	}
+      }
+      //else if (pos_metadata != NULL && *fields_here != "contains") {
+      else if (pos_metadata != NULL) {
+	tmetaptr->values = *pos_metadata;
+      }
+      else
+	tmetaptr->values.push_back("");
+
+      ++this_info;
+      if (this_info != end_info) {
+	tmetaptr->parent = new MetadataInfo_t();
+	tmetaptr = tmetaptr->parent;
+      }
+    }
+    metadata[*fields_here] = this_metadata;
+    ++fields_here;
+  }
+
+  db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+  return true;
+}
+
+bool sourceclass::get_document (const text_t &OID, text_t &doc, 
+				comerror_t &err, ostream &logout)
+{
+  outconvertclass text_t2ascii;
+
+  err = noError;
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: " << classname << " contains a null dbclass\n\n";
+    err = configurationError;
+    return true;
+  }
+
+  // open the database
+  db_ptr->setlogout(&logout);
+  if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {
+    // most likely a system problem (we have already checked that the database exists)
+    logout << text_t2ascii
+	   << "system problem: open on database \"" << db_filename << "\" failed\n\n";
+    err = systemProblem;
+    return true;
+  }
+
+  text_t tOID = OID;
+  if (needs_translating (OID)) 
+    translate_OID (OID, tOID, err, logout);
+  infodbclass info;
+  if (!db_ptr->getinfo(tOID, info)) {
+    db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+    return false;
+  }
+  
+  if (info["hastxt"].getint() == 1) {
+    int docnum = info["docnum"].getint();
+    
+    // set the collection directory
+    textsearchptr->setcollectdir (collectdir);
+    
+    // get the text
+    textsearchptr->docTargetDocument(defaultindex, defaultsubcollection,
+				   defaultlanguage, collection, docnum, doc);
+  }
+
+  db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+  return true;
+}
+
+bool sourceclass::is_searchable(bool &issearchable, comerror_t &err, ostream &logout)
+{
+  err = noError;
+  issearchable = false;
+
+  text_tarray fromarray;
+  indexmap.getfromarray(fromarray);
+  if (fromarray.size() == 0) {
+    return true;
+  } else if (fromarray.size() == 1) {
+    if (fromarray[0] == "dummy:text") {
+      // always return true - issearchable is false here though
+      return true;
+    }
+  }
+  issearchable = true;
+  return true;
+}
+
+
+bool operator==(const sourceptr &x, const sourceptr &y) {
+  return (x.s == y.s);
+}
+
+bool operator<(const sourceptr &x, const sourceptr &y) {
+  return (x.s < y.s);
+}
+
+
+// thesource remains the property of the calling code but
+// should not be deleted until it is removed from this list.
+void sourcelistclass::addsource (sourceclass *thesource) {
+  // can't add a source that doesn't exist
+  assert (thesource != NULL);
+  if (thesource == NULL) return;
+
+  sourceptr sp;
+  sp.s = thesource;
+
+  sourceptrs.push_back(sp);
+}
Index: /gsdl/trunk/runtime-src/src/colservr/source.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/source.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/source.h	(revision 16571)
@@ -0,0 +1,164 @@
+/**********************************************************************
+ *
+ * source.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef SOURCE_H
+#define SOURCE_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "dbclass.h"
+#include "search.h"
+#include "comtypes.h"
+#include "maptools.h"
+
+
+class sourceclass {
+protected:
+  text_t classname;
+
+  text_t gsdlhome;
+  text_t collecthome;
+  text_t dbhome;
+  text_t collection;
+  text_t collectdir;
+
+  stringmap indexmap;
+  stringmap subcollectionmap;
+  stringmap languagemap;
+
+  text_t defaultindex;
+  text_t defaultsubcollection;
+  text_t defaultlanguage;
+
+  text_t indexstem;
+
+  text_t parentOID;
+  infodbclass parentinfo;
+  text_tarray parentcontents;
+
+  text_t db_filename;
+  dbclass *db_ptr;
+
+  searchclass *textsearchptr;
+
+public:
+  sourceclass ();
+  virtual ~sourceclass ();
+
+  // the DB ptr remains the responsibility of the calling code
+  void set_db_ptr (dbclass *db_ptr_arg) { db_ptr = db_ptr_arg; }
+
+  // the textsearchptr remains the responsibility of the calling code
+  void set_textsearchptr (searchclass *textsearchptr_arg) { textsearchptr = textsearchptr_arg; }
+
+  // configure should be called once for each configuration line
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+
+  // init should be called after all the configuration is done but
+  // before any other methods are called
+  virtual bool init (ostream &logout);
+
+  // translate_OID translates OIDs using ".pr", ."fc" etc.
+  virtual bool translate_OID (const text_t &OIDin, text_t &OIDout, 
+			      comerror_t &err, ostream &logout);
+
+  // get_metadata fills out the metadata if possible, if it is not responsable
+  // for the given OID then it will return false.
+  virtual bool get_metadata (const text_t &requestParams, const text_t &refParams, 
+			     bool getParents, const text_tset &fields,
+			     const text_t &OID, MetadataInfo_tmap &metadata, 
+			     comerror_t &err, ostream &logout);
+
+  virtual bool get_document (const text_t &OID, text_t &doc, 
+			     comerror_t &err, ostream &logout);
+
+  virtual bool is_searchable(bool &issearchable, comerror_t &err, ostream &logout);
+
+ protected:
+  text_t resolve_db_filename(const text_t& idx,
+			     const text_t& file_ext);
+
+};
+
+
+// The sourceptr class does not 'own' the source. The 
+// source should be deleted by the code which created it.
+class sourceptr {
+public:
+  sourceclass *s;
+
+  sourceptr () {s=NULL;}
+  ~sourceptr () {}
+};
+
+bool operator==(const sourceptr &x, const sourceptr &y);
+bool operator<(const sourceptr &x, const sourceptr &y);
+
+typedef vector<sourceptr> sourceptrlist;
+
+// contains a list of sources
+class sourcelistclass {
+protected:
+  sourceptrlist sourceptrs;
+
+public:
+  // type support for sourcelistclass
+  typedef sourceptrlist::iterator iterator;
+  typedef sourceptrlist::const_iterator const_iterator;
+  typedef sourceptrlist::reference reference;
+  typedef sourceptrlist::const_reference const_reference;
+  typedef sourceptrlist::size_type size_type;
+
+  typedef sourceptrlist::difference_type difference_type;
+  typedef sourceptrlist::const_reverse_iterator const_reverse_iterator;
+  typedef sourceptrlist::reverse_iterator reverse_iterator;
+  
+  // basic container support
+  iterator begin () {return sourceptrs.begin();}
+  const_iterator begin () const {return sourceptrs.begin();}
+  iterator end () {return sourceptrs.end();}
+  const_iterator end () const {return sourceptrs.end();}
+
+  void erase(iterator pos) {sourceptrs.erase(pos);}
+  void erase(iterator first, iterator last) {sourceptrs.erase(first, last);}
+  sourcelistclass &operator=(const sourcelistclass &x) 
+    {sourceptrs=x.sourceptrs;return *this;}
+
+  bool empty () const {return sourceptrs.empty();}
+  size_type size() const {return sourceptrs.size();}
+
+
+  // added functionality
+  void clear () {sourceptrs.erase(sourceptrs.begin(),sourceptrs.end());}
+
+  // thesource remains the property of the calling code but
+  // should not be deleted until it is removed from this list.
+  void addsource (sourceclass *thesource);
+};
+
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/sqlbrowsefilter.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/sqlbrowsefilter.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/sqlbrowsefilter.cpp	(revision 16571)
@@ -0,0 +1,204 @@
+/**********************************************************************
+ *
+ * sqlbrowsefilter.cpp -- 
+ * Copyright (C) 2008  DL Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "sqlbrowsefilter.h"
+#include "fileutil.h"
+
+
+sqlbrowsefilterclass::sqlbrowsefilterclass ()
+{
+  sql_db_ptr = NULL;
+}
+
+
+sqlbrowsefilterclass::~sqlbrowsefilterclass ()
+{
+}
+
+
+void sqlbrowsefilterclass::configure (const text_t &key, const text_tarray &cfgline)
+{
+  filterclass::configure (key, cfgline);
+
+  if (key == "indexstem")
+  {
+    indexstem = cfgline[0];
+  }
+}
+
+
+bool sqlbrowsefilterclass::init (ostream &logout)
+{
+  outconvertclass text_t2ascii;
+
+  if (!filterclass::init(logout)) return false;
+
+  if (sql_db_ptr == NULL)
+  {
+    // most likely a configuration problem
+    logout << text_t2ascii << "configuration error: sqlbrowsefilter contains a null sqldbclass\n\n";
+    return false;
+  }
+
+  if (indexstem.empty())
+  {
+    indexstem = collection;
+  }
+
+  // get the filename for the database and make sure it exists
+  sql_db_filename = resolve_db_filename(indexstem,sql_db_ptr->getfileextension());
+  if (!file_exists(sql_db_filename))
+  {
+    logout << text_t2ascii << "warning: database \"" << sql_db_filename << "\" does not exist\n\n";
+    return false;
+  }
+
+  return true;
+}
+
+
+void sqlbrowsefilterclass::filter (const FilterRequest_t &request,
+				   FilterResponse_t &response,
+				   comerror_t &err, ostream &logout)
+{
+  outconvertclass text_t2ascii;
+
+  response.clear();
+  err = noError;
+
+  if (sql_db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii << "configuration error: sqlbrowsefilter contains a null sqldbclass\n\n";
+    err = configurationError;
+    return;
+  }
+
+  // open the database
+  sql_db_ptr->setlogout (&logout);
+  if (!sql_db_ptr->opendatabase (sql_db_filename, DB_READER, 100, false)) {
+    // most likely a system problem (we have already checked that the database exists)
+    logout << text_t2ascii << "system problem: open on database \"" << sql_db_filename << "\" failed\n\n";
+    err = systemProblem;
+    return;
+  }
+
+  // Request for the metadata values assigned to an element
+  if (request.requestParams == "GetMetadataValues")
+  {
+    text_tarray metadata_element_names;
+    text_t metadata_value_filter = "";
+    text_t metadata_value_grouping_expression = "";
+    OptionValue_tarray::const_iterator options_iterator = request.filterOptions.begin();
+    while (options_iterator != request.filterOptions.end())
+    {
+      if ((*options_iterator).name == "MetadataElements")
+      {
+	splitchar ((*options_iterator).value.begin(), (*options_iterator).value.end(), ',', metadata_element_names);
+      }
+      if ((*options_iterator).name == "MetadataValueFilter")
+      {
+	metadata_value_filter = (*options_iterator).value;
+      }
+      if ((*options_iterator).name == "MetadataValueGroupingExpression")
+      {
+	metadata_value_grouping_expression = (*options_iterator).value;
+      }
+      options_iterator++;
+    }
+
+    text_tarray metadata_values = sql_db_ptr->get_metadata_values (metadata_element_names, metadata_value_filter, metadata_value_grouping_expression);
+
+    // Create a map from metadata value to ResultDocInfo_t, to remove duplicate values and obtain occurrence counts
+    map<text_t, ResultDocInfo_t> unique_metadata_values_map;
+    text_tarray::iterator metadata_value_iterator = metadata_values.begin();
+    while (metadata_value_iterator != metadata_values.end())
+    {
+      text_t metadata_value = *metadata_value_iterator;
+
+      // If no ResultDocInfo_t has already been created for this metadata value, create one now
+      if (unique_metadata_values_map.find(metadata_value) == unique_metadata_values_map.end())
+      {
+	ResultDocInfo_t metadata_value_result_doc;
+	metadata_value_result_doc.OID = metadata_value;
+	metadata_value_result_doc.result_num = 1;
+	unique_metadata_values_map[metadata_value] = metadata_value_result_doc;
+      }
+      // Otherwise we've seen this value before, so just update the occurrence count
+      else
+      {
+	unique_metadata_values_map[metadata_value].result_num++;
+      }
+
+      metadata_value_iterator++;
+    }
+
+    // Fill in response.docInfo with the ResultDocInfo_t objects we've created above
+    map<text_t, ResultDocInfo_t>::iterator unique_metadata_values_iterator = unique_metadata_values_map.begin();
+    while (unique_metadata_values_iterator != unique_metadata_values_map.end())
+    {
+      response.docInfo.push_back ((*unique_metadata_values_iterator).second);
+      unique_metadata_values_iterator++;
+    }
+  }
+
+  // Request for the documents with a certain metadata value assigned
+  else if (request.requestParams == "GetDocumentsWithMetadataValue")
+  {
+    text_tarray metadata_element_names;
+    text_t metadata_value = "";
+    text_t sort_by_metadata_element_name = "";
+    OptionValue_tarray::const_iterator options_iterator = request.filterOptions.begin();
+    while (options_iterator != request.filterOptions.end())
+    {
+      if ((*options_iterator).name == "MetadataElements")
+      {
+	splitchar ((*options_iterator).value.begin(), (*options_iterator).value.end(), ',', metadata_element_names);
+      }
+      if ((*options_iterator).name == "MetadataValue")
+      {
+	metadata_value = (*options_iterator).value;
+      }
+      if ((*options_iterator).name == "SortByMetadataElement")
+      {
+	sort_by_metadata_element_name = (*options_iterator).value;
+      }
+      options_iterator++;
+    }
+
+    text_tarray document_OIDs = sql_db_ptr->get_documents_with_metadata_value (metadata_element_names, metadata_value, sort_by_metadata_element_name);
+
+    // Fill in response.docInfo with the document OIDs
+    text_tarray::iterator document_OID_iterator = document_OIDs.begin();
+    while (document_OID_iterator != document_OIDs.end())
+    {
+      ResultDocInfo_t document_result_doc;
+      document_result_doc.OID = *document_OID_iterator;
+      response.docInfo.push_back (document_result_doc);
+      document_OID_iterator++;
+    }
+  }
+
+  sql_db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+}
Index: /gsdl/trunk/runtime-src/src/colservr/sqlbrowsefilter.h
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/sqlbrowsefilter.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/sqlbrowsefilter.h	(revision 16571)
@@ -0,0 +1,63 @@
+/**********************************************************************
+ *
+ * sqlbrowsefilter.h -- 
+ * Copyright (C) 2008  DL Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef SQLBROWSEFILTER_H
+#define SQLBROWSEFILTER_H
+
+
+#include "filter.h"
+#include "comtypes.h"
+#include "sqldbclass.h"
+#include "text_t.h"
+
+
+class sqlbrowsefilterclass : public filterclass {
+protected:
+  text_t sql_db_filename;
+  text_t indexstem;
+  sqldbclass *sql_db_ptr;
+
+public:
+  sqlbrowsefilterclass ();
+  virtual ~sqlbrowsefilterclass ();
+
+  text_t get_filter_name () { return "SQLBrowseFilter"; }
+
+  // configure should be called once for each configuration line
+  // default configures the default filter options
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+
+  // the sql db ptr remains the responsibility of the calling code and
+  // should be destroyed after this sqlbrowsefilter is destroyed
+  void set_sql_db_ptr (sqldbclass *sql_db_ptr_arg) { sql_db_ptr = sql_db_ptr_arg; }
+
+  bool init (ostream &logout);
+  void filter (const FilterRequest_t &request,
+	       FilterResponse_t &response,
+	       comerror_t &err, ostream &logout);
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/colservr/win32.mak
===================================================================
--- /gsdl/trunk/runtime-src/src/colservr/win32.mak	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/colservr/win32.mak	(revision 16571)
@@ -0,0 +1,160 @@
+###########################################################################
+#
+# win32 makefile -- src/colservr
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ..\..
+INDEXERS_DIR = $(GSDL_DIR)\indexers
+PACKAGES_DIR = $(GSDL_DIR)\packages
+
+
+GSDL_VC4 = 0
+DLL = 0
+DLLDEBUG = 0
+USE_SQLITE = 0
+
+
+!IF $(GSDL_VC4)
+CPPFLAGS = -GX
+!ELSE
+CPPFLAGS = -EHsc
+!ENDIF
+
+!IF $(DLL)
+CPPFLAGS = $(CPPFLAGS) -MD
+!ELSE
+!IF ($(DLLDEBUG))
+CPPFLAGS = $(CPPFLAGS) -MDd
+!ENDIF
+!ENDIF
+
+!IF $(USE_SQLITE)
+SQLITE_DEFINES = -DUSE_SQLITE
+SQLITE_INCLUDES = -I"$(PACKAGES_DIR)\sqlite\include"
+!ELSE
+SQLITE_DEFINES = 
+SQLITE_INCLUDES = 
+!ENDIF
+
+
+AR = lib
+CC = cl
+DEFS = -D__WIN32__ -DHAVE_CONFIG_H -DPARADOCNUM -D_LITTLE_ENDIAN -DSHORT_SUFFIX -D_CRT_SECURE_NO_DEPRECATE \
+        -DXML_STATIC $(SQLITE_DEFINES)
+# Do NOT add the "recpt" directory here: the colserver should be independent of the receptionist!
+INCLUDES = -I"$(GSDL_DIR)" -I"$(GSDL_DIR)\src\lib" \
+	-I"$(INDEXERS_DIR)\mg" -I"$(INDEXERS_DIR)\mg\lib" -I"$(INDEXERS_DIR)\mg\src\text" \
+	-I"$(INDEXERS_DIR)\mgpp\lib" -I"$(INDEXERS_DIR)\mgpp\text" \
+	-I"$(PACKAGES_DIR)\windows\expat\expat" -I"$(PACKAGES_DIR)\windows\gdbm\gdbm" $(SQLITE_INCLUDES)
+
+!IF $(GSDL_VC4)
+DEFS=$(DEFS) -DGSDL_NAMESPACE_BROKEN -DGSDL_USE_IOS_H -D__STL_NO_NEW_IOSTREAMS
+INCLUDES = $(INCLUDES) -I"$(PACKAGES_DIR)\windows\stlport\stlport"
+!ENDIF
+
+
+COMPILE = $(CC) -nologo -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+
+
+.SUFFIXES:
+.SUFFIXES: .c .obj
+.c.obj:
+	$(COMPILE) $<
+
+.SUFFIXES: .cpp .obj
+.cpp.obj:
+	$(COMPILE) $< 
+
+
+SOURCES = \
+        browsefilter.cpp \
+	collectserver.cpp \
+	collectset.cpp \
+        colservrconfig.cpp \
+	comtypes.cpp \
+	expat_document.cpp \
+	expat_resultset.cpp \
+	filter.cpp \
+	lucenequeryfilter.cpp \
+	lucenesearch.cpp \
+	lucenesource.cpp \
+	maptools.cpp \
+	mgq.c \
+	mgqueryfilter.cpp \
+	mgsearch.cpp \
+	mgsource.cpp \
+	mgppqueryfilter.cpp \
+	mgppsearch.cpp \
+	phrasequeryfilter.cpp \
+	phrasesearch.cpp \
+	querycache.cpp \
+	queryfilter.cpp \
+	queryinfo.cpp \
+	search.cpp \
+	source.cpp \
+	sqlbrowsefilter.cpp
+
+OBJECTS = \
+        browsefilter.obj \
+	collectserver.obj \
+	collectset.obj \
+        colservrconfig.obj \
+	comtypes.obj \
+	expat_document.obj \
+	expat_resultset.obj \
+	filter.obj \
+	lucenequeryfilter.obj \
+	lucenesearch.obj \
+	lucenesource.obj \
+	maptools.obj \
+	mgq.obj \
+	mgqueryfilter.obj \
+	mgsearch.obj \
+	mgsource.obj \
+	mgppqueryfilter.obj \
+	mgppsearch.obj \
+	phrasequeryfilter.obj \
+	phrasesearch.obj \
+	querycache.obj \
+	queryfilter.obj \
+	queryinfo.obj \
+	search.obj \
+	source.obj \
+	sqlbrowsefilter.obj
+
+LIBRARY = gsdlcolservr.lib	
+
+
+# Default target: make gsdlcolservr.lib
+all: $(LIBRARY)
+
+gsdlcolservr.lib: $(OBJECTS) 
+	if EXIST $(LIBRARY) del $(LIBRARY)
+	$(AR) -nologo /out:$(LIBRARY) $(OBJECTS)
+
+install:
+
+clean:
+	del *.obj
+	del $(LIBRARY)
Index: /gsdl/trunk/runtime-src/src/corba/Makefile.in
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/Makefile.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/Makefile.in	(revision 16571)
@@ -0,0 +1,156 @@
+###########################################################################
+#
+# Makefile -- src/corba
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ../..
+INDEXERS_DIR = $(GSDL_DIR)/indexers
+PACKAGES_DIR = $(GSDL_DIR)/packages
+COLSERVR_DIR = $(GSDL_DIR)/src/colservr
+PROTOCOL_DIR = $(GSDL_DIR)/src/protocol
+RECPT_DIR = $(GSDL_DIR)/src/recpt
+
+
+ENABLE_ACCENTFOLD = @ENABLE_ACCENTFOLD@
+ifeq ($(ENABLE_ACCENTFOLD), 1)
+ACCENTFOLD_LIBS = $(INDEXERS_DIR)/packages/unac/libunac.a 
+else
+ACCENTFOLD_LIBS = 
+endif
+
+USE_SQLITE = @USE_SQLITE@
+ifeq ($(USE_SQLITE), 1)
+SQLITE_LIBS = $(PACKAGES_DIR)/sqlite/lib/libsqlite3.a -ldl -lpthread
+else
+SQLITE_LIBS = 
+endif
+
+MICO_DIR = @MICO_DIR@
+MICO_VER = @MICO_VER@
+ifeq ($(MICO_DIR), default)
+MICO_INCLUDES = -I$(PACKAGES_DIR)/mico/mico/include
+MICO_PATH = $(PACKAGES_DIR)/mico/bin/
+else
+ifeq ($(MICO_DIR), yes)
+MICO_INCLUDES =
+else
+MICO_INCLUDES = -I$(MICO_DIR)
+endif
+MICO_PATH =
+endif
+
+USE_CORBA = @USE_CORBA@
+ifeq ($(USE_CORBA), 1)
+AR = ar
+CC = @CC@
+CFLAGS = @CFLAGS@
+DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DGSDLSERVER
+INCLUDES = -I$(GSDL_DIR)/src/lib -I$(COLSERVR_DIR) -I$(PROTOCOL_DIR) -I$(RECPT_DIR) -I$(INDEXERS_DIR)/mgpp/text \
+	$(MICO_INCLUDES)
+INSTALL = @INSTALL@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@ @GDBM_LIBPATH@ -lgdbm -L$(PACKAGES_DIR)/expat/lib -lexpat $(ACCENTFOLD_LIBS) \
+        $(SQLITE_LIBS) -L$(PACKAGES_DIR)/mico/lib -lmico$(MICO_VER)
+RANLIB = @RANLIB@
+
+
+COMPILE = $(MICO_PATH)mico-c++ -x c++ $(CFLAGS) $(DEFS) $(INCLUDES) -c
+LINK = $(MICO_PATH)mico-ld $(LDFLAGS) -o $@
+
+
+.SUFFIXES: .mpp .o
+.mpp.o:
+	$(COMPILE) $<
+
+
+SOURCES = \
+	corbaconv_text_t.mpp \
+	corbaiface.mpp \
+	corbaiface_skel.mpp \
+	corbaproto.mpp \
+	corbatext_t.mpp
+
+OBJECTS = \
+	corbaconv_text_t.o \
+	corbaiface.o \
+	corbaiface_skel.o \
+	corbaproto.o \
+	corbatext_t.o
+
+CORBASERVER_OBJECTS = \
+	corbaServer.o
+
+CORBARECPT_OBJECTS = \
+	corbaclient.o
+
+GSDL_LIBS = \
+	$(RECPT_DIR)/gsdlrecpt.a \
+	$(PROTOCOL_DIR)/gsdlprotocol.a \
+	$(COLSERVR_DIR)/gsdlcolservr.a \
+	$(INDEXERS_DIR)/mg/src/text/libmgtext.a \
+	$(INDEXERS_DIR)/mg/lib/libmglib.a \
+	$(INDEXERS_DIR)/mgpp/text/libmgpptext.a \
+	$(INDEXERS_DIR)/mgpp/lib/libmgpplib.a \
+	$(GSDL_DIR)/src/lib/gsdllib.a
+
+CORBASERVER_EXECUTABLE_OBJECTS = \
+	$(OBJECTS) \
+	$(CORBASERVER_OBJECTS) \
+	$(GSDL_LIBS)
+
+CORBARECPT_EXECUTABLE_OBJECTS = \
+	$(OBJECTS) \
+	$(CORBARECPT_OBJECTS) \
+	$(GSDL_LIBS)
+
+EXECUTABLES = corbaserver corbarecptldd
+
+
+# Default target: make both corbaserver and corbarecptldd
+all: $(EXECUTABLES)
+
+corbaserver: $(CORBASERVER_EXECUTABLE_OBJECTS)
+	$(LINK) $(CORBASERVER_EXECUTABLE_OBJECTS) $(LIBS)
+
+corbarecptldd: $(CORBARECPT_EXECUTABLE_OBJECTS)
+	$(LINK) $(CORBARECPT_EXECUTABLE_OBJECTS) $(LIBS)
+
+install:
+
+clean:
+	rm -f $(OBJECTS) $(CORBASERVER_OBJECTS) $(CORBARECPT_OBJECTS) $(EXECUTABLES)
+
+distclean:
+	rm -f $(OBJECTS) $(CORBASERVER_OBJECTS) $(CORBARECPT_OBJECTS) $(EXECUTABLES) Makefile
+
+depend:
+	makedepend -Y -- $(DEFS) $(INCLUDES) $(CXXFLAGS) -- $(SOURCES)
+
+else
+all:
+install:
+clean:
+distclean:
+depend:
+endif
Index: /gsdl/trunk/runtime-src/src/corba/corbaServer.mpp
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbaServer.mpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbaServer.mpp	(revision 16571)
@@ -0,0 +1,491 @@
+// Standard headers
+#include <iostream.h>
+#include <fstream.h>
+
+// protocol headers
+#include "corbaiface.h"
+using namespace gsdlInterface;
+
+#include "corbaconv_text_t.h"
+
+// library headers
+#include "fileutil.h"
+//#include "gsdlhome.h"
+
+// greenstone headers
+#include "comtypes.h"
+#include "recptproto.h"
+#include "nullproto.h"
+
+// local headers
+#include "corbatext_t.h"
+
+void corbatext_setToCorbaArray(text_tset set, corbatext_tset *cset);
+void corbatext_corbaArrayToSet(corbatext_tset cset, text_tset *set);
+void corbatext_mapToCorbaMap(text_tmap map, corbatext_tmap *tm);
+void corbaresponse_resultDocInfoToCorba(ResultDocInfo_tarray docinfo, corbaResultDocInfo_array &corbainfo);
+
+void corbaresponse_termInfoToCorba(TermInfo_tarray terminfo, corbaTermInfo_array &corbainfo) {
+  TermInfo_tarray::iterator here = terminfo.begin();
+  TermInfo_tarray::iterator end  = terminfo.end();
+  unsigned int i;
+	
+  i = 0;
+
+  while (here != end) 
+    {
+      corbainfo.length(i+1);
+      
+      corbainfo[i].frequency = here->freq;
+      corbaconv_text_t::getCorbatext(here->term,corbainfo[i].term);
+      corbatext_arrayToCorbaArray(here->matchTerms, &corbainfo[i].matchTerms);
+
+      i ++;
+      here ++;
+    }
+  cout << "Terminfo " << i << endl;
+}
+
+void corbatext_optionValueArrayToC(corbaOptionValue_array corba, OptionValue_tarray &array)
+{
+  unsigned int i = 0;
+  OptionValue_t option;
+
+  for (i = 0; i < corba.length(); i ++)
+    {
+      corbaconv_text_t::setCorbatext(option.name,corba[i].name);
+      corbaconv_text_t::setCorbatext(option.value,corba[i].value);
+
+      // cout << corbatext_string(corba[i].name) << "?" << option
+
+      array.push_back(option);
+    }
+}
+
+class corbaServer : virtual public corbaiface_skel
+{
+private:
+  text_tarray collections;
+  recptproto *protocol;
+  text_t      gsdlhome;
+
+  void openLogfile(text_t extension, ofstream &out)
+  {
+    char *cfilename;
+    text_t filename;
+
+    filename = filename_cat(gsdlhome, extension);
+    cfilename = filename.getcstr();
+
+    out.open(cfilename);
+    delete cfilename;
+  }
+
+public:
+  corbaServer(recptproto *protocol, text_t home)
+  { 
+    text_t dirname;
+    char * cdirname;
+
+    cout << "CorbaServer: gsdlhome = " << home << endl;
+
+    this->gsdlhome = home;
+    cout << gsdlhome.getcstr() << endl;
+    dirname = filename_cat(gsdlhome, "/collect");
+    cdirname = dirname.getcstr();
+    if (!read_dir (cdirname, collections)) {
+      cout << "Unable to read the gsdl directory; terminating" << endl;
+      exit (1);
+    }
+    delete cdirname;
+
+    cout << "Constructing set list server" << endl;
+    this->protocol = protocol;
+
+  }
+  
+  CORBA::Boolean initialise(corbaComError &err) 
+  {
+      ofstream      logout;
+      int           reply;
+      comerror_t    error = noError;
+
+      this->openLogfile("/etc/corbaout.txt", logout);
+      reply = protocol->init(error, logout);
+      logout.close();
+      return (reply != 0 ? 1 : 0);
+    }
+
+  void configure(const corbatext_t &corbaKey, const corbatext_tarray &corbaCfgline,corbaComError &err)
+    {
+      text_t        key;
+      text_tarray   cfgline;
+      comerror_t    error = noError;
+
+      corbaconv_text_t::setCorbatext(key,corbaKey);
+      corbatext_corbaArrayToArray(corbaCfgline, &cfgline);
+
+
+      // ****
+      cout << "Recieved " << key << " = ";
+      for (int unsigned i=0; i<cfgline.size(); i++)
+	{
+	  cout << cfgline[i] << " ";
+	}
+      cout << endl;
+
+      // DB // ****
+      if (key=="gsdlhome")
+	{  
+	  text_tarray cfgline;
+	  cfgline.push_back (gsdlhome);
+	  cout << "Changing gsdlhome to " << gsdlhome << endl;
+	  protocol->configure(key, cfgline, error);
+	}
+      else if (key=="httpdomain")
+	{
+	  // Only let gsdlhome through !!!! // ****
+	  cout << "Supressing httpdomain" << endl;
+	}
+      else if (key=="httpprefix")
+	{
+	  cout << "Supressing httpprefix" << endl;
+	}
+      else
+	{ 
+	  protocol->configure(key, cfgline,error);
+	}
+    }
+
+  void hasCollection(const corbatext_t &corbaCollect, CORBA::Boolean &has,
+                     corbaComError &error) {
+    // do nowt!
+    corbaconv_text_t *cct;
+    bool    _has;
+    comerror_t err = noError;
+    ofstream logout;
+
+    this->openLogfile("/etc/corbaout.txt", logout);
+
+    cct = new corbaconv_text_t(corbaCollect);
+
+    cout << "Collection: " << cct->getcstr() << endl;
+
+    protocol->has_collection(*cct, _has, err, logout); // 'cct' typecast to text_t
+    if (_has)
+      { 
+	has = 1;
+      }
+    else
+      {
+	has = 0;
+      }
+
+    // cout << "  " << has << endl;
+
+    delete cct;
+
+    error = corbaNoError;
+    logout.close();
+  }
+
+  void ping(const struct corbatext_t &corbaCollect, CORBA::Boolean &wasSuccess, corbaComError &corbaError)
+  { 
+    text_t collection;
+    bool   success;
+    comerror_t error = noError;
+    ofstream logout;
+
+    this->openLogfile("/etc/corbaout.txt", logout);
+
+    corbaconv_text_t::setCorbatext(collection,corbaCollect);
+    protocol->ping(collection, success, error, logout);
+
+    corbaError = (corbaComError) error;
+    wasSuccess = (CORBA::Boolean) success;
+    logout.close();
+  }
+
+  void filter(const struct corbatext_t &corbaCollect,
+	      const struct corbaFilterRequest &corbaRequest,
+	      struct corbaFilterResponse &corbaResponse,
+	      corbaComError &corbaError)
+  {
+    // variables for action
+    FilterRequest_t request;
+    FilterResponse_t response;
+    comerror_t       error = noError;
+    text_t           collection;
+    ofstream         logout;
+
+    this->openLogfile("/etc/corbaout.txt", logout);
+
+    // copy collection id
+    corbaconv_text_t::setCorbatext(collection,corbaCollect);
+
+    // copy request values
+    corbaconv_text_t::setCorbatext(request.filterName,corbaRequest.filter);
+    corbatext_optionValueArrayToC(corbaRequest.filterOptions, request.filterOptions);
+    corbatext_corbaArrayToArray(corbaRequest.docSet, &request.docSet);
+    request.filterResultOptions = corbaRequest.filterResultOptions;
+    corbaconv_text_t::setCorbatext(request.requestParams,corbaRequest.requestParams);
+    corbaconv_text_t::setCorbatext(request.refParams,corbaRequest.refParams);
+    corbatext_corbaArrayToSet(corbaRequest.fields, &request.fields);
+    request.getParents = corbaRequest.getParents;
+
+    protocol->filter(collection, request, response, error, logout);
+
+    // copy response values
+    corbaResponse.numDocs = response.numDocs;
+    corbaResponse.isApprox = (::gsdlInterface::corbaIsApprox) response.isApprox;
+    corbaresponse_termInfoToCorba(response.termInfo, corbaResponse.termInfo);
+    corbaresponse_resultDocInfoToCorba(response.docInfo, corbaResponse.docInfo);
+
+    // tidy up variables
+    logout.close();
+    corbaError = (corbaComError) error;
+    cout << "Filter prepared" << corbaResponse.docInfo.length() << "," << corbaResponse.numDocs << endl;
+  }
+
+  void getCollectInfo(const struct corbatext_t &corbaCollect,
+                      corbaColInfoResponse &corbaResponse,
+                      corbaComError &corbaError)
+  {
+    ColInfoResponse_t response;
+    comerror_t       error = noError;
+    text_t           collection;
+    ofstream logout;
+
+    this->openLogfile("/etc/corbaout.txt", logout);
+
+    corbaconv_text_t::setCorbatext(collection,corbaCollect);
+    protocol->get_collectinfo(collection, response, error, logout);
+
+    cout << "IsPublic  = " << ((response.isPublic)?"True":"False") << endl;
+    cout << "IsBeta    = " << ((response.isBeta)  ?"True":"False") << endl;
+    cout << "BuildDate = " << response.buildDate << endl;
+    cout << "NumDocs   = " << response.numDocs << endl;
+    cout << "NumBytes  = " << response.numBytes << endl;
+    cout << "NumWords  = " << response.numWords << endl;
+    cout << "UseBook   = " << ((response.useBook)  ?"True":"False") << endl;
+    
+    corbaResponse.useBook   = response.useBook;
+    corbaResponse.isPublic  = response.isPublic;
+    corbaResponse.isBeta    = response.isBeta;
+    corbaResponse.buildDate = response.buildDate;
+    corbatext_arrayToCorbaArray(response.languages, &corbaResponse.languages);
+    corbatext_arrayToCorbaArray(response.ccsCols, &corbaResponse.ccsCols);
+    corbaResponse.numDocs   = response.numDocs;
+    corbaResponse.numBytes  = response.numBytes;
+    corbaResponse.numWords  = response.numWords;
+
+    corbatext_mapToCorbaMap(response.collectionmeta, &corbaResponse.collectionMeta);
+    corbatext_mapToCorbaMap(response.format, &corbaResponse.format);
+    corbatext_mapToCorbaMap(response.building, &corbaResponse.building);
+    corbaconv_text_t::getCorbatext(response.httpdomain,corbaResponse.httpdomain);
+
+    corbaconv_text_t::getCorbatext(response.httpprefix,corbaResponse.httpprefix);
+    corbaconv_text_t::getCorbatext(response.receptionist,corbaResponse.receptionist);
+
+    /* text_tmap::iterator f_here = response.format.begin();
+    text_tmap::iterator f_end = response.format.end();
+    while (f_here!=f_end)
+    {
+      cout << "**** format: " << f_here->first << " = " << f_here->second << endl;
+      f_here++;
+    } 
+    */ // ****
+
+    logout.close();
+    corbaError = (corbaComError) error;
+  }
+
+  void getFilterOptions(const struct corbatext_t &corbaCollect,
+			const struct corbatext_t &corbaFilterName,
+			struct corbaFilterOptionsResponse &corbaResponse,
+			enum corbaComError &corbaError)
+  {   
+    text_t collection;
+    InfoFilterOptionsRequest_t request;
+    InfoFilterOptionsResponse_t response;
+    comerror_t error = noError;
+    unsigned int i;
+    ofstream logout;
+
+    this->openLogfile("/etc/corbaout.txt", logout);
+
+    corbaconv_text_t::setCorbatext(collection,corbaCollect);
+    corbaconv_text_t::setCorbatext(request.filterName,corbaFilterName);
+    protocol->get_filteroptions(collection, request, response, error, logout);
+
+    // decode filters back into corba format
+    FilterOption_tmap::iterator here = response.filterOptions.begin();
+    FilterOption_tmap::iterator end = response.filterOptions.end();
+    i = 0;
+    while (here != end)
+      {
+	// set array for name/options to be one bigger
+	corbaResponse.names.length(i+1);
+	corbaResponse.options.length(i+1);
+
+	// get left-hand side of map
+	corbaconv_text_t::getCorbatext((*here).first,corbaResponse.names[i]);
+	
+	// get right-hand side of map
+	corbaconv_text_t::getCorbatext((*here).second.name,corbaResponse.options[i].name);
+	corbaResponse.options[i].type = 
+	  (::gsdlInterface::corbaFilterType)(*here).second.type;
+	corbaResponse.options[i].repeatable = 
+	  (::gsdlInterface::corbaFilterRepeatable)(*here).second.repeatable;
+	corbaconv_text_t::getCorbatext((*here).second.defaultValue,corbaResponse.options[i].defaultValue);
+	corbatext_arrayToCorbaArray((*here).second.validValues, &corbaResponse.options[i].validValues);
+
+	// take next iterators
+	i++;
+	here ++;
+      }
+
+    logout.close();
+    corbaError = (corbaComError) error;
+  }
+
+  void getFilterInfo(const struct corbatext_t &corbaCollect, 
+		     corbatext_tarray &filterNames, 
+		     enum corbaComError &corbaError)
+  { text_tarray ta;
+    comerror_t error = noError;
+    text_t collection;    
+    InfoFiltersResponse_t response;
+    ofstream logout;
+
+    this->openLogfile("/etc/corbaout.txt", logout);
+
+    corbaconv_text_t::setCorbatext(collection,corbaCollect);
+    cout << collection.getcstr() << endl;
+			    
+    protocol->get_filterinfo(collection, response, error, logout);
+    corbatext_setToCorbaArray(response.filterNames, &filterNames);
+
+    corbaError = (corbaComError) error;
+    logout.close();
+  }
+  
+  void getDocument(const struct corbatext_t &corbaCollection, struct corbaDocRequest &corbaRequest, 
+		   struct corbaDocResponse &corbaResponse,  enum corbaComError &corbaError)
+  { DocumentRequest_t request;
+    DocumentResponse_t response;
+    comerror_t         error = noError;
+    text_t             collection;
+    ofstream logout;
+
+    this->openLogfile("/etc/corbaout.txt", logout);
+
+    // set up request
+    corbaconv_text_t::setCorbatext(collection,corbaCollection);
+    corbaconv_text_t::setCorbatext(request.OID,corbaRequest.OID);
+    corbaconv_text_t::setCorbatext(request.docType,corbaRequest.docType);
+    corbaconv_text_t::setCorbatext(request.docFormat,corbaRequest.docFormat);
+
+    // do actual get document
+    protocol->get_document(collection, request, response, error, logout);
+    corbaconv_text_t::getCorbatext(response.doc,corbaResponse.doc);
+
+    // decode response
+    corbaError = (corbaComError) error;
+
+    logout.close();
+  }
+
+  void collectionList(corbatext_tarray &corbalist, corbaComError &error)
+  {
+    /* stringSeq *reply;
+    unsigned int i;
+    char *istring; */
+
+    text_tarray collist;
+    comerror_t  err;
+    ofstream logout;
+
+    cout << "Received collection list request" << endl;
+
+    this->openLogfile("/etc/corbaout.txt", logout);
+
+    protocol->get_collection_list(collist, err, logout);
+
+    /*    reply = new stringSeq(collections.size());
+    
+    (*reply).length(collections.size());
+    for (i = 0; i < collections.size(); i ++)
+      {
+	istring = collections[i].getcstr();
+	(*reply)[i] = CORBA::string_dup(istring);
+	delete istring;
+      }
+    
+    return reply;
+    */
+
+    corbatext_arrayToCorbaArray(collist, &corbalist);
+    cout << "Replying " << collist.size() << ": " << endl;
+
+    for (int unsigned i = 0; i < collist.size(); i ++)
+      {
+	cout << collist[i];
+	if (i<collist.size()-1) cout << ", ";
+      }
+    cout << endl;
+
+    logout.close();
+    // CORBA::string_dup(_listString);
+  }
+};
+
+int main (int argc, char *argv[])
+{
+  nullproto protocol;
+  collectset *cservers;
+  text_t     gsdlhome;
+
+  cservers = new collectset(gsdlhome);
+  protocol.set_collectset(cservers);
+
+  cout << "Started Corba ..." << endl;
+
+  // ORB initialization
+  CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "mico-local-orb" );
+  CORBA::BOA_var boa = orb->BOA_init( argc, argv, "mico-local-boa" );
+
+  cout << "Initialised ORB and BOA" << endl;
+
+  corbaServer* server = new corbaServer(&protocol, gsdlhome);
+
+  cout << "Initialised server" << endl;
+
+  CORBA::String_var ref = orb->object_to_string( server );
+
+  cout << "Mapped Corba object to string" << endl;
+
+  // write id to "naming service"
+  ofstream out ("/tmp/localcorba.objid");
+	if (out.is_open()) {
+		out << ref << endl;
+		if (out.fail() || out.bad()) {
+			cout << "Failed " << endl;
+		}
+		out.close ();
+	}
+	else {
+		cout << "Unable to write string to file /tmp/localcorba.objid" << endl;
+		cout << "Please check the file permissions/ownership" << endl;
+		return 0;
+	}
+  cout << "Corba string is " << ref << endl;
+
+  // indicate readiness and run
+  boa->impl_is_ready( CORBA::ImplementationDef::_nil() );
+  orb->run ();
+  CORBA::release( server );
+  return 0;
+}
+
+
Index: /gsdl/trunk/runtime-src/src/corba/corbaclient.mpp
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbaclient.mpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbaclient.mpp	(revision 16571)
@@ -0,0 +1,160 @@
+/**********************************************************************
+ *
+ * corbaclient.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+#include "receptionist.h"
+#include "cgiwrapper.h"
+#include "corbaproto.h"
+#include "collectserver.h"
+#include "filter.h"
+#include "browsefilter.h"
+#include "queryfilter.h"
+#include "mgsearch.h"
+#include "fileutil.h"
+#include <assert.h>
+
+#include "action.h"
+#include "statusaction.h"
+#include "pageaction.h"
+#include "pingaction.h"
+#include "queryaction.h"
+#include "documentaction.h"
+#include "authenaction.h"
+#include "usersaction.h"
+#include "authenaction.h"
+#include "extlinkaction.h"
+#include "tipaction.h"
+#include "collectoraction.h"
+
+#include "browserclass.h"
+#include "vlistbrowserclass.h"
+#include "hlistbrowserclass.h"
+#include "datelistbrowserclass.h"
+#include "invbrowserclass.h"
+#include "pagedbrowserclass.h"
+#include "htmlbrowserclass.h"
+
+// #include "gsdlhome.h"
+#include "gsdlsitecfg.h"
+
+int main (int argc, char *argv[]) {
+  receptionist recpt;
+  corbaproto*  cproto_array[argc];
+  text_t       gsdlhome;
+  text_t       httpdomain;
+  text_t       httpprefix;
+  
+  cproto_array[0] = NULL; // unused
+
+  if (argc == 1)
+  { cout << "Content-type: text/html" << endl << endl;
+    cout << "Usage: " << argv[0] << "site1.objid [site2.objid ....]" << endl;
+    return 0;
+  }
+
+  // Strictly speaking httpdomain and httpprefix are not needed.
+  // Need to modifiy site_cfg_read to eliminate this dependency. // ****
+  site_cfg_read(gsdlhome, httpdomain, httpprefix);
+
+  for (int i=1; i<argc; i ++)
+    {
+      // add the protocol to the receptionist
+      cproto_array[i] = new corbaproto(argv[i]);
+      recpt.add_protocol(cproto_array[i]);
+    }
+
+//  cout << "GRB 2" << endl;
+
+  // the list of actions. Note: these actions will become invalid
+  // at the end of this function.
+  tipaction atipaction;
+  recpt.add_action(&atipaction);
+
+  statusaction astatusaction;
+  astatusaction.set_receptionist (&recpt);
+  recpt.add_action (&astatusaction);
+
+  pageaction apageaction;
+  apageaction.set_receptionist (&recpt);
+  recpt.add_action (&apageaction);
+
+  pingaction apingaction;
+  recpt.add_action (&apingaction);
+
+  queryaction aqueryaction;
+  aqueryaction.set_receptionist (&recpt);
+  recpt.add_action (&aqueryaction);
+
+  documentaction adocumentaction;
+  adocumentaction.set_receptionist (&recpt);
+  recpt.add_action (&adocumentaction);
+
+  usersaction ausersaction;
+  recpt.add_action (&ausersaction);
+
+  extlinkaction anextlinkaction;
+  recpt.add_action (&anextlinkaction);
+
+  authenaction aauthenaction;
+  aauthenaction.set_receptionist(&recpt);
+  recpt.add_action (&aauthenaction);
+
+  collectoraction acollectoraction;
+  acollectoraction.set_receptionist (&recpt);
+  recpt.add_action(&acollectoraction);
+
+//  cout << "GRB 3" << endl;
+
+  // list of browsers
+  vlistbrowserclass avlistbrowserclass;
+  recpt.add_browser (&avlistbrowserclass);
+  recpt.setdefaultbrowser ("VList");
+
+  hlistbrowserclass ahlistbrowserclass;
+  recpt.add_browser (&ahlistbrowserclass);
+
+  datelistbrowserclass adatelistbrowserclass;
+  recpt.add_browser (&adatelistbrowserclass);
+
+  invbrowserclass ainvbrowserclass;
+  recpt.add_browser (&ainvbrowserclass);
+
+  pagedbrowserclass apagedbrowserclass;
+  recpt.add_browser (&apagedbrowserclass);
+
+  htmlbrowserclass ahtmlbrowserclass;
+  recpt.add_browser (&ahtmlbrowserclass);
+
+  cgiwrapper (recpt, "");
+
+  for (int i=1; i< argc; i++)
+    {
+      delete cproto_array[i];
+    }
+
+  return 0;
+}
+
Index: /gsdl/trunk/runtime-src/src/corba/corbaconv_text_t.h
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbaconv_text_t.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbaconv_text_t.h	(revision 16571)
@@ -0,0 +1,68 @@
+/**********************************************************************
+ *
+ * corbaconv_text_t.mpp -- conversion support text_t <-> corba_text_t
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+
+#ifndef CORBACONV_TEXT_T_H
+#define CORBACONV_TEXT_T_H
+
+#include "text_t.h"
+
+// Inherit from text_t
+// Provide support to convert from corba_text_t to text_t and vice versa
+
+class corbaconv_text_t : public text_t {
+  
+public:
+  // constructors
+  corbaconv_text_t (corbatext_t t);
+
+  void setCorbatext(corbatext_t ct);
+  void getCorbatext(corbatext_t &ct) const;
+  void fillUsString(usString *us) const;
+
+  static void setCorbatext(text_t& t, corbatext_t ct);
+  static void getCorbatext(const text_t& t, corbatext_t &ct);
+  static void fillUsString(const text_t& t, usString *us);
+};
+
+
+inline void corbaconv_text_t::setCorbatext(corbatext_t ct) 
+{ 
+  setCorbatext(*this,ct); 
+}
+
+inline void corbaconv_text_t::getCorbatext(corbatext_t& ct) const
+{ 
+  getCorbatext(*this,ct); 
+}
+
+inline void corbaconv_text_t::fillUsString(usString *us) const
+{
+  fillUsString(*this,us);
+}
+
+#endif
Index: /gsdl/trunk/runtime-src/src/corba/corbaconv_text_t.mpp
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbaconv_text_t.mpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbaconv_text_t.mpp	(revision 16571)
@@ -0,0 +1,109 @@
+/**********************************************************************
+ *
+ * corbaconv_text_t.mpp -- conversion support text_t <-> corba_text_t
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+#if defined(GSDL_USE_STL_H) || defined(__APPLE__)
+#include <vector.h>
+#else
+#include <vector>
+#endif
+
+// protocol header
+#include "corbaiface.h"
+using namespace gsdlInterface;
+
+#include "corbatext_t.h"
+
+#include "corbaconv_text_t.h"
+
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\algorithm>
+#elif defined(GSDL_USE_STL_H)
+#  if defined(GSDL_USE_ALGO_H)
+#    include <algo.h>
+#  else
+#    include <algorithm.h>
+#  endif
+#else
+#  include <algorithm>
+#endif
+
+#ifdef HAVE_CONFIG_H
+# ifdef __WIN32__
+#  include "win32cfg.h"
+# else
+#  include "mico/config.h"
+# endif
+#endif
+
+
+// #include "unitool.h" // ****
+
+////////////////////////////////////
+// corbaconv_text_t methods
+////////////////////////////////////
+
+corbaconv_text_t::corbaconv_text_t (corbatext_t t)
+{ 
+  setCorbatext(t);  
+}
+
+void corbaconv_text_t::getCorbatext(const text_t& t, corbatext_t &ct)
+{
+  ct.encoding = 0;
+  fillUsString(t,&ct.text);
+}
+
+void corbaconv_text_t::setCorbatext(text_t& t, corbatext_t ct)
+{
+  t.setencoding(0);
+  t.clear();
+  corbatext_usvector(ct, t.text_as_usvector());
+}
+
+void corbaconv_text_t::fillUsString(const text_t& t, usString *us)
+{
+  unsigned int i;
+  usvector::const_iterator here = t.text_as_usvector().begin();
+  usvector::const_iterator end = t.text_as_usvector().end();
+
+
+  if (end == here)
+    { 	
+      return;
+    }
+  (*us).length(end - here);
+  i = 0;
+
+  while (here != end)
+    {
+      (*us)[i] = *here;
+      i ++;
+      here ++;
+    }
+  
+}
Index: /gsdl/trunk/runtime-src/src/corba/corbaiface.h
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbaiface.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbaiface.h	(revision 16571)
@@ -0,0 +1,614 @@
+/*
+ *  MICO --- a free CORBA implementation
+ *  Copyright (C) 1997-98 Kay Roemer & Arno Puder
+ *
+ *  This file was automatically generated. DO NOT EDIT!
+ */
+
+#if !defined(__CORBAIFACE_H__) || defined(MICO_NO_TOPLEVEL_MODULES)
+#define __CORBAIFACE_H__
+
+#ifndef MICO_NO_TOPLEVEL_MODULES
+#include <CORBA.h>
+#include <mico/throw.h>
+#endif
+
+#ifndef MICO_NO_TOPLEVEL_MODULES
+MICO_NAMESPACE_DECL gsdlInterface {
+#endif
+
+#if !defined(MICO_NO_TOPLEVEL_MODULES) || defined(MICO_MODULE_gsdlInterface)
+
+
+typedef SequenceTmpl<CORBA::UShort,MICO_TID_DEF> usString;
+#ifdef _WINDOWS
+static usString _dummy_usString;
+#endif
+typedef TSeqVar<SequenceTmpl<CORBA::UShort,MICO_TID_DEF> > usString_var;
+typedef TSeqOut<SequenceTmpl<CORBA::UShort,MICO_TID_DEF> > usString_out;
+
+typedef StringSequenceTmpl<CORBA::String_var> stringSeq;
+#ifdef _WINDOWS
+static stringSeq _dummy_stringSeq;
+#endif
+typedef TSeqVar<StringSequenceTmpl<CORBA::String_var> > stringSeq_var;
+typedef TSeqOut<StringSequenceTmpl<CORBA::String_var> > stringSeq_out;
+
+struct corbatext_t;
+typedef TVarVar<corbatext_t> corbatext_t_var;
+typedef TVarOut<corbatext_t> corbatext_t_out;
+
+struct corbatext_t {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbatext_t_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbatext_t();
+  ~corbatext_t();
+  corbatext_t( const corbatext_t& s );
+  corbatext_t& operator=( const corbatext_t& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  usString text;
+  CORBA::UShort encoding;
+  CORBA::ULong length;
+};
+
+typedef SequenceTmpl<corbatext_t,MICO_TID_DEF> corbatext_tarray;
+#ifdef _WINDOWS
+static corbatext_tarray _dummy_corbatext_tarray;
+#endif
+typedef TSeqVar<SequenceTmpl<corbatext_t,MICO_TID_DEF> > corbatext_tarray_var;
+typedef TSeqOut<SequenceTmpl<corbatext_t,MICO_TID_DEF> > corbatext_tarray_out;
+
+typedef corbatext_tarray corbatext_tset;
+#ifdef _WINDOWS
+static corbatext_tset _dummy_corbatext_tset;
+#endif
+typedef TSeqVar<corbatext_tarray > corbatext_tset_var;
+typedef TSeqOut<corbatext_tarray > corbatext_tset_out;
+
+struct corbatext_tmap;
+typedef TVarVar<corbatext_tmap> corbatext_tmap_var;
+typedef TVarOut<corbatext_tmap> corbatext_tmap_out;
+
+struct corbatext_tmap {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbatext_tmap_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbatext_tmap();
+  ~corbatext_tmap();
+  corbatext_tmap( const corbatext_tmap& s );
+  corbatext_tmap& operator=( const corbatext_tmap& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_tarray names;
+  corbatext_tarray values;
+};
+
+enum corbaComError {
+  corbaNoError = 0,
+  corbaAuthenticationFailure,
+  corbaProtocolError,
+  corbaConfigurationError,
+  corbaSystemProblem
+};
+
+typedef corbaComError& corbaComError_out;
+
+struct corbaShortColInfo;
+typedef TVarVar<corbaShortColInfo> corbaShortColInfo_var;
+typedef TVarOut<corbaShortColInfo> corbaShortColInfo_out;
+
+struct corbaShortColInfo {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaShortColInfo_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaShortColInfo();
+  ~corbaShortColInfo();
+  corbaShortColInfo( const corbaShortColInfo& s );
+  corbaShortColInfo& operator=( const corbaShortColInfo& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_t name;
+  corbatext_t host;
+  CORBA::Long response;
+};
+
+struct corbaColInfoResponse;
+typedef TVarVar<corbaColInfoResponse> corbaColInfoResponse_var;
+typedef TVarOut<corbaColInfoResponse> corbaColInfoResponse_out;
+
+struct corbaColInfoResponse {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaColInfoResponse_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaColInfoResponse();
+  ~corbaColInfoResponse();
+  corbaColInfoResponse( const corbaColInfoResponse& s );
+  corbaColInfoResponse& operator=( const corbaColInfoResponse& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbaShortColInfo shoftInfo;
+  CORBA::Boolean useBook;
+  CORBA::Boolean isPublic;
+  CORBA::Boolean isBeta;
+  CORBA::ULong buildDate;
+  corbatext_tarray ccsCols;
+  corbatext_tarray languages;
+  CORBA::ULong numDocs;
+  CORBA::ULong numWords;
+  CORBA::ULong numBytes;
+  corbatext_tmap collectionMeta;
+  corbatext_tmap format;
+  corbatext_tmap building;
+  corbatext_t httpdomain;
+  corbatext_t httpprefix;
+  corbatext_t receptionist;
+};
+
+struct corbaDocRequest;
+typedef TVarVar<corbaDocRequest> corbaDocRequest_var;
+typedef TVarOut<corbaDocRequest> corbaDocRequest_out;
+
+struct corbaDocRequest {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaDocRequest_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaDocRequest();
+  ~corbaDocRequest();
+  corbaDocRequest( const corbaDocRequest& s );
+  corbaDocRequest& operator=( const corbaDocRequest& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_t OID;
+  corbatext_t docType;
+  corbatext_t docFormat;
+};
+
+struct corbaDocResponse;
+typedef TVarVar<corbaDocResponse> corbaDocResponse_var;
+typedef TVarOut<corbaDocResponse> corbaDocResponse_out;
+
+struct corbaDocResponse {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaDocResponse_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaDocResponse();
+  ~corbaDocResponse();
+  corbaDocResponse( const corbaDocResponse& s );
+  corbaDocResponse& operator=( const corbaDocResponse& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_t doc;
+};
+
+enum corbaFilterType {
+  booleanType = 0,
+  integerType,
+  enumeratedType,
+  stringType
+};
+
+typedef corbaFilterType& corbaFilterType_out;
+
+enum corbaFilterRepeatable {
+  onePerQuery = 0,
+  onePerTerm,
+  nPerTerm
+};
+
+typedef corbaFilterRepeatable& corbaFilterRepeatable_out;
+
+struct corbaFilterOption;
+typedef TVarVar<corbaFilterOption> corbaFilterOption_var;
+typedef TVarOut<corbaFilterOption> corbaFilterOption_out;
+
+struct corbaFilterOption {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaFilterOption_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaFilterOption();
+  ~corbaFilterOption();
+  corbaFilterOption( const corbaFilterOption& s );
+  corbaFilterOption& operator=( const corbaFilterOption& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_t name;
+  corbaFilterType type;
+  corbaFilterRepeatable repeatable;
+  corbatext_t defaultValue;
+  corbatext_tarray validValues;
+};
+
+typedef SequenceTmpl<corbaFilterOption,MICO_TID_DEF> corbaFilterOptionList;
+#ifdef _WINDOWS
+static corbaFilterOptionList _dummy_corbaFilterOptionList;
+#endif
+typedef TSeqVar<SequenceTmpl<corbaFilterOption,MICO_TID_DEF> > corbaFilterOptionList_var;
+typedef TSeqOut<SequenceTmpl<corbaFilterOption,MICO_TID_DEF> > corbaFilterOptionList_out;
+
+struct corbaFilterOptionsResponse;
+typedef TVarVar<corbaFilterOptionsResponse> corbaFilterOptionsResponse_var;
+typedef TVarOut<corbaFilterOptionsResponse> corbaFilterOptionsResponse_out;
+
+struct corbaFilterOptionsResponse {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaFilterOptionsResponse_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaFilterOptionsResponse();
+  ~corbaFilterOptionsResponse();
+  corbaFilterOptionsResponse( const corbaFilterOptionsResponse& s );
+  corbaFilterOptionsResponse& operator=( const corbaFilterOptionsResponse& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbaFilterOptionList options;
+  corbatext_tarray names;
+};
+
+struct corbaOptionValue;
+typedef TVarVar<corbaOptionValue> corbaOptionValue_var;
+typedef TVarOut<corbaOptionValue> corbaOptionValue_out;
+
+struct corbaOptionValue {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaOptionValue_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaOptionValue();
+  ~corbaOptionValue();
+  corbaOptionValue( const corbaOptionValue& s );
+  corbaOptionValue& operator=( const corbaOptionValue& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_t name;
+  corbatext_t value;
+};
+
+typedef SequenceTmpl<corbaOptionValue,MICO_TID_DEF> corbaOptionValue_array;
+#ifdef _WINDOWS
+static corbaOptionValue_array _dummy_corbaOptionValue_array;
+#endif
+typedef TSeqVar<SequenceTmpl<corbaOptionValue,MICO_TID_DEF> > corbaOptionValue_array_var;
+typedef TSeqOut<SequenceTmpl<corbaOptionValue,MICO_TID_DEF> > corbaOptionValue_array_out;
+
+struct corbaFilterRequest;
+typedef TVarVar<corbaFilterRequest> corbaFilterRequest_var;
+typedef TVarOut<corbaFilterRequest> corbaFilterRequest_out;
+
+struct corbaFilterRequest {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaFilterRequest_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaFilterRequest();
+  ~corbaFilterRequest();
+  corbaFilterRequest( const corbaFilterRequest& s );
+  corbaFilterRequest& operator=( const corbaFilterRequest& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_t filter;
+  corbaOptionValue_array filterOptions;
+  corbatext_tarray docSet;
+  CORBA::Long filterResultOptions;
+  corbatext_t requestParams;
+  corbatext_t refParams;
+  corbatext_tset fields;
+  CORBA::Boolean getParents;
+};
+
+struct corbaTermInfo;
+typedef TVarVar<corbaTermInfo> corbaTermInfo_var;
+typedef TVarOut<corbaTermInfo> corbaTermInfo_out;
+
+struct corbaTermInfo {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaTermInfo_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaTermInfo();
+  ~corbaTermInfo();
+  corbaTermInfo( const corbaTermInfo& s );
+  corbaTermInfo& operator=( const corbaTermInfo& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_t term;
+  CORBA::Long frequency;
+  corbatext_tarray matchTerms;
+};
+
+typedef SequenceTmpl<corbaTermInfo,MICO_TID_DEF> corbaTermInfo_array;
+#ifdef _WINDOWS
+static corbaTermInfo_array _dummy_corbaTermInfo_array;
+#endif
+typedef TSeqVar<SequenceTmpl<corbaTermInfo,MICO_TID_DEF> > corbaTermInfo_array_var;
+typedef TSeqOut<SequenceTmpl<corbaTermInfo,MICO_TID_DEF> > corbaTermInfo_array_out;
+
+struct corbaMetadataInfo;
+typedef TVarVar<corbaMetadataInfo> corbaMetadataInfo_var;
+typedef TVarOut<corbaMetadataInfo> corbaMetadataInfo_out;
+
+struct corbaMetadataInfo {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaMetadataInfo_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaMetadataInfo();
+  ~corbaMetadataInfo();
+  corbaMetadataInfo( const corbaMetadataInfo& s );
+  corbaMetadataInfo& operator=( const corbaMetadataInfo& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_t params;
+  CORBA::Boolean isRef;
+  corbatext_tarray values;
+  CORBA::Long id;
+  CORBA::Long parentid;
+};
+
+typedef SequenceTmpl<corbaMetadataInfo,MICO_TID_DEF> corbaMetadataInfo_array;
+#ifdef _WINDOWS
+static corbaMetadataInfo_array _dummy_corbaMetadataInfo_array;
+#endif
+typedef TSeqVar<SequenceTmpl<corbaMetadataInfo,MICO_TID_DEF> > corbaMetadataInfo_array_var;
+typedef TSeqOut<SequenceTmpl<corbaMetadataInfo,MICO_TID_DEF> > corbaMetadataInfo_array_out;
+
+struct corbaMetadataInfo_map;
+typedef TVarVar<corbaMetadataInfo_map> corbaMetadataInfo_map_var;
+typedef TVarOut<corbaMetadataInfo_map> corbaMetadataInfo_map_out;
+
+struct corbaMetadataInfo_map {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaMetadataInfo_map_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaMetadataInfo_map();
+  ~corbaMetadataInfo_map();
+  corbaMetadataInfo_map( const corbaMetadataInfo_map& s );
+  corbaMetadataInfo_map& operator=( const corbaMetadataInfo_map& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_tarray names;
+  corbaMetadataInfo_array values;
+};
+
+typedef SequenceTmpl<CORBA::Long,MICO_TID_DEF> corbaDocFreq_array;
+#ifdef _WINDOWS
+static corbaDocFreq_array _dummy_corbaDocFreq_array;
+#endif
+typedef TSeqVar<SequenceTmpl<CORBA::Long,MICO_TID_DEF> > corbaDocFreq_array_var;
+typedef TSeqOut<SequenceTmpl<CORBA::Long,MICO_TID_DEF> > corbaDocFreq_array_out;
+
+struct corbaResultDocInfo;
+typedef TVarVar<corbaResultDocInfo> corbaResultDocInfo_var;
+typedef TVarOut<corbaResultDocInfo> corbaResultDocInfo_out;
+
+struct corbaResultDocInfo {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaResultDocInfo_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaResultDocInfo();
+  ~corbaResultDocInfo();
+  corbaResultDocInfo( const corbaResultDocInfo& s );
+  corbaResultDocInfo& operator=( const corbaResultDocInfo& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  corbatext_t OID;
+  CORBA::Long resultNum;
+  CORBA::Long ranking;
+  CORBA::Long termsMatched;
+  CORBA::Long phraseMatched;
+  corbaDocFreq_array docFreq;
+  corbaMetadataInfo_map metadata;
+  corbatext_t classifierMetadataType;
+  CORBA::Long classifierMetadataOffset;
+  corbaMetadataInfo_array metaparents;
+};
+
+typedef SequenceTmpl<corbaResultDocInfo,MICO_TID_DEF> corbaResultDocInfo_array;
+#ifdef _WINDOWS
+static corbaResultDocInfo_array _dummy_corbaResultDocInfo_array;
+#endif
+typedef TSeqVar<SequenceTmpl<corbaResultDocInfo,MICO_TID_DEF> > corbaResultDocInfo_array_var;
+typedef TSeqOut<SequenceTmpl<corbaResultDocInfo,MICO_TID_DEF> > corbaResultDocInfo_array_out;
+
+enum corbaIsApprox {
+  resultExact = 0,
+  resultApprox,
+  resultMany
+};
+
+typedef corbaIsApprox& corbaIsApprox_out;
+
+struct corbaFilterResponse;
+typedef TVarVar<corbaFilterResponse> corbaFilterResponse_var;
+typedef TVarOut<corbaFilterResponse> corbaFilterResponse_out;
+
+struct corbaFilterResponse {
+  #ifdef HAVE_TYPEDEF_OVERLOAD
+  typedef corbaFilterResponse_var _var_type;
+  #endif
+  #ifdef HAVE_EXPLICIT_STRUCT_OPS
+  corbaFilterResponse();
+  ~corbaFilterResponse();
+  corbaFilterResponse( const corbaFilterResponse& s );
+  corbaFilterResponse& operator=( const corbaFilterResponse& s );
+  #endif //HAVE_EXPLICIT_STRUCT_OPS
+
+  CORBA::Long numDocs;
+  corbaIsApprox isApprox;
+  corbaTermInfo_array termInfo;
+  corbaResultDocInfo_array docInfo;
+};
+
+class corbaiface;
+typedef corbaiface *corbaiface_ptr;
+typedef corbaiface_ptr corbaifaceRef;
+typedef ObjVar<corbaiface> corbaiface_var;
+typedef ObjOut<corbaiface> corbaiface_out;
+
+
+// Common definitions for interface corbaiface
+class corbaiface : 
+  virtual public CORBA::Object
+{
+  public:
+    virtual ~corbaiface();
+
+    #ifdef HAVE_TYPEDEF_OVERLOAD
+    typedef corbaiface_ptr _ptr_type;
+    typedef corbaiface_var _var_type;
+    #endif
+
+    static corbaiface_ptr _narrow( CORBA::Object_ptr obj );
+    static corbaiface_ptr _narrow( CORBA::AbstractBase_ptr obj );
+    static corbaiface_ptr _duplicate( corbaiface_ptr _obj )
+    {
+      CORBA::Object::_duplicate (_obj);
+      return _obj;
+    }
+
+    static corbaiface_ptr _nil()
+    {
+      return 0;
+    }
+
+    virtual void *_narrow_helper( const char *repoid );
+    static vector<CORBA::Narrow_proto> *_narrow_helpers;
+    static bool _narrow_helper2( CORBA::Object_ptr obj );
+
+    virtual CORBA::Boolean initialise( corbaComError& error ) = 0;
+    virtual void configure( const corbatext_t& key, const corbatext_tarray& cfgline, corbaComError& error ) = 0;
+    virtual void collectionList( corbatext_tarray& collist, corbaComError& error ) = 0;
+    virtual void hasCollection( const corbatext_t& corbaCollection, CORBA::Boolean& has, corbaComError& error ) = 0;
+    virtual void ping( const corbatext_t& collection, CORBA::Boolean& wasSuccess, corbaComError& error ) = 0;
+    virtual void getDocument( const corbatext_t& collection, corbaDocRequest& request, corbaDocResponse& response, corbaComError& error ) = 0;
+    virtual void getCollectInfo( const corbatext_t& collection, corbaColInfoResponse& response, corbaComError& error ) = 0;
+    virtual void getFilterInfo( const corbatext_t& collection, corbatext_tarray& filterNames, corbaComError& error ) = 0;
+    virtual void getFilterOptions( const corbatext_t& collection, const corbatext_t& option, corbaFilterOptionsResponse& response, corbaComError& error ) = 0;
+    virtual void filter( const corbatext_t& collection, const corbaFilterRequest& request, corbaFilterResponse& response, corbaComError& error ) = 0;
+
+  protected:
+    corbaiface() {};
+  private:
+    corbaiface( const corbaiface& );
+    void operator=( const corbaiface& );
+};
+
+// Stub for interface corbaiface
+class corbaiface_stub:
+  virtual public corbaiface
+{
+  public:
+    virtual ~corbaiface_stub();
+    CORBA::Boolean initialise( corbaComError& error );
+    void configure( const corbatext_t& key, const corbatext_tarray& cfgline, corbaComError& error );
+    void collectionList( corbatext_tarray& collist, corbaComError& error );
+    void hasCollection( const corbatext_t& corbaCollection, CORBA::Boolean& has, corbaComError& error );
+    void ping( const corbatext_t& collection, CORBA::Boolean& wasSuccess, corbaComError& error );
+    void getDocument( const corbatext_t& collection, corbaDocRequest& request, corbaDocResponse& response, corbaComError& error );
+    void getCollectInfo( const corbatext_t& collection, corbaColInfoResponse& response, corbaComError& error );
+    void getFilterInfo( const corbatext_t& collection, corbatext_tarray& filterNames, corbaComError& error );
+    void getFilterOptions( const corbatext_t& collection, const corbatext_t& option, corbaFilterOptionsResponse& response, corbaComError& error );
+    void filter( const corbatext_t& collection, const corbaFilterRequest& request, corbaFilterResponse& response, corbaComError& error );
+
+  private:
+    void operator=( const corbaiface_stub& );
+};
+
+class corbaiface_skel :
+  virtual public StaticMethodDispatcher,
+  virtual public corbaiface
+{
+  public:
+    corbaiface_skel( const CORBA::BOA::ReferenceData & = CORBA::BOA::ReferenceData() );
+    virtual ~corbaiface_skel();
+    corbaiface_skel( CORBA::Object_ptr obj );
+    virtual bool dispatch( CORBA::StaticServerRequest_ptr _req, CORBA::Environment &_env );
+    corbaiface_ptr _this();
+
+};
+
+#endif // !defined(MICO_NO_TOPLEVEL_MODULES) || defined(MICO_MODULE_gsdlInterface)
+
+#ifndef MICO_NO_TOPLEVEL_MODULES
+
+} MICO_NAMESPACE_END_DECL
+#endif
+
+
+
+#ifndef MICO_CONF_NO_POA
+
+#endif // MICO_CONF_NO_POA
+
+#if !defined(MICO_NO_TOPLEVEL_MODULES) || defined(MICO_MODULE__GLOBAL)
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbatext_t;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbatext_tmap;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaComError;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaShortColInfo;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaColInfoResponse;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaDocRequest;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaDocResponse;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterType;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterRepeatable;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterOption;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterOptionsResponse;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaOptionValue;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterRequest;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaTermInfo;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaMetadataInfo;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaMetadataInfo_map;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaResultDocInfo;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaIsApprox;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterResponse;
+
+extern CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaiface;
+
+extern CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbatext_t;
+
+extern CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbaFilterOption;
+
+extern CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbaOptionValue;
+
+extern CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbaTermInfo;
+
+extern CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbaMetadataInfo;
+
+extern CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbaResultDocInfo;
+
+#endif // !defined(MICO_NO_TOPLEVEL_MODULES) || defined(MICO_MODULE__GLOBAL)
+
+
+#if !defined(MICO_NO_TOPLEVEL_MODULES) && !defined(MICO_IN_GENERATED_CODE)
+#include <mico/template_impl.h>
+#endif
+
+#endif
Index: /gsdl/trunk/runtime-src/src/corba/corbaiface.idl
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbaiface.idl	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbaiface.idl	(revision 16571)
@@ -0,0 +1,231 @@
+// basic elements for text
+
+module gsdlInterface {
+
+typedef sequence<unsigned short> usString;
+
+typedef sequence<string> stringSeq;
+
+struct corbatext_t
+{ 
+  usString text;
+  unsigned short encoding;
+  unsigned long  length;
+};
+
+typedef sequence<corbatext_t> corbatext_tarray;
+
+typedef corbatext_tarray corbatext_tset;
+
+struct corbatext_tmap
+{
+  corbatext_tarray names;
+  corbatext_tarray values;
+};
+
+// standard error values
+
+enum corbaComError
+{ corbaNoError, 
+  corbaAuthenticationFailure, 
+  corbaProtocolError, 
+  corbaConfigurationError, 
+  corbaSystemProblem
+};
+
+//
+// getColInfo response
+//
+
+struct corbaShortColInfo
+{
+  corbatext_t name;
+  corbatext_t host;
+  long        response;
+};
+
+struct corbaColInfoResponse
+{
+  boolean       useBook;
+  corbaShortColInfo shoftInfo;
+  boolean           isPublic;
+  boolean           isBeta;
+  unsigned long     buildDate;
+  corbatext_tarray  ccsCols;        // Added 05/04/2000
+  corbatext_tarray  languages;
+  unsigned long     numDocs;
+  unsigned long     numWords;
+  unsigned long     numBytes;
+  corbatext_tmap    collectionMeta;
+  corbatext_tmap    format;
+  corbatext_tmap    building;
+  corbatext_t       httpdomain ;    // Added 27/07/2000
+  corbatext_t       httpprefix;     // Added 27/07/2000
+  corbatext_t       receptionist;
+};
+
+//
+// getDocument request
+//
+
+struct corbaDocRequest
+{ 
+  corbatext_t OID;
+  corbatext_t docType;
+  corbatext_t docFormat;
+};
+
+//
+// getDocument response
+//
+
+struct corbaDocResponse
+{ 
+  corbatext_t doc;
+};
+
+enum corbaFilterType
+{
+  booleanType,
+  integerType,
+  enumeratedType,
+  stringType
+};
+
+enum corbaFilterRepeatable
+{
+  onePerQuery,
+  onePerTerm,
+  nPerTerm
+};
+
+struct corbaFilterOption
+{
+  corbatext_t           name;
+  corbaFilterType       type;
+  corbaFilterRepeatable repeatable;
+  corbatext_t           defaultValue;
+  corbatext_tarray      validValues;
+};
+
+typedef sequence<corbaFilterOption> corbaFilterOptionList;
+
+struct corbaFilterOptionsResponse
+{
+  corbaFilterOptionList options;
+  corbatext_tarray      names;
+};
+
+//
+// structures for filter call
+//
+
+struct corbaOptionValue
+{
+  corbatext_t name;
+  corbatext_t value;
+};
+
+typedef sequence<corbaOptionValue> corbaOptionValue_array;
+
+struct corbaFilterRequest
+{ 
+  corbatext_t            filter;
+  corbaOptionValue_array filterOptions;
+  corbatext_tarray       docSet;
+  long                   filterResultOptions;
+  corbatext_t            requestParams;
+  corbatext_t            refParams;
+  corbatext_tset         fields;
+  boolean                getParents;
+};
+
+struct corbaTermInfo
+{
+  corbatext_t      term;
+  long             frequency;
+  corbatext_tarray matchTerms;
+};
+
+typedef sequence<corbaTermInfo> corbaTermInfo_array;
+
+struct corbaMetadataInfo
+{
+  corbatext_t      params;
+  boolean          isRef;
+  corbatext_tarray values;
+  long             id;
+  long             parentid; // dodge for avoiding pointers for the moment
+};
+
+typedef sequence<corbaMetadataInfo> corbaMetadataInfo_array;
+
+struct corbaMetadataInfo_map
+{ 
+  corbatext_tarray        names;
+  corbaMetadataInfo_array values;
+};
+
+typedef sequence<long> corbaDocFreq_array;
+
+struct corbaResultDocInfo
+{
+  corbatext_t             OID;
+  long                    resultNum;
+  long                    ranking;
+  long                    termsMatched;
+  long                    phraseMatched;
+  corbaDocFreq_array      docFreq;
+  corbaMetadataInfo_map   metadata;
+  corbatext_t             classifierMetadataType;    // Added 05/04/2000
+  long                    classifierMetadataOffset;  // Added 05/04/2000
+  corbaMetadataInfo_array metaparents;
+};
+
+typedef sequence<corbaResultDocInfo> corbaResultDocInfo_array;
+
+enum corbaIsApprox
+{
+  resultExact,
+  resultApprox,
+  resultMany
+};
+
+struct corbaFilterResponse
+{
+  long                     numDocs;
+  corbaIsApprox            isApprox;
+  corbaTermInfo_array      termInfo;
+  corbaResultDocInfo_array docInfo;
+};
+
+interface corbaiface
+{
+  boolean   initialise(inout corbaComError error);
+  void      configure(in corbatext_t key, in corbatext_tarray cfgline,
+		      inout corbaComError error);
+  void      collectionList(inout corbatext_tarray collist,
+			   inout corbaComError error);
+  void      hasCollection(in corbatext_t corbaCollection, inout boolean has,
+		       inout corbaComError error);
+  void      ping(in corbatext_t collection, inout boolean wasSuccess, inout corbaComError error);
+  void      getDocument(in corbatext_t collection,
+			inout corbaDocRequest request, inout corbaDocResponse response,
+			inout corbaComError error);
+  void      getCollectInfo(in corbatext_t collection,
+			   inout corbaColInfoResponse response,
+			   inout corbaComError error);
+  void      getFilterInfo(in corbatext_t collection, 
+                          inout corbatext_tarray filterNames, 
+			  inout corbaComError error);
+  void      getFilterOptions(in corbatext_t collection,
+                             in corbatext_t option,
+                             inout corbaFilterOptionsResponse response,
+			     inout corbaComError error);
+  void      filter(in corbatext_t collection,
+		   in corbaFilterRequest request,
+                   inout corbaFilterResponse response,
+                   inout corbaComError error);
+};
+
+};
Index: /gsdl/trunk/runtime-src/src/corba/corbaiface.mpp
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbaiface.mpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbaiface.mpp	(revision 16571)
@@ -0,0 +1,2000 @@
+/*
+ *  MICO --- a free CORBA implementation
+ *  Copyright (C) 1997-98 Kay Roemer & Arno Puder
+ *
+ *  This file was automatically generated. DO NOT EDIT!
+ */
+
+#include "corbaiface.h"
+
+//--------------------------------------------------------
+//  Implementation of stubs
+//--------------------------------------------------------
+
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbatext_t::corbatext_t()
+{
+}
+
+gsdlInterface::corbatext_t::corbatext_t( const corbatext_t& _s )
+{
+  text = ((corbatext_t&)_s).text;
+  encoding = ((corbatext_t&)_s).encoding;
+  length = ((corbatext_t&)_s).length;
+}
+
+gsdlInterface::corbatext_t::~corbatext_t()
+{
+}
+
+gsdlInterface::corbatext_t&
+gsdlInterface::corbatext_t::operator=( const corbatext_t& _s )
+{
+  text = ((corbatext_t&)_s).text;
+  encoding = ((corbatext_t&)_s).encoding;
+  length = ((corbatext_t&)_s).length;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbatext_t : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbatext_t _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbatext_t::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbatext_t::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbatext_t::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbatext_t::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    CORBA::_stcseq_ushort->demarshal( dc, &((_MICO_T*)v)->text ) &&
+    CORBA::_stc_ushort->demarshal( dc, &((_MICO_T*)v)->encoding ) &&
+    CORBA::_stc_ulong->demarshal( dc, &((_MICO_T*)v)->length ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbatext_t::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  CORBA::_stcseq_ushort->marshal( ec, &((_MICO_T*)v)->text );
+  CORBA::_stc_ushort->marshal( ec, &((_MICO_T*)v)->encoding );
+  CORBA::_stc_ulong->marshal( ec, &((_MICO_T*)v)->length );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbatext_t;
+
+
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbatext_tmap::corbatext_tmap()
+{
+}
+
+gsdlInterface::corbatext_tmap::corbatext_tmap( const corbatext_tmap& _s )
+{
+  names = ((corbatext_tmap&)_s).names;
+  values = ((corbatext_tmap&)_s).values;
+}
+
+gsdlInterface::corbatext_tmap::~corbatext_tmap()
+{
+}
+
+gsdlInterface::corbatext_tmap&
+gsdlInterface::corbatext_tmap::operator=( const corbatext_tmap& _s )
+{
+  names = ((corbatext_tmap&)_s).names;
+  values = ((corbatext_tmap&)_s).values;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbatext_tmap : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbatext_tmap _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbatext_tmap::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbatext_tmap::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbatext_tmap::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbatext_tmap::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->names ) &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->values ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbatext_tmap::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->names );
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->values );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbatext_tmap;
+
+
+class _Marshaller_gsdlInterface_corbaComError : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaComError _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaComError::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaComError::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaComError::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaComError::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::ULong ul;
+  if( !dc.enumeration( ul ) )
+    return FALSE;
+  *(_MICO_T*) v = (_MICO_T) ul;
+  return TRUE;
+}
+
+void _Marshaller_gsdlInterface_corbaComError::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.enumeration( (CORBA::ULong) *(_MICO_T *) v );
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaComError;
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaShortColInfo::corbaShortColInfo()
+{
+}
+
+gsdlInterface::corbaShortColInfo::corbaShortColInfo( const corbaShortColInfo& _s )
+{
+  name = ((corbaShortColInfo&)_s).name;
+  host = ((corbaShortColInfo&)_s).host;
+  response = ((corbaShortColInfo&)_s).response;
+}
+
+gsdlInterface::corbaShortColInfo::~corbaShortColInfo()
+{
+}
+
+gsdlInterface::corbaShortColInfo&
+gsdlInterface::corbaShortColInfo::operator=( const corbaShortColInfo& _s )
+{
+  name = ((corbaShortColInfo&)_s).name;
+  host = ((corbaShortColInfo&)_s).host;
+  response = ((corbaShortColInfo&)_s).response;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaShortColInfo : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaShortColInfo _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaShortColInfo::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaShortColInfo::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaShortColInfo::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaShortColInfo::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->name ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->host ) &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->response ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaShortColInfo::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->name );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->host );
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->response );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaShortColInfo;
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaColInfoResponse::corbaColInfoResponse()
+{
+}
+
+gsdlInterface::corbaColInfoResponse::corbaColInfoResponse( const corbaColInfoResponse& _s )
+{
+  shoftInfo = ((corbaColInfoResponse&)_s).shoftInfo;
+  useBook = ((corbaColInfoResponse&)_s).useBook;
+  isPublic = ((corbaColInfoResponse&)_s).isPublic;
+  isBeta = ((corbaColInfoResponse&)_s).isBeta;
+  buildDate = ((corbaColInfoResponse&)_s).buildDate;
+  ccsCols = ((corbaColInfoResponse&)_s).ccsCols;
+  languages = ((corbaColInfoResponse&)_s).languages;
+  numDocs = ((corbaColInfoResponse&)_s).numDocs;
+  numWords = ((corbaColInfoResponse&)_s).numWords;
+  numBytes = ((corbaColInfoResponse&)_s).numBytes;
+  collectionMeta = ((corbaColInfoResponse&)_s).collectionMeta;
+  format = ((corbaColInfoResponse&)_s).format;
+  building = ((corbaColInfoResponse&)_s).building;
+  httpdomain = ((corbaColInfoResponse&)_s).httpdomain;
+  httpprefix = ((corbaColInfoResponse&)_s).httpprefix;
+  receptionist = ((corbaColInfoResponse&)_s).receptionist;
+}
+
+gsdlInterface::corbaColInfoResponse::~corbaColInfoResponse()
+{
+}
+
+gsdlInterface::corbaColInfoResponse&
+gsdlInterface::corbaColInfoResponse::operator=( const corbaColInfoResponse& _s )
+{
+  shoftInfo = ((corbaColInfoResponse&)_s).shoftInfo;
+  useBook = ((corbaColInfoResponse&)_s).useBook;
+  isPublic = ((corbaColInfoResponse&)_s).isPublic;
+  isBeta = ((corbaColInfoResponse&)_s).isBeta;
+  buildDate = ((corbaColInfoResponse&)_s).buildDate;
+  ccsCols = ((corbaColInfoResponse&)_s).ccsCols;
+  languages = ((corbaColInfoResponse&)_s).languages;
+  numDocs = ((corbaColInfoResponse&)_s).numDocs;
+  numWords = ((corbaColInfoResponse&)_s).numWords;
+  numBytes = ((corbaColInfoResponse&)_s).numBytes;
+  collectionMeta = ((corbaColInfoResponse&)_s).collectionMeta;
+  format = ((corbaColInfoResponse&)_s).format;
+  building = ((corbaColInfoResponse&)_s).building;
+  httpdomain = ((corbaColInfoResponse&)_s).httpdomain;
+  httpprefix = ((corbaColInfoResponse&)_s).httpprefix;
+  receptionist = ((corbaColInfoResponse&)_s).receptionist;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaColInfoResponse : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaColInfoResponse _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaColInfoResponse::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaColInfoResponse::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaColInfoResponse::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaColInfoResponse::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller_gsdlInterface_corbaShortColInfo->demarshal( dc, &((_MICO_T*)v)->shoftInfo ) &&
+    CORBA::_stc_boolean->demarshal( dc, &((_MICO_T*)v)->useBook ) &&
+    CORBA::_stc_boolean->demarshal( dc, &((_MICO_T*)v)->isPublic ) &&
+    CORBA::_stc_boolean->demarshal( dc, &((_MICO_T*)v)->isBeta ) &&
+    CORBA::_stc_ulong->demarshal( dc, &((_MICO_T*)v)->buildDate ) &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->ccsCols ) &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->languages ) &&
+    CORBA::_stc_ulong->demarshal( dc, &((_MICO_T*)v)->numDocs ) &&
+    CORBA::_stc_ulong->demarshal( dc, &((_MICO_T*)v)->numWords ) &&
+    CORBA::_stc_ulong->demarshal( dc, &((_MICO_T*)v)->numBytes ) &&
+    _marshaller_gsdlInterface_corbatext_tmap->demarshal( dc, &((_MICO_T*)v)->collectionMeta ) &&
+    _marshaller_gsdlInterface_corbatext_tmap->demarshal( dc, &((_MICO_T*)v)->format ) &&
+    _marshaller_gsdlInterface_corbatext_tmap->demarshal( dc, &((_MICO_T*)v)->building ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->httpdomain ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->httpprefix ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->receptionist ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaColInfoResponse::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller_gsdlInterface_corbaShortColInfo->marshal( ec, &((_MICO_T*)v)->shoftInfo );
+  CORBA::_stc_boolean->marshal( ec, &((_MICO_T*)v)->useBook );
+  CORBA::_stc_boolean->marshal( ec, &((_MICO_T*)v)->isPublic );
+  CORBA::_stc_boolean->marshal( ec, &((_MICO_T*)v)->isBeta );
+  CORBA::_stc_ulong->marshal( ec, &((_MICO_T*)v)->buildDate );
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->ccsCols );
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->languages );
+  CORBA::_stc_ulong->marshal( ec, &((_MICO_T*)v)->numDocs );
+  CORBA::_stc_ulong->marshal( ec, &((_MICO_T*)v)->numWords );
+  CORBA::_stc_ulong->marshal( ec, &((_MICO_T*)v)->numBytes );
+  _marshaller_gsdlInterface_corbatext_tmap->marshal( ec, &((_MICO_T*)v)->collectionMeta );
+  _marshaller_gsdlInterface_corbatext_tmap->marshal( ec, &((_MICO_T*)v)->format );
+  _marshaller_gsdlInterface_corbatext_tmap->marshal( ec, &((_MICO_T*)v)->building );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->httpdomain );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->httpprefix );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->receptionist );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaColInfoResponse;
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaDocRequest::corbaDocRequest()
+{
+}
+
+gsdlInterface::corbaDocRequest::corbaDocRequest( const corbaDocRequest& _s )
+{
+  OID = ((corbaDocRequest&)_s).OID;
+  docType = ((corbaDocRequest&)_s).docType;
+  docFormat = ((corbaDocRequest&)_s).docFormat;
+}
+
+gsdlInterface::corbaDocRequest::~corbaDocRequest()
+{
+}
+
+gsdlInterface::corbaDocRequest&
+gsdlInterface::corbaDocRequest::operator=( const corbaDocRequest& _s )
+{
+  OID = ((corbaDocRequest&)_s).OID;
+  docType = ((corbaDocRequest&)_s).docType;
+  docFormat = ((corbaDocRequest&)_s).docFormat;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaDocRequest : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaDocRequest _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaDocRequest::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaDocRequest::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaDocRequest::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaDocRequest::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->OID ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->docType ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->docFormat ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaDocRequest::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->OID );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->docType );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->docFormat );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaDocRequest;
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaDocResponse::corbaDocResponse()
+{
+}
+
+gsdlInterface::corbaDocResponse::corbaDocResponse( const corbaDocResponse& _s )
+{
+  doc = ((corbaDocResponse&)_s).doc;
+}
+
+gsdlInterface::corbaDocResponse::~corbaDocResponse()
+{
+}
+
+gsdlInterface::corbaDocResponse&
+gsdlInterface::corbaDocResponse::operator=( const corbaDocResponse& _s )
+{
+  doc = ((corbaDocResponse&)_s).doc;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaDocResponse : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaDocResponse _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaDocResponse::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaDocResponse::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaDocResponse::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaDocResponse::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->doc ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaDocResponse::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->doc );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaDocResponse;
+
+
+class _Marshaller_gsdlInterface_corbaFilterType : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaFilterType _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaFilterType::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterType::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterType::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaFilterType::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::ULong ul;
+  if( !dc.enumeration( ul ) )
+    return FALSE;
+  *(_MICO_T*) v = (_MICO_T) ul;
+  return TRUE;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterType::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.enumeration( (CORBA::ULong) *(_MICO_T *) v );
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterType;
+
+
+class _Marshaller_gsdlInterface_corbaFilterRepeatable : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaFilterRepeatable _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaFilterRepeatable::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterRepeatable::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterRepeatable::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaFilterRepeatable::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::ULong ul;
+  if( !dc.enumeration( ul ) )
+    return FALSE;
+  *(_MICO_T*) v = (_MICO_T) ul;
+  return TRUE;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterRepeatable::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.enumeration( (CORBA::ULong) *(_MICO_T *) v );
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterRepeatable;
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaFilterOption::corbaFilterOption()
+{
+}
+
+gsdlInterface::corbaFilterOption::corbaFilterOption( const corbaFilterOption& _s )
+{
+  name = ((corbaFilterOption&)_s).name;
+  type = ((corbaFilterOption&)_s).type;
+  repeatable = ((corbaFilterOption&)_s).repeatable;
+  defaultValue = ((corbaFilterOption&)_s).defaultValue;
+  validValues = ((corbaFilterOption&)_s).validValues;
+}
+
+gsdlInterface::corbaFilterOption::~corbaFilterOption()
+{
+}
+
+gsdlInterface::corbaFilterOption&
+gsdlInterface::corbaFilterOption::operator=( const corbaFilterOption& _s )
+{
+  name = ((corbaFilterOption&)_s).name;
+  type = ((corbaFilterOption&)_s).type;
+  repeatable = ((corbaFilterOption&)_s).repeatable;
+  defaultValue = ((corbaFilterOption&)_s).defaultValue;
+  validValues = ((corbaFilterOption&)_s).validValues;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaFilterOption : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaFilterOption _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaFilterOption::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterOption::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterOption::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaFilterOption::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->name ) &&
+    _marshaller_gsdlInterface_corbaFilterType->demarshal( dc, &((_MICO_T*)v)->type ) &&
+    _marshaller_gsdlInterface_corbaFilterRepeatable->demarshal( dc, &((_MICO_T*)v)->repeatable ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->defaultValue ) &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->validValues ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaFilterOption::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->name );
+  _marshaller_gsdlInterface_corbaFilterType->marshal( ec, &((_MICO_T*)v)->type );
+  _marshaller_gsdlInterface_corbaFilterRepeatable->marshal( ec, &((_MICO_T*)v)->repeatable );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->defaultValue );
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->validValues );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterOption;
+
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaFilterOptionsResponse::corbaFilterOptionsResponse()
+{
+}
+
+gsdlInterface::corbaFilterOptionsResponse::corbaFilterOptionsResponse( const corbaFilterOptionsResponse& _s )
+{
+  options = ((corbaFilterOptionsResponse&)_s).options;
+  names = ((corbaFilterOptionsResponse&)_s).names;
+}
+
+gsdlInterface::corbaFilterOptionsResponse::~corbaFilterOptionsResponse()
+{
+}
+
+gsdlInterface::corbaFilterOptionsResponse&
+gsdlInterface::corbaFilterOptionsResponse::operator=( const corbaFilterOptionsResponse& _s )
+{
+  options = ((corbaFilterOptionsResponse&)_s).options;
+  names = ((corbaFilterOptionsResponse&)_s).names;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaFilterOptionsResponse : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaFilterOptionsResponse _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaFilterOptionsResponse::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterOptionsResponse::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterOptionsResponse::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaFilterOptionsResponse::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller__seq_gsdlInterface_corbaFilterOption->demarshal( dc, &((_MICO_T*)v)->options ) &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->names ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaFilterOptionsResponse::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller__seq_gsdlInterface_corbaFilterOption->marshal( ec, &((_MICO_T*)v)->options );
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->names );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterOptionsResponse;
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaOptionValue::corbaOptionValue()
+{
+}
+
+gsdlInterface::corbaOptionValue::corbaOptionValue( const corbaOptionValue& _s )
+{
+  name = ((corbaOptionValue&)_s).name;
+  value = ((corbaOptionValue&)_s).value;
+}
+
+gsdlInterface::corbaOptionValue::~corbaOptionValue()
+{
+}
+
+gsdlInterface::corbaOptionValue&
+gsdlInterface::corbaOptionValue::operator=( const corbaOptionValue& _s )
+{
+  name = ((corbaOptionValue&)_s).name;
+  value = ((corbaOptionValue&)_s).value;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaOptionValue : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaOptionValue _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaOptionValue::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaOptionValue::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaOptionValue::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaOptionValue::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->name ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->value ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaOptionValue::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->name );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->value );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaOptionValue;
+
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaFilterRequest::corbaFilterRequest()
+{
+}
+
+gsdlInterface::corbaFilterRequest::corbaFilterRequest( const corbaFilterRequest& _s )
+{
+  filter = ((corbaFilterRequest&)_s).filter;
+  filterOptions = ((corbaFilterRequest&)_s).filterOptions;
+  docSet = ((corbaFilterRequest&)_s).docSet;
+  filterResultOptions = ((corbaFilterRequest&)_s).filterResultOptions;
+  requestParams = ((corbaFilterRequest&)_s).requestParams;
+  refParams = ((corbaFilterRequest&)_s).refParams;
+  fields = ((corbaFilterRequest&)_s).fields;
+  getParents = ((corbaFilterRequest&)_s).getParents;
+}
+
+gsdlInterface::corbaFilterRequest::~corbaFilterRequest()
+{
+}
+
+gsdlInterface::corbaFilterRequest&
+gsdlInterface::corbaFilterRequest::operator=( const corbaFilterRequest& _s )
+{
+  filter = ((corbaFilterRequest&)_s).filter;
+  filterOptions = ((corbaFilterRequest&)_s).filterOptions;
+  docSet = ((corbaFilterRequest&)_s).docSet;
+  filterResultOptions = ((corbaFilterRequest&)_s).filterResultOptions;
+  requestParams = ((corbaFilterRequest&)_s).requestParams;
+  refParams = ((corbaFilterRequest&)_s).refParams;
+  fields = ((corbaFilterRequest&)_s).fields;
+  getParents = ((corbaFilterRequest&)_s).getParents;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaFilterRequest : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaFilterRequest _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaFilterRequest::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterRequest::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterRequest::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaFilterRequest::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->filter ) &&
+    _marshaller__seq_gsdlInterface_corbaOptionValue->demarshal( dc, &((_MICO_T*)v)->filterOptions ) &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->docSet ) &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->filterResultOptions ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->requestParams ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->refParams ) &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->fields ) &&
+    CORBA::_stc_boolean->demarshal( dc, &((_MICO_T*)v)->getParents ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaFilterRequest::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->filter );
+  _marshaller__seq_gsdlInterface_corbaOptionValue->marshal( ec, &((_MICO_T*)v)->filterOptions );
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->docSet );
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->filterResultOptions );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->requestParams );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->refParams );
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->fields );
+  CORBA::_stc_boolean->marshal( ec, &((_MICO_T*)v)->getParents );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterRequest;
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaTermInfo::corbaTermInfo()
+{
+}
+
+gsdlInterface::corbaTermInfo::corbaTermInfo( const corbaTermInfo& _s )
+{
+  term = ((corbaTermInfo&)_s).term;
+  frequency = ((corbaTermInfo&)_s).frequency;
+  matchTerms = ((corbaTermInfo&)_s).matchTerms;
+}
+
+gsdlInterface::corbaTermInfo::~corbaTermInfo()
+{
+}
+
+gsdlInterface::corbaTermInfo&
+gsdlInterface::corbaTermInfo::operator=( const corbaTermInfo& _s )
+{
+  term = ((corbaTermInfo&)_s).term;
+  frequency = ((corbaTermInfo&)_s).frequency;
+  matchTerms = ((corbaTermInfo&)_s).matchTerms;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaTermInfo : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaTermInfo _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaTermInfo::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaTermInfo::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaTermInfo::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaTermInfo::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->term ) &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->frequency ) &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->matchTerms ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaTermInfo::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->term );
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->frequency );
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->matchTerms );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaTermInfo;
+
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaMetadataInfo::corbaMetadataInfo()
+{
+}
+
+gsdlInterface::corbaMetadataInfo::corbaMetadataInfo( const corbaMetadataInfo& _s )
+{
+  params = ((corbaMetadataInfo&)_s).params;
+  isRef = ((corbaMetadataInfo&)_s).isRef;
+  values = ((corbaMetadataInfo&)_s).values;
+  id = ((corbaMetadataInfo&)_s).id;
+  parentid = ((corbaMetadataInfo&)_s).parentid;
+}
+
+gsdlInterface::corbaMetadataInfo::~corbaMetadataInfo()
+{
+}
+
+gsdlInterface::corbaMetadataInfo&
+gsdlInterface::corbaMetadataInfo::operator=( const corbaMetadataInfo& _s )
+{
+  params = ((corbaMetadataInfo&)_s).params;
+  isRef = ((corbaMetadataInfo&)_s).isRef;
+  values = ((corbaMetadataInfo&)_s).values;
+  id = ((corbaMetadataInfo&)_s).id;
+  parentid = ((corbaMetadataInfo&)_s).parentid;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaMetadataInfo : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaMetadataInfo _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaMetadataInfo::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaMetadataInfo::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaMetadataInfo::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaMetadataInfo::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->params ) &&
+    CORBA::_stc_boolean->demarshal( dc, &((_MICO_T*)v)->isRef ) &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->values ) &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->id ) &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->parentid ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaMetadataInfo::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->params );
+  CORBA::_stc_boolean->marshal( ec, &((_MICO_T*)v)->isRef );
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->values );
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->id );
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->parentid );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaMetadataInfo;
+
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaMetadataInfo_map::corbaMetadataInfo_map()
+{
+}
+
+gsdlInterface::corbaMetadataInfo_map::corbaMetadataInfo_map( const corbaMetadataInfo_map& _s )
+{
+  names = ((corbaMetadataInfo_map&)_s).names;
+  values = ((corbaMetadataInfo_map&)_s).values;
+}
+
+gsdlInterface::corbaMetadataInfo_map::~corbaMetadataInfo_map()
+{
+}
+
+gsdlInterface::corbaMetadataInfo_map&
+gsdlInterface::corbaMetadataInfo_map::operator=( const corbaMetadataInfo_map& _s )
+{
+  names = ((corbaMetadataInfo_map&)_s).names;
+  values = ((corbaMetadataInfo_map&)_s).values;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaMetadataInfo_map : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaMetadataInfo_map _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaMetadataInfo_map::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaMetadataInfo_map::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaMetadataInfo_map::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaMetadataInfo_map::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller__seq_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->names ) &&
+    _marshaller__seq_gsdlInterface_corbaMetadataInfo->demarshal( dc, &((_MICO_T*)v)->values ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaMetadataInfo_map::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller__seq_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->names );
+  _marshaller__seq_gsdlInterface_corbaMetadataInfo->marshal( ec, &((_MICO_T*)v)->values );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaMetadataInfo_map;
+
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaResultDocInfo::corbaResultDocInfo()
+{
+}
+
+gsdlInterface::corbaResultDocInfo::corbaResultDocInfo( const corbaResultDocInfo& _s )
+{
+  OID = ((corbaResultDocInfo&)_s).OID;
+  resultNum = ((corbaResultDocInfo&)_s).resultNum;
+  ranking = ((corbaResultDocInfo&)_s).ranking;
+  termsMatched = ((corbaResultDocInfo&)_s).termsMatched;
+  phraseMatched = ((corbaResultDocInfo&)_s).phraseMatched;
+  docFreq = ((corbaResultDocInfo&)_s).docFreq;
+  metadata = ((corbaResultDocInfo&)_s).metadata;
+  classifierMetadataType = ((corbaResultDocInfo&)_s).classifierMetadataType;
+  classifierMetadataOffset = ((corbaResultDocInfo&)_s).classifierMetadataOffset;
+  metaparents = ((corbaResultDocInfo&)_s).metaparents;
+}
+
+gsdlInterface::corbaResultDocInfo::~corbaResultDocInfo()
+{
+}
+
+gsdlInterface::corbaResultDocInfo&
+gsdlInterface::corbaResultDocInfo::operator=( const corbaResultDocInfo& _s )
+{
+  OID = ((corbaResultDocInfo&)_s).OID;
+  resultNum = ((corbaResultDocInfo&)_s).resultNum;
+  ranking = ((corbaResultDocInfo&)_s).ranking;
+  termsMatched = ((corbaResultDocInfo&)_s).termsMatched;
+  phraseMatched = ((corbaResultDocInfo&)_s).phraseMatched;
+  docFreq = ((corbaResultDocInfo&)_s).docFreq;
+  metadata = ((corbaResultDocInfo&)_s).metadata;
+  classifierMetadataType = ((corbaResultDocInfo&)_s).classifierMetadataType;
+  classifierMetadataOffset = ((corbaResultDocInfo&)_s).classifierMetadataOffset;
+  metaparents = ((corbaResultDocInfo&)_s).metaparents;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaResultDocInfo : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaResultDocInfo _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaResultDocInfo::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaResultDocInfo::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaResultDocInfo::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaResultDocInfo::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->OID ) &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->resultNum ) &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->ranking ) &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->termsMatched ) &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->phraseMatched ) &&
+    CORBA::_stcseq_long->demarshal( dc, &((_MICO_T*)v)->docFreq ) &&
+    _marshaller_gsdlInterface_corbaMetadataInfo_map->demarshal( dc, &((_MICO_T*)v)->metadata ) &&
+    _marshaller_gsdlInterface_corbatext_t->demarshal( dc, &((_MICO_T*)v)->classifierMetadataType ) &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->classifierMetadataOffset ) &&
+    _marshaller__seq_gsdlInterface_corbaMetadataInfo->demarshal( dc, &((_MICO_T*)v)->metaparents ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaResultDocInfo::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->OID );
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->resultNum );
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->ranking );
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->termsMatched );
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->phraseMatched );
+  CORBA::_stcseq_long->marshal( ec, &((_MICO_T*)v)->docFreq );
+  _marshaller_gsdlInterface_corbaMetadataInfo_map->marshal( ec, &((_MICO_T*)v)->metadata );
+  _marshaller_gsdlInterface_corbatext_t->marshal( ec, &((_MICO_T*)v)->classifierMetadataType );
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->classifierMetadataOffset );
+  _marshaller__seq_gsdlInterface_corbaMetadataInfo->marshal( ec, &((_MICO_T*)v)->metaparents );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaResultDocInfo;
+
+
+
+class _Marshaller_gsdlInterface_corbaIsApprox : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaIsApprox _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaIsApprox::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaIsApprox::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaIsApprox::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaIsApprox::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::ULong ul;
+  if( !dc.enumeration( ul ) )
+    return FALSE;
+  *(_MICO_T*) v = (_MICO_T) ul;
+  return TRUE;
+}
+
+void _Marshaller_gsdlInterface_corbaIsApprox::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.enumeration( (CORBA::ULong) *(_MICO_T *) v );
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaIsApprox;
+
+#ifdef HAVE_EXPLICIT_STRUCT_OPS
+gsdlInterface::corbaFilterResponse::corbaFilterResponse()
+{
+}
+
+gsdlInterface::corbaFilterResponse::corbaFilterResponse( const corbaFilterResponse& _s )
+{
+  numDocs = ((corbaFilterResponse&)_s).numDocs;
+  isApprox = ((corbaFilterResponse&)_s).isApprox;
+  termInfo = ((corbaFilterResponse&)_s).termInfo;
+  docInfo = ((corbaFilterResponse&)_s).docInfo;
+}
+
+gsdlInterface::corbaFilterResponse::~corbaFilterResponse()
+{
+}
+
+gsdlInterface::corbaFilterResponse&
+gsdlInterface::corbaFilterResponse::operator=( const corbaFilterResponse& _s )
+{
+  numDocs = ((corbaFilterResponse&)_s).numDocs;
+  isApprox = ((corbaFilterResponse&)_s).isApprox;
+  termInfo = ((corbaFilterResponse&)_s).termInfo;
+  docInfo = ((corbaFilterResponse&)_s).docInfo;
+  return *this;
+}
+#endif
+
+class _Marshaller_gsdlInterface_corbaFilterResponse : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaFilterResponse _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaFilterResponse::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterResponse::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller_gsdlInterface_corbaFilterResponse::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaFilterResponse::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  return
+    dc.struct_begin() &&
+    CORBA::_stc_long->demarshal( dc, &((_MICO_T*)v)->numDocs ) &&
+    _marshaller_gsdlInterface_corbaIsApprox->demarshal( dc, &((_MICO_T*)v)->isApprox ) &&
+    _marshaller__seq_gsdlInterface_corbaTermInfo->demarshal( dc, &((_MICO_T*)v)->termInfo ) &&
+    _marshaller__seq_gsdlInterface_corbaResultDocInfo->demarshal( dc, &((_MICO_T*)v)->docInfo ) &&
+    dc.struct_end();
+}
+
+void _Marshaller_gsdlInterface_corbaFilterResponse::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  ec.struct_begin();
+  CORBA::_stc_long->marshal( ec, &((_MICO_T*)v)->numDocs );
+  _marshaller_gsdlInterface_corbaIsApprox->marshal( ec, &((_MICO_T*)v)->isApprox );
+  _marshaller__seq_gsdlInterface_corbaTermInfo->marshal( ec, &((_MICO_T*)v)->termInfo );
+  _marshaller__seq_gsdlInterface_corbaResultDocInfo->marshal( ec, &((_MICO_T*)v)->docInfo );
+  ec.struct_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaFilterResponse;
+
+
+// Stub interface corbaiface
+gsdlInterface::corbaiface::~corbaiface()
+{
+}
+
+void *gsdlInterface::corbaiface::_narrow_helper( const char *_rid )
+{
+  if( strcmp( _rid, "IDL:gsdlInterface/corbaiface:1.0" ) == 0 )
+    return (void *)this;
+  return NULL;
+}
+
+bool gsdlInterface::corbaiface::_narrow_helper2( CORBA::Object_ptr _obj )
+{
+  if( strcmp( _obj->_repoid(), "IDL:gsdlInterface/corbaiface:1.0" ) == 0) {
+    return true;
+  }
+  for( vector<CORBA::Narrow_proto>::size_type _i = 0;
+       _narrow_helpers && _i < _narrow_helpers->size(); _i++ ) {
+    bool _res = (*(*_narrow_helpers)[ _i ])( _obj );
+    if( _res )
+      return true;
+  }
+  return false;
+}
+
+gsdlInterface::corbaiface_ptr gsdlInterface::corbaiface::_narrow( CORBA::Object_ptr _obj )
+{
+  gsdlInterface::corbaiface_ptr _o;
+  if( !CORBA::is_nil( _obj ) ) {
+    void *_p;
+    if( (_p = _obj->_narrow_helper( "IDL:gsdlInterface/corbaiface:1.0" )))
+      return _duplicate( (gsdlInterface::corbaiface_ptr) _p );
+    if( _narrow_helper2( _obj ) ||
+       ( _obj->_is_a_remote( "IDL:gsdlInterface/corbaiface:1.0" ) ) ) {
+      _o = new gsdlInterface::corbaiface_stub;
+      _o->MICO_SCOPE(CORBA,Object::operator=)( *_obj );
+      return _o;
+    }
+  }
+  return _nil();
+}
+
+gsdlInterface::corbaiface_ptr
+gsdlInterface::corbaiface::_narrow( CORBA::AbstractBase_ptr _obj )
+{
+  return _narrow (_obj->_to_object());
+}
+
+gsdlInterface::corbaiface_stub::~corbaiface_stub()
+{
+}
+
+CORBA::Boolean gsdlInterface::corbaiface_stub::initialise( gsdlInterface::corbaComError& error )
+{
+  CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+  CORBA::Boolean _res;
+  CORBA::StaticAny __res( CORBA::_stc_boolean, &_res );
+
+  CORBA::StaticRequest __req( this, "initialise" );
+  __req.add_inout_arg( &_error );
+  __req.set_result( &__res );
+
+  __req.invoke();
+
+  mico_sii_throw( &__req, 
+    0);
+  return _res;
+}
+
+
+void gsdlInterface::corbaiface_stub::configure( const gsdlInterface::corbatext_t& key, const gsdlInterface::corbatext_tarray& cfgline, gsdlInterface::corbaComError& error )
+{
+  CORBA::StaticAny _key( _marshaller_gsdlInterface_corbatext_t, &key );
+  CORBA::StaticAny _cfgline( _marshaller__seq_gsdlInterface_corbatext_t, &cfgline );
+  CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+  CORBA::StaticRequest __req( this, "configure" );
+  __req.add_in_arg( &_key );
+  __req.add_in_arg( &_cfgline );
+  __req.add_inout_arg( &_error );
+
+  __req.invoke();
+
+  mico_sii_throw( &__req, 
+    0);
+}
+
+
+void gsdlInterface::corbaiface_stub::collectionList( gsdlInterface::corbatext_tarray& collist, gsdlInterface::corbaComError& error )
+{
+  CORBA::StaticAny _collist( _marshaller__seq_gsdlInterface_corbatext_t, &collist );
+  CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+  CORBA::StaticRequest __req( this, "collectionList" );
+  __req.add_inout_arg( &_collist );
+  __req.add_inout_arg( &_error );
+
+  __req.invoke();
+
+  mico_sii_throw( &__req, 
+    0);
+}
+
+
+void gsdlInterface::corbaiface_stub::hasCollection( const gsdlInterface::corbatext_t& corbaCollection, CORBA::Boolean& has, gsdlInterface::corbaComError& error )
+{
+  CORBA::StaticAny _corbaCollection( _marshaller_gsdlInterface_corbatext_t, &corbaCollection );
+  CORBA::StaticAny _has( CORBA::_stc_boolean, &has );
+  CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+  CORBA::StaticRequest __req( this, "hasCollection" );
+  __req.add_in_arg( &_corbaCollection );
+  __req.add_inout_arg( &_has );
+  __req.add_inout_arg( &_error );
+
+  __req.invoke();
+
+  mico_sii_throw( &__req, 
+    0);
+}
+
+
+void gsdlInterface::corbaiface_stub::ping( const gsdlInterface::corbatext_t& collection, CORBA::Boolean& wasSuccess, gsdlInterface::corbaComError& error )
+{
+  CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+  CORBA::StaticAny _wasSuccess( CORBA::_stc_boolean, &wasSuccess );
+  CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+  CORBA::StaticRequest __req( this, "ping" );
+  __req.add_in_arg( &_collection );
+  __req.add_inout_arg( &_wasSuccess );
+  __req.add_inout_arg( &_error );
+
+  __req.invoke();
+
+  mico_sii_throw( &__req, 
+    0);
+}
+
+
+void gsdlInterface::corbaiface_stub::getDocument( const gsdlInterface::corbatext_t& collection, gsdlInterface::corbaDocRequest& request, gsdlInterface::corbaDocResponse& response, gsdlInterface::corbaComError& error )
+{
+  CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+  CORBA::StaticAny _request( _marshaller_gsdlInterface_corbaDocRequest, &request );
+  CORBA::StaticAny _response( _marshaller_gsdlInterface_corbaDocResponse, &response );
+  CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+  CORBA::StaticRequest __req( this, "getDocument" );
+  __req.add_in_arg( &_collection );
+  __req.add_inout_arg( &_request );
+  __req.add_inout_arg( &_response );
+  __req.add_inout_arg( &_error );
+
+  __req.invoke();
+
+  mico_sii_throw( &__req, 
+    0);
+}
+
+
+void gsdlInterface::corbaiface_stub::getCollectInfo( const gsdlInterface::corbatext_t& collection, gsdlInterface::corbaColInfoResponse& response, gsdlInterface::corbaComError& error )
+{
+  CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+  CORBA::StaticAny _response( _marshaller_gsdlInterface_corbaColInfoResponse, &response );
+  CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+  CORBA::StaticRequest __req( this, "getCollectInfo" );
+  __req.add_in_arg( &_collection );
+  __req.add_inout_arg( &_response );
+  __req.add_inout_arg( &_error );
+
+  __req.invoke();
+
+  mico_sii_throw( &__req, 
+    0);
+}
+
+
+void gsdlInterface::corbaiface_stub::getFilterInfo( const gsdlInterface::corbatext_t& collection, gsdlInterface::corbatext_tarray& filterNames, gsdlInterface::corbaComError& error )
+{
+  CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+  CORBA::StaticAny _filterNames( _marshaller__seq_gsdlInterface_corbatext_t, &filterNames );
+  CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+  CORBA::StaticRequest __req( this, "getFilterInfo" );
+  __req.add_in_arg( &_collection );
+  __req.add_inout_arg( &_filterNames );
+  __req.add_inout_arg( &_error );
+
+  __req.invoke();
+
+  mico_sii_throw( &__req, 
+    0);
+}
+
+
+void gsdlInterface::corbaiface_stub::getFilterOptions( const gsdlInterface::corbatext_t& collection, const gsdlInterface::corbatext_t& option, gsdlInterface::corbaFilterOptionsResponse& response, gsdlInterface::corbaComError& error )
+{
+  CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+  CORBA::StaticAny _option( _marshaller_gsdlInterface_corbatext_t, &option );
+  CORBA::StaticAny _response( _marshaller_gsdlInterface_corbaFilterOptionsResponse, &response );
+  CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+  CORBA::StaticRequest __req( this, "getFilterOptions" );
+  __req.add_in_arg( &_collection );
+  __req.add_in_arg( &_option );
+  __req.add_inout_arg( &_response );
+  __req.add_inout_arg( &_error );
+
+  __req.invoke();
+
+  mico_sii_throw( &__req, 
+    0);
+}
+
+
+void gsdlInterface::corbaiface_stub::filter( const gsdlInterface::corbatext_t& collection, const gsdlInterface::corbaFilterRequest& request, gsdlInterface::corbaFilterResponse& response, gsdlInterface::corbaComError& error )
+{
+  CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+  CORBA::StaticAny _request( _marshaller_gsdlInterface_corbaFilterRequest, &request );
+  CORBA::StaticAny _response( _marshaller_gsdlInterface_corbaFilterResponse, &response );
+  CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+  CORBA::StaticRequest __req( this, "filter" );
+  __req.add_in_arg( &_collection );
+  __req.add_in_arg( &_request );
+  __req.add_inout_arg( &_response );
+  __req.add_inout_arg( &_error );
+
+  __req.invoke();
+
+  mico_sii_throw( &__req, 
+    0);
+}
+
+
+#ifdef HAVE_NAMESPACE
+namespace gsdlInterface { vector<CORBA::Narrow_proto> * corbaiface::_narrow_helpers; }
+#else
+vector<CORBA::Narrow_proto> * gsdlInterface::corbaiface::_narrow_helpers;
+#endif
+
+class _Marshaller_gsdlInterface_corbaiface : public CORBA::StaticTypeInfo {
+    typedef gsdlInterface::corbaiface_ptr _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller_gsdlInterface_corbaiface::create() const
+{
+  return (StaticValueType) new _MICO_T( 0 );
+}
+
+void _Marshaller_gsdlInterface_corbaiface::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = ::gsdlInterface::corbaiface::_duplicate( *(_MICO_T*) s );
+}
+
+void _Marshaller_gsdlInterface_corbaiface::free( StaticValueType v ) const
+{
+  CORBA::release( *(_MICO_T *) v );
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller_gsdlInterface_corbaiface::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::Object_ptr obj;
+  if (!CORBA::_stc_Object->demarshal(dc, &obj))
+    return FALSE;
+  *(_MICO_T *) v = ::gsdlInterface::corbaiface::_narrow( obj );
+  CORBA::Boolean ret = CORBA::is_nil (obj) || !CORBA::is_nil (*(_MICO_T *)v);
+  CORBA::release (obj);
+  return ret;
+}
+
+void _Marshaller_gsdlInterface_corbaiface::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  CORBA::Object_ptr obj = *(_MICO_T *) v;
+  CORBA::_stc_Object->marshal( ec, &obj );
+}
+
+CORBA::StaticTypeInfo *_marshaller_gsdlInterface_corbaiface;
+
+class _Marshaller__seq_gsdlInterface_corbatext_t : public CORBA::StaticTypeInfo {
+    typedef SequenceTmpl<gsdlInterface::corbatext_t,MICO_TID_DEF> _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller__seq_gsdlInterface_corbatext_t::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller__seq_gsdlInterface_corbatext_t::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller__seq_gsdlInterface_corbatext_t::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller__seq_gsdlInterface_corbatext_t::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::ULong len;
+  if( !dc.seq_begin( len ) )
+    return FALSE;
+  ((_MICO_T *) v)->length( len );
+  for( CORBA::ULong i = 0; i < len; i++ ) {
+    if( !_marshaller_gsdlInterface_corbatext_t->demarshal( dc, &(*(_MICO_T*)v)[i] ) )
+      return FALSE;
+  }
+  return dc.seq_end();
+}
+
+void _Marshaller__seq_gsdlInterface_corbatext_t::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  CORBA::ULong len = ((_MICO_T *) v)->length();
+  ec.seq_begin( len );
+  for( CORBA::ULong i = 0; i < len; i++ )
+    _marshaller_gsdlInterface_corbatext_t->marshal( ec, &(*(_MICO_T*)v)[i] );
+  ec.seq_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbatext_t;
+
+class _Marshaller__seq_gsdlInterface_corbaFilterOption : public CORBA::StaticTypeInfo {
+    typedef SequenceTmpl<gsdlInterface::corbaFilterOption,MICO_TID_DEF> _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller__seq_gsdlInterface_corbaFilterOption::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller__seq_gsdlInterface_corbaFilterOption::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller__seq_gsdlInterface_corbaFilterOption::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller__seq_gsdlInterface_corbaFilterOption::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::ULong len;
+  if( !dc.seq_begin( len ) )
+    return FALSE;
+  ((_MICO_T *) v)->length( len );
+  for( CORBA::ULong i = 0; i < len; i++ ) {
+    if( !_marshaller_gsdlInterface_corbaFilterOption->demarshal( dc, &(*(_MICO_T*)v)[i] ) )
+      return FALSE;
+  }
+  return dc.seq_end();
+}
+
+void _Marshaller__seq_gsdlInterface_corbaFilterOption::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  CORBA::ULong len = ((_MICO_T *) v)->length();
+  ec.seq_begin( len );
+  for( CORBA::ULong i = 0; i < len; i++ )
+    _marshaller_gsdlInterface_corbaFilterOption->marshal( ec, &(*(_MICO_T*)v)[i] );
+  ec.seq_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbaFilterOption;
+
+class _Marshaller__seq_gsdlInterface_corbaOptionValue : public CORBA::StaticTypeInfo {
+    typedef SequenceTmpl<gsdlInterface::corbaOptionValue,MICO_TID_DEF> _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller__seq_gsdlInterface_corbaOptionValue::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller__seq_gsdlInterface_corbaOptionValue::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller__seq_gsdlInterface_corbaOptionValue::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller__seq_gsdlInterface_corbaOptionValue::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::ULong len;
+  if( !dc.seq_begin( len ) )
+    return FALSE;
+  ((_MICO_T *) v)->length( len );
+  for( CORBA::ULong i = 0; i < len; i++ ) {
+    if( !_marshaller_gsdlInterface_corbaOptionValue->demarshal( dc, &(*(_MICO_T*)v)[i] ) )
+      return FALSE;
+  }
+  return dc.seq_end();
+}
+
+void _Marshaller__seq_gsdlInterface_corbaOptionValue::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  CORBA::ULong len = ((_MICO_T *) v)->length();
+  ec.seq_begin( len );
+  for( CORBA::ULong i = 0; i < len; i++ )
+    _marshaller_gsdlInterface_corbaOptionValue->marshal( ec, &(*(_MICO_T*)v)[i] );
+  ec.seq_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbaOptionValue;
+
+class _Marshaller__seq_gsdlInterface_corbaTermInfo : public CORBA::StaticTypeInfo {
+    typedef SequenceTmpl<gsdlInterface::corbaTermInfo,MICO_TID_DEF> _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller__seq_gsdlInterface_corbaTermInfo::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller__seq_gsdlInterface_corbaTermInfo::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller__seq_gsdlInterface_corbaTermInfo::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller__seq_gsdlInterface_corbaTermInfo::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::ULong len;
+  if( !dc.seq_begin( len ) )
+    return FALSE;
+  ((_MICO_T *) v)->length( len );
+  for( CORBA::ULong i = 0; i < len; i++ ) {
+    if( !_marshaller_gsdlInterface_corbaTermInfo->demarshal( dc, &(*(_MICO_T*)v)[i] ) )
+      return FALSE;
+  }
+  return dc.seq_end();
+}
+
+void _Marshaller__seq_gsdlInterface_corbaTermInfo::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  CORBA::ULong len = ((_MICO_T *) v)->length();
+  ec.seq_begin( len );
+  for( CORBA::ULong i = 0; i < len; i++ )
+    _marshaller_gsdlInterface_corbaTermInfo->marshal( ec, &(*(_MICO_T*)v)[i] );
+  ec.seq_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbaTermInfo;
+
+class _Marshaller__seq_gsdlInterface_corbaMetadataInfo : public CORBA::StaticTypeInfo {
+    typedef SequenceTmpl<gsdlInterface::corbaMetadataInfo,MICO_TID_DEF> _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller__seq_gsdlInterface_corbaMetadataInfo::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller__seq_gsdlInterface_corbaMetadataInfo::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller__seq_gsdlInterface_corbaMetadataInfo::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller__seq_gsdlInterface_corbaMetadataInfo::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::ULong len;
+  if( !dc.seq_begin( len ) )
+    return FALSE;
+  ((_MICO_T *) v)->length( len );
+  for( CORBA::ULong i = 0; i < len; i++ ) {
+    if( !_marshaller_gsdlInterface_corbaMetadataInfo->demarshal( dc, &(*(_MICO_T*)v)[i] ) )
+      return FALSE;
+  }
+  return dc.seq_end();
+}
+
+void _Marshaller__seq_gsdlInterface_corbaMetadataInfo::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  CORBA::ULong len = ((_MICO_T *) v)->length();
+  ec.seq_begin( len );
+  for( CORBA::ULong i = 0; i < len; i++ )
+    _marshaller_gsdlInterface_corbaMetadataInfo->marshal( ec, &(*(_MICO_T*)v)[i] );
+  ec.seq_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbaMetadataInfo;
+
+class _Marshaller__seq_gsdlInterface_corbaResultDocInfo : public CORBA::StaticTypeInfo {
+    typedef SequenceTmpl<gsdlInterface::corbaResultDocInfo,MICO_TID_DEF> _MICO_T;
+  public:
+    StaticValueType create () const;
+    void assign (StaticValueType dst, const StaticValueType src) const;
+    void free (StaticValueType) const;
+    CORBA::Boolean demarshal (CORBA::DataDecoder&, StaticValueType) const;
+    void marshal (CORBA::DataEncoder &, StaticValueType) const;
+};
+
+
+CORBA::StaticValueType _Marshaller__seq_gsdlInterface_corbaResultDocInfo::create() const
+{
+  return (StaticValueType) new _MICO_T;
+}
+
+void _Marshaller__seq_gsdlInterface_corbaResultDocInfo::assign( StaticValueType d, const StaticValueType s ) const
+{
+  *(_MICO_T*) d = *(_MICO_T*) s;
+}
+
+void _Marshaller__seq_gsdlInterface_corbaResultDocInfo::free( StaticValueType v ) const
+{
+  delete (_MICO_T*) v;
+}
+
+CORBA::Boolean _Marshaller__seq_gsdlInterface_corbaResultDocInfo::demarshal( CORBA::DataDecoder &dc, StaticValueType v ) const
+{
+  CORBA::ULong len;
+  if( !dc.seq_begin( len ) )
+    return FALSE;
+  ((_MICO_T *) v)->length( len );
+  for( CORBA::ULong i = 0; i < len; i++ ) {
+    if( !_marshaller_gsdlInterface_corbaResultDocInfo->demarshal( dc, &(*(_MICO_T*)v)[i] ) )
+      return FALSE;
+  }
+  return dc.seq_end();
+}
+
+void _Marshaller__seq_gsdlInterface_corbaResultDocInfo::marshal( CORBA::DataEncoder &ec, StaticValueType v ) const
+{
+  CORBA::ULong len = ((_MICO_T *) v)->length();
+  ec.seq_begin( len );
+  for( CORBA::ULong i = 0; i < len; i++ )
+    _marshaller_gsdlInterface_corbaResultDocInfo->marshal( ec, &(*(_MICO_T*)v)[i] );
+  ec.seq_end();
+}
+
+CORBA::StaticTypeInfo *_marshaller__seq_gsdlInterface_corbaResultDocInfo;
+
+struct __tc_init_CORBAIFACE {
+  __tc_init_CORBAIFACE()
+  {
+    _marshaller_gsdlInterface_corbatext_t = new _Marshaller_gsdlInterface_corbatext_t;
+    _marshaller_gsdlInterface_corbatext_tmap = new _Marshaller_gsdlInterface_corbatext_tmap;
+    _marshaller_gsdlInterface_corbaComError = new _Marshaller_gsdlInterface_corbaComError;
+    _marshaller_gsdlInterface_corbaShortColInfo = new _Marshaller_gsdlInterface_corbaShortColInfo;
+    _marshaller_gsdlInterface_corbaColInfoResponse = new _Marshaller_gsdlInterface_corbaColInfoResponse;
+    _marshaller_gsdlInterface_corbaDocRequest = new _Marshaller_gsdlInterface_corbaDocRequest;
+    _marshaller_gsdlInterface_corbaDocResponse = new _Marshaller_gsdlInterface_corbaDocResponse;
+    _marshaller_gsdlInterface_corbaFilterType = new _Marshaller_gsdlInterface_corbaFilterType;
+    _marshaller_gsdlInterface_corbaFilterRepeatable = new _Marshaller_gsdlInterface_corbaFilterRepeatable;
+    _marshaller_gsdlInterface_corbaFilterOption = new _Marshaller_gsdlInterface_corbaFilterOption;
+    _marshaller_gsdlInterface_corbaFilterOptionsResponse = new _Marshaller_gsdlInterface_corbaFilterOptionsResponse;
+    _marshaller_gsdlInterface_corbaOptionValue = new _Marshaller_gsdlInterface_corbaOptionValue;
+    _marshaller_gsdlInterface_corbaFilterRequest = new _Marshaller_gsdlInterface_corbaFilterRequest;
+    _marshaller_gsdlInterface_corbaTermInfo = new _Marshaller_gsdlInterface_corbaTermInfo;
+    _marshaller_gsdlInterface_corbaMetadataInfo = new _Marshaller_gsdlInterface_corbaMetadataInfo;
+    _marshaller_gsdlInterface_corbaMetadataInfo_map = new _Marshaller_gsdlInterface_corbaMetadataInfo_map;
+    _marshaller_gsdlInterface_corbaResultDocInfo = new _Marshaller_gsdlInterface_corbaResultDocInfo;
+    _marshaller_gsdlInterface_corbaIsApprox = new _Marshaller_gsdlInterface_corbaIsApprox;
+    _marshaller_gsdlInterface_corbaFilterResponse = new _Marshaller_gsdlInterface_corbaFilterResponse;
+    _marshaller_gsdlInterface_corbaiface = new _Marshaller_gsdlInterface_corbaiface;
+    _marshaller__seq_gsdlInterface_corbatext_t = new _Marshaller__seq_gsdlInterface_corbatext_t;
+    _marshaller__seq_gsdlInterface_corbaFilterOption = new _Marshaller__seq_gsdlInterface_corbaFilterOption;
+    _marshaller__seq_gsdlInterface_corbaOptionValue = new _Marshaller__seq_gsdlInterface_corbaOptionValue;
+    _marshaller__seq_gsdlInterface_corbaTermInfo = new _Marshaller__seq_gsdlInterface_corbaTermInfo;
+    _marshaller__seq_gsdlInterface_corbaMetadataInfo = new _Marshaller__seq_gsdlInterface_corbaMetadataInfo;
+    _marshaller__seq_gsdlInterface_corbaResultDocInfo = new _Marshaller__seq_gsdlInterface_corbaResultDocInfo;
+  }
+};
+
+static __tc_init_CORBAIFACE __init_CORBAIFACE;
+
Index: /gsdl/trunk/runtime-src/src/corba/corbaiface_skel.mpp
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbaiface_skel.mpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbaiface_skel.mpp	(revision 16571)
@@ -0,0 +1,274 @@
+/*
+ *  MICO --- a free CORBA implementation
+ *  Copyright (C) 1997-98 Kay Roemer & Arno Puder
+ *
+ *  This file was automatically generated. DO NOT EDIT!
+ */
+#include "corbaiface.h"
+
+//--------------------------------------------------------
+//  Implementation of skeletons
+//--------------------------------------------------------
+
+gsdlInterface::corbaiface_skel::corbaiface_skel( const CORBA::BOA::ReferenceData &_id )
+{
+  CORBA::ImplementationDef_var _impl =
+    _find_impl( "IDL:gsdlInterface/corbaiface:1.0", "corbaiface" );
+  assert( !CORBA::is_nil( _impl ) );
+  _create_ref( _id,
+    0,
+    _impl,
+    "IDL:gsdlInterface/corbaiface:1.0" );
+  register_dispatcher( new StaticInterfaceDispatcherWrapper<corbaiface_skel>( this ) );
+}
+
+gsdlInterface::corbaiface_skel::corbaiface_skel( CORBA::Object_ptr _obj )
+{
+  CORBA::ImplementationDef_var _impl =
+    _find_impl( "IDL:gsdlInterface/corbaiface:1.0", "corbaiface" );
+  assert( !CORBA::is_nil( _impl ) );
+  _restore_ref( _obj,
+    CORBA::BOA::ReferenceData(),
+    0,
+    _impl );
+  register_dispatcher( new StaticInterfaceDispatcherWrapper<corbaiface_skel>( this ) );
+}
+
+gsdlInterface::corbaiface_skel::~corbaiface_skel()
+{
+}
+
+bool gsdlInterface::corbaiface_skel::dispatch( CORBA::StaticServerRequest_ptr _req, CORBA::Environment & /*_env*/ )
+{
+  #ifdef HAVE_EXCEPTIONS
+  try {
+  #endif
+    switch (mico_string_hash (_req->op_name(), 17)) {
+    case 0:
+      if( strcmp( _req->op_name(), "collectionList" ) == 0 ) {
+        corbatext_tarray collist;
+        CORBA::StaticAny _collist( _marshaller__seq_gsdlInterface_corbatext_t, &collist );
+        corbaComError error;
+        CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+
+        _req->add_inout_arg( &_collist );
+        _req->add_inout_arg( &_error );
+
+        if( !_req->read_args() )
+          return true;
+
+        collectionList( collist, error );
+        _req->write_results();
+        return true;
+      }
+      break;
+    case 3:
+      if( strcmp( _req->op_name(), "ping" ) == 0 ) {
+        corbatext_t collection;
+        CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+        CORBA::Boolean wasSuccess;
+        CORBA::StaticAny _wasSuccess( CORBA::_stc_boolean, &wasSuccess );
+        corbaComError error;
+        CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+
+        _req->add_in_arg( &_collection );
+        _req->add_inout_arg( &_wasSuccess );
+        _req->add_inout_arg( &_error );
+
+        if( !_req->read_args() )
+          return true;
+
+        ping( collection, wasSuccess, error );
+        _req->write_results();
+        return true;
+      }
+      break;
+    case 7:
+      if( strcmp( _req->op_name(), "filter" ) == 0 ) {
+        corbatext_t collection;
+        CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+        corbaFilterRequest request;
+        CORBA::StaticAny _request( _marshaller_gsdlInterface_corbaFilterRequest, &request );
+        corbaFilterResponse response;
+        CORBA::StaticAny _response( _marshaller_gsdlInterface_corbaFilterResponse, &response );
+        corbaComError error;
+        CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+
+        _req->add_in_arg( &_collection );
+        _req->add_in_arg( &_request );
+        _req->add_inout_arg( &_response );
+        _req->add_inout_arg( &_error );
+
+        if( !_req->read_args() )
+          return true;
+
+        filter( collection, request, response, error );
+        _req->write_results();
+        return true;
+      }
+      break;
+    case 9:
+      if( strcmp( _req->op_name(), "getFilterOptions" ) == 0 ) {
+        corbatext_t collection;
+        CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+        corbatext_t option;
+        CORBA::StaticAny _option( _marshaller_gsdlInterface_corbatext_t, &option );
+        corbaFilterOptionsResponse response;
+        CORBA::StaticAny _response( _marshaller_gsdlInterface_corbaFilterOptionsResponse, &response );
+        corbaComError error;
+        CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+
+        _req->add_in_arg( &_collection );
+        _req->add_in_arg( &_option );
+        _req->add_inout_arg( &_response );
+        _req->add_inout_arg( &_error );
+
+        if( !_req->read_args() )
+          return true;
+
+        getFilterOptions( collection, option, response, error );
+        _req->write_results();
+        return true;
+      }
+      break;
+    case 10:
+      if( strcmp( _req->op_name(), "getCollectInfo" ) == 0 ) {
+        corbatext_t collection;
+        CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+        corbaColInfoResponse response;
+        CORBA::StaticAny _response( _marshaller_gsdlInterface_corbaColInfoResponse, &response );
+        corbaComError error;
+        CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+
+        _req->add_in_arg( &_collection );
+        _req->add_inout_arg( &_response );
+        _req->add_inout_arg( &_error );
+
+        if( !_req->read_args() )
+          return true;
+
+        getCollectInfo( collection, response, error );
+        _req->write_results();
+        return true;
+      }
+      break;
+    case 11:
+      if( strcmp( _req->op_name(), "initialise" ) == 0 ) {
+        corbaComError error;
+        CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+
+        CORBA::Boolean _res;
+        CORBA::StaticAny __res( CORBA::_stc_boolean, &_res );
+        _req->add_inout_arg( &_error );
+        _req->set_result( &__res );
+
+        if( !_req->read_args() )
+          return true;
+
+        _res = initialise( error );
+        _req->write_results();
+        return true;
+      }
+      if( strcmp( _req->op_name(), "getFilterInfo" ) == 0 ) {
+        corbatext_t collection;
+        CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+        corbatext_tarray filterNames;
+        CORBA::StaticAny _filterNames( _marshaller__seq_gsdlInterface_corbatext_t, &filterNames );
+        corbaComError error;
+        CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+
+        _req->add_in_arg( &_collection );
+        _req->add_inout_arg( &_filterNames );
+        _req->add_inout_arg( &_error );
+
+        if( !_req->read_args() )
+          return true;
+
+        getFilterInfo( collection, filterNames, error );
+        _req->write_results();
+        return true;
+      }
+      break;
+    case 12:
+      if( strcmp( _req->op_name(), "hasCollection" ) == 0 ) {
+        corbatext_t corbaCollection;
+        CORBA::StaticAny _corbaCollection( _marshaller_gsdlInterface_corbatext_t, &corbaCollection );
+        CORBA::Boolean has;
+        CORBA::StaticAny _has( CORBA::_stc_boolean, &has );
+        corbaComError error;
+        CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+
+        _req->add_in_arg( &_corbaCollection );
+        _req->add_inout_arg( &_has );
+        _req->add_inout_arg( &_error );
+
+        if( !_req->read_args() )
+          return true;
+
+        hasCollection( corbaCollection, has, error );
+        _req->write_results();
+        return true;
+      }
+      break;
+    case 13:
+      if( strcmp( _req->op_name(), "configure" ) == 0 ) {
+        corbatext_t key;
+        CORBA::StaticAny _key( _marshaller_gsdlInterface_corbatext_t, &key );
+        corbatext_tarray cfgline;
+        CORBA::StaticAny _cfgline( _marshaller__seq_gsdlInterface_corbatext_t, &cfgline );
+        corbaComError error;
+        CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+
+        _req->add_in_arg( &_key );
+        _req->add_in_arg( &_cfgline );
+        _req->add_inout_arg( &_error );
+
+        if( !_req->read_args() )
+          return true;
+
+        configure( key, cfgline, error );
+        _req->write_results();
+        return true;
+      }
+      if( strcmp( _req->op_name(), "getDocument" ) == 0 ) {
+        corbatext_t collection;
+        CORBA::StaticAny _collection( _marshaller_gsdlInterface_corbatext_t, &collection );
+        corbaDocRequest request;
+        CORBA::StaticAny _request( _marshaller_gsdlInterface_corbaDocRequest, &request );
+        corbaDocResponse response;
+        CORBA::StaticAny _response( _marshaller_gsdlInterface_corbaDocResponse, &response );
+        corbaComError error;
+        CORBA::StaticAny _error( _marshaller_gsdlInterface_corbaComError, &error );
+
+        _req->add_in_arg( &_collection );
+        _req->add_inout_arg( &_request );
+        _req->add_inout_arg( &_response );
+        _req->add_inout_arg( &_error );
+
+        if( !_req->read_args() )
+          return true;
+
+        getDocument( collection, request, response, error );
+        _req->write_results();
+        return true;
+      }
+      break;
+    }
+  #ifdef HAVE_EXCEPTIONS
+  } catch( CORBA::SystemException_catch &_ex ) {
+    _req->set_exception( _ex->_clone() );
+    _req->write_results();
+    return true;
+  } catch( ... ) {
+    assert( 0 );
+    return true;
+  }
+  #endif
+  return false;
+}
+
+gsdlInterface::corbaiface_ptr gsdlInterface::corbaiface_skel::_this()
+{
+  return gsdlInterface::corbaiface::_duplicate( this );
+}
+
Index: /gsdl/trunk/runtime-src/src/corba/corbaproto.h
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbaproto.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbaproto.h	(revision 16571)
@@ -0,0 +1,101 @@
+/**********************************************************************
+ *
+ * corbaproto.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef CORBAPROTO_H
+#define CORBAPROTO_H
+
+#include "gsdlconf.h"
+#include "collectserver.h"
+#include "recptproto.h"
+#include "corbaiface.h"
+using namespace gsdlInterface;
+
+class corbaproto : public recptproto {
+ private:
+  corbaiface_var getCorbaClient();
+ protected:
+  collectservermapclass cservers;
+  corbaiface_var        client;
+  CORBA::ORB_var        orb;
+  CORBA::BOA_var        boa;
+  CORBA::Object_var     obj;
+  text_t gsdlhome;
+  text_t site_name;
+
+ public:
+  virtual ~corbaproto() {}
+  corbaproto(char* site_name);
+
+  // add_collectserver should be called for each collection server
+  // before any configuration is done
+  void add_collectserver (collectserver *thecserver) 
+    {cservers.addcollectserver(thecserver);}
+
+  // this configure will configure each of the collection servers
+  void configure (const text_t &key, const text_tarray &cfgline, comerror_t &err);
+
+  // this init will init each of the collection servers
+  bool init (comerror_t &err,ostream &logout);
+
+  // used to check for icons and retrieve them from the collection
+  // site if they are missing
+  void  cache_missing_icons(text_tmap& format_map,
+			    text_t& httpdomain, 
+			    text_t& httpprefix);
+
+  text_t get_site_name (comerror_t &err);
+
+  text_t get_protocol_name (comerror_t &err);
+  void get_collection_list (text_tarray &collist, comerror_t &err, 
+			    ostream &logout);
+  void has_collection (const text_t &collection, bool &hascollection, 
+		       comerror_t &err, ostream &logout);
+  void ping (const text_t &collection, bool &wassuccess, 
+	     comerror_t &err, ostream &logout);
+  void get_collectinfo (const text_t &collection, 
+			ColInfoResponse_t &collectinfo,
+			comerror_t &err, ostream &logout);
+  void get_filterinfo (const text_t &collection,
+		       InfoFiltersResponse_t &response,
+		       comerror_t &err, ostream &logout);
+  void get_filteroptions (const text_t &collection,
+			  const InfoFilterOptionsRequest_t &request,
+			  InfoFilterOptionsResponse_t &response, 
+			  comerror_t &err, ostream &logout);
+  void filter (const text_t &collection,
+	       FilterRequest_t &request,
+	       FilterResponse_t &response,
+	       comerror_t &err, ostream &logout);
+
+  void get_document (const text_t &collection,
+		     const DocumentRequest_t &request,
+		     DocumentResponse_t &response,
+		     comerror_t &err, ostream &logout);
+
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/corba/corbaproto.mpp
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbaproto.mpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbaproto.mpp	(revision 16571)
@@ -0,0 +1,750 @@
+/**********************************************************************
+ *
+ * corbaproto.cpp -- 
+ * Copyright (C) 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+#include <iostream.h>
+#include <fstream.h>
+
+#include "fileutil.h"
+
+// protocol headers for CORBA
+#include "corbaiface.h"
+using namespace gsdlInterface;
+
+// greenstone library headers
+#include "corbaconv_text_t.h"
+
+// greenstone local headers
+#include "corbatext_t.h"
+
+#include "corbaproto.h"
+#include "colservrconfig.h"
+
+// default headers
+#include <assert.h>
+
+void corbatext_optionValueArrayToCorba(OptionValue_tarray array, corbaOptionValue_array &corba)
+{
+  unsigned int i = 0;
+  OptionValue_tarray::iterator here = array.begin();
+  OptionValue_tarray::iterator end = array.end();
+  
+  while (here != end)
+    {
+      corba.length(i+1);
+      
+      corbaconv_text_t::getCorbatext(here->name,corba[i].name);
+      corbaconv_text_t::getCorbatext(here->value,corba[i].value);
+
+      i ++;
+      here ++;
+    }
+  //  cout << "Options " << i << endl;
+}
+
+void corbaresponse_resultMetadataToCorba(MetadataInfo_t &meta, corbaMetadataInfo &corbaMeta)
+{
+  corbaconv_text_t::getCorbatext(meta.params,corbaMeta.params);
+  corbatext_arrayToCorbaArray(meta.values, &corbaMeta.values);
+  corbaMeta.isRef    = meta.isRef;
+}
+
+void corbaresponse_resultMetadataToC(const corbaMetadataInfo &corbaMeta, MetadataInfo_t &meta)
+{
+  corbaconv_text_t::setCorbatext(meta.params,corbaMeta.params);
+  corbatext_corbaArrayToArray(corbaMeta.values, &meta.values);
+  meta.isRef    = corbaMeta.isRef;
+}
+
+int corbaresponse_resultMetaParentToCorba(MetadataInfo_t *parent, corbaMetadataInfo_array &corbaparent)
+{
+  int reply = -1, pid = -1;
+
+  // extend for new parent
+  reply = corbaparent.length();
+  corbaparent.length(reply+1);
+
+  // copy content into new array element
+  corbaresponse_resultMetadataToCorba(*parent, corbaparent[reply]);
+
+  // deal with our own parent
+  if (parent->parent != NULL)
+    {
+      // get offset of new parent and extend parent vector
+
+      pid  = corbaresponse_resultMetaParentToCorba(parent->parent, corbaparent);
+    }
+  corbaparent[reply].parentid = pid;
+
+  // return the parent id from here
+  return reply;
+}
+
+MetadataInfo_t *corbaresponse_resultMetaParentToC(corbaMetadataInfo_array &corbaparent, int pid)
+{
+  MetadataInfo_t *reply;
+
+  reply = new MetadataInfo_t;
+
+  corbaresponse_resultMetadataToC(corbaparent[pid], *reply);
+
+  // deal with our own parent
+  if (corbaparent[pid].parentid >= 0)
+    {
+      // get offset of new parent and extend parent vector
+
+      reply->parent = corbaresponse_resultMetaParentToC(corbaparent, corbaparent[pid].parentid);
+    }
+  else
+    {
+      reply->parent = NULL;
+    }
+
+  // return the parent id from here
+  return reply;
+}
+
+void corbaresponse_resultDocInfoToCorba(ResultDocInfo_tarray docinfo, corbaResultDocInfo_array &corbainfo)
+{
+  ResultDocInfo_tarray::iterator here = docinfo.begin();
+  ResultDocInfo_tarray::iterator end  = docinfo.end();
+  unsigned int i;
+
+  i = 0;
+  while (here != end)
+    {
+      corbainfo.length(i+1);
+
+      // copy the easy bits
+      corbaconv_text_t::getCorbatext(here->OID,corbainfo[i].OID);
+
+      corbainfo[i].resultNum     = here->result_num;
+      corbainfo[i].ranking       = here->ranking;
+      corbainfo[i].termsMatched  = here->num_terms_matched;
+      corbainfo[i].phraseMatched = here->num_phrase_match;
+
+      // copy the docFreq array
+      vector<int>::iterator fhere = here->docFreq.begin();
+      vector<int>::iterator fend  = here->docFreq.end();
+      unsigned int          fi = 0;
+
+      while (fhere != fend)
+	{
+	  corbainfo[i].docFreq.length(fi+1);
+
+	  corbainfo[i].docFreq[fi] = *fhere;
+
+	  fhere ++;
+	  fi ++;
+	}
+
+      // copy the MetadataInfo map
+      MetadataInfo_tmap::iterator mhere = here->metadata.begin();
+      MetadataInfo_tmap::iterator mend  = here->metadata.end();
+      unsigned int mi = 0;
+
+      while (mhere != mend)
+	{
+	  corbainfo[i].metadata.names.length(mi+1);
+	  corbainfo[i].metadata.values.length(mi+1);
+	  
+	  // copy name
+	  corbaconv_text_t::getCorbatext((*mhere).first,corbainfo[i].metadata.names[mi]);
+
+	  // copy metadata
+	  corbaresponse_resultMetadataToCorba((*mhere).second, corbainfo[i].metadata.values[mi]);
+	  if (mhere->second.parent != NULL)
+	    {
+	      int pid;
+
+	      pid = corbaresponse_resultMetaParentToCorba(mhere->second.parent, 
+							      corbainfo[i].metaparents);
+	      corbainfo[i].metadata.values[mi].parentid = pid;
+	    }
+	  else
+	    {
+	      corbainfo[i].metadata.values[mi].parentid = -1;
+	    }
+
+	  cout << "Parent " << mi << " " << (int) &mhere->second << " " << (int) mhere->second.parent << endl;
+
+	  mhere ++;
+	  mi ++;
+	}
+
+      // Copy the classifier variables
+      corbaconv_text_t::getCorbatext(here->classifier_metadata_type, corbainfo[i].classifierMetadataType);
+      corbainfo[i].classifierMetadataOffset = here->classifier_metadata_offset;
+
+      // Get next Docinfo item
+      i++;
+      here ++;
+    }
+}
+
+void corbaresponse_resultDocInfoToC(corbaResultDocInfo_array corbainfo, ResultDocInfo_tarray &docinfo)
+{
+  unsigned int i;
+  ResultDocInfo_t doc;
+
+  for (i = 0; i < corbainfo.length(); i++)
+    {
+      corbaconv_text_t::setCorbatext(doc.OID,corbainfo[i].OID);
+      doc.result_num        = corbainfo[i].resultNum;
+      doc.ranking           = corbainfo[i].ranking;
+      doc.num_terms_matched = corbainfo[i].termsMatched;
+      doc.num_phrase_match  = corbainfo[i].phraseMatched;
+
+      // copy the doc freq array
+      unsigned int fi;
+      for (fi = 0; fi < corbainfo[i].docFreq.length(); fi ++)
+	{
+	  doc.docFreq.push_back(corbainfo[i].docFreq[fi]);
+	}
+
+      // copy the MetadataInfomap
+      unsigned int   mi;
+      text_t         mname;
+      MetadataInfo_t mdata;
+      
+      doc.metadata.clear();
+      for (mi = 0; mi < corbainfo[i].metadata.names.length(); mi ++)
+	{
+	  // get name
+	  corbaconv_text_t::setCorbatext(mname,corbainfo[i].metadata.names[mi]);
+
+	  // get metadata
+	  corbaresponse_resultMetadataToC(corbainfo[i].metadata.values[mi], mdata);
+
+	  if (corbainfo[i].metadata.values[mi].parentid >= 0)
+	    {
+	      mdata.parent = 
+		corbaresponse_resultMetaParentToC(corbainfo[i].metaparents, 
+						  corbainfo[i].metadata.values[mi].parentid);	      
+	    }
+	 
+	  doc.metadata.insert(make_pair(mname, mdata));
+	}
+
+      // GRB: sort out parent data
+      for (mi = 0; mi < corbainfo[i].metadata.names.length(); mi ++)
+	{
+	  if (corbainfo[i].metadata.values[mi].parentid != 0)
+	    { 
+	      int pi;
+
+	      for (pi = 0; pi < corbainfo[i].metadata.names.length(); pi ++)
+		{
+		  if (pi != mi &&
+		      corbainfo[i].metadata.values[mi].parentid ==
+		      corbainfo[i].metadata.values[pi].id)
+		    {
+		      doc.metadata[mi].parent = &doc.metadata[pi];
+		    }
+		}
+	    }
+	}
+      //      doc.metadata
+
+      // convert metadata classifer information
+      corbaconv_text_t::setCorbatext(doc.classifier_metadata_type,corbainfo[i].classifierMetadataType);
+      doc.classifier_metadata_offset = corbainfo[i].classifierMetadataOffset;
+
+      docinfo.push_back(doc); 
+    }
+}
+
+
+// Added 31/1/2001, Michael Dewsnip
+void corbaresponse_resultTermInfoToC(corbaTermInfo_array corbainfo, TermInfo_tarray &terminfo)
+{
+  TermInfo_t ti;
+
+  for (unsigned int i = 0; i < corbainfo.length(); i++) {
+    corbaconv_text_t::setCorbatext(ti.term, corbainfo[i].term);
+    ti.freq = corbainfo[i].frequency;
+
+    for (unsigned int j = 0; j < corbainfo[i].matchTerms.length(); j++) {
+      text_t mt;
+      corbaconv_text_t::setCorbatext(mt, corbainfo[i].matchTerms[j]);
+
+      ti.matchTerms.push_back(mt);
+    }
+
+    terminfo.push_back(ti);
+  }
+}
+
+
+corbaproto::corbaproto(char* _site_name)
+{ char *dummyv[1] = {""};
+  int   dummyc = 0;
+  // CORBA variables
+  /* static CORBA::ORB_var orb = CORBA::ORB_init( dummyc , dummyv, "mico-local-orb" );
+     static CORBA::BOA_var boa = orb->BOA_init( dummyc , dummyv, "mico-local-boa" ); */
+
+  CORBA::ORB_var orb = CORBA::ORB_init( dummyc , dummyv, "mico-local-orb" );
+  CORBA::BOA_var boa = orb->BOA_init( dummyc , dummyv, "mico-local-boa" );
+
+  char objid_filename[256];
+  sprintf(objid_filename,"/tmp/%s.objid",_site_name);
+
+  // Get ref from "naming service"
+  ifstream in (objid_filename);
+  char ref[1000];
+  in >> ref;
+  in.close ();
+
+  // startup corba
+  // static CORBA::Object_var obj = orb->string_to_object (ref);
+  CORBA::Object_var obj = orb->string_to_object (ref);
+
+  client = corbaiface::_narrow( obj ); 
+  // client = NULL; // ****
+
+  gsdlhome.clear();
+  site_name = _site_name;
+}
+
+corbaiface_var corbaproto::getCorbaClient()
+{
+  // This function was written to help corba when ORB and BOA were
+  // not working in "persistent" mode.
+  // Now that persistent mode is working it is not longer needed/used.
+
+  char *dummyv[1] = {""};
+  int   dummyc = 0;
+  // CORBA variables
+//  static CORBA::ORB_var orb = CORBA::ORB_init( dummyc , dummyv, "mico-local-orb" );
+//  static CORBA::BOA_var boa = orb->BOA_init( dummyc , dummyv, "mico-local-boa" );
+
+  // DB // Try this out!! // ****
+  CORBA::ORB_var orb = CORBA::ORB_init( dummyc , dummyv, "mico-local-orb" );
+  CORBA::BOA_var boa = orb->BOA_init( dummyc , dummyv, "mico-local-boa" );
+
+  /*  char* site_name_chars = site_name.getcstr();
+  char objid_filename[256];
+  sprintf(objid_filename,"/tmp/%s.objid",site_name_chars);
+  // delete site_name_chars; */
+
+  text_t objid_filename = "/tmp/" + site_name + ".objid";
+
+  // Get ref from "naming service"
+  ifstream in (objid_filename.getcstr());
+  char ref[1000];
+  in >> ref;
+  in.close ();
+
+  // startup corba
+  // DB // Try this out!! // ****
+  // static CORBA::Object_var obj = orb->string_to_object (ref);
+  CORBA::Object_var obj = orb->string_to_object (ref);
+
+  return corbaiface::_narrow( obj );
+}
+
+
+// this configure will configure each of the collection servers
+void corbaproto::configure (const text_t &key, const text_tarray &cfgline,
+			    comerror_t &err) {
+  // the naming of the collection should not be done here,
+  // it should be done just after the collection server has been 
+  // created
+
+  // cout << "Corbaproto::Configure" << endl;
+  corbatext_t      corbaKey;
+  corbatext_tarray corbaCfgline;
+  gsdlInterface::corbaComError error = corbaNoError;
+
+  // get the corba client reference
+  // corbaiface_var lclient = this->getCorbaClient(); // ****
+  corbaiface_var lclient = client;
+
+  // convert all the requisite structures into their CORBA form
+  corbaconv_text_t::getCorbatext(key,corbaKey);
+  corbatext_arrayToCorbaArray(cfgline, &corbaCfgline);
+
+  // execute the corba transaction
+  lclient->configure(corbaKey, corbaCfgline, error);    
+
+  if (key=="gsdlhome")
+    {
+      // store gsdlhome in corba prototype so it can be used later to
+      // check if icons specified in format statements exist on the
+      // recptionist's side
+      gsdlhome = cfgline[0];
+    }
+  err = (comerror_t) error;
+}
+
+// this init will configure and init each of the collection servers
+bool corbaproto::init (comerror_t &err, ostream &logout) {
+//  cout << "Corbaproto::Init" << endl;
+  gsdlInterface::corbaComError error = corbaNoError;
+
+  // get the corba client reference
+  // corbaiface_var lclient = this->getCorbaClient(); // ****
+  corbaiface_var lclient = client;
+
+  // execute the corba transaction
+  return lclient->initialise(error);
+}
+
+void  corbaproto::cache_missing_icons(text_tmap& format_map,
+				      text_t& httpdomain, 
+				      text_t& httpprefix)
+{
+  // consider making this a member function in the object?
+
+  text_tmap::iterator format_here = format_map.begin();
+  text_tmap::iterator format_end = format_map.end();
+  while (format_here!=format_end)
+    {
+      text_t format_line = format_here->second;
+
+      // cout << "*** format line = " << format_line << endl; // ****
+
+      text_t::iterator fl_begin = format_line.begin();
+      text_t::iterator fl_end = format_line.end();
+
+      text_t::iterator httpimg_find = findword(fl_begin,fl_end,"_httpimg_");
+      text_t::iterator http_find = httpimg_find;
+
+      while (httpimg_find!=fl_end)
+	{
+	  http_find = httpimg_find+5;
+	  httpimg_find += 9;
+
+	  // look for white space " or >
+	  text_t::iterator filename_end = httpimg_find;
+	  while (filename_end != fl_end)
+	    {
+	      if (*filename_end == ' ') break;
+	      if (*filename_end == '\t') break;
+	      if (*filename_end == '\"') break;
+	      if (*filename_end == '>') break;
+	      filename_end++;
+	    }
+
+	  text_t img_filename = substr(httpimg_find,filename_end);
+
+	  text_t site_img_filename = filename_cat(gsdlhome,"images",img_filename);
+
+	  // look to see if img filename exists in images directory
+	  if (!file_exists(site_img_filename))
+	    {
+	      text_t cache_img_dir
+		= filename_cat(gsdlhome,"images",".cache");
+
+	      text_t remote_img_url = "http://" + httpdomain + httpprefix
+		+ "/images" + img_filename;
+
+	      text_t wget_cmd = "wget -q -N --directory-prefix="+cache_img_dir
+		+ " " + remote_img_url;
+
+	      char* wget_cmd_chars = wget_cmd.getcstr();
+
+	      system(wget_cmd_chars);
+	      delete wget_cmd_chars;
+
+	      format_map[format_here->first] 
+		= substr(fl_begin,http_find) + "cache" + substr(http_find,fl_end);
+
+	    }
+
+	  httpimg_find = findword(httpimg_find,fl_end,"_httpimg_");
+	}
+      format_here++;
+    }
+}
+
+text_t corbaproto::get_site_name (comerror_t &err) {
+  return site_name;
+}
+
+text_t corbaproto::get_protocol_name (comerror_t &err) {
+  return "corbaproto";
+}
+
+
+void corbaproto::get_collection_list (text_tarray &collist, comerror_t &err, 
+				     ostream &/*logout*/) {
+
+  // cout << "Corbaproto::Collection list" << endl;
+
+  corbatext_tarray corba_collist;
+  text_tarray      tcollist;
+  gsdlInterface::corbaComError error = corbaNoError;
+
+  // get the corba client reference
+  // corbaiface_var lclient = this->getCorbaClient(); // ****
+  corbaiface_var lclient = client;
+
+  // execute the corba transaction
+  lclient->collectionList(corba_collist,error);
+
+  // convert the response back to normal form
+  corbatext_corbaArrayToArray(corba_collist, &tcollist);
+  collist = tcollist;
+
+  err = (comerror_t) error;
+}
+
+void corbaproto::has_collection (const text_t &collection, bool &hascollection, 
+				comerror_t &err, ostream &/*logout*/) {
+  // cout << "Corbaproto::Has collection" << endl;
+
+  corbatext_t     corbaCollection;
+  corbaComError corbaError = corbaNoError;
+  CORBA::Boolean corbaHas;
+
+  // get the corba client reference
+  // corbaiface_var lclient = this->getCorbaClient(); // ****
+  corbaiface_var lclient = client;
+
+  // convert all the requisite structures into their CORBA form
+  corbaconv_text_t::getCorbatext(collection,corbaCollection);
+  
+  // execute the corba transaction
+  lclient->hasCollection(corbaCollection, corbaHas, corbaError);
+
+  // convert the response back to normal form
+  hascollection = (corbaHas != 0);
+  err = noError;
+}
+
+void corbaproto::ping (const text_t &collection, bool &wassuccess, 
+		      comerror_t &err, ostream &/*logout*/) {
+  // cout << "Corbaproto::Ping" << endl;
+
+  corbatext_t corbaCollect;
+  corbaComError corbaError = corbaNoError;
+  CORBA::Boolean success;
+
+  // get the corba client reference
+  // corbaiface_var lclient = this->getCorbaClient(); // ****
+  corbaiface_var lclient = client;
+
+  // convert all the requisite structures into their CORBA form
+  corbaconv_text_t::getCorbatext(collection,corbaCollect);
+
+  // execute the corba transaction
+  lclient->ping(corbaCollect, success, corbaError);
+  
+  // convert the response back to normal form
+  wassuccess = (success != 0);
+  err = (comerror_t) corbaError;  
+  cout << "Corbaproto::Ping" << err << endl;
+}
+
+
+void corbaproto::get_collectinfo (const text_t &collection, 
+				 ColInfoResponse_t &collectinfo,
+				 comerror_t &err, ostream &logout) {
+  //  cout << "Corbaproto::Collectinfo" << endl;
+
+  corbatext_t          corbaCollection;
+  corbaComError        corbaError = corbaNoError;
+  corbaColInfoResponse corbaCollectInfo;
+
+  // get the corba client reference
+  // corbaiface_var lclient = this->getCorbaClient(); // ****
+  corbaiface_var lclient = client;
+
+  // convert all the requisite structures into their CORBA form
+  corbaconv_text_t::getCorbatext(collection,corbaCollection);
+
+  // execute the corba transaction
+  lclient->getCollectInfo(corbaCollection, corbaCollectInfo, corbaError);
+
+  // convert the response back to normal form
+  collectinfo.useBook = corbaCollectInfo.useBook;
+  collectinfo.isPublic = corbaCollectInfo.isPublic;
+  collectinfo.isBeta   = corbaCollectInfo.isBeta;
+  collectinfo.buildDate = corbaCollectInfo.buildDate;
+  corbatext_corbaArrayToArray(corbaCollectInfo.ccsCols, &collectinfo.ccsCols);
+  corbatext_corbaArrayToArray(corbaCollectInfo.languages, &collectinfo.languages);
+  collectinfo.numDocs   = corbaCollectInfo.numDocs;
+  collectinfo.numWords  = corbaCollectInfo.numWords;
+  collectinfo.numBytes  = corbaCollectInfo.numBytes;
+  corbatext_corbaMapToMap(corbaCollectInfo.collectionMeta, collectinfo.collectionmeta);
+  corbatext_corbaMapToMap(corbaCollectInfo.format, collectinfo.format);
+  corbatext_corbaMapToMap(corbaCollectInfo.building, collectinfo.building);
+  corbaconv_text_t::setCorbatext(collectinfo.httpdomain,corbaCollectInfo.httpdomain);
+  corbaconv_text_t::setCorbatext(collectinfo.httpprefix,corbaCollectInfo.httpprefix);
+  corbaconv_text_t::setCorbatext(collectinfo.receptionist,corbaCollectInfo.receptionist);
+
+  cache_missing_icons(collectinfo.format,collectinfo.httpdomain,
+		      collectinfo.httpprefix);
+
+  err = (comerror_t) corbaError;  
+}
+
+
+void corbaproto::get_filterinfo (const text_t &collection,
+				InfoFiltersResponse_t &response,
+				comerror_t &err, ostream &logout) {
+  //  cout << "Corbaproto::Filterinfo" << endl;
+
+  corbatext_t corbaCollection;
+  corbatext_tset corbaResponse;
+  corbaComError corbaError = corbaNoError;
+  
+  // get the corba client reference
+  // corbaiface_var lclient = this->getCorbaClient(); // ****
+  corbaiface_var lclient = client;
+
+  // convert all the requisite structures into their CORBA form
+  corbaconv_text_t::getCorbatext(collection,corbaCollection);
+
+  // execute the corba transaction
+  lclient->getFilterInfo(corbaCollection, corbaResponse, corbaError);
+
+  // convert the response back to normal form
+  corbatext_corbaArrayToSet(corbaResponse, &response.filterNames);
+
+  err = (comerror_t) corbaError;
+}
+
+void corbaproto::get_filteroptions (const text_t &collection,
+				   const InfoFilterOptionsRequest_t &request,
+				   InfoFilterOptionsResponse_t &response, 
+				   comerror_t &err, ostream &logout) {
+  //  cout << "Corbaproto::Filteroptions" << endl;
+
+  corbatext_t corbaCollection;
+  corbatext_t filterName;
+  corbaFilterOptionsResponse corbaResponse;
+  corbaComError corbaError = corbaNoError;
+  unsigned int i;
+  corbaconv_text_t *cc_name;
+  FilterOption_t *option;
+
+  // get the corba client reference
+  // corbaiface_var lclient = this->getCorbaClient(); // ****
+  corbaiface_var lclient = client;
+
+  // convert all the requisite structures into their CORBA form
+  corbaconv_text_t::getCorbatext(collection,corbaCollection);
+  corbaconv_text_t::getCorbatext(request.filterName,filterName);
+
+  // execute the corba transaction
+  lclient->getFilterOptions(corbaCollection, filterName, corbaResponse, corbaError);
+
+  // convert the response back to normal form
+  for (i = 0; i < corbaResponse.names.length(); i ++)
+    {
+      cc_name = new corbaconv_text_t(corbaResponse.names[i]);
+
+      option = new FilterOption_t;
+      corbaconv_text_t::setCorbatext(option->name,corbaResponse.options[i].name);
+      option->type = (FilterOption_t::type_t) corbaResponse.options[i].type;
+      option->repeatable = (FilterOption_t::repeatable_t) corbaResponse.options[i].repeatable;
+      corbaconv_text_t::setCorbatext(option->defaultValue,corbaResponse.options[i].defaultValue);
+      corbatext_corbaArrayToArray(corbaResponse.options[i].validValues, &option->validValues);
+
+      response.filterOptions.insert(make_pair(*cc_name, *option)); // typecast to text_t
+    }
+
+  err =  (comerror_t) corbaError;
+}
+
+
+void corbaproto::filter (const text_t &collection,
+			  FilterRequest_t &request,
+			  FilterResponse_t &response,
+			  comerror_t &err, ostream &logout) {
+  //  cout << "Corbaproto::Filter" << endl;
+
+  corbaFilterRequest corbaRequest;
+  corbaFilterResponse corbaResponse;
+  corbatext_t     corbaCollection;
+  corbaComError corbaError = corbaNoError;
+
+  // get the corba client reference
+  // corbaiface_var lclient = this->getCorbaClient(); // ****
+  corbaiface_var lclient = client;
+
+  // convert all the requisite structures into their CORBA form
+  corbaconv_text_t::getCorbatext(collection,corbaCollection);
+  corbaconv_text_t::getCorbatext(request.filterName,corbaRequest.filter);
+  corbatext_optionValueArrayToCorba(request.filterOptions, corbaRequest.filterOptions);
+  corbatext_arrayToCorbaArray(request.docSet, &corbaRequest.docSet);
+  corbaRequest.filterResultOptions = request.filterResultOptions;
+  corbaconv_text_t::getCorbatext(request.requestParams,corbaRequest.requestParams);
+  corbaconv_text_t::getCorbatext(request.refParams,corbaRequest.refParams);
+  corbaRequest.getParents = request.getParents;
+  corbatext_setToCorbaArray(request.fields, &corbaRequest.fields);
+
+  corbaResponse.numDocs = response.numDocs;
+  corbaresponse_resultDocInfoToCorba(response.docInfo, corbaResponse.docInfo);
+
+  // execute the corba transaction
+  lclient->filter (corbaCollection, corbaRequest, corbaResponse, corbaError);
+
+  // convert the response back to normal form
+  response.numDocs = corbaResponse.numDocs;
+  response.isApprox = (enum isapprox) corbaResponse.isApprox;
+  corbaresponse_resultDocInfoToC(corbaResponse.docInfo, response.docInfo);
+
+  // Added 31/1/2001, Michael Dewsnip
+  corbaresponse_resultTermInfoToC(corbaResponse.termInfo, response.termInfo);
+
+  err = (comerror_t) corbaError;
+  //  cout << "Corbaproto::Filter" << endl;
+}
+
+
+void corbaproto::get_document (const text_t &collection,
+			       const DocumentRequest_t &request,
+			       DocumentResponse_t &response,
+			       comerror_t &err, ostream &logout) {
+  //  cout << "Corbaproto::Get Document" << endl;
+
+  corbatext_t      corbaCollect;
+  corbaDocRequest  corbaRequest;
+  corbaDocResponse corbaResponse;
+  corbaComError    corbaError = corbaNoError;
+
+  // get the corba client reference
+  // corbaiface_var lclient = this->getCorbaClient(); // ****
+  corbaiface_var lclient = client;
+
+  // convert all the requisite structures into their CORBA form
+  corbaconv_text_t::getCorbatext(collection,corbaCollect);
+  corbaconv_text_t::getCorbatext(request.OID,corbaRequest.OID);
+  corbaconv_text_t::getCorbatext(request.docType,corbaRequest.docType);
+  corbaconv_text_t::getCorbatext(request.docFormat,corbaRequest.docFormat);
+
+  // execute the corba transaction
+  lclient->getDocument(corbaCollect, corbaRequest, corbaResponse, corbaError);
+
+  // convert the response back to normal form
+  corbaconv_text_t::setCorbatext(response.doc,corbaResponse.doc);
+
+  err = (comerror_t) corbaError;
+}
+
Index: /gsdl/trunk/runtime-src/src/corba/corbatext_t.h
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbatext_t.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbatext_t.h	(revision 16571)
@@ -0,0 +1,13 @@
+void corbatext_fillChar(corbatext_t *t, char *text);
+void corbatext_usvector(corbatext_t t, vector<unsigned short>& us);
+char *corbatext_string(corbatext_t t);
+#ifdef TEXT_T_H
+void corbatext_arrayToCorbaArray(text_tarray t, corbatext_tarray *ca);
+void corbatext_corbaArrayToArray(corbatext_tarray ca, text_tarray *ta);
+void corbatext_mapToCorbaMap(text_tmap tm, corbatext_tmap *cm);
+void corbatext_corbaMapToMap(corbatext_tmap cm, text_tmap &tm);
+void corbatext_setToCorbaArray(text_tset set, corbatext_tset *cset);
+void corbatext_corbaArrayToSet(corbatext_tset cset, text_tset *set);
+corbatext_t_var corbatext_corbatext(text_t t);
+int corbatext_corbatext(text_t t, corbatext_t_var ct);
+#endif
Index: /gsdl/trunk/runtime-src/src/corba/corbatext_t.mpp
===================================================================
--- /gsdl/trunk/runtime-src/src/corba/corbatext_t.mpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/corba/corbatext_t.mpp	(revision 16571)
@@ -0,0 +1,179 @@
+// standard headers
+#if defined(GSDL_USE_STL_H)
+#include <iostream.h>
+#include <fstream.h>
+#include <vector.h>
+#else
+#include <iostream>
+#include <fstream>
+#include <vector>
+#endif
+
+// protocol headers
+#include "corbaiface.h"
+using namespace gsdlInterface;
+
+// greenstone headers
+#include "corbaconv_text_t.h"
+
+//local headers
+#include "corbatext_t.h"
+
+void corbatext_fillChar(corbatext_t *t, char *text)
+{
+  unsigned int i;
+
+  t->text.length(0);
+  if (text == NULL)
+      {
+	  return;
+      }
+  for (i = 0; i < strlen(text); i ++)
+      {
+	  t->text[i] = text[i];
+      }  
+  t->encoding = 0;
+}
+
+void corbatext_usvector(corbatext_t t, usvector& us)
+{
+  unsigned int i;
+
+  for (i = 0; i < t.text.length(); i ++)
+    {
+      us.push_back(t.text[i]);
+    }
+}
+
+char *corbatext_string(corbatext_t t)
+{ 
+  char *lcopy;
+  unsigned int i;
+    lcopy = (char *) malloc(t.text.length() + 1);
+    for (i = 0; i < t.text.length(); i ++)
+    {
+      lcopy[i] = (char) t.text[i];
+    }
+    lcopy[i] = '\0';
+    return lcopy;
+}
+
+corbatext_t_var corbatext_corbatext(text_t t)
+{ corbatext_t_var ct;
+// usString_var    us;
+
+  // cout << "Making text\n";
+  ct = new corbatext_t;
+  //  ct->text.length(20);
+  // us = new usString(20);
+  //  cout << ct->text.length() << endl;
+  //  cout << ct->text.maximum() << endl;
+  corbaconv_text_t::fillUsString(t,&ct->text);
+  //t.fillUsString(us);
+  // delete us;
+  // cout << "Encoding text\n";
+  ct->encoding = 0;
+  // cout << "Encoding text\n";
+  return ct;
+}
+
+int corbatext_corbatext(text_t t, corbatext_t_var ct)
+{
+  cout << "A" << endl;
+  corbaconv_text_t::fillUsString(t,&ct->text);
+  cout << "B" << endl;
+  ct->encoding = 0;
+  cout << "C" << endl;
+}
+
+void corbatext_corbaArrayToArray(corbatext_tarray ca, text_tarray *ta)
+{
+  unsigned int i;
+  corbaconv_text_t *cct;
+
+  ta->clear();
+  ta->reserve(ca.length());
+  for (i = 0; i < ca.length(); i ++)
+    {
+      cct = new corbaconv_text_t(ca[i]);
+      ta->push_back(*cct); // cast to text_t
+    }  
+}
+
+void corbatext_arrayToCorbaArray(text_tarray ta, corbatext_tarray *_ca)
+{
+  text_tarray::iterator here = ta.begin();
+  text_tarray::iterator end = ta.end();
+  corbatext_tarray ca(end - here);
+  unsigned int i;
+
+  i = 0;
+  (*_ca).length(end - here);
+
+  while (here != end)
+    {
+      corbatext_t_var ptr;
+      //      cout << "Array: " << (*_ca).maximum() << " " << (*_ca).length() << endl;
+      ptr = corbatext_corbatext(*here);
+      (*_ca)[i] = ptr;
+      here ++;
+      i++;      
+    }
+}
+
+void corbatext_corbaArrayToSet(corbatext_tarray t, text_tset *ts)
+{ unsigned int i;
+ 
+  for (i = 0; i < t.length(); i ++)
+    {
+      ts->insert((corbaconv_text_t) t[i]); // further typecast to text_t
+    } 
+
+  return;
+}
+
+void corbatext_setToCorbaArray(text_tset ts, corbatext_tarray *t)
+{
+  corbatext_t str;
+  text_tset::iterator here = ts.begin();
+  text_tset::iterator end = ts.end();
+  unsigned int i;
+
+  i = 0;
+  while (here != end)
+    {
+      (*t).length(i+1);
+      (*t)[i] = *corbatext_corbatext(*here);
+      here ++;
+      i ++;
+    }
+}
+
+void corbatext_mapToCorbaMap(text_tmap map, corbatext_tmap *cmap)
+{
+  text_tmap::iterator here = map.begin();
+  text_tmap::iterator end  = map.end();
+  unsigned int i = 0;
+
+  while (here != end)
+    {
+      (*cmap).names.length(i+1);
+      (*cmap).values.length(i+1);
+      cmap->names[i] = *corbatext_corbatext((*here).first);
+      cmap->values[i] = *corbatext_corbatext((*here).second);
+      here ++;
+      i ++;
+    }
+}
+
+void corbatext_corbaMapToMap(corbatext_tmap cmap, text_tmap &map)
+{
+  unsigned int i;
+
+  for (i = 0; i < cmap.names.length(); i ++)
+    {
+      map.insert(make_pair(*(new corbaconv_text_t(cmap.names[i])), 
+                           *(new corbaconv_text_t(cmap.values[i])))); // further typecast to text_t
+    }
+}
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/CURL.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/CURL.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/CURL.java	(revision 16571)
@@ -0,0 +1,677 @@
+package org.nzdl.gsdl.GsdlCollageApplet;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+/** Examines html pages and extracts all the images and links */
+public class CURL {
+
+    private boolean url_valid = true;
+    private InputStream input = null;
+    private int peek_value = -1;
+    private String buffer = "";
+    private URL url = null;
+    private Vector href_links = null;
+    private Vector src_links = null;
+    private Vector link_links = null;
+    private Vector background_links = null;
+
+    /** Starts processing the given url for images and links
+     *  @param url_str The url to examine */
+    public CURL(String url_str) {
+	href_links = new Vector();
+	src_links = new Vector();
+	link_links = new Vector();
+	background_links = new Vector();
+
+	try {
+	     url = new URL(url_str);
+	     input = url.openStream();
+	     //  int value = 0;
+
+	     //            while ( (value=input.read())!=-1){
+	     //System.err.print((char)value);
+	     //}
+             
+	     //url = new URL(url_str);
+	     //input = url.openStream(); 
+
+	} 
+	catch (MalformedURLException e) {
+          
+	    url_valid = false;
+	} 
+	catch (IOException e) {
+	 
+	    url_valid = false;
+	}
+    }
+
+    /** Checks that a valid connection to the url has been made */
+    public boolean connected_ok()
+    {
+	return url_valid;
+    }
+
+    /** Gets any href links from this url
+     *  @return Vector of href links */
+    public Vector getHrefLinks() {
+	return href_links;
+    }
+    /** Gets any source links from this url
+     *  @return Vector of source links */
+    public Vector getSrcLinks() {
+	return src_links;
+    }
+    /** Gets any other links from this url
+     *  @return Vector of other links */
+    public Vector getLinkLinks() {
+	return link_links;
+    }
+    /** Gets any background links from this url
+     *  @return Vector of background links */
+    public Vector getBackgroundLinks() {
+	return background_links;
+    }
+    
+    /** Gets the url currently being processed */
+    public URL getURL() {
+	return url;
+    }
+    /** Checks that the content of the url is in html */
+    public boolean isHTML() {
+
+         String content_type = guessContentType(url.toString());
+   
+	if(content_type.startsWith("text/html")) {
+	    return true;
+	}
+	return false;
+    }
+    
+    /** Reads a value from the buffer
+     *  @return Value read if successful and -1 if not */
+    public int read() {
+	int value = -1;
+	if(isHTML()) {
+	    if(buffer.length() == 0) {
+		refill();
+	    }
+	    if(buffer.length() != 0) {
+		value = getBuffer();
+	    }
+	} else {
+	    value = getRaw();
+	}
+	return value;
+    }
+    /** Reads the entire URL */
+    public void readAll() {
+	int value;
+	while((value = read()) != -1) {
+	}
+    }
+    
+    // Gets the head of the buffered buffer.
+    private int getBuffer() {
+	if(buffer.length() > 0) {
+	    int value = buffer.charAt(0);
+	    buffer = buffer.substring(1, buffer.length());
+	    return value;
+	} else {
+	    System.err.println("Called getRaw on an empty string");
+	    return -1;
+	}
+    }
+    // Gets the head of the raw buffer.
+    private int getRaw() {
+	int value = -1;
+	if(peek_value != -1) {
+	    value = peek_value;
+	    peek_value = -1;
+	} 
+	else {
+	    try {
+		value = input.read();
+	    } catch (Exception e) {
+		e.printStackTrace();
+	    }
+	}
+	return value;
+    }
+    
+    private int peekRaw() {
+	if(peek_value == -1) {
+	    peek_value = getRaw();
+	}
+	return peek_value;
+    }
+    
+    // Refills the buffered buffer with the next tag or non-tag block
+    // The tag is checked for urls. Note a tag is taken to be < .. > or
+    // < .. < so comments are supported, but comment blocks are still
+    // scanned.
+    private void refill() {
+	int value = getRaw();
+	if(value != -1) {
+           
+	    if(value == '<') {
+		//System.err.println("Parsing a tag starting " + (char)value);
+		// Add opening < to buffer
+		setBuffer(value);
+		String tag = "";
+		value = getRaw();
+		while(value != -1 && peekRaw() != '<' && value != '>') {
+		    //System.err.print((char)value);
+		    tag = tag + (char) value;
+		    value = getRaw();
+		}
+	
+		//System.err.println("Read a " + (char)value);
+		//tag = smartLower(tag);
+		//System.err.println("tag "+tag);
+                tag = findURL(tag);
+		buffer = buffer + tag;
+		// Add closing > to buffer
+		setBuffer(value);
+		//System.err.println("Finished tag");
+	    } else {
+		//System.err.println("Parsing content");
+		//System.err.println("Value = " + value + " = '" + (char)value + "'");
+		while(value != -1 && value != '<') {
+		    //System.err.println("Read a '" + (char)value + "'");
+		    setBuffer(value);
+		    value = getRaw();
+		}
+		// If we've accidently read the '<' push it back in the stream by
+		// setting peek_value to value. Since the peek_value will be returned
+		// on the next read this has the desired effect.
+		if(value == '<') {
+		    peek_value = value;
+		}
+		//System.err.println("Read " + buffer);
+		//System.err.println("Finished Content");
+	    }
+	}
+    }
+    
+    // Sets the tail of the buffered buffer.
+    private void setBuffer(int value) {
+	buffer = buffer + (char) value;
+    }
+    
+    private String smartLower(String tag) {
+	boolean lower = true;
+	String new_tag = "";
+	for(int i = 0; i < tag.length(); i++) {
+				// Disable case lowering for value tags (bound by "")
+	    if (tag.charAt(i) == '"') {
+		if(lower) {
+		    lower = false;
+		} else {
+		    lower = true;
+		}
+	    }
+				// Lower everything else
+	    if(lower) {
+		new_tag = new_tag + Character.toLowerCase(tag.charAt(i));
+	    } else {
+		new_tag = new_tag + tag.charAt(i);
+	    }
+	}
+	return new_tag;
+    }
+    
+    private final static int GROUND           = 0;
+    private final static int COMMENT          = 5;
+    private final static int COMMENT_DASH     = 6;
+    private final static int COMMENT_FINAL    = 7;
+    private final static int H                = 11;
+    private final static int HR               = 12;
+    private final static int HRE              = 13;
+    private final static int HREF             = 14;
+    private final static int HREF_EQUAL       = 15;
+    private final static int HREF_Q           = 16;
+    private final static int HREF_NQ          = 17;
+    private final static int HREF_FINAL       = 18;
+    private final static int S                = 23;
+    private final static int SR               = 24;
+    private final static int SRC              = 25;
+    private final static int SRC_EQUAL        = 26;
+    private final static int SRC_Q            = 27;
+    private final static int SRC_NQ           = 28;
+    private final static int SRC_FINAL        = 29;
+    private final static int L                = 67;
+    private final static int LI               = 68;
+    private final static int LIN              = 69;
+    private final static int LINK             = 70;
+    private final static int LINK_QUOTE       = 72;
+    private final static int LINK_H           = 73;
+    private final static int LINK_HR          = 74;
+    private final static int LINK_HRE         = 75;
+    private final static int LINK_HREF        = 76;
+    private final static int LINK_EQUAL       = 77;
+    private final static int LINK_Q           = 78;
+    private final static int LINK_NQ          = 79;
+    private final static int LINK_FINAL       = 80;
+    private final static int B                = 85;
+    private final static int BA               = 86;
+    private final static int BAC              = 87;
+    private final static int BACK             = 88;
+    private final static int BACKG            = 89;
+    private final static int BACKGR           = 90;
+    private final static int BACKGRO          = 91;
+    private final static int BACKGROU         = 92;
+    private final static int BACKGROUN        = 93;
+    private final static int BACKGROUND       = 94;
+    private final static int BACKGROUND_EQUAL = 95;
+    private final static int BACKGROUND_Q     = 96;
+    private final static int BACKGROUND_NQ    = 97;
+    private final static int BACKGROUND_FINAL = 98;
+    private final static int FINAL            = 99;
+    
+    // Run the finite-state machine on a buffer-load.
+    private String findURL(String tail) {
+	int state = GROUND;
+	String head = "";
+	String url_str = "";
+	// Sift through the tag for urls
+	while(tail.length() > 0 && state != BACKGROUND_FINAL && state != COMMENT_FINAL && state != HREF_FINAL && state != LINK_FINAL && state != SRC_FINAL) {
+	    char ch = tail.charAt(0);
+	    String sch = "" + ch;
+	    sch = sch.toLowerCase();
+	    char lch = sch.charAt(0);
+	    tail = tail.substring(1);
+	    switch (state) {
+		// Initial state.
+	    case GROUND:
+		switch (lch) {
+		case '!': state = COMMENT; break;
+		case 'B': case 'b': state = B; break;
+		case 'H': case 'h': state = H; break;
+		case 'L': case 'l': state = L; break;
+		case 'S': case 's': state = S; break;
+		}
+		head = head + ch;
+		break;
+		// A possible comment
+	    case COMMENT:
+		switch(lch) {
+		case '-': state = COMMENT_DASH; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case COMMENT_DASH:
+		switch(lch) {
+		case '-': state = COMMENT_FINAL; break; // skip comments
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+		// A possible href
+	    case H:
+		switch(lch) {
+		case 'R': case 'r': state = HR; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case HR:
+		switch(lch) {
+		case 'E': case 'e': state = HRE; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case HRE:
+		switch(lch) {
+		case 'F': case 'f': state = HREF; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case HREF:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r': break; // Skip blanks
+		case '=': state = HREF_EQUAL; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case HREF_EQUAL:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r': break; // Skip blanks
+		case '\'': case '\"': state = HREF_Q; break;
+		default: state = HREF_NQ; break;
+		}
+		if(state == HREF_NQ) {
+		    url_str = url_str + ch;
+		} else {
+		    head = head + ch;
+		}
+		break;
+	    case HREF_NQ:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r':
+		    state = HREF_FINAL;
+		    tail = ch + tail;
+		    break;
+		default: url_str = url_str + ch; break;
+		}
+		break;
+	    case HREF_Q:
+		switch(lch) {
+		case '\'': case '\"':
+		    state = HREF_FINAL;
+		    tail = ch + tail;
+		    break;
+		default: url_str = url_str + ch; break;
+		}
+		break;
+		// A possible src
+	    case S:
+		switch(lch) {
+		case 'R': case 'r': state = SR; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case SR:
+		switch(lch) {
+		case 'C': case 'c': state = SRC; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case SRC:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r': break; // Skip blanks
+		case '=': state = SRC_EQUAL; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case SRC_EQUAL:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r': break; // Skip spaces
+		case '\'': case '\"': state = SRC_Q; break;
+		default: state = SRC_NQ; break;
+		}
+		if(state == SRC_NQ) {
+		    url_str = url_str + ch;
+		} else {
+		    head = head + ch;
+		}
+		break;
+	    case SRC_NQ:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r':
+		    state = SRC_FINAL;
+		    tail = ch + tail;
+		    break;
+		default: url_str = url_str + ch; break;
+		}
+		break;
+	    case SRC_Q:
+		switch(lch) {
+		case '\'': case '\"':
+		    state = SRC_FINAL;
+		    tail = ch + tail;
+		    break;
+		default: url_str = url_str + ch; break;
+		}
+		break;
+		// A possible link-src combo
+	    case L:
+		switch(lch) {
+		case 'I': case 'i': state = LI; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case LI:
+		switch(lch) {
+		case 'N': case 'n': state = LIN; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case LIN:
+		switch(lch) {
+		case 'K': case 'k': state = LINK; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case LINK:
+		switch(lch) {
+		case 'H': case 'h': state = LINK_H; break;
+		default: state = LINK; break;
+		}
+		head = head + ch;
+		break;
+	    case LINK_H:
+		switch(lch) {
+		case 'R': case 'r': state = LINK_HR; break;
+		default: state = LINK; break;
+		}
+		head = head + ch;
+		break;
+	    case LINK_HR:
+		switch(lch) {
+		case 'E': case 'e': state = LINK_HRE; break;
+		default: state = LINK; break;
+		}
+		head = head + ch;
+		break;
+	    case LINK_HRE:
+		switch(lch) {
+		case 'F': case 'f': state = LINK_HREF; break;
+		default: state = LINK; break;
+		}
+		head = head + ch;
+		break;
+	    case LINK_HREF:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r': break; // Skip blanks
+		case '=': state = LINK_EQUAL; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case LINK_EQUAL:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r': break; // Skip blanks
+		case '\'': case '\"': state = LINK_Q; break;
+		default: state = LINK_NQ; break;
+		}
+		if(state == LINK_NQ) {
+		    url_str = url_str + ch;
+		} else {
+		    head = head + ch;
+		}
+		break;
+	    case LINK_NQ:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r':
+		    state = LINK_FINAL;
+		    tail = ch + tail;
+		    break;
+		default: url_str = url_str + ch; break;
+		}
+		break;
+	    case LINK_Q:
+		switch(lch) {
+		case '\'': case '\"':
+		    state = LINK_FINAL;
+		    tail = ch + tail;
+		    break;
+		default: url_str = url_str + ch; break;
+		}
+		break;
+		// A possible background
+	    case B:
+		switch(lch) {
+		case 'A': case 'a': state = BA; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case BA:
+		switch(lch) {
+		case 'C': case 'c': state = BAC; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case BAC:
+		switch(lch) {
+		case 'K': case 'k': state = BACK; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case BACK:
+		switch(lch) {
+		case 'G': case 'g': state = BACKG; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case BACKG:
+		switch(lch) {
+		case 'R': case 'r': state = BACKGR; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case BACKGR:
+		switch(lch) {
+		case 'O': case 'o': state = BACKGRO; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case BACKGRO:
+		switch(lch) {
+		case 'U': case 'u': state = BACKGROU; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case BACKGROU:
+		switch(lch) {
+		case 'N': case 'n': state = BACKGROUN; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case BACKGROUN:
+		switch(lch) {
+		case 'D': case 'd': state = BACKGROUND; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case BACKGROUND:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r': break; // Skip blanks
+		case '=': state = BACKGROUND_EQUAL; break;
+		default: state = GROUND; break;
+		}
+		head = head + ch;
+		break;
+	    case BACKGROUND_EQUAL:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r': break; // Skip blanks
+		case '\'': case '\"': state = BACKGROUND_Q; break;
+		default: state = BACKGROUND_NQ; break;
+		}
+		if(state == BACKGROUND_NQ) {
+		    url_str = url_str + ch;
+		} else {
+		    head = head + ch;
+		}
+		break;
+	    case BACKGROUND_NQ:
+		switch(lch) {
+		case ' ': case '\t': case '\n': case '\r':
+		    state = BACKGROUND_FINAL;
+		    tail = ch + tail;
+		    break;
+		default: url_str = url_str + ch; break;
+		}
+		break;
+	    case BACKGROUND_Q:
+		switch(lch) {
+		case '\'': case '\"':
+		    state = BACKGROUND_FINAL;
+		    tail = ch + tail;
+		    break;
+		default: url_str = url_str + ch; break;
+		}
+		break;
+	    }
+	}
+       
+        url_str =   url_str.replaceAll("&amp;","&");
+    
+	if(state == HREF_FINAL ) {
+	    try {
+		URL new_url = new URL(url, url_str);
+		href_links.addElement(new_url);
+	    }
+	    catch (Exception e) {
+		e.printStackTrace();
+	    }
+        }
+
+	if(state == SRC_FINAL ) {
+	    try {
+		URL new_url = new URL(url, url_str);
+		src_links.addElement(new_url);
+	    }
+	    catch (Exception e) {
+		e.printStackTrace();
+	    }
+        }
+
+	if(state == LINK_FINAL ) {
+	    try {
+		URL new_url = new URL(url, url_str);
+		link_links.add(new_url);
+	    }
+	    catch (Exception e) {
+		e.printStackTrace();
+	    }
+        }
+
+	if(state == BACKGROUND_FINAL ) {
+	    try {
+		URL new_url = new URL(url, url_str);
+		background_links.add(new_url);
+	    }
+	    catch (Exception e) {
+		e.printStackTrace();
+	    }
+        }
+
+	return head + url + tail;
+    }
+    
+    static private String guessContentType(String text) {
+	if(text.endsWith("/")) {
+	    return "text/html";
+	} else if (text.endsWith(".html")) {
+	    return "text/html";
+	} else if (text.endsWith(".htm")) {
+	    return "text/html";
+	} else if (text.indexOf("?")>0) {
+	    return "text/html";
+	}
+	return "image/jpeg";
+    }
+    
+}
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/CollageImage.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/CollageImage.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/CollageImage.java	(revision 16571)
@@ -0,0 +1,508 @@
+package org.nzdl.gsdl.GsdlCollageApplet;
+
+import java.awt.*;
+import java.awt.geom.*;
+import java.io.*;
+import java.net.*;
+import java.awt.image.*;
+
+
+/** 
+ *  @author Katrina Edgar
+ *  @author David Bainbridge
+ *
+ *  Data Structure to store an image once it is displayed in the applet.
+ *  This structure remembers the images graphical representation, source url,
+ *  name, width, height, position on the screen and whether or not it has
+ *  previously been displayed. It provides methods to set the dimensions and
+ *  position of the image. It also provides access methods to the translated
+ *  x and y co-ordinates of the image */
+public class CollageImage {
+
+     /** Decrements the alpha value between adjacent rows on the edge of an image<br>
+     *  Used to fade the edges faster than the rest of the image <br>
+     *  Only used when java2 parameter is true and advanced image processing
+     *  techniques may be applied */
+    static final int FADEVALUE = 3;
+
+    /** Defines the shades of white used to colour the backgrounds of white images <br>
+     *  These colours are used because when several white images appear in the collage
+     *  simultaneously it is difficult to distinguish their edges<br>
+     *  Only used when java2 parameter is true and advanced image processing
+     *  techniques may be applied */
+    int colorMask [] = {0xF8FFFF, 0xFFF8FF, 0xFFFFF8, 0xF8F8FF, 0xFFF8F8, 0xF8FFF8, 0xFAFAFA};
+
+      
+    /** Defines the number of shades of white used to colour the backgrounds of white images <br>
+     *  These colours are used because when several white images appear in the collage
+     *  simultaneously it is difficult to distinguish their edges<br>
+     *  Only used when java2 parameter is true and advanced image processing
+     *  techniques may be applied */
+    static final int NO_OF_COLORS = 7;
+
+    /** Will fire a removal operation when 4 images in the collage overlap a single area */
+    static final int NO_IMAGES_OF_OVERLAP = 4;
+
+
+    /** Source url of the image */
+    String from_url_    = null;
+    /** Name of the image */
+    String name_        = null;
+    /** Width of the image */
+    int image_x_dim_    = 0;
+    /** Height of the image */
+    int image_y_dim_    = 0;
+    /** Indicates whether or not the image has been drawn on the applet previously */
+    boolean fresh       = true;
+    
+    URL url_ = null;      
+ 
+    /** Reflects the translation of the image from the origin to its position on the screen */
+    AffineTransform af_ = null;
+    /** Left x co-ordinate */
+    protected int xl_ = 0;
+    /** Top y co-ordinate */
+    protected int yt_ = 0;
+    /** Right x co-ordinate */
+    protected int xr_ = 0;
+    /** Bottom y co-ordinate */
+    protected int yb_ = 0;
+ 
+     /** Refers to applet */
+    GsdlCollageApplet app_ = null;
+
+    boolean isJava2_;
+ 
+    Image image_; 
+   
+    /** Constructs an CollageImage from the three specified parameters
+     *
+     *  @param image The graphical representation of the image
+     *  @param from_url The source url for the image
+     *  @param name The file name of the image */
+    public CollageImage(GsdlCollageApplet app, boolean isJava2, DownloadImages.ImageUrlTriple iutriple)
+    {
+         
+         image_ = iutriple.image();
+	 from_url_ = iutriple.urlString();
+	 name_ = iutriple.name();
+	 url_ =  iutriple.url();
+         
+         isJava2_=isJava2;
+         app_=app;  
+
+	 process();
+    }
+
+    /** Sets the translation for the image from the origin
+     *  And regenerate the image as the scaled version
+     *
+     *  @param af The AffineTransform translation that has been calculated */
+    public void setAffineTransform(MyAffineTransform af, boolean is_java2_)
+    {	
+	image_x_dim_ = (int) (image_x_dim_ * af.scaleX);
+	image_y_dim_ = (int) (image_y_dim_ * af.scaleY);
+        
+	image_ = image_.getScaledInstance(image_x_dim_, image_y_dim_, Image.SCALE_DEFAULT);
+	
+	if (is_java2_) {
+	    af_ = new AffineTransform();
+	    af_.translate(af.translateX, af.translateY);
+	    af_.scale(1.0, 1.0);
+	
+	    calculate_rect();
+	}
+	else {
+	    double trans_x = af.translateX;
+	    double trans_y = af.translateY;
+	    
+	    xl_ = Math.round((float)trans_x);
+	    xr_ = Math.round((float)(trans_x + image_x_dim_)) -1;
+	    yt_ = Math.round((float)trans_y);
+	    yb_ = Math.round((float)(trans_y + image_y_dim_)) -1; 
+	}
+
+    }
+
+    public void expand () {
+	
+	// still expands a little too fast... how to fix this?
+	magnify(new Rectangle((int) (xl_ + (image_x_dim_ * 0.000001)),
+			      (int) (yt_ + (image_y_dim_ * 0.000001)),
+			      (int) (image_x_dim_ * 0.999998),
+			      (int) (image_y_dim_ * 0.999998)));
+	
+    }
+    
+    public void magnify(Rectangle border) {
+	
+	double magX = image_x_dim_/(double)border.width;
+	double magY = image_y_dim_/(double)border.height;
+	int x = border.x + border.width/2;
+	int y = border.y + border.height/2;
+	paintImage(x,y,magX, magY);
+    }
+    
+    public void paintImage(int magCenterX, int magCenterY, double magX, double magY){
+	
+	try {
+	    //Point2D mgp = null;
+	    //mgp = af_.inverseTransform((new Point(magCenterX, magCenterY)),(Point)mgp);
+	    //double x = (mgp.getX()*magX)-mgp.getX();
+	    //double y = (mgp.getY()*magY)-mgp.getY();
+	    //scale(-x,-y, magX, magY);
+	}catch (Exception e) {System.out.println(e); }
+    }
+    
+    public void scale(double magOffsetX, double magOffsetY, double magX, double magY){
+	
+	af_.translate(magOffsetX,magOffsetY);
+	af_.scale(magX, magY);
+    }
+    
+    /** Calculates the new image co-ordinates after translation has occurred */
+    protected void calculate_rect()
+    {
+	double trans_x = af_.getTranslateX();
+	double trans_y = af_.getTranslateY();
+
+	xl_ = Math.round((float)trans_x);
+	xr_ = Math.round((float)(trans_x + image_x_dim_)) -1;
+	yt_ = Math.round((float)trans_y);
+	yb_ = Math.round((float)(trans_y + image_y_dim_)) -1; 
+    }
+
+    /** Determines whether a given co-ordinate is inside this image
+     *
+     *  @param x The x co-ordinate
+     *  @param y The y co-ordinate */
+    public boolean inside(int x, int y)
+    {
+	return ((x>=xl_) && (x<=xr_)) && ((y>=yt_) && (y<=yb_));
+    }
+
+    /** Gets the width of the translated image */
+    public double getX() {
+	return af_.getTranslateX();
+    }
+
+    /** Gets the height of the translated image */
+    public double getY() {
+	return af_.getTranslateY();
+    }
+    
+  
+    /** Fades and colours the image on a pixel-by-pixel basis <br>
+     *  First it grabs the pixels of the entire image and stores them in a 2D array.
+     *  Then a bound is calculated to indicate the point from which edge
+     *  fading should occur. The position of the bound will change in proportion
+     *  to the age of the image so that older images have a larger faded edge.
+     *  The area within the bounds, that forms the center of the image, is processed
+     *  first and faded by a standard alpha value. Then each edge of the image
+     *  is processed separately, creating a gradient fade from the true edge to the
+     *  position of the bound. <br>
+     *  The faded pixel array is then turned into a new image a returned.
+     *
+     *  @param img the image that requires processing
+     *  @param x the x co-ordinate of the image
+     *  @param y the y co-ordinate of the image
+     *  @param w the width of the image
+     *  @param h the height of the image
+     *  @param p the position of the image in the applet (indicates age)
+     *  @param fresh whether the image is being processed for the first time */
+    public int[]  handlepixels(int p) {
+       
+	int h = image_y_dim_;
+	int w = image_x_dim_;       
+	
+	// declare an array to hold the pixels
+	int[] pixels = new int[w * h];
+	// get the pixels of the image into the pixels array
+	PixelGrabber pg = new PixelGrabber(image_, 0, 0, w, h, pixels, 0, w);
+	
+	try {
+	    pg.grabPixels();
+	} catch (InterruptedException e) {
+	    System.err.println("interrupted waiting for pixels!");
+	}
+	
+	    
+	// check for any failures
+	if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
+	    System.err.println("image fetch aborted or errored");
+		
+	}
+	
+   
+	// calculates the bound from which fading should begin
+	double bound = p * 0.01;
+	if (w > h)
+	    bound *= w;
+	else
+	    bound *= h;
+
+	int upperboundheight = h - (int) bound;
+	int upperboundwidth = w - (int) bound;
+	int lowerbound = (int) bound;
+
+      	// loop through every pixel in the picture and handle it
+	for (int j = lowerbound; j < upperboundheight; j++) {
+	    for (int i = lowerbound; i < upperboundwidth; i++) {
+		// width and height: x+i y+j
+		pixels[j * w + i] = handlesinglepixel(pixels[j * w + i], p, fresh, false, 255);
+	    }
+	}
+
+	int fade = 0;
+	int fader = 0;
+	int corealpha = (pixels[(h/2) * w + (w/2)] >> 24) & 0xff;
+	
+	// top edge
+	for (int n = lowerbound; n >= 0; n--) {
+	    fader = corealpha - fade;
+	    if (fader < 0)
+		fader = 0;
+	    
+	    for (int m = 0; m < w; m++){
+		int index = n* w + m;
+		if (index <pixels.length){
+		    pixels[index] = handlesinglepixel(pixels[index], p, fresh, true, fader);
+		    
+		}
+	    }   
+	    
+	    fade+= FADEVALUE;
+	}
+
+	// bottom edge
+	fade = 0;
+	for (int n = upperboundheight; n < h; n++) {
+	    fader = corealpha - fade;
+	    if (fader < 0)
+		fader = 0;
+	    for (int m = 0; m < w; m++){
+		int index = n * w + m;
+		if (index <pixels.length){
+		    pixels[index] = handlesinglepixel(pixels[index], p, fresh, true, fader);
+		    
+		}
+	    }
+	    
+	    fade += FADEVALUE;
+	}
+
+	// left edge
+	fade = 0;
+	for (int n = lowerbound; n >= 0; n--) {
+	    fader = corealpha - fade;
+	    if (fader < 0)
+		fader = 0;
+	    for (int m = 0; m < h; m++) {
+		if ( m < lowerbound && n > m);
+		else if ( m > upperboundheight && n > (h - m));
+		else {
+		    int index = m * w + n;
+                    if (index <pixels.length){
+			pixels[index] = handlesinglepixel(pixels[index], p, fresh, true, fader);
+	
+		    }
+		}
+                   
+	    }
+	    fade += FADEVALUE;    
+	}
+	
+	// right edge
+	fade = 0;
+	for (int n = upperboundwidth; n < w; n++) {
+	    fader = corealpha - fade;
+	    if (fader < 0)
+		fader = 0;
+	    for (int m = 0; m < h; m++) {
+		if ( m < lowerbound && (w - n) > m);
+		else if ( m > upperboundheight && (w - n) > (h - m));
+		else {
+		    int index = m * w + n;
+                    if (index <pixels.length){
+			pixels[index] = handlesinglepixel(pixels[index], p, fresh, true, fader);
+	
+		    }
+		}
+		    
+	    }
+	    
+	    fade += FADEVALUE;
+	}  
+	
+       		// set the pixels of the whole picture to the pixels array
+       	pg.setPixels(0, 0, w, h, pg.getColorModel(), pixels, 0, w);
+
+	image_ =  app_.createImage(new MemoryImageSource(w, h, pixels, 0, w));
+
+	return pixels;
+    }
+
+    
+    /** Adjusts the colour and alpha value of an individual pixel <br>
+     *  If the image is being drawn for the first time, the RGB values are
+     *  extracted. If the pixel is close to white (RGB > 250) then an offwhite
+     *  colour is applied to this pixel.
+     *  This is done because when several white images appear in the collage
+     *  simultaneously it is difficult to distinguish their edges. <br>
+     *  This function also fades the alpha value of the pixel as the image ages.
+     *  The alpha value is more heavily decremented as pixels get closer to the
+     *  edge of the image
+     *
+     *  @param pixel the pixel to manipulate
+     *  @param p the position of the image in collage (representative of age)
+     *  @param fresh indicates whether or not the image is being drawn for the first time
+     *  @param edge indicates whether or not this pixel is near the edge of the image
+     *  @param fade the amount by which to fade this pixel
+     *  @return the adjusted pixel as an int */
+    public int handlesinglepixel(int pixel, int p, boolean fresh, boolean edge, int fade) {
+       	int newpixel = 0;
+
+        //changes the colour of the picture, only when first drawn
+	//and only if the pixel is close to white
+	if (fresh) {
+	    
+	    int red   = (pixel >> 16) & 0xff;
+	    int green = (pixel >>  8) & 0xff;
+	    int blue  = (pixel      ) & 0xff;
+	    
+	    if (red >= 250 && green >= 250 && blue >= 250) {
+		
+		int c = colorMask[((int) (p%NO_OF_COLORS))];
+
+		red = (c >> 16) & 0xff;
+		green = (c >> 8) & 0xff;
+		blue  = (c) & 0xff;
+	    }
+
+	    newpixel |= (red << 16) & 0x00ff0000;
+	    newpixel |= (green << 8) & 0x0000ff00;
+	    newpixel |= blue & 0x000000ff;
+	}
+
+	else {
+	    newpixel |= pixel & 0x00ffffff;
+	}
+
+	int alpha = (pixel >> 24) & 0xff;
+
+	if (edge) {
+	    // fade the edges more...
+	    alpha = fade;
+	}
+	else if (alpha > 10 && !fresh) {
+	    alpha -= 10;
+	}
+	
+	newpixel |= (alpha << 24) & 0xff000000;
+	
+	return (newpixel);
+    }
+
+
+  
+
+    /** Resets the alpha channel of an image so that it appears solid
+     *
+     *  @param img the image to restore
+     *  @param x the x co-ordinate of the image
+     *  @param y the y co-ordinate of the image
+     *  @param w the width of the image
+     *  @param h the height of the image */
+    public void restoreAlpha() {
+       	int h = image_y_dim_;
+	int w = image_x_dim_;       
+
+	// declare an array to hold the pixels
+	int[] pixels = new int[w * h];
+	// get the pixels of the image into the pixels array
+	PixelGrabber pg = new PixelGrabber(image_, 0, 0, w, h, pixels, 0, w);
+	try {
+	    pg.grabPixels();
+	    
+		
+	} catch (InterruptedException e) {
+	    System.err.println("interrupted waiting for pixels!");
+	}
+	
+	
+	// check for any failures
+	if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
+	    System.err.println("image fetch aborted or errored");
+	}
+	
+	
+	    
+	// loop through every pixel in the picture and handle it
+	for (int j = 0; j < h; j++) {
+	    for (int i = 0; i < w; i++) {
+		pixels[j * w + i] |= (255 << 24) & 0xff000000;
+	    }
+	}   
+ 
+	// set the pixels of the whole picture to the pixels array
+	pg.setPixels(0, 0, w, h, pg.getColorModel(), pixels, 0, w);
+
+	image_ =  app_.createImage(new MemoryImageSource(w, h, pixels, 0, w));       
+	
+    }
+    
+    /** Checks whether an image has faded to the point where it must be removed
+     *  from the collage.
+     *
+     *  @param img the image to restore
+     *  @param x the x co-ordinate of the image
+     *  @param y the y co-ordinate of the image
+     *  @param w the width of the image
+     *  @param h the height of the image */
+    public boolean checkFaded (int[] pixels) {
+	int h = image_y_dim_;
+	int w = image_x_dim_;
+
+	// get the alpha value of the middle pixel of the image
+	int corealpha = (pixels[(h/2) * w + (w/2)] >> 24) & 0xff;
+	
+	if (corealpha < 50)
+	    return true;
+	
+	return false;
+	
+    }
+
+    public boolean isValid(){
+	image_x_dim_ = image_.getWidth(app_);
+	image_y_dim_ = image_.getHeight(app_);
+
+	return  (image_x_dim_) >0 && ( image_x_dim_ >0);
+	
+    }
+
+    
+    public void process(){
+
+	// images x and y dimensions
+	image_x_dim_ = image_.getWidth(app_);
+	image_y_dim_ = image_.getHeight(app_);
+	 if (( image_x_dim_ >0) && ( image_x_dim_ >0))
+	     {		
+		 // places and sizes the image
+		 MyAffineTransform af = new MyAffineTransform(image_x_dim_,image_y_dim_);
+		 
+		 // sets location & size of collage image
+		 setAffineTransform(af, isJava2_);
+		 fresh = false;
+		 if (isJava2_ ) {      	 
+		     restoreAlpha(); 
+		 }
+		 	
+	     }
+  
+	
+    }
+
+}	
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/Display.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/Display.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/Display.java	(revision 16571)
@@ -0,0 +1,44 @@
+package org.nzdl.gsdl.GsdlCollageApplet;
+
+import java.applet.*;
+import java.awt.*;
+import java.awt.image.*;
+import java.awt.geom.*;
+import java.util.*;
+
+/** 
+ *  @author Katrina Edgar */
+public class Display extends Thread {
+
+    GsdlCollageApplet app_ = null;
+
+     public Display(GsdlCollageApplet app) {
+	super("Display");
+	app_ = app;
+	
+    }
+
+
+    /** Runs display thread by repeatedly calling the next frame,
+     *  waiting for a specified delay period between calls */
+    public void run() {
+	try {
+
+	    System.err.println("Started display thread.");
+
+	    Thread curr_thread = Thread.currentThread();
+	    
+	    while (curr_thread == this) {
+		app_.repaint();
+		// can't make it zero or it hogs the whole processor
+		Thread.sleep(100);
+		curr_thread = Thread.currentThread();
+	    }
+
+	    System.err.println("Stopped display thread.");
+	    
+	} catch (Exception e) {
+	    e.printStackTrace();
+	}
+    }
+}
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/DisplayImages.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/DisplayImages.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/DisplayImages.java	(revision 16571)
@@ -0,0 +1,437 @@
+package org.nzdl.gsdl.GsdlCollageApplet;
+
+import java.applet.*;
+import java.awt.*;
+import java.awt.image.*;
+import java.awt.geom.*;
+import java.util.*;
+
+/** 
+ *  @author Katrina Edgar
+ *  @author David Bainbridge
+ *
+ *  Retrieves images from the download thread, determines an appropriate position
+ *  for thes  images onscreen ensuring maximum whitespace coverage and minimal overlap
+ *  when possible. Draws images using advanced image processing techniques when applicable,
+ *  such as fading the edges of an image and discolouring backgrounds. Also re-uses images
+ *  from those that have previously been displayed, or are aging onscreen, in order to
+ *  to create movement when no new images have been downloaded. */
+public class DisplayImages extends Thread {
+
+
+    /** Will fire a removal operation when 4 images in the collage overlap a single area */
+    static final int NO_IMAGES_OF_OVERLAP = 4;
+    
+    /** To determine if there are several images overlapped, can remove the
+     *  layers underneath to save time in repainting */
+    boolean overlap = false;
+
+    /** Refers to download thread */
+    DownloadImages download_images_ = null;
+
+    /** Refers to applet */
+    GsdlCollageApplet app_ = null;
+
+    /** Applets width on screen */
+    public static int app_x_dim_  = 0;
+
+    /** Applets height on screen */
+    public static int app_y_dim_  = 0;
+    
+    /** Background colour of the applet screen */
+    protected Color bgcolor_        = null;
+
+    /** Indicates whether java2 functionality should be used <br>
+     *  If true will allow advanced image processing techniques to occur, 
+     *  such as fading and colouring using pixel manipulation <br>
+     *  If false, images will maintain an alpha value of 1 (appear solid), 
+     *  newer images will simply be pasted on top of existing images <br> */
+    protected boolean is_java2_     = false;
+
+  
+    /** Holds images currently on display in the applet */
+    protected Vector inuse_    = null;
+    
+     /** Holds images ready to be used */
+    protected Vector inuse_ready_    = null;
+
+    /** Holds previously displayed images for re-use */
+    protected Vector notinuse_ = null;
+   
+    protected Image    screen_buffer_    = null;
+    protected Graphics screen_graphic_   = null;
+    protected Image    finished_buffer_  = null;
+    protected Graphics finished_graphic_ = null;
+ 
+    Thread next_frame_ ;
+
+    String dots[] = new String[]{" ",".","..","...","....",".....","......"};
+    int dots_nums=0;
+    boolean start_paint = false;
+    /** Used to determine where to place new images on the applet to optimize
+     *  whitespace coverage <br>
+     *  A co-ordinate in the applet has a value of zero if it is whitespace,
+     *  one if it is covered by one image, two if it is covered by two images,
+     *  and so on. New images will be placed such that they cover the largest
+     *  area of whitespace (zero valued co-ordinates) */
+    public static int [] [] used_space = null;
+    
+  
+    /**
+     *  Starts the display images thread. Initialises variables using parameters and
+     *  static values. Creates the blank applet screen, initialises the used space
+     *  2D array to indicate that there are no images onscreen
+     *
+     *  @param app the applet to display the images on
+     *  @param download_images thread from which to retrieve downloaded images
+     *  @param is_java2 whether advanced image processing techniques should be used
+     *  @param bgcolor the background colour of the applet screen */
+    public DisplayImages(GsdlCollageApplet app, DownloadImages download_images,
+			 boolean is_java2, Color bgcolor)
+    {
+	super("DisplayImages");
+
+	// parameters saved locally
+	app_             = app;
+	is_java2_        = is_java2;
+	bgcolor_         = bgcolor;
+
+	inuse_    = new Vector();
+      	notinuse_ = new Vector();
+        inuse_ready_ = new Vector();
+	download_images_ = download_images;
+	// sets width and height
+	if (is_java2_)
+	{
+	    app_x_dim_  = app_.getWidth();
+	    app_y_dim_  = app_.getHeight();
+	}
+	else
+	{
+	    app_x_dim_  = 645;
+	    app_y_dim_  = 780;
+	}
+
+	// creates initial screen
+	screen_buffer_ = app_.createImage(app_x_dim_, app_y_dim_); 
+	screen_graphic_ = screen_buffer_.getGraphics();
+	screen_graphic_.setColor(bgcolor_);
+	screen_graphic_.fillRect(0,0,app_x_dim_,app_y_dim_);
+	
+	finished_buffer_  = app_.createImage(app_x_dim_, app_y_dim_);
+	finished_graphic_ = finished_buffer_.getGraphics();
+    
+	// initialises used space array to indicate an empty screen
+	used_space = new int [app_x_dim_][app_y_dim_];	
+	for (int n=0; n < app_x_dim_; n++)
+	    for (int m=0; m < app_y_dim_; m++)
+		used_space[n][m] = 0;
+
+        next_frame_ =  new Thread(new Runnable(){
+                public void run() {
+		  
+		    Thread curr_thread = Thread.currentThread();
+		    
+		    while (curr_thread == next_frame_) {
+			try {	    
+			    Runtime rt = Runtime.getRuntime();
+			    //System.out.println("total: "+rt.totalMemory());
+			    //System.out.println("free:  "+rt.freeMemory());
+			    rt.gc();             
+               		    //System.out.println("**************next frame...");
+			    next_frame();
+			    Thread.sleep(app_. refreshDelay_);
+			   
+			    curr_thread = Thread.currentThread();
+			} catch (Exception e) {
+                            e.printStackTrace(); 
+			    break;
+			}
+		    }
+		    	    
+		   
+		}
+
+
+	    });
+
+	 next_frame_.start();
+
+
+    }
+
+    /** Determines what the user has clicked on in the applet, either an image or whitespace
+     *  @param x the x co-ordinate of the mouse
+     *  @param y the y co-ordinate of the mouse
+     *  @return the image that the user has clicked on or null if the user has clicked whitespace */
+   public CollageImage clickedOnImage(int x, int y)
+    {
+	if (app_.verbosity() > 1)
+	{
+	    System.err.print("Checking for clicked on image: ("+x+","+y+")");
+	}
+
+	
+	// checks from last image down, as last images place will be at the top of the collage
+	for (int i= inuse_.size() - 1; i >= 0; i--)
+	{
+	    CollageImage collage_image = (CollageImage)inuse_.elementAt(i);
+	    if (collage_image.inside(x,y))
+	    {
+		return collage_image;
+	    }
+	}
+	// no image at these co-ordinates, just whitespace
+	return null;
+    }
+
+    /** Generates the images onscreen.
+     *  Loops through the vector of currently displayed images and draws each one in turn.
+     *  If the image is being drawn for the first time, its position will be determined
+     *  and its alpha channel set as solid prior to drawing. <br>
+     *  Drawing of the image will depend on whether or not java2 is enabled. If so then
+     *  the image will be processed so that fading occurs with age, so that the edges 
+     *  fade faster than the rest of the image and so that white images are slightly 
+     *  discoloured to allow distinction. If java2 is not enabled, new images will simply
+     *  be pasted on top of existing images without any special effects occuring<br>
+     *  This function also deletes old images. If java2 is enabled then images are deleted
+     *  once they have faded to a suitably low alpha value. If java2 is not enabled then
+     *  images will be removed once there are greater than 25 images onscreen, to ensure
+     *  the applet cannot be overloaded. */
+    public  void display_collage() 
+    {
+	
+	// if there is nothing new to add
+	if (inuse_.size()==0) return;
+	
+	// otherwise need to re-generate images
+	if (app_.verbosity() >= 2)
+	    {
+		//system.err.println("Regenerating images");
+	    }
+	
+	// get each image currently onscreen inturn
+	for (int i=0; i<inuse_.size();)
+	    {
+		CollageImage collage_image = (CollageImage)inuse_.elementAt(i);
+  
+                if (!collage_image.isValid()){
+		    continue;
+		}	    
+
+                int[] pixels = null;
+		// the first time the image is painted, determine its position and size
+		if (collage_image.fresh == true)
+		    {
+			collage_image.process();
+		    }
+		
+		// advanced image processing may be used
+		if (is_java2_)
+		    {
+			// conducts fading and colouring of image
+			pixels = collage_image.handlepixels(inuse_.size()-i); 
+		    }
+		
+		if (collage_image.fresh) {
+		    collage_image.fresh = false;
+		}
+		
+		
+		// if we remove when images have faded too much
+		if (is_java2_) {
+		    if (collage_image.checkFaded(pixels)|| overlap)
+			{
+			    overlap = false;
+			    
+			    CollageImage removed_image = (CollageImage)inuse_.elementAt(i);
+			    //System.out.println(removed_image.name_ + "is removed");
+			    inuse_.remove(i);
+			    // indicates space for this image is no longer used
+			    for (int n = removed_image.xl_; n < (removed_image.xl_ + removed_image.image_x_dim_); n++)
+				for (int m = removed_image.yt_; m < (removed_image.yt_ + removed_image.image_y_dim_); m++)
+				    if(used_space[n][m] != 0) {
+					used_space[n][m]--;
+					if (used_space[n][m] > NO_IMAGES_OF_OVERLAP)
+					    overlap = true;
+				    }
+			    
+			    // sets the image as fresh and adds it to the vector of images previously seen
+			    removed_image.fresh = true;
+			    notinuse_.addElement(removed_image);
+			}
+		    else{
+			i++;
+		    }
+		}
+		else 
+		    if (inuse_.size() > 25 || overlap) {
+			overlap = false;
+			
+			CollageImage removed_image = (CollageImage)inuse_.elementAt(i);
+			inuse_.remove(i);
+			
+			// indicates space for this image is no longer used
+			for (int n = removed_image.xl_; n < (removed_image.xl_ + removed_image.image_x_dim_); n++)
+			    for (int m = removed_image.yt_; m < (removed_image.yt_ + removed_image.image_y_dim_); m++)
+				if(used_space[n][m] != 0) {
+				    used_space[n][m]--;
+				if (used_space[n][m] > NO_IMAGES_OF_OVERLAP)
+				    overlap = true;
+				}
+			
+			// sets the image as fresh and adds it to the vector of images previously seen
+			removed_image.fresh = true;
+			notinuse_.addElement(removed_image);
+		    }
+		    else{
+			i++;
+		    }    
+		
+	    }
+    }
+    
+  
+    /** Alters the images currently on display in the applet <br>
+     *  Changes are prioritised in the following way:
+     *  1. If there are images that have been downloaded and are yet to be displayed 
+     *  they will be added to the list of images in use. <br>
+     *  2. Otherwise if there are images that have previously been displayed but
+     *  are not currently on the applet screen, re-use one of these images. <br>
+     *  3. Otherwise if there are any images on screen at all, take the oldest and
+     *  repaint it as the newest. <br>
+     *  Then the collage is asked to display and repaint with the new image set. */
+
+     public  void next_frame()
+    {
+	double random = Math.random();
+	
+     
+	 if (inuse_ready_.size() > 0){
+	    int pos = (int) ((inuse_ready_.size() - 1) * random);
+	    CollageImage collage_image = (CollageImage) inuse_ready_.remove(pos);
+	    inuse_.addElement(collage_image);
+ 	}
+	else if (notinuse_.size()>0)
+		{
+		    int position = (int) ((notinuse_.size() - 1) * random);
+		    
+		    CollageImage collage_image = (CollageImage)notinuse_.elementAt(position);
+		    notinuse_.remove(position);
+		    inuse_.addElement(collage_image);
+		    
+		    if (app_.verbosity()>3)
+		    {
+			System.err.println("Re-using an image not on screen");
+		    }
+		}
+	    else{
+		if (app_.verbosity()>=4)
+		    System.err.println("No images in download area");
+	    }
+
+	display_collage();
+	
+    }
+  
+  
+
+    /** Paints the applet on the screen */
+    public void paint(Graphics g)
+    {
+
+	screen_graphic_.setColor(bgcolor_);
+	screen_graphic_.fillRect(0,0,app_x_dim_,app_y_dim_);
+
+	// get each image currently onscreen inturn
+	
+	for (int i=0; i < inuse_.size(); i++)
+	    {
+          
+            CollageImage collage_image =null;
+           try{
+		   collage_image = (CollageImage)inuse_.elementAt(i);
+		   start_paint = true;
+		}
+            catch(Exception e){
+		  System.out.println("exception in paint");					
+              break;
+	     }
+	   // don't paint new images yet
+		if (collage_image.fresh) {
+		  if (app_.verbosity()>=1) {
+			System.err.println("doing nothing...  "+ collage_image.name_ +" is fresh.");
+		   }
+		}
+
+		// advanced image processing may be used
+		else if (is_java2_) {
+		  
+			//the alphacomposite controls the blending of these two images.
+			Graphics2D sg2d = (Graphics2D)screen_graphic_;
+			sg2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
+			sg2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
+					      RenderingHints.VALUE_ANTIALIAS_ON); 
+			collage_image.expand();
+			sg2d.drawImage(collage_image.image_, collage_image.af_, app_);
+		   }
+		// simple image collage
+		else
+		    {			// add the image to the collage
+			
+			screen_graphic_.drawImage(collage_image.image_, 
+						  collage_image.xl_, collage_image.yt_,
+						  collage_image.xr_, collage_image.yb_,
+						  0,0,collage_image.image_x_dim_-1,
+						  collage_image.image_y_dim_-1,  app_);
+	 	    }
+	
+	    }
+	
+        
+	finished_graphic_.drawImage(screen_buffer_,0,0,app_);
+	
+
+	if (finished_buffer_ != null)
+	    {
+		g.drawImage(finished_buffer_, 0, 0, app_);
+		if (!start_paint){
+		    g.setColor(Color.white);
+		    g.setFont(new Font("font",Font.PLAIN+Font.BOLD,30));
+		    g.drawString("Downloading" + dots[(dots_nums++)%dots.length],app_x_dim_/3-20,app_y_dim_/2-2);
+		}
+	    }
+	
+
+    }
+
+    /** Runs display thread by repeatedly calling the next frame,
+     *  waiting for a specified delay period between calls */
+    public void run() {
+	try {
+	    
+	    Thread curr_thread = Thread.currentThread();
+	    
+	    while (curr_thread == this) {
+		if (inuse_ready_.size() >= 1){
+		    Thread.sleep(1000);		    
+		    continue;
+		}    
+		CollageImage collage_image = download_images_.getCollageImage();
+ 	
+		if (collage_image !=null){
+		    inuse_ready_.addElement(collage_image);	
+ 		}
+		curr_thread = Thread.currentThread();
+	    }
+	        
+	} catch (Exception e) {
+	   e.printStackTrace();
+           System.out.println("Display images thread is interrupted");
+	}
+
+	System.out.println("Display images thread stoped");
+          
+    }
+
+}
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadImages.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadImages.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadImages.java	(revision 16571)
@@ -0,0 +1,166 @@
+package org.nzdl.gsdl.GsdlCollageApplet;
+
+import java.awt.*;
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.awt.image.*;
+import java.awt.geom.*;
+
+/** 
+ *  @author Katrina Edgar
+ *  @author David Bainbridge
+ *
+ *  Stores images that are downloaded but have not yet been displayed
+ *  in the applet. Provides methods to add to and remove from this list
+ *  and check it's size. It uses an inner class to store the data for these
+ *  images, comprising of three parts: the image itself, it's source url
+ *  and the name of the image */
+public class DownloadImages {
+
+    /** Data structure to store an image that has been downloaded and is
+     *  waiting to be used. */
+    public class ImageUrlTriple {
+
+	Image image_;
+	String urlString_;
+	String name_;
+        URL url_;
+
+	/** Constructs a downloaded image structure from the given parameters
+	 *  @param image the graphical image
+	 *  @param url the source url for this image
+	 *  @param name the name of the image file */
+	public ImageUrlTriple (Image image, URL url, String urlString, String name)
+	{
+	    image_ = image;
+	    url_ = url;
+            urlString_ = urlString; 
+	    name_ = name;
+	}
+
+	Image image() {
+	    return image_;
+	}
+
+	String urlString() {
+	    return urlString_;
+	}
+
+	String name() {
+	    return name_;
+	}
+
+	URL url(){
+	    return url_;
+	}
+
+    }
+
+   
+    ImageUrlTriple downloaded_image;
+    CollageImage collage_image; 
+
+    /** Refers to applet */
+    GsdlCollageApplet app_ = null;
+    boolean isJava2_;
+    int num_of_downloads = 1;
+    boolean stopDownload;
+
+    MediaTracker tracker_;
+
+    /** Initialises an empty vector to store downloaded images in and sets
+     *  the verbosity for this class */
+    public DownloadImages(GsdlCollageApplet app, int verbosity, boolean isJava2)
+    {
+	
+        app_=app;
+        isJava2_= isJava2;
+    }
+
+    /** Push a new image into the vector of downloaded images
+     *  @param image the graphical image to add
+     *  @param url the source url of the image
+     *  @param name the name of the image to add */
+    public  synchronized int downloadImage(MediaTracker tracker, URL url, String urlString, String name)
+    {
+	
+	tracker_= tracker;
+
+	while (downloaded_image != null ){
+	    System.out.println(Thread.currentThread().getName() + " wait to download..."); 
+	    try{
+		wait();
+	    }
+	    catch(InterruptedException e){
+		return 0;
+	    }
+
+	}
+      
+	Image image = Toolkit.getDefaultToolkit().getImage(url);
+	tracker_.addImage(image,num_of_downloads);
+
+	try{
+	    tracker_.waitForID(num_of_downloads);
+	}
+	catch (InterruptedException e){
+	    notify();
+	    return num_of_downloads;
+	}
+	
+
+	downloaded_image  = new ImageUrlTriple(image,url,urlString,name);
+
+	notify();
+       
+	return num_of_downloads ;
+    }
+ 
+ 
+    /** Remove the image from the specified position in the array of downloaded images
+     *  @return an ImageUrlTriple containing the image, url and image name */
+    public synchronized CollageImage getCollageImage()
+    {
+	if (stopDownload)  return null;   
+
+	while (downloaded_image == null){
+	    System.out.println(Thread.currentThread().getName() + " wait to get Collage image...");
+	    try{
+		wait();
+	    }
+	    catch(InterruptedException e){
+		//e.printStackTrace();
+		downloaded_image = null;
+		notify();
+		return null;
+	    }
+	}
+         
+      	if (tracker_.statusID(num_of_downloads, false) == MediaTracker.COMPLETE){
+	    collage_image = new CollageImage(app_,isJava2_,downloaded_image);
+	    downloaded_image = null; 
+	    num_of_downloads++;
+	    notify();
+	    return collage_image;
+	}
+	else{
+	    if ((tracker_.statusAll(false) & MediaTracker.ERRORED) != 0){
+		//System.out.println(downloaded_image.name_);
+		downloaded_image = null;
+		num_of_downloads++;
+		notify();
+		return null;
+	    }
+	}
+	
+	return null;
+
+    }
+
+    public void stopDownload(){
+        stopDownload = true;
+    }
+
+ 
+}
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadUrls.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadUrls.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadUrls.java	(revision 16571)
@@ -0,0 +1,596 @@
+package org.nzdl.gsdl.GsdlCollageApplet;
+
+import java.awt.*;
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+import javax.swing.ImageIcon; //****
+
+
+/** 
+ *  @author Katrina Edgar
+ *  @author David Bainbridge
+ *
+ *  Controls retrieval of images from the specified starting url. Follows appropriate
+ *  links from this starting point, traversing in a tree-like state through several other
+ *  pages. Filters images and links based on specified parameters. Also controls the quantity
+ *  of downloading that occurs by restricting the number of downloaded images that are yet to
+ *  be displayed to 10, and the total number of downloads allowed is also restricted by
+ *  the applet application (to prevent downloading occuring infinitely). */
+
+public class DownloadUrls extends Thread {
+
+    /** Refers to applet */
+    GsdlCollageApplet app_          = null;
+    /** Refers to download thread */
+    DownloadImages download_images_ = null;
+
+    /** The address from which the application should start looking for images */
+    String starting_url_  = null;
+
+    /** the root directory of Greenstone*/  
+    String document_root_ = null;
+
+
+    /** CHRIS - Holds the contents of the collection's assoc directory */
+    //    File[] assocDir_ = null;
+
+    /** Restricts links followed from the starting url to links that contain this string */
+    String href_musthave_ = null;
+    /** Restricts links followed from the starting url to links that do not contain this string. 
+     *  Also prevents image names from containing this string */
+    String image_mustnothave_ = null;
+    /** Ignore images whose names begin with this string */
+    String image_ignore_  = null;
+    /** Restricts the types of images included in the collage, for example jpg, gif, etc. */
+    String image_type_ = null;
+
+    /** A static delay used when attempting to download more images into a full downloading buffer */
+    final int delay_       = 3000;
+    /** The maximum number of images to have downloaded and not yet displayed */ 
+    final int buffer_size_ = 1;
+
+    /** Used in cases where the image maps to a url outside of it's original location.
+     *  When used with Greenstone the collage images will refer to documents in the collections
+     *  from which the images are sourced. When used individually, the images may be saved into
+     *  a user directory and the pages they reference may be external hyperlinks. */
+    Hashtable external_links_ = null;
+
+    /** Records all urls which have already been examined */
+    Hashtable visited_url_  = null;
+    /** Determines whether there are still pages to examine and images to download */
+    boolean thread_running_ = true;
+
+    int verbosity_ = 0;
+
+     /** Records all images which have already been examined */
+    Hashtable visited_images_  = null;
+        
+    MediaTracker tracker;
+
+    /** Constructor to initialise a download thread from which images are found, 
+     *  saves parameters into local variables for use within the class.
+     *
+     *  @param app reference to the applet
+     *  @param download_images class which stores the images retrieved in triplets
+     *  @param starting_url the url from which the search for images should begin
+     *  @param href_musthave restricts links to only those containing this string
+     *  @param image_mustnothave restricts links and image names to only those that don't contain this string
+     *  @param image_ignore restricts the beginning of image names
+     *  @param image_type restricts the type of images included in the collage to those named */
+    public DownloadUrls(GsdlCollageApplet app, 
+			DownloadImages download_images, String starting_url, 
+			String href_musthave, String image_mustnothave, 
+			String image_ignore, String image_type, String document_root,int verbosity, MediaTracker trk)
+    {
+	super("DownloadUrls");
+	app_             = app;
+	download_images_ = download_images;
+
+	starting_url_  = starting_url;
+	href_musthave_ = href_musthave;
+	image_mustnothave_ = image_mustnothave;
+	image_ignore_  = image_ignore;
+	image_type_    = image_type;
+	document_root_ = document_root; 
+	verbosity_ = verbosity;
+        tracker = trk;
+
+	System.err.println("starting_url_ "  + starting_url +"\n"+
+	                   "href_musthave_ " +  href_musthave +"\n"+
+			   "image_mustnothave_ " + image_mustnothave+"\n"+
+			   "image_ignore_ "+  image_ignore+"\n"+
+			   "image_type_ "+ image_type+"\n"+
+			   "document root "+ document_root_
+			       );
+
+
+
+
+    }
+
+  
+    /** Determines whether or not a url has already been examined
+     *
+     *  @param url_string the url to check
+     *  @return true if the url has been visited, false if not */
+    public boolean already_visited(String url_string)
+    {
+	int hash_pos = url_string.indexOf("#");
+	if (hash_pos>0)
+	 {
+	     // strip off #anchor reference
+	     url_string = url_string.substring(0,hash_pos);
+	 }
+
+      	// if the url has been visited before, return true
+	if (visited_url_.containsKey(url_string))
+	{
+	    if (verbosity_ > 3)
+		{
+		    System.err.println("Visited " + url_string + " before!");
+		}
+	    return true;
+	}
+	
+	visited_url_.put(url_string,"visited");
+
+	return false;
+    }
+
+  /** Determines whether or not an images or its screenview has been visited)
+     *  has already been examined
+     *
+     *  @param url_string the url to check
+     *  @param img_name the image to check
+     *  @return true if the url has been visited, false if not */
+    public boolean image_visited(String url_string, String img_name)
+    {
+	String hash_dir = url_string.substring(0,url_string.lastIndexOf("/"));  
+    
+ 	if ( visited_images_.containsKey(hash_dir)){
+	    Hashtable hashed_images = (Hashtable)visited_images_.get(hash_dir);   
+	   
+            if (img_name.startsWith("screenview")){
+		return true;
+	    }
+
+	    if (hashed_images.containsKey(img_name)){
+		return true;
+	    }
+         
+            Enumeration enu = hashed_images.keys();
+            for(;enu.hasMoreElements();){
+		String name = (String)enu.nextElement();
+		if(name.startsWith("screenview")){
+		    return true;
+		}
+	    }
+    
+            hashed_images.put(img_name,"visited");           
+	}
+	else{
+	    Hashtable hashed_images = new Hashtable();
+	    hashed_images.put(img_name,"visited");
+	    visited_images_.put(hash_dir,hashed_images);	    
+	}
+	     
+	return false;
+    }
+
+   
+
+
+
+    /** Restricts the type of images that can be included in the collage
+     *
+     * @param url_string the url to check
+     * @return true if the image is of a specified type, false if not */
+    public boolean image_file_extension(String url_string)
+    {
+	// lower case comparisons
+	String url_lstring = url_string.toLowerCase();
+
+	if (image_type_ == null)
+	    return true;
+
+	String tmp = image_type_;
+	String original_image_type_ = image_type_;
+
+	while (image_type_ != null && image_type_.indexOf("%") >= 0) {
+	    
+	    tmp = image_type_.substring(0, image_type_.indexOf("%"));
+             
+	    if (image_type_.length() > image_type_.indexOf("%") + 1)
+		image_type_ = image_type_.substring(image_type_.indexOf("%") + 1, image_type_.length());                 
+	    else
+		image_type_ = null;
+            
+	    if (!tmp.trim().equals("") && url_lstring.endsWith(tmp)) {
+		image_type_ = original_image_type_;
+		return true;
+	    }
+	}
+
+	if (image_type_ != null && url_lstring.endsWith(image_type_)) {
+		image_type_ = original_image_type_;
+		return true;
+	}
+
+	image_type_ = original_image_type_;
+	return false;
+    }
+
+    /** Restricts images to only those that satisfy several specified conditions
+     *  regarding the content of the image name and url.
+     *
+     *  @param url_string the url to check
+     *  @return true if the image is satisfactory, false if not */
+    public boolean filter_image(String url_string)
+    {
+        
+	if (image_ignore_==null || !url_string.startsWith(image_ignore_))
+	{
+	    if (!already_visited(url_string))
+	    {
+		if (image_mustnothave_ != null) {
+		    
+		    String tmp = image_mustnothave_;
+		    String original_image_mustnothave_ = image_mustnothave_;
+
+		    while (image_mustnothave_ != null && image_mustnothave_.indexOf("%") >= 0) {
+	    
+			tmp = image_mustnothave_.substring(0, image_mustnothave_.indexOf("%"));
+			if (image_mustnothave_.length() > image_mustnothave_.indexOf("%") + 1)
+			    image_mustnothave_ = image_mustnothave_.substring(image_mustnothave_.indexOf("%") + 1, 
+									      image_mustnothave_.length());
+			else
+			    image_mustnothave_ = null;
+                          			
+                     
+                         
+			if (!tmp.trim().equals("") && url_string.indexOf(tmp) >= 0) {
+			   
+			    image_mustnothave_ = original_image_mustnothave_;
+			    return false;
+			}
+       		    }
+
+		    image_mustnothave_ = original_image_mustnothave_;
+                    
+		    if (image_mustnothave_ != null && url_string.indexOf(image_mustnothave_) >= 0) {
+			image_mustnothave_ = original_image_mustnothave_;
+			return false;
+		    }
+
+		    if (verbosity_ > 2) {
+			System.err.println("src url = "+ url_string);
+		    }
+		    
+		    image_mustnothave_ = original_image_mustnothave_;
+		    
+		}
+	
+	    }
+            
+	}
+    
+	return true;
+    }
+
+    /** Restricts links to only those that satisfy several specified conditions
+     *  regarding the address of the link.
+     *
+     *  @param url_string the url to check
+     *  @param new_url_string the url from which this link was found
+     *  @param depth the number of links followed on this path
+     *  @return true if the image is satisfactory, false if not */
+    public boolean filter_href(String url_string, String new_url_string, int depth)
+    {
+	boolean has_href = false;
+	String tmp = href_musthave_;
+	String original_href_musthave_ = href_musthave_;
+
+	// checks that it does contain this content
+	if (href_musthave_ !=  null) {
+
+	    while (href_musthave_ != null && href_musthave_.indexOf("%") >= 0) {
+		
+		tmp = href_musthave_.substring(0, href_musthave_.indexOf("%"));
+		if (href_musthave_.length() > href_musthave_.indexOf("%") + 1)
+		    href_musthave_ = href_musthave_.substring(href_musthave_.indexOf("%") + 1, href_musthave_.length());
+		else
+		    href_musthave_ = null;
+		
+		if (url_string.indexOf(tmp) >= 0)
+		    has_href = true;
+	    }
+	    
+	    if (href_musthave_ != null && url_string.indexOf(href_musthave_) >= 0)
+		has_href = true;
+
+	    href_musthave_ = original_href_musthave_;
+	}
+
+	tmp = image_mustnothave_;
+	String original_image_mustnothave_ = image_mustnothave_;
+
+	// checks that it doesn't contain this content
+	if (image_mustnothave_ != null) {
+
+	    while (image_mustnothave_ != null && image_mustnothave_.indexOf("%") >= 0) {
+		
+		tmp = image_mustnothave_.substring(0, image_mustnothave_.indexOf("%"));
+		if (image_mustnothave_.length() > image_mustnothave_.indexOf("%") + 1)
+		    image_mustnothave_ = image_mustnothave_.substring(image_mustnothave_.indexOf("%") + 1, image_mustnothave_.length());
+		else
+		    image_mustnothave_ = null;
+		
+		if (url_string.indexOf(tmp) >= 0)
+		    has_href = false;
+	    }
+	    if (image_mustnothave_ != null && url_string.indexOf(image_mustnothave_) >= 0)
+		has_href = false;
+	  
+	    image_mustnothave_ = original_image_mustnothave_;
+	}
+
+	// return true if the link is valid and false if not
+	if (href_musthave_==null || has_href)
+	{
+	    // might be another URL
+	    if (depth < app_.maxDepth())
+	    {
+		if (!new_url_string.startsWith(url_string))
+		{
+		    return true;
+		}
+	    }
+	}
+	return false;
+    }
+
+    /** Adds an image to the stored downloaded images as a triplet.
+     *  Ensures that the number of images downloaded but not displayed at
+     *  any one time is controlled by using a buffer. If the buffer is
+     *  full this function will wait until space becomes available before
+     *  continuing. It also restricts the
+     *  total number of images to download as specified by the applet.
+     *
+     *  @param url the image to download
+     *  @param from_url the url that this image was sourced from
+     *  @param img_name the name of the image */
+    public void add_image(URL url, String from_url, String img_name)
+    {
+	    // get the image from the url
+	    if (verbosity_>=2) {
+		System.err.println("  Downloading image URL: " + url.toString());
+	    }
+            
+           if (image_visited(url.toString(),img_name)) return;
+
+	   int size = download_images_.downloadImage(tracker,url, from_url, img_name);
+          
+	   try{
+	       // if have completed the maximum number of downloads for the
+	       // application then stop
+	       if (size == app_.maxDownloads()) {
+		   stop();
+	       }
+	       
+	   }
+	   catch (Exception e) {
+	       thread_running_ = false;
+	       stop();
+	       e.printStackTrace();
+	   }
+    }
+
+    /** Connects to the starting url and looks for all images and links from this
+     *  original page. Image links are processed first, so that any images found can be
+     *  downloaded immediately and placed on the applet. Secondly, the links to other
+     *  pages are recursively processed by this function and treated as a starting url
+     *
+     *  @param new_url the url from which to start searching for images and links
+     *  @param depth the number of links that have been followed on this path */
+    public void rec_add_images(String new_url, int depth)
+    {
+   
+	if (already_visited(new_url)) return;
+
+	// check if there is a scenario where external hyperlinks are being used
+	externalLinks();
+	String img_name = new String();
+
+	// connect to the url
+	CURL curl = new CURL(new_url);
+	if (curl.connected_ok())
+	{
+	    if (verbosity_ >= 1) {
+		System.err.print("Connected OK ... ");
+	    }
+
+	    // read the page
+	    curl.readAll();
+	    if (verbosity_ >= 1) {
+		System.err.println("URL read.");
+	    }
+
+	    // get all the <code><img src=</code> links into a vector
+	    Vector src_links = curl.getSrcLinks();
+
+        	    
+	    if (verbosity_ >= 2) {
+		System.err.println("  Got src links... there are " + src_links.size() + " of them.");
+	    }
+	    // process each of the image links according to the parameters given.
+	    for (int i = 0; i < src_links.size(); i++) 
+	    {
+		URL url = (URL)src_links.get(i);
+		String url_string  = url.toString();
+            
+		//System.err.println(" source links " + i + " ["  + url_string +"]");
+
+		if (verbosity_ >= 4) {
+		    System.err.println("    Unfiltered: src_link[" + i + "] = " + url_string);
+		}
+
+		if (image_file_extension(url_string))
+		    {
+			if (filter_image(url_string))
+			    {
+				img_name = url_string.substring(url_string.lastIndexOf("/") + 1, url_string.length());
+                                
+				if (verbosity_ >= 2) {
+				    System.err.println("    Filtered: src_link[" + i + "] = " + url_string);
+				}
+
+				if ((external_links_ != null) && (!external_links_.isEmpty())) {
+				    String ext = (String) external_links_.get(img_name);
+				          
+				           
+				    if (ext != null){
+					add_image(url, ext, img_name);
+                                       
+				    }
+				    else{
+				
+					add_image(url, new_url, img_name);
+				    }
+				}
+				else {
+				    
+				    add_image(url, new_url, img_name);
+				}
+                           
+				
+			    }
+		
+		    }
+		
+	    }
+
+	    // get all the <code><a href=</code> links into a vector
+	    Vector href_links = curl.getHrefLinks();
+	    
+	  
+	    if (verbosity_ >= 2) {
+		System.err.println("  Got href links... there are " + href_links.size() + " of them.");
+	    }
+	    
+
+	    // process each of the href links according to the parameters given.
+	    for (int i = 0; i < href_links.size(); i++) 
+		{
+           
+		    URL url = (URL)href_links.get(i);
+		    String url_string  = url.toString();
+		    //System.err.println(" href links " + i + "["  + url_string +"]");      
+
+		    if (image_file_extension(url_string))
+			{
+			                      
+			    if (filter_image(url_string))
+
+				{
+				 					    
+				    img_name = url_string.substring(url_string.lastIndexOf("/") + 1, url_string.length());
+
+				    if ((external_links_ != null) && (!external_links_.isEmpty())) {
+					String ext = (String) external_links_.get(img_name);
+
+					if (ext != null) 
+					    add_image(url, ext, img_name);
+					else
+					    add_image(url, new_url, img_name);
+				    }
+				    else {
+					add_image(url, url_string, img_name);
+				    }
+				}
+			}
+		    else
+			{
+			    if (filter_href(url_string,new_url,depth))
+				{
+		
+				    rec_add_images(url_string,depth+1);
+				    
+				}
+			}
+		}
+	}
+   
+	else {
+	    System.err.println("Unable able to download "+new_url);
+	}
+    }
+
+    
+    /** Used in cases where the image maps to a url outside of it's original location.
+     *  When used with Greenstone the collage images will refer to documents in the collections
+     *  from which the images are sourced. When used individually, the images may be saved into
+     *  a user directory and the pages they reference may be external hyperlinks. 
+     *  This function reads that external links file and creates a hash map of the image to
+     *  its external hyperlink. If the file does not exist the download thread will continue
+     *  and assume the first case, that links are internal. */
+    public void externalLinks() {
+	external_links_ = null;
+	try {
+
+	    if (starting_url_ == null || (document_root_ != null && starting_url_.indexOf(document_root_) >= 0) ){ 
+		return;
+	    }
+	    
+	    // open a url to the file written
+	    URL u = new URL(starting_url_ + "externallinks");
+
+	    BufferedReader r = new BufferedReader(new InputStreamReader(u.openStream()));
+	    
+	    external_links_ = new Hashtable();
+
+	    String l = r.readLine();
+	    // split the line of the space, first part is the image, second part the link
+	    while (l != null) {
+	
+		String tmp1 = new String();
+		String tmp2 = new String();
+
+		if (l.indexOf(" ") >= 0) {
+		    
+		    tmp1 = l.substring(0, l.indexOf(" "));
+		    if (l.length() > l.indexOf(" ") + 1)
+			tmp2 = l.substring(l.indexOf(" ") + 1, l.length());
+		    else
+			tmp2 = null;
+		    
+		    if (tmp2 != null) {
+			
+			external_links_.put(tmp1, tmp2);
+			//System.err.println(tmp1 + " " + tmp2);
+		    }
+		}
+		l = r.readLine();
+	    }
+		
+		r.close();
+
+	} catch (Exception e) {
+	    e.printStackTrace();
+	    return;
+	}
+    }
+
+    /** Controls the download thread */
+    public void run () 
+    {
+	System.err.println("Starting download thread.");
+	visited_url_ = new Hashtable();
+	visited_images_ = new Hashtable();
+
+       	rec_add_images(starting_url_,1);
+	download_images_.stopDownload();
+	System.err.println("Download thread finished.");
+    }
+}
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/GsdlCollageApplet.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/GsdlCollageApplet.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/GsdlCollageApplet.java	(revision 16571)
@@ -0,0 +1,406 @@
+package org.nzdl.gsdl.GsdlCollageApplet;
+
+import java.applet.Applet;
+import java.awt.*;
+import java.net.*;
+
+/**
+ * 
+ *  @author Katrina Edgar
+ *  @author David Bainbridge
+ *
+ * Main class for the GsdlCollageApplet<br>
+ * Processes the parameters passed through the Applet<br>
+ * Builds an appropriate starting url from these parameters<br>
+ * Creates a storage class for downloaded images<br>
+ * Starts thread to download images and their associated url<br>
+ * Starts thread to display downloaded images on the applet screen<br>
+ */
+ 
+public class GsdlCollageApplet extends Applet {
+
+
+    /** Amount of error checking output produced <br>
+     *  Ranges from 0 - no output to 3 - maximum output */ 
+    protected int verbosity_     = 0;
+    /** Indicates whether java2 functionality should be used <br>
+     *  If true will allow advanced image processing techniques to occur, 
+     *  such as fading and colouring using pixel manipulation <br>
+     *  If false, images will maintain an alpha value of 1 (appear solid), 
+     *  newer images will simply be pasted on top of existing images <br> */
+    protected boolean isJava2_  = true;
+    /** Number of nested links to follow When used with greenstone,
+     *  controls to which level of the document links will be followed For
+     *  example a maximum depth of 1 will mean only the top page of a
+     *  document will be examined, while a depth of 2 will include sections
+     *  within this document, 3 includes sections within sections, and so
+     *  on */
+    protected int maxDepth_     = 3;
+
+    /** Maximum number of images to display on the canvas */
+    protected int maxDisplay_ = 25;
+
+    /** Maximum number of downloaded images to store <br> Prevents applet
+     *  from using excessive amounts of bandwidth by downloading too many
+     *  images simulataneously*/
+    protected int maxDownloads_ = Integer.MAX_VALUE;
+
+    /** Types of images permitted in the collage, for example gif, jpg,
+     * png... */
+    protected String imageType_ = ".jpg%.png";
+
+    /** Caption of the collage */
+    protected String caption_ = "";
+
+    /** Background color of applet screen */
+    protected Color bgcolor_ = new Color(150, 193, 155);
+
+    /** Time lapse between repainting of the applet */
+    protected int refreshDelay_ = 2000;
+    
+    /** Stores an image and url pair and provides associated methods */
+    protected DownloadImages download_images_ = null;
+    /** Downloads images from a starting url, recursively follows nested
+     * links */
+    protected DownloadUrls download_thread_   = null;
+    /** Image processing and placement on applet screen */
+    protected DisplayImages display_thread_   = null;
+
+   
+
+    /** Gets verbosity */
+    public int verbosity()    { return verbosity_; }
+    /** Gets maximum depth for nested links */
+    public int maxDepth()     { return maxDepth_; }
+
+    /** Gets maximum number of images to display */
+    public int maxDisplay() { return maxDisplay_;}
+
+    /** Gets maximum number of images to store during downloading */
+    public int maxDownloads() { return maxDownloads_; }
+    /** Gets the refresh delay used between repaint */
+    public int refreshDelay() { return refreshDelay_; }
+
+    /** Gets parameters from the applet code and stores locally.
+     * Forms a starting url for image retrieval to begin from.
+     * The starting url is formed either by:
+     *  * Using the image_url parameter as provided, which is assumed to 
+     *     be a complete url
+     *  * If this parameter does not exist, the assumption is that the 
+     *     collage is being incorporated with the Greenstone Digital Library 
+     *     Software. The starting url is formed by concatenating
+     *     the gwcgi, collection and classifier parameters as provided.
+     * Then starts downloading and displaying images */
+
+    Thread paint ;
+
+    public void init() 
+    {	    
+	if (verbosity_ >= 4) { 
+	    System.err.println("Attempting to retrieve parameters...");
+	}
+
+	// gets the parameters specified
+	String verbosity_param      = getParameter("verbosity");
+	String is_java2_param       = getParameter("isJava2");
+	String max_depth_param      = getParameter("maxDepth");
+	String max_downloads_param  = getParameter("maxDownloads");
+	String max_display_param    = getParameter("maxDisplay");
+	String refresh_delay_param  = getParameter("refreshDelay");
+	String image_type_param     = getParameter("imageType");
+	String bgcolor_param        = getParameter("bgcolor");
+	String caption_param        = getParameter("caption");
+        String document_root        = getParameter("documentroot");
+        String gwcgi                = getParameter("gwcgi");        
+
+
+	// Check it isn't null
+	if ((verbosity_param!=null) && (!verbosity_param.startsWith("_"))) {
+	    verbosity_  = Integer.parseInt(verbosity_param);
+	}
+	else {
+	    verbosity_ = 1;
+	}
+
+
+	if (verbosity_ >= 4) { 
+	    System.err.println("Got parameters.");
+	}
+
+	if (caption_param != null && !caption_param.startsWith("_")) {
+	    caption_ = caption_param;
+	}
+	else {
+	    if (verbosity_ >= 4) { 
+		System.err.println("No Caption: setting to a space.");
+	    }
+	    caption_ = " ";
+	}
+
+	if ((bgcolor_param != null) && (!bgcolor_param.startsWith("_"))) {
+	    if (bgcolor_param.startsWith("#")) {
+		bgcolor_ = Color.decode(bgcolor_param);   
+	    }
+	    else {
+		String [] c = bgcolor_param.split(",");
+		if (c.length == 3)
+		    bgcolor_ = new Color(Integer.parseInt(c[0]), Integer.parseInt(c[1]), Integer.parseInt(c[2]));
+	    }
+	    if (verbosity_ >= 4){ 
+		System.err.println("Set BG to be " + bgcolor_.toString());
+	    }
+	}
+	else {
+	    if (verbosity_ >= 4) { 
+		System.err.println("No BG: setting to NZDL green.");
+	    }	   
+	    bgcolor_ = new Color(150, 193, 155);
+	}
+
+	if ((image_type_param != null) && (!image_type_param.startsWith("_"))) {
+	    imageType_ = image_type_param;
+	}
+
+	if ((is_java2_param == null) || (is_java2_param.equals("auto")) || (is_java2_param.startsWith("_"))) {
+	    String version = System.getProperty("java.version");
+	    version = version.substring(0, version.lastIndexOf("."));
+	    System.err.println("VERSION: " + version);
+	    float ver = (new Float(version)).floatValue();
+	    isJava2_ = (ver >= 1.2) ? true : false;
+	}
+	else {
+	    isJava2_ = (is_java2_param.equals("true")) ? true : false;
+	}
+
+	if ((max_depth_param != null) && (!max_depth_param.startsWith("_"))) {
+	    // System.err.println("maxDepth = " + max_depth_param);
+	    maxDepth_ = Integer.parseInt(max_depth_param);
+	}
+
+	if ((max_downloads_param!=null) && (!max_downloads_param.startsWith("_"))) {
+	    maxDownloads_ = Integer.parseInt(max_downloads_param);
+            System.out.println(" maxDownloads " + maxDownloads_ );
+	    maxDownloads_=50;
+	}
+
+	if ((max_display_param!=null) && (!max_display_param.startsWith("_"))) {
+	    maxDisplay_ = Integer.parseInt(max_display_param);
+              
+	}
+
+	if ((refresh_delay_param!=null) && (!refresh_delay_param.startsWith("_"))) {
+	    refreshDelay_ = Integer.parseInt(refresh_delay_param);
+	}
+
+       
+        if (document_root !=null){          
+	    document_root = document_root.substring(1);
+            if (document_root.indexOf("/") > 0 ){
+		document_root = document_root.substring(0, document_root.indexOf("/"));
+	    }
+	    else{
+		document_root = gwcgi; 	
+	    }
+	}
+
+
+	String image_url  = getParameter("imageURL"); 
+	String image_ignore  = getParameter("imageIgnorePrefix"); 
+	String href_musthave  = getParameter("hrefMustHave"); 
+	String image_mustnothave = getParameter("imageMustNotHave");
+
+	// builds starting url when incorporated with Greenstone
+	if (image_url==null)
+	{
+	    String gwcgi_param  = getParameter("gwcgi");
+	    gwcgi_param = tidy_URL(gwcgi_param, true);
+	
+	    String collection_param  = getParameter("collection");
+	    String classifier_param  = getParameter("classifier");
+
+	    image_url = gwcgi_param + "a=d";
+	    image_url += "&c=" + collection_param;
+	    image_url += "&cl=" + classifier_param;
+	}
+
+	MediaTracker trk = new  MediaTracker(this);
+
+	// creates a class to store the image and it's associated url
+	download_images_ = new DownloadImages( this, verbosity_,isJava2_ );
+	// starts the download image thread with the starting url
+
+        download_thread_ = new DownloadUrls(this, download_images_, 
+					    image_url, href_musthave, image_mustnothave, 
+					    image_ignore, imageType_,document_root,verbosity_,trk);
+	// starts the display image thread with the currently downloaded images
+	display_thread_ = new DisplayImages(this, download_images_,isJava2_, bgcolor_);
+	
+    }
+
+ 
+    /** Goes to the url associated with the image that is clicked on screen<br>
+     *  Displays the url containing the image in a new window */
+    public boolean mouseDown(Event event, int x, int y)
+    {
+	// determines which image was clicked on
+	CollageImage cimage = display_thread_.clickedOnImage(x,y);
+	// if they were clicking on an image (as opposed to background)
+	if (cimage != null)
+	{
+	    System.err.println("Click on image: from url = " + cimage.from_url_);
+	    try {
+		// displays the associated url in a new window
+                URL from_url = null;		
+		
+		java.util.regex.Pattern p = java.util.regex.Pattern.compile("cl=CL\\d(\\.\\d)*\\s");
+		java.util.regex.Matcher m = p.matcher(cimage.from_url_.trim()+" ");
+
+                if (m.find() ){
+		    from_url = cimage.url_;
+		}
+		else{
+		    from_url =  new URL(cimage.from_url_  + "#" + cimage.name_);
+		}
+		getAppletContext().showDocument(from_url,"gsdlDoc");
+	    } 
+	    catch (MalformedURLException e) { 
+		e.printStackTrace();
+	    }
+
+	}
+        return true;
+    }
+    
+    /** Start threads for downloading and displaying images */
+    public void start() 
+    {
+	
+	download_thread_.start();	
+
+	display_thread_.start();
+
+         paint =  new Thread(new Runnable(){
+                public void run() {
+		    try {
+
+			Thread curr_thread = Thread.currentThread();
+	    
+			while (curr_thread == paint) {
+	      
+			   repaint();
+			    
+			    Thread.sleep(2000);
+			    curr_thread = Thread.currentThread();
+			}
+
+	    
+		    } catch (Exception e) {
+			
+		    }
+		}
+
+
+	    });
+
+	    paint.start();
+   
+    }
+
+    /** Stops threads for downloading and displaying images */
+    public void stop() 
+    {
+	download_thread_.stop();
+	display_thread_.stop();
+	
+	download_thread_ = null;
+	display_thread_ = null;
+	
+    }
+
+    /** Destroys threads for downloading and displaying images */
+    public void destroyed() 
+    {
+	download_thread_ = null;
+	
+	display_thread_ = null;
+	
+    }
+
+
+    /** Repaints the applet */
+    public void update(Graphics g) 
+    { 
+	// System.err.println("Update called");
+	paint(g); 
+    } 
+    
+    /** Repaints the applet using the paint method of the thread that is
+     * currently displaying images */
+    public void paint(Graphics g) {
+	if (display_thread_!=null)
+	    {	
+	      
+	    	//display_thread_.display_collage();
+	    	  display_thread_.paint(g);
+	    }
+	else
+	    {
+		System.err.println("Applet still trying to paint!!");
+	    }
+
+	
+	
+    }
+
+  
+    
+    /** Ensures a URL address (as string) has a protocol, host, and file.
+     *
+     * If the URL is a CGI script URL, it should be tidied up so that it is
+     * appropriate to tage attrib=value pairs on the end.  This means it
+     * must either end with a "?" or (if it contains a question-mark
+     * internally) end with a "&". */
+    String tidy_URL(String address, boolean isCGI) {
+
+	// System.err.println("tidy URL: " + address);
+	
+	// make sure the URL has protocol, host, and file
+	if (address.startsWith("http")) {
+	    // the address has all the necessary components
+	} else if (address.startsWith("/")) {
+	    // there is not protocol and host
+	    URL document = getDocumentBase();
+	    String port = "";
+	    if (document.getPort()!=-1) {
+		port = ":" + document.getPort();
+	    }
+	    address = "http://" + document.getHost() + port  + address;
+	} else {
+	    // this URL is relative to the directory the document is in
+	    URL document = getDocumentBase();
+	    String directory = document.getFile();
+	    int end = directory.lastIndexOf('/');
+	    String port = "";
+	    if (document.getPort()!=-1) {
+		port = ":" + document.getPort();
+	    }
+	    directory = directory.substring(0,end + 1);
+	    address = "http://" + document.getHost() + port + directory + address;
+
+	}
+
+	// if the URL is a cgi script, make sure it has a "?" in ti,
+	// and that it ends with a "?" or "&"
+	if (isCGI) {
+	    if (address.indexOf((int) '?') == -1) { 
+		address = address + "?";
+	    } else if (!address.endsWith("?")) {
+		address = address + "&";
+	    }
+	}
+
+	return address;
+    }
+
+
+}
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/Makefile
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/Makefile	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/Makefile	(revision 16571)
@@ -0,0 +1,20 @@
+
+
+
+CLASSES = CURL.class CollageImage.class DisplayImages.class \
+          DownloadImages.class DownloadUrls.class GsdlCollageApplet.class \
+          MyAffineTransform.class
+
+all: GsdlCollageApplet.jar
+
+install:
+	cp GsdlCollageApplet.jar ../../../../../../bin/java/
+
+clean:
+	rm -f $(CLASSES) GsdlCollageApplet.jar
+
+GsdlCollageApplet.jar: $(CLASSES)
+	jar cf GsdlCollageApplet.jar org
+
+%.class : %.java
+	javac -d . -classpath ../../../.. $<
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/MyAffineTransform.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/MyAffineTransform.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/GsdlCollageApplet/MyAffineTransform.java	(revision 16571)
@@ -0,0 +1,154 @@
+package org.nzdl.gsdl.GsdlCollageApplet;
+
+public class MyAffineTransform {
+
+    public double scaleX = 0;
+    public double scaleY = 0;
+    public double translateX = 0;
+    public double translateY = 0;
+    public boolean overlap = false;
+
+    public MyAffineTransform (int image_x_dim, int image_y_dim) {
+
+	random_set_pos(image_x_dim, image_y_dim);
+    }
+
+    /** The amount to adjust the size of an image so that it fits into the applet screen
+     *  @param image_x_dim the width of the image to scale
+     *  @param image_y_dim the height of the image to scale
+     *  @return a value by which to scale the image to ensure it will fit in the applet */
+    private double scaleFactor (int image_x_dim, int image_y_dim) {
+
+	double scale_factor = 1.0;
+
+	// three quarters of the application width & height
+	int tol_app_x_dim = 3*DisplayImages.app_x_dim_/4;
+	int tol_app_y_dim = 3*DisplayImages.app_y_dim_/4;
+
+	// if the image is too big, calculate a fraction
+	// by which to reduce the image
+	if (image_x_dim>tol_app_x_dim)
+	{
+	    scale_factor = image_x_dim/tol_app_x_dim + 1;
+	}
+
+	if (image_y_dim>tol_app_y_dim)
+	{
+	    int y_scale_factor = image_y_dim/tol_app_y_dim + 1;
+	    // take the biggest of the two as the same fraction must
+	    // be applied to both the x and y values to keep the image
+	    // in proportion
+	    if (y_scale_factor>scale_factor)
+	    {
+		scale_factor = y_scale_factor;
+	    }
+	}
+
+	return scale_factor;
+    }
+
+    /** Determines the placement of new images on the applet screen <br>
+     *  First the image is scaled, then the function loops until a satisfactory
+     *  image position is found. This is done by randomly selecting an x and y
+     *  co-ordinate for the image, then determining how much whitespace will be
+     *  covered if the image were to be placed at this position in the collage.
+     *  The standards for loop termination are as follows:<br>
+     *  1. On any occasion a whitespace coverage of greater than 70% will result 
+     *  in the loop being terminated.<br>
+     *  2. After three times through the loop, a whitespace coverage of 50% will
+     *  also allow the loop to terminate (a less stringent condition). <br>
+     *  3. After seven times through, the loop will terminate and the best
+     *  position will be used by default.<br>
+     *  This function also updates the used space array after image position has been selected.
+     *  
+     *  @param image_x_dim the width of the image
+     *  @param image_y_dim the height of the image
+     *  @return a transform operation by which to move the image from the origin */
+    protected void random_set_pos(int image_x_dim, int image_y_dim) 
+    {
+
+	double scale_factor = scaleFactor(image_x_dim, image_y_dim);
+
+	// scale the image (will be 1 and therefore no change as a default)
+	image_x_dim/=scale_factor;
+	image_y_dim/=scale_factor;
+	
+	// initialise variables required to determine image placement
+	int image_x_pos = 0;
+	int image_y_pos = 0;
+	int best_x = 0;
+	int best_y = 0;
+	double best_clear = 0;
+	double clear = 100;
+	int stoploop = 0;
+	
+	do {
+	    // increment the loop counter
+	    stoploop++;
+
+	    // the number of positions that the image could occupy on the x axis
+	    int safe_x_dim = DisplayImages.app_x_dim_ - image_x_dim;
+	    double rx = Math.random();
+	    // randomly pick an x co-ordinate for the image
+	    image_x_pos= ((int)(rx*safe_x_dim));
+	    
+	    // same process as for the x co-ordinate
+	    // ensuring the y co-ordinate will fit on the screen
+	    int safe_y_dim = DisplayImages.app_y_dim_ - image_y_dim;
+	    double ry = Math.random();
+	    // randomly pick a y co-ordinate for the image
+	    image_y_pos= ((int)(ry*safe_y_dim));
+	    
+	    double whitespace = 0;
+	    double space = 0;
+	    
+	    // determine how much whitespace the image will cover if placed in the
+	    // current position and how much overlap will occur
+	    for (int n = image_x_pos; n < (image_x_pos + image_x_dim); n++) {
+		for (int m = image_y_pos; m < (image_y_pos + image_y_dim); m++) {
+		    if (DisplayImages.used_space[n][m] == 0)
+			whitespace++;
+		    space++;
+		}
+	    }
+	    
+	    // divide the amount of whitespace covered by the amount of overlap
+	    clear = whitespace/space;
+	    // if this value is better than previous calculations, save these co-ordinates
+	    if (clear > best_clear) {
+		best_x = image_x_pos;
+		best_y = image_y_pos;
+		best_clear = clear;
+	    }
+
+	    if ((image_x_dim > (DisplayImages.app_x_dim_ / 2)) || (image_y_dim > (DisplayImages.app_y_dim_ / 2)))
+		break;
+
+	} while ((clear < 0.70 || (stoploop > 3 && clear < 0.50)) && stoploop < 7);
+	    
+	// if we only terminated because we went through so many times,
+	// then we set the position to the best value possible
+	if (stoploop == 7) {
+	    image_x_pos = best_x;
+	    image_y_pos = best_y;
+	}
+
+	// indicate that the space where the image is to be placed is now used
+	for (int n = image_x_pos; n < (image_x_pos + image_x_dim); n++)
+	    for (int m = image_y_pos; m < (image_y_pos + image_y_dim); m++) {
+		DisplayImages.used_space[n][m]++;
+		if (DisplayImages.used_space[n][m] > DisplayImages.NO_IMAGES_OF_OVERLAP)
+		    overlap = true;
+	    }
+	
+	translateX = image_x_pos;
+	translateY = image_y_pos;
+	
+	// scale the image appropriately
+	scaleX = 1.0/scale_factor;
+	scaleY = 1.0/scale_factor;
+	
+	return;
+    }
+
+}
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/Makefile
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/Makefile	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/Makefile	(revision 16571)
@@ -0,0 +1,18 @@
+
+
+
+CLASSES = Phind.class ResultCanvas.class ResultItemDocument.class \
+          ResultTitle.class PhindTitle.class ResultDisplay.class \
+          ResultItemLink.class ResultBox.class ResultItem.class \
+          ResultItemPhrase.class PhindTitle.class URLUTF8Encoder.class
+
+all: Phind.jar
+
+clean:
+	rm -f $(CLASSES) Phind.jar
+
+Phind.jar: $(CLASSES)
+	jar cf Phind.jar org
+
+%.class : %.java
+	javac -target 1.1 -d . -classpath ../../../.. $<
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/Phind.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/Phind.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/Phind.java	(revision 16571)
@@ -0,0 +1,1119 @@
+/**********************************************************************
+ *
+ * Phind.java -- the Phind java applet
+ *
+ * Copyright 1997-2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+/*********************************************************************
+
+To use the applet, you'll need to embed it in a web page like this:
+
+<APPLET CODE="Phind.class" WIDTH=500 HEIGHT=500>
+
+  <PARAM NAME=collection  VALUE="fao.org">
+  <PARAM NAME=classifier  VALUE="1">
+  <PARAM NAME=phindcgi    VALUE="http://kowhai/cgi-bin/phindcgi">
+  <PARAM NAME=library     VALUE="http://kowhai/cgi-bin/library">
+  <PARAM NAME=backdrop    VALUE="http://kowhai/~paynter/transfer/phindtest/green1.jpg">
+  The Phind java applet.
+</APPLET>
+
+There are a bunch of other parameters; these are described in the 
+getParameters method below.  It is all done for you in Greenstone
+in the document.dm macro file (the _phindapplet_ macro).
+
+You may have problems with Java applet security.  Java applet's can only
+open socket connections (including the HTTP connections the applet uses 
+to get data) to the same server the applet was loaded from.  This means
+that your phindcgi, library, and (optional) backdrop URLs must be on the
+same machine that your web page was loaded from.
+
+**********************************************************************
+
+The applet comprises several classes:
+
+1. Phind (this file) is the applet class, loaded by the browser.
+   It also handles network connections.
+2. ResultDisplay is a Panel that sits in the applet and displays 
+   things; displays are connected in a doubly-linked list.
+3. ResultBox holds the results of a query.  Result boxes are shown
+   to the user through ResultDisplays.  Another doubly-linked list.
+4. ResultTitle acts as a caption to a ResultBox describing its contents.
+5. ResultCanvas is what the ResultBox data is drawn on.  It draws the
+   words on the screen, and handles user input from the mouse.
+6. ResultItem represents a single result object (a phrase or document).
+7. PhindTitle is for drawing backdrops in ResultDisplays.
+
+**********************************************************************/
+
+package org.nzdl.gsdl.Phind;
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Choice;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Event;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.GridLayout;
+import java.awt.Image;
+import java.awt.Label;
+import java.awt.Panel;
+import java.awt.TextField;
+
+import java.net.URL;
+import java.net.URLConnection;
+import java.io.DataInputStream;
+import java.io.InputStream;
+
+import java.net.Socket;
+//import java.net.SocketTimeoutException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+
+import java.util.Vector;
+import java.util.Date;
+
+import org.nzdl.gsdl.Phind.URLUTF8Encoder;
+
+public class Phind extends java.applet.Applet {
+    
+    // What is the collection called?
+    public String collection;
+
+    // Which phind classifier are we using? (There may be more than one.)
+    public String classifier;
+
+    // Internet address of phind resources
+    public String library_address, phindcgi_address;
+
+    // Initial serach term
+    public String initialSearch;
+
+    // Number of phrases to retrieve at any one time
+    public int phraseBlockSize;
+
+    // Appearance parameters
+    public boolean vertical;
+    public int depth;
+
+    // Font
+    public int fontSize;
+    public String fontName;
+    public Font plainFont, boldFont;
+
+    // Do we want a background image in the applet?
+    public boolean showImage;
+    public String backdrop_address;
+    public Image backgroundImage;
+    public boolean showBorder;
+
+    // Colours
+    public Color panel_fg, panel_bg,
+	column_1_fg, column_1_bg, 
+	column_2_fg, column_2_bg,
+	highlight_fg, highlight_bg,
+	thesaurus_fg, thesaurus_bg, thesaurus_bar_fg, thesaurus_bar_bg,
+	expansion_fg, expansion_bg, expansion_bar_fg, expansion_bar_bg,
+	document_fg, document_bg, document_bar_fg, document_bar_bg,
+	message_fg, message_bg;
+    
+    // Column dimensions
+    int column_1_width, column_2_width;
+
+    // Where do we open new windows
+    String searchWindowName, documentWindowName;
+
+    // the mode of operation
+    int mode;
+    final int initMode = 0;
+    final int idleMode = 1;
+    final int searchMode = 2;
+
+    // Elements of the control panel
+    boolean showControlPanel;
+    Label titleLabel;
+    TextField wordField;
+    Button searchButton, prevButton, nextButton;
+
+    // Holders for the downloaded data
+    Panel resultPanel;
+    ResultDisplay firstDisplay, lastDisplay;
+
+    // The time at which the last query finished
+    Date lastQueryEndTime;
+
+    // lastQueryEndTime is stored to ensure a 1 second gap between a query
+    // returning and a new one beginning.  It is needed because the FAO
+    // folks in Rome have a huge lag, and frquently click several times
+    // while they wait; these clicks are turned into new queries, which
+    // they await again.  It is no elegant solution, but it seems like the
+    // easiest, given that I don't know threads.
+    // 1. The search button is easy to disable, and is disabled when a
+    //    socket connection is in progress.
+    // 2. ResutCanvas widgets can'r be similarly disabled because the
+    //    browser hides or wipes them, which looks very bad.
+    // 3. I cannot just ignore clicks on canvasses because the browser
+    //    caches the clicks while the socket connection is going on, and then
+    //    sends them through afterwards, when the canvas is accepting clicks
+    //    again.
+    // 4. Current sequence of events is to record the time the last query
+    //    ends, then whenever a click happens make sure a second has past.  if
+    //    you double-click the the first query is sent, returns, end-tie is
+    //    set, and the second (and any others made during query time) is
+    //    *immediately* processed, but since 1 second hasn't past it is
+    //    ignored.
+
+    /** We're adding a timeout to the loop used to read the result from the
+     *  server - partially because of the 'fails to return anything' death
+     *  spiral - but also because its a good idea anyway. Why DataInputStream
+     *  doesn't have a TimeOutException, given its most often used to get data
+     *  from a URL, I don't know. Lets default it to 60 seconds.
+     *  DLConsulting 12-07-2004
+     */
+    private int timeout = 60;
+
+    public String getAppletInfo() {
+	return "Phind by Gordon Paynter (paynter@cs.waikato.ac.nz). Copyright 1997-2000.";
+    }
+
+
+    public void init() {
+
+	mode = initMode;
+	
+        System.out.println("Java vendor: " + System.getProperty("java.vendor"));
+        System.out.println("Java version: " + System.getProperty("java.version"));
+
+	// Read applet parameters
+	getParameters();
+
+	// Initialise the user interface
+	setBackground(panel_bg);
+	lastQueryEndTime = new Date();
+
+	// fonts used to output text
+	plainFont = new Font(fontName, Font.PLAIN, fontSize);
+	boldFont  = new Font(fontName, Font.BOLD, fontSize);
+
+	// The phind applet layout manager
+	setLayout(new BorderLayout());
+
+	// Panel containing the displays is in the center of the display
+	resultPanel = new Panel();
+	if (vertical) {
+	    resultPanel.setLayout(new GridLayout(depth,1,0,2));
+	} else {
+	    System.out.println("horizontal");
+	    resultPanel.setLayout(new GridLayout(1,depth,2,0));
+	}
+	add("Center", resultPanel);
+
+	// Create ResultDisplays and place into the interface
+	ResultDisplay d1, d2 = null;
+	firstDisplay = new ResultDisplay(this, null);
+	resultPanel.add(firstDisplay);
+
+	if (depth == 1) {
+	    lastDisplay = firstDisplay;
+	} else {
+	    d1 = firstDisplay;
+	    for (int i = 2; i <= depth; i++) {
+		d2 = new ResultDisplay(this, d1);
+		resultPanel.add(d2);
+		d1 = d2;
+	    }
+	    lastDisplay = d2;
+	}
+
+	// The control panel
+	initialiseControlPanel();
+
+	// lets get started then
+	setStatus("Welcome to Phind.");
+	mode = idleMode;
+
+	// Perform initial search, if requested
+	if (initialSearch.length() > 0) {
+	    searchForWord(initialSearch);
+	}
+    }
+
+
+    // Display a message in the status bar
+    void setStatus(String status) {
+	showStatus(status);
+    }
+
+    // The user performs an action in the interface
+    public boolean action(Event evt, Object arg) {
+
+	if (evt.target == searchButton) {
+	    searchForWord(getSearchTerm());
+	} else if (evt.target == wordField) {
+	    searchForWord(getSearchTerm());
+	} else if (evt.target == prevButton) {
+	    shiftPrevious();
+	} else if (evt.target == nextButton) {
+	    shiftNext();
+	} else {
+	    System.out.println("unknown action: " + evt.toString() 
+			       + ", object: " + arg.toString());
+	}
+	return true;
+    }
+
+
+    // Search for a word 
+    //
+    // Called on two occasions:
+    //   when the "Search" Button is pressed, or
+    //   to perform an "initial search"
+    void searchForWord(String searchWord) {
+
+	if (mode == idleMode) {
+	    
+	    setSearchTerm(searchWord);
+
+	    // Convert the String from UTF8 charaters into 
+	    // an encoding that is okay for a URL.
+	    searchWord = URLUTF8Encoder.encode(searchWord);
+
+	    // Look up the word
+	    if (searchWord.length() > 1) {
+		setStatus("searching for \"" + searchWord + "\""); 
+		firstDisplay.emptyContents();
+		ResultBox result = lookupPhraseOnServer(null, false, searchWord, searchWord, 2);
+
+		// if there is an error, return
+		if (result == null) {
+		    setStatus("No results for \"" + searchWord + "\""); 
+		    return;
+		}
+
+		// display the result
+		result.display = firstDisplay.display(result);
+		result.resize(result.display.size());
+		result.paintAll(result.getGraphics());
+	    }
+
+	    enablePreviousAndNext();
+	}
+    }
+  
+
+    // Search for a phrase
+    //
+    // If querymode is 2, the user has clicked on a phrase.
+    // If querymode is 3, the user has requested more phrases.
+    // If querymode is 4, the user has requested more documents.
+    void searchForPhrase(ResultBox source, String key, String phrase, int queryMode) {
+
+	// System.out.println("searchForPhrase: " + key + " " + phrase + " " + queryMode);
+
+	if (mode == idleMode) {
+
+	    // If we are going to replace the first ResultDisplay, then empty it
+	    if (queryMode <= 2) {
+		if (source.display.next != null) source.display.next.emptyContents();
+	    }
+
+	    // look up the word
+	    setStatus("Searching for \"" + phrase + "\""); 
+	    ResultBox result = lookupPhraseOnServer(source, true, key, phrase, queryMode);
+	    if (result == null) {
+		setStatus("No result for \"" + phrase + "\""); 
+		return;
+	    }
+
+	    // If this is not already displayed, display it in the last free spot
+	    if (queryMode <= 2) {
+		result.display = lastDisplay.display(result);
+		result.resize(result.display.size());
+		result.paintAll(result.getGraphics());
+	    }
+
+	    enablePreviousAndNext();
+	}
+    }
+
+
+    // Look up a phrase (or symbol) on the server
+    //
+    // Arguments are the source of the query (a ResultBox, or null if the
+    // query comes from hitting the search button), the key to search for
+    // (the text of a phrase or a symbol number), the phrase as a string, 
+    // and the query mode.
+    // Query modes are: 
+    //   0 = obsolete
+    //   1 = obsolete
+    //   2 = get first N phrases and URLs,
+    //   3 = get another N phrases into same window
+    //   4 = get another N documents into same window
+    //   5 = get another N thesaurus links into same window
+
+    ResultBox lookupPhraseOnServer(ResultBox source, 
+				   boolean keyKnown, String key, String phrase, 
+				   int queryMode) { 
+    	disableSearchButton();
+	mode = searchMode;
+	ResultBox r = null;
+
+	if (queryMode <= 2) {
+	    r = new ResultBox(this, collection, key, phrase, source);
+	} else if ((queryMode == 3) || (queryMode == 4) || (queryMode == 5)) {
+	    r = source;
+	}
+
+	try { 
+	    queryServer(keyKnown, key, queryMode, r);
+	} catch (Exception e) { 
+	    System.out.println("Phind query error: " + e.toString());
+	    setStatus("Query error: " + e.toString());
+	    mode = idleMode;
+	    enableSearchButton();
+	    return null;
+	}
+      
+	// The query is finished
+	setStatus(r.c.numberOfItems + " results for \"" + phrase + "\""); 
+	mode = idleMode;
+	enableSearchButton();
+	lastQueryEndTime = new Date();
+
+	return r;
+    }
+
+
+    // Query the phindcgi program
+    //
+    // Send a query (a word or symbol number) to the server
+    // and pass the response to a ResultBox.
+
+    void queryServer(boolean keyKnown, String word, int queryMode, ResultBox area) 
+	throws IOException {
+
+	// Build the query
+	String query = phindcgi_address + "pxml=1&c=" + collection + "&pc=" + classifier;
+
+	if (keyKnown) {
+	  query = query + "&ppnum=" + word;
+	} else {
+	  query = query + "&pptext=" + word;
+	}
+
+	
+	// Specify the set of results to return 
+	int first_e = 0;
+	int last_e = 0;
+	int first_d = 0;
+	int last_d = 0;
+	int first_l = 0;
+	int last_l = 0;
+
+	// the initial query
+	if (queryMode <= 2) {
+	  last_e = phraseBlockSize;
+	  last_d = phraseBlockSize;
+	  last_l = phraseBlockSize;
+	}
+
+	// add phrases to an existing result set
+	else if (queryMode == 3) {
+	  first_e = area.nextPhraseBlock * phraseBlockSize;
+	  area.nextPhraseBlock++;
+	  last_e = area.nextPhraseBlock * phraseBlockSize;
+	} 
+	
+	// add documents to existing result set
+	else if (queryMode == 4) {
+	  first_d = area.nextDocumentBlock * phraseBlockSize;
+	  area.nextDocumentBlock++;
+	  last_d = area.nextDocumentBlock * phraseBlockSize;
+	}
+
+	// add thesaurus links to existing result set
+	else if (queryMode == 5) {
+	  first_l = area.nextThesaurusLinkBlock * phraseBlockSize;
+	  area.nextThesaurusLinkBlock++;
+	  last_l = area.nextThesaurusLinkBlock * phraseBlockSize;
+	}
+
+	query = query + "&pfe=" + first_e + "&ple=" + last_e
+                      + "&pfd=" + first_d + "&pld=" + last_d
+                      + "&pfl=" + first_l + "&pll=" + last_l;
+
+	// Send the query to the phindcgi program 
+	System.out.println("sending query: " + query);
+	/** Start timeout counter.
+	 *  DLConsulting 12-07-2004
+	 */
+	int time = 0;
+	try {
+	    URL phindcgi = new URL(query);
+            //            DataInputStream in = new DataInputStream(phindcgi.openStream());
+
+            URLConnection conn = phindcgi.openConnection();
+            DataInputStream in = new DataInputStream(conn.getInputStream());
+
+	    byte[] buffer;
+	    int availableBytes = 0;
+
+	    
+	    while (!area.finished) {
+		// Lovely old method, which would work just fine if Sun supported their own API and made
+		// in.available() work.
+
+		/*
+		availableBytes = in.available();
+		if (availableBytes == 0) {
+		    // if i had threads i'd do a wait here for 1 second
+		    /** Ah-ha but we do have threads here - at least one thread 
+		     *  anyway! Note that we want to prevent interrupted 
+		     *  exceptions flinging us out of the read loop.
+		     *  We also check that the time count hasn't reached out
+		     *  timeout threshold yet. If so, make use of the nifty
+		     *  execption handling.
+		     *  DLConsulting 12-07-2004
+		     *  Start...
+		     
+                    System.err.println("No bytes available");
+		    if(time >= timeout) {
+			throw new InterruptedIOException(
+			    "No data recieved in " + time + 
+			    " seconds. Connection timed-out.");
+		    }
+		    try {
+			Thread.sleep(1000);
+		    }
+		    catch(InterruptedException exception) {
+			System.err.println("Unexpected InterruptedException. Non-fatal.");
+			exception.printStackTrace();
+		    }
+		    time++;
+		    /** ...End 
+		} else {
+                    System.err.println("Preparing to read " + availableBytes + " bytes");
+		    buffer = new byte[availableBytes];
+		    in.read(buffer);
+                    System.err.println("Done reading");
+		    area.parseBytes(buffer);
+		}
+		*/
+
+		// New - and hopefully safer - method.
+
+		// Create a new SafeReader, and then wait while it reads
+		// we can watch for timeouts as necessary
+		int timeout = 0;
+		SafeReader reader = new SafeReader(in);
+		reader.start();
+		while(!reader.isComplete()) {
+		    // Wait timeout time.
+		    try {
+			Thread.sleep(1000);
+		    }
+		    catch(InterruptedException exception) {
+			System.err.println("test.init(): Unexpected InterruptedException. Non-fatal.");
+			exception.printStackTrace();
+		    }
+		    // Then see if the readers read anything
+		    if(reader.poll() == 0) {
+			timeout++;
+			// Have we reached timeout?
+			if(timeout > reader.getTimeout()) {
+			    // Nothing been read. Kill the reader
+			    reader.interrupt();
+			    // And throw a hissy fit
+			    throw new InterruptedIOException("No data recieved in " + reader.getTimeout() + 
+							     " seconds. Connection timed-out.");
+			}
+			// Otherwise, wait a little longer.
+		    }
+		    // Otherwise we can continue waiting and polling
+		}
+		// Process the buffer
+		System.err.println("Done reading");
+		area.parseBytes(reader.getBuffer());
+            }
+	    
+	    in.close();
+	} catch (Exception e) {
+	    System.err.println( "Error sending query to phindcgi: " + e);
+	}
+	area.repaint();
+    }
+    
+
+    // Tidy up URLs
+    //
+    // Ensure a URL address (as string) has a protocol, host, and file.
+    //
+    // If the URL is a CGI script URL, it should be tidied up so that it is
+    // appropriate to tage attrib=value pairs on the end.  This means it
+    // must either end with a "?" or (if it contains a question-mark
+    // internally) end with a "&".
+    String tidy_URL(String address, boolean isCGI) {
+
+	// System.err.println("tidy URL: " + address);
+	
+	// make sure the URL has protocol, host, and file
+	if (address.startsWith("http")) {
+	    // the address has all the necessary components
+	} else if (address.startsWith("/")) {
+	    // there is no protocol and host
+	    URL document = getDocumentBase();
+	    String protocol = document.getProtocol();
+	    String host = document.getHost();
+	    String port = "";
+	    if (document.getPort()!=-1) {
+		port = ":" + document.getPort();
+	    }
+	    address = protocol + "://" + host + port + address;
+	} else {
+	    // this URL is relative to the directory the document is in
+	    URL document = getDocumentBase();
+	    String protocol = document.getProtocol();
+	    String host = document.getHost();
+	    String directory = document.getFile();
+	    int end = directory.lastIndexOf('/');
+	    String port = "";
+	    if (document.getPort() != -1) {
+		port = ":" + document.getPort();
+	    }
+	    directory = directory.substring(0, end + 1);
+	    address = protocol + "://" + host + port + directory + address;
+	}
+
+	// if the URL is a cgi script, make sure it has a "?" in it,
+	// and that it ends with a "?" or "&"
+	if (isCGI) {
+	    if (address.indexOf((int) '?') == -1) { 
+		address = address + "?";
+	    } else if (!address.endsWith("?")) {
+		address = address + "&";
+	    }
+	}
+
+	return address;
+    }
+
+
+
+    // Open an arbitrary web page
+    void displayWebPage(String address, String window) {
+	try { 
+	    URL url= new URL(address);
+	    if (window.length() > 0) {
+		getAppletContext().showDocument(url, window);
+	    } else {
+		getAppletContext().showDocument(url);
+	    }
+	} catch (Exception e) { 
+	    System.out.println("Cannot open web page: " + e.toString());
+	}
+    }
+
+
+    // Get the applet parameters
+    void getParameters() {
+
+	// What is this collection called?
+	collection = parameterValue("collection");
+	System.out.println("Phind collection: " + collection);
+
+	// Which of the collection's classifiers are we using?
+	classifier = parameterValue("classifier", "1");
+	System.out.println("Phind classifier: " + classifier);
+
+	// Where is the phind CGI script
+	phindcgi_address = parameterValue("phindcgi");
+	phindcgi_address = tidy_URL(phindcgi_address, true);
+	System.out.println("Phind phindcgi: " + phindcgi_address);
+
+	// Where is the Greenstone library
+	library_address = parameterValue("library");
+	library_address = tidy_URL(library_address, true);
+	System.out.println("Phind library: " + library_address);
+	
+	// Is there a default search term?
+	initialSearch = parameterValue("initial_search", "");
+
+	// Should we display the control panel
+	showControlPanel = true;
+	if (parameterValue("control_panel", "show").toLowerCase().equals("hide")) {
+	    showControlPanel = false;
+	}
+	
+	// Should we show a background image?
+	backdrop_address = parameterValue("backdrop", "");
+	if (backdrop_address.length() > 0) {
+	    backdrop_address = tidy_URL(backdrop_address, false);
+	    System.out.println("Phind backdrop URL: " + backdrop_address);
+
+	    try {
+		URL backdrop_url = new URL(backdrop_address);
+		backgroundImage = getImage(backdrop_url);
+		showImage = true;
+	    } catch (Exception e) { 
+		System.out.println("Phind could not load " + backdrop_address);
+		showImage = false;
+	    }
+	}
+
+	// Should we draw a border?
+	showBorder = parameterValue("border", "on").equals("off");
+
+	// Are the windows arranged vertically or horizontally
+	if (parameterValue("orientation", "vertical").toLowerCase().startsWith("hori")) {
+	    vertical = false;
+	} else {
+	    vertical = true;
+	}
+	
+	// How many phind windows are there?
+	depth = parameterValue("depth", 3);
+
+	// Result sort order
+	// Standard is "LlEeDd", expansion-first is "EeLlDd"
+	String order = parameterValue("resultorder", "standard");
+	if (!order.equals("standard")) {
+	    int next = 20;
+	    ResultItem.sortMessage = next;
+	    for (int x = 0; x < order.length(); x++) {
+		if (order.charAt(x) == ',') {
+		    next--;
+		} else if (order.charAt(x) == 'L') {
+		    ResultItem.sortLinkItem = next;
+		} else if (order.charAt(x) == 'l') {
+		    ResultItem.sortMoreLinks = next;
+		} else if (order.charAt(x) == 'E') {
+		    ResultItem.sortPhraseItem = next;
+		} else if (order.charAt(x) == 'e') {
+		    ResultItem.sortMorePhrases = next;
+		} else if (order.charAt(x) == 'D') {
+		    ResultItem.sortDocumentItem = next;
+		} else if (order.charAt(x) == 'd') {
+		    ResultItem.sortMoreDocuments = next;
+		}
+	    }
+	    System.out.println("link: " + ResultItem.sortLinkItem);
+	    System.out.println("exps: " + ResultItem.sortPhraseItem);
+	    System.out.println("docs: " + ResultItem.sortDocumentItem);
+
+	}
+
+	// How many phrases should we fetch at any given time?
+	phraseBlockSize = parameterValue("blocksize", 10);
+
+	// What font should we use?
+	fontSize = parameterValue("fontsize", 10);
+	fontName = parameterValue("fontname", "Helvetica");
+
+	// Column dimensions
+	column_1_width = parameterValue("first_column_width", 6);
+	column_2_width = parameterValue("second_column_width", column_1_width);
+	
+	// Where do we open new windows
+	searchWindowName = parameterValue("search_window", "phindsearch");
+	documentWindowName = parameterValue("document_window", "phinddoc");
+
+	// Colours
+	panel_fg = parameterValue("panel_fg", Color.black);
+	panel_bg = parameterValue("panel_bg", Color.white);
+
+	highlight_bg = parameterValue("highlight_bg", Color.yellow);
+
+	expansion_fg = parameterValue("expansion_fg", Color.black);
+	thesaurus_fg = parameterValue("thesaurus_fg", new Color(0, 100, 0));
+	document_fg = parameterValue("document_fg", Color.blue);
+
+	thesaurus_bar_fg = parameterValue("thesaurus_bar_fg", Color.black);
+	expansion_bar_fg = parameterValue("expansion_bar_fg", Color.black);
+	document_bar_fg = parameterValue("document_bar_fg", Color.black);
+
+	thesaurus_bar_bg = parameterValue("thesaurus_bar_bg", new Color(160, 160, 190));
+	expansion_bar_bg = parameterValue("expansion_bar_bg", new Color(255, 200, 200));
+	document_bar_bg = parameterValue("document_bar_bg", new Color(150, 193, 156));
+
+	column_1_fg = parameterValue("first_column_fg", Color.black);
+	column_1_bg = parameterValue("first_column_bg", new Color(235, 245, 235));
+	column_2_fg = parameterValue("second_column_fg", Color.black);
+	column_2_bg = parameterValue("second_column_bg", new Color(200, 220, 200));
+
+	message_fg = parameterValue("message_fg", Color.black);
+	message_bg = parameterValue("message_bg", Color.white);
+
+	// Colours I don't use, yet
+	// thesaurus_bg = parameterValue("thesaurus_bg", Color.white);
+	// expansion_bg = parameterValue("expansion_bg", Color.white);
+	// document_bg = parameterValue("document_bg", Color.white);
+
+	/** How long should the read loop wait before timing out?
+	 *  DLConsulting 12-07-2004
+	 */
+	timeout = parameterValue("timeout", 60);
+    }
+
+    // Get the value of a parameter given its name.
+    // There are many types of parameters, hence the variety of functions.
+
+    // Get a REQUIRED string.  Stop the applet if we cannot.
+    String parameterValue(String name) {
+	try { 
+	    return getParameter(name);
+	} catch (Exception e) {
+	    System.err.println("Phind: you must give a parameter for \"" 
+			       + name + "\".  Stopping.");
+	    stop();
+	}
+	return "";
+    }
+
+    // Get an optional parameter.  Return a default if we cannot.
+    String parameterValue(String name, String defaultValue) {
+	String text = getParameter(name);
+	if (text == null) {
+	    return defaultValue;
+	}
+	System.out.println("Phind " + name + ": " + text);
+	return text;
+    }
+
+    int parameterValue(String name, int defaultValue) {
+	int value;
+	try { 
+	    value = Integer.parseInt(getParameter(name));
+	} catch (Exception e) {
+	    return defaultValue;
+	}
+	System.out.println("Phind " + name + ": " + value);
+	return value;
+    }
+
+    Color parameterValue(String name, Color defaultValue) {
+
+	String text = getParameter(name);
+	if (text == null) {
+	    return defaultValue;
+	}
+	text = text.toLowerCase();
+
+	// a number of the form "#ddffee" 
+	if (text.startsWith("#") && (text.length() == 7)) {
+	    text = text.substring(1);
+	    int r, g, b;
+	    try {
+		r = Integer.parseInt(text.substring(0,2), 16);
+		g = Integer.parseInt(text.substring(2,4), 16);
+		b = Integer.parseInt(text.substring(4), 16);
+		return new Color(r, g, b);
+	    }  catch (Exception e) {
+		return defaultValue;
+	    }
+	}
+
+	// a known Java colour string
+	else if (text.equals("black")) { return Color.black; }
+	else if (text.equals("blue")) { return Color.blue; }
+	else if (text.equals("cyan")) { return Color.cyan; }
+	else if (text.equals("darkgray")) { return Color.darkGray; }
+	else if (text.equals("gray")) { return Color.gray; }
+	else if (text.equals("green")) { return Color.green; }
+	else if (text.equals("lightgray")) { return Color.lightGray; }
+	else if (text.equals("magenta")) { return Color.magenta; }
+	else if (text.equals("orange")) { return Color.orange; }
+	else if (text.equals("pink")) { return Color.pink; }
+	else if (text.equals("red")) { return Color.red; }
+	else if (text.equals("white")) { return Color.white; }
+	else if (text.equals("yellow")) { return Color.yellow; }
+
+	return defaultValue;
+    }
+
+
+    // Control panel operations
+
+    // Initialise the control panel
+    void initialiseControlPanel() {
+	
+	if (showControlPanel) {
+	    Panel p1 = new Panel();
+	    add("North", p1);
+	    p1.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
+	    
+	    searchButton = new Button("Search");
+	    searchButton.setFont(boldFont);
+	    p1.add(searchButton);
+	    
+	    Label tempLabel = new Label("  for");
+	    tempLabel.setFont(boldFont);
+	    p1.add(tempLabel);
+	    
+	    wordField = new TextField(12);
+	    wordField.setFont(boldFont);
+	    p1.add(wordField);
+	    
+	    Label temp2 = new Label("          ");
+	    p1.add(temp2);
+	    
+	    prevButton = new Button("Previous");
+	    prevButton.setFont(boldFont);
+	    prevButton.disable();
+	    
+	    p1.add(prevButton);
+	    
+	    nextButton = new Button("  Next  ");
+	    nextButton.setFont(boldFont);
+	    nextButton.disable();
+	    p1.add(nextButton);
+	    
+	}
+    }
+    
+    // Button and field functionality
+    
+    // Enable and disable the word field
+    void enableSearchButton() {
+	if (showControlPanel) {
+	    searchButton.enable();
+	}
+    }
+    void disableSearchButton() {
+	if (showControlPanel) {
+	    searchButton.disable();
+	}
+    }
+
+    // Get and set the search text in the wordField
+    String getSearchTerm() {
+	if (showControlPanel) {
+	    return wordField.getText();
+	} else {
+	    return initialSearch;
+	}
+    }
+    void setSearchTerm(String word) {
+	if (showControlPanel) {
+	    wordField.setText(word);
+	} 
+    }
+
+    // Enable or disable the "Previous" and "Next" buttons
+    void enablePreviousAndNext() {
+	if (showControlPanel) {
+	    Component c = firstDisplay.current;
+	    if (c.getClass().getName().endsWith("ResultBox")) {
+		if (((ResultBox) c).prevBoxExists()) {
+		    prevButton.enable();
+		} else {
+		    prevButton.disable();
+		}
+	    }
+	    
+	    c = lastDisplay.current;
+	    if (c.getClass().getName().endsWith("ResultBox")) {
+		if (((ResultBox) c).nextBoxExists()) {
+		    nextButton.enable();
+		} else {
+		    nextButton.disable();
+		}
+	    }
+	}
+    }
+
+    // Shift to previous box
+    //
+    // If the user clicks "Previous" then scroll up.
+    void shiftPrevious() {
+
+	Component c = firstDisplay.current;
+	if (c.getClass().getName().endsWith("ResultBox")) {
+
+	    ResultBox b = (ResultBox) c;
+	    if (b.prevBoxExists()) {
+		b = b.prev;
+
+		// empty all the displays
+		firstDisplay.emptyContents();
+
+		// add as many result boxes as there are displays
+		for (int i = 1 ; ((i <= depth) && (b != null)); i++) {
+		    lastDisplay.display(b);
+		    b.resize(b.display.size());
+		    b.paintAll(b.getGraphics());
+		    b = b.next;
+		}
+	    }
+	}
+	enablePreviousAndNext();
+    }
+
+    // Shift to next box
+    //
+    // If the user clicks "Next" then scroll down if possible
+    void shiftNext() {
+
+	Component c = lastDisplay.current;
+	if (c.getClass().getName().endsWith("ResultBox")) {
+
+	    ResultBox b = (ResultBox) c;
+	    if (b.nextBoxExists()) {
+
+		// find the new "first" displayed box
+		c = firstDisplay.current;
+		b = (ResultBox) c;
+		b = b.next;
+
+		// empty all the displays
+		firstDisplay.emptyContents();
+
+		// add as many result boxes as there are displays
+		for (int i = 1 ; ((i <= depth) && (b != null)); i++) {
+		    lastDisplay.display(b);
+		    b.resize(b.display.size());
+		    b.paintAll(b.getGraphics());
+		    b = b.next;
+		}
+	    }
+	}
+	enablePreviousAndNext();
+    }
+
+    public class SafeReader 
+	extends Thread {
+	// Has the reader finished reading?
+	private boolean complete;
+	// The buffer in where the data read is stored
+	private byte[] buffer;
+	// The stream this reader reads from
+	private DataInputStream in;
+	// If the bytes_read hasn't changed in this time, then stop this thread
+	// and timeout
+	private int timeout; 
+	// The current buffer size
+	private int buffer_current_size;
+	// The maximum buffer size
+	private int buffer_max_size;
+	// The number of bytes read through this reader since the last poll
+	private int bytes_read;
+
+	/** Default constructor 
+	 *  @param in the DataInputStream to read from
+	 */
+	public SafeReader(DataInputStream in) {
+	    complete = false;
+	    buffer_current_size = 0;
+	    buffer_max_size = 16;
+	    buffer = new byte[buffer_max_size]; // Default size
+	    timeout = 60; // Sixty seconds
+	    bytes_read = 0;
+	    
+	    this.in = in;
+	}
+
+	/** Construct a new SafeReader
+	 *  @param in the DataInputStream to read from
+	 *  @param timeout how long this thread should wait when reading data
+	 */
+	public SafeReader(DataInputStream in, int timeout) {
+	    this(in);
+	    this.timeout = timeout;
+	}
+
+	/** Retrieve the current buffer
+	 *  @return a byte[] buffer trimmed to the appropriate size
+	 */
+	public byte[] getBuffer() {
+	    byte[] final_buffer = new byte[buffer_current_size];
+	    System.arraycopy(buffer, 0, final_buffer, 0, buffer_current_size);
+	    return final_buffer;
+	}
+
+	/** Retrieve the current timeout
+	 *  @return the timeout as an int
+	 */
+	public int getTimeout() {
+	    return timeout;
+	}
+
+	/** See whether the reader has finished reading
+	 *  @return true if the read is complete (-1 bytes read!) or false otherwise
+	 */
+	public synchronized boolean isComplete() {
+	    return complete;
+	}
+
+	/** Poll the reader to determine if it has read any bytes recently
+	 *  @return the number of bytes read
+	 */
+	public long poll() {
+	    // Maybe should test if complete - but its only one second right?
+	    long result = bytes_read;
+	    bytes_read = 0;
+	    return result;
+	}
+
+	/** Try to read bytes from the input stream. Note the caller is responsible for closing the datainputstream
+	 */
+	public void run() {
+	    try {
+		int i = 0;
+		byte[] read_buffer = new byte[8];
+		while ((i = in.read(read_buffer)) != -1) {
+		    // Check our storage buffer is big enough
+		    if(buffer_max_size - (buffer_current_size + i) <= 0) {
+			// Double the size
+			buffer_max_size = 2 * buffer_max_size;
+			byte[] new_buffer = new byte[buffer_max_size];
+			System.arraycopy(buffer, 0, new_buffer, 0, buffer_current_size);
+			buffer = new_buffer;
+		    }
+		    // Then copy in the read buffer
+		    System.arraycopy(read_buffer, 0, buffer, buffer_current_size, i);
+		    buffer_current_size += i;
+		    bytes_read += i;
+		}
+		setComplete(true);
+	    }
+	    catch(IOException exception) {
+		System.err.println("SafeReader.run(): Unexpected IOException. Fatal.");
+		exception.printStackTrace();
+	    }
+	}
+
+	/** Set the complete boolean to the desired state, synchronized to avoid race with isComplete()
+	 *  @param value the desired state
+	 */
+	private synchronized void setComplete(boolean value) {
+	    complete = value;
+	}
+    }
+}
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/PhindTitle.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/PhindTitle.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/PhindTitle.java	(revision 16571)
@@ -0,0 +1,84 @@
+/**********************************************************************
+ *
+ * PhindTitle.java -- backdrops to empty ResultDisplay panels.
+ *
+ * Copyright 1997-2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+/*********************************************************************
+
+PhindTitle is for drawing backdrops in empty ResultDisplay panels.
+
+**********************************************************************/
+
+package org.nzdl.gsdl.Phind;
+
+import java.applet.Applet;
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+
+public class PhindTitle extends Canvas {
+
+    Phind phind;
+    static Image backgroundImage;
+    boolean displayInfo;
+    
+    PhindTitle(Phind p) {
+	phind = p;
+    }
+
+    public void update(Graphics g) {
+	paint(g);
+    }
+
+    public void paint(Graphics g) {
+	Dimension canvasSize = size();
+
+	Color fore = phind.panel_fg;
+	Color back = phind.panel_bg;
+
+	// set the screen background
+	if (phind.showImage)
+	    try {
+		g.drawImage(phind.backgroundImage, 
+			    0, 0, canvasSize.width, canvasSize.height, back, null);
+	    } catch (Exception e) {
+		System.err.println("PhindTitle paint: "  + e);
+	    }
+	else {
+	    g.setColor(back);
+	    g.fillRect(0,0, canvasSize.width, canvasSize.height);
+	}
+    }
+}
+
+ 
+
+
+
+
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultBox.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultBox.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultBox.java	(revision 16571)
@@ -0,0 +1,774 @@
+/**********************************************************************
+ *
+ * ResultBox.java -- a list of phrases in the Phind java interface
+ *
+ * Copyright 1997-2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/*********************************************************************
+
+This class is used in the Phind java applet (Phind.java).
+
+A ResultBox holds the results of a query to phindcgi.  They deal mostly
+with the information content of the query, and have methods for parsing the
+input into phrase and document items.  They have little do with display:
+ResultBoxes are shown to the user through "ResultDisplay" panels, and are
+drawn using "ResultCanvas" objects.
+
+**********************************************************************/
+
+package org.nzdl.gsdl.Phind;
+
+import java.awt.Panel;
+import java.awt.BorderLayout;
+import java.awt.Scrollbar;
+
+import java.awt.Label;
+import java.awt.Event;
+
+import java.net.*;
+import java.applet.*;
+
+import java.util.Vector;
+
+
+public class ResultBox extends Panel {
+    
+    // Objects at a "higher" level than this one
+    Phind phind;
+    ResultDisplay display;
+
+    // Surroundig objects
+    ResultBox prev, next;
+
+    // The components contained by this one.
+    ResultCanvas c;
+    ResultTitle t;
+    Scrollbar s;
+    Panel label;
+
+    // The key identifying the phrase displayed, with its text and the
+    // collection from which it is drawn
+    String searchKey, searchPhrase, searchCollection;
+    
+    // The total frequency, expansion frequency, and document frequency
+    // of the phrase
+    int numberOfOccurances;
+    int numberOfExpansions;
+    int numberOfDocuments;
+    int numberOfThesaurusLinks;
+
+    // The number of phrases and documents retrieved, and the number of
+    // times the user has requested more phrases or documents.
+    int expansionsRetrieved;
+    int documentsRetrieved;
+    int thesaurusLinksRetrieved;
+    int nextPhraseBlock;
+    int nextDocumentBlock;
+    int nextThesaurusLinkBlock;
+    
+    int mode;
+    final int initMode = 0;
+    public final int emptyMode = 1;
+    final int loadingMode = 2;
+    final int finishedMode = 3;
+
+    String buffer;
+    boolean finished;
+
+
+    // Create a ResultBox
+    // given details of the search that generated it.
+    ResultBox(Phind p, String collect, String key, String phrase, ResultBox rb) {
+
+	super();
+	mode = initMode;
+
+	phind = p;
+	display = null;
+	next = null;
+	prev = rb;
+	if (prev != null) prev.next = this;
+
+	searchKey = key;
+	searchPhrase = phrase;
+	searchCollection = collect;
+
+	numberOfOccurances = -1;
+	numberOfExpansions = -1;
+	numberOfDocuments = -1;
+	numberOfThesaurusLinks = -1;
+
+	expansionsRetrieved = 0;
+	documentsRetrieved = 0;
+	thesaurusLinksRetrieved = 0;
+
+	nextPhraseBlock = 1;
+	nextDocumentBlock = 1;
+	nextThesaurusLinkBlock = 1;
+
+
+	setLayout(new BorderLayout());
+
+	s = new Scrollbar(Scrollbar.VERTICAL);
+	disableScrollbar();
+	add("East", s);
+
+	c = new ResultCanvas(this);
+	add("Center", c);
+
+	t = new ResultTitle(this);
+	add("North", t);
+
+	buffer = "";
+	finished = false;
+	mode = emptyMode;
+    }
+
+    static String describeContents(String phrase, String c) {
+	return( "\"" + phrase + "\" in " + c + ".");
+    }
+
+    String describeContents() {
+	return( describeContents(searchPhrase, searchCollection) );
+    }
+
+
+    // Reset the contents of the box
+    void resetBox( ) {
+	buffer = "";
+	finished = false;
+	c.resetCanvas();
+	disableScrollbar();
+	mode = emptyMode;
+    
+	numberOfExpansions = -1;
+	numberOfDocuments = -1;
+	numberOfThesaurusLinks = -1;
+
+	expansionsRetrieved = 0;
+	documentsRetrieved = 0;
+	thesaurusLinksRetrieved = 0;
+    }
+
+    void setStatus( String status ) {
+	phind.setStatus(status);
+    }
+
+    void disableScrollbar() {
+	if (s.isEnabled()) {
+	    s.setValues(0, 1, 0, 1);
+	    s.setLineIncrement(1);
+	    s.setPageIncrement(1);
+	    s.disable();
+	}
+    }
+
+    // Are there displays previous to and after this?
+    public boolean prevBoxExists () {
+	return (prev != null);
+    }
+    public boolean nextBoxExists () {
+	return (next != null);
+    }
+
+    
+    // Look up a phrase
+    // Phrase lookups are passed on to the Phind applet itself.
+    void lookupPhrase(String key, String phrase, int queryMode) {
+	buffer = "";
+	finished = false;
+	phind.searchForPhrase(this, key, phrase, queryMode);
+	t.repaint();
+    }
+
+    public boolean handleEvent(Event event) {
+	//    System.out.println("event: " + event.toString());
+	if ( (event.target == s) && 
+	     ( (event.id == Event.SCROLL_ABSOLUTE) ||
+	       (event.id == Event.SCROLL_LINE_DOWN) ||
+	       (event.id == Event.SCROLL_LINE_UP) ||
+	       (event.id == Event.SCROLL_PAGE_DOWN) ||
+	       (event.id == Event.SCROLL_PAGE_UP) ) ) {
+	    c.repaint();
+	    return true;
+	} else {
+	    return super.handleEvent(event);
+	}
+    }    
+
+
+    // a new section of the byte stream is read
+    void parseBytes(byte[] bytes) {
+	mode = loadingMode;
+
+	// update the buffer that holds the bytes read
+	String input;
+	try {
+	    input = new String(bytes, new String("UTF8"));
+	} catch (Exception e) {
+	    System.err.println(e);
+	    input = "";
+	}
+	buffer = buffer.concat(input);
+
+	// Parse each line until there are no more lines to parse
+	while(parseLine());
+
+	if (finished) {
+	    c.updateMarkers();
+	    buffer = "";
+	} else {
+	    // We haven't finished, give some feedback about progress
+	    setStatus("Connected to host, " + c.numberOfItems + " results read");
+	}
+    }
+
+    // Parse a line of XML
+    //
+    // This isn't necessarily real XML.  We assume every tag begins and
+    // ends on one line.  We read one line out of the buffer at a time,
+    // then "add" them to the box with the addLine method.
+    //
+    // Return true if there is a another line here to parse, otherwise false.
+
+    boolean parseLine() {
+
+        // System.out.print("parseLine " + "(length " + buffer.length() + ")");
+	String item;
+	int eol = buffer.indexOf((int) '\n');
+
+	// If there are no carriage returns, the line is incomplete
+	if (eol == -1) {
+	    return false;
+	}
+
+	// The </phinddata> tag concludes the dataset
+	else if (buffer.startsWith("</phinddata>")) {
+	    mode = finishedMode;
+	    finished = true;
+	    return false;
+	}
+	
+	// The <expansion> tag
+	else if (buffer.startsWith("<expansion ")) {
+	    item = buffer.substring(0, eol);
+	    buffer = buffer.substring(eol + 1);
+	    addExpansionTag(item);
+	    return true;
+	}
+ 
+	// The <document> tag
+	else if (buffer.startsWith("<document ")) {
+	    item = buffer.substring(0, eol);
+	    buffer = buffer.substring(eol + 1);
+	    addDocumentTag(item);
+	    return true;
+	}
+ 
+	// The <thesaurus> tag
+	else if (buffer.startsWith("<thesaurus ")) {
+	    item = buffer.substring(0, eol);
+	    buffer = buffer.substring(eol + 1);
+	    addThesaurusTag(item);
+	    return true;
+	}
+ 
+	// The <phinddata> tag introduces the dataset
+	else if (buffer.startsWith("<phinddata ")) {
+	    item = buffer.substring(0, eol);
+	    buffer = buffer.substring(eol + 1);
+	    addPhinddataTag(item);
+	    return true;
+	}
+
+	// The <phinderror> tag contains an error message
+	else if (buffer.startsWith("<phinderror")) {
+	    item = buffer.substring(0, eol);
+	    System.out.println("phind reported an error: " + item);
+	    buffer = buffer.substring(eol + 1);
+	    return true;
+	}
+ 
+	// Ignore the piece we've read
+	item = buffer.substring(0, eol);
+	// System.out.println("discarding: " + item);
+	buffer = buffer.substring(eol + 1);
+	return true;
+    }
+    
+
+
+    // Add a phinddata tag
+    //
+    // Given a string containing an XML phinddata tag of the form:
+    //   <phinddata id="35" text="FOREST" df="797" ef="134">
+    // Read the expansion information from the tag
+    //
+    // Return true if successful, otherwise false.
+
+    boolean addPhinddataTag( String line ) {
+
+	// System.out.println( "addExpansionListTag: " + line);
+
+	String idStr = "", text = "", tfStr = "", efStr = "", dfStr = "", lfStr = "";
+	int tf = 0, ef = 0, df = 0, lf = 0;
+
+	// Break the tag down into its component parts
+	int nextSplit;
+       	while (line.length() > 0) {
+	    line = line.trim();
+
+	    // Read the phrase identifier
+	    if (line.startsWith("id")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    idStr = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("addExpansionListTag: error parsing: " + line);
+ 		}
+	    } 
+	    
+	    // Read the total frequency
+	    else if (line.startsWith("tf")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    tfStr = line.substring(0, nextSplit);
+		    tf = Integer.valueOf(tfStr).intValue();
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("addExpansionListTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the text of the phrase
+	    else if (line.startsWith("text")) {
+		line = line.substring(6);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    text = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("addExpansionListTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the expansion frequency
+	    else if (line.startsWith("ef")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    efStr = line.substring(0, nextSplit);
+		    ef = Integer.valueOf(efStr).intValue();
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("addExpansionListTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the document frequency
+	    else if (line.startsWith("df")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    dfStr = line.substring(0, nextSplit);
+		    df = Integer.valueOf(dfStr).intValue();
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("addExpansionListTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the thesaurus link frequency
+	    else if (line.startsWith("lf")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    lfStr = line.substring(0, nextSplit);
+		    lf = Integer.valueOf(lfStr).intValue();
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("addExpansionListTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read and ignore some other tag
+	    else {
+		nextSplit = line.indexOf((int) ' ');
+		if (nextSplit >= 1) {
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    line = "";
+		}
+	    }
+	}
+
+	// Add the data to the ResultBox
+	searchKey = idStr;
+	searchPhrase = text;
+	numberOfOccurances = tf;
+	numberOfExpansions = ef;
+	numberOfDocuments = df;
+	numberOfThesaurusLinks = lf;
+	return true;
+    }
+
+
+    // Add an expansion tag
+    //
+    // Given a string containing an XML expansin tag of the form:
+    //   <expansion num="3" id="8421" prefix="PEOPLE and" suffix="" tf="3" df="3"/>
+    //   <expansion num="4" id="8696" prefix="" suffix="products" tf="3" df="3"/>
+    // Create a new ResultItemPhrase for display
+    //
+    // Return true if successful, otherwise false.
+
+    boolean addExpansionTag( String line ) {
+
+	// System.out.println( "addExpansionTag: " + line + " (" + expansionsRetrieved + ")");
+
+	String numStr = "", idStr = "", tfStr = "", dfStr = "", 
+	    prefix = "", body = "", suffix = "";
+
+	body = searchPhrase;
+
+	// Break the tag down into its component parts
+	line = line.substring(11);
+	int nextSplit;
+       	while (line.length() > 0) {
+	    line = line.trim();
+
+	    // Read the expansion number
+	    if (line.startsWith("num")) {
+		line = line.substring(5);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    numStr = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addExpansionTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the phrase ID
+	    else if (line.startsWith("id")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    idStr = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addExpansionTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the prefix of the phrase
+	    else if (line.startsWith("prefix")) {
+		line = line.substring(8);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 0) {
+		    prefix = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addExpansionTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the suffix of the phrase
+	    else if (line.startsWith("suffix")) {
+		line = line.substring(8);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 0) {
+		    suffix = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addExpansionTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the frequency
+	    else if (line.startsWith("tf")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    tfStr = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addExpansionTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the document frequency
+	    else if (line.startsWith("df")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    dfStr = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addExpansionTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read some other tag
+	    else {
+		nextSplit = line.indexOf((int) ' ');
+		if (nextSplit >= 1) {
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    line = "";
+		}
+	    }
+	}
+	
+	// Create a new ResultItem and add it to the display
+	ResultItemPhrase ri = new ResultItemPhrase(idStr, tfStr, dfStr, prefix, body, suffix);
+	
+	if (c.addResultItem(ri)) {
+	    expansionsRetrieved++;
+	    return true;
+	}
+	
+	return false;
+    }
+
+
+    // Add an document tag
+    //
+    // Given a string containing an XML document tag of the form:
+    //   <document num="2" hash="HASH424e64b811fdad933be69c" freq="1" title="CONTENTS"/>
+    //   <document num="3" hash="HASH01f08efd8752ad54ca0a99cf" freq="1" title="Tree mixtures"/>
+    //
+    // Create a new ResultItemDocument for display
+    //
+    // Return true if successful, otherwise false.
+
+    boolean addDocumentTag( String line ) {
+
+	// System.out.println( "addDocumentTag: " + line + " (" + documentsRetrieved + ")");
+	
+	String num = "", hash = "", freq = "", title = "";
+	line = line.substring(9);
+	
+	// Break the tag down into its component parts
+	int nextSplit;
+       	while (line.length() > 0) {
+	    line = line.trim();
+
+	    // Read the expansion number
+	    if (line.startsWith("num")) {
+		line = line.substring(5);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    num = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addDocumentTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the document OID hash
+	    else if (line.startsWith("hash")) {
+		line = line.substring(6);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    hash = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addDocumentTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the document frequency
+	    else if (line.startsWith("freq")) {
+		line = line.substring(6);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    freq = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addDocumentTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the title
+	    else if (line.startsWith("title")) {
+		line = line.substring(7);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    title = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addDocumentTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read some other tag or close the string off
+	    else {
+		nextSplit = line.indexOf((int) ' ');
+		if (nextSplit >= 1) {
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    line = "";
+		}
+	    }
+	}
+	
+	// Create a new ResultItem and add it to the display
+	ResultItemDocument ri = new ResultItemDocument(hash, title, freq);
+	
+	if (c.addResultItem(ri)) {
+	    documentsRetrieved++;
+	    return true;
+	}
+	
+	return false;
+    }
+
+
+    // Add a thesaurus tag
+    //
+    // Given a string containing an XML document tag of the form:
+    //
+    // <thesaurus num="3" id="36506" tf="0" df="0" type="RT" text="ANGLOPHONE AFRICA"/>
+    // <thesaurus num="4" id="28724" tf="0" df="0" type="RT" text="FRANCOPHONE AFRICA"/>
+    //
+    // Create a new ResultItemLink for display
+    //
+    // Return true if successful, otherwise false.
+
+    boolean addThesaurusTag( String line ) {
+    
+	// System.out.println( "addThesaurusTag: " + line + " (" + thesaurusLinksRetrieved + ")");
+
+	String num = "", id = "", tf = "", df = "", type = "", text = "";
+	line = line.substring(10);
+
+	// Break the tag down into its component parts
+	int nextSplit;
+       	while (line.length() > 0) {
+	    line = line.trim();
+
+	    // Read the expansion number
+	    if (line.startsWith("num")) {
+		line = line.substring(5);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    num = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addThesaurusTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the phrase ID
+	    else if (line.startsWith("id")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    id = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addThesaurusTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the phrase link type
+	    else if (line.startsWith("type")) {
+		line = line.substring(6);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    type = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addThesaurusTag: error parsing: " + line);
+ 		}
+	    } 
+
+
+	    // Read the phrase text
+	    else if (line.startsWith("text")) {
+		line = line.substring(6);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    text = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addThesaurusTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the frequency
+	    else if (line.startsWith("tf")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    tf = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addExpansionTag: error parsing: " + line);
+ 		}
+	    } 
+
+	    // Read the document frequency
+	    else if (line.startsWith("df")) {
+		line = line.substring(4);
+		nextSplit = line.indexOf((int) '"');
+		if (nextSplit >= 1) {
+		    df = line.substring(0, nextSplit);
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    System.err.println("ResultBox addExpansionTag: error parsing: " + line);
+ 		}
+	    } 
+
+
+	    // Read some other tag or close the string off
+	    else {
+		nextSplit = line.indexOf((int) ' ');
+		if (nextSplit >= 1) {
+		    line = line.substring(nextSplit + 1);
+		} else {
+		    line = "";
+		}
+	    }
+	}
+	
+	// Create a new ResultItem and add it to the display
+	ResultItemLink ri = new ResultItemLink(id, text, type, tf, df);
+
+	if (c.addResultItem(ri)) {
+	    thesaurusLinksRetrieved++;
+	    return true;
+	}
+	
+	return false;
+    }
+}
+
+
+
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultCanvas.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultCanvas.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultCanvas.java	(revision 16571)
@@ -0,0 +1,557 @@
+/**********************************************************************
+ *
+ * ResultCanvas.java -- a Canvas onto which a phrase list is drawn
+ *
+ * Copyright 1997-2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/*********************************************************************
+
+This class is used in the Phind java applet (Phind.java).
+
+The results of a query are displayed on a ResultCanvas object.  Each 
+entry in the result list is stored in a ResultItem, and the ResultCanvas 
+contains a Vector of ResultItems.
+
+Each ResultCanvas is embedded in a ResultBox alongside a Scrollbar.  
+When the ResultCanvas is drawn, it looks at the scrollbar, calculates 
+which ResultItems are visible, then draws them on the screen.
+
+**********************************************************************/
+
+package org.nzdl.gsdl.Phind;
+
+import java.awt.Canvas;
+import java.awt.Scrollbar;
+import java.awt.Graphics;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Dimension;
+import java.awt.Color;
+import java.util.Vector;
+import java.awt.Image;
+import java.awt.Event;
+
+import java.net.URL;
+import java.applet.Applet;
+import java.util.Date;
+
+public class ResultCanvas extends Canvas {
+
+    // Other objects associated with this 
+    Phind phind;
+    ResultBox parent;
+    Scrollbar scrollbar;
+    
+    // fonts and font spacings to use
+    Font areaPlain, areaBold;
+    int lineSpacing;
+    
+    // The items to display on this canvas
+    int numberOfItems;
+    int firstItemDisplayed;
+    int itemSelected;
+    Vector items;
+    
+    // the background image
+    public static Image backgroundImage;
+    
+    
+    // Create a ResultCanvas from the ResultBox which is its parent.
+    ResultCanvas(ResultBox p) {
+	
+	parent = p;
+	phind = p.phind;
+	scrollbar = p.s;
+	parent.disableScrollbar();
+
+	areaPlain = phind.plainFont;
+	areaBold  = phind.boldFont;
+
+	lineSpacing = phind.fontSize + 2;
+
+	items = new Vector();
+	numberOfItems = 0;
+	firstItemDisplayed = 0;
+	itemSelected = -1;
+    
+	if (backgroundImage == null) {
+	    backgroundImage = p.phind.backgroundImage;
+	}
+
+    }
+
+    void resetCanvas( ) {
+	items.removeAllElements();
+	numberOfItems = 0;
+	repaint();
+    }
+
+
+    // Add a new search result.
+    // Return true if successful, otherwise false.
+    boolean addResultItem( ResultItem item ) {
+ 
+	// Add a new result, in sorted order.
+	// First sort key is item kind (lowest first),
+	// second is frequency (highest first).
+	// This is not efficient, but I don't care right now.
+	int index = 0;
+	while ((index < numberOfItems) &&
+	       ((item.sort < ((ResultItem) items.elementAt(index)).sort) ||
+		((item.sort == ((ResultItem) items.elementAt(index)).sort) &&
+		 (item.frequency <= ((ResultItem) items.elementAt(index)).frequency)))) {
+	    index++;
+	}
+	items.insertElementAt(item,index);
+	numberOfItems++;
+	return true;
+    }
+
+
+    // Update more phrases/documents/links markers
+    void updateMarkers() {
+	updateMorePhrasesMarker();
+	updateMoreDocumentsMarker();
+	updateMoreLinksMarker();
+    }
+
+    // Make sure the more Phrases item only appears in the list
+    // if it is meant to.
+    void updateMorePhrasesMarker() {
+    
+	// System.out.println("updateMorePhrasesMarker() ");
+
+	// look for a marker
+	boolean found = false;
+	int index = 0;
+	while (!found && (index < numberOfItems)) {
+	    if (((ResultItem) items.elementAt(index)).isMorePhrases()) {
+		found = true;
+	    } else {
+		index++;
+	    }
+	}
+
+	if (parent.expansionsRetrieved == parent.numberOfExpansions) {
+	    // there should be no marker
+	    if (found) {
+		items.removeElementAt(index);
+		numberOfItems--;
+	    }
+
+	} else if (parent.expansionsRetrieved < parent.numberOfExpansions) {
+	    if (!found) {
+		ResultItem ri = new ResultItem(ResultItem.morePhrases);
+		addResultItem(ri);
+	    }
+	}
+    }
+
+
+    // Make sure the more documents marker appears when required
+    void updateMoreDocumentsMarker() {
+    
+	// System.out.println("updateMoreDocumentsMarker() ");
+
+	// look for a marker
+	boolean found = false;
+	int index = 0;
+	while (!found && (index < numberOfItems)) {
+	    if (((ResultItem) items.elementAt(index)).isMoreDocuments()) {
+		found = true;
+	    } else {
+		index++;
+	    }
+	}
+
+	if (parent.documentsRetrieved == parent.numberOfDocuments) {
+	    // there should be no marker
+	    if (found) {
+		items.removeElementAt(index);
+		numberOfItems--;
+	    }
+
+	} else if (parent.documentsRetrieved < parent.numberOfDocuments) {
+	    // there should be a marker
+	    if (!found) {
+		ResultItem ri = new ResultItem(ResultItem.moreDocuments);
+		addResultItem(ri);
+	    }
+	}
+    }
+
+      
+    // Make sure the more links marker appears when required
+    void updateMoreLinksMarker() {
+    
+	// System.out.println("updateMoreLinksMarker() ");
+
+	// look for a marker
+	boolean found = false;
+	int index = 0;
+	while (!found && (index < numberOfItems)) {
+	    if (((ResultItem) items.elementAt(index)).isMoreLinks()) {
+		found = true;
+	    } else {
+		index++;
+	    }
+	}
+
+	if (parent.thesaurusLinksRetrieved == parent.numberOfThesaurusLinks) {
+	    // there should be no marker
+	    if (found) {
+		items.removeElementAt(index);
+		numberOfItems--;
+	    }
+
+	} else if (parent.thesaurusLinksRetrieved < parent.numberOfThesaurusLinks) {
+	    // there should be a marker
+	    if (!found) {
+		ResultItem ri = new ResultItem(ResultItem.moreLinks);
+		addResultItem(ri);
+	    }
+	}
+    }
+
+      
+
+ 
+
+
+    public void update(Graphics g) {
+	paint(g);
+    }
+
+    public void paint(Graphics g) {
+
+	// calculate the canvas size, margins, and spacing
+	
+	// Note: the size() method is deprecated, but getSize fails in NetScape 4
+	// Dimension canvasSize = getSize();
+	Dimension canvasSize = size();
+
+	g.setFont(areaPlain);
+	int space = g.getFontMetrics().stringWidth(" ");
+	int nought = g.getFontMetrics().stringWidth("0");
+
+	int firstColumnWidth = phind.column_1_width * nought;
+	int secondColumnWidth = phind.column_2_width * nought;
+	int columnWidth = firstColumnWidth + secondColumnWidth;
+
+	int firstColumnLeft = canvasSize.width - columnWidth;
+	int secondColumnLeft = firstColumnLeft + firstColumnWidth;
+
+	int mainLeftMargin = 0;
+	int mainRightMargin = firstColumnLeft;
+
+	// the number of items that will fit on the canvas
+	int visible = canvasSize.height / lineSpacing;
+
+	// calculate the first item to output
+	int scrollValue = scrollbar.getValue();
+	if (numberOfItems <= visible) {
+	    scrollValue = 0;
+	} else if (scrollValue > (numberOfItems - visible)) {
+	    scrollValue = numberOfItems - visible;
+	} 
+	firstItemDisplayed = scrollValue;
+
+	// Draw the phrase area
+	Color fore = phind.panel_fg;
+	Color back = phind.panel_bg;
+
+
+	// draw the background
+	if (phind.showImage) {
+	    try {
+		g.drawImage(backgroundImage, 
+			    mainLeftMargin, 0, mainRightMargin, canvasSize.height, 
+			    back, null);
+	    } catch (Exception e) {
+		phind.showImage = false;
+		System.err.println("ResultCanvas paint error: " + e); 
+		g.setColor(back);
+		g.fillRect(0, 0, canvasSize.width, canvasSize.height);
+	    }
+	} else {
+	    g.setColor(back);
+	    g.fillRect(0, 0, canvasSize.width, canvasSize.height);
+	}
+    
+	// If there are no phrases, output a brief explanation.
+	if (numberOfItems == 0) {
+	    g.drawString("No phrases match this query.", mainLeftMargin + 10, lineSpacing);
+	}
+
+	// Output each of the visible ResultItems
+	ResultItem result;
+	int tab, i, y = 0;
+	int center = mainLeftMargin 
+	    + ((mainRightMargin - mainLeftMargin 
+		- g.getFontMetrics().stringWidth(parent.searchPhrase)) / 2);
+	int thesColumn = mainLeftMargin + firstColumnWidth 
+	    + g.getFontMetrics().stringWidth("Narrower term");
+
+	String body, prefix, suffix;
+	
+	for (i = scrollValue; 
+	     (i < numberOfItems) && (y + lineSpacing < canvasSize.height); i++) {
+
+	    // Get the resultItem to output
+	    result = (ResultItem) items.elementAt(i);
+	    
+	    // Graphics settings for drawing this line
+	    y += lineSpacing;
+	    g.setFont(areaPlain);
+
+	    // Highlight the selected phrase.
+	    if (i == itemSelected) {
+		g.setColor(phind.highlight_bg);
+		g.fillRect(mainLeftMargin, y-lineSpacing+2, mainRightMargin, lineSpacing);
+	    }
+
+	    // Draw the item
+
+	    // Draw a phrase item
+	    if (result.isPhrase()) {
+		prefix = result.prefixText();
+		body = result.mainText();
+		suffix = result.suffixText();
+		
+		g.setColor(phind.expansion_fg);
+		g.setFont(areaPlain);
+		tab = center - g.getFontMetrics().stringWidth(prefix) - space;
+		g.drawString(prefix, tab, y);
+		
+		g.setFont(areaBold);
+		g.drawString(body, center, y);
+		
+		tab = center + space + g.getFontMetrics().stringWidth(body);
+		g.setFont(areaPlain);
+		g.drawString(suffix, tab, y);
+	
+	    } 
+
+	    // Draw a document item
+	    else if (result.isDocument()){
+		body = result.mainText();
+
+		g.setColor(phind.document_fg);
+		g.setFont(areaPlain);
+		tab = (mainRightMargin - g.getFontMetrics().stringWidth(body)) / 2;
+		g.drawString(body, tab, y);
+      
+	    } 
+	
+	    // Draw a thesaurus link item
+	    else if (result.isLink()){
+		prefix = result.prefixText() + ":";
+		body = result.mainText();
+		tab = thesColumn - g.getFontMetrics().stringWidth(prefix) - space;
+
+		g.setColor(phind.thesaurus_fg);
+		g.setFont(areaPlain);
+		g.drawString(prefix, tab, y);
+		g.setFont(areaBold);
+		g.drawString(body, thesColumn, y);
+	    } 
+	    
+	    // Draw a "more phrases/documents/links" marker
+	    else if (result.isMorePhrases() 
+		     || result.isMoreDocuments() 
+		     || result.isMoreLinks()){
+		body = result.mainText();
+		
+		if (result.isMorePhrases()) {
+		    g.setColor(phind.expansion_bar_bg);
+		} else if (result.isMoreDocuments()) {
+		    g.setColor(phind.document_bar_bg);
+		} else {
+		    g.setColor(phind.thesaurus_bar_bg);		    
+		}
+		g.fillRect(mainLeftMargin, y-lineSpacing+2, mainRightMargin, lineSpacing);
+
+		if (result.isMorePhrases()) {
+		    g.setColor(phind.expansion_bar_fg);
+		} else if (result.isMoreDocuments()) {
+		    g.setColor(phind.document_bar_fg);
+		} else {
+		    g.setColor(phind.thesaurus_bar_fg);		    
+		}
+		g.setFont(areaPlain);
+		tab = (mainRightMargin - g.getFontMetrics().stringWidth(body)) / 2;
+		g.drawString(body, tab, y);
+	    } 
+	}
+
+	// Draw the frequecy columns
+
+	// column backgrounds
+	g.setColor(phind.column_1_bg);
+	g.fillRect(firstColumnLeft, 0, firstColumnWidth, canvasSize.height);
+	g.setColor(phind.column_2_bg);
+	g.fillRect(secondColumnLeft, 0, secondColumnWidth, canvasSize.height);
+
+	// fill in the numbers
+	g.setColor(phind.column_1_fg);
+	g.setFont(areaPlain);
+	y = 0;
+	String docsText, freqText;
+
+	for (i = scrollValue; 
+	     (i < numberOfItems) && (y + lineSpacing < canvasSize.height); i++) {
+	    
+	    // Get the resultItem to output
+	    result = (ResultItem) items.elementAt(i);
+	    docsText = result.docsText();
+	    freqText = result.freqText();
+	    
+	    // Graphics settings for drawing this line
+	    y += lineSpacing;
+
+	    // Write the document frequency
+	    if (docsText.length() > 0) {
+		tab = secondColumnLeft - space - g.getFontMetrics().stringWidth(docsText);
+		g.drawString(docsText, tab, y);
+	    }
+
+	    // Write the term frequency
+	    if (freqText.length() > 0) {
+		tab = secondColumnLeft + secondColumnWidth 
+		    - space - g.getFontMetrics().stringWidth(freqText);
+		g.drawString(freqText, tab, y);
+	    }
+	}
+
+	// Adjust the scrollbar
+	if (visible >= numberOfItems) {
+	    parent.disableScrollbar();
+	} else {
+	    scrollbar.setValues(scrollValue, visible, 0, numberOfItems);
+	    // Deprecated - setPageIncrement() has been replaced by
+	    // setBlockIncrement(), but the latter doesn't work on some
+	    // browsers.  Damn.
+	    // scrollbar.setBlockIncrement(visible - 1);
+	    scrollbar.setPageIncrement(visible - 1);
+	    // Deprecated - more nonsense: enable() has been replaced by
+	    // setEnabled(true), but this doesn't work on some browsers.
+	    //scrollbar.setEnabled(true);
+	    scrollbar.enable();
+	}
+
+	
+	// draw the border
+	if (phind.showBorder) {
+	    g.setColor(phind.panel_fg);
+	    g.drawRect(0,0, canvasSize.width - 1, canvasSize.height - 1);
+	}
+    }
+
+    // User interaction
+    //
+    // All interaction with the ResultCanvas is therough mouse clicks, and
+    // is handles in this method.  Note we ignore clicks that follow
+    // another too closely to avoid problems with slow connections.
+    public boolean handleEvent(Event event) {
+    
+	if (event.id == Event.MOUSE_UP) {
+
+	    // ignore actions that occur within 1 second of the last
+	    Date now = new Date();
+	    // System.out.println("Click time: " + now.toString());
+	    if (now.getTime() < (phind.lastQueryEndTime.getTime() + 1000)) {
+		System.out.println("Ignoring click - too close to last query.");
+		return true;
+	    }
+
+	    // which Item is selected?
+	    int rowSelected = event.y / lineSpacing;
+	    itemSelected = rowSelected + firstItemDisplayed;
+	    ResultItem item = (ResultItem) items.elementAt(itemSelected);
+
+	    if (itemSelected <= numberOfItems) {
+	
+		//User clicks on a phrase
+		if (item.isPhrase()) {
+		    itemSelected = itemSelected;
+		    update(getGraphics());
+		    parent.lookupPhrase(item.hiddenText(), item.toString(), 2);
+
+		    // If meta key is held down, send query to search engine
+		    if (event.metaDown() && !phind.library_address.equals("")) {
+			String address = phind.library_address  
+			    + "a=q&c=" + phind.collection
+			    + "&q=%22" + item.toString().replace(' ', '+') + "%22";
+			phind.displayWebPage(address, phind.searchWindowName);
+		    }
+		} 
+
+		// Click on a thesaurus link
+		else if (item.isLink()) {
+		    itemSelected = itemSelected;
+		    update(getGraphics());
+		    parent.lookupPhrase(item.hiddenText(), item.toString(), 2);
+
+		    // If meta key is held down, send query to search engine
+		    if (event.metaDown() && !phind.library_address.equals("")) {
+			String address = phind.library_address  
+			    + "a=q&c=" + phind.collection
+			    + "&q=%22" + item.toString().replace(' ', '+') + "%22";
+			phind.displayWebPage(address, phind.searchWindowName);
+		    }
+		} 
+
+		// The user clicks on a URL; display it.
+		else if (item.isDocument()) {
+		    itemSelected = itemSelected;
+		    update(getGraphics());
+
+		    String address = phind.library_address 
+			+ "a=d&c=" + phind.collection 
+			+ "&d=" + item.hiddenText()
+			+ "&q=" + parent.searchPhrase.replace(' ', '+');
+		    phind.displayWebPage(address, phind.documentWindowName);
+		}
+		 
+		// When the user clicks on "get more phrases" or other marker,
+		// we have to send a new query to the host
+		else if (item.isMorePhrases()){
+		    parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 3);
+		} else if (item.isMoreDocuments()){
+		    parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 4);
+		} else if (item.isMoreLinks()){
+		    parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 5);
+
+
+		}
+		repaint();
+	    }
+	}
+	return true;
+    }    
+  
+}
+
+
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultDisplay.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultDisplay.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultDisplay.java	(revision 16571)
@@ -0,0 +1,126 @@
+/**********************************************************************
+ *
+ * ResultDisplay.java -- Phrase list holder for Phind java applet
+ *
+ * Copyright 1997-2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/*********************************************************************
+
+This class is used in the Phind java applet (Phind.java).
+
+A ResultDisplay is a Panel that can display a single Component, which will
+be a ResultBox or PhindTitle object.
+
+ResultBoxes can be "chained" together with their "prev" and "next" fields,
+allowing us to have an arbitrary number of "displays" in which to show
+phrase lists.
+
+Main methods:
+* emptyContents will remove the component and emptyAll the "next" display
+* display will add an item to the first (ie: most "prev") available box
+
+**********************************************************************/
+
+package org.nzdl.gsdl.Phind;
+
+import java.awt.Panel;
+import java.awt.BorderLayout;
+import java.awt.Component;
+
+class ResultDisplay extends Panel {
+
+  Phind phind;
+  ResultDisplay prev, next;
+  Component current;
+  boolean empty;
+
+  // Create a new Display
+  ResultDisplay(Phind ph, ResultDisplay pr) {
+    phind = ph;
+    prev = pr;
+    next = null;
+    if (prev != null) prev.next = this;
+    setLayout(new BorderLayout());
+
+    empty = true;
+    current = new PhindTitle(ph);
+    add(current);
+  }
+
+  // Empty the contents of the display,
+  // and all the next displays
+  void emptyContents() {
+    if (empty == false) {
+      empty = true;
+      current = new PhindTitle(phind);
+      removeAll();
+      add(current);
+    }
+    if (next != null) next.emptyContents();
+  }
+
+  // Set the contents of this display
+  Component setContents( Component r ) {
+    removeAll();
+    add("Center", r);
+    current = r;
+    empty = false;
+    if (r.getClass().getName().equals("ResultBox")) {
+      ((ResultBox) r).display = this;
+    }
+    return r;
+  }
+
+
+  
+  // Display a component in the "most previous" display
+  ResultDisplay display( Component r ) {
+
+    if (prev == null) {
+      // if there is no previous box, add the component here
+      setContents(r);
+      return this;
+
+    } else if (prev.empty == true) {
+      // if the previous box is empty, add the component to it instead
+      return prev.display(r);
+
+    } else if (empty == true) {
+      // if this box is empty, add the compnent to it
+      setContents(r);
+      return this;
+
+    } else {
+      // if this box is occupied,
+      // shift it's contents prev-wards and add here.
+      prev.display(current);
+      setContents(r);
+      return this;
+    }
+  }
+
+}
+
+
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItem.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItem.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItem.java	(revision 16571)
@@ -0,0 +1,128 @@
+/**********************************************************************
+ *
+ * ResultItemDocument.java -- a result in the Phind applet
+ *
+ * Copyright 2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/*********************************************************************
+
+This class is used in the Phind java applet (Phind.java).
+
+A result item holds the data describing a single line returned from a phind
+query.  The complex functionality of phrase and URL items is implemented in
+subclasses; the base class handles simpler cases like the "get more phrases" 
+marker.
+
+**********************************************************************/
+
+package org.nzdl.gsdl.Phind;
+
+public class ResultItem {
+
+    // A text string describing the item
+    String text = "Generic ResultItem";
+
+    // There are several kinds of ResultItem, identified by their
+    // "kind" field, which has an integer value from the list below.
+    final static int message = 8;
+    final static int linkItem = 7;
+    final static int moreLinks = 6;
+    final static int phraseItem = 5;
+    final static int morePhrases = 4;
+    final static int documentItem = 3;
+    final static int moreDocuments = 2;
+    final static int unknownResultItem = 1;
+
+    // The kind of the item
+    int kind = unknownResultItem;
+
+    // When results are displayed, they are loosely sorted by their
+    // kind.  The user can change the sort order numbers with the 
+    // ResultOrder parameter in Phind.java.
+    static int sortMessage = 8;
+    static int sortLinkItem = 7;
+    static int sortMoreLinks = 6;
+    static int sortPhraseItem = 5;
+    static int sortMorePhrases = 4;
+    static int sortDocumentItem = 3;
+    static int sortMoreDocuments = 2;
+    static int sortUnknownResultItem = 1;
+
+    // the primary sort key
+    int sort = 0;
+    
+    // The frequency of the item (secondary sort key)
+    int frequency = 0;
+
+
+    // Create a blank ResultItem
+    ResultItem() {
+	text = "Unknown result type";
+	kind = unknownResultItem;
+	frequency = 0;
+    }
+
+    // Create a new ResultItem of some given kind
+    ResultItem(int newKind) {
+	kind = newKind;
+	frequency = 0;
+
+	if (kind == moreLinks) {
+	    text = "get more thesaurus links";
+	    sort = sortMoreLinks;
+	} else if (kind == morePhrases) {
+	    text = "get more phrases";
+	    sort = sortMorePhrases;
+	} else if (kind == moreDocuments) {
+	    text = "get more documents";
+	    sort = sortMoreDocuments;
+	} else {
+	    text = "Unknown result type";
+	    sort = sortUnknownResultItem;
+	}
+    }
+
+    // Test the type of a ResultItem
+    public boolean isLink() { return false; }
+    public boolean isMoreLinks() { return (kind == moreLinks); }
+    public boolean isPhrase() { return false; }
+    public boolean isMorePhrases() { return (kind == morePhrases); }
+    public boolean isDocument() { return false; }
+    public boolean isMoreDocuments() { return (kind == moreDocuments); }
+
+    // Return the bare text of the item
+    public String toString() { return(text.trim()); }
+
+    // Return the text of the item components
+    public String mainText() { return text; }
+    public String freqText() { 
+	if (frequency > 0) { return Integer.toString(frequency); } 
+	else { return ""; }
+    }
+    public String docsText() { return ""; }
+    public String prefixText() { return ""; }
+    public String suffixText() { return ""; }
+    public String hiddenText() { return ""; }
+}
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItemDocument.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItemDocument.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItemDocument.java	(revision 16571)
@@ -0,0 +1,70 @@
+/**********************************************************************
+ *
+ * ResultItemDocument.java -- a document result in the Phind applet
+ *
+ * Copyright 1997-2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/*********************************************************************
+
+This class is used in the Phind java applet (Phind.java).
+
+It contains information describing a document in which a search term 
+occurs.
+
+**********************************************************************/
+
+package org.nzdl.gsdl.Phind;
+
+public class ResultItemDocument extends ResultItem {
+
+    // The document's title is stored in the superclasses 
+    // text variable, and the number of times the phrase occurs
+    // in the frequency variable. 
+
+    // The document's unique object identifier (hash value).
+    String hash;
+
+    // Create a ResultItem for a document
+    ResultItemDocument(String newHash, String newTitle, String newFrequency) {
+	
+	kind = documentItem;
+	text = newTitle;
+
+	sort = sortDocumentItem;
+	frequency = Integer.valueOf(newFrequency).intValue();
+	hash = newHash;
+    }
+
+    // Is this item a document?
+    public boolean isDocument() { return true; }
+
+    // Return the bare text of the item
+    public String toString() { return(text); }
+
+    // Return the text of the item components
+    public String hiddenText() { return hash; }
+ 
+
+}
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItemLink.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItemLink.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItemLink.java	(revision 16571)
@@ -0,0 +1,86 @@
+/**********************************************************************
+ *
+ * ResultItemLink.java -- a thesaurus link in the Phind applet
+ *
+ * Copyright 2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/*********************************************************************
+
+This class is used in the Phind java applet (Phind.java).
+
+It contains information describing a thesaurus link.
+
+**********************************************************************/
+
+package org.nzdl.gsdl.Phind;
+
+public class ResultItemLink extends ResultItem {
+
+    // The phrase number, stored as a string and as a number
+    String id;
+    int symbol;
+
+    // The text of the link is stored in the inherited text field.
+
+    // The type of thesaurus link
+    String linkType;
+
+    // The total frequency is stored in the inherited frequency field.
+
+    // The document frequency of the thesaurus item
+    int documentFrequency;
+
+    // Create a ResultItem for a thesaurus link
+    ResultItemLink(String newId, String newText, String newLinkType, 
+		   String tf, String df) { 
+
+	kind = linkItem;
+	id = newId;
+	symbol = Integer.valueOf(newId).intValue();
+	text = newText.trim();
+	sort = sortLinkItem;
+	linkType = newLinkType;
+	frequency = Integer.valueOf(tf).intValue();
+	documentFrequency = Integer.valueOf(df).intValue();
+    }
+
+    // Is this item a phrase?
+    public boolean isLink() { return true; }
+
+    // Return the text of the item components
+    public String hiddenText() { return id; }
+    public String docsText() { 
+	if (documentFrequency <= 0) { return ""; }
+	else { return Integer.toString(documentFrequency); }
+    }
+    public String prefixText() { 
+	if (linkType.equals("RT")) { return "Related term"; }
+	else if (linkType.equals("BT")) { return "Broader term"; }
+	else if (linkType.equals("NT")) { return "Narrower term"; }
+	else if (linkType.equals("USE")) { return "Use"; }
+	else if (linkType.startsWith("UF")) { return "Used for"; }
+	else { return linkType; }
+    }
+}
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItemPhrase.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItemPhrase.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultItemPhrase.java	(revision 16571)
@@ -0,0 +1,85 @@
+/**********************************************************************
+ *
+ * ResultItemPhrase.java -- a phrase result in the Phind applet
+ *
+ * Copyright 2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/*********************************************************************
+
+This class is used in the Phind java applet (Phind.java).
+
+It contains information describing a phrase.
+
+**********************************************************************/
+
+package org.nzdl.gsdl.Phind;
+
+public class ResultItemPhrase extends ResultItem {
+
+    // The phrase number, stored as a string and as a number
+    String id;
+    int symbol;
+
+    // The text of the phrase is split into a prefix, body, and suffix.
+    // The body is the same as the parent phrase (or search term) and 
+    // the prefix and suffix are the surrounding text.
+    String prefix;
+    String body;
+    String suffix;
+
+    // The document frequency of the phrase
+    int documentFrequency;
+
+    // Create a ResultItem for a phrase
+    ResultItemPhrase(String newId, String tf, String df, 
+		     String p, String b, String s) {
+
+	kind = phraseItem;
+
+	id = newId;
+	symbol = Integer.valueOf(newId).intValue();
+
+	sort = sortPhraseItem;
+	frequency = Integer.valueOf(tf).intValue();
+	documentFrequency = Integer.valueOf(df).intValue();
+
+	prefix = p;
+	body = b;
+	suffix = s;
+	text = (prefix + " " + body + " " + suffix);
+
+    }
+
+    // Is this item a phrase?
+    public boolean isPhrase() { return true; }
+
+    // Return the text of the item components
+    public String mainText() { return body; }
+    public String docsText() { return Integer.toString(documentFrequency); }
+    public String prefixText() { return prefix; }
+    public String suffixText() { return suffix; }
+    public String hiddenText() { return id; }
+
+}
+
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultTitle.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultTitle.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/ResultTitle.java	(revision 16571)
@@ -0,0 +1,163 @@
+/**********************************************************************
+ *
+ * ResultTitle.java -- describe the contents of a ResultBox
+ *
+ * Copyright 1997-2000 Gordon W. Paynter
+ * Copyright 2000 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/*********************************************************************
+
+This class is used in the Phind java applet (Phind.java).
+
+ResultTitle is part of the result list displayed to the user.  It lists the
+phrase in the Result box, the number of expansions it occurs in, and the
+number of documents it occurs in.
+
+**********************************************************************/
+
+package org.nzdl.gsdl.Phind;
+
+import java.awt.Canvas;
+import java.awt.Graphics;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Dimension;
+import java.awt.Color;
+
+
+public class ResultTitle extends Canvas {
+
+  // Other objects associated with this 
+  Phind phind;
+  ResultBox parent;
+  ResultCanvas canvas;
+
+  // fonts and font spacings to use
+  Font plain, bold;
+  Graphics g;
+
+  // Create a ResultTitle from the ResultBox which is its parent.
+  ResultTitle(ResultBox p) {
+
+    parent = p;
+    phind = p.phind;
+    canvas = p.c;
+    g = getGraphics();
+
+    plain = phind.plainFont;
+    bold  = phind.boldFont;
+    
+    // Note: the size() and resize() methods are deprecated, but the newer
+    // getSize() and setSize() methods fail in NetScape 4
+    //Dimension d = getSize();
+    Dimension d = size();
+    d.height = phind.fontSize + 10;
+    //setSize(d);
+    resize(d);
+    
+  }
+
+  public void update(Graphics g) {
+    paint(g);
+  }
+
+  public void paint(Graphics g) {
+
+    // calculate the canvas size, margins, and spacing
+    Dimension canvasSize = size();
+    
+    g.setFont(plain);
+    int margin = g.getFontMetrics().stringWidth(" 8888 ");
+    int y = phind.fontSize + 5;
+
+    int rightMargin = canvas.size().width;
+    int secondColumn = rightMargin - margin;
+    int firstColumn = secondColumn - margin;
+
+    g.setColor(Color.white);
+    g.fillRect(0, 0, canvasSize.width, canvasSize.height);
+    g.setColor(Color.black);
+
+
+    // What is the phrase we are searching for?
+    String phrase = parent.searchPhrase.replace('+', ' ');
+ 
+    // Construct the description phrase
+    String links = "";
+    if (parent.numberOfThesaurusLinks <= 0) {
+	links = "";
+    } else if (parent.numberOfThesaurusLinks == 1) { 
+	links = "1 link";
+    } else if (parent.thesaurusLinksRetrieved == parent.numberOfThesaurusLinks) {
+	links = parent.numberOfThesaurusLinks + " links";
+    } else {
+	links = parent.thesaurusLinksRetrieved + " of " 
+	    + parent.numberOfThesaurusLinks + " links";
+    }
+
+    String expansions = "";
+    if (parent.numberOfExpansions <= 0) {
+	expansions = "no phrases";
+    } else if (parent.numberOfExpansions == 1) { 
+	expansions = "1 phrase";
+    } else if (parent.expansionsRetrieved == parent.numberOfExpansions) {
+	expansions = parent.numberOfExpansions + " phrases";
+    } else {
+	expansions = parent.expansionsRetrieved + " of " 
+	    + parent.numberOfExpansions + " phrases";
+    }
+
+    String documents = "";
+    if (parent.numberOfDocuments <= 0) { 
+	documents = "no documents";
+    } else if (parent.documentsRetrieved == 1) {
+	documents = "1 document";
+    } else if (parent.documentsRetrieved == parent.numberOfDocuments) {
+	documents = parent.numberOfDocuments + " documents";
+    } else {
+	documents = parent.documentsRetrieved + " of " 
+	    + parent.numberOfDocuments + " documents";
+    }
+
+    String status = "(";
+    if (parent.numberOfThesaurusLinks > 0) {
+	status = status + links + ", ";
+    } 
+    status = status + expansions + ", " + documents + ")";
+
+
+    // Draw the text 
+    g.setFont(bold);
+    g.drawString(phrase, 0, y);
+    int tab = g.getFontMetrics().stringWidth(phrase + "  ");
+
+    g.setFont(plain);
+    g.drawString(status, tab, y);
+    tab = tab + g.getFontMetrics().stringWidth(status);
+    
+    if (tab < firstColumn) {
+      g.drawString("docs", firstColumn, y);
+      g.drawString("freq", secondColumn, y);
+    }
+  }
+}
Index: /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/URLUTF8Encoder.java
===================================================================
--- /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/URLUTF8Encoder.java	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/java/org/nzdl/gsdl/Phind/URLUTF8Encoder.java	(revision 16571)
@@ -0,0 +1,159 @@
+/**********************************************************************
+ *
+ *
+ * URLUTF8Encoder.java -- encode UTF8 String into a URL form
+ *
+ * W3C® SOFTWARE NOTICE AND LICENSE
+ *
+ * Copyright © 1994-2000 World Wide Web Consortium, 
+ * (Massachusetts Institute of Technology, Institut National de 
+ * Recherche en Informatique et en Automatique, Keio University). 
+ * All Rights Reserved.  http://www.w3.org/Consortium/Legal/
+ * 
+ * This W3C work (including software, documents, or other related items) is
+ * being provided by the copyright holders under the following license. By
+ * obtaining, using and/or copying this work, you (the licensee) agree that
+ * you have read, understood, and will comply with the following terms and
+ * conditions:
+ * 
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation, with or without modification, for any purpose and without
+ * fee or royalty is hereby granted, provided that you include the following
+ * on ALL copies of the software and documentation or portions thereof,
+ * including modifications, that you make:
+ * 
+ *   1. The full text of this NOTICE in a location viewable to users of the
+ *      redistributed or derivative work.
+ * 
+ *   2. Any pre-existing intellectual property disclaimers, notices, or terms
+ *      and conditions. If none exist, a short notice of the following form
+ *      (hypertext is preferred, text is permitted) should be used within the
+ *      body of any redistributed or derivative code: "Copyright ©
+ *      [$date-of-software] World Wide Web Consortium, (Massachusetts
+ *      Institute of Technology, Institut National de Recherche en
+ *      Informatique et en Automatique, Keio University). All Rights
+ *      Reserved. http://www.w3.org/Consortium/Legal/"
+ * 
+ *   3. Notice of any changes or modifications to the W3C files, including the
+ *      date changes were made. (We recommend you provide URIs to the location
+ *      from which the code is derived.)
+ * 
+ * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS
+ * MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
+ * NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
+ * PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE
+ * ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
+ * 
+ * COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
+ * CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR
+ * DOCUMENTATION.
+ * 
+ * The name and trademarks of copyright holders may NOT be used in advertising
+ * or publicity pertaining to the software without specific, written prior
+ * permission. Title to copyright in this software and any associated
+ * documentation will at all times remain with copyright holders.
+ *
+ *********************************************************************/
+
+/**
+ * Provides a method to encode any string into a URL-safe
+ * form, the so-called "x-www-form-urlencoded" form.
+ * Non-ASCII characters are first encoded as sequences of
+ * two or three bytes, using the UTF-8 algorithm, before being
+ * encoded in "x-www-form-urlencoded".
+ */
+
+package org.nzdl.gsdl.Phind;
+
+public class URLUTF8Encoder
+{
+
+  final static String[] hex = {
+    "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
+    "%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f",
+    "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
+    "%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f",
+    "%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27",
+    "%28", "%29", "%2a", "%2b", "%2c", "%2d", "%2e", "%2f",
+    "%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37",
+    "%38", "%39", "%3a", "%3b", "%3c", "%3d", "%3e", "%3f",
+    "%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47",
+    "%48", "%49", "%4a", "%4b", "%4c", "%4d", "%4e", "%4f",
+    "%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57",
+    "%58", "%59", "%5a", "%5b", "%5c", "%5d", "%5e", "%5f",
+    "%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67",
+    "%68", "%69", "%6a", "%6b", "%6c", "%6d", "%6e", "%6f",
+    "%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77",
+    "%78", "%79", "%7a", "%7b", "%7c", "%7d", "%7e", "%7f",
+    "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
+    "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",
+    "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
+    "%98", "%99", "%9a", "%9b", "%9c", "%9d", "%9e", "%9f",
+    "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7",
+    "%a8", "%a9", "%aa", "%ab", "%ac", "%ad", "%ae", "%af",
+    "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7",
+    "%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf",
+    "%c0", "%c1", "%c2", "%c3", "%c4", "%c5", "%c6", "%c7",
+    "%c8", "%c9", "%ca", "%cb", "%cc", "%cd", "%ce", "%cf",
+    "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
+    "%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df",
+    "%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7",
+    "%e8", "%e9", "%ea", "%eb", "%ec", "%ed", "%ee", "%ef",
+    "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
+    "%f8", "%f9", "%fa", "%fb", "%fc", "%fd", "%fe", "%ff"
+  };
+
+  /**
+   * Encode a string to the "x-www-form-urlencoded" form, enhanced
+   * with the UTF-8-in-URL proposal. This is what happens:
+   *
+   * <ul>
+   * <li><p>The ASCII characters 'a' through 'z', 'A' through 'Z',
+   *        and '0' through '9' remain the same.
+   *
+   * <li><p>The space character ' ' is converted into a plus sign '+'.
+   *
+   * <li><p>All other ASCII characters are converted into the
+   *        3-character string "%xy", where xy is
+   *        the two-digit hexadecimal representation of the character
+   *        code
+   *
+   * <li><p>All non-ASCII characters are encoded in two steps: first
+   *        to a sequence of 2 or 3 bytes, using the UTF-8 algorithm;
+   *        secondly each of these bytes is encoded as "%xx".
+   * </ul>
+   *
+   * @param s The string to be encoded
+   * @return The encoded string
+   */
+  public static String encode(String s)
+  {
+    StringBuffer sbuf = new StringBuffer();
+    int len = s.length();
+    for (int i = 0; i < len; i++) {
+      int ch = s.charAt(i);
+      if ('A' <= ch && ch <= 'Z') {		// 'A'..'Z'
+	sbuf.append((char)ch);
+      } else if ('a' <= ch && ch <= 'z') {	// 'a'..'z'
+	sbuf.append((char)ch);
+      } else if ('0' <= ch && ch <= '9') {	// '0'..'9'
+	sbuf.append((char)ch);
+      } else if (ch == ' ') {			// space
+	sbuf.append('+');
+      } else if (ch <= 0x007f) {		// other ASCII
+	sbuf.append(hex[ch]);
+      } else if (ch <= 0x07FF) {		// non-ASCII <= 0x7FF
+	sbuf.append(hex[0xc0 | (ch >> 6)]);
+	sbuf.append(hex[0x80 | (ch & 0x3F)]);
+      } else {					// 0x7FF < ch <= 0xFFFF
+	sbuf.append(hex[0xe0 | (ch >> 12)]);
+	sbuf.append(hex[0x80 | ((ch >> 6) & 0x3F)]);
+	sbuf.append(hex[0x80 | (ch & 0x3F)]);
+      }
+    }
+    return sbuf.toString();
+  }
+
+}
+
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/Makefile.in
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/Makefile.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/Makefile.in	(revision 16571)
@@ -0,0 +1,149 @@
+###########################################################################
+#
+# Makefile -- src/oaiservr
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ../../..
+COMMON_DIR = $(GSDL_DIR)/gs2common
+RUNTIME_DIR = $(GSDL_DIR)/gs2runtime
+
+INDEXERS_DIR = $(COMMON_DIR)/indexers
+PACKAGES_DIR = $(RUNTIME_DIR)/packages
+COLSERVR_DIR = $(RUNTIME_DIR)/src/colservr
+PROTOCOL_DIR = $(RUNTIME_DIR)/src/protocol
+RECPT_DIR = $(RUNTIME_DIR)/src/recpt
+
+
+ENABLE_ACCENTFOLD = @ENABLE_ACCENTFOLD@
+ifeq ($(ENABLE_ACCENTFOLD), 1)
+ACCENTFOLD_LIBS = $(INDEXERS_DIR)/packages/unac/libunac.a 
+else
+ACCENTFOLD_LIBS = 
+endif
+
+USE_SQLITE = @USE_SQLITE@
+ifeq ($(USE_SQLITE), 1)
+SQLITE_LIBS = $(COMMON_DIR)/packages/sqlite/lib/libsqlite3.a -ldl -lpthread
+else
+SQLITE_LIBS = 
+endif
+
+
+CC = @CC@
+CFLAGS = @CFLAGS@ @COMPAT32BITFLAGS@
+CXX = @CXX@
+CXXFLAGS = @CXXFLAGS@ @COMPAT32BITFLAGS@
+INCLUDES = -I$(COMMON_DIR)/src/lib -I$(COLSERVR_DIR) -I$(PROTOCOL_DIR) -I$(RECPT_DIR) -I$(INDEXERS_DIR)/mgpp/text
+LDFLAGS = @LDFLAGS@ @COMPAT32BITFLAGS@
+LIBS = @LIBS@ @GDBM_LIBPATH@ -lgdbm -L$(PACKAGES_DIR)/expat/lib -lexpat $(ACCENTFOLD_LIBS) $(SQLITE_LIBS)
+INSTALL = @INSTALL@
+
+
+CXXCOMPILE = $(CXX) -c $(CXXFLAGS) $(INCLUDES)
+CXXLINK = $(CXX) $(LDFLAGS) -o $@
+
+
+.SUFFIXES:
+.SUFFIXES: .cpp .o
+.cpp.o:
+	$(CXXCOMPILE) -o $@ $< 
+
+
+RECPT_OBJECTS = \
+	$(RECPT_DIR)/cgiargs.o \
+	$(RECPT_DIR)/cgiutils.o \
+	$(RECPT_DIR)/htmlutils.o
+
+SOURCES = \
+	abstractlistaction.cpp \
+	dublincore.cpp \
+	identifyaction.cpp \
+	listidsaction.cpp \
+	listrecsaction.cpp \
+	listsetsaction.cpp \
+	metaformat.cpp \
+	metaformatsaction.cpp \
+	oaiaction.cpp \
+	oaiargs.cpp \
+	oaiconfig.cpp \
+	oaidispatcher.cpp \
+	oaimain.cpp \
+	oaitools.cpp \
+	recordaction.cpp \
+	resumptiontoken.cpp \
+	rfc1807.cpp
+
+OBJECTS = \
+	abstractlistaction.o \
+	dublincore.o \
+	identifyaction.o \
+	listidsaction.o \
+	listrecsaction.o \
+	listsetsaction.o \
+	metaformat.o \
+	metaformatsaction.o \
+	oaiaction.o \
+	oaiargs.o \
+	oaiconfig.o \
+	oaidispatcher.o \
+	oaimain.o \
+	oaitools.o \
+	recordaction.o \
+	resumptiontoken.o \
+	rfc1807.o
+
+GSDL_LIBS = \
+	$(PROTOCOL_DIR)/gsdlprotocol.a \
+	$(COLSERVR_DIR)/gsdlcolservr.a \
+	$(INDEXERS_DIR)/mg/src/text/libmgtext.a \
+	$(INDEXERS_DIR)/mg/lib/libmglib.a \
+	$(INDEXERS_DIR)/mgpp/text/libmgpptext.a \
+	$(INDEXERS_DIR)/mgpp/lib/libmgpplib.a \
+	$(COMMON_DIR)/src/lib/gsdllib.a
+
+EXECUTABLE_OBJECTS = \
+	$(OBJECTS) \
+	$(RECPT_OBJECTS) \
+	$(GSDL_LIBS)
+
+EXECUTABLE = oaiserver
+
+
+# Default target: make the oaiserver executable
+all: $(EXECUTABLE)
+
+oaiserver: $(EXECUTABLE_OBJECTS)
+	$(CXXLINK) $(EXECUTABLE_OBJECTS) $(LIBS)
+
+install: $(EXECUTABLE)
+	$(INSTALL) -m 755 -s $(EXECUTABLE) $(GSDL_DIR)/cgi-bin
+
+clean:
+	rm -f $(OBJECTS) $(EXECUTABLE)
+
+distclean:
+	rm -f $(OBJECTS) $(EXECUTABLE) Makefile
+
+depend:
+	makedepend -Y -- $(DEFS) $(INCLUDES) $(CXXFLAGS) -- $(SOURCES)
Index: /gsdl/trunk/runtime-src/src/oaiservr/README.txt
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/README.txt	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/README.txt	(revision 16571)
@@ -0,0 +1,101 @@
+OAI Server Configuration Instructions
+-------------------------------------
+
+Greenstone needs some configuration before successfully supporting OAI serving.  This consists of three steps:
+
+1) Server-wide configuration to support vital OAI commands such as Identify.
+   This allows the OAI client to obtain information on the maintainer of
+   the server, etc.  See the OAI documentation for further information on
+   the Identify verb.  These configurations are kept in gsdl/etc/oai.cfg.
+
+2) Configuring collections to be 'active' OAI collections; just as collections
+   in Greenstone can be 'private' or 'public', collections can similarly be
+   'visible' or 'invisible' to OAI.  By default, collections are NOT served
+   via OAI - you have to enable them by adding each collection's name to a
+   list in gsdl/etc/oai.cfg.
+
+3) Mapping your collection metadata to a "Namespace" supported by OAI.  At
+   present, Greenstone supports the Dublin Core metadata format alone in OAI,
+   and metadata fields in a Greenstone collection must be mapped into the
+   Dublin Core namespace.  This configuration can be done either server-wide,
+   for all collections, in gsdl/etc/oai.cfg or in the etc/collect.cfg of
+   each individual collection.
+
+This documentation explains how to set up Greenstone's configuration for steps 1-3 above, install, deplay and test OAI on your Greenstone system.
+
+Part 1: Server-Wide Configuration Information
+---------------------------------------------
+
+Your OAI server should provide some basic information on the collections it holds as a whole.  For this purpose, all collections on your server are treated the same: you cannot have different information for each collection.  In this section, we describe what information you should provide, and how to configure Greenstone correctly to provide it.
+
+The basic server-wide information is:
+  * The OAI repository (server) name - this is a human readable form such
+    as "The Research Authority's OAI Server".
+  * The central administrative email address for the OAI repository.
+  * The base URL for the repository.
+  * Which version of OAI the repository supports/delivers.
+  * A free text item of information about the OAI repository - e.g. its
+    purpose, size, origins, etc.
+
+These items are kept in the following items of gsdl/etc/oai.cfg.  The syntax rules for these configuration items are the same as for gsdl/etc/main.cfg -  e.g. strings containing spaces should be enclosed in quotation marks.  See the main Greenstone configuration documentation for further information.
+
+  * repositoryName
+       One item only, free text.
+  * maintainer
+       One item only, as a valid email address
+  * baseURL
+       One item only, see the example in the oai.cfg file.
+  * httpdomain 
+       NB: in the gsdlsite.cfg file, NOT oai.cfg
+       Should not require specific configuration if your Greenstone install
+       is already operational through your web server.
+  * oaiversion
+       One item only, which should be either "1.1 or "2.0"
+  * oaiinfo
+       Numerous items, which are usually in a label and value pair.
+       An example item may be:
+          oaiinfo sponsor "The Big Cheese Corporation"
+
+Sample items are already provided in the default oai.cfg file - please ensure that you complete these in your preferred text editor.
+
+
+Part 2: Enabling Collections
+----------------------------
+
+In addition to the items above, one further sort of item needs to be added to gsdl/etc/oai.cfg - a list of the collections that should be made available to OAI clients.  This list is supplied in one or more lines in gsdl/etc/oai.cfg in the form:
+
+  oaicollection OAIDemo HDL
+
+The first item in each line should be the same - "oaicollection" - followed by one or more collection names.  Each collection name should be the name of the folder/directory in the gsdl/collect directory which holds the collection.
+
+Once these items have been added to gsdl/etc/oai.cfg, the final stage of the OAI configuration can begin: mapping from a collection's own metdata fields into the Dublin Core metadata fields used by OAI.  This will be detailed in the folloowing section of this document.
+
+
+Part 3: Mapping fields
+----------------------
+
+In Greenstone, metadata fields are created by the collection designer.  These may follow an accepted standard - e.g. Dublin Core - be a modification or extension of an accepted standard, or a bespoke format specific to the needs of the particular collection.  As Greenstone installer, you should have decided upon one of these three approaches already.  You may have chosen one of the standard metadata structures incorporated into the Greenstone Librarian Interface (GLI), or created your own using your own metadata files and automatically extracted information from your document files.  Whatever the approach you have used for obtaining the metadata in your collection, or whatever the fields are that you have used in your collection, the approach to linking these fields (mapping them) to the OAI Dublin Core format is the same.
+
+The mapping of fields is done in two ways: first, globally for all collections, and secondly specifically for one collection.  The syntax for the configuration items to achieve these different mappings is the same.  The file in which they are placed determines whether they apply to all collections, are just one.  Global mappings are found with the other OAI configuration items in gsdl/etc/main.cfg whilst collection-specific mappings are placed in the etc/collect.cfg file of the collection itself.
+
+Mapping items in the configuration file take the following format:
+
+  oaimapping <greenstone fieldname> <dublin core fieldname>
+
+The syntax of each of the two fieldnames given above requires a little more detail; we will take the Dubline Core fieldname first.  
+
+The Dublin Core fieldsname should be given in the form "DC:<fieldname>", as OAI can support other metadata formats, and thus we use "DC:" to be clear that we are mapping to Dublin Core.  The fieldnames available for Dublin Core can be found on the central Dublin Core website at http://www.dublincore.org/.
+
+The Greenstone fieldname can be in two formats.  The simpler one is simply the name of the field to map from.  The more complex one has the name of the collection placed in front of the field name, followed by a colon.  e.g. "demo:Title" would mean the metadata field "Title" in the collection called "demo".  Using this, all mappings can be stored in the central gsdl/etc/oai.cfg file if you wish, and we recommend this approach.
+
+Let us recap at this point with a few example items for a gsdl/etc/oai.cfg:
+
+oaimapping Author dc.Creator
+oaimapping dls.Title  dc.Title
+oaimapping Photos:fileformat dc.Format
+
+The first item maps any occurrence of 'Author' in any collection to the Dublin Core 'Creator' field (there is no 'Author' field in DC).  The second item maps 'dls.Title' to 'dc.Title'. Finally, in the specific collection 'Photos', we will map the unique metadata field 'fileformat' to the Dublin Core 'Format' field.
+
+
+Installation and Testing
+------------------------
Index: /gsdl/trunk/runtime-src/src/oaiservr/abstractlistaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/abstractlistaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/abstractlistaction.cpp	(revision 16571)
@@ -0,0 +1,454 @@
+#include "abstractlistaction.h"
+#include "recptprototools.h"
+
+#include "oaitools.h"
+
+bool abstractlistaction::validateAction(recptproto *protocol, oaiargs &params, int &numArgs)
+{ 
+  // Remove any parameters that aren't valid for this action
+  text_tmap::const_iterator param_iterator = params.begin();
+  while (param_iterator != params.end())
+  {
+    if (param_iterator->first != "verb" &&
+	param_iterator->first != "from" &&
+	param_iterator->first != "until" &&
+	param_iterator->first != "set" &&
+	param_iterator->first != "resumptionToken" &&
+	param_iterator->first != "metadataPrefix")
+    {
+      params.erase(param_iterator->first);
+    }
+
+    param_iterator++;
+  }
+
+  text_t from  = params["from"];
+  text_t until = params["until"];
+
+  // from date must be less than, or equal to, until date
+  if ((from != "") && (until != "") && !(from <= until)){
+    this->errorType = "badArgument";
+    return false;
+  }
+
+  if (from != ""){
+    // Must be in the form YYYY-MM-DD
+    if(from.size() != 10){
+      this->errorType = "badArgument";
+      params.erase("from");
+    }
+    else{
+      if(from[4] != '-' || from[7] != '-'){
+	this->errorType = "badArgument";
+	params.erase("from");
+      }
+    }
+    ++numArgs; // Increase valid args count
+  }
+
+  if (until != ""){
+    // Must be in the form YYYY-MM-DD
+    if(until.size() != 10){
+      this->errorType = "badArgument";
+      params.erase("until");
+    }
+    else{
+      if(until[4] != '-' || until[7] != '-'){
+	this->errorType = "badArgument";
+	params.erase("until");
+      }
+    }
+    ++numArgs; // Increase valid args count
+  }
+
+  if (this->errorType == "badArgument")
+  {
+    return false;
+  }
+
+  if (params["set"] != "") { 
+    text_t gsdlSet = params["set"];
+    text_t gsdlCollect = "";
+
+    // given 'demo:CL2', toGSDL returns 'demo' in gsdlCollect and 'CL2' in gsdlSet. If there is no further
+    // set specified after the name of the collection however, then gsdlSet is empty.
+    oaiclassifier::toGSDL(gsdlCollect, gsdlSet);
+
+    comerror_t err;
+    ColInfoResponse_t cinfo;
+
+    // check that the collection is accessible
+    protocol->get_collectinfo(gsdlCollect, cinfo, err, cerr);
+    if (err != noError) {
+      this->errorType = "badArgument";
+      return false;
+    }
+
+    // exclude collections that are not listed in the configured OAI list
+    text_tarray &collections = this->configuration->getCollectionsList();
+    int          c;
+    for (c = 0; c < collections.size(); c ++) {
+      if (collections[c] == gsdlCollect)
+	break;
+    }
+    if (c == collections.size()) {
+      this->errorType = "badArgument";
+      return false;
+    }
+    
+    if (gsdlSet != "") {
+      // check the child set if it is given
+      if (!this->check_classifier(protocol, gsdlCollect, gsdlSet)) {
+	this->errorType = "badArgument";
+	return false;
+      }
+    }
+    ++numArgs;
+  }
+
+  if (params["resumptionToken"] != "") {
+    ResumptionToken token(params["resumptionToken"]);
+
+    if (!token.isValid()) {
+      this->errorType = "badResumptionToken";
+      return false;
+    }
+    ++numArgs;
+  }
+  
+  this->errorType = "";
+  return true;
+}
+
+//--------------------------------------------------------------------------------------------------
+
+bool abstractlistaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
+{
+  text_t from = params["from"];
+  text_t until = params["until"];
+  text_t metaFormat = params["metadataPrefix"];
+  bool   prevDocSeen;
+  ResumptionToken *token = NULL;
+
+  // start the call; clear down the total number of output documents
+  this->outputDocs = 0;
+
+  // We don't actually handle resumptionTokens yet; if we get one, ignore it
+  if (params["resumptionToken"] != "") {
+    token = new ResumptionToken(params["resumptionToken"]);
+  }
+
+  this->replyToken = NULL;
+
+  // if we've been asked for a set, then use it!
+  if (params["set"] != "") {
+    // get the children of this set
+    text_t gsdlSet = params["set"];
+    text_t gsdlCollect = "";
+
+    // given 'demo:CL2', toGSDL returns 'demo' in gsdlCollect and 'CL2' in gsdlSet. If there is no further
+    // set specified after the name of the collection however, then gsdlSet is empty.
+    oaiclassifier::toGSDL(gsdlCollect, gsdlSet);
+
+    // If gsdlSet is empty, then the user is requesting all the identifiers for the collection, so 
+    // we simply output all docs via their oai_id tag. But if a specific subset IS requested, then
+    // use recurse_set() to traverse any sub classifiers to find the relevant docs.
+    if(gsdlSet == ""){
+      ColInfoResponse_t cinfo;
+      comerror_t err;
+      this->output_content_for_col(output, protocol, gsdlCollect, cinfo, err, params);
+    }
+    else {
+      if (this->check_classifier(protocol, gsdlCollect, gsdlSet)) {
+	this->recurse_set(output, protocol, gsdlCollect, gsdlSet, params, token);
+      }
+    }
+  }
+  // output all records in all hierarchies
+  else {
+    this->output_content_for_all(output, protocol, params);
+  }
+
+  // If - regardless of set required - no documents have been seen, throw an error.
+  if (this->configuration->getOAIVersion() >= 200 && this->prevDocSeen == false) {
+    errorType = "noRecordsMatch";
+    this->output_error(output, errorType);
+
+    return false;
+  }
+
+  // do a resumption token if required; errors cancel a token...
+  if (this->replyToken != NULL && this->errorType == "") {
+    output << "  <resumptionToken>" << endl;
+    output << "    " << this->replyToken->getToken() << endl;
+    output << "  </resumptionToken>" << endl;
+  }
+
+  return true;
+}
+
+//--------------------------------------------------------------------------------------------------
+
+void abstractlistaction::output_content_for_col(ostream &output, recptproto *protocol, text_t &gsdlCollect,
+						ColInfoResponse_t &cinfo, comerror_t &err, oaiargs &params)
+{ int startDoc = 0;
+
+  // get the collection information
+  protocol->get_collectinfo(gsdlCollect, cinfo, err, *this->logout);
+
+  // check resumption token
+  if (params["resumptionToken"] != "") {
+    ResumptionToken token(params["resumptionToken"]);
+    if (token.getCollection() == gsdlCollect) {
+      startDoc = token.getPosition() - 1; // first document is said to be 1..
+    }
+  }
+  
+  // If numDocs is 0, do nothing - this->prevDocSeen will stay false if this is the only collection
+  // looked at, or will keep whatever value it had prior to this col (ensures that if the flag has
+  // been set to true by a previous collection that this won't overwrite it to be false). 
+  if (cinfo.numDocs > 0) {
+    int errorCount      = 0; // Count the number of errors found in the given collection
+    text_t from         = params["from"];
+    text_t until        = params["until"];
+
+    for (long i = startDoc; i < cinfo.numDocs; ++i) {
+      if (errorCount > 3) { // If num errors reaches the cut-off value, bail.
+	cerr << "Error: too many records(" << errorCount << ") in the " << gsdlCollect 
+	     << " collection have invalid or non-existant oai_ids - skipping remainder of collection.\n";
+	return;
+      }
+      
+      text_t oai_id = "oai.";
+      oai_id += i;
+      
+      text_t gsdl_id = oaiclassifier::getGSDL_OID(gsdlCollect, oai_id, protocol, *this->logout);
+      
+      if (gsdl_id == "") { // If the string is empty, then the document didn't have an oai_id, so
+	++errorCount;     // increase error count
+	continue;
+      }
+
+
+      // Check that the item with the 0ID 'gsdl_id' has a lastmodified field that fits within
+      // the required date range (if specified).
+      if (this->inDateRange(params["from"], params["until"], gsdlCollect, gsdl_id, protocol, output)) {
+	if (this->output_document(output, protocol, gsdlCollect, gsdl_id, params["metadataPrefix"])) {
+	  // this should be an IF statement, where prevDocSeen is only set to true if the above
+	  // function call returns true (indicating that the doc supported the metadata prefix) but
+	  // for some reason this is always false. This means that if no doc in the requested set supports
+	  // the metadata format, the "no records match" error that should be thrown won't be...
+	  //
+	  // GRB: the above comment is no longer true; proper checks are made
+	  this->prevDocSeen = true;
+	  ++this->outputDocs;
+	}
+      }
+
+      // if we've output the number of resumption documents; prepare a resumptionToken
+      if (this->outputDocs == this->configuration->resumeAfter()) {
+	this->replyToken = new ResumptionToken(gsdlCollect, "", "");
+	this->replyToken->setPosition("", i+2);
+	break;
+      }
+    }
+
+    cinfo.clear(); // Clear for next collection to use (if there is one).
+  }
+}
+
+//--------------------------------------------------------------------------------------------
+// Returns true if at least one document record is found
+void abstractlistaction::output_content_for_all(ostream &output, recptproto *protocol, oaiargs &params)
+{
+  ColInfoResponse_t cinfo;
+  comerror_t        err;
+  text_tarray       collections;
+  text_t            gsdlCollect = "";
+  ResumptionToken   *token = NULL;
+
+  // get a list of the collections available
+  collections = this->configuration->getCollectionsList();
+  //  protocol->get_collection_list(collections, err, output); 
+  
+  if (params["resumptionToken"] != "") {
+    token = new ResumptionToken(params["resumptionToken"]);
+  }
+
+  for(int current_col = 0; current_col < collections.size(); ++current_col){
+    gsdlCollect = collections[current_col];
+
+    // ignore all leading collections before the one that matches the resumptiontoken
+    if (token != NULL &&
+	token->getCollection() != gsdlCollect)
+    { continue;
+    }
+
+    this->output_content_for_col(output, protocol, gsdlCollect, cinfo, err, params);
+
+    // once we've output at least one collection, continue 
+    // outputting all others until the resumption total hits
+    token = NULL; 
+
+    if (this->outputDocs == this->configuration->resumeAfter()) {
+      break;
+    }
+  }
+}
+
+//-------------------------------------------------------------------------------------------------
+// Check that the requested from/until dates don't include a time, as this would be asking for too
+// fine a level of granularity, one that greenstone doesn't support. An OAI error must be thrown.
+/*
+bool abstractlistaction::granularityTooFine(text_t &from, text_t &until)
+{
+  if (from != "" && from.){
+    
+  }
+  
+}
+*/
+//-------------------------------------------------------------------------------------------------
+
+bool abstractlistaction::check_classifier(recptproto *protocol, const text_t &collection,
+					  const text_t &classifier)
+{ text_t topClass;
+  FilterResponse_t response;
+  text_tset        metadata;
+  ofstream         logout("oai.log", ios::app);
+
+  // exclude false children of a top-level classifier immediately...
+  if (!get_info(classifier, collection, "", metadata, false, protocol, response, logout)) {
+    return false;
+  }
+  
+  // now check the top-level parent
+  metadata.insert("supportsmemberof");
+
+  text_t::const_iterator dot = findchar(classifier.begin(), classifier.end(), '.');
+  if (dot != classifier.end()) {
+    topClass = substr(classifier.begin(), dot);
+  }
+  else {
+    topClass = classifier;
+  }
+
+  if (!get_info(topClass, collection, "", metadata, false, protocol, response, logout)) {
+    return false;
+  }
+  
+  if (response.docInfo[0].metadata["supportsmemberof"].values.size() == 0) {
+    return false;
+  }
+
+  if (response.docInfo[0].metadata["supportsmemberof"].values[0] != "true") {
+    return false;
+  }
+
+  return true;
+}
+
+void abstractlistaction::recurse_set(ostream &output, recptproto *protocol, const text_t &collection, 
+				     const text_t &classifier, oaiargs &params, ResumptionToken *resumptionToken)
+{
+  // metadata for this call
+  FilterResponse_t response;
+  text_tset        metadata;
+  ofstream         logout("oai.log", ios::app);
+  text_t           from = params["from"];
+  text_t           until = params["until"];
+  text_t           metadataPrefix = params["metadataPrefix"];
+  //  ResumptionToken  resumptionToken(params["resumptionToken"]);
+  int              startPos = 0;
+
+  // This is a recursive function, and so just because the current set is empty doesn't mean we necessarily
+  // want to throw a 'noRecordsMatch' error; another set (parent/sibling/child) may have had documents. It
+  // is therefore not enough to check that the response object in the current iteration has no docs - we
+  // must also verify that NO OTHER set has had any documents. This is done with the 'prevDocSeen' flag.
+  // It is set to FALSE initially, but as soon as we see a set that isn't empty, it is set to TRUE. The 
+  // 'noRecordsMatch' error will only be thrown if, after all appropriate sets have been recursed into, 
+  // the 'prevDocSeen' flag is still FALSE. The function returns false if no docs were seen, allowing us to 
+  // throw the noRecordsMatch error.
+  
+  //  bool prevDocSeen = false;
+
+  get_children(classifier, collection, "", metadata, false, protocol, response, *this->logout);
+
+  if (params["resumptionToken"] != "") {
+    // if we're at a resumptionToken
+    if (classifier == resumptionToken->getNode()) {
+      startPos = resumptionToken->getPosition();
+    }
+    else {
+      text_t fullNode = resumptionToken->getNode();
+      text_t::iterator leafIter = fullNode.begin() + classifier.size();
+
+      // if the next character isn't a dot, blow up!
+      if (*leafIter != '.') {
+	// fatal error;
+	exit(1);
+      }
+      
+      // get the first '.' after the current classifier point;
+      text_t::iterator separator = findchar(leafIter + 1, fullNode.end(), '.');
+
+      // now, create a new subpath
+      text_t nextNode = substr(fullNode.begin(), separator);
+
+      // seek forward; TODO: improve performance of this 
+      for (int c = 0; c < response.numDocs; ++c) {
+	if (response.docInfo[c].OID == nextNode) {
+	  startPos = c;
+	  break;
+	}
+      }
+    }
+
+    // We need to subtract one from the startPos value to turn it into an index value
+    startPos--;
+  }
+  
+  for (int c = startPos; c < response.numDocs; ++c) {
+    text_t child = response.docInfo[c].OID;
+    
+    // distinguish classifiers and documents by checking whether OID 
+    // starts with CL or not
+    text_t childHead;
+    text_t::const_iterator start = child.begin();
+    text_t::const_iterator here  = child.begin();
+    here += 2;
+    childHead = substr(start, here);
+    
+    // documents we output now
+    if (childHead != "CL") {
+      // Check that the item with the 0ID 'gsdl_id' has a lastmodified field that fits
+      // within the required date range (if specified)
+      if (this->inDateRange(from, until, collection, child, protocol, output)) {
+	// TODO: check that the document can be disseminated in the required metadataPrefix
+
+	if (this->output_document(output, protocol, collection, child, metadataPrefix)) {
+	  this->prevDocSeen = true;
+	  ++this->outputDocs;
+	}
+      }
+    }
+    // children which are classifiers are recursed
+    else {
+      if (resumptionToken != NULL) {
+	int depth = countchar(classifier.begin(), classifier.end(), '.');
+	resumptionToken->setOffset(depth, c+2);
+      }
+      this->recurse_set(output, protocol, collection, child, params, resumptionToken);
+    }
+
+    if (this->outputDocs == this->configuration->resumeAfter()) {
+      this->replyToken = new ResumptionToken(collection, params["set"], "");
+      this->replyToken->setPosition(classifier, c+2);      
+      break;
+    }
+  }
+}
+
+
+
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/abstractlistaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/abstractlistaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/abstractlistaction.h	(revision 16571)
@@ -0,0 +1,26 @@
+#ifndef _ABSTRACTLISTACTION_H_
+#define _ABSTRACTLISTACTION_H_
+
+#include "oaiaction.h"
+#include "resumptiontoken.h"
+
+class abstractlistaction : public oaiaction
+{ 
+ public:
+  abstractlistaction(const text_t &name) : oaiaction(name) {this->prevDocSeen = false;}
+  virtual bool validateAction(recptproto *protocol, oaiargs &params, int &numArgs); // Check that this is a valid action
+  virtual bool output_document(ostream &output, recptproto *protocol, const text_t &collection, 
+			       const text_t &OID, const text_t &metadataPrefix) = 0;
+  virtual bool output_content(ostream &output, recptproto *protocol, oaiargs &params);
+  virtual void output_content_for_all(ostream &output, recptproto *protocol, oaiargs &params);
+  virtual void output_content_for_col(ostream &output, recptproto *protocol, text_t &gsdlCollect, 
+				      ColInfoResponse_t &cinfo, comerror_t &err, oaiargs &params);
+  virtual void recurse_set(ostream &output, recptproto *protocol, const text_t &collection, 
+			   const text_t &classifier, oaiargs &params, ResumptionToken *resumptionToken);
+ protected:
+  bool prevDocSeen;
+  int  outputDocs;
+  ResumptionToken *replyToken;
+  bool check_classifier(recptproto *protocol, const text_t &collection, const text_t &classifier);
+};
+#endif
Index: /gsdl/trunk/runtime-src/src/oaiservr/dublincore.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/dublincore.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/dublincore.cpp	(revision 16571)
@@ -0,0 +1,67 @@
+
+#include "dublincore.h"
+
+const text_t dublin_core::formatName() {
+  return "oai_dc";
+}
+
+const text_t dublin_core::formatPrefix() {
+  return "dc";
+}
+
+bool dublin_core::output_record(ostream &output, recptproto *protocol, const text_t &collection, 
+				const text_t &record_OID) 
+{
+  return metaformat::output_record(output, protocol, collection, record_OID);
+}
+
+void dublin_core::output_metadata_header(ostream &output)
+{ 
+  output << "    <metadata>\n";
+  
+  if (this->oaiConfigure->getOAIVersion() <= 110){
+    // output dublin core wrapper for OAI v1.1
+    output << "      <dc xmlns=\"http://purl.org/dc/elements/1.1/\"\n"
+	   << "          xmlns:xsi=\"http://www.w3c.org/2001/XMLSchema-instance\"\n"
+	   << "          xsi:schemaLocation=\"http://purl.org/dc/elements/1.1/\n"
+	   << "                              http://www.openarchives.org/OAI/1.1/dc.xsd\">\n";
+  }
+  else { 
+    output << "      <oai_dc:dc\n"
+	   << "          xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\"\n"
+	   << "          xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"
+	   << "          xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+	   << "          xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/\n"
+	   << "                              http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">\n";
+  }
+}
+
+void dublin_core::output_metadata_footer(ostream &output)
+{
+  if (this->oaiConfigure->getOAIVersion() <= 110) {
+    output << "      </dc>" << endl;
+  }
+  else {
+    output << "      </oai_dc:dc>" << endl;
+  }
+
+  output << "    </metadata>" << endl; 
+  output.flush();
+}
+
+bool dublin_core::output_formatdata(ostream &output)
+{
+  output << "    <metadataPrefix>oai_dc</metadataPrefix>" << endl;
+
+  if (this->oaiConfigure->getOAIVersion() <= 110) {
+    output << "    <schema>http://www.openarchives.org/OAI/1.1/dc.xsd</schema>" << endl
+	   << "    <metadataNamespace>http://purl.org/dc/elements/1.1/</metadataNamespace>" << endl;
+  }
+  else {
+    output << "    <schema>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</schema>" << endl
+	   << "    <metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace>" 
+	   << endl;
+  }
+  return true;
+}
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/dublincore.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/dublincore.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/dublincore.h	(revision 16571)
@@ -0,0 +1,17 @@
+#include "metaformat.h"
+
+class dublin_core : public metaformat
+{
+ protected:
+  virtual void output_metadata_header(ostream &output);
+  virtual void output_metadata_footer(ostream &output);
+ public:
+  dublin_core() : metaformat(){};
+  virtual const text_t formatName();
+  virtual const text_t formatPrefix();
+  virtual bool output_record(ostream &output, recptproto *protocol, const text_t &collection, 
+			     const text_t &record_OID);
+  virtual bool output_formatdata(ostream &output);
+};
+
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/identifyaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/identifyaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/identifyaction.cpp	(revision 16571)
@@ -0,0 +1,64 @@
+#include "identifyaction.h"
+
+bool identifyaction::validateAction(recptproto *protocol, oaiargs &params)
+{ 
+  int params_size = params.getSize();
+
+  // Remove any parameters that aren't valid for this action
+  text_tmap::const_iterator param_iterator = params.begin();
+  while (param_iterator != params.end())
+  {
+    if (param_iterator->first != "verb")
+    {
+      params.erase(param_iterator->first);
+    }
+
+    param_iterator++;
+  }
+  
+  //"Verb=Identify" should be the only parameter - if there are others, throw an error.
+  // Don't need to check that the param we have is "Verb=Identify", as it has to be to get to here.
+  if(params_size != 1){
+    this->errorType = "badArgument";
+    return false;
+  }
+  
+  return true;
+}
+
+bool identifyaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
+{
+  // Get the repository name (some human-readable name for the site, or superset of collections)
+  text_t repositoryName = this->configuration->getCollectionConfig("", "repositoryName");
+  // Get admin's email address (i.e. the site maintainer)
+  text_t maintainer = this->configuration->getCollectionConfig("", "maintainer");
+  text_t version = (this->configuration->getOAIVersion() <= 110) ? (text_t)"1.1":(text_t)"2.0";
+
+  text_t baseURL = this->configuration->getCollectionConfig("", "baseURL");
+  
+  output << "  <repositoryName>"  << repositoryName << "</repositoryName>" << endl;
+  output << "  <baseURL>"         << baseURL     << "</baseURL>" << endl; // Tack on the app name
+  output << "  <protocolVersion>" << version        << "</protocolVersion>" << endl;
+  output << "  <adminEmail>"      << maintainer     << "</adminEmail>" << endl;
+
+  if(version == "2.0"){
+    // earliestDatestamp *should* be the YYYY-MM-DD format of the oldest lastmodified record in the
+    // repository, but we're just setting it to be the default oldest possible date - ugly, but judged
+    // not to be worth the effort of trolling through all the lastmodified dates (by others with more 
+    // say than me)
+    output << "  <earliestDatestamp>1970-01-01</earliestDatestamp>\n"
+	   << "  <deletedRecord>no</deletedRecord>\n"
+	   << "  <granularity>YYYY-MM-DD</granularity>\n";
+  }
+  // list all configuration information
+  text_tmap::iterator here = this->configuration->getInformation()->begin();
+  text_tmap::iterator end  = this->configuration->getInformation()->end();
+  while (here != end) {
+    output << "  <" << here->first << ">" << here->second;
+    output << "  </" << here->first << ">" << endl;
+    ++here;
+  }
+  
+  return true;
+}
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/identifyaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/identifyaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/identifyaction.h	(revision 16571)
@@ -0,0 +1,13 @@
+#include "oaiaction.h"
+
+#include "oaiconfig.h"
+
+class identifyaction : public oaiaction
+{
+ public:
+  identifyaction() : oaiaction("Identify") {}
+  virtual bool validateAction(recptproto *protocol, oaiargs &params);
+ protected:
+  bool output_content(ostream &output, recptproto *protocol, oaiargs &params);
+};
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/listidsaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/listidsaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/listidsaction.cpp	(revision 16571)
@@ -0,0 +1,72 @@
+#include "listidsaction.h"
+#include "recptprototools.h"
+#include "oaitools.h"
+
+//--------------------------------------------------------------------------------------------------
+
+bool listidsaction::validateAction(recptproto *protocol, oaiargs &params)
+{ 
+  int params_size = params.getSize();
+  int numArgs  = 1; // For "verb" arg
+
+  if (!abstractlistaction::validateAction(protocol, params, numArgs)) {
+    return false;
+  }
+
+  // In OAI v1.1 metadataPrefix is not allowed.
+  if (this->configuration->getOAIVersion() <= 110){
+    if(numArgs != params_size){
+      this->errorType = "badArgument";
+      return false;
+    }
+  }
+  else { // In OAI v2.0, it is compulsory
+    text_t metaFormat = params["metadataPrefix"];
+    if (metaFormat == ""){
+      this->errorType = "badArgument";
+      return false;
+    }
+    else { // If it isn't empty, increase the valid args count and compare this to the total num of args
+      if (++numArgs != params_size){
+	this->errorType = "badArgument";
+	return false;
+      }
+    }
+    // Check that the metadataPrefix is a format we support
+    if (this->formatNotSupported(metaFormat)){
+      this->errorType = "cannotDisseminateFormat";
+      return false;
+    }
+  }
+  this->errorType = "";
+  return true;
+}
+
+//--------------------------------------------------------------------------------------------------
+
+bool listidsaction::output_document(ostream& output, recptproto *protocol, const text_t &collection, 
+				    const text_t &OID, const text_t &metadataPrefix /* ignored */)
+{
+  FilterResponse_t response;
+  ResultDocInfo_t  doc_info;
+  text_tset        metadata;
+  ofstream         logout("oai.log", ios::app);
+  text_t           lastModified;
+  int              oaiVersion = this->configuration->getOAIVersion();
+
+  get_info(OID, collection, "", metadata, false, protocol, response, logout);
+  doc_info = response.docInfo[0];
+  this->getLastModifiedDate(doc_info, lastModified);
+  
+  // output the record for this document
+  text_t oaiLabel = OID;
+  oaiclassifier::toOAI(collection, oaiLabel);
+
+  if(oaiVersion <= 110)
+    output << "  <identifier>" << oaiLabel << "</identifier>\n";
+  else
+    this->output_record_header(output, oaiLabel, lastModified, 
+			       doc_info.metadata["memberof"].values, oaiVersion);
+
+  return true;
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/listidsaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/listidsaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/listidsaction.h	(revision 16571)
@@ -0,0 +1,12 @@
+#include "abstractlistaction.h"
+
+class listidsaction : public abstractlistaction
+{
+ public:
+  listidsaction() : abstractlistaction("ListIdentifiers") { };
+ protected:
+  bool validateAction(recptproto *protocol, oaiargs &params);
+  bool output_document(ostream &output, recptproto *protocol, const text_t &collection, const text_t &OID,
+		       const text_t &metadataPrefix = "");
+};
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/listrecsaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/listrecsaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/listrecsaction.cpp	(revision 16571)
@@ -0,0 +1,56 @@
+#include "listrecsaction.h"
+
+#include "oaitools.h"
+#include "recordaction.h"
+
+bool listrecsaction::validateAction(recptproto *protocol, oaiargs &params)
+{ 
+  int params_size = params.getSize();
+
+  text_t meta    = params["metadataPrefix"];
+  int    numArgs = 1;                // 1st arg (Verb=ListRecords) must be present for us to be here
+
+  if (!abstractlistaction::validateAction(protocol, params, numArgs)) {
+    return false;
+  }
+
+  // metadataPrefix is required - if it's not there, throw an error. Note that the arg isn't 
+  // required (or allowed) if a resumptionToken is given, but as we don't handle resumption
+  // tokens this is sufficient. When we DO handle the tokens, this will have to change.
+  if (meta == "") { 
+    this->errorType = "badArgument";
+    return false;
+  }
+  else {
+    ++numArgs; // If it's there, increase arg count
+  }
+  
+  // The number of valid args should be exactly equal to the number of args actually there.
+  // If not, throw a 'badArgument' error.
+  if (numArgs != params_size) {
+    this->errorType = "badArgument";
+    return false;
+  }
+     
+  if (this->formatNotSupported(meta)) { // Check that the metadataPrefix is supported
+    this->errorType = "cannotDisseminateFormat";
+    this->record_action->setErrorType(this->errorType);
+    return false;
+  }
+
+  return true;
+}
+
+//-----------------------------------------------------------------------------------------------
+
+bool listrecsaction::output_document(ostream &output, recptproto *protocol, const text_t &collection, 
+		     const text_t &OID, const text_t &metadataPrefix)
+{
+  this->record_action->output_record(output, protocol, collection, OID, metadataPrefix);
+  return true;
+}
+  
+//-----------------------------------------------------------------------------------------------
+
+
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/listrecsaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/listrecsaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/listrecsaction.h	(revision 16571)
@@ -0,0 +1,16 @@
+#include "abstractlistaction.h"
+
+#include "recordaction.h"
+
+class listrecsaction : public abstractlistaction
+{
+ public:
+  void set_recordMaker(recordaction *ptr) { this->record_action = ptr; }
+  listrecsaction() : abstractlistaction("ListRecords") { };
+  
+ protected:
+  recordaction *record_action;
+  virtual bool validateAction(recptproto *protocol, oaiargs &params);
+  bool output_document(ostream &output, recptproto *protocol, const text_t &collection, 
+		     const text_t &OID, const text_t &metadataPrefix);
+};
Index: /gsdl/trunk/runtime-src/src/oaiservr/listsetsaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/listsetsaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/listsetsaction.cpp	(revision 16571)
@@ -0,0 +1,228 @@
+#include "listsetsaction.h"
+
+#if defined(GSDL_USE_STL_H)
+#include <fstream.h>
+#else
+#include <fstream>
+#endif
+
+#include "recptprototools.h"
+#include "oaitools.h"
+
+bool listsetsaction::validateAction(recptproto *protocol, oaiargs &params)
+{
+  int params_size = params.getSize();
+
+  // Remove any parameters that aren't valid for this action
+  text_tmap::const_iterator param_iterator = params.begin();
+  while (param_iterator != params.end())
+  {
+    if (param_iterator->first != "verb" && param_iterator->first != "resumptionToken")
+    {
+      params.erase(param_iterator->first);
+    }
+
+    param_iterator++;
+  }
+
+  if (params_size != params.getSize()) {
+    this->errorType = "badArgument";
+    return false;
+  }
+
+  if (params["resumptionToken"] != "") {
+    ResumptionToken token(params["resumptionToken"]);
+    // TO DO: Resumption token validation checking (the token.isValid() function is useless for ListSets)
+    // if (!token.isValid()) {
+    //   this->errorType = "badResumptionToken";
+    //   return false;
+    // }
+  }
+
+  return true;
+}
+
+bool listsetsaction::output_content(ostream &output, recptproto *protocol, text_tset &collections, oaiargs &params)
+{
+  text_tset::iterator here = collections.begin();
+  text_tset::iterator end  = collections.end();
+  while (here != end) {
+    text_t collect = *here;
+    this->output_content(output, protocol, params);
+    ++here;
+  }
+  return true;
+}
+
+bool listsetsaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
+{
+  // output the total list of classifier points
+
+  // variables required
+  text_t browseOID = "browse";
+  FilterResponse_t response;
+  comerror_t       err;
+  text_tarray &    collections = this->configuration->getCollectionsList();
+  text_tset        metadata;
+  ofstream         logout("oai.log", ios::app);
+  
+  // get a list of the collections available
+  //  protocol->get_collection_list(collections, err, output); 
+  if (collections.size() == 0) {
+    logout << "Found *no* OAI collections - check main.cfg for oaicollection items and read the OAI documentation.\n";
+  }
+
+  // check resumption token
+  int startSet = 0;
+  if (params["resumptionToken"] != "") {
+    ResumptionToken token(params["resumptionToken"]);
+    startSet = token.getPosition() - 1; // first document is said to be 1..
+  }
+  this->replyToken = NULL;
+
+  this->setNumber = 0;
+  this->setsOutput = 0;
+  for(int current_col = 0; current_col < collections.size(); ++current_col) {
+    // output the collection as a set, first, then its children
+    text_t gsdlCollect = collections[current_col];
+
+    if (this->setsOutput == this->configuration->resumeAfter())
+    {
+      this->replyToken = new ResumptionToken("", "", "");
+      this->replyToken->setPosition("", this->setNumber+1);
+      break;
+    }
+
+    if (this->setNumber >= startSet)
+    {
+      output << "  <set>" << endl;
+      output << "    <setSpec>" << gsdlCollect << "</setSpec>" << endl;;
+      output << "    <setName>" << gsdlCollect << "</setName>" << endl;
+      output << "  </set>" << endl;
+      this->setsOutput++;
+    }
+    setNumber++;
+
+    // get all the children of the (relevant) classifier data structures
+    get_children(browseOID, gsdlCollect, "", metadata, false, protocol, response, logout);
+    // and send them to the "recurse_content" list
+    for (int c = 0; c < response.numDocs; ++c) {
+      this->recurse_content(output, protocol, gsdlCollect, response.docInfo[c].OID, gsdlCollect, startSet);
+    }
+  }
+
+  // do a resumption token if required; errors cancel a token...
+  if (this->replyToken != NULL && this->errorType == "") {
+    output << "  <resumptionToken>" << endl;
+    output << "    " << this->replyToken->getToken() << endl;
+    output << "  </resumptionToken>" << endl;
+  }
+
+  return true;
+}
+
+void listsetsaction::recurse_content(ostream &output, recptproto *protocol, text_t &collection, 
+				     const text_t &classifier, text_t setHierarchy, int startSet)
+{
+  // metadata for this call
+  FilterResponse_t response;
+  text_tset        metadata;
+  ofstream         logout("oai.log", ios::app);
+
+  if (this->setsOutput == this->configuration->resumeAfter())
+  {
+    this->replyToken = new ResumptionToken("", "", "");
+    this->replyToken->setPosition("", this->setNumber+1);
+    return;
+  }
+
+  metadata.insert("contains");
+  metadata.insert("Title");
+  metadata.insert("supportsmemberof");
+
+  // get the document information
+  if (!get_info(classifier, collection, "", metadata, false, protocol, response, logout)) {
+    //cerr << "recurse content: Bad identifier or protocol " << classifier << endl;
+    return;
+  }
+
+  // check for top-level classifiers, check if the set name includes a '.'; if 
+  // not, it is a top-level classifier: check for memberof support.  Those without
+  // memberof support will not be supported on OAI
+  if (findchar(classifier.begin(), classifier.end(), '.') == classifier.end()) {
+    if (response.docInfo[0].metadata["supportsmemberof"].values.size() > 0) {
+      text_t memberOf = response.docInfo[0].metadata["supportsmemberof"].values[0];
+      if (memberOf != "true") {
+	return;
+      }
+    }
+    else {
+      return;
+    }
+  }
+
+  MetadataInfo_tmap::iterator here = response.docInfo[0].metadata.begin();
+  MetadataInfo_tmap::iterator end  = response.docInfo[0].metadata.end();
+  text_t title;
+
+  while (here != end)
+  {
+    // Each set should only have one title - hence we only output one title here
+    // (it is a set title, not a collection)
+    if (here->first == "Title" && here->second.values.size() > 0) {	
+      title = here->second.values[0];
+    }
+
+    ++here;
+  }
+
+  // output the xml for this set; use the classifier id for the name
+  // if the title is blank
+  // curSet holds the colon-separated sequence of parent sets of the current set
+  text_t curSet;
+  if (this->setNumber >= startSet)
+  {
+    output << "  <set>" << endl;
+    text_t oai_classifier = classifier;
+    oaiclassifier::toOAI(collection, oai_classifier);
+    output << "    <setSpec>" << oai_classifier << "</setSpec>" << endl;
+    output << "    <setName>";
+    if (!title.empty()) {
+      curSet = setHierarchy + ":" + title;
+    }
+    else {
+      curSet = classifier; // Pretty much never gets here (shouldn't, at least)
+    }
+    output << curSet;
+    output << "</setName>" << endl;
+    output << "  </set>" << endl;
+    this->setsOutput++;
+  }
+  this->setNumber++;
+
+  // get the children of this classifier and iterate them
+  get_children(classifier, collection, "", metadata, false, protocol, response, logout);
+  for (int c = 0; c < response.numDocs; ++c) {
+    text_t child = response.docInfo[c].OID;
+
+    if (child == classifier)
+      continue;
+
+    // check for non classifier items and exclude them
+    text_t childHead;
+    text_t::const_iterator start = child.begin();
+    text_t::const_iterator here  = child.begin();
+    here += 2;
+    childHead = substr(start, here);
+
+    if (childHead != "CL")
+      continue;
+
+    // Recurse for "proper" classifier children. Pass curSet, the colon-separated list of 
+    // parent sets. curSet is pass-by-value, so that as we step out of recursion we remember
+    // old set hierarchies.
+    this->recurse_content(output, protocol, collection, child, curSet, startSet);
+  }
+  
+  return;
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/listsetsaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/listsetsaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/listsetsaction.h	(revision 16571)
@@ -0,0 +1,17 @@
+#include "oaiaction.h"
+#include "resumptiontoken.h"
+
+class listsetsaction : public oaiaction
+{
+ public:
+  listsetsaction() : oaiaction("ListSets") { };
+  virtual bool validateAction(recptproto *protocol, oaiargs &params);
+  bool output_content(ostream &output, recptproto *protocol, text_tset &collections, oaiargs &params);
+ protected:
+  int  setNumber;
+  int  setsOutput;
+  ResumptionToken *replyToken;
+  bool output_content(ostream &output, recptproto *protocol, oaiargs &params);
+  void recurse_content(ostream &output, recptproto *protocol, text_t &collection, const text_t &classifier, 
+		       text_t setHierarchy, int startSet);
+};
Index: /gsdl/trunk/runtime-src/src/oaiservr/metaformat.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/metaformat.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/metaformat.cpp	(revision 16571)
@@ -0,0 +1,171 @@
+#include "metaformat.h"
+#include "gsdlunicode.h"
+#include <fstream>
+
+#include "recptprototools.h"
+
+metaformat::metaformat()
+{
+}
+
+text_t metaformat::get_mapping(const text_t &collection, const text_t &collectionField)
+{
+  if (this->oaiConfigure == NULL) {
+    return "";
+  }
+
+  return this->oaiConfigure->getMapping(collection, collectionField, this->formatPrefix());
+}
+
+void metaformat::output_item(ostream &output, outconvertclass &outconvert, 
+			     bool &headerDone, const text_t &label, 
+			     const text_tarray &values)
+{ 
+
+  if (!headerDone && (values.size() > 0)) {
+    this->output_metadata_header(output);
+    headerDone = true;
+  }
+
+  for (int item = 0; item < values.size(); ++item) {
+    if (this->oaiConfigure->getOAIVersion() >= 200) { // TODO: GRB: This code may need to be subclassed by dc for 200 and later...
+      output << outconvert << "        <" << this->formatPrefix() << ":" << label << ">" << values[item] << "</" << this->formatPrefix() << ":" << label << ">\n";
+    }
+    else {
+      output << outconvert << "        <" << label << ">" << values[item] << "</" << label << ">\n";
+    }
+  }
+}
+
+bool metaformat::scan_metadata(ostream &output, const text_t &collection, ResultDocInfo_t &docInfo,
+			       bool doOutput) 
+{ 
+  bool headerDone = false;
+  MetadataInfo_tmap::iterator here = docInfo.metadata.begin();
+  MetadataInfo_tmap::iterator end = docInfo.metadata.end();
+
+  utf8outconvertclass utf8convert; // we want to output metadata in utf8
+
+  // metaItem is used initially to identify the rfc1807 (etc) metadata items. It is 
+  // then used to hold the name of the metadata item, such as "title" or "subject".
+  text_t metaItem;
+  text_t::const_iterator start, last; // Use two iterators to go through metaItem
+  
+  while (here != end) {
+    start = last = here->first.begin();
+
+    if (here->first.size() < this->formatPrefix().size() ||
+	here->first[this->formatPrefix().size()] != '.') {
+      metaItem == "";
+    }
+    else {
+      last += this->formatPrefix().size() + 1; // Move last so that it is one place beyond where the "." should be.
+      metaItem = substr(start, last);          // Gets the substring starting at start and going up to (but
+                                               // not including) last. This should be "dc." (for example)
+    }
+
+    if (metaItem == this->formatPrefix()) {
+      metaItem = substr(last, here->first.end()); // Get the rest of the metadata tag (it's name)
+      lc(metaItem); // Convert it to lowercase for putting in the xml tags
+
+      if (doOutput) {
+	this->output_item(output, utf8convert, headerDone, metaItem, here->second.values);
+      }
+      else {
+	if (here->second.values.size() > 0) {
+	  return true;
+	}
+      }
+    }  
+    else {
+      text_t mapTo = this->get_mapping(collection, here->first);
+      if (mapTo != "") {
+	// Do we actually want to do anything here? Doesn't getting here imply that this 
+	// particular metadata is stuff we don't want?
+	if (doOutput) {
+	  this->output_item(output, utf8convert, headerDone, mapTo, here->second.values);
+	}
+	else {
+	  if (here->second.values.size() > 0) {
+	    return true;
+	  }
+	}
+      }
+    }
+
+    ++here;
+  }
+
+  if (!doOutput) {
+    return false;
+  }
+  
+  if (headerDone) {
+    this->output_metadata_footer(output);
+  }
+  
+  return headerDone;
+}
+
+
+bool metaformat::is_available(const text_t &collection, ResultDocInfo_t &docInfo)
+{ 
+  ofstream o("dummy", ios::out);
+  return this->scan_metadata(o, collection, docInfo, false);
+}
+
+bool metaformat::output_metadata(ostream &output, const text_t &collection, ResultDocInfo_t &docInfo) 
+{ 
+  return this->scan_metadata(output, collection, docInfo, true);
+}
+
+bool metaformat::output_record(ostream &output, recptproto *protocol, const text_t &collection, 
+			       const text_t &OID) 
+{
+  FilterResponse_t response;
+  text_tset        metadata;
+  ofstream         logout("oai.log", ios::app);
+
+  // get the document information
+  if (!get_info(OID, collection, "", metadata, false, protocol, response, logout)) {
+    // TODO: error, bad request
+    //   cerr << "Bad identifier or protocol " << OID << endl;
+    return false;
+  }
+
+  // check to see if it's a classifier
+  text_t childHead;
+  //  int oaiVersion = this->oaiConfigure->getOAIVersion();
+  text_t::const_iterator start = OID.begin();
+  text_t::const_iterator here  = OID.begin();
+  here += 2;
+  childHead = substr(start, here);
+
+  // if it isn't a document, kill it now
+  if (childHead == "CL") {
+    //    cerr << "Not a document" << endl;
+    return false;
+  }
+
+  // output record header
+  output << "<record>\n";
+
+  // output header part of oai response
+  output << "<header>" << endl;
+  output << "  <identifier>" << OID << "</identifier>" << endl;
+  // TODO: add modified date
+
+  output << "</header>" << endl;
+
+  // output metadata part of oai response
+  this->output_metadata(output, collection, response.docInfo[0]);
+
+  // output the description of the document
+  //  output << "<about>\n";
+  //  output << "</about>\n";
+
+  // close record
+  output << "</record>\n";
+    
+  return true;
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/metaformat.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/metaformat.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/metaformat.h	(revision 16571)
@@ -0,0 +1,56 @@
+/**
+ *  A framework class for metadata formats.
+ *
+ *  Example child classes include oaimeta and rfc8507meta
+ */
+
+#ifndef _METAFORMAT_H_
+#define _METAFORMAT_H_
+#include <stdio.h>
+
+#include "text_t.h"
+#include "comtypes.h"
+#include "recptproto.h"
+
+#include "oaiconfig.h"
+
+class metaformat
+{  
+ protected:
+  virtual void output_metadata_header(ostream &output) = 0;
+  virtual void output_item(ostream &output, outconvertclass &outconvert, bool &headerDone, const text_t &label, 
+			   const text_tarray &values);
+  virtual void output_metadata_footer(ostream &output) = 0;
+  virtual bool scan_metadata(ostream &output, const text_t &collection,  ResultDocInfo_t &docInfo, 
+			     bool doOutput);
+  oaiconfig *    oaiConfigure;
+
+ public:
+  metaformat(); // Must be given the desired oai version when created 
+  virtual const text_t formatName() = 0;
+  virtual const text_t formatPrefix() = 0;
+  virtual bool output_record(ostream &output, recptproto *protocol, const text_t &collection, 
+			     const text_t &record_OID);
+  virtual bool is_available(const text_t &collection, ResultDocInfo_t &docInfo);
+  virtual bool output_metadata(ostream &output, const text_t &collection,  ResultDocInfo_t &docInfo);
+  virtual bool output_formatdata(ostream &output) = 0;
+  void    set_configuration(oaiconfig *config) { this->oaiConfigure = config; }
+  text_t  get_mapping(const text_t &collection, const text_t &collectionField);
+
+};
+
+class metaformatptr
+{
+ public:
+  metaformat *ptr;
+
+  metaformatptr() { this->ptr = NULL; }
+  metaformat *get_class() { return this->ptr; }
+  void set_class(metaformat *ptr) { this->ptr = ptr; }
+  void set_configuration(oaiconfig *config) { this->ptr->set_configuration(config);}
+  void clear() { delete this->ptr; this->ptr = NULL; }
+};
+
+typedef	map<text_t, metaformatptr, lttext_t> metaformat_map;
+
+#endif
Index: /gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.cpp	(revision 16571)
@@ -0,0 +1,120 @@
+#include "metaformatsaction.h"
+#include "metaformat.h"
+#include "recptprototools.h"
+#include "oaitools.h"
+
+bool metaformatsaction::validateAction(recptproto *protocol, oaiargs &params)
+{ 
+  int params_size = params.getSize();
+
+  // Remove any parameters that aren't valid for this action
+  text_tmap::const_iterator param_iterator = params.begin();
+  while (param_iterator != params.end())
+  {
+    if (param_iterator->first != "verb" &&
+	param_iterator->first != "identifier")
+    {
+      params.erase(param_iterator->first);
+    }
+
+    param_iterator++;
+  }
+
+  int numArgs = 1; // the number of expected arguments
+  
+  // increase the number of expected arguments if the optional 'identifier' argument
+  // is given 
+  if (params["identifier"] != "") {
+    ++numArgs;
+  }
+
+  // If the total number of params isn't equal to the number of valid
+  // args (i.e. we have an arg but it isn't the identifier), throw an error  
+  if((params_size != numArgs)){
+    this->errorType = "badArgument";
+    return false;
+  }
+
+  // Variables to hold identifier in Greenstone format
+  text_t docID = params["identifier"]; 
+  text_t collection = "";
+
+  // The following two variables are used solely by the get_info() function call to test if
+  // the identifier supplied is an actual document. If it isn't, we need to throw an exception.
+  const text_tset metadata;
+
+  // Check for the existence, etc. of the record if an identifier is given.
+  if (docID != "") {
+    oaiclassifier::toGSDL(collection, docID);
+    
+    // Only throw an error if we're using v2.0. 
+    // v1.1 should simply return a response without a metadataFormat container. 1.1
+    // should still set the errorType so we know that the error was encountered
+
+    // the information retrieved here is retained for the output_content function below
+    if (!get_info(docID, collection, "", metadata, false, protocol, this->gsdlResponse, cerr)){
+      this->errorType = "idDoesNotExist";
+      if(this->configuration->getOAIVersion() >= 200) {
+	return false;
+      }
+    }
+  }
+  return true;
+}
+
+bool metaformatsaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
+{
+  // if an identifier parameter is being used, then respond to it - currently we reject anything other
+  // than dublin core (unqualified)
+  //
+  // TODO: only return the selected identifier (if given) and don't validate the entry; just
+  //       return nothing if an invalid or unknown metadata format is given
+  
+  // give the required xml response
+
+  text_t gsdlId = params["identifier"];
+  text_t gsdlCollect;
+
+  // convert record identifier into GSDL format from OAI
+  if (gsdlId != "") {
+    oaiclassifier::toGSDL(gsdlCollect, gsdlId);
+  }
+  
+  metaformat_map::iterator here = this->formats->begin();
+  metaformat_map::iterator end  = this->formats->end();
+
+  // v1.1 should check that the id - if supplied - didn't cause an error. If it did,
+  // don't output the metadataFormat tags. OAI v2.0 should already have bailed.
+  if(this->errorType != "idDoesNotExist"){
+    while (here != end) { // Loop through the repository's supported metadata formats
+      bool doOutput = true;
+      
+      // if we were given an identifier, then check if it supports the metadata format in question
+      if (gsdlId != "") {
+	doOutput = here->second.get_class()->is_available(gsdlCollect, this->gsdlResponse.docInfo[0]);
+      }
+
+      if (doOutput) {
+	output << "  <metadataFormat>" << endl;
+	here->second.get_class()->output_formatdata(output);
+	output << "  </metadataFormat>\n";
+      }
+      ++here;
+    }
+  }
+
+  return true;
+}
+
+void metaformatsaction::setConfiguration(oaiconfig *configuration)
+{
+  this->configuration = configuration;
+
+  metaformat_map::iterator here = this->formats->begin();
+  metaformat_map::iterator end  = this->formats->end();
+  while (here != end) {    
+    here->second.set_configuration((oaiconfig *) configuration);
+    ++here;
+  }
+}
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.h	(revision 16571)
@@ -0,0 +1,15 @@
+#include "oaiaction.h"
+#include "metaformat.h"
+
+class metaformatsaction : public oaiaction
+{
+ public:
+  metaformatsaction() : oaiaction("ListMetadataFormats") { };
+  void set_formats(metaformat_map *formats) { this->formats = formats; }
+  virtual void setConfiguration(oaiconfig *configuration);
+  virtual bool validateAction(recptproto *protocol, oaiargs &params);
+ protected:
+  metaformat_map * formats;
+  FilterResponse_t gsdlResponse;
+  bool output_content(ostream &output, recptproto *protocol, oaiargs &params);
+};
Index: /gsdl/trunk/runtime-src/src/oaiservr/metaformatters.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/metaformatters.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/metaformatters.cpp	(revision 16571)
@@ -0,0 +1,36 @@
+#include "metaformatters.h"
+
+#include "dublincore.h"
+
+metaformatters::metaformatters() {
+  this->addFormat(new dublin_core);
+}
+
+/**
+ * Destructor code for the metaformatters class
+ */
+metaformatters::~metaformatters() {
+  vector<metaformat *>::iterator here = this->formatters.begin();
+  vector<metaformat *>::iterator end = this->formatters.end();
+  
+  // destroy the formatters themselves
+  while (here != end)
+    {
+      delete here->second;
+      ++here;
+    }
+}
+
+bool metaformatters::output_record(ostream &output, recptproto *protocol, text_t & collection, text_t &record_OID, text_t &format) {
+  
+}
+
+metaformat *metaformatters::getFormat(text_t &name)
+{
+  return this->formatters[name];
+}
+
+void metaformatters::addFormat(metaformat *formatter)
+{
+  this->formatters.push_back(formatter->getName(), formatter);
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/metaformatters.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/metaformatters.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/metaformatters.h	(revision 16571)
@@ -0,0 +1,14 @@
+#include "metaformat.h"
+
+#include <map>
+
+class metaformatters {
+ public:
+  metaformatters();
+  ~metaformatters();
+  bool output_record(ostream &output, recptproto *protocol, text_t &collection, text_t &record_OID, text_t formatName);
+ protected:
+  map<text_t, metaformat *> formatters;
+  addFormat(metaformat *formatter);
+  metaformat *getFormat(text_t &formatName);
+};
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaiaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaiaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaiaction.cpp	(revision 16571)
@@ -0,0 +1,466 @@
+#include "oaiaction.h"
+#include "oaitools.h"
+#include "recptprototools.h"
+
+#include <string>
+#if defined(GSDL_USE_IOS_H)
+#  if defined(__WIN32__)
+#    include <strstrea.h> // vc4
+#  else
+#    include <strstream.h>
+#  endif
+#else
+#  include <sstream>
+#endif
+
+#include <time.h>
+
+oaiaction::oaiaction(const text_t &name)
+{
+  this->logout = new ofstream("oai.log", ios::app);
+  this->configuration = NULL;
+  this->name = name;
+}
+
+//----------------------------------------------------------------------------------------------
+
+// Over-ridden by child classes
+bool oaiaction::validateAction(recptproto *protocol, oaiargs &params)
+{ 
+  this->errorType = ""; 
+  return true;
+}
+
+//----------------------------------------------------------------------------------------------
+
+/**********
+ * Compare the supplied metadataPrefix to all those that
+ * are supported. If there is NO match, return true. If 
+ * it DOES match one, return false.
+ */
+bool oaiaction::formatNotSupported(text_t &metaFormat)
+{
+  if (metaFormat == "oai_dc") return false;
+  else if (metaFormat == "rfc1807") return false;
+
+  return true;
+}
+
+//----------------------------------------------------------------------------------------------
+
+/**********
+ * Function for outputting the appropriate error(s) with the (version 2.0) request.
+ * The error(s) MUST be included in the response, and take the form:
+ * <error code="errorType">Description of error</error>
+ */
+void oaiaction::output_error(ostream &output, text_t &errorType)
+{
+  text_t description = "";
+
+  if(errorType == "badArgument"){
+    description = "The request includes illegal arguments, is missing required arguments, repeats arguments or the value for an argument has an illegal syntax";
+  }
+  else if(errorType == "noRecordsMatch"){
+    description = "No record matches all the requested parameters";
+  }
+  else if(errorType == "cannotDisseminateFormat"){
+    description = "The metadata format specified is not supported by the item or by the repository";
+  }
+  else if(errorType == "idDoesNotExist"){
+    description = "The value of the identifier is unknown or illegal in this repository";
+  }
+  else if(errorType == "badVerb"){
+    description = "Value of the verb argument is illegal, missing, or repeated";
+  }
+  else if(errorType == "noMetadataFormats"){
+    description = "There are no metadata formats available for the item";
+  }
+  else if(errorType == "badResumptionToken"){
+    description = "The value of the resumptionToken argument is invalid or expired";
+  }
+  else if(errorType == "noSetHierarchy"){
+    description = "The repository does not support sets";
+  }
+
+  output << "  <error code=\"" << errorType << "\">" << description << "</error>\n";
+}
+
+//----------------------------------------------------------------------------------------------
+
+text_t oaiaction::getName()
+{
+  return this->name;
+}
+
+//----------------------------------------------------------------------------------------------
+
+/**********
+ * Used in version 2.0 to provide the <datestamp> tag for each document. The function is passed
+ * the 'last modified' date of the file in epoch time (time in seconds since 1970-01-01 on Unix 
+ * systems) and converts it to YYYY-MM-DD format. 
+ */
+text_t oaiaction::parseDatestamp(time_t &rawtime)
+{
+  text_t year, month, day, lastModified;
+  tm *ptm;
+  ptm = gmtime(&rawtime);
+  int raw_month = ptm->tm_mon + 1;
+  int raw_day = ptm->tm_mday;
+
+  year = (ptm->tm_year + 1900); // Takes off 1900 for year by default, so replace it to get YYYY format
+
+  // Need the month in MM format, so if month is 1..9, add a 0 to the front
+  if(raw_month < 10){    
+    month = "0";
+    month += raw_month;
+  }
+  else month = raw_month;
+
+  if(raw_day < 10){    
+    day  = "0";
+    day += raw_day;
+  }
+  else day = raw_day;
+  
+  lastModified = year + "-" + month + "-" + day;
+
+  return lastModified;
+}
+
+//----------------------------------------------------------------------------------------------
+/**********
+ * Used by both versions to get the date & time of the client's request. The <responseDate> tag is
+ * in the format YYYY-MM-DDTHH:MM:SSZ, where T is simply the letter 'T' and Z is the local offset from
+ * GMT (now UTC). Examples of Z are +12:00 (NZ) or -03:00 for version 1.1. In version 2.0, the time
+ * is expected to be in UTC, and Z should simply be the character 'Z'.
+ */
+void oaiaction::getResponseDate(text_t &date)
+{
+  time_t rawtime;
+  tm    *ptm;
+
+  time(&rawtime);         // Get the epoch time
+
+  ptm = gmtime(&rawtime); // Convert to UTC-time formatted tm object
+
+  text_t month, day, hour, minute, second;
+  int    raw_month  = ptm->tm_mon + 1;  // Note Jan = 0 ... Dec = 11, so add 1
+  int    raw_day    = ptm->tm_mday;
+  int    raw_hour   = ptm->tm_hour;
+  int    raw_minute = ptm->tm_min;
+  int    raw_second = ptm->tm_sec;
+
+  // Need the month in MM format, so if month is 1..9, add a 0 to the front
+  if(raw_month < 10){    
+    month = "0";
+  }
+  month += raw_month;
+  
+  // Same for days, hours, minutes and seconds
+  if(raw_day < 10){    
+    day = "0";
+  }
+  day += raw_day;
+
+  if(raw_hour < 10){    
+    hour = "0";
+  }
+  hour += raw_hour;
+
+  if(raw_minute < 10){    
+    minute = "0";
+  }
+  minute += raw_minute;
+  
+  if(raw_second < 10){    
+    second = "0";
+  }
+  second += raw_second;
+ 
+  // Want YYYY-MM-DDTHH:MM:SS+UTC, where UTC is num hours from UTC(GMT) to localtime
+  date += (ptm->tm_year + 1900); // Takes off 1900 for year, so replace it to get YYYY format
+  date += "-";
+  date += month;
+  date += "-";
+  date += day;
+  date += "T";
+  date += hour;
+  date += ":";
+  date += minute;
+  date += ":";
+  date += second;
+  // If we're using v1.1, then tack on local time offset, otherwise don't
+  if(this->configuration->getOAIVersion() == 110){
+    date += _LOCALTIME_; // Defined in oaiaction.h. States how many hours localtime is from 
+                         // UTC (GMT), e.g. "+8:00", "-5:00"
+  }
+  else
+    date += "Z";         // If v2.0, we put 'Z' on the end rather than the localtime offset
+}
+
+//----------------------------------------------------------------------------------------------
+/**********
+ * Does different request tags depending on the version of the OAI protocol running
+ */
+void oaiaction::getRequestURL(oaiargs &params, text_t &requestURL)
+{
+  // Iterators for moving through the list of parameters (keys) specified
+  text_tmap::const_iterator here;
+  text_tmap::const_iterator end;
+  int numArgs = params.getSize();
+
+  here = params.begin();
+  end  = params.end();
+  
+  text_t baseURL = this->configuration->getCollectionConfig("", "baseURL");
+
+  int version = this->configuration->getOAIVersion();
+  
+  switch(version){
+  case 110:
+    /* Takes the form:
+     * <requestURL>http://baseURL.com/oaimain?verb="someVerb"&amp;key=value</requestURL>
+     */
+    requestURL = "  <requestURL>" + baseURL;
+    
+    if(numArgs == 0) break; // If no args, all done - the error will be picked up later 
+    
+    // The following lines will give us the "label=value" syntax
+    requestURL += "?";
+    requestURL += here->first;
+    requestURL += "=";
+    requestURL += html_safe(here->second); // parse the argument to ensure it is URL-encoding compliant
+    ++here;
+    
+    while(here != end){
+      requestURL +="&amp;"; // Stick in the ampersand in URL encoding
+      requestURL += (here->first + "=" + html_safe(here->second));
+      ++here;
+    }
+    requestURL += "</requestURL>\n";
+    break;
+  
+  case 200:
+  default:
+    /* Takes the form:
+     * <request verb="someVerb" key="value" key="value">
+     *          http://baseURL.com/oaimain</request>
+     */
+    if(numArgs == 0) {
+      requestURL = "  <request>" + baseURL + "</request>\n";
+      break;
+    }
+    requestURL = "  <request " + here->first + "=\"" + html_safe(here->second) + "\"";
+    ++here;
+    while(here != end){
+      requestURL += (" " + here->first + "=\"" + html_safe(here->second) + "\"");      
+      ++here;
+    }
+    requestURL += ">\n           " + baseURL + "</request>\n";
+    break;
+  }
+}
+
+//----------------------------------------------------------------------------------------------
+/**********
+ * Send the (OAI version-dependent) response text to the output stream
+ */
+void oaiaction::getResponse(ostream &output, recptproto *protocol, oaiargs &params)
+{
+  bool   error;
+  text_t date, requestURL;
+
+  // Write the response date & time into 'date'
+  this->getResponseDate(date);
+  int version = this->configuration->getOAIVersion();
+
+  // validate the action
+  error = !this->validateAction(protocol, params);
+
+  // raise an error for duplicated arguments and set the
+  // error type "manually" here...
+  if (params.hasDuplicateArg() && !error) {
+    this->errorType = "badArgument";
+    error = true;
+  }
+
+  // start with the required http header
+  if (version <= 110 && error){
+    output << "Status: 400 " << this->errorType << "\n";
+    output << "Content-Type: text/xml\n\n";
+    return;
+  }
+  
+  output << "Status: 200\n";
+  output << "Content-Type: text/xml\n\n";
+  
+  // output xml header parts
+  output << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
+
+  if(version <= 110){
+    // output OAI v1.1 action header tag
+    output << "<" << this->name;
+    output << "\n       xmlns=\"http://www.openarchives.org/OAI/1.1/OAI_" << this->name << "\" ";
+    output << "\n       xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
+    output << "\n       xsi:schemaLocation=\"http://www.openarchives.org/OAI/1.1/OAI_" << this->name;
+    output << "\n           http://www.openarchives.org/OAI/1.1/OAI_" << this->name << ".xsd\">\n";
+  }
+  else { 
+    // output OAI v2.0 action header tag
+    output << "<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\"\n"
+	   << "         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+	   << "         xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/\n"
+	   << "             http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">\n";
+  }
+  // output current time for response
+  output << "  <responseDate>" << date << "</responseDate>\n";
+ 
+  // output request URL. This differs depending on the OAI protocol version currently running, so
+  // the entire field - including tags - must be put into the text_t variable by getRequestURL()
+  this->getRequestURL(params, requestURL);
+
+  output << requestURL ;
+
+  if (error == false) {
+    // a string stream to write the content of the action to; this is done so that we can
+    // avoid outputting the action tag if the action's body is unsuccessful, in which
+    // case the leading tag must be suppressed
+#if defined(GSDL_USE_IOS_H)
+    ostrstream outstream;
+#else
+    ostringstream outstream;
+#endif
+
+    // Version 2.0 needs an <Identify>, etc. tag after the OAI-PMH header, IF there is no error
+    //
+    // An action that outputs no content should raise an error state to suppress the 
+    // matching opening and close tags if it outputs no content in OAI 2.0
+    error = !this->output_content(outstream, protocol, params);
+
+    // output the leading tag if no error occurred
+    if (error == false) {
+      if (version >= 200) {
+	this->output_action_tag(output, true);
+      }
+    }
+
+    // now output the body of the action content
+#if defined(GSDL_USE_IOS_H)
+    outstream << ends;  // Ensure outstream is null-terminated correctly
+#endif
+    output << outstream.str();
+  }
+  else {
+    if (version >= 200) {
+      this->output_error(output, this->errorType);
+    }
+  }
+
+  // close out our response - both versions need this line, but v2.0 only needs it if there was no error
+  if((version == 110) || (version >= 200 && error == false)){
+    this->output_action_tag(output, false);
+  }
+  if(version >= 200){
+    output << "</OAI-PMH>\n";
+  }
+}
+
+void oaiaction::output_action_tag(ostream &output, bool openTag)
+{
+  output << " <";
+  if (!openTag) {
+    output << "/";
+  }
+  output << this->name << ">" << endl;
+}
+
+void oaiaction::output_record_header(ostream &output, const text_t &oaiLabel, const text_t &lastModified, 
+				     const text_tarray &memberOf, int oaiVersion)
+{
+    output << "    <header>" << endl;
+    output << "      <identifier>" << oaiLabel     << "</identifier>" << endl;
+    output << "      <datestamp>"  << lastModified << "</datestamp>" << endl;
+    
+    // copy the collection name off the front of oaiLabel
+    text_t::const_iterator colon = findchar(oaiLabel.begin(), oaiLabel.end(), ':');
+    text_t collection = substr(oaiLabel.begin(), colon);
+    
+    if(oaiVersion >= 200){
+      text_tarray::const_iterator member = memberOf.begin();
+      text_tarray::const_iterator memEnd = memberOf.end();
+
+      // As well as all the subsets that a doc appears in, it is also a member of the 'collection' set
+      output << "      <setSpec>" << collection << "</setSpec>" << endl;
+      while (member != memEnd) {
+	text_t oaiSet = *member;
+	oaiclassifier::toOAI(collection, oaiSet);
+	output << "      <setSpec>" << oaiSet << "</setSpec>" << endl;
+	++member;
+      }
+    }
+    output << "    </header>" << endl;
+}
+
+void oaiaction::getLastModifiedDate(ResultDocInfo_t &doc_info, text_t &lastModified)
+{
+  text_t temp;
+
+  
+  MetadataInfo_tmap::iterator current = doc_info.metadata.begin();
+  MetadataInfo_tmap::iterator end = doc_info.metadata.end();
+
+  while(current != end){
+    temp = current->first;
+    lc(temp);
+    if(temp == "dc.date"){
+      lastModified = current->second.values[0];
+      return;
+    }
+    else{ 
+      if (temp == "lastmodified" && lastModified == "" && current->second.values.size() >= 1) {
+	lastModified = current->second.values[0];
+	time_t raw_time = (time_t)lastModified.getint();
+	lastModified = this->parseDatestamp(raw_time);
+	return;
+      }
+    }
+    ++current;
+  }  
+}
+
+bool oaiaction::inDateRange(const text_t &from, const text_t &until, const text_t &collection, 
+			    const text_t &OID, recptproto *protocol, ostream &logout)
+{
+  FilterResponse_t response;
+  text_tset        metadata;
+  bool status_ok = get_info(OID, collection, "", metadata, false, protocol, response, logout);
+  bool not_too_early = false, not_too_recent = false;
+
+  if(status_ok) {
+    ResultDocInfo_t doc_info = response.docInfo[0];
+    text_t lastModDate;
+    this->getLastModifiedDate(doc_info, lastModDate);
+    
+    // All date fields should be in the form YYYY-MM-DD, which allows for a direct comparison
+    if(from != ""){
+      if(from <= lastModDate)
+	not_too_early = true;
+    }
+    else 
+      not_too_early = true; // If there's no FROM field, then the record can't be too early
+
+    if(until != ""){
+      if(lastModDate <= until)
+	not_too_recent = true;
+    }
+    else 
+      not_too_recent = true; // If there's no UNTIL field, then the record can't be too recent    
+    
+    if(not_too_early && not_too_recent)
+      return true;
+    else
+      return false;
+  }
+  else
+    return false;
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaiaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaiaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaiaction.h	(revision 16571)
@@ -0,0 +1,64 @@
+#ifndef _oaiaction_h_
+#define _oaiaction_h_
+// standard c++ includes
+//#include <ostream.h>
+
+// generic gsdl stuff
+#include "text_t.h"
+#include "htmlutils.h" // For converting characters in a string to URL encoding. 
+
+// connection to a receptionist
+#include "receptionist.h"
+
+// oaistuff
+#include "oaiargs.h"
+#include "oaiconfig.h"
+#include <time.h>
+
+// Define hours & mins that separate local time from UTC (GMT) time; +ve is ahead of UTC, -ve behind
+#define _LOCALTIME_ "+12:00"
+
+class oaiaction
+{
+ public:
+  oaiaction(const text_t &name);
+
+  virtual void setConfiguration(oaiconfig *config) { this->configuration = config; }
+  text_t getName();
+  text_t parseDatestamp(time_t &rawtime);// Convert date from raw time_t format to the string YYYY-MM-DD
+  void   getResponseDate(text_t &date);  // Get the response date in UTC (GMT) time, plus local offset
+  void   getRequestURL(oaiargs &params, text_t &requestURL); // Get the URL of the request
+  void   getResponse(ostream &output, recptproto *protocol, oaiargs &params);
+  void   output_action_tag(ostream &output, bool openTag);
+  void   output_record_header(ostream &output, const text_t &oaiLabel, const text_t &lastModified, 
+			      const text_tarray &memberOf, int oaiVersion);
+  void   output_error(ostream &output, text_t &errorType); // Output any error conditions
+  bool   formatNotSupported(text_t &metaFormat);           // Return true if the supplied metadataPrefix
+                                                           // format is not supported
+  void   setErrorType(text_t &err){this->errorType = err;};
+  text_t getErrorType(){return this->errorType;};
+  void   getLastModifiedDate(ResultDocInfo_t &doc_info, text_t &lastModified);
+  bool   inDateRange(const text_t &from, const text_t &until, const text_t &collection, 
+		     const text_t &OID, recptproto *protocol, ostream &logout);
+  /******
+   * The following function sets the isInnerObject flag. It is used by the nested recordaction
+   * object in the listrecs object. This flag provides a means for identifying whether the 
+   * recordaction object is acting on its own or through a listrecsaction object. This is 
+   * to allow for appropriate handling of errors regarding unsupported metadata formats. If 
+   * we are using verb=GetRecord and the supplied metadata format is not supported by this 
+   * particular item, then an error must be thrown. But if were using verb=ListRecords, we only
+   * want to exclude the item in question from the list, not throw an error.
+   */
+  void       setAsInnerObject() { this->isInnerObject = true;}
+
+ protected:
+  oaiconfig *configuration;
+  virtual    bool validateAction(recptproto *protocol, oaiargs &params); // Check that this is a valid action
+  virtual    bool output_content(ostream &output, recptproto *protocol, oaiargs &params) = 0;
+  bool       isInnerObject;
+  text_t     name;
+  text_t     errorType;
+  ostream  * logout;
+};
+#endif
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaiargs.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaiargs.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaiargs.cpp	(revision 16571)
@@ -0,0 +1,100 @@
+#include "oaiargs.h"
+#include "cgiutils.h"
+
+// read the arguments from a stream for an OAI action
+void oaiargs::readArgs(istream &in)
+{
+  unsigned char  buffer[256];
+  unsigned char *end = buffer + 256;
+  unsigned char *here = end;
+  unsigned char *start, *equals;
+
+  // if no parameters, return now.
+  if (in.eof()) {
+    cerr << "Aborting on EOF" << endl;
+    return;
+  }
+
+  // fill the buffer with the stream
+  this->fillBuffer(in, buffer, &here, end);
+
+  // start at the beginning of the buffer, read
+  // the stream until exhausted
+  here = buffer;
+  while (*here != '\0')
+  {
+    // each iteration of the outer loop reads a single argument
+
+    // we start an argument and continue until the buffer is
+    // exhausted or the next argument is found
+    start = here;
+    equals = NULL;
+    while (*here != '&' && *here != '\0') {
+      // remember where the equals sign was if necessary
+      if (equals == NULL && *here == '=') {
+	equals = here;
+      }
+
+      // move to the next character
+      ++here;
+
+      // and refill the buffer as necessary
+      if (here == end) {
+	this->fillBuffer(in, buffer, &here, end);
+      }
+    }
+    
+    // we've now got the scope of one argument, where it begins, ends
+    // and where the equals sign is; we now split it up accordingly
+    // to create the actual text_t type elements for the label and the
+    // value.
+    text_t label, value;
+    if (equals == NULL) {
+      label.setcarr((char *) start, (int) here - (int) start);
+      value = label;
+    }
+    else {
+      label.setcarr((char *) start, (int) equals - (int) start);
+      ++equals;
+      value.setcarr((char *) equals, (int) here - (int) equals);
+    }
+
+    decode_cgi_arg(value);
+    
+    // output to the screen for tracing purposes
+    // cerr << label << "?" << value << endl;
+
+    // if the argument already exists, raise an error
+    if (this->arguments.count(label) > 0) {
+      this->duplicateArg = true;
+    }
+    else {
+      // add this argument to the argument map
+      this->arguments[label] = value;
+    }
+
+    // don't choke on an argument separator; swallow it so we don't get
+    // inifinite loops above
+    if (*here == '&') {
+      ++here;
+    }
+  }
+}
+
+void oaiargs::fillBuffer(istream &in, unsigned char *buffer, unsigned char **currentPtr, unsigned char *end)
+{
+  unsigned char *fill = buffer;
+
+  // copy out the remaining buffer space
+  while (*currentPtr != end) {
+    *fill = **currentPtr;
+    *currentPtr++;
+  }
+
+  // set the buffer appropriately
+  *currentPtr = fill;
+
+  // refill the buffer
+  in.get((char *)*currentPtr, (char *)end - (char *)*currentPtr);
+}
+
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaiargs.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaiargs.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaiargs.h	(revision 16571)
@@ -0,0 +1,32 @@
+#include <map>
+
+#include "text_t.h"
+
+class oaiargs
+{
+ private:
+  text_tmap arguments;
+  text_t    dummy;
+  bool      duplicateArg;
+  // fill the input buffer to parse the arguments
+  void fillBuffer(istream &stream, unsigned char *buffer, unsigned char **currentPtr, unsigned char *end);
+ public:
+  oaiargs() { this->duplicateArg = false; }
+
+  const text_t &operator [](const text_t &label) { 
+    if (this->arguments.count(label) > 0) {
+      return this->arguments[label]; 
+    }
+    return dummy; // Dodgy, but text_t's are initialised to "", so should be fine
+  };
+
+  void erase(const text_t &label) {
+    this->arguments.erase(label);
+  }
+
+  void readArgs(istream &stream);
+  bool hasDuplicateArg() { return this->duplicateArg; }
+  int getSize(){return arguments.size();}
+  text_tmap::const_iterator begin(){return arguments.begin();};
+  text_tmap::const_iterator end(){return arguments.end();};
+};
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaiconfig.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaiconfig.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaiconfig.cpp	(revision 16571)
@@ -0,0 +1,336 @@
+#include "oaiconfig.h"
+
+#include <algorithm>
+#include <iostream>
+
+#include "fileutil.h"
+
+/**
+ *  The mapping works as follows in the collect.cfg file.
+ *
+ *  A line is in the format oaimapping <collection field> <oai field>
+ *
+ *  The map here is used to look up the "Greenstone" name which is mapped from
+ *  a given OAI field name, the reverse direction to that given in the 
+ *  Greenstone collect.cfg file.  The oairecordaction class instance which
+ *  produces output for an OAI record information request thus uses the map
+ *  to work from the field in the collection it has on hand which OAI
+ *  record name it should use instead.
+ *
+ *  An extension is to be used for this in which the OAI field name in the
+ *  collect.cfg file can be made specific for a particular record format.
+ *  This is done using the OAI field name in the format of 
+ *    <OAI format>:<OAI field name>
+ *  Thus, an rfc1807 Title field would be referred to as rfc1807:Title
+ *
+ *  A collection-level mapping is not needed - to configure the behaviour
+ *  of a collection, ensure that you place the appropriate configuration in
+ *  its etc/collect.cfg file - the oaimapping stuff IS NOT picked up from 
+ *  the central main.cfg file at the moment.
+ *
+ *  In the absence of a particular format name, the mapping is taken to be
+ *  universal.
+ */
+
+oaiconfig::oaiconfig() : configurable () {
+  this->resumptionSize = -1; // Default = do not use resumption tokens
+}
+
+oaiconfig::oaiconfig(text_t &gsdlhome, text_t &gsdlcollect) 
+{
+  // read main configuration file to get oai collections
+  text_t mainconfig = filename_cat(gsdlhome, "etc", "oai.cfg");
+  this->collection = "";
+  this->resumptionSize = -1;
+  this->read_configfile(mainconfig);
+
+  // then if we've not got a specified collection in the gsdlcollect
+  // parameter, read in all the collection's individual configurations
+  if (gsdlcollect == "") {
+    text_tarray::iterator here = this->collectList.begin();
+    text_tarray::iterator end  = this->collectList.end();
+    while (here != end) {		
+      this->configureCollection(gsdlhome, *here);
+      ++here;
+    }
+  }
+  else {
+    this->configureCollection(gsdlhome, gsdlcollect);
+  }
+}
+
+oaiconfig::~oaiconfig() 
+{
+  oaicollectmap::iterator here = this->collectMap.begin();
+  oaicollectmap::iterator end  = this->collectMap.end();
+  while (here != end) {
+    delete here->second;
+    ++here;
+  }	
+}
+
+int oaiconfig::resumeAfter()
+{ return this->resumptionSize;
+}
+
+int oaiconfig::getOAIVersion()
+{ 
+  if (this->oaiVersion == "1.1") {
+    return 110;
+  }
+  return 200; 
+}
+
+void oaiconfig::configureCollection(const text_t &gsdlhome, const text_t &gsdlcollect)
+{
+  text_t cnfgfile = filename_cat(gsdlhome, "collect", gsdlcollect, "etc", "collect.cfg");
+  this->collection = gsdlcollect;
+  this->read_configfile(cnfgfile);
+}
+
+void oaiconfig::configure (const text_t &key, const text_tarray &cfgline)
+{
+  // we've got an oai mapping item, and at least two fields
+  if (key == "oaimapping" && cfgline.size() > 1) {
+    text_t::const_iterator colonAt;
+    text_t index, name, configCollection;
+
+    // Take a default collection as being whatever the collection being configured is...
+    configCollection = this->collection;
+    
+    // get the name of the (collection) field to map; this may actually
+    // be in a colon separated format of the type 
+    // <collection name>:<field name>
+    index = cfgline[0];
+    if ((colonAt = find(index.begin(), index.end(), ':')) != index.end()) {
+      configCollection = substr(index.begin(), colonAt);
+
+      if (this->collection != "" && configCollection != this->collection) {
+	cerr << "Attempt to configure OAI mappings for " << configCollection << " in " << this->collection << endl;
+      }
+
+      colonAt += 1;
+      index = substr(colonAt, index.end());
+    }
+    
+    // the second parameter is the metadata field to map the collection
+    // field onto.  It may be provided with a metadata protocol (which
+    // will be given first and separated by a period or full stop).  In 
+    // the case of format.field name, the splitting is done here.
+    if ((colonAt = find(cfgline[1].begin(), cfgline[1].end(), '.')) != cfgline[1].end()) {
+      text_t stub = substr(cfgline[1].begin(), colonAt);
+      colonAt += 1;
+      name = substr(colonAt, cfgline[1].end());
+      index.append(":");
+      index.append(stub);
+    }
+    else {
+      name = cfgline[1];
+    }
+    
+    // now 'index' is in the form <collectionfield>:(formatname) 
+    //     'name' is simply the fieldname within the format
+    //     'configCollection' is the collection to be configured
+    
+    // now simply map the field name (index) onto the collection name (name)
+    if (this->collectMap[configCollection] == NULL) {
+      this->collectMap[configCollection] = new oaicollectconfig(configCollection);
+    }
+    this->collectMap[configCollection]->fieldMap[index] = name;
+    
+    //    cerr << "Mapping " << index << " to " << name << " in " << configCollection << endl;
+    
+    // TODO: check that the mapped field is actually in use
+  }
+  else if (key == "oaicollection" && cfgline.size() >= 1) {
+    // Configure a collection to be used as part of the OAI archive.
+    // This line should read:
+    //
+    // oaicollection <collectionname>
+    //
+    // Where <collectionname> is the name of the directory inside the
+    // gsdl/collect folder which contains the collection.
+    //
+    // To configure several collections, merely repeat this line,
+    // or alternatively use additional collection names after the
+    // first one.
+    //
+    // This configuration should only appear in main.cfg
+    //
+    if (this->collection != "") {
+      cerr << "Attempt to configure an oai collection outside of main.cfg" << endl;
+      cerr << "Configuration attempted in " << this->collection << " collection." << endl;
+      exit(1);
+    }
+    for (int c = 0; c < cfgline.size(); ++c) {
+      this->collectList.push_back(cfgline[c]);
+    }
+  }
+  else if (key == "oaiinfo" && cfgline.size() >= 1) {
+    // Get a piece of information for the oai repository information
+    // request.  The line should read:
+    //
+    // oaiinfo <information field name> <value>
+    //
+    // This configuration should only be attempted in main.cfg
+    //
+    if (this->collection != "") {
+      cerr << "Attempt to set oai information outside of main.cfg" << endl;
+      cerr << "Configuration attempted in " << this->collection << " collection." << endl;
+      exit(1);
+    }
+    
+    // if no second parameter is given, then the first parameter
+    if (cfgline.size() == 1) {
+      this->infoMap[cfgline[0]] = cfgline[0];
+    }
+    else {
+      this->infoMap[cfgline[0]] = cfgline[1];
+    }
+  }
+  else if (key == "oaiversion" && cfgline.size() >= 1) {
+    this->oaiVersion = cfgline[0];
+  }
+  else if (key == "resumeafter" && cfgline.size() >= 1) {
+    this->resumptionSize = cfgline[0].getint();
+  }
+  // get and note a maintainer item to support the Identify Verb of OAI
+  else if (key == "maintainer" && cfgline.size() >= 1) {
+    int line = 0;
+    
+    // TODO: exhaustive checks for empty or default values of maintainer
+    while (line < cfgline.size()) {
+      if (cfgline[line] != "NULL" &&
+	  cfgline[line] != "") {
+	// do something
+	break;
+      }
+      else {
+	++line;
+      }
+    }
+    
+    // Only try to set the configuration if we have a legitimate value ...
+    if (line < cfgline.size()) {
+      // ensure we have a map to write to
+      if (this->collectMap[this->collection] == NULL) {
+	this->collectMap[this->collection] = new oaicollectconfig(this->collection);
+      }
+      this->collectMap[this->collection]->maintainer = cfgline[line];
+    }
+  }
+  else if (key == "repositoryName" && cfgline.size() >= 1) {
+    int line = 0;
+    
+    // TODO: exhaustive checks for empty or default values of repositoryName
+    while (line < cfgline.size()) {
+      if (cfgline[line] != "NULL" &&
+	  cfgline[line] != "") {
+	// do something
+	break;
+      }
+      else {
+	++line;
+      }
+    }
+    
+    // Only try to set the configuration if we have a legitimate value ...
+    if (line < cfgline.size()) {
+      // ensure we have a map to write to
+      if (this->collectMap[this->collection] == NULL) {
+	this->collectMap[this->collection] = new oaicollectconfig(this->collection);
+      }
+      this->collectMap[this->collection]->repositoryName = cfgline[line];
+    }
+  }
+  else if (key == "baseURL" && cfgline.size() >= 1) {
+    int line = 0;
+    
+    while (line < cfgline.size()) {
+      if (cfgline[line] != "NULL" &&
+	  cfgline[line] != "") {
+	// do something
+	break;
+      }
+      else {
+	++line;
+      }
+    }
+    
+    // Only try to set the configuration if we have a legitimate value ...
+    if (line < cfgline.size()) {
+      // ensure we have a map to write to
+      if (this->collectMap[this->collection] == NULL) {
+	this->collectMap[this->collection] = new oaicollectconfig(this->collection);
+      }
+      this->collectMap[this->collection]->baseURL = cfgline[line];
+    }
+  }
+}
+
+/** 
+ *  TODO: store all field values in a map per collection
+ */
+text_t oaiconfig::getCollectionConfig(const text_t &collection, const text_t &field)
+{
+  if (this->collectMap[collection] == NULL) {
+    return "";
+  }
+  if (field == "maintainer") {
+    return this->collectMap[collection]->maintainer;
+  }
+
+  if (field == "repositoryName") {
+    return this->collectMap[collection]->repositoryName;
+  }
+
+  if (field == "baseURL") {
+    return this->collectMap[collection]->baseURL;
+  }
+
+  return "";
+}
+
+text_t oaiconfig::getMapping(const text_t &collection, const text_t &collectfield)
+{
+  if (this->collectMap[collection] == NULL) {
+    return "";
+  }
+  return this->collectMap[collection]->fieldMap[collectfield];
+}
+
+/**
+ *  Get the mapping for a field in a given collection; if no mapping
+ *  exists, the result will be a blank string.
+ */
+text_t oaiconfig::getMapping(const text_t &collection, const text_t &collectfield, const text_t &formatname)
+{
+  text_t fullName = collectfield;
+  fullName.append(":");
+  fullName.append(formatname);
+
+  // try the collection-specific options first
+  if (this->collectMap[collection] != NULL) {
+    // first try the most specific item - this collection, and given that protocol
+    if (this->collectMap[collection]->fieldMap.count(fullName) >= 1) {
+      return this->collectMap[collection]->fieldMap[fullName];
+    }
+    // otherwise, fall back to this collection, and all protocols
+    else if (this->collectMap[collection]->fieldMap.count(collectfield) >= 1) {
+      return this->collectMap[collection]->fieldMap[collectfield];
+    }
+  }
+
+  // if no mappings exist, return an empty item
+  if (this->collectMap[""] == NULL) {
+    return "";
+  }
+
+  // then try generic rules
+  if (this->collectMap[""]->fieldMap.count(fullName) >= 1) {
+    return this->collectMap[""]->fieldMap[fullName];
+  }
+  else {
+    return this->collectMap[""]->fieldMap[collectfield];
+  }
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaiconfig.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaiconfig.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaiconfig.h	(revision 16571)
@@ -0,0 +1,48 @@
+#ifndef _OAICONFIG_H_
+#define _OAICONFIG_H_
+
+#include "cnfgable.h"
+
+#include <map>
+
+// TODO: sort out the members of oaicollectconfig as private/public and add
+//       corresponding set/get functions
+
+class oaicollectconfig {
+ public:
+  oaicollectconfig(const text_t &collectname) { this->collection = collectname; }
+  text_t    collection;
+  text_t    maintainer;
+  text_t    repositoryName;
+  text_t    baseURL;
+  text_tmap fieldMap;    // maps from OAI name to GSDL name
+};
+
+typedef map<text_t, oaicollectconfig *, lttext_t> oaicollectmap;
+
+class oaiconfig : configurable {
+ public:
+  oaiconfig();
+  oaiconfig(text_t &gsdlhome, text_t &gsdlcollect);
+  ~oaiconfig();
+  virtual void  configure(const text_t &key, const text_tarray &cfgline);
+  text_t        getCollectionConfig(const text_t &collection, const text_t &field);
+  text_tarray & getCollectionsList() { return this->collectList; }
+  text_t        getMapping(const text_t &collection, const text_t &collectfield);
+  text_t        getMapping(const text_t &collection, const text_t &collectfield, const text_t &format);
+  text_tmap   * getInformation() { return &this->infoMap; }
+  int           getOAIVersion();
+  int           resumeAfter();
+ private:
+  void configureCollection(const text_t &gsdlhome, const text_t &collection);
+  
+  text_tarray collectList;  // The list of collections to be taken in hand
+  text_tmap infoMap;        // Holds the information to be given in the case
+                            // of an OAI identify request
+  oaicollectmap collectMap; // The configuration of collections
+  text_t collection;        // Used to track which collection is being configured
+  text_t oaiVersion;        // The version of OAI running
+  int    resumptionSize;    // The number of items to produce before spitting out a
+                            // resumptionToken
+};
+#endif
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaidispatcher.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaidispatcher.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaidispatcher.cpp	(revision 16571)
@@ -0,0 +1,80 @@
+#include "oaidispatcher.h"
+
+oaidispatcher::oaidispatcher()
+{ this->configuration = NULL;
+}
+
+oaidispatcher::~oaidispatcher()
+{
+  oaiactionmap::iterator here = this->actions.begin();
+  oaiactionmap::iterator end  = this->actions.end();
+
+  while (here != end) {
+    delete here->second;
+    ++here;
+  }
+}
+
+void oaidispatcher::addAction(oaiaction *thisAction) {
+  thisAction->setConfiguration(this->configuration);
+  this->actions[thisAction->getName()] = thisAction;
+}
+
+void oaidispatcher::doAction(ostream &output, recptproto *protocol, oaiargs &args) {
+
+  text_t verb = args["Verb"];
+  if(verb == "") verb = args["verb"];
+  
+  oaiaction *action = actions[verb];
+  
+  if (action != NULL) {
+    action->getResponse(output, protocol, args);
+  }
+  else {  
+    // If the verb isn't correct, send an error.
+    action = actions["Identify"];
+    text_t responseDate, requestURL;
+    int version = this->configuration->getOAIVersion();
+    action->getResponseDate(responseDate);
+    oaiargs emptySet;
+    action->getRequestURL(emptySet, requestURL);
+
+    // Bad verb is signified by a status 400 response for OAI 1.1
+    if (version <= 110) {
+      output << "Status: 400\n";
+    }
+    else {
+      output << "Status: 200\n";
+    }
+    output << "Content-type: text/xml" << endl << endl;
+    output << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
+    
+    if(version <= 110){
+      // output OAI v1.1 action header tag - nil, as there is no valid heeader for the action
+      /*
+	output << "<" << action->name;
+	output << "\n       xmlns=\"http://www.openarchives.org/OAI/1.1/OAI_" << action->name << "\" ";
+	output << "\n       xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
+	output << "\n       xsi:schemaLocation=\"http://www.openarchives.org/OAI/1.1/OAI_" << action->name;
+	output << "\n           http://www.openarchives.org/OAI/1.1/OAI_" << action->name << ".xsd\">\n";
+      */    
+    }
+    else { 
+      // output OAI v2.0 action header tag
+      output << "<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\"\n"
+	     << "         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+	     << "         xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/\n"
+	     << "             http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">\n"
+	     << "  <responseDate>" << responseDate << "</responseDate>\n"
+	     << requestURL 
+	     << "  <error code=\"badVerb\">Illegal OAI verb</error>\n"
+	     << "</OAI-PMH>\n";
+    }
+
+    /*
+      cout << "<title>Bad OAI request</title>" << endl;
+      cout << "<h1>Bad OAI request</h1>" << endl;
+    */
+  }
+  output.flush();
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaidispatcher.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaidispatcher.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaidispatcher.h	(revision 16571)
@@ -0,0 +1,24 @@
+#include "oaiaction.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\map>
+#elif defined(GSDL_USE_STL_H)
+#  include <map.h>
+#else
+#  include <map>
+#endif
+
+typedef map<text_t, oaiaction *, lttext_t> oaiactionmap;
+
+class oaidispatcher
+{
+ private:
+  oaiactionmap actions;
+  oaiconfig   *configuration;
+ public:
+  oaidispatcher();
+  ~oaidispatcher();
+  void setConfiguration(oaiconfig *configuration) { this->configuration = configuration; }
+  void addAction(oaiaction *thisAction);
+  void doAction(ostream &stream, recptproto *protocol, oaiargs &args);
+};
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaimain.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaimain.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaimain.cpp	(revision 16571)
@@ -0,0 +1,165 @@
+#include "oaimain.h"
+
+/**********************************************************************
+ *
+ * oaimain.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdlconf.h"
+
+#if defined(GSDL_USE_IOS_H)
+#  include <fstream.h>
+#  if defined(__WIN32__)
+#    include <strstrea.h> // vc4
+#  else
+#    include <strstream.h>
+#  endif
+#else
+#  include <fstream>
+#  include <sstream>
+#endif
+
+#include "fileutil.h"
+#include "nullproto.h"
+#include "collectset.h"
+#include "cgiargs.h"
+
+#include "identifyaction.h"
+#include "recordaction.h"
+#include "listsetsaction.h"
+#include "listrecsaction.h"
+#include "listidsaction.h"
+#include "metaformatsaction.h"
+#include "oaidispatcher.h"
+#include "oaiconfig.h"
+
+void get_cgi_args(text_t &argstring)
+{
+  // get the query string if it is not being run as a fastcgi
+  // script
+  text_t argstr = "";
+  char *aURIStr;
+  char *request_method_str = getenv("REQUEST_METHOD");
+  char *content_length_str = getenv("CONTENT_LENGTH");
+  if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
+      content_length_str != NULL)  {
+    // POST form data
+    int content_length = text_t(content_length_str).getint();
+    if (content_length > 0) {
+      char c;
+      do {
+	cin.get(c);
+	if (cin.eof()) 
+	  break;
+	argstr.push_back (c);
+	--content_length;
+      } while (content_length > 0);
+    }
+    
+  } else {
+    aURIStr = getenv("QUERY_STRING");
+    if ((request_method_str != NULL && strcmp(request_method_str, "GET") == 0)
+	|| aURIStr != NULL) {
+      // GET form data
+      if (aURIStr != NULL) 
+	argstr = aURIStr;
+    } else {
+      // debugging from command line
+      // debug = true;
+      char inStr[1024];
+      
+      cin.get(inStr, 1024);
+      argstr = inStr;
+    }
+  }
+  argstring = argstr;
+}
+
+
+int main(int argc, char *argv[])
+{
+  text_t        cgiargstring;
+  nullproto     nproto;
+  collectset   *cservers;
+  text_t        gsdlhome;
+  text_t        collecthome;
+  text_t        gsdlcollect = "";
+  oaiargs       args;
+  ofstream      logout("oai.log", ios::app);
+  
+  // convert cgi to oai map
+  get_cgi_args(cgiargstring);
+  
+  char *cstr = cgiargstring.getcstr();
+#if defined(GSDL_USE_IOS_H)
+  istrstream cgi_in(cstr, cgiargstring.size());
+#else
+  istringstream cgi_in(cstr);
+#endif
+
+  // parse the arguments
+  args.readArgs(cgi_in);
+
+  delete []cstr;
+  
+  cservers = new collectset(gsdlhome,collecthome);
+
+  // set up the null protocol
+  nproto.set_collectset(cservers);
+  
+  // get the oai configuration
+  oaiconfig config(gsdlhome, gsdlcollect);
+
+  // set up the dispatcher
+  oaidispatcher dispatcher;
+  dispatcher.setConfiguration(&config);
+
+  identifyaction *id   = new identifyaction;
+  recordaction   *rec  = new recordaction;
+  listsetsaction *sets = new listsetsaction;
+  listrecsaction *records = new listrecsaction;
+  records->set_recordMaker(rec);
+
+  listidsaction  *ids     = new listidsaction;
+  metaformatsaction *formats = new metaformatsaction;
+  formats->set_formats(rec->get_formats());
+
+  dispatcher.addAction(id);
+  dispatcher.addAction(rec);
+  dispatcher.addAction(sets);
+  dispatcher.addAction(records);
+  dispatcher.addAction(ids);
+  dispatcher.addAction(formats);
+
+  // deal with this request
+  comerror_t error;
+  nproto.init(error, logout);
+
+  // GRB: any checks that a collection exists would be done here
+  //      At present, I foresee no useful application of that requirement.
+
+  dispatcher.doAction(cout, &nproto, args);
+  
+  delete cservers;
+  return 0;
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaimain.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaimain.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaimain.h	(revision 16571)
@@ -0,0 +1,1 @@
+// nothing
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaitools.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaitools.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaitools.cpp	(revision 16571)
@@ -0,0 +1,82 @@
+#include "oaitools.h"
+
+#include <algorithm>
+
+#include "recptprototools.h"
+
+void oaiclassifier::swapColonsAndPeriods(text_t &classifier)
+{
+  for (int i = 1; i <= classifier.size(); ++i) {
+    if (classifier[i] == '.') {
+      classifier[i] = ':';
+    }
+    else if (classifier[i] == ':') {
+      classifier[i] = '.';
+    }
+  }
+
+}
+
+text_t oaiclassifier::getGSDL_OID(const text_t &collection, const text_t& oai_id, 
+				  recptproto *protocol, ostream &logout)
+{
+  FilterResponse_t response;
+  text_tset        metadata;
+
+  // metadata.insert("gsdl_id");
+
+  bool status_ok = get_children(oai_id, collection, "", metadata, false, protocol, response, logout);
+  text_t gsdl_id = "";
+  if (status_ok) {
+    if(response.docInfo.size() > 0){
+      gsdl_id = response.docInfo[0].OID;
+    }
+    else {
+      // Response.docInfo is empty, meaning the doc in question didn't have an oai_id number.
+      return gsdl_id; // Return the empty string to indicate this.
+    }
+  }
+
+  return gsdl_id;
+}
+
+/**
+ *  Called to convert GS classifier/document identifiers that use
+ *  a '.' to separate levels in the hierarchy into OAI identifiers
+ *  that use ':' instead.
+ */
+void oaiclassifier::toOAI(const text_t &collection, text_t &classifier)
+{
+  oaiclassifier::swapColonsAndPeriods(classifier);
+
+  // prepend the collection identifier to the beginning of the
+  // OAI identifier.
+  text_t tmp = collection;
+  tmp.append(":");
+  tmp.append(classifier);
+  
+  classifier = tmp;
+}
+
+/**
+ *  Called to convert OAI classifier/document identifiers that use
+ *  a ':' to separate levels in the hierarchy into GS identifiers
+ *  that use '.' instead.
+ */
+void oaiclassifier::toGSDL(text_t &collection, text_t &classifier)
+{
+  oaiclassifier::swapColonsAndPeriods(classifier);
+
+  // separate out the collection identifier that should be
+  // found at the beginning of the OAI identifier from the
+  // item identifier within the collection
+  text_t::iterator colon = find(classifier.begin(), classifier.end(), '.');
+  if (colon != classifier.end()) {
+    collection = substr(classifier.begin(), colon);
+    classifier = substr(colon + 1, classifier.end());
+  }
+  else{
+    collection = classifier;
+    classifier = "";
+  }
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/oaitools.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/oaitools.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/oaitools.h	(revision 16571)
@@ -0,0 +1,17 @@
+
+#ifndef _OAITOOLS_H_
+#define _OAITOOLS_H_
+
+#include "text_t.h"
+#include "receptionist.h"
+
+class oaiclassifier {
+ public:
+  static text_t getGSDL_OID(const text_t &collection, const text_t& oai_id, recptproto *protocol, 
+			    ostream &logout);
+  static void   toOAI(const text_t &collection, text_t &classifier);
+  static void   toGSDL(text_t &collection, text_t &classifier);
+ private:
+  static void   swapColonsAndPeriods(text_t &classifier);
+};
+#endif
Index: /gsdl/trunk/runtime-src/src/oaiservr/recordaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/recordaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/recordaction.cpp	(revision 16571)
@@ -0,0 +1,170 @@
+#include "recordaction.h"
+#include "recptprototools.h"
+#include "dublincore.h"
+#include "rfc1807.h"
+#include "oaitools.h"
+#include <time.h>
+
+
+recordaction::recordaction() : oaiaction("GetRecord") {
+  metaformatptr fptr;
+
+  fptr.set_class(new dublin_core());  
+  this->formatMap[fptr.get_class()->formatName()] = fptr;
+  
+  fptr.set_class(new rfc1807());
+  this->formatMap[fptr.get_class()->formatName()] = fptr;
+}
+
+recordaction::~recordaction() {
+  metaformat_map::iterator here = this->formatMap.begin();
+  metaformat_map::iterator end  = this->formatMap.end();
+
+  while (here != end) {
+    here->second.clear();
+    ++here;
+  }
+}
+
+
+bool recordaction::validateAction(recptproto *protocol, oaiargs &params)
+{
+  int params_size = params.getSize();
+
+  // Remove any parameters that aren't valid for this action
+  text_tmap::const_iterator param_iterator = params.begin();
+  while (param_iterator != params.end())
+  {
+    if (param_iterator->first != "verb" &&
+	param_iterator->first != "identifier" &&
+	param_iterator->first != "metadataPrefix")
+    {
+      params.erase(param_iterator->first);
+    }
+
+    param_iterator++;
+  }
+
+  text_t meta = params["metadataPrefix"];
+  text_t gsdlId = params["identifier"];
+  text_t gsdlCollect;
+  text_t language = "";
+  int oaiVersion = this->configuration->getOAIVersion();
+
+  // The identifier and metadataPrefix args MUST be supplied, and are the only 
+  // args allowed (excluding verb arg). If we don't have them, throw an error.
+  if(gsdlId == "" || meta == "" || params_size != 3){
+    this->errorType = "badArgument";
+    return false;
+  }
+
+  // Check to see if the metadataPrefix supplied is supported
+  if(this->formatNotSupported(meta)) {
+    this->errorType = "cannotDisseminateFormat";
+    if(oaiVersion == 200) 
+      return false;
+  }
+
+  // convert record identifier into GSDL format from OAI
+  oaiclassifier::toGSDL(gsdlCollect, gsdlId);
+  
+  // get the document information
+  text_tset        metadata;
+  if (!get_info(gsdlId, gsdlCollect, language, metadata, false, protocol, this->gsdlResponse, *logout)) {
+    this->errorType = "idDoesNotExist";
+    if(oaiVersion == 200) 
+      return false;
+  }
+
+  return true;
+}
+
+//
+// Output the content of a GetRecord request; in this case, the static member 
+// output_record below is used to fulfill most of the request
+//
+bool recordaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
+{
+  // validateAction will already have set up the correct response content
+  text_t gsdlId = params["identifier"];
+  text_t gsdlCollect;
+
+  // convert record identifier into GSDL format from OAI
+  oaiclassifier::toGSDL(gsdlCollect, gsdlId);
+  
+  // go direct to output_record
+  return output_record(output, gsdlCollect, gsdlId, params["metadataPrefix"]);
+}
+
+//
+// A static member that does everything the output_content method above needs,
+// but can be called when individual records are being output for another 
+// action.
+//
+bool recordaction::output_record(ostream &output, recptproto *protocol, const text_t &collection, const text_t &OID, const text_t &metadataPrefix)
+{
+  text_tset        metadata;
+  ofstream         logout("oai.log", ios::app);
+
+  // get the document information
+  if (!get_info(OID, collection, "", metadata, false, protocol, this->gsdlResponse, logout)) {
+
+    this->errorType = "idDoesNotExist";
+
+    if(this->configuration->getOAIVersion() >= 200) {
+      this->output_error(output, errorType);
+      return false;
+    }
+  }
+
+  return this->output_record(output, collection, OID, metadataPrefix);
+}  
+
+bool recordaction::output_record(ostream &output, const text_t &collection, const text_t &OID, 
+				 const text_t &metadataPrefix)
+{ int oaiVersion = this->configuration->getOAIVersion();
+
+  // check to see if it's a classifier
+  text_t childHead;
+  text_t::const_iterator start = OID.begin();
+  text_t::const_iterator here  = OID.begin();
+  here += 2;
+  childHead = substr(start, here);
+  
+  // if it isn't a document, kill it now
+  if (childHead == "CL") {
+    cerr << "Not a document" << endl;
+    return false;
+  }
+
+  ResultDocInfo_t doc_info = this->gsdlResponse.docInfo[0];
+  text_t lastModified = "";
+
+  // Fills lastModified with the date from the document in doc_info, in the format YYYY-MM-DD
+  this->getLastModifiedDate(doc_info, lastModified);
+
+  // If the ID exists, output record for oai response (OAI v1.1)
+  // OAI v2.0 will already have bailed if ID doesn't exist (yes?)
+  if (this->errorType != "idDoesNotExist") {
+    text_t oaiLabel = OID;
+    oaiclassifier::toOAI(collection, oaiLabel); // Concatenates HASH id to collection, which OAI needs
+    
+    // output a record
+    output << "  <record>\n";
+    
+    // output header part of oai response
+    this->output_record_header(output, oaiLabel, lastModified, 
+			       doc_info.metadata["memberof"].values, oaiVersion);
+    
+    if (this->errorType != "cannotDisseminateFormat"){
+      if (this->formatMap[metadataPrefix].get_class()->output_metadata(output, collection, doc_info)) {
+	//  output 'about' part of oai response - we probably won't ever use this
+	//output << "    <about>\n";
+	//output << "    </about>\n";
+      } 
+    }
+    // close record
+    output << "  </record>\n\n";
+  }
+  return true;
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/recordaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/recordaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/recordaction.h	(revision 16571)
@@ -0,0 +1,29 @@
+#ifndef _RECORDACTION_H_
+#define _RECORDACTION_H_
+#include "oaiaction.h"
+
+#include <map>
+
+#include "comtypes.h"
+
+#include "metaformat.h"
+
+class recordaction : public oaiaction
+{
+ private:
+  metaformat_map formatMap;
+  FilterResponse_t gsdlResponse;
+  
+ public:
+  recordaction();
+  ~recordaction();
+  
+  virtual bool validateAction(recptproto *protocol, oaiargs &params);
+  bool output_content(ostream &output, recptproto *protocol, oaiargs &params);
+  bool output_record(ostream &output, const text_t &collection, const text_t &OID, 
+		     const text_t &metadataPrefix);
+  bool output_record(ostream &output, recptproto *protocol, const text_t &collection, const text_t &OID, 
+		     const text_t &metadataPrefix);
+  metaformat_map *get_formats() { return &this->formatMap; }
+};
+#endif
Index: /gsdl/trunk/runtime-src/src/oaiservr/resumptiontoken.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/resumptiontoken.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/resumptiontoken.cpp	(revision 16571)
@@ -0,0 +1,157 @@
+#include "resumptiontoken.h"
+#include "oaitools.h"
+
+/**
+ *  Generate an initial resumption token from some basic details.
+ *
+ *  TODO: add optional argument to set the server name.
+ */
+ResumptionToken::ResumptionToken(const text_t &collection, const text_t &node,
+				 const text_t &buildDate)
+{ this->collection = collection;
+  this->browseNode = node;
+  this->buildDate  = buildDate;
+  this->startItem  = 0;
+}
+
+/**
+ *  Generate a resumption token from a URN-style format.
+ *
+ *  See getToken() for details of the format.
+ *
+ *  TODO: support inclusion of an optional server name.
+ */
+ResumptionToken::ResumptionToken(const text_t &URN)
+{ text_t::const_iterator first = URN.begin();
+  text_t::const_iterator last = URN.end(); 
+  text_t::const_iterator second;
+
+  this->collection = "";
+  this->browseNode = "";
+  this->startItem  = -1;
+  
+  text_t::const_iterator here = findchar(first, last, ':');
+  if (here == first) {
+    return;
+  }
+  
+  text_t oainamespace = substr(first, here);
+  if (oainamespace != "gsdloai") {
+    return;
+  }
+
+  // increment past the first colon to get the location
+  first = ++here;  
+
+  // get the collection, browseNode
+  here = findchar(first, last, ',');
+  if (here == last) {
+    return;
+  }
+
+  second = findchar(first, here,'.');
+  this->collection = substr(first, second);
+
+  //  cerr << "Collection " << this->collection << endl;
+
+  if (second != here) {
+    // get past the '.'
+    ++second;
+    this->browseNode = substr(second, here);
+  }
+  else {
+    first = here;
+  }
+  // get past the ','
+  first = ++here;
+
+  // find the second ',' to delimit the position stack
+  second = findchar(first, last, ',');
+
+  // if not found, then get build and start item
+  if (second != first) {
+    // extract list and step past it
+    text_t offsetList = substr(first, second);
+    first = ++second;
+    
+    do {
+      second = findchar(offsetList.begin(), offsetList.end(), '.');
+      if (second == offsetList.end()) 
+	break;
+      
+      // extract and push the next position
+      text_t thisPos = substr(offsetList.begin(), second);
+      this->browsePosition.push_back(thisPos.getint());
+
+      // pop the position from the list
+      offsetList = substr(++second, offsetList.end());
+    } while (true);    
+    this->browsePosition.push_back(offsetList.getint());
+  }
+  else {
+    first ++;
+  }
+
+  // now find the build date marker
+  here = findchar(first, last, '-');
+  if (here == first) {
+    this->startItem = substr(first, last).getint();
+  }
+  else {
+    this->startItem = substr(first, here).getint();
+    this->buildDate = substr(++here, last); 
+  }
+}
+
+/**
+ *  Get a resumption token in text_t format.
+ * 
+ *  Resumption tokens are in the format:
+ *
+ *    gsdloai:<serverName>:collectionname.browseNode,startItem-BuildDate
+ *
+ *  The resumption token format does not currently implement the use of
+ *  the optional <serverName> item; it is taken to default to the name of
+ *  the receiving server.
+ *
+ *  TODO: add server identity as an optional argument; also change
+ *        ResumptionToken(text_t &) accordingly.
+ */
+text_t ResumptionToken::getToken()
+{ text_t reply = "gsdloai:";
+  reply = reply + this->collection;
+  if (this->browseNode != "") {
+    reply = reply + "." + this->browseNode;
+  }
+  reply = reply + ",";
+  for (int i = 0; i < this->browsePosition.size(); i++) {
+    if (i != 0) {
+      reply.append(".");
+    }
+    reply.appendint(i);
+  }
+  reply = reply + ",";
+  reply.append(this->startItem);
+  reply = reply + "-" + buildDate;
+
+  return reply;
+}
+
+/**
+ *  Update the position of an existing resumption token
+ */
+void ResumptionToken::setPosition(const text_t &node, int startItem)
+{ this->browseNode = node;
+  this->startItem  = startItem; 
+}
+
+/**
+ *  Check if the resumption token is valid - only a very primitive
+ *  check is done here; one ought to check for an existing collection
+ *  and valid browse Node, build date and startItem
+ *
+ *  TODO: implement improved validation checking.
+ */
+bool ResumptionToken::isValid()
+{ return this->collection != "";
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/resumptiontoken.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/resumptiontoken.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/resumptiontoken.h	(revision 16571)
@@ -0,0 +1,42 @@
+#ifndef _RESUMPTIONTOKEN_H_
+#define _RESUMPTIONTOKEN_H_
+
+#include <vector>
+
+#include "text_t.h"
+
+// use the standard namespace
+#if !defined (GSDL_NAMESPACE_BROKEN)
+#if defined(GSDL_USE_OBJECTSPACE)
+using namespace ospace::std;
+#else
+using namespace std;
+#endif
+#endif
+
+class ResumptionToken
+{ private:
+  text_t  collection;
+  text_t  browseNode;
+  vector<int> browsePosition;
+  int     startItem;
+  text_t  buildDate;
+  // TODO: add a server name to the variables list; see getToken in resumptionToken.cpp
+
+ public:
+  ResumptionToken(const text_t &collection, const text_t &rootNode, const text_t &buildDate);
+  ResumptionToken(const text_t &URN);
+  text_t  getToken();
+
+  void setPosition(const text_t &node, int startItem);
+
+  text_t  getCollection() { return collection; }
+  text_t  getNode() { return browseNode; }
+  int     getPosition() { return startItem; }
+  int     getOffsetDepth() { return this->browsePosition.size(); }
+  void    setOffset(int depth, int position) { this->browsePosition[depth] = position; }
+  int getOffset(int offset) { return this->browsePosition[offset]; }
+  bool isValid();
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/oaiservr/rfc1807.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/rfc1807.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/rfc1807.cpp	(revision 16571)
@@ -0,0 +1,57 @@
+#include "rfc1807.h"
+
+const text_t rfc1807::formatName() 
+{
+  return "rfc1807";
+}
+
+const text_t rfc1807::formatPrefix() {
+  return "rfc1807";
+}
+
+bool rfc1807::output_record(ostream &output, recptproto *protocol, const text_t &collection, 
+			    const text_t &record_OID) 
+{
+  return metaformat::output_record(output, protocol, collection, record_OID);
+}
+
+void rfc1807::output_metadata_header(ostream &output)
+{
+  output << "<metadata>\n";
+  
+  if(this->oaiConfigure->getOAIVersion() <= 110){
+  // output rfc1807 wrapper for OAI v1.1
+    output << "<rfc1807 xmlns=\"http://info.internet.isi.edu:80/in-notes/rfc/files/rfc1807.txt\"" << endl;
+    output << "         xmlns:xsi=\"http://www.w3c.org/2001/XMLSchema-instance\"" << endl;
+    output << "         xsi:schemaLocation=\"http://info.internet.isi.edu:80/in-notes/rfc/files/rfc1807.txt" 
+	   << endl;
+    output << "                            http://www.openarchives.org/OAI/1.1/rfc1807.xsd\">" << endl;
+  }
+  else {
+    // TODO: output rfc1807 wrapper for OAI v2.0
+    output << "<rfc1807 xmlns=\"http://info.internet.isi.edu:80/in-notes/rfc/files/rfc1807.txt\"" << endl;
+    output << "         xmlns:xsi=\"http://www.w3c.org/2001/XMLSchema-instance\"" << endl;
+    output << "         xsi:schemaLocation=\"http://info.internet.isi.edu:80/in-notes/rfc/files/rfc1807.txt"
+	   << endl;
+    output << "                            http://www.openarchives.org/OAI/1.1/rfc1807.xsd\">" << endl;
+  } 
+}
+
+void rfc1807::output_metadata_footer(ostream &output)
+{
+  // end rfc1807 wrapper
+  output << "</rfc1807>" << endl;
+    
+  output << "</metadata>\n";
+}
+
+bool rfc1807::output_formatdata(ostream &output)
+{
+  // Both versions of the protocol use the same schema (yes?)
+  output << "    <metadataPrefix>rfc1807</metadataPrefix>" << endl;
+  output << "    <schema>http://www.openarchives.org/OAI/1.1/rfc1807.xsd</schema>" << endl;
+  // N.B.: no namespace for this format
+  output << "    <metadataNamespace></metadataNamespace>" << endl;
+
+  return true;
+}
Index: /gsdl/trunk/runtime-src/src/oaiservr/rfc1807.h
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/rfc1807.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/rfc1807.h	(revision 16571)
@@ -0,0 +1,14 @@
+#include "metaformat.h"
+
+class rfc1807 : public metaformat {
+ protected:
+  void output_metadata_header(ostream &output);
+  virtual void output_metadata_footer(ostream &output);
+ public:
+  rfc1807() : metaformat(){}; // call parent constructor
+  virtual const text_t formatName();
+  virtual const text_t formatPrefix();
+  virtual bool output_record(ostream &output, recptproto *protocol, const text_t &collection, 
+			     const text_t &record_OID);
+  virtual bool output_formatdata(ostream &output);
+};
Index: /gsdl/trunk/runtime-src/src/oaiservr/win32.mak
===================================================================
--- /gsdl/trunk/runtime-src/src/oaiservr/win32.mak	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/oaiservr/win32.mak	(revision 16571)
@@ -0,0 +1,171 @@
+###########################################################################
+#
+# win32 makefile -- src/oaiserver
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ..\..
+INDEXERS_DIR = $(GSDL_DIR)\indexers
+PACKAGES_DIR = $(GSDL_DIR)\packages
+COLSERVR_DIR = $(GSDL_DIR)\src\colservr
+PROTOCOL_DIR = $(GSDL_DIR)\src\protocol
+RECPT_DIR = $(GSDL_DIR)\src\recpt
+
+
+GSDL_VC4 = 0
+LOCAL_LIBRARY = 0
+DLL = 0
+DLLDEBUG = 0
+ENABLE_ACCENTFOLD = 1
+USE_SQLITE = 0
+
+
+!IF $(GSDL_VC4)
+CPPFLAGS = -GX
+!ELSE
+CPPFLAGS = -EHsc
+!ENDIF
+
+!IF $(DLL)
+CPPFLAGS = $(CPPFLAGS) -MD
+!ELSE
+!IF ($(DLLDEBUG))
+CPPFLAGS = $(CPPFLAGS) -MDd
+!ENDIF
+!ENDIF
+
+!IF $(ENABLE_ACCENTFOLD)
+ACCENTFOLD_LIBS = "$(INDEXERS_DIR)\packages\unac\libunac.lib" "$(INDEXERS_DIR)\packages\unac\iconv.lib"
+!ELSE
+ACCENTFOLD_LIBS = 
+!ENDIF
+
+!IF $(USE_SQLITE)
+SQLITE_LIBS = "$(PACKAGES_DIR)\sqlite\lib\sqlite3.lib"
+!ELSE
+SQLITE_LIBS = 
+!ENDIF
+
+
+AR = lib
+CC = cl
+DEFS = -D__WIN32__ -DHAVE_CONFIG_H -DPARADOCNUM -D_LITTLE_ENDIAN -DSHORT_SUFFIX -D_CRT_SECURE_NO_DEPRECATE \
+        -DGSDL_NOCACHE
+INCLUDES = -I"$(GSDL_DIR)\src\lib" -I"$(COLSERVR_DIR)" -I"$(PROTOCOL_DIR)" -I"$(RECPT_DIR)" \
+        -I"$(INDEXERS_DIR)\mgpp\text" -I"$(PACKAGES_DIR)\windows\crypt\crypt" \
+	-I"$(PACKAGES_DIR)\windows\expat\expat" -I"$(PACKAGES_DIR)\windows\gdbm\gdbm"
+LDFLAGS = 
+LIBS = "$(PACKAGES_DIR)\windows\crypt\crypt\crypt.lib" "$(PACKAGES_DIR)\windows\expat\expat\libexpat.lib" \
+        "$(PACKAGES_DIR)\windows\gdbm\gdbm\gdbm.lib" $(ACCENTFOLD_LIBS) $(SQLITE_LIBS)
+
+!IF $(GSDL_VC4)
+DEFS = $(DEFS) -DGSDL_NAMESPACE_BROKEN -DGSDL_USE_IOS_H -D__STL_NO_NEW_IOSTREAMS
+INCLUDES = $(INCLUDES) -I"$(PACKAGES_DIR)\windows\stlport\stlport"
+!ENDIF
+!IF $(LOCAL_LIBRARY)
+DEFS = $(DEFS) -DGSDL_LOCAL_LIBRARY
+!ENDIF
+
+
+COMPILE = $(CC) -nologo -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+LINK = $(CC) -nologo -Fe"$@" 
+
+
+.SUFFIXES:
+.SUFFIXES: .cpp .obj
+.cpp.obj:
+	$(COMPILE) $< 
+
+
+RECPT_OBJECTS = \
+	"$(RECPT_DIR)\cgiargs.obj" \
+	"$(RECPT_DIR)\cgiutils.obj" \
+	"$(RECPT_DIR)\htmlutils.obj"
+
+SOURCES = \
+	abstractlistaction.cpp \
+	dublincore.cpp \
+	identifyaction.cpp \
+	listidsaction.cpp \
+	listrecsaction.cpp \
+	listsetsaction.cpp \
+	metaformat.cpp \
+	metaformatsaction.cpp \
+	oaiaction.cpp \
+	oaiargs.cpp \
+	oaiconfig.cpp \
+	oaidispatcher.cpp \
+	oaimain.cpp \
+	oaitools.cpp \
+	recordaction.cpp \
+	resumptiontoken.cpp \
+	rfc1807.cpp
+
+OBJECTS = \
+	abstractlistaction.obj \
+	dublincore.obj \
+	identifyaction.obj \
+	listidsaction.obj \
+	listrecsaction.obj \
+	listsetsaction.obj \
+	metaformat.obj \
+	metaformatsaction.obj \
+	oaiaction.obj \
+	oaiargs.obj \
+	oaiconfig.obj \
+	oaidispatcher.obj \
+	oaimain.obj \
+	oaitools.obj \
+	recordaction.obj \
+	resumptiontoken.obj \
+	rfc1807.obj
+
+GSDL_LIBS = \
+	"$(PROTOCOL_DIR)\gsdlprotocol.lib" \
+	"$(COLSERVR_DIR)\gsdlcolservr.lib" \
+	"$(INDEXERS_DIR)\mg\src\text\libmgtext.lib" \
+	"$(INDEXERS_DIR)\mg\lib\libmglib.lib" \
+	"$(INDEXERS_DIR)\mgpp\text\libmgpptext.lib" \
+	"$(INDEXERS_DIR)\mgpp\lib\libmgpplib.lib" \
+	"$(GSDL_DIR)\src\lib\gsdllib.lib"
+
+EXECUTABLE_OBJECTS = \
+	$(OBJECTS) \
+	$(RECPT_OBJECTS) \
+	$(GSDL_LIBS)
+
+EXECUTABLE = oaiserver.exe
+
+
+# Default target: make the oaiserver executable
+all: $(EXECUTABLE)
+
+oaiserver.exe: $(EXECUTABLE_OBJECTS)
+	$(LINK) $(EXECUTABLE_OBJECTS) $(LIBS)
+
+install: $(EXECUTABLE)
+	copy $(EXECUTABLE) "$(GSDL_DIR)\cgi-bin"
+
+clean:
+	del *.obj
+	del $(EXECUTABLE)
Index: /gsdl/trunk/runtime-src/src/protocol/Makefile.in
===================================================================
--- /gsdl/trunk/runtime-src/src/protocol/Makefile.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/protocol/Makefile.in	(revision 16571)
@@ -0,0 +1,83 @@
+###########################################################################
+#
+# Makefile -- src/protocol
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ../../..
+COMMON_DIR = $(GSDL_DIR)/gs2common
+
+INDEXERS_DIR = $(COMMON_DIR)/indexers
+PACKAGES_DIR = $(GSDL_DIR)/gs2runtime/packages
+COLSERVR_DIR = $(GSDL_DIR)/gs2runtime/src/colservr
+
+
+AR = ar
+CXX = @CXX@
+CXXFLAGS = @CXXFLAGS@ @COMPAT32BITFLAGS@
+DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DGSDLSERVER
+# Do NOT add the "recpt" directory here: the protocol should be independent of the receptionist!
+INCLUDES = @GDBM_INCLUDE@ -I. -I$(GSDL_DIR) -I$(COMMON_DIR)/src/lib -I$(COLSERVR_DIR) -I$(INDEXERS_DIR)/mgpp/text
+RANLIB = @RANLIB@
+
+
+CXXCOMPILE = $(CXX) -c $(CXXFLAGS) $(DEFS) $(INCLUDES)
+
+
+.SUFFIXES:
+.SUFFIXES: .cpp .o
+.cpp.o:
+	$(CXXCOMPILE) $< 
+
+
+SOURCES = \
+	nullproto.cpp \
+	recptproto.cpp \
+	recptprototools.cpp
+
+OBJECTS = \
+	nullproto.o \
+	recptproto.o \
+	recptprototools.o
+
+LIBRARY = gsdlprotocol.a
+
+
+# Default target: make gsdlprotocol.a
+all: $(LIBRARY)
+
+gsdlprotocol.a: $(OBJECTS)
+	rm -f $(LIBRARY)
+	$(AR) cru $(LIBRARY) $(OBJECTS)
+	$(RANLIB) $(LIBRARY)
+
+install:
+
+clean:
+	rm -f $(OBJECTS) $(LIBRARY)
+
+distclean:
+	rm -f $(OBJECTS) $(LIBRARY) Makefile
+
+depend:
+	makedepend -Y -- $(DEFS) $(INCLUDES) $(CXXFLAGS) -- $(SOURCES)
Index: /gsdl/trunk/runtime-src/src/protocol/nullproto.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/protocol/nullproto.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/protocol/nullproto.cpp	(revision 16571)
@@ -0,0 +1,164 @@
+/**********************************************************************
+ *
+ * nullproto.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "nullproto.h"
+#include <assert.h>
+
+#include "filter.h"
+#include "browsefilter.h"
+#include "mgqueryfilter.h"
+#include "mgppqueryfilter.h"
+#include "mgsearch.h"
+#include "mgppsearch.h"
+#include "fileutil.h"
+
+nullproto::nullproto() {
+  cset = NULL;
+}
+
+nullproto::~nullproto() {
+}
+
+// add collection to collectset (this should not be called until after the
+// collectset has been added to the protocol with set_collectset()
+void nullproto::add_collection (const text_t &collection, void *recpt, 
+				const text_t &gsdlhome, const text_t& collecthome,
+				const text_t &dbhome) 
+{      
+  
+  if (cset != NULL) {
+    this->cset->add_collection (collection, gsdlhome, collecthome);
+  }
+}
+
+
+// remove_collection deletes the collection server of collection.
+// This only needs to be called if a collectionserver is to be
+// removed while the library is running. The destructor function
+// cleans up all collectservers when the program exits.
+void nullproto::remove_collection (const text_t &collection, ostream &logout) {
+  cset->remove_collection(collection, logout);
+}
+
+// this configure will configure each of the collection servers
+void nullproto::configure (const text_t &key, const text_tarray &cfgline,
+			   comerror_t &err) {
+  // the naming of the collection should not be done here,
+  // it should be done just after the collection server has been 
+  // created
+
+  // the protocol should not configure the collection set; it should be
+  // done direct to the collection server set
+  if (key == "gsdlhome" || key == "gdbmhome"
+      || key == "collecthome" || key == "collectdir") {
+    cset->configure(key, cfgline);
+  }
+}
+
+// this init will configure and init each of the collection servers
+bool nullproto::init (comerror_t &err, ostream &logout) {
+  return cset->init(logout);
+}
+
+text_t nullproto::get_site_name (comerror_t &err) {
+  return "localhost";
+}
+
+text_t nullproto::get_protocol_name (comerror_t &err) {
+  return "nullproto";
+}
+
+
+void nullproto::get_collection_list (text_tarray &collist, comerror_t &err, 
+				     ostream &/*logout*/) {
+  cset->getCollectionList(collist);
+  err = noError; // no error is guaranteed - collection server shouldn't
+                 // about receptionist error states, logout is irrelevant
+}
+
+void nullproto::has_collection (const text_t &collection, bool &hascollection, 
+				comerror_t &err, ostream &/*logout*/) {
+  hascollection = (cset->getCollectServer(collection) != NULL);
+  err = noError;
+}
+
+void nullproto::ping (const text_t &collection, bool &wassuccess, 
+		      comerror_t &err, ostream &logout) {
+  collectserver *cserver = cset->getCollectServer(collection);
+  if (cserver != NULL) cserver->ping(wassuccess, err, logout);
+  else err = protocolError;
+}
+
+void nullproto::get_collectinfo (const text_t &collection, 
+				 ColInfoResponse_t &collectinfo,
+				 comerror_t &err, ostream &logout) {
+  collectserver *cserver = cset->getCollectServer (collection);
+  if (cserver != NULL) cserver->get_collectinfo (collectinfo, err, logout);
+  else err = protocolError;
+}
+
+
+void nullproto::get_filterinfo (const text_t &collection,
+				InfoFiltersResponse_t &response,
+				comerror_t &err, ostream &logout) {
+  collectserver *cserver = cset->getCollectServer (collection);
+  if (cserver != NULL) cserver->get_filterinfo (response, err, logout);
+  else err = protocolError;
+}
+
+void nullproto::get_filteroptions (const text_t &collection,
+				   const InfoFilterOptionsRequest_t &request,
+				   InfoFilterOptionsResponse_t &response, 
+				   comerror_t &err, ostream &logout) {
+  collectserver *cserver = cset->getCollectServer (collection);
+  if (cserver != NULL) cserver->get_filteroptions (request, response, err, logout);
+  else err = protocolError;
+}
+
+void nullproto::filter (const text_t &collection,
+			FilterRequest_t &request,
+			FilterResponse_t &response,
+			comerror_t &err, ostream &logout) {
+  collectserver *cserver = cset->getCollectServer (collection);
+  if (cserver != NULL) cserver->filter (request, response, err, logout);
+  else err = protocolError;
+}
+
+void nullproto::get_document (const text_t &collection,
+			      const DocumentRequest_t &request,
+			      DocumentResponse_t &response,
+			      comerror_t &err, ostream &logout) {
+  collectserver *cserver = cset->getCollectServer (collection);
+  if (cserver != NULL) cserver->get_document (request, response, err, logout);
+  else err = protocolError;
+}
+
+void nullproto::is_searchable (const text_t &collection, bool &issearchable, 
+			       comerror_t &err, ostream &logout) {
+  issearchable = false;
+  collectserver *cserver = cset->getCollectServer (collection);
+  if (cserver != NULL) cserver->is_searchable (issearchable, err, logout);
+  else err = protocolError;
+}
Index: /gsdl/trunk/runtime-src/src/protocol/nullproto.h
===================================================================
--- /gsdl/trunk/runtime-src/src/protocol/nullproto.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/protocol/nullproto.h	(revision 16571)
@@ -0,0 +1,100 @@
+/**********************************************************************
+ *
+ * nullproto.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef NULLPROTO_H
+#define NULLPROTO_H
+
+#include "gsdlconf.h"
+#include "collectserver.h"
+#include "collectset.h"
+#include "recptproto.h"
+
+
+class nullproto : public recptproto {
+protected:
+  collectset           *cset;
+public:
+  nullproto();
+  virtual ~nullproto();
+
+  // add_collection sets up the collectionserver and calls
+  // add_collectserver
+  virtual void add_collection (const text_t &collection, void *recpt, 
+			       const text_t &gsdlhome, const text_t& collecthome,
+			       const text_t &dbhome);
+
+  void set_collectset(collectset *set) { this->cset = set; }
+
+  // remove_collection deletes the collection server of collection.
+  // This only needs to be called if a collectionserver is to be
+  // removed while the library is running as the destructor function
+  // cleans up all collectservers when the program exits.
+  void remove_collection (const text_t &collection, ostream &logout);
+
+  // this configure will configure each of the collection servers
+  void configure (const text_t &key, const text_tarray &cfgline,
+		  comerror_t &err);
+
+  // this init will init each of the collection servers
+  bool init (comerror_t &err, ostream &logout);
+
+  text_t get_protocol_name (comerror_t &err);
+  text_t get_site_name (comerror_t &err);
+
+  void get_collection_list (text_tarray &collist, comerror_t &err, 
+			    ostream &logout);
+  void has_collection (const text_t &collection, bool &hascollection, 
+		       comerror_t &err, ostream &logout);
+  void ping (const text_t &collection, bool &wassuccess, 
+	     comerror_t &err, ostream &logout);
+  void get_collectinfo (const text_t &collection, 
+			ColInfoResponse_t &collectinfo,
+			comerror_t &err, ostream &logout);
+  void get_filterinfo (const text_t &collection,
+		       InfoFiltersResponse_t &response,
+		       comerror_t &err, ostream &logout);
+  void get_filteroptions (const text_t &collection,
+			  const InfoFilterOptionsRequest_t &request,
+			  InfoFilterOptionsResponse_t &response, 
+			  comerror_t &err, ostream &logout);
+  void filter (const text_t &collection,
+	       FilterRequest_t &request,
+	       FilterResponse_t &response,
+	       comerror_t &err, ostream &logout);
+
+  void get_document (const text_t &collection,
+		     const DocumentRequest_t &request,
+		     DocumentResponse_t &response,
+		     comerror_t &err, ostream &logout);
+
+  void is_searchable (const text_t &collection, bool &issearchable, 
+		      comerror_t &err, ostream &logout);
+
+
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/protocol/recptproto.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/protocol/recptproto.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/protocol/recptproto.cpp	(revision 16571)
@@ -0,0 +1,176 @@
+/**********************************************************************
+ *
+ * recptproto.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "recptproto.h"
+#include <assert.h>
+
+
+// add collection server to protocol
+void recptproto::add_collection (const text_t &/*collection*/, void * /*recpt*/, 
+				 const text_t &/*gsdlhome*/, const text_t& /*collecthome */, 
+				 const text_t &/*dbhome*/) 
+{
+}
+
+void recptproto::remove_collection (const text_t &/*collection*/, ostream &/*logout*/) {
+}
+
+// configure should be called for each line in the configuration file
+void recptproto::configure (const text_t &/*key*/, const text_tarray &/*cfgline*/, comerror_t &) {
+}
+
+// init should be called after the configuration but before any other
+// functions are called. If init returns false a message will be written
+// out to the log file and no other output should be produced.
+bool recptproto::init (comerror_t &err, ostream &/*logout*/) {
+  return true;
+}
+
+// get site name should return the name of the site used.
+// This is trivially empty in the case of a null protocol.  If a remote
+// connection to a site is being used then this should return the name
+// used to label a site
+text_t recptproto::get_site_name(comerror_t &err) {
+  return "localhost";
+}
+
+// get_protocol_name should return the name of this protocol (e.g. recptproto)
+// that can be used to do run time type identification and display information
+// about the protocol.
+text_t recptproto::get_protocol_name (comerror_t &err) {
+  return "recptproto";
+}
+
+// get_collection_list returns the list of collections that
+// this protocol knows about
+void recptproto::get_collection_list (text_tarray &collist, comerror_t &err, 
+				      ostream &/*logout*/) {
+  collist.erase(collist.begin(),collist.end());
+  err = noError;
+}
+
+// has_collection sets 'hascollection' to be true if the protocol
+// can communicate with the collection (i.e. it is within its 
+// collection list). This function should be implemented in as
+// efficient time as possible as it will be called for each page
+// access and for each protocol.
+void recptproto::has_collection (const text_t &/*collection*/, bool &hascollection, 
+				 comerror_t &err, ostream &/*logout*/) {
+  hascollection = false;
+  err = noError;
+}
+
+// sets 'wassuccess' to be true if a successful ping was done to
+// the given collection.
+void recptproto::ping (const text_t &/*collection*/, bool &wassuccess, 
+		       comerror_t &err, ostream &/*logout*/) {
+  wassuccess = false; // no collections are supported by this class
+  err = noError;
+}
+
+// obtains general information about the collection
+void recptproto::get_collectinfo (const text_t &/*collection*/, 
+				  ColInfoResponse_t &/*collectinfo*/,
+				  comerror_t &err, ostream &/*logout*/) {
+  err = protocolError;
+}
+
+// gets a list of all the filters
+void recptproto::get_filterinfo (const text_t &/*collection*/,
+				 InfoFiltersResponse_t &/*reponse*/,
+				 comerror_t &err, ostream &/*logout*/) {
+  err = protocolError;
+}
+
+// gets all the filter options for a particular filter
+void recptproto::get_filteroptions (const text_t &/*collection*/,
+				    const InfoFilterOptionsRequest_t &/*request*/,
+				    InfoFilterOptionsResponse_t &/*response*/, 
+				    comerror_t &err, ostream &/*logout*/) {
+  err = protocolError;
+}
+
+// filters (search or browse) a result set
+void recptproto::filter (const text_t &/*collection*/,
+			 FilterRequest_t &/*request*/,
+			 FilterResponse_t &/*response*/,
+			 comerror_t &err, ostream &/*logout*/) {
+  err = protocolError;
+}
+
+void recptproto::get_document (const text_t &/*collection*/,
+			       const DocumentRequest_t &/*request*/,
+			       DocumentResponse_t &/*response*/,
+			       comerror_t &err, ostream &/*logout*/) {
+  err = protocolError;
+}
+
+// sets issearchable to true if the given colection is searchable
+void recptproto::is_searchable (const text_t &/*collection*/, bool &issearchable, 
+				comerror_t &err, ostream &/*logout*/) {
+  issearchable = false; // no collections are supported by this class
+  err = noError;
+}
+
+
+
+
+
+
+
+// therecptproto remains the property of the calling code but
+// should not be deleted until it is removed from this list.
+void recptprotolistclass::addrecptproto (recptproto *therecptproto) {
+  // can't add a protocol that doesn't exist
+  assert (therecptproto != NULL);
+  if (therecptproto == NULL) return;
+
+  recptprotoptr rpp;
+  rpp.p = therecptproto;
+
+  recptprotoptrs.push_back(rpp);
+}
+
+// getrecptproto will return NULL if a recptproto for the given colelction
+// could not be found
+recptproto *recptprotolistclass::getrecptproto (const text_t &collection, 
+						ostream &logout) {
+  iterator here = recptprotoptrs.begin ();
+  iterator end = recptprotoptrs.end ();
+  bool hascollection;
+  comerror_t err;
+
+  while (here != end) {
+    assert ((*here).p != NULL);
+    if ((*here).p != NULL) {
+      (*here).p->has_collection (collection, hascollection, err, logout);
+      if ((err == noError) && (hascollection == true)) return (*here).p;
+    }
+    
+    ++here;
+  }
+  
+  return NULL;
+}
Index: /gsdl/trunk/runtime-src/src/protocol/recptproto.h
===================================================================
--- /gsdl/trunk/runtime-src/src/protocol/recptproto.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/protocol/recptproto.h	(revision 16571)
@@ -0,0 +1,194 @@
+/**********************************************************************
+ *
+ * recptproto.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef RECPTPROTO_H
+#define RECPTPROTO_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "comtypes.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\vector>
+#elif defined(GSDL_USE_STL_H)
+#  include <vector.h>
+#else
+#  include <vector>
+#endif
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+#endif
+
+
+// recptproto is a generalisation of a protocol for communicating
+// with a collection server.
+class recptproto {
+public:
+
+  // add collection server to protocol
+  virtual void add_collection (const text_t &collection, void *recpt, 
+			       const text_t &gsdlhome, const text_t& collecthome,
+			       const text_t &dbhome);
+
+  virtual void remove_collection (const text_t &collection, ostream &logout);
+
+  // configure should be called for each line in the configuration file
+  virtual void configure (const text_t &key, const text_tarray &cfgline, comerror_t &err);
+
+  // init should be called after the configuration but before any other
+  // functions are called. If init returns false a message will be written
+  // out to the log file and no other output should be produced.
+  virtual bool init (comerror_t &err, ostream &logout);
+
+  // get_site_name should return the name of the site used.
+  // This is trivially empty in the case of a null protocol.  If a remote
+  // connection to a site is being used then this should return the name
+  // used to label a site
+  virtual text_t get_site_name(comerror_t &err);
+
+  // get_protocol_name should return the name of this protocol (e.g. recptproto)
+  // that can be used to do run time type identification and display information
+  // about the protocol.
+  virtual text_t get_protocol_name (comerror_t &err);
+
+  // get_collection_list returns the list of collections that
+  // this protocol knows about
+  virtual void get_collection_list (text_tarray &collist, comerror_t &err, 
+				    ostream &logout);
+
+  // has_collection sets 'hascollection' to be true if the protocol
+  // can communicate with the collection (i.e. it is within its 
+  // collection list). This function should be implemented in as
+  // efficient time as possible as it will be called for each page
+  // access and for each protocol.
+  virtual void has_collection (const text_t &collection, bool &hascollection, 
+			       comerror_t &err, ostream &logout);
+
+  // sets 'wassuccess' to be true if a successful ping was done to
+  // the given collection.
+  virtual void ping (const text_t &collection, bool &wassuccess, 
+		     comerror_t &err, ostream &logout);
+
+  // obtains general information about the collection
+  virtual void get_collectinfo (const text_t &collection, 
+				ColInfoResponse_t &collectinfo,
+				comerror_t &err, ostream &logout);
+
+  // gets a list of all the filters
+  virtual void get_filterinfo (const text_t &collection,
+			       InfoFiltersResponse_t &response,
+			       comerror_t &err, ostream &logout);
+
+  // gets all the filter options for a particular filter
+  virtual void get_filteroptions (const text_t &collection,
+				  const InfoFilterOptionsRequest_t &request,
+				  InfoFilterOptionsResponse_t &response, 
+				  comerror_t &err, ostream &logout);
+
+  // filters (search or browse) a result set and returns information
+  // about the filtered set including term frequency information and 
+  // metadata
+  virtual void filter (const text_t &collection,
+		       FilterRequest_t &request,
+		       FilterResponse_t &response,
+		       comerror_t &err, ostream &logout);
+
+  // gets a document (duh!)
+  virtual void get_document (const text_t &collection,
+			     const DocumentRequest_t &request,
+			     DocumentResponse_t &response,
+			     comerror_t &err, ostream &logout);
+
+  virtual void is_searchable (const text_t &collection, bool &issearchable, 
+			      comerror_t &err, ostream &logout);
+
+};
+
+
+// The recptprotoptr function does not 'own' the recptproto. The 
+// recptproto should be deleted by the code which created it.
+class recptprotoptr {
+public:
+  recptproto *p;
+
+  recptprotoptr () {p=NULL;}
+  ~recptprotoptr () {}
+};
+
+typedef vector<recptprotoptr> recptprotoptrlist;
+
+
+// contains a list of recptprotos
+class recptprotolistclass {
+protected:
+  recptprotoptrlist recptprotoptrs;
+
+public:
+  // type support for recptprotolistclass
+  typedef recptprotoptrlist::iterator iterator;
+  typedef recptprotoptrlist::const_iterator const_iterator;
+  typedef recptprotoptrlist::reference reference;
+  typedef recptprotoptrlist::const_reference const_reference;
+  typedef recptprotoptrlist::size_type size_type;
+
+  typedef recptprotoptrlist::difference_type difference_type;
+  typedef recptprotoptrlist::const_reverse_iterator const_reverse_iterator;
+  typedef recptprotoptrlist::reverse_iterator reverse_iterator;
+  
+  // basic container support
+  iterator begin () {return recptprotoptrs.begin();}
+  const_iterator begin () const {return recptprotoptrs.begin();}
+  iterator end () {return recptprotoptrs.end();}
+  const_iterator end () const {return recptprotoptrs.end();}
+
+  void erase(iterator pos) {recptprotoptrs.erase(pos);}
+  void erase(iterator first, iterator last) {recptprotoptrs.erase(first, last);}
+  recptprotolistclass &operator=(const recptprotolistclass &x) 
+    {recptprotoptrs=x.recptprotoptrs;return *this;}
+
+  bool empty () const {return recptprotoptrs.empty();}
+  size_type size() const {return recptprotoptrs.size();}
+
+
+  // added functionality
+  void clear () {recptprotoptrs.erase(recptprotoptrs.begin(),recptprotoptrs.end());}
+
+  // therecptproto remains the property of the calling code but
+  // should not be deleted until it is removed from this list.
+  void addrecptproto (recptproto *therecptproto);
+
+  // getrecptproto will return NULL if a recptproto for the given collection
+  // could not be found
+  recptproto *getrecptproto (const text_t &collection, ostream &logout);
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/protocol/recptprototools.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/protocol/recptprototools.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/protocol/recptprototools.cpp	(revision 16571)
@@ -0,0 +1,330 @@
+/**********************************************************************
+ *
+ * recptprototools.cpp -- 
+ * Copyright (C) 1999-2008  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "recptprototools.h"
+#include <assert.h>
+
+
+// get_info does a protocol call and returns (in response) the metadata 
+// associated with OID. Metadata should be loaded with whatever
+// metadata fields are to be requested.
+
+bool get_info (const text_t &OID, const text_t &collection, const text_t &lang,
+	       const text_tset &metadata, bool getParents,
+	       recptproto *collectproto, FilterResponse_t &response, 
+	       ostream &logout)
+{
+  response.clear();
+
+  comerror_t err = noError;
+  FilterRequest_t request;
+  request.clear();
+
+  request.filterName = "NullFilter";
+  request.filterLang = lang;
+  request.filterResultOptions = FRmetadata;
+  request.getParents = getParents;
+  request.fields = metadata;
+  request.docSet.push_back (OID);
+  assert (collectproto != NULL);
+
+  collectproto->filter (collection, request, response, err, logout);
+  if (err != noError)
+  {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii
+	   << "Error: call to filter failed for " << OID
+	   << " in recptprototools::get_info (" 
+	   << get_comerror_string (err) << ")\n";
+    return false;
+  }
+  
+  return true;
+}
+
+
+// overloaded, to allow "custom" filter options.
+bool get_info (const text_t &OID, const text_t &collection, const text_t &lang,
+	       const text_tset &metadata, const OptionValue_tarray &options,
+	       bool getParents,
+	       recptproto *collectproto, FilterResponse_t &response, 
+	       ostream &logout)
+{
+  response.clear();
+
+  comerror_t err = noError;
+  FilterRequest_t request;
+
+  request.filterName = "NullFilter";
+  request.filterLang = lang;
+  request.filterResultOptions = FRmetadata;
+  request.getParents = getParents;
+  request.filterOptions = options;
+  request.fields = metadata;
+  request.docSet.push_back (OID);
+
+  assert (collectproto != NULL);
+  collectproto->filter (collection, request, response, err, logout);
+  if (err != noError)
+  {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii
+	   << "Error: call to filter failed for " << OID
+	   << " in recptprototools::get_info (" 
+	   << get_comerror_string (err) << ")\n";
+    return false;
+  }
+  
+  return true;
+}
+
+
+bool get_info (const text_tarray &OIDs, const text_t &collection, const text_t &lang,
+	       const text_tset &metadata, bool getParents,
+	       recptproto *collectproto, FilterResponse_t &response, 
+	       ostream &logout)
+{
+  response.clear();
+  if (OIDs.empty()) return true;
+
+  comerror_t err = noError;
+  FilterRequest_t request;
+
+  request.filterName = "NullFilter";
+  request.filterLang = lang;
+  request.filterResultOptions = FRmetadata;
+  request.getParents = getParents;
+  request.fields = metadata;
+
+  request.docSet = OIDs;
+  
+  collectproto->filter (collection, request, response, err, logout);
+  if (err != noError)
+  {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii
+	   << "Error: call to filter failed in recptprototools::get_info (" 
+	   << get_comerror_string (err) << ")\n";
+    return false;
+  }
+
+  return true;
+}
+
+
+// has_children returns true if OID has children
+bool has_children (const text_t &OID, const text_t &collection, const text_t &lang,
+		   recptproto *collectproto, ostream &logout) {
+
+  FilterResponse_t response;
+  text_tset metadata;
+  metadata.insert ("haschildren");
+
+  if (get_info (OID, collection, lang, metadata, false, collectproto,	response, logout))
+  {
+    if (response.docInfo[0].metadata["haschildren"].values[0] == "1")
+    {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+
+// get_children does a protocol call and returns (in response) the OIDs and 
+// metadata of all the children of OID. The metadata set should be loaded
+// with whatever metadata fields are to be requested.
+
+bool get_children (const text_t &OID, const text_t &collection, const text_t &lang,
+		   const text_tset &metadata, bool getParents,
+		   recptproto *collectproto, FilterResponse_t &response, 
+		   ostream &logout)
+{
+  response.clear();
+
+  comerror_t err = noError;
+  FilterRequest_t request;
+  OptionValue_t option;
+
+  option.name = "ParentNode";
+  option.value = OID;
+  request.filterOptions.push_back (option);
+  request.filterName = "BrowseFilter";
+  request.filterLang = lang;
+  request.filterResultOptions = FROID;
+
+  // Efficiency improvement: only get the filter to retrieve metadata if some has been requested
+  // Otherwise, the filter makes an unnecessary request to the database for each child node
+  // By Michael Dewsnip, DL Consulting Ltd
+  if (metadata.size() > 0)
+  {
+    request.filterResultOptions |= FRmetadata;
+  }
+
+  request.fields = metadata;
+  request.getParents = getParents;
+
+  collectproto->filter (collection, request, response, err, logout);
+
+  if (err != noError)
+  {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii
+	   << "Error: call to filter failed for " << OID 
+	   << " in recptprototools::get_children (" 
+	   << get_comerror_string (err) << ")\n";
+    return false;
+  }
+
+  return true;
+}
+
+
+static void recurse_contents (ResultDocInfo_t section, const bool &is_classify, 
+			      const text_t &collection, const text_t &lang,
+			      const text_tset &metadata, 
+			      recptproto *collectproto, FilterResponse_t &response, 
+			      ostream &logout)
+{
+  int haschildren = section.metadata["haschildren"].values[0].getint();
+  const text_t &doctype = section.metadata["doctype"].values[0];
+
+  if ((haschildren == 1) && ((!is_classify) || (doctype == "classify")))
+  {
+    FilterResponse_t tmp;
+    bool getParents = false;
+    get_children (section.OID, collection, lang, metadata, getParents, collectproto, tmp, logout);
+    ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
+    ResultDocInfo_tarray::iterator lastdoc = tmp.docInfo.end();
+    while (thisdoc != lastdoc)
+    {
+      response.docInfo.push_back (*thisdoc);
+      recurse_contents (*thisdoc, is_classify, collection, lang, metadata, collectproto, response, logout);
+      ++thisdoc;
+    }
+  }
+}
+
+
+// get_contents returns OIDs and metadata of all contents 
+// below (and including) OID.
+void get_contents (const text_t &topOID, const bool &is_classify, 
+		   text_tset &metadata, const text_t &collection, const text_t &lang,
+		   recptproto *collectproto, FilterResponse_t &response, 
+		   ostream &logout)
+{
+  if (topOID.empty()) return;
+  response.clear();
+
+  metadata.insert ("haschildren");
+  metadata.insert ("doctype");
+
+  // get topOIDs info
+  if (get_info (topOID, collection, lang, metadata, false, collectproto, response, logout))
+  {
+    recurse_contents (response.docInfo[0], is_classify, collection, lang, metadata, collectproto, response, logout);
+  }
+}
+
+
+bool get_metadata_values (const text_t metadata_elements, const text_t metadata_value_filter,
+			  const text_t metadata_value_grouping_expression, const text_t &collection,
+			  recptproto *collectproto, FilterResponse_t &response, ostream &logout)
+{
+  response.clear();
+
+  comerror_t err = noError;
+  FilterRequest_t request;
+  request.clear();
+
+  request.filterName = "SQLBrowseFilter";
+  request.requestParams = "GetMetadataValues";
+
+  OptionValue_t request_option;
+  request_option.name = "MetadataElements";
+  request_option.value = metadata_elements;
+  request.filterOptions.push_back (request_option);
+  request_option.name = "MetadataValueFilter";
+  request_option.value = metadata_value_filter;
+  request.filterOptions.push_back (request_option);
+  request_option.name = "MetadataValueGroupingExpression";
+  request_option.value = metadata_value_grouping_expression;
+  request.filterOptions.push_back (request_option);
+
+  assert (collectproto != NULL);
+  collectproto->filter (collection, request, response, err, logout);
+  if (err != noError)
+  {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii
+	   << "Error: call to filter failed for " << metadata_elements
+	   << " in recptprototools::get_metadata_values (" 
+	   << get_comerror_string (err) << ")\n";
+    return false;
+  }
+  
+  return true;
+}
+
+
+bool get_documents_with_metadata_value (const text_t metadata_elements, const text_t metadata_value,
+					const text_t sort_by_metadata_element_name, const text_t &collection,
+					recptproto *collectproto, FilterResponse_t &response, ostream &logout)
+{
+  response.clear();
+
+  comerror_t err = noError;
+  FilterRequest_t request;
+  request.clear();
+
+  request.filterName = "SQLBrowseFilter";
+  request.requestParams = "GetDocumentsWithMetadataValue";
+
+  OptionValue_t request_option;
+  request_option.name = "MetadataElements";
+  request_option.value = metadata_elements;
+  request.filterOptions.push_back (request_option);
+  request_option.name = "MetadataValue";
+  request_option.value = metadata_value;
+  request.filterOptions.push_back (request_option);
+  request_option.name = "SortByMetadataElement";
+  request_option.value = sort_by_metadata_element_name;
+  request.filterOptions.push_back (request_option);
+
+  assert (collectproto != NULL);
+  collectproto->filter (collection, request, response, err, logout);
+  if (err != noError)
+  {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii
+	   << "Error: call to filter failed for " << metadata_elements << " = " << metadata_value
+	   << " in recptprototools::get_documents_with_metadata_value (" 
+	   << get_comerror_string (err) << ")\n";
+    return false;
+  }
+  
+  return true;
+}
Index: /gsdl/trunk/runtime-src/src/protocol/recptprototools.h
===================================================================
--- /gsdl/trunk/runtime-src/src/protocol/recptprototools.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/protocol/recptprototools.h	(revision 16571)
@@ -0,0 +1,78 @@
+/**********************************************************************
+ *
+ * recptprototools.h -- 
+ * Copyright (C) 1999-2008  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef RECPTPROTOTOOLS_H
+#define RECPTPROTOTOOLS_H
+
+
+#include "text_t.h"
+#include "recptproto.h"
+
+
+// get_info does a protocol call and returns (in response) the info 
+// associated with OID. Metadata should be loaded with whatever
+// metadata fields are to be requested
+bool get_info (const text_t &OID, const text_t &collection, const text_t &lang,
+	       const text_tset &metadata, bool getParents,
+	       recptproto *collectproto, FilterResponse_t &response, 
+	       ostream &logout);
+bool get_info (const text_t &OID, const text_t &collection, const text_t &lang,
+	       const text_tset &metadata, const OptionValue_tarray &options,
+	       bool getParents,
+	       recptproto *collectproto, FilterResponse_t &response, 
+	       ostream &logout);
+bool get_info (const text_tarray &OIDs, const text_t &collection, const text_t &lang,
+	       const text_tset &metadata, bool getParents,
+	       recptproto *collectproto, FilterResponse_t &response, 
+	       ostream &logout);
+
+// has_children returns true if OID has children
+bool has_children (const text_t &OID, const text_t &collection, const text_t &lang, 
+		   recptproto *collectproto, ostream &logout);
+
+// get_children does a protocol call and returns (in response) the OIDs and 
+// metadata of all the children of OID. The metadata set should be loaded
+// with whatever metadata fields are to be requested.
+bool get_children (const text_t &OID, const text_t &collection, const text_t &lang, 
+		   const text_tset &metadata, bool getParents,
+		   recptproto *collectproto, FilterResponse_t &response, 
+		   ostream &logout);
+
+// get_contents returns OIDs and metadata of all contents 
+// below (and including) OID.
+void get_contents (const text_t &topOID, const bool &is_classify, 
+		   text_tset &metadata, const text_t &collection, const text_t &lang, 
+		   recptproto *collectproto, FilterResponse_t &response, 
+		   ostream &logout);
+
+bool get_metadata_values (const text_t metadata_elements, const text_t metadata_value_filter,
+			  const text_t metadata_value_grouping_expression, const text_t &collection,
+			  recptproto *collectproto, FilterResponse_t &response, ostream &logout);
+
+bool get_documents_with_metadata_value (const text_t metadata_elements, const text_t metadata_value,
+					const text_t sort_by_metadata_element_name, const text_t &collection,
+					recptproto *collectproto, FilterResponse_t &response, ostream &logout);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/protocol/win32.mak
===================================================================
--- /gsdl/trunk/runtime-src/src/protocol/win32.mak	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/protocol/win32.mak	(revision 16571)
@@ -0,0 +1,99 @@
+###########################################################################
+#
+# win32 makefile -- src/protocol
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ..\..
+INDEXERS_DIR = $(GSDL_DIR)\indexers
+PACKAGES_DIR = $(GSDL_DIR)\packages
+COLSERVR_DIR = $(GSDL_DIR)\src\colservr
+
+
+GSDL_VC4 = 0
+DLL = 0
+DLLDEBUG = 0
+
+
+!IF $(GSDL_VC4)
+CPPFLAGS = -GX
+!ELSE
+CPPFLAGS = -EHsc
+!ENDIF
+
+!IF $(DLL)
+CPPFLAGS = $(CPPFLAGS) -MD
+!ELSE
+!IF ($(DLLDEBUG))
+CPPFLAGS = $(CPPFLAGS) -MDd
+!ENDIF
+!ENDIF
+
+
+AR = lib
+CC = cl
+DEFS = -D__WIN32__ -DHAVE_CONFIG_H -DPARADOCNUM -D_LITTLE_ENDIAN -DSHORT_SUFFIX -D_CRT_SECURE_NO_DEPRECATE
+# Do NOT add the "recpt" directory here: the protocol should be independent of the receptionist!
+INCLUDES = -I"$(GSDL_DIR)" -I"$(GSDL_DIR)\src\lib" -I"$(COLSERVR_DIR)" -I"$(INDEXERS_DIR)\mgpp\text" \
+	 -I"$(PACKAGES_DIR)\windows\gdbm\gdbm"
+
+!IF $(GSDL_VC4)
+DEFS=$(DEFS) -DGSDL_NAMESPACE_BROKEN -DGSDL_USE_IOS_H -D__STL_NO_NEW_IOSTREAMS
+INCLUDES = $(INCLUDES) -I"$(PACKAGES_DIR)\windows\stlport\stlport"
+!ENDIF
+
+
+COMPILE = $(CC) -nologo -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+
+
+.SUFFIXES:
+.SUFFIXES: .cpp .obj
+.cpp.obj:
+	$(COMPILE) $< 
+
+
+SOURCES = \
+	nullproto.cpp \
+	recptproto.cpp \
+	recptprototools.cpp
+
+OBJECTS = \
+	nullproto.obj \
+	recptproto.obj \
+	recptprototools.obj
+
+LIBRARY = gsdlprotocol.lib	
+	
+
+# Default target: make gsdlprotocol.lib
+all: $(LIBRARY)
+
+gsdlprotocol.lib: $(OBJECTS) 
+	if EXIST $(LIBRARY) del $(LIBRARY)
+	$(AR) -nologo /out:$(LIBRARY) $(OBJECTS)
+
+install:
+
+clean:
+	del *.obj
+	del $(LIBRARY)
Index: /gsdl/trunk/runtime-src/src/recpt/Makefile.in
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/Makefile.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/Makefile.in	(revision 16571)
@@ -0,0 +1,229 @@
+###########################################################################
+#
+# Makefile -- src/recpt
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ../../..
+COMMON_DIR = $(GSDL_DIR)/gs2common
+RUNTIME_DIR = $(GSDL_DIR)/gs2runtime
+
+INDEXERS_DIR = $(COMMON_DIR)/indexers
+PACKAGES_DIR = $(RUNTIME_DIR)/packages
+COLSERVR_DIR = $(RUNTIME_DIR)/src/colservr
+PROTOCOL_DIR = $(RUNTIME_DIR)/src/protocol
+Z3950_DIR = $(RUNTIME_DIR)/src/z3950
+
+
+ENABLE_ACCENTFOLD = @ENABLE_ACCENTFOLD@
+ifeq ($(ENABLE_ACCENTFOLD), 1)
+ACCENTFOLD_LIBS = $(INDEXERS_DIR)/packages/unac/libunac.a 
+else
+ACCENTFOLD_LIBS = 
+endif
+
+USE_FASTCGI = @USE_FASTCGI@
+ifeq ($(USE_FASTCGI), 1)
+FASTCGI_DEFS = -DUSE_FASTCGI
+FASTCGI_INCLUDES = -I$(PACKAGES_DIR)/fcgi/include
+FASTCGI_LIBS = $(PACKAGES_DIR)/fcgi/libfcgi/libfcgi.a
+else
+FASTCGI_DEFS =
+FASTCGI_INCLUDES =
+FASTCGI_LIBS = 
+endif
+
+USE_SQLITE = @USE_SQLITE@
+ifeq ($(USE_SQLITE), 1)
+SQLITE_LIBS = $(COMMON_DIR)/packages/sqlite/lib/libsqlite3.a -ldl -lpthread
+else
+SQLITE_LIBS = 
+endif
+
+USE_Z3950 = @USE_Z3950@
+ifeq ($(USE_Z3950), 1)
+Z3950_DEFS = -DUSE_Z3950
+Z3950_INCLUDES = -I$(Z3950_DIR)
+Z3950_LIBS = $(Z3950_DIR)/gsdlz3950.a $(PACKAGES_DIR)/yaz/lib/libyaz.a
+else
+Z3950_DEFS =
+Z3950_INCLUDES = 
+Z3950_LIBS = 
+endif
+
+
+AR = ar
+CC = @CC@
+CFLAGS=@CFLAGS@ @COMPAT32BITFLAGS@
+CXX = @CXX@
+CXXFLAGS = @CXXFLAGS@ @COMPAT32BITFLAGS@
+DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DHAVE_CONFIG_H $(FASTCGI_DEFS) $(Z3950_DEFS)
+INCLUDES = @GDBM_INCLUDE@ -I. -I$(GSDL_DIR) -I$(COMMON_DIR)/src/lib \
+        -I$(COLSERVR_DIR) -I$(PROTOCOL_DIR) \
+	-I$(INDEXERS_DIR)/mg -I$(INDEXERS_DIR)/mg/lib -I$(INDEXERS_DIR)/mgpp/text \
+        -I$(PACKAGES_DIR)/expat/include $(FASTCGI_INCLUDES) $(Z3950_INCLUDES)
+INSTALL = @INSTALL@
+LDFLAGS = @LDFLAGS@ @COMPAT32BITFLAGS@
+LIBS = @LIBS@ @GDBM_LIBPATH@ -lgdbm -L$(PACKAGES_DIR)/expat/lib -lexpat $(ACCENTFOLD_LIBS) \
+	$(FASTCGI_LIBS) $(SQLITE_LIBS) $(Z3950_LIBS)
+RANLIB = @RANLIB@
+
+
+CXXCOMPILE = $(CXX) -c $(CXXFLAGS) $(DEFS) $(INCLUDES)
+CXXLINK = $(CXX) $(LDFLAGS) -o $@
+
+
+.SUFFIXES:
+.SUFFIXES: .cpp .o
+.cpp.o:
+	$(CXXCOMPILE) $< 
+
+
+SOURCES = \
+	action.cpp \
+	argdb.cpp \
+	authenaction.cpp \
+	browseaction.cpp \
+	browseactiontools.cpp \
+	browserclass.cpp \
+	browsetoolsclass.cpp \
+	cgiargs.cpp \
+	cgiutils.cpp \
+	cgiwrapper.cpp \
+	collectoraction.cpp \
+        converter.cpp \
+	datelistbrowserclass.cpp \
+	depositoraction.cpp \
+	documentaction.cpp \
+	dynamicclassifieraction.cpp \
+	extlinkaction.cpp \
+	formattools.cpp \
+	gtiaction.cpp \
+	highlighttext.cpp \
+	historydb.cpp \
+	hlistbrowserclass.cpp \
+	htmlbrowserclass.cpp \
+	htmlutils.cpp \
+	invbrowserclass.cpp \
+	librarymain.cpp \
+	maincfg.cpp \
+	pageaction.cpp \
+	pagedbrowserclass.cpp \
+	phindaction.cpp \
+	phindbrowserclass.cpp \
+	pingaction.cpp \
+	queryaction.cpp \
+	querytools.cpp \
+	receptionist.cpp \
+	statusaction.cpp \
+	summarise.cpp \
+	tipaction.cpp \
+	userdb.cpp \
+	usersaction.cpp \
+	vlistbrowserclass.cpp \
+	wizardaction.cpp
+
+OBJECTS = \
+	action.o \
+	argdb.o \
+	authenaction.o \
+	browseaction.o \
+	browseactiontools.o \
+	browserclass.o \
+	browsetoolsclass.o \
+	cgiargs.o \
+	cgiutils.o \
+	cgiwrapper.o \
+	collectoraction.o \
+        converter.o \
+	datelistbrowserclass.o \
+	depositoraction.o \
+	documentaction.o \
+	dynamicclassifieraction.o \
+	extlinkaction.o \
+	formattools.o \
+	gtiaction.o \
+	highlighttext.o \
+	historydb.o \
+	hlistbrowserclass.o \
+	htmlbrowserclass.o \
+	htmlutils.o \
+	invbrowserclass.o \
+	librarymain.o \
+	maincfg.o \
+	pageaction.o \
+	pagedbrowserclass.o \
+	phindaction.o \
+	phindbrowserclass.o \
+	pingaction.o \
+	queryaction.o \
+	querytools.o \
+	receptionist.o \
+	statusaction.o \
+	summarise.o \
+	tipaction.o \
+	userdb.o \
+	usersaction.o \
+	vlistbrowserclass.o \
+	wizardaction.o
+
+LIBRARY = gsdlrecpt.a
+
+GSDL_LIBS = \
+	$(PROTOCOL_DIR)/gsdlprotocol.a \
+	$(COLSERVR_DIR)/gsdlcolservr.a \
+	$(INDEXERS_DIR)/mg/src/text/libmgtext.a \
+	$(INDEXERS_DIR)/mg/lib/libmglib.a \
+	$(INDEXERS_DIR)/mgpp/text/libmgpptext.a \
+	$(INDEXERS_DIR)/mgpp/lib/libmgpplib.a \
+	$(COMMON_DIR)/src/lib/gsdllib.a
+
+EXECUTABLE_OBJECTS = \
+	$(OBJECTS) \
+	$(GSDL_LIBS)
+
+EXECUTABLE = library
+
+
+# Default target: make both gsdlrecpt.a and the library executable
+all: $(LIBRARY) $(EXECUTABLE)
+
+gsdlrecpt.a: $(OBJECTS)
+	rm -f $(LIBRARY)
+	$(AR) cru $(LIBRARY) $(OBJECTS)
+	$(RANLIB) $(LIBRARY)
+
+library: $(EXECUTABLE_OBJECTS) $(GSDL_LIBS)
+	$(CXXLINK) $(EXECUTABLE_OBJECTS) $(LIBS)
+
+install: $(EXECUTABLE)
+	$(INSTALL) -m 755 -s $(EXECUTABLE) $(GSDL_DIR)/cgi-bin
+
+clean:
+	rm -f $(OBJECTS) $(LIBRARY) $(EXECUTABLE)
+
+distclean:
+	rm -f $(OBJECTS) $(LIBRARY) $(EXECUTABLE) Makefile
+
+depend:
+	makedepend -Y -- $(DEFS) $(INCLUDES) $(CXXFLAGS) -- $(SOURCES)
Index: /gsdl/trunk/runtime-src/src/recpt/TODO
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/TODO	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/TODO	(revision 16571)
@@ -0,0 +1,57 @@
+For Z 39.50 Stuff
+
+pageaction.cpp
+--------------
+Macros:
+ * for "about" page, use a custom _textbrowseoptions_ macro (ie
+   create a new macro, maybe create a z3950.dm macro file ??)
+   (also maybe _numbrowseoptions_
+
+(Irrelevant?) (c. line 332)
+    disp.setmacro ("numdocs", "Global", cinfo.numDocs);
+    disp.setmacro ("builddate", "Global", builddate);
+
+That message "This collection contains..." is in the _collectionextra_
+macro.
+could get numdocs from the z39.50 server, as well as any other status
+information.
+
+win32.mak
+---------
+Needs updating for all added files (z*, parse.fl)
+
+yaz
+---
+Maybe put libyaz.a in $GSDLHOME/lib ?
+
+
+DESIGN ISSUES
+for z39.50 (and eventually nullproto when corba allows recept. and
+coll server to be physically separate), if the server is unavailable,
+should this be determined at:
+  * "home page" creation time, in which case the recept. must ping and
+test each collection it knows about, which may cause unacceptable delay, or
+  * "about page" creation time (ie individual collection), in which case
+the collection can not customise the page layout by modifying macros.
+
+Eg currently, the z39.50 collection will not create a TCP connection to the
+"target" (ie z39.50 server somewhere around the world) until it tries to
+get the "About this collection" information for that collection. 
+If the connection fails, the protocol can not change _queryform_ part of
+the page.
+
+
+MULTI-LINGUAL SUPPORT
+Multi-lingual - eg macros - want to set _collectionextra_ using
+metadata["collectionextra"] based on the chosen interface language.
+Should be done by OIDtools.cpp:get_info() and any action that calls
+proto->filter().
+queryaction.cpp (c. line 1097):
+  // add the requested language as an option to the query
+  if (!args["l"].empty()) {
+    OptionValue_t option;
+    option.name="Language";
+    option.value=args["l"];
+    request.filterOptions.push_back(option);
+  }
+
Index: /gsdl/trunk/runtime-src/src/recpt/action.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/action.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/action.cpp	(revision 16571)
@@ -0,0 +1,161 @@
+/**********************************************************************
+ *
+ * action.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "fileutil.h"
+
+#include "action.h"
+#include <assert.h>
+
+
+// define all the macros which are related to pages generated
+// by this action
+void action::define_internal_macros (displayclass &/*disp*/, cgiargsclass &/*args*/, 
+				     recptprotolistclass * /*protos*/, ostream &/*logout*/) {
+}
+
+action::action () {
+}
+
+action::~action () {
+}
+
+// configure should be called once for each configuration line
+void action::configure (const text_t &key, const text_tarray &cfgline) {
+  if (key == "gsdlhome") {
+    gsdlhome = cfgline[0];
+    if (collecthome.empty()) collecthome = filename_cat(gsdlhome,"collect");
+    if (dbhome.empty()) dbhome = cfgline[0];
+  }
+  if (key == "collecthome") {collecthome = cfgline[0];}
+  if (key == "gdbmhome") {dbhome = cfgline[0];}
+}
+
+// init should be called after all the configuration is done but
+// before any other methods are called
+bool action::init (ostream &/*logout*/) {
+  return true;
+}
+
+// returns the "a" argument value that will specify this action
+// this name should be short but does not have to be one character
+// long
+text_t action::get_action_name () {
+  return "nzdl";
+}
+
+// check_cgiargs should be called before get_cgihead_info, 
+// define_external_macros, and do_action. If an error is found
+// a message will be written to logout, if the error is severe
+// then the function will return false and no page content
+// should be produced based on the arguments.
+bool action::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/, 
+			    recptprotolistclass * /*protos*/, ostream &/*logout*/) {
+  return true;
+}
+
+// check_external_cgiargs should be called after check_cgiargs
+// for all actions. It should only be used to override some other
+// normal behaviour, for example, producing a login page when
+// the requested page needs authentication.
+bool action::check_external_cgiargs (cgiargsinfoclass &/*argsinfo*/,
+				     cgiargsclass &/*args*/,
+				     outconvertclass &/*outconvert*/,
+				     const text_t &/*saveconf*/,
+				     ostream &/*logout*/) {
+  return true;
+}
+
+// get_cgihead_info determines the cgi header information for
+// a set of cgi arguments. If response contains location then
+// response_data contains the redirect address. If reponse
+// contains content then reponse_data contains the content-type.
+// Note that images can now be produced by the receptionist.
+void action::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
+			       response_t &response, text_t &response_data, 
+			       ostream &/*logout*/) {
+  response = location;
+  response_data = "http://www.nzdl.org";
+}
+  
+// uses_display should return true if the receptionist should return
+// true if the display class is needed to output the page content
+// The default is to return true.
+bool action::uses_display (cgiargsclass &/*args*/) {
+  return true;
+}
+
+
+// define all the macros which might be used by other actions
+// to produce pages. These macros should be well documented.
+void action::define_external_macros (displayclass &/*disp*/, cgiargsclass &/*args*/, 
+				     recptprotolistclass * /*protos*/, ostream &/*logout*/) {
+}
+
+// returns false if there was an error which prevented the action
+// from outputing anything.
+bool action::do_action (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/, 
+			browsermapclass * /*browsers*/, displayclass &/*disp*/, 
+			outconvertclass &/*outconvert*/, ostream &/*textout*/, 
+			ostream &/*logout*/) {
+  return true;
+}
+
+
+bool operator==(const actionptr &x, const actionptr &y) {
+  return (x.a == y.a);
+}
+
+bool operator<(const actionptr &x, const actionptr &y) {
+  return (x.a < y.a);
+}
+
+
+// theaction remains the property of the calling code but
+// should not be deleted until it is removed from this list.
+void actionmapclass::addaction (action *theaction) {
+  // can't add a null action
+  assert (theaction != NULL);
+  if (theaction == NULL) return;
+  
+  // can't add an action with no name
+  assert (!(theaction->get_action_name()).empty());
+  if ((theaction->get_action_name()).empty()) return;
+
+  actionptr aptr;
+  aptr.a = theaction;
+  actionptrs[theaction->get_action_name()] = aptr;
+}
+
+// getaction will return NULL if the action could not be found
+action *actionmapclass::getaction (const text_t &key) {
+  // can't find an action with no name
+  assert (!key.empty());
+  if (key.empty()) return NULL;
+
+  iterator here = actionptrs.find (key);
+  if (here == actionptrs.end()) return NULL;
+  
+  return (*here).second.a;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/action.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/action.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/action.h	(revision 16571)
@@ -0,0 +1,184 @@
+/**********************************************************************
+ *
+ * action.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef ACTION_H
+#define ACTION_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "cgiargs.h"
+#include "display.h"
+#include "recptproto.h"
+#include "browserclass.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+#endif
+
+
+class action {
+protected:
+  cgiargsinfoclass argsinfo;
+  text_t gsdlhome;
+  text_t collecthome;
+  text_t dbhome;
+
+public:
+  action ();
+  virtual ~action ();
+
+  // configure should be called once for each configuration line
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+
+  // init should be called after all the configuration is done but
+  // before any other methods are called
+  virtual bool init (ostream &logout);
+
+  // returns the "a" argument value that will specify this action
+  // this name should be short but does not have to be one character
+  // long
+  virtual text_t get_action_name ();
+
+  // check_cgiargs should be called before get_cgihead_info, 
+  // define_external_macros, and do_action. If an error is found
+  // a message will be written to logout, if the error is severe
+  // then the function will return false and no page content
+  // should be produced based on the arguments.
+  virtual bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+			      recptprotolistclass *protos, ostream &logout);
+
+  // check_external_cgiargs should be called after check_cgiargs
+  // for all actions. It should only be used to override some other
+  // normal behaviour, for example, producing a login page when
+  // the requested page needs authentication.
+  virtual bool check_external_cgiargs (cgiargsinfoclass &argsinfo,
+				       cgiargsclass &args,
+				       outconvertclass &outconvert,
+				       const text_t &saveconf,
+				       ostream &logout);
+
+  // get_cgihead_info determines the cgi header information for
+  // a set of cgi arguments. If response contains location then
+  // response_data contains the redirect address. If reponse
+  // contains content then reponse_data contains the content-type.
+  // Note that images can now be produced by the receptionist.
+  virtual void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+				 response_t &response, text_t &response_data, 
+				 ostream &logout);
+  
+  // uses_display should return true if the receptionist should return
+  // true if the display class is needed to output the page content.
+  // The default is to return true.
+  virtual bool uses_display (cgiargsclass &args);
+
+  // define all the macros which are related to pages generated
+  // by this action
+  virtual void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+				       recptprotolistclass *protos, ostream &logout);
+
+  // define all the macros which might be used by other actions
+  // to produce pages. These macros should be well documented.
+  virtual void define_external_macros (displayclass &disp, cgiargsclass &args, 
+				       recptprotolistclass *protos, ostream &logout);
+
+  // returns false if there was an error which prevented the action
+  // from outputing anything.
+  virtual bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+			  browsermapclass *browsers, displayclass &disp, 
+			  outconvertclass &outconvert, ostream &textout, 
+			  ostream &logout);
+
+  // return true if the specified top classifier is handled by this action
+  virtual bool is_my_classifier(const text_t& topcl) { return false; }
+
+  // getargsinfo should be called after all configuration files
+  // have been read
+  cgiargsinfoclass *getargsinfo() {return &argsinfo;};
+};
+
+
+// The actionptr function does not 'own' the action. The 
+// action should be deleted by the code which created it.
+class actionptr {
+public:
+  action *a;
+
+  actionptr () {a=NULL;}
+};
+
+bool operator==(const actionptr &x, const actionptr &y);
+bool operator<(const actionptr &x, const actionptr &y);
+
+typedef map<text_t, actionptr, lttext_t> actionptrmap;
+
+// contains a list of actions indexed by their name
+class actionmapclass {
+protected:
+  actionptrmap actionptrs;
+
+public:
+  // type support for actionptrmap
+  typedef actionptrmap::iterator iterator;
+  typedef actionptrmap::const_iterator const_iterator;
+  typedef actionptrmap::reference reference;
+  typedef actionptrmap::const_reference const_reference;
+  typedef actionptrmap::size_type size_type;
+
+  typedef actionptrmap::difference_type difference_type;
+  typedef actionptrmap::const_reverse_iterator const_reverse_iterator;
+  typedef actionptrmap::reverse_iterator reverse_iterator;
+  
+  // basic container support
+  iterator begin () {return actionptrs.begin();}
+  const_iterator begin () const {return actionptrs.begin();}
+  iterator end () {return actionptrs.end();}
+  const_iterator end () const {return actionptrs.end();}
+
+  void erase(iterator pos) {actionptrs.erase(pos);}
+  void erase(iterator first, iterator last) {actionptrs.erase(first, last);}
+  actionmapclass &operator=(const actionmapclass &x) {actionptrs=x.actionptrs;return *this;}
+
+  bool empty () const {return actionptrs.empty();}
+  size_type size() const {return actionptrs.size();}
+
+
+  // added functionality
+  void clear () {actionptrs.erase(actionptrs.begin(),actionptrs.end());}
+
+  // theaction remains the property of the calling code but
+  // should not be deleted until it is removed from this list.
+  void addaction (action *theaction);
+
+  // getaction will return NULL if the action could not be found
+  action *getaction (const text_t &key);
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/argdb.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/argdb.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/argdb.cpp	(revision 16571)
@@ -0,0 +1,77 @@
+/**********************************************************************
+ *
+ * argdb.cpp -- 
+ * Copyright (C) 2001  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_COLLECTOR_ACTION
+
+// argdb is used by the collector for storing cgi arguments on disk (in a database)
+
+#include "argdb.h"
+#include "gdbmclass.h"
+
+argdb::argdb (const text_t &filename) {
+  dbfile = filename;
+}
+  
+bool argdb::update_args (text_tmap &argmap) {
+  gdbmclass argdb;
+  if (!argdb.opendatabase(dbfile, DB_WRITER_CREATE, 1000, true)) return false;
+  infodbclass info;
+  
+  argdb.getinfo("savedargs", info);
+
+  text_tmap::iterator here = argmap.begin();
+  text_tmap::iterator end = argmap.end();
+  while (here != end) {
+    if (!(*here).second.empty()) {
+      info.setinfo((*here).first, (*here).second);
+    }
+    ++here;
+  }
+
+  bool rv = argdb.setinfo ("savedargs", info);
+  argdb.closedatabase();
+  return rv;
+}
+
+bool argdb::get_args (text_tmap &argmap) {
+  argmap.erase(argmap.begin(), argmap.end());
+  gdbmclass argdb;
+  if (!argdb.opendatabase(dbfile, DB_READER, 1000, true)) return false;
+  infodbclass info;
+  
+  if (!argdb.getinfo("savedargs", info)) return false;
+  
+  infodbclass::const_iterator here = info.begin();
+  infodbclass::const_iterator end = info.end();
+  while (here != end) {
+    argmap[(*here).first] = info[(*here).first];
+    ++here;
+  }
+  argdb.closedatabase();
+  return true;
+}
+
+#endif //GSDL_USE_COLLECTOR_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/argdb.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/argdb.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/argdb.h	(revision 16571)
@@ -0,0 +1,50 @@
+/**********************************************************************
+ *
+ * argdb.h -- 
+ * Copyright (C) 2001  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_COLLECTOR_ACTION
+
+#ifndef ARGDB_H
+#define ARGDB_H
+
+#include "text_t.h"
+
+class argdb {
+
+protected:
+
+  text_t dbfile;
+
+public:
+  
+  argdb (const text_t &filename);
+  virtual ~argdb () {}
+  
+  bool update_args (text_tmap &argmap);
+  bool get_args (text_tmap &argmap);
+};
+
+#endif //!ARGDB_H
+#endif //GSDL_USE_COLLECTOR_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/authenaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/authenaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/authenaction.cpp	(revision 16571)
@@ -0,0 +1,345 @@
+/**********************************************************************
+ *
+ * authenaction.cpp -- authenticating users
+ * Copyright (C) 1999  DigiLib Systems Limited, New Zealand
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_AUTHEN_ACTION
+
+#include "authenaction.h"
+#include "fileutil.h"
+#include "cfgread.h"
+#include "cgiutils.h"
+#include "gsdltimes.h"
+
+
+///////////////
+// authenaction
+///////////////
+
+authenaction::authenaction () {
+  keydecay = 1800; // 30 minutes
+  recpt = NULL;
+
+  // this action uses cgi variable "a"
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "a";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "us"
+  arg_ainfo.shortname = "us";
+  arg_ainfo.longname = "user account status";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "invalid";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "ug"
+  arg_ainfo.shortname = "ug";
+  arg_ainfo.longname = "user groups"; // comma seperated list
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "un"
+  arg_ainfo.shortname = "un";
+  arg_ainfo.longname = "user name";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "pw"
+  arg_ainfo.shortname = "pw";
+  arg_ainfo.longname = "password";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "ky" - gives a specific user authentication for a
+  // limited amount of time
+  arg_ainfo.shortname = "ky";
+  arg_ainfo.longname = "user time key";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "ua" - ""=no, "1"=yes 
+  arg_ainfo.shortname = "ua";
+  arg_ainfo.longname = "whether a user has been authenticated";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "er" - compressed arguments for the referer page
+  arg_ainfo.shortname = "er";
+  arg_ainfo.longname = "the compressed args of the refer page";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "uan" - whether user authentication is needed
+  arg_ainfo.shortname = "uan";
+  arg_ainfo.longname = "whether user authentication is needed";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+}
+
+void authenaction::configure (const text_t &key, const text_tarray &cfgline) {
+  action::configure (key, cfgline);
+}
+
+bool authenaction::init (ostream &logout) {
+  if (dbhome.empty()) {
+    logout << "ERROR (authenaction::init) dbhome is not set\n";
+    return false;
+  }
+
+  return action::init (logout);
+}
+
+bool authenaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/, 
+				  recptprotolistclass * /*protos*/, ostream &/*logout*/) {
+  return true;
+}
+
+// returns false if there is a major problem with the cgi arguments -- not
+// if authentication fails. If the authentication fails "un" will be empty
+bool authenaction::check_external_cgiargs (cgiargsinfoclass &argsinfo,
+					   cgiargsclass &args,
+					   outconvertclass &outconvert,
+					   const text_t &saveconf,
+					   ostream &logout) {
+
+  // no need to go further unless authentication is
+  // required by this page
+  if (args["uan"].empty()) return true;
+
+  // failure means we have to redirect to this action to get authentication
+  // (if we are not already doing this)
+
+  userinfo_t thisuser;
+
+  text_t &args_uan = args["uan"];  text_t &args_un = args["un"];
+  text_t &args_pw = args["pw"];    text_t &args_us = args["us"];
+  text_t &args_ug = args["ug"];    text_t &args_ky = args["ky"];
+  text_t &args_ua = args["ua"];    text_t &args_a = args["a"];
+
+  // we must have a username and a password or a key to
+  // do any authentication
+  args_ua.clear(); // default = false;
+  if (args_un.empty() || args_pw.empty()) args_us = "invalid";
+  else args_us = "failed";
+
+  // make sure we have a username                                                                                                 
+  int status = user_database->get_user_info (args_un, thisuser);
+  if (!args_un.empty() && (status == ERRNO_SUCCEED)) {
+    if (!args_pw.empty()) {
+      // we are authenticating using a password
+      if (user_database->check_passwd (thisuser.username, args_pw) == ERRNO_SUCCEED) args_ua = "1"; // succeeded
+      
+    } else if (!args_ky.empty()) {
+      // we are authenticating using a key
+      if (key_database->check_key(thisuser, args_ky, args_ug, keydecay)) args_ua = "1";
+      else args_us = "stalekey";
+    }
+  }
+
+  args_pw.clear(); // password goes no further
+  if (!args_ua.empty()) {
+    if (thisuser.enabled) {
+      bool haspermission = true;
+
+      // check to make sure the user is in the required group
+      // one group is available only at the moment.
+      // this is what we are changing !
+      
+      if (!args_ug.empty()) {
+
+	 // Since we recieve a comma seperated list
+	 // of groups like mygroup,yourgroup,ourgroup
+	 // we want to split them into individual groups
+	 // and examine them. This is what is done here.
+	 
+	 text_tset splitgrps;
+	 text_t::const_iterator split_here = args_ug.begin();
+	 text_t::const_iterator split_end = args_ug.end();
+
+	 splitchar(split_here,split_end,',',splitgrps);
+
+	 haspermission = false;
+
+	 // This examines the current user to be authenticated and
+	 // tries to see if he or she is in the group that we have in
+	 // thisuser structure. We compare args_ua contents with that
+	 // of the user database.
+	 
+	 text_t::const_iterator group_here = thisuser.groups.begin();
+	 text_t::const_iterator group_end = thisuser.groups.end();
+	 text_t thisgroup;
+	while (group_here != group_end) {
+	   group_here = getdelimitstr (group_here, group_end, ',', thisgroup);
+	   if (splitgrps.find(thisgroup) != splitgrps.end() )
+	      {
+		 haspermission = true;
+		 break;
+	      }
+	}
+      }
+      
+      if (haspermission) {
+	 // succeeded, get info about this user
+	 // note: we don't need to set "ug" as it is already set to what it needs to be
+	 args_us = "enabled";
+	 args_ky = key_database->generate_key(args_un); // new key
+	
+	// delete old keys around every 50 accesses
+	if (rand()%50 == 1) key_database->remove_old_keys(keydecay);
+	
+      } else {
+	// succeeded, however, the user is not in the correct group
+	 args_ua.clear();
+	 args_us = "permissiondenied";
+	 args_ky.clear();
+      }
+      
+    } else {
+       // succeeded, however, the account is disabled
+      args_ua.clear();
+      args_us = "disabled";
+      args_ky.clear();
+    }
+
+  } else {
+    // failure, reset info about the user
+    args_ky.clear();
+  }
+
+  // we will have to redirect the user if authentication is needed,
+  // it failed, and we weren't on our way to be authenticated anyway
+  if ((!args_uan.empty()) && (args_ua.empty()) && (args_a != "a")) {
+    // need to save the current arguments in "er"
+    text_t &arg_er = args["er"];
+    if (!compress_save_args(argsinfo, saveconf, args, arg_er, outconvert, logout))
+      arg_er.clear();
+    
+    // needs to be decoded for use within forms
+    decode_cgi_arg (arg_er);    
+
+    // redirect to this action
+    args_a = "a";
+  }
+
+  return true;
+}
+
+void authenaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
+				     response_t &response, text_t &response_data, 
+				     ostream &/*logout*/) {
+  response = content;
+  response_data = "text/html";
+}
+
+void authenaction::define_internal_macros (displayclass &disp, cgiargsclass &args, 
+					   recptprotolistclass * /*protos*/, ostream &/*logout*/) {
+  // sets _authen:messageextra_ based on the value of args["us"]
+  //      _authen:hiddenargs_   to contain all the arguments that were
+  //                            explicitly set
+  disp.setmacro ("messagestatus", "authen", ("_authen:message" + args["us"]
+					     + "_"));
+  // change style of header and footer if page is a frame
+  if ((args["p"].empty()) || (args["p"] == "frameset")) {
+    disp.setmacro ("header", "authen", "_status:infoheader_(Log in)");
+    disp.setmacro ("header", "authenok", "_status:infoheader_(Log in)");
+    disp.setmacro ("footer", "authen", "_status:infofooter_(Log in)");
+    disp.setmacro ("footer", "authenok", "_status:infofooter_(Log in)");
+  }
+
+  // get a list of saved configuration arguments (if possible)
+  text_t saveconf;
+  text_tset saveconfset;
+  if (recpt != NULL) {
+    saveconf = recpt->get_configinfo().saveconf;
+    splitchar (saveconf.begin(), saveconf.end(), '-', saveconfset);
+  }
+  
+  text_t hiddenargs;
+  cgiargsclass::const_iterator args_here = args.begin();
+  cgiargsclass::const_iterator args_end = args.end();
+  while (args_here != args_end) {
+    // set this as a hidden argument if it came from the cgi arguments,
+    // its not the compressed arguments, the query string, a user name or
+    // password, or collect.cfg, and if it is not in the compressed arguments
+    if ((*args_here).second.source == cgiarg_t::cgi_arg &&
+	(*args_here).first != "e" && (*args_here).first != "q" &&
+	(*args_here).first != "un" && (*args_here).first != "pw" &&
+	(*args_here).first != "cfgfile" && 
+	saveconfset.find((*args_here).first) == saveconfset.end()) {
+      hiddenargs += "<input type=hidden name=\"" + (*args_here).first +
+	"\" value=\"_cgiarg" + (*args_here).first + "_\">\n";
+    }
+    ++args_here;
+  }
+
+  disp.setmacro ("hiddenargs", "authen", hiddenargs);
+}
+
+bool authenaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/, 
+			      browsermapclass * /*browsers*/, displayclass &disp, 
+			      outconvertclass &outconvert, ostream &textout, 
+			      ostream &/*logout*/) {
+  if (args["us"] == "enabled") {
+    // have been authenticated
+    textout << outconvert << disp
+	    << "_authenok:header_\n_authenok:content_\n_authenok:footer_\n";
+    return true;
+  }
+  
+  // need to be authenticated
+  textout << outconvert << disp
+	  << "_authen:header_\n_authen:content_\n_authen:footer_\n";
+
+  return true;
+}
+
+#endif //GSDL_USE_AUTHEN_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/authenaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/authenaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/authenaction.h	(revision 16571)
@@ -0,0 +1,89 @@
+/**********************************************************************
+ *
+ * authenaction.h -- authenticating users
+ * Copyright (C) 1999  DigiLib Systems Limited, New Zealand
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_AUTHEN_ACTION
+
+#ifndef AUTHENACTION_H
+#define AUTHENACTION_H
+
+#include "gsdlconf.h"
+#include "action.h"
+#include "text_t.h"
+#include "userdb.h"
+#include "receptionist.h"
+
+
+// note: you need to tell this action about the receptionist
+// using set_receptionist
+
+class authenaction : public action {
+protected:
+  userdbclass *user_database;
+  keydbclass *key_database;
+  int keydecay;
+
+  receptionist *recpt;
+  
+public:
+  authenaction ();
+  virtual ~authenaction () {}
+
+  void set_userdb(userdbclass *udb) {user_database = udb;}
+
+  void set_keydb (keydbclass *kdb) {key_database = kdb;}
+
+  void set_receptionist (receptionist *therecpt) {recpt=therecpt;}
+  
+  void configure (const text_t &key, const text_tarray &cfgline);
+
+  bool init (ostream &logout);
+  
+  text_t get_action_name () {return "a";}
+  
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass *protos, ostream &logout);
+
+  bool check_external_cgiargs (cgiargsinfoclass &argsinfo,
+			       cgiargsclass &args,
+			       outconvertclass &outconvert,
+			       const text_t &saveconf,
+			       ostream &logout);
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response, text_t &response_data, 
+			 ostream &logout);
+  
+  void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+  
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+};
+
+#endif //!AUTHENACTION_H
+#endif //GSDL_USE_AUTHEN_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/browseaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/browseaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/browseaction.cpp	(revision 16571)
@@ -0,0 +1,249 @@
+/**********************************************************************
+ *
+ * browseaction.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_BROWSE_ACTION
+
+#include "browseaction.h"
+#include "querytools.h"
+#include "browseactiontools.h"
+#include "recptprototools.h"
+
+browseaction::browseaction(){
+
+ 
+
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "br";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  //the first browsing criterion -- collection metadata types
+  arg_ainfo.shortname = "b1";
+  arg_ainfo.longname = "browse criterion 1";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+ 
+  //the second browsing criterion -- collection metadata types + none - meaning
+  //only one browsing criterion.  None is the default.
+  arg_ainfo.shortname = "b2";
+  arg_ainfo.longname = "browse criterion 2";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+  
+  //the number of documents to show per page -- if the box is empty then
+  //only the most basic divisions are made (so, first letter for A-Z, year 
+  //for date).
+  arg_ainfo.shortname = "bnu";
+  arg_ainfo.longname = "browse docs per page";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::good;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  //The text to filter documents for browsing (only documents containing these 
+  //words will be browsed).
+  arg_ainfo.shortname = "bft";
+  arg_ainfo.longname = "browse filter text";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::none;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+
+  //Whether all or just some of the words in the filter box have to be present
+  //0 - any 1- all
+  arg_ainfo.shortname = "bt";
+  arg_ainfo.longname = "browse all or any";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+  
+  
+}
+
+browseaction::~browseaction(){}
+
+bool browseaction::init (ostream &logout){
+  return true;
+}
+
+void browseaction::configure (const text_t &key, const text_tarray &cfgline){
+  action::configure(key, cfgline);
+}
+
+
+
+bool browseaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/, 
+				  recptprotolistclass * /*protos*/, ostream &/*logout*/) {
+  // don't want to check anything yet.
+  
+  return true;
+}
+
+  
+void browseaction::get_cgihead_info (cgiargsclass &args, 
+				     recptprotolistclass *protos,
+				     response_t &response, 
+				     text_t &response_data, 
+				     ostream &logout){
+  response = content;
+  response_data = "text/html";
+
+  
+}
+
+void browseaction::define_internal_macros (displayclass &disp, 
+					   cgiargsclass &args, 
+					   recptprotolistclass *protos, 
+					   ostream &logout){
+ 
+}
+
+void browseaction::define_external_macros (displayclass &disp, 
+					   cgiargsclass &args, 
+					   recptprotolistclass *protos, 
+					   ostream &logout){
+  
+}
+
+bool browseaction::do_action (cgiargsclass &args, recptprotolistclass *protos, 
+			      browsermapclass *browsers, displayclass &disp, 
+			      outconvertclass &outconvert, ostream &textout, 
+			      ostream &logout){
+ 
+  if(args["c"].empty()) return false;
+  else if(get_document_list(args, protos, browsers, disp, outconvert, textout,
+			    logout)) return true;
+  else return false;
+}
+
+bool browseaction::get_document_list(cgiargsclass &args, 
+		recptprotolistclass *protos, browsermapclass *browsers, 
+		displayclass &disp, outconvertclass &outconvert, 
+		ostream &textout, ostream &logout){ 
+  
+  text_t collection = args["c"];
+  comerror_t err;
+  text_t list_type = "VList";  //result display type
+
+  //check that the protocol is alive
+  recptproto* colproto = protos->getrecptproto (collection, logout);
+  if(colproto == NULL) {
+    logout << outconvert << "ERROR: Null collection protocol trying to browse "
+	   << collection << "\n";
+    return false;
+  }
+  
+  //check the collection is responding/in place
+  ColInfoResponse_t *colinfo = recpt->get_collectinfo_ptr(colproto, collection,
+							  logout);
+  if(colinfo == NULL){
+    logout << outconvert << "ERROR: Null returned for get_collectinfo_ptr on "
+	   << collection << "in browseaction\n";
+    return false;
+  }
+
+  browserclass* br_ptr = browsers->getbrowser(list_type);
+
+  FilterRequest_t request;
+  FilterResponse_t response;
+
+  //set up browser structure 
+  br_ptr->set_filter_options(request, args);
+  request.filterLang = args["l"];
+  br_ptr->load_metadata_defaults(request.fields);
+
+  //set up format information
+  format_t* formatptr = new format_t();
+  parse_formatstring(br_ptr->get_default_formatstring(), formatptr, 
+		     request.fields, request.getParents);
+
+  request.filterResultOptions = FROID | FRmetadata;
+  
+  text_t bf_string = g_EmptyText;
+  format_browsestring(args["bft"],bf_string,args.getintarg("bt"));
+  
+  set_browsefilter_options(request, bf_string, args);
+  
+  //set up browse filter string;
+  if(!args["bft"].empty()){
+
+    colproto->filter (collection, request, response, err, logout);
+    if (err != noError) {
+      outconvertclass text_t2ascii;
+      logout << text_t2ascii
+	     << "browseaction::get_document_list QueryFilter failed "
+	     << "for " << collection << " collection (" 
+	     << get_comerror_string (err) << ")\n";
+      return false;
+    }// if (err != noError) 
+
+  }// end if(!args["bft"].empty())
+  else {
+    text_tset metadata_items;
+    text_t temp = "Title";
+    metadata_items.insert(temp);
+    temp = "browselist";
+    if (!get_children(temp, args["c"], args["l"], metadata_items, false, colproto,
+		     response,logout)) return false;
+  }
+
+  //get rid of documents that do not have the metadata element classified on
+  if(!remove_no_meta_results("Title",response, outconvert)) {
+    return false;
+    logout<<"ERROR: browseactiontools::remove_no_meta_results failed"<<endl;
+  }
+
+  textout << outconvert << disp << "_browse:header_\n" <<"_browse:content_";
+
+  
+  bool use_table = is_table_content (formatptr);
+  br_ptr->output_section_group (response, args, collection, 0, formatptr, 
+			      use_table, request.fields, request.getParents, 
+			      colproto, disp, outconvert, textout, logout);
+
+  textout << outconvert << disp << "_browse:footer_";
+    
+  
+  
+  return true;
+}
+
+#endif //GSDL_USE_BROWSE_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/browseaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/browseaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/browseaction.h	(revision 16571)
@@ -0,0 +1,77 @@
+/**********************************************************************
+ *
+ * browseaction.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_BROWSE_ACTION
+
+#ifndef BROWSEACTION_H
+#define BROWSEACTION_H
+
+#include "action.h"
+#include "receptionist.h"
+
+class browseaction : public action{
+ protected:
+  receptionist* recpt;
+  bool get_document_list(cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+ public:
+  browseaction();
+  virtual ~browseaction();
+
+  bool init (ostream &logout);
+
+  void configure (const text_t &key, const text_tarray &cfgline);
+
+  text_t get_action_name() {return "br";}
+  
+  void set_receptionist (receptionist *therecpt) {recpt=therecpt;}
+
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass *protos, ostream &logout);
+
+  
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+				 response_t &response, text_t &response_data, 
+				 ostream &logout);
+
+  void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+  
+  void define_external_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+  const cgiargsinfoclass& getargsinfo() const {return argsinfo;};
+};
+
+#endif //!BROWSEACTION_H
+#endif //GSDL_USE_BROWSE_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/browseactiontools.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/browseactiontools.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/browseactiontools.cpp	(revision 16571)
@@ -0,0 +1,129 @@
+/**********************************************************************
+ *
+ * browseactiontools.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#include "browseactiontools.h"
+#include <ctype.h>
+
+void format_browsestring(const text_t& orig, text_t& formatted, int and_or)
+{
+  
+ 
+  text_t conj = g_EmptyText;
+  
+  if(and_or == 0){ conj = " | "; }
+  else { conj = " & "; }
+  text_t::const_iterator here = orig.begin();
+  text_t::const_iterator end = orig.end();
+  
+  //while not at the end of the filter string
+  while(here!=end){
+    //if seeing text, add it to the formatted string
+    if(!isspace(*here)){
+      formatted.push_back(*here);
+      ++here;
+    }
+    //else, if seeing spaces, check that there is following text and add
+    //the ncessary conjugation if there is.
+    else if(isspace(*here)){
+      while(isspace(*here) && here!=end) ++here;
+      if(here!=end) formatted += conj;
+    }
+  }
+
+}
+
+// this stuff is all copied from the queryoptions code - don't ask how it all
+// hangs in with the filters - those things are a mystery 
+void set_browsefilter_options(FilterRequest_t &request, const text_t &browsestring,
+			      cgiargsclass &args)
+{
+  request.filterName = "QueryFilter";
+
+   OptionValue_t option;
+
+   option.name = "Term";
+   option.value = browsestring;
+   request.filterOptions.push_back (option);
+   
+   option.name = "QueryType";
+   option.value = "boolean";
+   request.filterOptions.push_back (option);
+  
+   option.name = "MatchMode";
+   option.value = (args.getintarg("bt")) ? "some" : "all";
+   request.filterOptions.push_back (option);
+   
+   option.name = "Casefold";
+   option.value = (args.getintarg("k")) ? "true" : "false";
+   request.filterOptions.push_back (option);
+   
+   option.name = "Stem";
+   option.value = (args.getintarg("s")) ? "true" : "false";
+   request.filterOptions.push_back (option);
+
+   option.name = "Maxdocs";
+   option.value = -1;
+   request.filterOptions.push_back (option);
+   
+   option.name = "Index";
+   option.value = "dtx";
+   request.filterOptions.push_back (option);
+     
+   
+}
+
+bool remove_no_meta_results(const text_t& metaname, FilterResponse_t &response, 
+			    outconvertclass &outconvert)
+{
+  
+  ResultDocInfo_tarray::iterator check = response.docInfo.begin();
+  ResultDocInfo_tarray::iterator done = response.docInfo.end();
+  // look through all the returned documents
+  while(check != response.docInfo.end()){
+   
+    //if the document doesn't have the metadata item classified on 
+    //remove it.
+    text_t title = *((*check).metadata.find(metaname)->second).values.begin();
+    if(title == g_EmptyText)
+      {
+	
+	response.docInfo.erase(check);
+	
+      }
+    else {
+     
+      ++check;
+     
+    }
+ 
+  }
+  return true;
+}
+
+
+
+
+
Index: /gsdl/trunk/runtime-src/src/recpt/browseactiontools.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/browseactiontools.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/browseactiontools.h	(revision 16571)
@@ -0,0 +1,48 @@
+/********************************************************************
+ *
+ * browseactiontools.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef BROWSEACTIONTOOLS_H
+#define BROWSEACTIONTOOLS_H
+
+#include "cgiargs.h"
+#include "recptproto.h"
+
+//this puts ands or ors into the querystring as necessary
+void format_browsestring(const text_t& orig, text_t& formatted, int and_or);
+
+//this thing sets up the search associated with a browse.  It's programmed by 
+//witchcraft, so I don't really know how/why it works - I lifted the code from
+//somewhere else.
+void set_browsefilter_options(FilterRequest_t &request, const text_t &browsestring,
+			      cgiargsclass &args);
+
+//this thing filters out all the results of a request to the collection 
+//(whether it be for all documents or just the ones with specified terms)
+//that don't have the required "metaname" metadata element.
+bool remove_no_meta_results(const text_t &metaname, FilterResponse_t &response,
+			    outconvertclass &outconvert);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/browserclass.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/browserclass.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/browserclass.cpp	(revision 16571)
@@ -0,0 +1,198 @@
+/**********************************************************************
+ *
+ * browserclass.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "browserclass.h"
+#include <assert.h>
+
+
+browserclass::browserclass () {
+}
+
+browserclass::~browserclass () {
+}
+
+// configure should be called once for each configuration line
+// the default version does nothing
+void browserclass::configure (const text_t &/*key*/, const text_tarray &/*cfgline*/) {
+}
+
+// init should be called after all the configuration is done but
+// before any other methods are called
+bool browserclass::init (ostream &/*logout*/) {
+  return true;
+}
+
+// returns the name that specifies the browserclass type
+text_t browserclass::get_browser_name () {
+  return g_EmptyText;
+}
+
+void browserclass::processOID (cgiargsclass &/*args*/, recptproto * /*collectproto*/, ostream &/*logout*/) {
+}
+
+void browserclass::load_metadata_defaults (text_tset &/*metadata*/) {
+}
+
+text_t browserclass::get_default_formatstring () {
+  return g_EmptyText;
+}
+
+void browserclass::set_filter_options (FilterRequest_t &request, cgiargsclass &args) {
+  
+  OptionValue_t option;
+
+  if (args["a"] == "q") {
+    int arg_m = args.getintarg("m");
+    
+    option.name = "StartResults";
+    option.value = args["r"];
+    request.filterOptions.push_back (option);
+    
+    option.name = "EndResults";
+    int endresults = args.getintarg("o") + (args.getintarg("r") - 1);
+    //    int endresults = (args.getintarg("o")*3) + (args.getintarg("r") - 1);
+    if ((endresults > arg_m) && (arg_m != -1)) endresults = arg_m;
+    option.value = endresults;
+    request.filterOptions.push_back (option);
+
+  } else {
+    option.name = "StartResults";
+    option.value = args["r"];
+    request.filterOptions.push_back (option);
+    
+    option.name = "EndResults";
+    int endresults = 20 + (args.getintarg("r") - 1);
+    option.value = endresults;
+    request.filterOptions.push_back (option);
+  }
+}
+
+int browserclass::output_section_group (ResultDocInfo_t &/*section*/, cgiargsclass &/*args*/,
+					const text_t &/*collection*/, int /*colnumber*/, 
+					format_t * /*formatlistptr*/, bool /*use_table*/, 
+					text_tset &/*metadata*/, bool &/*getParents*/,
+					recptproto * /*collectproto*/, displayclass &/*disp*/, 
+					outconvertclass &/*outconvert*/, ostream &/*textout*/, 
+					ostream &/*logout*/) {
+  return 0;
+}
+
+int browserclass::output_section_group (ResultDocInfo_t &/*section*/, cgiargsclass &/*args*/,
+					const text_t &/*labels*/, const text_t &/*collection*/, int /*colnumber*/, 
+					format_t * /*formatlistptr*/, bool /*use_table*/, 
+					text_tset &/*metadata*/, bool &/*getParents*/,
+					recptproto * /*collectproto*/, displayclass &/*disp*/, 
+					outconvertclass &/*outconvert*/, ostream &/*textout*/, 
+					ostream &/*logout*/) {
+  return 0;
+}
+
+int browserclass::output_section_group (FilterResponse_t &/*sections*/, cgiargsclass &/*args*/,
+					const text_t &/*collection*/, int /*colnumber*/, 
+					format_t * /*formatlistptr*/, bool /*use_table*/, 
+					text_tset &/*metadata*/, bool &/*getParents*/,
+					recptproto * /*collectproto*/, displayclass &/*disp*/, 
+					outconvertclass &/*outconvert*/, ostream &/*textout*/, 
+					ostream &/*logout*/) {
+  return 0;
+}
+
+int browserclass::output_section_group (FilterResponse_t &/*sections*/, cgiargsclass &/*args*/,
+					const text_t& /*currentSection*/, const text_t &/*labels*/, const text_t &/*collection*/, int /*colnumber*/, 
+					format_t * /*formatlistptr*/, bool /*use_table*/, 
+					text_tset &/*metadata*/, bool &/*getParents*/,
+					recptproto * /*collectproto*/, displayclass &/*disp*/, 
+					outconvertclass &/*outconvert*/, ostream &/*textout*/, 
+					ostream &/*logout*/)
+{
+  return 0;
+}
+
+bool operator==(const browserptr &x, const browserptr &y) {
+  return (x.b == y.b);
+}
+
+bool operator<(const browserptr &x, const browserptr &y) {
+  return (x.b < y.b);
+}
+
+// thebrowserclass remains the property of the calling code but
+// should not be deleted until it is removed from this list.
+void browsermapclass::addbrowser (browserclass *thebrowserclass) {
+  // can't add a null browserclass
+  assert (thebrowserclass != NULL);
+  if (thebrowserclass == NULL) return;
+  
+  // can't add a browserclass with no name
+  assert (!(thebrowserclass->get_browser_name()).empty());
+  if ((thebrowserclass->get_browser_name()).empty()) return;
+
+  browserptr aptr;
+  aptr.b = thebrowserclass;
+  browserptrs[thebrowserclass->get_browser_name()] = aptr;
+}
+
+// getbrowser will return the default browser if the browser 
+// could not be found
+browserclass *browsermapclass::getbrowser (const text_t &key) {
+  // can't find a browser with no name
+  if (key.empty()) return get_default_browser();
+
+  iterator here = browserptrs.find (key);
+  if (here == browserptrs.end()) return get_default_browser();
+  
+  return (*here).second.b;
+}
+
+browserclass *browsermapclass::clonebrowser (const text_t &key) {
+  browserclass *browser = NULL;
+  if (key.empty()) {
+    browser = get_default_browser();
+  } else {
+    iterator here = browserptrs.find (key);
+    if (here == browserptrs.end()) 
+      browser = get_default_browser();
+    else
+      browser = here->second.b;
+  }
+  if (browser != NULL) {
+    browser = browser->clone();
+  }
+  return browser;
+}
+
+void browsermapclass::setdefaultbrowser (const text_t &browsername) {
+  defaultbrowser = browsername;
+}
+
+browserclass *browsermapclass::get_default_browser () {
+
+  iterator here = browserptrs.find (defaultbrowser);
+  if (here == browserptrs.end())
+    // we'll just take the first in the list if
+    // no valid default was set
+    here = browserptrs.begin();
+  return (*here).second.b;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/browserclass.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/browserclass.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/browserclass.h	(revision 16571)
@@ -0,0 +1,187 @@
+/**********************************************************************
+ *
+ * browserclass.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+
+#ifndef BROWSERCLASS_H
+#define BROWSERCLASS_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "cgiargs.h"
+#include "display.h"
+#include "recptproto.h"
+#include "formattools.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+#endif
+
+
+class browserclass {
+protected:
+
+public:
+  browserclass ();
+  virtual ~browserclass ();
+
+  // configure should be called once for each configuration line
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+
+  // init should be called after all the configuration is done but
+  // before any other methods are called
+  virtual bool init (ostream &logout);
+
+  virtual browserclass* clone() = 0;
+
+  // returns the name that specifies the browserclass type
+  virtual text_t get_browser_name ();
+  
+  virtual void processOID (cgiargsclass &args, recptproto *collectproto, ostream &logout);
+  
+  // load_metadata_defaults should be called before
+  // doing protocol call to get metadata for OID to
+  // be displayed by this browserclass. it adds fields
+  // to the metadata set that are needed by browserclass
+  // during display
+  virtual void load_metadata_defaults (text_tset &metadata);
+
+  virtual text_t get_default_formatstring ();
+
+  void set_filter_options (FilterRequest_t &request, cgiargsclass &args);
+  
+  // output_section_group returns the number of tabs to add before displaying the
+  // next section group
+  // The first version takes one result of a search/query action, the
+  // second takes all the results; ResultDocInfo_t is actually a child struct
+  // of FilterResponse_t items.  The second version tends to output parts of an
+  // abstract structure (e.g. for a table of contents/classifier list, the first
+  // for an individual document
+  virtual int output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
+				    const text_t &collection, int colnumber, 
+				    format_t *formatlistptr, bool use_table, 
+				    text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, 
+				    ostream &logout);
+
+  virtual int output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
+				    const text_t &labels, const text_t &collection, int colnumber, 
+				    format_t *formatlistptr, bool use_table, 
+				    text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, 
+				    ostream &logout);
+
+  virtual int output_section_group (FilterResponse_t &sections, cgiargsclass &args,
+				    const text_t &collection, int colnumber, 
+				    format_t *formatlistptr, bool use_table, 
+				    text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, 
+				    ostream &logout);
+
+  virtual int output_section_group (FilterResponse_t &sections, cgiargsclass &args,
+				    const text_t& currentSection, const text_t &labels,
+				    const text_t &collection, int colnumber, 
+				    format_t *formatlistptr, bool use_table, 
+				    text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, 
+				    ostream &logout);
+};
+
+
+// The browserptr function does not 'own' the browser. The 
+// browser should be deleted by the code which created it.
+class browserptr {
+public:
+  browserclass *b;
+
+  browserptr () {b=NULL;}
+};
+
+bool operator==(const browserptr &x, const browserptr &y);
+bool operator<(const browserptr &x, const browserptr &y);
+
+typedef map<text_t, browserptr, lttext_t> browserptrmap;
+
+// contains a list of browsers indexed by their name
+class browsermapclass {
+protected:
+  browserptrmap browserptrs;
+  text_t defaultbrowser;
+
+public:
+  // type support for browserptrmap
+  typedef browserptrmap::iterator iterator;
+  typedef browserptrmap::const_iterator const_iterator;
+  typedef browserptrmap::reference reference;
+  typedef browserptrmap::const_reference const_reference;
+  typedef browserptrmap::size_type size_type;
+
+  typedef browserptrmap::difference_type difference_type;
+  typedef browserptrmap::const_reverse_iterator const_reverse_iterator;
+  typedef browserptrmap::reverse_iterator reverse_iterator;
+  
+  // basic container support
+  iterator begin () {return browserptrs.begin();}
+  const_iterator begin () const {return browserptrs.begin();}
+  iterator end () {return browserptrs.end();}
+  const_iterator end () const {return browserptrs.end();}
+
+  void erase(iterator pos) {browserptrs.erase(pos);}
+  void erase(iterator first, iterator last) {browserptrs.erase(first, last);}
+  browsermapclass &operator=(const browsermapclass &x) {browserptrs=x.browserptrs;return *this;}
+
+  bool empty () const {return browserptrs.empty();}
+  size_type size() const {return browserptrs.size();}
+
+
+  // added functionality
+  void clear () {browserptrs.erase(browserptrs.begin(),browserptrs.end());}
+
+  // thebrowserclass remains the property of the calling code but
+  // should not be deleted until it is removed from this list.
+  void addbrowser (browserclass *thebrowserclass);
+
+  // getbrowser will return NULL if the browser could not be found
+  browserclass *getbrowser (const text_t &key);
+
+  // clone a browser; if not default and browser not found will return NULL
+  browserclass *clonebrowser (const text_t &key);
+
+  void setdefaultbrowser (const text_t &browsername);
+
+  browserclass *get_default_browser ();
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/browsetoolsclass.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/browsetoolsclass.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/browsetoolsclass.cpp	(revision 16571)
@@ -0,0 +1,921 @@
+
+/**********************************************************************
+ *
+ * browsetools.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
+ *
+ *********************************************************************/
+
+#include "browsetoolsclass.h"
+#include "recptprototools.h"
+#include "OIDtools.h"
+#include "gsdlunicode.h"
+
+#if defined(GSDL_USE_IOS_H)
+#  if defined(__WIN32__)
+#    include <strstrea.h> // vc4
+#  else
+#    include <strstream.h>
+#  endif
+#else
+#  include <sstream>
+#endif
+
+
+browsetoolsclass::browsetoolsclass()
+{
+}
+
+browsetoolsclass::~browsetoolsclass()
+{
+}
+
+// output_controls displays the detach, expand/contract contents,
+// expand/contract text and highlighting/no highlighting buttons
+
+void browsetoolsclass::output_controls(cgiargsclass &args, const text_tarray &ibuttons,
+                                       recptproto *collectproto, displayclass &disp, 
+                                       outconvertclass &outconvert, ostream &textout, 
+                                       ostream &logout)
+{
+  if (args["u"] != "1") {
+    
+    FilterResponse_t response;
+    text_tarray metadata;
+    text_tarray buttons;
+    
+    text_tarray::const_iterator here = ibuttons.begin();
+    text_tarray::const_iterator end = ibuttons.end();
+    
+    while (here != end) {
+      
+      if (*here == "Detach")
+	buttons.push_back ("_document:imagedetach_");
+      else if(*here == "Print")
+        buttons.push_back ("_document:imageprint_"); 
+      else if (*here == "Highlight") {
+	if (args["hl"] == "1") 
+	  buttons.push_back ("_document:imagenohighlight_");
+	else 
+	  buttons.push_back ("_document:imagehighlight_");
+      } else if (*here == "Expand Contents") {
+	if (args["gc"] == "1")
+	  buttons.push_back ("_document:imagecontracttoc_");
+	else 
+	  buttons.push_back ("_document:imageexpandtoc_");
+      } else if (*here == "Expand Text") {
+	if (args.getintarg("gt"))
+	  buttons.push_back ("_document:imagecontracttext_");
+	else 
+	  buttons.push_back ("_document:imageexpandtext_");
+      }
+      ++here;
+    }
+    
+    here = buttons.begin();
+    end = buttons.end();
+    while (here != end) {
+      textout << outconvert << disp << *here;
+      ++here;
+    }
+  }
+}
+
+text_t browsetoolsclass::get_cover_image()
+{
+  return "_httpprefix_/collect/[collection]/index/assoc/{Or}{[parent(Top):archivedir],[archivedir]}/cover.jpg";
+}
+
+// at the moment this just writes out the html to display 
+// the cover image (assuming it's called cover.jpg)
+// this whole thing should be done with a call to the collection
+// server which would send a link to the cover image if there
+// was one otherwise send title, author and stuff
+void browsetoolsclass::output_cover_image(cgiargsclass &args, recptproto *collectproto, 
+                                          displayclass &disp, outconvertclass &outconvert, 
+                                          ostream &textout, ostream &logout)
+{
+  if (args["d"].empty()) return;
+  
+  textout << outconvert << disp << "_document:coverimage_";
+}
+
+void browsetoolsclass::output_titles(cgiargsclass &args, recptproto *collectproto, 
+                                     browsermapclass *browsermap, formatinfo_t &formatinfo,
+                                     displayclass &disp, outconvertclass &outconvert,
+                                     ostream &textout, ostream &logout)
+{
+  if (args["d"].empty()) return;
+  
+  text_tset metadata;
+  bool getParents;
+  FilterResponse_t response;
+
+  format_t *formatlistptr = new format_t();
+  parse_formatstring (formatinfo.DocumentHeading, formatlistptr, metadata, getParents);
+
+  if (!get_info (args["d"], args["c"], args["l"], metadata, getParents, collectproto, response, logout))
+    return;
+
+  text_tmap options;
+  if (formatinfo.AllowExtendedOptions) {
+    load_extended_options(options, args, browsermap, formatinfo, 
+			  collectproto, disp, outconvert, logout);
+  }
+  textout << outconvert << disp 
+	  << get_formatted_string (args["c"],collectproto, response.docInfo[0], disp,
+				   formatlistptr, options, logout);
+}
+
+void browsetoolsclass::recurse_contents(ResultDocInfo_t &section, cgiargsclass &args, bool fulltoc,
+                                        browserclass *bptr, text_tset &metadata, bool &getParents, 
+                                        format_t *formatlistptr, format_tmap &formatlistmap, 
+                                        formatinfo_t &formatinfo, browsermapclass *browsermap, 
+                                        int tabcount, recptproto *collectproto, displayclass &disp, 
+                                        outconvertclass &outconvert, ostream &textout, ostream &logout)
+{
+  text_t formatstring;
+
+  bool is_classify = false;
+  if (args["d"].empty() || fulltoc) is_classify = true;
+
+  // output this section 
+  bool use_table = is_table_content (formatlistptr);
+  tabcount += bptr->output_section_group (section, args, args["c"], tabcount, formatlistptr, use_table, 
+					  metadata, getParents, collectproto, disp, outconvert, 
+					  textout, logout);
+
+  text_t classification;
+  if (!is_classify) classification = "Document";
+  else get_top (args["cl"], classification);
+
+  int haschildren = section.metadata["haschildren"].values[0].getint();
+  const text_t &doctype = section.metadata["doctype"].values[0];
+  text_t classifytype = section.metadata["childtype"].values[0];
+  // HLists and DateLists are displayed as VLists when contents 
+  // are expanded, Paged documents are displayed as HLists
+  if (classifytype == "HList" || classifytype == "DateList") classifytype = "VList";
+  if (classifytype == "Paged") classifytype = "HList";
+
+  // recurse through children
+  if ((haschildren == 1) && (!is_classify || fulltoc || doctype == "classify")) {
+
+    // get browser for displaying children
+    bptr = browsermap->getbrowser (classifytype);
+    bptr->load_metadata_defaults (metadata);
+
+    // get the formatstring if there is one 
+    if (!get_formatstring (classification, classifytype, 
+			   formatinfo.formatstrings, formatstring))
+      formatstring = bptr->get_default_formatstring();
+
+    format_tmap::const_iterator it = formatlistmap.find (formatstring);
+    // check if formatlistptr is cached
+    if (it != formatlistmap.end()) formatlistptr = (*it).second;
+    else {
+      formatlistptr = new format_t();
+      parse_formatstring (formatstring, formatlistptr, metadata, getParents);
+      formatlistmap[formatstring] = formatlistptr;
+    }
+
+    FilterResponse_t tmp;
+    get_children (section.OID, args["c"], args["l"], metadata, getParents, collectproto, tmp, logout);
+    ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
+    ResultDocInfo_tarray::iterator lastdoc = tmp.docInfo.end();
+
+    while (thisdoc != lastdoc) {
+      recurse_contents (*thisdoc, args, fulltoc, bptr, metadata, getParents, 
+			formatlistptr, formatlistmap, formatinfo, browsermap, 
+			tabcount, collectproto, disp, outconvert, textout, logout);
+      ++thisdoc;
+    }
+  }
+}
+
+
+// expanded_contents recurses through all contents. there's a special case
+// for an HList when contents are expanded (i.e. it's displayed as a VList)
+//
+// if we're inside a document we expand all contents from the top (unless
+// expand_from_current_level is true), if we're at classification level we'll just
+// expand out those contents below the current one
+
+void browsetoolsclass::expanded_contents(cgiargsclass &args, int tabcount, bool fulltoc,
+                                         browsermapclass *browsermap, formatinfo_t &formatinfo, 
+                                         recptproto *collectproto, displayclass &disp, 
+                                         outconvertclass &outconvert, ostream &textout, 
+                                         ostream &logout, bool expand_from_current_level)
+{
+  if (args["d"].empty() && args["cl"].empty()) return;
+  text_t OID;
+  
+  FilterResponse_t response;
+  bool getParents = false;
+  text_tset metadata;
+  text_t classifytype, classification, formatstring;
+
+  if (!args["d"].empty())
+    {
+      // document level
+      if (fulltoc)
+        {
+          get_top(args["cl"], OID);
+          classification = OID;
+        }
+      else 
+        {
+          classification = "Document";
+          if (expand_from_current_level)
+            {
+              OID = args["d"];
+            }
+          else
+            {
+              // Always expand document level from top, unless
+              // expand_from_current_level is true.
+              get_top(args["d"], OID);
+            }
+        }
+    }
+  else
+    {
+      // classification level
+      OID = args["cl"];
+      get_top(args["cl"], classification);
+    }
+
+  // get classifytype of this level
+  text_t tOID;
+  if (is_top(OID)) {
+    classifytype = "thistype";
+    tOID = OID;
+  } else {
+    classifytype = "childtype";
+    tOID = get_parent (OID);
+  }
+  metadata.insert (classifytype);
+
+  if (!get_info (tOID, args["c"], args["l"], metadata, getParents, collectproto, response, logout))
+    return;
+  classifytype = response.docInfo[0].metadata[classifytype].values[0];
+  // if we still don't have a classifytype we'll use the default
+  if (classifytype.empty()) {
+    browserclass *bptr = browsermap->get_default_browser ();
+    classifytype = bptr->get_browser_name ();
+  }
+
+  // HLists are displayed as VLists when contents are expanded,
+  // Paged documents are displayed as HLists
+  if (classifytype == "HList") {
+    classifytype = "VList";
+    text_t pOID = get_parent (OID);
+    if (!pOID.empty()) {
+      OID = pOID;
+      // this is assuming that top levels are always 'Invisible' !!!
+      if (is_top (OID)) classifytype = "Invisible";
+    }
+  }
+  if (classifytype == "Paged") classifytype = "HList";
+
+  metadata.erase (metadata.begin(), metadata.end());
+		  
+  // metadata elements needed by recurse_contents
+  metadata.insert ("childtype");
+  metadata.insert ("doctype");
+  metadata.insert ("haschildren");
+
+  // load up metadata array with browser defaults
+  browserclass *bptr = browsermap->getbrowser (classifytype);
+  bptr->load_metadata_defaults (metadata);
+
+  // get the formatstring if there is one or use the browsers default
+  if (!get_formatstring (classification, classifytype, 
+			 formatinfo.formatstrings, formatstring))
+    formatstring = bptr->get_default_formatstring();
+
+  format_t *formatlistptr = new format_t();
+  parse_formatstring (formatstring, formatlistptr, metadata, getParents);
+
+  // protocol call
+  if (!get_info (OID, args["c"], args["l"], metadata, getParents, collectproto, response, logout))
+    return;
+
+  format_tmap formatlistmap;
+  formatlistmap[formatstring] = formatlistptr;
+
+  recurse_contents (response.docInfo[0], args, fulltoc, bptr, metadata, 
+		    getParents, formatlistptr, formatlistmap, formatinfo, browsermap, 
+		    tabcount, collectproto, disp, outconvert, textout, logout);
+
+  // clean up format list pointers
+  format_tmap::const_iterator here = formatlistmap.begin();
+  format_tmap::const_iterator end = formatlistmap.end();
+  while (here != end) {
+    delete (*here).second;
+    ++here;
+  }
+}
+
+void browsetoolsclass::load_formatstring(const text_t &classifytype, text_tset &metadata,
+                                         bool &getParents, const text_t &classification, 
+                                         browsermapclass *browsermap, formatinfo_t &formatinfo,
+                                         format_tmap &formatlistmap)
+{
+  text_t formatstring;
+
+  // load up metadata array with browser defaults
+  browserclass *bptr = browsermap->getbrowser (classifytype);
+  bptr->load_metadata_defaults (metadata);
+
+  // get the formatstring if there is one or use the browsers default
+  if (!get_formatstring (classification, classifytype, 
+			 formatinfo.formatstrings, formatstring))
+    formatstring = bptr->get_default_formatstring();
+
+  // see if it's cached
+  format_tmap::const_iterator it = formatlistmap.find (formatstring);
+  if (it == formatlistmap.end()) {
+    format_t *formatlistptr = new format_t();
+    parse_formatstring (formatstring, formatlistptr, metadata, getParents);
+    formatlistmap[formatstring] = formatlistptr;
+  }
+}
+
+void browsetoolsclass::load_formatstrings(FilterResponse_t &response, text_tset &metadata,
+                                          bool &getParents, const text_t &classification,
+                                          browsermapclass *browsermap, formatinfo_t &formatinfo, 
+                                          format_tmap &formatlistmap)
+{
+  text_tset cache;
+
+  ResultDocInfo_tarray::iterator thisdoc = response.docInfo.begin();
+  ResultDocInfo_tarray::iterator lastdoc = response.docInfo.end();
+
+  while (thisdoc != lastdoc) {
+
+    if (is_top ((*thisdoc).OID)) {
+      load_formatstring ((*thisdoc).metadata["thistype"].values[0], metadata, 
+			 getParents, classification, browsermap, formatinfo, 
+			 formatlistmap);
+    }
+    
+    // sometimes childtype is not set - why??
+    if ((*thisdoc).metadata.find("childtype") != (*thisdoc).metadata.end()) {
+      text_t &childtype = (*thisdoc).metadata["childtype"].values[0];
+
+      text_tset::const_iterator it = cache.find (childtype);
+      if (it == cache.end()) {
+	load_formatstring (childtype, metadata, getParents, classification,
+			   browsermap, formatinfo, formatlistmap);
+	cache.insert (childtype);
+      }
+    }
+    ++thisdoc;
+  }
+}
+
+void browsetoolsclass::output_parents(FilterResponse_t &response, cgiargsclass &args, 
+                                      browsermapclass *browsermap, formatinfo_t &formatinfo, 
+                                      format_tmap &formatlistmap, const text_t &classification,
+                                      int &tabcount, text_tset &metadata, bool &getParents,
+                                      recptproto *collectproto, displayclass &disp, 
+                                      outconvertclass &outconvert, ostream &textout, 
+                                      ostream &logout)
+{
+  format_t *formatlistptr = NULL;
+  text_t classifytype, formatstring;
+  bool use_table, first = true;
+  ResultDocInfo_tarray::iterator thisparent = response.docInfo.begin();
+  ResultDocInfo_tarray::iterator lastparent = response.docInfo.end();
+  while (thisparent != lastparent) {
+
+    // get classifytype of this level
+    if (is_top ((*thisparent).OID)) classifytype = (*thisparent).metadata["thistype"].values[0];
+    else if (!first && (*(thisparent-1)).metadata.find("childtype") != (*(thisparent-1)).metadata.end()) classifytype = (*(thisparent-1)).metadata["childtype"].values[0];
+    
+    // if we still don't have a classifytype we'll use the default
+    if (classifytype.empty()) {
+      browserclass *bptr = browsermap->get_default_browser ();
+      classifytype = bptr->get_browser_name ();
+    }
+    
+    browserclass *bptr = browsermap->getbrowser (classifytype);
+
+    // get the formatstring if there is one or use the browsers default
+    if (!get_formatstring (classification, classifytype, 
+			   formatinfo.formatstrings, formatstring))
+      formatstring = bptr->get_default_formatstring();
+    
+    // see if it's cached
+    format_tmap::const_iterator it = formatlistmap.find (formatstring);
+    if (it != formatlistmap.end()) formatlistptr = (*it).second;
+    else {
+      logout << "browsetools error\n";
+      return;
+    }
+    
+    use_table = is_table_content (formatlistptr);
+    tabcount += bptr->output_section_group (*thisparent, args, args["c"], tabcount, formatlistptr, 
+					    use_table, metadata, getParents, collectproto, 
+					    disp, outconvert, textout, logout);
+    first = false;
+    ++thisparent;
+  }
+}
+
+void browsetoolsclass::contracted_contents(cgiargsclass &args, int tabcount, bool fulltoc, 
+                                           browsermapclass *browsermap, formatinfo_t &formatinfo, 
+                                           recptproto *collectproto, displayclass &disp, 
+                                           outconvertclass &outconvert, ostream &textout, 
+                                           ostream &logout)
+{
+  FilterResponse_t response;
+  text_tset metadata;
+  bool getParents = false;
+  text_t formatstring;
+  text_tarray parents;
+  text_t OID = args["d"];
+  text_t classification = "Document";
+
+  // if we're not outputting the TOC for a valid OID, then we should be giving
+  // the TOC of a classification
+  if (OID.empty()) {
+    OID = args["cl"];
+    get_top (OID, classification);
+  } 
+  // if we're to give the full TOC of a document, get the parent for the whole
+  // document now
+  else if (fulltoc)
+    get_top (args["cl"], classification);    
+
+  bool haschildren = has_children (OID, args["c"], args["l"], collectproto, logout);
+
+  if ((!args["d"].empty()) && fulltoc)
+    get_parents_array (args["cl"] + ".fc", parents);
+  if (haschildren) get_parents_array (OID + ".fc", parents);
+  else get_parents_array (OID, parents);
+
+  if (!parents.empty()) {
+    // get classifytypes of each parent
+    metadata.insert ("thistype");
+    metadata.insert ("childtype");
+    metadata.insert("mdtype");
+    
+    if (!get_info (parents, args["c"], args["l"], metadata, getParents, collectproto, response, logout))
+      return;
+    
+    // get formatstrings for all parents
+    format_tmap formatlistmap;  
+    load_formatstrings (response, metadata, getParents, classification, 
+			browsermap, formatinfo, formatlistmap);
+
+    if (!get_info (parents, args["c"], args["l"], metadata, getParents, collectproto, response, logout))
+      return;
+    
+    // display each parent
+    output_parents (response, args, browsermap, formatinfo, formatlistmap, 
+		    classification, tabcount, metadata, getParents, 
+		    collectproto, disp, outconvert, textout, logout);
+    
+    metadata.erase (metadata.begin(), metadata.end());
+    
+    // clean up cached format list pointers
+    format_tmap::const_iterator here = formatlistmap.begin();
+    format_tmap::const_iterator end = formatlistmap.end();
+    while (here != end) {
+      delete (*here).second;
+      ++here;
+    }
+  }
+
+  // get childrens classifytype
+  text_t classifytype;
+  int numparents = response.docInfo.size();
+  if (!parents.empty() && (response.docInfo[numparents-1].metadata.find("childtype") != response.docInfo[numparents-1].metadata.end()))
+    classifytype = response.docInfo[numparents-1].metadata["childtype"].values[0];
+  else {
+    // use the default
+    browserclass *bptr = browsermap->get_default_browser ();
+    classifytype = bptr->get_browser_name ();
+  }
+    
+  // load up metadata array with browser defaults
+  browserclass *bptr = browsermap->getbrowser (classifytype);
+  bptr->load_metadata_defaults (metadata);
+
+  if (classifytype == "DateList") {
+    // get the mdtype
+    text_t datelist = "Date";
+    if (!parents.empty() && (response.docInfo[0].metadata.find("mdtype") != response.docInfo[0].metadata.end())) {
+      datelist = response.docInfo[0].metadata["mdtype"].values[0];
+    }
+    args.setarg("dm", datelist);
+    text_tarray dates;
+    splitchar(datelist.begin(), datelist.end(), ',', dates);
+    text_tarray::iterator begin = dates.begin();
+    text_tarray::iterator end = dates.end();
+    while (begin!= end) {
+      metadata.insert(*begin);
+      begin++;
+    }
+    
+  }
+
+  // get the formatstring if there is one or use the browsers default
+  if (!get_formatstring (classification, classifytype, 
+			 formatinfo.formatstrings, formatstring))
+    formatstring = bptr->get_default_formatstring();
+
+  format_t *formatlistptr = new format_t();
+  parse_formatstring (formatstring, formatlistptr, metadata, getParents);
+
+  if (haschildren) 
+    get_children (OID, args["c"], args["l"], metadata, getParents,
+		  collectproto, response, logout);
+  else if (!is_top(OID)) {
+    get_children (OID + ".pr", args["c"], args["l"], metadata, getParents, 
+		  collectproto, response, logout);
+    haschildren = true;
+  }
+
+  // display children
+  if (haschildren) {
+    bool use_table = is_table_content (formatlistptr);
+    bptr->output_section_group (response, args, args["c"], tabcount, formatlistptr, use_table, 
+				metadata, getParents, collectproto, disp, outconvert, 
+				textout, logout);
+  }
+  delete formatlistptr;
+}
+
+/**
+ * This function outputs contents of a classifier to the reader
+ * including parent levels
+ */
+void browsetoolsclass::expand_show_contents(cgiargsclass &args, int tabcount, bool fulltoc,
+                                            browsermapclass *browsermap, formatinfo_t &formatinfo,
+                                            recptproto *collectproto, displayclass &disp,
+                                            outconvertclass &outconvert, ostream &textout, 
+                                            ostream &logout)
+{
+  int coloffset = 0;
+  text_tarray parents;
+  FilterResponse_t response;
+  text_t OID = args["d"];
+  if (OID.empty()) OID = args["cl"];
+
+  bool haschildren = has_children(OID, args["c"], args["l"], collectproto, logout);
+
+  // get parents list
+  if (!is_top(OID)) get_parents_array(OID, parents);
+  if (args["d"].empty() || haschildren || parents.empty()) parents.push_back(OID);
+
+  // if inside a book top title is needed
+  if (!args["d"].empty())
+    {
+      coloffset = 1;
+      text_t classification, classifytype, formatstring, topOID = parents[0];
+      text_tset metadata;
+      format_t *formatlistptr = new format_t();
+      bool use_table, getParents = false;
+		
+      get_top(args["cl"], classification);
+
+      // getting information about top OID
+      metadata.insert("thistype");
+
+      get_info(topOID, args["c"], args["l"], metadata, getParents, collectproto, response, logout);
+      if (!response.docInfo[0].metadata["thistype"].values.empty()) 
+        {
+          classifytype = response.docInfo[0].metadata["thistype"].values[0];
+        }
+
+      browserclass *bptr = browsermap->getbrowser (classifytype);
+
+      if (classifytype.empty())
+        {
+          bptr = browsermap->get_default_browser();
+        }
+
+      // get the formatstring if there is one or use the browsers default
+      if (!get_formatstring(classification, classifytype, formatinfo.formatstrings, formatstring))
+        {
+          formatstring = bptr->get_default_formatstring();
+        }
+
+      parse_formatstring(formatstring, formatlistptr, metadata, getParents);
+
+      metadata.insert("doctype");
+      metadata.insert("haschildren");
+
+      get_info(topOID, args["c"], args["l"], metadata, getParents, collectproto, response, logout);
+
+      // ouput top OID section
+      use_table = is_table_content(formatlistptr);
+      bptr->output_section_group(response.docInfo[0], args, args["c"], tabcount, formatlistptr, use_table,
+                                 metadata, getParents, collectproto, disp, outconvert, textout, logout);
+    }
+
+  recurse_contents_levels(parents, args, coloffset, tabcount, fulltoc, browsermap, 
+                          formatinfo, collectproto, disp, outconvert, textout, logout);
+}
+
+void browsetoolsclass::recurse_contents_levels(text_tarray &parents, cgiargsclass &args, int coloffset, int tabcount,
+                                               bool fulltoc, browsermapclass *browsermap, formatinfo_t &formatinfo,
+                                               recptproto *collectproto, displayclass &disp, outconvertclass &outconvert,
+                                               ostream &textout, ostream &logout)
+{
+  FilterResponse_t response;
+  text_tset metadata;
+  text_t OID, formatstring, classification, classifytype;;
+  bool use_table, getParents = false;
+  int haschildren = 0;
+  format_t *formatlistptr = new format_t();
+
+  // display children for last level
+  if (tabcount == (parents.size() - 1))
+    {
+      // setting metadata fields 
+      metadata.insert ("thistype");
+      metadata.insert ("childtype");
+      metadata.insert ("haschildren");
+
+      OID = parents[tabcount];
+      get_info(OID, args["c"], args["l"], metadata, getParents, collectproto, response, logout);
+      get_top(OID, classification);
+
+      if (!response.docInfo.empty())
+        {
+          haschildren = response.docInfo[0].metadata["haschildren"].values[0].getint();
+        }
+
+      // get childrens classifytype
+      if (!response.docInfo.empty())
+        {
+          classifytype = response.docInfo[0].metadata["childtype"].values[0];
+        }
+      else
+        {
+          // use the default
+          browserclass *bptr = browsermap->get_default_browser();
+          classifytype = bptr->get_browser_name();
+        }
+
+      // load up metadata array with browser defaults
+      browserclass *bptr = browsermap->getbrowser(classifytype);
+      bptr->load_metadata_defaults(metadata);
+
+      // get the formatstring if there is one or use the browsers default
+      if (!get_formatstring(classification, classifytype, formatinfo.formatstrings, formatstring))
+        {
+          formatstring = bptr->get_default_formatstring();
+        }
+
+      parse_formatstring(formatstring, formatlistptr, metadata, getParents);
+
+      if (haschildren) 
+        {
+          get_children(OID, args["c"], args["l"], metadata, getParents,
+                       collectproto, response, logout);
+        }
+      else if (!is_top(OID))
+        {
+          get_children(OID + ".pr", args["c"], args["l"], metadata, getParents, 
+                       collectproto, response, logout);
+          haschildren = true;
+        }
+
+      // display children
+      if (haschildren)
+        {
+          use_table = is_table_content (formatlistptr);
+          bptr->output_section_group(response, args, args["c"], coloffset + tabcount, formatlistptr, use_table, 
+                                     metadata, getParents, collectproto, disp, outconvert, textout, logout);
+        }
+    }
+  else
+    {
+      text_t pOID;
+      OID = parents[tabcount];
+      get_top(OID, classification);
+
+      // load metadata fields
+      metadata.insert("thistype");
+      metadata.insert("childtype");
+      metadata.insert("haschildren");
+      metadata.insert("doctype");
+
+      if (tabcount) pOID = parents[tabcount-1];
+      else pOID = OID;
+      get_info(pOID, args["c"], args["l"], metadata, getParents, collectproto, response, logout);
+
+      // get classifytype of this level
+      if (is_top (pOID)) classifytype = response.docInfo[0].metadata["childtype"].values[0];
+      else classifytype = response.docInfo[0].metadata["thistype"].values[0];
+
+      // if we still don't have a classifytype we'll use the default
+      if (classifytype.empty())
+        {
+          browserclass *bptr = browsermap->get_default_browser();
+          classifytype = bptr->get_browser_name();
+        }
+
+      browserclass *bptr = browsermap->getbrowser (classifytype);
+
+      // get the formatstring if there is one or use the browsers default
+      if (!get_formatstring (classification, classifytype, formatinfo.formatstrings, formatstring))
+        {
+          formatstring = bptr->get_default_formatstring();
+        }
+
+      // parse format string 
+      parse_formatstring(formatstring, formatlistptr, metadata, getParents);
+
+      use_table = is_table_content(formatlistptr);
+
+      get_children(OID, args["c"], args["l"], metadata, getParents, collectproto, response, logout);
+
+      ResultDocInfo_tarray::iterator thissibling = response.docInfo.begin();
+      ResultDocInfo_tarray::iterator lastsibling = response.docInfo.end();
+
+      while (thissibling != lastsibling)
+        {
+          bptr->output_section_group(*thissibling, args, args["c"], coloffset + tabcount, formatlistptr, 
+                                     use_table, metadata, getParents, collectproto, 
+                                     disp, outconvert, textout, logout);
+			
+          if ((*thissibling).OID == parents[tabcount+1])
+            {
+              recurse_contents_levels(parents, args, coloffset, tabcount+1, fulltoc, browsermap,
+                                      formatinfo, collectproto, disp, outconvert,textout, logout);
+            }
+          ++thissibling;
+        }
+    }
+  delete formatlistptr;
+}
+
+/**
+ * This function outputs the contents of a classifier list to the reader - 
+ * the document will in fact be empty, so this does the "real" output
+ */
+void browsetoolsclass::output_toc(cgiargsclass &args, browsermapclass *browsermap,
+                                  formatinfo_t &formatinfo, recptproto *collectproto,
+                                  displayclass &disp, outconvertclass &outconvert,
+                                  ostream &textout, ostream &logout)
+{
+  if (!args["d"].empty() && formatinfo.AllowExtendedOptions) {
+    // If AllowExtendedOptions is set and we're viewing a document,
+    // DocumentButtons, DocumentContent, and DocumentImages are effectively
+    // disabled. We just output the DocumentHeading format string and
+    // return
+    output_titles(args, collectproto, browsermap, formatinfo, disp, outconvert, textout, logout);    
+    return;
+  }
+
+  int tabcount = 0;
+  bool fulltoc = false;
+  text_t cl_top, full_toc;
+  if (args["cl"] != "search") {
+    // see if there's a FullTOC string
+    get_top (args["cl"], cl_top);
+    if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
+      if (full_toc == "true") fulltoc = true;
+  }
+  
+  // get the cover image (if there is one) and the control buttons
+  // if we're inside a book
+  if ((!fulltoc) && (!args["d"].empty())) {
+    if (formatinfo.DocumentImages) {
+      textout << outconvert << "<div class=\"heading_image\">\n";
+      output_cover_image(args, collectproto, disp, outconvert, textout, logout);
+      textout << outconvert << "</div>\n";
+    } else if (formatinfo.DocumentTitles) {
+      textout << outconvert << "<div class=\"heading_title\">\n";
+      output_titles(args, collectproto, browsermap, formatinfo, disp, outconvert, textout, logout);
+      textout << outconvert << "</div>\n";
+    }
+    textout << outconvert << "<div class=\"buttons\" id=\"toc_buttons\">\n"; 
+    if (args["u"] != "1") {
+      output_controls (args, formatinfo.DocumentButtons, collectproto, disp, 
+		       outconvert, textout, logout);
+    }
+    textout << outconvert << "</div>\n\n"; 
+  }
+
+  if (formatinfo.DocumentContents || args["d"].empty()) {
+    if (args["d"].empty()) {
+      disp.setmacro("tocopenextra", "document", "id=\"" + cl_top + "\"");
+    } else {
+      disp.setmacro("tocopenextra", "document", "");
+    }
+
+    textout << outconvert << disp << "_document:tocopen_\n";
+    if (args.getintarg("gc") == 1)
+      {
+        // expanded table of contents
+        expanded_contents(args, tabcount, fulltoc, browsermap, formatinfo, 
+                          collectproto, disp, outconvert, textout, logout, false);
+      }
+    else if (args.getintarg("gc") == 2)
+      {
+        // expand visible levels of table of contents
+        expand_show_contents(args, tabcount, fulltoc, browsermap, formatinfo,
+                             collectproto, disp, outconvert, textout, logout);
+      }
+    else
+      {
+        // contracted table of contents
+        contracted_contents(args, tabcount, fulltoc, browsermap, formatinfo, 
+                            collectproto, disp, outconvert, textout, logout);
+      }
+    textout << outconvert << disp << "_document:tocclose_\n";
+  }
+}
+
+void browsetoolsclass::load_extended_options(text_tmap &options, cgiargsclass &args, browsermapclass *browsers, 
+                                             formatinfo_t &formatinfo, recptproto *collectproto, 
+                                             displayclass &disp, outconvertclass &outconvert, ostream &logout)
+{
+  options["DocImage"] = get_cover_image();
+
+#if defined(GSDL_USE_IOS_H)
+  ostrstream *tmpstr = new ostrstream();
+#else
+  ostringstream *tmpstr = new ostringstream(ostringstream::binary);
+#endif
+
+  if (args["gc"] == "1")
+    {
+      expanded_contents(args, 0, false, browsers, formatinfo, collectproto,
+                        disp, outconvert, *tmpstr, logout, false);
+    }
+  else
+    {
+      contracted_contents(args, 0, false, browsers, formatinfo, 
+                          collectproto, disp, outconvert, *tmpstr, logout);
+    }
+#if defined(GSDL_USE_IOS_H)
+  char *t = tmpstr->str();
+  text_t tmp;
+  tmp.setcarr(t, tmpstr->pcount());
+  delete [] t;
+#else
+  text_t tmp = (char *)(tmpstr->str().c_str());
+#endif
+  int len = tmp.size();
+  char *ctmp = tmp.getcstr();
+  utf8inconvertclass utf82text_t;
+  utf82text_t.setinput(ctmp, len);
+  convertclass::status_t status;
+  utf82text_t.convert(tmp, status);
+  options["DocTOC"] = tmp;
+  delete []ctmp;
+  delete tmpstr;
+
+  options["DocumentButtonDetach"] = "_document:imagedetach_";
+  if (args["hl"] == "1")
+    {
+      options["DocumentButtonHighlight"] = "_document:imagenohighlight_";
+    }
+  else
+    {
+      options["DocumentButtonHighlight"] = "_document:imagehighlight_";
+    }
+  if (args["gc"] == "1")
+    {
+      options["DocumentButtonExpandContents"] = "_document:imagecontracttoc_";
+    }
+  else
+    {
+      options["DocumentButtonExpandContents"] = "_document:imageexpandtoc_";
+    }
+  if (args["gt"] == "1")
+    {
+      options["DocumentButtonExpandText"] = "_document:imagecontracttext_";
+    }
+  else
+    {
+      options["DocumentButtonExpandText"] = "_document:imageexpandtext_";
+    }
+}
Index: /gsdl/trunk/runtime-src/src/recpt/browsetoolsclass.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/browsetoolsclass.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/browsetoolsclass.h	(revision 16571)
@@ -0,0 +1,124 @@
+/**********************************************************************
+ *
+ * browsetools.h --
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef BROWSETOOLSCLASS_H
+#define BROWSETOOLSCLASS_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "cgiargs.h"
+#include "display.h"
+#include "recptproto.h"
+#include "formattools.h"
+#include "browserclass.h"
+
+class browsetoolsclass
+{
+public:
+  
+  browsetoolsclass();
+  virtual ~browsetoolsclass();
+
+  virtual void output_toc(cgiargsclass &args, browsermapclass *browsermap,
+                          formatinfo_t &formatinfo, recptproto *collectproto,
+                          displayclass &disp, outconvertclass &outconvert,
+                          ostream &textout, ostream &logout);
+
+  virtual text_t get_cover_image();
+
+  virtual void load_extended_options(text_tmap &options, cgiargsclass &args, browsermapclass *browsers, 
+                                     formatinfo_t &formatinfo, recptproto *collectproto, 
+                                     displayclass &disp, outconvertclass &outconvert, ostream &logout);
+
+  virtual void expanded_contents(cgiargsclass &args, int tabcount, bool fulltoc,
+                                 browsermapclass *browsermap, formatinfo_t &formatinfo, 
+                                 recptproto *collectproto, displayclass &disp, 
+                                 outconvertclass &outconvert, ostream &textout, 
+                                 ostream &logout, bool expand_from_current_level);
+
+  virtual void expand_show_contents(cgiargsclass &args, int tabcount, bool fulltoc,
+                                    browsermapclass *browsermap, formatinfo_t &formatinfo, 
+                                    recptproto *collectproto, displayclass &disp, 
+                                    outconvertclass &outconvert, ostream &textout, 
+                                    ostream &logout);
+
+  virtual void contracted_contents(cgiargsclass &args, int tabcount, bool fulltoc, 
+                                   browsermapclass *browsermap, formatinfo_t &formatinfo, 
+                                   recptproto *collectproto, displayclass &disp, 
+                                   outconvertclass &outconvert, ostream &textout, 
+                                   ostream &logout);
+
+protected:
+
+  typedef map<text_t, format_t*, lttext_t> format_tmap; 
+
+  virtual void recurse_contents_levels(text_tarray &parents, cgiargsclass &args, int coloffset,
+                                       int tabcount, bool fulltoc, browsermapclass *browsermap,
+                                       formatinfo_t &formatinfo, recptproto *collectproto,
+                                       displayclass &disp, outconvertclass &outconvert,
+                                       ostream &textout, ostream &logout);
+
+  virtual void output_titles(cgiargsclass &args, recptproto *collectproto, 
+                             browsermapclass *browsermap, formatinfo_t &formatinfo,
+                             displayclass &disp, outconvertclass &outconvert,
+                             ostream &textout, ostream &logout);
+
+  virtual void output_controls(cgiargsclass &args, const text_tarray &ibuttons,
+                               recptproto *collectproto, displayclass &disp, 
+                               outconvertclass &outconvert, ostream &textout, 
+                               ostream &logout);
+  
+  virtual void output_cover_image(cgiargsclass &args, recptproto *collectproto, 
+                                  displayclass &disp, outconvertclass &outconvert, 
+                                  ostream &textout, ostream &logout);
+
+  virtual void recurse_contents(ResultDocInfo_t &section, cgiargsclass &args, bool fulltoc,
+                                browserclass *bptr, text_tset &metadata, bool &getParents, 
+                                format_t *formatlistptr, format_tmap &formatlistmap, 
+                                formatinfo_t &formatinfo, browsermapclass *browsermap, 
+                                int tabcount, recptproto *collectproto, displayclass &disp, 
+                                outconvertclass &outconvert, ostream &textout, ostream &logout);
+
+  virtual void load_formatstring(const text_t &classifytype, text_tset &metadata,
+                                 bool &getParents, const text_t &classification, 
+                                 browsermapclass *browsermap, formatinfo_t &formatinfo,
+                                 format_tmap &formatlistmap);
+
+  virtual void load_formatstrings(FilterResponse_t &response, text_tset &metadata,
+                                  bool &getParents, const text_t &classification,
+                                  browsermapclass *browsermap, formatinfo_t &formatinfo, 
+                                  format_tmap &formatlistmap);
+
+  virtual void output_parents(FilterResponse_t &response, cgiargsclass &args, 
+                              browsermapclass *browsermap, formatinfo_t &formatinfo, 
+                              format_tmap &formatlistmap, const text_t &classification,
+                              int &tabcount, text_tset &metadata, bool &getParents,
+                              recptproto *collectproto, displayclass &disp, 
+                              outconvertclass &outconvert, ostream &textout, 
+                              ostream &logout);
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/cgiargs.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/cgiargs.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/cgiargs.cpp	(revision 16571)
@@ -0,0 +1,421 @@
+/**********************************************************************
+ *
+ * cgiargs.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "cgiargs.h"
+#include "gsdlunicode.h"
+
+
+
+void cgiarg_t::clear () {
+  value.clear();
+  source = program_arg;
+  fileupload.clear();
+}
+
+cgiarg_t &cgiarg_t::operator=(const cgiarg_t &x) {
+  value=x.value;
+  source=x.source;
+  return *this;
+}
+
+
+bool operator==(const cgiarg_t &x, const cgiarg_t &y) {
+  return ((x.value == y.value) && (x.source == y.source));
+}
+
+bool operator<(const cgiarg_t &x, const cgiarg_t &y) {
+  return ((x.value < y.value) ||
+	  ((x.value == y.value) && (x.source == y.source)));
+}
+
+
+void fileupload_t::clear() {
+  name.clear();
+  type.clear();
+  size = 0;
+  tmp_name.clear();
+}
+
+ostream &operator<<(ostream &outs, const fileupload_t &fu) {
+  utf8outconvertclass text_t2utf8;
+  outs << "*** fileupload\n";
+  
+  outs << text_t2utf8 << "name=" << fu.name << ", type="<< fu.type<<", size="<<fu.size<<", tmp_name="<<fu.tmp_name<<"\n";
+  return outs;
+}
+
+
+
+// constructors
+cgiargsclass::cgiargsclass () {
+}
+
+
+// this returns NULL if there isn't an entry with a value of
+// 'key' already defined
+
+void cgiargsclass::setarg (const text_t &key, const text_t &value,
+			   cgiarg_t::source_t source) {
+  cgiarg_t temparg;
+  temparg.value = value;
+  temparg.source = source;
+  args[key] = temparg;
+}
+
+void cgiargsclass::setdefaultarg (const text_t &key, const text_t &value,
+				  cgiarg_t::source_t source) {
+  if (getarg(key) == NULL) setarg (key, value, source);
+}
+
+void cgiargsclass::setintarg (const text_t &key, int value,
+			      cgiarg_t::source_t source) {
+  setarg (key, value, source);
+}
+
+void cgiargsclass::setdefaultintarg (const text_t &key, int value,
+				     cgiarg_t::source_t source) {
+  if (getarg(key) == NULL) setintarg (key, value, source);
+}
+
+void cgiargsclass::setcarg (const text_t &key, unsigned short c,
+			    cgiarg_t::source_t source) {
+  text_t t; 
+  t.push_back(c);
+  setarg(key,t, source);
+}
+
+void cgiargsclass::setdefaultcarg (const text_t &key, unsigned short c,
+				   cgiarg_t::source_t source) {
+  if (getarg(key) == NULL) setcarg (key, c, source);
+}
+
+void cgiargsclass::setargfile (const text_t &key, const fileupload_t &fileupload) {
+  iterator here = args.find (key);
+  if (here != args.end()) {
+    (*here).second.fileupload = fileupload;
+  }
+}
+
+text_t *cgiargsclass::getarg (const text_t &key) {
+  iterator here = args.find (key);
+  if (here == args.end()) return NULL;
+
+  return &((*here).second.value);
+}
+
+int cgiargsclass::getintarg (const text_t &key) {
+  text_t *text = getarg (key);
+  if (text == NULL) return 0;
+  return text->getint();
+}
+
+fileupload_t *cgiargsclass::getargfile (const text_t &key) {
+  iterator here = args.find (key);
+  if (here == args.end()) return NULL;
+  return &((*here).second.fileupload);
+}
+
+
+
+
+// stream operators to print cgi arguments for debugging purposes
+ostream &operator<<(ostream &outs, const cgiargsclass &args) {
+  utf8outconvertclass text_t2utf8;
+  cgiargsclass::const_iterator here = args.begin ();
+  cgiargsclass::const_iterator end = args.end ();
+
+  outs << "*** cgiargsclass\n";
+  
+  while (here != end) {
+    outs << text_t2utf8 << " \"" << (*here).first << "\"=\"" << 
+      (*here).second.value << "\"\n";
+    ++here;
+  }
+  outs << "\n";
+
+  return outs;
+}
+
+
+
+cgiarginfo::cgiarginfo () {
+  multiplechar = false;
+  multiplevalue = false;
+  fileupload = false;
+  defaultstatus = weak;
+  argdefault.clear();
+  savedarginfo = can;
+}
+
+
+bool operator==(const cgiarginfo &x, const cgiarginfo &y) {
+  return ((x.shortname == y.shortname) &&
+	  (x.longname == y.longname) &&
+	  (x.multiplechar == y.multiplechar) &&
+	  (x.multiplevalue == y.multiplevalue) &&
+	  (x.fileupload == y.fileupload) &&
+	  (x.defaultstatus == y.defaultstatus) &&
+	  (x.argdefault == y.argdefault) &&
+	  (x.savedarginfo == y.savedarginfo));
+}
+
+bool operator<(const cgiarginfo &x, const cgiarginfo &y) {
+  return ((x.shortname < y.shortname) ||
+	  ((x.shortname == y.shortname) &&
+	   ((x.longname < y.longname) ||
+	    ((x.longname == y.longname) &&
+	     ((x.multiplevalue < y.multiplevalue) ||
+	      ((x.multiplevalue == y.multiplevalue) &&
+	       ((x.fileupload == y.fileupload) &&
+		((x.fileupload < y.fileupload) ||
+		 ((x.multiplechar < y.multiplechar) ||
+		  ((x.multiplechar == y.multiplechar) &&
+		   ((x.defaultstatus < y.defaultstatus) ||
+		    ((x.defaultstatus == y.defaultstatus) &&
+		     ((x.argdefault < y.argdefault) ||
+		      ((x.argdefault == y.argdefault) &&
+		       ((x.savedarginfo < y.savedarginfo))))))))))))))));
+}
+
+
+// constructor
+cgiargsinfoclass::cgiargsinfoclass () {
+}
+
+// addarginfo will combine the information with the present
+// information. If name clashes were detected then the information
+// will be written to logout (or stderr) and addarginfo will return false. No
+// processing with the arguments should be done if this happens
+// as the results will be meaningless.
+bool cgiargsinfoclass::addarginfo (ostream *logout, cgiarginfo &info) {
+
+  // if info.fileupload is set certain other fields are implicitly
+  // overridden
+  if (info.fileupload) {
+    info.multiplechar = false;
+    info.defaultstatus = cgiarginfo::weak;
+    info.argdefault = "";
+    info.savedarginfo = cgiarginfo::mustnot;
+  }
+  cgiarginfo *orginfo = getarginfo (info.shortname);
+  if (orginfo == NULL) {
+    argsinfo[info.shortname] = info;
+    return true; // no clashes
+  }
+
+  if (orginfo->longname != info.longname) {
+    outconvertclass text_t2ascii;
+    if (logout != NULL) {
+      (*logout) << text_t2ascii << "Error: cgi argument name clash for argument \""
+		<< info.shortname << "\".\nOne long name was\n  \"" << orginfo->longname 
+		<< "\"\nand the other was\n  \"" << info.longname << "\".\n\n";
+    } else {
+      cerr << text_t2ascii << "Error: cgi argument name clash for argument \""
+	   << info.shortname << "\".\nOne long name was\n  \"" << orginfo->longname 
+	   << "\"\nand the other was\n  \"" << info.longname << "\".\n\n";
+    }
+    return false; // found a clash
+  }
+
+  if (orginfo->multiplevalue != info.multiplevalue) {
+    outconvertclass text_t2ascii;
+    if (logout != NULL) {
+      (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname 
+		<< "\" was given as being a single value option\n"
+		<< "and a multiple value option.\n\n";
+    } else {
+      cerr << text_t2ascii << "Error: cgi argument \"" << info.shortname 
+		<< "\" was given as being a single value option\n"
+		<< "and a multiple value option.\n\n";
+    }
+    return false; // found a clash
+  }
+
+  if (orginfo->fileupload != info.fileupload) {
+    outconvertclass text_t2ascii;
+    if (logout != NULL) {
+      (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname 
+		<< "\" was given as being a file upload argument\n"
+		<< "and a non file upload argument.\n\n";
+    } else {
+      cerr << text_t2ascii << "Error: cgi argument \"" << info.shortname 
+	   << "\" was given as being a file upload argument\n"
+	   << "and a non file upload argument.\n\n";
+    }
+    return false; // found a clash
+  }
+
+  if (orginfo->multiplechar != info.multiplechar) {
+    outconvertclass text_t2ascii;
+    if (logout != NULL) {
+      (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname 
+		<< "\" was given as being a single character option\n"
+		<< "and a multiple character option.\n\n";
+    } else {
+      cerr << text_t2ascii << "Error: cgi argument \"" << info.shortname 
+	   << "\" was given as being a single character option\n"
+	   << "and a multiple character option.\n\n";
+    } 
+    return false; // found a clash
+  }
+  
+  if (!info.multiplechar && info.argdefault.size() > 1) {
+    outconvertclass text_t2ascii;
+    if (logout != NULL) {
+      (*logout) << text_t2ascii << "Error: cgi argument \"" << info.shortname
+		<< "\" was defined as being a single character option\n"
+		<< "but a multiple character default was given.\n\n";
+    } else {
+      cerr << text_t2ascii << "Error: cgi argument \"" << info.shortname
+	   << "\" was defined as being a single character option\n"
+	   << "but a multiple character default was given.\n\n";
+    }
+    return false;  // found a problem
+  }
+
+  // make sure there is no clashes in the savedarginfo
+  if ((orginfo->savedarginfo==cgiarginfo::mustnot && 
+       info.savedarginfo==cgiarginfo::must) ||
+      (orginfo->savedarginfo==cgiarginfo::must && 
+       info.savedarginfo==cgiarginfo::mustnot)) {
+    outconvertclass text_t2ascii;
+    if (logout != NULL) {
+      (*logout) << text_t2ascii << "Error: it was specified that cgi argument \"" 
+		<< info.shortname << "\" should be saved in the state\n"
+		<< "information and that it should not be save in the state information.\n\n";
+    } else {
+      cerr << text_t2ascii << "Error: it was specified that cgi argument \"" 
+	   << info.shortname << "\" should be saved in the state\n"
+	   << "information and that it should not be save in the state information.\n\n";
+    }
+    return false; // found a clash
+  }
+  // the only time orginfo->savedarginfo can change is when it is set
+  // to "can"
+  if (orginfo->savedarginfo == cgiarginfo::can) 
+    orginfo->savedarginfo = info.savedarginfo;
+
+
+  if (orginfo->defaultstatus > info.defaultstatus) {
+    return true;
+  }
+  orginfo->defaultstatus = info.defaultstatus;
+  orginfo->argdefault = info.argdefault;
+
+  return true;
+}
+
+bool cgiargsinfoclass::addarginfo (ostream *logout, cgiargsinfoclass &info) {
+  
+  iterator here = info.begin ();
+  iterator end = info.end ();
+
+  while (here != end) {
+    if (!addarginfo (NULL, (*here).second)) {
+      cerr << "returning false\n";
+      return false;
+    }
+    ++here;
+  }
+  
+  return true; // made it, no clashes
+}
+
+bool cgiargsinfoclass::addarginfo (ostream *logout, const text_t& argshortname, const text_tmap& mapinfo)
+{
+  cgiarginfo *arginfo = getarginfo (argshortname);
+  if (arginfo == NULL) {
+    arginfo = &(argsinfo[argshortname]);
+    arginfo->shortname = argshortname;
+    arginfo->defaultstatus = cgiarginfo::config;
+  }
+  text_tmap::const_iterator thisInfo = mapinfo.begin();
+  text_tmap::const_iterator endInfo = mapinfo.end();
+  while (thisInfo != endInfo) {
+    if (thisInfo->first == "longname") arginfo->longname = thisInfo->second;
+    else if (thisInfo->first == "multiplechar") arginfo->multiplechar = (thisInfo->second == "true");
+    else if (thisInfo->first == "defaultstatus") {
+      if (thisInfo->second == "none") arginfo->defaultstatus = cgiarginfo::none;
+      else if (thisInfo->second == "weak") arginfo->defaultstatus = cgiarginfo::weak;
+      else if (thisInfo->second == "good") arginfo->defaultstatus = cgiarginfo::good;
+      else if (thisInfo->second == "config") arginfo->defaultstatus = cgiarginfo::config;
+      else if (thisInfo->second == "imperative") arginfo->defaultstatus = cgiarginfo::imperative;
+    }
+    else if (thisInfo->first == "argdefault") {
+      arginfo->argdefault = thisInfo->second;
+    }
+    else if (thisInfo->first == "savedarginfo") {
+      if (thisInfo->second == "mustnot") arginfo->savedarginfo = cgiarginfo::mustnot;
+      else if (thisInfo->second == "can") arginfo->savedarginfo = cgiarginfo::can;
+      else if (thisInfo->second == "must") arginfo->savedarginfo = cgiarginfo::must;
+    } else if (logout != NULL) {
+      (*logout) << ("Invalid argument for cgiarg for " + argshortname + " (" + thisInfo->first + ")\n");
+    }
+    ++thisInfo;
+  }
+  return true;
+}
+
+bool cgiargsinfoclass::addarginfo (ostream *logout, confcgiarg_tmap& info)
+{
+  confcgiarg_tmap::const_iterator thisArg = info.begin();
+  confcgiarg_tmap::const_iterator endArg = info.end();
+  while (thisArg != endArg) {
+    if (!addarginfo(logout, thisArg->first, thisArg->second)) return false;
+    ++thisArg;
+  }
+  return true;
+}
+
+cgiarginfo *cgiargsinfoclass::getarginfo (const text_t &key) {
+  iterator here = argsinfo.find (key);
+  if (here == argsinfo.end()) return NULL;
+
+  return &((*here).second);
+}
+
+const cgiarginfo *cgiargsinfoclass::getarginfo (const text_t &key) const {
+  const_iterator here = argsinfo.find (key);
+  if (here == argsinfo.end()) return NULL;
+
+  return &((*here).second);
+}
+
+// stream operators to print cgiarginfo for debugging purposes
+ostream &operator<<(ostream &outs, const cgiargsinfoclass &argsinfo) {
+  utf8outconvertclass text_t2utf8;
+  cgiargsinfoclass::const_iterator here = argsinfo.begin ();
+  cgiargsinfoclass::const_iterator end = argsinfo.end ();
+
+  outs << "*** cgiargsinfoclass\n";
+  
+  while (here != end) {
+    outs << text_t2utf8 << (*here).first << ", ";
+    ++here;
+  }
+  outs << "\n";
+
+  return outs;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/cgiargs.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/cgiargs.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/cgiargs.h	(revision 16571)
@@ -0,0 +1,260 @@
+/**********************************************************************
+ *
+ * cgiargs.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef CGIARGS_H
+#define CGIARGS_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+#endif
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\map>
+#elif defined(GSDL_USE_STL_H)
+#  include <map.h>
+#else
+#  include <map>
+#endif
+
+
+// response_t is used to define what type of cgi header 
+// should be produced
+// fullcontent same as content but the action should put content-type as last header.
+enum response_t {location, content, fullcontent, undecided_location};
+
+struct fileupload_t {
+  void clear();
+  fileupload_t() {clear();}
+  
+  text_t name;
+  text_t type;
+  int size;
+  text_t tmp_name;
+};
+
+typedef map<text_t, fileupload_t, lttext_t> fileupload_tmap;
+
+struct cgiarg_t {
+  void clear ();
+  cgiarg_t () {clear();}
+  cgiarg_t &operator=(const cgiarg_t &x);
+  
+  enum source_t {default_arg, compressed_arg, cgi_arg, program_arg};
+  
+  text_t value;
+  source_t source;
+  fileupload_t fileupload;
+};
+
+ostream &operator<<(ostream &outs, const fileupload_t &fu);
+
+bool operator==(const cgiarg_t &x, const cgiarg_t &y);
+bool operator<(const cgiarg_t &x, const cgiarg_t &y);
+
+typedef map<text_t, cgiarg_t, lttext_t> cgiarg_tmap;
+typedef map<text_t, text_tmap, lttext_t> confcgiarg_tmap;
+
+// cgiargsclass is used to store a particular set
+// of cgi arguments.
+class cgiargsclass {
+protected:
+  cgiarg_tmap args;
+
+public:
+  //type support for cgiarg_tmap
+  typedef cgiarg_tmap::iterator iterator;
+  typedef cgiarg_tmap::const_iterator const_iterator;
+  typedef cgiarg_tmap::reference reference;
+  typedef cgiarg_tmap::const_reference const_reference;
+  typedef cgiarg_tmap::size_type size_type;
+  typedef cgiarg_tmap::difference_type difference_type;
+  typedef cgiarg_tmap::const_reverse_iterator const_reverse_iterator;
+  typedef cgiarg_tmap::reverse_iterator reverse_iterator;
+  
+  // constructors
+  cgiargsclass ();
+
+  // basic container support
+  iterator begin () {return args.begin();}
+  const_iterator begin () const {return args.begin();}
+  iterator end () {return args.end();}
+  const_iterator end () const {return args.end();}
+
+  void erase(iterator pos) {args.erase(pos);}
+  void erase(iterator first, iterator last) {args.erase(first, last);}
+  cgiargsclass &operator=(const cgiargsclass &x) {args=x.args;return *this;}
+
+  bool empty () const {return args.empty();}
+  size_type size() const {return args.size();}
+
+
+  // added functionality
+  void clear () {args.erase(args.begin(),args.end());}
+
+  // setdefaultarg, setdefaultintarg, and setdefaultcarg will 
+  // only set the argument if it is not already set
+  // getargs returns NULL if there isn't an entry with
+  // 'key' already defined, getintarg returns 0 if there wasn't an
+  // entry with 'key' defined and operator[] returns "" if
+  // 'key' wasn't already defined (and sets 'key'="").
+  void setarg (const text_t &key, const text_t &value,
+	       cgiarg_t::source_t source=cgiarg_t::program_arg);
+  void setdefaultarg (const text_t &key, const text_t &value,
+		      cgiarg_t::source_t source=cgiarg_t::default_arg);
+  void setintarg (const text_t &key, int value,
+		  cgiarg_t::source_t source=cgiarg_t::program_arg);
+  void setdefaultintarg (const text_t &key, int value,
+			 cgiarg_t::source_t source=cgiarg_t::default_arg);
+  void setcarg (const text_t &key, unsigned short c,
+		cgiarg_t::source_t source=cgiarg_t::program_arg);
+  void setdefaultcarg (const text_t &key, unsigned short c,
+		       cgiarg_t::source_t source=cgiarg_t::default_arg);
+  void setargfile (const text_t &key, const fileupload_t &fileupload);
+  text_t *getarg (const text_t &key);
+  int getintarg (const text_t &key);
+  fileupload_t *getargfile (const text_t &key);
+  text_t &operator[] (const text_t &key) {return args[key].value;}
+  cgiarg_t &lookupcgiarg (const text_t &key) {return args[key];}
+};
+
+// stream operators to print cgi arguments for debugging purposes
+ostream &operator<<(ostream &outs, const cgiargsclass &args);
+
+
+
+// cgiarginfo holds information relating to a cgi argument
+class cgiarginfo {
+public:
+  cgiarginfo ();
+
+  // shortname is the name used in cgi arguments
+  text_t shortname;
+
+  // longname is the name used when giving information 
+  // about the argument and to spot name duplication
+  text_t longname;
+
+  // multiplechar should be set to true if the value can be
+  // more than one character long
+  bool multiplechar;
+
+  // multiplevalue should be set to true the argument may have 
+  // multiple values (as is the case when multiple checkboxes
+  // use the same name)
+  bool multiplevalue;
+
+  // fileupload should be set if the argument is to be used to upload files
+  bool fileupload;
+
+  // defaultstatus_t indicates how good the default is when different
+  // defaults are given for one argument. "none" means there is no default
+  // (a default might be given elsewhere). "weak" is a basic guess that
+  // doesn't hold much weight, "good" is a better guess, "config" was a default
+  // given in a configuration file, and "imperative" means it must not
+  // be overriden at any costs (unless there is another "imperative"...)
+  enum defaultstatus_t {none=0, weak=1, good=2, config=3, imperative=4};
+
+  defaultstatus_t defaultstatus;
+  text_t argdefault;   // a default value
+
+  // savedarginfo_t indicates whether the argument should be saved
+  // between pages (e.g. using the compressed argument) or not. The
+  // value of an argument can change from "can" to "mustnot" and 
+  // "can" to "must" but not "mustnot" to "must" or "must" to "mustnot".
+  enum savedarginfo_t {mustnot, can, must};
+
+  savedarginfo_t savedarginfo;
+};
+
+bool operator==(const cgiarginfo &x, const cgiarginfo &y);
+bool operator<(const cgiarginfo &x, const cgiarginfo &y);
+
+typedef map<text_t, cgiarginfo, lttext_t> argsinfomap;
+
+// contains a list of cgi argument information
+class cgiargsinfoclass {
+protected:
+  argsinfomap argsinfo;
+
+public:
+  // type support for arginfomap
+  typedef argsinfomap::iterator iterator;
+  typedef argsinfomap::const_iterator const_iterator;
+  typedef argsinfomap::reference reference;
+  typedef argsinfomap::const_reference const_reference;
+  typedef argsinfomap::size_type size_type;
+  typedef argsinfomap::difference_type difference_type;
+  typedef argsinfomap::const_reverse_iterator const_reverse_iterator;
+  typedef argsinfomap::reverse_iterator reverse_iterator;
+  
+  // constructors
+  cgiargsinfoclass ();
+
+  // basic container support
+  iterator begin () {return argsinfo.begin();}
+  const_iterator begin () const {return argsinfo.begin();}
+  iterator end () {return argsinfo.end();}
+  const_iterator end () const {return argsinfo.end();}
+
+  void erase(iterator pos) {argsinfo.erase(pos);}
+  void erase(iterator first, iterator last) {argsinfo.erase(first, last);}
+  cgiargsinfoclass &operator=(const cgiargsinfoclass &x) {argsinfo=x.argsinfo;return *this;}
+
+  bool empty () const {return argsinfo.empty();}
+  size_type size() const {return argsinfo.size();}
+
+
+  // added functionality
+  void clear () {argsinfo.erase(argsinfo.begin(),argsinfo.end());}
+
+  // addarginfo will combine the information with the present
+  // information. If name clashes were detected then the information
+  // will be written to logout and addarginfo will return false. No
+  // processing with the arguments should be done if this happens
+  // as the results will be meaningless.
+  bool addarginfo (ostream *logout, cgiarginfo &info);
+  bool addarginfo (ostream *logout, cgiargsinfoclass &info);
+
+  // addarginfo will override args info with info loaded from config files
+  // if the args do not exists will be created
+  bool addarginfo (ostream *logout, const text_t& argshortname, const text_tmap& mapinfo);
+  bool addarginfo (ostream *logout, confcgiarg_tmap& info);
+
+  cgiarginfo *getarginfo (const text_t &key);
+  const cgiarginfo *getarginfo (const text_t &key) const;
+  cgiarginfo &operator[] (const text_t &key) {return argsinfo[key];}
+};
+
+ostream &operator<<(ostream &outs, const cgiargsinfoclass &argsinfo);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/cgiutils.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/cgiutils.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/cgiutils.cpp	(revision 16571)
@@ -0,0 +1,847 @@
+/**********************************************************************
+ *
+ * cgiutils.cpp -- general cgi utilities
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "cgiutils.h"
+#include "md5.h"
+#include "fileutil.h"
+#include "gsdlunicode.h"
+#include "fileutil.h"
+#include "unitool.h" // in mg, for output_utf8_char
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#  include <ospace\std\fstream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#  include <fstream.h>
+#else
+#  include <iostream>
+#  include <fstream>
+#endif
+
+
+static unsigned short hexdigit (unsigned short c) {
+  if (c >= '0' && c <= '9') return (c-'0');
+  if (c >= 'a' && c <= 'f') return (c-'a'+10);
+  if (c >= 'A' && c <= 'F') return (c-'A'+10);
+  return c;
+}
+
+
+static void c2hex (unsigned short c, text_t &t) {
+  t.clear();
+  
+  if (c >= 256) {
+    t = "20"; // ' '
+    return;
+  }
+  
+  unsigned short o1, o2;
+  
+  o1 = (c/16) % 16;
+  o2 = c % 16;
+  if (o1 >= 10) o1 += 'a' - 10;
+  else o1 += '0';
+  if (o2 >= 10) o2 += 'a' - 10;
+  else o2 += '0';
+  
+  t.push_back(o1);
+  t.push_back(o2);
+}
+
+static text_t::iterator getline (text_t::iterator first, 
+				 text_t::iterator last,
+				 bool include_crlf) {
+  while (first != last) {
+    if (((first+1) != last) && (*first == 13) && (*(first+1) == 10)) {
+      // found <CRLF>
+      if (include_crlf) first += 2;
+      break;
+    }
+
+    first++;
+  }
+
+  return first;
+}
+
+static void process_post_section (text_t &argname, text_t &argdata, text_t &filename, text_t &filedata,
+				  text_t &filetype, bool &isfile, text_t &argstr,
+				  fileupload_tmap &fileuploads, const text_t &gsdlhome) {
+
+  if (!argname.empty()) {
+
+    if (!isfile) {
+      // argdata includes a trailing <CRLF> that we must remove
+      if ((argdata.size() > 1) && (*(argdata.end()-2) == 13) && (*(argdata.end()-1) == 10)) {
+	argdata.erase(argdata.end()-2, argdata.end());
+      }
+      if (!argstr.empty()) argstr += "&";
+      argstr += argname + "=" + argdata;
+
+    } else if (!filename.empty()) {
+      // filedata includes a trailing <CRLF> that we must remove
+      if ((filedata.size() > 1) && (*(filedata.end()-2) == 13) && (*(filedata.end()-1) == 10)) {
+	filedata.erase(filedata.end()-2, filedata.end());
+      }
+
+      // create tmp_name for storing the file on disk
+      text_t tmp_name = md5data(filedata);
+      tmp_name = filename_cat(gsdlhome, "tmp", tmp_name);
+
+      char *tmp_name_c = tmp_name.getcstr();
+
+      // write the file data to disk
+      outconvertclass out;
+      ofstream filestream(tmp_name_c, ios::out | ios::binary);
+      filestream << out << filedata;
+      filestream.close();
+      delete tmp_name_c;
+
+      // populate the fields of a fileupload_t and put it in the
+      // fileuploads map
+      fileupload_t fu;
+      // note that filename currently may or may not include the path since
+      // some browsers (e.g. IE) include the path while others
+      // (e.g. mozilla) do not. we should probably remove the path from
+      // this field here to get a consistent value across all browsers.
+      text_t::iterator slash = findlastchar(filename.begin(), filename.end(), '\\');
+      if (slash != filename.end()) {
+	filename = substr(slash+1, filename.end());
+      }
+      fu.name = filename;
+      fu.type = filetype;
+      // size has yet to be implemented
+      fu.size = filedata.size();
+
+      fu.tmp_name = tmp_name;
+      fileuploads[argname] = fu;
+    }
+  }
+  isfile = false;
+  argname.clear();
+  argdata.clear();
+  filename.clear();
+  filedata.clear();
+  filetype.clear();
+}
+
+// parse data obtained through a CGI POST request
+text_t parse_post_data (text_t &content_type, text_t &raw_post_data, 
+			fileupload_tmap &fileuploads, const text_t &gsdlhome) {
+
+  text_t argstr;
+
+  text_t::iterator content_type_begin = content_type.begin();
+  text_t::iterator content_type_end = content_type.end();
+  if (findword(content_type_begin, content_type_end, "multipart/form-data") == content_type_end) {
+    // a simple post request
+
+    return raw_post_data;
+
+  } else {
+    // multipart/form data - may contain one or more uploaded files
+
+    /*
+      content_type should look something like the following
+        multipart/form-data; boundary=---------------------------7d411e1a50330
+	
+      while raw_post_data will be as follows
+        -----------------------------7d43e73450330CRLF
+	Content-Disposition: form-data; name="e"<CRLF>
+	<CRLF>
+	d-0testss--1-0-00---4----0--0-110--1en-Zz-1---10-about-0--00031-001utfZz-8-0<CRLF>
+	-----------------------------7d43e73450330<CRLF>
+	Content-Disposition: form-data; name="afile"; filename="C:\somedoc.doc"<CRLF>
+	Content-Type: application/msword<CRLF>
+	<CRLF>
+	<Content of file><CRLF>
+	
+    */
+
+    // first get the boundary from content-type
+    text_t::iterator boundary_begin = findword(content_type_begin, content_type_end, "boundary=");
+    if (boundary_begin+9 < content_type_end) 
+      {
+	// skip over "boundary=" part of string
+	boundary_begin += 9;
+      }
+    else {
+      // error
+      cerr << "Error: malformed boundary? '" <<  content_type << "'" << endl;
+      return "";
+    }
+    text_t boundary = substr(boundary_begin, getline(boundary_begin, content_type_end, false));
+    int boundary_len = boundary.size();
+
+
+    text_t argname, argdata, filename, filedata, filetype;
+    bool isfile = false;
+    text_t::iterator data_here = raw_post_data.begin();
+    text_t::iterator data_end = raw_post_data.end();
+    while (data_here != data_end) {
+      
+      // get the next available line (including the trailing <CRLF>
+      text_t line = substr(data_here, getline(data_here, data_end, true));
+
+      data_here += line.size();
+      text_t::iterator line_begin = line.begin();
+      text_t::iterator line_end = line.end();
+      if (findword(line_begin, line_end, boundary) != line_end) {
+	// we've found a boundary
+	process_post_section(argname, argdata, filename, filedata, filetype,
+			     isfile, argstr, fileuploads, gsdlhome);
+
+      } else if (findword(line_begin, line_end, "Content-Disposition: form-data") != line_end) {
+	// we've found the the beginning of a new section
+	argname.clear();
+	argdata.clear();
+
+	// get the name of this piece of form data
+	text_t::iterator it = findword(line_begin, line_end, "name=\"");
+	if (it == line_end) break; // error - this shouldn't happen
+	it = findchar(it, line_end, '"');
+	if ((it != line_end) && (it+1 != line_end)) {
+	  argname = substr(it+1, findchar(it+1, line_end, '"'));
+	}
+
+	// if this piece of form data contains filename="" it's a file
+	// upload and needs to be treated special
+	it = (findword(line_begin, line_end, "filename=\""));
+	if (it != line_end) {
+	  // we've found a file upload
+	  isfile = true;
+	  it = findchar(it, line_end, '"');
+	  if ((it != line_end) && (it+1 != line_end)) {
+	    filename = substr(it+1, findchar(it+1, line_end, '"'));
+	  }
+
+	  // the next line is the content-type of this section
+	  line = substr(data_here, getline(data_here, data_end, true));
+	  data_here += line.size();
+	  line_begin = line.begin();
+	  line_end = line.end();
+	  it = (findword(line_begin, line_end, "Content-Type: "));
+	  if (it != line_end) {
+	    filetype = substr(it+14, getline(it, line_end, false));
+	  }
+	}
+
+	// eat up the next line as it's just a <CRLF> on it's own
+	data_here += 2;
+
+      } else {
+	if (isfile) filedata += line;
+	else argdata += line;
+      }
+
+    }
+
+    // process last section
+    process_post_section(argname, argdata, filename, filedata, filetype,
+			 isfile, argstr, fileuploads, gsdlhome);
+
+    return argstr;
+  }
+}
+
+// convert %xx and + to their appropriate equivalents
+// IE 6.0 and later use "%u" followed by 4 hex digits... MS IIS extension!
+// NOTE: this method is crap. It assumes the input encoding is utf-8. If it 
+// actually was, then this returns utf-8, and needs to_uni on the 
+// result to get it back to unicode. If the encoding wasn't utf-8, then the 
+// output may be crap. Seems to work for 8 bit encodings.
+// Really, this should be given the encoding, and should always return unicode. 
+void decode_cgi_arg (text_t &argstr) {
+  text_t::iterator in = argstr.begin();
+  text_t::iterator out = in;
+  text_t::iterator end = argstr.end();
+  
+  while (in != end) {
+    if (*in == '+') *out = ' ';
+    
+    else if (*in == '%') {
+      unsigned short c = '%';
+      ++in;
+      if (in != end) { // this is an encoding...
+	if (*in == 'u') { // convert %uHHHH to unicode then current encoding
+	  // this assumes a short int is at least 16 bits...
+	  ++in;  
+	  if (in != end)
+	    c=hexdigit(*in++) << 12;
+	  if (in != end)
+	    c+=hexdigit(*in++) << 8;
+	  if (in != end)
+	    c+=hexdigit(*in++) << 4;
+	  if (in != end)
+	    c+=hexdigit(*in);
+	  /* BAD!! The following assumes the interface is using utf-8. But
+	     at this point we don't know what encoding we are using, unless
+	     we can parse it out of the string we are currently decoding... */
+	  text_t uni=" ";
+	  uni[0]=c;
+	  text_t utf8=to_utf8(uni);
+	  int last_byte=utf8.size()-1;
+	  for (int i=0;i<last_byte;++i)
+	    *out++ = utf8[i];
+	  c=utf8[last_byte];
+	} else {  // convert %HH to hex value
+	  c = hexdigit (*in);
+	  ++in;
+	  if (in != end && c < 16) { // sanity check on the previous character
+	    c = c*16 + hexdigit (*in);
+	  }
+	}
+      }
+      *out = c;
+    } else *out = *in;
+    
+    if (in != end) ++in;
+    ++out;
+  }
+  
+  // remove the excess characters
+  argstr.erase (out, end);
+  
+}
+
+
+// split up the cgi arguments
+void split_cgi_args (const cgiargsinfoclass &argsinfo, text_t argstr, 
+		     cgiargsclass &args) {
+  args.clear();
+  
+  text_t::const_iterator here = argstr.begin();
+  text_t::const_iterator end = argstr.end();
+  text_t key, value;
+ 
+  // extract out the key=value pairs
+  while (here != end) {
+    // get the next key and value pair
+    here = getdelimitstr (here, end, '=', key);
+    here = getdelimitstr (here, end, '&', value);
+    
+    // convert %xx and + to their appropriate equivalents
+    decode_cgi_arg (value);
+    value.setencoding(1); // other encoding
+    // store this key=value pair
+    if (!key.empty()) {
+
+      // if arg occurs multiple times (as is the case with multiple
+      // checkboxes using the same name) we'll create a comma separated
+      // list of all the values (this uses a hack that encodes naturally
+      // occurring commas as %2C - values will therefore need to be decoded
+      // again before use) - it should use an array instead
+      const cgiarginfo *info = argsinfo.getarginfo (key);
+      if (info==NULL) {
+	// If info is NULL, we can't tell if the arg is multiple value or not
+	// Because we need to have dynamically named arguments multivalued, we
+	// will always assume multiplevalue = true
+	// If the arg is not multi valued, then you need to decode the commas.
+	if (args.getarg(key)==NULL) {
+	  args.setarg (key, encode_commas(value), cgiarg_t::cgi_arg);
+	}
+	else {
+	  text_t newvalue = args[key];
+
+	  newvalue += "," + encode_commas(value);
+	  args.setarg (key, newvalue, cgiarg_t::cgi_arg);
+	}
+      }
+      else {
+	if (info->multiplevalue) {
+
+	  text_t newvalue = args[key];
+	  if (args.lookupcgiarg(key).source == cgiarg_t::cgi_arg) newvalue += ",";
+	  newvalue += encode_commas(value);
+	  args.setarg (key, newvalue, cgiarg_t::cgi_arg);
+
+	} else {
+	  args.setarg (key, value, cgiarg_t::cgi_arg);
+	}
+      }
+    }
+  }
+}
+
+text_t encode_commas (const text_t &intext) {
+
+  text_t outtext;
+
+  text_t::const_iterator here = intext.begin ();
+  text_t::const_iterator end = intext.end ();
+
+  while (here != end) {
+    if (*here == ',') outtext += "%2C";
+    else outtext.push_back (*here);
+    ++here;
+  }
+  return outtext;
+}
+
+text_t decode_commas (const text_t &intext) {
+
+  text_t outtext;
+  
+  text_t::const_iterator here = intext.begin ();
+  text_t::const_iterator end = intext.end ();
+  
+  while (here != end) {
+    if ((here+2<end) && *here == '%' && *(here+1) == '2' &&
+	(*(here+2) == 'C' || *(here+2) == 'c')) {
+      here += 2;
+      outtext.push_back(',');
+      
+    }else outtext.push_back (*here);
+    ++here;
+  }
+  return outtext;
+}
+
+// set utf8 to true if input is in utf-8, otherwise expects input in unicode
+text_t minus_safe (const text_t &intext, bool utf8) {
+
+  text_t outtext;
+
+  text_t::const_iterator here = intext.begin ();
+  text_t::const_iterator end = intext.end ();
+
+  while (here != end) {
+    if (*here == '-') outtext += "Zz-";
+    else outtext.push_back (*here);
+    ++here;
+  }
+  if (utf8) {
+    outtext = cgi_safe_utf8 (outtext);
+  } else {
+    outtext = cgi_safe_unicode (outtext);
+  }
+  return outtext;
+}
+
+// takes utf-8 input
+text_t cgi_safe_utf8 (const text_t &intext) {
+  text_t outtext;
+  
+  text_t::const_iterator here = intext.begin ();
+  text_t::const_iterator end = intext.end ();
+  unsigned short c;
+  text_t ttmp;
+  
+  while (here != end) {
+    c = *here;
+    if (((c >= 'a') && (c <= 'z')) ||
+	((c >= 'A') && (c <= 'Z')) ||
+	((c >= '0') && (c <= '9')) ||
+	(c == '%') || (c == '-')) {
+      // alphanumeric character
+      outtext.push_back(c);
+    } else if (c == ' ') {
+      // space
+      outtext.push_back('+');
+    } else if (c > 255) { // not utf-8 character
+      cerr << "WARNING: expected utf-8 char, but got unicode!!\n";
+    } else {
+      // everything else
+      outtext.push_back('%');
+      c2hex(c, ttmp);
+      outtext += ttmp;
+    }
+    
+    ++here;
+  }
+  
+  return outtext;
+}
+// takes unicode input
+text_t cgi_safe_unicode (const text_t &intext) {
+  text_t outtext;
+  
+  text_t::const_iterator here = intext.begin ();
+  text_t::const_iterator end = intext.end ();
+  unsigned short c;
+  text_t ttmp;
+  
+  while (here != end) {
+    c = *here;
+    if (((c >= 'a') && (c <= 'z')) ||
+	((c >= 'A') && (c <= 'Z')) ||
+	((c >= '0') && (c <= '9')) ||
+	(c == '%') || (c == '-')) {
+      // alphanumeric character
+      outtext.push_back(c);
+    } else if (c == ' ') {
+      // space
+      outtext.push_back('+');
+    } else if (c > 127) { // unicode character
+      unsigned char buf[3]; // up to 3 bytes
+      buf[0]='\0';buf[1]='\0';buf[2]='\0';
+      output_utf8_char(c,buf, buf+2);
+      outtext.push_back('%');
+      c2hex(buf[0], ttmp);
+      outtext += ttmp;
+      outtext.push_back('%');
+      c2hex(buf[1], ttmp);
+      outtext += ttmp;
+      if (buf[2]) {
+      outtext.push_back('%');
+      c2hex(buf[2], ttmp);
+      outtext += ttmp;
+      }
+    } else {
+      // everything else
+      outtext.push_back('%');
+      c2hex(c, ttmp);
+      outtext += ttmp;
+    }
+    
+    ++here;
+  }
+  
+  return outtext;
+}
+
+
+
+
+static text_t::const_iterator get_next_save_arg (text_t::const_iterator first, 
+					   text_t::const_iterator last,
+					   text_t &argname) {
+  first = getdelimitstr (first, last, '-', argname);
+  return first;
+}
+
+
+// check_save_conf_str checks the configuration string for
+// the saved args and makes sure it does not conflict with
+// the information about the arguments. If an error is encountered
+// it will return false and the program should not produce any
+// output.
+bool check_save_conf_str (const text_t &saveconf, 
+			  const cgiargsinfoclass &argsinfo,
+			  ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  text_tset argsset;
+  text_t::const_iterator saveconfhere = saveconf.begin ();
+  text_t::const_iterator saveconfend = saveconf.end ();
+  text_t argname;
+  const cgiarginfo *info;
+
+  // first check to make sure all saved arguments can be saved
+  
+  while (saveconfhere != saveconfend) {
+    saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname);
+
+    if (!argname.empty()) {
+      // save the argument name for later
+      argsset.insert (argname);
+
+      // check the argument
+      info =  argsinfo.getarginfo (argname);
+      if (info == NULL) {
+	logout << text_t2ascii << "Error: the cgi argument \"" << argname 
+	       << "\" is used in the configuration string for the\n"
+	       << "saved arguments but does not exist as a valid argument.\n\n";
+	return false;
+      }
+      if (info->savedarginfo == cgiarginfo::mustnot) {
+	logout << text_t2ascii << "Error: the cgi argument \"" << argname
+	       << "\" is used in the configuration string for the\n"
+	       << "saved arguments but has been specified as an argument whose\n"
+	       << "state must not be saved.\n\n";
+	return false;
+      }
+    }
+  }
+
+
+  // next check that all saved arguments that should be saved
+  // are saved
+  cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
+  cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
+
+  while (argsinfohere != argsinfoend) {
+    if (((*argsinfohere).second.savedarginfo == cgiarginfo::must) &&
+	(argsset.find((*argsinfohere).second.shortname) == argsset.end())) {
+      logout << text_t2ascii << "Error: the cgi argument \"" 
+	     << (*argsinfohere).second.shortname << "\" was specified as needing to\n"
+	     << "be save but was not listed in the saved arguments.\n\n";
+      return false;
+    }
+
+    ++argsinfohere;
+  }
+  
+  return true; // made it, no clashes
+}
+
+
+// create_save_conf_str will create a configuration string
+// based on the information in argsinfo. This method of configuration
+// is not recomended as small changes can produce large changes in
+// the resulting configuration string (for instance a totally different
+// ordering). Only arguments which "must" be saved are included in
+// the resulting string.
+text_t create_save_conf_str (const cgiargsinfoclass &argsinfo,
+			     ostream &/*logout*/) {
+  cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
+  cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
+  text_t saveconf;
+  bool first = true;
+
+  while (argsinfohere != argsinfoend) {
+    // save this argument if it must be saved
+    if ((*argsinfohere).second.savedarginfo == cgiarginfo::must) {
+      if (!first) saveconf.push_back ('-');
+      else first = false;
+      saveconf += (*argsinfohere).second.shortname;
+    }
+
+    ++argsinfohere;
+  }
+  
+  return saveconf;
+}
+
+
+// expand_save_args will expand the saved arguments based
+// on saveconf placing the results in args if they are not
+// already defined. If it encounters an error it will return false
+// and output more information to logout.
+bool expand_save_args (const cgiargsinfoclass &argsinfo,
+		       const text_t &saveconf, 
+		       cgiargsclass &args,
+		       ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  text_t *arg_e = args.getarg("e");
+  if (arg_e == NULL) return true; // no compressed arguments
+  if (arg_e->empty()) return true; // no compressed arguments
+
+  text_t argname, argvalue;
+  const cgiarginfo *argnameinfo;
+  
+  text_t::const_iterator saveconfhere = saveconf.begin();
+  text_t::const_iterator saveconfend = saveconf.end();
+  
+  text_t::iterator arg_ebegin = arg_e->begin();
+  text_t::iterator arg_eend = arg_e->end();
+  text_t::iterator arg_ehere = arg_ebegin;
+  while (saveconfhere != saveconfend && arg_ehere != arg_eend) {
+    saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname);
+
+    if (!argname.empty()) {
+      // found another entry
+      argnameinfo = argsinfo.getarginfo (argname);
+
+      if (argnameinfo == NULL) {
+	// no information about the argument could be found
+	// we can't keep going because we don't know whether
+	// this argument is a single or multiple character value
+	logout << text_t2ascii << "Error: the cgi argument \"" << argname
+	       << "\" was specified as being a compressed argument\n"
+	       << "but no information about it could be found within the "
+	       << "cgiargsinfoclass.\n";
+	return false;
+
+      } else {
+
+	// found the argument information
+	if (argnameinfo->multiplechar) {
+	  text_t::const_iterator sav = arg_ehere;
+	  arg_ehere = getdelimitstr (arg_ehere, arg_eend, '-', argvalue);
+	  if (distance(arg_ebegin, arg_ehere) > 2) {
+	    // replace any '-' chars escaped with 'Zz'
+	    bool first = true;
+	    while ((*(arg_ehere-3) == 'Z') && (*(arg_ehere-2) == 'z')) {
+	      if (first) argvalue.clear();
+	      arg_ehere = (findchar (arg_ehere, arg_eend, '-')) + 1;
+	      while (sav != (arg_ehere-1)) {
+		if (!((*sav == 'Z') && (*(sav+1) == 'z') && (*(sav+2) == '-')) &&
+		    !((*(sav-1) == 'Z') && (*sav == 'z') && (*(sav+1) == '-'))) argvalue.push_back (*sav);
+		++sav;
+	      }
+	      first = false;
+	    }
+	  }
+	  argvalue.setencoding(1); // other encoding
+	  if (!argvalue.empty()) args.setdefaultarg (argname, argvalue, cgiarg_t::compressed_arg);
+	} else {
+	  args.setdefaultcarg (argname,*arg_ehere, cgiarg_t::compressed_arg);
+	  ++arg_ehere;
+	}
+      }
+    }
+  }
+
+  return true;
+}
+
+
+// adds the default values for those arguments which have not
+// been specified
+void add_default_args (const cgiargsinfoclass &argsinfo,
+		       cgiargsclass &args,
+		       ostream &/*logout*/) {
+  cgiargsinfoclass::const_iterator argsinfohere = argsinfo.begin ();
+  cgiargsinfoclass::const_iterator argsinfoend = argsinfo.end ();
+
+  while (argsinfohere != argsinfoend) {
+    if ((*argsinfohere).second.defaultstatus != cgiarginfo::none) {
+      args.setdefaultarg ((*argsinfohere).second.shortname,
+			  (*argsinfohere).second.argdefault, cgiarg_t::default_arg);
+    }
+    ++argsinfohere;
+  }
+}
+
+void add_fileupload_args (const cgiargsinfoclass &argsinfo,
+			  cgiargsclass &args,
+			  fileupload_tmap &fileuploads,
+			  ostream &logout) {
+ 
+  const cgiarginfo *info = argsinfo.getarginfo("a");
+  fileupload_tmap::const_iterator this_file = fileuploads.begin();
+  fileupload_tmap::const_iterator end_file = fileuploads.end();
+  while (this_file != end_file) {
+    const cgiarginfo *info = argsinfo.getarginfo((*this_file).first);
+    if (info != NULL) {
+
+      if ((*info).fileupload && (file_exists((*this_file).second.tmp_name))) {
+
+	args.setargfile((*this_file).first, (*this_file).second);
+      }
+    }
+    this_file++;
+  }
+}
+
+// compress_save_args will compress the arguments and return
+// them in compressed_args. If an error was encountered
+// compressed_args will be set to to "", an error will be
+// written to logout, and the function will return false.
+bool compress_save_args (const cgiargsinfoclass &argsinfo,
+			 const text_t &saveconf,
+			 cgiargsclass &args,
+			 text_t &compressed_args,
+			 outconvertclass &outconvert,
+			 ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  compressed_args.clear();
+
+  text_t argname, argvalue;
+  const cgiarginfo *argnameinfo;
+  
+  text_t::const_iterator saveconfhere = saveconf.begin();
+  text_t::const_iterator saveconfend = saveconf.end();
+  
+  while (saveconfhere != saveconfend) {
+    saveconfhere = get_next_save_arg (saveconfhere, saveconfend, argname);
+
+    if (!argname.empty()) {
+      // found another entry
+      argnameinfo = argsinfo.getarginfo (argname);
+
+      if (argnameinfo == NULL) {
+	// no information about the argument could be found
+	// we can't keep going because we don't know whether
+	// this argument is a single or multiple character value
+	logout << text_t2ascii << "Error: the cgi argument \"" << argname
+	       << "\" was specified as being a compressed argument\n"
+	       << "but no information about it could be found within the "
+	       << "cgiargsinfoclass.\n";
+	compressed_args.clear();
+	return false;
+
+      } else {
+	// found the argument information
+	if (argnameinfo->multiplechar) {
+	  // multiple character argument -- sort out any '-' chars
+	  if (args["w"]=="utf-16be") // browsers don't like \0 in urls...
+	    compressed_args += minus_safe (args[argname], false);
+	  else
+	    compressed_args += minus_safe (outconvert.convert(args[argname]), true);
+	  
+	  if (saveconfhere != saveconfend) compressed_args.push_back ('-');
+
+	} else {
+	  // single character argument
+	  if (args[argname].size() == 0) {
+	    logout << text_t2ascii << "Error: the cgi argument \"" << argname
+		   << "\" was specified as being a compressed argument which\n"
+		   << "should have a one character value but it was empty.\n\n";
+	    compressed_args.clear ();
+	    return false;
+
+	  } else if (args[argname].size() > 1) {
+	    logout << text_t2ascii << "Error: the cgi argument \"" << argname
+		   << "\" was specified as being a compressed argument which\n"
+		   << "should have a one character value but it had multiple characters.\n\n";
+	    compressed_args.clear ();
+	    return false;
+	  }
+
+	  // everything is ok
+	  compressed_args += args[argname];
+	}
+      }
+    }
+  }
+
+  return true;
+}
+
+
+// args_tounicode converts any arguments which are not in unicode
+// to unicode using inconvert
+void args_tounicode (cgiargsclass &args, inconvertclass &inconvert) {
+  cgiargsclass::iterator here = args.begin();
+  cgiargsclass::iterator end = args.end();
+
+  while (here != end) {
+    if ((*here).second.value.getencoding() > 0) {
+      (*here).second.value = inconvert.convert((*here).second.value);
+    }
+    
+    ++here;
+  }
+}
+
+// fcgienv will be loaded with environment name-value pairs
+// if using fastcgi (had to do this as getenv doesn't work
+// with our implementation of fastcgi). if fcgienv is empty
+// we'll simply use getenv
+text_t gsdl_getenv (const text_t &name, text_tmap &fcgienv) {
+  if (fcgienv.empty()) {
+    char *n = name.getcstr();
+    char *v = getenv(n);
+    delete []n;
+    if (v != NULL) return v;
+    return g_EmptyText;
+
+  } else return fcgienv[name];
+}
Index: /gsdl/trunk/runtime-src/src/recpt/cgiutils.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/cgiutils.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/cgiutils.h	(revision 16571)
@@ -0,0 +1,113 @@
+/**********************************************************************
+ *
+ * cgiutils.h -- general cgi utilities
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef CGIUTILS_H
+#define CGIUTILS_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "cgiargs.h"
+
+// parse data obtained through a CGI POST request
+text_t parse_post_data (text_t &content_type, text_t &raw_post_data, 
+			fileupload_tmap &fileuploads, const text_t &gsdlhome);
+
+// convert %xx and + to their appropriate equivalents
+void decode_cgi_arg (text_t &argstr);
+
+// split up the cgi arguments
+void split_cgi_args (const cgiargsinfoclass &argsinfo, text_t argstr, 
+		     cgiargsclass &args);
+
+text_t encode_commas (const text_t &intext);
+text_t decode_commas (const text_t &intext);
+
+// turns any '-' in a cgi argument into "(-)"
+// set utf8 to true if input is in utf-8, otherwise expects input in unicode
+text_t minus_safe (const text_t &intext, bool utf8);
+
+// returns the encoded version of a cgi argument
+// the original text should be in utf8
+text_t cgi_safe_utf8 (const text_t &intext);
+// the original text should be in unicode
+text_t cgi_safe_unicode (const text_t &intext);
+
+// check_save_conf_str checks the configuration string for
+// the saved args and makes sure it does not conflict with
+// the information about the arguments. If an error is encountered
+// it will return false and the program should not produce any
+// output.
+bool check_save_conf_str (const text_t &saveconf, 
+			  const cgiargsinfoclass &argsinfo,
+			  ostream &logout);
+
+// create_save_conf_str will create a configuration string
+// based on the information in argsinfo. This method of configuration
+// is not recomended as small changes can produce large changes in
+// the resulting configuration string (for instance a totally different
+// ordering). Only arguments which "must" be saved are included in
+// the resulting string.
+text_t create_save_conf_str (const cgiargsinfoclass &argsinfo,
+			     ostream &logout);
+
+// expand_compress_args will expand the compressed arguments based
+// on compressconf placing the results in args if they are not
+// already defined. If it encounters an error it will return false
+// and output more information to logout.
+bool expand_save_args (const cgiargsinfoclass &argsinfo,
+		       const text_t &saveconf, 
+		       cgiargsclass &args,
+		       ostream &logout);
+
+// adds the default values for those arguments which have not
+// been specified
+void add_default_args (const cgiargsinfoclass &argsinfo,
+		       cgiargsclass &args,
+		       ostream &logout);
+
+void add_fileupload_args (const cgiargsinfoclass &argsinfo,
+			  cgiargsclass &args,
+			  fileupload_tmap &fileuploads,
+			  ostream &logout);
+
+// compress_save_args will compress the arguments and return
+// them in compressed_args. If an error was encountered
+// compressed_args will be set to to "", an error will be
+// written to logout, and the function will return false.
+bool compress_save_args (const cgiargsinfoclass &argsinfo,
+			 const text_t &saveconf,
+			 cgiargsclass &args,
+			 text_t &compressed_args,
+			 outconvertclass &outconvert,
+			 ostream &logout);
+
+// args_tounicode converts any arguments which are not in unicode
+// to unicode using inconvert
+void args_tounicode (cgiargsclass &args, inconvertclass &inconvert);
+
+text_t gsdl_getenv (const text_t &name, text_tmap &fcgienv);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/cgiwrapper.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/cgiwrapper.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/cgiwrapper.cpp	(revision 16571)
@@ -0,0 +1,747 @@
+/**********************************************************************
+ *
+ * cgiwrapper.cpp -- output pages using the cgi protocol
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include <stdio.h>
+#ifdef __WIN32__
+#include <fcntl.h>
+#endif
+
+#include "gsdlconf.h"
+#include "cgiwrapper.h"
+#include "gsdlsitecfg.h"
+#include "maincfg.h"
+#include "fileutil.h"
+#include "cgiutils.h"
+#include <stdlib.h>
+#include <assert.h>
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace/std/iostream>
+#  include <ospace/std/fstream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#  include <fstream.h>
+#else
+#  include <iostream>
+#  include <fstream>
+#endif
+
+#ifdef USE_FASTCGI
+#include "fcgiapp.h"
+#endif
+
+
+#ifdef USE_FASTCGI
+// used to output the text from receptionist
+class fcgistreambuf : public streambuf {
+public:
+  fcgistreambuf ();
+  int sync ();
+  int overflow (int ch);
+  int underflow () {return EOF;}
+  
+  void fcgisbreset() {fcgx_stream = NULL; other_ostream = NULL;};
+  void set_fcgx_stream(FCGX_Stream *newone) {fcgx_stream=newone;};
+  void set_other_ostream(ostream *newone) {other_ostream=newone;};
+  
+private:
+  FCGX_Stream *fcgx_stream;
+  ostream *other_ostream;
+};
+
+fcgistreambuf::fcgistreambuf() {
+  fcgisbreset();
+  if (base() == ebuf()) allocate();
+  setp (base(), ebuf());
+};
+
+int fcgistreambuf::sync () {
+  if ((fcgx_stream != NULL) &&
+      (FCGX_PutStr (pbase(), out_waiting(), fcgx_stream) < 0)) {
+    fcgx_stream = NULL;
+  }
+
+  if (other_ostream != NULL) {
+    char *thepbase=pbase();
+    for (int i=0;i<out_waiting();++i) (*other_ostream).put(thepbase[i]);
+  }
+  
+  setp (pbase(), epptr());
+  
+  return 0;
+}
+
+int fcgistreambuf::overflow (int ch) {
+  if (sync () == EOF) return EOF;
+  if (ch != EOF) sputc (ch);
+  return 0;
+}
+
+#endif
+
+static void format_error_string (text_t &errorpage, const text_t &errortext, bool debug) {
+
+  errorpage.clear();
+
+  if (debug) {
+    errorpage += "\n";
+    errorpage += "ERROR: " + errortext;
+    errorpage += "\n";
+    
+  } else {
+
+    errorpage += "Content-type: text/html\n\n";
+    
+    errorpage += "<html>\n";
+    errorpage += "<head>\n";
+    errorpage += "<title>Error</title>\n";
+    errorpage += "</head>\n";
+    errorpage += "<body>\n";
+    errorpage += "<h2>Oops!</h2>\n";
+    errorpage += errortext;
+    errorpage += "</body>\n";
+    errorpage += "</html>\n";
+  }
+}
+
+static void page_errorcollect (const text_t &gsdlhome, text_t &errorpage, bool debug) {
+
+  text_t collecthome = filename_cat (gsdlhome, "collect");
+
+  text_t errortext = "No valid collections were found: Check that your collect directory\n";
+  errortext += "(" + collecthome + ") is readable and contains at least one valid collection.\n";
+  errortext += "Note that modelcol is NOT a valid collection.\n";
+  errortext += "If the path to your collect directory is wrong edit the 'gsdlhome' field\n";
+  errortext += "in your gsdlsite.cfg configuration file.\n";
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+static void page_errorsitecfg (text_t &errorpage, bool debug, int mode) {
+
+  text_t errortext;
+
+  if (mode == 0) {
+    errortext += "The gsdlsite.cfg configuration file could not be found. This\n";
+    errortext += "file should contain configuration information relating to this\n";
+    errortext += "site's setup.\n";
+
+  } else if (mode == 1) {
+    errortext += "The gsdlsite.cfg configuration file does not contain a valid\n";
+    errortext += "gsdlhome entry.\n";
+  }
+
+  if (debug) {
+    errortext += "gsdlsite.cfg should reside in the directory from which the\n";
+    errortext += "library executable was run.\n";
+  } else {
+    errortext += "gsdlsite.cfg should reside in the same directory as the library\n";
+    errortext += "executable file.\n";
+  }
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+
+static void page_errormaincfg (const text_t &gsdlhome, const text_t &collection,
+			       bool debug, text_t &errorpage) {
+
+  text_t errortext;
+
+  if (collection.empty()) {
+    text_t main_cfg_file = filename_cat (gsdlhome, "etc", "main.cfg");
+    errortext += "The main.cfg configuration file could not be found. This file\n";
+    errortext += "should contain configuration information relating to the\n";
+    errortext += "setup of the interface. As this receptionist is not being run\n";
+    errortext += "in collection specific mode the file should reside at\n";
+    errortext += main_cfg_file + ".\n";
+  } else {
+    text_t collect_cfg_file = filename_cat (gsdlhome, "collect", collection, "etc", "collect.cfg");
+    text_t main_collect_cfg_file = filename_cat (gsdlhome, "etc", "collect.cfg");
+    text_t main_cfg_file = filename_cat (gsdlhome, "etc", "main.cfg");
+    errortext += "Either the collect.cfg or main.cfg configuration file could\n";
+    errortext += "not be found. This file should contain configuration information\n";
+    errortext += "relating to the setup of the interface. As this receptionist is\n";
+    errortext += "being run in collection specific mode the file should reside\n";
+    errortext += "at either " + collect_cfg_file + ",\n";
+    errortext += main_collect_cfg_file + " or " + main_cfg_file + ".\n";
+  }
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+
+static void page_errorinit (const text_t &gsdlhome, bool debug, text_t &errorpage) {
+
+  text_t errortext = "An error occurred during the initialisation of the Greenstone Digital\n";
+  errortext += "Library software. It is likely that the software has not been setup\n";
+  errortext += "correctly.\n";
+
+  text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
+  char *efile = error_file.getcstr();
+  ifstream errin (efile);
+  delete []efile;
+  if (errin) {
+    errortext += "The error log, " + error_file + ", contains the\n";
+    errortext += "following information:\n\n";
+    if (!debug) errortext += "<pre>\n";
+
+    char c;
+    errin.get(c);
+    while (!errin.eof ()) {
+      errortext.push_back(c);
+      errin.get(c);
+    }
+    
+    if (!debug) errortext += "</pre>\n";
+
+    errin.close();
+
+  } else {
+    errortext += "Please consult " + error_file + " for more information.\n";
+  }
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+static void page_errorparseargs (const text_t &gsdlhome, bool debug, text_t &errorpage) {
+
+  text_t errortext = "An error occurred during the parsing of the cgi arguments.\n";
+
+  text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
+  char *efile = error_file.getcstr();
+  ifstream errin (efile);
+  delete []efile;
+  if (errin) {
+    errortext += "The error log, " + error_file + ", contains the\n";
+    errortext += "following information:\n\n";
+    if (!debug) errortext += "<pre>\n";
+
+    char c;
+    errin.get(c);
+    while (!errin.eof ()) {
+      errortext.push_back(c);
+      errin.get(c);
+    }
+    if (!debug) errortext += "</pre>\n";
+    errin.close();
+
+  } else {
+    errortext += "Please consult " + error_file + " for more information.\n";
+  }
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+static void page_errorcgipage (const text_t &gsdlhome, bool debug, text_t &errorpage) {
+
+  text_t errortext = "An error occurred during the construction of the cgi page.\n";
+
+  text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
+  char *efile = error_file.getcstr();
+  ifstream errin (efile);
+  delete []efile;
+  if (errin) {
+    errortext += "The error log, " + error_file + ", contains the\n";
+    errortext += "following information:\n\n";
+    if (!debug) errortext += "<pre>\n";
+
+    char c;
+    errin.get(c);
+    while (!errin.eof ()) {
+      errortext.push_back(c);
+      errin.get(c);
+    }
+    if (!debug) errortext += "</pre>\n";
+    errin.close();
+
+  } else {
+    errortext += "Please consult " + error_file + " for more information.\n";
+  }
+
+  format_error_string (errorpage, errortext, debug);
+}
+
+static void print_debug_info (receptionist &recpt) {
+
+  outconvertclass text_t2ascii;
+  const recptconf &configinfo = recpt.get_configinfo ();
+  text_t etc_dir = filename_cat (configinfo.gsdlhome, "etc");
+
+  cout << "\n";
+  cout << text_t2ascii
+       << "------------------------------------------------------------\n"
+       << "Configuration and initialization completed successfully.\n"
+       << "  Note that more debug information may be available in the\n"
+       << "  initialization and error log error.txt in " << etc_dir << ".\n"
+       << "------------------------------------------------------------\n\n";
+
+  bool colspec = false;
+  if (configinfo.collection.empty()) {
+    cout << "Receptionist is running in \"general\" (i.e. not \"collection "
+	 << "specific\") mode.\n";
+  } else {
+    cout << text_t2ascii 
+	 << "Receptionist is running in \"collection specific\" mode.\n"
+	 << "  collection=" << configinfo.collection << "\n"
+	 << "  collection directory=" << configinfo.collectdir << "\n";
+    colspec = true;
+  }
+  
+  cout << text_t2ascii << "  gsdlhome=" << configinfo.gsdlhome << "\n";
+  if (!configinfo.collecthome.empty())
+    cout << text_t2ascii << "  collecthome=" << configinfo.collecthome << "\n";
+  if (!configinfo.dbhome.empty())
+    cout << text_t2ascii << "  dbhome=" << configinfo.dbhome << "\n";
+  cout << text_t2ascii << "  httpprefix=" << configinfo.httpprefix << "\n";
+  cout << text_t2ascii << "  httpimg=" << configinfo.httpimg << "\n";
+  cout << text_t2ascii << "  gwcgi=" << configinfo.gwcgi << "\n\n"
+       << "  Note that unless gwcgi has been set from a configuration\n"
+       << "  file it is dependent on environment variables set by your\n"
+       << "  webserver. Therefore it may not have the same value when run\n"
+       << "  from the command line as it would be when run from your\n"
+       << "  web server.\n";
+  if (configinfo.usecookies) 
+    cout << "cookies are enabled\n";
+  else 
+    cout << "cookies are disabled\n";
+  if (configinfo.logcgiargs) 
+    cout << "logging is enabled\n";
+  else 
+    cout << "logging is disabled\n";
+  cout << "------------------------------------------------------------\n\n";
+
+  text_tset::const_iterator this_mfile = configinfo.macrofiles.begin();
+  text_tset::const_iterator end_mfile = configinfo.macrofiles.end();
+  cout << "Macro Files:\n"
+       << "------------\n";
+  text_t mfile;
+  bool found;
+  while (this_mfile != end_mfile) {
+    cout << text_t2ascii << *this_mfile;
+    int spaces = (22 - (*this_mfile).size());
+    if (spaces < 2) spaces = 2;
+    text_t outspaces;
+    for (int i = 0; i < spaces; ++i) outspaces.push_back (' ');
+    cout << text_t2ascii << outspaces;
+
+    found = false;
+    if (colspec) {
+      // collection specific - try collectdir/macros first
+      mfile = filename_cat (configinfo.collectdir, "macros", *this_mfile);
+      if (file_exists (mfile)) {
+	cout << text_t2ascii << "found (" << mfile << ")\n";
+	found = true;
+      }
+    }
+ 
+    if (!found) {
+      // try main macro directory
+      mfile = filename_cat (configinfo.gsdlhome, "macros", *this_mfile);
+      if (file_exists (mfile)) {
+	cout << text_t2ascii << "found (" << mfile << ")\n";
+	found = true;
+      }
+    }
+
+    if (!found)
+      cout << text_t2ascii << "NOT FOUND\n";
+
+    ++this_mfile;
+  }
+
+  cout << "------------------------------------------------------------\n\n"
+       << "Collections:\n"
+       << "------------\n"
+       << "  Note that collections will only appear as \"running\" if\n"
+       << "  their build.cfg files exist, are readable, contain a valid\n"
+       << "  builddate field (i.e. > 0), and are in the collection's\n"
+       << "  index directory (i.e. NOT the building directory)\n\n";
+
+  recptprotolistclass *protos = recpt.get_recptprotolist_ptr();
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+
+  bool is_z3950 = false;
+  bool found_valid_col = false;
+
+
+  while (rprotolist_here != rprotolist_end) {
+    comerror_t err;    
+    if ((*rprotolist_here).p == NULL) continue;
+    else if (is_z3950==false &&
+	     (*rprotolist_here).p->get_protocol_name(err) == "z3950proto") {
+      cout << "\nZ39.50 Servers:   (always public)\n"
+	   << "---------------\n";
+      is_z3950=true;
+    }
+
+    text_tarray collist;
+    (*rprotolist_here).p->get_collection_list (collist, err, cerr);
+    if (err == noError) {
+      text_tarray::iterator collist_here = collist.begin();
+      text_tarray::iterator collist_end = collist.end();
+      
+      while (collist_here != collist_end) {
+	
+	cout << text_t2ascii << *collist_here;
+	
+	int spaces = (22 - (*collist_here).size());
+	if (spaces < 2) spaces = 2;
+	text_t outspaces;
+	for (int i = 0; i < spaces; ++i) outspaces.push_back (' ');
+	cout << text_t2ascii << outspaces;
+	
+	  ColInfoResponse_t *cinfo = recpt.get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, cerr);
+	  if (cinfo != NULL) {
+	    if (cinfo->isPublic) cout << "public ";
+	    else cout << "private";
+
+	    if (cinfo->buildDate > 0) {
+	      cout << "   running    ";
+	      found_valid_col = true;
+	    } else {
+	      cout << "   not running";
+	    }
+	  }
+
+	  cout << "\n";
+
+	  ++collist_here;
+      }
+    }
+    is_z3950=false;
+    ++rprotolist_here;
+  } // end of while loop
+
+  if (!found_valid_col) {
+    cout << "WARNING: No \"running\" collections were found. You need to\n";
+    cout << "         build one of the above collections\n";
+  }
+
+  cout << "\n------------------------------------------------------------\n";
+  cout << "------------------------------------------------------------\n\n";
+  cout << "receptionist running in command line debug mode\n";
+  cout << "enter cgi arguments as name=value pairs (e.g. 'a=p&p=home'):\n";
+
+}
+
+// cgiwrapper does everything necessary to output a page
+// using the cgi protocol. If this is being run for a particular
+// collection then "collection" should be set, otherwise it
+// should equal "".
+void cgiwrapper (receptionist &recpt, text_t collection) {
+  int numrequests = 0;
+  bool debug = false;
+  const recptconf &configinfo = recpt.get_configinfo ();
+
+  // find out whether this is being run as a cgi-script
+  // or a fastcgi script
+#ifdef USE_FASTCGI
+  fcgistreambuf outbuf;
+  int isfastcgi = !FCGX_IsCGI();
+  FCGX_Stream *fcgiin, *fcgiout, *fcgierr;
+  FCGX_ParamArray fcgienvp;
+#else
+  int isfastcgi = 0;
+#endif
+
+  // we need gsdlhome to do fileupload stuff, so moved this configure stuff before the get argstr stuff
+  // init stuff - we can't output error pages directly with
+  // fastcgi so the pages are stored until we can output them
+  text_t errorpage;
+  outconvertclass text_t2ascii;
+
+  // set defaults
+  int maxrequests = 10000;
+  recpt.configure ("collection", collection);
+  recpt.configure ("httpimg", "/gsdl/images");
+  char *script_name = getenv("SCRIPT_NAME");
+  if (script_name != NULL) recpt.configure("gwcgi", script_name);
+  else recpt.configure("gwcgi", "/gsdl");
+
+  // read in the configuration files.
+  text_t gsdlhome;
+  text_t collecthome;
+  configurator gsdlconfigurator(&recpt);
+  if (!site_cfg_read (gsdlconfigurator, gsdlhome, collecthome, maxrequests)) {
+    // couldn't find the site configuration file
+    page_errorsitecfg (errorpage, debug, 0);
+  } else if (gsdlhome.empty()) {
+    // no gsdlhome in gsdlsite.cfg
+    page_errorsitecfg (errorpage, debug, 1);
+  } else if (!directory_exists(gsdlhome)) {
+    // gsdlhome not a valid directory
+    page_errorsitecfg (errorpage, debug, 1);
+  } else if (!main_cfg_read (recpt, gsdlhome, collecthome, collection)) {
+    // couldn't find the main configuration file
+    page_errormaincfg (gsdlhome, collection, debug, errorpage);
+  } else  if (configinfo.collectinfo.empty() && false) { // commented out for corba
+    // don't have any collections
+    page_errorcollect (gsdlhome, errorpage, debug);
+  }
+  // get the query string if it is not being run as a fastcgi
+  // script
+  text_t argstr = g_EmptyText;
+  fileupload_tmap fileuploads;
+  cgiargsclass args;
+  char *aURIStr;
+  if (!isfastcgi) {
+    char *request_method_str = getenv("REQUEST_METHOD");
+    char *content_length_str = getenv("CONTENT_LENGTH");
+    if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
+	content_length_str != NULL)  {
+      // POST form data
+      long content_length = (content_length_str ? atoi(content_length_str) : 0);
+      if (content_length > 0) {
+#ifdef __WIN32__
+	// On Windows it is important that standard input be read in binary
+	// mode, otherwise end of line "<CR><LF>" is turned into <LF> only
+	// which breaks the MIME standard (and our parsing code!)
+
+	int result = _setmode( _fileno( stdin ), _O_BINARY );
+	if( result == -1 ) {
+	  cerr << "Warning: Failed to set standard input to binary mode." << endl;
+	  cerr << "         Parsing of multi-part MIME will most likely fail" << endl;
+	}
+#endif
+
+	long length = content_length;
+	unsigned char * buffer = new unsigned char[content_length];
+
+	int chars_read = fread(buffer,1,content_length,stdin);
+
+	if (chars_read != content_length) {
+	  cerr << "Warning: mismatch between CONTENT_LENGTH and data read from standard in" << endl;
+	}
+
+	argstr.setcarr((char *)buffer, content_length);     
+
+	text_t content_type;
+	char *content_type_str = getenv("CONTENT_TYPE");
+	if (content_type_str) content_type = content_type_str;
+	argstr = parse_post_data(content_type, argstr, fileuploads, gsdlhome);
+      }
+    } else {
+      aURIStr = getenv("QUERY_STRING");
+      if ((request_method_str != NULL && strcmp(request_method_str, "GET") == 0)
+	  || aURIStr != NULL) {
+	// GET form data
+	if (aURIStr != NULL) argstr = aURIStr;
+      } else {
+	// debugging from command line
+	debug = true;
+      }
+    }
+  }
+
+  if (debug) {
+    cout << "Configuring Greenstone...\n";
+    cout << flush;
+  }
+
+
+  if (errorpage.empty()) {
+
+    // initialise the library software
+    if (debug) {
+      cout << "Initializing...\n";
+      cout << flush;
+    }
+
+    text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
+    char *eout = error_file.getcstr();
+    ofstream errout (eout, ios::app);
+    delete []eout;
+    if (!recpt.init(errout)) {
+      // an error occurred during the initialisation
+      errout.close();
+      page_errorinit(gsdlhome, debug, errorpage);
+    }
+    errout.close();
+  }
+
+  if (debug && errorpage.empty()) {
+    // get query string from command line
+    print_debug_info (recpt);
+    char cinURIStr[1024];
+    cin.get(cinURIStr, 1024);
+    argstr = cinURIStr;
+  }
+
+  // cgi scripts only deal with one request
+  if (!isfastcgi) maxrequests = 1;
+
+  // Page-request loop. If this is not being run as a fastcgi
+  // process then only one request will be processed and then
+  // the process will exit.
+  while (numrequests < maxrequests) {
+#ifdef USE_FASTCGI
+    if (isfastcgi) {
+      if (FCGX_Accept(&fcgiin, &fcgiout, &fcgierr, &fcgienvp) < 0) break;
+
+      char *request_method_str = FCGX_GetParam ("REQUEST_METHOD", fcgienvp);
+      char *content_length_str = FCGX_GetParam ("CONTENT_LENGTH", fcgienvp);
+
+      if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
+	  content_length_str != NULL)  {
+	// POST form data
+	int content_length = text_t(content_length_str).getint();
+	if (content_length > 0) {
+	  argstr.clear();
+	  int c;
+	  do {
+	    c = FCGX_GetChar (fcgiin);
+	    if (c < 0) break;
+	    argstr.push_back (c);
+	    --content_length;
+	  } while (content_length > 0);
+	}
+
+      } else {
+	// GET form data
+	aURIStr = FCGX_GetParam("QUERY_STRING", fcgienvp);
+	if (aURIStr != NULL) argstr = aURIStr;
+	else argstr = g_EmptyText;
+      }
+    }
+#endif
+
+    // get output streams ready
+#ifdef USE_FASTCGI
+    outbuf.fcgisbreset ();
+    if (isfastcgi) outbuf.set_fcgx_stream (fcgiout);
+    else outbuf.set_other_ostream (&cout);
+    ostream pageout (&outbuf);
+#else
+#define pageout cout
+#endif
+
+    // if using fastcgi we'll load environment into a map,
+    // otherwise simply pass empty map (can't get environment
+    // variables using getenv() while using FCGX versions
+    // of fastcgi - at least I can't ;-) - Stefan)
+    text_tmap fastcgienv;
+#ifdef USE_FASTCGI
+    if (isfastcgi) {
+      for(; *fcgienvp != NULL; ++fcgienvp) {
+	text_t fvalue = *fcgienvp;
+	text_t::const_iterator begin = fvalue.begin();
+	text_t::const_iterator end = fvalue.end();
+	text_t::const_iterator equals_sign = findchar (begin, end, '=');
+	if (equals_sign != end)
+	  fastcgienv[substr(begin, equals_sign)] = substr(equals_sign+1, end);
+      }
+    }
+#endif
+
+    // temporarily need to configure gwcgi here when using fastcgi as I can't
+    // get it to pass the SCRIPT_NAME environment variable to the initial 
+    // environment (if anyone can work out how to do this using the apache 
+    // server, let me know). Note that this overrides the gwcgi field in 
+    // site.cfg (which it shouldn't do) but I can't at present set gwcgi 
+    // from site.cfg as I have old receptionists laying around that wouldn't
+    // appreciate it. The following 5 lines of code should be deleted once
+    // I either a: get the server to pass SCRIPT_NAME at initialization
+    // time or b: convert all the collections using old receptionists over
+    // to this version and uncomment gwcgi in the site.cfg file -- Stefan.
+#ifdef USE_FASTCGI
+    if (isfastcgi) {
+      recpt.configure("gwcgi", fastcgienv["SCRIPT_NAME"]);
+    }
+#endif
+
+
+    // if there has been no error so far, perform the production of the
+    // output page
+    if (errorpage.empty()) {
+      text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
+      char *eout = error_file.getcstr();
+      ofstream errout (eout, ios::app);
+      delete []eout;
+
+#if defined(__WIN32__) && defined(GSDL_USE_IOS_H)
+      // old Windows compilers (VC++4.2)
+      cerr = errout;
+#else
+      // can't do this anymore according to c++ standard...
+      // cerr = errout;
+      // ... but can do this instead
+      streambuf* errbuf = cerr.rdbuf(errout.rdbuf());
+#endif
+
+      // parse the cgi arguments and produce the resulting page if there
+      // has been no errors so far
+      if (!recpt.parse_cgi_args (argstr, fileuploads, args, errout, fastcgienv)) {
+	errout.close ();
+	page_errorparseargs(gsdlhome, debug, errorpage);
+      } else {
+	// produce the output page
+
+	if (!recpt.produce_cgi_page (args, pageout, errout, fastcgienv)) {
+	  errout.close ();
+	  page_errorcgipage(gsdlhome, debug, errorpage);
+	}
+	recpt.log_cgi_args (args, errout, fastcgienv);
+	errout.close ();
+      }
+
+#if !defined(__WIN32__) || !defined(GSDL_USE_IOS_H)
+    // restore the cerr buffer
+    cerr.rdbuf(errbuf);
+#endif
+    }
+    // clean up any files that were uploaded 
+    fileupload_tmap::const_iterator this_file = fileuploads.begin();
+    fileupload_tmap::const_iterator end_file = fileuploads.end();
+    while (this_file != end_file)
+      {
+	if (file_exists((*this_file).second.tmp_name)) 
+	  {
+	    char *thefile = (*this_file).second.tmp_name.getcstr();
+	    unlink(thefile);
+	    delete [] thefile;
+	  }
+	++this_file;
+      }
+    
+    // there was an error, output the error page
+    if (!errorpage.empty()) {
+      pageout << text_t2ascii << errorpage;
+      errorpage.clear();
+      numrequests = maxrequests; // make this the last page
+    }
+    pageout << flush;
+    
+    // finish with the output streams
+#ifdef USE_FASTCGI
+    if (isfastcgi) FCGX_Finish();
+#endif
+
+    ++numrequests;
+  }
+
+  return;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/cgiwrapper.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/cgiwrapper.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/cgiwrapper.h	(revision 16571)
@@ -0,0 +1,44 @@
+/**********************************************************************
+ *
+ * cgiwrapper.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef CGIWRAPPER_H
+#define CGIWRAPPER_H
+
+
+#include "receptionist.h"
+
+// cgiwrapper does everything necessary to output a page
+// using the cgi protocol. If this is being run for a particular
+// collection then "collection" should be set, otherwise it
+// should equal "".
+//
+// NB: the collectset MAY NOT exist for remote protocols (e.g.
+//     the corba protocol; as references must point to a non-
+//     null instance, we must therefore use a pointer - sorry!
+void cgiwrapper (receptionist &recpt, text_t collection);
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/collectoraction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/collectoraction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/collectoraction.cpp	(revision 16571)
@@ -0,0 +1,1476 @@
+/**********************************************************************
+ *
+ * collectoraction.cpp -- 
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_COLLECTOR_ACTION
+
+// note that the collectoraction relies on having direct access to a
+// collections configuration file. this breaks the separation between
+// receptionist and collection server and so is not suitable (at least
+// in its current form) for use when collection servers are separate 
+// from the receptionist (e.g. when using the CORBA protocol).
+
+// following line required to get fstream.filedesc() on darwin (Mac OS X)
+#define _STREAM_COMPAT  1
+// required for utsname on solaris???
+#define _XOPEN_SOURCE 1
+#define _XOPEN_SOURCE_EXTENDED 1
+
+#include "collectoraction.h"
+#include "OIDtools.h"
+#include "fileutil.h"
+#include "cfgread.h"
+#include "gsdltools.h"
+#include "gsdltimes.h"
+#include "argdb.h"
+#include "cgiutils.h"
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#if !defined (__WIN32__)
+#include <sys/utsname.h>
+#include <unistd.h>
+#endif
+
+collectoraction::collectoraction () 
+  : wizardaction()
+{
+  macro_prefix = "bc1";
+
+  do_mkcol = false;
+  badsources = false;
+  failedsources.erase(failedsources.begin(), failedsources.end());
+
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "collector";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "p";
+  arg_ainfo.longname = "page";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "intro";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // temporary directory name for this collector
+  // session
+  arg_ainfo.shortname = "bc1tmp";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bc1fullname";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bc1dirname";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bc1contactemail";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bc1aboutdesc";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bc1clone";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bc1clonecol";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // set when cloning option has changed
+  arg_ainfo.shortname = "bc1clonechanged";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot; 
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // only set when one of the fields was changed in
+  // the "collection info" page
+  arg_ainfo.shortname = "bc1infochanged";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // only set when cfg file is altered from within
+  // "configure collection" page
+  arg_ainfo.shortname = "bc1cfgchanged";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "cfgfile";
+  arg_ainfo.longname = "configuration file contents";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bc1dodelete";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // will be set if we arrived at the "configure collection" page
+  // via the "changing an existing collection" page
+  arg_ainfo.shortname = "bc1econf";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // will be set if we arrived at the "source data" page
+  // via the "changing an existing collection" page
+  arg_ainfo.shortname = "bc1esrce";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bc1inputnum";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "3";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bc1input";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.multiplevalue = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bc1inputtype";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.multiplevalue = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // will be set when we've just come from the "source data" page
+  arg_ainfo.shortname = "bc1fromsrce";
+  arg_ainfo.longname = "collector specific";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.multiplevalue = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+}
+
+collectoraction::~collectoraction () {
+}
+
+
+
+bool collectoraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+				     recptprotolistclass * /*protos*/, ostream &logout) {
+
+  text_t &current_page = args["p"];
+
+  // note that the "bildstatus" and "bildframe1" pages don't actually do anything
+  // functional so we don't need to worry about authenticating them (it's the 
+  // underlying "bild" page that does the building (and creates the frameset))
+  // This helps us overcome a bit of a problem we have with multiple pages trying
+  // to read from the key.db database at the same time.
+  if (current_page != "intro" && current_page != "bildstatus" && current_page != "bildframe1") {
+    // authenticate the user if authentication is available
+    args["uan"] = 1;
+    args["ug"] = "all-collections-editor";
+  }
+  
+  if (current_page == "new" || current_page == "existing") {
+
+    // assign (and create) a temporary directory 
+    if (assign_tmpname (args, logout)==false) {
+      // there was an error creating the tmp dir
+      message="tmpfail";
+      return true; // true because we could still parse the arguments
+    }
+
+    // clean up any old builds left laying about in the tmp directory
+    // (note that it's possible this could take some time if there's a huge
+    // partially built collecton laying about so we'll make it an asynchronous
+    // system call)
+    gsdl_system ("perl -S cleantmp.pl", false, logout);
+  }
+
+  if (current_page != "intro" && current_page != "bildstatus" && 
+      current_page != "bildframe1" && current_page != "new") {
+    // update arguments that were saved to the harddrive
+    text_tmap saved_args;
+    saved_args["bc1fullname"] = g_EmptyText;
+    saved_args["bc1contactemail"] = g_EmptyText;
+    saved_args["bc1aboutdesc"] = g_EmptyText;
+    saved_args["bc1clone"] = g_EmptyText;
+    saved_args["bc1clonecol"] = g_EmptyText;
+    saved_args["bc1inputnum"] = g_EmptyText;
+    saved_args["bc1input"] = g_EmptyText;
+    saved_args["bc1inputtype"] = g_EmptyText;
+
+    // update the argdb database with any arguments that were set
+    // by previous page
+    text_tmap::iterator here = saved_args.begin();
+    text_tmap::iterator end = saved_args.end();
+    while (here != end) {
+      if (args.lookupcgiarg((*here).first).source != cgiarg_t::default_arg) {
+	(*here).second = args[(*here).first];
+      }
+      ++here;
+    }
+
+    text_t argfile = filename_cat(gsdlhome, "tmp", args["bc1tmp"], "argdb.db");
+    argdb *args_on_disk = new argdb(argfile);
+    if (!args_on_disk->update_args(saved_args)) {
+      // error
+      logout << "collectoraction: argdb::update_args failed (" << argfile << ")\n";
+    }
+
+    // update args from argdb
+    saved_args.erase(saved_args.begin(), saved_args.end());
+    if (!args_on_disk->get_args(saved_args)) {
+      // error
+      logout << "collectoraction: argdb::get_args failed (" << argfile << ")\n";
+    }
+    delete args_on_disk;
+    here = saved_args.begin();
+    end = saved_args.end();
+    while (here != end) {
+      if (!(*here).second.empty()) {
+	args[(*here).first] = (*here).second;
+      }
+      ++here;
+    }
+  }
+
+  if (args["bc1infochanged"] == "1") {
+    
+    if (args["bc1dirname"].empty()) {
+      // we've just come from the "collection information" page for the 
+      // first time so we'll need to create the collection with mkcol.pl
+      // and set up bc1dirname - we do this part here instead of in do_action
+      // because the bc1dirname argument must be set to its new value before
+      // the compressedoptions macros are set.
+      args["bc1dirname"] = get_directory_name (args["bc1fullname"]);
+
+      text_t createfile = filename_cat (gsdlhome, "tmp", args["bc1tmp"], ".create");
+      if (!file_exists (createfile)) {
+	// we could do the mkcol.pl here but I guess it's nicer to do it in do_action()
+	do_mkcol = true; 
+      } else {
+	// .create file already exists but bc1dirname wasn't set ... this should only be
+	// able to occur when the "reload" (and possibly the "back" and "forward" buttons)
+	// have been used to get us here.
+	// we'll check that the bc1dirname directory exists (in case of the unlikely 
+	// possibility that get_directory_name returned a different value this time
+	// than it did originally).
+	text_t coldir = filename_cat (get_collectdir(args), args["bc1dirname"]);
+	if (!directory_exists (coldir)) {
+	  message = "reloaderror";
+	  return true;
+	}
+      }
+    } else {
+      // "collection information" has been changed after collection already exists
+      // so we'll need to update the cfg file.
+      update_cfgfile_partial (args, false, logout);
+    }
+  }
+
+  if (args["bc1cfgchanged"] == "1") {
+    // configuration file has been changed from the "configure collection"
+    // page. we need to update the file on disk and catch bc1 arguments up
+    // with changes.
+    update_cfgfile_complete (args, logout);
+  }
+  
+  if (args["bc1clonechanged"] == "1") {
+    // cloning option has been changed on "source data" page. if it was turned 
+    // on we want to create a new collect.cfg file using the bc1clonecol cfg file
+    // as a model (we'll save the old file as collect.cfg.org). if cloning was
+    // turned off we'll revert to using the collect.cfg.org file (which will need
+    // updating in case the bc1 arguments have been altered since cloning was 
+    // turned on).
+    update_cfgfile_clone (args, logout);
+
+    // if cloning has just been turned on we'll also copy the rest of the files 
+    // (excluding collect.cfg which we've already done) from the cloned collections
+    // etc directory to the new collection.
+    if (args["bc1clone"] == "1") {
+      text_t clone_etc = filename_cat(collecthome, args["bc1clonecol"], "etc");
+      text_t new_etc = filename_cat(get_collectdir(args), args["bc1dirname"], "etc");
+      text_tarray files;
+
+      if (read_dir (clone_etc, files)) {
+	text_tarray::const_iterator here = files.begin();
+	text_tarray::const_iterator end = files.end();
+	while (here != end) {
+	  if (*here != "collect.cfg" && *here != "collect.cfg.org") {
+	    file_copy (filename_cat(clone_etc, *here), filename_cat(new_etc, *here));
+	  }
+	  ++here;
+	}
+      } else {
+	outconvertclass text_t2ascii;
+	logout <<text_t2ascii << "collectoraction::check_cgiargs couldn't read from " 
+	       << clone_etc << " directory\n";
+      }
+    }
+  }
+  
+  if (current_page == "bildstatus" || current_page == "bildcancel") {
+    // if .final file exists then build has finished
+    text_t fbld = filename_cat (gsdlhome, "tmp", args["bc1tmp"], args["bc1dirname"] + ".bld.final");
+    if (file_exists (fbld)) {
+      char *fbldc = fbld.getcstr();
+      ifstream fbld_in (fbldc);
+      if (fbld_in) {
+	failcode = fbld_in.get();
+	fbld_in.close();
+	if (failcode == '0') {
+	  // success - we need to create and configure a collection server for the
+	  // newly built collection (for fastcgi and local library where
+	  // initialization isn't going to be redone when the user clicks the
+	  // "view your new collection" button
+	  create_colserver (args["bc1dirname"], logout);
+	  current_page = "bilddone";
+	}
+	else current_page = "bildfail";
+      } else {
+	// assume build failed (we shouldn't get here though ... right?)
+	current_page = "bildfail";
+      }
+      delete []fbldc;
+    }
+  }
+
+  if (args["bc1fromsrce"] == "1") {
+
+    // we've just come from the "source data" page so we need to check that
+    // input sources are valid
+    if (!check_sources(args, logout)) {
+      args["p"] = "srce";
+    }
+  }
+
+  return true;
+}
+
+void collectoraction::update_cfgfile_clone (cgiargsclass &args, ostream &logout) {
+
+  text_t tmpdir = filename_cat(gsdlhome, "tmp", args["bc1tmp"]);
+  text_t cfgfile = filename_cat(tmpdir, args["bc1dirname"], "etc", "collect.cfg");
+  if (!file_exists (cfgfile)) {
+    message = "tmpfail";
+    return;
+  }
+
+  text_t cfgfile_org = filename_cat (tmpdir, "collect.cfg.org");
+
+  if (args["bc1clone"] == "1") {
+    // cloning was turned on
+
+    text_t cfgfile_clone = filename_cat(collecthome, args["bc1clonecol"], "etc", "collect.cfg");
+    if (file_exists (cfgfile_clone)) {
+      // if .org file doesn't exist already create it
+      if (!file_exists (cfgfile_org)) {
+	if (!file_copy (cfgfile, cfgfile_org)) {
+	  message = "tmpfail";
+	  return;
+	}
+      }
+      // copy clone collections cfg file to new collection
+      if (!file_copy (cfgfile_clone, cfgfile)) {
+	message = "tmpfail";
+	return;
+      }
+      // update the new cfg file
+      update_cfgfile_partial (args, true, logout);
+      
+    } else {
+      // can't clone non-existant or read-protected collection
+      message = "clonefail";
+    }
+
+  } else {
+    // cloning has been turned off having been on at some point. the .org file
+    // should exist, if it doesn't we'll bail out and leave the user with the 
+    // cloned copy
+    if (file_exists (cfgfile_org)) {
+      // copy original back again and update it with any recent changes
+      if (file_copy (cfgfile_org, cfgfile)) {
+	update_cfgfile_partial (args, false, logout);
+      } else {
+	message = "tmpfail";
+      }
+    }
+  }
+}
+
+// update configuration file on disk to match bc1 arguments
+// there's a special case if the clone option is true as certain parts of a
+// config file should not be cloned (e.g. the iconcollection stuff)
+void collectoraction::update_cfgfile_partial (cgiargsclass &args, bool clone, ostream &logout) {
+
+  text_t cfgfile = filename_cat(get_collectdir(args), args["bc1dirname"], "etc", "collect.cfg");
+  char *cfgfilec = cfgfile.getcstr();
+
+#if defined (__WIN32__)
+  // make sure collect.cfg isn't read-only
+  _chmod (cfgfilec, _S_IREAD | _S_IWRITE);
+#endif
+
+  vector<text_tarray> cfgarray;
+
+  // read in cfg file
+  ifstream cfg_in (cfgfilec);
+  if (cfg_in) {
+    text_tarray cfgline;
+    while (read_cfg_line(cfg_in, cfgline) >= 0) {
+      if (cfgline.size () >= 2) {
+	if (cfgline[0] == "creator" || cfgline[0] == "maintainer") {
+	  cfgline[1] = args["bc1contactemail"];
+	} else if (cfgline[0] == "collectionmeta") {
+	  if (cfgline[1] == "collectionname") {
+	    cfgline[2] = args["bc1fullname"];
+	  } else if (cfgline[1] == "collectionextra") {
+	    cfgline[2] = carriage_replace (args["bc1aboutdesc"], 0);
+	  } else if (clone && (cfgline[1] == "iconcollection" ||
+			       cfgline[1] == "iconcollectionsmall")) {
+	    cfgline[2] = g_EmptyText;
+	  }
+	}
+      }
+      cfgarray.push_back (cfgline);
+    }
+    cfg_in.close();
+    
+    // now write cfg file back out
+    int fd=open(cfgfilec, O_WRONLY | O_CREAT | O_TRUNC
+#if defined(__WIN32__)
+		| O_BINARY
+#endif
+		);
+
+    if (fd != -1) {
+      // lock the file
+      int lock_val = 1;
+      GSDL_LOCK_FILE (fd);
+      if (lock_val != 0) {
+	logout << "Error: Couldn't lock file " << cfgfilec << "\n";
+	close(fd);
+	message = "tmpfail";
+	
+      } else {
+
+	vector<text_tarray>::const_iterator this_line = cfgarray.begin();
+	vector<text_tarray>::const_iterator end_line = cfgarray.end();
+	while (this_line != end_line) {
+	  write_cfg_line (fd, *this_line);
+	  ++this_line;
+	}
+	GSDL_UNLOCK_FILE (fd);
+	close(fd);
+      }
+
+    } else {
+      logout << "collectoraction::update_cfgfile_partial: unable to open "
+	     << cfgfilec << " for output\n";
+      message = "tmpfail";
+    }
+    
+  } else {
+    logout << "collectoraction::update_cfgfile_partial: unable to open "
+	   << cfgfilec << " for input\n";
+    message = "tmpfail";
+  }
+
+  delete []cfgfilec;
+}
+
+// replace configuration file on disk with that in the cfgfile argument and 
+// catch other bc1 arguments up with those the new cfgfile contains
+void collectoraction::update_cfgfile_complete (cgiargsclass &args, ostream &logout) {
+
+  text_t cfgfile = filename_cat(get_collectdir(args), args["bc1dirname"], "etc", "collect.cfg");
+  char *cfgfilec = cfgfile.getcstr();
+
+#ifdef __WIN32__
+  // make sure collect.cfg isn't read-only
+  _chmod (cfgfilec, _S_IREAD | _S_IWRITE);
+#endif
+
+  int fd=open(cfgfilec, O_WRONLY | O_CREAT | O_TRUNC
+#if defined(__WIN32__)
+	      | O_BINARY
+#endif
+	      );
+
+  if (fd) {
+    // lock the file
+    int lock_val = 1;
+    GSDL_LOCK_FILE (fd);
+    if (lock_val != 0) {
+      logout << "Error: Couldn't lock file " << cfgfilec << "\n";
+      close(fd);
+      message = "tmpfail";
+      
+    } else {
+      
+      outconvertclass text_t2ascii;
+      text_t2ascii.setinput(&args["cfgfile"]);
+      size_t buffersize=args["cfgfile"].size();
+      char *buffer=new char[buffersize];
+      buffer[0]='\n'; // just in case something goes wrong...
+      size_t num_chars;
+      convertclass::status_t status;
+      text_t2ascii.convert(buffer, buffersize, num_chars, status);
+      // ignore status - assume it is "finished" as buffer is big enough
+      write(fd, buffer, num_chars);
+      GSDL_UNLOCK_FILE (fd);
+      close(fd);
+      delete []buffer;
+      
+      // now that we've written the file we'll read it back again and
+      // update our bc1 arguments
+      ifstream cfg_in (cfgfilec);
+      if (cfg_in) {
+	text_tarray cfgline;
+	while (read_cfg_line(cfg_in, cfgline) >= 0) {
+	  if (cfgline.size () >= 2) {
+	    if (cfgline[0] == "creator") {
+	      args["bc1contactemail"] = cfgline[1];
+	    } else if (cfgline[0] == "collectionmeta") {
+	      if (cfgline[1] == "collectionname") {
+		args["bc1fullname"] = cfgline[2];
+	      } else if (cfgline[1] == "collectionextra") {
+		args["bc1aboutdesc"] = carriage_replace (cfgline[2], 1);
+	      }
+	    }
+	  }
+	}
+	cfg_in.close();
+      } else {
+	logout << "collectoraction::update_cfgfile_complete: unable to open " 
+	       << cfgfilec << " for input\n";
+	message = "tmpfail";
+      }
+    }
+  } else {
+    logout << "collectoraction::update_cfgfile_complete: unable to open " 
+	   << cfgfilec << " for output\n";
+    message = "tmpfail";
+  }
+
+  delete []cfgfilec;
+}
+
+
+// return html for buttons used in collector bar
+// color may be "green", "grey", or "yellow"
+// type may be:
+//   "info" --> "collection information" button
+//   "srce" --> "source data" button
+//   "conf" --> "configure collection" button
+//   "bild" --> "build collection" button
+//   "view" --> "view collection" button
+// if enabled is true button will be flashy rollover type and 
+// will be hyperlinked
+
+// Wendy left a comment suggesting this be move, but where to
+// was not specified.  Into wizardaction.cpp?
+
+// set the _fullnamemenu_ macro (and _warnindex_ and _selectedindex_ if
+// we're on the "srce" page)
+void collectoraction::set_fullnamemenu (displayclass &disp, cgiargsclass &args, 
+					recptprotolistclass *protos, ostream &logout) {
+
+  if (recpt == NULL) {
+    logout << "ERROR (collectoraction::set_fullnamemenu): This action does not contain\n"
+	   << "       information about any receptionists. The method set_receptionist was\n"
+	   << "       probably not called from the module which instantiated this action.\n";
+    return;
+  }
+
+  text_t &current_page = args["p"];
+  text_t currentname = args[macro_prefix+"dirname"];
+  if (current_page == "srce") currentname = args[macro_prefix + "clonecol"];
+
+  text_tarray dirnames;
+  text_tarray fullnames;
+  vector<bool> write_protected;
+  bool is_selected = false;
+  int selected_index = 0;
+  int index = 0;
+
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    if ((*rprotolist_here).p != NULL) {
+
+      // don't include z39.50 collections
+      comerror_t err = noError;
+      if ((*rprotolist_here).p->get_protocol_name (err) == "z3950proto") {
+	++rprotolist_here;
+	continue;
+      }
+
+      text_tarray collist;
+      (*rprotolist_here).p->get_collection_list (collist, err, logout);
+      if (err == noError) {
+	text_tarray::iterator collist_here = collist.begin();
+	text_tarray::iterator collist_end = collist.end();
+	while (collist_here != collist_end) {
+	  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
+	  if (cinfo != NULL) {
+	    text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
+	    if (collectionname.empty()) {
+	      collectionname = *collist_here;
+	    }
+	    dirnames.push_back(*collist_here);
+	    fullnames.push_back(collectionname);
+	    // check to see if the collection is writable
+	    if (collection_protected (*collist_here)) write_protected.push_back(true);
+	    else write_protected.push_back(false);
+
+	    if (*collist_here == currentname) {
+	      is_selected = true;
+	      selected_index = index; 	    
+	    }
+	    ++index;
+	  }
+	  ++collist_here;
+	}
+      }
+    }
+    ++rprotolist_here;
+  }
+
+  bool first = true;
+
+  text_t warnindex;
+  text_t fullnamemenu = "<select name=\""+macro_prefix+"dirname\" onChange=\"menuchange();\">\n";
+
+  if (current_page == "srce") {
+    fullnamemenu = "<select name=\""+macro_prefix+"clonecol\" onChange=\"menuchange();\">\n";
+    fullnamemenu += "<option value=defaultstructure";
+    if (!is_selected) fullnamemenu += " selected>";
+    else fullnamemenu.push_back('>');
+    fullnamemenu += "_collector:textdefaultstructure_\n";
+  }
+
+  fullnamemenu += "<option value=\"\"></option>\n";
+
+  for (int i = 0; i < index; ++i) {
+    // don't want write protected collections in list on "change existing
+    // collection" page
+    if (write_protected[i] && current_page == "existing") continue;
+    fullnamemenu += "<option value=\"" + dirnames[i] + "\"";
+    if ((i == 0 && !is_selected && current_page != "srce") || 
+	(is_selected && i == selected_index)) {
+      fullnamemenu += " selected";
+      ++selected_index;
+      is_selected = false;
+    }
+    fullnamemenu.push_back ('>');
+    fullnamemenu += fullnames[i];
+    fullnamemenu.push_back ('\n');
+    
+    // add to Warnindex if collection uses any dubious plugins 
+    // (if creating clone collection list)
+    if (current_page == "srce") {
+      if (first) warnindex += "0,";
+      else warnindex.push_back(',');
+      if (uses_weird_plugin (dirnames[i])) {
+	warnindex += text_t (1);
+      } else {
+	warnindex += text_t (0);
+      }
+    }
+    first = false;
+  }
+  fullnamemenu += "</select>\n";
+  text_t action_name = get_action_name();
+  disp.setmacro ("fullnamemenu", action_name, fullnamemenu);
+  if (current_page == "srce") {
+    disp.setmacro ("warnindex",action_name , warnindex);
+    disp.setmacro ("selectedindex", action_name, text_t(selected_index));
+  }
+}
+
+
+// set _sourcelist_ and _badsources_ macros
+void collectoraction::set_inputsourceboxes (displayclass &disp, cgiargsclass &args, 
+					    ostream &logout) {
+  
+  if (badsources) disp.setmacro ("badsources", "collector", "1");
+
+  text_t sourcelist = get_source_box(args["bc1input"], args["bc1inputnum"].getint(),
+				     args["bc1inputtype"]);
+
+  disp.setmacro("sourcelist", "collector", sourcelist);
+
+  // reset badsources and failedsources variables
+  badsources = false;
+  failedsources.erase(failedsources.begin(), failedsources.end());
+}
+
+text_t collectoraction::get_source_box (text_t inputarglist, int numboxes,
+					text_t inputtypelist) {
+
+  text_tarray inputvalues;
+  splitchar (inputarglist.begin(), inputarglist.end(), ',', inputvalues);
+  // remove any empty values from the end of the array
+  if (inputvalues.size()) {
+    text_tarray::iterator l = inputvalues.end() - 1;
+    text_tarray::iterator b = inputvalues.begin();
+    while ((*l).empty() && l >= b) {
+      --l;
+    }
+    inputvalues.erase(l+1, inputvalues.end());
+  }
+
+  text_tarray inputtypes;
+  splitchar (inputtypelist.begin(), inputtypelist.end(), ',', inputtypes);
+
+  int numvalues = inputvalues.size();
+  int numtypes = inputtypes.size();
+
+  text_t last = "file://";
+  text_t rv;
+  for (int i = 0; i < numboxes; ++i) {
+    rv += "<nobr><select name=\"bc1inputtype\">\n";
+    rv += "<option value=\"file://\"";
+    if ((i < numtypes && inputtypes[i] == "file://") ||
+	(numboxes == 3 && i == 0 && numvalues == 0) ||
+	(i >= 3 && i >= numvalues && last == "file://")) {
+      rv += " selected";
+      last = "file://";
+    }
+    rv += ">file://\n";
+    rv += "<option value=\"http://\"";
+    if ((i < numtypes && inputtypes[i] == "http://") ||
+	(numboxes == 3 && i == 1 && numvalues == 0) ||
+	(i >= 3 && i >= numvalues && last == "http://")) {
+      rv += " selected";
+      last = "http://";
+    }
+    rv += ">http://\n";
+    rv += "<option value=\"ftp://\"";
+    if ((i < numtypes && inputtypes[i] == "ftp://") ||
+	(numboxes == 3 && i == 2 && numvalues == 0) ||
+	(i >= 3 && i >= numvalues && last == "ftp://")) {
+      rv += " selected";
+      last = "ftp://";
+    }
+    rv += ">ftp://\n";
+    rv += "</select>\n";
+    rv += "<input type=text name=\"bc1input\" value=\"";
+    if (i < numvalues) {
+      rv += dm_safe(decode_commas(inputvalues[i]));
+    }
+    rv += "\" size=50>";
+    if (badsources) {
+      if ((i < numvalues) && (!inputvalues[i].empty())) {
+	if (failedsources[decode_commas(inputvalues[i])] == "1") {
+	  rv += "_iconcross_";
+	} else {
+	  rv += "_icontick_";
+	}
+      } else {
+	rv += "_iconblank_";
+      }
+    }
+    if (i+1 == numboxes) {
+      if (!badsources) rv += "_iconblank_";
+      rv += "_imagemore_</nobr><br>";
+    } else {
+      rv += "</nobr><br>\n";
+    }
+  }
+  
+  return rv;
+}
+
+// set the _cfgfile_ macro
+void collectoraction::set_cfgfile (displayclass &disp, cgiargsclass &args, ostream &logout) {
+
+  text_t &collection = args["bc1dirname"];
+  if (collection.empty()) {
+    message = "nocollection";
+    return;
+  }
+
+  // read in collect.cfg      
+  text_t cfgfile = filename_cat(get_collectdir(args), collection, "etc", "collect.cfg");  
+  char *cfgfilec = cfgfile.getcstr();
+
+#ifdef GSDL_USE_IOS_H
+  ifstream cfg_ifs (cfgfilec, ios::in | ios::nocreate);
+#else
+  ifstream cfg_ifs (cfgfilec, ios::in);
+#endif
+  
+  if (cfg_ifs) {  
+    // read in collect.cfg      
+    text_t cfgtext;
+    char c;
+    cfg_ifs.get(c);
+    while (!cfg_ifs.eof ()) {
+      cfgtext.push_back(c);
+      cfg_ifs.get(c);
+    }
+    cfg_ifs.close();
+    
+    // define it as a macro
+    disp.setmacro("cfgfile", "collector", dm_safe(cfgtext));
+
+  } else {
+    logout << "collectoraction::set_cfgfile: couldn't open configuration file (" 
+	   << cfgfilec << ") for reading\n";
+    message = "tmpfail";
+  }    
+  delete []cfgfilec;
+}
+
+
+void collectoraction::define_internal_macros (displayclass &disp, cgiargsclass &args, 
+					      recptprotolistclass *protos, ostream &logout) {
+
+  // define_internal_macros sets the following macros:
+  // _collectorbar_
+  // _pagescriptextra_
+  // _fullnamemenu_ -- if displaying the "source data" page or the "changing existing 
+  //                   collection" page
+  // _cfgfile_ -- if displaying the "configure collection" page
+  // _statusline_ -- if displaying the bildstatus page
+  // _header_ -- may be set for pages that require it
+  // _textfailmsg_ -- set to different messages depending on failcode returned
+  //                  by build script (if build fails)
+  // _faillog_ - set to last 6 lines of .bld file if build failed
+  // _gsdlhome_ - the gsdlhome path (dm_safe)
+  // _sourcelist_ -- "input source" text boxes
+  // _badsources_ -- will be set to "1" if we've come from the 
+  //                 "source data" page and there's a problem 
+  //                 with the input sources
+
+  text_t &collector_page = args["p"];
+  int esrce = args["bc1esrce"].getint();
+  int econf = args["bc1econf"].getint();
+
+  // set _pagescriptextra_ macro to _cpagescriptextra_
+  disp.setmacro ("pagescriptextra", "collector", "_" + collector_page + "scriptextra_");
+
+  if (collector_page == "bildstatus" || collector_page == "bilddone" || 
+      collector_page == "bildfail" || collector_page == "bildframe1") {
+    disp.setmacro ("header", "collector", "_" + collector_page + "header_");
+  }
+
+  // set the collectorbar macro
+  text_t collectorbar = "<table class=wizardbar border=0 cellspacing=4 cellpadding=0><tr>\n";
+
+  if (collector_page == "new") {
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "green", "info", true);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "srce", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "conf", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "bild", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "view", false);
+
+  } else if (collector_page == "info") {
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "yellow", "info", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "green", "srce", true);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "conf", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "bild", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "view", false);
+    collectorbar += "</tr><tr><td></td><td align=center>_icongreyuparrow_</td><td colspan=8></td>\n";
+
+  } else if (collector_page == "srce") {
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    if (esrce == 1) {
+      // if we came from the "change an existing collection" page previous button(s)
+      // are disabled
+      collectorbar += get_button (args,collector_page, "grey", "info", false);
+    } else {
+      collectorbar += get_button (args,collector_page, "yellow", "info", true);
+    }
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "yellow", "srce", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "green", "conf", true);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "green", "bild", true);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "view", false);
+    collectorbar += "</tr><tr><td colspan=3></td><td align=center>_icongreyuparrow_</td><td colspan=6></td>\n";
+
+  } else if (collector_page == "conf") {
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    // disable appropriate buttons if we came from "change an existing collection"
+    // page
+    if (esrce == 1 || econf == 1) {
+      collectorbar += get_button (args,collector_page, "grey", "info", false);
+    } else {
+      collectorbar += get_button (args,collector_page, "yellow", "info", true);
+    }
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    if (econf == 1) {
+      collectorbar += get_button (args,collector_page, "grey", "srce", false);
+    } else {
+      collectorbar += get_button (args,collector_page, "yellow", "srce", true);
+    }
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "yellow", "conf", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "green", "bild", true);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "view", false);
+    collectorbar += "</tr><tr><td colspan=5></td><td align=center>_icongreyuparrow_</td><td colspan=4></td>\n";
+
+  } else if (collector_page == "bilddone") {
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    // all previous buttons grey after build was completed
+    collectorbar += get_button (args,collector_page, "grey", "info", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "srce", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "conf", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "yellow", "bild", false);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "green", "view", true);
+    collectorbar += "</tr><tr><td colspan=7></td><td align=center>_icongreyuparrow_</td><td colspan=2></td>\n";
+
+  } else if (collector_page == "bildcancel" || collector_page == "bildfail") {
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    // disable appropriate buttons if we came from "change an existing collection"
+    // page
+    if (esrce == 1 || econf == 1) {
+      collectorbar += get_button (args,collector_page, "grey", "info", false);
+    } else {
+      collectorbar += get_button (args,collector_page, "yellow", "info", true);
+    }
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    if (econf == 1) {
+      collectorbar += get_button (args,collector_page, "grey", "srce", false);
+    } else {
+      collectorbar += get_button (args,collector_page, "yellow", "srce", true);
+    }
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "yellow", "conf", true);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "yellow", "bild", true);
+    collectorbar += "<td>_icongreyarrow_</td>\n";
+    collectorbar += get_button (args,collector_page, "grey", "view", false);
+  }
+
+  collectorbar += "</tr></table>\n";
+  disp.setmacro ("collectorbar", "collector", collectorbar);
+
+  if (collector_page == "bildfail") {
+
+    text_t textfailmsg = "_textfailmsg";
+    textfailmsg.push_back(failcode);
+    textfailmsg.push_back('_');
+    disp.setmacro("textfailmsg", "collector", textfailmsg);
+
+    text_t bldlog = filename_cat(gsdlhome, "tmp", args["bc1tmp"], args["bc1dirname"] + ".bld");
+    text_t rawlog = file_tail (bldlog, 6, 0);
+    // we'll shove in some <br> tags where \n's occur
+    text_t faillog;
+    text_t::const_iterator here = rawlog.begin();
+    text_t::const_iterator end = rawlog.end();
+    while (here != end) {
+      if (*here == '\n') faillog += "<br>";
+      faillog.push_back (*here);
+      ++here;
+    }
+    disp.setmacro ("faillog", "collector", dm_safe(faillog));
+  }
+
+  if (collector_page == "srce" || collector_page == "existing") 
+    set_fullnamemenu (disp, args, protos, logout);
+  if (collector_page == "conf") 
+    set_cfgfile (disp, args, logout);
+  if (collector_page == "bildstatus")
+    set_statusline (disp, args, logout);
+  if (collector_page == "srce") {
+    set_inputsourceboxes (disp, args, logout);
+  }
+
+  disp.setmacro ("gsdlhome", "collector", dm_safe(gsdlhome));
+}
+
+
+bool collectoraction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/, 
+				 browsermapclass * /*browsers*/, displayclass &disp, 
+				 outconvertclass &outconvert, ostream &textout, 
+				 ostream &logout) {
+
+  // make sure the collector is enabled
+  if (disabled) {
+    textout << outconvert 
+	    << "<html>\n"
+	    << "<head>\n"
+	    << "<title>Collector disabled</title>\n"
+	    << "</head>\n"
+	    << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
+	    << "alink=\"#cc9900\" vlink=\"#666633\">\n"
+	    << "<h2>Facility disabled</h2>\n" 
+	    << "Sorry, the Collector end-user collection building facility is currently disabled\n"
+	    << "\n</body>\n"
+	    << "</html>\n";
+    return true;
+  }
+
+  text_t &collector_page = args["p"];
+  text_t &collection = args["bc1dirname"];
+
+  // make sure we have perl (we won't bother with this check for the 
+  // building status pages to avoid slowing things down unneccessarily)
+  if (collector_page != "bildstatus" && collector_page != "bildframe1" && !perl_ok(logout)) {
+    textout << outconvert 
+	    << "<html>\n"
+	    << "<head>\n"
+	    << "<title>Perl not found</title>\n"
+	    << "</head>\n"
+	    << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
+	    << "alink=\"#cc9900\" vlink=\"#666633\">\n"
+	    << "<h2>Perl not found</h2>\n" 
+	    << "Greenstone could not detect perl on this system. It is therefore not\n"
+	    << "possible to build a Greenstone collection, either from the Collector or the \n"
+	    << "command-line tools, or to use the Collector for any other task.\n"
+	    << "<p>Please refer to the Greenstone Installer's Guide for details on\n"
+	    << "installing perl on your system.\n"
+	    << "\n</body>\n"
+	    << "</html>\n";
+    return true;
+
+  }
+
+  if (collector_page == "bild") {
+    // do the work (download, import, build)
+    gsdl_build (args, logout);
+
+    if (message.empty()) {
+      // bild page is a frameset so we don't want headers and stuff
+      textout << outconvert << disp << ("_collector:bildcontent_\n");
+    }
+  }
+
+  if (do_mkcol == true) {
+    // execute mkcol.pl (do_mkcol is set from within check_cgiargs)
+    gsdl_mkcol (args, logout);
+    do_mkcol = false; // reset for fast-cgi
+  }
+
+  if (args["bc1dodelete"] == "1") {
+    // delete bcidirname collection
+    if (collection_protected (collection)) {
+      message = "delinvalid";
+	
+    } else {
+
+      const recptconf &rcinfo = recpt->get_configinfo ();
+      bool emailuserevents = rcinfo.EmailUserEvents;
+
+      // get collection maintainer email from collect.cfg before we
+      // delete it
+      text_t colmaintainer;
+      text_t cfgfile = filename_cat(collecthome, collection, "etc", "collect.cfg");
+      char *cfgfilec = cfgfile.getcstr();
+      ifstream cfg_in (cfgfilec);
+      delete []cfgfilec;
+      if (cfg_in) {
+	text_tarray cfgline;
+	while (read_cfg_line(cfg_in, cfgline) >= 0) {
+	  if (cfgline.size () == 2 && cfgline[0] == "maintainer") {
+	    colmaintainer = cfgline[1];
+	    break;
+	  }
+	}
+	cfg_in.close();
+      }
+      if (colmaintainer.empty()) {
+	logout << outconvert 
+	       << "collectoraction::do_action WARNING: Collection being deleted (" 
+	       << collection << ") has no maintainer address. EmailUserEvents "
+	       << "disabled\n";
+	emailuserevents = false;
+      }
+      
+      // first we need to free up the collection's collection server
+      // we must do this for the local library (and I guess when using
+      // fastcgi too) as you can't delete the database file while it's
+      // being kept open by the collection server
+      remove_colservr (collection, logout);
+
+      text_t delete_cmd = "perl -S delcol.pl -f " + collection;
+      int rv = gsdl_system (delete_cmd, true, logout);
+      if (rv != 0) {
+	// deletion failed -- permissions?
+	message = "delpermission";
+      } else {
+	message = "delsuccess";
+      }
+
+      // log the event
+      if (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents) {
+	
+	text_t eventlog = filename_cat (gsdlhome, "etc", "events.txt");
+	char *eventlogt = eventlog.getcstr();
+	ofstream eventl (eventlogt, ios::app);
+	delete []eventlogt;
+
+	if (eventl) {
+	  eventl << outconvert << "[Collector Event]\n"
+		 << "Date: " << get_date (true) << "\n"
+		 << "Greenstone Username: " << args["un"] << "\n"
+		 << "Collection: " << collection << "\n"
+		 << "Collection Maintainer: " << colmaintainer << "\n"
+		 << "GSDLHOME: " << gsdlhome << "\n";
+
+	  if (message == "delsuccess") {
+	    eventl << outconvert 
+		   << "The " << collection << " collection was successfully deleted\n\n";
+	  } else {
+	    eventl << outconvert 
+		   << "Attempt to delete the " << collection << " collection failed\n\n";
+	  }
+	  eventl.close();
+
+	} else {
+	  logout << outconvert << "collectoraction::do_action ERROR: Couldn't open "
+		 << "event log file " << eventlog << " for appending during collection "
+		 << "deletion. LogEvents disabled\n";
+	}
+      }
+      
+      if (rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents || emailuserevents) {
+	// use sendmail.pl perl script to send email events
+	text_t tmpmailfile = filename_cat (gsdlhome, "tmp", args["bc1tmp"], "event.txt");
+	char *tmpmailfilec = tmpmailfile.getcstr();
+	ofstream tmpfile (tmpmailfilec);
+	delete []tmpmailfilec;
+	if (tmpfile) {
+	  tmpfile << outconvert << "[Collector Event]\n"
+	    	  << "Date: " << get_date (true) << "\n"
+		  << "Greenstone Username: " << args["un"] << "\n"
+		  << "Collection: " << collection << "\n"
+		  << "Collection Maintainer: " << colmaintainer << "\n"
+		  << "GSDLHOME: " << gsdlhome << "\n";
+	  if (message == "delsuccess") {
+	    tmpfile << outconvert 
+		    << "The " << collection << " collection was successfully deleted\n\n";
+	  } else {
+	    tmpfile << outconvert 
+		    << "Attempt to delete the " << collection << " collection failed\n\n";
+	  }
+	  tmpfile.close();
+	  text_t to;
+	  if (rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents) to += rcinfo.maintainer;
+	  if (emailuserevents) {
+	    if (!to.empty()) to.push_back (',');
+	    to += colmaintainer;
+	  }
+	  text_t sendmail_cmd = "perl -S sendmail.pl -to \"" + to + "\" -from \"" + rcinfo.maintainer;
+	  sendmail_cmd += "\" -smtp \"" + rcinfo.MailServer + "\" -subject \"Greenstone Collector Event\"";
+	  sendmail_cmd += " -msgfile \"" + tmpmailfile + "\"";
+
+	  gsdl_system (sendmail_cmd, false, logout);
+	  
+	} else {
+	  logout << outconvert << "collectoraction::do_action ERROR: Couldn't open "
+		 << "temporary event log file " << tmpmailfile << " during collection "
+		 << "deletion. EmailEvents and EmailUserEvents disabled\n";
+	}
+      }
+    }
+  }
+  
+  if (collector_page == "bildcancel" || collector_page == "bildfail") {
+    // cancel the build (we'll also use the cancel_build script to tidy
+    // up if the build failed)
+    gsdl_cancel_build (args, logout);
+  }
+
+  if (collector_page == "expt") {
+
+    // export the collection - we'll do a synchronous system call to
+    // exportcol.pl as that's the easiest way to do it. if it becomes a
+    // problem that it's taking too long to export a large collection then
+    // we may have to revisit this.
+    text_t tmpfile = filename_cat (gsdlhome, "tmp", collection + "_export.txt");
+    text_t export_cmd = "perl -S exportcol.pl -out \"" + tmpfile + "\" " + collection;
+    gsdl_system (export_cmd, true, logout);
+    if (file_exists (tmpfile)) {
+      text_t returnline = file_tail (tmpfile, 1, 0);
+      if (returnline.size() > 23 && (substr(returnline.begin(), returnline.begin()+23) == "exportcol.pl succeeded:")) {
+	// success
+	message = "exptsuccess";
+      } else {
+	message = "exptfail";
+      }
+    } else {
+      message = "exptfail";
+    }
+  }
+
+  if (message.empty()) {
+    if (collector_page != "bild") {
+      // output page ("bild" page was already output above)
+      textout << outconvert << disp << ("_collector:header_\n")
+	      << ("_collector:" + collector_page + "content_\n")
+	      << ("_collector:footer_\n");
+    }
+  } else {
+    // message was set somewhere (probably an error), output message page
+    textout << outconvert << disp << ("_collector:header_\n")
+	    << ("_collector:" + message + "content_\n")
+	    << ("_collector:footer_\n");
+    message.clear();
+  }
+  return true;
+}
+
+void collectoraction::gsdl_mkcol (cgiargsclass &args, ostream &logout) {
+
+  text_t tmpdir = filename_cat (gsdlhome, "tmp", args["bc1tmp"]);
+  if (!directory_exists (tmpdir)) {
+    message = "tmpfail";
+    cerr << "WE CANNOT CREATE THE DIRECTORY!!! " << endl; 
+    return;
+  }
+
+  text_t &collection = args["bc1dirname"];
+  if (collection.empty()) {
+    message = "nocollection";
+    return;
+  }
+
+  // check for a .create file - if it exists then we've already created the collection
+  text_t createfile = filename_cat (tmpdir, ".create");
+  if (file_exists (createfile)) {
+    return;
+  }
+
+  // set up options
+  text_t options = "-quiet -creator \"" + args["bc1contactemail"] + "\"";
+  options += " -title \"" + args["bc1fullname"] + "\"";
+  options += " -about \"" + carriage_replace (args["bc1aboutdesc"] + "_collectorextra_", 0) + "\"";
+  options += " -collectdir \"" + remove_trailing_slashes(tmpdir) + "\" ";
+
+  text_t optionfile = filename_cat (tmpdir, "mkcol.opt");
+  char *optionfilec = optionfile.getcstr();
+  ofstream ofile_out (optionfilec);
+  delete []optionfilec;
+  if (!ofile_out) {
+    message = "tmpfail";
+    return;
+  }
+  outconvertclass text_t2ascii;
+  ofile_out << text_t2ascii << options << "\n";
+  ofile_out.close();
+
+  // run mkcol.pl
+  text_t mkcol_cmd = "perl -S mkcol.pl -optionfile \"" + optionfile;
+  mkcol_cmd += "\" " + collection;
+
+
+  gsdl_system (mkcol_cmd, true, logout);
+
+  // make sure it went ok
+  text_t cfgfile = filename_cat (tmpdir, collection, "etc", "collect.cfg");
+  if (!file_writable (cfgfile)) {
+    message = "mkcolfail";
+  } else {
+    // create the .create file (this file is just a place holder to let any future
+    // pages know that the collection already exists).
+    char *createfilec = createfile.getcstr();
+    ofstream cfile_out (createfilec);
+    delete []createfilec;
+    if (cfile_out) {
+      cfile_out << "collection created\n";
+      cfile_out.close();
+    } else {
+      message = "tmpfail";
+      return;
+    }
+  }
+}
+
+
+bool collectoraction::check_sources (cgiargsclass &args, ostream &logout) {
+
+  bool found = false;
+
+  text_tarray inputvalues;
+  splitchar (args["bc1input"].begin(), args["bc1input"].end(), ',', inputvalues);
+
+  text_tarray inputtypes;
+  splitchar (args["bc1inputtype"].begin(), args["bc1inputtype"].end(), ',', inputtypes);
+
+  int numvalues = inputvalues.size();
+  int numtypes = inputtypes.size();
+
+  for (int i = 0; i < numvalues; ++i) {
+    text_t value = format_url(decode_commas(inputvalues[i]));
+    text_t type = "file://"; // default
+    if (!value.empty()) {
+      found = true;
+      if (i >= numtypes || inputtypes[i].empty()) {
+	logout << "collectoraction::check_sources: WARNING type not set\n";
+      } else {
+	type = inputtypes[i];
+      }
+      if (type == "file://") {
+	if (!file_exists(value) && !directory_exists(value)) {
+	  failedsources[decode_commas(inputvalues[i])] = "1";
+	  badsources = true;
+	}
+      } else if (type == "http://") {
+	if (gsdl_system ("perl -S ping.pl -quiet http://" + value, true, logout)) {
+	  failedsources[decode_commas(inputvalues[i])] = "1";
+	  badsources = true;
+	}
+      } else if (type == "ftp://") {
+	if (gsdl_system ("perl -S ping.pl -quiet ftp://" + value, true, logout)) {
+	  failedsources[decode_commas(inputvalues[i])] = "1";
+	  badsources = true;
+	}
+      }
+    }
+  }
+
+  // set badsources if there weren't any sources at all
+  if (!found) badsources = true;
+
+  if (badsources) return false;
+  return true;
+}
+
+text_t collectoraction::get_button(cgiargsclass &args, const text_t &thispage, 
+				   const text_t &color, 
+				   const text_t &type, bool enabled) 
+{
+
+  if ((color != "green" && color != "grey" && color != "yellow") ||
+      (type != "info" && type != "srce" && type != "conf" && type != "bild" && type != "view"))
+    return g_EmptyText;
+
+  text_t href = "_http"+type+"_";
+  text_t target = "";
+
+  if (thispage == "info" || thispage == "srce" || thispage == "conf" || 
+      thispage == "bildcancel" || thispage == "bildfail") {
+    // call the check submit macro instead of linking directly to the page
+    href="\"javascript:check_submit('"+type+"');\"";
+  } else if (type == "view") {
+    // view button is special case as it needs a target=_top
+    target = " target=_top";
+  }
+
+  text_t tdclass = "wizardbar"+color; 
+  if (enabled) {
+    // link to the appropriate page
+    return "<td class="+tdclass+"><a href="+href+target+">_text"+type+"_</a></td>";
+  }
+  else {
+    // just display the text
+    return "<td class="+tdclass+">_text"+type+"_</td>";
+  }
+}
+
+#endif //GSDL_USE_COLLECTOR_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/collectoraction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/collectoraction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/collectoraction.h	(revision 16571)
@@ -0,0 +1,95 @@
+/**********************************************************************
+ *
+ * collectoraction.h -- 
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_COLLECTOR_ACTION
+
+#ifndef COLLECTORACTION_H
+#define COLLECTORACTION_H
+
+#include "wizardaction.h"
+#include "receptionist.h"
+
+class collectoraction : public wizardaction {
+  
+protected:
+
+  bool do_mkcol;
+
+  bool badsources;
+  text_tmap failedsources;
+
+  void set_fullnamemenu (displayclass &disp, cgiargsclass &args, 
+			 recptprotolistclass *protos, ostream &logout);
+
+
+  void set_inputsourceboxes (displayclass &disp, cgiargsclass &args, 
+			     ostream &logout);
+
+  text_t get_source_box (text_t inputarglist, int numboxes, 
+			 text_t inputtypelist);
+
+  void set_cfgfile (displayclass &disp, cgiargsclass &args, ostream &logout);
+
+
+  void update_cfgfile_clone (cgiargsclass &args, ostream &logout);
+
+  void update_cfgfile_partial (cgiargsclass &args, bool clone, ostream &logout);
+
+  void update_cfgfile_complete (cgiargsclass &args, ostream &logout);
+
+
+  void gsdl_mkcol (cgiargsclass &args, ostream &logout);
+
+
+
+  bool check_sources (cgiargsclass &args, ostream &logout);
+
+  text_t get_button (cgiargsclass &args, const text_t &thispage, 
+		     const text_t &color, 
+		     const text_t &type, bool enabled);
+
+
+public:
+  collectoraction ();
+  virtual ~collectoraction ();
+
+  text_t get_action_name () {return "collector";}
+
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass *protos, ostream &logout);
+
+  void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+};
+
+#endif //!COLLECTORACTION_H
+#endif //GSDL_USE_COLLECTOR_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/comproto.asn
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/comproto.asn	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/comproto.asn	(revision 16571)
@@ -0,0 +1,376 @@
+-- The protocol data unit (PDU) is the
+-- message that is transmitted between receptionists and
+-- collectionservers (colservers?).
+--
+-- Comments in ASN.1 start with two dashes and continue to the end
+-- of a line (or to the next two dashes, whichever is first).
+-- 
+-- Z39.50 has inspired much of this but I have tried to keep
+-- it simple. Its hard to tell if I have succeeded ;-)
+
+
+GSDL-APDU DEFINITIONS ::=
+BEGIN
+
+
+-- PDU is the basic message type. Note: in ASN.1 the
+-- field name comes first and the field type second (opposite
+-- to C). Ignore the numbers in the square brackets (e.g. [0]),
+-- they're just tags to disambiguate certain circumstances and to
+-- make the protocol easier to extend. The keyword 'IMPLICIT' just
+-- makes the tags a little more efficient.
+--
+-- A SEQUENCE is a list of fields where the order is important
+
+PDU ::= SEQUENCE {
+  header  StandardHeader,
+  message Message
+}
+
+
+-- ????? Is there anything else we want in the header ?????
+--
+-- Anonymous transactions should leave out the idAuthentication field
+
+StandardHeader ::= SEQUENCE {
+  protocolVersion       [0] IMPLICIT INTEGER,
+  idAuthentication      [1] IMPLICIT IdAuthentication OPTIONAL
+}
+
+IdAuthentication ::= SEQUENCE {
+  userId   GeneralString,
+  groupId  GeneralString,
+  password GeneralString
+}
+
+
+-- A CHOICE is like a union in C.
+-- 
+-- Short forms: Auth (Authority), Mir (Mirror), Col (Collection),
+--   Doc (Document), Info (Information)
+
+Message ::= CHOICE {
+  -- General
+  error                      [0]  IMPLICIT Error,
+  pingRequest                [1]  IMPLICIT PingRequest,
+  pingResponse               [2]  IMPLICIT PingResponse,
+
+  -- Authority
+--  authListRequest            [12] IMPLICIT AuthListRequest,
+--  authListResponse           [13] IMPLICIT AuthListResponse,
+--  editAuthListRequest        [14] IMPLICIT EditAuthListRequest,
+--  editAuthListResponse       [15] IMPLICIT EditAuthListResponse,
+
+  -- an authority mirror is a mirror of THIS authority
+--  authMirListRequest         [16] IMPLICIT AuthMirListRequest,
+--  authMirListResponse        [17] IMPLICIT AuthMirListResponse,
+--  editAuthMirListRequest     [18] IMPLICIT EditAuthMirListRequest,
+--  editAuthMirListResponse    [19] IMPLICIT EditAuthMirListResponse,
+
+  colListRequest             [20] IMPLICIT ColListRequest,
+  colListResponse            [21] IMPLICIT ColListResponse,
+--  editColListRequest         [22] IMPLICIT EditColListRequest,
+--  editColListResponse        [23] IMPLICIT EditColListResponse,
+
+--  colMirListRequest          [24] IMPLICIT ColMirListRequest,
+--  colMirListResponse         [25] IMPLICIT ColMirListResponse, 
+--  editColMirListRequest      [26] IMPLICIT EditColMirListRequest, 
+--  editColMirListResponse     [27] IMPLICIT EditColMirListResponse,
+
+  -- Collection
+  colInfoRequest             [40] IMPLICIT ColInfoRequest,
+  colInfoResponse            [41] IMPLICIT ColInfoResponse,
+
+  -- Document
+  documentRequest            [52] IMPLICIT DocumentRequest,
+  documentResponse           [53] IMPLICIT DocumentResponse,
+
+  -- Access (searching, browsing, and metadata information)
+  infoFiltersRequest         [60] IMPLICIT InfoFiltersRequest,
+  infoFiltersResponse        [61] IMPLICIT InfoFiltersResponse,
+  infoFilterOptionsRequest   [62] IMPLICIT InfoFilterOptionsRequest,
+  infoFilterOptionsResponse  [63] IMPLICIT InfoFilterOptionsResponse,
+  filterRequest              [64] IMPLICIT FilterRequest,
+  filterResponse             [65] IMPLICIT FilterResponse
+}
+
+
+
+-- ------------------------------
+-- GENERAL
+-- ------------------------------
+
+
+-- The error list is not complete yet ...
+
+Error ::= ENUMERATED {
+  authenticationFailure(0), protocolError(1), systemProblem(2)
+}
+
+
+PingRequest ::= SEQUENCE {
+}
+
+PingResponse ::= SEQUENCE {
+}
+
+
+
+-- ------------------------------
+-- AUTHORITY
+-- ------------------------------
+
+
+-- Support for subscription is optional for both the clients and
+-- the servers. It is recomended that it is not implemented yet
+-- for simplicity.
+
+-- AuthListRequest ::= SEQUENCE {
+-- }
+
+-- AuthListResponse ::= SEQUENCE {
+--   authList  [1] IMPLICIT StringSet
+-- }
+
+
+-- EditAuthListRequest ::= SEQUENCE {
+--   editAction EditAction,
+--   authority  GeneralString
+-- }
+
+-- EditAuthListResponse ::= SEQUENCE {
+-- }
+
+
+-- AuthMirListRequest ::= SEQUENCE {
+--   limitNumber [1] IMPLICIT INTEGER OPTIONAL,
+--   limitDomain [2] IMPLICIT GeneralString OPTIONAL
+-- }
+
+-- AuthMirListResponse ::= SEQUENCE {
+--   authMirList [1] IMPLICIT HostPortSet
+-- }
+
+
+-- EditAuthMirListRequest ::= SEQUENCE {
+--   editAction EditAction,
+--   authMir    HostPort
+-- }
+
+-- EditAuthMirListResponse ::= SEQUENCE {
+-- }
+
+
+ColListRequest ::= SEQUENCE {
+}
+
+ColListResponse ::= SEQUENCE {
+  colList   [1] IMPLICIT ShortColInfoSet
+}
+
+
+-- EditColListRequest ::= SEQUENCE {
+--   editAction EditAction,
+--   colInfo    ShortColInfo
+-- }
+
+-- EditColListResponse ::= SEQUENCE {
+-- }
+
+
+-- ColMirListRequest ::= SEQUENCE {
+--   limitNumber [1] IMPLICIT INTEGER OPTIONAL,
+--   limitDomain [2] IMPLICIT GeneralString OPTIONAL
+-- }
+
+-- ColMirListResponse ::= SEQUENCE {
+--   colMirList [1] IMPLICIT ShortColInfoSet
+-- }
+
+
+-- EditColMirListRequest ::= SEQUENCE {
+--   editAction EditAction,
+--   colMirInfo ShortColInfo
+-- }
+
+-- EditColMirListResponse ::= SEQUENCE {
+-- }
+
+
+
+
+-- ------------------------------
+-- COLLECTION
+-- ------------------------------
+
+
+ColInfoRequest ::= SEQUENCE {
+}
+
+ColInfoResponse ::= SEQUENCE {
+  shortInfo   [0] IMPLICIT ShortCollectionInfo,
+  isPublic    [2] IMPLICIT BOOLEAN,    -- whether has anonymous access
+  isBeta      [3] IMPLICIT BOOLEAN,    -- beta if still under development
+  builddate   [4] IMPLICIT GeneralizedTime,
+  languages   [5] IMPLICIT StringSet,  -- languages in the collection
+  numDocs     [6] IMPLICIT INTEGER,
+  numWords    [7] IMPLICIT INTEGER OPTIONAL,
+  numBytes    [8] IMPLICIT INTEGER OPTIONAL
+}
+
+
+
+-- ------------------------------
+-- DOCUMENT
+-- ------------------------------
+
+
+
+DocumentRequest ::= SEQUENCE {
+  OID       GeneralString,
+  docType   GeneralString,
+  docFormat GeneralString
+}
+
+DocumentResponse ::= SEQUENCE {
+  doc OCTET STRING
+}
+
+
+-- ------------------------------
+-- ACCESS (SEARCH AND BROWSE)
+-- ------------------------------
+
+
+-- filter options which might be supported for the QueryFilter
+--
+-- onePerQuery StartResults   integer
+-- onePerQuery EndResults     integer
+-- onePerQuery QueryType      enumerated (boolean, ranked)
+-- onePerTerm  Term           string ???
+-- onePerTerm  Casefold       boolean
+-- onePerTerm  Stem           boolean
+-- onePerTerm  Index          enumerated
+-- onePerTerm  Subcollection  enumerated
+--
+-- filter options which might be supported for the BrowseFilter
+--
+-- onePerQuery StartResults   integer
+-- onePerQuery EndResults     integer
+-- onePerQuery ParentNode     string ("" will return the browsing available)
+--
+-- The NullFilter always returns the set it was given, it doesn't have
+-- any options
+
+InfoFiltersRequest ::= SEQUENCE {
+}
+
+InfoFiltersResponse ::= SEQUENCE {
+  filterNames StringSet
+}
+
+InfoFilterOptionsRequest ::= SEQUENCE {
+  filterName GeneralString
+}
+
+InfoFilterOptionsResponse ::= SEQUENCE {
+  filterOptions SET OF FilterOption
+}
+
+FilterOption ::= SEQUENCE {
+  name         GeneralString,
+  type         ENUMERATED {booleant(0), integert(1), enumeratedt(2), stringt(3)},
+  repeatable   ENUMERATED {onePerQuery(0), onePerTerm(1), nPerTerm(2)},
+  defaultValue GeneralString,
+  -- the interpretation of the validValues depends on the type
+  -- for boolean: the first value is the false value, the second is true value
+  -- for integer: the first value is the minimum, the second the maximum
+  -- for enumerated: all values a listed
+  -- for string: this value is ignored
+  validValues  StringSequence
+}
+
+
+-- Terms are presented in the same order that they are requested,
+-- any information relating to the terms is in reference to the
+-- index specified for that term.
+-- Metadata is presented in the same order that it is requested.
+
+FilterRequest ::= SEQUENCE {
+  filterName          [0] GeneralString,
+  filterOptions       [1] IMPLICIT SEQUENCE OF OptionValue,
+  docSet              [2] IMPLICIT StringSequence, -- the OID "" represents everything
+  filterResultOptions [3] IMPLICIT BIT STRING {termFreq(0), matchTerms(1), OID(2), 
+                                               subCol(3), ranking(4), docFreq(5), 
+                                               metadata(6)}
+
+  -- the next set of options are for the metadata request, 
+  -- they can be left blank if metadata is not wanted
+  requestParams       [4] IMPLICIT GeneralString, -- used to negotiate the metadata content
+  refParams           [5] IMPLICIT GeneralString, -- used to decide whether to return a 
+                                                  -- reference to the data or the actual data
+  fields              [6] IMPLICIT StringSequence
+}
+
+OptionValue ::= SEQUENCE {
+  name  GeneralString,
+  value GeneralString
+}
+
+FilterResponse ::= SEQUENCE {
+  numDocs   [0] IMPLICIT INTEGER,
+  isApprox  [1] IMPLICIT BOOLEAN,                  -- whether numDocs is approximate
+  termInfo  [2] IMPLICIT SEQUENCE OF TermInfo,     -- empty if not required
+  docInfo   [3] IMPLICIT SEQUENCE OF ResultDocInfo -- empty if not required
+}
+
+TermInfo ::= SEQUENCE {
+  term       [0] GeneralString,
+  freq       [1] IMPLICIT INTEGER,       -- 0 if not requested
+  matchTerms [2] IMPLICIT StringSequence -- empty if not requested
+}
+
+ResultDocInfo ::= SEQUENCE {
+  OID      [0] IMPLICIT GeneralString,
+  ranking  [1] IMPLICIT INTEGER,             -- 0 if not requested, range 0-10000
+  docFreq  [2] IMPLICIT SEQUENCE OF INTEGER, -- empty if not requested
+  metadata [3] IMPLICIT SEQUENCE OF MetadataInfo
+}
+
+
+MetadataInfo ::= SEQUENCE {
+  params  [0] IMPLICIT GeneralString,
+  isRef   [1] IMPLICIT BOOLEAN,
+  field   [3] IMPLICIT GeneralString,
+  value   [4] IMPLICIT GeneralString
+}
+
+
+-- ------------------------------
+-- Useful Types
+-- ------------------------------
+
+-- HostPortSet ::= SET OF HostPort
+
+-- HostPort ::= SEQUENCE {
+--   host [0] IMPLICIT GeneralString,
+--   port [1] IMPLICIT INTEGER
+-- }
+
+ShortColInfoSet ::= SET OF ShortColInfo
+
+ShortColInfo ::= SEQUENCE {
+  name GeneralString,
+  host GeneralString,
+  port INTEGER
+}
+
+-- EditAction ::= ENUMERATED {
+--   update(0), delete(1)
+-- }
+
+StringSequence ::= SEQUENCE OF GeneralString
+StringSet ::= SET OF GeneralString
+
+
+END
Index: /gsdl/trunk/runtime-src/src/recpt/configaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/configaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/configaction.cpp	(revision 16571)
@@ -0,0 +1,151 @@
+/**********************************************************************
+ *
+ * configaction.cpp -- 
+ * Copyright (C) 2003 DL Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#include "configaction.h"
+
+#ifdef GSDL_LOCAL_LIBRARY
+// for PostMessage()
+#  include <windows.h>
+#endif
+
+configaction::configaction () {
+
+  recpt = NULL;
+
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "config";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  /* 
+     The cmd argument may be one of the following:
+     -- release-collection - release the collection specified by the "c"
+        argument
+     -- add-collection - add and configure a collection server for the
+        collection specified by the "c" argument
+     -- kill - if running as the local library this will kill the server
+  */
+  arg_ainfo.shortname = "cmd";
+  arg_ainfo.longname = "config command";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+}
+
+configaction::~configaction () {
+}
+
+void configaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+				     response_t &response, text_t &response_data, 
+				     ostream &logout) {
+  response = content;
+  response_data = "text/html";
+}
+
+bool configaction::do_action (cgiargsclass &args, recptprotolistclass *protos, 
+			      browsermapclass *browsers, displayclass &disp,
+			      outconvertclass &outconvert, ostream &textout,
+			      ostream &logout) {
+
+  if (recpt == NULL) return false;
+
+  if ((args["cmd"] == "add-collection") && (!args["c"].empty())) {
+    create_colservr(args["c"], logout);
+    textout << "configured add-collection\n";
+
+  } else if ((args["cmd"] == "release-collection") && (!args["c"].empty())) {
+    remove_colservr(args["c"], logout);
+    textout << "configured release-collection\n";
+
+  } else if (args["cmd"] == "kill") {
+    textout << "killed\n";
+#ifdef GSDL_LOCAL_LIBRARY
+    HWND gw = FindWindow("Greenstone Digital Library Software",
+			 "Greenstone Digital Library Software");
+    PostMessage(gw, WM_DESTROY, 0, 0);
+#endif
+  }
+
+  return true;
+}
+
+
+// create and initialize a new collection server and
+// add it to the null protocol.
+void configaction::create_colservr (const text_t &collection, ostream &logout) {
+
+  // just in case we're adding a collection that already exists
+  recpt->uncache_collection(collection);
+
+  recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    comerror_t err = noError;
+    if ((*rprotolist_here).p != NULL) {
+      if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
+	// create collection server and add it to nullproto
+	(*rprotolist_here).p->add_collection(collection, recpt, gsdlhome, collecthome, gsdlhome);
+	// re-initialize the null protocol
+	if (!(*rprotolist_here).p->init(err, logout)) {
+	  logout << "configaction::create_colservr: nullproto init failed\n";
+	}
+	return;
+      }
+    }
+    ++rprotolist_here;
+  }
+
+  logout << "configaction::create_colservr: no valid nullproto found\n";
+}
+
+// delete a collection server from the null protocol
+void configaction::remove_colservr (const text_t &collection, ostream &logout) {
+
+  recpt->uncache_collection(collection);
+
+  recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    comerror_t err = noError;
+    if ((*rprotolist_here).p != NULL) {
+      if ((*rprotolist_here).p->get_protocol_name(err) == "nullproto") {
+	(*rprotolist_here).p->remove_collection(collection, logout);
+	return;
+      }
+    }
+    ++rprotolist_here;
+  }
+
+  logout << "configaction::create_colserver: no valid nullproto found\n";
+}
Index: /gsdl/trunk/runtime-src/src/recpt/configaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/configaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/configaction.h	(revision 16571)
@@ -0,0 +1,60 @@
+/**********************************************************************
+ *
+ * configaction.h -- 
+ * Copyright (C) 2003 DL Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef CONFIGACTION_H
+#define CONFIGACTION_H
+
+#include "action.h"
+#include "receptionist.h"
+
+class configaction : public action {
+
+protected:
+  receptionist *recpt;
+
+  void create_colservr (const text_t &collection, ostream &logout);
+  void remove_colservr (const text_t &collection, ostream &logout);
+
+public:
+  configaction ();
+  virtual ~configaction ();
+
+  void set_receptionist (receptionist *therecpt) {recpt=therecpt;}
+
+  text_t get_action_name () {return "config";}
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response, text_t &response_data, 
+			 ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp,
+		  outconvertclass &outconvert, ostream &textout,
+		  ostream &logout);
+};
+
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/converter.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/converter.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/converter.cpp	(revision 16571)
@@ -0,0 +1,77 @@
+/**********************************************************************
+ *
+ * converter.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "converter.h"
+
+
+
+// the converters within converterinfo become the property of this class
+// after add_converter has been called. The converters remain the
+// responsability of the calling code and will not be deleted by this
+// class.
+void convertinfoclass::add_converter (const text_t &name, inconvertclass *inconverter,
+				      rzwsoutconvertclass *outconverter) {
+  // can't add a null converter or an action with no name
+  if (inconverter == NULL || outconverter == NULL || name.empty()) {
+    return;
+  }
+
+  converterinfo info;
+  info.name = name;
+  info.inconverter = inconverter;
+  info.outconverter = outconverter;
+  converters[name] = info;
+}
+
+
+bool operator==(const converterinfo &x, const converterinfo &y) {
+  return ((x.name == y.name) && (x.inconverter == y.inconverter) &&
+	  (x.outconverter == y.outconverter));
+}
+
+bool operator<(const converterinfo &x, const converterinfo &y) {
+  return ((x.name < y.name) ||
+	  ((x.name == y.name) &&
+	   ((x.inconverter < y.inconverter) ||
+	    ((x.inconverter == y.inconverter) &&
+	     ((x.outconverter < y.outconverter))))));
+}
+
+
+// get_inconverter will return NULL if the convert could not be found
+inconvertclass *convertinfoclass::get_inconverter (const text_t &name) {
+  iterator here = converters.find (name);
+  if (here == converters.end()) return NULL;
+
+  return (*here).second.inconverter;
+}
+
+// get_outconverter will return NULL if the convert could not be found
+rzwsoutconvertclass *convertinfoclass::get_outconverter (const text_t &name) {
+  iterator here = converters.find (name);
+  if (here == converters.end()) return NULL;
+
+  return (*here).second.outconverter;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/converter.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/converter.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/converter.h	(revision 16571)
@@ -0,0 +1,122 @@
+/**********************************************************************
+ *
+ * converter.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef CONVERTER_H
+#define CONVERTER_H
+
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "gsdlunicode.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\map>
+#elif defined(GSDL_USE_STL_H)
+#  include <map.h>
+#else
+#  include <map>
+#endif
+
+
+// inconverter and outconverter ARE NOT destroyed by this class
+// they should be destroyed by the code which created them after
+// no more pointers to the class exist.
+//
+// The above condition enables the class to be copied without
+// copying the converters which might contain a lot of data (and
+// be of an unknown derived type).
+class converterinfo {
+public:
+  text_t name;
+  inconvertclass *inconverter;
+  rzwsoutconvertclass *outconverter;
+
+  converterinfo() {inconverter=NULL; outconverter=NULL;}
+};
+
+bool operator==(const converterinfo &x, const converterinfo &y);
+bool operator<(const converterinfo &x, const converterinfo &y);
+
+
+typedef map<text_t, converterinfo, lttext_t> convertmap;
+
+// convertinfoclass is used to store a number of converters
+// indexing them by their name
+class convertinfoclass {
+protected:
+  convertmap converters;
+
+public:
+  // type support for convertmap
+  typedef convertmap::iterator iterator;
+  typedef convertmap::const_iterator const_iterator;
+  typedef convertmap::reference reference;
+  typedef convertmap::const_reference const_reference;
+  typedef convertmap::size_type size_type;
+  typedef convertmap::difference_type difference_type;
+  typedef convertmap::const_reverse_iterator const_reverse_iterator;
+  typedef convertmap::reverse_iterator reverse_iterator;
+  
+  // constructors
+  convertinfoclass () {}
+
+  // basic container support
+  iterator begin () {return converters.begin();}
+  const_iterator begin () const {return converters.begin();}
+  iterator end () {return converters.end();}
+  const_iterator end () const {return converters.end();}
+
+  void erase(iterator pos) {converters.erase(pos);}
+  void erase(iterator first, iterator last) {converters.erase(first, last);}
+  convertinfoclass &operator=(const convertinfoclass &x) 
+    {converters=x.converters;return *this;}
+
+  bool empty () const {return converters.empty();}
+  size_type size() const {return converters.size();}
+
+  const_iterator find(const text_t &key) {return converters.find(key);}
+
+  // added functionality
+  void clear () {converters.erase(converters.begin(),converters.end());}
+
+  // the converters within converterinfo become the property of
+  // of this class after add_converter has been called. The converters
+  // remain the responsability of the calling code and will not be
+  // deleted by this class.
+  void add_converter (const text_t &name, inconvertclass *inconverter,
+		      rzwsoutconvertclass *outconverter);
+
+  // get_inconverter will return NULL if the convert could not be found
+  inconvertclass *get_inconverter (const text_t &name);
+
+  // get_outconverter will return NULL if the convert could not be found
+  rzwsoutconvertclass *get_outconverter (const text_t &name);
+};
+
+
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/datelistbrowserclass.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/datelistbrowserclass.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/datelistbrowserclass.cpp	(revision 16571)
@@ -0,0 +1,186 @@
+/**********************************************************************
+ *
+ * datelistbrowserclass.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_DATELIST_BROWSER
+
+#include "datelistbrowserclass.h"
+#include <assert.h>
+
+
+datelistbrowserclass::datelistbrowserclass () {
+}
+
+datelistbrowserclass::~datelistbrowserclass () {
+}
+
+text_t datelistbrowserclass::get_browser_name () {
+  return "DateList";
+}
+
+browserclass* datelistbrowserclass::clone()
+{
+  return new datelistbrowserclass();
+}
+
+void datelistbrowserclass::load_metadata_defaults (text_tset &metadata) {
+  metadata.insert ("Date");
+  metadata.insert ("doctype");
+}
+
+text_t datelistbrowserclass::get_default_formatstring () {
+  return "<td>[link][icon][/link]</td><td>[highlight]{Or}{[dls.Title],[dc.Title],[Title],Untitled}[/highlight]</td><td>[Date]</td>";
+}
+
+int datelistbrowserclass::output_section_group (ResultDocInfo_t &/*section*/, cgiargsclass &/*args*/,
+						const text_t &/*collection*/, int /*colnumber*/, 
+						format_t * /*formatlistptr*/, bool /*use_table*/, 
+						text_tset &/*metadata*/, bool &/*getParents*/,
+						recptproto * /*collectproto*/, displayclass &/*disp*/, 
+						outconvertclass &/*outconvert*/, ostream &/*textout*/, 
+						ostream &/*logout*/) {
+  return 0;
+}
+
+int datelistbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
+						const text_t &collection, int colnumber, format_t *formatlistptr, 
+						bool use_table, text_tset &/*metadata*/, bool &/*getParents*/,
+						recptproto * collectproto, displayclass &disp, 
+						outconvertclass &outconvert, ostream &textout, ostream &logout) {
+
+  text_t lastyear = "0000";
+  text_t lastmonth = "00";
+  text_t tabbing, endtabbing;
+
+  if (use_table || colnumber > 0) {
+    textout << outconvert << "<table><tr><td>";
+    // get tab size
+    text_t tab; int itab;
+    disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
+    itab = tab.getint();
+    if (colnumber > 0) 
+      textout << outconvert << "<img alt=\"\" src=\"_httpimg_/space.gif\" width=\"" << (itab*colnumber) << "\"/>";
+    textout << outconvert << "</td><td>";
+  }
+
+  textout << outconvert << "<table class=\"date_list\">\n";
+
+  ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
+  ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
+  
+  // use the dm arg as date metadata or else Date
+  text_t date_meta = args["dm"];
+  if (date_meta == "") {
+    date_meta = "Date";
+  }
+  text_tarray dates;
+  splitchar(date_meta.begin(), date_meta.end(), ',', dates);
+
+  while (thissection != endsection) {
+
+    text_t &doctype = (*thissection).metadata["doctype"].values[0];
+
+    text_tarray::iterator begin = dates.begin();
+    text_tarray::iterator end = dates.end();
+    text_t date;
+    while (begin!= end && date.empty()) {
+      date = (*thissection).metadata[*begin].values[0];
+      begin++;
+    }
+    text_t thisyear = "";
+    text_t thismonth = "";
+    if (!date.empty()) {
+      text_t::const_iterator datebegin = date.begin();
+      int datesize = date.size();
+    
+      if (datesize >=4) {
+	thisyear = substr (datebegin, datebegin+4);
+	thismonth = "00";
+	int pos = 4;
+	// allow for yyyy-mm-dd
+	if (date[pos]=='-') {
+	  ++pos;
+	}
+	if (datesize >= pos+2)
+	  thismonth = substr (datebegin+pos, datebegin+pos+2); 
+      }
+    }
+    
+    text_t link = "<a href=\"_httpdocument_&cl=";
+    text_t icon = "_document:iconclosedbook_";
+      
+    if (doctype == "classify") {
+      icon = "_document:iconclosedbookshelf_";
+      link += (*thissection).OID + "\">";
+    } else {
+      link += args["cl"] + "&d=" + (*thissection).OID; // + "\">";
+      // [modification to allow default document detach settings -- kjdon]
+      if (args["xx"]=="1") {
+	// documents should be detached
+	link += "&x=1\" target=\\_blank>";
+      } else {
+	link += "\">";
+      }
+    }
+
+    textout << outconvert << "<tr valign=top>";
+
+    if (thisyear != "" && thisyear != lastyear) {
+      textout << outconvert << "<td><span class=\"date_list_year\">" << thisyear << "</span></td>";
+      lastyear = thisyear;
+    } else {
+      textout << outconvert << "<td></td>";
+    }
+    if (thismonth != "" && thismonth != lastmonth) {
+      textout << outconvert << disp << ("<td><span class=\"date_list_month\">_textmonth" + thismonth + "_</span></td>");
+      lastmonth = thismonth;
+    } else {
+      textout << outconvert << "<td></td>";
+    }
+    if (!use_table) textout << outconvert << "<td>\n";
+
+    text_tmap options;
+    options["link"] = link;
+    options["icon"] = icon;
+    options["highlight"] = "0";
+    textout << outconvert << disp 
+            << get_formatted_string (collection, collectproto,
+				     *thissection, disp, formatlistptr, 
+				     options, logout) << "\n";
+    
+    if (!use_table) textout << outconvert << "</td>";
+    
+    textout << outconvert << "</tr>\n";
+    
+    ++thissection;
+  }
+
+  textout << outconvert << "</table>\n";
+
+  if (use_table  || colnumber > 0) textout << outconvert << "</td></tr></table>\n";
+  return 1;
+}
+
+#endif //GSDL_USE_DATELIST_BROWSER
Index: /gsdl/trunk/runtime-src/src/recpt/datelistbrowserclass.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/datelistbrowserclass.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/datelistbrowserclass.h	(revision 16571)
@@ -0,0 +1,63 @@
+/**********************************************************************
+ *
+ * datelistbrowserclass.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_DATELIST_BROWSER
+
+#ifndef DATELISTBROWSERCLASS_H
+#define DATELISTBROWSERCLASS_H
+
+#include "browserclass.h"
+
+class datelistbrowserclass : public browserclass {
+protected:
+
+public:
+  datelistbrowserclass ();
+  virtual ~datelistbrowserclass ();
+
+  text_t get_browser_name ();
+
+  virtual browserclass* clone();
+
+  virtual void load_metadata_defaults (text_tset &metadata);
+
+  virtual text_t get_default_formatstring ();
+
+  virtual int output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
+				    const text_t &collection, int colnumber, format_t *formatlistptr, 
+				    bool use_table, text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, ostream &logout);
+  
+  virtual int output_section_group (FilterResponse_t &sections, cgiargsclass &args,
+				    const text_t &collection, int colnumber, format_t *formatlistptr, 
+				    bool use_table, text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, ostream &logout);
+};
+
+#endif //DATELISTBROWSERCLASS_H
+#endif //GSDL_USE_DATELIST_BROWSER
Index: /gsdl/trunk/runtime-src/src/recpt/depositoraction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/depositoraction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/depositoraction.cpp	(revision 16571)
@@ -0,0 +1,858 @@
+/**********************************************************************
+ *
+ * depositoraction.cpp -- 
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_DEPOSITOR_ACTION
+
+// note that the collectoraction relies on having direct access to a
+// collections configuration file. this breaks the separation between
+// receptionist and collection server and so is not suitable (at least
+// in its current form) for use when collection servers are separate 
+// from the receptionist (e.g. when using the CORBA protocol).
+
+// following line required to get fstream.filedesc() on darwin (Mac OS X)
+#define _STREAM_COMPAT  1
+// required for utsname on solaris???
+#define _XOPEN_SOURCE 1
+#define _XOPEN_SOURCE_EXTENDED 1
+
+#include "depositoraction.h"
+#include "OIDtools.h"
+#include "fileutil.h"
+#include "cfgread.h"
+#include "gsdltools.h"
+#include "gsdltimes.h"
+#include "argdb.h"
+#include "cgiutils.h"
+
+#include <stdio.h>
+//#include <strings.h> // seems to be needed for gcc 2.95, but not particularly happy it
+#include <fcntl.h>
+#include <time.h>
+
+#if !defined (__WIN32__)
+#include <sys/utsname.h>
+#include <unistd.h>
+#endif
+
+#include <new>
+//#include <string>
+#include <vector>
+#include <stdexcept>
+#include <iostream>
+//#include <cstdlib>
+
+depositoraction::depositoraction () 
+  : wizardaction()
+{
+  macro_prefix = "di1";  //deposit item
+  lastpage = 0; 
+
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "depositor";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "p";
+  arg_ainfo.longname = "page";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "select";   
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  //furthest page that has been visited
+  arg_ainfo.shortname = "di1lastpage";
+  arg_ainfo.longname = "depositor specific"; 
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";   
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+  
+  // the fileupload info that cgiwrapper produces - we parse the fileupload_t
+  // and set di1userfile, di1userfilesize
+  arg_ainfo.shortname = "di1userfileinfo";
+  arg_ainfo.longname = "depositor specific"; 
+  arg_ainfo.fileupload = true;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;  
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // essential: reset fileupload to default as we are not setting 
+  // it for each arg
+  arg_ainfo.fileupload = false;
+
+  //the name of the file to be added
+  arg_ainfo.shortname = "di1userfile";
+  arg_ainfo.longname = "depositor specific"; 
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;   
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  //the file size
+  arg_ainfo.shortname = "di1userfilesize";
+  arg_ainfo.longname = "depositor specific"; 
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";   
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+ //the file timestamp
+  arg_ainfo.shortname = "di1timestamp";
+  arg_ainfo.longname = "depositor specific"; 
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";   
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // temporary directory name for this collector
+  // session
+  arg_ainfo.shortname = "di1tmp";
+  arg_ainfo.longname = "depositor specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+//   arg_ainfo.shortname = "di1fullname";
+//   arg_ainfo.longname = "depositor specific";
+//   arg_ainfo.multiplechar = true;
+//   arg_ainfo.defaultstatus = cgiarginfo::weak;
+//   arg_ainfo.argdefault = g_EmptyText;
+//   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+//   argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "di1dirname";
+  arg_ainfo.longname = "depositor specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "di1contactemail";
+  arg_ainfo.longname = "depositor specific";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+//   arg_ainfo.shortname = "di1clone";
+//   arg_ainfo.longname = "depositor specific";
+//   arg_ainfo.multiplechar = false;
+//   arg_ainfo.defaultstatus = cgiarginfo::weak;
+//   arg_ainfo.argdefault = "0";
+//   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+//   argsinfo.addarginfo (NULL, arg_ainfo);
+
+//   arg_ainfo.shortname = "di1clonecol";
+//   arg_ainfo.longname = "depositor specific";
+//   arg_ainfo.multiplechar = true;
+//   arg_ainfo.defaultstatus = cgiarginfo::weak;
+//   arg_ainfo.argdefault = g_EmptyText;
+//   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+//   argsinfo.addarginfo (NULL, arg_ainfo);
+
+//   arg_ainfo.shortname = "cfgfile";
+//   arg_ainfo.longname = "configuration file contents";
+//   arg_ainfo.multiplechar = true;
+//   arg_ainfo.defaultstatus = cgiarginfo::weak;
+//   arg_ainfo.argdefault = g_EmptyText;
+//   arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+//   argsinfo.addarginfo (NULL, arg_ainfo);
+
+//   // will be set if we arrived at the "configure collection" page
+//   // via the "changing an existing collection" page
+//   arg_ainfo.shortname = "di1econf";
+//   arg_ainfo.longname = "depositor specific";
+//   arg_ainfo.multiplechar = false;
+//   arg_ainfo.defaultstatus = cgiarginfo::weak;
+//   arg_ainfo.argdefault = "0";
+//   arg_ainfo.savedarginfo = cgiarginfo::must;
+//   argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // wizard uses this to see if we are working with an existing collection:
+  // set the default to 1
+  arg_ainfo.shortname = "di1esrce";
+  arg_ainfo.longname = "depositor specific";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "1";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+//   arg_ainfo.shortname = "di1input";
+//   arg_ainfo.longname = "depositor specific";
+//   arg_ainfo.multiplechar = true;
+//   arg_ainfo.multiplevalue = true;
+//   arg_ainfo.defaultstatus = cgiarginfo::weak;
+//   arg_ainfo.argdefault = g_EmptyText;
+//   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+//   argsinfo.addarginfo (NULL, arg_ainfo);
+
+//   //we don't need this in the depositor
+//   arg_ainfo.shortname = "di1inputtype";
+//   arg_ainfo.longname = "depositor specific";
+//   arg_ainfo.multiplechar = true;
+//   arg_ainfo.multiplevalue = true;
+//   arg_ainfo.defaultstatus = cgiarginfo::weak;
+//   arg_ainfo.argdefault = g_EmptyText;
+//   arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
+//   argsinfo.addarginfo (NULL, arg_ainfo);
+
+}
+
+depositoraction::~depositoraction () {
+}
+
+
+bool depositoraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, recptprotolistclass * protos, ostream &logout) {
+
+  wizardaction::check_cgiargs(argsinfo,args,protos,logout);
+
+  text_t &current_page = args["p"];
+
+  // note that the "bildstatus" and "bildframe1" pages don't actually do anything
+  // functional so we don't need to worry about authenticating them (it's the 
+  // underlying "bild" page that does the building (and creates the frameset))
+  // This helps us overcome a bit of a problem we have with multiple pages trying
+  // to read from the key.db database at the same time.
+
+  //right now, anyone can do anything until it's time to build
+  if (current_page == "select") {
+    //authenticate the user if authentication is available
+    args["uan"] = 1;
+    args["ug"] = "all-collections-editor";
+  }
+
+
+  //Check to see if a file was specified
+  //if so, upload it and set the di1userfile, di1userfilesize, and 
+  //di1timestamp args.
+  //every time a new file is specified, a new timestamped folder is 
+  //created.  
+
+  // This doesn't create a problem but is inefficient (wasted space)
+  // Consider recoding at some point in the future.
+
+  fileupload_t *fileupload = args.getargfile("di1userfileinfo");
+
+  if (fileupload != NULL) {
+
+    if (!(*fileupload).tmp_name.empty() && file_exists((*fileupload).tmp_name)) {
+      // create the timestamp
+      time_t timestamp = time(NULL);
+      text_t timestamp_str(timestamp); 
+
+      args["di1timestamp"] = timestamp_str;
+
+      // set filename and size from the fileupload struct
+      args["di1userfilesize"] = (*fileupload).size;
+      args["di1userfile"] = (*fileupload).name;
+      // copy the file into its temporary location
+      text_t tmpdir = filename_cat(gsdlhome,"tmp",args["di1tmp"],timestamp_str);
+      bool tflag = mk_dir(tmpdir);
+      text_t tmpfile = filename_cat(tmpdir,(*fileupload).name);
+      if (!file_copy((*fileupload).tmp_name, tmpfile)) {
+	cerr << "Depositor error: cannot save uploaded fileto  "<<tmpfile<<endl;
+      } else {
+	cerr << "Depositor: saved uploaded file to "<<tmpfile<<endl;
+      }
+    } 
+  }
+  
+  if (current_page == "select") {  
+ 
+    //make sure the last page arg is re-set to zero 
+    //since a new collection is being chosen
+    args["di1lastpage"] = "0";
+
+    // assign (and create) a temporary directory This will create a new
+    // tbuild directory every time the user goes back to select a new
+    // collection.  It causes no problems except wasted space.  Should be
+    // addressed in the future
+    if (assign_tmpname (args, logout)==false) {
+      // there was an error creating the tmp dir
+      message="tmpfail";
+      return true; // true because we could still parse the arguments
+    }
+
+    // clean up any old builds left laying about in the tmp directory
+    // (note that it's possible this could take some time if there's a huge
+    // partially built collecton laying about so we'll make it an asynchronous
+    // system call)
+    gsdl_system ("perl -S cleantmp.pl", false, logout);
+
+  }
+
+  if (current_page == "bildstatus" || current_page == "bildcancel") {
+    // if .final file exists then build has finished
+    text_t fbld = filename_cat (gsdlhome, "tmp", args[macro_prefix + "tmp"], args[macro_prefix + "dirname"] + ".bld.final");
+    if (file_exists (fbld)) {
+      char *fbldc = fbld.getcstr();
+      ifstream fbld_in (fbldc);
+      if (fbld_in) {
+	failcode = fbld_in.get();
+	fbld_in.close();
+	if (failcode == '0') {
+	  // success - we need to create and configure a collection server for the
+	  // newly built collection (for fastcgi and local library where
+	  // initialization isn't going to be redone when the user clicks the
+	  // "view your new collection" button
+	  create_colserver (args[macro_prefix + "dirname"], logout);
+	  current_page = "bilddone";
+	}
+	else current_page = "bildfail";
+      } else {
+	// assume build failed (we shouldn't get here though ... right?)
+	current_page = "bildfail";
+      }
+      delete []fbldc;
+    }
+  }
+
+  //is it a step page?
+  text_t::const_iterator here = current_page.begin();
+  text_t::const_iterator end = current_page.end();
+  text_t stepstring = substr(here,here+4);
+
+  //if so, increment the step count 
+  //this should not be going up more than one at a time. 
+  if(stepstring == "step") {
+    text_t currpage_textt = substr(here+4,here+5);
+    int currpage = currpage_textt.getint();
+
+    text_t lastpage_textt = args["di1lastpage"]; 
+    int lastpage = lastpage_textt.getint(); 
+    if (currpage > lastpage) {
+      lastpage++; 
+      text_t lastpage_textt(lastpage); 
+      args["di1lastpage"] = lastpage_textt;      
+    }
+  }
+  return true;
+}  
+
+
+void depositoraction::define_internal_macros (displayclass &disp, cgiargsclass &args, 
+					      recptprotolistclass *protos, ostream &logout) {
+
+  // define_internal_macros sets some/all of the following macros (depending
+  // on cgiargs):
+  //
+  // _pagescriptextra_
+  // _header_
+  // _depositorbar_
+  // _textfailmsg_
+  // _di1userfile_
+  // _di1userfilesize_
+
+  text_t &depositor_page = args["p"];
+  
+  // set _pagescriptextra_ macro to _cpagescriptextra_
+  disp.setmacro ("pagescriptextra", "depositor", "_" + depositor_page + "scriptextra_");
+
+  if (depositor_page == "bildstatus" || depositor_page == "bilddone" || 
+      depositor_page == "bildfail" || depositor_page == "bildframe1" || 
+      depositor_page == "select") {
+    disp.setmacro ("header", "depositor", "_" + depositor_page + "header_");
+  }
+
+  if (depositor_page == "bildstatus") {
+    set_statusline (disp, args, logout);
+  }
+
+  if (depositor_page == "select") {
+    set_fullnamemenu (disp, args, protos, logout);
+  }
+
+  //how many pages in collection?
+  //we need a _depositorbar_ for each
+
+  text_t numsteps_str;
+  disp.expandstring("depositor", "_numsteps_", numsteps_str);
+  int numsteps = numsteps_str.getint();
+   
+  //is the page a step page? 
+
+  text_t::const_iterator here = depositor_page.begin();
+  text_t::const_iterator end = depositor_page.end();
+  text_t stepstring = substr(here,here+4);
+
+  if((stepstring) == "step" || (depositor_page == "depositonly") ) {
+    disp.setmacro("di1userfile","depositor",args["di1userfile"]);
+    disp.setmacro("di1userfilesize","depositor",args["di1userfilesize"]);
+  }
+
+  //set up the depositor bar
+  text_t depositorbar = "<table class=wizardbar border=0 cellspacing=4 cellpadding=0><tr>\n";
+
+  if(stepstring == "step") {
+
+    here = depositor_page.begin();
+    text_t stepnums = substr(here+4,here+5); 
+    int stepnum = stepnums.getint();
+
+    text_t lastpage_textt = args["di1lastpage"];
+    int lastpage = lastpage_textt.getint(); 
+    
+    // again, begin with the select bar...
+    //the first button - selecting a collection
+    for(int i = 1; i <= numsteps; i++) {
+      text_t numstr(i); 
+      if(i <= lastpage && i == stepnum) {
+	depositorbar += get_button (args,depositor_page, "yellow", "step"+numstr, false);
+      } else if (i <= lastpage) {
+	depositorbar += get_button (args,depositor_page, "yellow", "step"+numstr, true); 
+      } else if((i == lastpage+1)){
+	depositorbar += get_button (args,depositor_page, "green", "step"+numstr, true);       
+      } else { 
+	depositorbar += get_button (args,depositor_page, "grey", "step"+numstr, false);       
+      }
+      depositorbar += "<td>_icongreyarrow_</td>\n";
+
+    }
+
+    //the build and preview pages are always last
+    if(lastpage == numsteps) {
+      depositorbar += get_button (args,depositor_page, "green", "laststep", true);
+    } else {
+      depositorbar += get_button (args,depositor_page, "grey", "laststep", false);
+    }
+
+    text_t laststep_textt;
+    disp.expandstring("depositor", "_laststep_", laststep_textt);
+    if(laststep_textt == "bild") {
+      depositorbar += "<td>_icongreyarrow_</td>\n";
+      depositorbar += get_button (args,depositor_page, "grey", "view", false);
+    }
+    depositorbar += "</tr><tr>"; 
+
+    for(int j = 1; j <= 2*(stepnum-1); j++) {
+      depositorbar += "<td></td>";
+    }
+    depositorbar += "<td align=center>_icongreyuparrow_</td>\n";    
+
+    depositorbar += "</tr></table>\n";
+    
+  }
+  
+  if ((depositor_page == "bildcancel") || (depositor_page == "bildfail")) {
+  
+    for(int i = 1; i <= numsteps; i++) {
+
+      text_t numstr(i); 
+      depositorbar += get_button (args,depositor_page, "yellow", "step"+numstr, true);       
+      depositorbar += "<td>_icongreyarrow_</td>\n";
+
+    }
+
+    //the build and preview pages are always last
+    depositorbar += get_button (args,depositor_page, "green", "laststep", true);
+    depositorbar += "<td>_icongreyarrow_</td>\n";
+    depositorbar += get_button (args,depositor_page, "grey", "view", false); 
+
+    depositorbar += "</tr><tr>"; 
+
+    for(int j = 1; j <= 2*numsteps; j++) {
+      depositorbar += "<td></td>";
+    }
+    depositorbar += "<td align=center>_icongreyuparrow_</td>\n";    
+
+    depositorbar += "</tr></table>\n";
+
+  }
+
+  if(depositor_page == "bilddone"){
+    
+    for(int i = 1; i <= numsteps; i++) {
+
+      text_t numstr(i); 
+      depositorbar += get_button (args, depositor_page, "grey", "step"+numstr, false);       
+      depositorbar += "<td>_icongreyarrow_</td>\n";
+
+    }
+
+    //the build and preview pages are always last
+    depositorbar += get_button (args,depositor_page, "yellow", "laststep", false);
+    depositorbar += "<td>_icongreyarrow_</td>\n";
+    depositorbar += get_button (args,depositor_page, "green", "view", true);
+
+    depositorbar += "</tr><tr>"; 
+
+    for(int j = 1; j <= 2*numsteps; j++) {
+      depositorbar += "<td></td>";
+    }
+    depositorbar += "<td align=center>_icongreyuparrow_</td>\n";    
+
+    depositorbar += "</tr></table>\n";
+  }
+  disp.setmacro ("depositorbar", "depositor", depositorbar);
+
+  if (depositor_page == "bildfail") {
+ 
+    text_t textfailmsg = "_textfailmsg";
+    textfailmsg.push_back(failcode);
+    textfailmsg.push_back('_');
+    disp.setmacro("textfailmsg", "depositor", textfailmsg);
+
+    text_t bldlog = filename_cat(gsdlhome, "tmp", args["di1tmp"], args["di1dirname"] + ".bld");
+    text_t rawlog = file_tail (bldlog, 6, 0);
+    // we'll shove in some <br> tags where \n's occur
+    text_t faillog;
+    text_t::const_iterator here = rawlog.begin();
+    text_t::const_iterator end = rawlog.end();
+    while (here != end) {
+      if (*here == '\n') faillog += "<br>";
+      faillog.push_back (*here);
+      ++here;
+    }
+    disp.setmacro ("faillog", "depositor", dm_safe(faillog));
+  }
+}
+
+
+//basic framework
+bool depositoraction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/, 
+				 browsermapclass * /*browsers*/, displayclass &disp, 
+				 outconvertclass &outconvert, ostream &textout, 
+				 ostream &logout) {
+  // make sure the depositor is enabled
+  if (disabled) {
+    textout << outconvert 
+	    << "<html>\n"
+	    << "<head>\n"
+	    << "<title>Depositor disabled</title>\n"
+	    << "</head>\n"
+	    << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
+	    << "alink=\"#cc9900\" vlink=\"#666633\">\n"
+	    << "<h2>Facility disabled</h2>\n" 
+	    << "Sorry, the Depositor end-user collecation update facility is currently disabled\n"
+	    << "\n</body>\n"
+	    << "</html>\n";
+    return true;
+  }
+
+  text_t &depositor_page = args["p"];
+  text_t &collection = args["di1dirname"];
+
+  // make sure we have perl (we won't bother with this check for the 
+  // building status pages to avoid slowing things down unneccessarily)
+  if (depositor_page != "bildstatus" && depositor_page != "bildframe1" && !perl_ok(logout)) {
+    textout << outconvert 
+	    << "<html>\n"
+	    << "<head>\n"
+	    << "<title>Perl not found</title>\n"
+	    << "</head>\n"
+	    << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
+	    << "alink=\"#cc9900\" vlink=\"#666633\">\n"
+	    << "<h2>Perl not found</h2>\n" 
+	    << "Greenstone could not detect perl on this system. It is therefore not\n"
+	    << "possible to build a Greenstone collection, either from the Collector or the \n"
+	    << "command-line tools, or to use the Collector for any other task.\n"
+	    << "<p>Please refer to the Greenstone Installer's Guide for details on\n"
+	    << "installing perl on your system.\n"
+	    << "\n</body>\n"
+	    << "</html>\n";
+    return true;
+
+  }
+
+  text_t::const_iterator here = depositor_page.begin();
+  text_t::const_iterator end = depositor_page.end();
+  text_t stepstring = substr(here,here+4);
+
+  if ((depositor_page == "select") || (stepstring == "step")) {
+          textout << outconvert << disp << ("_depositor:header_\n")
+	      << ("_depositor:" + depositor_page + "content_\n")
+	      << ("_depositor:footer_\n");
+	  
+  }
+
+  if ((depositor_page == "bild") || (depositor_page == "depositoronly")) {
+
+    text_t filename_textt = args["di1userfile"];
+    text_t timestamp_str = args["di1timestamp"];
+    //check to make sure a file was uploaded
+    //if more than one upload occurred, the last one is taken
+    if(filename_textt == "") {
+      textout << outconvert << disp << "<p> no file available</p>\n"; 
+    } else {
+    
+      text_t col_dirname = filename_cat(collecthome,args[macro_prefix+"dirname"]);
+      text_t import_dirname = filename_cat(col_dirname,"import");
+      if(!directory_exists(import_dirname)) {
+	bool flag = mk_dir(import_dirname);
+	if(!flag) {
+	  cerr << "Error: unable to make directory " << import_dirname << endl;
+	  return true; 
+	}
+      } 
+
+      text_t dirname = filename_cat(import_dirname,timestamp_str);
+      bool flag = mk_dir(dirname);
+      if(!flag) {
+	cerr << "Error: unable to make timestamp directory " << dirname << endl;
+	return true; 
+      }
+
+      text_t filename_textt = args["di1userfile"]; 
+      text_t tmpdir = filename_cat(gsdlhome,"tmp",args["di1tmp"],timestamp_str);
+      text_t tmpfile = filename_cat(tmpdir,filename_textt);
+      text_t filename = filename_cat(dirname, filename_textt);  
+      if(!file_copy(tmpfile, filename)) {
+	cerr << "Unable to copy " << tmpfile << " to " << filename << endl; 
+      }
+      
+      //write the metadata file
+      write_metadata_file(args, filename_textt, timestamp_str); 
+
+      if(depositor_page == "bild"){
+
+	//create a manifest file 
+	write_manifest_file(args, filename_textt, timestamp_str);
+	
+	// do the work (download, import, build) 
+	gsdl_build (args, logout);
+
+	if (message.empty()) {
+	  // bild page is a frameset so we don't want headers and stuff
+	  textout << outconvert << disp << ("_depositor:bildcontent_\n");
+	}
+      }
+    }
+  }
+
+  if (message.empty()) {
+
+    if (depositor_page != "bild" && stepstring != "step" && depositor_page != "select") {
+      // output page ("bild" page was already output above)
+      textout << outconvert << disp << ("_depositor:header_\n")
+	      << ("_depositor:" + depositor_page + "content_\n")
+	      << ("_depositor:footer_\n");
+    }
+  } else {
+    // message was set somewhere (probably an error), output message page
+    textout << outconvert << disp << ("_depositor:header_\n")
+	    << ("_depositor:" + message + "content_\n")
+	    << ("_depositor:footer_\n");
+    message.clear();
+  }
+ 
+  return true;
+
+}
+
+
+//This function creates a metadata.xml file
+void depositoraction::write_metadata_file(cgiargsclass &args, text_t filename_str, text_t& timestamp_str)
+{
+
+    //build metadata file
+    //the front
+    text_t metadata_file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+    metadata_file += "<!DOCTYPE DirectoryMetadata SYSTEM \"http://greenstone.org/dtd/DirectoryMetadata/1.0/DirectoryMetadata.dtd\">\n"; 
+    metadata_file += "<DirectoryMetadata>\n";
+    metadata_file += "    <FileSet>\n";
+    metadata_file += "        <FileName>";
+
+    // Generate 'regular expression' save version of filename
+    // for now that means escaping any '.' characters
+    // consider generalising as function in gsdltools.h/cpp?
+
+    text_t filename_re;
+    text_t::const_iterator here = filename_str.begin();
+    text_t::const_iterator end = filename_str.end();
+    while (here != end) {
+      if (*here == '.') {
+	filename_re.push_back('\\');
+      }
+
+      filename_re.push_back(*here);
+      ++here;
+    }
+
+    metadata_file += filename_re;
+
+    metadata_file += "</FileName>\n"; 
+    metadata_file += "        <Description>\n";
+
+
+    cgiargsclass::const_iterator args_here = args.begin();
+    cgiargsclass::const_iterator args_end = args.end();
+
+    while (args_here != args_end) {
+      text_t args_name = (*args_here).first;
+
+      int prefix_len = macro_prefix.size();
+      
+      text_t args_prefix = substr(args_name.begin(),args_name.begin()+prefix_len+3);
+      
+      if (args_prefix == (macro_prefix+"md.")) {     
+        text_t args_val = args[args_name];
+
+	text_t args_suffix = substr(args_name.begin()+prefix_len+3,args_name.end()); 
+
+	text_tarray mdvalues;
+	splitchar (args_val.begin(), args_val.end(), ',', mdvalues);
+	int numvalues = mdvalues.size();
+
+	for (int i = 0; i < numvalues; ++i) {
+	  if (!mdvalues[i].empty()) {
+
+	    decode_cgi_arg(mdvalues[i]);
+
+	    metadata_file += "            <Metadata mode=\"accumulate\" name=\"";
+	    metadata_file += args_suffix;
+	    metadata_file += "\">";
+	    metadata_file += mdvalues[i];
+	    metadata_file += "</Metadata>\n";
+
+	  }
+	}
+
+      }	
+
+
+      ++args_here;
+    }
+    
+    //the end of the file
+    metadata_file += "        </Description>\n"; 
+    metadata_file += "    </FileSet>\n"; 
+    metadata_file += "</DirectoryMetadata>\n"; 
+
+    //create metadata.xml file
+    text_t metadata_path = filename_cat(collecthome, args[macro_prefix+"dirname"], "import", timestamp_str, "metadata.xml");
+    text_t my_path = filename_cat(gsdlhome,"tmp", "metadata.xml");
+
+    ofstream metadata(metadata_path.getcstr());
+    ofstream my_tmp(my_path.getcstr()); 
+
+    if(!metadata.is_open()) {
+      cerr << "Cannot open metadata.xml!" << endl; 
+    } else {
+
+      //write metadata.xml
+      metadata.write(metadata_file.getcstr(), metadata_file.size()); 
+      my_tmp.write(metadata_file.getcstr(), metadata_file.size()); 
+    }
+}
+
+//This function creates a manifest.xml file
+void depositoraction::write_manifest_file(cgiargsclass &args, text_t filename, 
+					  text_t& timestamp_str)
+{
+
+    //build manifest file
+
+    //the front
+    text_t manifest_file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+    manifest_file += "<Manifest>\n";
+    manifest_file += "    <Index>\n";
+    manifest_file += "        <Filename>\n";
+    manifest_file += "          " + timestamp_str + "\n";
+    manifest_file += "        </Filename>\n"; 
+    
+    //the end of the file
+    manifest_file += "    </Index>\n"; 
+    manifest_file += "</Manifest>\n"; 
+
+    //create manifest.xml file
+    text_t manifest_path = filename_cat(collecthome, args[macro_prefix+"dirname"], "manifest.xml");
+
+    char* manifest_cstr = manifest_path.getcstr();
+
+    ofstream manifest(manifest_cstr);
+
+    if(!manifest.is_open()) {
+      cerr << "Cannot open" << manifest_cstr << endl; 
+    } else {
+
+      //write manifest.xml
+      char *manifest_file_cstr = manifest_file.getcstr();
+      manifest.write(manifest_file_cstr, manifest_file.size()); 
+      delete [] manifest_file_cstr;
+    }
+
+    delete [] manifest_cstr;
+}
+
+
+
+text_t depositoraction::get_button(cgiargsclass &args, const text_t &thispage, 
+				   const text_t &color, 
+				   const text_t &type, bool enabled) 
+{
+
+  text_t::const_iterator here = type.begin();
+  text_t::const_iterator end = type.end();
+  text_t stepstring = substr(here,here+4);
+  if ((color != "green" && color != "grey" && color != "yellow") ||
+      (type != "select" && type != "laststep" && stepstring != "step" && type != "view"))
+    return g_EmptyText;
+
+  text_t href = "_http"+type+"_";
+  text_t target = "";
+
+  here = thispage.begin();
+  stepstring = substr(here,here+4);  
+  if (thispage == "bildcancel" || thispage == "bildfail" || thispage == "select"|| stepstring == "step") {
+    // call the check submit macro instead of linking directly to the page
+
+    if(type == "laststep") {
+      href="\"javascript:check_submit('_"+type+"_');\"";
+    } else {
+      href="\"javascript:check_submit('"+type+"');\"";
+    }
+
+  } else if (type == "view") {
+   //target = " target=_top";
+    target = " target=_blank";
+  }
+
+  text_t tdclass = "wizardbar"+color; 
+  if (enabled) {
+    // link to the appropriate page
+    return "<td class="+tdclass+"><a href="+href+target+">_text"+type+"_</a></td>";
+  }
+  else {
+    // just display the text
+    return "<td class="+tdclass+">_text"+type+"_</td>";
+  }
+}
+
+
+#endif //GSDL_USE_DEPOSITOR_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/depositoraction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/depositoraction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/depositoraction.h	(revision 16571)
@@ -0,0 +1,71 @@
+/**********************************************************************
+ *
+ * depositoraction.h -- 
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_DEPOSITOR_ACTION
+
+#ifndef DEPOSITORACTION_H
+#define DEPOSITORACTION_H
+
+#include "wizardaction.h"
+#include "receptionist.h"
+
+class depositoraction : public wizardaction {
+  
+protected:
+
+  int lastpage; 
+
+public:
+  depositoraction ();
+  virtual ~depositoraction ();
+
+  void write_metadata_file(cgiargsclass &args, text_t filename_str, text_t& timestamp_str);
+
+  void write_manifest_file(cgiargsclass &args, text_t filename, text_t& timestamp_str);
+
+  text_t get_action_name () {return "depositor";}
+
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass *protos, ostream &logout);
+
+  //we need to redefine this
+  void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+
+  //and this
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+  text_t get_button(cgiargsclass &args, const text_t &thispage, 
+		    const text_t &color, 
+		    const text_t &type, bool enabled);
+
+};
+
+#endif //!DEPOSITORACTION_H
+#endif //GSDL_USE_DEPOSITOR_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/documentaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/documentaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/documentaction.cpp	(revision 16571)
@@ -0,0 +1,1639 @@
+/**********************************************************************
+ *
+ * documentaction.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include <string.h>
+
+#include "documentaction.h"
+#include "recptprototools.h"
+#include "OIDtools.h"
+#include "querytools.h"
+#include "unitool.h"
+#include "gsdltools.h"
+#include "highlighttext.h"
+#include "browsetoolsclass.h"
+
+documentaction::documentaction () {
+  recpt = NULL;
+
+  // this action uses cgi variables "a", "d", "cl",
+  // "x", "gc", "gt", "gp", and "hl"
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "p";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "d";
+  arg_ainfo.longname = "document OID";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::none;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::can;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // whether or not a document should be retrieved from the 
+  // library or the Web.
+  arg_ainfo.shortname = "il";
+  arg_ainfo.longname = "internal link preference";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "l";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "cl";
+  arg_ainfo.longname = "classification OID";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::none;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::can;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // in this action "gc" controls the expand/contract
+  // contents function
+  arg_ainfo.shortname = "gc";
+  arg_ainfo.longname = "expand contents";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::can;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // in this action "gt" controls the expand/contract
+  // text function 0 = not expanded, 1 = expand unless 
+  // there are more than 10 sections containing text,
+  // 2 = expand all
+  arg_ainfo.shortname = "gt";
+  arg_ainfo.longname = "expand text";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::can;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // in this action "gp" is the "go to page" control
+  // used by the Book type of toc
+  arg_ainfo.shortname = "gp";
+  arg_ainfo.longname = "go to page";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::none;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // in this action "hl" is the "highlighting on/
+  // highlighting off control ("hl" == "2" is a
+  // special case that forces phrase highlighting
+  // to be used even if the query string doesn't
+  // appear to be a phrase)
+  arg_ainfo.shortname = "hl";
+  arg_ainfo.longname = "highlighting on/off";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "1";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "x" is 0 normally or 1 if page
+  // has been "detached"
+  arg_ainfo.shortname = "x";
+  arg_ainfo.longname = "detached page";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "xx" is 0 normally or 1 if documents should be detached by default
+  arg_ainfo.shortname = "xx";
+  arg_ainfo.longname = "detach all doc pages";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  
+  // f arg is set to 1 if document is to 
+  // be displayed in a frame
+  arg_ainfo.shortname = "f";
+  arg_ainfo.longname = "frame";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // fc arg is "1" if search bar is to be included (i.e. if "fc" == 1
+  // the httpdocument macro will include "&f=1"
+  arg_ainfo.shortname = "fc";
+  arg_ainfo.longname = "include search bar";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "1";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  //rd is whether a document will be displayed
+  //with a relevant document list
+  arg_ainfo.shortname = "rd";
+  arg_ainfo.longname = "include relevant documents";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  //dm is the metadata that has been used for the datelist
+  arg_ainfo.shortname = "dm";
+  arg_ainfo.longname = "date metadata";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+}
+
+documentaction::~documentaction()
+{
+}
+
+bool documentaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+				    recptprotolistclass *protos, ostream &logout) {
+
+   if(!args["d"].empty())
+      {
+	 text_t docTop;
+	 get_top(args["d"],docTop);
+	 
+	 recptproto* collectproto = protos->getrecptproto (args["c"], logout);
+	 if (collectproto != NULL)
+	    {
+	       ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
+	       
+	       if(cinfo->authenticate == "document") 
+		  {
+		     // both are either commented out or uncomment and are empty
+		     if (cinfo->public_documents.empty() && cinfo->private_documents.empty())
+			{
+			   //deny everything
+			   args["uan"] = "1";
+			   args["ug"] = cinfo->auth_group;
+			}
+
+		     // both public_documents and private_documents are turned on !
+		     else if (!cinfo->public_documents.empty() && !cinfo->private_documents.empty())
+			{
+			   //deny everything
+			   args["uan"] = "1";
+			   args["ug"] = cinfo->auth_group;
+			}
+		     
+		     // if public_documents is set but this document isn't
+		     // listed in it we need to authenticate
+		     else if ((!cinfo->public_documents.empty()) && 
+			      (cinfo->public_documents.find(docTop) == cinfo->public_documents.end()))
+		       {
+			 args["uan"] = "1";
+			 args["ug"] = cinfo->auth_group;
+		       }
+		     
+		     // if private_documents is set and this document is
+		     // listed in it we need to authenticate
+		     else if ((!cinfo->private_documents.empty()) &&
+			      (cinfo->private_documents.find(docTop) != cinfo->private_documents.end()))
+		       {
+			 args["uan"] = "1";
+			 args["ug"] = cinfo->auth_group;
+		       }
+		     
+		  }
+	    }
+      }
+   // check gc argument
+   int arg_gc = args.getintarg("gc");
+  if (arg_gc < 0 || arg_gc > 2) {
+    logout << "Warning: \"gc\" argument out of range (" << arg_gc << ")\n";
+    cgiarginfo *gcinfo = argsinfo.getarginfo ("gc");
+    if (gcinfo != NULL) args["gc"] = gcinfo->argdefault;
+  }
+
+  // check gt argument (may be either 0, 1 or 2)
+  int arg_gt = args.getintarg("gt");
+  if (arg_gt != 0 && arg_gt != 1 && arg_gt != 2) {
+    logout << "Warning: \"gt\" argument out of range (" << arg_gt << ")\n";
+    cgiarginfo *gtinfo = argsinfo.getarginfo ("gt");
+    if (gtinfo != NULL) args["gt"] = gtinfo->argdefault;
+  }
+
+  // check hl argument
+  int arg_hl = args.getintarg("hl");
+  if (arg_hl < 0 || arg_hl > 2) {
+    logout << "Warning: \"hl\" argument out of range (" << arg_hl << ")\n";
+    cgiarginfo *hlinfo = argsinfo.getarginfo ("hl");
+    if (hlinfo != NULL) args["hl"] = hlinfo->argdefault;
+  }
+
+  // check x argument
+  int arg_x = args.getintarg("x");
+  if (arg_x != 0 && arg_x != 1) {
+    logout << "Warning: \"x\" argument out of range (" << arg_x << ")\n";
+    cgiarginfo *xinfo = argsinfo.getarginfo ("x");
+    if (xinfo != NULL) args["x"] = xinfo->argdefault;
+  }
+
+  //checks whether rd arg is valid
+  int arg_rd = args.getintarg("rd");
+  if (arg_rd != 0 && arg_rd != 1) {
+    logout << "Warning: \"rd\" argument out of range (" << arg_rd << ")\n";
+    cgiarginfo *rdinfo = argsinfo.getarginfo ("rd");
+    if (rdinfo != NULL) args["rd"] = rdinfo->argdefault;
+  }
+
+
+  return true;
+}
+
+void documentaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+				       response_t &response,text_t &response_data, 
+				       ostream &logout) {
+
+  if ((args["il"] == "w") && (!args["d"].empty())) {
+
+    recptproto* collectproto = protos->getrecptproto (args["c"], logout);
+    if (collectproto != NULL) {
+      
+      text_tset metadata;
+      FilterResponse_t filt_response;
+      text_t top;
+
+      metadata.insert ("URL");
+      
+      // get metadata for parent document
+      get_top (args["d"], top);
+      if (get_info (top, args["c"], args["l"], metadata, false, collectproto, filt_response, logout)) {
+	text_t url = filt_response.docInfo[0].metadata["URL"].values[0];
+	
+	response = location;
+	response_data = url;
+	return;
+      } else {
+	// error, no URL
+	logout << "Error: documentaction::get_cgihead_info failed on get_info" << endl;
+      }
+    }
+  }
+  response = content;
+  response_data = "text/html";
+}
+
+// set_widthtspace calculates how wide the spaces in the nav bar should
+// be and sets the appropriate macro
+void documentaction::set_spacemacro (displayclass &disp, FilterResponse_t &response,
+				     bool has_search_button) {
+
+  text_t width;
+  int twidth, swidth, iwidth = 0;
+
+  int numc = response.docInfo.size();
+  ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
+  ResultDocInfo_tarray::iterator docend = response.docInfo.end();
+	
+  disp.expandstring (displayclass::defaultpackage, "_pagewidth_", width);
+  twidth = width.getint();
+
+  if (has_search_button) {
+    disp.expandstring ("query", "_searchwidth_", width);
+    iwidth += width.getint();
+  } else {
+    numc -= 1;
+  }
+  
+  while (dochere != docend) {
+    const text_t &title = (*dochere).metadata["Title"].values[0];
+
+    disp.expandstring ("document", "_" + title + "width_", width);
+    if (width == ("_" + title + "width_")) {
+      disp.expandstring ("document", "_defaultwidth_", width);
+    }
+    iwidth += width.getint();
+    ++dochere;
+  }
+
+  if ((twidth - iwidth) < numc) swidth = 2;
+  else {
+    swidth = twidth - iwidth;
+    if (numc > 0) swidth = swidth / numc;
+  }
+  disp.setmacro ("widthtspace", displayclass::defaultpackage, swidth);
+}
+
+// set_navbarmacros sets _navigationbar_ and _httpbrowseXXX_ macros
+// reponse contains 1 metadata field (Title)
+void documentaction::set_navbarmacros (displayclass &disp, FilterResponse_t &response, 
+				       bool has_search_button, cgiargsclass &args,
+				       ColInfoResponse_t &cinfo) {
+
+
+   bool use_pulldown = false;
+   text_tmap::iterator it = cinfo.format.find("NavigationBar");
+   if (it != cinfo.format.end()) {
+      if (it->second == "pulldown") {
+	 use_pulldown = true;
+      }
+   }
+
+   text_t topparent;
+   text_t &arg_d = args["d"];
+   text_t navigationbar = "<!-- Navigation Bar -->\n";
+
+   get_top (args["cl"], topparent);
+   int numc = response.docInfo.size();
+   ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
+   ResultDocInfo_tarray::iterator docend = response.docInfo.end();
+
+   if (!use_pulldown) {
+      if (has_search_button) {
+	// search uses its own navtab, as it may be suppressed based on other args
+	navigationbar += "_navtabsearch_";
+	if (args["a"] == "q") {
+	  navigationbar += "(selected)";
+	}
+      }
+      
+      if (has_search_button || numc == 0) navigationbar += "_navbarspacer_";
+      
+      bool first = true;
+      while (dochere != docend) {
+	if (!first) navigationbar += "_navbarspacer_";
+	
+	text_t title = (*dochere).metadata["Title"].values[0];
+	
+	navigationbar += "_navtab_(_httpbrowse"+(*dochere).OID+"_,"+title;
+	// if we are at this classifier
+	if (arg_d.empty() && ((*dochere).OID == topparent)) {
+	   // don't link to this classifier as it is the current one
+	   navigationbar += ",selected";
+	 }
+	 navigationbar += ")";
+
+	// set the _httpbrowseCLX_ macro for this classification
+	disp.setmacro ("httpbrowse" + (*dochere).OID, displayclass::defaultpackage, "_httpdocument_&amp;cl=" + (*dochere).OID);
+	 ++dochere;
+	 first = false;
+      }
+      
+      navigationbar += "_dynamicclassifiernavbarentries_";
+      navigationbar += "\n<!-- End of Navigation Bar -->\n";
+
+   } else {
+
+      navigationbar = "<form method=\"get\" name=\"navform\">\n";
+      navigationbar += "<select name=\"navbar\" onChange=\"location.href=";
+      navigationbar += "document.navform.navbar.options[document.navform.navbar.selectedIndex].value\">\n";
+
+      if (args["a"] != "q" && args["cl"].empty()) {
+	 navigationbar += "<option value=\"\" selected>_textselectpage_</option>\n";
+      }
+      
+      if (has_search_button) {
+	 navigationbar += "<option value=\"_httpquery_\"";
+	 if (args["a"] == "q") {
+	    navigationbar += " selected";
+	 }
+	 navigationbar += ">_labelSearch_</option>\n";
+      }
+
+      while (dochere != docend) {
+	 text_t title = dochere->metadata["Title"].values[0];	 
+
+	 navigationbar += "<option value=\"_httpdocument_&amp;cl=" + dochere->OID + "\"";
+	 if (topparent == dochere->OID) {
+	    navigationbar += " selected";
+	 }
+	 navigationbar += ">_navlinktitle_(" + title + ")</option>\n";
+	 ++dochere;
+      }
+
+      navigationbar += "</select>\n";
+      navigationbar += "</form>\n";
+   }
+
+   disp.setmacro ("navigationbar", displayclass::defaultpackage, navigationbar);
+}
+
+// define all the macros which might be used by other actions
+// to produce pages. 
+void documentaction::define_external_macros (displayclass &disp, cgiargsclass &args, 
+					     recptprotolistclass *protos, ostream &logout) {
+  
+  // define_external_macros sets the following macros:
+
+  // _navigationbar_     this is the navigation bar containing the search button
+  //                     and any classification buttons - it goes at the top of 
+  //                     most pages. for now we're assuming that there'll always 
+  //                     be a search button - we should probably check that there
+  //                     is a query action before making this assumption
+
+  // _httpbrowseXXX_     the http macros for each classification (i.e. if there
+  //                     are Title and Creator classifications _httpbrowseTitle_
+  //                     and _httpbrowseCreator_ will be set
+
+  // _widthtspace_       the width of the spacers between buttons in navigation
+  //                     bar
+  
+  // _httpdocument_      has '&f=1' added if displaying document inside a frame
+
+  // _gsdltop_           macro to replace _top targets with
+
+  // _httppagehome_      overridden home url if html collections have own homepage
+
+  // _usability_         macros for remote usability reporting: if
+  // _usabinterface_     "format Usability [multi|textonly|stepwise]" is in 
+  // _usabilityscript_   collect.cfg
+
+  // _versionnnum_   greenstone version number (hard-coded)
+  // must have a valid collection server to continue
+   
+  text_t &collection = args["c"];
+  if (collection.empty()) return;
+  recptproto *collectproto = protos->getrecptproto (collection, logout);
+  if (collectproto == NULL) return;
+  
+  if (recpt == NULL) {
+    logout << "ERROR (documentaction::define_external_macros): This action does not contain\n"
+	   << "      information about any receptionists. The method set_receptionist was\n"
+	   << "      probably not called from the module which instantiated this action.\n";
+    return;
+  }
+
+  outconvertclass text_t2ascii;
+  comerror_t err;
+  InfoFiltersResponse_t filterinfo;
+  FilterResponse_t response;
+  text_tset metadata;
+
+  // get info on current collection and load up formatinfo
+  // I'd prefer not to do this here as we're getting 
+  // collection info every time (and probably also getting
+  // it in other places some of the time) - One day I'll
+  // fix it ... maybe - Stefan.
+  ColInfoResponse_t cinfo;
+
+  collectproto->get_collectinfo (collection, cinfo, err, logout);
+  load_formatinfo (cinfo.format, args.getintarg("gt"));
+  //  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
+  //  if (cinfo == NULL) {
+  //    logout << "ERROR (documentaction::define_external_macros): get_collectinfo_ptr returned NULL\n";
+  //    return;
+  //  }
+  //load_formatinfo (cinfo->format, args.getintarg("gt"));
+
+  if (formatinfo.DocumentUseHTML) {
+
+    // frame stuff
+    if (args["fc"] == "1") {
+      text_t httpdocument;
+      disp.expandstring (displayclass::defaultpackage, "_httpdocument_", httpdocument);
+      httpdocument += "&amp;f=1";
+      disp.setmacro ("httpdocument", displayclass::defaultpackage, httpdocument);
+      disp.setmacro ("gsdltop", displayclass::defaultpackage, "documenttop");
+      formatinfo.DocumentText = "[Text]";
+    }
+    text_tmap::iterator it = cinfo.format.find ("homepage");
+    if (it != cinfo.format.end()) {
+      text_t httppagehome;
+      if (get_link (args, protos, (*it).second, httppagehome, logout))
+	disp.setmacro ("httppagehome", displayclass::defaultpackage, httppagehome);
+    } 
+  }
+
+  // don't want navigation bar if page is 'detached'
+  if (!args.getintarg("x")) {
+
+    collectproto->get_filterinfo (collection, filterinfo, err, logout);
+    if (err == noError) {
+      // check that there's a browse filter
+      if (filterinfo.filterNames.find ("BrowseFilter") != filterinfo.filterNames.end()) {
+	
+	metadata.insert ("Title");
+	bool getParents = false;
+	get_children ("", collection, args["l"], metadata, getParents, collectproto, response, logout);
+	
+	bool has_search_button = true;
+	collectproto->is_searchable(collection, has_search_button, err, logout);
+	if (err != noError) has_search_button = false;
+
+	// calculate width of spacers and set _widthtspace_ macro
+	if (args.getintarg("v") == 0) set_spacemacro (disp, response, has_search_button);
+
+	// set _navigationbar_ macro
+	set_navbarmacros (disp, response, has_search_button, args, cinfo);
+   
+      }
+    } else {
+      logout << text_t2ascii 
+	     << "Error (documentaction::define_external_macros()) in call to get_filterinfo() " 
+	     << get_comerror_string (err);
+    }
+  }
+
+  // send feedback button and pages
+  text_tmap::iterator usability = cinfo.format.find("Usability");
+  if(usability!=cinfo.format.end()){
+    disp.setmacro("usability",displayclass::defaultpackage,"_usablink_");
+    disp.setmacro("usabinterface",displayclass::defaultpackage,("_usab"+(*usability).second+"_"));
+    disp.setmacro("usabilityscript", displayclass::defaultpackage, "_usabshowscript_");
+  }
+
+  // version num
+  disp.setmacro("versionnum", displayclass::defaultpackage, GSDL_VERSION);
+
+}
+
+bool documentaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
+			       const text_t &inlink, text_t &outlink, ostream &logout) {
+
+  FilterResponse_t response;
+  text_tset metadata;
+  metadata.insert ("section");
+  
+  // check current collection first
+  recptproto *collectproto = protos->getrecptproto (args["c"], logout);
+
+  if (get_info (inlink, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
+    if (!response.docInfo[0].metadata["section"].values[0].empty()) {
+#ifndef DOCHANDLE
+      outlink = "_httpdocument_&amp;d=" + response.docInfo[0].metadata["section"].values[0];
+#else
+      outlink = "_httpdocumenthandle_("+args["c"]+","+response.docInfo[0].metadata["section"].values[0]+")";
+#endif
+
+      return true;
+    }
+  }
+
+  // check all the other enabled collections
+
+  if (args["ccs"] == "1" && !args["cc"].empty()) {
+    text_tarray collections;
+    splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
+    
+    text_tarray::const_iterator col_here = collections.begin();
+    text_tarray::const_iterator col_end = collections.end();
+
+    while (col_here != col_end) {
+	  
+      // don't need to check current collection again
+      if (*col_here == args["c"]) {++col_here; continue;}
+	  
+      collectproto = protos->getrecptproto (*col_here, logout);
+      
+      if (get_info (inlink, *col_here, args["l"], metadata, false, collectproto, response, logout)) {
+	if (!response.docInfo[0].metadata["section"].values[0].empty()) {
+#ifndef DOCHANDLE
+	  outlink = "_httpdocument_&amp;c=" + *col_here + "&amp;d=" +
+	    response.docInfo[0].metadata["section"].values[0];
+#else
+	  outlink = "_httpdocumenthandle_("+*col_here+","+response.docInfo[0].metadata["section"].values[0]+")";
+#endif
+
+	  return true;
+	}
+      }
+      ++col_here;
+    }
+  }
+  return false;
+}
+
+void documentaction::load_formatinfo (const text_tmap &colformat, int gt) {
+
+  formatinfo.clear();
+  text_tmap::const_iterator format_here = colformat.begin();
+  text_tmap::const_iterator format_end = colformat.end();
+
+  while (format_here != format_end) {
+    if (((*format_here).first == "DocumentImages") && 
+	((*format_here).second == "true"))
+      formatinfo.DocumentImages = true;
+    else if (((*format_here).first == "DocumentTitles") && 
+	     ((*format_here).second == "false"))
+      formatinfo.DocumentTitles = false;
+    else if ((*format_here).first == "DocumentHeading") 
+      formatinfo.DocumentHeading = (*format_here).second;
+    else if (((*format_here).first == "DocumentContents") && 
+	     ((*format_here).second == "false"))
+      formatinfo.DocumentContents = false;
+    else if (((*format_here).first == "DocumentArrowsBottom") && 
+	     ((*format_here).second == "false"))
+      formatinfo.DocumentArrowsBottom = false;
+    else if (((*format_here).first == "DocumentArrowsTop") && 
+	     ((*format_here).second == "true"))
+      formatinfo.DocumentArrowsTop = true;
+    else if ((*format_here).first == "DocumentButtons")
+      splitchar ((*format_here).second.begin(), (*format_here).second.end(),
+		 '|', formatinfo.DocumentButtons);
+    else if ((*format_here).first == "DocumentText") 
+      formatinfo.DocumentText = (*format_here).second;  
+    else if ((*format_here).first == "RelatedDocuments")
+      formatinfo.RelatedDocuments = (*format_here).second; 
+    else if (((*format_here).first == "DocumentUseHTML") && 
+	     ((*format_here).second == "true"))
+      formatinfo.DocumentUseHTML = true;
+    else if (((*format_here).first == "AllowExtendedOptions") && 
+	     ((*format_here).second == "true"))
+      formatinfo.AllowExtendedOptions = true;
+    else 
+      formatinfo.formatstrings[(*format_here).first] = (*format_here).second;
+    
+    ++format_here;
+  }
+
+  // never want arrows when text is expanded
+  if (gt) {
+    formatinfo.DocumentArrowsBottom = false;
+    formatinfo.DocumentArrowsTop = false;
+  }
+}
+
+
+// define all the macros which are related to pages generated
+// by this action. we also load up the formatinfo structure 
+// here (it's used in do_action as well as here)
+void documentaction::define_internal_macros (displayclass &disp, cgiargsclass &args, 
+					     recptprotolistclass *protos, ostream &logout) {
+  
+  // define_internal_macros sets the following macros:
+  
+  // _pagetitle_            the title to be displayed at the top of the browser window
+  
+  // _imagethispage_        the title image to be displayed at top right of page
+
+  // _navarrowsbottom_      this may be overridden to "" when format option 
+  //                        DocumentArrowsBottom is false
+
+  // _navarrowstop_         likewise for DocumentArrowsTop
+
+  // _httpprevarrow_        links to next and previous sections of document - used
+  // _httpnextarrow_        by DocumentArrowsBottom
+
+  // _header_               the header macro is overridden if we're not at a top level 
+  //                        classification to remove the title block
+
+  // _thisOID_              the OID (directory) of the current document - this corresponds
+  //                        to the archivedir metadata element
+
+  // _documentheader_       Custom header info for the specified document
+  // must have a valid collection server to continue
+
+   text_t &collection = args["c"];
+  if (collection.empty()) return;
+  recptproto *collectproto = protos->getrecptproto (collection, logout);
+  if (collectproto == NULL) return;
+
+  text_tset metadata;
+  FilterResponse_t response;
+  text_t &arg_d = args["d"];
+  text_t &arg_cl = args["cl"];
+
+  if (!formatinfo.DocumentArrowsBottom) {
+    disp.setmacro("navarrowsbottom", "document", "");
+  } else if (!formatinfo.DocumentArrowsBottom) {
+    disp.setmacro("navarrowstop", "document", "");
+  } 
+
+  if (!arg_d.empty() && (formatinfo.DocumentArrowsBottom || formatinfo.DocumentArrowsTop)) {
+    // set _httpprevarrow_ and _httpnextarrow_
+    set_arrow_macros (args, collectproto, disp, logout);
+  }
+
+  metadata.insert ("Title");
+  metadata.insert ("gs.DocumentHeader");
+  metadata.insert ("DocumentHeader");
+  
+  bool fulltoc = false;
+
+  if (args["cl"] != "search") {
+    // see if there's a FullTOC string
+    text_t cl_top, full_toc;
+    get_top (arg_cl, cl_top);
+    if (get_formatstring (cl_top, "FullTOC", formatinfo.formatstrings, full_toc))
+      if (full_toc == "true") fulltoc = true;
+  }
+  
+  if (!arg_d.empty() && !fulltoc) {
+    // we're at document level
+
+    metadata.insert ("archivedir");
+
+    comerror_t err;
+    OptionValue_tarray options;
+    // we need to do the query again for the z3950proto
+    if (collectproto->get_protocol_name(err)=="z3950proto") {
+      OptionValue_t opt;
+      opt.name="Term";opt.value=args["q"];options.push_back(opt);
+      opt.name="QueryType";
+      opt.value=(args.getintarg("t")) ? "ranked" : "boolean";
+      options.push_back(opt);
+      opt.name="Index";opt.value=args["h"];options.push_back(opt);
+    }
+    
+    //do not display relation metadata
+    disp.setmacro ("relateddoc", "document", "");  
+       
+    //if preferences indicate relevant docs should be collected
+    //and there is no particular format specified then display
+    //this default format.
+     if(args["rd"] == "1" && formatinfo.RelatedDocuments.empty()){
+
+       text_t relation = g_EmptyText; //string for displaying relation metadata
+
+       //call function in formattools.cpp which will return the text of the 
+       //related documents in a vertical list. This is the default format.
+
+       if (get_info (arg_d, collection, args["l"], metadata, options, false, collectproto, response, logout)) 
+	 relation += get_related_docs(collection, collectproto, response.docInfo[0], logout);
+       
+       //set macro to be the related document string
+
+       disp.setmacro ("relateddoc", "document", relation); 
+     }
+     
+  
+    // get metadata for this document and it's parents
+    if (get_info (arg_d, collection, args["l"], metadata, options, 
+		  true, collectproto, response, logout)) {
+
+      disp.setmacro ("header", "document", "_textheader_");
+      text_tarray pagetitlearray;
+      if (!response.docInfo[0].metadata["Title"].values[0].empty())
+	pagetitlearray.push_back (response.docInfo[0].metadata["Title"].values[0]);
+      
+      if (args["gt"] != "1") {
+	MetadataInfo_t *parenttitle = response.docInfo[0].metadata["Title"].parent;
+	while (parenttitle != NULL) {
+	  if (!parenttitle->values[0].empty())
+	    pagetitlearray.push_back (parenttitle->values[0]);
+	  parenttitle = parenttitle->parent;
+	}
+      }
+      reverse (pagetitlearray.begin(), pagetitlearray.end());
+      text_t pagetitle;
+      joinchar (pagetitlearray, ": ", pagetitle);
+      // remove html tags from the title
+      text_t::iterator open_tag=pagetitle.begin();
+      while (open_tag < pagetitle.end()) {
+	if (*open_tag == '<') {
+	  text_t::iterator close_tag=open_tag+1;
+	  text_t::iterator donechar=pagetitle.end();
+	  while (close_tag < donechar) {
+	    if (*close_tag == '>')
+	      break;
+	    ++close_tag;
+	  }
+	  if (close_tag < donechar) // remove this html tag, replace with space
+	    *close_tag=' ';
+	  pagetitle.erase(open_tag, close_tag);
+	}
+	++open_tag;
+      }
+      disp.setmacro ("pagetitle", "document", pagetitle);
+
+      // custom header info
+      text_t custom_header;
+      if (is_top (arg_d)) {
+	custom_header = response.docInfo[0].metadata["gs.DocumentHeader"].values[0];
+	if (custom_header.empty()) {
+	  // try ex header
+	  custom_header = response.docInfo[0].metadata["DocumentHeader"].values[0]; 
+	}
+      } else {
+	MetadataInfo_t *parentch = response.docInfo[0].metadata["gs.DocumentHeader"].parent;
+	while (parentch != NULL) {
+	  custom_header = parentch->values[0];
+	  parentch = parentch->parent;
+	}
+	if (custom_header.empty()) {
+	  // try ex header
+	  MetadataInfo_t *parentch = response.docInfo[0].metadata["DocumentHeader"].parent;
+	  while (parentch != NULL) {
+	    custom_header = parentch->values[0];
+	    parentch = parentch->parent;
+	  }
+	}
+      }
+      if (!custom_header.empty()) {
+	disp.setmacro("documentheader", "document", custom_header);
+      }
+	
+      if (is_top (arg_d))
+	disp.setmacro ("thisOID", displayclass::defaultpackage, dm_safe(response.docInfo[0].metadata["archivedir"].values[0]));
+      else {
+	MetadataInfo_t *parentad = response.docInfo[0].metadata["archivedir"].parent;
+	text_t thisOID;
+	while (parentad != NULL) {
+	  thisOID = parentad->values[0];
+	  parentad = parentad->parent;
+	}
+	disp.setmacro ("thisOID", displayclass::defaultpackage, dm_safe(thisOID));
+      }
+    }
+  } else {
+    if (!arg_cl.empty()) {
+	
+      // create the currentnodevalue macro - this is the value of the node
+      // in the hierarchy that is currently open.
+      if (get_info (arg_cl, collection, args["l"], metadata, false, collectproto, response, logout)) {
+	text_t &title = response.docInfo[0].metadata["Title"].values[0];
+	disp.setmacro ("currentnodevalue", "document", title);
+      }
+      // get metadata for top level classification
+      text_t classtop;
+      get_top (arg_cl, classtop);
+      metadata.insert ("childtype");
+      metadata.insert ("parameters");
+
+      if (get_info (classtop, collection, args["l"], metadata, false, collectproto, response, logout)) {
+	  
+	text_t &title = response.docInfo[0].metadata["Title"].values[0];
+	bool unknown = false;
+
+	// test if we have macros defined for this classification's
+	// metadata name - if not we'll just display the name
+	text_t tmp;
+	text_t macroname="_label" + title + "_";
+	disp.expandstring ("Global", macroname, tmp);
+	if (tmp == macroname) unknown = true; // it wasn't expanded
+
+	if (unknown) {
+	  disp.setmacro ("pagetitle", "document", title);
+	} else {
+	  disp.setmacro ("pagetitle", "document", macroname);
+	}
+	/* for ns4/image layout compatibility. when this is no longer
+	 * needed, set imagethispage to _label+title+_ */
+	text_t titlemacroname="_titleimage" + title + "_";
+	disp.expandstring ("Global", titlemacroname, tmp);
+	if (tmp == titlemacroname) { /* _titleimage$META_ isn't defined */
+	  if (!unknown) /* _label$META_ is defined */
+	    disp.setmacro ("imagethispage", "document", macroname);
+	  else
+	    disp.setmacro ("imagethispage", "document", title);
+	} else { /* _titleimage$META_ is defined */
+	  disp.setmacro ("imagethispage", "document", titlemacroname);
+	}
+
+      	//if the document is not a document from a collection
+	//we must set the macro to be an empty string
+	disp.setmacro ("relateddoc", "document", ""); 
+
+	// Add macros specific to the Collage/Phind classifiers 
+	text_t &childtype = response.docInfo[0].metadata["childtype"].values[0];
+	if (childtype == "Collage") {
+
+	  text_t::iterator a = arg_cl.begin();
+	  text_t::iterator b = arg_cl.end();
+
+	  bool collage = true;
+	  while (a != b) {
+	    if (*a == 46) collage = false;
+	    ++a;
+	  }
+
+	  if (collage) {
+	    disp.setmacro ("collageclassifier", "document", "_collageapplet_");
+
+            // Next, macros that control the way the classifier is displayed
+            text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
+
+            // extract key=value pairs and set as macros
+            text_t::iterator here = parameters.begin();
+            text_t::iterator end = parameters.end();
+            text_t key, value;
+
+            while (here != end) {
+              // get the next key and value pair
+              here = getdelimitstr (here, end, '=', key);
+              here = getdelimitstr (here, end, ';', value);
+
+              // store this key=value pair
+              if (!key.empty() && !value.empty()) {
+                disp.setmacro ("collage"+key, "document", value);
+              }
+            }
+
+	    
+	  }
+	}
+
+	if (childtype == "Phind") {
+
+	  // First, a macro to display the phind classifier
+	  disp.setmacro ("phindclassifier", "document", "_phindapplet_");
+
+	  // Next, macros that control the way the classifier is displayed
+	  text_t parameters = response.docInfo[0].metadata["parameters"].values[0];
+
+	  // extract key=value pairs and set as macros
+	  text_t::iterator here = parameters.begin();
+	  text_t::iterator end = parameters.end();
+	  text_t key, value;
+	  
+	  while (here != end) {
+	    // get the next key and value pair
+	    here = getdelimitstr (here, end, '=', key);
+	    here = getdelimitstr (here, end, ';', value);
+
+	    // store this key=value pair
+	    if (!key.empty() && !value.empty()) {
+	      disp.setmacro (key, "document", value);
+	    }
+	  }
+	} // end if (childtype == "Phind")
+      }
+    } // end if (!arg_cl.empty()) {
+  }
+}
+
+
+bool documentaction::do_action(cgiargsclass &args, recptprotolistclass *protos, 
+                               browsermapclass *browsers, displayclass &disp, 
+                               outconvertclass &outconvert, ostream &textout, 
+                               ostream &logout)
+{
+  if ((args["book"] == "flashxml") && (!args["d"].empty()))
+  {
+  	return do_action_flashxml(args,protos,browsers,disp,outconvert,textout,logout);
+  }
+  else if ((args["book"] == "on") && (!args["d"].empty())) 
+  {
+  	return do_action_book(args,protos,browsers,disp,outconvert,textout,logout);
+  }
+  else 
+  {
+   	return do_action_html(args,protos,browsers,disp,outconvert,textout,logout);
+  }
+
+}
+
+//displaying the normal display when bookswitch=0(html)
+bool documentaction::do_action_html(cgiargsclass &args, recptprotolistclass *protos, 
+                               browsermapclass *browsers, displayclass &disp, 
+                               outconvertclass &outconvert, ostream &textout, 
+                               ostream &logout)
+{
+  // must have a valid collection server
+  recptproto *collectproto = protos->getrecptproto (args["c"], logout);
+  if (collectproto == NULL) {
+    logout << "documentaction::do_action called with NULL collectproto\n";
+    textout << outconvert << disp << "_document:header_\n" 
+	    << "Error: Attempt to get document without setting collection\n"
+	    << "_document:footer_\n";
+  } else {  
+    
+    text_t OID = args["d"];
+    if (OID.empty()) OID = args["cl"];
+    if (OID.empty()) {
+      textout << outconvert << disp << "Document contains no data_document:footer_\n";
+      return true;
+    }
+
+  
+    if (formatinfo.DocumentUseHTML && !args["d"].empty()) {
+      
+      if (args["f"] == "1") {
+	textout << outconvert << disp 
+		<< "<html><head></head>\n"
+		<< "<frameset rows=\"68,*\" noresize border=0>\n"
+		<< "<frame scrolling=no frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=p&p=nav\">\n"
+#ifndef DOCHANDLE
+		<< "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d=" 
+		<< args["d"] << "\">"
+#else
+		<< "<frame name=\"documenttop\" frameborder=0 src=\"_httpdocumenthandle_(" 
+		<< args["c"] << "," << args["d"] << ")\">"
+#endif
+		<< "<noframes>\n"
+		<< "<p>You must have a frame enabled browser to view this.</p>\n"
+		<< "</noframes>\n"
+		<< "</frameset>\n"
+		<< "</html>\n";
+      } else {
+	output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);	
+      }
+      return true;
+    }
+
+   
+    textout << outconvert << disp << "_document:header_\n"
+	    << "_document:content_\n";
+      
+    // output the table of contents
+    browsetoolsclass b;
+    b.output_toc(args, browsers, formatinfo, collectproto, 
+                 disp, outconvert, textout, logout);
+   
+    if (formatinfo.DocumentArrowsTop && !args["d"].empty()) {
+      textout << outconvert << disp << "_document:navarrowstop_\n";
+    }
+
+    //output the related documents (may be the empty string)
+    //will not output the docs if a format string is specified
+    textout << outconvert << disp << "_document:relateddoc_\n";
+
+    // output the document text
+    if (!args["d"].empty()) {
+      output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
+    }
+
+    textout << outconvert << disp << "_document:footer_\n";
+  }
+  return true;
+}
+
+//displaying the book display when bookswitch=on
+bool documentaction::do_action_book(cgiargsclass &args, recptprotolistclass *protos, 
+                               browsermapclass *browsers, displayclass &disp, 
+                               outconvertclass &outconvert, ostream &textout, 
+                               ostream &logout)
+{
+  // must have a valid collection server
+  recptproto *collectproto = protos->getrecptproto (args["c"], logout);
+  if (collectproto == NULL) 
+  {
+    	logout << "documentaction::do_action called with NULL collectproto\n";
+    	textout << outconvert << disp << "_document:header_\n" 
+		<< "Error: Attempt to get document without setting collection\n";
+  } 
+  else 
+  {  
+    	text_t OID = args["d"];
+    	if (OID.empty()) OID = args["cl"];
+    	if (OID.empty()) 
+	{
+      		textout << outconvert << disp << "Document contains no data\n";
+      		return true;
+    	}
+
+    	if (formatinfo.DocumentUseHTML && !args["d"].empty()) 
+	{
+      		if (args["f"] == "1") 
+		{
+			textout << outconvert << disp 
+				<< "<html><head></head>\n"
+				<< "<frameset rows=\"68,*\" noresize border=0>\n"
+				<< "<frame scrolling=no frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=p&p=nav\">\n"
+			#ifndef DOCHANDLE
+				<< "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d=" 
+				<< args["d"] << "\">"
+			#else
+				<< "<frame name=\"documenttop\" frameborder=0 src=\"_httpdocumenthandle_(" 
+				<< args["c"] << "," << args["d"] << ")\">"
+			#endif
+				<< "<noframes>\n"
+				<< "<p>You must have a frame enabled browser to view this.</p>\n"
+				<< "</noframes>\n"
+				<< "</frameset>\n"
+				<< "</html>\n";
+      		} 
+		else 
+		{
+			output_document (OID, args, collectproto, browsers, disp, outconvert, textout, logout);	
+      		}
+      		
+		return true;
+    	}
+
+
+	//the header bit and the navigation button   
+    	textout << outconvert << disp << "_document:header_\n" << "_document:content_\n";
+       
+	//display the book
+	textout << outconvert << disp << "_document:flashbook_\n";
+	
+	//the footer bit without the document arrow
+	textout << outconvert << disp << "</div> <!-- id=document -->\n";
+	textout << outconvert << disp << "_endspacer__htmlfooter_\n";
+  }
+  
+  return true;
+}
+
+//Displaying the xml when bookswitch=flashxml
+bool documentaction::do_action_flashxml(cgiargsclass &args, recptprotolistclass *protos, 
+                               browsermapclass *browsers, displayclass &disp, 
+                               outconvertclass &outconvert, ostream &textout, 
+                               ostream &logout)
+{
+  // must have a valid collection server
+  recptproto *collectproto = protos->getrecptproto (args["c"], logout);
+  if (collectproto == NULL) 
+  {
+    logout << "documentaction::do_action called with NULL collectproto\n";
+    textout << outconvert << disp 
+	    << "<Message>\n"
+	    << "  Error: Attempt to get document without setting collection\n"
+	    << "</Message>\n";
+  } 
+  else 
+  {  
+    text_t OID = args["d"];
+    if (OID.empty()) OID = args["cl"];
+    if (OID.empty()) 
+    {
+      textout << outconvert << disp 
+	      << "<Message>\n"
+	      << "  Document contains no data\n"
+	      << "</Message>\n";
+      return true;
+    }
+
+    if (formatinfo.DocumentUseHTML && !args["d"].empty())
+    {  
+      if (args["f"] == "1") 
+      {
+	textout << outconvert << disp 
+		<< "<Message>\n"
+		<< "  Using frames makes no sense for XML output\n"
+		<< "</Message>\n";
+      } 
+      else 
+      {
+	output_document_flashxml (OID, args, collectproto, browsers, disp, outconvert, textout, logout);	
+      }
+
+      return true;
+    }
+
+    // output the document text
+    if (!args["d"].empty()) 
+    {
+      output_document_flashxml (OID, args, collectproto, browsers, disp, outconvert, textout, logout);
+    }
+  }
+
+  return true;
+}
+
+
+
+void documentaction::output_text (ResultDocInfo_t &docinfo, format_t *formatlistptr,
+				  const TermInfo_tarray &terminfo, const text_t &OID,
+				  bool highlight, int hastxt, int wanttext, 
+				  text_t &collection, recptproto *collectproto,
+				  browsermapclass *browsers, displayclass &disp,
+				  outconvertclass &outconvert, ostream &textout,
+				  ostream &logout, cgiargsclass &args) {
+  
+  DocumentRequest_t docrequest;
+  DocumentResponse_t docresponse;
+  comerror_t err;
+  if (hastxt == 1) {
+
+    if (wanttext) {
+      // get the text
+      docrequest.OID = OID;
+      collectproto->get_document (collection, docrequest, docresponse, err, logout);
+
+      // cut down on overhead by not using formattools if we only want the text
+      // (wanttext will equal 2 if we want text and other stuff too)
+      if (wanttext == 1)
+	if (highlight) {
+	  highlighttext(docresponse.doc, args, terminfo, disp, outconvert, textout);
+	} else {
+	  textout << outconvert << disp << docresponse.doc;
+	}
+    }
+  
+    if (wanttext != 1) {
+      text_tmap options;
+      options["text"] = docresponse.doc;
+
+      if (formatinfo.AllowExtendedOptions) {
+        browsetoolsclass b;
+	b.load_extended_options(options, args, browsers, formatinfo, 
+                                collectproto, disp, outconvert, logout);
+      }
+      
+      text_t doctext 
+	 = get_formatted_string (collection, collectproto, docinfo, disp,
+				 formatlistptr, options, logout); 
+      
+      if (highlight) {
+	highlighttext(doctext, args, terminfo, disp, outconvert, textout);
+      } else {
+	textout << outconvert << disp << doctext;
+      }
+    }
+  }
+}
+
+
+void documentaction::output_document (const text_t &OID, cgiargsclass &args, 
+				      recptproto *collectproto, browsermapclass *browsers,
+				      displayclass &disp, outconvertclass &outconvert,
+				      ostream &textout, ostream &logout) {
+  FilterResponse_t inforesponse;
+  FilterResponse_t queryresponse;
+  text_tset metadata;
+  bool getParents = false;
+  bool highlight = false;
+  int wanttext = 0;
+  int arg_gt = args.getintarg("gt");
+  text_t &collection = args["c"];
+    
+  // if we have a query string and highlighting is turned on we need
+  // to redo the query to get the terms for highlighting
+  
+  if (!args["q"].empty() && args.getintarg("hl")) {
+
+    ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
+    bool segment = false;
+    if (cinfo != NULL) {
+      segment = cinfo->isSegmented;
+    }
+    FilterRequest_t request;
+    comerror_t err;
+    request.filterResultOptions = FRmatchTerms;
+    text_t formattedstring = args["q"];
+    format_querystring (formattedstring, args.getintarg("b"), segment);
+    set_queryfilter_options (request, formattedstring, args);
+    args["q"] = formattedstring; // need to set this here for phrase 
+                   // highlighting, where we look at the querystring
+    collectproto->filter (args["c"], request, queryresponse, err, logout);
+    if (err != noError) {
+      outconvertclass text_t2ascii;
+      logout << text_t2ascii
+	     << "documentaction::output_document: call to QueryFilter failed "
+	     << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
+      highlight = false;
+    } else {
+      highlight = true;
+    }
+  }
+
+  format_t *formatlistptr = new format_t();
+  parse_formatstring (formatinfo.DocumentText, formatlistptr, metadata, getParents);
+
+  metadata.insert ("hastxt");
+  metadata.insert ("haschildren");
+
+  if (formatinfo.DocumentText == "[Text]")
+    wanttext = 1;
+  else {
+    char *docformat = formatinfo.DocumentText.getcstr();
+    if (strstr (docformat, "[Text]") != NULL)
+      wanttext = 2;
+    delete []docformat;
+  }
+    
+  textout << outconvert << "<div class=\"documenttext\">\n";
+
+  if (get_info (OID, collection, args["l"], metadata, getParents, collectproto, inforesponse, logout)) {
+    int hastxt = inforesponse.docInfo[0].metadata["hastxt"].values[0].getint();
+    int haschildren = inforesponse.docInfo[0].metadata["haschildren"].values[0].getint();
+    
+    if (arg_gt == 0) {
+      output_text (inforesponse.docInfo[0], formatlistptr, queryresponse.termInfo, 
+		   OID, highlight, hastxt, wanttext, collection, collectproto, 
+		   browsers, disp, outconvert, textout, logout, args);
+
+    } else {
+
+      ResultDocInfo_t thisdocinfo = inforesponse.docInfo[0];
+	
+      // text is to be expanded
+      text_t exOID = OID;
+      if (haschildren != 1) exOID = get_parent (OID);
+      if (exOID.empty()) exOID = OID;
+	
+      // if we're not in a document (i.e. we're in a top level classification)
+      // we need to pass "is_classify = true" to get_contents so that it 
+      // doesn't recurse all the way through each document in the classification
+      bool is_classify = false;
+      if (args["d"].empty()) is_classify = true;
+
+      get_contents (exOID, is_classify, metadata, collection, args["l"], 
+		    collectproto, inforesponse, logout);
+	
+      ResultDocInfo_tarray::iterator sechere = inforesponse.docInfo.begin();
+      ResultDocInfo_tarray::iterator secend = inforesponse.docInfo.end();
+
+      if (arg_gt == 1) {
+	// check if there are more than 10 sections containing text to be expanded - 
+	// if there are output warning message - this isn't a great way to do this
+	// since the sections may be very large or very small - one day I'll fix it 
+	// -- Stefan.
+	int seccount = 0;
+	while (sechere != secend) {
+	  int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
+	  if (shastxt == 1) ++seccount;
+	  if (seccount > 10) break;
+	  ++sechere;
+	}
+	if (seccount > 10) {
+	  // more than 10 sections so output warning message and text 
+	  // for current section only
+	  textout << outconvert << disp << "<div class=\"warning\">_document:textltwarning_</div>\n";
+
+	  output_text (thisdocinfo, formatlistptr, queryresponse.termInfo, 
+		       OID, highlight, hastxt, wanttext, collection, 
+		       collectproto, browsers, disp, outconvert, textout, logout, args);
+	  
+	}
+	else arg_gt = 2;
+      }
+
+      if (arg_gt == 2) {
+	// get the text for each section
+	sechere = inforesponse.docInfo.begin();
+	int count = 0;
+	while (sechere != secend) {
+	  textout << outconvert << disp << "\n<p><a name=" << (*sechere).OID << "></a>\n";
+
+	  int shastxt = (*sechere).metadata["hastxt"].values[0].getint();
+
+	  output_text (*sechere, formatlistptr, queryresponse.termInfo, 
+		       (*sechere).OID, highlight, shastxt, wanttext, collection, 
+		       collectproto, browsers, disp, outconvert, textout, logout, args);
+	  ++count;
+	  ++sechere;
+	}
+      }
+    }
+  }
+  textout << outconvert << "</div>\n";
+  delete formatlistptr;
+}
+
+void documentaction::output_document_flashxml(const text_t &OID, cgiargsclass &args, 
+				      recptproto *collectproto, browsermapclass *browsermap,
+				      displayclass &disp, outconvertclass &outconvert,
+				      ostream &textout, ostream &logout) {
+	//if this is not at the document level --> do Nothing!!
+	if (args["d"].empty())
+		return;
+		
+	//if we have a query string and highlighting is turned on we need
+  	//to redo the query to get the terms for highlighting
+	FilterResponse_t queryresponse;
+  	bool highlight = false;
+	if (!args["q"].empty() && args.getintarg("hl")) 
+	{
+		text_t &collection = args["c"];
+    		ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
+    		bool segment = false;
+    		if (cinfo != NULL) 
+		{
+      			segment = cinfo->isSegmented;
+    		}
+    		FilterRequest_t request;
+    		comerror_t err;
+    		request.filterResultOptions = FRmatchTerms;
+    		text_t formattedstring = args["q"];
+    		format_querystring (formattedstring, args.getintarg("b"), segment);
+    		set_queryfilter_options (request, formattedstring, args);
+    		args["q"] = formattedstring; 	//need to set this here for phrase 
+                   				//highlighting, where we look at the querystring
+    		collectproto->filter (args["c"], request, queryresponse, err, logout);
+    		if (err != noError)
+		{
+      			outconvertclass text_t2ascii;
+      			logout << text_t2ascii
+	     			<< "documentaction::output_document: call to QueryFilter failed "
+	     			<< "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
+      			highlight = false;
+    		} 
+		else 
+		{
+     			highlight = true;
+    		}
+  	}
+	
+	FilterResponse_t response;
+	bool getParents = false;
+	text_tset metadata;
+	text_t classifytype, classification, formatstring;
+	
+	//metadata elements needed by recurse_contents
+  	metadata.insert ("Title");
+	metadata.insert ("haschildren");
+
+  	//protocol call
+  	if (!get_info (OID, args["c"], args["l"], metadata, getParents, collectproto, response, logout))
+    		return;
+
+  	recurse_contents (response.docInfo[0], args, metadata, 
+			    getParents, collectproto, disp, outconvert, textout, logout, highlight, queryresponse.termInfo);
+}
+
+void documentaction::recurse_contents(ResultDocInfo_t &section, cgiargsclass &args,
+                                        text_tset &metadata, bool &getParents, 
+                                        recptproto *collectproto, displayclass &disp, 
+                                        outconvertclass &outconvert, ostream &textout, ostream &logout, 
+					bool highlight, const TermInfo_tarray &terminfo)
+{
+ 	text_t formatstring;
+
+  	bool is_classify = false;
+  	
+  	//output this section 
+  	text_t classification = "Document";
+  	
+	textout << outconvert << disp << "<Section>\n";
+	
+	//get the title
+	textout << outconvert << disp << "<Description>\n<Metadata name=\"Title\">";
+	text_t t_title = section.metadata["Title"].values[0];
+	//if it is highlighted
+	/*if (highlight == true)
+	{
+		highlighttext(t_title, args, terminfo, disp, outconvert, textout);
+	}
+	else
+	{*/
+		textout << outconvert << disp << t_title;
+	//}
+	textout << outconvert << disp << "</Metadata>\n</Description>\n";
+	
+	//get the text
+	DocumentRequest_t docrequest;
+	DocumentResponse_t docresponse;
+	comerror_t err;
+	docrequest.OID = section.OID;
+	text_t &collection = args["c"];
+	collectproto->get_document(collection, docrequest, docresponse, err, logout);
+	//if it is highlighted
+	if (highlight == true)
+	{
+		highlighttext(docresponse.doc, args, terminfo, disp, outconvert, textout);
+	}
+	else
+	{
+		textout << outconvert << disp << docresponse.doc;
+	}
+	textout << outconvert << disp << "\n";
+	
+  	int haschildren = section.metadata["haschildren"].values[0].getint();
+  	
+  	// recurse through children
+  	if (haschildren == 1)
+	{
+    		FilterResponse_t tmp;
+    		get_children (section.OID, args["c"], args["l"], metadata, getParents, collectproto, tmp, logout);
+    		ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
+    		ResultDocInfo_tarray::iterator lastdoc = tmp.docInfo.end();
+
+    		while (thisdoc != lastdoc) 
+		{
+      			recurse_contents (*thisdoc, args, metadata, getParents, collectproto, disp, outconvert, textout, logout, highlight, terminfo);
+      			++thisdoc;
+    		}
+  	}
+	
+	textout << outconvert << disp << "</Section>\n";
+}
+
+void documentaction::set_arrow_macros (cgiargsclass &args, recptproto *collectproto,
+				       displayclass &disp, ostream &logout) {
+
+  text_tset metadata;
+  FilterResponse_t response;
+  FilterResponse_t presponse;
+
+  int haschildren = 0;
+  text_tarray next_siblings;
+  text_t previous_sibling;
+  text_t &arg_d = args["d"];
+
+  // get info on current section
+  metadata.insert("haschildren");
+  if (!get_info(arg_d, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
+    logout << "error 1 in documentaction::set_arrow_macros\n";
+    return;
+  }
+  haschildren = response.docInfo[0].metadata["haschildren"].values[0].getint();
+      
+  // get OIDs of next and previous siblings of current section and
+  // all it's parents
+  int parentcount = countchar(arg_d.begin(), arg_d.end(), '.');
+  text_t thisoid = arg_d;
+  while (parentcount > 0) {
+    get_children (get_parent(thisoid), args["c"], args["l"], metadata, false, 
+		  collectproto, response, logout);
+    ResultDocInfo_tarray::iterator this_sibling = response.docInfo.begin();
+    ResultDocInfo_tarray::iterator last_sibling = response.docInfo.end();
+    bool first = true;
+    while (this_sibling != last_sibling) {
+      if ((*this_sibling).OID == thisoid) {
+	if (!first && next_siblings.empty()) {
+	  previous_sibling = (*(this_sibling-1)).OID;
+	  int section_has_children = (*(this_sibling-1)).metadata["haschildren"].values[0].getint();
+	  // if previous sibling has children we need to recurse
+	  // down to the last descendant
+	  while (section_has_children) {
+	    get_children (previous_sibling, args["c"], args["l"], metadata, false, 
+			  collectproto, presponse, logout);
+	    if (!presponse.docInfo.empty()) {
+	      ResultDocInfo_tarray::iterator it = presponse.docInfo.end() - 1;
+	      previous_sibling = (*it).OID;
+	      section_has_children = (*it).metadata["haschildren"].values[0].getint();
+	    } else {
+	      section_has_children = 0; // this should never happen
+	    }
+	  }
+	}
+	    
+	if ((this_sibling+1) != last_sibling) {
+	  next_siblings.push_back((*(this_sibling+1)).OID);
+	} else {
+	  next_siblings.push_back("");
+	}
+	break;
+      }
+      ++this_sibling;
+      first = false;
+    }
+    thisoid = get_parent(thisoid);
+    --parentcount;
+  }
+
+  // work out values for next link
+  if (haschildren) {
+#ifndef DOCHANLE
+    disp.setmacro ("httpnextarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
+		   "&amp;d=" + arg_d + ".fc");
+#else
+    disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+args["c"]+","+arg_d + ".fc)";
+
+#endif
+
+  } else {
+    text_tarray::const_iterator h = next_siblings.begin();
+    text_tarray::const_iterator e = next_siblings.end();
+    while (h != e) {
+      if (!(*h).empty()) {
+#ifndef DOCHANLE
+	disp.setmacro ("httpnextarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
+		       "&amp;d=" + *h);
+#else
+	disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+args["c"]+","+*h+")";
+
+#endif
+
+	break;
+      }
+      ++h;
+    }
+  }
+
+  // work out value for previous link
+  if (!previous_sibling.empty()) {
+#ifndef DOCHANDLE
+    disp.setmacro ("httpprevarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
+		   "&amp;d=" + previous_sibling);
+#else
+    disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+args["c"]+","+ previous_sibling+")");
+
+#endif
+
+  } else {
+    if (countchar(arg_d.begin(), arg_d.end(), '.')) {
+#ifndef DOCHANDLE
+      disp.setmacro ("httpprevarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
+		     "&amp;d=" + get_parent(arg_d));
+#else
+      disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+args["c"]+","+get_parent(arg_d)+")");
+
+#endif
+
+    }
+  }
+}
Index: /gsdl/trunk/runtime-src/src/recpt/documentaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/documentaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/documentaction.h	(revision 16571)
@@ -0,0 +1,129 @@
+/**********************************************************************
+ *
+ * documentaction.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef DOCUMENTACTION_H
+#define DOCUMENTACTION_H
+
+#include "action.h"
+#include "gsdlconf.h"
+#include "formattools.h"
+#include "receptionist.h"
+#include "browserclass.h"
+
+class documentaction : public action {
+
+protected:
+
+  receptionist *recpt;
+
+  formatinfo_t formatinfo;
+  typedef map<text_t, format_t*, lttext_t> format_tmap; 
+  
+  bool get_link (cgiargsclass &args, recptprotolistclass *protos,
+		 const text_t &inlink, text_t &outlink, ostream &logout);
+
+  void load_formatinfo (const text_tmap &colformat, int gt);
+
+  void set_spacemacro (displayclass &disp, FilterResponse_t &response,
+		       bool has_search_button);
+
+  void set_navbarmacros (displayclass &disp, FilterResponse_t &response, 
+			 bool has_search_button, cgiargsclass &args,
+			 ColInfoResponse_t &cinfo);
+
+  virtual void output_text (ResultDocInfo_t &docinfo, format_t *formatlistptr,
+			    const TermInfo_tarray &terminfo, const text_t &OID,
+			    bool highlight, int hastxt, int wanttext, 
+			    text_t &collection, recptproto *collectproto,
+			    browsermapclass *browsers, displayclass &disp,
+			    outconvertclass &outconvert, ostream &textout,
+			    ostream &logout, cgiargsclass &args);
+
+  virtual void output_document (const text_t &OID, cgiargsclass &args, 
+				recptproto *collectproto, browsermapclass *browsers,
+				displayclass &disp,  outconvertclass &outconvert,
+				ostream &textout,  ostream &logout);
+
+
+  virtual void output_document_flashxml (const text_t &OID, cgiargsclass &args, 
+				    recptproto *collectproto, browsermapclass *browsers,
+				    displayclass &disp, outconvertclass &outconvert,
+				    ostream &textout, ostream &logout);
+
+  virtual void recurse_contents(ResultDocInfo_t &section, cgiargsclass &args,
+                                        text_tset &metadata, bool &getParents, 
+                                        recptproto *collectproto, displayclass &disp, 
+                                        outconvertclass &outconvert, ostream &textout, ostream &logout, 
+					bool highlight, const TermInfo_tarray &terminfo);
+				    
+  void set_arrow_macros (cgiargsclass &args, recptproto *collectproto,
+			 displayclass &disp, ostream &logout);
+
+public:
+  documentaction ();
+  virtual ~documentaction ();
+
+  void set_receptionist (receptionist *therecpt) {recpt=therecpt;}
+
+  text_t get_action_name () {return "d";}
+
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass *protos, ostream &logout);
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response,text_t &response_data, 
+			 ostream &logout);
+
+  void define_external_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+
+  virtual void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+				       recptprotolistclass *protos, ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+  bool do_action_html(cgiargsclass &args, recptprotolistclass *protos, 
+		      browsermapclass *browsers, displayclass &disp, 
+		      outconvertclass &outconvert, ostream &textout, 
+		      ostream &logout);
+
+  bool do_action_flashxml(cgiargsclass &args, recptprotolistclass *protos, 
+		     browsermapclass *browsers, displayclass &disp, 
+		     outconvertclass &outconvert, ostream &textout, 
+		     ostream &logout);
+
+  bool do_action_book(cgiargsclass &args, recptprotolistclass *protos, 
+                               browsermapclass *browsers, displayclass &disp, 
+                               outconvertclass &outconvert, ostream &textout, 
+                               ostream &logout);
+};
+
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/dynamicclassifieraction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/dynamicclassifieraction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/dynamicclassifieraction.cpp	(revision 16571)
@@ -0,0 +1,618 @@
+/**********************************************************************
+ *
+ * dynamicclassifieraction.cpp -- 
+ * Copyright (C) 2008  DL Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "dynamicclassifieraction.h"
+#include "recptprototools.h"
+
+
+dynamicclassifieraction::dynamicclassifieraction ()
+{
+  recpt = NULL;
+
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "dcl";
+  arg_ainfo.longname = "dynamic classifier ID";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "dcn";
+  arg_ainfo.longname = "dynamic classifier node";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+}
+
+
+dynamicclassifieraction::~dynamicclassifieraction()
+{
+}
+
+
+bool dynamicclassifieraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+					     recptprotolistclass *protos, ostream &logout)
+{
+  return true;
+}
+
+
+void dynamicclassifieraction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+						response_t &response,text_t &response_data, 
+						ostream &logout)
+{
+  response = content;
+  response_data = "text/html";
+}
+
+
+// define all the macros which might be used by other actions to produce pages. 
+void dynamicclassifieraction::define_external_macros (displayclass &disp, cgiargsclass &args, 
+						      recptprotolistclass *protos, ostream &logout)
+{
+  // A valid collection server is vital
+  recptproto *collectproto = protos->getrecptproto (args["c"], logout);
+  if (collectproto == NULL)
+  {
+    logout << "dynamicclassifieraction::define_external_macros called with NULL collectproto\n";
+    return;
+  }
+
+  // Define _dynamicclassifiernavbarentries_ to add buttons to the navigation bar for the dynamic classifiers
+  text_t navigation_bar_entries = "";
+  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
+  text_tmap::iterator dynamic_classifier_iterator = cinfo->dynamic_classifiers.begin();
+  while (dynamic_classifier_iterator != cinfo->dynamic_classifiers.end())
+  {
+    text_t dynamic_classifier_id = (*dynamic_classifier_iterator).first;
+    navigation_bar_entries += "_navbarspacer_";
+    navigation_bar_entries += "_navtab_(_gwcgi_?c=" + args["c"] + "&amp;a=dc&amp;dcl=" + dynamic_classifier_id + "," + dynamic_classifier_id;
+    if (args["a"] == "dc" && args["dcl"] == dynamic_classifier_id)
+    {
+      navigation_bar_entries += ",selected";
+    }
+    navigation_bar_entries += ")";
+    dynamic_classifier_iterator++;
+  }
+
+  disp.setmacro("dynamicclassifiernavbarentries", displayclass::defaultpackage, navigation_bar_entries);
+}
+
+
+// define all the macros which are related to pages generated
+// by this action. we also load up the formatinfo structure 
+// here (it's used in do_action as well as here)
+void dynamicclassifieraction::define_internal_macros (displayclass &disp, cgiargsclass &args, 
+						      recptprotolistclass *protos, ostream &logout)
+{
+  // define_internal_macros sets the following macros:
+}
+
+
+bool dynamicclassifieraction::do_action(cgiargsclass &args, recptprotolistclass *protos, 
+					browsermapclass *browsers, displayclass &disp, 
+					outconvertclass &outconvert, ostream &textout, 
+					ostream &logout)
+{
+  // A valid collection server is vital
+  recptproto *collectproto = protos->getrecptproto (args["c"], logout);
+  if (collectproto == NULL)
+  {
+    logout << "dynamicclassifieraction::do_action called with NULL collectproto\n";
+    return false;
+  }
+
+  textout << outconvert << disp << "_dynamicclassifier:header_\n";
+  textout << outconvert << disp << "_dynamicclassifier:content_\n";
+
+  // Check a dynamic classifier ID has been specified
+  text_t arg_dcl = args["dcl"];
+  if (arg_dcl.empty())
+  {
+    textout << outconvert << disp << "Error: Missing dcl argument.\n";
+    textout << outconvert << disp << "_dynamicclassifier:footer_\n";
+    return true;
+  }
+
+  // Check the dynamic classifier ID is valid (ie. there is an entry in the collect.cfg file for it)
+  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
+  if (cinfo->dynamic_classifiers.find(arg_dcl) == cinfo->dynamic_classifiers.end())
+  {
+    textout << outconvert << disp << "Error: Invalid dcl value \"" << arg_dcl << "\".\n";
+    textout << outconvert << disp << "_dynamicclassifier:footer_\n";
+    return true;
+  }
+
+  // Parse the classifier options from the specification
+  text_t classifier_specification = cinfo->dynamic_classifiers[arg_dcl];
+  text_tmap classifier_options = parse_classifier_options (classifier_specification, args);
+
+  // Output the "<ID>Header" format statement if there is one
+  text_t classifier_header_format_statement = "";
+  get_formatstring (arg_dcl + "Header", cinfo->format, classifier_header_format_statement);
+  textout << outconvert << disp << classifier_header_format_statement << "\n";
+
+  // Resolve any ".pr" bits at the end of the "dcn" argument
+  text_t classifier_node_separator = classifier_options["-split_using_hierarchy_separator"];
+  if (ends_with (args["dcn"], ".pr"))
+  {
+    // Change the "dcn" argument to be the OID of the parent of the specified classifier node
+    text_tlist args_dcn_parts;
+    splitword (args["dcn"].begin(), args["dcn"].end(), classifier_node_separator, args_dcn_parts);
+    args_dcn_parts.pop_back();  // Remove the last part
+    joinchar (args_dcn_parts, classifier_node_separator, args["dcn"]);
+  }
+
+  // Prepare to output the dynamic classifier
+  text_t current_classifier_node_OID = "";
+  text_t current_metadata_value_filter = "";
+  int classifier_node_indent = 0;
+
+  // (Optional) Output an hlist to group the classifier nodes into buckets based on the first character
+  if (classifier_options["-group_by_first_character"] == "1")
+  {
+    text_t selected_grouping_node_OID = output_hlist_classifier_nodes (current_classifier_node_OID, current_metadata_value_filter, "substr(value,1,1)", classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
+
+    current_classifier_node_OID = selected_grouping_node_OID + ".";
+    current_metadata_value_filter = selected_grouping_node_OID + "*";
+  }
+
+  // (Optional) Output an hlist instead of a vlist at the top level
+  if (classifier_options["-use_hlist_at_top"] == "1")
+  {
+    text_t selected_hlist_node_OID = output_hlist_classifier_nodes (current_classifier_node_OID, current_metadata_value_filter, "", classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
+
+    current_classifier_node_OID = selected_hlist_node_OID + classifier_node_separator;
+  }
+
+  // args["dcn"] may have been modified by output_hlist_classifier_nodes() above
+  text_t classifier_node_OID = args["dcn"];
+
+  // If grouping is enabled remove the grouping node bit from the start of the OID
+  text_t classifier_node_OID_sans_grouping = classifier_node_OID;
+  if (classifier_options["-group_by_first_character"] == "1")
+  {
+    text_t::iterator grouping_node_separator = findchar (classifier_node_OID.begin(), classifier_node_OID.end(), '.');
+    if (grouping_node_separator != classifier_node_OID.end())
+    {
+      classifier_node_OID_sans_grouping = substr (grouping_node_separator + 1, classifier_node_OID.end());
+    }
+    else
+    {
+      classifier_node_OID_sans_grouping = "";
+    }
+  }
+
+  // Split the classifier node OID into its hierarchical parts, then remove any we've already dealt with (HLists)
+  text_tlist classifier_node_OID_parts_remaining;
+  splitword (classifier_node_OID_sans_grouping.begin(), classifier_node_OID_sans_grouping.end(), classifier_node_separator, classifier_node_OID_parts_remaining);
+  if (classifier_options["-use_hlist_at_top"] == "1")
+  {
+    classifier_node_OID_parts_remaining.pop_front();
+  }
+
+  text_t classifier_node_metadata_value = classifier_node_OID_sans_grouping;
+  text_t classifier_node_metadata_value_filter = classifier_node_metadata_value + classifier_node_separator + "*";
+
+  // If "-split_greenstone_dates" is on the metadata value and filter doesn't quite match the OID -- fix this
+  if (classifier_options["-split_greenstone_dates"] == "1")
+  {
+    classifier_node_metadata_value.replace (classifier_node_separator, "");
+    classifier_node_metadata_value_filter = classifier_node_metadata_value;
+    if (classifier_node_metadata_value_filter.size() == 8)
+    {
+      classifier_node_metadata_value_filter += classifier_node_separator;
+    }
+    classifier_node_metadata_value_filter += "*";
+  }
+
+  // Simple case at the top level: just output the child classifier nodes
+  if (classifier_node_metadata_value == "")
+  {
+    output_child_classifier_nodes (current_classifier_node_OID, "", current_metadata_value_filter, classifier_node_indent, classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
+  }
+
+  // More complex case below the top level
+  else
+  {
+    // Output the parent classifier nodes and the current classifier node
+    output_upper_classifier_nodes (current_classifier_node_OID, classifier_node_OID_parts_remaining, classifier_node_indent, classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
+
+    // Output the child classifier nodes
+    current_classifier_node_OID = classifier_node_OID + classifier_node_separator;
+    output_child_classifier_nodes (current_classifier_node_OID, classifier_node_metadata_value, classifier_node_metadata_value_filter, classifier_node_indent, classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
+
+    // Get the document nodes at this level
+    text_t metadata_elements = classifier_options["metadata_elements"];
+    text_t sort_documents_by = classifier_options["-sort_documents_by"];
+    FilterResponse_t documents_response;
+    get_documents_with_metadata_value (metadata_elements, classifier_node_metadata_value, sort_documents_by, args["c"], collectproto, documents_response, logout);
+
+    // Display the document nodes
+    display_document_nodes (documents_response, classifier_node_indent, args, collectproto, browsers, disp, outconvert, textout, logout);
+  }
+
+  // Output the "<ID>Footer" format statement if there is one
+  text_t classifier_footer_format_statement = "";
+  get_formatstring (arg_dcl + "Footer", cinfo->format, classifier_footer_format_statement);
+  textout << outconvert << disp << classifier_footer_format_statement << "\n";
+
+  textout << outconvert << disp << "_dynamicclassifier:footer_\n";
+  return true;
+}
+
+
+text_tmap dynamicclassifieraction::parse_classifier_options (text_t classifier_specification, cgiargsclass &args)
+{
+  text_tmap classifier_options;
+
+  // Default values
+  classifier_options["-split_using_hierarchy_separator"] = "|";
+
+  // Split the classifier specification string by spaces
+  text_tlist classifier_specification_parts;
+  splitchar (classifier_specification.begin(), classifier_specification.end(), ' ', classifier_specification_parts);
+
+  // The metadata element(s) to classify by should be the first value
+  classifier_options["metadata_elements"] = classifier_specification_parts.front();
+  classifier_specification_parts.pop_front();
+
+  // Parse options from the remainder of the classifier specification
+  while (!classifier_specification_parts.empty())
+  {
+    // Parse the option name
+    text_t classifier_option_name = classifier_specification_parts.front();
+    classifier_specification_parts.pop_front();
+
+    // Check if the option has a value (it may just be a flag, in which case we use "1" as the value)
+    text_t classifier_option_value = "1";
+    if (!classifier_specification_parts.empty() && !starts_with(classifier_specification_parts.front(), "-"))
+    {
+      classifier_option_value = classifier_specification_parts.front();
+      classifier_specification_parts.pop_front();
+    }
+
+    // Record the option
+    classifier_options[classifier_option_name] = classifier_option_value;
+  }
+
+  return classifier_options;
+}
+
+
+text_t dynamicclassifieraction::output_hlist_classifier_nodes (text_t parent_classifier_node_OID,
+							       text_t metadata_value_filter,
+							       text_t metadata_value_grouping_expression,
+							       text_tmap classifier_options, cgiargsclass &args,
+							       recptproto *collectproto, browsermapclass *browsers,
+							       displayclass &disp, outconvertclass &outconvert,
+							       ostream &textout, ostream &logout)
+{
+  // Get all the metadata values for the specified element(s) that match the filter
+  text_t metadata_elements = classifier_options["metadata_elements"];
+  FilterResponse_t metadata_values_response;
+  bool request_success = get_metadata_values (metadata_elements, metadata_value_filter, metadata_value_grouping_expression, args["c"], collectproto, metadata_values_response, logout);
+
+  // If the request failed then it's probably because the collection isn't using an SQL infodbtype
+  if (request_success == false)
+  {
+    textout << outconvert << disp << "Error: Dynamic classifier functionality is not available. Please check you are using an SQL infodbtype and the collection has been rebuilt.\n";
+    return "";
+  }
+
+  // Check some metadata values were returned
+  if (metadata_values_response.docInfo.empty())
+  {
+    return "";
+  }
+
+  // After processing any hierarchical metadata values we're left with the hlist classifer nodes
+  map<text_t, int, lttext_t> hlist_classifier_nodes;
+  ResultDocInfo_tarray::iterator metadata_value_iterator = metadata_values_response.docInfo.begin();
+  while (metadata_value_iterator != metadata_values_response.docInfo.end())
+  {
+    text_t hierarchical_metadata_value = split_metadata_value ((*metadata_value_iterator).OID, classifier_options);
+
+    // Assume for now we're always at the top
+    text_t hlist_metadata_value = hierarchical_metadata_value;
+
+    // Determine the label for the hlist classifier node from the metadata value
+    text_tlist hlist_metadata_value_parts;
+    text_t hlist_node_separator = classifier_options["-split_using_hierarchy_separator"];
+    splitword (hlist_metadata_value.begin(), hlist_metadata_value.end(), hlist_node_separator, hlist_metadata_value_parts);
+    text_t hlist_classifier_node_label = hlist_metadata_value_parts.front();
+
+    // Create a node for this value if we haven't seen it before
+    if (hlist_classifier_nodes.find(hlist_classifier_node_label) == hlist_classifier_nodes.end())
+    {
+      hlist_classifier_nodes[hlist_classifier_node_label] = 0;
+    }
+
+    // Increment the occurrence count
+    hlist_classifier_nodes[hlist_classifier_node_label] += (*metadata_value_iterator).result_num;
+
+    metadata_value_iterator++;
+  }
+
+  // Add the necessary metadata to the hlist classifier nodes
+  text_t selected_hlist_node_OID = "";
+  FilterResponse_t hlist_classifier_nodes_response;
+  map<text_t, int, lttext_t>::iterator hlist_classifier_nodes_iterator = hlist_classifier_nodes.begin();
+  while (hlist_classifier_nodes_iterator != hlist_classifier_nodes.end())
+  {
+    text_t hlist_classifier_node_OID = parent_classifier_node_OID + (*hlist_classifier_nodes_iterator).first;
+
+    // Is this the hlist node that is currently selected?
+    if (starts_with (args["dcn"], hlist_classifier_node_OID))
+    {
+      selected_hlist_node_OID = hlist_classifier_node_OID;
+    }
+
+    // Add the necessary metadata required to display the hlist nodes correctly
+    ResultDocInfo_t hlist_classifier_node;
+    hlist_classifier_node.OID = hlist_classifier_node_OID;
+    hlist_classifier_node.metadata["doctype"].values.push_back ("classify");
+    hlist_classifier_node.metadata["haschildren"].values.push_back ("1");
+    hlist_classifier_node.metadata["numleafdocs"].values.push_back ("?");  // We can't determine this without more database requests
+    hlist_classifier_node.metadata["Title"].values.push_back ((*hlist_classifier_nodes_iterator).first);
+    hlist_classifier_nodes_response.docInfo.push_back (hlist_classifier_node);
+
+    hlist_classifier_nodes_iterator++;
+  }
+
+  // Automatically select the first hlist node if necessary
+  if (selected_hlist_node_OID == "")
+  {
+    selected_hlist_node_OID = (*hlist_classifier_nodes_response.docInfo.begin()).OID;
+
+    // Don't really like messing with this here, but it needs to be done before display_classifier_nodes() below
+    if (starts_with (parent_classifier_node_OID, args["dcn"]))
+    {
+      args["dcn"] = selected_hlist_node_OID;
+    }
+  }
+
+  // Display the hlist nodes
+  display_classifier_nodes (hlist_classifier_nodes_response, "HList", 0, args, collectproto, browsers, disp, outconvert, textout, logout);
+
+  return selected_hlist_node_OID;
+}
+
+
+void dynamicclassifieraction::output_upper_classifier_nodes (text_t root_classifier_node_OID,
+							     text_tlist upper_classifier_node_labels,
+							     int& classifier_node_indent,
+							     text_tmap classifier_options, cgiargsclass &args,
+							     recptproto *collectproto, browsermapclass *browsers,
+							     displayclass &disp, outconvertclass &outconvert,
+							     ostream &textout, ostream &logout)
+{
+  // Display the upper classifier nodes
+  text_t upper_classifier_node_OID = root_classifier_node_OID;
+  text_tlist::iterator upper_classifier_node_labels_iterator = upper_classifier_node_labels.begin();
+  while (upper_classifier_node_labels_iterator != upper_classifier_node_labels.end())
+  {
+    upper_classifier_node_OID += *upper_classifier_node_labels_iterator;
+
+    ResultDocInfo_t upper_classifier_node;
+    upper_classifier_node.OID = upper_classifier_node_OID;
+    upper_classifier_node.metadata["doctype"].values.push_back ("classify");
+    upper_classifier_node.metadata["haschildren"].values.push_back ("1");
+    upper_classifier_node.metadata["numleafdocs"].values.push_back ("?");  // We can't determine this without more database requests
+    upper_classifier_node.metadata["Title"].values.push_back (*upper_classifier_node_labels_iterator);
+
+    FilterResponse_t upper_classifier_node_response;
+    upper_classifier_node_response.docInfo.push_back(upper_classifier_node);
+    display_classifier_nodes (upper_classifier_node_response, "VList", classifier_node_indent, args, collectproto, browsers, disp, outconvert, textout, logout);
+    classifier_node_indent++;
+
+    upper_classifier_node_OID += classifier_options["-split_using_hierarchy_separator"];
+    upper_classifier_node_labels_iterator++;
+  }
+}
+
+
+void dynamicclassifieraction::output_child_classifier_nodes (text_t classifier_node_OID,
+							     text_t classifier_node_metadata_value,
+							     text_t metadata_value_filter,
+							     int& classifier_node_indent,
+							     text_tmap classifier_options, cgiargsclass &args,
+							     recptproto *collectproto, browsermapclass *browsers,
+							     displayclass &disp, outconvertclass &outconvert,
+							     ostream &textout, ostream &logout)
+{
+  // Get all the metadata values for the specified element(s) that match the filter
+  text_t metadata_elements = classifier_options["metadata_elements"];
+  FilterResponse_t metadata_values_response;
+  bool request_success = get_metadata_values (metadata_elements, metadata_value_filter, "", args["c"], collectproto, metadata_values_response, logout);
+
+  // If the request failed then it's probably because the collection isn't using an SQL infodbtype
+  if (request_success == false)
+  {
+    textout << outconvert << disp << "Error: Dynamic classifier functionality is not available. Please check you are using an SQL infodbtype and the collection has been rebuilt.\n";
+    return;
+  }
+
+  // After processing any hierarchical metadata values we're left with the child classifer nodes
+  map<text_t, int, lttext_t> child_classifier_nodes;
+  ResultDocInfo_tarray::iterator metadata_value_iterator = metadata_values_response.docInfo.begin();
+  while (metadata_value_iterator != metadata_values_response.docInfo.end())
+  {
+    text_t hierarchical_metadata_value = split_metadata_value ((*metadata_value_iterator).OID, classifier_options);
+    text_t classifier_node_hierarchical_metadata_value = split_metadata_value (classifier_node_metadata_value, classifier_options);
+
+    // We need to remove the current position from the metadata value to leave the child metadata value
+    text_t child_metadata_value = hierarchical_metadata_value;
+    text_t child_node_separator = classifier_options["-split_using_hierarchy_separator"];
+    if (starts_with(hierarchical_metadata_value, classifier_node_hierarchical_metadata_value + child_node_separator))
+    {
+      child_metadata_value = substr(hierarchical_metadata_value.begin() + (classifier_node_hierarchical_metadata_value + child_node_separator).size(), hierarchical_metadata_value.end());
+    }
+
+    // Determine the label for the child classifier node from the metadata value
+    text_tlist child_metadata_value_parts;
+    splitword (child_metadata_value.begin(), child_metadata_value.end(), child_node_separator, child_metadata_value_parts);
+    text_t child_classifier_node_label = child_metadata_value_parts.front();
+
+    // Create a node for this value if we haven't seen it before
+    if (child_classifier_nodes.find(child_classifier_node_label) == child_classifier_nodes.end())
+    {
+      child_classifier_nodes[child_classifier_node_label] = 0;
+    }
+
+    // Increment the occurrence count
+    child_classifier_nodes[child_classifier_node_label] += (*metadata_value_iterator).result_num;
+
+    metadata_value_iterator++;
+  }
+
+  // Add the necessary metadata to the child classifier nodes
+  FilterResponse_t child_classifier_nodes_response;
+  map<text_t, int, lttext_t>::iterator child_classifier_nodes_iterator = child_classifier_nodes.begin();
+  while (child_classifier_nodes_iterator != child_classifier_nodes.end())
+  {
+    text_t child_classifier_node_OID = classifier_node_OID + (*child_classifier_nodes_iterator).first;
+
+    ResultDocInfo_t child_classifier_node;
+    child_classifier_node.OID = child_classifier_node_OID;
+    child_classifier_node.metadata["doctype"].values.push_back ("classify");
+    child_classifier_node.metadata["haschildren"].values.push_back ("1");
+    child_classifier_node.metadata["numleafdocs"].values.push_back ((*child_classifier_nodes_iterator).second);
+    child_classifier_node.metadata["Title"].values.push_back ((*child_classifier_nodes_iterator).first);
+    child_classifier_nodes_response.docInfo.push_back (child_classifier_node);
+
+    child_classifier_nodes_iterator++;
+  }
+
+  // Display the child classifier nodes
+  display_classifier_nodes (child_classifier_nodes_response, "VList", classifier_node_indent, args, collectproto, browsers, disp, outconvert, textout, logout);
+}
+
+
+text_t dynamicclassifieraction::split_metadata_value (text_t metadata_value, text_tmap classifier_options)
+{
+  text_t hierarchical_metadata_value = metadata_value;
+  text_t hierarchy_separator = classifier_options["-split_using_hierarchy_separator"];
+
+  // Add hierarchy separators into Greenstone date values (e.g. YYYYMMDD -> YYYY|MM|DD)
+  if (classifier_options["-split_greenstone_dates"] == "1")
+  {
+    if (metadata_value.size() == 4 || metadata_value.size() == 6 || metadata_value.size() == 8)
+    {
+      // Add year
+      hierarchical_metadata_value = substr (metadata_value.begin(), metadata_value.begin() + 4);
+      if (metadata_value.size() == 6 || metadata_value.size() == 8)
+      {
+	// Add month
+	hierarchical_metadata_value += hierarchy_separator;
+	hierarchical_metadata_value += substr (metadata_value.begin() + 4, metadata_value.begin() + 6);
+	if (metadata_value.size() == 8)
+	{
+	  // Add day
+	  hierarchical_metadata_value += hierarchy_separator;
+	  hierarchical_metadata_value += substr (metadata_value.begin() + 6, metadata_value.begin() + 8);
+	}
+      }
+    }
+  }
+
+  return hierarchical_metadata_value;
+}
+
+
+void dynamicclassifieraction::display_classifier_nodes (FilterResponse_t classifier_nodes_response,
+						        text_t classifier_nodes_type,
+							int classifier_nodes_indent,
+							cgiargsclass &args, recptproto *collectproto,
+							browsermapclass *browsers, displayclass &disp,
+							outconvertclass &outconvert, ostream &textout,
+							ostream &logout)
+{
+  // Check there are some classifier nodes to display
+  if (classifier_nodes_response.docInfo.empty()) return;
+
+  // Get the format statement for this classifier if there is one, or use the browser's default otherwise
+  text_t formatstring;
+  browserclass *bptr = browsers->getbrowser (classifier_nodes_type);
+  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
+  if (!get_formatstring (args["dcl"], classifier_nodes_type, cinfo->format, formatstring))
+  {
+    formatstring = bptr->get_default_formatstring();
+  }
+  format_t *formatlistptr = new format_t();
+  text_tset metadata;
+  bool getParents = false;
+  parse_formatstring (formatstring, formatlistptr, metadata, getParents);
+  bool use_table = is_table_content (formatlistptr);
+
+  // Display the classifier nodes
+  bptr->output_section_group (classifier_nodes_response, args, args["c"], classifier_nodes_indent, formatlistptr, use_table, metadata, getParents, collectproto, disp, outconvert, textout, logout);
+}
+
+
+void dynamicclassifieraction::display_document_nodes (FilterResponse_t documents_response,
+						      int document_nodes_indent,
+						      cgiargsclass &args, recptproto *collectproto,
+						      browsermapclass *browsers, displayclass &disp,
+						      outconvertclass &outconvert, ostream &textout,
+						      ostream &logout)
+{
+  // Check there are some documents to display
+  if (documents_response.docInfo.empty()) return;
+
+  // Get the format statement for the document nodes if there is one, or use the browser's default otherwise
+  text_t formatstring;
+  browserclass *bptr = browsers->getbrowser ("VList");
+  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, args["c"], logout);
+  if (!get_formatstring (args["dcl"], "DocumentNodes", cinfo->format, formatstring))
+  {
+    if (!get_formatstring (args["dcl"], "VList", cinfo->format, formatstring))
+    {
+      formatstring = bptr->get_default_formatstring();
+    }
+  }
+  format_t *formatlistptr = new format_t();
+  text_tset metadata;
+  bool getParents = false;
+  parse_formatstring (formatstring, formatlistptr, metadata, getParents);
+  bool use_table = is_table_content (formatlistptr);
+
+  // Request the necessary metadata for displaying the documents
+  text_tarray document_OIDs;
+  ResultDocInfo_tarray::iterator document_iterator = documents_response.docInfo.begin();
+  while (document_iterator != documents_response.docInfo.end())
+  {
+    document_OIDs.push_back ((*document_iterator).OID);
+    document_iterator++;
+  }
+  FilterResponse_t document_nodes_response;
+  get_info (document_OIDs, args["c"], args["l"], metadata, getParents, collectproto, document_nodes_response, logout);
+
+  // Display the document nodes
+  bptr->output_section_group (document_nodes_response, args, args["c"], document_nodes_indent, formatlistptr, use_table, metadata, getParents, collectproto, disp, outconvert, textout, logout);
+}
Index: /gsdl/trunk/runtime-src/src/recpt/dynamicclassifieraction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/dynamicclassifieraction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/dynamicclassifieraction.h	(revision 16571)
@@ -0,0 +1,111 @@
+/**********************************************************************
+ *
+ * dynamicclassifieraction.h -- 
+ * Copyright (C) 2008  DL Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef DYNAMICCLASSIFIERACTION_H
+#define DYNAMICCLASSIFIERACTION_H
+
+
+#include "action.h"
+#include "receptionist.h"
+
+
+class dynamicclassifieraction : public action
+{
+protected:
+  receptionist *recpt;
+
+public:
+  dynamicclassifieraction ();
+  virtual ~dynamicclassifieraction ();
+
+  void set_receptionist (receptionist *recpt_arg) { recpt = recpt_arg; }
+
+  text_t get_action_name () { return "dc"; }
+
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass *protos, ostream &logout);
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response,text_t &response_data, 
+			 ostream &logout);
+
+  void define_external_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+
+  virtual void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+				       recptprotolistclass *protos, ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+  text_tmap parse_classifier_options (text_t classifier_specification, cgiargsclass &args);
+
+  text_t output_hlist_classifier_nodes (text_t parent_classifier_node_OID,
+					text_t metadata_value_filter,
+					text_t metadata_value_grouping_expression,
+					text_tmap classifier_options, cgiargsclass &args,
+					recptproto *collectproto, browsermapclass *browsers,
+					displayclass &disp, outconvertclass &outconvert,
+					ostream &textout, ostream &logout);
+
+  void output_upper_classifier_nodes (text_t root_classifier_node_OID,
+				      text_tlist parent_classifier_node_labels,
+				      int& classifier_node_indent,
+				      text_tmap classifier_options, cgiargsclass &args,
+				      recptproto *collectproto, browsermapclass *browsers,
+				      displayclass &disp, outconvertclass &outconvert,
+				      ostream &textout, ostream &logout);
+
+  void output_child_classifier_nodes (text_t classifier_node_OID,
+				      text_t classifier_node_metadata_value,
+				      text_t metadata_value_filter,
+				      int& classifier_node_indent,
+				      text_tmap classifier_options, cgiargsclass &args,
+				      recptproto *collectproto, browsermapclass *browsers,
+				      displayclass &disp, outconvertclass &outconvert,
+				      ostream &textout, ostream &logout);
+
+  text_t split_metadata_value (text_t metadata_value, text_tmap classifier_options);
+
+  void display_classifier_nodes (FilterResponse_t classifier_nodes_response,
+				 text_t classifier_nodes_type,
+				 int classifier_nodes_indent,
+				 cgiargsclass &args, recptproto *collectproto,
+				 browsermapclass *browsers, displayclass &disp,
+				 outconvertclass &outconvert, ostream &textout,
+				 ostream &logout);
+
+  void display_document_nodes (FilterResponse_t documents_response,
+			       int document_nodes_indent,
+			       cgiargsclass &args, recptproto *collectproto,
+			       browsermapclass *browsers, displayclass &disp,
+			       outconvertclass &outconvert, ostream &textout,
+			       ostream &logout);
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/extlinkaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/extlinkaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/extlinkaction.cpp	(revision 16571)
@@ -0,0 +1,252 @@
+/**********************************************************************
+ *
+ * extlinkaction.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_EXTLINK_ACTION
+
+#include <string.h>
+#include "extlinkaction.h"
+#include "recptprototools.h"
+#include "cgiutils.h"
+
+extlinkaction::extlinkaction () {
+
+  // this action uses cgi variables "a", "d", and "href"
+
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "extlink";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "el";
+  arg_ainfo.longname = "external link preference";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "prompt";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "d";
+  arg_ainfo.longname = "document OID";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::none;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::can;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "href";
+  arg_ainfo.longname = "URL of external link";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::none;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::can;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "rl";
+  arg_ainfo.longname = "is relative link";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::none;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+}
+
+extlinkaction::~extlinkaction () {
+}
+
+
+void extlinkaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+				      response_t &response, text_t &response_data, 
+				      ostream &logout) {
+
+  text_t link;
+  if (get_link (args, protos, link, logout)) {
+    response = location;
+    response_data = link;
+    return;
+  }
+
+  // external link
+  if (!link.empty()) {
+    if (args["el"] == "direct") {
+      response = location;
+      response_data = link;
+      return;
+    }
+  }
+
+  response = content;
+  response_data = "text/html";
+}
+
+void extlinkaction::define_internal_macros (displayclass &disp, cgiargsclass &args, 
+					    recptprotolistclass * /*protos*/, 
+					    ostream &/*logout*/) {
+  
+  // define_internal_macros sets the following macros:
+
+  // _nexturl_             link to external page
+  // _prevdoc_             link to previous document
+  //  disp.setmacro("nexturl", "extlink", cgi_safe(args["href"]));
+  // problem in whist, above line changed.  Perhaps decode_cgi_arg ??
+  // see also HTML plugin
+  disp.setmacro("nexturl", "extlink", args["href"]);
+  disp.setmacro("prevdoc", "extlink", args["d"]);
+}
+
+
+// if link is found returns true and url in link, otherwise returns
+// false
+bool extlinkaction::get_link (cgiargsclass &args, recptprotolistclass *protos,
+			      text_t &link, ostream &logout) {
+
+    text_t &arg_href = args["href"];
+    text_t &thiscollection = args["c"];
+    if (arg_href.empty()) return false;
+
+    text_t httpdoc = "_gwcgi_?e=_compressedoptions_&a=d";
+    if (args["rl"] == "1") {
+
+      FilterResponse_t response;
+      text_tset metadata;
+      metadata.insert ("section");
+	  
+      recptproto *collectproto = protos->getrecptproto (thiscollection, logout);
+
+      if (get_info (arg_href, thiscollection, args["l"], metadata, false, collectproto, response, logout)) {
+	if (!response.docInfo[0].metadata["section"].values[0].empty()) {
+	  link = httpdoc+"&d=" + response.docInfo[0].metadata["section"].values[0];
+	  return true;
+	}
+      }
+
+      // need to see if link exists in any other collection
+      // if cross-collection searching/browsing is turned on 
+      if (args["ccs"] == "1" && !args["cc"].empty()) {
+	text_tarray collections;
+	splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
+
+	text_tarray::const_iterator col_here = collections.begin();
+	text_tarray::const_iterator col_end = collections.end();
+
+	while (col_here != col_end) {
+	  
+	  // don't need to check current collection again
+	  if (*col_here == thiscollection) {++col_here; continue;}
+	  
+	  recptproto *collectproto = protos->getrecptproto (*col_here, logout);
+	  if (collectproto == NULL) {++col_here; continue;}
+
+	  if (get_info (arg_href, *col_here, args["l"], metadata, false, collectproto, response, logout)) {
+	    if (!response.docInfo[0].metadata["section"].values[0].empty()) {
+	      link = httpdoc+"&c=" + *col_here + "&d=" +
+		response.docInfo[0].metadata["section"].values[0];
+	      return true;
+	    }
+	  }
+	  ++col_here;
+	}
+      }
+      return false;
+      
+    } else {
+      // link is external 
+      link = arg_href;
+      return false;
+    }
+}
+
+
+bool extlinkaction::do_action (cgiargsclass &args, recptprotolistclass *protos, 
+			       browsermapclass * /*browsers*/, displayclass &disp,
+			       outconvertclass &outconvert, ostream &textout,
+			       ostream &logout) {
+ 
+  if (args["href"].empty()) {
+     // oops, this shouldn't happen
+    textout << outconvert << disp << ("_extlink:header_\n")
+	    << ("_extlink:notfoundcontent_\n")
+	    << ("_extlink:footer_\n");
+    return true;
+  }
+
+  if (args["rl"] == "1") {
+    // need to see if link exists in any other collection
+    // if cross-collection searching/browsing is turned on 
+    if (args["ccs"] == "1" && !args["cc"].empty()) {
+      
+      FilterResponse_t response;
+      text_tset metadata;
+      metadata.insert ("section");
+      text_tarray collections;
+      splitchar (args["cc"].begin(), args["cc"].end(), ',', collections);
+      
+      text_tarray::const_iterator col_here = collections.begin();
+      text_tarray::const_iterator col_end = collections.end();
+      
+      while (col_here != col_end) {
+	
+	// don't need to check current collection
+	if (*col_here == args["c"]) {++col_here; continue;}
+	
+	recptproto *collectproto = protos->getrecptproto (*col_here, logout);
+	if (get_info (args["href"], *col_here, args["l"], metadata, false, collectproto, response, logout)) {
+	  if (!response.docInfo[0].metadata["section"].values[0].empty()) {
+	    ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
+	    text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]); //
+	    if (collectionname.empty()) {
+	      collectionname = *col_here;
+	    }
+	    textout << outconvert << disp << ("_extlink:header_\n")
+		    << ("_extlink:foundintcontent_(" + *col_here + ", " + collectionname + 
+			", " + response.docInfo[0].metadata["section"].values[0] + "\n")
+		    << ("_extlink:footer_\n");
+	    return true;
+	  }
+	}
+	++col_here;
+      }
+    }
+    textout << outconvert << disp << ("_extlink:header_\n")
+	    << ("_extlink:notfoundcontent_\n")
+	    << ("_extlink:footer_\n");
+    
+    
+  } else {
+    // link is external 
+    textout << outconvert << disp << ("_extlink:header_\n")
+	    << ("_extlink:foundcontent_\n")
+	    << ("_extlink:footer_\n");
+  }
+
+  return true;
+}
+
+#endif //GSDL_USE_EXTLINK_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/extlinkaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/extlinkaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/extlinkaction.h	(revision 16571)
@@ -0,0 +1,69 @@
+/**********************************************************************
+ *
+ * extlinkaction.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_EXTLINK_ACTION
+
+#ifndef EXTLINKACTION_H
+#define EXTLINKACTION_H
+
+#include "action.h"
+#include "receptionist.h"
+
+class extlinkaction : public action {
+
+
+public:
+  extlinkaction ();
+  virtual ~extlinkaction ();
+
+  void set_receptionist (receptionist *therecpt) {recpt=therecpt;}
+
+  text_t get_action_name () {return "extlink";}
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response, text_t &response_data, 
+			 ostream &logout);
+
+  void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, 
+			       ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp,
+		  outconvertclass &outconvert, ostream &textout,
+		  ostream &logout);
+
+
+protected:
+  
+  receptionist *recpt;
+  
+  bool get_link (cgiargsclass &args, recptprotolistclass *protos,
+		 text_t &link, ostream &logout);
+
+};
+
+#endif //!EXTLINKACTION_H
+#endif //GSDL_USE_EXTLINK_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/formattools.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/formattools.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/formattools.cpp	(revision 16571)
@@ -0,0 +1,1573 @@
+/**********************************************************************
+ *
+ * formattools.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "formattools.h"
+#include "cgiutils.h"
+#include "recptprototools.h"
+#include "OIDtools.h"
+#include "summarise.h"
+
+#include <assert.h>
+
+// a few function prototypes
+
+static text_t format_string (const text_t& collection, recptproto* collectproto,
+			     ResultDocInfo_t &docinfo, displayclass &disp, 
+			     format_t *formatlistptr, text_tmap &options,
+			     ostream& logout);
+
+static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 
+			  format_t *formatlistptr, text_tset &metadata, bool &getParents);
+
+static text_t format_summary (const text_t& collection, recptproto* collectproto,
+			      ResultDocInfo_t &docinfo, displayclass &disp, 
+			      text_tmap &options, ostream& logout);
+static text_t format_text (const text_t& collection, recptproto* collectproto,
+			      ResultDocInfo_t &docinfo, displayclass &disp, 
+			      text_tmap &options, ostream& logout);
+
+static text_t expand_metadata(const text_t &metavalue, const text_t& collection,
+			      recptproto* collectproto, ResultDocInfo_t &docinfo,
+			      displayclass &disp, text_tmap &options,
+			      ostream &logout);
+
+
+void metadata_t::clear() {
+  metaname.clear();
+  metacommand = mNone;
+  mqualifier.parent  = pNone;
+  mqualifier.sibling = sNone;
+  mqualifier.child   = cNone;
+  parentoptions.clear();
+  siblingoptions.clear();
+  childoptions.clear();
+}
+
+void decision_t::clear() {
+  command = dMeta;
+  meta.clear();
+  text.clear();
+}
+
+void format_t::clear() {
+  command = comText;
+  decision.clear();
+  text.clear();
+  meta.clear();
+  nextptr = NULL;
+  ifptr = NULL;
+  elseptr = NULL;
+  orptr = NULL;
+}
+
+void formatinfo_t::clear() {
+  DocumentImages = false;
+  DocumentTitles = true;
+  DocumentHeading = "{Or}{[parent(Top):Title],[Title],untitled}<br>";
+  DocumentContents = true;
+  DocumentArrowsBottom = true; 
+  DocumentArrowsTop = false; 
+  DocumentSearchResultLinks = false;
+  DocumentButtons.erase (DocumentButtons.begin(), DocumentButtons.end());
+  //  DocumentButtons.push_back ("Expand Text");
+  //  DocumentButtons.push_back ("Expand Contents");
+  DocumentButtons.push_back ("Detach");
+  DocumentButtons.push_back ("Highlight");
+  RelatedDocuments = "";
+  DocumentText = "[Text]";
+  formatstrings.erase (formatstrings.begin(), formatstrings.end());
+  DocumentUseHTML = false;
+  AllowExtendedOptions = false;
+}
+
+// simply checks to see if formatstring begins with a <td> tag
+bool is_table_content (const text_t &formatstring) {
+  text_t::const_iterator here = formatstring.begin();
+  text_t::const_iterator end = formatstring.end();
+  
+  while (here != end) {
+    if (*here != ' ') {
+      if ((*here == '<') && ((here+3) < end)) {
+	if ((*(here+1) == 't' || *(here+1) == 'T') &&
+	    (*(here+2) == 'd' || *(here+2) == 'D') &&
+	    (*(here+3) == '>' || *(here+3) == ' '))
+	  return true;
+      } else return false;
+    }
+    ++here;
+  }
+  return false;
+}
+
+bool is_table_content (const format_t *formatlistptr) {
+
+  if (formatlistptr == NULL) return false;
+  
+  if (formatlistptr->command == comText)
+    return is_table_content (formatlistptr->text);
+    
+  return false;
+}
+
+// returns false if key isn't in formatstringmap
+bool get_formatstring (const text_t &key, const text_tmap &formatstringmap,
+		       text_t &formatstring) {
+
+  formatstring.clear();
+  text_tmap::const_iterator it = formatstringmap.find(key);
+  if (it == formatstringmap.end()) return false;
+  formatstring = (*it).second;
+  return true;
+}
+
+// tries to find "key1key2" then "key1" then "key2"
+bool get_formatstring (const text_t &key1, const text_t &key2,  
+		       const text_tmap &formatstringmap,
+		       text_t &formatstring) {
+
+  formatstring.clear();
+  text_tmap::const_iterator it = formatstringmap.find(key1 + key2);
+  if (it != formatstringmap.end()) {
+    formatstring = (*it).second;
+    return true;
+  }
+  it = formatstringmap.find(key1);
+  if (it != formatstringmap.end()) {
+    formatstring = (*it).second;
+    return true;
+  }
+  it = formatstringmap.find(key2);
+  if (it != formatstringmap.end()) {
+    formatstring = (*it).second;
+    return true;
+  }
+  return false;
+}
+
+
+text_t remove_namespace(const text_t &meta_name) {
+  text_t::const_iterator end = meta_name.end();
+  text_t::const_iterator it = findchar(meta_name.begin(), end, '.');
+  if (it != end) {
+    return substr(it+1, end);
+  }
+
+  return meta_name;
+
+}
+// returns a date of form _format:date_(year, month, day)
+// input is date of type yyyy-?mm-?dd
+// at least the year must be present in date
+text_t format_date (const text_t &date) {
+
+  if (date.size() < 4) return "";
+
+  text_t::const_iterator datebegin = date.begin();
+
+  text_t year = substr (datebegin, datebegin+4);
+  int chars_seen_so_far = 4;
+
+  if (date[chars_seen_so_far] == '-') ++chars_seen_so_far ;
+  if (date.size() < chars_seen_so_far+2) return "_format:date_("+year+")";
+ 
+  text_t month = substr (datebegin+chars_seen_so_far, datebegin+chars_seen_so_far+2);
+  int imonth = month.getint();
+  if (imonth <= 0 || imonth > 12) return "_format:date_("+year+")";
+ 
+  chars_seen_so_far += 2;
+  if (date[chars_seen_so_far] == '-') ++chars_seen_so_far ;
+  
+  if (date.size() < chars_seen_so_far+2) return "_format:date_("+year+","+month+")";
+
+  text_t day = substr (datebegin+chars_seen_so_far, datebegin+chars_seen_so_far+2);
+  if (day[0] == '0') day = substr (day.begin()+1, day.end());
+  int iday = day.getint();
+  if (iday <= 0 || iday > 31) return "_format:date_("+year+","+month+")";
+    
+  return "_format:date_("+year+","+month+","+day+")";
+}  
+
+// converts an iso639 language code to its English equivalent
+// should we be checking that the macro exists??
+text_t iso639 (const text_t &langcode) {
+  if (langcode.empty()) return "";
+  return "_iso639:iso639"+langcode+"_";
+}
+
+
+text_t get_href (const text_t &link) {
+
+  text_t href;
+
+  text_t::const_iterator here = findchar(link.begin(), link.end(), '"');
+  text_t::const_iterator end = link.end();
+  if (here == end) return g_EmptyText;
+  
+  ++here;
+  while (here != end) {
+    if (*here == '"') break;
+    href.push_back(*here);
+    ++here;
+  }
+
+  return href;
+}
+
+//this function gets the information associated with the relation
+//metadata for the document associated with 'docinfo'. This relation
+//metadata consists of a line of pairs containing 'collection, document OID'
+//(this is the OID of the document related to the current document, and
+//the collection the related document belongs to). For each of these pairs
+//the title metadata is obtained and then an html link between the title
+//of the related doc and the document's position (the document will be
+//found in "<a href=\"_httpdocument_&c=collection&cl=search&d=OID">
+//(where collection is the related documents collection, and OID is the
+//related documents OID).  A list of these html links are made for as many
+//related documents as there are. This list is then returned. If there are
+//no related documents available for the current document then the string
+//'.. no related documents .. ' is returned.
+text_t get_related_docs(const text_t& collection, recptproto* collectproto,
+			ResultDocInfo_t &docinfo, ostream& logout){
+  
+  text_tset metadata;
+
+  //insert the metadata we wish to collect
+  metadata.insert("dc.Relation"); 
+  metadata.insert("Title");  
+  metadata.insert("Subject"); //for emails, where title data doesn't apply
+ 
+  FilterResponse_t response;
+  text_t relation = ""; //string for displaying relation metadata
+  text_t relationTitle = ""; //the related documents Title (or subject)
+  text_t relationOID = ""; //the related documents OID  
+
+  //get the information associated with the metadata for current doc
+  if (get_info (docinfo.OID, collection, "", metadata, 
+		false, collectproto, response, logout)) {
+    
+    //if the relation metadata exists, store for displaying
+    if(!response.docInfo[0].metadata["dc.Relation"].values.empty()){
+      relationOID += response.docInfo[0].metadata["dc.Relation"].values[0];
+
+      //split relation data into pairs of collectionname,ID number
+      text_tarray relationpairs;
+      splitchar (relationOID.begin(), relationOID.end(), ' ', relationpairs);
+      
+      text_tarray::const_iterator currDoc = relationpairs.begin();  
+      text_tarray::const_iterator lastDoc = relationpairs.end();
+
+      //iterate through the pairs to split and display
+      while(currDoc != lastDoc){
+	
+	//split pairs into collectionname and ID 
+	text_tarray relationdata;
+	splitchar ((*currDoc).begin(), (*currDoc).end(), ',', relationdata);
+	
+	//get first element in the array (collection)
+	text_tarray::const_iterator doc_data = relationdata.begin();
+	text_t document_collection = *doc_data;
+	++doc_data; //increment to get next item in array (oid)
+	text_t document_OID = *doc_data;
+	
+	//create html link to related document
+	relation += "<a href=\"_httpdocument_&c=" + document_collection;
+	relation += "&cl=search&d=" + document_OID;
+	   
+	//get the information associated with the metadata for related doc
+	if (get_info (document_OID, document_collection, "", metadata,
+		      false, collectproto, response, logout)) {
+	  
+	  //if title metadata doesn't exist, collect subject metadata
+	  //if that doesn't exist, just call it 'related document'
+	  if (!response.docInfo[0].metadata["Title"].values[0].empty())
+		relationTitle = response.docInfo[0].metadata["Title"].values[0];
+	  else if (!response.docInfo[0].metadata["Subject"].values.empty())
+	    relationTitle = response.docInfo[0].metadata["Subject"].values[0];
+	  else relationTitle =  "RELATED DOCUMENT";
+	  
+	}
+	
+	//link the related document's title to its page
+	relation += "\">" + relationTitle + "</a>"; 
+	relation += "  (" + document_collection + ")<br>";
+	
+	++currDoc;
+      }
+    }
+    
+  } 
+
+  if(relation.empty()) //no relation data for documnet
+    relation = ".. no related documents .. ";
+
+  return relation;
+}
+
+
+
+static void get_parent_options (text_t &instring, metadata_t &metaoption) {
+
+  assert (instring.size() > 7);
+  if (instring.size() <= 7) return;
+
+  text_t meta, com, op;
+  bool inbraces = false;
+  bool inquotes = false;
+  bool foundcolon = false;
+  text_t::const_iterator here = instring.begin()+6;
+  text_t::const_iterator end = instring.end();
+  while (here != end) {
+    if (foundcolon) meta.push_back (*here);
+    else if (*here == '(') inbraces = true;
+    else if (*here == ')') inbraces = false;
+    else if (*here == '\'' && !inquotes) inquotes = true;
+    else if (*here == '\'' && inquotes) inquotes = false;
+    else if (*here == ':' && !inbraces) foundcolon = true;
+    else if (inquotes) op.push_back (*here);
+    else com.push_back (*here);
+    ++here;
+  }
+
+  instring = meta;
+  if (com.empty())
+    metaoption.mqualifier.parent = pImmediate;
+  else if (com == "Top")
+    metaoption.mqualifier.parent = pTop;
+  else if (com == "All") {
+    metaoption.mqualifier.parent = pAll;
+    metaoption.parentoptions = op;
+  }
+}
+
+
+static void get_sibling_options (text_t &instring, metadata_t &metaoption) {
+
+  assert (instring.size() > 8);
+  if (instring.size() <= 8) return;
+  text_t meta, com, op;
+  bool inbraces = false;
+  bool inquotes = false;
+  bool foundcolon = false;
+  text_t::const_iterator here = instring.begin()+7;
+  text_t::const_iterator end = instring.end();
+  while (here != end) {
+    if (foundcolon) meta.push_back (*here);
+    else if (*here == '(') inbraces = true;
+    else if (*here == ')') inbraces = false;
+    else if (*here == '\'' && !inquotes) inquotes = true;
+    else if (*here == '\'' && inquotes) inquotes = false;
+    else if (*here == ':' && !inbraces) foundcolon = true;    
+    else if (inquotes) op.push_back (*here);
+    else com.push_back (*here);
+    ++here;
+  }
+
+  instring = meta;
+  metaoption.siblingoptions.clear();
+
+  if (com.empty()) {
+    metaoption.mqualifier.sibling = sAll;
+    metaoption.siblingoptions = " ";
+  }
+  else if (com == "first") {
+    metaoption.mqualifier.sibling = sNum;
+    metaoption.siblingoptions = "0";
+  }
+  else if (com == "last") {
+    metaoption.mqualifier.sibling = sNum;
+    metaoption.siblingoptions = "-2"; // == last
+  }
+  else if (com.getint()>0) {
+    metaoption.mqualifier.sibling = sNum;
+    int pos = com.getint()-1;
+    metaoption.siblingoptions +=pos;
+  }
+  else {
+    metaoption.mqualifier.sibling = sAll;
+    metaoption.siblingoptions = op;
+  }
+}
+
+static void get_child_options (text_t &instring, metadata_t &metaoption) {
+
+  assert (instring.size() > 6);
+  if (instring.size() <= 6) return;
+  text_t meta, com, op;
+  bool inbraces = false;
+  bool inquotes = false;
+  bool foundcolon = false;
+  text_t::const_iterator here = instring.begin()+5;
+  text_t::const_iterator end = instring.end();
+  while (here != end) {
+    if (foundcolon) meta.push_back (*here);
+    else if (*here == '(') inbraces = true;
+    else if (*here == ')') inbraces = false;
+    else if (*here == '\'' && !inquotes) inquotes = true;
+    else if (*here == '\'' && inquotes) inquotes = false;
+    else if (*here == ':' && !inbraces) foundcolon = true;
+    else if (inquotes) op.push_back (*here);
+    else com.push_back (*here);
+    ++here;
+  }
+
+  instring = meta;
+  if (com.empty()) {
+    metaoption.mqualifier.child = cAll;
+    metaoption.childoptions = " ";
+  }
+  else if (com == "first") {
+    metaoption.mqualifier.child = cNum;
+    metaoption.childoptions = ".fc";
+  }
+  else if (com == "last") {
+    metaoption.mqualifier.child = cNum;
+    metaoption.childoptions = ".lc";
+  }
+  else if (com.getint()>0) {
+    metaoption.mqualifier.child = cNum;
+    metaoption.childoptions = "."+com;
+  }
+  else {
+    metaoption.mqualifier.child = cAll;
+    metaoption.childoptions = op;
+  }
+}
+
+
+
+static void parse_meta (text_t &meta, metadata_t &metaoption,
+			text_tset &metadata, bool &getParents) {
+
+  if (meta.size() > 8 && (substr(meta.begin(), meta.begin()+8) == "cgisafe:")) {
+    metaoption.metacommand |= mCgiSafe;
+    meta = substr (meta.begin()+8, meta.end());
+  }
+  if (meta.size() > 7 && (substr(meta.begin(), meta.begin()+7) == "format:")) {    
+    metaoption.metacommand |= mSpecial;
+    meta = substr (meta.begin()+7, meta.end());
+  }
+
+  if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) {
+    getParents = true;
+    metaoption.metacommand |= mParent;
+    get_parent_options (meta, metaoption);
+  } 
+  else if (meta.size() > 6 && (substr (meta.begin(), meta.begin()+5) == "child")) {
+    metaoption.metacommand |= mChild;
+    get_child_options (meta, metaoption);
+    metadata.insert("contains");
+  } 
+  // parent and child can have sibling also
+  if (meta.size() > 8 && (substr (meta.begin(), meta.begin()+7) == "sibling")) {
+    metaoption.metacommand |= mSibling;
+    get_sibling_options (meta, metaoption);
+  } 
+  
+  // check for ex. which may occur in format statements
+  if (meta.size()>3 && (substr(meta.begin(), meta.begin()+3) == "ex.")) {
+    meta = substr (meta.begin()+3, meta.end());
+  }
+  metadata.insert (meta);
+  metaoption.metaname = meta;
+}
+
+static void parse_coll_meta(text_t &meta, metadata_t &metaoption) {
+  if (meta == "collection") {
+    // no qualifiers
+    metaoption.metaname = g_EmptyText;
+    return;
+  }
+  meta = substr (meta.begin()+11, meta.end());
+  metaoption.metaname = meta;
+  
+}
+
+static void parse_meta (text_t &meta, format_t *formatlistptr,
+			text_tset &metadata, bool &getParents) {
+  
+  if (meta == "link")
+    formatlistptr->command = comLink;
+  else if (meta == "/link")
+    formatlistptr->command = comEndLink;
+
+  else if (meta == "href")
+    formatlistptr->command = comHref;
+
+  else if (meta == "num")
+    formatlistptr->command = comNum;
+
+  else if (meta == "icon")
+    formatlistptr->command = comIcon;
+
+  else if (meta == "Text")
+    formatlistptr->command = comDoc;
+  
+  else if (meta == "RelatedDocuments")
+   formatlistptr->command = comRel;
+
+  else if (meta == "highlight")
+    formatlistptr->command = comHighlight;
+
+  else if (meta == "/highlight")
+    formatlistptr->command = comEndHighlight;
+
+  else if (meta == "Summary")
+    formatlistptr->command = comSummary;
+
+  else if (meta == "DocImage")
+    formatlistptr->command = comImage; 
+
+  else if (meta == "DocTOC")
+    formatlistptr->command = comTOC; 
+
+  else if (meta == "DocumentButtonDetach")
+     formatlistptr->command = comDocumentButtonDetach;
+  
+  else if (meta == "DocumentButtonHighlight")
+     formatlistptr->command = comDocumentButtonHighlight;
+  
+  else if (meta == "DocumentButtonExpandContents")
+    formatlistptr->command = comDocumentButtonExpandContents; 
+
+  else if (meta == "DocumentButtonExpandText")
+     formatlistptr->command = comDocumentButtonExpandText; 
+
+  else if (meta == "DocOID")
+     formatlistptr->command = comOID; 
+  else if (meta == "DocTopOID")
+    formatlistptr->command = comTopOID;
+  else if (meta == "DocRank")
+    formatlistptr->command = comRank;
+  else if (meta.size() >= 10 && (substr(meta.begin(), meta.begin()+10) == "collection")) {
+    formatlistptr->command = comCollection;
+    parse_coll_meta(meta, formatlistptr->meta);
+  }
+  else {
+    formatlistptr->command = comMeta;
+    parse_meta (meta, formatlistptr->meta, metadata, getParents);
+  }
+}
+
+
+static bool parse_string (const text_t &formatstring, format_t *formatlistptr, 
+			  text_tset &metadata, bool &getParents) {
+
+  text_t text;
+  text_t::const_iterator here = formatstring.begin();
+  text_t::const_iterator end = formatstring.end();
+
+  while (here != end) {
+
+    if (*here == '\\') {
+      ++here;
+      if (here != end) text.push_back (*here);
+
+    } else if (*here == '{') {
+      if (!text.empty()) {
+	formatlistptr->command = comText;
+	formatlistptr->text = text;
+	formatlistptr->nextptr = new format_t();
+	formatlistptr = formatlistptr->nextptr;
+	
+	text.clear();
+      }
+      if (parse_action (++here, end, formatlistptr, metadata, getParents)) {
+
+	formatlistptr->nextptr = new format_t();
+	formatlistptr = formatlistptr->nextptr;
+	if (here == end) break;
+      }
+    } else if (*here == '[') {
+      if (!text.empty()) {
+	formatlistptr->command = comText;
+	formatlistptr->text = text;
+	formatlistptr->nextptr = new format_t();
+	formatlistptr = formatlistptr->nextptr;
+
+	text.clear();
+      }
+      text_t meta;
+      ++here;
+      while (*here != ']') {
+	if (here == end) return false;
+	meta.push_back (*here);
+	++here;
+      }
+      parse_meta (meta, formatlistptr, metadata, getParents);
+      formatlistptr->nextptr = new format_t();
+      formatlistptr = formatlistptr->nextptr;
+
+    } else 
+      text.push_back (*here);
+
+    if (here != end) ++here;
+  }
+  if (!text.empty()) {
+    formatlistptr->command = comText;
+    formatlistptr->text = text;
+    formatlistptr->nextptr = new format_t();
+    formatlistptr = formatlistptr->nextptr;
+
+  }
+  return true;
+}
+
+
+static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 
+			  format_t *formatlistptr, text_tset &metadata, bool &getParents) {
+
+  text_t::const_iterator it = findchar (here, end, '}');
+  if (it == end) return false;
+
+  text_t com = substr (here, it);
+  here = findchar (it, end, '{');
+  if (here == end) return false;
+  else ++here;
+
+  if (com == "If" || com == "if" || com == "IF") formatlistptr->command = comIf;
+  else if (com == "Or" || com == "or" || com == "OR") formatlistptr->command = comOr;
+  else return false;
+
+  int commacount = 0;
+  text_t text;
+  while (here != end) {
+
+    if (*here == '\\') {
+      ++here;
+      if (here != end) text.push_back(*here);
+      
+    } 
+  
+    else if (*here == ',' || *here == '}' || *here == '{') {
+
+      if (formatlistptr->command == comOr) {
+	// the {Or}{this, or this, or this, or this} statement
+	format_t *or_ptr;
+	
+	// find the next unused orptr
+	if (formatlistptr->orptr == NULL) {
+	  formatlistptr->orptr = new format_t();
+	  or_ptr = formatlistptr->orptr;
+	} else {
+	  or_ptr = formatlistptr->orptr;
+	  while (or_ptr->nextptr != NULL)
+	    or_ptr = or_ptr->nextptr;
+	  or_ptr->nextptr = new format_t();
+	  or_ptr = or_ptr->nextptr;
+	}
+
+	if (!text.empty())
+	  {
+	    if (!parse_string(text, or_ptr, metadata, getParents)) { return false; }
+	  }
+
+	if (*here == '{')
+	  {
+	    // Supports: {Or}{[Booktitle],[Title],{If}{[XXXX],aaa,bbb}}
+	    // but not : {Or}{[Booktitle],[Title]{If}{[XXXX],aaa,bbb}}
+	    // The latter can always be re-written:
+	    // {Or}{[Booktitle],{If}{[Title],[Title]{If}{[XXXX],aaa,bbb}}}
+	    
+	    if (!text.empty()) // already used up allocated format_t
+	      {
+		// => allocate new one for detected action
+		or_ptr->nextptr = new format_t();
+		or_ptr = or_ptr->nextptr;
+	      }
+	    if (!parse_action(++here, end, or_ptr, metadata, getParents))
+	      { 
+		return false;
+	      }
+	  }
+	else
+	  {
+	    if (*here == '}') break;
+	  }
+	text.clear();
+
+      } 
+
+      // Parse an {If}{decide,do,else} statement
+      else {
+	
+	// Read the decision component.  
+	if (commacount == 0) {
+	  // Decsion can be a metadata element, or a piece of text.
+	  // Originally Stefan's code, updated 25/10/2000 by Gordon.
+
+	  text_t::const_iterator beginbracket = text.begin();
+	  text_t::const_iterator endbracket = (text.end() - 1);
+
+	  // Decision is based on a metadata element
+	  if ((*beginbracket == '[') && (*endbracket == ']')) {
+	    // Ignore the surrounding square brackets
+	    text_t meta = substr (beginbracket+1, endbracket);
+	    parse_meta (meta, formatlistptr->decision.meta, metadata, getParents);
+	    ++commacount;
+	    text.clear();
+	  } 
+
+	  // Decision is a piece of text (probably a macro like _cgiargmode_).
+	  else {
+
+	    // hunt for any metadata in string, which might be uses in
+	    // to test a condition, e.g. [Format] eq 'PDF'
+	    format_t* dummyformat = new format_t();
+	    // update which metadata fields needed 
+	    // (not interested in updatng formatlistptr)
+	    parse_string (text, dummyformat, metadata, getParents);
+	    delete dummyformat;
+
+	    formatlistptr->decision.command = dText;
+	    formatlistptr->decision.text = text;
+	    ++commacount;
+	    text.clear();
+	  }
+	} 
+
+	// Read the "then" and "else" components of the {If} statement.
+	else {
+	  format_t** nextlistptr = NULL;
+	  if (commacount == 1) {
+	    nextlistptr = &formatlistptr->ifptr;
+	  } else if (commacount == 2 ) {
+	    nextlistptr = &formatlistptr->elseptr;
+	  } else {
+	    return false;
+	  }
+
+	  if (!text.empty()) {
+	    if (*nextlistptr == NULL) {
+	      *nextlistptr = new format_t();
+	    } else {
+
+	      // skip to the end of any format_t statements already added
+	      while ((*nextlistptr)->nextptr != NULL)
+	      {
+		nextlistptr = &(*nextlistptr)->nextptr;
+	      }
+
+	      (*nextlistptr)->nextptr = new format_t();
+	      nextlistptr = &(*nextlistptr)->nextptr;
+	    }
+
+	    if (!parse_string (text, *nextlistptr, metadata, getParents)) 
+	      { 
+		return false; 
+	      }
+	    text.clear();
+	  }
+	  
+	  if (*here == '{')
+	    {
+	      if (*nextlistptr == NULL) {
+		*nextlistptr = new format_t();
+	      } else {
+		// skip to the end of any format_t statements already added
+		while ((*nextlistptr)->nextptr != NULL)
+		  {
+		    nextlistptr = &(*nextlistptr)->nextptr;
+		  }
+
+		(*nextlistptr)->nextptr = new format_t();
+		nextlistptr = &(*nextlistptr)->nextptr;
+	      }
+
+	      if (!parse_action(++here, end, *nextlistptr, metadata, getParents))
+		{ 
+		  return false;
+		}
+	    }
+	  else 
+	    { 
+	      if (*here == '}') break;
+	      ++commacount; 
+	    }
+	}
+      }
+      
+    } else text.push_back(*here);
+    
+    if (here != end) ++here;
+  }
+
+  return true;
+}
+
+
+bool parse_formatstring (const text_t &formatstring, format_t *formatlistptr, 
+			 text_tset &metadata, bool &getParents) {
+
+  formatlistptr->clear();
+  getParents = false;
+
+  return (parse_string (formatstring, formatlistptr, metadata, getParents));
+}
+
+// position -1 for all, -2 for the last, 0 for the first, or x for a particular piece
+// metainfo has all the values for the metadata, meta has the request metadata name and options, position tells which values to get
+static text_t get_formatted_meta_text(MetadataInfo_t &metainfo, const metadata_t &meta, int position, bool no_cgisafe = false) 
+{
+  text_t no_ns_metaname = remove_namespace(meta.metaname);
+  text_t tmp;
+  bool first = true;
+  
+  const int start_i=0;
+  const int end_i = metainfo.values.size()-1;
+  
+  if (position == -1) { // all
+    for (int i=start_i; i<=end_i; ++i) {
+      if (!first) tmp += meta.siblingoptions;
+      if (meta.metacommand & mSpecial) {
+	// special formatting
+	if (no_ns_metaname == "Date") tmp += format_date (metainfo.values[i]);
+	else if (no_ns_metaname == "Language") tmp += iso639(metainfo.values[i]);
+	else tmp += "_format:"+meta.metaname+"_("+metainfo.values[i]+")";
+      }
+      else tmp += metainfo.values[i];
+      first = false;
+      
+    }
+  } else {
+    if (position == -2) { // end
+      position = end_i;
+    } else if (position < start_i || position > end_i) {
+      return "";
+    }
+    if (meta.metacommand & mSpecial) {
+      // special formatting
+      if (no_ns_metaname == "Date") tmp += format_date (metainfo.values[position]);
+      else if (no_ns_metaname == "Language") tmp += iso639(metainfo.values[position]);
+      else tmp += "_format:"+meta.metaname+"_("+metainfo.values[position]+")";
+    } 
+    else tmp += metainfo.values[position];
+  }
+  if (meta.metacommand & mCgiSafe && !no_cgisafe) return cgi_safe_unicode (tmp);
+  else return tmp;
+}
+
+static text_t get_parent_meta (ResultDocInfo_t &docinfo, const metadata_t &meta, int siblings_values) 
+{
+  
+  MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent;
+  switch (meta.mqualifier.parent) {
+  case pNone:
+    return "Nothing!!";
+    break;
+
+  case pImmediate:
+    if (parent != NULL) {
+      return get_formatted_meta_text(*parent, meta, siblings_values);
+    }
+    break;
+
+  case pTop:
+    if (parent != NULL) {
+      while (parent->parent != NULL) parent = parent->parent;
+      return get_formatted_meta_text(*parent, meta, siblings_values);
+    }
+    break;
+
+  case pAll:
+    MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent;
+    if (parent != NULL) {
+      text_tarray tmparray;
+      while (parent != NULL) {
+	tmparray.push_back (get_formatted_meta_text(*parent, meta, siblings_values, true)); // set no_cgisafe to true, as we'll do it once we have all the metadata
+	parent = parent->parent;
+      }
+      // now join them up - use teh parent separator
+      bool first = true;
+      text_t tmp;
+      text_tarray::reverse_iterator here = tmparray.rbegin();
+      text_tarray::reverse_iterator end = tmparray.rend();
+      while (here != end) {
+	if (!first) tmp += meta.parentoptions;
+	tmp += *here;
+	first = false;
+	++here;
+      }
+      if (meta.metacommand & mCgiSafe) return cgi_safe_unicode (tmp);
+      else return tmp;
+    }
+  }
+  return "";
+
+}
+
+static text_t get_child_meta (const text_t& collection, 
+			      recptproto* collectproto,
+			      ResultDocInfo_t &docinfo, displayclass &disp,
+			      const metadata_t &meta, text_tmap &options,
+			      ostream& logout, int siblings_values) 
+{
+  if (docinfo.metadata["contains"].values[0].size()==0) return ""; // no children
+  
+  const text_t& child_metaname = meta.metaname;
+  const text_t& child_field = meta.childoptions;
+  text_tset child_metadata;
+  child_metadata.insert(child_metaname); 
+
+  FilterResponse_t child_response;
+  if (meta.mqualifier.child == cNum) {
+    // just one child
+    //get the information associated with the metadata for child doc
+    if (!get_info (docinfo.OID+child_field, collection, "", child_metadata, 
+		   false, collectproto, child_response, logout)) return ""; // invalid child number
+
+      if (child_response.docInfo.empty()) return false; // no info for the child
+  
+      ResultDocInfo_t& child_docinfo = child_response.docInfo[0];
+      MetadataInfo_t& metaname_rec = child_docinfo.metadata[child_metaname];
+  
+      text_t child_metavalue = get_formatted_meta_text(metaname_rec,meta,siblings_values);
+      return expand_metadata(child_metavalue,collection,collectproto,
+			 child_docinfo,disp,options,logout);
+  }
+  
+    
+  if (meta.mqualifier.child != cAll) return false; // invalid qualifier
+  
+  // we need to get all children
+  text_t result = "";
+  text_tarray children;
+  text_t contains = docinfo.metadata["contains"].values[0];
+  splitchar (contains.begin(), contains.end(), ';', children);
+  text_tarray::const_iterator here = children.begin();
+  text_tarray::const_iterator end = children.end();
+  bool first = true;
+  while (here !=end) {
+    text_t oid = *here;
+    here++;
+    if (*(oid.begin()) == '"') translate_parent (oid, docinfo.OID);
+    
+    
+    //get the information associated with the metadata for child doc
+    if (!get_info (oid, collection, "", child_metadata, 
+		   false, collectproto, child_response, logout) ||
+	child_response.docInfo.empty()) {
+      first = false;
+      continue;
+    }
+    
+    
+    ResultDocInfo_t& child_docinfo = child_response.docInfo[0];
+    MetadataInfo_t& metaname_rec = child_docinfo.metadata[child_metaname];
+    
+    text_t child_metavalue = get_formatted_meta_text(metaname_rec,meta,siblings_values);
+    if (!first) result += child_field;
+    first = false;
+    // need to do this here cos otherwise we are in the wrong document
+    result +=  expand_metadata(child_metavalue,collection,collectproto,
+			       child_docinfo,disp,options,logout);
+  }
+  return result;
+    
+}
+
+static text_t get_meta (const text_t& collection, recptproto* collectproto,
+			ResultDocInfo_t &docinfo, displayclass &disp,
+			const metadata_t &meta, text_tmap &options,
+			ostream& logout) {
+  
+  // make sure we have the requested metadata
+  MetadataInfo_tmap::iterator it = docinfo.metadata.find (meta.metaname);
+  if (it == docinfo.metadata.end()) return "";
+
+  int siblings_values = 0; // default is no siblings, just the first metadata available
+  if (meta.metacommand & mSibling) {
+    if (meta.mqualifier.sibling == sAll) {
+      siblings_values = -1; //all
+    } else if (meta.mqualifier.sibling == sNum) {
+      siblings_values = meta.siblingoptions.getint();
+    }
+  }
+  if (meta.metacommand & mParent) {
+    return get_parent_meta(docinfo,meta,siblings_values);
+  }
+
+  else if (meta.metacommand & mChild) {
+    return get_child_meta(collection,collectproto,docinfo,disp,meta,
+			    options,logout, siblings_values);
+  }
+  else if (meta.metacommand & mSibling) { // only siblings
+    MetadataInfo_t& metaname_rec = docinfo.metadata[meta.metaname];
+    return get_formatted_meta_text(docinfo.metadata[meta.metaname],meta, siblings_values);
+  }
+  else {
+	
+    // straightforward metadata request (nothing fancy)
+
+    text_t classifier_metaname = docinfo.classifier_metadata_type;
+    int metaname_index 
+      = (classifier_metaname == meta.metaname) ? docinfo.classifier_metadata_offset : 0;
+    return get_formatted_meta_text(docinfo.metadata[meta.metaname], meta, metaname_index);
+  }
+  
+  return "";
+}
+
+static text_t get_or (const text_t& collection, recptproto* collectproto,
+		      ResultDocInfo_t &docinfo, displayclass &disp,
+		      format_t *orptr, text_tmap &options,
+		      ostream& logout) {
+
+  text_t tmp;
+  while (orptr != NULL) {
+
+    tmp = format_string (collection,collectproto,docinfo, disp, orptr, 
+			 options, logout);
+    if (!tmp.empty()) return tmp;
+
+    orptr = orptr->nextptr;
+  }
+  return "";
+}
+
+static bool char_is_whitespace(const char c) 
+{
+  return ((c == ' ') || (c == '\t') || (c == '\n') || (c == '\r'));
+
+}
+
+static int scan_over_whitespace(const text_t& outstring, const int start_pos)
+{
+  int pos = start_pos;
+  while (pos<outstring.size()) {
+    if (!char_is_whitespace(outstring[pos])) {
+      break;
+    }
+    ++pos;
+  }
+
+  return pos;
+}
+
+static int rscan_over_whitespace(const text_t& outstring, const int start_pos)
+{
+  int pos = start_pos;
+  while (pos>=0) {
+    if (!char_is_whitespace(outstring[pos])) {
+      break;
+    }
+    --pos;
+  }
+
+  return pos;
+}
+
+static int rscan_for_whitespace(const text_t& outstring, const int start_pos)
+{
+  int pos = start_pos;
+  while (pos>=0) {
+    if (char_is_whitespace(outstring[pos])) {
+      break;
+    }
+    --pos;
+  }
+
+  return pos;
+}
+
+
+static int rscan_for(const text_t& outstring, const int start_pos, 
+		     const char find_c)
+{
+  int pos = start_pos;
+  while (pos>=0) {
+    char c = outstring[pos];
+    if (outstring[pos] == find_c) {
+      break;
+    }
+    --pos;
+  }
+
+  return pos;
+}
+
+text_t extract_substr(const text_t& outstring, const int start_pos,
+		      const int end_pos)
+{
+  text_t extracted_str;
+  extracted_str.clear();
+
+  for (int pos=start_pos; pos<=end_pos; ++pos) {
+    extracted_str.push_back(outstring[pos]);
+  }
+
+  return extracted_str;
+}
+
+
+static text_t expand_potential_metadata(const text_t& collection, 
+					recptproto* collectproto,
+					ResultDocInfo_t &docinfo, 
+					displayclass &disp,
+					const text_t& intext,
+					text_tmap &options,
+					ostream& logout)
+{
+  text_t outtext;
+
+  // decide if dealing with metadata or text
+
+  text_t::const_iterator beginbracket = intext.begin();
+  text_t::const_iterator endbracket = (intext.end() - 1);
+
+  // Decision is based on a metadata element
+  if ((*beginbracket == '[') && (*endbracket == ']')) {
+    // Ignore the surrounding square brackets
+    text_t meta_text = substr (beginbracket+1, endbracket);
+
+    if (meta_text == "Text") {
+      outtext = format_text(collection, collectproto, docinfo, disp, options, logout);
+    } else {
+
+      text_tset metadata;
+      bool getParents =false;
+      metadata_t meta;
+      
+      parse_meta (meta_text, meta, metadata, getParents);	
+      outtext 
+	= get_meta (collection,collectproto,docinfo,disp,meta,options,logout);
+    }
+
+  }
+  else {
+    outtext = intext;
+  }
+
+  return outtext;
+}
+
+
+
+
+static bool uses_expression(const text_t& collection, recptproto* collectproto,
+			    ResultDocInfo_t &docinfo,
+			    displayclass &disp,
+			    const text_t& outstring, text_t& lhs_expr,
+			    text_t& op_expr, text_t& rhs_expr,
+			    text_tmap &options,
+			    ostream& logout)
+{
+  // Note: the string may not be of the form: str1 op str2, however
+  // to deterine this we have to process it on the assumption it is,
+  // and if at any point an 'erroneous' value is encountered, return
+  // false and let something else have a go at evaluating it
+
+  // Starting at the end of the string and working backwards ..
+
+  const int outstring_len = outstring.size();
+
+  // skip over white space
+  int rhs_end = rscan_over_whitespace(outstring,outstring_len-1);
+
+  if (rhs_end<=0) { 
+    // no meaningful text or (rhs_end==0) no room for operator
+    return false;
+  }
+
+  // check for ' or " and then scan over token
+  const char potential_quote = outstring[rhs_end];
+  int rhs_start=rhs_end;
+  bool quoted = false;
+
+  if ((potential_quote == '\'') || (potential_quote == '\"')) {
+    --rhs_end;
+    rhs_start = rscan_for(outstring,rhs_end-1,potential_quote) +1;
+    quoted = true;
+  }
+  else {
+    rhs_start = rscan_for_whitespace(outstring,rhs_end-1) +1;
+  }
+
+  if ((rhs_end-rhs_start)<0) {
+    // no meaningful rhs expression
+    return false;
+  }
+
+  // form rhs_expr
+  rhs_expr = extract_substr(outstring,rhs_start,rhs_end);
+
+  // skip over white space
+  const int to_whitespace = (quoted) ? 2 : 1;
+
+  int op_end = rscan_over_whitespace(outstring,rhs_start-to_whitespace);
+  int op_start = rscan_for_whitespace(outstring,op_end-1)+1;
+
+
+  if (op_end-op_start<0) {
+    // no meaningful expression operator
+    return false;
+  }
+
+  op_expr = extract_substr(outstring,op_start,op_end);
+
+
+  // check for operator
+  if ((op_expr != "eq") && (op_expr != "ne") && (op_expr != "gt") &&
+     (op_expr != "ge") && (op_expr != "lt") && (op_expr != "le") && (op_expr != "==") && (op_expr != "!=") &&  (op_expr != ">") && (op_expr != ">=") && (op_expr != "<") && (op_expr != "<=") && (op_expr != "sw") && (op_expr != "ew")) {
+
+    // not a valid operator
+    return false;
+  }
+
+  int lhs_end = rscan_over_whitespace(outstring,op_start-1);
+  if (lhs_end<0) {
+    // no meaningful lhs expression
+    return false;
+  }
+
+  int lhs_start = scan_over_whitespace(outstring,0);
+
+  // form lhs_expr from remainder of string
+  lhs_expr = extract_substr(outstring,lhs_start,lhs_end);
+
+  // Now we know we have a valid expression, look up any 
+  // metadata terms
+
+  rhs_expr = expand_potential_metadata(collection,collectproto,docinfo,
+				       disp,rhs_expr,options,logout);
+  lhs_expr = expand_potential_metadata(collection,collectproto,docinfo,
+				       disp,lhs_expr,options,logout);
+
+  return true;
+}
+
+static bool eval_expression_true(const text_t& lhs_expr,const text_t& op_expr,
+				 const text_t& rhs_expr, ostream& logout)
+{
+  if (op_expr == "eq") return (lhs_expr == rhs_expr);
+  else if (op_expr == "ne" ) return (lhs_expr != rhs_expr);
+  else if (op_expr == "gt") return (lhs_expr > rhs_expr);
+  else if (op_expr == "ge") return (lhs_expr >= rhs_expr);
+  else if (op_expr == "lt") return (lhs_expr < rhs_expr);
+  else if (op_expr == "le") return (lhs_expr <= rhs_expr);
+  else if (op_expr == "==") return (lhs_expr.getint() == rhs_expr.getint());
+  else if (op_expr == "!=") return (lhs_expr.getint() != rhs_expr.getint());
+  else if (op_expr == ">") return (lhs_expr.getint() > rhs_expr.getint());
+  else if (op_expr == ">=") return (lhs_expr.getint() >= rhs_expr.getint());
+  else if (op_expr == "<") return (lhs_expr.getint() < rhs_expr.getint());
+  else if (op_expr == "<=") return (lhs_expr.getint() <= rhs_expr.getint());
+  else if (op_expr == "sw") return (starts_with(lhs_expr,rhs_expr));
+  else if (op_expr == "ew") return (ends_with(lhs_expr,rhs_expr));
+  else {
+    logout << "Error: '" << op_expr << "' is not a recognised operator." << endl;
+  }
+  
+  return false;
+}
+
+
+static text_t get_if (const text_t& collection, recptproto* collectproto,
+		      ResultDocInfo_t &docinfo, displayclass &disp, 
+		      const decision_t &decision,
+		      format_t *ifptr, format_t *elseptr,
+		      text_tmap &options, ostream& logout) 
+{
+  // If the decision component is a metadata element, then evaluate it
+  // to see whether we output the "then" or the "else" clause
+  if (decision.command == dMeta) {
+    if (get_meta (collection,collectproto,docinfo,disp,decision.meta,options,
+		  logout) != "") {
+      if (ifptr != NULL)
+	return get_formatted_string (collection,collectproto,docinfo, disp, ifptr, 
+				     options, logout);
+    }
+    else {
+      if (elseptr != NULL)
+	return get_formatted_string (collection,collectproto,docinfo, disp, elseptr,
+				     options, logout);
+    }
+  }
+
+  // If the decision component is text, then evaluate it (it is probably a 
+  // macro like _cgiargmode_) to decide what to output.
+  else if (decision.command == dText) {
+
+    text_t outstring;
+    disp.expandstring (decision.text, outstring);
+
+    // Check for if expression in form: str1 op str2 
+    // (such as [x] eq "y")
+    text_t lhs_expr, op_expr, rhs_expr;
+    if (uses_expression(collection,collectproto,docinfo, disp, outstring,lhs_expr,op_expr,rhs_expr, options,logout)) {
+      if (eval_expression_true(lhs_expr,op_expr,rhs_expr,logout)) {
+	if (ifptr != NULL) {
+	  return get_formatted_string (collection, collectproto, docinfo, disp, ifptr, 
+				       options, logout);
+	}
+	else {
+	  return "";
+	}
+      } else {
+	if (elseptr != NULL) {
+	  return get_formatted_string (collection, collectproto, docinfo, disp, elseptr,
+				       options, logout);
+	}
+	else {
+	  return "";
+	}
+      }
+    }
+
+
+    // This is a tad tricky.  When we expand a string like _cgiargmode_, that is
+    // a cgi argument macro that has not been set, it evaluates to itself.
+    // Therefore, were have to say that a piece of text evalautes true if
+    // it is non-empty and if it is a cgi argument evaulating to itself.
+
+    if ((outstring != "") && !((outstring == decision.text) && (outstring[0] == '_'))) {
+      if (ifptr != NULL)
+	return get_formatted_string (collection, collectproto, docinfo, disp, ifptr, 
+				     options, logout);
+    } else {
+      if (elseptr != NULL)
+	return get_formatted_string (collection, collectproto, docinfo, disp, elseptr,
+				     options, logout);
+    }
+  }
+  
+  return "";
+}
+
+bool includes_metadata(const text_t& text)
+{
+  text_t::const_iterator here = text.begin();
+  text_t::const_iterator end = text.end();
+  while (here != end) {
+    if (*here == '[') return true;
+    ++here;
+  }
+
+  return false;
+}
+
+static text_t expand_metadata(const text_t &metavalue, const text_t& collection,
+			      recptproto* collectproto,
+			      ResultDocInfo_t &docinfo,
+			      displayclass &disp, text_tmap &options,
+			      ostream &logout) {
+      
+  if (includes_metadata(metavalue)) {
+    
+    // text has embedded metadata in it => expand it
+    FilterRequest_t request;
+    FilterResponse_t response;
+    
+    request.getParents = false;
+    
+    format_t *expanded_formatlistptr = new format_t();
+    parse_formatstring (metavalue, expanded_formatlistptr, 
+			request.fields, request.getParents);
+    
+    // retrieve metadata
+    get_info(docinfo.OID, collection, "", request.fields, request.getParents,
+	     collectproto, response, logout);
+    
+    if (!response.docInfo.empty()) {
+      
+      text_t expanded_metavalue
+	= get_formatted_string(collection, collectproto,
+			       response.docInfo[0], disp, expanded_formatlistptr, 
+			       options, logout);
+      
+      return expanded_metavalue;
+    }
+    else {
+      return metavalue;
+    }
+  }
+  else {
+    
+    return metavalue;
+  }
+}
+
+text_t get_collection_meta(const text_t& collection, recptproto* collectproto,
+			   displayclass &disp, 
+			   text_t meta_name, ostream& logout) {
+  
+  ColInfoResponse_t collectinfo;
+  comerror_t err;
+  collectproto->get_collectinfo (collection, collectinfo,err,logout);
+  text_t meta_value = "";
+  text_t lang;
+  disp.expandstring("_cgiargl_",lang);
+  if (lang.empty()) {
+    lang = "en";
+  }
+
+  if (err == noError) {
+    meta_value = collectinfo.get_collectionmeta(meta_name, lang);
+  }
+  return meta_value;
+  
+
+}
+text_t format_string (const text_t& collection, recptproto* collectproto,
+		      ResultDocInfo_t &docinfo, displayclass &disp, 
+		      format_t *formatlistptr, text_tmap &options,
+		      ostream& logout) {
+
+  if (formatlistptr == NULL) return "";
+
+  switch (formatlistptr->command) {
+     case comOID:
+	return docinfo.OID;
+  case comTopOID:
+    {
+      text_t top_id;
+      get_top(docinfo.OID, top_id);
+      return top_id;
+    }
+  case comRank:
+    return text_t(docinfo.ranking);
+     case comText:
+	return formatlistptr->text;
+     case comLink:
+	return options["link"];
+     case comEndLink:
+	if (options["link"].empty()) return "";
+	else return "</a>";
+     case comHref:
+	return get_href(options["link"]);
+     case comIcon:
+	return options["icon"];
+     case comNum:
+	return docinfo.result_num;
+     case comRel: //if [RelatedDocuments] appears in format string, collect relation data
+	return get_related_docs(collection, collectproto, docinfo, logout);
+     case comSummary:
+	return format_summary(collection, collectproto, docinfo, disp, options, logout);
+     case comMeta:
+	{
+	   const text_t& metavalue =  get_meta (collection,collectproto, docinfo, disp,formatlistptr->meta,options,logout);
+	   return expand_metadata(metavalue, collection, collectproto, docinfo, disp, options, logout);
+	}
+     case comDoc:
+	return format_text(collection, collectproto, docinfo, disp, options, logout);
+	//return options["text"];
+     case comImage:
+	return expand_metadata(options["DocImage"], collection, collectproto, docinfo, disp, options, logout);
+     case comTOC:
+	return options["DocTOC"];
+     case comDocumentButtonDetach:
+	return options["DocumentButtonDetach"];
+     case comDocumentButtonHighlight:
+	return options["DocumentButtonHighlight"];
+     case comDocumentButtonExpandContents:
+	return options["DocumentButtonExpandContents"];
+     case comDocumentButtonExpandText:
+	return options["DocumentButtonExpandText"];
+     case comHighlight:
+	if (options["highlight"] == "1") return "<b>";
+	break;
+     case comEndHighlight:
+	if (options["highlight"] == "1") return "</b>";
+	break;
+     case comIf:
+	return get_if (collection, collectproto, docinfo, disp, 
+		       formatlistptr->decision, formatlistptr->ifptr, 
+		       formatlistptr->elseptr, options, logout);
+     case comOr:
+	return get_or (collection,collectproto, docinfo, disp, formatlistptr->orptr, 
+		       options, logout);
+     case comCollection:
+       if (formatlistptr->meta.metaname == g_EmptyText) {
+	 return collection;
+       }
+       return get_collection_meta(collection, collectproto, disp, formatlistptr->meta.metaname, logout);
+    
+  }
+  return "";
+}
+
+text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
+			     ResultDocInfo_t &docinfo, displayclass &disp,
+			     format_t *formatlistptr, text_tmap &options,
+			     ostream& logout) {
+
+   text_t ft;
+   while (formatlistptr != NULL) 
+      {
+	 ft += format_string (collection, collectproto, docinfo, disp, formatlistptr, 
+			      options, logout);
+	 formatlistptr = formatlistptr->nextptr;
+      }
+   
+   return ft;
+}
+
+
+// we have only preloaded the text in DocumentAction. But you may want to get the text in query. so copy what we have done with format_summary and get the text here. probably is quite expensive?
+text_t format_text (const text_t& collection, recptproto* collectproto,
+		    ResultDocInfo_t &docinfo, displayclass &disp, 
+		    text_tmap &options, ostream& logout) {
+  if(!options["text"].empty()) { 
+    return options["text"];
+  }
+  // else get document text here
+  DocumentRequest_t docrequest;
+  DocumentResponse_t docresponse;
+  comerror_t err;
+  docrequest.OID = docinfo.OID;
+  collectproto->get_document (collection, docrequest, docresponse, err, logout);
+  return docresponse.doc;
+
+}
+  
+/* FUNCTION NAME: format_summary
+ * DESC: this is invoked when a [Summary] special metadata is processed.
+ * RETURNS: a query-biased summary for the document */
+
+text_t format_summary (const text_t& collection, recptproto* collectproto,
+		       ResultDocInfo_t &docinfo, displayclass &disp, 
+		       text_tmap &options, ostream& logout) {
+
+  // GRB: added code here to ensure that the cstr (and other collections)
+  //      uses the document metadata item Summary, rather than compressing
+  //      the text of the document, processed via the methods in
+  //      summarise.cpp
+  if (docinfo.metadata.count("Summary") > 0 &&
+      docinfo.metadata["Summary"].values.size() > 0) {
+    return docinfo.metadata["Summary"].values[0];
+  }
+
+  text_t textToSummarise, query;
+  if(options["text"].empty()) { // get document text
+     DocumentRequest_t docrequest;
+     DocumentResponse_t docresponse;
+     comerror_t err;
+     docrequest.OID = docinfo.OID;
+     collectproto->get_document (collection, docrequest, docresponse, err, logout);
+     textToSummarise = docresponse.doc;
+  } else // in practice, this would not happen, because text is only 
+         // loaded with the [Text] command
+     textToSummarise = options["text"];
+  disp.expandstring("_cgiargq_",query);
+  return summarise(textToSummarise,query,80);
+}
Index: /gsdl/trunk/runtime-src/src/recpt/formattools.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/formattools.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/formattools.h	(revision 16571)
@@ -0,0 +1,145 @@
+/**********************************************************************
+ *
+ * formattools.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef FORMATTOOLS_H
+#define FORMATTOOLS_H
+
+#include "text_t.h"
+#include "recptproto.h"
+#include "display.h"
+
+enum command_t {comIf, comOr, comMeta, comText, comLink, comEndLink, comNum, comIcon, 
+		comDoc, comHighlight, comEndHighlight, comRel, comHref, comSummary,
+		comTOC, comImage, comDocumentButtonDetach, comDocumentButtonHighlight,
+		comDocumentButtonExpandContents, comDocumentButtonExpandText, comOID, comTopOID, comRank, comCollection};
+
+enum mcommand_t {mNone=0, mCgiSafe=1, mParent=2, mSibling=4, mChild=8, mSpecial=16};
+
+enum pcommand_t {pNone, pImmediate, pTop, pAll};
+enum scommand_t {sNone, sAll, sNum};
+enum ccommand_t {cNone, cAll, cNum};
+enum dcommand_t {dMeta, dText};
+
+struct metadata_t {
+  void clear();
+  metadata_t () {clear();}
+
+  text_t metaname;
+  int metacommand; // used to hold flags from mcommand_t
+  struct {
+    pcommand_t parent;
+    scommand_t sibling;
+    ccommand_t child;
+  } mqualifier;
+
+  text_t parentoptions;
+  text_t siblingoptions;
+  text_t childoptions;
+};
+
+
+// The decision component of an {If}{decision,true-text,false-text}
+// formatstring.  The decision can be based on metadata or on text;
+// normally that text would be a macro like _cgiargmode_.  --gordon
+struct decision_t {
+  void clear();
+  decision_t () {clear();}
+
+  dcommand_t command;
+  metadata_t meta;
+  text_t text;
+};
+
+struct format_t {
+  void clear();
+  format_t () {clear();}
+
+  command_t command;
+  decision_t decision;
+  text_t text;
+  metadata_t meta;
+  format_t *nextptr;
+  format_t *ifptr;
+  format_t *elseptr;
+  format_t *orptr;
+};
+
+// the format structure used by this receptionist
+struct formatinfo_t {
+  void clear();
+  formatinfo_t () {clear();}
+
+  bool DocumentImages;
+  bool DocumentTitles;
+  text_t DocumentHeading;
+  bool DocumentContents;
+  bool DocumentArrowsBottom;
+  bool DocumentArrowsTop;
+  bool DocumentSearchResultLinks;
+  text_tarray DocumentButtons;
+  text_t DocumentText;
+  //-----------------
+  text_t RelatedDocuments;
+  //----------------
+  text_tmap formatstrings;
+  bool DocumentUseHTML;
+  bool AllowExtendedOptions;
+};
+
+bool is_table_content (const text_t &formatstring);
+bool is_table_content (const format_t *formatlistptr);
+
+bool get_formatstring (const text_t &key, const text_tmap &formatstringmap,
+		       text_t &formatstring);
+bool get_formatstring (const text_t &key1, const text_t &key2,  
+		       const text_tmap &formatstringmap,
+		       text_t &formatstring);
+
+text_t format_date (const text_t &date);
+
+text_t remove_namespace(const text_t &meta_name);
+
+text_t iso639 (const text_t &langcode);
+
+text_t get_href (const text_t &link);
+
+text_t get_related_docs(const text_t& collection, recptproto* collectproto,
+			  ResultDocInfo_t &docinfo, ostream& logout);
+
+
+bool parse_formatstring (const text_t &formatstring, format_t *formatlistptr, 
+			 text_tset &metadata, bool &getParents);
+
+
+
+text_t get_formatted_string (const text_t& collection, recptproto* collectproto,
+			     ResultDocInfo_t &docinfo, displayclass &disp,
+			     format_t *formatlistptr, text_tmap &options,
+			     ostream& logout);
+
+#endif
+
+
Index: /gsdl/trunk/runtime-src/src/recpt/gsdl_compatibility_cfg.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/gsdl_compatibility_cfg.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/gsdl_compatibility_cfg.h	(revision 16571)
@@ -0,0 +1,38 @@
+#ifndef GSDL_COMPATIBILITY_CFG__H
+#define GSDL_COMPATIBILITY_CFG__H
+
+/**********************************************************************
+ *
+ * gsdl_compatibility_cfg.h -- 
+ * Copyright (C) 2004  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+//OLD NAME	NEW NAME
+#define __USE_MULTILANGUAGE_INTERFACE_         GSDL_USE_MULTILANGUAGE_INTERFACE
+#define GSDL_USE_GENERATOR_FEATURE             GSDL_USE_GENERATOR_ACTION
+#define GSDL_USE_EXPORT_FEATURE                GSDL_USE_EXPORT_ACTION
+#define __USE_CLASSIFIER_BROWSER_              GSDL_USE_CLASSIFIER_BROWSER
+#define GSDL_USE_CLONEBROWSERCLASS             GSDL_USE_CLONE_BROWSER
+#define __SOURCE_DIRECTORY_                    GSDL_SOURCE_DIRECTORY
+
+
+#endif //!GSDL_COMPATIBILITY_CFG__H
Index: /gsdl/trunk/runtime-src/src/recpt/gsdl_modules_cfg.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/gsdl_modules_cfg.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/gsdl_modules_cfg.h	(revision 16571)
@@ -0,0 +1,90 @@
+#ifndef GSDL_MODULES_CFG__H
+#define GSDL_MODULES_CFG__H
+
+/**********************************************************************
+ *
+ * gsdl_modules_cfg.h -- 
+ * Copyright (C) 2004  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+// BASE CONFIG
+#define GSDL_USE_PER_COLLECTION_SETTINGS
+#define GSDL_SOURCE_DIRECTORY            "files"
+
+// FNORD CONFIG
+#define GSDL_USE_MULTILANGUAGE_INTERFACE
+
+//RECEPTIONIST CONFIG
+#define GSDL_USE_SESSIONS
+
+//QUERY CONFIG
+#define GSDL_USE_REMOVE_TAG_TERMS
+#undef  GSDL_USE_SAFEM_QUERY_FORMAT
+
+//DOCUMENT CONFIG
+// ONLY ONE GSDL_SKIP_* option can be enabled
+#define GSDL_SKIP_ONLY_EMPTY_DOC
+#undef  GSDL_SKIP_ALL_EMPTY_DOC_PARTS
+#undef  GSDL_USE_DOCUMENT_ASSOC_LANGS
+#define GSDL_USE_CL_SINGLE_DOCUMENT
+
+
+//ACTION MODULES
+#define GSDL_USE_AUTHEN_ACTION
+#define GSDL_USE_BROWSE_ACTION
+#define GSDL_USE_COLLECTOR_ACTION
+#define GSDL_USE_DEPOSITOR_ACTION
+#define GSDL_USE_EXTLINK_ACTION
+#undef  GSDL_USE_GTI_ACTION
+#define GSDL_USE_PHIND_ACTION
+#define GSDL_USE_PING_ACTION
+#define GSDL_USE_STATUS_ACTION
+#define GSDL_USE_TIP_ACTION
+#define GSDL_USE_USERS_ACTION
+
+#undef  GSDL_USE_CL_DISPLAY_ACTION
+#undef  GSDL_USE_COURSES_ACTION
+#undef  GSDL_USE_DIR_BROWSE_ACTION
+#undef  GSDL_USE_EXPORT_ACTION
+#undef  GSDL_USE_GENERATOR_ACTION
+#undef  GSDL_USE_INDEX_BROWSE_ACTION
+
+
+//BROWSER MODULES
+#undef  GSDL_USE_CLASSIFIER_BROWSER
+#undef  GSDL_USE_TREE_EX_CLASSIFIER_BROWSER
+#undef  GSDL_USE_CLONE_BROWSER
+#define GSDL_USE_DATELIST_BROWSER
+#define GSDL_USE_HTML_BROWSER
+#define GSDL_USE_PAGED_BROWSER
+#define GSDL_USE_PHIND_BROWSER
+
+//FILTERS
+#undef  GSDL_USE_DIR_BROWSEFILTER
+
+//BROWSERS ADD-IN
+#define GSDL_USE_BY_BOOK_MACROS
+#undef  GSDL_USE_FLOAT_TOC
+
+#include "gsdl_compatibility_cfg.h"
+
+#endif //!GSDL_MODULES_CFG__H
Index: /gsdl/trunk/runtime-src/src/recpt/gtiaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/gtiaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/gtiaction.cpp	(revision 16571)
@@ -0,0 +1,839 @@
+/**********************************************************************
+ *
+ * gtiaction.cpp -- 
+ * Copyright (C) 2005  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_GTI_ACTION
+
+
+#include <expat.h>
+#include <stdio.h>
+#include <sys/utsname.h>
+#include "gtiaction.h"
+#include "cgiutils.h"
+#include "fileutil.h"
+#include "gsdlunicode.h"
+
+
+
+gtiaction::gtiaction()
+{
+  cgiarginfo arg_ainfo;
+
+  arg_ainfo.shortname = "tlc";
+  arg_ainfo.longname = "translation target language code";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (&cerr, arg_ainfo);
+
+  arg_ainfo.shortname = "tfk";
+  arg_ainfo.longname = "translation file key";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (&cerr, arg_ainfo);
+
+  arg_ainfo.shortname = "ncpp";
+  arg_ainfo.longname = "number of chunks per page";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "1";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (&cerr, arg_ainfo);
+}
+
+
+
+gtiaction::~gtiaction()
+{
+  delete[] set_gsdlhome_cstr;
+  delete[] set_gsdlos_cstr;
+}
+
+
+
+bool gtiaction::init (ostream& /*logout*/)
+{
+  // Set GSDLHOME and GSDLOS environment variables
+  text_t set_gsdlhome = "GSDLHOME=" + gsdlhome;
+  text_t set_gsdlos = "GSDLOS=";
+
+#if defined (__WIN32__)
+  set_gsdlos += "windows";
+#else
+  struct utsname *buf = new struct utsname();
+  if (uname(buf) == -1) {
+    // uname failed, so this must be linux
+    set_gsdlos += "linux";
+  }
+  else {
+    text_t gsdlos = buf->sysname;
+    lc(gsdlos);
+    set_gsdlos += gsdlos;
+  }
+  delete buf;
+#endif
+
+  // These will be cleaned up in the destructor
+  set_gsdlhome_cstr = set_gsdlhome.getcstr();
+  set_gsdlos_cstr = set_gsdlos.getcstr();
+  putenv(set_gsdlhome_cstr);
+  putenv(set_gsdlos_cstr);
+
+  return true;
+}
+
+
+
+bool gtiaction::check_cgiargs(cgiargsinfoclass& /*argsinfo*/, cgiargsclass& args,
+			      recptprotolistclass* /*protos*/, ostream& logout)
+{
+  // Authenticate the user, except for the "home" and "lang" pages
+  if (args["p"] != "home" && args["p"] != "lang" && args["p"] != "status") {
+    args["uan"] = 1;
+    args["ug"] = "langadmin_" + args["tlc"];
+  }
+
+  return true;
+}
+
+
+
+bool gtiaction::do_action(cgiargsclass& args, recptprotolistclass* /*protos*/, 
+			  browsermapclass* /*browsers*/, displayclass& disp, 
+			  outconvertclass& outconvert, ostream& textout, 
+			  ostream& logout)
+{
+  // Special case for producing Excel spreadsheets, as these are downloaded
+  if (args["p"] == "excel") {
+    return produce_excel_spreadsheet(args, logout);
+  }
+
+  textout << outconvert << disp << ("_gti:header_\n") << ("_gti:content_\n") << ("_gti:footer_\n");
+  return true;
+}
+
+
+
+void gtiaction::get_cgihead_info(cgiargsclass& args, recptprotolistclass* /*protos*/,
+				 response_t& response, text_t& response_data, 
+				 ostream& logout)
+{
+  // Special case for producing Excel spreadsheets, as these are downloaded
+  if (args["p"] == "excel") {
+    printf("Content-Disposition: attachment; filename=\"Greenstone-%s-%s.xml\"\n", args["tlc"].getcstr(), args["tfk"].getcstr());
+    response = content;
+    response_data = "text/xml";
+    return;
+  }
+
+  response = content;
+  response_data = "text/html";
+}
+
+
+
+void gtiaction::define_internal_macros(displayclass& disp, cgiargsclass& args, 
+				       recptprotolistclass* protos, ostream& logout)
+{
+  // logout << endl << "Arguments: " << args << endl;
+  logout << endl << "CGI arg p: " << args["p"] << endl;
+
+  // For some reason this must be done as well as setting the macro in gti.dm
+  // is that still true??
+  disp.setmacro("preflink", displayclass::defaultpackage, "_gti:preflink_");
+  
+  // Define the page content for the GTI home page
+  if (args["p"] == "home") {
+    define_gti_home_page(disp, args, logout);
+    return;
+  }
+
+  // Define the page content for the GTI language page
+  if (args["p"] == "lang") {
+    define_gti_lang_page(disp, args, logout);
+    return;
+  }
+
+  // Define the page content for the GTI search page
+  if (args["p"] == "find") {
+    define_gti_find_page(disp, args, logout);
+    return;
+  }
+
+  // Define the page content for the GTI offline page
+  if (args["p"] == "offline") {
+    define_gti_offline_page(disp, args, logout);
+    return;
+  }
+  
+  // Define the page content for the GTI view status page
+	if (args["p"] == "status") {
+		define_gti_status_page(disp, args, logout);
+		return;
+	}
+
+  // Process user translations
+  if (args["p"] == "submit") {
+    process_gti_submissions(disp, args, logout, true);
+  }
+  	
+  // Define the page content for the GTI core pages (containing the translation input forms)
+  define_gti_core_page(disp, args, logout);
+}
+
+
+
+void gtiaction::define_gti_home_page(displayclass& disp, cgiargsclass& args, ostream& logout)
+{
+  disp.setmacro("gtiformcontent", "gti", "_gti:gtihome_");
+
+  languageinfo_tmap loaded_languages = recpt->get_configinfo().languages;
+
+  // Get the languages specified in the main.cfg file, and put them into a map to sort by name
+  text_tmap gti_languages_name_code_mapping;
+  languageinfo_tmap::const_iterator loaded_language = loaded_languages.begin();
+  while (loaded_language != loaded_languages.end()) {
+    // English is not a valid GTI target language, since it is the source language
+    if (loaded_language->first != "en") {
+      gti_languages_name_code_mapping[loaded_language->second.longname] = loaded_language->first;
+    }
+    ++loaded_language;
+  }
+
+  // Set the gtitlcselection macro
+  text_t gti_tlc_selection = "<select name=\"tlc\">\n";
+  text_tmap::iterator gti_language = gti_languages_name_code_mapping.begin();
+  while (gti_language != gti_languages_name_code_mapping.end()) {
+    gti_tlc_selection += "<option value=\"" + gti_language->second + "\">" + gti_language->first + "</option>\n";
+    ++gti_language;
+  }
+  gti_tlc_selection += "</select>";
+  disp.setmacro("gtitlcselection", "gti", gti_tlc_selection);
+}
+
+
+
+void gtiaction::define_gti_lang_page(displayclass& disp, cgiargsclass& args, ostream& logout)
+{
+  // Get the target language code from the CGI arguments
+  text_t target_language_code = args["tlc"];
+
+  disp.setmacro("gtiformcontent", "gti", "_gti:gtilang_");
+
+  // Send a request to gti.pl to get the valid translation files
+  text_t gti_arguments = "get-language-status " + target_language_code;
+  GTI_Response gti_response = parse_gti_response(do_gti_request(gti_arguments, logout), logout);
+  if (gti_response.error_message != "") {
+    // An error has occurred
+    disp.setmacro("gtiformcontent", "gti", "_gti:gtierror_");
+    disp.setmacro("gtierrormessage", "gti", gti_response.error_message);
+    return;
+  }
+
+  languageinfo_tmap loaded_languages = recpt->get_configinfo().languages;
+  disp.setmacro("gtitargetlanguagename", "gti", loaded_languages[target_language_code].longname);
+
+  // Set the gtitfkselection macro
+  text_t gti_tfk_selection = "<table>";
+  text_tmap::iterator translation_file = gti_response.translation_files_index_to_key_mapping.begin();
+  while (translation_file != gti_response.translation_files_index_to_key_mapping.end()) {
+    text_t translation_file_key = translation_file->second;
+
+    gti_tfk_selection += "<tr><td>";
+    gti_tfk_selection += "<input type=\"radio\" name=\"tfk\" value=\"" + translation_file_key + "\"></td>\n";
+    gti_tfk_selection += "<td>_textgti" + translation_file_key + "_</td></tr>\n";
+
+    text_t num_chunks_translated = gti_response.translation_files_key_to_num_chunks_translated_mapping[translation_file_key];
+    text_t num_chunks_requiring_translation = gti_response.translation_files_key_to_num_chunks_requiring_translation_mapping[translation_file_key];
+    text_t num_chunks_requiring_updating = gti_response.translation_files_key_to_num_chunks_requiring_updating_mapping[translation_file_key];
+    gti_tfk_selection += "<tr><td></td><td>_gtitranslationfilestatus_(" + num_chunks_translated + "," + num_chunks_requiring_translation + "," + num_chunks_requiring_updating + ")</td></tr>\n";
+    ++translation_file;
+  }
+  gti_tfk_selection += "</table>";
+  disp.setmacro("gtitfkselection", "gti", gti_tfk_selection);
+}
+
+
+
+void gtiaction::define_gti_status_page(displayclass& disp, cgiargsclass& args, ostream& logout)
+{
+  disp.setmacro("gtiformcontent", "gti", "_gti:gtistatus_");
+
+  languageinfo_tmap loaded_languages = recpt->get_configinfo().languages;
+
+  // Get the languages specified in the main.cfg file, and put them into a map to sort by name
+  text_tmap gti_languages_name_code_mapping;
+  languageinfo_tmap::const_iterator loaded_language = loaded_languages.begin();
+  while (loaded_language != loaded_languages.end()) {
+    // English is not a valid GTI target language, since it is the source language
+    if (loaded_language->first != "en") {
+      gti_languages_name_code_mapping[loaded_language->second.longname] = loaded_language->first;
+    }
+    ++loaded_language;
+  }
+
+  // Get the languages, for each language, send a request to gti.pl to get the valid translation files and the current status for each file
+  text_t gti_status_table = "<table class=\"status\">\n";
+  text_tmap::iterator gti_language = gti_languages_name_code_mapping.begin();
+  bool first_lang = true;
+  while (gti_language != gti_languages_name_code_mapping.end()) {    
+    // Send a request to gti.pl to get the valid translation files
+    text_t gti_arguments = "get-language-status " + gti_language->second;
+    GTI_Response gti_response = parse_gti_response(do_gti_request(gti_arguments, logout), logout);
+    if (gti_response.error_message != "") {
+      // An error has occurred
+      disp.setmacro("gtiformcontent", "gti", "_gti:gtierror_");
+      disp.setmacro("gtierrormessage", "gti", gti_response.error_message);
+      return;
+    }
+
+    text_tmap::iterator translation_file = gti_response.translation_files_index_to_key_mapping.begin();
+        
+    text_t lang_status_temp = "<tr><td class=\"first\">" + gti_language->first + "</td>\n";
+    text_t files_temp = "<tr><th class=\"status\">_textgtilanguage_</th>\n";
+    text_t number_of_strings_temp = "<tr><td class=\"first\"><b>_textgtitotalnumberoftranslations_</b></td>\n";
+    
+    while (translation_file != gti_response.translation_files_index_to_key_mapping.end()) {
+      text_t translation_file_key = translation_file->second;                     
+
+      text_t num_chunks_translated = gti_response.translation_files_key_to_num_chunks_translated_mapping[translation_file_key];
+      text_t num_chunks_requiring_translation = gti_response.translation_files_key_to_num_chunks_requiring_translation_mapping[translation_file_key];
+    	text_t num_chunks_requiring_updating = gti_response.translation_files_key_to_num_chunks_requiring_updating_mapping[translation_file_key];   		
+    	
+    	lang_status_temp += "<td class=\"status\">";
+    	if(num_chunks_translated.getint() > 0){
+    		lang_status_temp += "<div class=\"nowrap\"><div class=\"done\">";
+    		lang_status_temp += num_chunks_translated+"</div><div class=\"plus\">+</div><div class=\"update\">";
+  	  	lang_status_temp += num_chunks_requiring_updating+"</div><div class=\"plus\">+</div><div class=\"todo\">";
+  	  	lang_status_temp += num_chunks_requiring_translation+"</div></div>";
+    	}
+    	lang_status_temp += "</td>\n";
+    	
+    	
+   		//lang_status_temp += "<td valign=\"top\" nowrap>_gtitranslationfilestatus2_(" + num_chunks_translated + "," + num_chunks_requiring_translation + "," + num_chunks_requiring_updating + ")</td>";   		
+   		
+   		// List the file names as the first row of the status table 
+   		// Add up number of strings need to be translate in each file, as the second line of the status table
+      if (first_lang) {
+        files_temp += "<th class=\"status\">_textgti" + translation_file_key + "_</th>\n";
+        int int_number_of_strings = num_chunks_translated.getint() + num_chunks_requiring_translation.getint();
+        number_of_strings_temp += "<td class=\"status\"><b>";
+        number_of_strings_temp.appendint(int_number_of_strings);
+        number_of_strings_temp += "</b></td>\n";
+      }
+    	++translation_file;
+    }    
+    
+    if(first_lang) {     
+     gti_status_table += files_temp + "</tr>" + number_of_strings_temp + "</tr>";   
+     first_lang = false;
+    }
+    
+    gti_status_table += lang_status_temp + "</tr>";    
+    ++gti_language;
+  }
+  gti_status_table += "\n</table>";
+  disp.setmacro("gtistatustable", "gti", gti_status_table);
+}
+
+
+
+void gtiaction::define_gti_find_page(displayclass& disp, cgiargsclass& args, ostream& logout)
+{
+  // Get the target language code and file to translate from the CGI arguments
+  text_t target_language_code = args["tlc"];
+  text_t translation_file_key = args["tfk"];
+  text_t query_string = to_utf8(args["q"]);
+
+  // Process user corrections
+  if (args["sp"] != "") {
+    process_gti_submissions(disp, args, logout, false);
+  }
+
+  disp.setmacro("gtiformcontent", "gti", "_gti:gtifind_");
+
+  languageinfo_tmap loaded_languages = recpt->get_configinfo().languages;
+  disp.setmacro("gtitargetlanguagename", "gti", loaded_languages[target_language_code].longname);
+  disp.setmacro("gtitranslationfiledesc", "gti", "_gti:textgti" + translation_file_key + "_");
+
+  if (query_string == "") {
+    // No query, so no search results
+    disp.setmacro("gtifindformcontent", "gti", "");
+    return;
+  }
+
+  // Display text right to left if target language is Arabic or Farsi or Urdu
+  if (target_language_code == "ar" || target_language_code == "fa" || target_language_code == "ur") {
+    disp.setmacro("gtitextdirection", "gti", "rtl");
+  }
+  else {
+    disp.setmacro("gtitextdirection", "gti", "ltr");
+  }
+
+  // Send a request to gti.pl to get the valid translation files
+  logout << "Query argument: " << query_string << endl;
+  text_t gti_arguments = "search-chunks " + target_language_code + " " + translation_file_key + " " + query_string;
+  GTI_Response gti_response = parse_gti_response(do_gti_request(gti_arguments, logout), logout);
+  if (gti_response.error_message != "") {
+    // An error has occurred
+    disp.setmacro("gtiformcontent", "gti", "_gti:gtierror_");
+    disp.setmacro("gtierrormessage", "gti", gti_response.error_message);
+    return;
+  }
+
+  disp.setmacro("gtinumchunksmatchingquery", "gti", gti_response.num_chunks_matching_query);
+
+  // Loop through the chunks returned, displaying them on the page
+  text_t gti_find_form_content = "_gtifindformheader_\n";
+  text_tmap::iterator chunk_key_iterator = gti_response.target_file_chunks_key_to_text_mapping.begin();
+  while (chunk_key_iterator != gti_response.target_file_chunks_key_to_text_mapping.end()) {
+    text_t chunk_key = chunk_key_iterator->first;
+
+    // Need to escape any underscores in the chunk key to show it correctly on the page
+    text_t chunk_key_escaped = escape_all(chunk_key, '_');
+
+    // Need to escape any backslashes, underscores, commas, parentheses, and single quotes in the chunk text
+    text_t target_file_chunk_text = gti_response.target_file_chunks_key_to_text_mapping[chunk_key];
+    text_t target_file_chunk_text_escaped = escape_all(target_file_chunk_text, '\\');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, '_');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, ',');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, '(');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, ')');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, '"');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, '\'');
+
+    // This chunk matches the query
+    gti_find_form_content += "_gtichunkmatchingquery_(" + chunk_key_escaped + "," + target_file_chunk_text_escaped + ")\n";
+
+    chunk_key_iterator++;
+  }
+  gti_find_form_content += "_gtifindformfooter_\n";
+
+  disp.setmacro("gtifindformcontent", "gti", gti_find_form_content);
+}
+
+
+
+void gtiaction::define_gti_offline_page(displayclass& disp, cgiargsclass& args, ostream& logout)
+{
+  // Get the target language code and file to translate from the CGI arguments
+  text_t target_language_code = args["tlc"];
+  text_t translation_file_key = args["tfk"];
+
+  disp.setmacro("gtiformcontent", "gti", "_gti:gtioffline_");
+
+  languageinfo_tmap loaded_languages = recpt->get_configinfo().languages;
+  disp.setmacro("gtitargetlanguagename", "gti", loaded_languages[target_language_code].longname);
+  disp.setmacro("gtitranslationfiledesc", "gti", "_gti:textgti" + translation_file_key + "_");
+}
+
+
+
+void gtiaction::define_gti_core_page(displayclass& disp, cgiargsclass& args, ostream& logout)
+{
+  // Get the target language code and file to translate from the CGI arguments
+  text_t target_language_code = args["tlc"];
+  text_t translation_file_key = args["tfk"];
+  text_t num_chunks_per_page = args["ncpp"];
+  logout << "Num chunks per page: " << num_chunks_per_page << endl;
+
+  disp.setmacro("gtiformcontent", "gti", "_gti:gticore_");
+
+  // Display text right to left if target language is Arabic or Farsi or Urdu
+  if (target_language_code == "ar" || target_language_code == "fa" || target_language_code == "ur") {
+    disp.setmacro("gtitextdirection", "gti", "rtl");
+  }
+  else {
+    disp.setmacro("gtitextdirection", "gti", "ltr");
+  }
+
+  // Send a request to gti.pl to get the first string to translate
+  text_t gti_arguments = "get-first-n-chunks-requiring-work " + target_language_code + " " + translation_file_key + " " + num_chunks_per_page;
+  GTI_Response gti_response = parse_gti_response(do_gti_request(gti_arguments, logout), logout);
+  if (gti_response.error_message != "") {
+    // An error has occurred
+    disp.setmacro("gtiformcontent", "gti", "_gti:gtierror_");
+    disp.setmacro("gtierrormessage", "gti", gti_response.error_message);
+    return;
+  }
+
+  languageinfo_tmap loaded_languages = recpt->get_configinfo().languages;
+  disp.setmacro("gtitargetlanguagename", "gti", loaded_languages[target_language_code].longname);
+  disp.setmacro("gtitargetfilepath", "gti", gti_response.translation_files_key_to_target_file_path_mapping[translation_file_key]);
+  disp.setmacro("gtitranslationfiledesc", "gti", "_gti:textgti" + translation_file_key + "_");
+  disp.setmacro("gtiviewtranslationfileinaction", "gti", "_gti:gtiview" + translation_file_key + "inaction_");
+
+  disp.setmacro("gtinumchunkstranslated", "gti", gti_response.translation_files_key_to_num_chunks_translated_mapping[translation_file_key]);
+  disp.setmacro("gtinumchunksrequiringtranslation", "gti", gti_response.translation_files_key_to_num_chunks_requiring_translation_mapping[translation_file_key]);
+  disp.setmacro("gtinumchunksrequiringupdating", "gti", gti_response.translation_files_key_to_num_chunks_requiring_updating_mapping[translation_file_key]);
+
+  // Check if the translation file is finished
+  if (gti_response.translation_files_key_to_num_chunks_requiring_translation_mapping[translation_file_key] == "0" && gti_response.translation_files_key_to_num_chunks_requiring_updating_mapping[translation_file_key] == "0") {
+    disp.setmacro("gtiformcontent", "gti", "_gti:gtidone_");
+    return;
+  }
+
+  // Loop through the chunks returned, displaying them on the page
+  text_t gti_core_form_content = "";
+  text_tmap::iterator chunk_key_iterator = gti_response.source_file_chunks_key_to_text_mapping.begin();
+  while (chunk_key_iterator != gti_response.source_file_chunks_key_to_text_mapping.end()) {
+    text_t chunk_key = chunk_key_iterator->first;
+
+    // Need to escape any underscores in the chunk key to show it correctly on the page
+    text_t chunk_key_escaped = escape_all(chunk_key, '_');
+
+    // Need to escape any backslashes, underscores, commas, parentheses, and single quotes in the chunk text
+    text_t source_file_chunk_text = gti_response.source_file_chunks_key_to_text_mapping[chunk_key];
+    text_t source_file_chunk_text_escaped = escape_all(source_file_chunk_text, '\\');
+    source_file_chunk_text_escaped = escape_all(source_file_chunk_text_escaped, '_');
+    source_file_chunk_text_escaped = escape_all(source_file_chunk_text_escaped, ',');
+    source_file_chunk_text_escaped = escape_all(source_file_chunk_text_escaped, '(');
+    source_file_chunk_text_escaped = escape_all(source_file_chunk_text_escaped, ')');
+    source_file_chunk_text_escaped = escape_all(source_file_chunk_text_escaped, '\'');
+    text_t target_file_chunk_text = gti_response.target_file_chunks_key_to_text_mapping[chunk_key];
+    text_t target_file_chunk_text_escaped = escape_all(target_file_chunk_text, '\\');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, '_');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, ',');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, '(');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, ')');
+    target_file_chunk_text_escaped = escape_all(target_file_chunk_text_escaped, '\'');
+
+    text_t source_file_chunk_date = gti_response.source_file_chunks_key_to_date_mapping[chunk_key];
+    text_t target_file_chunk_date = gti_response.target_file_chunks_key_to_date_mapping[chunk_key];
+
+    // This chunk requires translation
+    if (target_file_chunk_text == "") {
+      gti_core_form_content += "_gtichunkrequiringtranslation_(" + chunk_key_escaped + "," + source_file_chunk_text_escaped + "," + source_file_chunk_date + ")\n";
+    }
+    // This chunk requires updating
+    else {
+      gti_core_form_content += "_gtichunkrequiringupdating_(" + chunk_key_escaped + "," + source_file_chunk_text_escaped + "," + source_file_chunk_date + "," + target_file_chunk_text_escaped + "," + target_file_chunk_date + ")\n";
+    }
+
+    chunk_key_iterator++;
+  }
+
+  disp.setmacro("gticoreformcontent", "gti", gti_core_form_content);
+}
+
+
+
+void gtiaction::process_gti_submissions(displayclass& disp, cgiargsclass& args, ostream& logout, bool force_submission)
+{
+  // Get the target language code and file to translate from the CGI arguments
+  text_t target_language_code = args["tlc"];
+  text_t translation_file_key = args["tfk"];
+  text_t submitter_username = args["un"];
+
+  // Submitted chunk arguments contain the language code followed by "::"
+  char* source_chunk_key_start_cstr = ((text_t) "en" + "%3A%3A").getcstr();
+  char* target_chunk_key_start_cstr = (target_language_code + "%3A%3A").getcstr();
+
+  // Find the cgi arguments with submitted chunk information
+  text_t submission_text;
+  cgiargsclass::const_iterator cgi_argument = args.begin();
+  while (cgi_argument != args.end()) {
+    char* cgi_argument_name_cstr = cgi_argument->first.getcstr();
+
+    // Source file text
+    if (strncmp(cgi_argument_name_cstr, source_chunk_key_start_cstr, strlen(source_chunk_key_start_cstr)) == 0) {
+      submission_text += "<SourceFileText key=\"";
+      text_t source_key = &cgi_argument_name_cstr[strlen(source_chunk_key_start_cstr)];
+      decode_cgi_arg(source_key);
+      submission_text += source_key;
+      //submission_text += &cgi_argument_name_cstr[strlen(source_chunk_key_start_cstr)];
+      submission_text += "\">\n";
+
+      text_t source_value = xml_safe(decode_commas(args[cgi_argument->first]));
+      // if (args["w"] != "utf-8") {
+      // source_value = to_utf8(source_value);
+      // }
+      submission_text += source_value + "\n";
+      submission_text += "</SourceFileText>\n";
+    }
+    // Target file text
+    if (strncmp(cgi_argument_name_cstr, target_chunk_key_start_cstr, strlen(target_chunk_key_start_cstr)) == 0) {
+      submission_text += "<TargetFileText key=\"";
+      text_t target_key = &cgi_argument_name_cstr[strlen(target_chunk_key_start_cstr)];
+      decode_cgi_arg(target_key);
+      submission_text += target_key;
+      //submission_text += &cgi_argument_name_cstr[strlen(target_chunk_key_start_cstr)];
+      submission_text += "\">\n";
+
+      text_t target_value = xml_safe(decode_commas(args[cgi_argument->first]));
+      // if (args["w"] != "utf-8") {
+      // target_value = to_utf8(target_value);
+      // }
+      submission_text += target_value + "\n";
+      submission_text += "</TargetFileText>\n";
+    }
+
+    delete[] cgi_argument_name_cstr;
+    ++cgi_argument;
+  }
+
+  logout << "Submission text: " << submission_text << endl;
+
+  // Send the submission to gti.pl
+  text_t gti_arguments = "submit-translations " + target_language_code + " " + translation_file_key + " " + submitter_username;
+  if (force_submission) {
+    gti_arguments += " -force_submission";
+  }
+  do_gti_submission(gti_arguments, submission_text, logout);
+  logout << "Done." << endl;
+
+  delete[] source_chunk_key_start_cstr;
+  delete[] target_chunk_key_start_cstr;
+}
+
+
+
+bool gtiaction::produce_excel_spreadsheet(cgiargsclass& args, ostream& logout)
+{
+  // Get the target language code and file to translate from the CGI arguments
+  text_t target_language_code = args["tlc"];
+  text_t translation_file_key = args["tfk"];
+
+  // Send a request to gti.pl to get the Excel spreadsheet data
+  text_t gti_arguments = "get-first-n-chunks-requiring-work " + target_language_code + " " + translation_file_key + " " + "10000" + " | java -cp /home/nzdl/gti ApplyXSLT /home/nzdl/gti/gti-generate-excel-xml.xsl -";
+  text_t gti_response_xml_text = do_gti_request(gti_arguments, logout);
+  if (gti_response_xml_text == "") {
+    // An error has occurred
+    return false;
+  }
+
+  // Write the Excel spreadsheet data to the browser
+  char* gti_response_xml_text_cstr = gti_response_xml_text.getcstr();
+  printf(gti_response_xml_text_cstr);
+  delete[] gti_response_xml_text_cstr;
+
+  return true;
+}
+
+
+
+text_t gtiaction::escape_all(text_t text_string, char character_to_escape)
+{
+  text_t text_string_escaped = "";
+
+  text_t::iterator text_string_character = text_string.begin();
+  while (text_string_character != text_string.end()) {
+    if (*text_string_character == character_to_escape) {
+      text_string_escaped += "\\";
+    }
+    text_string_escaped.push_back(*text_string_character);
+    text_string_character++;
+  }
+
+  return text_string_escaped;
+}
+
+
+
+text_t gtiaction::xml_safe(const text_t &text_string)
+{
+  text_t text_string_safe;
+  text_t::const_iterator here = text_string.begin();
+  text_t::const_iterator end = text_string.end();
+  while (here != end) {
+    if (*here == '&') text_string_safe += "&amp;";
+    else if (*here == '<') text_string_safe += "&lt;";
+    else if (*here == '>') text_string_safe += "&gt;";
+    else text_string_safe.push_back(*here);
+    ++here;
+  }
+
+  return text_string_safe;
+}
+
+
+
+char* xml_get_attribute(const char** attributes, char* attribute_name)
+{
+  for (int i = 0; (attributes[i] != NULL); i += 2) {
+    if (strcmp(attribute_name, attributes[i]) == 0) {
+      return strdup(attributes[i+1]);
+    }
+  }
+
+  return NULL;
+}
+
+
+static void XMLCALL gti_response_xml_start_element(void* user_data, const char* element_name_cstr, const char** attributes)
+{
+  GTI_Response* gti_response = (GTI_Response*) user_data;
+  text_t element_name = element_name_cstr;
+  cerr << "In startElement() for " << element_name << endl;
+
+  if (element_name == "GTIError") {
+    gti_response->recorded_text = "";
+    gti_response->is_recording_text = true;
+  }
+
+  if (element_name == "TranslationFile") {
+    int translation_file_index = gti_response->translation_files_index_to_key_mapping.size();
+    gti_response->translation_file_key = xml_get_attribute(attributes, "key");
+    gti_response->translation_files_index_to_key_mapping[translation_file_index] = gti_response->translation_file_key;
+    gti_response->translation_files_key_to_target_file_path_mapping[gti_response->translation_file_key] = xml_get_attribute(attributes, "target_file_path");
+    gti_response->translation_files_key_to_num_chunks_translated_mapping[gti_response->translation_file_key] = xml_get_attribute(attributes, "num_chunks_translated");
+    gti_response->translation_files_key_to_num_chunks_requiring_translation_mapping[gti_response->translation_file_key] = xml_get_attribute(attributes, "num_chunks_requiring_translation");
+    gti_response->translation_files_key_to_num_chunks_requiring_updating_mapping[gti_response->translation_file_key] = xml_get_attribute(attributes, "num_chunks_requiring_updating");
+  }
+
+  if (element_name == "ChunksMatchingQuery") {
+    gti_response->num_chunks_matching_query = xml_get_attribute(attributes, "size");
+  }
+
+  if (element_name == "Chunk") {
+    gti_response->chunk_key = xml_get_attribute(attributes, "key");
+  }
+
+  if (element_name == "SourceFileText") {
+    gti_response->source_file_chunks_key_to_date_mapping[gti_response->chunk_key] = xml_get_attribute(attributes, "date");
+    gti_response->recorded_text = "";
+    gti_response->is_recording_text = true;
+  }
+
+  if (element_name == "TargetFileText") {
+    if (xml_get_attribute(attributes, "date") != NULL) {
+      gti_response->target_file_chunks_key_to_date_mapping[gti_response->chunk_key] = xml_get_attribute(attributes, "date");
+    }
+    gti_response->recorded_text = "";
+    gti_response->is_recording_text = true;
+  }
+}
+
+
+static void XMLCALL gti_response_xml_end_element(void* user_data, const char* element_name_cstr)
+{
+  GTI_Response* gti_response = (GTI_Response*) user_data;
+  text_t element_name = element_name_cstr;
+
+  if (element_name == "GTIError") {
+    gti_response->error_message = to_uni(gti_response->recorded_text);
+    gti_response->is_recording_text = false;
+  }
+
+  if (element_name == "SourceFileText") {
+    gti_response->source_file_chunks_key_to_text_mapping[gti_response->chunk_key] = to_uni(gti_response->recorded_text);
+    gti_response->is_recording_text = false;
+  }
+
+  if (element_name == "TargetFileText") {
+    gti_response->target_file_chunks_key_to_text_mapping[gti_response->chunk_key] = to_uni(gti_response->recorded_text);
+    gti_response->is_recording_text = false;
+  }
+}
+
+
+static void XMLCALL gti_response_xml_character_data(void *user_data, const char* text_cstr, int text_length)
+{
+  GTI_Response* gti_response = (GTI_Response*) user_data;
+  if (gti_response->is_recording_text) {
+    gti_response->recorded_text.appendcarr(text_cstr, text_length);
+  }
+}
+
+
+
+text_t gtiaction::do_gti_request(text_t gti_arguments, ostream& logout)
+{
+  // Send the request to gti.pl and read the XML output
+  text_t gti_command = "perl -S " + filename_cat(gsdlhome, "bin", "script", "gti.pl") + " " + gti_arguments;
+  char* gti_command_cstr = gti_command.getcstr();
+  FILE *gti_pipe = popen(gti_command_cstr, "r");
+  delete[] gti_command_cstr;
+  if (gti_pipe == NULL) {
+    logout << "Error: Could not open pipe for GTI command " << gti_command << endl;
+    return "";
+  }
+
+  // Read the gti.pl response
+  text_t gti_response_xml_text;
+  while (!feof(gti_pipe)) {
+    char buffer[1024];
+    gti_response_xml_text.appendcarr(buffer, fread(buffer, 1, 1024, gti_pipe));
+  }
+  pclose(gti_pipe);
+
+  return gti_response_xml_text;
+}
+
+
+
+GTI_Response gtiaction::parse_gti_response(text_t gti_response_xml_text, ostream& logout)
+{
+  GTI_Response gti_response;
+  gti_response.is_recording_text = false;
+
+  // Parse the gti.pl response (XML)
+  logout << "Parsing GTI command response: " << gti_response_xml_text << endl;
+  XML_Parser xml_parser = XML_ParserCreate(NULL);
+  XML_SetUserData(xml_parser, &gti_response);
+  XML_SetElementHandler(xml_parser, gti_response_xml_start_element, gti_response_xml_end_element);
+  XML_SetCharacterDataHandler(xml_parser, gti_response_xml_character_data);
+
+  char* gti_response_xml_text_cstr = gti_response_xml_text.getcstr();
+  int parse_status = XML_Parse(xml_parser, gti_response_xml_text_cstr, strlen(gti_response_xml_text_cstr), XML_TRUE);
+  delete[] gti_response_xml_text_cstr;
+  if (parse_status == XML_STATUS_ERROR) {
+    logout << "Parse error " << XML_ErrorString(XML_GetErrorCode(xml_parser)) << " at line " << XML_GetCurrentLineNumber(xml_parser) << endl;
+    return gti_response;
+  }
+
+  XML_ParserFree(xml_parser);
+
+  logout << "Finished parse." << endl;
+  return gti_response;
+}
+
+
+
+void gtiaction::do_gti_submission(text_t gti_arguments, text_t gti_submission, ostream& logout)
+{
+  // Send the submission to gti.pl
+  text_t gti_command = "perl -S " + filename_cat(gsdlhome, "bin", "script", "gti.pl") + " " + gti_arguments;
+  char* gti_command_cstr = gti_command.getcstr();
+  FILE *gti_pipe = popen(gti_command_cstr, "w");
+  delete[] gti_command_cstr;
+  if (gti_pipe == NULL) {
+    logout << "Error: Could not open pipe for GTI command " << gti_command << endl;
+    return;
+  }
+
+  // Write the gti.pl submission
+  char* gti_submission_cstr = gti_submission.getcstr();
+  fwrite(gti_submission_cstr, 1, strlen(gti_submission_cstr), gti_pipe);
+  delete[] gti_submission_cstr;
+
+  pclose(gti_pipe);
+}
+
+
+
+#endif  // GSDL_USE_GTI_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/gtiaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/gtiaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/gtiaction.h	(revision 16571)
@@ -0,0 +1,125 @@
+/**********************************************************************
+ *
+ * gtiaction.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef GTIACTION_H
+#define GTIACTION_H
+
+
+#include "action.h"
+#include "receptionist.h"
+
+
+
+struct GTI_Response
+{
+  text_t translation_file_key;
+  text_tmap translation_files_index_to_key_mapping;
+  text_tmap translation_files_key_to_num_chunks_translated_mapping;
+  text_tmap translation_files_key_to_num_chunks_requiring_translation_mapping;
+  text_tmap translation_files_key_to_num_chunks_requiring_updating_mapping;
+  text_tmap translation_files_key_to_target_file_path_mapping;
+
+  text_t chunk_key;
+  text_tmap source_file_chunks_key_to_text_mapping;
+  text_tmap source_file_chunks_key_to_date_mapping;
+
+  // For chunks requiring updating
+  text_tmap target_file_chunks_key_to_text_mapping;
+  text_tmap target_file_chunks_key_to_date_mapping;
+
+  text_t num_chunks_matching_query;
+
+  bool is_recording_text;
+  text_t recorded_text;
+
+  text_t error_message;
+};
+
+
+class gtiaction : public action {
+
+protected:
+  receptionist *recpt;
+
+  char* set_gsdlhome_cstr;
+  char* set_gsdlos_cstr;
+
+public:
+  gtiaction ();
+  virtual ~gtiaction ();
+
+  void set_receptionist (receptionist *therecpt) {recpt=therecpt;}
+
+  text_t get_action_name () {return "gti";}
+
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass *protos, ostream &logout);
+
+  void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response,text_t &response_data, 
+			 ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+  bool init (ostream & /*logout*/);
+
+
+  // The interesting functions
+  void define_gti_home_page(displayclass& disp, cgiargsclass& args, ostream& logout);
+
+  void define_gti_lang_page(displayclass& disp, cgiargsclass& args, ostream& logout);
+
+  void define_gti_find_page(displayclass& disp, cgiargsclass& args, ostream& logout);
+
+  void define_gti_offline_page(displayclass& disp, cgiargsclass& args, ostream& logout);
+
+  void define_gti_core_page(displayclass& disp, cgiargsclass& args, ostream& logout);
+
+  text_t escape_all(text_t source_string, char character_to_escape);
+
+  text_t xml_safe(const text_t &text_string);
+
+  void process_gti_submissions(displayclass& disp, cgiargsclass& args, ostream& logout, bool force_submission);
+
+  text_t do_gti_request(text_t gti_arguments, ostream& logout);
+
+  GTI_Response parse_gti_response(text_t gti_response_xml_text, ostream& logout);
+
+  void do_gti_submission(text_t gti_arguments, text_t gti_submission, ostream& logout);
+
+  void define_gti_status_page(displayclass& disp, cgiargsclass& args, ostream& logout);
+
+  bool produce_excel_spreadsheet(cgiargsclass& args, ostream& logout);
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/highlighttext.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/highlighttext.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/highlighttext.cpp	(revision 16571)
@@ -0,0 +1,288 @@
+/**********************************************************************
+ *
+ * highlighttext.cpp -- 
+ * Copyright (C) 2002   D L Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "highlighttext.h"
+#include "unitool.h"
+
+
+static void highlight_terms(const text_t &text, const TermInfo_tarray &terms, const text_t &shl,
+			    const text_t &ehl, displayclass &disp, outconvertclass &outconvert,
+			    ostream &textout);
+
+static void highlight_phrases(const text_t &text, const text_t &querystring, const TermInfo_tarray &terms, 
+			      const text_t &shl, const text_t &ehl, displayclass &disp, 
+			      outconvertclass &outconvert, ostream &textout);
+
+static void get_phrase_terms (const text_t &querystring, text_tarray &phrase_terms);
+
+static void remove_space (text_t &qstring);
+
+// highlights text string by adding _starthighlight_ and _endhightlight_
+// around terms and/or phrases that match querystring 
+
+// - at present this only handles phrase searches where the first and last
+// characters are double quotes (i.e. it won't correctly handle a mixture
+// of phrase and non-phrase terms or queries containing multiple phrases) -
+// it also doesn't highlight stemmed variations of terms within a phrase
+// because the terminfo returned by mgqueryfilter doesn't currently tell
+// you which term variants belong to which term
+
+// - this function can be forced to treat the querystring like a phrase
+// even if it isn't one by setting the "hl" cgi argument to "2"
+void highlighttext(const text_t &text, cgiargsclass &args, const TermInfo_tarray &terms, 
+		   displayclass &disp, outconvertclass &outconvert, ostream &textout) {
+
+
+  text_t &querystring = args["q"];
+
+  // get the text to start and end a hightlight
+  text_t shl = "<b><u>";
+  text_t ehl = "</u></b>";
+  if (disp.isdefaultmacro(displayclass::defaultpackage, "starthighlight")) {
+    disp.expandstring(displayclass::defaultpackage, "_starthighlight_", shl);
+  }
+  if (disp.isdefaultmacro(displayclass::defaultpackage, "endhighlight")) {
+    disp.expandstring(displayclass::defaultpackage, "_endhighlight_", ehl);
+  }
+
+  // remove leading and trailing whitespace
+  remove_space(querystring);
+
+  // Expand macros before highlighting -- by Jens Wille
+  text_t text_expanded = "";
+  disp.expandstring(text, text_expanded);
+
+  if ((args["hl"] == 2) || ((*(querystring.begin()) == '"') && (*(querystring.end()-1) == '"'))) {
+    highlight_phrases(text_expanded, querystring, terms, shl, ehl, disp, outconvert, textout);
+  } else {
+    highlight_terms(text_expanded, terms, shl, ehl, disp, outconvert, textout);
+  }
+}
+
+void highlight_terms(const text_t &text, const TermInfo_tarray &terms, const text_t &shl,
+		     const text_t &ehl, displayclass &disp, outconvertclass &outconvert,
+		     ostream &textout) {
+
+  text_tmap allterms;
+  text_tmap::const_iterator it;
+
+  // first load all the term variations into a map
+  TermInfo_tarray::const_iterator this_term = terms.begin();
+  TermInfo_tarray::const_iterator last_term = terms.end();
+  while (this_term != last_term) {
+    text_tarray::const_iterator this_var = (*this_term).matchTerms.begin();
+    text_tarray::const_iterator last_var = (*this_term).matchTerms.end();
+    while (this_var != last_var) {
+      allterms[*this_var] = 1;
+      ++this_var;
+    }
+    ++this_term;
+  }
+
+  text_t::const_iterator here = text.begin();
+  text_t::const_iterator end = text.end();
+
+  text_t word, buffer;
+  while (here != end) {
+    if (is_unicode_letdig(*here)) {
+      // not word boundary
+      word.push_back(*here);
+      ++here;
+
+    } else {
+      // found word boundary
+      // add last word if there was one
+      if (!word.empty()) {
+	it = allterms.find(word);
+	if (it != allterms.end()) {
+	  word = shl + word + ehl;
+	}
+	buffer += word;
+        word.clear();
+      }
+
+      if (*here == '<') {
+        // skip over rest of html tag
+	while ((here != end) && (*here != '>')) {
+	  buffer.push_back(*here);
+	  ++here;
+	}
+      }
+
+      buffer.push_back(*here);
+      ++here;
+
+      if (buffer.size() > 1024) {
+	textout << outconvert << disp << buffer;
+	buffer.clear();
+      }
+    }
+  }
+  textout << outconvert << disp << buffer;
+}
+
+void highlight_phrases(const text_t &text, const text_t &querystring, const TermInfo_tarray &terms, 
+		       const text_t &shl, const text_t &ehl, displayclass &disp, 
+		       outconvertclass &outconvert, ostream &textout) {
+
+  text_tmap allterms;
+  text_tarray phrase_terms;
+  text_tmap::const_iterator it;
+
+  get_phrase_terms(querystring, phrase_terms);
+  int phraselen = phrase_terms.size();
+
+  TermInfo_tarray::const_iterator this_term = terms.begin();
+  TermInfo_tarray::const_iterator last_term = terms.end();
+  bool first = true;
+  while (this_term != last_term) {
+    text_tarray::const_iterator this_var = (*this_term).matchTerms.begin();
+    text_tarray::const_iterator last_var = (*this_term).matchTerms.end();
+    while (this_var != last_var) {
+      allterms[*this_var] = 1;
+      ++this_var;
+    }
+    first = false;
+    ++this_term;
+  }
+
+  text_t::const_iterator here = text.begin();
+  text_t::const_iterator end = text.end();
+
+  text_t word, buffer;
+  int phrasecount = 0;
+  while (here != end) {
+    if (is_unicode_letdig(*here)) {
+      // not word boundary
+      word.push_back(*here);
+      ++here;
+
+    } else {
+      // found word boundary
+      // add last word if there was one
+      if (!word.empty()) {
+	it = allterms.find(word);
+	if (it != allterms.end()) {
+	  // found a word that matches somewhere in the phrase
+
+	  text_t lcword = word; lc(lcword);
+	  if (lcword == phrase_terms[phrasecount]) {
+
+	    if (phrasecount == 0) {
+	      // clear the buffer (from here on buffer will contain the phrase
+	      // as it's built up)
+	      textout << outconvert << disp << buffer;
+	      buffer.clear();
+	    }
+	    ++phrasecount;
+	  } else {
+	    phrasecount = 0;
+	  }
+	} else {
+	  phrasecount = 0;
+	}
+	buffer += word;
+        word.clear();
+	
+	if (phrasecount == phraselen) {
+	  // have found entire phrase
+	  textout << outconvert << disp << shl << buffer << ehl;
+	  buffer.clear();
+	  phrasecount = 0;
+	}
+      }
+
+      if (*here == '<') {
+        // skip over rest of html tag
+	while ((here != end) && (*here != '>')) {
+	  buffer.push_back(*here);
+	  ++here;
+	}
+      }
+
+      buffer.push_back(*here);
+      ++here;
+
+      if (buffer.size() > 1024 && phrasecount == 0) {
+	textout << outconvert << disp << buffer;
+	buffer.clear();
+      }
+    }
+  }
+  textout << outconvert << disp << buffer;
+}
+
+void get_phrase_terms (const text_t &querystring, text_tarray &phrase_terms) {
+
+  phrase_terms.erase(phrase_terms.begin(), phrase_terms.end());
+
+  text_t::const_iterator here = querystring.begin();
+  text_t::const_iterator end = querystring.end();
+
+  text_t word;
+  while (here != end) {
+    if (is_unicode_letdig(*here)) {
+      // not word boundary
+      word.push_back(*here);
+
+    } else {
+      // found word boundary
+      if (!word.empty()) {
+	lc(word);
+	phrase_terms.push_back(word);
+	word.clear();
+      }
+    }
+    ++here;
+  }
+
+  if (!word.empty()) {
+    lc(word);
+    phrase_terms.push_back(word);
+  }
+}
+
+void remove_space (text_t &qstring) {
+
+  text_t altered_string;
+  text_t space;
+
+  text_t::const_iterator here = qstring.begin();
+  text_t::const_iterator end = qstring.end();
+  while (here != end) {
+    if (is_unicode_space(*here)) {
+      space.push_back(*here);
+    } else {
+      if (!altered_string.empty()) {
+	altered_string += space;
+      }
+      space.clear();
+      altered_string.push_back(*here);
+    }
+    ++here;
+  }
+
+  qstring = altered_string;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/highlighttext.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/highlighttext.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/highlighttext.h	(revision 16571)
@@ -0,0 +1,46 @@
+/**********************************************************************
+ *
+ * highlighttext.h -- 
+ * Copyright (C) 2002   D L Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef HIGHLIGHTTEXT_H
+#define HIGHLIGHTTEXT_H
+
+#include "text_t.h"
+#include "comtypes.h"
+#include "display.h"
+#include "cgiargs.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#else
+#  include <iostream>
+#endif
+
+void highlighttext(const text_t &text, cgiargsclass &args, const TermInfo_tarray &terms, 
+		   displayclass &disp, outconvertclass &outconvert, ostream &textout);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/historydb.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/historydb.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/historydb.cpp	(revision 16571)
@@ -0,0 +1,302 @@
+/**********************************************************************
+ *
+ * historydb.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "historydb.h"
+#include "fileutil.h"
+#include "cgiutils.h"
+#include "recptproto.h"
+#include "recptprototools.h"
+#include "gdbmclass.h"
+
+#define MAX_RECORDS 20
+#define HIST_SEP ';'
+
+// returns true on success (in which case historyinfo will contain
+// the information for this history)
+bool get_history_info (const text_t &userid, text_tarray &historyinfo, 
+		       const text_t &gsdlhome, ostream &logout) {
+
+  text_t historyfile = filename_cat(gsdlhome, "etc", "history.db");
+  
+  bool result = false;
+  // open the history database  
+  gdbmclass historydb;
+  
+  if (historydb.opendatabase(historyfile, DB_READER, 1000, true)) {
+    // get history list
+    text_t historyresult;
+    
+    historydb.getkeydata(userid, historyresult);
+    
+    if (historyresult != "") { //  there are entries, process them
+      
+      splitchar(historyresult.begin(), historyresult.end(), '\n', historyinfo);
+      result = true;
+    }
+    historydb.closedatabase();
+    
+  } else {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii << "couldn't open history database " << historyfile << "\n";
+  }
+  return result;
+}
+
+
+// returns true on success
+// changed to only save 20 records per user, numbers not included
+// only save if there are already entries there, or if display=true
+bool set_history_info (const text_t &userid, const text_t &history, const text_t &gsdlhome, bool display) {
+
+  text_t historyfile = filename_cat(gsdlhome, "etc", "history.db");
+  
+  bool result = false;
+  // open the history database  
+  gdbmclass historydb;
+  
+  text_t oldhistoryresult;
+  text_t newhistoryresult;
+  int numentries=0;
+
+  if (!historydb.opendatabase(historyfile, DB_READER, 1000, true)) {
+    // not created yet
+    oldhistoryresult="";
+    if (!display) return true; // dont need to save
+  }
+  else {
+
+    // get history list
+   if (! historydb.getkeydata(userid, oldhistoryresult)) {
+     oldhistoryresult="";
+     if (!display) return true; // dont need to save
+   }
+   historydb.closedatabase();
+  }
+
+  text_tarray entries;
+  
+  if (oldhistoryresult!="") {
+    splitchar(oldhistoryresult.begin(), oldhistoryresult.end(), '\n', entries);
+    numentries = entries.size();
+    if (numentries >= MAX_RECORDS) numentries = MAX_RECORDS-1;
+  }
+  
+  // open for writing
+  if (!historydb.opendatabase(historyfile, DB_WRITER_CREATE, 1000, true)) return false;
+  
+  // add on new linethe new record to the front of the list, then add the
+  // appropriate entries from the old stuff 
+  newhistoryresult += history;
+  newhistoryresult += "\n";
+  for (int i=0; i<numentries;++i) {
+    newhistoryresult +=  entries[i]+"\n";
+  }
+  
+  if (historydb.setkeydata(userid, newhistoryresult)) 
+    result=true; 
+  
+  historydb.closedatabase();
+  return result;
+}
+
+// deletes all a users history
+bool delete_all_history_info (const text_t &userid, const text_t &gsdlhome) {
+
+  text_t historyfile = filename_cat(gsdlhome, "etc", "history.db");
+  
+  // open the history database  
+  gdbmclass historydb;
+  
+  if (!historydb.opendatabase(historyfile, DB_WRITER, 1000, true)) return false;
+
+  historydb.deletekey(userid);
+  historydb.closedatabase();
+  return true;
+  
+}
+
+// retrieves the value of one of the arguments
+void parse_saved_args(text_t &args, text_t key, text_t &value)
+{
+  text_t::iterator here = args.begin();
+  text_t::iterator end = args.end();
+  text_t::iterator it;
+  while (here != end) {
+    if(*here==key[0]) {
+      it=findchar(here, end, '=');
+      if (it==end) {
+	value=""; return;
+      }
+      text_t entry = substr(here, it);
+      if (entry==key) {
+	here=it+1;
+      	it=findchar(here, end, HIST_SEP);
+	value = substr(here, it);
+	return;
+      }
+    }
+    ++here;
+  }// while
+}
+
+// retrieves the value of all of the arguments
+void parse_saved_args(text_t &args, infodbclass &info)
+{
+  text_t::iterator here = args.begin();
+  text_t::iterator end = args.end();
+  text_t::iterator it;
+  text_tarray values;
+
+  splitchar(here, end, HIST_SEP, values);
+  
+  text_tarray::iterator start = values.begin();
+  text_tarray::iterator stop = values.end();
+
+  text_t key;
+  text_t value;
+  while(start!=stop) {
+
+    here=(*start).begin();
+    end=(*start).end();
+    it=findchar(here, end, '=');
+    if (it!=end) {
+      key = substr(here, it);
+      value = substr(it+1, end);
+      
+      info[key]=value;
+    }
+    ++start;
+  }
+}
+
+
+void split_saved_query(text_t &query, text_t &numdocs, text_t &cgiargs)
+{
+  text_t::iterator begin = query.begin();
+  text_t::iterator end = query.end();
+  
+  while (*begin >='0'&& *begin <='9') { // get the digits for numdocs
+    numdocs.push_back(*begin);
+    ++begin;
+  }          
+                 
+  if (*begin == '+') {  // get the + if there
+    numdocs.push_back(*begin);
+    ++begin;
+  }
+  if (*begin == ':') { // have the old format - previous bit was record number
+    numdocs.clear();
+    ++begin;
+
+    while(*begin >='0' && *begin <='9') { // get the digits
+      numdocs.push_back(*begin);
+      ++begin;
+    }
+    if (*begin == '+') { // get the + if there
+      numdocs.push_back(*begin);
+      ++begin;
+    }
+  }
+  cgiargs += (substr(begin, end));  // put rest of query into cgiargs
+
+}
+
+void format_user_info (text_t &historyargs, text_t &userinfo,  
+		       cgiargsclass &args,
+		       recptprotolistclass *protos, ostream &logout) 
+{
+  text_tset metadata;
+  userinfo.clear();
+
+  infodbclass argsinfo;
+  parse_saved_args(historyargs, argsinfo);
+  text_t collect = argsinfo["c"];
+  if (collect=="") {
+    userinfo="";
+    return;
+  }
+ 
+  if (collect != args["c"]) {
+    userinfo += collect+", ";
+  }
+  
+  if (argsinfo["h"] != args["h"]) {
+  
+    recptproto *collectproto = protos->getrecptproto(collect,logout);
+    if (collectproto == NULL) {
+      userinfo="";
+      return;
+    }
+    metadata.insert(argsinfo["h"]);
+    FilterResponse_t response;
+    
+    get_info("collection", collect, args["l"], metadata, false, collectproto, response, logout);
+    text_t index = response.docInfo[0].metadata[argsinfo["h"]].values[0];
+    if (!index.empty()) {
+      userinfo += index+", ";
+    }
+  }
+
+  if (argsinfo["b"] != args["b"] || argsinfo["t"] != args["t"]) {
+    if (argsinfo["b"]=="0") { // simple mode
+      if (argsinfo["t"]=="0") {
+	userinfo += " _texthallwords_, ";
+      }
+      else if (argsinfo["t"]=="1"){
+	userinfo += " _texthsomewords_, ";
+      }
+      
+    } 
+    else if (argsinfo["b"] == "1") { // advanced mode
+      if (argsinfo["t"]=="0") {
+	userinfo += " _texthboolean_, ";
+      }
+      else if (argsinfo["t"]=="1") {
+	userinfo += " _texthranked_, ";
+      }
+    }
+  }
+  
+  if (argsinfo["k"] != "" && argsinfo["k"] != args["k"]) {
+    text_t options;
+    // the text translations are the wrong way round
+    if (argsinfo["k"]=="1") {
+      userinfo += " _texthcaseoff_, ";
+    }
+    else if (argsinfo["k"]=="0") {
+      userinfo += " _texthcaseon_, ";
+    }
+  }
+
+  if (argsinfo["s"] != "" && argsinfo["s"] != args["s"]) {
+    if (argsinfo["s"]=="0") {
+      userinfo += " _texthstemoff_, ";
+    }
+    else if (argsinfo["s"]=="1") {
+      userinfo += " _texthstemon_, ";
+    }
+  }
+
+}
Index: /gsdl/trunk/runtime-src/src/recpt/historydb.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/historydb.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/historydb.h	(revision 16571)
@@ -0,0 +1,77 @@
+/**********************************************************************
+ *
+ * historydb.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef HISTORYDB_H
+#define HISTORYDB_H
+
+#include "text_t.h"
+#include "recptproto.h"
+#include "cgiargs.h"
+
+/*
+struct HistRecord {
+  text_t entry;
+  bool save;
+};
+
+struct ltinttext_t
+{
+  bool operator()(const text_t &t1, const text_t &t2) const
+  { return t1.getint() < t2.getint(); }
+};
+
+
+typedef map<text_t, HistRecord, ltinttext_t> HistRecordmap;
+
+*/
+// returns true on success (in which case historyinfo will contain
+// the information for this history)
+bool get_history_info (const text_t &userid, text_tarray &historyinfo, 
+		       const text_t &gsdlhome, ostream &logout);
+
+// returns true on success
+bool set_history_info (const text_t &userid, const text_t &historyinfo, 
+		       const text_t &gsdlhome, bool display);
+
+// delete all history for one user
+bool delete_all_history_info (const text_t &userid, const text_t &gsdlhome);
+
+// retrieves the value of an arg (key) from a list of cgi args
+// in the form a=q&b=1&...
+void parse_saved_args(text_t &args, text_t key, text_t &value);
+
+// extracts out the components of an entry in the database
+// currently:
+// numdocs cgiargs
+void split_saved_query(text_t &query,  text_t &numdocs, text_t &cgiargs);
+
+// takes the cgiarg string, and outputs it in some form useful
+// to the user
+void format_user_info (text_t &cgiargs, text_t &info, 
+		       cgiargsclass &args,
+		       recptprotolistclass *protos, ostream &logout);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/hlistbrowserclass.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/hlistbrowserclass.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/hlistbrowserclass.cpp	(revision 16571)
@@ -0,0 +1,221 @@
+/**********************************************************************
+ *
+ * hlistbrowserclass.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "hlistbrowserclass.h"
+#include "OIDtools.h"
+#include "recptprototools.h"
+#include "cgiutils.h"
+
+
+hlistbrowserclass::hlistbrowserclass () {
+}
+
+hlistbrowserclass::~hlistbrowserclass () {
+}
+
+// returns the name that specifies the browserclass type
+text_t hlistbrowserclass::get_browser_name () {
+  return "HList";
+}
+
+browserclass* hlistbrowserclass::clone()
+{
+  return new hlistbrowserclass();
+}
+
+void hlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
+  metadata.insert ("doctype");
+}
+
+text_t hlistbrowserclass::get_default_formatstring () {
+  return "[link][highlight][Title][/highlight][/link]";
+}
+
+// need to change OID to it's child 
+void hlistbrowserclass::processOID (cgiargsclass &args, recptproto *collectproto,
+				    ostream &logout) {
+
+  text_t OID = args["d"];
+  bool is_classify = false;
+  if (OID.empty()) {
+    is_classify = true;
+    OID = args["cl"];
+  }
+
+  FilterResponse_t response;
+  text_tset metadata;
+  metadata.insert ("childtype");
+  text_t classifytype = "Invisible";
+  text_tarray OIDs;
+
+  while (classifytype == "Invisible" || classifytype == "HList") {
+    OIDs.erase (OIDs.begin(), OIDs.end());
+    
+    OIDs.push_back (OID);
+    OIDs.push_back (OID + ".fc");
+
+    get_info (OIDs, args["c"], args["l"], metadata, false, collectproto, response, logout);
+
+    // Avoid infinite loops in strange situations by checking that the OID has changed
+    if (response.docInfo[1].OID == OID) {
+      break;
+    }
+    OID = response.docInfo[1].OID;
+    classifytype = response.docInfo[1].metadata["childtype"].values[0];
+  }
+  if (is_classify) args["cl"] = OID;
+  else args["d"] = OID;
+}
+
+int hlistbrowserclass::output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
+					     const text_t& collection, int colnumber, 
+					     format_t *formatlistptr, bool use_table, 
+					     text_tset &metadata, bool &getParents, 
+					     recptproto *collectproto, displayclass &disp, 
+					     outconvertclass &outconvert, ostream &textout, 
+					     ostream &logout)
+{
+  // expanded contents are going to cause some nasty recursions
+  // so we'll only continue if being passed the current section
+  if ((args["gc"] == 1) && (section.OID != args["d"])) return 0;
+
+  // get all siblings
+  FilterResponse_t response;
+  get_children (section.OID + ".pr", args["c"], args["l"], metadata, getParents, 
+		collectproto, response, logout);
+
+  return output_section_group (response, args, collection, colnumber, formatlistptr, use_table, metadata, getParents, collectproto, disp, outconvert, textout, logout);
+}
+
+int hlistbrowserclass::output_section_group (FilterResponse_t &response, cgiargsclass &args,
+					     const text_t &collection, int colnumber, 
+					     format_t * formatlistptr, bool use_table, 
+					     text_tset &metadata, bool &getParents,
+					     recptproto * collectproto, displayclass &disp, 
+					     outconvertclass &outconvert, ostream &textout, 
+					     ostream &logout)
+{
+  /* use_table is set to true if the format string starts with <td> */
+  if (use_table || colnumber > 0) {
+    textout << outconvert << "<table><tr><td>";
+    // get tab size
+    text_t tab; int itab;
+    disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
+    itab = tab.getint();
+    if (colnumber > 0) textout << outconvert << disp 
+			       << "<img alt=\"\" src=\"_httpimg_/space.gif\" width=\"" 
+			       << (itab*colnumber) << "\"/>";
+    textout << outconvert << "</td>\n";
+  }
+
+  if (use_table)
+    textout << outconvert << "<table class=\"h_list\"><tr>\n";
+  else
+    textout << outconvert << "<div class=\"h_list\">\n";
+
+  ResultDocInfo_tarray::iterator tsibling = response.docInfo.begin();
+  ResultDocInfo_tarray::iterator esibling = response.docInfo.end();
+
+  text_t icon, link;
+  
+  while (tsibling != esibling)
+  {
+    get_link_icon (*tsibling, args, link, icon);
+
+    bool highlight = false;
+    if ((*tsibling).OID == args["cl"] || is_child_of ((*tsibling).OID, args["cl"]) ||
+	(*tsibling).OID == args["dcn"] || starts_with (args["dcn"], (*tsibling).OID))
+    {
+      link.clear();
+      highlight = true;
+    }
+
+    text_tmap options;
+    options["link"] = link;
+    options["icon"] = icon;
+    if (highlight) options["highlight"] = "1";
+    else options["highlight"] = "0";
+    
+    text_t fmt_str=get_formatted_string (collection, collectproto,
+					  *tsibling, disp, formatlistptr,
+					  options, logout);
+
+    text_t span_class = "h_item";
+    if (highlight) {
+      // the current option
+      span_class += " h_item_current";
+    }
+      
+    textout << outconvert << "<span class=\""<<span_class<<"\">" << disp << fmt_str << "</span>\n";
+    ++tsibling;
+  }
+
+  if (use_table)
+    textout << outconvert << "</tr></table>\n";
+  else
+    textout << outconvert << "</div>\n";
+
+  if (use_table  || colnumber > 0) textout << outconvert << "</tr></table>\n";
+
+  return 0;
+}
+
+
+void hlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args, text_t &link, text_t &icon)
+{
+  link = "<a href=\"_httpdocument_";
+
+  text_t &doctype = section.metadata["doctype"].values[0];
+  if (doctype == "classify")
+  {
+    // Dynamic classifier nodes
+    if (args["a"] == "dc")
+    {
+      // The node label is going into the URL, so make it CGI-safe
+      text_t classifier_node_dcn_cgi_safe = cgi_safe_utf8(section.OID);
+      link = "<a href=\"_gwcgi_?c=" + args["c"] + "&amp;a=dc&amp;dcl=" + args["dcl"] + "&amp;dcn=" + classifier_node_dcn_cgi_safe + "\">";
+    }
+    // Static classifier nodes
+    else
+    {
+      link += "&amp;cl=" + section.OID + "\">";
+    }
+  }
+  else
+  {
+    link += "&amp;cl=" + args["cl"] + "&amp;d=" + section.OID;
+
+    // [modification to allow default document detach settings -- kjdon]
+    if (args["xx"] == "1")
+    {
+      // documents should be detached
+      link += "&amp;x=1\" target=\"_blank\">";
+    }
+    else
+    {
+      link += "\">";
+    }
+  }
+}
Index: /gsdl/trunk/runtime-src/src/recpt/hlistbrowserclass.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/hlistbrowserclass.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/hlistbrowserclass.h	(revision 16571)
@@ -0,0 +1,73 @@
+/**********************************************************************
+ *
+ * hlistbrowserclass.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef HLISTBROWSERCLASS_H
+#define HLISTBROWSERCLASS_H
+
+#include "browserclass.h"
+#include "receptionist.h"
+
+class hlistbrowserclass : public browserclass {
+protected:
+
+public:
+  hlistbrowserclass ();
+  virtual ~hlistbrowserclass ();
+
+  void set_receptionist(receptionist *therecpt) {recpt=therecpt;}
+
+  // returns the name that specifies the browserclass type
+  text_t get_browser_name ();
+
+  virtual browserclass* clone();
+
+  virtual void load_metadata_defaults (text_tset &metadata);
+
+  virtual text_t get_default_formatstring ();
+  
+  virtual void processOID (cgiargsclass &args, recptproto *collectproto,
+			   ostream &logout);
+
+  virtual int output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
+				    const text_t &collection, int colnumber, format_t *formatlistptr, 
+				    bool use_table, text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, ostream &logout);
+
+  virtual int output_section_group (FilterResponse_t &sections, cgiargsclass &args,
+				    const text_t &collection, int colnumber, format_t *formatlistptr, 
+				    bool use_table, text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, ostream &logout);
+
+protected:
+
+  virtual void get_link_icon (ResultDocInfo_t &section, cgiargsclass &args, text_t &link, text_t &icon);
+
+  receptionist *recpt;
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/htmlbrowserclass.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/htmlbrowserclass.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/htmlbrowserclass.cpp	(revision 16571)
@@ -0,0 +1,73 @@
+/**********************************************************************
+ *
+ * htmlbrowserclass.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_HTML_BROWSER
+
+#include "htmlbrowserclass.h"
+#include <assert.h>
+#include "OIDtools.h"
+
+htmlbrowserclass::htmlbrowserclass () {
+}
+
+htmlbrowserclass::~htmlbrowserclass () {
+}
+
+// returns the name that specifies the browserclass type
+text_t htmlbrowserclass::get_browser_name () {
+  return "HTML";
+}
+
+browserclass* htmlbrowserclass::clone()
+{
+  return new htmlbrowserclass();
+}
+
+// redirect to html page
+void htmlbrowserclass::processOID (cgiargsclass &args, recptproto *collectproto,
+				   ostream &logout) {
+
+  // should only reach here from within a classification
+  if (!args["d"].empty()) return;
+  if (args["cl"].empty()) return;
+
+  FilterRequest_t request;
+  FilterResponse_t response;
+  comerror_t err;
+  request.filterName = "NullFilter";
+  request.filterResultOptions = FROID;
+  request.docSet.push_back (args["cl"] + ".fc");
+  collectproto->filter (args["c"], request, response, err, logout);
+
+  if (err != noError || response.docInfo[0].OID.empty()) return;
+
+  // redirect to html page
+  args["a"] = "p";
+  args["p"] = "html";
+  args["hp"] = response.docInfo[0].OID;
+}
+
+#endif //GSDL_USE_HTML_BROWSER
Index: /gsdl/trunk/runtime-src/src/recpt/htmlbrowserclass.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/htmlbrowserclass.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/htmlbrowserclass.h	(revision 16571)
@@ -0,0 +1,52 @@
+/**********************************************************************
+ *
+ * htmlbrowserclass.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_HTML_BROWSER
+
+#ifndef HTMLBROWSERCLASS_H
+#define HTMLBROWSERCLASS_H
+
+#include "browserclass.h"
+
+class htmlbrowserclass : public browserclass {
+protected:
+
+public:
+
+  htmlbrowserclass ();
+  virtual ~htmlbrowserclass ();
+
+  // returns the name that specifies the browserclass type
+  virtual text_t get_browser_name ();
+
+  void processOID (cgiargsclass &args, recptproto *collectproto,
+		   ostream &logout);
+
+  virtual browserclass* clone();
+};
+
+#endif //!HTMLBROWSERCLASS_H
+#endif //GSDL_USE_HTML_BROWSER
Index: /gsdl/trunk/runtime-src/src/recpt/htmlutils.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/htmlutils.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/htmlutils.cpp	(revision 16571)
@@ -0,0 +1,58 @@
+/**********************************************************************
+ *
+ * htmlutils.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "htmlutils.h"
+
+text_t html_safe (const text_t &instring) {
+  
+  text_t outstring;
+  text_t::const_iterator here = instring.begin();
+  text_t::const_iterator end = instring.end();
+  while (here != end) {
+    if (*here == '"') outstring += "&quot;";
+    else if (*here == '&') outstring += "&amp;";
+    else if (*here == '<') outstring += "&lt;";
+    else if (*here == '>') outstring += "&gt;";
+    else if (*here == '#') outstring += "&#35;";
+    else outstring.push_back(*here);
+    ++here;
+  }
+  return outstring;
+}
+
+
+text_t javascript_safe (const text_t &instring) {
+
+  text_t outstring;
+  text_t::const_iterator here = instring.begin();
+  text_t::const_iterator end = instring.end();
+  while (here != end) {
+    if (*here == '"') outstring += "&quot;";
+    else if (*here == '\'') outstring += "\\'";
+    else outstring.push_back(*here);
+    ++here;
+  }
+  return outstring;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/htmlutils.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/htmlutils.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/htmlutils.h	(revision 16571)
@@ -0,0 +1,36 @@
+/**********************************************************************
+ *
+ * htmlutils.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef HTMLUTILS_H
+#define HTMLUTILS_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+
+text_t html_safe (const text_t &instring);
+text_t javascript_safe (const text_t &instring);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/invbrowserclass.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/invbrowserclass.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/invbrowserclass.cpp	(revision 16571)
@@ -0,0 +1,44 @@
+/**********************************************************************
+ *
+ * invbrowserclass.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "invbrowserclass.h"
+#include <assert.h>
+#include "OIDtools.h"
+
+invbrowserclass::invbrowserclass () {
+}
+
+invbrowserclass::~invbrowserclass () {
+}
+
+// returns the name that specifies the browserclass type
+text_t invbrowserclass::get_browser_name () {
+  return "Invisible";
+}
+
+browserclass* invbrowserclass::clone()
+{
+  return new invbrowserclass();
+}
Index: /gsdl/trunk/runtime-src/src/recpt/invbrowserclass.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/invbrowserclass.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/invbrowserclass.h	(revision 16571)
@@ -0,0 +1,50 @@
+/**********************************************************************
+ *
+ * invbrowserclass.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef INVBROWSERCLASS_H
+#define INVBROWSERCLASS_H
+
+#include "browserclass.h"
+
+class invbrowserclass : public browserclass {
+protected:
+
+public:
+
+  // this browser class does nothing by default - it should
+  // be overridden for receptionists wanting to display 
+  // 'Invisible' classifications in some way
+
+  invbrowserclass ();
+  virtual ~invbrowserclass ();
+
+  // returns the name that specifies the browserclass type
+  text_t get_browser_name ();
+
+  virtual browserclass* clone();
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/librarymain.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/librarymain.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/librarymain.cpp	(revision 16571)
@@ -0,0 +1,255 @@
+/**********************************************************************
+ *
+ * librarymain.cpp -- 
+ * Copyright (C) 1999  The New Zaland Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#include "receptionist.h"
+#include "cgiwrapper.h"
+#include "fileutil.h"
+#include "nullproto.h"
+// z39.50 stuff - johnmcp
+#if defined(USE_Z3950)
+#include "z3950proto.h"
+#endif
+#include "collectset.h"
+
+#include "action.h"
+#include "authenaction.h"
+#include "browseaction.h"
+#include "collectoraction.h"
+#include "depositoraction.h"
+#include "documentaction.h"
+#include "dynamicclassifieraction.h"
+#include "extlinkaction.h"
+#include "pageaction.h"
+#include "phindaction.h"
+#include "pingaction.h"
+#include "queryaction.h"
+#include "tipaction.h"
+#include "statusaction.h"
+#include "usersaction.h"
+
+#include "browserclass.h"
+#include "vlistbrowserclass.h"
+#include "hlistbrowserclass.h"
+#include "datelistbrowserclass.h"
+#include "invbrowserclass.h"
+#include "pagedbrowserclass.h"
+#include "htmlbrowserclass.h"
+#include "phindbrowserclass.h"
+
+
+int main ()
+{
+  receptionist recpt;
+  nullproto    nproto;
+  collectset  *cservers;
+#if defined(USE_Z3950)
+  z3950proto   zproto;
+#endif
+  text_t       gsdlhome;
+  text_t       collecthome;
+
+  cservers = new collectset(gsdlhome,collecthome);
+
+  // configure the receptionist server list
+  text_tarray collection_list;
+  cservers->getCollectionList(collection_list);
+  text_tarray::iterator collection_iterator = collection_list.begin();
+  while (collection_iterator != collection_list.end())
+  {
+    text_tarray colinfo;
+    colinfo.push_back(*collection_iterator);
+    colinfo.push_back(gsdlhome);
+    colinfo.push_back(collecthome);
+    colinfo.push_back(gsdlhome);
+    recpt.configure("collectinfo", colinfo);
+    collection_iterator++;
+  }
+
+  // set up the null protocol
+  nproto.set_collectset(cservers);
+
+  // add the protocol to the receptionist
+  recpt.add_protocol (&nproto);
+
+  // z39.50 stuff - johnmcp
+#if defined(USE_Z3950)
+  // add the z39.50 server information. Read in the file
+  // etc/recpt/z3950.cfg for list of servers and their databases.
+  text_t z3950cfg = filename_cat (gsdlhome, "etc");
+  z3950cfg = filename_cat (z3950cfg, "packages");
+  z3950cfg = filename_cat (z3950cfg, "z3950.cfg");
+#ifdef USE_FASTCGI
+  // currently can't use z39.50 if fastcgi used
+#warning  "Disabling z39.50 support as fastcgi is in use"
+  if (0) {
+#else
+  if (file_exists(z3950cfg)) {
+#endif
+    text_t z3950err = filename_cat (gsdlhome, "etc", "z3950log.txt");
+    zproto.read_config_file(z3950cfg,z3950err);
+    // only add this protocol if we have any servers configured.
+    if (zproto.getServerCount()>0)
+      recpt.add_protocol (&zproto);
+  }
+#endif
+
+  // the list of actions. Note: these actions will become invalid
+  // at the end of this function. We will clean them.
+
+#ifdef GSDL_USE_TIP_ACTION
+  recpt.add_action (new tipaction());
+#endif
+
+#ifdef GSDL_USE_STATUS_ACTION
+  statusaction *astatusaction = new statusaction();
+  astatusaction->set_receptionist (&recpt);
+  recpt.add_action (astatusaction);
+#endif
+
+  pageaction *apageaction = new pageaction();
+  apageaction->set_receptionist (&recpt);
+  recpt.add_action (apageaction);
+
+#ifdef GSDL_USE_PING_ACTION
+  recpt.add_action (new pingaction());
+#endif
+
+  queryaction *aqueryaction = new queryaction();
+  aqueryaction->set_receptionist (&recpt);
+  recpt.add_action (aqueryaction);
+		
+  documentaction *adocumentaction = new documentaction();
+  adocumentaction->set_receptionist (&recpt);
+  recpt.add_action (adocumentaction);
+
+  text_t userdbfile = filename_cat(gsdlhome, "etc", "users.db");
+  userdbclass *udb = new userdbclass(userdbfile);
+
+  text_t keydbfile = filename_cat(gsdlhome, "etc", "key.db");
+  keydbclass *kdb = new keydbclass(keydbfile);
+
+#ifdef GSDL_USE_USERS_ACTION
+  usersaction *ausersaction = new usersaction();
+  ausersaction->set_userdb(udb);
+  recpt.add_action (ausersaction);
+#endif
+
+#ifdef GSDL_USE_EXTLINK_ACTION
+  extlinkaction *aextlinkaction = new extlinkaction();
+  aextlinkaction->set_receptionist(&recpt);
+  recpt.add_action (aextlinkaction);
+#endif
+		
+#ifdef GSDL_USE_AUTHEN_ACTION
+  authenaction *aauthenaction = new authenaction();
+  aauthenaction->set_userdb(udb);
+  aauthenaction->set_keydb(kdb);
+  aauthenaction->set_receptionist(&recpt);
+  recpt.add_action (aauthenaction);
+#endif
+
+#ifdef GSDL_USE_COLLECTOR_ACTION
+  collectoraction *acollectoraction = new collectoraction();
+  acollectoraction->set_receptionist (&recpt);
+  recpt.add_action(acollectoraction);
+#endif
+
+#ifdef GSDL_USE_DEPOSITOR_ACTION
+  depositoraction *adepositoraction = new depositoraction();
+  adepositoraction->set_receptionist (&recpt);
+  recpt.add_action(adepositoraction);
+#endif
+
+#ifdef GSDL_USE_BROWSE_ACTION
+  browseaction *abrowseaction = new browseaction();
+  abrowseaction->set_receptionist (&recpt);
+  recpt.add_action(abrowseaction);
+#endif
+
+#ifdef GSDL_USE_PHIND_ACTION
+  recpt.add_action(new phindaction());
+#endif
+
+#ifdef GSDL_USE_GTI_ACTION
+  gtiaction *agtiaction = new gtiaction();
+  agtiaction->set_receptionist(&recpt);
+  recpt.add_action(agtiaction);
+#endif
+
+  dynamicclassifieraction *adynamicclassifieraction = new dynamicclassifieraction();
+  adynamicclassifieraction->set_receptionist(&recpt);
+  recpt.add_action(adynamicclassifieraction);  
+
+  // list of browsers
+  vlistbrowserclass avlistbrowserclass;
+  avlistbrowserclass.set_receptionist(&recpt);
+  recpt.add_browser (&avlistbrowserclass);
+  recpt.setdefaultbrowser ("VList");
+
+  hlistbrowserclass ahlistbrowserclass;
+  ahlistbrowserclass.set_receptionist(&recpt);
+  recpt.add_browser (&ahlistbrowserclass);
+
+#ifdef GSDL_USE_DATELIST_BROWSER
+  datelistbrowserclass adatelistbrowserclass;
+  recpt.add_browser (&adatelistbrowserclass);
+#endif
+
+  invbrowserclass ainvbrowserclass;
+  recpt.add_browser (&ainvbrowserclass);
+
+#ifdef GSDL_USE_PAGED_BROWSER
+  pagedbrowserclass apagedbrowserclass;
+  recpt.add_browser (&apagedbrowserclass);
+#endif
+
+#ifdef GSDL_USE_HTML_BROWSER
+  htmlbrowserclass ahtmlbrowserclass;
+  recpt.add_browser (&ahtmlbrowserclass);
+#endif
+
+#ifdef GSDL_USE_PHIND_BROWSER
+  phindbrowserclass aphindbrowserclass;
+  recpt.add_browser (&aphindbrowserclass);
+#endif
+
+  cgiwrapper (recpt, "");
+  delete cservers;
+  delete udb;
+  delete kdb;
+
+  // clean up the actions
+  actionmapclass::iterator thisAction = recpt.get_actionmap_ptr()->begin();
+  actionmapclass::iterator endAction = recpt.get_actionmap_ptr()->begin();
+  while (thisAction != endAction) {
+    delete thisAction->second.a; thisAction->second.a = NULL;
+    ++thisAction;
+  }
+  thisAction = recpt.get_actionmap_ptr()->begin();
+  recpt.get_actionmap_ptr()->erase(thisAction, endAction);
+
+  return 0;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/maincfg.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/maincfg.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/maincfg.cpp	(revision 16571)
@@ -0,0 +1,91 @@
+/**********************************************************************
+ *
+ * maincfg.cpp -- 
+ * Copyright (C) 2008  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "maincfg.h"
+#include "fileutil.h"
+
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace/std/iostream>
+#  include <ospace/std/fstream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#  include <fstream.h>
+#else
+#  include <iostream>
+#  include <fstream>
+#endif
+
+
+bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
+		    const text_t &collection) 
+{
+
+  cerr << "Warning: Using version of main_cfg_read() that does not support 'collecthome'" << endl;
+
+  text_t collecthome = filename_cat(gsdlhome,"collect");
+
+  cerr << "Setting collecthome to be " << collecthome << endl;
+
+
+  return main_cfg_read(recpt,gsdlhome,collecthome,collection);
+}
+
+
+// main_cfg_read reads both main.cfg and collect.cfg. It attempts
+// to read main.cfg first so values in collect.cfg override those
+// set earlier by main.cfg
+bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
+		    const text_t& collecthome, const text_t &collection) {
+
+  // read in the main configuration file
+  bool rv = false;
+
+  text_t key, filename;
+  text_tarray cfgline;
+  filename = filename_cat (gsdlhome, "etc", "main.cfg");
+  if (!collection.empty() && file_exists(filename)) {
+    rv = recpt.read_configfile(filename);
+  } else {
+    if (file_exists (filename)) {
+      rv = recpt.read_configfile(filename);
+    }
+  }
+
+  // Look for collect.cfg in <collecthome>/collection-name/etc directory 
+  // (if this is for a particular collection), and then GSDLHOME/etc.
+  if (!collection.empty()) {
+    filename = filename_cat (collecthome, collection, "etc", "collect.cfg");
+    if (!file_exists (filename)) {
+      filename = filename_cat (gsdlhome, "etc", "collect.cfg");
+      if (!file_exists (filename)) filename.clear();
+    }
+
+    if (!filename.empty()) {
+      rv |= recpt.read_configfile(filename);
+    }
+  }
+  return rv;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/maincfg.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/maincfg.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/maincfg.h	(revision 16571)
@@ -0,0 +1,48 @@
+/**********************************************************************
+ *
+ * maincfg.h -- 
+ * Copyright (C) 2008  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef MAINCFG_H
+#define MAINCFG_H
+
+
+#include "text_t.h"
+#include "receptionist.h"
+
+
+// read main.cfg for the actions and httpprefix
+void main_cfg_read (const text_t& collection, const text_t &gsdlhome, text_t &httpprefix, text_tset& actions, text_tset& browsers);
+
+// main_cfg_read reads either collect.cfg or main.cfg and returning 
+// true on success. It attempts to read collect.cfg first if a
+// collection is specified and then it tries to read in main.cfg
+bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
+		    const text_t& collecthome, const text_t &collection);
+
+bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
+		    const text_t &collection);
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/pageaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/pageaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/pageaction.cpp	(revision 16571)
@@ -0,0 +1,1037 @@
+/**********************************************************************
+ *
+ * pageaction.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+// Changelog:
+
+// 11th July 2003:
+
+//   Added 3 functions to deal with the collection style
+//   A deciding function and then 2 functions that actually
+//   do the work for us, either images or pulldown.
+
+
+#include "pageaction.h"
+#include "receptionist.h"
+#include "recptprototools.h"
+#include "fileutil.h"
+#include "gsdltools.h"
+#include "querytools.h"
+#include <time.h>
+
+pageaction::pageaction () {
+
+  status_disabled = true;
+  collector_disabled = true;
+  depositor_disabled = true; 
+  translator_disabled = true;
+  gliapplet_disabled = true;
+  recpt = NULL;
+
+  // this action uses cgi variables "a", "p", and "hp"
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "p";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "p";
+  arg_ainfo.longname = "page";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "home";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "hp";
+  arg_ainfo.longname = "html page";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "bp";
+  arg_ainfo.longname = "set preferences button";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // the "u" argument will disable the search facility, remove links to the
+  // home and preferences pages, and disable the DocumentButton buttons
+  // (for use when generating static html versions of collections)
+  arg_ainfo.shortname = "u";
+  arg_ainfo.longname = "static page";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "book";
+  arg_ainfo.longname = "book switch";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "off";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+}
+
+pageaction::~pageaction () {
+}
+
+bool pageaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args, 
+				recptprotolistclass * /*protos*/, ostream &/*logout*/) {
+
+  if (args["p"] == "preferences" && !args["bp"].empty()) {
+    if (args["hd"] != "0") args["hd"] = args["hdn"];
+  }
+
+  return true;
+}
+
+void pageaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
+				   response_t &response,text_t &response_data, 
+				   ostream &/*logout*/) {
+  response = content;
+  response_data = "text/html";
+}
+
+// This function helps decide whether we want a
+// images or pulldown style collection display
+// We refer to the macro files for the options
+// for images or pulldown menu and use that to
+// switch to the appropriate function to do the job
+
+// Aly Dharshi
+// 11th July 2003
+
+void pageaction::homepagestyle(displayclass &disp, recptprotolistclass *protos,
+			       cgiargsclass &args, ostream &logout)
+{
+
+  const recptconf &configinfo = recpt->get_configinfo();
+
+  if (configinfo.HomePageType == "images") {
+     home_images(disp, protos, args, configinfo, logout);
+
+  } else
+     {
+	home_pulldown(disp, protos, args, configinfo, logout);
+     }
+}
+
+// This function allows for the Greenstone
+// collection to be displayed in a pull down
+// menu similar to that in documentaction.cpp
+
+// Aly Dharshi
+// 11th July 2003
+
+void pageaction::home_pulldown(displayclass &disp, recptprotolistclass *protos, 
+			       cgiargsclass &args, const recptconf &configinfo,
+			       ostream &logout) {
+
+   text_t homeextra = "<form method=\"get\" name=\"browse\">\n";
+   homeextra += "<select name=\"collections\" onChange=\"location.href=";
+   homeextra += "document.browse.collections.options[document.browse.collections.selectedIndex].value\">\n";
+   homeextra += "<option value=\"\">_textdescrselcol_</option>\n";
+   
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    if ((*rprotolist_here).p != NULL) {
+
+      text_tarray collist;
+      comerror_t err;
+      (*rprotolist_here).p->get_collection_list (collist, err, logout);
+      if (err == noError) {
+	text_tarray::iterator collist_here = collist.begin();
+	text_tarray::iterator collist_end = collist.end();
+
+	int count = 0;
+	bool first = true;
+	while (collist_here != collist_end) {
+
+	  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
+	  
+	  if (cinfo != NULL) {
+	    if (cinfo->isPublic && (cinfo->buildDate > 0)) {
+
+	      text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
+	      if (collectionname.empty()) {
+		collectionname = *collist_here;
+	      }
+	      
+	      comerror_t err;
+	      text_t optsite = g_EmptyText;
+	      text_t site_name = (*rprotolist_here).p->get_site_name (err);
+	      if (!site_name.empty()) { optsite = "site="+site_name+"&amp;"; }
+	      
+	      text_t link = "_gwcgi_?"+optsite+"a=p&amp;p=about&amp;c=" + *collist_here;
+	      link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"];
+
+	      // We are "dynamically" overriding so to speak the
+	      // link to the collection aka receptionist.
+	      
+	      if (!cinfo->receptionist.empty()) 
+		 link = cinfo->receptionist;
+	      
+	      
+	      homeextra += "<option value=\"" + link + "\"";
+	      homeextra += ">" + collectionname + "</option>\n";
+	      	    
+	    }
+
+	    ++collist_here;
+	    }
+	    
+	  }
+      }
+	++rprotolist_here;
+    }
+    
+    }
+  homeextra += "</select>\n";
+  homeextra += "</form>\n";
+  
+  disp.setmacro ("homeextra", "home", homeextra); 
+}
+  
+// originally called set_homeextra_macro
+// this function displays the Greenstone
+// main page as usual with the graphics for
+// the collections.
+
+// Aly Dharshi
+// 11th July 2003
+
+void pageaction::home_images(displayclass &disp, recptprotolistclass *protos, 
+			     cgiargsclass &args, const recptconf &configinfo,
+			     ostream &logout) {
+  
+  text_t homeextra = "<table class=\"collections\">\n";
+  bool found_valid_col = false;
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    if ((*rprotolist_here).p != NULL) {
+
+      text_tarray collist;
+      comerror_t err;
+      (*rprotolist_here).p->get_collection_list (collist, err, logout);
+      if (err == noError) {
+	text_tarray::iterator collist_here = collist.begin();
+	text_tarray::iterator collist_end = collist.end();
+
+	int count = 0;
+	while (collist_here != collist_end) {
+
+	  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
+
+	  text_t arg_g = args["g"];
+	  text_t colname_dir = *collist_here;
+	  
+	  if (arg_g.empty()) {
+	    // normal top-level home page
+	    text_t::const_iterator begin = colname_dir.begin();
+	    text_t::const_iterator end = colname_dir.end();
+
+	    if (findchar(begin,end,'/')!=end) {
+	      // no g argument, so generating top level home page
+	      // => if colname_dir has "/" in collection name, filter it out
+
+	      ++collist_here;
+	      continue;
+	    }
+	  }
+	  else {
+	    // show only collections in the named group
+
+	    
+	    if (colname_dir == arg_g) {
+	      // display about this collect text
+
+	      text_t collectionextra = cinfo->get_collectionmeta("collectionextra", args["l"]);
+	      if (!collectionextra.empty()) {
+		// prepend text on at start
+		homeextra = "<p>" + collectionextra + "</p>" + homeextra;
+	      }
+
+	      ++collist_here;
+	      continue;
+	    }
+
+
+	    // => filter out anything that does not start with the group prefix
+	    
+	    if (!starts_with(colname_dir,arg_g + "/")) {
+	      ++collist_here;
+	      continue;
+	    }
+	  }
+
+
+	  if (cinfo != NULL) {
+	    if (cinfo->isPublic && ((cinfo->buildDate > 0)) || (cinfo->isCollectGroup)) {
+
+	      found_valid_col = true;
+	      text_t collectionname = *collist_here;
+	      text_t alt = cinfo->get_collectionmeta("collectionname", args["l"]);
+	      if (alt.empty()) {
+		alt = collectionname;
+	      }
+
+
+	      comerror_t err;
+	      text_t optsite = g_EmptyText;
+	      text_t site_name = (*rprotolist_here).p->get_site_name (err);
+	      if (!site_name.empty()) { optsite = "site="+site_name+"&amp;"; }
+
+	      text_t link;
+
+	      if (cinfo->isCollectGroup) {
+		link = "<a class=\"collectiontitle\" href=\"_gwcgi_?"+optsite+"a=p&amp;p=home&amp;g=" + *collist_here;
+		link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"] + "\">";
+	      }
+	      else {
+		link = "<a class=\"collectiontitle\"href=\"_gwcgi_?"+optsite+"a=p&amp;p=about&amp;c=" + *collist_here;
+		link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"] + "\">";
+	      }
+	      
+	      if (!cinfo->receptionist.empty()) 
+		link = "<a class=\"collectiontitle\"href=\"" + cinfo->receptionist + "\">";
+	      
+	      
+	      // url to image: try iconcollectionsmall, then iconcollection
+	      text_t iconurl = cinfo->get_collectionmeta("iconcollectionsmall", args["l"]);
+	      if (iconurl.empty()) {
+		iconurl = cinfo->get_collectionmeta("iconcollection", args["l"]);
+	      }
+	      
+	      if (!iconurl.empty()) {
+		
+		// check to see URL is local to colserver
+		text_t::iterator iconurl_head = iconurl.begin();
+		text_t iconhead = substr(iconurl_head,iconurl_head+16);
+		if (iconhead=="_httpcollection_") {
+		  
+		  // local and using _httpcollection_
+		  text_t icontail = substr(iconurl_head+16,iconurl.end());
+		  iconurl = "http://" + cinfo->httpdomain 
+		    + cinfo->httpprefix + "/collect/" 
+		    + *collist_here + "/" + icontail;
+		}
+		else if (iconurl[0]=='/') {
+		  
+		  // local but with full path
+		  iconurl = "http://" + cinfo->httpdomain + iconurl;
+		}
+		
+		collectionname 
+		  = link + "<img width=\"150\" src=\"" + iconurl + "\" alt=\"" + alt + "\">" + "</a>";
+	      } else {		
+
+		collectionname = "<div class=\"collecttitle\" style=\"width: 150px; border: 1px solid; \"><p class=\"collectiontitle\" style=\"font-size: 18px; width: 150px; white-space:normal; text-align: left;\">";
+		collectionname += alt + "</p></div>";
+
+		collectionname = link + collectionname + "</a>";
+
+	      }
+	      
+	      if (count%configinfo.HomePageCols == 0)
+		homeextra += "<tr valign=\"top\">\n";	      
+
+	      homeextra += "<td align=\"center\">" + collectionname + "</td>\n";
+	      
+	      ++count;
+	      if (count%configinfo.HomePageCols == 0)
+		homeextra += "</tr>\n";
+	    }
+	  }
+	  ++collist_here;
+	}
+
+	// Finish off the last row, if necessary
+	if (count%configinfo.HomePageCols != 0) {
+	  while (count%configinfo.HomePageCols != 0) {
+	    homeextra += "<td></td>\n";
+	    ++count;
+	  }
+	  homeextra += "</tr>\n";
+	}
+      }
+    }
+    ++rprotolist_here;
+  }
+
+  if (!found_valid_col) {
+    homeextra += "<tr><td>_textnocollections_</td></tr>\n";
+  }
+  homeextra += "</table>\n";
+  disp.setmacro ("homeextra", "home", homeextra); 
+}
+
+void pageaction::set_collectionlist_macro (displayclass &disp, 
+					   recptprotolistclass *protos, 
+					   cgiargsclass &args, 
+					   ostream &logout) {
+
+  text_t collectionlist;
+  int count = 0;
+  
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    if ((*rprotolist_here).p != NULL) {
+
+      text_tarray collist;
+      comerror_t err;
+      (*rprotolist_here).p->get_collection_list (collist, err, logout);
+      if (err == noError) {
+	text_tarray::iterator collist_here = collist.begin();
+	text_tarray::iterator collist_end = collist.end();
+
+	while (collist_here != collist_end) {
+	  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
+	  
+	  if (cinfo != NULL) {
+	    if (cinfo->isPublic && (cinfo->buildDate > 0)) {
+
+	      ++count;
+
+	      text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
+	      if (collectionname.empty()) {
+		collectionname = *collist_here;
+	      }
+	      
+	      comerror_t err;
+	      text_t optsite = g_EmptyText;
+	      text_t site_name = (*rprotolist_here).p->get_site_name (err);
+	      if (!site_name.empty()) { optsite = "site="+site_name+"&amp;"; }
+
+	      text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&p=about&c=" + *collist_here + "\">";
+
+	      if (!cinfo->receptionist.empty()) 
+		link = "<a href=\"" + cinfo->receptionist + "\">";
+	      
+	     collectionlist += "<li>" + link + collectionname + "</a>\n";
+	    }
+	  }
+	  ++collist_here;
+	}
+      }
+    }
+    ++rprotolist_here;
+  }
+
+  if (count == 1) {
+    collectionlist = "<p>_text1coll_\n<ul>" +
+      collectionlist + "</ul>\n";
+  } else if (count > 1) {
+    collectionlist = "<p>_textmorecolls_(" + text_t(count) + 
+      ")\n<ul>" + collectionlist + "</ul>\n";
+  }
+
+  disp.setmacro ("collectionlist", "homehelp", collectionlist); 
+}
+
+void pageaction::set_documentation_macro (displayclass &disp) {
+
+  text_t documentation;
+  text_t docsdir = filename_cat(gsdlhome, "docs");
+  
+  if (file_exists(filename_cat(docsdir, "User.pdf"))) {
+    documentation += "<tr valign=middle><td><a href=\"_httpdocs_/User.pdf\">_iconpdf_"
+      "</a></td><td>_textuserguide_</td></tr>";
+  }
+  
+  if (file_exists(filename_cat(docsdir, "Install.pdf"))) {
+    documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Install.pdf\">_iconpdf_"
+      "</a></td><td>_textinstallerguide_</td></tr>";
+  }
+  
+  if (file_exists(filename_cat(docsdir, "Develop.pdf"))) {
+    documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Develop.pdf\">_iconpdf_"
+      "</a></td><td>_textdeveloperguide_</td></tr>";
+  }
+  
+  if (file_exists(filename_cat(docsdir, "Paper.pdf"))) {
+    documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Paper.pdf\">_iconpdf_"
+      "</a></td><td>_textpaperguide_</td></tr>";
+  }
+  
+  if (file_exists(filename_cat(docsdir, "Organize.pdf"))) {
+    documentation += "<tr valign=middle><td><a href=\"_httpdocs_/Organize.pdf\">_iconpdf_"
+      "</a></td><td>_textorganizerguide_</td></tr>";
+  }
+
+  if (!documentation.empty()) {
+    disp.setmacro("documentation", "docs", "<p>\n<table border=0>\n" + documentation + "\n</table>\n");
+  }
+}
+
+void pageaction::set_macro_to_file_contents (displayclass &disp, const text_t &macroname,
+					     const text_t &packagename, const text_t &filename) {
+
+  text_t filecontent;
+  char *filenamec = filename.getcstr();
+  ifstream file_in (filenamec);
+  delete []filenamec;
+  if (file_in) {
+    char c;
+    file_in.get(c);
+    while (!file_in.eof ()) {
+      if (c == '\n') filecontent += "<br>";
+      filecontent.push_back(c);
+      file_in.get(c);
+    }
+    file_in.close();
+  }
+  disp.setmacro (macroname, packagename, dm_safe(filecontent));
+}
+
+void pageaction::set_language_encoding_macros(displayclass &disp, cgiargsclass &args,
+					      recptprotolistclass *protos, ColInfoResponse_t *cinfo,
+					      ostream &logout) {
+  // _languageoption_
+  // Create the "interface language" selection box for the preferences
+  // pages.  You can use something like "format PreferenceLanguages
+  // en|fr|zn" from within a collect.cfg file to use only a subset of
+  // the available languages for any given collection (for
+  // collection-specific preferences pages). This facility is kind of
+  // ugly though and should be replaced by something better when the
+  // configuration files are tidied up (as should all the other
+  // "format Preference..." options).
+  text_t &arg_l = args["l"];
+  const recptconf &configinfo = recpt->get_configinfo();
+  // put languages in another map to sort them by longname
+  text_tmap languages;
+  languageinfo_tmap::const_iterator thislang = configinfo.languages.begin();
+  languageinfo_tmap::const_iterator endlang = configinfo.languages.end();
+  while (thislang != endlang) {
+    languages[(*thislang).second.longname] = (*thislang).first;
+    ++thislang;
+  }
+  text_tmap::iterator tlang = languages.begin();
+  text_tmap::iterator elang = languages.end();
+
+  text_t languageoption;
+  bool collection_specific = false;
+
+  if (cinfo != NULL) {
+    text_tmap::const_iterator it = cinfo->format.find ("PreferenceLanguages");
+    if ((it != cinfo->format.end()) && (!(*it).second.empty())) {
+      collection_specific = true;
+      text_tset pref_langs;
+      splitchar ((*it).second.begin(), (*it).second.end(), '|', pref_langs);
+      if (pref_langs.size() > 1) {
+	while (tlang != elang) {
+	  if (pref_langs.find((*tlang).second) != pref_langs.end()) {
+	    languageoption += "<option value=\"" + (*tlang).second + "\"";
+	    if ((*tlang).second == arg_l) languageoption += " selected";
+	    languageoption += ">" + (*tlang).first + "</option>\n";
+	  }
+	  ++tlang;
+	}
+      }
+    }
+  }
+
+  if (!collection_specific) {
+    while (tlang != elang) {
+      languageoption += "<option value=\"" + (*tlang).second + "\"";
+      if ((*tlang).second == arg_l) languageoption += " selected";
+      languageoption += ">" + (*tlang).first + "</option>\n";
+      ++tlang;
+    }
+  }
+
+  if (!languageoption.empty()) {
+    languageoption = "<select name=\"l\" onChange=\"updatel();\">\n" + languageoption;
+    languageoption += "</select>\n";
+    disp.setmacro ("languageoption", args["p"], languageoption);
+  }
+
+  // _encodingoption_
+  // create the "encoding" selection box for the preferences page
+  if (configinfo.encodings.size() > 1) {
+    text_t &arg_w = args["w"];
+    text_t encodingoption;
+    text_tmap::const_iterator thisenc = configinfo.encodings.begin();
+    text_tmap::const_iterator endenc = configinfo.encodings.end();
+    while (thisenc != endenc) {
+      encodingoption += "<option value=\"" + (*thisenc).second + "\"";
+      if ((*thisenc).second == arg_w) encodingoption += " selected";
+      encodingoption += ">" + (*thisenc).first + "</option>\n";
+      ++thisenc;
+    }
+
+    encodingoption = "<select name=\"w\" onChange=\"updatew();\">\n" + encodingoption;
+    encodingoption += "</select>\n";
+    disp.setmacro ("encodingoption", args["p"], encodingoption);
+  } else if (configinfo.encodings.size() == 1) {
+    text_t encodingoption;
+    text_tmap::const_iterator thisenc = configinfo.encodings.begin();
+    encodingoption = (*thisenc).first;
+    disp.setmacro ("encodingoption", args["p"], encodingoption);
+  } else { // size == 0. shouldn't really happen, but allow it
+    disp.setmacro ("encodingoption", args["p"], "None");
+  }
+
+}
+
+
+void pageaction::define_internal_macros (displayclass &disp, cgiargsclass &args, 
+					 recptprotolistclass *protos, ostream &logout) {
+
+  // define_internal_macros sets the following macros:
+
+  // _numdocs_             the number of documents in the collection
+
+  // _builddate_           the date last built
+
+  // if page is "home"
+  // _homeextra_           this is the list of available collections and collection info
+  //                       to be displayed on the home page
+
+
+  // if page is "preferences"
+  // _collectionoption_    collections to search/browse (if cross-collection-searching is on)
+
+  // _htmloptions_         set to _htmloptionson_ if DocumentUseHTML is set
+
+  // _PreferencesDocsFromWeb_ set to 1 if corresponding format option is set
+
+
+  // if page is "preferences" or "homepref"
+  // _languageoption_      interface languages to select from (dependant on PreferenceLanguages)
+
+  // _encodingoption_      encodings to select from
+
+
+  // if page is "about"
+  // _textsubcollections_  the text on which subcollections make up the collection (if 
+  //                       cross-collection searching is being used
+
+  // _textbrowseoptions_   the 'how to find information' text in the about and help pages
+
+  // _numbrowseoptions_    the number of browsing options 
+
+  // _prefschanged_        will be set to _textprefschanged_ if the "set preferences" button
+  //                       was pressed
+
+  // _aboutqueryform_      will be set to "" if the collection isn't searchable
+
+  // if page is "help"
+  // _textbrowseoptions_   the 'how to find information' text in the about and help pages
+
+  // _numbrowseoptions_    the number of browsing options 
+
+  // _topicreadingdocs_    this section of the help text differs depending on what type of 
+  // _textreadingdocs_     collection it is (e.g. html collection, bibliographic collection etc.)
+  // _texthelpreadingdocs_ 
+
+  // if page is "home" or "homehelp"
+  // _textgocollector_     set to "" if collector is disabled in main.cfg
+  // _textgodepositor_     set to "" if depositor is disabled in main.cfg
+  // _textgoadmin_         set to "" if status is disabled in main.cfg
+  // _textgotranslator_    set to "" if translator is disabled in main.cfg
+  // _textgogliapplet_     set to "" if gliapplet is disabled in main.cfg
+
+
+  // if page is "homehelp"
+  // _collectionlist_      list of available collections to be displayed on the homehelp page
+
+  
+  // if page is "docs"
+  // _documentation_       links to PDF documents if they're available
+
+
+  // if page is "bsummary"
+  // _importlog_           set to contents of collections import.log file
+  // _faillog_             set to contents of collections fail.log file
+  //_buildlog_             set to contents of collections build.log file
+  
+  if (recpt == NULL) {
+    logout << "ERROR (pageaction::define_internal_macros): This action does not contain\n"
+	   << "      information about any receptionists. The method set_receptionist was\n"
+	   << "      probably not called from the module which instantiated this action.\n";
+    return;
+  }
+  // _versionnnum_   greenstone version number (hard-coded)
+  disp.setmacro("versionnum", displayclass::defaultpackage, GSDL_VERSION);
+
+  text_t &arg_p = args["p"];
+  text_t &arg_c = args["c"];
+  ColInfoResponse_t *cinfo = NULL;
+
+  recptproto* collectproto = protos->getrecptproto (arg_c, logout);
+  if (collectproto != NULL) {
+    cinfo = recpt->get_collectinfo_ptr (collectproto, arg_c, logout);
+    
+    //set the tidyoption
+    if (cinfo->useBook == false)
+    {
+        disp.setmacro ("tidyoption", displayclass::defaultpackage, "untidy");
+    }
+    else
+    {
+        disp.setmacro ("tidyoption", displayclass::defaultpackage, "tidy");
+    }
+    
+    disp.setmacro ("numdocs", displayclass::defaultpackage, cinfo->numDocs);
+    disp.setmacro ("numsections", displayclass::defaultpackage, cinfo->numSections);
+    disp.setmacro ("numwords", displayclass::defaultpackage, cinfo->numWords);
+    unsigned long current_time = time(NULL);
+    unsigned long builddate = (current_time - cinfo->buildDate) / 86400;
+    disp.setmacro ("builddate", displayclass::defaultpackage, builddate);
+    
+    text_t numbytes;
+    if ((cinfo->numBytes/(1024*1024)) > 1) {
+      numbytes = (text_t)(cinfo->numBytes/(1024*1024)) + " Mb";
+    } else if ((cinfo->numBytes/1024) > 1) {
+      numbytes = (text_t)(cinfo->numBytes/1024) + " kb";
+    } else {
+      numbytes = (text_t)cinfo->numBytes + " bytes";
+    }
+    disp.setmacro("numbytes", displayclass::defaultpackage, numbytes);
+
+    // set up ct, qt, qto
+    set_query_type_args(cinfo, args);
+    // set up ks, ss, afs
+    set_stem_index_args(cinfo, args);
+  
+  }
+  
+  //setting _queryformcontent_ so that the query interface is consistent.
+  //also adding usability button if necessary
+  if (arg_p == "about") {
+    if (cinfo == NULL) {
+      disp.setmacro("cvariable", displayclass::defaultpackage, arg_c);
+      disp.setmacro("content", arg_p, "<p>_textbadcollection_<p>");
+      return;
+    }
+    else {
+
+      text_tmap::iterator check = cinfo->format.find("QueryInterface");
+      if(check != cinfo->format.end()){
+	if((*check).second=="DateSearch"){
+	  text_t current = "_datesearch_";
+	  disp.setmacro("optdatesearch","query",current);
+	}
+      }
+      check = cinfo->format.find("Usability");
+      if(check != cinfo->format.end()){
+	disp.setmacro("usability", displayclass::defaultpackage, "_usablink_");
+	disp.setmacro("usabinterface", displayclass::defaultpackage, ("_usab"+(*check).second+"_"));
+	disp.setmacro("usabilityscript", displayclass::defaultpackage, "_usabshowscript_");
+      }
+    }
+  }
+  
+  
+  if (arg_p == "home" || arg_p == "homehelp") {
+    if (status_disabled) disp.setmacro ("textgoadmin", "home", "");
+    if (collector_disabled) disp.setmacro ("textgocollector", "home", "");
+    if (depositor_disabled) disp.setmacro ("textgodepositor", "home", "");
+    if (translator_disabled) disp.setmacro ("textgotranslator", "home", "");
+
+    if (arg_p == "home") {
+      homepagestyle (disp, protos, args, logout);
+    } else if (arg_p == "homehelp") {
+      set_collectionlist_macro (disp, protos, args, logout);
+    }
+
+  } else if (arg_p == "gli") {
+    if (gliapplet_disabled) disp.setmacro ("gliapplet", "gli", "");
+
+  } else if (arg_p == "homepref") {
+  
+    // set _languageoption_ and _encodingoption_
+    set_language_encoding_macros(disp, args, protos, cinfo, logout);
+
+  } else if (arg_p == "preferences") {
+  
+    if (cinfo == NULL) {
+      disp.setmacro("cvariable", displayclass::defaultpackage, arg_c);
+      disp.setmacro("content", arg_p, "<p>_textbadcollection_<p>");
+      return;
+    }
+
+    if (collectproto == NULL) {return;}
+    
+    // set _languageoption_ and _encodingoption_
+    set_language_encoding_macros(disp, args, protos, cinfo, logout);
+
+    // _collectionoption_
+    if ((args["ccs"] == "1") && (cinfo->ccsCols.size() > 1)) {
+      text_t collectionoption = "_textcollectionoption_";
+      text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
+      text_tarray::const_iterator col_end = cinfo->ccsCols.end();
+      int count = 0;
+      while (col_here != col_end) {
+	text_t colname;
+	if (*col_here == arg_c) {
+	    colname = cinfo->get_collectionmeta("collectionname", args["l"]);
+	} else {
+	  ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
+	  if (this_cinfo == NULL) {++col_here; continue;}
+	  colname = this_cinfo->get_collectionmeta("collectionname", args["l"]);
+	}
+	if (colname.empty()) {
+	  colname = *col_here;
+	}
+	++count;
+	collectionoption += "<input type=checkbox name=\"cc\" value=\"" + 
+	  *col_here + "\" onClick=\"updatecc(\'" + *col_here + "\');\"> " +
+	  colname + "<br>\n";
+	++col_here;
+      }
+      
+      if (count > 1)
+	disp.setmacro ("collectionoption", "preferences", collectionoption);
+    }
+
+    // _htmloptions_
+    
+    text_tmap::const_iterator it = cinfo->format.find ("DocumentUseHTML");
+    if ((it != cinfo->format.end()) && ((*it).second == "true")) {
+      disp.setmacro ("htmloptions", "preferences", "_htmloptionson_");
+
+
+      // _PreferenceDocsFromWeb_
+
+      it = cinfo->format.find ("PreferenceDocsFromWeb");
+      if ((it == cinfo->format.end()) || ((*it).second == "true"))
+	disp.setmacro ("PreferenceDocsFromWeb", "preferences", "1");
+    }
+
+    // _prefschanged_
+    if (!args["bp"].empty()) {
+      disp.setmacro ("prefschanged", "preferences", "_textprefschanged_");
+    }
+    
+  } else if (arg_p == "about" || arg_p == "help") {
+    if (collectproto == NULL) return;
+
+    comerror_t err;
+    bool has_search_button = true;
+    collectproto->is_searchable(args["c"], has_search_button, err, logout);
+    if (err != noError) has_search_button = true;
+    
+    // _textbrowseoptions_ and _numbrowseoptions_
+    
+    FilterResponse_t response;
+    text_tset metadata;
+    metadata.insert ("Title");
+    //****************
+    metadata.insert ("childtype");
+    //****************
+    bool getParents = false;
+    get_children ("", args["c"], args["l"], metadata, getParents, collectproto, response, logout);
+
+    int numbrowseoptions = response.docInfo.size();
+    if (has_search_button) numbrowseoptions += 1;
+    disp.setmacro ("numbrowseoptions", "help", numbrowseoptions);
+
+    ResultDocInfo_tarray::iterator here = response.docInfo.begin();
+    ResultDocInfo_tarray::iterator end = response.docInfo.end();
+
+    text_t helptext;
+    if (has_search_button) {
+      helptext = "<ul><li>_textSearchhelp_\n";
+    }
+
+    // ********************************      
+    int classifiernumber = 0;
+    bool collage = false;
+
+    while (here != end) {
+      
+      ++classifiernumber;
+      text_t childtype = (*here).metadata["childtype"].values[0];
+      if (childtype == "Collage" && arg_p == "about") {
+	// get the classifier number
+	disp.setmacro ("classifier", "about", classifiernumber);
+	disp.setmacro ("aboutCollage", "about", "_collageapplet_");
+	collage = true;
+      }
+      ++here;
+    } 
+    if (! collage)
+      disp.setmacro ("aboutCollage", "about", "_collageempty_");
+	
+    // ********************************
+     
+    here = response.docInfo.begin();
+
+    while (here != end) {
+      
+      text_t title = (*here).metadata["Title"].values[0];
+    
+      text_t stext;
+      disp.expandstring ("help", "_text" + title + "help_", stext);
+      if (stext == ("_text" + title + "help_")) {
+	text_t ltext, ttext;
+	disp.expandstring("Global", "_label"+title+"_", ltext);
+	if (ltext == ("_label"+title+"_")) {
+	  ltext = title;
+	}
+	disp.expandstring("Global", "_text"+title+"_", ttext);
+	if (ttext == ("_text"+title+"_")) {
+	  ttext = title;
+	}
+	helptext += "<li>_help:textdefaulthelp_("+ttext+","+ltext+")";
+      } else {
+	helptext += "<li>_help:text" + title + "help_";
+      }
+
+      ++here;
+    }
+    helptext += "</ul>\n";
+    disp.setmacro ("textbrowseoptions", "help", helptext);
+
+    if (arg_p == "help") {
+      // do we need to add in the datesearch help??
+      text_tmap::iterator check = cinfo->format.find("QueryInterface");
+      if(check != cinfo->format.end()){
+	if((*check).second=="DateSearch"){
+	  text_t current = "_datesearch_";
+	  disp.setmacro("optdatesearchhelp","help","_datesearchhelp_");
+	  disp.setmacro("optdatesearchhelpcontents","help","_datesearchhelpcontents_");
+	}
+      }
+      
+    }
+    
+    if (arg_p == "about") {
+
+      // _textsubcollections_
+      if (args["ccs"] == "1" && (cinfo->ccsCols.size() > 1)) {
+	text_t textsubcollections = "_textsubcols1_(" + text_t(cinfo->ccsCols.size()) + ")";
+	text_tarray::const_iterator here = cinfo->ccsCols.begin();
+	text_tarray::const_iterator end = cinfo->ccsCols.end();
+	bool first = true;
+	int count = 0;
+	while (here != end) {
+	  if (*here == arg_c) {
+	    if (!first) textsubcollections += "<br>";
+	    textsubcollections += "\n" + cinfo->get_collectionmeta("collectionname", args["l"]) + "\n";
+	  } else {
+	    ColInfoResponse_t *this_cinfo = recpt->get_collectinfo_ptr (collectproto, *here, logout);
+	    if (this_cinfo == NULL) {++here; continue;}
+	    if (!first) textsubcollections += "<br>";
+	    textsubcollections += "\n" + this_cinfo->get_collectionmeta("collectionname", args["l"]) + "\n";
+	  }
+	  ++count;
+	  first = false;
+	  ++here;
+	}
+	textsubcollections += "_textsubcols2_";
+	if (count > 1) {
+	  disp.setmacro ("textsubcollections", "about", textsubcollections);
+	}
+      }
+
+      comerror_t err;
+      bool issearchable = true;
+      collectproto->is_searchable(args["c"], issearchable, err, logout);
+      if (err != noError) issearchable = true;
+      outconvertclass t;
+      if (!issearchable ) {
+	disp.setmacro ("aboutqueryform", "about", "");
+      }
+    }
+
+  } else if (arg_p == "docs") {
+
+    set_documentation_macro (disp);
+
+  } else if (arg_p == "bsummary" && !arg_c.empty()) {
+
+    set_macro_to_file_contents (disp, "importlog", "bsummary",
+				filename_cat(collecthome, arg_c, "etc", "import.log"));
+    set_macro_to_file_contents (disp, "faillog", "bsummary",
+				filename_cat(collecthome, arg_c, "etc", "fail.log"));
+    set_macro_to_file_contents (disp, "buildlog", "bsummary",
+				filename_cat(collecthome, arg_c, "etc", "build.log"));
+  }
+}
+
+bool pageaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/, 
+			    browsermapclass * /*browsers*/, displayclass &disp, 
+			    outconvertclass &outconvert, ostream &textout, 
+			    ostream &/*logout*/) {
+
+  text_t &arg_p = args["p"];
+
+  textout << outconvert << disp << ("_" + arg_p + ":header_\n")
+	  << ("_" + arg_p + ":content_\n")
+	  << ("_" + arg_p + ":footer_\n");
+
+  return true;
+}
+
+void pageaction::configure (const text_t &key, const text_tarray &cfgline) {
+  if ((key == "status") && (cfgline.size() == 1) && 
+      (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
+    status_disabled = false;
+  } else if ((key == "collector") && (cfgline.size() == 1) && 
+	     (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
+    collector_disabled = false;
+  }
+ else if ((key == "depositor") && (cfgline.size() == 1) && 
+	     (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
+    depositor_disabled = false;
+  }
+    else if ((key == "translator") && (cfgline.size() == 1) && 
+	     (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
+    translator_disabled = false;
+  } else if ((key == "gliapplet") && (cfgline.size() == 1) && 
+	     (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
+    gliapplet_disabled = false;
+  }
+  else {
+    // call the parent class to deal with the things which
+    // are not dealt with here
+    action::configure (key, cfgline);
+  }
+}
+
+
+
+
+
+
+
+
+
+
Index: /gsdl/trunk/runtime-src/src/recpt/pageaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/pageaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/pageaction.h	(revision 16571)
@@ -0,0 +1,104 @@
+/**********************************************************************
+ *
+ * pageaction.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef PAGEACTION_H
+#define PAGEACTION_H
+
+
+#include "gsdlconf.h"
+#include "action.h"
+#include "receptionist.h"
+
+
+class pageaction : public action {
+  
+protected:
+  receptionist *recpt;
+
+  text_tset classify_meta;
+
+public:
+  pageaction ();
+  virtual ~pageaction ();
+
+  void set_receptionist (receptionist *therecpt) {recpt=therecpt;}
+
+  text_t get_action_name () {return "p";}
+  
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass *protos, ostream &logout);
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response,text_t &response_data, 
+			 ostream &logout);
+
+  void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+  void configure (const text_t &key, const text_tarray &cfgline);
+
+ protected:
+  
+  void home_images (displayclass &disp, recptprotolistclass *protos, 
+		   cgiargsclass &args, const recptconf &configinfo, ostream &logout);
+  
+  void home_pulldown (displayclass &disp, recptprotolistclass *protos, 
+		      cgiargsclass &args, const recptconf &configinfo, ostream &logout);
+  
+  void homepagestyle (displayclass &disp, recptprotolistclass *protos, 
+		      cgiargsclass &args, ostream &logout);
+  
+
+  
+  void set_collectionlist_macro (displayclass &disp, recptprotolistclass *protos, 
+				 cgiargsclass &args, ostream &logout);
+
+  void set_documentation_macro (displayclass &disp);
+
+  void set_macro_to_file_contents (displayclass &disp, const text_t &macroname,
+				   const text_t &packagename, const text_t &filename);
+
+  void set_language_encoding_macros(displayclass &disp, cgiargsclass &args,
+				    recptprotolistclass *protos, ColInfoResponse_t *cinfo,
+				    ostream &logout);
+
+
+  
+  bool status_disabled;
+  bool collector_disabled;
+  bool depositor_disabled;
+  bool translator_disabled;
+  bool gliapplet_disabled;
+
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/pagedbrowserclass.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/pagedbrowserclass.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/pagedbrowserclass.cpp	(revision 16571)
@@ -0,0 +1,208 @@
+/**********************************************************************
+ *
+ * pagedbrowserclass.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_PAGED_BROWSER
+
+#include "pagedbrowserclass.h"
+#include <assert.h>
+#include "recptprototools.h"
+#include "OIDtools.h"
+#include "gsdltools.h"
+
+pagedbrowserclass::pagedbrowserclass () {
+}
+
+pagedbrowserclass::~pagedbrowserclass () {
+}
+
+// returns the name that specifies the browserclass type
+text_t pagedbrowserclass::get_browser_name () {
+  return "Paged";
+}
+
+browserclass* pagedbrowserclass::clone()
+{
+  return new pagedbrowserclass();
+}
+
+void pagedbrowserclass::load_metadata_defaults (text_tset &metadata) {
+  metadata.insert ("Title");
+}
+
+// if the "gp" (go to page) argument is set we need to set
+// the "d" argument to the corresponding page
+// also want to set "d" argument to first child if we're at
+// an 'Invisible' top level
+void pagedbrowserclass::processOID (cgiargsclass &args, recptproto *collectproto,
+                                    ostream &logout) {
+
+  text_t &arg_d = args["d"];
+  text_t &arg_gp = args["gp"];
+  text_tset metadata;
+  bool getParents = false;
+  FilterResponse_t response;
+
+  if (!arg_d.empty() && !arg_gp.empty()) {
+    text_t top;
+    get_top (arg_d, top);
+    metadata.insert ("Title");
+    get_children (top, args["c"], args["l"], metadata, getParents, collectproto, response, logout);
+    ResultDocInfo_tarray::iterator dochere = response.docInfo.begin();
+    ResultDocInfo_tarray::iterator docend = response.docInfo.end();
+    while (dochere != docend) {
+      if ((*dochere).metadata["Title"].values[0] == arg_gp) {
+        arg_d = (*dochere).OID;
+        return;
+      }
+      ++dochere;
+    }
+  }
+
+  // The "gp" argument was either empty or invalid, so display the first child if given a document OID
+  if (!arg_d.empty() && is_top(arg_d)) { // if top level doc, check if not invisible
+    metadata.insert("thistype");
+    if (get_info(arg_d, args["c"], args["l"], metadata, getParents, collectproto, response, logout)) {
+      text_t type = response.docInfo[0].metadata["thistype"].values[0];
+      if (type=="Invisible") { // display first child
+        arg_d = arg_d + ".fc";
+      }
+    }
+  }
+}
+
+int pagedbrowserclass::output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
+					     const text_t &/*collection*/, int /*colnumber*/, 
+					     format_t * /*formatlistptr*/, bool /*use_table*/, 
+					     text_tset &/*metadata*/, bool &/*getParents*/,
+					     recptproto * /*collectproto*/, displayclass &disp, 
+					     outconvertclass &outconvert, ostream &textout, 
+					     ostream &/*logout*/) {
+
+  // this browser class only handles document levels
+  if (args["d"].empty()) return 0;
+
+  if (section.OID != args["d"]) {
+    text_t httpprevarrow = "_httpdocument_&cl=" + args["cl"] + "&d=" + dm_safe(section.OID);
+    text_t parentarrow = "<a href=\"" + httpprevarrow + "\">_iconprev_</a>\n";
+    disp.setmacro ("httpprevarrow", "document", httpprevarrow);
+    disp.setmacro ("parentarrow", "document", parentarrow);
+    return 0;
+  }
+
+  // must be at top level to get to here!
+  textout << outconvert << disp << "<b>" << section.metadata["Title"].values[0] 
+	  << "_document:textintro_</b>\n";
+  
+  return 0;
+}
+
+int pagedbrowserclass::output_section_group (FilterResponse_t &sections, cgiargsclass &args,
+					     const text_t &/*collection*/, int /*colnumber*/, 
+					     format_t * /*formatlistptr*/, bool /*use_table*/, 
+					     text_tset &/*metadata*/, bool &/*getParents*/,
+					     recptproto * /*collectproto*/, displayclass &disp, 
+					     outconvertclass &outconvert, ostream &textout, 
+					     ostream &/*logout*/) {
+
+  text_t &arg_d = args["d"];
+
+  // this browser class only handles document levels
+  if (arg_d.empty()) return 0;
+
+  text_t previousOID, previoustitle, nextOID, nexttitle;
+  text_t prevarrow, nextarrow, httpprevarrow, httpnextarrow;
+  bool found = false;
+
+  // this should be our list of pages
+
+  ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
+  ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
+
+  while (thissection != endsection) {
+    if (arg_d == (*thissection).OID) {
+      found = true;
+      textout << outconvert << disp 
+	      << "<table><tr valign=top><td colspan=3><center><b>_page_"
+	      << (*thissection).metadata["Title"].values[0] << "</b>\n";
+      if (thissection != sections.docInfo.begin()) {
+	previousOID = (*(thissection-1)).OID;
+	previoustitle = (*(thissection-1)).metadata["Title"].values[0];
+      } else {
+	prevarrow = "_document:parentarrow_";
+      }
+
+      if ((thissection+1) != endsection) {
+	nextOID = (*(thissection+1)).OID;
+	nexttitle = (*(thissection+1)).metadata["Title"].values[0];
+      }
+      break;
+    }
+    ++thissection;
+  }
+
+  if (!found) {
+    textout << outconvert << disp 
+	    << "<table><tr valign=top> <td colspan=3><center>\n";
+  }
+  int numpages = sections.docInfo.size();
+  textout << outconvert << disp 
+	  << ("_document:textnumpages_(" + text_t(numpages) + ")</center></td></tr>\n");
+
+  disp.setmacro ("numpages", "document", numpages);
+
+  if (!found) {
+    httpnextarrow = "_httpdocument_&cl=" + args["cl"] + "&d=" + sections.docInfo[0].OID;
+    nextarrow = "<a href=\"" + httpnextarrow + "\">" + 
+      sections.docInfo[0].metadata["Title"].values[0] + "_iconnext_</a>\n";
+
+  } else {
+    if (!previousOID.empty()) {
+      httpprevarrow = "_httpdocument_&cl=" + args["cl"] + "&d=" + dm_safe(previousOID);
+      prevarrow = "<a href=\"" + httpprevarrow + "\">_iconprev_" + previoustitle + "</a>\n";
+    }
+    if (!nextOID.empty()) {
+      httpnextarrow = "_httpdocument_&cl=" + args["cl"] + "&d=" + dm_safe(nextOID);
+      nextarrow = "<a href=\"" + httpnextarrow + "\">" + nexttitle + "_iconnext_</a>\n";
+    }
+  }
+
+  if (!httpprevarrow.empty()) disp.setmacro ("httpprevarrow", "document", httpprevarrow);
+  if (!httpnextarrow.empty()) disp.setmacro ("httpnextarrow", "document", httpnextarrow);
+
+  if (!prevarrow.empty()) disp.setmacro ("prevarrow", "document", prevarrow);
+  if (!nextarrow.empty()) disp.setmacro ("nextarrow", "document", nextarrow);
+
+
+  textout << outconvert << disp << "<tr valign=middle>\n"
+	  << "<td align=right>" << prevarrow << "</td>\n"
+	  << "<td align=center valign=top>_document:gotoform_</td>"
+	  << "<td align=left>" << nextarrow << "</td>\n"
+	  << "</tr></table>\n";
+
+  return 0;
+}
+
+#endif //GSDL_USE_PAGED_BROWSER
Index: /gsdl/trunk/runtime-src/src/recpt/pagedbrowserclass.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/pagedbrowserclass.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/pagedbrowserclass.h	(revision 16571)
@@ -0,0 +1,68 @@
+/**********************************************************************
+ *
+ * pagedbrowserclass.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_PAGED_BROWSER
+
+#ifndef PAGEDBROWSERCLASS_H
+#define PAGEDBROWSERCLASS_H
+
+#include "browserclass.h"
+
+class pagedbrowserclass : public browserclass {
+protected:
+
+public:
+
+  pagedbrowserclass ();
+  virtual ~pagedbrowserclass ();
+
+  // returns the name that specifies the browserclass type
+  virtual text_t get_browser_name ();
+
+  virtual browserclass* clone();
+
+  void load_metadata_defaults (text_tset &metadata);
+
+  virtual void processOID (cgiargsclass &args, recptproto *collectproto,
+			   ostream &logout);
+
+
+  virtual int output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
+				    const text_t &collection, int colnumber, format_t *formatlistptr, 
+				    bool use_table, text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, ostream &logout);
+
+  virtual int output_section_group (FilterResponse_t &sections, cgiargsclass &args,
+				    const text_t &collection, int colnumber, format_t *formatlistptr, 
+				    bool use_table, text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, ostream &logout);
+
+};
+
+#endif //!PAGEDBROWSERCLASS_H
+#endif //GSDL_USE_PAGED_BROWSER
Index: /gsdl/trunk/runtime-src/src/recpt/phindaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/phindaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/phindaction.cpp	(revision 16571)
@@ -0,0 +1,1062 @@
+/**********************************************************************
+ *
+ * phindaction.cpp -- 
+ *
+ * Copyright 2001 Gordon W. Paynter
+ * Copyright 2001 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_PHIND_ACTION
+
+// Note that this action uses mgpp to retrieve phind info, calling MGQuery
+// etc. directly, not through the protocol. This breaks our receptionist -
+// collection server separation and should be fixed some day I guess.
+
+#include "phindaction.h"
+#include "fileutil.h"
+
+phindaction::phindaction () {
+
+  cgiarginfo arg_ainfo;
+
+  arg_ainfo.shortname = "pc";
+  arg_ainfo.longname = "phind classifier";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "pxml";
+  arg_ainfo.longname = "phind XML mode";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "ppnum";
+  arg_ainfo.longname = "phind phrase number";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "pptext";
+  arg_ainfo.longname = "phind phrase text";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "pfe";
+  arg_ainfo.longname = "phind first_e";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "ple";
+  arg_ainfo.longname = "phind last_e";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "10";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "pfl";
+  arg_ainfo.longname = "phind first_l";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "pll";
+  arg_ainfo.longname = "phind last_l";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "10";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "pfd";
+  arg_ainfo.longname = "phind first_d";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "pld";
+  arg_ainfo.longname = "phind last_d";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "10";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+}
+
+phindaction::~phindaction () {
+}
+
+void phindaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass * /*protos*/,
+				    response_t &response,text_t &response_data, 
+				    ostream &/*logout*/) {
+  response = content;
+  if (args["pxml"] == "1") {
+    response_data = "text/xml";
+  } else {
+    response_data = "text/html";
+  }
+}
+
+bool phindaction::do_action (cgiargsclass &args, recptprotolistclass *protos, 
+			     browsermapclass * /*browsers*/, displayclass &disp, 
+			     outconvertclass &outconvert, ostream &textout, 
+			     ostream &logout) {
+
+  unsigned long count_l, count_e, count_d;
+  unsigned long phrase = args["ppnum"].getulong();
+  text_t &word = args["pptext"];
+  unsigned long first_e = args["pfe"].getulong();
+  unsigned long last_e = args["ple"].getulong();
+  unsigned long first_l = args["pfl"].getulong();
+  unsigned long last_l = args["pll"].getulong();
+  unsigned long first_d = args["pfd"].getulong();
+  unsigned long last_d = args["pld"].getulong();
+  bool XMLmode = false;
+  if (args["pxml"] == "1") XMLmode = true;
+
+  // must have a valid collection server
+  recptproto *collectproto = protos->getrecptproto (args["c"], logout);
+  if (collectproto == NULL) {
+    output_error("phindaction: ERROR: collection not set", textout, 
+		 outconvert, disp, logout, XMLmode);
+    return true;
+  }
+
+  // the frequency and occurances of the phrase
+  unsigned long tf;
+  vector <unsigned long> el, linkdest, docNums, docfreq;
+  vector <UCArray> linktype;
+
+  // the number of occurances to display
+  unsigned long ef, lf, df;
+  
+  text_t basepath = filename_cat(collecthome, args["c"], 
+				 "index", "phind" + args["pc"]);
+
+  // If we don't know the phrase number, look it up
+  if (phrase == 0) {
+    
+    if (word.empty()) {
+      output_error("phindaction: ERROR: no phrase number or word", textout, 
+		   outconvert, disp, logout, XMLmode);
+      return true;
+    }
+
+    DocNumArray result;
+    /** In order to prevent browser crashing problems, any method which
+     *  previously suffered a silent fatal error, now instead returns false
+     *  to indicate a fatal error has occured. We can then dispatch an
+     *  appropriate error tag to the Phind applet (rather than leave it
+     *  whiling away the milliseconds until the end of existence - or at
+     *  least your browser - in an infinite loop!)
+     *  DLConsulting 12-07-2004
+     */
+    if(!find_phrase_number_from_word(basepath, word, result)) {
+	output_error("phindaction: Fatal Error! Couldn't load index information in find_phrase_number_from_word()",
+		     textout, outconvert, disp, logout, XMLmode);
+	return true;
+    }
+    
+    if (result.empty()) {
+      output_error("phindaction: The search term does not occur in the collection",
+		   textout, outconvert, disp, logout, XMLmode);
+      return true;
+    } else {
+      phrase = result[0];
+    }
+  } 
+
+  // Create a TextData object to read the phrase data (pdata)
+  TextData textdata;
+
+  text_t fullpath = filename_cat(basepath, "pdata");
+  char *fullpathc = fullpath.getcstr();
+#if defined __WIN32__
+  char *base = "";
+#else
+  char *base = "/";
+#endif
+
+  if (!textdata.LoadData (base, fullpathc)) {
+    //    FatalError (1, "Couldn't load text information for \"%s\"", fullpathc);
+    //exit(0);
+    /** We must return something to the client, whether this error is fatal or 
+     *  no, otherwise we risk sending their browser into an infinite loop!
+     *  DLConsulting 12-07-2004
+     */
+    output_error("phindaction: Fatal Error! Couldn't load text information for collection",
+		 textout, outconvert, disp, logout, XMLmode);
+    return true;
+  }
+
+  delete []fullpathc;
+
+  /** Another previously silent method can now cry out.
+   *  DLConsulting 12-07-2004
+   */
+  if(!get_phrase_all_data(textdata, phrase, word, tf, ef, lf, df, el, 
+			  linkdest, linktype, docNums, docfreq)) {
+    output_error(
+      "phindaction: Fatal Error! Couldn't parse phrase in get_phrase_all_data()",
+      textout, outconvert, disp, logout, XMLmode);
+      return true;    
+  }
+
+  // Output the header
+  if (XMLmode) {
+    textout << "<phinddata id=\"" << phrase 
+	    << "\" text=\"" << word 
+	    << "\" tf=\"" << tf 
+	    << "\" ef=\"" << ef 
+	    << "\" df=\"" << df 
+	    << "\" lf=\"" << lf 
+	    << "\">\n";
+  } else {
+    textout << "<html><head><title>" << word << "</title></head>\n"
+	    << "<body><center>\n"
+	    << "<p><h1>" << word << "</h1>\n"
+	    << "<p><b>"<< word << "</b> occurs " 
+	    << tf << " times in " << df << " documents\n";
+  }
+
+  // Output the thesaurus links
+  if ((lf > 0) && (first_l < last_l)) {
+
+    // figure out the number of phrases to output
+    if (last_l > lf) {
+      last_l = lf;
+    }
+    count_l = last_l - first_l;
+    
+    if (XMLmode) {
+      textout << "<thesauruslist length=\"" << lf 
+	      << "\" start=\"" << first_l
+	      << "\" end=\"" << last_l << "\">\n";
+      /** DLConsulting 12-07-2004 */
+      if(!print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype,
+			       first_l, last_l, disp, outconvert, textout)) {
+	output_error(
+		     "phindaction: Fatal Error! Couldn't get phrase in get_phrase_freq_data()",
+		     textout, outconvert, disp, logout, XMLmode);
+	return true;	
+      }
+      textout << "</thesauruslist>\n";
+    }
+
+    // output links as HTML
+    else {
+      if (count_l == lf) {
+	textout << "<p><b> " << count_l << " thesaurus links</b>\n";
+      } else {
+	textout << "<p><b>" << count_l << " of " << lf << " thesaurus links</b>\n";
+      }
+
+      textout << "<p><table border=1><tr><th>type</th><th>topic</th><th>freq</th><th>docs</th></tr>\n";
+      /** DLConsulting 12-07-2004 */
+      if(!print_thesaurus_links(args["c"], XMLmode, textdata, linkdest, linktype, 
+			       first_l, last_l, disp, outconvert, textout)) {
+	output_error(
+		     "phindaction: Fatal Error! Couldn't get phrase in get_phrase_freq_data()",
+		     textout, outconvert, disp, logout, XMLmode);
+	return true;
+      }
+      textout << "</table>\n";
+
+      if (last_l < lf) {
+	if ((last_l + 10) < lf) {
+	  textout << outconvert << disp 
+		  << "<br><a href=\"_gwcgi_?"
+		  << "c=" << args["c"]
+		  << "&ppnum=" << phrase 
+		  << "&pfe=" << first_e 
+		  << "&ple=" << last_e 
+		  << "&pfd=" << first_d 
+		  << "&pld=" << last_d
+		  << "&pfl=" << first_l 
+		  << "&pll=" << (last_l + 10)
+		  << "\">Get more thesaurus links</a>\n"; 
+	}
+	textout << outconvert << disp
+		<< "<br><a href=\"_gwcgi_?"
+		<< "c=" << args["c"]
+		<< "&ppnum=" << phrase 
+		<< "&pfe=" << first_e 
+		<< "&ple=" << last_e 
+		<< "&pfd=" << first_d 
+		<< "&pld=" << last_d 
+		<< "&pfl=" << first_l 
+		<< "&pll=" << lf
+		<< "\">Get every thesaurus link</a>\n" ;
+      }
+    }
+  }
+  
+  // Output the expansions
+  if ((ef > 0) && (first_e < last_e)) {
+
+    // figure out the number of phrases to output
+    if (last_e > el.size()) {
+      last_e = el.size();
+    }
+    count_e = last_e - first_e;
+
+    // output expansions as XML
+    if (XMLmode) {
+      textout << "<expansionlist length=\"" << ef 
+	      << "\" start=\"" << first_e
+	      << "\" end=\"" << last_e << "\">" << endl;
+
+      print_expansions(args["c"], XMLmode, word, textdata, el, first_e,
+		       last_e, disp, outconvert, textout);
+
+      textout << "</expansionlist>\n";
+    }
+
+    // output expansions as HTML
+    else {
+      if (count_e == el.size()) {
+	textout << "<p><b> " << count_e << " expansions</b>\n";
+      } else {
+	textout << "<p><b>" << count_e << " of " << ef << " expansions</b>\n";
+      }
+
+      textout << "<p><table border=1><tr><th colspan=3>phrase</th><th>freq</th><th>docs</th></tr>\n";
+      print_expansions(args["c"], XMLmode, word, textdata, el, first_e, 
+		       last_e, disp, outconvert, textout);
+      textout << "</table>\n";
+
+      if (last_e < ef) {
+	if ((last_e + 10) < ef) {
+	  textout << outconvert << disp 
+		  << "<br><a href=\"_gwcgi_?"
+		  << "c=" << args["c"]
+		  << "&ppnum=" << phrase 
+		  << "&pfe=" << first_e 
+		  << "&ple=" << (last_e + 10) 
+		  << "&pfd=" << first_d 
+		  << "&pld=" << last_d 
+		  << "&pfl=" << first_l 
+		  << "&pll=" << last_l
+		  << "\">Get more expansions</a>\n";
+	}
+	textout << outconvert << disp
+		<< "<br><a href=\"_gwcgi_?"
+		<< "c=" << args["c"]
+		<< "&ppnum=" << phrase 
+		<< "&pfe=" << first_e 
+		<< "&ple=" << ef
+		<< "&pfd=" << first_d 
+		<< "&pld=" << last_d 
+		<< "&pfl=" << first_l 
+		<< "&pll=" << last_l
+		<< "\">Get every expansion</a>\n";
+      }
+    }
+  }
+
+  // Output the document occurances
+  if ((df > 0) && (first_d < last_d)) {
+
+    // figure out the phrases to output
+    if (last_d > docNums.size()) {
+      last_d = docNums.size();
+    }
+    count_d = last_d - first_d;
+
+    // output document list as XML
+    if (XMLmode) {
+      textout << "<documentlist length=\"" << df 
+	      << "\" start=\"" << first_d
+	      << "\" end=\"" << last_d << "\">\n";
+      
+      if(!print_documents(XMLmode, basepath, args["c"], docNums, docfreq,
+			  first_d, last_d, disp, outconvert, textout)) {
+	output_error(
+		     "phindaction: Fatal Error! Couldn't load text information in print_documents() or get_document_all_data()",
+		     textout, outconvert, disp, logout, XMLmode);
+	return true;	
+      }
+
+      textout << "</documentlist>\n";
+    }
+
+    // output document list as HTML 
+    else {
+      
+      if (count_d == docNums.size()) {
+	textout << "<p><b> " << count_d << " documents</b>\n";
+      } else {
+	textout << "<p><b>" << count_d << " of " << df << " documents</b>\n";
+      }
+
+      textout << "<p><table border=1><tr><th align=left>document</th><th>freq</th></tr>\n";
+      if(!print_documents(XMLmode, basepath, args["c"], docNums, docfreq, 
+			  first_d, last_d, disp, outconvert, textout)) {
+	output_error(
+		     "phindaction: Fatal Error! Couldn't load text information in print_documents()",
+		     textout, outconvert, disp, logout, XMLmode);
+	return true;
+      }
+      textout << "</table>\n";
+      
+      if (last_d < df) {
+	if ((last_d + 10) < df) {
+	  textout << outconvert << disp
+		  << "<br><a href=\"_gwcgi_?"
+		  << "c=" << args["c"]
+		  << "&ppnum=" << phrase 
+		  << "&pfe=" << first_e 
+		  << "&ple=" << last_e 
+		  << "&pfd=" << first_d
+		  << "&pld=" << (last_d + 10)  
+		  << "&pfl=" << first_l 
+		  << "&pll=" << last_l
+		  << "\">Get more documents</a>\n";
+	}
+	textout << outconvert << disp 
+		<< "<br><a href=\"_gwcgi_?"
+		<< "c=" << args["c"]
+		<< "&ppnum=" << phrase 
+		<< "&pfe=" << first_e 
+		<< "&ple=" << last_e 
+		<< "&pfd=" << first_d 
+		<< "&pld=" << df
+		<< "&pfl=" << first_l 
+		<< "&pll=" << last_l
+		<< "\">Get every document</a>\n";
+      }
+    }
+  }
+
+  // Close the document
+  if (XMLmode) {
+    textout << "</phinddata>\n";
+  } else {
+    textout << "</center></body></html>\n";
+  }
+
+  textdata.UnloadData ();
+
+  return true;
+}
+
+// Find the phrase number of a word in the index file
+bool phindaction::find_phrase_number_from_word(const text_t &basepath, 
+					       const text_t &query, 
+					       DocNumArray &result) {
+
+  // Open the index file for searching
+  IndexData indexData;
+
+  text_t fullpath = filename_cat(basepath, "pword");
+  char *fullpathc = fullpath.getcstr();
+#if defined __WIN32__
+  char *base = "";
+#else
+  char *base = "/";
+#endif
+
+  if (!indexData.LoadData (base, fullpathc)) {
+    //    FatalError (1, "Couldn't load index information for \"%s\"", fullpathc);
+    //exit(0);
+    /** Don't handle fatal errors here anymore.
+     *  DLConsulting 12-07-2004
+     */
+    return false; // Indicates something very bad has happened
+  }
+
+  delete []fullpathc;
+
+  // set up the query object
+  QueryInfo queryInfo;
+  SetCStr (queryInfo.docLevel, "Document", 8);
+  queryInfo.maxDocs = 5;
+  queryInfo.sortByRank = true;
+  queryInfo.exactWeights = false;
+  queryInfo.needRankInfo = true;
+  queryInfo.needTermFreqs = true;
+  
+  // mode 1 = casefolded, unstemmed search
+  UCArray ucquery;
+  toUCArray(query, ucquery);
+  QueryNode *queryTree = ParseQuery(ucquery, 1, 1, 4);
+      
+  // perform the query
+  ExtQueryResult queryResult;
+  MGQuery (indexData, queryInfo, queryTree, queryResult);
+  // cout << "-- word lookup result -- " << endl << queryResult << endl ;
+
+  result.clear();
+  result = queryResult.docs;
+
+  // delete the query
+  if (queryTree != NULL) delete queryTree;
+
+  indexData.UnloadData();
+
+  /** This method now returns a boolean, so...
+   *  DLConsulting 12-07-2004
+   */
+  return true; // Indicates that what happened is all good, baby.
+}
+
+// Get all the data about a phrase
+//
+// The phrase is stored in textData as record phrase.
+// We retrieve:
+//   word - the text of the phrase
+//   tf - the total frequency of the phrase
+//   ef - the expansion frequency of the phrase
+//   lf - the thesaurus link frequency of the phrase
+//   df - the document frequency of the phrase
+//   el - the list of phrases that are expansions of phrase
+//   ll - the list of phrases that are thesaurus links 
+//   dl - the list of documents that contain phrase
+bool phindaction::get_phrase_all_data(TextData &textdata, unsigned long phrase,
+				      text_t &word, unsigned long &tf, unsigned long &ef,
+				      unsigned long &lf, unsigned long &df,
+				      vector <unsigned long> &el,
+				      vector <unsigned long> &linkdest,
+				      vector <UCArray> &linktype,
+				      vector <unsigned long> &docnum, 
+				      vector <unsigned long> &docfrq) {
+  UCArray text;
+  UCArray docLevel;
+  SetCStr(docLevel, "Document", 8);
+
+  // Look the word up in the textData
+  if (!GetDocText (textdata, docLevel, phrase, text)) {
+    //    FatalError (1, "Error while trying to get phrase %u", phrase);
+    //exit(0);
+    return false; // Something very bad has happened.
+  }
+
+  // Ignore everything up to the first colon
+  UCArray::iterator next = text.begin();
+  while (*next++ != ':');
+
+  // ignore training carriage returns
+  while (text.back() == '\n') {
+    text.pop_back();
+  }
+  
+  // Get the word
+  word.clear();
+  for (; *next != ':'; ++next) {
+    word.push_back(*next);
+  }
+  
+  // Get total frequency
+  tf = 0;
+  for (++next; *next != ':'; ++next) {
+    tf *= 10;
+    tf += (*next - '0');
+  }
+  
+  // Get expansion frequency
+  ef = 0;
+  for (++next; *next != ':'; ++next) {
+    ef *= 10;
+    ef += (*next - '0');
+  }
+  
+  // Get document frequency
+  df = 0;
+  for (++next; *next != ':'; ++next) {
+    df *= 10;
+    df += (*next - '0');
+  }
+  
+  // Get expansion list
+  el.clear();
+  unsigned long e = 0;
+  for (++next; *next != ':'; ++next) {
+    if (*next == ',') {
+      el.push_back(e);
+      e = 0;
+    } else {
+      e *= 10;
+      e += (*next - '0');
+    }
+  }
+
+  // Get document list & the document frequency list
+  docnum.clear();
+  docfrq.clear();
+  bool readnum = false;
+  unsigned long d = 0;
+  for (++next; *next != ':'; ++next) {
+    if (*next == ',') {
+      docnum.push_back(d);
+      readnum = true;
+      d = 0;
+    } else if (*next == ';') {
+      if (readnum) {
+	docfrq.push_back(d);
+      } else {
+	docnum.push_back(d);
+	docfrq.push_back(1);
+      }
+      readnum = false;
+      d = 0;
+    } else {
+      d *= 10;
+      d += (*next - '0');
+    }
+  }
+
+  // Get thesaurus link frequency & link list
+  text.push_back(':');
+  text.push_back(':');
+
+  // link frequency
+  lf = 0;
+  for (++next; *next != ':'; ++next) {
+    lf *= 10;
+    lf += (*next - '0');
+  }
+
+  // two lists of link data
+  linkdest.clear();
+  linktype.clear();
+  
+  UCArray thistype;
+  thistype.clear();
+  bool typedone = false;
+  unsigned long l = 0;
+  for (++next; *next != ':'; ++next) {
+    
+    if (!typedone) {
+      // first read the link type, a charactor string
+      if (*next == ',') {
+	typedone = true;
+      } else {
+	thistype.push_back(*next);
+      }
+    } else {
+      // having read the link type, read the list of link destinations
+      if (*next == ',') {
+	linkdest.push_back(l);
+	linktype.push_back(thistype);
+	l = 0;
+      } else if (*next == ';') {
+	linkdest.push_back(l);
+	linktype.push_back(thistype);
+	l = 0;
+	thistype.clear();
+	typedone = false;
+      } else {
+	l *= 10;
+	l += (*next - '0');
+      }
+    }
+  }
+
+  return true; // Indicates that what happened is all good, baby.
+}
+
+bool phindaction::print_thesaurus_links(const text_t &collection, bool XMLmode, 
+					TextData &textdata, vector <unsigned long> &linkdest,
+					vector <UCArray> &linktype, unsigned long first,
+					unsigned long last, displayclass &disp, 
+					outconvertclass &outconvert, ostream &textout) {
+
+  // information describing each link in the list
+  unsigned long phrase, tf, ef, df;
+  UCArray type, text;
+  
+  for (unsigned long l = first; l < last; ++l) {
+
+    // get the phrase data
+    phrase = linkdest[l];
+    type = linktype[l];
+
+    /** DLConsulting 12-07-2004 */
+    if(!get_phrase_freq_data(textdata, phrase, text, tf, ef, df)) {
+      return false;
+    }
+    
+    if (XMLmode) {
+      textout << "<thesaurus num=\"" << l 
+	      << "\" id=\"" << phrase
+	      << "\" tf=\"" << tf 
+	      << "\" df=\"" << df
+	      << "\" type=\"" << type
+	      << "\" text=\"" << text
+	      << "\"/>\n";
+    } else {
+      textout << "<tr valign=top><td>" << type << "</td><td>";
+      textout << outconvert << disp
+	      << "<a href=\"_gwcgi_?c=" << collection;
+      textout << "&ppnum=" << phrase << "\">" << text << "</a>"
+	      << "</td><td>" << tf << "</td><td>" << df << "</td></tr>\n";
+    }
+  }
+
+  /** DLConsulting 12-07-2004 */
+  return true;
+}
+
+// Get the frequency data about a phrase
+//
+// The phrase is stored in textData as record phrase.
+// We retrieve:
+//   word - the text of the phrase
+//   tf - the total frequency of the phrase
+//   ef - the expansion frequency of the phrase
+//   df - the document frequency of the phrase
+/**
+ *   Returns:
+ *     false if the method suffered a fatal error, true otherwise
+ */
+bool phindaction::get_phrase_freq_data(TextData &textdata, unsigned long phrase,
+				       UCArray &word, unsigned long &tf, 
+				       unsigned long &ef, unsigned long &df) {
+  
+  UCArray text;
+  UCArray docLevel;
+  SetCStr(docLevel, "Document", 8);
+
+  // Look the word up in the textData
+  if (!GetDocText (textdata, docLevel, phrase, text)) {
+    //    FatalError (1, "Error while trying to get phrase %u", phrase);
+    //exit(0);
+    /** DLConsulting 12-07-2004 */
+    return false;
+  }
+
+  // Ignore everything up to the first colon
+  UCArray::iterator next = text.begin();
+  while (*next++ != ':');
+  
+  // Get the word
+  word.clear();
+  for (; *next != ':'; ++next) {
+    word.push_back(*next);
+  }
+  
+  // Get total frequency
+  tf = 0;
+  for (++next; *next != ':'; ++next) {
+    tf *= 10;
+    tf += (*next - '0');
+  }
+  
+  // Get expansion frequency
+  ef = 0;
+  for (++next; *next != ':'; ++next) {
+    ef *= 10;
+    ef += (*next - '0');
+  }
+  
+  // Get document frequency
+  df = 0;
+  for (++next; *next != ':'; ++next) {
+    df *= 10;
+    df += (*next - '0');
+  }
+
+  /** DLConsulting 12-07-2004 */
+  return true;
+}
+
+// Print a list of expansions
+//
+// Given the textData and a list of phrase numbers, print out each of the
+// expansions.
+void phindaction::print_expansions(const text_t &collection, bool XMLmode, 
+				   const text_t &body, TextData &textdata, 
+				   const vector <unsigned long> &elist,
+				   unsigned long first, unsigned long last,
+				   displayclass &disp, outconvertclass &outconvert,
+				   ostream &textout) {
+  
+  UCArray word;
+  unsigned long phrase, tf, df, ef;
+
+  UCArray suffix, prefix, ucbody;
+  
+  toUCArray(body, ucbody);
+
+  for (unsigned long e = first; e < last; ++e) {
+
+    phrase = elist[e];
+    get_phrase_freq_data(textdata, phrase, word, tf, ef, df);
+
+    split_phrase(word, ucbody, prefix, suffix);
+    
+    if (XMLmode) {
+      // body is always the same as the text of the phrase, so no need to send it
+      textout << "<expansion num=\"" << e 
+	      << "\" id=\"" << phrase
+	      << "\" tf=\"" << tf 
+	      << "\" df=\"" << df;
+      if (!prefix.empty()) {
+	textout << "\" prefix=\"" << prefix;
+      }
+      if (!suffix.empty()) {
+	textout << "\" suffix=\"" << suffix;
+      }
+      textout << "\"/>\n";
+    } else {
+      textout << outconvert << disp 
+	      << "<tr valign=top><td align=right><a href=\"_gwcgi_?"
+	      << "c=" << collection << "&ppnum=" << phrase << "\">";
+      textout << prefix << "</a></td>";
+      textout <<outconvert << disp
+	      << "<td align=center><a href=\"_gwcgi_?"
+	      << "c=" << collection << "&ppnum=" << phrase << "\">"
+	      << body << "</a></td>"
+	      << "<td align=left><a href=\"_gwcgi_?"
+	      << "c=" << collection << "&ppnum=" << phrase << "\">";
+      textout << suffix << "</a></td>"
+	      << "<td>" << tf << "</td><td>" << df << "</td></tr>\n";
+    }
+  }
+}
+
+// split an expansion into prefix and suffix
+void phindaction::split_phrase(const UCArray &word, const UCArray &body, 
+			       UCArray &prefix, UCArray &suffix) {
+
+  prefix.clear();
+  suffix.clear();
+
+  bool readingPrefix = true;
+  UCArray::const_iterator here = word.begin();
+  UCArray::const_iterator end = word.end();
+  
+  while (here != end) {
+
+    // if we've not read all the prefix, add the next char to the prefix
+    if (readingPrefix) {
+      if (phrase_match(body, here, end)) {
+	readingPrefix = false;
+	// trim whitespace from end of prefix & start of suffix
+	if (!prefix.empty()) {
+	  prefix.pop_back();
+	}
+	if ((here != end) && (*here == ' ')) {
+	  ++here;
+	}
+      } else {
+	prefix.push_back(*here);
+	++here;
+      }
+    }
+    // if we've finished with the prefix, update the suffix
+    else {
+      suffix.push_back(*here);
+      ++here;
+    }
+  }
+}
+
+// phrase_match
+//
+// compare two strings, one represented as an UCArray, the other as two
+// UCArray iterators.
+//
+// Return true if the UCArray is the same as the phrase the iterators point
+// to for the length of the UCArray.
+bool phindaction::phrase_match(const UCArray &text, UCArray::const_iterator &here, 
+			       UCArray::const_iterator end) {
+
+  UCArray::const_iterator one_here = text.begin();
+  UCArray::const_iterator one_end  = text.end();
+  UCArray::const_iterator two_here = here;
+
+  // iterate over the length of the first string, comparing each element to
+  // the corresponding element in the second string.
+  while (one_here != one_end) {
+   
+      if (two_here == end) {
+	  return false;
+      } else if (*one_here != *two_here) {
+	  return false;
+      }
+      ++one_here;
+      ++two_here;
+  }
+
+  here = two_here;
+  return true;
+}
+
+bool phindaction::print_documents(bool XMLmode, const text_t &basepath, 
+				  const text_t &collection,
+				  const vector <unsigned long> &docNums, 
+				  const vector <unsigned long> &docFreq,
+				  unsigned long first, unsigned long last,
+				  displayclass &disp, outconvertclass &outconvert,
+				  ostream &textout) {
+  
+  // Create a TextData object to read the document data
+  TextData docdata;
+
+  text_t fullpath = filename_cat(basepath, "docs");
+  char *fullpathc = fullpath.getcstr();
+#if defined __WIN32__
+  char *base = "";
+#else
+  char *base = "/";
+#endif
+
+  if (!docdata.LoadData (base, fullpathc)) {
+    //    FatalError (1, "Couldn't load text information for \"%s\"", fullpathc);
+    //exit(0);
+    /** DLConsulting 12-07-2004 */
+    return false;
+  }
+
+  delete []fullpathc;
+
+  UCArray title, hash;
+  unsigned long freq, doc;
+
+  for (unsigned long d = first; d < last; ++d) {
+    doc = docNums[d];
+    freq = docFreq[d];
+
+    /** DLConsulting 13-07-2004 */
+    if(!get_document_all_data(docdata, doc, title, hash)) {
+      return false;
+    }
+
+    if (XMLmode) {
+      textout << "<document num=\"" << d
+	      << "\" hash=\"" << hash 
+	      << "\" freq=\"" << freq 
+	      << "\" title=\"" << title << "\"/>\n";
+    } else {
+      textout << outconvert << disp
+	      << "<tr valign=top><td><a href=\"_gwcgi_?"
+	      << "c=" << collection;
+      textout << "&a=d&d=" << hash << "\">" << title << "</a>"
+	      << "</td><td>" << freq << "</td></tr>\n"; 
+    }
+  }
+
+  docdata.UnloadData();
+
+  /** DLConsulting 12-07-2004 */
+  return true;
+}
+
+// Get all the data about a docment
+//
+// The document's details are stored in docData as record docNum.
+// We retrieve:
+//   title - the document's title
+//   hash - the document's unique OID
+/** Returns:
+ *   false if a fatal error occured, true otherwise
+ *  DLConsulting 12-07-2004
+ */
+bool phindaction::get_document_all_data(TextData &docdata, unsigned long docNum,
+					UCArray &title, UCArray &hash) {
+
+  UCArray text;
+  UCArray docLevel;
+  SetCStr(docLevel, "Document", 8);
+
+  // Look the word up in the textData
+  if (!GetDocText (docdata, docLevel, docNum, text)) {
+    //    FatalError (1, "Error while trying to get document %u", docNum);
+    //exit(0);
+    /** DLConsulting 13-07-2004 */
+    return false;
+  }
+
+  // Ignore everything up to the first colon
+  UCArray::iterator next = text.begin();
+  while (*next++ != '\t');
+  
+  // Get the document OID (hash)
+  hash.clear();
+  for (; *next != '\t'; ++next) {
+    hash.push_back(*next);
+  }
+
+  // Get the title
+  text.push_back('\n');
+  title.clear();
+  for (++next; *next != '\n'; ++next) {
+    title.push_back(*next);
+  }
+
+  /** DLConsulting 13-07-2004 */
+  return true;
+}
+
+void phindaction::toUCArray(const text_t &in, UCArray &out) {
+  out.clear();
+  if (out.capacity() < in.size() + 1) {
+    out.reserve(in.size() + 1);
+  }
+  text_t::const_iterator here = in.begin();
+  text_t::const_iterator end = in.end();
+  while (here != end) {
+    out.push_back((unsigned char) *here);
+    ++here;
+  }
+}
+
+void phindaction::output_error (const text_t &message, ostream &textout, 
+				outconvertclass &outconvert,
+				displayclass & disp, ostream &logout,
+				bool XMLmode) {
+
+  logout << outconvert << message << "\n";
+  if (XMLmode) {
+    textout << outconvert
+	    << "<phinddata>\n"
+	    << "<phinderror>" << message << "</phinderror>\n"
+	    << "</phinddata>\n";
+  } else {
+    textout << outconvert << disp 
+	    << "_header_\n" 
+	    << message
+	    << "_footer_\n";
+  }
+}
+
+#endif //GSDL_USE_PHIND_ACTION
+
Index: /gsdl/trunk/runtime-src/src/recpt/phindaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/phindaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/phindaction.h	(revision 16571)
@@ -0,0 +1,122 @@
+/**********************************************************************
+ *
+ * phindaction.h -- 
+ *
+ * Copyright 2001 Gordon W. Paynter
+ * Copyright 2001 The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_PHIND_ACTION
+
+#ifndef PHINDACTION_H
+#define PHINDACTION_H
+
+#include "action.h"
+
+// Include MGPP functionality.
+#include <TextGet.h>
+#include <MGQuery.h>
+#include <Terms.h>
+#include <messages.h>
+#include <GSDLQueryParser.h>
+
+class phindaction : public action {
+  
+protected:
+
+  bool find_phrase_number_from_word(const text_t &basepath, 
+				    const text_t &query, 
+				    DocNumArray &result);
+
+  bool get_phrase_all_data(TextData &textdata, unsigned long phrase,
+			   text_t &word, unsigned long &tf, unsigned long &ef,
+			   unsigned long &lf, unsigned long &df,
+			   vector <unsigned long> &el,
+			   vector <unsigned long> &linkdest,
+			   vector <UCArray> &linktype,
+			   vector <unsigned long> &docnum, 
+			   vector <unsigned long> &docfrq);
+
+  bool print_thesaurus_links(const text_t &collection, bool XMLmode, 
+			     TextData &textdata, vector <unsigned long> &linkdest,
+			     vector <UCArray> &linktype, unsigned long first,
+			     unsigned long last, displayclass &disp, 
+			     outconvertclass &outconvert, ostream &textout);
+
+  bool get_phrase_freq_data(TextData &textdata, unsigned long phrase,
+			    UCArray &word, unsigned long &tf, 
+			    unsigned long &ef, unsigned long &df);
+
+  void print_expansions(const text_t &collection, bool XMLmode, 
+			const text_t &body, TextData &textdata, 
+			const vector <unsigned long> &elist,
+			unsigned long first, unsigned long last,
+			displayclass &disp, outconvertclass &outconvert,
+			ostream &textout);
+
+  void split_phrase(const UCArray &word, const UCArray &body, 
+		    UCArray &prefix, UCArray &suffix);
+
+  bool phrase_match(const UCArray &text, UCArray::const_iterator &here, 
+		    UCArray::const_iterator end);
+
+  bool print_documents(bool XMLmode, const text_t &basepath, 
+		       const text_t &collection,
+		       const vector <unsigned long> &docNums, 
+		       const vector <unsigned long> &docFreq,
+		       unsigned long first, unsigned long last,
+		       displayclass &disp, outconvertclass &outconvert,
+		       ostream &textout);
+
+  bool get_document_all_data(TextData &docdata, unsigned long docNum,
+			     UCArray &title, UCArray &hash);
+
+  void toUCArray(const text_t &in, UCArray &out);
+
+  void output_error (const text_t &message, ostream &textout, 
+		     outconvertclass &outconvert,
+		     displayclass & disp, ostream &logout,
+		     bool XMLmode);
+
+
+public:
+  phindaction ();
+  virtual ~phindaction ();
+
+  text_t get_action_name () {return "phind";}
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response,text_t &response_data, 
+			 ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+
+};
+
+#endif //!PHINDACTION_H
+#endif //GSDL_USE_PHIND_ACTION
+
Index: /gsdl/trunk/runtime-src/src/recpt/phindbrowserclass.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/phindbrowserclass.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/phindbrowserclass.cpp	(revision 16571)
@@ -0,0 +1,51 @@
+/**********************************************************************
+ *
+ * phindbrowserclass.cpp -- 
+ *
+ * Copyright (C) 2000 The New Zealand Digital Library Project
+ *
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_PHIND_BROWSER
+
+#include "phindbrowserclass.h"
+#include <assert.h>
+#include "OIDtools.h"
+
+phindbrowserclass::phindbrowserclass () {
+}
+
+phindbrowserclass::~phindbrowserclass () {
+}
+
+// returns the name that specifies the browserclass type
+text_t phindbrowserclass::get_browser_name () {
+  return "Phind";
+}
+
+browserclass* phindbrowserclass::clone()
+{
+  return new phindbrowserclass();
+}
+
+#endif //GSDL_USE_PHIND_BROWSER
Index: /gsdl/trunk/runtime-src/src/recpt/phindbrowserclass.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/phindbrowserclass.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/phindbrowserclass.h	(revision 16571)
@@ -0,0 +1,59 @@
+/**********************************************************************
+ *
+ * phindbrowserclass.h -- 
+ *
+ * Copyright (C) 2000 The New Zealand Digital Library Project
+ *
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_PHIND_BROWSER
+
+// The phindbrowserclass is necessary to add a phind classifier to the user
+// interface and navigation bar, but is basically empty - all the work is
+// done in documentaction.cpp and in the document.dm macro file.  What
+// happens is that documentaction.cpp has a section that sets various
+// macros when the document in question is a phind classifier; thse are in
+// turn used by the macro file to load the applet into the web page.
+
+#ifndef PHINDBROWSERCLASS_H
+#define PHINDBROWSERCLASS_H
+
+#include "browserclass.h"
+
+class phindbrowserclass : public browserclass {
+protected:
+
+public:
+
+  phindbrowserclass ();
+  virtual ~phindbrowserclass ();
+
+  // returns the name that specifies the browserclass type
+  virtual text_t get_browser_name ();
+
+  virtual browserclass* clone();
+
+};
+
+#endif //!PHINDBROWSERCLASS_H
+#endif //GSDL_USE_PHIND_BROWSER
Index: /gsdl/trunk/runtime-src/src/recpt/pingaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/pingaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/pingaction.cpp	(revision 16571)
@@ -0,0 +1,87 @@
+/**********************************************************************
+ *
+ * pingaction.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_PING_ACTION
+
+#include "pingaction.h"
+
+pingaction::pingaction () {
+  // this action uses cgi variable "a"
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "ping";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+}
+
+void pingaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
+				   response_t &response, text_t &response_data, 
+				   ostream &/*logout*/) {
+  response = content;
+  response_data = "text/html";
+}
+
+
+bool pingaction::do_action (cgiargsclass &args, recptprotolistclass *protos, 
+			    browsermapclass * /*browsers*/, displayclass &/*disp*/, 
+			    outconvertclass &outconvert, ostream &textout, 
+			    ostream &logout) {
+  bool wassuccess = false;
+  comerror_t err;
+  
+  recptproto *collectproto = protos->getrecptproto (args["c"], logout);
+  if (!args["c"].empty() && (collectproto != NULL)) {
+    collectproto->ping (args["c"], wassuccess, err, logout);
+    if (err != noError) wassuccess = false; // a communication error
+  }
+
+  textout << outconvert
+	  << "<html>\n"
+	  << "<head>\n"
+	  << "<title>Ping</title>\n"
+	  << "</head>\n"
+	  << "<body>\n"
+	  << "Ping for \"" << args["c"] << "\" ";
+
+  if (wassuccess) {
+    textout << outconvert << " succeeded.\n";
+  } else {
+    textout << outconvert << " did not succeed.\n";
+  }
+
+  textout << outconvert 
+	  << "</body>\n"
+	  << "</html>\n";
+
+  return true;
+};
+
+#endif //GSDL_USE_PING_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/pingaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/pingaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/pingaction.h	(revision 16571)
@@ -0,0 +1,55 @@
+/**********************************************************************
+ *
+ * pingaction.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_PING_ACTION
+
+#ifndef PINGACTION_H
+#define PINGACTION_H
+
+#include "gsdlconf.h"
+#include "action.h"
+
+
+class pingaction : public action {
+public:
+  pingaction ();
+  virtual ~pingaction () {}
+
+  text_t get_action_name () {return "ping";}
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response, text_t &response_data, 
+			 ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+};
+
+
+#endif //!PINGACTION_H
+#endif //GSDL_USE_PING_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/queryaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/queryaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/queryaction.cpp	(revision 16571)
@@ -0,0 +1,1819 @@
+/**********************************************************************
+ *
+ * queryaction.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "queryaction.h"
+#include "querytools.h"
+#include "formattools.h"
+#include "cgiutils.h"
+#include "OIDtools.h"
+#include "fileutil.h"
+#include "text_t.h"
+#include "historydb.h"
+#include "htmlutils.h" // for html_safe in do_action
+#include "gsdltools.h"
+#include "phrases.h" // for get_phrases
+#include <stdlib.h> // for strtol
+#include <assert.h>
+
+void colinfo_t::clear () {
+  formatlistptr = NULL;
+  browserptr = NULL;
+}
+
+void QueryResult_t::clear() {
+  doc.clear();
+  collection.clear();
+}
+
+queryaction::queryaction () {
+
+  recpt = NULL;
+  num_phrases = 0;
+
+  // this action uses cgi variable "a"
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "q";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+  
+   // "ct" - 0 = mg, 1 = mgpp, 2=lucene
+  arg_ainfo.shortname = "ct";
+  arg_ainfo.longname = "collection type";
+  arg_ainfo.multiplechar = true; // can be empty or single char
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+ 
+  // "b" - 0 = simple, 1 = advanced
+  arg_ainfo.shortname = "b";
+  arg_ainfo.longname = "query mode";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "h"
+  arg_ainfo.shortname = "h";
+  arg_ainfo.longname = "main index";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "h2"
+  arg_ainfo.shortname = "h2";
+  arg_ainfo.longname = "main index for second query";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "j"
+  arg_ainfo.shortname = "j";
+  arg_ainfo.longname = "sub collection index";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "j2"
+  arg_ainfo.shortname = "j2";
+  arg_ainfo.longname = "sub collection index for second query";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "n"
+  arg_ainfo.shortname = "n";
+  arg_ainfo.longname = "language index";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "n2"
+  arg_ainfo.shortname = "n2";
+  arg_ainfo.longname = "language index for second query";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+
+  // "q"
+  arg_ainfo.shortname = "q";
+  arg_ainfo.longname = "query string";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "q2"
+  arg_ainfo.shortname = "q2";
+  arg_ainfo.longname = "query string for second query";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "cq2" ""=don't combine, "and", "or", "not"
+  arg_ainfo.shortname = "cq2";
+  arg_ainfo.longname = "combine queries";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "t" - 1 = ranked 0 = boolean
+  arg_ainfo.shortname = "t";
+  arg_ainfo.longname = "search type";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "1";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "k"
+  arg_ainfo.shortname = "k";
+  arg_ainfo.longname = "casefolding";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "1";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "ks"
+  arg_ainfo.shortname = "ks";
+  arg_ainfo.longname = "casefolding support";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+  
+  // "s"
+  arg_ainfo.shortname = "s";
+  arg_ainfo.longname = "stemming";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "ss"
+  arg_ainfo.shortname = "ss";
+  arg_ainfo.longname = "stemming support";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "af"
+  arg_ainfo.shortname = "af";
+  arg_ainfo.longname = "accentfolding";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "afs"
+  arg_ainfo.shortname = "afs";
+  arg_ainfo.longname = "accentfolding support";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+ 
+  // "m"
+  arg_ainfo.shortname = "m";
+  arg_ainfo.longname = "maximum number of documents";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "50";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "o"
+  arg_ainfo.shortname = "o";
+  arg_ainfo.longname = "hits per page";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "20";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "r"
+  arg_ainfo.shortname = "r";
+  arg_ainfo.longname = "start results from";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "1";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "ccs"
+  arg_ainfo.shortname = "ccs";
+  arg_ainfo.longname = "cross collection searching";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "ccp"
+  arg_ainfo.shortname = "ccp";
+  arg_ainfo.longname = "cross collection page";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "cc"
+  arg_ainfo.shortname = "cc";
+  arg_ainfo.longname = "collections to search";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.multiplevalue = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "hd" history display  - search history only displayed when
+  // this var set to something other than 0
+  // this number of records is displayed
+  arg_ainfo.shortname = "hd";
+  arg_ainfo.longname = "history display";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.multiplevalue = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+	    
+  // "hs"  save - set to 1 in query form, so only save when submit
+  // query
+  // 0 = no save 1 = save
+  arg_ainfo.shortname = "hs";
+  arg_ainfo.longname = "history save";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "g" - new arg for granularity, for mgpp collections
+  arg_ainfo.shortname = "g";
+  arg_ainfo.longname = "granularity";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText; 
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "ds" - start date
+  arg_ainfo.shortname = "ds";
+  arg_ainfo.longname = "start date";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "de" - end date
+  arg_ainfo.shortname = "de";
+  arg_ainfo.longname = "end date";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "dsbc" - whether or not start date is prechristian
+  arg_ainfo.shortname = "dsbc";
+  arg_ainfo.longname = "start date bc";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "debc" - whether or not end date is prechristian
+  arg_ainfo.shortname = "debc";
+  arg_ainfo.longname = "end date bc";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "qt" - 0 = text, 1 = form
+  arg_ainfo.shortname = "qt";
+  arg_ainfo.longname = "query type";
+  arg_ainfo.multiplechar = true; // can be empty or single char
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "qto" - 1 = text only, 2 = form only, 3 = text and form
+  arg_ainfo.shortname = "qto";
+  arg_ainfo.longname = "query type options";
+  arg_ainfo.multiplechar = true; // can be empty or single char
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+    
+  // "qb" - 0 = regular, 1 = large
+  arg_ainfo.shortname = "qb";
+  arg_ainfo.longname = "query box type";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "fqn" - number of fields in the query form
+  arg_ainfo.shortname = "fqn";
+  arg_ainfo.longname = "form query num fields";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "4";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "fqf" - the list of field names in the form query
+  // - a comma separated list
+  arg_ainfo.shortname = "fqf";
+  arg_ainfo.longname = "form query fields";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+  
+  // "fqv" - the list of values in the form query
+  // - a comma separated list
+  arg_ainfo.shortname = "fqv";
+  arg_ainfo.longname = "form query values";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+  
+
+  // "fqs" - the list of stemming options in the form query
+  // - a comma separated list
+  arg_ainfo.shortname = "fqs";
+  arg_ainfo.longname = "form query stems";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+  
+
+  // "fqk" - the list of casefolding options in the form query
+  // - a comma separated list
+  arg_ainfo.shortname = "fqk";
+  arg_ainfo.longname = "form query casefolds";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+  
+  // "fqc" - the list of boolean operators in the form query
+  // - a comma separated list
+  arg_ainfo.shortname = "fqc";
+  arg_ainfo.longname = "form query combines";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "fqa" - form query advanced - for "run query"
+  arg_ainfo.shortname = "fqa";
+  arg_ainfo.longname = "form query advanced query";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "ifl" - I'm feeling lucky! (Go directly to a matching document)
+  arg_ainfo.shortname = "ifl";
+  arg_ainfo.longname = "i'm feeling lucky";
+  arg_ainfo.multiplechar = false;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "ifln" - I'm feeling lucky number (Go directly to the nth matching document)
+  arg_ainfo.shortname = "ifln";
+  arg_ainfo.longname = "i'm feeling lucky number";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "1";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "srn" - the next search result
+  arg_ainfo.shortname = "srn";
+  arg_ainfo.longname = "the next search result number";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "srp" - the previous search result
+  arg_ainfo.shortname = "srp";
+  arg_ainfo.longname = "the previous search result number";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "0";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "sf" - Sort field. Set to field to be used for sorting search reult
+  // set (only implemented for lucene collections at present).
+  arg_ainfo.shortname = "sf";
+  arg_ainfo.longname = "sort field";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "fuzziness" controls how closely the search terms must match
+  // 100 = exact match, 0 = very inexact match (only implemented for Lucene)
+  arg_ainfo.shortname = "fuzziness";
+  arg_ainfo.longname = "Lucene fuzziness value";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+}
+
+void queryaction::configure (const text_t &key, const text_tarray &cfgline) {
+  action::configure (key, cfgline);
+}
+
+bool queryaction::init (ostream &logout) {
+  return action::init (logout);
+}
+
+bool queryaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+				 recptprotolistclass * /*protos*/, ostream &logout) {
+
+  // check t argument
+  int arg_t = args.getintarg("t");
+  if (arg_t != 0 && arg_t != 1) {
+    logout << "Warning: \"t\" argument out of range (" << arg_t << ")\n";
+    cgiarginfo *tinfo = argsinfo.getarginfo ("t");
+    if (tinfo != NULL) args["t"] = tinfo->argdefault;
+  }
+
+  // check k argument
+  int arg_k = args.getintarg("k");
+  if (arg_k != 0 && arg_k != 1) {
+    logout << "Warning: \"k\" argument out of range (" << arg_k << ")\n";
+    cgiarginfo *kinfo = argsinfo.getarginfo ("k");
+    if (kinfo != NULL) args["k"] = kinfo->argdefault;
+  }
+
+  // check s argument
+  int arg_s = args.getintarg("s");
+  if (arg_s != 0 && arg_s != 1) {
+    logout << "Warning: \"s\" argument out of range (" << arg_s << ")\n";
+    cgiarginfo *sinfo = argsinfo.getarginfo ("s");
+    if (sinfo != NULL) args["s"] = sinfo->argdefault;
+  }
+
+  // check m argument
+  int arg_m = args.getintarg("m");
+  if (arg_m < -1) {
+    logout << "Warning: \"m\" argument less than -1 (" << arg_m << ")\n";
+    cgiarginfo *minfo = argsinfo.getarginfo ("m");
+    if (minfo != NULL) args["m"] = minfo->argdefault;
+  }
+
+  // check o argument
+  int arg_o = args.getintarg("o");
+  if (arg_o < -1) {
+    logout << "Warning: \"o\" argument less than -1 (" << arg_o << ")\n";
+    cgiarginfo *oinfo = argsinfo.getarginfo ("o");
+    if (oinfo != NULL) args["o"] = oinfo->argdefault;
+  }
+
+  // check r argument
+  int arg_r = args.getintarg("r");
+  if (arg_r < 1) {
+    logout << "Warning: \"r\" argument less than 1 (" << arg_r << ")\n";
+    cgiarginfo *rinfo = argsinfo.getarginfo ("r");
+    if (rinfo != NULL) args["r"] = rinfo->argdefault;
+  }
+  //check hd argument
+  int arg_hd = args.getintarg("hd");
+  if (arg_hd <0 ) {
+    logout << "Warning: \"hd\" argument less than 0 (" << arg_hd << ")\n";
+    cgiarginfo *hdinfo = argsinfo.getarginfo ("hd");
+    if (hdinfo != NULL) args["hd"] = hdinfo->argdefault;
+  }  
+  
+  //check hs argument
+  int arg_hs = args.getintarg("hs");
+  if (arg_hs !=0 && arg_hs !=1) {
+    logout << "Warning: \"hs\" argument out of range (" << arg_hs << ")\n";
+    cgiarginfo *hsinfo = argsinfo.getarginfo ("hs");
+    if (hsinfo != NULL) args["hs"] = hsinfo->argdefault;
+  }
+
+  // check ct argument
+  int arg_ct = args.getintarg("ct");
+  if (arg_ct < 0 || arg_ct > 2) {
+    logout << "Warning: \"ct\" argument out of range (" << arg_ct << ")\n";
+    cgiarginfo *ctinfo = argsinfo.getarginfo ("ct");
+    if (ctinfo != NULL) args["ct"] = ctinfo->argdefault;
+  }
+
+  // check qt argument
+  int arg_qt = args.getintarg("qt");
+  if (arg_qt !=0 && arg_qt !=1) {
+    logout << "Warning: \"qt\" argument out of range (" << arg_qt << ")\n";
+    cgiarginfo *qtinfo = argsinfo.getarginfo ("qt");
+    if (qtinfo != NULL) args["qt"] = qtinfo->argdefault;
+  }
+
+  // check qb argument
+  int arg_qb = args.getintarg("qb");
+  if (arg_qb !=0 && arg_qb !=1) {
+    logout << "Warning: \"qb\" argument out of range (" << arg_qb << ")\n";
+    cgiarginfo *qbinfo = argsinfo.getarginfo ("qb");
+    if (qbinfo != NULL) args["qb"] = qbinfo->argdefault;
+  }
+
+  // check fqa argument
+  int arg_fqa = args.getintarg("fqa");
+  if (arg_fqa !=0 && arg_fqa !=1) {
+    logout << "Warning: \"fqa\" argument out of range (" << arg_fqa << ")\n";
+    cgiarginfo *fqainfo = argsinfo.getarginfo ("fqa");
+    if (fqainfo != NULL) args["fqa"] = fqainfo->argdefault;
+  }
+
+  // check fqn argument
+  int arg_fqn = args.getintarg("fqn");
+  if (arg_fqn < -1) {
+    logout << "Warning: \"fqn\" argument less than -1 (" << arg_fqn << ")\n";
+    cgiarginfo *fqninfo = argsinfo.getarginfo ("fqn");
+    if (fqninfo != NULL) args["fqn"] = fqninfo->argdefault;
+  }
+
+  return true;
+}
+
+void queryaction::get_cgihead_info (cgiargsclass &args, recptprotolistclass * /*protos*/,
+				    response_t &response, text_t &response_data, 
+				    ostream &/*logout*/) {
+  // If this is an "I'm feeling lucky" request, we don't know the target location until later
+  if (!args["ifl"].empty()) {
+    response = undecided_location;
+    return;
+  }
+
+  response = content;
+  response_data = "text/html";
+}
+
+void queryaction::define_internal_macros (displayclass &disp, cgiargsclass &args, 
+					  recptprotolistclass * protos, 
+					  ostream &logout) {
+
+  // define_internal_macros sets the following macros:
+
+  // The following macros are set later (in define_query_macros) as they can't be set until 
+  // the query has been done.
+  // _quotedquery_   the part of the query string that was quoted for post-processing
+  // _freqmsg_      the term frequency string
+
+  // _resultline_   the "x documents matched the query" string
+
+  // _prevfirst_    these are used when setting up the links to previous/next
+  // _prevlast_     pages of results (_thisfirst_ and _thislast_ are used to set
+  // _nextfirst_    the 'results x-x for query: xxxx' string in the title bar)
+  // _nextlast_
+  // _thisfirst_
+  // _thislast_
+
+  
+  define_form_macros(disp, args, protos, logout);
+  
+  define_query_interface(disp, args, protos, logout);
+
+
+}
+
+void queryaction::define_query_interface(displayclass &disp, 
+					 cgiargsclass &args, 
+					 recptprotolistclass * protos, 
+					 ostream &logout){
+  text_t collection = args["c"];
+
+  //check that the protocol is alive
+  recptproto* colproto = protos->getrecptproto (collection, logout);
+  if(colproto == NULL) {
+    logout << "ERROR: Null collection protocol trying to query"
+	   << collection.getcstr() << "\n";
+    return;
+  }
+  
+  //check the collection is responding/in place
+  ColInfoResponse_t *colinfo = recpt->get_collectinfo_ptr(colproto, collection,
+							  logout);
+  if(colinfo == NULL){
+    logout << "ERROR: Null returned for get_collectinfo_ptr on "
+	   << collection.getcstr() << "in queryaction::define_query_interface\n";
+    return;
+  }
+   
+  text_tmap::iterator check = colinfo->format.find("QueryInterface");
+  if(check != colinfo->format.end()){
+    if((*check).second=="DateSearch"){
+      text_t current = "_datesearch_";
+      disp.setmacro("optdatesearch","query",current);
+    }
+  }
+}
+
+
+// sets the selection box macros _hselection_, _jselection_, _nselection_ _gselection_, fqfselection_ 
+void queryaction::set_option_macro (const text_t &macroname, 
+				    text_t current_value, 
+				    bool display_single, 
+				    bool add_js_update,
+				    const FilterOption_t &option, 
+				    displayclass &disp) {
+  
+  if (option.validValues.empty()) return;
+  if (option.validValues.size() == 1) {
+    if (display_single) {
+      disp.setmacro (macroname + "selection", displayclass::defaultpackage, "_" + option.defaultValue + "_");
+    }
+    return;    
+  } 
+  if (option.validValues.size() < 2) return;
+  
+  text_t macrovalue = "<select name=\"" + macroname + "\"";
+  if (add_js_update) {
+    macrovalue += " onChange=\"update"+macroname+"();\"";
+  }
+  macrovalue += ">\n";
+  
+  if (current_value.empty()) current_value = option.defaultValue;
+  
+  text_tarray::const_iterator thisvalue = option.validValues.begin();
+  text_tarray::const_iterator endvalue = option.validValues.end();
+
+  while (thisvalue != endvalue) {
+    macrovalue += "<option value=\"" + *thisvalue + "\"";
+    if (*thisvalue == current_value)
+      macrovalue += " selected";
+    macrovalue += ">_" + *thisvalue + "_\n";
+    ++thisvalue;
+  }
+  macrovalue += "</select>\n";
+  disp.setmacro (macroname + "selection", displayclass::defaultpackage, macrovalue);
+}
+
+
+void queryaction::define_external_macros (displayclass &disp, cgiargsclass &args, 
+					  recptprotolistclass *protos, ostream &logout) {
+
+  // define_external_macros sets the following macros:
+
+  // some or all of these may not be required to be set
+  // _hselection_, _h2selection_  the selection box for the main part of the index
+  // _jselection_, _j2selection_  the selection box for the subcollection part of the index
+  // _nselection_, _n2selection_  the selection box for the language part of the index
+  // _cq2selection                the selection box for combining two queries
+  
+  // _gselection_, the selection box forlevels (mgpp)
+  // _fqfselection_, the selection box for index/fields (mgpp)
+  // can't do anything if collectproto is null (i.e. no collection was specified)
+  recptproto *collectproto = protos->getrecptproto (args["c"], logout);
+  if (collectproto == NULL) return;
+
+  ColInfoResponse_t *colinfo = recpt->get_collectinfo_ptr(collectproto, 
+							  args["c"],
+							  logout);
+  set_query_type_args(colinfo, args);
+  set_stem_index_args(colinfo, args);
+
+  comerror_t err;
+  InfoFilterOptionsResponse_t response;
+  InfoFilterOptionsRequest_t request;
+  request.filterName = "QueryFilter";
+  
+  collectproto->get_filteroptions (args["c"], request, response, err, logout);
+  if (err == noError) {
+    
+    FilterOption_tmap::const_iterator it;
+    FilterOption_tmap::const_iterator end = response.filterOptions.end();
+    
+    // _hselection_ and _h2selection_ (Index)
+    it = response.filterOptions.find ("Index");
+    if (it != end) set_option_macro ("h", args["h"], true, false, (*it).second, disp);
+    if (it != end) set_option_macro ("h2", args["h2"], true,false, (*it).second, disp);
+    
+    // _jselection_ and _j2selection_ (Subcollection)
+    it = response.filterOptions.find ("Subcollection");
+    if (it != end) set_option_macro ("j", args["j"], true,false, (*it).second, disp);
+    if (it != end) set_option_macro ("j2", args["j2"], true,false, (*it).second, disp);
+    
+    // _nselection_ and _n2selection_ (Language)
+    it = response.filterOptions.find ("Language");
+    if (it != end) set_option_macro ("n", args["n"], true,false, (*it).second, disp);
+    if (it != end) set_option_macro ("n2", args["n2"], true,false, (*it).second, disp);
+
+    // _cq2selection_ (CombineQuery)
+    it = response.filterOptions.find ("CombineQuery");
+    if (it != end) set_option_macro ("cq2", args["cq2"], true,false, (*it).second, disp);
+
+    if ((args["ct"] == "1") || (args["ct"] == "2"))  { // mgpp/lucene collections
+      // _gselection_ (Level) 
+      it = response.filterOptions.find("Level");
+      if (it!=end) {
+	set_option_macro("g", args["g"], false, false, (*it).second, disp);
+	if (args["qt"]=="1") { // form search
+	  set_gformselection_macro(args["g"], (*it).second, disp);
+	}
+      }
+      // _fqfselection_ field list
+      it = response.filterOptions.find("IndexField");
+      if (it!=end) {
+	bool form_search = false;
+	if (args["qto"]=="2" || args["qt"]=="1") { 
+	  form_search = true;
+	}
+	set_option_macro ("fqf", args["fqf"], true, form_search, (*it).second, disp);
+	if (args["ct"] == "2") {// lucene
+	  // set the sort field macro
+	  set_sfselection_macro(args["sf"], (*it).second, disp);
+	}
+      }
+    }
+  }
+} // define external macros
+  
+void queryaction::set_sfselection_macro(text_t current_value, 
+				       const FilterOption_t &option, 
+				       displayclass &disp) {
+
+  // we need at least one option here to continue
+  if (option.validValues.size() < 1) {
+    return;
+  }
+
+  text_t macrovalue = "<select name=\"sf\">\n";
+  
+  if (current_value.empty()) current_value = "";
+  
+  // we give a rank option first
+  macrovalue += "<option value=\"\"";
+  if (current_value == "") {
+    macrovalue += " selected";
+  }
+  macrovalue += ">_query:textsortbyrank_\n";
+
+  text_tarray::const_iterator thisvalue = option.validValues.begin();
+  text_tarray::const_iterator endvalue = option.validValues.end();
+  int valid_count = 0;
+  while (thisvalue != endvalue) {
+    if (*thisvalue != "ZZ" && *thisvalue != "TX") {
+      ++valid_count;
+      macrovalue += "<option value=\"by" + *thisvalue + "\"";
+      if (current_value == "by"+*thisvalue)
+	macrovalue += " selected";
+      macrovalue += ">_" + *thisvalue + "_\n";
+    }
+    ++thisvalue;
+  }
+  macrovalue += "</select>";
+  if (valid_count > 0) {
+    disp.setmacro ("sfselection", displayclass::defaultpackage, macrovalue);
+  }
+  
+}
+ 
+// sets the selection box macro _gformselection_.
+// the default for _gformselection_ is _gselection_
+void queryaction::set_gformselection_macro (text_t current_value,
+					const FilterOption_t &option,
+					displayclass &disp) {
+  
+  if (option.validValues.size() <= 1) {
+    return;
+  }
+  // we need to check to see if there is paragraph present
+  text_tarray::const_iterator thisvalue = option.validValues.begin();
+  text_tarray::const_iterator endvalue = option.validValues.end();
+
+  bool has_paras = false;
+  while (thisvalue != endvalue) {
+    if (*thisvalue == "Para") {
+      has_paras = true;
+      break;
+    }
+    ++thisvalue;
+  }
+  if (!has_paras) return; // there is no difference between the form selection and the normal one
+
+  if (option.validValues.size() == 2) {
+    // we will only have one value, but we will still put it in as a text string
+    int opt = 0;
+    if (option.validValues[0] == "Para") {
+      opt = 1;
+    }
+    disp.setmacro ("gformselection", displayclass::defaultpackage, "_"+option.validValues[opt]+"_");
+    return;
+  }
+
+  // there will be a select box
+  text_t macrovalue = "<select name=\"g\">\n";
+
+  if (current_value.empty()) current_value = option.defaultValue;
+  
+  thisvalue = option.validValues.begin();
+  
+  while (thisvalue != endvalue) {
+    if (*thisvalue != "Para") {
+      macrovalue += "<option value=\"" + *thisvalue + "\"";
+      if (*thisvalue == current_value)
+	macrovalue += " selected";
+      macrovalue += ">_" + *thisvalue + "_\n";
+    }
+    ++thisvalue;
+  }
+  macrovalue += "</select>\n";
+  disp.setmacro ("gformselection", displayclass::defaultpackage, macrovalue);
+}
+void queryaction::define_form_macros (displayclass &disp, cgiargsclass &args, 
+			   recptprotolistclass *protos, ostream &logout) {
+
+  // defines the following macros
+  // _regformlist_
+  // _advformlist_
+
+  if (args["ct"]=="0" || args["qto"]=="1" || (args["qto"]=="3" && args["qt"] == "0") ) // mg, or mgpp/lucene with plain only, or mgpp with both, but set to plain
+    return; // dont need these macros
+
+  text_t form = "";
+  int argfqn = args.getintarg("fqn");
+  
+  if (args["b"] == "1") { // advanced form
+    form += "_firstadvformelement_\n";
+    for (int i=1; i<argfqn; ++i) {      
+	form += "_advformelement_\n";
+    }
+    disp.setmacro("advformlist", "query", form);
+  }
+  else { // simple form
+    for (int i=0; i<argfqn; ++i) {
+      form += "_regformelement_\n"; 
+    }
+    disp.setmacro("regformlist", "query", form);
+  }
+  
+}
+
+void queryaction::define_history_macros (displayclass &disp, cgiargsclass &args, 
+					 recptprotolistclass *protos, ostream &logout) {
+
+  // defines the following macros
+  // _searchhistorylist_
+
+  text_t historylist;
+  int arghd = args.getintarg("hd");
+  if (arghd == 0) {
+    historylist="";
+  }
+  else {
+    historylist = "<!-- Search History List -->\n";
+   
+    text_t userid = args["z"];
+    text_tarray entries;
+    if (get_history_info (userid, entries, dbhome, logout)) {
+      int count = 1;
+      text_tarray::iterator here = entries.begin();
+      text_tarray::iterator end = entries.end();
+      int numrecords=(int)entries.size();
+      if (numrecords>arghd) { // only display some of them 
+	numrecords = arghd;
+      }
+      historylist += "<form action=\"_gwcgi_\" name=\"HistoryForm\"><table width=\"537\">\n";
+
+      for (int i=0; i<numrecords;++i) {
+	text_t query;
+	text_t numdocs;
+	text_t cgiargs;
+	text_t userinfo;
+	text_t escquery;
+	split_saved_query(entries[i],numdocs,cgiargs);
+	parse_saved_args(cgiargs, "q", query); // get query string out
+	decode_cgi_arg(query); // un cgisafe it
+	escquery = escape_quotes(query); // escape the quotes and newlines
+	text_t histvalue = "histvalue";
+	histvalue += i;
+	disp.setmacro(histvalue, "query", escquery);
+	format_user_info(cgiargs, userinfo, args, protos, logout);
+	
+	historylist += "<tr><td align=\"right\">_imagehistbutton_(";
+	historylist += i;
+	historylist += ")</td>\n";
+	historylist += "<td><table border=\"1\" cellspacing=\"0\" ";
+	historylist += "cellpadding=\"0\"><tr><td width=\"365\" align=\"left\">"
+	  + query 
+	  + "</td></tr></table></td><td width=\"110\" align=\"center\"><small>"
+	  + numdocs;
+	if (numdocs == 1) historylist += " _texthresult_";
+	else historylist += " _texthresults_";
+	if (!userinfo.empty()) {
+	  historylist += "<br>( "+userinfo+" )";
+	}
+	historylist += "</small></td>\n";
+      }
+      historylist+="</table></form>\n\n";
+     
+    } // if get history info 
+    else {
+      historylist += "_textnohistory_";
+    }
+    historylist += "<! ---- end of history list ----->\n";
+  } // else display list
+  disp.setmacro("searchhistorylist", "query", historylist);
+  
+} // define history macros
+
+void queryaction::output_ccp (cgiargsclass &args, recptprotolistclass *protos,
+			      displayclass &disp, outconvertclass &outconvert,
+			      ostream &textout, ostream &logout) {
+
+  ColInfoResponse_t *cinfo = NULL;
+  comerror_t err;
+  InfoFilterOptionsResponse_t fresponse;
+  InfoFilterOptionsRequest_t frequest;
+  frequest.filterName = "QueryFilter";
+
+  text_t &index = args["h"];
+  text_t &subcollection = args["j"];
+  text_t &language = args["n"];
+
+  text_tset collections;
+  text_t arg_cc = args["cc"];
+  decode_cgi_arg (arg_cc);
+  splitchar (arg_cc.begin(), arg_cc.end(), ',', collections);
+
+  textout << outconvert << disp << "_query:header_\n"
+	  << "<center>_navigationbar_</center><br>\n"
+	  << "<form name=\"QueryForm\" method=\"get\" action=\"_gwcgi_\">\n"
+	  << "<input type=\"hidden\" name=\"a\" value=\"q\">\n"
+          << "<input type=\"hidden\" name=\"site\" value=\"_cgiargsite_\"\n"
+	  << "<input type=\"hidden\" name=\"e\" value=\"_compressedoptions_\">\n"
+	  << "<input type=\"hidden\" name=\"ccp\" value=\"1\">\n"
+	  << "<center><table width=\"_pagewidth_\"><tr valign=\"top\">\n"
+	  << "<td>Select collections to search for \"" << args["q"] 
+	  << "\" <i>(index=" << index << " subcollection=" << subcollection
+	  << " language=" << language << ")</i></td>\n"
+	  << "<td><input type=\"submit\" value=\"_query:textbeginsearch_\"></td>\n"
+	  << "</tr></table></center>\n"
+	  << "<center><table width=\"_pagewidth_\">\n"
+	  << "<tr><td>\n";
+  
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    if ((*rprotolist_here).p != NULL) {
+      
+      text_tarray collist;
+      (*rprotolist_here).p->get_collection_list (collist, err, logout);
+      if (err == noError) {
+	text_tarray::iterator collist_here = collist.begin();
+	text_tarray::iterator collist_end = collist.end();
+	while (collist_here != collist_end) {
+	  
+	  cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
+	  //	  if (err == noError && cinfo.isPublic && (cinfo.buildDate > 0)) {
+	  if (cinfo != NULL && (cinfo->buildDate > 0)) {
+	    
+	    (*rprotolist_here).p->get_filteroptions (*collist_here, frequest, fresponse, err, logout);
+	    if (err == noError) {
+	      
+	      FilterOption_tmap::const_iterator it;
+	      FilterOption_tmap::const_iterator end = fresponse.filterOptions.end();
+	      if (!index.empty()) {
+		it = fresponse.filterOptions.find ("Index");
+		if (it == end) {++collist_here; continue;}
+		text_tarray::const_iterator there = (*it).second.validValues.begin();
+		text_tarray::const_iterator tend = (*it).second.validValues.end();
+		while (there != tend) {
+		  if (*there == index) break;
+		  ++there;
+		}
+		if (there == tend) {++collist_here; continue;}
+	      }
+	      if (!subcollection.empty()) {
+		it = fresponse.filterOptions.find ("Subcollection");
+		if (it == end) {++collist_here; continue;}
+		text_tarray::const_iterator there = (*it).second.validValues.begin();
+		text_tarray::const_iterator tend = (*it).second.validValues.end();
+		while (there != tend) {
+		  if (*there == subcollection) break;
+		  ++there;
+		}
+		if (there == tend) {++collist_here; continue;}
+	      }
+	      if (!language.empty()) {
+		it = fresponse.filterOptions.find ("Language");
+		if (it == end) {++collist_here; continue;}
+		text_tarray::const_iterator there = (*it).second.validValues.begin();
+		text_tarray::const_iterator tend = (*it).second.validValues.end();
+		while (there != tend) {
+		  if (*there == language) break;
+		  ++there;
+		}
+		if (there == tend) {++collist_here; continue;}
+	      }
+	    
+	      // we've got a matching collection
+	      textout << outconvert << "<input type=\"checkbox\"";
+
+	      text_tset::const_iterator t = collections.find (*collist_here);
+	      if (t != collections.end()) textout << outconvert << " checked";
+	      
+	      text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
+	      if (collectionname.empty()) {
+		collectionname = *collist_here;
+	      }
+	      textout << outconvert << disp 
+		      << " name=\"cc\" value=\"" << *collist_here << "\">"
+		      << collectionname << "<br>\n";
+
+	      
+	    }
+	  }
+	  ++collist_here;
+	}
+      }
+    }
+    ++rprotolist_here;
+  }
+  textout << outconvert << disp 
+	  << "</td></tr></table></center>\n"
+	  << "</form>\n"
+	  << "_query:footer_\n";
+  
+}
+
+bool queryaction::do_action (cgiargsclass &args, recptprotolistclass *protos, 
+			     browsermapclass *browsers, displayclass &disp, 
+			     outconvertclass &outconvert, ostream &textout, 
+			     ostream &logout) {
+  
+  if (recpt == NULL) {
+    logout << "ERROR (queryaction::do_action): This action does not contain information\n"
+	   << "      about any receptionists. The method set_receptionist was probably\n"
+	   << "      not called from the module which instantiated this action.\n";
+    return true;
+  }
+
+
+
+  if (args["ccs"] == "1") {
+    if (!args["cc"].empty()) {
+      // query the selected collections
+      text_t::const_iterator b = args["cc"].begin();
+      text_t::const_iterator e = args["cc"].end();
+      if (findchar (b, e, ',') != e) {
+	if (!search_multiple_collections (args, protos, browsers, disp, outconvert,
+					  textout, logout)) return false;
+	return true;
+      } else {
+	if (!search_single_collection (args, args["cc"], protos, browsers, disp, 
+				       outconvert, textout, logout)) return false;
+  	return true;
+      }
+    }
+  }
+
+  // simply query the current collection
+  if (!search_single_collection (args, args["c"], protos, browsers, disp, 
+				 outconvert, textout, logout)) return false;
+  return true;
+}
+
+bool queryaction::search_multiple_collections (cgiargsclass &args, recptprotolistclass *protos,
+					       browsermapclass *browsers, displayclass &disp,
+					       outconvertclass &outconvert, ostream &textout,
+					       ostream &logout) {
+
+  text_tarray collections;
+  
+  text_t arg_cc = args["cc"];
+  decode_cgi_arg (arg_cc);
+  splitchar (arg_cc.begin(), arg_cc.end(), ',', collections);
+
+  if (collections.empty()) {
+    logout << "queryaction::search_multiple_collections: No collections "
+	   << "set for doing multiple query - will search current collection\n";
+    textout << outconvert << disp << "_query:textwarningnocollections_\n";
+    return search_single_collection (args, args["c"], protos, browsers, disp, 
+				     outconvert, textout, logout);
+  }
+
+  // queryaction uses "VList" browser to display results,
+  // a queries clasification is "Search"
+  text_t browsertype = "VList";
+  text_t classification = "Search";
+
+  QueryResult_tset results;
+  map<text_t, colinfo_t, lttext_t> colinfomap;
+
+  ColInfoResponse_t *cinfo = NULL;
+  recptproto *collectproto = NULL;
+  comerror_t err;
+  FilterRequest_t request;
+  FilterResponse_t response;
+  request.filterResultOptions = FROID | FRmetadata | FRtermFreq | FRranking;
+  text_t freqmsg = "_textfreqmsg1_";
+  int numdocs = 0;
+  isapprox isApprox = Exact;
+
+  // what to do about segmentation for multiple colls??
+  bool segment = false;
+  text_t formattedstring = "";
+  get_formatted_query_string(formattedstring, segment, args, disp, logout);
+
+  if (formattedstring.empty()) {
+    // dont bother doing a query if no query string
+    define_history_macros (disp, args, protos, logout);
+    textout << outconvert << disp << "_query:header_\n"
+	  << "_query:content_";
+    textout << outconvert << disp << "_query:footer_";
+
+    return true;
+  }
+  bool syntax_error = false;
+
+  set_queryfilter_options (request, formattedstring, args);
+
+  // need to retrieve maxdocs matches for each collection
+  // (will eventually want to tidy this up, do so caching etc.)
+  OptionValue_t option;
+  option.name = "StartResults";
+  option.value = "1";
+  request.filterOptions.push_back (option);
+  
+  option.name = "EndResults";
+  option.value = args["m"];
+  request.filterOptions.push_back (option);
+
+  text_tarray::iterator col_here = collections.begin();
+  text_tarray::iterator col_end = collections.end();
+
+  map<text_t, int, lttext_t> termfreqs;
+  
+  // just check the main col for formatting info - use individual format statements, or the main one?
+  
+  browserclass *bptr = browsers->getbrowser (browsertype);
+  
+  text_t main_col = args["c"];
+  cinfo = recpt->get_collectinfo_ptr (collectproto, main_col, logout);
+  if (cinfo == NULL) {
+    logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL for '"<<main_col<<"'\n";
+    return false;
+  }
+  
+  bool use_main_col_format = false;
+  if (cinfo->ccsOptions & CCSUniformSearchResultsFormatting) {
+    use_main_col_format = true;
+  }
+ 
+  request.fields.erase (request.fields.begin(), request.fields.end());
+  request.getParents = false;
+  bptr->load_metadata_defaults (request.fields);
+  
+  text_t formatstring;
+  format_t *formatlistptr = new format_t();
+  if (use_main_col_format) {
+    // just get one format for main coll and use it for each subcol
+    if (!get_formatstring (classification, browsertype, 
+			   cinfo->format, formatstring)) {
+      formatstring = bptr->get_default_formatstring();
+    }
+    
+    parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
+  }
+  
+  while (col_here != col_end) {
+
+    collectproto = protos->getrecptproto (*col_here, logout);
+    if (collectproto == NULL) {
+      logout << outconvert << "queryaction::search_multiple_collections: " << *col_here 
+	     << " collection has a NULL collectproto, ignoring\n";
+      ++col_here;
+      continue;
+    }
+    cinfo = recpt->get_collectinfo_ptr (collectproto, *col_here, logout);
+    if (cinfo == NULL) {
+      logout << "ERROR (query_action::search_multiple_collections): get_collectinfo_ptr returned NULL\n";
+      ++col_here;
+      continue;
+    }
+
+    if (!use_main_col_format) {
+      request.fields.erase (request.fields.begin(), request.fields.end());
+      request.getParents = false;
+      bptr->load_metadata_defaults (request.fields);
+      
+    //browserclass *bptr = browsers->getbrowser (browsertype);
+
+    // get the formatstring if there is one 
+      if (!get_formatstring (classification, browsertype, 
+			     cinfo->format, formatstring)) {
+	formatstring = bptr->get_default_formatstring();
+      }
+
+      formatlistptr = new format_t();
+      parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
+    }
+    
+    colinfo_t thiscolinfo;
+    thiscolinfo.formatlistptr = formatlistptr;
+    thiscolinfo.browserptr = bptr;
+    colinfomap[*col_here] = thiscolinfo;
+    
+    // do the query
+    collectproto->filter (*col_here, request, response, err, logout);
+    if (err != noError && err != syntaxError) {
+      outconvertclass text_t2ascii;
+      logout << text_t2ascii
+	     << "queryaction::search_multiple_collections: call to QueryFilter failed "
+	     << "for " << *col_here << " collection (" << get_comerror_string (err) << ")\n";
+      return false;
+    }
+
+    if (err == syntaxError) {
+      syntax_error = true;
+      freqmsg = "_textinvalidquery_";
+      // assume the syntax will be invalid for all colls
+      break;
+    }
+    if (response.error_message == "TOO_MANY_CLAUSES") {
+      freqmsg = "_textlucenetoomanyclauses_";
+      break;
+    }
+    if (isApprox == Exact)
+      isApprox = response.isApprox;
+    else if (isApprox == MoreThan)
+      if (response.isApprox == Approximate)
+	isApprox = response.isApprox;
+
+    TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
+    TermInfo_tarray::const_iterator end_term = response.termInfo.end();
+    while (this_term != end_term) {
+      termfreqs[(*this_term).term] += (*this_term).freq;
+      if ((col_here+1) == col_end) {
+	freqmsg += (*this_term).term + ": " + termfreqs[(*this_term).term];
+	if ((this_term+1) != end_term) freqmsg += ", ";
+      }
+      ++this_term;
+    }
+
+    if (response.numDocs > 0) {
+      numdocs += response.numDocs;
+    
+      QueryResult_t thisresult;
+      thisresult.collection = *col_here;
+      ResultDocInfo_tarray::iterator doc_here = response.docInfo.begin();
+      ResultDocInfo_tarray::iterator doc_end = response.docInfo.end();
+      while (doc_here != doc_end) {
+	thisresult.doc = *doc_here;
+	results.insert (thisresult);
+	++doc_here;
+      }
+    }
+    ++col_here;
+  } // for each coll
+  
+  text_t numdocs_t = numdocs;  
+  args["nmd"] = numdocs_t;
+
+  disp.setmacro ("freqmsg", "query", freqmsg);
+
+  define_query_macros( args, disp, numdocs, isApprox);
+  // save the query if appropriate
+  save_search_history(args, numdocs, isApprox);
+  define_history_macros (disp, args, protos, logout);
+
+  textout << outconvert << disp << "_query:header_\n"
+	  << "_query:content_";
+
+  if (!syntax_error) {
+    
+    // now go through each result and output it
+    QueryResult_tset::iterator res_here = results.begin();
+    QueryResult_tset::iterator res_end = results.end();
+    text_tset metadata; // empty !!
+    bool getParents = false; // don't care !!
+    bool use_table;
+    ResultDocInfo_t thisdoc;
+    format_t *formatlistptr = NULL;
+    browserclass *browserptr = NULL;
+    
+    int count = 1;
+    int firstdoc = args.getintarg("r");
+    int hitsperpage = args.getintarg("o");
+    int thislast = firstdoc + (hitsperpage - 1);
+    
+    // output results
+    while (res_here != res_end) {
+      if (count < firstdoc) {++count; ++res_here; continue;}
+      if (count > thislast) break;
+      
+      formatlistptr = colinfomap[(*res_here).collection].formatlistptr;
+      browserptr = colinfomap[(*res_here).collection].browserptr;
+      thisdoc = (*res_here).doc;
+      use_table = is_table_content (formatlistptr);
+      
+      collectproto = protos->getrecptproto ((*res_here).collection, logout);
+      if (collectproto == NULL) {
+	logout << outconvert << "queryaction::search_multiple_collections: " << (*res_here).collection
+	       << " collection has a NULL collectproto, ignoring results\n";
+	++res_here;
+	continue;
+      }
+      
+      browserptr->output_section_group (thisdoc, args, (*res_here).collection, 0, 
+					formatlistptr, use_table, metadata, getParents, 
+					collectproto, disp, outconvert, textout, logout);
+      //    textout << outconvert << "(ranking: " << (*res_here).doc.ranking << ")\n";
+      ++res_here;
+      ++count;
+    }
+  }
+  textout << outconvert << disp << "_query:footer_";
+  
+  // clean up the format_t pointers
+  map<text_t, colinfo_t, lttext_t>::iterator here =  colinfomap.begin();
+  map<text_t, colinfo_t, lttext_t>::iterator end =  colinfomap.end();
+  while (here != end) {
+    delete ((*here).second.formatlistptr);
+    ++here;
+  }
+  return true;
+}
+
+bool queryaction::search_single_collection (cgiargsclass &args, const text_t &collection,
+					    recptprotolistclass *protos, browsermapclass *browsers, 
+					    displayclass &disp, outconvertclass &outconvert, 
+					    ostream &textout, ostream &logout) {
+
+  recptproto *collectproto = protos->getrecptproto (collection, logout);
+  if (collectproto == NULL) {
+    logout << outconvert << "queryaction::search_single_collection: " << collection
+	   << " collection has a NULL collectproto\n";
+
+    // Display the "this collection is not installed on this system" page
+    disp.setmacro("cvariable", displayclass::defaultpackage, collection);
+    disp.setmacro("content", "query", "<p>_textbadcollection_<p>");
+
+    textout << outconvert << disp << "_query:header_\n"
+	    << "_query:content_\n" << "_query:footer_\n";
+    return true;
+  }
+
+  // queryaction uses "VList" browser to display results,
+  // a queries clasification is "Search"
+  text_t browsertype = "VList";
+  text_t classification = "Search";
+
+  comerror_t err;
+  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr (collectproto, collection, logout);
+
+  if (cinfo == NULL) {
+    logout << "ERROR (query_action::search_single_collection): get_collectinfo_ptr returned NULL\n";
+    return false;
+  }
+    
+  bool segment = cinfo->isSegmented;
+  browserclass *bptr = browsers->getbrowser (browsertype);
+
+  // get the formatstring if there is one 
+  text_t formatstring;
+  if (!get_formatstring (classification, browsertype, 
+			 cinfo->format, formatstring)) {
+    formatstring = bptr->get_default_formatstring();
+  }
+  FilterRequest_t request;
+  FilterResponse_t response;
+
+  text_t maxDoc_old = args["o"];
+  text_t starts_old = args["r"];  
+
+    //if the "ifl" argument is set ignore the "r" and "o" arg
+  if(!args["ifl"].empty()){
+    args["r"] = 1;
+    args["o"] = args["m"];
+  }
+ 
+
+  bptr->set_filter_options (request, args);
+  bptr->load_metadata_defaults (request.fields);
+
+  format_t *formatlistptr = new format_t();
+  parse_formatstring (formatstring, formatlistptr, request.fields, request.getParents);
+    
+  // do the query
+  request.filterResultOptions = FROID | FRmetadata | FRtermFreq;
+  text_t formattedstring = "";
+  get_formatted_query_string(formattedstring, segment, args, disp, logout);
+
+
+  if (!formattedstring.empty()) { // do the query
+    // note! formattedstring is in unicode! mg and mgpp must convert!
+    set_queryfilter_options (request, formattedstring, args);
+
+    collectproto->filter (collection, request, response, err, logout);
+
+    if (err != noError) {
+      outconvertclass text_t2ascii;
+      logout << text_t2ascii
+	     << "queryaction::search_single_collections: call to QueryFilter failed "
+	     << "for " << collection << " collection (" << get_comerror_string (err) << ")\n";
+     
+    }
+
+    // Perform the "I'm feeling lucky" trick if the "ifl" argument is set
+    if (err == noError && !args["ifl"].empty()) {
+      //Restore the "r" and "o" arg
+      args["r"] = starts_old;
+      args["o"] = maxDoc_old ;
+
+      //Find whether DocumentSearchResultLinks is enabled
+      bool show_links = false;
+      text_tmap::const_iterator format_here = cinfo->format.begin();
+      text_tmap::const_iterator format_end = cinfo->format.end();
+
+       while (format_here != format_end) {
+	 if (((*format_here).first == "DocumentSearchResultLinks") && 
+	     ((*format_here).second == "true")){
+	   show_links = true;
+           break;
+	 }
+         ++format_here;
+       } 
+
+       if (args["ifl"] == 1 || (args["ifl"] == 2 && response.numDocs == 1))
+       {
+	 // Find the search result specified by the ifln argument   
+	 ResultDocInfo_tarray::iterator thissection = response.docInfo.begin();
+	 int section_number = 1;
+	 int ifln = args["ifln"].getint();
+              
+	 while (section_number != ifln  && thissection != response.docInfo.end()) {   	
+	   thissection++;
+	   section_number++;
+	 }
+	 // If the search result exists, go directly to it
+	 if (section_number == ifln && thissection != response.docInfo.end()) {
+	   // Location response (this URL must have "&" and not "&amp;"!)
+	   int num_docs =  response.numDocs;
+	   int srn = 0;
+	   int srp = 0;
+	   if (show_links && section_number < num_docs ) {
+	     srn = section_number + 1;
+	   }
+	   if (show_links && section_number > 1 ) {
+	     srp = section_number - 1;
+	   }
+        
+	   textout << outconvert << disp << "Location: _gwcgi_?e=_compressedoptions_&a=d&c=" << collection << "&cl=search&d=" << (*thissection).OID <<"&srn="<<srn<<"&srp="<<srp<< "\n\n";
+	   textout << flush;
+	   
+	   return true;
+	 }
+       }
+       
+      // There weren't enough (or any) matching documents
+      // We'll just carry on as if ifl wasn't set. The only catch is that get_cgihead_info won't have
+      // done the right thing (because ifl was set), so we need to make sure the output is html
+      textout << "Content-type: text/html\n\n";
+      
+    }
+
+    if (err != noError) {
+      disp.setmacro("resultline", "query", "_textnodocs_");
+      if (err == syntaxError) {
+	disp.setmacro ("freqmsg", "query", "_textinvalidquery_");
+      } else {
+	disp.setmacro ("freqmsg", "query", "");
+      }
+    } else {
+      
+      define_query_macros (args, disp, response.numDocs, response.isApprox);
+      define_single_query_macros(args, disp, response);
+      // save the query if appropriate
+      save_search_history(args, response.numDocs, response.isApprox);
+    }
+
+    // If Lucene threw a TooManyClauses exception, tell the user about it
+    if (args["ct"] == 2 && response.error_message == "TOO_MANY_CLAUSES") {
+      disp.setmacro ("freqmsg", "query", "_textlucenetoomanyclauses_");
+    }
+  }
+  define_history_macros (disp, args, protos, logout);
+
+  textout << outconvert << disp << "_query:header_\n"
+	  << "_query:content_";
+  
+  if (err == noError) {
+    // output the results
+    text_t numdocs_t = response.numDocs;  
+    args["nmd"] = numdocs_t;
+    bool use_table = is_table_content (formatlistptr);
+    bptr->output_section_group (response, args, collection, 0, formatlistptr, 
+				use_table, request.fields, request.getParents, 
+				collectproto, disp, outconvert, textout, logout);
+  }
+
+  textout << outconvert << disp << "_query:footer_";
+  
+  delete (formatlistptr);
+  
+  return true;
+}
+ 
+// does the formatting of the query string - either uses q for a text search
+// or the form values for an form search
+// also adds dates if appropriate in text search
+void queryaction::get_formatted_query_string (text_t &formattedstring, 
+					      bool segment,
+					      cgiargsclass &args, 
+					      displayclass &disp,
+					      ostream &logout) {
+  if (args["qt"]=="0" && args["qto"] != "2") { // normal text search
+    formattedstring = args["q"];
+    // remove & | ! for simple search,do segmentation if necessary
+    format_querystring (formattedstring, args.getintarg("b"), segment);
+    if (args["ct"]!=0) { // mgpp and lucene - need to add in tag info if appropriate
+      format_field_info(formattedstring, args["fqf"], args.getintarg("ct"), 
+			args.getintarg("t"), args.getintarg("b"));
+    }
+
+    add_dates(formattedstring, args.getintarg("ds"), args.getintarg("de"),
+	      args.getintarg("dsbc"), args.getintarg("debc"),
+	      args.getintarg("ct"));
+    args["q"] = formattedstring;
+    
+  }
+  else if (args["qt"]=="1" || args["qto"]=="2"){ // form search
+
+    if (args["b"]=="1" && args["fqa"]=="1") { // explicit query
+      formattedstring = args["q"];
+    }
+    else { // form search
+      if (args["b"]=="0") { // regular form
+	parse_reg_query_form(formattedstring, args, segment);
+      }
+      else  { // advanced form
+	parse_adv_query_form(formattedstring, args, segment);
+      }
+      args["q"] = formattedstring;
+      
+      // reset the cgiargfqv macro - need to escape any quotes in it
+      disp.setmacro("cgiargfqv", "query", escape_quotes(args["fqv"]));
+
+      // also reset the _cgiargq_ macro as it has changed now
+      disp.setmacro("cgiargq", displayclass::defaultpackage, html_safe(args["q"]));
+      
+      // reset the compressed options to include the q arg
+      text_t compressedoptions = recpt->get_compressed_arg(args, logout);
+      if (!compressedoptions.empty()) {
+	disp.setmacro ("compressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
+	// need a decoded version of compressedoptions for use within forms
+	// as browsers encode values from forms before sending to server
+	// (e.g. %25 becomes %2525)
+	decode_cgi_arg (compressedoptions); 
+	if (args["w"] == "utf-8") { // if the encoding was utf-8, then compressed options was utf-8, and we need unicode.
+    // if encoding wasn't utf-8, then compressed opotions may be screwed up, but seems to work for 8 bit encodings?
+	  compressedoptions = to_uni(compressedoptions);
+	}
+
+	disp.setmacro ("decodedcompressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
+      }
+    } // form search
+  } // args["qt"]=1
+  else {
+    logout << "ERROR (query_action::get_formatted_query_string): querytype not defined\n";
+  }
+}
+
+
+// define_query_macros sets the macros that couldn't be set until the
+// query had been done. Those macros are 
+// _resultline_, _nextfirst_, _nextlast_, _prevfirst_, _prevlast_,
+// _thisfirst_, and _thislast_ and _quotedquery_ 
+// this has been simplified so it can be used with both search_single_coll
+// and search_multiple_coll
+void queryaction::define_query_macros (cgiargsclass &args, displayclass &disp,
+				       int numdocs, isapprox isApprox) {
+  
+  // set up _resultline_ macro
+  text_t resline;
+  int maxdocs = args.getintarg("m");
+  if (num_phrases > 0) isApprox = Exact;
+  if (maxdocs == -1) maxdocs = numdocs;
+  else if (numdocs > maxdocs) {
+    numdocs = maxdocs;
+    isApprox = MoreThan;
+  }
+
+  if (isApprox == Approximate) resline = "_textapprox_";
+  else if (isApprox == MoreThan) resline = "_textmorethan_";
+  
+  if (numdocs == 0) resline = "_textnodocs_";
+  else if (numdocs == 1) resline += "_text1doc_";
+  else resline += text_t(numdocs) + " _textlotsdocs_";
+  
+  disp.setmacro("resultline", "query", resline);
+
+  int firstdoc = args.getintarg("r");
+  int hitsperpage = args.getintarg("o");
+  if (hitsperpage == -1) hitsperpage = numdocs;
+
+  // set up _thisfirst_ and _thislast_ macros
+  disp.setmacro ("thisfirst", "query", firstdoc);
+  int thislast = firstdoc + (hitsperpage - 1);
+  if (thislast > numdocs) thislast = numdocs;
+  disp.setmacro ("thislast", "query", thislast);
+
+  // set up _prevfirst_ and _prevlast_ macros
+  if (firstdoc > 1) {
+    disp.setmacro ("prevlast", "query", firstdoc - 1);
+    int prevfirst = firstdoc - hitsperpage;
+    if (prevfirst < 1) prevfirst = 1;
+    disp.setmacro ("prevfirst", "query", prevfirst);
+  }
+
+  // set up _nextfirst_ and _nextlast_ macros
+  if (thislast < numdocs) {
+    disp.setmacro ("nextfirst", "query", thislast + 1);
+    int nextlast = thislast + hitsperpage;
+    if (nextlast > numdocs) nextlast = numdocs;
+    disp.setmacro ("nextlast", "query", nextlast);
+  }
+
+  // do quoted query here cos we may have added quotes during query pre-processing
+  if (args["ct"]==0) { // mg queries only, not mgpp
+    // get the quoted bits of the query string and set _quotedquery_
+    text_tarray phrases;
+    get_phrases (args["q"], phrases);
+    num_phrases = phrases.size();
+    text_tarray::const_iterator phere = phrases.begin();
+    text_tarray::const_iterator pend = phrases.end();
+    bool first = true;
+    text_t quotedquery;
+    while (phere != pend) {
+      if (!first)
+	if ((phere +1) == pend) quotedquery += " and ";
+	else quotedquery += ", ";
+      
+      quotedquery += "\"" + *phere + "\"";
+      first = false;
+      ++phere;
+    }
+    if (args.getintarg("s") && !quotedquery.empty()) quotedquery += "_textstemon_";
+    disp.setmacro ("quotedquery", "query", quotedquery);
+  }
+
+}
+
+// define_single_query_macros sets the extra macros for search_single_coll 
+// that couldn't be set until the query had been done. Those macros are 
+// _freqmsg_ and _stopwordsmsg_
+void queryaction::define_single_query_macros (cgiargsclass &args, 
+					      displayclass &disp, 
+					      const FilterResponse_t &response) {
+  // set up _freqmsg_ and _stopwordsmsg_ macros
+
+  text_t freqmsg = "";
+  freqmsg = "_textfreqmsg1_";
+  TermInfo_tarray::const_iterator this_term = response.termInfo.begin();
+  TermInfo_tarray::const_iterator end_term = response.termInfo.end();
+  while (this_term != end_term) {
+    freqmsg += (*this_term).term + ": " + (*this_term).freq;
+    if ((this_term + 1) != end_term)
+      freqmsg += ", ";
+    ++this_term;
+  }
+  disp.setmacro ("freqmsg", "query", freqmsg);
+
+  text_tset::const_iterator this_stopword = response.stopwords.begin();
+  text_tset::const_iterator end_stopword = response.stopwords.end();
+  if (this_stopword != end_stopword) {
+    text_t stopwordsmsg = "_textstopwordsmsg_ ";
+    while (this_stopword != end_stopword) {
+      if (stopwordsmsg != "_textstopwordsmsg_ ") {
+	stopwordsmsg += ", ";
+      }
+      stopwordsmsg += (*this_stopword);
+      ++this_stopword;
+    }
+    disp.setmacro("stopwordsmsg", "query", stopwordsmsg);
+  }
+}
+
+// should this change for cross coll search??
+bool queryaction::save_search_history (cgiargsclass &args, int numdocs, 
+				       isapprox isApprox) {
+  if (args["q"]=="") return true; // null query, dont save
+  if (args["hs"]=="0") return true; // only save when submit query pressed
+  
+  // get userid
+  text_t userid = args["z"];
+
+  // the number of docs goes on the front of the query string
+  text_t query = text_t(numdocs);
+  if (isApprox==MoreThan) { // there were more docs found
+    query.push_back('+');
+  }
+  query += "c="+args["c"];
+  query += ";h="+args["h"];
+  query += ";t="+args["t"];
+  query += ";b="+args["b"];
+  query += ";j="+args["j"];
+  query += ";n="+args["n"];
+  query += ";s="+args["s"];
+  query += ";k="+args["k"];
+  query += ";g="+args["g"]; 
+  
+  text_t qstring = args["q"];
+  //text_t formattedquery =cgi_safe(qstring);
+  //query += "&amp;q="+formattedquery;
+  query += ";q="+qstring;
+  bool display=false;
+  int hd = args.getintarg("hd");
+  if (hd > 0) display=true;
+  if (set_history_info(userid, query, dbhome, display)) return true;
+  else return false;
+
+
+}
+
Index: /gsdl/trunk/runtime-src/src/recpt/queryaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/queryaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/queryaction.h	(revision 16571)
@@ -0,0 +1,153 @@
+/**********************************************************************
+ *
+ * queryaction.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef QUERYACTION_H
+#define QUERYACTION_H
+
+#include "gsdlconf.h"
+#include "action.h"
+#include "receptionist.h"
+
+struct colinfo_t {
+  void clear();
+  colinfo_t () {clear();}
+
+  format_t *formatlistptr;
+  browserclass *browserptr;
+};
+
+struct QueryResult_t {
+  void clear ();
+  QueryResult_t () {clear();}
+
+  ResultDocInfo_t doc;
+  text_t collection;
+};
+
+struct gteqQueryResult_t 
+{
+  bool operator()(const QueryResult_t &t1, const QueryResult_t &t2) const
+  { return t1.doc.ranking >= t2.doc.ranking; }
+};
+
+typedef set<QueryResult_t, gteqQueryResult_t> QueryResult_tset;
+
+
+class queryaction : public action {
+
+protected:
+
+  receptionist *recpt;
+
+  text_t m_strUseInterfaceLanguageForQuery;
+  text_t formatstring;
+  text_tmap reqfields; // required fields
+  int num_phrases;
+
+  virtual void define_single_query_macros (cgiargsclass &args, 
+					   displayclass &disp, 
+					   const FilterResponse_t &response); 
+  virtual void define_query_macros (cgiargsclass &args, displayclass &disp, 
+			    int numDocs, isapprox isApprox); 
+
+  void get_formatted_query_string (text_t &formattedstring, bool segment, 
+				   cgiargsclass &args, 
+				   displayclass &disp, ostream &logout);
+  void define_query_interface(displayclass &disp, cgiargsclass &args, 
+			      recptprotolistclass *protos, ostream &logout);
+  
+  void define_form_macros (displayclass &disp, cgiargsclass &args, 
+			   recptprotolistclass *protos, ostream &logout);
+
+  void define_history_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+
+  virtual void set_option_macro (const text_t &macroname, text_t current_value,
+				 bool display_single, bool add_js_update,
+			 const FilterOption_t &option, displayclass &disp);
+
+  void set_gformselection_macro (text_t current_value,
+				 const FilterOption_t &option,
+				 displayclass &disp);
+  void set_sfselection_macro (text_t current_value, 
+			      const FilterOption_t &option, 
+			      displayclass &disp);
+
+  void output_ccp (cgiargsclass &args, recptprotolistclass *protos,
+		   displayclass &disp, outconvertclass &outconvert,
+		   ostream &textout, ostream &logout);
+  
+  bool search_multiple_collections (cgiargsclass &args, 
+				    recptprotolistclass *protos,
+				    browsermapclass *browsers, 
+				    displayclass &disp,
+				    outconvertclass &outconvert, 
+				    ostream &textout,
+				    ostream &logout);
+  
+  virtual bool search_single_collection (cgiargsclass &args, 
+					 const text_t &collection,
+					 recptprotolistclass *protos, 
+					 browsermapclass *browsers, 
+					 displayclass &disp, 
+					 outconvertclass &outconvert, 
+					 ostream &textout, ostream &logout);
+
+
+  bool save_search_history(cgiargsclass &args, int numdocs, isapprox isApprox);
+
+public:
+  queryaction ();
+  virtual ~queryaction () {}
+
+  void set_receptionist (receptionist *therecpt) {recpt=therecpt;}
+  
+  void configure (const text_t &key, const text_tarray &cfgline);
+  bool init (ostream &logout);
+  
+  virtual text_t get_action_name () {return "q";}
+  
+  virtual bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+			      recptprotolistclass *protos, ostream &logout);
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response, text_t &response_data, 
+			 ostream &logout);
+  
+  virtual void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+
+  virtual void define_external_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+  
+  virtual bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/querytools.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/querytools.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/querytools.cpp	(revision 16571)
@@ -0,0 +1,897 @@
+/**********************************************************************
+ *
+ * querytools.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "querytools.h"
+#include <ctype.h>
+#include "unitool.h" // for is_unicode_letdig
+
+// sets the ct, qt, qto arguments
+void set_query_type_args(ColInfoResponse_t *cinfo, cgiargsclass &args) {
+
+  if (args["ct"].empty()) {
+    text_t build_type = cinfo->buildType;
+    if (build_type == "mgpp") {
+      args["ct"] = "1";
+    } else if (build_type == "lucene") {
+      args["ct"] = "2";
+    } else {
+      args["ct"] = "0";
+    }
+  }
+  text_t arg_ct = args["ct"];
+  if (arg_ct == "0") {
+    // mg
+    args["qt"] = "0";
+    args["qto"] = "0";
+    return;
+  }
+
+  if (!args["qt"].empty() && !args["qto"].empty()) {
+    return;
+  }
+  
+  text_tmap::iterator check = cinfo->format.find("SearchTypes");
+  text_t search_types;
+  if(check != cinfo->format.end() && !(*check).second.empty()){
+    search_types = (*check).second;
+  } else {
+    // assume plain,form
+    if (args["qto"].empty()) args["qto"] = "3";
+    if (args["qt"].empty()) {
+      int arg_qto = args.getintarg("qto");
+      if (arg_qto == 2) {
+	args["qt"] = "1";
+      } else {
+	args["qt"] = "0";
+      }
+    }
+    return;
+  }
+  
+  
+  if (args["qto"].empty()) {
+    unsigned int type = 0;
+    if (findword(search_types.begin(), search_types.end(), "form") != search_types.end()) {
+      type |= 2;
+    }
+    if (findword(search_types.begin(), search_types.end(), "plain") != search_types.end()) {
+      type |= 1;
+    }
+    args.setintarg("qto", type);
+  } 
+  
+  if (args["qt"].empty()) {
+    int arg_qto = args.getintarg("qto");
+    if (arg_qto == 2 || (arg_qto == 3 && starts_with(search_types, "form"))) {
+      args["qt"] = "1";
+    } else {
+      args["qt"] = "0";
+    }
+  }
+}
+
+// sets the ks, ss, afs (casesupport, stemsupport, accentfoldsupport) args
+void set_stem_index_args(ColInfoResponse_t *cinfo, cgiargsclass &args) {
+  int stemIndexes = cinfo->stemIndexes;
+
+  if (stemIndexes & SIcasefold) {
+    args["ks"] = 1;
+  }
+  if (stemIndexes & SIstem) {
+    args["ss"] = 1;
+  }
+  if (stemIndexes & SIaccentfold) {
+    args["afs"] = 1;
+  }
+
+}
+
+// request.filterResultOptions and request.fields (if required) should
+// be set from the calling code
+void set_queryfilter_options (FilterRequest_t &request, 
+			      const text_t &querystring,
+			      cgiargsclass &args) {
+
+  request.filterName = "QueryFilter";
+
+  OptionValue_t option;
+
+  option.name = "Term";
+  option.value = querystring;
+  request.filterOptions.push_back (option);
+
+  option.name = "QueryType";
+  option.value = (args.getintarg("t")) ? "ranked" : "boolean";
+  request.filterOptions.push_back (option);
+
+  option.name = "MatchMode";
+  // mgpp in advanced mode, always use some query
+  if (args.getintarg("ct") == 1 && args.getintarg("b") == 1) {
+    option.value = "some";
+  } else {
+    option.value = (args.getintarg("t")) ? "some" : "all";
+  }
+  request.filterOptions.push_back (option);
+
+  option.name = "Casefold";
+  option.value = (args.getintarg("k")) ? "true" : "false";
+  request.filterOptions.push_back (option);
+
+  option.name = "Stem";
+  option.value = (args.getintarg("s")) ? "true" : "false";
+  request.filterOptions.push_back (option);
+
+  option.name = "AccentFold";
+  option.value = (args.getintarg("af")) ? "true" : "false";
+  request.filterOptions.push_back (option);
+  
+  if (!args["h"].empty()) {
+    option.name = "Index";
+    option.value = args["h"];
+    request.filterOptions.push_back (option);
+  }
+
+  if (!args["j"].empty()) {
+    option.name = "Subcollection";
+    option.value = args["j"];
+    request.filterOptions.push_back (option);
+  }
+
+  if (!args["n"].empty()) {
+    option.name = "Language";
+    option.value = args["n"];
+    request.filterOptions.push_back (option);
+  }
+  
+  if (!args["g"].empty()) { // granularity for mgpp
+    option.name = "Level";
+    option.value = args["g"];
+    request.filterOptions.push_back (option);
+  }
+
+  if (!args["fs"].empty()) { // filter string for lucene
+    option.name = "FilterString";
+    option.value = args["fs"];
+    request.filterOptions.push_back (option);
+  }
+
+  if (!args["sf"].empty()) { // sort field for lucene
+    option.name = "SortField";
+    option.value = args["sf"];
+    request.filterOptions.push_back (option);
+  }
+
+  if (!args["fuzziness"].empty() && args["fuzziness"] != "100") { // fuzziness value for lucene
+    option.name = "Fuzziness";
+    option.value = (text_t) "0." + args["fuzziness"];
+    request.filterOptions.push_back (option);
+  }
+
+  set_more_queryfilter_options (request, args);
+}
+
+void set_queryfilter_options (FilterRequest_t &request, 
+			      const text_t &querystring1,
+			      const text_t &querystring2, cgiargsclass &args) {
+
+  set_queryfilter_options (request, querystring1, args);
+
+  // fill in the second query if needed
+  if (!args["cq2"].empty()) {
+    OptionValue_t option;
+
+    option.name = "CombineQuery";
+    option.value = args["cq2"];
+    request.filterOptions.push_back (option);
+    
+    option.name = "Term";
+    option.value = querystring2;
+    request.filterOptions.push_back (option);
+    
+    option.name = "QueryType";
+    option.value = (args.getintarg("t")) ? "ranked" : "boolean";
+    request.filterOptions.push_back (option);
+
+    option.name = "Casefold";
+    option.value = (args.getintarg("k")) ? "true" : "false";
+    request.filterOptions.push_back (option);
+
+    option.name = "Stem";
+    option.value = (args.getintarg("s")) ? "true" : "false";
+    request.filterOptions.push_back (option);
+
+    option.name = "AccentFold";
+    option.value = (args.getintarg("af")) ? "true" : "false";
+    request.filterOptions.push_back (option);
+
+    if (!args["h2"].empty()) {
+      option.name = "Index";
+      option.value = args["h2"];
+      request.filterOptions.push_back (option);
+    }
+
+    if (!args["j2"].empty()) {
+      option.name = "Subcollection";
+      option.value = args["j2"];
+      request.filterOptions.push_back (option);
+    }
+
+    if (!args["n2"].empty()) {
+      option.name = "Language";
+      option.value = args["n2"];
+      request.filterOptions.push_back (option);
+    }
+  }
+  set_more_queryfilter_options (request, args);
+}
+
+void set_more_queryfilter_options (FilterRequest_t &request, 
+				   cgiargsclass &args) {
+
+  OptionValue_t option;
+  int arg_m = args.getintarg("m");
+  
+  option.name = "Maxdocs";
+  option.value = arg_m;
+  request.filterOptions.push_back (option);
+
+  //  option.name = "StartResults";
+  //  option.value = args["r"];
+  //  request.filterOptions.push_back (option);
+
+  //  option.name = "EndResults";
+  //  int endresults = args.getintarg("o") + (args.getintarg("r") - 1);
+  //  if ((endresults > arg_m) && (arg_m != -1)) endresults = arg_m;
+  //  option.value = endresults;
+  //  request.filterOptions.push_back (option);
+}
+
+bool is_special_character(int indexer_type, unsigned short character) {
+  // mgpp
+  if (indexer_type == 1) {
+    return (character == '#' || character == '/' || character == '*');
+  }
+  // lucene
+  else if (indexer_type == 2) {
+    return (character == '?' || character == '*' || character == '~' || 
+	    character == '^');
+  }
+  return false;
+}
+
+// This function removes boolean operators from simple searches, and segments
+// chinese characters if segment=true
+void format_querystring (text_t &querystring, int querymode, bool segment) {
+  text_t formattedstring;
+
+  // advanced search, no segmenting, don't need to do anything
+  if (querymode == 1 && !segment) return;
+  
+  text_t::const_iterator here = querystring.begin();
+  text_t::const_iterator end = querystring.end();
+
+  // space is used to insert spaces between Chinese
+  // characters. No space is needed before the first
+  // Chinese character.
+  bool space = false;
+
+  // want to remove ()|!& from querystring so boolean queries are just
+  // "all the words" queries (unless querymode is advanced)
+  while (here != end) {
+    if ((querymode == 0) && (*here == '(' || *here == ')' || *here == '|' ||
+			     *here == '!' || *here == '&')) {
+      formattedstring.push_back(' ');
+    } else if (segment) {
+      if ((*here >= 0x4e00 && *here <= 0x9fa5) ||
+	  (*here >= 0xf900 && *here <= 0xfa2d)) {
+	// Chinese character
+	if (!space) formattedstring.push_back (0x200b); // zero width space
+	formattedstring.push_back (*here);
+	formattedstring.push_back (0x200b);
+	space = true;
+      } else {
+	
+	// non-Chinese character
+	formattedstring.push_back (*here);
+	space = false;
+	
+      }
+    
+    } else {
+      formattedstring.push_back (*here);
+    }
+    ++here;
+  }
+  querystring = formattedstring;
+}
+
+
+	
+
+// search history tool 
+// also used for form query macros
+text_t escape_quotes(const text_t &querystring) {
+
+  text_t::const_iterator here = querystring.begin();
+  text_t::const_iterator end = querystring.end();
+ 
+  text_t escquery = "";
+  while (here != end) {
+    if (*here != '\'' && *here != '\"' && *here != '\n' && *here != '\r') escquery.push_back(*here);
+    else if (*here == '\n' || *here == '\r') {
+      escquery.push_back(' ');
+    } else {
+      escquery +="\\\\";
+      escquery.push_back(*here);
+    }
+
+    ++here;
+  }
+  return escquery;
+
+}
+
+// Parses the terms into words, and adds #si if necessary
+text_t addstemcase(const text_t &terms, const text_t &stem, const text_t &fold,
+		   const int indexer_type) {
+  
+  // the default stem and case are set to 0 if this is being used, so we are only adding on qualifiers if stem or fold is 1.
+  if (stem == "0" && fold == "0") {
+    return terms;
+  }
+  // this is only for mgpp collections, shouldn't be called for anything else
+  if (indexer_type != 1) {
+    return terms;
+  }
+  
+  text_t outtext;
+  text_t word;
+
+  text_t::const_iterator here = terms.begin();
+  text_t::const_iterator end = terms.end();
+
+  while (here !=end) {
+
+    if (is_unicode_letdig(*here) || is_special_character(indexer_type, *here)) {
+      // not word boundary
+      word.push_back(*here);
+      ++here;    
+    }
+    else {
+      // found word boundary   
+      if (!word.empty() ) {
+	if (starts_with(word, "NEAR") || starts_with(word, "WITHIN")) {
+	  outtext += word;
+	  word.clear();
+	}
+	else {
+	  word += "#";
+	  if (stem == "1") word += "s";
+	  if (fold == "1") word += "i";
+	  outtext += word;
+	  word.clear();
+	}
+      }
+      // this only used in advanced form, so we leave in boolean operators
+      if (*here == '\"' || *here == '&' || *here == '|' || *here == '!' || 
+	  *here == '(' || *here == ')' || is_unicode_space(*here)) {
+	outtext.push_back(*here);
+      }
+      ++here;
+    }
+  }
+   
+  // get last word
+  if (!word.empty()) {
+    word += "#";
+    if (stem == "1") word += "s";
+    if (fold == "1") word += "i";
+    word += " ";
+    outtext += word;
+  }
+  return outtext;
+}
+
+
+// some query form parsing functions for use with mgpp & lucene
+
+void parse_reg_query_form(text_t &querystring, cgiargsclass &args, bool segment)
+{
+  querystring.clear();
+
+  int argct = args.getintarg("ct");
+  int argt = args.getintarg("t");// t=0 -and, t=1 - or
+  int argb = args.getintarg("b");
+    
+  text_t combine;
+
+  // lucene uses global combine, so only need this for mgpp
+  if (argct==1) {
+    if (argt == 0) combine = "&";
+    else combine = "|";
+  }
+  
+  text_t field = args["fqf"];
+  if (field.empty()) return; // no query
+  text_tarray fields;
+  splitchar(field.begin(), field.end(), ',', fields); 
+  
+  text_t value = args["fqv"];
+  if (value.empty()) return; // somethings wrong
+  text_tarray values;
+  splitchar(value.begin(), value.end(), ',', values);
+
+
+  for (int i=0; i< values.size(); ++i) {
+    if (!values[i].empty()) {
+      text_t this_value = values[i];
+      // remove operators for simple search, segments text if necessary
+      format_querystring(this_value, argb, segment); 
+      // add tag info for this field (and other processing)
+      format_field_info(this_value, fields[i], argct, argt, argb);
+      // add into query string
+      if (argct == 2) {
+	// lucene
+	// we don't worry about AND/OR, cos this is done by defaultcombineoperator
+	querystring += this_value+" ";
+      } else {
+	// mgpp
+	if (!querystring.empty()) {
+	  querystring += " "+ combine+ " ";
+	}
+	querystring += this_value;
+      }
+    }
+  }
+}
+
+
+void parse_adv_query_form(text_t &querystring, cgiargsclass &args, bool segment){
+  querystring.clear();
+
+  const int argct = args.getintarg("ct");
+  int argt = 0;// arg t is either not used (lucene) or used for natural/ranked (mgpp), so we set it to 0 = AND, by default
+  int argb = args.getintarg("b");
+  text_t combine;
+  if (argct==1) {
+    combine = "&";
+  }
+  else { // lucene
+    combine = "AND";
+  }
+
+  text_t field = args["fqf"];
+  if (field.empty()) return; // no query
+  text_tarray fields;
+  splitchar(field.begin(), field.end(), ',', fields); 
+  
+  text_t value = args["fqv"];
+  if (value.empty()) return; // somethings wrong
+  text_tarray values;
+  splitchar(value.begin(), value.end(), ',', values);
+
+  text_t comb = args["fqc"];
+  if (comb.empty()) return; //somethings wrong
+  text_tarray combs;
+  splitchar(comb.begin(), comb.end(), ',', combs);
+
+  text_tarray stems;
+  text_tarray folds;
+  if (argct == 1) {// mgpp - lucene doesn't do stem/case
+    text_t stem = args["fqs"];
+    if (stem.empty()) return; // somethings wrong
+    splitchar(stem.begin(), stem.end(), ',', stems);
+    
+    text_t fold = args["fqk"];
+    if (fold.empty()) return; // somethings wrong
+    splitchar(fold.begin(), fold.end(), ',', folds);
+  }
+  
+  for(int i=0; i< values.size(); ++i) {
+    if (!values[i].empty()) {
+      if (i!=0) {
+	if (argct==1) {
+	  if (combs[i-1]=="and") combine = "&";
+	  else if (combs[i-1]=="or")combine = "|";
+	  else if (combs[i-1]=="not")combine = "!";
+	}
+	else { // lucene
+	  if (combs[i-1]=="and") combine = "AND";
+	  else if (combs[i-1]=="or")combine = "OR";
+	  else if (combs[i-1]=="not")combine = "NOT";
+	}
+      }
+      text_t this_value = values[i];
+      // remove operators for simple search, segments text if necessary
+      format_querystring(this_value, argb, segment); 
+      if (argct == 1) { // mgpp only
+	this_value = addstemcase(this_value, stems[i], folds[i], argct);
+      }
+      // add tag info for this field (and other processing)
+      format_field_info(this_value, fields[i], argct, argt, argb);
+      // add into query string
+      if (!querystring.empty()) {
+	querystring += " "+ combine+ " ";
+      }
+      querystring += this_value;
+      
+    }
+  }
+}
+
+// Extended addqueryelem for Human Info project
+void addqueryelem_ex(text_t &querystring, const text_t &tag, 
+		     const text_t &terms, const text_t &stem, 
+		     const text_t &fold,
+		     const text_t& combine, const text_t& word_combine) {
+
+  if (!querystring.empty()) { // have to put and/or
+    querystring += " " + combine + " ";
+  }
+  text_t outtext; outtext.reserve(512);
+  text_t word; word.reserve(100);
+  //unsigned short c;                                                            
+  text_t::const_iterator here = terms.begin();
+  text_t::const_iterator end = terms.end();
+  bool inquote = false, firstword = true;
+
+  text_t word2; word2.reserve(256);
+	
+  while (here !=end) {
+    if (is_unicode_space(*here)) {
+      if (word2 == "AND") { word2.clear(); word2.push_back(7527); word2.appendcarr("AND", 3); word2.push_back(7527); }
+      else if (word2 == "OR") { word2.clear(); word2.push_back(7527); word2.appendcarr("OR", 2); word2.push_back(7527); }
+      else if (word2 == "NOT") { word2.clear(); word2.push_back(7527); word2.appendcarr("NOT", 3); word2.push_back(7527); }
+      else if (word2 == "NEAR") { word2.clear(); word2.push_back(7527); word2.appendcarr("NEAR", 4); word2.push_back(7527); }
+      else if (word2 == "WITHIN") { word2.clear(); word2.push_back(7527); word2.appendcarr("WITHIN", 6); word2.push_back(7527); }
+      if (inquote) {
+	word2.push_back(*here);
+      }
+      word.append(word2); word2.clear();
+			
+      if (!inquote && !word.empty() ) {
+	// found word boundary   
+				
+	if (stem == "1" || fold =="1") {
+	  word += "#";
+	  if (stem == "1") word += "s";
+	  //else word += "u";
+					
+	  if (fold == "1") word += "i";
+	  //else word += "c";
+	}
+	if (firstword) {
+	  firstword = false;
+	} else {
+	  outtext += " " + word_combine + " ";
+	}
+	outtext += "[" + word + "]:"+tag;
+	word.clear();
+      }
+      ++here;
+    } else if (*here == '\"') {
+      word2.push_back(*here);
+      inquote = !inquote;
+      ++here;
+    } else {
+      // not word boundary
+      word2.push_back(*here);
+      ++here;    
+    }
+  }
+	
+  // get last word
+  if (!word2.empty()) {
+    if (word2 == "AND") { word2.clear(); word2.push_back(7527); word2.appendcarr("AND", 3); word2.push_back(7527); }
+    else if (word2 == "OR") { word2.clear(); word2.push_back(7527); word2.appendcarr("OR", 2); word2.push_back(7527); }
+    else if (word2 == "NOT") { word2.clear(); word2.push_back(7527); word2.appendcarr("NOT", 3); word2.push_back(7527); }
+    else if (word2 == "NEAR") { word2.clear(); word2.push_back(7527); word2.appendcarr("NEAR", 4); word2.push_back(7527); }
+    else if (word2 == "WITHIN") { word2.clear(); word2.push_back(7527); word2.appendcarr("WITHIN", 6); word2.push_back(7527); }
+    word.append(word2); word2.clear();
+		
+    if (stem == "1"|| fold == "1") {
+      word += "#";
+      if (stem == "1") word += "s";
+      //else word += "u";
+			
+      if (fold == "1") word += "i";
+      //else word += "c";
+    }
+    if (!outtext.empty()) outtext += " " + word_combine + " ";
+    outtext += "[" + word + "]:"+tag;
+  }
+  querystring += "(" + outtext + ")";
+}
+
+void add_field_info(text_t &querystring, const text_t &tag, int type) {
+
+  if (tag == "" || tag == "ZZ") return; // do nothing
+  if (type == 1) { //mgpp
+    querystring = "["+querystring+"]:"+tag;
+  } else if (type == 2) { // lucene
+    querystring = tag+":("+querystring+")";
+  }
+    
+}
+
+
+void format_field_info_lucene(text_t &querystring, text_t tag, int argt, int argb) {
+  if (tag == "ZZ") tag = ""; // ZZ is a special tag meaning no tag (all fields)
+  int type = 2; //lucene
+
+  if (argb==0) { // simple
+    // there will be no & or | as they should have already been removed
+    // just tag the entire thing
+    if (tag != "") {
+      add_field_info(querystring, tag, type);
+    }
+    return;
+  }
+
+  // need to replace & with &&, | with ||
+  text_t::const_iterator here = querystring.begin();
+  text_t::const_iterator end = querystring.end();
+
+  text_t finalquery = "";
+  while (here != end) {
+    if (*here ==  '&') {
+      finalquery.push_back('&');
+      finalquery.push_back('&');
+      while (*(here+1) == '&') {
+	++here;
+      }
+    } 
+    else if (*here == '|') {
+      finalquery.push_back('|');
+      finalquery.push_back('|');
+      while (*(here+1) == '|') {
+	++here;
+      }
+    } 
+    else {
+      finalquery.push_back(*here);
+    }
+    ++here;
+  }
+  querystring = finalquery;
+  add_field_info(querystring, tag, type);
+}
+
+
+void format_field_info_mgpp(text_t &querystring, text_t tag, int argt, int argb) {
+
+  if (tag == "ZZ") tag = ""; // ZZ is a special tag meaning no tag (all fields)
+  if (tag == "" && argb == 1) {
+    return; // no field specifier, advanced mode, the query stays as written
+  }
+
+  int type = 1; // mgpp
+
+  bool simple_and = (argb==0 && argt==0); 
+  text_t finalquery = "";
+  text_t fieldpart ="";
+  text_t queryelem = "";
+  bool in_phrase = false;
+  bool in_field = false;
+
+  text_t::const_iterator here = querystring.begin();
+  text_t::const_iterator end = querystring.end();
+  while (here != end) {
+    if (is_unicode_letdig(*here)  || *here == '&' || is_special_character(type, *here)) {
+      queryelem.push_back(*here);
+    }
+    else if (*here == '|') {
+      in_field = false;
+    }
+    else if (*here == '!' || *here == '(' || *here == ')') {
+      if (!in_phrase) { // ignore these if in_phrase
+	// output field, then output operator
+	in_field = false;
+	if (!queryelem.empty()) {
+	  if (!simple_and && !fieldpart.empty()) {
+	    add_field_info(fieldpart, tag, type);
+	    finalquery += fieldpart;
+	    finalquery.push_back(' ');
+	    fieldpart.clear();
+	  }
+	  fieldpart += queryelem;
+	}
+	if (!fieldpart.empty()) {
+	  add_field_info(fieldpart, tag, type);
+	  finalquery += fieldpart;
+	  finalquery.push_back(' ');
+	}
+	fieldpart.clear();
+	queryelem.clear();
+	finalquery.push_back(*here);
+	finalquery.push_back(' ');
+      }
+    }
+    else if (*here == '"') {
+      queryelem.push_back(*here);
+      if (in_phrase == false) in_phrase = true;
+      else {
+	in_phrase = false;
+      }
+    }
+
+    // Found word boundary, in a phrase
+    else if (in_phrase) {
+      queryelem.push_back(*here);
+    }
+    // Found a word boundary
+    else {
+      if (!queryelem.empty()) {
+	if (queryelem == "&") {
+	  in_field = true;
+	  queryelem.clear();
+	}
+	else if (starts_with(queryelem, "NEAR") || starts_with(queryelem, "WITHIN")) {
+	  
+	  if (argb==1) {
+	    // simple search, these not allowed
+	    in_field = true;
+	    fieldpart += queryelem;
+	    fieldpart.push_back(' ');
+	  }
+	  queryelem.clear();
+	  
+	} 
+	else {
+	  if (!simple_and && !in_field) {
+	    if (!fieldpart.empty()) {
+	      add_field_info(fieldpart, tag, type);
+	      finalquery += fieldpart;
+	      finalquery.push_back(' ');
+	      fieldpart.clear();
+	    } 
+	  }
+	  
+	  fieldpart += queryelem;
+	  fieldpart.push_back(' ');
+	  queryelem.clear();
+	}
+      }
+    }
+    ++here;
+  }
+  // at the end
+  if (!queryelem.empty()) {
+    if (!simple_and && !in_field && !fieldpart.empty()) {
+      add_field_info(fieldpart, tag, type);
+      finalquery += fieldpart;
+      finalquery.push_back(' ');
+      fieldpart.clear();
+    }
+    fieldpart += queryelem;
+  }
+  if (!fieldpart.empty()) {
+    add_field_info(fieldpart, tag, type);
+    finalquery += fieldpart;
+    fieldpart.clear();
+    finalquery.push_back(' ');
+  }
+
+  querystring  = finalquery;
+}
+
+
+void format_field_info(text_t &querystring, text_t tag, int argct, int argt, int argb) {  
+  if (argct == 1) {
+    format_field_info_mgpp(querystring, tag, argt, argb);
+  } else if (argct == 2) {
+    format_field_info_lucene(querystring, tag, argt, argb);
+  }
+}
+
+void mgpp_adddateelem(text_t& querystring, const int date)
+{
+  querystring.appendcstr(" [");
+  if(date<0) {
+      querystring.appendcstr("bc");
+      querystring.appendint((date*-1));
+  }
+  else {
+    querystring.appendint(date);
+  }
+  querystring.appendcstr("]:CV");
+}
+
+void lucene_adddateelem(text_t& querystring, const int date)
+{
+  querystring.appendcstr(" CV:(");
+  if(date<0) {
+      querystring.appendcstr("bc");
+      querystring.appendint((date*-1));
+  }
+  else {
+    querystring.appendint(date);
+  }
+  querystring.appendcstr(")");
+}
+
+
+void add_dates(text_t &querystring, int startdate, int enddate, 
+	       int startbc, int endbc, int ct)
+{
+  if(startdate)
+    {
+      int querystringis = 0;
+      text_t::const_iterator here = querystring.begin();
+      text_t::const_iterator end = querystring.end();
+      while(here!=end)
+	{
+	  if(!(isspace((*here)))){
+	    here = end;
+	    querystringis = 1;
+	  }
+	  else
+	    ++here;
+	}
+      //converting BCE dates
+      if(startbc && startdate > 0)
+	{
+	  startdate *= -1;
+	}
+      if(endbc && enddate > 0)
+	{
+	  enddate *= -1;
+	}
+       if(enddate != 0 && enddate<startdate)
+	{
+	  cout<<"enddate too small"<<endl;
+	  return;
+	}
+       if(querystringis)
+	 querystring.appendcstr(" AND");
+       if(!enddate)
+	 {
+	   if (ct==1) {
+	     mgpp_adddateelem(querystring,startdate);
+	   }
+	   else { // lucene
+	     lucene_adddateelem(querystring,startdate);
+	   }
+	 }
+       else{
+	 int nextdate = startdate;
+	 querystring.appendcstr(" (");
+	 while(nextdate<=enddate)
+	   {
+	     if(nextdate!=0) {
+	       if (ct==1) {
+		 mgpp_adddateelem(querystring,nextdate);
+	       }
+	       else { // lucene
+		 lucene_adddateelem(querystring,nextdate);
+	       }
+	     }
+	     ++nextdate;
+	   }
+	 querystring.appendcstr(" )");
+       }
+    }
+
+}
Index: /gsdl/trunk/runtime-src/src/recpt/querytools.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/querytools.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/querytools.h	(revision 16571)
@@ -0,0 +1,65 @@
+/**********************************************************************
+ *
+ * querytools.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef QUERYTOOLS_H
+#define QUERYTOOLS_H
+
+#include "cgiargs.h"
+#include "recptproto.h"
+
+void set_query_type_args(ColInfoResponse_t *cinfo, cgiargsclass &args);
+void set_stem_index_args(ColInfoResponse_t *cinfo, cgiargsclass &args);
+
+void set_queryfilter_options (FilterRequest_t &request, const text_t &querystring,
+			      cgiargsclass &args);
+
+void set_queryfilter_options (FilterRequest_t &request, const text_t &querystring1,
+			      const text_t &querystring2, cgiargsclass &args);
+
+// don't hassle the function name ... it's been a long day ;)
+void set_more_queryfilter_options (FilterRequest_t &request, cgiargsclass &args);
+
+void format_querystring (text_t &querystring, int querymode, bool segment);
+
+void add_dates(text_t &querystring, int startdate, int enddate, 
+	       int startbc, int endbc, int ct);
+
+// search history tool
+text_t escape_quotes(const text_t &querystring);
+
+// some query parsing functions for form processing (only for mgpp/lucene collections)
+void parse_reg_query_form(text_t &formattedstring, cgiargsclass &args, bool segment);
+void parse_adv_query_form(text_t &formattedstring, cgiargsclass &args, bool segment);
+
+// Added for Human Info project
+void addqueryelem_ex(text_t &querystring, const text_t &tag, 
+		     const text_t &terms, const text_t &stem, 
+		     const text_t &fold,
+		     const text_t& combine, const text_t& word_combine);
+
+void format_field_info(text_t &querystring, text_t tag, int argct, int argt, int argb);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/receptionist.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/receptionist.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/receptionist.cpp	(revision 16571)
@@ -0,0 +1,1742 @@
+/**********************************************************************
+ *
+ * receptionist.cpp -- a web interface for the gsdl
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+// following line required to get fstream.filedesc() on darwin (Mac OS X)
+// gcc 2.91 automatically defines this in stream.h
+#define _STREAM_COMPAT  1
+
+#include "receptionist.h"
+#include "recptprototools.h"
+#include "fileutil.h"
+#include "cgiutils.h"
+#include "htmlutils.h"
+#include "gsdltools.h"
+#include "gsdltimes.h"
+#include "OIDtools.h"
+#include <assert.h>
+#include <time.h>
+#include <stdio.h> // for open()
+#include <fcntl.h> // for open() flags
+// following 2 are for printing Last-Modified http header.
+#include <sys/stat.h>
+#include <time.h>
+
+#if defined (GSDL_USE_IOS_H)
+#include <fstream.h>
+#else 
+#include <fstream>
+#endif
+
+void recptconf::clear () {
+  gsdlhome.clear();
+  collecthome.clear();
+  dbhome.clear();
+  collectinfo.erase(collectinfo.begin(), collectinfo.end());
+  collection.clear();
+  collectdir.clear();
+  httpprefix.clear();
+  httpimg = "/images";
+  gwcgi.clear();
+  macrofiles.erase(macrofiles.begin(), macrofiles.end());
+  saveconf.clear();
+  usecookies = false;
+  logcgiargs = false;
+  LogDateFormat = LocalTime;
+
+  maintainer.clear();
+  MailServer.clear();
+  LogEvents = Disabled;
+  EmailEvents = Disabled;
+  EmailUserEvents = false;
+
+  languages.erase(languages.begin(), languages.end());
+  encodings.erase(encodings.begin(), encodings.end());
+
+  site_auth = false;
+  HomePageType = "images";
+  HomePageCols = 3;
+  
+  // these default page parameters can always be overriden
+  // in the configuration file
+  pageparams.erase(pageparams.begin(), pageparams.end());
+  pageparams["c"] = ""; 
+  pageparams["l"] = "en"; 
+
+#ifdef MACROPRECEDENCE
+  macroprecedence = MACROPRECEDENCE;
+#else
+  macroprecedence.clear();
+#endif
+}
+
+void collectioninfo_t::clear () {
+  gsdl_gsdlhome.clear();
+  gsdl_dbhome.clear();
+
+  info_loaded = false;
+  info.clear();
+}
+
+void languageinfo_t::clear () {
+  longname.clear();
+  defaultencoding.clear();
+}
+
+receptionist::receptionist () {
+  // create a list of cgi arguments
+  // this must be done before the configuration
+
+  cgiarginfo ainfo;
+
+  ainfo.shortname = "e";
+  ainfo.longname = "compressed arguments";
+  ainfo.multiplechar = true;
+  ainfo.defaultstatus = cgiarginfo::good;
+  ainfo.argdefault = g_EmptyText;
+  ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, ainfo);
+
+  ainfo.shortname = "a";
+  ainfo.longname = "action";
+  ainfo.multiplechar = true;
+  ainfo.defaultstatus = cgiarginfo::none;
+  ainfo.argdefault = g_EmptyText;
+  ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, ainfo);
+
+  // w=western
+  ainfo.shortname = "w";
+  ainfo.longname = "encoding";
+  ainfo.multiplechar = true;
+  ainfo.defaultstatus = cgiarginfo::none;
+  ainfo.argdefault = g_EmptyText;
+  ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, ainfo);
+  
+  ainfo.shortname = "nw";
+  ainfo.longname = "new encoding";
+  ainfo.multiplechar = true;
+  ainfo.defaultstatus = cgiarginfo::none;
+  ainfo.argdefault = g_EmptyText;
+  ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, ainfo);
+  
+  ainfo.shortname = "c";
+  ainfo.longname = "collection";
+  ainfo.multiplechar = true;
+  ainfo.defaultstatus = cgiarginfo::none;
+  ainfo.argdefault = g_EmptyText;
+  ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, ainfo);
+  
+  // the interface language name should use the ISO 639
+  // standard
+  ainfo.shortname = "l";
+  ainfo.longname = "interface language";
+  ainfo.multiplechar = true;
+  ainfo.defaultstatus = cgiarginfo::weak;
+  ainfo.argdefault = "en";
+  ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, ainfo);
+  
+  ainfo.shortname = "nl";
+  ainfo.longname = "new language";
+  ainfo.multiplechar = false;
+  ainfo.defaultstatus = cgiarginfo::none;
+  ainfo.argdefault = "0";
+  ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, ainfo);
+  
+  // the GSDL_UID (cookie)
+  ainfo.shortname = "z";
+  ainfo.longname = "gsdl uid";
+  ainfo.multiplechar = true;
+  ainfo.defaultstatus = cgiarginfo::none;
+  ainfo.argdefault = g_EmptyText;
+  ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, ainfo);
+}
+
+
+void receptionist::add_action (action *theaction) {
+  // make sure we have an action to add
+  if (theaction == NULL) return;
+
+  // add this action to the list of actions
+  actions.addaction(theaction);
+  
+  // add the cgi arguments from this action
+  argsinfo.addarginfo (NULL, *(theaction->getargsinfo()));
+}
+
+
+void receptionist::add_browser (browserclass *thebrowser) {
+  // make sure we have a browser to add
+  if (thebrowser == NULL) return;
+
+  // add this browser to the list of browsers
+  browsers.addbrowser(thebrowser);
+}
+
+
+void receptionist::setdefaultbrowser (const text_t &browsername) {
+  browsers.setdefaultbrowser (browsername);
+}
+
+
+// configure should be called for each line in the
+// configuration files to configure the receptionist and everything
+// it contains. The configuration should take place after everything
+// has been added but before the initialisation.
+
+void receptionist::configure (const text_t &key, const text_tarray &cfgline) {
+  // configure the receptionist
+
+   
+   
+  if (cfgline.size() >= 1) {
+    cgiarginfo *info = NULL;
+    if (key == "gsdlhome") {
+      configinfo.gsdlhome = cfgline[0];
+      if (configinfo.dbhome.empty()) configinfo.dbhome = cfgline[0];
+    }
+    else if (key == "collecthome") configinfo.collecthome = cfgline[0];
+    else if (key == "gdbmhome") configinfo.dbhome = cfgline[0];
+    else if (key == "collection") {
+      configinfo.collection = cfgline[0];
+      // also need to set the default arg to this collection
+      if ((info = argsinfo.getarginfo("c")) != NULL) {
+	info->defaultstatus = cgiarginfo::good;
+	info->argdefault = cfgline[0];
+      }
+      
+    }
+    else if (key == "collectdir") configinfo.collectdir = cfgline[0];
+    else if (key == "httpprefix") configinfo.httpprefix = cfgline[0];
+    else if (key == "httpimg") configinfo.httpimg = cfgline[0];
+    else if (key == "gwcgi") configinfo.gwcgi = cfgline[0];
+    else if (key == "macrofiles") {
+      // want to append to macrofiles (i.e. may be several config files
+      // contributing, maybe from several collections).
+      text_tarray::const_iterator here = cfgline.begin();
+      text_tarray::const_iterator end = cfgline.end();
+      while (here != end) {
+	configinfo.macrofiles.insert (*here);
+	++here;
+      }
+    }
+    else if (key == "saveconf") configinfo.saveconf = cfgline[0];
+    else if (key == "usecookies") configinfo.usecookies = (cfgline[0] == "true");
+    else if (key == "logcgiargs") configinfo.logcgiargs = (cfgline[0] == "true");
+    else if (key == "maintainer") configinfo.maintainer = cfgline[0];
+    else if (key == "MailServer") configinfo.MailServer = cfgline[0];
+    else if (key == "LogDateFormat") {
+      if (cfgline[0] == "UTCTime") configinfo.LogDateFormat = UTCTime;
+      else if (cfgline[0] == "Absolute") configinfo.LogDateFormat = Absolute;
+    } 
+    else if (key == "LogEvents") {
+      if (cfgline[0] == "CollectorEvents") configinfo.LogEvents = CollectorEvents;
+      else if (cfgline[0] == "AllEvents") configinfo.LogEvents = AllEvents;
+    } 
+    else if (key == "EmailEvents") {
+      if (cfgline[0] == "CollectorEvents") configinfo.EmailEvents = CollectorEvents;
+      else if (cfgline[0] == "AllEvents") configinfo.EmailEvents = AllEvents;
+    } 
+    else if (key == "EmailUserEvents") configinfo.EmailUserEvents = (cfgline[0] == "true");
+    else if (key == "pageparam") {
+      if (cfgline.size() >= 2) configinfo.pageparams[cfgline[0]] = cfgline[1];
+      else configinfo.pageparams[cfgline[0]] = "";
+    }
+    else if (key == "macroprecedence") configinfo.macroprecedence = cfgline[0];
+    else if (key == "collectinfo") {
+      if (cfgline.size() == 3) {
+	// for backwards compatability with older collections that only use
+	// gsdlhome and dbhome
+	collectioninfo_t cinfo;
+	cinfo.gsdl_gsdlhome = cfgline[1];
+	cinfo.gsdl_collecthome = filename_cat(cfgline[1],"collect");
+	cinfo.gsdl_dbhome = cfgline[2];
+	configinfo.collectinfo[cfgline[0]] = cinfo;
+      }
+      else if (cfgline.size() >= 4) {
+	collectioninfo_t cinfo;
+	cinfo.gsdl_gsdlhome = cfgline[1];
+	cinfo.gsdl_collecthome = cfgline[2];
+	cinfo.gsdl_dbhome = cfgline[3];
+	configinfo.collectinfo[cfgline[0]] = cinfo;
+      }
+    }
+
+    // Read in the value for the site_auth directive either true or false
+    else if (key == "site_auth") configinfo.site_auth = (cfgline[0] == "true");
+
+    else if (key == "site_group")
+       joinchar(cfgline,',',configinfo.site_group);
+       
+    else if (key == "SiteFormat") {
+       if (cfgline[0] == "HomePageType") {
+	  configinfo.HomePageType = cfgline[1];
+       } else if (cfgline[0] == "HomePageCols") {
+	  configinfo.HomePageCols = cfgline[1].getint();
+       }
+    }
+       
+    else if (key == "cgiarg") {
+      // get shortname
+      bool seen_defaultstatus = false;
+      text_t subkey, subvalue;
+      text_t shortname;
+      text_t::const_iterator cfglinesub_here;
+      text_tarray::const_iterator cfgline_here = cfgline.begin();
+      text_tarray::const_iterator cfgline_end = cfgline.end();
+      while (cfgline_here != cfgline_end) {
+	cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
+					(*cfgline_here).end(), '=', subkey);
+	if (subkey == "shortname") {
+	  shortname = substr (cfglinesub_here, (*cfgline_here).end());
+	}
+	++cfgline_here;
+      }
+
+      // if we found the shortname process the line again filling in values
+      if (!shortname.empty()) {
+	cgiarginfo &chinfo = argsinfo[shortname];
+	chinfo.shortname = shortname; // in case this is a new argument
+	
+	cfgline_here = cfgline.begin();
+	while (cfgline_here != cfgline_end) {
+	  cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
+					  (*cfgline_here).end(), '=', subkey);
+	  subvalue = substr (cfglinesub_here, (*cfgline_here).end());
+
+	  if (subkey == "longname") chinfo.longname = subvalue;
+	  else if (subkey == "multiplechar") chinfo.multiplechar = (subvalue == "true");
+	  else if (subkey == "defaultstatus") {
+	    seen_defaultstatus = true;
+	    if (subvalue == "none") chinfo.defaultstatus = cgiarginfo::none;
+	    else if (subvalue == "weak") chinfo.defaultstatus = cgiarginfo::weak;
+	    else if (subvalue == "good") chinfo.defaultstatus = cgiarginfo::good;
+	    else if (subvalue == "config") chinfo.defaultstatus = cgiarginfo::config;
+	    else if (subvalue == "imperative") chinfo.defaultstatus = cgiarginfo::imperative;
+	  }
+	  else if (subkey == "argdefault") {
+	    chinfo.argdefault = subvalue;
+	    if (!seen_defaultstatus) chinfo.defaultstatus = cgiarginfo::config;
+	  }
+	  else if (subkey == "savedarginfo") {
+	    if (subvalue == "mustnot") chinfo.savedarginfo = cgiarginfo::mustnot;
+	    else if (subvalue == "can") chinfo.savedarginfo = cgiarginfo::can;
+	    else if (subvalue == "must") chinfo.savedarginfo = cgiarginfo::must;
+	  }
+	  
+	  ++cfgline_here;
+	}
+      }
+
+    } else if (key == "Encoding") {
+
+      configure_encoding (cfgline);
+
+    } else if (key == "Language") {
+      text_t subkey, subvalue, shortname;
+      languageinfo_t lang;
+      text_t::const_iterator cfglinesub_here;
+      text_tarray::const_iterator cfgline_here = cfgline.begin();
+      text_tarray::const_iterator cfgline_end = cfgline.end();
+      while (cfgline_here != cfgline_end) {
+	cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
+					(*cfgline_here).end(), '=', subkey);
+	if (subkey == "shortname") {
+	  shortname = substr (cfglinesub_here, (*cfgline_here).end());
+	} else if (subkey == "longname") {
+	  lang.longname = substr (cfglinesub_here, (*cfgline_here).end());
+	} else if (subkey == "default_encoding") {
+	  lang.defaultencoding = substr (cfglinesub_here, (*cfgline_here).end());
+	}
+	++cfgline_here;
+      }
+      if (!shortname.empty()) {
+	if (lang.longname.empty()) lang.longname = shortname;
+	configinfo.languages[shortname] = lang;
+      }
+    }
+  }
+  
+  // configure the actions
+  actionptrmap::iterator actionhere = actions.begin ();
+  actionptrmap::iterator actionend = actions.end ();
+
+  while (actionhere != actionend) {
+    assert ((*actionhere).second.a != NULL);
+    if ((*actionhere).second.a != NULL) 
+      (*actionhere).second.a->configure(key, cfgline);
+
+    ++actionhere;
+  }
+
+  // configure the protocols
+  recptprotolistclass::iterator protohere = protocols.begin ();
+  recptprotolistclass::iterator protoend = protocols.end ();
+
+  while (protohere != protoend) {
+    assert ((*protohere).p != NULL);
+    comerror_t err;
+    if ((*protohere).p != NULL) 
+      (*protohere).p->configure(key, cfgline, err);
+    
+    ++protohere;
+  }
+
+  // configure the browsers
+  browserptrmap::iterator browserhere = browsers.begin ();
+  browserptrmap::iterator browserend = browsers.end ();
+
+  while (browserhere != browserend) {
+    assert ((*browserhere).second.b != NULL);
+    if ((*browserhere).second.b != NULL) 
+      (*browserhere).second.b->configure(key, cfgline);
+    
+    ++browserhere;
+  }
+}
+
+
+void receptionist::configure (const text_t &key, const text_t &value) {
+  text_tarray cfgline;
+  cfgline.push_back (value);
+  configure(key, cfgline);
+}
+
+
+// init should be called after all the actions and protocols have been
+// added to the receptionist and after everything has been configured but
+// before any pages are created.  It returns true on success and false on
+// failure. If false is returned getpage should not be called (without
+// producing meaningless output), instead an error page should be produced
+// by the calling code.
+bool receptionist::init (ostream &logout) {
+
+  // first configure collectdir
+  if (!configinfo.collection.empty()) {
+
+    // collection specific mode
+
+    text_t collectdir = configinfo.gsdlhome;
+
+    if (!configinfo.collectdir.empty()) {
+      // has already been configured
+      collectdir = configinfo.collectdir;
+    } else {
+
+      // decide where collectdir is by searching for collect.cfg
+      // look in $GSDLHOME/collect/collection-name/etc/collect.cfg and
+      // then $GSDLHOME/etc/collect.cfg
+      collectdir = filename_cat (configinfo.gsdlhome, "collect");
+      collectdir = filename_cat (collectdir, configinfo.collection);
+      text_t filename = filename_cat (collectdir, "etc");
+      filename = filename_cat (filename, "collect.cfg");
+      
+      if (!file_exists(filename)) collectdir = configinfo.gsdlhome;
+    }
+
+    configure("collectdir", collectdir);
+
+  }
+  else {
+
+    text_t collecthome;
+    if (configinfo.collecthome.empty()) {
+      collecthome = filename_cat(configinfo.gsdlhome,"collect");
+    }
+    else {
+      collecthome = configinfo.collecthome;
+    }
+
+    configure("collecthome", collecthome);
+
+    // for backwards compatability collectdir set to gsdlhome
+    // (possible it could now be removed)
+    configure("collectdir", configinfo.gsdlhome); 
+  } 
+
+
+  // read in the macro files
+  if (!read_macrofiles (logout)) return false;
+
+  // there must be at least one action defined
+  if (actions.empty()) {
+    logout << "Error: no actions have been added to the receptionist\n";
+    return false;
+  }
+
+  // there must be at least one browser defined
+  if (browsers.empty()) {
+    logout << "Error: no browsers have been added to the receptionist\n";
+    return false;
+  }
+
+  // create a saveconf string if there isn't one already
+  if (configinfo.saveconf.empty())
+    configinfo.saveconf = create_save_conf_str (argsinfo, logout);
+
+  // check the saveconf string
+  if (!check_save_conf_str (configinfo.saveconf, argsinfo, logout))
+    return false;
+
+  // set a random seed
+  srand (time(NULL));
+
+  // if maintainer email address is something dodgy (for now I'll define
+  // dodgy as being anything that doesn't contain '@') disable EmailEvents
+  // and EmailUserEvents (we don't strictly need to disable EmailUserEvents
+  // in this case but we will as it seems likely that MailServer will also
+  // be screwed up if maintainer is).
+  text_t::const_iterator maintainer_end = configinfo.maintainer.end ();
+  text_t::const_iterator maintainer_here = findchar ((text_t::const_iterator)configinfo.maintainer.begin(),
+						     maintainer_end, '@');
+  if (maintainer_here == maintainer_end) {
+    configinfo.EmailEvents = Disabled;
+    configinfo.EmailUserEvents = Disabled;
+  } else {
+    // if MailServer isn't set it should default to mail.maintainer-domain
+    if (configinfo.MailServer.empty()) {
+      configinfo.MailServer = "mail." + substr (maintainer_here+1, maintainer_end);
+    }
+  }
+
+  // init the actions
+  actionptrmap::iterator actionhere = actions.begin ();
+  actionptrmap::iterator actionend = actions.end ();
+  while (actionhere != actionend) {
+    if (((*actionhere).second.a == NULL) || 
+	!(*actionhere).second.a->init(logout)) return false;
+    ++actionhere;
+  }
+
+  // init the protocols
+  recptprotolistclass::iterator protohere = protocols.begin ();
+  recptprotolistclass::iterator protoend = protocols.end ();
+  while (protohere != protoend) {
+    comerror_t err;    
+    if (((*protohere).p == NULL) ||
+	!(*protohere).p->init(err, logout)) return false;
+    ++protohere;
+  }
+
+  // init the browsers
+  browserptrmap::iterator browserhere = browsers.begin ();
+  browserptrmap::iterator browserend = browsers.end ();
+  while (browserhere != browserend) {
+    if (((*browserhere).second.b == NULL) || 
+	!(*browserhere).second.b->init(logout)) return false;
+    ++browserhere;
+  }
+
+  return true;
+}
+
+// get the default encoding for the given language - if it fails for any
+// reason return ""
+text_t receptionist::get_default_encoding (const text_t &language) {
+  
+  // make sure language is valid
+  if (configinfo.languages.find(language) == configinfo.languages.end()) return "";
+
+  text_t default_encoding = configinfo.languages[language].defaultencoding;
+
+  // make sure the encoding is valid
+  if (converters.find(default_encoding) == converters.end()) {
+    // we don't support the encoding specified as default for this language
+    if (configinfo.encodings.size()==1) {
+      // only 1 encoding specified in main.cfg, so use it
+      return configinfo.encodings.begin()->second;
+    }
+    return "";
+  }
+
+  return default_encoding;
+}
+
+// parse_cgi_args parses cgi arguments into an argument class.
+// This function should be called for each page request. It returns false
+// if there was a major problem with the cgi arguments.
+bool receptionist::parse_cgi_args (const text_t &argstr, 
+				   fileupload_tmap &fileuploads, 
+				   cgiargsclass &args, 
+				   ostream &logout, text_tmap &fcgienv) {
+
+  // get an initial list of cgi arguments
+  args.clear();
+  split_cgi_args (argsinfo, argstr, args);
+
+  // expand the compressed argument (if there was one)
+  if (!expand_save_args (argsinfo, configinfo.saveconf, args, logout)) return false;
+
+  // add the defaults
+  add_default_args (argsinfo, args, logout);
+
+  // add any file upload arguments
+  add_fileupload_args(argsinfo, args, fileuploads, logout);
+
+  // get the cookie
+  if (configinfo.usecookies) get_cookie(args["z"], fcgienv);
+  
+  // if we're changing languages, set the encoding to the default for the new language
+  if (args["nl"] == "1") {
+    args["nw"] = get_default_encoding(args["l"]);
+  }
+
+  // get the input encoding
+  // if encoding isn't set, set it to the default for the current language
+  if ((args.getarg("w") == NULL) || args["w"].empty()) {
+    args["w"] = get_default_encoding(args["l"]);
+  }
+
+  text_t &arg_w = args["w"];
+
+  inconvertclass defaultinconvert;
+  inconvertclass *inconvert = converters.get_inconverter (arg_w);
+  if (inconvert == NULL) inconvert = &defaultinconvert;
+
+  // see if the next page will have a different encoding
+  if (args.getarg("nw") != NULL) arg_w = args["nw"];
+
+  // convert arguments which aren't in unicode to unicode
+  args_tounicode (args, *inconvert);
+
+
+  // decide on the output conversion class (needed for checking the external
+  // cgi arguments)
+  rzwsoutconvertclass defaultoutconverter;
+  rzwsoutconvertclass *outconverter = converters.get_outconverter (arg_w);
+  if (outconverter == NULL) outconverter = &defaultoutconverter;
+  outconverter->reset();
+
+  // check the main cgi arguments
+  if (!check_mainargs (args, logout)) return false;
+
+  // check the arguments for the action
+  action *a = actions.getaction (args["a"]);
+  if (a != NULL) {
+    if (!a->check_cgiargs (argsinfo, args, &protocols, logout)) return false;
+  } else {
+    // the action was not found!!
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii << "Error: the action \"" << args["a"] 
+	   << "\" could not be found.\n";
+    return false;
+  }
+
+  // check external cgi arguments for each action
+  actionptrmap::iterator actionhere = actions.begin ();
+  actionptrmap::iterator actionend = actions.end ();
+  while (actionhere != actionend) {
+    assert ((*actionhere).second.a != NULL);
+    if ((*actionhere).second.a != NULL) {
+      if (!(*actionhere).second.a->check_external_cgiargs (argsinfo, args, *outconverter,
+							   configinfo.saveconf, logout))
+	return false;
+    }
+    ++actionhere;
+  }
+
+  // the action might have changed but we will assume that
+  // the cgiargs were checked properly when the change was made
+
+  return true;
+}
+
+// returns true if cookie already existed, false
+// if it was generated
+bool receptionist::get_cookie (text_t &cookie, text_tmap &fcgienv) {
+
+  text_t cookiestring = gsdl_getenv ("HTTP_COOKIE", fcgienv);
+
+  text_t::const_iterator end = cookiestring.end();  
+  text_t::const_iterator here = findchar ((text_t::const_iterator)cookiestring.begin(), end, 'G');
+
+  while (here+9 < end) { 
+    
+    if (substr(here, here+8) == "GSDL_UID") {
+      cookie = substr (here+9, findchar (here+9, end, ';')); 
+      return true;
+    }
+    ++here;
+    here = findchar (here, end, 'G');
+  }
+
+  cookie.clear();
+  text_t host = gsdl_getenv("REMOTE_ADDR", fcgienv);
+  time_t ttime = time(NULL);
+  if (!host.empty()) {
+    cookie += host;
+    cookie.push_back ('-');
+  }
+  cookie += text_t(ttime);
+  
+  return false;
+}
+
+// as above but just tests if cookie exists
+bool receptionist::get_cookie (text_tmap &fcgienv) {
+
+  text_t c = gsdl_getenv("HTTP_COOKIE", fcgienv);
+  if (!c.empty()) {
+    text_t cookiestring = c;
+    
+    text_t::const_iterator end = cookiestring.end();  
+    text_t::const_iterator here = findchar ((text_t::const_iterator)cookiestring.begin(), end, 'G');
+
+    while (here+9 < end) { 
+      if (substr(here, here+8) == "GSDL_UID") return true;
+      ++here;
+      here = findchar (here, end, 'G');
+    }
+  }
+  return false;
+}
+
+bool receptionist::log_cgi_args (cgiargsclass &args, ostream &logout, text_tmap &fcgienv) {
+
+  // see if we want to log the cgi arguments
+  if (!configinfo.logcgiargs) return true;
+  
+  text_t host = gsdl_getenv ("REMOTE_HOST", fcgienv);
+  text_t script_name = gsdl_getenv ("SCRIPT_NAME", fcgienv);
+  if (host.empty()) host = gsdl_getenv ("REMOTE_ADDR", fcgienv);
+  text_t browser = gsdl_getenv ("HTTP_USER_AGENT", fcgienv);
+
+  cgiargsclass::const_iterator args_here = args.begin();
+  cgiargsclass::const_iterator args_end = args.end();
+
+  text_t argstr;
+  bool first = true;
+  while (args_here != args_end) {
+    if (!first) argstr += ", ";
+    argstr += (*args_here).first + "=" + (*args_here).second.value;
+    first = false;
+    ++args_here;
+  }
+
+  text_t logfile = filename_cat (configinfo.dbhome, "etc", "usage.txt");
+
+  text_t logstr = script_name;
+  logstr += " " + host;
+  logstr += " [";
+  if (configinfo.LogDateFormat == UTCTime) {
+    logstr += get_date (false);
+  } else if (configinfo.LogDateFormat == Absolute) {
+    time_t ttime = time(NULL);
+    logstr += ttime;
+  } else {
+    // LocalTime
+    logstr += get_date (true);
+  }
+  logstr += "] (" + argstr + ") \"";
+  logstr += browser;
+  logstr += "\"\n";
+
+  return append_logstr (logfile, logstr, logout);
+}
+
+bool receptionist::append_logstr (const text_t &filename, const text_t &logstr,
+				  ostream &logout) {
+
+  utf8outconvertclass text_t2utf8;
+  char *lfile = filename.getcstr();
+
+  int fd = open(lfile, O_WRONLY | O_APPEND);
+  
+  if (fd == -1) {
+    logout << "Error: Couldn't open file " << lfile << "\n";
+    delete []lfile;
+    return false;
+  }
+
+  // lock_val is set to 0 if file is locked successfully
+  int lock_val = 1;
+  GSDL_LOCK_FILE (fd);
+  if (lock_val == 0) {
+    text_t tmp_log_str(logstr); // so we don't pass a const to setinput...
+    text_t2utf8.setinput(&tmp_log_str);
+    char *buffer=new char[logstr.size()];
+    size_t num_chars;
+    convertclass::status_t status;
+    text_t2utf8.convert(buffer, logstr.size(), num_chars, status);
+    // ignore status - assume it is "finished" as buffer is big enough
+    write(fd, buffer, num_chars);
+    GSDL_UNLOCK_FILE (fd);
+    delete []buffer;
+  } else {
+    logout << "Error: Couldn't lock file " << lfile << "\n";
+    close(fd);
+    delete []lfile;
+    return false;
+  }
+
+  close(fd);
+		
+  delete []lfile;
+  return true;
+}
+
+text_t receptionist::expandmacros (const text_t &astring, cgiargsclass &args, 
+				   ostream &logout) {
+  text_t outstring;
+  outconvertclass text_t2ascii;
+
+  action *a = actions.getaction (args["a"]);
+  prepare_page (a, args, text_t2ascii, logout);
+  disp.expandstring (displayclass::defaultpackage, astring, outstring);
+  return outstring;
+}
+
+// produce_cgi_page will call get_cgihead_info and 
+// produce_content in the appropriate way to output a cgi header and
+// the page content (if needed). If a page could not be created it
+// will return false
+bool receptionist::produce_cgi_page (cgiargsclass &args, ostream &contentout, 
+				     ostream &logout, text_tmap &fcgienv) {
+  outconvertclass text_t2ascii;
+
+  response_t response;
+  text_t response_data;
+
+  // produce cgi header
+  get_cgihead_info (args, response, response_data, logout, fcgienv);
+  if (response == location) {
+    // location response (url may contain macros!!)
+    response_data = expandmacros (response_data, args, logout);
+    contentout << text_t2ascii << "Location: " << response_data << "\n\n";
+    contentout << flush;
+    return true;
+  } else if (response == content) {
+    // content response
+
+#ifdef GSDL_NOCACHE
+    contentout << "Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"; // date in the past
+    tm *tm_ptr = NULL;
+    time_t t = time(NULL);
+    tm_ptr = gmtime (&t);
+    if (tm_ptr != NULL) {
+      char *timestr = new char[128];
+      strftime (timestr, 128, "%a, %d %b %Y %H:%M:%S", tm_ptr);
+      contentout << "Last-Modified: " << timestr << " GMT\n"; // always modified
+      delete []timestr;
+    }
+    contentout << "Cache-Control: no-cache, must-revalidate\n"; // HTTP/1.1
+    contentout << "Pragma: no-cache\n"; // HTTP/1.0
+
+#else
+
+    // use the later of build.cfg and collect.cfg modification times
+    // as the Last-Modified: header, for caching values
+    struct stat file_info;
+    time_t latest=0;
+
+    text_t collectname="";
+    collectname=args["c"];
+    if (collectname != "") {
+
+      text_t collecthome;
+      if (!configinfo.collecthome.empty()) {
+	collecthome = configinfo.collecthome;
+      }    
+      else {
+	collecthome=filename_cat(configinfo.gsdlhome,"collect");
+      }
+      text_t collectdir=filename_cat(collecthome,collectname);
+      
+      text_t buildcfg=filename_cat(collectdir,"index");
+      buildcfg=filename_cat(buildcfg,"build.cfg");
+      char *buildcfg_ptr=buildcfg.getcstr();
+      text_t collectcfg=filename_cat(collectdir,"etc");
+      collectcfg=filename_cat(collectcfg,"collect.cfg");
+      char *collectcfg_ptr=collectcfg.getcstr();
+
+      if (stat(buildcfg_ptr, &file_info)) {
+	// we got an error. Currently don't handle error :(
+	//	logout << 
+      } else {
+	latest=file_info.st_mtime;
+      }
+    
+      if (stat(collectcfg_ptr, &file_info)) {
+	// error - unhandled for now
+      } else {
+	if (latest<file_info.st_mtime) latest=file_info.st_mtime;
+      }
+      delete []buildcfg_ptr;
+      delete []collectcfg_ptr;
+
+      if (latest>0) {
+	// print out modified time, "DDD, dd MMM YYYY hh:mm:ss" format
+	// c library takes care of mem for this string... (has \n at end!!!!)
+	// latest is currently local time, convert to UTC.
+	struct tm* utc_latest;
+	utc_latest=gmtime(&latest);
+	contentout << "Last-Modified: " << asctime(utc_latest);
+      }
+    } // end of collection != ""
+
+#endif
+
+    contentout << text_t2ascii << "Content-type: " << response_data << "\n\n";
+  }
+  else if (response == undecided_location) {
+    // Wait until later to output the target location
+    // Used for the "I'm feeling lucky" functionality
+  }
+  else {
+    // unknown response
+    logout << "Error: get_cgihead_info returned an unknown response type.\n";
+    return false;
+  }
+
+  // produce cgi page
+  if (!produce_content (args, contentout, logout)) return false;
+
+  // flush contentout
+  contentout << flush;
+  return true;
+}
+
+
+// get_cgihead_info determines the cgi header information for
+// a set of cgi arguments. If response contains location then
+// response_data contains the redirect address. If reponse
+// contains content then reponse_data contains the content-type.
+// Note that images can now be produced by the receptionist.
+// Note also, alternative for get_cgihead_info below which
+// stores the information in a text_tmap so it is more easily digested
+
+void receptionist::get_cgihead_info (cgiargsclass &args, response_t &response,
+				     text_t &response_data, ostream &logout, 
+				     text_tmap &fcgienv) {
+  outconvertclass text_t2ascii;
+
+  // get the action
+  action *a = actions.getaction (args["a"]);
+  if (a != NULL) {
+    a->get_cgihead_info (args, &protocols, response, response_data, logout);
+
+  } else {
+    // the action was not found!!
+    logout << text_t2ascii << "Error receptionist::get_cgihead_info: the action \"" 
+	   << args["a"] << "\" could not be found.\n";
+    response = content;
+    response_data = "text/html";
+  }
+
+  // add the encoding information
+  if (response == content) {
+    if (converters.find(args["w"]) != converters.end()) {
+      response_data += "; charset=" + args["w"];
+    } else {
+      // default to latin 1
+      response_data += "; charset=ISO-8859-1";
+    }
+
+    // add cookie if required
+    if (configinfo.usecookies && !get_cookie(fcgienv))
+      response_data += "\nSet-Cookie: GSDL_UID=" + args["z"]
+	+ "; expires=25-Dec-37 00:00:00 GMT";
+  }
+}
+
+
+// Alternative version of get_cgihead_info, stores fielded infomation
+// in text_tmap rather than concatenated string
+void receptionist::get_cgihead_info (cgiargsclass &args, text_tmap &headers,
+				     ostream &logout, text_tmap &fcgienv) {
+
+  response_t response;
+  text_t response_data;
+
+  // get the action
+  action *a = actions.getaction (args["a"]);
+  if (a != NULL) {
+    a->get_cgihead_info (args, &protocols, response, response_data, logout);
+
+  } else {
+    // the action was not found!!
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii << "Error receptionist::get_cgihead_info: the action \"" 
+	   << args["a"] << "\" could not be found.\n";
+    response = content;
+    response_data = "text/html";
+  }
+
+  if (response == location) {
+    response_data = expandmacros(response_data, args, logout);
+    headers["Location"] = response_data;
+    return;
+  }
+
+  // add the encoding information
+  if (response == content) {
+
+    if (converters.find(args["w"]) != converters.end()) {
+      headers["content-encoding"] = args["w"];
+      response_data += "; charset=" + args["w"];
+    } else {
+      // default to utf-8
+      headers["content-encoding"] = "utf-8";
+      response_data += "; charset=utf-8";
+    }
+
+    headers["content-type"] = response_data;
+
+  }
+
+}
+
+
+
+// produce the page content
+bool receptionist::produce_content (cgiargsclass &args, ostream &contentout,
+				    ostream &logout) {
+
+  // decide on the output conversion class
+  text_t &arg_w = args["w"];
+  rzwsoutconvertclass defaultoutconverter;
+  rzwsoutconvertclass *outconverter = converters.get_outconverter (arg_w);
+  if (outconverter == NULL) outconverter = &defaultoutconverter;
+  outconverter->reset();
+
+  // needed for 16-bit unicode only - big endian marker 0xfeff (RFC 2781)
+  if (arg_w=="utf-16be") {
+    contentout << '\xfe' << '\xff' ;
+  }
+
+  recptproto *collectproto = protocols.getrecptproto (args["c"], logout);
+  if (collectproto != NULL) {
+    // get browsers to process OID
+    text_t OID = args["d"];
+    if (OID.empty()) OID = args["cl"];
+    if (!OID.empty()) {
+      text_tset metadata;
+      text_tarray OIDs;
+      OIDs.push_back (OID);
+      if (!is_top(OID)) OIDs.push_back (OID + ".pr");
+      FilterResponse_t response;
+      metadata.insert ("childtype");
+      if (get_info (OIDs, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
+	text_t classifytype;
+	if (!response.docInfo[0].metadata["childtype"].values[0].empty())
+	  classifytype = response.docInfo[0].metadata["childtype"].values[0];
+	else if (!is_top (OID)) {
+	  // not sure why this is occasionally not set, but it will
+	  // cause a segfault... possibly if built with no_text? jrm21
+	  if (response.docInfo[1].metadata.find("childtype")
+	      == response.docInfo[1].metadata.end()) {
+	    cerr << "receptionist: no childtype element in metadata map!"
+		 << endl;
+	  } else {
+	    if (!response.docInfo[1].metadata["childtype"].values[0].empty())
+	      classifytype = response.docInfo[1].metadata["childtype"].values[0];
+	  }
+	}
+	browserclass *b = browsers.getbrowser (classifytype);
+	b->processOID (args, collectproto, logout);
+      }
+    }
+  
+    // translate "d" and "cl" arguments if required
+    translate_OIDs (args, collectproto, logout);
+  }
+  
+  // produce the page using the desired action
+  action *a = actions.getaction (args["a"]);
+  if (a != NULL) {
+    if (a->uses_display(args)) prepare_page (a, args, (*outconverter), logout);
+    if (!a->do_action (args, &protocols, &browsers, disp, (*outconverter), contentout, logout))
+      return false;
+  } else {
+    // the action was not found!!
+    outconvertclass text_t2ascii;
+
+    logout << text_t2ascii << "Error receptionist::produce_content: the action \"" 
+	   << args["a"] << "\" could not be found.\n";
+    
+    contentout << (*outconverter) 
+	       << "<html>\n"
+	       << "<head>\n"
+	       << "<title>Error</title>\n"
+	       << "</head>\n"
+	       << "<body>\n"
+	       << "<h2>Oops!</h2>\n"
+	       << "Undefined Page. The action \"" 
+	       << args["a"] << "\" could not be found.\n"
+	       << "</body>\n"
+	       << "</html>\n";
+  }
+  return true;
+}
+
+
+// returns the compressed argument ("e") corresponding to the argument
+// list. This can be used to save preferences between sessions.
+text_t receptionist::get_compressed_arg (cgiargsclass &args, ostream &logout) {
+  // decide on the output conversion class
+  text_t &arg_w = args["w"];
+  rzwsoutconvertclass defaultoutconverter;
+  rzwsoutconvertclass *outconverter = converters.get_outconverter (arg_w);
+  if (outconverter == NULL) outconverter = &defaultoutconverter;
+  outconverter->reset();
+
+  text_t compressed_args;
+  if (compress_save_args (argsinfo, configinfo.saveconf, args, 
+			  compressed_args, *outconverter, logout))
+    return compressed_args;
+
+  return g_EmptyText;
+}
+
+
+// will read in all the macro files. If one is not found an
+// error message will be written to logout and the method will
+// return false.
+bool receptionist::read_macrofiles (ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  // redirect the error output to logout
+  ostream *savedlogout = disp.setlogout (&logout);
+
+  // unload any macros that were previously loaded - this allows us to call
+  // this function a second time to reload all the macro files (useful for
+  // reading in changed macro files in server versions of greenstone)
+  disp.unloaddefaultmacros();
+
+  // load up the default macro files, the collection directory
+  // is searched first for the file (if this is being used in
+  // collection specific mode) and then the main directory(s)
+  text_t colmacrodir = filename_cat (configinfo.collectdir, "macros");
+
+  text_tset maindirs;
+  text_t gsdlmacrodir = filename_cat (configinfo.gsdlhome, "macros");
+  maindirs.insert (gsdlmacrodir);
+  colinfo_tmap::iterator colhere = configinfo.collectinfo.begin();
+  colinfo_tmap::iterator colend = configinfo.collectinfo.end();
+  while (colhere != colend) {
+    if (!((*colhere).second.gsdl_gsdlhome).empty()) {
+      gsdlmacrodir = filename_cat ((*colhere).second.gsdl_gsdlhome, "macros");
+      maindirs.insert (gsdlmacrodir);
+    }
+    ++colhere;
+  }
+
+  text_tset::iterator arrhere = configinfo.macrofiles.begin();
+  text_tset::iterator arrend = configinfo.macrofiles.end();
+  text_t filename;
+  while (arrhere != arrend) {
+    bool foundfile = false;
+
+    // try in the collection directory if this is being
+    // run in collection specific mode
+    if (!configinfo.collection.empty()) {
+      filename = filename_cat (colmacrodir, *arrhere);
+      if (file_exists (filename)) {
+	disp.loaddefaultmacros(filename);
+	foundfile = true;
+      }
+    }
+
+    // if we haven't found the macro file yet try in
+    // the main macro directory(s)
+    // if file is found in more than one main directory
+    // we'll load all copies
+    if (!foundfile) {
+      text_tset::const_iterator dirhere = maindirs.begin();
+      text_tset::const_iterator dirend = maindirs.end();
+      while (dirhere != dirend) {
+	filename = filename_cat (*dirhere, *arrhere);
+	if (file_exists (filename)) {
+	  disp.loaddefaultmacros(filename);
+	  foundfile = true;
+	}
+	++dirhere;
+      }
+    }
+
+    // see if we found the file or not
+    if (!foundfile) {
+      logout << text_t2ascii 
+	     << "Error: the macro file \"" << *arrhere << "\" could not be found.\n";
+      if (configinfo.collection.empty()) {
+	text_t dirs;
+	joinchar (maindirs, ", ", dirs);
+	logout << text_t2ascii 
+	       << "It should be in either of the following directories ("
+	       << dirs << ").\n\n";
+
+      } else {
+	logout << text_t2ascii
+	       << "It should be in either " << colmacrodir << " or in " 
+	       << gsdlmacrodir << ".\n\n";
+      }
+      // don't crap out if a macro file is missing
+      //disp.setlogout (savedlogout);
+      //return false;
+    }
+    ++arrhere;
+  }
+
+  // success
+
+  // reset logout to what it was
+  disp.setlogout (savedlogout);
+  return true;
+}
+
+
+
+
+// Go through the list of macro files looking to see
+// if any exist in the collectoin specific area.  If they
+// do then read them in and add them to the set of existing
+// current macros
+
+void receptionist::read_collection_macrofiles (const text_t& collection, ostream &logout) 
+{
+  outconvertclass text_t2ascii;
+
+  // disp.unloadcollectionmacros();
+
+  // redirect the error output to logout
+  ostream *savedlogout = disp.setlogout (&logout);
+
+  text_t colmacrodir 
+    = filename_cat (configinfo.collecthome,collection, "macros");
+
+  if (directory_exists (colmacrodir)) {
+
+    text_tset::iterator arrhere = configinfo.macrofiles.begin();
+    text_tset::iterator arrend = configinfo.macrofiles.end();
+    text_t filename;
+    while (arrhere != arrend) {
+
+      filename = filename_cat (colmacrodir, *arrhere);
+      if (file_exists (filename)) {
+	disp.loadcollectionmacros(filename);
+      }
+      
+      ++arrhere;
+    }
+  }
+
+  // reset logout to what it was
+  disp.setlogout (savedlogout);
+}
+
+
+
+
+// check_mainargs will check all the main arguments. If a major
+// error is found it will return false and no cgi page should
+// be created using the arguments.
+
+bool receptionist::check_mainargs (cgiargsclass &args, ostream &logout) {
+   
+   if(configinfo.site_auth)
+      {
+	 args["uan"] = "1";
+	 args["ug"] = configinfo.site_group;
+      }
+   
+   
+   // if this receptionist is running in collection dependant mode
+   // then it should always set the collection argument to the
+   // collection
+   if (!configinfo.collection.empty()) args["c"] = configinfo.collection;
+   
+   // if current collection uses ccscols make sure
+   // "ccs" argument is set and make "cc" default to
+   // all collections in "ccs"
+   if (args["a"] != "config" && !args["c"].empty()) {
+      
+      text_t &arg_c = args["c"];
+      recptproto *collectproto = protocols.getrecptproto (arg_c, logout);
+      if (collectproto == NULL) {
+	 // oops, this collection isn't valid
+	 outconvertclass text_t2ascii;
+	 logout << text_t2ascii << "ERROR: Invalid collection: " << arg_c << "\n";
+	 // args["c"].clear();
+	 
+      } else {
+	 
+	 ColInfoResponse_t *cinfo = get_collectinfo_ptr (collectproto, arg_c, logout);
+	 
+	 if(cinfo->authenticate == "collection")
+	    {
+	       args["uan"] = "1";
+	       args["ug"] = cinfo->auth_group;
+	    }
+	 
+	 
+      if (cinfo != NULL) {
+	 if (!cinfo->ccsCols.empty()) {
+	    args["ccs"] = 1;
+	    if (args["cc"].empty()) {
+	       text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
+	       text_tarray::const_iterator col_end = cinfo->ccsCols.end();
+	       bool first = true;
+	       while (col_here != col_end) {
+		  // make sure it's a valid collection
+		  if (protocols.getrecptproto (*col_here, logout) != NULL) {
+		     if (!first) args["cc"].push_back (',');
+		     args["cc"] += *col_here;
+		     first = false;
+		  }
+	      ++col_here;
+	    }
+	  }
+	}
+      } else {
+	logout << "ERROR (receptionist::check_mainargs): get_collectinfo_ptr returned NULL\n";
+      }
+    }
+  }
+
+  // argument "v" can only be 0 or 1. Use the default value
+  // if it is out of range
+  int arg_v = args.getintarg ("v");
+  if (arg_v != 0 && arg_v != 1) {
+    cgiarginfo *vinfo = argsinfo.getarginfo ("v");
+    if (vinfo != NULL) args["v"] = vinfo->argdefault;
+  }
+
+  // argument "f" can only be 0 or 1. Use the default value
+  // if it is out of range
+  int arg_f = args.getintarg ("f");
+  if (arg_f != 0 && arg_f != 1) {
+    cgiarginfo *finfo = argsinfo.getarginfo ("f");
+    if (finfo != NULL) args["f"] = finfo->argdefault;
+  }
+
+  return true;
+}
+
+// translate_OIDs translates the "d" and "cl" arguments to their correct values
+// if they use the tricky ".fc", ".lc" type syntax.
+void receptionist::translate_OIDs (cgiargsclass &args, recptproto *collectproto, 
+				   ostream &logout) {
+
+  FilterResponse_t response;
+  FilterRequest_t request;
+  comerror_t err;
+  text_t &arg_d = args["d"];
+  text_t &arg_cl = args["cl"];
+  text_t &collection = args["c"];
+  
+  // do a call to translate OIDs if required
+  request.filterName = "NullFilter";
+  request.filterResultOptions = FROID;
+  if (!arg_d.empty() && needs_translating (arg_d)) {
+    request.docSet.push_back (arg_d);
+    collectproto->filter (collection, request, response, err, logout);
+    arg_d = response.docInfo[0].OID;
+    request.clear();
+  }
+  // we'll also check here that the "cl" argument has a "classify" doctype 
+  // (in case ".fc" or ".lc" have screwed up)
+  if (needs_translating (arg_cl)) {
+    request.fields.insert ("doctype");
+    request.docSet.push_back (arg_cl);
+    request.filterResultOptions = FRmetadata;
+    collectproto->filter (collection, request, response, err, logout);
+    // set to original value (without .xx stuff) if doctype isn't "classify"
+    if (response.docInfo[0].metadata["doctype"].values[0] != "classify")
+      strip_suffix (arg_cl);
+    else
+      arg_cl = response.docInfo[0].OID;
+  }
+}
+
+// prepare_page sets up page parameters, sets display macros
+// and opens the page ready for output 
+void receptionist::prepare_page (action *a, cgiargsclass &args, 
+				 outconvertclass &outconvert, 
+				 ostream &logout) {
+  // set up page parameters
+  text_t pageparams;
+  bool first = true;
+
+  text_tmap::iterator params_here = configinfo.pageparams.begin();
+  text_tmap::iterator params_end = configinfo.pageparams.end();
+  while (params_here != params_end) {
+    // page params are those from main.cfg (eg pageparam v 0) plus
+    // two defaults set in recptconf.clear() (c="" and l=en)
+    // This used to check if the current value of the page param
+    // == the default value, then don't add in it the list
+    // but if l=en, and there is a macro with [l=en], then it doesn't
+    // find it.
+    // so now all page params will go into the list. I assume this will 
+    // mean more attempts to find each macro, but nothing worsee than 
+    // that.  --kjdon
+    //if (args[(*params_here).first] != (*params_here).second) {
+      if (first)
+	first = false;
+      else
+	pageparams += ",";
+
+      pageparams += (*params_here).first;
+      pageparams += "=";
+      pageparams += args[(*params_here).first];
+      // }
+    
+    ++params_here;
+  }
+  
+
+  // open the page
+  disp.openpage(pageparams, configinfo.macroprecedence);
+
+  disp.unloadcollectionmacros();
+
+  text_t collection = args["c"];
+  if (!collection.empty()) {
+    read_collection_macrofiles(collection,logout);
+  }
+
+  // define external macros for each action
+  actionptrmap::iterator actionhere = actions.begin ();
+  actionptrmap::iterator actionend = actions.end ();
+
+  while (actionhere != actionend) {
+    assert ((*actionhere).second.a != NULL);
+    if ((*actionhere).second.a != NULL) {
+      (*actionhere).second.a->define_external_macros (disp, args, &protocols, logout);
+    }
+    ++actionhere;
+  }
+
+
+  // define internal macros for the current action
+  a->define_internal_macros (disp, args, &protocols, logout);
+  
+  // define general macros. the defining of general macros is done here so that
+  // the last possible version of the cgi arguments are used
+  define_general_macros (args, outconvert, logout);
+}
+
+void receptionist::define_general_macros (cgiargsclass &args, outconvertclass &/*outconvert*/, 
+					  ostream &logout) {
+
+  text_t &collection = args["c"];
+
+  disp.setmacro ("gsdlhome", displayclass::defaultpackage, dm_safe(configinfo.gsdlhome));
+  disp.setmacro ("gwcgi", displayclass::defaultpackage, configinfo.gwcgi);
+  disp.setmacro ("httpimg", displayclass::defaultpackage, configinfo.httpimg);
+  disp.setmacro ("httpprefix", displayclass::defaultpackage, configinfo.httpprefix);
+
+
+  text_t compressedoptions = get_compressed_arg(args, logout);
+  disp.setmacro ("compressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
+  // need a decoded version of compressedoptions for use within forms
+  // as browsers encode values from forms before sending to server
+  // (e.g. %25 becomes %2525)
+  decode_cgi_arg (compressedoptions); 
+  if (args["w"] == "utf-8") { // if the encoding was utf-8, then compressed options was utf-8, and we need unicode.
+    // if encoding wasn't utf-8, then compressed opotions may be screwed up, but seems to work for 8 bit encodings?
+    compressedoptions = to_uni(compressedoptions);
+  }
+  disp.setmacro ("decodedcompressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions)); 
+
+#if defined (__WIN32__)
+  disp.setmacro ("win32", displayclass::defaultpackage, "1");
+#endif
+
+  // set _cgiargX_ macros for each cgi argument
+  cgiargsclass::const_iterator argshere = args.begin();
+  cgiargsclass::const_iterator argsend = args.end();
+  while (argshere != argsend) {
+    if (((*argshere).first == "q") ||
+	((*argshere).first == "qa") ||
+	((*argshere).first == "qtt") ||
+	((*argshere).first == "qty") ||
+	((*argshere).first == "qp") ||
+	((*argshere).first == "qpl") ||
+	((*argshere).first == "qr") ||
+	((*argshere).first == "q2"))
+      // need to escape special characters from query string
+      disp.setmacro ("cgiarg" + (*argshere).first, 
+		     displayclass::defaultpackage, html_safe((*argshere).second.value));
+    else if ((*argshere).first == "hp") {
+      disp.setmacro ("cgiarg" + (*argshere).first, displayclass::defaultpackage, (*argshere).second.value);
+    } else {
+      disp.setmacro ("cgiarg" + (*argshere).first, displayclass::defaultpackage, dm_safe((*argshere).second.value));
+    }
+    ++argshere;
+  }
+
+  // set collection specific macros
+  if (!collection.empty()) {
+    recptproto *collectproto = protocols.getrecptproto (collection, logout);
+    if (collectproto != NULL) {
+      FilterResponse_t response;
+      text_tset metadata;
+      get_info ("collection", collection, args["l"], metadata, false, 
+		collectproto, response, logout);
+      
+      if (!response.docInfo[0].metadata.empty()) {
+	MetadataInfo_tmap::const_iterator here = response.docInfo[0].metadata.begin();
+	MetadataInfo_tmap::const_iterator end = response.docInfo[0].metadata.end();
+	while (here != end) {
+	  if (((*here).first != "haschildren") && ((*here).first != "hasnext") &&
+	      ((*here).first != "hasprevious")) {
+	    // check for args in form name:lang
+	    text_t name = g_EmptyText;
+	    text_t lang = g_EmptyText;
+	    bool colonfound=false;
+	    text_t::const_iterator a = (*here).first.begin();
+	    text_t::const_iterator b = (*here).first.end();
+	    while (a !=b) {
+	      if (*a==':') {
+		colonfound=true;
+	      }
+	      else {
+		if (colonfound)
+		  lang.push_back(*a);
+		else name.push_back(*a);
+	      }
+	      ++a;
+	    }
+	    if (!lang.empty()) {
+	      if (args["l"]==lang) {
+		disp.setcollectionmacro(displayclass::defaultpackage, name, "", (*here).second.values[0]);
+	      }
+	    }
+	    else { // the default one
+	      disp.setcollectionmacro(displayclass::defaultpackage, (*here).first,  "", (*here).second.values[0]);
+	    }
+	  }
+	  ++here;
+	}
+      }
+
+      text_t iconcollection;
+      disp.expandstring (displayclass::defaultpackage, "_iconcollection_", iconcollection);
+      if (!iconcollection.empty())
+	{
+	  ColInfoResponse_t cinfo;
+	  comerror_t err;
+	  collectproto->get_collectinfo (collection, cinfo, err, logout);
+	  if (iconcollection[0]=='/' && !cinfo.httpdomain.empty())
+	    {
+	      // local but with full path
+	      iconcollection = "http://" + cinfo.httpdomain + iconcollection;
+	      disp.setmacro("iconcollection", displayclass::defaultpackage, iconcollection);
+	    }
+	}
+    }
+  }
+
+  if (!collection.empty()) {
+    ColInfoResponse_t cinfo;
+    comerror_t err;
+    recptproto *collectproto = protocols.getrecptproto (collection, logout);
+    if (collectproto != NULL) {
+      collectproto->get_collectinfo (collection, cinfo, err, logout);
+      text_t httpcollection;
+      if (!cinfo.httpdomain.empty()) httpcollection = "http://";
+      httpcollection += cinfo.httpdomain + cinfo.httpprefix + "/collect/"
+	+ collection; 
+      disp.setmacro ("httpcollection", displayclass::defaultpackage,
+		     httpcollection); 
+      // as of gsdl 2.53, collect.cfg can specify macros
+      if (cinfo.collection_macros.size() > 0) {
+	collectionmeta_map::const_iterator this_macro=cinfo.collection_macros.begin();
+	collectionmeta_map::const_iterator done_macro=cinfo.collection_macros.end();
+	while (this_macro != done_macro) {
+	  text_t package = "Global";
+	  text_t macroname = this_macro->first;
+	  // if this macro name is AAA:bbb then extract the package name
+	  text_t::const_iterator thischar, donechar;
+	  thischar = macroname.begin();
+	  donechar = macroname.end();
+	  while (thischar < donechar) {
+	    if (*thischar == ':') {
+	      package = substr(macroname.begin(),thischar);
+	      macroname = substr(thischar+1,donechar);
+	      break;
+	    }
+	    ++thischar;
+	  }
+
+	  text_tmap params_map = this_macro->second;
+	  text_tmap::const_iterator this_param = params_map.begin();
+	  text_tmap::const_iterator done_param = params_map.end();
+	  while (this_param != done_param) {
+	    disp.setcollectionmacro(package,
+				    macroname,
+				    this_param->first,
+				    this_param->second);
+	    ++this_param;
+	  }
+	  
+	  ++this_macro;
+	}
+      } // col macros
+    } // collectproto != NULL
+  }
+
+}
+
+// gets collection info from cache if found or 
+// calls collection server (and updates cache)
+// returns NULL if there's an error
+ColInfoResponse_t *receptionist::get_collectinfo_ptr (recptproto *collectproto, 
+						      const text_t &collection, 
+						      ostream &logout) {
+  
+  // check the cache
+  colinfo_tmap::iterator it = configinfo.collectinfo.find (collection);
+  if ((it != configinfo.collectinfo.end()) && ((*it).second.info_loaded)) {
+    // found it
+    return &((*it).second.info);
+  }
+
+  // not cached, get info from collection server
+  if (collectproto == NULL) {
+    logout << "ERROR: receptionist::get_collectinfo_ptr passed null collectproto\n";
+    return NULL;
+  }
+   
+  comerror_t err;
+  if (it == configinfo.collectinfo.end()) {
+    collectioninfo_t cinfo;
+    collectproto->get_collectinfo (collection, cinfo.info, err, logout);
+    if (err != noError) {
+      outconvertclass text_t2ascii;
+      logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
+	     << get_comerror_string (err) << "\"while getting collectinfo\n";
+      return NULL;
+    }
+    cinfo.info_loaded = true;
+    configinfo.collectinfo[collection] = cinfo;
+    return &(configinfo.collectinfo[collection].info);
+  } else {
+    collectproto->get_collectinfo (collection, (*it).second.info, err, logout);
+    if (err != noError) {
+      outconvertclass text_t2ascii;
+      logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
+	     << get_comerror_string (err) << "\"while getting collectinfo\n";
+      return NULL;
+    }
+    (*it).second.info_loaded = true;
+    return &((*it).second.info);
+  }
+}
+
+// removes a collection from the cache so that the next
+// call to get_collectinfo_ptr() for that collection will
+// retrieve the collection info from the collection server
+void receptionist::uncache_collection (const text_t &collection) {
+
+  colinfo_tmap::iterator it = configinfo.collectinfo.find (collection);
+  if ((it != configinfo.collectinfo.end()) && ((*it).second.info_loaded)) {
+
+    (*it).second.info_loaded = false;
+
+  }
+}
+
+// Handles an "Encoding" line from a configuration file - note that the
+// configinfo.encodings map is a bit of a hack (to be fixed when the
+// configuration files are tidied up).
+void receptionist::configure_encoding (const text_tarray &cfgline) {
+
+  text_t subkey, subvalue, shortname, longname, mapfile;
+  int multibyte = 0;
+  text_t::const_iterator cfglinesub_here;
+  text_tarray::const_iterator cfgline_here = cfgline.begin();
+  text_tarray::const_iterator cfgline_end = cfgline.end();
+  while (cfgline_here != cfgline_end) {
+    if (*cfgline_here == "multibyte") {
+      multibyte = 1;
+    } else {
+      cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
+				      (*cfgline_here).end(), '=', subkey);
+      if (subkey == "shortname") {
+	shortname = substr (cfglinesub_here, (*cfgline_here).end());
+      } else if (subkey == "longname") {
+	longname = substr (cfglinesub_here, (*cfgline_here).end());
+      } else if (subkey == "map") {
+	mapfile = substr (cfglinesub_here, (*cfgline_here).end());
+      }
+    }
+    ++cfgline_here;
+  }
+  if (!shortname.empty()) {
+    if (longname.empty()) longname = shortname;
+
+    // add the converter
+    if (shortname == "utf-8") {
+      utf8inconvertclass *utf8inconvert = new utf8inconvertclass();
+      utf8outconvertclass *utf8outconvert = new utf8outconvertclass();
+      utf8outconvert->set_rzws(1);
+      add_converter (shortname, utf8inconvert, utf8outconvert);
+      configinfo.encodings[longname] = shortname;
+
+    } else if (shortname == "utf-16be") {
+      // we use the default input converter as this shouldn't ever be used
+      // for converting from unicode...
+      inconvertclass *inconverter = new inconvertclass();
+      utf16outconvertclass *outconverter = new utf16outconvertclass();
+      add_converter (shortname, inconverter, outconverter);
+      configinfo.encodings[longname] = shortname;
+	
+    } else if (!mapfile.empty()) {
+
+      if (mapfile == "8859_1.ump") {
+	// iso-8859-1 is a special case as it'll always be supported by the
+	// standard converter class and therefore doesn't need to use its
+	// mapping file
+	inconvertclass *inconvert = new inconvertclass();
+	rzwsoutconvertclass *outconvert = new rzwsoutconvertclass();
+	outconvert->set_rzws(1);
+	add_converter (shortname, inconvert, outconvert);  
+	configinfo.encodings[longname] = shortname;
+
+      } else {
+	text_t to_uc_map = filename_cat(configinfo.gsdlhome, "mappings", "to_uc", mapfile);
+	text_t from_uc_map = filename_cat(configinfo.gsdlhome, "mappings", "from_uc", mapfile);
+	if (file_exists(to_uc_map) && file_exists(from_uc_map)) {
+
+	  mapinconvertclass *mapinconvert = new mapinconvertclass();
+	  mapinconvert->setmapfile (to_uc_map, 0x003F);
+	  mapinconvert->set_multibyte (multibyte);
+	  mapoutconvertclass *mapoutconvert = new mapoutconvertclass();
+	  mapoutconvert->setmapfile (from_uc_map, 0x3F);
+	  mapoutconvert->set_multibyte (multibyte);
+	  mapoutconvert->set_rzws(1);
+	  add_converter (shortname, mapinconvert, mapoutconvert);
+	  configinfo.encodings[longname] = shortname;
+	}
+      }
+    }
+  }
+}
Index: /gsdl/trunk/runtime-src/src/recpt/receptionist.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/receptionist.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/receptionist.h	(revision 16571)
@@ -0,0 +1,284 @@
+/**********************************************************************
+ *
+ * receptionist.h -- a web interface for the gsdl
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef RECEPTIONIST_H
+#define RECEPTIONIST_H
+
+#include "gsdlconf.h"
+#include "text_t.h"
+#include "cgiargs.h"
+#include "display.h"
+#include "browserclass.h"
+#include "recptproto.h"
+#include "converter.h"
+#include "cfgread.h"
+#include "action.h"
+#include "cnfgable.h"
+
+// the MACROPRECEDENCE macro is used as a default. override
+// it using something like:
+//
+// macroprecedence c,l
+//
+// in your configuration file
+#ifndef MACROPRECEDENCE
+#define MACROPRECEDENCE "c,l"
+#endif
+
+
+struct collectioninfo_t {
+  void clear ();
+  collectioninfo_t () {clear();}
+
+  text_t gsdl_gsdlhome;
+  text_t gsdl_collecthome;
+  text_t gsdl_dbhome;
+
+  bool info_loaded;
+  ColInfoResponse_t info;
+};
+
+struct languageinfo_t {
+  void clear();
+  languageinfo_t () {clear();}
+
+  text_t longname;
+  text_t defaultencoding;
+};
+
+typedef map<text_t, collectioninfo_t, lttext_t> colinfo_tmap;
+typedef map<text_t, languageinfo_t, lttext_t> languageinfo_tmap;
+
+enum events_t {Disabled, CollectorEvents, AllEvents};
+enum ldformat_t {LocalTime, UTCTime, Absolute};
+
+struct recptconf {
+   text_t gsdlhome;
+   text_t collecthome;
+   text_t dbhome;   // will equal gsdlhome if not set
+   text_t collection; // will equal "" in 'general' mode
+   text_t collectdir; // will equal gsdlhome in 'general' mode
+   colinfo_tmap collectinfo;
+   text_t httpprefix;
+   text_t httpimg;    // will equal /images if not set
+   text_t gwcgi;
+   text_tset macrofiles;
+   text_t saveconf;
+   bool usecookies;  // true if we want cookies set
+   bool logcgiargs;  // true if we want to log cgi arguments
+   
+   ldformat_t LogDateFormat;
+   
+   text_t maintainer; // email address of maintainer
+   text_t MailServer; // SMTP mail server to use when sending event messages by email
+                     // defaults to mail.maintainer-domain
+   events_t LogEvents;
+   events_t EmailEvents;
+   bool EmailUserEvents;
+
+   bool    site_auth;   // Complete site authentication, useful to lockout site for example.
+   text_t  site_group;  // Similar to the auth_groups functionality, infact exactly the same
+   
+   text_t HomePageType; 
+   int HomePageCols;
+   
+   text_tmap pageparams;
+   text_t macroprecedence;
+   
+   languageinfo_tmap languages;
+   
+   // encodings is just a simple mapping from encoding longnames to
+   // shortnames.  It's useful for now for creating the pulldown menu of
+   // encodings on the preferences page but isn't intended to be permanent.
+   text_tmap encodings;
+   
+   void clear ();
+   recptconf () {clear();}
+};
+
+class receptionist : public configurable {
+protected:
+
+   recptconf configinfo;
+   
+   cgiargsinfoclass argsinfo;
+   actionmapclass actions;
+   browsermapclass browsers;
+   recptprotolistclass protocols;
+   displayclass disp;
+   convertinfoclass converters;
+   ColInfoResponse_t collectinfo;
+   
+   // prepare_page sets up page parameters, sets display macros
+   // and opens the page ready for output 
+   virtual void prepare_page (action *a, cgiargsclass &args, 
+			      outconvertclass &outconvert, 
+			     ostream &logout);
+   
+   virtual void translate_OIDs (cgiargsclass &args, recptproto *collectproto,
+				ostream &logout);
+   
+   bool get_cookie (text_t &cookie, text_tmap &fcgienv);
+   bool get_cookie (text_tmap &fcgienv);
+   
+   // get the default encoding for the given language - if it fails for any
+   // reason, return ""
+   text_t get_default_encoding (const text_t &language);
+   
+   virtual void define_general_macros (cgiargsclass &args, outconvertclass &outconvert, 
+				       ostream &logout);
+   
+   virtual bool append_logstr (const text_t &filename, const text_t &logstr,
+                               ostream &logout);
+
+   virtual void configure_encoding (const text_tarray &cfgline);
+   
+ public:
+   receptionist ();
+   virtual ~receptionist() {}
+
+#ifdef _APACHE_MOD
+   bool loaded;
+#endif   
+   // add_action makes another action available to the receptionist
+   // the action remains the property of the calling code and that
+   // code should destroy the action after the recptionist has been
+   // destroyed.
+   void add_action (action *theaction);
+   actionmapclass *get_actionmap_ptr () {return &actions;}
+   
+   // add_browser makes another browser available to the receptionist
+   // the browser remains the property of the calling code and that
+   // code should destroy it after the recptionist has been
+   // destroyed.
+   void add_browser (browserclass *thebrowser);
+   browsermapclass *get_browsermap_ptr () {return &browsers;}
+   void setdefaultbrowser (const text_t &browsername);
+   
+   // add_protocol makes another protocol available to the receptionist
+   // without any protocols, no collections will be available. The
+   // protocols remain the property of the calling code.
+   void add_protocol (recptproto *theprotocol) {protocols.addrecptproto(theprotocol);}
+   recptprotolistclass *get_recptprotolist_ptr () {return &protocols;}
+   
+   // add_converter makes another converter available to the receptionist.
+   // Converters are needed to display pages using different encodings.
+   // The converters remain the property of the calling code.
+   void add_converter (const text_t &name, inconvertclass *inconverter,
+		       rzwsoutconvertclass *outconverter) {
+      converters.add_converter(name, inconverter, outconverter);}
+   convertinfoclass *get_convertinfo_ptr () {return &converters;}
+   
+   
+   // configure should be called for each line in the
+  // configuration files to configure the receptionist and everything
+  // it contains. The configuration should take place after everything
+  // has been added but before the initialisation.
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+  virtual void configure (const text_t &key, const text_t &value);
+  const recptconf &get_configinfo () const {return configinfo;}
+  cgiargsinfoclass *get_cgiargsinfo_ptr () {return &argsinfo;}
+  
+
+  // init should be called after all the actions, protocols, and
+  // converters have been added to the receptionist and after everything
+  // has been configured but before any pages are created.
+  // It returns true on success and false on failure. If false is
+  // returned getpage should not be called (without producing
+  // meaningless output), instead an error page should be
+  // produced by the calling code.
+  virtual bool init (ostream &logout);
+  
+  // There are two ways to produce a page. You can either call parse_cgi_args,
+  // get_cgihead_info, and produce_content or you can just call parse_cgi_args and
+  // produce_cgi_page (which will be satisfactory in most cases). You might want to call
+  // parse_cgi_args, get_cgihead_info, and produce_content when you want to
+  // interface directly with a web server for which the standard header is inappropriate.
+
+  // parse_cgi_args parses cgi arguments into an argument class.
+  // This function should be called for each page request. It returns false
+  // if there was a major problem with the cgi arguments.
+  virtual bool parse_cgi_args (const text_t &argstr, 
+			       fileupload_tmap &fileuploads,
+			       cgiargsclass &args, 
+			       ostream &logout, text_tmap &fcgienv);
+
+  virtual bool log_cgi_args (cgiargsclass &args, ostream &logout, text_tmap &fcgienv);
+
+  text_t expandmacros (const text_t &astring, cgiargsclass &args, 
+		       ostream &logout);
+
+  // produce_cgi_page will call get_cgihead_info and 
+  // produce_content in the appropriate way to output a cgi header and
+  // the page content (if needed). If a page could not be created it
+  // will return false
+  virtual bool produce_cgi_page (cgiargsclass &args, ostream &contentout, 
+				 ostream &logout, text_tmap &fcgienv);
+  
+  // get_cgihead_info determines the cgi header information for
+  // a set of cgi arguments. If response contains location then
+  // response_data contains the redirect address. If reponse
+  // contains content then reponse_data contains the content-type.
+  // Note that images can now be produced by the receptionist.
+  virtual void get_cgihead_info (cgiargsclass &args, response_t &response,
+				 text_t &response_data, ostream &logout,
+				 text_tmap &fcgienv);
+  virtual void get_cgihead_info (cgiargsclass &args, text_tmap &headers,
+				 ostream &logout, text_tmap &fcgienv);
+
+  // produce the page content
+  virtual bool produce_content (cgiargsclass &args, ostream &contentout,
+				ostream &logout);
+  
+  // returns the compressed argument ("e") corresponding to the argument
+  // list. This can be used to save preferences between sessions.
+  virtual text_t get_compressed_arg (cgiargsclass &args, ostream &logout);
+
+  // gets collection info from cache if found or 
+  // calls collection server (and updates cache)
+  // returns NULL if there's an error
+  ColInfoResponse_t *get_collectinfo_ptr (recptproto *collectproto, 
+					  const text_t &collection, 
+					  ostream &logout);
+
+  void uncache_collection (const text_t &collection);
+  
+protected:
+  // will read in all the macro files. If one is not found an
+  // error message will be written to logout and the method will
+  // return false.
+  virtual bool read_macrofiles (ostream &logout);
+  
+  virtual void read_collection_macrofiles (const text_t& collection, ostream &logout);
+
+  // check_mainargs will check all the main arguments. If a major
+  // error is found it will return false and no cgi page should
+  // be created using the arguments.
+  virtual bool check_mainargs (cgiargsclass &args, ostream &logout);
+};
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/recptmain.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/recptmain.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/recptmain.cpp	(revision 16571)
@@ -0,0 +1,35 @@
+/**********************************************************************
+ *
+ * recptmain.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "receptionist.h"
+#include "cgiwrapper.h"
+#include <assert.h>
+
+int main () {
+  receptionist recpt;
+  cgiwrapper (recpt, g_EmptyText);
+  return 0;
+}
+
Index: /gsdl/trunk/runtime-src/src/recpt/statusaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/statusaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/statusaction.cpp	(revision 16571)
@@ -0,0 +1,1147 @@
+/**********************************************************************
+ *
+ * statusaction.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_STATUS_ACTION
+
+// following line required to get fstream.filedesc() on darwin (Mac OS X)
+#define _STREAM_COMPAT  1
+
+#include "statusaction.h"
+#include "fileutil.h"
+#include "htmlutils.h"
+#include "gsdltools.h"
+#include <assert.h>
+#include <stdio.h>
+#include <fcntl.h> // for open() stuff
+
+void statusaction::output_frameset (cgiargsclass &/*args*/, displayclass &disp, 
+				    outconvertclass &outconvert, 
+				    ostream &textout, ostream &/*logout*/) {
+  textout << outconvert << disp << "_status:frameset_\n";
+}
+
+void statusaction::output_select (cgiargsclass &/*args*/, displayclass &disp, 
+				  outconvertclass &outconvert, 
+				  ostream &textout, ostream &/*logout*/) {
+  textout << outconvert << disp << "_status:header_(selector)\n"
+    "_status:select_\n"
+    "_status:footer_\n";
+}
+
+void statusaction::output_welcome (cgiargsclass &args, recptprotolistclass *protos, 
+				   displayclass &disp, outconvertclass &outconvert, 
+				   ostream &textout, ostream &logout) {
+
+  if (recpt == NULL) return;
+
+  textout << outconvert << disp 
+	  << "_status:infoheader_(_titlewelcome_)\n"
+	  << "_status:welcome_"
+	  << "<table>\n"
+	  << "<th align=left>abbrev.</th><th align=left>collection</th>"
+	  << "<th align=left>public?</th><th align=left>running?</th></tr>\n";
+
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    if ((*rprotolist_here).p != NULL) {
+      comerror_t err;
+      text_t protoname = (*rprotolist_here).p->get_protocol_name(err);
+      text_tarray collist;
+      (*rprotolist_here).p->get_collection_list (collist, err, logout);
+      if (err == noError) {
+	text_tarray::iterator collist_here = collist.begin();
+	text_tarray::iterator collist_end = collist.end();
+
+	while (collist_here != collist_end) {
+
+	    textout << outconvert << disp
+		    << "<tr><td><a href=\"_gwcgi_?_optsite_e=_compressedoptions_&a=status&p=collectioninfo&pr="
+		    << protoname
+		    << "&c="
+		    << *collist_here
+		    << "\">"
+		    << *collist_here 
+		    << "</a></td>";
+
+	  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
+	  if (cinfo != NULL) {
+	    text_t collname = cinfo->get_collectionmeta("collectionname", args["l"]);
+	    if (collname.empty()) {
+	      collname = *collist_here;
+	    }
+
+	    textout << "<td>";
+	    if (cinfo->buildDate > 0)
+	      textout << outconvert << disp 
+		      << "<a href=\"_httppagex_(about)&c=" << *collist_here
+		      << "\" target=\\_top>";
+
+	    textout << outconvert << disp << collname;
+
+	    if (cinfo->buildDate > 0) textout << "</a>";
+
+	    textout << "</td>";
+
+	    if (cinfo->isPublic) textout << "<td>yes</td>";
+	    else textout << "<td>no</td>";
+	    
+	    if (cinfo->buildDate > 0)
+	      textout << outconvert << "<td>yes</td>";
+	    else
+	      textout << "<td>no</td>";
+	    
+	  } else {
+	    textout << "<td></td><td></td><td></td>";
+	  }
+
+	  textout << "</tr>\n";
+	  ++collist_here;
+	}
+      }
+    }
+    ++rprotolist_here;
+  }
+
+  textout << "</table>\n";
+  textout << outconvert << disp << "_status:infofooter_\n";
+}
+
+void statusaction::output_generalinfo (cgiargsclass &/*args*/, displayclass &disp, 
+				       outconvertclass &outconvert, 
+				       ostream &textout, ostream &/*logout*/) {
+  if (recpt == NULL) return;
+  const recptconf &rcinfo = recpt->get_configinfo ();
+  
+  textout << outconvert << disp << "_status:infoheader_(General Information)\n";
+  textout << outconvert 
+	  << "<h2>General information</h2>\n"
+	  << "<table>\n"
+	  << "<tr valign=top><th>gsdlhome</th><td>\"" << rcinfo.gsdlhome
+	  << "\"</td></tr>\n"
+	  << "<tr valign=top><th>collection</th><td>\"" << rcinfo.collection
+	  << "\"</td></tr>\n"
+	  << "<tr valign=top><th>collectdir</th><td>\"" << rcinfo.collectdir
+	  << "\"</td></tr>\n"
+	  << "<tr valign=top><th>httpprefix</th><td>\"" << rcinfo.httpprefix
+	  << "\"</td></tr>\n"
+	  << "<tr valign=top><th>httpimg</th><td>\"" << rcinfo.httpimg
+	  << "\"</td></tr>\n"
+	  << "<tr valign=top><th>gwcgi</th><td>\"" << rcinfo.gwcgi
+	  << "\"</td></tr>\n";
+    
+  // macrofiles
+  textout << outconvert << "<tr valign=top><th>macrofiles</th><td>";
+  text_tset::const_iterator macrohere = rcinfo.macrofiles.begin ();
+  text_tset::const_iterator macroend = rcinfo.macrofiles.end ();
+  bool macrofirst = true;
+  while (macrohere != macroend) {
+    if (!macrofirst) textout << outconvert << ", ";
+    macrofirst = false;
+    textout << outconvert << "\"" << *macrohere << "\"";
+    ++macrohere;
+  }
+  textout << outconvert << "</td></tr>\n";
+  
+  // saveconf
+  textout << outconvert << "<tr valign=top><th>saveconf</th><td>\"" << rcinfo.saveconf
+	  << "\"</td></tr>\n";
+
+  // usecookies
+  textout << outconvert << "<tr valign=top><th>usecookies</th><td>\"";
+  if (rcinfo.usecookies) textout << outconvert << "true";
+  else textout << outconvert << "false";
+  textout << outconvert << "\"</td></tr>\n";
+  
+  // logcgiargs
+  textout << outconvert << "<tr valign=top><th>logcgiargs</th><td>\"";
+  if (rcinfo.logcgiargs) textout << outconvert << "true";
+  else textout << outconvert << "false";
+  textout << outconvert << "\"</td></tr>\n";
+
+  // pageparams
+  textout << outconvert << "<tr valign=top><th>pageparams</th><td>";
+  text_tmap::const_iterator params_here = rcinfo.pageparams.begin();
+  text_tmap::const_iterator params_end = rcinfo.pageparams.end();
+  bool params_first = true;
+  while (params_here != params_end) {
+    if (!params_first) textout << outconvert << ", ";
+    params_first = false;
+    textout << outconvert << "\"" << (*params_here).first << "\" != \""
+	    << (*params_here).second << "\"";
+    
+    ++params_here;
+  }
+  textout << outconvert << "</td></tr>\n";
+
+  // macroprecedence
+  textout << outconvert << "<tr valign=top><th>macroprecedence</th><td>\"" << rcinfo.macroprecedence
+	  << "\"</td></tr>\n";
+
+  // arguments
+  cgiargsinfoclass *rcargsinfo = recpt->get_cgiargsinfo_ptr ();
+  if (rcargsinfo != NULL) {
+    textout << outconvert << "<tr valign=top><th>arguments</th><td>";
+    
+    cgiargsinfoclass::const_iterator argsinfohere = rcargsinfo->begin ();
+    cgiargsinfoclass::const_iterator argsinfoend = rcargsinfo->end ();
+    bool argsinfofirst = true;
+    while (argsinfohere != argsinfoend) {
+      if (!argsinfofirst) textout << outconvert << ", ";
+      argsinfofirst = false;
+      textout << outconvert << "\"" << (*argsinfohere).second.shortname << "\"";
+      ++argsinfohere;
+    }
+    
+    textout << outconvert << "</td></tr>\n";
+  }      
+  
+  // actions
+  actionmapclass *actions = recpt->get_actionmap_ptr();
+  if (actions != NULL) {
+    textout << outconvert << "<tr valign=top><th>actions</th><td>";
+    
+    actionptrmap::iterator actionshere = actions->begin ();
+    actionptrmap::iterator actionsend = actions->end ();
+    bool actionsfirst = true;
+    while (actionshere != actionsend) {
+      if (!actionsfirst) textout << outconvert << ", ";
+      actionsfirst = false;
+      assert ((*actionshere).second.a != NULL);
+      if ((*actionshere).second.a != NULL) {
+	textout << outconvert << "\"" << (*actionshere).second.a->get_action_name() << "\"";
+      }
+      ++actionshere;
+    }
+    
+    textout << outconvert << "</td></tr>\n";
+  }
+  
+  // browsers
+  browsermapclass *browsers = recpt->get_browsermap_ptr();
+  if (browsers != NULL) {
+    textout << outconvert << "<tr valign=top><th>browsers</th><td>";
+    
+    browserptrmap::iterator browsershere = browsers->begin ();
+    browserptrmap::iterator browsersend = browsers->end ();
+    bool browsersfirst = true;
+    while (browsershere != browsersend) {
+      if (!browsersfirst) textout << outconvert << ", ";
+      browsersfirst = false;
+      assert ((*browsershere).second.b != NULL);
+      if ((*browsershere).second.b != NULL) {
+	textout << outconvert << "\"" << (*browsershere).second.b->get_browser_name() << "\"";
+      }
+      ++browsershere;
+    }
+    
+    textout << outconvert << "</td></tr>\n";
+  }
+
+  // protocols
+  recptprotolistclass *protocols = recpt->get_recptprotolist_ptr ();
+  if (protocols != NULL) {
+    textout << outconvert << "<tr valign=top><th>protocols</th><td>";
+    
+    recptprotolistclass::iterator protohere = protocols->begin ();
+    recptprotolistclass::iterator protoend = protocols->end ();
+    bool protofirst = true;
+    while (protohere != protoend) {
+      comerror_t err;
+      if (!protofirst) textout << outconvert << ", ";
+      protofirst = false;
+      if ((*protohere).p != NULL) {
+	textout << outconvert << "\"" << (*protohere).p->get_protocol_name(err) << "\"";
+      }
+      ++protohere;
+    }
+    
+    textout << outconvert << "</td></tr>\n";
+  }
+  
+  // converters
+  convertinfoclass *converters = recpt->get_convertinfo_ptr ();
+  if (converters != NULL) {
+    textout << outconvert << "<tr valign=top><th>converters</th><td>";
+    
+    convertinfoclass::iterator converthere = converters->begin ();
+    convertinfoclass::iterator convertend = converters->end ();
+    bool convertfirst = true;
+    while (converthere != convertend) {
+      if (!convertfirst) textout << outconvert << ", ";
+      convertfirst = false;
+      textout << outconvert << "\"" << (*converthere).second.name << "\"";
+      ++converthere;
+    }
+    
+    textout << outconvert << "</td></tr>\n";
+  }
+  
+  textout << outconvert << disp << "</table>\n_status:infofooter_\n";
+}
+
+void statusaction::output_argumentinfo (cgiargsclass &args, displayclass &disp, 
+					outconvertclass &outconvert, 
+					ostream &textout, ostream &/*logout*/) {
+  if (recpt == NULL) return;
+  cgiargsinfoclass *rcargsinfo = recpt->get_cgiargsinfo_ptr ();
+  if (rcargsinfo == NULL) return;
+
+  textout << outconvert << disp << "_status:infoheader_(Argument Information)\n";
+  textout << outconvert
+	  << "<h2>Argument information</h2>\n"
+	  << "<table>";
+
+  // argument information
+  textout << outconvert << "<tr valign=top><th>short name</th><th>long name</th>"
+	  << "<th>multiple char?</th>"
+	  << "<th>multiple value?</th>"
+	  << "<th>default</th><th>default status</th><th>saved args</th>"
+	  << "<th>current value</th></tr>\n";
+  
+
+  cgiargsinfoclass::const_iterator argsinfohere = rcargsinfo->begin();
+  cgiargsinfoclass::const_iterator argsinfoend = rcargsinfo->end();
+  text_t *arg_value;
+  while (argsinfohere != argsinfoend) {
+    const cgiarginfo &ainfo = (*argsinfohere).second;
+    textout << outconvert 
+	    << "<tr valign=top><td>" << ainfo.shortname << "</td>\n";
+    
+    textout << outconvert << "<td>" << ainfo.longname << "</td>\n";
+    if (ainfo.multiplechar) textout << outconvert << "<td>yes</td>\n";
+    else textout << outconvert << "<td>no</td>\n";
+    if (ainfo.multiplevalue) textout << outconvert << "<td>yes</td>\n";
+    else textout << outconvert << "<td>no</td>\n";
+    textout << outconvert << "<td>" << ainfo.argdefault << "</td>\n";
+    switch (ainfo.defaultstatus) {
+    case cgiarginfo::none: textout << outconvert << "<td>none</td>\n"; break;
+    case cgiarginfo::weak: textout << outconvert << "<td>weak</td>\n"; break;
+    case cgiarginfo::good: textout << outconvert << "<td>good</td>\n"; break;
+    case cgiarginfo::config: textout << outconvert << "<td>config</td>\n"; break;
+    case cgiarginfo::imperative: textout << outconvert << "<td>imperative</td>\n"; break;
+    }
+    switch (ainfo.savedarginfo) {
+    case cgiarginfo::mustnot: textout << outconvert << "<td>mustnot</td>\n"; break;
+    case cgiarginfo::can: textout << outconvert << "<td>can</td>\n"; break;
+    case cgiarginfo::must: textout << outconvert << "<td>must</td>\n"; break;
+    }
+    
+    arg_value = args.getarg (ainfo.shortname);
+    if (arg_value == NULL) textout << outconvert << "<td></td></tr>\n";
+    else textout << outconvert << "<td>\"" << *arg_value << "\"</td></tr>\n";
+    
+    ++argsinfohere;
+  }
+  
+  textout << outconvert << disp << "</table>\n_status:infofooter_\n";
+}
+
+void statusaction::output_actioninfo (cgiargsclass &/*args*/, displayclass &disp, 
+				      outconvertclass &outconvert, 
+				      ostream &textout, ostream &/*logout*/) {
+  if (recpt == NULL) return;
+  actionmapclass *actions = recpt->get_actionmap_ptr();
+
+  textout << outconvert << disp << "_status:infoheader_(Action Information)\n";
+  textout << outconvert
+	  << "<h2>Action information</h2>\n"
+	  << "<table>";
+
+  // action information
+  if (actions != NULL) {
+    textout << outconvert 
+	    << "<tr><th>action name</th><th>cgi arguments</th></tr>\n";
+	
+    actionptrmap::iterator actionshere = actions->begin ();
+    actionptrmap::iterator actionsend = actions->end ();
+    while (actionshere != actionsend) {
+      assert ((*actionshere).second.a != NULL);
+      if ((*actionshere).second.a != NULL) {
+	textout << outconvert 
+		<< "<tr><td>" << (*actionshere).second.a->get_action_name()
+		<< "</td><td>";
+	
+	cgiargsinfoclass *argsinfo = (*actionshere).second.a->getargsinfo();
+	cgiargsinfoclass::const_iterator argsinfohere = argsinfo->begin ();
+	cgiargsinfoclass::const_iterator argsinfoend = argsinfo->end ();
+	bool aifirst = true;
+	while (argsinfohere != argsinfoend) {
+	  if (!aifirst) textout << outconvert << ", ";
+	  aifirst = false;
+	  textout << outconvert << (*argsinfohere).second.shortname;
+	  ++argsinfohere;
+	}
+	
+	textout << outconvert << "</td></tr>\n";
+      }
+      ++actionshere;
+    }
+  }
+  
+  textout << outconvert << disp << "</table>\n_status:infofooter_\n";
+}
+
+void statusaction::output_browserinfo (cgiargsclass &/*args*/, displayclass &disp, 
+				       outconvertclass &outconvert, 
+				       ostream &textout, ostream &/*logout*/) {
+  if (recpt == NULL) return;
+  browsermapclass *browsers = recpt->get_browsermap_ptr();
+
+  textout << outconvert << disp << "_status:infoheader_(Browser Information)\n";
+  textout << outconvert
+	  << "<h2>Browser information</h2>\n"
+	  << "<table>";
+
+  // browser information
+  if (browsers != NULL) {
+    textout << outconvert 
+	    << "<tr><th>browser name</th><th>default formatstring</th></tr>\n";
+	
+    browserptrmap::iterator browsershere = browsers->begin ();
+    browserptrmap::iterator browsersend = browsers->end ();
+    while (browsershere != browsersend) {
+      assert ((*browsershere).second.b != NULL);
+      if ((*browsershere).second.b != NULL) {
+	textout << outconvert 
+		<< "<tr><td>" << (*browsershere).second.b->get_browser_name()
+		<< "</td><td>" << html_safe ((*browsershere).second.b->get_default_formatstring())
+		<< "</td></tr>\n";
+      }
+      ++browsershere;
+    }
+  }
+  
+  textout << outconvert << disp << "</table>\n_status:infofooter_\n";
+}
+
+void statusaction::output_protocolinfo (cgiargsclass &/*args*/, displayclass &disp, 
+					outconvertclass &outconvert, 
+					ostream &textout, ostream &logout) {
+  if (recpt == NULL) return;
+  const recptconf &rcinfo = recpt->get_configinfo ();
+  bool colspecific = !rcinfo.collection.empty();
+  bool unreachablecol = false;
+
+  recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr ();
+  if (rprotolist == NULL) return;
+
+  textout << outconvert << disp << "_status:infoheader_(Protocol Information)\n";
+  textout << outconvert
+	  << "<h2>Protocol information</h2>\n"
+	  << "<table>\n"
+	  << "<tr><th>protocol</th><th>collections</th></tr>\n";
+
+  text_t protoname;
+  recptprotolistclass::iterator rprotolist_here = rprotolist->begin();
+  recptprotolistclass::iterator rprotolist_end = rprotolist->end();
+  while (rprotolist_here != rprotolist_end) {
+    if ((*rprotolist_here).p != NULL) {
+      comerror_t err;
+      protoname = (*rprotolist_here).p->get_protocol_name(err);
+      textout << outconvert
+	      << "<tr><td>"
+	      << protoname
+	      << "</td><td>";
+
+      text_tarray collist;
+      (*rprotolist_here).p->get_collection_list (collist, err, logout);
+      if (err == noError) {
+	text_tarray::iterator collist_here = collist.begin();
+	text_tarray::iterator collist_end = collist.end();
+	bool first = true;
+	while (collist_here != collist_end) {
+	  if (!first) textout << outconvert << ", ";
+	  first = false;
+
+	  if (colspecific && *collist_here != rcinfo.collection) {
+	    unreachablecol = true;
+	    textout << outconvert << "\"" << *collist_here << "\"";
+	  } else {
+	    textout << outconvert << disp
+		    << "\"<a href=\"_gwcgi_?e=_compressedoptions_&a=status&p=collectioninfo&pr="
+		    << protoname
+		    << "&c="
+		    << *collist_here
+		    << "\">"
+		    << *collist_here 
+		    << "</a>\"";
+	  }
+
+	  ++collist_here;
+	}
+
+      } else {
+	textout << outconvert << "Error (" << get_comerror_string (err) 
+		<< ") while getting collect list\n";
+      }
+
+      textout << outconvert 
+	      << "</td></tr>\n";
+    }
+
+    ++rprotolist_here;
+  }
+
+  textout << outconvert << "</table>\n";
+  if (unreachablecol) {
+    textout << outconvert 
+	    << "<b>Warning:</b> the receptionist is running in collection specific\n"
+	    << "mode making some of the collections unreachable.\n";
+  }
+  textout << outconvert << disp << "_status:infofooter_\n";
+}
+
+void statusaction::output_collectioninfo (cgiargsclass &args, displayclass &disp, 
+					  outconvertclass &outconvert, 
+					  ostream &textout, ostream &logout) {
+  if (recpt == NULL) return;
+
+  textout << outconvert << disp << "_status:infoheader_(Collection info)\n";
+  textout << outconvert << "<h2>Collection info</h2>\n";
+
+  // get the list of protocols
+  recptprotolistclass *rprotolist = recpt->get_recptprotolist_ptr ();
+  if (rprotolist == NULL) return;
+
+  // look for the desired protocol
+  text_t &arg_pr = args["pr"];
+  text_t &arg_c = args["c"];
+  recptproto *rproto = NULL;
+  recptprotolistclass::iterator rprotolist_here = rprotolist->begin();
+  recptprotolistclass::iterator rprotolist_end = rprotolist->end();
+  while (rprotolist_here != rprotolist_end) {
+    rproto = (*rprotolist_here).p;
+    comerror_t err;
+    if (rproto != NULL && rproto->get_protocol_name(err) == arg_pr) {
+      // see if the protocol has the collection
+      bool hascollection;
+      rproto->has_collection (arg_c, hascollection, err, logout);
+      if (err == noError && hascollection) break;
+    }
+    ++rprotolist_here;
+  }
+  
+  if (rprotolist_here == rprotolist_end) {
+    textout << outconvert << "Protocol \"" << arg_pr << "\" with collection \""
+	    << arg_c << "\" was not found\n";
+
+  } else {
+    // rproto can't be NULL to get here
+    ColInfoResponse_t *collectinfo = recpt->get_collectinfo_ptr (rproto, arg_c, logout);
+    if (collectinfo != NULL) {
+      textout << outconvert << "<table>\n"
+	      << "<tr><th>collection name</th><td>\""
+	      << collectinfo->shortInfo.name
+	      << "\"</td></tr>\n"
+
+	      << "<tr><th>host</th><td>\""
+	      << collectinfo->shortInfo.host
+	      << "\"</td></tr>\n"
+
+	      << "<tr><th>port</th><td>\""
+	      << collectinfo->shortInfo.port
+	      << "\"</td></tr>\n"
+
+	      << "<tr><th>is public?</th><td>";
+      if (collectinfo->isPublic) textout << outconvert << "true";
+      else textout << outconvert << "false";
+      textout << outconvert 
+	      << "</td></tr>\n"
+
+	      << "<tr><th>is beta?</th><td>";
+      if (collectinfo->isBeta) textout << outconvert << "true";
+      else textout << outconvert << "false";
+      textout << outconvert 
+	      << "</td></tr>\n"
+
+	      << "<tr><th>build date</th><td>\""
+	      << collectinfo->buildDate
+	      << "\"</td></tr>\n"
+
+	      << "<tr><th>interface languages</th><td>";
+      text_tarray::iterator languages_here = collectinfo->languages.begin();
+      text_tarray::iterator languages_end = collectinfo->languages.end();
+      bool languages_first = true;
+      while (languages_here != languages_end) {
+	if (!languages_first) textout << outconvert << ", ";
+	languages_first = false;
+	textout << outconvert << "\"" << *languages_here << "\"";
+	++languages_here;
+      }
+
+      textout << "<tr><th valign=top>collection metadata</th><td><table>\n";
+      collectionmeta_map::iterator meta_here = collectinfo->collectionmeta.begin();
+      collectionmeta_map::iterator meta_end = collectinfo->collectionmeta.end();
+      
+      while (meta_here != meta_end) {
+	textout << outconvert << "<tr><td valign=top>" << (*meta_here).first
+		<< "</td><td><table>" ;
+      	text_tmap lang_map = (*meta_here).second;
+	text_tmap::iterator lang_here = lang_map.begin();
+	text_tmap::iterator lang_end = lang_map.end();
+	while (lang_here != lang_end) {
+	  textout << outconvert << "<tr><td>" << (*lang_here).first
+		    << "</td><td>" << (*lang_here).second << "</td></tr>\n";
+	  
+	  ++lang_here;
+	}
+	textout << outconvert << "</table></td></tr>\n";
+	++meta_here;
+      }
+      textout << "</table></td></tr>\n";
+
+      textout << "<tr><th valign=top>format info</th><td><table>\n";
+      text_tmap::iterator format_here = collectinfo->format.begin();
+      text_tmap::iterator format_end = collectinfo->format.end();
+      while (format_here != format_end) {
+	textout << outconvert << "<tr><td valign=top>" << (*format_here).first
+		<< "</td><td>" << html_safe((*format_here).second) << "</td></tr>\n";
+	++format_here;
+      }
+      textout << "</table></td></tr>\n";
+
+      textout << "<tr><th valign=top>building info</th><td><table>\n";
+      text_tmap::iterator building_here = collectinfo->building.begin();
+      text_tmap::iterator building_end = collectinfo->building.end();
+      while (building_here != building_end) {
+	textout << outconvert << "<tr><td>" << (*building_here).first
+		<< "</td><td>" << (*building_here).second << "</td></tr>\n";
+	++building_here;
+      }
+      textout << "</table></td></tr>\n";
+
+      textout << outconvert 
+	      << "</td></tr>\n"
+
+	      << "<tr><th>number of documents</th><td>\""
+	      << collectinfo->numDocs
+	      << "\"</td></tr>\n"
+
+	      << "<tr><th>number of sections</th><td>\""
+	      << collectinfo->numSections
+	      << "\"</td></tr>\n"
+
+	      << "<tr><th>number of words</th><td>\""
+	      << collectinfo->numWords
+	      << "\"</td></tr>\n"
+
+	      << "<tr><th>number of bytes</th><td>\""
+	      << collectinfo->numBytes
+	      << "\"</td></tr>\n"
+
+	      << "<tr><th>preferred receptionist</th><td>\""
+	      << collectinfo->receptionist
+	      << "\"</td></tr>\n"
+
+	      << "</table>";
+      
+    } else {
+      textout << "ERROR (statusaction::output_collectioninfo): while getting collect information\n";
+    }
+
+
+    InfoFiltersResponse_t filterinfo;
+    InfoFilterOptionsRequest_t filteroptions_request;
+    InfoFilterOptionsResponse_t filteroptions;
+    comerror_t err;
+    rproto->get_filterinfo (arg_c, filterinfo, err, logout);
+    if (err == noError) {
+      text_tset::iterator filternames_here = filterinfo.filterNames.begin();
+      text_tset::iterator filternames_end = filterinfo.filterNames.end();
+      while (filternames_here != filternames_end) {
+	textout << outconvert 
+		<< "<hr>\n"
+		<< "<h3>Filter options for \"" << (*filternames_here) << "\"</h3>\n"
+		<< "<table>\n"
+		<< "<tr><th>option name</th><th>type</th><th>repeatable</th>"
+		<< "<th>default value</th><th>valid values</th></tr>\n";
+
+	filteroptions_request.clear();
+	filteroptions_request.filterName = *filternames_here;
+	rproto->get_filteroptions (arg_c, filteroptions_request,
+				   filteroptions, err, logout);
+	if (err == noError) {
+	  FilterOption_tmap::iterator filteropt_here = 
+	    filteroptions.filterOptions.begin();
+	  FilterOption_tmap::iterator filteropt_end = 
+	    filteroptions.filterOptions.end();
+	  while (filteropt_here != filteropt_end) {
+	    textout << outconvert
+		    << "<tr><td>\""
+		    << (*filteropt_here).second.name
+		    << "\"</td>\n"
+	      
+		    << "<td>";
+	    text_t type_string;
+	    switch ((*filteropt_here).second.type) {
+	    case FilterOption_t::booleant: type_string = "boolean"; break;
+	    case FilterOption_t::integert: type_string = "integer"; break;
+	    case FilterOption_t::enumeratedt: type_string = "enumerated"; break;
+	    case FilterOption_t::stringt: type_string = "string"; break;
+	    }
+	    textout << outconvert
+		    << type_string
+		    << "</td>\n"
+	      
+		    << "<td>";
+	    text_t repeat_string;
+	    switch ((*filteropt_here).second.repeatable) {
+	    case FilterOption_t::onePerQuery: repeat_string = "one per query"; break;
+	    case FilterOption_t::onePerTerm: repeat_string = "one per term"; break;
+	    case FilterOption_t::nPerTerm: repeat_string = "n per term"; break;
+	    }
+	    textout << outconvert
+		    << repeat_string
+		    << "</td>\n"
+	      
+		    << "<td>\""
+		    << (*filteropt_here).second.defaultValue
+		    << "\"</td>\n"
+	      
+		    << "<td>";
+	    
+	    text_tarray::iterator valid_here = 
+	      (*filteropt_here).second.validValues.begin();
+	    text_tarray::iterator valid_end = 
+	      (*filteropt_here).second.validValues.end();
+	    bool valid_first = true;
+	    while (valid_here != valid_end) {
+	      if (!valid_first) textout << outconvert << ", ";
+	      valid_first = false;
+	      textout << outconvert << "\"" << *valid_here << "\"";
+	      ++valid_here;
+	    }
+	    textout << outconvert
+		    << "</td></tr>\n";
+
+	    ++filteropt_here;
+	  }
+
+	  textout << outconvert
+		  << "</table>\n";
+
+	} else {
+	  textout << outconvert << "Error (" << get_comerror_string (err) 
+		  << ") while getting filter option information\n";
+	}
+
+	++filternames_here;
+      }
+
+    } else {
+      textout << outconvert << "Error (" << get_comerror_string (err) 
+	      << ") while getting filter information\n";
+    }
+  }
+  
+  textout << outconvert << disp << "_status:infofooter_\n";
+}
+
+void statusaction::output_usagelog (cgiargsclass &/*args*/, displayclass &disp,
+				    outconvertclass &outconvert, 
+				    ostream &textout, ostream &/*logout*/) {
+
+  // output last 100 lines of usage.txt
+
+  text_t logfilename = filename_cat (gsdlhome, "etc", "usage.txt");
+
+  textout << outconvert << disp << "_status:infoheader_(Usage log)\n";
+  textout << outconvert << "<h2>Usage log</h2>\n";
+
+  textout << outconvert << "<p>The usage log, "
+	  << logfilename << ", contains the\n"
+	  << "following information:\n"
+	  << "<p>(note that if this file is more than 100 lines long only the last 100 lines will\n"
+	  << "be displayed on this page)\n\n"
+	  << "<pre>\n";
+
+  // note that we're expecting lines to be no more than 1500 characters on
+  // average - should fix this file_tail() thing sometime
+  textout << outconvert << file_tail (logfilename, 100, 1500);
+
+  textout << outconvert << disp << "</pre>\n"
+	  << "_status:infofooter_\n";
+}
+
+void statusaction::output_errorlog (cgiargsclass &/*args*/, displayclass &disp, 
+				    outconvertclass &outconvert, 
+				    ostream &textout, ostream &logout) {
+
+  text_t errfilename = filename_cat (gsdlhome, "etc", "error.txt");
+  char *cerrfilename = errfilename.getcstr();
+  if (cerrfilename == NULL) return;
+
+  textout << outconvert << disp << "_status:infoheader_(Error log)\n";
+  textout << outconvert << "<h2>Error log</h2>\n";
+  logout << flush;
+
+#ifdef GSDL_USE_IOS_H
+  ifstream errin (cerrfilename, ios::in | ios::nocreate);
+#else
+  ifstream errin (cerrfilename, ios::in);
+#endif
+
+  delete []cerrfilename;
+  if (errin) {
+    textout << outconvert << "<p>The error log, "
+		<< errfilename << ", contains the\n";
+    textout << outconvert << "following information:\n\n";
+    text_t errorpage = "<p><pre>\n";
+
+    char c;
+    errin.get(c);
+    while (!errin.eof ()) {
+      errorpage.push_back(c);
+      errin.get(c);
+    }
+    
+    errorpage += "</pre>\n";
+    errin.close();
+    textout << outconvert << errorpage;
+
+  } else {
+    textout << outconvert << "Couldn't read error log, " 
+		<< errfilename << ".\n";
+  }
+
+  textout << outconvert << disp << "_status:infofooter_\n";
+}
+
+void statusaction::output_gsdlsite (cgiargsclass &/*args*/, displayclass &disp, 
+				    outconvertclass &outconvert, 
+				    ostream &textout, ostream &logout) {
+
+  textout << outconvert << disp << "_status:infoheader_(gsdlsite.cfg)\n";
+  textout << outconvert << "<h2>gsdlsite.cfg</h2>\n";
+  logout << flush;
+
+#ifdef GSDL_LOCAL_LIBRARY
+  text_t gsdlsite_cfg = filename_cat (gsdlhome, "gsdlsite.cfg");
+#else
+  text_t gsdlsite_cfg = "gsdlsite.cfg";
+#endif
+
+  char *gsdlsite_cfgc = gsdlsite_cfg.getcstr();
+#ifdef GSDL_USE_IOS_H
+  ifstream gsdlsitein (gsdlsite_cfgc, ios::in | ios::nocreate);
+#else
+  ifstream gsdlsitein (gsdlsite_cfgc, ios::in);
+#endif
+
+  delete []gsdlsite_cfgc;
+
+  if (gsdlsitein) {
+    textout << "<p>The gsdlsite.cfg configuration file contains the\n"
+	    << "following information:\n\n";
+    text_t gsdlsite = "<p><pre>\n";
+
+    char c;
+    gsdlsitein.get(c);
+    while (!gsdlsitein.eof ()) {
+      gsdlsite.push_back(c);
+      gsdlsitein.get(c);
+    }
+    
+    gsdlsite += "</pre>\n";
+    gsdlsitein.close();
+    textout << outconvert << gsdlsite;
+
+  } else {
+    textout << "Couldn't read gsdlsite.cfg configuration file\n";
+  }
+
+  textout << outconvert << disp << "_status:infofooter_\n";
+}
+
+void statusaction::output_maincfg (cgiargsclass &/*args*/, displayclass &disp, 
+				   outconvertclass &outconvert, 
+				   ostream &textout, ostream &/*logout*/) {
+
+  text_t maincfgfile = filename_cat (dbhome, "etc", "main.cfg");
+
+  textout << outconvert << disp << "_status:infoheader_(main.cfg)\n"
+	  << "<h2>main.cfg</h2>\n"
+	  << "<p>The main configuration file, "
+	  << dm_safe(maincfgfile) << ", contains the following information:<br>\n\n"
+	  << "(Note that only users belonging to the \"administrator\" group "
+	  << "may edit this file)<br>\n"
+	  << "_status:maincfg_<br>\n"
+	  << "_status:infofooter_\n";
+}
+
+void statusaction::change_maincfg (cgiargsclass &args, displayclass &disp, 
+				   outconvertclass &outconvert, 
+				   ostream &textout, ostream &logout) {
+
+  // write out the contents of the cfgfile argument to main.cfg
+  text_t cfgfile = filename_cat(gsdlhome, "etc", "main.cfg");
+  char *cfgfilec = cfgfile.getcstr();
+
+  int fd=open(cfgfilec, O_WRONLY | O_CREAT | O_TRUNC
+#if defined(__WIN32__)
+	      | O_BINARY
+#endif
+	      );
+
+  if (fd != -1) {
+
+    int lock_val = 1;
+    GSDL_LOCK_FILE (fd);
+    if (lock_val != 0) {
+      logout << "statusaction::change_maincfg: Error: Couldn't lock file " << cfgfilec << "\n";
+      textout << outconvert << disp << "_status:changemaincfgfail_";
+      close (fd);
+    } else {
+      outconvertclass text_t2ascii;
+      text_t2ascii.setinput(&args["cfgfile"]);
+      size_t buffersize=args["cfgfile"].size();
+      char *buffer=new char[buffersize];
+      size_t num_chars;
+      convertclass::status_t status;
+      text_t2ascii.convert(buffer, buffersize, num_chars, status);
+      // ignore status - assume it is "finished" as buffer is big enough
+      write(fd, buffer, num_chars);
+      GSDL_UNLOCK_FILE (fd);
+      delete []buffer;
+      close (fd);
+      textout << outconvert << disp << "_status:changemaincfgsuccess_";
+    }
+  } else {
+    logout << "statusaction::change_maincfg: Error: Couldn't open file " << cfgfilec << "for writing\n";
+    textout << outconvert << disp << "_status:changemaincfgfail_";
+  }
+  delete []cfgfilec;
+}
+
+void statusaction::output_errorpage (outconvertclass &outconvert, 
+				     ostream &textout, ostream &/*logout*/,
+				     text_t message) {
+  textout << outconvert 
+	  << "<html>\n"
+	  << "<head>\n"
+	  << "<title>Error</title>\n"
+	  << "</head>\n"
+	  << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
+	  << "alink=\"#cc9900\" vlink=\"#666633\">\n"
+	  << "<h2>Oops!</h2>\n" 
+	  << message
+	  << "\n</body>\n"
+	  << "</html>\n";
+  return;
+}
+
+
+
+statusaction::statusaction () {
+  disabled = true;
+  recpt = NULL;
+
+  // this action uses cgi variable "a"
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "status";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "p" -- status page
+  arg_ainfo.shortname = "p";
+  arg_ainfo.longname = "page";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "frameset";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "pr" -- protocol
+  arg_ainfo.shortname = "pr";
+  arg_ainfo.longname = "protocol";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::none;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::can;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  arg_ainfo.shortname = "cfgfile";
+  arg_ainfo.longname = "configuration file contents";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+}
+
+statusaction::~statusaction () {
+}
+
+bool statusaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args, 
+				  recptprotolistclass * /*protos*/, ostream &/*logout*/) {
+
+  // only users belonging to the "administrator" group may edit 
+  // the main.cfg file
+  if (args["p"] == "maincfg" || args["p"] == "changemaincfg") {
+    args["uan"] = "1";
+    args["ug"] = "administrator";
+  }
+  return true;
+}
+
+void statusaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
+				     response_t &response, text_t &response_data, 
+				     ostream &/*logout*/) {
+  response = content;
+  response_data = "text/html";
+}
+
+
+void statusaction::define_internal_macros (displayclass &disp, cgiargsclass &args, 
+					   recptprotolistclass * /*protos*/, ostream &logout) {
+
+  // define_internal_macros sets the following macros:
+  // _maincfgfile_   the contents of the main.cfg configuration file
+
+  // _versionnnum_   greenstone version number (hard-coded)
+
+  disp.setmacro("versionnum", "status", GSDL_VERSION);
+
+  if (args["p"] == "maincfg") {
+
+    // read in main.cfg
+    text_t maincfg = filename_cat(gsdlhome, "etc", "main.cfg");  
+    char *maincfgc = maincfg.getcstr();
+    
+#ifdef GSDL_USE_IOS_H
+    ifstream cfg_ifs (maincfgc, ios::in | ios::nocreate);
+#else
+    ifstream cfg_ifs (maincfgc, ios::in);
+#endif
+    
+    if (cfg_ifs) {  
+      text_t cfgtext;
+      char c;
+      cfg_ifs.get(c);
+      while (!cfg_ifs.eof ()) {
+	cfgtext.push_back(c);
+	cfg_ifs.get(c);
+      }
+      cfg_ifs.close();
+      
+      // define it as a macro
+      disp.setmacro("maincfgfile", "status", dm_safe(cfgtext));
+      
+    } else {
+      logout << "statusaction::define_internal_macros: couldn't open configuration file (" 
+	     << maincfgc << ") for reading\n";
+      disp.setmacro("maincfgfile", "status", g_EmptyText);
+    }    
+    delete []maincfgc;
+  }
+}
+
+bool statusaction::do_action (cgiargsclass &args, recptprotolistclass *protos, 
+			      browsermapclass * /*browsers*/, displayclass &disp, 
+			      outconvertclass &outconvert, ostream &textout, 
+			      ostream &logout) {
+  // make sure the status function is enabled
+  if (disabled) {
+    textout << outconvert 
+	    << "<html>\n"
+	    << "<head>\n"
+	    << "<title>Status disabled</title>\n"
+	    << "</head>\n"
+	    << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
+	    << "alink=\"#cc9900\" vlink=\"#666633\">\n"
+	    << "<h2>Facility disabled</h2>\n" 
+	    << "Sorry, the Maintenance and Administration facility is currently disabled\n"
+	    << "\n</body>\n"
+	    << "</html>\n";
+    return true;
+  }
+  
+  // make sure we know about a receptionist
+  if (recpt == NULL) {
+    output_errorpage (outconvert, textout, logout, 
+		      "The status action does not contain information\n"
+		      "about any receptionists. The method set_receptionist\n"
+		      "was probably not called from the module which instantiated\n"
+		      "this status action.\n");
+    return true;
+  }
+
+  // check to make sure status.dm was read in
+  const recptconf &rcinfo = recpt->get_configinfo ();
+  text_tset::const_iterator macrohere = rcinfo.macrofiles.begin ();
+  text_tset::const_iterator macroend = rcinfo.macrofiles.end ();
+  while (macrohere != macroend) {
+    if (*macrohere == "status.dm") break;
+    ++macrohere;
+  }
+  if (macrohere == macroend) {
+    output_errorpage (outconvert, textout, logout, 
+		      "The status.dm file was not read in. This macro file is\n" 
+		      "needed to display configuration and status information.\n");
+    return true;
+  }
+
+  // output the required status page
+  text_t &arg_p = args["p"];
+  if (arg_p == "frameset") output_frameset (args, disp, outconvert, textout, logout);
+  else if (arg_p == "select") output_select (args, disp, outconvert, textout, logout);
+  else if (arg_p == "welcome") output_welcome (args, protos, disp, outconvert, textout, logout);
+  else if (arg_p == "generalinfo") output_generalinfo (args, disp, outconvert, textout, logout);
+  else if (arg_p == "argumentinfo") output_argumentinfo (args, disp, outconvert, textout, logout);
+  else if (arg_p == "actioninfo") output_actioninfo (args, disp, outconvert, textout, logout);
+  else if (arg_p == "browserinfo") output_browserinfo (args, disp, outconvert, textout, logout);
+  else if (arg_p == "protocolinfo") output_protocolinfo (args, disp, outconvert, textout, logout);
+  else if (arg_p == "collectioninfo") output_collectioninfo (args, disp, outconvert, textout, logout);
+  else if (arg_p == "usagelog") output_usagelog (args, disp, outconvert, textout, logout);
+  else if (arg_p == "errorlog") output_errorlog (args, disp, outconvert, textout, logout);
+  else if (arg_p == "gsdlsite") output_gsdlsite (args, disp, outconvert, textout, logout);
+  else if (arg_p == "maincfg") output_maincfg (args, disp, outconvert, textout, logout);
+  else if (arg_p == "changemaincfg") change_maincfg (args, disp, outconvert, textout, logout);
+  else {
+    output_errorpage (outconvert, textout, logout, 
+		      "Unknown page \"" + arg_p + "\".\n");
+  }
+
+  return true;
+}
+
+void statusaction::configure (const text_t &key, const text_tarray &cfgline) {
+  if ((key == "status") && (cfgline.size() == 1) && 
+      (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
+    disabled = false;
+  } else {
+    // call the parent class to deal with the things which
+    // are not dealt with here
+    action::configure (key, cfgline);
+  }
+}
+
+#endif //GSDL_USE_STATUS_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/statusaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/statusaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/statusaction.h	(revision 16571)
@@ -0,0 +1,132 @@
+/**********************************************************************
+ *
+ * statusaction.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_STATUS_ACTION
+
+#ifndef STATUSACTION_H
+#define STATUSACTION_H
+
+
+#include "gsdlconf.h"
+#include "action.h"
+#include "receptionist.h"
+
+
+class statusaction : public action {
+protected:
+  bool disabled;
+  receptionist *recpt;
+
+  void output_frameset (cgiargsclass &args, displayclass &disp, 
+			outconvertclass &outconvert, 
+			ostream &textout, ostream &logout);
+
+  void output_select (cgiargsclass &args, displayclass &disp, 
+		      outconvertclass &outconvert, 
+		      ostream &textout, ostream &logout);
+
+  void output_welcome (cgiargsclass &args, recptprotolistclass *protos,
+		       displayclass &disp, outconvertclass &outconvert, 
+		       ostream &textout, ostream &logout);
+
+  void output_generalinfo (cgiargsclass &args, displayclass &disp, 
+			   outconvertclass &outconvert, 
+			   ostream &textout, ostream &logout);
+
+  void output_argumentinfo (cgiargsclass &args, displayclass &disp, 
+			    outconvertclass &outconvert, 
+			    ostream &textout, ostream &logout);
+
+  void output_actioninfo (cgiargsclass &args, displayclass &disp, 
+			  outconvertclass &outconvert, 
+			  ostream &textout, ostream &logout);
+
+  void output_browserinfo (cgiargsclass &args, displayclass &disp, 
+			   outconvertclass &outconvert, 
+			   ostream &textout, ostream &logout);
+
+  void output_protocolinfo (cgiargsclass &args, displayclass &disp, 
+			    outconvertclass &outconvert, 
+			    ostream &textout, ostream &logout);
+
+  void output_collectioninfo (cgiargsclass &args, displayclass &disp, 
+			      outconvertclass &outconvert, 
+			      ostream &textout, ostream &logout);
+
+  void output_usagelog (cgiargsclass &args, displayclass &disp,
+			outconvertclass &outconvert, 
+			ostream &textout, ostream &logout);
+
+  void output_errorlog (cgiargsclass &args, displayclass &disp, 
+			outconvertclass &outconvert, 
+			ostream &textout, ostream &logout);
+
+  void output_gsdlsite (cgiargsclass &args, displayclass &disp, 
+			outconvertclass &outconvert, 
+			ostream &textout, ostream &logout);
+
+  void output_maincfg (cgiargsclass &args, displayclass &disp, 
+		       outconvertclass &outconvert, 
+		       ostream &textout, ostream &logout);
+
+  void change_maincfg (cgiargsclass &args, displayclass &disp, 
+		       outconvertclass &outconvert, 
+		       ostream &textout, ostream &logout);
+
+  void output_errorpage (outconvertclass &outconvert, 
+			 ostream &textout, ostream &logout,
+			 text_t message);
+
+public:
+  statusaction ();
+  virtual ~statusaction ();
+
+  text_t get_action_name () {return "status";}
+
+  void set_receptionist (receptionist *therecpt) {recpt=therecpt;}
+
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass *protos, ostream &logout);
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response, text_t &response_data, 
+			 ostream &logout);
+
+
+  void define_internal_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+  void configure (const text_t &key, const text_tarray &cfgline);
+};
+
+
+#endif //!STATUSACTION_H
+#endif //GSDL_USE_STATUS_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/string_pool.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/string_pool.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/string_pool.cpp	(revision 16571)
@@ -0,0 +1,44 @@
+/**********************************************************************
+ *
+ * string_pool.cpp -- 
+ * Copyright (C) 2003 DL Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "string_pool.h"
+
+string_pool::string_pool () {
+}
+
+string_pool::~string_pool () {
+  vector<char *>::const_iterator here = pool.begin();
+  vector<char *>::const_iterator end = pool.end();
+  while (here != end) {
+    delete(*here);
+    ++here;
+  }
+}
+
+char *string_pool::get_cstr_from_pool(const text_t &str) {
+  char *cstr = str.getcstr();
+  pool.push_back(cstr);
+  return cstr;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/string_pool.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/string_pool.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/string_pool.h	(revision 16571)
@@ -0,0 +1,45 @@
+/**********************************************************************
+ *
+ * string_pool.h -- 
+ * Copyright (C) 2003 DL Consulting Ltd
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef STRING_POOL_H
+#define STRING_POOL_H
+
+#include "text_t.h"
+
+class string_pool {
+protected:
+  
+  vector<char *> pool;
+
+public:
+  string_pool();
+  virtual ~string_pool();
+
+  char* get_cstr_from_pool (const text_t &str);
+
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/summarise.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/summarise.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/summarise.cpp	(revision 16571)
@@ -0,0 +1,270 @@
+/**********************************************************************
+ *
+ * summarise.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/* The function 'summarise' produces, given a document text and a query,
+ * a (query-biased) summary. In the future, several types of summaries will
+ * be supported.
+ */
+
+#include "summarise.h"
+#include "unitool.h"
+#include <string.h>
+
+
+/* **************** LOCAL PROTOTYPES **************** */
+
+text_t summarise_startend(text_t &htmlstr, int summaryLength);
+text_t summarise_keywords(text_t &htmlstr, text_t &query, int summaryLength);
+
+text_t next_sentence(text_t::iterator& start, text_t::iterator& end);
+text_t previous_sentence(text_t::iterator& start, text_t::iterator& end);
+bool paragraph_tag(text_t::iterator start);
+
+
+/****************************************************
+ NAME: summarise
+ DESC: produce a summary for a document
+*****************************************************/
+
+text_t summarise(text_t &htmlstr, text_t &query, int summaryLength) {
+  //  return summarise_startend(htmlstr,summaryLength);
+  return summarise_keywords(htmlstr,query,summaryLength);
+}
+
+
+/****************************************************
+ NAME: summarise_startend
+ DESC: return first and last sentences of a document
+*****************************************************/
+
+text_t summarise_startend(text_t &htmlstr, int summaryLength) {
+  text_t::iterator str_start = htmlstr.begin(), str_end = htmlstr.end();
+  text_t answer;
+
+  // add first sentences up to half the summary length
+
+  text_t::iterator str_current = str_start;
+  while(str_current<str_end && answer.size()<(summaryLength/2)) {
+    text_t sentence = next_sentence(str_current,str_end);
+    answer.append(sentence);
+  }
+
+  summaryLength -= answer.size(); // summary length left for last sentences
+  if(summaryLength<0)
+    summaryLength = 0;
+
+  str_end = str_current;
+  str_current = htmlstr.end()-1;
+  text_t lastSentence;
+  while(str_current>str_end && 
+        lastSentence.size()<summaryLength) {
+    text_t sentence = previous_sentence(str_current,str_end);
+    lastSentence = sentence + lastSentence;
+  }
+
+  answer += " ... ";
+  answer += lastSentence;
+
+  return answer;
+}
+
+
+/****************************************************
+ NAME: summarise_keywords
+ DESC: build a summary with sentences containing keyword(s).
+       the sentences with most matching keywords are returned 
+       first.
+*****************************************************/
+
+text_t summarise_keywords(text_t &htmlstr, text_t &query, int summaryLength) {
+
+  text_tarray allterms, terms;
+  splitchar(query.begin(),query.end(),' ',allterms);
+
+  // consider only non-empty terms
+  for(text_tarray::iterator term = allterms.begin();
+      term < allterms.end(); ++term) {
+    if(!(*term).empty())
+      terms.push_back(*term);
+  }
+
+  text_tarray::iterator terms_start = terms.begin(), terms_end = terms.end();
+
+  //text_tarray::iterator terms_current = terms_start;
+  //strstr("merde",*terms_current);
+
+  text_t::iterator str_start = htmlstr.begin(), str_end = htmlstr.end();
+
+  vector<text_tarray> answers(terms.size()); 
+    // an array of array of sentences for the summary:
+    //   answers[0] contains sentences with 1 keyword
+    //   answers[1] contains sentences with 2 keywords, etc.
+  vector<int> answersSize(terms.size());
+    // answersSize[0] is the combined size of sentences with 1 keyword, etc.
+  for(vector<int>::iterator size = answersSize.begin();
+      size<answersSize.end(); ++size)
+    *size = 0; // initialise sentence size
+
+  int totfound  = 0;
+  text_t::iterator str_current = str_start;
+  while(str_current<str_end && answersSize[terms.size()-1]<summaryLength) {
+    // if the size of best sentences is greater than summary, that's enough!
+    text_t sentence = next_sentence(str_current,str_end);
+
+    text_tarray::iterator terms_current = terms_start;
+    int nFound = 0;
+    while(terms_current!=terms_end) {
+      text_t::iterator word = findword(sentence.begin(),sentence.end(),
+				       *terms_current);
+      if(word!=sentence.end())
+	{        ++nFound; ++totfound; }
+      ++terms_current;
+    }
+
+    if(nFound>0 && answersSize[nFound-1]<summaryLength) {
+      answers[nFound-1].push_back(sentence);
+      answersSize[nFound-1] += sentence.size();
+    }
+  }
+
+  text_t answer;
+  for(vector<text_tarray>::iterator sentarray = answers.end()-1;
+      sentarray>=answers.begin(); --sentarray)
+    for(text_tarray::iterator sentence = (*sentarray).begin(); 
+        sentence < (*sentarray).end(); ++sentence) {
+      answer.append(*sentence);
+      if(answer.size()>=summaryLength)
+        return answer;
+    }
+
+  if(!answer.empty())
+    return answer;
+
+  return summarise_startend(htmlstr,summaryLength);
+}
+
+
+/* *********************** LOCAL FUNCTIONS ******************* */
+
+/* NAME: next_sentence
+   DESC: returns next sentence, text-only (ie. HTML markup is removed)
+ */
+
+text_t next_sentence(text_t::iterator& start, text_t::iterator& end) {
+  text_t sentence;                 // the sentence to be returned
+  bool   foundPunctuation = false; // set to true by '.', '!' or '?'
+  while(start<end && !foundPunctuation) {
+    switch (*start) {
+    case '<': // skip over rest of html tag
+      if(paragraph_tag(start) && has_unicode_letdig(sentence))
+        foundPunctuation = true;
+      while ((start<end) && (*start!='>'))
+	++start;
+      if(start<end) ++start;
+      break;
+    case '.':
+    case '!':
+    case '?':
+      sentence.push_back(*start);
+      ++start;
+      if(start>=end || 
+         (is_unicode_space(*start) && (*(start-2)<'A' || *(start-2)>'Z'))) {
+        foundPunctuation = true;
+      }
+      break;
+    default:
+      sentence.push_back(*start);
+      ++start;
+      break;
+    }
+  }
+  return sentence;
+}
+
+
+/* NAME: previous_sentence
+   DESC: returns previous sentence, text-only (ie. HTML markup is removed)
+ */
+
+text_t previous_sentence(text_t::iterator& start, text_t::iterator& end) {
+  text_t sentence;                    // the sentence to be returned
+  bool   found1stPunctuation = false, // set to true by '.', '!' or '?'
+                                      // first punct. is included in results
+         found2ndPunctuation = false; // second punct. is stop condition,
+                                      // and is not included in results
+  while(start>end && !found2ndPunctuation) {
+    switch (*start) {
+    case '>': // skip over rest of html tag
+      while ((start>end) && (*start!='<')) // backtrack to beginning of tag
+	--start;
+      if(start>end) {
+        if(paragraph_tag(start) && has_unicode_letdig(sentence))
+          found2ndPunctuation = true;
+        --start;
+      }
+      break;
+    case '.':
+    case '!':
+    case '?':
+      if(!is_unicode_space(*(start+1)) ||
+         (start-1>end && *(start-1)>='A' && *(start-1)<='Z')) {
+        // if next character is not a blank, or preceding character is
+	// a capital letter, we guess it's an acronym (e.g. "U.S.A.")
+        sentence.text_as_usvector().insert(sentence.text_as_usvector().begin(),
+          start,start+1);
+        --start;
+      } else
+        if(has_unicode_letdig(sentence) || found1stPunctuation)
+          found2ndPunctuation = true;
+        else {
+          sentence.text_as_usvector().insert(
+              sentence.text_as_usvector().begin(),start,start+1);
+          --start;
+          found1stPunctuation = true;
+        }
+      break;
+    default:
+      sentence.text_as_usvector().insert(
+        sentence.text_as_usvector().begin(),start,start+1);
+      --start;
+      break;
+    }
+  }
+  return sentence;
+}
+
+
+// start is positioned on the '<'
+bool paragraph_tag(text_t::iterator start) {
+  if(*start=='<') {
+    ++start;
+    if(*start=='p' || *start=='P') {
+      ++start;
+      if(is_unicode_space(*start) || *start=='>')
+        return true;
+    }
+  }
+  return false;
+}
Index: /gsdl/trunk/runtime-src/src/recpt/summarise.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/summarise.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/summarise.h	(revision 16571)
@@ -0,0 +1,34 @@
+/**********************************************************************
+ *
+ * summarise.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef SUMMARISE_H
+#define SUMMARISE_H
+
+#include "text_t.h"
+
+text_t summarise(text_t &htmlstr, text_t &query, int summaryLength);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/tipaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/tipaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/tipaction.cpp	(revision 16571)
@@ -0,0 +1,73 @@
+/**********************************************************************
+ *
+ * tipaction.cpp -- define random tip macros
+ * Copyright (C) 1999  DigiLib Systems Limited, New Zealand
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_TIP_ACTION
+
+#include "tipaction.h"
+#include <stdlib.h>
+
+
+tipaction::tipaction () {
+  // "st" show tips - "0"=no, "1"=yes
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "st";
+  arg_ainfo.longname = "show tips";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "1";
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+}
+
+void tipaction::define_external_macros (displayclass &disp, cgiargsclass &args, 
+					recptprotolistclass * /*protos*/, ostream &logout) {
+
+  // define_external_macros sets the following macros:
+
+  // _tip:thistip_  - a random tip (defined if st == "1")
+
+  if (args["st"].getint()) {
+    // get the maximum tip number (_tip:tipmax_)
+    text_t tipmax_str;
+    disp.expandstring ("tip", "_tipmax_", tipmax_str);
+    if (tipmax_str.empty()) {
+      // don't bother filling up the logs if tip.dm isn't loaded!
+      // logout << "Warning: _tip:tipmax_ not set. This macro is needed for displaying tips.\n";
+      return;
+    }
+    
+    int tipmax = tipmax_str.getint();
+    if (tipmax < 1) {
+      // don't bother filling up the logs if tip.dm isn't loaded!
+      // logout << "Warning: _tip:tipmax_ was less than 1. No tips were set.\n";
+      return;
+    }
+    
+    disp.setmacro("thistip", "tip", "_tip" + text_t((rand()%tipmax) + 1) + "_");
+  }
+}
+
+#endif //GSDL_USE_TIP_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/tipaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/tipaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/tipaction.h	(revision 16571)
@@ -0,0 +1,49 @@
+/**********************************************************************
+ *
+ * tipaction.h -- define tip macros
+ * Copyright (C) 1999  DigiLib Systems Limited, New Zealand
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_TIP_ACTION
+
+#ifndef TIPACTION_H
+#define TIPACTION_H
+
+#include "gsdlconf.h"
+#include "action.h"
+
+
+// tipaction exists just for the benefit of defining external macros
+class tipaction : public action {
+public:
+  tipaction ();
+  virtual ~tipaction () {}
+  text_t get_action_name () {return "tip";}
+  
+  void define_external_macros (displayclass &disp, cgiargsclass &args, 
+			       recptprotolistclass *protos, ostream &logout);
+};
+
+
+#endif //!TIPACTION_H
+#endif //GSDL_USE_TIP_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/userdb.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/userdb.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/userdb.cpp	(revision 16571)
@@ -0,0 +1,525 @@
+/**********************************************************************
+ *
+ * userdb.cpp -- functions to handle a user database
+ * Copyright (C) 1999  DigiLib Systems Limited, New Zealand
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdlconf.h"
+#include "userdb.h"
+#include "gdbmclass.h"
+#include "gsdltimes.h"
+#include "fileutil.h"
+#include <stdlib.h>
+
+// include crypt
+#if defined(__WIN32__)
+#include "crypt.h"
+#else
+#if defined(HAVE_CRYPT_H)
+#include <crypt.h>
+#else 
+#include <unistd.h>
+#endif
+#endif
+
+//==========================================//
+//      userinfo_t functions (Start)        //
+//==========================================//
+userinfo_t::userinfo_t()
+{
+  clear();
+}
+
+userinfo_t::~userinfo_t(){};
+
+void userinfo_t::clear () {
+  username.clear();
+  password.clear();
+  enabled = false;
+  groups.clear();
+  comment.clear();
+}
+
+userinfo_t &userinfo_t::operator=(const userinfo_t &x) {
+  username = x.username;
+  password = x.password;
+  enabled = x.enabled;
+  groups = x.groups;
+  comment = x.comment;
+  
+  return *this;
+}
+//==========================================//
+//       userinfo_t functions (END)         //
+//==========================================//
+
+//==========================================//
+//      userdbclass functions (Start)       //
+//==========================================//
+userdbclass::userdbclass(const text_t &userdbfilename)
+{
+  storeduserdbfilename = userdbfilename;
+  userdb = new gdbmclass();
+  activated = (!userdb->opendatabase(storeduserdbfilename, DB_READER, 1000, true)) ? false : true;
+  if (activated == false) 
+    {
+      activated = (!userdb->opendatabase(storeduserdbfilename, DB_WRITER_CREATE, 1000, true)) ? false : true;
+      if (activated == true)
+        {
+          userdb->closedatabase();
+          activated = (!userdb->opendatabase(storeduserdbfilename, DB_READER, 1000, true)) ? false : true;
+        }
+    }
+    
+  external_db = false;
+}
+
+userdbclass::~userdbclass()
+{
+  if (external_db == false)
+  {
+    userdb->closedatabase();
+    delete userdb;
+  }
+}
+
+// few useful functions
+text_t userdbclass::crypt_text (const text_t &text) 
+{
+  static const char *salt = "Tp";
+  text_t crypt_password;
+  
+  if (text.empty()) return g_EmptyText;
+  
+  // encrypt the password
+  char *text_cstr = text.getcstr();
+  if (text_cstr == NULL) return g_EmptyText;
+  crypt_password = crypt(text_cstr, salt);
+  delete []text_cstr;
+
+  return crypt_password;
+}
+
+// username_ok tests to make sure a username is ok. a username
+// must be at least 2 characters long, but no longer than 30
+// characters long. it can contain the characters a-z A-Z 0-9
+// . and _
+bool userdbclass::username_ok (const text_t &username) 
+{
+  if (username.size() < 2 || username.size() > 30) return false;
+
+  text_t::const_iterator here = username.begin();
+  text_t::const_iterator end = username.end();
+  while (here != end) 
+    {
+      if ((*here >= 'a' && *here <= 'z') ||
+          (*here >= 'A' && *here <= 'Z') ||
+          (*here >= '0' && *here <= '9') ||
+          *here == '.' ||
+          *here == '_') 
+        {
+          // ok
+        } else return false;
+      ++here;
+    }
+  
+  return true;
+}
+
+// password_ok tests to make sure a password is ok. a password
+// must be at least 3 characters long but no longer than 8 characters
+// long. it can contain any character in the range 0x20-0x7e
+bool userdbclass::password_ok (const text_t &password) 
+{
+  // DB: 20/02/08. Why mustn't the password exceed 8 chars, 
+  // windows 3.1 complicance?  Even then this doesn't make sense to me
+  // as storing this in GDBM wouldn't trigger a 8-char limit
+
+  // Have increased this to 128.  Not because I think someone will type
+  // in something that long, but some encryptions schemes (e.g. wireless
+  // networks) work with such lengths and someone one day might like
+  // to use such a generated password in Greenstone.
+  // 
+
+  if (password.size() < 3 || password.size() > 128) return false;
+
+  text_t::const_iterator here = password.begin();
+  text_t::const_iterator end = password.end();
+  while (here != end) {
+    if (*here >= 0x20 && *here <= 0x7e) 
+      {
+        // ok
+      } else return false;
+    ++here;
+  }
+
+  return true;
+}
+
+// removes spaces from user groups
+text_t userdbclass::format_user_groups(const text_t user_groups)
+{
+  text_t new_groups = g_EmptyText;
+  text_t::const_iterator here = user_groups.begin();
+  text_t::const_iterator end = user_groups.end();
+  while (here != end) {
+    if (*here != ' '&& *here != '\t' && *here != '\n') 
+      {
+        new_groups.push_back(*here);
+      }
+    ++here;
+  }
+  return new_groups;
+}
+
+// functions dealing with user databases
+// returns true on success (in which case userinfo will contain
+// the information for this user)
+// @return 0 success
+// @return -1 database is not currently connected
+// @return -2 not defined username
+int userdbclass::get_user_info (const text_t &username, userinfo_t &userinfo) 
+{
+  // Let's make sure the connection has been established.
+  if (activated == true)
+    {
+      userinfo.clear();
+      infodbclass info;
+      // See if we can get the user's infomration
+      if (userdb->getinfo (username, info)) 
+        {
+          userinfo.username = info["username"];
+          userinfo.password = info["password"];
+          userinfo.enabled = (info["enabled"] == "true");
+          userinfo.groups = info["groups"];
+          userinfo.comment = info["comment"];
+          return ERRNO_SUCCEED;
+        }
+      // If we failed to retrieve the users information, we should check if the username is admin or not.
+      // If it is the admin user, let's create a new account for the admin user.
+      else if (username == "admin") 
+        {
+          userinfo.clear();
+          userinfo.username = "admin";
+          userinfo.password = crypt_text("admin");
+          userinfo.enabled = true;
+          userinfo.groups = "administrator,all-collections-editor";
+          userinfo.comment = "change the password for this account as soon as possible";
+          // Return the set result.
+          return set_user_info (username, userinfo);
+        }
+      // The username is not found, return false
+      return ERRNO_USERNOTFOUND;
+    }
+  // Failed to connect to the database, return false.
+  return ERRNO_CONNECTIONFAILED;
+}
+
+// returns true on success
+int userdbclass::set_user_info (const text_t &username, const userinfo_t &userinfo) 
+{
+  // Let's make sure the connection has been established.
+  if (activated == true)
+    {
+      infodbclass info;
+      info["username"] = userinfo.username;
+      info["password"] = userinfo.password;
+      info["enabled"] = userinfo.enabled ? "true" : "false";
+      info["groups"] = userinfo.groups;
+      info["comment"] = userinfo.comment;
+      userdb->closedatabase();
+      userdb->opendatabase(storeduserdbfilename, DB_WRITER_CREATE, 1000, true);
+      int result = (userdb->setinfo (username, info)) ? ERRNO_SUCCEED : ERRNO_DBACTIONFAILED;
+      userdb->closedatabase();
+      userdb->opendatabase(storeduserdbfilename, DB_READER, 1000, true);         
+      return  result;
+    }
+  return ERRNO_CONNECTIONFAILED;
+}
+
+// returns true if the user's password is correct.
+int userdbclass::check_passwd (const text_t &username, const text_t &password) 
+{
+  userinfo_t thisuser;
+  int returned = get_user_info(username, thisuser);
+  if(returned != ERRNO_SUCCEED) return returned;
+  // couple of basic checks
+  if (thisuser.username.empty() || thisuser.password.empty() ||
+      password.empty()) return ERRNO_MISSINGPASSWORD;
+
+  text_t crypt_password = crypt_text(password);
+  return (thisuser.password == crypt_password) ? ERRNO_SUCCEED : ERRNO_PASSWORDMISMATCH;
+}
+
+int userdbclass::add_user (const userinfo_t &userinfo) 
+{
+  // Let's make sure the connection has been established.
+  if (activated == true)
+    {
+      infodbclass info;
+      if (userdb->getinfo (userinfo.username, info)) 
+        {
+          // There is an existing username already
+          return ERRNO_EXISTINGUSERNAME;
+        }
+      else
+        {
+          return set_user_info(userinfo.username, userinfo);
+        }      
+    }
+  return ERRNO_CONNECTIONFAILED;
+}
+
+int userdbclass::edit_user (const userinfo_t &userinfo) 
+{
+  // Let's make sure the connection has been established.
+  if (activated == true)
+    {
+      infodbclass info;
+      if (userdb->getinfo (userinfo.username, info)) 
+        {
+          return set_user_info(userinfo.username, userinfo);
+        }
+      else
+        {
+          // The user does not exist in the database.
+          return ERRNO_USERNOTFOUND;
+        }      
+    }
+  return ERRNO_CONNECTIONFAILED;
+}
+
+int userdbclass::delete_user (const text_t &username) 
+{  
+  // Let's make sure the connection has been established.
+  if (activated == true)
+    {
+      userdb->closedatabase();
+      userdb->opendatabase(storeduserdbfilename, DB_WRITER_CREATE, 1000, true);
+      userdb->deletekey (username);
+      userdb->closedatabase();
+      userdb->opendatabase(storeduserdbfilename, DB_READER, 1000, true);
+      return ERRNO_SUCCEED;
+    }
+  return ERRNO_CONNECTIONFAILED;
+}
+
+// gets all the users' information in the database. returns true
+// on success
+int userdbclass::get_all_users(userinfo_tarray &userinfo_array) 
+{
+  // Let's make sure the connection has been established.
+  if (activated == true)
+    {
+      userinfo_array.erase(userinfo_array.begin(), userinfo_array.end());
+      text_tarray userlist = userdb->getkeys();
+      text_tarray::iterator user_iterator = userlist.begin();
+      while (user_iterator != userlist.end())
+      {
+        userinfo_t one_userinfo;
+        int returned = get_user_info(*user_iterator, one_userinfo);
+        if (returned != ERRNO_SUCCEED) return returned;
+        userinfo_array.push_back(one_userinfo);
+	user_iterator++;
+      }
+      return ERRNO_SUCCEED;
+    }
+  return ERRNO_CONNECTIONFAILED;
+}
+
+// gets a list of all the users in the database. returns true
+// on success
+int userdbclass::get_user_list (text_tarray &userlist) 
+{
+  // Let's make sure the connection has been established.
+  if (activated == true)
+    {
+      userlist.erase (userlist.begin(), userlist.end());
+      userlist = userdb->getkeys();
+      return ERRNO_SUCCEED;
+    }
+  return ERRNO_CONNECTIONFAILED;
+}
+//==========================================//
+//       userdbclass functions (End)        //
+//==========================================//
+
+//==========================================//
+//      keydbclass functions (Start)        //
+//==========================================//
+keydbclass::keydbclass(const text_t &keydbfilename)
+{
+  storedkeydbfilename = keydbfilename;
+  keydb = new gdbmclass();
+  activated = keydb->opendatabase(storedkeydbfilename, DB_READER, 1000, true);
+  if (activated == false) 
+    {
+      activated = keydb->opendatabase(storedkeydbfilename, DB_WRITER_CREATE, 1000, true);
+      if (activated == true)
+        {
+          keydb->closedatabase();
+          activated = keydb->opendatabase(storedkeydbfilename, DB_READER, 1000, true);
+        }
+    }
+  external_db = false;
+}
+
+keydbclass::~keydbclass()
+{
+  if (external_db == false)
+  {
+    keydb->closedatabase();
+    delete keydb;
+  }
+}
+
+// generates a random key for the user, stores it in the database and
+// returns it so that it can be used in page generation
+// returns "" on failure
+text_t keydbclass::generate_key (const text_t &username) 
+{
+  // Let's make sure the connection has been established.
+  if (activated == true)
+    {
+      static const char *numconvert = "0123456789abcdefghijklmnopqrstuvwxyz"
+        "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+      
+      // loop looking for a suitable new key
+      text_t userkey;
+      text_t crypt_userkey;
+      do {
+        // convert to base 62 :-)
+        int userkey_int = rand ();
+        while (userkey_int > 0) 
+          {
+            userkey.push_back (numconvert[userkey_int%62]);
+            userkey_int /= 62;
+          }
+        
+        // make sure this key is not in the database
+        crypt_userkey = userdbclass::crypt_text(userkey);
+        if (keydb->exists (crypt_userkey)) userkey.clear();
+      } while (userkey.empty());
+      
+      // enter the key into the database
+      infodbclass keydata;
+      keydata["user"] = username;
+      keydata["time"] = time2text(time(NULL));
+      
+      keydb->closedatabase();
+      keydb->opendatabase(storedkeydbfilename, DB_WRITER_CREATE, 1000, true);
+      if (!keydb->setinfo (crypt_userkey, keydata)) 
+        {
+          userkey.clear(); // failed
+        }
+      keydb->closedatabase();
+      keydb->opendatabase(storedkeydbfilename, DB_READER, 1000, true); 
+      
+      return userkey;
+    }
+  return "";
+}
+
+// checks to see if there is a key for this particular user in the
+// database that hasn't decayed. a short decay is used when group
+// is set to administrator
+bool keydbclass::check_key (const userinfo_t &thisuser, const text_t &key, const text_t &group, int keydecay) 
+{
+  // Let's make sure the connection has been established.
+  if (activated == true)
+    {
+      if (thisuser.username.empty() || key.empty()) return false;
+      
+      // the keydecay is set to 5 minute for things requiring the
+      // administrator
+      //  if (group == "administrator") keydecay = 300;
+      
+      // success if there is a key in the key database that is owned by this
+      // user whose creation time is less that keydecay
+      text_t crypt_key = userdbclass::crypt_text(key);
+      infodbclass info;
+      if (keydb->getinfo (crypt_key, info))  {
+        if (info["user"] == thisuser.username) {
+          time_t keycreation = text2time (info["time"]);
+          if (keycreation != (time_t)-1 && difftime (text2time(time2text(time(NULL))),
+                                                     keycreation) <= keydecay) {
+            // succeeded, update the key's time
+            info["time"] = time2text(time(NULL));
+            keydb->closedatabase();
+            keydb->opendatabase(storedkeydbfilename, DB_WRITER_CREATE, 1000, true);
+            keydb->setinfo (crypt_key, info);
+            keydb->closedatabase();
+            keydb->opendatabase(storedkeydbfilename, DB_READER, 1000, true); 
+            return true;
+          }
+        }
+      }
+    }
+  return false;
+}
+
+// remove_old_keys will remove all keys created more than keydecay ago.
+// use sparingly, it can be quite an expensive function
+void keydbclass::remove_old_keys (int keydecay) 
+{
+  // Let's make sure the connection has been established.
+  if (activated == true)
+    {  
+      // get a list of keys created more than keydecay seconds agon
+      text_tarray oldkeys;
+      infodbclass info;
+      time_t timenow = text2time(time2text(time(NULL)));
+      time_t keycreation = (time_t)-1;
+
+      text_tarray keylist = keydb->getkeys();
+      text_tarray::iterator key_iterator = keylist.begin();
+      while (key_iterator != keylist.end())
+      {
+        if (keydb->getinfo (*key_iterator, info))  {
+          keycreation = text2time (info["time"]);
+          if (keycreation != (time_t)-1 && difftime (timenow, keycreation) > keydecay) {
+            // found an old key
+            oldkeys.push_back(*key_iterator);
+          }
+        }
+        
+	key_iterator++;
+      }
+      
+      // delete the old keys
+      if (oldkeys.size() > 0) {
+	keydb->closedatabase();
+	keydb->opendatabase(storedkeydbfilename, DB_WRITER_CREATE, 1000, true);
+	text_tarray::iterator keys_here = oldkeys.begin();
+	text_tarray::iterator keys_end = oldkeys.end();
+	while (keys_here != keys_end) {
+	  keydb->deletekey(*keys_here);
+	  ++keys_here;
+	}
+	keydb->closedatabase();
+	keydb->opendatabase(storedkeydbfilename, DB_READER, 1000, true);
+      }
+    }
+}
+//==========================================//
+//       keydbclass functions (End)         //
+//==========================================//
Index: /gsdl/trunk/runtime-src/src/recpt/userdb.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/userdb.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/userdb.h	(revision 16571)
@@ -0,0 +1,147 @@
+/**********************************************************************
+ *
+ * userdb.h -- functions to handle a user database
+ * Copyright (C) 1999  DigiLib Systems Limited, New Zealand
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef USERDB_H
+#define USERDB_H
+
+#define ERRNO_SUCCEED           0 
+#define ERRNO_CONNECTIONFAILED -1
+#define ERRNO_USERNOTFOUND     -2
+#define ERRNO_EXISTINGUSERNAME -3
+#define ERRNO_MISSINGPASSWORD  -4
+#define ERRNO_PASSWORDMISMATCH -5
+#define ERRNO_DBACTIONFAILED   -6
+
+
+#include "dbclass.h"
+
+// The user information object and it provides basic functions for the information object, such as clear and copy (=) functions;
+class userinfo_t
+{
+ public:
+  text_t username;
+  text_t password;
+  bool enabled;
+  text_t groups; // comma separated list
+  text_t comment;
+
+  userinfo_t ();
+  virtual ~userinfo_t();
+  userinfo_t &operator=(const userinfo_t &x);
+  void clear ();
+};
+
+typedef vector<userinfo_t> userinfo_tarray; // more space efficient than text_tlist
+
+class userdbclass
+{
+ protected:
+  // The internal storage for the userdbfilename and the userdb object
+  dbclass* userdb;
+  bool external_db;
+  bool activated;
+  text_t storeduserdbfilename; 
+  
+ public:
+  userdbclass (const text_t &userdbfilename);
+  virtual ~userdbclass();
+
+  //======== the static methods========//
+  // the password line in the userinfo_t must be encrypted using
+  // this function
+  static text_t crypt_text (const text_t &text);
+  // username_ok tests to make sure a username is ok. a username
+  // must be at least 2 characters long, but no longer than 30
+  // characters long. it can contain the characters a-z A-Z 0-9
+  // . and _
+  static bool username_ok (const text_t &username);
+  // password_ok tests to make sure a password is ok. a password
+  // must be at least 3 characters long but no longer than 8 characters
+  // long. it can contain any character in the range 0x20-0x7e
+  static bool password_ok (const text_t &password);
+  // removes spaces from user groups
+  static text_t format_user_groups(const text_t user_groups);
+  
+  //======== functions dealing with single user in the user databases ========//
+  // returns true on success (in which case userinfo will contain
+  // the information for this user)
+  int get_user_info (const text_t &username, userinfo_t &userinfo);
+  
+  // returns true on success
+  int set_user_info (const text_t &username, const userinfo_t &userinfo);
+  
+  // returns true if the user's password is correct.
+  int check_passwd (const text_t &username, const text_t &password);
+  
+  // adds a user from the user database -- forever
+  int add_user (const userinfo_t &userinfo);
+  
+  // edits a user from the user database -- forever
+  int edit_user (const userinfo_t &userinfo);
+  
+  // removes a user from the user database -- forever
+  int delete_user (const text_t &username);
+  
+  //======== functions dealing with multiple users in the user databases ========//
+  // gets all the users' information in the database. returns true
+  // on success
+  int get_all_users(userinfo_tarray &userinfo_array);
+  
+  // gets a list of all the users in the database. returns true
+  // on success
+  int get_user_list (text_tarray &userlist);
+};
+
+class keydbclass
+{
+ protected:
+  // The internal storage for the userdbfilename and the userdb object
+  dbclass* keydb;
+  bool external_db;
+  bool activated;
+   text_t storedkeydbfilename; 
+  
+ public:
+  keydbclass (const text_t &keydbfilename);
+  virtual ~keydbclass();
+  // functions dealing with databases of temporary keys
+  
+  // generates a random key for the user, stores it in the database and
+  // returns it so that it can be used in page generation
+  // returns "" on failure
+  text_t generate_key (const text_t &username);
+  
+  // checks to see if there is a key for this particular user in the
+  // database that hasn't decayed. a short decay is used when group
+  // is set to administrator
+  bool check_key (const userinfo_t &thisuser, const text_t &key, const text_t &group, int keydecay);
+  
+  // remove_old_keys will remove all keys created more than keydecay ago.
+  // use sparingly, it can be quite an expensive function
+  void remove_old_keys (int keydecay);
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/usersaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/usersaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/usersaction.cpp	(revision 16571)
@@ -0,0 +1,412 @@
+/**********************************************************************
+ *
+ * usersaction.cpp -- managing users
+ * Copyright (C) 1999  DigiLib Systems Limited, New Zealand
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_USERS_ACTION
+
+#include "usersaction.h"
+#include "fileutil.h"
+
+
+///////////////
+// usersaction
+///////////////
+
+usersaction::usersaction () {
+  // this action uses cgi variable "a"
+  cgiarginfo arg_ainfo;
+  arg_ainfo.shortname = "a";
+  arg_ainfo.longname = "action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "um"; // user management
+  arg_ainfo.savedarginfo = cgiarginfo::must;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "uma"
+  arg_ainfo.shortname = "uma";
+  arg_ainfo.longname = "user management action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = "listusers";
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "umun"
+  arg_ainfo.shortname = "umun";
+  arg_ainfo.longname = "user management user name";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "umpw"
+  arg_ainfo.shortname = "umpw";
+  arg_ainfo.longname = "user management password";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "umnpw1"
+  arg_ainfo.shortname = "umnpw1";
+  arg_ainfo.longname = "user management new password 1";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "umnpw2"
+  arg_ainfo.shortname = "umnpw2";
+  arg_ainfo.longname = "user management new password 2";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "umus"
+  arg_ainfo.shortname = "umus";
+  arg_ainfo.longname = "user management account status";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "umug"
+  arg_ainfo.shortname = "umug";
+  arg_ainfo.longname = "user management groups"; // comma seperated list
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "umc"
+  arg_ainfo.shortname = "umc";
+  arg_ainfo.longname = "user management comment";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "bcp"
+  arg_ainfo.shortname = "bcp";
+  arg_ainfo.longname = "change password submit button";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "beu"
+  arg_ainfo.shortname = "beu";
+  arg_ainfo.longname = "edit user submit button";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+
+  // "cm"
+  arg_ainfo.shortname = "cm";
+  arg_ainfo.longname = "confirm an action";
+  arg_ainfo.multiplechar = true;
+  arg_ainfo.defaultstatus = cgiarginfo::weak;
+  arg_ainfo.argdefault = g_EmptyText;
+  arg_ainfo.savedarginfo = cgiarginfo::mustnot;
+  argsinfo.addarginfo (NULL, arg_ainfo);
+}
+
+void usersaction::configure (const text_t &key, const text_tarray &cfgline) {
+  action::configure (key, cfgline);
+}
+
+bool usersaction::init (ostream &logout) {
+
+  if (dbhome.empty()) {
+    logout << "ERROR (usersaction::init) dbhome is not set\n";
+    return false;
+  }
+
+  return action::init (logout);
+}
+
+bool usersaction::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &args, 
+				 recptprotolistclass * /*protos*/, ostream &/*logout*/) {
+  args["uan"] = "1"; // user authentication is needed
+
+  if (args["uma"] == "changepasswd") {
+    // no particular group is needed to change a password
+    args["ug"].clear(); 
+  } else {
+    // administrator is needed for all other management tasks
+    args["ug"] = "administrator";
+  }
+  
+  return true;
+}
+
+void usersaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
+				    response_t &response, text_t &response_data, 
+				    ostream &/*logout*/) {
+  response = content;
+  response_data = "text/html";
+}
+
+bool usersaction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/, 
+			     browsermapclass * /*browsers*/, displayclass &disp, 
+			     outconvertclass &outconvert, ostream &textout, 
+			     ostream &logout) {
+
+  if (args["uma"] == "adduser" || args["uma"] == "edituser") {
+    // adduser is handled by edituser
+    return do_edituser (args, disp, outconvert, textout, logout);
+    
+  } else if (args["uma"] == "deleteuser") {
+    return do_deleteuser (args, disp, outconvert, textout, logout);
+    
+  } else if (args["uma"] == "changepasswd") {
+    return do_changepasswd (args, disp, outconvert, textout, logout);  
+  }
+
+  // default
+  return do_listusers (args, disp, outconvert, textout, logout);
+}
+
+bool usersaction::do_listusers (cgiargsclass &/*args*/, displayclass &disp, 
+				outconvertclass &outconvert, ostream &textout, 
+				ostream &/*logout*/) {
+
+  textout << outconvert << disp
+	  << "_userslistusers:header_\n_userslistusers:contentstart_\n";
+
+  text_tarray userlist;
+  // get user list
+  user_database->get_user_list (userlist);
+
+  // sort the list
+  sort(userlist.begin(), userlist.end());
+  
+  // output the information for each user
+  userinfo_t userinfo;
+  text_tarray::iterator users_here = userlist.begin();
+  text_tarray::iterator users_end = userlist.end();
+  while (users_here != users_end) {
+    if (user_database->get_user_info(*users_here, userinfo) == ERRNO_SUCCEED) {
+      textout << outconvert << disp
+	      << "<tr><td bgcolor=\"\\#eeeeee\">" << userinfo.username << "</td>\n"
+       	      << "<td bgcolor=\"\\#eeeeee\">" << (char *) (userinfo.enabled ? "enabled" : "disabled") << "</td>\n"
+	      << "<td bgcolor=\"\\#eeeeee\">" << userinfo.groups << "&nbsp;</td>\n"
+	      << "<td bgcolor=\"\\#eeeeee\">" << userinfo.comment << "&nbsp;</td>\n"
+	      << "<td><a href=\"_httpcurrentdocument_&a=um&uma=edituser&umun="
+	      << userinfo.username << "\">_userslistusers:textedituser_</a> "
+	      << "<a href=\"_httpcurrentdocument_&a=um&uma=deleteuser&umun="
+	      << userinfo.username << "\">_userslistusers:textdeleteuser_</a>"
+	      << "</td></tr>\n\n";
+
+    } else {
+      textout << outconvert << disp
+	      << "<tr><td bgcolor=\"\\#eeeeee\">" << *users_here << "</td>\n"
+	      << "<td bgcolor=\"\\#eeeeee\">&nbsp;</td>\n"
+	      << "<td bgcolor=\"\\#eeeeee\">&nbsp;</td>\n"
+	      << "<td bgcolor=\"\\#eeeeee\">&nbsp;</td>\n"
+	      << "<td>&nbsp;</td></tr>\n\n";
+    }
+    
+    ++users_here;
+  }
+  
+  textout << outconvert << disp
+	  << "_userslistusers:contentend_\n_userslistusers:footer_\n";
+  return true;
+}
+
+void usersaction::define_user_macros (cgiargsclass &args, displayclass &disp) {
+  disp.setmacro ("usersargun", "users", args["umun"]);
+  disp.setmacro ("usersargpw", "users", args["umpw"]);
+  disp.setmacro ("usersargus", "users", args["umus"]);
+  disp.setmacro ("usersargug", "users", args["umug"]);
+  disp.setmacro ("usersargc", "users", args["umc"]);
+}
+
+
+bool usersaction::do_edituser (cgiargsclass &args, displayclass &disp, 
+			       outconvertclass &outconvert, ostream &textout, 
+			       ostream &logout) {
+
+  userinfo_t userinfo;
+  text_t messagestatus;
+  bool noproblems = true;
+  
+  // fill in defaults from user database (if appropriate)
+  if (args["umun"].empty()) {
+    noproblems = false;
+    
+  } else if (!userdbclass::username_ok (args["umun"])) {
+    // problem with username
+    noproblems = false;
+    messagestatus += "_users:messageinvalidusername_";
+    
+  } else if (user_database->get_user_info (args["umun"], userinfo) == ERRNO_SUCCEED) {
+    if (args["uma"] == "adduser") {
+      // must not add a user that has the same name as another user
+      noproblems = false;
+      messagestatus += "_users:messageuserexists_";
+      
+    } else {
+      // only fill in the data if there is no user status defined
+      if (args["umus"].empty()) {
+	args["umus"] = userinfo.enabled ? "enabled" : "disabled";
+	if (args["umug"].empty()) args["umug"] = userinfo.groups;
+	if (args["umc"].empty()) args["umc"] = userinfo.comment;
+      }
+    }
+  }
+
+  // fill in the user status default
+  if (args["umus"].empty()) {
+    noproblems = false;
+    args["umus"] = "enabled";
+  }
+  
+  // make sure the password is ok
+  if (args["umpw"].empty()) {
+    // password must not be empty if none were supplied from database
+    // and we have had no other problems
+    if (userinfo.password.empty() && noproblems) {
+      noproblems = false;
+      messagestatus += "_users:messageemptypassword_";
+    }
+    
+  } else if (!userdbclass::password_ok(args["umpw"])) {
+    noproblems = false;
+    messagestatus += "_users:messageinvalidpassword_";
+  }
+
+  // set this info if no problems have been encounted
+  // and the submit button was pressed
+  if (noproblems && !args["beu"].empty()) {
+    userinfo.username = args["umun"];
+    if (!args["umpw"].empty()) {
+      // only set the password if it is not empty
+      userinfo.password = userdbclass::crypt_text(args["umpw"]);
+    }
+    userinfo.enabled = (args["umus"] == "enabled");    
+    userinfo.groups = userdbclass::format_user_groups(args["umug"]);
+    userinfo.comment = args["umc"];
+    
+    user_database->set_user_info (args["umun"], userinfo);
+    
+    // show list of users
+    return do_listusers (args, disp, outconvert, textout, logout);
+  }
+  
+  // define the macros for the user
+  define_user_macros (args, disp);
+  disp.setmacro ("messagestatus", "users", messagestatus);
+  
+  textout << outconvert << disp
+	  << "_usersedituser:header_\n_usersedituser:content_\n_usersedituser:footer_\n";
+
+  return true;
+}
+
+bool usersaction::do_deleteuser (cgiargsclass &args, displayclass &disp, 
+				 outconvertclass &outconvert, ostream &textout, 
+				 ostream &logout) {
+  if (!args["cm"].empty()) {
+    if (args["cm"] == "yes" && !args["umun"].empty()) {
+      // user confirmed the deletion of the user
+      user_database->delete_user(args["umun"]);
+    }
+    
+    // redirect the user back to the listusers page
+    return do_listusers (args, disp, outconvert, textout, logout);
+  }
+
+  define_user_macros (args, disp);
+  textout << outconvert << disp
+	  << "_usersdeleteuser:header_\n_usersdeleteuser:content_\n_usersdeleteuser:footer_\n";
+  
+  return true;
+}
+
+bool usersaction::do_changepasswd (cgiargsclass &args, displayclass &disp, 
+				   outconvertclass &outconvert, ostream &textout, 
+				   ostream &/*logout*/) {
+  text_t messagestatus;
+  
+  if (!args["bcp"].empty()) {
+    if (args["un"].empty()) {
+      messagestatus = "_users:messageusernameempty_";
+    } else if (args["umpw"].empty()) {
+      messagestatus = "_users:messagepasswordempty_";
+    } else if (args["umnpw1"].empty()) {
+      messagestatus = "_users:messagenewpass1empty_";
+    } else if (args["umnpw2"].empty()) {
+      messagestatus = "_users:messagenewpass2empty_";
+    } else if (args["umnpw1"] != args["umnpw2"]) {
+      messagestatus = "_users:messagenewpassmismatch_";
+    } else if (!userdbclass::password_ok(args["umnpw1"])) {
+      messagestatus = "_users:messageinvalidpassword_";
+    } else {
+      userinfo_t userinfo;
+      if (user_database->get_user_info (args["un"], userinfo) == ERRNO_SUCCEED) {
+	// check old password
+	if (userinfo.password != userdbclass::crypt_text(args["umpw"])) {
+	  messagestatus = "_users:messagefailed_";
+	  
+	} else {
+	  userinfo.password = userdbclass::crypt_text(args["umnpw1"]);
+	  if (user_database->set_user_info (args["un"], userinfo) == ERRNO_SUCCEED) {
+	    // everything is ok
+	    textout << outconvert << disp
+		    << "_userschangepasswdok:header_\n"
+	      "_userschangepasswdok:content_\n"
+	      "_userschangepasswdok:footer_\n";
+	    return true;
+	  }
+	}
+      }
+    }
+  }
+
+  disp.setmacro ("messagestatus", "users", messagestatus);
+
+  textout << outconvert << disp
+	  << "_userschangepasswd:header_\n"
+    "_userschangepasswd:content_\n"
+    "_userschangepasswd:footer_\n";
+
+  return true;
+}
+
+#endif //GSDL_USE_USERS_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/usersaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/usersaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/usersaction.h	(revision 16571)
@@ -0,0 +1,87 @@
+/**********************************************************************
+ *
+ * usersaction.h -- managing users
+ * Copyright (C) 1999  DigiLib Systems Limited, New Zealand
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+#ifdef GSDL_USE_USERS_ACTION
+
+#ifndef USERSACTION_H
+#define USERSACTION_H
+
+#include "gsdlconf.h"
+#include "action.h"
+#include "userdb.h"
+#include "text_t.h"
+
+
+class usersaction : public action {
+protected:
+  userdbclass *user_database;
+
+public:
+  usersaction ();
+  virtual ~usersaction () {}
+
+  void configure (const text_t &key, const text_tarray &cfgline);
+
+  bool init (ostream &logout);
+
+  void set_userdb(userdbclass *udb) {user_database = udb;}
+  
+  text_t get_action_name () {return "um";}
+  
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass *protos, ostream &logout);
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response, text_t &response_data, 
+			 ostream &logout);
+  
+  bool do_action (cgiargsclass &args, recptprotolistclass *protos, 
+		  browsermapclass *browsers, displayclass &disp, 
+		  outconvertclass &outconvert, ostream &textout, 
+		  ostream &logout);
+
+protected:
+  void define_user_macros (cgiargsclass &args, displayclass &disp);
+  
+  bool do_listusers (cgiargsclass &args, displayclass &disp, 
+		     outconvertclass &outconvert, ostream &textout, 
+		     ostream &logout);
+
+  bool do_edituser (cgiargsclass &args, displayclass &disp, 
+		    outconvertclass &outconvert, ostream &textout, 
+		    ostream &logout);
+
+  bool do_deleteuser (cgiargsclass &args, displayclass &disp, 
+		      outconvertclass &outconvert, ostream &textout, 
+		      ostream &logout);
+
+  bool do_changepasswd (cgiargsclass &args, displayclass &disp, 
+			outconvertclass &outconvert, ostream &textout, 
+			ostream &logout);
+};
+
+#endif //!USERSACTION_H
+#endif //GSDL_USE_USERS_ACTION
Index: /gsdl/trunk/runtime-src/src/recpt/vlistbrowserclass.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/vlistbrowserclass.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/vlistbrowserclass.cpp	(revision 16571)
@@ -0,0 +1,463 @@
+/**********************************************************************
+ *
+ * vlistbrowserclass.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "vlistbrowserclass.h"
+#include "OIDtools.h"
+#include "browsetoolsclass.h"
+#include "cgiutils.h"
+
+
+vlistbrowserclass::vlistbrowserclass () {
+}
+
+vlistbrowserclass::~vlistbrowserclass () {
+}
+
+// returns the name that specifies the browserclass type
+text_t vlistbrowserclass::get_browser_name () {
+  return "VList";
+}
+
+browserclass* vlistbrowserclass::clone()
+{
+  vlistbrowserclass* browser = new vlistbrowserclass();
+  if (browser != NULL) {
+#ifdef GSDL_USE_BY_BOOK_MACROS
+    browser->m_oByBookMacros.Copy(m_oByBookMacros);
+#endif
+  }
+  return browser;
+}
+
+void vlistbrowserclass::load_metadata_defaults (text_tset &metadata) {
+  metadata.insert ("haschildren");
+  metadata.insert ("doctype");
+}
+
+text_t vlistbrowserclass::get_default_formatstring () {
+  return "<td valign=\"top\">[link][icon][/link]</td>"
+    "<td valign=\"top\">[srclink]{Or}{[thumbicon],[srcicon]}[/srclink]</td>"
+    "<td valign=\"top\">[highlight]{Or}{[dls.Title],[dc.Title],[Title],Untitled}[/highlight]"
+    "{If}{[Source],<br><i>([Source])</i>}</td>";
+}
+
+bool vlistbrowserclass::show_search_result_links(recptproto * collectproto,const text_t &collection,ostream& logout){
+     ColInfoResponse_t cinfo;
+     comerror_t err;
+     collectproto->get_collectinfo (collection, cinfo, err, logout);
+     bool show_links = false;
+
+     text_tmap::const_iterator format_here = cinfo.format.begin();
+     text_tmap::const_iterator format_end = cinfo.format.end();
+     
+     while (format_here != format_end) {
+       if (((*format_here).first == "DocumentSearchResultLinks") && 
+	   ((*format_here).second == "true")){
+	 show_links = true;
+         break;
+       }
+       ++format_here;
+     } 
+     
+     return show_links;
+}
+
+int vlistbrowserclass::output_section_group(ResultDocInfo_t &section, cgiargsclass &args,
+                                            const text_t &collection, int colnumber, 
+                                            format_t *formatlistptr, bool use_table, 
+                                            text_tset &metadata, bool &getParents, 
+                                            recptproto * collectproto, displayclass &disp, 
+                                            outconvertclass &outconvert, ostream &textout, 
+                                            ostream& logout)
+{
+  browsetoolsclass btools;
+  text_t link, icon;
+  text_t collink = collection;
+  bool show_links = show_search_result_links(collectproto,collection,logout);
+
+
+#ifndef DOCHANDLE
+  if (!collink.empty()) collink = "&amp;c=" + collink;
+#endif
+
+  get_link_icon (section, args, collink, link, icon, show_links);
+
+  //get_link_icon (section, args, collink, link, icon);
+
+  bool highlight = false;
+  if (!args["d"].empty()) {
+    if (args["d"] == section.OID) highlight = true;
+  } else 
+    if (args["cl"] == section.OID) highlight = true;
+
+
+  /* use_table is set to true if the format string starts with <td> */
+  if (use_table || colnumber > 0) {
+    if (colnumber > 0 ){
+      textout << outconvert << "<table  class=\"v_list\"><tr valign=\"top\">";
+    }
+    else{
+      textout << outconvert << "<table id=\"toc_top\" class=\"v_list\"><tr valign=\"top\">";
+    }
+
+    // get tab size
+    text_t tab; int itab;
+    disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
+    itab = tab.getint();
+    if (colnumber > 0) textout << outconvert << disp 
+			       << "<td><img alt=\"\" src=\"_httpimg_/space.gif\" width=\"" 
+			       << (itab*colnumber) << "\"/></td>";
+  } else {
+    textout << outconvert << "<div class=\"v_list\">\n";
+  }
+
+  text_tmap options;
+  options["link"] = link;
+  options["icon"] = icon;
+  if (highlight) options["highlight"] = "1";
+  else options["highlight"] = "0";
+  options["DocImage"] = btools.get_cover_image();
+  textout << outconvert << disp 
+	  << get_formatted_string (collection, collectproto, 
+				   section, disp, formatlistptr, 
+				   options, logout);
+  
+  if (use_table  || colnumber > 0) {
+    textout << outconvert << "</tr></table>\n";
+  } else {
+    textout << outconvert << "</div>\n";
+  }
+
+  return 1;
+}
+
+int vlistbrowserclass::output_section_group(FilterResponse_t &sections, cgiargsclass &args,
+                                            const text_t &collection, int colnumber, 
+                                            format_t *formatlistptr, bool use_table, 
+                                            text_tset &/*metadata*/, bool &/*getParents*/, 
+                                            recptproto * collectproto, displayclass &disp, 
+                                            outconvertclass &outconvert, ostream &textout, 
+                                            ostream& logout)
+{
+  browsetoolsclass btools;
+  text_t link, icon;
+  text_t &arg_d = args["d"];
+  text_t &arg_cl = args["cl"];
+  
+  text_t collink = collection;
+  bool show_links = show_search_result_links(collectproto,collection,logout);
+
+#ifndef DOCHANDLE
+  if (!collink.empty()) collink = "&amp;c=" + collink;
+#endif
+
+  if (colnumber > 0) {
+    textout << outconvert << "<table><tr valign=\"top\">";
+    // get tab size
+    text_t tab; int itab;
+    disp.expandstring (displayclass::defaultpackage, "_tabwidth_", tab);
+    itab = tab.getint();
+    if (colnumber > 0) textout << outconvert << disp 
+			       << "<td><img alt=\"\" src=\"_httpimg_/space.gif\" width=\"" 
+			       << (itab*colnumber) << "\"/></td>";
+    textout << outconvert << "<td>";
+  }
+
+  /* use table set to true if format string starts with <td> */
+  if (use_table) {
+    textout << outconvert << "<table class=\"v_list\">\n";
+  } else {
+    textout << outconvert << "<div class=\"v_list\">\n";
+  }
+
+  ResultDocInfo_tarray::iterator thissection = sections.docInfo.begin();
+  ResultDocInfo_tarray::iterator endsection = sections.docInfo.end();
+
+  // ** here lies Alan's hack to get 4 results per table row
+  int item = 0, perline; // set perline to 1 normally
+  text_t fstring;
+
+  text_tmap options;
+  options["link"] = link;
+  options["icon"] = icon;
+  options["highlight"] = "0";
+  options["DocImage"] = btools.get_cover_image();
+  
+  if ( thissection != endsection ) { // only if there are results (else corrupts display)
+    fstring = get_formatted_string (collection, collectproto, *thissection,
+                                    disp, formatlistptr, options, logout);
+    // if format string
+    // has <td><t (e.g. <td><table>) then
+    // we assume it is an image and put it in 4 columns
+    if (fstring[5] == 't') 
+      perline = 4;
+    else
+      perline = 1;
+  }
+
+  int count = 0; 
+
+  while (thissection != endsection) {
+    ++item;
+    get_link_icon (*thissection, args, collink, link, icon,show_links);
+    //get_link_icon (*thissection, args, collink, link, icon);
+    bool highlight = false;
+    if (!arg_d.empty()) {
+      if (arg_d == (*thissection).OID) highlight = true;
+    } else 
+      if (arg_cl == (*thissection).OID) highlight = true;
+
+    if ((item == 1 && use_table) || colnumber > 0 )
+      textout << outconvert << "<tr valign=top>\n";
+
+    options["link"] = link;
+    options["icon"] = icon;
+    if (highlight) options["highlight"] = "1";
+    else options["highlight"] = "0";
+    options["DocImage"] = btools.get_cover_image();
+    
+    textout << outconvert << disp 
+	    << " " << get_formatted_string (collection, collectproto, *thissection, disp,
+					    formatlistptr, options, logout);
+
+    if ((item >= perline && use_table) || colnumber > 0) {
+      textout << outconvert << "\n</tr>";
+      item = 0;
+    }
+    textout << outconvert << "\n";
+    ++thissection;
+  }
+
+  if (use_table)
+    textout << outconvert << "</table>\n";
+  else
+    textout << outconvert << "</div>\n";
+  if (colnumber > 0) textout << outconvert << "</td></tr></table>\n";
+
+  return 1;
+}
+
+
+// get_link_icon attempts to work out what type of icon should be displayed for
+// the given section and what it should link to.
+// [modification to allow default document detach settings -- kjdon]
+void vlistbrowserclass::get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
+				       const text_t &collink, text_t &link, text_t &icon, bool showresultlinks) {
+
+ 
+
+#ifndef DOCHANDLE
+  link = "<a href=\"_httpdocument_" + collink;
+#else
+  link = "<a href=\"_httpdocumenthandle_(" + collink;
+#endif
+
+  text_t link_end = "\">";
+
+#ifndef DOCHANDLE
+  text_t detach_link_end = "&amp;x=1\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
+#else
+  text_t detach_link_end = "\" target=\\_blank>"; // to detach the link, and x=1 signifies it is a detached page
+#endif
+
+  icon = "_document:icontext_";
+
+  text_t doctype;
+  int haschildren = 0;
+
+  if (section.metadata.count("haschildren")>0)
+    haschildren = section.metadata["haschildren"].values[0].getint();
+  if (section.metadata.count("doctype")>0)
+    doctype = section.metadata["doctype"].values[0];
+
+  text_t &arg_d = args["d"];
+  text_t &arg_cl = args["cl"];
+
+  if (args["a"] == "q")
+  {
+    // query results list
+#ifndef DOCHANDLE
+    int result_num = section.result_num;
+    int num_docs = args["nmd"].getint();
+    int srn = 0;
+    int srp = 0;
+    if (showresultlinks && result_num < num_docs) {
+      srn = result_num  + 1;
+    }    
+    if (showresultlinks && result_num > 1 ) {
+      srp = result_num  - 1;
+    }    
+        
+    text_t srp_t = srp; 
+    text_t srn_t = srn; 
+    link +="&amp;srp="+srp_t;
+    link +="&amp;srn="+srn_t;
+    link +="&amp;cl=search&amp;d=" + section.OID;
+#else
+    link += "," + section.OID+")";
+#endif
+ 
+    if (args["xx"] == "1") {
+      link += detach_link_end;
+    }
+    else {
+      link += link_end;
+    }
+    if ((is_top (section.OID)) && (haschildren == 1)) icon = "_document:iconclosedbook_";
+    else if (haschildren == 1) icon = "_document:iconclosedfolder_";  
+  }
+  else if (!arg_d.empty()) {
+    // we are in a document - none of the links should be detach links
+    if (is_top(section.OID)) {
+      // we link back to the originating page eg search page or classifier page
+      icon = "_document:iconopenbook_";
+      if (arg_cl == "search") { 
+	link = "<a href=\"_httpquery_\">";
+      }
+      else {
+#ifndef DOCHANDLE
+	link += "&amp;cl=" + arg_cl + "\">";
+#else
+	link += ","+arg_cl + ")\">";
+#endif
+      }
+    }
+    else if (haschildren == 1) {
+      if ((args["gc"] == "1") || 
+	  (is_child_of (section.OID, arg_d)) ||
+	  (section.OID == arg_d)) {
+	icon = "_document:iconopenfolder_";
+#ifndef DOCHANDLE
+	link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + ".pr\">";
+#else
+	link += ","+section.OID + ".pr)\">";
+#endif
+      }
+      else {
+	icon = "_document:iconclosedfolder_";
+#ifndef DOCHANDLE
+	link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
+#else
+	link += ","+section.OID + ")\">";
+#endif
+      }
+    }
+    else {
+      if (args["gt"] == "0") {
+#ifndef DOCHANDLE
+	link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "\">";
+#else
+	link += ","+section.OID + ")\">";
+#endif
+      }
+      else {
+#ifndef DOCHANDLE
+	link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID + "#" + section.OID + "\">";
+#else
+	link += ","+section.OID + "#" + section.OID + ")\">";
+#endif
+      }
+    }
+  }
+  else {
+    // classification level - links to docs may be detaching
+    if (haschildren == 1) {
+      if (doctype == "classify") {
+	// Dynamic classifier nodes
+	if (args["a"] == "dc")
+	{
+	  // Parent node or current node
+	  text_t classifier_node_dcn = "";
+	  if (!starts_with (section.OID, args["dcn"]) || section.OID == args["dcn"])
+	  {
+	    icon = "_document:iconopenbookshelf_";
+	    classifier_node_dcn = section.OID + ".pr";
+	  }
+	  // Child node
+	  else
+	  {
+	    icon = "_document:iconclosedbookshelf_";
+	    classifier_node_dcn = section.OID;
+	  }
+
+	  // The node label is going into the URL, so make it CGI-safe
+	  text_t classifier_node_dcn_cgi_safe = cgi_safe_utf8(classifier_node_dcn);
+	  link = "<a href=\"_gwcgi_?c=" + args["c"] + "&amp;a=dc&amp;dcl=" + args["dcl"] + "&amp;dcn=" + classifier_node_dcn_cgi_safe + "\">";
+	}
+	// Static classifier nodes
+	else if ((args["gc"] == "1") || 
+	    (is_child_of (section.OID, arg_cl)) || 
+	    (section.OID == arg_cl)) {
+	  icon = "_document:iconopenbookshelf_";
+
+#ifndef DOCHANDLE
+	  link += "&amp;cl=" + section.OID + ".pr\">";
+#else
+	  link += ","+section.OID + ".pr)\">";
+#endif
+	}
+	else {
+	  icon = "_document:iconclosedbookshelf_";
+
+#ifndef DOCHANDLE
+	  link += "&amp;cl=" + section.OID + "\">";
+#else
+	  link += ","+section.OID + ")\">";
+#endif
+	}
+      }
+      else {
+	icon = "_document:iconclosedbook_";
+#ifndef DOCHANDLE
+	link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
+#else
+	link += ","+section.OID+")";
+#endif
+	if (args["xx"] == "1") {
+	  link +=  detach_link_end;
+	}
+	else {
+	  link += link_end;
+	}
+      }
+    }
+    else {
+      if (doctype == "classify") link = "";
+      else {
+#ifndef DOCHANDLE
+	link += "&amp;cl=" + arg_cl + "&amp;d=" + section.OID;
+#else
+	link += "," + section.OID +")";
+#endif
+	if (args["xx"] == "1") {
+	  link +=  detach_link_end;
+	}
+	else {
+	  link += link_end;
+	}
+      }
+    }
+  }
+}
Index: /gsdl/trunk/runtime-src/src/recpt/vlistbrowserclass.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/vlistbrowserclass.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/vlistbrowserclass.h	(revision 16571)
@@ -0,0 +1,73 @@
+/**********************************************************************
+ *
+ * vlistbrowserclass.h -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef VLISTBROWSERCLASS_H
+#define VLISTBROWSERCLASS_H
+
+#include "browserclass.h"
+#include "receptionist.h"
+
+class vlistbrowserclass : public browserclass {
+protected:
+
+public:
+  vlistbrowserclass ();
+  virtual ~vlistbrowserclass ();
+
+  void set_receptionist(receptionist *therecpt) {recpt=therecpt;}
+
+  text_t get_browser_name ();
+
+  virtual browserclass* clone();
+
+  virtual void load_metadata_defaults (text_tset &metadata);
+
+  virtual text_t get_default_formatstring ();
+
+  virtual int output_section_group (ResultDocInfo_t &section, cgiargsclass &args,
+				    const text_t &collection, int colnumber, format_t *formatlistptr, 
+				    bool use_table, text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, ostream &logout);
+
+  virtual int output_section_group (FilterResponse_t &sections, cgiargsclass &args,
+				    const text_t &collection, int colnumber, format_t *formatlistptr, 
+				    bool use_table, text_tset &metadata, bool &getParents,
+				    recptproto *collectproto, displayclass &disp, 
+				    outconvertclass &outconvert, ostream &textout, ostream &logout);
+
+protected:
+
+ 
+  virtual void get_link_icon (ResultDocInfo_t &section, cgiargsclass &args,
+			     const text_t &collink, text_t &link, text_t &icon, bool showresultlinks);
+
+  virtual bool show_search_result_links (recptproto * collectproto,const text_t &collection,ostream& logout);
+
+  receptionist *recpt;
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/recpt/win32.mak
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/win32.mak	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/win32.mak	(revision 16571)
@@ -0,0 +1,251 @@
+###########################################################################
+#
+# win32 makefile -- src/recpt
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ..\..
+INDEXERS_DIR = $(GSDL_DIR)\indexers
+PACKAGES_DIR = $(GSDL_DIR)\packages
+COLSERVR_DIR = $(GSDL_DIR)\src\colservr
+PROTOCOL_DIR = $(GSDL_DIR)\src\protocol
+Z3950_DIR = $(GSDL_DIR)\src\z3950
+
+
+GSDL_VC4 = 0
+LOCAL_LIBRARY = 0
+USE_Z3950 = 0
+DLL = 0
+DLLDEBUG = 0
+ENABLE_ACCENTFOLD = 1
+USE_SQLITE = 0
+
+
+!IF $(GSDL_VC4)
+CPPFLAGS = -GX
+!ELSE
+CPPFLAGS = -EHsc
+!ENDIF
+
+!IF $(DLL)
+CPPFLAGS = $(CPPFLAGS) -MD
+!ELSE
+!IF ($(DLLDEBUG))
+CPPFLAGS = $(CPPFLAGS) -MDd
+!ENDIF
+!ENDIF
+
+!IF $(ENABLE_ACCENTFOLD)
+ACCENTFOLD_LIBS = "$(INDEXERS_DIR)\packages\unac\libunac.lib" "$(INDEXERS_DIR)\packages\unac\iconv.lib"
+!ELSE
+ACCENTFOLD_LIBS = 
+!ENDIF
+
+!IF $(USE_SQLITE)
+SQLITE_LIBS = "$(PACKAGES_DIR)\sqlite\lib\sqlite3.lib"
+!ELSE
+SQLITE_LIBS = 
+!ENDIF
+
+!IF $(USE_Z3950)
+Z3950_DEFS = -DUSE_Z3950
+Z3950_INCLUDES = -I$(Z3950_DIR)
+Z3950_LIBS = $(Z3950_DIR)\gsdlz3950.lib $(PACKAGES_DIR)\yaz\yaz-2.1.4\lib\yaz.lib
+!ELSE
+Z3950_DEFS = 
+Z3950_INCLUDES = 
+Z3950_LIBS = 
+!ENDIF
+
+
+AR = lib
+CC = cl
+DEFS = -D__WIN32__ -DHAVE_CONFIG_H -DPARADOCNUM -D_LITTLE_ENDIAN -DSHORT_SUFFIX -D_CRT_SECURE_NO_DEPRECATE \
+        -DGSDL_NOCACHE $(Z3950_DEFS)
+INCLUDES = -I. -I"$(GSDL_DIR)" -I"$(GSDL_DIR)\src\lib" -I"$(COLSERVR_DIR)" -I"$(PROTOCOL_DIR)" \
+	-I"$(INDEXERS_DIR)\mg" -I"$(INDEXERS_DIR)\mg\lib" -I"$(INDEXERS_DIR)\mgpp\text" \
+	-I"$(PACKAGES_DIR)\windows\crypt\crypt" -I"$(PACKAGES_DIR)\windows\expat\expat" \
+	-I"$(PACKAGES_DIR)\windows\gdbm\gdbm" $(Z3950_INCLUDES)
+LDFLAGS = 
+LIBS = "$(PACKAGES_DIR)\windows\crypt\crypt\crypt.lib" "$(PACKAGES_DIR)\windows\expat\expat\libexpat.lib" \
+        "$(PACKAGES_DIR)\windows\gdbm\gdbm\gdbm.lib" $(ACCENTFOLD_LIBS) $(SQLITE_LIBS) $(Z3950_LIBS)
+
+!IF $(GSDL_VC4)
+DEFS = $(DEFS) -DGSDL_NAMESPACE_BROKEN -DGSDL_USE_IOS_H -D__STL_NO_NEW_IOSTREAMS
+INCLUDES = $(INCLUDES) -I"$(PACKAGES_DIR)\windows\stlport\stlport"
+!ENDIF
+!IF $(LOCAL_LIBRARY)
+DEFS = $(DEFS) -DGSDL_LOCAL_LIBRARY
+!ENDIF
+
+
+COMPILE = $(CC) -nologo -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+LINK = $(CC) -nologo -Fe"$@" $(LDFLAGS)
+
+
+.SUFFIXES:
+.SUFFIXES: .cpp .obj
+.cpp.obj:
+	$(COMPILE) $< 
+
+
+SOURCES = \
+	action.cpp \
+	argdb.cpp \
+	authenaction.cpp \
+	browseaction.cpp \
+	browseactiontools.cpp \
+	browserclass.cpp \
+	browsetoolsclass.cpp \
+	cgiargs.cpp \
+	cgiutils.cpp \
+	cgiwrapper.cpp \
+	collectoraction.cpp \
+	configaction.cpp \
+        converter.cpp \
+	datelistbrowserclass.cpp \
+	depositoraction.cpp \
+	documentaction.cpp \
+	dynamicclassifieraction.cpp \
+	extlinkaction.cpp \
+	formattools.cpp \
+	gtiaction.cpp \
+	highlighttext.cpp \
+	historydb.cpp \
+	hlistbrowserclass.cpp \
+	htmlbrowserclass.cpp \
+	htmlutils.cpp \
+	invbrowserclass.cpp \
+	librarymain.cpp \
+	maincfg.cpp \
+	pageaction.cpp \
+	pagedbrowserclass.cpp \
+	phindaction.cpp \
+	phindbrowserclass.cpp \
+	pingaction.cpp \
+	queryaction.cpp \
+	querytools.cpp \
+	receptionist.cpp \
+	statusaction.cpp \
+	summarise.cpp \
+	tipaction.cpp \
+	userdb.cpp \
+	usersaction.cpp \
+	vlistbrowserclass.cpp \
+	wizardaction.cpp
+
+OBJECTS = \
+	action.obj \
+	argdb.obj \
+	authenaction.obj \
+	browseaction.obj \
+	browseactiontools.obj \
+	browserclass.obj \
+	browsetoolsclass.obj \
+	cgiargs.obj \
+	cgiutils.obj \
+	cgiwrapper.obj \
+	collectoraction.obj \
+	configaction.obj \
+        converter.obj \
+	datelistbrowserclass.obj \
+	depositoraction.obj \
+	documentaction.obj \
+	dynamicclassifieraction.obj \
+	extlinkaction.obj \
+	formattools.obj \
+	gtiaction.obj \
+	highlighttext.obj \
+	historydb.obj \
+	hlistbrowserclass.obj \
+	htmlbrowserclass.obj \
+	htmlutils.obj \
+	invbrowserclass.obj \
+	librarymain.obj \
+	maincfg.obj \
+	pageaction.obj \
+	pagedbrowserclass.obj \
+	phindaction.obj \
+	phindbrowserclass.obj \
+	pingaction.obj \
+	queryaction.obj \
+	querytools.obj \
+	receptionist.obj \
+	statusaction.obj \
+	summarise.obj \
+	tipaction.obj \
+	userdb.obj \
+	usersaction.obj \
+	vlistbrowserclass.obj \
+	wizardaction.obj
+
+LIBRARY = gsdlrecpt.lib
+
+GSDL_LIBS = \
+	"$(PROTOCOL_DIR)\gsdlprotocol.lib" \
+	"$(COLSERVR_DIR)\gsdlcolservr.lib" \
+	"$(INDEXERS_DIR)\mg\src\text\libmgtext.lib" \
+	"$(INDEXERS_DIR)\mg\lib\libmglib.lib" \
+	"$(INDEXERS_DIR)\mgpp\text\libmgpptext.lib" \
+	"$(INDEXERS_DIR)\mgpp\lib\libmgpplib.lib" \
+	"$(GSDL_DIR)\src\lib\gsdllib.lib"
+
+EXECUTABLE_OBJECTS = \
+	$(OBJECTS) \
+	$(GSDL_LIBS)
+
+EXECUTABLE = library.exe
+
+
+# Default target: make gsdlrecpt.lib if LOCAL_LIBRARY is set, otherwise both gsdlrecpt.lib and library.exe
+!IF $(LOCAL_LIBRARY)
+all: $(LIBRARY)
+!ELSE
+all: $(LIBRARY) $(EXECUTABLE)
+!ENDIF
+
+gsdlrecpt.lib: $(OBJECTS) 
+	if EXIST $(LIBRARY) del $(LIBRARY)
+	$(AR) -nologo /out:$(LIBRARY) $(OBJECTS)
+
+library.exe: $(EXECUTABLE_OBJECTS)
+	$(LINK) $(EXECUTABLE_OBJECTS) $(LIBS)
+
+!IF $(LOCAL_LIBRARY)
+install:
+!ELSE
+install: $(EXECUTABLE)
+	copy $(EXECUTABLE) "$(GSDL_DIR)\cgi-bin"
+!ENDIF
+
+clean:
+	del *.obj
+	del $(LIBRARY)
+	del $(EXECUTABLE)
+
+
+# Always recompile configaction and statusaction in case GSDL_LOCAL_LIBRARY has changed
+statusaction.obj: FORCE
+configaction.obj: FORCE
+
+FORCE:
Index: /gsdl/trunk/runtime-src/src/recpt/wizardaction.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/wizardaction.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/wizardaction.cpp	(revision 16571)
@@ -0,0 +1,772 @@
+/**********************************************************************
+ *
+ * wizardaction.cpp -- 
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+
+// note that the wizardaction relies on having direct access to a
+// collections configuration file. this breaks the separation between
+// receptionist and collection server and so is not suitable (at least
+// in its current form) for use when collection servers are separate 
+// from the receptionist (e.g. when using the CORBA protocol).
+
+// following line required to get fstream.filedesc() on darwin (Mac OS X)
+#define _STREAM_COMPAT  1
+// required for utsname on solaris???
+#define _XOPEN_SOURCE 1
+#define _XOPEN_SOURCE_EXTENDED 1
+
+#include "wizardaction.h"
+#include "OIDtools.h"
+#include "fileutil.h"
+#include "cfgread.h"
+#include "gsdltools.h"
+#include "gsdltimes.h"
+#include "argdb.h"
+#include "cgiutils.h"
+#include <stdio.h>
+#include <fcntl.h>
+
+#if !defined (__WIN32__)
+#include <sys/utsname.h>
+#include <unistd.h>
+#endif
+
+wizardaction::wizardaction () {
+
+  recpt = NULL;
+  disabled = true;
+  gsdlosc = NULL;
+  gsdlhomec = NULL;
+  pathc = NULL;
+
+  macro_prefix = "";
+}
+
+wizardaction::~wizardaction () {
+  if (gsdlosc != NULL) delete []gsdlosc;
+  if (gsdlhomec != NULL) delete []gsdlhomec;
+  if (pathc != NULL) delete []pathc;
+}
+
+void wizardaction::configure (const text_t &key, const text_tarray &cfgline) {
+  
+  const text_t& action_name = get_action_name();
+
+  if ((key == action_name) && (cfgline.size() == 1) && 
+      (cfgline[0] == "true" || cfgline[0] == "on" || cfgline[0] == "enabled")) {
+    disabled = false;
+  } else {
+    // call the parent class to deal with the things which
+    // are not dealt with here
+    action::configure (key, cfgline);
+  }
+}
+
+
+bool wizardaction::init (ostream & /*logout*/) {
+
+  // set up GSDLOS, GSDLHOME and PATH environment variables
+  text_t gsdlos, path;
+  unsigned int path_separator = ':';
+#if defined (__WIN32__)
+  gsdlos = "windows";
+  path_separator = ';';
+
+  path = filename_cat (gsdlhome, "bin", "windows", "perl", "bin;");
+
+#else
+  struct utsname *buf = new struct utsname();
+  int i = uname (buf);
+  if (i == -1) gsdlos = "linux"; // uname failed
+  else gsdlos.setcstr (buf->sysname);
+  delete buf;
+  lc (gsdlos);
+#endif
+
+  pathc = getenv ("PATH");
+  path += filename_cat (gsdlhome, "bin", gsdlos);
+  path.push_back (path_separator);
+  path += filename_cat (gsdlhome, "bin", "script");
+  if (pathc != NULL) {
+    path.push_back (path_separator);
+    path += pathc;
+  }
+  path = "PATH=" + path;
+
+  gsdlos = "GSDLOS=" + gsdlos;
+  text_t setgsdlhome = "GSDLHOME=" + gsdlhome;
+
+  // these will be cleaned up in the destructor
+  gsdlosc = gsdlos.getcstr();
+  gsdlhomec = setgsdlhome.getcstr();
+  pathc = path.getcstr();
+  
+  putenv (gsdlosc);
+  putenv (gsdlhomec);
+  putenv (pathc);
+
+  return true;
+}
+
+
+void wizardaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
+					response_t &response,text_t &response_data, 
+					ostream &/*logout*/) {
+  response = content;
+  response_data = "text/html";
+}
+
+
+bool wizardaction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+				     recptprotolistclass * /*protos*/, ostream &logout) {
+  
+  text_t current_page = args["p"];
+
+  if (current_page != "intro" && 
+      current_page != "bildframe1" && current_page != "new" && current_page != "select") {
+    // update arguments that were saved to the harddrive
+    text_tmap saved_args;
+    
+    // update the argdb database with any arguments that were set
+    // by previous page as denoted by prefix (eg. di1 or bc1)
+
+    cgiargsclass::const_iterator args_here = args.begin();
+    cgiargsclass::const_iterator args_end = args.end();
+
+    while (args_here != args_end) {
+      text_t args_name = (*args_here).first;
+      
+      int prefix_len = macro_prefix.size();
+      
+      text_t args_prefix = substr(args_name.begin(),args_name.begin()+prefix_len);
+      
+      if (args_prefix == macro_prefix) {
+	saved_args[args_name] = args[args_name];
+      }	
+      ++args_here;
+    }
+      
+    text_t argfile = filename_cat(gsdlhome, "tmp", args[macro_prefix+"tmp"], "argdb.db");
+    argdb *args_on_disk = new argdb(argfile);
+    if (!args_on_disk->update_args(saved_args)) {
+      // error
+      logout << "wizardaction: argdb::update_args failed (" << argfile << ")\n";
+    }
+    
+    // update args from argdb
+    saved_args.erase(saved_args.begin(), saved_args.end());
+    if (!args_on_disk->get_args(saved_args)) {
+      // error
+      logout << "wizardaction: argdb::get_args failed (" << argfile << ")\n";
+    }
+    delete args_on_disk;
+    
+    text_tmap::iterator sa_here = saved_args.begin();
+    text_tmap::iterator sa_end = saved_args.end();
+    while (sa_here != sa_end) {
+      if (!(*sa_here).second.empty()) {
+	args[(*sa_here).first] = (*sa_here).second;
+      }
+      ++sa_here;
+    }  bool first = true;
+
+  }
+
+  return true;
+}
+
+// tests if collection is write protected (currently just checks if
+// collect.cfg file is writable
+bool wizardaction::collection_protected (const text_t &collection) {
+  text_t cfgfile = filename_cat(collecthome, collection, "etc", "collect.cfg");
+  if (file_writable(cfgfile)) return false;
+  return true;
+}
+
+// set the _statusline_ macro
+void wizardaction::set_statusline (displayclass &disp, cgiargsclass &args, ostream & /*logout*/) {
+
+  // the build command creates .bld.download, .bld.import, and .bld.build files (in that
+  // order) and deletes them (also in that order) when each stage is complete. the .bld
+  // file is the concatenation of all these files.
+  text_t bld_file = filename_cat (gsdlhome, "tmp", args[macro_prefix+"tmp"], args[macro_prefix+"dirname"] + ".bld");
+  text_t statusline;
+
+  if (file_exists (bld_file + ".download")) {
+    statusline = "_collector:textdownloadingfiles_<br>\n";
+    statusline += dm_safe(file_tail(bld_file + ".download", 1, 0));
+  } else if (file_exists (bld_file + ".import")) {
+    statusline = "_collector:textimportingcollection_<br>\n";
+    statusline += dm_safe(file_tail(bld_file + ".import", 1, 0));
+  } else if (file_exists (bld_file + ".build")) {
+    statusline = "_collector:textbuildingcollection_<br>\n";
+    statusline += dm_safe(file_tail(bld_file + ".build", 1, 0));
+  } else {
+    statusline += "_collector:textcreatingcollection_<br>\n";
+    statusline += dm_safe(file_tail(bld_file, 1, 0));
+  }
+
+  disp.setmacro ("statusline", "collector", statusline);
+  disp.setmacro ("statusline", "depositor", statusline); 
+}
+
+
+// if sw = 0 replace all carriage returns in intext with the string "\n"
+// else replace all occurances of "\n" with a carriage return
+text_t wizardaction::carriage_replace (const text_t &intext, int sw) {
+   
+  text_t outtext;
+  text_t::const_iterator here = intext.begin();
+  text_t::const_iterator end = intext.end();
+  while (here != end) {
+    if (sw == 0) {
+      if (*here == '\n') {
+	if ((here+1) != end && *(here+1) == '\r') ++here;
+	outtext += "\\n";
+      } else if (*here == '\r') {
+	if ((here+1) != end && *(here+1) == '\n') ++here;
+	outtext += "\\n";
+      } else {
+	outtext.push_back (*here);
+      }
+    } else if (*here == '\\' && (here+1) != end && *(here+1) == 'n') {
+      outtext.push_back ('\n');
+      ++here;
+    } else {
+      outtext.push_back (*here);
+    }
+    ++here;
+  }
+  return outtext;
+}
+
+
+// create a short directory name from fullname
+text_t wizardaction::get_directory_name (const text_t &fullname) {
+
+  text_t shortname;
+  if (fullname.empty()) {
+    shortname = "coll";
+
+  } else {
+    
+    // first make all lowercase and remove any dodgy characters
+    // (i.e. anything not [a-z]
+    text_t::const_iterator here = fullname.begin();
+    text_t::const_iterator end = fullname.end();
+    while (here != end) {
+      if ((*here >= 'A' && *here <= 'Z') || (*here >= 'a' && *here <= 'z') ||
+	  (*here == ' ')) {
+	if (*here >= 'A' && *here <= 'Z') shortname.push_back (*here+32);
+	else if (*here == ' ') {
+	  while ((*(here+1)) == ' ') ++here;
+	  shortname.push_back (*here);
+	} else shortname.push_back (*here);
+      }
+      ++here;
+    }
+
+    text_tarray words;
+    splitchar (shortname.begin(), shortname.end(), ' ', words);
+    int num_words = words.size();
+
+    if (num_words == 0) {
+      shortname = "coll";
+
+    } else {
+
+      shortname.clear();
+      int use_words = (num_words <= 6) ? num_words : 6;
+      unsigned int substr_len = 6 / use_words;
+      
+      for (int i = 0; i < use_words; ++i) {
+	if (words[i].size() < substr_len) shortname += words[i];
+	else shortname += substr (words[i].begin(), words[i].begin()+substr_len);
+      }
+    }
+  }
+
+  // check to see if shortname is unique
+  text_t fulldirname = filename_cat (collecthome, shortname);
+  if (directory_exists (fulldirname)) {
+    int version = 0;
+    text_t newname;
+    do {
+      ++version;
+      newname = shortname;
+      newname.push_back ('v');
+      newname.appendint (version);
+      fulldirname = filename_cat (collecthome, newname);
+    } while (directory_exists (fulldirname));
+
+    shortname = newname;
+  }
+  
+  return shortname;
+}
+
+// assigns a temporary directory name for this collector session
+// and creates temporary directory
+// returns false if it couldn't create the directory
+bool wizardaction::assign_tmpname (cgiargsclass &args, ostream &logout) {
+
+  int i = 0;
+  text_t tmpname = "tbuild";
+  while (directory_exists (filename_cat (gsdlhome, "tmp", tmpname + text_t(i)))) {
+    ++i;
+  }
+  tmpname.appendint (i);
+
+  text_t fulltmpdir = filename_cat (gsdlhome, "tmp", tmpname);
+  if (!mk_dir (fulltmpdir)) {
+    outconvertclass text_t2ascii;
+    logout << text_t2ascii << "wizardaction::assign_tmpname unable to create directory ("
+	   << fulltmpdir << ")\n";
+    return false;
+  }
+
+  args[macro_prefix + "tmp"] = tmpname;
+  return true;
+}
+
+// set the _fullnamemenu_ macro (and _warnindex_ and _selectedindex_ if
+// we're on the "srce" page)
+void wizardaction::set_fullnamemenu (displayclass &disp, cgiargsclass &args, 
+					recptprotolistclass *protos, ostream &logout) {
+
+  if (recpt == NULL) {
+    logout << "ERROR (wizardaction::set_fullnamemenu): This action does not contain\n"
+	   << "       information about any receptionists. The method set_receptionist was\n"
+	   << "       probably not called from the module which instantiated this action.\n";
+    return;
+  }
+
+  text_t &current_page = args["p"];
+  text_t currentname = args[macro_prefix+"dirname"];
+  if (current_page == "srce") currentname = args[macro_prefix + "clonecol"];
+
+  text_tarray dirnames;
+  text_tarray fullnames;
+  vector<bool> write_protected;
+  text_tarray  build_type;
+
+  bool is_selected = false;
+  int selected_index = 0;
+  int index = 0;
+
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    if ((*rprotolist_here).p != NULL) {
+
+      // don't include z39.50 collections
+      comerror_t err = noError;
+      if ((*rprotolist_here).p->get_protocol_name (err) == "z3950proto") {
+	++rprotolist_here;
+	continue;
+      }
+
+      text_tarray collist;
+      (*rprotolist_here).p->get_collection_list (collist, err, logout);
+      if (err == noError) {
+	text_tarray::iterator collist_here = collist.begin();
+	text_tarray::iterator collist_end = collist.end();
+	while (collist_here != collist_end) {
+	  ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout);
+	  if (cinfo != NULL) {
+	    text_t collectionname = cinfo->get_collectionmeta("collectionname", args["l"]);
+	    if (collectionname.empty()) {
+	      collectionname = *collist_here;
+	    }
+	    dirnames.push_back(*collist_here);
+	    fullnames.push_back(collectionname);
+	    // check to see if the collection is writable
+	    if (collection_protected (*collist_here)) write_protected.push_back(true);
+	    else write_protected.push_back(false);
+
+	    // remember build type for collection (mg, mgpp, lucene, ...)
+	    // used to determine cgi arg 'ct' later on and minus option to 'build'
+	    build_type.push_back(cinfo->buildType);
+
+	    if (*collist_here == currentname) {
+	      is_selected = true;
+	      selected_index = index; 	    
+	    }
+	    ++index;
+	  }
+	  ++collist_here;
+	}
+      }
+    }
+    ++rprotolist_here;
+  }
+
+  bool first = true;
+
+  text_t warnindex;
+  text_t fullnamemenu = "<select name=\""+macro_prefix+"dirname\" onChange=\"menuchange();\">\n";
+  text_t buildtype_jsarray = "var buildtype = new Array(";
+
+  fullnamemenu += "<option value=\"\">select collection ...</option>\n";
+  buildtype_jsarray += "\"\" ";
+
+  for (int i = 0; i < index; ++i) {
+    // don't want write protected collections in list on "change existing
+    // collection" page
+    if (write_protected[i] && current_page == "existing") continue;
+    fullnamemenu += "<option value=\"" + dirnames[i] + "\"";
+    if (is_selected && i == selected_index) {
+      fullnamemenu += " selected";
+      ++selected_index;
+      is_selected = false;
+    }
+    fullnamemenu.push_back ('>');
+    fullnamemenu += fullnames[i] + " ("+dirnames[i]+")";
+    fullnamemenu.push_back ('\n');
+
+    buildtype_jsarray += ", \"" + build_type[i] + "\"";
+    
+    first = false;
+  }
+  fullnamemenu += "</select>\n";
+
+  buildtype_jsarray += ");";
+
+  text_t action_name = get_action_name();
+  disp.setmacro ("fullnamemenu", action_name, fullnamemenu);
+  disp.setmacro ("buildtypearray", action_name, buildtype_jsarray);
+}
+
+// checks to see if any of the plugins in pluginset occur in 
+// collections configuration file
+bool wizardaction::uses_weird_plugin (const text_t &collection) {
+
+  text_tset pluginset;
+  pluginset.insert ("HBPlug");
+
+  text_t cfgfile_content;
+  text_t cfgfile_name = filename_cat (collecthome, collection, "etc", "collect.cfg");
+  text_t pluginstr, pluginname;
+
+  if (read_file (cfgfile_name, cfgfile_content)) {
+    text_t::const_iterator here = cfgfile_content.begin();
+    text_t::const_iterator end = cfgfile_content.end();
+    while (here != end) {
+      here = findchar (here, end, 'p');
+      if (here == end) break;
+      if ((here+6 < end) && (substr (here, here+6) == "plugin")) {
+	getdelimitstr (here+6, end, '\n', pluginstr);
+	text_t::const_iterator hp = pluginstr.begin();
+	text_t::const_iterator ep = pluginstr.end();
+	bool found = false;
+	// remove any leading whitespace, trailing options etc.
+	while (hp != ep) {
+	  if (*hp == '\t' || *hp == ' ' || *hp == '\n') {
+	    if (found) break;
+	  } else {
+	    pluginname.push_back (*hp);
+	    found = true;
+	  }
+	  ++hp;
+	}
+	text_tset::const_iterator it = pluginset.find (pluginname);
+	if (it != pluginset.end()) return true; // found matching plugin
+	pluginname.clear();
+      }
+      ++here;
+    }
+  }
+  return false;
+}
+
+void wizardaction::gsdl_build (cgiargsclass &args, ostream &logout) {
+
+  outconvertclass text_t2ascii;
+
+  //check to see if the tbuild directory exists
+  text_t tmpdir = filename_cat (gsdlhome, "tmp", args[macro_prefix+"tmp"]);
+  if (!directory_exists (tmpdir)) {
+    message = "tmpfail";
+    return;
+  }
+  
+  //check to see if collection name specified
+  text_t &collection = args[macro_prefix+"dirname"];
+  if (collection.empty()) {
+    message = "nocollection";
+    return;
+  }
+
+  // check for a .build file - if it exists then we've already built
+  // the collection (or are in the process of building it)
+  text_t buildfile = filename_cat (tmpdir, ".build");
+  if (file_exists (buildfile)) {
+    return;
+  } else {
+    // create the .build file (this file is just a place holder to let any future
+    // pages know that we've already been here)
+    char *buildfilec = buildfile.getcstr();
+    ofstream bfile_out (buildfilec);
+    delete []buildfilec;
+    if (bfile_out) {
+      bfile_out << "collection building\n";
+      bfile_out.close();
+    } else {
+      message = "tmpfail";
+      return;
+    }
+  }
+
+  //FLAG!
+  const recptconf &rcinfo = recpt->get_configinfo ();
+
+  // create the event header file if LogEvents, EmailEvents or
+  // EmailUserEvents options are turned on.
+  bool logevents = 
+    (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents || 
+     rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents ||
+     rcinfo.EmailUserEvents);
+  text_t ehead_file = filename_cat (tmpdir, "ehead.txt");
+  if (logevents) {
+    if (!create_event_header_file (ehead_file, args, logout)) {
+      logevents = false;
+    }
+  }
+    
+  text_t collectdir = get_collectdir (args);
+
+  // set up build options
+  //text_t options = "-make_writable -remove_import -out \""; 
+  text_t options = "-make_writable  -out \""; 
+  options += filename_cat (tmpdir, collection + ".bld");
+  options += "\" -collectdir \"" + collectdir + "\" -statsfile \"";
+  options += filename_cat(collectdir, collection, "etc", "import.log") + "\"";
+
+  if (args[macro_prefix+"esrce"] == 1) {
+    // we're adding data to an existing collection
+    options += " -save_archives -append -manifest";
+  }
+
+  text_tarray inputvalues, inputtypes;
+  splitchar (args[macro_prefix+"input"].begin(), args[macro_prefix+"input"].end(), ',', inputvalues);
+  splitchar (args[macro_prefix+"inputtype"].begin(), args[macro_prefix+"inputtype"].end(), ',', inputtypes);
+  int numvalues = inputvalues.size();
+  int numtypes = inputtypes.size();
+  for (int i = 0; i < numvalues; ++i) {
+    if (!inputvalues[i].empty()) {
+      text_t type = "file://"; // default
+      if (i < numtypes) type = inputtypes[i];
+      options += " -download \"" + 
+	remove_trailing_slashes(type + format_url(decode_commas(inputvalues[i]))) + "\"";
+    }
+  }
+
+  if (logevents) {
+    if (rcinfo.LogEvents == CollectorEvents || rcinfo.LogEvents == AllEvents) 
+      options += " -log_events";
+    if (rcinfo.EmailEvents == CollectorEvents || rcinfo.EmailEvents == AllEvents) {
+      options += " -mail_server " + rcinfo.MailServer;
+      options += " -email_events " + rcinfo.maintainer;
+      if (rcinfo.EmailUserEvents) options += "," + args[macro_prefix+"contactemail"];
+    } else if (rcinfo.EmailUserEvents) {
+      options += " -mail_server " + rcinfo.MailServer;
+      options += " -email_events " + args[macro_prefix+"contactemail"];
+    }
+    options += " -event_header " + ehead_file;
+  }
+
+  text_t indextype = args[macro_prefix+"buildtype"];
+  if(indextype == "") {
+    indextype = "mg";
+  }
+  options += " -indextype \"" + indextype + "\"";
+
+  text_t optionfile = filename_cat (tmpdir, "build.opt");
+  char *optionfilec = optionfile.getcstr();
+  ofstream ofile_out (optionfilec);
+  delete []optionfilec;
+  if (!ofile_out) {
+    message = "tmpfail";
+    return;
+  }
+  ofile_out << text_t2ascii << options << "\n";
+  ofile_out.close();
+
+  // if we're altering an existing collection we need to kill off
+  // the existing collection server - we do this for the local library
+  // (and any other persistent version of the library) as the existing
+  // database file can't be deleted while the collection server holds it open
+  if ((args[macro_prefix+"econf"] == 1) || (args[macro_prefix+"esrce"] == 1)) {
+    remove_colservr (collection, logout);
+  }    
+
+  // set up the build command - build.bat has some issues with quoting
+  // on win2k when gsdlhome contains spaces so we'll avoid using 
+  // "perl -S" here in favor of calling the "build" perl script explicitly
+  text_t build_cmd = "perl \"" + filename_cat (gsdlhome, "bin", "script", "build");
+  build_cmd += "\" -optionfile \"" + optionfile + "\" " + collection;
+
+  // run build command in background (i.e. asynchronously) 
+  gsdl_system (build_cmd, false, logout);
+
+}
+
+void wizardaction::gsdl_cancel_build (cgiargsclass &args, ostream &logout) {
+  // I really wanted to do what this perl script does from within the library
+  // c++ code. I ran into some problems though (like how do you write a portable
+  // "rm -r" in c++?). One day I'll spend some time sorting it out ... maybe.
+  text_t cancel_cmd = "perl -S cancel_build.pl -collectdir \"";
+  cancel_cmd += filename_cat (gsdlhome, "tmp", args[macro_prefix+"tmp"]) + "\" ";
+  cancel_cmd += args[macro_prefix+"dirname"];
+  // To be on the safe side we'll make this a synchronous call
+  // so that all tidying up is done before the user has a chance
+  // to do anything else (like start rebuilding their collection).
+  // This means that for a big collection where there's lots of 
+  // stuff to delete etc. it might take a while before the "build
+  // cancelled" page appears.
+  gsdl_system (cancel_cmd, true, logout);
+}
+
+text_t wizardaction::get_collectdir (cgiargsclass &args)
+{
+  if ((args[macro_prefix+"econf"] == 1) || (args[macro_prefix+"esrce"] == 1)) {
+    // we're adding to a collection in place
+    return collecthome;
+  }
+  else {
+    return filename_cat (gsdlhome, "tmp", args[macro_prefix+"tmp"]);
+  }
+}
+
+// create and initialize a new collection server and
+// add it to the null protocol.
+void wizardaction::create_colserver (const text_t &collection, ostream &logout) {
+
+  recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    comerror_t err = noError;
+    if ((*rprotolist_here).p != NULL) {
+      if ((*rprotolist_here).p->get_protocol_name (err) == "nullproto") {
+	// create collection server and add it to nullproto
+	(*rprotolist_here).p->add_collection (collection, recpt, gsdlhome, collecthome, dbhome);
+	// make sure gsdlhome is configured
+	text_tarray tmp;
+	tmp.push_back (gsdlhome);
+	(*rprotolist_here).p->configure ("gsdlhome", tmp, err);
+	// re-initialize the null protocol
+	if (!(*rprotolist_here).p->init (err, logout)) {
+	  logout << "wizardaction::create_colserver: nullproto init failed\n";
+	}
+	return;
+      }
+    }
+    ++rprotolist_here;
+  }
+
+  logout << "wizardaction::create_colserver: no valid nullproto found\n";
+}
+
+// delete a collection server from the null protocol
+void wizardaction::remove_colservr (const text_t &collection, ostream &logout) {
+
+  recpt->uncache_collection (collection);
+
+  recptprotolistclass *protos = recpt->get_recptprotolist_ptr();
+  recptprotolistclass::iterator rprotolist_here = protos->begin();
+  recptprotolistclass::iterator rprotolist_end = protos->end();
+  while (rprotolist_here != rprotolist_end) {
+    comerror_t err = noError;
+    if ((*rprotolist_here).p != NULL) {
+      if ((*rprotolist_here).p->get_protocol_name (err) == "nullproto") {
+	(*rprotolist_here).p->remove_collection (collection, logout);
+	return;
+      }
+    }
+    ++rprotolist_here;
+  }
+
+  logout << "wizardaction::create_colserver: no valid nullproto found\n";
+}
+
+bool wizardaction::create_event_header_file (const text_t &filename, cgiargsclass &args, 
+						ostream &logout) {
+
+  outconvertclass text_t2ascii;
+  char *filenamec = filename.getcstr();
+  ofstream eheadfile (filenamec);
+  delete []filenamec;
+
+  if (eheadfile) {
+    eheadfile << text_t2ascii << get_event_header (args);
+    eheadfile.close();
+    return true;
+  }
+   
+  logout << text_t2ascii << "wizardaction::create_event_header ERROR: Couldn't create "
+	 << "Event Header file " << filename << ". Event logging disabled\n";
+  return false;
+}
+
+text_t wizardaction::get_event_header (cgiargsclass &args) {
+  text_t header = "Greenstone Username: " + args["un"] + "\n";
+  header += "Collection: " + args[macro_prefix+"dirname"] + "\n";
+  header += "Collection Creator: " + args[macro_prefix+"contactemail"] + "\n";
+  header += "GSDLHOME: " + gsdlhome + "\n";
+  header += "Build Location: " + get_collectdir(args) + "\n";
+
+  return header;
+}
+
+
+// format_url simply strips "http://", "ftp://", or "file://" off the
+// beginning of url if they're there
+text_t wizardaction::format_url (const text_t &url) {
+  text_t::const_iterator begin = url.begin();
+  text_t::const_iterator end = url.end();
+
+  if (url.size() >= 7) {
+    text_t prefix = substr(begin, begin+7);
+    if (prefix == "http://" || prefix == "file://") {
+      return substr(begin+7, end);
+    }
+  }
+  if (url.size() >= 6) {
+    if (substr(begin, begin+6) == "ftp://") {
+      return substr(begin+6, end);
+    }
+  }
+  return url;
+}
+
+text_t wizardaction::remove_trailing_slashes (text_t str) {
+
+  while (*(str.end()-1) == '\\') {
+    str.pop_back();
+  }
+  return str;
+}
+
Index: /gsdl/trunk/runtime-src/src/recpt/wizardaction.h
===================================================================
--- /gsdl/trunk/runtime-src/src/recpt/wizardaction.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/recpt/wizardaction.h	(revision 16571)
@@ -0,0 +1,111 @@
+/**********************************************************************
+ *
+ * wizardaction.h -- 
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "gsdl_modules_cfg.h"
+
+#ifndef WIZARDACTION_H
+#define WIZARDACTION_H
+
+#include "action.h"
+#include "receptionist.h"
+
+class wizardaction : public action {
+  
+
+public:
+  wizardaction ();
+  virtual ~wizardaction ();
+
+  void configure (const text_t &key, const text_tarray &cfgline);
+
+  bool init (ostream &logout);
+
+  void set_receptionist (receptionist *therecpt) {recpt=therecpt;}
+
+  text_t get_action_name () {return "wizard";}
+
+  void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
+			 response_t &response,text_t &response_data, 
+			 ostream &logout);
+
+  bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, 
+		      recptprotolistclass * protos, ostream &logout);
+
+
+protected:
+  bool disabled;
+  receptionist *recpt;
+  char *gsdlosc;
+  char *gsdlhomec;
+  char *pathc;
+
+  text_t macro_prefix;
+
+  text_t message;
+  char failcode;
+
+  virtual text_t get_button (cgiargsclass &args, const text_t &thispage, 
+			     const text_t &color, 
+			     const text_t &type, bool enabled)=0;
+			    
+
+  text_t carriage_replace (const text_t &intext, int sw);
+
+  text_t get_directory_name (const text_t &fullname);
+
+  bool collection_protected (const text_t &collection);
+
+  bool assign_tmpname (cgiargsclass &args, ostream &logout);
+
+
+  void set_statusline (displayclass &disp, cgiargsclass &args, ostream &logout);
+  void gsdl_build (cgiargsclass &args, ostream &logout);
+
+  void gsdl_cancel_build (cgiargsclass &args, ostream &logout);
+
+  text_t get_collectdir (cgiargsclass &args);
+
+  void create_colserver (const text_t &collection, ostream &logout);
+
+  void remove_colservr (const text_t &collection, ostream &logout);
+
+  bool create_event_header_file (const text_t &filename, cgiargsclass &args, 
+				 ostream &logout);
+
+  text_t get_event_header (cgiargsclass &args);
+
+  text_t format_url (const text_t &url);
+
+  text_t remove_trailing_slashes (text_t str);
+
+  void set_fullnamemenu (displayclass &disp, cgiargsclass &args,
+			 recptprotolistclass *protos, ostream &logout);
+
+  bool uses_weird_plugin (const text_t &collection);
+
+};
+
+#endif //!WIZARDACTION_H
+
Index: /gsdl/trunk/runtime-src/src/w32server/cgiwrapper.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/cgiwrapper.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/cgiwrapper.cpp	(revision 16571)
@@ -0,0 +1,985 @@
+/**********************************************************************
+ *
+ * cgiwrapper.cpp -- windows local library cgiwrapper
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "text_t.h"
+
+#include <windows.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <direct.h>
+#include "cgiwrapper.h"
+#include "netio.h"
+#include "wincgiutils.h"
+#include "settings.h"
+#include "fileutil.h"
+#include "parse.h"
+
+#include "gsdlconf.h"
+#include "maincfg.h"
+
+#if defined (GSDL_USE_OBJECTSPACE)
+#include <ospace\std\iostream>
+#include <ospace\std\fstream>
+#elif defined (GSDL_USE_IOS_H)
+#include <iostream.h>
+#include <fstream.h>
+#else
+#include <iostream>
+#include <fstream>
+#endif
+
+#include "receptionist.h"
+#include "nullproto.h"
+
+// actions
+#include "statusaction.h"
+#include "pageaction.h"
+#include "pingaction.h"
+#include "queryaction.h"
+#include "documentaction.h"
+#include "dynamicclassifieraction.h"
+#include "tipaction.h"
+#include "authenaction.h"
+#include "usersaction.h"
+#include "userdb.h"
+#include "extlinkaction.h"
+#include "collectoraction.h"
+#include "phindaction.h"
+#include "configaction.h"
+
+// browsers
+#include "vlistbrowserclass.h"
+#include "hlistbrowserclass.h"
+#include "datelistbrowserclass.h"
+#include "invbrowserclass.h"
+#include "pagedbrowserclass.h"
+#include "htmlbrowserclass.h"
+#include "phindbrowserclass.h"
+
+// the number of times the library has been accessed
+int libaccessnum = 0;
+
+// used to output the text from receptionist
+class textstreambuf : public streambuf
+{
+public:
+  textstreambuf ();
+  int sync ();
+  int overflow (int ch);
+  int underflow () {return EOF;}
+  
+  void tsbreset() {RInfo=NULL;casostr=NULL;}
+  void setrequestinfo (RequestInfoT *theRInfo) {RInfo=theRInfo;}
+  void cascadeoutput (ostream *thecasostr) {casostr=thecasostr;}
+  
+private:
+  RequestInfoT *RInfo;
+  ostream *casostr;
+#if !defined (GSDL_USE_IOS_H)
+  char buffer[256];
+#endif
+};
+
+textstreambuf::textstreambuf() {
+  tsbreset();
+#if !defined (GSDL_USE_IOS_H)
+  setp (&buffer[0], &buffer[255]);
+#else
+  if (base() == ebuf()) allocate();
+  setp (base(), ebuf());
+#endif
+};
+
+int textstreambuf::sync () {
+  if ((RInfo != NULL) && 
+      (Send_String_N(pbase(), pptr()-pbase(), RInfo) < 0)) {
+    RInfo = NULL;
+  }
+  
+  if (casostr != NULL) {
+    char *thepbase=pbase();
+    for (int i=0;i<(pptr()-pbase());++i) (*casostr).put(thepbase[i]);
+  }
+  
+  setp (pbase(), epptr());
+  
+  return 0;
+}
+
+int textstreambuf::overflow (int ch) {
+  if (sync () == EOF) return EOF;
+  if (ch != EOF) sputc (ch);
+  return 0;
+}
+
+
+// used to output all the log and error messages
+// from receptionist
+class logstreambuf : public streambuf
+{
+public:
+  logstreambuf ();
+  int sync ();
+  int overflow (int ch);
+  int underflow () {return EOF;}
+
+#if !defined (GSDL_USE_IOS_H)
+private:
+  char buffer[256];
+#endif
+};
+
+logstreambuf::logstreambuf () {
+#if !defined (GSDL_USE_IOS_H)
+  setp (&buffer[0], &buffer[255]);
+#else
+  if (base() == ebuf()) allocate();
+  setp (base(), ebuf());
+#endif
+}
+
+int logstreambuf::sync () {
+  if (gsdl_keep_log || gsdl_show_console) {
+    log_message ("LOCAL LIB MESSAGE: ");
+		log_message_N (pbase(), pptr()-pbase());
+  }
+
+  setp (pbase(), epptr());
+  return 0;
+}
+
+int logstreambuf::overflow (int ch) {
+  if (sync () == EOF) return EOF;
+  if (ch != EOF) sputc (ch);
+  return 0;
+}
+
+static void page_errormaincfg (const text_t &gsdlhome, const text_t &collection) {
+
+  if (collection.empty()) {
+    text_t message = "Error\n\n"
+      "The main.cfg configuration file could not be found. This file\n"
+      "should contain configuration information relating to the\n"
+      "setup of the interface. As this program is not being run\n"
+      "in collection specific mode the file should reside at\n" +
+      gsdlhome + "\\etc\\main.cfg.\n";
+
+    MessageBox(NULL, message.getcstr(),
+	       "Greenstone Digital Library Software"
+	       ,MB_OK|MB_SYSTEMMODAL);
+  } else {
+    text_t message = "Neither the collect.cfg or main.cfg configuration files could\n"
+      "be found. This file should contain configuration information\n"
+      "relating to the setup of the interface. As this cgi script is\n"
+      "being run in collection specific mode the file should reside\n"
+      "at either " + gsdlhome + "\\collect\\" + collection + "\\etc\\collect.cfg,\n" +
+      gsdlhome + "\\etc\\collect.cfg or " + gsdlhome + "\\etc\\main.cfg.\n";
+
+    MessageBox(NULL, message.getcstr(),
+	       "Greenstone Digital Library Software"
+	       ,MB_OK|MB_SYSTEMMODAL);
+  }
+}
+
+static void page_errorinit (const text_t &/*gsdlhome*/) {
+
+  text_t message = "Error\n\n"
+    "An error occurred during the initialisation of the Greenstone Digital\n"
+    "Library software. It is likely that the software has not been setup\n"
+    "correctly.\n";
+
+  MessageBox(NULL, message.getcstr(),
+	     "Greenstone Digital Library Software"
+	     ,MB_OK|MB_SYSTEMMODAL);
+}
+
+static void page_errorparseargs (const text_t &/*gsdlhome*/) {
+
+  text_t message = "Error\n\n"
+    "An error occurred during the parsing of the cgi arguments.\n";
+
+  MessageBox(NULL, message.getcstr(),
+	     "Greenstone Digital Library Software"
+	     ,MB_OK|MB_SYSTEMMODAL);
+}
+
+static void page_errorcgipage (const text_t &/*gsdlhome*/) {
+
+  text_t message = "Error\n\n"
+    "An error occurred during the construction of the cgi page.\n";
+
+  MessageBox(NULL, message.getcstr(),
+	     "Greenstone Digital Library Software"
+	     ,MB_OK|MB_SYSTEMMODAL);
+}
+
+// returns 0 if the directories can't be found
+// and the user wants to quit (it returns 1
+// if everything is ok)
+int checkdir (const text_t &thedir) {
+  UINT curerrormode;
+  int drive = _getdrive();
+  char cwd[1024];
+  char rootpath[4];
+  UINT drivetype;
+  char *cstrthedir = thedir.getcstr();
+  int returnvalue = 1;
+  
+  // make sure no rude error messages are presented to the user
+  curerrormode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
+  
+  // get the drive name
+  if (thedir.size() >= 2 && thedir[1] == ':') {
+    if (thedir[0] >= 'a' && thedir[0] <= 'z') {
+      drive = thedir[0] - 'a' + 1;
+      
+    } else if (thedir[0] >= 'A' && thedir[0] <= 'Z') {
+      drive = thedir[0] - 'A' + 1;
+    }
+  }
+  
+  // find the drive type
+  rootpath[0] = drive + 'A' - 1;
+  rootpath[1] = ':';
+  rootpath[2] = '\\';
+  rootpath[3] = '\0';
+  drivetype = GetDriveType (rootpath);
+  
+  // try and set this directory to be the current working
+  // directory
+  _getcwd(cwd, 1024);
+  while (_chdir(cstrthedir) != 0) {
+    // failed
+    if (drivetype == DRIVE_CDROM) {
+      // message to insert the cdrom
+      if (MessageBox (NULL, 
+		      "Please insert the Greenstone Digital Library\n"
+		      "CD-ROM into the CD-ROM drive and press 'OK'.\n\n"
+		      "If you don't have the CD-ROM press 'Cancel' to exit\n"
+		      "this program.", "Greenstone Digital Library Software", 
+		      MB_OKCANCEL | MB_TASKMODAL) == IDCANCEL) {
+	
+	returnvalue = 0;
+	break;
+      }
+      
+    } else {
+      // message saying that the system was unable
+      // to find a certain directory
+      text_t message = "Failed to find the directory:\n\n" + thedir;
+      message += "\n\n"
+	"This directory is needed for the successful operation\n"
+	"of this software. Make sure it hasn't been deleted or\n"
+	"moved, and restart the software. You may need to\n"
+	"reinstall this software to correct the problem.";
+      char *cstrmessage = message.getcstr();
+      
+      MessageBox (NULL, cstrmessage, "Greenstone Digital Library Software",
+		  MB_OK | MB_TASKMODAL);
+      
+      delete []cstrmessage;
+      
+      returnvalue = 0;
+      break;
+    }
+  }
+  
+  // revert to the previous error and cwd states
+  _chdir(cwd);
+  SetErrorMode(curerrormode);
+  
+  // free the allocated C string
+  delete []cstrthedir;
+  
+  return returnvalue;
+}
+
+
+// c-string version of checkdir for the outside
+// world
+int cstrcheckdir (char *cstrthedir) {
+  return checkdir (cstrthedir);
+}
+
+
+receptionist recpt;
+nullproto nproto;
+collectset *cservers = NULL;
+
+textstreambuf textstream;
+logstreambuf logstream;
+DWORD lastlibaccesstime;
+DWORD baseavailvirtual;
+text_t current_gsdlhome;
+colinfo_tmap translated_collectinfo;
+  
+statusaction *astatusaction = NULL;
+pageaction *apageaction = NULL;
+pingaction *apingaction = NULL;
+tipaction *atipaction = NULL;
+queryaction *aqueryaction = NULL;
+documentaction *adocumentaction = NULL;
+dynamicclassifieraction *adynamicclassifieraction = NULL;
+usersaction *ausersaction = NULL;
+extlinkaction *anextlinkaction = NULL;
+collectoraction *acollectoraction = NULL;
+authenaction *aauthenaction = NULL;
+phindaction *aphindaction = NULL;
+configaction *aconfigaction = NULL;
+vlistbrowserclass *avlistbrowserclass = NULL;
+hlistbrowserclass *ahlistbrowserclass = NULL;
+datelistbrowserclass *adatelistbrowserclass = NULL;
+invbrowserclass *ainvbrowserclass = NULL;
+pagedbrowserclass *apagedbrowserclass = NULL;
+htmlbrowserclass *ahtmlbrowserclass = NULL;
+phindbrowserclass *aphindbrowserclass = NULL;
+text_t userdbfile = NULL;
+userdbclass *udb = NULL;
+text_t keydbfile = NULL;
+keydbclass *kdb = NULL;
+
+// returns 1 if successful, 0 if unsuccessful (note that as well as being
+// called when the server first starts up this function is called when the
+// "restart library" button is pressed)
+int gsdl_init (bool atStartup) {
+
+  if (atStartup) {
+#if defined (GSDL_USE_IOS_H)
+    cerr = &logstream;
+    cout = &textstream;
+#else
+    cerr.rdbuf(&logstream);
+    cout.rdbuf(&textstream);
+#endif
+  }
+
+  // collection should be set to "" unless in collection specific mode -
+  // changing this to the name of the collection should be all that's
+  // required to create a collection specific receptionist
+  text_t collection = "";
+  text_tset dbhomes;
+  text_tset collections;
+
+  if (atStartup) {
+    // note the current time
+    lastlibaccesstime = GetTickCount();
+    
+    // before we do the init we should make sure
+    // that we can find the relevant directories
+    if (!checkdir (gsdl_gsdlhome + "\\")) return 0;
+    if (!checkdir (gsdl_collecthome + "\\")) return 0;
+    if (!checkdir (gsdl_gsdlhome + "\\macros\\")) return 0;
+  }    
+
+  // deleting cservers clears all the collection servers 
+  if (cservers != NULL) delete cservers;
+
+  cservers = new collectset();
+
+  // get all collections from each gsdlhome (this relies 
+  // on there not being more than one collection with the same 
+  // name)
+  if (!collection.empty()) {
+    // collection specific receptionist - one collection, one gsdlhome
+    collections.insert (collection);
+    dbhomes.insert (gsdl_dbhome);
+    collectioninfo_t tmp;
+    tmp.gsdl_gsdlhome = gsdl_gsdlhome;
+    tmp.gsdl_collecthome = gsdl_collecthome;
+    tmp.gsdl_dbhome = gsdl_dbhome;
+    translated_collectinfo[collection] = tmp;
+
+  } else {
+
+    text_tset::const_iterator colhere;
+    text_tset::const_iterator colend;
+    text_tset these_collections;
+
+    // first volume gsdlhome's
+    colinfo_tmap::const_iterator this_info = gsdl_collectinfo.begin();
+    colinfo_tmap::const_iterator end_info = gsdl_collectinfo.end();
+    while (this_info != end_info) {
+      if (dbhomes.find ((*this_info).second.gsdl_dbhome) == dbhomes.end()) {
+	these_collections.erase (these_collections.begin(), these_collections.end());
+	read_dir ((*this_info).second.gsdl_collecthome, these_collections);
+	colhere = these_collections.begin();
+	colend = these_collections.end();
+	while (colhere != colend) {
+	  if ((collections.find (*colhere)) == collections.end()) {
+	    // make sure the build.cfg file is at gsdlhome (as it's possible that
+	    // the collection appears at this gsdlhome only because it's gdbm
+	    // file is installed here -- it's real gdbm will therefore be 
+	    // somewhere else).
+	    text_t build_cfg = filename_cat ((*this_info).second.gsdl_collecthome,
+					     *colhere, "index", "build.cfg");
+	    if (file_exists (build_cfg)) {
+	      collections.insert (*colhere);
+
+	      // since gsdl_collectinfo keys will be stuff like collection#1
+	      // for a multiple volume collection we want to translate it
+	      // so that the keys are the actual collection names
+	      translated_collectinfo[*colhere] = (*this_info).second;
+	    }
+	  }
+	  ++colhere;
+	}
+	dbhomes.insert ((*this_info).second.gsdl_dbhome);
+      }
+      ++this_info;
+    }
+  
+    // then if necessary the main dbhome (this should only happen if the 
+    // gsdl.ini is a little screwed up and no volume dbhomes occurred)
+    if (dbhomes.find (gsdl_dbhome) == dbhomes.end()) {
+      these_collections.erase (these_collections.begin(), these_collections.end());
+      read_dir (filename_cat (gsdl_dbhome, "collect"), these_collections);
+      colhere = these_collections.begin();
+      colend = these_collections.end();
+      while (colhere != colend) {
+	collections.insert (*colhere);
+	collectioninfo_t tmp;
+	tmp.gsdl_gsdlhome = gsdl_gsdlhome;
+	tmp.gsdl_collecthome = gsdl_collecthome;
+	tmp.gsdl_dbhome = gsdl_dbhome;
+	translated_collectinfo[*colhere] = tmp;
+	++colhere;
+      }
+      dbhomes.insert (gsdl_dbhome);
+    }
+  }
+
+  text_tset::const_iterator thiscol = collections.begin();
+  text_tset::const_iterator endcol = collections.end();
+
+  while (thiscol != endcol) {
+    
+    // ignore the modelcol
+    if (*thiscol == "modelcol") {
+      ++thiscol;
+      continue;
+    }
+    
+    // create collection server and add to null protocol
+    text_t this_gsdlhome = gsdl_gsdlhome;
+    text_t this_collecthome = gsdl_collecthome;
+    text_t this_dbhome = gsdl_dbhome;
+    colinfo_tmap::const_iterator it = translated_collectinfo.find (*thiscol);
+    assert (it != translated_collectinfo.end());
+    this_gsdlhome = (*it).second.gsdl_gsdlhome;
+    this_collecthome = (*it).second.gsdl_collecthome;
+    this_dbhome = (*it).second.gsdl_dbhome;
+
+    cservers->add_collection (*thiscol, this_gsdlhome, this_collecthome);
+
+    ++thiscol;
+  }
+
+  // set up the null protocol
+  nproto.set_collectset(cservers);
+  
+  if ((ausersaction == NULL) && (aauthenaction == NULL)){
+    userdbfile = filename_cat(gsdl_gsdlhome, "etc", "users.db");
+    udb = new userdbclass(userdbfile);
+    keydbfile = filename_cat(gsdl_gsdlhome, "etc", "key.db");
+    kdb = new keydbclass(keydbfile);
+  }
+  // add the protocol to the receptionist
+  if (atStartup) recpt.add_protocol (&nproto);
+  
+  // the list of actions.
+  if (astatusaction == NULL) {
+    astatusaction = new statusaction();
+    astatusaction->set_receptionist (&recpt);
+    recpt.add_action (astatusaction);
+  }
+  
+  if (apageaction == NULL) {
+    apageaction = new pageaction();
+    apageaction->set_receptionist (&recpt);
+    recpt.add_action (apageaction);
+  }
+  
+  if (apingaction == NULL) {
+    apingaction = new pingaction();
+    recpt.add_action (apingaction);
+  }
+  
+  if (atipaction == NULL) {
+    atipaction = new tipaction();
+    recpt.add_action (atipaction);
+  }
+  
+  if (aqueryaction == NULL) {
+    aqueryaction = new queryaction();
+    aqueryaction->set_receptionist (&recpt);
+    recpt.add_action (aqueryaction);
+  }
+  
+  if (adocumentaction == NULL) {
+    adocumentaction = new documentaction();
+    adocumentaction->set_receptionist (&recpt);
+    recpt.add_action (adocumentaction);
+  }
+  
+  if (ausersaction == NULL) {
+    ausersaction = new usersaction();
+    ausersaction->set_userdb(udb);
+    recpt.add_action (ausersaction);
+  }
+
+  if (anextlinkaction == NULL) {
+    anextlinkaction = new extlinkaction();
+    recpt.add_action (anextlinkaction);
+  }
+
+  if (acollectoraction == NULL) {
+    acollectoraction = new collectoraction();
+    acollectoraction->set_receptionist (&recpt);
+    recpt.add_action (acollectoraction);
+  }
+  
+  if (aauthenaction == NULL) {
+    aauthenaction = new authenaction();
+    aauthenaction->set_userdb(udb);
+    aauthenaction->set_keydb(kdb);
+    aauthenaction->set_receptionist(&recpt);
+    recpt.add_action (aauthenaction);
+  }
+
+  if (aphindaction == NULL) {
+    aphindaction = new phindaction();
+    recpt.add_action (aphindaction);
+  }
+  
+  if (aconfigaction == NULL) {
+    aconfigaction = new configaction();
+    aconfigaction->set_receptionist(&recpt);
+    recpt.add_action (aconfigaction);
+  }
+  
+  if (adynamicclassifieraction == NULL) {
+    adynamicclassifieraction = new dynamicclassifieraction();
+    adynamicclassifieraction->set_receptionist(&recpt);
+    recpt.add_action (adynamicclassifieraction);
+  }
+
+
+  // list of browsers
+  if (avlistbrowserclass == NULL) {
+    avlistbrowserclass = new vlistbrowserclass();
+    recpt.add_browser (avlistbrowserclass);
+    recpt.setdefaultbrowser ("VList");
+  }
+
+  if (ahlistbrowserclass == NULL) {
+    ahlistbrowserclass = new hlistbrowserclass();
+    recpt.add_browser (ahlistbrowserclass);
+  }
+
+  if (adatelistbrowserclass == NULL) {
+    adatelistbrowserclass = new datelistbrowserclass();
+    recpt.add_browser (adatelistbrowserclass);
+  }
+
+  if (ainvbrowserclass == NULL) {
+    ainvbrowserclass = new invbrowserclass();
+    recpt.add_browser (ainvbrowserclass);
+  }
+
+  if (apagedbrowserclass == NULL) {
+    apagedbrowserclass = new pagedbrowserclass();
+    recpt.add_browser (apagedbrowserclass);
+  }
+
+  if (ahtmlbrowserclass == NULL) {
+    ahtmlbrowserclass = new htmlbrowserclass();
+    recpt.add_browser (ahtmlbrowserclass);
+  }
+
+  if (aphindbrowserclass == NULL) {
+    aphindbrowserclass = new phindbrowserclass();;
+    recpt.add_browser (aphindbrowserclass);
+  }
+  
+  // set defaults
+  recpt.configure ("gsdlhome", gsdl_gsdlhome);
+  recpt.configure ("collecthome", gsdl_collecthome);
+  recpt.configure ("gdbmhome", gsdl_dbhome);
+  recpt.configure ("collection", collection);
+
+  int maxrequests = 1;
+
+  // configure collections (and receptionist) with collectinfo stuff
+  // different from the default
+  colinfo_tmap::const_iterator this_info = translated_collectinfo.begin();
+  colinfo_tmap::const_iterator end_info = translated_collectinfo.end();
+
+  while (this_info != end_info) {
+    text_tarray tmpconf;
+    tmpconf.push_back ((*this_info).first);
+    tmpconf.push_back ((*this_info).second.gsdl_gsdlhome);
+    tmpconf.push_back ((*this_info).second.gsdl_collecthome);
+    tmpconf.push_back ((*this_info).second.gsdl_dbhome);
+    recpt.configure ("collectinfo", tmpconf);
+    ++this_info;
+  }
+
+  // read in config files of each dbhome (in no particular order)
+  // those read in last will override those read earlier
+  // collections being used together in this way should be 
+  // careful not to have main.cfg files that might 
+  // interfere with each other.
+  text_tset::const_iterator thome = dbhomes.begin();
+  text_tset::const_iterator ehome = dbhomes.end();
+  while (thome != ehome) {
+    if (!main_cfg_read (recpt, *thome, collection)) {
+      // couldn't find the main configuration file
+      page_errormaincfg (*thome, collection);
+      return 0;
+    }
+    ++thome;
+  }
+
+  // w32server relies on gwcgi being set to "gsdl"
+  recpt.configure ("gwcgi", "gsdl");
+	
+  // initialise the library software
+  if (!recpt.init(cerr)) {
+    // an error occurred during the initialisation
+    page_errorinit(gsdl_gsdlhome);
+    return 0;
+  }
+
+  // get memory information
+  MEMORYSTATUS memstatus;
+  memstatus.dwLength = sizeof(MEMORYSTATUS);
+  GlobalMemoryStatus(&memstatus);
+  baseavailvirtual = memstatus.dwAvailVirtual; // save for later comparison
+
+  return 1;
+}
+
+
+static void rememberpref (const text_t &tailstr) {
+  gsdl_enterlib = tailstr;
+}
+
+
+static void send_file_from_disk(text_t filename,
+                                RequestInfoT *RInfo,
+                                RequestFieldsT *RFields) {
+  
+  // select appropriate mime type from file extension
+  text_t ext;
+  text_t::const_iterator end = filename.end();
+  text_t::const_iterator it = filename.begin();
+  text_t::const_iterator lastdot = end;
+  while ((it = findchar(it, end, '.')) != end) {
+    lastdot = it;
+    ++it;
+  }
+  if (lastdot < end) ext = substr(lastdot+1, end);
+
+  text_t mime = "unknown";
+  int len = ext.size();
+  if (len == 2) {
+    if ((ext[0] == 'p' || ext[0] == 'P') &&
+	(ext[1] == 's' || ext[1] == 'S'))
+      mime = "application/postscript";
+  }  else if (len == 3) {
+    if ((ext[0] == 'g' || ext[0] == 'G') &&
+	(ext[1] == 'i' || ext[1] == 'I') &&
+	(ext[2] == 'f' || ext[2] == 'F')) {
+      mime = "image/gif";
+    } else if ((ext[0] == 'j' || ext[0] == 'J') &&
+	       (ext[1] == 'p' || ext[1] == 'P') &&
+	       (ext[2] == 'g' || ext[2] == 'G')) {
+      mime = "image/jpeg";
+    } else if ((ext[0] == 'h' || ext[0] == 'H') &&
+	       (ext[1] == 't' || ext[1] == 'T') &&
+	       (ext[2] == 'm' || ext[2] == 'M')) {
+      mime = "text/html";
+    } else if ((ext[0] == 'p' || ext[0] == 'P') &&
+	       (ext[1] == 'd' || ext[1] == 'D') &&
+	       (ext[2] == 'f' || ext[2] == 'F')) {
+      mime = "application/pdf";
+    } else if ((ext[0] == 'p' || ext[0] == 'P') &&
+	       (ext[1] == 'n' || ext[1] == 'N') &&
+	       (ext[2] == 'g' || ext[2] == 'G')) {
+      mime = "image/png";
+    } else if ((ext[0] == 'd' || ext[0] == 'D') &&
+	       (ext[1] == 'o' || ext[1] == 'O') &&
+	       (ext[2] == 'c' || ext[2] == 'C')) {
+      mime = "application/msword";
+    } else if ((ext[0] == 'r' || ext[0] == 'R') &&
+	       (ext[1] == 't' || ext[1] == 'T') &&
+	       (ext[2] == 'f' || ext[2] == 'F')) {
+      mime = "application/rtf";
+    } else if ((ext[0] == 'x' || ext[0] == 'X') &&
+	       (ext[1] == 'l' || ext[1] == 'L') &&
+	       (ext[2] == 's' || ext[2] == 'S')) {
+      mime = "application/vnd.ms-excel";
+    } else if ((ext[0] == 'p' || ext[0] == 'P') &&
+	       (ext[1] == 'p' || ext[1] == 'P') &&
+	       (ext[2] == 'T' || ext[2] == 'T')) {
+      mime = "application/vnd.ms-powerpoint";
+    } else if ((ext[0] == 'm' || ext[0] == 'M') &&
+	       (ext[1] == 'p' || ext[1] == 'P') &&
+	       (ext[2] == '3')) {
+      mime = "audio/mpeg";
+    }
+  } else if (len == 4) {
+    if ((ext[0] == 'j' || ext[0] == 'J') &&
+	(ext[1] == 'p' || ext[1] == 'P') &&
+	(ext[2] == 'e' || ext[2] == 'E') &&
+	(ext[3] == 'g' || ext[3] == 'G')) {
+      mime = "image/jpeg";
+    } else if ((ext[0] == 'h' || ext[0] == 'H') &&
+	       (ext[1] == 't' || ext[1] == 'T') &&
+	       (ext[2] == 'm' || ext[2] == 'M') &&
+	       (ext[3] == 'l' || ext[3] == 'L')) {
+      mime = "text/html";
+    }
+  }
+	
+  // try to open the file
+  filename = filename_cat (current_gsdlhome, filename);
+  /* Feb 2002 - handle files with spaces in their name. */
+  text_t::iterator space_start;
+  space_start=findword(filename.begin(),filename.end(),"%20");
+  while (space_start != filename.end()) {
+    // we found a space...
+    text_t::iterator after_space=space_start+3;
+    text_t new_filename=substr(filename.begin(), space_start);
+    new_filename += " ";
+    new_filename += substr(after_space,filename.end());
+    filename=new_filename;
+    space_start=findword(filename.begin(),filename.end(),"%20");
+  }
+
+  char *filenamec = filename.getcstr();
+  TranslateEscapeString(filenamec);  // Resolve any %xx values
+  FILE *thefile = fopen(filenamec, "rb");
+  delete []filenamec;
+  if (thefile == NULL) {
+    log_message("file not found\n");
+    send_retrieve_error(404, "File not found",
+			"Could not find the local file requested", RInfo);
+    return;
+  }
+  int nr;
+  char buffer[2048];
+  // send back required information
+  char *mimec = mime.getcstr();
+  if (send_header(mimec, RInfo) >= 0) {
+    if (RFields->MethodStr != "HEAD") {
+      for (;;) {
+        nr = fread(buffer, 1, 2048, thefile);
+        if (nr <= 0) break;
+        if (SendData(RInfo->ClientSocket,
+                     (BYTE *)buffer, nr,
+		     RInfo->ThreadNum) < 0) break;        
+      }
+    }
+  }
+  delete []mimec;
+  fclose(thefile);
+}
+
+static void handle_library_request(const text_t &argstr, RequestInfoT *RInfo,
+				   RequestFieldsT *RequestFields) {
+
+  // parse the cgi arguments and produce the resulting page if there
+  // have been no errors so far
+  cgiargsclass args;
+  fileupload_tmap fileuploads;
+  text_tmap empty; // don't use this (it's for fastcgi on unix)
+  if (!recpt.parse_cgi_args (argstr, fileuploads, args, cerr, empty)) {
+    page_errorparseargs(gsdl_gsdlhome);
+    return;
+  } 
+
+  colinfo_tmap::const_iterator it = translated_collectinfo.find (args["c"]);
+  if (it != translated_collectinfo.end()) {
+    current_gsdlhome = (*it).second.gsdl_gsdlhome;
+  } else {
+    current_gsdlhome = gsdl_gsdlhome;
+  }
+
+  // produce cgi header
+  response_t response;
+  text_t response_data;
+
+  recpt.get_cgihead_info (args, response, response_data, cerr, empty);
+
+  if (response == location) {
+    // location response
+    response_data = "@" + recpt.expandmacros (response_data, args, cerr);
+    char *response_data_c = response_data.getcstr();
+    send_header(response_data_c, RInfo);
+    delete []response_data_c;
+    return;
+  } else if (response == content) {
+    // content response
+    char *response_data_c = response_data.getcstr();
+    if (send_header(response_data_c, RInfo) < 0) {
+      delete []response_data_c;
+      return;
+    }
+    delete []response_data_c;
+  }
+  else if (response == undecided_location) {
+    // We know this is a relocation request but at the moment we don't know exactly where to
+    // Just output the start of the header and wait until later to output the target location
+    // Used for the "I'm feeling lucky" functionality
+    cout << "HTTP/1.0 302 Relocation\r\n";
+    cout << "Server: GSDL\r\n";
+    cout << "Content-type: text/html \r\n";
+  }
+  else {
+    // unknown response
+    cerr << "Error: get_cgihead_info returned an unknown response type.\n";
+    return;
+  }
+
+  textstream.tsbreset();
+  textstream.setrequestinfo (RInfo);
+  if (!recpt.produce_content (args, cout, cerr)) {
+    page_errorcgipage(gsdl_gsdlhome);
+    return;
+  } 
+  recpt.log_cgi_args (args, cerr, empty);
+
+  cout << flush;
+  cerr << flush;
+  
+  ++libaccessnum;
+}
+
+static void handle_server_request(text_t &tailstr,
+				  RequestInfoT *RequestInfo,
+				  RequestFieldsT *RequestFields) {
+  
+  text_t argstr;
+
+  // do any url adjustments necessary
+  if (tailstr.empty() || tailstr == "/") {
+    tailstr = "/gsdl";
+  }
+
+  text_t::const_iterator begin = tailstr.begin();
+  text_t::const_iterator end = tailstr.end();
+  
+  // test to see if this is a library request or a local
+  // file request
+  if ((tailstr == "/gsdl") ||
+      ((tailstr.size() > 5) && (substr(begin, begin+6) == "/gsdl?"))) {
+
+    // library request
+    
+    // argstr is the bit after the '?'
+    if (tailstr != "/gsdl") {
+      argstr = substr(begin+6, end);
+    }
+
+    // log the difference in access times
+    DWORD thislibaccesstime = GetTickCount();
+    if (gsdl_keep_log || gsdl_show_console) {
+      char logstr[256];
+      sprintf(logstr, "DELTA LIB ACCESS TIME: %i\n", (int)(thislibaccesstime - lastlibaccesstime));
+      log_message (logstr);
+    }
+    lastlibaccesstime = thislibaccesstime;
+    
+    // log this request
+    if (gsdl_keep_log || gsdl_show_console) {
+      text_t logstr = "LOCAL LIB: " + tailstr + "\n";
+      char *logstrc = logstr.getcstr();
+      log_message (logstrc);
+      delete []logstrc;
+    }
+    
+    handle_library_request (argstr, RequestInfo, RequestFields);
+    
+    // remember the preferences
+    // rememberpref (tailstr);
+    
+    // log memory information
+    if (gsdl_keep_log || gsdl_show_console) {
+      MEMORYSTATUS memstatus;
+      memstatus.dwLength = sizeof(MEMORYSTATUS);
+      GlobalMemoryStatus(&memstatus);
+      char logstr[256];
+      sprintf (logstr, "BDELTA AVAIL VIRTUAL: %i K\n", 
+	       (int)((baseavailvirtual - memstatus.dwAvailVirtual)/1024));
+      log_message (logstr);
+    }
+    
+  } else {
+    // local file
+    if (gsdl_keep_log || gsdl_show_console) {
+      text_t logstr = "LOCAL FILE: " + tailstr + "\n";
+      char *logstrc = logstr.getcstr();
+      log_message (logstrc);
+      delete []logstrc;
+    }
+    send_file_from_disk (tailstr, RequestInfo, RequestFields);
+  }
+}
+
+int ExamineURIStr(text_t &URIStr, RequestInfoT *RequestInfo,
+		  RequestFieldsT *RequestFields)
+{
+  text_t protocol, machine, rest;
+  int port;
+
+  if (RequestFields->ContentLength > 0) {
+    // POST data
+    URIStr.push_back('?');
+    for (int i = 0; i < RequestFields->ContentLength; ++i) {
+      URIStr.push_back(RequestFields->Content[i]);
+    }
+  }
+  
+  if (parse_url(URIStr, protocol, machine, &port, rest)!=http_ok) {
+    // Alter local file request to address 'gsdl'
+    if (*(URIStr.begin()) != '/') URIStr = "http://gsdl/" + URIStr;
+    else URIStr = "http://gsdl" + URIStr;
+    parse_url(URIStr, protocol, machine, &port, rest);
+  }
+
+  if (machine == "gsdl") {
+    // a local file request
+    handle_server_request(rest, RequestInfo, RequestFields);
+    
+  } else {
+    send_retrieve_error(404, "File not found",
+			"Could not find the local file requested", RequestInfo);
+  }
+  
+  return 1;
+}
Index: /gsdl/trunk/runtime-src/src/w32server/cgiwrapper.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/cgiwrapper.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/cgiwrapper.h	(revision 16571)
@@ -0,0 +1,49 @@
+/**********************************************************************
+ *
+ * cgiwrapper.h -- windows local library cgiwrapper
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef CGIWRAPPER_H
+#define CGIWRAPPER_H
+
+#include "httpreq.h"
+#include "locate.h"
+#include "receptionist.h"
+
+// the number of times the library has been accessed
+extern int libaccessnum;
+
+int ExamineURIStr(text_t &URIStr,RequestInfoT *RequestInfo,
+		  RequestFieldsT *RequestFields);
+
+// reads any configure file that has been set up and
+// sets up the library
+// returns 1 if successful, 0 if unsuccessful
+int gsdl_init (bool atStartup = true);
+
+// returns 0 if the directories cant be found
+// and the user wants to quit (it returns 1
+// if everything is ok)
+int cstrcheckdir (char *cstrthedir);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/w32server/conftools.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/conftools.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/conftools.cpp	(revision 16571)
@@ -0,0 +1,55 @@
+/**********************************************************************
+ *
+ * conftools.cpp
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "text_t.h"
+#include "conftools.h"
+
+int write_confline (ofstream &fileout, const text_t &key, const text_t value) {
+  if (key.empty() || value.empty()) return -1;
+  outconvertclass text_t2ascii;
+  fileout << text_t2ascii << key << "=" << value << "\n";
+  return 0;
+}
+
+int get_confline (ifstream &filein, text_t &key, text_t &value) {
+  if (filein.eof()) return -1;
+
+  key.clear();
+  value.clear();
+  char c;
+  filein.get(c);
+
+  int foundeq = 0;
+  while (!filein.eof() && c != '\n') {
+    if (!foundeq && c == '=') {foundeq = 1; filein.get(c);}
+
+    if (foundeq) value.push_back(c);
+    else key.push_back(c);
+    filein.get(c);
+  }
+  if (key.empty()) return -1;
+  return 0;
+} 
+
Index: /gsdl/trunk/runtime-src/src/w32server/conftools.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/conftools.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/conftools.h	(revision 16571)
@@ -0,0 +1,40 @@
+/**********************************************************************
+ *
+ * conftools.h
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef CONFTOOLS_H
+#define CONFTOOLS_H
+
+#if defined (GSDL_USE_OBJECTSPACE)
+#include <ospace/std/fstream>
+#elif defined (GSDL_USE_IOS_H)
+#include <fstream.h>
+#else
+#include <fstream>
+#endif
+
+int write_confline (ofstream &fileout, const text_t &key, const text_t value);
+int get_confline (ifstream &filein, text_t &key, text_t &value);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/w32server/d_winsock.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/d_winsock.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/d_winsock.cpp	(revision 16571)
@@ -0,0 +1,669 @@
+/**********************************************************************
+ *
+ * d_winsock.cpp
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include <windows.h>
+#include "d_winsock.h"
+
+
+typedef SOCKET (PASCAL FAR *accept_Type)(SOCKET s, struct sockaddr FAR *addr, 
+					 int FAR *addrlen);
+typedef int (PASCAL FAR *bind_Type)(SOCKET s, const struct sockaddr FAR *addr, int namelen);
+typedef int (PASCAL FAR *closesocket_Type)(SOCKET s);
+typedef int (PASCAL FAR *connect_Type)(SOCKET s, const struct sockaddr FAR *name, 
+				       int namelen);
+typedef int (PASCAL FAR *ioctlsocket_Type)(SOCKET s, long cmd, u_long FAR *argp);
+typedef int (PASCAL FAR *getpeername_Type)(SOCKET s, struct sockaddr FAR *name,
+					   int FAR * namelen);
+typedef int (PASCAL FAR *getsockname_Type)(SOCKET s, struct sockaddr FAR *name,
+					   int FAR * namelen);
+typedef int (PASCAL FAR *getsockopt_Type)(SOCKET s, int level, int optname,
+					  char FAR * optval, int FAR *optlen);
+typedef u_long (PASCAL FAR *htonl_Type)(u_long hostlong);
+typedef u_short (PASCAL FAR *htons_Type)(u_short hostshort);
+typedef unsigned long (PASCAL FAR *inet_addr_Type)(const char FAR * cp);
+typedef char FAR * (PASCAL FAR *inet_ntoa_Type)(struct in_addr in);
+typedef int (PASCAL FAR *listen_Type)(SOCKET s, int backlog);
+typedef u_long (PASCAL FAR *ntohl_Type)(u_long netlong);
+typedef u_short (PASCAL FAR *ntohs_Type)(u_short netshort);
+typedef int (PASCAL FAR *recv_Type)(SOCKET s, char FAR * buf, int len, int flags);
+typedef int (PASCAL FAR *recvfrom_Type)(SOCKET s, char FAR * buf, int len, int flags,
+					struct sockaddr FAR *from, int FAR * fromlen);
+typedef int (PASCAL FAR *select_Type)(int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
+				      fd_set FAR *exceptfds, const struct timeval FAR *timeout);
+typedef int (PASCAL FAR *send_Type)(SOCKET s, const char FAR * buf, int len, int flags);
+typedef int (PASCAL FAR *sendto_Type)(SOCKET s, const char FAR * buf, int len, int flags,
+				      const struct sockaddr FAR *to, int tolen);
+typedef int (PASCAL FAR *setsockopt_Type)(SOCKET s, int level, int optname,
+					  const char FAR * optval, int optlen);
+typedef int (PASCAL FAR *shutdown_Type)(SOCKET s, int how);
+typedef SOCKET (PASCAL FAR *socket_Type)(int af, int type, int protocol);
+typedef struct hostent FAR * (PASCAL FAR *gethostbyaddr_Type)(const char FAR * addr,
+							      int len, int type);
+typedef struct hostent FAR * (PASCAL FAR *gethostbyname_Type)(const char FAR * name);
+typedef int (PASCAL FAR *gethostname_Type) (char FAR * name, int namelen);
+typedef struct servent FAR * (PASCAL FAR *getservbyport_Type)(int port, const char FAR * proto);
+typedef struct servent FAR * (PASCAL FAR *getservbyname_Type)(const char FAR * name,
+							      const char FAR * proto);
+typedef struct protoent FAR * (PASCAL FAR *getprotobynumber_Type)(int proto);
+typedef struct protoent FAR * (PASCAL FAR *getprotobyname_Type)(const char FAR * name);
+typedef int (PASCAL FAR *WSAStartup_Type)(WORD wVersionRequired, LPWSADATA lpWSAData);
+typedef int (PASCAL FAR *WSACleanup_Type)(void);
+typedef void (PASCAL FAR *WSASetLastError_Type)(int iError);
+typedef int (PASCAL FAR *WSAGetLastError_Type)(void);
+typedef BOOL (PASCAL FAR *WSAIsBlocking_Type)(void);
+typedef int (PASCAL FAR *WSAUnhookBlockingHook_Type)(void);
+typedef FARPROC (PASCAL FAR *WSASetBlockingHook_Type)(FARPROC lpBlockFunc);
+typedef int (PASCAL FAR *WSACancelBlockingCall_Type)(void);
+typedef HANDLE (PASCAL FAR *WSAAsyncGetServByName_Type)(HWND hWnd, u_int wMsg,
+							const char FAR * name,
+							const char FAR * proto,
+							char FAR * buf, int buflen);
+typedef HANDLE (PASCAL FAR *WSAAsyncGetServByPort_Type)(HWND hWnd, u_int wMsg, int port,
+							const char FAR * proto, char FAR * buf,
+							int buflen);
+typedef HANDLE (PASCAL FAR *WSAAsyncGetProtoByName_Type)(HWND hWnd, u_int wMsg,
+							 const char FAR * name, char FAR * buf,
+							 int buflen);
+typedef HANDLE (PASCAL FAR *WSAAsyncGetProtoByNumber_Type)(HWND hWnd, u_int wMsg,
+							   int number, char FAR * buf,
+							   int buflen);
+typedef HANDLE (PASCAL FAR *WSAAsyncGetHostByName_Type)(HWND hWnd, u_int wMsg,
+							const char FAR * name, char FAR * buf,
+							int buflen);
+typedef HANDLE (PASCAL FAR *WSAAsyncGetHostByAddr_Type)(HWND hWnd, u_int wMsg,
+							const char FAR * addr, int len, int type,
+							char FAR * buf, int buflen);
+typedef int (PASCAL FAR *WSACancelAsyncRequest_Type)(HANDLE hAsyncTaskHandle);
+typedef int (PASCAL FAR *WSAAsyncSelect_Type)(SOCKET s, HWND hWnd, u_int wMsg,
+					      long lEvent);
+
+
+
+static accept_Type accept_Ptr = NULL;
+static bind_Type bind_Ptr = NULL;
+static closesocket_Type closesocket_Ptr = NULL;
+static connect_Type connect_Ptr = NULL;
+static ioctlsocket_Type ioctlsocket_Ptr = NULL;
+static getpeername_Type getpeername_Ptr = NULL;
+static getsockname_Type getsockname_Ptr = NULL;
+static getsockopt_Type getsockopt_Ptr = NULL;
+static htonl_Type htonl_Ptr = NULL;
+static htons_Type htons_Ptr = NULL;
+static inet_addr_Type inet_addr_Ptr = NULL;
+static inet_ntoa_Type inet_ntoa_Ptr = NULL;
+static listen_Type listen_Ptr = NULL;
+static ntohl_Type ntohl_Ptr = NULL;
+static ntohs_Type ntohs_Ptr = NULL;
+static recv_Type recv_Ptr = NULL;
+static recvfrom_Type recvfrom_Ptr = NULL;
+static select_Type select_Ptr = NULL;
+static send_Type send_Ptr = NULL;
+static sendto_Type sendto_Ptr = NULL;
+static setsockopt_Type setsockopt_Ptr = NULL;
+static shutdown_Type shutdown_Ptr = NULL;
+static socket_Type socket_Ptr = NULL;
+static gethostbyaddr_Type gethostbyaddr_Ptr = NULL;
+static gethostbyname_Type gethostbyname_Ptr = NULL;
+static gethostname_Type gethostname_Ptr = NULL;
+static getservbyport_Type getservbyport_Ptr = NULL;
+static getservbyname_Type getservbyname_Ptr = NULL;
+static getprotobynumber_Type getprotobynumber_Ptr = NULL;
+static getprotobyname_Type getprotobyname_Ptr = NULL;
+static WSAStartup_Type WSAStartup_Ptr = NULL;
+static WSACleanup_Type WSACleanup_Ptr = NULL;
+static WSASetLastError_Type WSASetLastError_Ptr = NULL;
+static WSAGetLastError_Type WSAGetLastError_Ptr = NULL;
+static WSAIsBlocking_Type WSAIsBlocking_Ptr = NULL;
+static WSAUnhookBlockingHook_Type WSAUnhookBlockingHook_Ptr = NULL;
+static WSASetBlockingHook_Type WSASetBlockingHook_Ptr = NULL;
+static WSACancelBlockingCall_Type WSACancelBlockingCall_Ptr = NULL;
+static WSAAsyncGetServByName_Type WSAAsyncGetServByName_Ptr = NULL;
+static WSAAsyncGetServByPort_Type WSAAsyncGetServByPort_Ptr = NULL;
+static WSAAsyncGetProtoByName_Type WSAAsyncGetProtoByName_Ptr = NULL;
+static WSAAsyncGetProtoByNumber_Type WSAAsyncGetProtoByNumber_Ptr = NULL;
+static WSAAsyncGetHostByName_Type WSAAsyncGetHostByName_Ptr = NULL;
+static WSAAsyncGetHostByAddr_Type WSAAsyncGetHostByAddr_Ptr = NULL;
+static WSACancelAsyncRequest_Type WSACancelAsyncRequest_Ptr = NULL;
+static WSAAsyncSelect_Type WSAAsyncSelect_Ptr = NULL;
+
+
+static HINSTANCE wsock32lib = NULL;
+static HINSTANCE winsocklib = NULL;
+
+
+
+// set all the pointers back to null
+static void ResetWSPtrs () {
+  accept_Ptr = NULL;
+  bind_Ptr = NULL;
+  closesocket_Ptr = NULL;
+  connect_Ptr = NULL;
+  ioctlsocket_Ptr = NULL;
+  getpeername_Ptr = NULL;
+  getsockname_Ptr = NULL;
+  getsockopt_Ptr = NULL;
+  htonl_Ptr = NULL;
+  htons_Ptr = NULL;
+  inet_addr_Ptr = NULL;
+  inet_ntoa_Ptr = NULL;
+  listen_Ptr = NULL;
+  ntohl_Ptr = NULL;
+  ntohs_Ptr = NULL;
+  recv_Ptr = NULL;
+  recvfrom_Ptr = NULL;
+  select_Ptr = NULL;
+  send_Ptr = NULL;
+  sendto_Ptr = NULL;
+  setsockopt_Ptr = NULL;
+  shutdown_Ptr = NULL;
+  socket_Ptr = NULL;
+  gethostbyaddr_Ptr = NULL;
+  gethostbyname_Ptr = NULL;
+  gethostname_Ptr = NULL;
+  getservbyport_Ptr = NULL;
+  getservbyname_Ptr = NULL;
+  getprotobynumber_Ptr = NULL;
+  getprotobyname_Ptr = NULL;
+  WSAStartup_Ptr = NULL;
+  WSACleanup_Ptr = NULL;
+  WSASetLastError_Ptr = NULL;
+  WSAGetLastError_Ptr = NULL;
+  WSAIsBlocking_Ptr = NULL;
+  WSAUnhookBlockingHook_Ptr = NULL;
+  WSASetBlockingHook_Ptr = NULL;
+  WSACancelBlockingCall_Ptr = NULL;
+  WSAAsyncGetServByName_Ptr = NULL;
+  WSAAsyncGetServByPort_Ptr = NULL;
+  WSAAsyncGetProtoByName_Ptr = NULL;
+  WSAAsyncGetProtoByNumber_Ptr = NULL;
+  WSAAsyncGetHostByName_Ptr = NULL;
+  WSAAsyncGetHostByAddr_Ptr = NULL;
+  WSACancelAsyncRequest_Ptr = NULL;
+  WSAAsyncSelect_Ptr = NULL;
+}
+
+// get the pointers to all the socket functions
+static void SetupWSPtrs (HINSTANCE socketlib) {
+  if (socketlib == NULL) return;
+
+  accept_Ptr = (accept_Type)GetProcAddress(socketlib,"accept");
+  bind_Ptr = (bind_Type)GetProcAddress(socketlib,"bind");
+  closesocket_Ptr = (closesocket_Type)GetProcAddress(socketlib,"closesocket");
+  connect_Ptr = (connect_Type)GetProcAddress(socketlib,"connect");
+  ioctlsocket_Ptr = (ioctlsocket_Type)GetProcAddress(socketlib,"ioctlsocket");
+  getpeername_Ptr = (getpeername_Type)GetProcAddress(socketlib,"getpeername");
+  getsockname_Ptr = (getsockname_Type)GetProcAddress(socketlib,"getsockname");
+  getsockopt_Ptr = (getsockopt_Type)GetProcAddress(socketlib,"getsockopt");
+  htonl_Ptr = (htonl_Type)GetProcAddress(socketlib,"htonl");
+  htons_Ptr = (htons_Type)GetProcAddress(socketlib,"htons");
+  inet_addr_Ptr = (inet_addr_Type)GetProcAddress(socketlib,"inet_addr");
+  inet_ntoa_Ptr = (inet_ntoa_Type)GetProcAddress(socketlib,"inet_ntoa");
+  listen_Ptr = (listen_Type)GetProcAddress(socketlib,"listen");
+  ntohl_Ptr = (ntohl_Type)GetProcAddress(socketlib,"ntohl");
+  ntohs_Ptr = (ntohs_Type)GetProcAddress(socketlib,"ntohs");
+  recv_Ptr = (recv_Type)GetProcAddress(socketlib,"recv");
+  recvfrom_Ptr = (recvfrom_Type)GetProcAddress(socketlib,"recvfrom");
+  select_Ptr = (select_Type)GetProcAddress(socketlib,"select");
+  send_Ptr = (send_Type)GetProcAddress(socketlib,"send");
+  sendto_Ptr = (sendto_Type)GetProcAddress(socketlib,"sendto");
+  setsockopt_Ptr = (setsockopt_Type)GetProcAddress(socketlib,"setsockopt");
+  shutdown_Ptr = (shutdown_Type)GetProcAddress(socketlib,"shutdown");
+  socket_Ptr = (socket_Type)GetProcAddress(socketlib,"socket");
+  gethostbyaddr_Ptr = (gethostbyaddr_Type)GetProcAddress(socketlib,"gethostbyaddr");
+  gethostbyname_Ptr = (gethostbyname_Type)GetProcAddress(socketlib,"gethostbyname");
+  gethostname_Ptr = (gethostname_Type)GetProcAddress(socketlib,"gethostname");
+  getservbyport_Ptr = (getservbyport_Type)GetProcAddress(socketlib,"getservbyport");
+  getservbyname_Ptr = (getservbyname_Type)GetProcAddress(socketlib,"getservbyname");
+  getprotobynumber_Ptr = (getprotobynumber_Type)GetProcAddress(socketlib,"getprotobynumber");
+  getprotobyname_Ptr = (getprotobyname_Type)GetProcAddress(socketlib,"getprotobyname");
+  WSAStartup_Ptr = (WSAStartup_Type)GetProcAddress(socketlib,"WSAStartup");
+  WSACleanup_Ptr = (WSACleanup_Type)GetProcAddress(socketlib,"WSACleanup");
+  WSASetLastError_Ptr = (WSASetLastError_Type)GetProcAddress(socketlib,"WSASetLastError");
+  WSAGetLastError_Ptr = (WSAGetLastError_Type)GetProcAddress(socketlib,"WSAGetLastError");
+  WSAIsBlocking_Ptr = (WSAIsBlocking_Type)GetProcAddress(socketlib,"WSAIsBlocking");
+  WSAUnhookBlockingHook_Ptr = 
+    (WSAUnhookBlockingHook_Type)GetProcAddress(socketlib,"WSAUnhookBlockingHook");
+  WSASetBlockingHook_Ptr = 
+    (WSASetBlockingHook_Type)GetProcAddress(socketlib,"WSASetBlockingHook");
+  WSACancelBlockingCall_Ptr = 
+    (WSACancelBlockingCall_Type)GetProcAddress(socketlib,"WSACancelBlockingCall");
+  WSAAsyncGetServByName_Ptr = 
+    (WSAAsyncGetServByName_Type)GetProcAddress(socketlib,"WSAAsyncGetServByName");
+  WSAAsyncGetServByPort_Ptr = 
+    (WSAAsyncGetServByPort_Type)GetProcAddress(socketlib,"WSAAsyncGetServByPort");
+  WSAAsyncGetProtoByName_Ptr = 
+    (WSAAsyncGetProtoByName_Type)GetProcAddress(socketlib,"WSAAsyncGetProtoByName");
+  WSAAsyncGetProtoByNumber_Ptr = 
+    (WSAAsyncGetProtoByNumber_Type)GetProcAddress(socketlib,"WSAAsyncGetProtoByNumber");
+  WSAAsyncGetHostByName_Ptr = 
+    (WSAAsyncGetHostByName_Type)GetProcAddress(socketlib,"WSAAsyncGetHostByName");
+  WSAAsyncGetHostByAddr_Ptr = 
+    (WSAAsyncGetHostByAddr_Type)GetProcAddress(socketlib,"WSAAsyncGetHostByAddr");
+  WSACancelAsyncRequest_Ptr = 
+    (WSACancelAsyncRequest_Type)GetProcAddress(socketlib,"WSACancelAsyncRequest");
+  WSAAsyncSelect_Ptr = (WSAAsyncSelect_Type)GetProcAddress(socketlib,"WSAAsyncSelect");
+}
+
+
+
+// expects path to be NULL, a empty string, or a path which ends in a slash
+// returns D_NOERROR on success,
+// D_ERR_UNEXPECTED or D_ERR_LOADFAILED on failure
+int d_LoadWinsock (char *path) {
+  char dllname[2048]; // HARD LIMIT!!!!
+  OSVERSIONINFO osver;
+
+  if ((wsock32lib != NULL) || (winsocklib != NULL)) return D_ERR_UNEXPECTED;
+
+  // set the error mode so that no nasty dialog boxes come
+  // up when things aren't installed
+  int olderrormode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);
+
+  // get the operating system version information
+  memset(&osver, 0, sizeof(OSVERSIONINFO));
+  osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+  if (!GetVersionEx(&osver)) {
+    SetErrorMode(olderrormode);
+    return D_ERR_UNEXPECTED;
+  }
+
+  // see if we should load winsock before wsock32
+  if ((osver.dwPlatformId == VER_PLATFORM_WIN32s) && (path != NULL)) {
+    strcpy (dllname, path);
+    strcat (dllname, "winsock.dll");
+
+    // attempt to load the library
+    winsocklib = LoadLibrary (dllname);
+    if (winsocklib == NULL) {
+      SetErrorMode(olderrormode);
+      return D_ERR_LOADFAILED;
+    }
+  }
+
+  // attempt to load wsock32
+  int err = D_NOERROR;
+  dllname[0] = '\0';
+  if ((osver.dwPlatformId != VER_PLATFORM_WIN32s) && (path != NULL)) {
+    strcpy (dllname, path);
+  }
+  strcat (dllname, "wsock32.dll");
+  wsock32lib = LoadLibrary (dllname);
+  if (wsock32lib == NULL) err = D_ERR_LOADFAILED;
+  else SetupWSPtrs (wsock32lib);
+
+
+  // perform a few tests
+
+  // first try starting-up (and check the szDescription field)
+  if (err == D_NOERROR) {
+    WSADATA Data;
+    memset(&Data, 0, sizeof(WSADATA));
+    if ((d_WSAStartup(257, &Data) != 0) ||
+	(Data.szDescription == NULL) || 
+	(Data.szDescription[0] == '\0'))
+      err = D_ERR_LOADFAILED;
+  }
+
+  // next try setting and getting an error
+  if (err == D_NOERROR) {
+    d_WSASetLastError (WSAENOTSOCK);
+    if (d_WSAGetLastError () != WSAENOTSOCK) err = D_ERR_LOADFAILED;
+    d_WSASetLastError (0);
+  }
+
+  // last try cleaning up (if an error occurs here we might
+  // not be able to unload anything)
+  if ((err == D_NOERROR) && (d_WSACleanup() == SOCKET_ERROR))
+    err = D_ERR_LOADFAILED;
+
+  // if an error occurred then we need to unload everything
+  if (err != D_NOERROR) d_UnloadWinsock ();
+
+  SetErrorMode(olderrormode);
+  return err;
+}
+
+// returns D_NOERROR on success,
+// D_ERR_FREELIBFAILED on failure
+int d_UnloadWinsock () {
+  int err = D_NOERROR;
+
+  // unload wsock32
+  if ((wsock32lib != NULL) && !FreeLibrary (wsock32lib)) {
+    err = D_ERR_FREELIBFAILED;
+  }
+  wsock32lib = NULL;
+
+  // unload winsock
+  if ((winsocklib != NULL) && !FreeLibrary (winsocklib)) {
+    err = D_ERR_FREELIBFAILED;
+  }
+  winsocklib = NULL;
+  
+  // reset all the function pointers
+  ResetWSPtrs ();
+
+  return err;
+}
+
+
+
+
+// socket functions, these just call the dynamically loaded version
+
+SOCKET d_accept (SOCKET s, struct sockaddr *addr, int *addrlen) {
+  if (accept_Ptr != NULL) 
+    return (*accept_Ptr)(s, addr, addrlen);
+  return INVALID_SOCKET; // error winsock not loaded
+}
+
+int d_bind (SOCKET s, const struct sockaddr *addr, int namelen) {
+  if (bind_Ptr != NULL) 
+    return (*bind_Ptr)(s, addr, namelen);
+  return WSANOTINITIALISED; // error winsock not loaded
+}
+
+int d_closesocket (SOCKET s) {
+  if (closesocket_Ptr != NULL) 
+    return (*closesocket_Ptr)(s);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_connect (SOCKET s, const struct sockaddr *name, int namelen) {
+  if (connect_Ptr != NULL) 
+    return (*connect_Ptr)(s, name, namelen);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_ioctlsocket (SOCKET s, long cmd, u_long *argp) {
+  if (ioctlsocket_Ptr != NULL) 
+    return (*ioctlsocket_Ptr)(s, cmd, argp);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_getpeername (SOCKET s, struct sockaddr *name, int *namelen) {
+  if (getpeername_Ptr != NULL) 
+    return (*getpeername_Ptr)(s, name, namelen);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_getsockname (SOCKET s, struct sockaddr *name, int *namelen) {
+  if (getsockname_Ptr != NULL) 
+    return (*getsockname_Ptr)(s, name, namelen);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_getsockopt (SOCKET s, int level, int optname, char *optval, int *optlen) {
+  if (getsockopt_Ptr != NULL) 
+    return (*getsockopt_Ptr)(s, level, optname, optval, optlen);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+u_long d_htonl (u_long hostlong) {
+  if (htonl_Ptr != NULL) 
+    return (*htonl_Ptr)(hostlong);
+  return hostlong; // error winsock not loaded
+}
+
+u_short d_htons (u_short hostshort) {
+  if (htons_Ptr != NULL) 
+    return (*htons_Ptr)(hostshort);
+  return hostshort; // error winsock not loaded
+}
+
+unsigned long d_inet_addr (const char *cp) {
+  if (inet_addr_Ptr != NULL) 
+    return (*inet_addr_Ptr)(cp);
+  return INADDR_NONE; // error winsock not loaded
+}
+
+char *d_inet_ntoa (struct in_addr in) {
+  if (inet_ntoa_Ptr != NULL) 
+    return (*inet_ntoa_Ptr)(in);
+  return NULL; // error winsock not loaded
+}
+
+int d_listen (SOCKET s, int backlog) {
+  if (listen_Ptr != NULL) 
+    return (*listen_Ptr)(s, backlog);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+u_long d_ntohl (u_long netlong) {
+  if (ntohl_Ptr != NULL) 
+    return (*ntohl_Ptr)(netlong);
+  return netlong; // error winsock not loaded
+}
+
+u_short d_ntohs (u_short netshort) {
+  if (ntohs_Ptr != NULL) 
+    return (*ntohs_Ptr)(netshort);
+  return netshort; // error winsock not loaded
+}
+
+int d_recv (SOCKET s, char *buf, int len, int flags) {
+  if (recv_Ptr != NULL) 
+    return (*recv_Ptr)(s, buf, len, flags);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_recvfrom (SOCKET s, char *buf, int len, int flags,
+		struct sockaddr *from, int *fromlen) {
+  if (recvfrom_Ptr != NULL) 
+    return (*recvfrom_Ptr)(s, buf, len, flags, from, fromlen);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_select (int nfds, fd_set *readfds, fd_set *writefds,
+	      fd_set *exceptfds, const struct timeval *timeout) {
+  if (select_Ptr != NULL) 
+    return (*select_Ptr)(nfds, readfds, writefds, exceptfds, timeout);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_send (SOCKET s, const char *buf, int len, int flags) {
+  if (send_Ptr != NULL) 
+    return (*send_Ptr)(s, buf, len, flags);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_sendto (SOCKET s, const char *buf, int len, int flags,
+	      const struct sockaddr *to, int tolen) {
+  if (sendto_Ptr != NULL) 
+    return (*sendto_Ptr)(s, buf, len, flags, to, tolen);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_setsockopt (SOCKET s, int level, int optname,
+		  const char *optval, int optlen) {
+  if (setsockopt_Ptr != NULL) 
+    return (*setsockopt_Ptr)(s, level, optname, optval, optlen);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_shutdown (SOCKET s, int how) {
+  if (shutdown_Ptr != NULL) 
+    return (*shutdown_Ptr)(s, how);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+SOCKET d_socket (int af, int type, int protocol) {
+  if (socket_Ptr != NULL) 
+    return (*socket_Ptr)(af, type, protocol);
+  return INVALID_SOCKET; // error winsock not loaded
+}
+
+hostent *d_gethostbyaddr(const char *addr, int len, int type) {
+  if (gethostbyaddr_Ptr != NULL) 
+    return (*gethostbyaddr_Ptr)(addr, len, type);
+  return NULL; // error winsock not loaded
+}
+
+hostent *d_gethostbyname(const char *name) {
+  if (gethostbyname_Ptr != NULL) 
+    return (*gethostbyname_Ptr)(name);
+  return NULL; // error winsock not loaded
+}
+
+int d_gethostname (char *name, int namelen) {
+  if (gethostname_Ptr != NULL) 
+    return (*gethostname_Ptr)(name, namelen);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+servent *d_getservbyport(int port, const char *proto) {
+  if (getservbyport_Ptr != NULL) 
+    return (*getservbyport_Ptr)(port, proto);
+  return NULL; // error winsock not loaded
+}
+
+servent *d_getservbyname(const char *name, const char *proto) {
+  if (getservbyname_Ptr != NULL) 
+    return (*getservbyname_Ptr)(name, proto);
+  return NULL; // error winsock not loaded
+}
+
+protoent *d_getprotobynumber(int proto) {
+  if (getprotobynumber_Ptr != NULL) 
+    return (*getprotobynumber_Ptr)(proto);
+  return NULL; // error winsock not loaded
+}
+
+protoent *d_getprotobyname(const char *name) {
+  if (getprotobyname_Ptr != NULL) 
+    return (*getprotobyname_Ptr)(name);
+  return NULL; // error winsock not loaded
+}
+
+int d_WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData) {
+  if (WSAStartup_Ptr != NULL) 
+    return (*WSAStartup_Ptr)(wVersionRequired, lpWSAData);
+  return WSASYSNOTREADY; // error winsock not loaded
+}
+
+int d_WSACleanup(void) {
+  if (WSACleanup_Ptr != NULL) 
+    return (*WSACleanup_Ptr)();
+  return WSANOTINITIALISED; // error winsock not loaded
+}
+
+void d_WSASetLastError(int iError) {
+  if (WSASetLastError_Ptr != NULL) (*WSASetLastError_Ptr)(iError);
+}
+
+int d_WSAGetLastError(void) {
+  if (WSAGetLastError_Ptr != NULL) 
+    return (*WSAGetLastError_Ptr)();
+  return WSANOTINITIALISED; // error winsock not loaded
+}
+
+BOOL d_WSAIsBlocking(void) {
+  if (WSAIsBlocking_Ptr != NULL) 
+    return (*WSAIsBlocking_Ptr)();
+  return FALSE; // error winsock not loaded
+}
+
+int d_WSAUnhookBlockingHook(void) {
+  if (WSAUnhookBlockingHook_Ptr != NULL) 
+    return (*WSAUnhookBlockingHook_Ptr)();
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+FARPROC d_WSASetBlockingHook(FARPROC lpBlockFunc) {
+  if (WSASetBlockingHook_Ptr != NULL) 
+    return (*WSASetBlockingHook_Ptr)(lpBlockFunc);
+  return NULL; // error winsock not loaded
+}
+
+int d_WSACancelBlockingCall(void) {
+  if (WSACancelBlockingCall_Ptr != NULL) 
+    return (*WSACancelBlockingCall_Ptr)();
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+HANDLE d_WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
+			       const char *name,
+			       const char *proto,
+			       char *buf, int buflen) {
+  if (WSAAsyncGetServByName_Ptr != NULL) 
+    return (*WSAAsyncGetServByName_Ptr)(hWnd, wMsg, name, proto, buf, buflen);
+  return NULL; // error winsock not loaded
+}
+
+HANDLE d_WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
+			       const char *proto, char *buf,
+			       int buflen) {
+  if (WSAAsyncGetServByPort_Ptr != NULL) 
+    return (*WSAAsyncGetServByPort_Ptr)(hWnd, wMsg, port, proto, buf, buflen);
+  return NULL; // error winsock not loaded
+}
+
+HANDLE d_WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
+				const char *name, char *buf,
+				int buflen) {
+  if (WSAAsyncGetProtoByName_Ptr != NULL) 
+    return (*WSAAsyncGetProtoByName_Ptr)(hWnd, wMsg, name, buf, buflen);
+  return NULL; // error winsock not loaded
+}
+
+HANDLE d_WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
+				  int number, char *buf,
+				  int buflen) {
+  if (WSAAsyncGetProtoByNumber_Ptr != NULL) 
+    return (*WSAAsyncGetProtoByNumber_Ptr)(hWnd, wMsg, number, buf, buflen);
+  return NULL; // error winsock not loaded
+}
+
+HANDLE d_WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
+			       const char *name, char *buf,
+			       int buflen) {
+  if (WSAAsyncGetHostByName_Ptr != NULL) 
+    return (*WSAAsyncGetHostByName_Ptr)(hWnd, wMsg, name, buf, buflen);
+  return NULL; // error winsock not loaded
+}
+
+HANDLE d_WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
+                                        const char *addr, int len, int type,
+                                        char *buf, int buflen) {
+  if (WSAAsyncGetHostByAddr_Ptr != NULL) 
+    return (*WSAAsyncGetHostByAddr_Ptr)(hWnd, wMsg, addr, len, type, buf, buflen);
+  return NULL; // error winsock not loaded
+}
+
+int d_WSACancelAsyncRequest(HANDLE hAsyncTaskHandle) {
+  if (WSACancelAsyncRequest_Ptr != NULL) 
+    return (*WSACancelAsyncRequest_Ptr)(hAsyncTaskHandle);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
+int d_WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
+                               long lEvent) {
+  if (WSAAsyncSelect_Ptr != NULL) 
+    return (*WSAAsyncSelect_Ptr)(s, hWnd, wMsg, lEvent);
+  return SOCKET_ERROR; // error winsock not loaded
+}
+
Index: /gsdl/trunk/runtime-src/src/w32server/d_winsock.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/d_winsock.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/d_winsock.h	(revision 16571)
@@ -0,0 +1,120 @@
+/**********************************************************************
+ *
+ * d_winsock.h
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef D_WINSOCK_H
+#define D_WINSOCK_H
+
+/* get most definitions from the real winsock */
+#include <winsock.h>
+
+#define D_NOERROR           0
+#define D_ERR_UNEXPECTED    1
+#define D_ERR_LOADFAILED    2
+#define D_ERR_FREELIBFAILED 3
+
+// d_LoadWinsock must be called before an normal winsock
+// functions
+
+// expects path to be NULL, a empty string, or a path which ends in a slash
+// returns D_NOERROR on success,
+// D_ERR_UNEXPECTED or D_ERR_LOADFAILED on failure
+int d_LoadWinsock (char *path);
+
+// returns D_NOERROR on success,
+// D_ERR_FREELIBFAILED on failure
+int d_UnloadWinsock ();
+
+// dynamically loaded versions of the winsock functions
+
+SOCKET d_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
+int d_bind (SOCKET s, const struct sockaddr *addr, int namelen);
+int d_closesocket (SOCKET s);
+int d_connect (SOCKET s, const struct sockaddr *name, int namelen);
+int d_ioctlsocket (SOCKET s, long cmd, u_long *argp);
+int d_getpeername (SOCKET s, struct sockaddr *name, int *namelen);
+int d_getsockname (SOCKET s, struct sockaddr *name, int *namelen);
+int d_getsockopt (SOCKET s, int level, int optname, char *optval, int *optlen);
+u_long d_htonl (u_long hostlong);
+u_short d_htons (u_short hostshort);
+unsigned long d_inet_addr (const char *cp);
+char *d_inet_ntoa (struct in_addr in);
+int d_listen (SOCKET s, int backlog);
+u_long d_ntohl (u_long netlong);
+u_short d_ntohs (u_short netshort);
+int d_recv (SOCKET s, char *buf, int len, int flags);
+int d_recvfrom (SOCKET s, char *buf, int len, int flags,
+		struct sockaddr *from, int *fromlen);
+int d_select (int nfds, fd_set *readfds, fd_set *writefds,
+	      fd_set *exceptfds, const struct timeval *timeout);
+int d_send (SOCKET s, const char *buf, int len, int flags);
+int d_sendto (SOCKET s, const char *buf, int len, int flags,
+	      const struct sockaddr *to, int tolen);
+int d_setsockopt (SOCKET s, int level, int optname,
+		  const char *optval, int optlen);
+int d_shutdown (SOCKET s, int how);
+SOCKET d_socket (int af, int type, int protocol);
+
+hostent *d_gethostbyaddr(const char *addr, int len, int type);
+hostent *d_gethostbyname(const char *name);
+int d_gethostname (char *name, int namelen);
+servent *d_getservbyport(int port, const char *proto);
+servent *d_getservbyname(const char *name, const char *proto);
+protoent *d_getprotobynumber(int proto);
+protoent *d_getprotobyname(const char *name);
+
+int d_WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
+int d_WSACleanup(void);
+void d_WSASetLastError(int iError);
+int d_WSAGetLastError(void);
+BOOL d_WSAIsBlocking(void);
+int d_WSAUnhookBlockingHook(void);
+FARPROC d_WSASetBlockingHook(FARPROC lpBlockFunc);
+int d_WSACancelBlockingCall(void);
+HANDLE d_WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
+			       const char *name,
+			       const char *proto,
+			       char *buf, int buflen);
+HANDLE d_WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
+			       const char *proto, char *buf,
+			       int buflen);
+HANDLE d_WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
+				const char *name, char *buf,
+				int buflen);
+HANDLE d_WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
+				  int number, char *buf,
+				  int buflen);
+HANDLE d_WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
+			       const char *name, char *buf,
+			       int buflen);
+HANDLE d_WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
+			       const char *addr, int len, int type,
+			       char *buf, int buflen);
+int d_WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
+int d_WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
+		     long lEvent);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/w32server/fnord.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/fnord.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/fnord.cpp	(revision 16571)
@@ -0,0 +1,1191 @@
+/**********************************************************************
+ *
+ * fnord.cpp
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "text_t.h"
+#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <memory.h>
+#pragma hdrstop
+#include "netio.h"
+#include "settings.h"
+#include "httpsrv.h"
+#include "resource.h"
+#include "locate.h"
+#include "cgiwrapper.h"
+#include "startbrowser.h"
+#include "d_winsock.h"
+
+#define MAINWINDOWWIDTH 400
+#define MAINWINDOWHEIGHT 200
+
+#define WASTEHEIGHT 44  // Error in ht due to caption and menu bar
+#define WASTEWIDTH 6
+#define SPACERWIDTH 5
+
+// size and position of the collection title
+#define COLTITLEWIDTH 351
+#define COLTITLEHEIGHT 35
+#define COLTITLEX ((MAINWINDOWWIDTH-COLTITLEWIDTH)/2)
+#define COLTITLEY 10
+
+// size and position of the version string
+#define VERSIONWIDTH MAINWINDOWWIDTH
+#define VERSIONHEIGHT 20
+#define VERSIONX 0
+#define VERSIONY (COLTITLEY+COLTITLEHEIGHT)
+
+// size and position of the Greenstone digital library logo
+#define LOGOWIDTH 135
+#define LOGOHEIGHT 55
+#define LOGOX (MAINWINDOWWIDTH-(LOGOWIDTH+SPACERWIDTH))
+#define LOGOY (MAINWINDOWHEIGHT-(LOGOHEIGHT+SPACERWIDTH))
+
+// size and position of the enter button
+#define ENTERBUTTONWIDTH 160
+#define ENTERBUTTONHEIGHT 30
+#define ENTERBUTTONX SPACERWIDTH
+#define ENTERBUTTONY ((MAINWINDOWHEIGHT-(LOGOHEIGHT+SPACERWIDTH))-(ENTERBUTTONHEIGHT+SPACERWIDTH))
+
+// size and position of the enter string
+#define ENTERSTRINGX (ENTERBUTTONX+ENTERBUTTONWIDTH+SPACERWIDTH)
+#define ENTERSTRINGY ENTERBUTTONY
+#define ENTERSTRINGWIDTH (MAINWINDOWWIDTH-(ENTERBUTTONWIDTH+SPACERWIDTH+SPACERWIDTH+SPACERWIDTH))
+#define ENTERSTRINGHEIGHT ENTERBUTTONHEIGHT
+
+// size and position of the info string
+#define INFOWIDTH MAINWINDOWWIDTH
+#define INFOHEIGHT (MAINWINDOWHEIGHT-INFOY)
+#define INFOX 0
+#define INFOY ENTERBUTTONY
+
+// size and position of restricted buttons
+#define ALTERNATIVEBUTTONWIDTH 160
+#define ALTERNATIVEBUTTONHEIGHT 30
+#define ALTERNATIVEBUTTONX SPACERWIDTH
+#define ALTERNATIVEBUTTONY LOGOY
+
+#define INFOBUTTONWIDTH 30
+
+// size and position of restart button
+#define RESTARTBUTTONWIDTH 160
+#define RESTARTBUTTONHEIGHT 30
+#define RESTARTBUTTONX 50
+#define RESTARTBUTTONY (MAINWINDOWHEIGHT-RESTARTBUTTONHEIGHT-15)
+
+const char versionstring[] = "version " GSDL_VERSION;
+
+const char strnothing[] = "";
+const char strinit[] = "Initialising...";
+const char strsb[] = "Starting browser...";
+const char strrestartlib[] = "Press the 'Restart Library' button to start a browser\n"
+"and enter library";
+const char strenterlib[] = "Press this button to begin using\n"
+"the library";
+const char *enterstring = NULL; // points to the current enter string
+const char *infostring = NULL; // points to the current info string
+
+
+// globals to do with networking and browsers
+int have_networking = 0;
+int netscapeneeded = 0;
+char startbrowserdir[1024] = ""; // HARD LIMIT!!!!!
+
+
+// stats to do with the last time the enter library button was pressed
+// these stats are needed to make suggestions about the proxy
+int enterlib_libaccessnum = -1; // -1 = NA
+DWORD enterlib_time = 0;
+
+
+enum { undefined_window, console_window, plain_window }
+window_state;
+
+HDC coltitledc = NULL;
+HBITMAP defcoltitlebitmap = NULL, coltitlebitmap=NULL;
+
+HDC logodc=NULL;
+HBITMAP deflogobitmap=NULL, logobitmap=NULL;
+
+HWND GoButton = NULL;
+HWND Enter = NULL;
+// HWND EnterRestricted = NULL;
+// HWND InfoRestricted = NULL;
+int init_type = 0;
+int init_done = 0;
+
+
+// Added an argument so you can specify not to do any of the windows orientated clean up - jmt12 18/11/2003
+void finish_up(bool init_only) {
+  // remember the current preferences
+  write_settings("");
+
+  if(init_only) {
+    return;
+  }
+   
+ // Shutdown the HTTP server
+  EndHTTPServer();
+  
+  // Shutdown the main server modules
+  CleanUpNetIO();
+  //    RemoveFnordFromTray();
+  
+  // Unload the wsock32 dll
+  d_UnloadWinsock();
+  
+  // Clean up graphics stuff from window
+  
+  if (defcoltitlebitmap != NULL)
+    SelectObject (coltitledc, defcoltitlebitmap);
+  if (coltitlebitmap != NULL)
+    DeleteObject (coltitlebitmap);
+  if (coltitledc != NULL)
+    DeleteDC (coltitledc);
+  
+  if (deflogobitmap != NULL)
+    SelectObject (logodc, deflogobitmap);
+  if (logobitmap != NULL)
+    DeleteObject (logobitmap);
+  if (logodc != NULL)
+    DeleteDC (logodc);
+  
+  // Shutdown the main window
+  PostQuitMessage(0);
+}
+
+
+int overlap(int left, int top, int right, int bottom,
+            RECT &r2)
+{
+  if (left <= r2.right && r2.left <= right &&
+      top <= r2.bottom && r2.top <= bottom)
+    return 1;
+  else
+    return 0;
+}
+
+
+void paint_window (HDC pdc, RECT &updateRect) {
+  // make sure the various DCs are set up
+  if (coltitledc == NULL) {
+    coltitledc = CreateCompatibleDC(pdc);
+    defcoltitlebitmap = (HBITMAP)SelectObject (coltitledc, coltitlebitmap);
+  }
+  
+  if (logodc == NULL) {
+    logodc = CreateCompatibleDC(pdc);
+    deflogobitmap = (HBITMAP)SelectObject (logodc, logobitmap);
+  }
+
+  // remove any remaining sign of initial buttons
+  if (init_done && (overlap (ENTERBUTTONX, ENTERBUTTONY, ENTERBUTTONX+ENTERBUTTONWIDTH,
+		ALTERNATIVEBUTTONY+ALTERNATIVEBUTTONHEIGHT, updateRect))) {
+    RECT initRect;
+    initRect.left = ENTERBUTTONX;
+    initRect.top = ENTERBUTTONY;
+    initRect.right = ENTERBUTTONX+ENTERBUTTONWIDTH;
+    initRect.bottom = ALTERNATIVEBUTTONY+ALTERNATIVEBUTTONHEIGHT;
+    FillRect(pdc, &initRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
+  }
+
+  // update the collection title if needed
+  if (overlap(COLTITLEX, COLTITLEY,
+	      COLTITLEX+COLTITLEWIDTH, COLTITLEY+COLTITLEHEIGHT, 
+	      updateRect)) {
+    BitBlt (pdc, COLTITLEX, COLTITLEY, 
+	    COLTITLEX+COLTITLEWIDTH, COLTITLEY+COLTITLEHEIGHT,
+	    coltitledc, 0, 0, SRCCOPY);
+  }
+  
+  // update the version string if needed
+  if (overlap (VERSIONX, VERSIONY, 
+	       VERSIONX+VERSIONWIDTH, VERSIONY+VERSIONHEIGHT,
+	       updateRect)) {
+    RECT versionRect;
+    versionRect.left = VERSIONX;
+    versionRect.top = VERSIONY;
+    versionRect.right = VERSIONX+VERSIONWIDTH;
+    versionRect.bottom = VERSIONY+VERSIONHEIGHT;
+    DrawText(pdc, versionstring, -1, &versionRect, DT_CENTER);
+  }
+  
+  // decide what we want to draw
+  if (init_done && gsdl_show_console) {
+    // we want to draw a "console" window
+    if (window_state != console_window ||
+	overlap (text_rect.left, text_rect.top,
+		 text_rect.right, text_rect.bottom,
+		 updateRect)) {
+      refresh_console (pdc);
+    }
+    
+    window_state = console_window;
+    
+  } else {
+    // we want to draw a "plain" window
+    
+    // update the enter string if needed
+    if (overlap (ENTERSTRINGX, ENTERSTRINGY, ENTERSTRINGX+ENTERSTRINGWIDTH, 
+		 ENTERSTRINGY+ENTERSTRINGHEIGHT, updateRect)) {
+
+	RECT enterstringRect;
+	enterstringRect.left = ENTERSTRINGX;
+	enterstringRect.top = ENTERSTRINGY;
+	enterstringRect.right = ENTERSTRINGX+ENTERSTRINGWIDTH;
+	enterstringRect.bottom = ENTERSTRINGY+ENTERSTRINGHEIGHT;
+	FillRect(pdc, &enterstringRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
+
+	if ((enterstring != NULL) && (strlen(enterstring) > 0)) {
+      
+	  int cury = ENTERSTRINGY;
+	  int startline = 0, here = 0;
+	  while (enterstring[here] != '\0') {
+	    if (enterstring[here] < ' ') {
+	      if (here - startline > 0) {
+		// output the text
+		TextOut (pdc, ENTERSTRINGX, cury, 
+			 &enterstring[startline], here-startline);
+		cury += line_spacing;
+	      }
+	      startline = here+1;
+	    }
+	    ++here;
+	  }
+	  // output any remaining text
+	  if (here - startline > 0) {
+	    TextOut (pdc, ENTERSTRINGX, cury, &enterstring[startline], here-startline);
+	  }
+	}
+    }
+    
+    window_state = plain_window;
+  }
+  
+  // update the info string if needed
+  if (init_done && !gsdl_show_console && 
+      ((infostring != NULL) && overlap (INFOX, INFOY, 
+					INFOX+INFOWIDTH, INFOY+INFOHEIGHT,
+					updateRect))) {
+    RECT infoRect;
+    infoRect.left = INFOX;
+    infoRect.top = INFOY;
+    infoRect.right = INFOX+INFOWIDTH;
+    infoRect.bottom = INFOY+INFOHEIGHT;
+    FillRect(pdc, &infoRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
+    DrawText(pdc, infostring, -1, &infoRect, DT_CENTER);
+  }
+
+  // update the logo (always)
+  BitBlt (pdc, LOGOX, LOGOY, LOGOX+LOGOWIDTH, LOGOY+LOGOHEIGHT,
+	  logodc, 0, 0, SRCCOPY);
+}
+
+
+void handle_painting (HWND Window) {
+  HDC pdc;  PAINTSTRUCT ps;
+  pdc = BeginPaint(Window, &ps);
+  
+  paint_window (pdc, ps.rcPaint);
+  
+  EndPaint(Window, &ps);
+}
+
+
+// returns 1 on success, 0 otherwise
+int enter_library (HWND Window) {
+  int res;
+  
+  if (infostring == strrestartlib) {
+
+    // the "restart library" button was pressed so we want to reinitialize
+    // greenstone, read in all the macrofiles again, etc.
+    gsdl_init(false);
+  }
+
+  // get the url and attempt to start a browser
+  if (have_networking) {
+    // There are now four address resolution methods:
+    //   0: Standard -- get local IP then resolve to a name
+    //   1: IP only -- as above, but use IP only -- don't resolve to a name
+    //   2: localhost -- always use localhost
+    //   3: 127.0.0.1 -- always use 127.0.0.1
+    char gsdl_address[100];
+
+    DWORD local_ip = GetLocalIP();
+    if (local_ip == INADDR_ANY || gsdl_address_resolution_method == 3) {
+      local_ip = 127 + (0 << 8) + (0 << 16) + (1 << 24);
+    }
+
+    if (gsdl_address_resolution_method == 1 || gsdl_address_resolution_method == 3) {
+      sprintf(gsdl_address, "%d.%d.%d.%d", local_ip & 0xFF, (local_ip >> 8) & 0xFF, (local_ip >> 16) & 0xFF, (local_ip >> 24) & 0xFF);
+    }
+    else if (gsdl_address_resolution_method == 2) {
+      sprintf(gsdl_address, "localhost");
+    }
+    else {
+      strcpy(gsdl_address, GetLocalName(NULL));
+    }
+
+    text_t url = "http://" + text_t(gsdl_address);
+
+    gsdl_url = url;
+    write_settings(gsdl_url);
+
+    if (gsdl_port_num != 80)
+      url += ":" + text_t(gsdl_port_num);
+
+    url += gsdl_enterlib;
+
+    // add a unique ending so it will always result in a request
+    text_t::const_iterator it = 
+      findchar (gsdl_enterlib.begin(), gsdl_enterlib.end(), '?');
+    if (it == gsdl_enterlib.end()) url.push_back ('?');
+    else url.push_back ('&');
+    int tcount = GetTickCount();
+    url += "uq=" + text_t(tcount);
+    
+    // remember the library access number for later proxy checking
+    enterlib_libaccessnum = libaccessnum;
+    
+    if (gsdl_start_browser) {
+
+      // do a quick check to make sure we're using netscape when
+      // we should be (it might have been just installed)
+      if (netscapeneeded) gsdl_check_browser_settings (netscapeneeded);
+    
+      char *cstr_url = url.getcstr();
+      if (strlen (startbrowserdir) <= 0) {
+	res = startbrowser (cstr_url, gsdl_browser_exe, NULL);
+	
+      } else res = startbrowser (cstr_url, gsdl_browser_exe, startbrowserdir);
+    
+      delete []cstr_url;
+
+    } else {
+      return 1;
+    }
+  }
+  
+  if (res == SB_NOERROR) {
+    // success !!
+    
+    // remember the time the browser was started for later proxy checking
+    if (have_networking) enterlib_time = GetTickCount();
+    
+    return 1;
+  }
+  
+  // no browser was started
+  enterlib_libaccessnum = -1;
+  
+  if ((res == SB_FAIL_BADFORMAT) || (res == SB_FAIL_NOTFOUND)) {
+    if (!netscapeneeded) { // any browser
+      MessageBox(Window,
+		 "Failed to start your chosen browser. It seems that your\n"
+		 "chosen browser has been removed or corrupted.\n"
+		 "Please check your browser choice by going to the\n"
+		 "'Settings...' item under the 'File' menu.",
+		 "Greenstone Digital Library Software", MB_OK);
+    } else { // netscape used
+      MessageBox(Window,
+		 "Failed to start Netscape. It seems that Netscape has\n"
+		 "been removed or corrupted. You need Netscape\n"
+		 "installed to use the Greenstone Digital Library\n"
+		 "software on non-networked machines.",
+		 "Greenstone Digital Library Software", MB_OK);
+    }
+    
+  } else {
+    MessageBox(Window,
+	       "Failed to start your browser. This may have been\n"
+	       "because there was not enough memory available. Shut\n"
+	       "down all other applications you have running, and\n"
+	       "try again.",
+	       "Greenstone Digital Library Software", MB_OK);
+  }
+  
+  return 0; // failed
+}
+
+
+void install_netscape (HWND Window) {
+  char installpath[256];
+  
+  // try to find the browser directory
+  char *gsdlhome = gsdl_gsdlhome.getcstr();
+  strcpy (installpath, gsdlhome); // use gsdlhome to find the CD-ROM drive...
+  delete []gsdlhome;
+  
+  // remove any slashes from the pathname
+  int len = strlen (installpath);
+  while ((len > 0) && ((installpath[len-1] == '\\') || (installpath[len-1] == '/'))) {
+    --len;
+  }
+  // remove '\gsdl'
+  len = len - 5;
+  installpath[len] = '\0';
+  
+  strcat (installpath, "\\netscape\\");
+  
+  // check this directory
+  if (!cstrcheckdir(installpath)) {
+    return;
+  }
+  
+  // get the operating system information
+  OSVERSIONINFO osver;
+  memset(&osver, 0, sizeof(OSVERSIONINFO));
+  osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+  GetVersionEx(&osver);
+
+  // get the install program for this operating system
+  if (osver.dwPlatformId == VER_PLATFORM_WIN32s) {
+    strcat (installpath, "n16e405.exe");
+  } else {
+    strcat (installpath, "n32e405.exe");
+  }
+  
+  // run the install program
+  int res = WinExec (installpath, SW_SHOW);
+  if (res == 0) {
+    // out of resources or memory
+    MessageBox (Window,
+		"Did not have enough resources or memory to run the\n"
+		"install program. Try shutting down all other programs\n"
+		"and trying again.",
+		"Greenstone Digital Library Software",
+		MB_OK|MB_APPLMODAL);
+    
+  } else if (res == ERROR_BAD_FORMAT) {
+    // executable image is corrupt -- ????
+    MessageBox (Window,
+		"The install program seems to be corrupt.",
+		"Greenstone Digital Library Software",
+		MB_OK|MB_APPLMODAL);
+    
+  } else if ((res == ERROR_FILE_NOT_FOUND) || (res == ERROR_PATH_NOT_FOUND)) {
+    // couldn't find the executable -- ????
+    MessageBox (Window,
+		"Could not find the install program. Try installing\n"
+		"Netscape from the Greenstone Digital Library\n"
+		"software's install program.",
+		"Greenstone Digital Library Software",
+		MB_OK|MB_APPLMODAL);
+  }
+}
+
+void open_help () {
+  char topdir[256], cmd[256];
+  
+  // try to find the browser directory
+  char *gsdlhome = gsdl_gsdlhome.getcstr();
+  strcpy (topdir, gsdlhome); // use gsdlhome to find the CD-ROM drive...
+  delete []gsdlhome;
+  strcpy (cmd, "notepad ");
+  
+  // remove any slashes from the pathname
+  int len = strlen (topdir);
+  while ((len > 0) && ((topdir[len-1] == '\\') || (topdir[len-1] == '/'))) {
+    --len;
+  }
+  // remove the '\gsdl'
+  len = len - 5;
+  topdir[len] = '\0';
+
+  strcat (topdir, "\\README.txt");
+  strcat (cmd, topdir);
+  
+  WinExec (cmd, SW_SHOW);
+}
+
+
+long __stdcall WndProc(HWND Window, UINT Message, WPARAM WParam, LPARAM LParam) {
+  switch(Message) {
+    // Constant Messages
+  case WM_CREATE:
+    break;
+    
+  case WM_COMMAND:
+    if ((GoButton != NULL) && ((HWND)LParam == GoButton)) {
+      // attempt to start a browser
+      gsdl_start_browser = 1;
+      if (enter_library (Window) && !gsdl_show_console) 
+    	ShowWindow(Window,SW_MINIMIZE);
+
+    } else if ((Enter != NULL) && ((HWND)LParam == Enter)) {
+      init_done = 1;
+      init_type = 1;
+
+//      } else if ((EnterRestricted != NULL) && ((HWND)LParam == EnterRestricted)) {
+//        init_done = 1;
+//        init_type = 0;
+
+//      } else if ((InfoRestricted != NULL) && ((HWND)LParam == InfoRestricted)) {
+//        MessageBox (NULL, "The Greenstone system automatically determines whether your computer has\n"
+//  		  "network software installed or is connected to a network.  It operates correctly\n"
+//  		  "under any of these conditions.\n\n"
+//  		  "The restricted version is intended for use when the standard one\n\n"
+//  		  "   (a) causes an unwanted telephone dialup operation;\n"
+//  		  "   (b) fails to run because network software is installed, but installed\n"
+//  		  "         incorrectly.\n\n"
+//  		  "The restricted version only works with Netscape (not Internet Explorer).\n\n"
+//  		  "Unless these problems arise, you should always use the standard version\n"
+//  		  "(press the 'Enter Library' button).\n",
+//  		  "Greenstone Digital Library Software", 
+//  		  MB_OK | MB_ICONINFORMATION | MB_APPLMODAL);
+
+    } else {
+      switch (LOWORD(WParam)) {
+      case ID_PROJECT_SETTINGS:
+	Settings_Dialog(Window, netscapeneeded);
+	break;
+      case ID_INSTALL_NETSCAPE:
+	install_netscape(Window);
+	break;
+      case IDHELP:
+	open_help();
+	break;
+      case ID_PROJECT_EXIT:
+        finish_up(false);
+        break;
+      default:
+        break;
+      }
+    }
+    break;
+    
+  case WM_PAINT:
+    handle_painting(Window);
+    break;
+    
+  case HTTP_SERVER_MSG:
+    ProcessHTTPServerMsg(WParam, LParam);
+    break;
+    
+  case WM_DESTROY:
+    finish_up(false);
+    break;
+    
+  default:
+    //Unhandled Messages end up here (DefWindowProc)
+    return DefWindowProc(Window, Message, WParam, LParam);
+  }
+  
+  return(0);
+}
+
+// returns 0 if successful,
+// otherwise a WSA error number
+int tryinitnetwork (HANDLE Instance, HWND MsgWindow, char *path) {
+  // try to load winsock
+  int err = d_LoadWinsock (path);
+  
+  if (err == D_NOERROR) {
+    // next, try to init netio
+    err = InitNetIO();
+    
+    if (err == 0) {
+      // next, try to start the http server
+      err = StartHTTPServer(MsgWindow);
+      
+      if (err == 0) {
+	// finally, get the host name (no error value
+	// is returned from this function)
+	GetLocalName((HINSTANCE)Instance);
+	
+      } else {
+	// couldn't start the http server, 
+	// deinit netio and unload winsock
+	CleanUpNetIO();
+	d_UnloadWinsock();
+      }
+      
+    } else {
+      // couldn't init netio, unload winsock
+      d_UnloadWinsock();
+    }
+    
+  } else {
+    // couldn't load winsock
+    err = WSASYSNOTREADY;
+  }
+  
+  return err;
+}
+
+
+// inits all the network functionality
+// returns 0 if an unrecoverable error occurred,
+// and 1 if everything successfully initialised.
+int initnetwork (HANDLE Instance, HWND MsgWindow) {
+  OSVERSIONINFO osver;
+  
+  // get the operating system information
+  memset(&osver, 0, sizeof(OSVERSIONINFO));
+  osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+  GetVersionEx(&osver);
+  
+  // first try to initialise the network with system installed
+  // networking software
+  startbrowserdir[0] = '\0';
+  netscapeneeded = 0;
+  int err = 1;
+  if (init_type == 1) err = tryinitnetwork (Instance, MsgWindow, NULL);
+  
+  // if an error occurred, try again with billsock
+  if (err != 0) {
+    // get the path of billsock (current directory + ("net16" | "net32"))
+    char winsockpath[1024]; // HARD LIMIT!!!!
+    
+    find_location();
+    char *data_location_c = data_location.getcstr();
+    strcpy (winsockpath, data_location_c);
+    delete []data_location_c;
+    
+    // remove all the slashes at the end of billpath
+    int len = strlen (winsockpath);
+    while ((len > 0) && ((winsockpath[len-1] == '\\') || (winsockpath[len-1] == '/'))) {
+      --len;
+    }
+    winsockpath[len] = '\0';
+    
+    if (osver.dwPlatformId == VER_PLATFORM_WIN32s)
+      strcat (winsockpath, "\\net16\\");
+    else {
+      strcat (winsockpath, "\\net32\\");
+      strcpy (startbrowserdir, winsockpath);
+    }
+    
+    // try again
+    err = tryinitnetwork (Instance, MsgWindow, winsockpath);
+    
+    if (err == 0) {
+      // we will need to use netscape on 95/98/NT machines
+      if (osver.dwPlatformId != VER_PLATFORM_WIN32s) {
+	netscapeneeded = 1;
+	// make sure the browser state is in step with the network condition
+	gsdl_check_browser_settings (netscapeneeded);
+      }
+      
+      // check to see if a browser is running
+      if (browserrunning(gsdl_browser_exe) == NO_ERROR) {
+	MessageBox (NULL, 
+		    "The Greenstone Digital Library software has detected a\n"
+		    "running browser. To let our networking software\n"
+		    "correctly initialize, please shut down your browser\n"
+		    "and restart the Greenstone Digital Library software.",
+		    "Greenstone Digital Library Software", MB_OK|MB_APPLMODAL);
+	PostMessage(MsgWindow,WM_CLOSE,0,0);
+	finish_up(false); // will unload winsock
+	exit(0);      // nothing more to do
+      }
+    }
+  }
+  
+  // if an error occurred display a nice error message
+  if (err != 0) {
+    
+    // WSASYSNOTREADY	Couldn't load winsock
+    // WSAVERNOTSUPPORTED	The version of Windows Sockets support requested 
+    //			is not provided by this particular Windows Sockets implementation.
+    // WSAEINVAL	The Windows Sockets version specified by the application 
+    //			is not supported by this DLL.
+    // WSAEPROTONOSUPPORT	The specified protocol is not supported.
+    // WSAEPROTOTYPE	The specified protocol is the wrong type for this socket.
+    // WSAESOCKTNOSUPPORT	The specified socket type is not supported in 
+    //		this address family.
+    // WSANOTINITIALISED	A successful WSAStartup must occur before 
+    //		using this function.
+    // WSAENETDOWN	The Windows Sockets implementation 
+    //		has detected that the network subsystem has failed.
+    // WSAEADDRINUSE 	The specified address 
+    //		is already in use. (See the SO_REUSEADDR socket option under setsockopt.)
+    // WSAEFAULT	The namelen argument is too small (less 
+    //		than the size of a struct sockaddr).
+    // WSAEINPROGRESS	A blocking Windows Sockets call is in progress.
+    // WSAEAFNOSUPPORT	The specified address family is not supported 
+    //		by this protocol.
+    // WSAENOBUFS	Not enough buffers available, too many connections.
+    // WSAENOTSOCK	The descriptor is not a socket.
+    // WSAEISCONN	The socket is already connected.
+    // WSAEMFILE	No more file descriptors are available.
+    // WSAEOPNOTSUPP	The referenced socket is not of a type that 
+    //		supports the listen operation.
+    
+    // get a text version of the error number
+    char errstr[256];
+    
+    switch (err) {
+    case WSASYSNOTREADY: strcpy(errstr, "WSASYSNOTREADY"); 
+      break;
+    case WSAVERNOTSUPPORTED: strcpy (errstr, "WSAVERNOTSUPPORTED");
+      break;
+    case WSAEINVAL: strcpy (errstr, "WSAEINVAL");
+      break;
+    case WSAEPROTONOSUPPORT: strcpy (errstr, "WSAEPROTONOSUPPORT");
+      break;
+    case WSAEPROTOTYPE: strcpy (errstr, "WSAEPROTOTYPE");
+      break;
+    case WSAESOCKTNOSUPPORT: strcpy (errstr, "WSAESOCKTNOSUPPORT");
+      break;
+    case WSANOTINITIALISED: strcpy (errstr, "WSANOTINITIALISED");
+      break;
+    case WSAEFAULT: strcpy (errstr, "WSAEFAULT");
+      break;
+    case WSAEAFNOSUPPORT: strcpy (errstr, "WSAEAFNOSUPPORT");
+      break;
+    case WSAENOTSOCK: strcpy (errstr, "WSAENOTSOCK");
+      break;
+    case WSAEISCONN: strcpy (errstr, "WSAEISCONN");
+      break;
+    case WSAEOPNOTSUPP: strcpy (errstr, "WSAEOPNOTSUPP");
+      break;
+    case WSAENETDOWN: strcpy (errstr, "WSAENETDOWN");
+      break;
+    case WSAEADDRINUSE: strcpy (errstr, "WSAEADDRINUSE");
+      break;
+    case WSAEINPROGRESS: strcpy (errstr, "WSAEINPROGRESS");
+      break;
+    case WSAENOBUFS: strcpy (errstr, "WSAENOBUFS");
+      break;
+    case WSAEMFILE: strcpy (errstr, "WSAEMFILE");
+      break;
+    default: sprintf (errstr, "WSA ERROR: %i", err);
+      break;
+    }
+    
+    // create a nice error message
+    char message[2048];
+    
+    switch (err) {
+    case WSAEADDRINUSE:
+      // couldn't bind socket
+      sprintf (message, "Could not find a free socket.", errstr);
+      break;
+      
+    default:
+      // cannot init winsock
+      sprintf (message, "Could not initialize the network\n"
+	       " (Reason: %s).", errstr);
+      break;
+    }
+    
+    strcat (message, "\n\n"
+	    "Please submit a bug report using the support.htm file\n"
+	    "on the CD-ROM.");
+    
+    MessageBox (NULL, message, "Greenstone Digital Library Software", MB_OK);
+  }
+  
+  return (err == 0);
+}
+
+
+void log_computer_info () {
+  char tmpstr[1024];
+  
+  // get various information about this computer
+  if (gsdl_keep_log || gsdl_show_console) {
+    // get operating system information
+    OSVERSIONINFO osver;
+    osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+    
+    if (GetVersionEx(&osver)) {
+      if (osver.dwPlatformId == VER_PLATFORM_WIN32s) {
+	log_message ("Platform: win32s\n");
+      } else if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+	log_message ("Platform: windows 95\n");
+      } else if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) {
+	log_message ("Platform: windows NT\n");
+      }
+      
+      sprintf (tmpstr, "MajorVersion: %i\n", (int)osver.dwMajorVersion);
+      log_message(tmpstr);
+      sprintf (tmpstr, "MinorVersion: %i\n", (int)osver.dwMinorVersion);
+      log_message(tmpstr);
+      sprintf (tmpstr, "BuildNumber: %i\n", (int)osver.dwBuildNumber);
+      log_message(tmpstr);
+      sprintf (tmpstr, "CSDVersion: %s\n\n", osver.szCSDVersion);
+      log_message(tmpstr);
+    }
+    
+    // get memory information
+    MEMORYSTATUS memstatus;
+    memstatus.dwLength = sizeof(MEMORYSTATUS);
+    GlobalMemoryStatus(&memstatus);
+    
+    sprintf (tmpstr, "TotalPhys: %i Meg\n", (int)(memstatus.dwTotalPhys/1024/1024));
+    log_message (tmpstr);
+    sprintf (tmpstr, "AvailPhys: %i Meg\n", (int)(memstatus.dwAvailPhys/1024/1024));
+    log_message (tmpstr);
+    sprintf (tmpstr, "TotalPageFile: %i Meg\n", (int)(memstatus.dwTotalPageFile/1024/1024));
+    log_message (tmpstr);
+    sprintf (tmpstr, "AvailPageFile: %i Meg\n", (int)(memstatus.dwAvailPageFile/1024/1024));
+    log_message (tmpstr);
+    sprintf (tmpstr, "TotalVirtual: %i Meg\n", (int)(memstatus.dwTotalVirtual/1024/1024));
+    log_message (tmpstr);
+    sprintf (tmpstr, "AvailVirtual: %i Meg\n\n", (int)(memstatus.dwAvailVirtual/1024/1024));
+    log_message (tmpstr);
+    
+    // log the version number
+    log_message("GSDL version: " GSDL_VERSION "\n");
+  }
+  
+}
+
+// possible command line options are 
+// --location=directory (the path to GSDLHOME which defaults to the
+// directory where server.exe lives)
+// --config=file (the path to the configuration file to use which defaults
+// to GSDLHOME\gsdlsite.cfg)
+// --cmd=init  Used to initialize the gsdlsite.cfg file onlt - jmt12 18/11/2003
+static void parse_args(const text_t cmdline, text_t &location, text_t &config_file, text_t &command) {
+
+  location.clear();
+  config_file.clear();
+  command.clear(); // jmt12 18/11/2003
+
+  if (cmdline.size() < 3) return;
+
+  text_t name, val;
+  bool foundname = false;
+  text_t::const_iterator here = cmdline.begin();
+  text_t::const_iterator end = cmdline.end();
+  while (here != end) {
+    if (*here == '-' && ((here+1) != end) && (*(here+1) == '-')) {
+      ++here;
+      if (name == "location") {
+	location = val;
+      } else if (name == "config") {
+	config_file = val;
+      } 
+      // jmt12 18/11/2003
+      else if(name == "cmd") {
+	command = val;
+      }
+      foundname = false;
+      name.clear();
+      val.clear();
+    } else if (*here == '=') {
+      foundname = true;
+    } else {
+      if (foundname) {
+	val.push_back(*here);
+      } else {
+	name.push_back(*here);
+      }
+    }
+    ++here;
+  }
+  if (name == "location") {
+    location = val;
+  } else if (name == "config") {
+    config_file = val;
+  }
+  // jmt12 18/11/2003
+  else if(name == "cmd") {
+    command = val;
+  }
+}
+
+// Added code to allow for an 'init' run of the server which just creates the gsdlsite.cfg file
+int __stdcall WinMain(HINSTANCE Instance, HINSTANCE /*PrevInstance*/, LPSTR CmdLineStr, int /*CmdShow*/) {
+  HWND MainWindow;  MSG Message;  WNDCLASS MainClass;  
+
+  // One instance of the local library server is quite enough, thank you very much
+  HWND gw = FindWindow("Greenstone Digital Library Software",
+		       "Greenstone Digital Library Software");
+  if (gw != NULL) {
+    exit(1);
+  }
+
+  // parse arguments
+  text_t location, config_file, command;
+  parse_args(CmdLineStr, location, config_file, command);
+  gsdl_conffile = config_file;
+
+  // jmt12 18/11/2003
+  if(command == "init") {
+    // init various modules
+    read_settings(0); // don't know if netscape is needed at this point
+    finish_up(true);
+    exit(0);
+  }
+
+  //Create a window class
+  MainClass.style = CS_HREDRAW | CS_VREDRAW;
+  MainClass.lpfnWndProc = WndProc;
+  MainClass.cbClsExtra = 0;
+  MainClass.cbWndExtra = 0;
+  MainClass.hInstance = Instance;
+  MainClass.hIcon     = LoadIcon(Instance, MAKEINTRESOURCE(TRAY_ICON));
+  MainClass.hCursor   = LoadCursor(NULL, IDC_ARROW);
+  MainClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
+  MainClass.lpszMenuName = MAKEINTRESOURCE(Main_Menu);
+  MainClass.lpszClassName = "Greenstone Digital Library Software";
+  if (!RegisterClass(&MainClass))
+    return 0;
+  
+  
+  // Load various bitmaps
+  coltitlebitmap = LoadBitmap (Instance, MAKEINTRESOURCE(GSDL_COL_TITLE));
+  logobitmap= LoadBitmap (Instance, MAKEINTRESOURCE(GSDL_LOGO));
+  
+  // Create the main window
+  MainWindow = CreateWindow("Greenstone Digital Library Software", 
+			    "Greenstone Digital Library Software",
+			    WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
+			    WS_MINIMIZEBOX,
+			    CW_USEDEFAULT, CW_USEDEFAULT, 
+			    MAINWINDOWWIDTH + WASTEWIDTH, 
+			    MAINWINDOWHEIGHT + WASTEHEIGHT,
+			    NULL, NULL, Instance, NULL);
+  
+  text_rect.left = 0;  
+  text_rect.top = VERSIONY+VERSIONHEIGHT + 5;
+  text_rect.right = MAINWINDOWWIDTH;
+  text_rect.bottom = LOGOY-SPACERWIDTH;
+  
+  window_state = undefined_window;
+  
+  ShowWindow(MainWindow, SW_SHOW); 
+  set_location(location);
+  
+  // get ready to draw the main window
+  RECT windowRect;
+  GetClientRect (MainWindow, &windowRect);
+  HDC pdc = GetDC (MainWindow);
+  
+  // retrieve and save the text metrics
+  TEXTMETRIC tm;
+  GetTextMetrics(pdc, &tm);
+  line_spacing = tm.tmHeight + tm.tmExternalLeading;
+  GSDL_Window = MainWindow;  
+
+  // init various modules
+  read_settings (0); // don't know if netscape is needed at this point
+  
+  if (!gsdl_auto_enter) {
+    
+    // add the select version checkbox
+    Enter = CreateWindow("BUTTON",             // predefined class 
+			 "Enter Library",      // button text 
+			 WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_DEFPUSHBUTTON,  // styles 
+			 ENTERBUTTONX,         // starting x position 
+			 ENTERBUTTONY,         // starting y position 
+			 ENTERBUTTONWIDTH,     // button width 
+			 ENTERBUTTONHEIGHT,    // button height 
+			 MainWindow,           // parent window 
+			 NULL,                 // No menu 
+			 Instance, 
+			 NULL);                // pointer not needed 
+    
+//      EnterRestricted = CreateWindow("Button",                // predefined class 
+//  				   "Restricted Version",    // button text 
+//  				   WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_PUSHBUTTON,   // styles 
+//  				   ALTERNATIVEBUTTONX,      // starting x position 
+//  				   ALTERNATIVEBUTTONY,      // starting y position 
+//  				   ALTERNATIVEBUTTONWIDTH-(INFOBUTTONWIDTH+SPACERWIDTH),  // button width 
+//  				   ALTERNATIVEBUTTONHEIGHT, // button height 
+//  				   MainWindow,              // parent window 
+//  				   (HMENU)NULL,             // No menu 
+//  				   Instance, 
+//  				   NULL);                   // pointer not needed 
+    
+//      InfoRestricted = CreateWindow("Button",                // predefined class 
+//  				  NULL,
+//  				  WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_BITMAP,   // styles 
+//  				  ALTERNATIVEBUTTONWIDTH-INFOBUTTONWIDTH+SPACERWIDTH, // starting x position 
+//  				  ALTERNATIVEBUTTONY,      // starting y position 
+//  				  INFOBUTTONWIDTH,         // button width 
+//  				  ALTERNATIVEBUTTONHEIGHT, // button height 
+//  				  MainWindow,              // parent window 
+//  				  (HMENU)NULL,             // No menu 
+//  				  Instance, 
+//  				  NULL);                   // pointer not needed 
+    
+//      HANDLE i_icon = LoadImage (Instance, MAKEINTRESOURCE(GSDL_ICBMP), IMAGE_BITMAP, 
+//  			       INFOBUTTONWIDTH-4, ALTERNATIVEBUTTONHEIGHT-4, LR_DEFAULTCOLOR);
+//      SendMessage (InfoRestricted, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)i_icon);
+    
+    SetFocus (Enter);
+    
+    enterstring = strenterlib;
+    paint_window (pdc, windowRect);
+    
+    // message loop for init buttons
+    while (!init_done) {
+      if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) {
+	if (Message.message == WM_QUIT) return Message.wParam;
+	if (!IsDialogMessage (MainWindow, &Message)) {
+	  TranslateMessage(&Message); /* translate keyboard messages */
+	  DispatchMessage(&Message);  /* return control to Windows NT */
+	}
+      } else {
+	Sleep (1);
+      }
+    }
+    
+    // don't want these buttons anymore
+    DestroyWindow (Enter);
+    // DestroyWindow (EnterRestricted);
+    // DestroyWindow (InfoRestricted);
+    
+    enterstring = strnothing;
+    paint_window (pdc, windowRect);
+    
+  } else {
+    // auto enter is enabled - start up standard version
+    init_type = 1;
+    init_done = 1;
+  }
+  
+  // draw the main window containing an init message
+  infostring = strinit;
+  paint_window (pdc, windowRect);
+  DWORD lastcheck = GetTickCount();
+  
+  have_networking = initnetwork (Instance, MainWindow);
+  if (!have_networking) {
+    MessageBox(NULL,
+	       "Failed to initialize networking.",
+	       "Greenstone Digital Library Software",MB_OK|MB_SYSTEMMODAL);	
+    exit (0);
+  }
+
+  if (!gsdl_init()) // quit if can't initialise the library correctly
+    exit (0);
+  initstartbrowser();
+  log_computer_info ();
+  
+  // show the initialising message for at least 1 second
+  while (DiffTickCounts (lastcheck, GetTickCount()) < 1000) {
+    Sleep (1);
+  }
+  
+  // attempt to start a browser
+  if (gsdl_show_console || !gsdl_start_browser) infostring = strnothing;
+  else infostring = strsb;
+  paint_window (pdc, windowRect);
+  lastcheck = GetTickCount();
+  if (enter_library (MainWindow) && !gsdl_show_console) {
+    // stay maximised for at least 1 second
+    while (DiffTickCounts (lastcheck, GetTickCount()) < 1000) Sleep (1);
+    ShowWindow(MainWindow,SW_MINIMIZE);
+  }
+  
+  // add the "restart library" button
+  GoButton = CreateWindow("BUTTON",              // predefined class 
+			  "Restart Library",     // button text 
+			  WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles 
+			  RESTARTBUTTONX,        // starting x position 
+			  RESTARTBUTTONY,        // starting y position 
+			  RESTARTBUTTONWIDTH,    // button width 
+			  RESTARTBUTTONHEIGHT,   // button height 
+			  MainWindow,            // parent window 
+			  NULL,                  // No menu 
+			  Instance, 
+			  NULL);                 // pointer not needed 
+  
+  infostring = strrestartlib;
+  paint_window (pdc, windowRect);
+  
+  // release the DC used to display the init messages
+  ReleaseDC (MainWindow, pdc);
+  
+  //Message loop
+  lastcheck = GetTickCount();
+  int seenbrowser = 0;	// if we see a browser then it disappears
+                        // we will ask if they want to close the
+                        // the library down
+  char last_gsdl_browser_exe[MAX_FILENAME_SIZE]; // need to notice when the
+                                                 // browser setting changes
+  strcpy (last_gsdl_browser_exe, gsdl_browser_exe);
+  
+  for (;;) {
+    if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) {
+      if (Message.message == WM_QUIT) break;
+      if (!IsDialogMessage (MainWindow, &Message)) {
+	TranslateMessage(&Message); /* translate keyboard messages */
+	DispatchMessage(&Message);  /* return control to Windows NT */
+      }
+      
+    } else {
+      if (DiffTickCounts (lastcheck, GetTickCount()) > 500) {
+	// make sure the browser hasn't changed
+	if (strcmp (last_gsdl_browser_exe, gsdl_browser_exe) != 0) {
+	  seenbrowser = 0;
+	  strcpy (last_gsdl_browser_exe, gsdl_browser_exe);
+	}
+	
+	// do check
+	lastcheck = GetTickCount();
+	if (gsdl_start_browser && browserrunning(gsdl_browser_exe) == NO_ERROR) {
+	  // we were able to connect to a browser
+	  seenbrowser = 1;
+	  
+	  // see if the enter library button has been pressed
+	  // with nothing happening for 20 seconds
+	  if ((enterlib_libaccessnum >= 0) && 
+	      (enterlib_libaccessnum == libaccessnum) &&
+	      (DiffTickCounts (enterlib_time, GetTickCount()) > 20000)) {
+	    // something could be wrong!! (most likely cause is a proxy)
+	    MessageBox(NULL,
+		       "Your browser does not seem to be responding to the 'Enter Library'\n"
+		       "request. Try turning off all proxy servers in your browser settings.\n"
+		       "If you are using Internet Explorer make sure BOTH dialup settings\n"
+		       "AND LAN settings have their proxy servers disabled.",
+		       "Greenstone Digital Library Software",MB_OK|MB_SYSTEMMODAL);
+	    enterlib_libaccessnum = -1;
+	  }
+	  
+	  
+	} else {
+	  // no browser was found
+	  
+	  if (seenbrowser) {
+	    // we have seen a browser in the past
+	    if (MessageBox(NULL,
+			   "The Greenstone Digital Library software has noticed that you\n"
+			   "shut down your browser. Would you also like to shut down the\n"
+			   "Greenstone Digital Library software?",
+			   "Greenstone Digital Library Software",MB_YESNO|MB_SYSTEMMODAL) == IDYES)
+	      PostMessage(MainWindow,WM_CLOSE,0,0);
+	  }
+	  seenbrowser = 0;
+	}
+      }
+      
+      Sleep (1); // millisecond
+    }
+  }
+  
+  return Message.wParam;
+}
+
Index: /gsdl/trunk/runtime-src/src/w32server/httpreq.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/httpreq.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/httpreq.cpp	(revision 16571)
@@ -0,0 +1,445 @@
+/**********************************************************************
+ *
+ * httpreq.cpp
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <memory.h>
+#include "httpreq.h"
+#include "parse.h"
+#include "netio.h"
+#include "settings.h"
+#include "httpsrv.h"
+#include "httpsend.h"
+#include "cgiwrapper.h"
+#include "d_winsock.h"
+
+/*
+Implementation Notes:
+
+HTTP field names, method and version strings are converted to upper case
+right after being read from the client in order to allow case insensitive
+string comparisons to be done on them.  Since these fields are worked with a
+lot, this should help performance.
+*/
+
+//Private Data and declarations
+#define IO_BUFFER_SIZE 16384        //16K IO Buffer
+#define MAX_HTTP_LINE_LEN 1024      //Max length of line in a header of 1024
+
+//Private Function Declarations with Return Contstants
+
+/*
+Function Name: DispatchRequest
+Purpose: Manages having the request parsed, then sent to the right function
+         to send a response or handle an error.
+Parameters:
+         ClientSocket - Socket the client is on
+	 ClientSockAddr - Address of client
+	 AddrLen - Length of address of client
+	 IOBuffer - Pointer to buffer allocated for IO operations
+	 ThreadNum - Number of thread that called this function for debugging purposes
+Notes:   I'm still playing with the keep alive support.  I commented out
+	 the stuff for giving a client a timeout because I was unable to detect
+	 disconnects.
+More Notes: Not sure if this organization will allow me to easily add support
+	    for ISAPI filter DLLs.
+*/
+void DispatchRequest(SOCKET ClientSocket, SOCKADDR_IN ClientSockAddr, int AddrLen, BYTE *IOBuffer);
+
+/*
+Function Name: Get HTTP Headers
+Purpose: Manages having the request parsed, then sent to the right function
+         to send a response or handle an error.
+Parameters:
+	RequestInfo - Request information structure (see httpreq.h)
+	RequestFields - HTTP request fields structure (see httpreq.h)
+Returns: GH_ERROR on error (diconnect, bad data, Windows in a bad mood, etc.)
+			GH_UNKNOWN_VERSION if the version number is not HTTP/0.9 or HTTP/1.x
+			GH_SIMPLE_REQUEST on a properly formated HTTP/0.9 request
+			GH_10_REQUEST on a properly formated HTTP/1.x request
+*/
+int GetHTTPHeaders(RequestInfoT &RequestInfo, RequestFieldsT &RequestFields);
+#define GH_BAD_METHOD	   -2
+#define GH_ERROR           -1
+#define GH_UNKNOWN_VERSION  0
+#define GH_SIMPLE_REQUEST   1
+#define GH_10_REQUEST       2
+
+/*
+Function Name: Clean Up HTTP Headers
+Purpose: Cleans up memory dynamicly allocated for headers
+Parameters:
+	RequestInfo - Request information structure (see httpreq.h)
+	RequestFields - HTTP request fields structure (see httpreq.h)
+Returns: Nothing
+*/
+void CleanUpHTTPHeaders(RequestInfoT &RequestInfo, RequestFieldsT &RequestFields);
+
+/*
+Function Name: Split Query
+Purpose: Splits the file and query part of a URI.  In other words, it
+	 puts the parts before and after the "?" in differnet strings.
+Parameters:
+	 URIStr - The requested URI
+	 FileStr - String to contain the name of the path + file part of the URI
+	 QueryStr - String to contain the query part of the URI
+Returns: TRUE if there is a query, else FALSE
+*/
+BOOL SplitQuery(char *URIStr, char *FileStr, char *QueryStr, int ThreadNum);
+
+/*
+Function Name: Get File
+Purpose: Attempts to find a given file, including looking for index.html.
+	 Updates the given URI string so it points to the true document location
+Parameters:
+	 FilePath - Path of file, may be modified to best reflect the retrived file
+				  or directory
+	 URIStr - URI string, minus the query
+Returns: GF_ERROR on error
+			GF_FILE_FOUND on success
+			GF_INDEX_FOUND if file is a directory with an index.html file in it
+			GF_DIRECTORY if file is a directory
+			GF_FILE_NOT_FOUND if file was found
+*/
+
+/*
+Function Name: Process Simple Request
+Purpose: Sends a reply to a HTTP 0.9 "simple" request
+Parameters:
+	ClientSocket - Socket the client is on
+	RequestInfo - Structure storing the parsed headers
+	IOBuffer - Pointer to buffer allocated for IO operations
+	TheadNum - Number of calling thread for debugging
+Notes: I should really test this and see if it works...
+*/
+void ProcessSimpleRequest(RequestInfoT &RequestInfo, RequestFieldsT &RequestFields);
+
+//Public Functions
+/******************************************************************************/
+void RequestThread(RequestThreadMessageT *Parameters) {
+  SOCKADDR_IN ClientSockAddr;
+  SOCKET ClientSocket;
+  int AddrLen;
+  //Allocate an IO buffer for this thread
+  BYTE *IOBuffer = new BYTE[IO_BUFFER_SIZE];
+
+  //Get the parameters for the request
+  ClientSocket = Parameters->ClientSocket;
+  ClientSockAddr = Parameters->ClientSockAddr;
+  AddrLen = Parameters->AddrLen;
+  DispatchRequest(ClientSocket, ClientSockAddr, AddrLen, IOBuffer);
+}
+/******************************************************************************/
+
+//Private Functions
+
+/******************************************************************************/
+void DispatchRequest(SOCKET ClientSocket, SOCKADDR_IN ClientSockAddr, int AddrLen,  BYTE *IOBuffer) {
+  RequestInfoT RequestInfo;
+  RequestFieldsT RequestFields;
+
+  // TrayAddConnection();
+
+  //Setup the RequestInfo structure
+  memset(&RequestInfo, 0, sizeof(RequestInfoT));
+  RequestInfo.ThreadNum = 0;
+  RequestInfo.IOBuffer = IOBuffer;
+  RequestInfo.IOBufferSize = IO_BUFFER_SIZE;
+  RequestInfo.ClientSocket = ClientSocket;
+  RequestInfo.ClientSockAddr = ClientSockAddr;
+  RequestInfo.AddrLen = AddrLen;
+  RequestInfo.KeepAlive = FALSE;
+  
+  int GetHeadersResult;
+  do {
+    //Get Headers
+    GetHeadersResult = GetHTTPHeaders(RequestInfo, RequestFields);
+
+    //Figure out what version we're dealing with and deal with it
+    switch (GetHeadersResult) {
+    case GH_SIMPLE_REQUEST :
+      SendHTTPError(400, "HTTP Request not supported", "Only 1.x requests supported", RequestInfo, RequestFields);
+      // TrayIncNumServed();
+      break;
+    case GH_10_REQUEST :
+      ExamineURIStr(RequestFields.URIStr,&RequestInfo,&RequestFields);
+      // TrayIncNumServed();
+      break;
+    case GH_UNKNOWN_VERSION :
+      SendHTTPError(400, "HTTP Version not supported", "Only 1.x requests supported", RequestInfo, RequestFields);
+      // TrayIncNumServed();
+      break;
+/* added Feb 2002 to handle stupid MS behaviour */
+    case GH_BAD_METHOD :
+      SendHTTPError(501, "Not implemented", "Only GET and POST currently implemented", RequestInfo, RequestFields);
+      break;
+    case GH_ERROR:
+      //Disconnect
+      RequestInfo.KeepAlive = FALSE;
+      break;
+    }
+    CleanUpHTTPHeaders(RequestInfo, RequestFields);
+  } while (0/*RequestInfo.KeepAlive == TRUE*/);
+  //Close connection
+  CloseSocket(RequestInfo.ClientSocket);
+  // TrayRemoveConnection();
+}
+
+/******************************************************************************/
+int GetHTTPHeaders(RequestInfoT &RequestInfo, RequestFieldsT &RequestFields) {
+  //Parsing and IO buffers
+  text_t CurLine;
+  text_t NextLine;
+  text_t FieldNameStr;
+  text_t FieldValStr;
+  
+  //Parsing and IO working vars
+  int ReadBufferIndex;
+  int DataInBuffer;
+  text_t::const_iterator next;
+  text_t::const_iterator end;
+
+  //Clear all the fields
+  memset(&RequestFields, 0, sizeof(RequestFieldsT));
+
+  ReadBufferIndex = 0;
+  DataInBuffer = 0;
+  
+  //Get First Line
+  if (GetLine(CurLine, RequestInfo.ClientSocket, RequestInfo.IOBuffer,
+	      RequestInfo.IOBufferSize, ReadBufferIndex, DataInBuffer,
+	      RequestInfo.ThreadNum) != 0) return GH_ERROR;
+  do {//Get Next Line, append it if the first charactor is space
+    if(GetLine(NextLine, RequestInfo.ClientSocket, RequestInfo.IOBuffer,
+	       RequestInfo.IOBufferSize, ReadBufferIndex, DataInBuffer,
+	       RequestInfo.ThreadNum) != 0) return GH_ERROR;
+    if ((*(NextLine.begin()) == ' ') || (*(NextLine.begin()) == '\t')) {
+      CurLine += NextLine;
+    }
+  } while ((*(NextLine.begin()) == ' ') || (*(NextLine.begin()) == '\t'));
+  //Method String (first word)
+  GetWord(RequestFields.MethodStr, CurLine.begin(), CurLine.end(), next);
+  uc(RequestFields.MethodStr);
+
+  /* Added Feb 2002 - IE since about version 5 send stupid frontpage requests
+     for MS Document formats eg "GET /_vti_inf.html" */ 
+  if (RequestFields.MethodStr == "OPTIONS") {
+    return GH_BAD_METHOD;
+  } 
+  //Version String (last word)
+  GetLastWord(RequestFields.VersionStr, CurLine.begin(), CurLine.end(), end);
+  uc(RequestFields.VersionStr);
+  text_t::const_iterator versionbegin = RequestFields.VersionStr.begin();
+
+  if ((RequestFields.VersionStr.size() > 5) && (substr(versionbegin, versionbegin+5) != "HTTP/")) {
+    //No version, assume simple request
+    //part after method is URI
+    RequestFields.URIStr = CurLine;
+    return GH_SIMPLE_REQUEST;
+  }
+
+  //URI String (in between End of first and Start of last)
+  //<Method> <WhiteSpace> <URI> <WhiteSpace> <Version> <CRLF>
+  //                  next^             end^
+  text_t spacebuffer;
+  text_t::const_iterator here = next;
+  while (here != end) {
+    // do this to remove trailing space
+    if (*here == ' ' || *here == '\t') {
+      spacebuffer.push_back(*here);
+    } else {
+      if (!spacebuffer.empty()) {
+	RequestFields.URIStr += spacebuffer;
+	spacebuffer.clear();
+      }
+      RequestFields.URIStr.push_back(*here);
+    }
+    ++here;
+  }
+
+  //Only accept requests from HTTP/0.9 or HTTP/1.X clients, we'll
+  //assume that anything else will require an upgrade or patch
+  if ((RequestFields.VersionStr.size() > 7) && (substr(versionbegin, versionbegin+7) != "HTTP/1.")) {
+    return GH_UNKNOWN_VERSION;
+  }
+  
+  //Get the rest of the lines
+  CurLine = NextLine;
+  
+  while (!CurLine.empty()) {//Blank Line, we're done
+    do {//Get Next Line, append it if the first charactor is space
+      if (GetLine(NextLine, RequestInfo.ClientSocket, RequestInfo.IOBuffer,
+		  RequestInfo.IOBufferSize, ReadBufferIndex, DataInBuffer,
+		  RequestInfo.ThreadNum) != 0)
+	return GH_ERROR;
+      if (NextLine.empty())
+	break;
+      if ((*(NextLine.begin()) == ' ') || (*(NextLine.begin()) == '\t')) {
+	CurLine += NextLine;
+      }
+    } while ((*(NextLine.begin()) == ' ') || (*(NextLine.begin()) == '\t'));
+    
+    GetWord(FieldNameStr, CurLine.begin(), CurLine.end(), next);
+    uc(FieldNameStr);
+    
+    FieldValStr = substr(next, CurLine.end());
+    
+    //Process it
+    //In order of expected commonality
+    //All constants are in canonized, thus in upper case and case sensitive
+    //comparisons are used
+
+    //--Just About Always--
+    if (FieldNameStr == "ACCEPT:") {
+      if (!RequestFields.AcceptStr.empty()) {
+	RequestFields.AcceptStr += ", ";
+      }
+      RequestFields.AcceptStr += FieldValStr;
+    }
+    else if (FieldNameStr == "DATE:") {
+      RequestFields.DateStr = FieldValStr;
+    }
+    else if (FieldNameStr == "USER-AGENT:") {
+      RequestFields.UserAgentStr = FieldValStr;
+    }
+    else if (FieldNameStr == "CONNECTION:") {
+      RequestFields.ConnectionStr = FieldValStr;
+    }
+    //--Sometimes--
+    else if (FieldNameStr == "ACCEPT-LANGUAGE:") {
+      RequestFields.AcceptLangStr = FieldValStr;
+    }
+    else if (FieldNameStr == "REFERER:") {
+      RequestFields.RefererStr = FieldValStr;
+    }
+    else if (FieldNameStr == "IF-MODIFIED-SINCE:") {
+      RequestFields.IfModSinceStr = FieldValStr;
+    }
+    //--Uncommon--
+    else if (FieldNameStr == "FROM:") {
+      RequestFields.FromStr = FieldValStr;
+    }
+    else if (FieldNameStr == "MIME-VERSION:") {
+      RequestFields.MIMEVerStr = FieldValStr;
+    }
+    else if (FieldNameStr == "PRAGMA:") {
+      RequestFields.PragmaStr = FieldValStr;
+    }
+    //--Special case--
+    else if (FieldNameStr == "AUTHORIZATION:") {
+      RequestFields.AuthorizationStr = FieldValStr;
+    }
+    else if (FieldNameStr == "CONTENT-LENGTH:") {
+      RequestFields.ContentLengthStr = FieldValStr;
+    }
+    else if (FieldNameStr == "CONTENT-TYPE:") {
+      RequestFields.ContentTypeStr = FieldValStr;
+    }
+    else if (FieldNameStr == "CONTENT-ENCODING:") {
+      RequestFields.ContentEncodingStr = FieldValStr;
+    }
+    else if (!FieldNameStr.empty()) {
+      //Add it to the other headers
+
+      //Remove the colon
+      if (*(FieldNameStr.end()-1) == ':') {
+	FieldNameStr.pop_back();
+      }
+      RequestFields.OtherHeaders[RequestFields.NumOtherHeaders].Var = FieldNameStr;
+      RequestFields.OtherHeaders[RequestFields.NumOtherHeaders].Val = FieldValStr;
+      ++RequestFields.NumOtherHeaders;
+    }
+    CurLine = NextLine;
+  }
+  
+  if (!RequestFields.ContentLengthStr.empty()) { //Do we have attached data?
+    unsigned int NumRecv;
+    
+    RequestFields.ContentLength = RequestFields.ContentLengthStr.getint();
+    if (RequestFields.ContentLength > 0) {
+
+      //Allocate memory
+      RequestFields.Content = new BYTE[RequestFields.ContentLength];
+      
+      //Get rest of data from get lines
+      NumRecv = DataInBuffer - ReadBufferIndex;
+      
+      if (NumRecv >RequestFields.ContentLength) {
+	//Overflow, only read what they said they'd send
+	NumRecv = RequestFields.ContentLength;
+      }
+      memcpy(RequestFields.Content, RequestInfo.IOBuffer + ReadBufferIndex,
+	     NumRecv);
+      
+      while (NumRecv < RequestFields.ContentLength) {
+	NumRecv += GetData(RequestInfo.ClientSocket,
+			   RequestFields.Content + NumRecv,
+			   RequestFields.ContentLength - NumRecv,
+			   RequestInfo.ThreadNum);
+	if (NumRecv < 0) return GH_ERROR;
+      }
+
+      // It seems to be important on NT that all available data was read
+      // from the socket before the socket is closed (otherwise netscape
+      // throws a "connection reset by peer" error). Since netscape seems
+      // to send a few extra bytes in certain situations we'll make sure we
+      // slurp it all up here.
+      char *tmpbuffer = new char[100]; // this had new char(100)????
+      //      unsigned long int nonblockmode=1;
+      //      ioctlsocket(RequestInfo.ClientSocket, FIONBIO, &nonblockmode);
+      d_recv(RequestInfo.ClientSocket, tmpbuffer, 100, 0);
+      delete []tmpbuffer;
+
+    }
+    else {
+      RequestFields.Content = NULL;
+      RequestFields.ContentLength = 0;
+    }
+  }
+  else {
+    RequestFields.Content = NULL;
+    RequestFields.ContentLength = 0;
+  }
+  
+  return GH_10_REQUEST;
+}
+
+/******************************************************************************/
+void CleanUpHTTPHeaders(RequestInfoT &RequestInfo, RequestFieldsT &RequestFields) {
+  //Clean up memory allocated for the Content
+  if (RequestFields.Content != NULL) {
+    delete[] RequestFields.Content;
+  }
+  
+  // clean up memory allocated for the IOBuffer
+  if (RequestInfo.IOBuffer != NULL) {
+    delete[] RequestInfo.IOBuffer;
+    RequestInfo.IOBuffer = NULL;
+  }
+}
Index: /gsdl/trunk/runtime-src/src/w32server/httpreq.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/httpreq.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/httpreq.h	(revision 16571)
@@ -0,0 +1,143 @@
+/**********************************************************************
+ *
+ * httpreq.h
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef HTTPREQ_H
+#define HTTPREQ_H
+
+// need this to avoid bizarre compiler problems under VC++ 6.0
+#if !defined (GSDL_NAMESPACE_BROKEN) && !defined (GSDL_USE_IOS_H)
+# include <iostream>
+# include <fstream>
+using namespace std;
+#endif
+
+#include "locate.h"
+#include "text_t.h"
+
+/*
+Module Name: HTTP Request
+Purpose: Parses HTTP requests and then calls the appropriate function
+	to respond to the request
+Public Functions:
+	Request Thread
+*/
+
+// Public Data Structures
+
+//Used for sending information to the request thread
+struct RequestThreadMessageT {
+  SOCKADDR_IN ClientSockAddr;
+  SOCKET ClientSocket;
+  int AddrLen;
+};
+
+#define MAX_OTHER_HEADERS 100
+
+struct RequestHeaderT {
+  text_t Var;
+  text_t Val;
+};
+
+struct RequestFieldsT {
+  //Simple request line info v0.9
+  text_t MethodStr;
+  text_t URIStr;
+  //added v1.0
+  text_t VersionStr;
+  //General Header
+  text_t DateStr;
+  text_t MIMEVerStr;
+  text_t PragmaStr;
+  //Request Header
+  text_t AuthorizationStr;
+  text_t FromStr;
+  text_t IfModSinceStr;
+  text_t RefererStr;
+  text_t UserAgentStr;
+  //Entity Header (Only CGI stuff)
+  text_t ContentEncodingStr;
+  text_t ContentTypeStr;
+  text_t ContentLengthStr;
+  //v1.0 Optional (the more common ones)
+  text_t AcceptStr;
+  text_t AcceptLangStr;
+  //v1.1 Exentions
+  text_t ConnectionStr;
+  //Pointer to buffer containing the content
+  DWORD ContentLength;
+  BYTE *Content;
+  
+  //Other Headers
+  int NumOtherHeaders;
+  RequestHeaderT OtherHeaders[MAX_OTHER_HEADERS];
+};
+
+struct RequestInfoT {
+  int ThreadNum;
+  
+  //Buffer for IO operations (so we're not constantly reallocating buffers)
+  BYTE *IOBuffer;
+  int IOBufferSize;
+  
+  //Socket the request is on and its address
+  SOCKET ClientSocket;
+  SOCKADDR_IN ClientSockAddr;
+  int AddrLen;
+  
+  //Should we keep the connection alive?
+  BOOL KeepAlive;
+};
+
+
+// Public Functions
+
+/*
+Function Name: RequestThread
+Purpose: Was the HTTP request processing thread
+         Now just a standard procedure called to process a request
+Parameters:
+	       Pointer to packed parameter structure
+*/
+void RequestThread(RequestThreadMessageT *Parameters);
+
+/*
+Function Name: Process 1.0 Request
+Purpose: Sends a HTTP 1.0 (plus some) reply to a HTTP 1.x request
+Parameters:
+	ClientSocket - Socket the client is on
+	ClientSockAddr - Address of client
+	AddrLen - Length of client address
+	RequestInfo - Structure storing the parsed headers
+	KeepAlive - To be set to true if we are maintainig the connection
+	IOBuffer - Pointer to buffer allocated for IO operations
+	TheadNum - Number of calling thread for debugging
+Notes: The function uses "Connection: Keep-Alive" as written in the HTTP/1.1
+	draft and implemented by Netscape and MSIE
+*/
+void Process10Request(RequestInfoT &RequestInfo, RequestFieldsT &RequestFields);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/w32server/httpsend.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/httpsend.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/httpsend.cpp	(revision 16571)
@@ -0,0 +1,109 @@
+/**********************************************************************
+ *
+ * httpsend.cpp
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "text_t.h"
+
+#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <memory.h>
+#pragma hdrstop
+#include "netio.h"
+#include "httpreq.h"
+#include "httpsend.h"
+
+//Private Function Declarations
+/*
+Function Name: Check IMS Date
+Purpose: Checks the string date of an "If Modified Since" header against
+	a file date stamp.
+Parameters:
+	FileTime - Time stamp on file
+	IMSStr - "If Modified Since" date string
+Returns: TRUE if the file has been modified since the given date or
+	the data can not be resolved (the string to date function will log
+	any errors)
+*/
+BOOL CheckIMSDate(SYSTEMTIME &FileTime, char *IMSStr);
+
+//Public Functions
+/******************************************************************************/
+
+void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr, 
+		   RequestInfoT &RequestInfo, RequestFieldsT &RequestFields) {
+  char Header[512];
+  char Body[512];
+
+  char ErrorNumStr[17];
+  
+  DWORD BodyLength;
+  char BodyLengthStr[17];
+
+  int HeaderLength;
+  
+  itoa(ErrorNum, ErrorNumStr, 10);
+  
+  // Didn't find it, build the message manually
+  Body[0] = 0;
+  strcat(Body, "<HTML><HEAD><TITLE>Server Error</TITLE></HEAD><BODY>\n");
+  strcat(Body, "<H1>Error ");
+  strcat(Body, ErrorNumStr);
+  strcat(Body, ": ");
+  strcat(Body, ErrorTitleStr);
+  strcat(Body, "</H1>\n");
+  strcat(Body, ErrorDescStr);
+  strcat(Body, "\n</BODY></HTML>");
+  BodyLength = (DWORD) strlen(Body);
+
+  //Build Header
+  Header[0] = 0;
+  //Status Line
+  strcat(Header, "HTTP/1.0 ");
+  strcat(Header, ErrorNumStr);
+  strcat(Header, " ");
+  strcat(Header, ErrorDescStr);
+  strcat(Header, "\r\n");
+  //Server
+  strcat(Header, "Server: GSDL\r\n");
+  //Content Type (assume HTML)
+  strcat(Header, "Content-Type: text/html\r\n");
+  //Content Length
+  itoa(BodyLength, BodyLengthStr, 10);
+  strcat(Header, "Content-Length: ");
+  strcat(Header, BodyLengthStr);
+  strcat(Header, "\r\n");
+  //Single CRLF to end header
+  strcat(Header, "\r\n");
+  
+  HeaderLength = strlen(Header);
+  
+  //Send header
+  SendData(RequestInfo.ClientSocket, (BYTE *) Header, strlen(Header), RequestInfo.ThreadNum);
+  //Send generated data
+  SendData(RequestInfo.ClientSocket, (BYTE *) Body, BodyLength, RequestInfo.ThreadNum);
+}
Index: /gsdl/trunk/runtime-src/src/w32server/httpsend.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/httpsend.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/httpsend.h	(revision 16571)
@@ -0,0 +1,51 @@
+/**********************************************************************
+ *
+ * httpsend.h
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+/*
+Module Name: HTTP Send
+Purpose: Functions for sending HTTP responses to 1.X requests
+Public Functions:
+	SendHTTPError
+Notes: Considering adding a version number parameter to these functions.  Right
+	now the way people are implementing HTTP/1.1 is by adding the new stuff
+	to 1.0 requests.  I don't know of any browsers sending 1.1 requests yet.
+*/
+
+/*
+Function Name: Send HTTP Error
+Purpose: Sends a given error message to the client with either the error file
+			as a body or a default error message body.  Common and refenece log
+			entries are written, but not to the count log.
+Parameters:
+	ErrorNum - HTTP error number to send
+	ErrorTitleStr - Title of the error
+	ErrorDescStr - String describing the error
+	RequestInfo - HTTP request information (see httpreq.h)
+	RequestFields - Parsed HTTP header info (see httpreq.h)
+*/
+void SendHTTPError(int ErrorNum, char *ErrorTitleStr, char *ErrorDescStr, 
+		   RequestInfoT &RequestInfo, RequestFieldsT &RequestFields);
Index: /gsdl/trunk/runtime-src/src/w32server/httpsrv.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/httpsrv.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/httpsrv.cpp	(revision 16571)
@@ -0,0 +1,103 @@
+/**********************************************************************
+ *
+ * httpsrc.cpp
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "text_t.h"
+#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <memory.h>
+#pragma hdrstop
+#include "netio.h"
+#include "settings.h"
+#include "httpreq.h"
+#include "httpsrv.h"
+#include "locate.h"
+
+//Private Functions
+
+/*
+Function Name: HTTP Server Answer
+Purpose: Answers messages saying that a connection is ready to start
+*/
+void HTTPServerAnswer();
+
+//Module Vars
+static SOCKET ServerSocket = INVALID_SOCKET;
+
+static HWND MsgWindow;
+
+/******************************************************************************/
+// returns 0 on success, and a WSA error otherwise
+int StartHTTPServer(HWND PassedMsgWindow) {
+  
+  MsgWindow = PassedMsgWindow;
+  //Create the server socket
+  return CreateListeningSocket(gsdl_port_num, MsgWindow, HTTP_SERVER_MSG, ServerSocket);
+}
+
+/******************************************************************************/
+void EndHTTPServer()
+{
+  //Stop the listening socket
+  DestroyListeningSocket(ServerSocket, MsgWindow);
+}
+
+/******************************************************************************/
+void ProcessHTTPServerMsg(WPARAM Socket, LPARAM MsgInfo) {
+  log_message("accept message arrived\n");
+  if (Socket != ServerSocket) {
+    if (gsdl_keep_log || gsdl_show_console) log_message("Incorrect socket sent in message");
+  }
+  switch (WSAGETSELECTEVENT(MsgInfo)) {
+  case FD_ACCEPT:
+    switch (WSAGETSELECTERROR(MsgInfo)) {
+    case WSAENETDOWN:
+      LogCriticalError("1","Network Down");
+      break;
+    default: //No Error
+      HTTPServerAnswer();
+    }
+    break;
+  }
+}
+
+/******************************************************************************/
+void HTTPServerAnswer() {
+  SOCKADDR_IN ClientSockAddr;
+  SOCKET ClientSocket;
+  int AddrLen = sizeof(SOCKADDR_IN);
+  RequestThreadMessageT Parameters;
+  while (AnswerListeningSocket(ServerSocket, ClientSocket, ClientSockAddr, AddrLen) == 0) {
+    log_message("Answering socket\n");
+    //Call the thread procedure to handle the connection
+    Parameters.ClientSockAddr = ClientSockAddr;
+    Parameters.ClientSocket = ClientSocket;
+    Parameters.AddrLen = AddrLen;
+    RequestThread(&Parameters);
+  }
+}
Index: /gsdl/trunk/runtime-src/src/w32server/httpsrv.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/httpsrv.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/httpsrv.h	(revision 16571)
@@ -0,0 +1,57 @@
+/**********************************************************************
+ *
+ * httpsrv.h
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#define HTTP_SERVER_MSG WM_USER + 23
+
+/*
+Function Name: Start HTTP Server
+
+Purpose: Starts the HTTP server.  Inits Winsock, MIME, loads registry
+         stuff, etc.
+
+Parameters:
+	PassedMsgWindow - The handle of the window that handles messages.  Needed
+                          to setup WSASelect notification of socket events and
+                          to send a shutdown message on error.  */
+
+// returns 0 on success, and a WSA error otherwise
+int StartHTTPServer(HWND PassedMsgWindow);
+
+/*
+Function Name: End HTTP Server
+Purpose: Ends the HTTP server.  Cleans up MIME, users, etc.
+*/
+void EndHTTPServer();
+
+/*
+Function Name: Process HTTP Server Message
+Purpose: Processes HTTP_SERVER_MSG messages.
+Parameters:
+	Socket - The socket the message is regarding (WPARAM)
+	MsgInfo - The messsage (LPARAM)
+*/
+void ProcessHTTPServerMsg(WPARAM Socket, LPARAM MsgInfo);
Index: /gsdl/trunk/runtime-src/src/w32server/locate.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/locate.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/locate.cpp	(revision 16571)
@@ -0,0 +1,274 @@
+/**********************************************************************
+ *
+ * locate.cpp
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "text_t.h"
+#include <windows.h>
+#include <stdio.h>
+#include "locate.h"
+#include "settings.h"
+
+/* The following values are inserted or used by FNORD.CPP */
+HWND GSDL_Window;
+int line_spacing;
+RECT text_rect;
+
+
+static FILE *log_file=NULL;
+
+static int location_found=0;
+text_t data_location;
+
+void set_location(text_t possible)
+{
+  if (location_found != 0) return;
+  if (!possible.empty()) {
+    data_location = possible;
+    if (*(data_location.end()-1) != '\\') {
+      data_location.push_back('\\');
+    }
+    location_found = 1;
+  }
+}
+
+void find_location(void)
+{
+  if (location_found != 0) return;
+  
+  char here[MAX_FILENAME_SIZE];
+  char *send;
+
+  if (GetModuleFileName(NULL,here,MAX_FILENAME_SIZE) <= 0) {
+    // failed
+    data_location.clear();
+  } else {
+    send = strrchr(here,'\\');
+    if (send != NULL) {
+      ++send;
+    } else {
+      send = strchr(here,':');
+      if (send != NULL) {
+        ++send;
+      } else {
+        send = here;
+      }
+    }
+  }
+  *send = 0;
+  data_location.setcstr(here);
+  location_found = 1;
+}
+
+void open_log_file()
+{
+  if (log_file != NULL) fclose(log_file);
+  log_file = fopen(gsdl_log_name, "a");
+  if (log_file != NULL) {
+	  fprintf (log_file, "\n\n-----------\n");
+	  fprintf (log_file, "log started\n");
+	  fprintf (log_file, "-----------\n\n");
+  }
+}
+
+void close_log_file()
+{
+  if (log_file != NULL) {
+    fclose(log_file);
+    log_file = NULL;
+  }
+}
+
+#define CONSOLE_BUFFER_SIZE 2048
+char console_buffer[CONSOLE_BUFFER_SIZE];
+char *next_console, *last_console;
+int console_top, console_y;
+
+void activate_console(void)
+{
+  gsdl_show_console = 1;
+  next_console = console_buffer;
+  *next_console = 0;
+  last_console = next_console;
+  console_y = console_top = text_rect.top +
+    (text_rect.bottom - text_rect.top + 1) % line_spacing / 2;
+  InvalidateRect(GSDL_Window,NULL,TRUE);
+}
+
+void deactivate_console(void)
+{
+  gsdl_show_console = 0;
+  InvalidateRect(GSDL_Window,NULL,TRUE);
+}
+
+void refresh_console(HDC dc)
+{
+  int loc;  char *b, *e;
+  loc = console_top;
+  for (e = console_buffer;;) {
+    b = e;
+    while (*e >= ' ') ++e;
+    TextOut(dc,0,loc,b,e-b);
+    loc += line_spacing;
+    if (*e == 0) break;
+    ++e;
+    if (*e == 0) break;
+    }
+}
+
+void scroll(HDC dc, int nbits)
+{
+  RECT scroll, clip, update;
+
+  scroll.left = clip.left = text_rect.left;
+  scroll.right = clip.right = text_rect.right;
+  clip.top = console_top;
+  clip.bottom = text_rect.bottom;
+  scroll.top = clip.top + nbits;
+  scroll.bottom = text_rect.bottom;
+  ScrollDC(dc,0,-nbits,&scroll,&clip,NULL,&update);
+  FillRect(dc,&update, (HBRUSH)GetStockObject(WHITE_BRUSH));
+}
+
+int remove_line()
+{
+  char *bin, *bout;
+  bin = bout = console_buffer;
+  while (*bin >= ' ') ++bin;
+  if (*bin != 0) {
+    ++bin;
+    if (*bin != 0) {
+      while (*bin != 0) *bout++ = *bin++;
+      *bout = *bin;
+      last_console -= (bin - bout);
+      next_console = bout;
+      return line_spacing;
+      }
+    }
+  next_console = console_buffer;
+  *next_console = 0;
+  last_console = next_console;
+  return 0;
+}
+
+void display_line(HDC dc, char *line, int nch)
+{
+  int scroll_needed = 0;
+  while (next_console + nch + 1 
+         > console_buffer + CONSOLE_BUFFER_SIZE)
+    scroll_needed += remove_line();
+  console_y -= scroll_needed;
+  if (*last_console == '\n') {
+    console_y += line_spacing;
+    if (console_y + line_spacing > text_rect.bottom) {
+      scroll_needed += remove_line();
+      console_y -= line_spacing;
+      }
+    last_console = next_console;
+    }
+  if (scroll_needed != 0) scroll(dc, scroll_needed);
+  while (nch-- > 0) *next_console++ = *line++;
+  TextOut(dc,0,console_y,last_console,next_console-last_console);
+  *next_console = *line;
+  if (*next_console != 0) {
+    last_console = next_console;
+    ++next_console;
+    *next_console = 0;
+    }
+}
+
+void display_text(HDC dc, char *buffer)
+{
+  char *bl, *bp;
+  for (bl = buffer;;) {
+    for (bp = bl;;) {
+      if (*bp == '\t') *bp = ' ';
+      if (*bp < ' ') break;
+      ++bp;
+      }
+    if (*bp != 0) *bp = '\n';
+    display_line(dc, bl, bp-bl);
+    if (*bp == 0) break;
+    bl = bp+1;
+    if (*bl == 0) break;
+    }
+}
+
+void log_message(char *msg)
+{
+  if (log_file != NULL) {
+    fprintf(log_file,"%s",msg);
+    fflush(log_file);
+  }
+  if (gsdl_show_console) {
+    char buffer[1024];  HDC dc;
+    sprintf(buffer,"%s",msg);
+    dc = GetDC(GSDL_Window);
+    display_text(dc,buffer);
+    ReleaseDC(GSDL_Window,dc);
+  }
+}
+
+void log_message_N(char*msg, int n)
+{
+  if (log_file != NULL) {
+    int len = 0;
+    while (len < n) {
+      fputc (msg[len], log_file);
+      ++len;
+    }
+    fflush(log_file);
+  }
+  
+  // these messages are not send to the console
+  if (gsdl_show_console) {
+    HDC dc;
+    dc = GetDC(GSDL_Window);
+    display_text(dc,"message only written to log file\n");
+    ReleaseDC(GSDL_Window,dc);
+  }
+}
+
+void LogCriticalError(char *cderr, char *Msg)
+{
+  char MsgBoxStr[200];
+  
+  strcpy(MsgBoxStr, "Critical Error Number ");
+  strcat(MsgBoxStr, cderr);
+  strcat(MsgBoxStr, "\n");
+  strcat(MsgBoxStr, Msg);
+  strcat(MsgBoxStr, "\nGreenstone Digital Library software\nshutting down");
+  MessageBox(GSDL_Window, MsgBoxStr, "Greenstone Digital Library Software",
+	     MB_OK | MB_ICONERROR);
+  PostMessage(GSDL_Window, WM_DESTROY, 0, 0);
+}
+
+
+/* returns second-first taking into account wrap around */
+DWORD DiffTickCounts (DWORD first, DWORD second) 
+{
+  if (second >= first) return (second-first);
+  return (MAXDWORD-first+1+second);
+}
Index: /gsdl/trunk/runtime-src/src/w32server/locate.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/locate.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/locate.h	(revision 16571)
@@ -0,0 +1,56 @@
+/**********************************************************************
+ *
+ * locate.h
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef MAX_FILENAME_SIZE
+#define MAX_FILENAME_SIZE 2048
+#endif
+
+#include "text_t.h"
+
+extern HWND GSDL_Window;
+extern int line_spacing;
+extern RECT text_rect;
+
+void refresh_console(HDC dc);
+
+extern text_t data_location;
+
+extern void set_location(text_t possible);
+extern void find_location(void);
+
+extern void open_log_file(void);
+extern void close_log_file(void);
+extern void log_message(char *msg);
+extern void log_message_N(char*msg, int n);
+
+extern void activate_console(void);
+extern void deactivate_console(void);
+
+extern void LogCriticalError(char *cderr, char *Msg);
+
+/* returns first-second taking into account wrap around */
+extern DWORD DiffTickCounts (DWORD first, DWORD second);
Index: /gsdl/trunk/runtime-src/src/w32server/netio.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/netio.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/netio.cpp	(revision 16571)
@@ -0,0 +1,465 @@
+/**********************************************************************
+ *
+ * netio.cpp
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <memory.h>
+#pragma hdrstop
+#include "netio.h"
+#include "locate.h"
+#include "d_winsock.h"
+
+//Private Variables and Declarations
+
+//Max string size for a host name
+#define MAXHOSTNAME 100
+
+//Timeout for waiting between "packets" in seconds
+#define NETIO_CONN_TIMEOUT 20 //3 sec  was 180 @@@@@ WJR
+
+#define HTTP_DNS_MSG WM_USER + 1
+int dns_msg_received = 0;
+int dns_msg_error = 0;
+
+DWORD LocalIPNumber;
+char LocalName[MAXHOSTNAME];
+
+//Private Function Declarations
+DWORD GetHostID();
+
+// returns 0 on success,
+// WSASYSNOTREADY, WSAVERNOTSUPPORTED, or WSAEINVAL on failure
+int InitNetIO() {
+  WSADATA Data;
+  
+  // Load Winsock
+  int err = d_WSAStartup(MAKEWORD(1, 1), &Data);
+  
+  // get local IP number
+  if (err == 0) LocalIPNumber = GetHostID();
+  else LocalIPNumber = INADDR_ANY;
+  
+  // set the Local Name to "" for now
+  LocalName[0] = 0;
+  
+  return err;
+}
+
+
+void CleanUpNetIO() {
+  //Experimental, heard this will better clean up, especialy if a call is
+  //blocking....
+  d_WSAUnhookBlockingHook();
+
+  //Clean up Winsock
+  d_WSACleanup();
+}
+
+
+void ResetNetIO() {
+  //Figure out the local name on first querry, set to "" until then...
+  LocalName[0] = 0;
+}
+
+
+DWORD GetLocalIP() {
+  return LocalIPNumber;
+}
+
+long __stdcall DNSWindowProc(HWND hWnd,UINT wMsg, WPARAM wParam, LPARAM lParam) {
+  if (wMsg == HTTP_DNS_MSG) {
+    dns_msg_received = 1;
+    dns_msg_error = WSAGETASYNCERROR(lParam);
+    return 0;
+  }
+  
+  return DefWindowProc(hWnd, wMsg, wParam, lParam);
+}
+
+char *GetLocalName(HINSTANCE hInstance) {
+  // static in case it is written to after the function has finished
+  // (I did not error checking on WSACancelAsyncRequest)
+  static char buf[MAXGETHOSTSTRUCT];
+	
+  if (LocalName[0] == 0) {
+    hostent *DNSResult = NULL;
+    in_addr LocalInAddr;
+    
+    // if we failed to get the local IP number
+    // use the loop-back device
+    if (LocalIPNumber == INADDR_ANY) {
+      strcpy(LocalName, "127.0.0.1"); // loop-back device
+      return LocalName;
+    }
+    
+    //Convert the number to an in_addr struct
+    LocalInAddr.s_addr = LocalIPNumber;
+    
+    // if we fail to find the domain name we will
+    // still want the IP address
+    strcpy(LocalName, d_inet_ntoa(LocalInAddr));
+    
+    // make sure they actually passed in an instance handle
+    if (hInstance == NULL) return LocalName;
+    
+    // do a async domain name lookup so that we
+    // can control the timeout
+    
+    // create a window class and window to handle the async messages
+    WNDCLASS wc; HWND hwndDNS;
+    
+    wc.style = 0;
+    wc.lpfnWndProc = DNSWindowProc;
+    wc.cbClsExtra = 0;
+    wc.cbWndExtra = 0;
+    wc.hInstance = hInstance;
+    wc.hIcon = NULL;
+    wc.hCursor = NULL;
+    wc.hbrBackground = NULL;
+    wc.lpszMenuName = NULL;
+    wc.lpszClassName = "GSDL DNS Window";
+    if (!RegisterClass(&wc)) return LocalName;
+    
+    hwndDNS = CreateWindow("GSDL DNS Window", "", 
+			   WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, 
+			   NULL, NULL, hInstance, NULL);
+    if (!hwndDNS) return LocalName;
+    
+    // process all messages currently on the queue
+    MSG Message;
+    while (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) {
+      TranslateMessage(&Message); /* translate keyboard messages */
+      DispatchMessage(&Message);  /* return control to Windows NT */
+    }
+    
+    //Do a async DNS lookup on the IP number
+    dns_msg_received = 0;
+    dns_msg_error = 0;
+    HANDLE asyncGetHostReq = d_WSAAsyncGetHostByAddr(
+						     hwndDNS, HTTP_DNS_MSG, (char *)&(LocalInAddr), 
+						     4, PF_INET, buf, MAXGETHOSTSTRUCT);
+    
+    if (asyncGetHostReq != NULL) {
+      // wait 5 seconds for the request to complete
+      int now = GetTickCount();
+      while ((DiffTickCounts(now, GetTickCount()) < 5000) && !dns_msg_received) {
+	if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) {
+	  TranslateMessage(&Message); /* translate keyboard messages */
+	  DispatchMessage(&Message);  /* return control to Windows NT */
+	} else {
+	  Sleep(1);
+	}
+      }
+      if (!dns_msg_received)
+	d_WSACancelAsyncRequest(asyncGetHostReq);
+    }
+    
+    DestroyWindow(hwndDNS);
+    
+    if (dns_msg_received && (dns_msg_error == 0)) {
+      //Worked, use the primary name
+      strcpy(LocalName, ((hostent *)(buf))->h_name);
+      //Convert it to lower case for cosmedic reasons
+      CharLower(LocalName);
+    }
+  }
+  return LocalName;
+}
+
+
+// returns 0 on success, and a WSA error message on failure.
+// possible error messages include:
+// WSANOTINITIALISED, WSAENETDOWN, WSAEAFNOSUPPORT, WSAEINPROGRESS, WSAEMFILE,
+// WSAENOBUFS, WSAEPROTONOSUPPORT, WSAEPROTOTYPE, WSAESOCKTNOSUPPORT,
+// WSAEADDRINUSE, WSAEINVAL, WSAEISCONN, WSAENOTSOCK, WSAEOPNOTSUPP
+
+#define MAXBINDCOUNT 4096
+int CreateListeningSocket(int &PortNum, HWND MsgWindow, 
+			  WORD SocketMsg, SOCKET &ServerSocket) {
+  int err = 0;
+  SOCKADDR_IN ServerSockAddr;
+  int bind_port, bind_count;
+  
+  //Create the Server Socket
+  ServerSocket = d_socket(AF_INET, SOCK_STREAM, 0);
+  if (ServerSocket == INVALID_SOCKET) return d_WSAGetLastError();
+  
+  bind_port = PortNum;
+  for (bind_count=0; bind_count < MAXBINDCOUNT; ++bind_count) {
+    // Set up the Server Socket Address
+    memset(&ServerSockAddr, 0, sizeof(ServerSockAddr)); //Needed?
+    ServerSockAddr.sin_port = d_htons( (WORD) bind_port);
+    ServerSockAddr.sin_family = AF_INET;
+    ServerSockAddr.sin_addr.s_addr = d_htonl(INADDR_ANY);
+    
+    // Try to bind the socket with the address
+    if (d_bind(ServerSocket, (LPSOCKADDR) &ServerSockAddr,
+	       sizeof(ServerSockAddr)) != SOCKET_ERROR) {
+      PortNum = bind_port;
+      break;
+    }
+    
+    // make sure it failed to bind because it was
+    // already bound
+    err = d_WSAGetLastError ();
+    if (err != WSAEADDRINUSE) return err;
+    
+    // Or choose another port number to try
+    if (bind_port == 80) bind_port = IPPORT_RESERVED+1;
+    else if (bind_count == 0) bind_port = 80;
+    else ++bind_port;
+  }
+  
+  // return an error in we couldn't find a valid port
+  if (bind_count == MAXBINDCOUNT) return WSAEADDRINUSE;
+  
+  // Start listening for connections
+  if (d_listen(ServerSocket, SOMAXCONN) == SOCKET_ERROR)
+    return d_WSAGetLastError ();	
+  
+  // Set up event for new connections
+  if (d_WSAAsyncSelect(ServerSocket, MsgWindow, SocketMsg, FD_ACCEPT) == SOCKET_ERROR)
+    return d_WSAGetLastError ();
+  
+  return 0;
+}
+
+
+int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket, 
+			  SOCKADDR_IN &ClientSockAddr, int AddrLen) {
+  if (d_WSAIsBlocking()) {
+    log_message("rejected connect due blocking\n");
+    return -1;
+  }
+  
+  ClientSocket = d_accept(ServerSocket, (LPSOCKADDR) &ClientSockAddr, &AddrLen);
+  if (ClientSocket == INVALID_SOCKET) {
+    log_message("accept failed - connection lost\n");
+    return -1;
+  }
+  
+  log_message("accept success - connection made\n");
+  return 0;
+}
+
+void DestroyListeningSocket(SOCKET &ServerSocket, HWND MsgWindow) {
+  //Remove any message notification
+  d_WSAAsyncSelect(ServerSocket, MsgWindow, 0, 0);
+  
+  //Close the socket
+  CloseSocket(ServerSocket);
+}
+
+void CloseSocket(SOCKET &TargetSocket) {
+  if (TargetSocket != INVALID_SOCKET) {
+    //Since we're closing the socket, there's not much I can do about errors
+    //now so I'm not gonna bother checking...
+    
+    //Shutdown both ends, assume we have all data...
+    d_shutdown(TargetSocket, 2);
+    
+    d_closesocket(TargetSocket);
+    
+    //Make sure we can't use the old handle again...
+    TargetSocket = INVALID_SOCKET;
+  }
+}
+
+int GetData(SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize,
+	    int ThreadNum) {
+  
+  int NumRecv;
+  int Error;
+  struct timeval Timeout;
+  fd_set SocketSet;
+  
+  //Set up a socket set structure with just ClientSocket for  select(..)
+  FD_ZERO(&SocketSet);
+  FD_SET(ClientSocket, &SocketSet);
+  
+  //set timeout
+  Timeout.tv_sec = NETIO_CONN_TIMEOUT;
+  Timeout.tv_usec = 0;
+  
+  do {
+    NumRecv = d_recv(ClientSocket, (char *) IOBuffer, IOBufferSize, 0);
+    if (NumRecv == 0) {
+      //Lost connect
+      return -1;
+      
+    } else if (NumRecv == SOCKET_ERROR) {
+      Error = d_WSAGetLastError();
+      if (Error == WSAEWOULDBLOCK) {
+	NumRecv = 0;
+	//Wait for socket to be readable
+	if (d_select(0, &SocketSet, NULL, NULL, &Timeout) != 1) {
+	  //Timeout
+	  return -1;
+	}
+	
+      } else {
+	//Assume connection terminated
+	return -1;
+      }
+    }
+  } while(NumRecv == 0);
+  return NumRecv;
+}
+
+int GetLine(text_t &OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize,
+	    int &BufferIndex, int &DataInBuffer, int ThreadNum) {
+
+  OutStr.clear();
+  char CurChar;
+  
+  do {
+    if (BufferIndex == DataInBuffer) { //Need more data
+      DataInBuffer = GetData(ClientSocket, IOBuffer, IOBufferSize, ThreadNum);
+      if (DataInBuffer == -1) {
+	//Lost connect
+	return -1;
+      }
+      BufferIndex = 0;
+    }
+    CurChar = IOBuffer[BufferIndex];
+    ++BufferIndex;
+    if ((CurChar != 10) && (CurChar != 13))  {
+      OutStr.push_back(CurChar);
+    }
+  } while (CurChar != 10);
+  
+  return 0;
+}
+
+int SendData(SOCKET ClientSocket, BYTE *SendBuffer, int NumToSend,
+	     int ThreadNum) {
+  
+  int NumSent = 0;
+  int Error;
+  struct timeval Timeout;
+  fd_set SocketSet;
+  
+  char NumSentStr[50];
+  itoa(NumToSend, NumSentStr, 10);
+  
+  //Set up a socket set structure with just ClientSocket for  select(..)
+  FD_ZERO(&SocketSet);
+  FD_SET(ClientSocket, &SocketSet);
+  //set timeout
+  Timeout.tv_sec = NETIO_CONN_TIMEOUT;
+  Timeout.tv_usec = 0;
+  
+  while (NumToSend > 0) {
+    NumSent = d_send(ClientSocket, (char *) SendBuffer + NumSent, NumToSend, 0);
+    if (NumSent == 0) {
+      //Lost connect
+      return -1;
+    }
+    else if (NumSent == SOCKET_ERROR) {
+      Error = d_WSAGetLastError();
+      if (Error == WSAEWOULDBLOCK) {
+	NumSent = 0;
+	if (d_select(0, NULL, &SocketSet, NULL, &Timeout) != 1) {
+	  //Timeout
+	  return -1;
+	}
+      }
+      else {
+	//Lost Connection
+	return -1;
+      }
+    }
+    NumToSend -= NumSent;
+  }
+  return 0;
+}
+
+
+/******************************************************************************/
+//Private Functions
+/******************************************************************************/
+/*-----------------------------------------------------------
+ * Function: GetHostID()
+ *
+ * Description:
+ *  Get the Local IP address using the following algorithm:
+ *    - get local hostname with gethostname()
+ *    - attempt to resolve local hostname with gethostbyname()
+ *    if that fails:
+ *    - get a UDP socket
+ *    - connect UDP socket to arbitrary address and port
+ *    - use getsockname() to get local address
+ *
+ * Notes: Copyright by Bob Quinn, 1995, taken from his Winsock library
+ *        was removed from its original module unmodified
+ */
+DWORD GetHostID () {
+  char szLclHost [MAXHOSTNAME];
+  LPHOSTENT lpstHostent;
+  SOCKADDR_IN stLclAddr;
+  SOCKADDR_IN stRmtAddr;
+  int nAddrSize = sizeof(SOCKADDR);
+  SOCKET hSock;
+  int nRet;
+  
+  /* Init local address (to zero) */
+  stLclAddr.sin_addr.s_addr = INADDR_ANY;
+  
+  /* Get the local hostname */
+  nRet = d_gethostname(szLclHost, MAXHOSTNAME);
+  if (nRet != SOCKET_ERROR) {
+    /* Resolve hostname for local address */
+    lpstHostent = d_gethostbyname((LPSTR)szLclHost);
+    if (lpstHostent)
+      stLclAddr.sin_addr.s_addr = *((u_long FAR*) (lpstHostent->h_addr));
+  }
+  
+  /* If still not resolved, then try second strategy */
+  if (stLclAddr.sin_addr.s_addr == INADDR_ANY) {
+    /* Get a UDP socket */
+    hSock = d_socket(AF_INET, SOCK_DGRAM, 0);
+    if (hSock != INVALID_SOCKET)  {
+      /* Connect to arbitrary port and address (NOT loopback) */
+      stRmtAddr.sin_family = AF_INET;
+      stRmtAddr.sin_port   = d_htons(IPPORT_ECHO);
+      stRmtAddr.sin_addr.s_addr = d_inet_addr("128.127.50.1");
+      nRet = d_connect(hSock,
+		       (LPSOCKADDR)&stRmtAddr,
+		       sizeof(SOCKADDR));
+      if (nRet != SOCKET_ERROR) {
+	/* Get local address */
+	d_getsockname(hSock,
+		      (LPSOCKADDR)&stLclAddr,
+		      (int FAR*)&nAddrSize);
+      }
+      d_closesocket(hSock);   /* we're done with the socket */
+    }
+  }
+  return (stLclAddr.sin_addr.s_addr);
+}
Index: /gsdl/trunk/runtime-src/src/w32server/netio.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/netio.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/netio.h	(revision 16571)
@@ -0,0 +1,160 @@
+/**********************************************************************
+ *
+ * netio.h
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "text_t.h"
+
+/*
+Module Name: Net IO
+Purpose: High level Socket IO and Misc socket routines
+Public Functions:
+	InitNetIO
+   CleanUpNetIO
+
+	GetLocalIP
+	GetLocalName
+
+   CreateListeningSocket
+   AnswerListeningSocket
+   DestroyListeningSocket
+
+   CloseSocket
+
+	GetData
+	GetLine
+
+	SendData
+	SendFile
+*/
+
+//Public Functions
+
+/*
+Function Name: Init Net IO
+Purpose: Initializes the module so calls can be made querying network
+         information for the local macnine.
+Notes: MUST be called before GetLocalIP and GetLocalName
+*/
+
+// returns 0 on success,
+// WSASYSNOTREADY, WSAVERNOTSUPPORTED, or WSAEINVAL on failure
+int InitNetIO();
+
+/*
+Function Name: Cleanup Net IO
+Purpose: Cleans up the module and unloads Winsock
+*/
+void CleanUpNetIO();
+
+/*
+Function Name: Reset Net IO
+Purpose: Resets internal data in NetIO to reflect registry changes, etc.
+*/
+void ResetNetIO();
+
+/*
+Function Name: Get Local IP
+Purpose: Gets the local IP number
+Returns: The local IP number as an double word (4 bytes)
+*/
+DWORD GetLocalIP();
+
+/*
+Function Name: Get Local Name
+Purpose: Gets the local Domain name, or if there is none, then the server
+address in dotted format.
+Returns: A string containing the local address
+*/
+char *GetLocalName(HINSTANCE hInstance);
+
+// returns 0 on success, and a WSA error message on failure.
+// possible error messages include:
+// WSANOTINITIALISED, WSAENETDOWN, WSAEAFNOSUPPORT, WSAEINPROGRESS, WSAEMFILE,
+// WSAENOBUFS, WSAEPROTONOSUPPORT, WSAEPROTOTYPE, WSAESOCKTNOSUPPORT,
+// WSAEADDRINUSE, WSAEINVAL, WSAEISCONN, WSAENOTSOCK, WSAEOPNOTSUPP
+int CreateListeningSocket(int &PortNum, HWND MsgWindow, 
+			  WORD SocketMsg, SOCKET &ServerSocket);
+
+int AnswerListeningSocket(SOCKET ServerSocket, SOCKET &ClientSocket, 
+			  SOCKADDR_IN &ClientSockAddr, int AddrLen);
+
+void DestroyListeningSocket(SOCKET &ServerSocket, HWND MsgWindow);
+
+void CloseSocket(SOCKET &TargetSocket);
+
+/*
+Function Name: Get Data
+Purpose: Gets data from a socket with muli-threaded debugging
+Parameters:
+	ClientSocket - The socket to get data from
+	IOBuffer - A pointer to a chunk of memory to put data in
+	IOBufferSize - Size of the buffer
+	ThreadNum - Number of the thread that called this functions used for debugging
+
+Returns: -1 on error, else the number of bytes received
+
+Notes:
+Removed socket error checking because I was unable to isolate what
+errors I was getting when getting a "rude" disconnect
+*/
+int GetData(SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, int ThreadNum);
+
+/*
+Function Name: Get Line
+Purpose: Gets a line of text (ended by a LF (10)) from a socket with buffered
+			input.  If the buffer is empty this function fills the buffer, else it
+			just changes an index. Also has the ability to do multi-threaded debuging
+Parameters:
+	OutStr - Varible were output is put
+	ClientSocket - The socket to get data from
+	IOBuffer - A pointer to a chunk of memory to put data in
+	IOBufferSize - Size of the buffer
+	BufferIndex - A zero based index of what charactor in the buffer we're at
+	DataInBuffer - Amount of data in the buffer
+	ThreadNum - Number of the thread that called this functions used for debugging
+
+Returns: -1 on disconnect or error (abort connection), 0 on success
+*/
+int GetLine(text_t &OutStr, SOCKET ClientSocket, BYTE *IOBuffer, int IOBufferSize, 
+	    int &BufferIndex, int &DataInBuffer, int ThreadNum);
+
+/*
+Function Name: Send Data
+Purpose: Sends data to a socket with muli-thread debugging
+Parameters:
+	ClientSocket - The socket to get data from
+	SendBuffer - A pointer to a chunk of memory to put data in
+	NumToSend - Number of bytes to send from buffer
+	ThreadNum - Number of the thread that called this functions used for debugging
+
+Returns: -1 on error, 0 on success
+
+Notes:
+Removed socket error checking because I was unable to isolate what
+errors I was getting when getting a "rude" disconnect
+*/
+int SendData(SOCKET ClientSocket, BYTE *SendBuffer, 
+	     int NumToSend, int ThreadNum);
Index: /gsdl/trunk/runtime-src/src/w32server/parse.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/parse.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/parse.cpp	(revision 16571)
@@ -0,0 +1,205 @@
+/**********************************************************************
+ *
+ * parse.cpp
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <memory.h>
+#pragma hdrstop
+
+#include "parse.h"
+
+//Public Functions
+/******************************************************************************/
+void Left(char *DestStr, const char *SourceStr, const int Len) {
+  memcpy(DestStr, SourceStr, Len);
+  DestStr[Len] = 0;
+}
+/******************************************************************************/
+void Right(char *DestStr, const char *SourceStr, const int Len) {
+  int SourceLen, Offset;
+  
+  SourceLen = strlen(SourceStr);
+  Offset = SourceLen - Len;
+  
+  memcpy(DestStr, SourceStr + Offset, Len + 1);
+  //The null is already copied
+}
+/******************************************************************************/
+void TrimLeft(char *TargetStr) {
+  int i, NewStrSize;
+  
+  i = 0;
+  //Find the first non-space charactor
+  while ( (TargetStr[i] == ' ') || (TargetStr[i] == '\t') ) {
+    ++i;
+  }
+  //If we have space to get rid of, move the string
+  if (i > 0) {
+    NewStrSize = strlen(TargetStr) - i + 1; //Include the NULL in the size
+    memmove(TargetStr, TargetStr + i, NewStrSize);
+  }
+}
+/******************************************************************************/
+void TrimRight(char *TargetStr) {
+  int i;
+  
+  //Find the last non-space charactor (index i)
+  i = strlen(TargetStr) - 1;
+  while ((i >= 0) && ((TargetStr[i] == ' ') || (TargetStr[i] == '\t')) ) {
+    --i;
+  }
+  //Set the NULL 1 after the last non-space charactor
+  TargetStr[i+1] = 0;
+}
+/******************************************************************************/
+void Trim(char *TargetStr) {
+  TrimRight(TargetStr);
+  TrimLeft(TargetStr);
+}
+/******************************************************************************/
+void GetWord(text_t &DestStr, text_t::const_iterator first,
+	     text_t::const_iterator last, text_t::const_iterator &next) {
+
+  DestStr.clear();
+  next = last;
+
+  while (first != last) {
+    if (*first == ' ' || *first == '\t') {
+      ++first;
+      while ((first != last) && ((*first == ' ') || (*first == '\t'))) {
+	++first;
+      }
+      next = first;
+      break;
+    } else {
+      DestStr.push_back(*first);
+    }
+    ++first;
+  }
+}
+/******************************************************************************/
+
+void GetLastWord(text_t &DestStr, text_t::const_iterator first, text_t::const_iterator last, 
+		 text_t::const_iterator &Start) {
+
+  DestStr.clear();
+  Start = first;
+
+  while (first != last) {
+    if ((*first == ' ') || (*first == '\t')) {
+      DestStr.clear();
+      Start = first+1;
+    } else {
+      DestStr.push_back(*first);
+    }
+    ++first;
+  }
+}
+/******************************************************************************/
+void SplitPath(char *Path, char *Dir, char *FileName) {
+  int SplitPoint;
+  SplitPoint = strlen(Path) - 1;
+  while ((SplitPoint > 0) && (Path[SplitPoint] != '\\')) {
+    --SplitPoint;
+  }
+  if ((SplitPoint == 0) && (Path[SplitPoint] != '\\')) {
+    //No directory, just a file name
+    Dir[0] = 0;
+    strcpy(FileName, Path);
+  }
+  else {
+    //Move past the last slash
+    ++SplitPoint;
+    
+    //Directory
+    int i = 0;
+    while (i < SplitPoint) {
+      Dir[i] = Path[i];
+      ++i;
+    }
+    Dir[i] = 0;
+    
+    //File name
+    int j = 0;
+    while (Path[i] != 0) {
+      FileName[j] = Path[i];
+      ++j;
+      ++i;
+    }
+    FileName[j] = 0;
+  }
+}
+/******************************************************************************/
+void GetExtention(char *Path, char *Extention) {
+  int Dot;
+  int PathLen;
+  
+  PathLen = strlen(Path) - 1;
+  Dot = PathLen;
+  while ((Dot > 0) && (Path[Dot] != '.')) {
+    --Dot;
+  }
+  if (Dot > 0) {
+    strcpy(Extention, Path + Dot + 1);
+  }
+  else {
+    Extention[0] = 0;
+  }
+}
+/******************************************************************************/
+void TranslateEscapeString(char *TargetStr) {
+  int i = 0;
+  int j = 0;
+  
+  while (TargetStr[i] != 0) {
+    if ((TargetStr[i] == '%') && (TargetStr[i+1] != 0) && (TargetStr[i+2] != 0)) {
+      //Escaped value (did checking to make sure there are 2 more chars)
+      //         #pragma warn -sig //Suppress significant digit loss warning (BC++)
+      TargetStr[j] = 16 * HexVal(TargetStr[i+1]) + HexVal(TargetStr[i+2]);
+      //         #pragma warn +sig   //Restore significant digit loss warning (BC++)
+      i += 3;
+    }
+    else {
+      TargetStr[j] = TargetStr[i];
+      ++i;
+    }
+    ++j;
+  }
+  TargetStr[j] = 0;
+}
+/******************************************************************************/
+int HexVal(char c) {
+  //   #pragma warn -sig //Suppress significant digit loss warning (BC++)
+  if (c >= '0' && c <= '9') return c - '0';
+  else if (c >= 'a' && c <= 'f') return c - 'a' + 10;
+  else if (c >= 'A' && c <= 'F') return c - 'A' + 10;
+  else return 0;
+  //   #pragma warn +sig   //Restore significant digit loss warning (BC++)
+}
+/******************************************************************************/
Index: /gsdl/trunk/runtime-src/src/w32server/parse.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/parse.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/parse.h	(revision 16571)
@@ -0,0 +1,162 @@
+/**********************************************************************
+ *
+ * parse.h
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "text_t.h"
+
+/*
+Module Name: Parse
+Purpose: General string parsing.  These are functions that are not in string.h,
+	but are found in many other libraries and high level languages.
+Public Functions:
+	Left
+	Right
+
+	Trim
+	TrimLeft
+	TrimRight
+
+	GetWord
+	GetLastWord
+
+   Split Path
+   GetExtention
+*/
+
+/*
+Function Name: Left
+Purpose: Copies the leftmost x number of charactors of a string to a buffer
+Parameters:
+	DestStr - Destination buffer for substring
+	SourceStr - Source string to make substing from
+	Len - Length of substring
+
+Notes: If Len is greater than strlen(SourceStr) a memory error may occur.
+*/
+void Left(char *DestStr, const char *SourceStr, const int Len);
+
+/*
+Function Name: Right
+Purpose: Copies the rightmost x number of charactors of a string to a buffer
+Parameters:
+	DestStr - Destination buffer for substring
+	SourceStr - Source string to make substing from
+	Len - Length of substring
+
+Notes: If Len is greater than strlen(SourceStr) then a memory error may
+		 occur.
+*/
+void Right(char *DestStr, const char *SourceStr, const int Len);
+
+/*
+Function Name: TrimLeft
+Purpose: Removes spaces and tabs from the left end of a string.
+Parameters:
+	TargetString - String to be trimmed
+*/
+void TrimLeft(char *TargetStr);
+
+/*
+Function Name: TrimRight
+Purpose: Removes spaces and tabs from the right end of a string.
+Parameters:
+	TargetString - String to be trimmed
+*/
+void TrimRight(char *TargetStr);
+
+/*
+Function Name: Trim
+Purpose: Removes spaces and tabs from both ends of a string.
+Parameters:
+	TargetString - String to be trimmed
+*/
+void Trim(char *TargetStr);
+
+/*
+Function Name: GetWord
+Purpose: Gets leftmost substring without a space in the string between the iterators
+         'here' and 'end'. Sets 'DestStr' to the substring. Sets the 'next' iterator 
+	 to the next non-space charactor in the string.  ' ' and '\t' and considered
+         spaces
+Parameters:
+	 DestString - Destination buffer for substring
+	 first - First character in source string
+	 last - end iterator (one past last character) of source string
+	 next - At end of function call is set to the location of next non-space
+               charactor in source string
+*/
+void GetWord(text_t &DestStr, text_t::const_iterator first,
+	     text_t::const_iterator last, text_t::const_iterator &next);
+
+/*
+Function Name: GetLastWord
+Purpose: Gets rightmost substring without a space sets Start to be the first
+         character of the substring in the original string.
+Parameters:
+	DestString - Destination buffer for substring
+	first and last - Source string to make substing from
+	Start - where the DestString starts at in the source string
+*/
+void GetLastWord(text_t &DestStr, text_t::const_iterator first, text_t::const_iterator last, 
+		 text_t::const_iterator &Start);
+
+
+/*
+Function Name: Split Path
+Purpose: Splits a path string into directory and file name
+Parameters:
+	Path - Path string (example "c:\Fnord\SomeFile.Ext")
+	Dir - Directory part of the Path (example "c:\Fnord\")
+	FileName - File name part of the path (example "SomeFile.Ext")
+*/
+void SplitPath(char *Path, char *Dir, char *FileName);
+
+/*
+Function Name: Get Extention
+Purpose: Splits a path string into directory and file name
+Parameters:
+	Path - Path string or file name (example "c:\Fnord\SomeFile.Ext")
+	Extention - Extention part of the path (example "Ext")
+*/
+void GetExtention(char *Path, char *Extention);
+
+/*
+Function Name: Translate Escape String
+Purpose: Translates all URL escape sequences, such as "%20" where "20" is
+	the resulting charactor in hexidecimal
+Parameters:
+	TargetStr - String that may contain URL escape sequences.  All sequences
+   	are decoded on return.
+*/
+void TranslateEscapeString(char *TargetStr);
+
+/*
+Function Name: Hex Value
+Purpose: Returns the value of a hexidecimal digit character as an integer
+Parameters:
+	c - Charactor to translate
+*/
+int HexVal(char c);
Index: /gsdl/trunk/runtime-src/src/w32server/resource.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/resource.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/resource.h	(revision 16571)
@@ -0,0 +1,55 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by server.rc
+//
+#define TRAY_ICON                       101
+#define COMMS_DIALOG                    102
+#define COMMS_DIALOG_DEBUG              102
+#define Main_Menu                       103
+#define COMMS_DIALOG2                   103
+#define GSDL_LOGO                       108
+#define GSDL_COL_TITLE                  109
+#define IDD_DIALOG1                     118
+#define GSDL_ICBMP                      126
+#define APPLY_BUTTON                    1000
+#define REMOTE_CHECK                    1001
+#define PROXY_CHECK                     1002
+#define CONSOLE_CHECK                   1003
+#define PROXY_EDIT_BOX                  1004
+#define PROXY_PORT_EDIT_BOX             1005
+#define TrayID                          1006
+#define LOG_DEBUG_CHECK                 1007
+#define SERVER_PORT_EDIT_BOX            1008
+#define LOG_LOCAL_CHECK                 1009
+#define LOG_REMOTE_CHECK                1010
+#define LOG_NAME_BOX                    1011
+#define LOG_CHECK                       1012
+#define SAVE_NAME_BOX                   1013
+#define SAVE_CHECK                      1014
+#define ID_AUTO_ENTER_LIBRARY           1015
+#define ID_RADIO_NETSCAPE               1016
+#define ID_RADIO_IE                     1017
+#define ID_RADIO_OTHER                  1018
+#define ID_OTHER_NAME                   1019
+#define ID_BROWSE_BUTTON                1020
+#define ID_OK_BUTTON                    1021
+#define ID_CANCEL_BUTTON                1022
+#define ID_RADIO_DEFAULT                1023
+#define ID_ARM_NAME                     1024
+#define ID_ARM_IP                       1025
+#define ID_ARM_127_0_0_1                1026
+#define ID_ARM_LOCALHOST                1027
+#define ID_PROJECT_SETTINGS             40001
+#define ID_PROJECT_EXIT                 40002
+#define ID_INSTALL_NETSCAPE             40007
+
+// Next default values for new objects
+// 
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE        127
+#define _APS_NEXT_COMMAND_VALUE         40011
+#define _APS_NEXT_CONTROL_VALUE         1030
+#define _APS_NEXT_SYMED_VALUE           102
+#endif
+#endif
Index: /gsdl/trunk/runtime-src/src/w32server/settings.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/settings.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/settings.cpp	(revision 16571)
@@ -0,0 +1,924 @@
+/**********************************************************************
+ *
+ * settings.cpp
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "text_t.h"
+#include "fileutil.h"
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\fstream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <fstream.h>
+#else
+#  include <fstream>
+#endif
+
+#include <windows.h>
+#include "httpsrv.h"
+#include "settings.h"
+#include "locate.h"
+#include "resource.h"
+#include "cgiwrapper.h"
+
+// library settings
+text_t gsdl_enterlib;
+text_t gsdl_gsdlhome;
+text_t gsdl_collecthome;
+text_t gsdl_dbhome;
+text_t gsdl_collections;
+colinfo_tmap gsdl_collectinfo;
+
+char gsdl_staticpages[MAX_FILENAME_SIZE];
+
+// debug settings
+char gsdl_log_name[MAX_FILENAME_SIZE] = "c:\\gsdl.log";
+int gsdl_keep_log = 0;
+int gsdl_show_console = 0;
+
+// general settings
+int gsdl_port_num = 80;
+int gsdl_auto_enter = 0;
+int gsdl_browser = GS_DEFAULT;
+char gsdl_browser_exe[MAX_FILENAME_SIZE] = "";
+text_t gsdl_url;
+text_t gsdl_conffile;
+int gsdl_start_browser = 1;
+int gsdl_address_resolution_method = 1;  // Get an IP, but don't resolve to a name
+
+// private data
+
+// pathnames of the latest installed versions of netscape and
+// internet explorer
+static char netscape_exe[MAX_FILENAME_SIZE]="";
+static char iexplore_exe[MAX_FILENAME_SIZE]="";
+
+// pathname of the default browser
+static char default_browser_exe[MAX_FILENAME_SIZE]="";
+
+// whether netscape is needed (used in the settings dialog box)
+static int gsdl_netscapeneeded = 0;
+
+static void remove_end_slashes(char *str) {
+  int len = strlen (str);
+  while ((len > 0) && ((str[len-1] == '\\') || (str[len-1] == '/'))) {
+    --len;
+  }
+  str[len] = '\0';
+}
+
+static void remove_end_slashes (text_t &str) {
+  char *cstr = str.getcstr();
+  remove_end_slashes (cstr);
+  str = cstr;
+  delete []cstr;
+}
+
+// returns 1 if successful, 0 otherwise
+// checks for a file's existence
+static int check_program_exe (char *path) {
+  UINT curerrormode;
+  OFSTRUCT reOpenBuff;
+  int retvalue = 0;
+  
+  reOpenBuff.cBytes = sizeof (OFSTRUCT);
+  
+  curerrormode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
+  if (OpenFile(path, &reOpenBuff, OF_EXIST) != HFILE_ERROR) retvalue = 1;
+  SetErrorMode(curerrormode);
+  
+  return retvalue;
+}
+
+
+// returns 1 if successful, 0 otherwise
+static int get_default_browser_path (char *providedhtmltype, char *path, int maxsize) {
+  HKEY hk1, hk2;
+  char htmltype[256];
+  long size;
+  int retval = 0;
+  
+  htmltype[0] = '\0';
+  path[0] = '\0';
+  
+  // try and get information about the default browser from the 
+  // registry
+  
+  if (providedhtmltype != NULL) strcpy (htmltype, providedhtmltype);
+  
+  else if (RegOpenKey(HKEY_CLASSES_ROOT, ".htm", &hk1) == ERROR_SUCCESS) {
+    size = 256;
+    RegQueryValue(hk1, NULL, htmltype, &size);
+    RegCloseKey(hk1);
+  }
+  
+  if (RegOpenKey(HKEY_CLASSES_ROOT, htmltype, &hk1) == ERROR_SUCCESS) {
+    if (RegOpenKey(hk1, "shell\\open", &hk2) == ERROR_SUCCESS) {
+      // look for the command to start the browser
+      size = maxsize;
+      if (RegQueryValue(hk2,"command",path,&size) == ERROR_SUCCESS) {
+				// strip all excess stuff off the command
+	char endchar = ' ';
+	int i = 0, len = 0;
+	int state = 0; // 0=strip initial white-space and quotes, 1=grab path
+	while (path[i] != '\0') {
+	  if (state == 0) {
+	    if (path[i] == ' ') {
+	      // do nothing
+	    } else if (path[i] == '"') {
+	      endchar = '"';
+	      state = 1;
+	    } else {
+	      state = 1;
+	      path[len] = path[i];
+	      ++len;
+	    }
+	  } else {
+	    if (path[i] == endchar) break;
+	    path[len] = path[i];
+	    ++len;
+	  }
+	  ++i;
+	}
+	path[len] = '\0';
+	
+	// check the resulting pathname
+	if (check_program_exe (path)) {
+	  retval = 1; // succeeded
+	} else {
+	  path[0] = '\0'; // failed (must have been deleted or something...)
+	}
+      }
+      RegCloseKey(hk2);
+    }
+    RegCloseKey(hk1);
+  }
+  
+  return retval;
+}
+
+
+// returns 1 if successful, 0 otherwise
+// note that appname should include .exe (e.g. netscape.exe)
+static int registry_get_app_paths (char *appname, char *path, int maxsize) {
+  HKEY hk1;
+  long size;
+  int retval = 0;
+  
+  path[0] = '\0';
+  
+  if (RegOpenKey(HKEY_LOCAL_MACHINE, 
+		 "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths", 
+		 &hk1) == ERROR_SUCCESS) {
+    size = maxsize;
+    if (RegQueryValue (hk1, appname, path, &size) == ERROR_SUCCESS &&
+	check_program_exe (path));
+    retval = 1;
+    
+    RegCloseKey(hk1);
+  }
+  
+  return retval;
+}
+
+static void check_installed_browsers (int netscapeneeded) {
+  netscape_exe[0] = '\0';
+  iexplore_exe[0] = '\0';
+  default_browser_exe[0] = '\0';
+  
+  // update the default browser information (if netscape isn't needed)
+  if (!netscapeneeded) {
+    get_default_browser_path (NULL, default_browser_exe, MAX_FILENAME_SIZE);
+    _strlwr (default_browser_exe);
+  }
+  
+  // look for netscape
+  
+  // first look for netscape in the registry
+  if (!registry_get_app_paths("netscape.exe", netscape_exe, MAX_FILENAME_SIZE)) {
+    // next look for "NetscapeMarkup"
+    if (get_default_browser_path ("NetscapeMarkup", netscape_exe, MAX_FILENAME_SIZE)) {
+      _strlwr (netscape_exe);
+      if (!strstr (netscape_exe, "netscape.exe")) {
+	netscape_exe[0] = '\0';
+	
+	// next look for \netscape\netscape.exe
+	
+	// get drive letter of the windows directory
+	GetWindowsDirectory(netscape_exe, MAX_FILENAME_SIZE);
+	netscape_exe[1] = '\0';
+	strcat (netscape_exe, ":\\netscape\\netscape.exe");
+	
+	if (!check_program_exe (netscape_exe)) {
+	  // lastly look for \netscape\program\netscape.exe
+	  netscape_exe[1] = '\0';
+	  strcat (netscape_exe, ":\\netscape\\program\\netscape.exe");
+	  
+	}
+      }
+    }
+  }
+  _strlwr (netscape_exe);
+  if ((strlen (netscape_exe) > 0) && !check_program_exe (netscape_exe)) {
+    netscape_exe[0] = '\0';  // couldn't find netscape
+  }
+  
+  // look for internet explorer (if netscape isn't needed)
+  
+  // first look for iexplore in the registry
+  if (!netscapeneeded && !registry_get_app_paths("iexplore.exe", 
+						 iexplore_exe, MAX_FILENAME_SIZE)) {
+    // next look for "htmlfile"
+    if (get_default_browser_path ("htmlfile", iexplore_exe, MAX_FILENAME_SIZE)) {
+      _strlwr (iexplore_exe);
+      if (!strstr (iexplore_exe, "iexplore.exe")) {
+	iexplore_exe[0] = '\0';
+	
+	// next look for \iexplore\iexplore.exe
+	
+	// get drive letter of the windows directory
+	GetWindowsDirectory(iexplore_exe, MAX_FILENAME_SIZE);
+	iexplore_exe[1] = '\0';
+	strcat (iexplore_exe, ":\\iexplore\\iexplore.exe");
+      }
+    }
+  }
+  _strlwr (iexplore_exe);
+  if ((strlen (iexplore_exe) > 0) && !check_program_exe (iexplore_exe)) {
+    iexplore_exe[0] = '\0';  // couldn't find internet explorer
+  }
+}
+
+void write_settings (const text_t url) {
+  
+  if (gsdl_conffile.empty()) {
+    find_location();
+    gsdl_conffile = filename_cat(data_location, "gsdlsite.cfg");
+  }
+
+  char *conffile_c = gsdl_conffile.getcstr();
+  ofstream fout (conffile_c);
+  delete []conffile_c;
+  if (fout) {
+    
+    outconvertclass text_t2ascii;
+
+    // top (gsdl) level stuff
+    fout << "[gsdl]\n";
+    
+    if (!url.empty()) {
+      // url entry should only be written to gsdlsite.cfg when the
+      // server is actually running, not when it's stopped (since we
+      // can't be sure what the url is at that stage). That is,
+      // write_settings() is called with the url argument set when the
+      // server first starts up, it's then called without url set as
+      // the server shuts down.
+      write_ini_line(fout, "url", url);      
+    }
+
+    write_ini_line(fout, "enterlib", gsdl_enterlib);
+    write_ini_line(fout, "gsdlhome", gsdl_gsdlhome);
+    write_ini_line(fout, "collecthome", gsdl_collecthome);
+    write_ini_line(fout, "gdbmhome", gsdl_dbhome);
+    
+    write_ini_line(fout, "logfilename", gsdl_log_name);
+    write_ini_line(fout, "keeplog", text_t(gsdl_keep_log));
+    write_ini_line(fout, "consolelog", text_t(gsdl_show_console));
+    
+    write_ini_line(fout, "portnumber", text_t(gsdl_port_num));
+    write_ini_line(fout, "autoenter", text_t(gsdl_auto_enter));
+    write_ini_line(fout, "browser", text_t(gsdl_browser));
+    write_ini_line(fout, "browserexe", gsdl_browser_exe);
+    write_ini_line(fout, "collections", gsdl_collections);
+    write_ini_line(fout, "start_browser", text_t(gsdl_start_browser));
+    write_ini_line(fout, "address_resolution_method", text_t(gsdl_address_resolution_method));
+
+    // collection levels
+    colinfo_tmap::iterator here = gsdl_collectinfo.begin();
+    colinfo_tmap::iterator end = gsdl_collectinfo.end();
+    while (here != end) {
+      fout << text_t2ascii << "[" << (*here).first << "]\n";
+      if (!(*here).second.gsdl_gsdlhome.empty()) 
+	write_ini_line(fout, "gsdlhome", (*here).second.gsdl_gsdlhome);
+      if (!(*here).second.gsdl_collecthome.empty()) 
+	write_ini_line(fout, "collecthome", (*here).second.gsdl_collecthome);
+      if (!(*here).second.gsdl_dbhome.empty()) 
+	write_ini_line(fout, "gdbmhome", (*here).second.gsdl_dbhome);
+      
+      ++here;
+    }
+    fout.close();
+  }
+}
+
+
+// browser_compare assumes that check_exe is in lowercase
+static int browser_compare (char *browser_exe_path, char *check_exe) {
+  char tmp_exe[MAX_FILENAME_SIZE];
+  strcpy (tmp_exe, browser_exe_path);
+  _strlwr (tmp_exe);
+  return (strstr (tmp_exe, check_exe) != NULL);
+}
+
+// This function assumes that check_installed_browsers
+// has been recently called
+// It also assumes that browser_exe is large
+// enough to receive any path names to any browser
+static void check_browser_settings (int &browser, char *browser_exe, 
+				    int netscapeneeded) {
+  // sort out which browser to use
+  if ((browser == GS_NETSCAPE) && (netscape_exe[0] == '\0'))
+    browser = GS_IEXPLORE;
+  if ((browser == GS_IEXPLORE) && (netscapeneeded || (iexplore_exe[0] == '\0'))) {
+    if (netscape_exe[0] != '\0') browser = GS_NETSCAPE;
+    else browser = GS_OTHER;
+  }
+  if ((browser == GS_OTHER) && netscapeneeded && 
+      !browser_compare (browser_exe, "netscape.exe") && (netscape_exe[0] != '\0')) {
+    // this other browser isn't netscape and netscape is available
+    browser = GS_NETSCAPE;
+  }
+  
+  
+  // get the browser's executable
+  if (browser == GS_DEFAULT) {
+    strcpy (browser_exe, default_browser_exe);
+  } else if (browser == GS_NETSCAPE) {
+    strcpy (browser_exe, netscape_exe);
+  } else if (browser == GS_IEXPLORE) {
+    strcpy (browser_exe, iexplore_exe);
+  } else {
+    browser = GS_OTHER;
+    
+    // if the browser should be netscape then check to
+    // make sure it is
+    if (netscapeneeded && !browser_compare (browser_exe, "netscape.exe")) {
+      // not netscape, set to no browser
+      browser_exe[0] = '\0';
+    }
+  }
+}
+
+
+static void revert_defaults (int netscapeneeded) {
+  find_location();
+  
+  // library settings
+  gsdl_enterlib = "/gsdl";
+  gsdl_gsdlhome = data_location;
+  gsdl_collecthome = filename_cat(data_location,"collect");
+  gsdl_dbhome = data_location;
+  
+  // debug settings
+  gsdl_keep_log = 0;
+  strcpy (gsdl_log_name, "c:\\gsdl.log");
+  gsdl_show_console = 0;
+  
+  // general settings
+  gsdl_port_num = 80;
+  gsdl_auto_enter = 0;
+  gsdl_start_browser = 1;
+
+  check_installed_browsers (netscapeneeded);
+  gsdl_browser = GS_DEFAULT;
+  strcpy (gsdl_browser_exe, default_browser_exe);
+  check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
+}
+
+void read_settings (int netscapeneeded) {
+  
+  if (gsdl_conffile.empty()) {
+    find_location();
+    gsdl_conffile = filename_cat(data_location, "gsdlsite.cfg");
+  }
+  
+  // set up defaults
+  revert_defaults (netscapeneeded);
+  
+  text_t key, value, section;
+  char *cstr_value;
+  char *conffile_c = gsdl_conffile.getcstr();
+#if defined (GSDL_USE_IOS_H)
+  ifstream conf (conffile_c, ios::nocreate);
+#else
+  ifstream conf (conffile_c);
+#endif
+  delete []conffile_c;
+  if (conf) {
+    while (read_ini_line(conf, key, value) >= 0) {
+      if (key.empty()) continue;
+      if (value.empty()) {
+	// should be a section title
+	section = key;
+	// remove square brackets
+	section.erase (section.begin());
+	section.erase (section.end()-1);
+
+      } else {
+
+	cstr_value = value.getcstr ();
+      
+	if (section == "gsdl") {
+
+	  if (key == "enterlib") {
+	    gsdl_enterlib = value;
+	  
+	    // 'logfilename' should occur in the configuration file
+	    // before 'keeplog'
+	  } else if (key == "logfilename") {
+	    strcpy (gsdl_log_name, cstr_value);
+	  
+	  } else if (key == "keeplog") {
+	    gsdl_keep_log = value.getint();
+	    if (gsdl_keep_log) open_log_file();
+	
+	  } else if (key == "consolelog") {
+	    if (value.getint()) activate_console();
+	    else deactivate_console();
+	
+	  } else if (key == "portnumber") {
+	    gsdl_port_num = value.getint();
+	    
+	  } else if (key == "autoenter") {
+	    gsdl_auto_enter = value.getint();
+	    
+	  } else if (key == "start_browser") {
+	    gsdl_start_browser = value.getint();
+	
+	  } else if (key == "browser") {
+	    gsdl_browser = value.getint();
+	
+	  } else if (key == "browserexe") {
+	    strcpy (gsdl_browser_exe, cstr_value);
+
+	  } else if (key == "address_resolution_method") {
+	    gsdl_address_resolution_method = value.getint();
+
+	  } else if (key == "collections") {
+	    gsdl_collections = value;
+	  } 
+	  // gsdlhome must occur in file before dbhome	    
+	  else if (key == "gsdlhome") {
+	    gsdl_gsdlhome = value;
+	    gsdl_collecthome = filename_cat(value,"collect");
+	    gsdl_dbhome = value;	  
+	  } 
+	  else if (key == "collecthome") {
+	    gsdl_collecthome = value;
+	  } 
+	  else if (key == "gdbmhome") {
+	    gsdl_dbhome = value;
+	  }
+	} else {
+	  
+	  // gsdlhome must occur in file before dbhome
+	  if (key == "gsdlhome") {
+	    gsdl_collectinfo[section].gsdl_gsdlhome = value;
+	    gsdl_collectinfo[section].gsdl_collecthome = filename_cat(value,"collecct");
+	    gsdl_collectinfo[section].gsdl_dbhome = value;
+	  } 
+	  else if (key == "collecthome") {
+	    gsdl_collectinfo[section].gsdl_collecthome = value;
+	  }
+	  else if (key == "gdbmhome") {
+	    gsdl_collectinfo[section].gsdl_dbhome = value;
+	  }
+	}
+	delete []cstr_value;
+      }
+    }
+    conf.close();
+  }
+  
+  // check the homes to make sure they don't contain
+  // extra slashes at the end
+  remove_end_slashes (gsdl_gsdlhome);
+  remove_end_slashes (gsdl_collecthome);
+  remove_end_slashes (gsdl_dbhome);
+  colinfo_tmap::iterator here = gsdl_collectinfo.begin();
+  colinfo_tmap::iterator end = gsdl_collectinfo.end();
+  while (here != end) {
+    remove_end_slashes ((*here).second.gsdl_gsdlhome);
+    remove_end_slashes ((*here).second.gsdl_collecthome);
+    remove_end_slashes ((*here).second.gsdl_dbhome);
+    ++here;
+  }
+
+  // check the browser settings
+  check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
+}
+
+void gsdl_check_browser_settings (int netscapeneeded) {
+  check_installed_browsers (netscapeneeded);
+  check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
+}
+
+
+static void dialog_update_enables (HWND hwndDlg) {
+  int res;
+  
+  // if they want to use another browser, they should be able
+  // edit its filename
+  res = SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER, BM_GETCHECK,0,0);
+  SendDlgItemMessage(hwndDlg, ID_OTHER_NAME, WM_ENABLE, (res == 1), 0);
+}
+
+
+static int read_dialog_browser_field (HWND hwndDlg) {
+  if (SendDlgItemMessage(hwndDlg, ID_RADIO_DEFAULT,
+			 BM_GETCHECK, 0, 0) == 1) return GS_DEFAULT;
+  if (SendDlgItemMessage(hwndDlg, ID_RADIO_NETSCAPE,
+			 BM_GETCHECK, 0, 0) == 1) return GS_NETSCAPE;
+  if (SendDlgItemMessage(hwndDlg, ID_RADIO_IE,
+			 BM_GETCHECK, 0, 0) == 1) return GS_IEXPLORE;
+  if (SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER,
+			 BM_GETCHECK, 0, 0) == 1) return GS_OTHER;
+  return GS_NETSCAPE;
+}
+
+
+static void set_dialog_browser_field (HWND hwndDlg, int browser, char *othername) {
+  // if we are trying to set the browser to default, netscape or
+  // internet explorer and we can't find them, set the browser
+  // to 'other'
+  if ((browser == GS_DEFAULT) && (default_browser_exe[0] == '\0'))
+    browser = GS_NETSCAPE;
+  if ((browser == GS_NETSCAPE) && (netscape_exe[0] == '\0'))
+    browser = GS_IEXPLORE;
+  if ((browser == GS_IEXPLORE) && (iexplore_exe[0] == '\0')) {
+    if (netscape_exe[0] != '\0') browser = GS_NETSCAPE;
+    else browser = GS_OTHER;
+  }
+  
+  // update the radio buttons
+  SendDlgItemMessage(hwndDlg, ID_RADIO_DEFAULT, BM_SETCHECK,
+		     (browser == GS_DEFAULT) ? BST_CHECKED : BST_UNCHECKED, 0);
+  SendDlgItemMessage(hwndDlg, ID_RADIO_NETSCAPE, BM_SETCHECK,
+		     (browser == GS_NETSCAPE) ? BST_CHECKED : BST_UNCHECKED, 0);
+  SendDlgItemMessage(hwndDlg, ID_RADIO_IE, BM_SETCHECK,
+		     (browser == GS_IEXPLORE) ? BST_CHECKED : BST_UNCHECKED, 0);
+  SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER, BM_SETCHECK,
+		     (browser == GS_OTHER) ? BST_CHECKED : BST_UNCHECKED, 0);
+  
+  // update the other name field
+  if (browser == GS_DEFAULT) {
+    SetDlgItemText(hwndDlg, ID_OTHER_NAME, default_browser_exe);
+  } else if (browser == GS_NETSCAPE) {
+    SetDlgItemText(hwndDlg, ID_OTHER_NAME, netscape_exe);
+  } else if (browser == GS_IEXPLORE) {
+    SetDlgItemText(hwndDlg, ID_OTHER_NAME, iexplore_exe);
+  } else if (othername != NULL) {
+    SetDlgItemText(hwndDlg, ID_OTHER_NAME, othername);
+  }
+}
+
+
+static void read_browser_exe_field (HWND hwndDlg, char *filename, int maxsize) {
+  filename[0] = '\0';
+  GetDlgItemText(hwndDlg, ID_OTHER_NAME, filename, maxsize);
+}
+
+static int read_address_resolution_field (HWND hwndDlg) {
+  if (SendDlgItemMessage(hwndDlg, ID_ARM_NAME,
+			 BM_GETCHECK, 0, 0) == 1) return ARM_NAME;
+  if (SendDlgItemMessage(hwndDlg, ID_ARM_IP,
+			 BM_GETCHECK, 0, 0) == 1) return ARM_IP;
+  if (SendDlgItemMessage(hwndDlg, ID_ARM_LOCALHOST,
+			 BM_GETCHECK, 0, 0) == 1) return ARM_LOCALHOST;
+  if (SendDlgItemMessage(hwndDlg, ID_ARM_127_0_0_1,
+			 BM_GETCHECK, 0, 0) == 1) return ARM_127_0_0_1;
+  return ARM_NAME;
+}
+
+static void set_address_resolution_field (HWND hwndDlg, 
+					  int address_res_method) {
+  // update the radio buttons
+  SendDlgItemMessage(hwndDlg, ID_ARM_NAME, BM_SETCHECK,
+		     (address_res_method == ARM_NAME) ? BST_CHECKED : BST_UNCHECKED, 0);
+  SendDlgItemMessage(hwndDlg, ID_ARM_IP, BM_SETCHECK,
+		     (address_res_method == ARM_IP) ? BST_CHECKED : BST_UNCHECKED, 0);
+  SendDlgItemMessage(hwndDlg, ID_ARM_LOCALHOST, BM_SETCHECK,
+		     (address_res_method == ARM_LOCALHOST) ? BST_CHECKED : BST_UNCHECKED, 0);
+  SendDlgItemMessage(hwndDlg, ID_ARM_127_0_0_1, BM_SETCHECK,
+		     (address_res_method == ARM_127_0_0_1) ? BST_CHECKED : BST_UNCHECKED, 0);
+
+}
+
+static void read_dialog_fields (HWND hwndDlg) {
+  int res;  BOOL bres;
+  
+  // port number
+  gsdl_port_num = GetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, &bres, 0);
+  if (!bres) gsdl_port_num = 80;
+  
+  // whether to enter the library automatically on startup
+  res = SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_GETCHECK, 0, 0);
+  gsdl_auto_enter = (res == 1);
+  
+  // which browser to use
+  gsdl_browser = read_dialog_browser_field (hwndDlg);
+  
+  // find out where the browser exe lives
+  read_browser_exe_field (hwndDlg, gsdl_browser_exe, MAX_FILENAME_SIZE);
+
+  // which address resolution method
+  gsdl_address_resolution_method = read_address_resolution_field(hwndDlg);
+}
+
+
+
+
+static BOOL CALLBACK dialog_proc(HWND hwndDlg, UINT uMsg, 
+				 WPARAM wParam,LPARAM  lParam) {
+  int wNotifyCode = HIWORD(wParam);
+  int wID = LOWORD(wParam);
+  char *filefilter = "Program Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0\0";
+  OPENFILENAME fname;
+  char filename[MAX_FILENAME_SIZE];
+  
+  switch (uMsg) {
+  case WM_INITDIALOG:
+    // set current values
+    SetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, gsdl_port_num, FALSE);
+    SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_SETCHECK,
+		       gsdl_auto_enter ? 1 : 0, 0);
+    set_dialog_browser_field (hwndDlg, gsdl_browser, gsdl_browser_exe);
+    set_address_resolution_field(hwndDlg, gsdl_address_resolution_method);
+    dialog_update_enables(hwndDlg);
+    
+    // make sure that the default browser, netscape and internet explorer
+    // radio buttons are only enabled if they could be found
+    if (default_browser_exe[0] == '\0')
+      EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_DEFAULT), FALSE);
+    if (netscape_exe[0] == '\0')
+      EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_NETSCAPE), FALSE);
+    if (iexplore_exe[0] == '\0')
+      EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_IE), FALSE);
+    
+    return 1;
+    
+  case WM_COMMAND:
+    if (wNotifyCode == BN_CLICKED) {
+      switch (wID) {
+      case ID_CANCEL_BUTTON:
+	EndDialog(hwndDlg, 0);
+	return 1;
+	
+      case ID_OK_BUTTON:
+	// check to make sure we can find the browser
+	filename[0] = '\0';
+	read_browser_exe_field (hwndDlg, filename, MAX_FILENAME_SIZE);
+	if (check_program_exe (filename)) { 
+	  // the file exists
+	  // if netscape is needed, make sure the browser is netscape
+	  _strlwr(filename);
+	  if (!gsdl_netscapeneeded || strstr (filename, "netscape.exe") != NULL) {
+	    // everything is ok
+	    read_dialog_fields(hwndDlg);
+	    EndDialog(hwndDlg, 1);
+	    
+	  } else {
+	    // message: must use netscape with this version
+	    MessageBox(hwndDlg,
+		       "You are using this software on a machine which\n"
+		       "currently does not have a working TCP/IP network layer.\n"
+		       "To allow the Greenstone Digital Library software to use\n"
+		       "its own TCP/IP network layer you must use a Netscape\n"
+		       "web browser.",
+		       "Greenstone Digital Library Software",
+		       MB_OK|MB_APPLMODAL);
+	  }
+	} else {
+	  // message: the file did not exist
+	  MessageBox(hwndDlg,
+		     "Could not find the selected browser. You must have a\n"
+		     "web browser installed to use the Greenstone Digital\n"
+		     "Library software.",
+		     "Greenstone Digital Library Software",
+		     MB_OK|MB_APPLMODAL);
+	}
+	return 1;
+
+      case ID_RADIO_DEFAULT:
+	set_dialog_browser_field (hwndDlg, GS_DEFAULT, NULL);
+	dialog_update_enables(hwndDlg);
+	return 1;
+	
+      case ID_RADIO_NETSCAPE:
+	set_dialog_browser_field (hwndDlg, GS_NETSCAPE, NULL);
+	dialog_update_enables(hwndDlg);
+	return 1;
+	
+      case ID_RADIO_IE:
+	set_dialog_browser_field (hwndDlg, GS_IEXPLORE, NULL);
+	dialog_update_enables(hwndDlg);
+	return 1;
+	
+      case ID_RADIO_OTHER:
+	set_dialog_browser_field (hwndDlg, GS_OTHER, NULL);
+	dialog_update_enables(hwndDlg);
+	return 1;
+	
+      case ID_BROWSE_BUTTON:
+	filename[0] = '\0';
+	memset(&fname, 0, sizeof(OPENFILENAME));
+	fname.lStructSize = sizeof(OPENFILENAME);
+	fname.hwndOwner = hwndDlg;
+	fname.hInstance = NULL;
+	fname.lpstrFilter = filefilter;
+	fname.lpstrCustomFilter = NULL;
+	fname.nMaxCustFilter = 0;
+	fname.nFilterIndex = 1;
+	fname.lpstrFile = filename;
+	fname.nMaxFile = MAX_FILENAME_SIZE-1;
+	fname.lpstrFileTitle = NULL;
+	fname.nMaxFileTitle = 0;
+	fname.lpstrInitialDir = NULL;
+	fname.lpstrTitle = "Choose Web Browser";
+	fname.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
+	
+	if(GetOpenFileName(&fname)) {
+	  set_dialog_browser_field (hwndDlg, GS_OTHER, filename);
+	  dialog_update_enables(hwndDlg);
+	}
+	return 1;
+
+      case ID_ARM_NAME:
+	set_address_resolution_field (hwndDlg, ARM_NAME);
+	dialog_update_enables(hwndDlg);
+	return 1;
+     case ID_ARM_IP:
+	set_address_resolution_field (hwndDlg, ARM_IP);
+	dialog_update_enables(hwndDlg);
+	return 1;
+    case ID_ARM_LOCALHOST:
+	set_address_resolution_field (hwndDlg, ARM_LOCALHOST);
+	dialog_update_enables(hwndDlg);
+	return 1;
+     case ID_ARM_127_0_0_1:
+	set_address_resolution_field (hwndDlg, ARM_127_0_0_1);
+	dialog_update_enables(hwndDlg);
+	return 1;
+
+      }
+    }
+    return 0;
+    
+  case WM_CLOSE:
+  case WM_DESTROY:
+    EndDialog(hwndDlg, 0);
+    return 1;
+  }
+  
+  return 0;
+}
+
+static void dialog_debug_update_enables (HWND hwndDlg) {
+  int res;
+  
+  // if they want a log of program use allow them to
+  // edit its filename
+  res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
+  SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, WM_ENABLE, (res == 1), 0);
+}
+
+
+static void read_dialog_debug_fields (HWND hwndDlg) {
+  int res;
+  
+  // whether to log program use
+  res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
+  gsdl_keep_log = (res == 1);
+  
+  // log filename
+  res = SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, EM_GETMODIFY,0,0);
+  if (res != 0) {
+    res = GetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name, MAX_FILENAME_SIZE);
+  }
+  
+  // whether to display log information on console
+  res = SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_GETCHECK,0,0);
+  gsdl_show_console = (res == 1);
+}
+
+
+static BOOL CALLBACK dialog_debug_proc(HWND hwndDlg, UINT uMsg, 
+				       WPARAM wParam,LPARAM  lParam) {
+  int wNotifyCode = HIWORD(wParam);
+  int wID = LOWORD(wParam);
+  
+  switch (uMsg) {
+  case WM_INITDIALOG:
+    // set current values
+    SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_SETCHECK,
+		       gsdl_keep_log ? 1 : 0, 0);
+    SetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name);
+    SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_SETCHECK,
+		       gsdl_show_console ? 1 : 0, 0);
+    dialog_debug_update_enables(hwndDlg);
+    return 1;
+    
+  case WM_COMMAND:
+    if (wNotifyCode == BN_CLICKED) {
+      switch (wID) {
+      case ID_CANCEL_BUTTON:
+	EndDialog(hwndDlg, 0);
+	return 1;
+	
+      case ID_OK_BUTTON:
+	read_dialog_debug_fields(hwndDlg);
+	EndDialog(hwndDlg, 1);
+	return 1;
+	
+      case LOG_CHECK:
+	dialog_debug_update_enables(hwndDlg);
+	return 1;
+      }
+    }
+    return 0;
+    
+  case WM_CLOSE:
+  case WM_DESTROY:
+    EndDialog(hwndDlg, 0);
+    return 1;
+  }
+  
+  return 0;
+}
+
+
+void Settings_Dialog(HWND window, int netscapeneeded)
+{
+  int old_gsdl_show_console = gsdl_show_console;
+  int old_gsdl_port_num = gsdl_port_num;
+  
+  int res = 0;
+  
+  gsdl_netscapeneeded = netscapeneeded;
+  
+  if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && 
+      (GetAsyncKeyState(VkKeyScan('d')) & 0x8000)) {
+    // control-D was pressed, display debug settings
+    // dialog box
+    res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG_DEBUG),
+		     window, (DLGPROC)dialog_debug_proc);
+    
+    if (res == 1) {
+      // only update if exited via the OK button
+      if (gsdl_keep_log) open_log_file(); 
+      else close_log_file();
+      
+      // turn the console on/off if we need to
+      if (gsdl_show_console != old_gsdl_show_console) {
+	if (gsdl_show_console) activate_console ();
+	else deactivate_console ();
+      }
+    }
+    
+  } else {
+    // display normal settings dialog box
+    
+    // make sure everything is up-to-date
+    gsdl_check_browser_settings (netscapeneeded);
+    
+    res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG2),
+		     window, (DLGPROC)dialog_proc);
+
+    if (res == 1) {
+      // only update if exited via the OK button
+      if (gsdl_port_num != old_gsdl_port_num) {
+	EndHTTPServer();
+	StartHTTPServer(window);
+      }
+    }
+  }
+  
+  // save the settings if we exited via the ok button
+  if (res == 1) {
+    write_settings(gsdl_url);
+    // reset httpprefix in case port number was changed
+    //    configure_httpprefix ();
+  }
+}
Index: /gsdl/trunk/runtime-src/src/w32server/settings.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/settings.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/settings.h	(revision 16571)
@@ -0,0 +1,79 @@
+/**********************************************************************
+ *
+ * settings.h
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+#define GS_NETSCAPE 0
+#define GS_IEXPLORE 1
+#define GS_OTHER    2
+#define GS_DEFAULT  3
+
+// address resolution methods
+#define ARM_NAME 0
+#define ARM_IP 1
+#define ARM_LOCALHOST 2
+#define ARM_127_0_0_1 3
+
+#include "text_t.h"
+#include "cfgread.h"
+#include "receptionist.h"
+#include "locate.h"
+
+// library settings
+extern text_t gsdl_enterlib;
+extern text_t gsdl_gsdlhome;
+extern text_t gsdl_collecthome;
+extern text_t gsdl_dbhome;
+extern text_t gsdl_collections;
+extern colinfo_tmap gsdl_collectinfo;
+
+extern char gsdl_staticpages[MAX_FILENAME_SIZE];
+
+// debug settings
+extern char gsdl_log_name[MAX_FILENAME_SIZE];
+extern int gsdl_keep_log;
+extern int gsdl_show_console;
+
+// general settings
+extern int gsdl_port_num;
+extern int gsdl_auto_enter;
+extern int gsdl_browser;
+extern char gsdl_browser_exe[MAX_FILENAME_SIZE];
+extern text_t gsdl_url;
+extern text_t gsdl_conffile;
+extern int gsdl_start_browser;
+extern int gsdl_address_resolution_method;
+
+void Settings_Dialog(HWND window, int netscapeneeded);
+
+void read_settings (int netscapeneeded);
+void write_settings (const text_t url);
+
+void gsdl_check_browser_settings (int netscapeneeded);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/w32server/startbrowser.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/startbrowser.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/startbrowser.cpp	(revision 16571)
@@ -0,0 +1,287 @@
+/**********************************************************************
+ *
+ * startbrowser.cpp
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "startbrowser.h"
+#include <windows.h>
+#include <DDE.H>
+#include <DDEML.H>
+#include <string.h>
+#include <direct.h>
+#include "locate.h"
+
+#define SB_COMLEN 1024
+#define SB_DDETIMEOUT 60000UL  // One minute in milliseconds
+
+int numbrowserstarted = 0;
+
+static int inited = 0;
+
+static DWORD idInst = 0;
+static HINSTANCE hinst = NULL;
+static HSZ hszNetscapeName = NULL;
+static HSZ hszIExploreName = NULL;
+static HSZ hszOpenURLTopic = NULL;
+static HSZ hszActivateTopic = NULL;
+
+// budget callback
+HDDEDATA CALLBACK DdeCallback(UINT uType,     /* transaction type                 */
+			      UINT uFmt,      /* clipboard data format            */
+			      HCONV hconv,    /* handle of conversation           */
+			      HSZ hsz1,       /* handle of string                 */
+			      HSZ hsz2,       /* handle of string                 */
+			      HDDEDATA hdata, /* handle of global memory object   */
+			      DWORD dwData1,  /* transaction-specific data        */
+			      DWORD dwData2)  /* transaction-specific data        */ 
+{
+  return (HDDEDATA) NULL; 
+}
+
+// returns 0 on failure
+static int talkdde (HSZ hszServName, HSZ hszSysTopic, char *requeststr) {
+  HSZ hszRequest;
+  HCONV hConv;
+  HDDEDATA result;
+  
+  // try to connect to the newly started browser
+  hConv = DdeConnect (idInst, hszServName, hszSysTopic, (PCONVCONTEXT) NULL);
+  if (hConv == NULL) return 0;
+  
+  hszRequest = DdeCreateStringHandle (idInst, requeststr, CP_WINANSI);
+  result = DdeClientTransaction (
+				 NULL,          // pointer to data to pass to server
+				 0,             // length of data
+				 hConv,         // handle to conversation
+				 hszRequest,    // handle to item name string
+				 CF_TEXT,       // clipboard data format
+				 XTYP_REQUEST,  // transaction type
+				 SB_DDETIMEOUT, // time-out duration
+				 NULL           // pointer to transaction result
+				 );
+
+  if (result != NULL) DdeFreeDataHandle (result);
+  DdeDisconnect(hConv);
+  DdeFreeStringHandle (idInst, hszRequest);
+
+  return 1;
+}
+
+// returns 0 on failure
+static int openurl(HSZ hszServName, HSZ hszActivateTopic, HSZ hszOpenURLTopic, char *url) {
+  char requeststr[65600];
+  
+  // bring the browser to the front, don't worry if this fails
+  talkdde (hszServName, hszActivateTopic, "0xFFFFFFFF,0x0");
+  
+  // tell the browser to open a url
+  strcpy (requeststr, "\"");
+  strcat (requeststr, url);
+  strcat (requeststr, "\",,0xFFFFFFFF,0x0,,,");
+  
+  return talkdde (hszServName, hszOpenURLTopic, requeststr);
+}
+
+// returns 0 on failure
+static int tryconnect(HSZ hszServName, HSZ hszSysTopic) {
+  // try to connect to a running browser
+  HCONV hConv = DdeConnect (idInst, hszServName, hszSysTopic, (PCONVCONTEXT) NULL);
+  if (hConv == NULL) return 0;
+  DdeDisconnect(hConv);
+  return 1;
+}
+
+static void freestrings () {
+  // free up any currently allocated strings
+  if (hszNetscapeName != NULL) DdeFreeStringHandle (idInst, hszNetscapeName);
+  hszNetscapeName = NULL;
+  if (hszIExploreName != NULL) DdeFreeStringHandle (idInst, hszIExploreName);
+  hszIExploreName = NULL;
+  if (hszOpenURLTopic != NULL) DdeFreeStringHandle (idInst, hszOpenURLTopic);
+  hszOpenURLTopic = NULL;
+  if (hszActivateTopic != NULL) DdeFreeStringHandle (idInst, hszActivateTopic);
+  hszActivateTopic = NULL;
+}
+
+static void getbrowserinfo() {
+  freestrings();
+  
+  hszNetscapeName = DdeCreateStringHandle(idInst,"NETSCAPE",CP_WINANSI);
+  hszIExploreName = DdeCreateStringHandle(idInst,"IExplore",CP_WINANSI);
+  
+  hszOpenURLTopic = DdeCreateStringHandle(idInst,"WWW_OpenURL",CP_WINANSI);
+  hszActivateTopic = DdeCreateStringHandle(idInst,"WWW_Activate",CP_WINANSI);
+}
+
+// returns SB_NOERROR on success, 
+// SB_ALREADYINIT or SB_DDE_FAILINIT on failure
+int initstartbrowser () {
+  if (inited) return SB_ALREADYINIT;
+  
+  // from nstest if(DdeInitialize(&CDDEObject::m_dwidInst, NstestDdeCallBack, APPCLASS_STANDARD, 0ul))
+  if (DdeInitialize (&idInst, (PFNCALLBACK) DdeCallback, 
+		     APPCLASS_STANDARD, 0)
+      != DMLERR_NO_ERROR) {
+    freestrings();
+    inited = 0;
+    return SB_DDE_FAILINIT;
+  }
+
+  getbrowserinfo();
+  
+  inited = 1;
+  return SB_NOERROR;
+}
+
+
+// returns SB_NOERROR on success,
+// SB_DDE_FAILDEINIT of failure
+int deinitstartbrowser () {
+  // make sure this has been inited
+  // not being inited here, however, is not
+  // important
+  if (!inited) return SB_NOERROR;
+  inited = 0;
+  
+  freestrings();
+  
+  if (DdeUninitialize(idInst)) return SB_NOERROR;
+  
+  return SB_DDE_FAILDEINIT;
+}
+
+
+// startbrowser will try to start a browser (or connect to a running browser).
+//
+// Returns SB_NOERROR on success,
+// SB_NOTINITED, SB_FAIL_BADFORMAT, SB_FAIL_NOTFOUND, SB_FAIL_NORESOURCES, or
+// SB_FAILCONNECTBROWSER on failure
+int startbrowser (char *url, char *browser_exe, char *startdir) {
+  char newcommand[SB_COMLEN];
+  int usingnetscape = 0;
+  int usingiexplore = 0;
+  
+  if (!inited) return SB_NOTINITED; // has to be inited first
+  
+  // find out which browser we are dealing with
+  strcpy (newcommand, browser_exe);
+  _strlwr (newcommand);
+  if (strstr (newcommand, "netscape.exe") != NULL) { 
+    // netscape
+    usingnetscape = 1;
+  } else if (strstr (newcommand, "iexplore.exe") != NULL) { 
+    // internet explorer
+    usingiexplore = 1;
+  }
+  
+  // only try to communicate with a running browser if a startdir
+  // is not specified
+  if (startdir == NULL) {
+    if (usingnetscape && hszNetscapeName != NULL && 
+	openurl(hszNetscapeName, hszActivateTopic, hszOpenURLTopic, url)) {
+      return SB_NOERROR;
+    }
+    if (usingiexplore && hszIExploreName != NULL && 
+	openurl(hszIExploreName, hszActivateTopic, hszOpenURLTopic, url)) {
+      return SB_NOERROR;
+    }
+  }
+  
+  strcpy (newcommand, browser_exe);
+  
+  // don't put the url on the command line for internet explorer
+  if (usingiexplore) {
+    strcat (newcommand, " -nohome");
+    
+  } else {
+    // will have to put the url on the command line
+    strcat (newcommand, " \"");
+    strcat (newcommand, url);
+    strcat (newcommand, "\"");
+  }
+  
+  // change the working directory (if needed)
+  char cwd[1024];
+  cwd[0] = '\0';
+  if (startdir != NULL) {
+    _getcwd(cwd, 1024);
+    _chdir(startdir);
+  }
+  
+  // attempt to start the browser
+  int res = WinExec(newcommand, SW_SHOW);
+  
+  // change the working directory back (if needed)
+  if (startdir != NULL) _chdir(cwd);
+  
+  if (res == ERROR_BAD_FORMAT) return SB_FAIL_BADFORMAT;
+  if ((res == ERROR_FILE_NOT_FOUND) || (res == ERROR_PATH_NOT_FOUND)) 
+    return SB_FAIL_NOTFOUND;
+  if (res <= 31) return SB_FAIL_NORESOURCES;
+  
+  ++numbrowserstarted;
+  
+  // if we aren't using iexplore then the url was
+  // put on the command line and there is nothing left to do
+  if (!usingiexplore) return SB_NOERROR;
+  
+  // connect to the browser and get it to open a page,
+  // time out after 1 minute
+  DWORD lastcheck = GetTickCount ();
+  while (DiffTickCounts (lastcheck, GetTickCount()) <= 60000) {
+    if (usingnetscape && hszNetscapeName != NULL && 
+	openurl(hszNetscapeName, hszActivateTopic, hszOpenURLTopic, url)) {
+      return SB_NOERROR;
+    }
+    if (usingiexplore && hszIExploreName != NULL && 
+	openurl(hszIExploreName, hszActivateTopic, hszOpenURLTopic, url)) {
+      return SB_NOERROR;
+    }
+  }
+  
+  // timed out trying to connect to the browser
+  return SB_FAILCONNECTBROWSER;
+}
+
+// returns SB_NOERROR on success,
+// SB_NOTINITED, SB_FAILCONNECTBROWSER on failure
+int browserrunning (char *browser_exe) {
+  char newcommand[SB_COMLEN];
+  if (!inited) return SB_NOTINITED; // has to be inited first
+  
+  strcpy (newcommand, browser_exe);
+  _strlwr (newcommand);
+  
+  if ((strstr (newcommand, "netscape.exe") != NULL) && (hszNetscapeName != NULL) && 
+      tryconnect(hszNetscapeName, hszOpenURLTopic)) {
+    // succeeded connecting to netscape
+    return SB_NOERROR;
+    
+  } else if ((strstr (newcommand, "iexplore.exe") != NULL) && (hszIExploreName != NULL) && 
+	     tryconnect(hszIExploreName, hszOpenURLTopic)) {
+    // succeeded connecting to internet explorer
+    return SB_NOERROR;
+  }
+  
+  return SB_FAILCONNECTBROWSER;
+}
Index: /gsdl/trunk/runtime-src/src/w32server/startbrowser.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/startbrowser.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/startbrowser.h	(revision 16571)
@@ -0,0 +1,58 @@
+/**********************************************************************
+ *
+ * startbrowser.h
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#define SB_NOERROR            0
+#define SB_ALREADYINIT        1
+#define SB_DDE_FAILINIT       2
+#define SB_DDE_FAILDEINIT     3
+#define SB_NOTINITED          4
+#define SB_FAIL_BADFORMAT     5
+#define SB_FAIL_NOTFOUND      6
+#define SB_FAIL_NORESOURCES   7
+#define SB_FAILCONNECTBROWSER 9
+
+
+extern int numbrowserstarted;
+
+// initstartbrowser should be called before startbrowser
+//
+// returns SB_NOERROR on success, 
+// SB_ALREADYINIT or SB_DDE_FAILINIT on failure
+int initstartbrowser ();
+
+// returns SB_NOERROR on success,
+// SB_DDE_FAILDEINIT of failure
+int deinitstartbrowser ();
+
+// startbrowser will try to start a browser (or connect to a running browser).
+//
+// Returns SB_NOERROR on success,
+// SB_NOTINITED, SB_FAIL_BADFORMAT, SB_FAIL_NOTFOUND, or SB_FAIL_NORESOURCES, 
+//  on failure
+int startbrowser (char *url, char *browser_exe, char *startdir);
+
+// returns SB_NOERROR on success,
+// SB_NOTINITED, SB_FAILCONNECTBROWSER on failure
+int browserrunning (char *browser_exe);
Index: /gsdl/trunk/runtime-src/src/w32server/win32.mak
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/win32.mak	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/win32.mak	(revision 16571)
@@ -0,0 +1,174 @@
+###########################################################################
+#
+# win32 makefile -- src/w32server
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ..\..
+INDEXERS_DIR = $(GSDL_DIR)\indexers
+PACKAGES_DIR = $(GSDL_DIR)\packages
+COLSERVR_DIR = $(GSDL_DIR)\src\colservr
+PROTOCOL_DIR = $(GSDL_DIR)\src\protocol
+RECPT_DIR = $(GSDL_DIR)\src\recpt
+
+
+GSDL_VC4 = 0
+ENABLE_ACCENTFOLD = 1
+USE_SQLITE = 0
+
+
+!IF $(GSDL_VC4)
+CPPFLAGS = -GX
+!ELSE
+CPPFLAGS = -EHsc
+!ENDIF
+
+!IF $(ENABLE_ACCENTFOLD)
+ACCENTFOLD_LIBS = "$(INDEXERS_DIR)\packages\unac\libunac.lib" "$(INDEXERS_DIR)\packages\unac\iconv.lib"
+!ELSE
+ACCENTFOLD_LIBS = 
+!ENDIF
+
+!IF $(USE_SQLITE)
+SQLITE_LIBS = "$(PACKAGES_DIR)\sqlite\lib\sqlite3.lib"
+!ELSE
+SQLITE_LIBS = 
+!ENDIF
+
+
+AR = lib
+CC = cl
+DEFS = -D__WIN32__ -DHAVE_CONFIG_H -D_LITTLE_ENDIAN -DPARADOCNUM -DSHORT_SUFFIX -D_CRT_SECURE_NO_DEPRECATE
+INCLUDES = -I"$(GSDL_DIR)" -I"$(GSDL_DIR)\src\lib" -I"$(COLSERVR_DIR)" -I"$(PROTOCOL_DIR)" -I"$(RECPT_DIR)" \
+	-I"$(GSDL_DIR)\src\colservr" -I"$(GSDL_DIR)\indexers\mg" \
+	-I"$(PACKAGES_DIR)\windows\gdbm\gdbm" \
+        -I"$(GSDL_DIR)\indexers\mg\lib" -I"$(GSDL_DIR)\indexers\mg\src\text" \
+    	-I"$(GSDL_DIR)\indexers\mgpp\lib" -I"$(GSDL_DIR)\indexers\mgpp\text"
+LDFLAGS =
+LIBS = "$(PACKAGES_DIR)\windows\crypt\crypt\crypt.lib" "$(PACKAGES_DIR)\windows\expat\expat\libexpat.lib" \
+        "$(PACKAGES_DIR)\windows\gdbm\gdbm\gdbm.lib" $(ACCENTFOLD_LIBS) $(SQLITE_LIBS)
+RSC = rc
+WINLIBS = kernel32.lib user32.lib gdi32.lib winspool.lib \
+          comdlg32.lib advapi32.lib shell32.lib ole32.lib \
+          oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 
+#wsock32.lib
+
+
+!IF $(GSDL_VC4)
+DEFS = $(DEFS) -DGSDL_NAMESPACE_BROKEN -DGSDL_USE_IOS_H -D__STL_NO_NEW_IOSTREAMS
+INCLUDES = $(INCLUDES) -I"$(PACKAGES_DIR)\windows\stlport\stlport"
+!ENDIF
+
+
+COMPILE = $(CC) -nologo -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+LINK = $(CC) -nologo $(LDFLAGS) -Fe"$@"
+
+
+.SUFFIXES:
+.SUFFIXES: .cpp .obj
+.cpp.obj:
+	$(COMPILE) $< 
+
+
+SOURCES = \
+	cgiwrapper.cpp \
+	conftools.cpp \
+	d_winsock.cpp \
+	fnord.cpp \
+	httpreq.cpp \
+	httpsend.cpp \
+        httpsrv.cpp \
+	locate.cpp \
+	netio.cpp \
+	parse.cpp \
+	settings.cpp \
+	startbrowser.cpp \
+	wincgiutils.cpp
+
+OBJECTS = \
+	cgiwrapper.obj \
+	conftools.obj \
+	d_winsock.obj \
+	fnord.obj \
+	httpreq.obj \
+	httpsend.obj \
+        httpsrv.obj \
+	locate.obj \
+	netio.obj \
+	parse.obj \
+	settings.obj \
+	startbrowser.obj \
+	wincgiutils.obj
+
+RESOURCES = \
+	server.res
+
+GSDL_LIBS = \
+	"$(RECPT_DIR)\gsdlrecpt.lib" \
+	"$(PROTOCOL_DIR)\gsdlprotocol.lib" \
+	"$(COLSERVR_DIR)\gsdlcolservr.lib" \
+	"$(INDEXERS_DIR)\mg\src\text\libmgtext.lib" \
+	"$(INDEXERS_DIR)\mg\lib\libmglib.lib" \
+	"$(INDEXERS_DIR)\mgpp\text\libmgpptext.lib" \
+	"$(INDEXERS_DIR)\mgpp\lib\libmgpplib.lib" \
+	"$(GSDL_DIR)\src\lib\gsdllib.lib"
+
+EXECUTABLE_OBJECTS = \
+	$(OBJECTS) \
+	$(RESOURCES) \
+	$(GSDL_LIBS)
+
+EXECUTABLE = server.exe
+
+
+# Default target: make the local library executable
+all: $(EXECUTABLE)
+
+server.exe: $(EXECUTABLE_OBJECTS)
+	$(LINK) $(EXECUTABLE_OBJECTS) $(LIBS) $(WINLIBS) 
+install:
+	copy $(EXECUTABLE) "$(GSDL_DIR)"
+
+clean:
+	del *.obj
+	del $(EXECUTABLE)
+
+
+# Resources stuff
+SOURCE = "$(GSDL_DIR)\src\w32server\newgsdl.bmp"
+SOURCE = "$(GSDL_DIR)\src\w32server\resource.h"
+SOURCE = "$(GSDL_DIR)\src\w32server\server.ico"
+SOURCE = "$(GSDL_DIR)\src\w32server\gsdlcol.bmp"
+SOURCE = "$(GSDL_DIR)\src\w32server\server.rc"
+DEP_RSC_SERVE=\
+	"$(GSDL_DIR)\src\w32server\gsdlcol.bmp"\
+	"$(GSDL_DIR)\src\w32server\newgsdl.bmp"\
+	"$(GSDL_DIR)\src\w32server\server.ico"
+
+server.res : $(SOURCE) $(DEP_RSC_SERVE) "$(GSDL_DIR)\src\w32server"
+   $(RSC) /l 0x409 /fo"$(GSDL_DIR)\src\w32server\server.res" /i "$(GSDL_DIR)\src\w32server" \
+ /d "NDEBUG" $(SOURCE)
+
+"$(GSDL_DIR)\src\w32server\server.res" : $(SOURCE) $(DEP_RSC_SERVE) "$(GSDL_DIR)\src\w32server"
+   $(RSC) /l 0x409 /fo"$(GSDL_DIR)\src\w32server\server.res" /i "$(GSDL_DIR)\src\w32server" \
+ /d "NDEBUG" $(SOURCE)
Index: /gsdl/trunk/runtime-src/src/w32server/wincgiutils.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/wincgiutils.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/wincgiutils.cpp	(revision 16571)
@@ -0,0 +1,167 @@
+/**********************************************************************
+ *
+ * wincgiutils.cpp
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "text_t.h"
+#include <windows.h>
+#include <string.h>
+#include "netio.h"
+#include "httpreq.h"
+#include "wincgiutils.h"
+
+#define default_http_port 80
+
+// Attempt to break a url into segments. If the parsing fails, 'name' is
+// left pointing to the unparsed portion.
+int parse_url(const text_t &url, text_t &protocol, text_t &machine, 
+	      int *port, text_t &name) {
+
+  protocol.clear();
+  machine.clear();
+  *port = default_http_port;
+  name.clear();
+  
+  text_t::const_iterator begin = url.begin();
+  text_t::const_iterator end = url.end();
+  text_t::const_iterator it = findchar(begin, end, ':');
+  if (it == end) {name = url; return http_error_url_invalid;}
+  if (substr(it+1, it+3) != "//") {name = url; return http_error_url_invalid;}
+  protocol = substr(begin, it);
+  it += 3;
+  while (it < end) {
+    if (*it == ':') {
+      ++it;
+      text_t portstr;
+      while (it != end && (*it >= '0' && *it <= '9')) {
+	portstr.push_back(*it);
+	++it;
+      }
+      *port = portstr.getint();
+      if (it == end) break;
+    }
+
+    if (*it == '/') {
+      while (it != end) {
+	name.push_back(*it);
+	++it;
+      }
+      break;
+    }
+
+    machine.push_back(*it);
+    ++it;
+  }
+  return http_ok;
+}
+
+int Send_String(char *str, RequestInfoT *RInfo)
+{
+  return
+    SendData(RInfo->ClientSocket, (BYTE *)str, strlen(str), RInfo->ThreadNum);
+}
+
+int Send_String_N(char *str, int n,  RequestInfoT *RInfo)
+{
+  return
+    SendData(RInfo->ClientSocket, (BYTE *)str, n, RInfo->ThreadNum);
+}
+
+int send_header(char *content, RequestInfoT *RequestInfo)
+{
+  char Header[1536];  int len, lenc;
+  //Build Header
+  Header[0] = 0;
+  //Status Line
+  if (content[0] != '@')          /*No redirection needed*/
+    strcat(Header, "HTTP/1.0 200 OK\r\n");
+  else                            /*Redirection*/
+    strcat(Header, "HTTP/1.0 302 Relocation\r\n");
+  //Server
+  strcat(Header, "Server: GSDL\r\n");
+  //Content Type
+  strcat(Header, "Content-type: ");
+  if (content[0] != '@')          /*No redirection needed*/
+    strcat(Header, content);
+  else {                          /*Redirection entry*/
+    strcat(Header, "text/html \r\n");
+    strcat(Header, "Location: ");
+    len = strlen(Header);
+    lenc = strlen(content) - 1;
+    strncpy(&Header[len], &content[1], lenc);
+    Header[len+lenc] = 0;
+  }
+  strcat(Header, " \r\n");
+  //Single CRLF to end header
+  strcat(Header, "\r\n");
+  
+  return Send_String(Header, RequestInfo);
+}
+
+void send_retrieve_error(int error_num, char *msg1, char *msg2, RequestInfoT *RequestInfo)
+{
+  char Header[512], Body[512], ErrorNumStr[17], BodyLengthStr[17];
+  DWORD BodyLength; int HeaderLength;
+  
+  itoa(error_num, ErrorNumStr, 10);
+  
+  //Build Data (so we can determine length for the header)
+  Body[0] = 0;
+  strcat(Body, "<HTML><HEAD><TITLE>Server Error</TITLE></HEAD><BODY>\n");
+  strcat(Body, "<H1>Error ");
+  strcat(Body, ErrorNumStr);
+  strcat(Body, ": ");
+  strcat(Body, msg1);
+  strcat(Body, "</H1>\n");
+  strcat(Body, msg2);
+  strcat(Body, "\n</BODY></HTML>");
+  BodyLength = (DWORD) strlen(Body);
+
+  //Build Header
+  Header[0] = 0;
+  //Status Line
+  strcat(Header, "HTTP/1.0 ");
+  strcat(Header, ErrorNumStr);
+  strcat(Header, " ");
+  strcat(Header, msg1);
+  strcat(Header, "\r\n");
+  //Server
+  strcat(Header, "Server: GSDL\r\n");
+  strcat(Header, "Content-Type: text/html\r\n");
+  //Content Length
+  itoa(BodyLength, BodyLengthStr, 10);
+  strcat(Header, "Content-Length: ");
+  strcat(Header, BodyLengthStr);
+  strcat(Header, "\r\n");
+  //Single CRLF to end header
+  strcat(Header, "\r\n");
+  HeaderLength = strlen(Header);
+
+   //Send the file if we have one (and if it's not a HEAD request)
+  SendData(RequestInfo->ClientSocket, (BYTE *) Header, strlen(Header), RequestInfo->ThreadNum);
+  //   if ((FileFound == FALSE) && (strcmpi(RequestFields.MethodStr, "HEAD") != 0)) {
+  //Send generated data
+  SendData(RequestInfo->ClientSocket, (BYTE *) Body, BodyLength, RequestInfo->ThreadNum);
+}
Index: /gsdl/trunk/runtime-src/src/w32server/wincgiutils.h
===================================================================
--- /gsdl/trunk/runtime-src/src/w32server/wincgiutils.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/w32server/wincgiutils.h	(revision 16571)
@@ -0,0 +1,62 @@
+/**********************************************************************
+ *
+ * wincgiutils.h
+ * Copyright (C) 1996
+ * 
+ * A component of the fnord webserver written by bmorin@wpi.edu.
+ *
+ * Altered for use with the Greenstone digital library software by the
+ * New Zealand Digital Library Project at the University of Waikato,
+ * New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#define http_ok 0
+#define http_error_url_invalid 11
+
+int parse_url(const text_t &url, text_t &protocol, text_t &machine, 
+	      int *port, text_t &name);
+
+struct param_vals {char *name, *value; int vsize; char *dfault; };
+
+
+int Send_String(char *str, RequestInfoT *RInfo);
+int Send_String_N(char *str, int n,  RequestInfoT *RInfo);
+void send_retrieve_error(int error_num, char *msg1, char *msg2, RequestInfoT *RequestInfo);
+int send_header(char *content, RequestInfoT *RequestInfo);
+void decode(char *st);
+void decode_template(int ntemp, param_vals tmplate[]);
+void parse_query_string(char *qstring, int ntemp, param_vals tmplate[]);
+int mg_sender(char *UDoc, int ULen, int DocNum, float Weight, void *RInfo);
+
+#define OUT_CONST_A(t) \
+{if (Send_String_N(t, sizeof(t), RInfo) < 0) return;}
+
+#define OUT_CONST_B(t) \
+{if (Send_String_N(t, sizeof(t), (RequestInfoT *)RInfo) < 0) return -1;}
+
+#define OUT_STRING_A(t) \
+{if (Send_String(t, RInfo) < 0) return;}
+
+#define OUT_STRING_B(t) \
+{if (Send_String(t, (RequestInfoT *)RInfo) < 0) return -1;}
+
+#define OUT_STRING_N_A(t,n) \
+{if (Send_String_N(t, n, RInfo) < 0) return;}
+
+#define OUT_STRING_N_B(t,n) \
+{if (Send_String_N(t, n, (RequestInfoT *)RInfo) < 0) return -1;}
Index: /gsdl/trunk/runtime-src/src/z3950/Makefile.in
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/Makefile.in	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/Makefile.in	(revision 16571)
@@ -0,0 +1,157 @@
+###########################################################################
+#
+# Makefile -- src/z3950
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ../..
+INDEXERS_DIR = $(GSDL_DIR)/indexers
+PACKAGES_DIR = $(GSDL_DIR)/packages
+COLSERVR_DIR = $(GSDL_DIR)/src/colservr
+PROTOCOL_DIR = $(GSDL_DIR)/src/protocol
+
+
+ENABLE_ACCENTFOLD = @ENABLE_ACCENTFOLD@
+ifeq ($(ENABLE_ACCENTFOLD), 1)
+ACCENTFOLD_LIBS = $(INDEXERS_DIR)/packages/unac/libunac.a 
+else
+ACCENTFOLD_LIBS = 
+endif
+
+USE_SQLITE = @USE_SQLITE@
+ifeq ($(USE_SQLITE), 1)
+SQLITE_LIBS = $(PACKAGES_DIR)/sqlite/lib/libsqlite3.a -ldl -lpthread
+else
+SQLITE_LIBS = 
+endif
+
+USE_Z3950 = @USE_Z3950@
+ifeq ($(USE_Z3950), 1)
+AR = ar
+CC = @CC@
+CPP = @CXX@
+CFLAGS = @CFLAGS@
+CPPFLAGS = @CXXFLAGS@
+DEFS = @DEFS@ -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DGSDLSERVER
+GSDLOS = @gsdlos@
+# Do NOT add the "recpt" directory here: the z39.50 code should be independent of the receptionist!
+INCLUDES = -I. -I$(GSDL_DIR) -I$(GSDL_DIR)/src/lib -I$(COLSERVR_DIR) -I$(PROTOCOL_DIR) \
+	-I$(INDEXERS_DIR)/mgpp/text -I$(PACKAGES_DIR)/yaz/yaz-2.1.4/include \
+	-I$(PACKAGES_DIR)/yaz/yaz-2.1.4/client -I$(PACKAGES_DIR)/d2m
+INSTALL = @INSTALL@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@ @GDBM_LIBPATH@ -lgdbm -L$(PACKAGES_DIR)/expat/lib -lexpat $(ACCENTFOLD_LIBS) $(SQLITE_LIBS) \
+	$(PACKAGES_DIR)/yaz/lib/libyaz.a $(PACKAGES_DIR)/d2m/libd2m.a -lxml2
+RANLIB = @RANLIB@
+
+
+COMPILE = $(CC) -c $(CFLAGS) $(DEFS) $(INCLUDES)
+CPPCOMPILE = $(CPP) -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+CPPLINK = $(CPP) $(LDFLAGS) -o $@
+
+
+.SUFFIXES:
+.SUFFIXES: .c .o
+.c.o:
+	$(COMPILE) $<
+
+.SUFFIXES: .cpp .o
+.cpp.o:
+	$(CPPCOMPILE) $< 
+
+
+LIBRARY_SOURCES = \
+	yaz_zclient.c \
+	z3950proto.cpp \
+	z3950proxy.cpp \
+	zparse.tab.c \
+	zparse.yy.c
+
+LIBRARY_OBJECTS = \
+	yaz_zclient.o \
+	z3950proto.o \
+	z3950proxy.o \
+	zparse.tab.o \
+	zparse.yy.o
+
+LIBRARY = gsdlz3950.a
+
+SOURCES = \
+	z3950explain.cpp \
+	z3950parser.cpp \
+	z3950server.cpp \
+	z3950_to_gsdl.cpp
+
+OBJECTS = \
+	z3950explain.o \
+	z3950parser.o \
+	z3950server.o \
+	z3950_to_gsdl.o
+
+GSDL_LIBS = \
+	gsdlz3950.a \
+	$(PROTOCOL_DIR)/gsdlprotocol.a \
+	$(COLSERVR_DIR)/gsdlcolservr.a \
+	$(INDEXERS_DIR)/mg/src/text/libmgtext.a \
+	$(INDEXERS_DIR)/mg/lib/libmglib.a \
+	$(INDEXERS_DIR)/mgpp/text/libmgpptext.a \
+	$(INDEXERS_DIR)/mgpp/lib/libmgpplib.a \
+	$(GSDL_DIR)/src/lib/gsdllib.a
+
+EXECUTABLE_OBJECTS = \
+	$(OBJECTS) \
+	$(GSDL_LIBS)
+
+EXECUTABLE = z3950server
+
+
+# Default target: make both gsdlz3950.a and the z3950server executable
+all: $(LIBRARY) $(EXECUTABLE)
+
+gsdlz3950.a: $(LIBRARY_OBJECTS)
+	rm -f $(LIBRARY)
+	$(AR) cru $(LIBRARY) $(LIBRARY_OBJECTS) $(PACKAGES_DIR)/yaz/yaz-2.1.4/client/tabcomplete.o
+	$(RANLIB) $(LIBRARY)
+
+z3950server: $(EXECUTABLE_OBJECTS)
+	$(CPPLINK) $(EXECUTABLE_OBJECTS) $(LIBS)
+
+install: $(EXECUTABLE)
+	$(INSTALL) -m 755 -s $(EXECUTABLE) $(GSDL_DIR)/bin/$(GSDLOS)
+
+clean:
+	rm -f $(OBJECTS) $(LIBRARY) $(EXECUTABLE)
+
+distclean:
+	rm -f $(OBJECTS) $(LIBRARY) $(EXECUTABLE) Makefile
+
+depend:
+	makedepend -Y -- $(DEFS) $(INCLUDES) $(CPPFLAGS) -- $(SOURCES)
+
+else
+all:
+install:
+clean:
+distclean:
+depend:
+endif
Index: /gsdl/trunk/runtime-src/src/z3950/win32.mak
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/win32.mak	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/win32.mak	(revision 16571)
@@ -0,0 +1,163 @@
+###########################################################################
+#
+# win32 makefile -- src/z3950
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999-2008  The New Zealand Digital Library Project
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+GSDL_DIR = ..\..
+INDEXERS_DIR = $(GSDL_DIR)\indexers
+PACKAGES_DIR = $(GSDL_DIR)\packages
+COLSERVR_DIR = $(GSDL_DIR)\src\colservr
+PROTOCOL_DIR = $(GSDL_DIR)\src\protocol
+
+
+GSDL_VC4 = 0
+DLL = 0
+DLLDEBUG = 0
+ENABLE_ACCENTFOLD = 1
+USE_SQLITE = 0
+
+
+!IF $(GSDL_VC4)
+CPPFLAGS = -GX
+!ELSE
+CPPFLAGS = -EHsc
+!ENDIF
+
+!IF $(DLL)
+CPPFLAGS = $(CPPFLAGS) -MD
+!ELSE
+!IF ($(DLLDEBUG))
+CPPFLAGS = $(CPPFLAGS) -MDd
+!ENDIF
+!ENDIF
+
+!IF $(ENABLE_ACCENTFOLD)
+ACCENTFOLD_LIBS = "$(INDEXERS_DIR)\packages\unac\libunac.lib" "$(INDEXERS_DIR)\packages\unac\iconv.lib"
+!ELSE
+ACCENTFOLD_LIBS = 
+!ENDIF
+
+!IF $(USE_SQLITE)
+SQLITE_LIBS = "$(PACKAGES_DIR)\sqlite\lib\sqlite3.lib"
+!ELSE
+SQLITE_LIBS = 
+!ENDIF
+
+
+AR = lib
+CC = cl
+DEFS = -D__WIN32__ -DHAVE_CONFIG_H -DPARADOCNUM -D_LITTLE_ENDIAN -DSHORT_SUFFIX -D_CRT_SECURE_NO_DEPRECATE
+# Do NOT add the "recpt" directory here: the z39.50 code should be independent of the receptionist!
+INCLUDES = -I"$(GSDL_DIR)" -I"$(GSDL_DIR)\src\lib" -I"$(COLSERVR_DIR)" -I"$(PROTOCOL_DIR)" \
+	-I"$(INDEXERS_DIR)\mgpp\text" -I"$(PACKAGES_DIR)\yaz\yaz-2.1.4\include" \
+	-I"$(PACKAGES_DIR)\yaz\yaz-2.1.4\client" -I"$(PACKAGES_DIR)\d2m" \
+	-I"$(PACKAGES_DIR)\windows\gdbm\gdbm"
+LDFLAGS = 
+LIBS = "$(PACKAGES_DIR)\windows\expat\expat\libexpat.lib" "$(PACKAGES_DIR)\windows\gdbm\gdbm\gdbm.lib" \
+        "$(PACKAGES_DIR)\d2m\libd2m.lib" "$(PACKAGES_DIR)\yaz\yaz-2.1.4\lib\yaz.lib" $(ACCENTFOLD_LIBS) \
+	$(SQLITE_LIBS)
+
+!IF $(GSDL_VC4)
+DEFS=$(DEFS) -DGSDL_NAMESPACE_BROKEN -DGSDL_USE_IOS_H -D__STL_NO_NEW_IOSTREAMS
+INCLUDES = $(INCLUDES) -I"$(PACKAGES_DIR)\windows\stlport\stlport"
+!ENDIF
+
+
+COMPILE = $(CC) -nologo -c $(CPPFLAGS) $(DEFS) $(INCLUDES)
+LINK = $(CC) -nologo -Fe"$@" $(LDFLAGS)
+
+
+.SUFFIXES:
+.SUFFIXES: .c .obj
+.c.obj:
+	$(COMPILE) $<
+
+.SUFFIXES: .cpp .obj
+.cpp.obj:
+	$(COMPILE) $< 
+
+
+LIBRARY_SOURCES = \
+	yaz_zclient.c \
+	z3950proto.cpp \
+	z3950proxy.cpp \
+	zparse.tab.c \
+	zparse.yy.c
+
+LIBRARY_OBJECTS = \
+	yaz_zclient.obj \
+	z3950proto.obj \
+	z3950proxy.obj \
+	zparse.tab.obj \
+	zparse.yy.obj
+
+LIBRARY = gsdlz3950.lib
+
+
+SOURCES = \
+	z3950explain.cpp \
+	z3950parser.cpp \
+	z3950server.cpp \
+	z3950_to_gsdl.cpp
+
+OBJECTS = \
+	z3950explain.obj \
+	z3950parser.obj \
+	z3950server.obj \
+	z3950_to_gsdl.obj
+
+GSDL_LIBS = \
+	gsdlz3950.lib \
+	$(PROTOCOL_DIR)\gsdlprotocol.lib \
+	$(COLSERVR_DIR)\gsdlcolservr.lib \
+	$(INDEXERS_DIR)\mg/src/text/libmgtext.lib \
+	$(INDEXERS_DIR)\mg/lib/libmglib.lib \
+	$(INDEXERS_DIR)\mgpp/text/libmgpptext.lib \
+	$(INDEXERS_DIR)\mgpp/lib/libmgpplib.lib \
+	$(GSDL_DIR)\src\lib\gsdllib.lib
+
+EXECUTABLE_OBJECTS = \
+	$(OBJECTS) \
+	$(GSDL_LIBS)
+
+EXECUTABLE = z3950server.exe
+
+
+# Default target: make both gsdlz3950.lib and z3950server.exe
+all: $(LIBRARY) $(EXECUTABLE)
+
+gsdlz3950.lib: $(LIBRARY_OBJECTS)
+	if EXIST $(LIBRARY) del $(LIBRARY)
+	$(AR) -nologo /out:$(LIBRARY) $(LIBRARY_OBJECTS) $(PACKAGES_DIR)/yaz/yaz-2.1.4/win/obj/tabcomplete.obj
+
+z3950server.exe: $(EXECUTABLE_OBJECTS)
+	$(LINK) $(EXECUTABLE_OBJECTS) $(LIBS)
+
+install: $(EXECUTABLE)
+	copy $(EXECUTABLE) "$(GSDL_DIR)\bin\windows"
+
+clean:
+	del *.obj
+	del $(LIBRARY)
+	del $(EXECUTABLE)
Index: /gsdl/trunk/runtime-src/src/z3950/yaz_zclient.c
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/yaz_zclient.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/yaz_zclient.c	(revision 16571)
@@ -0,0 +1,5410 @@
+/* 
+ * Copyright (C) 1995-2005, Index Data 
+ * See the file LICENSE for details.
+ *
+ */
+
+/* Modified for the Greenstone Digital Library project, based on yaz 2's client.c
+ kjdon, copying version 1.6 mods done by johnmcp */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <time.h>
+#include <ctype.h>
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#if HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+/* this one needs to be there
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+*/
+#include <sys/stat.h>
+
+#if HAVE_OPENSSL_SSL_H
+#include <openssl/bio.h>
+#include <openssl/crypto.h>
+#include <openssl/x509.h>
+#include <openssl/pem.h>
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+#endif
+
+#ifdef __WIN32__
+#include <sys/stat.h>
+#include <io.h>
+#include <windows.h>
+#define S_ISREG(x) (x & _S_IFREG)
+#define S_ISDIR(x) (x & _S_IFDIR)
+#endif
+
+#include <yaz/yaz-util.h>
+
+#include <yaz/comstack.h>
+
+#include <yaz/proto.h>
+#include <yaz/marcdisp.h>
+#include <yaz/diagbib1.h>
+#include <yaz/otherinfo.h>
+#include <yaz/charneg.h>
+
+#include <yaz/pquery.h>
+#include <yaz/sortspec.h>
+
+#include <yaz/ill.h>
+#include <yaz/srw.h>
+#include <yaz/yaz-ccl.h>
+#include <yaz/cql.h>
+#include <yaz/log.h>
+
+#if HAVE_READLINE_READLINE_H
+#include <readline/readline.h>
+#endif
+#if HAVE_READLINE_HISTORY_H
+#include <readline/history.h>
+#endif
+
+/* these files are from the yaz client */
+#include "tabcomplete.h"
+
+#include "yaz_zclient.h"
+
+#define C_PROMPT "Z> "
+
+static char *codeset = 0;               /* character set for output */
+static int hex_dump = 0;
+static char *dump_file_prefix = 0;
+static ODR out, in, print;              /* encoding and decoding streams */
+#if HAVE_XML2
+static ODR srw_sr_odr_out = 0;
+static Z_SRW_PDU *srw_sr = 0;
+#endif
+static FILE *apdu_file = 0;
+static FILE *ber_file = 0;
+static COMSTACK conn = 0;               /* our z-association */
+static Z_IdAuthentication *auth = 0;    /* our current auth definition */
+char *databaseNames[128];
+int num_databaseNames = 0;
+static Z_External *record_last = 0;
+static int setnumber = -1;              /* current result set number */
+static int smallSetUpperBound = 0;
+static int largeSetLowerBound = 1;
+static int mediumSetPresentNumber = 0;
+static Z_ElementSetNames *elementSetNames = 0; 
+static int setno = 1;                   /* current set offset */
+static enum oid_proto protocol = PROTO_Z3950;      /* current app protocol */
+static enum oid_value recordsyntax = VAL_USMARC;
+static char *record_schema = 0;
+static int sent_close = 0;
+static NMEM session_mem = NULL;         /* memory handle for init-response */
+static Z_InitResponse *session = 0;     /* session parameters */
+static char last_scan_line[512] = "0";
+static char last_scan_query[512] = "0";
+static char ccl_fields[512] = "default.bib";
+/* ### How can I set this path to use wherever YAZ is installed? */
+/* ############## change */
+static char cql_fields[512] = "/research/kjdon/home/z3950/gsdl/packages/yaz2/etc/pqf.properties";
+static char *esPackageName = 0;
+static char *yazProxy = 0;
+static int kilobytes = 1024;
+static char *negotiationCharset = 0;
+static int  negotiationCharsetRecords = 1;
+static int  negotiationCharsetVersion = 3;
+static char *outputCharset = 0;
+static char *marcCharset = 0;
+static char* yazLang = 0;
+static char* http_version = "1.1";
+
+static char last_cmd[32] = "?";
+static FILE *marc_file = 0;
+static char *refid = NULL;
+static char *last_open_command = NULL;
+static int auto_reconnect = 0;
+static Odr_bitmask z3950_options;
+static int z3950_version = 3;
+static int scan_stepSize = 0;
+static int scan_position = 1;
+static int scan_size = 20;
+static char cur_host[200];
+
+typedef enum {
+    QueryType_Prefix,
+    QueryType_CCL,
+    QueryType_CCL2RPN,
+    QueryType_CQL,
+    QueryType_CQL2RPN
+} QueryType;
+
+static QueryType queryType = QueryType_Prefix;
+
+static CCL_bibset bibset;               /* CCL bibset handle */
+static cql_transform_t cqltrans;	/* CQL context-set handle */
+
+#if HAVE_READLINE_COMPLETION_OVER
+
+#else
+/* readline doesn't have this var. Define it ourselves. */
+int rl_attempted_completion_over = 0;
+#endif
+
+/* set this one to 1, to avoid decode of unknown MARCs  */
+#define AVOID_MARC_DECODE 1
+
+#define maxOtherInfosSupported 10
+struct {
+    int oidval;
+    char* value;
+} extraOtherInfos[maxOtherInfosSupported];
+	
+
+void process_cmd_line(char* line);
+char ** readline_completer(char *text, int start, int end);
+char *command_generator(const char *text, int state);
+char** curret_global_list=NULL;
+int cmd_register_tab(const char* arg);
+
+static void close_session (void);
+
+ODR getODROutputStream()
+{
+    return out;
+}
+
+const char* query_type_as_string(QueryType q) 
+{
+    switch (q) { 
+    case QueryType_Prefix: return "prefix (RPN sent to server)";
+    case QueryType_CCL: return "CCL (CCL sent to server) ";
+    case QueryType_CCL2RPN: return "CCL -> RPN (RPN sent to server)";
+    case QueryType_CQL: return "CQL (CQL sent to server)";
+    case QueryType_CQL2RPN: return "CQL -> RPN (RPN sent to server)";
+    default: 
+        return "unknown Query type internal yaz-client error";
+    }
+}
+
+static void do_hex_dump(const char* buf, int len) 
+{
+    if (hex_dump)
+    {
+	int i,x;
+	for( i=0; i<len ; i=i+16 ) 
+	{			
+	    printf(" %4.4d ",i);
+	    for(x=0 ; i+x<len && x<16; ++x) 
+	    {
+		printf("%2.2X ",(unsigned int)((unsigned char)buf[i+x]));
+	    }
+	    printf("\n");
+	}
+    }
+    if (dump_file_prefix)
+    {
+	static int no = 0;
+	if (++no < 1000 && strlen(dump_file_prefix) < 500)
+	{
+	    char fname[1024];
+	    FILE *of;
+	    sprintf (fname, "%s.%03d.raw", dump_file_prefix, no);
+	    of = fopen(fname, "wb");
+	    
+	    fwrite (buf, 1, len, of);
+	    
+	    fclose(of);
+	}
+    }
+}
+
+void add_otherInfos(Z_APDU *a) 
+{
+    Z_OtherInformation **oi;
+    int i;
+		
+    yaz_oi_APDU(a, &oi);
+    for(i=0; i<maxOtherInfosSupported; ++i) 
+    {
+        if(extraOtherInfos[i].oidval != -1) 
+            yaz_oi_set_string_oidval(oi, out, extraOtherInfos[i].oidval,
+                                     1, extraOtherInfos[i].value);
+    }   
+}
+
+int send_apdu(Z_APDU *a)
+{
+    char *buf;
+    int len;
+    
+    add_otherInfos(a);
+    
+    if (apdu_file)
+    {
+        z_APDU(print, &a, 0, 0);
+        odr_reset(print);
+    }
+    if (!z_APDU(out, &a, 0, 0))
+    {
+        odr_perror(out, "Encoding APDU");
+        close_session();
+        return 0;
+    }
+    buf = odr_getbuf(out, &len, 0);
+    if (ber_file)
+        odr_dumpBER(ber_file, buf, len);
+    /* printf ("sending APDU of size %d\n", len); */
+    do_hex_dump(buf, len);
+    if (cs_put(conn, buf, len) < 0)
+    {
+        fprintf(stderr, "cs_put: %s", cs_errmsg(cs_errno(conn)));
+        close_session();
+        return 0;
+    }
+    odr_reset(out); /* release the APDU structure  */
+    return 1;
+}
+
+static void print_stringn(const unsigned char *buf, size_t len)
+{
+    size_t i;
+    for (i = 0; i<len; i++)
+        if ((buf[i] <= 126 && buf[i] >= 32) || strchr ("\n\r\t\f", buf[i]))
+            printf ("%c", buf[i]);
+        else
+            printf ("\\X%02X", buf[i]);
+}
+
+static void print_refid (Z_ReferenceId *id)
+{
+    if (id)
+    {
+        printf ("Reference Id: ");
+        print_stringn (id->buf, id->len);
+        printf ("\n");
+    }
+}
+
+static Z_ReferenceId *set_refid (ODR out)
+{
+    Z_ReferenceId *id;
+    if (!refid)
+        return 0;
+    id = (Z_ReferenceId *) odr_malloc (out, sizeof(*id));
+    id->size = id->len = strlen(refid);
+    id->buf = (unsigned char *) odr_malloc (out, id->len);
+    memcpy (id->buf, refid, id->len);
+    return id;
+}   
+
+/* INIT SERVICE ------------------------------- */
+
+static void send_initRequest(const char* type_and_host)
+{
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_initRequest);
+    Z_InitRequest *req = apdu->u.initRequest;
+    int i;
+
+    req->options = &z3950_options;
+
+    ODR_MASK_ZERO(req->protocolVersion);
+    for (i = 0; i<z3950_version; i++)
+	ODR_MASK_SET(req->protocolVersion, i);
+
+    *req->maximumRecordSize = 1024*kilobytes;
+    *req->preferredMessageSize = 1024*kilobytes;
+
+    req->idAuthentication = auth;
+
+    req->referenceId = set_refid (out);
+
+    if (yazProxy && type_and_host) 
+        yaz_oi_set_string_oidval(&req->otherInfo, out, VAL_PROXY,
+        1, type_and_host);
+    
+    if (negotiationCharset || yazLang) {
+    	Z_OtherInformation **p;
+    	Z_OtherInformationUnit *p0;
+    	
+    	yaz_oi_APDU(apdu, &p);
+    	
+    	if ((p0=yaz_oi_update(p, out, NULL, 0, 0))) {
+	    ODR_MASK_SET(req->options, Z_Options_negotiationModel);
+	    
+	    p0->which = Z_OtherInfo_externallyDefinedInfo;
+	    p0->information.externallyDefinedInfo =
+		yaz_set_proposal_charneg(
+		    out,
+		    (const char**)&negotiationCharset, 
+		    negotiationCharset ? 1 : 0,
+		    (const char**)&yazLang, yazLang ? 1 : 0, 
+		    negotiationCharsetRecords);
+    	}
+    }
+    
+    send_apdu(apdu);
+    /* (send_apdu(apdu))
+	intf("Sent initrequest.\n");*/
+}
+
+/* in old version, John had got rid of process_initResponse, and added
+   z_get_initResponse. I'll add this in but leave the other one alone 
+ this returns the info that is used in the description for the 'collection'*/
+char *z_get_initResponse()
+{
+    
+    char* buffer; /* we are returning some info in this buffer */
+    char *text_id="ID: ";
+    char *text_name="<br>\nName: ";
+    char *text_ver="<br>\nVersion: ";
+    size_t initial_length;
+    
+    if (!*session->result)
+	return NULL; /* no init info to return */
+    
+   
+    initial_length = strlen(text_id)+strlen(text_name)+strlen(text_ver)+
+	(session->implementationId?strlen(session->implementationId):0) +
+	(session->implementationName?strlen(session->implementationName):0) +
+	(session->implementationVersion?strlen(session->implementationVersion)
+	 :0)  + 1; /* for null char */
+    
+    if ((buffer = malloc((sizeof(char *))*initial_length)) == NULL) {
+	fprintf(stderr,"Malloc failed while initialising z39.50 server\n");
+	return (NULL);
+    }
+    /* can't pass NULL to sprintf as a (char *) */
+    sprintf(buffer,"%s%s%s%s%s%s",
+	    session->implementationId?text_id:"",
+	    session->implementationId?session->implementationId:"",
+	    session->implementationName?text_name:"",
+	    session->implementationName?session->implementationName:"",
+	    session->implementationVersion?text_ver:"",
+	    session->implementationVersion?session->implementationVersion:""
+	    );
+    return (buffer);
+    
+}
+
+char *z_get_initResponseOld()
+{
+    char *buffer; 
+    size_t needed_length;
+    char *text_id="ID: ";
+    char *text_name="<br>\nName: ";
+    char *text_ver="<br>\nVersion: ";
+    int counter;
+    
+    buffer=NULL;
+    if (!*session->result)
+	return NULL;
+    
+    /* work out total string length needed. Note strlen(NULL) is a bad thing
+       to do. */
+    needed_length=strlen(text_id)+strlen(text_name)+strlen(text_ver)+
+	(session->implementationId?strlen(session->implementationId):0) +
+	(session->implementationName?strlen(session->implementationName):0) +
+	(session->implementationVersion?strlen(session->implementationVersion)
+	 :0) +
+	(session->userInformationField?
+	 strlen(session->userInformationField->u.octet_aligned->buf):0) +
+	1 /* for null char */ ;
+    if ((buffer=malloc((sizeof(char *)) * needed_length))==NULL) {
+	fprintf(stderr,"Malloc failed while initialising z39.50 server\n");
+	return (NULL);
+    }
+    /* can't pass NULL to sprintf as a (char *) */
+    sprintf(buffer,"%s%s%s%s%s%s",
+	    session->implementationId?text_id:"",
+	    session->implementationId?session->implementationId:"",
+	    session->implementationName?text_name:"",
+	    session->implementationName?session->implementationName:"",
+	    session->implementationVersion?text_ver:"",
+	    session->implementationVersion?session->implementationVersion:""
+	    );
+    
+    /* if version 3, also check the other-information parameter of the
+       response. (But check version is 3 first) */
+    if (session->otherInfo)
+	/**** From prt-proto.h *********** (comment added by johnmcp)
+	      typedef struct Z_OtherInformationUnit
+       .   {  Z_InfoCategory *category;        / * OPTIONAL * /
+       .      int which;
+       #define Z_OtherInfo_characterInfo 0
+       #define Z_OtherInfo_binaryInfo 1
+       #define Z_OtherInfo_externallyDefinedInfo 2
+       #define Z_OtherInfo_oid 3
+       .      union
+       .        {
+       .          char *characterInfo; 
+       .          Odr_oct *binaryInfo;
+       .          Z_External *externallyDefinedInfo;
+       .          Odr_oid *oid;
+       .        } information;
+       .   } Z_OtherInformationUnit;
+       
+       typedef struct Z_OtherInformation
+       {
+       int num_elements;
+       Z_OtherInformationUnit **list;
+       } Z_OtherInformation;
+	************/
+	for (counter=0;counter<session->otherInfo->num_elements;counter++) {
+	    if (session->otherInfo->list[counter]->which ==
+		Z_OtherInfo_characterInfo) {
+		
+		/* add this extra string to our buffer */
+		int where=strlen(buffer);
+		buffer=realloc(buffer,where+
+			       strlen(session->otherInfo->list[counter]->
+				      information.characterInfo));
+		strcpy(buffer+where,
+		       session->otherInfo->list[counter]->
+		       information.characterInfo);
+	    }
+	}
+    return (buffer);
+}
+
+
+/* These two are used only from process_initResponse() */
+static void render_initUserInfo(Z_OtherInformation *ui1);
+static void render_diag(Z_DiagnosticFormat *diag);
+
+static void pr_opt(const char *opt, void *clientData)
+{
+    printf (" %s", opt);
+}
+
+static int process_initResponse(Z_InitResponse *res)
+{
+    int ver = 0;
+    /* save session parameters for later use */
+    session_mem = odr_extract_mem(in);
+    session = res;
+
+    for (ver = 0; ver < 8; ver++)
+        if (!ODR_MASK_GET(res->protocolVersion, ver))
+            break;
+
+    if (!*res->result)
+        printf("Connection rejected by v%d target.\n", ver);
+    else
+        printf("Connection accepted by v%d target.\n", ver);
+    if (res->implementationId)
+        printf("ID     : %s\n", res->implementationId);
+    if (res->implementationName)
+        printf("Name   : %s\n", res->implementationName);
+    if (res->implementationVersion)
+        printf("Version: %s\n", res->implementationVersion);
+    if (res->userInformationField)
+    {
+	Z_External *uif = res->userInformationField;
+	if (uif->which == Z_External_userInfo1) {
+	    render_initUserInfo(uif->u.userInfo1);
+	} else {
+	    printf("UserInformationfield:\n");
+	    if (!z_External(print, (Z_External**)&uif, 0, 0))
+	    {
+		odr_perror(print, "Printing userinfo\n");
+		odr_reset(print);
+	    }
+	    if (uif->which == Z_External_octet) {
+		printf("Guessing visiblestring:\n");
+		printf("'%.*s'\n", uif->u.octet_aligned->len,
+		       uif->u.octet_aligned->buf);
+	    }
+	    else if (uif->which == Z_External_single) 
+	    {
+		Odr_any *sat = uif->u.single_ASN1_type;
+		oident *oid = oid_getentbyoid(uif->direct_reference);
+		if (oid->value == VAL_OCLCUI) {
+		    Z_OCLC_UserInformation *oclc_ui;
+		    ODR decode = odr_createmem(ODR_DECODE);
+		    odr_setbuf(decode, sat->buf, sat->len, 0);
+		    if (!z_OCLC_UserInformation(decode, &oclc_ui, 0, 0))
+			printf ("Bad OCLC UserInformation:\n");
+		    else
+			printf ("OCLC UserInformation:\n");
+		    if (!z_OCLC_UserInformation(print, &oclc_ui, 0, 0))
+			printf ("Bad OCLC UserInformation spec\n");
+		    odr_destroy(decode);
+		}
+		else
+		{
+		    /* Peek at any private Init-diagnostic APDUs */
+		    printf("### NAUGHTY: External is '%.*s'\n",
+			   sat->len, sat->buf);
+		}
+	    }
+	    odr_reset (print);
+	}
+    }
+    printf ("Options:");
+    yaz_init_opt_decode(res->options, pr_opt, 0);
+    printf ("\n");
+
+    if (ODR_MASK_GET(res->options, Z_Options_namedResultSets))
+        setnumber = 0;
+    
+    if (ODR_MASK_GET(res->options, Z_Options_negotiationModel)) {
+    
+    	Z_CharSetandLanguageNegotiation *p =
+    		yaz_get_charneg_record(res->otherInfo);
+    	
+    	if (p) {
+            
+            char *charset=NULL, *lang=NULL;
+
+            int selected;
+            
+            yaz_get_response_charneg(session_mem, p, &charset, &lang,
+                                     &selected);
+
+	    if (outputCharset && negotiationCharset) {
+		    odr_set_charset (out, charset, outputCharset);
+		    odr_set_charset (in, outputCharset, charset);
+	    }
+	    else {
+		    odr_set_charset (out, 0, 0);
+		    odr_set_charset (in, 0, 0);
+	    }
+            
+            printf("Accepted character set : %s\n", charset);
+            printf("Accepted code language : %s\n", lang ? lang : "none");
+            printf("Accepted records in ...: %d\n", selected );
+    	}
+    }
+    fflush (stdout);
+    return 0;
+}
+
+
+static void render_initUserInfo(Z_OtherInformation *ui1) {
+    int i;
+    printf("Init response contains %d otherInfo unit%s:\n",
+	   ui1->num_elements, ui1->num_elements == 1 ? "" : "s");
+
+    for (i = 0; i < ui1->num_elements; i++) {
+	Z_OtherInformationUnit *unit = ui1->list[i];
+	printf("  %d: otherInfo unit contains ", i+1);
+	if (unit->which == Z_OtherInfo_externallyDefinedInfo &&
+	    unit->information.externallyDefinedInfo &&
+	    unit->information.externallyDefinedInfo->which ==
+	    Z_External_diag1) {
+	    render_diag(unit->information.externallyDefinedInfo->u.diag1);
+	} 
+	else if (unit->which != Z_OtherInfo_externallyDefinedInfo)
+	{
+	    printf("unsupported otherInfo unit->which = %d\n", unit->which);
+	}
+	else 
+	{
+	    printf("unsupported otherInfo unit external %d\n",
+		   unit->information.externallyDefinedInfo ? 
+		   unit->information.externallyDefinedInfo->which : -2);
+	}
+    }
+}
+
+
+/* ### should this share code with display_diagrecs()? */
+static void render_diag(Z_DiagnosticFormat *diag) {
+    int i;
+
+    printf("%d diagnostic%s:\n", diag->num, diag->num == 1 ? "" : "s");
+    for (i = 0; i < diag->num; i++) {
+	Z_DiagnosticFormat_s *ds = diag->elements[i];
+	printf("    %d: ", i+1);
+	switch (ds->which) {
+	case Z_DiagnosticFormat_s_defaultDiagRec: {
+	    Z_DefaultDiagFormat *dd = ds->u.defaultDiagRec;
+	    /* ### should check `dd->diagnosticSetId' */
+	    printf("code=%d (%s)", *dd->condition,
+		   diagbib1_str(*dd->condition));
+	    /* Both types of addinfo are the same, so use type-pun */
+	    if (dd->u.v2Addinfo != 0)
+		printf(",\n\taddinfo='%s'", dd->u.v2Addinfo);
+	    break;
+	}
+	case Z_DiagnosticFormat_s_explicitDiagnostic:
+	    printf("Explicit diagnostic (not supported)");
+	    break;
+	default:
+	    printf("Unrecognised diagnostic type %d", ds->which);
+	    break;
+	}
+
+	if (ds->message != 0)
+	    printf(", message='%s'", ds->message);
+	printf("\n");
+    }
+}
+
+
+static int set_base(const char *arg)
+{
+    int i;
+    const char *cp;
+
+    for (i = 0; i<num_databaseNames; i++)
+        xfree (databaseNames[i]);
+    num_databaseNames = 0;
+    while (1)
+    {
+        char *cp1;
+        if (!(cp = strchr(arg, ' ')))
+            cp = arg + strlen(arg);
+        if (cp - arg < 1)
+            break;
+        databaseNames[num_databaseNames] = (char *)xmalloc (1 + cp - arg);
+        memcpy (databaseNames[num_databaseNames], arg, cp - arg);
+        databaseNames[num_databaseNames][cp - arg] = '\0';
+
+        for (cp1 = databaseNames[num_databaseNames]; *cp1 ; cp1++)
+            if (*cp1 == '+')
+                *cp1 = ' ';
+        num_databaseNames++;
+
+        if (!*cp)
+            break;
+        arg = cp+1;
+    }
+    if (num_databaseNames == 0)
+    {
+        num_databaseNames = 1;
+        databaseNames[0] = xstrdup("");
+    }
+    return 1;
+}
+
+static int cmd_base(const char *arg)
+{
+    if (!*arg)
+    {
+        printf("Usage: base <database> <database> ...\n");
+        return 0;
+    }
+    return set_base(arg);
+}
+
+void cmd_open_remember_last_open_command(const char* arg, char* new_open_command)
+{
+    if(last_open_command != arg) 
+    {
+        if(last_open_command) xfree(last_open_command);
+        last_open_command = xstrdup(new_open_command);
+    }
+}
+
+int session_connect(const char *arg)
+{
+    void *add;
+    char type_and_host[101];
+    const char *basep = 0;
+#if HAVE_OPENSSL_SSL_H
+    SSL *ssl;
+#endif
+    if (conn)
+    {
+        cs_close (conn);
+        conn = NULL;
+        if (session_mem)
+        {
+            nmem_destroy (session_mem);
+            session_mem = NULL;
+        }
+    }   
+    cs_get_host_args(arg, &basep);
+
+    strncpy(type_and_host, arg, sizeof(type_and_host)-1);
+    type_and_host[sizeof(type_and_host)-1] = '\0';
+
+    cmd_open_remember_last_open_command(arg, type_and_host);
+
+    if (yazProxy)
+        conn = cs_create_host(yazProxy, 1, &add);
+    else
+        conn = cs_create_host(arg, 1, &add);
+    if (!conn)
+    {
+        printf ("Couldn't create comstack\n");
+        return 0;
+    }
+#if HAVE_XML2
+    if (conn->protocol == PROTO_HTTP)
+	queryType = QueryType_CQL;
+#else
+    if (conn->protocol == PROTO_HTTP)
+    {
+        printf ("SRW/HTTP not enabled in this YAZ\n");
+        cs_close(conn);
+        conn = 0;
+        return 0;
+    }
+#endif
+    protocol = conn->protocol;
+    if (conn->protocol == PROTO_HTTP)
+        set_base("");
+    else
+        set_base("Default");
+    /*intf("Connecting...");*/
+    fflush(stdout);
+    if (cs_connect(conn, add) < 0)
+    {
+        printf ("error = %s\n", cs_strerror(conn));
+        if (conn->cerrno == CSYSERR)
+	{
+	    char msg[256];
+	    yaz_strerror(msg, sizeof(msg));
+	    printf ("%s\n", msg);
+	}
+        cs_close(conn);
+        conn = 0;
+        return 0;
+    }
+    /*intf("OK.\n");*/
+#if HAVE_OPENSSL_SSL_H
+    if ((ssl = (SSL *) cs_get_ssl(conn)))
+    {
+	X509 *server_cert = SSL_get_peer_certificate (ssl);
+
+	if (server_cert)
+	{
+	    char *pem_buf;
+	    int pem_len;
+	    BIO *bio = BIO_new(BIO_s_mem());
+
+	    /* get PEM buffer in memory */
+	    PEM_write_bio_X509(bio, server_cert);
+	    pem_len = BIO_get_mem_data(bio, &pem_buf);
+	    fwrite(pem_buf, pem_len, 1, stdout);
+	
+	    /* print all info on screen .. */
+	    X509_print_fp(stdout, server_cert);
+	    BIO_free(bio);
+
+	    X509_free (server_cert);
+	}
+    }
+#endif
+    if (basep && *basep)
+        set_base (basep);
+    if (protocol == PROTO_Z3950)
+    {
+        send_initRequest(type_and_host);
+        return 2;
+    }
+    return 0;
+}
+
+static int cmd_open(const char *arg)
+{
+    if (arg)
+    {
+        strncpy (cur_host, arg, sizeof(cur_host)-1);
+        cur_host[sizeof(cur_host)-1] = 0;
+    }
+    return session_connect(cur_host);
+}
+
+int z_cmd_open(char *host_and_port, char *base)
+{
+    char * full_command = (char *) xmalloc (strlen(host_and_port)+strlen(base)+6);
+    strcpy(full_command, "tcp:");
+    strcat(full_command, host_and_port);
+    strcat(full_command, "/");
+    strcat(full_command, base);
+    return cmd_open(full_command);
+}
+
+
+void try_reconnect() 
+{
+    char* open_command;
+	
+    if(!( auto_reconnect && last_open_command) ) return ;
+
+    open_command = (char *) xmalloc (strlen(last_open_command)+6);
+    strcpy (open_command, "open ");
+	
+    strcat (open_command, last_open_command);
+
+    process_cmd_line(open_command);
+	
+    xfree(open_command);				
+}
+
+int cmd_authentication(const char *arg)
+{
+    static Z_IdAuthentication au;
+    static char user[40], group[40], pass[40];
+    static Z_IdPass idPass;
+    int r;
+
+    if (!*arg)
+    {
+        printf("Auth field set to null\n");
+        auth = 0;
+        return 1;
+    }
+    r = sscanf (arg, "%39s %39s %39s", user, group, pass);
+    if (r == 0)
+    {
+        printf("Authentication set to null\n");
+        auth = 0;
+    }
+    if (r == 1)
+    {
+        auth = &au;
+	if (!strcmp(user, "-")) {
+	    au.which = Z_IdAuthentication_anonymous;
+	    printf("Authentication set to Anonymous\n");
+	} else {
+	    au.which = Z_IdAuthentication_open;
+	    au.u.open = user;
+	    printf("Authentication set to Open (%s)\n", user);
+	}
+    }
+    if (r == 2)
+    {
+        auth = &au;
+        au.which = Z_IdAuthentication_idPass;
+        au.u.idPass = &idPass;
+        idPass.groupId = NULL;
+        idPass.userId = user;
+        idPass.password = group;
+	printf("Authentication set to User (%s), Pass (%s)\n", user, group);
+    }
+    if (r == 3)
+    {
+        auth = &au;
+        au.which = Z_IdAuthentication_idPass;
+        au.u.idPass = &idPass;
+        idPass.groupId = group;
+        idPass.userId = user;
+        idPass.password = pass;
+	printf("Authentication set to User (%s), Group (%s), Pass (%s)\n",
+	       user, group, pass);
+    }
+    return 1;
+}
+
+/* SEARCH SERVICE ------------------------------ */
+static void display_record(Z_External *r);
+
+static void print_record(const unsigned char *buf, size_t len)
+{
+    size_t i = len;
+    print_stringn (buf, len);
+    /* add newline if not already added ... */
+    if (i <= 0 || buf[i-1] != '\n')
+        printf ("\n");
+}
+
+static void display_record(Z_External *r)
+{
+    oident *ent = oid_getentbyoid(r->direct_reference);
+
+    record_last = r;
+    /*
+     * Tell the user what we got.
+     */
+    if (r->direct_reference)
+    {
+        printf("Record type: ");
+        if (ent)
+            printf("%s\n", ent->desc);
+        else if (!odr_oid(print, &r->direct_reference, 0, 0))
+        {
+            odr_perror(print, "print oid");
+            odr_reset(print);
+        }
+    }
+    /* Check if this is a known, ASN.1 type tucked away in an octet string */
+    if (ent && r->which == Z_External_octet)
+    {
+        Z_ext_typeent *type = z_ext_getentbyref(ent->value);
+        char *rr;
+
+        if (type)
+        {
+            /*
+             * Call the given decoder to process the record.
+             */
+            odr_setbuf(in, (char*)r->u.octet_aligned->buf,
+                r->u.octet_aligned->len, 0);
+            if (!(*type->fun)(in, &rr, 0, 0))
+            {
+                odr_perror(in, "Decoding constructed record.");
+                fprintf(stdout, "[Near %d]\n", odr_offset(in));
+                fprintf(stdout, "Packet dump:\n---------\n");
+                odr_dumpBER(stdout, (char*)r->u.octet_aligned->buf,
+                            r->u.octet_aligned->len);
+                fprintf(stdout, "---------\n");
+                
+		/* note just ignores the error ant print the bytes form the octet_aligned later */
+            } else {
+                /*
+                 * Note: we throw away the original, BER-encoded record here.
+                 * Do something else with it if you want to keep it.
+                 */
+                r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */
+                r->which = type->what;
+            }
+        }
+    }
+    if (ent && ent->value == VAL_SOIF)
+    {
+        print_record((const unsigned char *) r->u.octet_aligned->buf,
+                     r->u.octet_aligned->len);
+        if (marc_file)
+            fwrite (r->u.octet_aligned->buf, 1, r->u.octet_aligned->len, marc_file);
+    }
+    else if (r->which == Z_External_octet)
+    {
+        const char *octet_buf = (char*)r->u.octet_aligned->buf;
+        if (ent->oclass == CLASS_RECSYN && 
+		(ent->value == VAL_TEXT_XML || 
+		 ent->value == VAL_APPLICATION_XML ||
+		 ent->value == VAL_HTML))
+        {
+            print_record((const unsigned char *) octet_buf,
+                         r->u.octet_aligned->len);
+        }
+        else if (ent->value == VAL_POSTSCRIPT)
+        {
+            int size = r->u.octet_aligned->len;
+            if (size > 100)
+                size = 100;
+            print_record((const unsigned char *) octet_buf, size);
+        }
+        else
+        {
+            if ( 
+#if AVOID_MARC_DECODE
+                /* primitive check for a marc OID 5.1-29 except 16 */
+                ent->oidsuffix[0] == 5 && ent->oidsuffix[1] < 30 &&
+                ent->oidsuffix[1] != 16
+#else
+                1
+#endif
+                )
+            {
+                char *result;
+                int rlen;
+                yaz_iconv_t cd = 0;
+                yaz_marc_t mt = yaz_marc_create();
+                    
+                if (yaz_marc_decode_buf(mt, octet_buf,r->u.octet_aligned->len,
+                                        &result, &rlen)> 0)
+                {
+                    char *from = 0;
+                    if (marcCharset && !strcmp(marcCharset, "auto"))
+                    {
+                        if (ent->value == VAL_USMARC)
+                        {
+                            if (octet_buf[9] == 'a')
+                                from = "UTF-8";
+                            else
+                                from = "MARC-8";
+                        }
+                        else
+                            from = "ISO-8859-1";
+                    }
+		    else if (marcCharset)
+			from = marcCharset;
+                    if (outputCharset && from)
+                    {   
+                        cd = yaz_iconv_open(outputCharset, from);
+                        printf ("convert from %s to %s", from, 
+                                outputCharset);
+			if (!cd)
+			    printf (" unsupported\n");
+			else
+			    printf ("\n");
+                    }
+                    if (!cd)
+                        fwrite (result, 1, rlen, stdout);
+                    else
+                    {
+                        char outbuf[6];
+                        size_t inbytesleft = rlen;
+                        const char *inp = result;
+                        
+                        while (inbytesleft)
+                        {
+                            size_t outbytesleft = sizeof(outbuf);
+                            char *outp = outbuf;
+			    size_t r;
+
+                            r = yaz_iconv (cd, (char**) &inp,
+					   &inbytesleft, 
+					   &outp, &outbytesleft);
+                            if (r == (size_t) (-1))
+                            {
+                                int e = yaz_iconv_error(cd);
+                                if (e != YAZ_ICONV_E2BIG)
+                                    break;
+                            }
+                            fwrite (outbuf, outp - outbuf, 1, stdout);
+                        }
+                    }
+                }
+		else
+                {
+                    printf ("bad MARC. Dumping as it is:\n");
+                    print_record((const unsigned char*) octet_buf,
+                                  r->u.octet_aligned->len);
+		}	
+                yaz_marc_destroy(mt);
+                if (cd)
+                    yaz_iconv_close(cd);
+            }
+            else
+            {
+                print_record((const unsigned char*) octet_buf,
+                             r->u.octet_aligned->len);
+            }
+        }
+        if (marc_file)
+            fwrite (octet_buf, 1, r->u.octet_aligned->len, marc_file);
+    }
+    else if (ent && ent->value == VAL_SUTRS)
+    {
+        if (r->which != Z_External_sutrs)
+        {
+            printf("Expecting single SUTRS type for SUTRS.\n");
+            return;
+        }
+        print_record(r->u.sutrs->buf, r->u.sutrs->len);
+        if (marc_file)
+            fwrite (r->u.sutrs->buf, 1, r->u.sutrs->len, marc_file);
+    }
+    else if (ent && ent->value == VAL_GRS1)
+    {
+        WRBUF w;
+        if (r->which != Z_External_grs1)
+        {
+            printf("Expecting single GRS type for GRS.\n");
+            return;
+        }
+        w = wrbuf_alloc();
+        yaz_display_grs1(w, r->u.grs1, 0);
+        puts (wrbuf_buf(w));
+        wrbuf_free(w, 1);
+    }
+    else if (ent && ent->value == VAL_OPAC)
+    {
+	int i;
+	if (r->u.opac->bibliographicRecord)
+	    display_record(r->u.opac->bibliographicRecord);
+	for (i = 0; i<r->u.opac->num_holdingsData; i++)
+	{
+	    Z_HoldingsRecord *h = r->u.opac->holdingsData[i];
+	    if (h->which == Z_HoldingsRecord_marcHoldingsRecord)
+	    {
+		printf ("MARC holdings %d\n", i);
+		display_record(h->u.marcHoldingsRecord);
+	    }
+	    else if (h->which == Z_HoldingsRecord_holdingsAndCirc)
+	    {
+		int j;
+
+		Z_HoldingsAndCircData *data = h->u.holdingsAndCirc;
+
+		printf ("Data holdings %d\n", i);
+		if (data->typeOfRecord)
+		    printf ("typeOfRecord: %s\n", data->typeOfRecord);
+		if (data->encodingLevel)
+		    printf ("encodingLevel: %s\n", data->encodingLevel);
+		if (data->receiptAcqStatus)
+		    printf ("receiptAcqStatus: %s\n", data->receiptAcqStatus);
+		if (data->generalRetention)
+		    printf ("generalRetention: %s\n", data->generalRetention);
+		if (data->completeness)
+		    printf ("completeness: %s\n", data->completeness);
+		if (data->dateOfReport)
+		    printf ("dateOfReport: %s\n", data->dateOfReport);
+		if (data->nucCode)
+		    printf ("nucCode: %s\n", data->nucCode);
+		if (data->localLocation)
+		    printf ("localLocation: %s\n", data->localLocation);
+		if (data->shelvingLocation)
+		    printf ("shelvingLocation: %s\n", data->shelvingLocation);
+		if (data->callNumber)
+		    printf ("callNumber: %s\n", data->callNumber);
+		if (data->shelvingData)
+		    printf ("shelvingData: %s\n", data->shelvingData);
+		if (data->copyNumber)
+		    printf ("copyNumber: %s\n", data->copyNumber);
+		if (data->publicNote)
+		    printf ("publicNote: %s\n", data->publicNote);
+		if (data->reproductionNote)
+		    printf ("reproductionNote: %s\n", data->reproductionNote);
+		if (data->termsUseRepro)
+		    printf ("termsUseRepro: %s\n", data->termsUseRepro);
+		if (data->enumAndChron)
+		    printf ("enumAndChron: %s\n", data->enumAndChron);
+		for (j = 0; j<data->num_volumes; j++)
+		{
+		    printf ("volume %d\n", j);
+		    if (data->volumes[j]->enumeration)
+			printf (" enumeration: %s\n",
+				data->volumes[j]->enumeration);
+		    if (data->volumes[j]->chronology)
+			printf (" chronology: %s\n",
+				data->volumes[j]->chronology);
+		    if (data->volumes[j]->enumAndChron)
+			printf (" enumAndChron: %s\n",
+				data->volumes[j]->enumAndChron);
+		}
+		for (j = 0; j<data->num_circulationData; j++)
+		{
+		    printf ("circulation %d\n", j);
+		    if (data->circulationData[j]->availableNow)
+			printf (" availableNow: %d\n",
+				*data->circulationData[j]->availableNow);
+		    if (data->circulationData[j]->availablityDate)
+			printf (" availabiltyDate: %s\n",
+				data->circulationData[j]->availablityDate);
+		    if (data->circulationData[j]->availableThru)
+			printf (" availableThru: %s\n",
+				data->circulationData[j]->availableThru);
+		    if (data->circulationData[j]->restrictions)
+			printf (" restrictions: %s\n",
+				data->circulationData[j]->restrictions);
+		    if (data->circulationData[j]->itemId)
+			printf (" itemId: %s\n",
+				data->circulationData[j]->itemId);
+		    if (data->circulationData[j]->renewable)
+			printf (" renewable: %d\n",
+				*data->circulationData[j]->renewable);
+		    if (data->circulationData[j]->onHold)
+			printf (" onHold: %d\n",
+				*data->circulationData[j]->onHold);
+		    if (data->circulationData[j]->enumAndChron)
+			printf (" enumAndChron: %s\n",
+				data->circulationData[j]->enumAndChron);
+		    if (data->circulationData[j]->midspine)
+			printf (" midspine: %s\n",
+				data->circulationData[j]->midspine);
+		    if (data->circulationData[j]->temporaryLocation)
+			printf (" temporaryLocation: %s\n",
+				data->circulationData[j]->temporaryLocation);
+		}
+	    }
+	}
+    }
+    else 
+    {
+        printf("Unknown record representation.\n");
+        if (!z_External(print, &r, 0, 0))
+        {
+            odr_perror(print, "Printing external");
+            odr_reset(print);
+        }
+    }
+}
+
+static void display_diagrecs(Z_DiagRec **pp, int num)
+{
+    int i;
+    oident *ent;
+    Z_DefaultDiagFormat *r;
+
+    printf("Diagnostic message(s) from database:\n");
+    for (i = 0; i<num; i++)
+    {
+        Z_DiagRec *p = pp[i];
+        if (p->which != Z_DiagRec_defaultFormat)
+        {
+            printf("Diagnostic record not in default format.\n");
+            return;
+        }
+        else
+            r = p->u.defaultFormat;
+        if (!(ent = oid_getentbyoid(r->diagnosticSetId)) ||
+            ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1)
+            printf("Missing or unknown diagset\n");
+        printf("    [%d] %s", *r->condition, diagbib1_str(*r->condition));
+        switch (r->which)
+        {
+        case Z_DefaultDiagFormat_v2Addinfo:
+            printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo);
+            break;
+        case Z_DefaultDiagFormat_v3Addinfo:
+            printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo);
+            break;
+        }
+    }
+}
+
+
+static void display_nameplusrecord(Z_NamePlusRecord *p)
+{
+    if (p->databaseName)
+        printf("[%s]", p->databaseName);
+    if (p->which == Z_NamePlusRecord_surrogateDiagnostic)
+        display_diagrecs(&p->u.surrogateDiagnostic, 1);
+    else if (p->which == Z_NamePlusRecord_databaseRecord)
+        display_record(p->u.databaseRecord);
+}
+
+static void display_records(Z_Records *p)
+{
+    int i;
+
+    if (p->which == Z_Records_NSD)
+    {
+        Z_DiagRec dr, *dr_p = &dr;
+        dr.which = Z_DiagRec_defaultFormat;
+        dr.u.defaultFormat = p->u.nonSurrogateDiagnostic;
+        display_diagrecs (&dr_p, 1);
+    }
+    else if (p->which == Z_Records_multipleNSD)
+        display_diagrecs (p->u.multipleNonSurDiagnostics->diagRecs,
+                          p->u.multipleNonSurDiagnostics->num_diagRecs);
+    else 
+    {
+        printf("Records: %d\n", p->u.databaseOrSurDiagnostics->num_records);
+        for (i = 0; i < p->u.databaseOrSurDiagnostics->num_records; i++)
+            display_nameplusrecord(p->u.databaseOrSurDiagnostics->records[i]);
+    }
+}
+
+static int send_deleteResultSetRequest(const char *arg)
+{
+    char names[8][32];
+    int i;
+
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest);
+    Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest;
+
+    req->referenceId = set_refid (out);
+
+    req->num_resultSetList =
+        sscanf (arg, "%30s %30s %30s %30s %30s %30s %30s %30s",
+                names[0], names[1], names[2], names[3],
+                names[4], names[5], names[6], names[7]);
+
+    req->deleteFunction = (int *)
+        odr_malloc (out, sizeof(*req->deleteFunction));
+    if (req->num_resultSetList > 0)
+    {
+        *req->deleteFunction = Z_DeleteResultSetRequest_list;
+        req->resultSetList = (char **)
+            odr_malloc (out, sizeof(*req->resultSetList)*
+                        req->num_resultSetList);
+        for (i = 0; i<req->num_resultSetList; i++)
+            req->resultSetList[i] = names[i];
+    }
+    else
+    {
+        *req->deleteFunction = Z_DeleteResultSetRequest_all;
+        req->resultSetList = 0;
+    }
+    
+    send_apdu(apdu);
+    printf("Sent deleteResultSetRequest.\n");
+    return 2;
+}
+
+#if HAVE_XML2
+static int send_srw(Z_SRW_PDU *sr)
+{
+    const char *charset = negotiationCharset;
+    const char *host_port = cur_host;
+    char *path = 0;
+    char ctype[50];
+    Z_SOAP_Handler h[2] = {
+        {"http://www.loc.gov/zing/srw/", 0, (Z_SOAP_fun) yaz_srw_codec},
+        {0, 0, 0}
+    };
+    ODR o = odr_createmem(ODR_ENCODE);
+    int ret;
+    Z_SOAP *p = odr_malloc(o, sizeof(*p));
+    Z_GDU *gdu;
+
+    path = odr_malloc(out, strlen(databaseNames[0])+2);
+    *path = '/';
+    strcpy(path+1, databaseNames[0]);
+
+    gdu = z_get_HTTP_Request(out);
+    gdu->u.HTTP_Request->version = http_version;
+    gdu->u.HTTP_Request->path = odr_strdup(out, path);
+
+    if (host_port)
+    {
+        const char *cp0 = strstr(host_port, "://");
+        const char *cp1 = 0;
+        if (cp0)
+            cp0 = cp0+3;
+        else
+            cp0 = host_port;
+
+        cp1 = strchr(cp0, '/');
+        if (!cp1)
+            cp1 = cp0+strlen(cp0);
+
+        if (cp0 && cp1)
+        {
+            char *h = odr_malloc(out, cp1 - cp0 + 1);
+            memcpy (h, cp0, cp1 - cp0);
+            h[cp1-cp0] = '\0';
+            z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers,
+                              "Host", h);
+        }
+    }
+
+    strcpy(ctype, "text/xml");
+    if (charset && strlen(charset) < 20)
+    {
+        strcat(ctype, "; charset=");
+        strcat(ctype, charset);
+    }
+    z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers,
+                      "Content-Type", ctype);
+    z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers,
+                      "SOAPAction", "\"\"");
+    p->which = Z_SOAP_generic;
+    p->u.generic = odr_malloc(o, sizeof(*p->u.generic));
+    p->u.generic->no = 0;
+    p->u.generic->ns = 0;
+    p->u.generic->p = sr;
+    p->ns = "http://schemas.xmlsoap.org/soap/envelope/";
+
+    ret = z_soap_codec_enc(o, &p,
+                           &gdu->u.HTTP_Request->content_buf,
+                           &gdu->u.HTTP_Request->content_len, h,
+                           charset);
+
+    if (z_GDU(out, &gdu, 0, 0))
+    {
+        /* encode OK */
+        char *buf_out;
+        int len_out;
+        int r;
+	if (apdu_file)
+	{
+	    if (!z_GDU(print, &gdu, 0, 0))
+		printf ("Failed to print outgoing APDU\n");
+	    odr_reset(print);
+	}
+        buf_out = odr_getbuf(out, &len_out, 0);
+        
+        /* we don't odr_reset(out), since we may need the buffer again */
+
+	do_hex_dump(buf_out, len_out);
+
+        r = cs_put(conn, buf_out, len_out);
+
+        odr_destroy(o);
+        
+        if (r >= 0)
+            return 2;
+    }
+    return 0;
+}
+#endif
+
+#if HAVE_XML2
+static int send_SRW_scanRequest(const char *arg, int pos, int num)
+{
+    Z_SRW_PDU *sr = 0;
+    
+    /* regular requestse .. */
+    sr = yaz_srw_get(out, Z_SRW_scan_request);
+
+    switch(queryType)
+    {
+    case QueryType_CQL:
+	sr->u.scan_request->query_type = Z_SRW_query_type_cql;
+	sr->u.scan_request->scanClause.cql = odr_strdup(out, arg);
+	break;
+    case QueryType_Prefix:
+	sr->u.scan_request->query_type = Z_SRW_query_type_pqf;
+	sr->u.scan_request->scanClause.pqf = odr_strdup(out, arg);
+	break;
+    default:
+	printf ("Only CQL and PQF supported in SRW\n");
+	return 0;
+    }
+    sr->u.scan_request->responsePosition = odr_intdup(out, pos);
+    sr->u.scan_request->maximumTerms = odr_intdup(out, num);
+    return send_srw(sr);
+}
+
+static int send_SRW_searchRequest(const char *arg)
+{
+    Z_SRW_PDU *sr = 0;
+    
+    if (!srw_sr)
+    {
+        assert(srw_sr_odr_out == 0);
+        srw_sr_odr_out = odr_createmem(ODR_ENCODE);
+    }
+    odr_reset(srw_sr_odr_out);
+
+    setno = 1;
+
+    /* save this for later .. when fetching individual records */
+    srw_sr =  yaz_srw_get(srw_sr_odr_out, Z_SRW_searchRetrieve_request);
+    
+    /* regular request .. */
+    sr = yaz_srw_get(out, Z_SRW_searchRetrieve_request);
+
+    switch(queryType)
+    {
+    case QueryType_CQL:
+	srw_sr->u.request->query_type = Z_SRW_query_type_cql;
+	srw_sr->u.request->query.cql = odr_strdup(srw_sr_odr_out, arg);
+
+	sr->u.request->query_type = Z_SRW_query_type_cql;
+	sr->u.request->query.cql = odr_strdup(out, arg);
+	break;
+    case QueryType_Prefix:
+	srw_sr->u.request->query_type = Z_SRW_query_type_pqf;
+	srw_sr->u.request->query.pqf = odr_strdup(srw_sr_odr_out, arg);
+
+	sr->u.request->query_type = Z_SRW_query_type_pqf;
+	sr->u.request->query.pqf = odr_strdup(out, arg);
+	break;
+    default:
+	printf ("Only CQL and PQF supported in SRW\n");
+	return 0;
+    }
+    sr->u.request->maximumRecords = odr_intdup(out, 0);
+
+    if (record_schema)
+        sr->u.request->recordSchema = record_schema;
+    if (recordsyntax == VAL_TEXT_XML)
+        sr->u.explain_request->recordPacking = "xml";
+    return send_srw(sr);
+}
+#endif
+
+static int send_searchRequest(const char *arg)
+{
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_searchRequest);
+    Z_SearchRequest *req = apdu->u.searchRequest;
+    Z_Query query;
+    struct ccl_rpn_node *rpn = NULL;
+    int error, pos;
+    char setstring[100];
+    Z_RPNQuery *RPNquery;
+    Odr_oct ccl_query;
+    YAZ_PQF_Parser pqf_parser;
+    Z_External *ext;
+    QueryType myQueryType = queryType;
+    char pqfbuf[512];
+
+    if (myQueryType == QueryType_CCL2RPN)
+    {
+        rpn = ccl_find_str(bibset, arg, &error, &pos);
+        if (error)
+        {
+            printf("CCL ERROR: %s\n", ccl_err_msg(error));
+            return 0;
+        }
+    } else if (myQueryType == QueryType_CQL2RPN) {
+	/* ### All this code should be wrapped in a utility function */
+	CQL_parser parser;
+	struct cql_node *node;
+	const char *addinfo;
+	if (cqltrans == 0) {
+            printf("Can't use CQL: no translation file.  Try set_cqlfile\n");
+	    return 0;
+	}
+	parser = cql_parser_create();
+	if ((error = cql_parser_string(parser, arg)) != 0) {
+            printf("Can't parse CQL: must be a syntax error\n");
+            return 0;
+	}
+	node = cql_parser_result(parser);
+	if ((error = cql_transform_buf(cqltrans, node, pqfbuf,
+				       sizeof pqfbuf)) != 0) {
+	    error = cql_transform_error(cqltrans, &addinfo);
+	    printf ("Can't convert CQL to PQF: %s (addinfo=%s)\n",
+		    cql_strerror(error), addinfo);
+            return 0;
+        }
+	arg = pqfbuf;
+	myQueryType = QueryType_Prefix;
+    }
+
+    req->referenceId = set_refid (out);
+    if (!strcmp(arg, "@big")) /* strictly for troublemaking */
+    {
+        static unsigned char big[2100];
+        static Odr_oct bigo;
+
+        /* send a very big referenceid to test transport stack etc. */
+        memset(big, 'A', 2100);
+        bigo.len = bigo.size = 2100;
+        bigo.buf = big;
+        req->referenceId = &bigo;
+    }
+    
+    if (setnumber >= 0)
+    {
+        sprintf(setstring, "%d", ++setnumber);
+        req->resultSetName = setstring;
+    }
+    *req->smallSetUpperBound = smallSetUpperBound;
+    *req->largeSetLowerBound = largeSetLowerBound;
+    *req->mediumSetPresentNumber = mediumSetPresentNumber;
+    if (smallSetUpperBound > 0 || (largeSetLowerBound > 1 &&
+        mediumSetPresentNumber > 0))
+    {
+        req->preferredRecordSyntax =
+            yaz_oidval_to_z3950oid(out, CLASS_RECSYN, recordsyntax);
+
+        req->smallSetElementSetNames =
+            req->mediumSetElementSetNames = elementSetNames;
+    }
+    req->num_databaseNames = num_databaseNames;
+    req->databaseNames = databaseNames;
+
+    req->query = &query;
+
+    switch (myQueryType)
+    {
+    case QueryType_Prefix:
+        query.which = Z_Query_type_1;
+        pqf_parser = yaz_pqf_create ();
+        RPNquery = yaz_pqf_parse (pqf_parser, out, arg);
+        if (!RPNquery)
+        {
+            const char *pqf_msg;
+            size_t off;
+            int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
+            printf("%*s^\n", off+4, "");
+            printf("Prefix query error: %s (code %d)\n", pqf_msg, code);
+            
+            yaz_pqf_destroy (pqf_parser);
+            return 0;
+        }
+        yaz_pqf_destroy (pqf_parser);
+        query.u.type_1 = RPNquery;
+        break;
+    case QueryType_CCL:
+        query.which = Z_Query_type_2;
+        query.u.type_2 = &ccl_query;
+        ccl_query.buf = (unsigned char*) arg;
+        ccl_query.len = strlen(arg);
+        break;
+    case QueryType_CCL2RPN:
+        query.which = Z_Query_type_1;
+        RPNquery = ccl_rpn_query(out, rpn);
+        if (!RPNquery)
+        {
+            printf ("Couldn't convert from CCL to RPN\n");
+            return 0;
+        }
+        query.u.type_1 = RPNquery;
+        ccl_rpn_delete (rpn);
+        break;
+    case QueryType_CQL:
+        query.which = Z_Query_type_104;
+        ext = (Z_External *) odr_malloc(out, sizeof(*ext));
+        ext->direct_reference = odr_getoidbystr(out, "1.2.840.10003.16.2");
+        ext->indirect_reference = 0;
+        ext->descriptor = 0;
+        ext->which = Z_External_CQL;
+        ext->u.cql = odr_strdup(out, arg);
+        query.u.type_104 =  ext;
+        break;
+    default:
+        printf ("Unsupported query type\n");
+        return 0;
+    }
+    send_apdu(apdu);
+    /*
+    if (send_apdu(apdu))
+    printf("Sent searchRequest.\n");*/
+    setno = 1;
+    return 2;
+}
+
+/* display Query Expression as part of searchResult-1 */
+/*
+static void display_queryExpression (Z_QueryExpression *qe)
+{
+    if (!qe)
+        return;
+    if (qe->which == Z_QueryExpression_term)
+    {
+        if (qe->u.term->queryTerm)
+        {
+            Z_Term *term = qe->u.term->queryTerm;
+            switch (term->which)
+            {
+            case Z_Term_general:
+                printf (" %.*s", term->u.general->len, term->u.general->buf);
+                break;
+            case Z_Term_characterString:
+                printf (" %s", term->u.characterString);
+                break;
+            case Z_Term_numeric:
+                printf (" %d", *term->u.numeric);
+                break;
+            case Z_Term_null:
+                printf (" null");
+                break;
+            }
+        }
+    }
+}
+*/
+/* see if we can find USR:SearchResult-1 */
+/*
+static void display_searchResult (Z_OtherInformation *o)
+{
+    int i;
+    if (!o)
+        return ;
+    for (i = 0; i < o->num_elements; i++)
+    {
+        if (o->list[i]->which == Z_OtherInfo_externallyDefinedInfo)
+        {
+            Z_External *ext = o->list[i]->information.externallyDefinedInfo;
+            
+            if (ext->which == Z_External_searchResult1)
+            {
+                int j;
+                Z_SearchInfoReport *sr = ext->u.searchResult1;
+                printf ("SearchResult-1:");
+                for (j = 0; j < sr->num; j++)
+                {
+		if (!sr->elements[j]->subqueryExpression)
+                        printf (" %d", j);
+                    display_queryExpression (
+                        sr->elements[j]->subqueryExpression);
+                    display_queryExpression (
+                        sr->elements[j]->subqueryInterpretation);
+                    display_queryExpression (
+                        sr->elements[j]->subqueryRecommendation);
+                    if (sr->elements[j]->subqueryCount)
+                        printf ("(%d)", *sr->elements[j]->subqueryCount);
+                }
+                printf ("\n");
+            }
+        }
+    }
+}
+*/
+/* kjdon: modified to not print the results, and return the number of hits */
+static int process_searchResponse(Z_SearchResponse *res)
+{
+    print_refid (res->referenceId);
+    if (!(*res->searchStatus)) {
+      /* this should return an error instead of 0 docs found... one day... */
+	return 0;
+    }
+    setno += *res->numberOfRecordsReturned;
+    /* what is this for? */
+    if (res->records)
+        display_records(res->records);
+    return *res->resultCount;
+
+}
+
+static void print_level(int iLevel)
+{
+    int i;
+    for (i = 0; i < iLevel * 4; i++)
+        printf(" ");
+}
+
+static void print_int(int iLevel, const char *pTag, int *pInt)
+{
+    if (pInt != NULL)
+    {
+        print_level(iLevel);
+        printf("%s: %d\n", pTag, *pInt);
+    }
+}
+
+static void print_string(int iLevel, const char *pTag, const char *pString)
+{
+    if (pString != NULL)
+    {
+        print_level(iLevel);
+        printf("%s: %s\n", pTag, pString);
+    }
+}
+
+static void print_oid(int iLevel, const char *pTag, Odr_oid *pOid)
+{
+    if (pOid != NULL)
+    {
+        int *pInt = pOid;
+
+        print_level(iLevel);
+        printf("%s:", pTag);
+        for (; *pInt != -1; pInt++)
+            printf(" %d", *pInt);
+        printf("\n");
+    }
+}
+
+static void print_referenceId(int iLevel, Z_ReferenceId *referenceId)
+{
+    if (referenceId != NULL)
+    {
+        int i;
+
+        print_level(iLevel);
+        printf("Ref Id (%d, %d): ", referenceId->len, referenceId->size);
+        for (i = 0; i < referenceId->len; i++)
+            printf("%c", referenceId->buf[i]);
+        printf("\n");
+    }
+}
+
+static void print_string_or_numeric(int iLevel, const char *pTag, Z_StringOrNumeric *pStringNumeric)
+{
+    if (pStringNumeric != NULL)
+    {
+        switch (pStringNumeric->which)
+        {
+        case Z_StringOrNumeric_string:
+            print_string(iLevel, pTag, pStringNumeric->u.string);
+            break;
+            
+        case Z_StringOrNumeric_numeric:
+            print_int(iLevel, pTag, pStringNumeric->u.numeric);
+            break;
+            
+        default:
+            print_level(iLevel);
+            printf("%s: valid type for Z_StringOrNumeric\n", pTag);
+            break;
+        }
+    }
+}
+
+static void print_universe_report_duplicate(
+    int iLevel,
+    Z_UniverseReportDuplicate *pUniverseReportDuplicate)
+{
+    if (pUniverseReportDuplicate != NULL)
+    {
+        print_level(iLevel);
+        printf("Universe Report Duplicate: \n");
+        iLevel++;
+        print_string_or_numeric(iLevel, "Hit No",
+                                pUniverseReportDuplicate->hitno);
+    }
+}
+
+static void print_universe_report_hits(
+    int iLevel,
+    Z_UniverseReportHits *pUniverseReportHits)
+{
+    if (pUniverseReportHits != NULL)
+    {
+        print_level(iLevel);
+        printf("Universe Report Hits: \n");
+        iLevel++;
+        print_string_or_numeric(iLevel, "Database",
+                                pUniverseReportHits->database);
+        print_string_or_numeric(iLevel, "Hits", pUniverseReportHits->hits);
+    }
+}
+
+static void print_universe_report(int iLevel, Z_UniverseReport *pUniverseReport)
+{
+    if (pUniverseReport != NULL)
+    {
+        print_level(iLevel);
+        printf("Universe Report: \n");
+        iLevel++;
+        print_int(iLevel, "Total Hits", pUniverseReport->totalHits);
+        switch (pUniverseReport->which)
+        {
+        case Z_UniverseReport_databaseHits:
+            print_universe_report_hits(iLevel,
+                                       pUniverseReport->u.databaseHits);
+            break;
+            
+        case Z_UniverseReport_duplicate:
+            print_universe_report_duplicate(iLevel,
+                                            pUniverseReport->u.duplicate);
+            break;
+            
+        default:
+            print_level(iLevel);
+            printf("Type: %d\n", pUniverseReport->which);
+            break;
+        }
+    }
+}
+
+static void print_external(int iLevel, Z_External *pExternal)
+{
+    if (pExternal != NULL)
+    {
+        print_level(iLevel);
+        printf("External: \n");
+        iLevel++;
+        print_oid(iLevel, "Direct Reference", pExternal->direct_reference);
+        print_int(iLevel, "InDirect Reference", pExternal->indirect_reference);
+        print_string(iLevel, "Descriptor", pExternal->descriptor);
+        switch (pExternal->which)
+        {
+        case Z_External_universeReport:
+            print_universe_report(iLevel, pExternal->u.universeReport);
+            break;
+            
+        default:
+            print_level(iLevel);
+            printf("Type: %d\n", pExternal->which);
+            break;
+        }
+    }
+}
+
+static int process_resourceControlRequest (Z_ResourceControlRequest *req)
+{
+    printf ("Received ResourceControlRequest.\n");
+    print_referenceId(1, req->referenceId);
+    print_int(1, "Suspended Flag", req->suspendedFlag);
+    print_int(1, "Partial Results Available", req->partialResultsAvailable);
+    print_int(1, "Response Required", req->responseRequired);
+    print_int(1, "Triggered Request Flag", req->triggeredRequestFlag);
+    print_external(1, req->resourceReport);
+    return 0;
+}
+
+void process_ESResponse(Z_ExtendedServicesResponse *res)
+{
+    printf("Status: ");
+    switch (*res->operationStatus)
+    {
+    case Z_ExtendedServicesResponse_done:
+        printf ("done\n");
+        break;
+    case Z_ExtendedServicesResponse_accepted:
+        printf ("accepted\n");
+        break;
+    case Z_ExtendedServicesResponse_failure:
+        printf ("failure\n");
+        display_diagrecs(res->diagnostics, res->num_diagnostics);
+        break;
+    default:
+        printf ("unknown\n");
+    }
+    if ( (*res->operationStatus != Z_ExtendedServicesResponse_failure) &&
+        (res->num_diagnostics != 0) ) {
+        display_diagrecs(res->diagnostics, res->num_diagnostics);
+    }
+    print_refid (res->referenceId);
+    if (res->taskPackage && 
+        res->taskPackage->which == Z_External_extendedService)
+    {
+        Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
+        Odr_oct *id = taskPackage->targetReference;
+        Z_External *ext = taskPackage->taskSpecificParameters;
+        
+        if (id)
+        {
+            printf ("Target Reference: ");
+            print_stringn (id->buf, id->len);
+            printf ("\n");
+        }
+        if (ext->which == Z_External_update)
+        {
+            Z_IUUpdateTaskPackage *utp = ext->u.update->u.taskPackage;
+            if (utp && utp->targetPart)
+            {
+                Z_IUTargetPart *targetPart = utp->targetPart;
+                int i;
+
+                for (i = 0; i<targetPart->num_taskPackageRecords;  i++)
+                {
+
+                    Z_IUTaskPackageRecordStructure *tpr =
+                        targetPart->taskPackageRecords[i];
+                    printf ("task package record %d\n", i+1);
+                    if (tpr->which == Z_IUTaskPackageRecordStructure_record)
+                    {
+                        display_record (tpr->u.record);
+                    }
+                    else
+                    {
+                        printf ("other type\n");
+                    }
+                }
+            }
+        }
+    }
+}
+
+const char *get_ill_element (void *clientData, const char *element)
+{
+    return 0;
+}
+
+static Z_External *create_external_itemRequest()
+{
+    struct ill_get_ctl ctl;
+    ILL_ItemRequest *req;
+    Z_External *r = 0;
+    int item_request_size = 0;
+    char *item_request_buf = 0;
+
+    ctl.odr = out;
+    ctl.clientData = 0;
+    ctl.f = get_ill_element;
+    
+    req = ill_get_ItemRequest(&ctl, "ill", 0);
+    if (!req)
+        printf ("ill_get_ItemRequest failed\n");
+        
+    if (!ill_ItemRequest (out, &req, 0, 0))
+    {
+        if (apdu_file)
+        {
+            ill_ItemRequest(print, &req, 0, 0);
+            odr_reset(print);
+        }
+        item_request_buf = odr_getbuf (out, &item_request_size, 0);
+        if (item_request_buf)
+            odr_setbuf (out, item_request_buf, item_request_size, 1);
+        printf ("Couldn't encode ItemRequest, size %d\n", item_request_size);
+        return 0;
+    }
+    else
+    {
+        oident oid;
+        
+        item_request_buf = odr_getbuf (out, &item_request_size, 0);
+        oid.proto = PROTO_GENERAL;
+        oid.oclass = CLASS_GENERAL;
+        oid.value = VAL_ISO_ILL_1;
+        
+        r = (Z_External *) odr_malloc (out, sizeof(*r));
+        r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid)); 
+        r->indirect_reference = 0;
+        r->descriptor = 0;
+        r->which = Z_External_single;
+        
+        r->u.single_ASN1_type = (Odr_oct *)
+            odr_malloc (out, sizeof(*r->u.single_ASN1_type));
+        r->u.single_ASN1_type->buf = (unsigned char *)
+        odr_malloc (out, item_request_size);
+        r->u.single_ASN1_type->len = item_request_size;
+        r->u.single_ASN1_type->size = item_request_size;
+        memcpy (r->u.single_ASN1_type->buf, item_request_buf,
+                item_request_size);
+        
+        do_hex_dump(item_request_buf,item_request_size);
+    }
+    return r;
+}
+
+static Z_External *create_external_ILL_APDU(int which)
+{
+    struct ill_get_ctl ctl;
+    ILL_APDU *ill_apdu;
+    Z_External *r = 0;
+    int ill_request_size = 0;
+    char *ill_request_buf = 0;
+        
+    ctl.odr = out;
+    ctl.clientData = 0;
+    ctl.f = get_ill_element;
+
+    ill_apdu = ill_get_APDU(&ctl, "ill", 0);
+
+    if (!ill_APDU (out, &ill_apdu, 0, 0))
+    {
+        if (apdu_file)
+        {
+            printf ("-------------------\n");
+            ill_APDU(print, &ill_apdu, 0, 0);
+            odr_reset(print);
+            printf ("-------------------\n");
+        }
+        ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
+        if (ill_request_buf)
+            odr_setbuf (out, ill_request_buf, ill_request_size, 1);
+        printf ("Couldn't encode ILL-Request, size %d\n", ill_request_size);
+        return 0;
+    }
+    else
+    {
+        oident oid;
+        ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
+        
+        oid.proto = PROTO_GENERAL;
+        oid.oclass = CLASS_GENERAL;
+        oid.value = VAL_ISO_ILL_1;
+        
+        r = (Z_External *) odr_malloc (out, sizeof(*r));
+        r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid)); 
+        r->indirect_reference = 0;
+        r->descriptor = 0;
+        r->which = Z_External_single;
+        
+        r->u.single_ASN1_type = (Odr_oct *)
+            odr_malloc (out, sizeof(*r->u.single_ASN1_type));
+        r->u.single_ASN1_type->buf = (unsigned char *)
+        odr_malloc (out, ill_request_size);
+        r->u.single_ASN1_type->len = ill_request_size;
+        r->u.single_ASN1_type->size = ill_request_size;
+        memcpy (r->u.single_ASN1_type->buf, ill_request_buf, ill_request_size);
+/*         printf ("len = %d\n", ill_request_size); */
+/* 		do_hex_dump(ill_request_buf,ill_request_size); */
+/* 		printf("--- end of extenal\n"); */
+
+    }
+    return r;
+}
+
+
+static Z_External *create_ItemOrderExternal(const char *type, int itemno)
+{
+    Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External));
+    oident ItemOrderRequest;
+  
+    ItemOrderRequest.proto = PROTO_Z3950;
+    ItemOrderRequest.oclass = CLASS_EXTSERV;
+    ItemOrderRequest.value = VAL_ITEMORDER;
+ 
+    r->direct_reference = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest)); 
+    r->indirect_reference = 0;
+    r->descriptor = 0;
+
+    r->which = Z_External_itemOrder;
+
+    r->u.itemOrder = (Z_ItemOrder *) odr_malloc(out,sizeof(Z_ItemOrder));
+    memset(r->u.itemOrder, 0, sizeof(Z_ItemOrder));
+    r->u.itemOrder->which=Z_IOItemOrder_esRequest;
+
+    r->u.itemOrder->u.esRequest = (Z_IORequest *) 
+        odr_malloc(out,sizeof(Z_IORequest));
+    memset(r->u.itemOrder->u.esRequest, 0, sizeof(Z_IORequest));
+
+    r->u.itemOrder->u.esRequest->toKeep = (Z_IOOriginPartToKeep *)
+        odr_malloc(out,sizeof(Z_IOOriginPartToKeep));
+    memset(r->u.itemOrder->u.esRequest->toKeep, 0, sizeof(Z_IOOriginPartToKeep));
+    r->u.itemOrder->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *)
+        odr_malloc(out,sizeof(Z_IOOriginPartNotToKeep));
+    memset(r->u.itemOrder->u.esRequest->notToKeep, 0, sizeof(Z_IOOriginPartNotToKeep));
+
+    r->u.itemOrder->u.esRequest->toKeep->supplDescription = NULL;
+    r->u.itemOrder->u.esRequest->toKeep->contact = NULL;
+    r->u.itemOrder->u.esRequest->toKeep->addlBilling = NULL;
+
+    r->u.itemOrder->u.esRequest->notToKeep->resultSetItem =
+        (Z_IOResultSetItem *) odr_malloc(out, sizeof(Z_IOResultSetItem));
+    memset(r->u.itemOrder->u.esRequest->notToKeep->resultSetItem, 0, sizeof(Z_IOResultSetItem));
+    r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->resultSetId = "1";
+
+    r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item =
+        (int *) odr_malloc(out, sizeof(int));
+    *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno;
+
+    if (!strcmp (type, "item") || !strcmp(type, "2"))
+    {
+        printf ("using item-request\n");
+        r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 
+            create_external_itemRequest();
+    }
+    else if (!strcmp(type, "ill") || !strcmp(type, "1"))
+    {
+        printf ("using ILL-request\n");
+        r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 
+            create_external_ILL_APDU(ILL_APDU_ILL_Request);
+    }
+    else if (!strcmp(type, "xml") || !strcmp(type, "3"))
+    {
+    const char *xml_buf =
+        "<itemorder>\n"
+        "  <type>request</type>\n"
+        "  <libraryNo>000200</libraryNo>\n"
+        "  <borrowerTicketNo> 1212 </borrowerTicketNo>\n"
+        "</itemorder>";
+        r->u.itemOrder->u.esRequest->notToKeep->itemRequest =
+            z_ext_record (out, VAL_TEXT_XML, xml_buf, strlen(xml_buf));
+    }
+    else
+        r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0;
+
+    return r;
+}
+
+static int send_itemorder(const char *type, int itemno)
+{
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
+    Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
+    oident ItemOrderRequest;
+
+    ItemOrderRequest.proto = PROTO_Z3950;
+    ItemOrderRequest.oclass = CLASS_EXTSERV;
+    ItemOrderRequest.value = VAL_ITEMORDER;
+    req->packageType = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest));
+    req->packageName = esPackageName;
+
+    req->taskSpecificParameters = create_ItemOrderExternal(type, itemno);
+
+    send_apdu(apdu);
+    return 0;
+}
+
+static int only_z3950()
+{
+    if (protocol == PROTO_HTTP)
+    {
+	printf ("Not supported by SRW\n");
+	return 1;
+    }
+    return 0;
+}
+
+
+static int cmd_update_common(const char *arg, int version);
+
+static int cmd_update(const char *arg)
+{
+    return cmd_update_common(arg, 1);
+}
+
+static int cmd_update0(const char *arg)
+{
+    return cmd_update_common(arg, 0);
+}
+
+static int cmd_update_common(const char *arg, int version)
+{
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
+    Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
+    Z_External *r;
+    char action[20], recid[20], fname[80];
+    int action_no;
+    Z_External *record_this = 0;
+
+    if (only_z3950())
+	return 0;
+    *action = 0;
+    *recid = 0;
+    *fname = 0;
+    sscanf (arg, "%19s %19s %79s", action, recid, fname);
+
+    if (!strcmp (action, "insert"))
+        action_no = Z_IUOriginPartToKeep_recordInsert;
+    else if (!strcmp (action, "replace"))
+        action_no = Z_IUOriginPartToKeep_recordReplace;
+    else if (!strcmp (action, "delete"))
+        action_no = Z_IUOriginPartToKeep_recordDelete;
+    else if (!strcmp (action, "update"))
+        action_no = Z_IUOriginPartToKeep_specialUpdate;
+    else 
+    {
+        printf ("Bad action: %s\n", action);
+        printf ("Possible values: insert, replace, delete, update\n");
+        return 0;
+    }
+
+    if (*fname)
+    {
+        FILE *inf;
+        struct stat status;
+        stat (fname, &status);
+        if (S_ISREG(status.st_mode) && (inf = fopen(fname, "rb")))
+        {
+            size_t len = status.st_size;
+            char *buf = (char *) xmalloc (len);
+
+            fread (buf, 1, len, inf);
+
+            fclose (inf);
+            
+            record_this = z_ext_record (out, VAL_TEXT_XML, buf, len);
+            
+            xfree (buf);
+        }
+        else
+        {
+            printf ("File %s doesn't exist\n", fname);
+            return 0;
+        }
+    }
+    else
+    {
+        if (!record_last)
+        {
+            printf ("No last record (update ignored)\n");
+            return 0;
+        }
+        record_this = record_last;
+    }
+
+    req->packageType =
+	yaz_oidval_to_z3950oid(out, CLASS_EXTSERV,
+			       version == 0 ? VAL_DBUPDATE0 : VAL_DBUPDATE);
+
+    req->packageName = esPackageName;
+    
+    req->referenceId = set_refid (out);
+
+    r = req->taskSpecificParameters = (Z_External *)
+        odr_malloc (out, sizeof(*r));
+    r->direct_reference = req->packageType;
+    r->indirect_reference = 0;
+    r->descriptor = 0;
+    if (version == 0)
+    {
+	Z_IU0OriginPartToKeep *toKeep;
+	Z_IU0SuppliedRecords *notToKeep;
+
+	r->which = Z_External_update0;
+	r->u.update0 = (Z_IU0Update *) odr_malloc(out, sizeof(*r->u.update0));
+	r->u.update0->which = Z_IUUpdate_esRequest;
+	r->u.update0->u.esRequest = (Z_IU0UpdateEsRequest *)
+	    odr_malloc(out, sizeof(*r->u.update0->u.esRequest));
+	toKeep = r->u.update0->u.esRequest->toKeep = (Z_IU0OriginPartToKeep *)
+	    odr_malloc(out, sizeof(*r->u.update0->u.esRequest->toKeep));
+	
+	toKeep->databaseName = databaseNames[0];
+	toKeep->schema = 0;
+	toKeep->elementSetName = 0;
+
+	toKeep->action = (int *) odr_malloc(out, sizeof(*toKeep->action));
+	*toKeep->action = action_no;
+	
+	notToKeep = r->u.update0->u.esRequest->notToKeep = (Z_IU0SuppliedRecords *)
+	    odr_malloc(out, sizeof(*r->u.update0->u.esRequest->notToKeep));
+	notToKeep->num = 1;
+	notToKeep->elements = (Z_IU0SuppliedRecords_elem **)
+	    odr_malloc(out, sizeof(*notToKeep->elements));
+	notToKeep->elements[0] = (Z_IU0SuppliedRecords_elem *)
+	    odr_malloc(out, sizeof(**notToKeep->elements));
+	notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque;
+	if (*recid)
+	{
+	    notToKeep->elements[0]->u.opaque = (Odr_oct *)
+		odr_malloc (out, sizeof(Odr_oct));
+	    notToKeep->elements[0]->u.opaque->buf = (unsigned char *) recid;
+	    notToKeep->elements[0]->u.opaque->size = strlen(recid);
+	    notToKeep->elements[0]->u.opaque->len = strlen(recid);
+	}
+	else
+	    notToKeep->elements[0]->u.opaque = 0;
+	notToKeep->elements[0]->supplementalId = 0;
+	notToKeep->elements[0]->correlationInfo = 0;
+	notToKeep->elements[0]->record = record_this;
+    }
+    else
+    {
+	Z_IUOriginPartToKeep *toKeep;
+	Z_IUSuppliedRecords *notToKeep;
+
+	r->which = Z_External_update;
+	r->u.update = (Z_IUUpdate *) odr_malloc(out, sizeof(*r->u.update));
+	r->u.update->which = Z_IUUpdate_esRequest;
+	r->u.update->u.esRequest = (Z_IUUpdateEsRequest *)
+	    odr_malloc(out, sizeof(*r->u.update->u.esRequest));
+	toKeep = r->u.update->u.esRequest->toKeep = (Z_IUOriginPartToKeep *)
+	    odr_malloc(out, sizeof(*r->u.update->u.esRequest->toKeep));
+	
+	toKeep->databaseName = databaseNames[0];
+	toKeep->schema = 0;
+	toKeep->elementSetName = 0;
+	toKeep->actionQualifier = 0;
+	toKeep->action = (int *) odr_malloc(out, sizeof(*toKeep->action));
+	*toKeep->action = action_no;
+
+	notToKeep = r->u.update->u.esRequest->notToKeep = (Z_IUSuppliedRecords *)
+	    odr_malloc(out, sizeof(*r->u.update->u.esRequest->notToKeep));
+	notToKeep->num = 1;
+	notToKeep->elements = (Z_IUSuppliedRecords_elem **)
+	    odr_malloc(out, sizeof(*notToKeep->elements));
+	notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *)
+	    odr_malloc(out, sizeof(**notToKeep->elements));
+	notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque;
+	if (*recid)
+	{
+	    notToKeep->elements[0]->u.opaque = (Odr_oct *)
+		odr_malloc (out, sizeof(Odr_oct));
+	    notToKeep->elements[0]->u.opaque->buf = (unsigned char *) recid;
+	    notToKeep->elements[0]->u.opaque->size = strlen(recid);
+	    notToKeep->elements[0]->u.opaque->len = strlen(recid);
+	}
+	else
+	    notToKeep->elements[0]->u.opaque = 0;
+	notToKeep->elements[0]->supplementalId = 0;
+	notToKeep->elements[0]->correlationInfo = 0;
+	notToKeep->elements[0]->record = record_this;
+    }
+    
+    send_apdu(apdu);
+
+    return 2;
+}
+
+
+static int cmd_itemorder(const char *arg)
+{
+    char type[12];
+    int itemno;
+   
+    if (only_z3950())
+	return 0;
+    if (sscanf (arg, "%10s %d", type, &itemno) != 2)
+        return 0;
+
+    printf("Item order request\n");
+    fflush(stdout);
+    send_itemorder(type, itemno);
+    return 2;
+}
+
+static void show_opt(const char *arg, void *clientData)
+{
+    printf ("%s ", arg);
+}
+
+static int cmd_zversion(const char *arg)
+{
+    if (*arg && arg)
+	z3950_version = atoi(arg);
+    else
+	printf ("version is %d\n", z3950_version);
+    return 0;
+}
+
+static int cmd_options(const char *arg)
+{
+    if (*arg)
+    {
+	int r;
+	int pos;
+	r = yaz_init_opt_encode(&z3950_options, arg, &pos);
+    }
+    else
+    {
+	yaz_init_opt_decode(&z3950_options, show_opt, 0);
+	printf ("\n");
+    }
+    return 0;
+}
+
+static int cmd_explain(const char *arg)
+{
+    if (protocol != PROTO_HTTP)
+	return 0;
+#if HAVE_XML2
+    if (!conn)
+	cmd_open(0);
+    if (conn)
+    {
+	Z_SRW_PDU *sr = 0;
+	
+	setno = 1;
+	
+	/* save this for later .. when fetching individual records */
+	sr = yaz_srw_get(out, Z_SRW_explain_request);
+	if (recordsyntax == VAL_TEXT_XML)
+            sr->u.explain_request->recordPacking = "xml";
+	send_srw(sr);
+	return 2;
+    }
+#endif
+    return 0;
+}
+
+static int cmd_init(const char *arg)
+{
+    if (*arg)
+    {
+        strncpy (cur_host, arg, sizeof(cur_host)-1);
+        cur_host[sizeof(cur_host)-1] = 0;
+    }
+    if (!conn || protocol != PROTO_Z3950)
+       return 0;
+    send_initRequest(cur_host);
+    return 2;
+
+}
+
+static int cmd_find(const char *arg)
+{
+    if (!*arg)
+    {
+        printf("Find what?\n");
+        return 0;
+    }
+    if (protocol == PROTO_HTTP)
+    {
+#if HAVE_XML2
+        if (!conn)
+            cmd_open(0);
+	if (!conn)
+	    return 0;
+        if (!send_SRW_searchRequest(arg))
+            return 0;
+#else
+        return 0;
+#endif
+    }
+    else
+    {
+        if (!conn)
+        {
+            try_reconnect(); 
+            
+            if (!conn) {					
+                printf("Not connected yet\n");
+                return 0;
+            }
+        }
+        if (!send_searchRequest(arg))
+            return 0;
+    }
+    return 2;
+}
+
+static int cmd_delete(const char *arg)
+{
+    if (!conn)
+    {
+        printf("Not connected yet\n");
+        return 0;
+    }
+    if (only_z3950())
+	return 0;
+    if (!send_deleteResultSetRequest(arg))
+        return 0;
+    return 2;
+}
+
+static int cmd_ssub(const char *arg)
+{
+    if (!(smallSetUpperBound = atoi(arg)))
+        return 0;
+    return 1;
+}
+
+static int cmd_lslb(const char *arg)
+{
+    if (only_z3950())
+	return 0;
+    if (!(largeSetLowerBound = atoi(arg)))
+        return 0;
+    return 1;
+}
+
+static int cmd_mspn(const char *arg)
+{
+    if (only_z3950())
+	return 0;
+    if (!(mediumSetPresentNumber = atoi(arg)))
+        return 0;
+    return 1;
+}
+
+static int cmd_status(const char *arg)
+{
+    printf("smallSetUpperBound: %d\n", smallSetUpperBound);
+    printf("largeSetLowerBound: %d\n", largeSetLowerBound);
+    printf("mediumSetPresentNumber: %d\n", mediumSetPresentNumber);
+    return 1;
+}
+
+static int cmd_setnames(const char *arg)
+{
+    if (*arg == '1')         /* enable ? */
+        setnumber = 0;
+    else if (*arg == '0')    /* disable ? */
+        setnumber = -1;
+    else if (setnumber < 0)  /* no args, toggle .. */
+        setnumber = 0;
+    else
+        setnumber = -1;
+   
+    if (setnumber >= 0)
+        printf("Set numbering enabled.\n");
+    else
+        printf("Set numbering disabled.\n");
+    return 1;
+}
+
+/* PRESENT SERVICE ----------------------------- */
+/* this one is based on johnmcps version - pretty much a copy of 
+   send_presentRequest, but passing in separate args, not an arg string */
+int z_send_getbriefrecords(int starting, int set, int howmany) {
+
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest);
+    Z_PresentRequest *req = apdu->u.presentRequest;
+    Z_RecordComposition compo;
+    int nos = 1;
+    char setstring[100];
+
+    req->referenceId = set_refid (out);
+    nos = howmany;
+    setno = starting;
+    sprintf(setstring, "%d", setnumber);
+    req->resultSetId = setstring;
+    req->resultSetStartPoint = &setno;
+    req->numberOfRecordsRequested = &nos;
+    
+    req->preferredRecordSyntax =
+        yaz_oidval_to_z3950oid(out, CLASS_RECSYN, recordsyntax);
+
+    if (record_schema)
+    {
+        req->recordComposition = &compo;
+        compo.which = Z_RecordComp_complex;
+        compo.u.complex = (Z_CompSpec *)
+            odr_malloc(out, sizeof(*compo.u.complex));
+        compo.u.complex->selectAlternativeSyntax = (bool_t *) 
+            odr_malloc(out, sizeof(bool_t));
+        *compo.u.complex->selectAlternativeSyntax = 0;
+
+        compo.u.complex->generic = (Z_Specification *)
+            odr_malloc(out, sizeof(*compo.u.complex->generic));
+        compo.u.complex->generic->which = Z_Schema_oid;
+
+        compo.u.complex->generic->schema.oid =
+	    yaz_str_to_z3950oid(out, CLASS_SCHEMA, record_schema);
+
+        if (!compo.u.complex->generic->schema.oid)
+        {
+            /* OID wasn't a schema! Try record syntax instead. */
+            compo.u.complex->generic->schema.oid = (Odr_oid *)
+		yaz_str_to_z3950oid(out, CLASS_RECSYN, record_schema);
+        }
+        if (!elementSetNames)
+            compo.u.complex->generic->elementSpec = 0;
+        else
+        {
+            compo.u.complex->generic->elementSpec = (Z_ElementSpec *)
+                odr_malloc(out, sizeof(Z_ElementSpec));
+            compo.u.complex->generic->elementSpec->which =
+                Z_ElementSpec_elementSetName;
+            compo.u.complex->generic->elementSpec->u.elementSetName =
+                elementSetNames->u.generic;
+        }
+        compo.u.complex->num_dbSpecific = 0;
+        compo.u.complex->dbSpecific = 0;
+        compo.u.complex->num_recordSyntax = 0;
+        compo.u.complex->recordSyntax = 0;
+    }
+    else if (elementSetNames)
+    {
+        req->recordComposition = &compo;
+        compo.which = Z_RecordComp_simple;
+        compo.u.simple = elementSetNames;
+    }
+    send_apdu(apdu);
+    return 0;
+}
+
+static void parse_show_args(const char *arg_c, char *setstring,
+                            int *start, int *number)
+{
+    char arg[40];
+    char *p;
+
+    strncpy(arg, arg_c, sizeof(arg)-1);
+    arg[sizeof(arg)-1] = '\0';
+
+    if ((p = strchr(arg, '+')))
+    {
+        *number = atoi(p + 1);
+        *p = '\0';
+    }
+    if (*arg)
+        *start = atoi(arg);
+    if (p && (p=strchr(p+1, '+')))
+        strcpy (setstring, p+1);
+    else if (setnumber >= 0)
+        sprintf(setstring, "%d", setnumber);
+    else
+        *setstring = '\0';
+}
+
+static int send_presentRequest(const char *arg)
+{
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_presentRequest);
+    Z_PresentRequest *req = apdu->u.presentRequest;
+    Z_RecordComposition compo;
+    int nos = 1;
+    char setstring[100];
+
+    req->referenceId = set_refid (out);
+
+    parse_show_args(arg, setstring, &setno, &nos);
+    if (*setstring)
+        req->resultSetId = setstring;
+
+    req->resultSetStartPoint = &setno;
+    req->numberOfRecordsRequested = &nos;
+
+    req->preferredRecordSyntax =
+        yaz_oidval_to_z3950oid(out, CLASS_RECSYN, recordsyntax);
+
+    if (record_schema)
+    {
+        req->recordComposition = &compo;
+        compo.which = Z_RecordComp_complex;
+        compo.u.complex = (Z_CompSpec *)
+            odr_malloc(out, sizeof(*compo.u.complex));
+        compo.u.complex->selectAlternativeSyntax = (bool_t *) 
+            odr_malloc(out, sizeof(bool_t));
+        *compo.u.complex->selectAlternativeSyntax = 0;
+
+        compo.u.complex->generic = (Z_Specification *)
+            odr_malloc(out, sizeof(*compo.u.complex->generic));
+        compo.u.complex->generic->which = Z_Schema_oid;
+
+        compo.u.complex->generic->schema.oid =
+	    yaz_str_to_z3950oid(out, CLASS_SCHEMA, record_schema);
+
+        if (!compo.u.complex->generic->schema.oid)
+        {
+            /* OID wasn't a schema! Try record syntax instead. */
+            compo.u.complex->generic->schema.oid = (Odr_oid *)
+		yaz_str_to_z3950oid(out, CLASS_RECSYN, record_schema);
+        }
+        if (!elementSetNames)
+            compo.u.complex->generic->elementSpec = 0;
+        else
+        {
+            compo.u.complex->generic->elementSpec = (Z_ElementSpec *)
+                odr_malloc(out, sizeof(Z_ElementSpec));
+            compo.u.complex->generic->elementSpec->which =
+                Z_ElementSpec_elementSetName;
+            compo.u.complex->generic->elementSpec->u.elementSetName =
+                elementSetNames->u.generic;
+        }
+        compo.u.complex->num_dbSpecific = 0;
+        compo.u.complex->dbSpecific = 0;
+        compo.u.complex->num_recordSyntax = 0;
+        compo.u.complex->recordSyntax = 0;
+    }
+    else if (elementSetNames)
+    {
+        req->recordComposition = &compo;
+        compo.which = Z_RecordComp_simple;
+        compo.u.simple = elementSetNames;
+    }
+    send_apdu(apdu);
+    printf("Sent presentRequest (%d+%d).\n", setno, nos);
+    return 2;
+}
+
+#if HAVE_XML2
+static int send_SRW_presentRequest(const char *arg)
+{
+    char setstring[100];
+    int nos = 1;
+    Z_SRW_PDU *sr = srw_sr;
+
+    if (!sr)
+        return 0;
+    parse_show_args(arg, setstring, &setno, &nos);
+    sr->u.request->startRecord = odr_intdup(out, setno);
+    sr->u.request->maximumRecords = odr_intdup(out, nos);
+    if (record_schema)
+        sr->u.request->recordSchema = record_schema;
+    if (recordsyntax == VAL_TEXT_XML)
+        sr->u.request->recordPacking = "xml";
+    return send_srw(sr);
+}
+#endif
+
+static void close_session (void)
+{
+    if (conn)
+        cs_close (conn);
+    conn = 0;
+    if (session_mem)
+    {
+        nmem_destroy (session_mem);
+        session_mem = NULL;
+    }
+    sent_close = 0;
+    odr_reset(out);
+    odr_reset(in);
+    odr_reset(print);
+}
+
+void process_close(Z_Close *req)
+{
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_close);
+    Z_Close *res = apdu->u.close;
+
+    static char *reasons[] =
+    {
+        "finished",
+        "shutdown",
+        "system problem",
+        "cost limit reached",
+        "resources",
+        "security violation",
+        "protocolError",
+        "lack of activity",
+        "peer abort",
+        "unspecified"
+    };
+
+    printf("Reason: %s, message: %s\n", reasons[*req->closeReason],
+        req->diagnosticInformation ? req->diagnosticInformation : "NULL");
+    if (sent_close)
+        close_session ();
+    else
+    {
+        *res->closeReason = Z_Close_finished;
+        send_apdu(apdu);
+        printf("Sent response.\n");
+        sent_close = 1;
+    }
+}
+
+static int cmd_show(const char *arg)
+{
+    if (protocol == PROTO_HTTP)
+    {
+#if HAVE_XML2
+        if (!conn)
+            cmd_open(0);
+	if (!conn)
+	    return 0;
+        if (!send_SRW_presentRequest(arg))
+            return 0;
+#else
+        return 0;
+#endif
+    }
+    else
+    {
+        if (!conn)
+        {
+            printf("Not connected yet\n");
+            return 0;
+        }
+        if (!send_presentRequest(arg))
+            return 0;
+    }
+    return 2;
+}
+
+int cmd_quit(const char *arg)
+{
+    printf("See you later, alligator.\n");
+    xmalloc_trav ("");
+    exit(0);
+    return 0;
+}
+
+int cmd_cancel(const char *arg)
+{
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_triggerResourceControlRequest);
+    Z_TriggerResourceControlRequest *req =
+        apdu->u.triggerResourceControlRequest;
+    bool_t rfalse = 0;
+    
+    if (!conn)
+    {
+        printf("Session not initialized yet\n");
+        return 0;
+    }
+    if (only_z3950())
+	return 0;
+    if (!ODR_MASK_GET(session->options, Z_Options_triggerResourceCtrl))
+    {
+        printf("Target doesn't support cancel (trigger resource ctrl)\n");
+        return 0;
+    }
+    *req->requestedAction = Z_TriggerResourceControlRequest_cancel;
+    req->resultSetWanted = &rfalse;
+    req->referenceId = set_refid (out);
+
+    send_apdu(apdu);
+    printf("Sent cancel request\n");
+    return 2;
+}
+
+
+int cmd_cancel_find(const char *arg) {
+    int fres;
+    fres=cmd_find(arg);
+    if( fres > 0 ) {
+	return cmd_cancel("");
+    };
+    return fres;
+}
+
+int send_scanrequest(const char *query, int pp, int num, const char *term)
+{
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest);
+    Z_ScanRequest *req = apdu->u.scanRequest;
+    
+    if (only_z3950())
+	return 0;
+    if (queryType == QueryType_CCL2RPN)
+    {
+        int error, pos;
+        struct ccl_rpn_node *rpn;
+
+        rpn = ccl_find_str (bibset,  query, &error, &pos);
+        if (error)
+        {
+            printf("CCL ERROR: %s\n", ccl_err_msg(error));
+            return -1;
+        }
+        req->attributeSet =
+	    yaz_oidval_to_z3950oid(out, CLASS_ATTSET, VAL_BIB1);
+        if (!(req->termListAndStartPoint = ccl_scan_query (out, rpn)))
+        {
+            printf("Couldn't convert CCL to Scan term\n");
+            return -1;
+        }
+        ccl_rpn_delete (rpn);
+    }
+    else
+    {
+        YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
+
+        if (!(req->termListAndStartPoint =
+              yaz_pqf_scan(pqf_parser, out, &req->attributeSet, query)))
+        {
+            const char *pqf_msg;
+            size_t off;
+            int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
+            printf("%*s^\n", off+7, "");
+            printf("Prefix query error: %s (code %d)\n", pqf_msg, code);
+            yaz_pqf_destroy (pqf_parser);
+            return -1;
+        }
+        yaz_pqf_destroy (pqf_parser);
+    }
+    if (term && *term)
+    {
+        if (req->termListAndStartPoint->term &&
+            req->termListAndStartPoint->term->which == Z_Term_general &&
+            req->termListAndStartPoint->term->u.general)
+        {
+            req->termListAndStartPoint->term->u.general->buf =
+                (unsigned char *) odr_strdup(out, term);
+            req->termListAndStartPoint->term->u.general->len =
+                req->termListAndStartPoint->term->u.general->size =
+                strlen(term);
+        }
+    }
+    req->referenceId = set_refid (out);
+    req->num_databaseNames = num_databaseNames;
+    req->databaseNames = databaseNames;
+    req->numberOfTermsRequested = &num;
+    req->preferredPositionInResponse = &pp;
+    req->stepSize = odr_intdup(out, scan_stepSize);
+    send_apdu(apdu);
+    return 2;
+}
+
+int send_sortrequest(const char *arg, int newset)
+{
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_sortRequest);
+    Z_SortRequest *req = apdu->u.sortRequest;
+    Z_SortKeySpecList *sksl = (Z_SortKeySpecList *)
+        odr_malloc (out, sizeof(*sksl));
+    char setstring[32];
+
+    if (only_z3950())
+	return 0;
+    if (setnumber >= 0)
+        sprintf (setstring, "%d", setnumber);
+    else
+        sprintf (setstring, "default");
+
+    req->referenceId = set_refid (out);
+
+    req->num_inputResultSetNames = 1;
+    req->inputResultSetNames = (Z_InternationalString **)
+        odr_malloc (out, sizeof(*req->inputResultSetNames));
+    req->inputResultSetNames[0] = odr_strdup (out, setstring);
+
+    if (newset && setnumber >= 0)
+        sprintf (setstring, "%d", ++setnumber);
+
+    req->sortedResultSetName = odr_strdup (out, setstring);
+
+    req->sortSequence = yaz_sort_spec (out, arg);
+    if (!req->sortSequence)
+    {
+        printf ("Missing sort specifications\n");
+        return -1;
+    }
+    send_apdu(apdu);
+    return 2;
+}
+
+void display_term(Z_TermInfo *t)
+{
+    if (t->displayTerm)
+        printf("%s", t->displayTerm);
+    else if (t->term->which == Z_Term_general)
+    {
+        printf("%.*s", t->term->u.general->len, t->term->u.general->buf);
+        sprintf(last_scan_line, "%.*s", t->term->u.general->len,
+            t->term->u.general->buf);
+    }
+    else
+        printf("Term (not general)");
+    if (t->globalOccurrences)
+        printf (" (%d)\n", *t->globalOccurrences);
+    else
+        printf ("\n");
+}
+
+void process_scanResponse(Z_ScanResponse *res)
+{
+    int i;
+    Z_Entry **entries = NULL;
+    int num_entries = 0;
+   
+    printf("Received ScanResponse\n"); 
+    print_refid (res->referenceId);
+    printf("%d entries", *res->numberOfEntriesReturned);
+    if (res->positionOfTerm)
+        printf (", position=%d", *res->positionOfTerm); 
+    printf ("\n");
+    if (*res->scanStatus != Z_Scan_success)
+        printf("Scan returned code %d\n", *res->scanStatus);
+    if (!res->entries)
+        return;
+    if ((entries = res->entries->entries))
+        num_entries = res->entries->num_entries;
+    for (i = 0; i < num_entries; i++)
+    {
+        int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1;
+        if (entries[i]->which == Z_Entry_termInfo)
+        {
+            printf("%c ", i + 1 == pos_term ? '*' : ' ');
+            display_term(entries[i]->u.termInfo);
+        }
+        else
+            display_diagrecs(&entries[i]->u.surrogateDiagnostic, 1);
+    }
+    if (res->entries->nonsurrogateDiagnostics)
+        display_diagrecs (res->entries->nonsurrogateDiagnostics,
+                          res->entries->num_nonsurrogateDiagnostics);
+}
+
+void process_sortResponse(Z_SortResponse *res)
+{
+    printf("Received SortResponse: status=");
+    switch (*res->sortStatus)
+    {
+    case Z_SortResponse_success:
+        printf ("success"); break;
+    case Z_SortResponse_partial_1:
+        printf ("partial"); break;
+    case Z_SortResponse_failure:
+        printf ("failure"); break;
+    default:
+        printf ("unknown (%d)", *res->sortStatus);
+    }
+    printf ("\n");
+    print_refid (res->referenceId);
+    if (res->diagnostics)
+        display_diagrecs(res->diagnostics,
+                         res->num_diagnostics);
+}
+
+void process_deleteResultSetResponse (Z_DeleteResultSetResponse *res)
+{
+    printf("Got deleteResultSetResponse status=%d\n",
+           *res->deleteOperationStatus);
+    if (res->deleteListStatuses)
+    {
+        int i;
+        for (i = 0; i < res->deleteListStatuses->num; i++)
+        {
+            printf ("%s status=%d\n", res->deleteListStatuses->elements[i]->id,
+                    *res->deleteListStatuses->elements[i]->status);
+        }
+    }
+}
+
+int cmd_sort_generic(const char *arg, int newset)
+{
+    if (!conn)
+    {
+        printf("Session not initialized yet\n");
+        return 0;
+    }
+    if (only_z3950())
+	return 0;
+    if (!ODR_MASK_GET(session->options, Z_Options_sort))
+    {
+        printf("Target doesn't support sort\n");
+        return 0;
+    }
+    if (*arg)
+    {
+        if (send_sortrequest(arg, newset) < 0)
+            return 0;
+        return 2;
+    }
+    return 0;
+}
+
+int cmd_sort(const char *arg)
+{
+    return cmd_sort_generic (arg, 0);
+}
+
+int cmd_sort_newset (const char *arg)
+{
+    return cmd_sort_generic (arg, 1);
+}
+
+int cmd_scanstep(const char *arg)
+{
+    scan_stepSize = atoi(arg);
+    return 0;
+}
+
+int cmd_scanpos(const char *arg)
+{
+    int r = sscanf(arg, "%d", &scan_position);
+    if (r == 0)
+        scan_position = 1;
+    return 0;
+}
+
+int cmd_scansize(const char *arg)
+{
+    int r = sscanf(arg, "%d", &scan_size);
+    if (r == 0)
+        scan_size = 20;
+    return 0;
+}
+
+int cmd_scan(const char *arg)
+{
+    if (protocol == PROTO_HTTP)
+    {
+#if HAVE_XML2
+        if (!conn)
+            cmd_open(0);
+	if (!conn)
+	    return 0;
+	if (*arg)
+	{
+	    if (send_SRW_scanRequest(arg, scan_position, scan_size) < 0)
+		return 0;
+	}
+	else
+	{
+	    if (send_SRW_scanRequest(last_scan_line, 1, scan_size) < 0)
+		return 0;
+	}
+	return 2;
+#else
+        return 0;
+#endif
+    }
+    else
+    {
+	if (!conn)
+	{
+	    try_reconnect();
+	    
+	    if (!conn) {								
+		printf("Session not initialized yet\n");
+		return 0;
+	    }
+	}
+	if (!ODR_MASK_GET(session->options, Z_Options_scan))
+	{
+	    printf("Target doesn't support scan\n");
+	    return 0;
+	}
+	if (*arg)
+	{
+	    strcpy (last_scan_query, arg);
+	    if (send_scanrequest(arg, scan_position, scan_size, 0) < 0)
+		return 0;
+	}
+	else
+	{
+	    if (send_scanrequest(last_scan_query, 1, scan_size, last_scan_line) < 0)
+		return 0;
+	}
+	return 2;
+    }
+}
+
+int cmd_schema(const char *arg)
+{
+    xfree(record_schema);
+    record_schema = 0;
+    if (arg && *arg)
+        record_schema = xstrdup(arg);
+    return 1;
+}
+
+int cmd_format(const char *arg)
+{
+    oid_value nsyntax;
+    if (!arg || !*arg)
+    {
+        printf("Usage: format <recordsyntax>\n");
+        return 0;
+    }
+    nsyntax = oid_getvalbyname (arg);
+    if (strcmp(arg, "none") && nsyntax == VAL_NONE)
+    {
+        printf ("unknown record syntax\n");
+        return 0;
+    }
+    recordsyntax = nsyntax;
+    return 1;
+}
+
+int cmd_elements(const char *arg)
+{
+    static Z_ElementSetNames esn;
+    static char what[100];
+
+    if (!arg || !*arg)
+    {
+        elementSetNames = 0;
+        return 1;
+    }
+    strcpy(what, arg);
+    esn.which = Z_ElementSetNames_generic;
+    esn.u.generic = what;
+    elementSetNames = &esn;
+    return 1;
+}
+
+int cmd_attributeset(const char *arg)
+{
+    char what[100];
+
+    if (!arg || !*arg)
+    {
+        printf("Usage: attributeset <setname>\n");
+        return 0;
+    }
+    sscanf(arg, "%s", what);
+    if (p_query_attset (what))
+    {
+        printf("Unknown attribute set name\n");
+        return 0;
+    }
+    return 1;
+}
+
+int cmd_querytype (const char *arg)
+{
+    if (!strcmp (arg, "ccl"))
+        queryType = QueryType_CCL;
+    else if (!strcmp (arg, "prefix") || !strcmp(arg, "rpn"))
+        queryType = QueryType_Prefix;
+    else if (!strcmp (arg, "ccl2rpn") || !strcmp (arg, "cclrpn"))
+        queryType = QueryType_CCL2RPN;
+    else if (!strcmp(arg, "cql"))
+        queryType = QueryType_CQL;        
+    else if (!strcmp (arg, "cql2rpn") || !strcmp (arg, "cqlrpn"))
+        queryType = QueryType_CQL2RPN;
+    else
+    {
+        printf ("Querytype must be one of:\n");
+        printf (" prefix         - Prefix query\n");
+        printf (" ccl            - CCL query\n");
+        printf (" ccl2rpn        - CCL query converted to RPN\n");
+        printf (" cql            - CQL\n");
+        printf (" cql2rpn        - CQL query converted to RPN\n");
+        return 0;
+    }
+    return 1;
+}
+
+int cmd_refid (const char *arg)
+{
+    xfree (refid);
+    refid = NULL;
+    if (*arg)
+        refid = xstrdup (arg);
+    return 1;
+}
+
+int z_cmd_close(const char *arg)
+{
+    Z_APDU *apdu;
+    Z_Close *req;
+    if (!conn)
+        return 0;
+    if (only_z3950())
+	return 0;
+
+    apdu = zget_APDU(out, Z_APDU_close);
+    req = apdu->u.close;
+    *req->closeReason = Z_Close_finished;
+    send_apdu(apdu);
+    printf("Sent close request.\n");
+    sent_close = 1;
+    return 2;
+}
+
+int cmd_packagename(const char* arg)
+{
+    xfree (esPackageName);
+    esPackageName = NULL;
+    if (*arg)
+        esPackageName = xstrdup(arg);
+    return 1;
+}
+
+int cmd_proxy(const char* arg)
+{
+    xfree (yazProxy);
+    yazProxy = NULL;
+    if (*arg)
+        yazProxy = xstrdup (arg);
+    return 1;
+}
+
+int cmd_marccharset(const char *arg)
+{
+    char l1[30];
+
+    *l1 = 0;
+    if (sscanf(arg, "%29s", l1) < 1)
+    {
+    	printf("MARC character set is `%s'\n", 
+               marcCharset ? marcCharset: "none");
+        return 1;
+    }
+    xfree (marcCharset);
+    marcCharset = 0;
+    if (strcmp(l1, "-"))
+        marcCharset = xstrdup(l1);
+    return 1;
+}
+
+int cmd_displaycharset(const char *arg)
+{
+    char l1[30];
+
+    *l1 = 0;
+    if (sscanf(arg, "%29s", l1) < 1)
+    {
+    	printf("Display character set is `%s'\n", 
+               outputCharset ? outputCharset: "none");
+    }
+    else
+    {
+        xfree (outputCharset);
+        outputCharset = 0;
+        if (!strcmp(l1, "auto") && codeset)
+        {
+            if (codeset)
+            {
+                printf ("Display character set: %s\n", codeset);
+                outputCharset = xstrdup(codeset);
+            }
+            else
+                printf ("No codeset found on this system\n");
+        }
+        else if (strcmp(l1, "-") && strcmp(l1, "none"))
+            outputCharset = xstrdup(l1);
+    } 
+    return 1;
+}
+
+int cmd_negcharset(const char *arg)
+{
+    char l1[30];
+
+    *l1 = 0;
+    if (sscanf(arg, "%29s %d %d", l1, &negotiationCharsetRecords,
+	       &negotiationCharsetVersion) < 1)
+    {
+    	printf("Current negotiation character set is `%s'\n", 
+               negotiationCharset ? negotiationCharset: "none");  
+	printf("Records in charset %s\n", negotiationCharsetRecords ? 
+	       "yes" : "no");
+	printf("Charneg version %d\n", negotiationCharsetVersion);
+    }
+    else
+    {
+	xfree (negotiationCharset);
+	negotiationCharset = NULL;
+	if (*l1 && strcmp(l1, "-") && strcmp(l1, "none"))
+	{
+	    negotiationCharset = xstrdup(l1);
+	    printf ("Character set negotiation : %s\n", negotiationCharset);
+	}
+    }
+    return 1;
+}
+
+int cmd_charset(const char* arg)
+{
+    char l1[30], l2[30], l3[30];
+
+    *l1 = *l2 = *l3 = 0;
+    if (sscanf(arg, "%29s %29s %29s", l1, l2, l3) < 1)
+    {
+	cmd_negcharset("");
+	cmd_displaycharset("");
+	cmd_marccharset("");
+    }
+    else
+    {
+	cmd_negcharset(l1);
+	if (*l2)
+	    cmd_displaycharset(l2);
+	if (*l3)
+	    cmd_marccharset(l3);
+    }
+    return 1;
+}
+
+int cmd_lang(const char* arg)
+{
+    if (*arg == '\0') {
+    	printf("Current language is `%s'\n", (yazLang)?yazLang:NULL);
+    	return 1;
+    }
+    xfree (yazLang);
+    yazLang = NULL;
+    if (*arg)
+        yazLang = xstrdup(arg);
+    return 1;
+}
+
+int cmd_source(const char* arg, int echo ) 
+{
+    /* first should open the file and read one line at a time.. */
+    FILE* includeFile;
+    char line[102400], *cp;
+
+    if(strlen(arg)<1) {
+        fprintf(stderr,"Error in source command use a filename\n");
+        return -1;
+    }
+    
+    includeFile = fopen (arg, "r");
+    
+    if(!includeFile) {
+        fprintf(stderr,"Unable to open file %s for reading\n",arg);
+        return -1;
+    }
+    
+    while(!feof(includeFile)) {
+        memset(line,0,sizeof(line));
+        fgets(line,sizeof(line),includeFile);
+        
+        if(strlen(line) < 2) continue;
+        if(line[0] == '#') continue;
+        
+        if ((cp = strrchr (line, '\n')))
+            *cp = '\0';
+	
+	if( echo ) {
+	    printf( "processing line: %s\n",line );
+	};
+        process_cmd_line(line);
+    }
+    
+    if(fclose(includeFile)<0) {
+        perror("unable to close include file");
+        exit(1);
+    }
+    return 1;
+}
+
+int cmd_source_echo(const char* arg)
+{ 
+    cmd_source(arg, 1);
+    return 1;
+}
+
+int cmd_source_noecho(const char* arg)
+{
+    cmd_source(arg, 0);
+    return 1;
+}
+
+
+int cmd_subshell(const char* args)
+{
+    if(strlen(args)) 
+        system(args);
+    else 
+        system(getenv("SHELL"));
+    
+    printf("\n");
+    return 1;
+}
+
+int cmd_set_berfile(const char *arg)
+{
+    if (ber_file && ber_file != stdout && ber_file != stderr)
+        fclose(ber_file);
+    if (!strcmp(arg, ""))
+        ber_file = 0;
+    else if (!strcmp(arg, "-"))
+        ber_file = stdout;
+    else
+        ber_file = fopen(arg, "a");
+    return 1;
+}
+
+int cmd_set_apdufile(const char *arg)
+{
+    if(apdu_file && apdu_file != stderr && apdu_file != stderr)
+        fclose(apdu_file);
+    if (!strcmp(arg, ""))
+        apdu_file = 0;
+    else if (!strcmp(arg, "-"))
+        apdu_file = stderr;
+    else
+    {
+        apdu_file = fopen(arg, "a");
+        if (!apdu_file)
+            perror("unable to open apdu log file");
+    }
+    if (apdu_file)
+        odr_setprint(print, apdu_file);
+    return 1;
+}
+
+int cmd_set_cclfile(const char* arg)
+{  
+    FILE *inf;
+
+    bibset = ccl_qual_mk (); 
+    inf = fopen (arg, "r");
+    if (!inf)
+        perror("unable to open CCL file");
+    else
+    {
+        ccl_qual_file (bibset, inf);
+        fclose (inf);
+    }
+    strcpy(ccl_fields,arg);
+    return 0;
+}
+
+int cmd_set_cqlfile(const char* arg)
+{
+    cql_transform_t newcqltrans;
+
+    if ((newcqltrans = cql_transform_open_fname(arg)) == 0) {
+        perror("unable to open CQL file");
+	return 0;
+    }
+    if (cqltrans != 0)
+	cql_transform_close(cqltrans);
+
+    cqltrans = newcqltrans;
+    strcpy(cql_fields, arg);
+    return 0;
+}
+
+int cmd_set_auto_reconnect(const char* arg)
+{  
+    if(strlen(arg)==0) {
+        auto_reconnect = ! auto_reconnect;
+    } else if(strcmp(arg,"on")==0) {
+        auto_reconnect = 1;
+    } else if(strcmp(arg,"off")==0) {
+        auto_reconnect = 0;		
+    } else {
+        printf("Error use on or off\n");
+        return 1;
+    }
+    
+    if (auto_reconnect)
+        printf("Set auto reconnect enabled.\n");
+    else
+        printf("Set auto reconnect disabled.\n");
+    
+    return 0;
+}
+
+int cmd_set_marcdump(const char* arg)
+{
+    if(marc_file && marc_file != stderr) { /* don't close stdout*/
+        fclose(marc_file);
+    }
+
+    if (!strcmp(arg, ""))
+        marc_file = 0;
+    else if (!strcmp(arg, "-"))
+        marc_file = stderr;
+    else
+    {
+        marc_file = fopen(arg, "a");
+        if (!marc_file)
+            perror("unable to open marc log file");
+    }
+    return 1;
+}
+
+/* 
+   this command takes 3 arge {name class oid} 
+*/
+int cmd_register_oid(const char* args) {
+    static struct {
+        char* className;
+        oid_class oclass;
+    } oid_classes[] = {
+        {"appctx",CLASS_APPCTX},
+        {"absyn",CLASS_ABSYN},
+        {"attset",CLASS_ATTSET},
+        {"transyn",CLASS_TRANSYN},
+        {"diagset",CLASS_DIAGSET},
+        {"recsyn",CLASS_RECSYN},
+        {"resform",CLASS_RESFORM},
+        {"accform",CLASS_ACCFORM},
+        {"extserv",CLASS_EXTSERV},
+        {"userinfo",CLASS_USERINFO},
+        {"elemspec",CLASS_ELEMSPEC},
+        {"varset",CLASS_VARSET},
+        {"schema",CLASS_SCHEMA},
+        {"tagset",CLASS_TAGSET},
+        {"general",CLASS_GENERAL},
+        {0,(enum oid_class) 0}
+    };
+    char oname_str[101], oclass_str[101], oid_str[101];  
+    char* name;
+    int i;
+    oid_class oidclass = CLASS_GENERAL;
+    int val = 0, oid[OID_SIZE];
+    struct oident * new_oident=NULL;
+    
+    if (sscanf (args, "%100[^ ] %100[^ ] %100s",
+                oname_str,oclass_str, oid_str) < 1) {
+        printf("Error in register command \n");
+        return 0;
+    }
+    
+    for (i = 0; oid_classes[i].className; i++) {
+        if (!strcmp(oid_classes[i].className, oclass_str))
+        {
+            oidclass=oid_classes[i].oclass;
+            break;
+        }
+    }
+    
+    if(!(oid_classes[i].className)) {
+        printf("Unknown oid class %s\n",oclass_str);
+        return 0;
+    }
+    
+    i = 0;
+    name = oid_str;
+    val = 0;
+    
+    while (isdigit (*(unsigned char *) name))
+    {
+        val = val*10 + (*name - '0');
+        name++;
+        if (*name == '.')
+        {
+            if (i < OID_SIZE-1)
+                oid[i++] = val;
+            val = 0;
+            name++;
+        }
+    }
+    oid[i] = val;
+    oid[i+1] = -1;
+    
+    new_oident = oid_addent (oid, PROTO_GENERAL, oidclass, oname_str,
+			     VAL_DYNAMIC);  
+    if(strcmp(new_oident->desc,oname_str))
+    {
+        fprintf(stderr,"oid is already named as %s, registration failed\n",
+                new_oident->desc);
+    }
+    return 1;  
+}
+
+int cmd_push_command(const char* arg) 
+{
+    
+#if HAVE_READLINE_HISTORY_H
+    if(strlen(arg)>1) 
+        add_history(arg);
+#else 
+    fprintf(stderr,"Not compiled with the readline/history module\n");
+#endif
+    return 1;
+}
+
+void source_rcfile() 
+{
+    /*  Look for a $HOME/.yazclientrc and source it if it exists */
+    struct stat statbuf;
+    char buffer[1000];
+    char* homedir=getenv("HOME");
+
+    if( homedir ) {
+	
+	sprintf(buffer,"%s/.yazclientrc",homedir);
+
+	if(stat(buffer,&statbuf)==0) {
+	    cmd_source(buffer, 0 );
+	}
+	
+    };
+    
+    if(stat(".yazclientrc",&statbuf)==0) {
+        cmd_source(".yazclientrc", 0 );
+    }
+}
+
+
+void z_initialize(void)
+{
+    FILE *inf;
+    int i;
+    
+    if (!(out = odr_createmem(ODR_ENCODE)) ||
+        !(in = odr_createmem(ODR_DECODE)) ||
+        !(print = odr_createmem(ODR_PRINT)))
+    {
+        fprintf(stderr, "failed to allocate ODR streams\n");
+        exit(1);
+    }
+    oid_init();
+    
+    setvbuf(stdout, 0, _IONBF, 0);
+    if (apdu_file)
+        odr_setprint(print, apdu_file);
+
+    bibset = ccl_qual_mk (); 
+    inf = fopen (ccl_fields, "r");
+    if (inf)
+    {
+        ccl_qual_file (bibset, inf);
+        fclose (inf);
+    }
+
+    cqltrans = cql_transform_open_fname(cql_fields);
+    /* If this fails, no problem: we detect cqltrans == 0 later */
+
+#if HAVE_READLINE_READLINE_H
+    rl_attempted_completion_function = (CPPFunction*)readline_completer;
+#endif
+    
+    
+    for(i=0; i<maxOtherInfosSupported; ++i) {
+        extraOtherInfos[i].oidval = -1;
+    }
+    
+    source_rcfile();
+}
+
+
+#if HAVE_GETTIMEOFDAY
+struct timeval tv_start, tv_end;
+#endif
+
+#if HAVE_XML2
+static void handle_srw_record(Z_SRW_record *rec)
+{
+    if (rec->recordPosition)
+    {
+	printf ("pos=%d", *rec->recordPosition);
+	setno = *rec->recordPosition + 1;
+    }
+    if (rec->recordSchema)
+	printf (" schema=%s", rec->recordSchema);
+    printf ("\n");
+    if (rec->recordData_buf && rec->recordData_len)
+    {
+	fwrite(rec->recordData_buf, 1, rec->recordData_len, stdout);
+	if (marc_file)
+	    fwrite (rec->recordData_buf, 1, rec->recordData_len, marc_file);
+    }
+    else
+	printf ("No data!");
+    printf("\n");
+}
+
+static void handle_srw_explain_response(Z_SRW_explainResponse *res)
+{
+    handle_srw_record(&res->record);
+}
+
+static void handle_srw_response(Z_SRW_searchRetrieveResponse *res)
+{
+    int i;
+
+    printf ("Received SRW SearchRetrieve Response\n");
+    
+    for (i = 0; i<res->num_diagnostics; i++)
+    {
+	if (res->diagnostics[i].uri)
+	    printf ("SRW diagnostic %s\n",
+		    res->diagnostics[i].uri);
+	else
+	    printf ("SRW diagnostic missing or could not be decoded\n");
+	if (res->diagnostics[i].message)
+            printf ("Message: %s\n", res->diagnostics[i].message);
+	if (res->diagnostics[i].details)
+            printf ("Details: %s\n", res->diagnostics[i].details);
+    }
+    if (res->numberOfRecords)
+        printf ("Number of hits: %d\n", *res->numberOfRecords);
+    for (i = 0; i<res->num_records; i++)
+	handle_srw_record(res->records + i);
+}
+
+static void handle_srw_scan_term(Z_SRW_scanTerm *term)
+{
+    if (term->displayTerm)
+	printf("%s:", term->displayTerm);
+    else if (term->value)
+	printf("%s:", term->value);
+    else
+	printf("No value:");
+    if (term->numberOfRecords)
+	printf(" %d", *term->numberOfRecords);
+    if (term->whereInList)
+	printf(" %s", term->whereInList);
+    if (term->value && term->displayTerm)
+	printf(" %s", term->value);
+
+    strcpy(last_scan_line, term->value);
+    printf("\n");
+}
+
+static void handle_srw_scan_response(Z_SRW_scanResponse *res)
+{
+    int i;
+
+    printf ("Received SRW Scan Response\n");
+    
+    for (i = 0; i<res->num_diagnostics; i++)
+    {
+	if (res->diagnostics[i].uri)
+	    printf ("SRW diagnostic %s\n",
+		    res->diagnostics[i].uri);
+	else
+	    printf ("SRW diagnostic missing or could not be decoded\n");
+	if (res->diagnostics[i].message)
+            printf ("Message: %s\n", res->diagnostics[i].message);
+	if (res->diagnostics[i].details)
+            printf ("Details: %s\n", res->diagnostics[i].details);
+    }
+    if (res->terms)
+	for (i = 0; i<res->num_terms; i++)
+	    handle_srw_scan_term(res->terms + i);
+}
+
+static void http_response(Z_HTTP_Response *hres)
+{
+    int ret = -1;
+    const char *content_type = z_HTTP_header_lookup(hres->headers,
+                                                    "Content-Type");
+    const char *connection_head = z_HTTP_header_lookup(hres->headers,
+                                                       "Connection");
+    if (content_type && !yaz_strcmp_del("text/xml", content_type, "; "))
+    {
+        Z_SOAP *soap_package = 0;
+        ODR o = odr_createmem(ODR_DECODE);
+        Z_SOAP_Handler soap_handlers[2] = {
+            {"http://www.loc.gov/zing/srw/", 0,
+             (Z_SOAP_fun) yaz_srw_codec},
+            {0, 0, 0}
+        };
+        ret = z_soap_codec(o, &soap_package,
+                           &hres->content_buf, &hres->content_len,
+                           soap_handlers);
+        if (!ret && soap_package->which == Z_SOAP_generic &&
+            soap_package->u.generic->no == 0)
+        {
+            Z_SRW_PDU *sr = soap_package->u.generic->p;
+            if (sr->which == Z_SRW_searchRetrieve_response)
+                handle_srw_response(sr->u.response);
+            else if (sr->which == Z_SRW_explain_response)
+                handle_srw_explain_response(sr->u.explain_response);
+            else if (sr->which == Z_SRW_scan_response)
+                handle_srw_scan_response(sr->u.scan_response);
+            else
+                ret = -1;
+        }
+        else if (soap_package && (soap_package->which == Z_SOAP_fault
+                          || soap_package->which == Z_SOAP_error))
+        {
+            printf ("HTTP Error Status=%d\n", hres->code);
+            printf ("SOAP Fault code %s\n",
+                    soap_package->u.fault->fault_code);
+            printf ("SOAP Fault string %s\n", 
+                    soap_package->u.fault->fault_string);
+	    if (soap_package->u.fault->details)
+		printf ("SOAP Details %s\n", 
+			soap_package->u.fault->details);
+        }
+        else
+            ret = -1;
+        odr_destroy(o);
+    }
+    if (ret)
+    {
+        if (hres->code != 200)
+        {
+	    printf ("HTTP Error Status=%d\n", hres->code);
+        }
+        else
+        {
+            printf ("Decoding of SRW package failed\n");
+        }
+        close_session();
+    }
+    else
+    {
+	if (!strcmp(hres->version, "1.0"))
+	{
+	    /* HTTP 1.0: only if Keep-Alive we stay alive.. */
+	    if (!connection_head || strcmp(connection_head, "Keep-Alive"))
+		close_session();
+	}
+	else 
+	{
+	    /* HTTP 1.1: only if no close we stay alive .. */
+	    if (connection_head && !strcmp(connection_head, "close"))
+		close_session();
+	}
+    }
+}
+#endif
+
+void wait_and_handle_response() 
+{
+    int reconnect_ok = 1;
+    int res;
+    char *netbuffer= 0;
+    int netbufferlen = 0;
+    Z_GDU *gdu;
+    
+    while(conn)
+    {
+        res = cs_get(conn, &netbuffer, &netbufferlen);
+        if (reconnect_ok && res <= 0 && protocol == PROTO_HTTP)
+        {
+            cs_close(conn);
+            conn = 0;
+            cmd_open(0);
+            reconnect_ok = 0;
+            if (conn)
+            {
+                char *buf_out;
+                int len_out;
+                
+                buf_out = odr_getbuf(out, &len_out, 0);
+                
+		do_hex_dump(buf_out, len_out);
+
+                cs_put(conn, buf_out, len_out);
+                
+                odr_reset(out);
+                continue;
+            }
+        }
+        else if (res <= 0)
+        {
+            printf("Target closed connection\n");
+            close_session();
+            break;
+        }
+        odr_reset(out);
+        odr_reset(in); /* release APDU from last round */
+        record_last = 0;
+        do_hex_dump(netbuffer, res);
+        odr_setbuf(in, netbuffer, res, 0);
+        
+        if (!z_GDU(in, &gdu, 0, 0))
+        {
+            FILE *f = ber_file ? ber_file : stdout;
+            odr_perror(in, "Decoding incoming APDU");
+            fprintf(f, "[Near %d]\n", odr_offset(in));
+            fprintf(f, "Packet dump:\n---------\n");
+            odr_dumpBER(f, netbuffer, res);
+            fprintf(f, "---------\n");
+            if (apdu_file)
+	    {
+                z_GDU(print, &gdu, 0, 0);
+		odr_reset(print);
+	    }
+            if (conn && cs_more(conn))
+                continue;
+	    break;
+        }
+        if (ber_file)
+            odr_dumpBER(ber_file, netbuffer, res);
+        if (apdu_file && !z_GDU(print, &gdu, 0, 0))
+        {
+            odr_perror(print, "Failed to print incoming APDU");
+            odr_reset(print);
+	    continue;
+        }
+        if (gdu->which == Z_GDU_Z3950)
+        {
+            Z_APDU *apdu = gdu->u.z3950;
+            switch(apdu->which)
+            {
+            case Z_APDU_initResponse:
+		// kjdon copying johnmcp
+		/* save session parameters for later use */
+		session_mem = odr_extract_mem(in);
+		session = apdu->u.initResponse;
+		// greenstone will call z_get_initResponse to get the info
+		// about what happened with the connection
+                //process_initResponse(apdu->u.initResponse);
+                break;
+            case Z_APDU_searchResponse:
+                process_searchResponse(apdu->u.searchResponse);
+                break;
+            case Z_APDU_scanResponse:
+                process_scanResponse(apdu->u.scanResponse);
+                break;
+            case Z_APDU_presentResponse:
+                print_refid (apdu->u.presentResponse->referenceId);
+                setno +=
+                    *apdu->u.presentResponse->numberOfRecordsReturned;
+                if (apdu->u.presentResponse->records)
+                    display_records(apdu->u.presentResponse->records);
+                else
+                    printf("No records.\n");
+                printf ("nextResultSetPosition = %d\n",
+                        *apdu->u.presentResponse->nextResultSetPosition);
+                break;
+            case Z_APDU_sortResponse:
+                process_sortResponse(apdu->u.sortResponse);
+                break;
+            case Z_APDU_extendedServicesResponse:
+                printf("Got extended services response\n");
+                process_ESResponse(apdu->u.extendedServicesResponse);
+                break;
+            case Z_APDU_close:
+                printf("Target has closed the association.\n");
+                process_close(apdu->u.close);
+                break;
+            case Z_APDU_resourceControlRequest:
+                process_resourceControlRequest
+                    (apdu->u.resourceControlRequest);
+                break;
+            case Z_APDU_deleteResultSetResponse:
+                process_deleteResultSetResponse(apdu->u.
+                                                deleteResultSetResponse);
+                break;
+            default:
+                printf("Received unknown APDU type (%d).\n", 
+                       apdu->which);
+                close_session ();
+            }
+        }
+#if HAVE_XML2
+        else if (gdu->which == Z_GDU_HTTP_Response)
+        {
+            http_response(gdu->u.HTTP_Response);
+        }
+#endif
+        if (conn && !cs_more(conn))
+            break;
+    } // while conn
+    if (conn)
+    {
+#if HAVE_GETTIMEOFDAY
+        gettimeofday (&tv_end, 0);
+#if 0
+        printf ("S/U S/U=%ld/%ld %ld/%ld",
+                (long) tv_start.tv_sec,
+                (long) tv_start.tv_usec,
+                (long) tv_end.tv_sec,
+                (long) tv_end.tv_usec);
+#endif
+        printf ("Elapsed: %.6f\n",
+                (double) tv_end.tv_usec / 1e6 + tv_end.tv_sec -
+                ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
+#endif
+    }
+    xfree (netbuffer);
+}
+
+
+int cmd_cclparse(const char* arg) 
+{
+    int error, pos;
+    struct ccl_rpn_node *rpn=NULL;
+    
+    
+    rpn = ccl_find_str (bibset, arg, &error, &pos);
+    
+    if (error) {
+        printf ("%*s^ - ", 3+strlen(last_cmd)+1+pos, " ");
+        printf ("%s\n", ccl_err_msg (error));
+    }
+    else
+    {
+        if (rpn)
+        {	
+            ccl_pr_tree(rpn, stdout); 
+        }
+    }
+    if (rpn)
+        ccl_rpn_delete(rpn);
+    
+    printf ("\n");
+    
+    return 0;
+}
+
+
+int cmd_set_otherinfo(const char* args)
+{
+    char oidstr[101], otherinfoString[101];
+    int otherinfoNo;
+    int sscan_res;
+    int oidval;
+    
+    sscan_res = sscanf (args, "%d %100[^ ] %100s", &otherinfoNo, oidstr, otherinfoString);
+    if (sscan_res==1) {
+        /* reset this otherinfo */
+        if(otherinfoNo>=maxOtherInfosSupported) {
+            printf("Error otherinfo index to large (%d>%d)\n",
+		   otherinfoNo,maxOtherInfosSupported);
+        }
+        extraOtherInfos[otherinfoNo].oidval = -1;
+        if (extraOtherInfos[otherinfoNo].value)
+	    free(extraOtherInfos[otherinfoNo].value);	 		
+        return 0;
+    }
+    if (sscan_res<3) {
+        printf("Error in set_otherinfo command \n");
+        return 0;
+    }
+    
+    if (otherinfoNo>=maxOtherInfosSupported) {
+        printf("Error otherinfo index to large (%d>%d)\n",
+	       otherinfoNo,maxOtherInfosSupported);
+    }
+    
+    oidval = oid_getvalbyname (oidstr);
+    if (oidval == -1 ) {
+        printf("Error in set_otherinfo command unknown oid %s \n",oidstr);
+        return 0;
+    }
+    extraOtherInfos[otherinfoNo].oidval = oidval;
+    if(extraOtherInfos[otherinfoNo].value) free(extraOtherInfos[otherinfoNo].value);
+    extraOtherInfos[otherinfoNo].value = strdup(otherinfoString);
+    
+    return 0;
+}
+
+int cmd_sleep(const char* args ) 
+{
+    int sec=atoi(args);
+    if( sec > 0 ) {
+#ifdef WIN32
+	Sleep(sec*1000);
+#else
+	sleep(sec);
+#endif
+	printf("Done sleeping %d seconds\n", sec);	
+    }
+    return 1;    
+}
+
+int cmd_list_otherinfo(const char* args)
+{
+    int i;	   
+    
+    if(strlen(args)>0) {
+        i = atoi(args);
+        if( i >= maxOtherInfosSupported ) {
+            printf("Error otherinfo index to large (%d>%d)\n",i,maxOtherInfosSupported);
+            return 0;
+        }
+
+        if(extraOtherInfos[i].oidval != -1) 
+            printf("  otherinfo %d %s %s\n",
+                   i,
+                   yaz_z3950_oid_value_to_str(
+                       (enum oid_value) extraOtherInfos[i].oidval,
+                       CLASS_RECSYN),
+                   extraOtherInfos[i].value);
+        
+    } else {		
+        for(i=0; i<maxOtherInfosSupported; ++i) {
+            if(extraOtherInfos[i].oidval != -1) 
+                printf("  otherinfo %d %s %s\n",
+                       i,
+                       yaz_z3950_oid_value_to_str(
+                           (enum oid_value) extraOtherInfos[i].oidval,
+                           CLASS_RECSYN),
+                       extraOtherInfos[i].value);
+        }
+        
+    }
+    return 0;
+}
+
+
+int cmd_list_all(const char* args) {
+    int i;
+    
+    /* connection options */
+    if(conn) {
+        printf("Connected to         : %s\n",last_open_command);
+    } else {
+        if(last_open_command) 
+            printf("Not connected to     : %s\n",last_open_command);
+        else 
+            printf("Not connected        : \n");
+        
+    }
+    if(yazProxy) printf("using proxy          : %s\n",yazProxy);		
+    
+    printf("auto_reconnect       : %s\n",auto_reconnect?"on":"off");
+    
+    if (!auth) {
+        printf("Authentication       : none\n");
+    } else {
+        switch(auth->which) {
+        case Z_IdAuthentication_idPass:
+            printf("Authentication       : IdPass\n"); 
+            printf("    Login User       : %s\n",auth->u.idPass->userId?auth->u.idPass->userId:"");
+            printf("    Login Group      : %s\n",auth->u.idPass->groupId?auth->u.idPass->groupId:"");
+            printf("    Password         : %s\n",auth->u.idPass->password?auth->u.idPass->password:"");
+            break;
+        case Z_IdAuthentication_open:
+            printf("Authentication       : psOpen\n");			
+            printf("    Open string      : %s\n",auth->u.open);	
+            break;
+        default:
+            printf("Authentication       : Unknown\n");
+        }
+    }
+    if (negotiationCharset)
+        printf("Neg. Character set   : `%s'\n", negotiationCharset);
+    
+    /* bases */
+    printf("Bases                : ");
+    for (i = 0; i<num_databaseNames; i++) printf("%s ",databaseNames[i]);
+    printf("\n");
+    
+    /* Query options */
+    printf("CCL file             : %s\n",ccl_fields);
+    printf("CQL file             : %s\n",cql_fields);
+    printf("Query type           : %s\n",query_type_as_string(queryType));
+    
+    printf("Named Result Sets    : %s\n",setnumber==-1?"off":"on");
+    
+    /* piggy back options */
+    printf("ssub/lslb/mspn       : %d/%d/%d\n",smallSetUpperBound,largeSetLowerBound,mediumSetPresentNumber);
+    
+    /* print present related options */
+    printf("Format               : %s\n",yaz_z3950_oid_value_to_str(recordsyntax,CLASS_RECSYN));
+    printf("Schema               : %s\n",record_schema ? record_schema : "not set");
+    printf("Elements             : %s\n",elementSetNames?elementSetNames->u.generic:"");
+    
+    /* loging options */
+    printf("APDU log             : %s\n",apdu_file?"on":"off");
+    printf("Record log           : %s\n",marc_file?"on":"off");
+    
+    /* other infos */
+    printf("Other Info: \n");
+    cmd_list_otherinfo("");
+    
+    return 0;
+}
+
+int cmd_clear_otherinfo(const char* args) 
+{
+    if(strlen(args)>0) {
+        int otherinfoNo;
+        otherinfoNo = atoi(args);
+        if( otherinfoNo >= maxOtherInfosSupported ) {
+            printf("Error otherinfo index to large (%d>%d)\n",otherinfoNo,maxOtherInfosSupported);
+            return 0;
+        }
+        
+        if(extraOtherInfos[otherinfoNo].oidval != -1) {			
+            /* only clear if set. */
+            extraOtherInfos[otherinfoNo].oidval=-1;
+            free(extraOtherInfos[otherinfoNo].value);
+        }
+    } else {
+        int i;
+	
+        for(i=0; i<maxOtherInfosSupported; ++i) {
+            if (extraOtherInfos[i].oidval!=-1 ) {				
+                extraOtherInfos[i].oidval=-1;
+                free(extraOtherInfos[i].value);
+            }
+        }
+    }
+    return 0;
+}
+
+static int cmd_help (const char *line);
+
+typedef char *(*completerFunctionType)(const char *text, int state);
+
+static struct {
+    char *cmd;
+    int (*fun)(const char *arg);
+    char *ad;
+    completerFunctionType rl_completerfunction;
+    int complete_filenames;
+    char **local_tabcompletes;
+} cmd_array[] = {
+    {"open", cmd_open, "('tcp'|'ssl')':<host>[':'<port>][/<db>]",NULL,0,NULL},
+    {"quit", cmd_quit, "",NULL,0,NULL},
+    {"find", cmd_find, "<query>",NULL,0,NULL},
+    {"delete", cmd_delete, "<setname>",NULL,0,NULL},
+    {"base", cmd_base, "<base-name>",NULL,0,NULL},
+    {"show", cmd_show, "<rec#>['+'<#recs>['+'<setname>]]",NULL,0,NULL},
+    {"scan", cmd_scan, "<term>",NULL,0,NULL},
+    {"scanstep", cmd_scanstep, "<size>",NULL,0,NULL},
+    {"scanpos", cmd_scanpos, "<size>",NULL,0,NULL},
+    {"scansize", cmd_scansize, "<size>",NULL,0,NULL},
+    {"sort", cmd_sort, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
+    {"sort+", cmd_sort_newset, "<sortkey> <flag> <sortkey> <flag> ...",NULL,0,NULL},
+    {"authentication", cmd_authentication, "<acctstring>",NULL,0,NULL},
+    {"lslb", cmd_lslb, "<largeSetLowerBound>",NULL,0,NULL},
+    {"ssub", cmd_ssub, "<smallSetUpperBound>",NULL,0,NULL},
+    {"mspn", cmd_mspn, "<mediumSetPresentNumber>",NULL,0,NULL},
+    {"status", cmd_status, "",NULL,0,NULL},
+    {"setnames", cmd_setnames, "",NULL,0,NULL},
+    {"cancel", cmd_cancel, "",NULL,0,NULL},
+    {"cancel_find", cmd_cancel_find, "<query>",NULL,0,NULL},
+    {"format", cmd_format, "<recordsyntax>",complete_format,0,NULL},
+    {"schema", cmd_schema, "<schema>",complete_schema,0,NULL},
+    {"elements", cmd_elements, "<elementSetName>",NULL,0,NULL},
+    {"close", z_cmd_close, "",NULL,0,NULL},
+    {"attributeset", cmd_attributeset, "<attrset>",complete_attributeset,0,NULL},
+    {"querytype", cmd_querytype, "<type>",complete_querytype,0,NULL},
+    {"refid", cmd_refid, "<id>",NULL,0,NULL},
+    {"itemorder", cmd_itemorder, "ill|item <itemno>",NULL,0,NULL},
+    {"update", cmd_update, "<action> <recid> [<file>]",NULL,0,NULL},
+    {"update0", cmd_update0, "<action> <recid> [<file>]",NULL,0,NULL},
+    {"packagename", cmd_packagename, "<packagename>",NULL,0,NULL},
+    {"proxy", cmd_proxy, "[('tcp'|'ssl')]<host>[':'<port>]",NULL,0,NULL},
+    {"charset", cmd_charset, "<nego_charset> <output_charset>",NULL,0,NULL},
+    {"negcharset", cmd_negcharset, "<nego_charset>",NULL,0,NULL},
+    {"displaycharset", cmd_displaycharset, "<output_charset>",NULL,0,NULL},
+    {"marccharset", cmd_marccharset, "<charset_name>",NULL,0,NULL},
+    {"lang", cmd_lang, "<language_code>",NULL,0,NULL},
+    {".", cmd_source_echo, "<filename>",NULL,1,NULL},
+    {"!", cmd_subshell, "Subshell command",NULL,1,NULL},
+    {"set_apdufile", cmd_set_apdufile, "<filename>",NULL,1,NULL},
+    {"set_berfile", cmd_set_berfile, "<filename>",NULL,1,NULL},
+    {"set_marcdump", cmd_set_marcdump," <filename>",NULL,1,NULL},
+    {"set_cclfile", cmd_set_cclfile," <filename>",NULL,1,NULL},
+    {"set_cqlfile", cmd_set_cqlfile," <filename>",NULL,1,NULL},
+    {"set_auto_reconnect", cmd_set_auto_reconnect," on|off",complete_auto_reconnect,1,NULL},
+    {"set_otherinfo", cmd_set_otherinfo,"<otherinfoinddex> <oid> <string>",NULL,0,NULL},
+    {"sleep", cmd_sleep,"<seconds>",NULL,0,NULL},
+    {"register_oid", cmd_register_oid,"<name> <class> <oid>",NULL,0,NULL},
+    {"push_command", cmd_push_command,"<command>",command_generator,0,NULL},
+    {"register_tab", cmd_register_tab,"<commandname> <tab>",command_generator,0,NULL},
+    {"cclparse", cmd_cclparse,"<ccl find command>",NULL,0,NULL},
+    {"list_otherinfo",cmd_list_otherinfo,"[otherinfoinddex]",NULL,0,NULL},
+    {"list_all",cmd_list_all,"",NULL,0,NULL},
+    {"clear_otherinfo",cmd_clear_otherinfo,"",NULL,0,NULL},
+    /* Server Admin Functions */
+    /*    {"adm-reindex", cmd_adm_reindex, "<database-name>",NULL,0,NULL},
+    {"adm-truncate", cmd_adm_truncate, "('database'|'index')<object-name>",NULL,0,NULL},
+    {"adm-create", cmd_adm_create, "",NULL,0,NULL},
+    {"adm-drop", cmd_adm_drop, "('database'|'index')<object-name>",NULL,0,NULL},
+    {"adm-import", cmd_adm_import, "<record-type> <dir> <pattern>",NULL,0,NULL},
+    {"adm-refresh", cmd_adm_refresh, "",NULL,0,NULL},
+    {"adm-commit", cmd_adm_commit, "",NULL,0,NULL},
+    {"adm-shutdown", cmd_adm_shutdown, "",NULL,0,NULL},
+    {"adm-startup", cmd_adm_startup, "",NULL,0,NULL},*/
+    {"explain", cmd_explain, "", NULL, 0, NULL},
+    {"options", cmd_options, "", NULL, 0, NULL},
+    {"zversion", cmd_zversion, "", NULL, 0, NULL},
+    {"help", cmd_help, "", NULL,0,NULL},
+    {"init", cmd_init, "", NULL,0,NULL},
+    {0,0,0,0,0,0}
+};
+
+static int cmd_help (const char *line)
+{
+    int i;
+    char topic[21];
+    
+    *topic = 0;
+    sscanf (line, "%20s", topic);
+
+    if (*topic == 0)
+        printf("Commands:\n");
+    for (i = 0; cmd_array[i].cmd; i++)
+        if (*topic == 0 || strcmp (topic, cmd_array[i].cmd) == 0)
+            printf("   %s %s\n", cmd_array[i].cmd, cmd_array[i].ad);
+    if (strcmp (topic, "find") == 0)
+    {
+        printf ("RPN:\n");
+        printf (" \"term\"                        Simple Term\n");
+        printf (" @attr [attset] type=value op  Attribute\n");
+        printf (" @and opl opr                  And\n");
+        printf (" @or opl opr                   Or\n");
+        printf (" @not opl opr                  And-Not\n");
+        printf (" @set set                      Result set\n");
+        printf ("\n");
+        printf ("Bib-1 attribute types\n");
+        printf ("1=Use:         ");
+        printf ("4=Title 7=ISBN 8=ISSN 30=Date 62=Abstract 1003=Author 1016=Any\n");
+        printf ("2=Relation:    ");
+        printf ("1<   2<=  3=  4>=  5>  6!=  102=Relevance\n");
+        printf ("3=Position:    ");
+        printf ("1=First in Field  2=First in subfield  3=Any position\n");
+        printf ("4=Structure:   ");
+        printf ("1=Phrase  2=Word  3=Key  4=Year  5=Date  6=WordList\n");
+        printf ("5=Truncation:  ");
+        printf ("1=Right  2=Left  3=L&R  100=No  101=#  102=Re-1  103=Re-2\n");
+        printf ("6=Completeness:");
+        printf ("1=Incomplete subfield  2=Complete subfield  3=Complete field\n");
+    }
+    return 1;
+}
+
+int cmd_register_tab(const char* arg) {
+	
+    char command[101], tabargument[101];
+    int i;
+    int num_of_tabs;
+    char** tabslist;
+    
+    if (sscanf (arg, "%100s %100s", command, tabargument) < 1) {
+        return 0;
+    }
+    
+    /* locate the amdn in the list */
+    for (i = 0; cmd_array[i].cmd; i++) {
+        if (!strncmp(cmd_array[i].cmd, command, strlen(command))) {
+            break;
+        }
+    }
+    
+    if(!cmd_array[i].cmd) { 
+        fprintf(stderr,"Unknown command %s\n",command);
+        return 1;
+    }
+    
+        
+    if(!cmd_array[i].local_tabcompletes)
+        cmd_array[i].local_tabcompletes = (char **) calloc(1,sizeof(char**));
+    
+    num_of_tabs=0;		
+    
+    tabslist = cmd_array[i].local_tabcompletes;
+    for(;tabslist && *tabslist;tabslist++) {
+        num_of_tabs++;
+    }
+    
+    cmd_array[i].local_tabcompletes =  (char **)
+        realloc(cmd_array[i].local_tabcompletes,(num_of_tabs+2)*sizeof(char**));
+    tabslist=cmd_array[i].local_tabcompletes;
+    tabslist[num_of_tabs]=strdup(tabargument);
+    tabslist[num_of_tabs+1]=NULL;
+    return 1;
+}
+
+
+void process_cmd_line(char* line)
+{  
+    int i,res;
+    char word[32], arg[10240];
+    
+#if HAVE_GETTIMEOFDAY
+    gettimeofday (&tv_start, 0);
+#endif
+    
+    if ((res = sscanf(line, "%31s %10239[^;]", word, arg)) <= 0)
+    {
+        strcpy(word, last_cmd);
+        *arg = '\0';
+    }
+    else if (res == 1)
+        *arg = 0;
+    strcpy(last_cmd, word);
+    
+    /* removed tailing spaces from the arg command */
+    { 
+        char* p = arg;
+        char* lastnonspace=NULL;
+        
+        for(;*p; ++p) {
+            if(!isspace(*(unsigned char *) p)) {
+                lastnonspace = p;
+            }
+        }
+        if(lastnonspace) 
+            *(++lastnonspace) = 0;
+    }
+    
+    for (i = 0; cmd_array[i].cmd; i++)
+        if (!strncmp(cmd_array[i].cmd, word, strlen(word)))
+        {
+            res = (*cmd_array[i].fun)(arg);
+            break;
+        }
+    
+    if (!cmd_array[i].cmd) /* dump our help-screen */
+    {
+        printf("Unknown command: %s.\n", word);
+        printf("use help for list of commands\n");
+        /* cmd_help (""); */
+        res = 1;
+    }
+    
+    if(apdu_file) fflush(apdu_file);
+    
+    if (res >= 2)
+        wait_and_handle_response();
+    
+    if(apdu_file)
+        fflush(apdu_file);
+    if(marc_file)
+        fflush(marc_file);
+}
+
+
+char *command_generator(const char *text, int state) 
+{
+    static int idx; 
+    if (state==0) {
+        idx = 0;
+    }
+    for( ; cmd_array[idx].cmd; ++idx) {
+        if (!strncmp(cmd_array[idx].cmd,text,strlen(text))) {
+            ++idx;  /* skip this entry on the next run */
+            return strdup(cmd_array[idx-1].cmd);
+        }
+    }
+    return NULL;
+}
+
+
+/* 
+   This function only known how to complete on the first word
+*/
+char ** readline_completer(char *text, int start, int end) {
+#if HAVE_READLINE_READLINE_H
+
+	completerFunctionType completerToUse;
+	
+    if(start == 0) {
+#if HAVE_READLINE_RL_COMPLETION_MATCHES
+        char** res=rl_completion_matches(text,
+                                      command_generator); 
+#else
+        char** res=completion_matches(text,
+                                      (CPFunction*)command_generator); 
+#endif
+        rl_attempted_completion_over = 1;
+        return res;
+    } else {
+        char arg[10240],word[32];
+        int i=0 ,res;
+        if ((res = sscanf(rl_line_buffer, "%31s %10239[^;]", word, arg)) <= 0) {     
+            rl_attempted_completion_over = 1;
+            return NULL;
+        }
+        
+        for (i = 0; cmd_array[i].cmd; i++) {
+            if (!strncmp(cmd_array[i].cmd, word, strlen(word))) {
+                break;
+            }
+        }
+        
+        if(!cmd_array[i].cmd) return NULL;
+        
+        curret_global_list = cmd_array[i].local_tabcompletes;
+        
+        completerToUse = cmd_array[i].rl_completerfunction;
+        if(completerToUse==NULL)  /* if no pr. command completer is defined use the default completer */
+            completerToUse = default_completer;
+        
+        if(completerToUse) {
+#ifdef HAVE_READLINE_RL_COMPLETION_MATCHES
+            char** res=
+                rl_completion_matches(text,
+                                      completerToUse);
+#else
+            char** res=
+                completion_matches(text,
+                                   (CPFunction*)completerToUse);
+#endif
+            if(!cmd_array[i].complete_filenames) 
+                rl_attempted_completion_over = 1;
+            return res;
+        } else {
+            if(!cmd_array[i].complete_filenames) 
+                rl_attempted_completion_over = 1;
+            return 0;
+        }
+    }
+#else 
+    return 0;
+#endif 
+}
+
+
+static void client(void)
+{
+    char line[10240];
+
+    line[10239] = '\0';
+
+#if HAVE_GETTIMEOFDAY
+    gettimeofday (&tv_start, 0);
+#endif
+
+    while (1)
+    {
+        char *line_in = NULL;
+#if HAVE_READLINE_READLINE_H
+        if (isatty(0))
+        {
+            line_in=readline(C_PROMPT);
+            if (!line_in)
+                break;
+#if HAVE_READLINE_HISTORY_H
+            if (*line_in)
+                add_history(line_in);
+#endif
+            strncpy(line, line_in, 10239);
+            free (line_in);
+        }
+#endif 
+        if (!line_in)
+        {
+            char *end_p;
+            printf (C_PROMPT);
+            fflush(stdout);
+            if (!fgets(line, 10239, stdin))
+                break;
+            if ((end_p = strchr (line, '\n')))
+                *end_p = '\0';
+        }
+        process_cmd_line(line);
+    }
+}
+
+static void show_version(void)
+{
+    char vstr[20];
+
+    yaz_version(vstr, 0);
+    printf ("YAZ version: %s\n", YAZ_VERSION);
+    if (strcmp(vstr, YAZ_VERSION))
+	printf ("YAZ DLL/SO: %s\n", vstr);
+    exit(0);
+}
+
+/*
+int main(int argc, char **argv)
+{
+    char *prog = *argv;
+    char *open_command = 0;
+    char *auth_command = 0;
+    char *arg;
+    int ret;
+    
+#if HAVE_LOCALE_H
+    if (!setlocale(LC_CTYPE, ""))
+        fprintf (stderr, "setlocale failed\n");
+#endif
+#if HAVE_LANGINFO_H
+#ifdef CODESET
+    codeset = nl_langinfo(CODESET);
+#endif
+#endif
+    if (codeset)
+	outputCharset = xstrdup(codeset);
+    
+    ODR_MASK_SET(&z3950_options, Z_Options_search);
+    ODR_MASK_SET(&z3950_options, Z_Options_present);
+    ODR_MASK_SET(&z3950_options, Z_Options_namedResultSets);
+    ODR_MASK_SET(&z3950_options, Z_Options_triggerResourceCtrl);
+    ODR_MASK_SET(&z3950_options, Z_Options_scan);
+    ODR_MASK_SET(&z3950_options, Z_Options_sort);
+    ODR_MASK_SET(&z3950_options, Z_Options_extendedServices);
+    ODR_MASK_SET(&z3950_options, Z_Options_delSet);
+
+    while ((ret = options("k:c:q:a:b:m:v:p:u:t:Vxd:", argv, argc, &arg)) != -2)
+    {
+        switch (ret)
+        {
+        case 0:
+            if (!open_command)
+            {
+                open_command = (char *) xmalloc (strlen(arg)+6);
+                strcpy (open_command, "open ");
+                strcat (open_command, arg);
+            }
+	    else
+	    {
+		fprintf(stderr, "%s: Specify at most one server address\n",
+			prog);
+		exit(1);
+	    }
+            break;
+	case 'd':
+	    dump_file_prefix = arg;
+	    break;
+        case 'k':
+            kilobytes = atoi(arg);
+            break;
+        case 'm':
+            if (!(marc_file = fopen (arg, "a")))
+            {
+                perror (arg);
+                exit (1);
+            }
+            break;
+        case 't':
+            outputCharset = xstrdup(arg);
+            break;
+        case 'c':
+            strncpy (ccl_fields, arg, sizeof(ccl_fields)-1);
+            ccl_fields[sizeof(ccl_fields)-1] = '\0';
+            break;
+        case 'q':
+            strncpy (cql_fields, arg, sizeof(cql_fields)-1);
+            cql_fields[sizeof(cql_fields)-1] = '\0';
+            break;
+        case 'b':
+            if (!strcmp(arg, "-"))
+                ber_file=stderr;
+            else
+                ber_file=fopen(arg, "a");
+            break;
+        case 'a':
+            if (!strcmp(arg, "-"))
+                apdu_file=stderr;
+            else
+                apdu_file=fopen(arg, "a");
+            break;
+	case 'x':
+	    hex_dump = 1;
+	    break;
+        case 'p':
+            yazProxy=strdup(arg);
+            break;
+        case 'u':
+            if (!auth_command)
+            {
+                auth_command = (char *) xmalloc (strlen(arg)+6);
+                strcpy (auth_command, "auth ");
+                strcat (auth_command, arg);
+            }
+            break;
+        case 'v':
+            yaz_log_init(yaz_log_mask_str(arg), "", 0);
+            break;
+        case 'V':
+	    show_version();
+            break;
+        default:
+            fprintf (stderr, "Usage: %s [-m <marclog>] [ -a <apdulog>] "
+                     "[-b berdump] [-c cclfields] \n"
+		     "[-q cqlfields] [-p <proxy-addr>] [-u <auth>] "
+                     "[-k size] [-d dump] [-V] [<server-addr>]\n",
+                     prog);
+            exit (1);
+        }      
+    }
+    z_initialize();
+    if (auth_command)
+    {
+#ifdef HAVE_GETTIMEOFDAY
+        gettimeofday (&tv_start, 0);
+#endif
+        process_cmd_line (auth_command);
+#if HAVE_READLINE_HISTORY_H
+        add_history(auth_command);
+#endif
+        xfree(auth_command);
+    }
+    if (open_command)
+    {
+#ifdef HAVE_GETTIMEOFDAY
+        gettimeofday (&tv_start, 0);
+#endif
+        process_cmd_line (open_command);
+#if HAVE_READLINE_HISTORY_H
+        add_history(open_command);
+#endif
+        xfree(open_command);
+    }
+    client ();
+    exit (0);
+}
+*/
+/*
+ * Local variables:
+ * tab-width: 8
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=8 fdm=marker
+ * vim<600: sw=4 ts=8
+ */
+
+static int z_getAPDU (Z_APDU **ret_apdu) {
+    int res;
+
+    char *netbuffer= 0;
+    int netbufferlen = 0;
+    Z_APDU *apdu;
+    Z_GDU *gdu;
+    
+    if ((res = cs_get(conn, &netbuffer, &netbufferlen)) < 0) {
+	close_session();
+	perror("cs_get");
+	exit(1);
+    }
+    if (!res) {
+	printf("Target closed connection.\n");
+	close_session();
+	exit(1);
+    }
+    odr_reset(in); /* release APDU from last round */
+    record_last = 0;
+    do_hex_dump(netbuffer, res);
+    odr_setbuf(in, netbuffer, res, 0);
+    
+    if (!z_GDU(in, &gdu, 0, 0)) {
+	
+	odr_perror(in, "Decoding incoming APDU");
+	fprintf(stderr, "[Near %d]\n", odr_offset(in));
+	fprintf(stderr, "Packet dump:\n---------\n");
+	odr_dumpBER(stderr, netbuffer, res);
+	fprintf(stderr, "---------\n");
+	if (apdu_file) {
+	    z_GDU(print, &gdu, 0, 0);
+	    odr_reset(print);
+	}
+	xfree(netbuffer);
+	exit(1); /* was break */
+    }
+    xfree(netbuffer);
+    if (apdu_file && !z_GDU(print, &gdu, 0, 0)) {
+	
+	odr_perror(print, "Failed to print incoming APDU");
+	odr_reset(print);
+	return -1; /* was continue */
+    }
+    if (gdu->which == Z_GDU_Z3950) {
+        
+	Z_APDU *apdu = gdu->u.z3950;
+	(*ret_apdu)=apdu;
+	return 0;
+    }
+    /* else a differnet kind of response, which we don't handle */
+    return -1;
+}
+
+/* gets a generic response from the server */
+int z_getnextAPDU () {
+  Z_APDU *apdu;
+  apdu=NULL;
+  
+  z_getAPDU(&apdu);
+
+  switch(apdu->which) {
+      
+  case Z_APDU_initResponse:
+      // kjdon copying johnmcp
+      /* save session parameters for later use */
+      session_mem = odr_extract_mem(in);
+      session = apdu->u.initResponse;
+      // greenstone will call z_get_initResponse to get the info
+      // about what happened with the connection
+      //process_initResponse(apdu->u.initResponse);
+      break;
+  case Z_APDU_searchResponse:
+      process_searchResponse(apdu->u.searchResponse);
+      break;
+  case Z_APDU_scanResponse:
+      process_scanResponse(apdu->u.scanResponse);
+      break;
+  case Z_APDU_presentResponse:
+      print_refid (apdu->u.presentResponse->referenceId);
+      setno +=
+	  *apdu->u.presentResponse->numberOfRecordsReturned;
+      if (apdu->u.presentResponse->records) {
+	  display_records(apdu->u.presentResponse->records);
+	  printf ("nextResultSetPosition = %d\n",
+		  *apdu->u.presentResponse->nextResultSetPosition);
+      }
+      else {
+	  printf("No records.\n");
+      }
+      break;
+  case Z_APDU_sortResponse:
+      process_sortResponse(apdu->u.sortResponse);
+      break;
+  case Z_APDU_extendedServicesResponse:
+      printf("Got extended services response\n");
+      process_ESResponse(apdu->u.extendedServicesResponse);
+      break;
+  case Z_APDU_close:
+      printf("Target has closed the association.\n");
+      process_close(apdu->u.close);
+      break;
+  case Z_APDU_resourceControlRequest:
+      process_resourceControlRequest
+	  (apdu->u.resourceControlRequest);
+      break;
+  case Z_APDU_deleteResultSetResponse:
+      process_deleteResultSetResponse(apdu->u.
+				      deleteResultSetResponse);
+      break;
+  default:
+      printf("Received unknown APDU type (%d).\n", 
+	     apdu->which);
+      close_session ();
+  }
+  return 0;
+ 
+}
+
+/* returns number of records found */
+/*int z_cmd_dosearch(char *search){
+
+}
+*/
+/* returns an array of strings containing record titles. The first element
+   is an int, saying how many titles follow (can be zero). NULL on error. */
+/*char **z_getrecordTitles(int start,int count){
+
+}
+*/
+/* returns a string containing the whole marc record */
+/*char *z_getfullRecord(int record){
+
+}
+*/
+
+
+/* returns number found, arg is query string */
+int z_cmd_dosearch(char *arg)
+{
+  Z_APDU *apdu;
+  int matching;
+  int ret_val;
+  ret_val=send_searchRequest(arg);
+  if (ret_val==-1) {
+    /* prefix query error */
+    return (-1);
+  }
+  z_getAPDU(&apdu);
+  /* check return value??? */
+  if (apdu->which != Z_APDU_searchResponse)
+    {
+      printf("sendsearchRequest() was not replied with a searchResponse!\n");
+      return (-2);
+    }
+  /* let's keep going anyway... */
+  matching=process_searchResponse(apdu->u.searchResponse);
+  /* this assumes we want to take action on failure (-1) here rather than
+     whereever we were called from */
+  return (matching);
+}
+
+/* src must be NULL-terminated */
+static char *safeappendstr(char *dest, size_t *allocsize, 
+			  size_t *offset, char *src) {
+  /* allocsize is the amount of space currently allocated to dest,
+     offset is how far into dest we want to append src */
+  if (*offset + strlen(src) >= *allocsize) {
+    *allocsize+=strlen(src)+64; /* add some extra space to save on reallocs */
+    if ((dest=realloc(dest,*allocsize))==NULL) {
+      fprintf(stderr, "malloc failed while decoding marc record.\n");
+      return (NULL);
+    }
+  }
+  strcpy(dest+(*offset), src);
+  *offset+=strlen(src);
+  return (dest);
+}
+
+static char *getmarcfields(Z_External *p, int titleonly) {
+  /* this code is based on marc_display(), with a couple of lines taken from
+     display_record() in the original client. */
+  /* if titleonly is non-zero, we only get a (the?) title field, otherwise
+     return the whole thing */
+  const char *buf=(char *)p->u.octet_aligned->buf;
+  char *title;      /* our string to return */
+  int title_maxlen=0; /* amount of space currently allocated */
+  int title_curlen=0;    /* amount of space actually used */
+  int entry_p;
+  int record_length;
+  int indicator_length;
+  int identifier_length;
+  int base_address;
+  int length_data_entry;
+  int length_starting;
+  int length_implementation;
+  FILE *outf;
+
+  /*  if (!outf) */
+  outf = stdout;
+
+  /* initialise our title. Start with 64 chars */
+  title_maxlen=64;
+  if((title=malloc(title_maxlen))==NULL) {
+    /* not quite sure where stderr will be going, but.... */
+    fprintf(stderr,"Malloc failed while decoding marc record\n");
+    return NULL;
+  }
+
+  if (!titleonly) {
+    strcpy(title,"<table border=1>\n");
+    title_curlen=strlen(title);
+  }
+  else  title_curlen=0;
+
+  record_length = atoi_n (buf, 5);
+  if (record_length < 25)
+    return (NULL); /* -1 */
+  if (isdigit(buf[10]))
+    indicator_length = atoi_n (buf+10, 1);
+  else
+    indicator_length = 2;
+  if (isdigit(buf[11]))
+    identifier_length = atoi_n (buf+11, 1);
+  else
+    identifier_length = 2;
+  base_address = atoi_n (buf+12, 4);
+  
+  length_data_entry = atoi_n (buf+20, 1);
+  length_starting = atoi_n (buf+21, 1);
+  length_implementation = atoi_n (buf+22, 1);
+  
+  if (0) /* debug */
+    {
+      fprintf (outf, "Record length         %5d\n", record_length);
+      fprintf (outf, "Indicator length      %5d\n", indicator_length);
+      fprintf (outf, "Identifier length     %5d\n", identifier_length);
+      fprintf (outf, "Base address          %5d\n", base_address);
+      fprintf (outf, "Length data entry     %5d\n", length_data_entry);
+      fprintf (outf, "Length starting       %5d\n", length_starting);
+      fprintf (outf, "Length implementation %5d\n", length_implementation);
+    }
+  for (entry_p = 24; buf[entry_p] != ISO2709_FS; )
+    {
+      entry_p += 3+length_data_entry+length_starting;
+      if (entry_p >= record_length)
+	return (NULL); /* -1 */
+    }
+  base_address = entry_p+1;
+  for (entry_p = 24; buf[entry_p] != ISO2709_FS; )
+    {
+      int data_length;
+      int data_offset;
+      int end_offset;
+      int i /*, j*/ ;
+      int startofstring;
+      int whichtag;
+      short int abbrtitle=0;
+      char tag[4];
+      memcpy (tag, buf+entry_p, 3);
+      entry_p += 3;
+      tag[3] = '\0';
+      whichtag=atoi(tag);
+      if (0) /* debug */
+	fprintf (outf, "Tag: ");
+      /* johnmcp 
+	 Relevant tags (for "main entry") - assume only one of these is set,
+	 as we will only return the first one found.
+	 100=personal name
+	 110=corporate name
+	 111=meeting name
+	 130=uniform title
+	 subfields: $a=personal name, $c=title/other, $d=date
+
+	 210=Abbreviated Title
+	 222=Key title
+	 240=uniform title
+	 243=collective uniform title
+	 245=title statement
+	 246=varying form of title
+	 247=former title or title variations
+	 subfields: $a=abbrev. title $b=qualifying info $2=source
+	 .          $6=linkage $8=link field and sequence number.
+      */
+      /*fprintf (outf, "%s ", tag); */
+      data_length = atoi_n (buf+entry_p, length_data_entry);
+      entry_p += length_data_entry;
+      data_offset = atoi_n (buf+entry_p, length_starting);
+      entry_p += length_starting;
+      i = data_offset + base_address;
+      end_offset = i+data_length-1;
+
+      if (0) /* debug */
+	fprintf (outf, " Ind: ");
+
+      /* memcmp (tag,"00",2) is true, then we DON'T have a control tag
+	 ie less than 10. */
+      /*if (memcmp (tag, "00", 2) && indicator_length)
+	{
+	for (j = 0; j<indicator_length; j++)
+	fprintf (outf, "%c", buf[i++]);
+	}
+      */
+      if (whichtag>=10) i+=indicator_length;
+      /* the control fields (<10) don't have leading chars. */
+
+
+      if (0) /* debug */
+	fprintf (outf, " Fields: ");
+
+      /* If we only want the title, then skip other fields */
+      if (titleonly &&(whichtag<200||whichtag>249)) {
+	/* skip this record */
+	continue;
+	i=end_offset;
+      }
+      
+      /* either titleonly is 0, or titleonly is 1 and whichtag is between
+	 200 and 249... */
+      if (!titleonly) {
+	/* This should probably be read in from a separate file.
+	   This is also hard-coded for USMARC/MARC21 fieldnames!!! */
+
+	/* print out what kind of tag this is */
+	char *tagname;
+	char *field_control1="<tr><td>Marc Control Number:</td><td>";
+	char *field_control3="<tr><td>Marc Organisation Code:</td><td>";
+	char *field_control5="<tr><td>Marc record Date Info.:</td><td>";
+	char *field_control8="<tr><td>Control Field (Marc info):</td><td>";
+	char *field_loc_nr="<tr><td>Lib. of Congress control #:</td><td>";
+	char *field_issn="<tr><td>ISSN Number:</td><td>";
+	char *field_catalog="<tr><td>Catalog agency:</td><td>";
+	char *field_lang="<tr><td>3-letter language code(s):</td><td>";
+	char *field_areacode="<tr><td>Geographic Area code:</td><td>";
+	char *field_cn_loc="<tr><td>Lib. of Congress Call #:</td><td>";
+	char *field_cn_dewdec="<tr><td>Dewey Decimal Call #:</td><td>";
+	char *field_cn_other="<tr><td>Other Classification Info.:</td><td>";
+	char *field_cn_gd="<tr><td>Govt. Document Call #:</td><td>";
+	char *field_personalname="<tr><td>Personal Name:</td><td>";
+	char *field_meetingname="<tr><td>Meeting Name:</td><td>";
+	char *field_maintitle="<tr><td>Title:</td><td>";
+	char *field_edition="<tr><td><Edition Information:</td><td>";
+	char *field_publication="<tr><td>Publication Info.:</td><td>";
+	char *field_physdesc="<tr><td>Physical Description:</td><td>";
+	char *field_series_title="<tr><td>Series Title:</td><td>";
+	char *field_series_statement="<tr><td>Series Statement:</td><td>";
+	char *field_note_general="<tr><td>Note:</td><td>";
+	char *field_note_bib="<tr><td>Bibliographic Note:</td><td>";
+	char *field_note_summary="<tr><td>Summary Note:</td><td>";
+	char *field_sub_note="<tr><td>Subject Notes:</td><td>";
+	char *field_sub_topic="<tr><td>Subject - Topic:</td><td>";
+	char *field_sub_geog="<tr><td>Subject - Location:</td><td>";
+	char *field_added_persname="<tr><td>Author Note - Name:</td><td>";
+	char *field_added_corpname="<tr><td>Author - Organisation:</td><td>";
+	char *field_uniform_title="<tr><td>Extra Title Information:</td><td>";
+	char *field_host_item="<tr><td>In:</td><td>";
+	char *field_series_corpname="<tr><td>Series - Organisation:</td><td>";
+	/*char *field_url="<tr><td>Electronic Access</td><td><a href=\"";*/
+	char *field_url="<tr><td>Electronic Access</td><td>";
+	/*char *field_other="<tr><td>(other field):</td><td>";*/
+	char tag_num[100];
+	switch (whichtag) {
+	case (1): {tagname=field_control1;break;}
+	case (3): {tagname=field_control3;break;}
+	case (5): {tagname=field_control5;break;}
+	case (8): {tagname=field_control8;break;}
+	case (10): {tagname=field_loc_nr;break;}
+	case (20): {tagname=field_issn;break;}
+	case (40): {tagname=field_catalog;break;}
+	case (41): {tagname=field_lang;break;}
+	case (43): {tagname=field_areacode;break;}
+	case (50): {tagname=field_cn_loc;break;}
+	case (82): {tagname=field_cn_dewdec;break;}
+	case (84): {tagname=field_cn_other;break;}
+	case (86): {tagname=field_cn_gd;break;}
+	case (100): {tagname=field_personalname;break;}
+	case (111): {tagname=field_meetingname;break;}
+	case (245): {tagname=field_maintitle;break;}
+	case (250): {tagname=field_edition;break;}
+	case (260): {tagname=field_publication;break;}
+	case (300): {tagname=field_physdesc;break;}
+	case (440): {tagname=field_series_title;break;}
+	case (490): {tagname=field_series_statement;break;}
+	case (500): {tagname=field_note_general;break;}
+	case (504): {tagname=field_note_bib;break;}
+	case (520): {tagname=field_note_summary;break;}
+	case (630): {tagname=field_sub_note;break;}
+	case (650): {tagname=field_sub_topic;break;}
+	case (651): {tagname=field_sub_geog;break;}
+	case (700): {tagname=field_added_persname;break;}
+	case (710): {tagname=field_added_corpname;break;}
+	case (730): {tagname=field_uniform_title;break;}
+	case (773): {tagname=field_host_item;break;}
+	case (810): {tagname=field_series_corpname;break;}
+	case (856): {tagname=field_url;break;}
+	default: 
+	  if (whichtag>=90&&whichtag<=99)
+	    tagname="<tr><td>Local Call #:</td><td>";
+	  else {
+	    /*tagname=field_other;*/
+	    
+	    /* The trailing '\0' seems to be necessary...?!? */
+	    sprintf(tag_num,"<tr><td>(field %d)</td><td>\n\0",whichtag);
+	    tagname=tag_num;
+	  }
+	}
+
+	/* add the field type */
+	title=safeappendstr(title, &title_maxlen, &title_curlen, tagname);
+      }
+
+      /* go through current field in current record */
+      while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && i < end_offset)
+	{
+	  /* this loop goes through byte by byte, to find end-of-field or
+	     end-of-record separator tags */
+
+	  /*	  if (memcmp (tag, "00", 2) && identifier_length)*/
+	  if ( ((titleonly==1&&whichtag==245)||(titleonly==0))
+	       && identifier_length)
+	    {
+	      if (buf[i]==ISO2709_IDFS) {
+		/*  this implies sub-fields for this field */
+		/* skip sub-field tag, but wrap $a sub-field with <b> & </b> 
+		   for HTML if titleonly==1 */
+		if (buf[i+1]=='a' && titleonly) {
+		  abbrtitle=1;
+		  title=safeappendstr(title,&title_maxlen,&title_curlen,"<b>");
+		}
+		i+=identifier_length; 
+	      }
+	      /* find end of this (sub-)field */
+	      startofstring=i;
+	      while (buf[i] != ISO2709_RS && buf[i] != ISO2709_IDFS &&
+		     buf[i] != ISO2709_FS && i < end_offset)
+		i++;
+		/*fprintf (outf, "%c", buf[i++]);*/
+
+	      /* this only happens the first time around */
+	      if (i==startofstring) continue;
+
+	      /* now put from $startofstring$ until $i$ into our 
+		 string to return */
+
+	      if (title_curlen+(i-startofstring)>=title_maxlen) {
+		/* we need to make more room - add max(64,needed) bytes */
+		if (title_curlen+(i-startofstring)-title_maxlen>63)
+		  title_maxlen+=(i-startofstring)+1;/*+1 for trailing \0 */
+		else
+		  title_maxlen+=64;
+		if ((title=realloc(title,title_maxlen))==NULL) {
+		  fprintf(stderr,"malloc failed decoding marc record\n");
+		  return (NULL);
+		}
+	      }
+
+	      strncpy(title+title_curlen,buf+startofstring,i-startofstring);
+	      title_curlen+=(i-startofstring);
+	      *(title+title_curlen)='\0';
+	      /* overwrite ISO2709_?S with \0 */
+	      /* *(title+title_curlen+i-startofstring)='\0';*/
+	      /*safeappendstr(title,&title_maxlen,
+		&title_curlen,buf+startofstring);*/
+
+	      /* if 'main' title, close HTML </B> tag */
+	      if (abbrtitle) {
+		title=safeappendstr(title,&title_maxlen,&title_curlen,"</b>");
+		abbrtitle=0;
+	      } 
+	      /* end of this marc sub--field                 
+		 buf[i]==ISO2709_RS if end of  record.
+		 buf[i]==ISO2709_FS if end of  field,
+		 buf[i]==ISO2709_IDFS if end of sub-field. */
+	      if (titleonly==0) {
+		if (buf[i]==ISO2709_IDFS) {
+		  /* there is a following sub-field, so only add whitespace */
+		  title=safeappendstr(title,&title_maxlen,&title_curlen," ");
+		}
+		else {
+		  /* end of record, so close HTML table row */
+#if 0
+		  if (whichtag==856) /* special case: this is a url! */
+		    title=safeappendstr(title,&title_maxlen,&title_curlen,
+					"\">Uniform Resource Locator</a>");
+#endif
+		  title=safeappendstr(title, &title_maxlen, &title_curlen,
+				      "</td></tr>\n");
+		}
+	      }  /* end of  if (titleonly==0)                */
+	    }    /* end of  if ( ((titleonly==1&&.......     */
+	  else { /* whichtag not matched  (if titleonly)     */
+	    /*fprintf (outf, "%c", buf[i++]);*/
+	    /* skip this char for now - should ideally skip whole field */
+	    i++;
+	  }
+	} /* end of while loop - at end of field or record */
+      /*fprintf (outf, "\n");*/
+      /*if (i < end_offset)
+	fprintf (outf, "-- separator but not at end of field\n");
+	if (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS)
+	fprintf (outf, "-- no separator at end of field\n");
+      */
+    }
+
+  /* at end of whole record. */
+  if (!titleonly) 
+    title=safeappendstr(title, &title_maxlen, &title_curlen, "</table>\n");
+  return (title);
+
+}
+static char *getrecordtitle(Z_External *record) {
+  return(getmarcfields(record,1));
+}
+
+char *z_getfullRecord(int start) {
+  Z_APDU *apdu;
+  Z_External *record;
+  char *fullrecord;
+
+  fullrecord=NULL;
+  z_send_getbriefrecords(start,1,1); /* for now, use getbriefrecords */
+  z_getAPDU(&apdu);
+  
+  if (apdu->which != Z_APDU_presentResponse) {
+    /* out-of-order packets.... */
+    fprintf(stderr,"Not a present response to present request\n");
+    return NULL;
+  }
+  
+  /* just do some double checking */
+  if (*apdu->u.presentResponse->numberOfRecordsReturned!=1 ||
+      !apdu->u.presentResponse->records ) {
+    /* something bad has happened... johnmcp */
+    fprintf (stderr,"Error occured in yaz while getting record (GSDL)\n");
+  }
+
+  switch (apdu->u.presentResponse->records->which) {
+  case Z_Records_DBOSD: break; /* do nothing - this is a record */
+
+    /* otherwise we got a diagnostic message... */
+  case Z_Records_NSD:
+    switch (apdu->u.presentResponse->records->u.nonSurrogateDiagnostic->which){
+      /* these are both represented as char* in yaz, so either is OK */
+      /*    case Z_DefaultDiagForm_v2Addinfo:
+	    case Z_DefaultDiagForm_v3Addinfo: --wrong names*/
+    case Z_DiagnosticFormat_s_defaultDiagRec:
+    case Z_DiagnosticFormat_s_explicitDiagnostic:
+      return apdu->u.presentResponse->records->u.nonSurrogateDiagnostic
+	->u.v2Addinfo; /* return the error message */
+    default: ; /* this should happen for v3 of the spec... */
+    }
+  case Z_Records_multipleNSD: ; /* should handle one day... */
+  }
+
+  record=apdu->u.presentResponse->records->u.databaseOrSurDiagnostics->
+    records[0]->u.databaseRecord;
+
+  return(getmarcfields(record,0));
+}
+
+char **z_getrecordTitles(/*int resultset,*/ int starting, int howmany) {
+  Z_APDU *apdu;
+  char **titles;
+  /* titles will be an array of strings. The first element will really
+     be an int, saying how many strings follow. Ie 1st string in titles[1] */
+  int count;
+  int i;
+
+  titles=NULL;
+
+  /* WE SHOULD SET THE RECORD FORMAT SOMEWHERE..... USMARC (default)
+     but may also want SUTRS support. */
+
+  /* sends a presentRequest - we need to know the set number - johnmcp */
+  z_send_getbriefrecords(starting, 1, howmany);
+  /* CHECK RETURN VALUE (currently only 0) */
+  
+
+  z_getAPDU(&apdu);
+  if (apdu->which != Z_APDU_presentResponse) {
+    /* we got out-of-sync.... */
+    fprintf(stderr,"Not a present response to present request\n");
+    return NULL;
+  }
+  
+  print_refid (apdu->u.presentResponse->referenceId);
+  count=*apdu->u.presentResponse->numberOfRecordsReturned;
+  setno += count;
+  if (apdu->u.presentResponse->records) {
+    /* extract the titles from each record, and return it as an array of 
+       strings */
+    if (count==1 &&
+	apdu->u.presentResponse->records->which!=Z_Records_DBOSD) {
+	fprintf(stderr,"only one returned");
+      /* apdu->u.presentResponse->records->which gives a type:
+	 1=databaseOrSurDiagnostics | 2=nonSurrogateDiagnostic | 
+	 3=multipleNonSurDiagnostics.
+	 Type 1 implies it is a database record. FROM z-core.h,
+      NOT prt-proto.h!!!!! */
+
+      /* for type 2:
+	 apdu->u.presentResponse->records->u.nonSurrogateDiagnostic->which:
+	 1=v2Addinfo | 2=v3Addinfo, and u.v[23]Addinfo is a (char *).
+
+      */
+      titles=malloc(sizeof(char *));
+      titles[0]=(char *)0;
+      /* could put error message and titles[1], and set titles[0] to -1. */
+
+
+    }
+    else /* more than 1 rec returned, so ?has? to be db records (dblcheck!!)*/
+      {
+	  fprintf(stderr,"more than one rec returned, count=%d\n", count);
+	titles=malloc(sizeof(char *)*count + 1);
+	/* check malloc succeeded... */
+	titles[0]=(char *)count;
+	for (i=1;i<=count;i++) {
+	  titles[i]=getrecordtitle(apdu->u.presentResponse->records->
+				   u.databaseOrSurDiagnostics->records[i-1]->
+				   u.databaseRecord);
+	}
+      } 
+  }
+  else {
+      fprintf(stderr,"no records retruend");
+    titles=malloc(sizeof(char *));
+    titles[0]=(char *)0;
+  }
+  /*  printf ("nextResultSetPosition = %d\n",
+   *apdu->u.presentResponse->nextResultSetPosition); */
+  return (titles);
+}
+
Index: /gsdl/trunk/runtime-src/src/z3950/yaz_zclient.h
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/yaz_zclient.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/yaz_zclient.h	(revision 16571)
@@ -0,0 +1,32 @@
+#ifndef YAZ_ZCLIENT_H
+#define YAZ_ZCLIENT_H
+/*#include "../include/yaz/z-core.h"*/
+
+
+/* the new yaz_zclient made for use with Greenstone. Based on client.c 
+ * (version 2.1.4) and the old yaz_zclient (version 1.6 for greenstone)
+ */
+void z_initialize(void);
+
+/* creates a connection, given a host and port, and database name */
+int z_cmd_open(char *host_and_port, char *base);
+
+/* returns number of records found */
+int z_cmd_dosearch(char *search);
+
+/* returns an array of strings containing record titles. The first element
+   is an int, saying how many titles follow (can be zero). NULL on error. */
+char **z_getrecordTitles(int start,int count);
+
+/* returns a string containing the whole marc record */
+char *z_getfullRecord(int record);
+
+/* close the connection */
+int z_cmd_close(const char *arg);
+
+/* returns a string containing name, ID, etc, or NULL if not connected */
+char *z_get_initResponse(); 
+
+/* gets a generic response from the server */
+int z_getnextAPDU ();
+#endif 
Index: /gsdl/trunk/runtime-src/src/z3950/z3950_to_gsdl.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950_to_gsdl.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950_to_gsdl.cpp	(revision 16571)
@@ -0,0 +1,345 @@
+/**********************************************************************
+ *
+ * z3950_to_gsdl.cpp --
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "z3950parser.h"
+#include "z3950server.h"
+#include "z3950_to_gsdl.h"
+
+// converts a char* to uppercase, I wouldn't be
+// writing this if I could find an existing
+// function to do it
+void toUpperString(char *&text)
+{
+  for (int i = 0; text[i] != '\0'; i++) {
+    text[i] = toupper(text[i]);
+  }
+}
+
+
+text_t gsdlCollection::getName() 
+{
+  return name;
+}
+
+bool gsdlCollection::z3950Capeable() const
+{
+  return z3950ready;
+}
+
+
+bool gsdlCollection::bib1_to_dc_mapping(text_t& filename)
+{
+    ifstream inFile;
+    int input_Bib1;
+    text_t input_DCES;
+    text_t input_Short;
+
+    char* filename_cstr = filename.getcstr();
+    inFile.open(filename_cstr, ios::in);
+    delete [] filename_cstr;
+
+    if (!inFile) {
+      return false;
+    }
+
+    const int BUFFERSIZE = 1024;
+    char buffer[BUFFERSIZE];
+
+    // read in pairs of values (mappings from Bib-1 to DCES)
+    while (!inFile.eof()) {
+      char input_DCES_tmp[BUFFERSIZE];
+
+      inFile.getline(buffer, BUFFERSIZE, '\n');
+      if (buffer[0] == '#') {
+	// ignore comments (# ...)
+	continue;
+      }
+
+      sscanf(buffer,"%d %s",&input_Bib1, input_DCES_tmp);
+
+      input_DCES = input_DCES_tmp;
+
+      Bib1_to_DCES[input_Bib1] = input_DCES;
+
+      if (z3950_verbosity_>2) {
+	cerr << "(" << input_Bib1 << "/" << input_DCES << ") ";
+      }
+    }
+
+    if (z3950_verbosity_>2) {
+      cerr << endl;
+    }
+    inFile.close();
+
+    return true;
+}
+
+
+bool gsdlCollection::dc_to_short_mapping(text_t& filename, 
+					 text_t& collectionName) 
+{
+    ifstream inFileBuild;
+    text_t input_DCES;
+    text_t input_Short;
+  
+    char* filename_cstr = filename.getcstr();
+    inFileBuild.open(filename_cstr, ios::in);
+    delete [] filename_cstr;
+
+    if (!inFileBuild) {
+      if (z3950_verbosity_>2) {
+	cerr << "Warning: Unable to open: " << filename << endl;
+	cerr << "         Collection " << collectionName << " might not be built" << endl;
+      }
+      return false;
+    }
+
+    const int BUFFERSIZE = 1024;
+    char buffer[BUFFERSIZE];
+
+    // find the indexfieldmap line
+    do {
+      inFileBuild >> buffer;
+      if (inFileBuild.eof()) {
+	if (z3950_verbosity_>1) {
+	  cerr << "Warning: Did not find indexfieldmap in build.cfg for " 
+	       << collectionName << endl;
+	}
+	return false;
+      }
+    } while (strcmp(buffer, "indexfieldmap") != 0);
+
+    // at this stage, buffer contains "indexfieldmap",
+    // if the file didn't contain it, would have returned above
+    inFileBuild >> buffer;
+    while (strstr(buffer, "->") != NULL) {
+      // buffer contains a DCES->Short mapping
+      input_DCES.clear();
+      input_Short.clear();
+
+      // copy in DCES
+      int i;
+      for (i = 0; buffer[i] != '-'; i++) {
+	input_DCES.appendcarr(&(buffer[i]), 1);
+      }
+
+      // skip over "->"
+      i+=2;
+
+      // copy in Short
+      for (; isalpha(buffer[i]); i++) {
+	input_Short.appendcarr(&(buffer[i]), 1);
+      }
+
+      // add to map
+      DCES_to_Short[input_DCES] = input_Short;
+
+      if (z3950_verbosity_>1) {
+	cerr << "<" << input_DCES << "/" << input_Short << "> ";
+      }
+
+      inFileBuild >> buffer;
+    }
+
+    inFileBuild.close();
+
+    if (z3950_verbosity_>1) {
+      cerr << endl;
+    }
+
+    return true;
+}    
+
+
+
+
+  // converts a Bib1 field number to a short index name,
+  // returns true if a mapping existed, false otherwise
+bool gsdlCollection::getFieldArg(int Bib1, text_t &Short) 
+{
+    if (Bib1_to_DCES.count(Bib1) < 1) return false;
+    if (DCES_to_Short.count(Bib1_to_DCES[Bib1]) < 1) return false;
+    Short = DCES_to_Short[Bib1_to_DCES[Bib1]];
+    return true;
+}
+  
+gsdlCollection::~gsdlCollection(void) 
+{
+    //cerr << "gsdlCollection destructor called" << endl;
+}
+
+gsdlCollection::gsdlCollection(void) 
+{
+    //cerr << "gsdlCollection void constructor called" << endl;
+}
+ 
+gsdlCollection::gsdlCollection(text_t collectionName, text_t gsdlhome) 
+{
+
+    //char *filename_cstr;
+    //ifstream inFile;
+    //int inFileSize = 0;
+    z3950ready = true;
+
+    // int input_Bib1;
+    //text_t input_DCES;
+    //text_t input_Short;
+
+    name = collectionName;
+
+    // read in the cfg file for Bib1_to_DCES
+    text_t col_filename = gsdlhome;
+    col_filename.appendcstr("/collect/");
+    col_filename.append(collectionName);
+    col_filename.appendcstr("/etc/bib1_to_dces.cfg");
+
+    if (!bib1_to_dc_mapping(col_filename)) {
+      text_t site_filename = gsdlhome;
+      site_filename.appendcstr("/etc/bib1_to_dces.cfg");
+
+      if (!bib1_to_dc_mapping(site_filename)) {
+	cerr << "Unable to find bib1->dublin core mapping for " 
+	     << collectionName << endl;
+	cerr << "Looked for:\n  " << col_filename << "\n  " 
+	     << site_filename << endl;
+	z3950ready = false;
+	return;
+      }
+    }
+
+    // read in the cfg file for mapping Dublin Core to Short (internal name)
+    text_t build_filename = gsdlhome;
+    build_filename.appendcstr("/collect/");
+    build_filename.append(collectionName);
+    build_filename.appendcstr("/index/build.cfg");
+
+    if (!dc_to_short_mapping(build_filename,collectionName)) {
+      // explicitly check for error (in case in future more work is done after
+      // this
+      z3950ready = false;
+      return;
+    }
+
+}
+
+
+void z3950Server::openLogfile(text_t extension, ofstream &out)
+{
+    char *cfilename;
+    text_t filename;
+
+    filename = filename_cat(gsdlhome, extension);
+    cfilename = filename.getcstr();
+
+    out.open(cfilename);
+    delete cfilename;
+}
+
+z3950Server::z3950Server(nullproto *protocol, text_t home)
+{ 
+
+    text_t dirname;
+    char * cdirname;
+    if (home.empty()) {
+      cerr  << "Z3950Server Error: gsdlhome not set. \nPlease make sure"
+	    << " you have a valid gsdlsite.cfg file in the directory \n"
+	    << "you are running z3950server\n";
+      cerr << "Exiting..."<<endl;
+      exit(1);
+    } 
+    cerr << "Z3950Server: gsdlhome = " << home << endl;
+
+    this->gsdlhome = home;
+    //cerr << gsdlhome.getcstr() << endl;
+    dirname = filename_cat(gsdlhome, "/collect");
+    cdirname = dirname.getcstr();
+    if (!read_dir (cdirname, collections)) { 
+      cerr << "Z3950Server Error: could not read directory "<<cdirname<<endl;
+      cerr << "Exiting..."<<endl;
+      exit (1);
+    }
+    delete cdirname;
+
+    cerr << "Constructing set list server" << endl;
+    this->protocol = protocol;
+
+    // initialise Yaz stuff for z39.50 server 
+}
+  
+bool z3950Server::initialise() 
+{
+      ofstream      logout;
+      int           reply;
+      comerror_t    error = noError;
+
+      this->openLogfile("/etc/z3950out.txt", logout);
+      reply = protocol->init(error, logout);
+      logout.close();
+      return (reply != 0 ? 1 : 0);
+}
+
+void z3950Server::configure(const text_t &key, const text_tarray &cfgline, 
+			    comerror_t &err)
+{
+      err = noError;
+
+      // ****
+      cerr << "Recieved " << key << " = ";
+      for (int unsigned i=0; i<cfgline.size(); i++)
+	{
+	  cout << cfgline[i] << " ";
+	}
+      cout << endl;
+
+      // DB // ****
+      if (key=="gsdlhome")
+	{  
+	  text_tarray cfgline;
+	  cfgline.push_back (gsdlhome);
+	  cerr << "Changing gsdlhome to " << gsdlhome << endl;
+	  protocol->configure(key, cfgline, err);
+	}
+      else if (key=="httpdomain")
+	{
+	  // Only let gsdlhome through !!!! // ****
+	  cerr << "Supressing httpdomain" << endl;
+	}
+      else if (key=="httpprefix")
+	{
+	  cerr << "Supressing httpprefix" << endl;
+	}
+      else
+	{ 
+	  protocol->configure(key, cfgline,err);
+	}
+}
+
+int z3950Server::run_z3950( int argc, char **argv ) 
+{
+
+    const int statserv_var =  statserv_main(argc, argv, bend_init, bend_close);
+    cerr << "statserv_main returns: " << statserv_var << endl;
+    return statserv_var;
+}
Index: /gsdl/trunk/runtime-src/src/z3950/z3950_to_gsdl.h
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950_to_gsdl.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950_to_gsdl.h	(revision 16571)
@@ -0,0 +1,87 @@
+/**********************************************************************
+ *
+ * z3950_to_gsdl.h --
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef Z3950_TO_GSDL_H
+#define Z3950_TO_GSDL_H
+
+
+void toUpperString(char *&text);
+
+class gsdlCollection
+{
+ public:
+  gsdlCollection(); 
+  gsdlCollection(text_t collectionName, text_t gsdlhome);
+  ~gsdlCollection(void);
+
+  bool z3950Capeable() const;
+
+  // converts a Bib1 field number to a short index name,
+  // returns true if a mapping existed, false otherwise
+  bool getFieldArg(int Bib1, text_t &Short);
+
+  text_t getName(); // returns the name of the collection in short form
+  
+ protected:
+
+
+  bool bib1_to_dc_mapping(text_t& filename);
+  bool dc_to_short_mapping(text_t& filename, text_t& collectionName);
+
+ protected:
+  text_t name;
+  map<int, text_t>    Bib1_to_DCES;  // Bib-1 to DC metadata names
+  map<text_t, text_t> DCES_to_Short; // DC to short (2-3 letter) internal name
+
+  bool z3950ready; // is the collection Z39.50-ready ?
+                   // (i.e. does it have the cfg files for mappings)
+
+
+};
+
+class z3950Server 
+{
+protected:
+  text_tarray collections;
+  nullproto *protocol;
+  text_t      gsdlhome;
+
+  // save particular YAZ variables ...
+
+  void openLogfile(text_t extension, ofstream &out);
+
+
+public:
+  z3950Server(nullproto *protocol, text_t home);
+  
+  bool initialise();
+
+  void configure(const text_t &key, const text_tarray &cfgline, comerror_t &err);
+
+  int run_z3950( int argc, char **argv );
+
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/z3950/z3950cfg.h
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950cfg.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950cfg.h	(revision 16571)
@@ -0,0 +1,47 @@
+/*
+  This defines a data structure shared between:
+  * the C++ z3950proto class defined in z3950proto.cpp, and
+  * the C function yyparse() created by bison from the file zparse.fl
+  */
+
+#ifndef _Z3950CFG_H
+#define _Z3950CFG_H
+
+#include <stdio.h> // for FILE* type
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct z3950aboutlist {
+  char *lang;
+  char *text;
+  struct z3950aboutlist *next;
+};
+struct z3950cfg {
+  char *shortname;
+  char *hostname;
+  int port;
+  char *dbname;
+  char *longname;
+  char *icon;
+  char *smallicon;
+  struct z3950aboutlist *about;
+  struct z3950cfg *next;
+};
+extern struct z3950cfg *zserver_list;
+extern FILE *errfile;
+
+/* can't use default yyparse(), as this name is used elsewhere (eg mg)*/
+#define yyin	zconfigin
+#define yyout	zconfigout
+#define yyparse	zconfigparse
+#define yylex	zconfiglex
+
+int yyparse ();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: /gsdl/trunk/runtime-src/src/z3950/z3950explain.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950explain.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950explain.cpp	(revision 16571)
@@ -0,0 +1,209 @@
+/**********************************************************************
+ *
+ * z3950explain.cpp --
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "z3950explain.h"
+
+void getExplainInfo(bend_search_rr *rr, FilterResponse_t &response, comerror_t &err)
+{
+  text_t GSQuery = ZQueryToGSQuery(rr);
+  char *GSQuery_char = GSQuery.getcstr(); 
+
+  int i;
+  if (strstr(GSQuery_char, "TargetInfo") != NULL) {
+    // should be one only
+    // real-life example:
+    /*
+      62
+      explain-category targetInfo
+      date-of-info Sep 22, 1999
+      language eng
+    */
+    ResultDocInfo_t docinfo;
+    docinfo.metadata["explain-category"].values.push_back("TargetInfo");
+    docinfo.metadata["name"].values.push_back("Greenstone");
+    docinfo.metadata["namedResultSets"].values.push_back("false");
+    docinfo.metadata["multipleDBsearch"].values.push_back("true");
+    docinfo.metadata["language"].values.push_back("eng");
+    response.docInfo.push_back(docinfo);
+    response.numDocs++;
+  }
+  if (strstr(GSQuery_char, "DatabaseInfo") != NULL) {
+    // should be one per collection
+    // real-life example:
+    /*
+      3
+      dbnum 0
+      explain-category DatabaseInfo
+      database-name.1 0
+      title Z39.50 EXPLAIN DB
+      database-name.2 ir-explain-1
+      date-of-info Sep 22, 1999
+      language eng
+      dbpath /usr/wald/z39.50root/explain
+      dbname explain
+    */
+    ResultDocInfo_t docinfo;
+    docinfo.metadata["explain-category"].values.push_back("DatabaseInfo");
+    docinfo.metadata["database-name"].values.push_back("IR-Explain-1");
+    docinfo.metadata["title"].values.push_back("Z39.50 EXPLAIN DB");
+    docinfo.metadata["language"].values.push_back("eng");
+    docinfo.metadata["dbname"].values.push_back("explain");
+    response.docInfo.push_back(docinfo);
+    response.numDocs++;
+    // now get the info for each collection
+    text_tarray collectlist;
+    Protocol->get_collection_list(collectlist, err, cerr);
+    text_tarray::iterator COLHERE = collectlist.begin();
+    text_tarray::iterator COLEND = collectlist.end();
+    while (COLHERE != COLEND) {
+      // don't include information for non-active collections
+      bool collection_active;
+      Protocol->ping(*COLHERE, collection_active, err, cerr);
+      if (collection_active != true) {
+	COLHERE++;
+	continue;
+      }
+      ColInfoResponse_t collectinfo;
+      Protocol->get_collectinfo(*COLHERE, collectinfo, err, cerr);
+      docinfo.clear();
+      docinfo.metadata["name"].values.push_back(collectinfo.shortInfo.name);
+      docinfo.metadata["host"].values.push_back(collectinfo.shortInfo.host);
+      if (collectinfo.isPublic) {
+	docinfo.metadata["isPublic"].values.push_back("true");
+      } else {
+	docinfo.metadata["isPublic"].values.push_back("false");
+      }
+      if (collectinfo.isBeta) {
+	docinfo.metadata["isBeta"].values.push_back("true");
+      } else {
+	docinfo.metadata["isBeta"].values.push_back("false");
+      }
+      if (collectinfo.useBook == true) {
+	docinfo.metadata["useBook"].values.push_back("true");
+      } else {
+	docinfo.metadata["useBook"].values.push_back("false");
+      }
+      docinfo.metadata["buildDate"].values.push_back(collectinfo.buildDate);
+      text_tarray::iterator TEXTT_HERE = collectinfo.ccsCols.begin();
+      text_tarray::iterator TEXTT_END = collectinfo.ccsCols.end();
+      for (i = 1; TEXTT_HERE != TEXTT_END; i++, TEXTT_HERE++) {
+	text_t tmp = "ccsCols.";
+	tmp.appendint(i);
+	docinfo.metadata[tmp].values.push_back(*TEXTT_HERE);
+      }
+      TEXTT_HERE = collectinfo.languages.begin();
+      TEXTT_END = collectinfo.languages.end();
+      for (i = 1; TEXTT_HERE != TEXTT_END; i++, TEXTT_HERE++) {
+	text_t tmp = "languages.";
+	tmp.appendint(i);
+	docinfo.metadata[tmp].values.push_back(*TEXTT_HERE);
+      }
+      docinfo.metadata["numDocs"].values.push_back(collectinfo.numDocs);
+      docinfo.metadata["numSections"].values.push_back(collectinfo.numSections);
+      docinfo.metadata["numWords"].values.push_back(collectinfo.numWords);
+      docinfo.metadata["numBytes"].values.push_back(collectinfo.numBytes);
+
+      collectionmeta_map::iterator COLLMETA_MAP_HERE = collectinfo.collectionmeta.begin();
+      collectionmeta_map::iterator COLLMETA_MAP_END = collectinfo.collectionmeta.end();
+      for (i = 1; COLLMETA_MAP_HERE != COLLMETA_MAP_END; i++, COLLMETA_MAP_HERE++) {
+	text_t tmp = "collectionmeta.";
+	tmp.appendint(i);
+	text_t tmp2 = COLLMETA_MAP_HERE->first;
+	tmp2.appendcstr(" -> ");
+	tmp2.append(COLLMETA_MAP_HERE->second[g_EmptyText]);
+	docinfo.metadata[tmp].values.push_back(tmp2);
+      }
+      text_tmap::iterator TEXTT_MAP_HERE;
+      text_tmap::iterator TEXTT_MAP_END;
+      // uncomment if you want to include this in the explain record,
+      // it's a bit messy to include by default
+      /*
+      TEXTT_MAP_HERE = collectinfo.format.begin();
+      TEXTT_MAP_END = collectinfo.format.end();
+      for (i = 1; TEXTT_MAP_HERE != TEXTT_MAP_END; i++, TEXTT_MAP_HERE++) {
+	text_t tmp = "format.";
+	tmp.appendint(i);
+	text_t tmp2 = TEXTT_MAP_HERE->first;
+	tmp2.appendcstr(" -> ");
+	tmp2.append(TEXTT_MAP_HERE->second);
+	docinfo.metadata[tmp].values.push_back(tmp2);
+      }
+      */
+      TEXTT_MAP_HERE = collectinfo.building.begin();
+      TEXTT_MAP_END = collectinfo.building.end();
+      for (i = 1; TEXTT_MAP_HERE != TEXTT_MAP_END; i++, TEXTT_MAP_HERE++) {
+	text_t tmp = "building.";
+	tmp.appendint(i);
+	text_t tmp2 = TEXTT_MAP_HERE->first;
+	tmp2.appendcstr(" -> ");
+	tmp2.append(TEXTT_MAP_HERE->second);
+	docinfo.metadata[tmp].values.push_back(tmp2);
+      }
+      docinfo.metadata["receptionist"].values.push_back(collectinfo.receptionist);
+      docinfo.metadata["buildType"].values.push_back(collectinfo.buildType);
+      response.docInfo.push_back(docinfo);
+      response.numDocs++;
+      COLHERE++;
+    }
+  }
+  if (strstr(GSQuery_char, "SchemaInfo") != NULL) {
+    // should be one per collection
+    // real-life example:
+    /*
+      10
+      dbnum 1
+      explain-category schemaInfo
+      database-name.1 1
+      database-name.2 books
+      database-name.3 default
+      database-name.4 cat
+      date-of-info Sep 22, 1999
+      language eng
+      schema.1 1.2.840.10003.13.1000.3.1
+      dbpath /usr/wald/z39.50root/books
+      dbname books
+     */
+  }
+  if (strstr(GSQuery_char, "AttributeSetInfo") != NULL) {
+    // should be one per collection
+    // real-life example:
+    /*
+      9
+      dbnum 1
+      explain-category AttributeSetInfo
+      database-name.1 1
+      database-name.2 books
+      database-name.3 default
+      database-name.4 cat
+      date-of-info Sep 22, 1999
+      language eng
+      attribute-set.1 1.2.840.10003.13.1000.3.1
+      dbpath /usr/wald/z39.50root/books
+      dbname books
+    */
+  }
+}
+
+
Index: /gsdl/trunk/runtime-src/src/z3950/z3950explain.h
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950explain.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950explain.h	(revision 16571)
@@ -0,0 +1,35 @@
+/**********************************************************************
+ *
+ * z3950proto.h --
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef Z3950EXPLAIN_H
+#define Z3950EXPLAIN_H
+
+
+#include "z3950parser.h"
+
+void getExplainInfo(bend_search_rr *rr, FilterResponse_t &response, comerror_t &err);
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/z3950/z3950parser.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950parser.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950parser.cpp	(revision 16571)
@@ -0,0 +1,373 @@
+
+#include "z3950parser.h"
+
+void Z_AttributeList_parse(bend_search_rr *rr, Z_AttributeList *Z, text_t &GSQuery)
+{
+  /*
+    struct Z_AttributeList {
+    int num_attributes;
+    Z_AttributeElement **attributes;
+    };
+  */
+
+  /*
+    struct Z_AttributeElement {
+    Z_AttributeSetId *attributeSet; // OPT
+    int *attributeType;
+    int which;
+    union {
+    int *numeric;
+    Z_ComplexAttribute *complex;
+    #define Z_AttributeValue_numeric 1
+    #define Z_AttributeValue_complex 2
+    } value;
+    };
+  */
+
+  
+
+}
+
+void Z_Term_parse(bend_search_rr *rr, Z_Term *Z, text_t &GSQuery)
+{
+  /*
+    struct Z_Term {
+    int which;
+    union {
+    Odr_oct *general;
+    int *numeric;
+    Z_InternationalString *characterString;
+    Odr_oid *oid;
+    char *dateTime;
+    Z_External *external;
+    Z_IntUnit *integerAndUnit;
+    Odr_null *null;
+    #define Z_Term_general 1
+    #define Z_Term_numeric 2
+    #define Z_Term_characterString 3
+    #define Z_Term_oid 4
+    #define Z_Term_dateTime 5
+    #define Z_Term_external 6
+    #define Z_Term_integerAndUnit 7
+    #define Z_Term_null 8
+    } u;
+    };
+  */
+
+  char *term;
+
+  switch(Z->which){
+  case Z_Term_general: {
+    // must copy no more than len bytes from buf, or else previous query terms may be included
+    int buflen = Z->u.general->len;
+    term = new char[buflen+1];
+    memset(term, '\0', buflen+1);
+    strncpy(term, (const char*)(Z->u.general->buf), buflen);
+    GSQuery += term;
+    break; }
+  case Z_Term_numeric:
+    GSQuery += *(Z->u.numeric); // int*
+    break;
+  case Z_Term_characterString:
+    GSQuery += Z->u.characterString; // what is this type?
+    break;
+  case Z_Term_oid:
+    GSQuery += *(Z->u.oid); // int*
+    break;
+  case Z_Term_dateTime:
+    GSQuery += Z->u.dateTime; // char*
+    break;
+  case Z_Term_external:
+    GSQuery += " "; // ignore this for now
+    break;
+  case Z_Term_integerAndUnit:
+    GSQuery += " "; // ignore this for now
+    break;
+  case Z_Term_null:
+    GSQuery += " "; // void
+    break;
+  default:
+    cerr << "Error in Z_Term_parse" << endl;
+    exit(1);
+  }
+}
+
+void Z_ProximityOperator_parse(bend_search_rr *rr, Z_ProximityOperator *Z, text_t &GSQuery)
+{
+  /*
+    struct Z_ProximityOperator {
+    bool_t *exclusion; // OPT
+    int *distance;
+    bool_t *ordered;
+    #define Z_ProximityOperator_Prox_lessThan 1
+    #define Z_ProximityOperator_Prox_lessThanOrEqual 2
+    #define Z_ProximityOperator_Prox_equal 3
+    #define Z_ProximityOperator_Prox_greaterThanOrEqual 4
+    #define Z_ProximityOperator_Prox_greaterThan 5
+    #define Z_ProximityOperator_Prox_notEqual 6
+    int *relationType;
+    int which;
+    union {
+    Z_ProxUnit *known;
+    int *zprivate;
+    #define Z_ProximityOperator_known 1
+    #define Z_ProximityOperator_private 2
+    } u;
+    };
+    
+    #define Z_ProxUnit_character 1
+    #define Z_ProxUnit_word 2
+    #define Z_ProxUnit_sentence 3
+    #define Z_ProxUnit_paragraph 4
+    #define Z_ProxUnit_section 5
+    #define Z_ProxUnit_chapter 6
+    #define Z_ProxUnit_document 7
+    #define Z_ProxUnit_element 8
+    #define Z_ProxUnit_subelement 9
+    #define Z_ProxUnit_elementType 10
+    #define Z_ProxUnit_byte 11
+  */
+
+  // Greenstone (actually mgpp) supports proximity, but only 
+  // to n words either side.
+  // A more complete implementation of proximity can be added
+  // by parsing the other fields in Z_ProximityOperator.
+  // Note: this only works properly with MGPP collections
+  
+  GSQuery += " NEAR"; 
+  GSQuery += *(Z->distance);
+  GSQuery += " ";
+}
+
+void Z_Operator_parse(bend_search_rr *rr, Z_Operator *Z, text_t &GSQuery)
+{
+  /*
+    struct Z_Operator {
+    int which;
+    union {
+    Odr_null *and;
+    Odr_null *or;
+    Odr_null *and_not;
+    Z_ProximityOperator *prox;
+    #define Z_Operator_and 1
+    #define Z_Operator_or 2
+    #define Z_Operator_and_not 3
+    #define Z_Operator_prox 4
+    } u;
+    };
+  */
+  
+  switch(Z->which){
+  case Z_Operator_and:
+    GSQuery += " & ";
+    break;
+  case Z_Operator_or:
+    GSQuery += " | ";
+    break;
+  case Z_Operator_and_not:
+    GSQuery += " ! ";
+    break;
+  case Z_Operator_prox:
+    Z_ProximityOperator_parse(rr, Z->u.prox, GSQuery);
+    break;
+  default:
+    cerr << "Error in Z_Operator_parse" << endl;
+    exit(1);
+  }
+}
+
+void Z_Operand_parse(bend_search_rr *rr, Z_Operand *Z, text_t &GSQuery)
+{
+    /*
+      struct Z_Operand {
+      int which;
+      union {
+      Z_AttributesPlusTerm *attributesPlusTerm;
+      Z_ResultSetId *resultSetId;
+      Z_ResultSetPlusAttributes *resultAttr;
+      #define Z_Operand_APT 1
+      #define Z_Operand_resultSetId 2
+      #define Z_Operand_resultAttr 3
+      } u;
+      };
+    */
+  
+  switch(Z->which) {
+  case Z_Operand_APT: {
+    /*
+      struct Z_AttributesPlusTerm {
+      Z_AttributeList *attributes;
+      Z_Term *term;
+      };
+    */
+    
+    /*
+      struct Z_AttributeList {
+      int num_attributes;
+      Z_AttributeElement **attributes;
+      };
+    */
+    
+    /*
+      struct Z_AttributeElement {
+      Z_AttributeSetId *attributeSet; // OPT
+      int *attributeType;
+      int which;
+      union {
+      int *numeric;
+      Z_ComplexAttribute *complex;
+      #define Z_AttributeValue_numeric 1
+      #define Z_AttributeValue_complex 2
+      } value;
+      };
+    */
+    
+    char *term;
+    
+    if (Z->u.attributesPlusTerm->attributes->num_attributes > 0) {
+      int Bib1_relation = *(Z->u.attributesPlusTerm->attributes->attributes[0]->attributeType);
+      int Bib1_use = *(Z->u.attributesPlusTerm->attributes->attributes[0]->value.numeric);
+
+      // if use value is 1010 ("Body of text"), is not a fielded search
+      if (Bib1_use == 1010) {
+	// if relation value is 6 ("not"), add a "not" to GSQuery
+	if (Bib1_relation == 6) {
+	  GSQuery += "! ";
+	}
+	Z_Term_parse(rr, Z->u.attributesPlusTerm->term, GSQuery);
+      }
+      // for other use values, is a fielded search
+      else {
+	text_t Short;
+	// only add [ ]: if the index exists in the collection,
+	// note: only the index names in the first collection of a
+	// multi-collection search are used at the moment
+	if ((Collection_map[rr->basenames[0]]).getFieldArg(Bib1_use, Short)) {
+	  GSQuery += "[";
+	  cerr << "Supressing square brackets for the moment!\n";
+
+	  Z_Term_parse(rr, Z->u.attributesPlusTerm->term, GSQuery);
+	  GSQuery += "]";
+	  GSQuery += ":";
+	  GSQuery += Short;
+	}
+	// if it doesn't, add it as an unfielded search term
+	else {
+	  cerr << "[" << rr->basenames[0] << "]: failed to find index" << endl;
+	  Z_Term_parse(rr, Z->u.attributesPlusTerm->term, GSQuery);
+	}
+      }
+    }
+    else {
+      Z_Term_parse(rr, Z->u.attributesPlusTerm->term, GSQuery);
+    }
+    break;
+  }
+  case Z_Operand_resultSetId: {
+    GSQuery += "(";
+    GSQuery += Resultsets[Z->u.resultSetId];
+    GSQuery += ")";
+    break; 
+  }
+  case Z_Operand_resultAttr:
+    GSQuery += " "; // ignore this for now
+    break;
+  default:
+    cerr << "Error in Z_Operand_parse" << endl;
+    exit(1);
+  } 
+}
+
+void Z_RPNStructure_parse(bend_search_rr *rr, Z_RPNStructure *Z, text_t &GSQuery)
+{
+  /*
+    struct Z_RPNStructure {
+    int which;
+    union {
+    Z_Operand *simple;
+    Z_Complex *complex;
+    #define Z_RPNStructure_simple 1
+    #define Z_RPNStructure_complex 2
+    } u;
+    };
+  */
+
+  switch(Z->which){
+  case Z_RPNStructure_simple:
+    Z_Operand_parse(rr, Z->u.simple, GSQuery);
+    break;
+  case Z_RPNStructure_complex:
+    GSQuery += "(";
+    Z_RPNStructure_parse(rr, Z->u.complex->s1, GSQuery);
+    Z_Operator_parse(rr, Z->u.complex->roperator, GSQuery);
+    Z_RPNStructure_parse(rr, Z->u.complex->s2, GSQuery);
+    GSQuery += ")";
+    break;
+  default:
+    cerr << "Error in Z_RPNStructure_parse" << endl;
+    exit(1);
+  }
+}
+
+text_t ZQueryToGSQuery(bend_search_rr *rr)
+{
+  text_t GSQuery;
+
+  switch(rr->query->which){
+  case Z_Query_type_0:
+    cerr << "querytype = 0" << endl;
+    // this is a void*, pretend it's a Greenstone-type query
+    GSQuery += (char*)(rr->query->u.type_0);
+    break;
+  case Z_Query_type_1: {
+    cerr << "querytype = 1" << endl;
+    /*
+      struct Z_RPNQuery {
+      Z_AttributeSetId *attributeSetId;
+      Z_RPNStructure *RPNStructure;
+      };
+    */
+    // parse attributeSetId
+    cerr << "attributeSetId = ";
+    int c, d = 0;
+    do {
+      c = rr->query->u.type_1->attributeSetId[d];
+      cerr << c;
+      d++;
+    } while (c >= 0);
+    cerr << endl;
+
+    Z_RPNStructure_parse(rr, rr->query->u.type_1->RPNStructure, GSQuery);
+    break; }
+  case Z_Query_type_2: {
+    cerr << "querytype = 2" << endl;
+    // this is just a buf (unsigned char*), pretend it's a Greenstone-type query
+    GSQuery += (char*)(rr->query->u.type_2->buf);
+    break; }
+  case Z_Query_type_100: {
+    cerr << "querytype = 100" << endl;
+     // this is just a buf (unsigned char*), pretend it's a Greenstone-type query
+    GSQuery += (char*)(rr->query->u.type_100->buf);
+    break; }
+  case Z_Query_type_101: {
+    cerr << "querytype = 101" << endl;
+    // check: is this really the same as a type 1 query?
+    Z_RPNStructure_parse(rr, rr->query->u.type_101->RPNStructure, GSQuery);
+    break; }
+  case Z_Query_type_102: {
+    cerr << "querytype = 102" << endl;
+     // this is just a buf (unsigned char*), pretend it's a Greenstone-type query
+    GSQuery += (char*)(rr->query->u.type_102->buf);
+    break; }
+  default: {
+    cerr << "Error in ZQueryToGSQuery" << endl;
+    exit(1); }
+  }
+
+  // override GSQuery (test code)
+  //GSQuery = "[the]:TX";
+
+  cerr << "GSQuery = `" << GSQuery << "'" << endl;
+  return GSQuery;
+}
+
Index: /gsdl/trunk/runtime-src/src/z3950/z3950parser.h
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950parser.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950parser.h	(revision 16571)
@@ -0,0 +1,77 @@
+/**********************************************************************
+ *
+ * z3950parser.h -- convert Z39.50's RPN query syntax into Greenstone
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef Z3950PARSER_H
+#define Z3950PARSER_H
+
+
+#include <string>
+#include <list>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <time.h>
+
+// Greenstone headers
+#include "fileutil.h"
+#include "comtypes.h"
+#include "nullproto.h"
+#include "z3950_to_gsdl.h"
+
+// YAZ headers
+extern "C" {
+#include <yaz/backend.h>
+#include <yaz/log.h>
+#ifdef ASN_COMPILED
+#include <yaz/ill.h>
+#endif
+}
+
+extern text_t gsdlhome;
+extern list<FilterResponse_t> Response_tlist;
+extern list<text_t> Response_tlist_colnames;
+extern list<int> Response_tlist_sizes;
+extern z3950Server *Server;
+extern collectset *Cservers;
+extern nullproto *Protocol;
+extern map<text_t, gsdlCollection> Collection_map;
+extern map<text_t, text_t> Resultsets;
+
+void Z_AttributeList_parse(bend_search_rr *rr, Z_AttributeList *Z, text_t &GSQuery);
+
+void Z_Term_parse(bend_search_rr *rr, Z_Term *Z, text_t &GSQuery);
+
+void Z_ProximityOperator_parse(bend_search_rr *rr, Z_ProximityOperator *Z, text_t &GSQuery);
+
+void Z_Operator_parse(bend_search_rr *rr, Z_Operator *Z, text_t &GSQuery);
+
+void Z_Operand_parse(bend_search_rr *rr, Z_Operand *Z, text_t &GSQuery);
+
+void Z_RPNStructure_parse(bend_search_rr *rr, Z_RPNStructure *Z, text_t &GSQuery);
+
+text_t ZQueryToGSQuery(bend_search_rr *rr);
+
+#endif
Index: /gsdl/trunk/runtime-src/src/z3950/z3950proto.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950proto.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950proto.cpp	(revision 16571)
@@ -0,0 +1,611 @@
+/**********************************************************************
+ *
+ * z3950proto.cpp --
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "z3950proto.h"
+#include "comtypes.h"
+#include "browsefilter.h"
+#include "queryfilter.h"
+#include "filter.h"
+// z39.50 yaz stuff
+
+#include "z3950cfg.h" // for reading in config files - 
+// defines "struct z3950cfg *zserver_list" as the head of the list.
+
+// note! yyin is hash-defined in z3950cfg.h to something else, to avoid
+// name conflicts with "other" yyins.
+extern FILE *yyin;
+extern FILE *yyout; // redirect for `errors' (unmatched tokens in flex)
+
+
+
+z3950proto::z3950proto() {
+  zserver_count=0;
+}
+
+z3950proto::~z3950proto() {
+}
+
+void z3950proto::add_server (z3950_proxy& zserver) {
+
+  // append the new server
+  ++zserver_count;
+  zservers.push_back(&zserver);
+}
+
+void z3950proto::read_config_file(const text_t &filename, const text_t &errf) {
+  struct z3950cfg *here;
+  struct z3950cfg *oldhere;
+  z3950_proxy *zserver;
+  ShortColInfo_t *tempinfo;
+
+  //  FILE *errfile declared in z3950cfg.h, defined in zparse.y
+
+  char *errf_str=errf.getcstr();
+  if ((errfile=fopen(errf_str,"a"))==NULL) {
+    // what do we do if we can't open the error file?
+    // this means that errors will go to stderr, which may stuff up 
+    // any cgi headers and the page.
+    errfile=stderr;
+  }
+  delete []errf_str;
+  yyout=errfile;
+
+  
+  char *filename_str=filename.getcstr();
+  yyin=fopen(filename_str,"r");
+  if (yyin==NULL) {
+    cerr << "Could not open "<<filename_str<<" for reading.\n";
+    delete []filename_str;
+    return;
+  }
+  delete []filename_str;
+
+  // this is in zparse.tab.c,
+  // which is the bison output of zparse.y
+  yyparse();
+
+  if (errfile!=stderr)
+    fclose(errfile);
+
+  // we now have the config files in the ptr zserver_list
+  if (zserver_list==NULL)
+    return; // no valid servers found in the config file - note that
+  // the parser will have already spat out any errors.
+
+  // now create z3950 proxies for each structure in server_list
+  here=zserver_list;
+  while (here!=NULL) {
+    zserver=new z3950_proxy;
+    tempinfo=new ShortColInfo_t;
+
+    tempinfo->host.setcstr(here->hostname);
+    tempinfo->port=here->port;
+    tempinfo->name.setcstr(here->dbname);
+    zserver->setInfo(tempinfo);
+    zserver->setName(here->shortname);
+    // now collection metadata.
+    zserver->setMeta("collectionname",here->longname);
+    if (here->icon!=NULL)
+      zserver->setMeta("iconcollection",here->icon);
+    if (here->smallicon!=NULL)
+      zserver->setMeta("iconcollectionsmall",here->smallicon);
+    
+    /*    filterclass *filter = new filterclass ();
+	  zserver->add_filter (filter);
+	  browsefilterclass *browsefilter = new browsefilterclass();
+	  zserver->add_filter (browsefilter);
+	  queryfilterclass *queryfilter = new queryfilterclass();
+	  zserver->add_filter (queryfilter);
+    */
+
+    // About list
+    if (here->about!=NULL) {
+      struct z3950aboutlist *about_here=here->about;
+      struct z3950aboutlist *oldabout;
+
+      while (about_here!=NULL) {
+	// problem with default lang (null): can't add ("",..)
+	if (about_here->lang==NULL)
+	  zserver->addcfgAbout("en",about_here->text);
+	else
+	  zserver->addcfgAbout(about_here->lang, about_here->text);
+	oldabout=about_here;
+	about_here=about_here->next;
+	free(oldabout->lang);
+	free(oldabout->text);
+	free(oldabout);
+      }
+    }
+
+    oldhere=here;
+    here=here->next;
+    free(oldhere->shortname); // these 4 strings should all be non-NULL...
+    free(oldhere->hostname);
+    free(oldhere->dbname);
+    free(oldhere->longname);
+    if (oldhere->icon) free(oldhere->icon);     // these 2 may be NULL
+    if (oldhere->smallicon) free(oldhere->smallicon);
+    free(oldhere);
+
+    add_server(*zserver);
+  } // end of while loop.
+
+}
+
+void z3950proto::configure (const text_t &/*key*/,
+			    const text_tarray &/*cfgline*/) {
+  // this is called for each line in the gsdlsite.cfg file
+}
+
+
+bool z3950proto::init (ostream &/*logout*/) {
+  // set up tcp connection to server here?
+  // we might also read in the config file here (instead of librarymain.cpp)
+
+  // 
+
+  // logout goes to initout.txt
+  //  logout <<"zdebug:init:Number of z3950 servers: "<< zserver_count << "\n";
+  //logout << "\t1st server name: " << zservers[0].getName().getcstr() << "\n";
+  return true;
+
+}
+
+/*text_t z3950proto::get_protocol_name () {
+  return "z3950proto";
+}
+*/
+
+void z3950proto::get_collection_list (text_tarray &collist, 
+				      comerror_t &/*err*/,
+				      ostream &/*logout*/) {
+
+  z3950_proxy_array::iterator here = zservers.begin();
+  z3950_proxy_array::iterator end = zservers.end();
+  while (here != end) {
+    collist.push_back((*here)->getName());
+    ++here;
+  }
+}
+
+void z3950proto::has_collection (const text_t &collection, bool &hascollection,
+				 comerror_t &/*err*/, ostream &/*logout*/) {
+  z3950_proxy_array::iterator here = zservers.begin();
+  z3950_proxy_array::iterator end = zservers.end();
+  while (here != end) {
+    if((*here)->getName()==collection) {
+      hascollection=true;
+      return;
+    }
+    ++here;
+  }
+  hascollection=false;
+}
+
+void z3950proto::ping (const text_t &/*collection*/, bool &wassuccess, 
+		       comerror_t &/*err*/, ostream &/*logout*/) {
+  // should we just ping the server, or actually create a connection
+  // to the z39.50 server process on the machine ?
+  wassuccess = true;
+}
+
+void z3950proto::get_collectinfo (const text_t &collection,
+				  ColInfoResponse_t &collectinfo,
+				  comerror_t &err, ostream &logout) {
+
+  // set err to protocolError if something goes wrong...
+  err=noError;
+
+  z3950_proxy_array::iterator here = zservers.begin();
+  z3950_proxy_array::iterator end = zservers.end();
+  while (here != end) {
+    if((*here)->getName()==collection) {
+      break;
+    }
+    ++here;
+  }
+
+  if (here==end) {
+    err=protocolError;
+    char *coll_str=collection.getcstr();
+    logout << "z39.50: couldn't find collection" 
+	   << coll_str
+	   << endl;
+    delete []coll_str;
+    return;
+  }
+
+  const ShortColInfo_t *colinfo=(*here)->getInfo();
+  collectinfo.shortInfo.name=colinfo->name;
+  collectinfo.shortInfo.host=colinfo->host;
+  collectinfo.shortInfo.port=colinfo->port;
+
+  collectinfo.isPublic=true;
+  // don't use beta field
+  /*collectinfo.isBeta=false;*/
+  collectinfo.buildDate=1;
+  // leave ccsCols empty (no cross-coll. searching - for now)
+  /*collectinfo.ccsCols=(text_tarray);*/ //not like this!!!
+  // This info is available from the config file -- johnmcp
+  /*******collectinfo.languages.push_back("en");
+	  collectinfo.languages.push_back("fr");********/
+  collectinfo.numDocs=0;
+  collectinfo.numWords=0;
+  collectinfo.numBytes=0;
+  // copy the text maps over.
+  //  collectinfo.collectionmeta; // text_tmap
+  text_tmap collmeta = *((*here)->getMeta());
+  text_tmap::iterator mhere = collmeta.begin();
+  text_tmap::iterator mend = collmeta.end();
+  while (mhere != mend) {
+    collectinfo.collectionmeta[(*mhere).first][g_EmptyText] = (*mhere).second;
+    mhere ++;
+  }
+  //collectinfo.collectionmeta=*((*here)->getMeta());
+  collectinfo.format=*((*here)->getFormat()); //text_tmap
+  /*    collectinfo.building; //text_tmap  */
+
+  ////collectinfo.receptionist="z3950"; 
+  /* for now... this is a url,  relative to .../cgi-bin.
+     NOTE: if this is empty, it defaults to _gwcgi_?a=p&p=about&c=<colname>
+  */
+}
+
+void z3950proto::get_filterinfo (const text_t &/*collection*/,
+				 InfoFiltersResponse_t &response,
+				 comerror_t &/*err*/, ostream &/*logout*/) {
+  // we'll fake it here, and say we have set up some filters
+  response.filterNames.insert("BrowseFilter");
+  response.filterNames.insert("QueryFilter");
+  response.filterNames.insert("NullFilter");
+
+}
+
+void z3950proto::get_filteroptions (const text_t &/*collection*/,
+				    const InfoFilterOptionsRequest_t &/*req*/,
+				    InfoFilterOptionsResponse_t &response, 
+				    comerror_t &err, ostream &/*logout*/) {
+  // for now, assume all servers have the same characteristics
+  /*  if (request.filterName=="QueryFilter") { } 
+      else if (request.filterName=="BrowseFilter") { } 
+      else if (request.filterName=="NullFilter") {  } */
+  response.filterOptions["Index"].type=FilterOption_t::stringt;
+  response.filterOptions["Index"].repeatable=FilterOption_t::onePerQuery;
+  response.filterOptions["Index"].defaultValue="any";
+  response.filterOptions["Index"].validValues.push_back(".any");
+  response.filterOptions["Index"].validValues.push_back(".title");
+  response.filterOptions["Index"].validValues.push_back(".author");
+  // and maybe ["Language"] option as well?
+  err=noError;
+}
+
+void z3950proto::filter (const text_t &collection,
+			 FilterRequest_t &request,
+			 FilterResponse_t &response,
+			 comerror_t &err, ostream &logout) {
+  // this function is called when:
+  //  *  creating the title page,(looking for iconcoll* & collectname metadata)
+  //  *  creating the about page (looking for "Title" metadata)
+  //  * doing the query - (note that a request for metadata comes first, then
+  // filterOptions = FRmetadata | FROID | FRtermFreq (64+4+1)
+
+  // metadata-only requests have filterName="NullFilter", else "QueryFilter".
+  // For the title page, we should not create a connection to the target
+  // (target means the actual z39.50 server, origin means us), but
+  // for the about page and query pages, we need to get information from the
+  // origin. (eg for the about page, we will print out some info such as ID,
+  // name and version.
+
+  // cerr now goes to errout.txt in etc directory
+  err=noError;
+
+  // get relevant "collection"
+  z3950_proxy_array::iterator zserver = zservers.begin();
+  z3950_proxy_array::iterator zend = zservers.end();
+  while (zserver != zend) {
+    if((*zserver)->getName()==collection) {
+      break;
+    }
+    ++zserver;
+  }
+  // now have collection in zserver.
+  
+  ColInfoResponse_t info;
+  ResultDocInfo_t *docInfo;
+  
+  // leave response.termInfo empty
+  // response.termInfo.push_back(g_EmptyText); ??????? (should be empty if not req.)
+
+  // See if this is for a query action
+  if (request.filterName=="QueryFilter") {
+    /* Sample OptionValue pairs
+      `StartResults'=`1'
+      `EndResults'=`20'
+      `Term'=`firstword secondword' (term is just whatever the user typed in)
+      `QueryType'=ranked|boolean   -> OR|AND
+      //`MatchMode'=`some' => 'OR'
+      //`MatchMode' = `all' => 'AND'
+      `Casefold'=`true'
+      `Stem'=`false'
+      `Maxdocs'=`50'
+     */
+    // go through options
+    text_t opt_term;            // the term(s) that the user entered 
+    int opt_querytype=0;        // 1=>ranked (or), 2=>boolean (and)
+    text_t opt_fields;          // which fields to search on
+    int opt_start=1, opt_end=20; // default values
+    int nummatches=0, maxdocs=50; // default values
+    OptionValue_tarray::iterator ov_here=request.filterOptions.begin();
+    OptionValue_tarray::iterator ov_end=request.filterOptions.end();
+    while (ov_here != ov_end) {
+      if (ov_here->name=="Term") {
+	opt_term=ov_here->value;
+      } else if (ov_here->name=="QueryType") {
+	if (ov_here->value=="ranked") opt_querytype=1;
+	else if (ov_here->value=="boolean") opt_querytype=2;
+	else { /* error - shouldn't happen */
+	  /* currently unhandled */
+	}
+      } else if (ov_here->name=="Index") {
+	opt_fields=ov_here->value;
+      } else if (ov_here->name=="StartResults") {
+	opt_start=ov_here->value.getint();
+      } else if (ov_here->name=="EndResults") {
+	opt_end=ov_here->value.getint(); 
+      } else if (ov_here->name=="Maxdocs") {
+	maxdocs=ov_here->value.getint();
+      } 
+      ++ov_here;
+    }
+    err=noError;
+    text_tarray *titles=(*zserver)->getrecordTitles(opt_term,
+						    opt_querytype,
+						    opt_fields,
+						    opt_start, // first to get
+						    opt_end-opt_start, //count
+						    &nummatches,err);
+    if (err!=noError) {
+      // can we return an err msg in a response, or just use
+      // the more drastic Greenstone error mechanism?
+      docInfo=new ResultDocInfo_t;
+      response.docInfo.push_back(*docInfo);
+      docInfo->metadata["Title"].values.push_back("Error - query err?");
+      logout << "\nz3950 filter query: error connecting to server\n";
+      // for now, DON'T use GSDL protocol err.
+      err=noError;
+      return;
+    }
+    // check if (titles==NULL) - only happens on error?
+    if (nummatches>0) {
+      text_tarray::iterator titles_here=titles->begin();
+      text_tarray::iterator titles_end=titles->end();
+      int counter=1;
+      while (titles_here!=titles_end) {
+	docInfo=new ResultDocInfo_t; 
+	docInfo->metadata["Title"].values.push_back(*titles_here);
+	docInfo->result_num=counter;
+	// we need to give some OID, so we'll just use counter for now...
+	// make it the number into the whole possible retrieved set.
+	docInfo->OID=counter+opt_start-1;
+	response.docInfo.push_back(*docInfo);
+	++counter;
+	++titles_here;
+      }
+    }
+
+    if (request.filterResultOptions & FRtermFreq) {
+      if (nummatches>maxdocs) {
+      	response.numDocs=maxdocs; // eg "more than 50" (if Maxdocs==50)
+	response.isApprox=MoreThan;
+      } else {
+	response.numDocs=nummatches; // eg "36 documents"
+	response.isApprox=Exact; // Exact | Approximate | MoreThan
+      }
+    } // end of if (... & FRtermFreq)
+    
+  } // end of if (... == "QueryFilter")
+  else {
+    // this wasn't a query action
+
+    if (request.filterOptions.size()>0 &&
+	request.filterOptions[0].name=="ParentNode") {
+      // don't want to return anything
+      return;
+      /*    } else if (request.docSet.size() &&
+	    request.docSet[0]!="collection") {
+	    // documentaction
+	    // if docSet is not empty, it is either "collection", or an array
+	    // of OIDs 
+	    docInfo=new ResultDocInfo_t;
+	    response.docInfo.push_back(*docInfo);
+      */
+    } else {
+      // in case we need to return only metadata
+      docInfo=new ResultDocInfo_t;
+      response.docInfo.push_back(*docInfo); 
+    }
+  } // end of not a query action
+
+
+
+  // Fill in metadata for each response.docInfo (if wanted)
+  if (request.filterResultOptions & FRmetadata) {
+    get_collectinfo (collection, info, err, logout);
+    // should check err returned here....
+
+    if (!request.fields.empty()) {
+      // currently, this is only true for NullFilter when getting the "Title"
+      // for a documentaction.
+
+      // loop on each document being returned
+      ResultDocInfo_tarray::iterator docs_here=response.docInfo.begin();
+      ResultDocInfo_tarray::iterator docs_end=response.docInfo.end();
+      while (docs_here!=docs_end) {
+	// loop on all the metadata fields in request.fields (type text_tset)
+	text_tset::iterator fields_here=request.fields.begin();
+	text_tset::iterator fields_end=request.fields.end();
+	//text_tmap::iterator it;
+	collectionmeta_map::iterator it;
+	while (fields_here!=fields_end) {
+	  it=info.collectionmeta.find(*fields_here);
+	  if (it!=info.collectionmeta.end())
+	    docs_here->metadata[*fields_here].values.push_back(((*it).second)[g_EmptyText]);
+	  else if (*fields_here=="Title" && !request.docSet.empty()) { 
+	    // We only do this for a document action.
+	    // (This comes through as a NullQuery).
+	    // hopefully docSet is only not empty for documentaction...
+	    text_t doctitle;
+	    int i;
+	    // check that docSet isn't empty first!!!!!!
+	    i=request.docSet[0].getint();
+	    text_t doctext="unneeded";
+	    /* following variables aren't used, as our query result has been
+	       cached in z3950proxy.cpp (but really we shouldn't know that
+	       here...) But for the NullFilter, we don't get given these
+	       again in the request, so for now we'll take advantage of this.*/
+
+	    int querytype=0; text_t field=g_EmptyText;
+
+	    // get the Query out of the filterOptions. (we need get the Title)
+	    text_t query=g_EmptyText;
+	    OptionValue_tarray::iterator opthere=request.filterOptions.begin();
+	    OptionValue_tarray::iterator opt_end=request.filterOptions.end();
+	    while (opthere!=opt_end) {
+	      if (opthere->name=="Term") {
+		query=opthere->value;
+	      } else if (opthere->name=="Index") {
+		field=opthere->value;
+	      } else if (opthere->name=="QueryType") {
+		if (opthere->value=="ranked") querytype=1;
+		else if (opthere->value=="boolean") querytype=2;
+		else { /* error - shouldn't happen */
+		  /* currently unhandled */
+		}
+	      }
+	      ++opthere;
+	    }
+	    (*zserver)->getfullrecord(query, querytype, field, i, doctitle, doctext, err);
+	    // check err value!
+	    docs_here->metadata["Title"].values.push_back(doctitle);	    
+	  } else {
+	    docs_here->metadata[*fields_here].values.push_back(g_EmptyText);
+	  }
+	  ++fields_here;
+	} // end of inner while loop
+	++docs_here;
+      } // end of outer while loop
+    } // end of if (!request.fields.empty())
+    
+    else { // request.fields empty: return all metadata for about page or query
+      // we'll only put it in the first docInfo.
+      collectionmeta_map::iterator colmeta_here=info.collectionmeta.begin();
+      collectionmeta_map::iterator colmeta_end=info.collectionmeta.end();
+      while (colmeta_here!=colmeta_end) {
+	response.docInfo[0].metadata[(*colmeta_here).first].
+	  values.push_back(((*colmeta_here).second)[g_EmptyText]);
+	++colmeta_here;
+      }
+
+      // check if "collectionextra" metadata is set. If it isn't, we should
+      // create connection to target to get it.
+      if (info.collectionmeta.find("collectionextra")==colmeta_end) {
+	// it hasn't been set yet...
+	text_t abouttext="<B>Server Online</B><br>\n";
+	abouttext+=(*zserver)->getzAbout();
+	// add in the "About" text we read in from config file.
+	// how do we incorporate multi-lingual metadata?
+	abouttext+="<P>\n";
+	text_t tmpabout;
+
+	if ((*zserver)->getcfgAbout("en", tmpabout)==true)
+	  abouttext+=tmpabout;
+	
+	(*zserver)->setMeta("collectionextra",abouttext);
+	response.docInfo[0].metadata["collectionextra"].values.push_back(abouttext);
+      }
+    } // end of else
+
+    // do indices' names, regardless of whether asked for or not...
+    if (!response.docInfo.empty()) {
+     response.docInfo[0].metadata[".author"].values.push_back("author fields");
+      response.docInfo[0].metadata[".title"].values.push_back("title fields");
+      response.docInfo[0].metadata[".any"].values.push_back("any fields");
+    }
+  } //end of  if (... & FRmetadata) ...
+}
+
+
+
+void z3950proto::get_document (const text_t &collection,
+			       const DocumentRequest_t &request,
+			       DocumentResponse_t &response,
+			       comerror_t &err, ostream &logout) {
+
+  err=noError;
+
+  // get relevant "collection"
+  z3950_proxy_array::iterator zserver = zservers.begin();
+  z3950_proxy_array::iterator zend = zservers.end();
+  while (zserver != zend) {
+    if((*zserver)->getName()==collection) {
+      break;
+    }
+    ++zserver;
+  }
+  // now have collection in zserver.
+
+  /* docresponse consists of
+     text_t response.doc */
+  text_t title="unneeded";
+  text_t doctext;
+  text_t query; // this should not be needed, as we have already connected to 
+  // get the  title....
+  int querytype = 1; //ditto...
+  text_t field;  // ditto...
+  (*zserver)->getfullrecord(query,querytype,field,request.OID.getint(),
+			    title,doctext,err);
+  // check return value of above? (false=>not connected) 
+  if (err==noError)
+    response.doc=doctext;
+  else {
+    // could print out different messages based on error type....
+    response.doc="<h2>Error</h2>There was an error while connecting to the ";
+    response.doc+="z39.50 server (ie target). Most likely this was a \n";
+    response.doc+="\"Connection Refused\" error.\n";
+
+  }
+  if (0) {
+    err=protocolError;
+    logout << "Some error\n";
+  }
+}
+
+// sets issearchable to true if the given colection is searchable
+void z3950proto::is_searchable (const text_t &/*collection*/, bool &issearchable, 
+				comerror_t &err, ostream &/*logout*/) {
+  issearchable = true; // assume all collections are searchable?
+  err = noError;
+}
+
Index: /gsdl/trunk/runtime-src/src/z3950/z3950proto.h
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950proto.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950proto.h	(revision 16571)
@@ -0,0 +1,98 @@
+/**********************************************************************
+ *
+ * z3950proto.h --
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef Z3950PROTO_H
+#define Z3950PROTO_H
+
+#include "recptproto.h"
+#include "z3950proxy.h"
+
+class z3950proto : public recptproto {
+protected:
+  int zserver_count;
+  z3950_proxy_array zservers;
+public:
+  z3950proto();
+  virtual ~z3950proto();
+
+  int getServerCount() { return zserver_count;}
+  /*
+  void add_collectserver (collectserver *thecserver) 
+        {cservers.addcollectserver(thecserver);}
+  */
+  
+  void add_server(z3950_proxy& zserver);
+
+  void read_config_file(const text_t &filename, const text_t &errfile);
+
+  void configure (const text_t &key, const text_tarray &cfgline);
+
+  bool init (ostream &logout);
+
+  text_t get_protocol_name (comerror_t &/*err*/) {return "z3950proto";}
+
+  void get_collection_list (text_tarray &collist, comerror_t &err, 
+			    ostream &logout);
+
+  void has_collection (const text_t &collection, bool &hascollection, 
+		       comerror_t &err, ostream &logout);
+  
+  void ping (const text_t &collection, bool &wassuccess, 
+	     comerror_t &err, ostream &logout);
+  
+  void get_collectinfo (const text_t &collection, 
+			ColInfoResponse_t &collectinfo,
+			comerror_t &err, ostream &logout);
+  
+  void get_filterinfo (const text_t &collection,
+		       InfoFiltersResponse_t &response,
+		       comerror_t &err, ostream &logout);
+  
+  /*  void get_info (const text_t &collection, const text_tset &metadata,
+      FilterResponse_t &response, ostream &logout);
+  */
+
+  void get_filteroptions (const text_t &collection,
+                          const InfoFilterOptionsRequest_t &request,
+                          InfoFilterOptionsResponse_t &response, 
+                          comerror_t &err, ostream &logout);
+  
+  void filter (const text_t &collection,
+	       FilterRequest_t &request,
+	       FilterResponse_t &response,
+	       comerror_t &err, ostream &logout);
+  
+  void get_document (const text_t &collection,
+		     const DocumentRequest_t &request,
+		     DocumentResponse_t &response,
+		     comerror_t &err, ostream &logout);
+  
+  void is_searchable (const text_t &collection, 
+			      bool &issearchable, 
+			      comerror_t &err, ostream &logout);
+
+};
+
+#endif
Index: /gsdl/trunk/runtime-src/src/z3950/z3950proxy.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950proxy.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950proxy.cpp	(revision 16571)
@@ -0,0 +1,365 @@
+/**********************************************************************
+ *
+ * z3950proxy.cpp --
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "z3950proxy.h"
+#include "comtypes.h"
+#include <stdio.h>
+
+// z39.50 yaz stuff
+#define min(a,b) (((a)<(b))?(a):(b))
+
+extern "C" {
+#include "yaz_zclient.h"
+}
+
+/*** 
+     each z39.50 server+database pair is a GSDL collection.
+***/
+
+z3950_proxy::z3950_proxy() {
+  info=NULL;
+  connected=false;
+  titles=NULL;
+  gotsinglerecord=false;
+  // for now, assume that all records will have text associated with them.
+  meta["hastxt"]="1";
+  // for now, assume we don't want ANY DocumentButtons.
+  format["DocumentButtons"]=g_EmptyText;
+}
+
+z3950_proxy::~z3950_proxy() {
+}
+
+void z3950_proxy::setMeta(const text_t &key, const text_t &value) {
+  meta[key]=value;
+}
+
+void z3950_proxy::setName(const text_t &newname) {
+  title=newname;
+  meta["collectionname"]=newname;
+}
+
+void z3950_proxy::addcfgAbout(const text_t &lang, const text_t &abouttext) {
+    about[lang]=abouttext;
+}
+
+bool z3950_proxy::getcfgAbout(const text_t &lang, text_t &abouttxt) {
+  text_tmap::iterator it;
+  it=about.find(lang);
+  if (it==about.end()) return (false);
+  abouttxt=((*it).second);
+  return (true);
+}
+
+
+// now functions that actually talk over the tcp connection.
+
+// create a tcp connection to the associated target. Currently, this will
+// re-initialise if we are already connected.
+bool z3950_proxy::connect() {
+  text_t server_and_port;
+  char *zserverinfo;
+
+  server_and_port=info->host+":"+info->port;
+  // remember that info.name is the database name
+
+  z_initialize();
+  char* serv_str=server_and_port.getcstr();
+  char* name_str=info->name.getcstr();
+  int retval=z_cmd_open(serv_str,name_str);
+  delete []serv_str;
+  delete []name_str;
+  if (retval==1)
+    // we got a connection error
+    return false;
+
+  // get initialisation response.
+  z_getnextAPDU();
+  zserverinfo=z_get_initResponse();
+  if (zserverinfo!=NULL) {
+    z_initstr.appendcstr(zserverinfo);
+  }
+  free(zserverinfo);
+
+  connected=true;
+  return true;
+}
+
+void z3950_proxy::parseQuery(const text_t &query, 
+			      const int querytype,
+			      const text_t &fields,
+			      text_t &parsed_query) {
+  /****** FIXME *****/
+  // We need to format the query string into RPN - 
+  // by just passing it like this, it will only work for simple queries.
+  // This will require us to actually come up with a query syntax and 
+  // a parser. For now, we'll just do an "AND" query for all terms
+  // But look at Common Command Language (CCL) query syntax (ISO 8777).
+
+  // need to remove " chars from the query. We should really tell the server
+  // to do a phrase search on the terms that are between the "s, but we
+  // can't (easily) tell if the server can do that or not, 
+  // so we'll currently just do a query and then post-process. (not yet
+  // implemented........)
+
+  // we need to count number of terms separated by a space
+  char *ptr=query.getcstr();
+  int strlength=strlen(ptr);
+  bool inword=false;
+  int num_terms=0;
+
+
+  for (int i=0;i<strlength;++i) {
+    if (*(ptr+i)=='"') { // convert " to SPACE...
+      *(ptr+i)=' '; 
+    }
+    if (*(ptr+i)!=' ') {
+      if (inword==false) {
+	inword=true;
+	++num_terms;
+      }
+    }
+    else { // ptr+i is a space
+      inword=false;
+      }
+  }
+  
+  // set the field(s) to search on - main ones include:
+  //  1016  => Any
+  //  1     => (Personal) Name
+  //  4     => Title
+  //  21    => Subject Heading
+  //  45    => Subject precis
+  // Note I have no idea how these actually work - I think some servers
+  // only have limited fields, and map all subject-type requests into that
+  // subject field, etc.
+
+  parsed_query="@attr 1=";
+  if (fields==".author")
+    parsed_query+="1 ";
+  else if (fields==".title")
+    parsed_query+="4 ";
+  else // fields==".any"
+    parsed_query+="1016 ";
+
+  // querytype=1 => ranked/or,  =2 => boolean/and
+  // append "@and" for each term after the first
+  {
+    char and_str[]="@and ";
+    char or_str[]="@or ";
+    char *q_type;
+    if (querytype==1) q_type=or_str; else q_type=and_str;
+    for (int i=1;i<num_terms;++i)
+      parsed_query+=q_type;
+    // append the actual query
+    parsed_query+=ptr;
+  }
+  delete []ptr;
+}
+
+text_tarray *z3950_proxy::getrecordTitles(const text_t &query, 
+					   const int querytype,
+					   const text_t &fields,
+					   int first, int count,
+					   int *nummatches, comerror_t &err) {
+  /* NOTE!!!!!! Because this code currently only works in cgi-bin mode,
+     we only ever do one request. Therefore, it is CURRENTLY OK to store
+     (cache) the retrieved titles, because if this function is ever called
+     more than once, the arguments will be the same each time.
+     (I think :)
+  */
+
+  char **c_str_titles; 
+  int i;
+  int last;
+
+  if (gotsinglerecord==true) {
+    /* If true, then this whole execution was done to retrieve a single
+       document. Therefore, the list of titles of all records matching the
+       query isn't actually required. It's just that for some reason our
+       filter (z3950proto::filter) gets called at least 7 times, with the
+       7th being a "QueryFilter" for some reason... */
+    nummatches=0;
+    return NULL; /* shouldn't really return NULL, but nummatches is checked
+		    first (I hope) */
+  }
+
+  //  if (titles!=NULL) delete (titles);
+  if (titles!=NULL) return titles;
+  titles=new text_tarray;
+
+  /* check if connected */
+  if (connected==false) 
+    if (connect()==false) {
+      // we could not connect.
+      err=protocolError;
+      return (NULL);
+    }
+  
+
+  text_t expanded_query=g_EmptyText;
+  parseQuery(query,querytype,fields,expanded_query);
+
+  char* query_str=expanded_query.getcstr();
+  // following functions defined in yaz_zclient.c
+  *nummatches=z_cmd_dosearch(query_str); // returns # found, -1 on err.
+  delete []query_str;
+  if (*nummatches<=0) {
+    if (*nummatches==0) {
+      // no matches
+      return (NULL);
+    } else  if (*nummatches==-1) {
+      // prefix query error
+      err=protocolError;
+      return (NULL);
+    }  else if (*nummatches==-2) {
+      // sendsearchRequest not answered by searchResponse
+      err=protocolError;
+      return (NULL);
+    }
+  }
+  // could do a sort eventually, eg on date, title, etc.
+  // (non-existent function)    z_sort(field, asc|desc);
+  /* min of (count, first + (*nummatches) ) */
+  // z_getrecordTitles ( first, howmany )
+  c_str_titles=z_getrecordTitles(first,min(count,*nummatches-first+1));
+  if (c_str_titles==NULL) {
+    // an error occurred. we need a logout/err as an arg
+    return (NULL);
+  }
+  if (c_str_titles[0]==0) {
+    // no matches.
+    return (NULL);
+  }
+  last=(int)c_str_titles[0];
+  for (i=1;i<=last;++i) {
+    titles->push_back(c_str_titles[i]);
+    free(c_str_titles[i]);
+  }
+  free(c_str_titles);
+  return (titles);
+  
+}
+
+bool z3950_proxy::getfullrecord(const text_t &query, 
+				 const int querytype,
+				 const text_t &fields,
+				 const int ID, 
+				 text_t &rettitle, 
+				 text_t &rettext, comerror_t &err) {
+
+  static char **c_str_titles=NULL;
+  static char *fulltext=NULL;
+  /* NOTE!!!!!! Because this code currently only works in cgi-bin mode,
+     we only ever do one request. Therefore, it is CURRENTLY OK to store
+     (cache) the retrieved titles, because if this function is ever called
+     more than once, the arguments will be the same each time.
+     (I think :)
+  */
+
+  gotsinglerecord=true; // well, not yet, but we've been called...
+
+  if (connected==false) {
+    if (connect()==false) {
+      // error connecting...
+      err=protocolError;
+      return (false);
+    }
+    // since we have just re-connected, we need to do the
+    // query again.
+
+    text_t expanded_query=g_EmptyText;
+    parseQuery(query,querytype,fields,expanded_query);
+
+    char* query_str=expanded_query.getcstr();
+    int returned=z_cmd_dosearch(query_str);
+    delete []query_str;
+    if (returned<=0) {
+      // 0 => none.
+      // <0 => error
+      err=protocolError;
+      return (false);
+    }
+  }
+
+  if (c_str_titles==NULL)
+    c_str_titles=z_getrecordTitles(ID,1); // check this return value.
+  
+  if (rettitle!="unneeded") {
+    //int dummy;
+    if (c_str_titles!=NULL && (int)c_str_titles[0]==1) {
+      rettitle.setcstr(c_str_titles[1]); // and check this 
+      //////      free (c_str_titles); - we want to "cache" it
+    } else {
+      // we didn't get something....
+      rettitle="Nothing Returned...";
+    }
+  }
+
+  if (fulltext==NULL)
+    // get the text
+    fulltext=z_getfullRecord(ID);
+
+  if (rettext!="unneeded") {
+    rettext.setcstr(fulltext);
+  }
+  return (true);
+  }
+
+text_t &z3950_proxy::getzAbout() {
+  text_t zserverresp;
+
+  // Assume we have not yet connected, so that must be done here.
+  if (connected==true)
+    return (z_initstr);
+  
+  // we need to create the tcp connection to the target (server)  
+  //  z_initstr=new text_t;
+  
+  if (connect()==false) {
+    z_initstr.setcstr("<H2>Server offline</H2>Error - could not connect to server <B>");
+    z_initstr += info->host;
+    z_initstr += "</B> on port ";
+    z_initstr += info->port;
+    z_initstr += "\n";
+    return (z_initstr);
+  }
+  
+  // z_initstr currently contains the target's response. We want to
+  // PREPEND the following information.
+  zserverresp=z_initstr;
+  z_initstr="Internet server: <b>";
+  z_initstr+=info->host;
+  z_initstr+="</b> on port ";
+  z_initstr+=info->port;
+  z_initstr+=".<br>\n";
+  z_initstr+=zserverresp;
+
+  // should close /******* WHAT IF DOING A QUERY!??!?!? ********/
+  // z_cmd_close(0);
+  // connected=false;
+  return (z_initstr);
+}
+
Index: /gsdl/trunk/runtime-src/src/z3950/z3950proxy.h
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950proxy.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950proxy.h	(revision 16571)
@@ -0,0 +1,79 @@
+/**********************************************************************
+ *
+ * z3950proxy.h --
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef Z3950PROXY_H
+#define Z3050PROXY_H
+
+#include "comtypes.h"
+
+// each "proxy to server" (i.e. collection) consists of a {z39.50 server + database} pair.
+class z3950_proxy {
+ protected:
+  text_t title;    // Descriptive name
+  text_t z_initstr; // a string returned when the connection is initialised.
+  text_tmap meta;  // metadata for this collection (ie server/database pair)
+  text_tmap format;
+  text_tmap about; // langauge/abouttext pair for collection.
+  ShortColInfo_t *info; // has  (database) name, host and port
+  text_tarray *titles; 
+  bool connect();
+  bool connected; // tcp connection to the z39.50 server (target)
+  bool gotsinglerecord; // if we do, then we don't need all titles...
+
+ public:
+  z3950_proxy();
+  ~z3950_proxy();
+  void setName(const text_t &newname);
+  const text_t getName() {return title;}
+  void setMeta(const text_t &key, const text_t &value);
+  const text_tmap *getMeta() {return &meta;}
+  const text_tmap *getFormat() {return &format;}
+  void setInfo(ShortColInfo_t *newinfo) {info=newinfo;}
+  const ShortColInfo_t *getInfo() {return info;}
+  void addcfgAbout(const text_t &lang, const text_t &abouttext);
+  bool getcfgAbout(const text_t &lang, text_t &abouttext);
+  // now the functions that actually talk to the target (ie zserver) over tcp
+  text_t &getzAbout(); // gets any name, id, MOTD, etc from server.
+  text_tarray *getrecordTitles(const text_t &query,
+			       const int andor_querytype,
+			       const text_t &fields,
+			       const int first, const int count,
+			       int *nummatches, comerror_t &err);
+  /* only get one record at a time? (Eventually we could buffer them, but
+     for now... */
+  bool getfullrecord(const text_t &query, const int andor_querytype,
+		     const text_t &fields,
+		     const int ID, text_t &rettitle, 
+		     text_t &rettext,comerror_t &err);
+ private:
+  void parseQuery(const text_t &query, const int andor_querytype, 
+		  const text_t &fields, 
+		  text_t &parsed_query);
+  text_t previousquery; // for caching purposes
+};
+
+typedef  vector<z3950_proxy *>  z3950_proxy_array;
+
+#endif
Index: /gsdl/trunk/runtime-src/src/z3950/z3950server.cpp
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950server.cpp	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950server.cpp	(revision 16571)
@@ -0,0 +1,927 @@
+
+
+// Standard headers
+
+#if defined(GSDL_USE_OBJECTSPACE)
+#  include <ospace\std\iostream>
+#  include <ospace\std\fstream>
+#  include <ospace\std\sstream>
+#elif defined(GSDL_USE_IOS_H)
+#  include <iostream.h>
+#  include <fstream.h>
+#  include <strstream.h>
+#else
+#  include <iostream>
+#  include <fstream>
+#  include <sstream>
+#endif
+
+#include <string>
+#include <list>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <time.h>
+
+// Greenstone headers
+#include "fileutil.h"
+#include "comtypes.h"
+#include "nullproto.h"
+
+// Z39.50 server headers
+#include "z3950parser.h"
+#include "z3950explain.h"
+
+#include "z3950server.h"
+
+// Dublin Core -> MARC (d2m) headers and source files
+#include "d2m4gs.h"
+
+// these globals are local to each thread,
+// one Z39.50 connection = one thread.
+text_t gsdlhome; // this is specified externally when Greenstone is installed
+list<FilterResponse_t> Response_tlist; // list of response sets
+list<text_t> Response_tlist_colnames;  // collection names for the above
+list<int> Response_tlist_sizes;        // sizes (number of records) for the above
+z3950Server *Server   = NULL;
+collectset  *Cservers = NULL;
+nullproto   *Protocol = NULL;
+
+map<text_t, gsdlCollection> Collection_map; // info and tools for collections
+map<text_t, text_t> Resultsets;             // mapping from ResultSetId to GSQuery 
+
+int z3950_verbosity_ = 3;
+
+// *** initialize things here ***
+bend_initresult *bend_init(bend_initrequest *q)
+{
+  // *** called when client connects to the server ***
+  if (z3950_verbosity_ > 1) {
+    cerr << "Entering bend_init" << endl;
+  }
+
+  Protocol = new nullproto();  
+  Cservers = new collectset(gsdlhome);
+  Protocol->set_collectset(Cservers);
+  
+  cerr << "Starting Z39.50 Server ..." << endl;
+  
+  Server = new z3950Server(Protocol, gsdlhome);
+  cerr << "Server constructed" << endl;
+  
+  const bool status = Server->initialise();
+  cerr << "Initialised server: return status = " << status << endl;
+  
+  text_tarray collist;
+  comerror_t err;
+  Protocol->get_collection_list( collist, err, cout );
+
+  // display the list of available Greenstone collections
+  text_tarray::iterator cols_here=collist.begin();
+  text_tarray::iterator cols_end=collist.end();
+  while (cols_here != cols_end) {
+    gsdlCollection tmpcol(*cols_here, gsdlhome);
+    
+    Collection_map[*cols_here] = tmpcol;
+    
+    if (tmpcol.z3950Capeable()) {
+      cerr << "  " << tmpcol.getName() << "\tis Z39.50 capable" << endl;
+    }
+    cols_here++;
+  }
+
+    
+  bend_initresult *r = (bend_initresult *) odr_malloc (q->stream, sizeof(*r));
+  //static char *dummy = "Hej fister"; // what's this for?
+  
+  r->errcode = 0;
+  r->errstring = 0;
+  r->handle = Protocol;
+  q->bend_sort = ztest_sort;       /* register sort handler */
+  q->bend_search = ztest_search;   /* register search handler */
+  q->bend_present = ztest_present; /* register present handle */
+  q->bend_esrequest = ztest_esrequest;
+  q->bend_delete = ztest_delete;
+  q->bend_fetch = ztest_fetch;
+  q->bend_scan = ztest_scan;
+
+  return r;
+}
+
+// *** perform query, get number of hits ***
+int ztest_search (void *handle, bend_search_rr *rr)
+{
+  // *** called when client issues a "find" command
+  if (z3950_verbosity_>1) {
+    cerr << "Entering ztest_search" << endl;
+  }
+
+  Response_tlist.clear();
+  Response_tlist_colnames.clear();
+  Response_tlist_sizes.clear();
+ 
+  comerror_t err;
+  FilterRequest_t request;
+
+  request.filterName = "QueryFilter";
+  request.filterResultOptions = FROID | FRtermFreq | FRmetadata;  
+
+  OptionValue_t option;
+
+  // how many results to get. grouping all results together into
+  // one set instead of breaking up into "pages". 
+  // note: see if Z39.50 has a concept of pages.
+  option.name = "StartResults";
+  option.value = "1";
+  request.filterOptions.push_back (option);
+  option.name = "EndResults";
+  option.value = MAXHITS;
+  request.filterOptions.push_back (option);
+  option.name = "Maxdocs";
+  option.value = MAXHITS;
+  request.filterOptions.push_back (option);
+
+  text_t GSQuery = ZQueryToGSQuery(rr);
+  option.name = "Term";
+  option.value = GSQuery;
+  request.filterOptions.push_back (option);
+  Resultsets[Resultsets.size()+1] = GSQuery;
+
+  option.name = "QueryType";
+  option.value = "boolean";
+  request.filterOptions.push_back (option);
+
+  option.name = "MatchMode";
+  option.value = "all";
+  request.filterOptions.push_back (option);
+
+  option.name = "Casefold";
+  option.value = "true";
+  request.filterOptions.push_back (option);
+
+  option.name = "Stem";
+  option.value = "false";
+  request.filterOptions.push_back (option);
+
+  option.name = "AccentFold";
+  option.value = "false";
+  request.filterOptions.push_back (option);
+  
+  // MG queries don't need this, MGPP queries do.
+  // doesn't do any harm to include it anyway.
+  // note: not all collections have document-level granularity...
+  option.name = "Level";
+  option.value = "Doc";
+  request.filterOptions.push_back (option);
+
+  // Z39.50 supports the searching of multiple databases
+  rr->hits = 0;
+  for (int i = 0; i < rr->num_bases; i++) {
+    FilterResponse_t response;
+    cerr << "Searching basename = " << rr->basenames[i] << endl;
+    // intercept Explain requests
+    if (strcmp(rr->basenames[i], "IR-Explain-1")==0) {
+      //ColInfoResponse_t collectinfo;
+      //Protocol->get_collectinfo("csbib", collectinfo, err, cerr);
+      //response.numDocs = 1;
+      //ResultDocInfo_t docinfo;
+      //docinfo.metadata["foo"].values.push_back("bar");
+      getExplainInfo(rr, response, err);
+      //response.docInfo.push_back(docinfo);
+    } else {
+      cerr << "calling filter..." << endl;
+      Protocol->filter(rr->basenames[i], request, response, err, cerr);
+      cerr << "returned from filter." << endl;
+      if (response.numDocs > MAXHITS) {
+	response.numDocs = MAXHITS;
+      }
+    }
+    rr->hits += response.numDocs;
+    Response_tlist.push_back(response);
+    text_t basename = rr->basenames[i];
+    Response_tlist_colnames.push_back(basename);
+    Response_tlist_sizes.push_back(response.numDocs);
+    cerr << "search complete." << endl;
+  }    
+
+  if (rr->hits > MAXHITS) rr->hits = MAXHITS;
+  return 0;
+}
+
+// *** extra code for showing results, not needed ***
+int ztest_present (void *handle, bend_present_rr *rr)
+{
+  // *** called when client issues a "show" command, 1st of 5
+  if (z3950_verbosity_>1) {
+    cerr << "entering ztest_present" << endl;
+  }
+  return 0;
+}
+
+int ztest_esrequest (void *handle, bend_esrequest_rr *rr)
+{
+
+    if (z3950_verbosity_>1) {
+      cerr << "Entering ztest_esrequest" << endl;
+    }
+    yaz_log(LOG_LOG, "function: %d", *rr->esr->function);
+    if (rr->esr->packageName)
+    	yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName);
+    yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction);
+
+    if (!rr->esr->taskSpecificParameters)
+    {
+        yaz_log (LOG_WARN, "No task specific parameters");
+    }
+    else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder)
+    {
+    	Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder;
+	yaz_log (LOG_LOG, "Received ItemOrder");
+	switch (it->which)
+	{
+#ifdef ASN_COMPILED
+	case Z_IOItemOrder_esRequest:
+#else
+	case Z_ItemOrder_esRequest:
+#endif
+	{
+	    Z_IORequest *ir = it->u.esRequest;
+	    Z_IOOriginPartToKeep *k = ir->toKeep;
+	    Z_IOOriginPartNotToKeep *n = ir->notToKeep;
+	    
+	    if (k && k->contact)
+	    {
+	        if (k->contact->name)
+		    yaz_log(LOG_LOG, "contact name %s", k->contact->name);
+		if (k->contact->phone)
+		    yaz_log(LOG_LOG, "contact phone %s", k->contact->phone);
+		if (k->contact->email)
+		    yaz_log(LOG_LOG, "contact email %s", k->contact->email);
+	    }
+	    if (k->addlBilling)
+	    {
+	        yaz_log(LOG_LOG, "Billing info (not shown)");
+	    }
+	    
+	    if (n->resultSetItem)
+	    {
+	        yaz_log(LOG_LOG, "resultsetItem");
+		yaz_log(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId);
+		yaz_log(LOG_LOG, "item: %d", *n->resultSetItem->item);
+	    }
+#ifdef ASN_COMPILED
+	    if (n->itemRequest)
+	    {
+		Z_External *r = (Z_External*) n->itemRequest;
+		ILL_ItemRequest *item_req = 0;
+		ILL_Request *ill_req = 0;
+		if (r->direct_reference)
+		{
+		    oident *ent = oid_getentbyoid(r->direct_reference);
+		    if (ent)
+			yaz_log(LOG_LOG, "OID %s", ent->desc);
+		    if (ent && ent->value == VAL_ISO_ILL_1)
+		    {
+			yaz_log (LOG_LOG, "ItemRequest");
+			if (r->which == ODR_EXTERNAL_single)
+			{
+			    odr_setbuf(rr->decode,
+				       (char*)(r->u.single_ASN1_type->buf),
+				       r->u.single_ASN1_type->len, 0);
+			    
+			    if (!ill_ItemRequest (rr->decode, &item_req, 0, 0))
+			    {
+				yaz_log (LOG_LOG,
+                                    "Couldn't decode ItemRequest %s near %d",
+                                       odr_errmsg(odr_geterror(rr->decode)),
+                                       odr_offset(rr->decode));
+                                yaz_log(LOG_LOG, "PDU dump:");
+                                odr_dumpBER(yaz_log_file(),
+                                     (const char*)(r->u.single_ASN1_type->buf),
+                                     r->u.single_ASN1_type->len);
+                            }
+			    if (rr->print)
+			    {
+				ill_ItemRequest (rr->print, &item_req, 0,
+                                    "ItemRequest");
+				odr_reset (rr->print);
+ 			    }
+			}
+			if (!item_req && r->which == ODR_EXTERNAL_single)
+			{
+			    yaz_log (LOG_LOG, "ILLRequest");
+			    odr_setbuf(rr->decode,
+				       (char*)(r->u.single_ASN1_type->buf),
+				       r->u.single_ASN1_type->len, 0);
+			    
+			    if (!ill_Request (rr->decode, &ill_req, 0, 0))
+			    {
+				yaz_log (LOG_LOG,
+                                    "Couldn't decode ILLRequest %s near %d",
+                                       odr_errmsg(odr_geterror(rr->decode)),
+                                       odr_offset(rr->decode));
+                                yaz_log(LOG_LOG, "PDU dump:");
+                                odr_dumpBER(yaz_log_file(),
+                                     (const char*)(r->u.single_ASN1_type->buf),
+                                     r->u.single_ASN1_type->len);
+                            }
+			    if (rr->print)
+                            {
+				ill_Request (rr->print, &ill_req, 0,
+                                    "ILLRequest");
+				odr_reset (rr->print);
+			    }
+			}
+		    }
+		}
+		if (item_req)
+		{
+		    yaz_log (LOG_LOG, "ILL protocol version = %d",
+			     *item_req->protocol_version_num);
+		}
+	    }
+#endif
+	}
+	break;
+	}
+    }
+    else if (rr->esr->taskSpecificParameters->which == Z_External_update)
+    {
+    	Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update;
+	yaz_log (LOG_LOG, "Received DB Update");
+	if (up->which == Z_IUUpdate_esRequest)
+	{
+	    Z_IUUpdateEsRequest *esRequest = up->u.esRequest;
+	    Z_IUOriginPartToKeep *toKeep = esRequest->toKeep;
+	    Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep;
+	    
+	    yaz_log (LOG_LOG, "action");
+	    if (toKeep->action)
+	    {
+		switch (*toKeep->action)
+		{
+		case Z_IUOriginPartToKeep_recordInsert:
+		    yaz_log (LOG_LOG, " recordInsert");
+		    break;
+		case Z_IUOriginPartToKeep_recordReplace:
+		    yaz_log (LOG_LOG, " recordUpdate");
+		    break;
+		case Z_IUOriginPartToKeep_recordDelete:
+		    yaz_log (LOG_LOG, " recordDelete");
+		    break;
+		case Z_IUOriginPartToKeep_elementUpdate:
+		    yaz_log (LOG_LOG, " elementUpdate");
+		    break;
+		case Z_IUOriginPartToKeep_specialUpdate:
+		    yaz_log (LOG_LOG, " specialUpdate");
+		    break;
+		default:
+		    yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action);
+		}
+	    }
+	    if (toKeep->databaseName)
+	    {
+		yaz_log (LOG_LOG, "database: %s", toKeep->databaseName);
+		if (!strcmp(toKeep->databaseName, "fault"))
+		{
+		    rr->errcode = 109;
+		    rr->errstring = toKeep->databaseName;
+		}
+		if (!strcmp(toKeep->databaseName, "accept"))
+		    rr->errcode = -1;
+	    }
+	    if (notToKeep)
+	    {
+		int i;
+		for (i = 0; i < notToKeep->num; i++)
+		{
+		    Z_External *rec = notToKeep->elements[i]->record;
+
+		    if (rec->direct_reference)
+		    {
+			struct oident *oident;
+			oident = oid_getentbyoid(rec->direct_reference);
+			if (oident)
+			    yaz_log (LOG_LOG, "record %d type %s", i,
+				     oident->desc);
+		    }
+		    switch (rec->which)
+		    {
+		    case Z_External_sutrs:
+			if (rec->u.octet_aligned->len > 170)
+			    yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
+				     rec->u.sutrs->len,
+				     rec->u.sutrs->buf);
+			else
+			    yaz_log (LOG_LOG, "%d bytes:\n%s",
+				     rec->u.sutrs->len,
+				     rec->u.sutrs->buf);
+                        break;
+		    case Z_External_octet        :
+			if (rec->u.octet_aligned->len > 170)
+			    yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
+				     rec->u.octet_aligned->len,
+				     rec->u.octet_aligned->buf);
+			else
+			    yaz_log (LOG_LOG, "%d bytes\n%s",
+				     rec->u.octet_aligned->len,
+				     rec->u.octet_aligned->buf);
+		    }
+		}
+	    }
+	}
+    }
+    else
+    {
+        yaz_log (LOG_WARN, "Unknown Extended Service(%d)",
+		 rr->esr->taskSpecificParameters->which);
+	
+    }
+    return 0;
+}
+
+int ztest_delete (void *handle, bend_delete_rr *rr)
+{
+  // *** called when client issues a "delete" command
+  if (z3950_verbosity_>1) {
+    cerr << "Entering ztest_delete" << endl;
+  }
+  if (rr->num_setnames == 1 && !strcmp (rr->setnames[0], "1"))
+    rr->delete_status = Z_DeleteStatus_success;
+  else
+    rr->delete_status = Z_DeleteStatus_resultSetDidNotExist;
+  return 0;
+}
+
+// *** do we want to sort the results? ***
+/* Our sort handler really doesn't sort... */
+int ztest_sort (void *handle, bend_sort_rr *rr)
+{
+  if (z3950_verbosity_>1) {
+    cerr << "entering ztest_sort" << endl;
+  }
+  rr->errcode = 0;
+  rr->sort_status = Z_SortStatus_success;
+  return 0;
+}
+
+static int atoin (const char *buf, int n)
+{
+  // *** called when client issues a "show" command, 5th of 5
+  // *** NOT called if the "show" command has an invalid argument
+    if (z3950_verbosity_>1) {
+      cerr << "Entering atoin" << endl;
+    }
+    int val = 0;
+    while (--n >= 0)
+    {
+        if (isdigit(*buf))
+            val = val*10 + (*buf - '0');
+        buf++;
+    }
+    return val;
+}
+
+
+bool get_sutrs_record (int recnum, text_t &MetadataResult, text_t &CollectionName)
+{
+  if (z3950_verbosity_>1) {
+    cerr << "Entering get_sutrs_record" << endl;
+  }
+  int total_records = 0;
+
+  list<FilterResponse_t>::iterator RESPONSE_here = Response_tlist.begin();
+  list<FilterResponse_t>::iterator RESPONSE_end = Response_tlist.end();
+  list<text_t>::iterator RESPONSE_COLNAMES_here = Response_tlist_colnames.begin();
+  list<text_t>::iterator RESPONSE_COLNAMES_end = Response_tlist_colnames.end();
+  list<int>::iterator RESPONSE_SIZES_here = Response_tlist_sizes.begin();
+  list<int>::iterator RESPONSE_SIZES_end = Response_tlist_sizes.end();
+
+  RESPONSE_here = Response_tlist.begin();
+  RESPONSE_end = Response_tlist.end();
+  while (RESPONSE_here != RESPONSE_end) {
+    total_records += (*RESPONSE_here).numDocs;
+    RESPONSE_here++;
+  }
+
+  // check that the index is within bounds
+  if (recnum < 1 || recnum > total_records) {
+    cerr << "get_sutrs_record failed" << endl;
+    return false; // failed
+  } else {
+    FilterResponse_t response;
+    // iterate through Response_tlist to find the right response
+    RESPONSE_here = Response_tlist.begin();
+    RESPONSE_end = Response_tlist.end();
+    RESPONSE_COLNAMES_here = Response_tlist_colnames.begin();
+    RESPONSE_COLNAMES_end = Response_tlist_colnames.end();
+    RESPONSE_SIZES_here = Response_tlist_sizes.begin();
+    RESPONSE_SIZES_end = Response_tlist_sizes.end();
+    int n = 0;
+
+    while (RESPONSE_here != RESPONSE_end) {
+      n += *RESPONSE_SIZES_here;
+      if (n >= recnum) {
+	response = *RESPONSE_here;
+	CollectionName = *RESPONSE_COLNAMES_here;
+	recnum = *RESPONSE_SIZES_here - (n - recnum);
+	break;
+      }
+      // these should all have the same number of elements,
+      // so only need to check that one is within bounds.
+      // may want to combine these into a larger data structure later.
+      RESPONSE_here++;
+      RESPONSE_COLNAMES_here++;
+      RESPONSE_SIZES_here++;
+    }
+
+    // locate the desired record in the response 
+   
+    MetadataInfo_tmap::iterator METAFIELD_here = response.docInfo[recnum-1].metadata.begin();
+    MetadataInfo_tmap::iterator METAFIELD_end = response.docInfo[recnum-1].metadata.end();
+
+    while (METAFIELD_here!=METAFIELD_end) {
+      text_tarray::iterator METAVALUE_here = METAFIELD_here->second.values.begin();
+      text_tarray::iterator METAVALUE_end = METAFIELD_here->second.values.end();
+      while (METAVALUE_here!=METAVALUE_end) {
+	// construct a text_t containing the record:
+	// there are multiple metadata fields,
+	// each field can have multiple values.
+	/*
+	// don't include fields starting with a lowercase letter,
+	// these are system fields.
+	// later: include these anyway, since Explain fields start with lowercase letters
+	if (METAFIELD_here->first[0] >= 'A' &&
+	    METAFIELD_here->first[0] <= 'Z') {
+	*/
+	  MetadataResult += METAFIELD_here->first; // field name
+	  MetadataResult += " ";
+	  MetadataResult += *METAVALUE_here; // field contents
+	  MetadataResult += "\n";
+	  //}
+	METAVALUE_here++;
+      }
+      METAFIELD_here++;
+    }
+    return true; // succeeded
+  }
+}
+
+bool get_marc_record (int recnum, list<metatag*> &Metatag_list, text_t &CollectionName)
+{
+  if (z3950_verbosity_>1) {
+    cerr << "Entering get_marc_record" << endl;
+  }
+  int total_records = 0;
+
+  list<FilterResponse_t>::iterator RESPONSE_here = Response_tlist.begin();
+  list<FilterResponse_t>::iterator RESPONSE_end = Response_tlist.end();
+  list<text_t>::iterator RESPONSE_COLNAMES_here = Response_tlist_colnames.begin();
+  list<text_t>::iterator RESPONSE_COLNAMES_end = Response_tlist_colnames.end();
+  list<int>::iterator RESPONSE_SIZES_here = Response_tlist_sizes.begin();
+  list<int>::iterator RESPONSE_SIZES_end = Response_tlist_sizes.end();
+
+  RESPONSE_here = Response_tlist.begin();
+  RESPONSE_end = Response_tlist.end();
+  while (RESPONSE_here != RESPONSE_end) {
+    total_records += (*RESPONSE_here).numDocs;
+    RESPONSE_here++;
+  }
+
+  // check that the index is within bounds
+  if (recnum < 1 || recnum > total_records) {
+    cerr << "get_marc_record failed" << endl;
+    return false; // failed
+  } else {
+    FilterResponse_t response;
+    // iterate through Response_tlist to find the right response
+    RESPONSE_here = Response_tlist.begin();
+    RESPONSE_end = Response_tlist.end();
+    RESPONSE_COLNAMES_here = Response_tlist_colnames.begin();
+    RESPONSE_COLNAMES_end = Response_tlist_colnames.end();
+    RESPONSE_SIZES_here = Response_tlist_sizes.begin();
+    RESPONSE_SIZES_end = Response_tlist_sizes.end();
+    int n = 0;
+    while (RESPONSE_here != RESPONSE_end) {
+      n += *RESPONSE_SIZES_here;
+      if (n >= recnum) {
+	response = *RESPONSE_here;
+	CollectionName = *RESPONSE_COLNAMES_here;
+	recnum = *RESPONSE_SIZES_here - (n - recnum);
+	break;
+      }
+      // these should all have the same number of elements,
+      // so only need to check that one is within bounds.
+      // may want to combine these into a larger data structure later.
+      RESPONSE_here++;
+      RESPONSE_COLNAMES_here++;
+      RESPONSE_SIZES_here++;
+    }
+
+    // locate the desired record in the response
+    
+    MetadataInfo_tmap::iterator METAFIELD_here = response.docInfo[recnum-1].metadata.begin();
+    MetadataInfo_tmap::iterator METAFIELD_end = response.docInfo[recnum-1].metadata.end();
+    
+    while (METAFIELD_here!=METAFIELD_end) {
+      text_tarray::iterator METAVALUE_here = METAFIELD_here->second.values.begin();
+      text_tarray::iterator METAVALUE_end = METAFIELD_here->second.values.end();
+      while (METAVALUE_here!=METAVALUE_end) {
+	if (METAFIELD_here->first[0] >= 'A' &&
+	    METAFIELD_here->first[0] <= 'Z') {
+	  metatag *tmptag = new metatag();
+	  tmptag->name = METAFIELD_here->first.getcstr();
+	  tmptag->type = "";
+	  tmptag->scheme = "";
+	  tmptag->value = (*METAVALUE_here).getcstr();
+	  Metatag_list.push_back(tmptag);
+	}
+	METAVALUE_here++;
+      }
+      METAFIELD_here++;
+    }
+    return true; // succeeded
+  }
+}
+
+// *** implement this ***
+int ztest_fetch(void *handle, bend_fetch_rr *r)
+{
+  // *** called when client issues a "show" command, 2nd of 5
+    if (z3950_verbosity_>1) {
+      cerr << "Entering ztest_fetch" << endl;
+    }
+    char *cp;
+    r->errstring = 0;
+    r->last_in_set = 0;
+    r->basename = "DUMMY"; // this is set below
+    r->output_format = r->request_format;
+
+    // *** use this until found a good way of mapping Greenstone
+    // *** metadata fields to USMARC fields
+    if (r->request_format == VAL_SUTRS)
+    {
+      // copies record into r, errcode will be 13 if fails
+      text_t MetadataResult;
+      text_t CollectionName;
+      if (!get_sutrs_record(r->number, MetadataResult, CollectionName)) {
+	r->errcode = 13;
+	return 0;
+      } else {			
+	r->len = MetadataResult.size();
+	r->record = (char*) odr_malloc(r->stream, r->len+1);
+	char *tmptxt = MetadataResult.getcstr();
+	strcpy(r->record, tmptxt);
+	delete tmptxt;
+	r->basename = (char*) odr_malloc(r->stream, CollectionName.size()+1);
+	tmptxt = CollectionName.getcstr();
+	strcpy(r->basename, tmptxt);
+	delete tmptxt;
+      }
+    }
+    // *** do we want to use this format? ***
+    else if (r->request_format == VAL_GRS1)
+    {
+      // bail out, since we don't support grs (yet?)
+      r->errcode = 107; // "Query type not supported"
+      return 0;
+      
+    } 
+    // assume that here on in is some sort of MARC format
+    else {
+      marcrec *mrec = new marcrec;
+
+      mrec = (marcrec*) malloc(sizeof(*mrec));
+      
+      mrec->marcline = (char*) malloc(100000);
+      mrec->partitle = (char*) malloc(10000);
+      mrec->subtitle = (char*) malloc(10000);
+      mrec->year     = (char*) malloc(1000);
+      mrec->url      = (char*) malloc(1000);
+      mrec->fmat     = (char*) malloc(1000);
+      mrec->s008     = (char*) malloc(41);
+      
+      mrec->ncreators = 0;
+      mrec->ntitles   = 0;
+      *mrec->marcline = 0;
+      *mrec->subtitle = 0;
+      *mrec->partitle = 0;
+      *mrec->year     = 0;
+      *mrec->url      = 0;
+      *mrec->fmat     = 0;
+      strcpy(mrec->s008, "                                        ");
+
+      text_t CollectionName;
+      list<metatag*> Metatag_list;
+
+      if (!get_marc_record(r->number, Metatag_list, CollectionName)) {
+	r->errcode = 13;
+	return 0;
+      } else {
+	list<metatag*>::iterator METATAG_here = Metatag_list.begin();
+	list<metatag*>::iterator METATAG_end = Metatag_list.end();
+	while (METATAG_here != METATAG_end) {
+	  usMARC(*METATAG_here, mrec);
+	  METATAG_here++;
+	}
+
+	// set the date in the marc record to the current date
+	char today[32];
+	time_t d;
+	struct tm *time_struct;
+	//putenv("TZ=NFT-1DFT");
+	d = time(NULL);
+	time_struct = localtime(&d);
+	strftime(today, 16, "%y%m%d", time_struct);
+	put008(mrec->s008, today, F008_DATE_ENTERED);
+	put008(mrec->s008, "s", F008_TYPE_OF_DATE);
+
+	// to do: make this safer + more efficient
+	cp = new char[1000000];
+	char *cp2 = new char[1000000];
+	
+	switch(r->request_format) {
+	case VAL_DANMARC: {
+	  MARCtidy(mrec, cp, DANMARC);
+	  r->output_format = VAL_DANMARC;
+	  break; }
+	case VAL_FINMARC: {
+	  MARCtidy(mrec, cp, FINMARC);
+	  r->output_format = VAL_FINMARC;
+	  break; }
+	// YAZ doesn't know about ISMARC
+	/*
+	case VAL_ISMARC: {
+	  put008(mrec->s008, "k", F008_FORM_OF_PUBLICATION);
+	  MARCtidy(mrec, cp, ISMARC);
+	  r->output_format = VAL_ISMARC;
+	  break; }
+	*/
+	case VAL_NORMARC: {
+	  MARCtidy(mrec, cp, NORMARC);
+	  r->output_format = VAL_NORMARC;
+	  break; }
+	case VAL_SWEMARC: {
+	  MARCtidy(mrec, cp, SWEMARC);
+	  r->output_format = VAL_SWEMARC;
+	  break; }
+	default: {
+	  MARCtidy(mrec, cp, USMARC);
+	  r->output_format = VAL_USMARC;
+	  break; }
+	}
+	
+	sprintf(cp2, "%s", (char*) MARC2709(cp, 0, 6, 'n', 'm', ' '));
+	r->len = strlen(cp2);
+	r->record = (char*) odr_malloc(r->stream, r->len+1);
+	strcpy(r->record, cp2);     
+	r->basename = (char*) odr_malloc(r->stream, CollectionName.size()+1);
+	char *tmptxt;
+	tmptxt = CollectionName.getcstr();
+	strcpy(r->basename, tmptxt);
+	delete tmptxt;
+	delete cp2;      
+	cerr << "dumping record:`" << cp << "'" << endl;
+	delete cp;
+      }
+    }
+
+    r->errcode = 0;
+    return 0;
+}
+
+/*
+ * silly dummy-scan what reads words from a file.
+ */
+int ztest_scan(void *handle, bend_scan_rr *q)
+{
+  // *** called when client issues a "scan" command
+  if (z3950_verbosity_>1) {
+    cerr << "Entering ztest_scan" << endl;
+  }
+    
+  // bail out, since we don't support scan (yet?)
+  q->errcode = 107; // "Query type not supported"
+  return 0;
+
+    static FILE *f = 0;
+    static struct scan_entry list[200];
+    static char entries[200][80];
+    int hits[200];
+    char term[80], *p;
+    int i, pos;
+    int term_position_req = q->term_position;
+    int num_entries_req = q->num_entries;
+
+    q->errcode = 0;
+    q->errstring = 0;
+    q->entries = list;
+    q->status = BEND_SCAN_SUCCESS;
+    if (!f && !(f = fopen("dummy-words", "r")))
+    {
+	perror("dummy-words");
+	exit(1);
+    }
+    if (q->term->term->which != Z_Term_general)
+    {
+    	q->errcode = 229; /* unsupported term type */
+	return 0;
+    }
+    if (*q->step_size != 0)
+    {
+	q->errcode = 205; /*Only zero step size supported for Scan */
+	return 0;
+    }
+    if (q->term->term->u.general->len >= 80)
+    {
+    	q->errcode = 11; /* term too long */
+	return 0;
+    }
+    if (q->num_entries > 200)
+    {
+    	q->errcode = 31;
+	return 0;
+    }
+    memcpy(term, q->term->term->u.general->buf, q->term->term->u.general->len);
+    term[q->term->term->u.general->len] = '\0';
+    for (p = term; *p; p++)
+    	if (islower(*p))
+	    *p = toupper(*p);
+
+    fseek(f, 0, SEEK_SET);
+    q->num_entries = 0;
+
+    for (i = 0, pos = 0; fscanf(f, " %79[^:]:%d", entries[pos], &hits[pos]) == 2;
+	i++, pos < 199 ? pos++ : (pos = 0))
+    {
+    	if (!q->num_entries && strcmp(entries[pos], term) >= 0) /* s-point fnd */
+	{
+	    if ((q->term_position = term_position_req) > i + 1)
+	    {
+	    	q->term_position = i + 1;
+		q->status = BEND_SCAN_PARTIAL;
+	    }
+	    for (; q->num_entries < q->term_position; q->num_entries++)
+	    {
+	    	int po;
+
+		po = pos - q->term_position + q->num_entries+1; /* find pos */
+		if (po < 0)
+		    po += 200;
+
+		if (!strcmp (term, "SD") && q->num_entries == 2)
+		{
+		    list[q->num_entries].term = entries[pos];
+		    list[q->num_entries].occurrences = -1;
+		    list[q->num_entries].errcode = 233;
+		    list[q->num_entries].errstring = "SD for Scan Term";
+		}
+		else
+		{
+		    list[q->num_entries].term = entries[po];
+		    list[q->num_entries].occurrences = hits[po];
+		}
+	    }
+	}
+	else if (q->num_entries)
+	{
+	    list[q->num_entries].term = entries[pos];
+	    list[q->num_entries].occurrences = hits[pos];
+	    q->num_entries++;
+	}
+	if (q->num_entries >= num_entries_req)
+	    break;
+    }
+    if (feof(f))
+    	q->status = BEND_SCAN_PARTIAL;
+    return 0;
+}
+
+
+
+void bend_close(void *handle)
+{
+  if (z3950_verbosity_>1) {
+    cerr << "Entering bend_close" << endl;
+  }
+  delete Server;
+  delete Cservers;
+  delete Protocol;
+  if (z3950_verbosity_>1) {
+    cerr << "heap cleaned up, exiting bend_close" << endl;
+  }
+  return;
+}
+
+int main (int argc, char *argv[])
+{
+  
+  const int statserv_var =  statserv_main(argc, argv, bend_init, bend_close);
+  cerr << "statserv_main returns: " << statserv_var << endl;
+  return statserv_var;
+  
+  return 0;
+}
+
+
Index: /gsdl/trunk/runtime-src/src/z3950/z3950server.h
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/z3950server.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/z3950server.h	(revision 16571)
@@ -0,0 +1,71 @@
+/**********************************************************************
+ *
+ * z3950server.h --
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#ifndef Z3950SERVER_H
+#define Z3950ESRVER_H
+
+#include <string>
+#include <list>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <time.h>
+
+// Greenstone headers
+#include "fileutil.h"
+
+// the maximum number of hits allowed
+#define MAXHITS 10000
+
+// These globals are local to each thread: one Z39.50 connection = one thread.
+
+extern text_t gsdlhome; // this is specified externally when Greenstone is installed
+extern list<FilterResponse_t> Response_tlist; // list of response sets
+extern list<text_t> Response_tlist_colnames;  // collection names for the above
+extern list<int> Response_tlist_sizes;        // sizes (number of records) for the above
+extern z3950Server *Server;
+extern collectset *Cservers;
+extern nullproto *Protocol;
+extern map<text_t, gsdlCollection> Collection_map; // info and tools for collections
+extern map<text_t, text_t> Resultsets;             // mapping from ResultSetId to GSQuery 
+
+extern int z3950_verbosity_;
+
+bend_initresult *bend_init(bend_initrequest *q);
+void bend_close(void *handle);
+
+Z_GenericRecord *read_grs1(FILE *f, ODR o);
+
+int ztest_search (void *handle, bend_search_rr *rr);
+int ztest_sort (void *handle, bend_sort_rr *rr);
+int ztest_present (void *handle, bend_present_rr *rr);
+int ztest_esrequest (void *handle, bend_esrequest_rr *rr);
+int ztest_delete (void *handle, bend_delete_rr *rr);
+int ztest_fetch(void *handle, bend_fetch_rr *r);
+int ztest_scan(void *handle, bend_scan_rr *q);
+
+
+#endif
Index: /gsdl/trunk/runtime-src/src/z3950/zparse.fl
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/zparse.fl	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/zparse.fl	(revision 16571)
@@ -0,0 +1,112 @@
+/* This is the lexical analyser - it returns tokens to the parsers.
+   This is used by both parsers - one for the build-time config files
+   and one for the run-time config files. Note the included file "parse.h"
+   is a symlink to the relevant header file. */
+
+%{
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/*#define YYSTYPE char * - YYSTYPE is defined in zparse.tab.h */
+#include "zparse.tab.h"
+
+/* forward declarations for std functions not picked up. */
+/*int fileno(FILE *);*/
+/*char *strdup(char *);*/
+
+int lineno=1;
+%}
+
+%option noyywrap
+
+COMMENT  \#.*(\n|\r)
+
+%x  STRINGCOND
+%%
+	char *string;
+	int string_len;
+
+{COMMENT}		lineno++;/*yylval.string=yytext;*/yyleng=0;
+,			return (',');
+:			return (':');
+\_			return ('_');
+\[GSDL[0-9]+\.[0-9]+\] yylval.string=yytext;return(GSDLVERSION);
+\[General\]		return (GENERAL_SECTION);
+\[Search\ [fF]ields\]	return (SEARCH_SECTION);
+\[Browse\ [fF]ields\]	return (BROWSE_SECTION);
+\[Macros\]		return (MACROS_SECTION);
+maintainer		return (MAINTAINER);
+Languages		return(LANGUAGES);
+About			return(ABOUT);
+Browse			return(BROWSE);
+Date[lL]ist		return(DATELIST);
+Document[aA]rrows[bB]ottom return(DOCUMENTARROWSBOTTOM);
+Document[bB]uttons	return(DOCUMENTBUTTONS);
+Document[hH]eader	return(DOCUMENTHEADER);
+Document[iI]mages	return(DOCUMENTIMAGES);
+Document[tT]ext		return(DOCUMENTTEXT);
+Icon[lL]ink		return(ICONLINK);
+List			return(LIST);
+Format			return(FORMAT);
+Name			return(NAME);
+Search[tT]ext		return(SEARCHTEXT);
+Section[lL]ist		return(SECTIONLIST);
+Sorted[lL]ist		return(SORTEDLIST);
+Sorted[sS]ection[lL]ist	return(SORTEDSECTIONLIST);
+Text[lL]ink		return(TEXTLINK);
+Type			return(TYPE);
+public			return (PUBLIC);
+true			return (TRUE);
+false			return (FALSE);
+^document		return (DOCUMENT);
+^section		return (SECTION);
+[iI]con			return (ICON);
+[sS]mall[iI]con		return (SMALLICON);
+\"			{string=NULL;BEGIN(STRINGCOND);}
+<STRINGCOND>{
+  ([^\"\\\n])*		{/* append this to our current string EXC NEWLINE */
+			if (string==NULL) string_len=0; else
+			string_len=strlen(string);
+			string=realloc(string,string_len+strlen(yytext)+1);
+			/* +1 is for trailing \0 */
+			strcpy(string+string_len,yytext);
+			}
+  ([^\"\\])*\n		{/* append this to our current string - INC NEWLINE */
+			lineno++;
+			if (string==NULL) string_len=0; else
+			string_len=strlen(string);
+			string=realloc(string,string_len+strlen(yytext)+1);
+			/* +1 is for trailing \0 */
+			strcpy(string+string_len,yytext);
+			}
+  "\\"\"		|
+  \"\"		{       /*replace quoted quote with one quote*/
+			string_len=strlen(string);
+			string=realloc(string,string_len+2);
+			string[string_len]='\"';
+			string[string_len+1]='\0';
+			}
+  \"		{
+			BEGIN(INITIAL);
+			yylval.string=string;
+			return(STRING);
+			  /* note that the string may have long bits of 
+			     whitespace in it that we could remove. */
+			}
+}
+[[:alnum:]@\.-]+	yylval.string=strdup(yytext);return (DATA);
+(" "|\t)		;
+(\n|\r)			lineno++;
+%%
+/******** deleted rules: *******
+en			return(EN);
+fr			return(FR);
+mi			return(MI);
+zh			return(ZH);
+de			return(DE);
+***************/
+
+
+
+
Index: /gsdl/trunk/runtime-src/src/z3950/zparse.tab.c
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/zparse.tab.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/zparse.tab.c	(revision 16571)
@@ -0,0 +1,1531 @@
+/* A Bison parser, made by GNU Bison 1.875.  */
+
+/* Skeleton parser for Yacc-like parsing with Bison,
+   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+/* As a special exception, when this file is copied by Bison into a
+   Bison output file, you may use that output file without restriction.
+   This special exception was added by the Free Software Foundation
+   in version 1.24 of Bison.  */
+
+/* Written by Richard Stallman by simplifying the original so called
+   ``semantic'' parser.  */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+   infringing on user name space.  This should be done even for local
+   variables, as they might otherwise be expanded by user macros.
+   There are some unavoidable exceptions within include files to
+   define necessary library symbols; they are noted "INFRINGES ON
+   USER NAME SPACE" below.  */
+
+/* Identify Bison output.  */
+#define YYBISON 1
+
+/* Skeleton name.  */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers.  */
+#define YYPURE 0
+
+/* Using locations.  */
+#define YYLSP_NEEDED 0
+
+
+
+/* Tokens.  */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+   /* Put the tokens into the symbol table, so that GDB and other debuggers
+      know about them.  */
+   enum yytokentype {
+     GSDLVERSION = 257,
+     GENERAL_SECTION = 258,
+     SEARCH_SECTION = 259,
+     BROWSE_SECTION = 260,
+     MACROS_SECTION = 261,
+     MAINTAINER = 262,
+     PUBLIC = 263,
+     TRUE = 264,
+     FALSE = 265,
+     LANGUAGES = 266,
+     EN = 267,
+     FR = 268,
+     MI = 269,
+     ZH = 270,
+     DE = 271,
+     NAME = 272,
+     STRING = 273,
+     ICON = 274,
+     SMALLICON = 275,
+     ABOUT = 276,
+     SEARCHTEXT = 277,
+     DOCUMENT = 278,
+     SECTION = 279,
+     BROWSE = 280,
+     TYPE = 281,
+     FORMAT = 282,
+     LIST = 283,
+     SORTEDLIST = 284,
+     SECTIONLIST = 285,
+     SORTEDSECTIONLIST = 286,
+     DATELIST = 287,
+     ICONLINK = 288,
+     TEXTLINK = 289,
+     DOCUMENTIMAGES = 290,
+     DOCUMENTHEADER = 291,
+     DOCUMENTTEXT = 292,
+     DOCUMENTBUTTONS = 293,
+     DOCUMENTARROWSBOTTOM = 294,
+     DATA = 295
+   };
+#endif
+#define GSDLVERSION 257
+#define GENERAL_SECTION 258
+#define SEARCH_SECTION 259
+#define BROWSE_SECTION 260
+#define MACROS_SECTION 261
+#define MAINTAINER 262
+#define PUBLIC 263
+#define TRUE 264
+#define FALSE 265
+#define LANGUAGES 266
+#define EN 267
+#define FR 268
+#define MI 269
+#define ZH 270
+#define DE 271
+#define NAME 272
+#define STRING 273
+#define ICON 274
+#define SMALLICON 275
+#define ABOUT 276
+#define SEARCHTEXT 277
+#define DOCUMENT 278
+#define SECTION 279
+#define BROWSE 280
+#define TYPE 281
+#define FORMAT 282
+#define LIST 283
+#define SORTEDLIST 284
+#define SECTIONLIST 285
+#define SORTEDSECTIONLIST 286
+#define DATELIST 287
+#define ICONLINK 288
+#define TEXTLINK 289
+#define DOCUMENTIMAGES 290
+#define DOCUMENTHEADER 291
+#define DOCUMENTTEXT 292
+#define DOCUMENTBUTTONS 293
+#define DOCUMENTARROWSBOTTOM 294
+#define DATA 295
+
+
+
+
+/* Copy the first part of user declarations.  */
+#line 27 "zparse.y"
+
+  /* verbatim C code - functions, etc */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include "z3950cfg.h" /* structure types, and #define of yyin/yyparse */
+
+#define YYDEBUG 1
+#define YYERROR_VERBOSE 1
+char defLanguage=0;
+
+/* defined in parse.fl */
+extern int lineno;
+
+#ifndef YYRECOVERING
+int YYRECOVERING=0; /* this is supposed to already be defined as a macro */
+#endif
+
+/* defined in z3950proto.cpp */
+struct z3950cfg *zserver_list=NULL;
+
+/* this is set in z3950proto.cpp */
+FILE *errfile;
+
+int yylex(void);
+
+int yyerror(char *string);
+
+void errormsg(char *str);
+
+
+
+/* Enabling traces.  */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+
+/* Enabling verbose error messages.  */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 0
+#endif
+
+#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
+#line 61 "zparse.y"
+typedef union YYSTYPE {
+  char *string;
+  struct z3950cfg *cfg;
+  struct z3950aboutlist *about;
+  int number;
+} YYSTYPE;
+/* Line 191 of yacc.c.  */
+#line 197 "zparse.tab.c"
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+/* Copy the second part of user declarations.  */
+
+
+/* Line 214 of yacc.c.  */
+#line 209 "zparse.tab.c"
+
+#if ! defined (yyoverflow) || YYERROR_VERBOSE
+
+/* The parser invokes alloca or malloc; define the necessary symbols.  */
+
+# if YYSTACK_USE_ALLOCA
+#  define YYSTACK_ALLOC alloca
+# else
+#  ifndef YYSTACK_USE_ALLOCA
+#   if defined (alloca) || defined (_ALLOCA_H)
+#    define YYSTACK_ALLOC alloca
+#   else
+#    ifdef __GNUC__
+#     define YYSTACK_ALLOC __builtin_alloca
+#    endif
+#   endif
+#  endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+   /* Pacify GCC's `empty if-body' warning. */
+#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+# else
+#  if defined (__STDC__) || defined (__cplusplus)
+#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+#   define YYSIZE_T size_t
+#  endif
+#  define YYSTACK_ALLOC malloc
+#  define YYSTACK_FREE free
+# endif
+#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
+
+
+#if (! defined (yyoverflow) \
+     && (! defined (__cplusplus) \
+	 || (YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member.  */
+union yyalloc
+{
+  short yyss;
+  YYSTYPE yyvs;
+  };
+
+/* The size of the maximum gap between one aligned stack and the next.  */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+   N elements.  */
+# define YYSTACK_BYTES(N) \
+     ((N) * (sizeof (short) + sizeof (YYSTYPE))				\
+      + YYSTACK_GAP_MAXIMUM)
+
+/* Copy COUNT objects from FROM to TO.  The source and destination do
+   not overlap.  */
+# ifndef YYCOPY
+#  if 1 < __GNUC__
+#   define YYCOPY(To, From, Count) \
+      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+#  else
+#   define YYCOPY(To, From, Count)		\
+      do					\
+	{					\
+	  register YYSIZE_T yyi;		\
+	  for (yyi = 0; yyi < (Count); yyi++)	\
+	    (To)[yyi] = (From)[yyi];		\
+	}					\
+      while (0)
+#  endif
+# endif
+
+/* Relocate STACK from its old location to the new one.  The
+   local variables YYSIZE and YYSTACKSIZE give the old and new number of
+   elements in the stack, and YYPTR gives the new location of the
+   stack.  Advance YYPTR to a properly aligned location for the next
+   stack.  */
+# define YYSTACK_RELOCATE(Stack)					\
+    do									\
+      {									\
+	YYSIZE_T yynewbytes;						\
+	YYCOPY (&yyptr->Stack, Stack, yysize);				\
+	Stack = &yyptr->Stack;						\
+	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+	yyptr += yynewbytes / sizeof (*yyptr);				\
+      }									\
+    while (0)
+
+#endif
+
+#if defined (__STDC__) || defined (__cplusplus)
+   typedef signed char yysigned_char;
+#else
+   typedef short yysigned_char;
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL  4
+/* YYLAST -- Last index in YYTABLE.  */
+#define YYLAST   44
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS  44
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS  13
+/* YYNRULES -- Number of rules. */
+#define YYNRULES  28
+/* YYNRULES -- Number of states. */
+#define YYNSTATES  37
+
+/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
+#define YYUNDEFTOK  2
+#define YYMAXUTOK   296
+
+#define YYTRANSLATE(YYX) 						\
+  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
+static const unsigned char yytranslate[] =
+{
+       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,    42,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,    43,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+       2,     2,     2,     2,     2,     2,     1,     3,     4,     5,
+       6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
+      16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
+      26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
+      36,    37,    38,    39,    40,    41,     2
+};
+
+#if YYDEBUG
+/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+   YYRHS.  */
+static const unsigned char yyprhs[] =
+{
+       0,     0,     3,     6,     8,    10,    11,    14,    16,    25,
+      27,    29,    30,    33,    34,    37,    40,    41,    44,    47,
+      48,    50,    51,    53,    56,    60,    63,    67,    69
+};
+
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+static const yysigned_char yyrhs[] =
+{
+      45,     0,    -1,    46,    47,    -1,    46,    -1,     3,    -1,
+      -1,    47,    48,    -1,    48,    -1,    41,    41,    50,    41,
+      49,    51,    52,    53,    -1,     1,    -1,    19,    -1,    -1,
+      42,    41,    -1,    -1,    20,    19,    -1,    20,    41,    -1,
+      -1,    21,    19,    -1,    21,    41,    -1,    -1,    54,    -1,
+      -1,    55,    -1,    54,    55,    -1,    22,    56,    19,    -1,
+      22,    19,    -1,    41,    43,    41,    -1,    41,    -1,     1,
+      -1
+};
+
+/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
+static const unsigned char yyrline[] =
+{
+       0,   106,   106,   107,   110,   111,   113,   114,   116,   137,
+     141,   142,   147,   148,   151,   152,   155,   156,   157,   162,
+     164,   165,   167,   169,   172,   183,   205,   213,   221
+};
+#endif
+
+#if YYDEBUG || YYERROR_VERBOSE
+/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+   First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+  "$end", "error", "$undefined", "GSDLVERSION", "GENERAL_SECTION", 
+  "SEARCH_SECTION", "BROWSE_SECTION", "MACROS_SECTION", "MAINTAINER", 
+  "PUBLIC", "TRUE", "FALSE", "LANGUAGES", "EN", "FR", "MI", "ZH", "DE", 
+  "NAME", "STRING", "ICON", "SMALLICON", "ABOUT", "SEARCHTEXT", 
+  "DOCUMENT", "SECTION", "BROWSE", "TYPE", "FORMAT", "LIST", "SORTEDLIST", 
+  "SECTIONLIST", "SORTEDSECTIONLIST", "DATELIST", "ICONLINK", "TEXTLINK", 
+  "DOCUMENTIMAGES", "DOCUMENTHEADER", "DOCUMENTTEXT", "DOCUMENTBUTTONS", 
+  "DOCUMENTARROWSBOTTOM", "DATA", "':'", "'_'", "$accept", "z3950", 
+  "version", "zserverlist", "zserver", "name", "port", "icon", 
+  "smallicon", "about", "aboutList", "aboutLang", "lang", 0
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
+   token YYLEX-NUM.  */
+static const unsigned short yytoknum[] =
+{
+       0,   256,   296,   257,   258,   259,   260,   261,   262,   263,
+     264,   265,   266,   267,   268,   269,   270,   271,   272,   273,
+     274,   275,   276,   277,   278,   279,   280,   281,   282,   283,
+     284,   285,   286,   287,   288,   289,   290,   291,   292,   293,
+     294,   295,    58,    95
+};
+# endif
+
+/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
+static const unsigned char yyr1[] =
+{
+       0,    44,    45,    45,    46,    46,    47,    47,    48,    48,
+      49,    49,    50,    50,    51,    51,    51,    52,    52,    52,
+      53,    53,    54,    54,    55,    55,    56,    56,    56
+};
+
+/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
+static const unsigned char yyr2[] =
+{
+       0,     2,     2,     1,     1,     0,     2,     1,     8,     1,
+       1,     0,     2,     0,     2,     2,     0,     2,     2,     0,
+       1,     0,     1,     2,     3,     2,     3,     1,     1
+};
+
+/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
+   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
+   means the default is an error.  */
+static const unsigned char yydefact[] =
+{
+       5,     4,     0,     0,     1,     9,     0,     0,     7,    13,
+       6,     0,     0,    12,    11,    10,    16,     0,    19,    14,
+      15,     0,    21,    17,    18,     0,     8,    20,    22,    28,
+      25,    27,     0,    23,     0,    24,    26
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yysigned_char yydefgoto[] =
+{
+      -1,     2,     3,     7,     8,    16,    12,    18,    22,    26,
+      27,    28,    32
+};
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+   STATE-NUM.  */
+#define YYPACT_NINF -33
+static const yysigned_char yypact[] =
+{
+       4,   -33,     8,     0,   -33,   -33,   -32,     2,   -33,   -31,
+     -33,   -29,   -28,   -33,    -9,   -33,    -6,   -14,    -5,   -33,
+     -33,   -13,    -7,   -33,   -33,     3,   -33,    -7,   -33,   -33,
+     -33,   -26,    -1,   -33,   -22,   -33,   -33
+};
+
+/* YYPGOTO[NTERM-NUM].  */
+static const yysigned_char yypgoto[] =
+{
+     -33,   -33,   -33,   -33,    13,   -33,   -33,   -33,   -33,   -33,
+     -33,    -4,   -33
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
+   positive, shift that token.  If negative, reduce the rule which
+   number is the opposite.  If zero, do what YYDEFACT says.
+   If YYTABLE_NINF, syntax error.  */
+#define YYTABLE_NINF -4
+static const yysigned_char yytable[] =
+{
+      -3,     5,    -2,     5,    29,    19,    23,     1,     4,     9,
+      15,    11,    13,    14,    17,    25,    21,    34,    35,    36,
+      10,     0,    30,    33,     0,     0,     0,    20,    24,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     6,     0,     6,    31
+};
+
+static const yysigned_char yycheck[] =
+{
+       0,     1,     0,     1,     1,    19,    19,     3,     0,    41,
+      19,    42,    41,    41,    20,    22,    21,    43,    19,    41,
+       7,    -1,    19,    27,    -1,    -1,    -1,    41,    41,    -1,
+      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,    41,    -1,    41,    41
+};
+
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+   symbol of state STATE-NUM.  */
+static const unsigned char yystos[] =
+{
+       0,     3,    45,    46,     0,     1,    41,    47,    48,    41,
+      48,    42,    50,    41,    41,    19,    49,    20,    51,    19,
+      41,    21,    52,    19,    41,    22,    53,    54,    55,     1,
+      19,    41,    56,    55,    43,    19,    41
+};
+
+#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
+# define YYSIZE_T __SIZE_TYPE__
+#endif
+#if ! defined (YYSIZE_T) && defined (size_t)
+# define YYSIZE_T size_t
+#endif
+#if ! defined (YYSIZE_T)
+# if defined (__STDC__) || defined (__cplusplus)
+#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYSIZE_T size_t
+# endif
+#endif
+#if ! defined (YYSIZE_T)
+# define YYSIZE_T unsigned int
+#endif
+
+#define yyerrok		(yyerrstatus = 0)
+#define yyclearin	(yychar = YYEMPTY)
+#define YYEMPTY		(-2)
+#define YYEOF		0
+
+#define YYACCEPT	goto yyacceptlab
+#define YYABORT		goto yyabortlab
+#define YYERROR		goto yyerrlab1
+
+
+/* Like YYERROR except do call yyerror.  This remains here temporarily
+   to ease the transition to the new meaning of YYERROR, for GCC.
+   Once GCC version 2 has supplanted version 1, this can go.  */
+
+#define YYFAIL		goto yyerrlab
+
+#define YYRECOVERING()  (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value)					\
+do								\
+  if (yychar == YYEMPTY && yylen == 1)				\
+    {								\
+      yychar = (Token);						\
+      yylval = (Value);						\
+      yytoken = YYTRANSLATE (yychar);				\
+      YYPOPSTACK;						\
+      goto yybackup;						\
+    }								\
+  else								\
+    { 								\
+      yyerror ("syntax error: cannot back up");\
+      YYERROR;							\
+    }								\
+while (0)
+
+#define YYTERROR	1
+#define YYERRCODE	256
+
+/* YYLLOC_DEFAULT -- Compute the default location (before the actions
+   are run).  */
+
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N)         \
+  Current.first_line   = Rhs[1].first_line;      \
+  Current.first_column = Rhs[1].first_column;    \
+  Current.last_line    = Rhs[N].last_line;       \
+  Current.last_column  = Rhs[N].last_column;
+#endif
+
+/* YYLEX -- calling `yylex' with the right arguments.  */
+
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (YYLEX_PARAM)
+#else
+# define YYLEX yylex ()
+#endif
+
+/* Enable debugging if requested.  */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+#  define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args)			\
+do {						\
+  if (yydebug)					\
+    YYFPRINTF Args;				\
+} while (0)
+
+# define YYDSYMPRINT(Args)			\
+do {						\
+  if (yydebug)					\
+    yysymprint Args;				\
+} while (0)
+
+# define YYDSYMPRINTF(Title, Token, Value, Location)		\
+do {								\
+  if (yydebug)							\
+    {								\
+      YYFPRINTF (stderr, "%s ", Title);				\
+      yysymprint (stderr, 					\
+                  Token, Value);	\
+      YYFPRINTF (stderr, "\n");					\
+    }								\
+} while (0)
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (cinluded).                                                   |
+`------------------------------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yy_stack_print (short *bottom, short *top)
+#else
+static void
+yy_stack_print (bottom, top)
+    short *bottom;
+    short *top;
+#endif
+{
+  YYFPRINTF (stderr, "Stack now");
+  for (/* Nothing. */; bottom <= top; ++bottom)
+    YYFPRINTF (stderr, " %d", *bottom);
+  YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top)				\
+do {								\
+  if (yydebug)							\
+    yy_stack_print ((Bottom), (Top));				\
+} while (0)
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced.  |
+`------------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yy_reduce_print (int yyrule)
+#else
+static void
+yy_reduce_print (yyrule)
+    int yyrule;
+#endif
+{
+  int yyi;
+  unsigned int yylineno = yyrline[yyrule];
+  YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
+             yyrule - 1, yylineno);
+  /* Print the symbols being reduced, and their result.  */
+  for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
+    YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
+  YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
+}
+
+# define YY_REDUCE_PRINT(Rule)		\
+do {					\
+  if (yydebug)				\
+    yy_reduce_print (Rule);		\
+} while (0)
+
+/* Nonzero means print parse trace.  It is left uninitialized so that
+   multiple parsers can coexist.  */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+# define YYDSYMPRINT(Args)
+# define YYDSYMPRINTF(Title, Token, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks.  */
+#ifndef	YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+   if the built-in stack extension method is used).
+
+   Do not make this value too large; the results are undefined if
+   SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
+   evaluated with infinite-precision integer arithmetic.  */
+
+#if YYMAXDEPTH == 0
+# undef YYMAXDEPTH
+#endif
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+#  if defined (__GLIBC__) && defined (_STRING_H)
+#   define yystrlen strlen
+#  else
+/* Return the length of YYSTR.  */
+static YYSIZE_T
+#   if defined (__STDC__) || defined (__cplusplus)
+yystrlen (const char *yystr)
+#   else
+yystrlen (yystr)
+     const char *yystr;
+#   endif
+{
+  register const char *yys = yystr;
+
+  while (*yys++ != '\0')
+    continue;
+
+  return yys - yystr - 1;
+}
+#  endif
+# endif
+
+# ifndef yystpcpy
+#  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
+#   define yystpcpy stpcpy
+#  else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+   YYDEST.  */
+static char *
+#   if defined (__STDC__) || defined (__cplusplus)
+yystpcpy (char *yydest, const char *yysrc)
+#   else
+yystpcpy (yydest, yysrc)
+     char *yydest;
+     const char *yysrc;
+#   endif
+{
+  register char *yyd = yydest;
+  register const char *yys = yysrc;
+
+  while ((*yyd++ = *yys++) != '\0')
+    continue;
+
+  return yyd - 1;
+}
+#  endif
+# endif
+
+#endif /* !YYERROR_VERBOSE */
+
+
+
+
+#if YYDEBUG
+/*--------------------------------.
+| Print this symbol on YYOUTPUT.  |
+`--------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yysymprint (yyoutput, yytype, yyvaluep)
+    FILE *yyoutput;
+    int yytype;
+    YYSTYPE *yyvaluep;
+#endif
+{
+  /* Pacify ``unused variable'' warnings.  */
+  (void) yyvaluep;
+
+  if (yytype < YYNTOKENS)
+    {
+      YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+# ifdef YYPRINT
+      YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# endif
+    }
+  else
+    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+  switch (yytype)
+    {
+      default:
+        break;
+    }
+  YYFPRINTF (yyoutput, ")");
+}
+
+#endif /* ! YYDEBUG */
+/*-----------------------------------------------.
+| Release the memory associated to this symbol.  |
+`-----------------------------------------------*/
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void
+yydestruct (int yytype, YYSTYPE *yyvaluep)
+#else
+static void
+yydestruct (yytype, yyvaluep)
+    int yytype;
+    YYSTYPE *yyvaluep;
+#endif
+{
+  /* Pacify ``unused variable'' warnings.  */
+  (void) yyvaluep;
+
+  switch (yytype)
+    {
+
+      default:
+        break;
+    }
+}
+
+
+
+/* Prevent warnings from -Wmissing-prototypes.  */
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM);
+# else
+int yyparse ();
+# endif
+#else /* ! YYPARSE_PARAM */
+#if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+
+
+/* The lookahead symbol.  */
+int yychar;
+
+/* The semantic value of the lookahead symbol.  */
+YYSTYPE yylval;
+
+/* Number of syntax errors so far.  */
+int yynerrs;
+
+
+
+/*----------.
+| yyparse.  |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM)
+# else
+int yyparse (YYPARSE_PARAM)
+  void *YYPARSE_PARAM;
+# endif
+#else /* ! YYPARSE_PARAM */
+#if defined (__STDC__) || defined (__cplusplus)
+int
+yyparse (void)
+#else
+int
+yyparse ()
+
+#endif
+#endif
+{
+  
+  register int yystate;
+  register int yyn;
+  int yyresult;
+  /* Number of tokens to shift before error messages enabled.  */
+  int yyerrstatus;
+  /* Lookahead token as an internal (translated) token number.  */
+  int yytoken = 0;
+
+  /* Three stacks and their tools:
+     `yyss': related to states,
+     `yyvs': related to semantic values,
+     `yyls': related to locations.
+
+     Refer to the stacks thru separate pointers, to allow yyoverflow
+     to reallocate them elsewhere.  */
+
+  /* The state stack.  */
+  short	yyssa[YYINITDEPTH];
+  short *yyss = yyssa;
+  register short *yyssp;
+
+  /* The semantic value stack.  */
+  YYSTYPE yyvsa[YYINITDEPTH];
+  YYSTYPE *yyvs = yyvsa;
+  register YYSTYPE *yyvsp;
+
+
+
+#define YYPOPSTACK   (yyvsp--, yyssp--)
+
+  YYSIZE_T yystacksize = YYINITDEPTH;
+
+  /* The variables used to return semantic value and location from the
+     action routines.  */
+  YYSTYPE yyval;
+
+
+  /* When reducing, the number of symbols on the RHS of the reduced
+     rule.  */
+  int yylen;
+
+  YYDPRINTF ((stderr, "Starting parse\n"));
+
+  yystate = 0;
+  yyerrstatus = 0;
+  yynerrs = 0;
+  yychar = YYEMPTY;		/* Cause a token to be read.  */
+
+  /* Initialize stack pointers.
+     Waste one element of value and location stack
+     so that they stay on the same level as the state stack.
+     The wasted elements are never initialized.  */
+
+  yyssp = yyss;
+  yyvsp = yyvs;
+
+  goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate.  |
+`------------------------------------------------------------*/
+ yynewstate:
+  /* In all cases, when you get here, the value and location stacks
+     have just been pushed. so pushing a state here evens the stacks.
+     */
+  yyssp++;
+
+ yysetstate:
+  *yyssp = yystate;
+
+  if (yyss + yystacksize - 1 <= yyssp)
+    {
+      /* Get the current used size of the three stacks, in elements.  */
+      YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+      {
+	/* Give user a chance to reallocate the stack. Use copies of
+	   these so that the &'s don't force the real ones into
+	   memory.  */
+	YYSTYPE *yyvs1 = yyvs;
+	short *yyss1 = yyss;
+
+
+	/* Each stack pointer address is followed by the size of the
+	   data in use in that stack, in bytes.  This used to be a
+	   conditional around just the two extra args, but that might
+	   be undefined if yyoverflow is a macro.  */
+	yyoverflow ("parser stack overflow",
+		    &yyss1, yysize * sizeof (*yyssp),
+		    &yyvs1, yysize * sizeof (*yyvsp),
+
+		    &yystacksize);
+
+	yyss = yyss1;
+	yyvs = yyvs1;
+      }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+      goto yyoverflowlab;
+# else
+      /* Extend the stack our own way.  */
+      if (YYMAXDEPTH <= yystacksize)
+	goto yyoverflowlab;
+      yystacksize *= 2;
+      if (YYMAXDEPTH < yystacksize)
+	yystacksize = YYMAXDEPTH;
+
+      {
+	short *yyss1 = yyss;
+	union yyalloc *yyptr =
+	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+	if (! yyptr)
+	  goto yyoverflowlab;
+	YYSTACK_RELOCATE (yyss);
+	YYSTACK_RELOCATE (yyvs);
+
+#  undef YYSTACK_RELOCATE
+	if (yyss1 != yyssa)
+	  YYSTACK_FREE (yyss1);
+      }
+# endif
+#endif /* no yyoverflow */
+
+      yyssp = yyss + yysize - 1;
+      yyvsp = yyvs + yysize - 1;
+
+
+      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+		  (unsigned long int) yystacksize));
+
+      if (yyss + yystacksize - 1 <= yyssp)
+	YYABORT;
+    }
+
+  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+  goto yybackup;
+
+/*-----------.
+| yybackup.  |
+`-----------*/
+yybackup:
+
+/* Do appropriate processing given the current state.  */
+/* Read a lookahead token if we need one and don't already have one.  */
+/* yyresume: */
+
+  /* First try to decide what to do without reference to lookahead token.  */
+
+  yyn = yypact[yystate];
+  if (yyn == YYPACT_NINF)
+    goto yydefault;
+
+  /* Not known => get a lookahead token if don't already have one.  */
+
+  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
+  if (yychar == YYEMPTY)
+    {
+      YYDPRINTF ((stderr, "Reading a token: "));
+      yychar = YYLEX;
+    }
+
+  if (yychar <= YYEOF)
+    {
+      yychar = yytoken = YYEOF;
+      YYDPRINTF ((stderr, "Now at end of input.\n"));
+    }
+  else
+    {
+      yytoken = YYTRANSLATE (yychar);
+      YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
+    }
+
+  /* If the proper action on seeing token YYTOKEN is to reduce or to
+     detect an error, take that action.  */
+  yyn += yytoken;
+  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+    goto yydefault;
+  yyn = yytable[yyn];
+  if (yyn <= 0)
+    {
+      if (yyn == 0 || yyn == YYTABLE_NINF)
+	goto yyerrlab;
+      yyn = -yyn;
+      goto yyreduce;
+    }
+
+  if (yyn == YYFINAL)
+    YYACCEPT;
+
+  /* Shift the lookahead token.  */
+  YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
+
+  /* Discard the token being shifted unless it is eof.  */
+  if (yychar != YYEOF)
+    yychar = YYEMPTY;
+
+  *++yyvsp = yylval;
+
+
+  /* Count tokens shifted since error; after three, turn off error
+     status.  */
+  if (yyerrstatus)
+    yyerrstatus--;
+
+  yystate = yyn;
+  goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state.  |
+`-----------------------------------------------------------*/
+yydefault:
+  yyn = yydefact[yystate];
+  if (yyn == 0)
+    goto yyerrlab;
+  goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction.  |
+`-----------------------------*/
+yyreduce:
+  /* yyn is the number of a rule to reduce with.  */
+  yylen = yyr2[yyn];
+
+  /* If YYLEN is nonzero, implement the default value of the action:
+     `$$ = $1'.
+
+     Otherwise, the following line sets YYVAL to garbage.
+     This behavior is undocumented and Bison
+     users should not rely upon it.  Assigning to YYVAL
+     unconditionally makes the parser a bit smaller, and it avoids a
+     GCC warning that YYVAL may be used uninitialized.  */
+  yyval = yyvsp[1-yylen];
+
+
+  YY_REDUCE_PRINT (yyn);
+  switch (yyn)
+    {
+        case 2:
+#line 106 "zparse.y"
+    {zserver_list=yyvsp[0].cfg;}
+    break;
+
+  case 3:
+#line 107 "zparse.y"
+    {zserver_list=NULL;}
+    break;
+
+  case 4:
+#line 110 "zparse.y"
+    {;}
+    break;
+
+  case 5:
+#line 111 "zparse.y"
+    {fprintf(errfile,"No version - not GSDL config file?\n");return(1);}
+    break;
+
+  case 6:
+#line 113 "zparse.y"
+    {if (yyvsp[0].cfg!=NULL) {yyvsp[0].cfg->next=yyvsp[-1].cfg;yyval.cfg=yyvsp[0].cfg;}}
+    break;
+
+  case 8:
+#line 117 "zparse.y"
+    {
+		     if (YYRECOVERING)
+		       {yyval.cfg=NULL;YYRECOVERING=0;} 
+		     else {
+		       if((yyval.cfg=malloc(sizeof(struct z3950cfg)))==NULL)
+			 {
+			   fprintf(errfile,"malloc failed\n");
+			   return(1);
+			 }
+		       yyval.cfg->shortname=yyvsp[-7].string;
+		       yyval.cfg->hostname=yyvsp[-6].string;
+		       yyval.cfg->port=yyvsp[-5].number;
+		       yyval.cfg->dbname=yyvsp[-4].string;
+		       yyval.cfg->longname=yyvsp[-3].string;
+		       yyval.cfg->icon=yyvsp[-2].string;
+		       yyval.cfg->smallicon=yyvsp[-1].string;
+		       yyval.cfg->about=yyvsp[0].about;
+		       yyval.cfg->next=NULL;
+		     }
+		   }
+    break;
+
+  case 9:
+#line 137 "zparse.y"
+    {yyval.cfg=NULL;
+	      fprintf(errfile,"discarding zserver (line %d)\n",lineno);}
+    break;
+
+  case 10:
+#line 141 "zparse.y"
+    {;}
+    break;
+
+  case 11:
+#line 142 "zparse.y"
+    {errormsg("Database name needs to be followed by a short "
+			  "descriptive name (enclosed in \" marks)");
+	         yyval.string=NULL;
+	         YYRECOVERING=1;}
+    break;
+
+  case 12:
+#line 147 "zparse.y"
+    {yyval.number=atoi(yyvsp[0].string);}
+    break;
+
+  case 13:
+#line 148 "zparse.y"
+    {yyval.number=210;}
+    break;
+
+  case 14:
+#line 151 "zparse.y"
+    {yyval.string=yyvsp[0].string;}
+    break;
+
+  case 15:
+#line 152 "zparse.y"
+    {yyval.string=yyvsp[0].string;
+                  errormsg("Icon must be enclosed in quotes");
+	      yylex();yylex();}
+    break;
+
+  case 16:
+#line 155 "zparse.y"
+    {yyval.string=NULL;}
+    break;
+
+  case 17:
+#line 156 "zparse.y"
+    {yyval.string=yyvsp[0].string;}
+    break;
+
+  case 18:
+#line 157 "zparse.y"
+    {yyval.string=yyvsp[0].string;
+	      /* this is because of the ':' */
+              errormsg("Smallicon must be enclosed in quotes.\n");
+	      yylex();yylex();
+	      }
+    break;
+
+  case 19:
+#line 162 "zparse.y"
+    {yyval.string=NULL;}
+    break;
+
+  case 20:
+#line 164 "zparse.y"
+    {defLanguage=0;}
+    break;
+
+  case 21:
+#line 165 "zparse.y"
+    {yyval.about=NULL;}
+    break;
+
+  case 22:
+#line 167 "zparse.y"
+    {;}
+    break;
+
+  case 23:
+#line 169 "zparse.y"
+    {yyval.about=yyvsp[0].about;yyvsp[0].about->next=yyvsp[-1].about;}
+    break;
+
+  case 24:
+#line 173 "zparse.y"
+    {
+			       if((yyval.about=malloc(sizeof(struct z3950aboutlist)))
+				  ==NULL) {
+				 fprintf(errfile,"Malloc failed\n");
+				 return(1);
+			       }
+			       yyval.about->lang=yyvsp[-1].string;
+			       yyval.about->text=yyvsp[0].string;
+			       yyval.about->next=NULL;
+			     }
+    break;
+
+  case 25:
+#line 184 "zparse.y"
+    {
+			       if (defLanguage)
+		                 {
+				   fprintf(errfile,"warning: (line %d): already have a default language in config file\n",lineno);
+				 }
+			       else defLanguage=1;
+			       
+			       if((yyval.about=malloc(sizeof(struct z3950aboutlist)))
+				  ==NULL) {
+				 fprintf(errfile,"Malloc failed\n");
+				 return(1);
+			       }
+			       yyval.about->lang=NULL; /* default lang... */
+			       yyval.about->text=yyvsp[0].string;
+			       yyval.about->next=NULL;
+			     }
+    break;
+
+  case 26:
+#line 206 "zparse.y"
+    {
+			       yyval.string=malloc(strlen(yyvsp[-2].string)+strlen(yyvsp[0].string)+1);
+			       strncpy(yyval.string,yyvsp[-2].string,strlen(yyvsp[-2].string));
+			       yyval.string[strlen(yyvsp[-2].string)]='_';
+			       strncpy(yyval.string+strlen(yyvsp[-2].string)+1,yyvsp[0].string,strlen(yyvsp[0].string));
+			       free(yyvsp[-2].string);free(yyvsp[0].string);
+			     }
+    break;
+
+  case 27:
+#line 213 "zparse.y"
+    {;}
+    break;
+
+  case 28:
+#line 221 "zparse.y"
+    {errormsg("missing language");}
+    break;
+
+
+    }
+
+/* Line 999 of yacc.c.  */
+#line 1309 "zparse.tab.c"
+
+
+  yyvsp -= yylen;
+  yyssp -= yylen;
+
+
+  YY_STACK_PRINT (yyss, yyssp);
+
+  *++yyvsp = yyval;
+
+
+  /* Now `shift' the result of the reduction.  Determine what state
+     that goes to, based on the state we popped back to and the rule
+     number reduced by.  */
+
+  yyn = yyr1[yyn];
+
+  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+    yystate = yytable[yystate];
+  else
+    yystate = yydefgoto[yyn - YYNTOKENS];
+
+  goto yynewstate;
+
+
+/*------------------------------------.
+| yyerrlab -- here on detecting error |
+`------------------------------------*/
+yyerrlab:
+  /* If not already recovering from an error, report this error.  */
+  if (!yyerrstatus)
+    {
+      ++yynerrs;
+#if YYERROR_VERBOSE
+      yyn = yypact[yystate];
+
+      if (YYPACT_NINF < yyn && yyn < YYLAST)
+	{
+	  YYSIZE_T yysize = 0;
+	  int yytype = YYTRANSLATE (yychar);
+	  char *yymsg;
+	  int yyx, yycount;
+
+	  yycount = 0;
+	  /* Start YYX at -YYN if negative to avoid negative indexes in
+	     YYCHECK.  */
+	  for (yyx = yyn < 0 ? -yyn : 0;
+	       yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
+	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+	      yysize += yystrlen (yytname[yyx]) + 15, yycount++;
+	  yysize += yystrlen ("syntax error, unexpected ") + 1;
+	  yysize += yystrlen (yytname[yytype]);
+	  yymsg = (char *) YYSTACK_ALLOC (yysize);
+	  if (yymsg != 0)
+	    {
+	      char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
+	      yyp = yystpcpy (yyp, yytname[yytype]);
+
+	      if (yycount < 5)
+		{
+		  yycount = 0;
+		  for (yyx = yyn < 0 ? -yyn : 0;
+		       yyx < (int) (sizeof (yytname) / sizeof (char *));
+		       yyx++)
+		    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
+		      {
+			const char *yyq = ! yycount ? ", expecting " : " or ";
+			yyp = yystpcpy (yyp, yyq);
+			yyp = yystpcpy (yyp, yytname[yyx]);
+			yycount++;
+		      }
+		}
+	      yyerror (yymsg);
+	      YYSTACK_FREE (yymsg);
+	    }
+	  else
+	    yyerror ("syntax error; also virtual memory exhausted");
+	}
+      else
+#endif /* YYERROR_VERBOSE */
+	yyerror ("syntax error");
+    }
+
+
+
+  if (yyerrstatus == 3)
+    {
+      /* If just tried and failed to reuse lookahead token after an
+	 error, discard it.  */
+
+      /* Return failure if at end of input.  */
+      if (yychar == YYEOF)
+        {
+	  /* Pop the error token.  */
+          YYPOPSTACK;
+	  /* Pop the rest of the stack.  */
+	  while (yyss < yyssp)
+	    {
+	      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
+	      yydestruct (yystos[*yyssp], yyvsp);
+	      YYPOPSTACK;
+	    }
+	  YYABORT;
+        }
+
+      YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
+      yydestruct (yytoken, &yylval);
+      yychar = YYEMPTY;
+
+    }
+
+  /* Else will try to reuse lookahead token after shifting the error
+     token.  */
+  goto yyerrlab1;
+
+
+/*----------------------------------------------------.
+| yyerrlab1 -- error raised explicitly by an action.  |
+`----------------------------------------------------*/
+yyerrlab1:
+  yyerrstatus = 3;	/* Each real token shifted decrements this.  */
+
+  for (;;)
+    {
+      yyn = yypact[yystate];
+      if (yyn != YYPACT_NINF)
+	{
+	  yyn += YYTERROR;
+	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+	    {
+	      yyn = yytable[yyn];
+	      if (0 < yyn)
+		break;
+	    }
+	}
+
+      /* Pop the current state because it cannot handle the error token.  */
+      if (yyssp == yyss)
+	YYABORT;
+
+      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
+      yydestruct (yystos[yystate], yyvsp);
+      yyvsp--;
+      yystate = *--yyssp;
+
+      YY_STACK_PRINT (yyss, yyssp);
+    }
+
+  if (yyn == YYFINAL)
+    YYACCEPT;
+
+  YYDPRINTF ((stderr, "Shifting error token, "));
+
+  *++yyvsp = yylval;
+
+
+  yystate = yyn;
+  goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here.  |
+`-------------------------------------*/
+yyacceptlab:
+  yyresult = 0;
+  goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here.  |
+`-----------------------------------*/
+yyabortlab:
+  yyresult = 1;
+  goto yyreturn;
+
+#ifndef yyoverflow
+/*----------------------------------------------.
+| yyoverflowlab -- parser overflow comes here.  |
+`----------------------------------------------*/
+yyoverflowlab:
+  yyerror ("parser stack overflow");
+  yyresult = 2;
+  /* Fall through.  */
+#endif
+
+yyreturn:
+#ifndef yyoverflow
+  if (yyss != yyssa)
+    YYSTACK_FREE (yyss);
+#endif
+  return yyresult;
+}
+
+
+#line 106 "zparse.y"
+
+/*int strncasecmp (const char *, const char *,size_t);*/
+int yyerror(char *string) {
+  fprintf(errfile,"Parse error (line %d) near \n\"%s\"<---:%s\n",lineno,
+	  yylval.string,string);
+  return(1);
+}
+
+void errormsg(char *str) {
+  fprintf(errfile,"Err (line %d, near \"%s\"): %s.\n",lineno,
+	  yylval.string,str);
+}
+
+/* *
+int main (int argc, char *argv[]) {
+  if (argc==2)
+    if (argv[1][0]=='-'&&argv[1][1]=='d')
+      yydebug=1;
+
+  yyparse();
+  return(0);
+}
+* */
+
Index: /gsdl/trunk/runtime-src/src/z3950/zparse.tab.h
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/zparse.tab.h	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/zparse.tab.h	(revision 16571)
@@ -0,0 +1,134 @@
+/* A Bison parser, made by GNU Bison 1.875.  */
+
+/* Skeleton parser for Yacc-like parsing with Bison,
+   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+/* As a special exception, when this file is copied by Bison into a
+   Bison output file, you may use that output file without restriction.
+   This special exception was added by the Free Software Foundation
+   in version 1.24 of Bison.  */
+
+/* Tokens.  */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+   /* Put the tokens into the symbol table, so that GDB and other debuggers
+      know about them.  */
+   enum yytokentype {
+     GSDLVERSION = 257,
+     GENERAL_SECTION = 258,
+     SEARCH_SECTION = 259,
+     BROWSE_SECTION = 260,
+     MACROS_SECTION = 261,
+     MAINTAINER = 262,
+     PUBLIC = 263,
+     TRUE = 264,
+     FALSE = 265,
+     LANGUAGES = 266,
+     EN = 267,
+     FR = 268,
+     MI = 269,
+     ZH = 270,
+     DE = 271,
+     NAME = 272,
+     STRING = 273,
+     ICON = 274,
+     SMALLICON = 275,
+     ABOUT = 276,
+     SEARCHTEXT = 277,
+     DOCUMENT = 278,
+     SECTION = 279,
+     BROWSE = 280,
+     TYPE = 281,
+     FORMAT = 282,
+     LIST = 283,
+     SORTEDLIST = 284,
+     SECTIONLIST = 285,
+     SORTEDSECTIONLIST = 286,
+     DATELIST = 287,
+     ICONLINK = 288,
+     TEXTLINK = 289,
+     DOCUMENTIMAGES = 290,
+     DOCUMENTHEADER = 291,
+     DOCUMENTTEXT = 292,
+     DOCUMENTBUTTONS = 293,
+     DOCUMENTARROWSBOTTOM = 294,
+     DATA = 295
+   };
+#endif
+#define GSDLVERSION 257
+#define GENERAL_SECTION 258
+#define SEARCH_SECTION 259
+#define BROWSE_SECTION 260
+#define MACROS_SECTION 261
+#define MAINTAINER 262
+#define PUBLIC 263
+#define TRUE 264
+#define FALSE 265
+#define LANGUAGES 266
+#define EN 267
+#define FR 268
+#define MI 269
+#define ZH 270
+#define DE 271
+#define NAME 272
+#define STRING 273
+#define ICON 274
+#define SMALLICON 275
+#define ABOUT 276
+#define SEARCHTEXT 277
+#define DOCUMENT 278
+#define SECTION 279
+#define BROWSE 280
+#define TYPE 281
+#define FORMAT 282
+#define LIST 283
+#define SORTEDLIST 284
+#define SECTIONLIST 285
+#define SORTEDSECTIONLIST 286
+#define DATELIST 287
+#define ICONLINK 288
+#define TEXTLINK 289
+#define DOCUMENTIMAGES 290
+#define DOCUMENTHEADER 291
+#define DOCUMENTTEXT 292
+#define DOCUMENTBUTTONS 293
+#define DOCUMENTARROWSBOTTOM 294
+#define DATA 295
+
+
+
+
+#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
+#line 61 "zparse.y"
+typedef union YYSTYPE {
+  char *string;
+  struct z3950cfg *cfg;
+  struct z3950aboutlist *about;
+  int number;
+} YYSTYPE;
+/* Line 1240 of yacc.c.  */
+#line 125 "zparse.tab.h"
+# define yystype YYSTYPE /* obsolescent; will be withdrawn */
+# define YYSTYPE_IS_DECLARED 1
+# define YYSTYPE_IS_TRIVIAL 1
+#endif
+
+extern YYSTYPE yylval;
+
+
+
Index: /gsdl/trunk/runtime-src/src/z3950/zparse.y
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/zparse.y	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/zparse.y	(revision 16571)
@@ -0,0 +1,252 @@
+/* RUN-TIME CONFIGURATION FILE PARSER */
+/**********************************************************************
+ *
+ * zparse.y --
+ * Copyright (C) 2000  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+%{
+  /* verbatim C code - functions, etc */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include "z3950cfg.h" /* structure types, and #define of yyin/yyparse */
+
+#define YYDEBUG 1
+#define YYERROR_VERBOSE 1
+char defLanguage=0;
+
+/* defined in parse.fl */
+extern int lineno;
+
+#ifndef YYRECOVERING
+int YYRECOVERING=0; /* this is supposed to already be defined as a macro */
+#endif
+
+/* defined in z3950proto.cpp */
+struct z3950cfg *zserver_list=NULL;
+
+/* this is set in z3950proto.cpp */
+FILE *errfile;
+
+int yylex(void);
+
+int yyerror(char *string);
+
+void errormsg(char *str);
+
+%}
+
+
+%union {
+  char *string;
+  struct z3950cfg *cfg;
+  struct z3950aboutlist *about;
+  int number;
+}
+
+
+/* keywords */
+/***** NOTE: can explicitly give values for each token, AND
+give a string for the token name eg 
+%token GSDLVERSION 257  "Version"
+*******/
+%token GSDLVERSION 257
+%token GENERAL_SECTION 258 SEARCH_SECTION 259 
+%token BROWSE_SECTION 260 MACROS_SECTION 261
+%token MAINTAINER 262
+%token PUBLIC 263
+%token TRUE 264 FALSE 265
+%token LANGUAGES 266 EN 267 FR 268 MI 269 ZH 270 DE 271
+%token NAME 272
+%token <string> STRING 273
+%token ICON 274 SMALLICON 275
+%token ABOUT 276
+%token SEARCHTEXT 277
+%token DOCUMENT 278 SECTION 279
+%token BROWSE 280 TYPE 281 FORMAT 282
+/* classifiers */
+%token  LIST 283 SORTEDLIST 284 SECTIONLIST 285 SORTEDSECTIONLIST 286 
+%token DATELIST 287
+/* formats */
+%token  ICONLINK 288 TEXTLINK 289
+/* layouts */
+%token  DOCUMENTIMAGES 290 DOCUMENTHEADER 291 DOCUMENTTEXT 292
+%token  DOCUMENTBUTTONS 293 DOCUMENTARROWSBOTTOM 294
+
+/* all other text */
+%token <string> DATA 295
+
+%type <cfg>      zserver zserverlist
+%type <number>  port
+%type <string>   icon smallicon lang name
+%type <about>    about aboutLang aboutList
+%%
+/* grammar */
+z3950         : version zserverlist {zserver_list=$2;}
+              | version {zserver_list=NULL;} /* if all commented out or none... */
+
+
+version       : GSDLVERSION {;}
+              | {fprintf(errfile,"No version - not GSDL config file?\n");return(1);}
+
+zserverlist   : zserverlist zserver {if ($2!=NULL) {$2->next=$1;$$=$2;}}
+              | zserver ;
+
+zserver       : DATA DATA port DATA name icon smallicon about 
+                   {
+		     if (YYRECOVERING)
+		       {$$=NULL;YYRECOVERING=0;} 
+		     else {
+		       if(($$=malloc(sizeof(struct z3950cfg)))==NULL)
+			 {
+			   fprintf(errfile,"malloc failed\n");
+			   return(1);
+			 }
+		       $$->shortname=$1;
+		       $$->hostname=$2;
+		       $$->port=$3;
+		       $$->dbname=$4;
+		       $$->longname=$5;
+		       $$->icon=$6;
+		       $$->smallicon=$7;
+		       $$->about=$8;
+		       $$->next=NULL;
+		     }
+		   }
+              | error {$$=NULL;
+	      fprintf(errfile,"discarding zserver (line %d)\n",lineno);}
+              ;
+
+name          : STRING {;}
+              | {errormsg("Database name needs to be followed by a short "
+			  "descriptive name (enclosed in \" marks)");
+	         $$=NULL;
+	         YYRECOVERING=1;} /* we should scrap this server */
+
+port          : ':' DATA {$$=atoi($2);}
+              | {$$=210;} /* default z39.50 server port */
+              ;
+
+icon          : ICON STRING {$$=$2;}
+              | ICON DATA {$$=$2;
+                  errormsg("Icon must be enclosed in quotes");
+	      yylex();yylex();}
+              | {$$=NULL;}
+smallicon     : SMALLICON STRING {$$=$2;}
+              | SMALLICON DATA {$$=$2;
+	      /* this is because of the ':' */
+              errormsg("Smallicon must be enclosed in quotes.\n");
+	      yylex();yylex();
+	      }
+              | {$$=NULL;}
+
+about         : aboutList {defLanguage=0;}
+              | {$$=NULL;}
+
+aboutList     : aboutLang {;}
+                      /* note this action reverses the order of the list */
+              | aboutList aboutLang {$$=$2;$2->next=$1;} 
+
+
+aboutLang     : ABOUT lang STRING 
+                             {
+			       if(($$=malloc(sizeof(struct z3950aboutlist)))
+				  ==NULL) {
+				 fprintf(errfile,"Malloc failed\n");
+				 return(1);
+			       }
+			       $$->lang=$2;
+			       $$->text=$3;
+			       $$->next=NULL;
+			     }
+              | ABOUT STRING 
+                             {
+			       if (defLanguage)
+		                 {
+				   fprintf(errfile,"warning: (line %d): already have a default language in config file\n",lineno);
+				 }
+			       else defLanguage=1;
+			       
+			       if(($$=malloc(sizeof(struct z3950aboutlist)))
+				  ==NULL) {
+				 fprintf(errfile,"Malloc failed\n");
+				 return(1);
+			       }
+			       $$->lang=NULL; /* default lang... */
+			       $$->text=$2;
+			       $$->next=NULL;
+			     }
+/* this can only happen once (default lang) */
+
+
+/* languages should be done using a lookup, rather than hard-coding 
+   them as tokens. Also '_' token for en_BR */
+lang          : DATA '_' DATA 
+                             {
+			       $$=malloc(strlen($1)+strlen($3)+1);
+			       strncpy($$,$1,strlen($1));
+			       $$[strlen($1)]='_';
+			       strncpy($$+strlen($1)+1,$3,strlen($3));
+			       free($1);free($3);
+			     }
+              | DATA {;}
+/*lang '_' DATA {;} */
+/*              | EN {;}
+		| FR {;}
+		| MI {;}
+		| ZH {;}
+		| DE {;}
+		| DATA {errormsg("unknown language");}*/
+              | error {errormsg("missing language");}
+
+/*documentHeader : DOCUMENTHEADER STRING {;}
+              | {;}
+
+documentText  : DOCUMENTTEXT STRING {;}
+              | {;}
+*/
+
+%%
+/*int strncasecmp (const char *, const char *,size_t);*/
+int yyerror(char *string) {
+  fprintf(errfile,"Parse error (line %d) near \n\"%s\"<---:%s\n",lineno,
+	  yylval.string,string);
+  return(1);
+}
+
+void errormsg(char *str) {
+  fprintf(errfile,"Err (line %d, near \"%s\"): %s.\n",lineno,
+	  yylval.string,str);
+}
+
+/* *
+int main (int argc, char *argv[]) {
+  if (argc==2)
+    if (argv[1][0]=='-'&&argv[1][1]=='d')
+      yydebug=1;
+
+  yyparse();
+  return(0);
+}
+* */
Index: /gsdl/trunk/runtime-src/src/z3950/zparse.yy.c
===================================================================
--- /gsdl/trunk/runtime-src/src/z3950/zparse.yy.c	(revision 16571)
+++ /gsdl/trunk/runtime-src/src/z3950/zparse.yy.c	(revision 16571)
@@ -0,0 +1,1969 @@
+#define yy_create_buffer zconfig_create_buffer
+#define yy_delete_buffer zconfig_delete_buffer
+#define yy_scan_buffer zconfig_scan_buffer
+#define yy_scan_string zconfig_scan_string
+#define yy_scan_bytes zconfig_scan_bytes
+#define yy_flex_debug zconfig_flex_debug
+#define yy_init_buffer zconfig_init_buffer
+#define yy_flush_buffer zconfig_flush_buffer
+#define yy_load_buffer_state zconfig_load_buffer_state
+#define yy_switch_to_buffer zconfig_switch_to_buffer
+#define yyin zconfigin
+#define yyleng zconfigleng
+#define yylex zconfiglex
+#define yyout zconfigout
+#define yyrestart zconfigrestart
+#define yytext zconfigtext
+
+#line 19 "zparse.yy.c"
+/* A lexical scanner generated by flex */
+
+/* Scanner skeleton version:
+ * $Header$
+ */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+
+#include <stdio.h>
+
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
+#ifdef c_plusplus
+#ifndef __cplusplus
+#define __cplusplus
+#endif
+#endif
+
+
+#ifdef __cplusplus
+
+#include <stdlib.h>
+
+/* Use prototypes in function declarations. */
+#define YY_USE_PROTOS
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else	/* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_PROTOS
+#define YY_USE_CONST
+
+#endif	/* __STDC__ */
+#endif	/* ! __cplusplus */
+
+#ifdef __TURBOC__
+ #pragma warn -rch
+ #pragma warn -use
+#include <io.h>
+#include <stdlib.h>
+#define YY_USE_CONST
+#define YY_USE_PROTOS
+#endif
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+
+#ifdef YY_USE_PROTOS
+#define YY_PROTO(proto) proto
+#else
+#define YY_PROTO(proto) ()
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index.  If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* Enter a start condition.  This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state.  The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#define YY_BUF_SIZE 16384
+
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+
+extern int yyleng;
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+/* The funky do-while in the following #define is used to turn the definition
+ * int a single C statement (which needs a semi-colon terminator).  This
+ * avoids problems with code like:
+ *
+ * 	if ( condition_holds )
+ *		yyless( 5 );
+ *	else
+ *		do_something_else();
+ *
+ * Prior to using the do-while the compiler would get upset at the
+ * "else" because it interpreted the "if" statement as being all
+ * done when it reached the ';' after the yyless() call.
+ */
+
+/* Return all but the first 'n' matched characters back to the input stream. */
+
+#define yyless(n) \
+	do \
+		{ \
+		/* Undo effects of setting up yytext. */ \
+		*yy_cp = yy_hold_char; \
+		YY_RESTORE_YY_MORE_OFFSET \
+		yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
+		YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+		} \
+	while ( 0 )
+
+#define unput(c) yyunput( c, yytext_ptr )
+
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+typedef unsigned int yy_size_t;
+
+
+struct yy_buffer_state
+	{
+	FILE *yy_input_file;
+
+	char *yy_ch_buf;		/* input buffer */
+	char *yy_buf_pos;		/* current position in input buffer */
+
+	/* Size of input buffer in bytes, not including room for EOB
+	 * characters.
+	 */
+	yy_size_t yy_buf_size;
+
+	/* Number of characters read into yy_ch_buf, not including EOB
+	 * characters.
+	 */
+	int yy_n_chars;
+
+	/* Whether we "own" the buffer - i.e., we know we created it,
+	 * and can realloc() it to grow it, and should free() it to
+	 * delete it.
+	 */
+	int yy_is_our_buffer;
+
+	/* Whether this is an "interactive" input source; if so, and
+	 * if we're using stdio for input, then we want to use getc()
+	 * instead of fread(), to make sure we stop fetching input after
+	 * each newline.
+	 */
+	int yy_is_interactive;
+
+	/* Whether we're considered to be at the beginning of a line.
+	 * If so, '^' rules will be active on the next match, otherwise
+	 * not.
+	 */
+	int yy_at_bol;
+
+	/* Whether to try to fill the input buffer when we reach the
+	 * end of it.
+	 */
+	int yy_fill_buffer;
+
+	int yy_buffer_status;
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+	/* When an EOF's been seen but there's still some text to process
+	 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+	 * shouldn't try reading from the input source any more.  We might
+	 * still have a bunch of tokens to match, though, because of
+	 * possible backing-up.
+	 *
+	 * When we actually see the EOF, we change the status to "new"
+	 * (via yyrestart()), so that the user can continue scanning by
+	 * just pointing yyin at a new input file.
+	 */
+#define YY_BUFFER_EOF_PENDING 2
+	};
+
+static YY_BUFFER_STATE yy_current_buffer = 0;
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ */
+#define YY_CURRENT_BUFFER yy_current_buffer
+
+
+/* yy_hold_char holds the character lost when yytext is formed. */
+static char yy_hold_char;
+
+static int yy_n_chars;		/* number of characters read into yy_ch_buf */
+
+
+int yyleng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 1;		/* whether we need to initialize */
+static int yy_start = 0;	/* start state number */
+
+/* Flag which is used to allow yywrap()'s to do buffer switches
+ * instead of setting up a fresh yyin.  A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart YY_PROTO(( FILE *input_file ));
+
+void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
+void yy_load_buffer_state YY_PROTO(( void ));
+YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
+void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
+void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b ));
+#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
+
+YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size ));
+YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str ));
+YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len ));
+
+static void *yy_flex_alloc YY_PROTO(( yy_size_t ));
+static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t ));
+static void yy_flex_free YY_PROTO(( void * ));
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+	{ \
+	if ( ! yy_current_buffer ) \
+		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+	yy_current_buffer->yy_is_interactive = is_interactive; \
+	}
+
+#define yy_set_bol(at_bol) \
+	{ \
+	if ( ! yy_current_buffer ) \
+		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+	yy_current_buffer->yy_at_bol = at_bol; \
+	}
+
+#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
+
+
+#define yywrap() 1
+#define YY_SKIP_YYWRAP
+typedef unsigned char YY_CHAR;
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
+typedef int yy_state_type;
+extern char *yytext;
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state YY_PROTO(( void ));
+static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
+static int yy_get_next_buffer YY_PROTO(( void ));
+static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+	yytext_ptr = yy_bp; \
+	yyleng = (int) (yy_cp - yy_bp); \
+	yy_hold_char = *yy_cp; \
+	*yy_cp = '\0'; \
+	yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 46
+#define YY_END_OF_BUFFER 47
+static yyconst short int yy_accept[274] =
+    {   0,
+        0,    0,   38,   38,   47,   46,   44,   45,   37,   46,
+        2,   43,    3,   43,   43,   43,   43,   43,   43,   43,
+       43,   43,   46,    4,   43,   43,   43,   43,   43,   43,
+       43,   43,   38,   39,   42,   46,    0,    1,    1,   43,
+       43,   43,   43,   43,   43,   43,   43,   43,   43,   43,
+       43,   43,   43,   43,    0,    0,    0,    0,   43,   43,
+       43,   43,   43,   43,   43,   38,   39,    0,   41,   40,
+       43,   43,   43,   43,   43,   43,   43,   43,   43,   43,
+       43,   43,   43,   43,   43,    0,    0,    0,    0,    0,
+       43,   43,   43,   43,   43,   43,   43,   43,   43,   43,
+
+       43,   43,   35,   43,   21,   23,   43,   43,   43,   43,
+       43,   29,    0,    0,    0,    0,    0,   43,   35,   43,
+       43,   31,   43,   43,   12,   43,   43,   43,   43,   43,
+       43,   43,   43,   43,   43,   43,    0,    0,    0,    0,
+        0,   32,   43,   43,   43,   43,   13,   43,   43,   22,
+       43,   43,   43,   43,   43,   43,   43,    0,    0,    0,
+        0,    0,   43,   30,   43,   43,   43,   43,   43,   43,
+       43,   43,   43,   43,   43,   43,    0,    0,    0,    0,
+        0,   43,   43,   34,   14,   43,   20,   43,   43,   43,
+       43,   43,   43,   28,    0,    0,    0,    9,    0,   43,
+
+       33,   43,   43,   43,   43,   43,   11,   43,   43,   36,
+       43,   43,    0,    5,    6,    0,   43,   43,   43,   43,
+       43,   43,   24,   43,   26,   43,    0,    0,   10,   43,
+       43,   43,   43,   43,   25,   43,    0,    0,   43,   43,
+       43,   43,   19,   43,    0,    0,   43,   43,   43,   43,
+       43,    0,    0,   43,   43,   17,   18,   43,    0,    0,
+       43,   16,   43,    8,    7,   43,   43,   43,   27,   43,
+       43,   15,    0
+    } ;
+
+static yyconst int yy_ec[256] =
+    {   0,
+        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
+        1,    1,    4,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    5,    1,    6,    7,    1,    1,    1,    1,    1,
+        1,    1,    1,    8,    9,   10,    1,   11,   11,   11,
+       11,   11,   11,   11,   11,   11,   11,   12,    1,    1,
+        1,    1,    1,    9,   13,   14,    9,   15,    9,   16,
+       17,   18,   19,    9,    9,   20,   21,   22,    9,    9,
+        9,    9,   23,   24,    9,    9,    9,    9,    9,    9,
+       25,   26,   27,    1,   28,    1,   29,   30,   31,   32,
+
+       33,   34,   35,   36,   37,    9,   38,   39,   40,   41,
+       42,   43,    9,   44,   45,   46,   47,    9,   48,   49,
+       50,    9,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1
+    } ;
+
+static yyconst int yy_meta[51] =
+    {   0,
+        1,    1,    1,    1,    1,    2,    1,    1,    3,    3,
+        3,    1,    3,    3,    3,    3,    3,    3,    3,    3,
+        3,    3,    3,    3,    1,    2,    1,    1,    3,    3,
+        3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
+        3,    3,    3,    3,    3,    3,    3,    3,    3,    3
+    } ;
+
+static yyconst short int yy_base[279] =
+    {   0,
+        0,   19,   49,   50,  331,  332,  332,  332,  332,   54,
+      332,    0,  332,  300,  285,   25,  286,  296,   31,  297,
+       29,   28,   49,  332,  296,  293,  294,  275,  281,  276,
+      277,   40,  315,  314,  310,  309,   78,  332,   80,    0,
+      272,  271,  266,  280,  266,  267,  267,  262,  266,   48,
+      276,  260,  254,  259,  257,   62,  271,  266,  259,  255,
+      259,  265,  247,  262,  261,  288,  287,  286,  332,  332,
+      241,  239,  253,  238,  244,  242,  247,  235,  247,  235,
+      232,  238,  230,  229,  241,  231,  257,  230,  239,  240,
+      223,  226,  225,  226,  231,  216,  216,  215,  215,   54,
+
+      219,  229,   66,  210,    0,    0,  225,  218,  215,  220,
+       67,    0,  204,  231,  217,  205,  204,  214,    0,  200,
+      208,    0,  204,  206,    0,  209,  204,  207,  193,  201,
+      208,  200,  193,   70,  202,  196,  187,  220,  186,  187,
+      197,    0,  198,  195,  192,  182,    0,  178,  181,    0,
+      180,  185,   64,  178,  187,   74,  176,  183,   80,  186,
+      169,  177,  175,    0,  170,  169,  163,  162,  169,  173,
+      172,   72,  162,  166,  169,  163,  195,  188,  159,  170,
+      191,  154,  148,    0,    0,  107,    0,  148,  143,  154,
+      149,  144,  157,    0,   80,   88,  160,  332,   82,  153,
+
+        0,  141,  137,  150,  142,  148,    0,  134,  134,    0,
+      132,  131,  139,  332,  332,  138,  130,  129,  126,  142,
+      141,  120,    0,  122,    0,  130,  133,  131,    0,  119,
+      106,  119,  115,  103,    0,  106,  108,  107,   97,  100,
+      108,  107,    0,   98,  106,  103,   89,   92,   88,   85,
+       83,   84,   83,   87,   82,    0,    0,   87,   96,   91,
+       70,    0,   64,  332,  332,   62,   58,   56,    0,   58,
+       25,    0,  332,  153,  156,   56,  159,  162
+    } ;
+
+static yyconst short int yy_def[279] =
+    {   0,
+      273,    1,  274,  274,  273,  273,  273,  273,  273,  275,
+      273,  276,  273,  276,  276,  276,  276,  276,  276,  276,
+      276,  276,  273,  273,  276,  276,  276,  276,  276,  276,
+      276,  276,  277,  278,  273,  273,  275,  273,  275,  276,
+      276,  276,  276,  276,  276,  276,  276,  276,  276,  276,
+      276,  276,  276,  276,  273,  273,  273,  273,  276,  276,
+      276,  276,  276,  276,  276,  277,  278,  278,  273,  273,
+      276,  276,  276,  276,  276,  276,  276,  276,  276,  276,
+      276,  276,  276,  276,  276,  273,  273,  273,  273,  273,
+      276,  276,  276,  276,  276,  276,  276,  276,  276,  276,
+
+      276,  276,  276,  276,  276,  276,  276,  276,  276,  276,
+      276,  276,  273,  273,  273,  273,  273,  276,  276,  276,
+      276,  276,  276,  276,  276,  276,  276,  276,  276,  276,
+      276,  276,  276,  276,  276,  276,  273,  273,  273,  273,
+      273,  276,  276,  276,  276,  276,  276,  276,  276,  276,
+      276,  276,  276,  276,  276,  276,  276,  273,  273,  273,
+      273,  273,  276,  276,  276,  276,  276,  276,  276,  276,
+      276,  276,  276,  276,  276,  276,  273,  273,  273,  273,
+      273,  276,  276,  276,  276,  276,  276,  276,  276,  276,
+      276,  276,  276,  276,  273,  273,  273,  273,  273,  276,
+
+      276,  276,  276,  276,  276,  276,  276,  276,  276,  276,
+      276,  276,  273,  273,  273,  273,  276,  276,  276,  276,
+      276,  276,  276,  276,  276,  276,  273,  273,  276,  276,
+      276,  276,  276,  276,  276,  276,  273,  273,  276,  276,
+      276,  276,  276,  276,  273,  273,  276,  276,  276,  276,
+      276,  273,  273,  276,  276,  276,  276,  276,  273,  273,
+      276,  276,  276,  273,  273,  276,  276,  276,  276,  276,
+      276,  276,    0,  273,  273,  273,  273,  273
+    } ;
+
+static yyconst short int yy_nxt[383] =
+    {   0,
+        6,    7,    8,    8,    7,    9,   10,   11,   12,   12,
+       12,   13,   14,   15,   16,   17,   12,   12,   18,   19,
+       12,   20,   21,   22,   23,    6,    6,   24,   12,   12,
+       12,   12,   12,   25,   12,   12,   26,   12,   12,   27,
+       12,   12,   28,   12,   29,   30,   12,   12,   12,   12,
+       31,   34,   34,   43,   35,   35,   38,   39,   40,   47,
+       53,   50,   55,   32,  272,   56,   44,   48,   51,   57,
+       52,   58,   65,  127,   36,   36,   80,   54,   81,   51,
+       38,   39,   38,   39,   87,  130,  136,  171,  155,  178,
+      159,  190,  127,  174,   88,  213,  175,  216,  196,  271,
+
+      261,  270,  258,  269,  130,  136,  155,  268,  267,  171,
+      190,  266,  174,  213,  214,  216,  261,  265,  175,  202,
+      203,  258,  264,  263,  204,  205,  262,  260,  259,  257,
+      206,  256,  255,  254,  253,  202,  203,  252,  251,  250,
+      249,  248,  204,  205,  247,  246,  245,  244,  243,  242,
+      241,  240,  206,   33,   33,   33,   37,   37,   37,   66,
+      239,   66,   68,  238,   68,  237,  236,  235,  234,  233,
+      232,  231,  230,  229,  228,  227,  226,  225,  224,  223,
+      222,  221,  220,  219,  218,  217,  215,  212,  211,  210,
+      209,  208,  207,  201,  200,  199,  198,  197,  196,  195,
+
+      194,  193,  192,  191,  189,  188,  187,  186,  185,  184,
+      183,  182,  181,  180,  179,  177,  176,  173,  172,  170,
+      169,  168,  167,  166,  165,  164,  163,  162,  161,  160,
+      159,  158,  157,  156,  154,  153,  152,  151,  150,  149,
+      148,  147,  146,  145,  144,  143,  142,  141,  140,  139,
+      138,  137,  135,  134,  133,  132,  131,  129,  128,  126,
+      125,  124,  123,  122,  121,  120,  119,  118,  117,  116,
+      115,  114,  113,  112,  111,  110,  109,  108,  107,  106,
+      105,  104,  103,  102,  101,  100,   99,   98,   67,   67,
+       67,   97,   96,   95,   94,   93,   92,   91,   90,   89,
+
+       86,   85,   84,   83,   82,   79,   78,   77,   76,   75,
+       74,   73,   72,   71,   70,   69,   67,   67,   64,   63,
+       51,   62,   61,   60,   59,   49,   46,   45,   42,   41,
+      273,    5,  273,  273,  273,  273,  273,  273,  273,  273,
+      273,  273,  273,  273,  273,  273,  273,  273,  273,  273,
+      273,  273,  273,  273,  273,  273,  273,  273,  273,  273,
+      273,  273,  273,  273,  273,  273,  273,  273,  273,  273,
+      273,  273,  273,  273,  273,  273,  273,  273,  273,  273,
+      273,  273
+    } ;
+
+static yyconst short int yy_chk[383] =
+    {   0,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        2,    3,    4,   16,    3,    4,   10,   10,  276,   19,
+       22,   21,   23,    2,  271,   23,   16,   19,   21,   23,
+       21,   23,   32,  100,    3,    4,   50,   22,   50,   32,
+       37,   37,   39,   39,   56,  103,  111,  153,  134,  159,
+      159,  172,  100,  156,   56,  195,  156,  199,  196,  270,
+
+      254,  268,  251,  267,  103,  111,  134,  266,  263,  153,
+      172,  261,  156,  195,  196,  199,  254,  260,  156,  186,
+      186,  251,  259,  258,  186,  186,  255,  253,  252,  250,
+      186,  249,  248,  247,  246,  186,  186,  245,  244,  242,
+      241,  240,  186,  186,  239,  238,  237,  236,  234,  233,
+      232,  231,  186,  274,  274,  274,  275,  275,  275,  277,
+      230,  277,  278,  228,  278,  227,  226,  224,  222,  221,
+      220,  219,  218,  217,  216,  213,  212,  211,  209,  208,
+      206,  205,  204,  203,  202,  200,  197,  193,  192,  191,
+      190,  189,  188,  183,  182,  181,  180,  179,  178,  177,
+
+      176,  175,  174,  173,  171,  170,  169,  168,  167,  166,
+      165,  163,  162,  161,  160,  158,  157,  155,  154,  152,
+      151,  149,  148,  146,  145,  144,  143,  141,  140,  139,
+      138,  137,  136,  135,  133,  132,  131,  130,  129,  128,
+      127,  126,  124,  123,  121,  120,  118,  117,  116,  115,
+      114,  113,  110,  109,  108,  107,  104,  102,  101,   99,
+       98,   97,   96,   95,   94,   93,   92,   91,   90,   89,
+       88,   87,   86,   85,   84,   83,   82,   81,   80,   79,
+       78,   77,   76,   75,   74,   73,   72,   71,   68,   67,
+       66,   65,   64,   63,   62,   61,   60,   59,   58,   57,
+
+       55,   54,   53,   52,   51,   49,   48,   47,   46,   45,
+       44,   43,   42,   41,   36,   35,   34,   33,   31,   30,
+       29,   28,   27,   26,   25,   20,   18,   17,   15,   14,
+        5,  273,  273,  273,  273,  273,  273,  273,  273,  273,
+      273,  273,  273,  273,  273,  273,  273,  273,  273,  273,
+      273,  273,  273,  273,  273,  273,  273,  273,  273,  273,
+      273,  273,  273,  273,  273,  273,  273,  273,  273,  273,
+      273,  273,  273,  273,  273,  273,  273,  273,  273,  273,
+      273,  273
+    } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "zparse.fl"
+#define INITIAL 0
+/* This is the lexical analyser - it returns tokens to the parsers.
+   This is used by both parsers - one for the build-time config files
+   and one for the run-time config files. Note the included file "parse.h"
+   is a symlink to the relevant header file. */
+#line 7 "zparse.fl"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/*#define YYSTYPE char * - YYSTYPE is defined in zparse.tab.h */
+#include "zparse.tab.h"
+
+/* forward declarations for std functions not picked up. */
+/*int fileno(FILE *);*/
+/*char *strdup(char *);*/
+
+int lineno=1;
+#define STRINGCOND 1
+
+#line 576 "zparse.yy.c"
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap YY_PROTO(( void ));
+#else
+extern int yywrap YY_PROTO(( void ));
+#endif
+#endif
+
+#ifndef YY_NO_UNPUT
+static void yyunput YY_PROTO(( int c, char *buf_ptr ));
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen YY_PROTO(( yyconst char * ));
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+static int yyinput YY_PROTO(( void ));
+#else
+static int input YY_PROTO(( void ));
+#endif
+#endif
+
+#if YY_STACK_USED
+static int yy_start_stack_ptr = 0;
+static int yy_start_stack_depth = 0;
+static int *yy_start_stack = 0;
+#ifndef YY_NO_PUSH_STATE
+static void yy_push_state YY_PROTO(( int new_state ));
+#endif
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state YY_PROTO(( void ));
+#endif
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state YY_PROTO(( void ));
+#endif
+
+#else
+#define YY_NO_PUSH_STATE 1
+#define YY_NO_POP_STATE 1
+#define YY_NO_TOP_STATE 1
+#endif
+
+#ifdef YY_MALLOC_DECL
+YY_MALLOC_DECL
+#else
+#if __STDC__
+#ifndef __cplusplus
+#include <stdlib.h>
+#endif
+#else
+/* Just try to get by without declaring the routines.  This will fail
+ * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
+ * or sizeof(void*) != sizeof(int).
+ */
+#endif
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+	if ( yy_current_buffer->yy_is_interactive ) \
+		{ \
+		int c = '*', n; \
+		for ( n = 0; n < max_size && \
+			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+			buf[n] = (char) c; \
+		if ( c == '\n' ) \
+			buf[n++] = (char) c; \
+		if ( c == EOF && ferror( yyin ) ) \
+			YY_FATAL_ERROR( "input in flex scanner failed" ); \
+		result = n; \
+		} \
+	else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
+		  && ferror( yyin ) ) \
+		YY_FATAL_ERROR( "input in flex scanner failed" );
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL int yylex YY_PROTO(( void ))
+#endif
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+	if ( yyleng > 0 ) \
+		yy_current_buffer->yy_at_bol = \
+				(yytext[yyleng - 1] == '\n'); \
+	YY_USER_ACTION
+
+YY_DECL
+	{
+	register yy_state_type yy_current_state;
+	register char *yy_cp = NULL, *yy_bp = NULL;
+	register int yy_act;
+
+#line 26 "zparse.fl"
+
+	char *string;
+	int string_len;
+
+#line 735 "zparse.yy.c"
+
+	if ( yy_init )
+		{
+		yy_init = 0;
+
+#ifdef YY_USER_INIT
+		YY_USER_INIT;
+#endif
+
+		if ( ! yy_start )
+			yy_start = 1;	/* first start state */
+
+		if ( ! yyin )
+			yyin = stdin;
+
+		if ( ! yyout )
+			yyout = stdout;
+
+		if ( ! yy_current_buffer )
+			yy_current_buffer =
+				yy_create_buffer( yyin, YY_BUF_SIZE );
+
+		yy_load_buffer_state();
+		}
+
+	while ( 1 )		/* loops until end-of-file is reached */
+		{
+		yy_cp = yy_c_buf_p;
+
+		/* Support of yytext. */
+		*yy_cp = yy_hold_char;
+
+		/* yy_bp points to the position in yy_ch_buf of the start of
+		 * the current run.
+		 */
+		yy_bp = yy_cp;
+
+		yy_current_state = yy_start;
+		yy_current_state += YY_AT_BOL();
+yy_match:
+		do
+			{
+			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+			if ( yy_accept[yy_current_state] )
+				{
+				yy_last_accepting_state = yy_current_state;
+				yy_last_accepting_cpos = yy_cp;
+				}
+			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+				{
+				yy_current_state = (int) yy_def[yy_current_state];
+				if ( yy_current_state >= 274 )
+					yy_c = yy_meta[(unsigned int) yy_c];
+				}
+			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+			++yy_cp;
+			}
+		while ( yy_base[yy_current_state] != 332 );
+
+yy_find_action:
+		yy_act = yy_accept[yy_current_state];
+		if ( yy_act == 0 )
+			{ /* have to back up */
+			yy_cp = yy_last_accepting_cpos;
+			yy_current_state = yy_last_accepting_state;
+			yy_act = yy_accept[yy_current_state];
+			}
+
+		YY_DO_BEFORE_ACTION;
+
+
+do_action:	/* This label is used only to access EOF actions. */
+
+
+		switch ( yy_act )
+	{ /* beginning of action switch */
+			case 0: /* must back up */
+			/* undo the effects of YY_DO_BEFORE_ACTION */
+			*yy_cp = yy_hold_char;
+			yy_cp = yy_last_accepting_cpos;
+			yy_current_state = yy_last_accepting_state;
+			goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 30 "zparse.fl"
+lineno++;/*yylval.string=yytext;*/yyleng=0;
+	YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 31 "zparse.fl"
+return (',');
+	YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 32 "zparse.fl"
+return (':');
+	YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 33 "zparse.fl"
+return ('_');
+	YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 34 "zparse.fl"
+yylval.string=yytext;return(GSDLVERSION);
+	YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 35 "zparse.fl"
+return (GENERAL_SECTION);
+	YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 36 "zparse.fl"
+return (SEARCH_SECTION);
+	YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 37 "zparse.fl"
+return (BROWSE_SECTION);
+	YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 38 "zparse.fl"
+return (MACROS_SECTION);
+	YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 39 "zparse.fl"
+return (MAINTAINER);
+	YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 40 "zparse.fl"
+return(LANGUAGES);
+	YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 41 "zparse.fl"
+return(ABOUT);
+	YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 42 "zparse.fl"
+return(BROWSE);
+	YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 43 "zparse.fl"
+return(DATELIST);
+	YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 44 "zparse.fl"
+return(DOCUMENTARROWSBOTTOM);
+	YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 45 "zparse.fl"
+return(DOCUMENTBUTTONS);
+	YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 46 "zparse.fl"
+return(DOCUMENTHEADER);
+	YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 47 "zparse.fl"
+return(DOCUMENTIMAGES);
+	YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 48 "zparse.fl"
+return(DOCUMENTTEXT);
+	YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 49 "zparse.fl"
+return(ICONLINK);
+	YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 50 "zparse.fl"
+return(LIST);
+	YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 51 "zparse.fl"
+return(FORMAT);
+	YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 52 "zparse.fl"
+return(NAME);
+	YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 53 "zparse.fl"
+return(SEARCHTEXT);
+	YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 54 "zparse.fl"
+return(SECTIONLIST);
+	YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 55 "zparse.fl"
+return(SORTEDLIST);
+	YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 56 "zparse.fl"
+return(SORTEDSECTIONLIST);
+	YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 57 "zparse.fl"
+return(TEXTLINK);
+	YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 58 "zparse.fl"
+return(TYPE);
+	YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 59 "zparse.fl"
+return (PUBLIC);
+	YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 60 "zparse.fl"
+return (TRUE);
+	YY_BREAK
+case 32:
+YY_RULE_SETUP
+#line 61 "zparse.fl"
+return (FALSE);
+	YY_BREAK
+case 33:
+YY_RULE_SETUP
+#line 62 "zparse.fl"
+return (DOCUMENT);
+	YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 63 "zparse.fl"
+return (SECTION);
+	YY_BREAK
+case 35:
+YY_RULE_SETUP
+#line 64 "zparse.fl"
+return (ICON);
+	YY_BREAK
+case 36:
+YY_RULE_SETUP
+#line 65 "zparse.fl"
+return (SMALLICON);
+	YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 66 "zparse.fl"
+{string=NULL;BEGIN(STRINGCOND);}
+	YY_BREAK
+
+case 38:
+YY_RULE_SETUP
+#line 68 "zparse.fl"
+{/* append this to our current string EXC NEWLINE */
+			if (string==NULL) string_len=0; else
+			string_len=strlen(string);
+			string=realloc(string,string_len+strlen(yytext)+1);
+			/* +1 is for trailing \0 */
+			strcpy(string+string_len,yytext);
+			}
+	YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 75 "zparse.fl"
+{/* append this to our current string - INC NEWLINE */
+			lineno++;
+			if (string==NULL) string_len=0; else
+			string_len=strlen(string);
+			string=realloc(string,string_len+strlen(yytext)+1);
+			/* +1 is for trailing \0 */
+			strcpy(string+string_len,yytext);
+			}
+	YY_BREAK
+case 40:
+#line 84 "zparse.fl"
+case 41:
+YY_RULE_SETUP
+#line 84 "zparse.fl"
+{       /*replace quoted quote with one quote*/
+			string_len=strlen(string);
+			string=realloc(string,string_len+2);
+			string[string_len]='\"';
+			string[string_len+1]='\0';
+			}
+	YY_BREAK
+case 42:
+YY_RULE_SETUP
+#line 90 "zparse.fl"
+{
+			BEGIN(INITIAL);
+			yylval.string=string;
+			return(STRING);
+			  /* note that the string may have long bits of 
+			     whitespace in it that we could remove. */
+			}
+	YY_BREAK
+
+case 43:
+YY_RULE_SETUP
+#line 98 "zparse.fl"
+yylval.string=strdup(yytext);return (DATA);
+	YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 99 "zparse.fl"
+;
+	YY_BREAK
+case 45:
+YY_RULE_SETUP
+#line 100 "zparse.fl"
+lineno++;
+	YY_BREAK
+case 46:
+YY_RULE_SETUP
+#line 101 "zparse.fl"
+ECHO;
+	YY_BREAK
+#line 1072 "zparse.yy.c"
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(STRINGCOND):
+	yyterminate();
+
+	case YY_END_OF_BUFFER:
+		{
+		/* Amount of text matched not including the EOB char. */
+		int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1;
+
+		/* Undo the effects of YY_DO_BEFORE_ACTION. */
+		*yy_cp = yy_hold_char;
+		YY_RESTORE_YY_MORE_OFFSET
+
+		if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW )
+			{
+			/* We're scanning a new file or input source.  It's
+			 * possible that this happened because the user
+			 * just pointed yyin at a new source and called
+			 * yylex().  If so, then we have to assure
+			 * consistency between yy_current_buffer and our
+			 * globals.  Here is the right place to do so, because
+			 * this is the first action (other than possibly a
+			 * back-up) that will match for the new input source.
+			 */
+			yy_n_chars = yy_current_buffer->yy_n_chars;
+			yy_current_buffer->yy_input_file = yyin;
+			yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
+			}
+
+		/* Note that here we test for yy_c_buf_p "<=" to the position
+		 * of the first EOB in the buffer, since yy_c_buf_p will
+		 * already have been incremented past the NUL character
+		 * (since all states make transitions on EOB to the
+		 * end-of-buffer state).  Contrast this with the test
+		 * in input().
+		 */
+		if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+			{ /* This was really a NUL. */
+			yy_state_type yy_next_state;
+
+			yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
+
+			yy_current_state = yy_get_previous_state();
+
+			/* Okay, we're now positioned to make the NUL
+			 * transition.  We couldn't have
+			 * yy_get_previous_state() go ahead and do it
+			 * for us because it doesn't know how to deal
+			 * with the possibility of jamming (and we don't
+			 * want to build jamming into it because then it
+			 * will run more slowly).
+			 */
+
+			yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+			yy_bp = yytext_ptr + YY_MORE_ADJ;
+
+			if ( yy_next_state )
+				{
+				/* Consume the NUL. */
+				yy_cp = ++yy_c_buf_p;
+				yy_current_state = yy_next_state;
+				goto yy_match;
+				}
+
+			else
+				{
+				yy_cp = yy_c_buf_p;
+				goto yy_find_action;
+				}
+			}
+
+		else switch ( yy_get_next_buffer() )
+			{
+			case EOB_ACT_END_OF_FILE:
+				{
+				yy_did_buffer_switch_on_eof = 0;
+
+				if ( yywrap() )
+					{
+					/* Note: because we've taken care in
+					 * yy_get_next_buffer() to have set up
+					 * yytext, we can now set up
+					 * yy_c_buf_p so that if some total
+					 * hoser (like flex itself) wants to
+					 * call the scanner after we return the
+					 * YY_NULL, it'll still work - another
+					 * YY_NULL will get returned.
+					 */
+					yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
+
+					yy_act = YY_STATE_EOF(YY_START);
+					goto do_action;
+					}
+
+				else
+					{
+					if ( ! yy_did_buffer_switch_on_eof )
+						YY_NEW_FILE;
+					}
+				break;
+				}
+
+			case EOB_ACT_CONTINUE_SCAN:
+				yy_c_buf_p =
+					yytext_ptr + yy_amount_of_matched_text;
+
+				yy_current_state = yy_get_previous_state();
+
+				yy_cp = yy_c_buf_p;
+				yy_bp = yytext_ptr + YY_MORE_ADJ;
+				goto yy_match;
+
+			case EOB_ACT_LAST_MATCH:
+				yy_c_buf_p =
+				&yy_current_buffer->yy_ch_buf[yy_n_chars];
+
+				yy_current_state = yy_get_previous_state();
+
+				yy_cp = yy_c_buf_p;
+				yy_bp = yytext_ptr + YY_MORE_ADJ;
+				goto yy_find_action;
+			}
+		break;
+		}
+
+	default:
+		YY_FATAL_ERROR(
+			"fatal flex scanner internal error--no action found" );
+	} /* end of action switch */
+		} /* end of scanning one token */
+	} /* end of yylex */
+
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ *	EOB_ACT_LAST_MATCH -
+ *	EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ *	EOB_ACT_END_OF_FILE - end of file
+ */
+
+static int yy_get_next_buffer()
+	{
+	register char *dest = yy_current_buffer->yy_ch_buf;
+	register char *source = yytext_ptr;
+	register int number_to_move, i;
+	int ret_val;
+
+	if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
+		YY_FATAL_ERROR(
+		"fatal flex scanner internal error--end of buffer missed" );
+
+	if ( yy_current_buffer->yy_fill_buffer == 0 )
+		{ /* Don't try to fill the buffer, so this is an EOF. */
+		if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 )
+			{
+			/* We matched a single character, the EOB, so
+			 * treat this as a final EOF.
+			 */
+			return EOB_ACT_END_OF_FILE;
+			}
+
+		else
+			{
+			/* We matched some text prior to the EOB, first
+			 * process it.
+			 */
+			return EOB_ACT_LAST_MATCH;
+			}
+		}
+
+	/* Try to read more data. */
+
+	/* First move last chars to start of buffer. */
+	number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
+
+	for ( i = 0; i < number_to_move; ++i )
+		*(dest++) = *(source++);
+
+	if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+		/* don't do the read, it's not guaranteed to return an EOF,
+		 * just force an EOF
+		 */
+		yy_current_buffer->yy_n_chars = yy_n_chars = 0;
+
+	else
+		{
+		int num_to_read =
+			yy_current_buffer->yy_buf_size - number_to_move - 1;
+
+		while ( num_to_read <= 0 )
+			{ /* Not enough room in the buffer - grow it. */
+#ifdef YY_USES_REJECT
+			YY_FATAL_ERROR(
+"input buffer overflow, can't enlarge buffer because scanner uses REJECT" );
+#else
+
+			/* just a shorter name for the current buffer */
+			YY_BUFFER_STATE b = yy_current_buffer;
+
+			int yy_c_buf_p_offset =
+				(int) (yy_c_buf_p - b->yy_ch_buf);
+
+			if ( b->yy_is_our_buffer )
+				{
+				int new_size = b->yy_buf_size * 2;
+
+				if ( new_size <= 0 )
+					b->yy_buf_size += b->yy_buf_size / 8;
+				else
+					b->yy_buf_size *= 2;
+
+				b->yy_ch_buf = (char *)
+					/* Include room in for 2 EOB chars. */
+					yy_flex_realloc( (void *) b->yy_ch_buf,
+							 b->yy_buf_size + 2 );
+				}
+			else
+				/* Can't grow it, we don't own it. */
+				b->yy_ch_buf = 0;
+
+			if ( ! b->yy_ch_buf )
+				YY_FATAL_ERROR(
+				"fatal error - scanner input buffer overflow" );
+
+			yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+			num_to_read = yy_current_buffer->yy_buf_size -
+						number_to_move - 1;
+#endif
+			}
+
+		if ( num_to_read > YY_READ_BUF_SIZE )
+			num_to_read = YY_READ_BUF_SIZE;
+
+		/* Read in more data. */
+		YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
+			yy_n_chars, num_to_read );
+
+		yy_current_buffer->yy_n_chars = yy_n_chars;
+		}
+
+	if ( yy_n_chars == 0 )
+		{
+		if ( number_to_move == YY_MORE_ADJ )
+			{
+			ret_val = EOB_ACT_END_OF_FILE;
+			yyrestart( yyin );
+			}
+
+		else
+			{
+			ret_val = EOB_ACT_LAST_MATCH;
+			yy_current_buffer->yy_buffer_status =
+				YY_BUFFER_EOF_PENDING;
+			}
+		}
+
+	else
+		ret_val = EOB_ACT_CONTINUE_SCAN;
+
+	yy_n_chars += number_to_move;
+	yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+	yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+	yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
+
+	return ret_val;
+	}
+
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+static yy_state_type yy_get_previous_state()
+	{
+	register yy_state_type yy_current_state;
+	register char *yy_cp;
+
+	yy_current_state = yy_start;
+	yy_current_state += YY_AT_BOL();
+
+	for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
+		{
+		register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+		if ( yy_accept[yy_current_state] )
+			{
+			yy_last_accepting_state = yy_current_state;
+			yy_last_accepting_cpos = yy_cp;
+			}
+		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+			{
+			yy_current_state = (int) yy_def[yy_current_state];
+			if ( yy_current_state >= 274 )
+				yy_c = yy_meta[(unsigned int) yy_c];
+			}
+		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+		}
+
+	return yy_current_state;
+	}
+
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ *	next_state = yy_try_NUL_trans( current_state );
+ */
+
+#ifdef YY_USE_PROTOS
+static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state )
+#else
+static yy_state_type yy_try_NUL_trans( yy_current_state )
+yy_state_type yy_current_state;
+#endif
+	{
+	register int yy_is_jam;
+	register char *yy_cp = yy_c_buf_p;
+
+	register YY_CHAR yy_c = 1;
+	if ( yy_accept[yy_current_state] )
+		{
+		yy_last_accepting_state = yy_current_state;
+		yy_last_accepting_cpos = yy_cp;
+		}
+	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+		{
+		yy_current_state = (int) yy_def[yy_current_state];
+		if ( yy_current_state >= 274 )
+			yy_c = yy_meta[(unsigned int) yy_c];
+		}
+	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+	yy_is_jam = (yy_current_state == 273);
+
+	return yy_is_jam ? 0 : yy_current_state;
+	}
+
+
+#ifndef YY_NO_UNPUT
+#ifdef YY_USE_PROTOS
+static void yyunput( int c, register char *yy_bp )
+#else
+static void yyunput( c, yy_bp )
+int c;
+register char *yy_bp;
+#endif
+	{
+	register char *yy_cp = yy_c_buf_p;
+
+	/* undo effects of setting up yytext */
+	*yy_cp = yy_hold_char;
+
+	if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
+		{ /* need to shift things up to make room */
+		/* +2 for EOB chars. */
+		register int number_to_move = yy_n_chars + 2;
+		register char *dest = &yy_current_buffer->yy_ch_buf[
+					yy_current_buffer->yy_buf_size + 2];
+		register char *source =
+				&yy_current_buffer->yy_ch_buf[number_to_move];
+
+		while ( source > yy_current_buffer->yy_ch_buf )
+			*--dest = *--source;
+
+		yy_cp += (int) (dest - source);
+		yy_bp += (int) (dest - source);
+		yy_current_buffer->yy_n_chars =
+			yy_n_chars = yy_current_buffer->yy_buf_size;
+
+		if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
+			YY_FATAL_ERROR( "flex scanner push-back overflow" );
+		}
+
+	*--yy_cp = (char) c;
+
+
+	yytext_ptr = yy_bp;
+	yy_hold_char = *yy_cp;
+	yy_c_buf_p = yy_cp;
+	}
+#endif	/* ifndef YY_NO_UNPUT */
+
+
+#ifdef __cplusplus
+static int yyinput()
+#else
+static int input()
+#endif
+	{
+	int c;
+
+	*yy_c_buf_p = yy_hold_char;
+
+	if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+		{
+		/* yy_c_buf_p now points to the character we want to return.
+		 * If this occurs *before* the EOB characters, then it's a
+		 * valid NUL; if not, then we've hit the end of the buffer.
+		 */
+		if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
+			/* This was really a NUL. */
+			*yy_c_buf_p = '\0';
+
+		else
+			{ /* need more input */
+			int offset = yy_c_buf_p - yytext_ptr;
+			++yy_c_buf_p;
+
+			switch ( yy_get_next_buffer() )
+				{
+				case EOB_ACT_LAST_MATCH:
+					/* This happens because yy_g_n_b()
+					 * sees that we've accumulated a
+					 * token and flags that we need to
+					 * try matching the token before
+					 * proceeding.  But for input(),
+					 * there's no matching to consider.
+					 * So convert the EOB_ACT_LAST_MATCH
+					 * to EOB_ACT_END_OF_FILE.
+					 */
+
+					/* Reset buffer status. */
+					yyrestart( yyin );
+
+					/* fall through */
+
+				case EOB_ACT_END_OF_FILE:
+					{
+					if ( yywrap() )
+						return EOF;
+
+					if ( ! yy_did_buffer_switch_on_eof )
+						YY_NEW_FILE;
+#ifdef __cplusplus
+					return yyinput();
+#else
+					return input();
+#endif
+					}
+
+				case EOB_ACT_CONTINUE_SCAN:
+					yy_c_buf_p = yytext_ptr + offset;
+					break;
+				}
+			}
+		}
+
+	c = *(unsigned char *) yy_c_buf_p;	/* cast for 8-bit char's */
+	*yy_c_buf_p = '\0';	/* preserve yytext */
+	yy_hold_char = *++yy_c_buf_p;
+
+	yy_current_buffer->yy_at_bol = (c == '\n');
+
+	return c;
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yyrestart( FILE *input_file )
+#else
+void yyrestart( input_file )
+FILE *input_file;
+#endif
+	{
+	if ( ! yy_current_buffer )
+		yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
+
+	yy_init_buffer( yy_current_buffer, input_file );
+	yy_load_buffer_state();
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
+#else
+void yy_switch_to_buffer( new_buffer )
+YY_BUFFER_STATE new_buffer;
+#endif
+	{
+	if ( yy_current_buffer == new_buffer )
+		return;
+
+	if ( yy_current_buffer )
+		{
+		/* Flush out information for old buffer. */
+		*yy_c_buf_p = yy_hold_char;
+		yy_current_buffer->yy_buf_pos = yy_c_buf_p;
+		yy_current_buffer->yy_n_chars = yy_n_chars;
+		}
+
+	yy_current_buffer = new_buffer;
+	yy_load_buffer_state();
+
+	/* We don't actually know whether we did this switch during
+	 * EOF (yywrap()) processing, but the only time this flag
+	 * is looked at is after yywrap() is called, so it's safe
+	 * to go ahead and always set it.
+	 */
+	yy_did_buffer_switch_on_eof = 1;
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_load_buffer_state( void )
+#else
+void yy_load_buffer_state()
+#endif
+	{
+	yy_n_chars = yy_current_buffer->yy_n_chars;
+	yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
+	yyin = yy_current_buffer->yy_input_file;
+	yy_hold_char = *yy_c_buf_p;
+	}
+
+
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
+#else
+YY_BUFFER_STATE yy_create_buffer( file, size )
+FILE *file;
+int size;
+#endif
+	{
+	YY_BUFFER_STATE b;
+
+	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
+	if ( ! b )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+	b->yy_buf_size = size;
+
+	/* yy_ch_buf has to be 2 characters longer than the size given because
+	 * we need to put in 2 end-of-buffer characters.
+	 */
+	b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 );
+	if ( ! b->yy_ch_buf )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
+
+	b->yy_is_our_buffer = 1;
+
+	yy_init_buffer( b, file );
+
+	return b;
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_delete_buffer( YY_BUFFER_STATE b )
+#else
+void yy_delete_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+	{
+	if ( ! b )
+		return;
+
+	if ( b == yy_current_buffer )
+		yy_current_buffer = (YY_BUFFER_STATE) 0;
+
+	if ( b->yy_is_our_buffer )
+		yy_flex_free( (void *) b->yy_ch_buf );
+
+	yy_flex_free( (void *) b );
+	}
+
+
+
+#ifdef YY_USE_PROTOS
+void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
+#else
+void yy_init_buffer( b, file )
+YY_BUFFER_STATE b;
+FILE *file;
+#endif
+
+
+	{
+	yy_flush_buffer( b );
+
+	b->yy_input_file = file;
+	b->yy_fill_buffer = 1;
+
+#if YY_ALWAYS_INTERACTIVE
+	b->yy_is_interactive = 1;
+#else
+#if YY_NEVER_INTERACTIVE
+	b->yy_is_interactive = 0;
+#else
+	b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+#endif
+#endif
+	}
+
+
+#ifdef YY_USE_PROTOS
+void yy_flush_buffer( YY_BUFFER_STATE b )
+#else
+void yy_flush_buffer( b )
+YY_BUFFER_STATE b;
+#endif
+
+	{
+	if ( ! b )
+		return;
+
+	b->yy_n_chars = 0;
+
+	/* We always need two end-of-buffer characters.  The first causes
+	 * a transition to the end-of-buffer state.  The second causes
+	 * a jam in that state.
+	 */
+	b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+	b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+	b->yy_buf_pos = &b->yy_ch_buf[0];
+
+	b->yy_at_bol = 1;
+	b->yy_buffer_status = YY_BUFFER_NEW;
+
+	if ( b == yy_current_buffer )
+		yy_load_buffer_state();
+	}
+
+
+#ifndef YY_NO_SCAN_BUFFER
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size )
+#else
+YY_BUFFER_STATE yy_scan_buffer( base, size )
+char *base;
+yy_size_t size;
+#endif
+	{
+	YY_BUFFER_STATE b;
+
+	if ( size < 2 ||
+	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
+	     base[size-1] != YY_END_OF_BUFFER_CHAR )
+		/* They forgot to leave room for the EOB's. */
+		return 0;
+
+	b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) );
+	if ( ! b )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
+
+	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
+	b->yy_buf_pos = b->yy_ch_buf = base;
+	b->yy_is_our_buffer = 0;
+	b->yy_input_file = 0;
+	b->yy_n_chars = b->yy_buf_size;
+	b->yy_is_interactive = 0;
+	b->yy_at_bol = 1;
+	b->yy_fill_buffer = 0;
+	b->yy_buffer_status = YY_BUFFER_NEW;
+
+	yy_switch_to_buffer( b );
+
+	return b;
+	}
+#endif
+
+
+#ifndef YY_NO_SCAN_STRING
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str )
+#else
+YY_BUFFER_STATE yy_scan_string( yy_str )
+yyconst char *yy_str;
+#endif
+	{
+	int len;
+	for ( len = 0; yy_str[len]; ++len )
+		;
+
+	return yy_scan_bytes( yy_str, len );
+	}
+#endif
+
+
+#ifndef YY_NO_SCAN_BYTES
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len )
+#else
+YY_BUFFER_STATE yy_scan_bytes( bytes, len )
+yyconst char *bytes;
+int len;
+#endif
+	{
+	YY_BUFFER_STATE b;
+	char *buf;
+	yy_size_t n;
+	int i;
+
+	/* Get memory for full buffer, including space for trailing EOB's. */
+	n = len + 2;
+	buf = (char *) yy_flex_alloc( n );
+	if ( ! buf )
+		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
+
+	for ( i = 0; i < len; ++i )
+		buf[i] = bytes[i];
+
+	buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
+
+	b = yy_scan_buffer( buf, n );
+	if ( ! b )
+		YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
+
+	/* It's okay to grow etc. this buffer, and we should throw it
+	 * away when we're done.
+	 */
+	b->yy_is_our_buffer = 1;
+
+	return b;
+	}
+#endif
+
+
+#ifndef YY_NO_PUSH_STATE
+#ifdef YY_USE_PROTOS
+static void yy_push_state( int new_state )
+#else
+static void yy_push_state( new_state )
+int new_state;
+#endif
+	{
+	if ( yy_start_stack_ptr >= yy_start_stack_depth )
+		{
+		yy_size_t new_size;
+
+		yy_start_stack_depth += YY_START_STACK_INCR;
+		new_size = yy_start_stack_depth * sizeof( int );
+
+		if ( ! yy_start_stack )
+			yy_start_stack = (int *) yy_flex_alloc( new_size );
+
+		else
+			yy_start_stack = (int *) yy_flex_realloc(
+					(void *) yy_start_stack, new_size );
+
+		if ( ! yy_start_stack )
+			YY_FATAL_ERROR(
+			"out of memory expanding start-condition stack" );
+		}
+
+	yy_start_stack[yy_start_stack_ptr++] = YY_START;
+
+	BEGIN(new_state);
+	}
+#endif
+
+
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state()
+	{
+	if ( --yy_start_stack_ptr < 0 )
+		YY_FATAL_ERROR( "start-condition stack underflow" );
+
+	BEGIN(yy_start_stack[yy_start_stack_ptr]);
+	}
+#endif
+
+
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state()
+	{
+	return yy_start_stack[yy_start_stack_ptr - 1];
+	}
+#endif
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+#ifdef YY_USE_PROTOS
+static void yy_fatal_error( yyconst char msg[] )
+#else
+static void yy_fatal_error( msg )
+char msg[];
+#endif
+	{
+	(void) fprintf( stderr, "%s\n", msg );
+	exit( YY_EXIT_FAILURE );
+	}
+
+
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+	do \
+		{ \
+		/* Undo effects of setting up yytext. */ \
+		yytext[yyleng] = yy_hold_char; \
+		yy_c_buf_p = yytext + n; \
+		yy_hold_char = *yy_c_buf_p; \
+		*yy_c_buf_p = '\0'; \
+		yyleng = n; \
+		} \
+	while ( 0 )
+
+
+/* Internal utility routines. */
+
+#ifndef yytext_ptr
+#ifdef YY_USE_PROTOS
+static void yy_flex_strncpy( char *s1, yyconst char *s2, int n )
+#else
+static void yy_flex_strncpy( s1, s2, n )
+char *s1;
+yyconst char *s2;
+int n;
+#endif
+	{
+	register int i;
+	for ( i = 0; i < n; ++i )
+		s1[i] = s2[i];
+	}
+#endif
+
+#ifdef YY_NEED_STRLEN
+#ifdef YY_USE_PROTOS
+static int yy_flex_strlen( yyconst char *s )
+#else
+static int yy_flex_strlen( s )
+yyconst char *s;
+#endif
+	{
+	register int n;
+	for ( n = 0; s[n]; ++n )
+		;
+
+	return n;
+	}
+#endif
+
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_alloc( yy_size_t size )
+#else
+static void *yy_flex_alloc( size )
+yy_size_t size;
+#endif
+	{
+	return (void *) malloc( size );
+	}
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_realloc( void *ptr, yy_size_t size )
+#else
+static void *yy_flex_realloc( ptr, size )
+void *ptr;
+yy_size_t size;
+#endif
+	{
+	/* The cast to (char *) in the following accommodates both
+	 * implementations that use char* generic pointers, and those
+	 * that use void* generic pointers.  It works with the latter
+	 * because both ANSI C and C++ allow castless assignment from
+	 * any pointer type to void*, and deal with argument conversions
+	 * as though doing an assignment.
+	 */
+	return (void *) realloc( (char *) ptr, size );
+	}
+
+#ifdef YY_USE_PROTOS
+static void yy_flex_free( void *ptr )
+#else
+static void yy_flex_free( ptr )
+void *ptr;
+#endif
+	{
+	free( ptr );
+	}
+
+#if YY_MAIN
+int main()
+	{
+	yylex();
+	return 0;
+	}
+#endif
+#line 101 "zparse.fl"
+
+/******** deleted rules: *******
+en			return(EN);
+fr			return(FR);
+mi			return(MI);
+zh			return(ZH);
+de			return(DE);
+***************/
+
+
+
+
