static const char *_def_delim=" \t\n\r";
static const char *_eq_delim="= \t\n\r";
+static const char *_eq_nospace_delim="=\t\n\r";
static const char *_eol_delim="\n\r";
/* static const char *_pr_delim="[] \t\n\r"; */
return 0;
}
-char *get_next_tok(char *str, const char *delim, int alloc, char **p)
+static char *get_next_tok(char *str, const char *delim, int alloc, char **p)
{
int i=0;
char *out;
return out;
}
+static char *get_next_name(char *str, int alloc, char **p)
+{
+ int i=0;
+ char *out;
+
+ while (*str && is_delim(*str, _def_delim)) {
+ str++;
+ }
+
+ if (*str == '"') {
+ while (str[i] && !is_delim(str[i], _eol_delim)) {
+ i++;
+ if (str[i] == '"') {
+ i++;
+ break;
+ }
+ }
+ } else {
+ while (str[i] && !is_delim(str[i], _eq_nospace_delim)) {
+ i++;
+ }
+
+ while (str[i] && is_delim(str[i], _def_delim)) {
+ i--;
+ }
+ }
+
+ if (alloc) {
+ out = (char *)malloc(i+1);
+ memcpy(out, str, i);
+ out[i] = '\0';
+ } else {
+ out = str;
+ }
+
+ if (p)
+ *p = &str[i];
+
+ return out;
+}
+
+static char *str_trim(char *str)
+{
+ char *head = str;
+ char *tail;
+
+ while (*head && is_delim(*head, _def_delim))
+ ++head;
+
+ head = strdup(head);
+
+ if (!(*head))
+ goto done;
+
+ tail = &head[strlen(head)-1];
+
+ while (*tail && is_delim(*tail, _def_delim))
+ --tail;
+
+ *(tail + 1) = '\0';
+
+done:
+ return head;
+}
+
+/*
+ * normalizes a var name, removes extra spaces; e.g., 'foo bar' -> 'foo bar'
+ */
+static char *normalize_name(char *name)
+{
+ char *newname, *p;
+ int i, len;
+ int last_delim = 0, had_delim = 0, had_non_delim = 0;
+
+ len = strlen(name);
+ newname = (char *)malloc(len + 1);
+
+ p = newname;
+
+ for (i=0; i < len; i++) {
+ int now_delim = is_delim(name[i], _def_delim);
+
+ if (!now_delim) {
+
+ if (had_delim && had_non_delim)
+ *p++ = ' ';
+
+ *p++ = name[i];
+
+ had_non_delim = 1;
+ had_delim = 0;
+ } else {
+ had_delim = 1;
+ }
+
+ last_delim = now_delim;
+ }
+
+ return newname;
+}
+
#define MAX_LINE 256
-char *get_next_delim(char *str, const char *delim, int alloc, char **p)
+static char *get_next_delim(char *str, const char *delim, int alloc, char **p)
{
int i=0;
char *out;
char *p = NULL;
char *eq;
int ret = 0;
+ char *var_name;
memset(parsed, 0, sizeof(ConfLine));
goto out;
switch (*p) {
+ case ';':
case '#':
parsed->set_suffix(p);
goto out;
char *str_val;
float fval;
bool bval;
+ char *s;
+
+
+ s = " hello world = kaka ";
+
+ printf("s'%s'\n", s);
+ s = get_next_name(s, 1, NULL);
+
+ printf("str_trim='%s'\n", s);
+
cf.parse();
cf.dump();
+
+
cf.set_auto_update(true);
cf.read("core", "repositoryformatversion", &val, 12);
dout_sym_dir: "out", // if daemonize == true
conf_file: "ceph.conf",
+ dump_conf: false,
fake_clock: false,
fakemessenger_serialize: true,
#define CF_READ_STR(section, var, inout) \
cf.read(section, var, (char **)&g_conf.inout, (char *)g_conf.inout)
-void parse_config_file(const char *fname)
+void parse_config_file(const char *fname, bool dump_conf)
{
ConfFile cf(fname);
- cf.set_auto_update(true);
+ cf.set_auto_update(dump_conf);
cf.parse();
CF_READ("bdstore", "bdbstore_transactional", bdbstore_transactional);
#endif
- cf.flush();
+ if (dump_conf)
+ cf.flush();
}
void parse_config_options(std::vector<const char*>& args, bool open)
{
std::vector<const char*> nargs;
+ for (unsigned i=0; i<args.size(); i++) {
+ if (strcmp(args[i], "--conf_file") == 0)
+ g_conf.conf_file = args[++i];
+ else if (strcmp(args[i], "--dump_conf") == 0)
+ g_conf.dump_conf = true;
+ }
+
+ parse_config_file(g_conf.conf_file, g_conf.dump_conf);
+
for (unsigned i=0; i<args.size(); i++) {
if (strcmp(args[i],"--bind") == 0)
assert(parse_ip_port(args[++i], g_my_addr));
}
}
- parse_config_file(g_conf.conf_file);
-
// open log file?
if (open)
_dout_open_log();