Sync getopt from gnulib.
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 20 Aug 2004 02:10:15 +0000 (02:10 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 20 Aug 2004 02:10:15 +0000 (02:10 +0000)
lib/.cvsignore
lib/ChangeLog
lib/Makefile.am
lib/getopt.c
lib/getopt1.c
lib/getopt_.h [moved from lib/getopt.h with 98% similarity]
lib/getopt_int.h
m4/ChangeLog
m4/getopt.m4

index c5a94a3..b03b347 100644 (file)
@@ -4,6 +4,7 @@ alloca.h
 charset.alias
 getdate.c
 getdate.tab.c
+getopt.h
 fnmatch.h
 fts.h
 lstat.c
index 97296b6..acbaa7b 100644 (file)
@@ -1,3 +1,14 @@
+2004-08-19  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * getopt.c, getopt1.c: Sync from gnulib.
+       * getopt_.h: Renamed from getopt.h (this syncs from gnulib).
+       * Makefile.am (libfetish_a_SOURCES): Remove getopt.c, getopt.h,
+       getopt1.c, getopt_int.h.
+       (BUILT_SOURCES, EXTRA_DIST, all-local, $(lib_OBJECTS), getopt.h,
+       MOSTLYCLEANFILES): Add current gnulib snippet for getopt.
+       * .cppi-disable: Add getopt_.h, getopt_int.h.
+       * .cvsignore: Add getopt.h.
+
 2004-08-18  Paul Eggert  <eggert@cs.ucla.edu>
 
        * userspec.c: Don't use <alloca.h>, so that we don't use alloca on
index 386194c..e5a776b 100644 (file)
@@ -33,7 +33,6 @@ libfetish_a_SOURCES = \
   posixtm.c posixtm.h \
   posixver.c posixver.h \
   strftime.c strftime.h \
-  getopt.c getopt.h getopt1.c getopt_int.h \
   hash.c hash.h \
   hash-pjw.c hash-pjw.h \
   __fpending.h \
@@ -239,3 +238,14 @@ fnmatch.h: fnmatch_.h
        cp $(srcdir)/fnmatch_.h $@-t
        mv $@-t $@
 MOSTLYCLEANFILES += fnmatch.h fnmatch.h-t
+
+BUILT_SOURCES += $(GETOPT_H)
+EXTRA_DIST += getopt_.h getopt_int.h
+
+# We need the following in order to create an <getopt.h> when the system
+# doesn't have one that works with the given compiler.
+all-local $(lib_OBJECTS): $(GETOPT_H)
+getopt.h: getopt_.h
+       cp $(srcdir)/getopt_.h $@-t
+       mv $@-t $@
+MOSTLYCLEANFILES += getopt.h getopt.h-t
index afc2848..95b3604 100644 (file)
@@ -3,7 +3,7 @@
    "Keep this file name-space clean" means, talk to drepper@gnu.org
    before changing it!
    Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002,2003,2004
-       Free Software Foundation, Inc.
+       Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    This program is free software; you can redistribute it and/or modify
 
 #include <stdio.h>
 
-/* Comment out all this code if we are using the GNU C Library, and are not
-   actually compiling the library itself.  This code is part of the GNU C
-   Library, but also included in many other GNU distributions.  Compiling
-   and linking in this code is a waste when using the GNU C library
-   (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.  */
-
-#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__
@@ -1181,7 +1162,6 @@ getopt (int argc, char *const *argv, const char *optstring)
                           0);
 }
 
-#endif /* Not ELIDE_CODE.  */
 \f
 #ifdef TEST
 
index 7671eba..706f59c 100644 (file)
 
 #include <stdio.h>
 
-/* Comment out all this code if we are using the GNU C Library, and are not
-   actually compiling the library itself.  This code is part of the GNU C
-   Library, but also included in many other GNU distributions.  Compiling
-   and linking in this code is a waste when using the GNU C library
-   (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.  */
-
-#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__
@@ -96,7 +77,6 @@ _getopt_long_only_r (int argc, char *const *argv, const char *options,
                             1, d);
 }
 
-#endif /* Not ELIDE_CODE.  */
 \f
 #ifdef TEST
 
