~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/my_getopt.cc

  • Committer: Brian Aker
  • Date: 2010-01-22 00:53:13 UTC
  • Revision ID: brian@gaz-20100122005313-jmizcbcdi1lt4tcx
Revert db patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "mysys_priv.h"
17
 
#include <libdrizzle/gettext.h>
18
 
 
19
 
#include <mystrings/m_string.h>
 
16
#include "drizzled/internal/mysys_priv.h"
 
17
#include <drizzled/gettext.h>
 
18
 
 
19
#include "drizzled/internal/m_string.h"
 
20
#include "drizzled/internal/my_sys.h"
 
21
#include "drizzled/my_error.h"
 
22
#include "drizzled/my_getopt.h"
 
23
 
 
24
#include <stdio.h>
20
25
#include <stdlib.h>
21
 
#include <my_sys.h>
22
 
#include <mysys_err.h>
23
 
#include <my_getopt.h>
24
26
#include <errno.h>
 
27
#include <iostream>
 
28
#include <algorithm>
 
29
 
 
30
using namespace std;
25
31
 
26
32
typedef void (*init_func_p)(const struct my_option *option, char **variable,
27
33
                            int64_t value);
28
34
 
29
 
static void default_reporter(enum loglevel level, const char *format, ...);
 
35
extern "C" void default_reporter(enum loglevel level, const char *format, ...);
30
36
my_error_reporter my_getopt_error_reporter= &default_reporter;
31
37
 
32
 
