summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt17
-rw-r--r--command_line/CmdLine/Src/OSLib/FileHandles.c29
-rw-r--r--command_line/CmdLine/Src/OSLib/Generic.c93
-rw-r--r--command_line/CmdLine/Src/OSLib/MacFileTypes.c29
-rw-r--r--command_line/CmdLine/Src/OSLib/MacSpecs.c25
-rw-r--r--command_line/CmdLine/Src/OSLib/MemUtils.c21
-rw-r--r--command_line/CmdLine/Src/OSLib/Posix.c866
-rw-r--r--command_line/CmdLine/Src/OSLib/StringExtras.c17
-rw-r--r--command_line/CmdLine/Src/OSLib/StringUtils.c49
-rw-r--r--includes/common.h266
-rw-r--r--includes/macemul.h168
-rw-r--r--includes/mwcc_decomp.h632
-rw-r--r--includes/oslib.h220
13 files changed, 1787 insertions, 645 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 55edbe1..d619b06 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,19 +47,4 @@ add_executable(mwcc
command_line/CmdLine/Src/CLPrefs.c
command_line/CmdLine/Src/CLTarg.c
command_line/CmdLine/Src/CLToolExec.c
- command_line/CmdLine/Src/CLWriteObjectFile.c
- includes/mwcc_decomp.h
- sdk_hdrs/CatTypes.h
- sdk_hdrs/CompilerMapping.h
- sdk_hdrs/CWDropInPanel.h
- sdk_hdrs/CWPluginErrors.h
- sdk_hdrs/CWPlugins.h
- sdk_hdrs/CWRuntimeFeatures.h
- sdk_hdrs/CWUnixPluginPrefix.h
- sdk_hdrs/CWWinPluginPrefix.h
- sdk_hdrs/DropInCompilerLinker.h
- sdk_hdrs/DropInPanel.h
- sdk_hdrs/DropInPanelWin32.h
- sdk_hdrs/DropInVCS.h
- sdk_hdrs/MWBrowse.h
- sdk_hdrs/MWLangDefs.h)
+ command_line/CmdLine/Src/CLWriteObjectFile.c)
diff --git a/command_line/CmdLine/Src/OSLib/FileHandles.c b/command_line/CmdLine/Src/OSLib/FileHandles.c
index e69de29..4609d77 100644
--- a/command_line/CmdLine/Src/OSLib/FileHandles.c
+++ b/command_line/CmdLine/Src/OSLib/FileHandles.c
@@ -0,0 +1,29 @@
+#include "oslib.h"
+
+static int OS_LoadFileHandle(OSFileHandle *hand) {
+
+}
+
+static int OS_WriteFileHandle(OSFileHandle *hand) {
+
+}
+
+int OS_NewFileHandle(const OSSpec *spec, OSHandle *src, Boolean writeable, OSFileHandle *hand) {
+
+}
+
+int OS_LockFileHandle(OSFileHandle *hand, Ptr *ptr, UInt32 *size) {
+
+}
+
+int OS_UnlockFileHandle(OSFileHandle *hand) {
+
+}
+
+int OS_FreeFileHandle(OSFileHandle *hand) {
+
+}
+
+void OS_GetFileHandleSpec(const OSFileHandle *hand, OSSpec *spec) {
+
+}
diff --git a/command_line/CmdLine/Src/OSLib/Generic.c b/command_line/CmdLine/Src/OSLib/Generic.c
index e69de29..4430790 100644
--- a/command_line/CmdLine/Src/OSLib/Generic.c
+++ b/command_line/CmdLine/Src/OSLib/Generic.c
@@ -0,0 +1,93 @@
+#include "oslib.h"
+
+static char wildname[63];
+static char wilddir[255];
+static OSOpenedDir wilddirref;
+static OSSpec wildmatch;
+char STSbuf[256];
+
+int WildCardMatch(const char *wild, const char *name) {
+ char next;
+ const char *prev;
+}
+
+OSSpec *OS_MatchPath(const char *path) {
+ char filename[64];
+ Boolean isfile;
+ OSSpec spec;
+ const char *nptr;
+}
+
+char *OS_GetFileNamePtr(char *path) {
+ char *ptr;
+}
+
+char *OS_GetDirName(const OSPathSpec *spec, char *buf, int size) {
+ char *path;
+ char *pptr;
+}
+
+int OS_MakeSpec2(const char *path, const char *filename, OSSpec *spec) {
+ char bpath[256];
+ char *eptr;
+ int pthlen;
+ int fnlen;
+}
+
+int OS_MakeSpecWithPath(OSPathSpec *path, const char *filename, Boolean noRelative, OSSpec *spec) {
+ Boolean relpath;
+ char buf[256];
+ char *mptr;
+ char *eptr;
+}
+
+int OS_NameSpecChangeExtension(OSNameSpec *spec, const char *ext, Boolean append) {
+ char tmp[64];
+ char *per;
+}
+
+int OS_NameSpecSetExtension(OSNameSpec *spec, const char *ext) {
+ char tmp[64];
+ char *per;
+}
+
+char *OS_CompactPaths(char *buf, const char *p, const char *n, int size) {
+ int plen;
+ int nlen;
+ char *ptr;
+ int bidx;
+}
+
+char *OS_SpecToStringRelative(const OSSpec *spec, const OSPathSpec *cwdspec, char *path, int size) {
+ char fullbuf[256];
+ char *full;
+ char cwfbuf[256];
+ char *cwd;
+ OSPathSpec mycwdspec;
+ char *pptr;
+}
+
+int OS_FindFileInPath(const char *filename, const char *plist, OSSpec *spec) {
+ char *next;
+ char path[256];
+ int err;
+}
+
+int OS_FindProgram(const char *filename, OSSpec *spec) {
+ char *plist;
+ int err;
+ char temp[256];
+}
+
+int OS_CopyHandle(OSHandle *hand, OSHandle *copy) {
+ int err;
+ UInt32 sz;
+ void *f;
+ void *t;
+}
+
+int OS_AppendHandle(OSHandle *hand, const void *data, UInt32 len) {
+ int err;
+ UInt32 sz;
+ void *buffer;
+}
diff --git a/command_line/CmdLine/Src/OSLib/MacFileTypes.c b/command_line/CmdLine/Src/OSLib/MacFileTypes.c
index e69de29..9d18723 100644
--- a/command_line/CmdLine/Src/OSLib/MacFileTypes.c
+++ b/command_line/CmdLine/Src/OSLib/MacFileTypes.c
@@ -0,0 +1,29 @@
+#include "oslib.h"
+
+void OS_AddFileTypeMappingList(OSFileTypeMappings **list, OSFileTypeMappingList *entry) {
+
+}
+
+void OS_UseFileTypeMappings(OSFileTypeMappings *list) {
+
+}
+
+void OS_MacType_To_OSType(OSType mactype, uOSTypePair *type) {
+
+}
+
+int OS_SetMacFileType(const OSSpec *spec, OSType mactype) {
+
+}
+
+Boolean OS_GetMacFileTypeMagic(const char *buffer, int count, OSType *mactype) {
+
+}
+
+int OS_GetMacFileType(const OSSpec *spec, OSType *mactype) {
+
+}
+
+int OS_SetMacFileCreatorAndType(const OSSpec *spec, OSType creator, OSType mactype) {
+
+}
diff --git a/command_line/CmdLine/Src/OSLib/MacSpecs.c b/command_line/CmdLine/Src/OSLib/MacSpecs.c
index e69de29..8648324 100644
--- a/command_line/CmdLine/Src/OSLib/MacSpecs.c
+++ b/command_line/CmdLine/Src/OSLib/MacSpecs.c
@@ -0,0 +1,25 @@
+#include "oslib.h"
+
+int OS_OSPathSpec_To_VolDir(const OSPathSpec *spec, SInt16 *vRefNum, SInt32 *dirID) {
+
+}
+
+int OS_OSSpec_To_FSSpec(const OSSpec *spec, FSSpec *fss) {
+
+}
+
+int OS_VolDir_To_OSNameSpec(SInt16 vRefNum, SInt32 dirID, OSNameSpec *spec, SInt32 *parID) {
+
+}
+
+int OS_VolDir_To_OSPathSpec(SInt16 vRefNum, SInt32 dirID, OSPathSpec *spec) {
+
+}
+
+int OS_FSSpec_To_OSSpec(const FSSpec *fss, OSSpec *spec) {
+
+}
+
+int OS_GetRsrcOSSpec(const OSSpec *spec, OSSpec *rspec, Boolean create) {
+
+}
diff --git a/command_line/CmdLine/Src/OSLib/MemUtils.c b/command_line/CmdLine/Src/OSLib/MemUtils.c
index e69de29..4eb611c 100644
--- a/command_line/CmdLine/Src/OSLib/MemUtils.c
+++ b/command_line/CmdLine/Src/OSLib/MemUtils.c
@@ -0,0 +1,21 @@
+#include "oslib.h"
+
+void *xmalloc(const char *what, int size) {
+
+}
+
+void *xcalloc(const char *what, int size) {
+
+}
+
+void *xrealloc(const char *what, void *old, int size) {
+
+}
+
+char *xstrdup(const char *str) {
+
+}
+
+void xfree(void *ptr) {
+
+}
diff --git a/command_line/CmdLine/Src/OSLib/Posix.c b/command_line/CmdLine/Src/OSLib/Posix.c
index e69de29..0711559 100644
--- a/command_line/CmdLine/Src/OSLib/Posix.c
+++ b/command_line/CmdLine/Src/OSLib/Posix.c
@@ -0,0 +1,866 @@
+#include "oslib.h"
+#include <dirent.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/times.h>
+#include <time.h>
+#include <utime.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+enum {
+ OSErrNeg2 = -2
+};
+
+static char *lastdlerr;
+static char intbuf[256];
+enum { MAX_PATH = 256 };
+
+#define CONVERT_SPEC(spec, pathbuf) \
+do { \
+int _plen = strlen((spec)->path.s); \
+int _nlen = strlen((spec)->name.s); \
+if (_plen + _nlen >= sizeof(pathbuf)) return 63; \
+memcpy((pathbuf), (spec)->path.s, _plen); \
+memcpy((pathbuf) + _plen, (spec)->name.s, _nlen + 1); \
+} while (0)
+
+#define CONVERT_PATHSPEC(spec, pathbuf) \
+do { \
+int _plen = strlen((spec)->s); \
+if (_plen >= sizeof(pathbuf)) return 63;\
+memcpy((pathbuf), (spec)->s, _plen + 1);\
+if (_plen > 1) { \
+if ((pathbuf)[_plen - 1] == '/') \
+(pathbuf)[_plen - 1] = 0; \
+} \
+} while (0)
+
+const char *OS_GetErrText(int err) {
+ if (err == -2) {
+ return !lastdlerr ? "Shared library function failed" : lastdlerr;
+ } else {
+ return strerror(err);
+ }
+}
+
+int OS_InitProgram(int *pArgc, const char ***pArgv) {
+ return 0;
+}
+
+int OS_TermProgram() {
+ return 0;
+}
+
+uOSTypePair OS_TEXTTYPE = {0666};
+
+int OS_Create(const OSSpec *spec, const uOSTypePair *type) {
+ int h;
+ int err;
+ CONVERT_SPEC(spec, intbuf);
+ h = open(intbuf, O_CREAT | O_TRUNC, type->perm);
+ if (h < 0)
+ return errno;
+ close(h);
+
+ err = OS_SetFileType(spec, type);
+ return (err < 1) ? EPERM : 0;
+}
+
+int OS_Status(const OSSpec *spec) {
+ struct stat st;
+ CONVERT_SPEC(spec, intbuf);
+ if (stat(intbuf, &st))
+ return errno;
+ else
+ return 0;
+}
+
+int OS_GetFileType(const OSSpec *spec, uOSTypePair *type) {
+ struct stat st;
+ CONVERT_SPEC(spec, intbuf);
+ if (stat(intbuf, &st) < 0)
+ return errno;
+ type->perm = st.st_mode;
+ return 0;
+}
+
+int OS_SetFileType(const OSSpec *spec, const uOSTypePair *type) {
+ int err, oldmask;
+
+ CONVERT_SPEC(spec, intbuf);
+ oldmask = umask(0) & UF_SETTABLE;
+ err = chmod(intbuf, type->perm & ~oldmask);
+ umask(oldmask);
+
+ if (err < 0)
+ return errno;
+ return 0;
+}
+
+int OS_GetFileTime(const OSSpec *spec, time_t *crtm, time_t *chtm) {
+ struct stat st;
+ CONVERT_SPEC(spec, intbuf);
+ if (stat(intbuf, &st) < 0)
+ return errno;
+ if (crtm)
+ *crtm = st.st_ctimespec.tv_sec;
+ if (chtm)
+ *chtm = st.st_mtimespec.tv_sec;
+ return 0;
+}
+
+int OS_SetFileTime(const OSSpec *spec, const time_t *crtm, const time_t *chtm) {
+ struct utimbuf buf;
+ struct stat st;
+ CONVERT_SPEC(spec, intbuf);
+ if (stat(intbuf, &st) < 0)
+ return errno;
+ buf.actime = chtm ? *chtm : st.st_atimespec.tv_sec;
+ buf.modtime = crtm ? *crtm : st.st_mtimespec.tv_sec;
+ if (utime(intbuf, &buf) < 0)
+ return errno;
+ return 0;
+}
+
+int OS_Open(const OSSpec *spec, OSOpenMode mode, int *ref) {
+ static int modetrans[4] = {
+ O_RDONLY,
+ O_WRONLY,
+ O_RDWR,
+ O_RDONLY | O_APPEND
+ };
+ CONVERT_SPEC(spec, intbuf);
+ *ref = open(intbuf, modetrans[mode]);
+ if (*ref < 0) {
+ *ref = -1;
+ return errno;
+ }
+ return 0;
+}
+
+int OS_Write(int ref, const void *buffer, UInt32 *length) {
+ struct stat st;
+ UInt32 pos;
+
+ if (fstat(ref, &st) < 0)
+ return errno;
+
+ pos = lseek(ref, 0, SEEK_CUR);
+ if (pos > st.st_size && !*length) {
+ lseek(ref, -1, SEEK_CUR);
+ if (write(ref, "", 1) != 1) {
+ *length = 0;
+ return errno;
+ }
+ }
+
+ *length = write(ref, buffer, *length);
+ if (((SInt32) *length) < 0)
+ return errno;
+ return 0;
+}
+
+int OS_Read(int ref, void *buffer, UInt32 *length) {
+ *length = read(ref, buffer, *length);
+ if (((SInt32) *length) < 0)
+ return errno;
+ return 0;
+}
+
+int OS_Seek(int ref, OSSeekMode how, SInt32 offset) {
+ static int howtrans[3] = {
+ SEEK_CUR,
+ SEEK_SET,
+ SEEK_END
+ };
+
+ return (lseek(ref, offset, howtrans[how]) < 0) ? errno : 0;
+}
+
+int OS_Tell(int ref, SInt32 *offset) {
+ *offset = lseek(ref, 0, SEEK_CUR);
+ if (*offset < 0)
+ return errno;
+ else
+ return 0;
+}
+
+int OS_Close(int ref) {
+ if (ref == -1)
+ return EBADF;
+
+ if (close(ref))
+ return errno;
+ else
+ return 0;
+}
+
+int OS_GetSize(int ref, UInt32 *length) {
+ struct stat st;
+ if (fstat(ref, &st) < 0) {
+ return errno;
+ } else {
+ *length = st.st_size;
+ return 0;
+ }
+}
+
+int OS_SetSize(int ref, UInt32 size) {
+ if (ftruncate(ref, size))
+ return errno;
+ else
+ return 0;
+}
+
+int OS_Delete(const OSSpec *spec) {
+ CONVERT_SPEC(spec, intbuf);
+ if (unlink(intbuf))
+ return errno;
+ else
+ return 0;
+}
+
+int OS_Rename(const OSSpec *oldspec, const OSSpec *newspec) {
+ char newbuf[256];
+ CONVERT_SPEC(newspec, newbuf);
+ CONVERT_SPEC(oldspec, intbuf);
+ return rename(intbuf, newbuf) ? errno : 0;
+}
+
+int OS_Mkdir(const OSSpec *spec) {
+ CONVERT_SPEC(spec, intbuf);
+ if (mkdir(intbuf, 0777))
+ return errno;
+ else
+ return 0;
+}
+
+int OS_Rmdir(const OSPathSpec *spec) {
+ CONVERT_PATHSPEC(spec, intbuf);
+ if (rmdir(intbuf))
+ return errno;
+ else
+ return 0;
+}
+
+int OS_Chdir(const OSPathSpec *spec) {
+ CONVERT_PATHSPEC(spec, intbuf);
+ if (chdir(intbuf))
+ return errno;
+ else
+ return 0;
+}
+
+int OS_GetCWD(OSPathSpec *spec) {
+ char *ptr;
+ if (!getcwd(spec->s, sizeof(spec->s)))
+ return errno;
+
+ ptr = &spec->s[strlen(spec->s)];
+ if (ptr[-1] != '/')
+ strcpy(ptr, "/");
+ return 0;
+}
+
+extern char **environ;
+int OS_Execute(OSSpec *spec, char **argv, char **envp, const char *stdoutfile, const char *stderrfile, int *exitcode) {
+ int svstdout;
+ int svstderr;
+ pid_t kidpid;
+ int status;
+ int err; // not in stabs but i think this exists...?
+
+ if (stdoutfile) {
+ svstdout = dup(1);
+ close(1);
+ if (open(stdoutfile, O_CREAT|O_TRUNC|O_WRONLY, 0666) < 0) {
+ status = errno;
+ dup2(svstdout, 1);
+ close(svstdout);
+ return status;
+ }
+ }
+
+ if (stderrfile) {
+ svstderr = dup(2);
+ close(2);
+ if (open(stderrfile, O_CREAT|O_TRUNC|O_WRONLY, 0666) < 0) {
+ status = errno;
+ dup2(svstderr, 2);
+ close(svstderr);
+ return status;
+ }
+ }
+
+ kidpid = fork();
+ if (!kidpid) {
+ if (execve(argv[0], argv, (envp && envp[0]) ? envp : environ) < 0)
+ exit(-1);
+ return EINVAL;
+ } else {
+ if (stdoutfile) {
+ dup2(svstdout, 1);
+ close(svstdout);
+ }
+ if (stderrfile) {
+ dup2(svstderr, 2);
+ close(svstderr);
+ }
+ *exitcode = 0;
+
+ err = (waitpid(kidpid, &status, 0) <= 0) ? errno : 0;
+
+ if (!(status & 0x7F))
+ *exitcode = status >> 8;
+
+ if ((status & 0x7F) != 0x7F && (status & 0x7F) != 0)
+ *exitcode = -(status & 0x7F);
+
+ return err;
+ }
+}
+
+int OS_IsLegalPath(const char *path) {
+ const char *scan = path;
+ int pthlen;
+ int fnlen;
+
+ pthlen = 0;
+ fnlen = 0;
+
+ while (*scan) {
+ if (*scan == '/')
+ fnlen = 0;
+ else
+ fnlen++;
+ ++pthlen;
+ if (fnlen > 63 || pthlen > 255)
+ return ENAMETOOLONG;
+ //if ((fnlen = (*scan == '/') ? 0 : (fnlen + 1)) > 63 || ++pthlen > 255)
+ // return ENAMETOOLONG;
+ ++scan;
+ }
+
+ return 0;
+}
+
+int OS_IsFullPath(const char *path) {
+ return path[0] == '/';
+}
+
+char *OS_GetDirPtr(char *path) {
+ return path;
+}
+
+static int OS_CompactPath(const char *src, char *dst) {
+ char buf[256];
+ char *bptr;
+ char *to;
+ char *from;
+ char *start;
+ char *brk;
+}
+
+int OS_EqualPath(const char *a, const char *b) {
+ return !strcmp(a, b);
+}
+
+int OS_CanonPath(char *src, char *dst) {
+ int idx;
+
+ if (strlen(src) > 255)
+ return ENAMETOOLONG;
+
+ if (!dst)
+ dst = src;
+
+ for (idx = 0; src[idx]; idx++) {
+ if (src[idx] == '\\')
+ dst[idx] = '/';
+ else
+ dst[idx] = src[idx];
+ }
+
+ dst[idx] = 0;
+ return 0;
+}
+
+int OS_MakeSpec(const char *path, OSSpec *spec, Boolean *isfile) {
+ char tmp[256];
+ struct stat st;
+ char *ptr;
+ int len;
+ int err;
+ char *end;
+ char orig[256];
+
+ spec->name.s[0] = 0;
+ spec->path.s[0] = 0;
+ err = OS_CanonPath((char *) path, tmp);
+ if (err)
+ return err;
+
+ if (!OS_IsFullPath(tmp)) {
+ strcpy(orig, tmp);
+ if (!getcwd(tmp, sizeof(tmp)))
+ return errno;
+
+ ptr = tmp + strlen(tmp) - 1;
+ if (ptr[0] != '/') {
+ ptr[1] = '/';
+ ptr[2] = 0;
+ ptr += 2;
+ }
+
+ if (((ptr - tmp) + strlen(orig)) >= 256)
+ return ENAMETOOLONG;
+
+ strcpy(ptr, orig);
+ } else {
+ if (strlen(tmp) >= 256)
+ return ENAMETOOLONG;
+ }
+
+ err = OS_CompactPath(tmp, 0);
+ if (err)
+ return err;
+ err = OS_IsLegalPath(tmp);
+ if (err)
+ return err;
+
+ if (!stat(tmp, &st)) {
+ ptr = tmp + strlen(tmp);
+ if (ptr[-1] == '/')
+ ptr--;
+ if ((st.st_mode & S_IFMT) == S_IFDIR) {
+ if (isfile)
+ *isfile = 0;
+ ptr[0] = '/';
+ ptr++;
+ } else {
+ if (isfile)
+ *isfile = 1;
+ }
+ *ptr = 0;
+ } else {
+ if (errno != ENOENT)
+ return errno;
+ if (isfile)
+ *isfile = 1;
+ }
+
+ ptr = strrchr(tmp, '/') + 1;
+ len = ptr - tmp;
+ if (len >= 256) {
+ spec->path.s[0] = 0;
+ return ENAMETOOLONG;
+ }
+
+ memcpy(spec->path.s, tmp, len);
+ spec->path.s[len] = 0;
+
+ len = strlen(ptr);
+ if (len >= 64) {
+ spec->name.s[0] = 0;
+ return ENAMETOOLONG;
+ }
+
+ memcpy(spec->name.s, ptr, len);
+ spec->name.s[len] = 0;
+
+ return 0;
+}
+
+int OS_MakeFileSpec(const char *path, OSSpec *spec) {
+ Boolean isfile;
+ int err;
+
+ err = OS_MakeSpec(path, spec, &isfile);
+ if (err)
+ return err;
+ else
+ return (isfile != 0) ? 0 : EISDIR;
+}
+
+int OS_MakePathSpec(const char *vol, const char *dir, OSPathSpec *spec) {
+ Boolean isfile;
+ OSSpec tmp;
+ int err;
+ char path[256];
+
+ if (((vol ? strlen(vol) : 0) + (dir ? strlen(dir) : 0) + 2) > 256)
+ return ENAMETOOLONG;
+
+ sprintf(path,
+ "%s%s%s",
+ vol ? (strchr("/\\:", vol[0]) ? "" : "/") : "",
+ vol ? vol : "",
+ dir ? dir : ""
+ );
+
+ err = OS_MakeSpec(path, &tmp, &isfile);
+ strcpy(spec->s, tmp.path.s);
+ if (err)
+ return err;
+
+ if (isfile)
+ return !OS_Status(&tmp) ? ENOTDIR : ENOENT;
+
+ return 0;
+}
+
+int OS_MakeNameSpec(const char *name, OSNameSpec *spec) {
+ int len;
+
+ len = strlen(name);
+ spec->s[0] = 0;
+ if (len > 63)
+ return ENAMETOOLONG;
+ if (strchr(name, '/'))
+ return EISDIR;
+ if (strlen(name) > 63)
+ return ENAMETOOLONG;
+ memcpy(spec->s, name, len + 1);
+ return 0;
+}
+
+int OS_GetRootSpec(OSPathSpec *spec) {
+ strcpy(spec->s, "/");
+ return 0;
+}
+
+char *OS_SpecToString(const OSSpec *spec, char *path, int size) {
+ int plen;
+ int nlen;
+
+ if (!size)
+ size = 256;
+
+ if (!path) {
+ path = malloc(size);
+ if (!path)
+ return 0;
+ }
+
+ plen = strlen(spec->path.s);
+ nlen = strlen(spec->name.s);
+ if ((plen + nlen) >= size) {
+ if (plen >= size) {
+ nlen = 0;
+ plen = size - 1;
+ } else {
+ nlen = (size - plen) - 1;
+ }
+ }
+
+ memcpy(path, spec->path.s, plen);
+ memcpy(&path[plen], spec->name.s, nlen);
+ path[plen + nlen] = 0;
+ return path;
+}
+
+char *OS_PathSpecToString(const OSPathSpec *pspec, char *path, int size) {
+ int plen;
+
+ if (!size)
+ size = 256;
+
+ if (!path) {
+ path = malloc(size);
+ if (!path)
+ return 0;
+ }
+
+ plen = strlen(pspec->s);
+ if (plen >= size)
+ plen = size - 1;
+
+ memcpy(path, pspec->s, plen);
+ path[plen] = 0;
+ return path;
+}
+
+char *OS_NameSpecToString(const OSNameSpec *nspec, char *name, int size) {
+ int nlen;
+
+ if (!size)
+ size = 64;
+
+ if (!name) {
+ name = malloc(size);
+ if (!name)
+ return 0;
+ }
+
+ nlen = strlen(nspec->s);
+ if (nlen >= size)
+ nlen = size - 1;
+
+ memcpy(name, nspec->s, nlen);
+ name[nlen] = 0;
+ return name;
+}
+
+int OS_SizeOfPathSpec(const OSPathSpec *spec) {
+ return strlen(spec->s) + 1;
+}
+
+int OS_SizeOfNameSpec(const OSNameSpec *spec) {
+ return strlen(spec->s) + 1;
+}
+
+int OS_EqualSpec(const OSSpec *a, const OSSpec *b) {
+ return OS_EqualPathSpec(&a->path, &b->path) && OS_EqualNameSpec(&a->name, &b->name);
+}
+
+int OS_EqualPathSpec(const OSPathSpec *a, const OSPathSpec *b) {
+ return !strcmp(a->s, b->s);
+}
+
+int OS_EqualNameSpec(const OSNameSpec *a, const OSNameSpec *b) {
+ return !strcmp(a->s, b->s);
+}
+
+int OS_IsDir(const OSSpec *spec) {
+ struct stat st;
+
+ if (!OS_SpecToString(spec, intbuf, sizeof(intbuf)))
+ return 0;
+ if (stat(intbuf, &st) < 0)
+ return 0;
+ return ((st.st_mode & S_IFMT) == S_IFDIR);
+}
+
+int OS_IsFile(const OSSpec *spec) {
+ struct stat st;
+
+ if (!OS_SpecToString(spec, intbuf, sizeof(intbuf)))
+ return 0;
+ if (stat(intbuf, &st) < 0)
+ return 0;
+ return ((st.st_mode & S_IFMT) != S_IFDIR);
+}
+
+int OS_IsLink(const OSSpec *spec) {
+ struct stat st;
+ char *ptr;
+
+ if (!OS_SpecToString(spec, intbuf, sizeof(intbuf)))
+ return 0;
+
+ ptr = intbuf + strlen(intbuf) - 1;
+ if (*ptr == '/')
+ *ptr = 0;
+
+ if (lstat(intbuf, &st) < 0)
+ return 0;
+
+ return ((st.st_mode & S_IFMT) == S_IFLNK);
+}
+
+int OS_ResolveLink(const OSSpec *link, OSSpec *target) {
+ char fn[64];
+ char path[256];
+ int len;
+
+ if (!OS_SpecToString(link, intbuf, sizeof(intbuf)))
+ return ENAMETOOLONG;
+
+ len = readlink(intbuf, fn, sizeof(fn));
+ if (len < 0)
+ return errno;
+ fn[len] = 0;
+
+ sprintf(path, "%s%s", (fn[0] != '/') ? link->path.s : "", fn);
+ return OS_MakeSpec(path, target, 0);
+}
+
+int OS_OpenDir(const OSPathSpec *spec, OSOpenedDir *ref) {
+ DIR *dptr;
+
+ CONVERT_PATHSPEC(spec, intbuf);
+ dptr = opendir(intbuf);
+ if (!dptr) {
+ ref->dir = 0;
+ return errno;
+ }
+
+ ref->spec = *spec;
+ ref->dir = dptr;
+ return 0;
+}
+
+int OS_ReadDir(OSOpenedDir *ref, OSSpec *spec, char *filename, Boolean *isfile) {
+ struct dirent *de;
+ char fn[256];
+ int err;
+ int len;
+
+ do {
+ de = readdir(ref->dir);
+ if (!de)
+ return ENOENT;
+ } while (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..") || (strlen(ref->spec.s) + strlen(de->d_name) >= 256));
+
+ len = strlen(ref->spec.s);
+ strncpy(fn, ref->spec.s, 255);
+ if (len < 256) {
+ strncpy(&fn[len], de->d_name, 255 - len);
+ fn[255] = 0;
+ } else {
+ return ENAMETOOLONG;
+ }
+
+ strncpy(filename, de->d_name, 63);
+ filename[63] = 0;
+
+ return OS_MakeSpec(fn, spec, isfile);
+}
+
+int OS_CloseDir(OSOpenedDir *ref) {
+ if (ref->dir)
+ return closedir(ref->dir);
+ else
+ return 0;
+}
+
+UInt32 OS_GetMilliseconds() {
+ struct tms tms;
+ return times(&tms) * 1000 / CLOCKS_PER_SEC;
+}
+
+void OS_GetTime(time_t *p) {
+ time(p);
+}
+
+int OS_NewHandle(UInt32 size, OSHandle *hand) {
+ hand->addr = 0;
+ hand->used = size;
+ hand->size = (size + 256) & ~255;
+ hand->addr = malloc(hand->size);
+ return !hand->addr ? ENOMEM : 0;
+}
+
+int OS_ResizeHandle(OSHandle *hand, UInt32 size) {
+ UInt32 nsize;
+ void *naddr;
+
+ nsize = (size + 256) & ~255;
+ naddr = realloc(hand->addr, nsize);
+ if (!naddr)
+ return ENOMEM;
+
+ hand->addr = naddr;
+ hand->size = nsize;
+ hand->used = size;
+ return 0;
+}
+
+void *OS_LockHandle(OSHandle *hand) {
+ return hand->addr;
+}
+
+void OS_UnlockHandle(OSHandle *hand) {
+}
+
+int OS_FreeHandle(OSHandle *hand) {
+ if (!hand->addr)
+ return ENOMEM;
+
+ free(hand->addr);
+ hand->size = 0;
+ hand->used = 0;
+ hand->addr = 0;
+ return 0;
+}
+
+int OS_GetHandleSize(OSHandle *hand, UInt32 *size) {
+ if (hand->addr) {
+ *size = hand->used;
+ return 0;
+ } else {
+ *size = 0;
+ return ENOMEM;
+ }
+}
+
+void OS_InvalidateHandle(OSHandle *hand) {
+ hand->addr = 0;
+ hand->used = 0;
+}
+
+Boolean OS_ValidHandle(OSHandle *hand) {
+ return (hand && hand->addr);
+}
+
+OSErr OS_MacError(int err) {
+ switch (err) {
+ case 0: return noErr;
+ case ENOENT /*2*/: return fnfErr;
+ case EFAULT /*14*/:
+ case EINVAL /*22*/: return paramErr;
+ case ENOTDIR /*20*/: return dirNFErr;
+ case EISDIR /*21*/: return notAFileErr;
+ case ENAMETOOLONG /*63*/: return bdNamErr;
+ case EBUSY /*16*/: return memLockedErr;
+ case E2BIG /*7*/:
+ case ENOMEM /*12*/: return memFullErr;
+ case EACCES /*13*/: return permErr;
+ case EIO /*5*/: return ioErr;
+ case EEXIST /*17*/: return dupFNErr;
+ case EMFILE /*24*/: return tmfoErr;
+ case EFBIG /*27*/: return fsDataTooBigErr;
+ case EBADF /*9*/: return rfNumErr;
+ case EINTR /*4*/: return abortErr;
+ default: return (OSErr) (0xFFFF8000 | err);
+ }
+}
+
+void OS_TimeToMac(time_t sectm, UInt32 *secs) {
+ struct tm *tmrec;
+ int years;
+ int ydays;
+
+ tmrec = localtime(&sectm);
+ // this is horrendous lol
+}
+
+void OS_MacToTime(UInt32 secs, time_t *sectm) {
+ struct tm tmrec;
+ int month;
+}
+
+SInt16 OS_RefToMac(int ref) {
+ //return (ref >= -1) ? (ref + 1) : ref;
+ // wtf is going on here augh
+}
+
+int OS_MacToRef(SInt16 refnum) {
+ return (refnum >= 0) ? (refnum - 1) : -1;
+}
+
+int OS_OpenLibrary(const char *a, void **lib) {
+ *lib = 0;
+ lastdlerr = "No support for shared libraries";
+ return OSErrNeg2;
+}
+
+int OS_GetLibrarySymbol(void *a, void *b, void **sym) {
+ *sym = 0;
+ lastdlerr = "No support for shared libraries";
+ return OSErrNeg2;
+}
+
+int OS_CloseLibrary(void *a) {
+ lastdlerr = "No support for shared libraries";
+ return OSErrNeg2;
+}
+
+int OS_LoadMacResourceFork(const OSSpec *spec, void **file_data, SInt32 *file_len) {
+ return ENOENT;
+}
+
+int OS_IsMultiByte(const char *str, int offset) {
+ return 0;
+}
diff --git a/command_line/CmdLine/Src/OSLib/StringExtras.c b/command_line/CmdLine/Src/OSLib/StringExtras.c
index e69de29..04ef6b4 100644
--- a/command_line/CmdLine/Src/OSLib/StringExtras.c
+++ b/command_line/CmdLine/Src/OSLib/StringExtras.c
@@ -0,0 +1,17 @@
+#include "oslib.h"
+
+char *strcatn(char *d, const char *s, SInt32 max) {
+
+}
+
+char *strcpyn(char *d, const char *s, SInt32 len, SInt32 max) {
+
+}
+
+int ustrcmp(const char *src, const char *dst) {
+
+}
+
+int ustrncmp(const char *src, const char *dst, UInt32 len) {
+
+}
diff --git a/command_line/CmdLine/Src/OSLib/StringUtils.c b/command_line/CmdLine/Src/OSLib/StringUtils.c
index e69de29..5f0d5bd 100644
--- a/command_line/CmdLine/Src/OSLib/StringUtils.c
+++ b/command_line/CmdLine/Src/OSLib/StringUtils.c
@@ -0,0 +1,49 @@
+#include "oslib.h"
+
+StringPtr _pstrcpy(StringPtr dst, ConstStringPtr src) {
+
+}
+
+void _pstrcat(StringPtr dst, ConstStringPtr src) {
+
+}
+
+void _pstrcharcat(StringPtr to, char ch) {
+
+}
+
+void pstrncpy(StringPtr to, ConstStringPtr from, int max) {
+
+}
+
+void pstrncat(StringPtr to, ConstStringPtr append, int max) {
+
+}
+
+int pstrcmp(ConstStringPtr a, ConstStringPtr b) {
+
+}
+
+int pstrchr(ConstStringPtr str, char find) {
+
+}
+
+void c2pstrcpy(StringPtr dst, const char *src) {
+
+}
+
+void p2cstrcpy(char *dst, ConstStringPtr src) {
+
+}
+
+char *mvprintf(char *mybuf, unsigned int len, const char *format, va_list va) {
+
+}
+
+char *mprintf(char *mybuf, unsigned int len, const char *format, ...) {
+
+}
+
+int HPrintF(Handle text, const char *format, ...) {
+
+}
diff --git a/includes/common.h b/includes/common.h
new file mode 100644
index 0000000..8f9c346
--- /dev/null
+++ b/includes/common.h
@@ -0,0 +1,266 @@
+#pragma once
+
+/*
+ * Common imports and Mac OS types
+ */
+#include <ctype.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#ifdef __MWERKS__
+#define macintosh
+//#include <MacHeadersMach-O>
+#define CW_PASCAL pascal
+#undef toupper
+#else
+#include <stdarg.h>
+// expand this to nothing
+#define CW_PASCAL
+#endif
+
+// ----------
+// MacTypes.h
+typedef uint8_t UInt8;
+typedef int8_t SInt8;
+typedef uint16_t UInt16;
+typedef int16_t SInt16;
+typedef uint32_t UInt32;
+typedef int32_t SInt32;
+typedef uint64_t UInt64;
+typedef int64_t SInt64;
+
+typedef char *Ptr;
+typedef Ptr *Handle;
+typedef int32_t Size;
+
+typedef SInt16 OSErr;
+typedef SInt32 OSStatus;
+typedef SInt16 ScriptCode;
+typedef UInt32 FourCharCode;
+typedef FourCharCode OSType;
+typedef FourCharCode ResType;
+typedef OSType *OSTypePtr;
+typedef ResType *ResTypePtr;
+
+typedef uint8_t Boolean;
+
+enum {
+ noErr = 0,
+ abortErr = -27,
+ ioErr = -36,
+ bdNamErr = -37,
+ tmfoErr = -42,
+ fnfErr = -43, // file not found
+ dupFNErr = -48, // duplicate filename
+ paramErr = -50,
+ rfNumErr = -51,
+ permErr = -54,
+ memFullErr = -108, // not enough memory
+ nilHandleErr = -109, // pointer was nil
+ memLockedErr = -117,
+ dirNFErr = -120,
+ inputOutOfBounds = -190,
+ resNotFound = -192, // resource not found
+ resFNotFound = -193, // resource file not found
+ addResFailed = -194, // AddResource failed
+ rmvResFailed = -196, // RmveResource failed
+ resAttrErr = -198, // inconsistent attribute
+ mapReadErr = -199, // map inconsistent with operation
+ notAFileErr = -1302,
+ fsDataTooBigErr = -1310
+};
+enum { kNilOptions = 0 };
+enum { kUnknownType = 0x3F3F3F3F };
+
+// Pascal strings
+typedef unsigned char Str255[256];
+typedef unsigned char Str63[64];
+typedef unsigned char *StringPtr;
+typedef const unsigned char *ConstStringPtr;
+typedef const unsigned char *ConstStr63Param;
+typedef const unsigned char *ConstStr255Param;
+// XXX: MacTypes.h defines StrLength() which is an inline for C++ and a macro for C
+// This might be useful?
+
+#ifdef __MWERKS__
+#pragma options align=mac68k
+#endif
+typedef struct Point {
+ SInt16 v, h;
+} Point;
+
+typedef struct Rect {
+ SInt16 top, left, bottom, right;
+} Rect;
+
+// -------
+// Files.h
+enum {
+ fsCurPerm = 0x00,
+ fsRdPerm = 0x01,
+ fsWrPerm = 0x02,
+ fsRdWrPerm = 0x03,
+ fsRdWrShPerm = 0x04,
+ fsRdDenyPerm = 0x10,
+ fsWrDenyPerm = 0x20
+};
+enum {
+ fsAtMark = 0,
+ fsFromStart = 1,
+ fsFromLEOF = 2,
+ fsFromMark = 3
+};
+
+typedef struct FSSpec {
+ SInt16 vRefNum;
+ SInt32 parID;
+ Str255 name;
+} FSSpec;
+
+typedef struct FInfo {
+ OSType fdType;
+ OSType fdCreator;
+ UInt16 fdFlags;
+ Point fdLocation;
+ SInt16 fdFldr;
+} FInfo;
+
+typedef struct FXInfo {
+ SInt16 fdIconID;
+ SInt16 fdUnused[3];
+ SInt8 fdScript;
+ SInt8 fdXFlags;
+ SInt16 fdComment;
+ SInt32 fdPutAway;
+} FXInfo;
+
+typedef struct DInfo {
+ Rect frRect;
+ SInt16 frFlags;
+ Point frLocation;
+ SInt16 frView;
+} DInfo;
+
+typedef struct DXInfo {
+ Point frScroll;
+ SInt32 frOpenChain;
+ SInt16 frUnused;
+ SInt16 frComment;
+ SInt32 frPutAway;
+} DXInfo;
+
+typedef struct IOParam {
+ SInt16 ioResult;
+ SInt16 ioRefNum;
+ char *ioBuffer;
+ SInt32 ioReqCount;
+ SInt32 ioActCount;
+ SInt16 ioPosMode;
+ SInt32 ioPosOffset;
+} IOParam;
+
+typedef union ParamBlockRec {
+ IOParam ioParam;
+} ParamBlockRec;
+typedef ParamBlockRec *ParmBlkPtr;
+
+typedef struct HFileParam {
+ void *qLink;
+ SInt16 qType;
+ SInt16 ioTrap;
+ Ptr ioCmdAddr;
+ void *ioCompletion;
+ SInt16 ioResult;
+ StringPtr ioNamePtr;
+ SInt16 ioVRefNum;
+ SInt16 ioFRefNum;
+ SInt8 ioFVersNum;
+ SInt8 filler1;
+ SInt16 ioFDirIndex;
+ SInt8 ioFlAttrib;
+ SInt8 ioFlVersNum;
+ FInfo ioFlFndrInfo;
+ SInt32 ioDirID;
+ UInt16 ioFlStBlk;
+ SInt32 ioFlLgLen;
+ SInt32 ioFlPyLen;
+ UInt16 ioFlRStBlk;
+ SInt32 ioFlRLgLen;
+ SInt32 ioFlRPyLen;
+ UInt32 ioFlCrDat;
+ UInt32 ioFlMdDat;
+} HFileParam;
+
+typedef union HParamBlockRec {
+ HFileParam fileParam;
+} HParamBlockRec;
+typedef HParamBlockRec *HParmBlkPtr;
+
+typedef struct HFileInfo {
+ void *qLink;
+ SInt16 qType;
+ SInt16 ioTrap;
+ Ptr ioCmdAddr;
+ void *ioCompletion;
+ SInt16 ioResult;
+ StringPtr ioNamePtr;
+ SInt16 ioVRefNum;
+ SInt16 ioFRefNum;
+ SInt8 ioFVersNum;
+ SInt8 filler1;
+ SInt16 ioFDirIndex;
+ SInt8 ioFlAttrib;
+ SInt8 ioACUser;
+ FInfo ioFlFndrInfo;
+ SInt32 ioDirID;
+ UInt16 ioFlStBlk;
+ SInt32 ioFlLgLen;
+ SInt32 ioFlPyLen;
+ UInt16 ioFlRStBlk;
+ SInt32 ioFlRLgLen;
+ SInt32 ioFlRPyLen;
+ UInt32 ioFlCrDat;
+ UInt32 ioFlMdDat;
+ UInt32 ioFlBkDat;
+ FXInfo ioFlXFndrInfo;
+ SInt32 ioFlParID;
+ SInt32 ioFlClpSiz;
+} HFileInfo;
+typedef struct DirInfo {
+ void *qLink;
+ SInt16 qType;
+ SInt16 ioTrap;
+ Ptr ioCmdAddr;
+ void *ioCompletion;
+ SInt16 ioResult;
+ StringPtr ioNamePtr;
+ SInt16 ioVRefNum;
+ SInt16 ioFRefNum;
+ SInt8 ioFVersNum;
+ SInt8 filler1;
+ SInt16 ioFDirIndex;
+ SInt8 ioFlAttrib;
+ SInt8 ioACUser;
+ DInfo ioDrUsrWds;
+ SInt32 ioDrDirID;
+ UInt16 ioDrNmFls;
+ SInt16 filler3[9];
+ UInt32 ioDrCrDat;
+ UInt32 ioDrMdDat;
+ UInt32 ioDrBkDat;
+ DXInfo ioDrFndrInfo;
+ SInt32 ioDrParID;
+} DirInfo;
+
+typedef union CInfoPBRec {
+ HFileInfo hFileInfo;
+ DirInfo hDirInfo;
+} CInfoPBRec;
+typedef CInfoPBRec *CInfoPBPtr;
+
+#ifdef __MWERKS__
+#pragma options align=reset
+#endif
diff --git a/includes/macemul.h b/includes/macemul.h
new file mode 100644
index 0000000..03b6c68
--- /dev/null
+++ b/includes/macemul.h
@@ -0,0 +1,168 @@
+#pragma once
+#include "common.h"
+#include "oslib.h"
+
+/**
+ * Functions emulating classic Mac OS on other OSes
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/********************************/
+/* ErrMgr */
+extern char *GetSysErrText(SInt16 msgNbr, char *errMsg);
+
+/********************************/
+/* Files */
+extern OSErr HCreate(SInt16 volume, SInt32 dirid, ConstStr255Param fileName, OSType creator, OSType type);
+extern OSErr HOpen(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, SInt8 permission, SInt16 *refNum);
+extern OSErr HOpenDF(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, SInt8 permission, SInt16 *refNum);
+extern OSErr HDelete(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName);
+extern OSErr HRename(SInt16 vRefNum, SInt32 dirID, ConstStr255Param oldName, ConstStr255Param newName);
+extern OSErr HGetFInfo(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, FInfo *fndrInfo);
+extern OSErr HSetFInfo(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, const FInfo *fndrInfo);
+extern OSErr FSpCreate(const FSSpec *fss, OSType creator, OSType fileType, ScriptCode scriptTag);
+extern OSErr FSpDirCreate(const FSSpec *fss, ScriptCode scriptTag, SInt32 *createdDirID);
+extern OSErr FSpOpenDF(const FSSpec *fss, SInt8 permission, SInt16 *refNum);
+extern OSErr FSpDelete(const FSSpec *fss);
+extern OSErr FSpRename(const FSSpec *oldfss, ConstStr255Param newName);
+extern OSErr FSpGetFInfo(const FSSpec *fss, FInfo *fndrInfo);
+extern OSErr FSpSetFInfo(const FSSpec *fss, const FInfo *fndrInfo);
+extern OSErr HGetVol(StringPtr volName, SInt16 *vRefNum, SInt32 *dirID);
+extern OSErr HSetVol(ConstStr63Param volName, SInt16 vRefNum, SInt32 dirID);
+extern OSErr FlushVol(ConstStr63Param volName, SInt16 vRefNum);
+extern OSErr FSRead(SInt16 fRefNum, SInt32 *Size, void *Buffer);
+extern OSErr FSWrite(SInt16 fRefNum, SInt32 *Size, const void *Buffer);
+extern OSErr FSClose(SInt16 fRefNum);
+extern OSErr GetEOF(SInt16 fRefNum, SInt32 *curEOF);
+extern OSErr SetEOF(SInt16 fRefNum, SInt32 newEOF);
+extern OSErr GetFPos(SInt16 fRefNum, SInt32 *pos);
+extern OSErr SetFPos(SInt16 fRefNum, SInt16 posMode, SInt32 posOffset);
+extern OSErr GetVInfo(SInt16 vRefNum, StringPtr name, SInt16 *vRef, SInt32 *hDir);
+extern OSErr PBWriteSync(ParmBlkPtr paramBlock);
+extern OSErr PBHGetFInfoSync(HParmBlkPtr paramBlock);
+extern OSErr PBHSetFInfoSync(HParmBlkPtr paramBlock);
+extern OSErr PBGetCatInfoSync(CInfoPBPtr paramBlock);
+extern OSErr ResolveAliasFile(FSSpec *fss, Boolean resolveChains, Boolean *isFolder, Boolean *wasAliased);
+extern OSErr FSMakeFSSpec(SInt16 vRefNum, SInt32 dirID, ConstStr255Param pathName, FSSpec *fss);
+extern OSErr Allocate(SInt16 refNum, SInt32 *byteCount);
+
+/********************************/
+/* LowMem */
+extern UInt32 LMGetTicks();
+extern UInt32 LMGetTime();
+extern OSErr LMGetMemErr();
+extern void LMSetMemErr(OSErr value);
+
+/********************************/
+/* Memory */
+extern OSHandle *OS_PeekMacHandle(Handle h);
+extern Handle OS_CreateMacHandle(OSHandle *h);
+extern Handle OS_CreateMacHandleDup(OSHandle *h);
+extern void OS_DestroyMacHandle(Handle h, OSHandle *ret);
+
+extern OSErr MemError();
+extern Handle NewHandle(SInt32 dataSize);
+extern Handle NewHandleClear(UInt32 dataSize);
+extern Handle TempNewHandle(UInt32 dataSize, OSErr *resultCode);
+extern void DisposeHandle(Handle h);
+extern void HLock(Handle h);
+extern void HLockHi(Handle h);
+extern void HUnlock(Handle h);
+extern void HPurge(Handle theHandle);
+extern void HNoPurge(Handle theHandle);
+extern SInt8 HGetState(Handle theHandle);
+extern void HSetState(Handle theHandle, SInt8 flags);
+extern SInt32 GetHandleSize(Handle h);
+extern void SetHandleSize(Handle h, SInt32 newSize);
+extern OSErr PtrAndHand(const void *srcPtr, Handle destHandle, SInt32 size);
+extern OSErr PtrToHand(const void *srcPtr, Handle *destHandle, SInt32 size);
+extern OSErr HandToHand(Handle *destHandle);
+extern OSErr HandAndHand(Handle src, Handle dst);
+extern void MoveHHi(Handle theHandle);
+extern void BlockMove(const void *srcPtr, void *destPtr, UInt32 byteCount);
+extern void BlockMoveData(const void *srcPtr, void *destPtr, UInt32 byteCount);
+extern Ptr NewPtr(SInt32 dataSize);
+extern void DisposePtr(Ptr p);
+extern Ptr NewPtrClear(SInt32 dataSize);
+extern void DebugStr(ConstStringPtr str);
+extern struct Zone *HandleZone();
+extern struct Zone *ApplicationZone();
+
+/********************************/
+/* Resources */
+extern Boolean OS_UsingMacResourceForkInfo();
+extern void OS_UseMacResourceForkInfo(Boolean which);
+extern OSErr SystemInitResources(OSSpec *spec);
+extern void OS_AddMacResourceForkRef(int ref, const OSSpec *spec);
+extern void OS_RemoveMacResourceForkRef(int ref);
+extern OSSpec *OS_GetMacResourceForkFromRef(int ref);
+extern Boolean OS_SearchMacResourceForkList(const OSSpec *rspec, int *ref);
+extern int OS_SetMacResourceForkCreatorAndType(int ref, OSType creator, OSType type);
+extern int OS_GetMacResourceForkCreatorAndType(int ref, OSType *creator, OSType *type);
+extern void OS_CleanupMacResourceForkDir(const OSPathSpec *dir);
+extern OSErr OS_MacDumpResourceFork(SInt16 ref, Boolean dumpContents);
+extern OSErr FSpOpenRF(const FSSpec *fss, SInt8 permission, SInt16 *refNum);
+extern OSErr HOpenRF(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName, SInt8 permission, SInt16 *refNum);
+extern OSErr InitResources();
+extern OSErr ResError();
+extern void FSpCreateResFile(const FSSpec *fss, OSType creator, OSType fileType, ScriptCode scriptTag);
+extern void HCreateResFile(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName);
+extern OSErr FSpOpenResFile(const FSSpec *fss, SInt8 permission);
+extern SInt16 HOpenResFile(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName, SInt8 permission);
+extern SInt16 CurResFile();
+extern void UseResFile(SInt16 refNum);
+extern SInt16 HomeResFile(Handle theResource);
+extern Handle GetResource(OSType theType, SInt16 theID);
+extern Handle Get1Resource(OSType theType, SInt16 theID);
+extern Handle GetNamedResource(OSType theType, ConstStringPtr theName);
+extern Handle Get1NamedResource(OSType theType, ConstStringPtr theName);
+extern void SetResLoad(Boolean load);
+extern void MacEmul_LoadResource(Handle theResource);
+extern void GetResInfo(Handle theResource, SInt16 *theID, OSType *theType, StringPtr name);
+extern void SetResInfo(Handle theResource, SInt16 theID, ConstStringPtr name);
+extern SInt16 GetResAttrs(Handle theResource);
+extern void SetResAttrs(Handle theResource, SInt16 attrs);
+extern void ChangedResource(Handle theResource);
+extern void AddResource(Handle theData, OSType theType, SInt16 theID, ConstStringPtr name);
+extern void UpdateResFile(SInt16 refnum);
+extern void WriteResource(Handle theResource);
+extern void SetResPurge(Boolean install);
+extern SInt16 CountResources(OSType theType);
+extern SInt16 Count1Resources(OSType theType);
+extern Handle GetIndResource(OSType theType, SInt16 index);
+extern Handle Get1IndResource(OSType theType, SInt16 index);
+extern SInt16 Count1Types();
+extern void Get1IndType(OSType *theType, SInt16 index);
+extern void ReleaseResource();
+extern void DetachResource(Handle theResource);
+extern void RemoveResource(Handle theResource);
+extern void CloseResFile(SInt16 refNum);
+extern SInt16 GetResFileAttrs(SInt16);
+extern Boolean LMGetResLoad();
+
+/********************************/
+/* ResourceStrings */
+extern void Res_Initialize();
+extern int Res_AddResource(const char *name, SInt16 rsrcid, const char **strings);
+extern const char *Res_GetResource(SInt16 rsrcid, SInt16 index);
+extern void Res_Cleanup();
+
+/********************************/
+/* TextUtils */
+extern StringPtr c2pstr(char *s);
+extern char *p2cstr(StringPtr s);
+extern SInt16 CharacterByteType(Ptr textBuf, SInt16 textOffset, ScriptCode script);
+extern SInt16 CharByte();
+extern void GetDateTime(UInt32 *secs);
+extern Boolean EqualString(ConstStr255Param strA, ConstStr255Param strB, Boolean caseSens, Boolean diacSens);
+extern void GetIndString(Str255 theString, SInt16 strListID, SInt16 index);
+extern char *getindstring(char *theString, SInt16 strListID, SInt16 index);
+extern void NumToString(SInt32 theNum, Str255 theString);
+extern void StringToNum(ConstStr255Param theString, SInt32 *theNum);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/includes/mwcc_decomp.h b/includes/mwcc_decomp.h
index bc9d071..5efb2a1 100644
--- a/includes/mwcc_decomp.h
+++ b/includes/mwcc_decomp.h
@@ -1,301 +1,13 @@
#pragma once
-
-#ifdef __MWERKS__
-#define macintosh
-//#include <MacHeadersMach-O>
-#define CW_PASCAL pascal
-#include <ctype.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#undef toupper
-#else
-#include <ctype.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-// expand this to nothing
-#define CW_PASCAL
-#endif
-
-// MacOS nonsense
-
-// ----------
-// MacTypes.h
-typedef uint8_t UInt8;
-typedef int8_t SInt8;
-typedef uint16_t UInt16;
-typedef int16_t SInt16;
-typedef uint32_t UInt32;
-typedef int32_t SInt32;
-typedef uint64_t UInt64;
-typedef int64_t SInt64;
-
-typedef char *Ptr;
-typedef Ptr *Handle;
-typedef int32_t Size;
-
-typedef SInt16 OSErr;
-typedef SInt32 OSStatus;
-typedef SInt16 ScriptCode;
-typedef UInt32 FourCharCode;
-typedef FourCharCode OSType;
-typedef FourCharCode ResType;
-typedef OSType *OSTypePtr;
-typedef ResType *ResTypePtr;
-
-typedef uint8_t Boolean;
-
-enum {
- noErr = 0,
- fnfErr = -43, // file not found
- dupFNErr = -48, // duplicate filename
- memFullErr = -108, // not enough memory
- nilHandleErr = -109, // pointer was nil
- inputOutOfBounds = -190,
- resNotFound = -192, // resource not found
- resFNotFound = -193, // resource file not found
- addResFailed = -194, // AddResource failed
- rmvResFailed = -196, // RmveResource failed
- resAttrErr = -198, // inconsistent attribute
- mapReadErr = -199 // map inconsistent with operation
-};
-enum { kNilOptions = 0 };
-enum { kUnknownType = 0x3F3F3F3F };
-
-// Pascal strings
-typedef unsigned char Str255[256];
-typedef unsigned char Str63[64];
-typedef unsigned char *StringPtr;
-typedef const unsigned char *ConstStringPtr;
-typedef const unsigned char *ConstStr63Param;
-typedef const unsigned char *ConstStr255Param;
-// XXX: MacTypes.h defines StrLength() which is an inline for C++ and a macro for C
-// This might be useful?
-
-#ifdef __MWERKS__
-#pragma options align=mac68k
-#endif
-typedef struct Point {
- SInt16 v, h;
-} Point;
-
-typedef struct Rect {
- SInt16 top, left, bottom, right;
-} Rect;
-#ifdef __MWERKS__
-#pragma options align=reset
-#endif
-
-// -------
-// Files.h
-#ifdef __MWERKS__
-#pragma options align=mac68k
-#endif
-enum {
- fsCurPerm = 0x00,
- fsRdPerm = 0x01,
- fsWrPerm = 0x02,
- fsRdWrPerm = 0x03,
- fsRdWrShPerm = 0x04,
- fsRdDenyPerm = 0x10,
- fsWrDenyPerm = 0x20
-};
-enum {
- fsAtMark = 0,
- fsFromStart = 1,
- fsFromLEOF = 2,
- fsFromMark = 3
-};
-
-typedef struct FSSpec {
- SInt16 vRefNum;
- SInt32 parID;
- Str255 name;
-} FSSpec;
-
-typedef struct FInfo {
- OSType fdType;
- OSType fdCreator;
- UInt16 fdFlags;
- Point fdLocation;
- SInt16 fdFldr;
-} FInfo;
-
-typedef struct FXInfo {
- SInt16 fdIconID;
- SInt16 fdUnused[3];
- SInt8 fdScript;
- SInt8 fdXFlags;
- SInt16 fdComment;
- SInt32 fdPutAway;
-} FXInfo;
-
-typedef struct DInfo {
- Rect frRect;
- SInt16 frFlags;
- Point frLocation;
- SInt16 frView;
-} DInfo;
-
-typedef struct DXInfo {
- Point frScroll;
- SInt32 frOpenChain;
- SInt16 frUnused;
- SInt16 frComment;
- SInt32 frPutAway;
-} DXInfo;
-
-typedef struct IOParam {
- SInt16 ioResult;
- SInt16 ioRefNum;
- char *ioBuffer;
- SInt32 ioReqCount;
- SInt32 ioActCount;
- SInt16 ioPosMode;
- SInt32 ioPosOffset;
-} IOParam;
-typedef union ParamBlockRec {
- IOParam ioParam;
-} ParamBlockRec;
-typedef ParamBlockRec *ParmBlkPtr;
-
-typedef struct HFileParam {
- void *qLink;
- SInt16 qType;
- SInt16 ioTrap;
- Ptr ioCmdAddr;
- void *ioCompletion;
- SInt16 ioResult;
- StringPtr ioNamePtr;
- SInt16 ioVRefNum;
- SInt16 ioFRefNum;
- SInt8 ioFVersNum;
- SInt8 filler1;
- SInt16 ioFDirIndex;
- SInt8 ioFlAttrib;
- SInt8 ioFlVersNum;
- FInfo ioFlFndrInfo;
- SInt32 ioDirID;
- UInt16 ioFlStBlk;
- SInt32 ioFlLgLen;
- SInt32 ioFlPyLen;
- UInt16 ioFlRStBlk;
- SInt32 ioFlRLgLen;
- SInt32 ioFlRPyLen;
- UInt32 ioFlCrDat;
- UInt32 ioFlMdDat;
-} HFileParam;
-typedef union HParamBlockRec {
- HFileParam fileParam;
-} HParamBlockRec;
-typedef HParamBlockRec *HParmBlkPtr;
-
-typedef struct HFileInfo {
- void *qLink;
- SInt16 qType;
- SInt16 ioTrap;
- Ptr ioCmdAddr;
- void *ioCompletion;
- SInt16 ioResult;
- StringPtr ioNamePtr;
- SInt16 ioVRefNum;
- SInt16 ioFRefNum;
- SInt8 ioFVersNum;
- SInt8 filler1;
- SInt16 ioFDirIndex;
- SInt8 ioFlAttrib;
- SInt8 ioACUser;
- FInfo ioFlFndrInfo;
- SInt32 ioDirID;
- UInt16 ioFlStBlk;
- SInt32 ioFlLgLen;
- SInt32 ioFlPyLen;
- UInt16 ioFlRStBlk;
- SInt32 ioFlRLgLen;
- SInt32 ioFlRPyLen;
- UInt32 ioFlCrDat;
- UInt32 ioFlMdDat;
- UInt32 ioFlBkDat;
- FXInfo ioFlXFndrInfo;
- SInt32 ioFlParID;
- SInt32 ioFlClpSiz;
-} HFileInfo;
-typedef struct DirInfo {
- void *qLink;
- SInt16 qType;
- SInt16 ioTrap;
- Ptr ioCmdAddr;
- void *ioCompletion;
- SInt16 ioResult;
- StringPtr ioNamePtr;
- SInt16 ioVRefNum;
- SInt16 ioFRefNum;
- SInt8 ioFVersNum;
- SInt8 filler1;
- SInt16 ioFDirIndex;
- SInt8 ioFlAttrib;
- SInt8 ioACUser;
- DInfo ioDrUsrWds;
- SInt32 ioDrDirID;
- UInt16 ioDrNmFls;
- SInt16 filler3[9];
- UInt32 ioDrCrDat;
- UInt32 ioDrMdDat;
- UInt32 ioDrBkDat;
- DXInfo ioDrFndrInfo;
- SInt32 ioDrParID;
-} DirInfo;
-typedef union CInfoPBRec {
- HFileInfo hFileInfo;
- DirInfo hDirInfo;
-} CInfoPBRec;
-typedef CInfoPBRec *CInfoPBPtr;
-#ifdef __MWERKS__
-#pragma options align=reset
-#endif
-
-//#include "../sdk_hdrs/CompilerMapping.h"
-//#include "../sdk_hdrs/DropInCompilerLinker.h"
+#include "common.h"
+#include "oslib.h"
+#include "macemul.h"
#ifdef __cplusplus
extern "C" {
#endif
/********************************/
-/* OS Garbage */
-typedef struct OSPathSpec {
- char s[256];
-} OSPathSpec;
-typedef struct OSNameSpec {
- char s[64];
-} OSNameSpec;
-typedef struct OSSpec {
- OSPathSpec path;
- OSNameSpec name;
-} OSSpec;
-
-typedef struct OSHandle {
- void *addr;
- UInt32 used;
- UInt32 size;
-} OSHandle;
-
-typedef struct {
- OSSpec spec;
- OSHandle hand;
- Boolean loaded;
- Boolean changed;
- Boolean writeable;
-} OSFileHandle; // assumed name
-
-/********************************/
/* Option Fuckery */
#ifdef __MWERKS__
#pragma options align=packed
@@ -1024,19 +736,6 @@ typedef struct {
int stdout_written;
} CLState; // assumed name
-typedef struct OSFileTypeMapping {
- OSType mactype;
- const char *magic;
- char length;
- const char *mimetype;
- char executable; // not sure why this is rearranged
-} OSFileTypeMapping;
-
-typedef struct OSFileTypeMappingList {
- SInt16 numMappings;
- const OSFileTypeMapping *mappings;
-} OSFileTypeMappingList;
-
typedef struct BasePluginCallbacks {
SInt16 (*main)(void *context);
SInt16 (*GetDropInFlags)(const DropInFlags **flags, SInt32 *flagsSize);
@@ -1403,10 +1102,6 @@ extern Plugin *Plugins_GetCompilerForLinker(Plugin *list, Plugin *linker, OSType
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);
-typedef struct OSFileTypeMappings {
- OSFileTypeMappingList *mappingList;
- struct OSFileTypeMappings *next;
-} OSFileTypeMappings;
extern Boolean Plugins_AddFileTypeMappingsForTarget(Plugin *list, OSFileTypeMappings **mlist, OSType cpu, OSType os);
extern SInt16 Plugin_Call(Plugin *pl, void *context);
@@ -1460,122 +1155,6 @@ extern int DeleteTemporaries(SInt32 idx, File *file);
extern int ExecuteLinker(Plugin *plugin, SInt32 dropinflags, File *file, char *stdoutfile, char *stderrfile);
/********************************/
-/* command_line/CmdLine/Src/OSLib/Posix.c */
-typedef struct uOSTypePair {
- int perm;
-} uOSTypePair; // unknown name
-extern uOSTypePair OS_TEXTTYPE;
-typedef enum {
- OSReadOnly,
- OSWrite,
- OSReadWrite,
- OSAppend
-} OSOpenMode; // assumed name
-typedef enum {
- OSSeekRel,
- OSSeekAbs,
- OSSeekEnd
-} OSSeekMode; // assumed name
-extern const char *OS_GetErrText(int err);
-extern int OS_InitProgram(int *pArgc, const char ***pArgv);
-extern int OS_TermProgram();
-extern int OS_Create(const OSSpec *spec, const uOSTypePair *type);
-extern int OS_Status(const OSSpec *spec);
-extern int OS_GetFileType(const OSSpec *spec, uOSTypePair *type);
-extern int OS_SetFileType(const OSSpec *spec, const uOSTypePair *type);
-extern int OS_GetFileTime(const OSSpec *spec, time_t *crtm, time_t *chtm);
-extern int OS_SetFileTime(const OSSpec *spec, const time_t *crtm, const time_t *chtm);
-extern int OS_Open(const OSSpec *spec, OSOpenMode mode, int *ref);
-extern int OS_Write(int ref, const void *buffer, UInt32 *length);
-extern int OS_Read(int ref, void *buffer, UInt32 *length);
-extern int OS_Seek(int ref, OSSeekMode how, SInt32 offset);
-extern int OS_Tell(int ref, SInt32 *offset);
-extern int OS_Close(int ref);
-extern int OS_GetSize(int ref, UInt32 *length);
-extern int OS_SetSize(int ref, UInt32 size);
-extern int OS_Delete(const OSSpec *spec);
-extern int OS_Rename(const OSSpec *oldspec, const OSSpec *newspec);
-extern int OS_Mkdir(const OSSpec *spec);
-extern int OS_Rmdir(const OSPathSpec *spec);
-extern int OS_Chdir(const OSPathSpec *spec);
-extern int OS_GetCWD(OSPathSpec *spec);
-extern int OS_Execute(const char **argv, const char **envp, const char *stdoutfile, const char *stderrfile, int *exitcode);
-extern int OS_IsLegalPath(const char *path);
-extern int OS_IsFullPath(const char *path);
-extern char *OS_GetDirPtr(char *path);
-// static int OS_CompactPath(const char *src, char *dst);
-extern int OS_EqualPath(const char *a, const char *b);
-extern int OS_CanonPath(const char *src, char *dst);
-extern int OS_MakeSpec(const char *path, OSSpec *spec, Boolean *isfile);
-extern int OS_MakeFileSpec(const char *path, OSSpec *spec);
-extern int OS_MakePathSpec(const char *vol, const char *dir, OSPathSpec *spec);
-extern int OS_MakeNameSpec(const char *name, OSNameSpec *spec);
-extern int OS_GetRootSpec(OSPathSpec *spec);
-extern char *OS_SpecToString(const OSSpec *spec, char *path, int size);
-extern char *OS_PathSpecToString(const OSPathSpec *pspec, char *path, int size);
-extern char *OS_NameSpecToString(const OSNameSpec *nspec, char *name, int size);
-extern int OS_SizeOfPathSpec(const OSPathSpec *spec);
-extern int OS_SizeOfNameSpec(const OSNameSpec *spec);
-extern int OS_EqualSpec(const OSSpec *a, const OSSpec *b);
-extern int OS_EqualPathSpec(const OSPathSpec *a, const OSPathSpec *b);
-extern int OS_EqualNameSpec(const OSNameSpec *a, const OSNameSpec *b);
-extern int OS_IsDir(const OSSpec *spec);
-extern int OS_IsFile(const OSSpec *spec);
-extern int OS_IsLink(const OSSpec *spec);
-extern int OS_ResolveLink(const OSSpec *link, OSSpec *target);
-typedef struct {
- void *dir;
- OSPathSpec spec;
-} OSOpenedDir; // assumed name
-extern int OS_OpenDir(const OSPathSpec *spec, OSOpenedDir *ref);
-extern int OS_ReadDir(OSOpenedDir *ref, OSSpec *spec, char *filename, Boolean *isfile);
-extern int OS_CloseDir(OSOpenedDir *ref);
-extern UInt32 OS_GetMilliseconds();
-extern void OS_GetTime(time_t *p);
-extern int OS_NewHandle(UInt32 size, OSHandle *hand);
-extern int OS_ResizeHandle(OSHandle *hand, UInt32 size);
-extern void *OS_LockHandle(OSHandle *hand);
-extern void OS_UnlockHandle(OSHandle *hand);
-extern int OS_FreeHandle(OSHandle *hand);
-extern int OS_GetHandleSize(OSHandle *hand, UInt32 *size);
-extern void OS_InvalidateHandle(OSHandle *hand);
-extern Boolean OS_ValidHandle(OSHandle *hand);
-extern OSErr OS_MacError(int err);
-extern void OS_TimeToMac(time_t sectm, UInt32 *secs);
-extern void OS_MacToTime(UInt32 secs, time_t *sectm);
-extern SInt16 OS_RefToMac(int ref);
-extern int OS_MacToRef(SInt16 refnum);
-extern int OS_OpenLibrary(const char *a, void **lib);
-extern int OS_GetLibrarySymbol(void *a, void *b, void **sym);
-extern int OS_CloseLibrary(void *a);
-extern int OS_LoadMacResourceFork(const OSSpec *spec, void **file_data, SInt32 *file_len);
-extern int OS_IsMultiByte(const char *str, int offset);
-
-/********************************/
-/* command_line/CmdLine/Src/OSLib/StringExtras.c */
-extern char *strcatn(char *d, const char *s, SInt32 max);
-extern char *strcpyn(char *d, const char *s, SInt32 len, SInt32 max);
-extern int ustrcmp(const char *src, const char *dst);
-extern int ustrncmp(const char *src, const char *dst, UInt32 len);
-
-/********************************/
-/* command_line/CmdLine/Src/OSLib/Generic.c */
-extern int WildCardMatch(const char *wild, const char *name);
-extern OSSpec *OS_MatchPath(const char *path);
-extern char *OS_GetFileNamePtr(char *path);
-extern char *OS_GetDirName(const OSPathSpec *spec, char *buf, int size);
-extern int OS_MakeSpec2(const char *path, const char *filename, OSSpec *spec);
-extern int OS_MakeSpecWithPath(OSPathSpec *path, const char *filename, Boolean noRelative, OSSpec *spec);
-extern int OS_NameSpecChangeExtension(OSNameSpec *spec, const char *ext, Boolean append);
-extern int OS_NameSpecSetExtension(OSNameSpec *spec, const char *ext);
-extern char *OS_CompactPaths(char *buf, const char *p, const char *n, int size);
-extern char *OS_SpecToStringRelative(const OSSpec *spec, const OSPathSpec *cwdspec, char *path, int size);
-extern int OS_FindFileInPath(const char *filename, const char *plist, OSSpec *spec);
-extern int OS_FindProgram(const char *filename, OSSpec *spec);
-extern int OS_CopyHandle(OSHandle *hand, OSHandle *copy);
-extern int OS_AppendHandle(OSHandle *hand, const void *data, UInt32 len);
-
-/********************************/
/* command_line/CmdLine/Src/Project/CLProj.c */
typedef struct Project {
Target *targets;
@@ -1594,14 +1173,6 @@ extern void License_Checkin();
extern void License_AutoCheckin();
/********************************/
-/* command_line/CmdLine/Src/OSLib/MemUtils.c */
-extern void *xmalloc(const char *what, int size);
-extern void *xcalloc(const char *what, int size);
-extern void *xrealloc(const char *what, void *old, int size);
-extern char *xstrdup(const char *str);
-extern void xfree(void *ptr);
-
-/********************************/
/* command_line/CmdLine/Src/CLPluginRequests.cpp */
extern Boolean SendParserRequest(
Plugin *plugin,
@@ -1710,31 +1281,6 @@ extern int Frameworks_GetCount();
extern Paths_FWInfo *Frameworks_GetInfo(int which);
/********************************/
-/* command_line/CmdLine/Src/OSLib/MacSpecs.c */
-// This is pretty much self-contained lol
-extern int OS_OSPathSpec_To_VolDir(const OSPathSpec *spec, SInt16 *vRefNum, SInt32 *dirID);
-extern int OS_OSSpec_To_FSSpec(const OSSpec *spec, FSSpec *fss);
-extern int OS_VolDir_To_OSNameSpec(SInt16 vRefNum, SInt32 dirID, OSNameSpec *spec, SInt32 *parID);
-extern int OS_VolDir_To_OSPathSpec(SInt16 vRefNum, SInt32 dirID, OSPathSpec *spec);
-extern int OS_FSSpec_To_OSSpec(const FSSpec *fss, OSSpec *spec);
-extern int OS_GetRsrcOSSpec(const OSSpec *spec, OSSpec *rspec, Boolean create);
-
-/********************************/
-/* command_line/CmdLine/Src/OSLib/StringUtils.c */
-extern StringPtr _pstrcpy(StringPtr dst, ConstStringPtr src);
-extern void _pstrcat(StringPtr dst, ConstStringPtr src);
-extern void _pstrcharcat(StringPtr to, char ch);
-extern void pstrncpy(StringPtr to, ConstStringPtr from, int max);
-extern void pstrncat(StringPtr to, ConstStringPtr append, int max);
-extern int pstrcmp(ConstStringPtr a, ConstStringPtr b);
-extern int pstrchr(ConstStringPtr str, char find);
-extern void c2pstrcpy(StringPtr dst, const char *src);
-extern void p2cstrcpy(char *dst, ConstStringPtr src);
-extern char *mvprintf(char *mybuf, unsigned int len, const char *format, va_list va);
-extern char *mprintf(char *mybuf, unsigned int len, const char *format, ...);
-extern int HPrintF(Handle text, const char *format, ...);
-
-/********************************/
/* ??? */
extern int AddFileTypeMappingList(void *a, void *b); // TODO sig
extern void UseFileTypeMappings(void *a); // TODO sig
@@ -1797,26 +1343,6 @@ extern UInt16 Segments_Count(const Segments *segs);
// TODO
/********************************/
-/* command_line/CmdLine/Src/OSLib/MacFileTypes.c */
-extern void OS_AddFileTypeMappingList(OSFileTypeMappings **list, OSFileTypeMappingList *entry);
-extern void OS_UseFileTypeMappings(OSFileTypeMappings *list);
-extern void OS_MacType_To_OSType(OSType mactype, uOSTypePair *type);
-extern int OS_SetMacFileType(const OSSpec *spec, OSType mactype);
-extern Boolean OS_GetMacFileTypeMagic(const char *buffer, int count, OSType *mactype);
-extern int OS_GetMacFileType(const OSSpec *spec, OSType *mactype);
-extern int OS_SetMacFileCreatorAndType(const OSSpec *spec, OSType creator, OSType mactype);
-
-/********************************/
-/* command_line/CmdLine/Src/OSLib/FileHandles.c */
-//extern int OS_LoadFileHandle(OSFileHandle *hand);
-//extern int OS_WriteFileHandle(OSFileHandle *hand);
-extern int OS_NewFileHandle(const OSSpec *spec, OSHandle *src, Boolean writeable, OSFileHandle *hand);
-extern int OS_LockFileHandle(OSFileHandle *hand, Ptr *ptr, UInt32 *size);
-extern int OS_UnlockFileHandle(OSFileHandle *hand);
-extern int OS_FreeFileHandle(OSFileHandle *hand);
-extern void OS_GetFileHandleSpec(const OSFileHandle *hand, OSSpec *spec);
-
-/********************************/
/* command_line/CmdLine/Src/Callbacks/CLCompilerLinkerDropin_V10.cpp */
// TODO
@@ -2246,158 +1772,6 @@ extern void COS_FileGetFSSpecInfo(const FSSpec *spec, SInt16 *vRefNum, SInt32 *d
extern void COS_FileGetPathName(char *buffer, const FSSpec *spec, SInt32 *mdDat);
extern Boolean COS_EqualFileSpec(const FSSpec *a, const FSSpec *b);
-/********************************/
-/* MacEmul - ErrMgr */
-extern char *GetSysErrText(SInt16 msgNbr, char *errMsg);
-
-/********************************/
-/* MacEmul - Files */
-extern OSErr HCreate(SInt16 volume, SInt32 dirid, ConstStr255Param fileName, OSType creator, OSType type);
-extern OSErr HOpen(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, SInt8 permission, SInt16 *refNum);
-extern OSErr HOpenDF(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, SInt8 permission, SInt16 *refNum);
-extern OSErr HDelete(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName);
-extern OSErr HRename(SInt16 vRefNum, SInt32 dirID, ConstStr255Param oldName, ConstStr255Param newName);
-extern OSErr HGetFInfo(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, FInfo *fndrInfo);
-extern OSErr HSetFInfo(SInt16 vRefNum, SInt32 dirID, ConstStr255Param fileName, const FInfo *fndrInfo);
-extern OSErr FSpCreate(const FSSpec *fss, OSType creator, OSType fileType, ScriptCode scriptTag);
-extern OSErr FSpDirCreate(const FSSpec *fss, ScriptCode scriptTag, SInt32 *createdDirID);
-extern OSErr FSpOpenDF(const FSSpec *fss, SInt8 permission, SInt16 *refNum);
-extern OSErr FSpDelete(const FSSpec *fss);
-extern OSErr FSpRename(const FSSpec *oldfss, ConstStr255Param newName);
-extern OSErr FSpGetFInfo(const FSSpec *fss, FInfo *fndrInfo);
-extern OSErr FSpSetFInfo(const FSSpec *fss, const FInfo *fndrInfo);
-extern OSErr HGetVol(StringPtr volName, SInt16 *vRefNum, SInt32 *dirID);
-extern OSErr HSetVol(ConstStr63Param volName, SInt16 vRefNum, SInt32 dirID);
-extern OSErr FlushVol(ConstStr63Param volName, SInt16 vRefNum);
-extern OSErr FSRead(SInt16 fRefNum, SInt32 *Size, void *Buffer);
-extern OSErr FSWrite(SInt16 fRefNum, SInt32 *Size, const void *Buffer);
-extern OSErr FSClose(SInt16 fRefNum);
-extern OSErr GetEOF(SInt16 fRefNum, SInt32 *curEOF);
-extern OSErr SetEOF(SInt16 fRefNum, SInt32 newEOF);
-extern OSErr GetFPos(SInt16 fRefNum, SInt32 *pos);
-extern OSErr SetFPos(SInt16 fRefNum, SInt16 posMode, SInt32 posOffset);
-extern OSErr GetVInfo(SInt16 vRefNum, StringPtr name, SInt16 *vRef, SInt32 *hDir);
-extern OSErr PBWriteSync(ParmBlkPtr paramBlock);
-extern OSErr PBHGetFInfoSync(HParmBlkPtr paramBlock);
-extern OSErr PBHSetFInfoSync(HParmBlkPtr paramBlock);
-extern OSErr PBGetCatInfoSync(CInfoPBPtr paramBlock);
-extern OSErr ResolveAliasFile(FSSpec *fss, Boolean resolveChains, Boolean *isFolder, Boolean *wasAliased);
-extern OSErr FSMakeFSSpec(SInt16 vRefNum, SInt32 dirID, ConstStr255Param pathName, FSSpec *fss);
-extern OSErr Allocate(SInt16 refNum, SInt32 *byteCount);
-
-/********************************/
-/* MacEmul - LowMem */
-extern UInt32 LMGetTicks();
-extern UInt32 LMGetTime();
-extern OSErr LMGetMemErr();
-extern void LMSetMemErr(OSErr value);
-
-/********************************/
-/* MacEmul - Memory */
-extern OSHandle *OS_PeekMacHandle(Handle h);
-extern Handle OS_CreateMacHandle(OSHandle *h);
-extern Handle OS_CreateMacHandleDup(OSHandle *h);
-extern void OS_DestroyMacHandle(Handle h, OSHandle *ret);
-
-extern OSErr MemError();
-extern Handle NewHandle(SInt32 dataSize);
-extern Handle NewHandleClear(UInt32 dataSize);
-extern Handle TempNewHandle(UInt32 dataSize, OSErr *resultCode);
-extern void DisposeHandle(Handle h);
-extern void HLock(Handle h);
-extern void HLockHi(Handle h);
-extern void HUnlock(Handle h);
-extern void HPurge(Handle theHandle);
-extern void HNoPurge(Handle theHandle);
-extern SInt8 HGetState(Handle theHandle);
-extern void HSetState(Handle theHandle, SInt8 flags);
-extern SInt32 GetHandleSize(Handle h);
-extern void SetHandleSize(Handle h, SInt32 newSize);
-extern OSErr PtrAndHand(const void *srcPtr, Handle destHandle, SInt32 size);
-extern OSErr PtrToHand(const void *srcPtr, Handle *destHandle, SInt32 size);
-extern OSErr HandToHand(Handle *destHandle);
-extern OSErr HandAndHand(Handle src, Handle dst);
-extern void MoveHHi(Handle theHandle);
-extern void BlockMove(const void *srcPtr, void *destPtr, UInt32 byteCount);
-extern void BlockMoveData(const void *srcPtr, void *destPtr, UInt32 byteCount);
-extern Ptr NewPtr(SInt32 dataSize);
-extern void DisposePtr(Ptr p);
-extern Ptr NewPtrClear(SInt32 dataSize);
-extern void DebugStr(ConstStringPtr str);
-extern struct Zone *HandleZone();
-extern struct Zone *ApplicationZone();
-
-/********************************/
-/* MacEmul - Resources */
-extern Boolean OS_UsingMacResourceForkInfo();
-extern void OS_UseMacResourceForkInfo(Boolean which);
-extern OSErr SystemInitResources(OSSpec *spec);
-extern void OS_AddMacResourceForkRef(int ref, const OSSpec *spec);
-extern void OS_RemoveMacResourceForkRef(int ref);
-extern OSSpec *OS_GetMacResourceForkFromRef(int ref);
-extern Boolean OS_SearchMacResourceForkList(const OSSpec *rspec, int *ref);
-extern int OS_SetMacResourceForkCreatorAndType(int ref, OSType creator, OSType type);
-extern int OS_GetMacResourceForkCreatorAndType(int ref, OSType *creator, OSType *type);
-extern void OS_CleanupMacResourceForkDir(const OSPathSpec *dir);
-extern OSErr OS_MacDumpResourceFork(SInt16 ref, Boolean dumpContents);
-extern OSErr FSpOpenRF(const FSSpec *fss, SInt8 permission, SInt16 *refNum);
-extern OSErr HOpenRF(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName, SInt8 permission, SInt16 *refNum);
-extern OSErr InitResources();
-extern OSErr ResError();
-extern void FSpCreateResFile(const FSSpec *fss, OSType creator, OSType fileType, ScriptCode scriptTag);
-extern void HCreateResFile(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName);
-extern OSErr FSpOpenResFile(const FSSpec *fss, SInt8 permission);
-extern SInt16 HOpenResFile(SInt16 vRefNum, SInt32 dirID, ConstStringPtr fileName, SInt8 permission);
-extern SInt16 CurResFile();
-extern void UseResFile(SInt16 refNum);
-extern SInt16 HomeResFile(Handle theResource);
-extern Handle GetResource(OSType theType, SInt16 theID);
-extern Handle Get1Resource(OSType theType, SInt16 theID);
-extern Handle GetNamedResource(OSType theType, ConstStringPtr theName);
-extern Handle Get1NamedResource(OSType theType, ConstStringPtr theName);
-extern void SetResLoad(Boolean load);
-extern void MacEmul_LoadResource(Handle theResource);
-extern void GetResInfo(Handle theResource, SInt16 *theID, OSType *theType, StringPtr name);
-extern void SetResInfo(Handle theResource, SInt16 theID, ConstStringPtr name);
-extern SInt16 GetResAttrs(Handle theResource);
-extern void SetResAttrs(Handle theResource, SInt16 attrs);
-extern void ChangedResource(Handle theResource);
-extern void AddResource(Handle theData, OSType theType, SInt16 theID, ConstStringPtr name);
-extern void UpdateResFile(SInt16 refnum);
-extern void WriteResource(Handle theResource);
-extern void SetResPurge(Boolean install);
-extern SInt16 CountResources(OSType theType);
-extern SInt16 Count1Resources(OSType theType);
-extern Handle GetIndResource(OSType theType, SInt16 index);
-extern Handle Get1IndResource(OSType theType, SInt16 index);
-extern SInt16 Count1Types();
-extern void Get1IndType(OSType *theType, SInt16 index);
-extern void ReleaseResource();
-extern void DetachResource(Handle theResource);
-extern void RemoveResource(Handle theResource);
-extern void CloseResFile(SInt16 refNum);
-extern SInt16 GetResFileAttrs(SInt16);
-extern Boolean LMGetResLoad();
-
-/********************************/
-/* MacEmul - ResourceStrings */
-extern void Res_Initialize();
-extern int Res_AddResource(const char *name, SInt16 rsrcid, const char **strings);
-extern const char *Res_GetResource(SInt16 rsrcid, SInt16 index);
-extern void Res_Cleanup();
-
-/********************************/
-/* MacEmul - TextUtils */
-extern StringPtr c2pstr(char *s);
-extern char *p2cstr(StringPtr s);
-extern SInt16 CharacterByteType(Ptr textBuf, SInt16 textOffset, ScriptCode script);
-extern SInt16 CharByte();
-extern void GetDateTime(UInt32 *secs);
-extern Boolean EqualString(ConstStr255Param strA, ConstStr255Param strB, Boolean caseSens, Boolean diacSens);
-extern void GetIndString(Str255 theString, SInt16 strListID, SInt16 index);
-extern char *getindstring(char *theString, SInt16 strListID, SInt16 index);
-extern void NumToString(SInt32 theNum, Str255 theString);
-extern void StringToNum(ConstStr255Param theString, SInt32 *theNum);
// TODO sort me
extern Project *gProj;
diff --git a/includes/oslib.h b/includes/oslib.h
new file mode 100644
index 0000000..fa444a3
--- /dev/null
+++ b/includes/oslib.h
@@ -0,0 +1,220 @@
+#pragma once
+#include "common.h"
+
+/**
+ * OS abstraction layer
+ */
+
+typedef struct uOSTypePair {
+ int perm;
+} uOSTypePair; // unknown name
+
+typedef enum {
+ OSReadOnly,
+ OSWrite,
+ OSReadWrite,
+ OSAppend
+} OSOpenMode; // assumed name
+
+typedef enum {
+ OSSeekRel,
+ OSSeekAbs,
+ OSSeekEnd
+} OSSeekMode; // assumed name
+
+typedef struct OSPathSpec {
+ char s[256];
+} OSPathSpec;
+
+typedef struct OSNameSpec {
+ char s[64];
+} OSNameSpec;
+
+typedef struct OSSpec {
+ OSPathSpec path;
+ OSNameSpec name;
+} OSSpec;
+
+typedef struct OSHandle {
+ void *addr;
+ UInt32 used;
+ UInt32 size;
+} OSHandle;
+
+typedef struct {
+ OSSpec spec;
+ OSHandle hand;
+ Boolean loaded;
+ Boolean changed;
+ Boolean writeable;
+} OSFileHandle; // assumed name
+
+typedef struct {
+ void *dir;
+ OSPathSpec spec;
+} OSOpenedDir; // assumed name, might be something like OSDirRef though?
+
+typedef struct OSFileTypeMapping {
+ OSType mactype;
+ const char *magic;
+ char length;
+ const char *mimetype;
+ char executable; // not sure why this is rearranged
+} OSFileTypeMapping;
+
+typedef struct OSFileTypeMappingList {
+ SInt16 numMappings;
+ const OSFileTypeMapping *mappings;
+} OSFileTypeMappingList;
+
+typedef struct OSFileTypeMappings {
+ OSFileTypeMappingList *mappingList;
+ struct OSFileTypeMappings *next;
+} OSFileTypeMappings;
+
+/********************************/
+/* Generic */
+extern int WildCardMatch(const char *wild, const char *name);
+extern OSSpec *OS_MatchPath(const char *path);
+extern char *OS_GetFileNamePtr(char *path);
+extern char *OS_GetDirName(const OSPathSpec *spec, char *buf, int size);
+extern int OS_MakeSpec2(const char *path, const char *filename, OSSpec *spec);
+extern int OS_MakeSpecWithPath(OSPathSpec *path, const char *filename, Boolean noRelative, OSSpec *spec);
+extern int OS_NameSpecChangeExtension(OSNameSpec *spec, const char *ext, Boolean append);
+extern int OS_NameSpecSetExtension(OSNameSpec *spec, const char *ext);
+extern char *OS_CompactPaths(char *buf, const char *p, const char *n, int size);
+extern char *OS_SpecToStringRelative(const OSSpec *spec, const OSPathSpec *cwdspec, char *path, int size);
+extern int OS_FindFileInPath(const char *filename, const char *plist, OSSpec *spec);
+extern int OS_FindProgram(const char *filename, OSSpec *spec);
+extern int OS_CopyHandle(OSHandle *hand, OSHandle *copy);
+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_TermProgram();
+extern int OS_Create(const OSSpec *spec, const uOSTypePair *type);
+extern int OS_Status(const OSSpec *spec);
+extern int OS_GetFileType(const OSSpec *spec, uOSTypePair *type);
+extern int OS_SetFileType(const OSSpec *spec, const uOSTypePair *type);
+extern int OS_GetFileTime(const OSSpec *spec, time_t *crtm, time_t *chtm);
+extern int OS_SetFileTime(const OSSpec *spec, const time_t *crtm, const time_t *chtm);
+extern int OS_Open(const OSSpec *spec, OSOpenMode mode, int *ref);
+extern int OS_Write(int ref, const void *buffer, UInt32 *length);
+extern int OS_Read(int ref, void *buffer, UInt32 *length);
+extern int OS_Seek(int ref, OSSeekMode how, SInt32 offset);
+extern int OS_Tell(int ref, SInt32 *offset);
+extern int OS_Close(int ref);
+extern int OS_GetSize(int ref, UInt32 *length);
+extern int OS_SetSize(int ref, UInt32 size);
+extern int OS_Delete(const OSSpec *spec);
+extern int OS_Rename(const OSSpec *oldspec, const OSSpec *newspec);
+extern int OS_Mkdir(const OSSpec *spec);
+extern int OS_Rmdir(const OSPathSpec *spec);
+extern int OS_Chdir(const OSPathSpec *spec);
+extern int OS_GetCWD(OSPathSpec *spec);
+extern int OS_Execute(OSSpec *spec, char **argv, char **envp, const char *stdoutfile, const char *stderrfile, int *exitcode);
+extern int OS_IsLegalPath(const char *path);
+extern int OS_IsFullPath(const char *path);
+extern char *OS_GetDirPtr(char *path);
+extern int OS_EqualPath(const char *a, const char *b);
+extern int OS_CanonPath(char *src, char *dst);
+extern int OS_MakeSpec(const char *path, OSSpec *spec, Boolean *isfile);
+extern int OS_MakeFileSpec(const char *path, OSSpec *spec);
+extern int OS_MakePathSpec(const char *vol, const char *dir, OSPathSpec *spec);
+extern int OS_MakeNameSpec(const char *name, OSNameSpec *spec);
+extern int OS_GetRootSpec(OSPathSpec *spec);
+extern char *OS_SpecToString(const OSSpec *spec, char *path, int size);
+extern char *OS_PathSpecToString(const OSPathSpec *pspec, char *path, int size);
+extern char *OS_NameSpecToString(const OSNameSpec *nspec, char *name, int size);
+extern int OS_SizeOfPathSpec(const OSPathSpec *spec);
+extern int OS_SizeOfNameSpec(const OSNameSpec *spec);
+extern int OS_EqualSpec(const OSSpec *a, const OSSpec *b);
+extern int OS_EqualPathSpec(const OSPathSpec *a, const OSPathSpec *b);
+extern int OS_EqualNameSpec(const OSNameSpec *a, const OSNameSpec *b);
+extern int OS_IsDir(const OSSpec *spec);
+extern int OS_IsFile(const OSSpec *spec);
+extern int OS_IsLink(const OSSpec *spec);
+extern int OS_ResolveLink(const OSSpec *link, OSSpec *target);
+extern int OS_OpenDir(const OSPathSpec *spec, OSOpenedDir *ref);
+extern int OS_ReadDir(OSOpenedDir *ref, OSSpec *spec, char *filename, Boolean *isfile);
+extern int OS_CloseDir(OSOpenedDir *ref);
+extern UInt32 OS_GetMilliseconds();
+extern void OS_GetTime(time_t *p);
+extern int OS_NewHandle(UInt32 size, OSHandle *hand);
+extern int OS_ResizeHandle(OSHandle *hand, UInt32 size);
+extern void *OS_LockHandle(OSHandle *hand);
+extern void OS_UnlockHandle(OSHandle *hand);
+extern int OS_FreeHandle(OSHandle *hand);
+extern int OS_GetHandleSize(OSHandle *hand, UInt32 *size);
+extern void OS_InvalidateHandle(OSHandle *hand);
+extern Boolean OS_ValidHandle(OSHandle *hand);
+extern OSErr OS_MacError(int err);
+extern void OS_TimeToMac(time_t sectm, UInt32 *secs);
+extern void OS_MacToTime(UInt32 secs, time_t *sectm);
+extern SInt16 OS_RefToMac(int ref);
+extern int OS_MacToRef(SInt16 refnum);
+extern int OS_OpenLibrary(const char *a, void **lib);
+extern int OS_GetLibrarySymbol(void *a, void *b, void **sym);
+extern int OS_CloseLibrary(void *a);
+extern int OS_LoadMacResourceFork(const OSSpec *spec, void **file_data, SInt32 *file_len);
+extern int OS_IsMultiByte(const char *str, int offset);
+
+/********************************/
+/* FileHandles */
+extern int OS_NewFileHandle(const OSSpec *spec, OSHandle *src, Boolean writeable, OSFileHandle *hand);
+extern int OS_LockFileHandle(OSFileHandle *hand, Ptr *ptr, UInt32 *size);
+extern int OS_UnlockFileHandle(OSFileHandle *hand);
+extern int OS_FreeFileHandle(OSFileHandle *hand);
+extern void OS_GetFileHandleSpec(const OSFileHandle *hand, OSSpec *spec);
+
+/********************************/
+/* MacFileTypes */
+extern void OS_AddFileTypeMappingList(OSFileTypeMappings **list, OSFileTypeMappingList *entry);
+extern void OS_UseFileTypeMappings(OSFileTypeMappings *list);
+extern void OS_MacType_To_OSType(OSType mactype, uOSTypePair *type);
+extern int OS_SetMacFileType(const OSSpec *spec, OSType mactype);
+extern Boolean OS_GetMacFileTypeMagic(const char *buffer, int count, OSType *mactype);
+extern int OS_GetMacFileType(const OSSpec *spec, OSType *mactype);
+extern int OS_SetMacFileCreatorAndType(const OSSpec *spec, OSType creator, OSType mactype);
+
+/********************************/
+/* MacSpecs */
+extern int OS_OSPathSpec_To_VolDir(const OSPathSpec *spec, SInt16 *vRefNum, SInt32 *dirID);
+extern int OS_OSSpec_To_FSSpec(const OSSpec *spec, FSSpec *fss);
+extern int OS_VolDir_To_OSNameSpec(SInt16 vRefNum, SInt32 dirID, OSNameSpec *spec, SInt32 *parID);
+extern int OS_VolDir_To_OSPathSpec(SInt16 vRefNum, SInt32 dirID, OSPathSpec *spec);
+extern int OS_FSSpec_To_OSSpec(const FSSpec *fss, OSSpec *spec);
+extern int OS_GetRsrcOSSpec(const OSSpec *spec, OSSpec *rspec, Boolean create);
+
+/********************************/
+/* MemUtils */
+extern void *xmalloc(const char *what, int size);
+extern void *xcalloc(const char *what, int size);
+extern void *xrealloc(const char *what, void *old, int size);
+extern char *xstrdup(const char *str);
+extern void xfree(void *ptr);
+
+/********************************/
+/* StringExtras.c */
+extern char *strcatn(char *d, const char *s, SInt32 max);
+extern char *strcpyn(char *d, const char *s, SInt32 len, SInt32 max);
+extern int ustrcmp(const char *src, const char *dst);
+extern int ustrncmp(const char *src, const char *dst, UInt32 len);
+
+/********************************/
+/* StringUtils.c */
+extern StringPtr _pstrcpy(StringPtr dst, ConstStringPtr src);
+extern void _pstrcat(StringPtr dst, ConstStringPtr src);
+extern void _pstrcharcat(StringPtr to, char ch);
+extern void pstrncpy(StringPtr to, ConstStringPtr from, int max);
+extern void pstrncat(StringPtr to, ConstStringPtr append, int max);
+extern int pstrcmp(ConstStringPtr a, ConstStringPtr b);
+extern int pstrchr(ConstStringPtr str, char find);
+extern void c2pstrcpy(StringPtr dst, const char *src);
+extern void p2cstrcpy(char *dst, ConstStringPtr src);
+extern char *mvprintf(char *mybuf, unsigned int len, const char *format, va_list va);
+extern char *mprintf(char *mybuf, unsigned int len, const char *format, ...);
+extern int HPrintF(Handle text, const char *format, ...);