m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: 58-gary-gnulib-error-import.patch


From: Gary V. Vaughan
Subject: FYI: 58-gary-gnulib-error-import.patch
Date: Tue, 09 Sep 2003 18:23:26 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5b) Gecko/20030903 Thunderbird/0.2

Applied to HEAD.
--
  ())_.  Gary V. Vaughan    gary@(oranda.demon.co.uk|gnu.org)
  ( '/   Research Scientist http://www.oranda.demon.co.uk       ,_())____
  / )=   GNU Hacker         http://www.gnu.org/software/libtool  \'      `&
`(_~)_   Tech' Author       http://sources.redhat.com/autobook   =`---d__/
Index: ChangeLog
from  Gary V. Vaughan  <address@hidden>
        Import the error and progname modules from CVS gnulib.  Our old
        error.c subsumed the functionality of both, so a little adjustment
        was required to accomodate the split in sources.  Also added more
        wrapper macros to choose between a system installed error.h or our
        shipped gnulib error module:

        * m4/error.c, m4/error.h: Removed.
        * m4/Makefile.am: Adjust.
        (pkgincdir): Removed.  Use pkgincludedir instead.
        * m4/module.h, src/main.c: Don't include `m4/error.h'.
        * m4/system_.h (INCLUDE_ERROR_H): Add a substitution for suitable
        error.h.
        * gnulib/m4/progname.c: Imported from CVS gnulib.
        * gnulib/m4/progname.h: Ditto.
        * src/main.c: Adjust to use progname module.
        * gnulib/m4/error.c: Imported from CVS gnulib.
        * gnulib/m4/error_.h: Ditto.
        * gnulib/m4/Makefile.am: Build the error module into our libgnu.la
        if appropriate, and link a local error.h if the system version is
        missing.
        (libgnu_la_SOURCES) Add progname module sources.
        * gnulib/config/error.m4: Imported from CVS gnulib.
        * gnulib/config/strerror_r.m4: Ditto.
        * config/m4-error.c: New file.  Wrap gnulib error.m4 but arrange
        to have ERROR_H for Makefile substitutions and tell system.h
        whether the system error.h should be used, or a locally installed
        version.
        * configure.ac (jm_PREREQ_ERROR): Replaced by a call to m4_ERROR.

2003-09-09  Gary V. Vaughan  <address@hidden>

Index: configure.ac
===================================================================
RCS file: /cvsroot/m4/m4/configure.ac,v
retrieving revision 1.17
diff -u -p -u -r1.17 configure.ac
--- configure.ac 9 Sep 2003 14:08:26 -0000 1.17
+++ configure.ac 9 Sep 2003 17:14:10 -0000
@@ -184,8 +184,7 @@ AC_FUNC_VPRINTF
 
 AM_WITH_DMALLOC
 
-jm_PREREQ_ERROR
-
+m4_ERROR
 m4_OBSTACK
 m4_SYS_STACKOVF
 
