aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2019-08-13 10:43:37 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2019-08-13 10:53:34 +0300
commitde2199355a67daa33d3b86a8e5a78d3e7f15a121 (patch)
tree083c30637a67e26c684023fa1cb0f7a5480cdf44
parenta296768406acb95aade0320975bf1232041422b8 (diff)
downloadvcsync-de2199355a67daa33d3b86a8e5a78d3e7f15a121.tar.gz
vcsync-de2199355a67daa33d3b86a8e5a78d3e7f15a121.tar.bz2
Minor changes
* src/config.c: Use grecs assertion functions instead of local wrappers. (config_finish): If vcs_type is specified, try to select a matching named configuration first, even if the default one has the vcs-type statement.
-rw-r--r--src/config.c79
1 files changed, 20 insertions, 59 deletions
diff --git a/src/config.c b/src/config.c
index 422863e..2a3e89e 100644
--- a/src/config.c
+++ b/src/config.c
@@ -16,7 +16,6 @@
*/
#include "vcsync.h"
-#include <assert.h>
int cfg_facility = LOG_USER;
int cfg_print_priority;
@@ -26,44 +25,6 @@ static struct vcsync_config *config_head, *config_tail;
struct vcsync_config *config;
char const *config_name;
-#define ASSERT_SCALAR(cmd, locus) \
- if ((cmd) != grecs_callback_set_value) { \
- grecs_error(locus, 0, "Unexpected block statement"); \
- return 1; \
- }
-
-static char *
-my_grecs_basic_type_string(int t)
-{
- switch (t) {
- case GRECS_TYPE_STRING:
- return "string";
- case GRECS_TYPE_ARRAY:
- return "array";
- case GRECS_TYPE_LIST:
- return "list";
- }
- return "unknown";
-}
-
-int
-assert_grecs_value_type(grecs_locus_t *locus,
- const grecs_value_t *value, int type)
-{
- if (GRECS_VALUE_EMPTY_P(value)) {
- grecs_error(locus, 0, "expected %s",
- my_grecs_basic_type_string(type));
- return 1;
- }
- if (value->type != type) {
- grecs_error(locus, 0, "expected %s, but found %s",
- my_grecs_basic_type_string(type),
- my_grecs_basic_type_string(value->type));
- return 1;
- }
- return 0;
-}
-
static int
cb_vcs_type(enum grecs_callback_command cmd, grecs_node_t *node,
void *varptr, void *cb_data)
@@ -71,9 +32,9 @@ cb_vcs_type(enum grecs_callback_command cmd, grecs_node_t *node,
grecs_locus_t *locus = &node->locus;
grecs_value_t *value = node->v.value;
struct vcsync_config *conf = varptr;
-
- ASSERT_SCALAR(cmd, locus);
- if (assert_grecs_value_type(&value->locus, value, GRECS_TYPE_STRING))
+
+ grecs_assert_scalar_stmt(locus, cmd);
+ if (grecs_assert_value_type(value, GRECS_TYPE_STRING, &value->locus))
return 1;
conf->vcs_type = estrdup(value->v.string);
conf->proc = vcs_proc_get(value->v.string);
@@ -90,7 +51,7 @@ cb_define(enum grecs_callback_command cmd, grecs_node_t *node,
grecs_value_t *value = node->v.value;
int rc;
- ASSERT_SCALAR(cmd, locus);
+ grecs_assert_scalar_stmt(locus, cmd);
switch (value->type) {
case GRECS_TYPE_STRING:
rc = checkoutrc_register_keyword(value->v.string, NULL);
@@ -99,21 +60,21 @@ cb_define(enum grecs_callback_command cmd, grecs_node_t *node,
case GRECS_TYPE_ARRAY:
switch (value->v.arg.c) {
case 1:
- if (assert_grecs_value_type(&value->v.arg.v[0]->locus,
- value->v.arg.v[0],
- GRECS_TYPE_STRING))
+ if (grecs_assert_value_type(value->v.arg.v[0],
+ GRECS_TYPE_STRING,
+ &value->v.arg.v[0]->locus))
return 1;
rc = checkoutrc_register_keyword
(value->v.arg.v[0]->v.string, NULL);
break;
case 2:
- if (assert_grecs_value_type(&value->v.arg.v[0]->locus,
- value->v.arg.v[0],
- GRECS_TYPE_STRING))
+ if (grecs_assert_value_type(value->v.arg.v[0],
+ GRECS_TYPE_STRING,
+ &value->v.arg.v[0]->locus))
return 1;
- if (assert_grecs_value_type(&value->v.arg.v[1]->locus,
- value->v.arg.v[1],
- GRECS_TYPE_STRING))
+ if (grecs_assert_value_type(value->v.arg.v[1],
+ GRECS_TYPE_STRING,
+ &value->v.arg.v[1]->locus))
return 1;
rc = checkoutrc_register_keyword
(value->v.arg.v[0]->v.string,
@@ -208,8 +169,8 @@ cb_syslog_facility(enum grecs_callback_command cmd, grecs_node_t *node,
grecs_locus_t *locus = &node->locus;
grecs_value_t *value = node->v.value;
- ASSERT_SCALAR(cmd, locus);
- if (assert_grecs_value_type(&value->locus, value, GRECS_TYPE_STRING))
+ grecs_assert_scalar_stmt(locus, cmd);
+ if (grecs_assert_value_type(value, GRECS_TYPE_STRING, &value->locus))
return 1;
if (get_facility(value->v.string, varptr))
@@ -420,8 +381,8 @@ cb_sockaddr(enum grecs_callback_command cmd, grecs_node_t *node,
char *path;
char *port;
- ASSERT_SCALAR(cmd, locus);
- if (assert_grecs_value_type(&value->locus, value, GRECS_TYPE_STRING))
+ grecs_assert_scalar_stmt(locus, cmd);
+ if (grecs_assert_value_type(value, GRECS_TYPE_STRING, &value->locus))
return 1;
if (parse_url(&value->locus, value->v.string,
@@ -441,8 +402,8 @@ cb_config(enum grecs_callback_command cmd, grecs_node_t *node,
switch (cmd) {
case grecs_callback_section_begin:
- if (assert_grecs_value_type(&node->locus,
- node->v.value, GRECS_TYPE_STRING))
+ if (grecs_assert_value_type(node->v.value, GRECS_TYPE_STRING,
+ &node->locus))
return 1;
cp = ecalloc(1, sizeof(*cp));
cp->name = estrdup(node->v.value->v.string);
@@ -612,7 +573,7 @@ config_finish(struct grecs_node *tree)
if (!config)
die(EX_USAGE, "configuration \"%s\" not defined",
config_name);
- } else if (default_config.vcs_type) {
+ } else if (default_config.vcs_type && !vcs_type) {
default_config.proc = vcs_proc_get(default_config.vcs_type);
if (!default_config.proc)
die(EX_USAGE, "unknown VCS: %s",

Return to:

Send suggestions and report system problems to the System administrator.