/* * add_string_reloption * Add a new string reloption * * "validator" is an optional function pointer that can be used to test the * validity of the values. It must elog(ERROR) when the argument string is * not acceptable for the variable. Note that the default value must pass * the validation. */ void add_string_reloption(bits32 kinds, char *name, char *desc, char *default_val, validate_string_relopt validator) { relopt_string *newoption; /* make sure the validator/default combination is sane */ if (validator) (validator) (default_val); newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING, name, desc); newoption->validate_cb = validator; if (default_val) { newoption->default_val = MemoryContextStrdup(TopMemoryContext, default_val); newoption->default_len = strlen(default_val); newoption->default_isnull = false; } else { newoption->default_val = ""; newoption->default_len = 0; newoption->default_isnull = true; } add_reloption((relopt_gen *) newoption); }
/* * add_bool_reloption * Add a new boolean reloption */ void add_bool_reloption(bits32 kinds, char *name, char *desc, bool default_val) { relopt_bool *newoption; newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL, name, desc); newoption->default_val = default_val; add_reloption((relopt_gen *) newoption); }
/* * add_real_reloption * Add a new float reloption */ void add_real_reloption(bits32 kinds, char *name, char *desc, double default_val, double min_val, double max_val) { relopt_real *newoption; newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL, name, desc); newoption->default_val = default_val; newoption->min = min_val; newoption->max = max_val; add_reloption((relopt_gen *) newoption); }
/* * add_int_reloption * Add a new integer reloption */ void add_int_reloption(bits32 kinds, char *name, char *desc, int default_val, int min_val, int max_val) { relopt_int *newoption; newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT, name, desc); newoption->default_val = default_val; newoption->min = min_val; newoption->max = max_val; add_reloption((relopt_gen *) newoption); }
/* * add_string_reloption * Add a new string reloption * * "validator" is an optional function pointer that can be used to test the * validity of the values. It must elog(ERROR) when the argument string is * not acceptable for the variable. Note that the default value must pass * the validation. */ void add_string_reloption(bits32 kinds, char *name, char *desc, char *default_val, validate_string_relopt validator) { MemoryContext oldcxt; relopt_string *newoption; int default_len = 0; oldcxt = MemoryContextSwitchTo(TopMemoryContext); if (default_val) default_len = strlen(default_val); newoption = palloc0(sizeof(relopt_string) + default_len); newoption->gen.name = pstrdup(name); if (desc) newoption->gen.desc = pstrdup(desc); else newoption->gen.desc = NULL; newoption->gen.kinds = kinds; newoption->gen.namelen = strlen(name); newoption->gen.type = RELOPT_TYPE_STRING; newoption->validate_cb = validator; if (default_val) { strcpy(newoption->default_val, default_val); newoption->default_len = default_len; newoption->default_isnull = false; } else { newoption->default_val[0] = '\0'; newoption->default_len = 0; newoption->default_isnull = true; } /* make sure the validator/default combination is sane */ if (newoption->validate_cb) (newoption->validate_cb) (newoption->default_val); MemoryContextSwitchTo(oldcxt); add_reloption((relopt_gen *) newoption); }