2022-10-07 19:02:27 +00:00
|
|
|
#include "UCWInterface.h"
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
static short CLT_dummymain(void *context) {
|
2022-10-07 19:02:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static short CLT_GetDropInFlags(const DropInFlags **flags, long *flagsSize) {
|
|
|
|
static const DropInFlags sFlags = {
|
|
|
|
kCurrentDropInFlagsVersion,
|
|
|
|
CWFOURCHAR('c','l','d','r'),
|
|
|
|
7,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
12
|
|
|
|
};
|
|
|
|
*flags = &sFlags;
|
|
|
|
*flagsSize = sizeof(sFlags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
static short CLT_GetDropInName(const char **dropinName) {
|
2022-10-07 19:02:27 +00:00
|
|
|
static const char *sDropInName = "Command-Line Driver";
|
2022-10-11 02:18:42 +00:00
|
|
|
*dropinName = sDropInName;
|
2022-10-07 19:02:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static short CLT_GetDisplayName(const char **displayName) {
|
|
|
|
static const char *sDisplayName = "Command-Line Driver";
|
|
|
|
*displayName = sDisplayName;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static short CLT_GetPanelList(const CWPanelList **panelList) {
|
|
|
|
static const char *sPanelNames[4];
|
|
|
|
static CWPanelList sPanelList = {
|
|
|
|
kCurrentCWPanelListVersion,
|
|
|
|
4,
|
|
|
|
sPanelNames
|
|
|
|
};
|
|
|
|
|
|
|
|
sPanelNames[0] = "CmdLine Panel";
|
|
|
|
if (clState.plugintype == CWDROPINCOMPILERTYPE) {
|
|
|
|
sPanelNames[1] = "CmdLine Compiler Panel";
|
|
|
|
sPanelNames[2] = "CmdLine Linker Panel";
|
|
|
|
sPanelList.count = 3;
|
|
|
|
} else {
|
|
|
|
sPanelNames[1] = "CmdLine Linker Panel";
|
|
|
|
sPanelList.count = 2;
|
|
|
|
}
|
|
|
|
*panelList = &sPanelList;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static short CLT_GetTargetList(const CWTargetList **targetList) {
|
|
|
|
static CWDataType sCPU = CWFOURCHAR('*','*','*','*');
|
|
|
|
static CWDataType sOS = CWFOURCHAR('*','*','*','*');
|
|
|
|
static CWTargetList sTargetList = {
|
|
|
|
kCurrentCWTargetListVersion,
|
|
|
|
1,
|
|
|
|
&sCPU,
|
|
|
|
1,
|
|
|
|
&sOS
|
|
|
|
};
|
|
|
|
*targetList = &sTargetList;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static short CLT_GetVersionInfo(const VersionInfo **versioninfo) {
|
|
|
|
static const VersionInfo vi = {
|
|
|
|
3, 0, 0, 0
|
|
|
|
};
|
|
|
|
*versioninfo = &vi;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
static short CLT_GetFileTypeMappings(const OSFileTypeMappingList **mappinglist) {
|
2022-10-07 19:02:27 +00:00
|
|
|
static const OSFileTypeMapping ftmes[2] = {
|
|
|
|
{CWFOURCHAR('B','r','w','s'), "DubL", 4, 0, 0},
|
|
|
|
{CWFOURCHAR('M','M','P','r'), "looc", 4, 0, 0}
|
|
|
|
};
|
|
|
|
static const OSFileTypeMappingList ftml = {
|
|
|
|
2,
|
|
|
|
ftmes
|
|
|
|
};
|
2022-10-11 02:18:42 +00:00
|
|
|
*mappinglist = &ftml;
|
2022-10-07 19:02:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BasePluginCallbacks clcb = {
|
|
|
|
CLT_dummymain,
|
|
|
|
CLT_GetDropInFlags,
|
|
|
|
CLT_GetDisplayName,
|
|
|
|
CLT_GetDropInName,
|
|
|
|
CLT_GetPanelList,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
CLT_GetVersionInfo,
|
|
|
|
CLT_GetFileTypeMappings
|
|
|
|
};
|
|
|
|
|
|
|
|
static int RegisterStaticCmdLinePlugin() {
|
|
|
|
return RegisterStaticPlugin(&clcb);
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
// TODO do me later - this comes from CmdLine/Project/Resources/CLErrors.r
|
|
|
|
const char *STR12000[100];
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
static int RegisterCmdLineResources() {
|
|
|
|
return RegisterResource("Command-line strings", 12000, &STR12000);
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
static int special_debug(unsigned char pre, char *) {
|
|
|
|
if (pre) {
|
2022-10-07 19:02:27 +00:00
|
|
|
SetupDebuggingTraps();
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
static int special_plugin_debug(unsigned char pre, char *) {
|
|
|
|
if (pre) {
|
2022-10-07 19:02:27 +00:00
|
|
|
clState.pluginDebug = 1;
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return clState.pluginDebug;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
static int special_stdout_base(unsigned char pre, char *) {
|
|
|
|
if (pre) {
|
2022-10-07 19:02:27 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return clState.stdoutBase != 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SpecialOption {
|
2022-10-11 02:18:42 +00:00
|
|
|
const char *optname;
|
|
|
|
char **argp;
|
|
|
|
int (*func)(unsigned char a, char *b);
|
2022-10-07 19:02:27 +00:00
|
|
|
};
|
|
|
|
static struct SpecialOption special_options[3] = {
|
|
|
|
{"", 0, special_debug},
|
|
|
|
{"--plugin-debug", 0, special_plugin_debug},
|
|
|
|
{"--stdout", /*TODO clState*/ 0, special_stdout_base}
|
|
|
|
};
|
|
|
|
|
|
|
|
void Main_PreParse(int *pArgc, char ***pArgv) {
|
2022-10-11 02:18:42 +00:00
|
|
|
struct SpecialOption *so;
|
|
|
|
int idx;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
if (*pArgc > 1) {
|
|
|
|
restart:
|
2022-10-11 02:18:42 +00:00
|
|
|
for (idx = 0, so = &special_options[0]; idx < 3; idx++, so++) {
|
|
|
|
if (!strcmp(so->optname, (*pArgv)[1])) {
|
|
|
|
if (so->argp) {
|
|
|
|
*so->argp = (*pArgv)[2];
|
|
|
|
so->func(1, *so->argp);
|
2022-10-07 19:02:27 +00:00
|
|
|
(*pArgv)[1] = (*pArgv)[0];
|
|
|
|
(*pArgc)--;
|
|
|
|
(*pArgv)++;
|
|
|
|
|
|
|
|
(*pArgv)[1] = (*pArgv)[0];
|
|
|
|
(*pArgc)--;
|
|
|
|
(*pArgv)++;
|
|
|
|
} else {
|
2022-10-11 02:18:42 +00:00
|
|
|
so->func(1, 0);
|
2022-10-07 19:02:27 +00:00
|
|
|
(*pArgv)[1] = (*pArgv)[0];
|
|
|
|
(*pArgc)--;
|
|
|
|
(*pArgv)++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
if ((*pArgc) > 1 && idx < 3)
|
2022-10-07 19:02:27 +00:00
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Main_PassSpecialArgs(void *unk1, void *unk2) {
|
2022-10-11 02:18:42 +00:00
|
|
|
struct SpecialOption *so;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
for (idx = 0; idx < 3; idx++) {
|
|
|
|
so = &special_options[idx];
|
|
|
|
if (so->func(0, 0)) {
|
|
|
|
AppendArgumentList(unk1, unk2, so->optname);
|
|
|
|
if (so->argp)
|
|
|
|
AppendArgumentList(unk1, unk2, (*so->argp) ? *so->argp : "");
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MainInitialized;
|
|
|
|
void *gProj;
|
|
|
|
PCmdLine optsCmdLine;
|
|
|
|
PCmdLineEnvir optsEnvir;
|
|
|
|
PCmdLineCompiler optsCompiler;
|
|
|
|
PCmdLineLinker optsLinker;
|
|
|
|
|
|
|
|
int Main_Initialize(int argc, const char **argv) {
|
|
|
|
static char secret[8];
|
2022-10-11 02:18:42 +00:00
|
|
|
char exename[256];
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
OS_InitProgram(&argc, &argv);
|
|
|
|
memset(&clState, 0, sizeof(CLState));
|
2022-10-11 02:18:42 +00:00
|
|
|
special_options[0].optname = secret;
|
2022-10-07 19:02:27 +00:00
|
|
|
secret[7] = 0;
|
|
|
|
secret[4] = 'b';
|
|
|
|
secret[1] = '-';
|
|
|
|
secret[5] = 'u';
|
|
|
|
secret[2] = 'd';
|
|
|
|
secret[0] = '-';
|
|
|
|
secret[3] = 'e';
|
|
|
|
secret[6] = 'g';
|
|
|
|
|
|
|
|
Main_PreParse(&argc, &argv);
|
|
|
|
clState.argc = argc;
|
|
|
|
clState.argv = argv;
|
|
|
|
// TODO more shite
|
|
|
|
|
|
|
|
MainInitialized = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
int Main_Terminate(int exitcode) {
|
2022-10-07 19:02:27 +00:00
|
|
|
if (MainInitialized) {
|
|
|
|
Plugins_Term();
|
|
|
|
License_Terminate();
|
|
|
|
Proj_Terminate(gProj);
|
|
|
|
IO_Terminate();
|
|
|
|
MainInitialized = 0;
|
|
|
|
}
|
2022-10-11 02:18:42 +00:00
|
|
|
return exitcode;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int Main_ParseCommandLine() {
|
|
|
|
// TODO: clState, Plugins, gTarg, ...
|
2022-10-11 02:18:42 +00:00
|
|
|
long vislang;
|
|
|
|
int x, y;
|
|
|
|
CWCommandLineArgs myargs;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int Main_SetupParamBlock() {
|
|
|
|
// TODO: OS, PrefPanes, clState, ...
|
|
|
|
PrefPanelsChangedCallback(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int Main_ResolveProject() {
|
|
|
|
// TODO: Various project things
|
2022-10-11 02:18:42 +00:00
|
|
|
int err;
|
|
|
|
long startTime, endTime;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
static int UpdatePCmdLineFromVersion(const PCmdLine *given, PCmdLine *target) {
|
2022-10-07 19:02:27 +00:00
|
|
|
static unsigned char warned;
|
2022-10-11 02:18:42 +00:00
|
|
|
short version = given->version;
|
|
|
|
*target = *given;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
// TODO: clState
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
static int UpdatePCmdLineEnvirFromVersion(const PCmdLineEnvir *given, PCmdLineEnvir *target) {
|
2022-10-07 19:02:27 +00:00
|
|
|
static unsigned char warned;
|
2022-10-11 02:18:42 +00:00
|
|
|
short version = given->version;
|
|
|
|
*target = *given;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
// TODO: clState
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
static int UpdatePCmdLineCompilerFromVersion(const PCmdLineCompiler *given, PCmdLineCompiler *target) {
|
2022-10-07 19:02:27 +00:00
|
|
|
static unsigned char warned;
|
2022-10-11 02:18:42 +00:00
|
|
|
short version = given->version;
|
|
|
|
*target = *given;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
// TODO: clState
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
static int UpdatePCmdLineLinkerFromVersion(const PCmdLineLinker *given, PCmdLineLinker *target) {
|
2022-10-07 19:02:27 +00:00
|
|
|
static unsigned char warned;
|
2022-10-11 02:18:42 +00:00
|
|
|
short version = given->version;
|
|
|
|
*target = *given;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
// TODO: clState
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int UpdatePrefPanels(const char *name) {
|
|
|
|
PrefPanel *panel;
|
2022-10-11 02:18:42 +00:00
|
|
|
Handle h;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
if (!name || !ustrcmp(name, "CmdLine Panel")) {
|
2022-10-11 02:18:42 +00:00
|
|
|
if ((panel = Prefs_FindPanel("CmdLine Panel")) && (h = PrefPanel_GetHandle(panel))) {
|
2022-10-07 19:02:27 +00:00
|
|
|
if (name) {
|
2022-10-11 02:18:42 +00:00
|
|
|
if (!UpdatePCmdLineFromVersion((PCmdLine *) *h, &optsCmdLine))
|
2022-10-07 19:02:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CLReportError(91, "CmdLine Panel");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name || !ustrcmp(name, "CmdLine Environment")) {
|
2022-10-11 02:18:42 +00:00
|
|
|
if ((panel = Prefs_FindPanel("CmdLine Environment")) && (h = PrefPanel_GetHandle(panel))) {
|
2022-10-07 19:02:27 +00:00
|
|
|
if (name) {
|
2022-10-11 02:18:42 +00:00
|
|
|
if (!UpdatePCmdLineEnvirFromVersion((PCmdLineEnvir *) *h, &optsEnvir))
|
2022-10-07 19:02:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CLReportError(91, "CmdLine Environment");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name || !ustrcmp(name, "CmdLine Compiler Panel")) {
|
2022-10-11 02:18:42 +00:00
|
|
|
if ((panel = Prefs_FindPanel("CmdLine Compiler Panel")) && (h = PrefPanel_GetHandle(panel))) {
|
2022-10-07 19:02:27 +00:00
|
|
|
if (name) {
|
2022-10-11 02:18:42 +00:00
|
|
|
if (!UpdatePCmdLineCompilerFromVersion((PCmdLineCompiler *) *h, &optsCompiler))
|
2022-10-07 19:02:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CLReportError(91, "CmdLine Compiler Panel");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name || !ustrcmp(name, "CmdLine Linker Panel")) {
|
2022-10-11 02:18:42 +00:00
|
|
|
if ((panel = Prefs_FindPanel("CmdLine Linker Panel")) && (h = PrefPanel_GetHandle(panel))) {
|
2022-10-07 19:02:27 +00:00
|
|
|
if (name) {
|
2022-10-11 02:18:42 +00:00
|
|
|
if (!UpdatePCmdLineLinkerFromVersion((PCmdLineLinker *) *h, &optsLinker))
|
2022-10-07 19:02:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CLReportError(91, "CmdLine Linker Panel");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SetupCmdLinePrefPanels() {
|
2022-10-11 02:18:42 +00:00
|
|
|
int ret;
|
2022-10-07 19:02:27 +00:00
|
|
|
|
|
|
|
PrefPanelsChangedCallback = UpdatePrefPanels;
|
2022-10-11 02:18:42 +00:00
|
|
|
ret = Prefs_AddPanel(
|
2022-10-07 19:02:27 +00:00
|
|
|
PrefPanel_New("CmdLine Environment", &optsEnvir, sizeof(PCmdLineEnvir))
|
|
|
|
);
|
2022-10-11 02:18:42 +00:00
|
|
|
ret |= (
|
2022-10-07 19:02:27 +00:00
|
|
|
Prefs_AddPanel(PrefPanel_New("CmdLine Panel", 0, sizeof(PCmdLine)))
|
|
|
|
&& Prefs_AddPanel(PrefPanel_New("CmdLine Compiler Panel", 0, sizeof(PCmdLineCompiler)))
|
|
|
|
&& Prefs_AddPanel(PrefPanel_New("CmdLine Linker Panel", 0, sizeof(PCmdLineLinker)))
|
|
|
|
);
|
|
|
|
|
2022-10-11 02:18:42 +00:00
|
|
|
return ret;
|
2022-10-07 19:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int Main_SetupContext() {
|
|
|
|
// TODO Target, Plugins, clState
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmp_buf exit_program;
|
|
|
|
|
|
|
|
int Main_Driver() {
|
|
|
|
volatile int result;
|
|
|
|
|
|
|
|
result = setjmp(exit_program);
|
|
|
|
if (!result) {
|
|
|
|
if (!SetupCmdLinePrefPanels())
|
|
|
|
CLFatalError("Could not initialize preferences");
|
|
|
|
|
|
|
|
Main_SetupContext();
|
|
|
|
if (!(result = Main_ParseCommandLine())) {
|
|
|
|
if (!(result = Main_SetupParamBlock()))
|
|
|
|
result = Main_ResolveProject();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|