1 /* gnu_getopt_long and getopt_long_only entry points for GNU getopt.
2 Copyright (C) 1987,88,89,90,91,92,93,94,96,97 Free Software Foundation, Inc.
4 This file is part of the GNU C Library. Its master source is NOT part of
5 the C library, however. The master source lives in /gd/gnu/lib.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 * modified July 9, 1999 by mark gates <mgates@nlanr.net>
26 * renamed all functions and variables by prepending "gnu_"
27 * removed/redid a bunch of stuff under the assumption we're
28 * using a modern standard C compiler.
29 * renamed file to gnu_getopt_long.c (from gnu_getopt1.c)
31 * $Id: gnu_getopt_long.c,v 1.1.1.1 2004/05/18 01:50:44 kgibbs Exp $
36 #include "gnu_getopt.h"
46 gnu_getopt_long( int argc,
49 const struct option *long_options,
51 return _gnu_getopt_internal (argc, argv, options, long_options, opt_index, 0);
54 /* Like gnu_getopt_long, but '-' as well as '--' can indicate a long option.
55 If an option that starts with '-' (not '--') doesn't match a long option,
56 but does match a short option, it is parsed as a short option
60 gnu_getopt_long_only( int argc,
63 const struct option *long_options,
65 return _gnu_getopt_internal (argc, argv, options, long_options, opt_index, 1);
69 } /* end extern "C" */
86 int this_option_optind = gnu_optind ? gnu_optind : 1;
88 static struct option long_options[] =
99 c = gnu_getopt_long (argc, argv, "abc:d:0123456789",
100 long_options, &option_index);
106 fprintf ( stderr, "option %s", long_options[option_index].name);
108 fprintf ( stderr, " with arg %s", gnu_optarg);
109 fprintf ( stderr, "\n");
122 if ( digit_optind != 0 && digit_optind != this_option_optind )
123 fprintf ( stderr, "digits occur in two different argv-elements.\n");
124 digit_optind = this_option_optind;
125 fprintf ( stderr, "option %c\n", c);
129 fprintf ( stderr, "option a\n");
133 fprintf ( stderr, "option b\n");
137 fprintf ( stderr, "option c with value `%s'\n", gnu_optarg);
141 fprintf ( stderr, "option d with value `%s'\n", gnu_optarg);
148 fprintf ( stderr, "?? gnu_getopt returned character code 0%o ??\n", c);
152 if ( gnu_optind < argc ) {
153 fprintf ( stderr, "non-option ARGV-elements: ");
154 while ( gnu_optind < argc )
155 fprintf ( stderr, "%s ", argv[gnu_optind++]);
156 fprintf ( stderr, "\n");