From 92f7852b6979239214848b7ebb4046d52e4aba06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 13 Feb 2022 13:25:39 +0100 Subject: Begin Win32 re-implementation. --- win.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 win.c (limited to 'win.c') diff --git a/win.c b/win.c new file mode 100644 index 0000000..660275d --- /dev/null +++ b/win.c @@ -0,0 +1,122 @@ +#include +#include +#include + +static int Attach(void); +static void ShowEpisode(int); +static void UpdateList(void); + +/* +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + PSTR lpCmdLine, INT nCmdShow) +*/ +int main(int argc, char *argv[]) +{ + char *rgArgs[2]; + + rgArgs[0] = "episode_browser"; + rgArgs[1] = NULL; + + if (!PL_initialise(1, rgArgs)) + PL_halt(1); + + Attach(); + //UpdateList(); + ShowEpisode(400); + + PL_halt(0); +} + +/* Attach persistent databases. */ +int Attach() +{ + int r; + term_t t; + + t = PL_new_term_refs(2); + r = PL_call_predicate(NULL, PL_Q_NORMAL, + PL_predicate("attach", 0, "track_episodes"), + t); + if (!r) return r; + + r = PL_call_predicate(NULL, PL_Q_NORMAL, + PL_predicate("attach", 0, "episode_data"), + t); + if (!r) return r; + + return 1; +} + +/* Update episode list. */ +void UpdateList() +{ + term_t t; + qid_t q; + + t = PL_new_term_refs(2); + PL_call_predicate(NULL, PL_Q_NORMAL, + PL_predicate("update_tracked_episodes", 0, "track_episode"), + t); + + q = PL_open_query(NULL, PL_Q_NORMAL, + PL_predicate("episode_file", 2, "local_episodes"), + t); + + while (PL_next_solution(q)) { + char *sFile; + int nEpisode; + + if (!PL_get_integer(t+0, &nEpisode)) + goto close; + if (!PL_get_atom_chars(t+1, &sFile)) + goto close; + printf("%d: %s\n", nEpisode, sFile); + } + +close: + PL_close_query(q); /* Or PL_cut_query? */ +} + +/* Show episode data. */ +void ShowEpisode(int nEpisode) +{ + int r; + term_t t; + + t = PL_new_term_refs(3); + if(!PL_put_integer(t+0, nEpisode)) + return; + + r = PL_call_predicate(NULL, PL_Q_NORMAL, + PL_predicate("lookup_episode_local", 3, "episode_data"), + t); + if (!r) return; + + /* The episode data is a list of unary compounds, + * whose name is the key and whose value is the value. */ + + { + term_t tHead, tList; + + tHead = PL_new_term_ref(); + tList = PL_copy_term_ref(t+2); + + while (PL_get_list(tList, tHead, tList)) { + atom_t aKey; + const char *sKey; + char *sValue; + term_t tValue; + size_t iArity; + + if (!PL_get_name_arity(tHead, &aKey, &iArity)) + continue; + if (!PL_get_arg(1, tHead, tValue)) + continue; + sKey = PL_atom_chars(aKey); + if(!PL_get_atom_chars(tValue, &sValue)) + continue; + + printf("%s/%d: %s\n", sKey, iArity, sValue); + } + } +} -- cgit v1.2.3