~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_getopt.c

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "mysys_priv.h"
17
 
#include <drizzled/gettext.h>
 
17
#include <libdrizzle/gettext.h>
18
18
 
19
19
#include <mystrings/m_string.h>
20
20
#include <stdlib.h>
29
29
static void default_reporter(enum loglevel level, const char *format, ...);
30
30
my_error_reporter my_getopt_error_reporter= &default_reporter;
31
31
 
32
 
static int findopt(char *optpat, uint32_t length,
 
32
static int findopt(char *optpat, uint length,
33
33
                   const struct my_option **opt_res,
34
34
                   char **ffname);
35
35
static int64_t getopt_ll(char *arg, const struct my_option *optp, int *err);
52
52
*/
53
53
static const char *special_opt_prefix[]=
54
54
{"skip", "disable", "enable", "maximum", "loose", 0};
55
 
static const uint32_t special_opt_prefix_lengths[]=
 
55
static const uint special_opt_prefix_lengths[]=
56
56
{ 4,      7,         6,        7,         5,      0};
57
57
enum enum_special_opt
58
58
{ OPT_SKIP, OPT_DISABLE, OPT_ENABLE, OPT_MAXIMUM, OPT_LOOSE};
111
111
                   const struct my_option *longopts,
112
112
                   my_get_one_option get_one_option)
113
113
{
114
 
  uint32_t opt_found, argvpos= 0, length;
 
114
  uint opt_found, argvpos= 0, length;
115
115
  bool end_of_options= 0, must_be_var, set_maximum_value=false,
116
116
          option_is_loose;
117
117
  char **pos, **pos_end, *optend, *prev_found=NULL,
386
386
              */
387
387
            (*argc)--;
388
388
            if (!optend || *optend == '1' ||
389
 
                !my_strcasecmp(&my_charset_utf8_general_ci, optend, "true"))
 
389
                !my_strcasecmp(&my_charset_latin1, optend, "true"))
390
390
              *((bool*) value)= (bool) 1;
391
391
            else if (*optend == '0' ||
392
 
                     !my_strcasecmp(&my_charset_utf8_general_ci, optend, "false"))
 
392
                     !my_strcasecmp(&my_charset_latin1, optend, "false"))
393
393
              *((bool*) value)= (bool) 0;
394
394
            else
395
395
            {
443
443
          opt_found= 0;
444
444
          for (optp= longopts; optp->id; optp++)
445
445
          {
446
 
            if (optp->id == (int) (unsigned char) *optend)
 
446
            if (optp->id == (int) (uchar) *optend)
447
447
            {
448
448
              /* Option recognized. Find next what to do with it */
449
449
              opt_found= 1;
574
574
  */
575
575
  if ((ptr != NULL) && (end != NULL) && (end - ptr > 1))
576
576
  {
577
 
    uint32_t len= (uint) (ptr - cur_arg);
 
577
    uint len= (uint) (ptr - cur_arg);
578
578
    set_if_smaller(len, FN_REFLEN-1);
579
579
    strmake(key_name, cur_arg, len);
580
580
    return ++ptr;
636
636
      break;
637
637
    case GET_STR_ALLOC:
638
638
      if ((*((char**) result_pos)))
639
 
        free((*(char**) result_pos));
 
639
        my_free((*(char**) result_pos), MYF(MY_WME | MY_FAE));
640
640
      if (!(*((char**) result_pos)= my_strdup(argument, MYF(MY_WME))))
641
641
        return EXIT_OUT_OF_MEMORY;
642
642
      break;
681
681
        ffname points to first matching option
682
682
*/
683
683
 
684
 
static int findopt(char *optpat, uint32_t length,
 
684
static int findopt(char *optpat, uint length,
685
685
                   const struct my_option **opt_res,
686
686
                   char **ffname)
687
687
{
688
 
  uint32_t count;
 
688
  uint count;
689
689
  struct my_option *opt= (struct my_option *) *opt_res;
690
690
 
691
691
  for (count= 0; opt->name; opt++)
722
722
*/
723
723
 
724
724
bool getopt_compare_strings(register const char *s, register const char *t,
725
 
                               uint32_t length)
 
725
                               uint length)
726
726
{
727
727
  char const *end= s + length;
728
728
  for (;s != end ; s++, t++)
820
820
    }
821
821
    break;
822
822
  case GET_LONG:
823
 
    if (num > (int64_t) INT32_MAX)
 
823
#if SIZEOF_LONG < SIZEOF_LONG_LONG
 
824
    if (num > (int64_t) LONG_MAX)
824
825
    {
825
 
      num= ((int64_t) INT32_MAX);
 
826
      num= ((int64_t) LONG_MAX);
826
827
      adjusted= true;
827
828
    }
 
829
#endif
828
830
    break;
829
831
  default:
830
832
    assert((optp->var_type & GET_TYPE_MASK) == GET_LL);
852
854
/*
853
855
  function: getopt_ull
854
856
 
855
 
  This is the same as getopt_ll, but is meant for uint64_t
 
857
  This is the same as getopt_ll, but is meant for unsigned long long
856
858
  values.
857
859
*/
858
860
 
886
888
    }
887
889
    break;
888
890
  case GET_ULONG:
889
 
    if (num > (uint64_t) UINT32_MAX)
 
891
#if SIZEOF_LONG < SIZEOF_LONG_LONG
 
892
    if (num > (uint64_t) ULONG_MAX)
890
893
    {
891
 
      num= ((uint64_t) UINT32_MAX);
 
894
      num= ((uint64_t) ULONG_MAX);
892
895
      adjusted= true;
893
896
    }
 
897
#endif
894
898
    break;
895
899
  default:
896
900
    assert((optp->var_type & GET_TYPE_MASK) == GET_ULL);
948
952
  }
949
953
  if (optp->max_value && num > (double) optp->max_value)
950
954
    num= (double) optp->max_value;
951
 
  return cmax(num, (double) optp->min_value);
 
955
  return max(num, (double) optp->min_value);
952
956
}
953
957
 
954
958
/*
1009
1013
    */
1010
1014
    if ((char*) (intptr_t) value)
1011
1015
    {
1012
 
      free((*(char**) variable));
 
1016
      my_free((*(char**) variable), MYF(MY_ALLOW_ZERO_PTR));
1013
1017
      *((char**) variable)= my_strdup((char*) (intptr_t) value, MYF(MY_WME));
1014
1018
    }
1015
1019
    break;
1034
1038
{
1035
1039
  switch ((option->var_type & GET_TYPE_MASK)) {
1036
1040
  case GET_STR_ALLOC:
1037
 
    free((*(char**) variable));
 
1041
    my_free((*(char**) variable), MYF(MY_ALLOW_ZERO_PTR));
1038
1042
    *((char**) variable)= NULL;
1039
1043
    break;
1040
1044
  default: /* dummy default to avoid compiler warnings */
1094
1098
 
1095
1099
void my_print_help(const struct my_option *options)
1096
1100
{
1097
 
  uint32_t col, name_space= 22, comment_space= 57;
 
1101
  uint col, name_space= 22, comment_space= 57;
1098
1102
  const char *line_end;
1099
1103
  const struct my_option *optp;
1100
1104
 
1178
1182
 
1179
1183
void my_print_variables(const struct my_option *options)
1180
1184
{
1181
 
  uint32_t name_space= 34, length, nr;
 
1185
  uint name_space= 34, length, nr;
1182
1186
  uint64_t bit, llvalue;
1183
1187
  char buff[255];
1184
1188
  const struct my_option *optp;