~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/my_getopt.cc

  • Committer: Monty Taylor
  • Date: 2010-02-04 08:14:46 UTC
  • mfrom: (1277.2.1 build) (1280.2.1 build)
  • mto: This revision was merged to the branch mainline in revision 1283.
  • Revision ID: mordred@inaugust.com-20100204081446-ldh9m486va30uap6
Put everything in drizzled into drizzled namespace.
Put internal stuff into drizzled::internal namespace.
Removed some cruft.
Now every symbol that is shipped in a header is in the drizzled namespace
and everything in the server that's not shipped is labeled internal. woot. 
Removed a lot of the extra extern "C" stuff that was in there. Less ugliness for
internal callbacks now for Sun Studio.

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 "drizzled/internal/mysys_priv.h"
 
16
#include "config.h"
 
17
#include "drizzled/internal/my_sys.h"
17
18
#include <drizzled/gettext.h>
18
19
 
19
20
#include "drizzled/internal/m_string.h"
28
29
#include <algorithm>
29
30
 
30
31
using namespace std;
 
32
namespace drizzled
 
33
{
31
34
 
32
35
typedef void (*init_func_p)(const struct my_option *option, char **variable,
33
36
                            int64_t value);
34
37
 
35
 
extern "C" void default_reporter(enum loglevel level, const char *format, ...);
 
38
void default_reporter(enum loglevel level, const char *format, ...);
36
39
my_error_reporter my_getopt_error_reporter= &default_reporter;
37
40
 
38
41
static int findopt(char *optpat, uint32_t length,
73
76
 
74
77
bool my_getopt_skip_unknown= 0;
75
78
 
76
 
extern "C" void default_reporter(enum loglevel level, const char *format, ...)
 
79
void default_reporter(enum loglevel level, const char *format, ...)
77
80
{
78
81
  va_list args;
79
82
  va_start(args, format);
144
147
            {
145
148
              my_getopt_error_reporter(ERROR_LEVEL,
146
149
                                       "%s: Option '-O' requires an argument",
147
 
                                       my_progname);
 
150
                                       internal::my_progname);
148
151
              return EXIT_ARGUMENT_REQUIRED;
149
152
            }
150
153
            cur_arg= *pos;
161
164
            {
162
165
              my_getopt_error_reporter(ERROR_LEVEL,
163
166
                                       "%s: Option '--set-variable' requires an argument",
164
 
                                       my_progname);
 
167
                                       internal::my_progname);
165
168
              return EXIT_ARGUMENT_REQUIRED;
166
169
            }
167
170
          }
174
177
            {
175
178
              my_getopt_error_reporter(ERROR_LEVEL,
176
179
                                       "%s: Option '--set-variable' requires an argument",
177
 
                                       my_progname);
 
180
                                       internal::my_progname);
178
181
              return EXIT_ARGUMENT_REQUIRED;
179
182
            }
180
183
            cur_arg= *pos;
239
242
                  {
240
243
                    my_getopt_error_reporter(ERROR_LEVEL,
241
244
                                             "%s: ambiguous option '--%s-%s' (--%s-%s)",
242
 
                                             my_progname, special_opt_prefix[i],
 
245
                                             internal::my_progname,
 
246
                                             special_opt_prefix[i],
243
247
                                             cur_arg, special_opt_prefix[i],
244
248
                                             prev_found);
245
249
                    return EXIT_AMBIGUOUS_OPTION;
289
293
              my_getopt_error_reporter(option_is_loose ?
290
294
                                       WARNING_LEVEL : ERROR_LEVEL,
291
295
                                       "%s: unknown variable '%s'",
292
 
                                       my_progname, cur_arg);
 
296
                                       internal::my_progname, cur_arg);
293
297
              if (!option_is_loose)
294
298
                return EXIT_UNKNOWN_VARIABLE;
295
299
            }
298
302
              my_getopt_error_reporter(option_is_loose ?
299
303
                                       WARNING_LEVEL : ERROR_LEVEL,
300
304
                                       "%s: unknown option '--%s'",
301
 
                                       my_progname, cur_arg);
 
