X-Git-Url: https://plomlompom.com/repos/index.html?a=blobdiff_plain;f=src%2Fclient%2Fwindows.c;h=674e6ad67a00f149dfa06fa20c778ebb3f414697;hb=cdb90723dd636591bcfa98ebb165cf74a0cdeec7;hp=2fd51313405e1c4d9ebedaa33ff1273e4947be4a;hpb=37fb9ef76174a83e27dd27a3250f4be5542e7452;p=plomrogue
diff --git a/src/client/windows.c b/src/client/windows.c
index 2fd5131..674e6ad 100644
--- a/src/client/windows.c
+++ b/src/client/windows.c
@@ -11,10 +11,9 @@
#include /* uint8_t, uint16_t, uint32_t, UINT16_MAX */
#include /* sprintf() */
#include /* memcpy(), strlen(), strnlen(), strchr(), memset() */
+#include "../common/err_try_fgets.h" /* err_try_fgets(), err_line() */
+#include "../common/readwrite.h" /* try_fputc(), try_write(), try_fgetc() */
#include "../common/rexit.h" /* exit_trouble(), exit_err() */
-#include "../common/readwrite.h" /* try_fputc(), try_write(), try_fgets(),
- * try_fgetc()
- */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint16.h" /* struct yx_uint16 */
#include "draw_wins.h" /* draw_winconf_geometry(), draw_winconf_keybindings(),
@@ -27,6 +26,7 @@
#include "keybindings.h" /* free_keybindings(), write_keybidings_to_file(),
* read_keybindings_from_file()
*/
+#include "misc.h" /* array_append() */
#include "world.h" /* global world */
@@ -100,9 +100,6 @@ static void draw_wins(struct Win * w);
static void append_win(struct Win * w);
static void suspend_win(struct Win * w);
-/* Copy Win content pointed to by "win" into appendend world.winDB.wins area. */
-static void add_win_to_winDB(struct Win * win);
-
static uint8_t get_pos_in_order(char c)
@@ -554,35 +551,8 @@ static void suspend_win(struct Win * w)
-static void add_win_to_winDB(struct Win * win)
-{
- char * f_name = "add_win_to_winDB()";
- if (world.winDB.ids)
- {
- uint8_t old_ids_size = strlen(world.winDB.ids);
- char * new_ids = try_malloc(old_ids_size + 1 + 1, f_name);
- sprintf(new_ids, "%s%c", world.winDB.ids, win->id);
- free(world.winDB.ids);
- world.winDB.ids = new_ids;
- uint16_t old_wins_size = old_ids_size * sizeof(struct Win);
- uint16_t new_wins_size = old_wins_size + sizeof(struct Win);
- struct Win * new_wins = try_malloc(new_wins_size, f_name);
- memcpy(new_wins, world.winDB.wins, old_wins_size);
- new_wins[old_ids_size] = *win;
- free(world.winDB.wins);
- world.winDB.wins = new_wins;
- return;
- }
- world.winDB.ids = try_malloc(2, f_name);
- sprintf(world.winDB.ids, "%c", win->id);
- world.winDB.wins = try_malloc(sizeof(struct Win), f_name);
- world.winDB.wins[0] = *win;
-}
-
-
-
-extern uint16_t center_offset(uint16_t position, uint16_t mapsize,
- uint16_t frame_size)
+extern uint16_t center_offset(uint16_t position, uint32_t mapsize,
+ uint32_t frame_size)
{
uint16_t offset = 0;
if (mapsize > frame_size)
@@ -624,33 +594,55 @@ extern uint8_t read_winconf_from_file(char * line, uint32_t linemax,
FILE * file)
{
char * f_name = "read_winconf_from_file()";
- int test = try_fgetc(file, f_name);
- if (EOF == test || '\n' == test)
+ char * context = "Failed reading individual window's configuration from "
+ "interface config file. ";
+ char * err_id = "Illegal ID(s) selected.";
+ char * err_2 = "Double-initialized window.";
+ int test_for_end = try_fgetc(file, f_name);
+ if (EOF == test_for_end || '\n' == test_for_end)
{
return 0;
}
+ exit_trouble(EOF == ungetc(test_for_end, file), f_name, "ungetc()");
+ err_try_fgets(line, linemax, file, context, "ns");
+ err_line(NULL == strchr(world.winDB.legal_ids, line[0]), line, context,
+ err_id);
+ exit_err(world.winDB.ids && NULL!=strchr(world.winDB.ids, line[0]), err_2);
struct Win win;
memset(&win, 0, sizeof(struct Win));
- win.id = (char) test;
- try_fgetc(file, f_name);
- try_fgets(line, linemax + 1, file, f_name);
+ win.id = (char) line[0];
+ err_try_fgets(line, linemax, file, context, "0n");
win.title = try_malloc(strlen(line), f_name);
- memcpy(win.title, line, strlen(line) - 1); /* Eliminate newline char */
- win.title[strlen(line) - 1] = '\0'; /* char at end of string. */
- try_fgets(line, linemax + 1, file, f_name);
+ memcpy(win.title, line, strlen(line) - 1); /* Eliminate newline char */
+ win.title[strlen(line) - 1] = '\0'; /* char at end of string. */
+ err_try_fgets(line, linemax, file, context, "0ni");
win.target_height = atoi(line);
win.target_height_type = (0 >= win.target_height);
- try_fgets(line, linemax + 1, file, f_name);
+ err_try_fgets(line, linemax, file, context, "0ni");
win.target_width = atoi(line);
win.target_width_type = (0 >= win.target_width);
read_keybindings_from_file(line, linemax, file, &win.kb);
- add_win_to_winDB(&win);
+ if (world.winDB.ids)
+ {
+ uint8_t old_ids_size = strlen(world.winDB.ids);
+ char * new_ids = try_malloc(old_ids_size + 1 + 1, f_name);
+ sprintf(new_ids, "%s%c", world.winDB.ids, win.id);
+ free(world.winDB.ids);
+ world.winDB.ids = new_ids;
+ array_append(old_ids_size, sizeof(struct Win), (void *) &win,
+ (void **) &world.winDB.wins);
+ return 1;
+ }
+ world.winDB.ids = try_malloc(2, f_name);
+ sprintf(world.winDB.ids, "%c", win.id);
+ world.winDB.wins = try_malloc(sizeof(struct Win), f_name);
+ world.winDB.wins[0] = win;
return 1;
}
-extern void write_winconf_of_id_to_file(FILE * file, char c, char * delim)
+extern void write_winconf_of_id_to_file(FILE * file, char c)
{
char * f_name = "write_winconf_of_id_to_file()";
struct Win * wc = get_win_by_id(c);
@@ -668,38 +660,53 @@ extern void write_winconf_of_id_to_file(FILE * file, char c, char * delim)
try_fwrite(line, sizeof(char), strlen(line), file, f_name);
sprintf(line, "%d\n", wc->target_width);
try_fwrite(line, sizeof(char), strlen(line), file, f_name);
- write_keybindings_to_file(file, &wc->kb, delim);
+ write_keybindings_to_file(file, &wc->kb);
}
extern void read_order_wins_visible_active(char * line, uint32_t linemax,
- FILE * file)
+ FILE * file, char ** tmp_order,
+ char * tmp_active)
{
char * f_name = "read_order_wins_visible_active()";
- char win_order[linemax + 1];
- try_fgets(win_order, linemax + 1, file, f_name);
- win_order[strlen(win_order) - 1] = '\0';
- world.winDB.order = try_malloc(strlen(win_order) + 1, f_name);
- sprintf(world.winDB.order, "%s", win_order);
- int char_or_eof = try_fgetc(file, f_name);
- char * err_eof = "fgetc() unexpectedly hitting EOF";
- exit_trouble(EOF == char_or_eof, f_name, err_eof);
- world.winDB.active = (uint8_t) char_or_eof;
- exit_trouble(EOF == try_fgetc(file, f_name), f_name, err_eof);
- try_fgets(line, linemax + 1, file, f_name);
+ char * context = "Failed reading order and activation of visible windows "
+ "from interface config file. ";
+ char * err_id = "Illegal ID(s) selected.";
+ err_try_fgets(line, linemax, file, context, "01");
+ uint32_t i = 0;
+ for (; i < strlen(line) - 1; i++)
+ {
+ char * test = strchr(world.winDB.legal_ids, line[i]);
+ err_line(!test, line, context, err_id);
+ }
+ line[strlen(line) - 1] = '\0';
+ *tmp_order = try_malloc(strlen(line) + 1, f_name);
+ sprintf(*tmp_order, "%s", line);
+ if (*tmp_order[0])
+ {
+ err_try_fgets(line, linemax, file, context, "0nfs");
+ err_line(NULL == strchr(*tmp_order, line[0]), line, context, err_id);
+ *tmp_active = line[0];
+ }
+ else
+ {
+ err_try_fgets(line, linemax, file, context, "0ne");
+ *tmp_active = '\0';
+ }
+ err_try_fgets(line, linemax, file, context, "d");
}
-extern void write_order_wins_visible_active(FILE * file, char * delim)
+extern void write_order_wins_visible_active(FILE * file)
{
char * f_name = "write_order_wins_visible_active()";
try_fwrite(world.winDB.order, strlen(world.winDB.order), 1, file, f_name);
try_fputc('\n', file, f_name);
try_fputc(world.winDB.active, file, f_name);
try_fputc('\n', file, f_name);
- try_fwrite(delim, strlen(delim), 1, file, f_name);
+ try_fwrite(world.delim, strlen(world.delim), 1, file, f_name);
}