cmdopt.h
 1  #ifndef     __COMMAND_LINE_OPTION_H_
 2  #define     __COMMAND_LINE_OPTION_H_
 3  
 4  
 5  #ifdef  __cplusplus
 6  extern  "C" {
 7  #endif
 8  
 9  
10  // Long option.
11  typedef     struct LongOpt
12  {
13      const char  *name;      // Option name.
14                              // Name of the last option must be NULL.
15      int         has_arg;    // Option has argument (1), has no argument (0),
16                              // may have argument (2).
17      int         *flag;      // If flag isn't NULL,
18                              // opts_get() overwrites *flag by return value.
19      int         val;        // Return value.
20  }   LongOpt, *hLongOpt;
21  
22  // Command line option.
23  typedef     struct CmdOpt
24  {
25      // Arguments.
26      int     argc;
27      char    **argv;
28  
29      // Setting.
30      const LongOpt   *longopts;      // Long options.
31      const char      *optstring;     // Option string.
32  
33      // Status.
34      int     optind;     // Index of target option.
35      char    *nextchar;  // Next character.
36      char    *optarg;    // Argument of option.
37      int     optopt;     // Option character.
38      char    *optlong;   // Long option.
39      int     opterr;     // Warning level ( 0: no, 1: error, 2: all ).
40      int     longindex;  // Index of long option.
41      int     optnum;     // Number of options.
42  }   CmdOpt, *hCmdOpt;
43  
44  
45  // Analyze command line option.
46  int     CmdOpt_Get( hCmdOpt h );
47  // Initialize structure.
48  void    CmdOpt_Init( hCmdOpt h, int argc, char **argv,
49                       const char *optstring, const LongOpt *longopts );
50  
51  
52  #ifdef  __cplusplus
53  }
54  #endif
55  
56  
57  #endif