#include <Sound.h>
#if TARGET_API_MAC_CARBON
#include <Navigation.h>
+# ifdef MAC_MPW
+# include <CarbonStdCLib.h>
+# endif
#endif
#ifdef JP
/*
* Globals for MPW compilation
*/
-#ifdef MAC_MPW
+#if defined(MACH_O_CARBON) || defined(MAC_MPW)
/* Globals needed */
- QDGlobals qd;
- u32b _ftype;
- u32b _fcreator;
+ OSType _ftype;
+ OSType _fcreator;
#endif
*/
static bool initialized = FALSE;
+/*
+ * Version of Mac OS - for version specific bug workarounds (; ;)
+ */
+static long mac_os_version;
/*
#if TARGET_API_MAC_CARBON
static void refnum_to_name(char *buf, long refnum, short vrefnum, char *fname)
{
- DirInfo pb;
+ CInfoPBRec pb;
Str255 name;
int err;
int i, j;
while (1)
{
- pb.ioDrDirID=pb.ioDrParID;
+ pb.dirInfo.ioDrDirID=pb.dirInfo.ioDrParID;
err = FSMakeFSSpec( vref, dirID, "\p", &spec );
if( err != noErr )
}
+#ifdef MAC_MPW
+
+/*
+ * Convert pathname to an appropriate format, because MPW's
+ * CarbonStdCLib chose to use system's native path format,
+ * making our lives harder to create binaries that run on
+ * OS 8/9 and OS X :( -- pelpel
+ */
+void convert_pathname(char* path)
+{
+ char buf[1024];
+
+ /* Nothing has to be done for CarbonLib on Classic */
+ if (mac_os_version >= 0x1000)
+ {
+ /* Convert to POSIX style */
+ ConvertHFSPathToUnixPath(path, buf);
+
+ /* Copy the result back */
+ strcpy(path, buf);
+ }
+
+ /* Done. */
+ return;
+}
+
+# ifdef CHECK_MODIFICATION_TIME
+
+/*
+ * Although there is no easy way to emulate fstat in the old interface,
+ * we still can do stat-like things, because Mac OS is an OS.
+ */
+static int get_modification_time(cptr path, u32b *mod_time)
+{
+ CInfoPBRec pb;
+ Str255 pathname;
+ int i;
+
+ /* Paranoia - make sure the pathname fits in Str255 */
+ i = strlen(path);
+ if (i > 255) return (-1);
+
+ /* Convert pathname to a Pascal string */
+ strncpy((char *)pathname + 1, path, 255);
+ pathname[0] = i;
+
+ /* Set up parameter block */
+ pb.hFileInfo.ioNamePtr = pathname;
+ pb.hFileInfo.ioFDirIndex = 0;
+ pb.hFileInfo.ioVRefNum = app_vol;
+ pb.hFileInfo.ioDirID = 0;
+
+ /* Get catalog information of the file */
+ if (PBGetCatInfoSync(&pb) != noErr) return (-1);
+
+ /* Set modification date and time */
+ *mod_time = pb.hFileInfo.ioFlMdDat;
+
+ /* Success */
+ return (0);
+}
+
+
+/*
+ * A (non-Mach-O) Mac OS version of check_modification_time, for those
+ * compilers without good enough POSIX-compatibility libraries XXX XXX
+ */
+errr check_modification_date(int fd, cptr template_file)
+{
+#pragma unused(fd)
+ u32b txt_stat, raw_stat;
+ char *p;
+ char fname[32];
+ char buf[1024];
+
+ /* Build the file name */
+ path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
+
+ /* XXX XXX XXX */
+ convert_pathname(buf);
+
+ /* Obtain modification time */
+ if (get_modification_time(buf, &txt_stat)) return (-1);
+
+ /* XXX Build filename of the corresponding *.raw file */
+ strnfmt(fname, sizeof(fname), "%s", template_file);
+
+ /* Find last '.' */
+ p = strrchr(fname, '.');
+
+ /* Can't happen */
+ if (p == NULL) return (-1);
+
+ /* Substitute ".raw" for ".txt" */
+ strcpy(p, ".raw");
+
+ /* Build the file name of the raw file */
+ path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, fname);
+
+ /* XXX XXX XXX */
+ convert_pathname(buf);
+
+ /* Obtain modification time */
+ if (get_modification_time(buf, &raw_stat)) return (-1);
+
+ /* Ensure the text file is not newer than the raw file */
+ if (txt_stat > raw_stat) return (-1);
+
+ /* Keep using the current .raw file */
+ return (0);
+}
+
+# endif /* CHECK_MODIFICATION_TIME */
+
+#endif /* MAC_MPW */
+
/*
* Center a rectangle inside another rectangle
*/
// there is only one selection here we get only the first AEDescList:
if (( err = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyWord, &typeCode, &finalFSSpec, sizeof( FSSpec ), &actualSize )) == noErr )
{
- refnum_to_name( filename, finalFSSpec.parID, finalFSSpec.vRefNum, finalFSSpec.name );
+ refnum_to_name( (char *)filename, finalFSSpec.parID, finalFSSpec.vRefNum, (char *)finalFSSpec.name );
// 'finalFSSpec' is the chosen file¥Î
}
static void init_sound( void )
{
int err, i;
- DirInfo pb;
+ CInfoPBRec pb;
SignedByte permission = fsRdPerm;
pascal short ret;
Str255 sound;
/* Descend into "lib" folder */
- pb.ioCompletion = NULL;
- pb.ioNamePtr = "\plib";
- pb.ioVRefNum = app_vol;
- pb.ioDrDirID = app_dir;
- pb.ioFDirIndex = 0;
+ pb.dirInfo.ioCompletion = NULL;
+ pb.dirInfo.ioNamePtr = "\plib";
+ pb.dirInfo.ioVRefNum = app_vol;
+ pb.dirInfo.ioDrDirID = app_dir;
+ pb.dirInfo.ioFDirIndex = 0;
/* Check for errors */
err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
/* Success */
- if ((err == noErr) && (pb.ioFlAttrib & 0x10))
+ if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
{
/* Descend into "lib/save" folder */
- pb.ioCompletion = NULL;
- pb.ioNamePtr = "\pxtra";
- pb.ioVRefNum = app_vol;
- pb.ioDrDirID = pb.ioDrDirID;
- pb.ioFDirIndex = 0;
+ pb.dirInfo.ioCompletion = NULL;
+ pb.dirInfo.ioNamePtr = "\pxtra";
+ pb.dirInfo.ioVRefNum = app_vol;
+ pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
+ pb.dirInfo.ioFDirIndex = 0;
/* Check for errors */
err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
/* Success */
- if ((err == noErr) && (pb.ioFlAttrib & 0x10))
+ if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
{
/* Descend into "lib/save" folder */
- pb.ioCompletion = NULL;
- pb.ioNamePtr = "\psound";
- pb.ioVRefNum = app_vol;
- pb.ioDrDirID = pb.ioDrDirID;
- pb.ioFDirIndex = 0;
+ pb.dirInfo.ioCompletion = NULL;
+ pb.dirInfo.ioNamePtr = "\psound";
+ pb.dirInfo.ioVRefNum = app_vol;
+ pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
+ pb.dirInfo.ioFDirIndex = 0;
/* Check for errors */
err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
/* Success */
- if ((err == noErr) && (pb.ioFlAttrib & 0x10))
+ if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
{
- ret = HOpenResFile( app_vol , pb.ioDrDirID , "\psound.rsrc" , permission );
+ ret = HOpenResFile( app_vol , pb.dirInfo.ioDrDirID , "\psound.rsrc" , permission );
if( ret != -1 ){
ext_sound = 1;
static void init_graf( void )
{
int err, i;
- DirInfo pb;
+ CInfoPBRec pb;
SignedByte permission = fsRdPerm;
pascal short ret;
Str255 graf;
/* Descend into "lib" folder */
- pb.ioCompletion = NULL;
- pb.ioNamePtr = "\plib";
- pb.ioVRefNum = app_vol;
- pb.ioDrDirID = app_dir;
- pb.ioFDirIndex = 0;
+ pb.dirInfo.ioCompletion = NULL;
+ pb.dirInfo.ioNamePtr = "\plib";
+ pb.dirInfo.ioVRefNum = app_vol;
+ pb.dirInfo.ioDrDirID = app_dir;
+ pb.dirInfo.ioFDirIndex = 0;
/* Check for errors */
err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
/* Success */
- if ((err == noErr) && (pb.ioFlAttrib & 0x10))
+ if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
{
/* Descend into "lib/xtra" folder */
- pb.ioCompletion = NULL;
- pb.ioNamePtr = "\pxtra";
- pb.ioVRefNum = app_vol;
- pb.ioDrDirID = pb.ioDrDirID;
- pb.ioFDirIndex = 0;
+ pb.dirInfo.ioCompletion = NULL;
+ pb.dirInfo.ioNamePtr = "\pxtra";
+ pb.dirInfo.ioVRefNum = app_vol;
+ pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
+ pb.dirInfo.ioFDirIndex = 0;
/* Check for errors */
err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
/* Success */
- if ((err == noErr) && (pb.ioFlAttrib & 0x10))
+ if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
{
/* Descend into "lib/xtra/graf" folder */
- pb.ioCompletion = NULL;
- pb.ioNamePtr = "\pgraf";
- pb.ioVRefNum = app_vol;
- pb.ioDrDirID = pb.ioDrDirID;
- pb.ioFDirIndex = 0;
+ pb.dirInfo.ioCompletion = NULL;
+ pb.dirInfo.ioNamePtr = "\pgraf";
+ pb.dirInfo.ioVRefNum = app_vol;
+ pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrDirID;
+ pb.dirInfo.ioFDirIndex = 0;
/* Check for errors */
err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE);
/* Success */
- if ((err == noErr) && (pb.ioFlAttrib & 0x10))
+ if ((err == noErr) && (pb.dirInfo.ioFlAttrib & 0x10))
{
- ret = HOpenResFile( app_vol , pb.ioDrDirID , "\pgraf.rsrc" , permission );
+ ret = HOpenResFile( app_vol , pb.dirInfo.ioDrDirID , "\pgraf.rsrc" , permission );
if (ret != -1)
{
ext_graf = 1;
for( i = 1 ; i < 7 ; i++ )
SetCheck( dialog, i+2 , soundmode[i] );
- ShowWindow(dialog);
+ /* ShowWindow(dialog); */
for( item_hit = 100 ; cancel < item_hit ; ){
ModalDialog(0, &item_hit);
FSpLocationFromFullPath( strlen(path), path, &fsp );
/* Get any file */
- err = ChooseFile( savefile, fsp );
+ ChooseFile( (StringPtr)savefile, fsp );
/* Allow cancel */
if (err != noErr) return;
* Apple Event Handler -- Open Application
*/
static pascal OSErr AEH_Start(const AppleEvent *theAppleEvent,
- const AppleEvent *reply, long handlerRefCon)
+ AppleEvent *reply, long handlerRefCon)
{
#pragma unused(reply, handlerRefCon)
* Apple Event Handler -- Quit Application
*/
static pascal OSErr AEH_Quit(const AppleEvent *theAppleEvent,
- const AppleEvent *reply, long handlerRefCon)
+ AppleEvent *reply, long handlerRefCon)
{
#pragma unused(reply, handlerRefCon)
#if TARGET_API_MAC_CARBON
* Apple Event Handler -- Print Documents
*/
static pascal OSErr AEH_Print(const AppleEvent *theAppleEvent,
- const AppleEvent *reply, long handlerRefCon)
+ AppleEvent *reply, long handlerRefCon)
{
#pragma unused(theAppleEvent, reply, handlerRefCon)
* snippet from Think Reference 2.0. (The prior sentence could read
* "shamelessly swiped & hacked")
*/
-static pascal OSErr AEH_Open(AppleEvent *theAppleEvent,
+static pascal OSErr AEH_Open(const AppleEvent *theAppleEvent,
AppleEvent* reply, long handlerRefCon)
{
#pragma unused(reply, handlerRefCon)
#endif /* ANGBAND_LITE_MAC */
+ /*
+ * Remember Mac OS version, in case we have to cope with version-specific
+ * problems
+ */
+ (void)Gestalt(gestaltSystemVersion, &mac_os_version);
#ifdef USE_SFL_CODE
/* Obtain a "Universal Procedure Pointer" */