~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/my_getopt.cc

Merge Monty.

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 <my_global.h>
17
 
#include <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>
18
25
#include <stdlib.h>
19
 
#include <my_sys.h>
20
 
#include <mysys_err.h>
21
 
#include <my_getopt.h>
22
26
#include <errno.h>
 
27
#include <iostream>
 
28
#include <algorithm>
 
29
 
 
30
using namespace std;
23
31
 
24
32
typedef void (*init_func_p)(const struct my_option *option, char **variable,
25
33
                            int64_t value);
26
34
 
27
 
static void default_reporter(enum loglevel level, const char *format, ...);
 
35
extern "C" void default_reporter(enum loglevel level, const char *format, ...);
28
36
my_error_reporter my_getopt_error_reporter= &default_reporter;
29
37
 
30
 
static int findopt(char *optpat, uint length,
 
38
static int findopt(char *optpat, uint32_t length,
31
39
                   const struct my_option **opt_res,
32
40
                   char **ffname);
33
41
static int64_t getopt_ll(char *arg, const struct my_option *optp, int *err);
34
42
static uint64_t getopt_ull(char *arg, const struct my_option *optp,
35
43
                            int *err);
 
44
static size_t getopt_size(char *arg, const struct my_option *optp, int *err);
36
45
static double getopt_double(char *arg, const struct my_option *optp, int *err);
37
46
static void init_variables(const struct my_option *options,
38
47
                           init_func_p init_one_value);
50
59
*/
51
60
static const char *special_opt_prefix[]=
52
61
{"skip", "disable", "enable", "maximum", "loose", 0};
53
 
static const uint special_opt_prefix_lengths[]=
 
62
static const uint32_t special_opt_prefix_lengths[]=
54
63
{ 4,      7,         6,        7,         5,      0};
55
64
enum enum_special_opt
56
65
{ OPT_SKIP, OPT_DISABLE, OPT_ENABLE, OPT_MAXIMUM, OPT_LOOSE};
57
66
 
58
67
char *disabled_my_option= (char*) "0";
59
68
 
60
 
/* 
61
 
   This is a flag that can be set in client programs. 0 means that
62
 
   my_getopt will not print error messages, but the client should do
63
 
   it by itself
64
 
*/
65
 
 
66
 
bool my_getopt_print_errors= 1;
67
 
 
68
 
/* 
 
69
/*
69
70
   This is a flag that can be set in client programs. 1 means that
70
71
   my_getopt will skip over options it does not know how to handle.
71
72
*/
72
73
 
73
74
bool my_getopt_skip_unknown= 0;
74
75
 
75
 
static void default_reporter(enum loglevel level,
76
 
                             const char *format, ...)
 
76
extern "C" void default_reporter(enum loglevel level, const char *format, ...)
77
77
{
78
78
  va_list args;
79
79
  va_start(args, format);
80
80
  if (level == WARNING_LEVEL)
81
 
    fprintf(stderr, "%s", "Warning: ");
 
81
    fprintf(stderr, "%s", _("Warning: "));
82
82
  else if (level == INFORMATION_LEVEL)
83
 
    fprintf(stderr, "%s", "Info: ");
 
83
    fprintf(stderr, "%s", _("Info: "));
84
84
  vfprintf(stderr, format, args);
85
85
  va_end(args);
86
86
  fputc('\n', stderr);
87
87
  fflush(stderr);
88
88
}
89
89
 
90
 
/* 
 
90
/*
91
91
  function: handle_options
92
92
 
93
93
  Sort options; put options first, until special end of options (--), or
97
97
  one. Call function 'get_one_option()' once for each option.
98
98
*/
99
99
 
100
 
static char** (*getopt_get_addr)(const char *, uint, const struct my_option *);
101
 
 
102
 
void my_getopt_register_get_addr(char** (*func_addr)(const char *, uint,
103
 
                                                    const struct my_option *))
104
 
{
105
 
  getopt_get_addr= func_addr;
106
 
}
107
 
 
108
 
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,
109
103
                   const struct my_option *longopts,
110
104
                   my_get_one_option get_one_option)