similarity index 98%
rename from lib/getopt.h
rename to lib/getopt_.h
index 9774110..c61768c 100644 (file)
@@ -89,7 +89,7 @@ extern int optopt;
    The field `has_arg' is:
    no_argument         (or 0) if the option does not take an argument,
    required_argument   (or 1) if the option requires an argument,
-   optional_argument   (or 2) if the option takes an optional argument.
+   optional_argument   (or 2) if the option takes an optional argument.
 
    If the field `flag' is not NULL, it points to a variable that is set
    to the value given in the field `val' when the option is found, but
index 36b711e..0c5edde 100644 (file)
@@ -18,7 +18,7 @@
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #ifndef _GETOPT_INT_H
-# define _GETOPT_INT_H 1
+#define _GETOPT_INT_H  1
 
 extern int _getopt_internal (int ___argc, char *const *___argv,
                             const char *__shortopts,
@@ -100,7 +100,7 @@ struct _getopt_data
   int __first_nonopt;
   int __last_nonopt;
 
-# if defined _LIBC && defined USE_NONOPTION_FLAGS
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
   int __nonoption_flags_max_len;
   int __nonoption_flags_len;
 # endif
@@ -108,7 +108,7 @@ struct _getopt_data
 
 /* The initializer is necessary to set OPTIND and OPTERR to their
    default values and to clear the initialization flag.  */
-# define _GETOPT_DATA_INITIALIZER      { 1, 1 }
+#define _GETOPT_DATA_INITIALIZER       { 1, 1 }
 
 extern int _getopt_internal_r (int ___argc, char *const *___argv,
                               const char *__shortopts,
index 3f27621..cb5e17b 100644 (file)
@@ -1,3 +1,7 @@
+2004-08-19  Paul Eggert  <eggert@cs.ucla.edu>
+
+       * getopt.m4: Sync from gnulib.
+
 2004-08-11  Paul Eggert  <eggert@cs.ucla.edu>
 
        * obstack.m4 (gl_PREREQ_OBSTACK): Require
index df602b9..5ab3570 100644 (file)
@@ -1,13 +1,47 @@
-# getopt.m4 serial 2
-dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+# getopt.m4 serial 3
+dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
 dnl that contains a configuration script generated by Autoconf, under
 dnl the same distribution terms as the rest of that program.
 
+# The getopt module assume you want GNU getopt, with getopt_long etc,
+# rather than vanilla POSIX getopt.  This means your your code should
+# always include <getopt.h> for the getopt prototypes.
+
+AC_DEFUN([gl_GETOPT_SUBSTITUTE],
+[
+  GETOPT_H=getopt.h
+  AC_LIBOBJ([getopt])
+  AC_LIBOBJ([getopt1])
+  AC_DEFINE([optarg], [rpl_optarg],
+    [Define to rpl_optarg if the replacement variable should be used.])
+  AC_DEFINE([optind], [rpl_optind],
+    [Define to rpl_optind if the replacement variable should be used.])
+  AC_DEFINE([optopt], [rpl_optopt],
+    [Define to rpl_optopt if the replacement variable should be used.])
+  AC_DEFINE([getopt], [rpl_getopt],
+    [Define to rpl_getopt if the replacement function should be used.])
+  AC_DEFINE([getopt_long], [rpl_getopt_long],
+    [Define to rpl_getopt_long if the replacement function should be used.])
+  AC_DEFINE([getopt_long_only], [rpl_getopt_long_only],
+    [Define to rpl_getopt_long_only if the replacement function should be used.])
+  AC_SUBST([GETOPT_H])
+])
+
 AC_DEFUN([gl_GETOPT],
 [
-  dnl Prerequisites of lib/getopt.c.
-  :
+  gl_PREREQ_GETOPT
+
+  GETOPT_H=
+  AC_CHECK_HEADERS([getopt.h], [], [GETOPT_H=getopt.h])
+  AC_CHECK_FUNCS([getopt_long_only], [], [GETOPT_H=getopt.h])
+
+  if test -n "$GETOPT_H"; then
+     gl_GETOPT_SUBSTITUTE
+  fi
 ])
+
+# Prerequisites of lib/getopt*.
+AC_DEFUN([gl_PREREQ_GETOPT], [:])