X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fcommon%2Fceph_argparse.cc;fp=src%2Fceph%2Fsrc%2Fcommon%2Fceph_argparse.cc;h=0000000000000000000000000000000000000000;hb=7da45d65be36d36b880cc55c5036e96c24b53f00;hp=355224d0a84f0b975d10a722ed1d036145031207;hpb=691462d09d0987b47e112d6ee8740375df3c51b2;p=stor4nfv.git diff --git a/src/ceph/src/common/ceph_argparse.cc b/src/ceph/src/common/ceph_argparse.cc deleted file mode 100644 index 355224d..0000000 --- a/src/ceph/src/common/ceph_argparse.cc +++ /dev/null @@ -1,535 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2004-2006 Sage Weil - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#include "auth/Auth.h" -#include "common/ceph_argparse.h" -#include "common/config.h" -#include "common/version.h" -#include "include/str_list.h" - -/* - * Ceph argument parsing library - * - * We probably should eventually replace this with something standard like popt. - * Until we do that, though, this file is the place for argv parsing - * stuff to live. - */ - -#undef dout -#undef pdout -#undef derr -#undef generic_dout -#undef dendl - -struct strict_str_convert { - const char *str; - std::string *err; - strict_str_convert(const char *str, std::string *err) - : str(str), err(err) {} - - inline operator float() const - { - return strict_strtof(str, err); - } - inline operator int() const - { - return strict_strtol(str, 10, err); - } - inline operator long long() const - { - return strict_strtoll(str, 10, err); - } -}; - -void string_to_vec(std::vector& args, std::string argstr) -{ - istringstream iss(argstr); - while(iss) { - string sub; - iss >> sub; - if (sub == "") break; - args.push_back(sub); - } -} - -bool split_dashdash(const std::vector& args, - std::vector& options, - std::vector& arguments) { - bool dashdash = false; - for (std::vector::const_iterator i = args.begin(); - i != args.end(); - ++i) { - if (dashdash) { - arguments.push_back(*i); - } else { - if (strcmp(*i, "--") == 0) - dashdash = true; - else - options.push_back(*i); - } - } - return dashdash; -} - -void env_to_vec(std::vector& args, const char *name) -{ - if (!name) - name = "CEPH_ARGS"; - char *p = getenv(name); - if (!p) - return; - - bool dashdash = false; - std::vector options; - std::vector arguments; - if (split_dashdash(args, options, arguments)) - dashdash = true; - - std::vector env_options; - std::vector env_arguments; - static vector str_vec; - std::vector env; - str_vec.clear(); - get_str_vec(p, " ", str_vec); - for (vector::iterator i = str_vec.begin(); - i != str_vec.end(); - ++i) - env.push_back(i->c_str()); - if (split_dashdash(env, env_options, env_arguments)) - dashdash = true; - - args.clear(); - args.insert(args.end(), options.begin(), options.end()); - args.insert(args.end(), env_options.begin(), env_options.end()); - if (dashdash) - args.push_back("--"); - args.insert(args.end(), arguments.begin(), arguments.end()); - args.insert(args.end(), env_arguments.begin(), env_arguments.end()); -} - -void argv_to_vec(int argc, const char **argv, - std::vector& args) -{ - args.insert(args.end(), argv + 1, argv + argc); -} - -void vec_to_argv(const char *argv0, std::vector& args, - int *argc, const char ***argv) -{ - *argv = (const char**)malloc(sizeof(char*) * (args.size() + 1)); - if (!*argv) - throw bad_alloc(); - *argc = 1; - (*argv)[0] = argv0; - - for (unsigned i=0; i= '0' && nextargstr[i] <= '9')) { - // May be negative numeral value - if ((i == 0) && (strlen(nextargstr) >= 2)) { - if (nextargstr[0] == '-') - continue; - } - if ( (nextargstr[i] == '.') && (is_float == false) ) { - is_float = true; - continue; - } - - is_numeric = false; - break; - } - } - - // -