diff src/sdl/getopt.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/sdl/getopt.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,141 @@
     1.4 +/* Declarations for getopt.
     1.5 +   Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 2000
     1.6 +   Free Software Foundation, Inc.
     1.7 +
     1.8 +   NOTE: The canonical source of this file is maintained with the GNU C Library.
     1.9 +   Bugs can be reported to bug-glibc@gnu.org.
    1.10 +
    1.11 +   This program is free software; you can redistribute it and/or modify it
    1.12 +   under the terms of the GNU General Public License as published by the
    1.13 +   Free Software Foundation; either version 2, or (at your option) any
    1.14 +   later version.
    1.15 +
    1.16 +   This program is distributed in the hope that it will be useful,
    1.17 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.18 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.19 +   GNU General Public License for more details.
    1.20 +
    1.21 +   You should have received a copy of the GNU General Public License
    1.22 +   along with this program; if not, write to the Free Software
    1.23 +   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    1.24 +   USA.  */
    1.25 +
    1.26 +#ifndef _GETOPT_H
    1.27 +#define _GETOPT_H 1
    1.28 +
    1.29 +#ifdef	__cplusplus
    1.30 +extern "C" {
    1.31 +#endif
    1.32 +
    1.33 +/* For communication from `getopt' to the caller.
    1.34 +   When `getopt' finds an option that takes an argument,
    1.35 +   the argument value is returned here.
    1.36 +   Also, when `ordering' is RETURN_IN_ORDER,
    1.37 +   each non-option ARGV-element is returned here.  */
    1.38 +
    1.39 +extern char *optarg;
    1.40 +
    1.41 +/* Index in ARGV of the next element to be scanned.
    1.42 +   This is used for communication to and from the caller
    1.43 +   and for communication between successive calls to `getopt'.
    1.44 +
    1.45 +   On entry to `getopt', zero means this is the first call; initialize.
    1.46 +
    1.47 +   When `getopt' returns -1, this is the index of the first of the
    1.48 +   non-option elements that the caller should itself scan.
    1.49 +
    1.50 +   Otherwise, `optind' communicates from one call to the next
    1.51 +   how much of ARGV has been scanned so far.  */
    1.52 +
    1.53 +extern int optind;
    1.54 +
    1.55 +/* Callers store zero here to inhibit the error message `getopt' prints
    1.56 +   for unrecognized options.  */
    1.57 +
    1.58 +extern int opterr;
    1.59 +
    1.60 +/* Set to an option character which was unrecognized.  */
    1.61 +
    1.62 +extern int optopt;
    1.63 +
    1.64 +/* Describe the long-named options requested by the application.
    1.65 +   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
    1.66 +   of `struct option' terminated by an element containing a name which is
    1.67 +   zero.
    1.68 +
    1.69 +   The field `has_arg' is:
    1.70 +   no_argument		(or 0) if the option does not take an argument,
    1.71 +   required_argument	(or 1) if the option requires an argument,
    1.72 +   optional_argument 	(or 2) if the option takes an optional argument.
    1.73 +
    1.74 +   If the field `flag' is not NULL, it points to a variable that is set
    1.75 +   to the value given in the field `val' when the option is found, but
    1.76 +   left unchanged if the option is not found.
    1.77 +
    1.78 +   To have a long-named option do something other than set an `int' to
    1.79 +   a compiled-in constant, such as set a value from `optarg', set the
    1.80 +   option's `flag' field to zero and its `val' field to a nonzero
    1.81 +   value (the equivalent single-letter option character, if there is
    1.82 +   one).  For long options that have a zero `flag' field, `getopt'
    1.83 +   returns the contents of the `val' field.  */
    1.84 +
    1.85 +struct option
    1.86 +{
    1.87 +#if defined (__STDC__) && __STDC__
    1.88 +  const char *name;
    1.89 +#else
    1.90 +  char *name;
    1.91 +#endif
    1.92 +  /* has_arg can't be an enum because some compilers complain about
    1.93 +     type mismatches in all the code that assumes it is an int.  */
    1.94 +  int has_arg;
    1.95 +  int *flag;
    1.96 +  int val;
    1.97 +};
    1.98 +
    1.99 +/* Names for the values of the `has_arg' field of `struct option'.  */
   1.100 +
   1.101 +#define	no_argument		0
   1.102 +#define required_argument	1
   1.103 +#define optional_argument	2
   1.104 +
   1.105 +#if defined (__STDC__) && __STDC__
   1.106 +/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1.  If it is
   1.107 +   undefined, we haven't run the autoconf check so provide the
   1.108 +   declaration without arguments.  If it is 0, we checked and failed
   1.109 +   to find the declaration so provide a fully prototyped one.  If it
   1.110 +   is 1, we found it so don't provide any declaration at all.  */
   1.111 +#if defined (__GNU_LIBRARY__) || (defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT)
   1.112 +/* Many other libraries have conflicting prototypes for getopt, with
   1.113 +   differences in the consts, in stdlib.h.  To avoid compilation
   1.114 +   errors, only prototype getopt for the GNU C library.  */
   1.115 +extern int getopt (int argc, char *const *argv, const char *shortopts);
   1.116 +#else /* not __GNU_LIBRARY__ */
   1.117 +# if !defined (HAVE_DECL_GETOPT)
   1.118 +extern int getopt ();
   1.119 +# endif
   1.120 +#endif /* __GNU_LIBRARY__ */
   1.121 +extern int getopt_long (int argc, char *const *argv, const char *shortopts,
   1.122 +		        const struct option *longopts, int *longind);
   1.123 +extern int getopt_long_only (int argc, char *const *argv,
   1.124 +			     const char *shortopts,
   1.125 +		             const struct option *longopts, int *longind);
   1.126 +
   1.127 +/* Internal only.  Users should not call this directly.  */
   1.128 +extern int _getopt_internal (int argc, char *const *argv,
   1.129 +			     const char *shortopts,
   1.130 +		             const struct option *longopts, int *longind,
   1.131 +			     int long_only);
   1.132 +#else /* not __STDC__ */
   1.133 +extern int getopt ();
   1.134 +extern int getopt_long ();
   1.135 +extern int getopt_long_only ();
   1.136 +
   1.137 +extern int _getopt_internal ();
   1.138 +#endif /* __STDC__ */
   1.139 +
   1.140 +#ifdef	__cplusplus
   1.141 +}
   1.142 +#endif
   1.143 +
   1.144 +#endif /* getopt.h */