Index: config/m4-error.m4
===================================================================
RCS file: config/m4-error.m4
diff -N config/m4-error.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ config/m4-error.m4 9 Sep 2003 17:14:10 -0000
@@ -0,0 +1,41 @@
+#                                                            -*- Autoconf -*-
+# m4-error.m4 -- Use the installed version of error.h if available.
+#
+# Copyright (C) 2003 Free Software Foundation, Inc
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# Written by Gary V. Vaughan <address@hidden>
+
+# serial 1
+
+# m4_ERROR
+# --------
+# Use the installed version of error.h if available.
+AC_DEFUN([m4_ERROR],
+[AC_REQUIRE([gl_ERROR])
+
+AC_CHECK_HEADERS([error.h],
+    [ERROR_H=""], [ERROR_H="error.h"], [AC_INCLUDES_DEFAULT])
+AC_SUBST(ERROR_H)
+
+if test $ac_cv_header_error_h = yes; then
+  INCLUDE_ERROR_H='#include <error.h>'
+else
+  INCLUDE_ERROR_H='#include <m4/error.h>'
+fi
+AC_SUBST([INCLUDE_ERROR_H])
+])# m4_ERROR
Index: gnulib/config/error.m4
===================================================================
RCS file: gnulib/config/error.m4
diff -N gnulib/config/error.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnulib/config/error.m4 9 Sep 2003 17:14:10 -0000
@@ -0,0 +1,18 @@
+#serial 7
+
+AC_DEFUN([gl_ERROR],
+[
+  AC_FUNC_ERROR_AT_LINE
+  dnl Note: AC_FUNC_ERROR_AT_LINE does AC_LIBSOURCES([error.h, error.c]).
+  jm_PREREQ_ERROR
+])
+
+# Prerequisites of lib/error.c.
+AC_DEFUN([jm_PREREQ_ERROR],
+[
+  AC_REQUIRE([AC_HEADER_STDC])
+  AC_REQUIRE([AC_FUNC_VPRINTF])
+  AC_CHECK_FUNCS(strerror)
+  AC_CHECK_DECLS([strerror])
+  AC_FUNC_STRERROR_R
+])
Index: gnulib/config/strerror_r.m4
===================================================================
RCS file: gnulib/config/strerror_r.m4
diff -N gnulib/config/strerror_r.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnulib/config/strerror_r.m4 9 Sep 2003 17:14:10 -0000
@@ -0,0 +1,59 @@
+#serial 1003
+# Experimental replacement for the function in the latest CVS autoconf.
+# Use with the error.c file in ../lib.
+
+# Copyright 2001 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+undefine([AC_FUNC_STRERROR_R])
+
+# AC_FUNC_STRERROR_R
+# ------------------
+AC_DEFUN([AC_FUNC_STRERROR_R],
+[AC_CHECK_DECLS([strerror_r])
+AC_CHECK_FUNCS([strerror_r])
+AC_CACHE_CHECK([whether strerror_r returns char *],
+               ac_cv_func_strerror_r_char_p,
+   [
+    ac_cv_func_strerror_r_char_p=no
+    if test $ac_cv_have_decl_strerror_r = yes; then
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
+       [[
+         char buf[100];
+         char x = *strerror_r (0, buf, sizeof buf);
+         char *p = strerror_r (0, buf, sizeof buf);
+       ]])],
+                       ac_cv_func_strerror_r_char_p=yes)
+    else
+      # strerror_r is not declared.  Choose between
+      # systems that have relatively inaccessible declarations for the
+      # function.  BeOS and DEC UNIX 4.0 fall in this category, but the
+      # former has a strerror_r that returns char*, while the latter
+      # has a strerror_r that returns `int'.
+      # This test should segfault on the DEC system.
+      AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
+       extern char *strerror_r ();],
+       [[char buf[100];
+         char x = *strerror_r (0, buf, sizeof buf);
+         exit (!isalpha (x));]])],
+                    ac_cv_func_strerror_r_char_p=yes, , :)
+    fi
+  ])
+if test $ac_cv_func_strerror_r_char_p = yes; then
+  AC_DEFINE([STRERROR_R_CHAR_P], 1,
+           [Define to 1 if strerror_r returns char *.])
+fi
+])# AC_FUNC_STRERROR_R
Index: gnulib/m4/Makefile.am
===================================================================
RCS file: /cvsroot/m4/m4/gnulib/m4/Makefile.am,v
retrieving revision 1.3
diff -u -p -u -r1.3 Makefile.am
--- gnulib/m4/Makefile.am 9 Sep 2003 15:08:36 -0000 1.3
+++ gnulib/m4/Makefile.am 9 Sep 2003 17:14:10 -0000
@@ -38,6 +38,17 @@ MAINTAINERCLEANFILES = Makefile.in
 # Gnulib Makefile.am snippets #
 # --------------------------- #
 
+## error: (not yet in gnulib)
+BUILT_SOURCES += $(ERROR_H)
+EXTRA_DIST += error_.h
+
+all-local $(lib_OBJECTS): $(ERROR_H)
+error.h: error_.h
+       rm -f $@ && $(LN_S) error_.h $@
+
+MOSTLYCLEANFILES += error.h
+
+
 ## gettext: (not yet in gnulib)
 BUILT_SOURCES += $(GETTEXT_H)
 EXTRA_DIST += gettext_.h
@@ -58,6 +69,10 @@ obstack.h: obstack_.h
        rm -f $@ && $(LN_S) obstack_.h $@
 
 MOSTLYCLEANFILES += obstack.h
+
+
+## progname:
+libgnu_la_SOURCES += progname.c progname.h
 
 
 ## stdbool:
