X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=src%2Fclient%2Fwincontrol.c;h=eb9270b411130e5f4ce38471de247a817060857c;hb=a6fd795234fd4e4f9aebcfdc1771afd22c3c9c23;hp=21308e728117756f7dc62f3ec356fd01920f5924;hpb=87aec00b668777cef82a9a43e490563e9c90f039;p=plomrogue
diff --git a/src/client/wincontrol.c b/src/client/wincontrol.c
index 21308e7..eb9270b 100644
--- a/src/client/wincontrol.c
+++ b/src/client/wincontrol.c
@@ -1,4 +1,9 @@
-/* src/client/wincontrol.c */
+/* src/client/wincontrol.c
+ *
+ * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
+ * or any later version. For details on its copyright, license, and warranties,
+ * see the file NOTICE in the root directory of the PlomRogue source package.
+ */
#include "wincontrol.h"
#include /* getmaxx(), getmaxy(), wresize() */
@@ -7,10 +12,9 @@
#include /* sprintf() */
#include /* free() */
#include /* memcpy(), memset(), strchr(), strlen() */
-#include "../common/rexit.h" /* exit_err() */
+#include "../common/rexit.h" /* exit_err(), exit_trouble() */
#include "../common/try_malloc.h" /* try_malloc() */
-#include "../common/yx_uint16.h" /* struct yx_uint16 */
-#include "windows.h" /* struct Win, get_win_by_id(), get_win_pos_in_order() */
+#include "windows.h" /* Win,yx_uint16, get_win_by_id(),get_win_pos_in_order() */
#include "world.h" /* global world */
@@ -178,9 +182,8 @@ static void set_win_target_size(struct Win * w)
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';
@@ -194,14 +197,14 @@ static void append_win(struct Win * w)
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];
- sprintf(new_order, "%s%s", world.winDB.order, second_part);
+ int test = sprintf(new_order, "%s%s", world.winDB.order, second_part);
+ exit_trouble(test < 0, __func__, "sprintf");
free(world.winDB.order);
world.winDB.order = new_order;
world.winDB.active = world.winDB.order[i];
@@ -222,7 +225,7 @@ static void suspend_win(struct Win * w)
extern void toggle_window(char id)
{
struct Win * win = get_win_by_id(id);
- if (NULL == strchr(world.winDB.order, id))
+ if (!strchr(world.winDB.order, id))
{
append_win(win);
return;
@@ -332,7 +335,7 @@ extern void shift_active_win(char dir)
uint8_t len_order = strlen(world.winDB.order);
if (1 < len_order)
{
- char tmp[len_order + 1];
+ 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)
@@ -363,6 +366,7 @@ extern void shift_active_win(char dir)
world.winDB.order[pos - 1] = world.winDB.active;
}
}
+ free(tmp);
update_wins(get_win_by_id(world.winDB.order[0]));
}
}