From e2d0b92ffc536c3d34ee751ba688946613bc5693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 7 Aug 2022 00:40:48 +0200 Subject: Add Strcpy. --- c/main.cpp | 27 ++++++++++++++------------- c/util.h | 7 +++++++ 2 files changed, 21 insertions(+), 13 deletions(-) (limited to 'c') diff --git a/c/main.cpp b/c/main.cpp index 449863b..5a7ec27 100644 --- a/c/main.cpp +++ b/c/main.cpp @@ -215,7 +215,7 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR Mark m; char* s; if (Pl("cfg","get_limit_screenwriter",&s)) - strcpy_s(g_limitScreenwriter, sizeof(g_limitScreenwriter), s); + Strcpy(g_limitScreenwriter, s); int dlvHeight = 0; Pl("cfg","get_dlv_height",&dlvHeight); @@ -418,18 +418,19 @@ void HandleMainMenu(const HWND hWnd, const WORD command) g_elv->Update(); g_elv->EnsureFocusVisible(); break; - case IDM_VIEW_OTHERS: /* Show/hide other screenwriters. */ - if (g_limitScreenwriter[0]) { + case IDM_VIEW_OTHERS: + if (g_limitScreenwriter[0]) { /* Show episodes by all screenwriters. */ CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, MF_CHECKED); g_limitScreenwriter[0] = 0; - } else { - LVITEM lvi = {LVIF_PARAM, -1}; - if (!g_elv->FindNextItem(&lvi, LVNI_FOCUSED)) break; - + } else { /* Hide episodes by other screenwriters than current. */ + Mark m; char* s; - if (!Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&s)) break; - strcpy_s(g_limitScreenwriter, sizeof(g_limitScreenwriter), s); - CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, MF_UNCHECKED); + LVITEM lvi = {LVIF_PARAM, -1}; + if (g_elv->FindNextItem(&lvi, LVNI_FOCUSED) + && Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&s)) { + Strcpy(g_limitScreenwriter, s); + CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, MF_UNCHECKED); + } } Pl("cfg","set_limit_screenwriter",g_limitScreenwriter); g_elv->Update(); @@ -484,8 +485,7 @@ void HandleContextMenu(const HWND, const WORD command) g_elv->Redraw(); if (cNotFound == 1) { - EBMessageBox(L"Episode could not be opened locally.", - L"Error", MB_ICONWARNING); + EBMessageBox(L"Episode could not be opened locally.", L"Error", MB_ICONWARNING); } else if (cNotFound) { wchar_t msg[64] = {0}; Swprintf(msg, L"%d episodes could not be opened locally.", cNotFound); @@ -504,7 +504,8 @@ void WaitFor(const char* mod, const char* pred) if (activePred) { wchar_t msg[256] = {0}; - Swprintf(msg, L"Another task (%s) is active. " + Swprintf(msg, + L"Another task (%s) is active. " L"Do you want to cancel the existing task and start a new one?", static_cast(activePred)); if (EBMessageBox(msg, L"Error", MB_YESNO|MB_ICONWARNING) != IDYES) diff --git a/c/util.h b/c/util.h index 11840fa..51fd020 100644 --- a/c/util.h +++ b/c/util.h @@ -10,6 +10,13 @@ inline int Swprintf(wchar_t (&buf)[N], const wchar_t* const fmt, T... xs) return _snwprintf_s(buf, N, _TRUNCATE, fmt, xs...); } +/* Copy to static narrow string buffer. */ +template +inline int Strcpy(char (&dst)[N], const char* const src) +{ + return strcpy_s(dst, N, src); +} + inline int Cmp(const int a, const int b) { if (a == b) return 0; -- cgit v1.2.3