summaryrefslogtreecommitdiff
path: root/include/apr_getopt.h
diff options
context:
space:
mode:
authorgstein <gstein@13f79535-47bb-0310-9956-ffa450edef68>2000-11-17 07:56:52 +0000
committergstein <gstein@13f79535-47bb-0310-9956-ffa450edef68>2000-11-17 07:56:52 +0000
commitca5d5c7891b576a96a1a8404c2a2dd3639f200c3 (patch)
treefb18046ed3b4e84f43e1f4c0a62072bdfbebd808 /include/apr_getopt.h
parent0c32ac03bb24856f6d9b302b161e9b260dbb49b2 (diff)
downloadlibapr-ca5d5c7891b576a96a1a8404c2a2dd3639f200c3.tar.gz
include/apr_getopt.h:
*) Added new struct and typedef for apr_getopt_long_t. *) Added prototype and inline documentation for new apr_getopt_long function. misc/unix/getopt.c: *) Added new apr_getopt_long function to handle long option processing. *) Added static method pretty_path() to avoid duplicating code *) modified apr_getopt to use pretty_path. Removed cut-and-paste code as well as char *p. Submitted by: B. W. Fitzpatrick <fitz@red-bean.com> Reviewed by: Greg Stein git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@60752 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'include/apr_getopt.h')
-rw-r--r--include/apr_getopt.h57
1 files changed, 53 insertions, 4 deletions
diff --git a/include/apr_getopt.h b/include/apr_getopt.h
index 91be72c28..76d13e2aa 100644
--- a/include/apr_getopt.h
+++ b/include/apr_getopt.h
@@ -82,6 +82,20 @@ struct apr_getopt_t {
char const* place;
};
+typedef struct apr_getopt_long_t apr_getopt_long_t;
+
+/* structure representing a single longopt */
+struct apr_getopt_long_t {
+ /** the name of the long argument (sans "--") */
+ const char *name;
+ /** 0 for no arg, 1 for arg */
+ int has_arg;
+ /** Either the short option char that this option corresponds to
+ * or a unique integer > 255
+ */
+ int val;
+};
+
/**
* Initialize the arguments for parsing by apr_getopt().
* @param cont The pool to operate on
@@ -92,7 +106,7 @@ struct apr_getopt_t {
* @deffunc apr_status_t apr_initopt(apr_getopt_t **os, apr_pool_t *cont,int argc, char *const *argv)
*/
APR_DECLARE(apr_status_t) apr_initopt(apr_getopt_t **os, apr_pool_t *cont,
- int argc, char *const *argv);
+ int argc, char *const *argv);
/**
* Parse the options initialized by apr_initopt().
@@ -112,8 +126,43 @@ APR_DECLARE(apr_status_t) apr_initopt(apr_getopt_t **os, apr_pool_t *cont,
* @deffunc apr_status_t apr_getopt(apr_getopt_t *os, const char *opts, char *optch, const char **optarg)
*/
APR_DECLARE(apr_status_t) apr_getopt(apr_getopt_t *os, const char *opts,
- char *optch, const char **optarg);
-
-#endif /* ! APR_GETOPT_H */
+ char *optch, const char **optarg);
+/**
+ * Parse the options initialized by apr_initopt(), accepting long
+ * options beginning with "--" in addition to single-character
+ * options beginning with "-" (which are passed along to apr_getopt).
+ *
+ * Long options are accepted in both "--foo bar" and well as
+ * "--foo=bar" format
+ *
+ * End of argument processing if we encounter "--" or any option that
+ * doesn't start with "-" or "--".
+ *
+ * @param os The apr_opt_t structure returned by apr_initopt()
+ * @param opts A string of acceptable single-character options to the
+ * program. Characters followed by ":" are required to have
+ * an argument associated
+ * @param longopts A pointer to an array of apr_long_option_t structures, which
+ * can be initialized with { "name", has_args, val }. has_args
+ * is nonzero if the option requires an argument. A structure
+ * with a NULL name terminates the list
+ * @param optval The next option character parsed, or the value of "optval"
+ * from the appropriate apr_long_option_t structure if
+ * the next option is a long option.
+ * @param optarg The argument following the option, if any
+ * @tip There are four potential status values on exit. They are:
+ * <PRE>
+ * APR_EOF -- No more options to parse
+ * APR_BADCH -- Found a bad option character
+ * APR_BADARG -- No argument followed @parameter:
+ * APR_SUCCESS -- The next option was found.
+ * </PRE>
+ * @deffunc apr_status_t apr_getopt_long(apr_getopt_t *os, const char *opts, const apr_getopt_long_t *longopts, int *optval, const char **optarg) */
+APR_DECLARE(apr_status_t) apr_getopt_long(apr_getopt_t *os,
+ const char *opts,
+ const apr_getopt_long_t *long_opts,
+ int *optval,
+ const char **optarg);
+#endif /* ! APR_GETOPT_H */