summaryrefslogtreecommitdiff
path: root/UMain.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--UMain.c110
1 files changed, 110 insertions, 0 deletions
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);
+}