aboutsummaryrefslogtreecommitdiff
path: root/c/main.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-06-02 02:27:43 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-06-02 02:27:43 +0200
commit7f37c580c4e55468ffedba910d01abffe26154f4 (patch)
tree3e50de469d1d871aa77ea23427d6d72d93c3b5cd /c/main.c
parent5b004563a06dd41e5ba474b82088b5ca516bda85 (diff)
downloadEpisodeBrowser-7f37c580c4e55468ffedba910d01abffe26154f4.tar.gz
Simplify C interface to Prolog.
Diffstat (limited to 'c/main.c')
-rw-r--r--c/main.c133
1 files changed, 42 insertions, 91 deletions
diff --git a/c/main.c b/c/main.c
index bcee867..3f94986 100644
--- a/c/main.c
+++ b/c/main.c
@@ -35,7 +35,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR tszErr;
MSG msg;
INITCOMMONCONTROLSEX icc;
- term_t t;
WNDCLASSEX wc;
/* Set constant values. */
@@ -89,8 +88,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
ShowWindow(hWnd, nCmdShow);
/* Populate episode list view. */
- t = T(0);
- P("track_episodes","update_tracked_episodes",0,t);
+ Pl("track_episodes", "update_tracked_episodes", "");
ElvUpdate();
ElvSelectFocus();
@@ -124,34 +122,22 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
FreeLibrary(hModule);
}
SetWindowPos(hWnd, NULL, -1, -1, Dpi(510), Dpi(400), SWP_NOMOVE);
- {
- term_t t;
- t = T(1);
- P("cfg","get_view_watched",1,t) goto s;
- GI(t,&BViewWatched) goto s;
+ if (Pl("cfg","get_view_watched","i",&BViewWatched))
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED,
BViewWatched? MF_CHECKED: MF_UNCHECKED);
- }
- s: {
- term_t t;
- t = T(1);
- P("cfg","get_view_tv_original",1,t) goto t;
- GI(t,&BViewTVOriginal) goto t;
+ if (Pl("cfg","get_view_tv_original","i",&BViewTVOriginal))
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL,
BViewTVOriginal? MF_CHECKED: MF_UNCHECKED);
- }
- t: {
+ {
char *sz;
- term_t t;
- t = T(1);
- P("cfg","get_limit_screenwriter",1,t) goto u;
- GAC(t,&sz) goto u;
+ if (!Pl("cfg","get_limit_screenwriter","s",&sz))
+ goto s;
strcpy_s(SzLimitScreenwriter,
sizeof(SzLimitScreenwriter), sz);
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
SzLimitScreenwriter[0]? MF_UNCHECKED: MF_CHECKED);
}
- u: SetupFonts();
+ s: SetupFonts();
DlvCreate();
ElvCreate();
UpdateTheme();
@@ -167,13 +153,9 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
extern HWND HElv;
lvi.mask = LVIF_PARAM;
if ((lvi.iItem=ListView_GetNextItem(HElv,-1,LVNI_FOCUSED)) != -1
- && ListView_GetItem(HElv, &lvi)) {
- term_t t;
- t = T(1);
- PI(t,lvi.lParam) goto q;
- P("cfg","set_focus",1,t);
- }
- q: PostQuitMessage(0);
+ && ListView_GetItem(HElv, &lvi))
+ Pl("cfg","set_focus","I",lvi.lParam);
+ PostQuitMessage(0);
break;
}
case WM_SIZE:
@@ -210,13 +192,9 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
case WA_ACTIVE:
case WA_CLICKACTIVE:
- {
- term_t t;
SetFocus(HFocus);
- t = T(0);
- P("track_episodes","update_tracked_episodes",0,t);
+ Pl("track_episodes","update_tracked_episodes","");
ElvRedraw();
- }
}
break;
case WM_NOTIFY:
@@ -234,21 +212,13 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
ElvUpdate();
break;
case IDM_FILE_FETCH_DATA:
- {
- term_t t;
- t = T(0);
- P("episode_data","update_episode_data",0,t);
+ Pl("episode_data","update_episode_data","");
ElvUpdate();
break;
- }
case IDM_FILE_FETCH_SCREENWRITERS:
- {
- term_t t;
- t = T(0);
- P("episode_data","update_screenwriters",0,t);
+ Pl("episode_data","update_screenwriters","");
ElvUpdate();
break;
- }
case IDM_FILE_ABOUT:
DialogBox(
GetModuleHandle(NULL),
@@ -260,15 +230,12 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case IDM_VIEW_WATCHED:
{
int iEpFocus;
- term_t t;
extern HWND HElv;
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED,
BViewWatched? MF_UNCHECKED: MF_CHECKED);
BViewWatched = !BViewWatched;
ElvUpdate();
- t = T(1);
- PI(t,BViewWatched) break;
- P("cfg","set_view_watched",1,t);
+ Pl("cfg","set_view_watched","I",BViewWatched);
iEpFocus = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
ListView_EnsureVisible(HElv, iEpFocus, TRUE);
@@ -277,15 +244,12 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case IDM_VIEW_TV_ORIGINAL:
{
int iEpFocus;
- term_t t;
extern HWND HElv;
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL,
BViewTVOriginal? MF_UNCHECKED: MF_CHECKED);
BViewTVOriginal = !BViewTVOriginal;
ElvUpdate();
- t = T(1);
- PI(t,BViewTVOriginal) break;
- P("cfg","set_view_tv_original",1,t);
+ Pl("cfg","set_view_tv_original","I",BViewTVOriginal);
iEpFocus = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
ListView_EnsureVisible(HElv, iEpFocus, TRUE);
@@ -293,40 +257,31 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
case IDM_VIEW_OTHERS: /* Show/hide other screenwriters. */
{
- atom_t a;
int iEpFocus;
- term_t t;
extern HWND HElv;
if (SzLimitScreenwriter[0]) {
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
MF_CHECKED);
SzLimitScreenwriter[0] = 0;
} else {
- atom_t a;
char *sz;
LVITEM lvi;
- term_t t;
iEpFocus = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
lvi.iItem = iEpFocus;
lvi.mask = LVIF_PARAM;
if (!ListView_GetItem(HElv, &lvi)) break;
- t = T(3);
- a = A("Screenwriter");
- PI(t,lvi.lParam) break;
- PA(t+1,a) break;
- P("episode_data","episode_datum",3,t) break;
- GAC(t+2,&sz) break;
+ if (!Pl("episode_data","episode_datum","ISs",
+ lvi.lParam,"Screenwriter",&sz))
+ break;
strcpy_s(SzLimitScreenwriter,
sizeof(SzLimitScreenwriter), sz);
CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
MF_UNCHECKED);
}
ElvUpdate();
- t = T(1);
- a = A(SzLimitScreenwriter);
- PA(t,a) break;
- P("cfg","set_limit_screenwriter",1,t);
+ Pl("cfg","set_limit_screenwriter","S",
+ SzLimitScreenwriter);
iEpFocus = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED);
if (iEpFocus == -1) break;
ListView_EnsureVisible(HElv, iEpFocus, TRUE);
@@ -350,8 +305,8 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case IDM_RATE1:
case IDM_RATE0:
{
+ int iRating;
LVITEM lvi;
- term_t t;
extern HWND HElv;
/* Look through selected items, applying the
@@ -359,70 +314,68 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
lvi.mask = LVIF_PARAM;
lvi.iItem = -1;
- t = T(2);
while ((lvi.iItem = ListView_GetNextItem(
HElv, lvi.iItem, LVNI_SELECTED)) != -1) {
if (!ListView_GetItem(HElv, &lvi)) goto b;
- PI(t,lvi.lParam) goto b;
switch (LOWORD(wParam)) {
case IDM_WATCH_LOCALLY:
- P("local_episode","open_episode_locally",1,t);
+ Pl("local_episode","open_episode_locally","I",lvi.lParam);
break;
case IDM_WATCH_ONLINE:
- P("local_episode","open_episode_online",1,t);
+ Pl("local_episode","open_episode_online","I",lvi.lParam);
break;
case IDM_TOGGLE:
- P("track_episodes","toggle_episode",1,t);
+ Pl("track_episodes","toggle_episode","I",lvi.lParam);
ElvRedraw();
break;
case IDM_FORGET:
- P("track_episodes","forget_episode",1,t);
- P("track_episodes","update_tracked_episodes",0,t);
+ Pl("track_episodes","forget_episode","I",lvi.lParam);
+ Pl("track_episodes","update_tracked_episodes","");
ElvRedraw();
break;
case IDM_LOOKUP:
- P("episode_data","retract_episode",1,t);
+ Pl("episode_data","retract_episode","I",lvi.lParam);
ElvUpdateItem(&lvi);
ElvRedraw();
DlvShowEpisode(lvi.lParam);
break;
case IDM_WIKI:
- P("episode_data","open_episode_wiki",1,t);
+ Pl("episode_data","open_episode_wiki","I",lvi.lParam);
break;
case IDM_RATE10:
- PI(t+1,10) break;
+ iRating = 0;
goto r;
case IDM_RATE9:
- PI(t+1,9) break;
+ iRating = 9;
goto r;
case IDM_RATE8:
- PI(t+1,8) break;
+ iRating = 8;
goto r;
case IDM_RATE7:
- PI(t+1,7) break;
+ iRating = 7;
goto r;
case IDM_RATE6:
- PI(t+1,6) break;
+ iRating = 6;
goto r;
case IDM_RATE5:
- PI(t+1,5) break;
+ iRating = 5;
goto r;
case IDM_RATE4:
- PI(t+1,4) break;
+ iRating = 4;
goto r;
case IDM_RATE3:
- PI(t+1,3) break;
+ iRating = 3;
goto r;
case IDM_RATE2:
- PI(t+1,2) break;
+ iRating = 2;
goto r;
case IDM_RATE1:
- PI(t+1,1) break;
+ iRating = 1;
goto r;
case IDM_RATE0:
- PI(t+1,0) break;
- r: P("episode_data","rate_episode",2,t);
+ iRating = 0;
+ r: Pl("episode_data","rate_episode","II",lvi.lParam,iRating);
ElvUpdateItem(&lvi);
break;
}
@@ -499,10 +452,8 @@ CreateStatusBar(HWND hWndParent, HINSTANCE hInstance)
int
Attach()
{
- term_t t;
- t = T(0);
- P("track_episodes","attach",0,t) return 0;
- P("episode_data","attach",0,t) return 0;
+ if (!Pl("track_episodes","attach","")) return 0;
+ if (!Pl("episode_data","attach","")) return 0;
return 1;
}