From 1613e75a4809dd7d37c5b70cbb48d0d6d728c118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Mon, 17 Aug 2015 00:08:19 +0200 Subject: mv 'struct config_item'{_,} Finally we can get rid of the trailing underscore. --- common.c | 106 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) (limited to 'common.c') diff --git a/common.c b/common.c index b104e0e..21634d4 100644 --- a/common.c +++ b/common.c @@ -1014,7 +1014,7 @@ enum config_item_type CONFIG_ITEM_STRING_ARRAY ///< Comma-separated list of strings }; -struct config_item_ +struct config_item { enum config_item_type type; ///< Type of the item union @@ -1040,10 +1040,10 @@ struct config_schema /// Check if the new value can be accepted. /// In addition to this, "type" and having a default is considered. - bool (*validate) (const struct config_item_ *, struct error **e); + bool (*validate) (const struct config_item *, struct error **e); /// The value has changed - void (*on_change) (struct config_item_ *); + void (*on_change) (struct config_item *); }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1073,7 +1073,7 @@ config_item_type_is_string (enum config_item_type type) } static void -config_item_free (struct config_item_ *self) +config_item_free (struct config_item *self) { switch (self->type) { @@ -1089,7 +1089,7 @@ config_item_free (struct config_item_ *self) } static void -config_item_destroy (struct config_item_ *self) +config_item_destroy (struct config_item *self) { config_item_free (self); free (self); @@ -1098,7 +1098,7 @@ config_item_destroy (struct config_item_ *self) /// Doesn't do any validations or handle schemas, just moves source data /// to the target item and destroys the source item static void -config_item_move (struct config_item_ *self, struct config_item_ *source) +config_item_move (struct config_item *self, struct config_item *source) { // Not quite sure how to handle that hard_assert (!source->schema); @@ -1109,40 +1109,40 @@ config_item_move (struct config_item_ *self, struct config_item_ *source) free (source); } -static struct config_item_ * +static struct config_item * config_item_new (enum config_item_type type) { - struct config_item_ *self = xcalloc (1, sizeof *self); + struct config_item *self = xcalloc (1, sizeof *self); self->type = type; return self; } -static struct config_item_ * +static struct config_item * config_item_null (void) { return config_item_new (CONFIG_ITEM_NULL); } -static struct config_item_ * +static struct config_item * config_item_boolean (bool b) { - struct config_item_ *self = config_item_new (CONFIG_ITEM_BOOLEAN); + struct config_item *self = config_item_new (CONFIG_ITEM_BOOLEAN); self->value.boolean = b; return self; } -static struct config_item_ * +static struct config_item * config_item_integer (int64_t i) { - struct config_item_ *self = config_item_new (CONFIG_ITEM_INTEGER); + struct config_item *self = config_item_new (CONFIG_ITEM_INTEGER); self->value.integer = i; return self; } -static struct config_item_ * +static struct config_item * config_item_string (const struct str *s) { - struct config_item_ *self = config_item_new (CONFIG_ITEM_STRING); + struct config_item *self = config_item_new (CONFIG_ITEM_STRING); str_init (&self->value.string); hard_assert (utf8_validate (self->value.string.str, self->value.string.len)); @@ -1150,29 +1150,29 @@ config_item_string (const struct str *s) return self; } -static struct config_item_ * +static struct config_item * config_item_string_from_cstr (const char *s) { struct str tmp; str_init (&tmp); str_append (&tmp, s); - struct config_item_ *self = config_item_string (&tmp); + struct config_item *self = config_item_string (&tmp); str_free (&tmp); return self; } -static struct config_item_ * +static struct config_item * config_item_string_array (const struct str *s) { - struct config_item_ *self = config_item_string (s); + struct config_item *self = config_item_string (s); self->type = CONFIG_ITEM_STRING_ARRAY; return self; } -static struct config_item_ * +static struct config_item * config_item_object (void) { - struct config_item_ *self = config_item_new (CONFIG_ITEM_OBJECT); + struct config_item *self = config_item_new (CONFIG_ITEM_OBJECT); str_map_init (&self->value.object); self->value.object.free = (void (*)(void *)) config_item_destroy; return self; @@ -1192,7 +1192,7 @@ config_schema_accepts_type } static bool -config_item_validate_by_schema (struct config_item_ *self, +config_item_validate_by_schema (struct config_item *self, struct config_schema *schema, struct error **e) { struct error *error = NULL; @@ -1211,7 +1211,7 @@ config_item_validate_by_schema (struct config_item_ *self, } static bool -config_item_set_from (struct config_item_ *self, struct config_item_ *source, +config_item_set_from (struct config_item *self, struct config_item *source, struct error **e) { struct config_schema *schema = self->schema; @@ -1238,8 +1238,8 @@ config_item_set_from (struct config_item_ *self, struct config_item_ *source, return true; } -static struct config_item_ * -config_item_get (struct config_item_ *self, const char *path, struct error **e) +static struct config_item * +config_item_get (struct config_item *self, const char *path, struct error **e) { hard_assert (self->type == CONFIG_ITEM_OBJECT); @@ -1247,7 +1247,7 @@ config_item_get (struct config_item_ *self, const char *path, struct error **e) str_vector_init (&v); split_str (path, '.', &v); - struct config_item_ *result = NULL; + struct config_item *result = NULL; size_t i = 0; while (true) { @@ -1277,7 +1277,7 @@ struct config_writer }; static void config_item_write_object_innards - (struct config_writer *self, struct config_item_ *object); + (struct config_writer *self, struct config_item *object); static void config_item_write_string (struct str *output, const struct str *s) @@ -1299,7 +1299,7 @@ config_item_write_string (struct str *output, const struct str *s) static void config_item_write_object - (struct config_writer *self, struct config_item_ *value) + (struct config_writer *self, struct config_item *value) { char indent[self->indent + 1]; memset (indent, '\t', self->indent); @@ -1318,7 +1318,7 @@ config_item_write_object } static void -config_item_write_value (struct config_writer *self, struct config_item_ *value) +config_item_write_value (struct config_writer *self, struct config_item *value) { switch (value->type) { @@ -1345,7 +1345,7 @@ config_item_write_value (struct config_writer *self, struct config_item_ *value) static void config_item_write_kv_pair (struct config_writer *self, - const char *key, struct config_item_ *value) + const char *key, struct config_item *value) { char indent[self->indent + 1]; memset (indent, '\t', self->indent); @@ -1362,20 +1362,20 @@ config_item_write_kv_pair (struct config_writer *self, static void config_item_write_object_innards - (struct config_writer *self, struct config_item_ *object) + (struct config_writer *self, struct config_item *object) { hard_assert (object->type == CONFIG_ITEM_OBJECT); struct str_map_iter iter; str_map_iter_init (&iter, &object->value.object); - struct config_item_ *value; + struct config_item *value; while ((value = str_map_iter_next (&iter))) config_item_write_kv_pair (self, iter.link->key, value); } static void -config_item_write (struct config_item_ *value, +config_item_write (struct config_item *value, bool object_innards, struct str *output) { struct config_writer writer = { .output = output, .indent = 0 }; @@ -1769,13 +1769,13 @@ config_parser_expect #define EXPECT(token) config_parser_expect (self, token, err) #define SKIP_NL() do {} while (ACCEPT (CONFIG_T_NEWLINE)) -static struct config_item_ *config_parser_parse_object +static struct config_item *config_parser_parse_object (struct config_parser *self, jmp_buf out); -static struct config_item_ * +static struct config_item * config_parser_parse_value (struct config_parser *self, jmp_buf out) { - struct config_item_ *volatile result = NULL; + struct config_item *volatile result = NULL; jmp_buf err; if (setjmp (err)) @@ -1810,7 +1810,7 @@ config_parser_parse_value (struct config_parser *self, jmp_buf out) /// Parse a single "key = value" assignment into @a object static bool config_parser_parse_kv_pair (struct config_parser *self, - struct config_item_ *object, jmp_buf out) + struct config_item *object, jmp_buf out) { char *volatile key = NULL; jmp_buf err; @@ -1851,10 +1851,10 @@ config_parser_parse_kv_pair (struct config_parser *self, } /// Parse the inside of an object definition -static struct config_item_ * +static struct config_item * config_parser_parse_object (struct config_parser *self, jmp_buf out) { - struct config_item_ *volatile object = config_item_object (); + struct config_item *volatile object = config_item_object (); jmp_buf err; if (setjmp (err)) @@ -1877,14 +1877,14 @@ config_parser_parse_object (struct config_parser *self, jmp_buf out) /// Parse a configuration snippet either as an object or a bare value. /// If it's the latter (@a single_value_only), no newlines may follow. -static struct config_item_ * +static struct config_item * config_item_parse (const char *script, size_t len, bool single_value_only, struct error **e) { struct config_parser parser; config_parser_init (&parser, script, len); - struct config_item_ *volatile object = NULL; + struct config_item *volatile object = NULL; jmp_buf err; if (setjmp (err)) @@ -1916,14 +1916,14 @@ end: } /// Clone an item. Schema assignments aren't retained. -struct config_item_ * -config_item_clone (struct config_item_ *self) +struct config_item * +config_item_clone (struct config_item *self) { // Oh well, it saves code struct str tmp; str_init (&tmp); config_item_write (self, false, &tmp); - struct config_item_ *result = + struct config_item *result = config_item_parse (tmp.str, tmp.len, true, NULL); str_free (&tmp); return result; @@ -1933,9 +1933,9 @@ config_item_clone (struct config_item_ *self) static void config_schema_initialize_item (struct config_schema *schema, - struct config_item_ *parent, void *user_data) + struct config_item *parent, void *user_data) { - struct config_item_ *item = + struct config_item *item = str_map_find (&parent->value.object, schema->name); bool replace = true; @@ -1981,7 +1981,7 @@ config_schema_initialize_item (struct config_schema *schema, static void config_schema_apply_to_object (struct config_schema *schema_array, - struct config_item_ *object, void *user_data) + struct config_item *object, void *user_data) { hard_assert (object->type == CONFIG_ITEM_OBJECT); while (schema_array->name) @@ -1989,14 +1989,14 @@ config_schema_apply_to_object (struct config_schema *schema_array, } static void -config_schema_call_changed (struct config_item_ *item) +config_schema_call_changed (struct config_item *item) { if (item->type == CONFIG_ITEM_OBJECT) { struct str_map_iter iter; str_map_iter_init (&iter, &item->value.object); - struct config_item_ *child; + struct config_item *child; while ((child = str_map_iter_next (&iter))) config_schema_call_changed (child); } @@ -2009,7 +2009,7 @@ config_schema_call_changed (struct config_item_ *item) // XXX: this doesn't necessarily have to be well designed at all typedef void (*config_module_load_fn) - (struct config_item_ *subtree, void *user_data); + (struct config_item *subtree, void *user_data); struct config_module { @@ -2035,7 +2035,7 @@ config_module_destroy (struct config_module *self) struct config { struct str_map modules; ///< Toplevel modules - struct config_item_ *root; ///< CONFIG_ITEM_OBJECT + struct config_item *root; ///< CONFIG_ITEM_OBJECT }; static void @@ -2067,7 +2067,7 @@ config_register_module (struct config *self, } static void -config_load (struct config *self, struct config_item_ *root) +config_load (struct config *self, struct config_item *root) { hard_assert (root->type == CONFIG_ITEM_OBJECT); self->root = root; @@ -2078,7 +2078,7 @@ config_load (struct config *self, struct config_item_ *root) struct config_module *module; while ((module = str_map_iter_next (&iter))) { - struct config_item_ *subtree = str_map_find + struct config_item *subtree = str_map_find (&root->value.object, module->name); // Silently fix inputs that only a lunatic user could create if (!subtree || subtree->type != CONFIG_ITEM_OBJECT) -- cgit v1.2.3