111
105
{
112
 
  uint opt_found, argvpos= 0, length;
 
106
  uint32_t opt_found, argvpos= 0, length;
113
107
  bool end_of_options= 0, must_be_var, set_maximum_value=false,
114
108
          option_is_loose;
115
109
  char **pos, **pos_end, *optend, *prev_found=NULL,
148
142
            /* the argument must be in next argv */
149
143
            if (!*++pos)
150
144
            {
151
 
              if (my_getopt_print_errors)
152
 
                my_getopt_error_reporter(ERROR_LEVEL,
153
 
                                         "%s: Option '-O' requires an argument",
154
 
                                         my_progname);
 
145
              my_getopt_error_reporter(ERROR_LEVEL,
 
146
                                       "%s: Option '-O' requires an argument",
 
147
                                       my_progname);
155
148
              return EXIT_ARGUMENT_REQUIRED;
156
149
            }
157
150
            cur_arg= *pos;
166
159
            cur_arg+= 14;
167
160
            if (!*cur_arg)
168
161
            {
169
 
              if (my_getopt_print_errors)
170
 
                my_getopt_error_reporter(ERROR_LEVEL,
171
 
                                         "%s: Option '--set-variable' requires an argument",
172
 
                                         my_progname);
 
162
              my_getopt_error_reporter(ERROR_LEVEL,
 
163
                                       "%s: Option '--set-variable' requires an argument",
 
164
                                       my_progname);
173
165
              return EXIT_ARGUMENT_REQUIRED;
174
166
            }
175
167
          }
180
172
            /* the argument must be in next argv */
181
173
            if (!*++pos)
182
174
            {
183
 
              if (my_getopt_print_errors)
184
 
                my_getopt_error_reporter(ERROR_LEVEL,
185
 
                                         "%s: Option '--set-variable' requires an argument",
186
 
                                         my_progname);
 
175
              my_getopt_error_reporter(ERROR_LEVEL,
 
176
                                       "%s: Option '--set-variable' requires an argument",
 
177
                                       my_progname);
187
178
              return EXIT_ARGUMENT_REQUIRED;
188
179
            }
189
180
            cur_arg= *pos;
201
192
          }
202
193
        }
203
194
        opt_str= check_struct_option(cur_arg, key_name);
204
 
        optend= strcend(opt_str, '=');
205
 
        length= (uint) (optend - opt_str);
206
 
        if (*optend == '=')
 
195
        optend= strrchr(opt_str, '=');
 
196
        if (optend != NULL)
 
197
        {
 
198
          length= (uint32_t) (optend - opt_str);
207
199
          optend++;
 
200
        }
208
201
        else
 
202
        {
 
203
          length= static_cast<uint32_t>(strlen(opt_str));
209
204
          optend= 0;
 
205
        }
210
206
 
