~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_getopt.c

  • Committer: Brian Aker
  • Date: 2008-07-13 22:45:08 UTC
  • Revision ID: brian@tangent.org-20080713224508-hb20z4okblotb39a
longlong replacement

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <errno.h>
23
23
 
24
24
typedef void (*init_func_p)(const struct my_option *option, char **variable,
25
 
                            longlong value);
 
25
                            int64_t value);
26
26
 
27
27
static void default_reporter(enum loglevel level, const char *format, ...);
28
28
my_error_reporter my_getopt_error_reporter= &default_reporter;
30
30
static int findopt(char *optpat, uint length,
31
31
                   const struct my_option **opt_res,
32
32
                   char **ffname);
33
 
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err);
 
33
static int64_t getopt_ll(char *arg, const struct my_option *optp, int *err);
34
34
static uint64_t getopt_ull(char *arg, const struct my_option *optp,
35
35
                            int *err);
36
36
static double getopt_double(char *arg, const struct my_option *optp, int *err);
37
37
static void init_variables(const struct my_option *options,
38
38
                           init_func_p init_one_value);
39
39
static void init_one_value(const struct my_option *option, char **variable,
40
 
                           longlong value);
 
40
                           int64_t value);
41
41
static void fini_one_value(const struct my_option *option, char **variable,
42
 
                           longlong value);
 
42
                           int64_t value);
43
43
static int setval(const struct my_option *opts, char* *value, char *argument,
44
44
                  bool set_maximum_value);
45
45
static char *check_struct_option(char *cur_arg, char *key_name);
616
616
      *((long*) result_pos)= (long) getopt_ull(argument, opts, &err);
617
617
      break;
618
618
    case GET_LL:
619
 
      *((longlong*) result_pos)= getopt_ll(argument, opts, &err);
 
619
      *((int64_t*) result_pos)= getopt_ll(argument, opts, &err);
620
620
      break;
621
621
    case GET_ULL:
622
622
      *((uint64_t*) result_pos)= getopt_ull(argument, opts, &err);
733
733
  be k|K for kilo, m|M for mega or g|G for giga.
734
734
*/
735
735
 
736
 
static longlong eval_num_suffix(char *argument, int *error, char *option_name)
 
736
static int64_t eval_num_suffix(char *argument, int *error, char *option_name)
737
737
{
738
738
  char *endchar;
739
 
  longlong num;
 
739
  int64_t num;
740
740
  
741
741
  *error= 0;
742
742
  errno= 0;
776
776
  In case of an error, set error value in *err.
777
777
*/
778
778
 
779
 
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err)
 
779
static int64_t getopt_ll(char *arg, const struct my_option *optp, int *err)
780
780
{
781
 
  longlong num=eval_num_suffix(arg, err, (char*) optp->name);
 
781
  int64_t num=eval_num_suffix(arg, err, (char*) optp->name);
782
782
  return getopt_ll_limit_value(num, optp, NULL);
783
783
}
784
784
 
789
789
  Returns "fixed" value.
790
790
*/
791
791
 
792
 
longlong getopt_ll_limit_value(longlong num, const struct my_option *optp,
 
792
int64_t getopt_ll_limit_value(int64_t num, const struct my_option *optp,
793
793
                               bool *fix)
794
794
{
795
 
  longlong old= num;
 
795
  int64_t old= num;
796
796
  bool adjusted= FALSE;
797
797
  char buf1[255], buf2[255];
798
798
  uint64_t block_size= (optp->block_size ? (uint64_t) optp->block_size : 1L);
806
806
 
807
807
  switch ((optp->var_type & GET_TYPE_MASK)) {
808
808
  case GET_INT:
809
 
    if (num > (longlong) INT_MAX)
 
809
    if (num > (int64_t) INT_MAX)
810
810
    {
811
 
      num= ((longlong) INT_MAX);
 
811
      num= ((int64_t) INT_MAX);
812
812
      adjusted= TRUE;
813
813
    }
814
814
    break;
815
815
  case GET_LONG:
816
816
#if SIZEOF_LONG < SIZEOF_LONG_LONG
817
 
    if (num > (longlong) LONG_MAX)
 
817
    if (num > (int64_t) LONG_MAX)
818
818
    {
819
 
      num= ((longlong) LONG_MAX);
 
819
      num= ((int64_t) LONG_MAX);
820
820
      adjusted= TRUE;
821
821
    }
822
822
#endif
827
827
  }
828
828
 
829
829
  num= ((num - optp->sub_size) / block_size);
830
 
  num= (longlong) (num * block_size);
 
830
  num= (int64_t) (num * block_size);
831
831
 
832
832
  if (num < optp->min_value)
833
833
  {
958
958
*/
959
959
 
960
960
static void init_one_value(const struct my_option *option, char** variable,
961
 
                           longlong value)
 
961
                           int64_t value)
962
962
{
963
963
  DBUG_ENTER("init_one_value");
964
964
  switch ((option->var_type & GET_TYPE_MASK)) {
979
979
    *((ulong*) variable)= (ulong) value;
980
980
    break;
981
981
  case GET_LL:
982
 
    *((longlong*) variable)= (longlong) value;
 
982
    *((int64_t*) variable)= (int64_t) value;
983
983
    break;
984
984
  case GET_ULL:
985
985
  case GET_SET:
992
992
    /*
993
993
      Do not clear variable value if it has no default value.
994
994
      The default value may already be set.
995
 
      NOTE: To avoid compiler warnings, we first cast longlong to intptr,
 
995
      NOTE: To avoid compiler warnings, we first cast int64_t to intptr,
996
996
      so that the value has the same size as a pointer.
997
997
    */
998
998
    if ((char*) (intptr) value)
1002
1002
    /*
1003
1003
      Do not clear variable value if it has no default value.
1004
1004
      The default value may already be set.
1005
 
      NOTE: To avoid compiler warnings, we first cast longlong to intptr,
 
1005
      NOTE: To avoid compiler warnings, we first cast int64_t to intptr,
1006
1006
      so that the value has the same size as a pointer.
1007
1007
    */
1008
1008
    if ((char*) (intptr) value)
1028
1028
*/
1029
1029
 
1030
1030
static void fini_one_value(const struct my_option *option, char **variable,
1031
 
                           longlong value __attribute__ ((unused)))
 
1031
                           int64_t value __attribute__ ((unused)))
1032
1032
{
1033
1033
  DBUG_ENTER("fini_one_value");
1034
1034
  switch ((option->var_type & GET_TYPE_MASK)) {
1236
1236
        printf("%lu\n", *((ulong*) value));
1237
1237
        break;
1238
1238
      case GET_LL:
1239
 
        printf("%s\n", llstr(*((longlong*) value), buff));
 
1239
        printf("%s\n", llstr(*((int64_t*) value), buff));
1240
1240
        break;
1241
1241
      case GET_ULL:
1242
 
        longlong2str(*((uint64_t*) value), buff, 10);
 
1242
        int64_t2str(*((uint64_t*) value), buff, 10);
1243
1243
        printf("%s\n", buff);
1244
1244
        break;
1245
1245
      case GET_DOUBLE: