aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey A Law <law@cygnus.com>1998-05-15 23:21:05 +0000
committerJeffrey A Law <law@cygnus.com>1998-05-15 23:21:05 +0000
commit6f30fcf7e36060ea31897df1acfd06df7a01468c (patch)
treeaeeb97ec8f20e21224eea9c228091d14406c5f10
parent1357d7a42e0655ffb79c1f05bc14cb4082a8aced (diff)
import from Cygnus libiberty
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/egcs@19789 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libiberty/COPYING.LIB5
-rw-r--r--libiberty/ChangeLog352
-rw-r--r--libiberty/Makefile.in263
-rw-r--r--libiberty/README116
-rw-r--r--libiberty/argv.c57
-rw-r--r--libiberty/asprintf.c10
-rw-r--r--libiberty/atexit.c6
-rw-r--r--libiberty/basename.c6
-rw-r--r--libiberty/choose-temp.c28
-rw-r--r--libiberty/clock.c4
-rw-r--r--libiberty/config.table40
-rw-r--r--libiberty/config/mh-aix3
-rw-r--r--libiberty/config/mh-cxux74
-rw-r--r--libiberty/config/mh-windows3
-rw-r--r--libiberty/configure.bat1
-rw-r--r--libiberty/configure.in370
-rw-r--r--libiberty/cplus-dem.c1186
-rw-r--r--libiberty/getcwd.c4
-rw-r--r--libiberty/getopt.c436
-rw-r--r--libiberty/getopt1.c49
-rw-r--r--libiberty/getpagesize.c4
-rw-r--r--libiberty/getruntime.c14
-rw-r--r--libiberty/makefile.vms4
-rw-r--r--libiberty/mpw-config.in2
-rw-r--r--libiberty/pexecute.c188
-rw-r--r--libiberty/strerror.c18
-rw-r--r--libiberty/strsignal.c24
-rw-r--r--libiberty/vasprintf.c9
-rw-r--r--libiberty/vmsbuild.com9
-rw-r--r--libiberty/xmalloc.c22
30 files changed, 2443 insertions, 794 deletions
diff --git a/libiberty/COPYING.LIB b/libiberty/COPYING.LIB
index eb685a5ec98..161a3d1d47b 100644
--- a/libiberty/COPYING.LIB
+++ b/libiberty/COPYING.LIB
@@ -2,7 +2,7 @@
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
- 675 Mass Ave, Cambridge, MA 02139, USA
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@@ -464,7 +464,8 @@ convey the exclusion of warranty; and each file should have at least the
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ MA 02111-1307, USA
Also add information on how to contact you by electronic and paper mail.
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 265acc49a4e..e2585909759 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,349 @@
+Wed May 13 14:24:38 1998 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
+
+ * cplus-dem.c (squangle_mop_up): Change return type to void.
+ (internal_cplus_demangle): Remove unused parameter `options'.
+ All callers changed.
+ (cplus_demangle_opname): Remove function wide variable `int i' and
+ replace with `size_t i' at each location where it is used.
+ (cplus_mangle_opname): change type of `i' from int to size_t.
+
+Wed May 13 13:39:38 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ * alloca-conf.h: Include config.h. Check HAVE_ALLOCA_H rather
+ than sparc or sun.
+ * Makefile.in (argv.o): Depend upon config.h and alloca-conf.h.
+
+Fri May 8 00:23:51 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ * configure.in: Set libiberty_topdir correctly when srcdir is
+ "." and with_target_subdir is not set.
+ * configure: Rebuild.
+
+Thu May 7 13:01:44 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ * configure.in: Add *-*-mingw32* case.
+ * configure: Rebuild.
+
+Wed May 6 11:33:51 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ * config.table: Never use a PIC file for *-*-cygwin32*.
+
+ * Makefile.in (config.status): Depend upon config.table.
+
+ * configure.in: On a cygwin32 host, always compile random, and
+ don't test for sys_siglist, strsignal, or psignal.
+ * configure: Rebuild.
+
+ * clock.c: Check HAVE_SYS_PARAM_H rather than NO_SYS_PARAM_H.
+ * getcwd.c: Likewise.
+ * getpagesize.c: Likewise.
+ * getruntime.c: Likewise.
+
+Tue May 5 18:08:32 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ Use autoconf tests rather than the old dummy.c test:
+ * configure.in: Add AC_ARG_WITH calls for --with-target-subdir and
+ --with-newlib. Add AC_CONFIG_HEADER. Use AC_REPLACE_FUNCS for
+ most functions. Add special cases to handle newlib and VxWorks.
+ Remove target_makefile_frag. Create stamp-h in AC_OUTPUT if
+ CONFIG_HEADERS is set. Only call config-ml.in in AC_OUTPUT if
+ CONFIG_FILES is set; set ac_file before calling it.
+ * config.table (arm-*-riscix*, *-*-cygwin32): Remove.
+ (*-*-hpux*, *-*-hiux*, *-*-irix4*, *-*-solaris2*): Remove.
+ (*-*-sysv4*, *-*-go32, *-*-vxworks5*, *-*-vxworks): Remove
+ (i[3456]-*-mingw32*): Remove.
+ * Makefile.in (ERRORS_CC, CONFIG_H, NEEDED_LIST): Remove.
+ (LIBOBJS): New variable.
+ (HOST_OFILES, DO_ALSO, STAGESTUFF): Remove.
+ (all): Depend upon needed-list. Don't check RULE1.
+ (@target_makefile_frag@): Remove.
+ (COMPILE.c): Include @DEFS@.
+ (HFILES): Add alloca-conf.h.
+ (REQUIRED_OFILES): Remove basename.o.
+ ($(TARGETLIB)): New target.
+ (stamp-needed, lneeded-list, needed.awk, stamp-config): Remove.
+ (lconfig.h, needed2.awk, dummy.o, errors): Remove.
+ (needed-list, config.h): Rewrite.
+ (RULE1, $(RULE1), RULE2, $(RULE2)): Remove.
+ (.always.): Remove.
+ (Makefile): Set CONFIG_FILES and CONFIG_HEADERS.
+ (stamp-h): New target.
+ (atexit.o, clock.o, getcwd.o, getpagesize.o): New targets.
+ (basename.o): Don't depend upon config.h.
+ (getruntime.o): Depend upon config.h.
+ * atexit.c: Include config.h. Check HAVE_ON_EXIT rather than
+ NEED_on_exit.
+ * basename.c: Don't include config.h. Don't check NEED_basename.
+ * clock.c: Include config.h.
+ * getcwd.c: Likewise.
+ * getpagesize.c: Likewise.
+ * getruntime.c: Likewise. Fix checks which set HAVE_GETRUSAGE and
+ HAVE_TIMES.
+ * strerror.c: Change uses of NEED_sys_errlist to
+ HAVE_SYS_ERRLIST. Likewise for NEED_strerror and HAVE_STRERROR.
+ * strsignal.c: Likewise for NEED_sys_siglist and HAVE_SYS_SIGLIST,
+ and for NEED_strsignal and HAVE_STRSIGNAL and for NEED_psignal and
+ HAVE_PSIGNAL.
+ * acconfig.h: New file.
+ * dummy.c: Remove.
+ * functions.def: Remove.
+ * config/mh-cxux7 (HDEFINES): Remove -DHAVE_SYSCONF.
+ * config/mh-windows (HDEFINES): Remove.
+ * config/mh-cygwin32: Remove.
+ * config/mh-go32: Remove.
+ * config/mh-irix4: Remove.
+ * config/mh-riscix: Remove.
+ * config/mh-sysv4: Remove.
+ * config/mt-mingw32: Remove.
+ * config/mt-vxworks5: Remove.
+ * config.in: New file, generated using autoheader.
+ * configure: Rebuild.
+
+Mon May 4 13:00:28 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ * configure.in: Rewrite to use autoconf.
+ * configure: Generate using autoconf.
+ * config/mh-a68bsd: Remove.
+ * config/mh-apollo68: Remove.
+ * config/mh-hpbsd: Remove.
+ * config/mh-ncr3000: Remove.
+ * config/mh-sysv: Remove.
+ * config/mh-aix (RANLIB, INSTALL): Don't define.
+ * config/mh-cxux7 (RANLIB, INSTALL): Don't define.
+ * config/mh-irix4 (CC, RANLIB, INSTALL): Don't define.
+ * config/mh-sysv4 (RANLIB, INSTALL): Don't define.
+ * config.table: Change config_shell to CONFIG_SHELL, and use
+ libiberty_topdir to find move-if-change.
+ (m68k-apollo-bsd*, m68k-apollo-sysv*): Remove.
+ (i[3456]86-ncr-sysv4*, *-*-dgux*, hppa*-hp-bsd*): Remove.
+ (*-*-irix*, *-*-m88kbcs*, *-*-sysv*): Remove.
+ * Makefile.in (srcdir): Set to @srcdir@.
+ (VPATH): Likewise.
+ (prefix, exec_prefix, bindir, libdir): Set to autoconf variables.
+ (SHELL, INSTALL, INSTALL_PROGRAM, INSTALL_DATA): Likewise.
+ (CC, CFLAGS, RANLIB)): Likewise.
+ (datadir, man*dir, infodir, includedir, MAKEINFO): Remove.
+ (target_makefile_frag, host_makefile_frag): Add substitutions.
+ (INSTALL_DEST): Set to @INSTALL_DEST@.
+ (Makefile): Depend upon config.status. Don't depend upon
+ $(host_makefile_frag) or $(target_makefile_frag).
+ (config.status): New target.
+
+Sun May 3 17:58:49 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ * config/mt-sunos4: Remove. Should be handled by --with-headers
+ and --with-libraries options at top level.
+ * config.table: Never use mt-sunos4.
+
+ * alloca-conf.h: New file, combining alloca-norm.h and
+ alloca-botch.h.
+ * alloca-norm.h: Remove.
+ * alloca-botch.h: Remove.
+ * configure.in: Set shell variables files and links to empty.
+ * config.table: Don't set shell variable files.
+ * configure.bat: Don't create alloca-conf.h.
+ * makefile.vms: Likewise.
+ * mpw-config.in: Likewise.
+ * vmsbuild.com: Likewise.
+
+Fri May 1 11:41:42 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ * Makefile.in ($(HOST_OFILES) $(REQUIRED_OFILES)): Remove old
+ target depending upon config.h.
+ (alloca.o): Add target depending upon config.h
+ (basename.o, choose-temp.o, fnmatch.o): Likewise.
+ (getopt.o, getopt1.o, pexecute.o, strerror.o): Likewise.
+ (strsignal.o, xstrerror.o): Likewise.
+
+Fri May 1 04:26:25 1998 Peter Schauer <pes@regent.e-technik.tu-muenchen.de>
+
+ * cplus-dem.c (cplus_demangle_opname): Initialize work.
+
+Mon Apr 27 15:53:30 EDT 1998 Andrew MacLeod <amacleod@cygnus.com>
+
+ * cplus-dem.c (demangle_qualified): Replace missing else.
+
+Sun Apr 26 15:38:50 1998 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
+
+ * cplus-dem.c (gnu_special): Fix off-by-one bug when checking the
+ length in the name of a virtual table.
+
+Wed Apr 22 10:53:49 EDT 1998 Andrew MacLeod <amacleod@cygnus.com>
+
+ * cplus-dem.c (struct work stuff): Add field for B and K mangle codes.
+ (cplus_demangle_opname): Call mop_up_squangle.
+ (cplus_demangle): Initialize squangle info, then call
+ internal_cplus_demangle. (Most code moved there as well)
+ (internal_cplus_demangle): New function, performs most of what use
+ to be done in cplus_demangle, but is only called with this file.
+ (squangle_mop_up): New function to clean up B and K code data.
+ (mop_up): set pointers to NULL after freeing.
+ (demangle_signature, demangle_template, demangle_class): Add
+ switch elements to handle K and B codes.
+ (demangle_prefix, gnu_special, demangle_qualified): Add
+ code to handle K and B codes.
+ (do_type, demangle_fund_type): Handle B and K codes.
+ (remember_Ktype): New function to store K info.
+ (register_Btype, remember_Btype): New functions for B codes.
+ (forget_B_and_K_types): New function to destroy B and K info.
+
+Fri Apr 10 01:49:10 1998 Jeffrey A Law (law@cygnus.com)
+
+ * COPYING.LIB, choose-temp.c, cplus-dem.c: Sync with egcs & gcc.
+
+Mon Feb 23 14:33:15 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ * choose-temp.c: Fix handling of sys/file.h to work in libiberty.
+
+Sun Feb 22 18:03:23 1998 Jeffrey A Law (law@cygnus.com)
+
+ * choose-temp.c: Sync with copy in gcc.
+
+Thu Feb 12 16:29:49 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ * getopt.c: Update to latest FSF version.
+ * getopt1.c: Likewise.
+
+Tue Feb 10 16:58:33 1998 Stan Shebs <shebs@andros.cygnus.com>
+
+ * cplus-dem.c (gnu_special): Don't get confused by .<digits>
+ strings that are not actually lengths.
+
+Thu Feb 5 18:48:56 1998 Geoffrey Noer <noer@cygnus.com>
+
+ * config/mh-cygwin32: remove vasprintf.o from EXTRA_OFILES
+ since it gets built automatically
+
+Sun Feb 1 02:52:32 1998 Mike Stump <mrs@wrs.com>
+
+ * config.table (vxworks configs): Default to VxWorks 5.x, as that is
+ the currently shipping OS.
+
+Tue Jan 27 16:08:20 1998 Pat Rankin <rankin@eql.caltech.edu>
+
+ * vmsbuild.com [REQUIRE_OFILES]: Synchronized with Makefile.in:
+ Add fnmatch.o and objalloc.o; remove vasprintf.o.
+ [config.h]: Define NEED_strsignal.
+
+Mon Jan 19 12:20:01 1998 Ian Lance Taylor <ian@cygnus.com>
+
+ * functions.def: Correct argument types for strerror and
+ strsignal. Reported by Alex Gutman <agutman@emc.com>.
+
+Sun Jan 18 15:57:28 1998 Michael Snyder <msnyder@cleaver.cygnus.com>
+
+ * vasprintf.c (int_vasprintf): Increase buffer size for float/double
+ values.
+
+Sat Jan 17 22:28:38 1998 Mumit Khan <khan@xraylith.wisc.edu>
+ J.J. VanderHeijden <J.J.vanderHeijden@student.utwente.nl>
+
+ Add mingw32 support.
+ * pexecute.c (pexecute): New function for mingw32. Supports pipes.
+ (pwait): New function for mingw32.
+
+ * config.table (i[3456]86-*-mingw32*): Support for i386-mingw32.
+ * config/mt-mingw32: New file.
+ * xmalloc.c (first_break): Not used for mingw32.
+ (xmalloc_set_program_name): Don't use sbrk on mingw32.
+ (xmalloc): Likewise.
+ (xrealloc): Likewise.
+
+Sat Jan 17 22:28:05 1998 Jeffrey A Law (law@cygnus.com)
+
+ * choose-temp.c: Sync with gcc version.
+
+Tue Jan 13 18:34:39 1998 Jim Wilson <wilson@cygnus.com>
+
+ * Makefile.in (install_to_libdir, install_to_tooldir): Add MULTISUBDIR
+ to all filenames in libdir and tooldir.
+ (distclean): Do MULTICLEAN before deleting Makefile.
+ (stamp-needed, stamp-config): Add MULTISRCTOP to
+ pathname for move-if-change.
+
+Thu Dec 4 17:25:19 1997 Jeffrey A Law (law@cygnus.com)
+
+ * strsignal.c (sys_nsig): Try NSIG and _NSIG.
+
+Wed Nov 19 13:37:06 1997 Michael Meissner <meissner@cygnus.com>
+
+ * alloca-norm.h (alloca, GCC case): Don't redefine alloca if it
+ was already defined previously.
+
+Mon Nov 10 12:48:03 1997 Philippe De Muyter <phdm@macqel.be>
+
+ * Makefile.in (INSTALL): Use ../install-sh, not install.
+
+Tue Oct 28 23:41:15 1997 Judy Goldberg <jodyg@idt.net>
+
+ * Makefile.in (CFILES): Add pexecute.c.
+
+Wed Oct 15 19:13:48 1997 Ian Lance Taylor <ian@cygnus.com>
+
+ * asprintf.c: Consistently use either stdarg or varargs.
+
+Tue Oct 14 12:01:00 1997 Mark Mitchell <mmitchell@usa.net>
+
+ * cplus-dem.c (demangle_signature): Don't look for return types on
+ constructors. Handle member template constructors.
+
+Fri Oct 3 17:53:30 1997 Ian Lance Taylor <ian@cygnus.com>
+
+ * README: Fix configuration instructions.
+
+Mon Sep 29 12:28:41 1997 Ian Lance Taylor <ian@cygnus.com>
+
+ * pexecute.c: Update to current version from /gd/gnu/lib:
+
+ Mon Sep 29 12:27:59 1997 Ian Lance Taylor <ian@cygnus.com>
+
+ * pexecute.c: Use spawn if __CYGWIN32__.
+
+ 1997-08-08 Paul Eggert <eggert@twinsun.com>
+
+ * pexecute.c: Include "config.h" first, as per autoconf manual.
+
+ Fri Jun 27 15:20:29 1997 Scott Christley <scottc@net-community.com>
+
+ * pexecute.c (fix_argv): New function.
+ (pexecute): Win32 but not Cygwin32 needs its arguments fixed.
+ Add underscore to cwait function call.
+
+Sun Sep 28 12:00:52 1997 Mark Mitchell <mmitchell@usa.net>
+
+ * cplus-dem.c (demangle_template): Add new parameter. Handle new
+ template-function mangling.
+ (consume_count_with_underscores): New function.
+ (demangle_signature): Handle new name-mangling scheme.
+
+Wed Sep 24 00:31:59 1997 Felix Lee <flee@yin.cygnus.com>
+
+ * asprintf.c: stdarg.h when ALMOST_STDC
+ * config/mh-windows (EXTRA_OFILES): add asprintf.o and
+ strncasecmp.o.
+
+Thu Aug 28 14:27:15 1997 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * vasprintf.c (vasprintf): Allow for _BSD_VA_LIST_.
+
+ * config.table: Add case for FreeBSD 2.1 and 2.2, needs mh-fbsd21.
+
+ * config/mh-fbsd21 (EXTRA_OFILES): Force vasprintf.o
+
+Wed Sep 10 12:43:10 1997 Jason Merrill <jason@yorick.cygnus.com>
+
+ * cplus-dem.c (demangle_fund_type): Change "complex" to "__complex".
+
+Fri Sep 5 16:34:42 1997 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * asprintf.c (asprintf): New file.
+ * Makefile.in (CFILES): Add asprintf.c
+ * functions.def: Ditto.
+
+Thu Aug 28 18:53:34 1997 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * argv.c (dupargv): New function, duplicate an argument vector.
+
Tue Aug 19 20:28:45 1997 Geoffrey Noer <noer@cygnus.com>
* config/mh-cygwin32: also build random.o
@@ -6,12 +352,6 @@ Tue Aug 19 17:10:56 1997 Jason Merrill <jason@yorick.cygnus.com>
* cplus-dem.c: Add 'extern' to prepends_underscore.
-Wed Jul 30 11:42:19 1997 Per Bothner <bothner@cygnus.com>
-
- * cplus-dem.c: Various changes to produce Java output when passed
- DMGL_JAVA. Thus "::" becomes "." and "JArray<Foo>" becomes "Foo[]".
- (main): Support --java and -j flags to set DMGL_JAVA.
-
Tue Jul 22 19:05:23 1997 Robert Hoehne <robert.hoehne@Mathematik.TU-Chemnitz.DE>
* config/mh-go32 (CC, AR, RANLIB): Don't define.
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index 46874e12bf4..fd5026a9289 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -1,6 +1,7 @@
#
# Makefile
-# Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation
+# Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 1998
+# Free Software Foundation
#
# This file is part of the libiberty library.
# Libiberty is free software; you can redistribute it and/or
@@ -19,37 +20,22 @@
# Boston, MA 02111-1307, USA.
#
-# This file was written, and is maintained by K. Richard Pixley
-# <rich@cygnus.com>.
+# This file was written by K. Richard Pixley <rich@cygnus.com>.
#
# Makefile for libiberty directory
#
-srcdir = .
+srcdir = @srcdir@
+VPATH = @srcdir@
-prefix = /usr/local
+prefix = @prefix@
-exec_prefix = $(prefix)
-bindir = $(exec_prefix)/bin
-libdir = $(exec_prefix)/lib
+exec_prefix = @exec_prefix@
+bindir = @bindir@
+libdir = @libdir@
-datadir = $(prefix)/share
-
-mandir = $(prefix)/man
-man1dir = $(mandir)/man1
-man2dir = $(mandir)/man2
-man3dir = $(mandir)/man3
-man4dir = $(mandir)/man4
-man5dir = $(mandir)/man5
-man6dir = $(mandir)/man6
-man7dir = $(mandir)/man7
-man8dir = $(mandir)/man8
-man9dir = $(mandir)/man9
-infodir = $(prefix)/info
-includedir = $(prefix)/include
-
-SHELL = /bin/sh
+SHELL = @SHELL@
# Multilib support variables.
MULTISRCTOP =
@@ -59,19 +45,17 @@ MULTISUBDIR =
MULTIDO = true
MULTICLEAN = true
-INSTALL = install -c
-INSTALL_PROGRAM = $(INSTALL)
-INSTALL_DATA = $(INSTALL)
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
-AR = ar
+AR = @AR@
AR_FLAGS = rc
-ERRORS_CC = $(CC)
-CC = cc
-CFLAGS = -g
+CC = @CC@
+CFLAGS = @CFLAGS@
LIBCFLAGS = $(CFLAGS)
-MAKEINFO = makeinfo
-RANLIB = ranlib
+RANLIB = @RANLIB@
PICFLAG =
@@ -79,19 +63,7 @@ MAKEOVERRIDES =
TARGETLIB = libiberty.a
-CONFIG_H = lconfig.h
-NEEDED_LIST = lneeded-list
-
-# HOST_OFILES contains the list of objects that should be in the
-# library (in addition to the REQUIRED_OFILES and EXTRA_OFILES).
-# A configuration may override this with a fixed list a object files
-# names (hard to maintain), or some other way to generate a list.
-HOST_OFILES=`cat needed-list`
-
-# Extra targets that the top-level target depends on.
-# Specifically, what needs to be made before HOST_OFILES can be used.
-# Can be empty if HOST_OFILES is just a list of file names.
-DO_ALSO = needed-list
+LIBOBJS = @LIBOBJS@
# A configuration can specify extra .o files that should be included,
# even if they are in libc. (Perhaps the libc version is buggy.)
@@ -115,168 +87,88 @@ FLAGS_TO_PASS = \
"RANLIB=$(RANLIB)" \
"SHELL=$(SHELL)"
-all: stamp-picdir $(TARGETLIB) required-list
- @if [ "$(RULE1)" != "not-used" ]; then \
- $(MULTIDO) $(FLAGS_TO_PASS) multi-do DO=all; \
- else true; \
- fi
+all: stamp-picdir $(TARGETLIB) needed-list required-list
+ @$(MULTIDO) $(FLAGS_TO_PASS) multi-do DO=all
.PHONY: check installcheck
check installcheck:
-
-#### Host, target, and site specific Makefile fragments come in here.
-###
+@host_makefile_frag@
INCDIR=$(srcdir)/$(MULTISRCTOP)../include
-COMPILE.c = $(CC) -c $(LIBCFLAGS) -I. -I$(INCDIR) $(HDEFINES)
+COMPILE.c = $(CC) -c @DEFS@ $(LIBCFLAGS) -I. -I$(INCDIR) $(HDEFINES)
.c.o:
test -z "$(PICFLAG)" || \
$(COMPILE.c) $(PICFLAG) $< -o pic/$@
$(COMPILE.c) $<
-# The default target just invokes make recursively.
-# However, the automatic configuration (in config/mh_default).
-# first causes it to figure out the objects missing in libc.
info install-info clean-info dvi:
# Include files that are in this directory.
-HFILES =
+HFILES = alloca-conf.h
# NOTE: If you add new files to the library, add them to this list
-# (alphabetical), and add them to REQUIRED_OFILES or 'functions.def'.
-CFILES = alloca.c argv.c atexit.c basename.c bcmp.c bcopy.c bzero.c \
- choose-temp.c clock.c concat.c cplus-dem.c fdmatch.c fnmatch.c \
- getcwd.c getopt.c getopt1.c getpagesize.c getruntime.c \
- floatformat.c hex.c index.c insque.c \
- memchr.c memcmp.c memcpy.c memmove.c memset.c objalloc.c \
- obstack.c random.c rename.c rindex.c sigsetmask.c spaces.c \
- strcasecmp.c strncasecmp.c \
- strchr.c strdup.c strerror.c strrchr.c strsignal.c \
- strstr.c strtod.c strtol.c strtoul.c tmpnam.c \
- vasprintf.c vfork.c vfprintf.c vprintf.c vsprintf.c waitpid.c \
- xatexit.c xexit.c xmalloc.c xstrdup.c xstrerror.c
+# (alphabetical), and add them to REQUIRED_OFILES or funcs in
+# configure.in.
+CFILES = asprintf.c alloca.c argv.c atexit.c basename.c bcmp.c bcopy.c \
+ bzero.c choose-temp.c clock.c concat.c cplus-dem.c fdmatch.c \
+ fnmatch.c getcwd.c getopt.c getopt1.c getpagesize.c \
+ getruntime.c floatformat.c hex.c index.c insque.c memchr.c \
+ memcmp.c memcpy.c memmove.c memset.c objalloc.c obstack.c \
+ pexecute.c random.c rename.c rindex.c sigsetmask.c spaces.c \
+ strcasecmp.c strncasecmp.c strchr.c strdup.c strerror.c \
+ strrchr.c strsignal.c strstr.c strtod.c strtol.c strtoul.c \
+ tmpnam.c vasprintf.c vfork.c vfprintf.c vprintf.c vsprintf.c \
+ waitpid.c xatexit.c xexit.c xmalloc.c xstrdup.c xstrerror.c
+
# These are always included in the library.
-REQUIRED_OFILES = argv.o basename.o choose-temp.o concat.o cplus-dem.o \
+REQUIRED_OFILES = argv.o choose-temp.o concat.o cplus-dem.o \
fdmatch.o fnmatch.o getopt.o getopt1.o getruntime.o hex.o \
floatformat.o objalloc.o obstack.o pexecute.o spaces.o strerror.o \
strsignal.o xatexit.o xexit.o xmalloc.o xstrdup.o xstrerror.o
-# Do we want/need any config overrides?
-#
-
-STAGESTUFF = $(TARGETLIB) *.o
+$(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
+ rm -f $(TARGETLIB)
+ $(AR) $(AR_FLAGS) $(TARGETLIB) \
+ $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
+ $(RANLIB) $(TARGETLIB)
-INSTALL_DEST = libdir
+INSTALL_DEST = @INSTALL_DEST@
install: install_to_$(INSTALL_DEST)
install_to_libdir: all
- $(INSTALL_DATA) $(TARGETLIB) $(libdir)/$(TARGETLIB).n
- ( cd $(libdir) ; $(RANLIB) $(libdir)/$(TARGETLIB).n )
- mv -f $(libdir)/$(TARGETLIB).n $(libdir)$(MULTISUBDIR)/$(TARGETLIB)
+ $(INSTALL_DATA) $(TARGETLIB) $(libdir)$(MULTISUBDIR)/$(TARGETLIB).n
+ ( cd $(libdir)$(MULTISUBDIR) ; $(RANLIB) $(TARGETLIB).n )
+ mv -f $(libdir)$(MULTISUBDIR)/$(TARGETLIB).n $(libdir)$(MULTISUBDIR)/$(TARGETLIB)
@$(MULTIDO) $(FLAGS_TO_PASS) multi-do DO=install
install_to_tooldir: all
- $(INSTALL_DATA) $(TARGETLIB) $(tooldir)/lib/$(TARGETLIB).n
- ( cd $(tooldir) ; $(RANLIB) $(tooldir)/lib/$(TARGETLIB).n )
- mv -f $(tooldir)/lib/$(TARGETLIB).n $(tooldir)/lib$(MULTISUBDIR)/$(TARGETLIB)
+ $(INSTALL_DATA) $(TARGETLIB) $(tooldir)/lib$(MULTISUBDIR)/$(TARGETLIB).n
+ ( cd $(tooldir)/lib$(MULTISUBDIR) ; $(RANLIB) $(TARGETLIB).n )
+ mv -f $(tooldir)/lib$(MULTISUBDIR)/$(TARGETLIB).n $(tooldir)/lib$(MULTISUBDIR)/$(TARGETLIB)
@$(MULTIDO) $(FLAGS_TO_PASS) multi-do DO=install
-# The default configuration adds to libiberty all those functions that are
-# missing in libc. More precisely, it includes whatever $(CC) fails to find.
-# Then a sed+awk combination translates the ld error messages into
-# a list of .o files.
-
-stamp-needed: stamp-picdir $(NEEDED_LIST)
- cp $(NEEDED_LIST) needed-tmp
- $(SHELL) $(srcdir)/../move-if-change needed-tmp needed-list
- touch stamp-needed
-
-needed-list: stamp-needed ; @true
-
-lneeded-list: $(EXTRA_OFILES) needed.awk errors
- rm -f lneeded-list
- f=""; \
- for i in `awk -f needed.awk <errors` $(EXTRA_OFILES) ; do \
- case " $$f " in \
- *" $$i "*) ;; \
- *) f="$$f $$i" ;; \
- esac ; \
- done ; \
+# needed-list is used by libstdc++.
+needed-list: Makefile
+ f="$(LIBOBJS) $(EXTRA_OFILES)"; \
case $$f in \
- *alloca.o*) f="$$f xmalloc.o xexit.o" ;; \
- esac ; \
- echo $$f >>lneeded-list
-
-# Generate an awk script that looks for functions in functions.def
-
-needed.awk: $(srcdir)/functions.def Makefile
- echo "# !Automatically generated from $(srcdir)/functions.def"\
- "- DO NOT EDIT!" >needed.awk
- grep '^DEF(' < $(srcdir)/functions.def \
- | sed -e '/DEF/s|DEF.\([^,]*\).*|/\1/ { printf "\1.o " }|' \
- >>needed.awk
-
-stamp-config: $(CONFIG_H)
- cp $(CONFIG_H) config.tmp
- $(SHELL) $(srcdir)/../move-if-change config.tmp config.h
- touch stamp-config
-
-config.h: stamp-config ; @true
-
-lconfig.h: needed2.awk errors
- echo "/* !Automatically generated from $(srcdir)/functions.def"\
- "- DO NOT EDIT! */" >lconfig.h
- awk -f needed2.awk <errors >>lconfig.h
-
-# Generate an awk script that looks for variables in functions.def
-
-needed2.awk: $(srcdir)/functions.def Makefile
- echo "# !Automatically generated from $(srcdir)/functions.def"\
- "- DO NOT EDIT!" >needed2.awk
- grep '^DEFVAR(' < $(srcdir)/functions.def \
- | sed -e '/DEFVAR/s|DEFVAR.\([^,]*\).*|/\1/ { printf "#ifndef NEED_\1\\n#define NEED_\1\\n#endif\\n" }|' \
- >>needed2.awk
- grep '^DEFFUNC(' < $(srcdir)/functions.def \
- | sed -e '/DEFFUNC/s|DEFFUNC.\([^,]*\).*|/\1/ { printf "#ifndef NEED_\1\\n#define NEED_\1\\n#endif\\n" }|' \
- >>needed2.awk
-
-dummy.o: $(srcdir)/dummy.c $(srcdir)/functions.def
- $(CC) -c $(CFLAGS) -I. -I$(INCDIR) $(HDEFINES) $(srcdir)/dummy.c 2>/dev/null
-
-errors: dummy.o $(EXTRA_OFILES)
- -($(ERRORS_CC) -o dummy $(CFLAGS) $(LDFLAGS) $(ERRORS_LDFLAGS) dummy.o $(EXTRA_OFILES) $(LOADLIBES)) >errors 2>&1 || true
-
-# required-list is used when building a shared bfd/opcodes/libiberty library.
+ *alloca.o*) f="$$f xmalloc.o xexit.o" ;; \
+ esac; \
+ echo $$f > needed-list
+
+# required-list was used when building a shared bfd/opcodes/libiberty
+# library. I don't know if it used by anything currently.
required-list: Makefile
echo $(REQUIRED_OFILES) > required-list
-$(HOST_OFILES) $(REQUIRED_OFILES) : config.h
-
-RULE1 = $(TARGETLIB)
-$(RULE1): $(REQUIRED_OFILES) $(DO_ALSO) .always.
- @$(MAKE) RULE1=not-used RULE2=$(TARGETLIB) $(FLAGS_TO_PASS) \
- "HOST_OFILES=$(HOST_OFILES)"
-
-# Rule invoked by recursive make in $(RULE1).
-RULE2 = not-used
-$(RULE2): $(REQUIRED_OFILES) $(HOST_OFILES)
- rm -rf $(TARGETLIB)
- $(AR) $(AR_FLAGS) $(TARGETLIB) \
- $(REQUIRED_OFILES) $(HOST_OFILES)
- $(RANLIB) $(TARGETLIB)
-
stamp-picdir:
if [ -n "$(PICFLAG)" ] && [ ! -d pic ]; then \
mkdir pic; \
else true; fi
touch stamp-picdir
-.always.:
-# Do nothing.
-
-.PHONY: all etags tags ls clean stage1 stage2 .always.
+.PHONY: all etags tags ls clean stage1 stage2
etags tags: TAGS
@@ -303,34 +195,47 @@ clean: mostlyclean
rm -f *.a required-list tmpmulti.out
@$(MULTICLEAN) multi-clean DO=clean
distclean: clean
- rm -f *~ Makefile config.status alloca-conf.h xhost-mkfrag TAGS multilib.out
@$(MULTICLEAN) multi-clean DO=distclean
+ rm -f *~ Makefile config.status alloca-conf.h xhost-mkfrag TAGS multilib.out
maintainer-clean realclean: distclean
force:
-Makefile: $(srcdir)/Makefile.in $(host_makefile_frag) $(target_makefile_frag)
- $(SHELL) ./config.status
+Makefile: $(srcdir)/Makefile.in config.status
+ CONFIG_FILES=Makefile CONFIG_HEADERS= $(SHELL) ./config.status
+
+config.h: stamp-h ; @true
+stamp-h: config.in config.status
+ CONFIG_FILES= CONFIG_HEADERS=config.h:config.in $(SHELL) ./config.status
+
+config.status: $(srcdir)/configure $(srcdir)/config.table
+ $(SHELL) ./config.status --recheck
-argv.o: $(INCDIR)/libiberty.h
+alloca.o: config.h
+atexit.o: config.h
+argv.o: config.h alloca-conf.h $(INCDIR)/libiberty.h
basename.o: $(INCDIR)/libiberty.h
+choose-temp.o: config.h
+clock.o: config.h
concat.o: $(INCDIR)/libiberty.h
cplus-dem.o: $(INCDIR)/demangle.h
fdmatch.o: $(INCDIR)/libiberty.h
-fnmatch.o: $(INCDIR)/fnmatch.h
-getopt.o: $(INCDIR)/getopt.h
-getopt1.o: $(INCDIR)/getopt.h
-getruntime.o: $(INCDIR)/libiberty.h
+fnmatch.o: config.h $(INCDIR)/fnmatch.h
+getcwd.o: config.h
+getopt.o: config.h $(INCDIR)/getopt.h
+getopt1.o: config.h $(INCDIR)/getopt.h
+getpagesize.o: config.h
+getruntime.o: config.h $(INCDIR)/libiberty.h
hex.o: $(INCDIR)/libiberty.h
floatformat.o: $(INCDIR)/floatformat.h
objalloc.o: $(INCDIR)/objalloc.h
obstack.o: $(INCDIR)/obstack.h
-pexecute.o: $(INCDIR)/libiberty.h
+pexecute.o: config.h $(INCDIR)/libiberty.h
spaces.o: $(INCDIR)/libiberty.h
-strerror.o: $(INCDIR)/libiberty.h
-strsignal.o: $(INCDIR)/libiberty.h
+strerror.o: config.h $(INCDIR)/libiberty.h
+strsignal.o: config.h $(INCDIR)/libiberty.h
xatexit.o: $(INCDIR)/libiberty.h
xexit.o: $(INCDIR)/libiberty.h
xmalloc.o: $(INCDIR)/libiberty.h
xstrdup.o: $(INCDIR)/libiberty.h
-xstrerror.o: $(INCDIR)/libiberty.h
+xstrerror.o: config.h $(INCDIR)/libiberty.h
diff --git a/libiberty/README b/libiberty/README
index 5081bbac196..9f5226a6b1d 100644
--- a/libiberty/README
+++ b/libiberty/README
@@ -11,10 +11,9 @@ Current members include:
We expect many of the GNU subroutines that are floating around to
eventually arrive here.
-To build the library, do:
-
- ./configure HOSTTYPE
- make
+The library must be configured from the top source directory. Don't
+try to run configure in this directory. Follow the configuration
+instructions in ../README.
Please report bugs and fixes to "bug-gnu-utils@prep.ai.mit.edu". Thank you.
@@ -28,62 +27,29 @@ that are "optional" will be included in the library only if "needed."
To add a new required file, edit Makefile to add the source file
name to CFILES and the object file to REQUIRED_OFILES.
-Adding a new optional file is more fragile. As a general rule,
-an optional file will be included in the library if it provides
-functionality missing in the "standard" C library.
-For most hosts, the Makefile automatically figures out which
-functionality is missing by compiling and linking a dummy test
-program, and examining the error messages.
-
-So to get this to work, you should do the following:
-
-1) Select one function defined in the file you're adding.
-For example, the getcwd function.
-2) Add that function to the list in the file functions.def.
-3) The name of the new file must be the same as the function
-you've chosen with the .c suffix added. E.g. getcwd() must be
-defined in getcwd.c. (The file can define other functions as well.)
-4) In Makefile.in, add the name of the source file (e.g. getcwd.c)
-to CFILES.
-
-The file you've added (e.g. getcwd.c) should compile and work
-on all hosts where it is needed (e.g. not found when linking
-the dummy.c program). It does not have to work or even
-compile on hosts where it is not needed.
+To add a new optional file, it must provide a single function, and the
+name of the function must be the same as the name of the file.
+
+ * Add the source file name to CFILES.
+
+ * Add the function to name to the funcs shell variable in
+ configure.in.
-HOW THE AUTOMATIC CONFIGURATION WORKS
-=====================================
-
-The libiberty.a target (in RULE1) depends on $(DO_ALSO).
-For normal configurations, DO_ALSO=needed-list.
-
-So needed-list is first made. The needed-list rule compiles
-dummy.c. Because dummy.c includes functions.def, the
-resulting object file will contain a call to each of the
-optional functions (for simplicity assume each optional file
-defines a single function). This object file will be linked
-against the standard libraries (as defined by using $(CC)
-and various flags). Any function missing will causes the
-linker to emit an error message. We assume the name
-of the missing function(s) are in the error message(s).
-The awk script find-needed.awk has been generated from
-functions.def. It is used to search the linker output
-messages for words that match the functions listed in
-functions.def. The list of functions found is written
-on a single line to the file needed-list.
-
-After needed-list has been generated, the libiberty.a
-target (in RULE1) just calls 'make' recursively.
-It passes the contents of needed-list using the
-definition (expanded) HOST_OFILES="`cat needed-list`".
-It also tells the inferior 'make' to use RULE2.
-
-The inferior 'make' is very conventional: The main
-rule is $(RULE2) (which is libiberty.a). It depends
-on a list of object files: $(REQUIRED_OFILES) $(HOST_OFILES)
-(and $(EXTRA_OFILES), which is usually empty). The superior
-'make' passes in $(HOST_OFILES); the others are fixed
-in the Makefile.
+ * Add the function to the AC_CHECK_FUNCS lists just after the
+ setting of the funcs shell variable. These AC_CHECK_FUNCS calls
+ are never executed; they are there to make autoheader work
+ better.
+
+ * Consider the special cases of building libiberty; as of this
+ writing, the special cases are newlib and VxWorks. If a
+ particular special case provides the function, you do not need
+ to do anything. If it does not provide the function, add the
+ object file to LIBOBJS, and add the function name to the case
+ controlling whether to define HAVE_func.
+
+The optional file you've added (e.g. getcwd.c) should compile and work
+on all hosts where it is needed. It does not have to work or even
+compile on hosts where it is not needed.
ADDING A NEW CONFIGURATION
==========================
@@ -96,34 +62,4 @@ If the fully automatic scheme doesn't work, you may be able to get
by with defining EXTRA_OFILES in your Makefile stub. This is
a list of object file names that should be treated as required
for this configuration - they will be included in libiberty.a,
-regardless of whatever might be in the C library. Moreover,
-when the dummy.c program is linked, it will be linked with
-$(EXTRA_OFILES). Therefore, if a function in functions.def
-is defined by one of the EXTRA_OFILES, it will not be listed as
-"needed". Thus if your hal9000 host needs a special implementation
-of getcwd, you can just create hal9000-getcwd.c, and define:
- EXTRA_OFILES=hal9000-getcwd.o
-Or if you want to use the libiberty version of strstr(),
-even though there is a version in the C library (it might be
-buggy or slow), just define:
- EXTRA_OFILES=strstr.o
-
-You can create a "manual" host configuration FOO with a file
-config/mh-FOO. In it, the HOST_OFILES macro should explicitly
-list that subset of the optional files that should be in the
-library. You should also set:
- DO_ALSO =
-This overrides all of the magic needed to automatically
-determine which files are "needed." However, keeping that list
-up to date is another matter...
-
-HOW THE MANUAL CONFIGURATION WORKS
-==================================
-
-This also uses a recursive make, but the superior make
-does not do anything interesting - it just calls the
-inferior make with HOST_OFILES defined as $(HOST_OFILES),
-which is the list you created in your configuration.
-
-You probably don't want to depend on manual configuration,
-because keeping the HOST_OFILES list up-to-date will be a pain.
+regardless of whatever might be in the C library.
diff --git a/libiberty/argv.c b/libiberty/argv.c
index 60694f919bb..195d31019a0 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -72,6 +72,63 @@ extern char *strdup (); /* Duplicate a string */
NAME
+ dupargv -- duplicate an argument vector
+
+SYNOPSIS
+
+ char **dupargv (vector)
+ char **vector;
+
+DESCRIPTION
+
+ Duplicate an argument vector. Simply scans through the
+ vector, duplicating each argument until the
+ terminating NULL is found.
+
+RETURNS
+
+ Returns a pointer to the argument vector if
+ successful. Returns NULL if there is insufficient memory to
+ complete building the argument vector.
+
+*/
+
+char **
+dupargv (argv)
+ char **argv;
+{
+ int argc;
+ char **copy;
+
+ if (argv == NULL)
+ return NULL;
+
+ /* the vector */
+ for (argc = 0; argv[argc] != NULL; argc++);
+ copy = (char **) malloc ((argc + 1) * sizeof (char *));
+ if (copy == NULL)
+ return NULL;
+
+ /* the strings */
+ for (argc = 0; argv[argc] != NULL; argc++)
+ {
+ int len = strlen (argv[argc]);
+ copy[argc] = malloc (sizeof (char *) * (len + 1));
+ if (copy[argc] == NULL)
+ {
+ freeargv (copy);
+ return NULL;
+ }
+ strcpy (copy[argc], argv[argc]);
+ }
+ copy[argc] = NULL;
+ return copy;
+}
+
+/*
+
+NAME
+
freeargv -- free an argument vector
SYNOPSIS
diff --git a/libiberty/asprintf.c b/libiberty/asprintf.c
index 1cd63978037..5aaf3200f0d 100644
--- a/libiberty/asprintf.c
+++ b/libiberty/asprintf.c
@@ -22,14 +22,18 @@ Boston, MA 02111-1307, USA. */
#include "ansidecl.h"
#include "libiberty.h"
-#if defined __STDC__ || defined ALMOST_STDC
+#if defined (ANSI_PROTOTYPES) || defined (ALMOST_STDC)
+#define USE_STDARG
+#endif
+
+#ifdef USE_STDARG
#include <stdarg.h>
#else
#include <varargs.h>
#endif
/* VARARGS */
-#ifdef ANSI_PROTOTYPES
+#ifdef USE_STDARG
int
asprintf (char **buf, const char *fmt, ...)
#else
@@ -42,7 +46,7 @@ asprintf (buf, fmt, va_alist)
{
int status;
va_list ap;
-#ifdef ANSI_PROTOTYPES
+#ifdef USE_STDARG
va_start (ap, fmt);
#else
va_start (ap);
diff --git a/libiberty/atexit.c b/libiberty/atexit.c
index 4463cb69501..137d985e4cb 100644
--- a/libiberty/atexit.c
+++ b/libiberty/atexit.c
@@ -1,7 +1,10 @@
/* Wrapper to implement ANSI C's atexit using SunOS's on_exit. */
/* This function is in the public domain. --Mike Stump. */
-#ifndef NEED_on_exit
+#include "config.h"
+
+#ifdef HAVE_ON_EXIT
+
int
atexit(f)
void (*f)();
@@ -11,4 +14,5 @@ atexit(f)
on_exit (f, 0);
return 0;
}
+
#endif
diff --git a/libiberty/basename.c b/libiberty/basename.c
index 689b0c2d39a..f544c853910 100644
--- a/libiberty/basename.c
+++ b/libiberty/basename.c
@@ -20,10 +20,6 @@ BUGS
#include "ansidecl.h"
#include "libiberty.h"
-#include "config.h"
-
-#ifdef NEED_basename
-
char *
basename (name)
const char *name;
@@ -39,5 +35,3 @@ basename (name)
}
return (char *) base;
}
-
-#endif
diff --git a/libiberty/choose-temp.c b/libiberty/choose-temp.c
index 798de4822a5..ea4f9ed5f32 100644
--- a/libiberty/choose-temp.c
+++ b/libiberty/choose-temp.c
@@ -1,5 +1,5 @@
/* Utility to pick a temporary filename prefix.
- Copyright (C) 1996 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
@@ -22,7 +22,21 @@ Boston, MA 02111-1307, USA. */
/* This file lives in at least two places: libiberty and gcc.
Don't change one without the other. */
-#ifndef NO_SYS_FILE_H
+#if defined (IN_GCC) || defined (HAVE_CONFIG_H)
+#include "config.h"
+#endif
+
+#ifdef IN_GCC
+#include "system.h"
+#else
+
+/* If we are in gcc, system.h has handled everything. When not in
+ gcc, if we have a config.h we assume that HAVE_SYS_FILE_H tells us
+ whether to include sys/file.h. However, libiberty does not have a
+ config.h, and instead arranges to define NO_SYS_FILE_H on the
+ command line when there is no sys/file.h. */
+
+#if defined (HAVE_CONFIG_H) ? defined (HAVE_SYS_FILE_H) : ! defined (NO_SYS_FILE_H)
#include <sys/types.h>
#include <sys/file.h> /* May get R_OK, etc. on some systems. */
#endif
@@ -34,9 +48,9 @@ Boston, MA 02111-1307, USA. */
#endif
#include <stdio.h> /* May get P_tmpdir. */
+#endif /* IN_GCC */
#ifdef IN_GCC
-#include "config.h"
#include "gansidecl.h"
extern char *xmalloc ();
#else
@@ -54,7 +68,7 @@ extern char *xmalloc ();
/* On MSDOS, write temp files in current dir
because there's no place else we can expect to use. */
/* ??? Although the current directory is tried as a last resort,
- this is left in so that on MSDOS it is prefered to /tmp on the
+ this is left in so that on MSDOS it is preferred to /tmp on the
off chance that someone requires this, since that was the previous
behaviour. */
#ifdef __MSDOS__
@@ -68,7 +82,7 @@ extern char *xmalloc ();
#define TEMP_FILE "ccXXXXXX"
/* Subroutine of choose_temp_base.
- If BASE is non-NULL, returh it.
+ If BASE is non-NULL, return it.
Otherwise it checks if DIR is a usable directory.
If success, DIR is returned.
Otherwise NULL is returned. */
@@ -114,11 +128,7 @@ choose_temp_base ()
/* If all else fails, use the current directory! */
if (base == 0)
-#ifdef VMS
- base = "[";
-#else
base = ".";
-#endif
#else /* MPW */
base = ":";
diff --git a/libiberty/clock.c b/libiberty/clock.c
index b60de1657a4..b204566ff25 100644
--- a/libiberty/clock.c
+++ b/libiberty/clock.c
@@ -22,13 +22,15 @@ the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
+#include "config.h"
+
#ifdef HAVE_GETRUSAGE
#include <sys/time.h>
#include <sys/resource.h>
#endif
#ifdef HAVE_TIMES
-#ifndef NO_SYS_PARAM_H
+#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <sys/times.h>
diff --git a/libiberty/config.table b/libiberty/config.table
index dba783b489f..881c1a7ecc3 100644
--- a/libiberty/config.table
+++ b/libiberty/config.table
@@ -1,41 +1,10 @@
case "${host}" in
rs6000-ibm-aix3.1 | rs6000-ibm-aix)
- frag=mh-aix
- files=${xsrcdir}alloca-botch.h ;;
- *-ibm-aix*) files=${xsrcdir}alloca-botch.h ;;
- arm-*-riscix*) frag=mh-riscix ;;
- m68k-apollo-bsd*) frag=mh-a68bsd ;;
- m68k-apollo-sysv*) frag=mh-apollo68 ;;
- i[3456]86-ncr-sysv4*) frag=mh-ncr3000 ;;
+ frag=mh-aix ;;
*-*-cxux7*) frag=mh-cxux7 ;;
- *-*-cygwin32) frag=mh-cygwin32 ;;
- *-*-dgux*) frag=mh-sysv ;;
- hppa*-hp-bsd*) frag=mh-hpbsd ;;
- *-*-hpux*) frag=mh-hpux ;;
- *-*-hiux*) frag=mh-hpux ;;
- *-*-irix4*) frag=mh-irix4 ;;
- *-*-irix*) frag=mh-sysv ;;
- *-*-m88kbcs*) frag=mh-sysv ;;
- *-*-solaris2*) frag=mh-sysv4 ;;
- *-*-sysv4*) frag=mh-sysv4 ;;
- *-*-sysv*) frag=mh-sysv ;;
- *-*-go32) frag=mh-go32 ;;
+ *-*-freebsd2.1.*) frag=mh-fbsd21 ;;
+ *-*-freebsd2.2.*) frag=mh-fbsd21 ;;
i[345]86-*-windows*) frag=mh-windows ;;
-
- *-*-vxworks5*)
- # VxWorks 5 needs special action, because the usual
- # autoconfiguration scheme does not work.
- frag=mt-vxworks5
- ;;
-esac
-
-# Try to handle funky case of solaris 2 -> sun 4.
-case "${host}" in
- sparc-sun-sunos4.1.3)
- if [ "${with_cross_host}" != "${host}" ] ; then
- frag=mt-sunos4
- fi
- ;;
esac
frags=$frag
@@ -48,6 +17,7 @@ case "${enable_shared}" in
esac
if [ "${shared}" = "yes" ]; then
case "${host}" in
+ *-*-cygwin32*) ;;
hppa*-*-*) frags="${frags} ../../config/mh-papic" ;;
i[3456]86-*-*) frags="${frags} ../../config/mh-x86pic" ;;
*-*-*) frags="${frags} ../../config/mh-${host_cpu}pic" ;;
@@ -66,4 +36,4 @@ for frag in ${frags}; do
done
frag=xhost-mkfrag
-${config_shell} ${moveifchange} temp-frag xhost-mkfrag
+${CONFIG_SHELL} ${libiberty_topdir}/move-if-change temp-frag xhost-mkfrag
diff --git a/libiberty/config/mh-aix b/libiberty/config/mh-aix
index c7b848d976a..6b645058fa9 100644
--- a/libiberty/config/mh-aix
+++ b/libiberty/config/mh-aix
@@ -1,6 +1,5 @@
+# This file is only needed by AIX 3.1.
HDEFINES = -D__IEEE_BIG_ENDIAN
-RANLIB=true
-INSTALL=cp
# Most releases of AIX 3.1 include an incorrect internal version of copysign
# in libc.a for use by some libc public functions including modf. The public
diff --git a/libiberty/config/mh-cxux7 b/libiberty/config/mh-cxux7
index 6d4d30bf46f..a924b0853fc 100644
--- a/libiberty/config/mh-cxux7
+++ b/libiberty/config/mh-cxux7
@@ -1,3 +1 @@
-HDEFINES = -DHAVE_SYSCONF -DHARRIS_FLOAT_FORMAT
-RANLIB=true
-INSTALL = cp
+HDEFINES = -DHARRIS_FLOAT_FORMAT
diff --git a/libiberty/config/mh-windows b/libiberty/config/mh-windows
index f20c51f2191..3ff5f794e9f 100644
--- a/libiberty/config/mh-windows
+++ b/libiberty/config/mh-windows
@@ -1,2 +1 @@
-HDEFINES=-DNEED_basename -DNEED_sys_siglist -DNEED_strsignal -DNO_SYS_FILE_H
-EXTRA_OFILES=strcasecmp.o vasprintf.o
+EXTRA_OFILES=asprintf.o strcasecmp.o strncasecmp.o vasprintf.o
diff --git a/libiberty/configure.bat b/libiberty/configure.bat
index ed33777174b..18881ac2f75 100644
--- a/libiberty/configure.bat
+++ b/libiberty/configure.bat
@@ -5,7 +5,6 @@ echo Configuring libiberty for go32
copy Makefile.dos Makefile
echo #define NEED_sys_siglist 1 >> config.h
echo #define NEED_psignal 1 >> config.h
-update alloca-normal.h alloca-conf.h
goto exit
:h8300
diff --git a/libiberty/configure.in b/libiberty/configure.in
index b0020d8bab4..05a9df1e975 100644
--- a/libiberty/configure.in
+++ b/libiberty/configure.in
@@ -1,66 +1,328 @@
-# This file is a shell script fragment that supplies the information
-# necessary for a configure script to process the program in
-# this directory. For more information, look at ../configure.
+dnl Process this file with autoconf to produce a configure script
-configdirs=
-srctrigger=getopt1.c
-srcname="-liberty library"
+AC_PREREQ(2.5)
+AC_INIT(pexecute.c)
-# per-host:
+dnl We use these options to decide which functions to include.
+AC_ARG_WITH(target-subdir,
+[ --with-target-subdir=SUBDIR Configuring with a cross compiler])
+AC_ARG_WITH(newlib,
+[ --with-newlib Configuring with newlib])
-files="alloca-norm.h"
-links="alloca-conf.h"
+if test "${srcdir}" = "."; then
+ if test -z "${with_target_subdir}"; then
+ libiberty_topdir="${srcdir}/.."
+ else
+ if test "${with_target_subdir}" != "."; then
+ libiberty_topdir="${srcdir}/${with_multisrctop}../.."
+ else
+ libiberty_topdir="${srcdir}/${with_multisrctop}.."
+ fi
+ fi
+else
+ libiberty_topdir="${srcdir}/.."
+fi
+AC_CONFIG_AUX_DIR($libiberty_topdir)
+
+AC_CANONICAL_HOST
+
+dnl When we start using automake:
+dnl AM_INIT_AUTOMAKE(libiberty, 1.0)
+
+dnl These must be called before AM_PROG_LIBTOOL, because it may want
+dnl to call AC_CHECK_PROG.
+AC_CHECK_TOOL(AR, ar)
+AC_CHECK_TOOL(RANLIB, ranlib, :)
+
+# FIXME: We temporarily define our own version of AC_PROG_CC. This is
+# copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS. We
+# are probably using a cross compiler, which will not be able to fully
+# link an executable. This should really be fixed in autoconf
+# itself.
+
+AC_DEFUN(LIB_AC_PROG_CC,
+[AC_BEFORE([$0], [AC_PROG_CPP])dnl
+AC_PROVIDE([AC_PROG_CC])
+AC_CHECK_PROG(CC, gcc, gcc)
+if test -z "$CC"; then
+ AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
+ test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
+fi
+
+AC_PROG_CC_GNU
+
+if test $ac_cv_prog_gcc = yes; then
+ GCC=yes
+dnl Check whether -g works, even if CFLAGS is set, in case the package
+dnl plays around with CFLAGS (such as to build both debugging and
+dnl normal versions of a library), tasteless as that idea is.
+ ac_test_CFLAGS="${CFLAGS+set}"
+ ac_save_CFLAGS="$CFLAGS"
+ CFLAGS=
+ AC_PROG_CC_G
+ if test "$ac_test_CFLAGS" = set; then
+ CFLAGS="$ac_save_CFLAGS"
+ elif test $ac_cv_prog_cc_g = yes; then
+ CFLAGS="-g -O2"
+ else
+ CFLAGS="-O2"
+ fi
+else
+ GCC=
+ test "${CFLAGS+set}" = set || CFLAGS="-g"
+fi
+])
+
+LIB_AC_PROG_CC
+
+AC_ISC_POSIX
+
+dnl When we start using libtool:
+dnl Default to a non shared library. This may be overridden by the
+dnl configure option --enable-shared.
+dnl AM_DISABLE_SHARED
+
+dnl When we start using libtool:
+dnl AM_PROG_LIBTOOL
+
+dnl When we start using automake:
+dnl AM_CONFIG_HEADER(config.h:config.in)
+AC_CONFIG_HEADER(config.h:config.in)
+
+dnl When we start using automake:
+dnl AM_MAINTAINER_MODE
+dnl AM_EXEEXT
+
+dnl When we start using automake:
+dnl AM_PROG_INSTALL
+AC_PROG_INSTALL
. ${srcdir}/config.table
host_makefile_frag=${frag}
+AC_SUBST_FILE(host_makefile_frag)
+
+# It's OK to check for header files. Although the compiler may not be
+# able to link anything, it had better be able to at least compile
+# something.
+AC_CHECK_HEADERS(sys/file.h sys/param.h stdlib.h string.h)
-# per-target:
-
-# post-target:
-
-# If this is the target libiberty, check at compile time whether we are using
-# newlib. If we are, we already know the files we need, since the linker
-# will fail when run on some of the newlib targets.
-if [ -n "${with_target_subdir}" ] ; then
- cat > Makefile.tem <<'!EOF!'
-CONFIG_H = xconfig.h
-NEEDED_LIST = xneeded-list
-
-xconfig.h: Makefile
- if [ -f ../newlib/Makefile ]; then \
- echo "#define NEED_sys_nerr 1" >xconfig.h; \
- echo "#define NEED_sys_errlist 1" >>xconfig.h; \
- echo "#define NEED_sys_siglist 1" >>xconfig.h; \
- echo "#define NEED_strsignal 1" >>xconfig.h; \
- echo "#define NEED_psignal 1" >>xconfig.h; \
- else \
- $(MAKE) $(FLAGS_TO_PASS) lconfig.h; \
- cp lconfig.h xconfig.h; \
- fi
-
-xneeded-list: Makefile
- if [ -f ../newlib/Makefile ]; then \
- echo insque.o random.o strdup.o alloca.o vasprintf.o >xneeded-list; \
- else \
- $(MAKE) $(FLAGS_TO_PASS) lneeded-list; \
- cp lneeded-list xneeded-list; \
- fi
-!EOF!
-sed -e "/^####/ r Makefile.tem" \
- -e '/INSTALL_DEST =/s/libdir/tooldir/' ${Makefile} > Makefile.tem3
-mv Makefile.tem3 ${Makefile}
-rm -f Makefile.tem
+# This is the list of functions which libiberty will provide if they
+# are not available on the host.
+
+funcs="asprintf"
+funcs="$funcs atexit"
+funcs="$funcs basename"
+funcs="$funcs bcmp"
+funcs="$funcs bcopy"
+funcs="$funcs bzero"
+funcs="$funcs clock"
+funcs="$funcs getcwd"
+funcs="$funcs getpagesize"
+funcs="$funcs index"
+funcs="$funcs insque"
+funcs="$funcs memchr"
+funcs="$funcs memcmp"
+funcs="$funcs memcpy"
+funcs="$funcs memmove"
+funcs="$funcs memset"
+funcs="$funcs random"
+funcs="$funcs rename"
+funcs="$funcs rindex"
+funcs="$funcs sigsetmask"
+funcs="$funcs strcasecmp"
+funcs="$funcs strchr"
+funcs="$funcs strdup"
+funcs="$funcs strncasecmp"
+funcs="$funcs strrchr"
+funcs="$funcs strstr"
+funcs="$funcs strtod"
+funcs="$funcs strtol"
+funcs="$funcs strtoul"
+funcs="$funcs tmpnam"
+funcs="$funcs vasprintf"
+funcs="$funcs vfprintf"
+funcs="$funcs vprintf"
+funcs="$funcs vsprintf"
+funcs="$funcs waitpid"
+
+# Also in the old function.def file: alloca, vfork, getopt.
+
+vars="sys_errlist sys_nerr sys_siglist"
+
+checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times"
+
+# These are neither executed nor required, but they help keep
+# autoheader happy without adding a bunch of text to acconfig.h.
+if test "x" = "y"; then
+ AC_CHECK_FUNCS(asprintf atexit basename bcmp bcopy bzero clock getcwd)
+ AC_CHECK_FUNCS(getpagesize index insque memchr memcmp memcpy memmove)
+ AC_CHECK_FUNCS(memset random rename rindex sigsetmask strcasecmp)
+ AC_CHECK_FUNCS(strchr strdup strncasecmp strrchr strstr strtod strtol)
+ AC_CHECK_FUNCS(strtoul tmpnam vasprintf vfprintf vprintf vsprintf waitpid)
+ AC_DEFINE(HAVE_SYS_ERRLIST)
+ AC_DEFINE(HAVE_SYS_NERR)
+ AC_DEFINE(HAVE_SYS_SIGLIST)
+ AC_CHECK_FUNCS(getrusage on_exit psignal strerror strsignal sysconf times)
fi
-# We need multilib support, but only if configuring for the target.
-if [ -n "${with_target_subdir}" ] ; then
- if [ "${srcdir}" = "." ] ; then
- if [ "${with_target_subdir}" != "." ] ; then
- . ${with_multisrctop}../../config-ml.in
+# For each of these functions, if the host does not provide the
+# function we want to put FN.o in LIBOBJS, and if the host does
+# provide the function, we want to define HAVE_FN in config.h. Also,
+# if the host does not provide alloca, we set ALLOCA to alloca.o
+
+setobjs=
+if test -n "${with_target_subdir}"; then
+
+ # We are being configured with a cross compiler. AC_REPLACE_FUNCS
+ # may not work correctly, because the compiler may not be able to
+ # link executables.
+
+ # If we are being configured for newlib, we know which functions
+ # newlib provide and which ones we will be expected to provide.
+
+ if test "x${with_newlib}" = "xyes"; then
+ ALLOCA="alloca.o"
+ LIBOBJS="basename.o insque.o random.o strdup.o vasprintf.o"
+
+ for f in $funcs; do
+ case "$f" in
+ basename | insque | random | strdup | vasprintf)
+ ;;
+ *)
+ n=HAVE_`echo $f | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
+ AC_DEFINE_UNQUOTED($n)
+ ;;
+ esac
+ done
+
+ # newlib doesnt provide any of the variables in $vars, so we
+ # dont have to check them here.
+
+ # Of the functions in $checkfuncs, VxWorks only has strerror.
+ AC_DEFINE(HAVE_STRERROR)
+
+ setobjs=yes
+
+ fi
+fi
+
+if test -z "${setobjs}"; then
+ case "${host}" in
+
+ *-*-vxworks*)
+ # Handle VxWorks configuration specially, since on VxWorks the
+ # libraries are actually on the target board, not in the file
+ # system.
+ LIBOBJS="basename.o getpagesize.o insque.o random.o strcasecmp.o"
+ LIBOBJS="$LIBOBJS strncasecmp.o strdup.o vfork.o waitpid.o vasprintf.o"
+ for f in $funcs; do
+ case "$f" in
+ basename | getpagesize | insque | random | strcasecmp)
+ ;;
+ strncasecmp | strdup | vfork | waitpid | vasprintf)
+ ;;
+ *)
+ n=HAVE_`echo $f | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
+ AC_DEFINE_UNQUOTED($n)
+ ;;
+ esac
+ done
+
+ # VxWorks doesn't provide any of the variables in $vars, so we
+ # don't have to check them here.
+
+ # Of the functions in $checkfuncs, VxWorks only has strerror.
+ AC_DEFINE(HAVE_STRERROR)
+
+ setobjs=yes
+ ;;
+
+ esac
+fi
+
+if test -z "${setobjs}"; then
+
+ case "${host}" in
+
+ *-*-cygwin32*)
+ # The cygwin32 library actually uses a couple of files from
+ # libiberty when it is built. If we are building a native
+ # cygwin32, and we run the tests, we will appear to have these
+ # files. However, when we go on to build winsup, we will wind up
+ # with a library which does not have the files, since they should
+ # have come from libiberty.
+
+ # We handle this by removing the functions the winsup library
+ # provides from our shell variables, so that they appear to be
+ # missing.
+
+ funcs="`echo $funcs | sed -e 's/random//'`"
+ LIBOBJS="$LIBOBJS random.o"
+ vars="`echo $vars | sed -e 's/sys_siglist//'`"
+ checkfuncs="`echo $checkfuncs | sed -e 's/strsignal//' -e 's/psignal//`"
+ ;;
+
+ *-*-mingw32*)
+ # Under mingw32, sys_nerr and sys_errlist exist, but they are
+ # macros, so the test below won't find them.
+ vars="`echo $vars | sed -e 's/sys_nerr//' -e 's/sys_errlist//'`"
+ AC_DEFINE(HAVE_SYS_NERR)
+ AC_DEFINE(HAVE_SYS_ERRLIST)
+ ;;
+
+ esac
+
+ # We haven't set the list of objects yet. Use the standard autoconf
+ # tests. This will only work if the compiler works.
+ AC_PROG_CC_WORKS
+ AC_REPLACE_FUNCS($funcs)
+ AC_FUNC_ALLOCA
+ AC_FUNC_VFORK
+ if test $ac_cv_func_vfork_works = no; then
+ LIBOBJS="$LIBOBJS vfork.o"
+ fi
+ for v in $vars; do
+ AC_MSG_CHECKING([for $v])
+ AC_CACHE_VAL(libiberty_cv_var_$v,
+ [AC_TRY_LINK([int *p;], [extern int $v; p = &$v;],
+ [eval "libiberty_cv_var_$v=yes"],
+ [eval "libiberty_cv_var_$v=no"])])
+ if eval "test \"`echo '$libiberty_cv_var_'$v`\" = yes"; then
+ AC_MSG_RESULT(yes)
+ n=HAVE_`echo $v | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
+ AC_DEFINE_UNQUOTED($n)
else
- . ${with_multisrctop}../config-ml.in
+ AC_MSG_RESULT(no)
fi
- else
- . ${srcdir}/../config-ml.in
- fi
+ done
+ AC_CHECK_FUNCS($checkfuncs)
+fi
+
+# Install a library built with a cross compiler in $(tooldir) rather
+# than $(libdir).
+if test -z "${with_target_subdir}"; then
+ INSTALL_DEST=libdir
+else
+ INSTALL_DEST=tooldir
fi
+AC_SUBST(INSTALL_DEST)
+
+# We need multilib support, but only if configuring for the target.
+AC_OUTPUT(Makefile,
+[test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h
+if test -n "$CONFIG_FILES"; then
+ if test -n "${with_target_subdir}"; then
+ # FIXME: We shouldn't need to set ac_file
+ ac_file=Makefile
+ . ${libiberty_topdir}/config-ml.in
+ fi
+fi],
+srcdir=${srcdir}
+host=${host}
+target=${target}
+with_target_subdir=${with_target_subdir}
+with_multisubdir=${with_multisubdir}
+ac_configure_args="--enable-multilib ${ac_configure_args}"
+CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
+libiberty_topdir=${libiberty_topdir}
+)
diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c
index 5794a5bb869..ccf7aef4a85 100644
--- a/libiberty/cplus-dem.c
+++ b/libiberty/cplus-dem.c
@@ -29,9 +29,14 @@ Boston, MA 02111-1307, USA. */
try not to break either. */
#include <ctype.h>
+#include <sys/types.h>
#include <string.h>
#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
#include <demangle.h>
#undef CURRENT_DEMANGLING_STYLE
#define CURRENT_DEMANGLING_STYLE work->options
@@ -96,12 +101,20 @@ struct work_stuff
{
int options;
char **typevec;
+ char **ktypevec;
+ char **btypevec;
+ int numk;
+ int numb;
+ int ksize;
+ int bsize;
int ntypes;
int typevec_size;
int constructor;
int destructor;
int static_type; /* A static member function */
int const_type; /* A const member function */
+ char **tmpl_argvec; /* Template function arguments. */
+ int ntmpl_args; /* The number of template function arguments. */
};
#define PRINT_ANSI_QUALIFIERS (work -> options & DMGL_ANSI)
@@ -190,7 +203,8 @@ static const struct optable
{"min", "<?", 0}, /* old */
{"mn", "<?", DMGL_ANSI}, /* pseudo-ansi */
{"nop", "", 0}, /* old (for operator=) */
- {"rm", "->*", DMGL_ANSI} /* ansi */
+ {"rm", "->*", DMGL_ANSI}, /* ansi */
+ {"sz", "sizeof ", DMGL_ANSI} /* pseudo-ansi */
};
@@ -206,6 +220,7 @@ typedef struct string /* Beware: these aren't required to be */
string_prepend(str, " ");}
#define APPEND_BLANK(str) {if (!STRING_EMPTY(str)) \
string_append(str, " ");}
+#define LEN_STRING(str) ( (STRING_EMPTY(str))?0:((str)->p - (str)->b))
#define ARM_VTABLE_STRING "__vtbl__" /* Lucid/ARM virtual table prefix */
#define ARM_VTABLE_STRLEN 8 /* strlen (ARM_VTABLE_STRING) */
@@ -215,14 +230,24 @@ typedef struct string /* Beware: these aren't required to be */
static char *
mop_up PARAMS ((struct work_stuff *, string *, int));
+static void
+squangle_mop_up PARAMS ((struct work_stuff *));
+
#if 0
static int
-demangle_method_args PARAMS ((struct work_stuff *work, const char **, string *));
+demangle_method_args PARAMS ((struct work_stuff *, const char **, string *));
#endif
+static char *
+internal_cplus_demangle PARAMS ((struct work_stuff *, const char *));
+
+static int
+demangle_template_template_parm PARAMS ((struct work_stuff *work,
+ const char **, string *));
+
static int
demangle_template PARAMS ((struct work_stuff *work, const char **, string *,
- string *));
+ string *, int));
static int
arm_pt PARAMS ((struct work_stuff *, const char *, int, const char **,
@@ -254,7 +279,7 @@ static int
gnu_special PARAMS ((struct work_stuff *, const char **, string *));
static int
-arm_special PARAMS ((struct work_stuff *, const char **, string *));
+arm_special PARAMS ((const char **, string *));
static void
string_need PARAMS ((string *, int));
@@ -294,6 +319,9 @@ get_count PARAMS ((const char **, int *));
static int
consume_count PARAMS ((const char **));
+static int
+consume_count_with_underscores PARAMS ((const char**));
+
static int
demangle_args PARAMS ((struct work_stuff *, const char **, string *));
@@ -311,11 +339,27 @@ static void
remember_type PARAMS ((struct work_stuff *, const char *, int));
static void
+remember_Btype PARAMS ((struct work_stuff *, const char *, int, int));
+
+static int
+register_Btype PARAMS ((struct work_stuff *));
+
+static void
+remember_Ktype PARAMS ((struct work_stuff *, const char *, int));
+
+static void
forget_types PARAMS ((struct work_stuff *));
static void
+forget_B_and_K_types PARAMS ((struct work_stuff *));
+
+static void
string_prepends PARAMS ((string *, string *));
+static int
+demangle_template_value_parm PARAMS ((struct work_stuff*,
+ const char**, string*));
+
/* Translate count to integer, consuming tokens in the process.
Conversion terminates on the first non-digit character.
Trying to consume something that isn't a count results in
@@ -336,13 +380,49 @@ consume_count (type)
return (count);
}
+
+/* Like consume_count, but for counts that are preceded and followed
+ by '_' if they are greater than 10. Also, -1 is returned for
+ failure, since 0 can be a valid value. */
+
+static int
+consume_count_with_underscores (mangled)
+ const char **mangled;
+{
+ int idx;
+
+ if (**mangled == '_')
+ {
+ (*mangled)++;
+ if (!isdigit (**mangled))
+ return -1;
+
+ idx = consume_count (mangled);
+ if (**mangled != '_')
+ /* The trailing underscore was missing. */
+ return -1;
+
+ (*mangled)++;
+ }
+ else
+ {
+ if (**mangled < '0' || **mangled > '9')
+ return -1;
+
+ idx = **mangled - '0';
+ (*mangled)++;
+ }
+
+ return idx;
+}
+
int
cplus_demangle_opname (opname, result, options)
const char *opname;
char *result;
int options;
{
- int len, i, len1, ret;
+ int len, len1, ret;
string type;
struct work_stuff work[1];
const char *tem;
@@ -350,6 +430,7 @@ cplus_demangle_opname (opname, result, options)
len = strlen(opname);
result[0] = '\0';
ret = 0;
+ memset ((char *) work, 0, sizeof (work));
work->options = options;
if (opname[0] == '_' && opname[1] == '_'
@@ -373,6 +454,7 @@ cplus_demangle_opname (opname, result, options)
if (opname[4] == '\0')
{
/* Operator. */
+ size_t i;
for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++)
{
if (strlen (optable[i].in) == 2
@@ -390,6 +472,7 @@ cplus_demangle_opname (opname, result, options)
if (opname[2] == 'a' && opname[5] == '\0')
{
/* Assignment. */
+ size_t i;
for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++)
{
if (strlen (optable[i].in) == 3
@@ -413,6 +496,7 @@ cplus_demangle_opname (opname, result, options)
if (len >= 10 /* op$assign_ */
&& memcmp (opname + 3, "assign_", 7) == 0)
{
+ size_t i;
for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++)
{
len1 = len - 10;
@@ -429,6 +513,7 @@ cplus_demangle_opname (opname, result, options)
}
else
{
+ size_t i;
for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++)
{
len1 = len - 3;
@@ -456,6 +541,7 @@ cplus_demangle_opname (opname, result, options)
ret = 1;
}
}
+ squangle_mop_up (work);
return ret;
}
@@ -470,7 +556,7 @@ cplus_mangle_opname (opname, options)
const char *opname;
int options;
{
- int i;
+ size_t i;
int len;
len = strlen (opname);
@@ -517,18 +603,44 @@ cplus_demangle (mangled, options)
const char *mangled;
int options;
{
+ char *ret;
+ struct work_stuff work[1];
+ memset ((char *) work, 0, sizeof (work));
+ work -> options = options;
+ if ((work -> options & DMGL_STYLE_MASK) == 0)
+ work -> options |= (int) current_demangling_style & DMGL_STYLE_MASK;
+
+ ret = internal_cplus_demangle (work, mangled);
+ squangle_mop_up (work);
+ return (ret);
+}
+
+
+/* This function performs most of what cplus_demangle use to do, but
+ to be able to demangle a name with a B, K or n code, we need to
+ have a longer term memory of what types have been seen. The original
+ now intializes and cleans up the squangle code info, while internal
+ calls go directly to this routine to avoid resetting that info. */
+
+static char *
+internal_cplus_demangle (work, mangled)
+ struct work_stuff *work;
+ const char *mangled;
+{
+
string decl;
int success = 0;
- struct work_stuff work[1];
char *demangled = NULL;
+ int s1,s2,s3,s4;
+ s1 = work->constructor;
+ s2 = work->destructor;
+ s3 = work->static_type;
+ s4 = work->const_type;
+ work->constructor = work->destructor = 0;
+ work->static_type = work->const_type = 0;
if ((mangled != NULL) && (*mangled != '\0'))
{
- memset ((char *) work, 0, sizeof (work));
- work -> options = options;
- if ((work->options & DMGL_STYLE_MASK) == 0)
- work->options |= (int)current_demangling_style & DMGL_STYLE_MASK;
-
string_init (&decl);
/* First check to see if gnu style demangling is active and if the
@@ -552,19 +664,43 @@ cplus_demangle (mangled, options)
}
if (work->constructor == 2)
{
- string_prepend(&decl, "global constructors keyed to ");
+ string_prepend (&decl, "global constructors keyed to ");
work->constructor = 0;
}
else if (work->destructor == 2)
{
- string_prepend(&decl, "global destructors keyed to ");
+ string_prepend (&decl, "global destructors keyed to ");
work->destructor = 0;
}
demangled = mop_up (work, &decl, success);
}
+ work->constructor = s1;
+ work->destructor = s2;
+ work->static_type = s3;
+ work->const_type = s4;
return (demangled);
}
+
+/* Clear out and squangling related storage */
+static void
+squangle_mop_up (work)
+ struct work_stuff *work;
+{
+ /* clean up the B and K type mangling types. */
+ forget_B_and_K_types (work);
+ if (work -> btypevec != NULL)
+ {
+ free ((char *) work -> btypevec);
+ }
+ if (work -> ktypevec != NULL)
+ {
+ free ((char *) work -> ktypevec);
+ }
+}
+
+/* Clear out any mangled storage */
+
static char *
mop_up (work, declp, success)
struct work_stuff *work;
@@ -579,8 +715,20 @@ mop_up (work, declp, success)
if (work -> typevec != NULL)
{
free ((char *) work -> typevec);
+ work -> typevec = NULL;
}
-
+ if (work->tmpl_argvec)
+ {
+ int i;
+
+ for (i = 0; i < work->ntmpl_args; i++)
+ if (work->tmpl_argvec[i])
+ free ((char*) work->tmpl_argvec[i]);
+
+ free ((char*) work->tmpl_argvec);
+ work->tmpl_argvec = NULL;
+ }
+
/* If demangling was successful, ensure that the demangled string is null
terminated and return it. Otherwise, free the demangling decl. */
@@ -635,6 +783,7 @@ demangle_signature (work, mangled, declp)
int success = 1;
int func_done = 0;
int expect_func = 0;
+ int expect_return_type = 0;
const char *oldmangled = NULL;
string trawname;
string tname;
@@ -656,6 +805,16 @@ demangle_signature (work, mangled, declp)
}
oldmangled = NULL;
break;
+
+ case 'K':
+ oldmangled = *mangled;
+ success = demangle_qualified (work, mangled, declp, 1, 0);
+ if (AUTO_DEMANGLING || GNU_DEMANGLING)
+ {
+ expect_func = 1;
+ }
+ oldmangled = NULL;
+ break;
case 'S':
/* Static member function */
@@ -726,12 +885,13 @@ demangle_signature (work, mangled, declp)
{
oldmangled = *mangled;
}
- success = demangle_template (work, mangled, &tname, &trawname);
+ success = demangle_template (work, mangled, &tname, &trawname, 1);
if (success)
{
remember_type (work, oldmangled, *mangled - oldmangled);
}
- string_append(&tname, (work -> options & DMGL_JAVA) ? "." : "::");
+ string_append (&tname, "::");
+
string_prepends(declp, &tname);
if (work -> destructor & 1)
{
@@ -751,14 +911,43 @@ demangle_signature (work, mangled, declp)
break;
case '_':
- /* At the outermost level, we cannot have a return type specified,
- so if we run into another '_' at this point we are dealing with
- a mangled name that is either bogus, or has been mangled by
- some algorithm we don't know how to deal with. So just
- reject the entire demangling. */
- success = 0;
+ if (GNU_DEMANGLING && expect_return_type)
+ {
+ /* Read the return type. */
+ string return_type;
+ string_init (&return_type);
+
+ (*mangled)++;
+ success = do_type (work, mangled, &return_type);
+ APPEND_BLANK (&return_type);
+
+ string_prepends (declp, &return_type);
+ string_delete (&return_type);
+ break;
+ }
+ else
+ /* At the outermost level, we cannot have a return type specified,
+ so if we run into another '_' at this point we are dealing with
+ a mangled name that is either bogus, or has been mangled by
+ some algorithm we don't know how to deal with. So just
+ reject the entire demangling. */
+ success = 0;
break;
+ case 'H':
+ if (GNU_DEMANGLING)
+ {
+ /* A G++ template function. Read the template arguments. */
+ success = demangle_template (work, mangled, declp, 0, 0);
+ if (!(work->constructor & 1))
+ expect_return_type = 1;
+ (*mangled)++;
+ break;
+ }
+ else
+ /* fall through */
+ {;}
+
default:
if (AUTO_DEMANGLING || GNU_DEMANGLING)
{
@@ -785,6 +974,10 @@ demangle_signature (work, mangled, declp)
{
func_done = 1;
success = demangle_args (work, mangled, declp);
+ /* Since template include the mangling of their return types,
+ we must set expect_func to 0 so that we don't try do
+ demangle more arguments the next time we get here. */
+ expect_func = 0;
}
}
}
@@ -838,50 +1031,411 @@ demangle_method_args (work, mangled, declp)
#endif
static int
-demangle_template (work, mangled, tname, trawname)
+demangle_template_template_parm (work, mangled, tname)
+ struct work_stuff *work;
+ const char **mangled;
+ string *tname;
+{
+ int i;
+ int r;
+ int need_comma = 0;
+ int success = 1;
+ string temp;
+
+ string_append (tname, "template <");
+ /* get size of template parameter list */
+ if (get_count (mangled, &r))
+ {
+ for (i = 0; i < r; i++)
+ {
+ if (need_comma)
+ {
+ string_append (tname, ", ");
+ }
+
+ /* Z for type parameters */
+ if (**mangled == 'Z')
+ {
+ (*mangled)++;
+ string_append (tname, "class");
+ }
+ /* z for template parameters */
+ else if (**mangled == 'z')
+ {
+ (*mangled)++;
+ success =
+ demangle_template_template_parm (work, mangled, tname);
+ if (!success)
+ {
+ break;
+ }
+ }
+ else
+ {
+ /* temp is initialized in do_type */
+ success = do_type (work, mangled, &temp);
+ if (success)
+ {
+ string_appends (tname, &temp);
+ }
+ string_delete(&temp);
+ if (!success)
+ {
+ break;
+ }
+ }
+ need_comma = 1;
+ }
+
+ }
+ if (tname->p[-1] == '>')
+ string_append (tname, " ");
+ string_append (tname, "> class");
+ return (success);
+}
+
+static int
+demangle_integral_value (work, mangled, s)
+ struct work_stuff *work;
+ const char** mangled;
+ string* s;
+{
+ int success;
+
+ if (**mangled == 'E')
+ {
+ int need_operator = 0;
+
+ success = 1;
+ string_appendn (s, "(", 1);
+ (*mangled)++;
+ while (success && **mangled != 'W' && **mangled != '\0')
+ {
+ if (need_operator)
+ {
+ size_t i;
+ size_t len;
+
+ success = 0;
+
+ len = strlen (*mangled);
+
+ for (i = 0;
+ i < sizeof (optable) / sizeof (optable [0]);
+ ++i)
+ {
+ size_t l = strlen (optable[i].in);
+
+ if (l <= len
+ && memcmp (optable[i].in, *mangled, l) == 0)
+ {
+ string_appendn (s, " ", 1);
+ string_append (s, optable[i].out);
+ string_appendn (s, " ", 1);
+ success = 1;
+ (*mangled) += l;
+ break;
+ }
+ }
+
+ if (!success)
+ break;
+ }
+ else
+ need_operator = 1;
+
+ success = demangle_template_value_parm (work, mangled, s);
+ }
+
+ if (**mangled != 'W')
+ success = 0;
+ else
+ {
+ string_appendn (s, ")", 1);
+ (*mangled)++;
+ }
+ }
+ else if (**mangled == 'Q' || **mangled == 'K')
+ success = demangle_qualified (work, mangled, s, 0, 1);
+ else
+ {
+ success = 0;
+
+ if (**mangled == 'm')
+ {
+ string_appendn (s, "-", 1);
+ (*mangled)++;
+ }
+ while (isdigit (**mangled))
+ {
+ string_appendn (s, *mangled, 1);
+ (*mangled)++;
+ success = 1;
+ }
+ }
+
+ return success;
+}
+
+static int
+demangle_template_value_parm (work, mangled, s)
+ struct work_stuff *work;
+ const char **mangled;
+ string* s;
+{
+ const char *old_p = *mangled;
+ int is_pointer = 0;
+ int is_real = 0;
+ int is_integral = 0;
+ int is_char = 0;
+ int is_bool = 0;
+ int done = 0;
+ int success = 1;
+
+ while (*old_p && !done)
+ {
+ switch (*old_p)
+ {
+ case 'P':
+ case 'p':
+ case 'R':
+ done = is_pointer = 1;
+ break;
+ case 'C': /* const */
+ case 'S': /* explicitly signed [char] */
+ case 'U': /* unsigned */
+ case 'V': /* volatile */
+ case 'F': /* function */
+ case 'M': /* member function */
+ case 'O': /* ??? */
+ case 'J': /* complex */
+ old_p++;
+ continue;
+ case 'E': /* expression */
+ case 'Q': /* qualified name */
+ case 'K': /* qualified name */
+ done = is_integral = 1;
+ break;
+ case 'B': /* squangled name */
+ done = is_integral = 1;
+ break;
+ case 'T': /* remembered type */
+ abort ();
+ break;
+ case 'v': /* void */
+ abort ();
+ break;
+ case 'x': /* long long */
+ case 'l': /* long */
+ case 'i': /* int */
+ case 's': /* short */
+ case 'w': /* wchar_t */
+ done = is_integral = 1;
+ break;
+ case 'b': /* bool */
+ done = is_bool = 1;
+ break;
+ case 'c': /* char */
+ done = is_char = 1;
+ break;
+ case 'r': /* long double */
+ case 'd': /* double */
+ case 'f': /* float */
+ done = is_real = 1;
+ break;
+ default:
+ /* it's probably user defined type, let's assume
+ it's integral, it seems hard to figure out
+ what it really is */
+ done = is_integral = 1;
+ }
+ }
+ if (**mangled == 'Y')
+ {
+ /* The next argument is a template parameter. */
+ int idx;
+
+ (*mangled)++;
+ idx = consume_count_with_underscores (mangled);
+ if (idx == -1
+ || (work->tmpl_argvec && idx >= work->ntmpl_args)
+ || consume_count_with_underscores (mangled) == -1)
+ return -1;
+ if (work->tmpl_argvec)
+ string_append (s, work->tmpl_argvec[idx]);
+ else
+ {
+ char buf[10];
+ sprintf(buf, "T%d", idx);
+ string_append (s, buf);
+ }
+ }
+ else if (is_integral)
+ success = demangle_integral_value (work, mangled, s);
+ else if (is_char)
+ {
+ char tmp[2];
+ int val;
+ if (**mangled == 'm')
+ {
+ string_appendn (s, "-", 1);
+ (*mangled)++;
+ }
+ string_appendn (s, "'", 1);
+ val = consume_count(mangled);
+ if (val == 0)
+ return -1;
+ tmp[0] = (char)val;
+ tmp[1] = '\0';
+ string_appendn (s, &tmp[0], 1);
+ string_appendn (s, "'", 1);
+ }
+ else if (is_bool)
+ {
+ int val = consume_count (mangled);
+ if (val == 0)
+ string_appendn (s, "false", 5);
+ else if (val == 1)
+ string_appendn (s, "true", 4);
+ else
+ success = 0;
+ }
+ else if (is_real)
+ {
+ if (**mangled == 'm')
+ {
+ string_appendn (s, "-", 1);
+ (*mangled)++;
+ }
+ while (isdigit (**mangled))
+ {
+ string_appendn (s, *mangled, 1);
+ (*mangled)++;
+ }
+ if (**mangled == '.') /* fraction */
+ {
+ string_appendn (s, ".", 1);
+ (*mangled)++;
+ while (isdigit (**mangled))
+ {
+ string_appendn (s, *mangled, 1);
+ (*mangled)++;
+ }
+ }
+ if (**mangled == 'e') /* exponent */
+ {
+ string_appendn (s, "e", 1);
+ (*mangled)++;
+ while (isdigit (**mangled))
+ {
+ string_appendn (s, *mangled, 1);
+ (*mangled)++;
+ }
+ }
+ }
+ else if (is_pointer)
+ {
+ int symbol_len = consume_count (mangled);
+ if (symbol_len == 0)
+ return -1;
+ if (symbol_len == 0)
+ string_appendn (s, "0", 1);
+ else
+ {
+ char *p = xmalloc (symbol_len + 1), *q;
+ strncpy (p, *mangled, symbol_len);
+ p [symbol_len] = '\0';
+ q = internal_cplus_demangle (work, p);
+ string_appendn (s, "&", 1);
+ if (q)
+ {
+ string_append (s, q);
+ free (q);
+ }
+ else
+ string_append (s, p);
+ free (p);
+ }
+ *mangled += symbol_len;
+ }
+
+ return success;
+}
+
+static int
+demangle_template (work, mangled, tname, trawname, is_type)
struct work_stuff *work;
const char **mangled;
string *tname;
string *trawname;
+ int is_type;
{
int i;
- int is_pointer;
- int is_real;
- int is_integral;
- int is_char;
- int is_bool;
int r;
int need_comma = 0;
int success = 0;
- int done;
- const char *old_p;
const char *start;
- int symbol_len;
- int is_java_array;
string temp;
(*mangled)++;
- start = *mangled;
- /* get template name */
- if ((r = consume_count (mangled)) == 0 || strlen (*mangled) < r)
+ if (is_type)
{
- return (0);
- }
- if (trawname)
- string_appendn (trawname, *mangled, r);
- is_java_array = (work -> options & DMGL_JAVA)
- && strncmp (*mangled, "JArray1Z", 8) == 0;
- if (! is_java_array)
- {
- string_appendn (tname, *mangled, r);
- string_append (tname, "<");
+ start = *mangled;
+ /* get template name */
+ if (**mangled == 'z')
+ {
+ int idx;
+ (*mangled)++;
+ (*mangled)++;
+
+ idx = consume_count_with_underscores (mangled);
+ if (idx == -1
+ || (work->tmpl_argvec && idx >= work->ntmpl_args)
+ || consume_count_with_underscores (mangled) == -1)
+ {
+ return (0);
+ }
+ if (work->tmpl_argvec)
+ {
+ string_append (tname, work->tmpl_argvec[idx]);
+ if (trawname)
+ string_append (trawname, work->tmpl_argvec[idx]);
+ }
+ else
+ {
+ char buf[10];
+ sprintf(buf, "T%d", idx);
+ string_append (tname, buf);
+ if (trawname)
+ string_append (trawname, work->tmpl_argvec[idx]);
+ }
+ }
+ else
+ {
+ if ((r = consume_count (mangled)) == 0 || strlen (*mangled) < r)
+ {
+ return (0);
+ }
+ if (trawname)
+ string_appendn (trawname, *mangled, r);
+ string_appendn (tname, *mangled, r);
+ *mangled += r;
+ }
}
- *mangled += r;
+ string_append (tname, "<");
/* get size of template parameter list */
if (!get_count (mangled, &r))
{
return (0);
}
+ if (!is_type)
+ {
+ /* Create an array for saving the template argument values. */
+ work->tmpl_argvec = (char**) xmalloc (r * sizeof (char *));
+ work->ntmpl_args = r;
+ for (i = 0; i < r; i++)
+ work->tmpl_argvec[i] = 0;
+ }
for (i = 0; i < r; i++)
{
if (need_comma)
@@ -897,6 +1451,15 @@ demangle_template (work, mangled, tname, trawname)
if (success)
{
string_appends (tname, &temp);
+
+ if (!is_type)
+ {
+ /* Save the template argument. */
+ int len = temp.p - temp.b;
+ work->tmpl_argvec[i] = xmalloc (len + 1);
+ memcpy (work->tmpl_argvec[i], temp.b, len);
+ work->tmpl_argvec[i][len] = '\0';
+ }
}
string_delete(&temp);
if (!success)
@@ -904,22 +1467,46 @@ demangle_template (work, mangled, tname, trawname)
break;
}
}
+ /* z for template parameters */
+ else if (**mangled == 'z')
+ {
+ int r2;
+ (*mangled)++;
+ success = demangle_template_template_parm (work, mangled, tname);
+
+ if (success
+ && (r2 = consume_count (mangled)) > 0 && strlen (*mangled) >= r2)
+ {
+ string_append (tname, " ");
+ string_appendn (tname, *mangled, r2);
+ if (!is_type)
+ {
+ /* Save the template argument. */
+ int len = r2;
+ work->tmpl_argvec[i] = xmalloc (len + 1);
+ memcpy (work->tmpl_argvec[i], *mangled, len);
+ work->tmpl_argvec[i][len] = '\0';
+ }
+ *mangled += r2;
+ }
+ if (!success)
+ {
+ break;
+ }
+ }
else
{
+ string param;
+ string* s;
+
/* otherwise, value parameter */
- old_p = *mangled;
- is_pointer = 0;
- is_real = 0;
- is_integral = 0;
- is_char = 0;
- is_bool = 0;
- done = 0;
+
/* temp is initialized in do_type */
success = do_type (work, mangled, &temp);
/*
if (success)
{
- string_appends (tname, &temp);
+ string_appends (s, &temp);
}
*/
string_delete(&temp);
@@ -928,174 +1515,40 @@ demangle_template (work, mangled, tname, trawname)
break;
}
/*
- string_append (tname, "=");
+ string_append (s, "=");
*/
- while (*old_p && !done)
- {
- switch (*old_p)
- {
- case 'P':
- case 'p':
- case 'R':
- done = is_pointer = 1;
- break;
- case 'C': /* const */
- case 'S': /* explicitly signed [char] */
- case 'U': /* unsigned */
- case 'V': /* volatile */
- case 'F': /* function */
- case 'M': /* member function */
- case 'O': /* ??? */
- case 'J': /* complex */
- old_p++;
- continue;
- case 'Q': /* qualified name */
- done = is_integral = 1;
- break;
- case 'T': /* remembered type */
- abort ();
- break;
- case 'v': /* void */
- abort ();
- break;
- case 'x': /* long long */
- case 'l': /* long */
- case 'i': /* int */
- case 's': /* short */
- case 'w': /* wchar_t */
- done = is_integral = 1;
- break;
- case 'b': /* bool */
- done = is_bool = 1;
- break;
- case 'c': /* char */
- done = is_char = 1;
- break;
- case 'r': /* long double */
- case 'd': /* double */
- case 'f': /* float */
- done = is_real = 1;
- break;
- default:
- /* it's probably user defined type, let's assume
- it's integral, it seems hard to figure out
- what it really is */
- done = is_integral = 1;
- }
- }
- if (is_integral)
- {
- if (**mangled == 'm')
- {
- string_appendn (tname, "-", 1);
- (*mangled)++;
- }
- while (isdigit (**mangled))
- {
- string_appendn (tname, *mangled, 1);
- (*mangled)++;
- }
- }
- else if (is_char)
+
+ if (!is_type)
{
- char tmp[2];
- int val;
- if (**mangled == 'm')
- {
- string_appendn (tname, "-", 1);
- (*mangled)++;
- }
- string_appendn (tname, "'", 1);
- val = consume_count(mangled);
- if (val == 0)
- {
- success = 0;
- break;
- }
- tmp[0] = (char)val;
- tmp[1] = '\0';
- string_appendn (tname, &tmp[0], 1);
- string_appendn (tname, "'", 1);
- }
- else if (is_bool)
- {
- int val = consume_count (mangled);
- if (val == 0)
- string_appendn (tname, "false", 5);
- else if (val == 1)
- string_appendn (tname, "true", 4);
- else
- success = 0;
+ s = &param;
+ string_init (s);
}
- else if (is_real)
+ else
+ s = tname;
+
+ success = demangle_template_value_parm (work, mangled, s);
+
+ if (!success)
{
- if (**mangled == 'm')
- {
- string_appendn (tname, "-", 1);
- (*mangled)++;
- }
- while (isdigit (**mangled))
- {
- string_appendn (tname, *mangled, 1);
- (*mangled)++;
- }
- if (**mangled == '.') /* fraction */
- {
- string_appendn (tname, ".", 1);
- (*mangled)++;
- while (isdigit (**mangled))
- {
- string_appendn (tname, *mangled, 1);
- (*mangled)++;
- }
- }
- if (**mangled == 'e') /* exponent */
- {
- string_appendn (tname, "e", 1);
- (*mangled)++;
- while (isdigit (**mangled))
- {
- string_appendn (tname, *mangled, 1);
- (*mangled)++;
- }
- }
+ if (!is_type)
+ string_delete (s);
+ success = 0;
+ break;
}
- else if (is_pointer)
+
+ if (!is_type)
{
- symbol_len = consume_count (mangled);
- if (symbol_len == 0)
- {
- success = 0;
- break;
- }
- if (symbol_len == 0)
- string_appendn (tname, "0", 1);
- else
- {
- char *p = xmalloc (symbol_len + 1), *q;
- strncpy (p, *mangled, symbol_len);
- p [symbol_len] = '\0';
- q = cplus_demangle (p, work->options);
- string_appendn (tname, "&", 1);
- if (q)
- {
- string_append (tname, q);
- free (q);
- }
- else
- string_append (tname, p);
- free (p);
- }
- *mangled += symbol_len;
+ int len = s->p - s->b;
+ work->tmpl_argvec[i] = xmalloc (len + 1);
+ memcpy (work->tmpl_argvec[i], s->b, len);
+ work->tmpl_argvec[i][len] = '\0';
+
+ string_appends (tname, s);
+ string_delete (s);
}
}
need_comma = 1;
}
- if (is_java_array)
- {
- string_append (tname, "[]");
- }
- else
{
if (tname->p[-1] == '>')
string_append (tname, " ");
@@ -1237,9 +1690,11 @@ demangle_class (work, mangled, declp)
string *declp;
{
int success = 0;
+ int btype;
string class_name;
string_init (&class_name);
+ btype = register_Btype (work);
if (demangle_class_name (work, mangled, &class_name))
{
if ((work->constructor & 1) || (work->destructor & 1))
@@ -1255,7 +1710,9 @@ demangle_class (work, mangled, declp)
work -> constructor -= 1;
}
}
- string_prepend (declp, (work -> options & DMGL_JAVA) ? "." : "::");
+ remember_Ktype (work, class_name.b, LEN_STRING(&class_name));
+ remember_Btype (work, class_name.b, LEN_STRING(&class_name), btype);
+ string_prepend (declp, "::");
string_prepends (declp, &class_name);
success = 1;
}
@@ -1377,7 +1834,8 @@ demangle_prefix (work, mangled, declp)
}
}
else if ((scan == *mangled)
- && (isdigit (scan[2]) || (scan[2] == 'Q') || (scan[2] == 't')))
+ && (isdigit (scan[2]) || (scan[2] == 'Q') || (scan[2] == 't')
+ || (scan[2] == 'K') || (scan[2] == 'H')))
{
/* The ARM says nothing about the mangling of local variables.
But cfront mangles local variables by prepending __<nesting_level>
@@ -1394,7 +1852,8 @@ demangle_prefix (work, mangled, declp)
{
/* A GNU style constructor starts with __[0-9Qt]. But cfront uses
names like __Q2_3foo3bar for nested type names. So don't accept
- this style of constructor for cfront demangling. */
+ this style of constructor for cfront demangling. A GNU
+ style member-template constructor starts with 'H'. */
if (!(LUCID_DEMANGLING || ARM_DEMANGLING))
work -> constructor += 1;
*mangled = scan + 2;
@@ -1406,7 +1865,7 @@ demangle_prefix (work, mangled, declp)
then find the next "__" that separates the prefix from the signature.
*/
if (!(ARM_DEMANGLING || LUCID_DEMANGLING)
- || (arm_special (work, mangled, declp) == 0))
+ || (arm_special (mangled, declp) == 0))
{
while (*scan == '_')
{
@@ -1523,15 +1982,25 @@ gnu_special (work, mangled, declp)
switch (**mangled)
{
case 'Q':
+ case 'K':
success = demangle_qualified (work, mangled, declp, 0, 1);
break;
case 't':
- success = demangle_template (work, mangled, declp, 0);
+ success = demangle_template (work, mangled, declp, 0, 1);
break;
default:
if (isdigit(*mangled[0]))
{
n = consume_count(mangled);
+ /* We may be seeing a too-large size, or else a
+ ".<digits>" indicating a static local symbol. In
+ any case, declare victory and move on; *don't* try
+ to use n to allocate. */
+ if (n > strlen (*mangled))
+ {
+ success = 1;
+ break;
+ }
}
else
{
@@ -1545,8 +2014,7 @@ gnu_special (work, mangled, declp)
{
if (p != NULL)
{
- string_append (declp,
- (work -> options & DMGL_JAVA) ? "." : "::");
+ string_append (declp, "::");
(*mangled)++;
}
}
@@ -1568,10 +2036,11 @@ gnu_special (work, mangled, declp)
switch (**mangled)
{
case 'Q':
+ case 'K':
success = demangle_qualified (work, mangled, declp, 0, 1);
break;
case 't':
- success = demangle_template (work, mangled, declp, 0);
+ success = demangle_template (work, mangled, declp, 0, 1);
break;
default:
n = consume_count (mangled);
@@ -1583,7 +2052,7 @@ gnu_special (work, mangled, declp)
/* Consumed everything up to the cplus_marker, append the
variable name. */
(*mangled)++;
- string_append (declp, (work -> options & DMGL_JAVA) ? "." : "::");
+ string_append (declp, "::");
n = strlen (*mangled);
string_appendn (declp, *mangled, n);
(*mangled) += n;
@@ -1596,7 +2065,7 @@ gnu_special (work, mangled, declp)
else if (strncmp (*mangled, "__thunk_", 8) == 0)
{
int delta = ((*mangled) += 8, consume_count (mangled));
- char *method = cplus_demangle (++*mangled, work->options);
+ char *method = internal_cplus_demangle (work, ++*mangled);
if (method)
{
char buf[50];
@@ -1620,10 +2089,11 @@ gnu_special (work, mangled, declp)
switch (**mangled)
{
case 'Q':
+ case 'K':
success = demangle_qualified (work, mangled, declp, 0, 1);
break;
case 't':
- success = demangle_template (work, mangled, declp, 0);
+ success = demangle_template (work, mangled, declp, 0, 1);
break;
default:
success = demangle_fund_type (work, mangled, declp);
@@ -1650,8 +2120,8 @@ LOCAL FUNCTION
SYNOPSIS
static int
- arm_special (struct work_stuff *work, const char **mangled,
- string *declp);
+ arm_special (const char **mangled,
+ string *declp);
DESCRIPTION
@@ -1665,8 +2135,7 @@ DESCRIPTION
*/
static int
-arm_special (work, mangled, declp)
- struct work_stuff *work;
+arm_special (mangled, declp)
const char **mangled;
string *declp;
{
@@ -1755,7 +2224,7 @@ demangle_qualified (work, mangled, result, isfuncname, append)
int isfuncname;
int append;
{
- int qualifiers;
+ int qualifiers = 0;
int namelength;
int success = 1;
const char *p;
@@ -1763,7 +2232,20 @@ demangle_qualified (work, mangled, result, isfuncname, append)
string temp;
string_init (&temp);
- switch ((*mangled)[1])
+
+ if ((*mangled)[0] == 'K')
+ {
+ /* Squangling qualified name reuse */
+ int idx;
+ (*mangled)++;
+ idx = consume_count_with_underscores (mangled);
+ if (idx == -1 || idx > work -> numk)
+ success = 0;
+ else
+ string_append (&temp, work -> ktypevec[idx]);
+ }
+ else
+ switch ((*mangled)[1])
{
case '_':
/* GNU mangled name with more than 9 classes. The count is preceded
@@ -1821,11 +2303,30 @@ demangle_qualified (work, mangled, result, isfuncname, append)
while (qualifiers-- > 0)
{
+ int remember_K = 1;
if (*mangled[0] == '_')
*mangled = *mangled + 1;
if (*mangled[0] == 't')
{
- success = demangle_template(work, mangled, &temp, 0);
+ success = demangle_template(work, mangled, &temp, 0, 1);
+ if (!success) break;
+ }
+ else if (*mangled[0] == 'X')
+ {
+ success = do_type (work, mangled, &temp);
+ if (!success) break;
+ }
+ else if (*mangled[0] == 'K')
+ {
+ int idx;
+ (*mangled)++;
+ idx = consume_count_with_underscores (mangled);
+ if (idx == -1 || idx > work->numk)
+ success = 0;
+ else
+ string_append (&temp, work->ktypevec[idx]);
+ remember_K = 0;
+
if (!success) break;
}
else
@@ -1840,9 +2341,15 @@ demangle_qualified (work, mangled, result, isfuncname, append)
string_appendn (&temp, *mangled, namelength);
*mangled += namelength;
}
+
+ if (remember_K)
+ {
+ remember_Ktype (work, temp.b, LEN_STRING (&temp));
+ }
+
if (qualifiers > 0)
{
- string_append (&temp, (work -> options & DMGL_JAVA) ? "." : "::");
+ string_append (&temp, "::");
}
}
@@ -1853,7 +2360,7 @@ demangle_qualified (work, mangled, result, isfuncname, append)
if (isfuncname && (work->constructor & 1 || work->destructor & 1))
{
- string_append (&temp, (work -> options & DMGL_JAVA) ? "." : "::");
+ string_append (&temp, "::");
if (work -> destructor & 1)
{
string_append (&temp, "~");
@@ -1872,7 +2379,7 @@ demangle_qualified (work, mangled, result, isfuncname, append)
{
if (!STRING_EMPTY (result))
{
- string_append (&temp, (work -> options & DMGL_JAVA) ? "." : "::");
+ string_append (&temp, "::");
}
string_prepends (result, &temp);
}
@@ -1949,7 +2456,9 @@ do_type (work, mangled, result)
const char *remembered_type;
int constp;
int volatilep;
+ string btype;
+ string_init (&btype);
string_init (&decl);
string_init (result);
@@ -1965,7 +2474,6 @@ do_type (work, mangled, result)
case 'P':
case 'p':
(*mangled)++;
- if (! (work -> options & DMGL_JAVA))
string_prepend (&decl, "*");
break;
@@ -2048,7 +2556,7 @@ do_type (work, mangled, result)
}
string_append (&decl, ")");
- string_prepend (&decl, (work -> options & DMGL_JAVA) ? "." : "::");
+ string_prepend (&decl, "::");
if (isdigit (**mangled))
{
n = consume_count (mangled);
@@ -2064,7 +2572,7 @@ do_type (work, mangled, result)
{
string temp;
string_init (&temp);
- success = demangle_template (work, mangled, &temp, NULL);
+ success = demangle_template (work, mangled, &temp, NULL, 1);
if (success)
{
string_prependn (&decl, temp.b, temp.p - temp.b);
@@ -2149,9 +2657,56 @@ do_type (work, mangled, result)
{
/* A qualified name, such as "Outer::Inner". */
case 'Q':
- success = demangle_qualified (work, mangled, result, 0, 1);
+ case 'K':
+ {
+ int btype = register_Btype (work);
+ success = demangle_qualified (work, mangled, result, 0, 1);
+ remember_Btype (work, result->b, LEN_STRING (result), btype);
+
+ break;
+ }
+
+ /* A back reference to a previously seen squangled type */
+ case 'B':
+ (*mangled)++;
+ if (!get_count (mangled, &n) || n >= work -> numb)
+ success = 0;
+ else
+ {
+ string_append (result, work->btypevec[n]);
+ }
break;
+ case 'X':
+ case 'Y':
+ /* A template parm. We substitute the corresponding argument. */
+ {
+ int idx;
+
+ (*mangled)++;
+ idx = consume_count_with_underscores (mangled);
+
+ if (idx == -1
+ || (work->tmpl_argvec && idx >= work->ntmpl_args)
+ || consume_count_with_underscores (mangled) == -1)
+ {
+ success = 0;
+ break;
+ }
+
+ if (work->tmpl_argvec)
+ string_append (result, work->tmpl_argvec[idx]);
+ else
+ {
+ char buf[10];
+ sprintf(buf, "T%d", idx);
+ string_append (result, buf);
+ }
+
+ success = 1;
+ }
+ break;
+
default:
success = demangle_fund_type (work, mangled, result);
break;
@@ -2194,6 +2749,8 @@ demangle_fund_type (work, mangled, result)
{
int done = 0;
int success = 1;
+ string btype;
+ string_init (&btype);
/* First pick off any type qualifiers. There can be more than one. */
@@ -2230,7 +2787,7 @@ demangle_fund_type (work, mangled, result)
case 'J':
(*mangled)++;
APPEND_BLANK (result);
- string_append (result, "complex");
+ string_append (result, "__complex");
break;
default:
done = 1;
@@ -2319,15 +2876,28 @@ demangle_fund_type (work, mangled, result)
case '7':
case '8':
case '9':
- APPEND_BLANK (result);
- if (!demangle_class_name (work, mangled, result)) {
- --result->p;
- success = 0;
+ {
+ int bindex = register_Btype (work);
+ string btype;
+ string_init (&btype);
+ if (demangle_class_name (work, mangled, &btype)) {
+ remember_Btype (work, btype.b, LEN_STRING (&btype), bindex);
+ APPEND_BLANK (result);
+ string_appends (result, &btype);
+ }
+ else
+ success = 0;
+ string_delete (&btype);
+ break;
}
- break;
case 't':
- success = demangle_template(work,mangled, result, 0);
- break;
+ {
+ int bindex= register_Btype (work);
+ success = demangle_template (work, mangled, &btype, 0, 1);
+ remember_Btype (work, btype.b, LEN_STRING (&btype), bindex);
+ string_appends (result, &btype);
+ break;
+ }
default:
success = 0;
break;
@@ -2387,6 +2957,112 @@ remember_type (work, start, len)
work -> typevec[work -> ntypes++] = tem;
}
+
+/* Remember a K type class qualifier. */
+static void
+remember_Ktype (work, start, len)
+ struct work_stuff *work;
+ const char *start;
+ int len;
+{
+ char *tem;
+
+ if (work -> numk >= work -> ksize)
+ {
+ if (work -> ksize == 0)
+ {
+ work -> ksize = 5;
+ work -> ktypevec
+ = (char **) xmalloc (sizeof (char *) * work -> ksize);
+ }
+ else
+ {
+ work -> ksize *= 2;
+ work -> ktypevec
+ = (char **) xrealloc ((char *)work -> ktypevec,
+ sizeof (char *) * work -> ksize);
+ }
+ }
+ tem = xmalloc (len + 1);
+ memcpy (tem, start, len);
+ tem[len] = '\0';
+ work -> ktypevec[work -> numk++] = tem;
+}
+
+/* Register a B code, and get an index for it. B codes are registered
+ as they are seen, rather than as they are completed, so map<temp<char> >
+ registers map<temp<char> > as B0, and temp<char> as B1 */
+
+static int
+register_Btype (work)
+ struct work_stuff *work;
+{
+ int ret;
+
+ if (work -> numb >= work -> bsize)
+ {
+ if (work -> bsize == 0)
+ {
+ work -> bsize = 5;
+ work -> btypevec
+ = (char **) xmalloc (sizeof (char *) * work -> bsize);
+ }
+ else
+ {
+ work -> bsize *= 2;
+ work -> btypevec
+ = (char **) xrealloc ((char *)work -> btypevec,
+ sizeof (char *) * work -> bsize);
+ }
+ }
+ ret = work -> numb++;
+ work -> btypevec[ret] = NULL;
+ return(ret);
+}
+
+/* Store a value into a previously registered B code type. */
+
+static void
+remember_Btype (work, start, len, index)
+ struct work_stuff *work;
+ const char *start;
+ int len, index;
+{
+ char *tem;
+
+ tem = xmalloc (len + 1);
+ memcpy (tem, start, len);
+ tem[len] = '\0';
+ work -> btypevec[index] = tem;
+}
+
+/* Lose all the info related to B and K type codes. */
+static void
+forget_B_and_K_types (work)
+ struct work_stuff *work;
+{
+ int i;
+
+ while (work -> numk > 0)
+ {
+ i = --(work -> numk);
+ if (work -> ktypevec[i] != NULL)
+ {
+ free (work -> ktypevec[i]);
+ work -> ktypevec[i] = NULL;
+ }
+ }
+
+ while (work -> numb > 0)
+ {
+ i = --(work -> numb);
+ if (work -> btypevec[i] != NULL)
+ {
+ free (work -> btypevec[i]);
+ work -> btypevec[i] = NULL;
+ }
+ }
+}
/* Forget the remembered types, but not the type vector itself. */
static void
@@ -2582,8 +3258,7 @@ demangle_function_name (work, mangled, declp, scan)
string *declp;
const char *scan;
{
- int i;
- int len;
+ size_t i;
string type;
const char *tem;
@@ -2630,7 +3305,7 @@ demangle_function_name (work, mangled, declp, scan)
{
for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++)
{
- len = declp->p - declp->b - 10;
+ int len = declp->p - declp->b - 10;
if (strlen (optable[i].in) == len
&& memcmp (optable[i].in, declp->b + 10, len) == 0)
{
@@ -2934,12 +3609,20 @@ static struct option long_options[] = {
{"strip-underscores", no_argument, 0, '_'},
{"format", required_argument, 0, 's'},
{"help", no_argument, 0, 'h'},
- {"java", no_argument, 0, 'j'},
{"no-strip-underscores", no_argument, 0, 'n'},
{"version", no_argument, 0, 'v'},
{0, no_argument, 0, 0}
};
+/* More 'friendly' abort that prints the line and file.
+ config.h can #define abort fancy_abort if you like that sort of thing. */
+
+void
+fancy_abort ()
+{
+ fatal ("Internal gcc abort.");
+}
+
int
main (argc, argv)
int argc;
@@ -2970,9 +3653,6 @@ main (argc, argv)
case '_':
strip_underscore = 1;
break;
- case 'j':
- flags |= DMGL_JAVA;
- break;
case 's':
if (strcmp (optarg, "gnu") == 0)
{
diff --git a/libiberty/getcwd.c b/libiberty/getcwd.c
index 60c1dd84eed..06d55c04f58 100644
--- a/libiberty/getcwd.c
+++ b/libiberty/getcwd.c
@@ -20,7 +20,9 @@ BUGS
*/
-#ifndef NO_SYS_PARAM_H
+#include "config.h"
+
+#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <errno.h>
diff --git a/libiberty/getopt.c b/libiberty/getopt.c
index 79080aa54b3..fc87ce67d69 100644
--- a/libiberty/getopt.c
+++ b/libiberty/getopt.c
@@ -3,29 +3,26 @@
"Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
before changing it!
- Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95
+ Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97
Free Software Foundation, Inc.
-This file is part of the libiberty library. This library is free
-software; you can redistribute it and/or modify it under the
-terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU CC; see the file COPYING. If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-As a special exception, if you link this library with files
-compiled with a GNU compiler to produce an executable, this does not cause
-the resulting executable to be covered by the GNU General Public License.
-This exception does not however invalidate any other reasons why
-the executable file might be covered by the GNU General Public License. */
+ NOTE: The canonical source of this file is maintained with the GNU C Library.
+ Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
Ditto for AIX 3.2 and <stdlib.h>. */
@@ -34,17 +31,10 @@ the executable file might be covered by the GNU General Public License. */
#endif
#ifdef HAVE_CONFIG_H
-#if defined (emacs) || defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
- using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
- (which it would do because it found this file in $srcdir). */
#include <config.h>
-#else
-#include "config.h"
-#endif
#endif
-#ifndef __STDC__
+#if !defined (__STDC__) || !__STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
@@ -61,11 +51,16 @@ the executable file might be covered by the GNU General Public License. */
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
-/* Many versions of the Linux C library include older, broken versions
- of these routines, which will break the linker's command-line
- parsing. */
-#if defined (_LIBC) || !defined (__GNU_LIBRARY__) || defined (__linux__)
+#define GETOPT_INTERFACE_VERSION 2
+#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
+#include <gnu-versions.h>
+#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
+#define ELIDE_CODE
+#endif
+#endif
+
+#ifndef ELIDE_CODE
/* This needs to come after some library #include
@@ -74,8 +69,27 @@ the executable file might be covered by the GNU General Public License. */
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
#include <stdlib.h>
+#include <unistd.h>
#endif /* GNU C library. */
+#ifdef VMS
+#include <unixlib.h>
+#if HAVE_STRING_H - 0
+#include <string.h>
+#endif
+#endif
+
+#ifndef _
+/* This is for other GNU distributions with internationalized messages.
+ When compiling libc, the _ macro is predefined. */
+#ifdef HAVE_LIBINTL_H
+# include <libintl.h>
+# define _(msgid) gettext (msgid)
+#else
+# define _(msgid) (msgid)
+#endif
+#endif
+
/* This version of `getopt' appears to the caller like standard Unix `getopt'
but it behaves differently for the user, since it allows the user
to intersperse the options with the other arguments.
@@ -106,14 +120,20 @@ char *optarg = NULL;
On entry to `getopt', zero means this is the first call; initialize.
- When `getopt' returns EOF, this is the index of the first of the
+ When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
-/* XXX 1003.2 says this must be 1 before any call. */
-int optind = 0;
+/* 1003.2 says this must be 1 before any call. */
+int optind = 1;
+
+/* Formerly, initialization of getopt depended on optind==0, which
+ causes problems with re-calling getopt as programs generally don't
+ know that. */
+
+int __getopt_initialized = 0;
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
@@ -162,12 +182,15 @@ int optopt = '?';
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
- `--' can cause `getopt' to return EOF with `optind' != ARGC. */
+ `--' can cause `getopt' to return -1 with `optind' != ARGC. */
static enum
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} ordering;
+
+/* Value of POSIXLY_CORRECT environment variable. */
+static char *posixly_correct;
#ifdef __GNU_LIBRARY__
/* We want to avoid inclusion of string.h with non-GNU libraries
@@ -202,7 +225,7 @@ my_index (str, chr)
#ifdef __GNUC__
/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
That was relevant to code that was here before. */
-#ifndef __STDC__
+#if !defined (__STDC__) || !__STDC__
/* gcc with -traditional declares the built-in strlen to return int,
and has done so at least since version 2.4.5. -- rms. */
extern int strlen (const char *);
@@ -220,6 +243,46 @@ extern int strlen (const char *);
static int first_nonopt;
static int last_nonopt;
+#ifdef _LIBC
+/* Bash 2.0 gives us an environment variable containing flags
+ indicating ARGV elements that should not be considered arguments. */
+
+/* Defined in getopt_init.c */
+extern char *__getopt_nonoption_flags;
+
+static int nonoption_flags_max_len;
+static int nonoption_flags_len;
+
+static int original_argc;
+static char *const *original_argv;
+
+/* Make sure the environment variable bash 2.0 puts in the environment
+ is valid for the getopt call we must make sure that the ARGV passed
+ to getopt is that one passed to the process. */
+static void
+__attribute__ ((unused))
+store_args_and_env (int argc, char *const *argv)
+{
+ /* XXX This is no good solution. We should rather copy the args so
+ that we can compare them later. But we must not use malloc(3). */
+ original_argc = argc;
+ original_argv = argv;
+}
+# ifdef text_set_element
+text_set_element (__libc_subinit, store_args_and_env);
+# endif /* text_set_element */
+
+# define SWAP_FLAGS(ch1, ch2) \
+ if (nonoption_flags_len > 0) \
+ { \
+ char __tmp = __getopt_nonoption_flags[ch1]; \
+ __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
+ __getopt_nonoption_flags[ch2] = __tmp; \
+ }
+#else /* !_LIBC */
+# define SWAP_FLAGS(ch1, ch2)
+#endif /* _LIBC */
+
/* Exchange two adjacent subsequences of ARGV.
One subsequence is elements [first_nonopt,last_nonopt)
which contains all the non-options that have been skipped so far.
@@ -229,6 +292,10 @@ static int last_nonopt;
`first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */
+#if defined (__STDC__) && __STDC__
+static void exchange (char **);
+#endif
+
static void
exchange (argv)
char **argv;
@@ -243,6 +310,28 @@ exchange (argv)
It leaves the longer segment in the right place overall,
but it consists of two parts that need to be swapped next. */
+#ifdef _LIBC
+ /* First make sure the handling of the `__getopt_nonoption_flags'
+ string can work normally. Our top argument must be in the range
+ of the string. */
+ if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
+ {
+ /* We must extend the array. The user plays games with us and
+ presents new arguments. */
+ char *new_str = malloc (top + 1);
+ if (new_str == NULL)
+ nonoption_flags_len = nonoption_flags_max_len = 0;
+ else
+ {
+ memset (__mempcpy (new_str, __getopt_nonoption_flags,
+ nonoption_flags_max_len),
+ '\0', top + 1 - nonoption_flags_max_len);
+ nonoption_flags_max_len = top + 1;
+ __getopt_nonoption_flags = new_str;
+ }
+ }
+#endif
+
while (top > middle && middle > bottom)
{
if (top - middle > middle - bottom)
@@ -257,6 +346,7 @@ exchange (argv)
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
+ SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
@@ -273,6 +363,7 @@ exchange (argv)
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
+ SWAP_FLAGS (bottom + i, middle + i);
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
@@ -287,18 +378,25 @@ exchange (argv)
/* Initialize the internal data when the first call is made. */
+#if defined (__STDC__) && __STDC__
+static const char *_getopt_initialize (int, char *const *, const char *);
+#endif
static const char *
-_getopt_initialize (optstring)
+_getopt_initialize (argc, argv, optstring)
+ int argc;
+ char *const *argv;
const char *optstring;
{
/* Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
- first_nonopt = last_nonopt = optind = 1;
+ first_nonopt = last_nonopt = optind;
nextchar = NULL;
+ posixly_correct = getenv ("POSIXLY_CORRECT");
+
/* Determine how to handle the ordering of options and nonoptions. */
if (optstring[0] == '-')
@@ -311,11 +409,41 @@ _getopt_initialize (optstring)
ordering = REQUIRE_ORDER;
++optstring;
}
- else if (getenv ("POSIXLY_CORRECT") != NULL)
+ else if (posixly_correct != NULL)
ordering = REQUIRE_ORDER;
else
ordering = PERMUTE;
+#ifdef _LIBC
+ if (posixly_correct == NULL
+ && argc == original_argc && argv == original_argv)
+ {
+ if (nonoption_flags_max_len == 0)
+ {
+ if (__getopt_nonoption_flags == NULL
+ || __getopt_nonoption_flags[0] == '\0')
+ nonoption_flags_max_len = -1;
+ else
+ {
+ const char *orig_str = __getopt_nonoption_flags;
+ int len = nonoption_flags_max_len = strlen (orig_str);
+ if (nonoption_flags_max_len < argc)
+ nonoption_flags_max_len = argc;
+ __getopt_nonoption_flags =
+ (char *) malloc (nonoption_flags_max_len);
+ if (__getopt_nonoption_flags == NULL)
+ nonoption_flags_max_len = -1;
+ else
+ memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
+ '\0', nonoption_flags_max_len - len);
+ }
+ }
+ nonoption_flags_len = nonoption_flags_max_len;
+ }
+ else
+ nonoption_flags_len = 0;
+#endif
+
return optstring;
}
@@ -332,7 +460,7 @@ _getopt_initialize (optstring)
updating `optind' and `nextchar' so that the next call to `getopt' can
resume the scan with the following option character or ARGV-element.
- If there are no more option characters, `getopt' returns `EOF'.
+ If there are no more option characters, `getopt' returns -1.
Then `optind' is the index in ARGV of the first ARGV-element
that is not an option. (The ARGV-elements have been permuted
so that those that are not options now come last.)
@@ -386,16 +514,37 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
optarg = NULL;
- if (optind == 0)
- optstring = _getopt_initialize (optstring);
+ if (optind == 0 || !__getopt_initialized)
+ {
+ if (optind == 0)
+ optind = 1; /* Don't scan ARGV[0], the program name. */
+ optstring = _getopt_initialize (argc, argv, optstring);
+ __getopt_initialized = 1;
+ }
- if (argc == 0)
- return EOF;
+ /* Test whether ARGV[optind] points to a non-option argument.
+ Either it does not have option syntax, or there is an environment flag
+ from the shell indicating it is not an option. The later information
+ is only used when the used in the GNU libc. */
+#ifdef _LIBC
+#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
+ || (optind < nonoption_flags_len \
+ && __getopt_nonoption_flags[optind] == '1'))
+#else
+#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
+#endif
if (nextchar == NULL || *nextchar == '\0')
{
/* Advance to the next ARGV-element. */
+ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
+ moved back by the user (who may also have changed the arguments). */
+ if (last_nonopt > optind)
+ last_nonopt = optind;
+ if (first_nonopt > optind)
+ first_nonopt = optind;
+
if (ordering == PERMUTE)
{
/* If we have just processed some options following some non-options,
@@ -409,8 +558,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
/* Skip any additional non-options
and extend the range of non-options previously skipped. */
- while (optind < argc
- && (argv[optind][0] != '-' || argv[optind][1] == '\0'))
+ while (optind < argc && NONOPTION_P)
optind++;
last_nonopt = optind;
}
@@ -442,16 +590,16 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
optind = first_nonopt;
- return EOF;
+ return -1;
}
/* If we have come to a non-option and did not permute it,
either stop the scan or describe it to the caller and pass it by. */
- if ((argv[optind][0] != '-' || argv[optind][1] == '\0'))
+ if (NONOPTION_P)
{
if (ordering == REQUIRE_ORDER)
- return EOF;
+ return -1;
optarg = argv[optind++];
return 1;
}
@@ -487,7 +635,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
const struct option *pfound = NULL;
int exact = 0;
int ambig = 0;
- int indfound;
+ int indfound = -1;
int option_index;
for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
@@ -498,7 +646,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp (p->name, nextchar, nameend - nextchar))
{
- if (nameend - nextchar == strlen (p->name))
+ if ((unsigned int) (nameend - nextchar)
+ == (unsigned int) strlen (p->name))
{
/* Exact match found. */
pfound = p;
@@ -520,10 +669,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
if (ambig && !exact)
{
if (opterr)
- fprintf (stderr, "%s: option `%s' is ambiguous\n",
+ fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
argv[0], argv[optind]);
nextchar += strlen (nextchar);
optind++;
+ optopt = 0;
return '?';
}
@@ -540,19 +690,20 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
else
{
if (opterr)
- {
- if (argv[optind - 1][1] == '-')
- /* --option */
- fprintf (stderr,
- "%s: option `--%s' doesn't allow an argument\n",
- argv[0], pfound->name);
- else
- /* +option or -option */
- fprintf (stderr,
- "%s: option `%c%s' doesn't allow an argument\n",
- argv[0], argv[optind - 1][0], pfound->name);
- }
+ if (argv[optind - 1][1] == '-')
+ /* --option */
+ fprintf (stderr,
+ _("%s: option `--%s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+ else
+ /* +option or -option */
+ fprintf (stderr,
+ _("%s: option `%c%s' doesn't allow an argument\n"),
+ argv[0], argv[optind - 1][0], pfound->name);
+
nextchar += strlen (nextchar);
+
+ optopt = pfound->val;
return '?';
}
}
@@ -563,9 +714,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
else
{
if (opterr)
- fprintf (stderr, "%s: option `%s' requires an argument\n",
- argv[0], argv[optind - 1]);
+ fprintf (stderr,
+ _("%s: option `%s' requires an argument\n"),
+ argv[0], argv[optind - 1]);
nextchar += strlen (nextchar);
+ optopt = pfound->val;
return optstring[0] == ':' ? ':' : '?';
}
}
@@ -591,15 +744,16 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
if (argv[optind][1] == '-')
/* --option */
- fprintf (stderr, "%s: unrecognized option `--%s'\n",
+ fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
argv[0], nextchar);
else
/* +option or -option */
- fprintf (stderr, "%s: unrecognized option `%c%s'\n",
+ fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
argv[0], argv[optind][0], nextchar);
}
nextchar = (char *) "";
optind++;
+ optopt = 0;
return '?';
}
}
@@ -618,12 +772,141 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
if (opterr)
{
- /* 1003.2 specifies the format of this message. */
- fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
+ if (posixly_correct)
+ /* 1003.2 specifies the format of this message. */
+ fprintf (stderr, _("%s: illegal option -- %c\n"),
+ argv[0], c);
+ else
+ fprintf (stderr, _("%s: invalid option -- %c\n"),
+ argv[0], c);
}
optopt = c;
return '?';
}
+ /* Convenience. Treat POSIX -W foo same as long option --foo */
+ if (temp[0] == 'W' && temp[1] == ';')
+ {
+ char *nameend;
+ const struct option *p;
+ const struct option *pfound = NULL;
+ int exact = 0;
+ int ambig = 0;
+ int indfound = 0;
+ int option_index;
+
+ /* This is an option that requires an argument. */
+ if (*nextchar != '\0')
+ {
+ optarg = nextchar;
+ /* If we end this ARGV-element by taking the rest as an arg,
+ we must advance to the next element now. */
+ optind++;
+ }
+ else if (optind == argc)
+ {
+ if (opterr)
+ {
+ /* 1003.2 specifies the format of this message. */
+ fprintf (stderr, _("%s: option requires an argument -- %c\n"),
+ argv[0], c);
+ }
+ optopt = c;
+ if (optstring[0] == ':')
+ c = ':';
+ else
+ c = '?';
+ return c;
+ }
+ else
+ /* We already incremented `optind' once;
+ increment it again when taking next ARGV-elt as argument. */
+ optarg = argv[optind++];
+
+ /* optarg is now the argument, see if it's in the
+ table of longopts. */
+
+ for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
+ /* Do nothing. */ ;
+
+ /* Test all long options for either exact match
+ or abbreviated matches. */
+ for (p = longopts, option_index = 0; p->name; p++, option_index++)
+ if (!strncmp (p->name, nextchar, nameend - nextchar))
+ {
+ if ((unsigned int) (nameend - nextchar) == strlen (p->name))
+ {
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
+ }
+ else if (pfound == NULL)
+ {
+ /* First nonexact match found. */
+ pfound = p;
+ indfound = option_index;
+ }
+ else
+ /* Second or later nonexact match found. */
+ ambig = 1;
+ }
+ if (ambig && !exact)
+ {
+ if (opterr)
+ fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
+ argv[0], argv[optind]);
+ nextchar += strlen (nextchar);
+ optind++;
+ return '?';
+ }
+ if (pfound != NULL)
+ {
+ option_index = indfound;
+ if (*nameend)
+ {
+ /* Don't test has_arg with >, because some C compilers don't
+ allow it to be used on enums. */
+ if (pfound->has_arg)
+ optarg = nameend + 1;
+ else
+ {
+ if (opterr)
+ fprintf (stderr, _("\
+%s: option `-W %s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+
+ nextchar += strlen (nextchar);
+ return '?';
+ }
+ }
+ else if (pfound->has_arg == 1)
+ {
+ if (optind < argc)
+ optarg = argv[optind++];
+ else
+ {
+ if (opterr)
+ fprintf (stderr,
+ _("%s: option `%s' requires an argument\n"),
+ argv[0], argv[optind - 1]);
+ nextchar += strlen (nextchar);
+ return optstring[0] == ':' ? ':' : '?';
+ }
+ }
+ nextchar += strlen (nextchar);
+ if (longind != NULL)
+ *longind = option_index;
+ if (pfound->flag)
+ {
+ *(pfound->flag) = pfound->val;
+ return 0;
+ }
+ return pfound->val;
+ }
+ nextchar = NULL;
+ return 'W'; /* Let the application handle it. */
+ }
if (temp[1] == ':')
{
if (temp[2] == ':')
@@ -653,8 +936,9 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
if (opterr)
{
/* 1003.2 specifies the format of this message. */
- fprintf (stderr, "%s: option requires an argument -- %c\n",
- argv[0], c);
+ fprintf (stderr,
+ _("%s: option requires an argument -- %c\n"),
+ argv[0], c);
}
optopt = c;
if (optstring[0] == ':')
@@ -685,7 +969,7 @@ getopt (argc, argv, optstring)
0);
}
-#endif /* _LIBC or not __GNU_LIBRARY__. */
+#endif /* Not ELIDE_CODE. */
#ifdef TEST
@@ -705,7 +989,7 @@ main (argc, argv)
int this_option_optind = optind ? optind : 1;
c = getopt (argc, argv, "abc:d:0123456789");
- if (c == EOF)
+ if (c == -1)
break;
switch (c)
diff --git a/libiberty/getopt1.c b/libiberty/getopt1.c
index c3400e5b643..af8e6819657 100644
--- a/libiberty/getopt1.c
+++ b/libiberty/getopt1.c
@@ -1,35 +1,31 @@
/* getopt_long and getopt_long_only entry points for GNU getopt.
- Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
- Free Software Foundation, Inc.
+ Copyright (C) 1987,88,89,90,91,92,93,94,96,97 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License
- as published by the Free Software Foundation; either version 2, or
- (at your option) any later version.
+ NOTE: The canonical source of this file is maintained with the GNU C Library.
+ Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Library General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Library 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
- Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
#ifdef HAVE_CONFIG_H
-#if defined (emacs) || defined (CONFIG_BROKETS)
-/* We use <config.h> instead of "config.h" so that a compilation
- using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
- (which it would do because it found this file in $srcdir). */
#include <config.h>
-#else
-#include "config.h"
-#endif
#endif
#include "getopt.h"
-#ifndef __STDC__
+#if !defined (__STDC__) || !__STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
@@ -46,19 +42,22 @@
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
-/* Many versions of the Linux C library include older, broken versions
- of these routines, which will break the linker's command-line
- parsing. */
-#if defined (_LIBC) || !defined (__GNU_LIBRARY__) || defined (__linux__)
+#define GETOPT_INTERFACE_VERSION 2
+#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
+#include <gnu-versions.h>
+#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
+#define ELIDE_CODE
+#endif
+#endif
+
+#ifndef ELIDE_CODE
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#include <stdlib.h>
-#else
-char *getenv ();
#endif
#ifndef NULL
@@ -93,7 +92,7 @@ getopt_long_only (argc, argv, options, long_options, opt_index)
}
-#endif /* _LIBC or not __GNU_LIBRARY__. */
+#endif /* Not ELIDE_CODE. */
#ifdef TEST
@@ -124,7 +123,7 @@ main (argc, argv)
c = getopt_long (argc, argv, "abc:d:0123456789",
long_options, &option_index);
- if (c == EOF)
+ if (c == -1)
break;
switch (c)
diff --git a/libiberty/getpagesize.c b/libiberty/getpagesize.c
index e9784b8520b..d6327a8887d 100644
--- a/libiberty/getpagesize.c
+++ b/libiberty/getpagesize.c
@@ -28,8 +28,10 @@ BUGS
#ifndef VMS
+#include "config.h"
+
#include <sys/types.h>
-#ifndef NO_SYS_PARAM_H
+#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
diff --git a/libiberty/getruntime.c b/libiberty/getruntime.c
index 1be3b4c4a2a..86162225901 100644
--- a/libiberty/getruntime.c
+++ b/libiberty/getruntime.c
@@ -17,6 +17,8 @@ License along with libiberty; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include "config.h"
+
#include "ansidecl.h"
#include "libiberty.h"
@@ -26,23 +28,13 @@ Boston, MA 02111-1307, USA. */
#include <time.h>
-/* These should go away when libiberty uses autoconf. */
-
-#if defined(__sun__) && !defined(__svr4__)
-#define HAVE_GETRUSAGE
-#endif
-
-#ifdef HAVE_SYSCONF
-#define HAVE_TIMES
-#endif
-
#ifdef HAVE_GETRUSAGE
#include <sys/time.h>
#include <sys/resource.h>
#endif
#ifdef HAVE_TIMES
-#ifndef NO_SYS_PARAM_H
+#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <sys/times.h>
diff --git a/libiberty/makefile.vms b/libiberty/makefile.vms
index 6f49ee1b1ea..b61b51290da 100644
--- a/libiberty/makefile.vms
+++ b/libiberty/makefile.vms
@@ -23,15 +23,11 @@ libiberty.olb: config.h alloca-conf.h $(OBJS)
purge
lib/create libiberty *.obj
-alloca-conf.h: alloca-norm.h
- $(CP) $< $@
-
config.h: config.h-vms
$(CP) $< $@
clean:
$$ purge
- $(RM) alloca-conf.h;
$(RM) config.h;
$(RM) *.obj;
$(RM) libiberty.olb;
diff --git a/libiberty/mpw-config.in b/libiberty/mpw-config.in
index 829d8e730d4..2a21802148d 100644
--- a/libiberty/mpw-config.in
+++ b/libiberty/mpw-config.in
@@ -1,7 +1,5 @@
# MPW configuration fragment for libiberty.
-forward-include "{srcdir}"alloca-norm.h alloca-conf.h
-
Echo '/* config.h. Generated by mpw-configure. */' > "{o}"config.new
MoveIfChange "{o}"config.new "{o}"config.h
diff --git a/libiberty/pexecute.c b/libiberty/pexecute.c
index ab5f392780c..fbbea409147 100644
--- a/libiberty/pexecute.c
+++ b/libiberty/pexecute.c
@@ -23,11 +23,14 @@ Boston, MA 02111-1307, USA. */
/* This file lives in at least two places: libiberty and gcc.
Don't change one without the other. */
+#ifdef IN_GCC
+#include "config.h"
+#endif
+
#include <stdio.h>
#include <errno.h>
#ifdef IN_GCC
-#include "config.h"
#include "gansidecl.h"
/* ??? Need to find a suitable header file. */
#define PEXECUTE_FIRST 1
@@ -220,6 +223,11 @@ pwait (pid, status, flags)
#if defined (_WIN32)
#include <process.h>
+
+#ifdef __CYGWIN32__
+
+#define fix_argv(argvec) (argvec)
+
extern int _spawnv ();
extern int _spawnvp ();
@@ -236,7 +244,8 @@ pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE)
abort ();
- pid = (flags & PEXECUTE_SEARCH ? _spawnvp : _spawnv) (_P_NOWAIT, program, argv);
+ pid = (flags & PEXECUTE_SEARCH ? _spawnvp : _spawnv)
+ (_P_NOWAIT, program, fix_argv(argv));
if (pid == -1)
{
*errmsg_fmt = install_error_msg;
@@ -257,6 +266,181 @@ pwait (pid, status, flags)
return cwait (status, pid, WAIT_CHILD);
}
+#else /* ! __CYGWIN32__ */
+
+/* This is a kludge to get around the Microsoft C spawn functions' propensity
+ to remove the outermost set of double quotes from all arguments. */
+
+const char * const *
+fix_argv (argvec)
+ char **argvec;
+{
+ int i;
+
+ for (i = 1; argvec[i] != 0; i++)
+ {
+ int len, j;
+ char *temp, *newtemp;
+
+ temp = argvec[i];
+ len = strlen (temp);
+ for (j = 0; j < len; j++)
+ {
+ if (temp[j] == '"')
+ {
+ newtemp = xmalloc (len + 2);
+ strncpy (newtemp, temp, j);
+ newtemp [j] = '\\';
+ strncpy (&newtemp [j+1], &temp [j], len-j);
+ newtemp [len+1] = 0;
+ temp = newtemp;
+ len++;
+ j++;
+ }
+ }
+
+ argvec[i] = temp;
+ }
+
+ return (const char * const *) argvec;
+}
+
+#include <io.h>
+#include <fcntl.h>
+#include <signal.h>
+
+/* mingw32 headers may not define the following. */
+
+#ifndef _P_WAIT
+# define _P_WAIT 0
+# define _P_NOWAIT 1
+# define _P_OVERLAY 2
+# define _P_NOWAITO 3
+# define _P_DETACH 4
+
+# define WAIT_CHILD 0
+# define WAIT_GRANDCHILD 1
+#endif
+
+/* Win32 supports pipes */
+int
+pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
+ const char *program;
+ char * const *argv;
+ const char *this_pname;
+ const char *temp_base;
+ char **errmsg_fmt, **errmsg_arg;
+ int flags;
+{
+ int pid;
+ int pdes[2], org_stdin, org_stdout;
+ int input_desc, output_desc;
+ int retries, sleep_interval;
+
+ /* Pipe waiting from last process, to be used as input for the next one.
+ Value is STDIN_FILE_NO if no pipe is waiting
+ (i.e. the next command is the first of a group). */
+ static int last_pipe_input;
+
+ /* If this is the first process, initialize. */
+ if (flags & PEXECUTE_FIRST)
+ last_pipe_input = STDIN_FILE_NO;
+
+ input_desc = last_pipe_input;
+
+ /* If this isn't the last process, make a pipe for its output,
+ and record it as waiting to be the input to the next process. */
+ if (! (flags & PEXECUTE_LAST))
+ {
+ if (_pipe (pdes, 256, O_BINARY) < 0)
+ {
+ *errmsg_fmt = "pipe";
+ *errmsg_arg = NULL;
+ return -1;
+ }
+ output_desc = pdes[WRITE_PORT];
+ last_pipe_input = pdes[READ_PORT];
+ }
+ else
+ {
+ /* Last process. */
+ output_desc = STDOUT_FILE_NO;
+ last_pipe_input = STDIN_FILE_NO;
+ }
+
+ if (input_desc != STDIN_FILE_NO)
+ {
+ org_stdin = dup (STDIN_FILE_NO);
+ dup2 (input_desc, STDIN_FILE_NO);
+ close (input_desc);
+ }
+
+ if (output_desc != STDOUT_FILE_NO)
+ {
+ org_stdout = dup (STDOUT_FILE_NO);
+ dup2 (output_desc, STDOUT_FILE_NO);
+ close (output_desc);
+ }
+
+ pid = (flags & PEXECUTE_SEARCH ? _spawnvp : _spawnv)
+ (_P_NOWAIT, program, fix_argv(argv));
+
+ if (input_desc != STDIN_FILE_NO)
+ {
+ dup2 (org_stdin, STDIN_FILE_NO);
+ close (org_stdin);
+ }
+
+ if (output_desc != STDOUT_FILE_NO)
+ {
+ dup2 (org_stdout, STDOUT_FILE_NO);
+ close (org_stdout);
+ }
+
+ if (pid == -1)
+ {
+ *errmsg_fmt = install_error_msg;
+ *errmsg_arg = program;
+ return -1;
+ }
+
+ return pid;
+}
+
+/* MS CRTDLL doesn't return enough information in status to decide if the
+ child exited due to a signal or not, rather it simply returns an
+ integer with the exit code of the child; eg., if the child exited with
+ an abort() call and didn't have a handler for SIGABRT, it simply returns
+ with status = 3. We fix the status code to conform to the usual WIF*
+ macros. Note that WIFSIGNALED will never be true under CRTDLL. */
+
+int
+pwait (pid, status, flags)
+ int pid;
+ int *status;
+ int flags;
+{
+ int termstat;
+
+ pid = _cwait (&termstat, pid, WAIT_CHILD);
+
+ /* ??? Here's an opportunity to canonicalize the values in STATUS.
+ Needed? */
+
+ /* cwait returns the child process exit code in termstat.
+ A value of 3 indicates that the child caught a signal, but not
+ which one. Since only SIGABRT, SIGFPE and SIGINT do anything, we
+ report SIGABRT. */
+ if (termstat == 3)
+ *status = SIGABRT;
+ else
+ *status = (((termstat) & 0xff) << 8);
+
+ return pid;
+}
+
+#endif /* ! defined (__CYGWIN32__) */
+
#endif /* _WIN32 */
#ifdef OS2
diff --git a/libiberty/strerror.c b/libiberty/strerror.c
index f5e2eebee2e..644cc75462a 100644
--- a/libiberty/strerror.c
+++ b/libiberty/strerror.c
@@ -7,7 +7,7 @@
#include "config.h"
-#ifndef NEED_sys_errlist
+#ifdef HAVE_SYS_ERRLIST
/* Note that errno.h (not sure what OS) or stdio.h (BSD 4.4, at least)
might declare sys_errlist in a way that the compiler might consider
incompatible with our later declaration, perhaps by using const
@@ -19,7 +19,7 @@
#include <stdio.h>
#include <errno.h>
-#ifndef NEED_sys_errlist
+#ifdef HAVE_SYS_ERRLIST
#undef sys_errlist
#endif
@@ -55,12 +55,12 @@ struct error_info
{
int value; /* The numeric value from <errno.h> */
const char *name; /* The equivalent symbolic value */
-#ifdef NEED_sys_errlist
+#ifndef HAVE_SYS_ERRLIST
const char *msg; /* Short message about this value */
#endif
};
-#ifdef NEED_sys_errlist
+#ifndef HAVE_SYS_ERRLIST
# define ENTRY(value, name, msg) {value, name, msg}
#else
# define ENTRY(value, name, msg) {value, name}
@@ -455,7 +455,7 @@ static int num_error_names = 0;
same name, it differs from other implementations in that it is dynamically
initialized rather than statically initialized. */
-#ifdef NEED_sys_errlist
+#ifndef HAVE_SYS_ERRLIST
static int sys_nerr;
static const char **sys_errlist;
@@ -532,7 +532,7 @@ init_error_tables ()
}
}
-#ifdef NEED_sys_errlist
+#ifndef HAVE_SYS_ERRLIST
/* Now attempt to allocate the sys_errlist table, zero it out, and then
initialize it from the statically initialized error_table. */
@@ -595,7 +595,7 @@ errno_max ()
return (maxsize - 1);
}
-#ifdef NEED_strerror
+#ifndef HAVE_STRERROR
/*
@@ -634,7 +634,7 @@ strerror (errnoval)
char *msg;
static char buf[32];
-#ifdef NEED_sys_errlist
+#ifndef HAVE_SYS_ERRLIST
if (error_names == NULL)
{
@@ -668,7 +668,7 @@ strerror (errnoval)
return (msg);
}
-#endif /* NEED_strerror */
+#endif /* ! HAVE_STRERROR */
/*
diff --git a/libiberty/strsignal.c b/libiberty/strsignal.c
index 7d40b4cedff..c7bb10c441c 100644
--- a/libiberty/strsignal.c
+++ b/libiberty/strsignal.c
@@ -64,12 +64,12 @@ struct signal_info
{
int value; /* The numeric value from <signal.h> */
const char *name; /* The equivalent symbolic value */
-#ifdef NEED_sys_siglist
+#ifndef HAVE_SYS_SIGLIST
const char *msg; /* Short message about this value */
#endif
};
-#ifdef NEED_sys_siglist
+#ifndef HAVE_SYS_SIGLIST
# define ENTRY(value, name, msg) {value, name, msg}
#else
# define ENTRY(value, name, msg) {value, name}
@@ -236,14 +236,20 @@ static int num_signal_names = 0;
same name, it differs from other implementations in that it is dynamically
initialized rather than statically initialized. */
-#ifdef NEED_sys_siglist
+#ifndef HAVE_SYS_SIGLIST
static int sys_nsig;
static const char **sys_siglist;
#else
+#ifdef NSIG
static int sys_nsig = NSIG;
+#else
+#ifdef _NSIG
+static int sys_nsig = _NSIG;
+#endif
+#endif
extern const char * const sys_siglist[];
#endif
@@ -313,7 +319,7 @@ init_signal_tables ()
}
}
-#ifdef NEED_sys_siglist
+#ifndef HAVE_SYS_SIGLIST
/* Now attempt to allocate the sys_siglist table, zero it out, and then
initialize it from the statically initialized signal_table. */
@@ -408,7 +414,7 @@ DESCRIPTION
*/
-#ifdef NEED_strsignal
+#ifndef HAVE_STRSIGNAL
const char *
strsignal (signo)
@@ -417,7 +423,7 @@ strsignal (signo)
const char *msg;
static char buf[32];
-#ifdef NEED_sys_siglist
+#ifndef HAVE_SYS_SIGLIST
if (signal_names == NULL)
{
@@ -446,7 +452,7 @@ strsignal (signo)
return (msg);
}
-#endif /* NEED_strsignal */
+#endif /* ! HAVE_STRSIGNAL */
/*
@@ -574,7 +580,7 @@ DESCRIPTION
followed by a newline.
*/
-#ifdef NEED_psignal
+#ifndef HAVE_PSIGNAL
void
psignal (signo, message)
@@ -595,7 +601,7 @@ psignal (signo, message)
}
}
-#endif /* NEED_psignal */
+#endif /* ! HAVE_PSIGNAL */
/* A simple little main that does nothing but print all the signal translations
diff --git a/libiberty/vasprintf.c b/libiberty/vasprintf.c
index 3794cbd2c4f..da83db2ea75 100644
--- a/libiberty/vasprintf.c
+++ b/libiberty/vasprintf.c
@@ -74,7 +74,7 @@ int_vasprintf (result, format, args)
}
while (strchr ("hlL", *p))
++p;
- /* Should be big enough for any format specifier except %s. */
+ /* Should be big enough for any format specifier except %s and floats. */
total_width += 30;
switch (*p)
{
@@ -93,6 +93,9 @@ int_vasprintf (result, format, args)
case 'g':
case 'G':
(void) va_arg (ap, double);
+ /* Since an ieee double can have an exponent of 307, we'll
+ make the buffer wide enough to cover the gross case. */
+ total_width += 307;
break;
case 's':
total_width += strlen (va_arg (ap, char *));
@@ -118,7 +121,11 @@ int
vasprintf (result, format, args)
char **result;
const char *format;
+#if defined (_BSD_VA_LIST_) && defined (__FreeBSD__)
+ _BSD_VA_LIST_ args;
+#else
va_list args;
+#endif
{
return int_vasprintf (result, format, &args);
}
diff --git a/libiberty/vmsbuild.com b/libiberty/vmsbuild.com
index 9400b45723a..4fede380bfd 100644
--- a/libiberty/vmsbuild.com
+++ b/libiberty/vmsbuild.com
@@ -13,9 +13,9 @@ $ WORK_LIB = "new-lib.olb" !used to guard against an incomplete build
$
$! manually copied from Makefile.in
$ REQUIRED_OFILES = "argv.o basename.o choose-temp.o concat.o cplus-dem.o "-
- + "fdmatch.o getopt.o getopt1.o getruntime.o hex.o "-
- + "floatformat.o obstack.o spaces.o strerror.o strsignal.o "-
- + "vasprintf.o xatexit.o xexit.o xmalloc.o xstrdup.o xstrerror.o"
+ + "fdmatch.o fnmatch.o getopt.o getopt1.o getruntime.o hex.o "-
+ + "floatformat.o objalloc.o obstack.o spaces.o strerror.o strsignal.o "-
+ + "xatexit.o xexit.o xmalloc.o xstrdup.o xstrerror.o"
$! anything not caught by link+search of dummy.* should be added here
$ EXTRA_OFILES = ""
$!
@@ -28,10 +28,9 @@ $ ECHO "Starting libiberty build..."
$ create config.h
/* libiberty config.h for VMS */
#define NEED_sys_siglist
+#define NEED_strsignal
#define NEED_psignal
#define NEED_basename
-$ if f$search("alloca-conf.h").eqs."" then -
- copy alloca-norm.h alloca-conf.h
$ LIBR 'WORK_LIB' /Create
$
$! first pass: compile "required" modules
diff --git a/libiberty/xmalloc.c b/libiberty/xmalloc.c
index c479b1f9e95..b88105a9b74 100644
--- a/libiberty/xmalloc.c
+++ b/libiberty/xmalloc.c
@@ -42,16 +42,22 @@ PTR sbrk PARAMS ((ptrdiff_t));
/* The program name if set. */
static const char *name = "";
-/* The initial sbrk, set when the program name is set. */
+#if ! defined (_WIN32) || defined (__CYGWIN32__)
+/* The initial sbrk, set when the program name is set. Not used for win32
+ ports other than cygwin32. */
static char *first_break = NULL;
+#endif
void
xmalloc_set_program_name (s)
const char *s;
{
name = s;
+#if ! defined (_WIN32) || defined (__CYGWIN32__)
+ /* Win32 ports other than cygwin32 don't have brk() */
if (first_break == NULL)
first_break = (char *) sbrk (0);
+#endif /* ! _WIN32 || __CYGWIN32 __ */
}
PTR
@@ -65,6 +71,7 @@ xmalloc (size)
newmem = malloc (size);
if (!newmem)
{
+#if ! defined (_WIN32) || defined (__CYGWIN32__)
extern char **environ;
size_t allocated;
@@ -76,6 +83,12 @@ xmalloc (size)
"\n%s%sCan not allocate %lu bytes after allocating %lu bytes\n",
name, *name ? ": " : "",
(unsigned long) size, (unsigned long) allocated);
+#else
+ fprintf (stderr,
+ "\n%s%sCan not allocate %lu bytes\n",
+ name, *name ? ": " : "",
+ (unsigned long) size);
+#endif /* ! _WIN32 || __CYGWIN32 __ */
xexit (1);
}
return (newmem);
@@ -96,6 +109,7 @@ xrealloc (oldmem, size)
newmem = realloc (oldmem, size);
if (!newmem)
{
+#ifndef __MINGW32__
extern char **environ;
size_t allocated;
@@ -107,6 +121,12 @@ xrealloc (oldmem, size)
"\n%s%sCan not reallocate %lu bytes after allocating %lu bytes\n",
name, *name ? ": " : "",
(unsigned long) size, (unsigned long) allocated);
+#else
+ fprintf (stderr,
+ "\n%s%sCan not reallocate %lu bytes\n",
+ name, *name ? ": " : "",
+ (unsigned long) size);
+#endif /* __MINGW32__ */
xexit (1);
}
return (newmem);