aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-19 14:49:24 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-19 14:49:24 +0200
commit2ffbd7fcc178e68e7132d2f8f649d131c5a5d3af (patch)
tree7a3983e4ccd4ab14413fe9209a8142727cb83a23
parentaac409bdd73fd96d256f87285a7c9b959d2117b3 (diff)
downloadEpisodeBrowser-2ffbd7fcc178e68e7132d2f8f649d131c5a5d3af.tar.gz
Add comments.
-rw-r--r--c/common.cpp27
-rw-r--r--c/pl.cpp20
-rw-r--r--c/pl.h8
3 files changed, 36 insertions, 19 deletions
diff --git a/c/common.cpp b/c/common.cpp
index 494c382..a91836d 100644
--- a/c/common.cpp
+++ b/c/common.cpp
@@ -2,6 +2,8 @@
#include "common.h"
+/* Win32Error: Exception for Windows API errors. */
+
Win32Error::Win32Error(const DWORD dwErr) : m_dwErr(dwErr) {}
Win32Error::~Win32Error()
@@ -46,6 +48,8 @@ const TCHAR* Win32Error::twhat() const noexcept
#undef M
}
+/* Library: Wrapper for loading and freeing dynamically linked libraries. */
+
Library::Library(const TCHAR* const tszLibrary)
{
m_hModule = LoadLibrary(tszLibrary);
@@ -66,21 +70,22 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR
return CallNextHookEx(0, nCode, wParam, lParam);
HWND hWnd = (HWND)wParam;
- if (long lStyle = GetWindowLong(hWnd, GWL_STYLE))
- if (lStyle & WS_POPUP) {
- RECT rcMain, rcMsg;
- GetWindowRect(g_hWnd, &rcMain);
- GetWindowRect(hWnd, &rcMsg);
- SetWindowPos(hWnd, NULL,
- rcMain.left+(rcMain.right-rcMain.left)/2-(rcMsg.right-rcMsg.left)/2,
- rcMain.top+(rcMain.bottom-rcMain.top)/2-(rcMsg.bottom-rcMsg.top)/2,
- -1, -1,
- SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
- }
+ long lStyle = GetWindowLong(hWnd, GWL_STYLE);
+ if (!(lStyle & WS_POPUP)) return 0;
+
+ RECT rcMain, rcMsg;
+ GetWindowRect(g_hWnd, &rcMain);
+ GetWindowRect(hWnd, &rcMsg);
+ SetWindowPos(hWnd, NULL,
+ rcMain.left+(rcMain.right-rcMain.left)/2-(rcMsg.right-rcMsg.left)/2,
+ rcMain.top+(rcMain.bottom-rcMain.top)/2-(rcMsg.bottom-rcMsg.top)/2,
+ -1, -1,
+ SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
return 0;
}
+/* Show message box owned by and centered in the main window. */
int EBMessageBox(const TCHAR* const tszText, const TCHAR* const tszCaption, const unsigned uType)
{
extern HWND g_hWnd;
diff --git a/c/pl.cpp b/c/pl.cpp
index fb3d4af..ef8aaf9 100644
--- a/c/pl.cpp
+++ b/c/pl.cpp
@@ -3,6 +3,8 @@
#include "pl.h"
+/* Frame: Wrapper for opening and closing Prolog foreign frames. */
+
Frame::Frame()
{
m_f = PL_open_foreign_frame();
@@ -18,6 +20,7 @@ void Frame::Close()
PL_close_foreign_frame(m_f);
}
+/* Close foreign frame and invalidate associated data. */
void Frame::Discard()
{
PL_discard_foreign_frame(m_f);
@@ -28,6 +31,8 @@ void Frame::Rewind()
PL_rewind_foreign_frame(m_f);
}
+/* Mark: Wrapper for marking and releasing strings on the Prolog stack. */
+
Mark::Mark()
{
PL_mark_string_buffers(&m_m);
@@ -38,6 +43,8 @@ Mark::~Mark()
PL_release_string_buffers_from_mark(m_m);
}
+/* Query: Wrapper for opening, solving and cutting Prolog query. */
+
Query::Query(const module_t ctx, const predicate_t p, const term_t t0)
{
m_q = PL_open_query(ctx, PL_Q_CATCH_EXCEPTION, p, t0);
@@ -55,6 +62,7 @@ int Query::Cut()
return 0;
}
+/* Cut query and invalidate associated data. */
int Query::Close()
{
if (PL_close_query(m_q)) return 1;
@@ -69,6 +77,7 @@ int Query::NextSolution()
return 0;
}
+/* Convert Prolog term to normal or wide characters. */
int PL_get_tchars(const term_t t, TCHAR** const pTsz, const int iFlags)
{
#ifdef UNICODE
@@ -83,6 +92,7 @@ int PL_get_tchars(const term_t t, TCHAR** const pTsz, const int iFlags)
#endif
}
+/* Call nullary Prolog predicate, propagating Prolog exceptions. */
int Plx(const char* const szMod, const char* const szPred)
{
Frame f;
@@ -90,3 +100,13 @@ int Plx(const char* const szMod, const char* const szPred)
Query q(NULL, PL_predicate(szPred, 0, szMod), t);
return q.NextSolution();
}
+
+/* Call nullary Prolog predicate, ignoring Prolog exceptions. */
+int Pl(const char* const szMod, const char* const szPred)
+{
+ try {
+ return Plx(szMod, szPred);
+ } catch (term_t& t) {
+ return 0;
+ }
+}
diff --git a/c/pl.h b/c/pl.h
index d4bf18b..00285e0 100644
--- a/c/pl.h
+++ b/c/pl.h
@@ -95,14 +95,6 @@ int Plx(const char* const szMod, const char* const szPred, T... args)
}
/* Call Prolog predicate, ignoring Prolog exceptions. */
-inline int Pl(const char* const szMod, const char* const szPred)
-{
- try {
- return Plx(szMod, szPred);
- } catch (term_t& t) {
- return 0;
- }
-}
template <typename ...T>
int Pl(const char* const szMod, const char* const szPred, T... args)
{