00001 /* 00002 * my_getopt.h - interface to my re-implementation of getopt. 00003 * Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler 00004 * 00005 * Permission is hereby granted, free of charge, to any person 00006 * obtaining a copy of this software and associated documentation 00007 * files (the "Software"), to deal in the Software without 00008 * restriction, including without limitation the rights to use, copy, 00009 * modify, merge, publish, distribute, sublicense, and/or sell copies 00010 * of the Software, and to permit persons to whom the Software is 00011 * furnished to do so, subject to the following conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be 00014 * included in all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00020 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00021 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00022 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00023 * DEALINGS IN THE SOFTWARE. 00024 */ 00025 00026 #ifndef MY_GETOPT_H_INCLUDED 00027 #define MY_GETOPT_H_INCLUDED 00028 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif 00032 00033 /* reset argument parser to start-up values */ 00034 extern int my_getopt_reset(void); 00035 00036 /* UNIX-style short-argument parser */ 00037 extern int my_getopt(int argc, char * argv[], const char *opts); 00038 00039 extern int my_optind, my_opterr, my_optopt; 00040 extern char *my_optarg; 00041 00042 struct option { 00043 const char *name; 00044 int has_arg; 00045 int *flag; 00046 int val; 00047 }; 00048 00049 /* human-readable values for has_arg */ 00050 #undef no_argument 00051 #define no_argument 0 00052 #undef required_argument 00053 #define required_argument 1 00054 #undef optional_argument 00055 #define optional_argument 2 00056 00057 /* GNU-style long-argument parsers */ 00058 extern int my_getopt_long(int argc, char * argv[], const char *shortopts, 00059 const struct option *longopts, int *longind); 00060 00061 extern int my_getopt_long_only(int argc, char * argv[], const char *shortopts, 00062 const struct option *longopts, int *longind); 00063 00064 extern int _my_getopt_internal(int argc, char * argv[], const char *shortopts, 00065 const struct option *longopts, int *longind, 00066 int long_only); 00067 00068 #ifdef __cplusplus 00069 } 00070 #endif 00071 00072 #endif /* MY_GETOPT_H_INCLUDED */