305
                                       internal::my_progname, cur_arg);
302
306
              if (!option_is_loose)
303
307
                return EXIT_UNKNOWN_OPTION;
304
308
            }
315
319
          {
316
320
            my_getopt_error_reporter(ERROR_LEVEL,
317
321
                                     "%s: variable prefix '%s' is not unique",
318
 
                                     my_progname, opt_str);
 
322
                                     internal::my_progname, opt_str);
319
323
            return EXIT_VAR_PREFIX_NOT_UNIQUE;
320
324
          }
321
325
          else
322
326
          {
323
327
            my_getopt_error_reporter(ERROR_LEVEL,
324
328
                                     "%s: ambiguous option '--%s' (%s, %s)",
325
 
                                     my_progname, opt_str, prev_found,
 
329
                                     internal::my_progname, opt_str, prev_found,
326
330
                                     optp->name);
327
331
            return EXIT_AMBIGUOUS_OPTION;
328
332
          }
330
334
        if ((optp->var_type & GET_TYPE_MASK) == GET_DISABLED)
331
335
        {
332
336
          fprintf(stderr,
333
 
                  _("%s: %s: Option '%s' used, but is disabled\n"), my_progname,
 
337
                  _("%s: %s: Option '%s' used, but is disabled\n"),
 
338
                  internal::my_progname,
334
339
                  option_is_loose ? _("WARNING") : _("ERROR"), opt_str);
335
340
          if (option_is_loose)
336
341
          {
343
348
        {
344
349
          my_getopt_error_reporter(ERROR_LEVEL,
345
350
                                   "%s: option '%s' cannot take an argument",
346
 
                                   my_progname, optp->name);
 
351
                                   internal::my_progname, optp->name);
347
352
          return EXIT_NO_ARGUMENT_ALLOWED;
348
353
        }
349
354
        value= optp->var_type & GET_ASK_ADDR ?
355
360
          {
356
361
            my_getopt_error_reporter(ERROR_LEVEL,
357
362
                                     "%s: option '--%s' cannot take an argument",
358
 
                                     my_progname, optp->name);
 
363
                                     internal::my_progname, optp->name);
359
364
            return EXIT_NO_ARGUMENT_ALLOWED;
360
365
          }
361
366
          if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL)
375
380
            else
376
381
            {
377
382
              my_getopt_error_reporter(WARNING_LEVEL,
378
 
                                       "%s: ignoring option '--%s' due to \
379
 
invalid value '%s'",
380
 
                                       my_progname, optp->name, optend);
 
383
                                       "%s: ignoring option '--%s' due to "
 
384
                                       "invalid value '%s'",
 
385
                                       internal::my_progname,
 
386
                                       optp->name, optend);
381
387
              continue;
382
388
            }
383
389
            get_one_option(optp->id, optp,
407
413
          {
408
414
            my_getopt_error_reporter(ERROR_LEVEL,
409
415
                                     "%s: option '--%s' requires an argument",
410
 
                                     my_progname, optp->name);
 
416
                                     internal::my_progname, optp->name);
411
417
            return EXIT_ARGUMENT_REQUIRED;
412
418
          }
413
419
          argument= *pos;
431
437
              {
432
438
                fprintf(stderr,
433
439
                        _("%s: ERROR: Option '-%c' used, but is disabled\n"),
434
 
                        my_progname, optp->id);
 
440
                        internal::my_progname, optp->id);
435
441
                return EXIT_OPTION_DISABLED;
436
442
              }
437
443
              if ((optp->var_type & GET_TYPE_MASK) == GET_BOOL &&
464
470
                  if (!pos[1])
465
471
                  {
466
472
                    my_getopt_error_reporter(ERROR_LEVEL,
467
 
                                             "%s: option '-%c' requires an argument",
468
 
                                             my_progname, optp->id);
 
473
                                             "%s: option '-%c' requires "
 
474
                                             "an argument",
 
475
                                             internal::my_progname, optp->id);
469
476
                    return EXIT_ARGUMENT_REQUIRED;
470
477
                  }
