~ubuntu-branches/ubuntu/trusty/hexcurse/trusty

« back to all changes in this revision

Viewing changes to include/hgetopt.h

  • Committer: Bazaar Package Importer
  • Author(s): RISKO Gergely
  • Date: 2002-03-29 12:24:14 UTC
  • Revision ID: james.westby@ubuntu.com-20020329122414-rh3gzqb6aslm4fgp
Tags: 1.40-1
new upstream release

Show diffs side-by-side

added added

removed removed

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