summaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/main.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/app/main.c b/src/app/main.c
index ab8688f..ce43b61 100644
--- a/src/app/main.c
+++ b/src/app/main.c
@@ -1,15 +1,57 @@
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
#include "mcp/server.h"
+#include "storage/store.h"
+
+static void
+usage(FILE *stream)
+{
+ fwprintf(stream, L"Usage: tiny-convmem-mcp --data-dir <path>\n");
+}
int
-main(void)
+wmain(int argc, wchar_t **argv)
{
- const int result = tiny_convmem_server_run(stdin, stdout);
+ wchar_t *absolute = NULL;
+ DWORD required;
+ tiny_store_t *store = NULL;
+ tiny_store_status_t status;
+ int result;
+ if (argc == 2 && wcscmp(argv[1], L"--help") == 0)
+ {
+ usage(stdout);
+ return 0;
+ }
+ if (argc != 3 || wcscmp(argv[1], L"--data-dir") != 0 || argv[2][0] == L'\0')
+ {
+ usage(stderr);
+ return 2;
+ }
+ required = GetFullPathNameW(argv[2], 0, NULL, NULL);
+ if (required == 0 || (absolute = malloc((size_t)required * sizeof(wchar_t))) == NULL
+ || GetFullPathNameW(argv[2], required, absolute, NULL) == 0)
+ {
+ fprintf(stderr, "unable to resolve --data-dir\n");
+ free(absolute);
+ return 2;
+ }
+ status = tiny_store_open(&store, absolute);
+ free(absolute);
+ if (status != TINY_STORE_OK)
+ {
+ fprintf(stderr, "unable to open conversation store: %s\n", tiny_store_status_name(status));
+ return status == TINY_STORE_BUSY ? 3 : 1;
+ }
+ result = tiny_convmem_server_run(stdin, stdout, store);
+ tiny_store_close(store);
if (result != 0)
{
fprintf(stderr, "tiny-convmem-mcp stopped with error code %d\n", result);
}
return result;
}
-