Skip to content

Commit

Permalink
ceph_argparse: remove unused macros, functions
Browse files Browse the repository at this point in the history
Signed-off-by: Colin McCabe <[email protected]>
  • Loading branch information
cmccabe committed Sep 6, 2011
1 parent a00e9db commit 21dbec9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 156 deletions.
114 changes: 0 additions & 114 deletions src/common/ceph_argparse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "include/str_list.h"
#include "msg/msg_types.h"

#include <deque>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
Expand All @@ -46,91 +45,6 @@
#undef generic_dout
#undef dendl

static bool cmd_is_char(const char *cmd)
{
return ((cmd[0] == '-') &&
cmd[1] && !cmd[2]);
}

bool ceph_argparse_cmd_equals(const char *cmd, const char *opt, char char_opt,
unsigned int *val_pos)
{
unsigned int i;
unsigned int len = strlen(opt);

*val_pos = 0;

if (!*cmd)
return false;

if (char_opt && cmd_is_char(cmd))
return (char_opt == cmd[1]);

if ((cmd[0] != '-') || (cmd[1] != '-'))
return false;

for (i=0; i<len; i++) {
if ((opt[i] == '_') || (opt[i] == '-')) {
switch (cmd[i+2]) {
case '-':
case '_':
continue;
default:
break;
}
}

if (cmd[i+2] != opt[i])
return false;
}

if (cmd[i+2] == '=')
*val_pos = i+3;
else if (cmd[i+2])
return false;

return true;
}

bool ceph_argparse_cmdline_val(void *field, int type, const char *val)
{
switch (type) {
case OPT_BOOL:
if (strcasecmp(val, "false") == 0)
*(bool *)field = false;
else if (strcasecmp(val, "true") == 0)
*(bool *)field = true;
else
*(bool *)field = (bool)atoi(val);
break;
case OPT_INT:
*(int *)field = atoi(val);
break;
case OPT_LONGLONG:
*(long long *)field = atoll(val);
break;
case OPT_STR:
if (val)
*(char **)field = strdup(val);
else
*(char **)field = NULL;
break;
case OPT_FLOAT:
*(float *)field = atof(val);
break;
case OPT_DOUBLE:
*(double *)field = strtod(val, NULL);
break;
case OPT_ADDR:
((entity_addr_t *)field)->parse(val);
break;
default:
return false;
}

return true;
}

void env_to_vec(std::vector<const char*>& args)
{
char *p = getenv("CEPH_ARGS");
Expand All @@ -154,41 +68,13 @@ void env_to_vec(std::vector<const char*>& args)
}
}

void env_to_deq(std::deque<const char*>& args)
{
char *p = getenv("CEPH_ARGS");
if (!p) return;

static char buf[1000];
int len = MIN(strlen(p), sizeof(buf)-1); // bleh.
memcpy(buf, p, len);
buf[len] = 0;

p = buf;
while (*p && p < buf + len) {
char *e = p;
while (*e && *e != ' ')
e++;
*e = 0;
args.push_back(p);
p = e+1;
}
}

void argv_to_vec(int argc, const char **argv,
std::vector<const char*>& args)
{
for (int i=1; i<argc; i++)
args.push_back(argv[i]);
}

void argv_to_deq(int argc, const char **argv,
std::deque<const char*>& args)
{
for (int i=1; i<argc; i++)
args.push_back(argv[i]);
}

void vec_to_argv(std::vector<const char*>& args,
int& argc, const char **&argv)
{
Expand Down
42 changes: 0 additions & 42 deletions src/common/ceph_argparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,6 @@
#include "common/entity_name.h"
#include "msg/msg_types.h"

/////////////////////// Macros ///////////////////////
#define FOR_EACH_ARG(args) \
__isarg = 1 < args.size(); \
for (unsigned i=0; i<args.size(); i++, __isarg = i+1 < args.size())

#define DEFINE_CONF_VARS(usage_func) \
unsigned int val_pos __attribute__((unused)); \
void (*args_usage)() __attribute__((unused)) = usage_func; \
bool __isarg __attribute__((unused))

#define CEPH_ARGPARSE_NEXT_VAL (val_pos ? &args[i][val_pos] : args[++i])

#define CEPH_ARGPARSE_VAL args[i]

#define CEPH_ARGPARSE_SET_ARG_VAL(dest, type) \
do { \
__isarg = i+1 < args.size(); \
if (__isarg && !val_pos && \
args[i+1][0] == '-' && args[i+1][1] != '\0') \
__isarg = false; \
if (type == OPT_BOOL) { \
if (val_pos) { \
ceph_argparse_cmdline_val(dest, type, CEPH_ARGPARSE_NEXT_VAL); \
} else \
ceph_argparse_cmdline_val(dest, type, "true"); \
} else if (__isarg || val_pos) { \
ceph_argparse_cmdline_val(dest, type, CEPH_ARGPARSE_NEXT_VAL); \
} else if (args_usage) \
args_usage(); \
} while (0)

#define CEPH_ARGPARSE_EQ(str_cmd, char_cmd) \
ceph_argparse_cmd_equals(args[i], str_cmd, char_cmd, &val_pos)

extern bool ceph_argparse_cmdline_val(void *field, int type,
const char *val);
extern bool ceph_argparse_cmd_equals(const char *cmd, const char *opt,
char char_opt, unsigned int *val_pos);

/////////////////////// Types ///////////////////////
class CephInitParameters
{
Expand All @@ -83,11 +44,8 @@ class CephInitParameters

/////////////////////// Functions ///////////////////////
extern void env_to_vec(std::vector<const char*>& args);
extern void env_to_deq(std::deque<const char*>& args);
extern void argv_to_vec(int argc, const char **argv,
std::vector<const char*>& args);
extern void argv_to_deq(int argc, const char **argv,
std::deque<const char*>& args);
extern void vec_to_argv(std::vector<const char*>& args,
int& argc, const char **&argv);

Expand Down

0 comments on commit 21dbec9

Please sign in to comment.