471
478
                  argument= *++pos;
477
484
                                 set_maximum_value)))
478
485
              {
479
486
                my_getopt_error_reporter(ERROR_LEVEL,
480
 
                                         "%s: Error while setting value '%s' to '%s'",
481
 
                                         my_progname, argument, optp->name);
 
487
                                         "%s: Error while setting value '%s' "
 
488
                                         "to '%s'",
 
489
                                         internal::my_progname,
 
490
                                         argument, optp->name);
482
491
                return error;
483
492
              }
484
493
              get_one_option(optp->id, optp, argument);
489
498
          {
490
499
            my_getopt_error_reporter(ERROR_LEVEL,
491
500
                                     "%s: unknown option '-%c'",
492
 
                                     my_progname, *optend);
 
501
                                     internal::my_progname, *optend);
493
502
            return EXIT_UNKNOWN_OPTION;
494
503
          }
495
504
        }
500
509
      {
501
510
        my_getopt_error_reporter(ERROR_LEVEL,
502
511
                                 "%s: Error while setting value '%s' to '%s'",
503
 
                                 my_progname, argument, optp->name);
 
512
                                 internal::my_progname, argument, optp->name);
504
513
        return error;
505
514
      }
506
515
      get_one_option(optp->id, optp, argument);
824
833
  else if (adjusted)
825
834
    my_getopt_error_reporter(WARNING_LEVEL,
826
835
                             "option '%s': signed value %s adjusted to %s",
827
 
                             optp->name, llstr(old, buf1), llstr(num, buf2));
 
836
                             optp->name, internal::llstr(old, buf1), internal::llstr(num, buf2));
828
837
  return num;
829
838
}
830
839
 
909
918
  else if (adjusted)
910
919
    my_getopt_error_reporter(WARNING_LEVEL,
911
920
                             "option '%s': unsigned value %s adjusted to %s",
912
 
                             optp->name, ullstr(old, buf1), ullstr(num, buf2));
 
921
                             optp->name, internal::ullstr(old, buf1), internal::ullstr(num, buf2));
913
922
 
914
923
  return num;
915
924
}
932
941
  double num;
933
942
  int error;
934
943
  char *end= arg + 1000;                     /* Big enough as *arg is \0 terminated */
935
 
  num= my_strtod(arg, &end, &error);
 
944
  num= internal::my_strtod(arg, &end, &error);
936
945
  if (end[0] != 0 || error)
937
946
  {
938
947
    fprintf(stderr,
939
948
            _("%s: ERROR: Invalid decimal value for option '%s'\n"),
940
 
            my_progname, optp->name);
 
949
            internal::my_progname, optp->name);
941
950
    *err= EXIT_ARGUMENT_INVALID;
942
951
    return 0.0;
943
952
  }
1241
1250
        printf("%lu\n", *((ulong*) value));
1242
1251
        break;
1243
1252
      case GET_SIZE:
1244
 
        int64_t2str((uint64_t)(*(size_t*)value), buff, 10);
 
1253
        internal::int64_t2str((uint64_t)(*(size_t*)value), buff, 10);
1245
1254
        printf("%s\n", buff);
1246
1255
        break;
1247
1256
      case GET_LL:
1248
 
        printf("%s\n", llstr(*((int64_t*) value), buff));
 
1257
        printf("%s\n", internal::llstr(*((int64_t*) value), buff));
1249
1258
        break;
1250
1259
      case GET_ULL:
1251
1260
      case GET_UINT64:
1252
 
        int64_t2str(*((uint64_t*) value), buff, 10);
 
1261
        internal::int64_t2str(*((uint64_t*) value), buff, 10);
1253
1262
        printf("%s\n", buff);
1254
1263
        break;
1255
1264
      case GET_DOUBLE:
1262
1271
    }
1263
1272
  }
1264
1273
}
 
1274
 
 
1275
} /* namespace drizzled */