static int findopt(char *optpat, uint length,
 
38
static int findopt(char *optpat, uint32_t length,
33
39
                   const struct my_option **opt_res,
34
40
                   char **ffname);
35
41
static int64_t getopt_ll(char *arg, const struct my_option *optp, int *err);
36
42
static uint64_t getopt_ull(char *arg, const struct my_option *optp,
37
43
                            int *err);
 
44
static size_t getopt_size(char *arg, const struct my_option *optp, int *err);
38
45
static double getopt_double(char *arg, const struct my_option *optp, int *err);
39
46
static void init_variables(const struct my_option *options,
40
47
                           init_func_p init_one_value);
52
59
*/
53
60
static const char *special_opt_prefix[]=
54
61
{"skip", "disable", "enable", "maximum", "loose", 0};
55
 
static const uint special_opt_prefix_lengths[]=
 
62
static const uint32_t special_opt_prefix_lengths[]=
56
63
{ 4,      7,         6,        7,         5,      0};
57
64
enum enum_special_opt
58
65
{ OPT_SKIP, OPT_DISABLE, OPT_ENABLE, OPT_MAXIMUM, OPT_LOOSE};
59
66
 
60
67
char *disabled_my_option= (char*) "0";
61
68
 
62
 
/* 
63
 
   This is a flag that can be set in client programs. 0 means that
64
 
   my_getopt will not print error messages, but the client should do
65
 
   it by itself
66
 
*/
67
 
 
68
 
bool my_getopt_print_errors= 1;
69
 
 
70
 
/* 
 
69
/*
71
70
   This is a flag that can be set in client programs. 1 means that
72
71
   my_getopt will skip over options it does not know how to handle.
73
72
*/
74
73
 
75
74
bool my_getopt_skip_unknown= 0;
76
75
 
77
 
static void default_reporter(enum loglevel level,
78
 
                             const char *format, ...)
 
76
extern "C" void default_reporter(enum loglevel level, const char *format, ...)
79
77
{
80
78
  va_list args;
81
79
  va_start(args, format);
89
87
  fflush(stderr);
90
88
}
91
89
 
92
 
/* 
 
90
/*
93
91
  function: handle_options
94
92
 
95
93
  Sort options; put options first, until special end of options (--), or
99
97
  one. Call function 'get_one_option()' once for each option.
100
98
*/
101
99
 
102
 
static char** (*getopt_get_addr)(const char *, uint, const struct my_option *);
103
 
 
104
 
void my_getopt_register_get_addr(char** (*func_addr)(const char *, uint,
105
 
                                                    const struct my_option *))
106
 
{
107
 
  getopt_get_addr= func_addr;
108
 
}
109
 
 
110
 
int handle_options(int *argc, char ***argv, 
 
100
static getopt_get_addr_func getopt_get_addr;
 
101
 
 
102
int handle_options(int *argc, char ***argv,
111
103
                   const struct my_option *longopts,
112
104
                   my_get_one_option get_one_option)
113
105
{
114
 
  uint opt_found, argvpos= 0, length;
 
106
  uint32_t opt_found, argvpos= 0, length;
115
107
  bool end_of_options= 0, must_be_var, set_maximum_value=false,
116
108
          option_is_loose;
117
109
  char **pos, **pos_end, *optend, *prev_found=NULL,
150
142
            /* the argument must be in next argv */
151
143
            if (!*++pos)
152
144
            {
153
 
              if (my_getopt_print_errors)
154
 
                my_getopt_error_reporter(ERROR_LEVEL,
155
 
                                         "%s: Option '-O' requires an argument",
156
 
                                         my_progname);
 
145
              my_getopt_error_reporter(ERROR_LEVEL,
 
146
                                       "%s: Option '-O' requires an argument",
 
147
                                       my_progname);
157
148
              return EXIT_ARGUMENT_REQUIRED;
158
149
            }
159
150
            cur_arg= *pos;
168
159
            cur_arg+= 14;
169
160
            if (!*cur_arg)
170
161
            {
171
 
              if (my_getopt_print_errors)
172
 
                my_getopt_error_reporter(ERROR_LEVEL,
173
 
                                         "%s: Option '--set-variable' requires an argument",
174
 
                                         my_progname);
 
162
              my_getopt_error_reporter(ERROR_LEVEL,
 
163
                                       "%s: Option '--set-variable' requires an argument",
 
164
                                       my_progname);
175
165
              return EXIT_ARGUMENT_REQUIRED;
176
166
            }
177
167
          }
182
172
            /* the argument must be in next argv */
183
173
            if (!*++pos)
184
174
            {
185
 
              if (my_getopt_print_errors)
186
 
                my_getopt_error_reporter(ERROR_LEVEL,
187
 
                                         "%s: Option '--set-variable' requires an argument",
188
 
                                         my_progname);
 
175
              my_getopt_error_reporter(ERROR_LEVEL,
 
176
                                       "%s: Option '--set-variable' requires an argument",
 
177
                                       my_progname);
189
178
              return EXIT_ARGUMENT_REQUIRED;
190
179
            }
191
180
            cur_arg= *pos;
206
195
        optend= strrchr(opt_str, '=');
207
196
        if (optend != NULL)
208
197
        {
209
 
          length= (uint) (optend - opt_str);
 
198
          length= (uint32_t) (optend - opt_str);
210
199
          optend++;
211
200
        }
212
201
        else
213
202
        {
214
 
          length= strlen(opt_str);
 
203
          length= static_cast<uint32_t>(strlen(opt_str));
215
204
          optend= 0;
216
205
        }
217
206
 
248
237
                {
249
238
                  if (opt_found > 1)
250
239
                  {
251
 
                    if (my_getopt_print_errors)
252
 
                      my_getopt_error_reporter(ERROR_LEVEL,
253
 
                                               "%s: ambiguous option '--%s-%s' (--%s-%s)",
254
 
                                               my_progname, special_opt_prefix[i],
255
 
                                               cur_arg, special_opt_prefix[i],
256
 
                                               prev_found);
 
240
                    my_getopt_error_reporter(ERROR_LEVEL,
 
241
                                             "%s: ambiguous option '--%s-%s' (--%s-%s)",
 
242
                                             my_progname, special_opt_prefix[i],
 
243
                                             cur_arg, special_opt_prefix[i],
 
244
                                             prev_found);
257
245
                    return EXIT_AMBIGUOUS_OPTION;
258
246
                  }
259
247
                  switch (i) {
298
286
            }
299
287
            if (must_be_var)
300
288
            {
301
 
              if (my_getopt_print_errors)
302
 
                my_getopt_error_reporter(option_is_loose ? 
303
 
                                           WARNING_LEVEL : ERROR_LEVEL,
304
 
                                         "%s: unknown variable '%s'",
305
 
                                         my_progname, cur_arg);
 
289
              my_getopt_error_reporter(option_is_loose ?
 
290
                                       WARNING_LEVEL : ERROR_LEVEL,
 
291
                                       "%s: unknown variable '%s'",
 
292
                                       my_progname, cur_arg);
306
293
              if (!option_is_loose)
307
294
                return EXIT_UNKNOWN_VARIABLE;
308
295
            }
309
296
            else
310
297
            {
311
 
              if (my_getopt_print_errors)
312
 
                my_getopt_error_reporter(option_is_loose ? 
313
 
                                           WARNING_LEVEL : ERROR_LEVEL,
314
 
                                         "%s: unknown option '--%s'", 
315
 
                                         my_progname, cur_arg);
 
298
              my_getopt_error_reporter(option_is_loose ?
 
299
                                       WARNING_LEVEL : ERROR_LEVEL,
 
300
                                       "%s: unknown option '--%s'",
 
301
                                       my_progname, cur_arg);
316
302
              if (!option_is_loose)
317
303
                return EXIT_UNKNOWN_OPTION;
318
304
            }
327
313
        {
328
314
          if (must_be_var)
329
315
          {
330
 
            if (my_getopt_print_errors)
331
 
              my_getopt_error_reporter(ERROR_LEVEL,
332
 
                                       "%s: variable prefix '%s' is not unique",
333
 
                                       my_progname, opt_str);
 
316
            my_getopt_error_reporter(ERROR_LEVEL,
 
317
                                     "%s: variable prefix '%s' is not unique",
 
318
                                     my_progname, opt_str);
334
319
            return EXIT_VAR_PREFIX_NOT_UNIQUE;
335
320
          }
336
321
          else
337
322
          {
338
 
            if (my_getopt_print_errors)
339
 
              my_getopt_error_reporter(ERROR_LEVEL,
340
 
                                       "%s: ambiguous option '--%s' (%s, %s)",
341
 
                                       my_progname, opt_str, prev_found, 
342
 
                                       optp->name);
 
323
            my_getopt_error_reporter(ERROR_LEVEL,
 
324
                                     "%s: ambiguous option '--%s' (%s, %s)",
 
325
                                     my_progname, opt_str, prev_found,
 
326
                                     optp->name);
343
327
            return EXIT_AMBIGUOUS_OPTION;
344
328
          }
345
329
        }
346
330
        if ((optp->var_type & GET_TYPE_MASK) == GET_DISABLED)
347
331
        {
348
 
          if (my_getopt_print_errors)
349
 
            fprintf(stderr,
350
 
                    _("%s: %s: Option '%s' used, but is disabled\n"), my_progname,
351
 
                    option_is_loose ? _("WARNING") : _("ERROR"), opt_str);
 
332
          fprintf(stderr,
 
333
                  _("%s: %s: Option '%s' used, but is disabled\n"), my_progname,
 
334
                  option_is_loose ? _("WARNING") : _("ERROR"), opt_str);
352
335
          if (option_is_loose)
353
336
          {
354
337
            (*argc)--;
358
341
        }
359
342
        if (must_be_var && (optp->var_type & GET_TYPE_MASK) == GET_NO_ARG)
360
343
        {
361
 
          if (my_getopt_print_errors)
362
 
            my_getopt_error_reporter(ERROR_LEVEL, 
363
 
                                     "%s: option '%s' cannot take an argument",
364
 
                                     my_progname, optp->name);
 
344
          my_getopt_error_reporter(ERROR_LEVEL,
 
345
                                   "%s: option '%s' cannot take an argument",
 
346
                                   my_progname, optp->name);
365
347
          return EXIT_NO_ARGUMENT_ALLOWED;
366
348
        }
367
349
        value= optp->var_type & GET_ASK_ADDR ?
368
 
          (*getopt_get_addr)(key_name, (uint) strlen(key_name), optp) : optp->value;
369
 
  
 
350
          (*getopt_get_addr)(key_name, (uint32_t) strlen(key_name), optp) : optp->value;
 
351
 
370
352
        if (optp->arg_type == NO_ARG)
371
353
        {
372
354
          if (optend && (optp->var_type & GET_TYPE_MASK) != GET_BOOL)
373
355
          {
374
 
            if (my_getopt_print_errors)
375
 
              my_getopt_error_reporter(ERROR_LEVEL,
376
 
                                       "%s: option '--%s' cannot take an argument",
377
 
                                       my_progname, optp->name);
 
356
            my_getopt_error_reporter(ERROR_LEVEL,
 
357
                                     "%s: option '--%s' cannot take an argument",
 
358
                                     my_progname, optp->name);
378
359
            return EXIT_NO_ARGUMENT_ALLOWED;
379
360
          }
380
361
          if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL)
386
367
              */
387
368
            (*argc)--;
388
369
            if (!optend || *optend == '1' ||
389
 
                !my_strcasecmp(&my_charset_latin1, optend, "true"))
 
370
                !my_strcasecmp(&my_charset_utf8_general_ci, optend, "true"))
390
371
              *((bool*) value)= (bool) 1;
391
372
            else if (*optend == '0' ||
392
 
                     !my_strcasecmp(&my_charset_latin1, optend, "false"))
 
373
                     !my_strcasecmp(&my_charset_utf8_general_ci, optend, "false"))
393
374
              *((bool*) value)= (bool) 0;
394
375
            else
395
376
            {
424
405
          /* Check if there are more arguments after this one */
425
406
          if (!*++pos)
426
407
          {
427
 
            if (my_getopt_print_errors)
428
 
              my_getopt_error_reporter(ERROR_LEVEL,
429
 
                                       "%s: option '--%s' requires an argument",
430
 
                                       my_progname, optp->name);
 
408
            my_getopt_error_reporter(ERROR_LEVEL,
 
409
                                     "%s: option '--%s' requires an argument",
 
410
                                     my_progname, optp->name);
431
411
            return EXIT_ARGUMENT_REQUIRED;
432
412
          }
433
413
          argument= *pos;
443
423
          opt_found= 0;
444
424
          for (optp= longopts; optp->id; optp++)
445
425
          {
446
 
            if (optp->id == (int) (uchar) *optend)
 
426
            if (optp->id == (int) (unsigned char) *optend)
447
427
            {
448
428
              /* Option recognized. Find next what to do with it */
449
429
              opt_found= 1;
450
430
              if ((optp->var_type & GET_TYPE_MASK) == GET_DISABLED)
451
431
              {
452
 
                if (my_getopt_print_errors)
453
 
                  fprintf(stderr,
454
 
                          _("%s: ERROR: Option '-%c' used, but is disabled\n"),
455
 
                          my_progname, optp->id);
 
432
                fprintf(stderr,
 
433
                        _("%s: ERROR: Option '-%c' used, but is disabled\n"),
 
434
                        my_progname, optp->id);
456
435
                return EXIT_OPTION_DISABLED;
457
436
              }
458
437
              if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL &&
484
463
                  /* Check if there are more arguments after this one */
485
464
                  if (!pos[1])
486
465
                  {
487
 
                    if (my_getopt_print_errors)
488
 
                      my_getopt_error_reporter(ERROR_LEVEL,
489
 
                                               "%s: option '-%c' requires an argument",
490
 
                                               my_progname, optp->id);
 
466
                    my_getopt_error_reporter(ERROR_LEVEL,
 
467
                                             "%s: option '-%c' requires an argument",
 
468
                                             my_progname, optp->id);
491
469
                    return EXIT_ARGUMENT_REQUIRED;
492
470
                  }
493
471
                  argument= *++pos;
509
487
          }
510
488
          if (!opt_found)
511
489
          {
512
 
            if (my_getopt_print_errors)
513
 
              my_getopt_error_reporter(ERROR_LEVEL,
514
 
                                       "%s: unknown option '-%c'", 
515
 
                                       my_progname, *optend);
 
490
            my_getopt_error_reporter(ERROR_LEVEL,
 
491
                                     "%s: unknown option '-%c'",
 
492
                                     my_progname, *optend);
516
493
            return EXIT_UNKNOWN_OPTION;
517
494
          }
518
495
        }
565
542
  ptr= strrchr(cur_arg + 1, '.'); /* Skip the first character */
566
543
  end= strrchr(cur_arg, '=');
567
544
 
568
 
  /* 
 
545
  /*
569
546
     If the first dot is after an equal sign, then it is part
570
547
     of a variable value and the option is not a struct option.
571
548
     Also, if the last character in the string before the ending
574
551
  */
575
552
  if ((ptr != NULL) && (end != NULL) && (end - ptr > 1))
576
553
  {
577
 
    uint len= (uint) (ptr - cur_arg);
578
 
    set_if_smaller(len, FN_REFLEN-1);
579
 
    strmake(key_name, cur_arg, len);
 
554
    uint32_t len= (uint32_t) (ptr - cur_arg);
 
555
    set_if_smaller(len, (uint32_t)FN_REFLEN-1);
 
556
    strncpy(key_name, cur_arg, len);
580
557
    return ++ptr;
581
558
  }
582
 
  else
583
 
  {
584
 
    key_name[0]= 0;
585
 
    return cur_arg;
586
 
  }
 
559
  key_name[0]= 0;
 
560
  return cur_arg;
587
561
}
588
562
 
589
563
/*
611
585
      *((bool*) result_pos)= (bool) atoi(argument) != 0;
612
586
      break;
613
587
    case GET_INT:
614
 
      *((int*) result_pos)= (int) getopt_ll(argument, opts, &err);
 
588
      *((int32_t*) result_pos)= (int) getopt_ll(argument, opts, &err);
615
589
      break;
616
590
    case GET_UINT:
617
 
      *((uint*) result_pos)= (uint) getopt_ull(argument, opts, &err);
 
591
    case GET_UINT32:
 
592
      *((uint32_t*) result_pos)= (uint32_t) getopt_ull(argument, opts, &err);
 
593
      break;
 
594
    case GET_ULONG_IS_FAIL:
 
595
      *((ulong*) result_pos)= (ulong) getopt_ull(argument, opts, &err);
618
596
      break;
619
597
    case GET_LONG:
620
598
      *((long*) result_pos)= (long) getopt_ll(argument, opts, &err);
621
599
      break;
622
 
    case GET_ULONG:
623
 
      *((long*) result_pos)= (long) getopt_ull(argument, opts, &err);
624
 
      break;
625
600
    case GET_LL:
626
601
      *((int64_t*) result_pos)= getopt_ll(argument, opts, &err);
627
602
      break;
628
603
    case GET_ULL:
 
604
    case GET_UINT64:
629
605
      *((uint64_t*) result_pos)= getopt_ull(argument, opts, &err);
630
606
      break;
 
607
    case GET_SIZE:
 
608
      *((size_t*) result_pos)= getopt_size(argument, opts, &err);
 
609
      break;
631
610
    case GET_DOUBLE:
632
611
      *((double*) result_pos)= getopt_double(argument, opts, &err);
633
612
      break;
636
615
      break;
637
616
    case GET_STR_ALLOC:
638
617
      if ((*((char**) result_pos)))
639
 
        my_free((*(char**) result_pos), MYF(MY_WME | MY_FAE));
640
 
      if (!(*((char**) result_pos)= my_strdup(argument, MYF(MY_WME))))
 
618
        free((*(char**) result_pos));
 
619
      if (!(*((char**) result_pos)= strdup(argument)))
641
620
        return EXIT_OUT_OF_MEMORY;
642
621
      break;
643
622
    case GET_ENUM:
659
638
}
660
639
 
661
640
 
662
 
/* 
 
641
/*
663
642
  Find option
664
643
 
665
644
  SYNOPSIS
681
660
        ffname points to first matching option
682
661
*/
683
662
 
684
 
static int findopt(char *optpat, uint length,
 
663
static int findopt(char *optpat, uint32_t length,
685
664
                   const struct my_option **opt_res,
686
665
                   char **ffname)
687
666
{
688
 
  uint count;
 
667
  uint32_t count;
689
668
  struct my_option *opt= (struct my_option *) *opt_res;
690
669
 
691
670
  for (count= 0; opt->name; opt++)
714
693
}
715
694
 
716
695
 
717
 
/* 
 
696
/*
718
697
  function: compare_strings
719
698
 
720
699
  Works like strncmp, other than 1.) considers '-' and '_' the same.
722
701
*/
723
702
 
724
703
bool getopt_compare_strings(register const char *s, register const char *t,
725
 
                               uint length)
 
704
                               uint32_t length)
726
705
{
727
706
  char const *end= s + length;
728
707
  for (;s != end ; s++, t++)
744
723
{
745
724
  char *endchar;
746
725
  int64_t num;
747
 
  
 
726
 
748
727
  *error= 0;
749
728
  errno= 0;
750
729
  num= strtoll(argument, &endchar, 10);
772
751
  return num;
773
752
}
774
753
 
775
 
/* 
 
754
/*
776
755
  function: getopt_ll
777
756
 
778
757
  Evaluates and returns the value that user gave as an argument
820
799
    }
821
800
    break;
822
801
  case GET_LONG:
823
 
#if SIZEOF_LONG < SIZEOF_LONG_LONG
824
 
    if (num > (int64_t) LONG_MAX)
 
802
    if (num > (int64_t) INT32_MAX)
825
803
    {
826
 
      num= ((int64_t) LONG_MAX);
 
804
      num= ((int64_t) INT32_MAX);
827
805
      adjusted= true;
828
806
    }
829
 
#endif
830
807
    break;
831
808
  default:
832
809
    assert((optp->var_type & GET_TYPE_MASK) == GET_LL);
854
831
/*
855
832
  function: getopt_ull
856
833
 
857
 
  This is the same as getopt_ll, but is meant for unsigned long long
 
834
  This is the same as getopt_ll, but is meant for uint64_t
858
835
  values.
859
836
*/
860
837
 
865
842
}
866
843
 
867
844
 
 
845
static size_t getopt_size(char *arg, const struct my_option *optp, int *err)
 
846
{
 
847
  return (size_t)getopt_ull(arg, optp, err);
 
848
}
 
849
 
 
850
 
 
851
 
868
852
uint64_t getopt_ull_limit_value(uint64_t num, const struct my_option *optp,
869
 
                                 bool *fix)
 
853
                                bool *fix)
870
854
{
871
855
  bool adjusted= false;
872
856
  uint64_t old= num;
887
871
      adjusted= true;
888
872
    }
889
873
    break;
890
 
  case GET_ULONG:
891
 
#if SIZEOF_LONG < SIZEOF_LONG_LONG
892
 
    if (num > (uint64_t) ULONG_MAX)
893
 
    {
894
 
      num= ((uint64_t) ULONG_MAX);
895
 
      adjusted= true;
896
 
    }
897
 
#endif
 
874
  case GET_UINT32:
 
875
  case GET_ULONG_IS_FAIL:
 
876
    if (num > (uint64_t) UINT32_MAX)
 
877
    {
 
878
      num= ((uint64_t) UINT32_MAX);
 
879
      adjusted= true;
 
880
    }
 
881
    break;
 
882
  case GET_SIZE:
 
883
    if (num > (uint64_t) SIZE_MAX)
 
884
    {
 
885
      num= ((uint64_t) SIZE_MAX);
 
886
      adjusted= true;
 
887
    }
898
888
    break;
899
889
  default:
900
 
    assert((optp->var_type & GET_TYPE_MASK) == GET_ULL);
 
890
    assert(((optp->var_type & GET_TYPE_MASK) == GET_ULL)
 
891
           || ((optp->var_type & GET_TYPE_MASK) == GET_UINT64));
901
892
    break;
902
893
  }