Index: gnulib/m4/error.c
===================================================================
RCS file: gnulib/m4/error.c
diff -N gnulib/m4/error.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnulib/m4/error.c 9 Sep 2003 17:14:10 -0000
@@ -0,0 +1,389 @@
+/* Error handler for noninteractive utilities
+   Copyright (C) 1990-1998, 2000, 2001, 2002, 2003 Free Software Foundation, 
Inc.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* Written by David MacKenzie <address@hidden>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "gettext.h"
+#endif
+
+#ifdef _LIBC
+# include <wchar.h>
+# define mbsrtowcs __mbsrtowcs
+#endif
+
+#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
+# if __STDC__
+#  include <stdarg.h>
+#  define VA_START(args, lastarg) va_start(args, lastarg)
+# else
+#  include <varargs.h>
+#  define VA_START(args, lastarg) va_start(args)
+# endif
+#else
+# define va_alist a1, a2, a3, a4, a5, a6, a7, a8
+# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
+#endif
+
+#if STDC_HEADERS || _LIBC
+# include <stdlib.h>
+# include <string.h>
+#else
+void exit ();
+#endif
+
+#include "error.h"
+
+#if !_LIBC
+# include "unlocked-io.h"
+#endif
+
+#ifndef _
+# define _(String) String
+#endif
+
+/* If NULL, error will flush stdout, then print on stderr the program
+   name, a colon and a space.  Otherwise, error will call this
+   function without parameters instead.  */
+void (*error_print_progname) (
+#if __STDC__ - 0
+                             void
+#endif
+                             );
+
+/* This variable is incremented each time `error' is called.  */
+unsigned int error_message_count;
+
+#ifdef _LIBC
+/* In the GNU C library, there is a predefined variable for this.  */
+
+# define program_name program_invocation_name
+# include <errno.h>
+# include <libio/libioP.h>
+
+/* In GNU libc we want do not want to use the common name `error' directly.
+   Instead make it a weak alias.  */
+extern void __error (int status, int errnum, const char *message, ...)
+     __attribute__ ((__format__ (__printf__, 3, 4)));
+extern void __error_at_line (int status, int errnum, const char *file_name,
+                            unsigned int line_number, const char *message,
+                            ...)
+     __attribute__ ((__format__ (__printf__, 5, 6)));;
+# define error __error
+# define error_at_line __error_at_line
+
+# include <libio/iolibio.h>
+# define fflush(s) INTUSE(_IO_fflush) (s)
+# undef putc
+# define putc(c, fp) INTUSE(_IO_putc) (c, fp)
+
+#else /* not _LIBC */
+
+# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
+#  ifndef HAVE_DECL_STRERROR_R
+"this configure-time declaration test was not run"
+#  endif
+char *strerror_r ();
+# endif
+
+/* The calling program should define program_name and set it to the
+   name of the executing program.  */
+extern char *program_name;
+
+# if HAVE_STRERROR_R || defined strerror_r
+#  define __strerror_r strerror_r
+# else
+#  if HAVE_STRERROR
+#   ifndef HAVE_DECL_STRERROR
+"this configure-time declaration test was not run"
+#   endif
+#   if !HAVE_DECL_STRERROR
+char *strerror ();
+#   endif
+#  else
+static char *
+private_strerror (int errnum)
+{
+  extern char *sys_errlist[];
+  extern int sys_nerr;
+
+  if (errnum > 0 && errnum <= sys_nerr)
+    return _(sys_errlist[errnum]);
+  return _("Unknown system error");
+}
+#   define strerror private_strerror
+#  endif /* HAVE_STRERROR */
+# endif        /* HAVE_STRERROR_R || defined strerror_r */
+#endif /* not _LIBC */
+
+static void
+print_errno_message (int errnum)
+{
+  char const *s;
+
+#if defined HAVE_STRERROR_R || _LIBC
+  char errbuf[1024];
+# if STRERROR_R_CHAR_P || _LIBC
+  s = __strerror_r (errnum, errbuf, sizeof errbuf);
+# else
+  if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
+    s = errbuf;
+  else
+    s = 0;
+# endif
+#else
+  s = strerror (errnum);
+#endif
+
+#if !_LIBC
+  if (! s)
+    s = _("Unknown system error");
+#endif
+
+#if _LIBC
+  if (_IO_fwide (stderr, 0) > 0)
+    {
+      __fwprintf (stderr, L": %s", s);
+      return;
+    }
+#endif
+
+  fprintf (stderr, ": %s", s);
+}
+
+#ifdef VA_START
+static void
+error_tail (int status, int errnum, const char *message, va_list args)
+{
+# if HAVE_VPRINTF || _LIBC
+#  if _LIBC
+  if (_IO_fwide (stderr, 0) > 0)
+    {
+#   define ALLOCA_LIMIT        2000
+      size_t len = strlen (message) + 1;
+      wchar_t *wmessage = NULL;
+      mbstate_t st;
+      size_t res;
+      const char *tmp;
+
+      do
+       {
+         if (len < ALLOCA_LIMIT)
+           wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
+         else
+           {
+             if (wmessage != NULL && len / 2 < ALLOCA_LIMIT)
+               wmessage = NULL;
+
+             wmessage = (wchar_t *) realloc (wmessage,
+                                             len * sizeof (wchar_t));
+
+             if (wmessage == NULL)
+               {
+                 fputws_unlocked (L"out of memory\n", stderr);
+                 return;
+               }
+           }
+
+         memset (&st, '\0', sizeof (st));
+         tmp =message;
+       }
+      while ((res = mbsrtowcs (wmessage, &tmp, len, &st)) == len);
+
+      if (res == (size_t) -1)
+       /* The string cannot be converted.  */
+       wmessage = (wchar_t *) L"???";
+
+      __vfwprintf (stderr, wmessage, args);
+    }
+  else
+#  endif
+    vfprintf (stderr, message, args);
+# else
+  _doprnt (message, args, stderr);
+# endif
+  va_end (args);
+
+  ++error_message_count;
+  if (errnum)
+    print_errno_message (errnum);
+# if _LIBC
+  if (_IO_fwide (stderr, 0) > 0)
+    putwc (L'\n', stderr);
+  else
+# endif
+    putc ('\n', stderr);
+  fflush (stderr);
+  if (status)
+    exit (status);
+}
+#endif
+
+
+/* Print the program name and error message MESSAGE, which is a printf-style
+   format string with optional args.
+   If ERRNUM is nonzero, print its corresponding system error message.
+   Exit with status STATUS if it is nonzero.  */
+/* VARARGS */
+void
+#if defined VA_START && __STDC__
+error (int status, int errnum, const char *message, ...)
+#else
+error (status, errnum, message, va_alist)
+     int status;
+     int errnum;
+     char *message;
+     va_dcl
+#endif
+{
+#ifdef VA_START
+  va_list args;
+#endif
+
+  fflush (stdout);
+#ifdef _LIBC
+  _IO_flockfile (stderr);
+#endif
+  if (error_print_progname)
+    (*error_print_progname) ();
+  else
+    {
+#if _LIBC
+      if (_IO_fwide (stderr, 0) > 0)
+       __fwprintf (stderr, L"%s: ", program_name);
+      else
+#endif
+       fprintf (stderr, "%s: ", program_name);
+    }
+
+#ifdef VA_START
+  VA_START (args, message);
+  error_tail (status, errnum, message, args);
+#else
+  fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
+
+  ++error_message_count;
+  if (errnum)
+    print_errno_message (errnum);
+  putc ('\n', stderr);
+  fflush (stderr);
+  if (status)
+    exit (status);
+#endif
+
+#ifdef _LIBC
+  _IO_funlockfile (stderr);
+#endif
+}
+
+/* Sometimes we want to have at most one error per line.  This
+   variable controls whether this mode is selected or not.  */
+int error_one_per_line;
+
+void
+#if defined VA_START && __STDC__
+error_at_line (int status, int errnum, const char *file_name,
+              unsigned int line_number, const char *message, ...)
+#else
+error_at_line (status, errnum, file_name, line_number, message, va_alist)
+     int status;
+     int errnum;
+     const char *file_name;
+     unsigned int line_number;
+     char *message;
+     va_dcl
+#endif
+{
+#ifdef VA_START
+  va_list args;
+#endif
+
+  if (error_one_per_line)
+    {
+      static const char *old_file_name;
+      static unsigned int old_line_number;
+
+      if (old_line_number == line_number
+         && (file_name == old_file_name
+             || strcmp (old_file_name, file_name) == 0))
+       /* Simply return and print nothing.  */
+       return;
+
+      old_file_name = file_name;
+      old_line_number = line_number;
+    }
+
+  fflush (stdout);
+#ifdef _LIBC
+  _IO_flockfile (stderr);
+#endif
+  if (error_print_progname)
+    (*error_print_progname) ();
+  else
+    {
+#if _LIBC
+      if (_IO_fwide (stderr, 0) > 0)
+       __fwprintf (stderr, L"%s: ", program_name);
+      else
+#endif
+       fprintf (stderr, "%s:", program_name);
+    }
+
+  if (file_name != NULL)
+    {
+#if _LIBC
+      if (_IO_fwide (stderr, 0) > 0)
+       __fwprintf (stderr, L"%s:%d: ", file_name, line_number);
+      else
+#endif
+       fprintf (stderr, "%s:%d: ", file_name, line_number);
+    }
+
+#ifdef VA_START
+  VA_START (args, message);
+  error_tail (status, errnum, message, args);
+#else
+  fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
+
+  ++error_message_count;
+  if (errnum)
+    print_errno_message (errnum);
+  putc ('\n', stderr);
+  fflush (stderr);
+  if (status)
+    exit (status);
+#endif
+
+#ifdef _LIBC
+  _IO_funlockfile (stderr);
+#endif
+}
+
+#ifdef _LIBC
+/* Make the weak alias.  */
+# undef error
+# undef error_at_line
+weak_alias (__error, error)
+weak_alias (__error_at_line, error_at_line)
+#endif
Index: gnulib/m4/error_.h
===================================================================
RCS file: gnulib/m4/error_.h
diff -N gnulib/m4/error_.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnulib/m4/error_.h 9 Sep 2003 17:14:10 -0000
@@ -0,0 +1,78 @@
+/* Declaration for error-reporting function
+   Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+
+
+   NOTE: The canonical source of this file is maintained with the GNU C 
Library.
+   Bugs can be reported to address@hidden
+
+   This program is free software; you can redistribute 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.  */
+
+#ifndef _ERROR_H
+#define _ERROR_H 1
+
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+#  define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#  define __format__ format
+#  define __printf__ printf
+# endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined (__STDC__) && __STDC__
+
+/* Print a message with `fprintf (stderr, FORMAT, ...)';
+   if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
+   If STATUS is nonzero, terminate the program with `exit (STATUS)'.  */
+
+extern void error (int status, int errnum, const char *format, ...)
+     __attribute__ ((__format__ (__printf__, 3, 4)));
+
+extern void error_at_line (int status, int errnum, const char *fname,
+                          unsigned int lineno, const char *format, ...)
+     __attribute__ ((__format__ (__printf__, 5, 6)));
+
+/* If NULL, error will flush stdout, then print on stderr the program
+   name, a colon and a space.  Otherwise, error will call this
+   function without parameters instead.  */
+extern void (*error_print_progname) (void);
+
+#else
+void error ();
+void error_at_line ();
+extern void (*error_print_progname) ();
+#endif
+
+/* This variable is incremented each time `error' is called.  */
+extern unsigned int error_message_count;
+
+/* Sometimes we want to have at most one error per line.  This
+   variable controls whether this mode is selected or not.  */
+extern int error_one_per_line;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* error.h */
Index: gnulib/m4/progname.c
===================================================================
RCS file: gnulib/m4/progname.c
diff -N gnulib/m4/progname.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnulib/m4/progname.c 9 Sep 2003 17:14:10 -0000
@@ -0,0 +1,53 @@
+/* Program name management.
+   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Written by Bruno Haible <address@hidden>, 2001.
+
+   This program is free software; you can redistribute 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.  */
+
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+/* Specification.  */
+#include "progname.h"
+
+#include <string.h>
+
+#undef set_program_name
+
+
+/* String containing name the program is called with.
+   To be initialized by main().  */
+const char *program_name;
+
+/* Set program_name, based on argv[0].  */
+void
+set_program_name (const char *argv0)
+{
+  /* libtool creates a temporary executable whose name is sometimes prefixed
+     with "lt-" (depends on the platform).  It also makes argv[0] absolute.
+     Remove this "<dirname>/.libs/" or "<dirname>/.libs/lt-" prefix here.  */
+  const char *slash;
+  const char *base;
+
+  slash = strrchr (argv0, '/');
+  base = (slash != NULL ? slash + 1 : argv0);
+  if (base - argv0 >= 7 && memcmp (base - 7, "/.libs/", 7) == 0)
+    argv0 = base;
+  if (strncmp (base, "lt-", 3) == 0)
+    argv0 = base + 3;
+  program_name = argv0;
+}
Index: gnulib/m4/progname.h
===================================================================
RCS file: gnulib/m4/progname.h
diff -N gnulib/m4/progname.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnulib/m4/progname.h 9 Sep 2003 17:14:10 -0000
@@ -0,0 +1,50 @@
+/* Program name management.
+   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Written by Bruno Haible <address@hidden>, 2001.
+
+   This program is free software; you can redistribute 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.  */
+
+#ifndef _PROGNAME_H
+#define _PROGNAME_H
+
+#include <stdbool.h>
+
+/* Programs using this file should do the following in main():
+     set_program_name (argv[0]);
+ */
+
+/* String containing name the program is called with.  */
+extern const char *program_name;
+
+/* Set program_name, based on argv[0].  */
+extern void set_program_name (const char *argv0);
+
+#if ENABLE_RELOCATABLE
+
+/* Set program_name, based on argv[0], and original installation prefix and
+   directory, for relocatability.  */
+extern void set_program_name_and_installdir (const char *argv0,
+                                            const char *orig_installprefix,
+                                            const char *orig_installdir);
+#define set_program_name(ARG0) \
+  set_program_name_and_installdir (ARG0, INSTALLPREFIX, INSTALLDIR)
+
+/* Return the full pathname of the current executable, based on the earlier
+   call to set_program_name_and_installdir.  Return NULL if unknown.  */
+extern char *get_full_program_name (void);
+
+#endif
+
+#endif /* _PROGNAME_H */
Index: m4/Makefile.am
===================================================================
RCS file: /cvsroot/m4/m4/m4/Makefile.am,v
retrieving revision 1.22
diff -u -p -u -r1.22 Makefile.am
--- m4/Makefile.am 5 Sep 2003 18:32:26 -0000 1.22
+++ m4/Makefile.am 9 Sep 2003 17:14:10 -0000
@@ -21,7 +21,7 @@ AM_CPPFLAGS   = -I$(top_builddir)/gnulib -
                  -I$(top_builddir) -I$(top_srcdir) $(INTLINCL)
 
 lib_LTLIBRARIES                = libm4.la
-libm4_la_SOURCES       = builtin.c debug.c error.c hash.c input.c \
+libm4_la_SOURCES       = builtin.c debug.c hash.c input.c \
                          ltdl.c m4.c m4private.h macro.c module.c output.c \
                          path.c regex.c symtab.c syntax.c utility.c
 libm4_la_LIBADD                = $(top_builddir)/gnulib/m4/libgnu.la 
$(LIBADD_DL)
@@ -36,9 +36,8 @@ EXTRA_DIST    = system_.h
 dist-hook:
        rm -f $(distdir)/system.h
 
-pkgincdir      = $(includedir)/@PACKAGE@
-pkginc_HEADERS = error.h hash.h ltdl.h regex.h system.h
-include_HEADERS        = m4module.h
+pkginclude_HEADERS     = hash.h ltdl.h regex.h system.h
+include_HEADERS                = m4module.h
 
 CLEANFILES             = pathconf.h
 MAINTAINERCLEANFILES   = Makefile.in
Index: m4/error.c
===================================================================
RCS file: m4/error.c
diff -N m4/error.c
--- m4/error.c 27 Aug 2003 17:10:12 -0000 1.4
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,250 +0,0 @@
-/* Error handler for noninteractive utilities
-   Copyright (C) 1990-98,2000 Free Software Foundation, Inc.
-
-   This file is part of the GNU C Library.  Its master source is NOT part of
-   the C library, however.  The master source lives in /gd/gnu/lib.
-
-   The GNU C Library 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 of the
-   License, or (at your option) any later version.
-
-   The GNU C 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
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
-
-/* Written by David MacKenzie <address@hidden>.  */
-/* Modified for GNU m4 by Gary V. Vaughan <address@hidden> */
-
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-
-#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
-# if __STDC__
-#  include <stdarg.h>
-#  define VA_START(args, lastarg) va_start(args, lastarg)
-# else
-#  include <varargs.h>
-#  define VA_START(args, lastarg) va_start(args)
-# endif
-#else
-# define va_alist a1, a2, a3, a4, a5, a6, a7, a8
-# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
-#endif
-
-#if STDC_HEADERS || _LIBC
-# include <stdlib.h>
-# include <string.h>
-#else
-void exit ();
-#endif
-
-/* Get prototypes for the functions defined here.  */
-#include "error.h"
-
-/* If NULL, error will flush stdout, then print on stderr the program
-   name, a colon and a space.  Otherwise, error will call this
-   function without parameters instead.  */
-void (*error_print_progname) (
-#if __STDC__ - 0
-                             void
-#endif
-                             );
-
-/* This variable is incremented each time `error' is called.  */
-unsigned int error_message_count;
-
-#ifdef _LIBC
-/* In the GNU C library, there is a predefined variable for this.  */
-
-# define program_name program_invocation_name
-# include <errno.h>
-
-/* In GNU libc we want do not want to use the common name `error' directly.
-   Instead make it a weak alias.  */
-# define error __error
-# define error_at_line __error_at_line
-
-# ifdef USE_IN_LIBIO
-# include <libio/iolibio.h>
-#  define fflush(s) _IO_fflush (s)
-# endif
-
-#else /* not _LIBC */
-
-/* The calling program should define program_name and set it to the
-   name of the executing program.  */
-char *program_name;
-
-# ifdef HAVE_STRERROR_R
-#  define __strerror_r strerror_r
-# else
-#  if HAVE_STRERROR
-#   ifndef strerror            /* On some systems, strerror is a macro */
-char *strerror ();
-#   endif
-#  else
-static char *
-private_strerror (errnum)
-     int errnum;
-{
-  extern char *sys_errlist[];
-  extern int sys_nerr;
-
-  if (errnum > 0 && errnum <= sys_nerr)
-    return _(sys_errlist[errnum]);
-  return _("Unknown system error");
-}
-#   define strerror private_strerror
-#  endif /* HAVE_STRERROR */
-# endif        /* HAVE_STRERROR_R */
-#endif /* not _LIBC */
-
-/* Print the program name and error message MESSAGE, which is a printf-style
-   format string with optional args.
-   If ERRNUM is nonzero, print its corresponding system error message.
-   Exit with status STATUS if it is nonzero.  */
-/* VARARGS */
-
-void
-#if defined VA_START && __STDC__
-error (int status, int errnum, const char *message, ...)
-#else
-error (status, errnum, message, va_alist)
-     int status;
-     int errnum;
-     char *message;
-     va_dcl
-#endif
-{
-#ifdef VA_START
-  va_list args;
-#endif
-
-  if (error_print_progname)
-    (*error_print_progname) ();
-  else
-    {
-      fflush (stdout);
-      fprintf (stderr, "%s: ", program_name);
-    }
-
-#ifdef VA_START
-  VA_START (args, message);
-# if HAVE_VPRINTF || _LIBC
-  vfprintf (stderr, message, args);
-# else
-  _doprnt (message, args, stderr);
-# endif
-  va_end (args);
-#else
-  fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
-#endif
-
-  ++error_message_count;
-  if (errnum)
-    {
-#if defined HAVE_STRERROR_R || defined _LIBC
-      char errbuf[1024];
-      fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
-#else
-      fprintf (stderr, ": %s", strerror (errnum));
-#endif
-    }
-  putc ('\n', stderr);
-  fflush (stderr);
-  if (status)
-    exit (status);
-}
-
-/* Sometimes we want to have at most one error per line.  This
-   variable controls whether this mode is selected or not.  */
-int error_one_per_line;
-
-void
-#if defined VA_START && __STDC__
-error_at_line (int status, int errnum, const char *file_name,
-              unsigned int line_number, const char *message, ...)
-#else
-error_at_line (status, errnum, file_name, line_number, message, va_alist)
-     int status;
-     int errnum;
-     const char *file_name;
-     unsigned int line_number;
-     char *message;
-     va_dcl
-#endif
-{
-#ifdef VA_START
-  va_list args;
-#endif
-
-  if (error_one_per_line)
-    {
-      static const char *old_file_name;
-      static unsigned int old_line_number;
-
-      if (old_line_number == line_number &&
-         (file_name == old_file_name || !strcmp (old_file_name, file_name)))
-       /* Simply return and print nothing.  */
-       return;
-
-      old_file_name = file_name;
-      old_line_number = line_number;
-    }
-
-  if (error_print_progname)
-    (*error_print_progname) ();
-  else
-    {
-      fflush (stdout);
-      fprintf (stderr, "%s:", program_name);
-    }
-
-  if (file_name != NULL)
-    fprintf (stderr, "%s:%d: ", file_name, line_number);
-
-#ifdef VA_START
-  VA_START (args, message);
-# if HAVE_VPRINTF || _LIBC
-  vfprintf (stderr, message, args);
-# else
-  _doprnt (message, args, stderr);
-# endif
-  va_end (args);
-#else
-  fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
-#endif
-
-  ++error_message_count;
-  if (errnum)
-    {
-#if defined HAVE_STRERROR_R || defined _LIBC
-      char errbuf[1024];
-      fprintf (stderr, ": %s", __strerror_r (errnum, errbuf, sizeof errbuf));
-#else
-      fprintf (stderr, ": %s", strerror (errnum));
-#endif
-    }
-  putc ('\n', stderr);
-  fflush (stderr);
-  if (status)
-    exit (status);
-}
-
-#ifdef _LIBC
-/* Make the weak alias.  */
-# undef error
-# undef error_at_line
-weak_alias (__error, error)
-weak_alias (__error_at_line, error_at_line)
-#endif
Index: m4/error.h
===================================================================
RCS file: m4/error.h
diff -N m4/error.h
--- m4/error.h 27 Aug 2003 17:10:12 -0000 1.5
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,77 +0,0 @@
-/* Declaration for error-reporting function
-   Copyright (C) 1995-1997, 2000, 2003 Free Software Foundation, Inc.
-
-   This file is part of the GNU C Library.  Its master source is NOT part of
-   the C library, however.  The master source lives in /gd/gnu/lib.
-
-   The GNU C Library 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 of the
-   License, or (at your option) any later version.
-
-   The GNU C 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
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
-
-/* Modified for GNU m4 by Gary V. Vaughan <address@hidden> */
-
-#ifndef M4_ERROR_H
-#define M4_ERROR_H 1
-
-#include <m4/system.h>
-
-BEGIN_C_DECLS
-
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
-#  define __attribute__(Spec) /* empty */
-# endif
-/* The __-protected variants of `format' and `printf' attributes
-   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-#  define __format__ format
-#  define __printf__ printf
-# endif
-#endif
-
-#if defined (__STDC__) && __STDC__
-
-/* Print a message with `fprintf (stderr, FORMAT, ...)';
-   if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
-   If STATUS is nonzero, terminate the program with `exit (STATUS)'.  */
-
-extern void error (int status, int errnum, const char *format, ...)
-     __attribute__ ((__format__ (__printf__, 3, 4)));
-
-extern void error_at_line (int status, int errnum, const char *fname,
-                          unsigned int lineno, const char *format, ...)
-     __attribute__ ((__format__ (__printf__, 5, 6)));
-
-/* If NULL, error will flush stdout, then print on stderr the program
-   name, a colon and a space.  Otherwise, error will call this
-   function without parameters instead.  */
-extern void (*error_print_progname) (void);
-
-#else
-extern void error ();
-extern void error_at_line ();
-extern void (*error_print_progname) ();
-#endif
-
-/* This variable is incremented each time `error' is called.  */
-extern unsigned int error_message_count;
-
-/* Sometimes we want to have at most one error per line.  This
-   variable controls whether this mode is selected or not.  */
-extern int error_one_per_line;
-
-END_C_DECLS
-
-#endif /* !M4_ERROR_H */
Index: m4/m4module.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4module.h,v
retrieving revision 1.68
diff -u -p -u -r1.68 m4module.h
--- m4/m4module.h 27 Aug 2003 17:10:12 -0000 1.68
+++ m4/m4module.h 9 Sep 2003 17:14:10 -0000
@@ -21,7 +21,6 @@
 #define M4MODULE_H 1
 
 #include <m4/system.h>
