|
Packit |
762fc5 |
/* getopt_long and getopt_long_only entry points for GNU getopt.
|
|
Packit |
762fc5 |
Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
|
|
Packit |
762fc5 |
Free Software Foundation, Inc.
|
|
Packit |
762fc5 |
This file was part of the GNU C Library.
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
762fc5 |
modify it under the terms of the GNU Library General Public License as
|
|
Packit |
762fc5 |
published by the Free Software Foundation; either version 2 of the
|
|
Packit |
762fc5 |
License, or (at your option) any later version.
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
762fc5 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
762fc5 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
762fc5 |
Library General Public License for more details.
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
You should have received a copy of the GNU Library General Public
|
|
Packit |
762fc5 |
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
|
Packit |
762fc5 |
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Packit |
762fc5 |
Boston, MA 02111-1307, USA. */
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#include "aide.h"
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#include "getopt.h"
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#if !defined __STDC__ || !__STDC__
|
|
Packit |
762fc5 |
/* This is a separate conditional since some stdc systems
|
|
Packit |
762fc5 |
reject `defined (const)'. */
|
|
Packit |
762fc5 |
#ifndef const
|
|
Packit |
762fc5 |
#define const
|
|
Packit |
762fc5 |
#endif
|
|
Packit |
762fc5 |
#endif
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#include <stdio.h>
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
/* Comment out all this code if we are using the GNU C Library, and are not
|
|
Packit |
762fc5 |
actually compiling the library itself. This code is part of the GNU C
|
|
Packit |
762fc5 |
Library, but also included in many other GNU distributions. Compiling
|
|
Packit |
762fc5 |
and linking in this code is a waste when using the GNU C library
|
|
Packit |
762fc5 |
(especially if it is a shared library). Rather than having every GNU
|
|
Packit |
762fc5 |
program understand `configure --with-gnu-libc' and omit the object files,
|
|
Packit |
762fc5 |
it is simpler to just do this in the source for each such file. */
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#define GETOPT_INTERFACE_VERSION 2
|
|
Packit |
762fc5 |
#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
|
|
Packit |
762fc5 |
#include <gnu-versions.h>
|
|
Packit |
762fc5 |
#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
|
|
Packit |
762fc5 |
#define ELIDE_CODE
|
|
Packit |
762fc5 |
#endif
|
|
Packit |
762fc5 |
#endif
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#ifndef ELIDE_CODE
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
/* This needs to come after some library #include
|
|
Packit |
762fc5 |
to get __GNU_LIBRARY__ defined. */
|
|
Packit |
762fc5 |
#ifdef __GNU_LIBRARY__
|
|
Packit |
762fc5 |
#include <stdlib.h>
|
|
Packit |
762fc5 |
#endif
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#ifndef NULL
|
|
Packit |
762fc5 |
#define NULL 0
|
|
Packit |
762fc5 |
#endif
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
int
|
|
Packit |
762fc5 |
getopt_long (argc, argv, options, long_options, opt_index)
|
|
Packit |
762fc5 |
int argc;
|
|
Packit |
762fc5 |
char *const *argv;
|
|
Packit |
762fc5 |
const char *options;
|
|
Packit |
762fc5 |
const struct option *long_options;
|
|
Packit |
762fc5 |
int *opt_index;
|
|
Packit |
762fc5 |
{
|
|
Packit |
762fc5 |
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
|
|
Packit |
762fc5 |
}
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
|
|
Packit |
762fc5 |
If an option that starts with '-' (not '--') doesn't match a long option,
|
|
Packit |
762fc5 |
but does match a short option, it is parsed as a short option
|
|
Packit |
762fc5 |
instead. */
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
int
|
|
Packit |
762fc5 |
getopt_long_only (argc, argv, options, long_options, opt_index)
|
|
Packit |
762fc5 |
int argc;
|
|
Packit |
762fc5 |
char *const *argv;
|
|
Packit |
762fc5 |
const char *options;
|
|
Packit |
762fc5 |
const struct option *long_options;
|
|
Packit |
762fc5 |
int *opt_index;
|
|
Packit |
762fc5 |
{
|
|
Packit |
762fc5 |
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
|
|
Packit |
762fc5 |
}
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#endif /* Not ELIDE_CODE. */
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#ifdef TEST
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#include <stdio.h>
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
int
|
|
Packit |
762fc5 |
main (argc, argv)
|
|
Packit |
762fc5 |
int argc;
|
|
Packit |
762fc5 |
char **argv;
|
|
Packit |
762fc5 |
{
|
|
Packit |
762fc5 |
int c;
|
|
Packit |
762fc5 |
int digit_optind = 0;
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
while (1)
|
|
Packit |
762fc5 |
{
|
|
Packit |
762fc5 |
int this_option_optind = optind ? optind : 1;
|
|
Packit |
762fc5 |
int option_index = 0;
|
|
Packit |
762fc5 |
static struct option long_options[] =
|
|
Packit |
762fc5 |
{
|
|
Packit |
762fc5 |
{"add", 1, 0, 0},
|
|
Packit |
762fc5 |
{"append", 0, 0, 0},
|
|
Packit |
762fc5 |
{"delete", 1, 0, 0},
|
|
Packit |
762fc5 |
{"verbose", 0, 0, 0},
|
|
Packit |
762fc5 |
{"create", 0, 0, 0},
|
|
Packit |
762fc5 |
{"file", 1, 0, 0},
|
|
Packit |
762fc5 |
{0, 0, 0, 0}
|
|
Packit |
762fc5 |
};
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
c = getopt_long (argc, argv, "abc:d:0123456789",
|
|
Packit |
762fc5 |
long_options, &option_index);
|
|
Packit |
762fc5 |
if (c == -1)
|
|
Packit |
762fc5 |
break;
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
switch (c)
|
|
Packit |
762fc5 |
{
|
|
Packit |
762fc5 |
case 0:
|
|
Packit |
762fc5 |
printf ("option %s", long_options[option_index].name);
|
|
Packit |
762fc5 |
if (optarg)
|
|
Packit |
762fc5 |
printf (" with arg %s", optarg);
|
|
Packit |
762fc5 |
printf ("\n");
|
|
Packit |
762fc5 |
break;
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
case '0':
|
|
Packit |
762fc5 |
case '1':
|
|
Packit |
762fc5 |
case '2':
|
|
Packit |
762fc5 |
case '3':
|
|
Packit |
762fc5 |
case '4':
|
|
Packit |
762fc5 |
case '5':
|
|
Packit |
762fc5 |
case '6':
|
|
Packit |
762fc5 |
case '7':
|
|
Packit |
762fc5 |
case '8':
|
|
Packit |
762fc5 |
case '9':
|
|
Packit |
762fc5 |
if (digit_optind != 0 && digit_optind != this_option_optind)
|
|
Packit |
762fc5 |
printf ("digits occur in two different argv-elements.\n");
|
|
Packit |
762fc5 |
digit_optind = this_option_optind;
|
|
Packit |
762fc5 |
printf ("option %c\n", c);
|
|
Packit |
762fc5 |
break;
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
case 'a':
|
|
Packit |
762fc5 |
printf ("option a\n");
|
|
Packit |
762fc5 |
break;
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
case 'b':
|
|
Packit |
762fc5 |
printf ("option b\n");
|
|
Packit |
762fc5 |
break;
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
case 'c':
|
|
Packit |
762fc5 |
printf ("option c with value `%s'\n", optarg);
|
|
Packit |
762fc5 |
break;
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
case 'd':
|
|
Packit |
762fc5 |
printf ("option d with value `%s'\n", optarg);
|
|
Packit |
762fc5 |
break;
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
case '?':
|
|
Packit |
762fc5 |
break;
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
default:
|
|
Packit |
762fc5 |
printf ("?? getopt returned character code 0%o ??\n", c);
|
|
Packit |
762fc5 |
}
|
|
Packit |
762fc5 |
}
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
if (optind < argc)
|
|
Packit |
762fc5 |
{
|
|
Packit |
762fc5 |
printf ("non-option ARGV-elements: ");
|
|
Packit |
762fc5 |
while (optind < argc)
|
|
Packit |
762fc5 |
printf ("%s ", argv[optind++]);
|
|
Packit |
762fc5 |
printf ("\n");
|
|
Packit |
762fc5 |
}
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
exit (0);
|
|
Packit |
762fc5 |
}
|
|
Packit |
762fc5 |
|
|
Packit |
762fc5 |
#endif /* TEST */
|