903
894
 
976
967
    break;
977
968
  case GET_UINT:
978
969
  case GET_ENUM:
979
 
    *((uint*) variable)= (uint) value;
 
970
    *((uint*) variable)= (uint32_t) value;
980
971
    break;
981
972
  case GET_LONG:
982
973
    *((long*) variable)= (long) value;
983
974
    break;
984
 
  case GET_ULONG:
 
975
  case GET_UINT32:
985
976
    *((uint32_t*) variable)= (uint32_t) value;
986
977
    break;
 
978
  case GET_ULONG_IS_FAIL:
 
979
    *((ulong*) variable)= (ulong) value;
 
980
    break;
987
981
  case GET_LL:
988
982
    *((int64_t*) variable)= (int64_t) value;
989
983
    break;
 
984
  case GET_SIZE:
 
985
    *((size_t*) variable)= (size_t) value;
 
986
    break;
990
987
  case GET_ULL:
991
988
  case GET_SET:
 
989
  case GET_UINT64:
992
990
    *((uint64_t*) variable)=  (uint64_t) value;
993
991
    break;
994
992
  case GET_DOUBLE:
1013
1011
    */
1014
1012
    if ((char*) (intptr_t) value)
1015
1013
    {
1016
 
      my_free((*(char**) variable), MYF(MY_ALLOW_ZERO_PTR));
1017
 
      *((char**) variable)= my_strdup((char*) (intptr_t) value, MYF(MY_WME));
 
1014
      free((*(char**) variable));
 
1015
      char *tmpptr= strdup((char *) (intptr_t) value);
 
1016
      if (tmpptr != NULL)
 
1017
        *((char**) variable)= tmpptr;
1018
1018
    }