211
207
        /*
212
208
          Find first the right option. Return error in case of an ambiguous,
241
237
                {
242
238
                  if (opt_found > 1)
243
239
                  {
244
 
                    if (my_getopt_print_errors)
245
 
                      my_getopt_error_reporter(ERROR_LEVEL,
246
 
                                               "%s: ambiguous option '--%s-%s' (--%s-%s)",
247
 
                                               my_progname, special_opt_prefix[i],
248
 
                                               cur_arg, special_opt_prefix[i],
249
 
                                               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);
250
245
                    return EXIT_AMBIGUOUS_OPTION;
251
246
                  }
252
247
                  switch (i) {
291
286
            }
292
287
            if (must_be_var)
293
288
            {
294
 
              if (my_getopt_print_errors)
295
 
                my_getopt_error_reporter(option_is_loose ? 
296
 
                                           WARNING_LEVEL : ERROR_LEVEL,
297
 
                                         "%s: unknown variable '%s'",
298
 
                                         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);
299
293
              if (!option_is_loose)
300
294
                return EXIT_UNKNOWN_VARIABLE;
301
295
            }
302
296
            else
303
297
            {
304
 
              if (my_getopt_print_errors)
305
 
                my_getopt_error_reporter(option_is_loose ? 
306
 
                                           WARNING_LEVEL : ERROR_LEVEL,
307
 
                                         "%s: unknown option '--%s'", 
308
 
                                         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);
309
302
              if (!option_is_loose)
310
303
                return EXIT_UNKNOWN_OPTION;
311
304
            }
320
313
        {
321
314
          if (must_be_var)
322
315
          {
323
 
            if (my_getopt_print_errors)
324
 
              my_getopt_error_reporter(ERROR_LEVEL,
325
 
                                       "%s: variable prefix '%s' is not unique",
326
 
                                       my_progname, opt_str);
 
316
            my_getopt_error_reporter(ERROR_LEVEL,
 
317
                                     "%s: variable prefix '%s' is not unique",
 
318
                                     my_progname, opt_str);
327
319
            return EXIT_VAR_PREFIX_NOT_UNIQUE;
328
320
          }
329
321
          else
330
322
          {
331
 
            if (my_getopt_print_errors)
332
 
              my_getopt_error_reporter(ERROR_LEVEL,
333
 
                                       "%s: ambiguous option '--%s' (%s, %s)",
334
 
                                       my_progname, opt_str, prev_found, 
335
 
                                       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);
336
327
            return EXIT_AMBIGUOUS_OPTION;
337
328
          }
338
329
        }
339
330
        if ((optp->var_type & GET_TYPE_MASK) == GET_DISABLED)
340
331
        {
341
 
          if (my_getopt_print_errors)
342
 
            fprintf(stderr,
343
 
                    "%s: %s: Option '%s' used, but is disabled\n", my_progname,
344
 
                    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);
345
335
          if (option_is_loose)
346
336
          {
347
337
            (*argc)--;
351
341
        }
352
342
        if (must_be_var && (optp->var_type & GET_TYPE_MASK) == GET_NO_ARG)
353
343
        {
354
 
          if (my_getopt_print_errors)
355
 
            my_getopt_error_reporter(ERROR_LEVEL, 
356
 
                                     "%s: option '%s' cannot take an argument",
357
 
                                     my_progname, optp->name);
 
344
          my_getopt_error_reporter(ERROR_LEVEL,
 
345
                                   "%s: option '%s' cannot take an argument",
 
346
                                   my_progname, optp->name);
358
347
          return EXIT_NO_ARGUMENT_ALLOWED;
359
348
        }
360
349
        value= optp->var_type & GET_ASK_ADDR ?
361
 
          (*getopt_get_addr)(key_name, (uint) strlen(key_name), optp) : optp->value;
362
 
  
 
350
          (*getopt_get_addr)(key_name, (uint32_t) strlen(key_name), optp) : optp->value;
 
351
 
363
352
        if (optp->arg_type == NO_ARG)
364
353
        {
365
354
          if (optend && (optp->var_type & GET_TYPE_MASK) != GET_BOOL)
366
355
          {
367
 
            if (my_getopt_print_errors)
368
 
              my_getopt_error_reporter(ERROR_LEVEL,
369
 
                                       "%s: option '--%s' cannot take an argument",
370
 
                                       my_progname, optp->name);
 
356
            my_getopt_error_reporter(ERROR_LEVEL,
 
357
                                     "%s: option '--%s' cannot take an argument",
 
358
                                     my_progname, optp->name);
371
359
            return EXIT_NO_ARGUMENT_ALLOWED;
372
360
          }
373
361
          if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL)
379
367
              */
380
368
            (*argc)--;
381
369
            if (!optend || *optend == '1' ||
382
 
                !my_strcasecmp(&my_charset_latin1, optend, "true"))
 
370
                !my_strcasecmp(&my_charset_utf8_general_ci, optend, "true"))
383
371
              *((bool*) value)= (bool) 1;
384
372
            else if (*optend == '0' ||
385
 
                     !my_strcasecmp(&my_charset_latin1, optend, "false"))
 
373
                     !my_strcasecmp(&my_charset_utf8_general_ci, optend, "false"))
386
374
              *((bool*) value)= (bool) 0;
387
375
            else
