lib: Update getopt1.c from Gnulib.
The only difference was maintaining the conditional inclusion for config.h.
This commit is contained in:
parent
7e884c00d0
commit
52bf644bdf
|
@ -1,44 +1,31 @@
|
||||||
/* getopt_long and getopt_long_only entry points for GNU getopt.
|
/* getopt_long and getopt_long_only entry points for GNU getopt.
|
||||||
Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006
|
Copyright (C) 1987-2023 Free Software Foundation, Inc.
|
||||||
Free Software Foundation, Inc.
|
This file is part of the GNU C Library and is also part of gnulib.
|
||||||
This file is part of the GNU C Library.
|
Patches to this file should be submitted to both projects.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
modify it under the terms of the GNU Lesser General Public
|
||||||
the Free Software Foundation; either version 2.1, or (at your option)
|
License as published by the Free Software Foundation; either
|
||||||
any later version.
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
GNU Lesser General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public License along
|
You should have received a copy of the GNU Lesser General Public
|
||||||
with this program; if not, write to the Free Software Foundation,
|
License along with the GNU C Library; if not, see
|
||||||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifdef _LIBC
|
#ifndef _LIBC
|
||||||
# include <getopt.h>
|
|
||||||
#else
|
|
||||||
# ifdef HAVE_CONFIG_H
|
# ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "getopt.h"
|
#include "getopt.h"
|
||||||
#endif
|
|
||||||
#include "getopt_int.h"
|
#include "getopt_int.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
/* This needs to come after some library #include
|
|
||||||
to get __GNU_LIBRARY__ defined. */
|
|
||||||
#ifdef __GNU_LIBRARY__
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NULL
|
|
||||||
#define NULL 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
int
|
||||||
getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
|
getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
|
||||||
const struct option *long_options, int *opt_index)
|
const struct option *long_options, int *opt_index)
|
||||||
|
@ -53,7 +40,7 @@ _getopt_long_r (int argc, char **argv, const char *options,
|
||||||
struct _getopt_data *d)
|
struct _getopt_data *d)
|
||||||
{
|
{
|
||||||
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
|
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
|
||||||
0, 0, d);
|
0, d, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
|
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
|
||||||
|
@ -76,13 +63,14 @@ _getopt_long_only_r (int argc, char **argv, const char *options,
|
||||||
struct _getopt_data *d)
|
struct _getopt_data *d)
|
||||||
{
|
{
|
||||||
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
|
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
|
||||||
1, 0, d);
|
1, d, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
|
@ -94,7 +82,7 @@ main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
int this_option_optind = optind ? optind : 1;
|
int this_option_optind = optind ? optind : 1;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
static struct option long_options[] =
|
static const struct option long_options[] =
|
||||||
{
|
{
|
||||||
{"add", 1, 0, 0},
|
{"add", 1, 0, 0},
|
||||||
{"append", 0, 0, 0},
|
{"append", 0, 0, 0},
|
||||||
|
@ -144,11 +132,11 @@ main (int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
printf ("option c with value `%s'\n", optarg);
|
printf ("option c with value '%s'\n", optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
printf ("option d with value `%s'\n", optarg);
|
printf ("option d with value '%s'\n", optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
|
|
Loading…
Reference in New Issue