aboutsummaryrefslogtreecommitdiff
path: root/c/main.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-30 03:14:13 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-30 03:14:13 +0200
commitebabd34385feb629b759216c1f7d85edc20bf2fd (patch)
tree432e68a6a58bcaf4bc1dd3c5ae438157f09f4d4a /c/main.cpp
parentd485eb2bf7e0a82702afec9387f21bf0f89c985f (diff)
downloadEpisodeBrowser-ebabd34385feb629b759216c1f7d85edc20bf2fd.tar.gz
Add wstring_owner, replacing std::wstring.
std::basic_string is nice, but it is not very ergonomic if everything you really need is to automatically free C strings at end of scope. I suppose I could have used std::unique_ptr for this, but I suspect the ergonomics would be worse.
Diffstat (limited to 'c/main.cpp')
-rw-r--r--c/main.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/c/main.cpp b/c/main.cpp
index c9be01d..2edc6ec 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -48,7 +48,7 @@ void TerminateMsg(const wchar_t* wsz1, const wchar_t* wsz2) noexcept
{
wchar_t wsz[256] = {0};
if (wsz2)
- wszf(wsz, L"Episode Browser was terminated due to %s: %s.", wsz1, wsz2);
+ wszf(wsz, L"Episode Browser was terminated due to %s: %s", wsz1, wsz2);
else
wszf(wsz, L"Episode Browser was terminated due to %s.", wsz1);
MessageBox(g_hWnd, wsz, L"Fatal Error", MB_ICONERROR);
@@ -59,15 +59,14 @@ void OnTerminate() noexcept
try {
std::rethrow_exception(std::current_exception());
} catch (const term_t& t) {
- std::wstring ws;
- if (PlString(t, &ws))
- TerminateMsg(L"a Prolog exception", ws.c_str());
+ if (auto wso = PlString(t))
+ TerminateMsg(L"a Prolog exception", wso.p);
else
TerminateMsg(L"a Prolog exception", NULL);
} catch (const Win32Error& e) {
TerminateMsg(L"a Windows error", e.WhatW());
} catch (const std::exception& e) {
- TerminateMsg(L"an exception", WsFromSz(e.what()).c_str());
+ TerminateMsg(L"an exception", WsoFromSz(e.what()).p);
} catch (...) {
TerminateMsg(L"an exception", NULL);
}
@@ -466,13 +465,13 @@ void WaitFor(const char* szMod, const char* szPred)
static atom_t aThread;
static int bActive;
static int iTimer;
- static std::wstring wsPred;
+ static wstring_owner wsoPred;
if (bActive) {
- wchar_t wsz[128] = {0};
+ wchar_t wsz[256] = {0};
wszf(wsz, L"Another task (%s) is active. "
L"Do you want to cancel the existing task and start a new one?",
- wsPred.c_str());
+ wsoPred.p);
if (EBMessageBox(wsz, L"Error", MB_YESNO|MB_ICONWARNING) != IDYES)
return;
KillTimer(NULL, iTimer);
@@ -483,7 +482,8 @@ void WaitFor(const char* szMod, const char* szPred)
/* The timer procedure animates an ellipsis in the status bar
* while the thread is running. */
- static auto proc = [](HWND, UINT, UINT_PTR, DWORD) -> void {
+ static auto proc = [](HWND, UINT, UINT_PTR, DWORD) -> void
+ {
static int i = 0;
if (Pl("episode_data","thread_running",aThread)) {
@@ -501,7 +501,7 @@ void WaitFor(const char* szMod, const char* szPred)
Plx(szMod,"thread_create",szPred,&aThread);
SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)L".");
if (prefer(iTimer = SetTimer(NULL, -1, 500, proc))) {
- wsPred = WsFromSz(szPred);
+ wsoPred = WsoFromSz(szPred);
bActive = 1;
}
}