388
376
            {
417
405
          /* Check if there are more arguments after this one */
418
406
          if (!*++pos)
419
407
          {
420
 
            if (my_getopt_print_errors)
421
 
              my_getopt_error_reporter(ERROR_LEVEL,
422
 
                                       "%s: option '--%s' requires an argument",
423
 
                                       my_progname, optp->name);
 
408
            my_getopt_error_reporter(ERROR_LEVEL,
 
409
                                     "%s: option '--%s' requires an argument",
 
410
                                     my_progname, optp->name);
424
411
            return EXIT_ARGUMENT_REQUIRED;
425
412
          }
426
413
          argument= *pos;
436
423
          opt_found= 0;
437
424
          for (optp= longopts; optp->id; optp++)
438
425
          {
439
 
            if (optp->id == (int) (uchar) *optend)
 
426
            if (optp->id == (int) (unsigned char) *optend)
440
427
            {
441
428
              /* Option recognized. Find next what to do with it */
442
429
              opt_found= 1;
443
430
              if ((optp->var_type & GET_TYPE_MASK) == GET_DISABLED)
444
431
              {
445
 
                if (my_getopt_print_errors)
446
 
                  fprintf(stderr,
447
 
                          "%s: ERROR: Option '-%c' used, but is disabled\n",
448
 
                          my_progname, optp->id);
 
432
                fprintf(stderr,
 
433
                        _("%s: ERROR: Option '-%c' used, but is disabled\n"),
 
434
                        my_progname, optp->id);
449
435
                return EXIT_OPTION_DISABLED;
450
436
              }
451
437
              if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL &&
477
463
                  /* Check if there are more arguments after this one */
478
464
                  if (!pos[1])
479
465
                  {
480
 
                    if (my_getopt_print_errors)
481
 
                      my_getopt_error_reporter(ERROR_LEVEL,
482
 
                                               "%s: option '-%c' requires an argument",
483
 
                                               my_progname, optp->id);
 
466
                    my_getopt_error_reporter(ERROR_LEVEL,
 
467
                                             "%s: option '-%c' requires an argument",
 
468
                                             my_progname, optp->id);
484
469
                    return EXIT_ARGUMENT_REQUIRED;
485
470
                  }
486
471
                  argument= *++pos;
502
487
          }
503
488
          if (!opt_found)
504
489
          {
505
 
            if (my_getopt_print_errors)
506
 
              my_getopt_error_reporter(ERROR_LEVEL,
507
 
                                       "%s: unknown option '-%c'", 
508
 
                                       my_progname, *optend);
 
490
            my_getopt_error_reporter(ERROR_LEVEL,
 
491
                                     "%s: unknown option '-%c'",
 
492
                                     my_progname, *optend);
509
493
            return EXIT_UNKNOWN_OPTION;
510
494
          }
511
495
        }
555
539
{
556
540
  char *ptr, *end;
557
541
 
558
 
  ptr= strcend(cur_arg + 1, '.'); /* Skip the first character */
559
 
  end= strcend(cur_arg, '=');
 
542
  ptr= strrchr(cur_arg + 1, '.'); /* Skip the first character */
 
543
  end= strrchr(cur_arg, '=');
560
544
 
561
 
  /* 
 
545
  /*
562
546
     If the first dot is after an equal sign, then it is part
563
547
     of a variable value and the option is not a struct option.
564
548
     Also, if the last character in the string before the ending
565
549
     NULL, or the character right before equal sign is the first
566
550
     dot found, the option is not a struct option.
567
551
  */
568
 
  if (end - ptr > 1)
 
552
  if ((ptr != NULL) && (end != NULL) && (end - ptr > 1))
569
553
  {
570
 
    uint len= (uint) (ptr - cur_arg);
571
 
    set_if_smaller(len, FN_REFLEN-1);
572
 
    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);
573
557
    return ++ptr;
574
558
  }
575
 
  else
576
 
  {
577
 
    key_name[0]= 0;
578
 
    return cur_arg;
579
 
  }
 
559
  key_name[0]= 0;
 
560
  return cur_arg;
580
561
}
581
562
 
