Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

option.h

Go to the documentation of this file.
00001 /*! \file option.h
00002     This file defines data structures for the option reader.
00003  */
00004 
00005 
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009 
00010 
00011 #ifndef OPTION_H
00012 #define OPTION_H
00013 #endif
00014 
00015 /*! \brief This data structure contains the definition for one option.
00016  */
00017 
00018 typedef struct Option_
00019         {
00020           /*! \brief Pointer to a zero terminated string of characters that represents the option flag.
00021                      Please note that an option's flag should verify the following rules:
00022                      <UL>
00023                          <LI>At least 2 characters.
00024                          <LI>Begin with a '-'.
00025                          <LI>No spaces.
00026                          <LI>Not all '-'.
00027                      </UL>
00028           */
00029           char   *flag;
00030 
00031           /*! \brief This flag defines the number of argument required by the option. The option may require
00032                      zero (ex: --help) or one argument.
00033                      <UL>
00034                          <LI>If you set this argument to the value 0, it means that the option does not
00035                              require any arguemnt (ex: --help).
00036                          <LI>Any other value means that the option requires one (and only one) argument.
00037                      </UL>
00038           */
00039           int    arg;
00040 
00041           /*! \brief The tag defines the maximum number of characters for the option's argument.
00042           */
00043           int    max_size;
00044 
00045           /*! \brief Pointer to a zero terminated string of characters that represents the regular expression
00046                      that matches the option's argument.
00047           */
00048           char   *reg_exp;
00049 
00050           /*! \brief Address to a pointer that will receive the address of the sero terminated string of 
00051                      characters that represents en option's argument.
00052           */ 
00053           char   **pointer;
00054 
00055           /*! \brief Pointer to a zero terminated string of characters that contains a literal description of
00056                      the option.
00057           */
00058           char   *desc;
00059         } Option;
00060 
00061 /*! \brief This data structure is used to store all option definitions for the process.
00062  */
00063 typedef struct Option_set_
00064         {
00065           /*! \brief Pointer to an array of <I>Option</I> data structures that define all the process' options.
00066           */
00067           Option *opt;
00068 
00069           /*! \brief Number of elements in the array pointed by <I>opt</I>.
00070           */
00071           int    count;
00072 
00073           /*! \brief This integer represents the index (in the array of strings that represents the command
00074                      line) of the last item (option or argument) parsed. Following arguments start at index
00075                      <I>last_index</I> + 1.
00076           */
00077           int    last_index; 
00078         } Option_set;
00079 
00080 int init_options (Option_set *opt);
00081 int parse_command_line (char *argv[], int argc, Option_set *opt, char **err, char **flag, char **arg);
00082 int get_argument (Option_set *opt, char *flag, char **arg);
00083 int is_argument_required (Option_set *opt, char *flag);
00084 
00085 /*! \brief Return the index (in the array of strings that represents the command ine) of the last item 
00086            (option or argument) parsed.
00087  */
00088 
00089 #define last_argv_index(options)        (options.last_index)
00090 
00091 #ifdef __cplusplus
00092 }
00093 #endif

Generated on Thu Apr 3 16:23:43 2003 for Common_C_libraries by doxygen1.3-rc1