1019
1019
    break;
1020
1020
  default: /* dummy default to avoid compiler warnings */
1034
1034
*/
1035
1035
 
1036
1036
static void fini_one_value(const struct my_option *option, char **variable,
1037
 
                           int64_t value __attribute__ ((unused)))
 
1037
                           int64_t)
1038
1038
{
1039
1039
  switch ((option->var_type & GET_TYPE_MASK)) {
1040
1040
  case GET_STR_ALLOC:
1041
 
    my_free((*(char**) variable), MYF(MY_ALLOW_ZERO_PTR));
 
1041
    free((*(char**) variable));
1042
1042
    *((char**) variable)= NULL;
1043
1043
    break;
1044
1044
  default: /* dummy default to avoid compiler warnings */
1054
1054
}
1055
1055
 
1056
1056
 
1057
 
/* 
 
1057
/*
1058
1058
  initialize all variables to their default values
1059
1059
 
1060
1060
  SYNOPSIS
1098
1098
 
1099
1099
void my_print_help(const struct my_option *options)
1100
1100
{
1101
 
  uint col, name_space= 22, comment_space= 57;
 
1101
  uint32_t col, name_space= 22, comment_space= 57;
1102
1102
  const char *line_end;
1103
1103
  const struct my_option *optp;
1104
1104
 
1117
1117
    if (strlen(optp->name))
1118
1118
    {
1119
1119
      printf("--%s", optp->name);
1120
 
      col+= 2 + (uint) strlen(optp->name);
 
1120
      col+= 2 + (uint32_t) strlen(optp->name);
1121
1121
      if ((optp->var_type & GET_TYPE_MASK) == GET_STR ||
1122
1122
          (optp->var_type & GET_TYPE_MASK) == GET_STR_ALLOC)
1123
1123
      {
1147
1147
      putchar(' ');
1148
1148
    if (optp->comment && *optp->comment)
1149
1149
    {
1150
 
      const char *comment= _(optp->comment), *end= strend(comment);
 
1150
      const char *comment= _(optp->comment), *end= strchr(comment, '\0');
1151
1151
 
1152
 
      while ((uint) (end - comment) > comment_space)
 
1152
      while ((uint32_t) (end - comment) > comment_space)
1153
1153
      {
1154
 
        for (line_end= comment + comment_space; *line_end != ' '; line_end--);
 
1154
        for (line_end= comment + comment_space; *line_end != ' '; line_end--)
 
1155
          {}
1155
1156
        for (; comment != line_end; comment++)
1156
1157
          putchar(*comment);
1157
1158
        comment++; /* skip the space, as a newline will take it's place now */
1182
1183
 
1183
1184
void my_print_variables(const struct my_option *options)
1184
1185
{
1185
 
  uint name_space= 34, length, nr;
 
1186
  uint32_t name_space= 34, length, nr;
1186
1187
  uint64_t bit, llvalue;
1187
1188
  char buff[255];
1188
1189
  const struct my_option *optp;
1197
1198
    if (value)
1198
1199
    {
1199
1200
      printf("%s ", optp->name);
1200
 
      length= (uint) strlen(optp->name)+1;
 
1201
      length= (uint32_t) strlen(optp->name)+1;
1201
1202
      for (; length < name_space; length++)
1202
1203
        putchar(' ');
1203
1204
      switch ((optp->var_type & GET_TYPE_MASK)) {
1233
1234
      case GET_LONG:
1234
1235
        printf("%ld\n", *((long*) value));
1235
1236
        break;
1236
 
      case GET_ULONG:
 
1237
      case GET_UINT32:
1237
1238
        printf("%u\n", *((uint32_t*) value));
1238
1239
        break;
 
1240
      case GET_ULONG_IS_FAIL:
 
1241
        printf("%lu\n", *((ulong*) value));
 
1242
        break;
 
1243
      case GET_SIZE:
 
1244
        int64_t2str((uint64_t)(*(size_t*)value), buff, 10);
 
1245
        printf("%s\n", buff);
 
1246
        break;
1239
1247
      case GET_LL:
1240
1248
        printf("%s\n", llstr(*((int64_t*) value), buff));
1241
1249
        break;
1242
1250
      case GET_ULL:
 
1251
      case GET_UINT64:
1243
1252
        int64_t2str(*((uint64_t*) value), buff, 10);
1244
1253
        printf("%s\n", buff);
1245
1254
        break;