From 97f6a2438df1eaeb4128ce36f29346ea38a3db4a Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Fri, 7 Oct 2022 20:02:27 +0100 Subject: first very unfinished commit lol --- UMain.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 UMain.c (limited to 'UMain.c') diff --git a/UMain.c b/UMain.c new file mode 100644 index 0000000..717eee1 --- /dev/null +++ b/UMain.c @@ -0,0 +1,110 @@ +#include "UCWInterface.h" + +// 1C40 to 2008 + +// TODO move me +// TODO move me + +// unsure where this is, may be here, maybe not? +extern char cmdline_build_date[32]; +extern char cmdline_build_time[32]; + +int main(int argc, const char **argv) { + unsigned long cpu; + unsigned long os; + unsigned long language; + unsigned long plugintype; + unsigned long style; + int result; + + if (CmdLine_Initialize(argc, argv, CMDLINE_BUILD_DATE, CMDLINE_BUILD_TIME)) + exit(1); + + if (!RegisterStaticParserResources() || !RegisterStaticTargetResources()) { + fprintf(stderr, "\nFATAL ERROR: Could not initialize resource strings\n"); + exit(1); + } + + if (!RegisterStaticParserPlugins() || !RegisterStaticTargetPlugins()) { + fprintf(stderr, "\nFATAL ERROR: Could not initialize built-in plugins\n"); + exit(1); + } + + if (!RegisterStaticParserToolInfo()) { + fprintf(stderr, "\nFATAL ERROR: Could not initialize options\n"); + exit(1); + } + + GetStaticTarget(&cpu, &os); + SetBuildTarget(cpu, os); + GetStaticPluginType(&language, &plugintype); + SetPluginType(language, plugintype); + GetStaticParserPluginType(&style); + SetParserType(style); + + result = CmdLine_Driver(); + if (result) { + if (result == 2) + fprintf(stderr, "\nUser break, cancelled...\n"); + else + fprintf(stderr, "\nErrors caused tool to abort.\n"); + } + CmdLine_Terminate(result); + return result; +} + +int RegisterResource(const char *name, short index, void *data) { + Handle r; + + if (data == 0) { + r = GetResource('STR#', index); + if (r == 0) { + CLFatalError("Resource ('STR#',%d) '%s' not found in executable\n", index, name); + return 0; + } + ReleaseResource(r); + return 1; + } else { + return Res_AddResource(name, index, data); + } +} + +int RegisterStaticPlugin(const BasePluginCallbacks *cb) { + return Plugins_Add(Plugin_New(cb, 0, 0)); +} + +int RegisterStaticCompilerLinkerPlugin(const BasePluginCallbacks *cb, void *b) { + return Plugins_Add(Plugin_New(cb, b, 0)); +} + +int RegisterStaticParserPlugin(const BasePluginCallbacks *cb, void *b) { + return Plugins_Add(Plugin_New(cb, 0, b)); +} + +void SetBuildTarget(CWDataType cpu, CWDataType os) { + clState.cpu = cpu; + clState.os = os; +} + +void SetParserType(CWDataType style) { + clState.style = style; +} + +void SetPluginType(CWDataType language, CWDataType plugintype) { + clState.language = language; + clState.plugintype = plugintype; +} + +int CmdLine_Initialize(int argc, const char **argv, const char *buildDate, const char *buildTime) { + strncpy(cmdline_build_date, buildDate, sizeof(cmdline_build_date)); + strncpy(cmdline_build_time, buildTime, sizeof(cmdline_build_time)); + return Main_Initialize(argc, argv); +} + +int CmdLine_Driver() { + return Main_Driver(); +} + +int CmdLine_Terminate(int code) { + return Main_Terminate(code); +} -- cgit v1.2.3