582
563
/*
604
585
      *((bool*) result_pos)= (bool) atoi(argument) != 0;
605
586
      break;
606
587
    case GET_INT:
607
 
      *((int*) result_pos)= (int) getopt_ll(argument, opts, &err);
 
588
      *((int32_t*) result_pos)= (int) getopt_ll(argument, opts, &err);
608
589
      break;
609
590
    case GET_UINT:
610
 
      *((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);
611
596
      break;
612
597
    case GET_LONG:
613
598
      *((long*) result_pos)= (long) getopt_ll(argument, opts, &err);
614
599
      break;
615
 
    case GET_ULONG:
616
 
      *((long*) result_pos)= (long) getopt_ull(argument, opts, &err);
617
 
      break;
618
600
    case GET_LL:
619
601
      *((int64_t*) result_pos)= getopt_ll(argument, opts, &err);
620
602
      break;
621
603
    case GET_ULL:
 
604
    case GET_UINT64:
622
605
      *((uint64_t*) result_pos)= getopt_ull(argument, opts, &err);
623
606
      break;
 
607
    case GET_SIZE:
 
608
      *((size_t*) result_pos)= getopt_size(argument, opts, &err);
 
609
      break;
624
610
    case GET_DOUBLE:
625
611
      *((double*) result_pos)= getopt_double(argument, opts, &err);
626
612
      break;
629
615
      break;
630
616
    case GET_STR_ALLOC:
631
617
      if ((*((char**) result_pos)))
632
 
        my_free((*(char**) result_pos), MYF(MY_WME | MY_FAE));
633
 
      if (!(*((char**) result_pos)= my_strdup(argument, MYF(MY_WME))))
 
618
        free((*(char**) result_pos));
 
619
      if (!(*((char**) result_pos)= strdup(argument)))
634
620
        return EXIT_OUT_OF_MEMORY;
635
621
      break;
636
622
    case GET_ENUM:
652
638
}
653
639
 
654
640
 
655
 
/* 
 
641
/*
656
642
  Find option
657
643
 
658
644
  SYNOPSIS
674
660
        ffname points to first matching option
675
661
*/
676
662
 
677
 
static int findopt(char *optpat, uint length,
 
663
static int findopt(char *optpat, uint32_t length,
678
664
                   const struct my_option **opt_res,
679
665
                   char **ffname)
680
666
{
681
 
  uint count;
 
667
  uint32_t count;
682
668
  struct my_option *opt= (struct my_option *) *opt_res;
683
669
 
684
670
  for (count= 0; opt->name; opt++)
707
693
}
708
694
 
709
695
 
710
 
/* 
 
696
/*
711
697
  function: compare_strings
712
698
 
713
699
  Works like strncmp, other than 1.) considers '-' and '_' the same.
715
701
*/
716
702
 
717
703
bool getopt_compare_strings(register const char *s, register const char *t,
718
 
                               uint length)
 
704
                               uint32_t length)
719
705
{
720
706
  char const *end= s + length;
721
707
  for (;s != end ; s++, t++)
737
723
{
738
724
  char *endchar;
739
725
  int64_t num;
740
 
  
 
726
 
741
727
  *error= 0;
742
728
  errno= 0;
743
729
  num= strtoll(argument, &endchar, 10);
757
743
  else if (*endchar)
758
744
  {
759
745
    fprintf(stderr,
760
 
            "Unknown suffix '%c' used for variable '%s' (value '%s')\n",
 
746
            _("Unknown suffix '%c' used for variable '%s' (value '%s')\n"),
761
747
            *endchar, option_name, argument);
762
748
    *error= 1;
763
749
    return 0;
765
751
  return num;
766
752
}
767
753
 
768
 
/* 
 
754
/*
769
755
  function: getopt_ll
770
756
 
771
757
  Evaluates and returns the value that user gave as an argument
813
799
    }
814
800
    break;
815
801
  case GET_LONG:
816
 
#if SIZEOF_LONG < SIZEOF_LONG_LONG
817
 
    if (num > (int64_t) LONG_MAX)
 
802
    if (num > (int64_t) INT32_MAX)
818
803
    {
819
 
      num= ((int64_t) LONG_MAX);
 
804
      num= ((int64_t) INT32_MAX);
820
805
      adjusted= true;
821
806
    }
822
 
#endif
823
807
    break;
824
808
  default:
825
809
    assert((optp->var_type & GET_TYPE_MASK) == GET_LL);
847
831
/*
848
832
  function: getopt_ull
849
833
 
850
 
  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
851
835
  values.
852
836
*/
853
837
 
858
842
}
859
843
 
860
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
 
861
852
uint64_t getopt_ull_limit_value(uint64_t num, const struct my_option *optp,
862
 
                                 bool *fix)
 
853
                                bool *fix)
863
854
{
864
855
  bool adjusted= false;
865
856
  uint64_t old= num;
880
871
      adjusted= true;
881
872
    }
882
873
    break;
883
 
  case GET_ULONG:
884
 
#if SIZEOF_LONG < SIZEOF_LONG_LONG
885
 
    if (num > (uint64_t) ULONG_MAX)
886
 
    {
887
 
      num= ((uint64_t) ULONG_MAX);
888
 
      adjusted= true;
889
 
    }
890
 
