2022-10-11 02:18:42 +00:00
|
|
|
#include "includes/mwcc_decomp.h"
|
2022-10-07 19:02:27 +00:00
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
// TODO split main off into CLStaticMain.c
|
2022-10-07 19:02:27 +00:00
|
|
|
int main(int argc, const char **argv) {
|
2022-10-11 02:18:42 +00:00
|
|
|
CWDataType cpu;
|
|
|
|
CWDataType os;
|
|
|
|
CWDataType lang;
|
|
|
|
CWDataType type;
|
|
|
|
CWDataType style;
|
|
|
|
int ret;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
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);
|
2022-10-11 02:18:42 +00:00
|
|
|
GetStaticPluginType(&lang, &type);
|
|
|
|
SetPluginType(lang, type);
|
2022-10-07 19:02:27 +00:00
|
|
|
GetStaticParserPluginType(&style);
|
|
|
|
SetParserType(style);
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
ret = CmdLine_Driver();
|
|
|
|
if (ret) {
|
|
|
|
if (ret == 2)
|
2022-10-07 19:02:27 +00:00
|
|
|
fprintf(stderr, "\nUser break, cancelled...\n");
|
|
|
|
else
|
|
|
|
fprintf(stderr, "\nErrors caused tool to abort.\n");
|
|
|
|
}
|
2022-10-11 02:18:42 +00:00
|
|
|
CmdLine_Terminate(ret);
|
|
|
|
return ret;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
int RegisterResource(const char *name, short rsrcid, Handle list) {
|
|
|
|
Handle h;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
if (data == 0) {
|
2022-10-11 02:18:42 +00:00
|
|
|
h = GetResource('STR#', rsrcid);
|
|
|
|
if (h == 0) {
|
|
|
|
CLFatalError("Resource ('STR#',%d) '%s' not found in executable\n", rsrcid, name);
|
2022-10-07 19:02:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2022-10-11 02:18:42 +00:00
|
|
|
ReleaseResource(h);
|
2022-10-07 19:02:27 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
2022-10-11 02:18:42 +00:00
|
|
|
return Res_AddResource(name, rsrcid, list);
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
int RegisterStaticPlugin(const BasePluginCallbacks *callbacks) {
|
|
|
|
return Plugins_Add(Plugin_New(callbacks, 0, 0));
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
int RegisterStaticCompilerLinkerPlugin(const BasePluginCallbacks *callbacks, const CompilerLinkerPluginCallbacks *cl_callbacks) {
|
|
|
|
return Plugins_Add(Plugin_New(callbacks, cl_callbacks, 0));
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
int RegisterStaticParserPlugin(const BasePluginCallbacks *callbacks, const ParserPluginCallbacks *pr_callbacks) {
|
|
|
|
return Plugins_Add(Plugin_New(callbacks, 0, pr_callbacks));
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetBuildTarget(CWDataType cpu, CWDataType os) {
|
|
|
|
clState.cpu = cpu;
|
|
|
|
clState.os = os;
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
void SetParserType(CWDataType plang) {
|
|
|
|
clState.parserstyle = plang;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
void SetPluginType(CWDataType lang, CWDataType type) {
|
|
|
|
clState.language = lang;
|
|
|
|
clState.plugintype = type;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
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));
|
2022-10-07 19:02:27 +00:00
|
|
|
return Main_Initialize(argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CmdLine_Driver() {
|
|
|
|
return Main_Driver();
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
int CmdLine_Terminate(int exitcode) {
|
|
|
|
return Main_Terminate(exitcode);
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|