finish CLMain.c

This commit is contained in:
Ash Wolf 2022-10-13 17:56:43 +01:00
parent 59a724bd4c
commit b8df05413a
12 changed files with 518 additions and 615 deletions

View File

@ -1,390 +0,0 @@
#include "UCWInterface.h"
static short CLT_dummymain(void *context) {
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);
}
// TODO do me later - this comes from CmdLine/Project/Resources/CLErrors.r
const char *STR12000[100];
static int RegisterCmdLineResources() {
return RegisterResource("Command-line strings", 12000, &STR12000);
}
static int special_debug(unsigned char pre, char *) {
if (pre) {
SetupDebuggingTraps();
return 1;
} else {
return 0;
}
}
static int special_plugin_debug(unsigned char pre, char *) {
if (pre) {
clState.pluginDebug = 1;
return 1;
} else {
return clState.pluginDebug;
}
}
static int special_stdout_base(unsigned char pre, char *) {
if (pre) {
return 1;
} else {
return clState.stdoutBase != 0;
}
}
struct SpecialOption {
const char *optname;
char **argp;
int (*func)(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) {
struct SpecialOption *so;
int idx;
if (*pArgc > 1) {
restart:
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);
(*pArgv)[1] = (*pArgv)[0];
(*pArgc)--;
(*pArgv)++;
(*pArgv)[1] = (*pArgv)[0];
(*pArgc)--;
(*pArgv)++;
} else {
so->func(1, 0);
(*pArgv)[1] = (*pArgv)[0];
(*pArgc)--;
(*pArgv)++;
}
break;
}
}
if ((*pArgc) > 1 && idx < 3)
goto restart;
}
}
void Main_PassSpecialArgs(void *unk1, void *unk2) {
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 : "");
}
}
}
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 exename[256];
OS_InitProgram(&argc, &argv);
memset(&clState, 0, sizeof(CLState));
special_options[0].optname = 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 exitcode) {
if (MainInitialized) {
Plugins_Term();
License_Terminate();
Proj_Terminate(gProj);
IO_Terminate();
MainInitialized = 0;
}
return exitcode;
}
static int Main_ParseCommandLine() {
// TODO: clState, Plugins, gTarg, ...
long vislang;
int x, y;
CWCommandLineArgs myargs;
}
static int Main_SetupParamBlock() {
// TODO: OS, PrefPanes, clState, ...
PrefPanelsChangedCallback(0);
}
static int Main_ResolveProject() {
// TODO: Various project things
int err;
long startTime, endTime;
}
static int UpdatePCmdLineFromVersion(const PCmdLine *given, PCmdLine *target) {
static unsigned char warned;
short version = given->version;
*target = *given;
// TODO: clState
return 0;
}
static int UpdatePCmdLineEnvirFromVersion(const PCmdLineEnvir *given, PCmdLineEnvir *target) {
static unsigned char warned;
short version = given->version;
*target = *given;
// TODO: clState
return 0;
}
static int UpdatePCmdLineCompilerFromVersion(const PCmdLineCompiler *given, PCmdLineCompiler *target) {
static unsigned char warned;
short version = given->version;
*target = *given;
// TODO: clState
return 0;
}
static int UpdatePCmdLineLinkerFromVersion(const PCmdLineLinker *given, PCmdLineLinker *target) {
static unsigned char warned;
short version = given->version;
*target = *given;
// TODO: clState
return 0;
}
static int UpdatePrefPanels(const char *name) {
PrefPanel *panel;
Handle h;
if (!name || !ustrcmp(name, "CmdLine Panel")) {
if ((panel = Prefs_FindPanel("CmdLine Panel")) && (h = PrefPanel_GetHandle(panel))) {
if (name) {
if (!UpdatePCmdLineFromVersion((PCmdLine *) *h, &optsCmdLine))
return 0;
}
} else {
CLReportError(91, "CmdLine Panel");
return 0;
}
}
if (!name || !ustrcmp(name, "CmdLine Environment")) {
if ((panel = Prefs_FindPanel("CmdLine Environment")) && (h = PrefPanel_GetHandle(panel))) {
if (name) {
if (!UpdatePCmdLineEnvirFromVersion((PCmdLineEnvir *) *h, &optsEnvir))
return 0;
}
} else {
CLReportError(91, "CmdLine Environment");
return 0;
}
}
if (!name || !ustrcmp(name, "CmdLine Compiler Panel")) {
if ((panel = Prefs_FindPanel("CmdLine Compiler Panel")) && (h = PrefPanel_GetHandle(panel))) {
if (name) {
if (!UpdatePCmdLineCompilerFromVersion((PCmdLineCompiler *) *h, &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")) && (h = PrefPanel_GetHandle(panel))) {
if (name) {
if (!UpdatePCmdLineLinkerFromVersion((PCmdLineLinker *) *h, &optsLinker))
return 0;
}
} else {
CLReportError(91, "CmdLine Linker Panel");
return 0;
}
}
return 1;
}
static int SetupCmdLinePrefPanels() {
int ret;
PrefPanelsChangedCallback = UpdatePrefPanels;
ret = Prefs_AddPanel(
PrefPanel_New("CmdLine Environment", &optsEnvir, sizeof(PCmdLineEnvir))
);
ret |= (
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 ret;
}
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;
}

102
UMain.c
View File

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

View File

@ -0,0 +1,109 @@
static const char *STR12000[112] = {
"Could not get current working directory",
"Cannot find my executable '%s'",
"Could not initialize plugin '%s'",
"The %s '%s' requires functionality not present in the command-line driver.",
"The command-line parser does not support these panels:",
"\t%s\n",
"Compiling function: '%s'",
"Could not write file '%s'",
"Could not write file '%s' in directory '%s'",
"Write error on output (errno=%ld)",
"Current working directory is too long",
"Unknown filetype '%c%c%c%c', defaulting to '%s'",
"%s:\ttype %s",
"Storing output for '%s' in '%s'",
"Writing text file '%s'",
"Writing %sobject file '%s'",
"Writing browse data '%s'",
"Could not write %s '%s' (error %ld)",
"Deleting temporary file '%s'",
"Could not resolve alias for '%s' (error %ld)",
"%s:\t'%s'%s",
"File '%s' has browse fileID %d",
"Can't locate directory '%s'",
" %8.2f seconds to %s %s%s%s",
" %8d lines compiled",
" %8d %s code\n %8d %s init'd data\n %8d %s uninit'd data",
" %8d total %s code\n %8d total %s init'd data\n %8d total %s uninit'd data",
"File '%s' is not compilable source, target object data, or command file; ignoring",
"All specified files were ignored",
"Compiling: '%s'",
"Compiling: '%s' with '%s'",
"Precompiling: '%s'",
"Precompiling: '%s' with '%s'",
"Preprocessing: '%s'",
"Preprocessing: '%s' with '%s'",
"Finding dependencies: '%s'",
"Finding dependencies: '%s' with '%s'",
"Importing: '%s'",
"Importing: '%s' with '%s'",
"Linking project",
"Linking project with '%s'",
"Pre-linking project",
"Pre-linking project with '%s'",
"Post-linking project",
"Post-linking project with '%s'",
"Disassembling: '%s'",
"Disassembling: '%s' with '%s'",
"Syntax checking: '%s'",
"Syntax checking: '%s' with '%s'",
"Getting target info from '%s'",
"Initializing '%s'",
"Terminating '%s'",
"'%s' cannot preprocess, skipping '%s'",
"'%s' cannot precompile, skipping '%s'",
"'%s' cannot generate code, skipping '%s'",
"'%s' has no object code to disassemble",
"'%s' cannot disassemble, skipping '%s'",
"Neither '%s' nor '%s' can disassemble, skipping '%s'",
"No precompiled header name given, '%s' assumed",
"Precompile target '%s' given on command line; source-specified name '%s' ignored",
"Writing precompiled %s file '%s'",
"Reading precompiled %s file '%s'",
"Cannot %s memory for %s",
"Files/directories must have length <= %ld characters;\n'%s' not accepted",
"Guessed linker name '%s' from compiler name '%s'",
"Can't find %s '%s' in path",
"Calling %s '%s'",
"Can't execute %s '%s' (%s)",
"%s '%s' returned with exit code %d",
"Too many errors printed, aborting program",
"Too many errors printed, suppressing errors for current file",
"Too many warnings printed, suppressing warnings for current file",
"No %s mapping matches '%s' (unrecognized file contents or filename extension); %s",
"No plugin or target matches the file '%s', ignoring",
"File '%s' cannot be handled by this tool, ignoring",
"File '%s' does not match the active target",
"Adding%s:\t'%s'",
"Creating new overlay '%s' in group '%s'",
"Creating new overlay group '%s' at addr %08X:%08X",
"File '%s' cannot be added to overlay group; define an overlay in the group first",
"Cannot create virtual export file '%s' (from '-export name,...')",
"Too many %s defined; at most %d%s is allowed",
"Loading preference panel '%s'",
"%s:",
"\t%s%s",
"Already defined %s search path; '%s' added after other paths",
"License check failed: %s",
"The plugin '%s' (version '%s') cannot be used:\n%s",
"Plugin '%s' has already been registered",
"Preferences for '%s' have already been registered",
"Preferences for '%s' not found",
"Some preferences needed by the plugin '%s' have not been registered",
"Could not load file '%s'",
"Could not find change current working directory to '%s'",
"Out of memory",
"The tool did not produce any output while %s the file '%s'",
"The filename '%s' is invalid",
"The %slinker for this target was not found",
"%s\n%s (OS error %d)",
"%s\n%s (error %d)",
"Note: '%s' did not generate any browse information \nfor '%s'; no browser output generated",
"Source and specified output for the file '%s' are identical; no output will be generated",
"More than one output filename specified for '%s'; ignoring '%s'",
"Pref panel data for '%s' is out-of-date or invalid",
"Changing primary user access path to '%s'",
"The linker does not expect duplicate files; ignoring repeated '%s'",
""
};

View File

@ -1,10 +1,28 @@
#include "mwcc_decomp.h"
static short CLT_dummymain(void *context) {
jmp_buf exit_program;
int numPlugins;
CLPluginInfo *pluginInfo;
int numPanels;
char **panelNames;
CWCommandLineArgs *panel_args;
CWCommandLineArgs *plugin_args;
Project mainProj;
Target *gTarg;
PCmdLine optsCmdLine;
PCmdLineEnvir optsEnvir;
PCmdLineCompiler optsCompiler;
PCmdLineLinker optsLinker;
CLState clState;
char cmdline_build_date[32];
char cmdline_build_time[32];
Project *gProj = &mainProj;
static SInt16 CLT_dummymain(void *context) {
return 0;
}
static short CLT_GetDropInFlags(const DropInFlags **flags, long *flagsSize) {
static SInt16 CLT_GetDropInFlags(const DropInFlags **flags, SInt32 *flagsSize) {
static const DropInFlags sFlags = {
kCurrentDropInFlagsVersion,
CWFOURCHAR('c','l','d','r'),
@ -18,19 +36,19 @@ static short CLT_GetDropInFlags(const DropInFlags **flags, long *flagsSize) {
return 0;
}
static short CLT_GetDropInName(const char **dropinName) {
static SInt16 CLT_GetDropInName(const char **dropinName) {
static const char *sDropInName = "Command-Line Driver";
*dropinName = sDropInName;
return 0;
}
static short CLT_GetDisplayName(const char **displayName) {
static SInt16 CLT_GetDisplayName(const char **displayName) {
static const char *sDisplayName = "Command-Line Driver";
*displayName = sDisplayName;
return 0;
}
static short CLT_GetPanelList(const CWPanelList **panelList) {
static SInt16 CLT_GetPanelList(const CWPanelList **panelList) {
static const char *sPanelNames[4];
static CWPanelList sPanelList = {
kCurrentCWPanelListVersion,
@ -38,12 +56,13 @@ static short CLT_GetPanelList(const CWPanelList **panelList) {
sPanelNames
};
sPanelNames[0] = "CmdLine Panel";
if (clState.plugintype == CWDROPINCOMPILERTYPE) {
sPanelNames[0] = "CmdLine Panel";
sPanelNames[1] = "CmdLine Compiler Panel";
sPanelNames[2] = "CmdLine Linker Panel";
sPanelList.count = 3;
} else {
sPanelNames[0] = "CmdLine Panel";
sPanelNames[1] = "CmdLine Linker Panel";
sPanelList.count = 2;
}
@ -51,9 +70,9 @@ static short CLT_GetPanelList(const CWPanelList **panelList) {
return 0;
}
static short CLT_GetTargetList(const CWTargetList **targetList) {
static CWDataType sCPU = CWFOURCHAR('*','*','*','*');
static CWDataType sOS = CWFOURCHAR('*','*','*','*');
static SInt16 CLT_GetTargetList(const CWTargetList **targetList) {
static FourCharCode sCPU = CWFOURCHAR('*','*','*','*');
static FourCharCode sOS = CWFOURCHAR('*','*','*','*');
static CWTargetList sTargetList = {
kCurrentCWTargetListVersion,
1,
@ -65,7 +84,7 @@ static short CLT_GetTargetList(const CWTargetList **targetList) {
return 0;
}
static short CLT_GetVersionInfo(const VersionInfo **versioninfo) {
static SInt16 CLT_GetVersionInfo(const VersionInfo **versioninfo) {
static const VersionInfo vi = {
3, 0, 0, 0
};
@ -73,7 +92,7 @@ static short CLT_GetVersionInfo(const VersionInfo **versioninfo) {
return 0;
}
static short CLT_GetFileTypeMappings(const OSFileTypeMappingList **mappinglist) {
static SInt16 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}
@ -102,14 +121,13 @@ static int RegisterStaticCmdLinePlugin() {
return RegisterStaticPlugin(&clcb);
}
// TODO do me later - this comes from CmdLine/Project/Resources/CLErrors.r
const char *STR12000[100];
#include "command_line/CmdLine/Project/Resources/CLErrors.r"
static int RegisterCmdLineResources() {
return RegisterResource("Command-line strings", 12000, &STR12000);
return RegisterResource("Command-line strings", 12000, STR12000);
}
static int special_debug(unsigned char pre, char *) {
static Boolean special_debug(Boolean pre, char *) {
if (pre) {
SetupDebuggingTraps();
return 1;
@ -118,7 +136,7 @@ static int special_debug(unsigned char pre, char *) {
}
}
static int special_plugin_debug(unsigned char pre, char *) {
static Boolean special_plugin_debug(Boolean pre, char *) {
if (pre) {
clState.pluginDebug = 1;
return 1;
@ -127,80 +145,82 @@ static int special_plugin_debug(unsigned char pre, char *) {
}
}
static int special_stdout_base(unsigned char pre, char *) {
static Boolean special_stdout_base(Boolean pre, char *) {
if (pre) {
return 1;
} else {
return clState.stdoutBase != 0;
return clState.stdout_base != 0;
}
}
struct SpecialOption {
const char *optname;
char **argp;
int (*func)(unsigned char a, char *b);
Boolean (*func)(Boolean 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}
{"--stdout", &clState.stdout_base, special_stdout_base}
};
void Main_PreParse(int *pArgc, char ***pArgv) {
struct SpecialOption *so;
void Main_PreParse(int *argc, char ***argv) {
int idx;
struct SpecialOption *so;
if (*pArgc > 1) {
restart:
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);
(*pArgv)[1] = (*pArgv)[0];
(*pArgc)--;
(*pArgv)++;
if (*argc > 1) {
do {
idx = 0;
so = special_options;
(*pArgv)[1] = (*pArgv)[0];
(*pArgc)--;
(*pArgv)++;
} else {
so->func(1, 0);
(*pArgv)[1] = (*pArgv)[0];
(*pArgc)--;
(*pArgv)++;
do {
if (!strcmp(so->optname, (*argv)[1])) {
if (so->argp) {
*so->argp = (*argv)[2];
so->func(1, *so->argp);
(*argv)[1] = (*argv)[0];
(*argc)--;
(*argv)++;
(*argv)[1] = (*argv)[0];
(*argc)--;
(*argv)++;
} else {
so->func(1, 0);
(*argv)[1] = (*argv)[0];
(*argc)--;
(*argv)++;
}
break;
}
break;
}
}
if ((*pArgc) > 1 && idx < 3)
goto restart;
idx++;
so++;
} while (idx < 3);
} while (*argc > 1 && idx < 3);
}
}
void Main_PassSpecialArgs(void *unk1, void *unk2) {
struct SpecialOption *so;
void Main_PassSpecialArgs(int *argc, char ***argv) {
int idx;
struct SpecialOption *so;
for (idx = 0; idx < 3; idx++) {
so = &special_options[idx];
idx = 0;
so = special_options;
do {
if (so->func(0, 0)) {
AppendArgumentList(unk1, unk2, so->optname);
AppendArgumentList(argc, argv, so->optname);
if (so->argp)
AppendArgumentList(unk1, unk2, (*so->argp) ? *so->argp : "");
AppendArgumentList(argc, argv, (*so->argp) ? *so->argp : "");
}
}
idx++;
so++;
} while (idx < 3);
}
static int MainInitialized;
void *gProj;
PCmdLine optsCmdLine;
PCmdLineEnvir optsEnvir;
PCmdLineCompiler optsCompiler;
PCmdLineLinker optsLinker;
int Main_Initialize(int argc, const char **argv) {
int Main_Initialize(int argc, char **argv) {
static char secret[8];
char exename[256];
@ -219,7 +239,29 @@ int Main_Initialize(int argc, const char **argv) {
Main_PreParse(&argc, &argv);
clState.argc = argc;
clState.argv = argv;
// TODO more shite
strcpyn(exename, argv[0], strlen(argv[0]), 256);
exename[255] = 0;
IO_Initialize();
if (!RegisterCmdLineResources())
CLFatalError("Could not initialize resource strings");
if (!OS_IsFullPath(argv[0])) {
clState.programName = argv[0];
} else {
clState.programName = OS_GetFileNamePtr(argv[0]);
}
if (OS_FindProgram(exename, &clState.programSpec))
CLReportError(2, exename);
Plugins_Init();
if (!RegisterStaticCmdLinePlugin())
CLFatalError("Could not initialize built-in plugins");
Proj_Initialize(gProj);
SystemInitResources(&clState.programSpec);
License_Initialize();
MainInitialized = 1;
return 0;
@ -236,58 +278,239 @@ int Main_Terminate(int exitcode) {
return exitcode;
}
enum {
ResultCode_0 = 0,
ResultCode_1 = 1,
ResultCode_2 = 2
};
static int Main_ParseCommandLine() {
// TODO: clState, Plugins, gTarg, ...
long vislang;
int x, y;
Plugin *parser;
CWCommandLineArgs myargs;
int x, y;
FourCharCode vislang;
if (
!Plugins_GetPluginList(0, &numPlugins, &pluginInfo)
|| !Plugins_GetPrefPanelUnion(0, &numPanels, &panelNames)
|| !(panel_args = xcalloc(0, numPanels * sizeof(CWCommandLineArgs)))
|| !(plugin_args = xcalloc(0, numPlugins * sizeof(CWCommandLineArgs)))
) {
CLFatalError("Out of memory during init\n");
}
parser = Plugins_GetParserForPlugin(0, clState.parserstyle, numPlugins, pluginInfo, gTarg->cpu, gTarg->os, numPanels, panelNames);
if (!parser)
CLFatalError("Could not find a command-line parser!");
myargs.argc = clState.argc;
myargs.argv = clState.argv;
myargs.envp = 0;
if (!SendParserRequest(parser, gTarg, &myargs, gTarg->cpu, gTarg->os, numPlugins, pluginInfo, numPanels, panelNames, plugin_args, panel_args, cmdline_build_date, cmdline_build_time, Plugin_GetToolVersionInfo())) {
return CheckForUserBreak() ? ResultCode_2 : ResultCode_1;
}
if (clState.pluginDebug) {
for (y = 0; y < numPanels; y++) {
CLPrintErr("Outgoing args for '%s': ", panelNames[y]);
for (x = 0; x < panel_args[y].argc; x++) {
CLPrintErr("%s ", panel_args[y].argv[x]);
}
CLPrintErr("\n");
}
for (x = 0; x < numPlugins; x++) {
vislang = pluginInfo[x].language ? pluginInfo[x].language : CWFOURCHAR('-','-','-','-');
CLPrintErr(
"Outgoing args for '%c%c%c%c/%c%c%c%c': ",
(pluginInfo[x].plugintype & 0xFF000000) >> 24,
(pluginInfo[x].plugintype & 0x00FF0000) >> 16,
(pluginInfo[x].plugintype & 0x0000FF00) >> 8,
(pluginInfo[x].plugintype & 0x000000FF),
(vislang & 0xFF000000) >> 24,
(vislang & 0x00FF0000) >> 16,
(vislang & 0x0000FF00) >> 8,
(vislang & 0x000000FF)
);
for (y = 1; y < plugin_args[x].argc; y++) {
CLPrintErr("%s ", plugin_args[x].argv[y]);
}
CLPrintErr("\n");
}
}
return ResultCode_0;
}
static int Main_SetupParamBlock() {
// TODO: OS, PrefPanes, clState, ...
PrefPanelsChangedCallback(0);
if (optsCompiler.outMakefile[0]) {
int err = OS_MakeFileSpec(optsCompiler.outMakefile, &clState.makefileSpec);
if (err) {
CLReportOSError(8, err, optsCompiler.outMakefile);
return 1;
}
OS_Delete(&clState.makefileSpec);
}
if (optsCompiler.sbmPath[0]) {
int err = OS_MakePathSpec(0, optsCompiler.sbmPath, &clState.sbmPathSpec);
if (err) {
CLReportOSError(23, err, optsCompiler.sbmPath);
return 1;
}
} else {
OS_GetCWD(&clState.sbmPathSpec);
}
return 0;
}
static int Main_ResolveProject() {
// TODO: Various project things
SInt32 startTime;
SInt32 endTime;
int err;
long startTime, endTime;
}
static int UpdatePCmdLineFromVersion(const PCmdLine *given, PCmdLine *target) {
static unsigned char warned;
short version = given->version;
*target = *given;
if (optsCmdLine.state == OptsCmdLineState_0 || optsCmdLine.state == OptsCmdLineState_1)
return 0;
startTime = LMGetTicks();
err = CompileFilesInProject();
if (err)
return err;
if (optsCmdLine.state == OptsCmdLineState_3) {
err = LinkProject();
if (err)
return err;
}
if (!DeleteTemporaries())
return 1;
endTime = LMGetTicks();
if (optsCmdLine.timeWorking) {
CLReport(24, (endTime - startTime) / 60.0, "resolve", "", "project", "");
}
// TODO: clState
return 0;
}
static int UpdatePCmdLineEnvirFromVersion(const PCmdLineEnvir *given, PCmdLineEnvir *target) {
static unsigned char warned;
short version = given->version;
static int UpdatePCmdLineFromVersion(PCmdLine *given, PCmdLine *target) {
static Boolean warned;
SInt16 version = given->version;
*target = *given;
// TODO: clState
return 0;
if (clState.pluginDebug && version < 0x1002 && !warned) {
CLReportWarning(104, "CmdLine Panel");
warned = 1;
}
if (version == 0x1000) {
target->stderr2stdout = 0;
version++;
}
if (version == 0x1001) {
target->noCmdLineWarnings = 0;
version++;
}
if (version < 0x1000 || version > 0x1002) {
CLReportError(104, "CmdLine Panel");
return 0;
} else {
target->version = 0x1002;
return 1;
}
}
static int UpdatePCmdLineCompilerFromVersion(const PCmdLineCompiler *given, PCmdLineCompiler *target) {
static unsigned char warned;
short version = given->version;
static int UpdatePCmdLineEnvirFromVersion(PCmdLineEnvir *given, PCmdLineEnvir *target) {
SInt16 version = given->version;
*target = *given;
// TODO: clState
return 0;
if ((clState.pluginDebug && version < 0x1000) || version > 0x1000) {
CLReportError(104, "CmdLine Environment");
return 0;
} else {
target->version = 0x1000;
return 1;
}
}
static int UpdatePCmdLineLinkerFromVersion(const PCmdLineLinker *given, PCmdLineLinker *target) {
static unsigned char warned;
short version = given->version;
static int UpdatePCmdLineCompilerFromVersion(PCmdLineCompiler *given, PCmdLineCompiler *target) {
static Boolean warned;
SInt16 version = given->version;
*target = *given;
// TODO: clState
return 0;
if (clState.pluginDebug && version < 0x1005 && !warned) {
CLReportWarning(104, "CmdLine Compiler Panel");
warned = 1;
}
if (version == 0x1001) {
target->ignoreMissingFiles = 0;
target->printHeaderNames = 0;
version++;
}
if (version == 0x1002) {
target->sbmState = 0;
target->sbmPath[0] = 0;
version++;
}
if (version == 0x1003) {
target->canonicalIncludes = 0;
version++;
}
if (version == 0x1004) {
target->keepObjects = 0;
version++;
}
if (version <= 0x1000 || version > 0x1005) {
CLReportError(104, "CmdLine Compiler Panel");
return 0;
} else {
target->version = 0x1005;
return 1;
}
}
static int UpdatePCmdLineLinkerFromVersion(PCmdLineLinker *given, PCmdLineLinker *target) {
static Boolean warned;
SInt16 version = given->version;
*target = *given;
if (clState.pluginDebug && version < 0x1002 && !warned) {
CLReportWarning(104, "CmdLine Linker Panel");
warned = 1;
}
if (version == 0x1000) {
target->callPreLinker = 1;
target->callPostLinker = 1;
target->keepLinkerOutput = 1;
version++;
}
if (version == 0x1001) {
target->callLinker = 1;
version++;
}
if (version < 0x1000 || version > 0x1002) {
CLReportError(104, "CmdLine Linker Panel");
return 0;
} else {
target->version = 0x1002;
return 1;
}
}
static int UpdatePrefPanels(const char *name) {
@ -362,12 +585,49 @@ static int SetupCmdLinePrefPanels() {
}
static int Main_SetupContext() {
// TODO Target, Plugins, clState
gTarg = Target_New("default", clState.cpu, clState.os, clState.language);
Target_Add(&gProj->targets, gTarg);
Plugins_AddFileTypeMappingsForTarget(0, 0, gTarg->cpu, gTarg->os);
gTarg->linker = Plugins_GetLinker(0, gTarg->cpu, gTarg->os);
if (gTarg->linker) {
gTarg->linkerDropinFlags = Plugin_GetDropInFlags(gTarg->linker)->dropinflags;
} else {
if (Plugins_GetLinker(0, CWFOURCHAR('*','*','*','*'), CWFOURCHAR('*','*','*','*')))
CLFatalError("A linker is compiled in, but does not match the static target!\n");
gTarg->linkerDropinFlags = 0;
}
gTarg->preLinker = Plugins_GetPreLinker(0, gTarg->cpu, gTarg->os);
if (gTarg->preLinker) {
gTarg->preLinkerDropinFlags = Plugin_GetDropInFlags(gTarg->preLinker)->dropinflags;
} else {
if (Plugins_GetPreLinker(0, CWFOURCHAR('*','*','*','*'), CWFOURCHAR('*','*','*','*')))
CLFatalError("A pre-linker is compiled in, but does not match the static target!\n");
gTarg->preLinkerDropinFlags = 0;
}
gTarg->postLinker = Plugins_GetPostLinker(0, gTarg->cpu, gTarg->os);
if (gTarg->postLinker) {
gTarg->postLinkerDropinFlags = Plugin_GetDropInFlags(gTarg->postLinker)->dropinflags;
} else {
if (Plugins_GetPostLinker(0, CWFOURCHAR('*','*','*','*'), CWFOURCHAR('*','*','*','*')))
CLFatalError("A post-linker is compiled in, but does not match the static target!\n");
gTarg->postLinkerDropinFlags = 0;
}
if (clState.plugintype == CWDROPINLINKERTYPE) {
if (!gTarg->preLinker && !gTarg->linker && !gTarg->postLinker)
CLFatalError("The linker plugin was not found!");
}
gTarg->linkmodel = 0;
Framework_GetEnvInfo();
return 1;
}
jmp_buf exit_program;
int Main_Driver() {
volatile int result;
@ -387,4 +647,3 @@ int Main_Driver() {
return result;
}

View File

@ -1,6 +1,6 @@
#include "mwcc_decomp.h"
int RegisterResource(const char *name, SInt16 rsrcid, Handle list) {
int RegisterResource(const char *name, SInt16 rsrcid, const char **list) {
Handle h;
if (list == 0) {

View File

@ -149,15 +149,15 @@ void CLPrintType(SInt16 msgtype, ...) {
}
void CLPrint(SInt16 msgtype, ...) {
void CLPrint(const char *format, ...) {
}
void CLPrintWarning(SInt16 msgtype, ...) {
void CLPrintWarning(const char *format, ...) {
}
void CLPrintErr(SInt16 msgtype, ...) {
void CLPrintErr(const char *format, ...) {
}

View File

@ -3,7 +3,7 @@
typedef struct {
const char *name;
SInt16 rsrcid;
const char **strings;
Handle strings;
} Res;
static Res rlist[16];
@ -12,7 +12,7 @@ void Res_Initialize() {
memset(rlist, 0, sizeof(rlist));
}
int Res_AddResource(const char *name, SInt16 rsrcid, const char **strings) {
int Res_AddResource(const char *name, SInt16 rsrcid, Handle strings) {
int scan;
for (scan = 0; scan < 16 && rlist[scan].rsrcid; scan++) {

View File

@ -44,7 +44,7 @@ const char *OS_GetErrText(int err) {
}
}
int OS_InitProgram(int *pArgc, const char ***pArgv) {
int OS_InitProgram(int *pArgc, char ***pArgv) {
return 0;
}

View File

@ -4,6 +4,7 @@
* Common imports and Mac OS types
*/
#include <ctype.h>
#include <setjmp.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -146,7 +146,7 @@ extern Boolean LMGetResLoad();
/********************************/
/* ResourceStrings */
extern void Res_Initialize();
extern int Res_AddResource(const char *name, SInt16 rsrcid, const char **strings);
extern int Res_AddResource(const char *name, SInt16 rsrcid, Handle strings);
extern const char *Res_GetResource(SInt16 rsrcid, SInt16 index);
extern void Res_Cleanup();

View File

@ -268,6 +268,11 @@ enum {
#pragma options align=reset
#endif
#define CWFOURCHAR(a, b, c, d) \
(((OSType) ((a) & 0xff) << 24) \
| ((OSType) ((b) & 0xff) << 16) \
| ((OSType) ((c) & 0xff) << 8) \
| ((OSType) ((d) & 0xff)))
struct IDEAccessPath {
FSSpec pathSpec;
@ -367,6 +372,21 @@ typedef struct CWHelpInfo {
SInt16 version;
const char *helpFileName;
} CWHelpInfo;
#define kCurrentDropInFlagsVersion 2
#define kCurrentCWPanelListVersion 1
#define kCurrentCWFamilyListVersion 1
#define kCurrentCWFamilyResourceVersion 1
#define kCurrentCWHelpInfoVersion 1
#define kCurrentCWPluginInfoVersion 1
#define kCurrentCWTargetListVersion 1
#define kCurrentCWTargetListResourceVersion 1
enum {
CWDROPINCOMPILERTYPE = CWFOURCHAR('C', 'o', 'm', 'p'),
CWDROPINLINKERTYPE = CWFOURCHAR('L', 'i', 'n', 'k')
};
#ifdef __MWERKS__
#pragma options align=reset
#endif
@ -472,6 +492,12 @@ struct CWPluginPrivateContext {
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
enum {
OptsCmdLineState_0 = 0,
OptsCmdLineState_1 = 1,
OptsCmdLineState_2 = 2,
OptsCmdLineState_3 = 3
};
typedef struct PCmdLine {
SInt16 version;
SInt16 state;
@ -485,8 +511,8 @@ typedef struct PCmdLine {
Boolean timeWorking;
Boolean noWarnings;
Boolean warningsAreErrors;
Boolean maxErrors;
Boolean maxWarnings;
UInt16 maxErrors;
UInt16 maxWarnings;
SInt16 msgStyle;
Boolean noWrapOutput;
Boolean stderr2stdout;
@ -640,9 +666,6 @@ typedef struct {
Str255 mapfilename;
Str255 symfilename;
} PCLTExtras;
#ifdef __MWERKS__
#pragma options align=reset
#endif
typedef struct CWCommandLineArgs {
int argc;
@ -672,6 +695,9 @@ typedef struct ToolVersionInfo {
char *copyright;
char *version;
} ToolVersionInfo;
#ifdef __MWERKS__
#pragma options align=reset
#endif
// may not actually be named this
struct ParseOptsType {
@ -715,7 +741,7 @@ struct ParseOptsType {
typedef struct {
int argc;
const char **argv;
char **argv;
OSType cpu;
OSType os;
OSType plugintype;
@ -732,7 +758,7 @@ typedef struct {
OSSpec makefileSpec;
OSPathSpec sbmPathSpec;
OSHandle browseTableHandle;
const char *stdout_base;
char *stdout_base;
int stdout_written;
} CLState; // assumed name
@ -1028,7 +1054,7 @@ extern int main(int argc, const char **argv);
/********************************/
/* command_line/CmdLine/Src/Clients/ClientGlue.c */
extern int RegisterResource(const char *name, SInt16 rsrcid, Handle list);
extern int RegisterResource(const char *name, SInt16 rsrcid, const char **list);
extern int RegisterStaticPlugin(const BasePluginCallbacks *callbacks);
extern int RegisterStaticCompilerLinkerPlugin(const BasePluginCallbacks *callbacks, const CompilerLinkerPluginCallbacks *cl_callbacks);
extern int RegisterStaticParserPlugin(const BasePluginCallbacks *cb, const ParserPluginCallbacks *pr_callbacks);
@ -1041,9 +1067,9 @@ extern int CmdLine_Terminate(int exitcode);
/********************************/
/* command_line/CmdLine/Src/CLMain.c */
extern void Main_PreParse(int *pArgc, char ***pArgv);
extern void Main_PassSpecialArgs(void *unk1, void *unk2);
extern int Main_Initialize(int argc, const char **argv);
extern void Main_PreParse(int *argc, char ***argv);
extern void Main_PassSpecialArgs(int *argc, char ***argv);
extern int Main_Initialize(int argc, char **argv);
extern int Main_Terminate(int code);
extern int Main_Driver();
@ -1099,10 +1125,10 @@ extern Plugin *Plugins_GetPreLinker(Plugin *list, OSType cpu, OSType os);
extern Plugin *Plugins_GetPostLinker(Plugin *list, OSType cpu, OSType os);
extern Plugin *Plugins_GetParserForPlugin(Plugin *list, OSType style, int numPlugins, CLPluginInfo *plugins, OSType cpu, OSType os, int numPanels, char **panelNames);
extern Plugin *Plugins_GetCompilerForLinker(Plugin *list, Plugin *linker, OSType type, const char *ext, OSType edit);
extern Boolean Plugins_GetPluginList(Plugin *list, int *numPlugins, CLPluginInfo **pluginInfo);
extern Boolean Plugins_GetPrefPanelUnion(Plugin *list, int *numPanels, const char ***panelNames);
extern Boolean Plugin_AddFileTypeMappings(Plugin *pl, OSFileTypeMappingList *ftml);
extern Boolean Plugins_AddFileTypeMappingsForTarget(Plugin *list, OSFileTypeMappings **mlist, OSType cpu, OSType os);
extern int Plugins_GetPluginList(Plugin *list, int *numPlugins, CLPluginInfo **pluginInfo);
extern int Plugins_GetPrefPanelUnion(Plugin *list, int *numPanels, char ***panelNames);
extern int Plugin_AddFileTypeMappings(Plugin *pl, OSFileTypeMappingList *ftml);
extern int Plugins_AddFileTypeMappingsForTarget(Plugin *list, OSFileTypeMappings **mlist, OSType cpu, OSType os);
extern SInt16 Plugin_Call(Plugin *pl, void *context);
/********************************/
@ -1139,19 +1165,19 @@ extern Boolean CheckForUserBreak();
extern char *IO_FormatText(char *buffer, SInt32 size, char *newline, const char *format, ...);
extern void CLPrintDispatch(SInt16 msgtype, const char *message, FILE *out, char *ptr, char *nptr);
extern void CLPrintType(SInt16 msgtype, ...);
extern void CLPrint(SInt16 msgtype, ...);
extern void CLPrintWarning(SInt16 msgtype, ...);
extern void CLPrintErr(SInt16 msgtype, ...);
extern void CLPrint(const char *format, ...);
extern void CLPrintWarning(const char *format, ...);
extern void CLPrintErr(const char *format, ...);
extern SInt16 CLStyledMessageDispatch(Plugin *plugin, MessageRef *ref, SInt32 errorNumber, SInt16 msgType);
/********************************/
/* command_line/CmdLine/Src/CLToolExec.c */
extern void AppendArgumentList(int *argc, const char ***argv, const char *str);
extern void AppendArgumentList(int *argc, char ***argv, const char *str);
// static int CopyArgumentList(int argc, const char **argv, int *Argc, const char ***Argv);
// static int FreeArgumentList(const char **argv);
// static int SetupLinkerCommandLine(SInt32 dropinflags, File *file, CWCommandLineArgs *args);
extern int SetupTemporaries(SInt32 idx, File *file);
extern int DeleteTemporaries(SInt32 idx, File *file);
extern int SetupTemporaries();
extern int DeleteTemporaries();
extern int ExecuteLinker(Plugin *plugin, SInt32 dropinflags, File *file, char *stdoutfile, char *stderrfile);
/********************************/
@ -1183,12 +1209,12 @@ extern Boolean SendParserRequest(
int numPlugins,
CLPluginInfo *pluginInfo,
int numPanels,
const char **panelNames,
char **panelNames,
CWCommandLineArgs *plugin_args,
CWCommandLineArgs *panel_args,
const char *build_date,
const char *build_time,
ToolVersionInfo *build_tool
const ToolVersionInfo *build_tool
);
extern Boolean SendCompilerRequest(Plugin *plugin, File *file, SInt16 stage);
extern Boolean SendTargetInfoRequest(Target *targ, Plugin *linker, SInt32 dropinflags);

View File

@ -101,7 +101,7 @@ extern int OS_AppendHandle(OSHandle *hand, const void *data, UInt32 len);
/* Platform-Specific */
extern uOSTypePair OS_TEXTTYPE;
extern const char *OS_GetErrText(int err);
extern int OS_InitProgram(int *pArgc, const char ***pArgv);
extern int OS_InitProgram(int *pArgc, char ***pArgv);
extern int OS_TermProgram();
extern int OS_Create(const OSSpec *spec, const uOSTypePair *type);
extern int OS_Status(const OSSpec *spec);