- expand use of hardcoded_strings module(s)
-- use __func__ instead of f_name
-
BOTH SERVER/CLIENT:
- make server and client communicate by specific world state info requests
extern void array_append(uint32_t old_n, size_t region_size, void * new_region,
void ** ptr_old_array)
{
- char * f_name = "array_append()";
uint32_t old_size = old_n * region_size;
uint32_t new_size = old_size + region_size;
- char * new_array = try_malloc(new_size, f_name);
+ char * new_array = try_malloc(new_size, __func__);
memcpy(new_array, * ptr_old_array, old_size);
memcpy(new_array + (old_n * region_size), new_region, region_size);
free(* ptr_old_array);
extern void cleanup()
{
- char * f_name = "cleanup()";
free(world.map.cells);
free(world.log);
free(world.player_inventory);
}
if (cleanup_flags & CLEANUP_SERVER_IN)
{
- try_fclose(world.file_server_in, f_name);
+ try_fclose(world.file_server_in, __func__);
}
if (cleanup_flags & CLEANUP_SERVER_OUT)
{
- try_fclose(world.file_server_out, f_name);
+ try_fclose(world.file_server_out, __func__);
}
}
static char * build_server_message_with_argument(struct Command * cmd)
{
- char * f_name = "build_server_message_with_argument()";
uint8_t command_size = strlen(cmd->server_msg);
char * arg_str = "";
uint8_t arg_size = 0;
if ('i' == cmd->arg)
{
arg_size = 3;
- arg_str = try_malloc(arg_size + 1, f_name);
+ arg_str = try_malloc(arg_size + 1, __func__);
int test = sprintf(arg_str, "%d",world.player_inventory_select);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
}
else if ( set_string_if_char_match(cmd->arg, 'd', &arg_str, "east")
|| set_string_if_char_match(cmd->arg, 'c', &arg_str, "south-east")
{
exit_err(1, "Illegal server command argument.");
}
- char * msg = try_malloc(command_size + 1 + arg_size + 1, f_name);
+ char * msg = try_malloc(command_size + 1 + arg_size + 1, __func__);
int test = sprintf(msg, "%s %s", cmd->server_msg, arg_str);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
if ('i' == cmd->arg)
{
free(arg_str);
static void try_resize_winmap(struct Win * win, int new_size_y, int new_size_x)
{
- char * f_name = "try_resize_winmap()";
if (win->winmap_size.y >= new_size_y && win->winmap_size.x >= new_size_x)
{
return;
}
chtype * old_winmap = win->winmap;
uint32_t new_size = sizeof(chtype) * new_size_y * new_size_x;
- win->winmap = try_malloc(new_size, f_name);
+ win->winmap = try_malloc(new_size, __func__);
uint16_t y, x;
for (y = 0; y < new_size_y; y++)
{
static void add_line_compact(struct Win * win, char * line, attr_t attri,
uint16_t * offset, uint8_t last)
{
- char * f_name = "add_line_compact()";
uint16_t y_start = win->winmap_size.y - (win->winmap_size.y > 0);
try_resize_winmap(win, y_start + 1, win->frame_size.x);
uint16_t len_line = strlen(line);
char * separator = last ? "" : " / ";
uint32_t len_line_new = len_line + strlen(separator);
- char * line_new = try_malloc(len_line_new, f_name);
+ char * line_new = try_malloc(len_line_new, __func__);
int test = sprintf(line_new, "%s%s", line, separator);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
uint16_t x = 0;
uint16_t y;
uint32_t z;
static char * get_kb_line(struct KeyBinding * kb)
{
- char * f_name = "get_kb_line()";
char * keyname = get_keyname_to_keycode(kb->keycode);
uint16_t size = strlen(keyname) + 3 + strlen(kb->command->dsc_long) + 1;
- char * kb_line = try_malloc(size, f_name);
+ char * kb_line = try_malloc(size, __func__);
int test = sprintf(kb_line, "%s - %s", keyname, kb->command->dsc_long);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
free(keyname);
return kb_line;
}
extern void draw_win_info(struct Win * win)
{
- char * f_name = "draw_win_info()";
char * dsc_turn = "Turn: ";
char * dsc_hitpoints = "\nHitpoints: ";
uint16_t maxl = strlen(dsc_turn) + 5 + strlen(dsc_hitpoints) + 3;
- char * text = try_malloc(maxl + 1, f_name);
+ char * text = try_malloc(maxl + 1, __func__);
int test = sprintf(text, "%s%d%s%d", dsc_turn, world.turn, dsc_hitpoints,
world.player_lifepoints);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
add_text_with_linebreaks(win, text);
free(text);
}
extern void draw_winconf_geometry(struct Win * win)
{
- char * f_name = "draw_winconf_geometry()";
char * title = "Window's geometry:\n\n";
char * h_title = "Height to save: ";
char h_value[6 + 1]; /* 6: int16_t value max strlen */
int test = sprintf(h_value, "%d", win->target_height);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
char * h_plus = " (width in cells)\n\n";
char * h_minus = " (negative diff: cells to screen width)\n\n";
char * h_type = (1 == win->target_height_type) ? h_minus : h_plus;
char * w_title = "Width to save: ";
char w_value[6 + 1];
test = sprintf(w_value, "%d", win->target_width);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
char * w_plus = "(height in cells)\n\n";
char * w_minus = " (negative diff: cells to screen height)\n\n";
char * w_type = (1 == win->target_width_type) ? w_minus : w_plus;
+ strlen(h_title) + strlen(h_value) + strlen(h_type)
+ strlen(w_title) + strlen(w_value) + strlen(w_type)
+ strlen(breaks_title) + strlen(breaks_type);
- char * text = try_malloc(text_size + 1, f_name);
+ char * text = try_malloc(text_size + 1, __func__);
test = sprintf(text, "%s%s%s%s%s%s%s%s%s", title, h_title, h_value, h_type,
w_title, w_value, w_type, breaks_title, breaks_type);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
add_text_with_linebreaks(win, text);
free(text);
}
static void write_keybindings(FILE * file, struct KeyBindingDB * kbdb)
{
- char * f_name = "write_keybindings()";
char * sep = " ";
char * tok0 = "KEY";
uint8_t i_kb;
{
size_t size = strlen(tok0) + strlen(sep) + 3 + strlen(sep)
+ strlen(kbdb->kbs[i_kb].command->dsc_short) + 1 + 1;
- char * line = try_malloc(size, f_name);
+ char * line = try_malloc(size, __func__);
int test = snprintf(line, size, "%s%s%d%s%s\n",
tok0, sep, kbdb->kbs[i_kb].keycode, sep,
kbdb->kbs[i_kb].command->dsc_short);
- exit_trouble(test < 0, f_name, "snprintf()");
- try_fwrite(line, sizeof(char), strlen(line), file, f_name);
+ exit_trouble(test < 0, __func__, "snprintf");
+ try_fwrite(line, sizeof(char), strlen(line), file, __func__);
free(line);
}
}
static void write_def(FILE * file, char * prefix, uint8_t quotes, char * val,
char type)
{
- char * f_name = "write_def()";
char * val_str = NULL;
int test_val_str = 1;
if ('s' == type)
if ('i' == type)
{
size_t size_val_str = 6 + 1;
- val_str = try_malloc(size_val_str, f_name);
+ val_str = try_malloc(size_val_str, __func__);
test_val_str = snprintf(val_str, size_val_str, "%d", (int16_t) *val);
}
else if ('c' == type)
{
size_t size_val_str = 1 + 1;
- val_str = try_malloc(size_val_str, f_name);
+ val_str = try_malloc(size_val_str, __func__);
test_val_str = snprintf(val_str, size_val_str, "%c", * val);
}
- exit_trouble(test_val_str < 0, f_name, "snprintf()");
+ exit_trouble(test_val_str < 0, __func__, "snprintf");
char * quote = quotes ? "'": "";
char * affix = "\n";
size_t size = strlen(prefix) + strlen(val_str) + (2 * strlen(quote))
+ strlen(affix) + 1;
- char * line = try_malloc(size, f_name);
+ char * line = try_malloc(size, __func__);
int test = snprintf(line, size, "%s%s%s%s%s",
prefix, quote, val_str, quote, affix);
- exit_trouble(test < 0, f_name, "snprintf()");
+ exit_trouble(test < 0, __func__, "snprintf");
free(val_str);
- try_fwrite(line, sizeof(char), strlen(line), file, f_name);
+ try_fwrite(line, sizeof(char), strlen(line), file, __func__);
free(line);
}
static void write_if_win(struct Win ** win)
{
- char * f_name = "write_if_win()";
if (*win)
{
(*win)->target_height_type = (0 >= (*win)->target_height);
(*win)->target_width_type = (0 >= (*win)->target_width);;
size_t old_ids_size = strlen(world.winDB.ids);
size_t new_size = old_ids_size + 1 + 1;
- char * new_ids = try_malloc(new_size, f_name);
+ char * new_ids = try_malloc(new_size, __func__);
int test = snprintf(new_ids,new_size,"%s%c",world.winDB.ids,(*win)->id);
- exit_trouble(test < 0, f_name, "snprintf()");
+ exit_trouble(test < 0, __func__, "snprintf");
free(world.winDB.ids);
world.winDB.ids = new_ids;
array_append(old_ids_size, sizeof(struct Win), *win,
extern void load_interface_conf()
{
- char * f_name = "load_interface_conf()";
- world.winDB.ids = try_malloc(1, f_name);
+ world.winDB.ids = try_malloc(1, __func__);
world.winDB.ids[0] = '\0';
world.winDB.wins = NULL;
- tmp_order = try_malloc(1, f_name);
+ tmp_order = try_malloc(1, __func__);
tmp_order[0] = '\0';
tmp_active = '\0';
detect_atomic_leftover(world.path_interface);
char * err = "Not all expected windows defined in config file.";
exit_err(strlen(world.winDB.legal_ids) != strlen(world.winDB.ids), err);
make_v_screen_and_init_win_sizes();
- world.winDB.order = try_malloc(1, f_name);
+ world.winDB.order = try_malloc(1, __func__);
world.winDB.order[0] = '\0';
uint8_t i;
for (i = 0; i < strlen(tmp_order); toggle_window(tmp_order[i]), i++);
static void read_inventory(char * read_buf, uint32_t linemax, FILE * file)
{
- char * f_name = "read_inventory()";
char * delimiter = "%\n";
free(world.player_inventory);
world.player_inventory = NULL; /* Avoids illegal strlen() below. */
while (1)
{
- try_fgets(read_buf, linemax + 1, file, f_name);
+ try_fgets(read_buf, linemax + 1, file, __func__);
if (!(strcmp(read_buf, delimiter)))
{
break;
old_size = strlen(world.player_inventory);
}
int new_size = strlen(read_buf);
- char * new_inventory = try_malloc(old_size + new_size + 1, f_name);
+ char * new_inventory = try_malloc(old_size + new_size + 1, __func__);
memcpy(new_inventory, world.player_inventory, old_size);
int test = sprintf(new_inventory + old_size, "%s", read_buf);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
free(world.player_inventory);
world.player_inventory = new_inventory;
}
static void read_map_cells(FILE * file)
{
- char * f_name = "read_map_cells()";
free(world.map.cells);
- world.map.cells = try_malloc(world.map.length * world.map.length, f_name);
+ world.map.cells = try_malloc(world.map.length * world.map.length, __func__);
uint16_t y, x;
for (y = 0; y < world.map.length; y++)
{
for (x = 0; x < world.map.length; x++)
{
- char c = try_fgetc(file, f_name);
+ char c = try_fgetc(file, __func__);
world.map.cells[(y * world.map.length) + x] = c;
}
- try_fgetc(file, f_name);
+ try_fgetc(file, __func__);
}
}
static void read_log(char * read_buf, uint32_t linemax, FILE * file)
{
- char * f_name = "read_log()";
free(world.log);
world.log = NULL;
- while (try_fgets(read_buf, linemax + 1, file, f_name))
+ while (try_fgets(read_buf, linemax + 1, file, __func__))
{
int old_size = 0;
if (NULL != world.log)
old_size = strlen(world.log);
}
int new_size = strlen(read_buf);
- char * new_log = try_malloc(old_size + new_size + 1, f_name);
+ char * new_log = try_malloc(old_size + new_size + 1, __func__);
memcpy(new_log, world.log, old_size);
int test = sprintf(new_log + old_size, "%s", read_buf);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
free(world.log);
world.log = new_log;
}
static uint16_t read_value_from_line(char * read_buf, uint32_t linemax,
FILE * file)
{
- char * f_name = "read_value_from_line()";
- try_fgets(read_buf, linemax + 1, file, f_name);
+ try_fgets(read_buf, linemax + 1, file, __func__);
return atoi(read_buf);
}
static FILE * changed_worldstate_file(char * path)
{
- char * f_name = "changed_worldstate_file()";
struct stat stat_buf;
- exit_trouble(stat(path, &stat_buf), f_name, "stat()");
+ exit_trouble(stat(path, &stat_buf), __func__, "stat");
if (stat_buf.st_mtime != world.last_update)
{
world.last_update = stat_buf.st_mtime;
- return try_fopen(path, "r", f_name);
+ return try_fopen(path, "r", __func__);
}
- FILE * file = try_fopen(path, "r", f_name);
+ FILE * file = try_fopen(path, "r", __func__);
char turn_string[6];
- try_fgets(turn_string, 6, file, f_name);
+ try_fgets(turn_string, 6, file, __func__);
if (world.turn == atoi(turn_string))
{
- try_fclose(file, f_name);
+ try_fclose(file, __func__);
return NULL;
}
- exit_trouble(fseek(file, 0, SEEK_SET), f_name, "fseek()");
+ exit_trouble(fseek(file, 0, SEEK_SET), __func__, "fseek");
return file;
}
static uint8_t read_world()
{
- char * f_name = "read_world()";
char * path = "server/worldstate";
char * quit_msg = "No worldstate file found to read. Server may be down.";
static uint8_t first_read = 1;
return 0;
}
uint32_t linemax = textfile_width(file);
- char * read_buf = try_malloc(linemax + 1, f_name);
+ char * read_buf = try_malloc(linemax + 1, __func__);
world.turn = read_value_from_line(read_buf, linemax, file);
world.player_lifepoints = read_value_from_line(read_buf, linemax, file);
read_inventory(read_buf, linemax, file);
read_map_cells(file);
read_log(read_buf, linemax, file);
free(read_buf);
- try_fclose(file, f_name);
+ try_fclose(file, __func__);
return 1;
}
static void test_server_activity(time_t * last_server_answer_time)
{
- char * f_name = "test_server_activity()";
- int test = try_fgetc(world.file_server_out, f_name);
+ int test = try_fgetc(world.file_server_out, __func__);
if (EOF == test)
{
return;
{
;
}
- while (EOF != (test = try_fgetc(world.file_server_out, f_name)));
+ while (EOF != (test = try_fgetc(world.file_server_out, __func__)));
* last_server_answer_time = time(0);
}
extern void send(char * msg)
{
- char * f_name = "send()";
uint32_t msg_size = strlen(msg) + 1;
char * err = "send() tries to send message larger than PIPE_BUF bytes.";
exit_err(msg_size > PIPE_BUF, err);
- try_fwrite(msg, strlen(msg), 1, world.file_server_in, f_name);
- try_fputc('\n', world.file_server_in, f_name);
+ try_fwrite(msg, strlen(msg), 1, world.file_server_in, __func__);
+ try_fputc('\n', world.file_server_in, __func__);
fflush(world.file_server_in);
}
static uint8_t try_keycode(uint16_t keycode_given, char * keyname,
uint16_t keycode_match, char * keyname_match)
{
- char * f_name = "try_keycode()";
if (keycode_given == keycode_match)
{
int test = sprintf(keyname, "%s", keyname_match);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
return 1;
}
return 0;
extern char * get_keyname_to_keycode(uint16_t keycode)
{
- char * f_name = "get_name_to_keycode()";
- char * keyname = try_malloc(10, f_name); /* max keyname length + 1 */
+ char * keyname = try_malloc(10, __func__); /* max keyname length + 1 */
if (32 < keycode && keycode < 127)
{
- exit_trouble(sprintf(keyname, "%c", keycode) < 0, f_name, "sprintf()");
+ exit_trouble(sprintf(keyname, "%c", keycode) < 0, __func__, "sprintf");
}
else if (keycode >= KEY_F0 && keycode <= KEY_F(63))
{
uint16_t f = keycode - KEY_F0;
- exit_trouble(sprintf(keyname, "F%d", f) < 0, f_name, "sprintf()");;
+ exit_trouble(sprintf(keyname, "F%d", f) < 0, __func__, "sprintf");;
}
else if ( try_keycode(keycode, keyname, 9, "TAB")
|| try_keycode(keycode, keyname, 10, "RETURN")
}
else
{
- exit_trouble(sprintf(keyname, "(unknown)") < 0, f_name, "sprintf()");
+ exit_trouble(sprintf(keyname, "(unknown)") < 0, __func__, "sprintf");
}
return keyname;
}
int main(int argc, char * argv[])
{
- char * f_name = "main()";
-
/* Declare hard-coded paths and values here. */
world.path_commands = "confclient/commands";
world.path_interface = "confclient/interface_conf";
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = &winch_called;
- exit_trouble(sigaction(SIGWINCH, &act, NULL), f_name, "sigaction()");
+ exit_trouble(sigaction(SIGWINCH, &act, NULL), __func__, "sigaction");
/* Open file streams for communicating with the server. */
exit_err(access(path_server_in, F_OK), "No server input file found.");
- world.file_server_in = try_fopen(path_server_in, "a", f_name);
+ world.file_server_in = try_fopen(path_server_in, "a", __func__);
set_cleanup_flag(CLEANUP_SERVER_IN);
- world.file_server_out = try_fopen(path_server_out, "r", f_name);
+ world.file_server_out = try_fopen(path_server_out, "r", __func__);
set_cleanup_flag(CLEANUP_SERVER_OUT);
/* This is where most everything happens. */
/* Leave properly. */
cleanup();
- exit_trouble(printf("%s\n", quit_msg) < 0, f_name, "printf()");
+ exit_trouble(printf("%s\n", quit_msg) < 0, __func__, "printf");
exit(EXIT_SUCCESS);
}
extern void parse_file(char * path, void (* token_to_entry) (char *, char *))
{
- char * f_name = "read_new_config_file()";
char * prefix = "Failed reading config file: \"";
char * affix = "\". ";
size_t size = strlen(prefix) + strlen(path) + strlen(affix) + 1;
- char * errline_intro = try_malloc(size, f_name);
+ char * errline_intro = try_malloc(size, __func__);
int test = snprintf(errline_intro, size, "%s%s%s", prefix, path, affix);
- exit_trouble(test < 0, f_name, "snprintf()");
+ exit_trouble(test < 0, __func__, "snprintf");
exit_err(access(path, F_OK), errline_intro);
- FILE * file = try_fopen(path, "r", f_name);
+ FILE * file = try_fopen(path, "r", __func__);
uint32_t linemax = textfile_width(file);
- char * errline_line = try_malloc(linemax + 1, f_name);
+ char * errline_line = try_malloc(linemax + 1, __func__);
set_err_line_options(errline_intro, errline_line, 1);
err_line_zero();
err_line(0 == linemax, "File is empty.");
char * token0 = NULL; /* For final token_to_entry() if while() stagnates. */
char * token1 = NULL;
char * err_val = "No value given.";
- while (try_fgets(errline_line, linemax + 1, file, f_name))
+ while (try_fgets(errline_line, linemax + 1, file, __func__))
{
err_line_inc();
char * line_copy = strdup(errline_line);
free(line_copy);
}
token_to_entry(token0, token1);
- try_fclose(file, f_name);
+ try_fclose(file, __func__);
free(errline_line);
free(errline_intro);
}
extern char * parse_init_entry(uint8_t * flags, size_t size)
{
- char * f_name = "parse_init_entry()";
*flags = EDIT_STARTED;
- char * p = try_malloc(size, f_name);
+ char * p = try_malloc(size, __func__);
memset(p, 0, size);
return p;
}
static void append_win(struct Win * w)
{
- char * f_name = "append_win()";
uint8_t old_size = strlen(world.winDB.order) + 1;
- char * new_order = try_malloc(old_size + 1, f_name);
+ char * new_order = try_malloc(old_size + 1, __func__);
memcpy(new_order, world.winDB.order, old_size - 1);
new_order[old_size - 1] = w->id;
new_order[old_size] = '\0';
static void suspend_win(struct Win * w)
{
- char * f_name = "suspend_win()";
uint8_t new_size = strlen(world.winDB.order);
- char * new_order = try_malloc(new_size, f_name);
+ char * new_order = try_malloc(new_size, __func__);
uint8_t i = get_win_pos_in_order(w->id);
char next_char = world.winDB.order[i + 1];
world.winDB.order[i] = '\0';
char * second_part = &world.winDB.order[i + 1];
int test = sprintf(new_order, "%s%s", world.winDB.order, second_part);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
free(world.winDB.order);
world.winDB.order = new_order;
world.winDB.active = world.winDB.order[i];
extern void shift_active_win(char dir)
{
- char * f_name = "shift_active_win()";
uint8_t len_order = strlen(world.winDB.order);
if (1 < len_order)
{
- char * tmp = try_malloc(len_order + 1, f_name);
+ char * tmp = try_malloc(len_order + 1, __func__);
tmp[len_order] = '\0';
uint8_t pos = get_win_pos_in_order(world.winDB.active);
if ('f' == dir)
static void scroll_hint(struct yx_uint16 fsize, char dir, uint16_t dist,
char * unit, struct yx_uint16 start)
{
- char * f_name = "sprintf()";
-
/* Decide on alignment (vertical/horizontal?), thereby hint text space. */
char * more = "more";
uint16_t dsc_space = fsize.x;
dsc_space = fsize.y;
} /* vv-- 10 = max strlen for uint16_t */
uint16_t size = 1 + strlen(more) + 1 + 10 + 1 + strlen(unit) + 1 + 1;
- char * scrolldsc = try_malloc(size, f_name);
+ char * scrolldsc = try_malloc(size, __func__);
int test = sprintf(scrolldsc, " %d %s %s ", dist, more, unit);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
/* Decide on offset of the description text inside the scroll hint line. */
uint16_t dsc_offset = 1;
offset = (w->frame_size.x - (strlen(w->title) + 2)) / 2;
} /* +2 is for padding/decoration */
uint16_t length_visible = strnlen(w->title, w->frame_size.x - 2);
- char * title = try_malloc(length_visible + 3, "draw_win_borderlines()");
+ char * title = try_malloc(length_visible + 3, "draw_win_borderlines");
char decoration = ' ';
if (w->id == world.winDB.active)
{
extern void make_v_screen_and_init_win_sizes()
{
- char * f_name = "make_v_screen_and_init_win_sizes()";
char * err_s = "creating an illegaly large virtual screen";
- char * err_m = "triggering a memory allocation error via newpad()";
+ char * err_m = "triggering a memory allocation error via newpad";
uint32_t maxy_test = getmaxy(world.winDB.t_screen);
uint32_t maxx_test = getmaxx(world.winDB.t_screen);
- exit_trouble(maxy_test>UINT16_MAX || maxx_test>UINT16_MAX, f_name, err_s);
+ exit_trouble(maxy_test>UINT16_MAX || maxx_test>UINT16_MAX, __func__, err_s);
world.winDB.v_screen_size.y = maxy_test;
world.winDB.v_screen_size.x = maxx_test;
world.winDB.v_screen = newpad(world.winDB.v_screen_size.y, 1);
- exit_trouble(NULL == world.winDB.v_screen, f_name, err_m);
+ exit_trouble(NULL == world.winDB.v_screen, __func__, err_m);
char id;
while (0 != (id = get_next_win_id()))
{
extern void reset_windows_on_winch()
{
- char * f_name = "reset_windows_on_winch()";
endwin(); /* "[S]tandard way" to recalibrate ncurses post SIGWINCH, says */
refresh(); /* <http://invisible-island.net/ncurses/ncurses-intro.html>. */
- char * tmp_order = try_malloc(strlen(world.winDB.order) + 1, f_name);
+ char * tmp_order = try_malloc(strlen(world.winDB.order) + 1, __func__);
int test = sprintf(tmp_order, "%s", world.winDB.order);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
uint8_t i;
char tmp_active = world.winDB.active;
for (i = 0; i < strlen(tmp_order); toggle_window(tmp_order[i]), i++);
{
return 0;
}
- char * f_name = "err_line()";
char * prefix = " Offending line ";
char * affix = ": ";
size_t size = strlen(err_line_intro) + strlen(msg) + strlen(prefix)
+ 10 /* strlen for uint32_t representations */
+ strlen(affix) + strlen(err_line_line) + 1;
- char * err = try_malloc(size, f_name);
+ char * err = try_malloc(size, __func__);
int ret = snprintf(err, size, "%s%s%s%d%s%s", err_line_intro, msg, prefix,
err_line_count, affix, err_line_line);
- exit_trouble(ret < 0, f_name, "snprintf()");
+ exit_trouble(ret < 0, __func__, "snprintf");
if (err_line_exit)
{
exit_err(1, err);
}
- exit_trouble(0 > printf("%s\n", err), f_name, "printf()");
- exit_trouble(EOF == fflush(stdout), f_name, "fflush()");
+ exit_trouble(0 > printf("%s\n", err), __func__, "printf");
+ exit_trouble(EOF == fflush(stdout), __func__, "fflush");
free(err);
return 1;
}
static char * build_temp_path(char * path)
{
- char * f_name = "build_temp_path";
char * suffix_tmp = "_tmp";
uint16_t size = strlen(path) + strlen(suffix_tmp) + 1;
- char * path_tmp = try_malloc(size, f_name);
+ char * path_tmp = try_malloc(size, __func__);
int test = sprintf(path_tmp, "%s%s", path, suffix_tmp);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
return path_tmp;
}
-extern FILE * try_fopen(char * path, char * mode, char * f)
+extern FILE * try_fopen(char * path, char * mode, const char * f)
{
- char * f_name = "try_fopen()";
char * msg1 = "Trouble in ";
- char * msg2 = " with fopen() (mode '";
+ char * msg2 = " with fopen (mode '";
char * msg3 = "') on path '";
char * msg4 = "'.";
uint16_t size = strlen(msg1) + strlen(msg2) + strlen(msg3) + strlen(msg4)
+ strlen(f) + strlen(path) + strlen(mode) + 1;
- char * msg = try_malloc(size, f_name);
+ char * msg = try_malloc(size, __func__);
int test = sprintf(msg, "%s%s%s%s%s%s%s", msg1,f,msg2,mode,msg3,path,msg4);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
FILE * file_p = fopen(path, mode);
exit_err(NULL == file_p, msg);
free(msg);
-extern void try_fclose(FILE * file, char * f)
+extern void try_fclose(FILE * file, const char * f)
{
- exit_trouble(fclose(file), f, "fclose()");
+ exit_trouble(fclose(file), f, "fclose");
}
extern void try_fwrite(void * ptr, size_t size, size_t nmemb, FILE * stream,
- char * f)
+ const char * f)
{
- exit_trouble(0 == fwrite(ptr, size, nmemb, stream), f, "fwrite()");
+ exit_trouble(0 == fwrite(ptr, size, nmemb, stream), f, "fwrite");
}
-extern void try_fputc(uint8_t c, FILE * file, char * f)
+extern void try_fputc(uint8_t c, FILE * file, const char * f)
{
- exit_trouble(EOF == fputc(c, file), f, "fputc()");
+ exit_trouble(EOF == fputc(c, file), f, "fputc");
}
-extern int try_fgetc(FILE * file, char * f)
+extern int try_fgetc(FILE * file, const char * f)
{
clearerr(file); /* OSX' (BSD?) fgetc() needs this to undo previous EOFs. */
int test = fgetc(file);
- exit_trouble(EOF == test && ferror(file), f, "fgetc()");
+ exit_trouble(EOF == test && ferror(file), f, "fgetc");
return test;
}
-extern char * try_fgets(char * line, int linemax, FILE * file, char * f)
+extern char * try_fgets(char * line, int linemax, FILE * file, const char * f)
{
char * test = fgets(line, linemax, file);
- exit_trouble(NULL == test && ferror(file), f, "fgets()");
+ exit_trouble(NULL == test && ferror(file), f, "fgets");
return test;
}
extern FILE * atomic_write_start(char * path, char ** path_tmp)
{
- char * f_name = "atomic_write_start()";
*path_tmp = build_temp_path(path);
- return try_fopen(*path_tmp, "w", f_name);
+ return try_fopen(*path_tmp, "w", __func__);
}
extern void atomic_write_finish(FILE * file, char * path, char * path_tmp)
{
- char * f_name = "atomic_write_finish()";
- try_fclose(file, f_name);
+ try_fclose(file, __func__);
char * msg1 = "Trouble in ";
char * msg4 = "'.";
if (!access(path, F_OK))
{
- char * msg2 = " with unlink() on path '";
+ char * msg2 = " with unlink on path '";
uint16_t size = strlen(msg1) + strlen(msg2) + strlen(msg4)
- + strlen(f_name) + strlen(path) + 1;
- char * msg = try_malloc(size, f_name);
- int test = sprintf(msg, "%s%s%s%s%s", msg1, f_name, msg2, path, msg4);
- exit_trouble(test < 0, f_name, "sprintf()");
+ + strlen(__func__) + strlen(path) + 1;
+ char * msg = try_malloc(size, __func__);
+ int test = sprintf(msg, "%s%s%s%s%s", msg1, __func__, msg2, path, msg4);
+ exit_trouble(test < 0, __func__, "sprintf");
exit_err(unlink(path), msg);
free(msg);
}
- char * msg2 = " with rename() from '";
+ char * msg2 = " with rename from '";
char * msg3 = "' to '";
- uint16_t size = strlen(msg1) + strlen(f_name) + strlen(msg2) +
+ uint16_t size = strlen(msg1) + strlen(__func__) + strlen(msg2) +
+ strlen(path_tmp) + strlen(msg3) + strlen(path)
+ strlen(msg4) + 1;
- char * msg = try_malloc(size, f_name);
+ char * msg = try_malloc(size, __func__);
int test = sprintf(msg, "%s%s%s%s%s%s%s",
- msg1, f_name, msg2, path_tmp, msg3, path, msg4);
- exit_trouble(test < 0, f_name, "sprintf()");
+ msg1, __func__, msg2, path_tmp, msg3, path, msg4);
+ exit_trouble(test < 0, __func__, "sprintf");
exit_err(rename(path_tmp, path), msg);
free(msg);
free(path_tmp);
extern void detect_atomic_leftover(char * path)
{
- char * f_name = "detect_atomic_leftover()";
char * path_tmp = build_temp_path(path);
char * part1 = "Found file '";
char * part2 = "' that may be a leftover from an aborted previous attempt "
char * part3 = "'. Aborting until the matter is solved by (re-)moving it.";
uint32_t size = strlen(part1) + strlen(path_tmp) + strlen(part2)
+ strlen(path) + strlen(part3) + 1;
- char * msg = try_malloc(size, f_name);
+ char * msg = try_malloc(size, __func__);
int test = sprintf(msg, "%s%s%s%s%s", part1, path_tmp, part2, path, part3);
- exit_trouble(test < 0, f_name, "sprintf()");
+ exit_trouble(test < 0, __func__, "sprintf");
exit_err(!access(path_tmp, F_OK), msg);
free(msg);
free(path_tmp);
extern uint32_t textfile_width(FILE * file)
{
- char * f_name = "textfile_width()";
int c = 0;
uint32_t c_count = 0;
uint32_t linemax = 0;
while (1)
{
- c = try_fgetc(file, f_name);
+ c = try_fgetc(file, __func__);
if (EOF == c)
{
break;
}
c_count++;
- exit_trouble(UINT32_MAX == c_count, f_name, "too large text file line");
+ exit_trouble(UINT32_MAX==c_count, __func__, "too large text file line");
if ('\n' == c)
{
if (c_count > linemax)
{ /* line / lack newline chars. */
linemax = c_count;
}
- exit_trouble(-1 == fseek(file, 0, SEEK_SET), f_name, "fseek()");
+ exit_trouble(-1 == fseek(file, 0, SEEK_SET), __func__, "fseek");
return linemax;
}
/* Wrappers to fopen(), fclose(), fgets() and fwrite() from function called "f",
* calling exit_err() upon error with appropriate error messages.
*/
-extern FILE * try_fopen(char * path, char * mode, char * f);
-extern void try_fclose(FILE * file, char * f);
+extern FILE * try_fopen(char * path, char * mode, const char * f);
+extern void try_fclose(FILE * file, const char * f);
extern void try_fwrite(void * ptr, size_t size, size_t nmemb, FILE * stream,
- char * f);
-extern void try_fputc(uint8_t c, FILE * file, char * f);
+ const char * f);
+extern void try_fputc(uint8_t c, FILE * file, const char * f);
/* Wrapper to calling fgetc() and fgets() from function "f". The return code is
* returned unless ferror() indicates an error (i.e. to signify an end of file,
* on "file" before fgetc(), because some Unixes fgetc() remember old EOFs and
* only return those until explicitely cleared.
*/
-extern int try_fgetc(FILE * file, char * f);
-extern char * try_fgets(char * line, int size, FILE * file, char * f);
+extern int try_fgetc(FILE * file, const char * f);
+extern char * try_fgets(char * line, int size, FILE * file, const char * f);
/* Write to "path_tmp" "path" + "_tmp" and return a new file at that "path_tmp"
* open for writing. "path_tmp" is malloc()'d, must be freed externally.
-extern void exit_err(int err, char * msg)
+extern void exit_err(int err, const char * msg)
{
if (0 == err)
{
-extern void exit_trouble(int err, char * parent, char * child)
+extern void exit_trouble(int err, const char * parent, const char * child)
{
- char * f_name = "exit_trouble()";
char * p1 = "Trouble in ";
char * p2 = " with ";
char * p3 = ".";
uint16_t size = strlen(p1) + strlen(parent) + strlen(p2) + strlen(child)
+ strlen(p3) + 1;
- char * msg = try_malloc(size, f_name);
+ char * msg = try_malloc(size, __func__);
int test = sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3);
- exit_err(test < 0, "Trouble in exit_trouble() with sprintf()");
+ exit_err(test < 0, "Trouble in exit_trouble with sprintf.");
exit_err(err, msg);
free(msg);
}
* consists of "msg" or (if "msg" is NULL pointer) a generic "Details unknown"
* and of errno's content (if it is non-zero).
*/
-extern void exit_err(int err, char * msg);
+extern void exit_err(int err, const char * msg);
/* Do exit_err() with "msg" as: "Trouble in ".parent." with ".child."." */
-extern void exit_trouble(int err, char * parent, char * child);
+extern void exit_trouble(int err, const char * parent, const char * child);
-extern void * try_malloc(size_t size, char * f)
+extern void * try_malloc(size_t size, const char * f)
{
- char * prefix = "Trouble with malloc() in ";
+ char * prefix = "Trouble with malloc in ";
char * msg = malloc(strlen(prefix) + strlen(f) + 1 + 1);
exit_err(NULL == msg,
- "Trouble in try_malloc() with malloc() for error message string.");
+ "Trouble in try_malloc with malloc for error message string.");
int test = sprintf(msg, "%s%s.", prefix, f);
- exit_err(test < 0, "Trouble in try_malloc() with sprintf().");
+ exit_err(test < 0, "Trouble in try_malloc with sprintf.");
void * p = malloc(size);
exit_err(NULL == p, msg); /* Bypass exit_trouble() calling try_malloc(). */
free(msg);
/* Call malloc("size") from function called "f"; exit_trouble() on error. */
-extern void * try_malloc(size_t size, char * f);
+extern void * try_malloc(size_t size, const char * f);
static char get_dir_to_nearest_enemy(struct Thing * t_origin)
{
- char * f_name = "get_dir_to_nearest_enemy()";
-
/* Calculate for each cell the distance to the visibly nearest map actor not
* "t_origin", with movement only possible in the directions of "dir".
* (Actors' own cells start with a distance of 0 towards themselves.)
*/
uint32_t map_size = world.map.length * world.map.length;
uint16_t max_score = UINT16_MAX - 1;
- uint16_t * score_map = try_malloc(map_size * sizeof(uint16_t), f_name);
+ uint16_t * score_map = try_malloc(map_size * sizeof(uint16_t), __func__);
uint32_t i;
for (i = 0; i < map_size; i++)
{
extern void cleanup()
{
- char * f_name = "cleanup()";
free(world.queue);
free(world.log);
free(world.map.cells);
}
if (cleanup_flags & CLEANUP_IN)
{
- try_fclose(world.file_in, f_name);
+ try_fclose(world.file_in, __func__);
unlink(s[S_PATH_IN]);
}
if (cleanup_flags & CLEANUP_OUT)
{
- try_fclose(world.file_out, f_name);
+ try_fclose(world.file_out, __func__);
free(world.server_test);
unlink(s[S_PATH_OUT]);
}
*/
static uint8_t mv_yx_in_dir_wrap(char d, struct yx_uint8 * yx, uint8_t unwrap);
-/* Wrapper to "mv_yx_in_dir_wrap()", returns 1 if the wrapped function moved
- * "yx" within the wrap borders and the map size, else 0.
+/* Wrapper to mv_yx_in_dir_wrap(), returns 1 if the wrapped function moved "yx"
+ * within the wrap borders and the map size, else 0.
*/
static uint8_t mv_yx_in_dir_legal(char dir, struct yx_uint8 * yx);
struct shadow_angle ** shadows, uint16_t pos_in_map,
uint8_t * fov_map)
{
- char * f_name = "set_shadow()";
struct shadow_angle * shadow_i;
if (fov_map[pos_in_map] & VISIBLE)
{
if (!try_merging_angles(left_angle, right_angle, shadows))
{
struct shadow_angle * shadow;
- shadow = try_malloc(sizeof(struct shadow_angle), f_name);
+ shadow = try_malloc(sizeof(struct shadow_angle), __func__);
shadow->left_angle = left_angle;
shadow->right_angle = right_angle;
shadow->next = NULL;
extern uint8_t * build_fov_map(struct Thing * eye)
{
- char * f_name = "build_fov_map()";
uint32_t map_size = world.map.length * world.map.length;
- uint8_t * fov_map = try_malloc(map_size, f_name);
+ uint8_t * fov_map = try_malloc(map_size, __func__);
memset(fov_map, VISIBLE, map_size);
struct yx_uint8 test_pos = eye->pos;
struct shadow_angle * shadows = NULL;
static uint8_t parse_world_active(char * tok0, char * tok1)
{
- char * f_name = "parse_world_active()";
if (!strcmp(tok0, s[S_CMD_WORLD_ACTIVE]) && !parsetest_int(tok1, '8'))
{
if (!parsetest_int(tok1, '8'))
if (!access(s[S_PATH_WORLDSTATE], F_OK))
{
int test = unlink(s[S_PATH_WORLDSTATE]);
- exit_trouble(-1 == test, f_name, "unlink()");
+ exit_trouble(-1 == test, __func__, "unlink");
}
world.exists = 0;
}
s[S_CMD_PICKUP] = "pick_up";
s[S_CMD_DROP] = "drop";
s[S_CMD_USE] = "use";
- s[S_FCN_SPRINTF] = "sprintf()";
+ s[S_FCN_SPRINTF] = "sprintf";
s[S_CMD_THINGTYPE] = "THING_TYPE";
s[S_CMD_TT_CONSUM] = "TT_CONSUMABLE";
s[S_CMD_TT_STARTN] = "TT_START_NUMBER";
static void obey_lines_from_file(char * path, uint8_t record)
{
- char * f_name = "obey_lines_from_file()";
- FILE * file = try_fopen(path, "r", f_name);
+ FILE * file = try_fopen(path, "r", __func__);
uint32_t linemax = textfile_width(file);
- char * line = try_malloc(linemax + 1, f_name);
- while (NULL != try_fgets(line, linemax + 1, file, f_name))
+ char * line = try_malloc(linemax + 1, __func__);
+ while (NULL != try_fgets(line, linemax + 1, file, __func__))
{
if (strlen(line))
{
}
}
free(line);
- try_fclose(file, f_name);
+ try_fclose(file, __func__);
}
static void replay_game()
{
- char * f_name = "replay_game()";
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);
+ FILE * file = try_fopen(s[S_PATH_RECORD], "r", __func__);
uint32_t linemax = textfile_width(file);
- char * line = try_malloc(linemax + 1, f_name);
+ char * line = try_malloc(linemax + 1, __func__);
while ( world.turn < world.replay
- && NULL != try_fgets(line, linemax + 1, file, f_name))
+ && NULL != try_fgets(line, linemax + 1, file, __func__))
{
obey_msg(line, 0, 1);
err_line_inc();
{
if (!end)
{
- end = (NULL == try_fgets(line, linemax + 1, file, f_name));
+ end = (NULL == try_fgets(line, linemax + 1, file, __func__));
if (!end)
{
obey_msg(line, 0, 1);
}
}
free(line);
- try_fclose(file, f_name);
+ try_fclose(file, __func__);
}
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[S_PATH_OUT], "w", f_name);
- world.server_test = try_malloc(10 + 1 + 10 + 1 + 1, f_name);
+ exit_trouble(test && EEXIST != errno, __func__, "mkdir");
+ world.file_out = try_fopen(s[S_PATH_OUT], "w", __func__);
+ world.server_test = try_malloc(10 + 1 + 10 + 1 + 1, __func__);
test = sprintf(world.server_test, "%d %d\n", getpid(), (int) time(0));
- exit_trouble(test < 0, f_name, s[S_FCN_SPRINTF]);
+ exit_trouble(test < 0, __func__, s[S_FCN_SPRINTF]);
try_fwrite(world.server_test, strlen(world.server_test), 1,
- world.file_out, f_name);
+ world.file_out, __func__);
fflush(world.file_out);
set_cleanup_flag(CLEANUP_OUT);
char * path_in = s[S_PATH_IN];
{ /* file streams of clients */
unlink(path_in) ; /* communicating with server processes */
} /* superseded by this current one. */
- world.file_in = try_fopen(path_in, "w", f_name);
- try_fclose(world.file_in, f_name);
- world.file_in = try_fopen(path_in, "r", f_name);
+ world.file_in = try_fopen(path_in, "w", __func__);
+ try_fclose(world.file_in, __func__);
+ world.file_in = try_fopen(path_in, "r", __func__);
set_cleanup_flag(CLEANUP_IN);
}
extern void run_game()
{
- char * f_name = "run_game()";
detect_atomic_leftover(s[S_PATH_SAVE]);
detect_atomic_leftover(s[S_PATH_RECORD]);
err_line_zero();
obey_lines_from_file(s[S_PATH_CONFIG], 1);
err_line_zero();
char * command = s[S_CMD_MAKE_WORLD];
- char * msg = try_malloc(strlen(command) + 1 + 11 + 1, f_name);
+ char * msg = try_malloc(strlen(command) + 1 + 11 + 1, __func__);
int test = sprintf(msg, "%s %d", command, (int) time(NULL));
- exit_trouble(test < 0, f_name, s[S_FCN_SPRINTF]);
+ exit_trouble(test < 0, __func__, s[S_FCN_SPRINTF]);
obey_msg(msg, 1, 1);
free(msg);
}
static void write_key_value(FILE * file, char * key, uint32_t value)
{
- char * f_name = "write_key_value()";
- 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, s[S_FCN_SPRINTF]);
- try_fwrite(line, strlen(line), 1, file, f_name);
+ try_fwrite(key, strlen(key), 1, file, __func__);
+ try_fputc(' ', file, __func__);
+ char * line = try_malloc(11, __func__);
+ exit_trouble(-1 == sprintf(line, "%u", value), __func__, s[S_FCN_SPRINTF]);
+ try_fwrite(line, strlen(line), 1, file, __func__);
free(line);
- try_fputc('\n', file, f_name);
+ try_fputc('\n', file, __func__);
}
static void write_key_string(FILE * file, char * key, char * string)
{
- char * f_name = "write_key_string()";
- try_fwrite(key, strlen(key), 1, file, f_name);
- try_fputc(' ', file, f_name);
+ try_fwrite(key, strlen(key), 1, file, __func__);
+ try_fputc(' ', file, __func__);
uint8_t contains_space = NULL != strchr(string, ' ');
if (contains_space)
{
- try_fputc('\'', file, f_name);
+ try_fputc('\'', file, __func__);
}
- try_fwrite(string, strlen(string), 1, file, f_name);
+ try_fwrite(string, strlen(string), 1, file, __func__);
if (contains_space)
{
- try_fputc('\'', file, f_name);
+ try_fputc('\'', file, __func__);
}
- try_fputc('\n', file, f_name);
+ try_fputc('\n', file, __func__);
}
static void write_thing(FILE * file, struct Thing * t)
{
- char * f_name = "write_thing()";
struct Thing * o;
for (o = t->owns; o; o = o->next)
{
{
write_key_value(file, s[S_CMD_T_CARRIES], o->id);
}
- try_fputc('\n', file, f_name);
+ try_fputc('\n', file, __func__);
}
static char * get_message_from_queue()
{
- char * f_name = "get_message_from_queue()";
char * message = NULL;
if (world.queue_size)
{
if (0 < cutout_len)
{
cutout_len++;
- message = try_malloc(cutout_len, f_name);
+ message = try_malloc(cutout_len, __func__);
memcpy(message, world.queue, cutout_len);
}
for (;
} /* un-allocated first. */
else
{
- char * new_queue = try_malloc(world.queue_size, f_name);
+ char * new_queue = try_malloc(world.queue_size, __func__);
memcpy(new_queue, &(world.queue[cutout_len]), world.queue_size);
free(world.queue);
world.queue = new_queue;
static void read_file_into_queue()
{
- char * f_name = "read_file_into_queue()";
uint8_t wait_seconds = 5;
time_t now = time(0);
struct timespec dur;
dur.tv_sec = 0;
dur.tv_nsec = 33333333;
int test;
- while (EOF == (test = try_fgetc(world.file_in, f_name)))
+ while (EOF == (test = try_fgetc(world.file_in, __func__)))
{
nanosleep(&dur, NULL);
if (time(0) > now + wait_seconds)
{
c = '\0';
}
- char * new_queue = try_malloc(world.queue_size + 1, f_name);
+ char * new_queue = try_malloc(world.queue_size + 1, __func__);
memcpy(new_queue, world.queue, world.queue_size);
char * new_pos = new_queue + world.queue_size;
* new_pos = c;
free(world.queue);
world.queue = new_queue;
}
- while (EOF != (test = try_fgetc(world.file_in, f_name)));
+ while (EOF != (test = try_fgetc(world.file_in, __func__)));
}
static void update_worldstate_file()
{
- char * f_name = "update_worldstate_file()";
char * path_tmp;
FILE * file = atomic_write_start(s[S_PATH_WORLDSTATE], &path_tmp);
struct Thing * player = get_player();
write_map(player, file);
if (world.log)
{
- try_fwrite(world.log, strlen(world.log), 1, file, f_name);
+ try_fwrite(world.log, strlen(world.log), 1, file, __func__);
}
atomic_write_finish(file, s[S_PATH_WORLDSTATE], path_tmp);
set_cleanup_flag(CLEANUP_WORLDSTATE);
char * dot = ".\n";
- try_fwrite(dot, strlen(dot), 1, world.file_out, f_name);
+ try_fwrite(dot, strlen(dot), 1, world.file_out, __func__);
fflush(world.file_out);
}
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. */
- 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);
+ exit_trouble(sprintf(write_buf,"%u\n",value) < 0,__func__,s[S_FCN_SPRINTF]);
+ try_fwrite(write_buf, strlen(write_buf), 1, file, __func__);
}
static void write_inventory(struct Thing * player, FILE * file)
{
- char * f_name = "write_inventory()";
struct Thing * owned = player->owns;
if (NULL == owned)
{
char * empty = "(none)\n";
- try_fwrite(empty, strlen(empty), 1, file, f_name);
+ try_fwrite(empty, strlen(empty), 1, file, __func__);
}
else
{
for (q = 0; NULL != owned; q++)
{
struct ThingType * tt = get_thing_type(owned->type);
- try_fwrite(tt->name, strlen(tt->name), 1, file, f_name);
- try_fputc('\n', file, f_name);
+ try_fwrite(tt->name, strlen(tt->name), 1, file, __func__);
+ try_fputc('\n', file, __func__);
owned = owned->next;
}
}
- try_fputc('%', file, f_name);
- try_fputc('\n', file, f_name);
+ try_fputc('%', file, __func__);
+ try_fputc('\n', file, __func__);
}
static char * build_visible_map(struct Thing * player)
{
- char * f_name = "build_visible_map()";
uint32_t map_size = world.map.length * world.map.length;
- char * visible_map = try_malloc(map_size, f_name);
+ char * visible_map = try_malloc(map_size, __func__);
memset(visible_map, ' ', map_size);
if (player->fov_map) /* May fail if player thing was created / positioned */
{ /* by god command after turning off FOV building. */
static void write_map(struct Thing * player, FILE * file)
{
- char * f_name = "write_map()";
char * visible_map = build_visible_map(player);
uint16_t x, y;
for (y = 0; y < world.map.length; y++)
{
for (x = 0; x < world.map.length; x++)
{
- try_fputc(visible_map[(y * world.map.length) + x], file, f_name);
+ try_fputc(visible_map[(y * world.map.length) + x], file, __func__);
}
- try_fputc('\n', file, f_name);
+ try_fputc('\n', file, __func__);
}
free(visible_map);
}
extern char * io_round()
{
- char * f_name = "io_round()";
if (0 < world.queue_size)
{
return get_message_from_queue();
read_file_into_queue();
if (world.queue_size && '\0' != world.queue[world.queue_size - 1])
{
- char * new_queue = try_malloc(world.queue_size + 1, f_name);
+ char * new_queue = try_malloc(world.queue_size + 1, __func__);
memcpy(new_queue, world.queue, world.queue_size);
new_queue[world.queue_size] = '\0';
world.queue_size++;
extern void save_world()
{
- char * f_name = "save_world()";
char * path_tmp;
FILE * file = atomic_write_start(s[S_PATH_SAVE], &path_tmp);
write_key_value(file, s[S_CMD_MAPLENGTH], world.map.length);
write_key_value(file, s[S_CMD_PLAYTYPE], world.player_type);
- try_fputc('\n', file, f_name);
+ try_fputc('\n', file, __func__);
struct ThingAction * ta;
for (ta = world.thing_actions; ta; ta = ta->next)
{
write_key_value(file, s[S_CMD_THINGACTION], ta->id);
write_key_value(file, s[S_CMD_TA_EFFORT], ta->effort);
write_key_string(file, s[S_CMD_TA_NAME], ta->name);
- try_fputc('\n', file, f_name);
+ try_fputc('\n', file, __func__);
}
struct ThingType * tt;
for (tt = world.thing_types; tt; tt = tt->next)
write_key_value(file, s[S_CMD_TT_STARTN], tt->start_n);
write_key_value(file, s[S_CMD_TT_HP], tt->lifepoints);
int test = fprintf(file, "%s %c\n", s[S_CMD_TT_SYMB], tt->char_on_map);
- exit_trouble(test < 0, f_name, "fprintf()");
+ exit_trouble(test < 0, __func__, "fprintf");
write_key_string(file, s[S_CMD_TT_NAME], tt->name);
write_key_value(file, s[S_CMD_TT_CONSUM], tt->consumable);
- try_fputc('\n', file, f_name);
+ try_fputc('\n', file, __func__);
}
for (tt = world.thing_types; tt; tt = tt->next)
{
write_key_value(file, s[S_CMD_THINGTYPE], tt->id);
write_key_value(file, s[S_CMD_TT_CORPS], tt->corpse_id);
}
- try_fputc('\n', file, f_name);
+ try_fputc('\n', file, __func__);
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);
+ try_fputc('\n', file, __func__);
struct Thing * t;
for (t = world.things; t; t = t->next)
{
extern void remake_map()
{
- char * f_name = "init_map()";
free(world.map.cells);
- world.map.cells = try_malloc(world.map.length * world.map.length, f_name);
+ world.map.cells = try_malloc(world.map.length * world.map.length, __func__);
uint32_t store_seed = world.seed;
world.seed = world.seed_map;
make_sea();
static void server_test()
{
- char * f_name = "server_test()";
char test[10 + 1 + 10 + 1 + 1];
- 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);
+ FILE * file = try_fopen(s[S_PATH_OUT], "r", __func__);
+ try_fgets(test, 10 + 10 + 1 + 1, file, __func__);
+ try_fclose(file, __func__);
if (strcmp(test, world.server_test))
{
unset_cleanup_flag(CLEANUP_WORLDSTATE);
static void record_msg(char * msg)
{
- char * f_name = "record_msg()";
char * path_tmp;
FILE * file_tmp = atomic_write_start(s[S_PATH_RECORD], &path_tmp);
if (!access(s[S_PATH_RECORD], F_OK))
{
- FILE * file_read = try_fopen(s[S_PATH_RECORD], "r", f_name);
+ FILE * file_read = try_fopen(s[S_PATH_RECORD], "r", __func__);
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))
+ char * line = try_malloc(linemax + 1, __func__);
+ while (try_fgets(line, linemax + 1, file_read, __func__))
{
- try_fwrite(line, strlen(line), 1, file_tmp, f_name);
+ try_fwrite(line, strlen(line), 1, file_tmp, __func__);
}
free(line);
- try_fclose(file_read, f_name);
+ try_fclose(file_read, __func__);
}
- try_fwrite(msg, strlen(msg), 1, file_tmp, f_name);
- try_fputc('\n', file_tmp, f_name);
+ try_fwrite(msg, strlen(msg), 1, file_tmp, __func__);
+ try_fputc('\n', file_tmp, __func__);
atomic_write_finish(file_tmp, s[S_PATH_RECORD], path_tmp);
}
extern void obey_msg(char * msg, uint8_t do_record, uint8_t do_verbose)
{
- char * f_name = "obey_msg()";
if (world.is_verbose && do_verbose)
{
- exit_trouble(-1 == printf("Input: %s\n", msg), f_name, "printf()");
+ exit_trouble(-1 == printf("Input: %s\n", msg), __func__, "printf");
}
set_err_line_options("Trouble with message: ", msg, 0);
char * msg_copy = strdup(msg);
extern uint8_t io_loop()
{
- char * f_name = "io_loop()";
while (1)
{
server_test();
}
if (world.is_verbose)
{
- exit_trouble(-1 == printf("Input: %s\n", msg), f_name, "printf()");
+ exit_trouble(-1 == printf("Input: %s\n", msg), __func__, "printf");
}
if (!strcmp("QUIT", msg))
{
{
free(msg);
char * pong = "PONG\n";
- try_fwrite(pong, strlen(pong), 1, world.file_out, f_name);
+ try_fwrite(pong, strlen(pong), 1, world.file_out, __func__);
fflush(world.file_out);
continue;
}
static void update_log(char * text)
{
- char * f_name = "update_log()";
uint16_t len_new = strlen(text);
uint16_t len_old = 0;
uint16_t offset = 0;
}
}
uint16_t len_whole = len_old + len_new + 1;
- char * new_text = try_malloc(len_whole, f_name);
+ char * new_text = try_malloc(len_whole, __func__);
memcpy(new_text, world.log + offset, len_old);
int test = sprintf(new_text + len_old, "%s", text);
- exit_trouble(test < 0, f_name, s[S_FCN_SPRINTF]);
+ exit_trouble(test < 0, __func__, s[S_FCN_SPRINTF]);
free(world.log);
world.log = new_text;
}
static void actor_hits_actor(struct Thing * hitter, struct Thing * hitted)
{
- char * f_name = "actor_hits_actor()";
struct ThingType * tt_hitter = get_thing_type(hitter->type);
struct ThingType * tt_hitted = get_thing_type(hitted->type);
struct Thing * player = get_player();
msg3 = tt_hitted->name;
}
uint8_t len = 1 + strlen(msg1) + 1 + strlen(msg2) + 1 + strlen(msg3) + 2;
- char * msg = try_malloc(len, f_name);
+ char * msg = try_malloc(len, __func__);
int test = sprintf(msg, "\n%s %s %s.", msg1, msg2, msg3);
- exit_trouble(test < 0, f_name, s[S_FCN_SPRINTF]);
+ exit_trouble(test < 0, __func__, s[S_FCN_SPRINTF]);
update_log(msg);
free(msg);
hitted->lifepoints--;
static void playerbonus_move(char d, uint8_t passable)
{
- char * f_name = "playerbonus_move()";
char * dsc_dir = "north-east";
if ( match_dir(d, &dsc_dir, 'd', "east")
|| match_dir(d, &dsc_dir, 'c', "south-east")
{
dsc_move = "You fail to move ";
}
- char * msg = try_malloc(strlen(dsc_move) + strlen (dsc_dir) + 3, f_name);
+ char * msg = try_malloc(strlen(dsc_move) + strlen (dsc_dir) + 3, __func__);
int test = sprintf(msg, "\n%s%s.", dsc_move, dsc_dir);
- exit_trouble(test < 0, f_name, s[S_FCN_SPRINTF]);
+ exit_trouble(test < 0, __func__, s[S_FCN_SPRINTF]);
update_log(msg);
free(msg);
}
int16_t id, uint8_t struct_id,
struct NextAndId ** start)
{
- char * f_name = "add_to_struct_list()";
- struct NextAndId * nai = try_malloc(n_size, f_name);
+ struct NextAndId * nai = try_malloc(n_size, __func__);
memset(nai, 0, n_size);
nai->id = (start_id<=id && id<=UINT8_MAX) ? id : get_unused_id(struct_id);
struct NextAndId ** nai_ptr_ptr = start;