/[mailutils]/mailutils/mh/mh_getopt.c
ViewVC logotype

Diff of /mailutils/mh/mh_getopt.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by polak, Thu Dec 26 20:51:06 2002 UTC revision 1.9 by gray, Thu Jan 16 13:43:05 2003 UTC
# Line 25  Line 25 
25  #include <stdlib.h>  #include <stdlib.h>
26  #include <mh_getopt.h>  #include <mh_getopt.h>
27    
28  int mh_optind = 1;  static int mh_optind = 1;
29  char *mh_optarg;  static char *mh_optarg;
30  char *mh_optptr;  static char *mh_optptr;
31    
32  int  int
33  mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc)  mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc)
# Line 46  mh_getopt (int argc, char **argv, struct Line 46  mh_getopt (int argc, char **argv, struct
46        return '+';        return '+';
47      }      }
48        
49    if (mh_optptr[0] != '-')    if (mh_optptr[0] != '-' || mh_optptr[1] == '-')
50      return EOF;      {
51          mh_optind++;
52          return 0;
53        }
54    
55    optlen = strlen (mh_optptr+1);    optlen = strlen (mh_optptr+1);
56    for (p = mh_opt; p->opt; p++)    for (p = mh_opt; p->opt; p++)
# Line 64  mh_getopt (int argc, char **argv, struct Line 67  mh_getopt (int argc, char **argv, struct
67        
68    if (p->opt)    if (p->opt)
69      {      {
70          char *longopt = p->longopt ? p->longopt : p->opt;
71        switch (p->flags)        switch (p->flags)
72          {          {
73          case MH_OPT_BOOL:          case MH_OPT_BOOL:
# Line 71  mh_getopt (int argc, char **argv, struct Line 75  mh_getopt (int argc, char **argv, struct
75              mh_optarg = "no";              mh_optarg = "no";
76            else            else
77              mh_optarg = "yes";              mh_optarg = "yes";
78              asprintf (&argv[mh_optind], "--%s=%s", longopt, mh_optarg);
79            break;            break;
80                        
81          case MH_OPT_ARG:          case MH_OPT_ARG:
82              asprintf (&argv[mh_optind], "--%s", longopt);
83            mh_optarg = argv[++mh_optind];            mh_optarg = argv[++mh_optind];
84            break;            break;
85    
86          default:          default:
87              asprintf (&argv[mh_optind], "--%s", longopt);
88            mh_optarg = NULL;            mh_optarg = NULL;
89          }          }
90        mh_optind++;        mh_optind++;
91        return p->key;        return 1;
92      }      }
93    else if (!strcmp (mh_optptr+1, "help"))    else if (!strcmp (mh_optptr+1, "help"))
94      {      {
# Line 92  mh_getopt (int argc, char **argv, struct Line 99  mh_getopt (int argc, char **argv, struct
99  }  }
100    
101  void  void
102    mh_argv_preproc (int argc, char **argv, struct mh_argp_data *data)
103    {
104      mh_optind = 1;
105      while (mh_getopt (argc, argv, data->mh_option, data->doc) != EOF)
106        ;
107    }
108    
109    void
110  mh_help (struct mh_option *mh_opt, const char *doc)  mh_help (struct mh_option *mh_opt, const char *doc)
111  {  {
112    struct mh_option *p;    struct mh_option *p;

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26