home
·
contact
·
privacy
projects
/
plomrogue
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
47139e3
)
Server: Merge duplicate string literals of "sprintf()".
author
Christian Heller
<c.heller@plomlompom.de>
Wed, 9 Jul 2014 21:14:37 +0000
(23:14 +0200)
committer
Christian Heller
<c.heller@plomlompom.de>
Wed, 9 Jul 2014 21:14:37 +0000
(23:14 +0200)
src/server/hardcoded_strings.c
patch
|
blob
|
history
src/server/hardcoded_strings.h
patch
|
blob
|
history
src/server/init.c
patch
|
blob
|
history
src/server/io.c
patch
|
blob
|
history
src/server/run.c
patch
|
blob
|
history
src/server/thing_actions.c
patch
|
blob
|
history
src/server/things.c
patch
|
blob
|
history
diff --git
a/src/server/hardcoded_strings.c
b/src/server/hardcoded_strings.c
index 8ce7475a725ef5d0cea7209342764154a2c29c9c..652527ae4d2a49363cbc63f65b2f088564d4c83d 100644
(file)
--- a/
src/server/hardcoded_strings.c
+++ b/
src/server/hardcoded_strings.c
@@
-4,7
+4,7
@@
-char * s[2
6
];
+char * s[2
7
];
@@
-36,4
+36,5
@@
extern void init_strings()
s[S_CMD_PICKUP] = "pick_up";
s[S_CMD_DROP] = "drop";
s[S_CMD_USE] = "use";
s[S_CMD_PICKUP] = "pick_up";
s[S_CMD_DROP] = "drop";
s[S_CMD_USE] = "use";
+ s[S_FCN_SPRINTF] = "sprintf()";
}
}
diff --git
a/src/server/hardcoded_strings.h
b/src/server/hardcoded_strings.h
index e017d7c33c7be5afd510b366681fcf9c295731fb..a14e85ff38f69a42377985d9bd70483c0ee6fc81 100644
(file)
--- a/
src/server/hardcoded_strings.h
+++ b/
src/server/hardcoded_strings.h
@@
-35,12
+35,13
@@
enum string_num
S_CMD_MOVE,
S_CMD_PICKUP,
S_CMD_DROP,
S_CMD_MOVE,
S_CMD_PICKUP,
S_CMD_DROP,
- S_CMD_USE
+ S_CMD_USE,
+ S_FCN_SPRINTF
};
extern void init_strings();
};
extern void init_strings();
-extern char * s[2
6
];
+extern char * s[2
7
];
diff --git
a/src/server/init.c
b/src/server/init.c
index 766d92e26bd5f56064fcede85824c5c08b262e3e..ea13bc105afd39ef1ff9dc08b4ca0db77d58ee8b 100644
(file)
--- a/
src/server/init.c
+++ b/
src/server/init.c
@@
-101,7
+101,7
@@
extern void setup_server_io()
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));
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()"
);
+ exit_trouble(test < 0, f_name,
s[S_FCN_SPRINTF]
);
try_fwrite(world.server_test, strlen(world.server_test), 1,
world.file_out, f_name);
fflush(world.file_out);
try_fwrite(world.server_test, strlen(world.server_test), 1,
world.file_out, f_name);
fflush(world.file_out);
@@
-188,7
+188,7
@@
extern void run_game()
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));
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()"
);
+ exit_trouble(test < 0, f_name,
s[S_FCN_SPRINTF]
);
obey_msg(msg, 1);
free(msg);
}
obey_msg(msg, 1);
free(msg);
}
diff --git
a/src/server/io.c
b/src/server/io.c
index e4a40d0ccc13685d076080a82d467bbd8c920d99..c703f0e68929a9c879c84bb8ced011875f27874d 100644
(file)
--- a/
src/server/io.c
+++ b/
src/server/io.c
@@
-72,7
+72,7
@@
static void write_key_value(FILE * file, char * key, uint32_t value)
try_fwrite(key, strlen(key), 1, file, f_name);
try_fputc(' ', file, f_name);
char * line = try_malloc(11, f_name);
try_fwrite(key, strlen(key), 1, file, f_name);
try_fputc(' ', file, f_name);
char * line = try_malloc(11, f_name);
- exit_trouble(-1 == sprintf(line, "%u", value), f_name,
"sprintf()"
);
+ exit_trouble(-1 == sprintf(line, "%u", value), f_name,
s[S_FCN_SPRINTF]
);
try_fwrite(line, strlen(line), 1, file, f_name);
free(line);
try_fputc('\n', file, f_name);
try_fwrite(line, strlen(line), 1, file, f_name);
free(line);
try_fputc('\n', file, f_name);
@@
-183,7
+183,7
@@
static void update_worldstate_file()
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[S_PATH_WORLDSTATE],s[S_PATH_SUFFIX_TMP]);
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[S_PATH_WORLDSTATE],s[S_PATH_SUFFIX_TMP]);
- exit_trouble(test < 0, f_name,
"sprintf()"
);
+ exit_trouble(test < 0, f_name,
s[S_FCN_SPRINTF]
);
FILE * file = try_fopen(path_tmp, "w", f_name);
struct Thing * player = get_player();
write_value_as_line(world.turn, file);
FILE * file = try_fopen(path_tmp, "w", f_name);
struct Thing * player = get_player();
write_value_as_line(world.turn, file);
@@
-211,7
+211,7
@@
static void write_value_as_line(uint32_t value, FILE * file)
{
char * f_name = "write_value_as_line()";
char write_buf[12]; /* Holds 10 digits of uint32_t maximum + \n + \0. */
{
char * f_name = "write_value_as_line()";
char write_buf[12]; /* Holds 10 digits of uint32_t maximum + \n + \0. */
- exit_trouble(sprintf(write_buf, "%u\n",
value) < 0, f_name, "sprintf()"
);
+ exit_trouble(sprintf(write_buf, "%u\n",
value) < 0, f_name,s[S_FCN_SPRINTF]
);
try_fwrite(write_buf, strlen(write_buf), 1, file, f_name);
}
try_fwrite(write_buf, strlen(write_buf), 1, file, f_name);
}
diff --git
a/src/server/run.c
b/src/server/run.c
index d081ae3473a12f6a97becf64616865cfc3f75392..452c10b19a9f8c15d80fa1afe9676735483835a0 100644
(file)
--- a/
src/server/run.c
+++ b/
src/server/run.c
@@
-312,7
+312,7
@@
static void record_msg(char * msg)
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[S_PATH_RECORD],s[S_PATH_SUFFIX_TMP]);
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[S_PATH_RECORD],s[S_PATH_SUFFIX_TMP]);
- exit_trouble(test < 0, f_name,
"sprintf()"
);
+ exit_trouble(test < 0, f_name,
s[S_FCN_SPRINTF]
);
FILE * file_tmp = try_fopen(path_tmp, "w", f_name);
if (!access(s[S_PATH_RECORD], F_OK))
{
FILE * file_tmp = try_fopen(path_tmp, "w", f_name);
if (!access(s[S_PATH_RECORD], F_OK))
{
diff --git
a/src/server/thing_actions.c
b/src/server/thing_actions.c
index c1e337b6842ab067ee2ef4e2d54d83023708131d..b153ff868ef749fc92497e955a75cc849c725674 100644
(file)
--- a/
src/server/thing_actions.c
+++ b/
src/server/thing_actions.c
@@
-10,6
+10,7
@@
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* struct yx_uint8 */
#include "field_of_view.h" /* build_fov_map() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* struct yx_uint8 */
#include "field_of_view.h" /* build_fov_map() */
+#include "hardcoded_strings.h" /* s */
#include "things.h" /* structs Thing, ThingType, get_player(), own_thing(),
* set_thing_position(), get_thing_type()
*/
#include "things.h" /* structs Thing, ThingType, get_player(), own_thing(),
* set_thing_position(), get_thing_type()
*/
@@
-105,7
+106,7
@@
static void update_log(char * text)
char * new_text = try_malloc(len_whole, f_name);
memcpy(new_text, world.log + offset, len_old);
int test = sprintf(new_text + len_old, "%s", text);
char * new_text = try_malloc(len_whole, f_name);
memcpy(new_text, world.log + offset, len_old);
int test = sprintf(new_text + len_old, "%s", text);
- exit_trouble(test < 0, f_name,
"sprintf()"
);
+ exit_trouble(test < 0, f_name,
s[S_FCN_SPRINTF]
);
free(world.log);
world.log = new_text;
}
free(world.log);
world.log = new_text;
}
@@
-133,7
+134,7
@@
static void actor_hits_actor(struct Thing * hitter, struct Thing * hitted)
uint8_t len = 1 + strlen(msg1) + 1 + strlen(msg2) + 1 + strlen(msg3) + 2;
char * msg = try_malloc(len, f_name);
int test = sprintf(msg, "\n%s %s %s.", msg1, msg2, msg3);
uint8_t len = 1 + strlen(msg1) + 1 + strlen(msg2) + 1 + strlen(msg3) + 2;
char * msg = try_malloc(len, f_name);
int test = sprintf(msg, "\n%s %s %s.", msg1, msg2, msg3);
- exit_trouble(test < 0, f_name,
"sprintf()"
);
+ exit_trouble(test < 0, f_name,
s[S_FCN_SPRINTF]
);
update_log(msg);
free(msg);
hitted->lifepoints--;
update_log(msg);
free(msg);
hitted->lifepoints--;
@@
-189,7
+190,7
@@
static void playerbonus_move(char d, uint8_t passable)
}
char * msg = try_malloc(strlen(dsc_move) + strlen (dsc_dir) + 3, f_name);
int test = sprintf(msg, "\n%s%s.", dsc_move, dsc_dir);
}
char * msg = try_malloc(strlen(dsc_move) + strlen (dsc_dir) + 3, f_name);
int test = sprintf(msg, "\n%s%s.", dsc_move, dsc_dir);
- exit_trouble(test < 0, f_name,
"sprintf()"
);
+ exit_trouble(test < 0, f_name,
s[S_FCN_SPRINTF]
);
update_log(msg);
free(msg);
}
update_log(msg);
free(msg);
}
diff --git
a/src/server/things.c
b/src/server/things.c
index eabded27bf98a554330ff84aab1abd34f384fccc..9425f9cc3c315c5362733f93d13d9dbc984ce7a5 100644
(file)
--- a/
src/server/things.c
+++ b/
src/server/things.c
@@
-8,6
+8,7
@@
#include "../common/rexit.h" /* exit_err(), exit_trouble() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* yx_uint8 */
#include "../common/rexit.h" /* exit_err(), exit_trouble() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* yx_uint8 */
+#include "hardcoded_strings.h" /* s */
#include "map.h" /* is_passable() */
#include "rrand.h" /* rrand() */
#include "world.h" /* global world */
#include "map.h" /* is_passable() */
#include "rrand.h" /* rrand() */
#include "world.h" /* global world */
@@
-192,7
+193,7
@@
extern struct ThingType * get_thing_type(uint8_t id)
char * err_intro = "Requested thing type of unused ID ";
uint16_t size = strlen(err_intro) + 3 + 1 + 1;
char * err = try_malloc(size, f_name);
char * err_intro = "Requested thing type of unused ID ";
uint16_t size = strlen(err_intro) + 3 + 1 + 1;
char * err = try_malloc(size, f_name);
- exit_trouble(sprintf(err,
"%s%d.", err_intro, id) < 0, f_name, "sprintf()"
);
+ exit_trouble(sprintf(err,
"%s%d.",err_intro,id) < 0,f_name,s[S_FCN_SPRINTF]
);
exit_err(NULL == tt, err);
free(err);
return tt;
exit_err(NULL == tt, err);
free(err);
return tt;