source: rtems-schedsim/schedsim/shell/shared/include/newlib/getopt.h @ b38dbcc

Last change on this file since b38dbcc was b38dbcc, checked in by Joel Sherrill <joel.sherrill@…>, on May 14, 2014 at 2:55:21 PM

Many files: rm white space at EOL and EOF

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/****************************************************************************
2
3getopt.h - Read command line options
4
5AUTHOR: Gregory Pietsch
6CREATED Thu Jan 09 22:37:00 1997
7
8DESCRIPTION:
9
10The getopt() function parses the command line arguments.  Its arguments argc
11and argv are the argument count and array as passed to the main() function
12on program invocation.  The argument optstring is a list of available option
13characters.  If such a character is followed by a colon (`:'), the option
14takes an argument, which is placed in optarg.  If such a character is
15followed by two colons, the option takes an optional argument, which is
16placed in optarg.  If the option does not take an argument, optarg is NULL.
17
18The external variable optind is the index of the next array element of argv
19to be processed; it communicates from one call to the next which element to
20process.
21
22The getopt_long() function works like getopt() except that it also accepts
23long options started by two dashes `--'.  If these take values, it is either
24in the form
25
26--arg=value
27
28 or
29
30--arg value
31
32It takes the additional arguments longopts which is a pointer to the first
33element of an array of type GETOPT_LONG_OPTION_T, defined below.  The last
34element of the array has to be filled with NULL for the name field.
35
36The longind pointer points to the index of the current long option relative
37to longopts if it is non-NULL.
38
39The getopt() function returns the option character if the option was found
40successfully, `:' if there was a missing parameter for one of the options,
41`?' for an unknown option character, and EOF for the end of the option list.
42
43The getopt_long() function's return value is described below.
44
45The function getopt_long_only() is identical to getopt_long(), except that a
46plus sign `+' can introduce long options as well as `--'.
47
48Describe how to deal with options that follow non-option ARGV-elements.
49
50If the caller did not specify anything, the default is REQUIRE_ORDER if the
51environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise.
52
53REQUIRE_ORDER means don't recognize them as options; stop option processing
54when the first non-option is seen.  This is what Unix does.  This mode of
55operation is selected by either setting the environment variable
56POSIXLY_CORRECT, or using `+' as the first character of the optstring
57parameter.
58
59PERMUTE is the default.  We permute the contents of ARGV as we scan, so that
60eventually all the non-options are at the end.  This allows options to be
61given in any order, even with programs that were not written to expect this.
62
63RETURN_IN_ORDER is an option available to programs that were written to
64expect options and other ARGV-elements in any order and that care about the
65ordering of the two.  We describe each non-option ARGV-element as if it were
66the argument of an option with character code 1.  Using `-' as the first
67character of the optstring parameter selects this mode of operation.
68
69The special argument `--' forces an end of option-scanning regardless of the
70value of `ordering'.  In the case of RETURN_IN_ORDER, only `--' can cause
71getopt() and friends to return EOF with optind != argc.
72
73COPYRIGHT NOTICE AND DISCLAIMER:
74
75Copyright (C) 1997 Gregory Pietsch
76
77This file and the accompanying getopt.c implementation file are hereby
78placed in the public domain without restrictions.  Just give the author
79credit, don't claim you wrote it or prevent anyone else from using it.
80
81Gregory Pietsch's current e-mail address:
82gpietsch@comcast.net
83****************************************************************************/
84
85/* use _GETOPT_H so we avoid dupe include of glibc getopt.h */
86#ifndef _GETOPT_H
87#define _GETOPT_H
88
89#include <newlib/_ansi.h>
90
91/* include files needed by this include file */
92
93  /* These #defines are to keep the namespace clear... */
94#define getopt_r                __getopt_r
95#define getopt_long_r           __getopt_long_r
96#define getopt_long_only_r      __getopt_long_only_r
97
98#ifdef __cplusplus
99extern "C"
100{
101
102#endif                          /* __cplusplus */
103
104/* types defined by this include file */
105  struct option
106  {
107    char *name;                 /* the name of the long option */
108    int has_arg;                /* one of the above macros */
109    int *flag;                  /* determines if getopt_long() returns a
110                                 * value for a long option; if it is
111                                 * non-NULL, 0 is returned as a function
112                                 * value and the value of val is stored in
113                                 * the area pointed to by flag.  Otherwise,
114                                 * val is returned. */
115    int val;                    /* determines the value to return if flag is
116                                 * NULL. */
117
118  };
119
120  /* The getopt_data structure is for reentrancy. Its members are similar to
121     the externally-defined variables.  */
122  typedef struct getopt_data
123  {
124    char *optarg;
125    int optind, opterr, optopt, optwhere;
126  } getopt_data;
127
128  /* externally-defined variables */
129  extern char *optarg;
130  extern int optind;
131  extern int opterr;
132  extern int optopt;
133
134  /* function prototypes */
135  int _EXFUN (getopt,
136              (int __argc, char *const __argv[], const char *__optstring));
137
138  int _EXFUN (getopt_long,
139              (int __argc, char *const __argv[], const char *__shortopts,
140               const struct option * __longopts, int *__longind));
141
142  int _EXFUN (getopt_long_only,
143              (int __argc, char *const __argv[], const char *__shortopts,
144               const struct option * __longopts, int *__longind));
145
146  int _EXFUN (__getopt_r,
147              (int __argc, char *const __argv[], const char *__optstring,
148               struct getopt_data * __data));
149
150  int _EXFUN (__getopt_long_r,
151              (int __argc, char *const __argv[], const char *__shortopts,
152               const struct option * __longopts, int *__longind,
153               struct getopt_data * __data));
154
155  int _EXFUN (__getopt_long_only_r,
156              (int __argc, char *const __argv[], const char *__shortopts,
157               const struct option * __longopts, int *__longind,
158               struct getopt_data * __data));
159
160#ifdef __cplusplus
161};
162
163#endif /* __cplusplus  */
164
165#endif /* GETOPT_H */
166
167/* END OF FILE getopt.h */
Note: See TracBrowser for help on using the repository browser.