From: Christian Heller Date: Wed, 9 Jul 2014 20:59:04 +0000 (+0200) Subject: Server: Start hardcoded_strings s's enum names with prefix "S_". X-Git-Tag: tce~724 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/conditions?a=commitdiff_plain;h=150b9f88a4c73caad8fcf0b850db8e52e4f4c6ae;p=plomrogue Server: Start hardcoded_strings s's enum names with prefix "S_". --- diff --git a/src/server/ai.c b/src/server/ai.c index bc78e06..497d35d 100644 --- a/src/server/ai.c +++ b/src/server/ai.c @@ -170,11 +170,11 @@ static char get_dir_to_nearest_enemy(struct Thing * t_origin) extern void ai(struct Thing * t) { - t->command = get_thing_action_id_by_name(s[CMD_WAIT]); + t->command = get_thing_action_id_by_name(s[S_CMD_WAIT]); char sel = t->fov_map ? get_dir_to_nearest_enemy(t) : 0;/* t->fov_map may */ if (0 != sel) /* be absent due */ { /* to god command.*/ - t->command = get_thing_action_id_by_name(s[CMD_MOVE]); + t->command = get_thing_action_id_by_name(s[S_CMD_MOVE]); t->arg = sel; } } diff --git a/src/server/cleanup.c b/src/server/cleanup.c index 02f52b3..2e7ab83 100644 --- a/src/server/cleanup.c +++ b/src/server/cleanup.c @@ -26,7 +26,7 @@ extern void cleanup() free(world.map.cells); if (cleanup_flags & CLEANUP_WORLDSTATE) { - unlink(s[PATH_WORLDSTATE]); + unlink(s[S_PATH_WORLDSTATE]); } if (cleanup_flags & CLEANUP_THINGS) { @@ -43,13 +43,13 @@ extern void cleanup() if (cleanup_flags & CLEANUP_IN) { try_fclose(world.file_in, f_name); - unlink(s[PATH_IN]); + unlink(s[S_PATH_IN]); } if (cleanup_flags & CLEANUP_OUT) { try_fclose(world.file_out, f_name); free(world.server_test); - unlink(s[PATH_OUT]); + unlink(s[S_PATH_OUT]); } } diff --git a/src/server/configfile.c b/src/server/configfile.c index f6561aa..ca1b07f 100644 --- a/src/server/configfile.c +++ b/src/server/configfile.c @@ -257,10 +257,10 @@ static uint8_t set_members(char * token0, char * token1, uint8_t * thing_flags, && parse_flagval(token0, token1, "NAME", action_flags, NAME_SET, 's', (char *) &ta->name)) { - if (!( try_func_name(ta, s[CMD_MOVE], actor_move) - || try_func_name(ta, s[CMD_PICKUP], actor_pick) - || try_func_name(ta, s[CMD_DROP], actor_drop) - || try_func_name(ta, s[CMD_USE], actor_use))) + if (!( try_func_name(ta, s[S_CMD_MOVE], actor_move) + || try_func_name(ta, s[S_CMD_PICKUP], actor_pick) + || try_func_name(ta, s[S_CMD_DROP], actor_drop) + || try_func_name(ta, s[S_CMD_USE], actor_use))) { ta->func = actor_wait; } @@ -304,7 +304,7 @@ static uint8_t try_func_name(struct ThingAction * ta, char * name, extern void read_config_file() { - parse_file(s[PATH_CONFIG], tokens_into_entries); + parse_file(s[S_PATH_CONFIG], tokens_into_entries); exit_err(!world.map.length, "Map size not defined in config file."); uint8_t player_type_is_valid = 0; struct ThingType * tt; diff --git a/src/server/hardcoded_strings.c b/src/server/hardcoded_strings.c index e007547..8ce7475 100644 --- a/src/server/hardcoded_strings.c +++ b/src/server/hardcoded_strings.c @@ -10,30 +10,30 @@ char * s[26]; extern void init_strings() { - s[PATH_CONFIG] = "confserver/world"; - s[PATH_WORLDSTATE] = "server/worldstate"; - s[PATH_OUT] = "server/out"; - s[PATH_IN] = "server/in"; - s[PATH_RECORD] = "record"; - s[PATH_SUFFIX_TMP] = "_tmp"; - s[PATH_SAVE] = "savefile"; - s[CMD_MAKE_WORLD] = "MAKE_WORLD"; - s[CMD_DO_FOV] = "BUILD_FOVS"; - s[CMD_SEED_MAP] = "SEED_MAP"; - s[CMD_SEED_RAND] = "SEED_RANDOMNESS"; - s[CMD_TURN] = "TURN"; - s[CMD_THING] = "THING"; - s[CMD_TYPE] = "TYPE"; - s[CMD_POS_Y] = "POS_Y"; - s[CMD_POS_X] = "POS_X"; - s[CMD_COMMAND] = "COMMAND"; - s[CMD_ARGUMENT] = "ARGUMENT"; - s[CMD_PROGRESS] = "PROGRESS"; - s[CMD_LIFEPOINTS] = "LIFEPOINTS"; - s[CMD_CARRIES] = "CARRIES"; - s[CMD_WAIT] = "wait"; - s[CMD_MOVE] = "move"; - s[CMD_PICKUP] = "pick_up"; - s[CMD_DROP] = "drop"; - s[CMD_USE] = "use"; + s[S_PATH_CONFIG] = "confserver/world"; + s[S_PATH_WORLDSTATE] = "server/worldstate"; + s[S_PATH_OUT] = "server/out"; + s[S_PATH_IN] = "server/in"; + s[S_PATH_RECORD] = "record"; + s[S_PATH_SUFFIX_TMP] = "_tmp"; + s[S_PATH_SAVE] = "savefile"; + s[S_CMD_MAKE_WORLD] = "MAKE_WORLD"; + s[S_CMD_DO_FOV] = "BUILD_FOVS"; + s[S_CMD_SEED_MAP] = "SEED_MAP"; + s[S_CMD_SEED_RAND] = "SEED_RANDOMNESS"; + s[S_CMD_TURN] = "TURN"; + s[S_CMD_THING] = "THING"; + s[S_CMD_TYPE] = "TYPE"; + s[S_CMD_POS_Y] = "POS_Y"; + s[S_CMD_POS_X] = "POS_X"; + s[S_CMD_COMMAND] = "COMMAND"; + s[S_CMD_ARGUMENT] = "ARGUMENT"; + s[S_CMD_PROGRESS] = "PROGRESS"; + s[S_CMD_LIFEPOINTS] = "LIFEPOINTS"; + s[S_CMD_CARRIES] = "CARRIES"; + s[S_CMD_WAIT] = "wait"; + s[S_CMD_MOVE] = "move"; + s[S_CMD_PICKUP] = "pick_up"; + s[S_CMD_DROP] = "drop"; + s[S_CMD_USE] = "use"; } diff --git a/src/server/hardcoded_strings.h b/src/server/hardcoded_strings.h index 3fda2ac..563323a 100644 --- a/src/server/hardcoded_strings.h +++ b/src/server/hardcoded_strings.h @@ -10,32 +10,32 @@ enum string_num { - PATH_CONFIG, - PATH_WORLDSTATE, - PATH_OUT, - PATH_IN, - PATH_RECORD, - PATH_SUFFIX_TMP, - PATH_SAVE, - CMD_MAKE_WORLD, - CMD_DO_FOV, - CMD_SEED_MAP, - CMD_SEED_RAND, - CMD_TURN, - CMD_THING, - CMD_TYPE, - CMD_POS_Y, - CMD_POS_X, - CMD_COMMAND, - CMD_ARGUMENT, - CMD_PROGRESS, - CMD_LIFEPOINTS, - CMD_CARRIES, - CMD_WAIT, - CMD_MOVE, - CMD_PICKUP, - CMD_DROP, - CMD_USE + S_S_PATH_CONFIG, + S_S_PATH_WORLDSTATE, + S_S_PATH_OUT, + S_S_PATH_IN, + S_S_PATH_RECORD, + S_S_PATH_SUFFIX_TMP, + S_S_PATH_SAVE, + S_S_CMD_MAKE_WORLD, + S_S_CMD_DO_FOV, + S_S_CMD_SEED_MAP, + S_S_CMD_SEED_RAND, + S_S_CMD_TURN, + S_S_CMD_THING, + S_S_CMD_TYPE, + S_S_CMD_POS_Y, + S_S_CMD_POS_X, + S_S_CMD_COMMAND, + S_S_CMD_ARGUMENT, + S_S_CMD_PROGRESS, + S_S_CMD_LIFEPOINTS, + S_S_CMD_CARRIES, + S_S_CMD_WAIT, + S_S_CMD_MOVE, + S_S_CMD_PICKUP, + S_S_CMD_DROP, + S_S_CMD_USE }; extern void init_strings(); diff --git a/src/server/init.c b/src/server/init.c index 1060474..766d92e 100644 --- a/src/server/init.c +++ b/src/server/init.c @@ -40,8 +40,8 @@ static void replay_game(); static void replay_game() { char * f_name = "replay_game()"; - exit_err(access(s[PATH_RECORD], F_OK), "No record found to replay."); - FILE * file = try_fopen(s[PATH_RECORD], "r", f_name); + exit_err(access(s[S_PATH_RECORD], F_OK), "No record found to replay."); + FILE * file = try_fopen(s[S_PATH_RECORD], "r", f_name); uint32_t linemax = textfile_width(file); char * line = try_malloc(linemax + 1, f_name); while ( world.turn < world.replay @@ -98,7 +98,7 @@ extern void setup_server_io() char * f_name = "setup_server_io()"; int test = mkdir("server", 0700); exit_trouble(test && EEXIST != errno, f_name, "mkdir()"); - world.file_out = try_fopen(s[PATH_OUT], "w", f_name); + world.file_out = try_fopen(s[S_PATH_OUT], "w", f_name); world.server_test = try_malloc(10 + 1 + 10 + 1 + 1, f_name); test = sprintf(world.server_test, "%d %d\n", getpid(), (int) time(0)); exit_trouble(test < 0, f_name, "sprintf()"); @@ -106,7 +106,7 @@ extern void setup_server_io() world.file_out, f_name); fflush(world.file_out); set_cleanup_flag(CLEANUP_OUT); - char * path_in = s[PATH_IN]; + char * path_in = s[S_PATH_IN]; if (!access(path_in, F_OK)) /* This keeps out input from old input */ { /* file streams of clients */ unlink(path_in) ; /* communicating with server processes */ @@ -150,9 +150,9 @@ extern void remake_world() { t->fov_map = t->lifepoints ? build_fov_map(t) : NULL; } - if (!world.replay && !access(s[PATH_RECORD], F_OK)) + if (!world.replay && !access(s[S_PATH_RECORD], F_OK)) { - exit_trouble(unlink(s[PATH_RECORD]), f_name, "unlink()"); + exit_trouble(unlink(s[S_PATH_RECORD]), f_name, "unlink()"); } world.turn = 1; } @@ -167,7 +167,7 @@ extern void run_game() replay_game(); return; } - char * path_savefile = s[PATH_SAVE]; + char * path_savefile = s[S_PATH_SAVE]; if (!access(path_savefile, F_OK)) { FILE * file = try_fopen(path_savefile, "r", f_name); @@ -185,7 +185,7 @@ extern void run_game() } else { - char * command = s[CMD_MAKE_WORLD]; + char * command = s[S_CMD_MAKE_WORLD]; char * msg = try_malloc(strlen(command) + 1 + 11 + 1, f_name); int test = sprintf(msg, "%s %d", command, (int) time(NULL)); exit_trouble(test < 0, f_name, "sprintf()"); diff --git a/src/server/io.c b/src/server/io.c index 258ec45..e4a40d0 100644 --- a/src/server/io.c +++ b/src/server/io.c @@ -88,17 +88,17 @@ static void write_thing(FILE * file, struct Thing * t) { write_thing(file, o); } - write_key_value(file, s[CMD_THING], t->id); - write_key_value(file, s[CMD_TYPE], t->type); - write_key_value(file, s[CMD_POS_Y], t->pos.y); - write_key_value(file, s[CMD_POS_X], t->pos.x); - write_key_value(file, s[CMD_COMMAND], t->command); - write_key_value(file, s[CMD_ARGUMENT], t->arg); - write_key_value(file, s[CMD_PROGRESS], t->progress); - write_key_value(file, s[CMD_LIFEPOINTS], t->lifepoints); + write_key_value(file, s[S_CMD_THING], t->id); + write_key_value(file, s[S_CMD_TYPE], t->type); + write_key_value(file, s[S_CMD_POS_Y], t->pos.y); + write_key_value(file, s[S_CMD_POS_X], t->pos.x); + write_key_value(file, s[S_CMD_COMMAND], t->command); + write_key_value(file, s[S_CMD_ARGUMENT], t->arg); + write_key_value(file, s[S_CMD_PROGRESS], t->progress); + write_key_value(file, s[S_CMD_LIFEPOINTS], t->lifepoints); for (o = t->owns; o; o = o->next) { - write_key_value(file, s[CMD_CARRIES], o->id); + write_key_value(file, s[S_CMD_CARRIES], o->id); } try_fputc('\n', file, f_name); } @@ -180,9 +180,9 @@ static void read_file_into_queue() static void update_worldstate_file() { char * f_name = "update_worldstate_file()"; - uint16_t size = strlen(s[PATH_WORLDSTATE]) + strlen(s[PATH_SUFFIX_TMP]) + 1; + uint16_t size = strlen(s[S_PATH_WORLDSTATE])+strlen(s[S_PATH_SUFFIX_TMP])+1; char * path_tmp = try_malloc(size, f_name); - int test = sprintf(path_tmp, "%s%s", s[PATH_WORLDSTATE],s[PATH_SUFFIX_TMP]); + int test=sprintf(path_tmp,"%s%s",s[S_PATH_WORLDSTATE],s[S_PATH_SUFFIX_TMP]); exit_trouble(test < 0, f_name, "sprintf()"); FILE * file = try_fopen(path_tmp, "w", f_name); struct Thing * player = get_player(); @@ -197,7 +197,7 @@ static void update_worldstate_file() { try_fwrite(world.log, strlen(world.log), 1, file, f_name); } - try_fclose_unlink_rename(file, path_tmp, s[PATH_WORLDSTATE], f_name); + try_fclose_unlink_rename(file, path_tmp, s[S_PATH_WORLDSTATE], f_name); free(path_tmp); set_cleanup_flag(CLEANUP_WORLDSTATE); char * dot = ".\n";; @@ -331,19 +331,19 @@ extern char * io_round() extern void save_world() { char * f_name = "save_world()"; - char * path = s[PATH_SAVE]; + char * path = s[S_PATH_SAVE]; FILE * file = try_fopen(path, "w", f_name); - write_key_value(file, s[CMD_DO_FOV], 0); + write_key_value(file, s[S_CMD_DO_FOV], 0); try_fputc('\n', file, f_name); - write_key_value(file, s[CMD_SEED_MAP], world.seed_map); - write_key_value(file, s[CMD_SEED_RAND], world.seed); - write_key_value(file, s[CMD_TURN], world.turn); + write_key_value(file, s[S_CMD_SEED_MAP], world.seed_map); + write_key_value(file, s[S_CMD_SEED_RAND], world.seed); + write_key_value(file, s[S_CMD_TURN], world.turn); try_fputc('\n', file, f_name); struct Thing * t; for (t = world.things; t; t = t->next) { write_thing(file, t); } - write_key_value(file, s[CMD_DO_FOV], 1); + write_key_value(file, s[S_CMD_DO_FOV], 1); try_fclose(file, f_name); } diff --git a/src/server/run.c b/src/server/run.c index 2b56a9d..d081ae3 100644 --- a/src/server/run.c +++ b/src/server/run.c @@ -78,7 +78,7 @@ static uint8_t do_fov = 0; static uint8_t parse_carry(char * tok0, char * tok1, struct Thing * t) { uint8_t id; - if (parse_val(tok0, tok1, s[CMD_CARRIES], '8', (char *) &id)) + if (parse_val(tok0, tok1, s[S_CMD_CARRIES], '8', (char *) &id)) { if (!err_line(id == t->id, "Thing cannot carry itself.")) { @@ -99,11 +99,11 @@ static uint8_t parse_carry(char * tok0, char * tok1, struct Thing * t) static uint8_t parse_position(char* tok0, char * tok1, struct Thing * t) { char axis = 0; - if (!strcmp(tok0, s[CMD_POS_Y])) + if (!strcmp(tok0, s[S_CMD_POS_Y])) { axis = 'y'; } - else if (!strcmp(tok0, s[CMD_POS_X])) + else if (!strcmp(tok0, s[S_CMD_POS_X])) { axis = 'x'; } @@ -134,7 +134,7 @@ static uint8_t parse_position(char* tok0, char * tok1, struct Thing * t) static uint8_t parse_thing_type(char * tok0, char * tok1, struct Thing * t) { uint8_t type; - if (parse_val(tok0, tok1, s[CMD_TYPE], '8', (char *) &type)) + if (parse_val(tok0, tok1, s[S_CMD_TYPE], '8', (char *) &type)) { struct ThingType * tt = world.thing_types; for (; NULL != tt && type != tt->id; tt = tt->next); @@ -152,7 +152,7 @@ static uint8_t parse_thing_type(char * tok0, char * tok1, struct Thing * t) static uint8_t parse_thing_command(char * tok0, char * tok1, struct Thing * t) { uint8_t command; - if (parse_val(tok0, tok1, s[CMD_COMMAND], '8', (char *) &command)) + if (parse_val(tok0, tok1, s[S_CMD_COMMAND], '8', (char *) &command)) { if (!command) { @@ -174,7 +174,7 @@ static uint8_t parse_thing_command(char * tok0, char * tok1, struct Thing * t) static uint8_t parse_do_fov(char * tok0, char * tok1) { - if (parse_val(tok0, tok1, s[CMD_DO_FOV], '8', (char *) &do_fov)) + if (parse_val(tok0, tok1, s[S_CMD_DO_FOV], '8', (char *) &do_fov)) { if (do_fov) { @@ -197,13 +197,13 @@ static uint8_t parse_thing_manipulation(char * tok0, char * tok1) static struct Thing * t = NULL; if (t && ( parse_thing_type(tok0, tok1, t) || parse_thing_command(tok0, tok1, t) - || parse_val(tok0, tok1, s[CMD_ARGUMENT], '8', (char *)&t->arg) - || parse_val(tok0, tok1, s[CMD_PROGRESS],'8',(char *)&t->progress) - || parse_val(tok0, tok1, s[CMD_LIFEPOINTS],'8', + || parse_val(tok0, tok1, s[S_CMD_ARGUMENT], '8', (char *)&t->arg) + || parse_val(tok0,tok1,s[S_CMD_PROGRESS],'8',(char *)&t->progress) + || parse_val(tok0, tok1, s[S_CMD_LIFEPOINTS], '8', (char *) &t->lifepoints) || parse_position(tok0, tok1, t) || parse_carry(tok0, tok1, t))); - else if (parse_val(tok0, tok1, s[CMD_THING], '8', (char *) &id)) + else if (parse_val(tok0, tok1, s[S_CMD_THING], '8', (char *) &id)) { t = get_thing(world.things, id, 1); if (!t) @@ -225,11 +225,11 @@ static uint8_t parse_thing_manipulation(char * tok0, char * tok1) static uint8_t parse_player_command(char * tok0, char * tok1) { struct Thing * player = get_player(); - if ( parse_val(tok0, tok1, s[CMD_WAIT], '8', (char *) &player->arg) - || parse_val(tok0, tok1, s[CMD_MOVE], '8', (char *) &player->arg) - || parse_val(tok0, tok1, s[CMD_PICKUP], '8', (char *) &player->arg) - || parse_val(tok0, tok1, s[CMD_DROP], '8', (char *) &player->arg) - || parse_val(tok0, tok1, s[CMD_USE], '8', (char *) &player->arg)) + if ( parse_val(tok0, tok1, s[S_CMD_WAIT], '8', (char *) &player->arg) + || parse_val(tok0, tok1, s[S_CMD_MOVE], '8', (char *) &player->arg) + || parse_val(tok0, tok1, s[S_CMD_PICKUP], '8', (char *) &player->arg) + || parse_val(tok0, tok1, s[S_CMD_DROP], '8', (char *) &player->arg) + || parse_val(tok0, tok1, s[S_CMD_USE], '8', (char *) &player->arg)) { player->command = get_thing_action_id_by_name(tok0); turn_over(); @@ -247,7 +247,7 @@ static void server_test() { char * f_name = "server_test()"; char test[10 + 1 + 10 + 1 + 1]; - FILE * file = try_fopen(s[PATH_OUT], "r", f_name); + FILE * file = try_fopen(s[S_PATH_OUT], "r", f_name); try_fgets(test, 10 + 10 + 1 + 1, file, f_name); try_fclose(file, f_name); if (strcmp(test, world.server_test)) @@ -309,14 +309,14 @@ static void turn_over() static void record_msg(char * msg) { char * f_name = "record_msg()"; - uint16_t size = strlen(s[PATH_RECORD]) + strlen(s[PATH_SUFFIX_TMP]) + 1; + uint16_t size = strlen(s[S_PATH_RECORD]) + strlen(s[S_PATH_SUFFIX_TMP]) + 1; char * path_tmp = try_malloc(size, f_name); - int test = sprintf(path_tmp, "%s%s", s[PATH_RECORD], s[PATH_SUFFIX_TMP]); + int test = sprintf(path_tmp, "%s%s", s[S_PATH_RECORD],s[S_PATH_SUFFIX_TMP]); exit_trouble(test < 0, f_name, "sprintf()"); FILE * file_tmp = try_fopen(path_tmp, "w", f_name); - if (!access(s[PATH_RECORD], F_OK)) + if (!access(s[S_PATH_RECORD], F_OK)) { - FILE * file_read = try_fopen(s[PATH_RECORD], "r", f_name); + FILE * file_read = try_fopen(s[S_PATH_RECORD], "r", f_name); uint32_t linemax = textfile_width(file_read); char * line = try_malloc(linemax + 1, f_name); while (try_fgets(line, linemax + 1, file_read, f_name)) @@ -328,7 +328,7 @@ static void record_msg(char * msg) } try_fwrite(msg, strlen(msg), 1, file_tmp, f_name); try_fputc('\n', file_tmp, f_name); - try_fclose_unlink_rename(file_tmp, path_tmp, s[PATH_RECORD], f_name); + try_fclose_unlink_rename(file_tmp, path_tmp, s[S_PATH_RECORD], f_name); free(path_tmp); } @@ -347,15 +347,15 @@ extern void obey_msg(char * msg, uint8_t do_record) } if ( parse_thing_manipulation(tok0, tok1) || parse_player_command(tok0, tok1) - || parse_val(tok0, tok1, s[CMD_SEED_RAND], 'U', (char *) &world.seed) - || parse_val(tok0, tok1, s[CMD_TURN], 'u', (char *) &world.turn) + || parse_val(tok0, tok1, s[S_CMD_SEED_RAND], 'U', (char *) &world.seed) + || parse_val(tok0, tok1, s[S_CMD_TURN], 'u', (char *) &world.turn) || parse_do_fov(tok0, tok1)); - else if (parse_val(tok0, tok1, s[CMD_SEED_MAP],'U',(char *)&world.seed_map)) + else if (parse_val(tok0,tok1,s[S_CMD_SEED_MAP],'U',(char *)&world.seed_map)) { remake_map(); } - else if (parse_val(tok0, tok1, s[CMD_MAKE_WORLD],'U', (char *) &world.seed)) + else if (parse_val(tok0, tok1, s[S_CMD_MAKE_WORLD],'U',(char *)&world.seed)) { remake_world(); }