diff options
author | Ash Wolf <ninji@wuffs.org> | 2022-10-12 03:03:57 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2022-10-12 03:03:57 +0100 |
commit | 45e57168fa0d33206731e391fb24759ddf179861 (patch) | |
tree | d09621ca6e201865ce9975fa72426f63ac054fd3 /includes | |
parent | 4c9d73d7243c82ca3f55d2d8a388328968303b3f (diff) | |
download | MWCC-45e57168fa0d33206731e391fb24759ddf179861.tar.gz MWCC-45e57168fa0d33206731e391fb24759ddf179861.zip |
lots more reorganisation, done part of OSLib
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.h | 266 | ||||
-rw-r--r-- | includes/macemul.h | 168 | ||||
-rw-r--r-- | includes/mwcc_decomp.h | 632 | ||||
-rw-r--r-- | includes/oslib.h | 220 |
4 files changed, 657 insertions, 629 deletions
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, ...); |