00001 #ifndef _GETOPT_H 00002 #define _GETOPT_H 00003 00004 #ifndef NULL 00005 #define NULL 0 00006 #endif 00007 00008 #include <l4/sys/compiler.h> 00009 00010 EXTERN_C_BEGIN 00011 00012 /* For communication from `getopt' to the caller. 00013 When `getopt' finds an option that takes an argument, 00014 the argument value is returned here. 00015 Also, when `ordering' is RETURN_IN_ORDER, 00016 each non-option ARGV-element is returned here. */ 00017 00018 extern char *optarg; 00019 00020 /* Index in ARGV of the next element to be scanned. 00021 This is used for communication to and from the caller 00022 and for communication between successive calls to `getopt'. 00023 00024 On entry to `getopt', zero means this is the first call; initialize. 00025 00026 When `getopt' returns -1, this is the index of the first of the 00027 non-option elements that the caller should itself scan. 00028 00029 Otherwise, `optind' communicates from one call to the next 00030 how much of ARGV has been scanned so far. */ 00031 00032 extern int optind; 00033 00034 /* Callers store zero here to inhibit the error message `getopt' prints 00035 for unrecognized options. */ 00036 00037 extern int opterr; 00038 00039 /* Set to an option character which was unrecognized. */ 00040 00041 extern int optopt; 00042 00043 /* Describe the long-named options requested by the application. 00044 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 00045 of `struct option' terminated by an element containing a name which is 00046 zero. 00047 00048 The field `has_arg' is: 00049 no_argument (or 0) if the option does not take an argument, 00050 required_argument (or 1) if the option requires an argument, 00051 optional_argument (or 2) if the option takes an optional argument. 00052 00053 If the field `flag' is not NULL, it points to a variable that is set 00054 to the value given in the field `val' when the option is found, but 00055 left unchanged if the option is not found. 00056 00057 To have a long-named option do something other than set an `int' to 00058 a compiled-in constant, such as set a value from `optarg', set the 00059 option's `flag' field to zero and its `val' field to a nonzero 00060 value (the equivalent single-letter option character, if there is 00061 one). For long options that have a zero `flag' field, `getopt' 00062 returns the contents of the `val' field. */ 00063 00064 struct option 00065 { 00066 const char *name; 00067 /* has_arg can't be an enum because some compilers complain about 00068 type mismatches in all the code that assumes it is an int. */ 00069 int has_arg; 00070 int *flag; 00071 int val; 00072 }; 00073 00074 /* Names for the values of the `has_arg' field of `struct option'. */ 00075 00076 #define no_argument 0 00077 #define required_argument 1 00078 #define optional_argument 2 00079 00080 L4_CV int getopt (int argc, char *const *argv, const char *shortopts); 00081 00082 L4_CV int getopt_long (int argc, char *const *argv, const char *shortopts, 00083 const struct option *longopts, int *longind); 00084 L4_CV int getopt_long_only (int argc, char *const *argv, 00085 const char *shortopts, 00086 const struct option *longopts, int *longind); 00087 00088 L4_CV int _getopt_internal (int argc, char *const *argv, 00089 const char *shortopts, 00090 const struct option *longopts, int *longind, 00091 int long_only); 00092 00093 EXTERN_C_END 00094 00095 #endif /* _GETOPT_H */