~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/drizzled.cc

  • Committer: Monty Taylor
  • Date: 2010-08-17 02:54:36 UTC
  • mfrom: (1711.1.7 build)
  • Revision ID: mordred@inaugust.com-20100817025436-iuuqihjal6ubyffy
boost::program_options for InnoDB.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <netinet/in.h>
28
28
#include <signal.h>
29
29
#include <limits.h>
 
30
#include <stdexcept>
30
31
 
31
32
#include <boost/program_options.hpp>
32
33
#include <boost/thread/recursive_mutex.hpp>
787
788
  return 0;
788
789
}
789
790
 
 
791
static pair<string, string> parse_size_suffixes(string s)
 
792
{
 
793
  size_t equal_pos= s.find("=");
 
794
  if (equal_pos != string::npos)
 
795
  {
 
796
    string arg_key(s.substr(0, equal_pos));
 
797
    string arg_val(s.substr(equal_pos+1));
 
798
 
 
799
    try
 
800
    {
 
801
      size_t size_suffix_pos= arg_val.find_last_of("kmgKMG");
 
802
      if (size_suffix_pos == arg_val.size()-1)
 
803
      {
 
804
        char suffix= arg_val[size_suffix_pos];
 
805
        string size_val(arg_val.substr(0, size_suffix_pos));
 
806
 
 
807
        uint64_t base_size= boost::lexical_cast<uint64_t>(size_val);
 
808
        uint64_t new_size= 0;
 
809
 
 
810
        switch (suffix)
 
811
        {
 
812
        case 'K':
 
813
        case 'k':
 
814
          new_size= base_size * 1024;
 
815
          break;
 
816
        case 'M':
 
817
        case 'm':
 
818
          new_size= base_size * 1024 * 1024;
 
819
          break;
 
820
        case 'G':
 
821
        case 'g':
 
822
          new_size= base_size * 1024 * 1024 * 1024;
 
823
          break;
 
824
        }
 
825
        return make_pair(arg_key,
 
826
                         boost::lexical_cast<string>(new_size));
 
827
      }
 
828
    }
 
829
    catch (...)
 
830
    {
 
831
      /* Screw it, let the normal parser take over */
 
832
    }
 
833
  }
 
834
 
 
835
  return make_pair(string(""), string(""));
 
836
}
 
837
 
 
838
static pair<string, string> parse_size_arg(string s)
 
839
{
 
840
  if (s.find("--") == 0)
 
841
  {
 
842
    return parse_size_suffixes(s.substr(2));
 
843
  }
 
844
  return make_pair(string(""), string(""));
 
845
}
790
846
 
791
847
int init_server_components(module::Registry &plugins)
792
848
{
823
879
 
824
880
  po::parsed_options parsed= po::command_line_parser(defaults_argc,
825
881
                                                     defaults_argv).
826
 
    options(long_options).allow_unregistered().run();
 
882
    options(long_options).extra_parser(parse_size_arg).
 
883
    allow_unregistered().run();
827
884
 
828
885
  vector<string> unknown_options=
829
886
    po::collect_unrecognized(parsed.options, po::include_positional);