~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_getopt.cc

  • Committer: Brian Aker
  • Date: 2008-12-01 03:06:56 UTC
  • mfrom: (632.1.9 devel)
  • Revision ID: brian@tangent.org-20081201030656-u1lp02eer6oyxjac
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <stdio.h>
25
25
#include <stdlib.h>
26
26
#include <errno.h>
 
27
#include <iostream>
 
28
 
 
29
using namespace std;
27
30
 
28
31
typedef void (*init_func_p)(const struct my_option *option, char **variable,
29
32
                            int64_t value);
37
40
static int64_t getopt_ll(char *arg, const struct my_option *optp, int *err);
38
41
static uint64_t getopt_ull(char *arg, const struct my_option *optp,
39
42
                            int *err);
 
43
static size_t getopt_size(char *arg, const struct my_option *optp, int *err);
40
44
static double getopt_double(char *arg, const struct my_option *optp, int *err);
41
45
static void init_variables(const struct my_option *options,
42
46
                           init_func_p init_one_value);
626
630
    case GET_ULL:
627
631
      *((uint64_t*) result_pos)= getopt_ull(argument, opts, &err);
628
632
      break;
 
633
    case GET_SIZE:
 
634
      *((size_t*) result_pos)= getopt_size(argument, opts, &err);
 
635
      break;
629
636
    case GET_DOUBLE:
630
637
      *((double*) result_pos)= getopt_double(argument, opts, &err);
631
638
      break;
861
868
}
862
869
 
863
870
 
 
871
static size_t getopt_size(char *arg, const struct my_option *optp, int *err)
 
872
{
 
873
  return (size_t)getopt_ull(arg, optp, err);
 
874
}
 
875
 
 
876
 
 
877
 
864
878
uint64_t getopt_ull_limit_value(uint64_t num, const struct my_option *optp,
865
 
                                 bool *fix)
 
879
                                bool *fix)
866
880
{
867
881
  bool adjusted= false;
868
882
  uint64_t old= num;
890
904
      adjusted= true;
891
905
    }
892
906
    break;
 
907
  case GET_SIZE:
 
908
    if (num > (uint64_t) SIZE_MAX)
 
909
    {
 
910
      num= ((uint64_t) SIZE_MAX);
 
911
      adjusted= true;
 
912
    }
 
913
    break;
893
914
  default:
894
915
    assert((optp->var_type & GET_TYPE_MASK) == GET_ULL);
895
916
    break;
981
1002
  case GET_LL:
982
1003
    *((int64_t*) variable)= (int64_t) value;
983
1004
    break;
 
1005
  case GET_SIZE:
 
1006
    *((size_t*) variable)= (size_t) value;
984
1007
  case GET_ULL:
985
1008
  case GET_SET:
986
1009
    *((uint64_t*) variable)=  (uint64_t) value;
1231
1254
      case GET_ULONG:
1232
1255
        printf("%u\n", *((uint32_t*) value));
1233
1256
        break;
 
1257
      case GET_SIZE:
 
1258
        cout << value;
 
1259
        break;
1234
1260
      case GET_LL:
1235
1261
        printf("%s\n", llstr(*((int64_t*) value), buff));
1236
1262
        break;