LIBGCRYPT-1-2-BRANCH libgcrypt (16 files)

cvs user wk cvs at cvs.gnupg.org
Tue Jan 4 21:44:03 CET 2005


    Date: Tuesday, January 4, 2005 @ 21:50:23
  Author: wk
    Path: /cvs/libgcrypt/libgcrypt
     Tag: LIBGCRYPT-1-2-BRANCH

Modified: ChangeLog INSTALL acinclude.m4 compile config.guess config.sub
          depcomp doc/ChangeLog doc/gcrypt.texi doc/mdate-sh
          doc/texinfo.tex install-sh missing mkinstalldirs src/ChangeLog
          src/gcrypt.h

Updated for automake 1.9.


-----------------+
 ChangeLog       |    6 
 INSTALL         |   52 
 acinclude.m4    |   24 
 compile         |  155 -
 config.guess    |   95 
 config.sub      |   57 
 depcomp         |  104 -
 doc/ChangeLog   |    8 
 doc/gcrypt.texi |  128 -
 doc/mdate-sh    |   37 
 doc/texinfo.tex | 5594 ++++++++++++++++++++++++++++--------------------------
 install-sh      |  471 ++--
 missing         |  131 -
 mkinstalldirs   |   69 
 src/ChangeLog   |    4 
 src/gcrypt.h    |   50 
 16 files changed, 3761 insertions(+), 3224 deletions(-)


Index: libgcrypt/ChangeLog
diff -u libgcrypt/ChangeLog:1.158.2.2 libgcrypt/ChangeLog:1.158.2.3
--- libgcrypt/ChangeLog:1.158.2.2	Sat Dec 18 12:05:54 2004
+++ libgcrypt/ChangeLog	Tue Jan  4 21:50:23 2005
@@ -1,3 +1,9 @@
+2005-01-04  Werner Koch  <wk at g10code.com>
+
+	Updated to automake 1.9.
+	
+	* acinclude.m4:  Updated for automake 1.9.
+
 2004-12-18  Werner Koch  <wk at g10code.com>
 
 	* autogen.sh: Added option --build-w32 to run W32 cross compiling
Index: libgcrypt/INSTALL
diff -u libgcrypt/INSTALL:1.28 libgcrypt/INSTALL:1.28.2.1
--- libgcrypt/INSTALL:1.28	Mon Dec  8 22:43:02 2003
+++ libgcrypt/INSTALL	Tue Jan  4 21:50:23 2005
@@ -1,13 +1,16 @@
-Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
-Foundation, Inc.
+Installation Instructions
+*************************
 
-   This file is free documentation; the Free Software Foundation gives
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004 Free
+Software Foundation, Inc.
+
+This file is free documentation; the Free Software Foundation gives
 unlimited permission to copy, distribute and modify it.
 
 Basic Installation
 ==================
 
-   These are generic installation instructions.
+These are generic installation instructions.
 
    The `configure' shell script attempts to guess correct values for
 various system-dependent variables used during compilation.  It uses
@@ -67,9 +70,9 @@
 Compilers and Options
 =====================
 
-   Some systems require unusual options for compilation or linking that
-the `configure' script does not know about.  Run `./configure --help'
-for details on some of the pertinent environment variables.
+Some systems require unusual options for compilation or linking that the
+`configure' script does not know about.  Run `./configure --help' for
+details on some of the pertinent environment variables.
 
    You can give `configure' initial values for configuration parameters
 by setting variables in the command line or in the environment.  Here
@@ -82,7 +85,7 @@
 Compiling For Multiple Architectures
 ====================================
 
-   You can compile the package for more than one kind of computer at the
+You can compile the package for more than one kind of computer at the
 same time, by placing the object files for each architecture in their
 own directory.  To do this, you must use a version of `make' that
 supports the `VPATH' variable, such as GNU `make'.  `cd' to the
@@ -99,19 +102,19 @@
 Installation Names
 ==================
 
-   By default, `make install' will install the package's files in
+By default, `make install' will install the package's files in
 `/usr/local/bin', `/usr/local/man', etc.  You can specify an
 installation prefix other than `/usr/local' by giving `configure' the
-option `--prefix=PATH'.
+option `--prefix=PREFIX'.
 
    You can specify separate installation prefixes for
 architecture-specific files and architecture-independent files.  If you
-give `configure' the option `--exec-prefix=PATH', the package will use
-PATH as the prefix for installing programs and libraries.
+give `configure' the option `--exec-prefix=PREFIX', the package will
+use PREFIX as the prefix for installing programs and libraries.
 Documentation and other data files will still use the regular prefix.
 
    In addition, if you use an unusual directory layout you can give
-options like `--bindir=PATH' to specify different values for particular
+options like `--bindir=DIR' to specify different values for particular
 kinds of files.  Run `configure --help' for a list of the directories
 you can set and what kinds of files go in them.
 
@@ -122,7 +125,7 @@
 Optional Features
 =================
 
-   Some packages pay attention to `--enable-FEATURE' options to
+Some packages pay attention to `--enable-FEATURE' options to
 `configure', where FEATURE indicates an optional part of the package.
 They may also pay attention to `--with-PACKAGE' options, where PACKAGE
 is something like `gnu-as' or `x' (for the X Window System).  The
@@ -137,11 +140,11 @@
 Specifying the System Type
 ==========================
 
-   There may be some features `configure' cannot figure out
-automatically, but needs to determine by the type of machine the package
-will run on.  Usually, assuming the package is built to be run on the
-_same_ architectures, `configure' can figure that out, but if it prints
-a message saying it cannot guess the machine type, give it the
+There may be some features `configure' cannot figure out automatically,
+but needs to determine by the type of machine the package will run on.
+Usually, assuming the package is built to be run on the _same_
+architectures, `configure' can figure that out, but if it prints a
+message saying it cannot guess the machine type, give it the
 `--build=TYPE' option.  TYPE can either be a short name for the system
 type, such as `sun4', or a canonical name which has the form:
 
@@ -167,9 +170,9 @@
 Sharing Defaults
 ================
 
-   If you want to set default values for `configure' scripts to share,
-you can create a site shell script called `config.site' that gives
-default values for variables like `CC', `cache_file', and `prefix'.
+If you want to set default values for `configure' scripts to share, you
+can create a site shell script called `config.site' that gives default
+values for variables like `CC', `cache_file', and `prefix'.
 `configure' looks for `PREFIX/share/config.site' if it exists, then
 `PREFIX/etc/config.site' if it exists.  Or, you can set the
 `CONFIG_SITE' environment variable to the location of the site script.
@@ -178,7 +181,7 @@
 Defining Variables
 ==================
 
-   Variables not defined in a site shell script can be set in the
+Variables not defined in a site shell script can be set in the
 environment passed to `configure'.  However, some packages may run
 configure again during the build, and the customized values of these
 variables may be lost.  In order to avoid this problem, you should set
@@ -192,8 +195,7 @@
 `configure' Invocation
 ======================
 
-   `configure' recognizes the following options to control how it
-operates.
+`configure' recognizes the following options to control how it operates.
 
 `--help'
 `-h'
Index: libgcrypt/acinclude.m4
diff -u libgcrypt/acinclude.m4:1.43 libgcrypt/acinclude.m4:1.43.2.1
--- libgcrypt/acinclude.m4:1.43	Fri Oct 31 06:06:09 2003
+++ libgcrypt/acinclude.m4	Tue Jan  4 21:50:23 2005
@@ -21,14 +21,14 @@
 dnl GNUPG_MSG_PRINT(STRING)
 dnl print a message
 dnl
-define(GNUPG_MSG_PRINT,
+define([GNUPG_MSG_PRINT],
   [ echo $ac_n "$1"" $ac_c" 1>&AS_MESSAGE_FD([])
   ])
 
 dnl GNUPG_CHECK_TYPEDEF(TYPE, HAVE_NAME)
 dnl Check whether a typedef exists and create a #define $2 if it exists
 dnl
-AC_DEFUN(GNUPG_CHECK_TYPEDEF,
+AC_DEFUN([GNUPG_CHECK_TYPEDEF],
   [ AC_MSG_CHECKING(for $1 typedef)
     AC_CACHE_VAL(gnupg_cv_typedef_$1,
     [AC_TRY_COMPILE([#define _GNU_SOURCE 1
@@ -50,7 +50,7 @@
 dnl We must use a temp file in the current directory because make distcheck 
 dnl install all sourcefiles RO.
 dnl
-AC_DEFUN(GNUPG_FIX_HDR_VERSION,
+AC_DEFUN([GNUPG_FIX_HDR_VERSION],
   [ sed "s/^#define $2 \".*/#define $2 \"$VERSION\"/" $srcdir/$1 > fixhdr.tmp
     if cmp -s $srcdir/$1 fixhdr.tmp 2>/dev/null; then
         rm -f fixhdr.tmp
@@ -72,7 +72,7 @@
 
 dnl GNUPG_CHECK_GNUMAKE
 dnl
-AC_DEFUN(GNUPG_CHECK_GNUMAKE,
+AC_DEFUN([GNUPG_CHECK_GNUMAKE],
   [
     if ${MAKE-make} --version 2>/dev/null | grep '^GNU ' >/dev/null 2>&1; then
         :
@@ -93,7 +93,7 @@
 # Does the compiler prefix global symbols with an underscore?
 #
 # Taken from GnuPG 1.2 and modified to use the libtool macros.
-AC_DEFUN(GNUPG_SYS_SYMBOL_UNDERSCORE,
+AC_DEFUN([GNUPG_SYS_SYMBOL_UNDERSCORE],
 [tmp_do_check="no"
 case "${target}" in
     i386-emx-os2 | i[3456]86-pc-os2*emx | i386-pc-msdosdjgpp)
@@ -158,7 +158,7 @@
 ######################################################################
 dnl GNUPG_CHECK_MLOCK
 dnl
-define(GNUPG_CHECK_MLOCK,
+define([GNUPG_CHECK_MLOCK],
   [ AC_CHECK_FUNCS(mlock)
     if test "$ac_cv_func_mlock" = "no"; then
         AC_CHECK_HEADERS(sys/mman.h)
@@ -244,7 +244,7 @@
   ])
 
 # GNUPG_SYS_LIBTOOL_CYGWIN32 - find tools needed on cygwin32
-AC_DEFUN(GNUPG_SYS_LIBTOOL_CYGWIN32,
+AC_DEFUN([GNUPG_SYS_LIBTOOL_CYGWIN32],
 [AC_CHECK_TOOL(DLLTOOL, dlltool, false)
 AC_CHECK_TOOL(AS, as, false)
 ])
@@ -252,7 +252,7 @@
 dnl LIST_MEMBER()
 dnl Check wether an element ist contained in a list.  Set `found' to
 dnl `1' if the element is found in the list, to `0' otherwise.
-AC_DEFUN(LIST_MEMBER,
+AC_DEFUN([LIST_MEMBER],
 [
 name=$1
 list=$2
@@ -269,7 +269,7 @@
 dnl                   [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
 dnl Test for libgpg-error and define GPG_ERROR_CFLAGS and GPG_ERROR_LIBS
 dnl
-AC_DEFUN(AM_PATH_GPG_ERROR,
+AC_DEFUN([AM_PATH_GPG_ERROR],
 [ AC_ARG_WITH(gpg-error-prefix,
             AC_HELP_STRING([--with-gpg-error-prefix=PFX],
                            [prefix where GPG Error is installed (optional)]),
@@ -363,7 +363,7 @@
 dnl ##
 dnl
 dnl #   auxilliary macros
-AC_DEFUN(_AC_PTH_ERROR, [dnl
+AC_DEFUN([_AC_PTH_ERROR], [dnl
 AC_MSG_RESULT([*FAILED*])
 dnl define(_ac_pth_line,dnl
 dnl "+------------------------------------------------------------------------+")
@@ -375,13 +375,13 @@
 dnl undefine(_ac_pth_line)
 exit 1
 ])
-AC_DEFUN(_AC_PTH_VERBOSE, [dnl
+AC_DEFUN([_AC_PTH_VERBOSE], [dnl
 if test ".$verbose" = .yes; then
     AC_MSG_RESULT([  $1])
 fi
 ])
 dnl #   the user macro
-AC_DEFUN(AC_CHECK_PTH, [dnl
+AC_DEFUN([AC_CHECK_PTH], [dnl
 dnl
 dnl #   prerequisites
 AC_REQUIRE([AC_PROG_CC])dnl
Index: libgcrypt/compile
diff -u libgcrypt/compile:1.1 libgcrypt/compile:1.1.2.1
--- libgcrypt/compile:1.1	Mon Mar 29 10:40:44 2004
+++ libgcrypt/compile	Tue Jan  4 21:50:23 2005
@@ -1,8 +1,9 @@
 #! /bin/sh
-
 # Wrapper for compilers which do not understand `-c -o'.
 
-# Copyright 1999, 2000 Free Software Foundation, Inc.
+scriptversion=2004-10-12.08
+
+# Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
 # Written by Tom Tromey <tromey at cygnus.com>.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -24,84 +25,118 @@
 # configuration script generated by Autoconf, you may include it under
 # the same distribution terms that you use for the rest of that program.
 
-# Usage:
-# compile PROGRAM [ARGS]...
-# `-o FOO.o' is removed from the args passed to the actual compile.
-
-# Usage statement added by Billy Biggs <vektor at dumbterm.net>.
-if [ -z $1 ]; then
-    echo "Wrapper for compilers which do not understand '-c -o'."
-    echo "usage: compile PROGRAM [ARGS]..."
-    echo "'-o FOO.o' is removed from the args passed to the actual compile."
-    exit 1
-fi
-
-prog=$1
-shift
+# This file is maintained in Automake, please report
+# bugs to <bug-automake at gnu.org> or send patches to
+# <automake-patches at gnu.org>.
+
+case $1 in
+  '')
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: compile [--help] [--version] PROGRAM [ARGS]
+
+Wrapper for compilers which do not understand `-c -o'.
+Remove `-o dest.o' from ARGS, run PROGRAM with the remaining
+arguments, and rename the output as expected.
+
+If you are trying to build a whole package this is not the
+right script to run: please start by reading the file `INSTALL'.
+
+Report bugs to <bug-automake at gnu.org>.
+EOF
+    exit 0
+    ;;
+  -v | --v*)
+    echo "compile $scriptversion"
+    exit 0
+    ;;
+esac
 
 ofile=
 cfile=
-args=
-while test $# -gt 0; do
-   case "$1" in
-    -o)
-       # configure might choose to run compile as `compile cc -o foo foo.c'.
-       # So we do something ugly here.
-       ofile=$2
-       shift
-       case "$ofile" in
-	*.o | *.obj)
-	   ;;
-	*)
-	   args="$args -o $ofile"
-	   ofile=
-	   ;;
-       esac
-       ;;
-    *.c)
-       cfile=$1
-       args="$args $1"
-       ;;
-    *)
-       args="$args $1"
-       ;;
-   esac
-   shift
+eat=
+
+for arg
+do
+  if test -n "$eat"; then
+    eat=
+  else
+    case $1 in
+      -o)
+	# configure might choose to run compile as `compile cc -o foo foo.c'.
+	# So we strip `-o arg' only if arg is an object.
+	eat=1
+	case $2 in
+	  *.o | *.obj)
+	    ofile=$2
+	    ;;
+	  *)
+	    set x "$@" -o "$2"
+	    shift
+	    ;;
+	esac
+	;;
+      *.c)
+	cfile=$1
+	set x "$@" "$1"
+	shift
+	;;
+      *)
+	set x "$@" "$1"
+	shift
+	;;
+    esac
+  fi
+  shift
 done
 
 if test -z "$ofile" || test -z "$cfile"; then
-   # If no `-o' option was seen then we might have been invoked from a
-   # pattern rule where we don't need one.  That is ok -- this is a
-   # normal compilation that the losing compiler can handle.  If no
-   # `.c' file was seen then we are probably linking.  That is also
-   # ok.
-   exec "$prog" $args
+  # If no `-o' option was seen then we might have been invoked from a
+  # pattern rule where we don't need one.  That is ok -- this is a
+  # normal compilation that the losing compiler can handle.  If no
+  # `.c' file was seen then we are probably linking.  That is also
+  # ok.
+  exec "$@"
 fi
 
 # Name of file we expect compiler to create.
-cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
+cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
 
 # Create the lock directory.
 # Note: use `[/.-]' here to ensure that we don't use the same name
 # that we are using for the .o file.  Also, base the name on the expected
 # object file name, since that is what matters with a parallel build.
-lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
+lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
 while true; do
-   if mkdir $lockdir > /dev/null 2>&1; then
-      break
-   fi
-   sleep 1
+  if mkdir "$lockdir" >/dev/null 2>&1; then
+    break
+  fi
+  sleep 1
 done
 # FIXME: race condition here if user kills between mkdir and trap.
-trap "rmdir $lockdir; exit 1" 1 2 15
+trap "rmdir '$lockdir'; exit 1" 1 2 15
 
 # Run the compile.
-"$prog" $args
-status=$?
+"$@"
+ret=$?
 
 if test -f "$cofile"; then
-   mv "$cofile" "$ofile"
+  mv "$cofile" "$ofile"
+elif test -f "${cofile}bj"; then
+  mv "${cofile}bj" "$ofile"
 fi
 
-rmdir $lockdir
-exit $status
+rmdir "$lockdir"
+exit $ret
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:
Index: libgcrypt/config.guess
diff -u libgcrypt/config.guess:1.2 libgcrypt/config.guess:1.2.2.1
--- libgcrypt/config.guess:1.2	Tue Apr  6 15:24:24 2004
+++ libgcrypt/config.guess	Tue Jan  4 21:50:23 2005
@@ -1,9 +1,9 @@
 #! /bin/sh
 # Attempt to guess a canonical system name.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+#   2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
-timestamp='2004-01-05'
+timestamp='2004-08-13'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -53,7 +53,7 @@
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
@@ -197,15 +197,21 @@
 	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
 	echo "${machine}-${os}${release}"
 	exit 0 ;;
+    amd64:OpenBSD:*:*)
+	echo x86_64-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
     amiga:OpenBSD:*:*)
 	echo m68k-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
-    arc:OpenBSD:*:*)
-	echo mipsel-unknown-openbsd${UNAME_RELEASE}
+    cats:OpenBSD:*:*)
+	echo arm-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
     hp300:OpenBSD:*:*)
 	echo m68k-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
+    luna88k:OpenBSD:*:*)
+    	echo m88k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
     mac68k:OpenBSD:*:*)
 	echo m68k-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
@@ -221,28 +227,33 @@
     mvmeppc:OpenBSD:*:*)
 	echo powerpc-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
-    pegasos:OpenBSD:*:*)
-	echo powerpc-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    pmax:OpenBSD:*:*)
-	echo mipsel-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
     sgi:OpenBSD:*:*)
-	echo mipseb-unknown-openbsd${UNAME_RELEASE}
+	echo mips64-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
     sun3:OpenBSD:*:*)
 	echo m68k-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
-    wgrisc:OpenBSD:*:*)
-	echo mipsel-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
     *:OpenBSD:*:*)
 	echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
+    *:ekkoBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
+	exit 0 ;;
+    macppc:MirBSD:*:*)
+	echo powerppc-unknown-mirbsd${UNAME_RELEASE}
+	exit 0 ;;
+    *:MirBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
+	exit 0 ;;
     alpha:OSF1:*:*)
-	if test $UNAME_RELEASE = "V4.0"; then
+	case $UNAME_RELEASE in
+	*4.0)
 		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
-	fi
+		;;
+	*5.*)
+	        UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+		;;
+	esac
 	# According to Compaq, /usr/sbin/psrinfo has been available on
 	# OSF/1 and Tru64 systems produced since 1995.  I hope that
 	# covers most systems running today.  This code pipes the CPU
@@ -280,14 +291,12 @@
 	    "EV7.9 (21364A)")
 		UNAME_MACHINE="alphaev79" ;;
 	esac
+	# A Pn.n version is a patched version.
 	# A Vn.n version is a released version.
 	# A Tn.n version is a released field test version.
 	# A Xn.n version is an unreleased experimental baselevel.
 	# 1.2 uses "1.2" for uname -r.
-	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-	exit 0 ;;
-    Alpha*:OpenVMS:*:*)
-	echo alpha-hp-vms
+	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
 	exit 0 ;;
     Alpha\ *:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
@@ -405,6 +414,9 @@
     *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
         echo m68k-unknown-mint${UNAME_RELEASE}
         exit 0 ;;
+    m68k:machten:*:*)
+	echo m68k-apple-machten${UNAME_RELEASE}
+	exit 0 ;;
     powerpc:machten:*:*)
 	echo powerpc-apple-machten${UNAME_RELEASE}
 	exit 0 ;;
@@ -740,7 +752,7 @@
 	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
 	exit 0 ;;
     *:UNICOS/mp:*:*)
-	echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
 	exit 0 ;;
     F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
 	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
@@ -763,21 +775,7 @@
 	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
 	exit 0 ;;
     *:FreeBSD:*:*)
-	# Determine whether the default compiler uses glibc.
-	eval $set_cc_for_build
-	sed 's/^	//' << EOF >$dummy.c
-	#include <features.h>
-	#if __GLIBC__ >= 2
-	LIBC=gnu
-	#else
-	LIBC=
-	#endif
-EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
-	# GNU/KFreeBSD systems have a "k" prefix to indicate we are using
-	# FreeBSD's kernel, but not the complete OS.
-	case ${LIBC} in gnu) kernel_only='k' ;; esac
-	echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC}
+	echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
 	exit 0 ;;
     i*:CYGWIN*:*)
 	echo ${UNAME_MACHINE}-pc-cygwin
@@ -829,6 +827,9 @@
     ia64:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	exit 0 ;;
+    m32r*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
     m68*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	exit 0 ;;
@@ -1069,9 +1070,9 @@
     M680?0:D-NIX:5.3:*)
 	echo m68k-diab-dnix
 	exit 0 ;;
-    M68*:*:R3V[567]*:*)
+    M68*:*:R3V[5678]*:*)
 	test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
-    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0)
+    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
 	OS_REL=''
 	test -r /etc/.relid \
 	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
@@ -1169,9 +1170,10 @@
 	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
 	exit 0 ;;
     *:Darwin:*:*)
-	case `uname -p` in
+	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+	case $UNAME_PROCESSOR in
 	    *86) UNAME_PROCESSOR=i686 ;;
-	    powerpc) UNAME_PROCESSOR=powerpc ;;
+	    unknown) UNAME_PROCESSOR=powerpc ;;
 	esac
 	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
 	exit 0 ;;
@@ -1230,9 +1232,16 @@
     SEI:*:*:SEIUX)
         echo mips-sei-seiux${UNAME_RELEASE}
 	exit 0 ;;
-    *:DRAGONFLY:*:*)
-	echo ${UNAME_MACHINE}-unknown-dragonfly${UNAME_RELEASE}
+    *:DragonFly:*:*)
+	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
 	exit 0 ;;
+    *:*VMS:*:*)
+    	UNAME_MACHINE=`(uname -p) 2>/dev/null`
+	case "${UNAME_MACHINE}" in
+	    A*) echo alpha-dec-vms && exit 0 ;;
+	    I*) echo ia64-dec-vms && exit 0 ;;
+	    V*) echo vax-dec-vms && exit 0 ;;
+	esac
 esac
 
 #echo '(No uname command or uname output not recognized.)' 1>&2
Index: libgcrypt/config.sub
diff -u libgcrypt/config.sub:1.2 libgcrypt/config.sub:1.2.2.1
--- libgcrypt/config.sub:1.2	Tue Apr  6 15:24:24 2004
+++ libgcrypt/config.sub	Tue Jan  4 21:50:23 2005
@@ -1,9 +1,9 @@
 #! /bin/sh
 # Configuration validation subroutine script.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+#   2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
-timestamp='2004-01-05'
+timestamp='2004-06-24'
 
 # This file is (in principle) common to ALL GNU software.
 # The presence of a machine in this file suggests that SOME GNU software
@@ -70,7 +70,7 @@
 version="\
 GNU config.sub ($timestamp)
 
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
@@ -145,7 +145,7 @@
 	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
 	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
 	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-	-apple | -axis)
+	-apple | -axis | -knuth | -cray)
 		os=
 		basic_machine=$1
 		;;
@@ -237,7 +237,7 @@
 	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
 	| i370 | i860 | i960 | ia64 \
 	| ip2k | iq2000 \
-	| m32r | m68000 | m68k | m88k | mcore \
+	| m32r | m32rle | m68000 | m68k | m88k | mcore \
 	| mips | mipsbe | mipseb | mipsel | mipsle \
 	| mips16 \
 	| mips64 | mips64el \
@@ -262,7 +262,7 @@
 	| pyramid \
 	| sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
 	| sh64 | sh64le \
-	| sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \
+	| sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv8 | sparcv9 | sparcv9b \
 	| strongarm \
 	| tahoe | thumb | tic4x | tic80 | tron \
 	| v850 | v850e \
@@ -300,7 +300,7 @@
 	| avr-* \
 	| bs2000-* \
 	| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
-	| clipper-* | cydra-* \
+	| clipper-* | craynv-* | cydra-* \
 	| d10v-* | d30v-* | dlx-* \
 	| elxsi-* \
 	| f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \
@@ -308,7 +308,7 @@
 	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
 	| i*86-* | i860-* | i960-* | ia64-* \
 	| ip2k-* | iq2000-* \
-	| m32r-* \
+	| m32r-* | m32rle-* \
 	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
 	| m88110-* | m88k-* | mcore-* \
 	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
@@ -326,8 +326,9 @@
 	| mipsisa64sb1-* | mipsisa64sb1el-* \
 	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
 	| mipstx39-* | mipstx39el-* \
+	| mmix-* \
 	| msp430-* \
-	| none-* | np1-* | nv1-* | ns16k-* | ns32k-* \
+	| none-* | np1-* | ns16k-* | ns32k-* \
 	| orion-* \
 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
 	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
@@ -336,7 +337,7 @@
 	| sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \
 	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
 	| sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \
-	| sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
 	| tahoe-* | thumb-* \
 	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
 	| tron-* \
@@ -363,6 +364,9 @@
 		basic_machine=a29k-amd
 		os=-udi
 		;;
+    	abacus)
+		basic_machine=abacus-unknown
+		;;
 	adobe68k)
 		basic_machine=m68010-adobe
 		os=-scout
@@ -442,12 +446,24 @@
 		basic_machine=j90-cray
 		os=-unicos
 		;;
+	craynv)
+		basic_machine=craynv-cray
+		os=-unicosmp
+		;;
+	cr16c)
+		basic_machine=cr16c-unknown
+		os=-elf
+		;;
 	crds | unos)
 		basic_machine=m68k-crds
 		;;
 	cris | cris-* | etrax*)
 		basic_machine=cris-axis
 		;;
+	crx)
+		basic_machine=crx-unknown
+		os=-elf
+		;;
 	da30 | da30-*)
 		basic_machine=m68k-da30
 		;;
@@ -648,10 +664,6 @@
 	mips3*)
 		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
 		;;
-	mmix*)
-		basic_machine=mmix-knuth
-		os=-mmixware
-		;;
 	monitor)
 		basic_machine=m68k-rom68k
 		os=-coff
@@ -732,10 +744,6 @@
 	np1)
 		basic_machine=np1-gould
 		;;
-	nv1)
-		basic_machine=nv1-cray
-		os=-unicosmp
-		;;
 	nsr-tandem)
 		basic_machine=nsr-tandem
 		;;
@@ -1048,6 +1056,9 @@
 	romp)
 		basic_machine=romp-ibm
 		;;
+	mmix)
+		basic_machine=mmix-knuth
+		;;
 	rs6000)
 		basic_machine=rs6000-ibm
 		;;
@@ -1070,7 +1081,7 @@
 	sh64)
 		basic_machine=sh64-unknown
 		;;
-	sparc | sparcv9 | sparcv9b)
+	sparc | sparcv8 | sparcv9 | sparcv9b)
 		basic_machine=sparc-sun
 		;;
 	cydra)
@@ -1143,8 +1154,9 @@
 	      | -aos* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
-	      | -hiux* | -386bsd* | -knetbsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \
-	      | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* | -openbsd* \
+	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
 	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
 	      | -chorusos* | -chorusrdb* \
@@ -1362,6 +1374,9 @@
 	*-ibm)
 		os=-aix
 		;;
+    	*-knuth)
+		os=-mmixware
+		;;
 	*-wec)
 		os=-proelf
 		;;
Index: libgcrypt/depcomp
diff -u libgcrypt/depcomp:1.1 libgcrypt/depcomp:1.1.2.1
--- libgcrypt/depcomp:1.1	Mon Dec  8 22:42:35 2003
+++ libgcrypt/depcomp	Tue Jan  4 21:50:23 2005
@@ -1,7 +1,9 @@
 #! /bin/sh
-
 # depcomp - compile a program generating dependencies as side-effects
-# Copyright 1999, 2000 Free Software Foundation, Inc.
+
+scriptversion=2004-05-31.23
+
+# Copyright (C) 1999, 2000, 2003, 2004 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
@@ -25,22 +27,45 @@
 
 # Originally written by Alexandre Oliva <oliva at dcc.unicamp.br>.
 
+case $1 in
+  '')
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: depcomp [--help] [--version] PROGRAM [ARGS]
+
+Run PROGRAMS ARGS to compile a file, generating dependencies
+as side-effects.
+
+Environment variables:
+  depmode     Dependency tracking mode.
+  source      Source file read by `PROGRAMS ARGS'.
+  object      Object file output by `PROGRAMS ARGS'.
+  DEPDIR      directory where to store dependencies.
+  depfile     Dependency file to output.
+  tmpdepfile  Temporary file to use when outputing dependencies.
+  libtool     Whether libtool is used (yes/no).
+
+Report bugs to <bug-automake at gnu.org>.
+EOF
+    exit 0
+    ;;
+  -v | --v*)
+    echo "depcomp $scriptversion"
+    exit 0
+    ;;
+esac
+
 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
   echo "depcomp: Variables source, object and depmode must be set" 1>&2
   exit 1
 fi
-# `libtool' can also be set to `yes' or `no'.
-
-if test -z "$depfile"; then
-   base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'`
-   dir=`echo "$object" | sed 's,/.*$,/,'`
-   if test "$dir" = "$object"; then
-      dir=
-   fi
-   # FIXME: should be _deps on DOS.
-   depfile="$dir.deps/$base"
-fi
 
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
+depfile=${depfile-`echo "$object" |
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
 
 rm -f "$tmpdepfile"
@@ -172,19 +197,25 @@
 
 aix)
   # The C for AIX Compiler uses -M and outputs the dependencies
-  # in a .u file.  This file always lives in the current directory.
-  # Also, the AIX compiler puts `$object:' at the start of each line;
-  # $object doesn't have directory information.
-  stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'`
+  # in a .u file.  In older versions, this file always lives in the
+  # current directory.  Also, the AIX compiler puts `$object:' at the
+  # start of each line; $object doesn't have directory information.
+  # Version 6 uses the directory in both cases.
+  stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
   tmpdepfile="$stripped.u"
-  outname="$stripped.o"
   if test "$libtool" = yes; then
     "$@" -Wc,-M
   else
     "$@" -M
   fi
-
   stat=$?
+
+  if test -f "$tmpdepfile"; then :
+  else
+    stripped=`echo "$stripped" | sed 's,^.*/,,'`
+    tmpdepfile="$stripped.u"
+  fi
+
   if test $stat -eq 0; then :
   else
     rm -f "$tmpdepfile"
@@ -192,6 +223,7 @@
   fi
 
   if test -f "$tmpdepfile"; then
+    outname="$stripped.o"
     # Each line is of the form `foo.o: dependent.h'.
     # Do two passes, one to just change these to
     # `$object: dependent.h' and one to simply `dependent.h:'.
@@ -255,31 +287,40 @@
    base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
 
    if test "$libtool" = yes; then
+      # Dependencies are output in .lo.d with libtool 1.4.
+      # With libtool 1.5 they are output both in $dir.libs/$base.o.d
+      # and in $dir.libs/$base.o.d and $dir$base.o.d.  We process the
+      # latter, because the former will be cleaned when $dir.libs is
+      # erased.
       tmpdepfile1="$dir.libs/$base.lo.d"
-      tmpdepfile2="$dir.libs/$base.d"
+      tmpdepfile2="$dir$base.o.d"
+      tmpdepfile3="$dir.libs/$base.d"
       "$@" -Wc,-MD
    else
       tmpdepfile1="$dir$base.o.d"
       tmpdepfile2="$dir$base.d"
+      tmpdepfile3="$dir$base.d"
       "$@" -MD
    fi
 
    stat=$?
    if test $stat -eq 0; then :
    else
-      rm -f "$tmpdepfile1" "$tmpdepfile2"
+      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
       exit $stat
    fi
 
    if test -f "$tmpdepfile1"; then
       tmpdepfile="$tmpdepfile1"
-   else
+   elif test -f "$tmpdepfile2"; then
       tmpdepfile="$tmpdepfile2"
+   else
+      tmpdepfile="$tmpdepfile3"
    fi
    if test -f "$tmpdepfile"; then
       sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
-      # That's a space and a tab in the [].
-      sed -e 's,^.*\.[a-z]*:[ 	]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
+      # That's a tab and a space in the [].
+      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
    else
       echo "#dummy" > "$depfile"
    fi
@@ -292,7 +333,7 @@
 
 dashmstdout)
   # Important note: in order to support this mode, a compiler *must*
-  # always write the proprocessed file to stdout, regardless of -o.
+  # always write the preprocessed file to stdout, regardless of -o.
   "$@" || exit $?
 
   # Remove the call to Libtool.
@@ -388,7 +429,7 @@
 
 cpp)
   # Important note: in order to support this mode, a compiler *must*
-  # always write the proprocessed file to stdout.
+  # always write the preprocessed file to stdout.
   "$@" || exit $?
 
   # Remove the call to Libtool.
@@ -430,7 +471,7 @@
 
 msvisualcpp)
   # Important note: in order to support this mode, a compiler *must*
-  # always write the proprocessed file to stdout, regardless of -o,
+  # always write the preprocessed file to stdout, regardless of -o,
   # because we must use -o when running libtool.
   "$@" || exit $?
   IFS=" "
@@ -470,3 +511,12 @@
 esac
 
 exit 0
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:
Index: libgcrypt/doc/ChangeLog
diff -u libgcrypt/doc/ChangeLog:1.38.2.2 libgcrypt/doc/ChangeLog:1.38.2.3
--- libgcrypt/doc/ChangeLog:1.38.2.2	Tue Jan  4 21:13:48 2005
+++ libgcrypt/doc/ChangeLog	Tue Jan  4 21:50:23 2005
@@ -1,7 +1,13 @@
 2005-01-04  Werner Koch  <wk at g10code.com>
 
 	* gcrypt.texi: Updated to use @copying.  Fixed list of copyright
-	years; we had real changes in 2004.
+	years; we had real changes in 2004.  Fixed some formatting issues.
+
+	Merged in changes from the devel branch by Moritz Schulte:
+	
+	* gcrypt.texi (Miscellaneous): Document gcry_mpi_randomize.
+	(Multi Threading): Document GCRY_THREAD_OPTION_PTH_IMPL,
+	GCRY_THREAD_OPTION_PTHREAD_IMPL.
 
 2004-05-07  Moritz Schulte  <moritz at g10code.de>
 
Index: libgcrypt/doc/gcrypt.texi
diff -u libgcrypt/doc/gcrypt.texi:1.38.2.2 libgcrypt/doc/gcrypt.texi:1.38.2.3
--- libgcrypt/doc/gcrypt.texi:1.38.2.2	Tue Jan  4 21:13:48 2005
+++ libgcrypt/doc/gcrypt.texi	Tue Jan  4 21:50:23 2005
@@ -39,7 +39,7 @@
 @subtitle Version @value{VERSION}
 @subtitle @value{UPDATED}
 @author Werner Koch (@email{wk@@gnupg.org})
- at author Moritz Schulte (@email{mo at g10code.com})
+ at author Moritz Schulte (@email{mo@@g10code.com})
 
 @page
 @vskip 0pt plus 1filll
@@ -64,7 +64,7 @@
 * Preparation::                  What you should do before using the library.
 * Generalities::                 General library functions and data types.
 * Handler Functions::            Working with handler functions.
-* Symmetric cryptography::       How to use symmetric crytography.
+* Symmetric cryptography::       How to use symmetric cryptography.
 * Hashing::                      How to use hashing.
 * Public Key cryptography (I)::  How to use public key cryptography.
 * Public Key cryptography (II):: How to use public key cryptography, alternatively.
@@ -96,12 +96,12 @@
 Preparation
 * Header::                              What header file you need to include.
 * Building sources::                    How to build sources using the library.
-* Building sources using Automake::     How to build sources with the help auf Automake.
+* Building sources using Automake::     How to build sources with the help of Automake.
 * Initializing the library::            How to initialize the library.
 * Multi Threading::                     How @acronym{Libgcrypt} can be used in a MT environment.
 
 Generalities
-* Controlling the library::     Controlling @acronym{Libgcrypt}'s behaviour.
+* Controlling the library::     Controlling @acronym{Libgcrypt}'s behavior.
 * Modules::                     Description of extension modules.
 * Error Handling::              Error codes and such.
 
@@ -153,7 +153,7 @@
 * Calculations::                Performing MPI calculations.
 * Comparisons::                 How to compare MPI values.
 * Bit manipulations::           How to access single bits of MPI values.
-* Misc::                        Miscellaneous MPI functions.
+* Miscellaneous::               Miscellaneous MPI functions.
 
 Utilities
 * Memory allocation::           Functions related with memory allocation.
@@ -219,16 +219,16 @@
 
 @end table
 
-
 @node Overview
 @section Overview
 
+ at noindent
 The `@acronym{Libgcrypt}' library is fully thread-safe, where it makes
 sense to be thread-safe.  An exception for thread-safety are some
 cryptographic functions that modify a certain context stored in
 handles.  If the user really intents to use such functions from
 different threads on the same handle, he has to take care of the
-serialisation of such functions himself.  If not described otherwise,
+serialization of such functions himself.  If not described otherwise,
 every function is thread-safe.
 
 @acronym{Libgcrypt} depends on the library `libgpg-error', which
@@ -249,7 +249,7 @@
 @menu
 * Header::                      What header file you need to include.
 * Building sources::            How to build sources using the library.
-* Building sources using Automake::  How to build sources with the help auf Automake.
+* Building sources using Automake::  How to build sources with the help of Automake.
 * Initializing the library::    How to initialize the library.
 * Multi Threading::             How @acronym{Libgcrypt} can be used in a MT environment.
 @end menu
@@ -390,24 +390,24 @@
 @strong{before} any other function in the library.
 
 This is easy enough if you are indeed writing an application using
-libgcrypt.  It is rather problematic if you are writing a library
+Libgcrypt.  It is rather problematic if you are writing a library
 instead.  Here are some tips what to do if you are writing a library:
 
 If your library requires a certain thread package, just initialize
-gcrypt to use this thread package.  If your library supports multiple
+Libgcrypt to use this thread package.  If your library supports multiple
 thread packages, but needs to be configured, you will have to
 implement a way to determine which thread package the application
-wants to use with your library anyway.  Then configure gcrypt to use
+wants to use with your library anyway.  Then configure Libgcrypt to use
 this thread package.
 
 If your library is fully reentrant without any special support by a
 thread package, then you are lucky indeed.  Unfortunately, this does
 not relieve you from doing either of the two above, or use a third
-option.  The third option is to let the application initialize gcrypt
-for you.  Then you are not using gcrypt transparently, though.
+option.  The third option is to let the application initialize Libgcrypt
+for you.  Then you are not using Libgcrypt transparently, though.
 
 As if this was not difficult enough, a conflict may arise if two
-libraries try to initialize gcrypt independently of each others, and
+libraries try to initialize Libgcrypt independently of each others, and
 both such libraries are then linked into the same application.  To
 make it a bit simpler for you, this will probably work, but only if
 both libraries have the same requirement for the thread package.  This
@@ -418,7 +418,7 @@
 @item
 The function @code{gcry_check_version} must be called before any other
 function in the library, except the @code{GCRYCTL_SET_THREAD_CBS}
-command (called via the @code{gcry_control} function0, because it
+command (called via the @code{gcry_control} function), because it
 initializes the thread support subsystem in @acronym{Libgcrypt}.  To
 achieve this in multi-threaded programs, you must synchronize the
 memory with respect to other threads that also want to use
@@ -433,11 +433,42 @@
 strict rules may apply.}.
 
 @item
+
 As with the function @code{gpg_strerror}, @code{gcry_strerror} is not
 thread safe.  You have to use @code{gpg_strerror_r} instead.
 @end itemize
 
 
+ at acronym{Libgcrypt} contains convenient macros, which define the
+necessary thread callbacks for PThread and for GNU Pth:
+
+ at table @code
+ at item GCRY_THREAD_OPTION_PTH_IMPL
+
+This macro defines the following (static) symbols: gcry_pth_init,
+gcry_pth_mutex_init, gcry_pth_mutex_destroy, gcry_pth_mutex_lock,
+gcry_pth_mutex_unlock, gcry_pth_read, gcry_pth_write, gcry_pth_select,
+gcry_pth_waitpid, gcry_pth_accept, gcry_pth_connect, gcry_threads_pth.
+
+After including this macro, gcry_control() shall be used with a
+command of GCRYCTL_SET_THREAD_CBS in order to register the thread
+callback structure named ``gcry_threads_pth''.
+
+ at item GCRY_THREAD_OPTION_PTHREAD_IMPL
+
+This macro defines the following (static) symbols:
+gcry_pthread_mutex_init, gcry_pthread_mutex_destroy, gcry_mutex_lock,
+gcry_mutex_unlock, gcry_threads_pthread.
+
+After including this macro, gcry_control() shall be used with a
+command of GCRYCTL_SET_THREAD_CBS in order to register the thread
+callback structure named ``gcry_threads_pthread''.
+ at end table
+
+Note that these macros need to be terminated with a semicolon.  Keep
+in mind that these are convenient macros for C programmers; C++
+programmers might have to wrap these macros in an ``extern C'' body.
+
 @c **********************************************************
 @c *******************  General  ****************************
 @c **********************************************************
@@ -445,7 +476,7 @@
 @chapter Generalities
 
 @menu
-* Controlling the library::     Controlling @acronym{Libgcrypt}'s behaviour.
+* Controlling the library::     Controlling @acronym{Libgcrypt}'s behavior.
 * Modules::                     Description of extension modules.
 * Error Handling::              Error codes and such.
 @end menu
@@ -455,7 +486,7 @@
 
 @deftypefun gcry_error_t gcry_control (enum gcry_ctl_cmds @var{cmd}, ...)
 
-This function can be used to influence the general behaviour of
+This function can be used to influence the general behavior of
 @acronym{Libgcrypt} in several ways.  Depending on @var{cmd}, more
 arguments can or have to be provided.
 
@@ -476,7 +507,7 @@
 specification structure' as input and return a value of
 @code{gcry_module_t} and an ID that is unique in the modules'
 category.  This ID can be used to reference the newly registered
-module.  After registering a module successfuly, the new functionality
+module.  After registering a module successfully, the new functionality
 should be able to be used through the normal functions provided by
 @acronym{Libgcrypt} until it is unregistered again.
 
@@ -524,7 +555,7 @@
 Some error values do not indicate a system error or an error in the
 operation, but the result of an operation that failed properly.
 
-GnuPG components, including libgcrypt, use an extra library named
+GnuPG components, including Libgcrypt, use an extra library named
 libgpg-error to provide a common error handling scheme.  For more
 information on libgpg-error, see the according manual.
 
@@ -575,7 +606,7 @@
 the error value are set to 0, too.
 
 Note that in @acronym{Libgcrypt}, the error source is used purely for
-diagnostical purposes.  Only the error code should be checked to test
+diagnostic purposes.  Only the error code should be checked to test
 for a certain outcome of a function.  The manual only documents the
 error code part of an error value.  The error source is left
 unspecified and might be anything.
@@ -621,7 +652,7 @@
 error numbers it knows about.  If @var{err} is an unknown error
 number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used.  The
 following functions can be used to construct error values from system
-errnor numbers.
+errno numbers.
 
 @deftypefun {gcry_error_t} gcry_err_make_from_errno (@w{gcry_err_source_t @var{source}}, @w{int @var{err}})
 The function @code{gcry_err_make_from_errno} is like
@@ -1222,8 +1253,7 @@
 To use a cipher algorithm, you must first allocate an according
 handle.  This is to be done using the open function:
 
- at deftypefun gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *@var{hd},
-int @var{algo}, int @var{mode}, unsigned int @var{flags})
+ at deftypefun gcry_error_t gcry_cipher_open (gcry_cipher_hd_t *@var{hd}, int @var{algo}, int @var{mode}, unsigned int @var{flags})
 
 This function creates the context handle required for most of the
 other cipher functions and returns a handle to it in `hd'.  In case of
@@ -1698,8 +1728,7 @@
 If the flag @code{GCRY_MD_FLAG_HMAC} was used, the key for the MAC must
 be set using the function:
 
- at deftypefun gcry_error_t gcry_md_setkey (gcry_md_hd_t @var{h}, const void *@var{key},
-size_t @var{keylen})
+ at deftypefun gcry_error_t gcry_md_setkey (gcry_md_hd_t @var{h}, const void *@var{key}, size_t @var{keylen})
 
 For use with the HMAC feature, set the MAC key to the value of @var{key}
 of length @var{keylen}.
@@ -2181,10 +2210,13 @@
 @node Cryptographic Functions
 @section Cryptographic Functions
 
+ at noindent
 Note, that we will in future allow to use keys without p,q and u
 specified and may also support other parameters for performance
 reasons. 
 
+ at noindent
+
 Some functions operating on S-expressions support `flags', that
 influence the operation.  These flags have to be listed in a
 sub-S-expression named `flags'; the following flags are known:
@@ -2697,8 +2729,7 @@
 Destroys the data set @var{data}.
 @end deftypefun
 
- at deftypefun gcry_error_t gcry_ac_data_set (gcry_ac_data_t @var{data},
-unsigned int @var{flags}, char *@var{name}, gcry_mpi_t @var{mpi})
+ at deftypefun gcry_error_t gcry_ac_data_set (gcry_ac_data_t @var{data}, unsigned int @var{flags}, char *@var{name}, gcry_mpi_t @var{mpi})
 Add the value @var{mpi} to @var{data} with the label @var{name}.  If
 @var{flags} contains GCRY_AC_FLAG_DATA_COPY, the data set will contain
 copies of @var{name} and @var{mpi}.  If @var{flags} contains
@@ -2716,16 +2747,13 @@
 @var{data}.
 @end deftypefun
 
- at deftypefun gcry_error_t gcry_ac_data_get_name (gcry_ac_data_t @var{data},
-unsigned int @var{flags}, char *@var{name}, gcry_mpi_t *@var{mpi})
+ at deftypefun gcry_error_t gcry_ac_data_get_name (gcry_ac_data_t @var{data}, unsigned int @var{flags}, char *@var{name}, gcry_mpi_t *@var{mpi})
 Store the value labelled with @var{name} found in @var{data} in
 @var{mpi}.  If @var{flags} contains GCRY_AC_FLAG_COPY, store a copy of
 the @var{mpi} value contained in the data set.  @var{mpi} may be NULL.
 @end deftypefun
 
- at deftypefun gcry_error_t gcry_ac_data_get_index (gcry_ac_data_t @var{data},
-unsigned int flags, unsigned int @var{index},
-const char **@var{name}, gcry_mpi_t *@var{mpi})
+ at deftypefun gcry_error_t gcry_ac_data_get_index (gcry_ac_data_t @var{data}, unsigned int flags, unsigned int @var{index}, const char **@var{name}, gcry_mpi_t *@var{mpi})
 Stores in @var{name} and @var{mpi} the named @var{mpi} value contained
 in the data set @var{data} with the index @var{idx}.  If @var{flags}
 contains GCRY_AC_FLAG_COPY, store copies of the values contained in
@@ -2742,8 +2770,7 @@
 In order to use an algorithm, an according handle must be created.
 This is done using the following function:
 
- at deftypefun gcry_error_t gcry_ac_open (gcry_ac_handle_t *@var{handle},
-int @var{algorithm}, int @var{flags})
+ at deftypefun gcry_error_t gcry_ac_open (gcry_ac_handle_t *@var{handle}, int @var{algorithm}, int @var{flags})
 
 Creates a new handle for the algorithm @var{algorithm} and stores it
 in @var{handle}.  @var{flags} is not used yet.
@@ -2791,9 +2818,7 @@
 contained in the data set @var{data} and stores it in @var{key}.
 @end deftypefun
 
- at deftypefun gcry_error_t gcry_ac_key_pair_generate (gcry_ac_handle_t @var{handle},
-unsigned int @var{nbits}, void *@var{key_spec}, gcry_ac_key_pair_t *@var{key_pair},
-gcry_mpi_t **@var{misc_data})
+ at deftypefun gcry_error_t gcry_ac_key_pair_generate (gcry_ac_handle_t @var{handle}, unsigned int @var{nbits}, void *@var{key_spec}, gcry_ac_key_pair_t *@var{key_pair}, gcry_mpi_t **@var{misc_data})
 
 Generates a new key pair via the handle @var{handle} of @var{NBITS}
 bits and stores it in @var{key_pair}.
@@ -2866,13 +2891,11 @@
 Verifies that the private key @var{key} is sane via @var{handle}.
 @end deftypefun
 
- at deftypefun gcry_error_t gcry_ac_key_get_nbits (gcry_ac_handle_t @var{handle},
-gcry_ac_key_t @var{key}, unsigned int *@var{nbits})
+ at deftypefun gcry_error_t gcry_ac_key_get_nbits (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, unsigned int *@var{nbits})
 Stores the number of bits of the key @var{key} in @var{nbits} via @var{handle}.
 @end deftypefun
 
- at deftypefun gcry_error_t gcry_ac_key_get_grip (gcry_ac_handle_t @var{handle},
-gcry_ac_key_t @var{key}, unsigned char *@var{key_grip})
+ at deftypefun gcry_error_t gcry_ac_key_get_grip (gcry_ac_handle_t @var{handle}, gcry_ac_key_t @var{key}, unsigned char *@var{key_grip})
 Writes the 20 byte long key grip of the key @var{key} to
 @var{key_grip} via @var{handle}.
 @end deftypefun
@@ -3248,7 +3271,7 @@
 * Calculations::                Performing MPI calculations.
 * Comparisons::                 How to compare MPI values.
 * Bit manipulations::           How to access single bits of MPI values.
-* Misc::                        Misc, fixme.
+* Miscellaneous::               Miscellaneous MPI functions.
 @end menu
 
 Public key cryptography is based on mathematics with large numbers.  To
@@ -3559,19 +3582,15 @@
 result in @var{x}.
 @end deftypefun
 
- at node Misc
- at section Misc
-
- at noindent
-The remaining MPI functions take care of very special properties of the
-implementation:
+ at node Miscellaneous
+ at section Miscellanous
 
 @deftypefun gcry_mpi_t gcry_mpi_set_opaque (@w{gcry_mpi_t @var{a}}, @w{void *@var{p}}, @w{unsigned int @var{nbits}})
 
 Store @var{nbits} of the value @var{p} points to in @var{a} and mark
 @var{a} as an opaque value (i.e. an value that can't be used for any
 math calculation and is only used to store an arbitrary bit pattern in
- at var{a}.
+ at var{a}).
 
 WARNING: Never use an opaque MPI for actual math operations.  The only
 valid functions are gcry_mpi_get_opaque and gcry_mpi_release.  Use
@@ -3605,6 +3624,14 @@
 Return true when the @var{flag} is set for @var{a}.
 @end deftypefun
 
+ at deftypefun void gcry_mpi_randomize (@w{gcry_mpi_t @var{w}}, @w{unsigned int @var{nbits}}, @w{enum gcry_random_level @var{level}})
+
+Set the big integer @var{w} to a random value of @var{nbits}, using
+random data quality of level @var{level}.  In case @var{nbits} is not
+a multiple of a byte, @var{nbits} is rounded up to the next byte
+boundary.
+ at end deftypefun
+
 @node Utilities
 @chapter Utilities
 
@@ -3724,3 +3751,6 @@
 
 @c  LocalWords:  int HD
 
+
+
+
Index: libgcrypt/doc/mdate-sh
diff -u libgcrypt/doc/mdate-sh:1.1 libgcrypt/doc/mdate-sh:1.1.2.1
--- libgcrypt/doc/mdate-sh:1.1	Mon Dec  8 22:42:34 2003
+++ libgcrypt/doc/mdate-sh	Tue Jan  4 21:50:23 2005
@@ -1,5 +1,8 @@
 #!/bin/sh
 # Get modification time of a file or directory and pretty-print it.
+
+scriptversion=2003-11-09.00
+
 # Copyright (C) 1995, 1996, 1997, 2003  Free Software Foundation, Inc.
 # written by Ulrich Drepper <drepper at gnu.ai.mit.edu>, June 1995
 #
@@ -22,6 +25,31 @@
 # configuration script generated by Autoconf, you may include it under
 # the same distribution terms that you use for the rest of that program.
 
+# This file is maintained in Automake, please report
+# bugs to <bug-automake at gnu.org> or send patches to
+# <automake-patches at gnu.org>.
+
+case $1 in
+  '')
+     echo "$0: No file.  Try \`$0 --help' for more information." 1>&2
+     exit 1;
+     ;;
+  -h | --h*)
+    cat <<\EOF
+Usage: mdate-sh [--help] [--version] FILE
+
+Pretty-print the modification time of FILE.
+
+Report bugs to <bug-automake at gnu.org>.
+EOF
+    exit 0
+    ;;
+  -v | --v*)
+    echo "mdate-sh $scriptversion"
+    exit 0
+    ;;
+esac
+
 # Prevent date giving response in another language.
 LANG=C
 export LANG
@@ -131,3 +159,12 @@
 
 # The result.
 echo $day $month $year
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:
Index: libgcrypt/doc/texinfo.tex
diff -u libgcrypt/doc/texinfo.tex:1.1 libgcrypt/doc/texinfo.tex:1.1.2.1
--- libgcrypt/doc/texinfo.tex:1.1	Mon Dec  8 22:42:34 2003
+++ libgcrypt/doc/texinfo.tex	Tue Jan  4 21:50:23 2005
@@ -3,10 +3,11 @@
 % Load plain if necessary, i.e., if running under initex.
 \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
 %
-\def\texinfoversion{2003-05-04.08}
+\def\texinfoversion{2004-10-31.06}
 %
 % Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
-% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
+% Foundation, Inc.
 %
 % This texinfo.tex file is free software; you can redistribute it and/or
 % modify it under the terms of the GNU General Public License as
@@ -23,21 +24,16 @@
 % to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 % Boston, MA 02111-1307, USA.
 %
-% In other words, you are welcome to use, share and improve this program.
-% You are forbidden to forbid anyone else to use, share and improve
-% what you give them.   Help stamp out software-hoarding!
+% As a special exception, when this file is read by TeX when processing
+% a Texinfo source document, you may use the result without
+% restriction.  (This has been our intent since Texinfo was invented.)
 %
 % Please try the latest version of texinfo.tex before submitting bug
 % reports; you can get the latest version from:
-%   ftp://ftp.gnu.org/gnu/texinfo/texinfo.tex
-%     (and all GNU mirrors, see http://www.gnu.org/order/ftp.html)
+%   http://www.gnu.org/software/texinfo/ (the Texinfo home page), or
 %   ftp://tug.org/tex/texinfo.tex
-%     (and all CTAN mirrors, see http://www.ctan.org),
-%   and /home/gd/gnu/doc/texinfo.tex on the GNU machines.
-%
-% The GNU Texinfo home page is http://www.gnu.org/software/texinfo.
-%
-% The texinfo.tex in any given Texinfo distribution could well be out
+%     (and all CTAN mirrors, see http://www.ctan.org).
+% The texinfo.tex in any given distribution could well be out
 % of date, so if that's what you're using, please check.
 %
 % Send bug reports to bug-texinfo at gnu.org.  Please include including a
@@ -59,6 +55,9 @@
 % It is possible to adapt texinfo.tex for other languages, to some
 % extent.  You can get the existing language-specific files from the
 % full Texinfo distribution.
+%
+% The GNU Texinfo home page is http://www.gnu.org/software/texinfo.
+
 
 \message{Loading texinfo [version \texinfoversion]:}
 
@@ -85,10 +84,13 @@
 \let\ptexend=\end
 \let\ptexequiv=\equiv
 \let\ptexexclam=\!
+\let\ptexfootnote=\footnote
 \let\ptexgtr=>
 \let\ptexhat=^
 \let\ptexi=\i
 \let\ptexindent=\indent
+\let\ptexnoindent=\noindent
+\let\ptexinsert=\insert
 \let\ptexlbrace=\{
 \let\ptexless=<
 \let\ptexplus=+
@@ -101,6 +103,15 @@
 % starts a new line in the output.
 \newlinechar = `^^J
 
+% Use TeX 3.0's \inputlineno to get the line number, for better error
+% messages, but if we're using an old version of TeX, don't do anything.
+%
+\ifx\inputlineno\thisisundefined
+  \let\linenumber = \empty % Pre-3.0.
+\else
+  \def\linenumber{l.\the\inputlineno:\space}
+\fi
+
 % Set up fixed words for English if not already set.
 \ifx\putwordAppendix\undefined  \gdef\putwordAppendix{Appendix}\fi
 \ifx\putwordChapter\undefined   \gdef\putwordChapter{Chapter}\fi
@@ -139,43 +150,81 @@
 \ifx\putwordDefspec\undefined   \gdef\putwordDefspec{Special Form}\fi
 \ifx\putwordDefvar\undefined    \gdef\putwordDefvar{Variable}\fi
 \ifx\putwordDefopt\undefined    \gdef\putwordDefopt{User Option}\fi
-\ifx\putwordDeftypevar\undefined\gdef\putwordDeftypevar{Variable}\fi
 \ifx\putwordDeffunc\undefined   \gdef\putwordDeffunc{Function}\fi
-\ifx\putwordDeftypefun\undefined\gdef\putwordDeftypefun{Function}\fi
 
 % In some macros, we cannot use the `\? notation---the left quote is
 % in some cases the escape char.
 \chardef\colonChar = `\:
 \chardef\commaChar = `\,
 \chardef\dotChar   = `\.
-\chardef\equalChar = `\=
 \chardef\exclamChar= `\!
 \chardef\questChar = `\?
 \chardef\semiChar  = `\;
-\chardef\spaceChar = `\ %
 \chardef\underChar = `\_
 
+\chardef\spaceChar = `\ %
+\chardef\spacecat = 10
+\def\spaceisspace{\catcode\spaceChar=\spacecat}
+
 % Ignore a token.
 %
 \def\gobble#1{}
 
-% True if #1 is the empty string, i.e., called like `\ifempty{}'.
-%
-\def\ifempty#1{\ifemptyx #1\emptymarkA\emptymarkB}%
-\def\ifemptyx#1#2\emptymarkB{\ifx #1\emptymarkA}%
+% The following is used inside several \edef's.
+\def\makecsname#1{\expandafter\noexpand\csname#1\endcsname}
 
 % Hyphenation fixes.
-\hyphenation{ap-pen-dix}
-\hyphenation{eshell}
-\hyphenation{mini-buf-fer mini-buf-fers}
-\hyphenation{time-stamp}
-\hyphenation{white-space}
+\hyphenation{
+  Flor-i-da Ghost-script Ghost-view Mac-OS Post-Script
+  ap-pen-dix bit-map bit-maps
+  data-base data-bases eshell fall-ing half-way long-est man-u-script
+  man-u-scripts mini-buf-fer mini-buf-fers over-view par-a-digm
+  par-a-digms rath-er rec-tan-gu-lar ro-bot-ics se-vere-ly set-up spa-ces
+  spell-ing spell-ings
+  stand-alone strong-est time-stamp time-stamps which-ever white-space
+  wide-spread wrap-around
+}
 
 % Margin to add to right of even pages, to left of odd pages.
 \newdimen\bindingoffset
 \newdimen\normaloffset
 \newdimen\pagewidth \newdimen\pageheight
 
+% For a final copy, take out the rectangles
+% that mark overfull boxes (in case you have decided
+% that the text looks ok even though it passes the margin).
+%
+\def\finalout{\overfullrule=0pt}
+
+% @| inserts a changebar to the left of the current line.  It should
+% surround any changed text.  This approach does *not* work if the
+% change spans more than two lines of output.  To handle that, we would
+% have adopt a much more difficult approach (putting marks into the main
+% vertical list for the beginning and end of each change).
+%
+\def\|{%
+  % \vadjust can only be used in horizontal mode.
+  \leavevmode
+  %
+  % Append this vertical mode material after the current line in the output.
+  \vadjust{%
+    % We want to insert a rule with the height and depth of the current
+    % leading; that is exactly what \strutbox is supposed to record.
+    \vskip-\baselineskip
+    %
+    % \vadjust-items are inserted at the left edge of the type.  So
+    % the \llap here moves out into the left-hand margin.
+    \llap{%
+      %
+      % For a thicker or thinner bar, change the `1pt'.
+      \vrule height\baselineskip width1pt
+      %
+      % This is the space between the bar and the text.
+      \hskip 12pt
+    }%
+  }%
+}
+
 % Sometimes it is convenient to have everything in the transcript file
 % and nothing on the terminal.  We don't just call \tracingall here,
 % since that produces some useless output on the terminal.  We also make
@@ -200,7 +249,7 @@
     \tracingassigns1
   \fi
   \tracingcommands3  % 3 gives us more in etex
-  \errorcontextlines\maxdimen
+  \errorcontextlines16
 }%
 
 % add check for \lastpenalty to plain's definitions.  If the last thing
@@ -258,7 +307,7 @@
                    % the page break happens to be in the middle of an example.
     \shipout\vbox{%
       % Do this early so pdf references go to the beginning of the page.
-      \ifpdfmakepagedest \pdfmkdest{\the\pageno} \fi
+      \ifpdfmakepagedest \pdfdest name{\the\pageno} xyz\fi
       %
       \ifcropmarks \vbox to \outervsize\bgroup
         \hsize = \outerhsize
@@ -339,132 +388,162 @@
 % the input line (except we remove a trailing comment).  #1 should be a
 % macro which expects an ordinary undelimited TeX argument.
 %
-\def\parsearg#1{%
-  \let\next = #1%
+\def\parsearg{\parseargusing{}}
+\def\parseargusing#1#2{%
+  \def\next{#2}%
   \begingroup
     \obeylines
-    \futurelet\temp\parseargx
-}
-
-% If the next token is an obeyed space (from an @example environment or
-% the like), remove it and recurse.  Otherwise, we're done.
-\def\parseargx{%
-  % \obeyedspace is defined far below, after the definition of \sepspaces.
-  \ifx\obeyedspace\temp
-    \expandafter\parseargdiscardspace
-  \else
-    \expandafter\parseargline
-  \fi
+    \spaceisspace
+    #1%
+    \parseargline\empty% Insert the \empty token, see \finishparsearg below.
 }
 
-% Remove a single space (as the delimiter token to the macro call).
-{\obeyspaces %
- \gdef\parseargdiscardspace {\futurelet\temp\parseargx}}
-
 {\obeylines %
   \gdef\parseargline#1^^M{%
     \endgroup % End of the group started in \parsearg.
-    %
-    % First remove any @c comment, then any @comment.
-    % Result of each macro is put in \toks0.
-    \argremovec #1\c\relax %
-    \expandafter\argremovecomment \the\toks0 \comment\relax %
-    %
-    % Call the caller's macro, saved as \next in \parsearg.
-    \expandafter\next\expandafter{\the\toks0}%
+    \argremovecomment #1\comment\ArgTerm%
   }%
 }
 
-% Since all \c{,omment} does is throw away the argument, we can let TeX
-% do that for us.  The \relax here is matched by the \relax in the call
-% in \parseargline; it could be more or less anything, its purpose is
-% just to delimit the argument to the \c.
-\def\argremovec#1\c#2\relax{\toks0 = {#1}}
-\def\argremovecomment#1\comment#2\relax{\toks0 = {#1}}
+% First remove any @comment, then any @c comment.
+\def\argremovecomment#1\comment#2\ArgTerm{\argremovec #1\c\ArgTerm}
+\def\argremovec#1\c#2\ArgTerm{\argcheckspaces#1\^^M\ArgTerm}
 
-% \argremovec{,omment} might leave us with trailing spaces, though; e.g.,
+% Each occurence of `\^^M' or `<space>\^^M' is replaced by a single space.
+%
+% \argremovec might leave us with trailing space, e.g.,
 %    @end itemize  @c foo
-% will have two active spaces as part of the argument with the
-% `itemize'.  Here we remove all active spaces from #1, and assign the
-% result to \toks0.
-%
-% This loses if there are any *other* active characters besides spaces
-% in the argument -- _ ^ +, for example -- since they get expanded.
-% Fortunately, Texinfo does not define any such commands.  (If it ever
-% does, the catcode of the characters in questionwill have to be changed
-% here.)  But this means we cannot call \removeactivespaces as part of
-% \argremovec{,omment}, since @c uses \parsearg, and thus the argument
-% that \parsearg gets might well have any character at all in it.
+% This space token undergoes the same procedure and is eventually removed
+% by \finishparsearg.
 %
-\def\removeactivespaces#1{%
-  \begingroup
-    \ignoreactivespaces
-    \edef\temp{#1}%
-    \global\toks0 = \expandafter{\temp}%
-  \endgroup
+\def\argcheckspaces#1\^^M{\argcheckspacesX#1\^^M \^^M}
+\def\argcheckspacesX#1 \^^M{\argcheckspacesY#1\^^M}
+\def\argcheckspacesY#1\^^M#2\^^M#3\ArgTerm{%
+  \def\temp{#3}%
+  \ifx\temp\empty
+    % We cannot use \next here, as it holds the macro to run;
+    % thus we reuse \temp.
+    \let\temp\finishparsearg
+  \else
+    \let\temp\argcheckspaces
+  \fi
+  % Put the space token in:
+  \temp#1 #3\ArgTerm
 }
 
-% Change the active space to expand to nothing.
+% If a _delimited_ argument is enclosed in braces, they get stripped; so
+% to get _exactly_ the rest of the line, we had to prevent such situation.
+% We prepended an \empty token at the very beginning and we expand it now,
+% just before passing the control to \next.
+% (Similarily, we have to think about #3 of \argcheckspacesY above: it is
+% either the null string, or it ends with \^^M---thus there is no danger
+% that a pair of braces would be stripped.
 %
-\begingroup
-  \obeyspaces
-  \gdef\ignoreactivespaces{\obeyspaces\let =\empty}
-\endgroup
+% But first, we have to remove the trailing space token.
+%
+\def\finishparsearg#1 \ArgTerm{\expandafter\next\expandafter{#1}}
 
+% \parseargdef\foo{...}
+%	is roughly equivalent to
+% \def\foo{\parsearg\Xfoo}
+% \def\Xfoo#1{...}
+%
+% Actually, I use \csname\string\foo\endcsname, ie. \\foo, as it is my
+% favourite TeX trick.  --kasal, 16nov03
 
-\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
+\def\parseargdef#1{%
+  \expandafter \doparseargdef \csname\string#1\endcsname #1%
+}
+\def\doparseargdef#1#2{%
+  \def#2{\parsearg#1}%
+  \def#1##1%
+}
 
-%% These are used to keep @begin/@end levels from running away
-%% Call \inENV within environments (after a \begingroup)
-\newif\ifENV \ENVfalse \def\inENV{\ifENV\relax\else\ENVtrue\fi}
-\def\ENVcheck{%
-\ifENV\errmessage{Still within an environment; press RETURN to continue}
-\endgroup\fi} % This is not perfect, but it should reduce lossage
+% Several utility definitions with active space:
+{
+  \obeyspaces
+  \gdef\obeyedspace{ }
 
-% @begin foo  is the same as @foo, for now.
-\newhelp\EMsimple{Press RETURN to continue.}
+  % Make each space character in the input produce a normal interword
+  % space in the output.  Don't allow a line break at this space, as this
+  % is used only in environments like @example, where each line of input
+  % should produce a line of output anyway.
+  %
+  \gdef\sepspaces{\obeyspaces\let =\tie}
+
+  % If an index command is used in an @example environment, any spaces
+  % therein should become regular spaces in the raw index file, not the
+  % expansion of \tie (\leavevmode \penalty \@M \ ).
+  \gdef\unsepspaces{\let =\space}
+}
 
-\outer\def\begin{\parsearg\beginxxx}
 
-\def\beginxxx #1{%
-\expandafter\ifx\csname #1\endcsname\relax
-{\errhelp=\EMsimple \errmessage{Undefined command @begin #1}}\else
-\csname #1\endcsname\fi}
+\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
 
-% @end foo executes the definition of \Efoo.
+% Define the framework for environments in texinfo.tex.  It's used like this:
 %
-\def\end{\parsearg\endxxx}
-\def\endxxx #1{%
-  \removeactivespaces{#1}%
-  \edef\endthing{\the\toks0}%
-  %
-  \expandafter\ifx\csname E\endthing\endcsname\relax
-    \expandafter\ifx\csname \endthing\endcsname\relax
-      % There's no \foo, i.e., no ``environment'' foo.
-      \errhelp = \EMsimple
-      \errmessage{Undefined command `@end \endthing'}%
-    \else
-      \unmatchedenderror\endthing
-    \fi
+%   \envdef\foo{...}
+%   \def\Efoo{...}
+%
+% It's the responsibility of \envdef to insert \begingroup before the
+% actual body; @end closes the group after calling \Efoo.  \envdef also
+% defines \thisenv, so the current environment is known; @end checks
+% whether the environment name matches.  The \checkenv macro can also be
+% used to check whether the current environment is the one expected.
+%
+% Non-false conditionals (@iftex, @ifset) don't fit into this, so they
+% are not treated as enviroments; they don't open a group.  (The
+% implementation of @end takes care not to call \endgroup in this
+% special case.)
+
+
+% At runtime, environments start with this:
+\def\startenvironment#1{\begingroup\def\thisenv{#1}}
+% initialize
+\let\thisenv\empty
+
+% ... but they get defined via ``\envdef\foo{...}'':
+\long\def\envdef#1#2{\def#1{\startenvironment#1#2}}
+\def\envparseargdef#1#2{\parseargdef#1{\startenvironment#1#2}}
+
+% Check whether we're in the right environment:
+\def\checkenv#1{%
+  \def\temp{#1}%
+  \ifx\thisenv\temp
   \else
-    % Everything's ok; the right environment has been started.
-    \csname E\endthing\endcsname
+    \badenverr
   \fi
 }
 
-% There is an environment #1, but it hasn't been started.  Give an error.
-%
-\def\unmatchedenderror#1{%
+% Evironment mismatch, #1 expected:
+\def\badenverr{%
   \errhelp = \EMsimple
-  \errmessage{This `@end #1' doesn't have a matching `@#1'}%
+  \errmessage{This command can appear only \inenvironment\temp,
+    not \inenvironment\thisenv}%
+}
+\def\inenvironment#1{%
+  \ifx#1\empty
+    out of any environment%
+  \else
+    in environment \expandafter\string#1%
+  \fi
 }
 
-% Define the control sequence \E#1 to give an unmatched @end error.
+% @end foo executes the definition of \Efoo.
+% But first, it executes a specialized version of \checkenv
 %
-\def\defineunmatchedend#1{%
-  \expandafter\def\csname E#1\endcsname{\unmatchedenderror{#1}}%
+\parseargdef\end{%
+  \if 1\csname iscond.#1\endcsname
+  \else
+    % The general wording of \badenverr may not be ideal, but... --kasal, 06nov03
+    \expandafter\checkenv\csname#1\endcsname
+    \csname E#1\endcsname
+    \endgroup
+  \fi
 }
 
+\newhelp\EMsimple{Press RETURN to continue.}
+
 
 %% Simple single-character @ commands
 
@@ -496,6 +575,9 @@
   !gdef!rbraceatcmd[@}]%
 !endgroup
 
+% @comma{} to avoid , parsing problems.
+\let\comma = ,
+
 % Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
 % Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H.
 \let\, = \c
@@ -505,10 +587,12 @@
 \let\ubaraccent = \b
 \let\udotaccent = \d
 
-% Other special characters: @questiondown @exclamdown
+% Other special characters: @questiondown @exclamdown @ordf @ordm
 % Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss.
 \def\questiondown{?`}
 \def\exclamdown{!`}
+\def\ordf{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{a}}}
+\def\ordm{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{o}}}
 
 % Dotless i and dotless j, used for accents.
 \def\imacro{i}
@@ -521,6 +605,25 @@
   \fi\fi
 }
 
+% The \TeX{} logo, as in plain, but resetting the spacing so that a
+% period following counts as ending a sentence.  (Idea found in latex.)
+%
+\edef\TeX{\TeX \spacefactor=1000 }
+
+% @LaTeX{} logo.  Not quite the same results as the definition in
+% latex.ltx, since we use a different font for the raised A; it's most
+% convenient for us to use an explicitly smaller font, rather than using
+% the \scriptstyle font (since we don't reset \scriptstyle and
+% \scriptscriptstyle).
+%
+\def\LaTeX{%
+  L\kern-.36em
+  {\setbox0=\hbox{T}%
+   \vbox to \ht0{\hbox{\selectfonts\lllsize A}\vss}}%
+  \kern-.15em
+  \TeX
+}
+
 % Be sure we're in horizontal mode when doing a tie, since we make space
 % equivalent to this in @example-like environments. Otherwise, a space
 % at the beginning of a line will start with \penalty -- and
@@ -574,59 +677,14 @@
 \newbox\groupbox
 \def\vfilllimit{0.7}
 %
-\def\group{\begingroup
-  \ifnum\catcode13=\active \else
+\envdef\group{%
+  \ifnum\catcode`\^^M=\active \else
     \errhelp = \groupinvalidhelp
     \errmessage{@group invalid in context where filling is enabled}%
   \fi
-  %
-  % The \vtop we start below produces a box with normal height and large
-  % depth; thus, TeX puts \baselineskip glue before it, and (when the
-  % next line of text is done) \lineskip glue after it.  (See p.82 of
-  % the TeXbook.)  Thus, space below is not quite equal to space
-  % above.  But it's pretty close.
-  \def\Egroup{%
-    \egroup           % End the \vtop.
-    % \dimen0 is the vertical size of the group's box.
-    \dimen0 = \ht\groupbox  \advance\dimen0 by \dp\groupbox
-    % \dimen2 is how much space is left on the page (more or less).
-    \dimen2 = \pageheight   \advance\dimen2 by -\pagetotal
-    % if the group doesn't fit on the current page, and it's a big big
-    % group, force a page break.
-    \ifdim \dimen0 > \dimen2
-      \ifdim \pagetotal < \vfilllimit\pageheight
-        \page
-      \fi
-    \fi
-    \copy\groupbox
-    \endgroup         % End the \group.
-  }%
+  \startsavinginserts
   %
   \setbox\groupbox = \vtop\bgroup
-    % We have to put a strut on the last line in case the @group is in
-    % the midst of an example, rather than completely enclosing it.
-    % Otherwise, the interline space between the last line of the group
-    % and the first line afterwards is too small.  But we can't put the
-    % strut in \Egroup, since there it would be on a line by itself.
-    % Hence this just inserts a strut at the beginning of each line.
-    \everypar = {\strut}%
-    %
-    % Since we have a strut on every line, we don't need any of TeX's
-    % normal interline spacing.
-    \offinterlineskip
-    %
-    % OK, but now we have to do something about blank
-    % lines in the input in @example-like environments, which normally
-    % just turn into \lisppar, which will insert no space now that we've
-    % turned off the interline space.  Simplest is to make them be an
-    % empty paragraph.
-    \ifx\par\lisppar
-      \edef\par{\leavevmode \par}%
-      %
-      % Reset ^^M's definition to new definition of \par.
-      \obeylines
-    \fi
-    %
     % Do @comment since we are called inside an environment such as
     % @example, where each end-of-line in the input causes an
     % end-of-line in the output.  We don't want the end-of-line after
@@ -636,6 +694,32 @@
     \comment
 }
 %
+% The \vtop produces a box with normal height and large depth; thus, TeX puts
+% \baselineskip glue before it, and (when the next line of text is done)
+% \lineskip glue after it.  Thus, space below is not quite equal to space
+% above.  But it's pretty close.
+\def\Egroup{%
+    % To get correct interline space between the last line of the group
+    % and the first line afterwards, we have to propagate \prevdepth.
+    \endgraf % Not \par, as it may have been set to \lisppar.
+    \global\dimen1 = \prevdepth
+  \egroup           % End the \vtop.
+  % \dimen0 is the vertical size of the group's box.
+  \dimen0 = \ht\groupbox  \advance\dimen0 by \dp\groupbox
+  % \dimen2 is how much space is left on the page (more or less).
+  \dimen2 = \pageheight   \advance\dimen2 by -\pagetotal
+  % if the group doesn't fit on the current page, and it's a big big
+  % group, force a page break.
+  \ifdim \dimen0 > \dimen2
+    \ifdim \pagetotal < \vfilllimit\pageheight
+      \page
+    \fi
+  \fi
+  \box\groupbox
+  \prevdepth = \dimen1
+  \checkinserts
+}
+%
 % TeX puts in an \escapechar (i.e., `@') at the beginning of the help
 % message, so this ends up printing `@group can only ...'.
 %
@@ -648,10 +732,8 @@
 
 \newdimen\mil  \mil=0.001in
 
-\def\need{\parsearg\needx}
-
 % Old definition--didn't work.
-%\def\needx #1{\par %
+%\parseargdef\need{\par %
 %% This method tries to make TeX break the page naturally
 %% if the depth of the box does not fit.
 %{\baselineskip=0pt%
@@ -659,7 +741,7 @@
 %\prevdepth=-1000pt
 %}}
 
-\def\needx#1{%
+\parseargdef\need{%
   % Ensure vertical mode, so we don't make a big box in the middle of a
   % paragraph.
   \par
@@ -698,35 +780,10 @@
   \fi
 }
 
-% @br   forces paragraph break
+% @br   forces paragraph break (and is undocumented).
 
 \let\br = \par
 
-% @dots{} output an ellipsis using the current font.
-% We do .5em per period so that it has the same spacing in a typewriter
-% font as three actual period characters.
-%
-\def\dots{%
-  \leavevmode
-  \hbox to 1.5em{%
-    \hskip 0pt plus 0.25fil minus 0.25fil
-    .\hss.\hss.%
-    \hskip 0pt plus 0.5fil minus 0.5fil
-  }%
-}
-
-% @enddots{} is an end-of-sentence ellipsis.
-%
-\def\enddots{%
-  \leavevmode
-  \hbox to 2em{%
-    \hskip 0pt plus 0.25fil minus 0.25fil
-    .\hss.\hss.\hss.%
-    \hskip 0pt plus 0.5fil minus 0.5fil
-  }%
-  \spacefactor=3000
-}
-
 % @page forces the start of a new page.
 %
 \def\page{\par\vfill\supereject}
@@ -739,13 +796,11 @@
 \newskip\exdentamount
 
 % This defn is used inside fill environments such as @defun.
-\def\exdent{\parsearg\exdentyyy}
-\def\exdentyyy #1{{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}}
+\parseargdef\exdent{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}
 
 % This defn is used inside nofill environments such as @example.
-\def\nofillexdent{\parsearg\nofillexdentyyy}
-\def\nofillexdentyyy #1{{\advance \leftskip by -\exdentamount
-\leftline{\hskip\leftskip{\rm#1}}}}
+\parseargdef\nofillexdent{{\advance \leftskip by -\exdentamount
+  \leftline{\hskip\leftskip{\rm#1}}}}
 
 % @inmargin{WHICH}{TEXT} puts TEXT in the WHICH margin next to the current
 % paragraph.  For more general purposes, use the \margin insertion
@@ -797,8 +852,19 @@
 }
 
 % @include file    insert text of that file as input.
-% Allow normal characters that  we make active in the argument (a file name).
-\def\include{\begingroup
+%
+\def\include{\parseargusing\filenamecatcodes\includezzz}
+\def\includezzz#1{%
+  \pushthisfilestack
+  \def\thisfile{#1}%
+  {%
+    \makevalueexpandable
+    \def\temp{\input #1 }%
+    \expandafter
+  }\temp
+  \popthisfilestack
+}
+\def\filenamecatcodes{%
   \catcode`\\=\other
   \catcode`~=\other
   \catcode`^=\other
@@ -807,33 +873,50 @@
   \catcode`<=\other
   \catcode`>=\other
   \catcode`+=\other
-  \parsearg\includezzz}
-% Restore active chars for included file.
-\def\includezzz#1{\endgroup\begingroup
-  % Read the included file in a group so nested @include's work.
-  \def\thisfile{#1}%
-  \let\value=\expandablevalue
-  \input\thisfile
-\endgroup}
+  \catcode`-=\other
+}
+
+\def\pushthisfilestack{%
+  \expandafter\pushthisfilestackX\popthisfilestack\StackTerm
+}
+\def\pushthisfilestackX{%
+  \expandafter\pushthisfilestackY\thisfile\StackTerm
+}
+\def\pushthisfilestackY #1\StackTerm #2\StackTerm {%
+  \gdef\popthisfilestack{\gdef\thisfile{#1}\gdef\popthisfilestack{#2}}%
+}
+
+\def\popthisfilestack{\errthisfilestackempty}
+\def\errthisfilestackempty{\errmessage{Internal error:
+  the stack of filenames is empty.}}
 
 \def\thisfile{}
 
 % @center line
 % outputs that line, centered.
 %
-\def\center{\parsearg\docenter}
-\def\docenter#1{{%
-  \ifhmode \hfil\break \fi
-  \advance\hsize by -\leftskip
-  \advance\hsize by -\rightskip
-  \line{\hfil \ignorespaces#1\unskip \hfil}%
-  \ifhmode \break \fi
-}}
+\parseargdef\center{%
+  \ifhmode
+    \let\next\centerH
+  \else
+    \let\next\centerV
+  \fi
+  \next{\hfil \ignorespaces#1\unskip \hfil}%
+}
+\def\centerH#1{%
+  {%
+    \hfil\break
+    \advance\hsize by -\leftskip
+    \advance\hsize by -\rightskip
+    \line{#1}%
+    \break
+  }%
+}
+\def\centerV#1{\line{\kern\leftskip #1\kern\rightskip}}
 
 % @sp n   outputs n lines of vertical space
 
-\def\sp{\parsearg\spxxx}
-\def\spxxx #1{\vskip #1\baselineskip}
+\parseargdef\sp{\vskip #1\baselineskip}
 
 % @comment ...line which is ignored...
 % @c is the same as @comment
@@ -854,8 +937,7 @@
 \def\asisword{asis} % no translation, these are keywords
 \def\noneword{none}
 %
-\def\paragraphindent{\parsearg\doparagraphindent}
-\def\doparagraphindent#1{%
+\parseargdef\paragraphindent{%
   \def\temp{#1}%
   \ifx\temp\asisword
   \else
@@ -872,8 +954,7 @@
 % We'll use ems for NCHARS like @paragraphindent.
 % It seems @exampleindent asis isn't necessary, but
 % I preserve it to make it similar to @paragraphindent.
-\def\exampleindent{\parsearg\doexampleindent}
-\def\doexampleindent#1{%
+\parseargdef\exampleindent{%
   \def\temp{#1}%
   \ifx\temp\asisword
   \else
@@ -887,21 +968,18 @@
 
 % @firstparagraphindent WORD
 % If WORD is `none', then suppress indentation of the first paragraph
-% after a section heading.  If WORD is `insert', then do indentat such
+% after a section heading.  If WORD is `insert', then do indent at such
 % paragraphs.
 %
 % The paragraph indentation is suppressed or not by calling
-% \suppressfirstparagraphindent, which the sectioning commands do.  We
-% switch the definition of this back and forth according to WORD.  By
-% default, we suppress indentation.
+% \suppressfirstparagraphindent, which the sectioning commands do.
+% We switch the definition of this back and forth according to WORD.
+% By default, we suppress indentation.
 %
 \def\suppressfirstparagraphindent{\dosuppressfirstparagraphindent}
-\newdimen\currentparindent
-%
 \def\insertword{insert}
 %
-\def\firstparagraphindent{\parsearg\dofirstparagraphindent}
-\def\dofirstparagraphindent#1{%
+\parseargdef\firstparagraphindent{%
   \def\temp{#1}%
   \ifx\temp\noneword
     \let\suppressfirstparagraphindent = \dosuppressfirstparagraphindent
@@ -921,15 +999,24 @@
 %
 \gdef\dosuppressfirstparagraphindent{%
   \gdef\indent{%
-    \global\let\indent=\ptexindent
-    \global\everypar = {}%
+    \restorefirstparagraphindent
+    \indent
+  }%
+  \gdef\noindent{%
+    \restorefirstparagraphindent
+    \noindent
   }%
   \global\everypar = {%
-    \kern-\parindent
-    \global\let\indent=\ptexindent
-    \global\everypar = {}%
+    \kern -\parindent
+    \restorefirstparagraphindent
   }%
-}%
+}
+
+\gdef\restorefirstparagraphindent{%
+  \global \let \indent = \ptexindent
+  \global \let \noindent = \ptexnoindent
+  \global \everypar = {}%
+}
 
 
 % @asis just yields its argument.  Used with @table, for example.
@@ -937,23 +1024,18 @@
 \def\asis#1{#1}
 
 % @math outputs its argument in math mode.
-% We don't use $'s directly in the definition of \math because we need
-% to set catcodes according to plain TeX first, to allow for subscripts,
-% superscripts, special math chars, etc.
-%
-\let\implicitmath = $%$ font-lock fix
 %
 % One complication: _ usually means subscripts, but it could also mean
 % an actual _ character, as in @math{@var{some_variable} + 1}.  So make
-% _ within @math be active (mathcode "8000), and distinguish by seeing
-% if the current family is \slfam, which is what @var uses.
-%
-{\catcode\underChar = \active
-\gdef\mathunderscore{%
-  \catcode\underChar=\active
-  \def_{\ifnum\fam=\slfam \_\else\sb\fi}%
-}}
-%
+% _ active, and distinguish by seeing if the current family is \slfam,
+% which is what @var uses.
+{
+  \catcode\underChar = \active
+  \gdef\mathunderscore{%
+    \catcode\underChar=\active
+    \def_{\ifnum\fam=\slfam \_\else\sb\fi}%
+  }
+}
 % Another complication: we want \\ (and @\) to output a \ character.
 % FYI, plain.tex uses \\ as a temporary control sequence (why?), but
 % this is not advertised and we don't care.  Texinfo does not
@@ -964,15 +1046,16 @@
 %
 \def\math{%
   \tex
-  \mathcode`\_="8000 \mathunderscore
+  \mathunderscore
   \let\\ = \mathbackslash
   \mathactive
-  \implicitmath\finishmath}
-\def\finishmath#1{#1\implicitmath\Etex}
+  $\finishmath
+}
+\def\finishmath#1{#1$\endgroup}  % Close the group opened by \tex.
 
 % Some active characters (such as <) are spaced differently in math.
-% We have to reset their definitions in case the @math was an
-% argument to a command which set the catcodes (such as @item or @section).
+% We have to reset their definitions in case the @math was an argument
+% to a command which sets the catcodes (such as @item or @section).
 %
 {
   \catcode`^ = \active
@@ -988,8 +1071,33 @@
 }
 
 % @bullet and @minus need the same treatment as @math, just above.
-\def\bullet{\implicitmath\ptexbullet\implicitmath}
-\def\minus{\implicitmath-\implicitmath}
+\def\bullet{$\ptexbullet$}
+\def\minus{$-$}
+
+% @dots{} outputs an ellipsis using the current font.
+% We do .5em per period so that it has the same spacing in a typewriter
+% font as three actual period characters.
+%
+\def\dots{%
+  \leavevmode
+  \hbox to 1.5em{%
+    \hskip 0pt plus 0.25fil
+    .\hfil.\hfil.%
+    \hskip 0pt plus 0.5fil
+  }%
+}
+
+% @enddots{} is an end-of-sentence ellipsis.
+%
+\def\enddots{%
+  \dots
+  \spacefactor=3000
+}
+
+% @comma{} is so commas can be inserted into text without messing up
+% Texinfo's parsing.
+%
+\let\comma = ,
 
 % @refill is a no-op.
 \let\refill=\relax
@@ -1005,20 +1113,20 @@
 % So open here the files we need to have open while reading the input.
 % This makes it possible to make a .fmt file for texinfo.
 \def\setfilename{%
+   \fixbackslash  % Turn off hack to swallow `\input texinfo'.
    \iflinks
-     \readauxfile
+     \tryauxfile
+     % Open the new aux file.  TeX will close it automatically at exit.
+     \immediate\openout\auxfile=\jobname.aux
    \fi % \openindices needs to do some work in any case.
    \openindices
-   \fixbackslash  % Turn off hack to swallow `\input texinfo'.
-   \global\let\setfilename=\comment % Ignore extra @setfilename cmds.
+   \let\setfilename=\comment % Ignore extra @setfilename cmds.
    %
    % If texinfo.cnf is present on the system, read it.
    % Useful for site-wide @afourpaper, etc.
-   % Just to be on the safe side, close the input stream before the \input.
    \openin 1 texinfo.cnf
-   \ifeof1 \let\temp=\relax \else \def\temp{\input texinfo.cnf }\fi
-   \closein1
-   \temp
+   \ifeof 1 \else \input texinfo.cnf \fi
+   \closein 1
    %
    \comment % Ignore the actual filename.
 }
@@ -1054,17 +1162,23 @@
 \newif\ifpdf
 \newif\ifpdfmakepagedest
 
+% when pdftex is run in dvi mode, \pdfoutput is defined (so \pdfoutput=1
+% can be set).  So we test for \relax and 0 as well as \undefined,
+% borrowed from ifpdf.sty.
 \ifx\pdfoutput\undefined
-  \pdffalse
-  \let\pdfmkdest = \gobble
-  \let\pdfurl = \gobble
-  \let\endlink = \relax
-  \let\linkcolor = \relax
-  \let\pdfmakeoutlines = \relax
 \else
-  \pdftrue
-  \pdfoutput = 1
+  \ifx\pdfoutput\relax
+  \else
+    \ifcase\pdfoutput
+    \else
+      \pdftrue
+    \fi
+  \fi
+\fi
+%
+\ifpdf
   \input pdfcolor
+  \pdfcatalog{/PageMode /UseOutlines}%
   \def\dopdfimage#1#2#3{%
     \def\imagewidth{#2}%
     \def\imageheight{#3}%
@@ -1085,7 +1199,13 @@
     \ifnum\pdftexversion < 14 \else
       \pdfrefximage \pdflastximage
     \fi}
-  \def\pdfmkdest#1{{\normalturnoffactive \pdfdest name{#1} xyz}}
+  \def\pdfmkdest#1{{%
+    % We have to set dummies so commands such as @code in a section title
+    % aren't expanded.
+    \atdummies
+    \normalturnoffactive
+    \pdfdest name{#1} xyz%
+  }}
   \def\pdfmkpgn#1{#1}
   \let\linkcolor = \Blue  % was Cyan, but that seems light?
   \def\endlink{\Black\pdfendlink}
@@ -1094,48 +1214,94 @@
   \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
     \else \csname#1\endcsname \fi}
   \def\advancenumber#1{\tempnum=\expnumber{#1}\relax
-    \advance\tempnum by1
+    \advance\tempnum by 1
     \expandafter\xdef\csname#1\endcsname{\the\tempnum}}
-  \def\pdfmakeoutlines{{%
-    \openin 1 \jobname.toc
-    \ifeof 1\else\begingroup
-      \closein 1
+  %
+  % #1 is the section text.  #2 is the pdf expression for the number
+  % of subentries (or empty, for subsubsections).  #3 is the node
+  % text, which might be empty if this toc entry had no
+  % corresponding node.  #4 is the page number.
+  %
+  \def\dopdfoutline#1#2#3#4{%
+    % Generate a link to the node text if that exists; else, use the
+    % page number.  We could generate a destination for the section
+    % text in the case where a section has no node, but it doesn't
+    % seem worthwhile, since most documents are normally structured.
+    \def\pdfoutlinedest{#3}%
+    \ifx\pdfoutlinedest\empty \def\pdfoutlinedest{#4}\fi
+    %
+    \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{#1}%
+  }
+  %
+  \def\pdfmakeoutlines{%
+    \begingroup
       % Thanh's hack / proper braces in bookmarks
       \edef\mylbrace{\iftrue \string{\else}\fi}\let\{=\mylbrace
       \edef\myrbrace{\iffalse{\else\string}\fi}\let\}=\myrbrace
       %
-      \def\chapentry ##1##2##3{}
-      \def\secentry ##1##2##3##4{\advancenumber{chap##2}}
-      \def\subsecentry ##1##2##3##4##5{\advancenumber{sec##2.##3}}
-      \def\subsubsecentry ##1##2##3##4##5##6{\advancenumber{subsec##2.##3.##4}}
-      \let\appendixentry = \chapentry
-      \let\unnumbchapentry = \chapentry
-      \let\unnumbsecentry = \secentry
-      \let\unnumbsubsecentry = \subsecentry
-      \let\unnumbsubsubsecentry = \subsubsecentry
+      % Read toc silently, to get counts of subentries for \pdfoutline.
+      \def\numchapentry##1##2##3##4{%
+	\def\thischapnum{##2}%
+	\let\thissecnum\empty
+	\let\thissubsecnum\empty
+      }%
+      \def\numsecentry##1##2##3##4{%
+	\advancenumber{chap\thischapnum}%
+	\def\thissecnum{##2}%
+	\let\thissubsecnum\empty
+      }%
+      \def\numsubsecentry##1##2##3##4{%
+	\advancenumber{sec\thissecnum}%
+	\def\thissubsecnum{##2}%
+      }%
+      \def\numsubsubsecentry##1##2##3##4{%
+	\advancenumber{subsec\thissubsecnum}%
+      }%
+      \let\thischapnum\empty
+      \let\thissecnum\empty
+      \let\thissubsecnum\empty
+      %
+      % use \def rather than \let here because we redefine \chapentry et
+      % al. a second time, below.
+      \def\appentry{\numchapentry}%
+      \def\appsecentry{\numsecentry}%
+      \def\appsubsecentry{\numsubsecentry}%
+      \def\appsubsubsecentry{\numsubsubsecentry}%
+      \def\unnchapentry{\numchapentry}%
+      \def\unnsecentry{\numsecentry}%
+      \def\unnsubsecentry{\numsubsecentry}%
+      \def\unnsubsubsecentry{\numsubsubsecentry}%
       \input \jobname.toc
-      \def\chapentry ##1##2##3{%
-        \pdfoutline goto name{\pdfmkpgn{##3}}count-\expnumber{chap##2}{##1}}
-      \def\secentry ##1##2##3##4{%
-        \pdfoutline goto name{\pdfmkpgn{##4}}count-\expnumber{sec##2.##3}{##1}}
-      \def\subsecentry ##1##2##3##4##5{%
-        \pdfoutline goto name{\pdfmkpgn{##5}}count-\expnumber{subsec##2.##3.##4}{##1}}
-      \def\subsubsecentry ##1##2##3##4##5##6{%
-        \pdfoutline goto name{\pdfmkpgn{##6}}{##1}}
-      \let\appendixentry = \chapentry
-      \let\unnumbchapentry = \chapentry
-      \let\unnumbsecentry = \secentry
-      \let\unnumbsubsecentry = \subsecentry
-      \let\unnumbsubsubsecentry = \subsubsecentry
       %
-      % Make special characters normal for writing to the pdf file.
+      % Read toc second time, this time actually producing the outlines.
+      % The `-' means take the \expnumber as the absolute number of
+      % subentries, which we calculated on our first read of the .toc above.
+      %
+      % We use the node names as the destinations.
+      \def\numchapentry##1##2##3##4{%
+        \dopdfoutline{##1}{count-\expnumber{chap##2}}{##3}{##4}}%
+      \def\numsecentry##1##2##3##4{%
+        \dopdfoutline{##1}{count-\expnumber{sec##2}}{##3}{##4}}%
+      \def\numsubsecentry##1##2##3##4{%
+        \dopdfoutline{##1}{count-\expnumber{subsec##2}}{##3}{##4}}%
+      \def\numsubsubsecentry##1##2##3##4{% count is always zero
+        \dopdfoutline{##1}{}{##3}{##4}}%
+      %
+      % PDF outlines are displayed using system fonts, instead of
+      % document fonts.  Therefore we cannot use special characters,
+      % since the encoding is unknown.  For example, the eogonek from
+      % Latin 2 (0xea) gets translated to a | character.  Info from
+      % Staszek Wawrykiewicz, 19 Jan 2004 04:09:24 +0100.
       %
+      % xx to do this right, we have to translate 8-bit characters to
+      % their "best" equivalent, based on the @documentencoding.  Right
+      % now, I guess we'll just let the pdf reader have its way.
       \indexnofonts
-      \let\tt=\relax
       \turnoffactive
       \input \jobname.toc
-    \endgroup\fi
-  }}
+    \endgroup
+  }
+  %
   \def\makelinks #1,{%
     \def\params{#1}\def\E{END}%
     \ifx\params\E
@@ -1166,7 +1332,6 @@
   \def\ppn#1{\pgn=#1\gobble}
   \def\ppnn{\pgn=\first}
   \def\pdfmklnk#1{\lnkcount=0\makelinks #1,END,}
-  \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
   \def\skipspaces#1{\def\PP{#1}\def\D{|}%
     \ifx\PP\D\let\nextsp\relax
     \else\let\nextsp\skipspaces
@@ -1184,18 +1349,17 @@
   \def\pdfurl#1{%
     \begingroup
       \normalturnoffactive\def\@{@}%
-      \let\value=\expandablevalue
+      \makevalueexpandable
       \leavevmode\Red
       \startlink attr{/Border [0 0 0]}%
         user{/Subtype /Link /A << /S /URI /URI (#1) >>}%
-        % #1
     \endgroup}
   \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
   \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
   \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
   \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
   \def\maketoks{%
-    \expandafter\poptoks\the\toksA|ENDTOKS|
+    \expandafter\poptoks\the\toksA|ENDTOKS|\relax
     \ifx\first0\adn0
     \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
     \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
@@ -1215,20 +1379,44 @@
     \startlink attr{/Border [0 0 0]} goto name{\pdfmkpgn{#1}}
     \linkcolor #1\endlink}
   \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
-\fi % \ifx\pdfoutput
+\else
+  \let\pdfmkdest = \gobble
+  \let\pdfurl = \gobble
+  \let\endlink = \relax
+  \let\linkcolor = \relax
+  \let\pdfmakeoutlines = \relax
+\fi  % \ifx\pdfoutput
 
 
 \message{fonts,}
-% Font-change commands.
+
+% Change the current font style to #1, remembering it in \curfontstyle.
+% For now, we do not accumulate font styles: @b{@i{foo}} prints foo in
+% italics, not bold italics.
+%
+\def\setfontstyle#1{%
+  \def\curfontstyle{#1}% not as a control sequence, because we are \edef'd.
+  \csname ten#1\endcsname  % change the current font
+}
+
+% Select #1 fonts with the current style.
+%
+\def\selectfonts#1{\csname #1fonts\endcsname \csname\curfontstyle\endcsname}
+
+\def\rm{\fam=0 \setfontstyle{rm}}
+\def\it{\fam=\itfam \setfontstyle{it}}
+\def\sl{\fam=\slfam \setfontstyle{sl}}
+\def\bf{\fam=\bffam \setfontstyle{bf}}
+\def\tt{\fam=\ttfam \setfontstyle{tt}}
 
 % Texinfo sort of supports the sans serif font style, which plain TeX does not.
-% So we set up a \sf analogous to plain's \rm, etc.
+% So we set up a \sf.
 \newfam\sffam
-\def\sf{\fam=\sffam \tensf}
+\def\sf{\fam=\sffam \setfontstyle{sf}}
 \let\li = \sf % Sometimes we call it \li, not \sf.
 
-% We don't need math for this one.
-\def\ttsl{\tenttsl}
+% We don't need math for this font style.
+\def\ttsl{\setfontstyle{ttsl}}
 
 % Default leading.
 \newdimen\textleading  \textleading = 13.2pt
@@ -1279,6 +1467,7 @@
 \def\scshape{csc}
 \def\scbshape{csc}
 
+% Text fonts (11.2pt, magstep1).
 \newcount\mainmagstep
 \ifx\bigger\relax
   % not really supported.
@@ -1290,10 +1479,6 @@
   \setfont\textrm\rmshape{10}{\mainmagstep}
   \setfont\texttt\ttshape{10}{\mainmagstep}
 \fi
-% Instead of cmb10, you may want to use cmbx10.
-% cmbx10 is a prettier font on its own, but cmb10
-% looks better when embedded in a line with cmr10
-% (in Bob's opinion).
 \setfont\textbf\bfshape{10}{\mainmagstep}
 \setfont\textit\itshape{10}{\mainmagstep}
 \setfont\textsl\slshape{10}{\mainmagstep}
@@ -1303,10 +1488,11 @@
 \font\texti=cmmi10 scaled \mainmagstep
 \font\textsy=cmsy10 scaled \mainmagstep
 
-% A few fonts for @defun, etc.
-\setfont\defbf\bxshape{10}{\magstep1} %was 1314
+% A few fonts for @defun names and args.
+\setfont\defbf\bfshape{10}{\magstep1}
 \setfont\deftt\ttshape{10}{\magstep1}
-\def\df{\let\tentt=\deftt \let\tenbf = \defbf \bf}
+\setfont\defttsl\ttslshape{10}{\magstep1}
+\def\df{\let\tentt=\deftt \let\tenbf = \defbf \let\tenttsl=\defttsl \bf}
 
 % Fonts for indices, footnotes, small examples (9pt).
 \setfont\smallrm\rmshape{9}{1000}
@@ -1332,7 +1518,7 @@
 \font\smalleri=cmmi8
 \font\smallersy=cmsy8
 
-% Fonts for title page:
+% Fonts for title page (20.4pt):
 \setfont\titlerm\rmbshape{12}{\magstep3}
 \setfont\titleit\itbshape{10}{\magstep4}
 \setfont\titlesl\slbshape{10}{\magstep4}
@@ -1378,11 +1564,21 @@
 \setfont\ssecttsl\ttslshape{10}{1315}
 \setfont\ssecsf\sfbshape{12}{\magstephalf}
 \let\ssecbf\ssecrm
-\setfont\ssecsc\scbshape{10}{\magstep1}
+\setfont\ssecsc\scbshape{10}{1315}
 \font\sseci=cmmi12 scaled \magstephalf
 \font\ssecsy=cmsy10 scaled 1315
-% The smallcaps and symbol fonts should actually be scaled \magstep1.5,
-% but that is not a standard magnification.
+
+% Reduced fonts for @acro in text (10pt).
+\setfont\reducedrm\rmshape{10}{1000}
+\setfont\reducedtt\ttshape{10}{1000}
+\setfont\reducedbf\bfshape{10}{1000}
+\setfont\reducedit\itshape{10}{1000}
+\setfont\reducedsl\slshape{10}{1000}
+\setfont\reducedsf\sfshape{10}{1000}
+\setfont\reducedsc\scshape{10}{1000}
+\setfont\reducedttsl\ttslshape{10}{1000}
+\font\reducedi=cmmi10
+\font\reducedsy=cmsy10
 
 % In order for the font changes to affect most math symbols and letters,
 % we have to define the \textfont of the standard families.  Since
@@ -1397,50 +1593,72 @@
 }
 
 % The font-changing commands redefine the meanings of \tenSTYLE, instead
-% of just \STYLE.  We do this so that font changes will continue to work
-% in math mode, where it is the current \fam that is relevant in most
-% cases, not the current font.  Plain TeX does \def\bf{\fam=\bffam
-% \tenbf}, for example.  By redefining \tenbf, we obviate the need to
-% redefine \bf itself.
+% of just \STYLE.  We do this because \STYLE needs to also set the
+% current \fam for math mode.  Our \STYLE (e.g., \rm) commands hardwire
+% \tenSTYLE to set the current font.
+%
+% Each font-changing command also sets the names \lsize (one size lower)
+% and \lllsize (three sizes lower).  These relative commands are used in
+% the LaTeX logo and acronyms.
+%
+% This all needs generalizing, badly.
+%
 \def\textfonts{%
   \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl
   \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc
-  \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy \let\tenttsl=\textttsl
+  \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy
+  \let\tenttsl=\textttsl
+  \def\lsize{reduced}\def\lllsize{smaller}%
   \resetmathfonts \setleading{\textleading}}
 \def\titlefonts{%
   \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl
   \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc
   \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy
   \let\tenttsl=\titlettsl
+  \def\lsize{chap}\def\lllsize{subsec}%
   \resetmathfonts \setleading{25pt}}
 \def\titlefont#1{{\titlefonts\rm #1}}
 \def\chapfonts{%
   \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl
   \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc
   \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy \let\tenttsl=\chapttsl
+  \def\lsize{sec}\def\lllsize{text}%
   \resetmathfonts \setleading{19pt}}
 \def\secfonts{%
   \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl
   \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc
-  \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy \let\tenttsl=\secttsl
+  \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy
+  \let\tenttsl=\secttsl
+  \def\lsize{subsec}\def\lllsize{reduced}%
   \resetmathfonts \setleading{16pt}}
 \def\subsecfonts{%
   \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl
   \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc
-  \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy \let\tenttsl=\ssecttsl
+  \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy
+  \let\tenttsl=\ssecttsl
+  \def\lsize{text}\def\lllsize{small}%
   \resetmathfonts \setleading{15pt}}
-\let\subsubsecfonts = \subsecfonts % Maybe make sssec fonts scaled magstephalf?
+\let\subsubsecfonts = \subsecfonts
+\def\reducedfonts{%
+  \let\tenrm=\reducedrm \let\tenit=\reducedit \let\tensl=\reducedsl
+  \let\tenbf=\reducedbf \let\tentt=\reducedtt \let\reducedcaps=\reducedsc
+  \let\tensf=\reducedsf \let\teni=\reducedi \let\tensy=\reducedsy
+  \let\tenttsl=\reducedttsl
+  \def\lsize{small}\def\lllsize{smaller}%
+  \resetmathfonts \setleading{10.5pt}}
 \def\smallfonts{%
   \let\tenrm=\smallrm \let\tenit=\smallit \let\tensl=\smallsl
   \let\tenbf=\smallbf \let\tentt=\smalltt \let\smallcaps=\smallsc
   \let\tensf=\smallsf \let\teni=\smalli \let\tensy=\smallsy
   \let\tenttsl=\smallttsl
+  \def\lsize{smaller}\def\lllsize{smaller}%
   \resetmathfonts \setleading{10.5pt}}
 \def\smallerfonts{%
   \let\tenrm=\smallerrm \let\tenit=\smallerit \let\tensl=\smallersl
   \let\tenbf=\smallerbf \let\tentt=\smallertt \let\smallcaps=\smallersc
   \let\tensf=\smallersf \let\teni=\smalleri \let\tensy=\smallersy
   \let\tenttsl=\smallerttsl
+  \def\lsize{smaller}\def\lllsize{smaller}%
   \resetmathfonts \setleading{9.5pt}}
 
 % Set the fonts to use with the @small... environments.
@@ -1449,7 +1667,7 @@
 % About \smallexamplefonts.  If we use \smallfonts (9pt), @smallexample
 % can fit this many characters:
 %   8.5x11=86   smallbook=72  a4=90  a5=69
-% If we use \smallerfonts (8pt), then we can fit this many characters:
+% If we use \scriptfonts (8pt), then we can fit this many characters:
 %   8.5x11=90+  smallbook=80  a4=90+  a5=77
 % For me, subjectively, the few extra characters that fit aren't worth
 % the additional smallness of 8pt.  So I'm making the default 9pt.
@@ -1457,14 +1675,13 @@
 % By the way, for comparison, here's what fits with @example (10pt):
 %   8.5x11=71  smallbook=60  a4=75  a5=58
 %
-% I wish we used A4 paper on this side of the Atlantic.
-%
+% I wish the USA used A4 paper.
 % --karl, 24jan03.
 
 
 % Set up the default fonts, so we can use them for creating boxes.
 %
-\textfonts
+\textfonts \rm
 
 % Define these so they can be easily changed for other fonts.
 \def\angleleft{$\langle$}
@@ -1475,7 +1692,7 @@
 
 % Fonts for short table of contents.
 \setfont\shortcontrm\rmshape{12}{1000}
-\setfont\shortcontbf\bxshape{12}{1000}
+\setfont\shortcontbf\bfshape{10}{\magstep1}  % no cmb12
 \setfont\shortcontsl\slshape{12}{1000}
 \setfont\shortconttt\ttshape{12}{1000}
 
@@ -1489,11 +1706,19 @@
 \def\smartslanted#1{{\ifusingtt\ttsl\sl #1}\futurelet\next\smartitalicx}
 \def\smartitalic#1{{\ifusingtt\ttsl\it #1}\futurelet\next\smartitalicx}
 
+% like \smartslanted except unconditionally uses \ttsl.
+% @var is set to this for defun arguments.
+\def\ttslanted#1{{\ttsl #1}\futurelet\next\smartitalicx}
+
+% like \smartslanted except unconditionally use \sl.  We never want
+% ttsl for book titles, do we?
+\def\cite#1{{\sl #1}\futurelet\next\smartitalicx}
+
 \let\i=\smartitalic
+\let\slanted=\smartslanted
 \let\var=\smartslanted
 \let\dfn=\smartslanted
 \let\emph=\smartitalic
-\let\cite=\smartslanted
 
 \def\b#1{{\bf #1}}
 \let\strong=\b
@@ -1520,7 +1745,6 @@
   {\tt \rawbackslash \frenchspacing #1}%
   \null
 }
-\let\ttfont=\t
 \def\samp#1{`\tclose{#1}'\null}
 \setfont\keyrm\rmshape{8}{1000}
 \font\keysy=cmsy9
@@ -1561,7 +1785,7 @@
   \null
 }
 
-% We *must* turn on hyphenation at `-' and `_' in \code.
+% We *must* turn on hyphenation at `-' and `_' in @code.
 % Otherwise, it is too hard to avoid overfull hboxes
 % in the Emacs manual, the Library manual, etc.
 
@@ -1579,10 +1803,6 @@
     \catcode`\_=\active \let_\codeunder
     \codex
   }
-  %
-  % If we end up with any active - characters when handling the index,
-  % just treat them as a normal -.
-  \global\def\indexbreaks{\catcode`\-=\active \let-\realdash}
 }
 
 \def\realdash{-}
@@ -1606,8 +1826,7 @@
 % @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
 %   `example' (@kbd uses ttsl only inside of @example and friends),
 %   or `code' (@kbd uses normal tty font always).
-\def\kbdinputstyle{\parsearg\kbdinputstylexxx}
-\def\kbdinputstylexxx#1{%
+\parseargdef\kbdinputstyle{%
   \def\arg{#1}%
   \ifx\arg\worddistinct
     \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
@@ -1633,8 +1852,8 @@
 \else{\tclose{\kbdfont\look}}\fi
 \else{\tclose{\kbdfont\look}}\fi}
 
-% For @url, @env, @command quotes seem unnecessary, so use \code.
-\let\url=\code
+% For @indicateurl, @env, @command quotes seem unnecessary, so use \code.
+\let\indicateurl=\code
 \let\env=\code
 \let\command=\code
 
@@ -1666,6 +1885,10 @@
   \endlink
 \endgroup}
 
+% @url synonym for @uref, since that's how everyone uses it.
+%
+\let\url=\uref
+
 % rms does not like angle brackets --karl, 17may97.
 % So now @email is just like @uref, unless we are pdf.
 %
@@ -1707,22 +1930,53 @@
 \def\sc#1{{\smallcaps#1}}       % smallcaps font
 \def\ii#1{{\it #1}}             % italic font
 
-% @acronym downcases the argument and prints in smallcaps.
-\def\acronym#1{{\smallcaps \lowercase{#1}}}
+% @acronym for "FBI", "NATO", and the like.
+% We print this one point size smaller, since it's intended for
+% all-uppercase.
+% 
+\def\acronym#1{\doacronym #1,,\finish}
+\def\doacronym#1,#2,#3\finish{%
+  {\selectfonts\lsize #1}%
+  \def\temp{#2}%
+  \ifx\temp\empty \else
+    \space ({\unsepspaces \ignorespaces \temp \unskip})%
+  \fi
+}
+
+% @abbr for "Comput. J." and the like.
+% No font change, but don't do end-of-sentence spacing.
+% 
+\def\abbr#1{\doabbr #1,,\finish}
+\def\doabbr#1,#2,#3\finish{%
+  {\frenchspacing #1}%
+  \def\temp{#2}%
+  \ifx\temp\empty \else
+    \space ({\unsepspaces \ignorespaces \temp \unskip})%
+  \fi
+}
 
-% @pounds{} is a sterling sign.
+% @pounds{} is a sterling sign, which Knuth put in the CM italic font.
+%
 \def\pounds{{\it\$}}
 
-% @registeredsymbol - R in a circle.  For now, only works in text size;
-% we'd have to redo the font mechanism to change the \scriptstyle and
-% \scriptscriptstyle font sizes to make it look right in headings.
+% @registeredsymbol - R in a circle.  The font for the R should really
+% be smaller yet, but lllsize is the best we can do for now.
 % Adapted from the plain.tex definition of \copyright.
 %
 \def\registeredsymbol{%
-  $^{{\ooalign{\hfil\raise.07ex\hbox{$\scriptstyle\rm R$}\hfil\crcr\Orb}}%
+  $^{{\ooalign{\hfil\raise.07ex\hbox{\selectfonts\lllsize R}%
+               \hfil\crcr\Orb}}%
     }$%
 }
 
+% Laurent Siebenmann reports \Orb undefined with:
+%  Textures 1.7.7 (preloaded format=plain 93.10.14)  (68K)  16 APR 2004 02:38
+% so we'll define it if necessary.
+% 
+\ifx\Orb\undefined
+\def\Orb{\mathhexbox20D}
+\fi
+
 
 \message{page headings,}
 
@@ -1741,87 +1995,103 @@
 \newif\ifsetshortcontentsaftertitlepage
  \let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue
 
-\def\shorttitlepage{\parsearg\shorttitlepagezzz}
-\def\shorttitlepagezzz #1{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
+\parseargdef\shorttitlepage{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
         \endgroup\page\hbox{}\page}
 
-\def\titlepage{\begingroup \parindent=0pt \textfonts
-   \let\subtitlerm=\tenrm
-   \def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}%
-   %
-   \def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines
-                   \let\tt=\authortt}%
-   %
-   % Leave some space at the very top of the page.
-   \vglue\titlepagetopglue
-   %
-   % Now you can print the title using @title.
-   \def\title{\parsearg\titlezzz}%
-   \def\titlezzz##1{\leftline{\titlefonts\rm ##1}
-                    % print a rule at the page bottom also.
-                    \finishedtitlepagefalse
-                    \vskip4pt \hrule height 4pt width \hsize \vskip4pt}%
-   % No rule at page bottom unless we print one at the top with @title.
-   \finishedtitlepagetrue
-   %
-   % Now you can put text using @subtitle.
-   \def\subtitle{\parsearg\subtitlezzz}%
-   \def\subtitlezzz##1{{\subtitlefont \rightline{##1}}}%
-   %
-   % @author should come last, but may come many times.
-   \def\author{\parsearg\authorzzz}%
-   \def\authorzzz##1{\ifseenauthor\else\vskip 0pt plus 1filll\seenauthortrue\fi
-      {\authorfont \leftline{##1}}}%
-   %
-   % Most title ``pages'' are actually two pages long, with space
-   % at the top of the second.  We don't want the ragged left on the second.
-   \let\oldpage = \page
-   \def\page{%
+\envdef\titlepage{%
+  % Open one extra group, as we want to close it in the middle of \Etitlepage.
+  \begingroup
+    \parindent=0pt \textfonts
+    % Leave some space at the very top of the page.
+    \vglue\titlepagetopglue
+    % No rule at page bottom unless we print one at the top with @title.
+    \finishedtitlepagetrue
+    %
+    % Most title ``pages'' are actually two pages long, with space
+    % at the top of the second.  We don't want the ragged left on the second.
+    \let\oldpage = \page
+    \def\page{%
       \iffinishedtitlepage\else
-         \finishtitlepage
+	 \finishtitlepage
       \fi
-      \oldpage
       \let\page = \oldpage
-      \hbox{}}%
-%   \def\page{\oldpage \hbox{}}
+      \page
+      \null
+    }%
 }
 
 \def\Etitlepage{%
-   \iffinishedtitlepage\else
-      \finishtitlepage
-   \fi
-   % It is important to do the page break before ending the group,
-   % because the headline and footline are only empty inside the group.
-   % If we use the new definition of \page, we always get a blank page
-   % after the title page, which we certainly don't want.
-   \oldpage
-   \endgroup
-   %
-   % Need this before the \...aftertitlepage checks so that if they are
-   % in effect the toc pages will come out with page numbers.
-   \HEADINGSon
-   %
-   % If they want short, they certainly want long too.
-   \ifsetshortcontentsaftertitlepage
-     \shortcontents
-     \contents
-     \global\let\shortcontents = \relax
-     \global\let\contents = \relax
-   \fi
-   %
-   \ifsetcontentsaftertitlepage
-     \contents
-     \global\let\contents = \relax
-     \global\let\shortcontents = \relax
-   \fi
+    \iffinishedtitlepage\else
+	\finishtitlepage
+    \fi
+    % It is important to do the page break before ending the group,
+    % because the headline and footline are only empty inside the group.
+    % If we use the new definition of \page, we always get a blank page
+    % after the title page, which we certainly don't want.
+    \oldpage
+  \endgroup
+  %
+  % Need this before the \...aftertitlepage checks so that if they are
+  % in effect the toc pages will come out with page numbers.
+  \HEADINGSon
+  %
+  % If they want short, they certainly want long too.
+  \ifsetshortcontentsaftertitlepage
+    \shortcontents
+    \contents
+    \global\let\shortcontents = \relax
+    \global\let\contents = \relax
+  \fi
+  %
+  \ifsetcontentsaftertitlepage
+    \contents
+    \global\let\contents = \relax
+    \global\let\shortcontents = \relax
+  \fi
 }
 
 \def\finishtitlepage{%
-   \vskip4pt \hrule height 2pt width \hsize
-   \vskip\titlepagebottomglue
-   \finishedtitlepagetrue
+  \vskip4pt \hrule height 2pt width \hsize
+  \vskip\titlepagebottomglue
+  \finishedtitlepagetrue
+}
+
+%%% Macros to be used within @titlepage:
+
+\let\subtitlerm=\tenrm
+\def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}
+
+\def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines
+		\let\tt=\authortt}
+
+\parseargdef\title{%
+  \checkenv\titlepage
+  \leftline{\titlefonts\rm #1}
+  % print a rule at the page bottom also.
+  \finishedtitlepagefalse
+  \vskip4pt \hrule height 4pt width \hsize \vskip4pt
+}
+
+\parseargdef\subtitle{%
+  \checkenv\titlepage
+  {\subtitlefont \rightline{#1}}%
+}
+
+% @author should come last, but may come many times.
+% It can also be used inside @quotation.
+%
+\parseargdef\author{%
+  \def\temp{\quotation}%
+  \ifx\thisenv\temp
+    \def\quotationauthor{#1}% printed in \Equotation.
+  \else
+    \checkenv\titlepage
+    \ifseenauthor\else \vskip 0pt plus 1filll \seenauthortrue \fi
+    {\authorfont \leftline{#1}}%
+  \fi
 }
 
+
 %%% Set up page headings and footings.
 
 \let\thispage=\folio
@@ -1831,7 +2101,7 @@
 \newtoks\evenfootline    % footline on even pages
 \newtoks\oddfootline     % footline on odd pages
 
-% Now make Tex use those variables
+% Now make TeX use those variables
 \headline={{\textfonts\rm \ifodd\pageno \the\oddheadline
                             \else \the\evenheadline \fi}}
 \footline={{\textfonts\rm \ifodd\pageno \the\oddfootline
@@ -1845,32 +2115,27 @@
 % @evenfooting @thisfile||
 % @oddfooting ||@thisfile
 
-\def\evenheading{\parsearg\evenheadingxxx}
-\def\oddheading{\parsearg\oddheadingxxx}
-\def\everyheading{\parsearg\everyheadingxxx}
-
-\def\evenfooting{\parsearg\evenfootingxxx}
-\def\oddfooting{\parsearg\oddfootingxxx}
-\def\everyfooting{\parsearg\everyfootingxxx}
 
-{\catcode`\@=0 %
-
-\gdef\evenheadingxxx #1{\evenheadingyyy #1@|@|@|@|\finish}
-\gdef\evenheadingyyy #1@|#2@|#3@|#4\finish{%
+\def\evenheading{\parsearg\evenheadingxxx}
+\def\evenheadingxxx #1{\evenheadingyyy #1\|\|\|\|\finish}
+\def\evenheadingyyy #1\|#2\|#3\|#4\finish{%
 \global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
 
-\gdef\oddheadingxxx #1{\oddheadingyyy #1@|@|@|@|\finish}
-\gdef\oddheadingyyy #1@|#2@|#3@|#4\finish{%
+\def\oddheading{\parsearg\oddheadingxxx}
+\def\oddheadingxxx #1{\oddheadingyyy #1\|\|\|\|\finish}
+\def\oddheadingyyy #1\|#2\|#3\|#4\finish{%
 \global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
 
-\gdef\everyheadingxxx#1{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
+\parseargdef\everyheading{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
 
-\gdef\evenfootingxxx #1{\evenfootingyyy #1@|@|@|@|\finish}
-\gdef\evenfootingyyy #1@|#2@|#3@|#4\finish{%
+\def\evenfooting{\parsearg\evenfootingxxx}
+\def\evenfootingxxx #1{\evenfootingyyy #1\|\|\|\|\finish}
+\def\evenfootingyyy #1\|#2\|#3\|#4\finish{%
 \global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
 
-\gdef\oddfootingxxx #1{\oddfootingyyy #1@|@|@|@|\finish}
-\gdef\oddfootingyyy #1@|#2@|#3@|#4\finish{%
+\def\oddfooting{\parsearg\oddfootingxxx}
+\def\oddfootingxxx #1{\oddfootingyyy #1\|\|\|\|\finish}
+\def\oddfootingyyy #1\|#2\|#3\|#4\finish{%
   \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}%
   %
   % Leave some space for the footline.  Hopefully ok to assume
@@ -1879,9 +2144,8 @@
   \global\advance\vsize by -\baselineskip
 }
 
-\gdef\everyfootingxxx#1{\oddfootingxxx{#1}\evenfootingxxx{#1}}
-%
-}% unbind the catcode of @.
+\parseargdef\everyfooting{\oddfootingxxx{#1}\evenfootingxxx{#1}}
+
 
 % @headings double      turns headings on for double-sided printing.
 % @headings single      turns headings on for single-sided printing.
@@ -1895,7 +2159,7 @@
 
 \def\headings #1 {\csname HEADINGS#1\endcsname}
 
-\def\HEADINGSoff{
+\def\HEADINGSoff{%
 \global\evenheadline={\hfil} \global\evenfootline={\hfil}
 \global\oddheadline={\hfil} \global\oddfootline={\hfil}}
 \HEADINGSoff
@@ -1904,7 +2168,7 @@
 % chapter name on inside top of right hand pages, document
 % title on inside top of left hand pages, and page numbers on outside top
 % edge of all pages.
-\def\HEADINGSdouble{
+\def\HEADINGSdouble{%
 \global\pageno=1
 \global\evenfootline={\hfil}
 \global\oddfootline={\hfil}
@@ -1916,7 +2180,7 @@
 
 % For single-sided printing, chapter title goes across top left of page,
 % page number on top right.
-\def\HEADINGSsingle{
+\def\HEADINGSsingle{%
 \global\pageno=1
 \global\evenfootline={\hfil}
 \global\oddfootline={\hfil}
@@ -1963,12 +2227,11 @@
 % @settitle line...  specifies the title of the document, for headings.
 % It generates no output of its own.
 \def\thistitle{\putwordNoTitle}
-\def\settitle{\parsearg\settitlezzz}
-\def\settitlezzz #1{\gdef\thistitle{#1}}
+\def\settitle{\parsearg{\gdef\thistitle}}
 
 
 \message{tables,}
-% Tables -- @table, @ftable, @vtable, @item(x), @kitem(x), @xitem(x).
+% Tables -- @table, @ftable, @vtable, @item(x).
 
 % default indentation of table text
 \newdimen\tableindent \tableindent=.8in
@@ -1980,7 +2243,7 @@
 % used internally for \itemindent minus \itemmargin
 \newdimen\itemmax
 
-% Note @table, @vtable, and @vtable define @item, @itemx, etc., with
+% Note @table, @ftable, and @vtable define @item, @itemx, etc., with
 % these defs.
 % They also define \itemindex
 % to index the item name in whatever manner is desired (perhaps none).
@@ -1992,22 +2255,10 @@
 \def\internalBitem{\smallbreak \parsearg\itemzzz}
 \def\internalBitemx{\itemxpar \parsearg\itemzzz}
 
-\def\internalBxitem "#1"{\def\xitemsubtopix{#1} \smallbreak \parsearg\xitemzzz}
-\def\internalBxitemx "#1"{\def\xitemsubtopix{#1} \itemxpar \parsearg\xitemzzz}
-
-\def\internalBkitem{\smallbreak \parsearg\kitemzzz}
-\def\internalBkitemx{\itemxpar \parsearg\kitemzzz}
-
-\def\kitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \lastfunction}}%
-                 \itemzzz {#1}}
-
-\def\xitemzzz #1{\dosubind {kw}{\code{#1}}{for {\bf \xitemsubtopic}}%
-                 \itemzzz {#1}}
-
 \def\itemzzz #1{\begingroup %
   \advance\hsize by -\rightskip
   \advance\hsize by -\tableindent
-  \setbox0=\hbox{\itemfont{#1}}%
+  \setbox0=\hbox{\itemindicate{#1}}%
   \itemindex{#1}%
   \nobreak % This prevents a break before @itemx.
   %
@@ -2031,17 +2282,13 @@
     % \parskip glue -- logically it's part of the @item we just started.
     \nobreak \vskip-\parskip
     %
-    % Stop a page break at the \parskip glue coming up.  (Unfortunately
-    % we can't prevent a possible page break at the following
-    % \baselineskip glue.)  However, if what follows is an environment
-    % such as @example, there will be no \parskip glue; then
-    % the negative vskip we just would cause the example and the item to
-    % crash together.  So we use this bizarre value of 10001 as a signal
-    % to \aboveenvbreak to insert \parskip glue after all.
-    % (Possibly there are other commands that could be followed by
-    % @example which need the same treatment, but not section titles; or
-    % maybe section titles are the only special case and they should be
-    % penalty 10001...)
+    % Stop a page break at the \parskip glue coming up.  However, if
+    % what follows is an environment such as @example, there will be no
+    % \parskip glue; then the negative vskip we just inserted would
+    % cause the example and the item to crash together.  So we use this
+    % bizarre value of 10001 as a signal to \aboveenvbreak to insert
+    % \parskip glue after all.  Section titles are handled this way also.
+    % 
     \penalty 10001
     \endgroup
     \itemxneedsnegativevskipfalse
@@ -2061,81 +2308,72 @@
   \fi
 }
 
-\def\item{\errmessage{@item while not in a table}}
-\def\itemx{\errmessage{@itemx while not in a table}}
-\def\kitem{\errmessage{@kitem while not in a table}}
-\def\kitemx{\errmessage{@kitemx while not in a table}}
-\def\xitem{\errmessage{@xitem while not in a table}}
-\def\xitemx{\errmessage{@xitemx while not in a table}}
-
-% Contains a kludge to get @end[description] to work.
-\def\description{\tablez{\dontindex}{1}{}{}{}{}}
+\def\item{\errmessage{@item while not in a list environment}}
+\def\itemx{\errmessage{@itemx while not in a list environment}}
 
 % @table, @ftable, @vtable.
-\def\table{\begingroup\inENV\obeylines\obeyspaces\tablex}
-{\obeylines\obeyspaces%
-\gdef\tablex #1^^M{%
-\tabley\dontindex#1        \endtabley}}
-
-\def\ftable{\begingroup\inENV\obeylines\obeyspaces\ftablex}
-{\obeylines\obeyspaces%
-\gdef\ftablex #1^^M{%
-\tabley\fnitemindex#1        \endtabley
-\def\Eftable{\endgraf\afterenvbreak\endgroup}%
-\let\Etable=\relax}}
-
-\def\vtable{\begingroup\inENV\obeylines\obeyspaces\vtablex}
-{\obeylines\obeyspaces%
-\gdef\vtablex #1^^M{%
-\tabley\vritemindex#1        \endtabley
-\def\Evtable{\endgraf\afterenvbreak\endgroup}%
-\let\Etable=\relax}}
-
-\def\dontindex #1{}
-\def\fnitemindex #1{\doind {fn}{\code{#1}}}%
-\def\vritemindex #1{\doind {vr}{\code{#1}}}%
-
-{\obeyspaces %
-\gdef\tabley#1#2 #3 #4 #5 #6 #7\endtabley{\endgroup%
-\tablez{#1}{#2}{#3}{#4}{#5}{#6}}}
-
-\def\tablez #1#2#3#4#5#6{%
-\aboveenvbreak %
-\begingroup %
-\def\Edescription{\Etable}% Necessary kludge.
-\let\itemindex=#1%
-\ifnum 0#3>0 \advance \leftskip by #3\mil \fi %
-\ifnum 0#4>0 \tableindent=#4\mil \fi %
-\ifnum 0#5>0 \advance \rightskip by #5\mil \fi %
-\def\itemfont{#2}%
-\itemmax=\tableindent %
-\advance \itemmax by -\itemmargin %
-\advance \leftskip by \tableindent %
-\exdentamount=\tableindent
-\parindent = 0pt
-\parskip = \smallskipamount
-\ifdim \parskip=0pt \parskip=2pt \fi%
-\def\Etable{\endgraf\afterenvbreak\endgroup}%
-\let\item = \internalBitem %
-\let\itemx = \internalBitemx %
-\let\kitem = \internalBkitem %
-\let\kitemx = \internalBkitemx %
-\let\xitem = \internalBxitem %
-\let\xitemx = \internalBxitemx %
+\envdef\table{%
+  \let\itemindex\gobble
+  \tablecheck{table}%
+}
+\envdef\ftable{%
+  \def\itemindex ##1{\doind {fn}{\code{##1}}}%
+  \tablecheck{ftable}%
+}
+\envdef\vtable{%
+  \def\itemindex ##1{\doind {vr}{\code{##1}}}%
+  \tablecheck{vtable}%
+}
+\def\tablecheck#1{%
+  \ifnum \the\catcode`\^^M=\active
+    \endgroup
+    \errmessage{This command won't work in this context; perhaps the problem is
+      that we are \inenvironment\thisenv}%
+    \def\next{\doignore{#1}}%
+  \else
+    \let\next\tablex
+  \fi
+  \next
+}
+\def\tablex#1{%
+  \def\itemindicate{#1}%
+  \parsearg\tabley
 }
+\def\tabley#1{%
+  {%
+    \makevalueexpandable
+    \edef\temp{\noexpand\tablez #1\space\space\space}%
+    \expandafter
+  }\temp \endtablez
+}
+\def\tablez #1 #2 #3 #4\endtablez{%
+  \aboveenvbreak
+  \ifnum 0#1>0 \advance \leftskip by #1\mil \fi
+  \ifnum 0#2>0 \tableindent=#2\mil \fi
+  \ifnum 0#3>0 \advance \rightskip by #3\mil \fi
+  \itemmax=\tableindent
+  \advance \itemmax by -\itemmargin
+  \advance \leftskip by \tableindent
+  \exdentamount=\tableindent
+  \parindent = 0pt
+  \parskip = \smallskipamount
+  \ifdim \parskip=0pt \parskip=2pt \fi
+  \let\item = \internalBitem
+  \let\itemx = \internalBitemx
+}
+\def\Etable{\endgraf\afterenvbreak}
+\let\Eftable\Etable
+\let\Evtable\Etable
+\let\Eitemize\Etable
+\let\Eenumerate\Etable
 
 % This is the counter used by @enumerate, which is really @itemize
 
 \newcount \itemno
 
-\def\itemize{\parsearg\itemizezzz}
+\envdef\itemize{\parsearg\doitemize}
 
-\def\itemizezzz #1{%
-  \begingroup % ended by the @end itemize
-  \itemizey {#1}{\Eitemize}
-}
-
-\def\itemizey#1#2{%
+\def\doitemize#1{%
   \aboveenvbreak
   \itemmax=\itemindent
   \advance\itemmax by -\itemmargin
@@ -2144,13 +2382,33 @@
   \parindent=0pt
   \parskip=\smallskipamount
   \ifdim\parskip=0pt \parskip=2pt \fi
-  \def#2{\endgraf\afterenvbreak\endgroup}%
   \def\itemcontents{#1}%
   % @itemize with no arg is equivalent to @itemize @bullet.
   \ifx\itemcontents\empty\def\itemcontents{\bullet}\fi
   \let\item=\itemizeitem
 }
 
+% Definition of @item while inside @itemize and @enumerate.
+%
+\def\itemizeitem{%
+  \advance\itemno by 1  % for enumerations
+  {\let\par=\endgraf \smallbreak}% reasonable place to break
+  {%
+   % If the document has an @itemize directly after a section title, a
+   % \nobreak will be last on the list, and \sectionheading will have
+   % done a \vskip-\parskip.  In that case, we don't want to zero
+   % parskip, or the item text will crash with the heading.  On the
+   % other hand, when there is normal text preceding the item (as there
+   % usually is), we do want to zero parskip, or there would be too much
+   % space.  In that case, we won't have a \nobreak before.  At least
+   % that's the theory.
+   \ifnum\lastpenalty<10000 \parskip=0in \fi
+   \noindent
+   \hbox to 0pt{\hss \itemcontents \kern\itemmargin}%
+   \vadjust{\penalty 1200}}% not good to break after first line of item.
+  \flushcr
+}
+
 % \splitoff TOKENS\endmark defines \first to be the first token in
 % TOKENS, and \rest to be the remainder.
 %
@@ -2160,11 +2418,8 @@
 % or number, to specify the first label in the enumerated list.  No
 % argument is the same as `1'.
 %
-\def\enumerate{\parsearg\enumeratezzz}
-\def\enumeratezzz #1{\enumeratey #1  \endenumeratey}
+\envparseargdef\enumerate{\enumeratey #1  \endenumeratey}
 \def\enumeratey #1 #2\endenumeratey{%
-  \begingroup % ended by the @end enumerate
-  %
   % If we were given no argument, pretend we were given `1'.
   \def\thearg{#1}%
   \ifx\thearg\empty \def\thearg{1}\fi
@@ -2235,13 +2490,13 @@
   }%
 }
 
-% Call itemizey, adding a period to the first argument and supplying the
+% Call \doitemize, adding a period to the first argument and supplying the
 % common last two arguments.  Also subtract one from the initial value in
 % \itemno, since @item increments \itemno.
 %
 \def\startenumeration#1{%
   \advance\itemno by -1
-  \itemizey{#1.}\Eenumerate\flushcr
+  \doitemize{#1.}\flushcr
 }
 
 % @alphaenumerate and @capsenumerate are abbreviations for giving an arg
@@ -2252,16 +2507,6 @@
 \def\Ealphaenumerate{\Eenumerate}
 \def\Ecapsenumerate{\Eenumerate}
 
-% Definition of @item while inside @itemize.
-
-\def\itemizeitem{%
-\advance\itemno by 1
-{\let\par=\endgraf \smallbreak}%
-\ifhmode \errmessage{In hmode at itemizeitem}\fi
-{\parskip=0in \hskip 0pt
-\hbox to 0pt{\hss \itemcontents\hskip \itemmargin}%
-\vadjust{\penalty 1200}}%
-\flushcr}
 
 % @multitable macros
 % Amy Hendrickson, 8/18/94, 3/6/96
@@ -2288,24 +2533,14 @@
 %   @multitable {Column 1 template} {Column 2 template} {Column 3 template}
 %   @item ...
 %   using the widest term desired in each column.
-%
-% For those who want to use more than one line's worth of words in
-% the preamble, break the line within one argument and it
-% will parse correctly, i.e.,
-%
-%     @multitable {Column 1 template} {Column 2 template} {Column 3
-%      template}
-% Not:
-%     @multitable {Column 1 template} {Column 2 template}
-%      {Column 3 template}
 
 % Each new table line starts with @item, each subsequent new column
 % starts with @tab. Empty columns may be produced by supplying @tab's
 % with nothing between them for as many times as empty columns are needed,
 % ie, @tab at tab@tab will produce two empty columns.
 
-% @item, @tab, @multitable or @end multitable do not need to be on their
-% own lines, but it will not hurt if they are.
+% @item, @tab do not need to be on their own lines, but it will not hurt
+% if they are.
 
 % Sample multitable:
 
@@ -2349,13 +2584,12 @@
 \def\xcolumnfractions{\columnfractions}
 \newif\ifsetpercent
 
-% #1 is the part of the @columnfraction before the decimal point, which
-% is presumably either 0 or the empty string (but we don't check, we
-% just throw it away).  #2 is the decimal part, which we use as the
-% percent of \hsize for this column.
-\def\pickupwholefraction#1.#2 {%
+% #1 is the @columnfraction, usually a decimal number like .5, but might
+% be just 1.  We just use it, whatever it is.
+%
+\def\pickupwholefraction#1 {%
   \global\advance\colcount by 1
-  \expandafter\xdef\csname col\the\colcount\endcsname{.#2\hsize}%
+  \expandafter\xdef\csname col\the\colcount\endcsname{#1\hsize}%
   \setuptable
 }
 
@@ -2388,18 +2622,33 @@
   \go
 }
 
+% multitable-only commands.
+%
+% @headitem starts a heading row, which we typeset in bold.
+% Assignments have to be global since we are inside the implicit group
+% of an alignment entry.  Note that \everycr resets \everytab.
+\def\headitem{\checkenv\multitable \crcr \global\everytab={\bf}\the\everytab}%
+%
+% A \tab used to include \hskip1sp.  But then the space in a template
+% line is not enough.  That is bad.  So let's go back to just `&' until
+% we encounter the problem it was intended to solve again.
+%					--karl, nathan at acm.org, 20apr99.
+\def\tab{\checkenv\multitable &\the\everytab}%
+
 % @multitable ... @end multitable definitions:
 %
-\def\multitable{\parsearg\dotable}
-\def\dotable#1{\bgroup
+\newtoks\everytab  % insert after every tab.
+%
+\envdef\multitable{%
   \vskip\parskip
-  \let\item=\crcrwithfootnotes
-  % A \tab used to include \hskip1sp.  But then the space in a template
-  % line is not enough.  That is bad.  So let's go back to just & until
-  % we encounter the problem it was intended to solve again.  --karl,
-  % nathan at acm.org, 20apr99.
-  \let\tab=&%
-  \let\startfootins=\startsavedfootnote
+  \startsavinginserts
+  %
+  % @item within a multitable starts a normal row.
+  % We use \def instead of \let so that if one of the multitable entries
+  % contains an @itemize, we don't choke on the \item (seen as \crcr aka
+  % \endtemplate) expanding \doitemize.
+  \def\item{\crcr}%
+  %
   \tolerance=9500
   \hbadness=9500
   \setmultitablespacing
@@ -2407,85 +2656,93 @@
   \parindent=\multitableparindent
   \overfullrule=0pt
   \global\colcount=0
-  \def\Emultitable{%
-    \global\setpercentfalse
-    \crcrwithfootnotes\crcr
-    \egroup\egroup
+  %
+  \everycr = {%
+    \noalign{%
+      \global\everytab={}%
+      \global\colcount=0 % Reset the column counter.
+      % Check for saved footnotes, etc.
+      \checkinserts
+      % Keeps underfull box messages off when table breaks over pages.
+      %\filbreak
+	% Maybe so, but it also creates really weird page breaks when the
+	% table breaks over pages. Wouldn't \vfil be better?  Wait until the
+	% problem manifests itself, so it can be fixed for real --karl.
+    }%
   }%
   %
+  \parsearg\domultitable
+}
+\def\domultitable#1{%
   % To parse everything between @multitable and @item:
   \setuptable#1 \endsetuptable
   %
-  % \everycr will reset column counter, \colcount, at the end of
-  % each line. Every column entry will cause \colcount to advance by one.
-  % The table preamble
-  % looks at the current \colcount to find the correct column width.
-  \everycr{\noalign{%
-  %
-  % \filbreak%% keeps underfull box messages off when table breaks over pages.
-  % Maybe so, but it also creates really weird page breaks when the table
-  % breaks over pages. Wouldn't \vfil be better?  Wait until the problem
-  % manifests itself, so it can be fixed for real --karl.
-    \global\colcount=0\relax}}%
-  %
   % This preamble sets up a generic column definition, which will
   % be used as many times as user calls for columns.
   % \vtop will set a single line and will also let text wrap and
   % continue for many paragraphs if desired.
-  \halign\bgroup&\global\advance\colcount by 1\relax
-    \multistrut\vtop{\hsize=\expandafter\csname col\the\colcount\endcsname
+  \halign\bgroup &%
+    \global\advance\colcount by 1
+    \multistrut
+    \vtop{%
+      % Use the current \colcount to find the correct column width:
+      \hsize=\expandafter\csname col\the\colcount\endcsname
+      %
+      % In order to keep entries from bumping into each other
+      % we will add a \leftskip of \multitablecolspace to all columns after
+      % the first one.
+      %
+      % If a template has been used, we will add \multitablecolspace
+      % to the width of each template entry.
+      %
+      % If the user has set preamble in terms of percent of \hsize we will
+      % use that dimension as the width of the column, and the \leftskip
+      % will keep entries from bumping into each other.  Table will start at
+      % left margin and final column will justify at right margin.
+      %
+      % Make sure we don't inherit \rightskip from the outer environment.
+      \rightskip=0pt
+      \ifnum\colcount=1
+	% The first column will be indented with the surrounding text.
+	\advance\hsize by\leftskip
+      \else
+	\ifsetpercent \else
+	  % If user has not set preamble in terms of percent of \hsize
+	  % we will advance \hsize by \multitablecolspace.
+	  \advance\hsize by \multitablecolspace
+	\fi
+       % In either case we will make \leftskip=\multitablecolspace:
+      \leftskip=\multitablecolspace
+      \fi
+      % Ignoring space at the beginning and end avoids an occasional spurious
+      % blank line, when TeX decides to break the line at the space before the
+      % box from the multistrut, so the strut ends up on a line by itself.
+      % For example:
+      % @multitable @columnfractions .11 .89
+      % @item @code{#}
+      % @tab Legal holiday which is valid in major parts of the whole country.
+      % Is automatically provided with highlighting sequences respectively
+      % marking characters.
+      \noindent\ignorespaces##\unskip\multistrut
+    }\cr
+}
+\def\Emultitable{%
+  \crcr
+  \egroup % end the \halign
+  \global\setpercentfalse
+}
+
+\def\setmultitablespacing{%
+  \def\multistrut{\strut}% just use the standard line spacing
   %
-  % In order to keep entries from bumping into each other
-  % we will add a \leftskip of \multitablecolspace to all columns after
-  % the first one.
-  %
-  % If a template has been used, we will add \multitablecolspace
-  % to the width of each template entry.
-  %
-  % If the user has set preamble in terms of percent of \hsize we will
-  % use that dimension as the width of the column, and the \leftskip
-  % will keep entries from bumping into each other.  Table will start at
-  % left margin and final column will justify at right margin.
-  %
-  % Make sure we don't inherit \rightskip from the outer environment.
-  \rightskip=0pt
-  \ifnum\colcount=1
-    % The first column will be indented with the surrounding text.
-    \advance\hsize by\leftskip
-  \else
-    \ifsetpercent \else
-      % If user has not set preamble in terms of percent of \hsize
-      % we will advance \hsize by \multitablecolspace.
-      \advance\hsize by \multitablecolspace
-    \fi
-   % In either case we will make \leftskip=\multitablecolspace:
-  \leftskip=\multitablecolspace
-  \fi
-  % Ignoring space at the beginning and end avoids an occasional spurious
-  % blank line, when TeX decides to break the line at the space before the
-  % box from the multistrut, so the strut ends up on a line by itself.
-  % For example:
-  % @multitable @columnfractions .11 .89
-  % @item @code{#}
-  % @tab Legal holiday which is valid in major parts of the whole country.
-  % Is automatically provided with highlighting sequences respectively marking
-  % characters.
-  \noindent\ignorespaces##\unskip\multistrut}\cr
-}
-
-\def\setmultitablespacing{% test to see if user has set \multitablelinespace.
-% If so, do nothing. If not, give it an appropriate dimension based on
-% current baselineskip.
+  % Compute \multitablelinespace (if not defined by user) for use in
+  % \multitableparskip calculation.  We used define \multistrut based on
+  % this, but (ironically) that caused the spacing to be off.
+  % See bug-texinfo report from Werner Lemberg, 31 Oct 2004 12:52:20 +0100.
 \ifdim\multitablelinespace=0pt
 \setbox0=\vbox{X}\global\multitablelinespace=\the\baselineskip
 \global\advance\multitablelinespace by-\ht0
-%% strut to put in table in case some entry doesn't have descenders,
-%% to keep lines equally spaced
-\let\multistrut = \strut
-\else
-%% FIXME: what is \box0 supposed to be?
-\gdef\multistrut{\vrule height\multitablelinespace depth\dp0
-width0pt\relax} \fi
+\fi
 %% Test to see if parskip is larger than space between lines of
 %% table. If not, do nothing.
 %%        If so, set to same dimension as multitablelinespace.
@@ -2500,163 +2757,33 @@
                                       %% than skip between lines in the table.
 \fi}
 
-% In case a @footnote appears inside an alignment, save the footnote
-% text to a box and make the \insert when a row of the table is
-% finished.  Otherwise, the insertion is lost, it never migrates to the
-% main vertical list.  --kasal, 22jan03.
-%
-\newbox\savedfootnotes
-%
-% \dotable \let's \startfootins to this, so that \dofootnote will call
-% it instead of starting the insertion right away.
-\def\startsavedfootnote{%
-  \global\setbox\savedfootnotes = \vbox\bgroup
-    \unvbox\savedfootnotes
-}
-\def\crcrwithfootnotes{%
-  \crcr
-  \ifvoid\savedfootnotes \else
-    \noalign{\insert\footins{\box\savedfootnotes}}%
-  \fi
-}
 
 \message{conditionals,}
-% Prevent errors for section commands.
-% Used in @ignore and in failing conditionals.
-\def\ignoresections{%
-  \let\chapter=\relax
-  \let\unnumbered=\relax
-  \let\top=\relax
-  \let\unnumberedsec=\relax
-  \let\unnumberedsection=\relax
-  \let\unnumberedsubsec=\relax
-  \let\unnumberedsubsection=\relax
-  \let\unnumberedsubsubsec=\relax
-  \let\unnumberedsubsubsection=\relax
-  \let\section=\relax
-  \let\subsec=\relax
-  \let\subsubsec=\relax
-  \let\subsection=\relax
-  \let\subsubsection=\relax
-  \let\appendix=\relax
-  \let\appendixsec=\relax
-  \let\appendixsection=\relax
-  \let\appendixsubsec=\relax
-  \let\appendixsubsection=\relax
-  \let\appendixsubsubsec=\relax
-  \let\appendixsubsubsection=\relax
-  \let\contents=\relax
-  \let\smallbook=\relax
-  \let\titlepage=\relax
-}
-
-% Used in nested conditionals, where we have to parse the Texinfo source
-% and so want to turn off most commands, in case they are used
-% incorrectly.
-%
-% We use \empty instead of \relax for the @def... commands, so that \end
-% doesn't throw an error.  For instance:
-% @ignore
-% @deffn ...
-% @end deffn
-% @end ignore
-%
-% The @end deffn is going to get expanded, because we're trying to allow
-% nested conditionals.  But we don't want to expand the actual @deffn,
-% since it might be syntactically correct and intended to be ignored.
-% Since \end checks for \relax, using \empty does not cause an error.
-%
-\def\ignoremorecommands{%
-  \let\defcodeindex = \relax
-  \let\defcv = \empty
-  \let\defcvx = \empty
-  \let\Edefcv = \empty
-  \let\deffn = \empty
-  \let\deffnx = \empty
-  \let\Edeffn = \empty
-  \let\defindex = \relax
-  \let\defivar = \empty
-  \let\defivarx = \empty
-  \let\Edefivar = \empty
-  \let\defmac = \empty
-  \let\defmacx = \empty
-  \let\Edefmac = \empty
-  \let\defmethod = \empty
-  \let\defmethodx = \empty
-  \let\Edefmethod = \empty
-  \let\defop = \empty
-  \let\defopx = \empty
-  \let\Edefop = \empty
-  \let\defopt = \empty
-  \let\defoptx = \empty
-  \let\Edefopt = \empty
-  \let\defspec = \empty
-  \let\defspecx = \empty
-  \let\Edefspec = \empty
-  \let\deftp = \empty
-  \let\deftpx = \empty
-  \let\Edeftp = \empty
-  \let\deftypefn = \empty
-  \let\deftypefnx = \empty
-  \let\Edeftypefn = \empty
-  \let\deftypefun = \empty
-  \let\deftypefunx = \empty
-  \let\Edeftypefun = \empty
-  \let\deftypeivar = \empty
-  \let\deftypeivarx = \empty
-  \let\Edeftypeivar = \empty
-  \let\deftypemethod = \empty
-  \let\deftypemethodx = \empty
-  \let\Edeftypemethod = \empty
-  \let\deftypeop = \empty
-  \let\deftypeopx = \empty
-  \let\Edeftypeop = \empty
-  \let\deftypevar = \empty
-  \let\deftypevarx = \empty
-  \let\Edeftypevar = \empty
-  \let\deftypevr = \empty
-  \let\deftypevrx = \empty
-  \let\Edeftypevr = \empty
-  \let\defun = \empty
-  \let\defunx = \empty
-  \let\Edefun = \empty
-  \let\defvar = \empty
-  \let\defvarx = \empty
-  \let\Edefvar = \empty
-  \let\defvr = \empty
-  \let\defvrx = \empty
-  \let\Edefvr = \empty
-  \let\clear = \relax
-  \let\down = \relax
-  \let\evenfooting = \relax
-  \let\evenheading = \relax
-  \let\everyfooting = \relax
-  \let\everyheading = \relax
-  \let\headings = \relax
-  \let\include = \relax
-  \let\item = \relax
-  \let\lowersections = \relax
-  \let\oddfooting = \relax
-  \let\oddheading = \relax
-  \let\printindex = \relax
-  \let\pxref = \relax
-  \let\raisesections = \relax
-  \let\ref = \relax
-  \let\set = \relax
-  \let\setchapternewpage = \relax
-  \let\setchapterstyle = \relax
-  \let\settitle = \relax
-  \let\up = \relax
-  \let\verbatiminclude = \relax
-  \let\xref = \relax
-}
+
+% @iftex, @ifnotdocbook, @ifnothtml, @ifnotinfo, @ifnotplaintext,
+% @ifnotxml always succeed.  They currently do nothing; we don't
+% attempt to check whether the conditionals are properly nested.  But we
+% have to remember that they are conditionals, so that @end doesn't
+% attempt to close an environment group.
+%
+\def\makecond#1{%
+  \expandafter\let\csname #1\endcsname = \relax
+  \expandafter\let\csname iscond.#1\endcsname = 1
+}
+\makecond{iftex}
+\makecond{ifnotdocbook}
+\makecond{ifnothtml}
+\makecond{ifnotinfo}
+\makecond{ifnotplaintext}
+\makecond{ifnotxml}
 
 % Ignore @ignore, @ifhtml, @ifinfo, and the like.
 %
 \def\direntry{\doignore{direntry}}
-\def\documentdescriptionword{documentdescription}
 \def\documentdescription{\doignore{documentdescription}}
+\def\docbook{\doignore{docbook}}
 \def\html{\doignore{html}}
+\def\ifdocbook{\doignore{ifdocbook}}
 \def\ifhtml{\doignore{ifhtml}}
 \def\ifinfo{\doignore{ifinfo}}
 \def\ifnottex{\doignore{ifnottex}}
@@ -2666,198 +2793,133 @@
 \def\menu{\doignore{menu}}
 \def\xml{\doignore{xml}}
 
-% @dircategory CATEGORY  -- specify a category of the dir file
-% which this file should belong to.  Ignore this in TeX.
-\let\dircategory = \comment
-
-% Ignore text until a line `@end #1'.
+% Ignore text until a line `@end #1', keeping track of nested conditionals.
 %
+% A count to remember the depth of nesting.
+\newcount\doignorecount
+
 \def\doignore#1{\begingroup
-  % Don't complain about control sequences we have declared \outer.
-  \ignoresections
-  %
-  % Define a command to swallow text until we reach `@end #1'.
-  % This @ is a catcode 12 token (that is the normal catcode of @ in
-  % this texinfo.tex file).  We change the catcode of @ below to match.
-  \long\def\doignoretext##1 at end #1{\enddoignore}%
+  % Scan in ``verbatim'' mode:
+  \catcode`\@ = \other
+  \catcode`\{ = \other
+  \catcode`\} = \other
   %
   % Make sure that spaces turn into tokens that match what \doignoretext wants.
-  \catcode\spaceChar = 10
+  \spaceisspace
   %
-  % Ignore braces, too, so mismatched braces don't cause trouble.
-  \catcode`\{ = 9
-  \catcode`\} = 9
-  %
-  % We must not have @c interpreted as a control sequence.
-  \catcode`\@ = 12
-  %
-  \def\ignoreword{#1}%
-  \ifx\ignoreword\documentdescriptionword
-    % The c kludge breaks documentdescription, since
-    % `documentdescription' contains a `c'.  Means not everything will
-    % be ignored inside @documentdescription, but oh well...
-  \else
-    % Make the letter c a comment character so that the rest of the line
-    % will be ignored. This way, the document can have (for example)
-    %   @c @end ifinfo
-    % and the @end ifinfo will be properly ignored.
-    % (We've just changed @ to catcode 12.)
-    \catcode`\c = 14
-  \fi
-  %
-  % And now expand the command defined above.
-  \doignoretext
-}
-
-% What we do to finish off ignored text.
-%
-\def\enddoignore{\endgroup\ignorespaces}%
-
-\newif\ifwarnedobs\warnedobsfalse
-\def\obstexwarn{%
-  \ifwarnedobs\relax\else
-  % We need to warn folks that they may have trouble with TeX 3.0.
-  % This uses \immediate\write16 rather than \message to get newlines.
-    \immediate\write16{}
-    \immediate\write16{WARNING: for users of Unix TeX 3.0!}
-    \immediate\write16{This manual trips a bug in TeX version 3.0 (tex hangs).}
-    \immediate\write16{If you are running another version of TeX, relax.}
-    \immediate\write16{If you are running Unix TeX 3.0, kill this TeX process.}
-    \immediate\write16{  Then upgrade your TeX installation if you can.}
-    \immediate\write16{  (See ftp://ftp.gnu.org/non-gnu/TeX.README.)}
-    \immediate\write16{If you are stuck with version 3.0, run the}
-    \immediate\write16{  script ``tex3patch'' from the Texinfo distribution}
-    \immediate\write16{  to use a workaround.}
-    \immediate\write16{}
-    \global\warnedobstrue
-    \fi
-}
-
-% **In TeX 3.0, setting text in \nullfont hangs tex.  For a
-% workaround (which requires the file ``dummy.tfm'' to be installed),
-% uncomment the following line:
-%%%%%\font\nullfont=dummy\let\obstexwarn=\relax
-
-% Ignore text, except that we keep track of conditional commands for
-% purposes of nesting, up to an `@end #1' command.
-%
-\def\nestedignore#1{%
-  \obstexwarn
-  % We must actually expand the ignored text to look for the @end
-  % command, so that nested ignore constructs work.  Thus, we put the
-  % text into a \vbox and then do nothing with the result.  To minimize
-  % the chance of memory overflow, we follow the approach outlined on
-  % page 401 of the TeXbook.
-  %
-  \setbox0 = \vbox\bgroup
-    % Don't complain about control sequences we have declared \outer.
-    \ignoresections
-    %
-    % Define `@end #1' to end the box, which will in turn undefine the
-    % @end command again.
-    \expandafter\def\csname E#1\endcsname{\egroup\ignorespaces}%
-    %
-    % We are going to be parsing Texinfo commands.  Most cause no
-    % trouble when they are used incorrectly, but some commands do
-    % complicated argument parsing or otherwise get confused, so we
-    % undefine them.
-    %
-    % We can't do anything about stray @-signs, unfortunately;
-    % they'll produce `undefined control sequence' errors.
-    \ignoremorecommands
-    %
-    % Set the current font to be \nullfont, a TeX primitive, and define
-    % all the font commands to also use \nullfont.  We don't use
-    % dummy.tfm, as suggested in the TeXbook, because some sites
-    % might not have that installed.  Therefore, math mode will still
-    % produce output, but that should be an extremely small amount of
-    % stuff compared to the main input.
-    %
-    \nullfont
-    \let\tenrm=\nullfont \let\tenit=\nullfont \let\tensl=\nullfont
-    \let\tenbf=\nullfont \let\tentt=\nullfont \let\smallcaps=\nullfont
-    \let\tensf=\nullfont
-    % Similarly for index fonts.
-    \let\smallrm=\nullfont \let\smallit=\nullfont \let\smallsl=\nullfont
-    \let\smallbf=\nullfont \let\smalltt=\nullfont \let\smallsc=\nullfont
-    \let\smallsf=\nullfont
-    % Similarly for smallexample fonts.
-    \let\smallerrm=\nullfont \let\smallerit=\nullfont \let\smallersl=\nullfont
-    \let\smallerbf=\nullfont \let\smallertt=\nullfont \let\smallersc=\nullfont
-    \let\smallersf=\nullfont
-    %
-    % Don't complain when characters are missing from the fonts.
-    \tracinglostchars = 0
-    %
-    % Don't bother to do space factor calculations.
-    \frenchspacing
-    %
-    % Don't report underfull hboxes.
-    \hbadness = 10000
-    %
-    % Do minimal line-breaking.
-    \pretolerance = 10000
+  % Count number of #1's that we've seen.
+  \doignorecount = 0
+  %
+  % Swallow text until we reach the matching `@end #1'.
+  \dodoignore{#1}%
+}
+
+{ \catcode`_=11 % We want to use \_STOP_ which cannot appear in texinfo source.
+  \obeylines %
+  %
+  \gdef\dodoignore#1{%
+    % #1 contains the command name as a string, e.g., `ifinfo'.
     %
-    % Do not execute instructions in @tex.
-    \def\tex{\doignore{tex}}%
-    % Do not execute macro definitions.
-    % `c' is a comment character, so the word `macro' will get cut off.
-    \def\macro{\doignore{ma}}%
+    % Define a command to find the next `@end #1', which must be on a line
+    % by itself.
+    \long\def\doignoretext##1^^M at end #1{\doignoretextyyy##1^^M@#1\_STOP_}%
+    % And this command to find another #1 command, at the beginning of a
+    % line.  (Otherwise, we would consider a line `@c @ifset', for
+    % example, to count as an @ifset for nesting.)
+    \long\def\doignoretextyyy##1^^M@#1##2\_STOP_{\doignoreyyy{##2}\_STOP_}%
+    %
+    % And now expand that command.
+    \obeylines %
+    \doignoretext ^^M%
+  }%
+}
+
+\def\doignoreyyy#1{%
+  \def\temp{#1}%
+  \ifx\temp\empty			% Nothing found.
+    \let\next\doignoretextzzz
+  \else					% Found a nested condition, ...
+    \advance\doignorecount by 1
+    \let\next\doignoretextyyy		% ..., look for another.
+    % If we're here, #1 ends with ^^M\ifinfo (for example).
+  \fi
+  \next #1% the token \_STOP_ is present just after this macro.
+}
+
+% We have to swallow the remaining "\_STOP_".
+%
+\def\doignoretextzzz#1{%
+  \ifnum\doignorecount = 0	% We have just found the outermost @end.
+    \let\next\enddoignore
+  \else				% Still inside a nested condition.
+    \advance\doignorecount by -1
+    \let\next\doignoretext      % Look for the next @end.
+  \fi
+  \next
 }
 
+% Finish off ignored text.
+\def\enddoignore{\endgroup\ignorespaces}
+
+
 % @set VAR sets the variable VAR to an empty value.
 % @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE.
 %
 % Since we want to separate VAR from REST-OF-LINE (which might be
 % empty), we can't just use \parsearg; we have to insert a space of our
 % own to delimit the rest of the line, and then take it out again if we
-% didn't need it.  Make sure the catcode of space is correct to avoid
-% losing inside @example, for instance.
+% didn't need it.
+% We rely on the fact that \parsearg sets \catcode`\ =10.
 %
-\def\set{\begingroup\catcode` =10
-  \catcode`\-=12 \catcode`\_=12 % Allow - and _ in VAR.
-  \parsearg\setxxx}
-\def\setxxx#1{\setyyy#1 \endsetyyy}
+\parseargdef\set{\setyyy#1 \endsetyyy}
 \def\setyyy#1 #2\endsetyyy{%
-  \def\temp{#2}%
-  \ifx\temp\empty \global\expandafter\let\csname SET#1\endcsname = \empty
-  \else \setzzz{#1}#2\endsetzzz % Remove the trailing space \setxxx inserted.
-  \fi
-  \endgroup
+  {%
+    \makevalueexpandable
+    \def\temp{#2}%
+    \edef\next{\gdef\makecsname{SET#1}}%
+    \ifx\temp\empty
+      \next{}%
+    \else
+      \setzzz#2\endsetzzz
+    \fi
+  }%
 }
-% Can't use \xdef to pre-expand #2 and save some time, since \temp or
-% \next or other control sequences that we've defined might get us into
-% an infinite loop. Consider `@set foo @cite{bar}'.
-\def\setzzz#1#2 \endsetzzz{\expandafter\gdef\csname SET#1\endcsname{#2}}
+% Remove the trailing space \setxxx inserted.
+\def\setzzz#1 \endsetzzz{\next{#1}}
 
 % @clear VAR clears (i.e., unsets) the variable VAR.
 %
-\def\clear{\parsearg\clearxxx}
-\def\clearxxx#1{\global\expandafter\let\csname SET#1\endcsname=\relax}
+\parseargdef\clear{%
+  {%
+    \makevalueexpandable
+    \global\expandafter\let\csname SET#1\endcsname=\relax
+  }%
+}
 
 % @value{foo} gets the text saved in variable foo.
+\def\value{\begingroup\makevalueexpandable\valuexxx}
+\def\valuexxx#1{\expandablevalue{#1}\endgroup}
 {
-  \catcode`\_ = \active
+  \catcode`\- = \active \catcode`\_ = \active
   %
-  % We might end up with active _ or - characters in the argument if
-  % we're called from @code, as @code{@value{foo-bar_}}.  So \let any
-  % such active characters to their normal equivalents.
-  \gdef\value{\begingroup
+  \gdef\makevalueexpandable{%
+    \let\value = \expandablevalue
+    % We don't want these characters active, ...
     \catcode`\-=\other \catcode`\_=\other
-    \indexbreaks \let_\normalunderscore
-    \valuexxx}
+    % ..., but we might end up with active ones in the argument if
+    % we're called from @code, as @code{@value{foo-bar_}}, though.
+    % So \let them to their normal equivalents.
+    \let-\realdash \let_\normalunderscore
+  }
 }
-\def\valuexxx#1{\expandablevalue{#1}\endgroup}
 
 % We have this subroutine so that we can handle at least some @value's
-% properly in indexes (we \let\value to this in \indexdummies).  Ones
-% whose names contain - or _ still won't work, but we can't do anything
-% about that.  The command has to be fully expandable (if the variable
-% is set), since the result winds up in the index file.  This means that
-% if the variable's value contains other Texinfo commands, it's almost
-% certain it will fail (although perhaps we could fix that with
-% sufficient work to do a one-level expansion on the result, instead of
-% complete).
+% properly in indexes (we call \makevalueexpandable in \indexdummies).
+% The command has to be fully expandable (if the variable is set), since
+% the result winds up in the index file.  This means that if the
+% variable's value contains other Texinfo commands, it's almost certain
+% it will fail (although perhaps we could fix that with sufficient work
+% to do a one-level expansion on the result, instead of complete).
 %
 \def\expandablevalue#1{%
   \expandafter\ifx\csname SET#1\endcsname\relax
@@ -2871,55 +2933,36 @@
 % @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
 % with @set.
 %
-\def\ifset{\parsearg\doifset}
-\def\doifset#1{%
-  \expandafter\ifx\csname SET#1\endcsname\relax
-    \let\next=\ifsetfail
-  \else
-    \let\next=\ifsetsucceed
-  \fi
-  \next
+% To get special treatment of `@end ifset,' call \makeond and the redefine.
+%
+\makecond{ifset}
+\def\ifset{\parsearg{\doifset{\let\next=\ifsetfail}}}
+\def\doifset#1#2{%
+  {%
+    \makevalueexpandable
+    \let\next=\empty
+    \expandafter\ifx\csname SET#2\endcsname\relax
+      #1% If not set, redefine \next.
+    \fi
+    \expandafter
+  }\next
 }
-\def\ifsetsucceed{\conditionalsucceed{ifset}}
-\def\ifsetfail{\nestedignore{ifset}}
-\defineunmatchedend{ifset}
+\def\ifsetfail{\doignore{ifset}}
 
 % @ifclear VAR ... @end ifclear reads the `...' iff VAR has never been
 % defined with @set, or has been undefined with @clear.
 %
-\def\ifclear{\parsearg\doifclear}
-\def\doifclear#1{%
-  \expandafter\ifx\csname SET#1\endcsname\relax
-    \let\next=\ifclearsucceed
-  \else
-    \let\next=\ifclearfail
-  \fi
-  \next
-}
-\def\ifclearsucceed{\conditionalsucceed{ifclear}}
-\def\ifclearfail{\nestedignore{ifclear}}
-\defineunmatchedend{ifclear}
-
-% @iftex, @ifnothtml, @ifnotinfo, @ifnotplaintext always succeed; we
-% read the text following, through the first @end iftex (etc.).  Make
-% `@end iftex' (etc.) valid only after an @iftex.
-%
-\def\iftex{\conditionalsucceed{iftex}}
-\def\ifnothtml{\conditionalsucceed{ifnothtml}}
-\def\ifnotinfo{\conditionalsucceed{ifnotinfo}}
-\def\ifnotplaintext{\conditionalsucceed{ifnotplaintext}}
-\defineunmatchedend{iftex}
-\defineunmatchedend{ifnothtml}
-\defineunmatchedend{ifnotinfo}
-\defineunmatchedend{ifnotplaintext}
-
-% True conditional.  Since \set globally defines its variables, we can
-% just start and end a group (to keep the @end definition undefined at
-% the outer level).
-%
-\def\conditionalsucceed#1{\begingroup
-  \expandafter\def\csname E#1\endcsname{\endgroup}%
-}
+% The `\else' inside the `\doifset' parameter is a trick to reuse the
+% above code: if the variable is not set, do nothing, if it is set,
+% then redefine \next to \ifclearfail.
+%
+\makecond{ifclear}
+\def\ifclear{\parsearg{\doifset{\else \let\next=\ifclearfail}}}
+\def\ifclearfail{\doignore{ifclear}}
+
+% @dircategory CATEGORY  -- specify a category of the dir file
+% which this file should belong to.  Ignore this in TeX.
+\let\dircategory=\comment
 
 % @defininfoenclose.
 \let\definfoenclose=\comment
@@ -3044,6 +3087,7 @@
   \def\definedummyletter##1{%
     \expandafter\def\csname ##1\endcsname{\realbackslash ##1}%
   }%
+  \let\definedummyaccent\definedummyletter
   %
   % Do the redefinitions.
   \commondummies
@@ -3066,6 +3110,7 @@
   \def\definedummyletter##1{%
     \expandafter\def\csname ##1\endcsname{@##1}%
   }%
+  \let\definedummyaccent\definedummyletter
   %
   % Do the redefinitions.
   \commondummies
@@ -3078,26 +3123,11 @@
   %
   \normalturnoffactive
   %
-  % Control letters and accents.
+  \commondummiesnofonts
+  %
   \definedummyletter{_}%
-  \definedummyletter{,}%
-  \definedummyletter{"}%
-  \definedummyletter{`}%
-  \definedummyletter{'}%
-  \definedummyletter{^}%
-  \definedummyletter{~}%
-  \definedummyletter{=}%
-  \definedummyword{u}%
-  \definedummyword{v}%
-  \definedummyword{H}%
-  \definedummyword{dotaccent}%
-  \definedummyword{ringaccent}%
-  \definedummyword{tieaccent}%
-  \definedummyword{ubaraccent}%
-  \definedummyword{udotaccent}%
-  \definedummyword{dotless}%
   %
-  % Other non-English letters.
+  % Non-English letters.
   \definedummyword{AA}%
   \definedummyword{AE}%
   \definedummyword{L}%
@@ -3109,6 +3139,10 @@
   \definedummyword{oe}%
   \definedummyword{o}%
   \definedummyword{ss}%
+  \definedummyword{exclamdown}%
+  \definedummyword{questiondown}%
+  \definedummyword{ordf}%
+  \definedummyword{ordm}%
   %
   % Although these internal commands shouldn't show up, sometimes they do.
   \definedummyword{bf}%
@@ -3120,37 +3154,14 @@
   \definedummyword{tclose}%
   \definedummyword{tt}%
   %
-  % Texinfo font commands.
-  \definedummyword{b}%
-  \definedummyword{i}%
-  \definedummyword{r}%
-  \definedummyword{sc}%
-  \definedummyword{t}%
-  %
+  \definedummyword{LaTeX}%
   \definedummyword{TeX}%
-  \definedummyword{acronym}%
-  \definedummyword{cite}%
-  \definedummyword{code}%
-  \definedummyword{command}%
-  \definedummyword{dfn}%
-  \definedummyword{dots}%
-  \definedummyword{emph}%
-  \definedummyword{env}%
-  \definedummyword{file}%
-  \definedummyword{kbd}%
-  \definedummyword{key}%
-  \definedummyword{math}%
-  \definedummyword{option}%
-  \definedummyword{samp}%
-  \definedummyword{strong}%
-  \definedummyword{uref}%
-  \definedummyword{url}%
-  \definedummyword{var}%
-  \definedummyword{w}%
   %
   % Assorted special characters.
   \definedummyword{bullet}%
+  \definedummyword{comma}%
   \definedummyword{copyright}%
+  \definedummyword{registeredsymbol}%
   \definedummyword{dots}%
   \definedummyword{enddots}%
   \definedummyword{equiv}%
@@ -3162,10 +3173,9 @@
   \definedummyword{print}%
   \definedummyword{result}%
   %
-  % Handle some cases of @value -- where the variable name does not
-  % contain - or _, and the value does not contain any
+  % Handle some cases of @value -- where it does not contain any
   % (non-fully-expandable) commands.
-  \let\value = \expandablevalue
+  \makevalueexpandable
   %
   % Normal spaces, not active ones.
   \unsepspaces
@@ -3174,45 +3184,97 @@
   \turnoffmacros
 }
 
-% If an index command is used in an @example environment, any spaces
-% therein should become regular spaces in the raw index file, not the
-% expansion of \tie (\leavevmode \penalty \@M \ ).
-{\obeyspaces
- \gdef\unsepspaces{\obeyspaces\let =\space}}
-
+% \commondummiesnofonts: common to \commondummies and \indexnofonts.
+%
+% Better have this without active chars.
+{
+  \catcode`\~=\other
+  \gdef\commondummiesnofonts{%
+    % Control letters and accents.
+    \definedummyletter{!}%
+    \definedummyaccent{"}%
+    \definedummyaccent{'}%
+    \definedummyletter{*}%
+    \definedummyaccent{,}%
+    \definedummyletter{.}%
+    \definedummyletter{/}%
+    \definedummyletter{:}%
+    \definedummyaccent{=}%
+    \definedummyletter{?}%
+    \definedummyaccent{^}%
+    \definedummyaccent{`}%
+    \definedummyaccent{~}%
+    \definedummyword{u}%
+    \definedummyword{v}%
+    \definedummyword{H}%
+    \definedummyword{dotaccent}%
+    \definedummyword{ringaccent}%
+    \definedummyword{tieaccent}%
+    \definedummyword{ubaraccent}%
+    \definedummyword{udotaccent}%
+    \definedummyword{dotless}%
+    %
+    % Texinfo font commands.
+    \definedummyword{b}%
+    \definedummyword{i}%
+    \definedummyword{r}%
+    \definedummyword{sc}%
+    \definedummyword{t}%
+    %
+    % Commands that take arguments.
+    \definedummyword{acronym}%
+    \definedummyword{cite}%
+    \definedummyword{code}%
+    \definedummyword{command}%
+    \definedummyword{dfn}%
+    \definedummyword{emph}%
+    \definedummyword{env}%
+    \definedummyword{file}%
+    \definedummyword{kbd}%
+    \definedummyword{key}%
+    \definedummyword{math}%
+    \definedummyword{option}%
+    \definedummyword{samp}%
+    \definedummyword{strong}%
+    \definedummyword{tie}%
+    \definedummyword{uref}%
+    \definedummyword{url}%
+    \definedummyword{var}%
+    \definedummyword{verb}%
+    \definedummyword{w}%
+  }
+}
 
 % \indexnofonts is used when outputting the strings to sort the index
 % by, and when constructing control sequence names.  It eliminates all
 % control sequences and just writes whatever the best ASCII sort string
 % would be for a given command (usually its argument).
 %
-\def\indexdummytex{TeX}
-\def\indexdummydots{...}
-%
 \def\indexnofonts{%
+  % Accent commands should become @asis.
+  \def\definedummyaccent##1{%
+    \expandafter\let\csname ##1\endcsname\asis
+  }%
+  % We can just ignore other control letters.
+  \def\definedummyletter##1{%
+    \expandafter\def\csname ##1\endcsname{}%
+  }%
+  % Hopefully, all control words can become @asis.
+  \let\definedummyword\definedummyaccent
+  %
+  \commondummiesnofonts
+  %
+  % Don't no-op \tt, since it isn't a user-level command
+  % and is used in the definitions of the active chars like <, >, |, etc.
+  % Likewise with the other plain tex font commands.
+  %\let\tt=\asis
+  %
   \def\ { }%
   \def\@{@}%
   % how to handle braces?
   \def\_{\normalunderscore}%
   %
-  \let\,=\asis
-  \let\"=\asis
-  \let\`=\asis
-  \let\'=\asis
-  \let\^=\asis
-  \let\~=\asis
-  \let\==\asis
-  \let\u=\asis
-  \let\v=\asis
-  \let\H=\asis
-  \let\dotaccent=\asis
-  \let\ringaccent=\asis
-  \let\tieaccent=\asis
-  \let\ubaraccent=\asis
-  \let\udotaccent=\asis
-  \let\dotless=\asis
-  %
-  % Other non-English letters.
+  % Non-English letters.
   \def\AA{AA}%
   \def\AE{AE}%
   \def\L{L}%
@@ -3226,130 +3288,169 @@
   \def\ss{ss}%
   \def\exclamdown{!}%
   \def\questiondown{?}%
+  \def\ordf{a}%
+  \def\ordm{o}%
   %
-  % Don't no-op \tt, since it isn't a user-level command
-  % and is used in the definitions of the active chars like <, >, |, etc.
-  % Likewise with the other plain tex font commands.
-  %\let\tt=\asis
+  \def\LaTeX{LaTeX}%
+  \def\TeX{TeX}%
+  %
+  % Assorted special characters.
+  % (The following {} will end up in the sort string, but that's ok.)
+  \def\bullet{bullet}%
+  \def\comma{,}%
+  \def\copyright{copyright}%
+  \def\registeredsymbol{R}%
+  \def\dots{...}%
+  \def\enddots{...}%
+  \def\equiv{==}%
+  \def\error{error}%
+  \def\expansion{==>}%
+  \def\minus{-}%
+  \def\pounds{pounds}%
+  \def\point{.}%
+  \def\print{-|}%
+  \def\result{=>}%
   %
-  % Texinfo font commands.
-  \let\b=\asis
-  \let\i=\asis
-  \let\r=\asis
-  \let\sc=\asis
-  \let\t=\asis
-  %
-  \let\TeX=\indexdummytex
-  \let\acronym=\asis
-  \let\cite=\asis
-  \let\code=\asis
-  \let\command=\asis
-  \let\dfn=\asis
-  \let\dots=\indexdummydots
-  \let\emph=\asis
-  \let\env=\asis
-  \let\file=\asis
-  \let\kbd=\asis
-  \let\key=\asis
-  \let\math=\asis
-  \let\option=\asis
-  \let\samp=\asis
-  \let\strong=\asis
-  \let\uref=\asis
-  \let\url=\asis
-  \let\var=\asis
-  \let\w=\asis
+  % Don't write macro names.
+  \emptyusermacros
 }
 
 \let\indexbackslash=0  %overridden during \printindex.
 \let\SETmarginindex=\relax % put index entries in margin (undocumented)?
 
-% For \ifx comparisons.
-\def\emptymacro{\empty}
-
 % Most index entries go through here, but \dosubind is the general case.
-%
-\def\doind#1#2{\dosubind{#1}{#2}\empty}
+% #1 is the index name, #2 is the entry text.
+\def\doind#1#2{\dosubind{#1}{#2}{}}
 
 % Workhorse for all \fooindexes.
 % #1 is name of index, #2 is stuff to put there, #3 is subentry --
-% \empty if called from \doind, as we usually are.  The main exception
-% is with defuns, which call us directly.
+% empty if called from \doind, as we usually are (the main exception
+% is with most defuns, which call us directly).
 %
 \def\dosubind#1#2#3{%
+  \iflinks
+  {%
+    % Store the main index entry text (including the third arg).
+    \toks0 = {#2}%
+    % If third arg is present, precede it with a space.
+    \def\thirdarg{#3}%
+    \ifx\thirdarg\empty \else
+      \toks0 = \expandafter{\the\toks0 \space #3}%
+    \fi
+    %
+    \edef\writeto{\csname#1indfile\endcsname}%
+    %
+    \ifvmode
+      \dosubindsanitize
+    \else
+      \dosubindwrite
+    \fi
+  }%
+  \fi
+}
+
+% Write the entry in \toks0 to the index file:
+%
+\def\dosubindwrite{%
   % Put the index entry in the margin if desired.
   \ifx\SETmarginindex\relax\else
-    \insert\margin{\hbox{\vrule height8pt depth3pt width0pt #2}}%
+    \insert\margin{\hbox{\vrule height8pt depth3pt width0pt \the\toks0}}%
   \fi
-  {%
-    \count255=\lastpenalty
-    {%
-      \indexdummies % Must do this here, since \bf, etc expand at this stage
-      \escapechar=`\\
-      {%
-        \let\folio = 0% We will expand all macros now EXCEPT \folio.
-        \def\rawbackslashxx{\indexbackslash}% \indexbackslash isn't defined now
-        % so it will be output as is; and it will print as backslash.
-        %
-        % The main index entry text.
-        \toks0 = {#2}%
-        %
-        % If third arg is present, precede it with space in sort key.
-        \def\thirdarg{#3}%
-        \ifx\thirdarg\emptymacro \else
-           % If the third (subentry) arg is present, add it to the index
-           % line to write.
-          \toks0 = \expandafter{\the\toks0 \space #3}%
-        \fi
-        %
-        % Process the index entry with all font commands turned off, to
-        % get the string to sort by.
-        {\indexnofonts
-         \edef\temp{\the\toks0}% need full expansion
-         \xdef\indexsorttmp{\temp}%
-        }%
-        %
-        % Set up the complete index entry, with both the sort key and
-        % the original text, including any font commands.  We write
-        % three arguments to \entry to the .?? file (four in the
-        % subentry case), texindex reduces to two when writing the .??s
-        % sorted result.
-        \edef\temp{%
-          \write\csname#1indfile\endcsname{%
-            \realbackslash entry{\indexsorttmp}{\folio}{\the\toks0}}%
-        }%
-        %
-        % If a skip is the last thing on the list now, preserve it
-        % by backing up by \lastskip, doing the \write, then inserting
-        % the skip again.  Otherwise, the whatsit generated by the
-        % \write will make \lastskip zero.  The result is that sequences
-        % like this:
-        % @end defun
-        % @tindex whatever
-        % @defun ...
-        % will have extra space inserted, because the \medbreak in the
-        % start of the @defun won't see the skip inserted by the @end of
-        % the previous defun.
-        %
-        % But don't do any of this if we're not in vertical mode.  We
-        % don't want to do a \vskip and prematurely end a paragraph.
-        %
-        % Avoid page breaks due to these extra skips, too.
-        %
-        \iflinks
-          \ifvmode
-            \skip0 = \lastskip
-            \ifdim\lastskip = 0pt \else \nobreak\vskip-\skip0 \fi
-          \fi
-          %
-          \temp % do the write
-          %
-          \ifvmode \ifdim\skip0 = 0pt \else \nobreak\vskip\skip0 \fi \fi
-        \fi
-      }%
-    }%
-    \penalty\count255
+  %
+  % Remember, we are within a group.
+  \indexdummies % Must do this here, since \bf, etc expand at this stage
+  \escapechar=`\\
+  \def\backslashcurfont{\indexbackslash}% \indexbackslash isn't defined now
+      % so it will be output as is; and it will print as backslash.
+  %
+  % Process the index entry with all font commands turned off, to
+  % get the string to sort by.
+  {\indexnofonts
+   \edef\temp{\the\toks0}% need full expansion
+   \xdef\indexsorttmp{\temp}%
+  }%
+  %
+  % Set up the complete index entry, with both the sort key and
+  % the original text, including any font commands.  We write
+  % three arguments to \entry to the .?? file (four in the
+  % subentry case), texindex reduces to two when writing the .??s
+  % sorted result.
+  \edef\temp{%
+    \write\writeto{%
+      \string\entry{\indexsorttmp}{\noexpand\folio}{\the\toks0}}%
   }%
+  \temp
+}
+
+% Take care of unwanted page breaks:
+%
+% If a skip is the last thing on the list now, preserve it
+% by backing up by \lastskip, doing the \write, then inserting
+% the skip again.  Otherwise, the whatsit generated by the
+% \write will make \lastskip zero.  The result is that sequences
+% like this:
+% @end defun
+% @tindex whatever
+% @defun ...
+% will have extra space inserted, because the \medbreak in the
+% start of the @defun won't see the skip inserted by the @end of
+% the previous defun.
+%
+% But don't do any of this if we're not in vertical mode.  We
+% don't want to do a \vskip and prematurely end a paragraph.
+%
+% Avoid page breaks due to these extra skips, too.
+%
+% But wait, there is a catch there:
+% We'll have to check whether \lastskip is zero skip.  \ifdim is not
+% sufficient for this purpose, as it ignores stretch and shrink parts
+% of the skip.  The only way seems to be to check the textual
+% representation of the skip.
+%
+% The following is almost like \def\zeroskipmacro{0.0pt} except that
+% the ``p'' and ``t'' characters have catcode \other, not 11 (letter).
+%
+\edef\zeroskipmacro{\expandafter\the\csname z at skip\endcsname}
+%
+% ..., ready, GO:
+%
+\def\dosubindsanitize{%
+  % \lastskip and \lastpenalty cannot both be nonzero simultaneously.
+  \skip0 = \lastskip
+  \edef\lastskipmacro{\the\lastskip}%
+  \count255 = \lastpenalty
+  %
+  % If \lastskip is nonzero, that means the last item was a
+  % skip.  And since a skip is discardable, that means this
+  % -\skip0 glue we're inserting is preceded by a
+  % non-discardable item, therefore it is not a potential
+  % breakpoint, therefore no \nobreak needed.
+  \ifx\lastskipmacro\zeroskipmacro
+  \else
+    \vskip-\skip0
+  \fi
+  %
+  \dosubindwrite
+  %
+  \ifx\lastskipmacro\zeroskipmacro
+    % If \lastskip was zero, perhaps the last item was a penalty, and
+    % perhaps it was >=10000, e.g., a \nobreak.  In that case, we want
+    % to re-insert the same penalty (values >10000 are used for various
+    % signals); since we just inserted a non-discardable item, any
+    % following glue (such as a \parskip) would be a breakpoint.  For example:
+    % 
+    %   @deffn deffn-whatever
+    %   @vindex index-whatever
+    %   Description.
+    % would allow a break between the index-whatever whatsit
+    % and the "Description." paragraph.
+    \ifnum\count255>9999 \penalty\count255 \fi
+  \else
+    % On the other hand, if we had a nonzero \lastskip,
+    % this make-up glue would be preceded by a non-discardable item
+    % (the whatsit from the \write), so we must insert a \nobreak.
+    \nobreak\vskip\skip0
+  \fi
 }
 
 % The index entry written in the file actually looks like
@@ -3387,14 +3488,12 @@
 % @printindex causes a particular index (the ??s file) to get printed.
 % It does not print any chapter heading (usually an @unnumbered).
 %
-\def\printindex{\parsearg\doprintindex}
-\def\doprintindex#1{\begingroup
+\parseargdef\printindex{\begingroup
   \dobreak \chapheadingskip{10000}%
   %
   \smallfonts \rm
   \tolerance = 9500
   \everypar = {}% don't want the \kern\-parindent from indentation suppression.
-  \indexbreaks
   %
   % See if the index file exists and is nonempty.
   % Change catcode of @ here so that if the index file contains
@@ -3421,7 +3520,7 @@
       % Index files are almost Texinfo source, but we use \ as the escape
       % character.  It would be better to use @, but that's too big a change
       % to make right now.
-      \def\indexbackslash{\rawbackslashxx}%
+      \def\indexbackslash{\backslashcurfont}%
       \catcode`\\ = 0
       \escapechar = `\\
       \begindoublecolumns
@@ -3443,7 +3542,10 @@
   \removelastskip
   %
   % We like breaks before the index initials, so insert a bonus.
-  \penalty -300
+  \nobreak
+  \vskip 0pt plus 3\baselineskip
+  \penalty 0
+  \vskip 0pt plus -3\baselineskip
   %
   % Typeset the initial.  Making this add up to a whole number of
   % baselineskips increases the chance of the dots lining up from column
@@ -3453,80 +3555,100 @@
   % No shrink because it confuses \balancecolumns.
   \vskip 1.67\baselineskip plus .5\baselineskip
   \leftline{\secbf #1}%
-  \vskip .33\baselineskip plus .1\baselineskip
-  %
   % Do our best not to break after the initial.
   \nobreak
+  \vskip .33\baselineskip plus .1\baselineskip
 }}
 
-% This typesets a paragraph consisting of #1, dot leaders, and then #2
-% flush to the right margin.  It is used for index and table of contents
-% entries.  The paragraph is indented by \leftskip.
-%
-\def\entry#1#2{\begingroup
-  %
-  % Start a new paragraph if necessary, so our assignments below can't
-  % affect previous text.
-  \par
-  %
-  % Do not fill out the last line with white space.
-  \parfillskip = 0in
-  %
-  % No extra space above this paragraph.
-  \parskip = 0in
-  %
-  % Do not prefer a separate line ending with a hyphen to fewer lines.
-  \finalhyphendemerits = 0
-  %
-  % \hangindent is only relevant when the entry text and page number
-  % don't both fit on one line.  In that case, bob suggests starting the
-  % dots pretty far over on the line.  Unfortunately, a large
-  % indentation looks wrong when the entry text itself is broken across
-  % lines.  So we use a small indentation and put up with long leaders.
-  %
-  % \hangafter is reset to 1 (which is the value we want) at the start
-  % of each paragraph, so we need not do anything with that.
-  \hangindent = 2em
-  %
-  % When the entry text needs to be broken, just fill out the first line
-  % with blank space.
-  \rightskip = 0pt plus1fil
-  %
-  % A bit of stretch before each entry for the benefit of balancing columns.
-  \vskip 0pt plus1pt
-  %
-  % Start a ``paragraph'' for the index entry so the line breaking
-  % parameters we've set above will have an effect.
-  \noindent
-  %
-  % Insert the text of the index entry.  TeX will do line-breaking on it.
-  #1%
-  % The following is kludged to not output a line of dots in the index if
-  % there are no page numbers.  The next person who breaks this will be
-  % cursed by a Unix daemon.
-  \def\tempa{{\rm }}%
-  \def\tempb{#2}%
-  \edef\tempc{\tempa}%
-  \edef\tempd{\tempb}%
-  \ifx\tempc\tempd\ \else%
-    %
-    % If we must, put the page number on a line of its own, and fill out
-    % this line with blank space.  (The \hfil is overwhelmed with the
-    % fill leaders glue in \indexdotfill if the page number does fit.)
-    \hfil\penalty50
-    \null\nobreak\indexdotfill % Have leaders before the page number.
-    %
-    % The `\ ' here is removed by the implicit \unskip that TeX does as
-    % part of (the primitive) \par.  Without it, a spurious underfull
-    % \hbox ensues.
-    \ifpdf
-      \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
+% \entry typesets a paragraph consisting of the text (#1), dot leaders, and
+% then page number (#2) flushed to the right margin.  It is used for index
+% and table of contents entries.  The paragraph is indented by \leftskip.
+%
+% A straightforward implementation would start like this:
+%	\def\entry#1#2{...
+% But this frozes the catcodes in the argument, and can cause problems to
+% @code, which sets - active.  This problem was fixed by a kludge---
+% ``-'' was active throughout whole index, but this isn't really right.
+%
+% The right solution is to prevent \entry from swallowing the whole text.
+%                                 --kasal, 21nov03
+\def\entry{%
+  \begingroup
+    %
+    % Start a new paragraph if necessary, so our assignments below can't
+    % affect previous text.
+    \par
+    %
+    % Do not fill out the last line with white space.
+    \parfillskip = 0in
+    %
+    % No extra space above this paragraph.
+    \parskip = 0in
+    %
+    % Do not prefer a separate line ending with a hyphen to fewer lines.
+    \finalhyphendemerits = 0
+    %
+    % \hangindent is only relevant when the entry text and page number
+    % don't both fit on one line.  In that case, bob suggests starting the
+    % dots pretty far over on the line.  Unfortunately, a large
+    % indentation looks wrong when the entry text itself is broken across
+    % lines.  So we use a small indentation and put up with long leaders.
+    %
+    % \hangafter is reset to 1 (which is the value we want) at the start
+    % of each paragraph, so we need not do anything with that.
+    \hangindent = 2em
+    %
+    % When the entry text needs to be broken, just fill out the first line
+    % with blank space.
+    \rightskip = 0pt plus1fil
+    %
+    % A bit of stretch before each entry for the benefit of balancing
+    % columns.
+    \vskip 0pt plus1pt
+    %
+    % Swallow the left brace of the text (first parameter):
+    \afterassignment\doentry
+    \let\temp =
+}
+\def\doentry{%
+    \bgroup % Instead of the swallowed brace.
+      \noindent
+      \aftergroup\finishentry
+      % And now comes the text of the entry.
+}
+\def\finishentry#1{%
+    % #1 is the page number.
+    %
+    % The following is kludged to not output a line of dots in the index if
+    % there are no page numbers.  The next person who breaks this will be
+    % cursed by a Unix daemon.
+    \def\tempa{{\rm }}%
+    \def\tempb{#1}%
+    \edef\tempc{\tempa}%
+    \edef\tempd{\tempb}%
+    \ifx\tempc\tempd
+      \ %
     \else
-      \ #2% The page number ends the paragraph.
+      %
+      % If we must, put the page number on a line of its own, and fill out
+      % this line with blank space.  (The \hfil is overwhelmed with the
+      % fill leaders glue in \indexdotfill if the page number does fit.)
+      \hfil\penalty50
+      \null\nobreak\indexdotfill % Have leaders before the page number.
+      %
+      % The `\ ' here is removed by the implicit \unskip that TeX does as
+      % part of (the primitive) \par.  Without it, a spurious underfull
+      % \hbox ensues.
+      \ifpdf
+	\pdfgettoks#1.%
+	\ \the\toksA
+      \else
+	\ #1%
+      \fi
     \fi
-  \fi%
-  \par
-\endgroup}
+    \par
+  \endgroup
+}
 
 % Like \dotfill except takes at least 1 em.
 \def\indexdotfill{\cleaders
@@ -3695,6 +3817,12 @@
 \message{sectioning,}
 % Chapters, sections, etc.
 
+% \unnumberedno is an oxymoron, of course.  But we count the unnumbered
+% sections so that we can refer to them unambiguously in the pdf
+% outlines by their "section number".  We avoid collisions with chapter
+% numbers by starting them at 10000.  (If a document ever has 10000
+% chapters, we're in trouble anyway, I'm sure.)
+\newcount\unnumberedno \unnumberedno = 10000
 \newcount\chapno
 \newcount\secno        \secno=0
 \newcount\subsecno     \subsecno=0
@@ -3702,9 +3830,12 @@
 
 % This counter is funny since it counts through charcodes of letters A, B, ...
 \newcount\appendixno  \appendixno = `\@
+%
 % \def\appendixletter{\char\the\appendixno}
-% We do the following for the sake of pdftex, which needs the actual
+% We do the following ugly conditional instead of the above simple
+% construct for the sake of pdftex, which needs the actual
 % letter in the expansion, not just typeset.
+%
 \def\appendixletter{%
   \ifnum\appendixno=`A A%
   \else\ifnum\appendixno=`B B%
@@ -3742,11 +3873,12 @@
 
 % Each @chapter defines this as the name of the chapter.
 % page headings and footings can use it.  @section does likewise.
+% However, they are not reliable, because we don't use marks.
 \def\thischapter{}
 \def\thissection{}
 
 \newcount\absseclevel % used to calculate proper heading level
-\newcount\secbase\secbase=0 % @raise/lowersections modify this count
+\newcount\secbase\secbase=0 % @raisesections/@lowersections modify this count
 
 % @raisesections: treat @section as chapter, @subsection as section, etc.
 \def\raisesections{\global\advance\secbase by -1}
@@ -3756,121 +3888,142 @@
 \def\lowersections{\global\advance\secbase by 1}
 \let\down=\lowersections % original BFox name
 
-% Choose a numbered-heading macro
-% #1 is heading level if unmodified by @raisesections or @lowersections
-% #2 is text for heading
-\def\numhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
-\ifcase\absseclevel
-  \chapterzzz{#2}
-\or
-  \seczzz{#2}
-\or
-  \numberedsubseczzz{#2}
-\or
-  \numberedsubsubseczzz{#2}
-\else
-  \ifnum \absseclevel<0
-    \chapterzzz{#2}
+% we only have subsub.
+\chardef\maxseclevel = 3
+%
+% A numbered section within an unnumbered changes to unnumbered too.
+% To achive this, remember the "biggest" unnum. sec. we are currently in:
+\chardef\unmlevel = \maxseclevel
+%
+% Trace whether the current chapter is an appendix or not:
+% \chapheadtype is "N" or "A", unnumbered chapters are ignored.
+\def\chapheadtype{N}
+
+% Choose a heading macro
+% #1 is heading type
+% #2 is heading level
+% #3 is text for heading
+\def\genhead#1#2#3{%
+  % Compute the abs. sec. level:
+  \absseclevel=#2
+  \advance\absseclevel by \secbase
+  % Make sure \absseclevel doesn't fall outside the range:
+  \ifnum \absseclevel < 0
+    \absseclevel = 0
   \else
-    \numberedsubsubseczzz{#2}
+    \ifnum \absseclevel > 3
+      \absseclevel = 3
+    \fi
   \fi
-\fi
-\suppressfirstparagraphindent
-}
-
-% like \numhead, but chooses appendix heading levels
-\def\apphead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
-\ifcase\absseclevel
-  \appendixzzz{#2}
-\or
-  \appendixsectionzzz{#2}
-\or
-  \appendixsubseczzz{#2}
-\or
-  \appendixsubsubseczzz{#2}
-\else
-  \ifnum \absseclevel<0
-    \appendixzzz{#2}
+  % The heading type:
+  \def\headtype{#1}%
+  \if \headtype U%
+    \ifnum \absseclevel < \unmlevel
+      \chardef\unmlevel = \absseclevel
+    \fi
   \else
-    \appendixsubsubseczzz{#2}
+    % Check for appendix sections:
+    \ifnum \absseclevel = 0
+      \edef\chapheadtype{\headtype}%
+    \else
+      \if \headtype A\if \chapheadtype N%
+	\errmessage{@appendix... within a non-appendix chapter}%
+      \fi\fi
+    \fi
+    % Check for numbered within unnumbered:
+    \ifnum \absseclevel > \unmlevel
+      \def\headtype{U}%
+    \else
+      \chardef\unmlevel = 3
+    \fi
   \fi
-\fi
-\suppressfirstparagraphindent
-}
-
-% like \numhead, but chooses numberless heading levels
-\def\unnmhead#1#2{\absseclevel=\secbase\advance\absseclevel by #1
-\ifcase\absseclevel
-  \unnumberedzzz{#2}
-\or
-  \unnumberedseczzz{#2}
-\or
-  \unnumberedsubseczzz{#2}
-\or
-  \unnumberedsubsubseczzz{#2}
-\else
-  \ifnum \absseclevel<0
-    \unnumberedzzz{#2}
+  % Now print the heading:
+  \if \headtype U%
+    \ifcase\absseclevel
+	\unnumberedzzz{#3}%
+    \or \unnumberedseczzz{#3}%
+    \or \unnumberedsubseczzz{#3}%
+    \or \unnumberedsubsubseczzz{#3}%
+    \fi
   \else
-    \unnumberedsubsubseczzz{#2}
+    \if \headtype A%
+      \ifcase\absseclevel
+	  \appendixzzz{#3}%
+      \or \appendixsectionzzz{#3}%
+      \or \appendixsubseczzz{#3}%
+      \or \appendixsubsubseczzz{#3}%
+      \fi
+    \else
+      \ifcase\absseclevel
+	  \chapterzzz{#3}%
+      \or \seczzz{#3}%
+      \or \numberedsubseczzz{#3}%
+      \or \numberedsubsubseczzz{#3}%
+      \fi
+    \fi
   \fi
-\fi
-\suppressfirstparagraphindent
+  \suppressfirstparagraphindent
 }
 
-% @chapter, @appendix, @unnumbered.
-\def\thischaptername{No Chapter Title}
-\outer\def\chapter{\parsearg\chapteryyy}
-\def\chapteryyy #1{\numhead0{#1}} % normally numhead0 calls chapterzzz
-\def\chapterzzz #1{%
-  \secno=0 \subsecno=0 \subsubsecno=0
-  \global\advance \chapno by 1 \message{\putwordChapter\space \the\chapno}%
-  \chapmacro {#1}{\the\chapno}%
-  \gdef\thissection{#1}%
-  \gdef\thischaptername{#1}%
-  % We don't substitute the actual chapter name into \thischapter
-  % because we don't want its macros evaluated now.
-  \xdef\thischapter{\putwordChapter{} \the\chapno: \noexpand\thischaptername}%
-  \writetocentry{chap}{#1}{{\the\chapno}}
-  \donoderef
+% an interface:
+\def\numhead{\genhead N}
+\def\apphead{\genhead A}
+\def\unnmhead{\genhead U}
+
+% @chapter, @appendix, @unnumbered.  Increment top-level counter, reset
+% all lower-level sectioning counters to zero.
+%
+% Also set \chaplevelprefix, which we prepend to @float sequence numbers
+% (e.g., figures), q.v.  By default (before any chapter), that is empty.
+\let\chaplevelprefix = \empty
+%
+\outer\parseargdef\chapter{\numhead0{#1}} % normally numhead0 calls chapterzzz
+\def\chapterzzz#1{%
+  % section resetting is \global in case the chapter is in a group, such
+  % as an @include file.
+  \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
+    \global\advance\chapno by 1
+  %
+  % Used for \float.
+  \gdef\chaplevelprefix{\the\chapno.}%
+  \resetallfloatnos
+  %
+  \message{\putwordChapter\space \the\chapno}%
+  %
+  % Write the actual heading.
+  \chapmacro{#1}{Ynumbered}{\the\chapno}%
+  %
+  % So @section and the like are numbered underneath this chapter.
   \global\let\section = \numberedsec
   \global\let\subsection = \numberedsubsec
   \global\let\subsubsection = \numberedsubsubsec
 }
 
-% we use \chapno to avoid indenting back
-\def\appendixbox#1{%
-  \setbox0 = \hbox{\putwordAppendix{} \the\chapno}%
-  \hbox to \wd0{#1\hss}}
-
-\outer\def\appendix{\parsearg\appendixyyy}
-\def\appendixyyy #1{\apphead0{#1}} % normally apphead0 calls appendixzzz
-\def\appendixzzz #1{%
-  \secno=0 \subsecno=0 \subsubsecno=0
-  \global\advance \appendixno by 1
-  \message{\putwordAppendix\space \appendixletter}%
-  \chapmacro {#1}{\appendixbox{\putwordAppendix{} \appendixletter}}%
-  \gdef\thissection{#1}%
-  \gdef\thischaptername{#1}%
-  \xdef\thischapter{\putwordAppendix{} \appendixletter: \noexpand\thischaptername}%
-  \writetocentry{appendix}{#1}{{\appendixletter}}
-  \appendixnoderef
+\outer\parseargdef\appendix{\apphead0{#1}} % normally apphead0 calls appendixzzz
+\def\appendixzzz#1{%
+  \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
+    \global\advance\appendixno by 1
+  \gdef\chaplevelprefix{\appendixletter.}%
+  \resetallfloatnos
+  %
+  \def\appendixnum{\putwordAppendix\space \appendixletter}%
+  \message{\appendixnum}%
+  %
+  \chapmacro{#1}{Yappendix}{\appendixletter}%
+  %
   \global\let\section = \appendixsec
   \global\let\subsection = \appendixsubsec
   \global\let\subsubsection = \appendixsubsubsec
 }
 
-% @centerchap is like @unnumbered, but the heading is centered.
-\outer\def\centerchap{\parsearg\centerchapyyy}
-\def\centerchapyyy #1{{\let\unnumbchapmacro=\centerchapmacro \unnumberedyyy{#1}}}
-
-% @top is like @unnumbered.
-\outer\def\top{\parsearg\unnumberedyyy}
-
-\outer\def\unnumbered{\parsearg\unnumberedyyy}
-\def\unnumberedyyy #1{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
-\def\unnumberedzzz #1{%
-  \secno=0 \subsecno=0 \subsubsecno=0
+\outer\parseargdef\unnumbered{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
+\def\unnumberedzzz#1{%
+  \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
+    \global\advance\unnumberedno by 1
+  %
+  % Since an unnumbered has no number, no prefix for figures.
+  \global\let\chaplevelprefix = \empty
+  \resetallfloatnos
   %
   % This used to be simply \message{#1}, but TeX fully expands the
   % argument to \message.  Therefore, if #1 contained @-commands, TeX
@@ -3883,134 +4036,98 @@
   % \the<toks register> to achieve this: TeX expands \the<toks> only once,
   % simply yielding the contents of <toks register>.  (We also do this for
   % the toc entries.)
-  \toks0 = {#1}\message{(\the\toks0)}%
+  \toks0 = {#1}%
+  \message{(\the\toks0)}%
+  %
+  \chapmacro{#1}{Ynothing}{\the\unnumberedno}%
   %
-  \unnumbchapmacro {#1}%
-  \gdef\thischapter{#1}\gdef\thissection{#1}%
-  \writetocentry{unnumbchap}{#1}{{\the\chapno}}
-  \unnumbnoderef
   \global\let\section = \unnumberedsec
   \global\let\subsection = \unnumberedsubsec
   \global\let\subsubsection = \unnumberedsubsubsec
 }
 
-% Sections.
-\outer\def\numberedsec{\parsearg\secyyy}
-\def\secyyy #1{\numhead1{#1}} % normally calls seczzz
-\def\seczzz #1{%
-  \subsecno=0 \subsubsecno=0 \global\advance \secno by 1 %
-  \gdef\thissection{#1}\secheading {#1}{\the\chapno}{\the\secno}%
-  \writetocentry{sec}{#1}{{\the\chapno}{\the\secno}}
-  \donoderef
-  \nobreak
+% @centerchap is like @unnumbered, but the heading is centered.
+\outer\parseargdef\centerchap{%
+  % Well, we could do the following in a group, but that would break
+  % an assumption that \chapmacro is called at the outermost level.
+  % Thus we are safer this way:		--kasal, 24feb04
+  \let\centerparametersmaybe = \centerparameters
+  \unnmhead0{#1}%
+  \let\centerparametersmaybe = \relax
 }
 
-\outer\def\appendixsection{\parsearg\appendixsecyyy}
-\outer\def\appendixsec{\parsearg\appendixsecyyy}
-\def\appendixsecyyy #1{\apphead1{#1}} % normally calls appendixsectionzzz
-\def\appendixsectionzzz #1{%
-  \subsecno=0 \subsubsecno=0 \global\advance \secno by 1 %
-  \gdef\thissection{#1}\secheading {#1}{\appendixletter}{\the\secno}%
-  \writetocentry{sec}{#1}{{\appendixletter}{\the\secno}}
-  \appendixnoderef
-  \nobreak
-}
+% @top is like @unnumbered.
+\let\top\unnumbered
 
-\outer\def\unnumberedsec{\parsearg\unnumberedsecyyy}
-\def\unnumberedsecyyy #1{\unnmhead1{#1}} % normally calls unnumberedseczzz
-\def\unnumberedseczzz #1{%
-  \plainsecheading {#1}\gdef\thissection{#1}%
-  \writetocentry{unnumbsec}{#1}{{\the\chapno}{\the\secno}}
-  \unnumbnoderef
-  \nobreak
+% Sections.
+\outer\parseargdef\numberedsec{\numhead1{#1}} % normally calls seczzz
+\def\seczzz#1{%
+  \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
+  \sectionheading{#1}{sec}{Ynumbered}{\the\chapno.\the\secno}%
+}
+
+\outer\parseargdef\appendixsection{\apphead1{#1}} % normally calls appendixsectionzzz
+\def\appendixsectionzzz#1{%
+  \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
+  \sectionheading{#1}{sec}{Yappendix}{\appendixletter.\the\secno}%
+}
+\let\appendixsec\appendixsection
+
+\outer\parseargdef\unnumberedsec{\unnmhead1{#1}} % normally calls unnumberedseczzz
+\def\unnumberedseczzz#1{%
+  \global\subsecno=0 \global\subsubsecno=0  \global\advance\secno by 1
+  \sectionheading{#1}{sec}{Ynothing}{\the\unnumberedno.\the\secno}%
 }
 
 % Subsections.
-\outer\def\numberedsubsec{\parsearg\numberedsubsecyyy}
-\def\numberedsubsecyyy #1{\numhead2{#1}} % normally calls numberedsubseczzz
-\def\numberedsubseczzz #1{%
-  \gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
-  \subsecheading {#1}{\the\chapno}{\the\secno}{\the\subsecno}%
-  \writetocentry{subsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}}
-  \donoderef
-  \nobreak
-}
-
-\outer\def\appendixsubsec{\parsearg\appendixsubsecyyy}
-\def\appendixsubsecyyy #1{\apphead2{#1}} % normally calls appendixsubseczzz
-\def\appendixsubseczzz #1{%
-  \gdef\thissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
-  \subsecheading {#1}{\appendixletter}{\the\secno}{\the\subsecno}%
-  \writetocentry{subsec}{#1}{{\appendixletter}{\the\secno}{\the\subsecno}}
-  \appendixnoderef
-  \nobreak
-}
-
-\outer\def\unnumberedsubsec{\parsearg\unnumberedsubsecyyy}
-\def\unnumberedsubsecyyy #1{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
-\def\unnumberedsubseczzz #1{%
-  \plainsubsecheading {#1}\gdef\thissection{#1}%
-  \writetocentry{unnumbsubsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}}
-  \unnumbnoderef
-  \nobreak
+\outer\parseargdef\numberedsubsec{\numhead2{#1}} % normally calls numberedsubseczzz
+\def\numberedsubseczzz#1{%
+  \global\subsubsecno=0  \global\advance\subsecno by 1
+  \sectionheading{#1}{subsec}{Ynumbered}{\the\chapno.\the\secno.\the\subsecno}%
+}
+
+\outer\parseargdef\appendixsubsec{\apphead2{#1}} % normally calls appendixsubseczzz
+\def\appendixsubseczzz#1{%
+  \global\subsubsecno=0  \global\advance\subsecno by 1
+  \sectionheading{#1}{subsec}{Yappendix}%
+                 {\appendixletter.\the\secno.\the\subsecno}%
+}
+
+\outer\parseargdef\unnumberedsubsec{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
+\def\unnumberedsubseczzz#1{%
+  \global\subsubsecno=0  \global\advance\subsecno by 1
+  \sectionheading{#1}{subsec}{Ynothing}%
+                 {\the\unnumberedno.\the\secno.\the\subsecno}%
 }
 
 % Subsubsections.
-\outer\def\numberedsubsubsec{\parsearg\numberedsubsubsecyyy}
-\def\numberedsubsubsecyyy #1{\numhead3{#1}} % normally numberedsubsubseczzz
-\def\numberedsubsubseczzz #1{%
-  \gdef\thissection{#1}\global\advance \subsubsecno by 1 %
-  \subsubsecheading {#1}
-    {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
-  \writetocentry{subsubsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}}
-  \donoderef
-  \nobreak
-}
-
-\outer\def\appendixsubsubsec{\parsearg\appendixsubsubsecyyy}
-\def\appendixsubsubsecyyy #1{\apphead3{#1}} % normally appendixsubsubseczzz
-\def\appendixsubsubseczzz #1{%
-  \gdef\thissection{#1}\global\advance \subsubsecno by 1 %
-  \subsubsecheading {#1}
-    {\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
-  \writetocentry{subsubsec}{#1}{{\appendixletter}{\the\secno}{\the\subsecno}{\the\subsubsecno}}
-  \appendixnoderef
-  \nobreak
-}
-
-\outer\def\unnumberedsubsubsec{\parsearg\unnumberedsubsubsecyyy}
-\def\unnumberedsubsubsecyyy #1{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
-\def\unnumberedsubsubseczzz #1{%
-  \plainsubsubsecheading {#1}\gdef\thissection{#1}%
-  \writetocentry{unnumbsubsubsec}{#1}{{\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}}
-  \unnumbnoderef
-  \nobreak
+\outer\parseargdef\numberedsubsubsec{\numhead3{#1}} % normally numberedsubsubseczzz
+\def\numberedsubsubseczzz#1{%
+  \global\advance\subsubsecno by 1
+  \sectionheading{#1}{subsubsec}{Ynumbered}%
+                 {\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno}%
+}
+
+\outer\parseargdef\appendixsubsubsec{\apphead3{#1}} % normally appendixsubsubseczzz
+\def\appendixsubsubseczzz#1{%
+  \global\advance\subsubsecno by 1
+  \sectionheading{#1}{subsubsec}{Yappendix}%
+                 {\appendixletter.\the\secno.\the\subsecno.\the\subsubsecno}%
+}
+
+\outer\parseargdef\unnumberedsubsubsec{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
+\def\unnumberedsubsubseczzz#1{%
+  \global\advance\subsubsecno by 1
+  \sectionheading{#1}{subsubsec}{Ynothing}%
+                 {\the\unnumberedno.\the\secno.\the\subsecno.\the\subsubsecno}%
 }
 
-% These are variants which are not "outer", so they can appear in @ifinfo.
-% Actually, they should now be obsolete; ordinary section commands should work.
-\def\infotop{\parsearg\unnumberedzzz}
-\def\infounnumbered{\parsearg\unnumberedzzz}
-\def\infounnumberedsec{\parsearg\unnumberedseczzz}
-\def\infounnumberedsubsec{\parsearg\unnumberedsubseczzz}
-\def\infounnumberedsubsubsec{\parsearg\unnumberedsubsubseczzz}
-
-\def\infoappendix{\parsearg\appendixzzz}
-\def\infoappendixsec{\parsearg\appendixseczzz}
-\def\infoappendixsubsec{\parsearg\appendixsubseczzz}
-\def\infoappendixsubsubsec{\parsearg\appendixsubsubseczzz}
-
-\def\infochapter{\parsearg\chapterzzz}
-\def\infosection{\parsearg\sectionzzz}
-\def\infosubsection{\parsearg\subsectionzzz}
-\def\infosubsubsection{\parsearg\subsubsectionzzz}
-
 % These macros control what the section commands do, according
 % to what kind of chapter we are in (ordinary, appendix, or unnumbered).
 % Define them by default for a numbered chapter.
-\global\let\section = \numberedsec
-\global\let\subsection = \numberedsubsec
-\global\let\subsubsection = \numberedsubsubsec
+\let\section = \numberedsec
+\let\subsection = \numberedsubsec
+\let\subsubsection = \numberedsubsubsec
 
 % Define @majorheading, @heading and @subheading
 
@@ -4023,23 +4140,27 @@
 %          if justification is not attempted.  Hence \raggedright.
 
 
-\def\majorheading{\parsearg\majorheadingzzz}
-\def\majorheadingzzz #1{%
+\def\majorheading{%
   {\advance\chapheadingskip by 10pt \chapbreak }%
-  {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
-                    \parindent=0pt\raggedright
-                    \rm #1\hfill}}\bigskip \par\penalty 200}
+  \parsearg\chapheadingzzz
+}
 
-\def\chapheading{\parsearg\chapheadingzzz}
-\def\chapheadingzzz #1{\chapbreak %
+\def\chapheading{\chapbreak \parsearg\chapheadingzzz}
+\def\chapheadingzzz#1{%
   {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
                     \parindent=0pt\raggedright
-                    \rm #1\hfill}}\bigskip \par\penalty 200}
+                    \rm #1\hfill}}%
+  \bigskip \par\penalty 200\relax
+  \suppressfirstparagraphindent
+}
 
 % @heading, @subheading, @subsubheading.
-\def\heading{\parsearg\plainsecheading}
-\def\subheading{\parsearg\plainsubsecheading}
-\def\subsubheading{\parsearg\plainsubsubsecheading}
+\parseargdef\heading{\sectionheading{#1}{sec}{Yomitfromtoc}{}
+  \suppressfirstparagraphindent}
+\parseargdef\subheading{\sectionheading{#1}{subsec}{Yomitfromtoc}{}
+  \suppressfirstparagraphindent}
+\parseargdef\subsubheading{\sectionheading{#1}{subsubsec}{Yomitfromtoc}{}
+  \suppressfirstparagraphindent}
 
 % These macros generate a chapter, section, etc. heading only
 % (including whitespace, linebreaking, etc. around it),
@@ -4048,8 +4169,6 @@
 %%% Args are the skip and penalty (usually negative)
 \def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
 
-\def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
-
 %%% Define plain chapter starts, and page on/off switching for it
 % Parameter controlling skip before chapter headings (if needed)
 
@@ -4072,7 +4191,7 @@
 \global\let\pagealignmacro=\chappager
 \global\def\HEADINGSon{\HEADINGSsingle}}
 
-\def\CHAPPAGodd{
+\def\CHAPPAGodd{%
 \global\let\contentsalignmacro = \chapoddpage
 \global\let\pchapsepmacro=\chapoddpage
 \global\let\pagealignmacro=\chapoddpage
@@ -4080,116 +4199,193 @@
 
 \CHAPPAGon
 
-\def\CHAPFplain{
-\global\let\chapmacro=\chfplain
-\global\let\unnumbchapmacro=\unnchfplain
-\global\let\centerchapmacro=\centerchfplain}
-
-% Plain chapter opening.
-% #1 is the text, #2 the chapter number or empty if unnumbered.
-\def\chfplain#1#2{%
+% Chapter opening.
+%
+% #1 is the text, #2 is the section type (Ynumbered, Ynothing,
+% Yappendix, Yomitfromtoc), #3 the chapter number.
+%
+% To test against our argument.
+\def\Ynothingkeyword{Ynothing}
+\def\Yomitfromtockeyword{Yomitfromtoc}
+\def\Yappendixkeyword{Yappendix}
+%
+\def\chapmacro#1#2#3{%
   \pchapsepmacro
   {%
     \chapfonts \rm
-    \def\chapnum{#2}%
-    \setbox0 = \hbox{#2\ifx\chapnum\empty\else\enspace\fi}%
+    %
+    % Have to define \thissection before calling \donoderef, because the
+    % xref code eventually uses it.  On the other hand, it has to be called
+    % after \pchapsepmacro, or the headline will change too soon.
+    \gdef\thissection{#1}%
+    \gdef\thischaptername{#1}%
+    %
+    % Only insert the separating space if we have a chapter/appendix
+    % number, and don't print the unnumbered ``number''.
+    \def\temptype{#2}%
+    \ifx\temptype\Ynothingkeyword
+      \setbox0 = \hbox{}%
+      \def\toctype{unnchap}%
+      \def\thischapter{#1}%
+    \else\ifx\temptype\Yomitfromtockeyword
+      \setbox0 = \hbox{}% contents like unnumbered, but no toc entry
+      \def\toctype{omit}%
+      \xdef\thischapter{}%
+    \else\ifx\temptype\Yappendixkeyword
+      \setbox0 = \hbox{\putwordAppendix{} #3\enspace}%
+      \def\toctype{app}%
+      % We don't substitute the actual chapter name into \thischapter
+      % because we don't want its macros evaluated now.  And we don't
+      % use \thissection because that changes with each section.
+      %
+      \xdef\thischapter{\putwordAppendix{} \appendixletter:
+                        \noexpand\thischaptername}%
+    \else
+      \setbox0 = \hbox{#3\enspace}%
+      \def\toctype{numchap}%
+      \xdef\thischapter{\putwordChapter{} \the\chapno:
+                        \noexpand\thischaptername}%
+    \fi\fi\fi
+    %
+    % Write the toc entry for this chapter.  Must come before the
+    % \donoderef, because we include the current node name in the toc
+    % entry, and \donoderef resets it to empty.
+    \writetocentry{\toctype}{#1}{#3}%
+    %
+    % For pdftex, we have to write out the node definition (aka, make
+    % the pdfdest) after any page break, but before the actual text has
+    % been typeset.  If the destination for the pdf outline is after the
+    % text, then jumping from the outline may wind up with the text not
+    % being visible, for instance under high magnification.
+    \donoderef{#2}%
+    %
+    % Typeset the actual heading.
     \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
-          \hangindent = \wd0 \centerparametersmaybe
+          \hangindent=\wd0 \centerparametersmaybe
           \unhbox0 #1\par}%
   }%
   \nobreak\bigskip % no page break after a chapter title
   \nobreak
 }
 
-% Plain opening for unnumbered.
-\def\unnchfplain#1{\chfplain{#1}{}}
-
 % @centerchap -- centered and unnumbered.
 \let\centerparametersmaybe = \relax
-\def\centerchfplain#1{{%
-  \def\centerparametersmaybe{%
-    \advance\rightskip by 3\rightskip
-    \leftskip = \rightskip
-    \parfillskip = 0pt
-  }%
-  \chfplain{#1}{}%
-}}
+\def\centerparameters{%
+  \advance\rightskip by 3\rightskip
+  \leftskip = \rightskip
+  \parfillskip = 0pt
+}
 
-\CHAPFplain % The default
 
+% I don't think this chapter style is supported any more, so I'm not
+% updating it with the new noderef stuff.  We'll see.  --karl, 11aug03.
+%
+\def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
+%
 \def\unnchfopen #1{%
 \chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
                        \parindent=0pt\raggedright
                        \rm #1\hfill}}\bigskip \par\nobreak
 }
-
 \def\chfopen #1#2{\chapoddpage {\chapfonts
 \vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}%
 \par\penalty 5000 %
 }
-
 \def\centerchfopen #1{%
 \chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
                        \parindent=0pt
                        \hfill {\rm #1}\hfill}}\bigskip \par\nobreak
 }
+\def\CHAPFopen{%
+  \global\let\chapmacro=\chfopen
+  \global\let\centerchapmacro=\centerchfopen}
 
-\def\CHAPFopen{
-\global\let\chapmacro=\chfopen
-\global\let\unnumbchapmacro=\unnchfopen
-\global\let\centerchapmacro=\centerchfopen}
 
-
-% Section titles.
+% Section titles.  These macros combine the section number parts and
+% call the generic \sectionheading to do the printing.
+%
 \newskip\secheadingskip
-\def\secheadingbreak{\dobreak \secheadingskip {-1000}}
-\def\secheading#1#2#3{\sectionheading{sec}{#2.#3}{#1}}
-\def\plainsecheading#1{\sectionheading{sec}{}{#1}}
+\def\secheadingbreak{\dobreak \secheadingskip{-1000}}
 
 % Subsection titles.
-\newskip \subsecheadingskip
-\def\subsecheadingbreak{\dobreak \subsecheadingskip {-500}}
-\def\subsecheading#1#2#3#4{\sectionheading{subsec}{#2.#3.#4}{#1}}
-\def\plainsubsecheading#1{\sectionheading{subsec}{}{#1}}
+\newskip\subsecheadingskip
+\def\subsecheadingbreak{\dobreak \subsecheadingskip{-500}}
 
 % Subsubsection titles.
-\let\subsubsecheadingskip = \subsecheadingskip
-\let\subsubsecheadingbreak = \subsecheadingbreak
-\def\subsubsecheading#1#2#3#4#5{\sectionheading{subsubsec}{#2.#3.#4.#5}{#1}}
-\def\plainsubsubsecheading#1{\sectionheading{subsubsec}{}{#1}}
+\def\subsubsecheadingskip{\subsecheadingskip}
+\def\subsubsecheadingbreak{\subsecheadingbreak}
 
 
-% Print any size section title.
+% Print any size, any type, section title.
 %
-% #1 is the section type (sec/subsec/subsubsec), #2 is the section
-% number (maybe empty), #3 the text.
-\def\sectionheading#1#2#3{%
-  {%
-    \expandafter\advance\csname #1headingskip\endcsname by \parskip
-    \csname #1headingbreak\endcsname
-  }%
+% #1 is the text, #2 is the section level (sec/subsec/subsubsec), #3 is
+% the section type for xrefs (Ynumbered, Ynothing, Yappendix), #4 is the
+% section number.
+%
+\def\sectionheading#1#2#3#4{%
   {%
     % Switch to the right set of fonts.
-    \csname #1fonts\endcsname \rm
+    \csname #2fonts\endcsname \rm
+    %
+    % Insert space above the heading.
+    \csname #2headingbreak\endcsname
     %
-    % Only insert the separating space if we have a section number.
-    \def\secnum{#2}%
-    \setbox0 = \hbox{#2\ifx\secnum\empty\else\enspace\fi}%
+    % Only insert the space after the number if we have a section number.
+    \def\sectionlevel{#2}%
+    \def\temptype{#3}%
+    %
+    \ifx\temptype\Ynothingkeyword
+      \setbox0 = \hbox{}%
+      \def\toctype{unn}%
+      \gdef\thissection{#1}%
+    \else\ifx\temptype\Yomitfromtockeyword
+      % for @headings -- no section number, don't include in toc,
+      % and don't redefine \thissection.
+      \setbox0 = \hbox{}%
+      \def\toctype{omit}%
+      \let\sectionlevel=\empty
+    \else\ifx\temptype\Yappendixkeyword
+      \setbox0 = \hbox{#4\enspace}%
+      \def\toctype{app}%
+      \gdef\thissection{#1}%
+    \else
+      \setbox0 = \hbox{#4\enspace}%
+      \def\toctype{num}%
+      \gdef\thissection{#1}%
+    \fi\fi\fi
+    %
+    % Write the toc entry (before \donoderef).  See comments in \chfplain.
+    \writetocentry{\toctype\sectionlevel}{#1}{#4}%
+    %
+    % Write the node reference (= pdf destination for pdftex).
+    % Again, see comments in \chfplain.
+    \donoderef{#3}%
     %
+    % Output the actual section heading.
     \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
-          \hangindent = \wd0 % zero if no section number
-          \unhbox0 #3}%
+          \hangindent=\wd0  % zero if no section number
+          \unhbox0 #1}%
   }%
-  % Add extra space after the heading -- either a line space or a
-  % paragraph space, whichever is more.  (Some people like to set
-  % \parskip to large values for some reason.)  Don't allow stretch, though.
-  \nobreak
-  \ifdim\parskip>\normalbaselineskip
-    \kern\parskip
-  \else
-    \kern\normalbaselineskip
-  \fi
+  % Add extra space after the heading -- half of whatever came above it.
+  % Don't allow stretch, though.
+  \kern .5 \csname #2headingskip\endcsname
+  %
+  % Do not let the kern be a potential breakpoint, as it would be if it
+  % was followed by glue.
   \nobreak
+  %
+  % We'll almost certainly start a paragraph next, so don't let that
+  % glue accumulate.  (Not a breakpoint because it's preceded by a
+  % discardable item.)
+  \vskip-\parskip
+  % 
+  % This is purely so the last item on the list is a known \penalty >
+  % 10000.  This is so \startdefun can avoid allowing breakpoints after
+  % section headings.  Otherwise, it would insert a valid breakpoint between:
+  % 
+  %   @section sec-whatever
+  %   @deffn def-whatever
+  \penalty 10001
 }
 
 
@@ -4198,119 +4394,152 @@
 \newwrite\tocfile
 
 % Write an entry to the toc file, opening it if necessary.
-% Called from @chapter, etc.  We supply {\folio} at the end of the
-% argument, which will end up as the last argument to the \...entry macro.
+% Called from @chapter, etc.
+%
+% Example usage: \writetocentry{sec}{Section Name}{\the\chapno.\the\secno}
+% We append the current node name (if any) and page number as additional
+% arguments for the \{chap,sec,...}entry macros which will eventually
+% read this.  The node name is used in the pdf outlines as the
+% destination to jump to.
 %
-% Usage: \writetocentry{chap}{The Name of The Game}{{\the\chapno}}
 % We open the .toc file for writing here instead of at @setfilename (or
 % any other fixed time) so that @contents can be anywhere in the document.
+% But if #1 is `omit', then we don't do anything.  This is used for the
+% table of contents chapter openings themselves.
 %
 \newif\iftocfileopened
+\def\omitkeyword{omit}%
+%
 \def\writetocentry#1#2#3{%
-  \iftocfileopened\else
-    \immediate\openout\tocfile = \jobname.toc
-    \global\tocfileopenedtrue
-  \fi
-  %
-  \iflinks
-    \toks0 = {#2}%
-    \edef\temp{\write\tocfile{\realbackslash #1entry{\the\toks0}#3{\folio}}}%
-    \temp
+  \edef\writetoctype{#1}%
+  \ifx\writetoctype\omitkeyword \else
+    \iftocfileopened\else
+      \immediate\openout\tocfile = \jobname.toc
+      \global\tocfileopenedtrue
+    \fi
+    %
+    \iflinks
+      \toks0 = {#2}%
+      \toks2 = \expandafter{\lastnode}%
+      \edef\temp{\write\tocfile{\realbackslash #1entry{\the\toks0}{#3}%
+                               {\the\toks2}{\noexpand\folio}}}%
+      \temp
+    \fi
   \fi
   %
-  % Tell \shipout to create a page destination if we're doing pdf, which
-  % will be the target of the links in the table of contents.  We can't
-  % just do it on every page because the title pages are numbered 1 and
-  % 2 (the page numbers aren't printed), and so are the first two pages
-  % of the document.  Thus, we'd have two destinations named `1', and
-  % two named `2'.
-  \ifpdf \pdfmakepagedesttrue \fi
+  % Tell \shipout to create a pdf destination on each page, if we're
+  % writing pdf.  These are used in the table of contents.  We can't
+  % just write one on every page because the title pages are numbered
+  % 1 and 2 (the page numbers aren't printed), and so are the first
+  % two pages of the document.  Thus, we'd have two destinations named
+  % `1', and two named `2'.
+  \ifpdf \global\pdfmakepagedesttrue \fi
 }
 
 \newskip\contentsrightmargin \contentsrightmargin=1in
 \newcount\savepageno
 \newcount\lastnegativepageno \lastnegativepageno = -1
 
-% Finish up the main text and prepare to read what we've written
-% to \tocfile.
+% Prepare to read what we've written to \tocfile.
 %
 \def\startcontents#1{%
-   % If @setchapternewpage on, and @headings double, the contents should
-   % start on an odd page, unlike chapters.  Thus, we maintain
-   % \contentsalignmacro in parallel with \pagealignmacro.
-   % From: Torbjorn Granlund <tege at matematik.su.se>
-   \contentsalignmacro
-   \immediate\closeout\tocfile
-   %
-   % Don't need to put `Contents' or `Short Contents' in the headline.
-   % It is abundantly clear what they are.
-   \unnumbchapmacro{#1}\def\thischapter{}%
-   \savepageno = \pageno
-   \begingroup                  % Set up to handle contents files properly.
-      \catcode`\\=0  \catcode`\{=1  \catcode`\}=2  \catcode`\@=11
-      % We can't do this, because then an actual ^ in a section
-      % title fails, e.g., @chapter ^ -- exponentiation.  --karl, 9jul97.
-      %\catcode`\^=7 % to see ^^e4 as \"a etc. juha at piuha.ydi.vtt.fi
-      \raggedbottom             % Worry more about breakpoints than the bottom.
-      \advance\hsize by -\contentsrightmargin % Don't use the full line length.
-      %
-      % Roman numerals for page numbers.
-      \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
+  % If @setchapternewpage on, and @headings double, the contents should
+  % start on an odd page, unlike chapters.  Thus, we maintain
+  % \contentsalignmacro in parallel with \pagealignmacro.
+  % From: Torbjorn Granlund <tege at matematik.su.se>
+  \contentsalignmacro
+  \immediate\closeout\tocfile
+  %
+  % Don't need to put `Contents' or `Short Contents' in the headline.
+  % It is abundantly clear what they are.
+  \def\thischapter{}%
+  \chapmacro{#1}{Yomitfromtoc}{}%
+  %
+  \savepageno = \pageno
+  \begingroup                  % Set up to handle contents files properly.
+    \catcode`\\=0  \catcode`\{=1  \catcode`\}=2  \catcode`\@=11
+    % We can't do this, because then an actual ^ in a section
+    % title fails, e.g., @chapter ^ -- exponentiation.  --karl, 9jul97.
+    %\catcode`\^=7 % to see ^^e4 as \"a etc. juha at piuha.ydi.vtt.fi
+    \raggedbottom             % Worry more about breakpoints than the bottom.
+    \advance\hsize by -\contentsrightmargin % Don't use the full line length.
+    %
+    % Roman numerals for page numbers.
+    \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
 }
 
 
 % Normal (long) toc.
 \def\contents{%
-   \startcontents{\putwordTOC}%
-     \openin 1 \jobname.toc
-     \ifeof 1 \else
-       \closein 1
-       \input \jobname.toc
-     \fi
-     \vfill \eject
-     \contentsalignmacro % in case @setchapternewpage odd is in effect
-     \pdfmakeoutlines
-   \endgroup
-   \lastnegativepageno = \pageno
-   \global\pageno = \savepageno
+  \startcontents{\putwordTOC}%
+    \openin 1 \jobname.toc
+    \ifeof 1 \else
+      \input \jobname.toc
+    \fi
+    \vfill \eject
+    \contentsalignmacro % in case @setchapternewpage odd is in effect
+    \ifeof 1 \else
+      \pdfmakeoutlines
+    \fi
+    \closein 1
+  \endgroup
+  \lastnegativepageno = \pageno
+  \global\pageno = \savepageno
 }
 
 % And just the chapters.
 \def\summarycontents{%
-   \startcontents{\putwordShortTOC}%
-      %
-      \let\chapentry = \shortchapentry
-      \let\appendixentry = \shortappendixentry
-      \let\unnumbchapentry = \shortunnumberedentry
-      % We want a true roman here for the page numbers.
-      \secfonts
-      \let\rm=\shortcontrm \let\bf=\shortcontbf
-      \let\sl=\shortcontsl \let\tt=\shortconttt
-      \rm
-      \hyphenpenalty = 10000
-      \advance\baselineskip by 1pt % Open it up a little.
-      \def\secentry ##1##2##3##4{}
-      \def\subsecentry ##1##2##3##4##5{}
-      \def\subsubsecentry ##1##2##3##4##5##6{}
-      \let\unnumbsecentry = \secentry
-      \let\unnumbsubsecentry = \subsecentry
-      \let\unnumbsubsubsecentry = \subsubsecentry
-      \openin 1 \jobname.toc
-      \ifeof 1 \else
-        \closein 1
-        \input \jobname.toc
-      \fi
-     \vfill \eject
-     \contentsalignmacro % in case @setchapternewpage odd is in effect
-   \endgroup
-   \lastnegativepageno = \pageno
-   \global\pageno = \savepageno
+  \startcontents{\putwordShortTOC}%
+    %
+    \let\numchapentry = \shortchapentry
+    \let\appentry = \shortchapentry
+    \let\unnchapentry = \shortunnchapentry
+    % We want a true roman here for the page numbers.
+    \secfonts
+    \let\rm=\shortcontrm \let\bf=\shortcontbf
+    \let\sl=\shortcontsl \let\tt=\shortconttt
+    \rm
+    \hyphenpenalty = 10000
+    \advance\baselineskip by 1pt % Open it up a little.
+    \def\numsecentry##1##2##3##4{}
+    \let\appsecentry = \numsecentry
+    \let\unnsecentry = \numsecentry
+    \let\numsubsecentry = \numsecentry
+    \let\appsubsecentry = \numsecentry
+    \let\unnsubsecentry = \numsecentry
+    \let\numsubsubsecentry = \numsecentry
+    \let\appsubsubsecentry = \numsecentry
+    \let\unnsubsubsecentry = \numsecentry
+    \openin 1 \jobname.toc
+    \ifeof 1 \else
+      \input \jobname.toc
+    \fi
+    \closein 1
+    \vfill \eject
+    \contentsalignmacro % in case @setchapternewpage odd is in effect
+  \endgroup
+  \lastnegativepageno = \pageno
+  \global\pageno = \savepageno
 }
 \let\shortcontents = \summarycontents
 
-\ifpdf
-  \pdfcatalog{/PageMode /UseOutlines}%
-\fi
+% Typeset the label for a chapter or appendix for the short contents.
+% The arg is, e.g., `A' for an appendix, or `3' for a chapter.
+%
+\def\shortchaplabel#1{%
+  % This space should be enough, since a single number is .5em, and the
+  % widest letter (M) is 1em, at least in the Computer Modern fonts.
+  % But use \hss just in case.
+  % (This space doesn't include the extra space that gets added after
+  % the label; that gets put in by \shortchapentry above.)
+  %
+  % We'd like to right-justify chapter numbers, but that looks strange
+  % with appendix letters.  And right-justifying numbers and
+  % left-justifying letters looks strange when there is less than 10
+  % chapters.  Have to read the whole toc once to know how many chapters
+  % there are before deciding ...
+  \hbox to 1em{#1\hss}%
+}
 
 % These macros generate individual entries in the table of contents.
 % The first argument is the chapter or section name.
@@ -4318,58 +4547,46 @@
 % The arguments in between are the chapter number, section number, ...
 
 % Chapters, in the main contents.
-\def\chapentry#1#2#3{\dochapentry{#2\labelspace#1}{#3}}
+\def\numchapentry#1#2#3#4{\dochapentry{#2\labelspace#1}{#4}}
 %
 % Chapters, in the short toc.
 % See comments in \dochapentry re vbox and related settings.
-\def\shortchapentry#1#2#3{%
-  \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#3\egroup}%
+\def\shortchapentry#1#2#3#4{%
+  \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#4\egroup}%
 }
 
 % Appendices, in the main contents.
-\def\appendixentry#1#2#3{%
-  \dochapentry{\appendixbox{\putwordAppendix{} #2}\labelspace#1}{#3}}
-%
-% Appendices, in the short toc.
-\let\shortappendixentry = \shortchapentry
-
-% Typeset the label for a chapter or appendix for the short contents.
-% The arg is, e.g., `Appendix A' for an appendix, or `3' for a chapter.
-% We could simplify the code here by writing out an \appendixentry
-% command in the toc file for appendices, instead of using \chapentry
-% for both, but it doesn't seem worth it.
+% Need the word Appendix, and a fixed-size box.
 %
-\newdimen\shortappendixwidth
+\def\appendixbox#1{%
+  % We use M since it's probably the widest letter.
+  \setbox0 = \hbox{\putwordAppendix{} M}%
+  \hbox to \wd0{\putwordAppendix{} #1\hss}}
 %
-\def\shortchaplabel#1{%
-  % This space should be enough, since a single number is .5em, and the
-  % widest letter (M) is 1em, at least in the Computer Modern fonts.
-  % But use \hss just in case.
-  % (This space doesn't include the extra space that gets added after
-  % the label; that gets put in by \shortchapentry above.)
-  \dimen0 = 1em
-  \hbox to \dimen0{#1\hss}%
-}
+\def\appentry#1#2#3#4{\dochapentry{\appendixbox{#2}\labelspace#1}{#4}}
 
 % Unnumbered chapters.
-\def\unnumbchapentry#1#2#3{\dochapentry{#1}{#3}}
-\def\shortunnumberedentry#1#2#3{\tocentry{#1}{\doshortpageno\bgroup#3\egroup}}
+\def\unnchapentry#1#2#3#4{\dochapentry{#1}{#4}}
+\def\shortunnchapentry#1#2#3#4{\tocentry{#1}{\doshortpageno\bgroup#4\egroup}}
 
 % Sections.
-\def\secentry#1#2#3#4{\dosecentry{#2.#3\labelspace#1}{#4}}
-\def\unnumbsecentry#1#2#3#4{\dosecentry{#1}{#4}}
+\def\numsecentry#1#2#3#4{\dosecentry{#2\labelspace#1}{#4}}
+\let\appsecentry=\numsecentry
+\def\unnsecentry#1#2#3#4{\dosecentry{#1}{#4}}
 
 % Subsections.
-\def\subsecentry#1#2#3#4#5{\dosubsecentry{#2.#3.#4\labelspace#1}{#5}}
-\def\unnumbsubsecentry#1#2#3#4#5{\dosubsecentry{#1}{#5}}
+\def\numsubsecentry#1#2#3#4{\dosubsecentry{#2\labelspace#1}{#4}}
+\let\appsubsecentry=\numsubsecentry
+\def\unnsubsecentry#1#2#3#4{\dosubsecentry{#1}{#4}}
 
 % And subsubsections.
-\def\subsubsecentry#1#2#3#4#5#6{%
-  \dosubsubsecentry{#2.#3.#4.#5\labelspace#1}{#6}}
-\def\unnumbsubsubsecentry#1#2#3#4#5#6{\dosubsubsecentry{#1}{#6}}
+\def\numsubsubsecentry#1#2#3#4{\dosubsubsecentry{#2\labelspace#1}{#4}}
+\let\appsubsubsecentry=\numsubsubsecentry
+\def\unnsubsubsecentry#1#2#3#4{\dosubsubsecentry{#1}{#4}}
 
 % This parameter controls the indentation of the various levels.
-\newdimen\tocindent \tocindent = 3pc
+% Same as \defaultparindent.
+\newdimen\tocindent \tocindent = 15pt
 
 % Now for the actual typesetting. In all these, #1 is the text and #2 is the
 % page number.
@@ -4400,17 +4617,8 @@
   \tocentry{#1}{\dopageno\bgroup#2\egroup}%
 \endgroup}
 
-% Final typesetting of a toc entry; we use the same \entry macro as for
-% the index entries, but we want to suppress hyphenation here.  (We
-% can't do that in the \entry macro, since index entries might consist
-% of hyphenated-identifiers-that-do-not-fit-on-a-line-and-nothing-else.)
-\def\tocentry#1#2{\begingroup
-  \vskip 0pt plus1pt % allow a little stretch for the sake of nice page breaks
-  % Do not use \turnoffactive in these arguments.  Since the toc is
-  % typeset in cmr, characters such as _ would come out wrong; we
-  % have to do the usual translation tricks.
-  \entry{#1}{#2}%
-\endgroup}
+% We use the same \entry macro as for the index entries.
+\let\tocentry = \entry
 
 % Space between chapter (or whatever) number and the title.
 \def\labelspace{\hskip1em \relax}
@@ -4420,8 +4628,8 @@
 
 \def\chapentryfonts{\secfonts \rm}
 \def\secentryfonts{\textfonts}
-\let\subsecentryfonts = \textfonts
-\let\subsubsecentryfonts = \textfonts
+\def\subsecentryfonts{\textfonts}
+\def\subsubsecentryfonts{\textfonts}
 
 
 \message{environments,}
@@ -4448,10 +4656,10 @@
 % The text. (`r' is open on the right, `e' somewhat less so on the left.)
 \setbox0 = \hbox{\kern-.75pt \tensf error\kern-1.5pt}
 %
-\global\setbox\errorbox=\hbox to \dimen0{\hfil
+\setbox\errorbox=\hbox to \dimen0{\hfil
    \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right.
    \advance\hsize by -2\dimen2 % Rules.
-   \vbox{
+   \vbox{%
       \hrule height\dimen2
       \hbox{\vrule width\dimen2 \kern3pt          % Space to left of text.
          \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below.
@@ -4465,14 +4673,13 @@
 % One exception: @ is still an escape character, so that @end tex works.
 % But \@ or @@ will get a plain tex @ character.
 
-\def\tex{\begingroup
+\envdef\tex{%
   \catcode `\\=0 \catcode `\{=1 \catcode `\}=2
   \catcode `\$=3 \catcode `\&=4 \catcode `\#=6
   \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie
   \catcode `\%=14
   \catcode `\+=\other
   \catcode `\"=\other
-  \catcode `\==\other
   \catcode `\|=\other
   \catcode `\<=\other
   \catcode `\>=\other
@@ -4488,6 +4695,7 @@
   \let\!=\ptexexclam
   \let\i=\ptexi
   \let\indent=\ptexindent
+  \let\noindent=\ptexnoindent
   \let\{=\ptexlbrace
   \let\+=\tabalign
   \let\}=\ptexrbrace
@@ -4498,10 +4706,11 @@
   \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
   \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
   \def\@{@}%
-\let\Etex=\endgroup}
+}
+% There is no need to define \Etex.
 
 % Define @lisp ... @end lisp.
-% @lisp does a \begingroup so it can rebind things,
+% @lisp environment forms a group so it can rebind things,
 % including the definition of @end lisp (which normally is erroneous).
 
 % Amount to narrow the margins by for @lisp.
@@ -4512,19 +4721,6 @@
 % have any width.
 \def\lisppar{\null\endgraf}
 
-% Make each space character in the input produce a normal interword
-% space in the output.  Don't allow a line break at this space, as this
-% is used only in environments like @example, where each line of input
-% should produce a line of output anyway.
-%
-{\obeyspaces %
-\gdef\sepspaces{\obeyspaces\let =\tie}}
-
-% Define \obeyedspace to be our active space, whatever it is.  This is
-% for use in \parsearg.
-{\sepspaces%
-\global\let\obeyedspace= }
-
 % This space is always present above and below environments.
 \newskip\envskipamount \envskipamount = 0pt
 
@@ -4534,7 +4730,8 @@
 % start of the next paragraph will insert \parskip.
 %
 \def\aboveenvbreak{{%
-  % =10000 instead of <10000 because of a special case in \itemzzz, q.v.
+  % =10000 instead of <10000 because of a special case in \itemzzz and
+  % \sectionheading, q.v.
   \ifnum \lastpenalty=10000 \else
     \advance\envskipamount by \parskip
     \endgraf
@@ -4542,7 +4739,7 @@
       \removelastskip
       % it's not a good place to break if the last penalty was \nobreak
       % or better ...
-      \ifnum\lastpenalty>10000 \else \penalty-50 \fi
+      \ifnum\lastpenalty<10000 \penalty-50 \fi
       \vskip\envskipamount
     \fi
   \fi
@@ -4574,52 +4771,52 @@
 %
 \newskip\lskip\newskip\rskip
 
-\def\cartouche{%
-\par  % can't be in the midst of a paragraph.
-\begingroup
-        \lskip=\leftskip \rskip=\rightskip
-        \leftskip=0pt\rightskip=0pt %we want these *outside*.
-        \cartinner=\hsize \advance\cartinner by-\lskip
-                          \advance\cartinner by-\rskip
-        \cartouter=\hsize
-        \advance\cartouter by 18.4pt % allow for 3pt kerns on either
-%                                    side, and for 6pt waste from
-%                                    each corner char, and rule thickness
-        \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
-        % Flag to tell @lisp, etc., not to narrow margin.
-        \let\nonarrowing=\comment
-        \vbox\bgroup
-                \baselineskip=0pt\parskip=0pt\lineskip=0pt
-                \carttop
-                \hbox\bgroup
-                        \hskip\lskip
-                        \vrule\kern3pt
-                        \vbox\bgroup
-                                \hsize=\cartinner
-                                \kern3pt
-                                \begingroup
-                                        \baselineskip=\normbskip
-                                        \lineskip=\normlskip
-                                        \parskip=\normpskip
-                                        \vskip -\parskip
+\envdef\cartouche{%
+  \ifhmode\par\fi  % can't be in the midst of a paragraph.
+  \startsavinginserts
+  \lskip=\leftskip \rskip=\rightskip
+  \leftskip=0pt\rightskip=0pt % we want these *outside*.
+  \cartinner=\hsize \advance\cartinner by-\lskip
+  \advance\cartinner by-\rskip
+  \cartouter=\hsize
+  \advance\cartouter by 18.4pt	% allow for 3pt kerns on either
+				% side, and for 6pt waste from
+				% each corner char, and rule thickness
+  \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
+  % Flag to tell @lisp, etc., not to narrow margin.
+  \let\nonarrowing=\comment
+  \vbox\bgroup
+      \baselineskip=0pt\parskip=0pt\lineskip=0pt
+      \carttop
+      \hbox\bgroup
+	  \hskip\lskip
+	  \vrule\kern3pt
+	  \vbox\bgroup
+	      \kern3pt
+	      \hsize=\cartinner
+	      \baselineskip=\normbskip
+	      \lineskip=\normlskip
+	      \parskip=\normpskip
+	      \vskip -\parskip
+	      \comment % For explanation, see the end of \def\group.
+}
 \def\Ecartouche{%
-                                \endgroup
-                                \kern3pt
-                        \egroup
-                        \kern3pt\vrule
-                        \hskip\rskip
-                \egroup
-                \cartbot
-        \egroup
-\endgroup
-}}
+              \ifhmode\par\fi
+	      \kern3pt
+	  \egroup
+	  \kern3pt\vrule
+	  \hskip\rskip
+      \egroup
+      \cartbot
+  \egroup
+  \checkinserts
+}
 
 
 % This macro is called at the beginning of all the @example variants,
 % inside a group.
 \def\nonfillstart{%
   \aboveenvbreak
-  \inENV % This group ends at the end of the body
   \hfuzz = 12pt % Don't be fussy
   \sepspaces % Make spaces be word-separators rather than space tokens.
   \let\par = \lisppar % don't ignore blank lines
@@ -4632,103 +4829,99 @@
   \ifx\nonarrowing\relax
     \advance \leftskip by \lispnarrowing
     \exdentamount=\lispnarrowing
-    \let\exdent=\nofillexdent
-    \let\nonarrowing=\relax
   \fi
+  \let\exdent=\nofillexdent
 }
 
-% Define the \E... control sequence only if we are inside the particular
-% environment, so the error checking in \end will work.
-%
-% To end an @example-like environment, we first end the paragraph (via
-% \afterenvbreak's vertical glue), and then the group.  That way we keep
-% the zero \parskip that the environments set -- \parskip glue will be
-% inserted at the beginning of the next paragraph in the document, after
-% the environment.
+% If you want all examples etc. small: @set dispenvsize small.
+% If you want even small examples the full size: @set dispenvsize nosmall.
+% This affects the following displayed environments:
+%    @example, @display, @format, @lisp
 %
-\def\nonfillfinish{\afterenvbreak\endgroup}
+\def\smallword{small}
+\def\nosmallword{nosmall}
+\let\SETdispenvsize\relax
+\def\setnormaldispenv{%
+  \ifx\SETdispenvsize\smallword
+    \smallexamplefonts \rm
+  \fi
+}
+\def\setsmalldispenv{%
+  \ifx\SETdispenvsize\nosmallword
+  \else
+    \smallexamplefonts \rm
+  \fi
+}
 
-% @lisp: indented, narrowed, typewriter font.
-\def\lisp{\begingroup
-  \nonfillstart
-  \let\Elisp = \nonfillfinish
-  \tt
-  \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
-  \gobble       % eat return
+% We often define two environments, @foo and @smallfoo.
+% Let's do it by one command:
+\def\makedispenv #1#2{
+  \expandafter\envdef\csname#1\endcsname {\setnormaldispenv #2}
+  \expandafter\envdef\csname small#1\endcsname {\setsmalldispenv #2}
+  \expandafter\let\csname E#1\endcsname \afterenvbreak
+  \expandafter\let\csname Esmall#1\endcsname \afterenvbreak
 }
 
-% @example: Same as @lisp.
-\def\example{\begingroup \def\Eexample{\nonfillfinish\endgroup}\lisp}
+% Define two synonyms:
+\def\maketwodispenvs #1#2#3{
+  \makedispenv{#1}{#3}
+  \makedispenv{#2}{#3}
+}
 
+% @lisp: indented, narrowed, typewriter font; @example: same as @lisp.
+%
 % @smallexample and @smalllisp: use smaller fonts.
 % Originally contributed by Pavel at xerox.
-\def\smalllisp{\begingroup
-  \def\Esmalllisp{\nonfillfinish\endgroup}%
-  \def\Esmallexample{\nonfillfinish\endgroup}%
-  \smallexamplefonts
-  \lisp
+%
+\maketwodispenvs {lisp}{example}{%
+  \nonfillstart
+  \tt
+  \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
+  \gobble       % eat return
 }
-\let\smallexample = \smalllisp
-
 
-% @display: same as @lisp except keep current font.
+% @display/@smalldisplay: same as @lisp except keep current font.
 %
-\def\display{\begingroup
+\makedispenv {display}{%
   \nonfillstart
-  \let\Edisplay = \nonfillfinish
   \gobble
 }
-%
-% @smalldisplay: @display plus smaller fonts.
-%
-\def\smalldisplay{\begingroup
-  \def\Esmalldisplay{\nonfillfinish\endgroup}%
-  \smallexamplefonts \rm
-  \display
-}
 
-% @format: same as @display except don't narrow margins.
+% @format/@smallformat: same as @display except don't narrow margins.
 %
-\def\format{\begingroup
-  \let\nonarrowing = t
+\makedispenv{format}{%
+  \let\nonarrowing = t%
   \nonfillstart
-  \let\Eformat = \nonfillfinish
   \gobble
 }
-%
-% @smallformat: @format plus smaller fonts.
-%
-\def\smallformat{\begingroup
-  \def\Esmallformat{\nonfillfinish\endgroup}%
-  \smallexamplefonts \rm
-  \format
-}
 
-% @flushleft (same as @format).
-%
-\def\flushleft{\begingroup \def\Eflushleft{\nonfillfinish\endgroup}\format}
+% @flushleft: same as @format, but doesn't obey \SETdispenvsize.
+\envdef\flushleft{%
+  \let\nonarrowing = t%
+  \nonfillstart
+  \gobble
+}
+\let\Eflushleft = \afterenvbreak
 
 % @flushright.
 %
-\def\flushright{\begingroup
-  \let\nonarrowing = t
+\envdef\flushright{%
+  \let\nonarrowing = t%
   \nonfillstart
-  \let\Eflushright = \nonfillfinish
   \advance\leftskip by 0pt plus 1fill
   \gobble
 }
+\let\Eflushright = \afterenvbreak
 
 
 % @quotation does normal linebreaking (hence we can't use \nonfillstart)
-% and narrows the margins.
+% and narrows the margins.  We keep \parskip nonzero in general, since
+% we're doing normal filling.  So, when using \aboveenvbreak and
+% \afterenvbreak, temporarily make \parskip 0.
 %
-\def\quotation{%
-  \begingroup\inENV %This group ends at the end of the @quotation body
+\envdef\quotation{%
   {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
   \parindent=0pt
-  % We have retained a nonzero parskip for the environment, since we're
-  % doing normal filling. So to avoid extra space below the environment...
-  \def\Equotation{\parskip = 0pt \nonfillfinish}%
   %
   % @cartouche defines \nonarrowing to inhibit narrowing at next level down.
   \ifx\nonarrowing\relax
@@ -4737,6 +4930,27 @@
     \exdentamount = \lispnarrowing
     \let\nonarrowing = \relax
   \fi
+  \parsearg\quotationlabel
+}
+
+% We have retained a nonzero parskip for the environment, since we're
+% doing normal filling.
+%
+\def\Equotation{%
+  \par
+  \ifx\quotationauthor\undefined\else
+    % indent a bit.
+    \leftline{\kern 2\leftskip \sl ---\quotationauthor}%
+  \fi
+  {\parskip=0pt \afterenvbreak}%
+}
+
+% If we're given an argument, typeset it in bold with a colon after.
+\def\quotationlabel#1{%
+  \def\temp{#1}%
+  \ifx\temp\empty \else
+    {\bf #1: }%
+  \fi
 }
 
 
@@ -4758,7 +4972,7 @@
 %
 % [Knuth] p. 380
 \def\uncatcodespecials{%
-  \def\do##1{\catcode`##1=12}\dospecials}
+  \def\do##1{\catcode`##1=\other}\dospecials}
 %
 % [Knuth] pp. 380,381,391
 % Disable Spanish ligatures ?` and !` of \tt font
@@ -4806,6 +5020,8 @@
   }
 \endgroup
 \def\setupverbatim{%
+  \nonfillstart
+  \advance\leftskip by -\defbodyindent
   % Easiest (and conventionally used) font for verbatim
   \tt
   \def\par{\leavevmode\egroup\box0\endgraf}%
@@ -4827,7 +5043,7 @@
 %
 % [Knuth] p. 382; only eat outer {}
 \begingroup
-  \catcode`[=1\catcode`]=2\catcode`\{=12\catcode`\}=12
+  \catcode`[=1\catcode`]=2\catcode`\{=\other\catcode`\}=\other
   \gdef\doverb{#1[\def\next##1#1}[##1\endgroup]\next]
 \endgroup
 %
@@ -4844,13 +5060,6 @@
 % we need not redefine '\', '{' and '}'.
 %
 % Inspired by LaTeX's verbatim command set [latex.ltx]
-%% Include LaTeX hack for completeness -- never know
-%% \begingroup
-%% \catcode`|=0 \catcode`[=1
-%% \catcode`]=2\catcode`\{=12\catcode`\}=12\catcode`\ =\active
-%% \catcode`\\=12|gdef|doverbatim#1 at end verbatim[
-%% #1|endgroup|def|Everbatim[]|end[verbatim]]
-%% |endgroup
 %
 \begingroup
   \catcode`\ =\active
@@ -4858,54 +5067,32 @@
   % ignore everything up to the first ^^M, that's the newline at the end
   % of the @verbatim input line itself.  Otherwise we get an extra blank
   % line in the output.
-  \gdef\doverbatim#1^^M#2 at end verbatim{#2\end{verbatim}}%
+  \xdef\doverbatim#1^^M#2 at end verbatim{#2\noexpand\end\gobble verbatim}%
+  % We really want {...\end verbatim} in the body of the macro, but
+  % without the active space; thus we have to use \xdef and \gobble.
 \endgroup
 %
-\def\verbatim{%
-  \def\Everbatim{\nonfillfinish\endgroup}%
-  \begingroup
-    \nonfillstart
-    \advance\leftskip by -\defbodyindent
-    \begingroup\setupverbatim\doverbatim
+\envdef\verbatim{%
+    \setupverbatim\doverbatim
 }
+\let\Everbatim = \afterenvbreak
+
 
 % @verbatiminclude FILE - insert text of file in verbatim environment.
 %
-% Allow normal characters that we make active in the argument (a file name).
-\def\verbatiminclude{%
-  \begingroup
-    \catcode`\\=\other
-    \catcode`~=\other
-    \catcode`^=\other
-    \catcode`_=\other
-    \catcode`|=\other
-    \catcode`<=\other
-    \catcode`>=\other
-    \catcode`+=\other
-    \parsearg\doverbatiminclude
-}
-\def\setupverbatiminclude{%
-  \begingroup
-    \nonfillstart
-    \advance\leftskip by -\defbodyindent
-    \begingroup\setupverbatim
-}
+\def\verbatiminclude{\parseargusing\filenamecatcodes\doverbatiminclude}
 %
 \def\doverbatiminclude#1{%
-     % Restore active chars for included file.
-  \endgroup
-  \begingroup
-    \let\value=\expandablevalue
-    \def\thisfile{#1}%
-    \expandafter\expandafter\setupverbatiminclude\input\thisfile
-  \endgroup
-  \nonfillfinish
-  \endgroup
+  {%
+    \makevalueexpandable
+    \setupverbatim
+    \input #1
+    \afterenvbreak
+  }%
 }
 
 % @copying ... @end copying.
-% Save the text away for @insertcopying later.  Many commands won't be
-% allowed in this context, but that's ok.
+% Save the text away for @insertcopying later.
 %
 % We save the uninterpreted tokens, rather than creating a box.
 % Saving the text in a box would be much easier, but then all the
@@ -4914,670 +5101,392 @@
 % file; b) letting users define the frontmatter in as flexible order as
 % possible is very desirable.
 %
-\def\copying{\begingroup
-  % Define a command to swallow text until we reach `@end copying'.
-  % \ is the escape char in this texinfo.tex file, so it is the
-  % delimiter for the command; @ will be the escape char when we read
-  % it, but that doesn't matter.
-  \long\def\docopying##1\end copying{\gdef\copyingtext{##1}\enddocopying}%
-  %
-  % We must preserve ^^M's in the input file; see \insertcopying below.
-  \catcode`\^^M = \active
-  \docopying
-}
-
-% What we do to finish off the copying text.
-%
-\def\enddocopying{\endgroup\ignorespaces}
-
-% @insertcopying.  Here we must play games with ^^M's.  On the one hand,
-% we need them to delimit commands such as `@end quotation', so they
-% must be active.  On the other hand, we certainly don't want every
-% end-of-line to be a \par, as would happen with the normal active
-% definition of ^^M.  On the third hand, two ^^M's in a row should still
-% generate a \par.
-%
-% Our approach is to make ^^M insert a space and a penalty1 normally;
-% then it can also check if \lastpenalty=1.  If it does, then manually
-% do \par.
-%
-% This messes up the normal definitions of @c[omment], so we redefine
-% it.  Similarly for @ignore.  (These commands are used in the gcc
-% manual for man page generation.)
-%
-% Seems pretty fragile, most line-oriented commands will presumably
-% fail, but for the limited use of getting the copying text (which
-% should be quite simple) inserted, we can hope it's ok.
-%
-{\catcode`\^^M=\active %
-\gdef\insertcopying{\begingroup %
-  \parindent = 0pt  % looks wrong on title page
-  \def^^M{%
-    \ifnum \lastpenalty=1 %
-      \par %
-    \else %
-      \space \penalty 1 %
-    \fi %
-  }%
-  %
-  % Fix @c[omment] for catcode 13 ^^M's.
-  \def\c##1^^M{\ignorespaces}%
-  \let\comment = \c %
-  %
-  % Don't bother jumping through all the hoops that \doignore does, it
-  % would be very hard since the catcodes are already set.
-  \long\def\ignore##1\end ignore{\ignorespaces}%
-  %
-  \copyingtext %
-\endgroup}%
+\def\copying{\checkenv{}\begingroup\scanargctxt\docopying}
+\def\docopying#1 at end copying{\endgroup\def\copyingtext{#1}}
+%
+\def\insertcopying{%
+  \begingroup
+    \parindent = 0pt  % paragraph indentation looks wrong on title page
+    \scanexp\copyingtext
+  \endgroup
 }
 
 \message{defuns,}
 % @defun etc.
 
-% Allow user to change definition object font (\df) internally
-\def\setdeffont#1 {\csname DEF#1\endcsname}
-
 \newskip\defbodyindent \defbodyindent=.4in
 \newskip\defargsindent \defargsindent=50pt
 \newskip\deflastargmargin \deflastargmargin=18pt
 
-\newcount\parencount
-
-% We want ()&[] to print specially on the defun line.
-%
-\def\activeparens{%
-  \catcode`\(=\active \catcode`\)=\active
-  \catcode`\&=\active
-  \catcode`\[=\active \catcode`\]=\active
-}
-
-% Make control sequences which act like normal parenthesis chars.
-\let\lparen = ( \let\rparen = )
-
-{\activeparens % Now, smart parens don't turn on until &foo (see \amprm)
-
-% Be sure that we always have a definition for `(', etc.  For example,
-% if the fn name has parens in it, \boldbrax will not be in effect yet,
-% so TeX would otherwise complain about undefined control sequence.
-\global\let(=\lparen \global\let)=\rparen
-\global\let[=\lbrack \global\let]=\rbrack
-
-\gdef\functionparens{\boldbrax\let&=\amprm\parencount=0 }
-\gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
-% This is used to turn on special parens
-% but make & act ordinary (given that it's active).
-\gdef\boldbraxnoamp{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb\let&=\ampnr}
-
-% Definitions of (, ) and & used in args for functions.
-% This is the definition of ( outside of all parentheses.
-\gdef\oprm#1 {{\rm\char`\(}#1 \bf \let(=\opnested
-  \global\advance\parencount by 1
-}
-%
-% This is the definition of ( when already inside a level of parens.
-\gdef\opnested{\char`\(\global\advance\parencount by 1 }
-%
-\gdef\clrm{% Print a paren in roman if it is taking us back to depth of 0.
-  % also in that case restore the outer-level definition of (.
-  \ifnum \parencount=1 {\rm \char `\)}\sl \let(=\oprm \else \char `\) \fi
-  \global\advance \parencount by -1 }
-% If we encounter &foo, then turn on ()-hacking afterwards
-\gdef\amprm#1 {{\rm\&#1}\let(=\oprm \let)=\clrm\ }
-%
-\gdef\normalparens{\boldbrax\let&=\ampnr}
-} % End of definition inside \activeparens
-%% These parens (in \boldbrax) actually are a little bolder than the
-%% contained text.  This is especially needed for [ and ]
-\def\opnr{{\sf\char`\(}\global\advance\parencount by 1 }
-\def\clnr{{\sf\char`\)}\global\advance\parencount by -1 }
-\let\ampnr = \&
-\def\lbrb{{\bf\char`\[}}
-\def\rbrb{{\bf\char`\]}}
-
-% Active &'s sneak into the index arguments, so make sure it's defined.
-{
-  \catcode`& = \active
-  \global\let& = \ampnr
-}
-
-% \defname, which formats the name of the @def (not the args).
-% #1 is the function name.
-% #2 is the type of definition, such as "Function".
-%
-\def\defname#1#2{%
-  % How we'll output the type name.  Putting it in brackets helps
-  % distinguish it from the body text that may end up on the next line
-  % just below it.
-  \ifempty{#2}%
-    \def\defnametype{}%
+% Start the processing of @deffn:
+\def\startdefun{%
+  \ifnum\lastpenalty<10000
+    \medbreak
   \else
-    \def\defnametype{[\rm #2]}%
+    % If there are two @def commands in a row, we'll have a \nobreak,
+    % which is there to keep the function description together with its
+    % header.  But if there's nothing but headers, we need to allow a
+    % break somewhere.  Check specifically for penalty 10002, inserted
+    % by \defargscommonending, instead of 10000, since the sectioning
+    % commands also insert a nobreak penalty, and we don't want to allow
+    % a break between a section heading and a defun.
+    % 
+    \ifnum\lastpenalty=10002 \penalty2000 \fi
+    %
+    % Similarly, after a section heading, do not allow a break.
+    % But do insert the glue.
+    \medskip  % preceded by discardable penalty, so not a breakpoint
   \fi
   %
-  % Get the values of \leftskip and \rightskip as they were outside the @def...
-  \dimen2=\leftskip
-  \advance\dimen2 by -\defbodyindent
-  %
-  % Figure out values for the paragraph shape.
-  \setbox0=\hbox{\hskip \deflastargmargin{\defnametype}}%
-  \dimen0=\hsize \advance \dimen0 by -\wd0  % compute size for first line
-  \dimen1=\hsize \advance \dimen1 by -\defargsindent  % size for continuations
-  \parshape 2 0in \dimen0 \defargsindent \dimen1
-  %
-  % Output arg 2 ("Function" or some such) but stuck inside a box of
-  % width 0 so it does not interfere with linebreaking.
-  \noindent
-  %
-  {% Adjust \hsize to exclude the ambient margins,
-   % so that \rightline will obey them.
-   \advance \hsize by -\dimen2
-   \dimen3 = 0pt  % was -1.25pc
-   \rlap{\rightline{\defnametype\kern\dimen3}}%
-  }%
-  %
-  % Allow all lines to be underfull without complaint:
-  \tolerance=10000 \hbadness=10000
-  \advance\leftskip by -\defbodyindent
-  \exdentamount=\defbodyindent
-  {\df #1}\enskip        % output function name
-  % \defunargs will be called next to output the arguments, if any.
-}
-
-% Common pieces to start any @def...
-% #1 is the \E... control sequence to end the definition (which we define).
-% #2 is the \...x control sequence (which our caller defines).
-% #3 is the control sequence to process the header, such as \defunheader.
-%
-\def\parsebodycommon#1#2#3{%
-  \begingroup\inENV
-  % If there are two @def commands in a row, we'll have a \nobreak,
-  % which is there to keep the function description together with its
-  % header.  But if there's nothing but headers, we want to allow a
-  % break after all.  Check for penalty 10002 (inserted by
-  % \defargscommonending) instead of 10000, since the sectioning
-  % commands insert a \penalty10000, and we don't want to allow a break
-  % between a section heading and a defun.
-  \ifnum\lastpenalty=10002 \penalty0 \fi
-  \medbreak
-  %
-  % Define the \E... end token that this defining construct specifies
-  % so that it will exit this group.
-  \def#1{\endgraf\endgroup\medbreak}%
-  %
   \parindent=0in
   \advance\leftskip by \defbodyindent
   \exdentamount=\defbodyindent
 }
 
-% Common part of the \...x definitions.
-%
-\def\defxbodycommon{%
-  % As with \parsebodycommon above, allow line break if we have multiple
-  % x headers in a row.  It's not a great place, though.
-  \ifnum\lastpenalty=10000 \penalty1000 \fi
+\def\dodefunx#1{%
+  % First, check whether we are in the right environment:
+  \checkenv#1%
   %
-  \begingroup\obeylines
-}
-
-% Process body of @defun, @deffn, @defmac, etc.
-%
-\def\defparsebody#1#2#3{%
-  \parsebodycommon{#1}{#2}{#3}%
-  \def#2{\defxbodycommon \activeparens \spacesplit#3}%
-  \catcode\equalChar=\active
-  \begingroup\obeylines\activeparens
-  \spacesplit#3%
-}
-
-% #1, #2, #3 are the common arguments (see \parsebodycommon above).
-% #4, delimited by the space, is the class name.
-%
-\def\defmethparsebody#1#2#3#4 {%
-  \parsebodycommon{#1}{#2}{#3}%
-  \def#2##1 {\defxbodycommon \activeparens \spacesplit{#3{##1}}}%
-  \begingroup\obeylines\activeparens
-  % The \empty here prevents misinterpretation of a construct such as
-  %   @deffn {whatever} {Enharmonic comma}
-  % See comments at \deftpparsebody, although in our case we don't have
-  % to remove the \empty afterwards, since it is empty.
-  \spacesplit{#3{#4}}\empty
-}
-
-% Used for @deftypemethod and @deftypeivar.
-% #1, #2, #3 are the common arguments (see \defparsebody).
-% #4, delimited by a space, is the class name.
-% #5 is the method's return type.
-%
-\def\deftypemethparsebody#1#2#3#4 #5 {%
-  \parsebodycommon{#1}{#2}{#3}%
-  \def#2##1 ##2 {\defxbodycommon \activeparens \spacesplit{#3{##1}{##2}}}%
-  \begingroup\obeylines\activeparens
-  \spacesplit{#3{#4}{#5}}%
+  % As above, allow line break if we have multiple x headers in a row.
+  % It's not a great place, though.
+  \ifnum\lastpenalty=10002 \penalty3000 \fi
+  %
+  % And now, it's time to reuse the body of the original defun:
+  \expandafter\gobbledefun#1%
 }
+\def\gobbledefun#1\startdefun{}
 
-% Used for @deftypeop.  The change from \deftypemethparsebody is an
-% extra argument at the beginning which is the `category', instead of it
-% being the hardwired string `Method' or `Instance Variable'.  We have
-% to account for this both in the \...x definition and in parsing the
-% input at hand.  Thus also need a control sequence (passed as #5) for
-% the \E... definition to assign the category name to.
+% \printdefunline \deffnheader{text}
 %
-\def\deftypeopparsebody#1#2#3#4#5 #6 {%
-  \parsebodycommon{#1}{#2}{#3}%
-  \def#2##1 ##2 ##3 {\def#4{##1}%
-    \defxbodycommon \activeparens \spacesplit{#3{##2}{##3}}}%
-  \begingroup\obeylines\activeparens
-  \spacesplit{#3{#5}{#6}}%
+\def\printdefunline#1#2{%
+  \begingroup
+    % call \deffnheader:
+    #1#2 \endheader
+    % common ending:
+    \interlinepenalty = 10000
+    \advance\rightskip by 0pt plus 1fil
+    \endgraf
+    \nobreak\vskip -\parskip
+    \penalty 10002  % signal to \startdefun and \dodefunx
+    % Some of the @defun-type tags do not enable magic parentheses,
+    % rendering the following check redundant.  But we don't optimize.
+    \checkparencounts
+  \endgroup
 }
 
-% For @defop.
-\def\defopparsebody #1#2#3#4#5 {%
-  \parsebodycommon{#1}{#2}{#3}%
-  \def#2##1 ##2 {\def#4{##1}%
-    \defxbodycommon \activeparens \spacesplit{#3{##2}}}%
-  \begingroup\obeylines\activeparens
-  \spacesplit{#3{#5}}%
-}
+\def\Edefun{\endgraf\medbreak}
 
-% These parsing functions are similar to the preceding ones
-% except that they do not make parens into active characters.
-% These are used for "variables" since they have no arguments.
+% \makedefun{deffn} creates \deffn, \deffnx and \Edeffn;
+% the only thing remainnig is to define \deffnheader.
 %
-\def\defvarparsebody #1#2#3{%
-  \parsebodycommon{#1}{#2}{#3}%
-  \def#2{\defxbodycommon \spacesplit#3}%
-  \catcode\equalChar=\active
-  \begingroup\obeylines
-  \spacesplit#3%
-}
-
-% @defopvar.
-\def\defopvarparsebody #1#2#3#4#5 {%
-  \parsebodycommon{#1}{#2}{#3}%
-  \def#2##1 ##2 {\def#4{##1}%
-    \defxbodycommon \spacesplit{#3{##2}}}%
-  \begingroup\obeylines
-  \spacesplit{#3{#5}}%
-}
-
-\def\defvrparsebody#1#2#3#4 {%
-  \parsebodycommon{#1}{#2}{#3}%
-  \def#2##1 {\defxbodycommon \spacesplit{#3{##1}}}%
-  \begingroup\obeylines
-  \spacesplit{#3{#4}}%
+\def\makedefun#1{%
+  \expandafter\let\csname E#1\endcsname = \Edefun
+  \edef\temp{\noexpand\domakedefun
+    \makecsname{#1}\makecsname{#1x}\makecsname{#1header}}%
+  \temp
 }
 
-% This loses on `@deftp {Data Type} {struct termios}' -- it thinks the
-% type is just `struct', because we lose the braces in `{struct
-% termios}' when \spacesplit reads its undelimited argument.  Sigh.
-% \let\deftpparsebody=\defvrparsebody
+% \domakedefun \deffn \deffnx \deffnheader
 %
-% So, to get around this, we put \empty in with the type name.  That
-% way, TeX won't find exactly `{...}' as an undelimited argument, and
-% won't strip off the braces.
+% Define \deffn and \deffnx, without parameters.
+% \deffnheader has to be defined explicitly.
 %
-\def\deftpparsebody #1#2#3#4 {%
-  \parsebodycommon{#1}{#2}{#3}%
-  \def#2##1 {\defxbodycommon \spacesplit{#3{##1}}}%
-  \begingroup\obeylines
-  \spacesplit{\parsetpheaderline{#3{#4}}}\empty
+\def\domakedefun#1#2#3{%
+  \envdef#1{%
+    \startdefun
+    \parseargusing\activeparens{\printdefunline#3}%
+  }%
+  \def#2{\dodefunx#1}%
+  \def#3%
 }
 
-% Fine, but then we have to eventually remove the \empty *and* the
-% braces (if any).  That's what this does.
-%
-\def\removeemptybraces\empty#1\relax{#1}
-
-% After \spacesplit has done its work, this is called -- #1 is the final
-% thing to call, #2 the type name (which starts with \empty), and #3
-% (which might be empty) the arguments.
-%
-\def\parsetpheaderline#1#2#3{%
-  #1{\removeemptybraces#2\relax}{#3}%
-}%
+%%% Untyped functions:
 
-% Split up #2 (the rest of the input line) at the first space token.
-% call #1 with two arguments:
-%  the first is all of #2 before the space token,
-%  the second is all of #2 after that space token.
-% If #2 contains no space token, all of it is passed as the first arg
-% and the second is passed as empty.
-%
-{\obeylines %
- \gdef\spacesplit#1#2^^M{\endgroup\spacesplitx{#1}#2 \relax\spacesplitx}%
- \long\gdef\spacesplitx#1#2 #3#4\spacesplitx{%
-   \ifx\relax #3%
-     #1{#2}{}%
-   \else %
-     #1{#2}{#3#4}%
-   \fi}%
-}
+% @deffn category name args
+\makedefun{deffn}{\deffngeneral{}}
 
-% Define @defun.
+% @deffn category class name args
+\makedefun{defop}#1 {\defopon{#1\ \putwordon}}
 
-% This is called to end the arguments processing for all the @def... commands.
-%
-\def\defargscommonending{%
-  \interlinepenalty = 10000
-  \advance\rightskip by 0pt plus 1fil
-  \endgraf
-  \nobreak\vskip -\parskip
-  \penalty 10002  % signal to \parsebodycommon.
-}
+% \defopon {category on}class name args
+\def\defopon#1#2 {\deffngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
 
-% This expands the args and terminates the paragraph they comprise.
+% \deffngeneral {subind}category name args
 %
-\def\defunargs#1{\functionparens \sl
-% Expand, preventing hyphenation at `-' chars.
-% Note that groups don't affect changes in \hyphenchar.
-% Set the font temporarily and use \font in case \setfont made \tensl a macro.
-{\tensl\hyphenchar\font=0}%
-#1%
-{\tensl\hyphenchar\font=45}%
-\ifnum\parencount=0 \else \errmessage{Unbalanced parentheses in @def}\fi%
-  \defargscommonending
+\def\deffngeneral#1#2 #3 #4\endheader{%
+  % Remember that \dosubind{fn}{foo}{} is equivalent to \doind{fn}{foo}.
+  \dosubind{fn}{\code{#3}}{#1}%
+  \defname{#2}{}{#3}\magicamp\defunargs{#4\unskip}%
 }
 
-\def\deftypefunargs #1{%
-% Expand, preventing hyphenation at `-' chars.
-% Note that groups don't affect changes in \hyphenchar.
-% Use \boldbraxnoamp, not \functionparens, so that & is not special.
-\boldbraxnoamp
-\tclose{#1}% avoid \code because of side effects on active chars
-  \defargscommonending
-}
+%%% Typed functions:
 
-% Do complete processing of one @defun or @defunx line already parsed.
+% @deftypefn category type name args
+\makedefun{deftypefn}{\deftypefngeneral{}}
 
-% @deffn Command forward-char nchars
+% @deftypeop category class type name args
+\makedefun{deftypeop}#1 {\deftypeopon{#1\ \putwordon}}
 
-\def\deffn{\defmethparsebody\Edeffn\deffnx\deffnheader}
+% \deftypeopon {category on}class type name args
+\def\deftypeopon#1#2 {\deftypefngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
 
-\def\deffnheader #1#2#3{\doind {fn}{\code{#2}}%
-\begingroup\defname {#2}{#1}\defunargs{#3}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
+% \deftypefngeneral {subind}category type name args
+%
+\def\deftypefngeneral#1#2 #3 #4 #5\endheader{%
+  \dosubind{fn}{\code{#4}}{#1}%
+  \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
 }
 
-% @defun == @deffn Function
-
-\def\defun{\defparsebody\Edefun\defunx\defunheader}
+%%% Typed variables:
 
-\def\defunheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
-\begingroup\defname {#1}{\putwordDeffunc}%
-\defunargs {#2}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
-}
+% @deftypevr category type var args
+\makedefun{deftypevr}{\deftypecvgeneral{}}
 
-% @deftypefun int foobar (int @var{foo}, float @var{bar})
+% @deftypecv category class type var args
+\makedefun{deftypecv}#1 {\deftypecvof{#1\ \putwordof}}
 
-\def\deftypefun{\defparsebody\Edeftypefun\deftypefunx\deftypefunheader}
+% \deftypecvof {category of}class type var args
+\def\deftypecvof#1#2 {\deftypecvgeneral{\putwordof\ \code{#2}}{#1\ \code{#2}} }
 
-% #1 is the data type.  #2 is the name and args.
-\def\deftypefunheader #1#2{\deftypefunheaderx{#1}#2 \relax}
-% #1 is the data type, #2 the name, #3 the args.
-\def\deftypefunheaderx #1#2 #3\relax{%
-\doind {fn}{\code{#2}}% Make entry in function index
-\begingroup\defname {\defheaderxcond#1\relax$.$#2}{\putwordDeftypefun}%
-\deftypefunargs {#3}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
+% \deftypecvgeneral {subind}category type var args
+%
+\def\deftypecvgeneral#1#2 #3 #4 #5\endheader{%
+  \dosubind{vr}{\code{#4}}{#1}%
+  \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
 }
 
-% @deftypefn {Library Function} int foobar (int @var{foo}, float @var{bar})
-
-\def\deftypefn{\defmethparsebody\Edeftypefn\deftypefnx\deftypefnheader}
+%%% Untyped variables:
 
-% \defheaderxcond#1\relax$.$
-% puts #1 in @code, followed by a space, but does nothing if #1 is null.
-\def\defheaderxcond#1#2$.${\ifx#1\relax\else\code{#1#2} \fi}
+% @defvr category var args
+\makedefun{defvr}#1 {\deftypevrheader{#1} {} }
 
-% #1 is the classification.  #2 is the data type.  #3 is the name and args.
-\def\deftypefnheader #1#2#3{\deftypefnheaderx{#1}{#2}#3 \relax}
-% #1 is the classification, #2 the data type, #3 the name, #4 the args.
-\def\deftypefnheaderx #1#2#3 #4\relax{%
-\doind {fn}{\code{#3}}% Make entry in function index
-\begingroup
-\normalparens % notably, turn off `&' magic, which prevents
-%               at least some C++ text from working
-\defname {\defheaderxcond#2\relax$.$#3}{#1}%
-\deftypefunargs {#4}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
-}
-
-% @defmac == @deffn Macro
+% @defcv category class var args
+\makedefun{defcv}#1 {\defcvof{#1\ \putwordof}}
 
-\def\defmac{\defparsebody\Edefmac\defmacx\defmacheader}
+% \defcvof {category of}class var args
+\def\defcvof#1#2 {\deftypecvof{#1}#2 {} }
 
-\def\defmacheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
-\begingroup\defname {#1}{\putwordDefmac}%
-\defunargs {#2}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
+%%% Type:
+% @deftp category name args
+\makedefun{deftp}#1 #2 #3\endheader{%
+  \doind{tp}{\code{#2}}%
+  \defname{#1}{}{#2}\defunargs{#3\unskip}%
 }
 
-% @defspec == @deffn Special Form
-
-\def\defspec{\defparsebody\Edefspec\defspecx\defspecheader}
-
-\def\defspecheader #1#2{\doind {fn}{\code{#1}}% Make entry in function index
-\begingroup\defname {#1}{\putwordDefspec}%
-\defunargs {#2}\endgroup %
-\catcode\equalChar=\other % Turn off change made in \defparsebody
-}
+% Remaining @defun-like shortcuts:
+\makedefun{defun}{\deffnheader{\putwordDeffunc} }
+\makedefun{defmac}{\deffnheader{\putwordDefmac} }
+\makedefun{defspec}{\deffnheader{\putwordDefspec} }
+\makedefun{deftypefun}{\deftypefnheader{\putwordDeffunc} }
+\makedefun{defvar}{\defvrheader{\putwordDefvar} }
+\makedefun{defopt}{\defvrheader{\putwordDefopt} }
+\makedefun{deftypevar}{\deftypevrheader{\putwordDefvar} }
+\makedefun{defmethod}{\defopon\putwordMethodon}
+\makedefun{deftypemethod}{\deftypeopon\putwordMethodon}
+\makedefun{defivar}{\defcvof\putwordInstanceVariableof}
+\makedefun{deftypeivar}{\deftypecvof\putwordInstanceVariableof}
 
-% @defop CATEGORY CLASS OPERATION ARG...
+% \defname, which formats the name of the @def (not the args).
+% #1 is the category, such as "Function".
+% #2 is the return type, if any.
+% #3 is the function name.
 %
-\def\defop #1 {\def\defoptype{#1}%
-\defopparsebody\Edefop\defopx\defopheader\defoptype}
+% We are followed by (but not passed) the arguments, if any.
 %
-\def\defopheader#1#2#3{%
-  \dosubind{fn}{\code{#2}}{\putwordon\ \code{#1}}% function index entry
-  \begingroup
-    \defname{#2}{\defoptype\ \putwordon\ #1}%
-    \defunargs{#3}%
-  \endgroup
+\def\defname#1#2#3{%
+  % Get the values of \leftskip and \rightskip as they were outside the @def...
+  \advance\leftskip by -\defbodyindent
+  %
+  % How we'll format the type name.  Putting it in brackets helps
+  % distinguish it from the body text that may end up on the next line
+  % just below it.
+  \def\temp{#1}%
+  \setbox0=\hbox{\kern\deflastargmargin \ifx\temp\empty\else [\rm\temp]\fi}
+  %
+  % Figure out line sizes for the paragraph shape.
+  % The first line needs space for \box0; but if \rightskip is nonzero,
+  % we need only space for the part of \box0 which exceeds it:
+  \dimen0=\hsize  \advance\dimen0 by -\wd0  \advance\dimen0 by \rightskip
+  % The continuations:
+  \dimen2=\hsize  \advance\dimen2 by -\defargsindent
+  % (plain.tex says that \dimen1 should be used only as global.)
+  \parshape 2 0in \dimen0 \defargsindent \dimen2
+  %
+  % Put the type name to the right margin.
+  \noindent
+  \hbox to 0pt{%
+    \hfil\box0 \kern-\hsize
+    % \hsize has to be shortened this way:
+    \kern\leftskip
+    % Intentionally do not respect \rightskip, since we need the space.
+  }%
+  %
+  % Allow all lines to be underfull without complaint:
+  \tolerance=10000 \hbadness=10000
+  \exdentamount=\defbodyindent
+  {%
+    % defun fonts. We use typewriter by default (used to be bold) because:
+    % . we're printing identifiers, they should be in tt in principle.
+    % . in languages with many accents, such as Czech or French, it's
+    %   common to leave accents off identifiers.  The result looks ok in
+    %   tt, but exceedingly strange in rm.
+    % . we don't want -- and --- to be treated as ligatures.
+    % . this still does not fix the ?` and !` ligatures, but so far no
+    %   one has made identifiers using them :).
+    \df \tt
+    \def\temp{#2}% return value type
+    \ifx\temp\empty\else \tclose{\temp} \fi
+    #3% output function name
+  }%
+  {\rm\enskip}% hskip 0.5 em of \tenrm
+  %
+  \boldbrax
+  % arguments will be output next, if any.
 }
 
-% @deftypeop CATEGORY CLASS TYPE OPERATION ARG...
+% Print arguments in slanted roman (not ttsl), inconsistently with using
+% tt for the name.  This is because literal text is sometimes needed in
+% the argument list (groff manual), and ttsl and tt are not very
+% distinguishable.  Prevent hyphenation at `-' chars.
 %
-\def\deftypeop #1 {\def\deftypeopcategory{#1}%
-  \deftypeopparsebody\Edeftypeop\deftypeopx\deftypeopheader
-                       \deftypeopcategory}
-%
-% #1 is the class name, #2 the data type, #3 the operation name, #4 the args.
-\def\deftypeopheader#1#2#3#4{%
-  \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index
-  \begingroup
-    \defname{\defheaderxcond#2\relax$.$#3}
-            {\deftypeopcategory\ \putwordon\ \code{#1}}%
-    \deftypefunargs{#4}%
-  \endgroup
+\def\defunargs#1{%
+  % use sl by default (not ttsl),
+  % tt for the names.
+  \df \sl \hyphenchar\font=0
+  %
+  % On the other hand, if an argument has two dashes (for instance), we
+  % want a way to get ttsl.  Let's try @var for that.
+  \let\var=\ttslanted
+  #1%
+  \sl\hyphenchar\font=45
 }
 
-% @deftypemethod CLASS TYPE METHOD ARG...
-%
-\def\deftypemethod{%
-  \deftypemethparsebody\Edeftypemethod\deftypemethodx\deftypemethodheader}
+% We want ()&[] to print specially on the defun line.
 %
-% #1 is the class name, #2 the data type, #3 the method name, #4 the args.
-\def\deftypemethodheader#1#2#3#4{%
-  \dosubind{fn}{\code{#3}}{\putwordon\ \code{#1}}% entry in function index
-  \begingroup
-    \defname{\defheaderxcond#2\relax$.$#3}{\putwordMethodon\ \code{#1}}%
-    \deftypefunargs{#4}%
-  \endgroup
+\def\activeparens{%
+  \catcode`\(=\active \catcode`\)=\active
+  \catcode`\[=\active \catcode`\]=\active
+  \catcode`\&=\active
 }
 
-% @deftypeivar CLASS TYPE VARNAME
-%
-\def\deftypeivar{%
-  \deftypemethparsebody\Edeftypeivar\deftypeivarx\deftypeivarheader}
-%
-% #1 is the class name, #2 the data type, #3 the variable name.
-\def\deftypeivarheader#1#2#3{%
-  \dosubind{vr}{\code{#3}}{\putwordof\ \code{#1}}% entry in variable index
-  \begingroup
-    \defname{\defheaderxcond#2\relax$.$#3}
-            {\putwordInstanceVariableof\ \code{#1}}%
-    \defvarargs{#3}%
-  \endgroup
-}
+% Make control sequences which act like normal parenthesis chars.
+\let\lparen = ( \let\rparen = )
 
-% @defmethod == @defop Method
-%
-\def\defmethod{\defmethparsebody\Edefmethod\defmethodx\defmethodheader}
-%
-% #1 is the class name, #2 the method name, #3 the args.
-\def\defmethodheader#1#2#3{%
-  \dosubind{fn}{\code{#2}}{\putwordon\ \code{#1}}% entry in function index
-  \begingroup
-    \defname{#2}{\putwordMethodon\ \code{#1}}%
-    \defunargs{#3}%
-  \endgroup
+% Be sure that we always have a definition for `(', etc.  For example,
+% if the fn name has parens in it, \boldbrax will not be in effect yet,
+% so TeX would otherwise complain about undefined control sequence.
+{
+  \activeparens
+  \global\let(=\lparen \global\let)=\rparen
+  \global\let[=\lbrack \global\let]=\rbrack
+  \global\let& = \&
+
+  \gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
+  \gdef\magicamp{\let&=\amprm}
 }
 
-% @defcv {Class Option} foo-class foo-flag
+\newcount\parencount
 
-\def\defcv #1 {\def\defcvtype{#1}%
-\defopvarparsebody\Edefcv\defcvx\defcvarheader\defcvtype}
+% If we encounter &foo, then turn on ()-hacking afterwards
+\newif\ifampseen
+\def\amprm#1 {\ampseentrue{\bf\&#1 }}
 
-\def\defcvarheader #1#2#3{%
-  \dosubind{vr}{\code{#2}}{\putwordof\ \code{#1}}% variable index entry
-  \begingroup
-    \defname{#2}{\defcvtype\ \putwordof\ #1}%
-    \defvarargs{#3}%
-  \endgroup
+\def\parenfont{%
+  \ifampseen
+    % At the first level, print parens in roman,
+    % otherwise use the default font.
+    \ifnum \parencount=1 \rm \fi
+  \else
+    % The \sf parens (in \boldbrax) actually are a little bolder than
+    % the contained text.  This is especially needed for [ and ] .
+    \sf
+  \fi
 }
-
-% @defivar CLASS VARNAME == @defcv {Instance Variable} CLASS VARNAME
-%
-\def\defivar{\defvrparsebody\Edefivar\defivarx\defivarheader}
-%
-\def\defivarheader#1#2#3{%
-  \dosubind{vr}{\code{#2}}{\putwordof\ \code{#1}}% entry in var index
-  \begingroup
-    \defname{#2}{\putwordInstanceVariableof\ #1}%
-    \defvarargs{#3}%
-  \endgroup
+\def\infirstlevel#1{%
+  \ifampseen
+    \ifnum\parencount=1
+      #1%
+    \fi
+  \fi
 }
+\def\bfafterword#1 {#1 \bf}
 
-% @defvar
-% First, define the processing that is wanted for arguments of @defvar.
-% This is actually simple: just print them in roman.
-% This must expand the args and terminate the paragraph they make up
-\def\defvarargs #1{\normalparens #1%
-  \defargscommonending
+\def\opnr{%
+  \global\advance\parencount by 1
+  {\parenfont(}%
+  \infirstlevel \bfafterword
 }
-
-% @defvr Counter foo-count
-
-\def\defvr{\defvrparsebody\Edefvr\defvrx\defvrheader}
-
-\def\defvrheader #1#2#3{\doind {vr}{\code{#2}}%
-\begingroup\defname {#2}{#1}\defvarargs{#3}\endgroup}
-
-% @defvar == @defvr Variable
-
-\def\defvar{\defvarparsebody\Edefvar\defvarx\defvarheader}
-
-\def\defvarheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index
-\begingroup\defname {#1}{\putwordDefvar}%
-\defvarargs {#2}\endgroup %
+\def\clnr{%
+  {\parenfont)}%
+  \infirstlevel \sl
+  \global\advance\parencount by -1
 }
 
-% @defopt == @defvr {User Option}
-
-\def\defopt{\defvarparsebody\Edefopt\defoptx\defoptheader}
-
-\def\defoptheader #1#2{\doind {vr}{\code{#1}}% Make entry in var index
-\begingroup\defname {#1}{\putwordDefopt}%
-\defvarargs {#2}\endgroup %
+\newcount\brackcount
+\def\lbrb{%
+  \global\advance\brackcount by 1
+  {\bf[}%
+}
+\def\rbrb{%
+  {\bf]}%
+  \global\advance\brackcount by -1
 }
 
-% @deftypevar int foobar
-
-\def\deftypevar{\defvarparsebody\Edeftypevar\deftypevarx\deftypevarheader}
-
-% #1 is the data type.  #2 is the name, perhaps followed by text that
-% is actually part of the data type, which should not be put into the index.
-\def\deftypevarheader #1#2{%
-\dovarind#2 \relax% Make entry in variables index
-\begingroup\defname {\defheaderxcond#1\relax$.$#2}{\putwordDeftypevar}%
-  \defargscommonending
-\endgroup}
-\def\dovarind#1 #2\relax{\doind{vr}{\code{#1}}}
-
-% @deftypevr {Global Flag} int enable
-
-\def\deftypevr{\defvrparsebody\Edeftypevr\deftypevrx\deftypevrheader}
-
-\def\deftypevrheader #1#2#3{\dovarind#3 \relax%
-\begingroup\defname {\defheaderxcond#2\relax$.$#3}{#1}
-  \defargscommonending
-\endgroup}
-
-% Now define @deftp
-% Args are printed in bold, a slight difference from @defvar.
-
-\def\deftpargs #1{\bf \defvarargs{#1}}
-
-% @deftp Class window height width ...
-
-\def\deftp{\deftpparsebody\Edeftp\deftpx\deftpheader}
-
-\def\deftpheader #1#2#3{\doind {tp}{\code{#2}}%
-\begingroup\defname {#2}{#1}\deftpargs{#3}\endgroup}
-
-% These definitions are used if you use @defunx (etc.)
-% anywhere other than immediately after a @defun or @defunx.
-%
-\def\defcvx#1 {\errmessage{@defcvx in invalid context}}
-\def\deffnx#1 {\errmessage{@deffnx in invalid context}}
-\def\defivarx#1 {\errmessage{@defivarx in invalid context}}
-\def\defmacx#1 {\errmessage{@defmacx in invalid context}}
-\def\defmethodx#1 {\errmessage{@defmethodx in invalid context}}
-\def\defoptx #1 {\errmessage{@defoptx in invalid context}}
-\def\defopx#1 {\errmessage{@defopx in invalid context}}
-\def\defspecx#1 {\errmessage{@defspecx in invalid context}}
-\def\deftpx#1 {\errmessage{@deftpx in invalid context}}
-\def\deftypefnx#1 {\errmessage{@deftypefnx in invalid context}}
-\def\deftypefunx#1 {\errmessage{@deftypefunx in invalid context}}
-\def\deftypeivarx#1 {\errmessage{@deftypeivarx in invalid context}}
-\def\deftypemethodx#1 {\errmessage{@deftypemethodx in invalid context}}
-\def\deftypeopx#1 {\errmessage{@deftypeopx in invalid context}}
-\def\deftypevarx#1 {\errmessage{@deftypevarx in invalid context}}
-\def\deftypevrx#1 {\errmessage{@deftypevrx in invalid context}}
-\def\defunx#1 {\errmessage{@defunx in invalid context}}
-\def\defvarx#1 {\errmessage{@defvarx in invalid context}}
-\def\defvrx#1 {\errmessage{@defvrx in invalid context}}
+\def\checkparencounts{%
+  \ifnum\parencount=0 \else \badparencount \fi
+  \ifnum\brackcount=0 \else \badbrackcount \fi
+}
+\def\badparencount{%
+  \errmessage{Unbalanced parentheses in @def}%
+  \global\parencount=0
+}
+\def\badbrackcount{%
+  \errmessage{Unbalanced square braces in @def}%
+  \global\brackcount=0
+}
 
 
 \message{macros,}
 % @macro.
 
-% To do this right we need a feature of e-TeX, \scantokens,
-% which we arrange to emulate with a temporary file in ordinary TeX.
-\ifx\eTeXversion\undefined
- \newwrite\macscribble
- \def\scanmacro#1{%
-   \begingroup \newlinechar`\^^M
-   % Undo catcode changes of \startcontents and \doprintindex
-   \catcode`\@=0 \catcode`\\=\other \escapechar=`\@
-   % Append \endinput to make sure that TeX does not see the ending newline.
-   \toks0={#1\endinput}%
-   \immediate\openout\macscribble=\jobname.tmp
-   \immediate\write\macscribble{\the\toks0}%
-   \immediate\closeout\macscribble
-   \let\xeatspaces\eatspaces
-   \input \jobname.tmp
-   \endgroup
+% To do this right we need a feature of e-TeX, \scantokens,
+% which we arrange to emulate with a temporary file in ordinary TeX.
+\ifx\eTeXversion\undefined
+  \newwrite\macscribble
+  \def\scantokens#1{%
+    \toks0={#1}%
+    \immediate\openout\macscribble=\jobname.tmp
+    \immediate\write\macscribble{\the\toks0}%
+    \immediate\closeout\macscribble
+    \input \jobname.tmp
+  }
+\fi
+
+\def\scanmacro#1{%
+  \begingroup
+    \newlinechar`\^^M
+    \let\xeatspaces\eatspaces
+    % Undo catcode changes of \startcontents and \doprintindex
+    % When called from @insertcopying or (short)caption, we need active
+    % backslash to get it printed correctly.  Previously, we had
+    % \catcode`\\=\other instead.  We'll see whether a problem appears
+    % with macro expansion.				--kasal, 19aug04
+    \catcode`\@=0 \catcode`\\=\active \escapechar=`\@
+    % ... and \example
+    \spaceisspace
+    %
+    % Append \endinput to make sure that TeX does not see the ending newline.
+    %
+    % I've verified that it is necessary both for e-TeX and for ordinary TeX
+    %							--kasal, 29nov03
+    \scantokens{#1\endinput}%
+  \endgroup
+}
+
+\def\scanexp#1{%
+  \edef\temp{\noexpand\scanmacro{#1}}%
+  \temp
 }
-\else
-\def\scanmacro#1{%
-\begingroup \newlinechar`\^^M
-% Undo catcode changes of \startcontents and \doprintindex
-\catcode`\@=0 \catcode`\\=\other \escapechar=`\@
-\let\xeatspaces\eatspaces\scantokens{#1\endinput}\endgroup}
-\fi
 
 \newcount\paramno   % Count of parameters
 \newtoks\macname    % Macro name
@@ -5586,13 +5495,15 @@
                     % \do\macro1\do\macro2...
 
 % Utility routines.
-% Thisdoes \let #1 = #2, except with \csnames.
+% This does \let #1 = #2, with \csnames; that is,
+%   \let \csname#1\endcsname = \csname#2\endcsname
+% (except of course we have to play expansion games).
+% 
 \def\cslet#1#2{%
-\expandafter\expandafter
-\expandafter\let
-\expandafter\expandafter
-\csname#1\endcsname
-\csname#2\endcsname}
+  \expandafter\let
+  \csname#1\expandafter\endcsname
+  \csname#2\endcsname
+}
 
 % Trim leading and trailing spaces off a string.
 % Concepts from aro-bend problem 15 (see CTAN).
@@ -5619,30 +5530,36 @@
 % done by  making ^^M (\endlinechar) catcode 12 when reading the macro
 % body, and then making it the \newlinechar in \scanmacro.
 
-\def\macrobodyctxt{%
-  \catcode`\~=\other
+\def\scanctxt{%
+  \catcode`\"=\other
+  \catcode`\+=\other
+  \catcode`\<=\other
+  \catcode`\>=\other
+  \catcode`\@=\other
   \catcode`\^=\other
   \catcode`\_=\other
   \catcode`\|=\other
-  \catcode`\<=\other
-  \catcode`\>=\other
-  \catcode`\+=\other
+  \catcode`\~=\other
+}
+
+\def\scanargctxt{%
+  \scanctxt
+  \catcode`\\=\other
+  \catcode`\^^M=\other
+}
+
+\def\macrobodyctxt{%
+  \scanctxt
   \catcode`\{=\other
   \catcode`\}=\other
-  \catcode`\@=\other
   \catcode`\^^M=\other
-  \usembodybackslash}
+  \usembodybackslash
+}
 
 \def\macroargctxt{%
-  \catcode`\~=\other
-  \catcode`\^=\other
-  \catcode`\_=\other
-  \catcode`\|=\other
-  \catcode`\<=\other
-  \catcode`\>=\other
-  \catcode`\+=\other
-  \catcode`\@=\other
-  \catcode`\\=\other}
+  \scanctxt
+  \catcode`\\=\other
+}
 
 % \mbodybackslash is the definition of \ in @macro bodies.
 % It maps \foo\ => \csname macarg.foo\endcsname => #N
@@ -5683,8 +5600,7 @@
   \else \expandafter\parsemacbody
   \fi}
 
-\def\unmacro{\parsearg\dounmacro}
-\def\dounmacro#1{%
+\parseargdef\unmacro{%
   \if1\csname ismacro.#1\endcsname
     \global\cslet{#1}{macsave.#1}%
     \global\expandafter\let \csname ismacro.#1\endcsname=0%
@@ -5825,25 +5741,41 @@
     \expandafter\parsearg
   \fi \next}
 
-% We mant to disable all macros during \shipout so that they are not
+% We want to disable all macros during \shipout so that they are not
 % expanded by \write.
 \def\turnoffmacros{\begingroup \def\do##1{\let\noexpand##1=\relax}%
   \edef\next{\macrolist}\expandafter\endgroup\next}
 
+% For \indexnofonts, we need to get rid of all macros, leaving only the
+% arguments (if present).  Of course this is not nearly correct, but it
+% is the best we can do for now.  makeinfo does not expand macros in the
+% argument to @deffn, which ends up writing an index entry, and texindex
+% isn't prepared for an index sort entry that starts with \.
+% 
+% Since macro invocations are followed by braces, we can just redefine them
+% to take a single TeX argument.  The case of a macro invocation that
+% goes to end-of-line is not handled.
+% 
+\def\emptyusermacros{\begingroup
+  \def\do##1{\let\noexpand##1=\noexpand\asis}%
+  \edef\next{\macrolist}\expandafter\endgroup\next}
+
 
 % @alias.
 % We need some trickery to remove the optional spaces around the equal
 % sign.  Just make them active and then expand them all to nothing.
-\def\alias{\begingroup\obeyspaces\parsearg\aliasxxx}
+\def\alias{\parseargusing\obeyspaces\aliasxxx}
 \def\aliasxxx #1{\aliasyyy#1\relax}
-\def\aliasyyy #1=#2\relax{\ignoreactivespaces
-\edef\next{\global\let\expandafter\noexpand\csname#1\endcsname=%
-           \expandafter\noexpand\csname#2\endcsname}%
-\expandafter\endgroup\next}
+\def\aliasyyy #1=#2\relax{%
+  {%
+    \expandafter\let\obeyedspace=\empty
+    \xdef\next{\global\let\makecsname{#1}=\makecsname{#2}}%
+  }%
+  \next
+}
 
 
 \message{cross references,}
-% @xref etc.
 
 \newwrite\auxfile
 
@@ -5855,64 +5787,70 @@
 \def\inforefzzz #1,#2,#3,#4**{\putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}},
   node \samp{\ignorespaces#1{}}}
 
-% @node's job is to define \lastnode.
-\def\node{\ENVcheck\parsearg\nodezzz}
-\def\nodezzz#1{\nodexxx #1,\finishnodeparse}
-\def\nodexxx#1,#2\finishnodeparse{\gdef\lastnode{#1}}
+% @node's only job in TeX is to define \lastnode, which is used in
+% cross-references.  The @node line might or might not have commas, and
+% might or might not have spaces before the first comma, like:
+% @node foo , bar , ...
+% We don't want such trailing spaces in the node name.
+%
+\parseargdef\node{\checkenv{}\donode #1 ,\finishnodeparse}
+%
+% also remove a trailing comma, in case of something like this:
+% @node Help-Cross,  ,  , Cross-refs
+\def\donode#1 ,#2\finishnodeparse{\dodonode #1,\finishnodeparse}
+\def\dodonode#1,#2\finishnodeparse{\gdef\lastnode{#1}}
+
 \let\nwnode=\node
-\let\lastnode=\relax
+\let\lastnode=\empty
 
-% The sectioning commands (@chapter, etc.) call these.
-\def\donoderef{%
-  \ifx\lastnode\relax\else
-    \expandafter\expandafter\expandafter\setref{\lastnode}%
-      {Ysectionnumberandtype}%
-    \global\let\lastnode=\relax
-  \fi
-}
-\def\unnumbnoderef{%
-  \ifx\lastnode\relax\else
-    \expandafter\expandafter\expandafter\setref{\lastnode}{Ynothing}%
-    \global\let\lastnode=\relax
-  \fi
-}
-\def\appendixnoderef{%
-  \ifx\lastnode\relax\else
-    \expandafter\expandafter\expandafter\setref{\lastnode}%
-      {Yappendixletterandtype}%
-    \global\let\lastnode=\relax
+% Write a cross-reference definition for the current node.  #1 is the
+% type (Ynumbered, Yappendix, Ynothing).
+%
+\def\donoderef#1{%
+  \ifx\lastnode\empty\else
+    \setref{\lastnode}{#1}%
+    \global\let\lastnode=\empty
   \fi
 }
 
-
 % @anchor{NAME} -- define xref target at arbitrary point.
 %
 \newcount\savesfregister
-\gdef\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
-\gdef\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
-\gdef\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
+%
+\def\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
+\def\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
+\def\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
 
 % \setref{NAME}{SNT} defines a cross-reference point NAME (a node or an
-% anchor), namely NAME-title (the corresponding @chapter/etc. name),
-% NAME-pg (the page number), and NAME-snt (section number and type).
-% Called from \foonoderef.
-%
-% We have to set \indexdummies so commands such as @code in a section
-% title aren't expanded.  It would be nicer not to expand the titles in
-% the first place, but there's so many layers that that is hard to do.
-%
-% Likewise, use \turnoffactive so that punctuation chars such as underscore
-% and backslash work in node names.
+% anchor), which consists of three parts:
+% 1) NAME-title - the current sectioning name taken from \thissection,
+%                 or the anchor name.
+% 2) NAME-snt   - section number and type, passed as the SNT arg, or
+%                 empty for anchors.
+% 3) NAME-pg    - the page number.
+%
+% This is called from \donoderef, \anchor, and \dofloat.  In the case of
+% floats, there is an additional part, which is not written here:
+% 4) NAME-lof   - the text as it should appear in a @listoffloats.
 %
-\def\setref#1#2{{%
-  \atdummies
+\def\setref#1#2{%
   \pdfmkdest{#1}%
-  %
-  \turnoffactive
-  \dosetq{#1-title}{Ytitle}%
-  \dosetq{#1-pg}{Ypagenumber}%
-  \dosetq{#1-snt}{#2}%
-}}
+  \iflinks
+    {%
+      \atdummies  % preserve commands, but don't expand them
+      \turnoffactive
+      \otherbackslash
+      \edef\writexrdef##1##2{%
+	\write\auxfile{@xrdef{#1-% #1 of \setref, expanded by the \edef
+	  ##1}{##2}}% these are parameters of \writexrdef
+      }%
+      \toks0 = \expandafter{\thissection}%
+      \immediate \writexrdef{title}{\the\toks0 }%
+      \immediate \writexrdef{snt}{\csname #2\endcsname}% \Ynumbered etc.
+      \writexrdef{pg}{\folio}% will be written later, during \shipout
+    }%
+  \fi
+}
 
 % @xref, @pxref, and @ref generate cross-references.  For \xrefX, #1 is
 % the node name, #2 the name of the Info cross-reference, #3 the printed
@@ -5925,38 +5863,33 @@
 \def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup
   \unsepspaces
   \def\printedmanual{\ignorespaces #5}%
-  \def\printednodename{\ignorespaces #3}%
-  \setbox1=\hbox{\printedmanual}%
-  \setbox0=\hbox{\printednodename}%
+  \def\printedrefname{\ignorespaces #3}%
+  \setbox1=\hbox{\printedmanual\unskip}%
+  \setbox0=\hbox{\printedrefname\unskip}%
   \ifdim \wd0 = 0pt
     % No printed node name was explicitly given.
     \expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax
       % Use the node name inside the square brackets.
-      \def\printednodename{\ignorespaces #1}%
+      \def\printedrefname{\ignorespaces #1}%
     \else
       % Use the actual chapter/section title appear inside
       % the square brackets.  Use the real section title if we have it.
       \ifdim \wd1 > 0pt
         % It is in another manual, so we don't have it.
-        \def\printednodename{\ignorespaces #1}%
+        \def\printedrefname{\ignorespaces #1}%
       \else
         \ifhavexrefs
           % We know the real title if we have the xref values.
-          \def\printednodename{\refx{#1-title}{}}%
+          \def\printedrefname{\refx{#1-title}{}}%
         \else
           % Otherwise just copy the Info node name.
-          \def\printednodename{\ignorespaces #1}%
+          \def\printedrefname{\ignorespaces #1}%
         \fi%
       \fi
     \fi
   \fi
   %
-  % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
-  % insert empty discretionaries after hyphens, which means that it will
-  % not find a line break at a hyphen in a node names.  Since some manuals
-  % are best written with fairly long node names, containing hyphens, this
-  % is a loss.  Therefore, we give the text of the node name again, so it
-  % is as if TeX is seeing it for the first time.
+  % Make link in pdf output.
   \ifpdf
     \leavevmode
     \getfilename{#4}%
@@ -5966,64 +5899,86 @@
          goto file{\the\filename.pdf} name{#1}%
      \else
        \startlink attr{/Border [0 0 0]}%
-         goto name{#1}%
+         goto name{\pdfmkpgn{#1}}%
      \fi
     }%
     \linkcolor
   \fi
   %
-  \ifdim \wd1 > 0pt
-    \putwordsection{} ``\printednodename'' \putwordin{} \cite{\printedmanual}%
-  \else
-    % _ (for example) has to be the character _ for the purposes of the
-    % control sequence corresponding to the node, but it has to expand
-    % into the usual \leavevmode...\vrule stuff for purposes of
-    % printing. So we \turnoffactive for the \refx-snt, back on for the
-    % printing, back off for the \refx-pg.
-    {\turnoffactive \otherbackslash
-     % Only output a following space if the -snt ref is nonempty; for
-     % @unnumbered and @anchor, it won't be.
-     \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
-     \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
-    }%
-    % output the `[mynode]' via a macro.
-    \xrefprintnodename\printednodename
+  % Float references are printed completely differently: "Figure 1.2"
+  % instead of "[somenode], p.3".  We distinguish them by the
+  % LABEL-title being set to a magic string.
+  {%
+    % Have to otherify everything special to allow the \csname to
+    % include an _ in the xref name, etc.
+    \indexnofonts
+    \turnoffactive
+    \otherbackslash
+    \expandafter\global\expandafter\let\expandafter\Xthisreftitle
+      \csname XR#1-title\endcsname
+  }%
+  \iffloat\Xthisreftitle
+    % If the user specified the print name (third arg) to the ref,
+    % print it instead of our usual "Figure 1.2".
+    \ifdim\wd0 = 0pt
+      \refx{#1-snt}%
+    \else
+      \printedrefname
+    \fi
     %
-    % But we always want a comma and a space:
-    ,\space
+    % if the user also gave the printed manual name (fifth arg), append
+    % "in MANUALNAME".
+    \ifdim \wd1 > 0pt
+      \space \putwordin{} \cite{\printedmanual}%
+    \fi
+  \else
+    % node/anchor (non-float) references.
     %
-    % output the `page 3'.
-    \turnoffactive \otherbackslash \putwordpage\tie\refx{#1-pg}{}%
+    % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
+    % insert empty discretionaries after hyphens, which means that it will
+    % not find a line break at a hyphen in a node names.  Since some manuals
+    % are best written with fairly long node names, containing hyphens, this
+    % is a loss.  Therefore, we give the text of the node name again, so it
+    % is as if TeX is seeing it for the first time.
+    \ifdim \wd1 > 0pt
+      \putwordsection{} ``\printedrefname'' \putwordin{} \cite{\printedmanual}%
+    \else
+      % _ (for example) has to be the character _ for the purposes of the
+      % control sequence corresponding to the node, but it has to expand
+      % into the usual \leavevmode...\vrule stuff for purposes of
+      % printing. So we \turnoffactive for the \refx-snt, back on for the
+      % printing, back off for the \refx-pg.
+      {\turnoffactive \otherbackslash
+       % Only output a following space if the -snt ref is nonempty; for
+       % @unnumbered and @anchor, it won't be.
+       \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
+       \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
+      }%
+      % output the `[mynode]' via a macro so it can be overridden.
+      \xrefprintnodename\printedrefname
+      %
+      % But we always want a comma and a space:
+      ,\space
+      %
+      % output the `page 3'.
+      \turnoffactive \otherbackslash \putwordpage\tie\refx{#1-pg}{}%
+    \fi
   \fi
   \endlink
 \endgroup}
 
 % This macro is called from \xrefX for the `[nodename]' part of xref
 % output.  It's a separate macro only so it can be changed more easily,
-% since not square brackets don't work in some documents.  Particularly
+% since square brackets don't work well in some documents.  Particularly
 % one that Bob is working on :).
 %
 \def\xrefprintnodename#1{[#1]}
 
-% \dosetq is called from \setref to do the actual \write (\iflinks).
-%
-\def\dosetq#1#2{%
-  {\let\folio=0%
-   \edef\next{\write\auxfile{\internalsetq{#1}{#2}}}%
-   \iflinks \next \fi
-  }%
-}
-
-% \internalsetq{foo}{page} expands into
-%   CHARACTERS @xrdef{foo}{...expansion of \page...}
-\def\internalsetq#1#2{@xrdef{#1}{\csname #2\endcsname}}
-
-% Things to be expanded by \internalsetq.
+% Things referred to by \setref.
 %
-\def\Ypagenumber{\folio}
-\def\Ytitle{\thissection}
 \def\Ynothing{}
-\def\Ysectionnumberandtype{%
+\def\Yomitfromtoc{}
+\def\Ynumbered{%
   \ifnum\secno=0
     \putwordChapter at tie \the\chapno
   \else \ifnum\subsecno=0
@@ -6034,8 +5989,7 @@
     \putwordSection at tie \the\chapno.\the\secno.\the\subsecno.\the\subsubsecno
   \fi\fi\fi
 }
-
-\def\Yappendixletterandtype{%
+\def\Yappendix{%
   \ifnum\secno=0
      \putwordAppendix at tie @char\the\appendixno{}%
   \else \ifnum\subsecno=0
@@ -6048,15 +6002,6 @@
   \fi\fi\fi
 }
 
-% Use TeX 3.0's \inputlineno to get the line number, for better error
-% messages, but if we're using an old version of TeX, don't do anything.
-%
-\ifx\inputlineno\thisisundefined
-  \let\linenumber = \empty % Pre-3.0.
-\else
-  \def\linenumber{\the\inputlineno:\space}
-\fi
-
 % Define \refx{NAME}{SUFFIX} to reference a cross-reference string named NAME.
 % If its value is nonempty, SUFFIX is output afterward.
 %
@@ -6065,7 +6010,7 @@
     \indexnofonts
     \otherbackslash
     \expandafter\global\expandafter\let\expandafter\thisrefX
-      \csname X#1\endcsname
+      \csname XR#1\endcsname
   }%
   \ifx\thisrefX\relax
     % If not defined, say something at least.
@@ -6087,11 +6032,44 @@
   #2% Output the suffix in any case.
 }
 
-% This is the macro invoked by entries in the aux file.
-%
-\def\xrdef#1{\expandafter\gdef\csname X#1\endcsname}
+% This is the macro invoked by entries in the aux file.  Usually it's
+% just a \def (we prepend XR to the control sequence name to avoid
+% collisions).  But if this is a float type, we have more work to do.
+%
+\def\xrdef#1#2{%
+  \expandafter\gdef\csname XR#1\endcsname{#2}% remember this xref value.
+  %
+  % Was that xref control sequence that we just defined for a float?
+  \expandafter\iffloat\csname XR#1\endcsname
+    % it was a float, and we have the (safe) float type in \iffloattype.
+    \expandafter\let\expandafter\floatlist
+      \csname floatlist\iffloattype\endcsname
+    %
+    % Is this the first time we've seen this float type?
+    \expandafter\ifx\floatlist\relax
+      \toks0 = {\do}% yes, so just \do
+    \else
+      % had it before, so preserve previous elements in list.
+      \toks0 = \expandafter{\floatlist\do}%
+    \fi
+    %
+    % Remember this xref in the control sequence \floatlistFLOATTYPE,
+    % for later use in \listoffloats.
+    \expandafter\xdef\csname floatlist\iffloattype\endcsname{\the\toks0{#1}}%
+  \fi
+}
 
 % Read the last existing aux file, if any.  No error if none exists.
+%
+\def\tryauxfile{%
+  \openin 1 \jobname.aux
+  \ifeof 1 \else
+    \readauxfile
+    \global\havexrefstrue
+  \fi
+  \closein 1
+}
+
 \def\readauxfile{\begingroup
   \catcode`\^^@=\other
   \catcode`\^^A=\other
@@ -6150,7 +6128,16 @@
   \catcode`\%=\other
   \catcode`+=\other % avoid \+ for paranoia even though we've turned it off
   %
-  % Make the characters 128-255 be printing characters
+  % This is to support \ in node names and titles, since the \
+  % characters end up in a \csname.  It's easier than
+  % leaving it active and making its active definition an actual \
+  % character.  What I don't understand is why it works in the *value*
+  % of the xrdef.  Seems like it should be a catcode12 \, and that
+  % should not typeset properly.  But it works, so I'm moving on for
+  % now.  --karl, 15jan04.
+  \catcode`\\=\other
+  %
+  % Make the characters 128-255 be printing characters.
   {%
     \count 1=128
     \def\loop{%
@@ -6160,31 +6147,17 @@
     }%
   }%
   %
-  % Turn off \ as an escape so we do not lose on
-  % entries which were dumped with control sequences in their names.
-  % For example, @xrdef{$\leq $-fun}{page ...} made by @defun ^^
-  % Reference to such entries still does not work the way one would wish,
-  % but at least they do not bomb out when the aux file is read in.
-  \catcode`\\=\other
-  %
-  % @ is our escape character in .aux files.
+  % @ is our escape character in .aux files, and we need braces.
   \catcode`\{=1
   \catcode`\}=2
   \catcode`\@=0
   %
-  \openin 1 \jobname.aux
-  \ifeof 1 \else
-    \closein 1
-    \input \jobname.aux
-    \global\havexrefstrue
-    \global\warnedobstrue
-  \fi
-  % Open the new aux file.  TeX will close it automatically at exit.
-  \openout\auxfile=\jobname.aux
+  \input \jobname.aux
 \endgroup}
 
 
-% Footnotes.
+\message{insertions,}
+% including footnotes.
 
 \newcount \footnoteno
 
@@ -6198,13 +6171,12 @@
 % @footnotestyle is meaningful for info output only.
 \let\footnotestyle=\comment
 
-\let\ptexfootnote=\footnote
-
 {\catcode `\@=11
 %
 % Auto-number footnotes.  Otherwise like plain.
 \gdef\footnote{%
   \let\indent=\ptexindent
+  \let\noindent=\ptexnoindent
   \global\advance\footnoteno by \@ne
   \edef\thisfootno{$^{\the\footnoteno}$}%
   %
@@ -6222,17 +6194,12 @@
 % Don't bother with the trickery in plain.tex to not require the
 % footnote text as a parameter.  Our footnotes don't need to be so general.
 %
-% Oh yes, they do; otherwise, @ifset and anything else that uses
-% \parseargline fail inside footnotes because the tokens are fixed when
+% Oh yes, they do; otherwise, @ifset (and anything else that uses
+% \parseargline) fails inside footnotes because the tokens are fixed when
 % the footnote is read.  --karl, 16nov96.
 %
-% The start of the footnote looks usually like this:
-\gdef\startfootins{\insert\footins\bgroup}
-%
-% ... but this macro is redefined inside @multitable.
-%
 \gdef\dofootnote{%
-  \startfootins
+  \insert\footins\bgroup
   % We want to typeset this text as a normal paragraph, even if the
   % footnote reference occurs in (for example) a display environment.
   % So reset some parameters.
@@ -6268,40 +6235,66 @@
 }
 }%end \catcode `\@=11
 
-% @| inserts a changebar to the left of the current line.  It should
-% surround any changed text.  This approach does *not* work if the
-% change spans more than two lines of output.  To handle that, we would
-% have adopt a much more difficult approach (putting marks into the main
-% vertical list for the beginning and end of each change).
-%
-\def\|{%
-  % \vadjust can only be used in horizontal mode.
-  \leavevmode
-  %
-  % Append this vertical mode material after the current line in the output.
-  \vadjust{%
-    % We want to insert a rule with the height and depth of the current
-    % leading; that is exactly what \strutbox is supposed to record.
-    \vskip-\baselineskip
-    %
-    % \vadjust-items are inserted at the left edge of the type.  So
-    % the \llap here moves out into the left-hand margin.
-    \llap{%
-      %
-      % For a thicker or thinner bar, change the `1pt'.
-      \vrule height\baselineskip width1pt
-      %
-      % This is the space between the bar and the text.
-      \hskip 12pt
-    }%
-  }%
+% In case a @footnote appears in a vbox, save the footnote text and create
+% the real \insert just after the vbox finished.  Otherwise, the insertion
+% would be lost.
+% Similarily, if a @footnote appears inside an alignment, save the footnote
+% text to a box and make the \insert when a row of the table is finished.
+% And the same can be done for other insert classes.  --kasal, 16nov03.
+
+% Replace the \insert primitive by a cheating macro.
+% Deeper inside, just make sure that the saved insertions are not spilled
+% out prematurely.
+%
+\def\startsavinginserts{%
+  \ifx \insert\ptexinsert
+    \let\insert\saveinsert
+  \else
+    \let\checkinserts\relax
+  \fi
 }
 
-% For a final copy, take out the rectangles
-% that mark overfull boxes (in case you have decided
-% that the text looks ok even though it passes the margin).
+% This \insert replacement works for both \insert\footins{foo} and
+% \insert\footins\bgroup foo\egroup, but it doesn't work for \insert27{foo}.
 %
-\def\finalout{\overfullrule=0pt}
+\def\saveinsert#1{%
+  \edef\next{\noexpand\savetobox \makeSAVEname#1}%
+  \afterassignment\next
+  % swallow the left brace
+  \let\temp =
+}
+\def\makeSAVEname#1{\makecsname{SAVE\expandafter\gobble\string#1}}
+\def\savetobox#1{\global\setbox#1 = \vbox\bgroup \unvbox#1}
+
+\def\checksaveins#1{\ifvoid#1\else \placesaveins#1\fi}
+
+\def\placesaveins#1{%
+  \ptexinsert \csname\expandafter\gobblesave\string#1\endcsname
+    {\box#1}%
+}
+
+% eat @SAVE -- beware, all of them have catcode \other:
+{
+  \def\dospecials{\do S\do A\do V\do E} \uncatcodespecials  %  ;-)
+  \gdef\gobblesave @SAVE{}
+}
+
+% initialization:
+\def\newsaveins #1{%
+  \edef\next{\noexpand\newsaveinsX \makeSAVEname#1}%
+  \next
+}
+\def\newsaveinsX #1{%
+  \csname newbox\endcsname #1%
+  \expandafter\def\expandafter\checkinserts\expandafter{\checkinserts
+    \checksaveins #1}%
+}
+
+% initialize:
+\let\checkinserts\empty
+\newsaveins\footins
+\newsaveins\margin
+
 
 % @image.  We use the macros from epsf.tex to support this.
 % If epsf.tex is not installed and @image is used, we complain.
@@ -6311,12 +6304,12 @@
 % undone and the next image would fail.
 \openin 1 = epsf.tex
 \ifeof 1 \else
-  \closein 1
   % Do not bother showing banner with epsf.tex v2.7k (available in
   % doc/epsf.tex and on ctan).
   \def\epsfannounce{\toks0 = }%
   \input epsf.tex
 \fi
+\closein 1
 %
 % We will only complain once about lack of epsf.tex.
 \newif\ifwarnednoepsf
@@ -6372,6 +6365,269 @@
 \endgroup}
 
 
+% @float FLOATTYPE,LABEL,LOC ... @end float for displayed figures, tables,
+% etc.  We don't actually implement floating yet, we always include the
+% float "here".  But it seemed the best name for the future.
+%
+\envparseargdef\float{\eatcommaspace\eatcommaspace\dofloat#1, , ,\finish}
+
+% There may be a space before second and/or third parameter; delete it.
+\def\eatcommaspace#1, {#1,}
+
+% #1 is the optional FLOATTYPE, the text label for this float, typically
+% "Figure", "Table", "Example", etc.  Can't contain commas.  If omitted,
+% this float will not be numbered and cannot be referred to.
+%
+% #2 is the optional xref label.  Also must be present for the float to
+% be referable.
+%
+% #3 is the optional positioning argument; for now, it is ignored.  It
+% will somehow specify the positions allowed to float to (here, top, bottom).
+%
+% We keep a separate counter for each FLOATTYPE, which we reset at each
+% chapter-level command.
+\let\resetallfloatnos=\empty
+%
+\def\dofloat#1,#2,#3,#4\finish{%
+  \let\thiscaption=\empty
+  \let\thisshortcaption=\empty
+  %
+  % don't lose footnotes inside @float.
+  %
+  % BEWARE: when the floats start float, we have to issue warning whenever an
+  % insert appears inside a float which could possibly float. --kasal, 26may04
+  %
+  \startsavinginserts
+  %
+  % We can't be used inside a paragraph.
+  \par
+  %
+  \vtop\bgroup
+    \def\floattype{#1}%
+    \def\floatlabel{#2}%
+    \def\floatloc{#3}% we do nothing with this yet.
+    %
+    \ifx\floattype\empty
+      \let\safefloattype=\empty
+    \else
+      {%
+        % the floattype might have accents or other special characters,
+        % but we need to use it in a control sequence name.
+        \indexnofonts
+        \turnoffactive
+        \xdef\safefloattype{\floattype}%
+      }%
+    \fi
+    %
+    % If label is given but no type, we handle that as the empty type.
+    \ifx\floatlabel\empty \else
+      % We want each FLOATTYPE to be numbered separately (Figure 1,
+      % Table 1, Figure 2, ...).  (And if no label, no number.)
+      %
+      \expandafter\getfloatno\csname\safefloattype floatno\endcsname
+      \global\advance\floatno by 1
+      %
+      {%
+        % This magic value for \thissection is output by \setref as the
+        % XREFLABEL-title value.  \xrefX uses it to distinguish float
+        % labels (which have a completely different output format) from
+        % node and anchor labels.  And \xrdef uses it to construct the
+        % lists of floats.
+        %
+        \edef\thissection{\floatmagic=\safefloattype}%
+        \setref{\floatlabel}{Yfloat}%
+      }%
+    \fi
+    %
+    % start with \parskip glue, I guess.
+    \vskip\parskip
+    %
+    % Don't suppress indentation if a float happens to start a section.
+    \restorefirstparagraphindent
+}
+
+% we have these possibilities:
+% @float Foo,lbl & @caption{Cap}: Foo 1.1: Cap
+% @float Foo,lbl & no caption:    Foo 1.1
+% @float Foo & @caption{Cap}:     Foo: Cap
+% @float Foo & no caption:        Foo
+% @float ,lbl & Caption{Cap}:     1.1: Cap
+% @float ,lbl & no caption:       1.1
+% @float & @caption{Cap}:         Cap
+% @float & no caption:
+%
+\def\Efloat{%
+    \let\floatident = \empty
+    %
+    % In all cases, if we have a float type, it comes first.
+    \ifx\floattype\empty \else \def\floatident{\floattype}\fi
+    %
+    % If we have an xref label, the number comes next.
+    \ifx\floatlabel\empty \else
+      \ifx\floattype\empty \else % if also had float type, need tie first.
+        \appendtomacro\floatident{\tie}%
+      \fi
+      % the number.
+      \appendtomacro\floatident{\chaplevelprefix\the\floatno}%
+    \fi
+    %
+    % Start the printed caption with what we've constructed in
+    % \floatident, but keep it separate; we need \floatident again.
+    \let\captionline = \floatident
+    %
+    \ifx\thiscaption\empty \else
+      \ifx\floatident\empty \else
+	\appendtomacro\captionline{: }% had ident, so need a colon between
+      \fi
+      %
+      % caption text.
+      \appendtomacro\captionline{\scanexp\thiscaption}%
+    \fi
+    %
+    % If we have anything to print, print it, with space before.
+    % Eventually this needs to become an \insert.
+    \ifx\captionline\empty \else
+      \vskip.5\parskip
+      \captionline
+      %
+      % Space below caption.
+      \vskip\parskip
+    \fi
+    %
+    % If have an xref label, write the list of floats info.  Do this
+    % after the caption, to avoid chance of it being a breakpoint.
+    \ifx\floatlabel\empty \else
+      % Write the text that goes in the lof to the aux file as
+      % \floatlabel-lof.  Besides \floatident, we include the short
+      % caption if specified, else the full caption if specified, else nothing.
+      {%
+        \atdummies \turnoffactive \otherbackslash
+        % since we read the caption text in the macro world, where ^^M
+        % is turned into a normal character, we have to scan it back, so
+        % we don't write the literal three characters "^^M" into the aux file.
+	\scanexp{%
+	  \xdef\noexpand\gtemp{%
+	    \ifx\thisshortcaption\empty
+	      \thiscaption
+	    \else
+	      \thisshortcaption
+	    \fi
+	  }%
+	}%
+        \immediate\write\auxfile{@xrdef{\floatlabel-lof}{\floatident
+	  \ifx\gtemp\empty \else : \gtemp \fi}}%
+      }%
+    \fi
+  \egroup  % end of \vtop
+  %
+  % place the captured inserts
+  %
+  % BEWARE: when the floats start float, we have to issue warning whenever an
+  % insert appears inside a float which could possibly float. --kasal, 26may04
+  %
+  \checkinserts
+}
+
+% Append the tokens #2 to the definition of macro #1, not expanding either.
+%
+\def\appendtomacro#1#2{%
+  \expandafter\def\expandafter#1\expandafter{#1#2}%
+}
+
+% @caption, @shortcaption
+%
+\def\caption{\docaption\thiscaption}
+\def\shortcaption{\docaption\thisshortcaption}
+\def\docaption{\checkenv\float \bgroup\scanargctxt\defcaption}
+\def\defcaption#1#2{\egroup \def#1{#2}}
+
+% The parameter is the control sequence identifying the counter we are
+% going to use.  Create it if it doesn't exist and assign it to \floatno.
+\def\getfloatno#1{%
+  \ifx#1\relax
+      % Haven't seen this figure type before.
+      \csname newcount\endcsname #1%
+      %
+      % Remember to reset this floatno at the next chap.
+      \expandafter\gdef\expandafter\resetallfloatnos
+        \expandafter{\resetallfloatnos #1=0 }%
+  \fi
+  \let\floatno#1%
+}
+
+% \setref calls this to get the XREFLABEL-snt value.  We want an @xref
+% to the FLOATLABEL to expand to "Figure 3.1".  We call \setref when we
+% first read the @float command.
+%
+\def\Yfloat{\floattype at tie \chaplevelprefix\the\floatno}%
+
+% Magic string used for the XREFLABEL-title value, so \xrefX can
+% distinguish floats from other xref types.
+\def\floatmagic{!!float!!}
+
+% #1 is the control sequence we are passed; we expand into a conditional
+% which is true if #1 represents a float ref.  That is, the magic
+% \thissection value which we \setref above.
+%
+\def\iffloat#1{\expandafter\doiffloat#1==\finish}
+%
+% #1 is (maybe) the \floatmagic string.  If so, #2 will be the
+% (safe) float type for this float.  We set \iffloattype to #2.
+%
+\def\doiffloat#1=#2=#3\finish{%
+  \def\temp{#1}%
+  \def\iffloattype{#2}%
+  \ifx\temp\floatmagic
+}
+
+% @listoffloats FLOATTYPE - print a list of floats like a table of contents.
+%
+\parseargdef\listoffloats{%
+  \def\floattype{#1}% floattype
+  {%
+    % the floattype might have accents or other special characters,
+    % but we need to use it in a control sequence name.
+    \indexnofonts
+    \turnoffactive
+    \xdef\safefloattype{\floattype}%
+  }%
+  %
+  % \xrdef saves the floats as a \do-list in \floatlistSAFEFLOATTYPE.
+  \expandafter\ifx\csname floatlist\safefloattype\endcsname \relax
+    \ifhavexrefs
+      % if the user said @listoffloats foo but never @float foo.
+      \message{\linenumber No `\safefloattype' floats to list.}%
+    \fi
+  \else
+    \begingroup
+      \leftskip=\tocindent  % indent these entries like a toc
+      \let\do=\listoffloatsdo
+      \csname floatlist\safefloattype\endcsname
+    \endgroup
+  \fi
+}
+
+% This is called on each entry in a list of floats.  We're passed the
+% xref label, in the form LABEL-title, which is how we save it in the
+% aux file.  We strip off the -title and look up \XRLABEL-lof, which
+% has the text we're supposed to typeset here.
+%
+% Figures without xref labels will not be included in the list (since
+% they won't appear in the aux file).
+%
+\def\listoffloatsdo#1{\listoffloatsdoentry#1\finish}
+\def\listoffloatsdoentry#1-title\finish{{%
+  % Can't fully expand XR#1-lof because it can contain anything.  Just
+  % pass the control sequence.  On the other hand, XR#1-pg is just the
+  % page number, and we want to fully expand that so we can get a link
+  % in pdf output.
+  \toksA = \expandafter{\csname XR#1-lof\endcsname}%
+  %
+  % use the same \entry macro we use to generate the TOC and index.
+  \edef\writeentry{\noexpand\entry{\the\toksA}{\csname XR#1-pg\endcsname}}%
+  \writeentry
+}}
+
 \message{localization,}
 % and i18n.
 
@@ -6380,19 +6636,17 @@
 % properly.  Single argument is the language abbreviation.
 % It would be nice if we could set up a hyphenation file here.
 %
-\def\documentlanguage{\parsearg\dodocumentlanguage}
-\def\dodocumentlanguage#1{%
+\parseargdef\documentlanguage{%
   \tex % read txi-??.tex file in plain TeX.
-  % Read the file if it exists.
-  \openin 1 txi-#1.tex
-  \ifeof1
-    \errhelp = \nolanghelp
-    \errmessage{Cannot read language file txi-#1.tex}%
-    \let\temp = \relax
-  \else
-    \def\temp{\input txi-#1.tex }%
-  \fi
-  \temp
+    % Read the file if it exists.
+    \openin 1 txi-#1.tex
+    \ifeof 1
+      \errhelp = \nolanghelp
+      \errmessage{Cannot read language file txi-#1.tex}%
+    \else
+      \input txi-#1.tex
+    \fi
+    \closein 1
   \endgroup
 }
 \newhelp\nolanghelp{The given language definition file cannot be found or
@@ -6575,8 +6829,7 @@
 % Perhaps we should allow setting the margins, \topskip, \parskip,
 % and/or leading, also. Or perhaps we should compute them somehow.
 %
-\def\pagesizes{\parsearg\pagesizesxxx}
-\def\pagesizesxxx#1{\pagesizesyyy #1,,\finish}
+\parseargdef\pagesizes{\pagesizesyyy #1,,\finish}
 \def\pagesizesyyy#1,#2,#3\finish{{%
   \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
   \globaldefs = 1
@@ -6623,8 +6876,8 @@
 \def\normalplus{+}
 \def\normaldollar{$}%$ font-lock fix
 
-% This macro is used to make a character print one way in ttfont
-% where it can probably just be output, and another way in other fonts,
+% This macro is used to make a character print one way in \tt
+% (where it can probably be output as-is), and another way in other fonts,
 % where something hairier probably needs to be done.
 %
 % #1 is what to print if we are indeed using \tt; #2 is what to print
@@ -6672,13 +6925,6 @@
 \catcode`\$=\active
 \def${\ifusingit{{\sl\$}}\normaldollar}%$ font-lock fix
 
-% Set up an active definition for =, but don't enable it most of the time.
-{\catcode`\==\active
-\global\def={{\tt \char 61}}}
-
-\catcode`+=\active
-\catcode`\_=\active
-
 % If a .fmt file is being used, characters that might appear in a file
 % name cannot be active until we have parsed the command line.
 % So turn them off again, and have \everyjob (or @setfilename) turn them on.
@@ -6687,15 +6933,16 @@
 
 \catcode`\@=0
 
-% \rawbackslashxx outputs one backslash character in current font,
+% \backslashcurfont outputs one backslash character in current font,
 % as in \char`\\.
-\global\chardef\rawbackslashxx=`\\
+\global\chardef\backslashcurfont=`\\
+\global\let\rawbackslashxx=\backslashcurfont  % let existing .??s files work
 
-% \rawbackslash defines an active \ to do \rawbackslashxx.
+% \rawbackslash defines an active \ to do \backslashcurfont.
 % \otherbackslash defines an active \ to be a literal `\' character with
 % catcode other.
 {\catcode`\\=\active
- @gdef at rawbackslash{@let\=@rawbackslashxx}
+ @gdef at rawbackslash{@let\=@backslashcurfont}
  @gdef at otherbackslash{@let\=@realbackslash}
 }
 
@@ -6703,7 +6950,7 @@
 {\catcode`\\=\other @gdef at realbackslash{\}}
 
 % \normalbackslash outputs one backslash in fixed width font.
-\def\normalbackslash{{\tt\rawbackslashxx}}
+\def\normalbackslash{{\tt\backslashcurfont}}
 
 \catcode`\\=\active
 
@@ -6720,6 +6967,7 @@
   @let>=@normalgreater
   @let+=@normalplus
   @let$=@normaldollar %$ font-lock fix
+  @unsepspaces
 }
 
 % Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of
@@ -6759,10 +7007,6 @@
 @catcode`@# = @other
 @catcode`@% = @other
 
- at c Set initial fonts.
- at textfonts
- at rm
-
 
 @c Local variables:
 @c eval: (add-hook 'write-file-hooks 'time-stamp)
@@ -6771,3 +7015,9 @@
 @c time-stamp-format: "%:y-%02m-%02d.%02H"
 @c time-stamp-end: "}"
 @c End:
+
+ at c vim:sw=2:
+
+ at ignore
+   arch-tag: e1b36e32-c96e-4135-a41a-0b2efa2ea115
+ at end ignore
Index: libgcrypt/install-sh
diff -u libgcrypt/install-sh:1.1 libgcrypt/install-sh:1.1.2.1
--- libgcrypt/install-sh:1.1	Mon Dec  8 22:42:35 2003
+++ libgcrypt/install-sh	Tue Jan  4 21:50:23 2005
@@ -1,7 +1,8 @@
 #!/bin/sh
-#
 # install - install a program, script, or datafile
-#
+
+scriptversion=2004-10-22.00
+
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # later released in X11R6 (xc/config/util/install.sh) with the
 # following copyright and license.
@@ -41,13 +42,11 @@
 # from scratch.  It can only install one file at a time, a restriction
 # shared with many OS's install programs.
 
-
 # set DOITPROG to echo to test this script
 
 # Don't use :- since 4.3BSD and earlier shells don't like it.
 doit="${DOITPROG-}"
 
-
 # put in absolute paths if you don't have them in your path; or use env. vars.
 
 mvprog="${MVPROG-mv}"
@@ -59,236 +58,266 @@
 rmprog="${RMPROG-rm}"
 mkdirprog="${MKDIRPROG-mkdir}"
 
-transformbasename=""
-transform_arg=""
-instcmd="$mvprog"
 chmodcmd="$chmodprog 0755"
-chowncmd=""
-chgrpcmd=""
-stripcmd=""
+chowncmd=
+chgrpcmd=
+stripcmd=
 rmcmd="$rmprog -f"
 mvcmd="$mvprog"
-src=""
-dst=""
-dir_arg=""
-
-while [ x"$1" != x ]; do
-    case $1 in
-	-c) instcmd=$cpprog
-	    shift
-	    continue;;
-
-	-d) dir_arg=true
-	    shift
-	    continue;;
-
-	-m) chmodcmd="$chmodprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-o) chowncmd="$chownprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-g) chgrpcmd="$chgrpprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-s) stripcmd=$stripprog
-	    shift
-	    continue;;
-
-	-t=*) transformarg=`echo $1 | sed 's/-t=//'`
-	    shift
-	    continue;;
-
-	-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
-	    shift
-	    continue;;
-
-	*)  if [ x"$src" = x ]
-	    then
-		src=$1
-	    else
-		# this colon is to work around a 386BSD /bin/sh bug
-		:
-		dst=$1
-	    fi
-	    shift
-	    continue;;
-    esac
-done
-
-if [ x"$src" = x ]
-then
-	echo "$0: no input file specified" >&2
-	exit 1
-else
-	:
-fi
+src=
+dst=
+dir_arg=
+dstarg=
+no_target_directory=
+
+usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
+
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
+
+Options:
+-c         (ignored)
+-d         create directories instead of installing files.
+-g GROUP   $chgrpprog installed files to GROUP.
+-m MODE    $chmodprog installed files to MODE.
+-o USER    $chownprog installed files to USER.
+-s         $stripprog installed files.
+-t DIRECTORY  install into DIRECTORY.
+-T         report an error if DSTFILE is a directory.
+--help     display this help and exit.
+--version  display version info and exit.
+
+Environment variables override the default commands:
+  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
+"
+
+while test -n "$1"; do
+  case $1 in
+    -c) shift
+        continue;;
+
+    -d) dir_arg=true
+        shift
+        continue;;
+
+    -g) chgrpcmd="$chgrpprog $2"
+        shift
+        shift
+        continue;;
+
+    --help) echo "$usage"; exit 0;;
+
+    -m) chmodcmd="$chmodprog $2"
+        shift
+        shift
+        continue;;
+
+    -o) chowncmd="$chownprog $2"
+        shift
+        shift
+        continue;;
+
+    -s) stripcmd=$stripprog
+        shift
+        continue;;
 
-if [ x"$dir_arg" != x ]; then
-	dst=$src
-	src=""
-
-	if [ -d "$dst" ]; then
-		instcmd=:
-		chmodcmd=""
-	else
-		instcmd=$mkdirprog
-	fi
-else
-
-# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-# might cause directories to be created, which would be especially bad
-# if $src (and thus $dsttmp) contains '*'.
-
-	if [ -f "$src" ] || [ -d "$src" ]
-	then
-		:
-	else
-		echo "$0: $src does not exist" >&2
-		exit 1
-	fi
-
-	if [ x"$dst" = x ]
-	then
-		echo "$0: no destination specified" >&2
-		exit 1
-	else
-		:
-	fi
-
-# If destination is a directory, append the input filename; if your system
-# does not like double slashes in filenames, you may need to add some logic
-
-	if [ -d "$dst" ]
-	then
-		dst=$dst/`basename "$src"`
-	else
-		:
-	fi
-fi
-
-## this sed command emulates the dirname command
-dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
-
-# Make sure that the destination directory exists.
-#  this part is taken from Noah Friedman's mkinstalldirs script
-
-# Skip lots of stat calls in the usual case.
-if [ ! -d "$dstdir" ]; then
-defaultIFS='
-	'
-IFS="${IFS-$defaultIFS}"
-
-oIFS=$IFS
-# Some sh's can't handle IFS=/ for some reason.
-IFS='%'
-set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
-IFS=$oIFS
-
-pathcomp=''
+    -t) dstarg=$2
+	shift
+	shift
+	continue;;
 
-while [ $# -ne 0 ] ; do
-	pathcomp=$pathcomp$1
+    -T) no_target_directory=true
 	shift
+	continue;;
 
-	if [ ! -d "$pathcomp" ] ;
-        then
-		$mkdirprog "$pathcomp"
-	else
-		:
-	fi
+    --version) echo "$0 $scriptversion"; exit 0;;
 
-	pathcomp=$pathcomp/
+    *)  # When -d is used, all remaining arguments are directories to create.
+	# When -t is used, the destination is already specified.
+	test -n "$dir_arg$dstarg" && break
+        # Otherwise, the last argument is the destination.  Remove it from $@.
+	for arg
+	do
+          if test -n "$dstarg"; then
+	    # $@ is not empty: it contains at least $arg.
+	    set fnord "$@" "$dstarg"
+	    shift # fnord
+	  fi
+	  shift # arg
+	  dstarg=$arg
+	done
+	break;;
+  esac
 done
-fi
-
-if [ x"$dir_arg" != x ]
-then
-	$doit $instcmd "$dst" &&
-
-	if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
-	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
-	if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
-	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
-else
-
-# If we're going to rename the final executable, determine the name now.
 
-	if [ x"$transformarg" = x ]
-	then
-		dstfile=`basename "$dst"`
-	else
-		dstfile=`basename "$dst" $transformbasename |
-			sed $transformarg`$transformbasename
-	fi
-
-# don't allow the sed command to completely eliminate the filename
-
-	if [ x"$dstfile" = x ]
-	then
-		dstfile=`basename "$dst"`
-	else
-		:
-	fi
-
-# Make a couple of temp file names in the proper directory.
-
-	dsttmp=$dstdir/_inst.$$_
-	rmtmp=$dstdir/_rm.$$_
-
-# Trap to clean up temp files at exit.
-
-	trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
-	trap '(exit $?); exit' 1 2 13 15
-
-# Move or copy the file name to the temp name
-
-	$doit $instcmd "$src" "$dsttmp" &&
-
-# and set any options; do chmod last to preserve setuid bits
-
-# If any of these fail, we abort the whole thing.  If we want to
-# ignore errors from any of these, just make sure not to ignore
-# errors from the above "$doit $instcmd $src $dsttmp" command.
-
-	if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
-	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
-	if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
-	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
-
-# Now remove or move aside any old file at destination location.  We try this
-# two ways since rm can't unlink itself on some systems and the destination
-# file might be busy for other reasons.  In this case, the final cleanup
-# might fail but the new file should still install successfully.
-
-{
-	if [ -f "$dstdir/$dstfile" ]
-	then
-		$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
-		$doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
-		{
-		  echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
-		  (exit 1); exit
-		}
-	else
-		:
-	fi
-} &&
-
-# Now rename the file to the real destination.
+if test -z "$1"; then
+  if test -z "$dir_arg"; then
+    echo "$0: no input file specified." >&2
+    exit 1
+  fi
+  # It's OK to call `install-sh -d' without argument.
+  # This can happen when creating conditional directories.
+  exit 0
+fi
 
-	$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
+for src
+do
+  # Protect names starting with `-'.
+  case $src in
+    -*) src=./$src ;;
+  esac
+
+  if test -n "$dir_arg"; then
+    dst=$src
+    src=
+
+    if test -d "$dst"; then
+      mkdircmd=:
+      chmodcmd=
+    else
+      mkdircmd=$mkdirprog
+    fi
+  else
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+    # might cause directories to be created, which would be especially bad
+    # if $src (and thus $dsttmp) contains '*'.
+    if test ! -f "$src" && test ! -d "$src"; then
+      echo "$0: $src does not exist." >&2
+      exit 1
+    fi
+
+    if test -z "$dstarg"; then
+      echo "$0: no destination specified." >&2
+      exit 1
+    fi
+
+    dst=$dstarg
+    # Protect names starting with `-'.
+    case $dst in
+      -*) dst=./$dst ;;
+    esac
 
-fi &&
+    # If destination is a directory, append the input filename; won't work
+    # if double slashes aren't ignored.
+    if test -d "$dst"; then
+      if test -n "$no_target_directory"; then
+	echo "$0: $dstarg: Is a directory" >&2
+	exit 1
+      fi
+      dst=$dst/`basename "$src"`
+    fi
+  fi
+
+  # This sed command emulates the dirname command.
+  dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
+
+  # Make sure that the destination directory exists.
+
+  # Skip lots of stat calls in the usual case.
+  if test ! -d "$dstdir"; then
+    defaultIFS='
+	 '
+    IFS="${IFS-$defaultIFS}"
+
+    oIFS=$IFS
+    # Some sh's can't handle IFS=/ for some reason.
+    IFS='%'
+    set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
+    shift
+    IFS=$oIFS
+
+    pathcomp=
+
+    while test $# -ne 0 ; do
+      pathcomp=$pathcomp$1
+      shift
+      if test ! -d "$pathcomp"; then
+        $mkdirprog "$pathcomp"
+	# mkdir can fail with a `File exist' error in case several
+	# install-sh are creating the directory concurrently.  This
+	# is OK.
+	test -d "$pathcomp" || exit
+      fi
+      pathcomp=$pathcomp/
+    done
+  fi
+
+  if test -n "$dir_arg"; then
+    $doit $mkdircmd "$dst" \
+      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
+      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
+      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
+      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
+
+  else
+    dstfile=`basename "$dst"`
+
+    # Make a couple of temp file names in the proper directory.
+    dsttmp=$dstdir/_inst.$$_
+    rmtmp=$dstdir/_rm.$$_
+
+    # Trap to clean up those temp files at exit.
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+    trap '(exit $?); exit' 1 2 13 15
+
+    # Copy the file name to the temp name.
+    $doit $cpprog "$src" "$dsttmp" &&
+
+    # and set any options; do chmod last to preserve setuid bits.
+    #
+    # If any of these fail, we abort the whole thing.  If we want to
+    # ignore errors from any of these, just make sure not to ignore
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
+    #
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
+      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
+      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
+      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
+
+    # Now rename the file to the real destination.
+    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
+      || {
+	   # The rename failed, perhaps because mv can't rename something else
+	   # to itself, or perhaps because mv is so ancient that it does not
+	   # support -f.
+
+	   # Now remove or move aside any old file at destination location.
+	   # We try this two ways since rm can't unlink itself on some
+	   # systems and the destination file might be busy for other
+	   # reasons.  In this case, the final cleanup might fail but the new
+	   # file should still install successfully.
+	   {
+	     if test -f "$dstdir/$dstfile"; then
+	       $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
+	       || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
+	       || {
+		 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
+		 (exit 1); exit
+	       }
+	     else
+	       :
+	     fi
+	   } &&
+
+	   # Now rename the file to the real destination.
+	   $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
+	 }
+    }
+  fi || { (exit 1); exit; }
+done
 
 # The final little trick to "correctly" pass the exit status to the exit trap.
-
 {
-	(exit 0); exit
+  (exit 0); exit
 }
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:
Index: libgcrypt/missing
diff -u libgcrypt/missing:1.1 libgcrypt/missing:1.1.2.1
--- libgcrypt/missing:1.1	Mon Dec  8 22:42:35 2003
+++ libgcrypt/missing	Tue Jan  4 21:50:23 2005
@@ -1,6 +1,10 @@
 #! /bin/sh
 # Common stub for a few missing GNU programs while installing.
-# Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
+
+scriptversion=2004-09-07.08
+
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004
+#   Free Software Foundation, Inc.
 # Originally by Fran,cois Pinard <pinard at iro.umontreal.ca>, 1996.
 
 # This program is free software; you can redistribute it and/or modify
@@ -38,18 +42,24 @@
   configure_ac=configure.in
 fi
 
+msg="missing on your system"
+
 case "$1" in
 --run)
   # Try to run requested program, and just exit if it succeeds.
   run=
   shift
   "$@" && exit 0
+  # Exit code 63 means version mismatch.  This often happens
+  # when the user try to use an ancient version of a tool on
+  # a file that requires a minimum version.  In this case we
+  # we should proceed has if the program had been absent, or
+  # if --run hadn't been passed.
+  if test $? = 63; then
+    run=:
+    msg="probably too old"
+  fi
   ;;
-esac
-
-# If it does not exist, or fails to run (possibly an outdated version),
-# try to emulate it.
-case "$1" in
 
   -h|--h|--he|--hel|--help)
     echo "\
@@ -74,11 +84,15 @@
   lex          create \`lex.yy.c', if possible, from existing .c
   makeinfo     touch the output file
   tar          try tar, gnutar, gtar, then tar without non-portable flags
-  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]"
+  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
+
+Send bug reports to <bug-automake at gnu.org>."
+    exit 0
     ;;
 
   -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
-    echo "missing 0.4 - GNU automake"
+    echo "missing $scriptversion (GNU Automake)"
+    exit 0
     ;;
 
   -*)
@@ -87,14 +101,44 @@
     exit 1
     ;;
 
-  aclocal*)
+esac
+
+# Now exit if we have it, but it failed.  Also exit now if we
+# don't have it and --version was passed (most likely to detect
+# the program).
+case "$1" in
+  lex|yacc)
+    # Not GNU programs, they don't have --version.
+    ;;
+
+  tar)
+    if test -n "$run"; then
+       echo 1>&2 "ERROR: \`tar' requires --run"
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       exit 1
+    fi
+    ;;
+
+  *)
     if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
        # We have it, but it failed.
        exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       # Could not run --version or --help.  This is probably someone
+       # running `$TOOL --version' or `$TOOL --help' to check whether
+       # $TOOL exists and not knowing $TOOL uses missing.
+       exit 1
     fi
+    ;;
+esac
 
+# If it does not exist, or fails to run (possibly an outdated version),
+# try to emulate it.
+case "$1" in
+  aclocal*)
     echo 1>&2 "\
-WARNING: \`$1' is missing on your system.  You should only need it if
+WARNING: \`$1' is $msg.  You should only need it if
          you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
          to install the \`Automake' and \`Perl' packages.  Grab them from
          any GNU archive site."
@@ -102,13 +146,8 @@
     ;;
 
   autoconf)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
-WARNING: \`$1' is missing on your system.  You should only need it if
+WARNING: \`$1' is $msg.  You should only need it if
          you modified \`${configure_ac}'.  You might want to install the
          \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
          archive site."
@@ -116,13 +155,8 @@
     ;;
 
   autoheader)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
-WARNING: \`$1' is missing on your system.  You should only need it if
+WARNING: \`$1' is $msg.  You should only need it if
          you modified \`acconfig.h' or \`${configure_ac}'.  You might want
          to install the \`Autoconf' and \`GNU m4' packages.  Grab them
          from any GNU archive site."
@@ -140,13 +174,8 @@
     ;;
 
   automake*)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
-WARNING: \`$1' is missing on your system.  You should only need it if
+WARNING: \`$1' is $msg.  You should only need it if
          you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
          You might want to install the \`Automake' and \`Perl' packages.
          Grab them from any GNU archive site."
@@ -156,16 +185,11 @@
     ;;
 
   autom4te)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
-WARNING: \`$1' is needed, and you do not seem to have it handy on your
-         system.  You might have modified some files without having the
+WARNING: \`$1' is needed, but is $msg.
+         You might have modified some files without having the
          proper tools for further handling them.
-         You can get \`$1Help2man' as part of \`Autoconf' from any GNU
+         You can get \`$1' as part of \`Autoconf' from any GNU
          archive site."
 
     file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
@@ -185,7 +209,7 @@
 
   bison|yacc)
     echo 1>&2 "\
-WARNING: \`$1' is missing on your system.  You should only need it if
+WARNING: \`$1' $msg.  You should only need it if
          you modified a \`.y' file.  You may need the \`Bison' package
          in order for those modifications to take effect.  You can get
          \`Bison' from any GNU archive site."
@@ -215,7 +239,7 @@
 
   lex|flex)
     echo 1>&2 "\
-WARNING: \`$1' is missing on your system.  You should only need it if
+WARNING: \`$1' is $msg.  You should only need it if
          you modified a \`.l' file.  You may need the \`Flex' package
          in order for those modifications to take effect.  You can get
          \`Flex' from any GNU archive site."
@@ -237,13 +261,8 @@
     ;;
 
   help2man)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
-WARNING: \`$1' is missing on your system.  You should only need it if
+WARNING: \`$1' is $msg.  You should only need it if
 	 you modified a dependency of a manual page.  You may need the
 	 \`Help2man' package in order for those modifications to take
 	 effect.  You can get \`Help2man' from any GNU archive site."
@@ -262,13 +281,8 @@
     ;;
 
   makeinfo)
-    if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then
-       # We have makeinfo, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
-WARNING: \`$1' is missing on your system.  You should only need it if
+WARNING: \`$1' is $msg.  You should only need it if
          you modified a \`.texi' or \`.texinfo' file, or any other file
          indirectly affecting the aspect of the manual.  The spurious
          call might also be the consequence of using a buggy \`make' (AIX,
@@ -284,10 +298,6 @@
 
   tar)
     shift
-    if test -n "$run"; then
-      echo 1>&2 "ERROR: \`tar' requires --run"
-      exit 1
-    fi
 
     # We have already tried tar in the generic part.
     # Look for gnutar/gtar before invocation to avoid ugly error
@@ -323,10 +333,10 @@
 
   *)
     echo 1>&2 "\
-WARNING: \`$1' is needed, and you do not seem to have it handy on your
-         system.  You might have modified some files without having the
+WARNING: \`$1' is needed, and is $msg.
+         You might have modified some files without having the
          proper tools for further handling them.  Check the \`README' file,
-         it often tells you about the needed prerequirements for installing
+         it often tells you about the needed prerequisites for installing
          this package.  You may also peek at any GNU archive site, in case
          some other package would contain this missing \`$1' program."
     exit 1
@@ -334,3 +344,10 @@
 esac
 
 exit 0
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
+# End:
Index: libgcrypt/mkinstalldirs
diff -u libgcrypt/mkinstalldirs:1.1 libgcrypt/mkinstalldirs:1.1.2.1
--- libgcrypt/mkinstalldirs:1.1	Mon Dec  8 22:42:35 2003
+++ libgcrypt/mkinstalldirs	Tue Jan  4 21:50:23 2005
@@ -1,20 +1,32 @@
 #! /bin/sh
 # mkinstalldirs --- make directory hierarchy
-# Author: Noah Friedman <friedman at prep.ai.mit.edu>
+
+scriptversion=2004-02-15.20
+
+# Original author: Noah Friedman <friedman at prep.ai.mit.edu>
 # Created: 1993-05-16
-# Public domain
+# Public domain.
+#
+# This file is maintained in Automake, please report
+# bugs to <bug-automake at gnu.org> or send patches to
+# <automake-patches at gnu.org>.
 
 errstatus=0
 dirmode=""
 
 usage="\
-Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
+Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
+
+Create each directory DIR (with mode MODE, if specified), including all
+leading file name components.
+
+Report bugs to <bug-automake at gnu.org>."
 
 # process command line arguments
 while test $# -gt 0 ; do
   case $1 in
     -h | --help | --h*)         # -h for help
-      echo "$usage" 1>&2
+      echo "$usage"
       exit 0
       ;;
     -m)                         # -m PERM arg
@@ -23,6 +35,10 @@
       dirmode=$1
       shift
       ;;
+    --version)
+      echo "$0 $scriptversion"
+      exit 0
+      ;;
     --)                         # stop option processing
       shift
       break
@@ -50,17 +66,37 @@
   0) exit 0 ;;
 esac
 
+# Solaris 8's mkdir -p isn't thread-safe.  If you mkdir -p a/b and
+# mkdir -p a/c at the same time, both will detect that a is missing,
+# one will create a, then the other will try to create a and die with
+# a "File exists" error.  This is a problem when calling mkinstalldirs
+# from a parallel make.  We use --version in the probe to restrict
+# ourselves to GNU mkdir, which is thread-safe.
 case $dirmode in
   '')
-    if mkdir -p -- . 2>/dev/null; then
+    if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
       echo "mkdir -p -- $*"
       exec mkdir -p -- "$@"
+    else
+      # On NextStep and OpenStep, the `mkdir' command does not
+      # recognize any option.  It will interpret all options as
+      # directories to create, and then abort because `.' already
+      # exists.
+      test -d ./-p && rmdir ./-p
+      test -d ./--version && rmdir ./--version
     fi
     ;;
   *)
-    if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
+    if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
+       test ! -d ./--version; then
       echo "mkdir -m $dirmode -p -- $*"
       exec mkdir -m "$dirmode" -p -- "$@"
+    else
+      # Clean up after NextStep and OpenStep mkdir.
+      for d in ./-m ./-p ./--version "./$dirmode";
+      do
+        test -d $d && rmdir $d
+      done
     fi
     ;;
 esac
@@ -84,17 +120,17 @@
       mkdir "$pathcomp" || lasterr=$?
 
       if test ! -d "$pathcomp"; then
-  	errstatus=$lasterr
+	errstatus=$lasterr
       else
-  	if test ! -z "$dirmode"; then
+	if test ! -z "$dirmode"; then
 	  echo "chmod $dirmode $pathcomp"
-    	  lasterr=""
-  	  chmod "$dirmode" "$pathcomp" || lasterr=$?
+	  lasterr=""
+	  chmod "$dirmode" "$pathcomp" || lasterr=$?
 
-  	  if test ! -z "$lasterr"; then
-  	    errstatus=$lasterr
-  	  fi
-  	fi
+	  if test ! -z "$lasterr"; then
+	    errstatus=$lasterr
+	  fi
+	fi
       fi
     fi
 
@@ -107,5 +143,8 @@
 # Local Variables:
 # mode: shell-script
 # sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-end: "$"
 # End:
-# mkinstalldirs ends here
Index: libgcrypt/src/ChangeLog
diff -u libgcrypt/src/ChangeLog:1.151.2.9 libgcrypt/src/ChangeLog:1.151.2.10
--- libgcrypt/src/ChangeLog:1.151.2.9	Mon Dec  6 18:36:34 2004
+++ libgcrypt/src/ChangeLog	Tue Jan  4 21:50:23 2005
@@ -1,3 +1,7 @@
+2004-12-20  Werner Koch  <wk at g10code.com>
+
+	* gcrypt.h (GCRY_THREAD_OPTION_PTH_IMPL): Tweaks for W32.
+
 2004-12-06  Werner Koch  <wk at g10code.com>
 
 	* g10lib.h (stpcpy, strcasecmp): Prefix them with _gcry_ and add
Index: libgcrypt/src/gcrypt.h
diff -u libgcrypt/src/gcrypt.h:1.125.2.3 libgcrypt/src/gcrypt.h:1.125.2.4
--- libgcrypt/src/gcrypt.h:1.125.2.3	Fri Nov 26 17:27:08 2004
+++ libgcrypt/src/gcrypt.h	Tue Jan  4 21:50:22 2005
@@ -162,6 +162,19 @@
     GCRY_THREAD_OPTION_PTHREAD = 3
   };
 
+/* Do avoid inclusing of too much W32 stuff, we redefine some types.  */
+#ifdef _WIN32
+#define _GCRY_PTH_FD_SET    void
+#define _GCRY_PTH_SOCKADDR  void
+#define _GCRY_PTH_SOCKLEN_T int
+#define _GCRY_PTH_MSGHDR    void
+#else
+#define _GCRY_PTH_FD_SET    fd_set
+#define _GCRY_PTH_SOCKADDR  struct sockaddr
+#define _GCRY_PTH_SOCKLEN_T socklen_t
+#define _GCRY_PTH_MSGHDR    struct msghdr
+#endif
+
 /* Wrapper for struct ath_ops.  */
 struct gcry_thread_cbs
 {
@@ -173,23 +186,15 @@
   int (*mutex_unlock) (void **priv);
   ssize_t (*read) (int fd, void *buf, size_t nbytes);
   ssize_t (*write) (int fd, const void *buf, size_t nbytes);
-#ifdef _WIN32
-  ssize_t (*select) (int nfd, void *rset, void *wset, void *eset,
-		     struct timeval *timeout);
-  ssize_t (*waitpid) (pid_t pid, int *status, int options);
-  int (*accept) (int s, void  *addr, int *length_ptr);
-  int (*connect) (int s, void *addr, int length);
-  int (*sendmsg) (int s, const void *msg, int flags);
-  int (*recvmsg) (int s, void *msg, int flags);
-#else
-  ssize_t (*select) (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
-		     struct timeval *timeout);
+  ssize_t (*select) (int nfd, _GCRY_PTH_FD_SET *rset, _GCRY_PTH_FD_SET *wset,
+                     _GCRY_PTH_FD_SET *eset, struct timeval *timeout);
   ssize_t (*waitpid) (pid_t pid, int *status, int options);
-  int (*accept) (int s, struct sockaddr *addr, socklen_t *length_ptr);
-  int (*connect) (int s, struct sockaddr *addr, socklen_t length);
-  int (*sendmsg) (int s, const struct msghdr *msg, int flags);
-  int (*recvmsg) (int s, struct msghdr *msg, int flags);
-#endif
+  int (*accept) (int s, _GCRY_PTH_SOCKADDR *addr,
+                 _GCRY_PTH_SOCKLEN_T *length_ptr);
+  int (*connect) (int s, _GCRY_PTH_SOCKADDR *addr,
+                  _GCRY_PTH_SOCKLEN_T length);
+  int (*sendmsg) (int s, const _GCRY_PTH_MSGHDR *msg, int flags);
+  int (*recvmsg) (int s, _GCRY_PTH_MSGHDR *msg, int flags);
 };
 
 #define GCRY_THREAD_OPTION_PTH_IMPL					      \
@@ -228,15 +233,18 @@
   { return pth_read (fd, buf, nbytes); }				      \
 static ssize_t gcry_pth_write (int fd, const void *buf, size_t nbytes)	      \
   { return pth_write (fd, buf, nbytes); }				      \
-static ssize_t gcry_pth_select (int nfd, fd_set *rset, fd_set *wset,	      \
-				fd_set *eset, struct timeval *timeout)	      \
+static ssize_t gcry_pth_select (int nfd, _GCRY_PTH_FD_SET *rset,              \
+                                _GCRY_PTH_FD_SET *wset,	                      \
+				_GCRY_PTH_FD_SET *eset,                       \
+                                struct timeval *timeout)	              \
   { return pth_select (nfd, rset, wset, eset, timeout); }		      \
 static ssize_t gcry_pth_waitpid (pid_t pid, int *status, int options)	      \
   { return pth_waitpid (pid, status, options); }			      \
-static int gcry_pth_accept (int s, struct sockaddr *addr,		      \
-			    socklen_t *length_ptr)			      \
+static int gcry_pth_accept (int s, _GCRY_PTH_SOCKADDR *addr,		      \
+			    _GCRY_PTH_SOCKLEN_T *length_ptr)		      \
   { return pth_accept (s, addr, length_ptr); }				      \
-static int gcry_pth_connect (int s, struct sockaddr *addr, socklen_t length)  \
+static int gcry_pth_connect (int s, _GCRY_PTH_SOCKADDR *addr,                 \
+                             _GCRY_PTH_SOCKLEN_T length)                      \
   { return pth_connect (s, addr, length); }				      \
 									      \
 /* FIXME: GNU Pth is missing pth_sendmsg and pth_recvmsg.  */		      \




More information about the Gnupg-commits mailing list