Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

apr_getopt.h

Go to the documentation of this file.
00001 /* Copyright 2000-2004 The Apache Software Foundation 00002 * 00003 * Licensed under the Apache License, Version 2.0 (the "License"); 00004 * you may not use this file except in compliance with the License. 00005 * You may obtain a copy of the License at 00006 * 00007 * http://www.apache.org/licenses/LICENSE-2.0 00008 * 00009 * Unless required by applicable law or agreed to in writing, software 00010 * distributed under the License is distributed on an "AS IS" BASIS, 00011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 * See the License for the specific language governing permissions and 00013 * limitations under the License. 00014 */ 00015 00016 #ifndef APR_GETOPT_H 00017 #define APR_GETOPT_H 00018 00019 /** 00020 * @file apr_getopt.h 00021 * @brief APR Command Arguments (getopt) 00022 */ 00023 00024 #include "apr_pools.h" 00025 00026 #ifdef __cplusplus 00027 extern "C" { 00028 #endif /* __cplusplus */ 00029 00030 /** 00031 * @defgroup apr_getopt Command Argument Parsing 00032 * @ingroup APR 00033 * @{ 00034 */ 00035 00036 /** 00037 * defintion of a error function 00038 */ 00039 typedef void (apr_getopt_err_fn_t)(void *arg, const char *err, ...); 00040 00041 /** @see apr_getopt_t */ 00042 typedef struct apr_getopt_t apr_getopt_t; 00043 00044 /** 00045 * Structure to store command line argument information. 00046 */ 00047 struct apr_getopt_t { 00048 /** context for processing */ 00049 apr_pool_t *cont; 00050 /** function to print error message (NULL == no messages) */ 00051 apr_getopt_err_fn_t *errfn; 00052 /** user defined first arg to pass to error message */ 00053 void *errarg; 00054 /** index into parent argv vector */ 00055 int ind; 00056 /** character checked for validity */ 00057 int opt; 00058 /** reset getopt */ 00059 int reset; 00060 /** count of arguments */ 00061 int argc; 00062 /** array of pointers to arguments */ 00063 const char **argv; 00064 /** argument associated with option */ 00065 char const* place; 00066 /** set to nonzero to support interleaving options with regular args */ 00067 int interleave; 00068 /** start of non-option arguments skipped for interleaving */ 00069 int skip_start; 00070 /** end of non-option arguments skipped for interleaving */ 00071 int skip_end; 00072 }; 00073 00074 /** @see apr_getopt_option_t */ 00075 typedef struct apr_getopt_option_t apr_getopt_option_t; 00076 00077 /** 00078 * Structure used to describe options that getopt should search for. 00079 */ 00080 struct apr_getopt_option_t { 00081 /** long option name, or NULL if option has no long name */ 00082 const char *name; 00083 /** option letter, or a value greater than 255 if option has no letter */ 00084 int optch; 00085 /** nonzero if option takes an argument */ 00086 int has_arg; 00087 /** a description of the option */ 00088 const char *description; 00089 }; 00090 00091 /** 00092 * Initialize the arguments for parsing by apr_getopt(). 00093 * @param os The options structure created for apr_getopt() 00094 * @param cont The pool to operate on 00095 * @param argc The number of arguments to parse 00096 * @param argv The array of arguments to parse 00097 * @remark Arguments 2 and 3 are most commonly argc and argv from main(argc, argv) 00098 * The errfn is initialized to fprintf(stderr... but may be overridden. 00099 */ 00100 APR_DECLARE(apr_status_t) apr_getopt_init(apr_getopt_t **os, apr_pool_t *cont, 00101 int argc, const char * const *argv); 00102 00103 /** 00104 * Parse the options initialized by apr_getopt_init(). 00105 * @param os The apr_opt_t structure returned by apr_getopt_init() 00106 * @param opts A string of characters that are acceptable options to the 00107 * program. Characters followed by ":" are required to have an 00108 * option associated 00109 * @param option_ch The next option character parsed 00110 * @param option_arg The argument following the option character: 00111 * @return There are four potential status values on exit. They are: 00112 * <PRE> 00113 * APR_EOF -- No more options to parse 00114 * APR_BADCH -- Found a bad option character 00115 * APR_BADARG -- No argument followed the option flag 00116 * APR_SUCCESS -- The next option was found. 00117 * </PRE> 00118 */ 00119 APR_DECLARE(apr_status_t) apr_getopt(apr_getopt_t *os, const char *opts, 00120 char *option_ch, const char **option_arg); 00121 00122 /** 00123 * Parse the options initialized by apr_getopt_init(), accepting long 00124 * options beginning with "--" in addition to single-character 00125 * options beginning with "-". 00126 * @param os The apr_getopt_t structure created by apr_getopt_init() 00127 * @param opts A pointer to a list of apr_getopt_option_t structures, which 00128 * can be initialized with { "name", optch, has_args }. has_args 00129 * is nonzero if the option requires an argument. A structure 00130 * with an optch value of 0 terminates the list. 00131 * @param option_ch Receives the value of "optch" from the apr_getopt_option_t 00132 * structure corresponding to the next option matched. 00133 * @param option_arg Receives the argument following the option, if any. 00134 * @return There are four potential status values on exit. They are: 00135 * <PRE> 00136 * APR_EOF -- No more options to parse 00137 * APR_BADCH -- Found a bad option character 00138 * APR_BADARG -- No argument followed the option flag 00139 * APR_SUCCESS -- The next option was found. 00140 * </PRE> 00141 * When APR_SUCCESS is returned, os->ind gives the index of the first 00142 * non-option argument. On error, a message will be printed to stdout unless 00143 * os->err is set to 0. If os->interleave is set to nonzero, options can come 00144 * after arguments, and os->argv will be permuted to leave non-option arguments 00145 * at the end (the original argv is unaffected). 00146 */ 00147 APR_DECLARE(apr_status_t) apr_getopt_long(apr_getopt_t *os, 00148 const apr_getopt_option_t *opts, 00149 int *option_ch, 00150 const char **option_arg); 00151 /** @} */ 00152 00153 #ifdef __cplusplus 00154 } 00155 #endif 00156 00157 #endif /* ! APR_GETOPT_H */

Generated on Thu Sep 16 13:47:10 2004 for Apache Portable Runtime by doxygen 1.3.7