[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] getopt patch to assume C89 or better
From: |
Paul Eggert |
Subject: |
[Bug-gnulib] getopt patch to assume C89 or better |
Date: |
09 Sep 2003 11:41:10 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
This patch breaks the linkage between glibc and gnulib for getopt.h
and getopt1.c (getopt.c was already not linked). I hope to merge this
back into libc.
2003-09-09 Paul Eggert <address@hidden>
* src/getopt.h (struct option.name): Assume C89, and use 'const'.
(getopt, etopt_long, getopt_long_only, _getopt_internal)
[defined __GNU_LIBRARY__]: Assume C89, so we can always declare
with a prototype.
* src/getopt.c (const): Remove macro.
Include <string.h> unconditionally.
(my_index): Remove; all uses changed to strchr.
(strlen): Remove decl.
(exchange): Remove forward decl; no longer needed.
(exchange, _getopt_initialize, _getopt_internal, getopt, main):
Define with prototype.
* src/getopt1.c (const): Remove macro.
(getopt_long, getopt_long_only, main): Define with prototype.
* m4/getopt.m4 (gl_GETOPT): Don't check for string.h.
* config/srclist.txt: Do not get getopt.h or getopt1.c from libc.
Index: lib/getopt.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/getopt.h,v
retrieving revision 1.16
diff -p -u -r1.16 getopt.h
--- lib/getopt.h 13 Aug 2003 20:23:14 -0000 1.16
+++ lib/getopt.h 9 Sep 2003 18:26:56 -0000
@@ -1,5 +1,8 @@
/* Declarations for getopt.
- Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc.
+
+ Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998,
+ 1999, 2001, 2003 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
@@ -92,11 +95,7 @@ extern int optopt;
struct option
{
-# if (defined __STDC__ && __STDC__) || defined __cplusplus
const char *name;
-# else
- char *name;
-# endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
@@ -136,17 +135,16 @@ struct option
arguments to the option '\0'. This behavior is specific to the GNU
`getopt'. */
-#if (defined __STDC__ && __STDC__) || defined __cplusplus
-# ifdef __GNU_LIBRARY__
+#ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);
-# else /* not __GNU_LIBRARY__ */
+#else /* not __GNU_LIBRARY__ */
extern int getopt ();
-# endif /* __GNU_LIBRARY__ */
+#endif /* __GNU_LIBRARY__ */
-# ifndef __need_getopt
+#ifndef __need_getopt
extern int getopt_long (int ___argc, char *const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind);
@@ -159,16 +157,7 @@ extern int _getopt_internal (int ___argc
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only);
-# endif
-#else /* not __STDC__ */
-extern int getopt ();
-# ifndef __need_getopt
-extern int getopt_long ();
-extern int getopt_long_only ();
-
-extern int _getopt_internal ();
-# endif
-#endif /* __STDC__ */
+#endif
#ifdef __cplusplus
}
Index: lib/getopt.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/getopt.c,v
retrieving revision 1.39
diff -p -u -r1.39 getopt.c
--- lib/getopt.c 25 Nov 2002 00:17:33 -0000 1.39
+++ lib/getopt.c 9 Sep 2003 18:26:58 -0000
@@ -2,8 +2,11 @@
NOTE: getopt is now part of the C library, so if you don't know what
"Keep this file name-space clean" means, talk to address@hidden
before changing it!
- Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002
- Free Software Foundation, Inc.
+
+ Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+ 1996, 1998, 1999, 2000, 2001, 2002, 2003 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
@@ -30,14 +33,6 @@
# include <config.h>
#endif
-#if !defined __STDC__ || !__STDC__
-/* This is a separate conditional since some stdc systems
- reject `defined (const)'. */
-# ifndef const
-# define const
-# endif
-#endif
-
#include <stdio.h>
/* Comment out all this code if we are using the GNU C Library, and are not
@@ -68,11 +63,10 @@
# include <unistd.h>
#endif /* GNU C library. */
+#include <string.h>
+
#ifdef VMS
# include <unixlib.h>
-# if HAVE_STRING_H - 0
-# include <string.h>
-# endif
#endif
#ifdef _LIBC
@@ -193,20 +187,7 @@ static enum
/* 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
- because there are many ways it can cause trouble.
- On some systems, it contains special magic macros that don't work
- in GCC. */
-# include <string.h>
-# define my_index strchr
-#else
-
-# if HAVE_STRING_H
-# include <string.h>
-# else
-# include <strings.h>
-# endif
+#ifndef __GNU_LIBRARY__
/* Avoid depending on library functions or files
whose names are inconsistent. */
@@ -215,32 +196,6 @@ static char *posixly_correct;
extern char *getenv ();
#endif
-static char *
-my_index (str, chr)
- const char *str;
- int chr;
-{
- while (*str)
- {
- if (*str == chr)
- return (char *) str;
- str++;
- }
- return 0;
-}
-
-/* If using GCC, we can safely declare strlen this way.
- If not using GCC, it is ok not to declare it. */
-#ifdef __GNUC__
-/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
- That was relevant to code that was here before. */
-# if (!defined __STDC__ || !__STDC__) && !defined strlen
-/* 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 *);
-# endif /* not __STDC__ */
-#endif /* __GNUC__ */
-
#endif /* not __GNU_LIBRARY__ */
/* Handle permutation of arguments. */
@@ -294,13 +249,8 @@ static int nonoption_flags_len;
`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;
+exchange (char **argv)
{
int bottom = first_nonopt;
int middle = last_nonopt;
@@ -380,14 +330,8 @@ 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 (argc, argv, optstring)
- int argc;
- char *const *argv;
- const char *optstring;
+_getopt_initialize (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
@@ -506,13 +450,9 @@ _getopt_initialize (argc, argv, optstrin
long-named options. */
int
-_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
- int argc;
- char *const *argv;
- const char *optstring;
- const struct option *longopts;
- int *longind;
- int long_only;
+_getopt_internal (int argc, char *const *argv,
+ const char *optstring, const struct option *longopts,
+ int *longind, int long_only)
{
int print_errors = opterr;
if (optstring[0] == ':')
@@ -637,7 +577,8 @@ _getopt_internal (argc, argv, optstring,
if (longopts != NULL
&& (argv[optind][1] == '-'
- || (long_only && (argv[optind][2] || !my_index (optstring,
argv[optind][1])))))
+ || (long_only
+ && (argv[optind][2] || !strchr (optstring, argv[optind][1])))))
{
char *nameend;
const struct option *p;
@@ -822,7 +763,7 @@ _getopt_internal (argc, argv, optstring,
option, then it's an error.
Otherwise interpret it as a short option. */
if (!long_only || argv[optind][1] == '-'
- || my_index (optstring, *nextchar) == NULL)
+ || strchr (optstring, *nextchar) == NULL)
{
if (print_errors)
{
@@ -877,7 +818,7 @@ _getopt_internal (argc, argv, optstring,
{
char c = *nextchar++;
- char *temp = my_index (optstring, c);
+ char *temp = strchr (optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*nextchar == '\0')
@@ -1187,10 +1128,7 @@ _getopt_internal (argc, argv, optstring,
}
int
-getopt (argc, argv, optstring)
- int argc;
- char *const *argv;
- const char *optstring;
+getopt (int argc, char *const *argv, const char *optstring)
{
return _getopt_internal (argc, argv, optstring,
(const struct option *) 0,
@@ -1206,9 +1144,7 @@ getopt (argc, argv, optstring)
the above definition of `getopt'. */
int
-main (argc, argv)
- int argc;
- char **argv;
+main (int argc, char **argv)
{
int c;
int digit_optind = 0;
Index: lib/getopt1.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/getopt1.c,v
retrieving revision 1.14
diff -p -u -r1.14 getopt1.c
--- lib/getopt1.c 25 Nov 2002 00:17:33 -0000 1.14
+++ lib/getopt1.c 9 Sep 2003 18:26:58 -0000
@@ -1,6 +1,8 @@
/* getopt_long and getopt_long_only entry points for GNU getopt.
- Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
- Free Software Foundation, Inc.
+
+ Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996,
+ 1997, 1998, 2003 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
@@ -27,14 +29,6 @@
# include "getopt.h"
#endif
-#if !defined __STDC__ || !__STDC__
-/* This is a separate conditional since some stdc systems
- reject `defined (const)'. */
-#ifndef const
-#define const
-#endif
-#endif
-
#include <stdio.h>
/* Comment out all this code if we are using the GNU C Library, and are not
@@ -67,12 +61,11 @@
#endif
int
-getopt_long (argc, argv, options, long_options, opt_index)
- int argc;
- char *const *argv;
- const char *options;
- const struct option *long_options;
- int *opt_index;
+getopt_long (int argc,
+ char *const *argv,
+ const char *options,
+ const struct option *long_options,
+ int *opt_index)
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
}
@@ -83,12 +76,11 @@ getopt_long (argc, argv, options, long_o
instead. */
int
-getopt_long_only (argc, argv, options, long_options, opt_index)
- int argc;
- char *const *argv;
- const char *options;
- const struct option *long_options;
- int *opt_index;
+getopt_long_only (int argc,
+ char *const *argv,
+ const char *options,
+ const struct option *long_options,
+ int *opt_index)
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
}
@@ -105,9 +97,7 @@ libc_hidden_def (getopt_long_only)
#include <stdio.h>
int
-main (argc, argv)
- int argc;
- char **argv;
+main (int argc, char **argv)
{
int c;
int digit_optind = 0;
Index: m4/getopt.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/getopt.m4,v
retrieving revision 1.1
diff -p -u -r1.1 getopt.m4
--- m4/getopt.m4 31 Dec 2002 13:42:06 -0000 1.1
+++ m4/getopt.m4 9 Sep 2003 18:26:58 -0000
@@ -1,5 +1,5 @@
-# getopt.m4 serial 1
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# getopt.m4 serial 2
+dnl Copyright (C) 2002, 2003 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
@@ -9,5 +9,5 @@ dnl the same distribution terms as the r
AC_DEFUN([gl_GETOPT],
[
dnl Prerequisites of lib/getopt.c.
- AC_CHECK_HEADERS_ONCE(string.h)
+ :
])
Index: config/srclist.txt
===================================================================
RCS file: /cvsroot/gnulib/gnulib/config/srclist.txt,v
retrieving revision 1.23
diff -p -u -r1.23 srclist.txt
--- config/srclist.txt 17 Aug 2003 05:30:20 -0000 1.23
+++ config/srclist.txt 9 Sep 2003 18:26:58 -0000
@@ -74,8 +74,6 @@ $LIBCSRC/argp/argp-pv.c lib gpl
$LIBCSRC/argp/argp-pvh.c lib gpl
$LIBCSRC/argp/argp-xinl.c lib gpl
$LIBCSRC/argp/argp.h lib gpl
-$LIBCSRC/posix/getopt.h lib gpl
-$LIBCSRC/posix/getopt1.c lib gpl
$LIBCSRC/posix/regex.h lib gpl
$LIBCSRC/string/strdup.c lib gpl
$LIBCSRC/sysdeps/generic/strtoll.c lib gpl
@@ -96,6 +94,8 @@ $LIBCSRC/sysdeps/generic/strtoul.c lib g
#$LIBCSRC/posix/fnmatch.h lib gpl (fnmatch_.h in gnulib)
#$LIBCSRC/posix/fnmatch_loop.c lib gpl
#$LIBCSRC/posix/getopt.c lib gpl
+#$LIBCSRC/posix/getopt.h lib gpl
+#$LIBCSRC/posix/getopt1.c lib gpl
#$LIBCSRC/posix/tempname.c lib gpl
#$LIBCSRC/stdlib/rpmatch.c lib gpl
#$LIBCSRC/string/strndup.c lib gpl
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-gnulib] getopt patch to assume C89 or better,
Paul Eggert <=