~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to mysys/my_getopt.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2002-2006 MySQL AB
 
1
/*
 
2
   Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
2
3
 
3
4
   This program is free software; you can redistribute it and/or modify
4
5
   it under the terms of the GNU General Public License as published by
11
12
 
12
13
   You should have received a copy of the GNU General Public License
13
14
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
16
*/
15
17
 
16
18
#include <my_global.h>
17
19
#include <m_string.h>
30
32
 
31
33
static int findopt(char *optpat, uint length,
32
34
                   const struct my_option **opt_res,
33
 
                   char **ffname);
 
35
                   const char **ffname);
34
36
my_bool getopt_compare_strings(const char *s,
35
37
                               const char *t,
36
38
                               uint length);
112
114
                   const struct my_option *longopts,
113
115
                   my_get_one_option get_one_option)
114
116
{
115
 
  uint opt_found, argvpos= 0, length;
 
117
  uint UNINIT_VAR(opt_found), argvpos= 0, length;
116
118
  my_bool end_of_options= 0, must_be_var, set_maximum_value,
117
119
          option_is_loose;
118
 
  char **pos, **pos_end, *optend, *UNINIT_VAR(prev_found),
119
 
       *opt_str, key_name[FN_REFLEN];
 
120
  char **pos, **pos_end, *optend, *opt_str, key_name[FN_REFLEN];
 
121
  const char *UNINIT_VAR(prev_found);
120
122
  const struct my_option *optp;
121
123
  void *value;
122
124
  int error, i;
123
125
 
124
 
  LINT_INIT(opt_found);
125
126
  /* handle_options() assumes arg0 (program name) always exists */
126
127
  DBUG_ASSERT(argc && *argc >= 1);
127
128
  DBUG_ASSERT(argv && *argv);
225
226
          Find first the right option. Return error in case of an ambiguous,
226
227
          or unknown option
227
228
        */
228
 
        LINT_INIT(prev_found);
229
229
        optp= longopts;
230
230
        if (!(opt_found= findopt(opt_str, length, &optp, &prev_found)))
231
231
        {
657
657
        return EXIT_OUT_OF_MEMORY;
658
658
      break;
659
659
    case GET_ENUM:
660
 
      if (((*(int*)result_pos)=
661
 
             find_type(argument, opts->typelib, 2) - 1) < 0)
662
660
      {
663
 
        /*
664
 
          Accept an integer representation of the enumerated item.
665
 
        */
666
 
        char *endptr;
667
 
        unsigned int arg= (unsigned int) strtol(argument, &endptr, 10);
668
 
        if (*endptr || arg >= opts->typelib->count)
669
 
          return EXIT_ARGUMENT_INVALID;
670
 
        *(int*)result_pos= arg;
 
661
        int type= find_type(argument, opts->typelib, 2);
 
662
        if (type < 1)
 
663
        {
 
664
          /*
 
665
            Accept an integer representation of the enumerated item.
 
666
          */
 
667
          char *endptr;
 
668
          ulong arg= strtoul(argument, &endptr, 10);
 
669
          if (*endptr || arg >= opts->typelib->count)
 
670
            return EXIT_ARGUMENT_INVALID;
 
671
          *((ulong*) result_pos)= arg;
 
672
        }
 
673
        else
 
674
          *((ulong*) result_pos)= type - 1;
671
675
      }
672
676
      break;
673
677
    case GET_SET:
709
713
 
710
714
static int findopt(char *optpat, uint length,
711
715
                   const struct my_option **opt_res,
712
 
                   char **ffname)
 
716
                   const char **ffname)
713
717
{
714
718
  uint count;
715
 
  struct my_option *opt= (struct my_option *) *opt_res;
 
719
  const struct my_option *opt= *opt_res;
716
720
 
717
721
  for (count= 0; opt->name; opt++)
718
722
  {
723
727
        return 1;
724
728
      if (!count)
725
729
      {
 
730
        /* We only need to know one prev */
726
731
        count= 1;
727
 
        *ffname= (char *) opt->name;    /* We only need to know one prev */
 
732
        *ffname= opt->name;
728
733
      }
729
734
      else if (strcmp(*ffname, opt->name))
730
735
      {
1004
1009
    *((int*) variable)= (int) getopt_ll_limit_value((int) value, option, NULL);
1005
1010
    break;
1006
1011
  case GET_ENUM:
1007
 
    *((uint*) variable)= (uint) value;
 
1012
    *((ulong*) variable)= (ulong) value;
1008
1013
    break;
1009
1014
  case GET_UINT:
1010
1015
    *((uint*) variable)= (uint) getopt_ull_limit_value((uint) value, option, NULL);
1244
1249
        }
1245
1250
        break;
1246
1251
      case GET_ENUM:
1247
 
        printf("%s\n", get_type(optp->typelib, *(uint*) value));
 
1252
        printf("%s\n", get_type(optp->typelib, *(ulong*) value));
1248
1253
        break;
1249
1254
      case GET_STR:
1250
1255
      case GET_STR_ALLOC:                    /* fall through */