#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
    }
891
888
    break;
892
889
  default:
893
 
    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));
894
892
    break;
895
893
  }
896
894
 
938
936
  if (end[0] != 0 || error)
939
937
  {
940
938
    fprintf(stderr,
941
 
            "%s: ERROR: Invalid decimal value for option '%s'\n",
 
939
            _("%s: ERROR: Invalid decimal value for option '%s'\n"),
942
940
            my_progname, optp->name);
943
941
    *err= EXIT_ARGUMENT_INVALID;
944
942
    return 0.0;
969
967
    break;
970
968
  case GET_UINT:
971
969
  case GET_ENUM:
972
 
    *((uint*) variable)= (uint) value;
 
970
    *((uint*) variable)= (uint32_t) value;
973
971
    break;
974
972
  case GET_LONG:
975
973
    *((long*) variable)= (long) value;
976
974
    break;
977
 
  case GET_ULONG:
 
975
  case GET_UINT32:
 
976
    *((uint32_t*) variable)= (uint32_t) value;
 
977
    break;
 
978
  case GET_ULONG_IS_FAIL:
978
979
    *((ulong*) variable)= (ulong) value;
979
980
    break;
980
981
  case GET_LL:
981
982
    *((int64_t*) variable)= (int64_t) value;
982
983
    break;
 
984
  case GET_SIZE:
 
985
    *((size_t*) variable)= (size_t) value;
 
986
    break;
983
987
  case GET_ULL:
984
988
  case GET_SET:
 
989
  case GET_UINT64:
985
990
    *((uint64_t*) variable)=  (uint64_t) value;
986
991
    break;
987
992
  case GET_DOUBLE:
1006
1011
    */
1007
1012
    if ((char*) (intptr_t) value)
1008
1013
    {
1009
 
      my_free((*(char**) variable), MYF(MY_ALLOW_ZERO_PTR));
1010
 
      *((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;
1011
1018
    }
1012
1019
    break;
1013
1020
  default: /* dummy default to avoid compiler warnings */
1027
1034
*/
1028
1035
 
1029
1036
static void fini_one_value(const struct my_option *option, char **variable,
1030
 
                           int64_t value __attribute__ ((unused)))
 
1037
                           int64_t)
1031
1038
{
1032
1039
  switch ((option->var_type & GET_TYPE_MASK)) {
1033
1040
  case GET_STR_ALLOC:
1034
 
    my_free((*(char**) variable), MYF(MY_ALLOW_ZERO_PTR));
 
1041
    free((*(char**) variable));
1035
1042
    *((char**) variable)= NULL;
1036
1043
    break;
1037
1044
  default: /* dummy default to avoid compiler warnings */
1047
1054
}
1048
1055
 
1049
1056
 
1050
 
/* 
 
1057
/*
1051
1058
  initialize all variables to their default values
1052
1059
 
1053
1060
  SYNOPSIS
1091
1098
 
1092
1099
void my_print_help(const struct my_option *options)
1093
1100
{
1094
 
  uint col, name_space= 22, comment_space= 57;
 
1101
  uint32_t col, name_space= 22, comment_space= 57;
1095
1102
  const char *line_end;
1096
1103
  const struct my_option *optp;
1097
1104
 
1110
1117
    if (strlen(optp->name))
1111
1118
    {
1112
1119
      printf("--%s", optp->name);
1113
 
      col+= 2 + (uint) strlen(optp->name);
 
1120
      col+= 2 + (uint32_t) strlen(optp->name);
1114
1121
      if ((optp->var_type & GET_TYPE_MASK) == GET_STR ||
1115
1122
          (optp->var_type & GET_TYPE_MASK) == GET_STR_ALLOC)
1116
1123
      {
1140
1147
      putchar(' ');
1141
1148
    if (optp->comment && *optp->comment)
1142
1149
    {
1143
 
      const char *comment= optp->comment, *end= strend(comment);
 
1150
      const char *comment= _(optp->comment), *end= strchr(comment, '\0');
1144
1151
 
1145
 
      while ((uint) (end - comment) > comment_space)
 
1152
      while ((uint32_t) (end - comment) > comment_space)
1146
1153
      {
1147
 
        for (line_end= comment + comment_space; *line_end != ' '; line_end--);
 
1154
        for (line_end= comment + comment_space; *line_end != ' '; line_end--)
 
1155
          {}
1148
1156
        for (; comment != line_end; comment++)
1149
1157
          putchar(*comment);
1150
1158
        comment++; /* skip the space, as a newline will take it's place now */
1160
1168
    {
1161
1169
      if (optp->def_value != 0)
1162
1170
      {
1163
 
        printf("%*s(Defaults to on; use --skip-%s to disable.)\n", name_space, "", optp->name);
 
1171
        printf(_("%*s(Defaults to on; use --skip-%s to disable.)\n"), name_space, "", optp->name);
1164
1172
      }
1165
1173
    }
1166
1174
  }
1175
1183
 
1176
1184
void my_print_variables(const struct my_option *options)
1177
1185
{
1178
 
  uint name_space= 34, length, nr;
 
1186
  uint32_t name_space= 34, length, nr;
1179
1187
  uint64_t bit, llvalue;
1180
1188
  char buff[255];
1181
1189
  const struct my_option *optp;
1182
1190
 
1183
 
  printf("\nVariables (--variable-name=value)\n");
1184
 
  printf("and boolean options {false|true}  Value (after reading options)\n");
1185
 
  printf("--------------------------------- -----------------------------\n");
 
1191
  printf(_("\nVariables (--variable-name=value)\n"
 
1192
         "and boolean options {false|true}  Value (after reading options)\n"
 
1193
         "--------------------------------- -----------------------------\n"));
1186
1194
  for (optp= options; optp->id; optp++)
1187
1195
  {
1188
1196
    char* *value= (optp->var_type & GET_ASK_ADDR ?
1190
1198
    if (value)
1191
1199
    {
1192
1200
      printf("%s ", optp->name);
1193
 
      length= (uint) strlen(optp->name)+1;
 
1201
      length= (uint32_t) strlen(optp->name)+1;
1194
1202
      for (; length < name_space; length++)
1195
1203
        putchar(' ');
1196
1204
      switch ((optp->var_type & GET_TYPE_MASK)) {
1197
1205
      case GET_SET:
1198
1206
        if (!(llvalue= *(uint64_t*) value))
1199
 
          printf("%s\n", "(No default value)");
 
1207
          printf("%s\n", _("(No default value)"));
1200
1208
        else
1201
1209
        for (nr= 0, bit= 1; llvalue && nr < optp->typelib->count; nr++, bit<<=1)
1202
1210
        {
1212
1220
      case GET_STR:
1213
1221
      case GET_STR_ALLOC:                    /* fall through */
1214
1222
        printf("%s\n", *((char**) value) ? *((char**) value) :
1215
 
               "(No default value)");
 
1223
               _("(No default value)"));
1216
1224
        break;
1217
1225
      case GET_BOOL:
1218
 
        printf("%s\n", *((bool*) value) ? "true" : "false");
 
1226
        printf("%s\n", *((bool*) value) ? _("true") : _("false"));
1219
1227
        break;
1220
1228
      case GET_INT:
1221
1229
        printf("%d\n", *((int*) value));
1226
1234
      case GET_LONG:
1227
1235
        printf("%ld\n", *((long*) value));
1228
1236
        break;
1229
 
      case GET_ULONG:
 
1237
      case GET_UINT32:
 
1238
        printf("%u\n", *((uint32_t*) value));
 
1239
        break;
 
1240
      case GET_ULONG_IS_FAIL:
1230
1241
        printf("%lu\n", *((ulong*) value));
1231
1242
        break;
 
1243
      case GET_SIZE:
 
1244
        int64_t2str((uint64_t)(*(size_t*)value), buff, 10);
 
1245
        printf("%s\n", buff);
 
1246
        break;
1232
1247
      case GET_LL:
1233
1248
        printf("%s\n", llstr(*((int64_t*) value), buff));
1234
1249
        break;
1235
1250
      case GET_ULL:
 
1251
      case GET_UINT64:
1236
1252
        int64_t2str(*((uint64_t*) value), buff, 10);
1237
1253
        printf("%s\n", buff);
1238
1254
        break;
1240
1256
        printf("%g\n", *(double*) value);
1241
1257
        break;
1242
1258
      default:
1243
 
        printf("(Disabled)\n");
 
1259
        printf(_("(Disabled)\n"));
1244
1260
        break;
1245
1261
      }
1246
1262
    }