-#include <m4/error.h>
 #include <m4/ltdl.h>
 #include <m4/hash.h>
 
Index: m4/system_.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/system_.h,v
retrieving revision 1.1
diff -u -p -u -r1.1 system_.h
--- m4/system_.h 29 Aug 2003 17:44:48 -0000 1.1
+++ m4/system_.h 9 Sep 2003 17:14:10 -0000
@@ -30,6 +30,7 @@
 /* I have yet to see a system that doesn't have these... */
 #include <stdio.h>
 #include <sys/types.h>
address@hidden@
 @INCLUDE_OBSTACK_H@
 @INCLUDE_STDBOOL_H@
 
Index: src/main.c
===================================================================
RCS file: /cvsroot/m4/m4/src/main.c,v
retrieving revision 1.50
diff -u -p -u -r1.50 main.c
--- src/main.c 27 Aug 2003 17:10:13 -0000 1.50
+++ src/main.c 9 Sep 2003 17:14:10 -0000
@@ -22,16 +22,7 @@
 
 #include "m4.h"
 #include "m4private.h"
-#include "error.h"
-
-/* The name this program was run with. */
-#ifdef _LIBC
-  /* In the GNU C library, there is a predefined variable for this.  */
-#  define program_name program_invocation_name
-#endif
-
-/* This will be provided either by GNU libc, or error.c. */
-extern const char *program_name;
+#include "m4/progname.h"
 
 static void print_program_name_CB (void);
 
@@ -226,7 +217,7 @@ main (int argc, char *const *argv, char 
 
   int exit_status;
 
-  program_name = argv[0];
+  set_program_name (argv[0]);
   error_print_progname = print_program_name_CB;
 
   setlocale (LC_ALL, "");

reply via email to

[Prev in Thread] Current Thread [Next in Thread]