mirror of https://git.wuffs.org/MWCC
385 lines
9.7 KiB
C
385 lines
9.7 KiB
C
|
#include "UCWInterface.h"
|
||
|
|
||
|
static short CLT_dummymain() {
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
static short CLT_GetDropInName(const char **dropInName) {
|
||
|
static const char *sDropInName = "Command-Line Driver";
|
||
|
*dropInName = sDropInName;
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
static short CLT_GetFileTypeMappings(const OSFileTypeMappingList **mappingList) {
|
||
|
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
|
||
|
};
|
||
|
*mappingList = &ftml;
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
const char *STR12000[100]; // TODO do me later
|
||
|
|
||
|
static int RegisterCmdLineResources() {
|
||
|
return RegisterResource("Command-line strings", 12000, &STR12000);
|
||
|
}
|
||
|
|
||
|
static int special_debug(unsigned char flag, char *) {
|
||
|
if (flag) {
|
||
|
SetupDebuggingTraps();
|
||
|
return 1;
|
||
|
} else {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static int special_plugin_debug(unsigned char flag, char *) {
|
||
|
if (flag) {
|
||
|
clState.pluginDebug = 1;
|
||
|
return 1;
|
||
|
} else {
|
||
|
return clState.pluginDebug;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static int special_stdout_base(unsigned char flag, char *) {
|
||
|
if (flag) {
|
||
|
return 1;
|
||
|
} else {
|
||
|
return clState.stdoutBase != 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
struct SpecialOption {
|
||
|
const char *name;
|
||
|
char **location;
|
||
|
int (*callback)(unsigned char a, char *b);
|
||
|
};
|
||
|
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) {
|
||
|
int i;
|
||
|
struct SpecialOption *opt;
|
||
|
|
||
|
if (*pArgc > 1) {
|
||
|
restart:
|
||
|
for (i = 0, opt = &special_options[0]; i < 3; i++, opt++) {
|
||
|
if (!strcmp(opt->name, (*pArgv)[1])) {
|
||
|
if (opt->location) {
|
||
|
*opt->location = (*pArgv)[2];
|
||
|
opt->callback(1, *opt->location);
|
||
|
(*pArgv)[1] = (*pArgv)[0];
|
||
|
(*pArgc)--;
|
||
|
(*pArgv)++;
|
||
|
|
||
|
(*pArgv)[1] = (*pArgv)[0];
|
||
|
(*pArgc)--;
|
||
|
(*pArgv)++;
|
||
|
} else {
|
||
|
opt->callback(1, 0);
|
||
|
(*pArgv)[1] = (*pArgv)[0];
|
||
|
(*pArgc)--;
|
||
|
(*pArgv)++;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ((*pArgc) > 1 && i < 3)
|
||
|
goto restart;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Main_PassSpecialArgs(void *unk1, void *unk2) {
|
||
|
int i;
|
||
|
struct SpecialOption *opt;
|
||
|
|
||
|
for (i = 0; i < 3; i++) {
|
||
|
opt = &special_options[i];
|
||
|
if (opt->callback(0, 0)) {
|
||
|
AppendArgumentList(unk1, unk2, opt->name);
|
||
|
if (opt->location)
|
||
|
AppendArgumentList(unk1, unk2, (*opt->location) ? *opt->location : "");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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];
|
||
|
char buf[256];
|
||
|
|
||
|
OS_InitProgram(&argc, &argv);
|
||
|
memset(&clState, 0, sizeof(CLState));
|
||
|
special_options[0].name = secret;
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
int Main_Terminate(int code) {
|
||
|
if (MainInitialized) {
|
||
|
Plugins_Term();
|
||
|
License_Terminate();
|
||
|
Proj_Terminate(gProj);
|
||
|
IO_Terminate();
|
||
|
MainInitialized = 0;
|
||
|
}
|
||
|
return code;
|
||
|
}
|
||
|
|
||
|
static int Main_ParseCommandLine() {
|
||
|
// TODO: clState, Plugins, gTarg, ...
|
||
|
}
|
||
|
|
||
|
static int Main_SetupParamBlock() {
|
||
|
// TODO: OS, PrefPanes, clState, ...
|
||
|
PrefPanelsChangedCallback(0);
|
||
|
}
|
||
|
|
||
|
static int Main_ResolveProject() {
|
||
|
// TODO: Various project things
|
||
|
}
|
||
|
|
||
|
static int UpdatePCmdLineFromVersion(const PCmdLine *oldVer, PCmdLine *newVer) {
|
||
|
static unsigned char warned;
|
||
|
short ver = oldVer->version;
|
||
|
*newVer = *oldVer;
|
||
|
|
||
|
// TODO: clState
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
static int UpdatePCmdLineEnvirFromVersion(const PCmdLineEnvir *oldVer, PCmdLineEnvir *newVer) {
|
||
|
static unsigned char warned;
|
||
|
short ver = oldVer->version;
|
||
|
*newVer = *oldVer;
|
||
|
|
||
|
// TODO: clState
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
static int UpdatePCmdLineCompilerFromVersion(const PCmdLineCompiler *oldVer, PCmdLineCompiler *newVer) {
|
||
|
static unsigned char warned;
|
||
|
short ver = oldVer->version;
|
||
|
*newVer = *oldVer;
|
||
|
|
||
|
// TODO: clState
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
static int UpdatePCmdLineLinkerFromVersion(const PCmdLineLinker *oldVer, PCmdLineLinker *newVer) {
|
||
|
static unsigned char warned;
|
||
|
short ver = oldVer->version;
|
||
|
*newVer = *oldVer;
|
||
|
|
||
|
// TODO: clState
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
static int UpdatePrefPanels(const char *name) {
|
||
|
PrefPanel *panel;
|
||
|
Handle handle;
|
||
|
|
||
|
if (!name || !ustrcmp(name, "CmdLine Panel")) {
|
||
|
if ((panel = Prefs_FindPanel("CmdLine Panel")) && (handle = PrefPanel_GetHandle(panel))) {
|
||
|
if (name) {
|
||
|
if (!UpdatePCmdLineFromVersion((PCmdLine *) *handle, &optsCmdLine))
|
||
|
return 0;
|
||
|
}
|
||
|
} else {
|
||
|
CLReportError(91, "CmdLine Panel");
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!name || !ustrcmp(name, "CmdLine Environment")) {
|
||
|
if ((panel = Prefs_FindPanel("CmdLine Environment")) && (handle = PrefPanel_GetHandle(panel))) {
|
||
|
if (name) {
|
||
|
if (!UpdatePCmdLineEnvirFromVersion((PCmdLineEnvir *) *handle, &optsEnvir))
|
||
|
return 0;
|
||
|
}
|
||
|
} else {
|
||
|
CLReportError(91, "CmdLine Environment");
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!name || !ustrcmp(name, "CmdLine Compiler Panel")) {
|
||
|
if ((panel = Prefs_FindPanel("CmdLine Compiler Panel")) && (handle = PrefPanel_GetHandle(panel))) {
|
||
|
if (name) {
|
||
|
if (!UpdatePCmdLineCompilerFromVersion((PCmdLineCompiler *) *handle, &optsCompiler))
|
||
|
return 0;
|
||
|
}
|
||
|
} else {
|
||
|
CLReportError(91, "CmdLine Compiler Panel");
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!name || !ustrcmp(name, "CmdLine Linker Panel")) {
|
||
|
if ((panel = Prefs_FindPanel("CmdLine Linker Panel")) && (handle = PrefPanel_GetHandle(panel))) {
|
||
|
if (name) {
|
||
|
if (!UpdatePCmdLineLinkerFromVersion((PCmdLineLinker *) *handle, &optsLinker))
|
||
|
return 0;
|
||
|
}
|
||
|
} else {
|
||
|
CLReportError(91, "CmdLine Linker Panel");
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
static int SetupCmdLinePrefPanels() {
|
||
|
int result;
|
||
|
|
||
|
PrefPanelsChangedCallback = UpdatePrefPanels;
|
||
|
result = Prefs_AddPanel(
|
||
|
PrefPanel_New("CmdLine Environment", &optsEnvir, sizeof(PCmdLineEnvir))
|
||
|
);
|
||
|
result |= (
|
||
|
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)))
|
||
|
);
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|