feat(ui,db,cmd): reduce dublicate code in window subwin logic, unify SQLite helpers, NULL checks added
window.c: add _get_subwin_cols, _apply_split_resize, _check_subwin_width; refactor show/hide/resize/refresh/update database.c: add _db_prepare_ctx, _db_teardown; safer init/queries with fallback timestamp cmd_defs.c: guard fopen in docgen; inputwin.c: replace assert with runtime check
This commit is contained in:
@@ -75,6 +75,21 @@ static void _win_print_internal(ProfWin* window, const char* show_char, int pad_
|
||||
int flags, theme_item_t theme_item, const char* const from, const char* const message, DeliveryReceipt* receipt);
|
||||
static void _win_print_wrapped(WINDOW* win, const char* const message, size_t indent, int pad_indent);
|
||||
|
||||
// Helper: clamp a subwindow width to a sane range [1, cols-1] if possible
|
||||
static int
|
||||
_check_subwin_width(int cols, int width)
|
||||
{
|
||||
if (cols > 1) {
|
||||
if (width < 1)
|
||||
width = 1;
|
||||
if (width >= cols)
|
||||
width = cols - 1;
|
||||
} else {
|
||||
width = 1;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
int
|
||||
win_roster_cols(void)
|
||||
{
|
||||
@@ -82,12 +97,7 @@ win_roster_cols(void)
|
||||
int cols = getmaxx(stdscr);
|
||||
int width = CEILING((((double)cols) / 100) * roster_win_percent);
|
||||
// Clamp to a sane range to avoid zero/full-width pads
|
||||
if (cols > 1) {
|
||||
if (width < 1) width = 1;
|
||||
if (width >= cols) width = cols - 1;
|
||||
} else {
|
||||
width = 1;
|
||||
}
|
||||
width = _check_subwin_width(cols, width);
|
||||
return width;
|
||||
}
|
||||
|
||||
@@ -98,12 +108,7 @@ win_occpuants_cols(void)
|
||||
int cols = getmaxx(stdscr);
|
||||
int width = CEILING((((double)cols) / 100) * occupants_win_percent);
|
||||
// Clamp to a sane range to avoid zero/full-width pads
|
||||
if (cols > 1) {
|
||||
if (width < 1) width = 1;
|
||||
if (width >= cols) width = cols - 1;
|
||||
} else {
|
||||
width = 1;
|
||||
}
|
||||
width = _check_subwin_width(cols, width);
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user