From: Christian Heller Date: Fri, 4 Apr 2014 01:30:04 +0000 (+0200) Subject: Minor refactorings in config file parse code to clear up code. X-Git-Tag: tce~782 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/todo?a=commitdiff_plain;h=0ff9d0a37959c6f297d33c23fed0eb889114c4bc;p=plomrogue Minor refactorings in config file parse code to clear up code. --- diff --git a/src/client/command_db.c b/src/client/command_db.c index 6e43ff6..a1c3551 100644 --- a/src/client/command_db.c +++ b/src/client/command_db.c @@ -36,8 +36,7 @@ enum cmd_flag * Individual CommandDB entries are put together line by line before being * written. Writing happens after all necessary members of an entry have been * assembled, and when additionally a) a new entry is started by a - * context->token0 of "COMMAND"; or b) a NULL context->token0 is passed. This is - * interpreted as the CommandDB read's end: appropriate cleanup flags are set. + * context->token0 of "COMMAND"; or b) a NULL context->token0 is passed. */ static void tokens_into_entries(struct Context * context); @@ -51,8 +50,9 @@ static void tokens_into_entries(struct Context * context) static struct Command * cmd = NULL; if (!context->token0 || !strcmp(context->token0, str_cmd)) { - err_line((cmd_flags & READY_CMD) ^ READY_CMD, context->line, - context->err_pre, "Last definition block not finished yet."); + char * err_fin = "Last definition block not finished yet."; + err_line((cmd_flags & READY_CMD) ^ READY_CMD, + context->line, context->err_pre, err_fin); if (cmd) { array_append(world.commandDB.n, sizeof(struct Command), @@ -61,27 +61,26 @@ static void tokens_into_entries(struct Context * context) cmd = NULL; } } - if (!context->token0) - { - set_cleanup_flag(CLEANUP_COMMANDS); - } - else if (!strcmp(context->token0, str_cmd)) + if (context->token0 && !strcmp(context->token0, str_cmd)) { + char * err_uniq = "Declaration of ID already used."; cmd_flags = EDIT_STARTED; cmd = try_malloc(sizeof(struct Command), f_name); memset(cmd, 0, sizeof(struct Command)); cmd->dsc_short = strdup(context->token1); - err_line(NULL != get_command(cmd->dsc_short), context->line, - context->err_pre, "Declaration of ID already used."); + err_line(NULL != get_command(cmd->dsc_short), + context->line, context->err_pre, err_uniq); } - else if (!( set_val(context, "DESCRIPTION", &cmd_flags, - DESC_SET, 's', (char *) &cmd->dsc_long) - || set_val(context, "SERVER_COMMAND", &cmd_flags, - SERVERCMD_SET, 's', (char *) &cmd->server_msg) - || set_val(context, "SERVER_ARGUMENT", &cmd_flags, - SERVERARG_SET, 'c', (char *) &cmd->arg))) + else if ( context->token0 + && !( set_val(context, "DESCRIPTION", &cmd_flags, + DESC_SET, 's', (char *) &cmd->dsc_long) + || set_val(context, "SERVER_COMMAND", &cmd_flags, + SERVERCMD_SET, 's', (char *) &cmd->server_msg) + || set_val(context, "SERVER_ARGUMENT", &cmd_flags, + SERVERARG_SET, 'c', (char *) &cmd->arg))) { - err_line(1, context->line, context->err_pre, "Unknown argument"); + char * err_unknown = "Unknown argument."; + err_line(1, context->line, context->err_pre, err_unknown); } } @@ -108,6 +107,7 @@ extern struct Command * get_command(char * dsc_short) extern void init_command_db() { parse_file(world.path_commands, tokens_into_entries); + set_cleanup_flag(CLEANUP_COMMANDS); } diff --git a/src/server/configfile.c b/src/server/configfile.c index f3d831e..e9cb34e 100644 --- a/src/server/configfile.c +++ b/src/server/configfile.c @@ -56,9 +56,7 @@ struct EntryHead * Individual MapObjDef / MapObjAct DB entries are put together line by line * before being written. Writing only happens after all necessary members of an * entry have been assembled, and when additionally a) a new entry is started by - * a context->token0 of "ACTION" or "OBJECT"; or b) a NULL context->token0 is - * passed. This is interpreted as the end of the MapObjDef / MapObjAct DB read, - * so the appropriate cleanup flags are set and test_corpse_ids() is called. + * a context->token0 of "ACTION" or "OBJECT"; or b) context->token0 is NULL. */ static void tokens_into_entries(struct Context * context); @@ -122,22 +120,18 @@ static void tokens_into_entries(struct Context * context) write_if_entry(&mod, (struct EntryHead ***) &mod_p_p); object_flags = action_flags = READY_OBJ; } - if (!context->token0) + if ( context->token0 + && !( new_entry(context, str_act, &action_flags, + sizeof(struct MapObjAct), (struct EntryHead**) &moa, + (struct EntryHead *) world.map_obj_acts) + || new_entry(context, str_obj, &object_flags, + sizeof(struct MapObjDef), (struct EntryHead**) &mod, + (struct EntryHead *) world.map_obj_defs) + || set_members(context, &object_flags, &action_flags, + (struct MapObjDef *) mod, (struct MapObjAct *) moa))) { - set_cleanup_flag(CLEANUP_MAP_OBJECT_ACTS | CLEANUP_MAP_OBJECT_DEFS); - test_corpse_ids(); - return; - } - if (!( new_entry(context, str_act, &action_flags, - sizeof(struct MapObjAct), (struct EntryHead**) &moa, - (struct EntryHead *) world.map_obj_acts) - || new_entry(context, str_obj, &object_flags, - sizeof(struct MapObjDef), (struct EntryHead**) &mod, - (struct EntryHead *) world.map_obj_defs) - || set_members(context, &object_flags, &action_flags, - (struct MapObjDef *) mod, (struct MapObjAct *) moa))) - { - err_line(1, context->line, context->err_pre, "Unknown argument"); + char * err_unknown = "Unknown argument."; + err_line(1, context->line, context->err_pre, err_unknown); } } @@ -261,4 +255,6 @@ static uint8_t try_func_name(struct MapObjAct * moa, extern void read_config_file() { parse_file(world.path_config, tokens_into_entries); + set_cleanup_flag(CLEANUP_MAP_OBJECT_ACTS | CLEANUP_MAP_OBJECT_DEFS); + test_corpse_ids(); }