summaryrefslogtreecommitdiff
path: root/command_line/CmdLine
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2022-10-11 03:18:42 +0100
committerAsh Wolf <ninji@wuffs.org>2022-10-11 03:18:42 +0100
commit26b57fbea1a969ef6405365ff78391e9d3605621 (patch)
treeb6f14f5c083d0fbb42c5495eea7c74099ff45315 /command_line/CmdLine
parent7d4bee5f8f28b72610c8518e5cb9dc145c68b816 (diff)
downloadMWCC-26b57fbea1a969ef6405365ff78391e9d3605621.tar.gz
MWCC-26b57fbea1a969ef6405365ff78391e9d3605621.zip
add cmakelists for CLion, tons and tons of reorganisation using new info from the Pro8 compiler
Diffstat (limited to 'command_line/CmdLine')
-rw-r--r--command_line/CmdLine/Src/CLBrowser.c0
-rw-r--r--command_line/CmdLine/Src/CLDependencies.c0
-rw-r--r--command_line/CmdLine/Src/CLFileOps.c0
-rw-r--r--command_line/CmdLine/Src/CLIncludeFileCache.c0
-rw-r--r--command_line/CmdLine/Src/CLLicenses.c0
-rw-r--r--command_line/CmdLine/Src/CLLoadAndCache.c0
-rw-r--r--command_line/CmdLine/Src/CLMain.c390
-rw-r--r--command_line/CmdLine/Src/CLPluginAPI.c0
-rw-r--r--command_line/CmdLine/Src/CLPrefs.c0
-rw-r--r--command_line/CmdLine/Src/CLTarg.c0
-rw-r--r--command_line/CmdLine/Src/CLToolExec.c0
-rw-r--r--command_line/CmdLine/Src/CLWriteObjectFile.c0
-rw-r--r--command_line/CmdLine/Src/Callbacks/CLCompilerLinkerDropin_V10.cpp27
-rw-r--r--command_line/CmdLine/Src/Callbacks/CLDropinCallbacks_V10.cpp48
-rw-r--r--command_line/CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp13
-rw-r--r--command_line/CmdLine/Src/Clients/CLStaticMain.c45
-rw-r--r--command_line/CmdLine/Src/Clients/ClientGlue.c57
-rw-r--r--command_line/CmdLine/Src/Envir/CLErrors.c37
-rw-r--r--command_line/CmdLine/Src/Envir/CLIO.c170
-rw-r--r--command_line/CmdLine/Src/MacEmul/ErrMgr.c54
-rw-r--r--command_line/CmdLine/Src/MacEmul/Files.c149
-rw-r--r--command_line/CmdLine/Src/MacEmul/LowMem.c20
-rw-r--r--command_line/CmdLine/Src/MacEmul/Memory.c266
-rw-r--r--command_line/CmdLine/Src/MacEmul/ResourceStrings.c68
-rw-r--r--command_line/CmdLine/Src/MacEmul/Resources.c1230
-rw-r--r--command_line/CmdLine/Src/MacEmul/TextUtils.c132
-rw-r--r--command_line/CmdLine/Src/OSLib/FileHandles.c0
-rw-r--r--command_line/CmdLine/Src/OSLib/Generic.c0
-rw-r--r--command_line/CmdLine/Src/OSLib/MacFileTypes.c0
-rw-r--r--command_line/CmdLine/Src/OSLib/MacSpecs.c0
-rw-r--r--command_line/CmdLine/Src/OSLib/MemUtils.c0
-rw-r--r--command_line/CmdLine/Src/OSLib/Posix.c0
-rw-r--r--command_line/CmdLine/Src/OSLib/StringExtras.c0
-rw-r--r--command_line/CmdLine/Src/OSLib/StringUtils.c0
-rw-r--r--command_line/CmdLine/Src/Plugins/CLPlugins.c0
-rw-r--r--command_line/CmdLine/Src/Project/CLAccessPaths.c0
-rw-r--r--command_line/CmdLine/Src/Project/CLFiles.c0
-rw-r--r--command_line/CmdLine/Src/Project/CLOverlays.c0
-rw-r--r--command_line/CmdLine/Src/Project/CLProj.c0
-rw-r--r--command_line/CmdLine/Src/Project/CLSegs.c0
40 files changed, 2706 insertions, 0 deletions
diff --git a/command_line/CmdLine/Src/CLBrowser.c b/command_line/CmdLine/Src/CLBrowser.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLBrowser.c
diff --git a/command_line/CmdLine/Src/CLDependencies.c b/command_line/CmdLine/Src/CLDependencies.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLDependencies.c
diff --git a/command_line/CmdLine/Src/CLFileOps.c b/command_line/CmdLine/Src/CLFileOps.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLFileOps.c
diff --git a/command_line/CmdLine/Src/CLIncludeFileCache.c b/command_line/CmdLine/Src/CLIncludeFileCache.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLIncludeFileCache.c
diff --git a/command_line/CmdLine/Src/CLLicenses.c b/command_line/CmdLine/Src/CLLicenses.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLLicenses.c
diff --git a/command_line/CmdLine/Src/CLLoadAndCache.c b/command_line/CmdLine/Src/CLLoadAndCache.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLLoadAndCache.c
diff --git a/command_line/CmdLine/Src/CLMain.c b/command_line/CmdLine/Src/CLMain.c
new file mode 100644
index 0000000..c4d782b
--- /dev/null
+++ b/command_line/CmdLine/Src/CLMain.c
@@ -0,0 +1,390 @@
+#include "mwcc_decomp.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;
+}
+
diff --git a/command_line/CmdLine/Src/CLPluginAPI.c b/command_line/CmdLine/Src/CLPluginAPI.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLPluginAPI.c
diff --git a/command_line/CmdLine/Src/CLPrefs.c b/command_line/CmdLine/Src/CLPrefs.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLPrefs.c
diff --git a/command_line/CmdLine/Src/CLTarg.c b/command_line/CmdLine/Src/CLTarg.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLTarg.c
diff --git a/command_line/CmdLine/Src/CLToolExec.c b/command_line/CmdLine/Src/CLToolExec.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLToolExec.c
diff --git a/command_line/CmdLine/Src/CLWriteObjectFile.c b/command_line/CmdLine/Src/CLWriteObjectFile.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/CLWriteObjectFile.c
diff --git a/command_line/CmdLine/Src/Callbacks/CLCompilerLinkerDropin_V10.cpp b/command_line/CmdLine/Src/Callbacks/CLCompilerLinkerDropin_V10.cpp
new file mode 100644
index 0000000..5861e94
--- /dev/null
+++ b/command_line/CmdLine/Src/Callbacks/CLCompilerLinkerDropin_V10.cpp
@@ -0,0 +1,27 @@
+/**
+ P 1F458 | _UCBCachePrecompiledHeader
+ P 1F4F8 | _UCBLoadObjectData
+ P 1F5BC | _UCBStoreObjectData
+ P 1F860 | _UCBFreeObjectData
+ P 1F90C | _UCBDisplayLines
+ P 1F980 | _UCBBeginSubCompile
+ P 1F9F0 | _UCBEndSubCompile
+ P 1FA60 | _UCBGetPrecompiledHeaderSpec
+ P 1FD38 | _UCBGetResourceFile
+ P 1FDA8 | _UCBPutResourceFile
+ 1FE18 | _UnitNameToSBMName__FP6OSSpecP4File
+ P 1FEA0 | _UCBLookUpUnit
+ P 20544 | _UCBSBMfiles
+ P 20594 | _UCBStoreUnit
+ P 20848 | _UCBReleaseUnit
+ P 208C8 | _UCBUnitNameToFileName
+ P 20978 | _UCBOSAlert
+ P 20A50 | _UCBOSErrorMessage
+ P 20B38 | _UCBGetModifiedFiles
+ P 20BBC | _UCBGetSuggestedObjectFileSpec
+ P 20C78 | _UCBGetStoredObjectFileSpec
+ P 20D4C | _UCBGetFrameworkCount
+ P 20DB0 | _UCBGetFrameworkInfo
+ P 20E48 | ___ct__23CWCompilerLinkerContextFv
+ P 20FEC | ___dt__23CWCompilerLinkerContextFv
+*/
diff --git a/command_line/CmdLine/Src/Callbacks/CLDropinCallbacks_V10.cpp b/command_line/CmdLine/Src/Callbacks/CLDropinCallbacks_V10.cpp
new file mode 100644
index 0000000..cf6f1f7
--- /dev/null
+++ b/command_line/CmdLine/Src/Callbacks/CLDropinCallbacks_V10.cpp
@@ -0,0 +1,48 @@
+/*
+ 1B9C8 | _ANSI_To_Mac_GMT_Time__FlPUl
+ 1BA88 | _Mac_To_ANSI_Time__FUlPl
+ P 1BCA4 | _UCBGetFileInfo
+ 1BEA8 | _FindAndLoad_VirtualFile__FP22CWPluginPrivateContextPCcP10CWFileInfoP6OSSpecPUc
+ 1BF98 | _FindAndLoad_AccessPathFile__FP22CWPluginPrivateContextPCcP10CWFileInfoP6OSSpecPUc
+ 1C108 | _FindAndLoad_MissingFile__FP22CWPluginPrivateContextPCcP10CWFileInfoP6OSSpecPUc
+ P 1C278 | _UCBFindAndLoadFile
+ P 1C50C | _UCBGetFileText
+ P 1C6BC | _UCBReleaseFileText
+ P 1C754 | _UCBGetSegmentInfo
+ P 1C814 | _UCBGetOverlay1GroupInfo
+ P 1C8F0 | _UCBGetOverlay1FileInfo
+ P 1C9A0 | _UCBGetOverlay1Info
+ P 1CA74 | _UCBReportMessage
+ P 1CCDC | _UCBAlert
+ P 1CEB4 | _UCBShowStatus
+ P 1D00C | _UCBUserBreak
+ P 1D078 | _UCBGetNamedPreferences
+ P 1D13C | _UCBStorePluginData
+ P 1D1AC | _UCBGetPluginData
+ P 1D21C | _UCBSetModDate
+ P 1D35C | _UCBAddProjectEntry
+ P 1DB20 | _UCBCreateNewTextDocument
+ P 1DE74 | _UCBAllocateMemory
+ P 1DF00 | _UCBFreeMemory
+ P 1DF74 | _UCBAllocMemHandle
+ P 1E00C | _UCBFreeMemHandle
+ P 1E08C | _UCBGetMemHandleSize
+ P 1E11C | _UCBResizeMemHandle
+ P 1E1C0 | _UCBLockMemHandle
+ P 1E238 | _UCBUnlockMemHandle
+ P 1E29C | _UCBGetTargetName
+ P 1E320 | _UCBPreDialog
+ P 1E370 | _UCBPostDialog
+ P 1E3C0 | _UCBPreFileAction
+ P 1E430 | _UCBPostFileAction
+ P 1E4A0 | _UCBCacheAccessPathList
+ P 1E7A8 | _UCBSecretAttachHandle
+ P 1E814 | _UCBSecretDetachHandle
+ P 1E8A0 | _UCBSecretPeekHandle
+ P 1E92C | _UCBCheckoutLicense
+ P 1E998 | _UCBCheckinLicense
+ P 1E9E8 | _UCBResolveRelativePath
+ P 1EA28 | _UCBMacOSErrToCWResult
+ P 1EA88 | ___ct__22CWPluginPrivateContextFll
+ P 1EB10 | ___dt__22CWPluginPrivateContextFv
+ */
diff --git a/command_line/CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp b/command_line/CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp
new file mode 100644
index 0000000..5dbd4d8
--- /dev/null
+++ b/command_line/CmdLine/Src/Callbacks/CLParserCallbacks_v1.cpp
@@ -0,0 +1,13 @@
+/*
+ P 9C50 | _UCBParserAddAccessPath
+ P 9DE4 | _UCBParserSwapAccessPaths
+ P 9E90 | _UCBParserSetNamedPreferences
+ P 9F50 | _UCBParserSetFileOutputName
+ P A03C | _UCBParserSetOutputFileDirectory
+ P A110 | _UCBParserAddOverlay1Group
+ P A1EC | _UCBParserAddOverlay1
+ P A2D0 | _UCBParserAddSegment
+ P A364 | _UCBParserSetSegment
+ P A400 | ___ct__15CWParserContextFv
+ P A480 | ___dt__15CWParserContextFv
+ */ \ No newline at end of file
diff --git a/command_line/CmdLine/Src/Clients/CLStaticMain.c b/command_line/CmdLine/Src/Clients/CLStaticMain.c
new file mode 100644
index 0000000..cecab30
--- /dev/null
+++ b/command_line/CmdLine/Src/Clients/CLStaticMain.c
@@ -0,0 +1,45 @@
+#include "mwcc_decomp.h"
+
+int main(int argc, const char **argv) {
+ OSType cpu;
+ OSType os;
+ OSType lang;
+ OSType type;
+ OSType 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;
+}
diff --git a/command_line/CmdLine/Src/Clients/ClientGlue.c b/command_line/CmdLine/Src/Clients/ClientGlue.c
new file mode 100644
index 0000000..9573f51
--- /dev/null
+++ b/command_line/CmdLine/Src/Clients/ClientGlue.c
@@ -0,0 +1,57 @@
+#include "mwcc_decomp.h"
+
+int RegisterResource(const char *name, SInt16 rsrcid, Handle list) {
+ Handle h;
+
+ if (list == 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(OSType cpu, OSType os) {
+ clState.cpu = cpu;
+ clState.os = os;
+}
+
+void SetParserType(OSType plang) {
+ clState.parserstyle = plang;
+}
+
+void SetPluginType(OSType lang, OSType 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);
+}
diff --git a/command_line/CmdLine/Src/Envir/CLErrors.c b/command_line/CmdLine/Src/Envir/CLErrors.c
new file mode 100644
index 0000000..76ff06f
--- /dev/null
+++ b/command_line/CmdLine/Src/Envir/CLErrors.c
@@ -0,0 +1,37 @@
+#include "mwcc_decomp.h"
+
+static void CLGetErrorString(SInt16 errid, char *buffer) {
+
+}
+
+static void CLMessageReporter(int flags, SInt16 errid, va_list va) {
+
+}
+
+void CLReportError(SInt16 errid, ...) {
+
+}
+
+void CLReportWarning(SInt16 errid, ...) {
+
+}
+
+void CLReport(SInt16 errid, ...) {
+
+}
+
+void CLReportOSError(SInt16 errid, int err, ...) {
+
+}
+
+void CLReportCError(SInt16 errid, int err_no, ...) {
+
+}
+
+void CLInternalError(const char *file, int line, const char *format, ...) {
+
+}
+
+void CLFatalError(const char *format, ...) {
+
+}
diff --git a/command_line/CmdLine/Src/Envir/CLIO.c b/command_line/CmdLine/Src/Envir/CLIO.c
new file mode 100644
index 0000000..ac58506
--- /dev/null
+++ b/command_line/CmdLine/Src/Envir/CLIO.c
@@ -0,0 +1,170 @@
+#include "mwcc_decomp.h"
+
+static void catchinterrupt() {
+
+}
+
+static void SetupConsoleInfo() {
+
+}
+
+static void Crash() {
+
+}
+
+void SetupDebuggingTraps() {
+
+}
+
+Boolean IO_Initialize() {
+
+}
+
+Boolean IO_Terminate() {
+
+}
+
+Boolean IO_HelpInitialize() {
+
+}
+
+Boolean IO_HelpTerminate() {
+
+}
+
+static Boolean SendHandleToFile(FILE *file, OSHandle *text) {
+
+}
+
+void FixHandleForIDE(OSHandle *text) {
+
+}
+
+Boolean ShowHandle(OSHandle *text, Boolean decorate) {
+
+}
+
+Boolean WriteHandleToFile(OSSpec *spec, OSHandle *text, CWDataType creator, CWDataType type) {
+
+}
+
+Boolean WriteBinaryHandleToFile(OSSpec *spec, CWDataType maccreator, CWDataType mactype, OSHandle *text) {
+
+}
+
+Boolean AppendHandleToFile(OSSpec *spec, OSHandle *text, CWDataType maccreator, CWDataType mactype) {
+
+}
+
+void InitWorking() {
+
+}
+
+void ShowWorking() {
+
+}
+
+void TermWorking() {
+
+}
+
+static void ProgressFunction(const char *functionname) {
+
+}
+
+Boolean CheckForUserBreak() {
+
+}
+
+typedef struct {
+ char *buffer;
+ int pos;
+ int maxlen;
+ SInt16 col;
+ Boolean origina;
+ char *newline;
+} UnkCLIOStruct;
+
+static void StartLine(UnkCLIOStruct *f) {
+
+}
+
+static void WrapText(UnkCLIOStruct *f) {
+
+}
+
+static char *IO_VFormatText(char *buffer, SInt32 size, char *newline, const char *format, va_list ap) {
+
+}
+
+char *IO_FormatText(char *buffer, SInt32 size, char *newline, const char *format, ...) {
+
+}
+
+void CLPrintDispatch(SInt16 msgtype, const char *message, FILE *out, char *ptr, char *nptr) {
+
+}
+
+static void GetFileInfo(MessageRef *ref) {
+
+}
+
+static char *Arrows(MessageRef *ref) {
+
+}
+
+static Boolean IsLikelyAnImporter(Plugin *plugin) {
+
+}
+
+static char *GuessTool(Plugin *plugin) {
+
+}
+
+static char *GuessDoing(Plugin *plugin) {
+
+}
+
+static void styledMessage_MPW(Plugin *plugin, MessageRef *ref, SInt16 msgType, const char *format, va_list va) {
+
+}
+
+static void styledMessage_Default(Plugin *plugin, MessageRef *ref, SInt16 msgType, const char *format, va_list va) {
+
+}
+
+static void styledMessage_Terse(Plugin *plugin, MessageRef *ref, SInt16 msgType, const char *format, va_list va) {
+
+}
+
+static void styledMessage_IDE(Plugin *plugin, MessageRef *ref, SInt16 msgType, const char *format, va_list va) {
+
+}
+
+static void styledMessage_Parseable(Plugin *plugin, MessageRef *ref, SInt16 msgType, const char *format, va_list va) {
+
+}
+
+void CLPrintType(SInt16 msgtype, ...) {
+
+}
+
+void CLPrint(SInt16 msgtype, ...) {
+
+}
+
+void CLPrintWarning(SInt16 msgtype, ...) {
+
+}
+
+void CLPrintErr(SInt16 msgtype, ...) {
+
+}
+
+static void FixupMessageRef(MessageRef *ref) {
+
+}
+
+SInt16 CLStyledMessageDispatch(Plugin *plugin, MessageRef *ref, SInt32 errorNumber, SInt16 msgType) {
+
+}
diff --git a/command_line/CmdLine/Src/MacEmul/ErrMgr.c b/command_line/CmdLine/Src/MacEmul/ErrMgr.c
new file mode 100644
index 0000000..65bb89c
--- /dev/null
+++ b/command_line/CmdLine/Src/MacEmul/ErrMgr.c
@@ -0,0 +1,54 @@
+#include "mwcc_decomp.h"
+
+static const char *getsyserr(SInt16 msgNbr) {
+ switch (msgNbr) {
+ case 0: return "No error";
+ case -27: return "I/O call aborted by KillIO";
+ case -34: return "Disk full";
+ case -35: return "No such volume";
+ case -36: return "Input/output error";
+ case -37: return "Some component of filename is too long";
+ case -39: return "End-of-file error";
+ case -40: return "Tried to position before EOF";
+ case -42: return "Too many files open";
+ case -43: return "File or directory not found";
+ case -48: return "Filename already exists on rename or create";
+ case -50: return "Error in user parameter list";
+ case -51: return "Bad reference number";
+ case -52: return "Get file position error";
+ case -54: return "Invalid file access or invalid permissions";
+ case -61: return "Write permissions error";
+ case -108: return "Null or invalid address detected";
+ case -109: return "invalid handle detected";
+ case -113: return "Directory not found";
+ case -120: return "User cancelled";
+ case -192: return "Resource not found";
+ case -1302: return "Not a file";
+ case -1309: return "Seek position exceeds boundaries for filesystem";
+ case -1310: return "File size too big for filesystem";
+ case -188: return "Resource already in memory";
+ case -189: return "Writing past end of file";
+ case -190: return "Offset of Count out of bounds";
+ case -193: return "Resource file not found";
+ case -194: return "Could not add resource";
+ case -195: return "Could not add reference";
+ case -196: return "Could not remove resource";
+ case -197: return "Could not remove reference";
+ case -198: return "Resource attribute inconsistent with operation";
+ case -199: return "Resource map corrupted or inconsistent with operation";
+ case -32767: return "Feature not supported";
+ default: return 0;
+ }
+}
+
+char *GetSysErrText(SInt16 msgNbr, char *errMsg) {
+ const char *txt;
+
+ txt = getsyserr(msgNbr);
+ if (!txt)
+ sprintf(errMsg, "Operating system error %ld", msgNbr & 0x7FFF);
+ else
+ strcpy(errMsg, txt);
+
+ return errMsg;
+}
diff --git a/command_line/CmdLine/Src/MacEmul/Files.c b/command_line/CmdLine/Src/MacEmul/Files.c
new file mode 100644
index 0000000..7216c6b
--- /dev/null
+++ b/command_line/CmdLine/Src/MacEmul/Files.c
@@ -0,0 +1,149 @@
+#include "mwcc_decomp.h"
+
+typedef struct MacFileInfo {
+ UInt32 ioFlCrDat;
+ UInt32 ioFlMdDat;
+ SInt32 ioFlLgLen;
+ SInt32 ioFlPyLen;
+ SInt32 ioFlRLgLen;
+ SInt32 ioFlRPyLen;
+ SInt32 ioFlStBlk;
+ SInt32 ioFlRStBlk;
+ SInt32 ioFlAttrib;
+} MacFileInfo;
+
+static int OS_GetFileParamInfo(const OSSpec *spec, MacFileInfo *mfi, FInfo *fi) {
+
+}
+
+static int OS_SetFileParamInfo(const OSSpec *spec, MacFileInfo *mfi, FInfo *fi) {
+
+}
+
+OSErr HCreate(SInt16 volume, SInt32 dirid, ConstStr255Param fileName, OSType creator, OSType type) {
+
+}
+
+OSErr HOpen(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, SInt8 permission, SInt16 *refNum) {
+
+}
+
+OSErr HOpenDF(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, SInt8 permission, SInt16 *refNum) {
+
+}
+
+OSErr HDelete(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName) {
+
+}
+
+OSErr HRename(SInt16 vRefNum, SInt32 dirID, ConstStr255Param oldName, ConstStr255Param newName) {
+
+}
+
+OSErr HGetFInfo(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, FInfo *fndrInfo) {
+
+}
+
+OSErr HSetFInfo(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, const FInfo *fndrInfo) {
+
+}
+
+OSErr FSpCreate(const FSSpec *fss, OSType creator, OSType fileType, ScriptCode scriptTag) {
+
+}
+
+OSErr FSpDirCreate(const FSSpec *fss, ScriptCode scriptTag, SInt32 *createdDirID) {
+
+}
+
+OSErr FSpOpenDF(const FSSpec *fss, SInt8 permission, SInt16 *refNum) {
+
+}
+
+OSErr FSpDelete(const FSSpec *fss) {
+
+}
+
+OSErr FSpRename(const FSSpec *oldfss, ConstStr255Param newName) {
+
+}
+
+OSErr FSpGetFInfo(const FSSpec *fss, FInfo *fndrInfo) {
+
+}
+
+OSErr FSpSetFInfo(const FSSpec *fss, const FInfo *fndrInfo) {
+
+}
+
+OSErr HGetVol(StringPtr volName, SInt16 *vRefNum, SInt32 *dirID) {
+
+}
+
+OSErr HSetVol(ConstStr63Param volName, SInt16 vRefNum, SInt32 dirID) {
+
+}
+
+OSErr FlushVol(ConstStr63Param volName, SInt16 vRefNum) {
+
+}
+
+OSErr FSRead(SInt16 fRefNum, SInt32 *Size, void *Buffer) {
+
+}
+
+OSErr FSWrite(SInt16 fRefNum, SInt32 *Size, const void *Buffer) {
+
+}
+
+OSErr FSClose(SInt16 fRefNum) {
+
+}
+
+OSErr GetEOF(SInt16 fRefNum, SInt32 *curEOF) {
+
+}
+
+OSErr SetEOF(SInt16 fRefNum, SInt32 newEOF) {
+
+}
+
+OSErr GetFPos(SInt16 fRefNum, SInt32 *pos) {
+
+}
+
+OSErr SetFPos(SInt16 fRefNum, SInt16 posMode, SInt32 posOffset) {
+
+}
+
+OSErr GetVInfo(SInt16 vRefNum, StringPtr name, SInt16 *vRef, SInt32 *hDir) {
+
+}
+
+OSErr PBWriteSync(ParmBlkPtr paramBlock) {
+
+}
+
+OSErr PBHGetFInfoSync(HParmBlkPtr paramBlock) {
+
+}
+
+OSErr PBHSetFInfoSync(HParmBlkPtr paramBlock) {
+
+}
+
+OSErr PBGetCatInfoSync(CInfoPBPtr paramBlock) {
+
+}
+
+OSErr ResolveAliasFile(FSSpec *fss, Boolean resolveChains, Boolean *isFolder, Boolean *wasAliased) {
+
+}
+
+OSErr FSMakeFSSpec(SInt16 vRefNum, SInt32 dirID, ConstStr255Param pathName, FSSpec *fss) {
+
+}
+
+OSErr Allocate(SInt16 refNum, SInt32 *byteCount) {
+
+}
diff --git a/command_line/CmdLine/Src/MacEmul/LowMem.c b/command_line/CmdLine/Src/MacEmul/LowMem.c
new file mode 100644
index 0000000..7fab079
--- /dev/null
+++ b/command_line/CmdLine/Src/MacEmul/LowMem.c
@@ -0,0 +1,20 @@
+#include "mwcc_decomp.h"
+
+static OSErr memErr;
+
+UInt32 LMGetTicks() {
+ return (OS_GetMilliseconds() * 60) / 1000;
+}
+
+UInt32 LMGetTime() {
+ return OS_GetMilliseconds() / 1000;
+}
+
+OSErr LMGetMemErr() {
+ return memErr;
+}
+
+void LMSetMemErr(OSErr value) {
+ memErr = value;
+}
+
diff --git a/command_line/CmdLine/Src/MacEmul/Memory.c b/command_line/CmdLine/Src/MacEmul/Memory.c
new file mode 100644
index 0000000..8b956a0
--- /dev/null
+++ b/command_line/CmdLine/Src/MacEmul/Memory.c
@@ -0,0 +1,266 @@
+#include "mwcc_decomp.h"
+
+static OSErr memError;
+
+typedef struct HandleStructure {
+ char *addr;
+ OSHandle hand;
+} HandleStructure;
+
+#define HS(h) ((HandleStructure *) (h))
+
+OSHandle *OS_PeekMacHandle(Handle h) {
+ return &HS(h)->hand;
+}
+
+static void FixHandlePtr(Handle h, void *ptr) {
+ HS(h)->hand.addr = ptr;
+}
+
+Handle OS_CreateMacHandle(OSHandle *h) {
+ HandleStructure *hs = malloc(sizeof(HandleStructure));
+ if (!hs) {
+ memError = -108;
+ return 0;
+ };
+
+ hs->hand = *h;
+ OS_InvalidateHandle(h);
+ hs->addr = OS_LockHandle(&hs->hand);
+ OS_UnlockHandle(&hs->hand);
+ return (Handle) hs;
+}
+
+Handle OS_CreateMacHandleDup(OSHandle *h) {
+ HandleStructure *hs = malloc(sizeof(HandleStructure));
+ if (!hs) {
+ memError = -108;
+ return 0;
+ };
+
+ hs->hand = *h;
+ hs->addr = OS_LockHandle(&hs->hand);
+ OS_UnlockHandle(&hs->hand);
+ return (Handle) hs;
+}
+
+void OS_DestroyMacHandle(Handle h, OSHandle *ret) {
+ *ret = HS(h)->hand;
+ free(h);
+}
+
+OSErr MemError() {
+ return memError;
+}
+
+Handle NewHandle(SInt32 dataSize) {
+ int err;
+ OSHandle oh;
+
+ err = OS_NewHandle(dataSize, &oh);
+ if (err) {
+ memError = OS_MacError(err);
+ return 0;
+ }
+
+ return OS_CreateMacHandle(&oh);
+}
+
+Handle NewHandleClear(UInt32 dataSize) {
+ Handle hdl = NewHandle(dataSize);
+
+ if (hdl) {
+ HLock(hdl);
+ if (*hdl)
+ memset(*hdl, 0, dataSize);
+ HUnlock(hdl);
+ }
+
+ return hdl;
+}
+
+Handle TempNewHandle(UInt32 dataSize, OSErr *resultCode) {
+ *resultCode = 0;
+ Handle hdl = NewHandle(dataSize);
+ if (!hdl)
+ *resultCode = memError;
+ return hdl;
+}
+
+void DisposeHandle(Handle h) {
+ if (h) {
+ memError = OS_MacError(OS_FreeHandle(&HS(h)->hand));
+ FixHandlePtr(h, 0);
+ } else {
+ memError = -109;
+ }
+}
+
+void HLock(Handle h) {
+ void *buffer;
+
+ if (h) {
+ buffer = OS_LockHandle(&HS(h)->hand);
+ FixHandlePtr(h, buffer);
+ memError = 0;
+ } else {
+ memError = -109;
+ }
+}
+
+void HLockHi(Handle h) {
+ HLock(h);
+}
+
+void HUnlock(Handle h) {
+ if (h) {
+ memError = 0;
+ OS_UnlockHandle(&HS(h)->hand);
+ } else {
+ memError = -109;
+ }
+}
+
+void HPurge(Handle theHandle) {
+ memError = 0;
+}
+
+void HNoPurge(Handle theHandle) {
+ memError = 0;
+}
+
+SInt8 HGetState(Handle theHandle) {
+ memError = 0;
+ return 0;
+}
+
+void HSetState(Handle theHandle, SInt8 flags) {
+ memError = 0;
+}
+
+SInt32 GetHandleSize(Handle h) {
+ UInt32 sz;
+
+ if (h) {
+ memError = OS_MacError(OS_GetHandleSize(&HS(h)->hand, &sz));
+ } else {
+ sz = 0;
+ memError = -109;
+ }
+
+ return sz;
+}
+
+void SetHandleSize(Handle h, SInt32 newSize) {
+ memError = OS_MacError(OS_ResizeHandle(&HS(h)->hand, newSize));
+ FixHandlePtr(h, OS_LockHandle(&HS(h)->hand));
+ OS_UnlockHandle(&HS(h)->hand);
+}
+
+OSErr PtrAndHand(const void *srcPtr, Handle destHandle, SInt32 size) {
+ OSErr err;
+
+ err = OS_MacError(OS_AppendHandle(&HS(destHandle)->hand, srcPtr, size));
+ FixHandlePtr(h, OS_LockHandle(&HS(destHandle)->hand));
+ OS_UnlockHandle(&HS(h)->hand);
+
+ return err;
+}
+
+OSErr PtrToHand(const void *srcPtr, Handle *destHandle, SInt32 size) {
+ *destHandle = NewHandle(size);
+ if (!*destHandle)
+ return MemError();
+
+ HLock(*destHandle);
+ memcpy(**destHandle, srcPtr, size);
+ HUnlock(*destHandle);
+
+ return MemError();
+}
+
+OSErr HandToHand(Handle *destHandle) {
+ Handle srcHandle = *destHandle;
+ SInt32 size;
+
+ size = GetHandleSize(srcHandle);
+ *destHandle = NewHandle(size);
+ if (!*destHandle)
+ return MemError();
+
+ HLock(*destHandle);
+ HLock(srcHandle);
+ memcpy(**destHandle, *srcHandle, size);
+ HUnlock(srcHandle);
+ HUnlock(*destHandle);
+
+ return MemError();
+}
+
+OSErr HandAndHand(Handle src, Handle dst) {
+ OSErr err;
+ SInt32 size;
+
+ HLock(src);
+ size = GetHandleSize(src);
+ err = PtrAndHand(*src, dst, size);
+ HUnlock(src);
+ return err;
+}
+
+void MoveHHi(Handle theHandle) {
+ memError = theHandle ? 0 : -109;
+}
+
+void BlockMove(const void *srcPtr, void *destPtr, UInt32 byteCount) {
+ memmove(destPtr, srcPtr, byteCount);
+}
+
+void BlockMoveData(const void *srcPtr, void *destPtr, UInt32 byteCount) {
+ memmove(destPtr, srcPtr, byteCount);
+}
+
+Ptr NewPtr(SInt32 dataSize) {
+ Ptr p;
+
+ if (!dataSize)
+ dataSize = 1;
+
+ p = malloc(dataSize);
+ memError = p ? 0 : -108;
+ return p;
+}
+
+void DisposePtr(Ptr p) {
+ memError = 0;
+ if (p)
+ free(p);
+}
+
+Ptr NewPtrClear(SInt32 dataSize) {
+ Ptr p;
+
+ memError = -108;
+ if (!dataSize)
+ dataSize = 1;
+
+ p = malloc(dataSize);
+ if (p) {
+ memError = 0;
+ memset(p, 0, dataSize);
+ }
+
+ return p;
+}
+
+void DebugStr(ConstStringPtr str) {
+ fprintf(stderr, "*.*s", str[0], str[1], &str[1]);
+}
+
+struct Zone *HandleZone() {
+ return 0;
+}
+
+struct Zone *ApplicationZone() {
+ return 0;
+}
diff --git a/command_line/CmdLine/Src/MacEmul/ResourceStrings.c b/command_line/CmdLine/Src/MacEmul/ResourceStrings.c
new file mode 100644
index 0000000..bdf3735
--- /dev/null
+++ b/command_line/CmdLine/Src/MacEmul/ResourceStrings.c
@@ -0,0 +1,68 @@
+#include "mwcc_decomp.h"
+
+typedef struct {
+ const char *name;
+ SInt16 rsrcid;
+ const char **strings;
+} Res;
+
+static Res rlist[16];
+
+void Res_Initialize() {
+ memset(rlist, 0, sizeof(rlist));
+}
+
+int Res_AddResource(const char *name, SInt16 rsrcid, const char **strings) {
+ int scan;
+
+ for (scan = 0; scan < 16 && rlist[scan].rsrcid; scan++) {
+ if (rsrcid == rlist[scan].rsrcid) {
+ fprintf(stderr, "Resource %d is already added!\n", rsrcid);
+ return 0;
+ }
+ }
+
+ if (scan >= 16)
+ return 0;
+
+ rlist[scan].name = name;
+ rlist[scan].rsrcid = rsrcid;
+ rlist[scan].strings = strings;
+ return 1;
+}
+
+enum { MaxRes = 16 };
+
+const char *Res_GetResource(SInt16 rsrcid, SInt16 index) {
+ // Does not match, absolutely hopeless
+ int scan, find;
+ static char err[256];
+
+ scan = 0;
+ do {
+ if (rsrcid == rlist[scan].rsrcid) {
+ find = 0;
+ if ((SInt16) (index - 1) < 0) {
+ snprintf(err, sizeof(err), "[Illegal string index #%d in list '%s' (%d)]", (SInt16) (index - 1), rlist[scan].name, rsrcid);
+ return err;
+ }
+
+ while (find <= (index - 1)) {
+ if (!rlist[scan].strings[find]) {
+ snprintf(err, sizeof(err), "[String #%d not found in resource '%s' (%d)]", (SInt16) (index - 1), rlist[scan].name, rsrcid);
+ return err;
+ }
+ if (find == (index - 1)) {
+ return rlist[scan].strings[find];
+ } else {
+ find++;
+ }
+ }
+ }
+ } while (scan++ < MaxRes);
+
+ return 0;
+}
+
+void Res_Cleanup() {
+}
diff --git a/command_line/CmdLine/Src/MacEmul/Resources.c b/command_line/CmdLine/Src/MacEmul/Resources.c
new file mode 100644
index 0000000..7c2bea8
--- /dev/null
+++ b/command_line/CmdLine/Src/MacEmul/Resources.c
@@ -0,0 +1,1230 @@
+#include "mwcc_decomp.h"
+
+// base is 0,51, ptr is 0,54
+typedef struct MemRefList {
+ UInt16 id;
+ OSType type;
+ StringPtr name;
+ unsigned char attr;
+ Handle hand;
+ struct MemRefList *next;
+} MemRefList;
+
+// base is 0,50, ptr is 0,55
+typedef struct MemRsrcTypeList {
+ OSType type;
+ MemRefList *ref_list;
+ struct MemRsrcTypeList *next;
+} MemRsrcTypeList;
+
+// base is 0,56
+typedef struct {
+ char sysdata[66];
+ char type[4];
+ char creator[4];
+ char sysdata2[38];
+ char appdata[128];
+} MemRsrcSysData; // assumed name
+
+// base is 0,49, ptr is 0,62, ptrptr is 0,63
+typedef struct MemRsrcMap {
+ SInt16 refnum;
+ UInt16 fork_attr;
+ MemRsrcTypeList *type_list;
+ MemRsrcSysData sys_data;
+ struct MemRsrcMap *prev;
+} MemRsrcMap;
+
+typedef struct {
+ UInt32 data_offs;
+ UInt32 map_offs;
+ UInt32 data_len;
+ UInt32 map_len;
+} Ty70;
+typedef struct {
+ Ty70 mem_hdr;
+ Handle mem_next_map_handle;
+ SInt16 mem_refnum;
+ UInt16 fork_addr;
+ UInt16 typelist_offs;
+ UInt16 namelist_offs;
+ UInt16 types_idx;
+} Ty73;
+typedef struct {
+ OSType type;
+ UInt16 rsrc_idx;
+ UInt16 ref_list_offs;
+} Ty75;
+typedef struct {
+ UInt16 id;
+ UInt16 name_offs;
+ unsigned char attr;
+ unsigned char data_offs[3];
+ Handle mem_rsrc_handle;
+} Ty77;
+typedef struct {
+ unsigned char len;
+} Ty80;
+typedef struct {
+ UInt32 len;
+} Ty82;
+
+typedef struct ResRef {
+ OSSpec spec;
+ int ref;
+ struct ResRef *next;
+} ResRef;
+
+static OSErr resError;
+static SInt16 cur_res_file;
+Boolean ResLoad;
+static MemRsrcMap *maplist;
+static ResRef *resForkList;
+static ResRef *resForkLast;
+static Boolean UseResourceForkInfo;
+
+// Forward declarations
+static void ReadResourceFork(SInt16 ref, SInt8 permission, void *file_data, SInt32 file_size);
+
+Boolean OS_UsingMacResourceForkInfo() {
+ return UseResourceForkInfo;
+}
+
+void OS_UseMacResourceForkInfo(Boolean which) {
+ UseResourceForkInfo = which;
+}
+
+OSErr SystemInitResources(OSSpec *spec) {
+ void *file_data;
+ SInt32 file_len;
+
+ maplist = 0;
+ cur_res_file = 0;
+
+ if (!OS_LoadMacResourceFork(spec, &file_data, &file_len)) {
+ ReadResourceFork(-1, 1, file_data, file_len);
+ cur_res_file = -1;
+ resError = noErr;
+ return noErr;
+ } else {
+ FSSpec prog;
+ if (!OS_OSSpec_To_FSSpec(spec, &prog) && !FSpOpenResFile(&prog, 1)) {
+ resError = noErr;
+ return noErr;
+ } else {
+ resError = fnfErr;
+ return fnfErr;
+ }
+ }
+}
+
+static MemRsrcMap *NewResourceMap(SInt16 ref, UInt16 attr, MemRsrcTypeList *list) {
+ MemRsrcMap *nw;
+ MemRsrcMap **scan;
+
+ scan = &maplist;
+ nw = malloc(sizeof(MemRsrcMap));
+
+ if (!nw) {
+ resError = memFullErr;
+ return 0;
+ }
+
+ nw->refnum = ref;
+ nw->fork_attr = attr;
+ nw->type_list = list;
+ nw->prev = *scan;
+ *scan = nw;
+ return nw;
+}
+
+static MemRsrcTypeList *NewTypeListEntry(MemRsrcTypeList **scan, OSType type, MemRefList *list, MemRsrcTypeList *next) {
+ MemRsrcTypeList *nw;
+
+ while (*scan)
+ scan = &(*scan)->next;
+
+ nw = malloc(sizeof(MemRsrcTypeList));
+ if (!nw) {
+ resError = memFullErr;
+ return 0;
+ }
+
+ nw->type = type;
+ nw->ref_list = list;
+ nw->next = next;
+ *scan = nw;
+ return nw;
+}
+
+static MemRefList *NewRefListEntry(MemRefList **scan, UInt16 id, OSType type, StringPtr name, unsigned char attr, Handle hand) {
+ char mname[256];
+ MemRefList *prev;
+ MemRefList *nw;
+
+ prev = 0;
+ if (name)
+ p2cstrcpy(mname, name);
+ else
+ strcpy(mname, "(none)");
+
+ while (*scan && (*scan)->id != id) {
+ prev = *scan;
+ scan = &(*scan)->next;
+ }
+
+ nw = malloc(sizeof(MemRefList));
+ if (!nw) {
+ resError = memFullErr;
+ return 0;
+ }
+
+ nw->id = id;
+ nw->type = type;
+ nw->name = name;
+ nw->attr = attr;
+ nw->hand = hand;
+ if (prev) {
+ nw->next = prev->next;
+ prev->next = nw;
+ } else {
+ nw->next = 0;
+ }
+ *scan = nw;
+ return nw;
+}
+
+static MemRsrcMap *FindResourceMap(SInt16 ref) {
+ MemRsrcMap *list = maplist;
+
+ while (list) {
+ if (list->refnum == ref)
+ return list;
+ list = list->prev;
+ }
+
+ return 0;
+}
+
+static MemRsrcMap *FindResourceMap2(SInt16 ref, MemRsrcMap **next) {
+ MemRsrcMap *list = maplist;
+
+ *next = 0;
+ while (list) {
+ if (list->refnum == ref)
+ return list;
+ *next = list;
+ list = list->prev;
+ }
+
+ return 0;
+}
+
+static void DeleteResources(SInt16 refNum) {
+ MemRsrcMap *rm, *rmnext;
+ MemRsrcTypeList *mtyptmp, *mtyp;
+ MemRefList *mrletmp, *mrle;
+
+ rm = FindResourceMap2(refNum, &rmnext);
+ if (rm) {
+ mtyp = rm->type_list;
+ while (mtyp) {
+ mrle = mtyp->ref_list;
+ while (mrle) {
+ if (mrle->hand)
+ DisposeHandle(mrle->hand);
+ if (mrle->name)
+ free(mrle->name);
+ mrletmp = mrle;
+ mrle = mrle->next;
+ free(mrletmp);
+ }
+ mtyptmp = mtyp;
+ mtyp = mtyp->next;
+ free(mtyptmp);
+ }
+
+ if (rmnext)
+ rmnext->prev = rm->prev;
+ else
+ maplist = rm->prev;
+ free(rm);
+ }
+}
+
+static void ReadResourceFork(SInt16 ref, SInt8 permission, void *file_data, SInt32 file_size) {
+ unsigned char *nameptr;
+ unsigned char *name;
+ Handle hand;
+ SInt32 offs;
+ SInt32 esize;
+ Ty82 tent;
+ MemRsrcTypeList *mtyp;
+ int rcnt;
+ SInt32 ref_offs;
+ SInt32 cnt;
+ SInt32 msize;
+ void *buffer;
+ Ty80 *dnam;
+ Ty77 *drle;
+ Ty75 *dtyp;
+ Ty73 *dmap;
+ MemRsrcSysData *dsys;
+ MemRsrcSysData tsys;
+ Ty70 *dhdr;
+ Ty70 thdr;
+ MemRsrcMap *rm;
+
+ // Not Right Now Folk's
+}
+
+static void GetResourceSizes(MemRsrcMap *rm, SInt32 *data_size, SInt32 *name_size, SInt32 *reflist_size, SInt32 *typelist_size) {
+ MemRefList *mrle;
+ MemRsrcTypeList *mtyp;
+
+ *data_size = *name_size = *reflist_size = *typelist_size = 0;
+
+ mtyp = rm->type_list;
+ while (mtyp) {
+ mrle = mtyp->ref_list;
+ while (mrle) {
+ *name_size += !mrle->name ? 0 : (mrle->name[0] + 1);
+ *data_size += (!mrle->hand ? 0 : GetHandleSize(mrle->hand)) + 4;
+ *reflist_size += 12;
+ mrle = mrle->next;
+ }
+ *typelist_size += 8;
+ mtyp = mtyp->next;
+ }
+}
+
+static SInt32 GetResourceTypesCount(MemRsrcMap *dm) {
+ MemRsrcTypeList *mtyp;
+ SInt32 tmp;
+
+ tmp = 0;
+ mtyp = dm->type_list;
+ while (mtyp) {
+ mtyp = mtyp->next;
+ ++tmp;
+ }
+
+ return tmp;
+}
+
+static SInt32 GetResourceEntriesCount(MemRsrcTypeList *mtyp) {
+ MemRefList *mrle;
+ SInt32 tmp;
+
+ tmp = 0;
+ mrle = mtyp->ref_list;
+ while (mrle) {
+ mrle = mrle->next;
+ ++tmp;
+ }
+
+ return tmp;
+}
+
+static void WriteResourceFork(SInt16 ref) {
+ // some weird shit going on with locals here
+ // there's probably a bunch of macros
+ // may be able to refer to the Windows binary for assert values
+ SInt32 sz;
+ SInt32 __len;
+ SInt32 __offs;
+ SInt32 __offs_2;
+ SInt32 __len_2;
+ SInt32 __offs_3;
+ SInt32 __offs_4;
+ Ty82 tent;
+ Ty82 dent;
+ Ty77 trle;
+ Ty77 drle;
+ SInt32 __offs_5;
+ MemRefList *mrle;
+ Ty75 ttyp;
+ Ty75 dtyp;
+ MemRsrcTypeList *mtyp;
+ SInt32 __offs_6;
+ SInt32 data_offs;
+ SInt32 name_offs;
+ SInt32 typelist_offs;
+ SInt32 reflist_offs;
+ SInt32 data_size;
+ SInt32 name_size;
+ SInt32 typelist_size;
+ SInt32 reflist_size;
+ Handle hand_ref;
+ Ty73 tmap;
+ Ty73 dmap;
+ MemRsrcSysData tsys;
+ Ty70 thdr;
+ Ty70 dhdr;
+ MemRsrcMap *rm;
+}
+
+static void WriteEmptyResourceFork(SInt16 ref) {
+ SInt32 sz;
+ Handle hand_ref;
+ Ty73 dmap;
+ MemRsrcSysData dsys;
+ Ty70 dhdr;
+
+ // i'll do this one later lol
+}
+
+static MemRsrcTypeList *FindResourceType1(MemRsrcMap *rm, OSType theType) {
+ MemRsrcTypeList *mtyp;
+
+ mtyp = rm->type_list;
+ while (mtyp) {
+ if (mtyp->type == theType)
+ return mtyp;
+ mtyp = mtyp->next;
+ }
+
+ return 0;
+}
+
+static SInt32 CountResourceType1(MemRsrcMap *rm, OSType theType) {
+ MemRsrcTypeList *mtyp;
+
+ mtyp = rm->type_list;
+ while (mtyp) {
+ if (mtyp->type == theType)
+ return GetResourceEntriesCount(mtyp);
+ mtyp = mtyp->next;
+ }
+
+ return 0;
+}
+
+static SInt32 CountResourceType(OSType theType) {
+ MemRsrcMap *rm;
+ SInt32 total;
+
+ total = 0;
+ rm = FindResourceMap(cur_res_file);
+
+ while (rm) {
+ total += CountResourceType1(rm, theType);
+ rm = rm->prev;
+ }
+
+ return total;
+}
+
+static MemRefList *FindIndResource1(MemRsrcMap *rm, OSType theType, SInt16 index) {
+ MemRefList *mrle;
+ MemRsrcTypeList *mtyp;
+
+ mtyp = rm->type_list;
+ while (mtyp) {
+ if (mtyp->type == theType) {
+ mrle = mtyp->ref_list;
+ while (mrle && --index > 0) {
+ mrle = mrle->next;
+ }
+ return mrle;
+ }
+ mtyp = mtyp->next;
+ }
+
+ return 0;
+}
+
+static MemRefList *FindIndResource(OSType theType, SInt16 index) {
+ MemRefList *mrle;
+ MemRsrcMap *rm = FindResourceMap(cur_res_file);
+
+ while (rm) {
+ mrle = FindIndResource1(rm, theType, index);
+ if (mrle)
+ return mrle;
+ rm = rm->prev;
+ }
+
+ return 0;
+}
+
+static MemRefList *FindResourceTypeAndID1(MemRsrcMap *rm, OSType theType, SInt16 theID) {
+ MemRefList *mref;
+ MemRsrcTypeList *mtyp = FindResourceType1(rm, theType);
+
+ if (mtyp) {
+ mref = mtyp->ref_list;
+ while (mref) {
+ if (mref->id == theID)
+ return mref;
+ mref = mref->next;
+ }
+ }
+
+ return 0;
+}
+
+static MemRefList *FindResourceTypeAndID(OSType theType, SInt16 theID) {
+ MemRefList *mref;
+ MemRsrcMap *rm = FindResourceMap(cur_res_file);
+
+ while (rm) {
+ mref = FindResourceTypeAndID1(rm, theType, theID);
+ if (mref)
+ return mref;
+ rm = rm->prev;
+ }
+
+ return 0;
+}
+
+static MemRefList *FindResourceTypeAndName1(MemRsrcMap *rm, OSType theType, ConstStringPtr theName) {
+ MemRefList *mref;
+ MemRsrcTypeList *mtyp;
+
+ mtyp = FindResourceType1(rm, theType);
+ if (mtyp) {
+ mref = mtyp->ref_list;
+ while (mref) {
+ if (mref->name && EqualString(mref->name, theName, 0, 0))
+ return mref;
+ mref = mref->next;
+ }
+ }
+
+ return 0;
+}
+
+static MemRefList *FindResourceTypeAndName(OSType theType, ConstStringPtr theName) {
+ MemRefList *mref;
+ MemRsrcMap *rm = FindResourceMap(cur_res_file);
+
+ while (rm) {
+ mref = FindResourceTypeAndName1(rm, theType, theName);
+ if (mref)
+ return mref;
+ rm = rm->prev;
+ }
+
+ return 0;
+}
+
+static MemRefList *FindResourceHandle1(MemRsrcMap *rm, Handle theResource) {
+ MemRefList *mrle;
+ MemRsrcTypeList *mtyp;
+
+ for (mtyp = rm->type_list; mtyp; mtyp = mtyp->next) {
+ for (mrle = mtyp->ref_list; mrle; mrle = mrle->next) {
+ if (mrle->hand == theResource)
+ return mrle;
+ }
+ }
+
+ return 0;
+}
+
+static MemRefList *FindResourceHandle(Handle theResource) {
+ MemRefList *mrle;
+ MemRsrcMap *rm;
+
+ for (rm = FindResourceMap(cur_res_file); rm; rm = rm->prev) {
+ mrle = FindResourceHandle1(rm, theResource);
+ if (mrle)
+ return mrle;
+ }
+
+ return 0;
+}
+
+static int RemoveResourceHandle1(MemRsrcMap *rm, Handle theResource) {
+ MemRefList *mrle, *pmrle;
+ MemRsrcTypeList *mtyp, *pmtyp;
+
+ mtyp = rm->type_list;
+ pmtyp = 0;
+ while (mtyp) {
+ mrle = mtyp->ref_list;
+ pmrle = 0;
+ while (mrle) {
+ if (mrle->hand == theResource) {
+ if (pmrle)
+ pmrle->next = mrle->next;
+ else
+ mtyp->ref_list = mrle->next;
+ free(mrle);
+
+ if (!mtyp->ref_list) {
+ if (pmtyp)
+ pmtyp->next = mtyp->next;
+ else
+ rm->type_list = mtyp->next;
+ free(mtyp);
+ }
+
+ return 1;
+ }
+
+ pmrle = mrle;
+ mrle = mrle->next;
+ }
+ pmtyp = mtyp;
+ mtyp = mtyp->next;
+ }
+
+ return 0;
+}
+
+static int RemoveResourceHandle(Handle theResource) {
+ MemRsrcMap *rm;
+
+ for (rm = FindResourceMap(cur_res_file); rm; rm = rm->prev) {
+ if (RemoveResourceHandle1(rm, theResource))
+ return 1;
+ }
+
+ return 0;
+}
+
+static SInt16 FindResourceHandleFile1(MemRsrcMap *rm, Handle theResource) {
+ MemRefList *mrle;
+ MemRsrcTypeList *mtyp;
+}
+
+static SInt16 FindResourceHandleFile(Handle theResource) {
+ MemRefList *mrle;
+ MemRsrcMap *rm;
+}
+
+void OS_AddMacResourceForkRef(int ref, const OSSpec *spec) {
+ ResRef *nw;
+}
+
+void OS_RemoveMacResourceForkRef(int ref) {
+ ResRef *prev;
+ ResRef *lst;
+}
+
+OSSpec *OS_GetMacResourceForkFromRef(int ref) {
+ ResRef *lst;
+}
+
+Boolean OS_SearchMacResourceForkList(const OSSpec *rspec, int *ref) {
+ ResRef *lst;
+}
+
+int OS_SetMacResourceForkCreatorAndType(int ref, OSType creator, OSType type) {
+ MemRsrcMap *rm;
+ UInt32 sz;
+ UInt32 buf[2];
+ int err;
+
+ if (!OS_GetMacResourceForkFromRef(ref)) {
+ sz = 8;
+ buf[0] = type;
+ buf[1] = creator;
+ err = OS_Seek(ref, OSSeekAbs, 0x52);
+ if (!err) {
+ err = OS_Write(ref, buf, &sz);
+ if (!err && sz == 8) {
+ err = 0;
+ }
+ }
+ } else {
+ rm = FindResourceMap(OS_RefToMac(ref));
+ if (!rm) {
+ err = 2;
+ } else if (rm->fork_attr & 0x80) {
+ err = 13;
+ } else {
+ rm->sys_data.creator[0] = (creator & 0xFF000000) >> 24;
+ rm->sys_data.creator[1] = (creator & 0x00FF0000) >> 16;
+ rm->sys_data.creator[2] = (creator & 0x0000FF00) >> 8;
+ rm->sys_data.creator[3] = (creator & 0x000000FF);
+ rm->sys_data.type[0] = (type & 0xFF000000) >> 24;
+ rm->sys_data.type[1] = (type & 0x00FF0000) >> 16;
+ rm->sys_data.type[2] = (type & 0x0000FF00) >> 8;
+ rm->sys_data.type[3] = (type & 0x000000FF);
+ rm->fork_attr |= 0x20;
+ err = 0;
+ }
+ }
+
+ return err;
+}
+
+int OS_GetMacResourceForkCreatorAndType(int ref, OSType *creator, OSType *type) {
+ MemRsrcMap *rm;
+ UInt32 sz;
+ UInt32 buf[2];
+ int err;
+
+ if (!OS_GetMacResourceForkFromRef(ref)) {
+ sz = 8;
+ err = OS_Seek(ref, OSSeekAbs, 0x52);
+ if (!err) {
+ err = OS_Read(ref, buf, &sz);
+ if (!err && sz == 8) {
+ err = 0;
+ *type = buf[0];
+ *creator = buf[1];
+ }
+ }
+ } else {
+ rm = FindResourceMap(OS_RefToMac(ref));
+ if (!rm) {
+ err = 2;
+ } else {
+ *creator = (rm->sys_data.creator[0] << 24) | (rm->sys_data.creator[1] << 16) | (rm->sys_data.creator[2] << 8) | rm->sys_data.creator[3];
+ *type = (rm->sys_data.type[0] << 24) | (rm->sys_data.type[1] << 16) | (rm->sys_data.type[2] << 8) | rm->sys_data.type[3];
+ err = 0;
+ }
+ }
+
+ return err;
+}
+
+void OS_CleanupMacResourceForkDir(const OSPathSpec *dir) {
+ OS_Rmdir(dir);
+}
+
+OSErr OS_MacDumpResourceFork(SInt16 ref, Boolean dumpContents) {
+ int spaces;
+ char safe[16];
+ SInt32 size;
+ SInt32 idx;
+ StringPtr ptr;
+ char name[256];
+ MemRefList *rl;
+ MemRsrcTypeList *tl;
+ MemRsrcMap *rm;
+
+ // Debug shit
+}
+
+OSErr FSpOpenRF(const FSSpec *fss, SInt8 permission, SInt16 *refNum) {
+ Boolean create;
+ OSSpec rspec;
+ OSSpec spec;
+ FSSpec rfss;
+ int oserr;
+ OSErr err;
+
+ create = (permission == 1) | (permission > 1);
+ oserr = OS_FSSpec_To_OSSpec(fss, &spec);
+ if (oserr)
+ return OS_MacError(oserr);
+
+ oserr = OS_GetRsrcOSSpec(&spec, &rspec, create);
+ if (oserr)
+ return OS_MacError(oserr);
+
+ oserr = OS_OSSpec_To_FSSpec(&rspec, &rfss);
+ if (oserr)
+ return OS_MacError(oserr);
+
+ if (OS_Status(&rspec) && create)
+ HCreate(rfss.vRefNum, rfss.parID, rfss.name, 'CWIE', 'rsrc');
+
+ err = HOpen(rfss.vRefNum, rfss.parID, rfss.name, permission, refNum);
+ if (!err)
+ OS_AddMacResourceForkRef(OS_MacToRef(*refNum), &rspec);
+
+ return err;
+}
+
+OSErr HOpenRF(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName, SInt8 permission, SInt16 *refNum) {
+ OSErr __err;
+ FSSpec fss;
+
+ __err = FSMakeFSSpec(vRefNum, dirID, fileName, &fss);
+ if (__err != noErr && __err != fnfErr) {
+ return __err;
+ } else {
+ return FSpOpenRF(&fss, permission, refNum);
+ }
+}
+
+OSErr InitResources() {
+ MemRsrcMap *map;
+
+ map = maplist;
+ cur_res_file = 0;
+ while (map) {
+ cur_res_file = map->refnum;
+ map = map->prev;
+ }
+
+ ResLoad = 1;
+ resError = noErr;
+ return 0;
+}
+
+OSErr ResError() {
+ return resError;
+}
+
+void FSpCreateResFile(const FSSpec *fss, OSType creator, OSType fileType, ScriptCode scriptTag) {
+ SInt16 ref;
+ OSSpec spec, rspec;
+ int oserr;
+
+ FSpCreate(fss, creator, fileType, scriptTag);
+ oserr = OS_FSSpec_To_OSSpec(fss, &spec);
+ if (oserr) {
+ resError = OS_MacError(oserr);
+ return;
+ }
+
+ oserr = OS_GetRsrcOSSpec(&spec, &rspec, 1);
+ if (oserr) {
+ resError = OS_MacError(oserr);
+ return;
+ }
+
+ if (OS_Status(&rspec)) {
+ oserr = OS_Create(&rspec, &OS_TEXTTYPE);
+ if (oserr) {
+ resError = OS_MacError(oserr);
+ return;
+ }
+
+ resError = FSpOpenRF(fss, 3, &ref);
+ if (!resError) {
+ WriteEmptyResourceFork(ref);
+ FSClose(ref);
+ }
+ } else {
+ resError = dupFNErr;
+ }
+
+}
+
+void HCreateResFile(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName) {
+ OSErr __err;
+ FSSpec fss;
+
+ __err = FSMakeFSSpec(vRefNum, dirID, fileName, &fss);
+ if (__err != noErr && __err != fnfErr) {
+ resError = __err;
+ } else {
+ FSpCreateResFile(&fss, 'CWIE', kUnknownType, -1);
+ }
+}
+
+OSErr FSpOpenResFile(const FSSpec *fss, SInt8 permission) {
+ SInt32 size;
+ SInt16 ref;
+
+ if (permission != 1)
+ FSpCreate(fss, 'CWIE', 'TEXT', -1);
+
+ resError = FSpOpenRF(fss, (permission != 2) ? permission : 3, &ref);
+ if (!resError) {
+ GetEOF(ref, &size);
+ if (size == 0 && permission != 1)
+ WriteEmptyResourceFork(ref);
+ ReadResourceFork(ref, permission, 0, 0);
+ if (resError) {
+ FSClose(ref);
+ CloseResFile(ref);
+ ref = -1;
+ }
+ cur_res_file = ref;
+ } else {
+ ref = -1;
+ }
+
+ return ref;
+}
+
+OSErr HOpenResFile(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName, SInt8 permission) {
+ OSErr __err;
+ FSSpec fss;
+
+ __err = FSMakeFSSpec(vRefNum, dirID, fileName, &fss);
+ if (__err != noErr && __err != fnfErr)
+ return __err;
+ return FSpOpenResFile(&fss, permission);
+}
+
+SInt16 CurResFile() {
+ return cur_res_file;
+}
+
+void UseResFile(SInt16 refNum) {
+ MemRsrcMap *map;
+
+ for (map = maplist; map; map = map->prev) {
+ if (map->refnum == refNum) {
+ cur_res_file = refNum;
+ resError = noErr;
+ return;
+ }
+ }
+
+ resError = resFNotFound;
+}
+
+SInt16 HomeResFile(Handle theResource) {
+ SInt16 refnum = FindResourceHandleFile(theResource);
+ resError = (refnum == -1) ? resNotFound : 0;
+ return refnum;
+}
+
+Handle GetResource(OSType theType, SInt16 theID) {
+ MemRefList *mref;
+
+ mref = FindResourceTypeAndID(theType, theID);
+ if (mref) {
+ resError = noErr;
+ return mref->hand;
+ } else {
+ resError = ResLoad ? resNotFound : noErr;
+ return 0;
+ }
+}
+
+Handle Get1Resource(OSType theType, SInt16 theID) {
+ MemRefList *mref;
+ MemRsrcMap *rm;
+
+ rm = FindResourceMap(cur_res_file);
+ if (!rm) {
+ resError = resFNotFound;
+ return 0;
+ }
+
+ mref = FindResourceTypeAndID1(rm, theType, theID);
+ if (mref) {
+ resError = noErr;
+ return mref->hand;
+ } else {
+ resError = ResLoad ? resNotFound : noErr;
+ return 0;
+ }
+}
+
+Handle GetNamedResource(OSType theType, ConstStringPtr theName) {
+ MemRefList *mref;
+
+ mref = FindResourceTypeAndName(theType, theName);
+ if (mref) {
+ resError = noErr;
+ return mref->hand;
+ } else {
+ resError = ResLoad ? resNotFound : noErr;
+ return 0;
+ }
+}
+
+Handle Get1NamedResource(OSType theType, ConstStringPtr theName) {
+ MemRefList *mref;
+ MemRsrcMap *rm;
+
+ rm = FindResourceMap(cur_res_file);
+ if (!rm) {
+ resError = resFNotFound;
+ return 0;
+ }
+
+ mref = FindResourceTypeAndName1(rm, theType, theName);
+ if (mref) {
+ resError = noErr;
+ return mref->hand;
+ } else {
+ resError = (ResLoad != 0) ? resNotFound : noErr;
+ return 0;
+ }
+}
+
+void SetResLoad(Boolean load) {
+ ResLoad = load;
+}
+
+void MacEmul_LoadResource(Handle theResource) {
+ resError = (theResource == 0) ? nilHandleErr : 0;
+}
+
+void GetResInfo(Handle theResource, SInt16 *theID, OSType *theType, StringPtr name) {
+ MemRefList *mrle;
+
+ mrle = FindResourceHandle(theResource);
+ if (mrle) {
+ resError = noErr;
+ *theID = mrle->id;
+ *theType = mrle->type;
+ if (mrle->name)
+ _pstrcpy(name, mrle->name);
+ else
+ name[0] = 0;
+ } else {
+ resError = resNotFound;
+ }
+}
+
+void SetResInfo(Handle theResource, SInt16 theID, ConstStringPtr name) {
+ MemRefList *mrle;
+
+ mrle = FindResourceHandle(theResource);
+ if (mrle) {
+ resError = noErr;
+ if (mrle->name)
+ free(mrle->name);
+ mrle->name = malloc(name[0] + 1);
+ mrle->attr |= 2;
+ if (mrle->name)
+ _pstrcpy(mrle->name, name);
+ else
+ resError = memFullErr;
+ } else {
+ resError = resNotFound;
+ }
+}
+
+SInt16 GetResAttrs(Handle theResource) {
+ MemRefList *mrle;
+
+ mrle = FindResourceHandle(theResource);
+ if (mrle) {
+ resError = noErr;
+ return mrle->attr;
+ } else {
+ resError = resNotFound;
+ return 0;
+ }
+}
+
+void SetResAttrs(Handle theResource, SInt16 attrs) {
+ MemRefList *mrle;
+
+ mrle = FindResourceHandle(theResource);
+ if (mrle) {
+ resError = noErr;
+ mrle->attr = attrs;
+ } else {
+ resError = resNotFound;
+ }
+}
+
+void ChangedResource(Handle theResource) {
+ MemRefList *mrle;
+ MemRsrcMap *rm;
+
+ rm = FindResourceMap(cur_res_file);
+ mrle = FindResourceHandle(theResource);
+ if (mrle) {
+ if (rm && (rm->fork_attr & 0x80)) {
+ resError = resAttrErr;
+ } else {
+ resError = noErr;
+ mrle->attr |= 2;
+ rm->fork_attr |= 0x20;
+ }
+ } else {
+ resError = resNotFound;
+ }
+}
+
+void AddResource(Handle theData, OSType theType, SInt16 theID, ConstStringPtr name) {
+ MemRsrcMap *rm;
+ MemRsrcTypeList *mtyp;
+ MemRefList *mrle;
+ StringPtr namecpy;
+
+ rm = FindResourceMap(cur_res_file);
+ if (rm) {
+ if (rm->fork_attr & 0x80) {
+ resError = resAttrErr;
+ return;
+ }
+
+ resError = noErr;
+ mtyp = FindResourceType1(rm, theType);
+ if (!mtyp) {
+ mtyp = NewTypeListEntry(&rm->type_list, theType, 0, 0);
+ if (!mtyp) {
+ resError = memFullErr;
+ return;
+ }
+ rm->fork_attr |= 0x20;
+ }
+ if (!theData || FindResourceHandle(theData)) {
+ resError = addResFailed;
+ return;
+ }
+
+ if (name && name[0]) {
+ namecpy = malloc(name[0] + 1);
+ _pstrcpy(namecpy, name);
+ } else {
+ namecpy = 0;
+ }
+
+ mrle = NewRefListEntry(&mtyp->ref_list, theID, theType, namecpy, 2, theData);
+ if (!mrle) {
+ resError = memFullErr;
+ return;
+ }
+
+ rm->fork_attr |= 0x20;
+ } else {
+ resError = resFNotFound;
+ }
+}
+
+void UpdateResFile(SInt16 refnum) {
+ WriteResourceFork(refnum);
+}
+
+void WriteResource(Handle theResource) {
+ resError = noErr;
+}
+
+void SetResPurge(Boolean install) {
+}
+
+SInt16 CountResources(OSType theType) {
+ return CountResourceType(theType);
+}
+
+SInt16 Count1Resources(OSType theType) {
+ MemRsrcMap *rm;
+
+ rm = FindResourceMap(cur_res_file);
+ if (rm) {
+ resError = noErr;
+ return CountResourceType1(rm, theType);
+ } else {
+ resError = resFNotFound;
+ return 0;
+ }
+}
+
+Handle GetIndResource(OSType theType, SInt16 index) {
+ MemRefList *mrle;
+
+ mrle = FindIndResource(theType, index);
+ resError = mrle ? 0 : resNotFound;
+ return mrle->hand;
+}
+
+Handle Get1IndResource(OSType theType, SInt16 index) {
+ MemRefList *mrle;
+ MemRsrcMap *rm;
+
+ rm = FindResourceMap(cur_res_file);
+ if (rm) {
+ mrle = FindIndResource1(rm, theType, index);
+ if (mrle) {
+ resError = noErr;
+ return mrle->hand;
+ } else {
+ resError = resNotFound;
+ return 0;
+ }
+ } else {
+ resError = resFNotFound;
+ return 0;
+ }
+}
+
+SInt16 Count1Types() {
+ SInt16 count;
+ MemRsrcTypeList *rtl;
+ MemRsrcMap *rm;
+
+ count = 0;
+ rm = FindResourceMap(cur_res_file);
+ if (rm) {
+ rtl = rm->type_list;
+ while (rtl) {
+ rtl = rtl->next;
+ ++count;
+ }
+ } else {
+ resError = resFNotFound;
+ }
+
+ return count;
+}
+
+void Get1IndType(OSType *theType, SInt16 index) {
+ SInt16 count;
+ MemRsrcTypeList *rtl;
+ MemRsrcMap *rm;
+
+ count = 1;
+ rm = FindResourceMap(cur_res_file);
+ if (rm) {
+ rtl = rm->type_list;
+ while (rtl && count < index) {
+ rtl = rtl->next;
+ ++count;
+ }
+ if (rtl)
+ *theType = rtl->type;
+ else
+ resError = inputOutOfBounds;
+ } else {
+ resError = resFNotFound;
+ }
+}
+
+void ReleaseResource(Handle theResource) {
+ resError = noErr;
+}
+
+void DetachResource(Handle theResource) {
+ SInt32 ns;
+ MemRefList *mrle;
+
+ mrle = FindResourceHandle(theResource);
+ if (mrle) {
+ ns = GetHandleSize(theResource);
+ mrle->hand = NewHandle(ns);
+ if (!mrle->hand) {
+ resError = memFullErr;
+ } else {
+ HLock(mrle->hand);
+ HLock(theResource);
+ memcpy(*mrle->hand, *theResource, ns);
+ HUnlock(theResource);
+ HUnlock(mrle->hand);
+ resError = noErr;
+ }
+ } else {
+ resError = resNotFound;
+ }
+}
+
+void RemoveResource(Handle theResource) {
+ resError = RemoveResourceHandle(theResource) ? 0 : rmvResFailed;
+}
+
+void CloseResFile(SInt16 refNum) {
+ MemRsrcMap *rm = FindResourceMap(refNum);
+
+ if (rm && refNum != -1) {
+ WriteResourceFork(refNum);
+ DeleteResources(refNum);
+ FSClose(refNum);
+ }
+
+ cur_res_file = maplist ? maplist->refnum : 0;
+}
+
+SInt16 GetResFileAttrs(SInt16) {
+ MemRsrcMap *rm = FindResourceMap(cur_res_file);
+
+ if (rm) {
+ resError = 0;
+ return rm->fork_attr;
+ } else {
+ resError = resFNotFound;
+ return 0;
+ }
+}
+
+Boolean LMGetResLoad() {
+ return 1;
+}
diff --git a/command_line/CmdLine/Src/MacEmul/TextUtils.c b/command_line/CmdLine/Src/MacEmul/TextUtils.c
new file mode 100644
index 0000000..a23ac7e
--- /dev/null
+++ b/command_line/CmdLine/Src/MacEmul/TextUtils.c
@@ -0,0 +1,132 @@
+#include "mwcc_decomp.h"
+
+StringPtr c2pstr(char *s) {
+ unsigned int l;
+ l = strlen(s);
+ if (l > 255)
+ l = 255;
+ memmove(s + 1, s, l);
+ s[0] = l;
+ return (StringPtr) s;
+}
+
+char *p2cstr(StringPtr s) {
+ unsigned int l;
+ l = s[0];
+ memmove(s, s + 1, l);
+ s[l] = 0;
+ return (char *) s;
+}
+
+SInt16 CharacterByteType(Ptr textBuf, SInt16 textOffset, ScriptCode script) {
+ return 0;
+}
+
+SInt16 CharByte() {
+ return 0;
+}
+
+void GetDateTime(UInt32 *secs) {
+ time_t time;
+ OS_GetTime(&time);
+ OS_TimeToMac(time, secs);
+}
+
+Boolean EqualString(ConstStr255Param strA, ConstStr255Param strB, Boolean caseSens, Boolean diacSens) {
+ int i, length;
+ Boolean equal;
+
+ equal = 0;
+ length = strA[0];
+ if (strA && strB && length == strB[0]) {
+ if (caseSens) {
+ equal = !memcmp(strA + 1, strB + 1, length);
+ } else {
+ equal = 1;
+ i = 0;
+ while (equal && i < length) {
+ equal = toupper(strA[i]) == toupper(strB[i]);
+ ++i;
+ }
+ }
+ }
+
+ return equal;
+}
+
+void GetIndString(Str255 theString, SInt16 strListID, SInt16 index) {
+ SInt16 last;
+ SInt16 idc;
+ SInt32 len;
+ Handle strs;
+ const char *ret;
+ StringPtr ptr;
+ StringPtr dptr;
+ Str255 tmp;
+
+ ret = Res_GetResource(strListID, index);
+ if (ret) {
+ strcpy((char *) tmp, ret);
+ c2pstr((char *) tmp);
+ } else {
+ sprintf((char *) tmp, "[Resource string id=%d index=%d not found]", strListID, index);
+ c2pstr((char *) tmp);
+
+ strs = GetResource('STR#', strListID);
+ if (strs) {
+ last = (((unsigned char) (*strs)[0]) << 8) + ((unsigned char) (*strs)[1]);
+ if (index > 0 && index <= last) {
+ len = GetHandleSize(strs);
+ HLock(strs);
+ ptr = (StringPtr) (*strs + 2);
+ idc = index;
+ dptr = (StringPtr) (*strs + len);
+ while (ptr < dptr && --idc) {
+ ptr += *ptr + 1;
+ }
+ if (ptr < dptr)
+ _pstrcpy(tmp, ptr);
+ HUnlock(strs);
+ }
+ }
+ }
+
+ ptr = &tmp[1];
+ dptr = &theString[1];
+ while (ptr <= &tmp[tmp[0]]) {
+ if (*ptr == 0xD4) {
+ *dptr = '`';
+ } else if (*ptr == 0xD5) {
+ *dptr = '\'';
+ } else if (*ptr == 0xD2 || *ptr == 0xD3) {
+ *dptr = '"';
+ } else if (*ptr == 0xC9 && (dptr - theString) < 253) {
+ dptr[0] = '.';
+ dptr[1] = '.';
+ dptr[2] = '.';
+ dptr += 2;
+ } else {
+ *dptr = *ptr;
+ }
+ ++ptr;
+ ++dptr;
+ }
+
+ theString[0] = (dptr - theString) - 1;
+}
+
+char *getindstring(char *theString, SInt16 strListID, SInt16 index) {
+ GetIndString((StringPtr) theString, strListID, index);
+ return p2cstr((StringPtr) theString);
+}
+
+void NumToString(SInt32 theNum, Str255 theString) {
+ sprintf((char *) theString, "%d", theNum);
+ c2pstr((char *) theString);
+}
+
+void StringToNum(ConstStr255Param theString, SInt32 *theNum) {
+ p2cstr((StringPtr) theString);
+ sscanf((char *) theString, "%d", theNum);
+ c2pstr((char *) theString);
+}
diff --git a/command_line/CmdLine/Src/OSLib/FileHandles.c b/command_line/CmdLine/Src/OSLib/FileHandles.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/OSLib/FileHandles.c
diff --git a/command_line/CmdLine/Src/OSLib/Generic.c b/command_line/CmdLine/Src/OSLib/Generic.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/OSLib/Generic.c
diff --git a/command_line/CmdLine/Src/OSLib/MacFileTypes.c b/command_line/CmdLine/Src/OSLib/MacFileTypes.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/OSLib/MacFileTypes.c
diff --git a/command_line/CmdLine/Src/OSLib/MacSpecs.c b/command_line/CmdLine/Src/OSLib/MacSpecs.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/OSLib/MacSpecs.c
diff --git a/command_line/CmdLine/Src/OSLib/MemUtils.c b/command_line/CmdLine/Src/OSLib/MemUtils.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/OSLib/MemUtils.c
diff --git a/command_line/CmdLine/Src/OSLib/Posix.c b/command_line/CmdLine/Src/OSLib/Posix.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/OSLib/Posix.c
diff --git a/command_line/CmdLine/Src/OSLib/StringExtras.c b/command_line/CmdLine/Src/OSLib/StringExtras.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/OSLib/StringExtras.c
diff --git a/command_line/CmdLine/Src/OSLib/StringUtils.c b/command_line/CmdLine/Src/OSLib/StringUtils.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/OSLib/StringUtils.c
diff --git a/command_line/CmdLine/Src/Plugins/CLPlugins.c b/command_line/CmdLine/Src/Plugins/CLPlugins.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/Plugins/CLPlugins.c
diff --git a/command_line/CmdLine/Src/Project/CLAccessPaths.c b/command_line/CmdLine/Src/Project/CLAccessPaths.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/Project/CLAccessPaths.c
diff --git a/command_line/CmdLine/Src/Project/CLFiles.c b/command_line/CmdLine/Src/Project/CLFiles.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/Project/CLFiles.c
diff --git a/command_line/CmdLine/Src/Project/CLOverlays.c b/command_line/CmdLine/Src/Project/CLOverlays.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/Project/CLOverlays.c
diff --git a/command_line/CmdLine/Src/Project/CLProj.c b/command_line/CmdLine/Src/Project/CLProj.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/Project/CLProj.c
diff --git a/command_line/CmdLine/Src/Project/CLSegs.c b/command_line/CmdLine/Src/Project/CLSegs.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/command_line/CmdLine/Src/Project/CLSegs.c