~ubuntu-branches/ubuntu/dapper/simulavr/dapper

« back to all changes in this revision

Viewing changes to src/getopt/gnu_getopt.h

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2004-04-10 13:54:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040410135417-zywapjyz252y65se
Tags: upstream-0.1.2.1
ImportĀ upstreamĀ versionĀ 0.1.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Declarations for getopt.
 
2
   Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 2000, 2001,
 
3
   2002
 
4
   Free Software Foundation, Inc.
 
5
 
 
6
   NOTE: The canonical source of this file is maintained with the GNU C Library.
 
7
   Bugs can be reported to bug-glibc@gnu.org.
 
8
 
 
9
   This program is free software; you can redistribute it and/or modify it
 
10
   under the terms of the GNU General Public License as published by the
 
11
   Free Software Foundation; either version 2, or (at your option) any
 
12
   later version.
 
13
 
 
14
   This program is distributed in the hope that it will be useful,
 
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
   GNU General Public License for more details.
 
18
 
 
19
   You should have received a copy of the GNU General Public License
 
20
   along with this program; if not, write to the Free Software
 
21
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
22
   USA.  */
 
23
 
 
24
#ifndef _GNU_GETOPT_H
 
25
#define _GNU_GETOPT_H 1
 
26
 
 
27
/* We only use getopt_long(), not getopt(), so we don't need a fully
 
28
   prototyped declaration of getopt(). This forces the prototype for getopt()
 
29
   to be compatible with all systems. Solaris in particular seems to have a
 
30
   prototype for getopt() in unistd.h which conflicts with the one in this
 
31
   file if we don't do this. */
 
32
 
 
33
#undef HAVE_DECL_GETOPT
 
34
#define HAVE_DECL_GETOPT 1
 
35
 
 
36
#ifdef  __cplusplus
 
37
extern "C" {
 
38
#endif
 
39
 
 
40
/* For communication from `getopt' to the caller.
 
41
   When `getopt' finds an option that takes an argument,
 
42
   the argument value is returned here.
 
43
   Also, when `ordering' is RETURN_IN_ORDER,
 
44
   each non-option ARGV-element is returned here.  */
 
45
 
 
46
extern char *optarg;
 
47
 
 
48
/* Index in ARGV of the next element to be scanned.
 
49
   This is used for communication to and from the caller
 
50
   and for communication between successive calls to `getopt'.
 
51
 
 
52
   On entry to `getopt', zero means this is the first call; initialize.
 
53
 
 
54
   When `getopt' returns -1, this is the index of the first of the
 
55
   non-option elements that the caller should itself scan.
 
56
 
 
57
   Otherwise, `optind' communicates from one call to the next
 
58
   how much of ARGV has been scanned so far.  */
 
59
 
 
60
extern int optind;
 
61
 
 
62
/* Callers store zero here to inhibit the error message `getopt' prints
 
63
   for unrecognized options.  */
 
64
 
 
65
extern int opterr;
 
66
 
 
67
/* Set to an option character which was unrecognized.  */
 
68
 
 
69
extern int optopt;
 
70
 
 
71
/* Describe the long-named options requested by the application.
 
72
   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
 
73
   of `struct option' terminated by an element containing a name which is
 
74
   zero.
 
75
 
 
76
   The field `has_arg' is:
 
77
   no_argument          (or 0) if the option does not take an argument,
 
78
   required_argument    (or 1) if the option requires an argument,
 
79
   optional_argument    (or 2) if the option takes an optional argument.
 
80
 
 
81
   If the field `flag' is not NULL, it points to a variable that is set
 
82
   to the value given in the field `val' when the option is found, but
 
83
   left unchanged if the option is not found.
 
84
 
 
85
   To have a long-named option do something other than set an `int' to
 
86
   a compiled-in constant, such as set a value from `optarg', set the
 
87
   option's `flag' field to zero and its `val' field to a nonzero
 
88
   value (the equivalent single-letter option character, if there is
 
89
   one).  For long options that have a zero `flag' field, `getopt'
 
90
   returns the contents of the `val' field.  */
 
91
 
 
92
struct option
 
93
{
 
94
#if defined (__STDC__) && __STDC__
 
95
  const char *name;
 
96
#else
 
97
  char *name;
 
98
#endif
 
99
  /* has_arg can't be an enum because some compilers complain about
 
100
     type mismatches in all the code that assumes it is an int.  */
 
101
  int has_arg;
 
102
  int *flag;
 
103
  int val;
 
104
};
 
105
 
 
106
/* Names for the values of the `has_arg' field of `struct option'.  */
 
107
 
 
108
#define no_argument             0
 
109
#define required_argument       1
 
110
#define optional_argument       2
 
111
 
 
112
#if defined (__STDC__) && __STDC__
 
113
/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1.  If it is
 
114
   undefined, we haven't run the autoconf check so provide the
 
115
   declaration without arguments.  If it is 0, we checked and failed
 
116
   to find the declaration so provide a fully prototyped one.  If it
 
117
   is 1, we found it so don't provide any declaration at all.  */
 
118
#if defined (__GNU_LIBRARY__) || (defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT)
 
119
/* Many other libraries have conflicting prototypes for getopt, with
 
120
   differences in the consts, in stdlib.h.  To avoid compilation
 
121
   errors, only prototype getopt for the GNU C library.  */
 
122
extern int getopt (int argc, char *const *argv, const char *shortopts);
 
123
#else /* not __GNU_LIBRARY__ */
 
124
# if !defined (HAVE_DECL_GETOPT)
 
125
extern int getopt ();
 
126
# endif
 
127
#endif /* __GNU_LIBRARY__ */
 
128
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
 
129
                        const struct option *longopts, int *longind);
 
130
extern int getopt_long_only (int argc, char *const *argv,
 
131
                             const char *shortopts,
 
132
                             const struct option *longopts, int *longind);
 
133
 
 
134
/* Internal only.  Users should not call this directly.  */
 
135
extern int _getopt_internal (int argc, char *const *argv,
 
136
                             const char *shortopts,
 
137
                             const struct option *longopts, int *longind,
 
138
                             int long_only);
 
139
#else /* not __STDC__ */
 
140
extern int getopt ();
 
141
extern int getopt_long ();
 
142
extern int getopt_long_only ();
 
143
 
 
144
extern int _getopt_internal ();
 
145
#endif /* __STDC__ */
 
146
 
 
147
#ifdef  __cplusplus
 
148
}
 
149
#endif
 
150
 
 
151
#endif /* gnu_getopt.h */