home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / apache_2.2.8-win32-x86-no_ssl.msi / Data1.cab / _EDF74C3F5D0369505E73074CD8E0833E < prev    next >
Text File  |  2006-08-03  |  6KB  |  159 lines

  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2.  * contributor license agreements.  See the NOTICE file distributed with
  3.  * this work for additional information regarding copyright ownership.
  4.  * The ASF licenses this file to You under the Apache License, Version 2.0
  5.  * (the "License"); you may not use this file except in compliance with
  6.  * the License.  You may obtain a copy of the License at
  7.  *
  8.  *     http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16.  
  17. #ifndef APR_GETOPT_H
  18. #define APR_GETOPT_H
  19.  
  20. /**
  21.  * @file apr_getopt.h
  22.  * @brief APR Command Arguments (getopt)
  23.  */
  24.  
  25. #include "apr_pools.h"
  26.  
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif /* __cplusplus */
  30.  
  31. /**
  32.  * @defgroup apr_getopt Command Argument Parsing
  33.  * @ingroup APR 
  34.  * @{
  35.  */
  36.  
  37. /** 
  38.  * defintion of a error function 
  39.  */
  40. typedef void (apr_getopt_err_fn_t)(void *arg, const char *err, ...);
  41.  
  42. /** @see apr_getopt_t */
  43. typedef struct apr_getopt_t apr_getopt_t;
  44.  
  45. /**
  46.  * Structure to store command line argument information.
  47.  */ 
  48. struct apr_getopt_t {
  49.     /** context for processing */
  50.     apr_pool_t *cont;
  51.     /** function to print error message (NULL == no messages) */
  52.     apr_getopt_err_fn_t *errfn;
  53.     /** user defined first arg to pass to error message  */
  54.     void *errarg;
  55.     /** index into parent argv vector */
  56.     int ind;
  57.     /** character checked for validity */
  58.     int opt;
  59.     /** reset getopt */
  60.     int reset;
  61.     /** count of arguments */
  62.     int argc;
  63.     /** array of pointers to arguments */
  64.     const char **argv;
  65.     /** argument associated with option */
  66.     char const* place;
  67.     /** set to nonzero to support interleaving options with regular args */
  68.     int interleave;
  69.     /** start of non-option arguments skipped for interleaving */
  70.     int skip_start;
  71.     /** end of non-option arguments skipped for interleaving */
  72.     int skip_end;
  73. };
  74.  
  75. /** @see apr_getopt_option_t */
  76. typedef struct apr_getopt_option_t apr_getopt_option_t;
  77.  
  78. /**
  79.  * Structure used to describe options that getopt should search for.
  80.  */
  81. struct apr_getopt_option_t {
  82.     /** long option name, or NULL if option has no long name */
  83.     const char *name;
  84.     /** option letter, or a value greater than 255 if option has no letter */
  85.     int optch;
  86.     /** nonzero if option takes an argument */
  87.     int has_arg;
  88.     /** a description of the option */
  89.     const char *description;
  90. };
  91.  
  92. /**
  93.  * Initialize the arguments for parsing by apr_getopt().
  94.  * @param os   The options structure created for apr_getopt()
  95.  * @param cont The pool to operate on
  96.  * @param argc The number of arguments to parse
  97.  * @param argv The array of arguments to parse
  98.  * @remark Arguments 2 and 3 are most commonly argc and argv from main(argc, argv)
  99.  * The errfn is initialized to fprintf(stderr... but may be overridden.
  100.  */
  101. APR_DECLARE(apr_status_t) apr_getopt_init(apr_getopt_t **os, apr_pool_t *cont,
  102.                                       int argc, const char * const *argv);
  103.  
  104. /**
  105.  * Parse the options initialized by apr_getopt_init().
  106.  * @param os     The apr_opt_t structure returned by apr_getopt_init()
  107.  * @param opts   A string of characters that are acceptable options to the 
  108.  *               program.  Characters followed by ":" are required to have an 
  109.  *               option associated
  110.  * @param option_ch  The next option character parsed
  111.  * @param option_arg The argument following the option character:
  112.  * @return There are four potential status values on exit. They are:
  113.  * <PRE>
  114.  *             APR_EOF      --  No more options to parse
  115.  *             APR_BADCH    --  Found a bad option character
  116.  *             APR_BADARG   --  No argument followed the option flag
  117.  *             APR_SUCCESS  --  The next option was found.
  118.  * </PRE>
  119.  */
  120. APR_DECLARE(apr_status_t) apr_getopt(apr_getopt_t *os, const char *opts, 
  121.                                      char *option_ch, const char **option_arg);
  122.  
  123. /**
  124.  * Parse the options initialized by apr_getopt_init(), accepting long
  125.  * options beginning with "--" in addition to single-character
  126.  * options beginning with "-".
  127.  * @param os     The apr_getopt_t structure created by apr_getopt_init()
  128.  * @param opts   A pointer to a list of apr_getopt_option_t structures, which
  129.  *               can be initialized with { "name", optch, has_args }.  has_args
  130.  *               is nonzero if the option requires an argument.  A structure
  131.  *               with an optch value of 0 terminates the list.
  132.  * @param option_ch  Receives the value of "optch" from the apr_getopt_option_t
  133.  *                   structure corresponding to the next option matched.
  134.  * @param option_arg Receives the argument following the option, if any.
  135.  * @return There are four potential status values on exit.   They are:
  136.  * <PRE>
  137.  *             APR_EOF      --  No more options to parse
  138.  *             APR_BADCH    --  Found a bad option character
  139.  *             APR_BADARG   --  No argument followed the option flag
  140.  *             APR_SUCCESS  --  The next option was found.
  141.  * </PRE>
  142.  * When APR_SUCCESS is returned, os->ind gives the index of the first
  143.  * non-option argument.  On error, a message will be printed to stdout unless
  144.  * os->err is set to 0.  If os->interleave is set to nonzero, options can come
  145.  * after arguments, and os->argv will be permuted to leave non-option arguments
  146.  * at the end (the original argv is unaffected).
  147.  */
  148. APR_DECLARE(apr_status_t) apr_getopt_long(apr_getopt_t *os,
  149.                       const apr_getopt_option_t *opts,
  150.                       int *option_ch,
  151.                                           const char **option_arg);
  152. /** @} */
  153.  
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157.  
  158. #endif  /* ! APR_GETOPT_H */
  159.