Browse Source

Import upstream version 4.19

Christos Zoulas 17 years ago
parent
commit
c4242d6fa4
59 changed files with 2784 additions and 4999 deletions
  1. 86 0
      ChangeLog
  2. 2 2
      LEGAL.NOTICE
  3. 31 9
      MAINT
  4. 1 2
      Makefile.in
  5. 3 2
      README
  6. 225 116
      config.guess
  7. 3 0
      config.h.in
  8. 152 57
      config.sub
  9. 5 899
      configure
  10. 4 10
      configure.in
  11. 149 42
      depcomp
  12. 10 5
      doc/file.man
  13. 3 3
      doc/libmagic.man
  14. 29 4
      doc/magic.man
  15. 284 212
      install-sh
  16. 0 2797
      ltconfig
  17. 32 0
      ltmain.sh
  18. 23 0
      magic/Magdir/archive
  19. 73 7
      magic/Magdir/audio
  20. 15 0
      magic/Magdir/cad
  21. 21 0
      magic/Magdir/cafebabe
  22. 2 0
      magic/Magdir/commands
  23. 3 0
      magic/Magdir/editors
  24. 16 11
      magic/Magdir/elf
  25. 117 10
      magic/Magdir/filesystems
  26. 5 3
      magic/Magdir/images
  27. 3 6
      magic/Magdir/java
  28. 7 0
      magic/Magdir/linux
  29. 6 23
      magic/Magdir/mach
  30. 3 0
      magic/Magdir/misctools
  31. 15 3
      magic/Magdir/msdos
  32. 32 0
      magic/Magdir/os400
  33. 1 0
      magic/Magdir/python
  34. 7 0
      magic/Magdir/riff
  35. 8 0
      magic/Magdir/sun
  36. 125 2
      magic/Magdir/sysex
  37. 15 0
      magic/Magdir/unicode
  38. 0 7
      magic/Magdir/vmware
  39. 20 1
      magic/Magdir/wordprocessors
  40. 1 1
      magic/Magdir/xwindows
  41. 3 0
      magic/Makefile.am
  42. 3 0
      magic/Makefile.in
  43. 45 33
      magic/magic.mime
  44. 2 1
      magic/magic2mime
  45. 85 61
      missing
  46. 119 60
      mkinstalldirs
  47. 302 170
      src/apprentice.c
  48. 3 3
      src/ascmagic.c
  49. 49 10
      src/compress.c
  50. 26 10
      src/file.c
  51. 54 16
      src/file.h
  52. 16 12
      src/funcs.c
  53. 10 2
      src/is_tar.c
  54. 75 28
      src/magic.c
  55. 8 2
      src/patchlevel.h
  56. 26 8
      src/print.c
  57. 112 43
      src/readelf.c
  58. 306 304
      src/softmagic.c
  59. 3 2
      src/tar.h

+ 86 - 0
ChangeLog

@@ -1,3 +1,89 @@
+2006-12-11 16:49 Christos Zoulas <christos@zoulas.com>
+
+	* fix byteswapping issue
+
+	* report the number of bytes we tried to
+	  allocate when allocation fails
+
+	* add a few missed cases in the strength routine
+
+2006-12-08 16:32 Christos Zoulas <christos@zoulas.com>
+
+	* store and print the line number of the magic
+	  entry for debugging.         
+
+	* if the magic entry did not print anything,
+	  don't treat it as a match
+
+	* change the magic strength algorithm to take
+	  into account the relationship op.
+
+	* fix a bug in search where we could accidentally
+	  return a match.
+
+	* propagate the error return from match to
+	  file_softmagic.
+
+2006-11-25 13:35 Christos Zoulas <christos@zoulas.com>
+	
+	* Don't store the current offset in the magic
+	  struct, because it needs to be restored and
+	  it was not done properly all the time. Bug
+	  found by: Arkadiusz Miskiewicz
+
+	* Fix problem in the '\0' separator; and don't
+	  print it as an additional separator; print
+	  it as the only separator.
+
+2006-11-17 10:51 Christos Zoulas <christos@zoulas.com>
+
+	* Added a -0 option to print a '\0' separator
+	  Etienne Buira <etienne.buira@free.fr>
+
+2006-10-31 15:14 Christos Zoulas <christos@zoulas.com>
+
+	* Check offset before copying (Mike Frysinger)
+
+	* merge duplicated code
+
+	* add quad date support
+
+	* make sure that we nul terminate desc (Ryoji Kanai)
+
+	* don't process elf notes multiple times
+
+	* allow -z to report empty compressed files
+
+	* use calloc to initialize the ascii buffers (Jos van den Oever)
+
+2006-06-08 11:11 Christos Zoulas <christos@zoulas.com>
+
+	* QNX fixes (Mike Gorchak)
+
+	* Add quad support.
+
+	* FIFO checks (Dr. Werner Fink)
+
+	* Linux ELF fixes (Dr. Werner Fink)
+
+	* Magic format checks (Dr. Werner Fink)
+
+	* Magic format function improvent (Karl Chen)
+
+2006-05-03 11:11 Christos Zoulas <christos@zoulas.com>
+
+	* Pick up some elf changes and some constant fixes from SUSE
+
+	* Identify gnu tar vs. posix tar
+
+	* When keep going, don't print spurious newlines (Radek Vokál)
+
+2006-04-01 12:02 Christos Zoulas <christos@zoulas.com>
+
+	* Use calloc instead of malloc (Mike Frysinger)
+
+	* Fix configure script to detect wctypes.h (Mike Frysinger)
+
 2006-03-02 16:06 Christos Zoulas <christos@zoulas.com>
 2006-03-02 16:06 Christos Zoulas <christos@zoulas.com>
 
 
 	* Print empty if the file is (Mike Frysinger)
 	* Print empty if the file is (Mike Frysinger)

+ 2 - 2
LEGAL.NOTICE

@@ -1,7 +1,7 @@
-$Id: LEGAL.NOTICE,v 1.14 2004/09/11 19:15:56 christos Exp $
+$Id: LEGAL.NOTICE,v 1.15 2006/05/03 18:48:33 christos Exp $
 Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
 Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
 Software written by Ian F. Darwin and others;
 Software written by Ian F. Darwin and others;
-maintained 1994-2004 Christos Zoulas.
+maintained 1994- Christos Zoulas.
 
 
 This software is not subject to any export provision of the United States
 This software is not subject to any export provision of the United States
 Department of Commerce, and may be exported to any country or planet.
 Department of Commerce, and may be exported to any country or planet.

+ 31 - 9
MAINT

@@ -1,4 +1,4 @@
-$Id: MAINT,v 1.5 2003/03/23 04:36:37 christos Exp $
+$Id: MAINT,v 1.7 2006/06/01 18:19:41 ian Exp $
 
 
 Maintenance notes:
 Maintenance notes:
 
 
@@ -18,16 +18,38 @@ short.
 - Do not distribute changed versions.
 - Do not distribute changed versions.
 
 
 People trying to be helpful occasionally put up their hacked versions
 People trying to be helpful occasionally put up their hacked versions
-of the file command for FTP, then the "archie" server finds and publishes
-the hacked version, and people all over the world get copies of it.
-Within a day or two I am getting email from around the world
-asking me why "my" file command won't compile!!! Needless to say this
-detracts from the limited time I have available to work on the actual
-software.  Therefore I ask you again to please NOT distribute
-your changed version.
-
+of the file command for anonymous FTP, and people all over the
+world get copies of the hacked versions.  Within a day or two I am
+getting email from around the world asking me why "my" file command
+won't compile!!! Needless to say this detracts from the limited
+time I have available to work on the actual software. Therefore I
+ask you again to please NOT distribute your changed version. If
+you need to make changes, please add a patch file next to the
+distribution tar, and a README file that clearly explains what you
+are trying to fix.
 
 
 Thank you for your assistance and cooperation.
 Thank you for your assistance and cooperation.
 
 
+Code Overview
+
+This is a rough idea of the control flow from the main program:
+
+file.c	main()
+file.c	process (called for each file)
+		printf file name
+magic.c		magic_file()
+fsmagic.c		file_fsmagic()
+				(handles statbuf modes for DEV)
+			(handles statbuf modes for executable &c.
+			reads data from file.
+funcs.c:		file_buffer()
+compress.c			file_zmagic()
+is_tar.c			file_is_tar()
+softmagic.c			file_softmagic()
+						match() - looks for match against main magic database
+ascmagic.c			file_ascmagic()
+readelf.c		file_tryelf()
+				"unknown"
+
 Christos Zoulas
 Christos Zoulas
 christos@astron.com
 christos@astron.com

+ 1 - 2
Makefile.in

@@ -38,8 +38,7 @@ host_triplet = @host@
 DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
 DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
 	$(srcdir)/Makefile.in $(srcdir)/config.h.in \
 	$(srcdir)/Makefile.in $(srcdir)/config.h.in \
 	$(top_srcdir)/configure ChangeLog config.guess config.sub \
 	$(top_srcdir)/configure ChangeLog config.guess config.sub \
-	depcomp install-sh ltcf-c.sh ltconfig ltmain.sh missing \
-	mkinstalldirs
+	depcomp install-sh ltcf-c.sh ltmain.sh missing mkinstalldirs
 subdir = .
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \

+ 3 - 2
README

@@ -1,5 +1,5 @@
 ** README for file(1) Command **
 ** README for file(1) Command **
-@(#) $Id: README,v 1.33 2003/05/23 21:31:56 christos Exp $
+@(#) $Id: README,v 1.34 2006/05/03 18:48:33 christos Exp $
 
 
 This is Release 4.x of Ian Darwin's (copyright but distributable)
 This is Release 4.x of Ian Darwin's (copyright but distributable)
 file(1) command. This version is the standard "file" command for Linux,
 file(1) command. This version is the standard "file" command for Linux,
@@ -96,7 +96,8 @@ and does not exist any longer.
 
 
 From: Kees Zeelenberg
 From: Kees Zeelenberg
 
 
-An MS-Windows (Win32) port of File-3.36 is available from
+An MS-Windows (Win32) port of File-4.17 is available from
 http://gnuwin32.sourceforge.net/
 http://gnuwin32.sourceforge.net/
+
 File is an implementation of the Unix File(1) command.
 File is an implementation of the Unix File(1) command.
 It knows the 'magic number' of several thousands of file types.
 It knows the 'magic number' of several thousands of file types.

+ 225 - 116
config.guess

@@ -1,9 +1,12 @@
 #! /bin/sh
 #! /bin/sh
+#
+# $NetBSD: config.guess,v 1.8 2004/08/14 19:13:55 schmonz Exp $
+#
 # Attempt to guess a canonical system name.
 # Attempt to guess a canonical system name.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002 Free Software Foundation, Inc.
+#   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
 
-timestamp='2002-07-23'
+timestamp='2004-06-11'
 
 
 # This file is free software; you can redistribute it and/or modify it
 # 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
 # under the terms of the GNU General Public License as published by
@@ -98,30 +101,32 @@ trap 'exit 1' 1 2 15
 # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
 # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
 # use `HOST_CC' if defined, but it is deprecated.
 # use `HOST_CC' if defined, but it is deprecated.
 
 
-# This shell variable is my proudest work .. or something. --bje
+# Portable tmp directory creation inspired by the Autoconf team.
 
 
-set_cc_for_build='tmpdir=${TMPDIR-/tmp}/config-guess-$$ ;
-(old=`umask` && umask 077 && mkdir $tmpdir && umask $old && unset old)
-   || (echo "$me: cannot create $tmpdir" >&2 && exit 1) ;
-dummy=$tmpdir/dummy ;
-files="$dummy.c $dummy.o $dummy.rel $dummy" ;
-trap '"'"'rm -f $files; rmdir $tmpdir; exit 1'"'"' 1 2 15 ;
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
 case $CC_FOR_BUILD,$HOST_CC,$CC in
 case $CC_FOR_BUILD,$HOST_CC,$CC in
  ,,)    echo "int x;" > $dummy.c ;
  ,,)    echo "int x;" > $dummy.c ;
 	for c in cc gcc c89 c99 ; do
 	for c in cc gcc c89 c99 ; do
-	  if ($c $dummy.c -c -o $dummy.o) >/dev/null 2>&1 ; then
+	  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
 	     CC_FOR_BUILD="$c"; break ;
 	     CC_FOR_BUILD="$c"; break ;
 	  fi ;
 	  fi ;
 	done ;
 	done ;
-	rm -f $files ;
 	if test x"$CC_FOR_BUILD" = x ; then
 	if test x"$CC_FOR_BUILD" = x ; then
 	  CC_FOR_BUILD=no_compiler_found ;
 	  CC_FOR_BUILD=no_compiler_found ;
 	fi
 	fi
 	;;
 	;;
  ,,*)   CC_FOR_BUILD=$CC ;;
  ,,*)   CC_FOR_BUILD=$CC ;;
  ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
  ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
-esac ;
-unset files'
+esac ;'
 
 
 # This is needed to find uname on a Pyramid OSx when run in the BSD universe.
 # This is needed to find uname on a Pyramid OSx when run in the BSD universe.
 # (ghazi@noc.rutgers.edu 1994-08-24)
 # (ghazi@noc.rutgers.edu 1994-08-24)
@@ -156,6 +161,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
 	    arm*) machine=arm-unknown ;;
 	    arm*) machine=arm-unknown ;;
 	    sh3el) machine=shl-unknown ;;
 	    sh3el) machine=shl-unknown ;;
 	    sh3eb) machine=sh-unknown ;;
 	    sh3eb) machine=sh-unknown ;;
+	    sh5el) machine=sh5le-unknown ;;
 	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
 	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
 	esac
 	esac
 	# The Operating System including object format, if it has switched
 	# The Operating System including object format, if it has switched
@@ -178,21 +184,41 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
 		;;
 		;;
 	esac
 	esac
 	# The OS release
 	# The OS release
-	release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+	# Debian GNU/NetBSD machines have a different userland, and
+	# thus, need a distinct triplet. However, they do not need
+	# kernel version information, so it can be replaced with a
+	# suitable tag, in the style of linux-gnu.
+	case "${UNAME_VERSION}" in
+	    Debian*)
+		release='-gnu'
+		;;
+	    *)
+		release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+		;;
+	esac
 	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
 	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
 	# contains redundant information, the shorter form:
 	# contains redundant information, the shorter form:
 	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
 	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
 	echo "${machine}-${os}${release}"
 	echo "${machine}-${os}${release}"
 	exit 0 ;;
 	exit 0 ;;
+    amd64:OpenBSD:*:*)
+	echo x86_64-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
     amiga:OpenBSD:*:*)
     amiga:OpenBSD:*:*)
 	echo m68k-unknown-openbsd${UNAME_RELEASE}
 	echo m68k-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
     arc:OpenBSD:*:*)
     arc:OpenBSD:*:*)
 	echo mipsel-unknown-openbsd${UNAME_RELEASE}
 	echo mipsel-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
+    cats:OpenBSD:*:*)
+	echo arm-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
     hp300:OpenBSD:*:*)
     hp300:OpenBSD:*:*)
 	echo m68k-unknown-openbsd${UNAME_RELEASE}
 	echo m68k-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
+    luna88k:OpenBSD:*:*)
+    	echo m88k-unknown-openbsd${UNAME_RELEASE}
+	exit 0 ;;
     mac68k:OpenBSD:*:*)
     mac68k:OpenBSD:*:*)
 	echo m68k-unknown-openbsd${UNAME_RELEASE}
 	echo m68k-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
@@ -223,71 +249,70 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
     *:OpenBSD:*:*)
     *:OpenBSD:*:*)
 	echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
 	echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
 	exit 0 ;;
 	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:*:*)
     alpha:OSF1:*:*)
-	if test $UNAME_RELEASE = "V4.0"; then
+	case $UNAME_RELEASE in
+	*4.0)
 		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
 		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
+	# types through head -n 1, so we only detect the type of CPU 0.
+	ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+	case "$ALPHA_CPU_TYPE" in
+	    "EV4 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV4.5 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "LCA4 (21066/21068)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV5 (21164)")
+		UNAME_MACHINE="alphaev5" ;;
+	    "EV5.6 (21164A)")
+		UNAME_MACHINE="alphaev56" ;;
+	    "EV5.6 (21164PC)")
+		UNAME_MACHINE="alphapca56" ;;
+	    "EV5.7 (21164PC)")
+		UNAME_MACHINE="alphapca57" ;;
+	    "EV6 (21264)")
+		UNAME_MACHINE="alphaev6" ;;
+	    "EV6.7 (21264A)")
+		UNAME_MACHINE="alphaev67" ;;
+	    "EV6.8CB (21264C)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8AL (21264B)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8CX (21264D)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.9A (21264/EV69A)")
+		UNAME_MACHINE="alphaev69" ;;
+	    "EV7 (21364)")
+		UNAME_MACHINE="alphaev7" ;;
+	    "EV7.9 (21364A)")
+		UNAME_MACHINE="alphaev79" ;;
+	esac
+	# A Pn.n version is a patched version.
 	# A Vn.n version is a released version.
 	# A Vn.n version is a released version.
 	# A Tn.n version is a released field test version.
 	# A Tn.n version is a released field test version.
 	# A Xn.n version is an unreleased experimental baselevel.
 	# A Xn.n version is an unreleased experimental baselevel.
 	# 1.2 uses "1.2" for uname -r.
 	# 1.2 uses "1.2" for uname -r.
-	eval $set_cc_for_build
-	cat <<EOF >$dummy.s
-	.data
-\$Lformat:
-	.byte 37,100,45,37,120,10,0	# "%d-%x\n"
-
-	.text
-	.globl main
-	.align 4
-	.ent main
-main:
-	.frame \$30,16,\$26,0
-	ldgp \$29,0(\$27)
-	.prologue 1
-	.long 0x47e03d80 # implver \$0
-	lda \$2,-1
-	.long 0x47e20c21 # amask \$2,\$1
-	lda \$16,\$Lformat
-	mov \$0,\$17
-	not \$1,\$18
-	jsr \$26,printf
-	ldgp \$29,0(\$26)
-	mov 0,\$16
-	jsr \$26,exit
-	.end main
-EOF
-	$CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null
-	if test "$?" = 0 ; then
-		case `$dummy` in
-			0-0)
-				UNAME_MACHINE="alpha"
-				;;
-			1-0)
-				UNAME_MACHINE="alphaev5"
-				;;
-			1-1)
-				UNAME_MACHINE="alphaev56"
-				;;
-			1-101)
-				UNAME_MACHINE="alphapca56"
-				;;
-			2-303)
-				UNAME_MACHINE="alphaev6"
-				;;
-			2-307)
-				UNAME_MACHINE="alphaev67"
-				;;
-			2-1307)
-				UNAME_MACHINE="alphaev68"
-				;;
-			3-1307)
-				UNAME_MACHINE="alphaev7"
-				;;
-		esac
-	fi
-	rm -f $dummy.s $dummy && rmdir $tmpdir
-	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	exit 0 ;;
+    Alpha*:OpenVMS:*:*)
+	echo alpha-hp-vms
 	exit 0 ;;
 	exit 0 ;;
     Alpha\ *:Windows_NT*:*)
     Alpha\ *:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# How do we know it's Interix rather than the generic POSIX subsystem?
@@ -310,6 +335,9 @@ EOF
     *:OS/390:*:*)
     *:OS/390:*:*)
 	echo i370-ibm-openedition
 	echo i370-ibm-openedition
 	exit 0 ;;
 	exit 0 ;;
+    *:OS400:*:*)
+        echo powerpc-ibm-os400
+	exit 0 ;;
     arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
     arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
 	echo arm-acorn-riscix${UNAME_RELEASE}
 	echo arm-acorn-riscix${UNAME_RELEASE}
 	exit 0;;
 	exit 0;;
@@ -327,6 +355,9 @@ EOF
     NILE*:*:*:dcosx)
     NILE*:*:*:dcosx)
 	echo pyramid-pyramid-svr4
 	echo pyramid-pyramid-svr4
 	exit 0 ;;
 	exit 0 ;;
+    DRS?6000:unix:4.0:6*)
+	echo sparc-icl-nx6
+	exit 0 ;;
     DRS?6000:UNIX_SV:4.2*:7*)
     DRS?6000:UNIX_SV:4.2*:7*)
 	case `/usr/bin/uname -p` in
 	case `/usr/bin/uname -p` in
 	    sparc) echo sparc-icl-nx7 && exit 0 ;;
 	    sparc) echo sparc-icl-nx7 && exit 0 ;;
@@ -399,6 +430,9 @@ EOF
     *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
     *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
         echo m68k-unknown-mint${UNAME_RELEASE}
         echo m68k-unknown-mint${UNAME_RELEASE}
         exit 0 ;;
         exit 0 ;;
+    m68k:machten:*:*)
+	echo m68k-apple-machten${UNAME_RELEASE}
+	exit 0 ;;
     powerpc:machten:*:*)
     powerpc:machten:*:*)
 	echo powerpc-apple-machten${UNAME_RELEASE}
 	echo powerpc-apple-machten${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
@@ -437,16 +471,18 @@ EOF
 	  exit (-1);
 	  exit (-1);
 	}
 	}
 EOF
 EOF
-	$CC_FOR_BUILD $dummy.c -o $dummy \
+	$CC_FOR_BUILD -o $dummy $dummy.c \
 	  && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
 	  && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
-	  && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0
-	rm -f $dummy.c $dummy && rmdir $tmpdir
+	  && exit 0
 	echo mips-mips-riscos${UNAME_RELEASE}
 	echo mips-mips-riscos${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
     Motorola:PowerMAX_OS:*:*)
     Motorola:PowerMAX_OS:*:*)
 	echo powerpc-motorola-powermax
 	echo powerpc-motorola-powermax
 	exit 0 ;;
 	exit 0 ;;
-    Night_Hawk:*:*:PowerMAX_OS)
+    Motorola:*:4.3:PL8-*)
+	echo powerpc-harris-powermax
+	exit 0 ;;
+    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
 	echo powerpc-harris-powermax
 	echo powerpc-harris-powermax
 	exit 0 ;;
 	exit 0 ;;
     Night_Hawk:Power_UNIX:*:*)
     Night_Hawk:Power_UNIX:*:*)
@@ -521,8 +557,7 @@ EOF
 			exit(0);
 			exit(0);
 			}
 			}
 EOF
 EOF
-		$CC_FOR_BUILD $dummy.c -o $dummy && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0
-		rm -f $dummy.c $dummy && rmdir $tmpdir
+		$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
 		echo rs6000-ibm-aix3.2.5
 		echo rs6000-ibm-aix3.2.5
 	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
 	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
 		echo rs6000-ibm-aix3.2.4
 		echo rs6000-ibm-aix3.2.4
@@ -620,11 +655,21 @@ EOF
                   exit (0);
                   exit (0);
               }
               }
 EOF
 EOF
-		    (CCOPTS= $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null) && HP_ARCH=`$dummy`
-		    if test -z "$HP_ARCH"; then HP_ARCH=hppa; fi
-		    rm -f $dummy.c $dummy && rmdir $tmpdir
+		    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+		    test -z "$HP_ARCH" && HP_ARCH=hppa
 		fi ;;
 		fi ;;
 	esac
 	esac
+	if [ ${HP_ARCH} = "hppa2.0w" ]
+	then
+	    # avoid double evaluation of $set_cc_for_build
+	    test -n "$CC_FOR_BUILD" || eval $set_cc_for_build
+	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null
+	    then
+		HP_ARCH="hppa2.0w"
+	    else
+		HP_ARCH="hppa64"
+	    fi
+	fi
 	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
 	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
 	exit 0 ;;
 	exit 0 ;;
     ia64:HP-UX:*:*)
     ia64:HP-UX:*:*)
@@ -658,8 +703,7 @@ EOF
 	  exit (0);
 	  exit (0);
 	}
 	}
 EOF
 EOF
-	$CC_FOR_BUILD $dummy.c -o $dummy && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0
-	rm -f $dummy.c $dummy && rmdir $tmpdir
+	$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
 	echo unknown-hitachi-hiuxwe2
 	echo unknown-hitachi-hiuxwe2
 	exit 0 ;;
 	exit 0 ;;
     9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
     9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
@@ -717,21 +761,26 @@ EOF
     CRAY*TS:*:*:*)
     CRAY*TS:*:*:*)
 	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
 	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
 	exit 0 ;;
 	exit 0 ;;
-    CRAY*T3D:*:*:*)
-	echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
     CRAY*T3E:*:*:*)
     CRAY*T3E:*:*:*)
 	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
 	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
 	exit 0 ;;
 	exit 0 ;;
     CRAY*SV1:*:*:*)
     CRAY*SV1:*:*:*)
 	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
 	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
 	exit 0 ;;
 	exit 0 ;;
+    *:UNICOS/mp:*:*)
+	echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit 0 ;;
     F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
     F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
 	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
 	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
         FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
         FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
         FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
         FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
         echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
         echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
         exit 0 ;;
         exit 0 ;;
+    5000:UNIX_System_V:4.*:*)
+        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+        FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+        echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	exit 0 ;;
     i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
     i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
 	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
 	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
@@ -753,8 +802,10 @@ EOF
 	#endif
 	#endif
 EOF
 EOF
 	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
 	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
-	rm -f $dummy.c && rmdir $tmpdir
-	echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$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}
 	exit 0 ;;
 	exit 0 ;;
     i*:CYGWIN*:*)
     i*:CYGWIN*:*)
 	echo ${UNAME_MACHINE}-pc-cygwin
 	echo ${UNAME_MACHINE}-pc-cygwin
@@ -765,14 +816,17 @@ EOF
     i*:PW*:*)
     i*:PW*:*)
 	echo ${UNAME_MACHINE}-pc-pw32
 	echo ${UNAME_MACHINE}-pc-pw32
 	exit 0 ;;
 	exit 0 ;;
-    x86:Interix*:3*)
-	echo i386-pc-interix3
+    x86:Interix*:[34]*)
+	echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//'
+	exit 0 ;;
+    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
+	echo i${UNAME_MACHINE}-pc-mks
 	exit 0 ;;
 	exit 0 ;;
     i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
     i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
 	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
 	# UNAME_MACHINE based on the output of uname instead of i386?
 	# UNAME_MACHINE based on the output of uname instead of i386?
-	echo i386-pc-interix
+	echo i586-pc-interix
 	exit 0 ;;
 	exit 0 ;;
     i*:UWIN*:*)
     i*:UWIN*:*)
 	echo ${UNAME_MACHINE}-pc-uwin
 	echo ${UNAME_MACHINE}-pc-uwin
@@ -784,17 +838,28 @@ EOF
 	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
 	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
 	exit 0 ;;
 	exit 0 ;;
     *:GNU:*:*)
     *:GNU:*:*)
+	# the GNU system
 	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
 	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
 	exit 0 ;;
 	exit 0 ;;
+    *:GNU/*:*:*)
+	# other systems with GNU libc and userland
+	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
+	exit 0 ;;
     i*86:Minix:*:*)
     i*86:Minix:*:*)
 	echo ${UNAME_MACHINE}-pc-minix
 	echo ${UNAME_MACHINE}-pc-minix
 	exit 0 ;;
 	exit 0 ;;
     arm*:Linux:*:*)
     arm*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	exit 0 ;;
 	exit 0 ;;
+    cris:Linux:*:*)
+	echo cris-axis-linux-gnu
+	exit 0 ;;
     ia64:Linux:*:*)
     ia64:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	exit 0 ;;
 	exit 0 ;;
+    m32r*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
     m68*:Linux:*:*)
     m68*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	exit 0 ;;
 	exit 0 ;;
@@ -815,8 +880,26 @@ EOF
 	#endif
 	#endif
 EOF
 EOF
 	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
 	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
-	rm -f $dummy.c && rmdir $tmpdir
-	test x"${CPU}" != x && echo "${CPU}-pc-linux-gnu" && exit 0
+	test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
+	;;
+    mips64:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef mips64
+	#undef mips64el
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=mips64el
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=mips64
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
+	test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
 	;;
 	;;
     ppc:Linux:*:*)
     ppc:Linux:*:*)
 	echo powerpc-unknown-linux-gnu
 	echo powerpc-unknown-linux-gnu
@@ -852,6 +935,9 @@ EOF
     s390:Linux:*:* | s390x:Linux:*:*)
     s390:Linux:*:* | s390x:Linux:*:*)
 	echo ${UNAME_MACHINE}-ibm-linux
 	echo ${UNAME_MACHINE}-ibm-linux
 	exit 0 ;;
 	exit 0 ;;
+    sh64*:Linux:*:*)
+    	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit 0 ;;
     sh*:Linux:*:*)
     sh*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
 	exit 0 ;;
 	exit 0 ;;
@@ -909,9 +995,11 @@ EOF
 	LIBC=gnuaout
 	LIBC=gnuaout
 	#endif
 	#endif
 	#endif
 	#endif
+	#ifdef __dietlibc__
+	LIBC=dietlibc
+	#endif
 EOF
 EOF
 	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
 	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
-	rm -f $dummy.c && rmdir $tmpdir
 	test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
 	test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
 	test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
 	test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
 	;;
 	;;
@@ -929,6 +1017,26 @@ EOF
         # Use sysv4.2uw... so that sysv4* matches it.
         # Use sysv4.2uw... so that sysv4* matches it.
 	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
 	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
 	exit 0 ;;
 	exit 0 ;;
+    i*86:OS/2:*:*)
+	# If we were able to find `uname', then EMX Unix compatibility
+	# is probably installed.
+	echo ${UNAME_MACHINE}-pc-os2-emx
+	exit 0 ;;
+    i*86:XTS-300:*:STOP)
+	echo ${UNAME_MACHINE}-unknown-stop
+	exit 0 ;;
+    i*86:atheos:*:*)
+	echo ${UNAME_MACHINE}-unknown-atheos
+	exit 0 ;;
+	i*86:syllable:*:*)
+	echo ${UNAME_MACHINE}-pc-syllable
+	exit 0 ;;
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
+	echo i386-unknown-lynxos${UNAME_RELEASE}
+	exit 0 ;;
+    i*86:*DOS:*:*)
+	echo ${UNAME_MACHINE}-pc-msdosdjgpp
+	exit 0 ;;
     i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
     i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
 	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
 	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
 	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
 	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
@@ -963,9 +1071,6 @@ EOF
 		echo ${UNAME_MACHINE}-pc-sysv32
 		echo ${UNAME_MACHINE}-pc-sysv32
 	fi
 	fi
 	exit 0 ;;
 	exit 0 ;;
-    i*86:*DOS:*:*)
-	echo ${UNAME_MACHINE}-pc-msdosdjgpp
-	exit 0 ;;
     pc:*:*:*)
     pc:*:*:*)
 	# Left here for compatibility:
 	# Left here for compatibility:
         # uname -m prints for DJGPP always 'pc', but it prints nothing about
         # uname -m prints for DJGPP always 'pc', but it prints nothing about
@@ -989,9 +1094,15 @@ EOF
 	# "miniframe"
 	# "miniframe"
 	echo m68010-convergent-sysv
 	echo m68010-convergent-sysv
 	exit 0 ;;
 	exit 0 ;;
-    M68*:*:R3V[567]*:*)
+    mc68k:UNIX:SYSTEM5:3.51m)
+	echo m68k-convergent-sysv
+	exit 0 ;;
+    M680?0:D-NIX:5.3:*)
+	echo m68k-diab-dnix
+	exit 0 ;;
+    M68*:*:R3V[5678]*:*)
 	test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
 	test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
-    3[34]??:*: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)
+    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)
 	OS_REL=''
 	OS_REL=''
 	test -r /etc/.relid \
 	test -r /etc/.relid \
 	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
 	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
@@ -1008,9 +1119,6 @@ EOF
     mc68030:UNIX_System_V:4.*:*)
     mc68030:UNIX_System_V:4.*:*)
 	echo m68k-atari-sysv4
 	echo m68k-atari-sysv4
 	exit 0 ;;
 	exit 0 ;;
-    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
-	echo i386-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
     TSUNAMI:LynxOS:2.*:*)
     TSUNAMI:LynxOS:2.*:*)
 	echo sparc-unknown-lynxos${UNAME_RELEASE}
 	echo sparc-unknown-lynxos${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
@@ -1082,6 +1190,9 @@ EOF
     SX-5:SUPER-UX:*:*)
     SX-5:SUPER-UX:*:*)
 	echo sx5-nec-superux${UNAME_RELEASE}
 	echo sx5-nec-superux${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
+    SX-6:SUPER-UX:*:*)
+	echo sx6-nec-superux${UNAME_RELEASE}
+	exit 0 ;;
     Power*:Rhapsody:*:*)
     Power*:Rhapsody:*:*)
 	echo powerpc-apple-rhapsody${UNAME_RELEASE}
 	echo powerpc-apple-rhapsody${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
@@ -1089,7 +1200,11 @@ EOF
 	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
 	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
     *:Darwin:*:*)
     *:Darwin:*:*)
-	echo `uname -p`-apple-darwin${UNAME_RELEASE}
+	case `uname -p` in
+	    *86) UNAME_PROCESSOR=i686 ;;
+	    powerpc) UNAME_PROCESSOR=powerpc ;;
+	esac
+	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
     *:procnto*:*:* | *:QNX:[0123456789]*:*)
     *:procnto*:*:* | *:QNX:[0123456789]*:*)
 	UNAME_PROCESSOR=`uname -p`
 	UNAME_PROCESSOR=`uname -p`
@@ -1102,7 +1217,7 @@ EOF
     *:QNX:*:4*)
     *:QNX:*:4*)
 	echo i386-pc-qnx
 	echo i386-pc-qnx
 	exit 0 ;;
 	exit 0 ;;
-    NSR-[GKLNPTVW]:NONSTOP_KERNEL:*:*)
+    NSR-?:NONSTOP_KERNEL:*:*)
 	echo nsr-tandem-nsk${UNAME_RELEASE}
 	echo nsr-tandem-nsk${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
     *:NonStop-UX:*:*)
     *:NonStop-UX:*:*)
@@ -1125,11 +1240,6 @@ EOF
 	fi
 	fi
 	echo ${UNAME_MACHINE}-unknown-plan9
 	echo ${UNAME_MACHINE}-unknown-plan9
 	exit 0 ;;
 	exit 0 ;;
-    i*86:OS/2:*:*)
-	# If we were able to find `uname', then EMX Unix compatibility
-	# is probably installed.
-	echo ${UNAME_MACHINE}-pc-os2-emx
-	exit 0 ;;
     *:TOPS-10:*:*)
     *:TOPS-10:*:*)
 	echo pdp10-unknown-tops10
 	echo pdp10-unknown-tops10
 	exit 0 ;;
 	exit 0 ;;
@@ -1148,11 +1258,11 @@ EOF
     *:ITS:*:*)
     *:ITS:*:*)
 	echo pdp10-unknown-its
 	echo pdp10-unknown-its
 	exit 0 ;;
 	exit 0 ;;
-    i*86:XTS-300:*:STOP)
-	echo ${UNAME_MACHINE}-unknown-stop
+    SEI:*:*:SEIUX)
+        echo mips-sei-seiux${UNAME_RELEASE}
 	exit 0 ;;
 	exit 0 ;;
-    i*86:atheos:*:*)
-	echo ${UNAME_MACHINE}-unknown-atheos
+    *:DragonFly:*:*)
+	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
 	exit 0 ;;
 	exit 0 ;;
 esac
 esac
 
 
@@ -1274,8 +1384,7 @@ main ()
 }
 }
 EOF
 EOF
 
 
-$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0
-rm -f $dummy.c $dummy && rmdir $tmpdir
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0
 
 
 # Apollos put the system type in the environment.
 # Apollos put the system type in the environment.
 
 

+ 3 - 0
config.h.in

@@ -118,6 +118,9 @@
 /* Define to 1 if you have the <wchar.h> header file. */
 /* Define to 1 if you have the <wchar.h> header file. */
 #undef HAVE_WCHAR_H
 #undef HAVE_WCHAR_H
 
 
+/* Define to 1 if you have the <wctype.h> header file. */
+#undef HAVE_WCTYPE_H
+
 /* Define to 1 if you have the `wcwidth' function. */
 /* Define to 1 if you have the `wcwidth' function. */
 #undef HAVE_WCWIDTH
 #undef HAVE_WCWIDTH
 
 

+ 152 - 57
config.sub

@@ -1,9 +1,12 @@
 #! /bin/sh
 #! /bin/sh
+#
+# $NetBSD: config.sub,v 1.7 2004/08/14 19:14:42 schmonz Exp $
+#
 # Configuration validation subroutine script.
 # Configuration validation subroutine script.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002 Free Software Foundation, Inc.
+#   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
 
-timestamp='2002-07-03'
+timestamp='2004-03-12'
 
 
 # This file is (in principle) common to ALL GNU software.
 # This file is (in principle) common to ALL GNU software.
 # The presence of a machine in this file suggests that SOME GNU software
 # The presence of a machine in this file suggests that SOME GNU software
@@ -118,7 +121,8 @@ esac
 # Here we must recognize all the valid KERNEL-OS combinations.
 # Here we must recognize all the valid KERNEL-OS combinations.
 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
 case $maybe_os in
 case $maybe_os in
-  nto-qnx* | linux-gnu* | freebsd*-gnu* | storm-chaos* | os2-emx* | windows32-* | rtmk-nova*)
+  nto-qnx* | linux-gnu* | linux-dietlibc | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | \
+  kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
     os=-$maybe_os
     os=-$maybe_os
     basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
     basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
     ;;
     ;;
@@ -228,36 +232,42 @@ case $basic_machine in
 	| a29k \
 	| a29k \
 	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
 	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
 	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
 	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+	| am33_2.0 \
 	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
 	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
 	| c4x | clipper \
 	| c4x | clipper \
 	| d10v | d30v | dlx | dsp16xx \
 	| d10v | d30v | dlx | dsp16xx \
 	| fr30 | frv \
 	| fr30 | frv \
 	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
 	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
 	| i370 | i860 | i960 | ia64 \
 	| i370 | i860 | i960 | ia64 \
-	| ip2k \
-	| m32r | m68000 | m68k | m88k | mcore \
+	| ip2k | iq2000 \
+	| m32r | m32rle | m68000 | m68k | m88k | mcore \
 	| mips | mipsbe | mipseb | mipsel | mipsle \
 	| mips | mipsbe | mipseb | mipsel | mipsle \
 	| mips16 \
 	| mips16 \
 	| mips64 | mips64el \
 	| mips64 | mips64el \
+	| mips64vr | mips64vrel \
 	| mips64orion | mips64orionel \
 	| mips64orion | mips64orionel \
 	| mips64vr4100 | mips64vr4100el \
 	| mips64vr4100 | mips64vr4100el \
 	| mips64vr4300 | mips64vr4300el \
 	| mips64vr4300 | mips64vr4300el \
 	| mips64vr5000 | mips64vr5000el \
 	| mips64vr5000 | mips64vr5000el \
 	| mipsisa32 | mipsisa32el \
 	| mipsisa32 | mipsisa32el \
+	| mipsisa32r2 | mipsisa32r2el \
 	| mipsisa64 | mipsisa64el \
 	| mipsisa64 | mipsisa64el \
+	| mipsisa64r2 | mipsisa64r2el \
 	| mipsisa64sb1 | mipsisa64sb1el \
 	| mipsisa64sb1 | mipsisa64sb1el \
+	| mipsisa64sr71k | mipsisa64sr71kel \
 	| mipstx39 | mipstx39el \
 	| mipstx39 | mipstx39el \
 	| mn10200 | mn10300 \
 	| mn10200 | mn10300 \
+	| msp430 \
 	| ns16k | ns32k \
 	| ns16k | ns32k \
 	| openrisc | or32 \
 	| openrisc | or32 \
 	| pdp10 | pdp11 | pj | pjl \
 	| pdp10 | pdp11 | pj | pjl \
 	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
 	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
 	| pyramid \
 	| pyramid \
-	| sh | sh[1234] | sh3e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
+	| sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
 	| sh64 | sh64le \
 	| sh64 | sh64le \
-	| sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \
+	| sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv8 | sparcv9 | sparcv9b \
 	| strongarm \
 	| strongarm \
-	| tahoe | thumb | tic80 | tron \
+	| tahoe | thumb | tic4x | tic80 | tron \
 	| v850 | v850e \
 	| v850 | v850e \
 	| we32k \
 	| we32k \
 	| x86 | xscale | xstormy16 | xtensa \
 	| x86 | xscale | xstormy16 | xtensa \
@@ -292,7 +302,7 @@ case $basic_machine in
 	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
 	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
 	| avr-* \
 	| avr-* \
 	| bs2000-* \
 	| bs2000-* \
-	| c[123]* | c30-* | [cjt]90-* | c54x-* \
+	| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
 	| clipper-* | cydra-* \
 	| clipper-* | cydra-* \
 	| d10v-* | d30v-* | dlx-* \
 	| d10v-* | d30v-* | dlx-* \
 	| elxsi-* \
 	| elxsi-* \
@@ -300,32 +310,39 @@ case $basic_machine in
 	| h8300-* | h8500-* \
 	| h8300-* | h8500-* \
 	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
 	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
 	| i*86-* | i860-* | i960-* | ia64-* \
 	| i*86-* | i860-* | i960-* | ia64-* \
-	| ip2k-* \
-	| m32r-* \
+	| ip2k-* | iq2000-* \
+	| m32r-* | m32rle-* \
 	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
 	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
 	| m88110-* | m88k-* | mcore-* \
 	| m88110-* | m88k-* | mcore-* \
 	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
 	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
 	| mips16-* \
 	| mips16-* \
 	| mips64-* | mips64el-* \
 	| mips64-* | mips64el-* \
+	| mips64vr-* | mips64vrel-* \
 	| mips64orion-* | mips64orionel-* \
 	| mips64orion-* | mips64orionel-* \
 	| mips64vr4100-* | mips64vr4100el-* \
 	| mips64vr4100-* | mips64vr4100el-* \
 	| mips64vr4300-* | mips64vr4300el-* \
 	| mips64vr4300-* | mips64vr4300el-* \
 	| mips64vr5000-* | mips64vr5000el-* \
 	| mips64vr5000-* | mips64vr5000el-* \
 	| mipsisa32-* | mipsisa32el-* \
 	| mipsisa32-* | mipsisa32el-* \
+	| mipsisa32r2-* | mipsisa32r2el-* \
 	| mipsisa64-* | mipsisa64el-* \
 	| mipsisa64-* | mipsisa64el-* \
+	| mipsisa64r2-* | mipsisa64r2el-* \
 	| mipsisa64sb1-* | mipsisa64sb1el-* \
 	| mipsisa64sb1-* | mipsisa64sb1el-* \
-	| mipstx39 | mipstx39el \
-	| none-* | np1-* | ns16k-* | ns32k-* \
+	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
+	| mipstx39-* | mipstx39el-* \
+	| msp430-* \
+	| none-* | np1-* | nv1-* | ns16k-* | ns32k-* \
 	| orion-* \
 	| orion-* \
 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
 	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
 	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
 	| pyramid-* \
 	| pyramid-* \
 	| romp-* | rs6000-* \
 	| romp-* | rs6000-* \
-	| sh-* | sh[1234]-* | sh3e-* | sh[34]eb-* | shbe-* \
+	| sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \
 	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
 	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
 	| sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \
 	| sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \
-	| sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
-	| tahoe-* | thumb-* | tic30-* | tic54x-* | tic80-* | tron-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
+	| tahoe-* | thumb-* \
+	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+	| tron-* \
 	| v850-* | v850e-* | vax-* \
 	| v850-* | v850e-* | vax-* \
 	| we32k-* \
 	| we32k-* \
 	| x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \
 	| x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \
@@ -349,6 +366,9 @@ case $basic_machine in
 		basic_machine=a29k-amd
 		basic_machine=a29k-amd
 		os=-udi
 		os=-udi
 		;;
 		;;
+    	abacus)
+		basic_machine=abacus-unknown
+		;;
 	adobe68k)
 	adobe68k)
 		basic_machine=m68010-adobe
 		basic_machine=m68010-adobe
 		os=-scout
 		os=-scout
@@ -363,6 +383,12 @@ case $basic_machine in
 		basic_machine=a29k-none
 		basic_machine=a29k-none
 		os=-bsd
 		os=-bsd
 		;;
 		;;
+	amd64)
+		basic_machine=x86_64-pc
+		;;
+	amd64-*)
+		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
 	amdahl)
 	amdahl)
 		basic_machine=580-amdahl
 		basic_machine=580-amdahl
 		os=-sysv
 		os=-sysv
@@ -422,12 +448,20 @@ case $basic_machine in
 		basic_machine=j90-cray
 		basic_machine=j90-cray
 		os=-unicos
 		os=-unicos
 		;;
 		;;
+	cr16c)
+		basic_machine=cr16c-unknown
+		os=-elf
+		;;
 	crds | unos)
 	crds | unos)
 		basic_machine=m68k-crds
 		basic_machine=m68k-crds
 		;;
 		;;
 	cris | cris-* | etrax*)
 	cris | cris-* | etrax*)
 		basic_machine=cris-axis
 		basic_machine=cris-axis
 		;;
 		;;
+	crx)
+		basic_machine=crx-unknown
+		os=-elf
+		;;
 	da30 | da30-*)
 	da30 | da30-*)
 		basic_machine=m68k-da30
 		basic_machine=m68k-da30
 		;;
 		;;
@@ -712,6 +746,10 @@ case $basic_machine in
 	np1)
 	np1)
 		basic_machine=np1-gould
 		basic_machine=np1-gould
 		;;
 		;;
+	nv1)
+		basic_machine=nv1-cray
+		os=-unicosmp
+		;;
 	nsr-tandem)
 	nsr-tandem)
 		basic_machine=nsr-tandem
 		basic_machine=nsr-tandem
 		;;
 		;;
@@ -723,6 +761,10 @@ case $basic_machine in
 		basic_machine=or32-unknown
 		basic_machine=or32-unknown
 		os=-coff
 		os=-coff
 		;;
 		;;
+	os400)
+		basic_machine=powerpc-ibm
+		os=-os400
+		;;
 	OSE68000 | ose68000)
 	OSE68000 | ose68000)
 		basic_machine=m68000-ericsson
 		basic_machine=m68000-ericsson
 		os=-ose
 		os=-ose
@@ -745,49 +787,55 @@ case $basic_machine in
 	pbb)
 	pbb)
 		basic_machine=m68k-tti
 		basic_machine=m68k-tti
 		;;
 		;;
-        pc532 | pc532-*)
+	pc532 | pc532-*)
 		basic_machine=ns32k-pc532
 		basic_machine=ns32k-pc532
 		;;
 		;;
 	pentium | p5 | k5 | k6 | nexgen | viac3)
 	pentium | p5 | k5 | k6 | nexgen | viac3)
 		basic_machine=i586-pc
 		basic_machine=i586-pc
 		;;
 		;;
-	pentiumpro | p6 | 6x86 | athlon)
+	pentiumpro | p6 | 6x86 | athlon | athlon_*)
 		basic_machine=i686-pc
 		basic_machine=i686-pc
 		;;
 		;;
-	pentiumii | pentium2)
+	pentiumii | pentium2 | pentiumiii | pentium3)
 		basic_machine=i686-pc
 		basic_machine=i686-pc
 		;;
 		;;
+	pentium4)
+		basic_machine=i786-pc
+		;;
 	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
 	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
 		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
 		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
 		;;
 		;;
 	pentiumpro-* | p6-* | 6x86-* | athlon-*)
 	pentiumpro-* | p6-* | 6x86-* | athlon-*)
 		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
 		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
 		;;
 		;;
-	pentiumii-* | pentium2-*)
+	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
 		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
 		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
 		;;
 		;;
+	pentium4-*)
+		basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
 	pn)
 	pn)
 		basic_machine=pn-gould
 		basic_machine=pn-gould
 		;;
 		;;
 	power)	basic_machine=power-ibm
 	power)	basic_machine=power-ibm
 		;;
 		;;
 	ppc)	basic_machine=powerpc-unknown
 	ppc)	basic_machine=powerpc-unknown
-	        ;;
+		;;
 	ppc-*)	basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
 	ppc-*)	basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
 		;;
 		;;
 	ppcle | powerpclittle | ppc-le | powerpc-little)
 	ppcle | powerpclittle | ppc-le | powerpc-little)
 		basic_machine=powerpcle-unknown
 		basic_machine=powerpcle-unknown
-	        ;;
+		;;
 	ppcle-* | powerpclittle-*)
 	ppcle-* | powerpclittle-*)
 		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
 		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
 		;;
 		;;
 	ppc64)	basic_machine=powerpc64-unknown
 	ppc64)	basic_machine=powerpc64-unknown
-	        ;;
+		;;
 	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
 	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
 		;;
 		;;
 	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
 	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
 		basic_machine=powerpc64le-unknown
 		basic_machine=powerpc64le-unknown
-	        ;;
+		;;
 	ppc64le-* | powerpc64little-*)
 	ppc64le-* | powerpc64little-*)
 		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
 		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
 		;;
 		;;
@@ -818,6 +866,16 @@ case $basic_machine in
 		basic_machine=a29k-amd
 		basic_machine=a29k-amd
 		os=-udi
 		os=-udi
 		;;
 		;;
+	sb1)
+		basic_machine=mipsisa64sb1-unknown
+		;;
+	sb1el)
+		basic_machine=mipsisa64sb1el-unknown
+		;;
+	sei)
+		basic_machine=mips-sei
+		os=-seiux
+		;;
 	sequent)
 	sequent)
 		basic_machine=i386-sequent
 		basic_machine=i386-sequent
 		;;
 		;;
@@ -825,6 +883,9 @@ case $basic_machine in
 		basic_machine=sh-hitachi
 		basic_machine=sh-hitachi
 		os=-hms
 		os=-hms
 		;;
 		;;
+	sh64)
+		basic_machine=sh64-unknown
+		;;
 	sparclite-wrs | simso-wrs)
 	sparclite-wrs | simso-wrs)
 		basic_machine=sparclite-wrs
 		basic_machine=sparclite-wrs
 		os=-vxworks
 		os=-vxworks
@@ -883,7 +944,7 @@ case $basic_machine in
 	sun386 | sun386i | roadrunner)
 	sun386 | sun386i | roadrunner)
 		basic_machine=i386-sun
 		basic_machine=i386-sun
 		;;
 		;;
-        sv1)
+	sv1)
 		basic_machine=sv1-cray
 		basic_machine=sv1-cray
 		os=-unicos
 		os=-unicos
 		;;
 		;;
@@ -891,10 +952,6 @@ case $basic_machine in
 		basic_machine=i386-sequent
 		basic_machine=i386-sequent
 		os=-dynix
 		os=-dynix
 		;;
 		;;
-	t3d)
-		basic_machine=alpha-cray
-		os=-unicos
-		;;
 	t3e)
 	t3e)
 		basic_machine=alphaev5-cray
 		basic_machine=alphaev5-cray
 		os=-unicos
 		os=-unicos
@@ -907,6 +964,14 @@ case $basic_machine in
 		basic_machine=tic54x-unknown
 		basic_machine=tic54x-unknown
 		os=-coff
 		os=-coff
 		;;
 		;;
+	tic55x | c55x*)
+		basic_machine=tic55x-unknown
+		os=-coff
+		;;
+	tic6x | c6x*)
+		basic_machine=tic6x-unknown
+		os=-coff
+		;;
 	tx39)
 	tx39)
 		basic_machine=mipstx39-unknown
 		basic_machine=mipstx39-unknown
 		;;
 		;;
@@ -920,6 +985,10 @@ case $basic_machine in
 	tower | tower-32)
 	tower | tower-32)
 		basic_machine=m68k-ncr
 		basic_machine=m68k-ncr
 		;;
 		;;
+	tpf)
+		basic_machine=s390x-ibm
+		os=-tpf
+		;;
 	udi29k)
 	udi29k)
 		basic_machine=a29k-amd
 		basic_machine=a29k-amd
 		os=-udi
 		os=-udi
@@ -941,8 +1010,8 @@ case $basic_machine in
 		os=-vms
 		os=-vms
 		;;
 		;;
 	vpp*|vx|vx-*)
 	vpp*|vx|vx-*)
-               basic_machine=f301-fujitsu
-               ;;
+		basic_machine=f301-fujitsu
+		;;
 	vxworks960)
 	vxworks960)
 		basic_machine=i960-wrs
 		basic_machine=i960-wrs
 		os=-vxworks
 		os=-vxworks
@@ -963,11 +1032,7 @@ case $basic_machine in
 		basic_machine=hppa1.1-winbond
 		basic_machine=hppa1.1-winbond
 		os=-proelf
 		os=-proelf
 		;;
 		;;
-	windows32)
-		basic_machine=i386-pc
-		os=-windows32-msvcrt
-		;;
-        xps | xps100)
+	xps | xps100)
 		basic_machine=xps100-honeywell
 		basic_machine=xps100-honeywell
 		;;
 		;;
 	ymp)
 	ymp)
@@ -1013,16 +1078,19 @@ case $basic_machine in
 	we32k)
 	we32k)
 		basic_machine=we32k-att
 		basic_machine=we32k-att
 		;;
 		;;
-	sh3 | sh4 | sh3eb | sh4eb | sh[1234]le | sh3ele)
+	sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele)
 		basic_machine=sh-unknown
 		basic_machine=sh-unknown
 		;;
 		;;
+	sh5el)
+		basic_machine=sh5le-unknown
+		;;
 	sh64)
 	sh64)
 		basic_machine=sh64-unknown
 		basic_machine=sh64-unknown
 		;;
 		;;
-	sparc | sparcv9 | sparcv9b)
+	sparc | sparcv8 | sparcv9 | sparcv9b)
 		basic_machine=sparc-sun
 		basic_machine=sparc-sun
 		;;
 		;;
-        cydra)
+	cydra)
 		basic_machine=cydra-cydrome
 		basic_machine=cydra-cydrome
 		;;
 		;;
 	orion)
 	orion)
@@ -1037,10 +1105,6 @@ case $basic_machine in
 	pmac | pmac-mpw)
 	pmac | pmac-mpw)
 		basic_machine=powerpc-apple
 		basic_machine=powerpc-apple
 		;;
 		;;
-	c4x*)
-		basic_machine=c4x-none
-		os=-coff
-		;;
 	*-unknown)
 	*-unknown)
 		# Make sure to match an already-canonicalized machine name.
 		# Make sure to match an already-canonicalized machine name.
 		;;
 		;;
@@ -1096,18 +1160,20 @@ case $os in
 	      | -aos* \
 	      | -aos* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
-	      | -hiux* | -386bsd* | -netbsd* | -openbsd* | -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* \
 	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
 	      | -chorusos* | -chorusrdb* \
 	      | -chorusos* | -chorusrdb* \
 	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
 	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
-	      | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \
-	      | -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \
+	      | -mingw32* | -linux-gnu* | -linux-uclibc* | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
 	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
 	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
 	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
 	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
 	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
 	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
-	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* | -powermax*)
+	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly*)
 	# Remember, each alternative MUST END IN *, to match a version number.
 	# Remember, each alternative MUST END IN *, to match a version number.
 		;;
 		;;
 	-qnx*)
 	-qnx*)
@@ -1119,8 +1185,10 @@ case $os in
 			;;
 			;;
 		esac
 		esac
 		;;
 		;;
+	-nto-qnx*)
+		;;
 	-nto*)
 	-nto*)
-		os=-nto-qnx
+		os=`echo $os | sed -e 's|nto|nto-qnx|'`
 		;;
 		;;
 	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
 	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
 	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* \
 	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* \
@@ -1129,6 +1197,9 @@ case $os in
 	-mac*)
 	-mac*)
 		os=`echo $os | sed -e 's|mac|macos|'`
 		os=`echo $os | sed -e 's|mac|macos|'`
 		;;
 		;;
+	-linux-dietlibc)
+		os=-linux-dietlibc
+		;;
 	-linux*)
 	-linux*)
 		os=`echo $os | sed -e 's|linux|linux-gnu|'`
 		os=`echo $os | sed -e 's|linux|linux-gnu|'`
 		;;
 		;;
@@ -1141,6 +1212,9 @@ case $os in
 	-opened*)
 	-opened*)
 		os=-openedition
 		os=-openedition
 		;;
 		;;
+        -os400*)
+		os=-os400
+		;;
 	-wince*)
 	-wince*)
 		os=-wince
 		os=-wince
 		;;
 		;;
@@ -1162,6 +1236,9 @@ case $os in
 	-atheos*)
 	-atheos*)
 		os=-atheos
 		os=-atheos
 		;;
 		;;
+	-syllable*)
+		os=-syllable
+		;;
 	-386bsd)
 	-386bsd)
 		os=-bsd
 		os=-bsd
 		;;
 		;;
@@ -1172,7 +1249,7 @@ case $os in
 		os=-rtmk-nova
 		os=-rtmk-nova
 		;;
 		;;
 	-ns2 )
 	-ns2 )
-	        os=-nextstep2
+		os=-nextstep2
 		;;
 		;;
 	-nsk*)
 	-nsk*)
 		os=-nsk
 		os=-nsk
@@ -1184,6 +1261,9 @@ case $os in
 	-sinix*)
 	-sinix*)
 		os=-sysv4
 		os=-sysv4
 		;;
 		;;
+        -tpf*)
+		os=-tpf
+		;;
 	-triton*)
 	-triton*)
 		os=-sysv3
 		os=-sysv3
 		;;
 		;;
@@ -1211,8 +1291,14 @@ case $os in
 	-xenix)
 	-xenix)
 		os=-xenix
 		os=-xenix
 		;;
 		;;
-        -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
-	        os=-mint
+	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+		os=-mint
+		;;
+	-aros*)
+		os=-aros
+		;;
+	-kaos*)
+		os=-kaos
 		;;
 		;;
 	-none)
 	-none)
 		;;
 		;;
@@ -1245,11 +1331,14 @@ case $basic_machine in
 	arm*-semi)
 	arm*-semi)
 		os=-aout
 		os=-aout
 		;;
 		;;
+    c4x-* | tic4x-*)
+        os=-coff
+        ;;
 	# This must come before the *-dec entry.
 	# This must come before the *-dec entry.
 	pdp10-*)
 	pdp10-*)
 		os=-tops20
 		os=-tops20
 		;;
 		;;
-        pdp11-*)
+	pdp11-*)
 		os=-none
 		os=-none
 		;;
 		;;
 	*-dec | vax-*)
 	*-dec | vax-*)
@@ -1342,19 +1431,19 @@ case $basic_machine in
 	*-next)
 	*-next)
 		os=-nextstep3
 		os=-nextstep3
 		;;
 		;;
-        *-gould)
+	*-gould)
 		os=-sysv
 		os=-sysv
 		;;
 		;;
-        *-highlevel)
+	*-highlevel)
 		os=-bsd
 		os=-bsd
 		;;
 		;;
 	*-encore)
 	*-encore)
 		os=-bsd
 		os=-bsd
 		;;
 		;;
-        *-sgi)
+	*-sgi)
 		os=-irix
 		os=-irix
 		;;
 		;;
-        *-siemens)
+	*-siemens)
 		os=-sysv4
 		os=-sysv4
 		;;
 		;;
 	*-masscomp)
 	*-masscomp)
@@ -1423,9 +1512,15 @@ case $basic_machine in
 			-mvs* | -opened*)
 			-mvs* | -opened*)
 				vendor=ibm
 				vendor=ibm
 				;;
 				;;
+			-os400*)
+				vendor=ibm
+				;;
 			-ptx*)
 			-ptx*)
 				vendor=sequent
 				vendor=sequent
 				;;
 				;;
+			-tpf*)
+				vendor=ibm
+				;;
 			-vxsim* | -vxworks* | -windiss*)
 			-vxsim* | -vxworks* | -windiss*)
 				vendor=wrs
 				vendor=wrs
 				;;
 				;;

+ 5 - 899
configure

@@ -1808,7 +1808,7 @@ fi
 
 
 # Define the identity of the package.
 # Define the identity of the package.
  PACKAGE=file
  PACKAGE=file
- VERSION=4.17
+ VERSION=4.19
 
 
 
 
 cat >>confdefs.h <<_ACEOF
 cat >>confdefs.h <<_ACEOF
@@ -20514,159 +20514,11 @@ done
 
 
 
 
 
 
-for ac_header in fcntl.h locale.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
-  # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
-else
-  ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
-    (
-      cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists.  ##
-## ------------------------------------------ ##
-_ASBOX
-    ) |
-      sed "s/^/$as_me: WARNING:     /" >&2
-    ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
 
 
 
 
 
 
 
 
-for ac_header in sys/mman.h sys/stat.h sys/types.h
+for ac_header in fcntl.h locale.h stdint.h inttypes.h unistd.h getopt.h
 do
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 if eval "test \"\${$as_ac_Header+set}\" = set"; then
 if eval "test \"\${$as_ac_Header+set}\" = set"; then
@@ -20817,7 +20669,8 @@ done
 
 
 
 
 
 
-for ac_header in stdint.h inttypes.h
+
+for ac_header in utime.h wchar.h wctype.h
 do
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 if eval "test \"\${$as_ac_Header+set}\" = set"; then
 if eval "test \"\${$as_ac_Header+set}\" = set"; then
@@ -20967,757 +20820,10 @@ fi
 done
 done
 
 
 
 
-for ac_header in unistd.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
-  # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
-else
-  ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
 
 
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
-    (
-      cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists.  ##
-## ------------------------------------------ ##
-_ASBOX
-    ) |
-      sed "s/^/$as_me: WARNING:     /" >&2
-    ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-
-
-for ac_header in getopt.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
-  # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
-else
-  ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
-    (
-      cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists.  ##
-## ------------------------------------------ ##
-_ASBOX
-    ) |
-      sed "s/^/$as_me: WARNING:     /" >&2
-    ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-
-
-for ac_header in locale.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
-  # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
-else
-  ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
-    (
-      cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists.  ##
-## ------------------------------------------ ##
-_ASBOX
-    ) |
-      sed "s/^/$as_me: WARNING:     /" >&2
-    ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-
-
-for ac_header in utime.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
-  # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
-else
-  ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
-    (
-      cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists.  ##
-## ------------------------------------------ ##
-_ASBOX
-    ) |
-      sed "s/^/$as_me: WARNING:     /" >&2
-    ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-
-
-for ac_header in sys/utime.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
-  # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-	 { ac_try='test -z "$ac_c_werror_flag"
-			 || test ! -s conftest.err'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  ac_header_compiler=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
-  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } >/dev/null; then
-  if test -s conftest.err; then
-    ac_cpp_err=$ac_c_preproc_warn_flag
-    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
-  else
-    ac_cpp_err=
-  fi
-else
-  ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
-  ac_header_preproc=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-  ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So?  What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
-  yes:no: )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
-    ac_header_preproc=yes
-    ;;
-  no:yes:* )
-    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
-    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
-    (
-      cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists.  ##
-## ------------------------------------------ ##
-_ASBOX
-    ) |
-      sed "s/^/$as_me: WARNING:     /" >&2
-    ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
-  cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
 
 
 
 
-for ac_header in wchar.h
+for ac_header in sys/mman.h sys/stat.h sys/types.h sys/utime.h
 do
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 if eval "test \"\${$as_ac_Header+set}\" = set"; then
 if eval "test \"\${$as_ac_Header+set}\" = set"; then

+ 4 - 10
configure.in

@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 dnl Process this file with autoconf to produce a configure script.
 AC_INIT
 AC_INIT
 AC_CONFIG_SRCDIR([src/file.c])
 AC_CONFIG_SRCDIR([src/file.c])
-AM_INIT_AUTOMAKE(file, 4.17)
+AM_INIT_AUTOMAKE(file, 4.19)
 AM_CONFIG_HEADER([config.h])
 AM_CONFIG_HEADER([config.h])
 AM_MAINTAINER_MODE
 AM_MAINTAINER_MODE
 
 
@@ -79,15 +79,9 @@ AC_HEADER_STDC
 AC_HEADER_MAJOR
 AC_HEADER_MAJOR
 AC_HEADER_SYS_WAIT
 AC_HEADER_SYS_WAIT
 AC_HEADER_STDINT
 AC_HEADER_STDINT
-AC_CHECK_HEADERS(fcntl.h locale.h)
-AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h)
-AC_CHECK_HEADERS(stdint.h inttypes.h)
-AC_CHECK_HEADERS(unistd.h)
-AC_CHECK_HEADERS(getopt.h)
-AC_CHECK_HEADERS(locale.h)
-AC_CHECK_HEADERS(utime.h)
-AC_CHECK_HEADERS(sys/utime.h)
-AC_CHECK_HEADERS(wchar.h)
+AC_CHECK_HEADERS(fcntl.h locale.h stdint.h inttypes.h unistd.h getopt.h)
+AC_CHECK_HEADERS(utime.h wchar.h wctype.h)
+AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h)
 
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
 AC_C_CONST

+ 149 - 42
depcomp

@@ -1,7 +1,9 @@
 #! /bin/sh
 #! /bin/sh
-
 # depcomp - compile a program generating dependencies as side-effects
 # depcomp - compile a program generating dependencies as side-effects
-# Copyright 1999, 2000 Free Software Foundation, Inc.
+
+scriptversion=2005-07-09.11
+
+# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
 
 
 # This program is free software; you can redistribute it and/or modify
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
@@ -15,8 +17,8 @@
 
 
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
 
 
 # As a special exception to the GNU General Public License, if you
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # distribute this file as part of a program that contains a
@@ -25,22 +27,45 @@
 
 
 # Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
 # Originally written by Alexandre Oliva <oliva@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@gnu.org>.
+EOF
+    exit $?
+    ;;
+  -v | --v*)
+    echo "depcomp $scriptversion"
+    exit $?
+    ;;
+esac
+
 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
 if test -z "$depmode" || test -z "$source" || test -z "$object"; then
   echo "depcomp: Variables source, object and depmode must be set" 1>&2
   echo "depcomp: Variables source, object and depmode must be set" 1>&2
   exit 1
   exit 1
 fi
 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/'`}
 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
 
 
 rm -f "$tmpdepfile"
 rm -f "$tmpdepfile"
@@ -172,19 +197,25 @@ sgi)
 
 
 aix)
 aix)
   # The C for AIX Compiler uses -M and outputs the dependencies
   # 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"
   tmpdepfile="$stripped.u"
-  outname="$stripped.o"
   if test "$libtool" = yes; then
   if test "$libtool" = yes; then
     "$@" -Wc,-M
     "$@" -Wc,-M
   else
   else
     "$@" -M
     "$@" -M
   fi
   fi
-
   stat=$?
   stat=$?
+
+  if test -f "$tmpdepfile"; then :
+  else
+    stripped=`echo "$stripped" | sed 's,^.*/,,'`
+    tmpdepfile="$stripped.u"
+  fi
+
   if test $stat -eq 0; then :
   if test $stat -eq 0; then :
   else
   else
     rm -f "$tmpdepfile"
     rm -f "$tmpdepfile"
@@ -192,6 +223,7 @@ aix)
   fi
   fi
 
 
   if test -f "$tmpdepfile"; then
   if test -f "$tmpdepfile"; then
+    outname="$stripped.o"
     # Each line is of the form `foo.o: dependent.h'.
     # Each line is of the form `foo.o: dependent.h'.
     # Do two passes, one to just change these to
     # Do two passes, one to just change these to
     # `$object: dependent.h' and one to simply `dependent.h:'.
     # `$object: dependent.h' and one to simply `dependent.h:'.
@@ -206,6 +238,44 @@ aix)
   rm -f "$tmpdepfile"
   rm -f "$tmpdepfile"
   ;;
   ;;
 
 
+icc)
+  # Intel's C compiler understands `-MD -MF file'.  However on
+  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
+  # ICC 7.0 will fill foo.d with something like
+  #    foo.o: sub/foo.c
+  #    foo.o: sub/foo.h
+  # which is wrong.  We want:
+  #    sub/foo.o: sub/foo.c
+  #    sub/foo.o: sub/foo.h
+  #    sub/foo.c:
+  #    sub/foo.h:
+  # ICC 7.1 will output
+  #    foo.o: sub/foo.c sub/foo.h
+  # and will wrap long lines using \ :
+  #    foo.o: sub/foo.c ... \
+  #     sub/foo.h ... \
+  #     ...
+
+  "$@" -MD -MF "$tmpdepfile"
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+    rm -f "$tmpdepfile"
+    exit $stat
+  fi
+  rm -f "$depfile"
+  # Each line is of the form `foo.o: dependent.h',
+  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
+  # Do two passes, one to just change these to
+  # `$object: dependent.h' and one to simply `dependent.h:'.
+  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
+  # Some versions of the HPUX 10.20 sed can't process this invocation
+  # correctly.  Breaking it into two sed invocations is a workaround.
+  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
+    sed -e 's/$/ :/' >> "$depfile"
+  rm -f "$tmpdepfile"
+  ;;
+
 tru64)
 tru64)
    # The Tru64 compiler uses -MD to generate dependencies as a side
    # The Tru64 compiler uses -MD to generate dependencies as a side
    # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
    # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
@@ -217,31 +287,47 @@ tru64)
    base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
    base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
 
 
    if test "$libtool" = yes; then
    if test "$libtool" = yes; then
-      tmpdepfile1="$dir.libs/$base.lo.d"
-      tmpdepfile2="$dir.libs/$base.d"
+      # With Tru64 cc, shared objects can also be used to make a
+      # static library.  This mecanism is used in libtool 1.4 series to
+      # handle both shared and static libraries in a single compilation.
+      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
+      #
+      # With libtool 1.5 this exception was removed, and libtool now
+      # generates 2 separate objects for the 2 libraries.  These two
+      # compilations output dependencies in in $dir.libs/$base.o.d and
+      # in $dir$base.o.d.  We have to check for both files, because
+      # one of the two compilations can be disabled.  We should prefer
+      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+      # automatically cleaned when .libs/ is deleted, while ignoring
+      # the former would cause a distcleancheck panic.
+      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
+      tmpdepfile2=$dir$base.o.d          # libtool 1.5
+      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
+      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
       "$@" -Wc,-MD
       "$@" -Wc,-MD
    else
    else
-      tmpdepfile1="$dir$base.o.d"
-      tmpdepfile2="$dir$base.d"
+      tmpdepfile1=$dir$base.o.d
+      tmpdepfile2=$dir$base.d
+      tmpdepfile3=$dir$base.d
+      tmpdepfile4=$dir$base.d
       "$@" -MD
       "$@" -MD
    fi
    fi
 
 
    stat=$?
    stat=$?
    if test $stat -eq 0; then :
    if test $stat -eq 0; then :
    else
    else
-      rm -f "$tmpdepfile1" "$tmpdepfile2"
+      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
       exit $stat
       exit $stat
    fi
    fi
 
 
-   if test -f "$tmpdepfile1"; then
-      tmpdepfile="$tmpdepfile1"
-   else
-      tmpdepfile="$tmpdepfile2"
-   fi
+   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+   do
+     test -f "$tmpdepfile" && break
+   done
    if test -f "$tmpdepfile"; then
    if test -f "$tmpdepfile"; then
       sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
       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
    else
       echo "#dummy" > "$depfile"
       echo "#dummy" > "$depfile"
    fi
    fi
@@ -254,7 +340,7 @@ tru64)
 
 
 dashmstdout)
 dashmstdout)
   # Important note: in order to support this mode, a compiler *must*
   # 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 $?
   "$@" || exit $?
 
 
   # Remove the call to Libtool.
   # Remove the call to Libtool.
@@ -265,9 +351,7 @@ dashmstdout)
     shift
     shift
   fi
   fi
 
 
-  # Remove `-o $object'.  We will use -o /dev/null later,
-  # however we can't do the remplacement now because
-  # `-o $object' might simply not be used
+  # Remove `-o $object'.
   IFS=" "
   IFS=" "
   for arg
   for arg
   do
   do
@@ -287,7 +371,11 @@ dashmstdout)
   done
   done
 
 
   test -z "$dashmflag" && dashmflag=-M
   test -z "$dashmflag" && dashmflag=-M
-  "$@" -o /dev/null $dashmflag | sed 's:^[^:]*\:[ 	]*:'"$object"'\: :' > "$tmpdepfile"
+  # Require at least two characters before searching for `:'
+  # in the target name.  This is to cope with DOS-style filenames:
+  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
+  "$@" $dashmflag |
+    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
   rm -f "$depfile"
   rm -f "$depfile"
   cat < "$tmpdepfile" > "$depfile"
   cat < "$tmpdepfile" > "$depfile"
   tr ' ' '
   tr ' ' '
@@ -306,6 +394,13 @@ dashXmstdout)
 
 
 makedepend)
 makedepend)
   "$@" || exit $?
   "$@" || exit $?
+  # Remove any Libtool call
+  if test "$libtool" = yes; then
+    while test $1 != '--mode=compile'; do
+      shift
+    done
+    shift
+  fi
   # X makedepend
   # X makedepend
   shift
   shift
   cleared=no
   cleared=no
@@ -318,7 +413,9 @@ makedepend)
     case "$arg" in
     case "$arg" in
     -D*|-I*)
     -D*|-I*)
       set fnord "$@" "$arg"; shift ;;
       set fnord "$@" "$arg"; shift ;;
-    -*)
+    # Strip any option that makedepend may not understand.  Remove
+    # the object too, otherwise makedepend will parse it as a source file.
+    -*|$object)
       ;;
       ;;
     *)
     *)
       set fnord "$@" "$arg"; shift ;;
       set fnord "$@" "$arg"; shift ;;
@@ -339,7 +436,7 @@ makedepend)
 
 
 cpp)
 cpp)
   # Important note: in order to support this mode, a compiler *must*
   # 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 $?
   "$@" || exit $?
 
 
   # Remove the call to Libtool.
   # Remove the call to Libtool.
@@ -370,7 +467,8 @@ cpp)
   done
   done
 
 
   "$@" -E |
   "$@" -E |
-    sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
+    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
     sed '$ s: \\$::' > "$tmpdepfile"
     sed '$ s: \\$::' > "$tmpdepfile"
   rm -f "$depfile"
   rm -f "$depfile"
   echo "$object : \\" > "$depfile"
   echo "$object : \\" > "$depfile"
@@ -381,7 +479,7 @@ cpp)
 
 
 msvisualcpp)
 msvisualcpp)
   # Important note: in order to support this mode, a compiler *must*
   # 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.
   # because we must use -o when running libtool.
   "$@" || exit $?
   "$@" || exit $?
   IFS=" "
   IFS=" "
@@ -421,3 +519,12 @@ none)
 esac
 esac
 
 
 exit 0
 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:

+ 10 - 5
doc/file.man

@@ -1,5 +1,5 @@
 .TH FILE __CSECTION__ "Copyright but distributable"
 .TH FILE __CSECTION__ "Copyright but distributable"
-.\" $Id: file.man,v 1.57 2005/08/18 15:18:22 christos Exp $
+.\" $Id: file.man,v 1.59 2006/11/17 16:11:10 christos Exp $
 .SH NAME
 .SH NAME
 file
 file
 \- determine file type
 \- determine file type
@@ -200,7 +200,7 @@ traditional human readable ones. Thus it may say
 rather
 rather
 than ``ASCII text''.
 than ``ASCII text''.
 In order for this option to work, file changes the way
 In order for this option to work, file changes the way
-it handles files recognised by the command itself (such as many of the
+it handles files recognized by the command itself (such as many of the
 text file types, directories etc), and makes use of an alternative
 text file types, directories etc), and makes use of an alternative
 ``magic'' file.
 ``magic'' file.
 (See ``FILES'' section, below).
 (See ``FILES'' section, below).
@@ -271,6 +271,10 @@ Print the version of the program and exit.
 .TP 8
 .TP 8
 .B "\-z, \-\-uncompress"
 .B "\-z, \-\-uncompress"
 Try to look inside compressed files.
 Try to look inside compressed files.
+.B "\-0, \-\-print0"
+Output a null character ('\0') after the end of the filename. Nice to
+.BR cut (1)
+the output. This does not affect the separator which is still printed.
 .TP 8
 .TP 8
 .B "\-\-help"
 .B "\-\-help"
 Print a help message and exit.
 Print a help message and exit.
@@ -322,9 +326,10 @@ options.
 This program is believed to exceed the System V Interface Definition
 This program is believed to exceed the System V Interface Definition
 of FILE(CMD), as near as one can determine from the vague language
 of FILE(CMD), as near as one can determine from the vague language
 contained therein. 
 contained therein. 
-Its behaviour is mostly compatible with the System V program of the same name.
+Its behavior is mostly compatible with the System V program of the same name.
 This version knows more magic, however, so it will produce
 This version knows more magic, however, so it will produce
 different (albeit more accurate) output in many cases. 
 different (albeit more accurate) output in many cases. 
+.\" URL: http://www.opengroup.org/onlinepubs/009695399/utilities/file.html
 .PP
 .PP
 The one significant difference 
 The one significant difference 
 between this version and System V
 between this version and System V
@@ -456,7 +461,7 @@ were written by John Gilmore from his public-domain
 program, and are not covered by the above license.
 program, and are not covered by the above license.
 .SH BUGS
 .SH BUGS
 There must be a better way to automate the construction of the Magic
 There must be a better way to automate the construction of the Magic
-file from all the glop in magdir.
+file from all the glop in Magdir.
 What is it?
 What is it?
 Better yet, the magic file should be compiled into binary (say,
 Better yet, the magic file should be compiled into binary (say,
 .BR ndbm (3)
 .BR ndbm (3)
@@ -501,7 +506,7 @@ The list of keywords in
 probably belongs in the Magic file.
 probably belongs in the Magic file.
 This could be done by using some keyword like `*' for the offset value.
 This could be done by using some keyword like `*' for the offset value.
 .PP
 .PP
-Another optimisation would be to sort
+Another optimization would be to sort
 the magic file so that we can just run down all the
 the magic file so that we can just run down all the
 tests for the first byte, first word, first long, etc, once we
 tests for the first byte, first word, first long, etc, once we
 have fetched it.
 have fetched it.

+ 3 - 3
doc/libmagic.man

@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\" SUCH DAMAGE.
 .\"
 .\"
-.Dd March 22, 2003
+.Dd November 15, 2006
 .Dt MAGIC 3
 .Dt MAGIC 3
 .Os
 .Os
 .Sh NAME
 .Sh NAME
@@ -119,8 +119,8 @@ no error.
 .Pp
 .Pp
 The
 The
 .Fn magic_errno
 .Fn magic_errno
-function returns the last operating system error number (
-.Xr errno 3 )
+function returns the last operating system error number
+.Pq .Xr errno 2
 that was encountered by a system call.
 that was encountered by a system call.
 .Pp
 .Pp
 The
 The

+ 29 - 4
doc/magic.man

@@ -38,6 +38,8 @@ A one-byte value.
 A two-byte value (on most systems) in this machine's native byte order.
 A two-byte value (on most systems) in this machine's native byte order.
 .IP long
 .IP long
 A four-byte value (on most systems) in this machine's native byte order.
 A four-byte value (on most systems) in this machine's native byte order.
+.IP quad
+An eight-byte value (on most systems) in this machine's native byte order.
 .IP string
 .IP string
 A string of bytes.
 A string of bytes.
 The string type specification can be optionally followed
 The string type specification can be optionally followed
@@ -59,33 +61,56 @@ A pascal style string where the first byte is interpreted as the an
 unsigned length. The string is not NUL terminated.
 unsigned length. The string is not NUL terminated.
 .IP date
 .IP date
 A four-byte value interpreted as a UNIX date.
 A four-byte value interpreted as a UNIX date.
+.IP qdate
+A eight-byte value interpreted as a UNIX date.
 .IP ldate
 .IP ldate
 A four-byte value interpreted as a UNIX-style date, but interpreted as
 A four-byte value interpreted as a UNIX-style date, but interpreted as
 local time rather than UTC.
 local time rather than UTC.
+.IP qldate
+An eight-byte value interpreted as a UNIX-style date, but interpreted as
+local time rather than UTC.
 .IP beshort
 .IP beshort
 A two-byte value (on most systems) in big-endian byte order.
 A two-byte value (on most systems) in big-endian byte order.
 .IP belong
 .IP belong
 A four-byte value (on most systems) in big-endian byte order.
 A four-byte value (on most systems) in big-endian byte order.
+.IP bequad
+An eight-byte value (on most systems) in big-endian byte order.
 .IP bedate
 .IP bedate
 A four-byte value (on most systems) in big-endian byte order,
 A four-byte value (on most systems) in big-endian byte order,
 interpreted as a Unix date.
 interpreted as a Unix date.
+.IP beqdate
+An eight-byte value (on most systems) in big-endian byte order,
+interpreted as a Unix date.
 .IP beldate
 .IP beldate
 A four-byte value (on most systems) in big-endian byte order,
 A four-byte value (on most systems) in big-endian byte order,
 interpreted as a UNIX-style date, but interpreted as local time rather
 interpreted as a UNIX-style date, but interpreted as local time rather
 than UTC.
 than UTC.
+.IP beqldate
+An eight-byte value (on most systems) in big-endian byte order,
+interpreted as a UNIX-style date, but interpreted as local time rather
+than UTC.
 .IP bestring16
 .IP bestring16
 A two-byte unicode (UCS16) string in big-endian byte order.
 A two-byte unicode (UCS16) string in big-endian byte order.
 .IP leshort
 .IP leshort
 A two-byte value (on most systems) in little-endian byte order.
 A two-byte value (on most systems) in little-endian byte order.
 .IP lelong
 .IP lelong
 A four-byte value (on most systems) in little-endian byte order.
 A four-byte value (on most systems) in little-endian byte order.
+.IP lequad
+An eight-byte value (on most systems) in little-endian byte order.
 .IP ledate
 .IP ledate
 A four-byte value (on most systems) in little-endian byte order,
 A four-byte value (on most systems) in little-endian byte order,
 interpreted as a UNIX date.
 interpreted as a UNIX date.
+.IP leqdate
+An eight-byte value (on most systems) in little-endian byte order,
+interpreted as a UNIX date.
 .IP leldate
 .IP leldate
 A four-byte value (on most systems) in little-endian byte order,
 A four-byte value (on most systems) in little-endian byte order,
 interpreted as a UNIX-style date, but interpreted as local time rather
 interpreted as a UNIX-style date, but interpreted as local time rather
 than UTC.
 than UTC.
+.IP leqldate
+An eight-byte value (on most systems) in little-endian byte order,
+interpreted as a UNIX-style date, but interpreted as local time rather
+than UTC.
 .IP lestring16
 .IP lestring16
 A two-byte unicode (UCS16) string in little-endian byte order.
 A two-byte unicode (UCS16) string in little-endian byte order.
 .IP melong
 .IP melong
@@ -297,7 +322,7 @@ the value read from the file before it is used as an offset:
 .PP
 .PP
 Sometimes you do not know the exact offset as this depends on the length or
 Sometimes you do not know the exact offset as this depends on the length or
 position (when indirection was used before) of preceding fields. You can
 position (when indirection was used before) of preceding fields. You can
-specify an offset relative to the end of the last uplevel field using
+specify an offset relative to the end of the last up-level field using
 .BI &
 .BI &
 as a prefix to the offset:
 as a prefix to the offset:
 .sp
 .sp
@@ -329,7 +354,7 @@ Or the other way around:
     >0x18             leshort >0x3f
     >0x18             leshort >0x3f
     >>(0x3c.l)        string  LE\e0\e0  LE executable (MS-Windows)
     >>(0x3c.l)        string  LE\e0\e0  LE executable (MS-Windows)
     # at offset 0x80 (-4, since relative offsets start at the end
     # at offset 0x80 (-4, since relative offsets start at the end
-    # of the uplevel match) inside the LE header, we find the absolute
+    # of the up-level match) inside the LE header, we find the absolute
     # offset to the code area, where we look for a specific signature
     # offset to the code area, where we look for a specific signature
     >>>(&0x7c.l+0x26) string  UPX     \eb, UPX compressed
     >>>(&0x7c.l+0x26) string  UPX     \eb, UPX compressed
 .fi
 .fi
@@ -346,7 +371,7 @@ Or even both!
 .fi
 .fi
 .PP
 .PP
 Finally, if you have to deal with offset/length pairs in your file, even the
 Finally, if you have to deal with offset/length pairs in your file, even the
-second value in a parenthesed expression can be taken from the file itself,
+second value in a parenthesized expression can be taken from the file itself,
 using another set of parentheses. Note that this additional indirect offset
 using another set of parentheses. Note that this additional indirect offset
 is always relative to the start of the main indirect offset.
 is always relative to the start of the main indirect offset.
 .sp
 .sp
@@ -397,4 +422,4 @@ a system on which the lengths are invariant.
 .\" the changes I posted to the S5R2 version.
 .\" the changes I posted to the S5R2 version.
 .\"
 .\"
 .\" Modified for Ian Darwin's version of the file command.
 .\" Modified for Ian Darwin's version of the file command.
-.\" @(#)$Id: magic.man,v 1.30 2006/02/19 18:16:03 christos Exp $
+.\" @(#)$Id: magic.man,v 1.33 2006/10/31 19:37:16 christos Exp $

+ 284 - 212
install-sh

@@ -1,19 +1,38 @@
 #!/bin/sh
 #!/bin/sh
-#
 # install - install a program, script, or datafile
 # install - install a program, script, or datafile
-# This comes from X11R5 (mit/util/scripts/install.sh).
+
+scriptversion=2005-05-14.22
+
+# 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.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
 #
 #
-# Copyright 1991 by the Massachusetts Institute of Technology
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #
 #
-# Permission to use, copy, modify, distribute, and sell this software and its
-# documentation for any purpose is hereby granted without fee, provided that
-# the above copyright notice appear in all copies and that both that
-# copyright notice and this permission notice appear in supporting
-# documentation, and that the name of M.I.T. not be used in advertising or
-# publicity pertaining to distribution of the software without specific,
-# written prior permission.  M.I.T. makes no representations about the
-# suitability of this software for any purpose.  It is provided "as is"
-# without express or implied warranty.
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
 #
 #
 # Calling this script install-sh is preferred over install.sh, to prevent
 # Calling this script install-sh is preferred over install.sh, to prevent
 # `make' implicit rules from creating a file called install from it
 # `make' implicit rules from creating a file called install from it
@@ -23,13 +42,11 @@
 # from scratch.  It can only install one file at a time, a restriction
 # from scratch.  It can only install one file at a time, a restriction
 # shared with many OS's install programs.
 # shared with many OS's install programs.
 
 
-
 # set DOITPROG to echo to test this script
 # set DOITPROG to echo to test this script
 
 
 # Don't use :- since 4.3BSD and earlier shells don't like it.
 # Don't use :- since 4.3BSD and earlier shells don't like it.
 doit="${DOITPROG-}"
 doit="${DOITPROG-}"
 
 
-
 # put in absolute paths if you don't have them in your path; or use env. vars.
 # put in absolute paths if you don't have them in your path; or use env. vars.
 
 
 mvprog="${MVPROG-mv}"
 mvprog="${MVPROG-mv}"
@@ -41,211 +58,266 @@ stripprog="${STRIPPROG-strip}"
 rmprog="${RMPROG-rm}"
 rmprog="${RMPROG-rm}"
 mkdirprog="${MKDIRPROG-mkdir}"
 mkdirprog="${MKDIRPROG-mkdir}"
 
 
-transformbasename=""
-transform_arg=""
-instcmd="$mvprog"
 chmodcmd="$chmodprog 0755"
 chmodcmd="$chmodprog 0755"
-chowncmd=""
-chgrpcmd=""
-stripcmd=""
+chowncmd=
+chgrpcmd=
+stripcmd=
 rmcmd="$rmprog -f"
 rmcmd="$rmprog -f"
 mvcmd="$mvprog"
 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 "install:	no input file specified"
-	exit 1
-else
-	:
-fi
-
-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 "install:  $src does not exist"
-		exit 1
-	fi
-	
-	if [ x"$dst" = x ]
-	then
-		echo "install:	no destination specified"
-		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=''
-
-while [ $# -ne 0 ] ; do
-	pathcomp="${pathcomp}${1}"
+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 $?;;
+
+    -m) chmodcmd="$chmodprog $2"
+        shift
+        shift
+        continue;;
+
+    -o) chowncmd="$chownprog $2"
+        shift
+        shift
+        continue;;
+
+    -s) stripcmd=$stripprog
+        shift
+        continue;;
+
+    -t) dstarg=$2
 	shift
 	shift
+	shift
+	continue;;
 
 
-	if [ ! -d "${pathcomp}" ] ;
-        then
-		$mkdirprog "${pathcomp}"
-	else
-		:
-	fi
-
-	pathcomp="${pathcomp}/"
+    -T) no_target_directory=true
+	shift
+	continue;;
+
+    --version) echo "$0 $scriptversion"; exit $?;;
+
+    *)  # 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
 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 temp file name in the proper directory.
-
-	dsttmp=$dstdir/#inst.$$#
 
 
-# Move or copy the file name to the temp name
-
-	$doit $instcmd $src $dsttmp &&
-
-	trap "rm -f ${dsttmp}" 0 &&
-
-# 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 rename the file to the real destination.
-
-	$doit $rmcmd -f $dstdir/$dstfile &&
-	$doit $mvcmd $dsttmp $dstdir/$dstfile 
+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
 
 
-fi &&
+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
 
 
+    # 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 1
+	       }
+	     else
+	       :
+	     fi
+	   } &&
+
+	   # Now rename the file to the real destination.
+	   $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
+	 }
+    }
+  fi || { (exit 1); exit 1; }
+done
 
 
-exit 0
+# The final little trick to "correctly" pass the exit status to the exit trap.
+{
+  (exit 0); 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:

File diff suppressed because it is too large
+ 0 - 2797
ltconfig


+ 32 - 0
ltmain.sh

@@ -1576,6 +1576,12 @@ EOF
 	compiler_flags="$compiler_flags $arg"
 	compiler_flags="$compiler_flags $arg"
 	compile_command="$compile_command $arg"
 	compile_command="$compile_command $arg"
 	finalize_command="$finalize_command $arg"
 	finalize_command="$finalize_command $arg"
+	case $host:$arg in
+	*-*-dragonfly*:-pthread)
+	  # pkgsrc hack to use -pthread in .la file for final linking
+	  deplibs="$deplibs $arg"
+	  ;;
+	esac
 	continue
 	continue
 	;;
 	;;
 
 
@@ -2066,6 +2072,30 @@ EOF
 	  else
 	  else
 	    compiler_flags="$compiler_flags $deplib"
 	    compiler_flags="$compiler_flags $deplib"
 	  fi
 	  fi
+	  case $host:$deplib in
+	  *-*-dragonfly*:-pthread)
+	    # pkgsrc hack to use -pthread in .la file for final linking
+	    case $linkmode in
+	    lib)
+	      deplibs="$deplib $deplibs"
+	      test "$pass" = conv && continue
+	      newdependency_libs="$deplib $newdependency_libs"
+	      ;;
+	    prog)
+	      if test "$pass" = conv; then
+		deplibs="$deplib $deplibs"
+		continue
+	      fi
+	      if test "$pass" = scan; then
+		deplibs="$deplib $deplibs"
+	      else
+		compile_deplibs="$deplib $compile_deplibs"
+		finalize_deplibs="$deplib $finalize_deplibs"
+	      fi
+	      ;;
+	    esac
+	    ;;
+	  esac
 	  continue
 	  continue
 	  ;;
 	  ;;
 	-l*)
 	-l*)
@@ -3206,6 +3236,7 @@ EOF
 	# Calculate the version variables.
 	# Calculate the version variables.
 	major=
 	major=
 	versuffix=
 	versuffix=
+	versuffix2=
 	verstring=
 	verstring=
 	case $version_type in
 	case $version_type in
 	none) ;;
 	none) ;;
@@ -3318,6 +3349,7 @@ EOF
 	if test "$avoid_version" = yes && test "$need_version" = no; then
 	if test "$avoid_version" = yes && test "$need_version" = no; then
 	  major=
 	  major=
 	  versuffix=
 	  versuffix=
+	  versuffix2=
 	  verstring=""
 	  verstring=""
 	fi
 	fi
 
 

+ 23 - 0
magic/Magdir/archive

@@ -509,6 +509,12 @@
 # RAR archiver (Greg Roelofs, newt@uchicago.edu)
 # RAR archiver (Greg Roelofs, newt@uchicago.edu)
 0	string		Rar!		RAR archive data,
 0	string		Rar!		RAR archive data,
 >44	byte		x		v%0x,
 >44	byte		x		v%0x,
+>10	byte		>0		flags:
+>>10	byte		&0x01		Archive volume,
+>>10	byte		&0x02		Commented,
+>>10	byte		&0x04		Locked,
+>>10	byte		&0x08		Solid,
+>>10	byte		&0x20		Authenticated,
 >35	byte		0		os: MS-DOS
 >35	byte		0		os: MS-DOS
 >35	byte		1		os: OS/2
 >35	byte		1		os: OS/2
 >35	byte		2		os: Win32
 >35	byte		2		os: Win32
@@ -530,6 +536,8 @@
 >4	byte		0x0b		Zip archive data, at least v1.1 to extract
 >4	byte		0x0b		Zip archive data, at least v1.1 to extract
 >4	byte		0x14
 >4	byte		0x14
 >>30	ubelong		!0x6d696d65	Zip archive data, at least v2.0 to extract
 >>30	ubelong		!0x6d696d65	Zip archive data, at least v2.0 to extract
+>0x161	string		WINZIP          Zip archive data, WinZIP self-extracting
+
 
 
 # OpenOffice.org / KOffice / StarOffice documents
 # OpenOffice.org / KOffice / StarOffice documents
 # From: Abel Cheung <abel@oaka.org>
 # From: Abel Cheung <abel@oaka.org>
@@ -700,3 +708,18 @@
 # EET archive
 # EET archive
 # From: Tilman Sauerbeck <tilman@code-monkey.de>
 # From: Tilman Sauerbeck <tilman@code-monkey.de>
 0	belong	0x1ee7ff00	EET archive
 0	belong	0x1ee7ff00	EET archive
+
+# rzip archives
+0	string	RZIP		rzip compressed data
+>4	byte	x		- version %d
+>5	byte	x		\b.%d
+>6	belong	x		(%d bytes)
+
+# From: "Robert Dale" <robdale@gmail.com>
+0	belong	123		dar archive,
+>4	belong	x		label "%.8x
+>>8	belong	x		%.8x
+>>>12	beshort	x		%.4x"
+>14	byte	0x54		end slice
+>14	beshort	0x4e4e		multi-part
+>14	beshort	0x4e53		multi-part, with -S

+ 73 - 7
magic/Magdir/audio

@@ -25,7 +25,7 @@
 >12	belong		19		16-bit linear compressed,
 >12	belong		19		16-bit linear compressed,
 >12	belong		20		16-bit linear with emphasis and compression,
 >12	belong		20		16-bit linear with emphasis and compression,
 >12	belong		21		Music kit DSP commands,
 >12	belong		21		Music kit DSP commands,
->12	belong		23		8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice data encoding),
+>12	belong		23		8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice enc.),
 >12	belong		24		compressed (8-bit CCITT G.722 ADPCM)
 >12	belong		24		compressed (8-bit CCITT G.722 ADPCM)
 >12	belong		25		compressed (3-bit CCITT G.723.3 ADPCM),
 >12	belong		25		compressed (3-bit CCITT G.723.3 ADPCM),
 >12	belong		26		compressed (5-bit CCITT G.723.5 ADPCM),
 >12	belong		26		compressed (5-bit CCITT G.723.5 ADPCM),
@@ -55,7 +55,7 @@
 >12	belong		19		16-bit linear compressed,
 >12	belong		19		16-bit linear compressed,
 >12	belong		20		16-bit linear with emphasis and compression,
 >12	belong		20		16-bit linear with emphasis and compression,
 >12	belong		21		Music kit DSP commands,
 >12	belong		21		Music kit DSP commands,
->12	lelong		23		8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice data encoding),
+>12	lelong		23		8-bit ISDN mu-law compressed (CCITT G.721 ADPCM voice enc.),
 >12	belong		24		compressed (8-bit CCITT G.722 ADPCM)
 >12	belong		24		compressed (8-bit CCITT G.722 ADPCM)
 >12	belong		25		compressed (3-bit CCITT G.723.3 ADPCM),
 >12	belong		25		compressed (3-bit CCITT G.723.3 ADPCM),
 >12	belong		26		compressed (5-bit CCITT G.723.5 ADPCM),
 >12	belong		26		compressed (5-bit CCITT G.723.5 ADPCM),
@@ -221,9 +221,41 @@
 # SGI SoundTrack <mpruett@sgi.com>
 # SGI SoundTrack <mpruett@sgi.com>
 0	string		_SGI_SoundTrack		SGI SoundTrack project file
 0	string		_SGI_SoundTrack		SGI SoundTrack project file
 # ID3 version 2 tags <waschk@informatik.uni-rostock.de>
 # ID3 version 2 tags <waschk@informatik.uni-rostock.de>
-0	string		ID3	MP3 file with ID3 version 2.
+0	string		ID3	Audio file with ID3 version 2
 >3	ubyte	<0xff	\b%d.
 >3	ubyte	<0xff	\b%d.
 >4	ubyte	<0xff	\b%d tag
 >4	ubyte	<0xff	\b%d tag
+>2584	string	fLaC		\b, FLAC encoding
+>>2588	byte&0x7f		>0		\b, unknown version
+>>2588	byte&0x7f		0		\b
+# some common bits/sample values
+>>>2600	beshort&0x1f0		0x030		\b, 4 bit
+>>>2600	beshort&0x1f0		0x050		\b, 6 bit
+>>>2600	beshort&0x1f0		0x070		\b, 8 bit
+>>>2600	beshort&0x1f0		0x0b0		\b, 12 bit
+>>>2600	beshort&0x1f0		0x0f0		\b, 16 bit
+>>>2600	beshort&0x1f0		0x170		\b, 24 bit
+>>>2600	byte&0xe		0x0		\b, mono
+>>>2600	byte&0xe		0x2		\b, stereo
+>>>2600	byte&0xe		0x4		\b, 3 channels
+>>>2600	byte&0xe		0x6		\b, 4 channels
+>>>2600	byte&0xe		0x8		\b, 5 channels
+>>>2600	byte&0xe		0xa		\b, 6 channels
+>>>2600	byte&0xe		0xc		\b, 7 channels
+>>>2600	byte&0xe		0xe		\b, 8 channels
+# some common sample rates
+>>>2597	belong&0xfffff0		0x0ac440	\b, 44.1 kHz
+>>>2597	belong&0xfffff0		0x0bb800	\b, 48 kHz
+>>>2597	belong&0xfffff0		0x07d000	\b, 32 kHz
+>>>2597	belong&0xfffff0		0x056220	\b, 22.05 kHz
+>>>2597	belong&0xfffff0		0x05dc00	\b, 24 kHz
+>>>2597	belong&0xfffff0		0x03e800	\b, 16 kHz
+>>>2597	belong&0xfffff0		0x02b110	\b, 11.025 kHz
+>>>2597	belong&0xfffff0		0x02ee00	\b, 12 kHz
+>>>2597	belong&0xfffff0		0x01f400	\b, 8 kHz
+>>>2597	belong&0xfffff0		0x177000	\b, 96 kHz
+>>>2597	belong&0xfffff0		0x0fa000	\b, 64 kHz
+>>>2601	byte&0xf		>0		\b, >4G samples
+>2584	string	!fLaC		\b, MP3 encoding
 
 
 # NSF (NES sound file) magic
 # NSF (NES sound file) magic
 0	string		NESM\x1a	NES Sound File
 0	string		NESM\x1a	NES Sound File
@@ -443,10 +475,6 @@
 # From: Emanuel Haupt <ehaupt@critical.ch>
 # From: Emanuel Haupt <ehaupt@critical.ch>
 0	string		ZXAYEMUL	Spectrum 128 tune
 0	string		ZXAYEMUL	Spectrum 128 tune
 
 
-# From: Alex Beregszaszi <alex@fsn.hu>
-0	string		MP+		Musepack
->3	byte&0x0f	x		SV%d
-
 0	string		\0BONK		BONK,
 0	string		\0BONK		BONK,
 #>5	byte		x		version %d
 #>5	byte		x		version %d
 >14	byte		x		%d channel(s),
 >14	byte		x		%d channel(s),
@@ -479,3 +507,41 @@
 0	string	\[playlist\]	PLS playlist
 0	string	\[playlist\]	PLS playlist
 # licq.conf
 # licq.conf
 1	string	\[licq\]	LICQ configuration file
 1	string	\[licq\]	LICQ configuration file
+
+# Atari ST audio files by Dirk Jagdmann <doj@cubic.org>
+0	string		ICE!		SNDH Atari ST music
+0	string		SC68\ Music-file\ /\ (c)\ (BeN)jami	sc68 Atari ST music
+
+# musepak support From: "Jiri Pejchal" <jiri.pejchal@gmail.com>
+0       string          MP+     Musepack audio
+>3      byte            255     \b, SV pre8
+>3      byte&0xF        0x6     \b, SV 6
+>3      byte&0xF        0x8     \b, SV 8
+>3      byte&0xF        0x7     \b, SV 7
+>>3     byte&0xF0       0x0     \b.0
+>>3     byte&0xF0       0x10    \b.1
+>>3     byte&0xF0       240     \b.15
+>>10    byte&0xF0       0x0     \b, no profile
+>>10    byte&0xF0       0x10    \b, profile 'Unstable/Experimental'
+>>10    byte&0xF0       0x50    \b, quality 0
+>>10    byte&0xF0       0x60    \b, quality 1
+>>10    byte&0xF0       0x70    \b, quality 2 (Telephone)
+>>10    byte&0xF0       0x80    \b, quality 3 (Thumb)
+>>10    byte&0xF0       0x90    \b, quality 4 (Radio)
+>>10    byte&0xF0       0xA0    \b, quality 5 (Standard)
+>>10    byte&0xF0       0xB0    \b, quality 6 (Xtreme)
+>>10    byte&0xF0       0xC0    \b, quality 7 (Insane)
+>>10    byte&0xF0       0xD0    \b, quality 8 (BrainDead)
+>>10    byte&0xF0       0xE0    \b, quality 9
+>>10    byte&0xF0       0xF0    \b, quality 10
+>>27    byte            0x0     \b, Buschmann 1.7.0-9, Klemm 0.90-1.05
+>>27    byte            102     \b, Beta 1.02
+>>27    byte            104     \b, Beta 1.04
+>>27    byte            105     \b, Alpha 1.05
+>>27    byte            106     \b, Beta 1.06
+>>27    byte            110     \b, Release 1.1
+>>27    byte            111     \b, Alpha 1.11
+>>27    byte            112     \b, Beta 1.12
+>>27    byte            113     \b, Alpha 1.13
+>>27    byte            114     \b, Beta 1.14
+>>27    byte            115     \b, Alpha 1.15

+ 15 - 0
magic/Magdir/cad

@@ -35,6 +35,7 @@
 >>30	string	\120\104			DGNFile
 >>30	string	\120\104			DGNFile
 >>30	string	\172\104			DGNFile
 >>30	string	\172\104			DGNFile
 >>30	string	\172\105			DGNFile
 >>30	string	\172\105			DGNFile
+>>30	string	\172\106			DGNFile
 >>30	string	\234\106			DGNFile
 >>30	string	\234\106			DGNFile
 >>30	string	\273\105			DGNFile
 >>30	string	\273\105			DGNFile
 >>30	string	\306\106			DGNFile
 >>30	string	\306\106			DGNFile
@@ -52,3 +53,17 @@
 0	string AC1012	AutoCad (release 12)
 0	string AC1012	AutoCad (release 12)
 0	string AC1013	AutoCad (release 13)
 0	string AC1013	AutoCad (release 13)
 0	string AC1014	AutoCad (release 14)
 0	string AC1014	AutoCad (release 14)
+
+# CAD: file(1) magic for computer aided design files
+# Phillip Griffith <phillip dot griffith at gmail dot com>
+# AutoCAD magic taken from the Open Design Alliance's OpenDWG specifications.
+#
+0	belong	0x08051700	Bentley/Intergraph MicroStation DGN cell library
+0	belong	0x0809fe02	Bentley/Intergraph MicroStation DGN vector CAD
+0	belong	0xc809fe02	Bentley/Intergraph MicroStation DGN vector CAD
+0	beshort	0x0809		Bentley/Intergraph MicroStation
+>0x02	byte	0xfe
+>>0x04	beshort	0x1800		CIT raster CAD
+0	string	AC1012		AutoDesk AutoCAD R13
+0	string	AC1014		AutoDesk AutoCAD R14 
+0	string	AC1015		AutoDesk AutoCAD R2000

+ 21 - 0
magic/Magdir/cafebabe

@@ -0,0 +1,21 @@
+#------------------------------------------------------------------------------
+# Cafe Babes unite!
+#
+# Since Java bytecode and Mach-O fat-files have the same magic number, the test
+# must be performed in the same "magic" sequence to get both right.  The long
+# at offset 4 in a mach-O fat file tells the number of architectures; the short at
+# offset 4 in a Java bytecode file is the JVM minor version and the
+# short at offset 6 is the JVM major version.  Since there are only 
+# only 18 labeled Mach-O architectures at current, and the first released 
+# Java class format was version 43.0, we can safely choose any number
+# between 18 and 39 to test the number of architectures against
+# (and use as a hack). Let's not use 18, because the Mach-O people
+# might add another one or two as time goes by...
+#
+0	belong		0xcafebabe
+>4	belong		>30		compiled Java class data,
+>>6     beshort		x	        version %d.
+>>4     beshort		x       	\b%d
+>4	belong		1		Mach-O fat file with 1 architecture
+>4	belong		>1
+>>4	belong		<20		Mach-O fat file with %ld architectures

+ 2 - 0
magic/Magdir/commands

@@ -52,3 +52,5 @@
 0	string/b	#!\ /usr/bin/php	PHP script text executable
 0	string/b	#!\ /usr/bin/php	PHP script text executable
 
 
 0	string		Zend\x00		PHP script Zend Optimizer data
 0	string		Zend\x00		PHP script Zend Optimizer data
+
+0	string		\$!			DCL command file

+ 3 - 0
magic/Magdir/editors

@@ -11,3 +11,6 @@
 # Vi IMproved Encrypted file 
 # Vi IMproved Encrypted file 
 # by David Necas <yeti@physics.muni.cz>
 # by David Necas <yeti@physics.muni.cz>
 0	string	VimCrypt~	Vim encrypted file data
 0	string	VimCrypt~	Vim encrypted file data
+# Vi IMproved Swap file
+# by Sven Wegener <swegener@gentoo.org>
+0	string	b0VIM\		Vim swap file, version %s

+ 16 - 11
magic/Magdir/elf

@@ -84,21 +84,22 @@
 >>18	leshort		40		ARM,
 >>18	leshort		40		ARM,
 >>18	leshort		41		Alpha,
 >>18	leshort		41		Alpha,
 >>18	leshort		0xa390		IBM S/390 (obsolete),
 >>18	leshort		0xa390		IBM S/390 (obsolete),
->>18	leshort		42		Hitachi SH,
+>>18	leshort		42		Renesas SH,
 >>18	leshort		43		SPARC V9 - invalid byte order,
 >>18	leshort		43		SPARC V9 - invalid byte order,
 >>18	leshort		44		Siemens Tricore Embedded Processor,
 >>18	leshort		44		Siemens Tricore Embedded Processor,
 >>18	leshort		45		Argonaut RISC Core, Argonaut Technologies Inc.,
 >>18	leshort		45		Argonaut RISC Core, Argonaut Technologies Inc.,
->>18	leshort		46		Hitachi H8/300,
->>18	leshort		47		Hitachi H8/300H,
->>18	leshort		48		Hitachi H8S,
->>18	leshort		49		Hitachi H8/500,
+>>18	leshort		46		Renesas H8/300,
+>>18	leshort		47		Renesas H8/300H,
+>>18	leshort		48		Renesas H8S,
+>>18	leshort		49		Renesas H8/500,
 >>18	leshort		50		IA-64,
 >>18	leshort		50		IA-64,
 >>18	leshort		51		Stanford MIPS-X,
 >>18	leshort		51		Stanford MIPS-X,
 >>18	leshort		52		Motorola Coldfire,
 >>18	leshort		52		Motorola Coldfire,
 >>18	leshort		53		Motorola M68HC12,
 >>18	leshort		53		Motorola M68HC12,
->>18	leshort		62		AMD x86-64,
+>>18	leshort		62		x86-64,
 >>18	leshort		75		Digital VAX,
 >>18	leshort		75		Digital VAX,
 >>18	leshort		88		Renesas M32R,
 >>18	leshort		88		Renesas M32R,
+>>18	leshort		94		Tensilica Xtensa,
 >>18	leshort		97		NatSemi 32k,
 >>18	leshort		97		NatSemi 32k,
 >>18	leshort		0x9026		Alpha (unofficial),
 >>18	leshort		0x9026		Alpha (unofficial),
 >>20	lelong		0		invalid version
 >>20	lelong		0		invalid version
@@ -176,14 +177,14 @@
 >>18	beshort		39		Motorola RCE,
 >>18	beshort		39		Motorola RCE,
 >>18	beshort		40		ARM,
 >>18	beshort		40		ARM,
 >>18	beshort		41		Alpha,
 >>18	beshort		41		Alpha,
->>18	beshort		42		Hitachi SH,
+>>18	beshort		42		Renesas SH,
 >>18	beshort		43		SPARC V9,
 >>18	beshort		43		SPARC V9,
 >>18	beshort		44		Siemens Tricore Embedded Processor,
 >>18	beshort		44		Siemens Tricore Embedded Processor,
 >>18	beshort		45		Argonaut RISC Core, Argonaut Technologies Inc.,
 >>18	beshort		45		Argonaut RISC Core, Argonaut Technologies Inc.,
->>18	beshort		46		Hitachi H8/300,
->>18	beshort		47		Hitachi H8/300H,
->>18	beshort		48		Hitachi H8S,
->>18	beshort		49		Hitachi H8/500,
+>>18	beshort		46		Renesas H8/300,
+>>18	beshort		47		Renesas H8/300H,
+>>18	beshort		48		Renesas H8S,
+>>18	beshort		49		Renesas H8/500,
 >>18	beshort		50		IA-64,
 >>18	beshort		50		IA-64,
 >>18	beshort		51		Stanford MIPS-X,
 >>18	beshort		51		Stanford MIPS-X,
 >>18	beshort		52		Motorola Coldfire,
 >>18	beshort		52		Motorola Coldfire,
@@ -191,6 +192,7 @@
 >>18	beshort		73		Cray NV1,
 >>18	beshort		73		Cray NV1,
 >>18	beshort		75		Digital VAX,
 >>18	beshort		75		Digital VAX,
 >>18	beshort		88		Renesas M32R,
 >>18	beshort		88		Renesas M32R,
+>>18	beshort		94		Tensilica Xtensa,
 >>18	beshort		97		NatSemi 32k,
 >>18	beshort		97		NatSemi 32k,
 >>18	beshort		0x9026		Alpha (unofficial),
 >>18	beshort		0x9026		Alpha (unofficial),
 >>18	beshort		0xa390		IBM S/390 (obsolete),
 >>18	beshort		0xa390		IBM S/390 (obsolete),
@@ -215,5 +217,8 @@
 >>7	byte		10		(Tru64)
 >>7	byte		10		(Tru64)
 >>7	byte		11		(Novell Modesto)
 >>7	byte		11		(Novell Modesto)
 >>7	byte		12		(OpenBSD)
 >>7	byte		12		(OpenBSD)
+# VMS Itanium added by gerardo.cacciari@gmail.com
+>8      string          \2
+>>7     byte            13              (OpenVMS)
 >>7	byte		97		(ARM)
 >>7	byte		97		(ARM)
 >>7	byte		255		(embedded)
 >>7	byte		255		(embedded)

+ 117 - 10
magic/Magdir/filesystems

@@ -658,7 +658,7 @@
 
 
 0x18b	string	OS/2	OS/2 Boot Manager
 0x18b	string	OS/2	OS/2 Boot Manager
 
 
-9564	lelong		0x00011954	Unix Fast File system (little-endian),
+9564	lelong		0x00011954	Unix Fast File system [v1] (little-endian),
 >8404	string		x		last mounted on %s,
 >8404	string		x		last mounted on %s,
 #>9504	ledate		x		last checked at %s,
 #>9504	ledate		x		last checked at %s,
 >8224	ledate		x		last written at %s,
 >8224	ledate		x		last written at %s,
@@ -674,8 +674,48 @@
 >8320	lelong		0		TIME optimization
 >8320	lelong		0		TIME optimization
 >8320	lelong		1		SPACE optimization
 >8320	lelong		1		SPACE optimization
 
 
-9564	belong		0x00011954	Unix Fast File system (big-endian),
->7168   long		0x4c41424c	Apple UFS Volume
+42332	lelong		0x19540119	Unix Fast File system [v2] (little-endian)
+>&-1164	string		x		last mounted on %s,
+>&-696	string		>\0		volume name %s,
+>&-304	leqldate	x		last written at %s,
+>&-1167	byte		x		clean flag %d,
+>&-1168	byte		x		readonly flag %d,
+>&-296	lequad		x		number of blocks %lld,
+>&-288	lequad		x		number of data blocks %lld,
+>&-1332	lelong		x		number of cylinder groups %d,
+>&-1328	lelong		x		block size %d,
+>&-1324	lelong		x		fragment size %d,
+>&-180	lelong		x		average file size %d,
+>&-176	lelong		x		average number of files in dir %d,
+>&-272	lequad		x		pending blocks to free %lld,
+>&-264	lelong		x		pending inodes to free %ld,
+>&-664	lequad		x		system-wide uuid %0llx,
+>&-1316	lelong		x		minimum percentage of free blocks %d,
+>&-1248	lelong		0		TIME optimization
+>&-1248	lelong		1		SPACE optimization
+
+66908	lelong		0x19540119	Unix Fast File system [v2] (little-endian)
+>&-1164	string		x		last mounted on %s,
+>&-696	string		>\0		volume name %s,
+>&-304	leqldate	x		last written at %s,
+>&-1167	byte		x		clean flag %d,
+>&-1168	byte		x		readonly flag %d,
+>&-296	lequad		x		number of blocks %lld,
+>&-288	lequad		x		number of data blocks %lld,
+>&-1332	lelong		x		number of cylinder groups %d,
+>&-1328	lelong		x		block size %d,
+>&-1324	lelong		x		fragment size %d,
+>&-180	lelong		x		average file size %d,
+>&-176	lelong		x		average number of files in dir %d,
+>&-272	lequad		x		pending blocks to free %lld,
+>&-264	lelong		x		pending inodes to free %ld,
+>&-664	lequad		x		system-wide uuid %0llx,
+>&-1316	lelong		x		minimum percentage of free blocks %d,
+>&-1248	lelong		0		TIME optimization
+>&-1248	lelong		1		SPACE optimization
+
+9564	belong		0x00011954	Unix Fast File system [v1] (big-endian),
+>7168   belong		0x4c41424c	Apple UFS Volume
 >>7186  string		x		named %s,
 >>7186  string		x		named %s,
 >>7176  belong		x		volume label version %d,
 >>7176  belong		x		volume label version %d,
 >>7180  bedate		x		created on %s,
 >>7180  bedate		x		created on %s,
@@ -694,6 +734,46 @@
 >8320	belong		0		TIME optimization
 >8320	belong		0		TIME optimization
 >8320	belong		1		SPACE optimization
 >8320	belong		1		SPACE optimization
 
 
+42332	belong		0x19540119	Unix Fast File system [v2] (big-endian)
+>&-1164	string		x		last mounted on %s,
+>&-696	string		>\0		volume name %s,
+>&-304	beqldate	x		last written at %s,
+>&-1167	byte		x		clean flag %d,
+>&-1168	byte		x		readonly flag %d,
+>&-296	bequad		x		number of blocks %lld,
+>&-288	bequad		x		number of data blocks %lld,
+>&-1332	belong		x		number of cylinder groups %d,
+>&-1328	belong		x		block size %d,
+>&-1324	belong		x		fragment size %d,
+>&-180	belong		x		average file size %d,
+>&-176	belong		x		average number of files in dir %d,
+>&-272	bequad		x		pending blocks to free %lld,
+>&-264	belong		x		pending inodes to free %ld,
+>&-664	bequad		x		system-wide uuid %0llx,
+>&-1316	belong		x		minimum percentage of free blocks %d,
+>&-1248	belong		0		TIME optimization
+>&-1248	belong		1		SPACE optimization
+
+66908	belong		0x19540119	Unix Fast File system [v2] (big-endian)
+>&-1164	string		x		last mounted on %s,
+>&-696	string		>\0		volume name %s,
+>&-304	beqldate	x		last written at %s,
+>&-1167	byte		x		clean flag %d,
+>&-1168	byte		x		readonly flag %d,
+>&-296	bequad		x		number of blocks %lld,
+>&-288	bequad		x		number of data blocks %lld,
+>&-1332	belong		x		number of cylinder groups %d,
+>&-1328	belong		x		block size %d,
+>&-1324	belong		x		fragment size %d,
+>&-180	belong		x		average file size %d,
+>&-176	belong		x		average number of files in dir %d,
+>&-272	bequad		x		pending blocks to free %lld,
+>&-264	belong		x		pending inodes to free %ld,
+>&-664	bequad		x		system-wide uuid %0llx,
+>&-1316	belong		x		minimum percentage of free blocks %d,
+>&-1248	belong		0		TIME optimization
+>&-1248	belong		1		SPACE optimization
+
 # ext2/ext3 filesystems - Andreas Dilger <adilger@turbolabs.com>
 # ext2/ext3 filesystems - Andreas Dilger <adilger@turbolabs.com>
 0x438	leshort		0xEF53		Linux
 0x438	leshort		0xEF53		Linux
 >0x44c	lelong		x		rev %d
 >0x44c	lelong		x		rev %d
@@ -783,7 +863,16 @@
 #
 #
 
 
 # CDROM Filesystems
 # CDROM Filesystems
-32769    string    CD001     ISO 9660 CD-ROM filesystem data
+# Modified for UDF by gerardo.cacciari@gmail.com
+32769    string    CD001
+>38913   string   !NSR0      ISO 9660 CD-ROM filesystem data
+>38913   string    NSR01     UDF filesystem data (version 1.0)
+>38913   string    NSR02     UDF filesystem data (version 1.5)
+>38913   string    NSR03     UDF filesystem data (version 2.0)
+>38913   string    >NSR03    UDF filesystem data (unknown version,
+>>38917  byte      x         id 'NSR0%c')
+>38913   string    <NSR01    UDF filesystem data (unknown version,
+>>38917  byte      x         id 'NSR0%c')
 # "application id" which appears to be used as a volume label
 # "application id" which appears to be used as a volume label
 >32808	 string    >\0       '%s'
 >32808	 string    >\0       '%s'
 >34816	 string    \000CD001\001EL\ TORITO\ SPECIFICATION    (bootable)
 >34816	 string    \000CD001\001EL\ TORITO\ SPECIFICATION    (bootable)
@@ -834,21 +923,25 @@
 0	string	VoIP\ Startup\ and	Aculab VoIP firmware
 0	string	VoIP\ Startup\ and	Aculab VoIP firmware
 >35	string	x	format %s
 >35	string	x	format %s
 
 
-# PPCBoot image file
+# u-boot/PPCBoot image file
 # From: Mark Brown <broonie@sirena.org.uk>
 # From: Mark Brown <broonie@sirena.org.uk>
-0	belong	0x27051956	PPCBoot image
+0	belong	0x27051956	u-boot/PPCBoot image
 >4	string  PPCBoot
 >4	string  PPCBoot
 >>12	string  x		version %s
 >>12	string  x		version %s
 
 
 # JFFS2 file system
 # JFFS2 file system
-0       leshort         0x1984                  Linux old jffs2 filesystem data little endian
-0       lelong          0xe0011985              Linux jffs2 filesystem data little endian
+0	leshort	0x1984		Linux old jffs2 filesystem data little endian
+0	leshort	0x1985		Linux jffs2 filesystem data little endian
 
 
 # Squashfs
 # Squashfs
 0	string	sqsh	Squashfs filesystem, big endian,
 0	string	sqsh	Squashfs filesystem, big endian,
 >28	beshort	x	version %d.
 >28	beshort	x	version %d.
 >30	beshort x	\b%d,
 >30	beshort x	\b%d,
->8	belong	x	%d bytes,
+>28	beshort <3
+>>8	belong	x	%d bytes,
+>28	beshort >2
+>>63	bequad x	%lld bytes,
+#>>67	belong	x	%d bytes,
 >4	belong	x	%d inodes,
 >4	belong	x	%d inodes,
 >28	beshort <2
 >28	beshort <2
 >>32	beshort	x	blocksize: %d bytes,
 >>32	beshort	x	blocksize: %d bytes,
@@ -858,7 +951,11 @@
 0	string	hsqs	Squashfs filesystem, little endian,
 0	string	hsqs	Squashfs filesystem, little endian,
 >28	leshort	x	version %d.
 >28	leshort	x	version %d.
 >30	leshort	x	\b%d,
 >30	leshort	x	\b%d,
->8	lelong	x	%d bytes,
+>28	leshort <3
+>>8	lelong	x	%d bytes,
+>28	leshort >2
+>>63	lequad x	%lld bytes,
+#>>63	lelong	x	%d bytes,
 >4	lelong	x	%d inodes,
 >4	lelong	x	%d inodes,
 >28	leshort <2
 >28	leshort <2
 >>32	leshort	x	blocksize: %d bytes,
 >>32	leshort	x	blocksize: %d bytes,
@@ -866,6 +963,8 @@
 >>51	lelong	x	blocksize: %d bytes,
 >>51	lelong	x	blocksize: %d bytes,
 >39	ledate	x	created: %s
 >39	ledate	x	created: %s
 
 
+0	string		td\000		floppy image data (TeleDisk)
+
 # AFS Dump Magic
 # AFS Dump Magic
 # From: Ty Sarna <tsarna@sarna.org> 
 # From: Ty Sarna <tsarna@sarna.org> 
 0       string                  \x01\xb3\xa1\x13\x22    AFS Dump
 0       string                  \x01\xb3\xa1\x13\x22    AFS Dump
@@ -879,3 +978,11 @@
 >>>>>>>>&4      bedate          x                       on: %s
 >>>>>>>>&4      bedate          x                       on: %s
 >>>>>>>>&0      bedate          =0                      full dump
 >>>>>>>>&0      bedate          =0                      full dump
 >>>>>>>>&0      bedate          !0                      incremental since: %s
 >>>>>>>>&0      bedate          !0                      incremental since: %s
+
+# VMS backup savesets - gerardo.cacciari@gmail.com
+# had to comment out GEM Image and G3 raw data  entries due to conflict
+#0            byte    x
+#>(0.s+16)    string  \x01\x01
+#>>&(&0.b+8)  byte    0x42       OpenVMS backup saveset data
+#>>>40        lelong  x          (block size %d
+#>>>49        string  >\0        original name '%s')

+ 5 - 3
magic/Magdir/images

@@ -267,9 +267,6 @@
 #
 #
 0	beshort		0x1010		PEX Binary Archive
 0	beshort		0x1010		PEX Binary Archive
 
 
-# Visio drawings
-03000	string	Visio\ (TM)\ Drawing	%s
-
 # Tgif files
 # Tgif files
 0	string	\%TGIF\ x 		Tgif file version %s
 0	string	\%TGIF\ x 		Tgif file version %s
 
 
@@ -526,3 +523,8 @@
 # specifications at http://hdf.ncsa.uiuc.edu/
 # specifications at http://hdf.ncsa.uiuc.edu/
 0	belong	0x0e031301	Hierarchical Data Format (version 4) data
 0	belong	0x0e031301	Hierarchical Data Format (version 4) data
 0	string	\211HDF\r\n\032	Hierarchical Data Format (version 5) data
 0	string	\211HDF\r\n\032	Hierarchical Data Format (version 5) data
+
+# From: Tobias Burnus <burnus@net-b.de>
+# Xara (for a while: Corel Xara) is a graphic package, see
+# http://www.xara.com/ for Windows and as GPL application for
+0	string	XARA\243\243	Xara graphics file

+ 3 - 6
magic/Magdir/java

@@ -1,10 +1,7 @@
 #------------------------------------------------------------
 #------------------------------------------------------------
-# Java ByteCode
-# From Larry Schwimmer (schwim@cs.stanford.edu)
-# Handled in Mach now
-#0	belong		0xcafebabe	compiled Java class data,
-#>6	beshort x	version %d.
-#>4	beshort x	\b%d
+# Java ByteCode and Mach-O binaries (e.g., Mac OS X) use the
+# same magic number, 0xcafebabe, so they are both handled
+# in the entry called "cafebabe".
 #------------------------------------------------------------
 #------------------------------------------------------------
 # Java serialization
 # Java serialization
 # From Martin Pool (m.pool@pharos.com.au)
 # From Martin Pool (m.pool@pharos.com.au)

+ 7 - 0
magic/Magdir/linux

@@ -229,3 +229,10 @@
 
 
 0x618		 string	LVM2\ 001	LVM2 (Linux Logical Volume Manager)
 0x618		 string	LVM2\ 001	LVM2 (Linux Logical Volume Manager)
 >(0x614.l+0x600) string	>\0		, UUID: %s
 >(0x614.l+0x600) string	>\0		, UUID: %s
+
+# SE Linux policy database
+0	lelong	0xf97cff8c		SE Linux policy
+>16	lelong	x			v%d
+>20	lelong	1			MLS
+>24	lelong	x			%d symbols
+>28	lelong	x			%d ocons

+ 6 - 23
magic/Magdir/mach

@@ -1,26 +1,9 @@
-#------------------------------------------------------------------------------
-# mach file description
-#
-# Since Java bytecode and Mach-O fat-files have the same magic number the test
-# must be preformed in the same "magic" sequence to get both right.  The long
-# at offset 4 in a fat file tells the number of architectures.  The short at
-# offset 4 in a Java bytecode file is the compiler minor version and the
-# short at offset 6 is the compiler major version.  Since there are only 
-# only 18 labeled Mach-O architectures at current, and the first released 
-# Java class format was version 43.0, we can safely choose any number
-# between 18 and 39 to test the number of architectures against
-# (and use as a hack).
-#
-0	belong		0xcafebabe
->4	belong		>19		compiled Java class data,
->>6     beshort		x	        version %d.
->>4     beshort		x       	\b%d
->4	belong		1		Mach-O fat file with 1 architecture
->4	belong		>1
-# The following is necessary to support java class files.
->>4	belong		<20		Mach-O fat file with %ld architectures
-#>>4	belong		<0xffff		Mach-O fat file with %ld architectures
-#
+#------------------------------------------------------------
+# Mach has two magic numbers, 0xcafebabe and 0xfeedface.
+# Unfortunately the first, cafebabe, is shared with
+# Java ByteCode, so they are both handled in the file "cafebabe".
+# The "feedface" ones are handled herein.
+#------------------------------------------------------------
 0	lelong&0xfeffffff	0xfeedface	Mach-O
 0	lelong&0xfeffffff	0xfeedface	Mach-O
 >0	byte		0xcf		64-bit
 >0	byte		0xcf		64-bit
 >12	lelong		1		object
 >12	lelong		1		object

+ 3 - 0
magic/Magdir/misctools

@@ -8,3 +8,6 @@
 # From: Alex Beregszaszi <alex@fsn.hu>
 # From: Alex Beregszaszi <alex@fsn.hu>
 4	string	gtktalog		GNOME Catalogue (gtktalog)
 4	string	gtktalog		GNOME Catalogue (gtktalog)
 >13	string	>\0			version %s
 >13	string	>\0			version %s
+
+# From: Tomasz Trojanowski <tomek@uninet.com.pl>
+0	search/80	.la\ -\ a\ libtool\ library\ file	libtool library file

+ 15 - 3
magic/Magdir/msdos

@@ -86,6 +86,7 @@
 >>>>(0x3c.l+4)	leshort		0x290	PA-RISC
 >>>>(0x3c.l+4)	leshort		0x290	PA-RISC
 >>>>(0x3c.l+22)	leshort&0x0100	>0	32-bit
 >>>>(0x3c.l+22)	leshort&0x0100	>0	32-bit
 >>>>(0x3c.l+22)	leshort&0x1000	>0	system file
 >>>>(0x3c.l+22)	leshort&0x1000	>0	system file
+>>>>(0x3c.l+232)	lelong	>0	Mono/.Net assembly
 
 
 >>>>(0x3c.l+0xf8)	string		UPX0 \b, UPX compressed
 >>>>(0x3c.l+0xf8)	string		UPX0 \b, UPX compressed
 >>>>(0x3c.l+0xf8)	search/0x140	PEC2 \b, PECompact2 compressed
 >>>>(0x3c.l+0xf8)	search/0x140	PEC2 \b, PECompact2 compressed
@@ -358,6 +359,8 @@
 >30	byte	12		(4kB sectors)
 >30	byte	12		(4kB sectors)
 
 
 # Popular applications
 # Popular applications
+# False positive with PPT
+#0       string \xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3E\x00\x03\x00\xFE\xFF Microsoft Installer
 2080	string	Microsoft\ Word\ 6.0\ Document	%s
 2080	string	Microsoft\ Word\ 6.0\ Document	%s
 2080	string	Documento\ Microsoft\ Word\ 6 Spanish Microsoft Word 6 document data
 2080	string	Documento\ Microsoft\ Word\ 6 Spanish Microsoft Word 6 document data
 # Pawel Wiecek <coven@i17linuxb.ists.pwr.wroc.pl> (for polish Word)
 # Pawel Wiecek <coven@i17linuxb.ists.pwr.wroc.pl> (for polish Word)
@@ -368,7 +371,6 @@
 0       string  PO^Q`				Microsoft Word 6.0 Document
 0       string  PO^Q`				Microsoft Word 6.0 Document
 #
 #
 0	string	\376\067\0\043			Microsoft Office Document
 0	string	\376\067\0\043			Microsoft Office Document
-0	string	\320\317\021\340\241\261\032\341	Microsoft Office Document
 0	string	\333\245-\0\0\0			Microsoft Office Document
 0	string	\333\245-\0\0\0			Microsoft Office Document
 #
 #
 2080	string	Microsoft\ Excel\ 5.0\ Worksheet	%s
 2080	string	Microsoft\ Excel\ 5.0\ Worksheet	%s
@@ -590,10 +592,16 @@
 >>(64.l)  lestring16 >0 Description: %15.15s
 >>(64.l)  lestring16 >0 Description: %15.15s
 
 
 # From: Alex Beregszaszi <alex@fsn.hu>
 # From: Alex Beregszaszi <alex@fsn.hu>
-0	string	COWD		VMWare3 disk image
->12	belong	x		%d bytes
+0	string	COWD		VMWare3
+>4	byte	3	 	disk image
+>>32	lelong	x		(%d/
+>>36	lelong	x		\b%d/
+>>40	lelong	x		\b%d)
+>4	byte	2	 	undoable disk image
+>>32	string  >\0		(%s)
 
 
 0	string	VMDK		 VMware4 disk image
 0	string	VMDK		 VMware4 disk image
+0	string	KDMV		 VMware4 disk image
 
 
 0	belong	0x514649fb	QEMU Copy-On-Write disk image
 0	belong	0x514649fb	QEMU Copy-On-Write disk image
 >4	belong	x		version %d,
 >4	belong	x		version %d,
@@ -607,3 +615,7 @@
 >48	string	x				subtype %s
 >48	string	x				subtype %s
 
 
 0	lelong	0x02468ace			Bochs Sparse disk image
 0	lelong	0x02468ace			Bochs Sparse disk image
+
+# from http://filext.com by Derek M Jones <derek@knosof.co.uk>
+0	string	\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3E\x00\x03\x00\xFE\xFF	Microsoft Installer
+0	string	\320\317\021\340\241\261\032\341	Microsoft Office Document

+ 32 - 0
magic/Magdir/os400

@@ -0,0 +1,32 @@
+#------------------------------------------------------------------------------
+# os400:  file(1) magic for IBM OS/400 files
+
+# IBM OS/400 (i5/OS) Save file (SAVF) - gerardo.cacciari@gmail.com
+# In spite of its quite variable format (due to internal memory page
+# length differences between CISC and RISC versions of the OS) the
+# SAVF structure hasn't suitable offsets to identify the catalog
+# header in the first descriptor where there are some useful infos,
+# so we must search in a somewhat large area for a particular string
+# that represents the EBCDIC encoding of 'QSRDSSPC' (save/restore
+# descriptor space) preceded by a two byte constant.
+40	 string		@@@@@@@@
+>1089	 search/7394	\x19\xDB\xD8\xE2\xD9\xC4\xE2\xE2\xD7\xC3 IBM OS/400 save file data
+>>&212	 byte		0x01			 \b, created with SAVOBJ
+>>&212	 byte		0x02			 \b, created with SAVLIB
+>>&212	 byte		0x07			 \b, created with SAVCFG
+>>&212	 byte		0x0B			 \b, created with SAVDLO
+>>&213	 byte		0x43			 \b, at least V5R3 to open
+>>&213	 byte		0x42			 \b, at least V5R2 to open
+>>&213	 byte		0x41			 \b, at least V5R1 to open
+>>&213	 byte		0x40			 \b, at least V4R5 to open
+>>&213	 byte		0x3F			 \b, at least V4R4 to open
+>>&213	 byte		0x3E			 \b, at least V4R3 to open
+>>&213	 byte		0x3C			 \b, at least V4R2 to open
+>>&213	 byte		0x3D			 \b, at least V4R1M4 to open
+>>&213	 byte		0x3B			 \b, at least V4R1 to open
+>>&213	 byte		0x3A			 \b, at least V3R7 to open
+>>&213	 byte		0x35			 \b, at least V3R6 to open
+>>&213	 byte		0x36			 \b, at least V3R2 to open
+>>&213	 byte		0x34			 \b, at least V3R1 to open
+>>&213	 byte		0x31			 \b, at least V3R0M5 to open
+>>&213	 byte		0x30			 \b, at least V2R3 to open

+ 1 - 0
magic/Magdir/python

@@ -13,6 +13,7 @@
 0	belong		0x2ded0d0a	python 2.2 byte-compiled
 0	belong		0x2ded0d0a	python 2.2 byte-compiled
 0	belong		0x3bf20d0a	python 2.3 byte-compiled
 0	belong		0x3bf20d0a	python 2.3 byte-compiled
 0	belong		0x6df20d0a	python 2.4 byte-compiled
 0	belong		0x6df20d0a	python 2.4 byte-compiled
+0	belong		0xb3f20d0a	python 2.5 byte-compiled
 
 
 0	string/b  #!\ /usr/bin/python	python script text executable
 0	string/b  #!\ /usr/bin/python	python script text executable
 
 

+ 7 - 0
magic/Magdir/riff

@@ -29,6 +29,8 @@
 >8	string		RMID		\b, MIDI
 >8	string		RMID		\b, MIDI
 # RIFF Multimedia Movie File format
 # RIFF Multimedia Movie File format
 >8	string		RMMP		\b, multimedia movie
 >8	string		RMMP		\b, multimedia movie
+# RIFF wrapper for MP3
+>8	string		RMP3		\b, MPEG Layer 3 audio
 # Microsoft WAVE format (*.wav)
 # Microsoft WAVE format (*.wav)
 >8	string		WAVE		\b, WAVE audio
 >8	string		WAVE		\b, WAVE audio
 >>20	leshort		1		\b, Microsoft PCM
 >>20	leshort		1		\b, Microsoft PCM
@@ -120,6 +122,7 @@
 >>>>>>>(104.l+132)      string/c        iv50    Indeo 5.0
 >>>>>>>(104.l+132)      string/c        iv50    Indeo 5.0
 >>>>>>>(104.l+132)      string/c        mp42    Microsoft MPEG-4 v2
 >>>>>>>(104.l+132)      string/c        mp42    Microsoft MPEG-4 v2
 >>>>>>>(104.l+132)      string/c        mp43    Microsoft MPEG-4 v3
 >>>>>>>(104.l+132)      string/c        mp43    Microsoft MPEG-4 v3
+>>>>>>>(104.l+132)      string/c        fmp4    FFMpeg MPEG-4
 >>>>>>>(104.l+132)      string/c        mjpg    Motion JPEG
 >>>>>>>(104.l+132)      string/c        mjpg    Motion JPEG
 >>>>>>>(104.l+132)      string/c        div3    DivX 3
 >>>>>>>(104.l+132)      string/c        div3    DivX 3
 >>>>>>>>112             string/c        div3    Low-Motion
 >>>>>>>>112             string/c        div3    Low-Motion
@@ -127,6 +130,7 @@
 >>>>>>>(104.l+132)      string/c        divx    DivX 4
 >>>>>>>(104.l+132)      string/c        divx    DivX 4
 >>>>>>>(104.l+132)      string/c        dx50    DivX 5
 >>>>>>>(104.l+132)      string/c        dx50    DivX 5
 >>>>>>>(104.l+132)      string/c        xvid    XviD
 >>>>>>>(104.l+132)      string/c        xvid    XviD
+>>>>>>>(104.l+132)      string/c        wmv3    Windows Media Video 9
 >>>>>>>(104.l+132)      string/c        h264    X.264
 >>>>>>>(104.l+132)      string/c        h264    X.264
 >>>>>>>(104.l+132)      lelong  0
 >>>>>>>(104.l+132)      lelong  0
 ##>>>>>>>(104.l+132)      string  x       (%.4s)
 ##>>>>>>>(104.l+132)      string  x       (%.4s)
@@ -138,6 +142,9 @@
 >>>>>>>(92.l+172)       string          strf
 >>>>>>>(92.l+172)       string          strf
 >>>>>>>>(92.l+180)      leshort 0x0001  uncompressed PCM
 >>>>>>>>(92.l+180)      leshort 0x0001  uncompressed PCM
 >>>>>>>>(92.l+180)      leshort 0x0002  ADPCM
 >>>>>>>>(92.l+180)      leshort 0x0002  ADPCM
+>>>>>>>>(92.l+180)      leshort 0x0006  aLaw
+>>>>>>>>(92.l+180)      leshort 0x0007  uLaw
+>>>>>>>>(92.l+180)      leshort 0x0050  MPEG-1 Layer 1 or 2
 >>>>>>>>(92.l+180)      leshort 0x0055  MPEG-1 Layer 3
 >>>>>>>>(92.l+180)      leshort 0x0055  MPEG-1 Layer 3
 >>>>>>>>(92.l+180)      leshort 0x2000  Dolby AC3
 >>>>>>>>(92.l+180)      leshort 0x2000  Dolby AC3
 >>>>>>>>(92.l+180)      leshort 0x0161  DivX
 >>>>>>>>(92.l+180)      leshort 0x0161  DivX

+ 8 - 0
magic/Magdir/sun

@@ -12,10 +12,12 @@
 >>20	belong		>4096		dynamically linked executable
 >>20	belong		>4096		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
+
 0	belong&077777777	0600410		sparc pure
 0	belong&077777777	0600410		sparc pure
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
+
 0	belong&077777777	0600407		sparc
 0	belong&077777777	0600407		sparc
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
@@ -26,11 +28,14 @@
 >>20	belong		<4096		shared library
 >>20	belong		<4096		shared library
 >>20	belong		=4096		dynamically linked executable
 >>20	belong		=4096		dynamically linked executable
 >>20	belong		>4096		dynamically linked executable
 >>20	belong		>4096		dynamically linked executable
+>0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
+
 0	belong&077777777	0400410		mc68020 pure
 0	belong&077777777	0400410		mc68020 pure
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
+
 0	belong&077777777	0400407		mc68020
 0	belong&077777777	0400407		mc68020
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
@@ -41,11 +46,14 @@
 >>20	belong		<4096		shared library
 >>20	belong		<4096		shared library
 >>20	belong		=4096		dynamically linked executable
 >>20	belong		=4096		dynamically linked executable
 >>20	belong		>4096		dynamically linked executable
 >>20	belong		>4096		dynamically linked executable
+>0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
+
 0	belong&077777777	0200410		mc68010 pure
 0	belong&077777777	0200410		mc68010 pure
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable
 >16	belong		>0		not stripped
 >16	belong		>0		not stripped
+
 0	belong&077777777	0200407		mc68010
 0	belong&077777777	0200407		mc68010
 >0	byte		&0x80		dynamically linked executable
 >0	byte		&0x80		dynamically linked executable
 >0	byte		^0x80		executable
 >0	byte		^0x80		executable

+ 125 - 2
magic/Magdir/sysex

@@ -11,7 +11,28 @@
 >1	byte			0x04		Moog
 >1	byte			0x04		Moog
 >1	byte			0x05		Passport
 >1	byte			0x05		Passport
 >1	byte			0x06		Lexicon
 >1	byte			0x06		Lexicon
->1	byte			0x07		Kurzweil
+>1	byte			0x07		Kurzweil/Future Retro
+>>3	byte			0x77		777
+>>4	byte			0x00		Bank
+>>4	byte			0x01		Song
+>>5	byte			0x0f		16
+>>5	byte			0x0e		15
+>>5	byte			0x0d		14
+>>5	byte			0x0c		13
+>>5	byte			0x0b		12
+>>5	byte			0x0a		11
+>>5	byte			0x09		10
+>>5	byte			0x08		9
+>>5	byte			0x07		8
+>>5	byte			0x06		7
+>>5	byte			0x05		6
+>>5	byte			0x04		5
+>>5	byte			0x03		4
+>>5	byte			0x02		3
+>>5	byte			0x01		2
+>>5	byte			0x00		1
+>>5	byte			0x10		(ALL)
+>>2	byte			x			\b, Channel %d
 >1	byte			0x08		Fender
 >1	byte			0x08		Fender
 >1	byte			0x09		Gulbransen
 >1	byte			0x09		Gulbransen
 >1	byte			0x0a		AKG
 >1	byte			0x0a		AKG
@@ -21,6 +42,12 @@
 >1	byte			0x0e		Garfield
 >1	byte			0x0e		Garfield
 >1	byte			0x0f		Ensoniq
 >1	byte			0x0f		Ensoniq
 >1	byte			0x10		Oberheim
 >1	byte			0x10		Oberheim
+>>2	byte			0x06		Matrix 6 series
+>>3	byte			0x0A		Dump (All)
+>>3	byte			0x01		Dump (Bank)
+>>4 belong			0x0002040E		Matrix 1000
+>>>11 byte			<2			User bank %d
+>>>11 byte			>1			Preset bank %d
 >1	byte			0x11		Apple
 >1	byte			0x11		Apple
 >1	byte			0x12		GreyMatter
 >1	byte			0x12		GreyMatter
 >1	byte			0x14		PalmTree
 >1	byte			0x14		PalmTree
@@ -52,11 +79,107 @@
 >>3	byte			0x09		EK-44
 >>3	byte			0x09		EK-44
 
 
 >1	byte			0x30		Dynacord
 >1	byte			0x30		Dynacord
+>1	byte			0x31		Jomox
 >1	byte			0x33		Clavia
 >1	byte			0x33		Clavia
 >1	byte			0x39		Soundcraft
 >1	byte			0x39		Soundcraft
-
+# Some Waldorf info from http://Stromeko.Synth.net/Downloads#WaldorfDocs
 >1	byte			0x3e		Waldorf
 >1	byte			0x3e		Waldorf
+>>2	byte			0x00		microWave
+>>2	byte			0x0E		microwave2 / XT
+>>2	byte			0x0F		Q / Q+
+>>3	byte			=0			(default id)
+>>3 byte			>0			(
+>>>3 byte			<0x7F		\bdevice %d)
+>>>3 byte			=0x7F		\bbroadcast id)
 >>3	byte			0x7f		Microwave I
 >>3	byte			0x7f		Microwave I
+>>>4	byte			0x00		SNDR (Sound Request)
+>>>4	byte			0x10		SNDD (Sound Dump)
+>>>4	byte			0x20		SNDP (Sound Parameter Change)
+>>>4	byte			0x30		SNDQ (Sound Parameter Inquiry)
+>>>4	byte			0x70		BOOT (Sound Reserved)
+>>>4	byte			0x01		MULR (Multi Request)
+>>>4	byte			0x11		MULD (Multi Dump)
+>>>4	byte			0x21		MULP (Multi Parameter Change)
+>>>4	byte			0x31		MULQ (Multi Parameter Inquiry)
+>>>4	byte			0x71		OS (Multi Reserved)
+>>>4	byte			0x02		DRMR (Drum Map Request)
+>>>4	byte			0x12		DRMD (Drum Map Dump)
+>>>4	byte			0x22		DRMP (Drum Map Parameter Change)
+>>>4	byte			0x32		DRMQ (Drum Map Parameter Inquiry)
+>>>4	byte			0x72		BIN (Drum Map Reserved)
+>>>4	byte			0x03		PATR (Sequencer Pattern Request)
+>>>4	byte			0x13		PATD (Sequencer Pattern Dump)
+>>>4	byte			0x23		PATP (Sequencer Pattern Parameter Change)
+>>>4	byte			0x33		PATQ (Sequencer Pattern Parameter Inquiry)
+>>>4	byte			0x73		AFM (Sequencer Pattern Reserved)
+>>>4	byte			0x04		GLBR (Global Parameter Request)
+>>>4	byte			0x14		GLBD (Global Parameter Dump)
+>>>4	byte			0x24		GLBP (Global Parameter Parameter Change)
+>>>4	byte			0x34		GLBQ (Global Parameter Parameter Inquiry)
+>>>4	byte			0x07		MODR (Mode Parameter Request)
+>>>4	byte			0x17		MODD (Mode Parameter Dump)
+>>>4	byte			0x27		MODP (Mode Parameter Parameter Change)
+>>>4	byte			0x37		MODQ (Mode Parameter Parameter Inquiry)
+>>2	byte			0x10		microQ
+>>>4	byte			0x00		SNDR (Sound Request)
+>>>4	byte			0x10		SNDD (Sound Dump)
+>>>4	byte			0x20		SNDP (Sound Parameter Change)
+>>>4	byte			0x30		SNDQ (Sound Parameter Inquiry)
+>>>4	byte			0x70		(Sound Reserved)
+>>>4	byte			0x01		MULR (Multi Request)
+>>>4	byte			0x11		MULD (Multi Dump)
+>>>4	byte			0x21		MULP (Multi Parameter Change)
+>>>4	byte			0x31		MULQ (Multi Parameter Inquiry)
+>>>4	byte			0x71		OS (Multi Reserved)
+>>>4	byte			0x02		DRMR (Drum Map Request)
+>>>4	byte			0x12		DRMD (Drum Map Dump)
+>>>4	byte			0x22		DRMP (Drum Map Parameter Change)
+>>>4	byte			0x32		DRMQ (Drum Map Parameter Inquiry)
+>>>4	byte			0x72		BIN (Drum Map Reserved)
+>>>4	byte			0x04		GLBR (Global Parameter Request)
+>>>4	byte			0x14		GLBD (Global Parameter Dump)
+>>>4	byte			0x24		GLBP (Global Parameter Parameter Change)
+>>>4	byte			0x34		GLBQ (Global Parameter Parameter Inquiry)
+>>2	byte			0x11		rackAttack
+>>>4	byte			0x00		SNDR (Sound Parameter Request)
+>>>4	byte			0x10		SNDD (Sound Parameter Dump)
+>>>4	byte			0x20		SNDP (Sound Parameter Parameter Change)
+>>>4	byte			0x30		SNDQ (Sound Parameter Parameter Inquiry)
+>>>4	byte			0x01		PRGR (Program Parameter Request)
+>>>4	byte			0x11		PRGD (Program Parameter Dump)
+>>>4	byte			0x21		PRGP (Program Parameter Parameter Change)
+>>>4	byte			0x31		PRGQ (Program Parameter Parameter Inquiry)
+>>>4	byte			0x71		OS (Program Parameter Reserved)
+>>>4	byte			0x03		PATR (Pattern Parameter Request)
+>>>4	byte			0x13		PATD (Pattern Parameter Dump)
+>>>4	byte			0x23		PATP (Pattern Parameter Parameter Change)
+>>>4	byte			0x33		PATQ (Pattern Parameter Parameter Inquiry)
+>>>4	byte			0x04		GLBR (Global Parameter Request)
+>>>4	byte			0x14		GLBD (Global Parameter Dump)
+>>>4	byte			0x24		GLBP (Global Parameter Parameter Change)
+>>>4	byte			0x34		GLBQ (Global Parameter Parameter Inquiry)
+>>>4	byte			0x05		EFXR (FX Parameter Request)
+>>>4	byte			0x15		EFXD (FX Parameter Dump)
+>>>4	byte			0x25		EFXP (FX Parameter Parameter Change)
+>>>4	byte			0x35		EFXQ (FX Parameter Parameter Inquiry)
+>>>4	byte			0x07		MODR (Mode Command Request)
+>>>4	byte			0x17		MODD (Mode Command Dump)
+>>>4	byte			0x27		MODP (Mode Command Parameter Change)
+>>>4	byte			0x37		MODQ (Mode Command Parameter Inquiry)
+>>2	byte			0x03		Wave
+>>>4	byte			0x00		SBPR (Soundprogram)
+>>>4	byte			0x01		SAPR (Performance)
+>>>4	byte			0x02		SWAVE (Wave)
+>>>4	byte			0x03		SWTBL (Wave control table)
+>>>4	byte			0x04		SVT (Velocity Curve)
+>>>4	byte			0x05		STT (Tuning Table)
+>>>4	byte			0x06		SGLB (Global Parameters)
+>>>4	byte			0x07		SARRMAP (Performance Program Change Map)
+>>>4	byte			0x08		SBPRMAP (Sound Program Change Map)
+>>>4	byte			0x09		SBPRPAR (Sound Parameter)
+>>>4	byte			0x0A		SARRPAR (Performance Parameter)
+>>>4	byte			0x0B		SINSPAR (Instrument/External Parameter)
+>>>4	byte			0x0F		SBULK (Bulk Switch on/off)
 
 
 # Japanese Group
 # Japanese Group
 >1	byte			0x40		Kawai
 >1	byte			0x40		Kawai

+ 15 - 0
magic/Magdir/unicode

@@ -0,0 +1,15 @@
+
+#---------------------------------------------------------------------------
+# Unicode:  BOM prefixed text files - Adrian Havill <havill@turbolinux.co.jp>
+#
+0	string	+/v8			Unicode text, UTF-7
+0	string	+/v9			Unicode text, UTF-7
+0	string	+/v+			Unicode text, UTF-7
+0	string	+/v/			Unicode text, UTF-7
+0	string	\357\273\277		Unicode text, UTF-8
+0	string	\335\163\146\163	Unicode text, UTF-8-EBCDIC
+0	string	\376\377\000\000	Unicode text, UTF-32, big-endian
+0	string	\377\376\000\000	Unicode text, UTF-32, little-endian
+0	string	\376\377		Unicode text, UTF-16, big-endian
+0	string	\377\376		Unicode text, UTF-16, little-endian
+0	string	\016\376\377		Unicode text, SCSU (Standard Compression Scheme for Unicode)

+ 0 - 7
magic/Magdir/vmware

@@ -3,10 +3,3 @@
 # VMware specific files (deducted from version 1.1 and log file entries)
 # VMware specific files (deducted from version 1.1 and log file entries)
 # Anthon van der Neut (anthon@mnt.org)
 # Anthon van der Neut (anthon@mnt.org)
 0	belong	0x4d52564e	VMware nvram 
 0	belong	0x4d52564e	VMware nvram 
-0	belong	0x434f5744	VMware
->4	byte	3	 	virtual disk 
->>32	lelong	x		(%d/
->>36	lelong	x		\b%d/
->>40	lelong	x		\b%d)
->4	byte	2	 	undoable disk
->>32	string  >\0		(%s)

+ 20 - 1
magic/Magdir/wordprocessors

@@ -104,7 +104,9 @@
 #end of WordPerfect type files Version 1.6 - PLEASE DO NOT REMOVE THIS LINE
 #end of WordPerfect type files Version 1.6 - PLEASE DO NOT REMOVE THIS LINE
 
 
 # Hangul (Korean) Word Processor File
 # Hangul (Korean) Word Processor File
-0	string	HWP\ Document\ File	Hangul (Korean) Word Processor File
+0	string	HWP\ Document\ File	Hangul (Korean) Word Processor File 3.0
+# From: Won-Kyu Park <wkpark@kldp.org>
+512	string		R\0o\0o\0t\0	Hangul (Korean) Word Processor File 2000
 
 
 # CosmicBook, from Benoît Rouits
 # CosmicBook, from Benoît Rouits
 0       string  CSBK    Ted Neslson's CosmicBook hypertext file
 0       string  CSBK    Ted Neslson's CosmicBook hypertext file
@@ -115,3 +117,20 @@
 0       string          \\1cw\          ChiWriter file
 0       string          \\1cw\          ChiWriter file
 >5      string          >\0             version %s
 >5      string          >\0             version %s
 0       string          \\1cw           ChiWriter file
 0       string          \\1cw           ChiWriter file
+
+# Quark Express from http://www.garykessler.net/library/file_sigs.html
+2	string	IIXPR3			Intel Quark Express Document (English)
+2	string	IIXPRa			Intel Quark Express Document (Korean)
+2	string	MMXPR3			Motorola Quark Express Document (English)
+2	string	MMXPRa			Motorola Quark Express Document (Korean)
+
+# adobe indesign (document, whatever...) from querkan
+0	belong	0x0606edf5		Adobe InDesign
+>16	string	DOCUMENT		Document
+
+# From: Michael Piefel <piefel@debian.org>
+# sqtroff intermediate language (replacement for ditroff int. lang.)
+0	string		X\ 495		SoftQuad troff Context intermediate for AT&T 495 laser printer
+0	string		X\ hp		SoftQuad troff Context intermediate for HP LaserJet
+0	string		X\ impr		SoftQuad troff Context intermediate for IMAGEN imPRESS
+0	string		X\ ps		SoftQuad troff Context intermediate for PostScript

+ 1 - 1
magic/Magdir/xwindows

@@ -13,7 +13,7 @@
 
 
 # xfsdump archive
 # xfsdump archive
 0	string	xFSdump0			xfsdump archive
 0	string	xFSdump0			xfsdump archive
->8	long	x	(version %d)
+>8	belong	x	(version %d)
 
 
 # Jaleo XFS files
 # Jaleo XFS files
 0	long	395726				Jaleo XFS file
 0	long	395726				Jaleo XFS file

+ 3 - 0
magic/Makefile.am

@@ -52,6 +52,7 @@ Magdir/bout \
 Magdir/bsdi \
 Magdir/bsdi \
 Magdir/btsnoop \
 Magdir/btsnoop \
 Magdir/cad \
 Magdir/cad \
+Magdir/cafebabe \
 Magdir/c-lang \
 Magdir/c-lang \
 Magdir/c64 \
 Magdir/c64 \
 Magdir/cddb \
 Magdir/cddb \
@@ -143,6 +144,7 @@ Magdir/ocaml \
 Magdir/octave \
 Magdir/octave \
 Magdir/olf \
 Magdir/olf \
 Magdir/os2 \
 Magdir/os2 \
+Magdir/os400 \
 Magdir/os9 \
 Magdir/os9 \
 Magdir/osf1 \
 Magdir/osf1 \
 Magdir/palm \
 Magdir/palm \
@@ -194,6 +196,7 @@ Magdir/troff \
 Magdir/tuxedo \
 Magdir/tuxedo \
 Magdir/typeset \
 Magdir/typeset \
 Magdir/unknown \
 Magdir/unknown \
+Magdir/unicode \
 Magdir/uuencode \
 Magdir/uuencode \
 Magdir/varied.out \
 Magdir/varied.out \
 Magdir/varied.script \
 Magdir/varied.script \

+ 3 - 0
magic/Makefile.in

@@ -192,6 +192,7 @@ Magdir/bout \
 Magdir/bsdi \
 Magdir/bsdi \
 Magdir/btsnoop \
 Magdir/btsnoop \
 Magdir/cad \
 Magdir/cad \
+Magdir/cafebabe \
 Magdir/c-lang \
 Magdir/c-lang \
 Magdir/c64 \
 Magdir/c64 \
 Magdir/cddb \
 Magdir/cddb \
@@ -283,6 +284,7 @@ Magdir/ocaml \
 Magdir/octave \
 Magdir/octave \
 Magdir/olf \
 Magdir/olf \
 Magdir/os2 \
 Magdir/os2 \
+Magdir/os400 \
 Magdir/os9 \
 Magdir/os9 \
 Magdir/osf1 \
 Magdir/osf1 \
 Magdir/palm \
 Magdir/palm \
@@ -334,6 +336,7 @@ Magdir/troff \
 Magdir/tuxedo \
 Magdir/tuxedo \
 Magdir/typeset \
 Magdir/typeset \
 Magdir/unknown \
 Magdir/unknown \
+Magdir/unicode \
 Magdir/uuencode \
 Magdir/uuencode \
 Magdir/varied.out \
 Magdir/varied.out \
 Magdir/varied.script \
 Magdir/varied.script \

+ 45 - 33
magic/magic.mime

@@ -99,9 +99,7 @@
 
 
 # svg
 # svg
 
 
-0	string		\<?xml
-#			text/xml
->38	string		\<\!DOCTYPE\040svg	image/svg+xml
+38	string		\<\!DOCTYPE\040svg	image/svg+xml
 
 
 
 
 # xml
 # xml
@@ -111,8 +109,8 @@
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
 # Java
 # Java
 
 
-0	short		0xcafe
->2	short		0xbabe		application/java
+0	beshort		0xcafe
+>2	beshort		0xbabe		application/java
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
 # audio:  file(1) magic for sound formats
 # audio:  file(1) magic for sound formats
@@ -135,7 +133,7 @@
 # DEC systems (e.g. DECstation 5000) use a variant of the Sun/NeXT format
 # DEC systems (e.g. DECstation 5000) use a variant of the Sun/NeXT format
 # that uses little-endian encoding and has a different magic number
 # that uses little-endian encoding and has a different magic number
 # (0x0064732E in little-endian encoding).
 # (0x0064732E in little-endian encoding).
-0	lelong		0x0064732E	
+0	lelong		0x0064732E
 >12	lelong		1		audio/x-dec-basic
 >12	lelong		1		audio/x-dec-basic
 >12	lelong		2		audio/x-dec-basic
 >12	lelong		2		audio/x-dec-basic
 >12	lelong		3		audio/x-dec-basic
 >12	lelong		3		audio/x-dec-basic
@@ -148,25 +146,25 @@
 
 
 # Bytes 0-3 of AIFF, AIFF-C, & 8SVX audio files are "FORM"
 # Bytes 0-3 of AIFF, AIFF-C, & 8SVX audio files are "FORM"
 #					AIFF audio data
 #					AIFF audio data
-8	string		AIFF		audio/x-aiff	
+8	string		AIFF		audio/x-aiff
 #					AIFF-C audio data
 #					AIFF-C audio data
-8	string		AIFC		audio/x-aiff	
+8	string		AIFC		audio/x-aiff
 #					IFF/8SVX audio data
 #					IFF/8SVX audio data
-8	string		8SVX		audio/x-aiff	
+8	string		8SVX		audio/x-aiff
 
 
 
 
 
 
 # Creative Labs AUDIO stuff
 # Creative Labs AUDIO stuff
 #					Standard MIDI data
 #					Standard MIDI data
-0	string	MThd			audio/unknown	
+0	string	MThd			audio/unknown
 #>9 	byte	>0			(format %d)
 #>9 	byte	>0			(format %d)
 #>11	byte	>1			using %d channels
 #>11	byte	>1			using %d channels
 #					Creative Music (CMF) data
 #					Creative Music (CMF) data
-0	string	CTMF			audio/unknown	
+0	string	CTMF			audio/unknown
 #					SoundBlaster instrument data
 #					SoundBlaster instrument data
-0	string	SBI			audio/unknown	
+0	string	SBI			audio/unknown
 #					Creative Labs voice data
 #					Creative Labs voice data
-0	string	Creative\ Voice\ File	audio/unknown	
+0	string	Creative\ Voice\ File	audio/unknown
 ## is this next line right?  it came this way...
 ## is this next line right?  it came this way...
 #>19	byte	0x1A
 #>19	byte	0x1A
 #>23	byte	>0			- version %d
 #>23	byte	>0			- version %d
@@ -209,8 +207,8 @@
 # ideally should go into "images", but entries below would tag XPM as C source
 # ideally should go into "images", but entries below would tag XPM as C source
 0	string		/*\ XPM		image/x-xpmi 7bit
 0	string		/*\ XPM		image/x-xpmi 7bit
 
 
-# 3DS (3d Studio files)
-16	beshort		0x3d3d		image/x-3ds
+# 3DS (3d Studio files) Conflicts with diff output 0x3d '='
+#16	beshort		0x3d3d		image/x-3ds
 
 
 # this first will upset you if you're a PL/1 shop... (are there any left?)
 # this first will upset you if you're a PL/1 shop... (are there any left?)
 # in which case rm it; ascmagic will catch real C programs
 # in which case rm it; ascmagic will catch real C programs
@@ -408,10 +406,7 @@
 0	string		\<!--	text/html
 0	string		\<!--	text/html
 0	string		\<h1	text/html
 0	string		\<h1	text/html
 0	string		\<H1	text/html
 0	string		\<H1	text/html
-0	string		\<!doctype\ HTML	text/html
-0	string		\<!DOCTYPE\ HTML	text/html
-0	string		\<!doctype\ html	text/html
-0	string		\<!doctype\ HTML	text/html
+0	string/c	\<!doctype\ html	text/html
 
 
 #------------------------------------------------------------------------------
 #------------------------------------------------------------------------------
 # images:  file(1) magic for image formats (see also "c-lang" for XPM bitmaps)
 # images:  file(1) magic for image formats (see also "c-lang" for XPM bitmaps)
@@ -530,7 +525,11 @@
 #
 #
 
 
 0	string		\376\067\0\043			application/msword
 0	string		\376\067\0\043			application/msword
-0	string		\320\317\021\340\241\261	application/msword
+# disable this one because it applies also to other
+# Office/OLE documents for which msword is not correct. See PR#2608.
+# from magic file of the apache
+#0	string		\320\317\021\340\241\261	application/msword
+512	string		\354\245\301			application/msword
 0	string		\333\245-\0\0\0			application/msword
 0	string		\333\245-\0\0\0			application/msword
 
 
 
 
@@ -566,7 +565,7 @@
 #0	string		\367\203	TeX generic font data
 #0	string		\367\203	TeX generic font data
 #0	string		\367\131	TeX packed font data
 #0	string		\367\131	TeX packed font data
 #0	string		\367\312	TeX virtual font data
 #0	string		\367\312	TeX virtual font data
-#0	string		This\ is\ TeX,	TeX transcript text	
+#0	string		This\ is\ TeX,	TeX transcript text
 #0	string		This\ is\ METAFONT,	METAFONT transcript text
 #0	string		This\ is\ METAFONT,	METAFONT transcript text
 
 
 # There is no way to detect TeX Font Metric (*.tfm) files without
 # There is no way to detect TeX Font Metric (*.tfm) files without
@@ -603,7 +602,7 @@
 0       belong             0x000001B3     video/mpv
 0       belong             0x000001B3     video/mpv
 0       belong&0xFF5FFF1F  0x47400010     video/mp2t
 0       belong&0xFF5FFF1F  0x47400010     video/mp2t
 0       belong             0x00000001
 0       belong             0x00000001
->4      byte&1F            0x07           video/h264
+>4      byte&0x1F	   0x07           video/h264
 
 
 # FLI animation format
 # FLI animation format
 0	leshort		0xAF11				video/fli
 0	leshort		0xAF11				video/fli
@@ -658,7 +657,7 @@
 #
 #
 # Executables
 # Executables
 #
 #
-0	string		\177ELF 
+0	string		\177ELF
 >16	leshort		0		application/octet-stream
 >16	leshort		0		application/octet-stream
 >16	leshort		1		application/x-object
 >16	leshort		1		application/x-object
 >16	leshort		2		application/x-executable
 >16	leshort		2		application/x-executable
@@ -712,19 +711,19 @@
 4	string	Standard\ Jet\ DB	application/msaccess
 4	string	Standard\ Jet\ DB	application/msaccess
 
 
 ## magic for XBase files
 ## magic for XBase files
-#0      byte       0x02	
+#0      byte       0x02
 #>8     leshort	  >0
 #>8     leshort	  >0
 #>>12   leshort    0	application/x-dbf
 #>>12   leshort    0	application/x-dbf
 #
 #
-#0      byte       0x03	
+#0      byte       0x03
 #>8     leshort	  >0
 #>8     leshort	  >0
 #>>12   leshort    0	application/x-dbf
 #>>12   leshort    0	application/x-dbf
 #
 #
-#0      byte       0x04	
+#0      byte       0x04
 #>8     leshort	  >0
 #>8     leshort	  >0
 #>>12   leshort    0	application/x-dbf
 #>>12   leshort    0	application/x-dbf
 #
 #
-#0      byte       0x05	
+#0      byte       0x05
 #>8     leshort	  >0
 #>8     leshort	  >0
 #>>12   leshort    0	application/x-dbf
 #>>12   leshort    0	application/x-dbf
 #
 #
@@ -740,7 +739,7 @@
 #>8     leshort	  >0
 #>8     leshort	  >0
 #>>12   leshort    0	application/x-dbf
 #>>12   leshort    0	application/x-dbf
 #
 #
-#0      byte       0x83	
+#0      byte       0x83
 #>8     leshort	  >0
 #>8     leshort	  >0
 #>>12   leshort    0	application/x-dbf
 #>>12   leshort    0	application/x-dbf
 #
 #
@@ -748,7 +747,7 @@
 #>8     leshort	  >0
 #>8     leshort	  >0
 #>>12   leshort    0	application/x-dbf
 #>>12   leshort    0	application/x-dbf
 #
 #
-#0      byte       0x8e	
+#0      byte       0x8e
 #>8     leshort	  >0
 #>8     leshort	  >0
 #>>12   leshort    0	application/x-dbf
 #>>12   leshort    0	application/x-dbf
 #
 #
@@ -769,7 +768,7 @@
 0       beshort         0x9501                  text/PGP key security ring
 0       beshort         0x9501                  text/PGP key security ring
 0       beshort         0x9500                  text/PGP key security ring
 0       beshort         0x9500                  text/PGP key security ring
 0       beshort         0xa600                  text/PGP encrypted data
 0       beshort         0xa600                  text/PGP encrypted data
-0       string          -----BEGIN\040PGP       text/PGP armored data 
+0       string          -----BEGIN\040PGP       text/PGP armored data
 >15     string          PUBLIC\040KEY\040BLOCK- public key block
 >15     string          PUBLIC\040KEY\040BLOCK- public key block
 >15     string          MESSAGE-                message
 >15     string          MESSAGE-                message
 >15     string          SIGNED\040MESSAGE-      signed message
 >15     string          SIGNED\040MESSAGE-      signed message
@@ -777,7 +776,7 @@
 0       beshort         0x8501                  data
 0       beshort         0x8501                  data
 #
 #
 # GnuPG Magic:
 # GnuPG Magic:
-# 
+#
 0       beshort         0x9901                  text/GnuPG key public ring
 0       beshort         0x9901                  text/GnuPG key public ring
 0       beshort         0x8501                  text/OpenPGP data
 0       beshort         0x8501                  text/OpenPGP data
 
 
@@ -787,7 +786,7 @@
 #
 #
 #       http://www.macromedia.com/software/flash/open/
 #       http://www.macromedia.com/software/flash/open/
 #
 #
-0	string		FWS             
+0	string		FWS
 >3	byte		x			application/x-shockwave-flash
 >3	byte		x			application/x-shockwave-flash
 
 
 # The following paramaters are created for Namazu.
 # The following paramaters are created for Namazu.
@@ -914,7 +913,7 @@
 #0	string	\000\000\001\000	image/x-ico
 #0	string	\000\000\001\000	image/x-ico
 
 
 # Quark Xpress 3 Files:
 # Quark Xpress 3 Files:
-# (made the mimetype up) 
+# (made the mimetype up)
 0	string	\0\0MMXPR3\0	application/x-quark-xpress-3
 0	string	\0\0MMXPR3\0	application/x-quark-xpress-3
 
 
 # EET archive
 # EET archive
@@ -924,3 +923,16 @@
 # From: Denis Knauf, via gentoo.
 # From: Denis Knauf, via gentoo.
 0	string	fLaC		audio/x-flac
 0	string	fLaC		audio/x-flac
 0	string	CWS		application/x-shockwave-flash
 0	string	CWS		application/x-shockwave-flash
+
+# Hangul Document Files:
+# Reversed-engineered HWP magic numbers
+# From: Won-Kyu Park <wkpark@kldp.org>
+512	string		R\0o\0o\0t\0	application/x-hwp
+
+0	string/c	BEGIN:VCARD	text/x-vcard
+0	string		WordPro\0	application/vnd.lotus-wordpro
+0	string		WordPro\r\373	application/vnd.lotus-wordpro
+0	string		CPC\262		image/cpi
+
+# 
+128	string		DICM		application/dicom

+ 2 - 1
magic/magic2mime

@@ -1,6 +1,6 @@
 #! /usr/bin/env perl
 #! /usr/bin/env perl
 # -*- PERL -*-
 # -*- PERL -*-
-# $Id: magic2mime,v 1.3 2006/03/02 22:10:26 christos Exp $
+# $Id: magic2mime,v 1.4 2006/11/25 18:36:10 christos Exp $
 # Copyright (c) 1996, 1997 vax@linkdead.paranoia.com (VaX#n8)
 # Copyright (c) 1996, 1997 vax@linkdead.paranoia.com (VaX#n8)
 #
 #
 # Usage: echo 'your-file-output-here' | file_to_ctype.pl
 # Usage: echo 'your-file-output-here' | file_to_ctype.pl
@@ -42,6 +42,7 @@
 	'^Sun/NeXT audio data', 'audio/basic',
 	'^Sun/NeXT audio data', 'audio/basic',
     '^MPEG', 'video/mpeg',
     '^MPEG', 'video/mpeg',
     '^Apple QuickTime movie', 'video/quicktime',
     '^Apple QuickTime movie', 'video/quicktime',
+    '^DICOM medical imaging data', 'application/dicom',
 	# made up by me
 	# made up by me
     '^bitmap', 'image/x-bitmap',
     '^bitmap', 'image/x-bitmap',
     '^PC bitmap data, Windows 3.x format', 'image/x-msw3bmp',
     '^PC bitmap data, Windows 3.x format', 'image/x-msw3bmp',

+ 85 - 61
missing

@@ -1,6 +1,10 @@
 #! /bin/sh
 #! /bin/sh
 # Common stub for a few missing GNU programs while installing.
 # Common stub for a few missing GNU programs while installing.
-# Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
+
+scriptversion=2005-06-08.21
+
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005
+#   Free Software Foundation, Inc.
 # Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
 # Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
 
 
 # This program is free software; you can redistribute it and/or modify
 # This program is free software; you can redistribute it and/or modify
@@ -15,8 +19,8 @@
 
 
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
 
 
 # As a special exception to the GNU General Public License, if you
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # distribute this file as part of a program that contains a
@@ -38,18 +42,24 @@ else
   configure_ac=configure.in
   configure_ac=configure.in
 fi
 fi
 
 
+msg="missing on your system"
+
 case "$1" in
 case "$1" in
 --run)
 --run)
   # Try to run requested program, and just exit if it succeeds.
   # Try to run requested program, and just exit if it succeeds.
   run=
   run=
   shift
   shift
   "$@" && exit 0
   "$@" && 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)
   -h|--h|--he|--hel|--help)
     echo "\
     echo "\
@@ -74,11 +84,15 @@ Supported PROGRAM values:
   lex          create \`lex.yy.c', if possible, from existing .c
   lex          create \`lex.yy.c', if possible, from existing .c
   makeinfo     touch the output file
   makeinfo     touch the output file
   tar          try tar, gnutar, gtar, then tar without non-portable flags
   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@gnu.org>."
+    exit $?
     ;;
     ;;
 
 
   -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
   -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
-    echo "missing 0.4 - GNU automake"
+    echo "missing $scriptversion (GNU Automake)"
+    exit $?
     ;;
     ;;
 
 
   -*)
   -*)
@@ -87,14 +101,44 @@ Supported PROGRAM values:
     exit 1
     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
     if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
        # We have it, but it failed.
        # We have it, but it failed.
        exit 1
        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
     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 "\
     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
          you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
          to install the \`Automake' and \`Perl' packages.  Grab them from
          to install the \`Automake' and \`Perl' packages.  Grab them from
          any GNU archive site."
          any GNU archive site."
@@ -102,13 +146,8 @@ WARNING: \`$1' is missing on your system.  You should only need it if
     ;;
     ;;
 
 
   autoconf)
   autoconf)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
     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
          you modified \`${configure_ac}'.  You might want to install the
          \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
          \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
          archive site."
          archive site."
@@ -116,13 +155,8 @@ WARNING: \`$1' is missing on your system.  You should only need it if
     ;;
     ;;
 
 
   autoheader)
   autoheader)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
     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
          you modified \`acconfig.h' or \`${configure_ac}'.  You might want
          to install the \`Autoconf' and \`GNU m4' packages.  Grab them
          to install the \`Autoconf' and \`GNU m4' packages.  Grab them
          from any GNU archive site."
          from any GNU archive site."
@@ -140,13 +174,8 @@ WARNING: \`$1' is missing on your system.  You should only need it if
     ;;
     ;;
 
 
   automake*)
   automake*)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
     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 modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
          You might want to install the \`Automake' and \`Perl' packages.
          You might want to install the \`Automake' and \`Perl' packages.
          Grab them from any GNU archive site."
          Grab them from any GNU archive site."
@@ -156,16 +185,11 @@ WARNING: \`$1' is missing on your system.  You should only need it if
     ;;
     ;;
 
 
   autom4te)
   autom4te)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
     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.
          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."
          archive site."
 
 
     file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
     file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
@@ -185,7 +209,7 @@ WARNING: \`$1' is needed, and you do not seem to have it handy on your
 
 
   bison|yacc)
   bison|yacc)
     echo 1>&2 "\
     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
          you modified a \`.y' file.  You may need the \`Bison' package
          in order for those modifications to take effect.  You can get
          in order for those modifications to take effect.  You can get
          \`Bison' from any GNU archive site."
          \`Bison' from any GNU archive site."
@@ -215,7 +239,7 @@ WARNING: \`$1' is missing on your system.  You should only need it if
 
 
   lex|flex)
   lex|flex)
     echo 1>&2 "\
     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
          you modified a \`.l' file.  You may need the \`Flex' package
          in order for those modifications to take effect.  You can get
          in order for those modifications to take effect.  You can get
          \`Flex' from any GNU archive site."
          \`Flex' from any GNU archive site."
@@ -237,13 +261,8 @@ WARNING: \`$1' is missing on your system.  You should only need it if
     ;;
     ;;
 
 
   help2man)
   help2man)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
     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
 	 you modified a dependency of a manual page.  You may need the
 	 \`Help2man' package in order for those modifications to take
 	 \`Help2man' package in order for those modifications to take
 	 effect.  You can get \`Help2man' from any GNU archive site."
 	 effect.  You can get \`Help2man' from any GNU archive site."
@@ -262,32 +281,30 @@ WARNING: \`$1' is missing on your system.  You should only need it if
     ;;
     ;;
 
 
   makeinfo)
   makeinfo)
-    if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then
-       # We have makeinfo, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
     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
          you modified a \`.texi' or \`.texinfo' file, or any other file
          indirectly affecting the aspect of the manual.  The spurious
          indirectly affecting the aspect of the manual.  The spurious
          call might also be the consequence of using a buggy \`make' (AIX,
          call might also be the consequence of using a buggy \`make' (AIX,
          DU, IRIX).  You might want to install the \`Texinfo' package or
          DU, IRIX).  You might want to install the \`Texinfo' package or
          the \`GNU make' package.  Grab either from any GNU archive site."
          the \`GNU make' package.  Grab either from any GNU archive site."
+    # The file to touch is that specified with -o ...
     file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
     file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
     if test -z "$file"; then
     if test -z "$file"; then
-      file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
-      file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
+      # ... or it is the one specified with @setfilename ...
+      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
+      file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $infile`
+      # ... or it is derived from the source name (dir/f.texi becomes f.info)
+      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
     fi
     fi
+    # If the file does not exist, the user really needs makeinfo;
+    # let's fail without touching anything.
+    test -f $file || exit 1
     touch $file
     touch $file
     ;;
     ;;
 
 
   tar)
   tar)
     shift
     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.
     # We have already tried tar in the generic part.
     # Look for gnutar/gtar before invocation to avoid ugly error
     # Look for gnutar/gtar before invocation to avoid ugly error
@@ -323,10 +340,10 @@ WARNING: I can't seem to be able to run \`tar' with the given arguments.
 
 
   *)
   *)
     echo 1>&2 "\
     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,
          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
          this package.  You may also peek at any GNU archive site, in case
          some other package would contain this missing \`$1' program."
          some other package would contain this missing \`$1' program."
     exit 1
     exit 1
@@ -334,3 +351,10 @@ WARNING: \`$1' is needed, and you do not seem to have it handy on your
 esac
 esac
 
 
 exit 0
 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:

+ 119 - 60
mkinstalldirs

@@ -1,29 +1,56 @@
 #! /bin/sh
 #! /bin/sh
 # mkinstalldirs --- make directory hierarchy
 # mkinstalldirs --- make directory hierarchy
-# Author: Noah Friedman <friedman@prep.ai.mit.edu>
+
+scriptversion=2005-06-29.22
+
+# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
 # Created: 1993-05-16
 # Created: 1993-05-16
-# Public domain
+# Public domain.
+#
+# This file is maintained in Automake, please report
+# bugs to <bug-automake@gnu.org> or send patches to
+# <automake-patches@gnu.org>.
 
 
 errstatus=0
 errstatus=0
-dirmode=""
+dirmode=
 
 
 usage="\
 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@gnu.org>."
 
 
 # process command line arguments
 # process command line arguments
 while test $# -gt 0 ; do
 while test $# -gt 0 ; do
-   case "${1}" in
-     -h | --help | --h* )			# -h for help
-	echo "${usage}" 1>&2; exit 0 ;;
-     -m )					# -m PERM arg
-	shift
-	test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
-	dirmode="${1}"
-	shift ;;
-     -- ) shift; break ;;			# stop option processing
-     -* ) echo "${usage}" 1>&2; exit 1 ;;	# unknown option
-     * )  break ;;				# first non-opt arg
-   esac
+  case $1 in
+    -h | --help | --h*)         # -h for help
+      echo "$usage"
+      exit $?
+      ;;
+    -m)                         # -m PERM arg
+      shift
+      test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
+      dirmode=$1
+      shift
+      ;;
+    --version)
+      echo "$0 $scriptversion"
+      exit $?
+      ;;
+    --)                         # stop option processing
+      shift
+      break
+      ;;
+    -*)                         # unknown option
+      echo "$usage" 1>&2
+      exit 1
+      ;;
+    *)                          # first non-opt arg
+      break
+      ;;
+  esac
 done
 done
 
 
 for file
 for file
@@ -36,64 +63,96 @@ do
 done
 done
 
 
 case $# in
 case $# in
-0) exit 0 ;;
+  0) exit 0 ;;
 esac
 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
 case $dirmode in
-'')
-  if mkdir -p -- . 2>/dev/null; then
-    echo "mkdir -p -- $*"
-    exec mkdir -p -- "$@"
-  fi ;;
-*)
-  if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
-    echo "mkdir -m $dirmode -p -- $*"
-    exec mkdir -m "$dirmode" -p -- "$@"
-  fi ;;
+  '')
+    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 --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
 esac
 
 
 for file
 for file
 do
 do
-   set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
-   shift
-
-   pathcomp=
-   for d
-   do
-     pathcomp="$pathcomp$d"
-     case "$pathcomp" in
-       -* ) pathcomp=./$pathcomp ;;
-     esac
-
-     if test ! -d "$pathcomp"; then
-	echo "mkdir $pathcomp"
-
-	mkdir "$pathcomp" || lasterr=$?
-
-	if test ! -d "$pathcomp"; then
-	  errstatus=$lasterr
-	else
-	  if test ! -z "$dirmode"; then
-	     echo "chmod $dirmode $pathcomp"
-
-	     lasterr=""
-	     chmod "$dirmode" "$pathcomp" || lasterr=$?
-
-	     if test ! -z "$lasterr"; then
-	       errstatus=$lasterr
-	     fi
+  case $file in
+    /*) pathcomp=/ ;;
+    *)  pathcomp= ;;
+  esac
+  oIFS=$IFS
+  IFS=/
+  set fnord $file
+  shift
+  IFS=$oIFS
+
+  for d
+  do
+    test "x$d" = x && continue
+
+    pathcomp=$pathcomp$d
+    case $pathcomp in
+      -*) pathcomp=./$pathcomp ;;
+    esac
+
+    if test ! -d "$pathcomp"; then
+      echo "mkdir $pathcomp"
+
+      mkdir "$pathcomp" || lasterr=$?
+
+      if test ! -d "$pathcomp"; then
+	errstatus=$lasterr
+      else
+	if test ! -z "$dirmode"; then
+	  echo "chmod $dirmode $pathcomp"
+	  lasterr=
+	  chmod "$dirmode" "$pathcomp" || lasterr=$?
+
+	  if test ! -z "$lasterr"; then
+	    errstatus=$lasterr
 	  fi
 	  fi
 	fi
 	fi
-     fi
+      fi
+    fi
 
 
-     pathcomp="$pathcomp/"
-   done
+    pathcomp=$pathcomp/
+  done
 done
 done
 
 
 exit $errstatus
 exit $errstatus
 
 
 # Local Variables:
 # Local Variables:
 # mode: shell-script
 # mode: shell-script
-# sh-indentation: 3
+# 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:
 # End:
-# mkinstalldirs ends here

+ 302 - 170
src/apprentice.c

@@ -36,6 +36,7 @@
 #include <unistd.h>
 #include <unistd.h>
 #endif
 #endif
 #include <string.h>
 #include <string.h>
+#include <assert.h>
 #include <ctype.h>
 #include <ctype.h>
 #include <fcntl.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
@@ -45,7 +46,7 @@
 #endif
 #endif
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$Id: apprentice.c,v 1.87 2006/03/02 22:08:57 christos Exp $")
+FILE_RCSID("@(#)$Id: apprentice.c,v 1.100 2006/12/11 21:48:49 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 #define	EATAB {while (isascii((unsigned char) *l) && \
 #define	EATAB {while (isascii((unsigned char) *l) && \
@@ -86,12 +87,17 @@ struct magic_entry {
 	uint32_t max_count;
 	uint32_t max_count;
 };
 };
 
 
+const int file_formats[] = { FILE_FORMAT_STRING };
+const size_t file_nformats = sizeof(file_formats) / sizeof(file_formats[0]);
+const char *file_names[] = { FILE_FORMAT_NAME };
+const size_t file_nnames = sizeof(file_names) / sizeof(file_names[0]);
+
 private int getvalue(struct magic_set *ms, struct magic *, const char **);
 private int getvalue(struct magic_set *ms, struct magic *, const char **);
 private int hextoint(int);
 private int hextoint(int);
 private const char *getstr(struct magic_set *, const char *, char *, int,
 private const char *getstr(struct magic_set *, const char *, char *, int,
     int *);
     int *);
 private int parse(struct magic_set *, struct magic_entry **, uint32_t *,
 private int parse(struct magic_set *, struct magic_entry **, uint32_t *,
-    const char *, int);
+    const char *, size_t, int);
 private void eatsize(const char **);
 private void eatsize(const char **);
 private int apprentice_1(struct magic_set *, const char *, int, struct mlist *);
 private int apprentice_1(struct magic_set *, const char *, int, struct mlist *);
 private size_t apprentice_magic_strength(const struct magic *);
 private size_t apprentice_magic_strength(const struct magic *);
@@ -102,11 +108,13 @@ private void byteswap(struct magic *, uint32_t);
 private void bs1(struct magic *);
 private void bs1(struct magic *);
 private uint16_t swap2(uint16_t);
 private uint16_t swap2(uint16_t);
 private uint32_t swap4(uint32_t);
 private uint32_t swap4(uint32_t);
+private uint64_t swap8(uint64_t);
 private char *mkdbname(const char *, char *, size_t, int);
 private char *mkdbname(const char *, char *, size_t, int);
 private int apprentice_map(struct magic_set *, struct magic **, uint32_t *,
 private int apprentice_map(struct magic_set *, struct magic **, uint32_t *,
     const char *);
     const char *);
 private int apprentice_compile(struct magic_set *, struct magic **, uint32_t *,
 private int apprentice_compile(struct magic_set *, struct magic **, uint32_t *,
     const char *);
     const char *);
+private int check_format_type(const char *, int);
 private int check_format(struct magic_set *, struct magic *);
 private int check_format(struct magic_set *, struct magic *);
 
 
 private size_t maxmagic = 0;
 private size_t maxmagic = 0;
@@ -186,8 +194,6 @@ apprentice_1(struct magic_set *ms, const char *fn, int action,
 		mapped = 0;
 		mapped = 0;
 	}
 	}
 
 
-	if (rv == -1)
-		return rv;
 	mapped = rv;
 	mapped = rv;
 	     
 	     
 	if (magic == NULL || nmagic == 0) {
 	if (magic == NULL || nmagic == 0) {
@@ -197,7 +203,7 @@ apprentice_1(struct magic_set *ms, const char *fn, int action,
 
 
 	if ((ml = malloc(sizeof(*ml))) == NULL) {
 	if ((ml = malloc(sizeof(*ml))) == NULL) {
 		file_delmagic(magic, mapped, nmagic);
 		file_delmagic(magic, mapped, nmagic);
-		file_oomem(ms);
+		file_oomem(ms, sizeof(*ml));
 		return -1;
 		return -1;
 	}
 	}
 
 
@@ -243,6 +249,7 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
 	char *p, *mfn, *afn = NULL;
 	char *p, *mfn, *afn = NULL;
 	int file_err, errs = -1;
 	int file_err, errs = -1;
 	struct mlist *mlist;
 	struct mlist *mlist;
+	static const char mime[] = ".mime";
 
 
 	if (fn == NULL)
 	if (fn == NULL)
 		fn = getenv("MAGIC");
 		fn = getenv("MAGIC");
@@ -250,13 +257,13 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
 		fn = MAGIC;
 		fn = MAGIC;
 
 
 	if ((fn = mfn = strdup(fn)) == NULL) {
 	if ((fn = mfn = strdup(fn)) == NULL) {
-		file_oomem(ms);
+		file_oomem(ms, strlen(fn));
 		return NULL;
 		return NULL;
 	}
 	}
 
 
 	if ((mlist = malloc(sizeof(*mlist))) == NULL) {
 	if ((mlist = malloc(sizeof(*mlist))) == NULL) {
 		free(mfn);
 		free(mfn);
-		file_oomem(ms);
+		file_oomem(ms, sizeof(*mlist));
 		return NULL;
 		return NULL;
 	}
 	}
 	mlist->next = mlist->prev = mlist;
 	mlist->next = mlist->prev = mlist;
@@ -268,14 +275,15 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
 		if (*fn == '\0')
 		if (*fn == '\0')
 			break;
 			break;
 		if (ms->flags & MAGIC_MIME) {
 		if (ms->flags & MAGIC_MIME) {
-			if ((afn = malloc(strlen(fn) + 5 + 1)) == NULL) {
+			size_t len = strlen(fn) + sizeof(mime);
+			if ((afn = malloc(len)) == NULL) {
 				free(mfn);
 				free(mfn);
 				free(mlist);
 				free(mlist);
-				file_oomem(ms);
+				file_oomem(ms, len);
 				return NULL;
 				return NULL;
 			}
 			}
 			(void)strcpy(afn, fn);
 			(void)strcpy(afn, fn);
-			(void)strcat(afn, ".mime");
+			(void)strcat(afn, mime);
 			fn = afn;
 			fn = afn;
 		}
 		}
 		file_err = apprentice_1(ms, fn, action, mlist);
 		file_err = apprentice_1(ms, fn, action, mlist);
@@ -298,49 +306,107 @@ file_apprentice(struct magic_set *ms, const char *fn, int action)
 	return mlist;
 	return mlist;
 }
 }
 
 
+/*
+ * Get weight of this magic entry, for sorting purposes.
+ */
 private size_t
 private size_t
 apprentice_magic_strength(const struct magic *m)
 apprentice_magic_strength(const struct magic *m)
 {
 {
+#define MULT 10
+	size_t val = 2 * MULT;	/* baseline strength */
+
 	switch (m->type) {
 	switch (m->type) {
 	case FILE_BYTE:
 	case FILE_BYTE:
-		return 1;
+		val += 1 * MULT;
+		break;
 
 
 	case FILE_SHORT:
 	case FILE_SHORT:
 	case FILE_LESHORT:
 	case FILE_LESHORT:
 	case FILE_BESHORT:
 	case FILE_BESHORT:
-		return 2;
+		val += 2 * MULT;
+		break;
 
 
 	case FILE_LONG:
 	case FILE_LONG:
 	case FILE_LELONG:
 	case FILE_LELONG:
 	case FILE_BELONG:
 	case FILE_BELONG:
 	case FILE_MELONG:
 	case FILE_MELONG:
-		return 4;
+		val += 4 * MULT;
+		break;
 
 
 	case FILE_PSTRING:
 	case FILE_PSTRING:
 	case FILE_STRING:
 	case FILE_STRING:
-	case FILE_REGEX:
+		val += m->vallen * MULT;
+		break;
+
 	case FILE_BESTRING16:
 	case FILE_BESTRING16:
 	case FILE_LESTRING16:
 	case FILE_LESTRING16:
+		val += m->vallen * MULT / 2;
+		break;
+
 	case FILE_SEARCH:
 	case FILE_SEARCH:
-		return m->vallen;
+	case FILE_REGEX:
+		val += m->vallen;
+		break;
 
 
 	case FILE_DATE:
 	case FILE_DATE:
 	case FILE_LEDATE:
 	case FILE_LEDATE:
 	case FILE_BEDATE:
 	case FILE_BEDATE:
 	case FILE_MEDATE:
 	case FILE_MEDATE:
-		return 4;
-
 	case FILE_LDATE:
 	case FILE_LDATE:
 	case FILE_LELDATE:
 	case FILE_LELDATE:
 	case FILE_BELDATE:
 	case FILE_BELDATE:
 	case FILE_MELDATE:
 	case FILE_MELDATE:
-		return 8;
+		val += 4 * MULT;
+		break;
+
+	case FILE_QUAD:
+	case FILE_BEQUAD:
+	case FILE_LEQUAD:
+	case FILE_QDATE:
+	case FILE_LEQDATE:
+	case FILE_BEQDATE:
+	case FILE_QLDATE:
+	case FILE_LEQLDATE:
+	case FILE_BEQLDATE:
+		val += 8 * MULT;
+		break;
 
 
 	default:
 	default:
-		return 0;
+		val = 0;
+		(void)fprintf(stderr, "Bad type %d\n", m->type);
+		abort();
 	}
 	}
+
+	switch (m->reln) {
+	case 'x':	/* matches anything penalize */
+		val = 0;
+		break;
+
+	case '!':
+	case '=':	/* Exact match, prefer */
+		val += MULT;
+		break;
+
+	case '>':
+	case '<':	/* comparison match reduce strength */
+		val -= 2 * MULT;
+		break;
+
+	case '^':
+	case '&':	/* masking bits, we could count them too */
+		val -= MULT;
+		break;
+
+	default:
+		(void)fprintf(stderr, "Bad relation %c\n", m->reln);
+		abort();
+	}
+	return val;
 }
 }
 
 
+/*  
+ * Sort callback for sorting entries by "strength" (basically length)
+ */
 private int
 private int
 apprentice_sort(const void *a, const void *b)
 apprentice_sort(const void *a, const void *b)
 {
 {
@@ -370,7 +436,10 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	char line[BUFSIZ+1];
 	char line[BUFSIZ+1];
 	int errs = 0;
 	int errs = 0;
 	struct magic_entry *marray;
 	struct magic_entry *marray;
-	uint32_t marraycount, i, mentrycount;
+	uint32_t marraycount, i, mentrycount = 0;
+	size_t lineno = 0;
+
+	ms->flags |= MAGIC_CHECK;	/* Enable checks for parsed files */
 
 
 	f = fopen(ms->file = fn, "r");
 	f = fopen(ms->file = fn, "r");
 	if (f == NULL) {
 	if (f == NULL) {
@@ -381,9 +450,9 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	}
 	}
 
 
         maxmagic = MAXMAGIS;
         maxmagic = MAXMAGIS;
-	if ((marray = malloc(maxmagic * sizeof(*marray))) == NULL) {
+	if ((marray = calloc(maxmagic, sizeof(*marray))) == NULL) {
 		(void)fclose(f);
 		(void)fclose(f);
-		file_oomem(ms);
+		file_oomem(ms, maxmagic * sizeof(*marray));
 		return -1;
 		return -1;
 	}
 	}
 	marraycount = 0;
 	marraycount = 0;
@@ -392,17 +461,21 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	if (action == FILE_CHECK)
 	if (action == FILE_CHECK)
 		(void)fprintf(stderr, "%s\n", hdr);
 		(void)fprintf(stderr, "%s\n", hdr);
 
 
-	/* parse it */
+	/* read and parse this file */
 	for (ms->line = 1; fgets(line, BUFSIZ, f) != NULL; ms->line++) {
 	for (ms->line = 1; fgets(line, BUFSIZ, f) != NULL; ms->line++) {
 		size_t len;
 		size_t len;
-		if (line[0] == '#')	/* comment, do not parse */
-			continue;
 		len = strlen(line);
 		len = strlen(line);
-		if (len < 2) /* null line, garbage, etc */
+		if (len == 0) /* null line, garbage, etc */
 			continue;
 			continue;
-		if (line[len - 1] == '\n')
+		if (line[len - 1] == '\n') {
+			lineno++;
 			line[len - 1] = '\0'; /* delete newline */
 			line[len - 1] = '\0'; /* delete newline */
-		if (parse(ms, &marray, &marraycount, line, action) != 0)
+		}
+		if (line[0] == '\0')	/* empty, do not parse */
+			continue;
+		if (line[0] == '#')	/* comment, do not parse */
+			continue;
+		if (parse(ms, &marray, &marraycount, line, lineno, action) != 0)
 			errs++;
 			errs++;
 	}
 	}
 
 
@@ -414,11 +487,11 @@ apprentice_file(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 	qsort(marray, marraycount, sizeof(*marray), apprentice_sort);
 	qsort(marray, marraycount, sizeof(*marray), apprentice_sort);
 #endif
 #endif
 
 
-	for (i = 0, mentrycount = 0; i < marraycount; i++)
+	for (i = 0; i < marraycount; i++)
 		mentrycount += marray[i].cont_count;
 		mentrycount += marray[i].cont_count;
 
 
 	if ((*magicp = malloc(sizeof(**magicp) * mentrycount)) == NULL) {
 	if ((*magicp = malloc(sizeof(**magicp) * mentrycount)) == NULL) {
-		file_oomem(ms);
+		file_oomem(ms, sizeof(**magicp) * mentrycount);
 		errs++;
 		errs++;
 		goto out;
 		goto out;
 	}
 	}
@@ -447,8 +520,8 @@ out:
 /*
 /*
  * extend the sign bit if the comparison is to be signed
  * extend the sign bit if the comparison is to be signed
  */
  */
-protected uint32_t
-file_signextend(struct magic_set *ms, struct magic *m, uint32_t v)
+protected uint64_t
+file_signextend(struct magic_set *ms, struct magic *m, uint64_t v)
 {
 {
 	if (!(m->flag & UNSIGNED))
 	if (!(m->flag & UNSIGNED))
 		switch(m->type) {
 		switch(m->type) {
@@ -479,6 +552,17 @@ file_signextend(struct magic_set *ms, struct magic *m, uint32_t v)
 		case FILE_MELONG:
 		case FILE_MELONG:
 			v = (int32_t) v;
 			v = (int32_t) v;
 			break;
 			break;
+		case FILE_QUAD:
+		case FILE_BEQUAD:
+		case FILE_LEQUAD:
+		case FILE_QDATE:
+		case FILE_QLDATE:
+		case FILE_BEQDATE:
+		case FILE_BEQLDATE:
+		case FILE_LEQDATE:
+		case FILE_LEQLDATE:
+			v = (int64_t) v;
+			break;
 		case FILE_STRING:
 		case FILE_STRING:
 		case FILE_PSTRING:
 		case FILE_PSTRING:
 		case FILE_BESTRING16:
 		case FILE_BESTRING16:
@@ -500,16 +584,16 @@ file_signextend(struct magic_set *ms, struct magic *m, uint32_t v)
  */
  */
 private int
 private int
 parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, 
 parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp, 
-    const char *line, int action)
+    const char *line, size_t lineno, int action)
 {
 {
-	int i = 0;
+	size_t i;
 	struct magic_entry *me;
 	struct magic_entry *me;
 	struct magic *m;
 	struct magic *m;
 	const char *l = line;
 	const char *l = line;
 	char *t;
 	char *t;
 	private const char *fops = FILE_OPS;
 	private const char *fops = FILE_OPS;
-	uint32_t val;
-	uint32_t cont_level, cont_count;
+	uint64_t val;
+	uint32_t cont_level;
 
 
 	cont_level = 0;
 	cont_level = 0;
 
 
@@ -531,7 +615,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 			struct magic *nm;
 			struct magic *nm;
 			size_t cnt = me->max_count + ALLOC_CHUNK;
 			size_t cnt = me->max_count + ALLOC_CHUNK;
 			if ((nm = realloc(me->mp, sizeof(*nm) * cnt)) == NULL) {
 			if ((nm = realloc(me->mp, sizeof(*nm) * cnt)) == NULL) {
-				file_oomem(ms);
+				file_oomem(ms, sizeof(*nm) * cnt);
 				return -1;
 				return -1;
 			}
 			}
 			me->mp = m = nm;
 			me->mp = m = nm;
@@ -547,7 +631,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 			maxmagic += ALLOC_INCR;
 			maxmagic += ALLOC_INCR;
 			if ((mp = realloc(*mentryp, sizeof(*mp) * maxmagic)) ==
 			if ((mp = realloc(*mentryp, sizeof(*mp) * maxmagic)) ==
 			    NULL) {
 			    NULL) {
-				file_oomem(ms);
+				file_oomem(ms, sizeof(*mp) * maxmagic);
 				return -1;
 				return -1;
 			}
 			}
 			(void)memset(&mp[*nmentryp], 0, sizeof(*mp) *
 			(void)memset(&mp[*nmentryp], 0, sizeof(*mp) *
@@ -557,7 +641,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 		me = &(*mentryp)[*nmentryp];
 		me = &(*mentryp)[*nmentryp];
 		if (me->mp == NULL) {
 		if (me->mp == NULL) {
 			if ((m = malloc(sizeof(*m) * ALLOC_CHUNK)) == NULL) {
 			if ((m = malloc(sizeof(*m) * ALLOC_CHUNK)) == NULL) {
-				file_oomem(ms);
+				file_oomem(ms, sizeof(*m) * ALLOC_CHUNK);
 				return -1;
 				return -1;
 			}
 			}
 			me->mp = m;
 			me->mp = m;
@@ -568,6 +652,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 		m->cont_level = 0;
 		m->cont_level = 0;
 		me->cont_count = 1;
 		me->cont_count = 1;
 	}
 	}
+	m->lineno = lineno;
 
 
 	if (m->cont_level != 0 && *l == '&') {
 	if (m->cont_level != 0 && *l == '&') {
                 ++l;            /* step over */
                 ++l;            /* step over */
@@ -690,105 +775,21 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 		++l;
 		++l;
 	EATAB;
 	EATAB;
 
 
-#define NBYTE		4
-#define NSHORT		5
-#define NLONG		4
-#define NSTRING 	6
-#define NDATE		4
-#define NBESHORT	7
-#define NBELONG		6
-#define NBEDATE		6
-#define NLESHORT	7
-#define NLELONG		6
-#define NMELONG		6
-#define NLEDATE		6
-#define NMEDATE		6
-#define NPSTRING	7
-#define NLDATE		5
-#define NBELDATE	7
-#define NLELDATE	7
-#define NMELDATE	7
-#define NREGEX		5
-#define NBESTRING16	10
-#define NLESTRING16	10
-#define NSEARCH		6
-
 	if (*l == 'u') {
 	if (*l == 'u') {
 		++l;
 		++l;
 		m->flag |= UNSIGNED;
 		m->flag |= UNSIGNED;
 	}
 	}
 
 
 	/* get type, skip it */
 	/* get type, skip it */
-	if (strncmp(l, "char", NBYTE)==0) {	/* HP/UX compat */
-		m->type = FILE_BYTE;
-		l += NBYTE;
-	} else if (strncmp(l, "byte", NBYTE)==0) {
-		m->type = FILE_BYTE;
-		l += NBYTE;
-	} else if (strncmp(l, "short", NSHORT)==0) {
-		m->type = FILE_SHORT;
-		l += NSHORT;
-	} else if (strncmp(l, "long", NLONG)==0) {
-		m->type = FILE_LONG;
-		l += NLONG;
-	} else if (strncmp(l, "string", NSTRING)==0) {
-		m->type = FILE_STRING;
-		l += NSTRING;
-	} else if (strncmp(l, "date", NDATE)==0) {
-		m->type = FILE_DATE;
-		l += NDATE;
-	} else if (strncmp(l, "beshort", NBESHORT)==0) {
-		m->type = FILE_BESHORT;
-		l += NBESHORT;
-	} else if (strncmp(l, "belong", NBELONG)==0) {
-		m->type = FILE_BELONG;
-		l += NBELONG;
-	} else if (strncmp(l, "bedate", NBEDATE)==0) {
-		m->type = FILE_BEDATE;
-		l += NBEDATE;
-	} else if (strncmp(l, "leshort", NLESHORT)==0) {
-		m->type = FILE_LESHORT;
-		l += NLESHORT;
-	} else if (strncmp(l, "lelong", NLELONG)==0) {
-		m->type = FILE_LELONG;
-		l += NLELONG;
-	} else if (strncmp(l, "melong", NMELONG)==0) {
-		m->type = FILE_MELONG;
-		l += NMELONG;
-	} else if (strncmp(l, "ledate", NLEDATE)==0) {
-		m->type = FILE_LEDATE;
-		l += NLEDATE;
-	} else if (strncmp(l, "medate", NMEDATE)==0) {
-		m->type = FILE_MEDATE;
-		l += NMEDATE;
-	} else if (strncmp(l, "pstring", NPSTRING)==0) {
-		m->type = FILE_PSTRING;
-		l += NPSTRING;
-	} else if (strncmp(l, "ldate", NLDATE)==0) {
-		m->type = FILE_LDATE;
-		l += NLDATE;
-	} else if (strncmp(l, "beldate", NBELDATE)==0) {
-		m->type = FILE_BELDATE;
-		l += NBELDATE;
-	} else if (strncmp(l, "leldate", NLELDATE)==0) {
-		m->type = FILE_LELDATE;
-		l += NLELDATE;
-	} else if (strncmp(l, "meldate", NMELDATE)==0) {
-		m->type = FILE_MELDATE;
-		l += NMELDATE;
-	} else if (strncmp(l, "regex", NREGEX)==0) {
-		m->type = FILE_REGEX;
-		l += NREGEX;
-	} else if (strncmp(l, "bestring16", NBESTRING16)==0) {
-		m->type = FILE_BESTRING16;
-		l += NBESTRING16;
-	} else if (strncmp(l, "lestring16", NLESTRING16)==0) {
-		m->type = FILE_LESTRING16;
-		l += NLESTRING16;
-	} else if (strncmp(l, "search", NSEARCH)==0) {
-		m->type = FILE_SEARCH;
-		l += NSEARCH;
-	} else {
+	for (i = 0; i < file_nnames; i++) {
+		size_t len = strlen(file_names[i]);
+		if (strncmp(l, file_names[i], len) == 0) {
+			m->type = i;
+			l+= len;
+			break;
+		}
+	}
+	if (i == file_nnames) {
 		if (ms->flags & MAGIC_CHECK)
 		if (ms->flags & MAGIC_CHECK)
 			file_magwarn(ms, "type `%s' invalid", l);
 			file_magwarn(ms, "type `%s' invalid", l);
 		return -1;
 		return -1;
@@ -805,7 +806,7 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
 		if (op != FILE_OPDIVIDE || !IS_PLAINSTRING(m->type)) {
 		if (op != FILE_OPDIVIDE || !IS_PLAINSTRING(m->type)) {
 			++l;
 			++l;
 			m->mask_op |= op;
 			m->mask_op |= op;
-			val = (uint32_t)strtoul(l, &t, 0);
+			val = (uint64_t)strtoull(l, &t, 0);
 			l = t;
 			l = t;
 			m->mask = file_signextend(ms, m, val);
 			m->mask = file_signextend(ms, m, val);
 			eatsize(&l);
 			eatsize(&l);
@@ -892,11 +893,20 @@ GetDesc:
 		m->nospflag = 1;
 		m->nospflag = 1;
 	} else
 	} else
 		m->nospflag = 0;
 		m->nospflag = 0;
-	while ((m->desc[i++] = *l++) != '\0' && i < MAXDESC)
-		/* NULLBODY */;
+	for (i = 0; (m->desc[i++] = *l++) != '\0' && i < sizeof(m->desc); )
+		continue;
+	if (i == sizeof(m->desc)) {
+		m->desc[sizeof(m->desc) - 1] = '\0';
+		if (ms->flags & MAGIC_CHECK)
+			file_magwarn(ms, "description `%s' truncated", m->desc);
+	}
 
 
-	if (ms->flags & MAGIC_CHECK) {
-		if (!check_format(ms, m))
+        /*
+	 * We only do this check while compiling, or if any of the magic
+	 * files were not compiled.
+         */
+        if (ms->flags & MAGIC_CHECK) {
+		if (check_format(ms, m) == -1)
 			return -1;
 			return -1;
 	}
 	}
 #ifndef COMPILE_ONLY
 #ifndef COMPILE_ONLY
@@ -909,6 +919,105 @@ GetDesc:
 	return 0;
 	return 0;
 }
 }
 
 
+private int
+check_format_type(const char *ptr, int type)
+{
+	int quad = 0;
+	if (*ptr == '\0') {
+		/* Missing format string; bad */
+		return -1;
+	}
+
+	switch (type) {
+	case FILE_FMT_QUAD:
+		quad = 1;
+		/*FALLTHROUGH*/
+	case FILE_FMT_NUM:
+		if (*ptr == '-')
+			ptr++;
+		if (*ptr == '.')
+			ptr++;
+		while (isdigit((unsigned char)*ptr)) ptr++;
+		if (*ptr == '.')
+			ptr++;
+		while (isdigit((unsigned char)*ptr)) ptr++;
+		if (quad) {
+			if (*ptr++ != 'l')
+				return -1;
+			if (*ptr++ != 'l')
+				return -1;
+		}
+	
+		switch (*ptr++) {
+		case 'l':
+			switch (*ptr++) {
+			case 'i':
+			case 'd':
+			case 'u':
+			case 'x':
+			case 'X':
+				return 0;
+			default:
+				return -1;
+			}
+		
+		case 'h':
+			switch (*ptr++) {
+			case 'h':
+				switch (*ptr++) {
+				case 'i':
+				case 'd':
+				case 'u':
+				case 'x':
+				case 'X':
+					return 0;
+				default:
+					return -1;
+				}
+			case 'd':
+				return 0;
+			default:
+				return -1;
+			}
+
+		case 'i':
+		case 'c':
+		case 'd':
+		case 'u':
+		case 'x':
+		case 'X':
+			return 0;
+			
+		default:
+			return -1;
+		}
+		
+	case FILE_FMT_STR:
+		if (*ptr == '-')
+			ptr++;
+		while (isdigit((unsigned char )*ptr))
+			ptr++;
+		if (*ptr == '.') {
+			ptr++;
+			while (isdigit((unsigned char )*ptr))
+				ptr++;
+		}
+		
+		switch (*ptr++) {
+		case 's':
+			return 0;
+		default:
+			return -1;
+		}
+		
+	default:
+		/* internal error */
+		abort();
+	}
+	/*NOTREACHED*/
+	return -1;
+}
+	
 /*
 /*
  * Check that the optional printf format in description matches
  * Check that the optional printf format in description matches
  * the type of the magic.
  * the type of the magic.
@@ -916,8 +1025,6 @@ GetDesc:
 private int
 private int
 check_format(struct magic_set *ms, struct magic *m)
 check_format(struct magic_set *ms, struct magic *m)
 {
 {
-	static const char *formats[] = { FILE_FORMAT_STRING };
-	static const char *names[] = { FILE_FORMAT_NAME };
 	char *ptr;
 	char *ptr;
 
 
 	for (ptr = m->desc; *ptr; ptr++)
 	for (ptr = m->desc; *ptr; ptr++)
@@ -927,37 +1034,42 @@ check_format(struct magic_set *ms, struct magic *m)
 		/* No format string; ok */
 		/* No format string; ok */
 		return 1;
 		return 1;
 	}
 	}
-	if (m->type >= sizeof(formats)/sizeof(formats[0])) {
-		file_magwarn(ms, "Internal error inconsistency between m->type"
-		    " and format strings");
-		return 0;
+
+	assert(file_nformats == file_nnames);
+
+	if (m->type >= file_nformats) {
+		file_error(ms, 0, "Internal error inconsistency between "
+		    "m->type and format strings");		
+		return -1;
 	}
 	}
-	if (formats[m->type] == NULL) {
-		file_magwarn(ms, "No format string for `%s' with description "
-		    "`%s'", m->desc, names[m->type]);
-		return 0;
+	if (file_formats[m->type] == FILE_FMT_NONE) {
+		file_error(ms, 0, "No format string for `%s' with description "
+		    "`%s'", m->desc, file_names[m->type]);
+		return -1;
+	}
+
+	ptr++;
+	if (check_format_type(ptr, file_formats[m->type]) == -1) {
+		/*
+		 * TODO: this error message is unhelpful if the format
+		 * string is not one character long
+		 */
+		file_error(ms, 0, "Printf format `%c' is not valid for type "
+		    " `%s' in description `%s'", *ptr,
+		    file_names[m->type], m->desc);
+		return -1;
 	}
 	}
+	
 	for (; *ptr; ptr++) {
 	for (; *ptr; ptr++) {
-		if (*ptr == 'l' || *ptr == 'h') {
-			/* XXX: we should really fix this one day */
-			continue;
+		if (*ptr == '%') {
+			file_error(ms, 0,
+			    "Too many format strings (should have at most one) "
+			    "for `%s' with description `%s'",
+			    file_names[m->type], m->desc);
+			return -1;
 		}
 		}
-		if (islower((unsigned char)*ptr) || *ptr == 'X')
-			break;
-	}
-	if (*ptr == '\0') {
-		/* Missing format string; bad */
-		file_magwarn(ms, "Invalid format `%s' for type `%s'",
-			m->desc, names[m->type]);
-		return 0;
 	}
 	}
-	if (strchr(formats[m->type], *ptr) == NULL) {
-		file_magwarn(ms, "Printf format `%c' is not valid for type `%s'"
-		    " in description `%s'",
-			*ptr, names[m->type], m->desc);
-		return 0;
-	}
-	return 1;
+	return 0;
 }
 }
 
 
 /* 
 /* 
@@ -989,8 +1101,8 @@ getvalue(struct magic_set *ms, struct magic *m, const char **p)
 	default:
 	default:
 		if (m->reln != 'x') {
 		if (m->reln != 'x') {
 			char *ep;
 			char *ep;
-			m->value.l = file_signextend(ms, m,
-			    (uint32_t)strtoul(*p, &ep, 0));
+			m->value.q = file_signextend(ms, m,
+			    (uint64_t)strtoull(*p, &ep, 0));
 			*p = ep;
 			*p = ep;
 			eatsize(p);
 			eatsize(p);
 		}
 		}
@@ -1242,7 +1354,7 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 #define RET	2
 #define RET	2
 #else
 #else
 	if ((mm = malloc((size_t)st.st_size)) == NULL) {
 	if ((mm = malloc((size_t)st.st_size)) == NULL) {
-		file_oomem(ms);
+		file_oomem(ms, (size_t)st.st_size);
 		goto error;
 		goto error;
 	}
 	}
 	if (read(fd, mm, (size_t)st.st_size) != (size_t)st.st_size) {
 	if (read(fd, mm, (size_t)st.st_size) != (size_t)st.st_size) {
@@ -1396,6 +1508,26 @@ swap4(uint32_t sv)
 }
 }
 
 
 /*
 /*
+ * swap a quad
+ */
+private uint64_t
+swap8(uint64_t sv)
+{
+	uint32_t rv;
+	uint8_t *s = (uint8_t *)(void *)&sv; 
+	uint8_t *d = (uint8_t *)(void *)&rv; 
+	d[0] = s[3];
+	d[1] = s[2];
+	d[2] = s[1];
+	d[3] = s[0];
+	d[4] = s[7];
+	d[5] = s[6];
+	d[6] = s[5];
+	d[7] = s[4];
+	return rv;
+}
+
+/*
  * byteswap a single magic entry
  * byteswap a single magic entry
  */
  */
 private void
 private void
@@ -1405,6 +1537,6 @@ bs1(struct magic *m)
 	m->offset = swap4((uint32_t)m->offset);
 	m->offset = swap4((uint32_t)m->offset);
 	m->in_offset = swap4((uint32_t)m->in_offset);
 	m->in_offset = swap4((uint32_t)m->in_offset);
 	if (!IS_STRING(m->type))
 	if (!IS_STRING(m->type))
-		m->value.l = swap4(m->value.l);
-	m->mask = swap4(m->mask);
+		m->value.q = swap8(m->value.q);
+	m->mask = swap8(m->mask);
 }
 }

+ 3 - 3
src/ascmagic.c

@@ -49,7 +49,7 @@
 #include "names.h"
 #include "names.h"
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$Id: ascmagic.c,v 1.45 2006/03/12 22:09:33 christos Exp $")
+FILE_RCSID("@(#)$Id: ascmagic.c,v 1.46 2006/10/20 21:04:15 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 typedef unsigned long unichar;
 typedef unsigned long unichar;
@@ -102,9 +102,9 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
 	while (nbytes > 1 && buf[nbytes - 1] == '\0')
 	while (nbytes > 1 && buf[nbytes - 1] == '\0')
 		nbytes--;
 		nbytes--;
 
 
-	if ((nbuf = malloc((nbytes + 1) * sizeof(nbuf[0]))) == NULL)
+	if ((nbuf = calloc(1, (nbytes + 1) * sizeof(nbuf[0]))) == NULL)
 		goto done;
 		goto done;
-	if ((ubuf = malloc((nbytes + 1) * sizeof(ubuf[0]))) == NULL)
+	if ((ubuf = calloc(1, (nbytes + 1) * sizeof(ubuf[0]))) == NULL)
 		goto done;
 		goto done;
 
 
 	/*
 	/*

+ 49 - 10
src/compress.c

@@ -42,6 +42,7 @@
 #include <string.h>
 #include <string.h>
 #include <errno.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/types.h>
+#include <sys/ioctl.h>
 #ifdef HAVE_SYS_WAIT_H
 #ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #include <sys/wait.h>
 #endif
 #endif
@@ -50,10 +51,9 @@
 #endif
 #endif
 
 
 #ifndef lint
 #ifndef lint
-FILE_RCSID("@(#)$Id: compress.c,v 1.42 2005/03/06 05:58:22 christos Exp $")
+FILE_RCSID("@(#)$Id: compress.c,v 1.45 2006/10/31 19:37:17 christos Exp $")
 #endif
 #endif
 
 
-
 private struct {
 private struct {
 	const char *magic;
 	const char *magic;
 	size_t maglen;
 	size_t maglen;
@@ -76,9 +76,10 @@ private struct {
 
 
 private int ncompr = sizeof(compr) / sizeof(compr[0]);
 private int ncompr = sizeof(compr) / sizeof(compr[0]);
 
 
+#define NODATA ((size_t)~0)
+
 
 
 private ssize_t swrite(int, const void *, size_t);
 private ssize_t swrite(int, const void *, size_t);
-private ssize_t sread(int, void *, size_t);
 private size_t uncompressbuf(struct magic_set *, int, size_t,
 private size_t uncompressbuf(struct magic_set *, int, size_t,
     const unsigned char *, unsigned char **, size_t);
     const unsigned char *, unsigned char **, size_t);
 #ifdef HAVE_LIBZ
 #ifdef HAVE_LIBZ
@@ -102,7 +103,7 @@ file_zmagic(struct magic_set *ms, int fd, const unsigned char *buf,
 			continue;
 			continue;
 		if (memcmp(buf, compr[i].magic, compr[i].maglen) == 0 &&
 		if (memcmp(buf, compr[i].magic, compr[i].maglen) == 0 &&
 		    (nsz = uncompressbuf(ms, fd, i, buf, &newbuf,
 		    (nsz = uncompressbuf(ms, fd, i, buf, &newbuf,
-		    nbytes)) != 0) {
+		    nbytes)) != NODATA) {
 			ms->flags &= ~MAGIC_COMPRESS;
 			ms->flags &= ~MAGIC_COMPRESS;
 			rv = -1;
 			rv = -1;
 			if (file_buffer(ms, -1, newbuf, nsz) == -1)
 			if (file_buffer(ms, -1, newbuf, nsz) == -1)
@@ -152,14 +153,52 @@ swrite(int fd, const void *buf, size_t n)
 /*
 /*
  * `safe' read for sockets and pipes.
  * `safe' read for sockets and pipes.
  */
  */
-private ssize_t
+protected ssize_t
 sread(int fd, void *buf, size_t n)
 sread(int fd, void *buf, size_t n)
 {
 {
 	int rv;
 	int rv;
+#ifdef FIONREAD
+	int t = 0;
+#endif
 	size_t rn = n;
 	size_t rn = n;
 
 
+	if (fd == STDIN_FILENO)
+		goto nocheck;
+
+#ifdef FIONREAD
+	if ((ioctl(fd, FIONREAD, &t) < 0) || (t == 0)) {
+#ifdef FD_ZERO
+		for (;;) {
+			fd_set check;
+			struct timeval tout = {0, 100 * 1000};
+
+			FD_ZERO(&check);
+			FD_SET(fd, &check);
+
+			/*
+			 * Avoid soft deadlock: do not read if there
+			 * is nothing to read from sockets and pipes.
+			 */
+			if (select(fd + 1, &check, NULL, NULL, &tout) <= 0) {
+				if (errno == EINTR || errno == EAGAIN)
+					continue;
+				return 0;
+			}
+			break;
+		}
+#endif
+		(void)ioctl(fd, FIONREAD, &t);
+	}
+
+	if (t > 0 && (size_t)t < n) {
+		n = t;
+		rn = n;
+	}
+#endif
+
+nocheck:
 	do
 	do
-		switch (rv = read(fd, buf, n)) {
+		switch ((rv = read(fd, buf, n))) {
 		case -1:
 		case -1:
 			if (errno == EINTR)
 			if (errno == EINTR)
 				continue;
 				continue;
@@ -305,7 +344,7 @@ uncompressgzipped(struct magic_set *ms, const unsigned char *old,
 	inflateEnd(&z);
 	inflateEnd(&z);
 	
 	
 	/* let's keep the nul-terminate tradition */
 	/* let's keep the nul-terminate tradition */
-	(*newch)[n++] = '\0';
+	(*newch)[n] = '\0';
 
 
 	return n;
 	return n;
 }
 }
@@ -327,7 +366,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
 
 
 	if ((fd != -1 && pipe(fdin) == -1) || pipe(fdout) == -1) {
 	if ((fd != -1 && pipe(fdin) == -1) || pipe(fdout) == -1) {
 		file_error(ms, errno, "cannot create pipe");	
 		file_error(ms, errno, "cannot create pipe");	
-		return 0;
+		return NODATA;
 	}
 	}
 	switch (fork()) {
 	switch (fork()) {
 	case 0:	/* child */
 	case 0:	/* child */
@@ -360,7 +399,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
 		/*NOTREACHED*/
 		/*NOTREACHED*/
 	case -1:
 	case -1:
 		file_error(ms, errno, "could not fork");
 		file_error(ms, errno, "could not fork");
-		return 0;
+		return NODATA;
 
 
 	default: /* parent */
 	default: /* parent */
 		(void) close(fdout[1]);
 		(void) close(fdout[1]);
@@ -420,7 +459,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
 			n = r;
 			n = r;
 		}
 		}
  		/* NUL terminate, as every buffer is handled here. */
  		/* NUL terminate, as every buffer is handled here. */
- 		(*newch)[n++] = '\0';
+ 		(*newch)[n] = '\0';
 err:
 err:
 		if (fdin[1] != -1)
 		if (fdin[1] != -1)
 			(void) close(fdin[1]);
 			(void) close(fdin[1]);

+ 26 - 10
src/file.c

@@ -71,7 +71,7 @@
 #include "patchlevel.h"
 #include "patchlevel.h"
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$Id: file.c,v 1.100 2005/10/17 18:41:44 christos Exp $")
+FILE_RCSID("@(#)$Id: file.c,v 1.104 2006/11/25 17:28:54 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 
 
@@ -81,7 +81,7 @@ FILE_RCSID("@(#)$Id: file.c,v 1.100 2005/10/17 18:41:44 christos Exp $")
 #define SYMLINKFLAG ""
 #define SYMLINKFLAG ""
 #endif
 #endif
 
 
-# define USAGE  "Usage: %s [-bcik" SYMLINKFLAG "nNsvz] [-f namefile] [-F separator] [-m magicfiles] file...\n       %s -C -m magicfiles\n"
+# define USAGE  "Usage: %s [-bcik" SYMLINKFLAG "nNrsvz0] [-f namefile] [-F separator] [-m magicfiles] file...\n       %s -C -m magicfiles\n"
 
 
 #ifndef MAXPATHLEN
 #ifndef MAXPATHLEN
 #define	MAXPATHLEN	512
 #define	MAXPATHLEN	512
@@ -90,7 +90,8 @@ FILE_RCSID("@(#)$Id: file.c,v 1.100 2005/10/17 18:41:44 christos Exp $")
 private int 		/* Global command-line options 		*/
 private int 		/* Global command-line options 		*/
 	bflag = 0,	/* brief output format	 		*/
 	bflag = 0,	/* brief output format	 		*/
 	nopad = 0,	/* Don't pad output			*/
 	nopad = 0,	/* Don't pad output			*/
-	nobuffer = 0;   /* Do not buffer stdout 		*/
+	nobuffer = 0,   /* Do not buffer stdout 		*/
+	nulsep = 0;	/* Append '\0' to the separator		*/
 
 
 private const char *magicfile = 0;	/* where the magic is	*/
 private const char *magicfile = 0;	/* where the magic is	*/
 private const char *default_magicfile = MAGIC;
 private const char *default_magicfile = MAGIC;
@@ -126,10 +127,11 @@ main(int argc, char *argv[])
 	int flags = 0;
 	int flags = 0;
 	char *home, *usermagic;
 	char *home, *usermagic;
 	struct stat sb;
 	struct stat sb;
-#define OPTSTRING	"bcCdf:F:hikLm:nNprsvz"
+	static const char hmagic[] = "/.magic";
+#define OPTSTRING	"bcCdf:F:hikLm:nNprsvz0"
 #ifdef HAVE_GETOPT_LONG
 #ifdef HAVE_GETOPT_LONG
 	int longindex;
 	int longindex;
-	private struct option long_options[] =
+	static const struct option long_options[] =
 	{
 	{
 		{"version", 0, 0, 'v'},
 		{"version", 0, 0, 'v'},
 		{"help", 0, 0, 0},
 		{"help", 0, 0, 0},
@@ -154,6 +156,7 @@ main(int argc, char *argv[])
 		{"no-pad", 0, 0, 'N'},
 		{"no-pad", 0, 0, 'N'},
 		{"special-files", 0, 0, 's'},
 		{"special-files", 0, 0, 's'},
 		{"compile", 0, 0, 'C'},
 		{"compile", 0, 0, 'C'},
+		{"print0", 0, 0, '0'},
 		{0, 0, 0, 0},
 		{0, 0, 0, 0},
 	};
 	};
 #endif
 #endif
@@ -178,9 +181,10 @@ main(int argc, char *argv[])
 		magicfile = usermagic;
 		magicfile = usermagic;
 	else
 	else
 		if ((home = getenv("HOME")) != NULL) {
 		if ((home = getenv("HOME")) != NULL) {
-			if ((usermagic = malloc(strlen(home) + 8)) != NULL) {
+			if ((usermagic = malloc(strlen(home)
+			    + sizeof(hmagic))) != NULL) {
 				(void)strcpy(usermagic, home);
 				(void)strcpy(usermagic, home);
-				(void)strcat(usermagic, "/.magic");
+				(void)strcat(usermagic, hmagic);
 				if (stat(usermagic, &sb)<0) 
 				if (stat(usermagic, &sb)<0) 
 					free(usermagic);
 					free(usermagic);
 				else
 				else
@@ -204,6 +208,9 @@ main(int argc, char *argv[])
 				help();
 				help();
 			break;
 			break;
 #endif
 #endif
+		case '0':
+			nulsep = 1;
+			break;
 		case 'b':
 		case 'b':
 			++bflag;
 			++bflag;
 			break;
 			break;
@@ -385,15 +392,24 @@ unwrap(char *fn)
 	(void)fclose(f);
 	(void)fclose(f);
 }
 }
 
 
+/*
+ * Called for each input file on the command line (or in a list of files)
+ */
 private void
 private void
 process(const char *inname, int wid)
 process(const char *inname, int wid)
 {
 {
 	const char *type;
 	const char *type;
 	int std_in = strcmp(inname, "-") == 0;
 	int std_in = strcmp(inname, "-") == 0;
 
 
-	if (wid > 0 && !bflag)
-		(void)printf("%s%s%*s ", std_in ? "/dev/stdin" : inname,
-		    separator, (int) (nopad ? 0 : (wid - file_mbswidth(inname))), "");
+	if (wid > 0 && !bflag) {
+		(void)printf("%s", std_in ? "/dev/stdin" : inname);
+		if (nulsep)
+			(void)puts('\0');
+		else
+			(void)printf("%s", separator);
+		(void)printf("%*s ",
+		    (int) (nopad ? 0 : (wid - file_mbswidth(inname))), "");
+	}
 
 
 	type = magic_file(magic, std_in ? NULL : inname);
 	type = magic_file(magic, std_in ? NULL : inname);
 	if (type == NULL)
 	if (type == NULL)

+ 54 - 16
src/file.h

@@ -27,7 +27,7 @@
  */
  */
 /*
 /*
  * file.h - definitions for file(1) program
  * file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.73 2005/10/20 14:59:01 christos Exp $
+ * @(#)$Id: file.h,v 1.83 2006/12/11 21:48:49 christos Exp $
  */
  */
 
 
 #ifndef __file_h__
 #ifndef __file_h__
@@ -46,6 +46,7 @@
 #ifdef HAVE_INTTYPES_H
 #ifdef HAVE_INTTYPES_H
 #include <inttypes.h>
 #include <inttypes.h>
 #endif
 #endif
+#include <sys/types.h>
 /* Do this here and now, because struct stat gets re-defined on solaris */
 /* Do this here and now, because struct stat gets re-defined on solaris */
 #include <sys/stat.h>
 #include <sys/stat.h>
 
 
@@ -73,7 +74,7 @@
 #define MAXstring 32		/* max leng of "string" types */
 #define MAXstring 32		/* max leng of "string" types */
 
 
 #define MAGICNO		0xF11E041C
 #define MAGICNO		0xF11E041C
-#define VERSIONNO	2
+#define VERSIONNO	3
 #define FILE_MAGICSIZE	(32 * 4)
 #define FILE_MAGICSIZE	(32 * 4)
 
 
 #define	FILE_LOAD	0
 #define	FILE_LOAD	0
@@ -116,6 +117,15 @@ struct magic {
 #define				FILE_MEDATE	21
 #define				FILE_MEDATE	21
 #define				FILE_MELDATE	22
 #define				FILE_MELDATE	22
 #define				FILE_MELONG	23
 #define				FILE_MELONG	23
+#define				FILE_QUAD	24
+#define				FILE_LEQUAD	25
+#define				FILE_BEQUAD	26
+#define				FILE_QDATE	27
+#define				FILE_LEQDATE	28
+#define				FILE_BEQDATE	29
+#define				FILE_QLDATE	30
+#define				FILE_LEQLDATE	31
+#define				FILE_BEQLDATE	32
 
 
 #define				FILE_FORMAT_NAME	\
 #define				FILE_FORMAT_NAME	\
 /* 0 */ 			"invalid 0",		\
 /* 0 */ 			"invalid 0",		\
@@ -141,16 +151,28 @@ struct magic {
 /* 20 */ 			"search",		\
 /* 20 */ 			"search",		\
 /* 21 */ 			"medate",		\
 /* 21 */ 			"medate",		\
 /* 22 */ 			"meldate",		\
 /* 22 */ 			"meldate",		\
-/* 23 */ 			"melong",
+/* 23 */ 			"melong",		\
+/* 24 */ 			"quad",			\
+/* 25 */ 			"lequad",		\
+/* 26 */ 			"bequad",		\
+/* 27 */ 			"qdate",		\
+/* 28 */ 			"leqdate",		\
+/* 29 */ 			"beqdate",		\
+/* 30 */ 			"qldate",		\
+/* 31 */ 			"leqldate",		\
+/* 32 */ 			"beqldate",
 
 
-#define	FILE_FMT_NUM	"cduxXi"
-#define FILE_FMT_STR	"s"	
+
+#define FILE_FMT_NONE 0
+#define FILE_FMT_NUM  1 /* "cduxXi" */
+#define FILE_FMT_STR  2 /* "s" */
+#define FILE_FMT_QUAD 3 /* "ll" */
 
 
 #define				FILE_FORMAT_STRING	\
 #define				FILE_FORMAT_STRING	\
-/* 0 */ 			NULL,			\
+/* 0 */ 			FILE_FMT_NONE,		\
 /* 1 */				FILE_FMT_NUM,		\
 /* 1 */				FILE_FMT_NUM,		\
 /* 2 */ 			FILE_FMT_NUM,		\
 /* 2 */ 			FILE_FMT_NUM,		\
-/* 3 */ 			NULL,			\
+/* 3 */ 			FILE_FMT_NONE,		\
 /* 4 */ 			FILE_FMT_NUM,		\
 /* 4 */ 			FILE_FMT_NUM,		\
 /* 5 */ 			FILE_FMT_STR,		\
 /* 5 */ 			FILE_FMT_STR,		\
 /* 6 */ 			FILE_FMT_STR,		\
 /* 6 */ 			FILE_FMT_STR,		\
@@ -170,7 +192,17 @@ struct magic {
 /* 20 */			FILE_FMT_STR,		\
 /* 20 */			FILE_FMT_STR,		\
 /* 21 */			FILE_FMT_STR,		\
 /* 21 */			FILE_FMT_STR,		\
 /* 22 */			FILE_FMT_STR,		\
 /* 22 */			FILE_FMT_STR,		\
-/* 23 */			FILE_FMT_NUM,
+/* 23 */			FILE_FMT_NUM,		\
+/* 24 */			FILE_FMT_QUAD,		\
+/* 25 */			FILE_FMT_QUAD,		\
+/* 26 */			FILE_FMT_QUAD,		\
+/* 27 */			FILE_FMT_STR,		\
+/* 28 */			FILE_FMT_STR,		\
+/* 29 */			FILE_FMT_STR,		\
+/* 30 */			FILE_FMT_STR,		\
+/* 31 */			FILE_FMT_STR,		\
+/* 32 */			FILE_FMT_STR,
+
 
 
 	/* Word 3 */
 	/* Word 3 */
 	uint8_t in_op;		/* operator for indirection */
 	uint8_t in_op;		/* operator for indirection */
@@ -193,16 +225,15 @@ struct magic {
 	/* Word 5 */
 	/* Word 5 */
 	int32_t in_offset;	/* offset from indirection */
 	int32_t in_offset;	/* offset from indirection */
 	/* Word 6 */
 	/* Word 6 */
-	uint32_t mask;	/* mask before comparison with value */
-	/* Word 7 */
-	uint32_t dummy3;
-	/* Word 8 */
-	uint32_t dummp4;
+	uint32_t lineno;	/* line number in magic file */
+	/* Word 7,8 */
+	uint64_t mask;	/* mask before comparison with value */
 	/* Words 9-16 */
 	/* Words 9-16 */
 	union VALUETYPE {
 	union VALUETYPE {
 		uint8_t b;
 		uint8_t b;
 		uint16_t h;
 		uint16_t h;
 		uint32_t l;
 		uint32_t l;
+		uint64_t q;
 		char s[MAXstring];
 		char s[MAXstring];
 		struct {
 		struct {
 			char *buf;
 			char *buf;
@@ -210,6 +241,7 @@ struct magic {
 		} search;
 		} search;
 		uint8_t hs[2];	/* 2 bytes of a fixed-endian "short" */
 		uint8_t hs[2];	/* 2 bytes of a fixed-endian "short" */
 		uint8_t hl[4];	/* 4 bytes of a fixed-endian "long" */
 		uint8_t hl[4];	/* 4 bytes of a fixed-endian "long" */
+		uint8_t hq[8];	/* 8 bytes of a fixed-endian "quad" */
 	} value;		/* either number or string */
 	} value;		/* either number or string */
 	/* Words 17..31 */
 	/* Words 17..31 */
 	char desc[MAXDESC];	/* description */
 	char desc[MAXDESC];	/* description */
@@ -250,6 +282,7 @@ struct magic_set {
 	char *pbuf;
 	char *pbuf;
 	size_t psize;
 	size_t psize;
     } o;
     } o;
+    uint32_t offset;
     int error;
     int error;
     int flags;
     int flags;
     int haderr;
     int haderr;
@@ -270,17 +303,23 @@ protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t);
 protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
 protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
 protected int file_softmagic(struct magic_set *, const unsigned char *, size_t);
 protected int file_softmagic(struct magic_set *, const unsigned char *, size_t);
 protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
 protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
-protected uint32_t file_signextend(struct magic_set *, struct magic *, uint32_t);
+protected uint64_t file_signextend(struct magic_set *, struct magic *, uint64_t);
 protected void file_delmagic(struct magic *, int type, size_t entries);
 protected void file_delmagic(struct magic *, int type, size_t entries);
 protected void file_badread(struct magic_set *);
 protected void file_badread(struct magic_set *);
 protected void file_badseek(struct magic_set *);
 protected void file_badseek(struct magic_set *);
-protected void file_oomem(struct magic_set *);
+protected void file_oomem(struct magic_set *, size_t);
 protected void file_error(struct magic_set *, int, const char *, ...);
 protected void file_error(struct magic_set *, int, const char *, ...);
 protected void file_magwarn(struct magic_set *, const char *, ...);
 protected void file_magwarn(struct magic_set *, const char *, ...);
 protected void file_mdump(struct magic *);
 protected void file_mdump(struct magic *);
 protected void file_showstr(FILE *, const char *, size_t);
 protected void file_showstr(FILE *, const char *, size_t);
 protected size_t file_mbswidth(const char *);
 protected size_t file_mbswidth(const char *);
 protected const char *file_getbuffer(struct magic_set *);
 protected const char *file_getbuffer(struct magic_set *);
+protected ssize_t sread(int, void *, size_t);
+
+#ifndef COMPILE_ONLY
+extern const char *file_names[];
+extern const size_t file_nnames;
+#endif
 
 
 #ifndef HAVE_STRERROR
 #ifndef HAVE_STRERROR
 extern int sys_nerr;
 extern int sys_nerr;
@@ -309,6 +348,5 @@ int snprintf(char *, size_t, const char *, ...);
 static const char *rcsid(const char *p) { \
 static const char *rcsid(const char *p) { \
 	return rcsid(p = id); \
 	return rcsid(p = id); \
 }
 }
-#else
 
 
 #endif /* __file_h__ */
 #endif /* __file_h__ */

+ 16 - 12
src/funcs.c

@@ -33,9 +33,12 @@
 #if defined(HAVE_WCHAR_H)
 #if defined(HAVE_WCHAR_H)
 #include <wchar.h>
 #include <wchar.h>
 #endif
 #endif
+#if defined(HAVE_WCTYPE_H)
+#include <wctype.h>
+#endif
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$Id: funcs.c,v 1.19 2006/03/02 22:10:26 christos Exp $")
+FILE_RCSID("@(#)$Id: funcs.c,v 1.23 2006/12/11 21:48:49 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 #ifndef HAVE_VSNPRINTF
 #ifndef HAVE_VSNPRINTF
@@ -57,7 +60,7 @@ file_printf(struct magic_set *ms, const char *fmt, ...)
 	if ((len = vsnprintf(ms->o.ptr, ms->o.len, fmt, ap)) >= ms->o.len) {
 	if ((len = vsnprintf(ms->o.ptr, ms->o.len, fmt, ap)) >= ms->o.len) {
 		va_end(ap);
 		va_end(ap);
 		if ((buf = realloc(ms->o.buf, len + 1024)) == NULL) {
 		if ((buf = realloc(ms->o.buf, len + 1024)) == NULL) {
-			file_oomem(ms);
+			file_oomem(ms, len + 1024);
 			return -1;
 			return -1;
 		}
 		}
 		ms->o.ptr = buf + (ms->o.ptr - ms->o.buf);
 		ms->o.ptr = buf + (ms->o.ptr - ms->o.buf);
@@ -99,9 +102,9 @@ file_error(struct magic_set *ms, int error, const char *f, ...)
 
 
 
 
 protected void
 protected void
-file_oomem(struct magic_set *ms)
+file_oomem(struct magic_set *ms, size_t len)
 {
 {
-	file_error(ms, errno, "cannot allocate memory");
+	file_error(ms, errno, "cannot allocate %zu bytes", len);
 }
 }
 
 
 protected void
 protected void
@@ -159,11 +162,12 @@ file_reset(struct magic_set *ms)
 }
 }
 
 
 #define OCTALIFY(n, o)	\
 #define OCTALIFY(n, o)	\
-	*(n)++ = '\\', \
+	/*LINTED*/ \
+	(void)(*(n)++ = '\\', \
 	*(n)++ = (((uint32_t)*(o) >> 6) & 3) + '0', \
 	*(n)++ = (((uint32_t)*(o) >> 6) & 3) + '0', \
 	*(n)++ = (((uint32_t)*(o) >> 3) & 7) + '0', \
 	*(n)++ = (((uint32_t)*(o) >> 3) & 7) + '0', \
 	*(n)++ = (((uint32_t)*(o) >> 0) & 7) + '0', \
 	*(n)++ = (((uint32_t)*(o) >> 0) & 7) + '0', \
-	(o)++
+	(o)++)
 
 
 protected const char *
 protected const char *
 file_getbuffer(struct magic_set *ms)
 file_getbuffer(struct magic_set *ms)
@@ -180,7 +184,7 @@ file_getbuffer(struct magic_set *ms)
 	nsize = ms->o.len * 4 + 1;
 	nsize = ms->o.len * 4 + 1;
 	if (ms->o.psize < nsize) {
 	if (ms->o.psize < nsize) {
 		if ((nbuf = realloc(ms->o.pbuf, nsize)) == NULL) {
 		if ((nbuf = realloc(ms->o.pbuf, nsize)) == NULL) {
-			file_oomem(ms);
+			file_oomem(ms, nsize);
 			return NULL;
 			return NULL;
 		}
 		}
 		ms->o.psize = nsize;
 		ms->o.psize = nsize;
@@ -201,15 +205,15 @@ file_getbuffer(struct magic_set *ms)
 		eop = op + strlen(ms->o.buf);
 		eop = op + strlen(ms->o.buf);
 
 
 		while (op < eop) {
 		while (op < eop) {
-			bytesconsumed = mbrtowc(&nextchar, op, eop - op,
-			    &state);
+			bytesconsumed = mbrtowc(&nextchar, op,
+			    (size_t)(eop - op), &state);
 			if (bytesconsumed == (size_t)(-1) ||
 			if (bytesconsumed == (size_t)(-1) ||
 			    bytesconsumed == (size_t)(-2)) {
 			    bytesconsumed == (size_t)(-2)) {
 				mb_conv = 0;
 				mb_conv = 0;
 				break;
 				break;
 			}
 			}
 
 
-			if (iswprint(nextchar) ) {
+			if (iswprint(nextchar)) {
 				(void)memcpy(np, op, bytesconsumed);
 				(void)memcpy(np, op, bytesconsumed);
 				op += bytesconsumed;
 				op += bytesconsumed;
 				np += bytesconsumed;
 				np += bytesconsumed;
@@ -238,8 +242,8 @@ file_getbuffer(struct magic_set *ms)
 }
 }
 
 
 /*
 /*
- * Yes these suffer from buffer overflows, but if your OS does not have
- * these functions, then maybe you should consider replacing your OS?
+ * Yes these wrappers suffer from buffer overflows, but if your OS does not have
+ * the real functions, maybe you should consider replacing your OS?
  */
  */
 #ifndef HAVE_VSNPRINTF
 #ifndef HAVE_VSNPRINTF
 int
 int

+ 10 - 2
src/is_tar.c

@@ -45,7 +45,7 @@
 #include "tar.h"
 #include "tar.h"
 
 
 #ifndef lint
 #ifndef lint
-FILE_RCSID("@(#)$Id: is_tar.c,v 1.25 2004/09/11 19:15:57 christos Exp $")
+FILE_RCSID("@(#)$Id: is_tar.c,v 1.26 2006/05/03 15:19:25 christos Exp $")
 #endif
 #endif
 
 
 #define	isodigit(c)	( ((c) >= '0') && ((c) <= '7') )
 #define	isodigit(c)	( ((c) >= '0') && ((c) <= '7') )
@@ -71,6 +71,12 @@ file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
 		    "application/x-tar, POSIX" : "POSIX tar archive") == -1)
 		    "application/x-tar, POSIX" : "POSIX tar archive") == -1)
 			return -1;
 			return -1;
 		return 1;
 		return 1;
+	case 3:
+		if (file_printf(ms, (ms->flags & MAGIC_MIME) ?
+		    "application/x-tar, POSIX (GNU)" :
+		    "POSIX tar archive (GNU)") == -1)
+			return -1;
+		return 1;
 	default:
 	default:
 		return 0;
 		return 0;
 	}
 	}
@@ -113,7 +119,9 @@ is_tar(const unsigned char *buf, size_t nbytes)
 	if (sum != recsum)
 	if (sum != recsum)
 		return 0;	/* Not a tar archive */
 		return 0;	/* Not a tar archive */
 	
 	
-	if (0==strcmp(header->header.magic, TMAGIC)) 
+	if (strcmp(header->header.magic, GNUTMAGIC) == 0) 
+		return 3;		/* GNU Unix Standard tar archive */
+	if (strcmp(header->header.magic, TMAGIC) == 0) 
 		return 2;		/* Unix Standard tar archive */
 		return 2;		/* Unix Standard tar archive */
 
 
 	return 1;			/* Old fashioned tar archive */
 	return 1;			/* Old fashioned tar archive */

+ 75 - 28
src/magic.c

@@ -38,6 +38,7 @@
 #ifdef QUICK
 #ifdef QUICK
 #include <sys/mman.h>
 #include <sys/mman.h>
 #endif
 #endif
+#include <limits.h>	/* for PIPE_BUF */
 
 
 #if defined(HAVE_UTIMES)
 #if defined(HAVE_UTIMES)
 # include <sys/time.h>
 # include <sys/time.h>
@@ -62,7 +63,7 @@
 #include "patchlevel.h"
 #include "patchlevel.h"
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$Id: magic.c,v 1.32 2005/10/17 15:31:10 christos Exp $")
+FILE_RCSID("@(#)$Id: magic.c,v 1.35 2006/10/31 19:37:17 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 #ifdef __EMX__
 #ifdef __EMX__
@@ -74,6 +75,7 @@ protected int file_os2_apptype(struct magic_set *ms, const char *fn,
 private void free_mlist(struct mlist *);
 private void free_mlist(struct mlist *);
 private void close_and_restore(const struct magic_set *, const char *, int,
 private void close_and_restore(const struct magic_set *, const char *, int,
     const struct stat *);
     const struct stat *);
+private int info_from_stat(struct magic_set *, mode_t);
 
 
 #ifndef	STDIN_FILENO
 #ifndef	STDIN_FILENO
 #define	STDIN_FILENO	0
 #define	STDIN_FILENO	0
@@ -136,9 +138,26 @@ free_mlist(struct mlist *mlist)
 	free(ml);
 	free(ml);
 }
 }
 
 
+private int
+info_from_stat(struct magic_set *ms, mode_t md)
+{
+	/* We cannot open it, but we were able to stat it. */
+	if (md & 0222)
+		if (file_printf(ms, "writable, ") == -1)
+			return -1;
+	if (md & 0111)
+		if (file_printf(ms, "executable, ") == -1)
+			return -1;
+	if (S_ISREG(md))
+		if (file_printf(ms, "regular file, ") == -1)
+			return -1;
+	if (file_printf(ms, "no read permission") == -1)
+		return -1;
+	return 0;
+}
+
 public void
 public void
-magic_close(ms)
-    struct magic_set *ms;
+magic_close(struct magic_set *ms)
 {
 {
 	free_mlist(ms->mlist);
 	free_mlist(ms->mlist);
 	free(ms->o.pbuf);
 	free(ms->o.pbuf);
@@ -221,6 +240,7 @@ magic_file(struct magic_set *ms, const char *inname)
 	unsigned char *buf;
 	unsigned char *buf;
 	struct stat	sb;
 	struct stat	sb;
 	ssize_t nbytes = 0;	/* number of bytes read from a datafile */
 	ssize_t nbytes = 0;	/* number of bytes read from a datafile */
+	int	ispipe = 0;
 
 
 	/*
 	/*
 	 * one extra for terminating '\0', and
 	 * one extra for terminating '\0', and
@@ -234,48 +254,75 @@ magic_file(struct magic_set *ms, const char *inname)
 		goto done;
 		goto done;
 
 
 	switch (file_fsmagic(ms, inname, &sb)) {
 	switch (file_fsmagic(ms, inname, &sb)) {
-	case -1:
+	case -1:		/* error */
 		goto done;
 		goto done;
-	case 0:
+	case 0:			/* nothing found */
 		break;
 		break;
-	default:
+	default:		/* matched it and printed type */
 		rv = 0;
 		rv = 0;
 		goto done;
 		goto done;
 	}
 	}
 
 
-	if (inname == NULL)
+	if (inname == NULL) {
 		fd = STDIN_FILENO;
 		fd = STDIN_FILENO;
-	else if ((fd = open(inname, O_RDONLY|O_BINARY)) < 0) {
+		if (fstat(fd, &sb) == 0 && S_ISFIFO(sb.st_mode))
+			ispipe = 1;
+	} else {
+		int flags = O_RDONLY|O_BINARY;
+
+		if (stat(inname, &sb) == 0 && S_ISFIFO(sb.st_mode)) {
+			flags |= O_NONBLOCK;
+			ispipe = 1;
+		}
+
+		errno = 0;
+		if ((fd = open(inname, flags)) < 0) {
 #ifdef __CYGWIN__
 #ifdef __CYGWIN__
-	    char *tmp = alloca(strlen(inname) + 5);
-	    (void)strcat(strcpy(tmp, inname), ".exe");
-	    if ((fd = open(tmp, O_RDONLY|O_BINARY)) < 0) {
+		    char *tmp = alloca(strlen(inname) + 5);
+		    (void)strcat(strcpy(tmp, inname), ".exe");
+		    if ((fd = open(tmp, flags)) < 0) {
 #endif
 #endif
-		/* We cannot open it, but we were able to stat it. */
-		if (sb.st_mode & 0222)
-			if (file_printf(ms, "writable, ") == -1)
-				goto done;
-		if (sb.st_mode & 0111)
-			if (file_printf(ms, "executable, ") == -1)
-				goto done;
-		if (S_ISREG(sb.st_mode))
-			if (file_printf(ms, "regular file, ") == -1)
-				goto done;
-		if (file_printf(ms, "no read permission") == -1)
+			if (info_from_stat(ms, sb.st_mode) == -1)
+			    goto done;
+			rv = 0;
 			goto done;
 			goto done;
-		rv = 0;
-		goto done;
 #ifdef __CYGWIN__
 #ifdef __CYGWIN__
-	    }
+		    }
+#endif
+		}
+#ifdef O_NONBLOCK
+		if ((flags = fcntl(fd, F_GETFL)) != -1) {
+			flags &= ~O_NONBLOCK;
+			(void)fcntl(fd, F_SETFL, flags);
+		}
 #endif
 #endif
 	}
 	}
 
 
 	/*
 	/*
 	 * try looking at the first HOWMANY bytes
 	 * try looking at the first HOWMANY bytes
 	 */
 	 */
-	if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
-		file_error(ms, errno, "cannot read `%s'", inname);
-		goto done;
+	if (ispipe) {
+		ssize_t r = 0;
+
+		while ((r = sread(fd, (void *)&buf[nbytes],
+		    (size_t)(HOWMANY - nbytes))) > 0) {
+			nbytes += r;
+			if (r < PIPE_BUF) break;
+		}
+
+		if (nbytes == 0) {
+			/* We can not read it, but we were able to stat it. */
+			if (info_from_stat(ms, sb.st_mode) == -1)
+				goto done;
+			rv = 0;
+			goto done;
+		}
+
+	} else {
+		if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
+			file_error(ms, errno, "cannot read `%s'", inname);
+			goto done;
+		}
 	}
 	}
 
 
 	if (nbytes == 0) {
 	if (nbytes == 0) {

+ 8 - 2
src/patchlevel.h

@@ -1,11 +1,17 @@
 #define	FILE_VERSION_MAJOR	4
 #define	FILE_VERSION_MAJOR	4
-#define	patchlevel		17
+#define	patchlevel		19
 
 
 /*
 /*
  * Patchlevel file for Ian Darwin's MAGIC command.
  * Patchlevel file for Ian Darwin's MAGIC command.
- * $Id: patchlevel.h,v 1.60 2006/03/02 22:15:12 christos Exp $
+ * $Id: patchlevel.h,v 1.62 2006/12/11 21:49:58 christos Exp $
  *
  *
  * $Log: patchlevel.h,v $
  * $Log: patchlevel.h,v $
+ * Revision 1.62  2006/12/11 21:49:58  christos
+ * time for 4.19
+ *
+ * Revision 1.61  2006/10/31 21:18:09  christos
+ * bump
+ *
  * Revision 1.60  2006/03/02 22:15:12  christos
  * Revision 1.60  2006/03/02 22:15:12  christos
  * welcome to 4.17
  * welcome to 4.17
  *
  *

+ 26 - 8
src/print.c

@@ -41,7 +41,7 @@
 #include <time.h>
 #include <time.h>
 
 
 #ifndef lint
 #ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.50 2006/03/02 22:07:53 christos Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.56 2006/12/08 20:31:07 christos Exp $")
 #endif  /* lint */
 #endif  /* lint */
 
 
 #define SZOF(a)	(sizeof(a) / sizeof(a[0]))
 #define SZOF(a)	(sizeof(a) / sizeof(a[0]))
@@ -50,18 +50,17 @@ FILE_RCSID("@(#)$Id: print.c,v 1.50 2006/03/02 22:07:53 christos Exp $")
 protected void
 protected void
 file_mdump(struct magic *m)
 file_mdump(struct magic *m)
 {
 {
-	private const char *typ[] = { FILE_FORMAT_NAME };
 	private const char optyp[] = { FILE_OPS };
 	private const char optyp[] = { FILE_OPS };
 
 
-	(void) fputc('[', stderr);
+	(void) fprintf(stderr, "[%zu", m->lineno);
 	(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
 	(void) fprintf(stderr, ">>>>>>>> %d" + 8 - (m->cont_level & 7),
 		       m->offset);
 		       m->offset);
 
 
 	if (m->flag & INDIR) {
 	if (m->flag & INDIR) {
 		(void) fprintf(stderr, "(%s,",
 		(void) fprintf(stderr, "(%s,",
 			       /* Note: type is unsigned */
 			       /* Note: type is unsigned */
-			       (m->in_type < SZOF(typ)) ? 
-					typ[m->in_type] : "*bad*");
+			       (m->in_type < file_nnames) ? 
+					file_names[m->in_type] : "*bad*");
 		if (m->in_op & FILE_OPINVERSE)
 		if (m->in_op & FILE_OPINVERSE)
 			(void) fputc('~', stderr);
 			(void) fputc('~', stderr);
 		(void) fprintf(stderr, "%c%d),",
 		(void) fprintf(stderr, "%c%d),",
@@ -71,7 +70,7 @@ file_mdump(struct magic *m)
 	}
 	}
 	(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
 	(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
 		       /* Note: type is unsigned */
 		       /* Note: type is unsigned */
-		       (m->type < SZOF(typ)) ? typ[m->type] : "*bad*");
+		       (m->type < file_nnames) ? file_names[m->type] : "*bad*");
 	if (m->mask_op & FILE_OPINVERSE)
 	if (m->mask_op & FILE_OPINVERSE)
 		(void) fputc('~', stderr);
 		(void) fputc('~', stderr);
 	if (m->mask) {
 	if (m->mask) {
@@ -80,7 +79,8 @@ file_mdump(struct magic *m)
 		else
 		else
 			fputc('?', stderr);
 			fputc('?', stderr);
 		if (FILE_STRING != m->type || FILE_PSTRING != m->type)
 		if (FILE_STRING != m->type || FILE_PSTRING != m->type)
-			(void) fprintf(stderr, "%.8x", m->mask);
+			(void) fprintf(stderr, "%.8llx",
+			    (unsigned long long)m->mask);
 		else {
 		else {
 			if (m->mask & STRING_IGNORE_LOWERCASE) 
 			if (m->mask & STRING_IGNORE_LOWERCASE) 
 				(void) fputc(CHAR_IGNORE_LOWERCASE, stderr);
 				(void) fputc(CHAR_IGNORE_LOWERCASE, stderr);
@@ -106,13 +106,19 @@ file_mdump(struct magic *m)
 		case FILE_BELONG:
 		case FILE_BELONG:
 			(void) fprintf(stderr, "%d", m->value.l);
 			(void) fprintf(stderr, "%d", m->value.l);
 			break;
 			break;
+		case FILE_BEQUAD:
+		case FILE_LEQUAD:
+		case FILE_QUAD:
+			(void) fprintf(stderr, "%lld",
+			    (unsigned long long)m->value.q);
+			break;
 		case FILE_PSTRING:
 		case FILE_PSTRING:
 		case FILE_STRING:
 		case FILE_STRING:
 		case FILE_REGEX:
 		case FILE_REGEX:
 		case FILE_BESTRING16:
 		case FILE_BESTRING16:
 		case FILE_LESTRING16:
 		case FILE_LESTRING16:
 		case FILE_SEARCH:
 		case FILE_SEARCH:
-			file_showstr(stderr, m->value.s, m->vallen);
+			file_showstr(stderr, m->value.s, (size_t)m->vallen);
 			break;
 			break;
 		case FILE_DATE:
 		case FILE_DATE:
 		case FILE_LEDATE:
 		case FILE_LEDATE:
@@ -128,6 +134,18 @@ file_mdump(struct magic *m)
 			(void)fprintf(stderr, "%s,",
 			(void)fprintf(stderr, "%s,",
 			    file_fmttime(m->value.l, 0));
 			    file_fmttime(m->value.l, 0));
 			break;
 			break;
+		case FILE_QDATE:
+		case FILE_LEQDATE:
+		case FILE_BEQDATE:
+			(void)fprintf(stderr, "%s,",
+			    file_fmttime((uint32_t)m->value.q, 1));
+			break;
+		case FILE_QLDATE:
+		case FILE_LEQLDATE:
+		case FILE_BEQLDATE:
+			(void)fprintf(stderr, "%s,",
+			    file_fmttime((uint32_t)m->value.q, 0));
+			break;
 		default:
 		default:
 			(void) fputs("*bad*", stderr);
 			(void) fputs("*bad*", stderr);
 			break;
 			break;

+ 112 - 43
src/readelf.c

@@ -37,14 +37,16 @@
 #include "readelf.h"
 #include "readelf.h"
 
 
 #ifndef lint
 #ifndef lint
-FILE_RCSID("@(#)$Id: readelf.c,v 1.54 2006/01/13 00:45:21 christos Exp $")
+FILE_RCSID("@(#)$Id: readelf.c,v 1.61 2006/11/15 15:53:23 christos Exp $")
 #endif
 #endif
 
 
 #ifdef	ELFCORE
 #ifdef	ELFCORE
-private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t);
+private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,
+    off_t, int *);
 #endif
 #endif
-private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t);
-private int doshn(struct magic_set *, int, int, int, off_t, int, size_t);
+private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
+    off_t, int *);
+private int doshn(struct magic_set *, int, int, int, off_t, int, size_t, int *);
 private size_t donote(struct magic_set *, unsigned char *, size_t, size_t, int,
 private size_t donote(struct magic_set *, unsigned char *, size_t, size_t, int,
     int, size_t, int *);
     int, size_t, int *);
 
 
@@ -189,15 +191,16 @@ getu64(int swap, uint64_t value)
 #ifdef ELFCORE
 #ifdef ELFCORE
 size_t	prpsoffsets32[] = {
 size_t	prpsoffsets32[] = {
 	8,		/* FreeBSD */
 	8,		/* FreeBSD */
-	28,		/* Linux 2.0.36 */
-	32,		/* Linux (I forget which kernel version) */
+	28,		/* Linux 2.0.36 (short name) */
+	44,		/* Linux (path name) */
 	84,		/* SunOS 5.x */
 	84,		/* SunOS 5.x */
 };
 };
 
 
 size_t	prpsoffsets64[] = {
 size_t	prpsoffsets64[] = {
 	16,		/* FreeBSD, 64-bit */
 	16,		/* FreeBSD, 64-bit */
-	40,             /* Linux (tested on core from 2.4.x) */
-       120,		/* SunOS 5.x, 64-bit */
+	40,             /* Linux (tested on core from 2.4.x, short name) */
+	56,		/* Linux (path name) */
+	120,		/* SunOS 5.x, 64-bit */
 };
 };
 
 
 #define	NOFFSETS32	(sizeof prpsoffsets32 / sizeof prpsoffsets32[0])
 #define	NOFFSETS32	(sizeof prpsoffsets32 / sizeof prpsoffsets32[0])
@@ -237,17 +240,24 @@ private const char *os_style_names[] = {
 };
 };
 
 
 #define FLAGS_DID_CORE		1
 #define FLAGS_DID_CORE		1
+#define FLAGS_DID_NOTE		2
 
 
 private int
 private int
 dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
 dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
-    int num, size_t size)
+    int num, size_t size, off_t fsize, int *flags)
 {
 {
 	Elf32_Phdr ph32;
 	Elf32_Phdr ph32;
 	Elf64_Phdr ph64;
 	Elf64_Phdr ph64;
 	size_t offset;
 	size_t offset;
 	unsigned char nbuf[BUFSIZ];
 	unsigned char nbuf[BUFSIZ];
 	ssize_t bufsize;
 	ssize_t bufsize;
-	int flags = 0;
+	off_t savedoffset;
+ 	struct stat st;
+
+	if (fstat(fd, &st) < 0) {
+		file_badread(ms);
+		return -1;
+	}
 
 
 	if (size != xph_sizeof) {
 	if (size != xph_sizeof) {
 		if (file_printf(ms, ", corrupted program header size") == -1)
 		if (file_printf(ms, ", corrupted program header size") == -1)
@@ -259,7 +269,7 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
 	 * Loop through all the program headers.
 	 * Loop through all the program headers.
 	 */
 	 */
 	for ( ; num; num--) {
 	for ( ; num; num--) {
-		if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
+		if ((savedoffset = lseek(fd, off, SEEK_SET)) == (off_t)-1) {
 			file_badseek(ms);
 			file_badseek(ms);
 			return -1;
 			return -1;
 		}
 		}
@@ -267,6 +277,14 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
 			file_badread(ms);
 			file_badread(ms);
 			return -1;
 			return -1;
 		}
 		}
+		if (xph_offset > fsize) {
+			if (lseek(fd, savedoffset, SEEK_SET) == (off_t)-1) {
+				file_badseek(ms);
+				return -1;
+			}
+			continue;
+		}
+
 		off += size;
 		off += size;
 		if (xph_type != PT_NOTE)
 		if (xph_type != PT_NOTE)
 			continue;
 			continue;
@@ -290,7 +308,7 @@ dophn_core(struct magic_set *ms, int class, int swap, int fd, off_t off,
 			if (offset >= (size_t)bufsize)
 			if (offset >= (size_t)bufsize)
 				break;
 				break;
 			offset = donote(ms, nbuf, offset, (size_t)bufsize,
 			offset = donote(ms, nbuf, offset, (size_t)bufsize,
-			    class, swap, 4, &flags);
+			    class, swap, 4, flags);
 			if (offset == 0)
 			if (offset == 0)
 				break;
 				break;
 
 
@@ -321,7 +339,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 		/*
 		/*
 		 * We're out of note headers.
 		 * We're out of note headers.
 		 */
 		 */
-		return offset;
+		return (offset >= size) ? offset : size;
 	}
 	}
 
 
 	if (namesz & 0x80000000) {
 	if (namesz & 0x80000000) {
@@ -349,9 +367,15 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 
 
 	offset = ELF_ALIGN(doff + descsz);
 	offset = ELF_ALIGN(doff + descsz);
 	if (doff + descsz > size) {
 	if (doff + descsz > size) {
-		return offset;
+		/*
+		 * We're past the end of the buffer.
+		 */
+		return (offset >= size) ? offset : size;
 	}
 	}
 
 
+	if (*flags & FLAGS_DID_NOTE)
+		goto core;
+
 	if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
 	if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
 	    xnh_type == NT_GNU_VERSION && descsz == 16) {
 	    xnh_type == NT_GNU_VERSION && descsz == 16) {
 		uint32_t desc[4];
 		uint32_t desc[4];
@@ -379,6 +403,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 		if (file_printf(ms, " %d.%d.%d", getu32(swap, desc[1]),
 		if (file_printf(ms, " %d.%d.%d", getu32(swap, desc[1]),
 		    getu32(swap, desc[2]), getu32(swap, desc[3])) == -1)
 		    getu32(swap, desc[2]), getu32(swap, desc[3])) == -1)
 			return size;
 			return size;
+		*flags |= FLAGS_DID_NOTE;
 		return size;
 		return size;
 	}
 	}
 
 
@@ -403,10 +428,10 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 		 * p = patchlevel
 		 * p = patchlevel
 		 */
 		 */
 		if (desc > 100000000U) {
 		if (desc > 100000000U) {
-			u_int ver_patch = (desc / 100) % 100;
-			u_int ver_rel = (desc / 10000) % 100;
-			u_int ver_min = (desc / 1000000) % 100;
-			u_int ver_maj = desc / 100000000;
+			uint32_t ver_patch = (desc / 100) % 100;
+			uint32_t ver_rel = (desc / 10000) % 100;
+			uint32_t ver_min = (desc / 1000000) % 100;
+			uint32_t ver_maj = desc / 100000000;
 
 
 			if (file_printf(ms, " %u.%u", ver_maj, ver_min) == -1)
 			if (file_printf(ms, " %u.%u", ver_maj, ver_min) == -1)
 				return size;
 				return size;
@@ -415,12 +440,16 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 					return size;
 					return size;
 			} else if (ver_rel != 0) {
 			} else if (ver_rel != 0) {
 				while (ver_rel > 26) {
 				while (ver_rel > 26) {
-					file_printf(ms, "Z");
+					if (file_printf(ms, "Z") == -1)
+						return size;
 					ver_rel -= 26;
 					ver_rel -= 26;
 				}
 				}
-				file_printf(ms, "%c", 'A' + ver_rel - 1);
+				if (file_printf(ms, "%c", 'A' + ver_rel - 1)
+				    == -1)
+					return size;
 			}
 			}
 		}
 		}
+		*flags |= FLAGS_DID_NOTE;
 		return size;
 		return size;
 	}
 	}
 
 
@@ -498,6 +527,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 					return size;
 					return size;
 			}
 			}
 		}
 		}
+		*flags |= FLAGS_DID_NOTE;
 		return size;
 		return size;
 	}
 	}
 
 
@@ -506,6 +536,7 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 		if (file_printf(ms, ", for OpenBSD") == -1)
 		if (file_printf(ms, ", for OpenBSD") == -1)
 			return size;
 			return size;
 		/* Content of note is always 0 */
 		/* Content of note is always 0 */
+		*flags |= FLAGS_DID_NOTE;
 		return size;
 		return size;
 	}
 	}
 
 
@@ -519,9 +550,11 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 		if (file_printf(ms, " %d.%d.%d", desc / 100000,
 		if (file_printf(ms, " %d.%d.%d", desc / 100000,
 		    desc / 10000 % 10, desc % 10000) == -1)
 		    desc / 10000 % 10, desc % 10000) == -1)
 			return size;
 			return size;
+		*flags |= FLAGS_DID_NOTE;
 		return size;
 		return size;
 	}
 	}
 
 
+core:
 	/*
 	/*
 	 * Sigh.  The 2.0.36 kernel in Debian 2.1, at
 	 * Sigh.  The 2.0.36 kernel in Debian 2.1, at
 	 * least, doesn't correctly implement name
 	 * least, doesn't correctly implement name
@@ -551,13 +584,13 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 	}
 	}
 
 
 #ifdef ELFCORE
 #ifdef ELFCORE
+	if ((*flags & FLAGS_DID_CORE) != 0)
+		return size;
+
 	if (os_style != -1) {
 	if (os_style != -1) {
-		if ((*flags & FLAGS_DID_CORE) == 0) {
-			if (file_printf(ms, ", %s-style",
-			    os_style_names[os_style]) == -1)
-				return size;
-			*flags |= FLAGS_DID_CORE;
-		}
+		if (file_printf(ms, ", %s-style", os_style_names[os_style])
+		    == -1)
+			return size;
 	}
 	}
 
 
 	switch (os_style) {
 	switch (os_style) {
@@ -660,17 +693,17 @@ donote(struct magic_set *ms, unsigned char *nbuf, size_t offset, size_t size,
 		break;
 		break;
 	}
 	}
 #endif
 #endif
+	*flags |= FLAGS_DID_CORE;
 	return offset;
 	return offset;
 }
 }
 
 
 private int
 private int
 doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
 doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
-    size_t size)
+    size_t size, int *flags)
 {
 {
 	Elf32_Shdr sh32;
 	Elf32_Shdr sh32;
 	Elf64_Shdr sh64;
 	Elf64_Shdr sh64;
 	int stripped = 1;
 	int stripped = 1;
-	int flags = 0;
 	void *nbuf;
 	void *nbuf;
 	off_t noff;
 	off_t noff;
 
 
@@ -727,7 +760,7 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
 					break;
 					break;
 				noff = donote(ms, nbuf, (size_t)noff,
 				noff = donote(ms, nbuf, (size_t)noff,
 				    (size_t)xsh_size, class, swap, 4,
 				    (size_t)xsh_size, class, swap, 4,
-				    &flags);
+				    flags);
 				if (noff == 0)
 				if (noff == 0)
 					break;
 					break;
 			}
 			}
@@ -752,7 +785,7 @@ doshn(struct magic_set *ms, int class, int swap, int fd, off_t off, int num,
  */
  */
 private int
 private int
 dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
 dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
-    int num, size_t size)
+    int num, size_t size, off_t fsize, int *flags)
 {
 {
 	Elf32_Phdr ph32;
 	Elf32_Phdr ph32;
 	Elf64_Phdr ph64;
 	Elf64_Phdr ph64;
@@ -761,14 +794,20 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
 	unsigned char nbuf[BUFSIZ];
 	unsigned char nbuf[BUFSIZ];
 	int bufsize;
 	int bufsize;
 	size_t offset, align;
 	size_t offset, align;
-	off_t savedoffset;
-	int flags = 0;
+	off_t savedoffset = (off_t)-1;
+	struct stat st;
 
 
+	if (fstat(fd, &st) < 0) {
+		file_badread(ms);
+		return -1;
+	}
+	
 	if (size != xph_sizeof) {
 	if (size != xph_sizeof) {
 		if (file_printf(ms, ", corrupted program header size") == -1)
 		if (file_printf(ms, ", corrupted program header size") == -1)
 		    return -1;
 		    return -1;
 		return 0;
 		return 0;
 	}
 	}
+
 	if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
 	if (lseek(fd, off, SEEK_SET) == (off_t)-1) {
 		file_badseek(ms);
 		file_badseek(ms);
 		return -1;
 		return -1;
@@ -779,11 +818,27 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
   			file_badread(ms);
   			file_badread(ms);
 			return -1;
 			return -1;
 		}
 		}
+		if (xph_offset > st.st_size && savedoffset != (off_t)-1) {
+			if (lseek(fd, savedoffset, SEEK_SET) == (off_t)-1) {
+				file_badseek(ms);
+				return -1;
+			}
+			continue;
+		}
+
 		if ((savedoffset = lseek(fd, (off_t)0, SEEK_CUR)) == (off_t)-1) {
 		if ((savedoffset = lseek(fd, (off_t)0, SEEK_CUR)) == (off_t)-1) {
   			file_badseek(ms);
   			file_badseek(ms);
 			return -1;
 			return -1;
 		}
 		}
 
 
+		if (xph_offset > fsize) {
+			if (lseek(fd, savedoffset, SEEK_SET) == (off_t)-1) {
+				file_badseek(ms);
+				return -1;
+			}
+			continue;
+		}
+
 		switch (xph_type) {
 		switch (xph_type) {
 		case PT_DYNAMIC:
 		case PT_DYNAMIC:
 			linking_style = "dynamically";
 			linking_style = "dynamically";
@@ -820,7 +875,7 @@ dophn_exec(struct magic_set *ms, int class, int swap, int fd, off_t off,
 					break;
 					break;
 				offset = donote(ms, nbuf, offset,
 				offset = donote(ms, nbuf, offset,
 				    (size_t)bufsize, class, swap, align,
 				    (size_t)bufsize, class, swap, align,
-				    &flags);
+				    flags);
 				if (offset == 0)
 				if (offset == 0)
 					break;
 					break;
 			}
 			}
@@ -848,6 +903,9 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 	} u;
 	} u;
 	int class;
 	int class;
 	int swap;
 	int swap;
+	struct stat st;
+	off_t fsize;
+	int flags = 0;
 
 
 	/*
 	/*
 	 * If we cannot seek, it must be a pipe, socket or fifo.
 	 * If we cannot seek, it must be a pipe, socket or fifo.
@@ -855,6 +913,12 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 	if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
 	if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
 		fd = file_pipe2file(ms, fd, buf, nbytes);
 		fd = file_pipe2file(ms, fd, buf, nbytes);
 
 
+	if (fstat(fd, &st) == -1) {
+  		file_badread(ms);
+		return -1;
+	}
+	fsize = st.st_size;
+
 	/*
 	/*
 	 * ELF executables have multiple section headers in arbitrary
 	 * ELF executables have multiple section headers in arbitrary
 	 * file locations and thus file(1) cannot determine it from easily.
 	 * file locations and thus file(1) cannot determine it from easily.
@@ -867,7 +931,7 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 	    return 0;
 	    return 0;
 
 
 
 
-	class = buf[4];
+	class = buf[EI_CLASS];
 
 
 	if (class == ELFCLASS32) {
 	if (class == ELFCLASS32) {
 		Elf32_Ehdr elfhdr;
 		Elf32_Ehdr elfhdr;
@@ -877,14 +941,15 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 
 
 		u.l = 1;
 		u.l = 1;
 		(void) memcpy(&elfhdr, buf, sizeof elfhdr);
 		(void) memcpy(&elfhdr, buf, sizeof elfhdr);
-		swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[5];
+		swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
 
 
 		if (getu16(swap, elfhdr.e_type) == ET_CORE) {
 		if (getu16(swap, elfhdr.e_type) == ET_CORE) {
 #ifdef ELFCORE
 #ifdef ELFCORE
 			if (dophn_core(ms, class, swap, fd,
 			if (dophn_core(ms, class, swap, fd,
 			    (off_t)getu32(swap, elfhdr.e_phoff),
 			    (off_t)getu32(swap, elfhdr.e_phoff),
 			    getu16(swap, elfhdr.e_phnum), 
 			    getu16(swap, elfhdr.e_phnum), 
-			    (size_t)getu16(swap, elfhdr.e_phentsize)) == -1)
+			    (size_t)getu16(swap, elfhdr.e_phentsize),
+			    fsize, &flags) == -1)
 				return -1;
 				return -1;
 #else
 #else
 			;
 			;
@@ -894,14 +959,16 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 				if (dophn_exec(ms, class, swap,
 				if (dophn_exec(ms, class, swap,
 				    fd, (off_t)getu32(swap, elfhdr.e_phoff),
 				    fd, (off_t)getu32(swap, elfhdr.e_phoff),
 				    getu16(swap, elfhdr.e_phnum), 
 				    getu16(swap, elfhdr.e_phnum), 
-				    (size_t)getu16(swap, elfhdr.e_phentsize))
+				    (size_t)getu16(swap, elfhdr.e_phentsize),
+				    fsize, &flags)
 				    == -1)
 				    == -1)
 					return -1;
 					return -1;
 			}
 			}
 			if (doshn(ms, class, swap, fd,
 			if (doshn(ms, class, swap, fd,
 			    (off_t)getu32(swap, elfhdr.e_shoff),
 			    (off_t)getu32(swap, elfhdr.e_shoff),
 			    getu16(swap, elfhdr.e_shnum),
 			    getu16(swap, elfhdr.e_shnum),
-			    (size_t)getu16(swap, elfhdr.e_shentsize)) == -1)
+			    (size_t)getu16(swap, elfhdr.e_shentsize),
+			    &flags) == -1)
 				return -1;
 				return -1;
 		}
 		}
 		return 1;
 		return 1;
@@ -915,14 +982,15 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 
 
 		u.l = 1;
 		u.l = 1;
 		(void) memcpy(&elfhdr, buf, sizeof elfhdr);
 		(void) memcpy(&elfhdr, buf, sizeof elfhdr);
-		swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[5];
+		swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
 
 
 		if (getu16(swap, elfhdr.e_type) == ET_CORE) {
 		if (getu16(swap, elfhdr.e_type) == ET_CORE) {
 #ifdef ELFCORE
 #ifdef ELFCORE
 			if (dophn_core(ms, class, swap, fd,
 			if (dophn_core(ms, class, swap, fd,
 			    (off_t)elf_getu64(swap, elfhdr.e_phoff),
 			    (off_t)elf_getu64(swap, elfhdr.e_phoff),
 			    getu16(swap, elfhdr.e_phnum), 
 			    getu16(swap, elfhdr.e_phnum), 
-			    (size_t)getu16(swap, elfhdr.e_phentsize)) == -1)
+			    (size_t)getu16(swap, elfhdr.e_phentsize),
+			    fsize, &flags) == -1)
 				return -1;
 				return -1;
 #else
 #else
 			;
 			;
@@ -932,14 +1000,15 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
 				if (dophn_exec(ms, class, swap, fd,
 				if (dophn_exec(ms, class, swap, fd,
 				    (off_t)elf_getu64(swap, elfhdr.e_phoff),
 				    (off_t)elf_getu64(swap, elfhdr.e_phoff),
 				    getu16(swap, elfhdr.e_phnum), 
 				    getu16(swap, elfhdr.e_phnum), 
-				    (size_t)getu16(swap, elfhdr.e_phentsize))
-				    == -1)
+				    (size_t)getu16(swap, elfhdr.e_phentsize),
+				    fsize, &flags) == -1)
 					return -1;
 					return -1;
 			}
 			}
 			if (doshn(ms, class, swap, fd,
 			if (doshn(ms, class, swap, fd,
 			    (off_t)elf_getu64(swap, elfhdr.e_shoff),
 			    (off_t)elf_getu64(swap, elfhdr.e_shoff),
 			    getu16(swap, elfhdr.e_shnum),
 			    getu16(swap, elfhdr.e_shnum),
-			    (size_t)getu16(swap, elfhdr.e_shentsize)) == -1)
+			    (size_t)getu16(swap, elfhdr.e_shentsize), &flags)
+			    == -1)
 				return -1;
 				return -1;
 		}
 		}
 		return 1;
 		return 1;

+ 306 - 304
src/softmagic.c

@@ -39,24 +39,28 @@
 
 
 
 
 #ifndef	lint
 #ifndef	lint
-FILE_RCSID("@(#)$Id: softmagic.c,v 1.78 2006/03/12 22:09:33 christos Exp $")
+FILE_RCSID("@(#)$Id: softmagic.c,v 1.87 2006/12/11 21:48:49 christos Exp $")
 #endif	/* lint */
 #endif	/* lint */
 
 
 private int match(struct magic_set *, struct magic *, uint32_t,
 private int match(struct magic_set *, struct magic *, uint32_t,
     const unsigned char *, size_t);
     const unsigned char *, size_t);
 private int mget(struct magic_set *, union VALUETYPE *, const unsigned char *,
 private int mget(struct magic_set *, union VALUETYPE *, const unsigned char *,
     struct magic *, size_t, unsigned int);
     struct magic *, size_t, unsigned int);
-private int mcheck(struct magic_set *, union VALUETYPE *, struct magic *);
+private int magiccheck(struct magic_set *, union VALUETYPE *, struct magic *);
 private int32_t mprint(struct magic_set *, union VALUETYPE *, struct magic *);
 private int32_t mprint(struct magic_set *, union VALUETYPE *, struct magic *);
 private void mdebug(uint32_t, const char *, size_t);
 private void mdebug(uint32_t, const char *, size_t);
 private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
 private int mcopy(struct magic_set *, union VALUETYPE *, int, int,
-    const unsigned char *, size_t, size_t);
+    const unsigned char *, uint32_t, size_t);
 private int mconvert(struct magic_set *, union VALUETYPE *, struct magic *);
 private int mconvert(struct magic_set *, union VALUETYPE *, struct magic *);
 private int check_mem(struct magic_set *, unsigned int);
 private int check_mem(struct magic_set *, unsigned int);
+private int print_sep(struct magic_set *, int);
+private void cvt_8(union VALUETYPE *, const struct magic *);
+private void cvt_16(union VALUETYPE *, const struct magic *);
+private void cvt_32(union VALUETYPE *, const struct magic *);
+private void cvt_64(union VALUETYPE *, const struct magic *);
 
 
 /*
 /*
- * softmagic - lookup one file in database 
- * (already read from MAGIC by apprentice.c).
+ * softmagic - lookup one file in parsed, in-memory copy of database
  * Passed the name and FILE * of one file to be typed.
  * Passed the name and FILE * of one file to be typed.
  */
  */
 /*ARGSUSED1*/		/* nbytes passed for regularity, maybe need later */
 /*ARGSUSED1*/		/* nbytes passed for regularity, maybe need later */
@@ -64,9 +68,10 @@ protected int
 file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
 file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
 {
 {
 	struct mlist *ml;
 	struct mlist *ml;
+	int rv;
 	for (ml = ms->mlist->next; ml != ms->mlist; ml = ml->next)
 	for (ml = ms->mlist->next; ml != ms->mlist; ml = ml->next)
-		if (match(ms, ml->magic, ml->nmagic, buf, nbytes))
-			return 1;
+		if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes)) != 0)
+			return rv;
 
 
 	return 0;
 	return 0;
 }
 }
@@ -109,18 +114,21 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 	int32_t oldoff = 0;
 	int32_t oldoff = 0;
 	int returnval = 0; /* if a match is found it is set to 1*/
 	int returnval = 0; /* if a match is found it is set to 1*/
 	int firstline = 1; /* a flag to print X\n  X\n- X */
 	int firstline = 1; /* a flag to print X\n  X\n- X */
+	int printed_something = 0;
 
 
 	if (check_mem(ms, cont_level) == -1)
 	if (check_mem(ms, cont_level) == -1)
 		return -1;
 		return -1;
 
 
 	for (magindex = 0; magindex < nmagic; magindex++) {
 	for (magindex = 0; magindex < nmagic; magindex++) {
 		/* if main entry matches, print it... */
 		/* if main entry matches, print it... */
+		ms->offset = magic[magindex].offset;
 		int flush = !mget(ms, &p, s, &magic[magindex], nbytes,
 		int flush = !mget(ms, &p, s, &magic[magindex], nbytes,
 		    cont_level);
 		    cont_level);
 		if (flush) {
 		if (flush) {
-			if (magic[magindex].reln == '!') flush = 0;
+			if (magic[magindex].reln == '!')
+				flush = 0;
 		} else {	
 		} else {	
-			switch (mcheck(ms, &p, &magic[magindex])) {
+			switch (magiccheck(ms, &p, &magic[magindex])) {
 			case -1:
 			case -1:
 				return -1;
 				return -1;
 			case 0:
 			case 0:
@@ -141,21 +149,21 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 			continue;
 			continue;
 		}
 		}
 
 
-		if (!firstline) { /* we found another match */
-			/* put a newline and '-' to do some simple formatting*/
-			if (file_printf(ms, "\n- ") == -1)
+		/*
+		 * If we are going to print something, we'll need to print
+		 * a blank before we print something else.
+		 */
+		if (magic[magindex].desc[0]) {
+			need_separator = 1;
+			printed_something = 1;
+			if (print_sep(ms, firstline) == -1)
 				return -1;
 				return -1;
 		}
 		}
 
 
 		if ((ms->c.off[cont_level] = mprint(ms, &p, &magic[magindex]))
 		if ((ms->c.off[cont_level] = mprint(ms, &p, &magic[magindex]))
 		    == -1)
 		    == -1)
 			return -1;
 			return -1;
-		/*
-		 * If we printed something, we'll need to print
-		 * a blank before we print something else.
-		 */
-		if (magic[magindex].desc[0])
-			need_separator = 1;
+
 		/* and any continuations that match */
 		/* and any continuations that match */
 		if (check_mem(ms, ++cont_level) == -1)
 		if (check_mem(ms, ++cont_level) == -1)
 			return -1;
 			return -1;
@@ -171,24 +179,33 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 				 */
 				 */
 				cont_level = magic[magindex].cont_level;
 				cont_level = magic[magindex].cont_level;
 			}
 			}
-			oldoff = magic[magindex].offset;
+			ms->offset = magic[magindex].offset;
 			if (magic[magindex].flag & OFFADD) {
 			if (magic[magindex].flag & OFFADD) {
-				magic[magindex].offset +=
+				ms->offset +=
 				    ms->c.off[cont_level - 1];
 				    ms->c.off[cont_level - 1];
 			}
 			}
 
 
 			flush = !mget(ms, &p, s, &magic[magindex], nbytes,
 			flush = !mget(ms, &p, s, &magic[magindex], nbytes,
 			    cont_level);
 			    cont_level);
 			if (flush && magic[magindex].reln != '!')
 			if (flush && magic[magindex].reln != '!')
-				goto done;
+				continue;
 				
 				
-			switch (flush ? 1 : mcheck(ms, &p, &magic[magindex])) {
+			switch (flush ? 1 : magiccheck(ms, &p, &magic[magindex])) {
 			case -1:
 			case -1:
 				return -1;
 				return -1;
 			case 0:
 			case 0:
 				break;
 				break;
 			default:
 			default:
 				/*
 				/*
+				 * If we are going to print something,
+				 * make sure that we have a separator first.
+				 */
+				if (magic[magindex].desc[0]) {
+					printed_something = 1;
+					if (print_sep(ms, firstline) == -1)
+						return -1;
+				}
+				/*
 				 * This continuation matched.
 				 * This continuation matched.
 				 * Print its message, with
 				 * Print its message, with
 				 * a blank before it if
 				 * a blank before it if
@@ -217,12 +234,11 @@ match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
 				if (check_mem(ms, ++cont_level) == -1)
 				if (check_mem(ms, ++cont_level) == -1)
 					return -1;
 					return -1;
 			}
 			}
-done:
-			magic[magindex].offset = oldoff;
 		}
 		}
 		firstline = 0;
 		firstline = 0;
-		returnval = 1;
-		if ((ms->flags & MAGIC_CONTINUE) == 0) {
+		if (printed_something)
+			returnval = 1;
+		if ((ms->flags & MAGIC_CONTINUE) == 0 && printed_something) {
 			return 1; /* don't keep searching */
 			return 1; /* don't keep searching */
 		}			
 		}			
 	}
 	}
@@ -241,44 +257,113 @@ check_mem(struct magic_set *ms, unsigned int level)
 	ms->c.off = (ms->c.off == NULL) ? malloc(len) : realloc(ms->c.off, len);
 	ms->c.off = (ms->c.off == NULL) ? malloc(len) : realloc(ms->c.off, len);
 	if (ms->c.off != NULL)
 	if (ms->c.off != NULL)
 		return 0;
 		return 0;
-	file_oomem(ms);
+	file_oomem(ms, len);
 	return -1;
 	return -1;
 }
 }
 
 
+private int
+check_fmt(struct magic_set *ms, struct magic *m)
+{
+	regex_t rx;
+	int rc;
+
+	if (strchr(m->desc, '%') == NULL)
+		return 0;
+
+	rc = regcomp(&rx, "%[-0-9\\.]*s", REG_EXTENDED|REG_NOSUB);
+	if (rc) {
+		char errmsg[512];
+		regerror(rc, &rx, errmsg, sizeof(errmsg));
+		file_error(ms, 0, "regex error %d, (%s)", rc, errmsg);
+		return -1;
+	} else {
+		rc = regexec(&rx, m->desc, 0, 0, 0);
+		regfree(&rx);
+		return !rc;
+	}
+}
+
 private int32_t
 private int32_t
 mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 {
 {
-	uint32_t v;
-	int32_t t=0 ;
+	uint64_t v;
+	int32_t t = 0;
+ 	char buf[512];
 
 
 
 
   	switch (m->type) {
   	switch (m->type) {
   	case FILE_BYTE:
   	case FILE_BYTE:
-		v = file_signextend(ms, m, (size_t)p->b);
-		if (file_printf(ms, m->desc, (unsigned char) v) == -1)
+		v = file_signextend(ms, m, (uint64_t)p->b);
+		switch (check_fmt(ms, m)) {
+		case -1:
 			return -1;
 			return -1;
-		t = m->offset + sizeof(char);
+		case 1:
+			if (snprintf(buf, sizeof(buf), "%c",
+			    (unsigned char)v) < 0)
+				return -1;
+			if (file_printf(ms, m->desc, buf) == -1)
+				return -1;
+			break;
+		default:
+			if (file_printf(ms, m->desc, (unsigned char) v) == -1)
+				return -1;
+			break;
+		}
+		t = ms->offset + sizeof(char);
 		break;
 		break;
 
 
   	case FILE_SHORT:
   	case FILE_SHORT:
   	case FILE_BESHORT:
   	case FILE_BESHORT:
   	case FILE_LESHORT:
   	case FILE_LESHORT:
-		v = file_signextend(ms, m, (size_t)p->h);
-		if (file_printf(ms, m->desc, (unsigned short) v) == -1)
+		v = file_signextend(ms, m, (uint64_t)p->h);
+		switch (check_fmt(ms, m)) {
+		case -1:
 			return -1;
 			return -1;
-		t = m->offset + sizeof(short);
+		case 1:
+			if (snprintf(buf, sizeof(buf), "%hu",
+			    (unsigned short)v) < 0)
+				return -1;
+			if (file_printf(ms, m->desc, buf) == -1)
+				return -1;
+			break;
+		default:
+			if (file_printf(ms, m->desc, (unsigned short) v) == -1)
+				return -1;
+			break;
+		}
+		t = ms->offset + sizeof(short);
 		break;
 		break;
 
 
   	case FILE_LONG:
   	case FILE_LONG:
   	case FILE_BELONG:
   	case FILE_BELONG:
   	case FILE_LELONG:
   	case FILE_LELONG:
   	case FILE_MELONG:
   	case FILE_MELONG:
-		v = file_signextend(ms, m, p->l);
-		if (file_printf(ms, m->desc, (uint32_t) v) == -1)
+		v = file_signextend(ms, m, (uint64_t)p->l);
+		switch (check_fmt(ms, m)) {
+		case -1:
 			return -1;
 			return -1;
-		t = m->offset + sizeof(int32_t);
+		case 1:
+			if (snprintf(buf, sizeof(buf), "%u", (uint32_t)v) < 0)
+				return -1;
+			if (file_printf(ms, m->desc, buf) == -1)
+				return -1;
+			break;
+		default:
+			if (file_printf(ms, m->desc, (uint32_t) v) == -1)
+				return -1;
+			break;
+		}
+		t = ms->offset + sizeof(int32_t);
   		break;
   		break;
 
 
+  	case FILE_QUAD:
+  	case FILE_BEQUAD:
+  	case FILE_LEQUAD:
+		v = file_signextend(ms, m, p->q);
+		if (file_printf(ms, m->desc, (uint64_t) v) == -1)
+			return -1;
+		t = ms->offset + sizeof(int64_t);
+  		break;
   	case FILE_STRING:
   	case FILE_STRING:
   	case FILE_PSTRING:
   	case FILE_PSTRING:
   	case FILE_BESTRING16:
   	case FILE_BESTRING16:
@@ -286,7 +371,7 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 		if (m->reln == '=' || m->reln == '!') {
 		if (m->reln == '=' || m->reln == '!') {
 			if (file_printf(ms, m->desc, m->value.s) == -1)
 			if (file_printf(ms, m->desc, m->value.s) == -1)
 				return -1;
 				return -1;
-			t = m->offset + m->vallen;
+			t = ms->offset + m->vallen;
 		}
 		}
 		else {
 		else {
 			if (*m->value.s == '\0') {
 			if (*m->value.s == '\0') {
@@ -296,7 +381,7 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 			}
 			}
 			if (file_printf(ms, m->desc, p->s) == -1)
 			if (file_printf(ms, m->desc, p->s) == -1)
 				return -1;
 				return -1;
-			t = m->offset + strlen(p->s);
+			t = ms->offset + strlen(p->s);
 		}
 		}
 		break;
 		break;
 
 
@@ -306,7 +391,7 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 	case FILE_MEDATE:
 	case FILE_MEDATE:
 		if (file_printf(ms, m->desc, file_fmttime(p->l, 1)) == -1)
 		if (file_printf(ms, m->desc, file_fmttime(p->l, 1)) == -1)
 			return -1;
 			return -1;
-		t = m->offset + sizeof(time_t);
+		t = ms->offset + sizeof(time_t);
 		break;
 		break;
 
 
 	case FILE_LDATE:
 	case FILE_LDATE:
@@ -315,17 +400,37 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 	case FILE_MELDATE:
 	case FILE_MELDATE:
 		if (file_printf(ms, m->desc, file_fmttime(p->l, 0)) == -1)
 		if (file_printf(ms, m->desc, file_fmttime(p->l, 0)) == -1)
 			return -1;
 			return -1;
-		t = m->offset + sizeof(time_t);
+		t = ms->offset + sizeof(time_t);
+		break;
+
+	case FILE_QDATE:
+	case FILE_BEQDATE:
+	case FILE_LEQDATE:
+		if (file_printf(ms, m->desc, file_fmttime((uint32_t)p->q, 1))
+		    == -1)
+			return -1;
+		t = ms->offset + sizeof(uint64_t);
+		break;
+
+	case FILE_QLDATE:
+	case FILE_BEQLDATE:
+	case FILE_LEQLDATE:
+		if (file_printf(ms, m->desc, file_fmttime((uint32_t)p->q, 0))
+		    == -1)
+			return -1;
+		t = ms->offset + sizeof(uint64_t);
 		break;
 		break;
+
 	case FILE_REGEX:
 	case FILE_REGEX:
 	  	if (file_printf(ms, m->desc, p->s) == -1)
 	  	if (file_printf(ms, m->desc, p->s) == -1)
 			return -1;
 			return -1;
-		t = m->offset + strlen(p->s);
+		t = ms->offset + strlen(p->s);
 		break;
 		break;
+
 	case FILE_SEARCH:
 	case FILE_SEARCH:
 	  	if (file_printf(ms, m->desc, m->value.s) == -1)
 	  	if (file_printf(ms, m->desc, m->value.s) == -1)
 			return -1;
 			return -1;
-		t = m->offset + m->vallen;
+		t = ms->offset + m->vallen;
 		break;
 		break;
 
 
 	default:
 	default:
@@ -335,6 +440,62 @@ mprint(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 	return(t);
 	return(t);
 }
 }
 
 
+
+#define DO_CVT(fld, cast) \
+	if (m->mask) \
+		switch (m->mask_op & 0x7F) { \
+		case FILE_OPAND: \
+			p->fld &= cast m->mask; \
+			break; \
+		case FILE_OPOR: \
+			p->fld |= cast m->mask; \
+			break; \
+		case FILE_OPXOR: \
+			p->fld ^= cast m->mask; \
+			break; \
+		case FILE_OPADD: \
+			p->fld += cast m->mask; \
+			break; \
+		case FILE_OPMINUS: \
+			p->fld -= cast m->mask; \
+			break; \
+		case FILE_OPMULTIPLY: \
+			p->fld *= cast m->mask; \
+			break; \
+		case FILE_OPDIVIDE: \
+			p->fld /= cast m->mask; \
+			break; \
+		case FILE_OPMODULO: \
+			p->fld %= cast m->mask; \
+			break; \
+		} \
+	if (m->mask_op & FILE_OPINVERSE) \
+		p->fld = ~p->fld \
+
+private void
+cvt_8(union VALUETYPE *p, const struct magic *m)
+{
+	DO_CVT(b, (uint8_t));
+}
+
+private void
+cvt_16(union VALUETYPE *p, const struct magic *m)
+{
+	DO_CVT(h, (uint16_t));
+}
+
+private void
+cvt_32(union VALUETYPE *p, const struct magic *m)
+{
+	DO_CVT(l, (uint32_t));
+}
+
+private void
+cvt_64(union VALUETYPE *p, const struct magic *m)
+{
+	DO_CVT(q, (uint64_t));
+}
+
 /*
 /*
  * Convert the byte order of the data we are looking at
  * Convert the byte order of the data we are looking at
  * While we're here, let's apply the mask operation
  * While we're here, let's apply the mask operation
@@ -345,99 +506,20 @@ mconvert(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 {
 {
 	switch (m->type) {
 	switch (m->type) {
 	case FILE_BYTE:
 	case FILE_BYTE:
-		if (m->mask)
-			switch (m->mask_op & 0x7F) {
-			case FILE_OPAND:
-				p->b &= m->mask;
-				break;
-			case FILE_OPOR:
-				p->b |= m->mask;
-				break;
-			case FILE_OPXOR:
-				p->b ^= m->mask;
-				break;
-			case FILE_OPADD:
-				p->b += m->mask;
-				break;
-			case FILE_OPMINUS:
-				p->b -= m->mask;
-				break;
-			case FILE_OPMULTIPLY:
-				p->b *= m->mask;
-				break;
-			case FILE_OPDIVIDE:
-				p->b /= m->mask;
-				break;
-			case FILE_OPMODULO:
-				p->b %= m->mask;
-				break;
-			}
-		if (m->mask_op & FILE_OPINVERSE)
-			p->b = ~p->b;
+		cvt_8(p, m);
 		return 1;
 		return 1;
 	case FILE_SHORT:
 	case FILE_SHORT:
-		if (m->mask)
-			switch (m->mask_op & 0x7F) {
-			case FILE_OPAND:
-				p->h &= m->mask;
-				break;
-			case FILE_OPOR:
-				p->h |= m->mask;
-				break;
-			case FILE_OPXOR:
-				p->h ^= m->mask;
-				break;
-			case FILE_OPADD:
-				p->h += m->mask;
-				break;
-			case FILE_OPMINUS:
-				p->h -= m->mask;
-				break;
-			case FILE_OPMULTIPLY:
-				p->h *= m->mask;
-				break;
-			case FILE_OPDIVIDE:
-				p->h /= m->mask;
-				break;
-			case FILE_OPMODULO:
-				p->h %= m->mask;
-				break;
-			}
-		if (m->mask_op & FILE_OPINVERSE)
-			p->h = ~p->h;
+		cvt_16(p, m);
 		return 1;
 		return 1;
 	case FILE_LONG:
 	case FILE_LONG:
 	case FILE_DATE:
 	case FILE_DATE:
 	case FILE_LDATE:
 	case FILE_LDATE:
-		if (m->mask)
-			switch (m->mask_op & 0x7F) {
-			case FILE_OPAND:
-				p->l &= m->mask;
-				break;
-			case FILE_OPOR:
-				p->l |= m->mask;
-				break;
-			case FILE_OPXOR:
-				p->l ^= m->mask;
-				break;
-			case FILE_OPADD:
-				p->l += m->mask;
-				break;
-			case FILE_OPMINUS:
-				p->l -= m->mask;
-				break;
-			case FILE_OPMULTIPLY:
-				p->l *= m->mask;
-				break;
-			case FILE_OPDIVIDE:
-				p->l /= m->mask;
-				break;
-			case FILE_OPMODULO:
-				p->l %= m->mask;
-				break;
-			}
-		if (m->mask_op & FILE_OPINVERSE)
-			p->l = ~p->l;
+		cvt_32(p, m);
+		return 1;
+	case FILE_QUAD:
+	case FILE_QDATE:
+	case FILE_QLDATE:
+		cvt_64(p, m);
 		return 1;
 		return 1;
 	case FILE_STRING:
 	case FILE_STRING:
 	case FILE_BESTRING16:
 	case FILE_BESTRING16:
@@ -468,172 +550,50 @@ mconvert(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 		}
 		}
 	case FILE_BESHORT:
 	case FILE_BESHORT:
 		p->h = (short)((p->hs[0]<<8)|(p->hs[1]));
 		p->h = (short)((p->hs[0]<<8)|(p->hs[1]));
-		if (m->mask)
-			switch (m->mask_op&0x7F) {
-			case FILE_OPAND:
-				p->h &= m->mask;
-				break;
-			case FILE_OPOR:
-				p->h |= m->mask;
-				break;
-			case FILE_OPXOR:
-				p->h ^= m->mask;
-				break;
-			case FILE_OPADD:
-				p->h += m->mask;
-				break;
-			case FILE_OPMINUS:
-				p->h -= m->mask;
-				break;
-			case FILE_OPMULTIPLY:
-				p->h *= m->mask;
-				break;
-			case FILE_OPDIVIDE:
-				p->h /= m->mask;
-				break;
-			case FILE_OPMODULO:
-				p->h %= m->mask;
-				break;
-			}
-		if (m->mask_op & FILE_OPINVERSE)
-			p->h = ~p->h;
+		cvt_16(p, m);
 		return 1;
 		return 1;
 	case FILE_BELONG:
 	case FILE_BELONG:
 	case FILE_BEDATE:
 	case FILE_BEDATE:
 	case FILE_BELDATE:
 	case FILE_BELDATE:
 		p->l = (int32_t)
 		p->l = (int32_t)
 		    ((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
 		    ((p->hl[0]<<24)|(p->hl[1]<<16)|(p->hl[2]<<8)|(p->hl[3]));
-		if (m->mask)
-			switch (m->mask_op&0x7F) {
-			case FILE_OPAND:
-				p->l &= m->mask;
-				break;
-			case FILE_OPOR:
-				p->l |= m->mask;
-				break;
-			case FILE_OPXOR:
-				p->l ^= m->mask;
-				break;
-			case FILE_OPADD:
-				p->l += m->mask;
-				break;
-			case FILE_OPMINUS:
-				p->l -= m->mask;
-				break;
-			case FILE_OPMULTIPLY:
-				p->l *= m->mask;
-				break;
-			case FILE_OPDIVIDE:
-				p->l /= m->mask;
-				break;
-			case FILE_OPMODULO:
-				p->l %= m->mask;
-				break;
-			}
-		if (m->mask_op & FILE_OPINVERSE)
-			p->l = ~p->l;
+		cvt_32(p, m);
+		return 1;
+	case FILE_BEQUAD:
+	case FILE_BEQDATE:
+	case FILE_BEQLDATE:
+		p->q = (int64_t)
+		    (((int64_t)p->hq[0]<<56)|((int64_t)p->hq[1]<<48)|
+		     ((int64_t)p->hq[2]<<40)|((int64_t)p->hq[3]<<32)|
+		     (p->hq[4]<<24)|(p->hq[5]<<16)|(p->hq[6]<<8)|(p->hq[7]));
+		cvt_64(p, m);
 		return 1;
 		return 1;
 	case FILE_LESHORT:
 	case FILE_LESHORT:
 		p->h = (short)((p->hs[1]<<8)|(p->hs[0]));
 		p->h = (short)((p->hs[1]<<8)|(p->hs[0]));
-		if (m->mask)
-			switch (m->mask_op&0x7F) {
-			case FILE_OPAND:
-				p->h &= m->mask;
-				break;
-			case FILE_OPOR:
-				p->h |= m->mask;
-				break;
-			case FILE_OPXOR:
-				p->h ^= m->mask;
-				break;
-			case FILE_OPADD:
-				p->h += m->mask;
-				break;
-			case FILE_OPMINUS:
-				p->h -= m->mask;
-				break;
-			case FILE_OPMULTIPLY:
-				p->h *= m->mask;
-				break;
-			case FILE_OPDIVIDE:
-				p->h /= m->mask;
-				break;
-			case FILE_OPMODULO:
-				p->h %= m->mask;
-				break;
-			}
-		if (m->mask_op & FILE_OPINVERSE)
-			p->h = ~p->h;
+		cvt_16(p, m);
 		return 1;
 		return 1;
 	case FILE_LELONG:
 	case FILE_LELONG:
 	case FILE_LEDATE:
 	case FILE_LEDATE:
 	case FILE_LELDATE:
 	case FILE_LELDATE:
 		p->l = (int32_t)
 		p->l = (int32_t)
 		    ((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
 		    ((p->hl[3]<<24)|(p->hl[2]<<16)|(p->hl[1]<<8)|(p->hl[0]));
-		if (m->mask)
-			switch (m->mask_op&0x7F) {
-			case FILE_OPAND:
-				p->l &= m->mask;
-				break;
-			case FILE_OPOR:
-				p->l |= m->mask;
-				break;
-			case FILE_OPXOR:
-				p->l ^= m->mask;
-				break;
-			case FILE_OPADD:
-				p->l += m->mask;
-				break;
-			case FILE_OPMINUS:
-				p->l -= m->mask;
-				break;
-			case FILE_OPMULTIPLY:
-				p->l *= m->mask;
-				break;
-			case FILE_OPDIVIDE:
-				p->l /= m->mask;
-				break;
-			case FILE_OPMODULO:
-				p->l %= m->mask;
-				break;
-			}
-		if (m->mask_op & FILE_OPINVERSE)
-			p->l = ~p->l;
+		cvt_32(p, m);
+		return 1;
+	case FILE_LEQUAD:
+	case FILE_LEQDATE:
+	case FILE_LEQLDATE:
+		p->q = (int64_t)
+		    (((int64_t)p->hq[7]<<56)|((int64_t)p->hq[6]<<48)|
+		     ((int64_t)p->hq[5]<<40)|((int64_t)p->hq[4]<<32)|
+		     (p->hq[3]<<24)|(p->hq[2]<<16)|(p->hq[1]<<8)|(p->hq[0]));
+		cvt_64(p, m);
 		return 1;
 		return 1;
 	case FILE_MELONG:
 	case FILE_MELONG:
 	case FILE_MEDATE:
 	case FILE_MEDATE:
 	case FILE_MELDATE:
 	case FILE_MELDATE:
 		p->l = (int32_t)
 		p->l = (int32_t)
 		    ((p->hl[1]<<24)|(p->hl[0]<<16)|(p->hl[3]<<8)|(p->hl[2]));
 		    ((p->hl[1]<<24)|(p->hl[0]<<16)|(p->hl[3]<<8)|(p->hl[2]));
-		if (m->mask)
-			switch (m->mask_op&0x7F) {
-			case FILE_OPAND:
-				p->l &= m->mask;
-				break;
-			case FILE_OPOR:
-				p->l |= m->mask;
-				break;
-			case FILE_OPXOR:
-				p->l ^= m->mask;
-				break;
-			case FILE_OPADD:
-				p->l += m->mask;
-				break;
-			case FILE_OPMINUS:
-				p->l -= m->mask;
-				break;
-			case FILE_OPMULTIPLY:
-				p->l *= m->mask;
-				break;
-			case FILE_OPDIVIDE:
-				p->l /= m->mask;
-				break;
-			case FILE_OPMODULO:
-				p->l %= m->mask;
-				break;
-			}
-		if (m->mask_op & FILE_OPINVERSE)
-			p->l = ~p->l;
+		cvt_32(p, m);
 		return 1;
 		return 1;
 	case FILE_REGEX:
 	case FILE_REGEX:
 	case FILE_SEARCH:
 	case FILE_SEARCH:
@@ -656,7 +616,7 @@ mdebug(uint32_t offset, const char *str, size_t len)
 
 
 private int
 private int
 mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
 mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
-    const unsigned char *s, size_t offset, size_t nbytes)
+    const unsigned char *s, uint32_t offset, size_t nbytes)
 {
 {
 	if (type == FILE_REGEX && indir == 0) {
 	if (type == FILE_REGEX && indir == 0) {
 		/*
 		/*
@@ -670,7 +630,7 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
 			return 0;
 			return 0;
 		}
 		}
 		if ((p->search.buf = strdup((const char *)s)) == NULL) {
 		if ((p->search.buf = strdup((const char *)s)) == NULL) {
-			file_oomem(ms);
+			file_oomem(ms, strlen((const char *)s));
 			return -1;
 			return -1;
 		}
 		}
 		for (b = p->search.buf; offset && 
 		for (b = p->search.buf; offset && 
@@ -694,6 +654,13 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
 		if (type == FILE_BESTRING16)
 		if (type == FILE_BESTRING16)
 			src++;
 			src++;
 
 
+		/* check for pointer overflow */
+		if (src < s) {
+			file_error(ms, 0, "invalid offset %zu in mcopy()",
+			    offset);
+			return -1;
+		}
+
 		for (;src < esrc; src++, dst++) {
 		for (;src < esrc; src++, dst++) {
 			if (dst < edst)
 			if (dst < edst)
 				*dst = *src++;
 				*dst = *src++;
@@ -731,7 +698,7 @@ private int
 mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
 mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
     struct magic *m, size_t nbytes, unsigned int cont_level)
     struct magic *m, size_t nbytes, unsigned int cont_level)
 {
 {
-	uint32_t offset = m->offset;
+	uint32_t offset = ms->offset;
 
 
 	if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes) == -1)
 	if (mcopy(ms, p, m->type, m->flag & INDIR, s, offset, nbytes) == -1)
 		return -1;
 		return -1;
@@ -1208,7 +1175,7 @@ mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
 		if (m->flag & INDIROFFADD) offset += ms->c.off[cont_level-1];
 		if (m->flag & INDIROFFADD) offset += ms->c.off[cont_level-1];
 		if (mcopy(ms, p, m->type, 0, s, offset, nbytes) == -1)
 		if (mcopy(ms, p, m->type, 0, s, offset, nbytes) == -1)
 			return -1;
 			return -1;
-		m->offset = offset;
+		ms->offset = offset;
 
 
 		if ((ms->flags & MAGIC_DEBUG) != 0) {
 		if ((ms->flags & MAGIC_DEBUG) != 0) {
 			mdebug(offset, (char *)(void *)p,
 			mdebug(offset, (char *)(void *)p,
@@ -1257,7 +1224,7 @@ mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
 	}
 	}
 
 
 	if (m->type == FILE_SEARCH) {
 	if (m->type == FILE_SEARCH) {
-		size_t mlen = m->mask + m->vallen;
+		size_t mlen = (size_t)(m->mask + m->vallen);
 		size_t flen = nbytes - offset;
 		size_t flen = nbytes - offset;
 		if (flen < mlen)
 		if (flen < mlen)
 			mlen = flen;
 			mlen = flen;
@@ -1276,10 +1243,10 @@ mget(struct magic_set *ms, union VALUETYPE *p, const unsigned char *s,
 }
 }
 
 
 private int
 private int
-mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
+magiccheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 {
 {
-	uint32_t l = m->value.l;
-	uint32_t v;
+	uint64_t l = m->value.q;
+	uint64_t v;
 	int matched;
 	int matched;
 
 
 	if ( (m->value.s[0] == 'x') && (m->value.s[1] == '\0') ) {
 	if ( (m->value.s[0] == 'x') && (m->value.s[1] == '\0') ) {
@@ -1313,6 +1280,18 @@ mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 		v = p->l;
 		v = p->l;
 		break;
 		break;
 
 
+	case FILE_QUAD:
+	case FILE_LEQUAD:
+	case FILE_BEQUAD:
+	case FILE_QDATE:
+	case FILE_BEQDATE:
+	case FILE_LEQDATE:
+	case FILE_QLDATE:
+	case FILE_BEQLDATE:
+	case FILE_LEQLDATE:
+		v = p->q;
+		break;
+
 	case FILE_STRING:
 	case FILE_STRING:
 	case FILE_BESTRING16:
 	case FILE_BESTRING16:
 	case FILE_LESTRING16:
 	case FILE_LESTRING16:
@@ -1408,21 +1387,25 @@ mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 			while (len-- > 0 && (v = *b++ - *a++) == 0)
 			while (len-- > 0 && (v = *b++ - *a++) == 0)
 				continue;
 				continue;
 			if (!v) {
 			if (!v) {
-				m->offset += range - 1;
+				ms->offset += range - 1;
 				break;
 				break;
 			}
 			}
-			if (range + slen >= p->search.buflen)
+			if (range + slen >= p->search.buflen) {
+				v = 1;
 				break;
 				break;
+			}
 			len = slen;
 			len = slen;
 			a = (unsigned char*)m->value.s;
 			a = (unsigned char*)m->value.s;
 			b = (unsigned char*)p->search.buf + range;
 			b = (unsigned char*)p->search.buf + range;
 		}
 		}
 		free(p->search.buf);
 		free(p->search.buf);
 		p->search.buf = NULL;
 		p->search.buf = NULL;
+		if (v)
+			return 0;
 		break;
 		break;
 	}
 	}
 	default:
 	default:
-		file_error(ms, 0, "invalid type %d in mcheck()", m->type);
+		file_error(ms, 0, "invalid type %d in magiccheck()", m->type);
 		return -1;
 		return -1;
 	}
 	}
 
 
@@ -1432,36 +1415,40 @@ mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 	switch (m->reln) {
 	switch (m->reln) {
 	case 'x':
 	case 'x':
 		if ((ms->flags & MAGIC_DEBUG) != 0)
 		if ((ms->flags & MAGIC_DEBUG) != 0)
-			(void) fprintf(stderr, "%u == *any* = 1\n", v);
+			(void) fprintf(stderr, "%llu == *any* = 1\n",
+			    (unsigned long long)v);
 		matched = 1;
 		matched = 1;
 		break;
 		break;
 
 
 	case '!':
 	case '!':
 		matched = v != l;
 		matched = v != l;
 		if ((ms->flags & MAGIC_DEBUG) != 0)
 		if ((ms->flags & MAGIC_DEBUG) != 0)
-			(void) fprintf(stderr, "%u != %u = %d\n",
-				       v, l, matched);
+			(void) fprintf(stderr, "%llu != %llu = %d\n",
+			    (unsigned long long)v, (unsigned long long)l,
+			    matched);
 		break;
 		break;
 
 
 	case '=':
 	case '=':
 		matched = v == l;
 		matched = v == l;
 		if ((ms->flags & MAGIC_DEBUG) != 0)
 		if ((ms->flags & MAGIC_DEBUG) != 0)
-			(void) fprintf(stderr, "%u == %u = %d\n",
-				       v, l, matched);
+			(void) fprintf(stderr, "%llu == %llu = %d\n",
+			    (unsigned long long)v, (unsigned long long)l,
+			    matched);
 		break;
 		break;
 
 
 	case '>':
 	case '>':
 		if (m->flag & UNSIGNED) {
 		if (m->flag & UNSIGNED) {
 			matched = v > l;
 			matched = v > l;
 			if ((ms->flags & MAGIC_DEBUG) != 0)
 			if ((ms->flags & MAGIC_DEBUG) != 0)
-				(void) fprintf(stderr, "%u > %u = %d\n",
-					       v, l, matched);
+				(void) fprintf(stderr, "%llu > %llu = %d\n",
+				    (unsigned long long)v,
+				    (unsigned long long)l, matched);
 		}
 		}
 		else {
 		else {
 			matched = (int32_t) v > (int32_t) l;
 			matched = (int32_t) v > (int32_t) l;
 			if ((ms->flags & MAGIC_DEBUG) != 0)
 			if ((ms->flags & MAGIC_DEBUG) != 0)
-				(void) fprintf(stderr, "%d > %d = %d\n",
-					       v, l, matched);
+				(void) fprintf(stderr, "%lld > %lld = %d\n",
+				    (long long)v, (long long)l, matched);
 		}
 		}
 		break;
 		break;
 
 
@@ -1469,29 +1456,32 @@ mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 		if (m->flag & UNSIGNED) {
 		if (m->flag & UNSIGNED) {
 			matched = v < l;
 			matched = v < l;
 			if ((ms->flags & MAGIC_DEBUG) != 0)
 			if ((ms->flags & MAGIC_DEBUG) != 0)
-				(void) fprintf(stderr, "%u < %u = %d\n",
-					       v, l, matched);
+				(void) fprintf(stderr, "%llu < %llu = %d\n",
+				    (unsigned long long)v,
+				    (unsigned long long)l, matched);
 		}
 		}
 		else {
 		else {
 			matched = (int32_t) v < (int32_t) l;
 			matched = (int32_t) v < (int32_t) l;
 			if ((ms->flags & MAGIC_DEBUG) != 0)
 			if ((ms->flags & MAGIC_DEBUG) != 0)
-				(void) fprintf(stderr, "%d < %d = %d\n",
-					       v, l, matched);
+				(void) fprintf(stderr, "%lld < %lld = %d\n",
+				       (long long)v, (long long)l, matched);
 		}
 		}
 		break;
 		break;
 
 
 	case '&':
 	case '&':
 		matched = (v & l) == l;
 		matched = (v & l) == l;
 		if ((ms->flags & MAGIC_DEBUG) != 0)
 		if ((ms->flags & MAGIC_DEBUG) != 0)
-			(void) fprintf(stderr, "((%x & %x) == %x) = %d\n",
-				       v, l, l, matched);
+			(void) fprintf(stderr, "((%llx & %llx) == %llx) = %d\n",
+			    (unsigned long long)v, (unsigned long long)l,
+			    (unsigned long long)l, matched);
 		break;
 		break;
 
 
 	case '^':
 	case '^':
 		matched = (v & l) != l;
 		matched = (v & l) != l;
 		if ((ms->flags & MAGIC_DEBUG) != 0)
 		if ((ms->flags & MAGIC_DEBUG) != 0)
-			(void) fprintf(stderr, "((%x & %x) != %x) = %d\n",
-				       v, l, l, matched);
+			(void) fprintf(stderr, "((%llx & %llx) != %llx) = %d\n",
+			    (unsigned long long)v, (unsigned long long)l,
+			    (unsigned long long)l, matched);
 		break;
 		break;
 
 
 	default:
 	default:
@@ -1503,3 +1493,15 @@ mcheck(struct magic_set *ms, union VALUETYPE *p, struct magic *m)
 
 
 	return matched;
 	return matched;
 }
 }
+
+private int
+print_sep(struct magic_set *ms, int firstline)
+{
+	if (firstline)
+		return 0;
+	/*
+	 * we found another match 
+	 * put a newline and '-' to do some simple formatting
+	 */
+	return file_printf(ms, "\n- ");
+}

+ 3 - 2
src/tar.h

@@ -32,7 +32,7 @@
  *
  *
  * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  *
  *
- * $Id: tar.h,v 1.8 2004/09/11 19:15:58 christos Exp $ # checkin only
+ * $Id: tar.h,v 1.9 2006/05/03 15:19:25 christos Exp $ # checkin only
  */
  */
 
 
 /*
 /*
@@ -82,7 +82,8 @@ union record {
 #define	CHKBLANKS	"        "	/* 8 blanks, no null */
 #define	CHKBLANKS	"        "	/* 8 blanks, no null */
 
 
 /* The magic field is filled with this if uname and gname are valid. */
 /* The magic field is filled with this if uname and gname are valid. */
-#define	TMAGIC		"ustar  "	/* 7 chars and a null */
+#define	TMAGIC		"ustar"		/* 5 chars and a null */
+#define	GNUTMAGIC	"ustar  "	/* 7 chars and a null */
 
 
 /* The linkflag defines the type of file */
 /* The linkflag defines the type of file */
 #define	LF_OLDNORMAL	'\0'		/* Normal disk file, Unix compat */
 #define	LF_OLDNORMAL	'\0'		/* Normal disk file, Unix compat */