Exemplo n.º 1
0
void write_setting_filename(void *handle, const char *key, Filename fn)
{
    int fd = *(int *)handle;
    AliasHandle h;
    int id;
    OSErr error;
    Str255 pkey;

    UseResFile(fd);
    if (ResError() != noErr)
        fatalbox("Failed to open saved session (%d)", ResError());

    if (filename_is_null(fn)) {
	/* Generate a special "null" alias */
	h = (AliasHandle)NewHandle(sizeof(**h));
	if (h == NULL)
	    fatalbox("Failed to create fake alias");
	(*h)->userType = 'pTTY';
	(*h)->aliasSize = sizeof(**h);
    } else {
	error = NewAlias(NULL, &fn.fss, &h);
	if (error == fnfErr) {
	    /*
	     * NewAlias can't create an alias for a nonexistent file.
	     * Create an alias for the directory, and record the
	     * filename as well.
	     */
	    FSSpec tmpfss;

	    FSMakeFSSpec(fn.fss.vRefNum, fn.fss.parID, NULL, &tmpfss);
	    error = NewAlias(NULL, &tmpfss, &h);
	    if (error != noErr)
		fatalbox("Failed to create alias");
	    (*h)->userType = 'pTTY';
	    SetHandleSize((Handle)h, (*h)->aliasSize + fn.fss.name[0] + 1);
	    if (MemError() != noErr)
		fatalbox("Failed to create alias");
	    memcpy((char *)*h + (*h)->aliasSize, fn.fss.name,
		   fn.fss.name[0] + 1);
	}
	if (error != noErr)
	    fatalbox("Failed to create alias");
    }
    /* Put the data in a resource. */
    id = Unique1ID(rAliasType);
    if (ResError() != noErr)
	fatalbox("Failed to get ID for resource %s (%d)", key, ResError());
    c2pstrcpy(pkey, key);
    AddResource((Handle)h, rAliasType, id, pkey);
    if (ResError() != noErr)
	fatalbox("Failed to add resource %s (%d)", key, ResError());
}
Exemplo n.º 2
0
static void ProcTokens( class typ, unsigned *next )
{
    symbol      *sym;
    unsigned    value;

    WantColon();
    do {
        if( CurrToken != T_NAME )
            Error( "expecting name" );
        sym = NewSym( typ );
        Scan();
        switch( typ ) {
        case CLASS_INPUT:
        case CLASS_OUTPUT:
        case CLASS_INOUT:
            if( CurrToken == T_LITERAL ) {
                NewAlias( sym );
                Scan();
            }
        }
        if( CurrToken == T_EQUALS ) {
            Scan();
            value = GetNum();
            Scan();
        } else {
            value = *next;
        }
        sym->v.token = value;
        if( value >= *next ) {
            *next = value + 1;
        }
    } while( CurrToken != T_SEMI );
    Scan();
}
Exemplo n.º 3
0
AliasHandle	ChooseFile()
{
	NavReplyRecord reply;
	
	OSStatus err = NavChooseFile(NULL, &reply, NULL, NULL, NULL, NULL, NULL, NULL);
	if (err == noErr && reply.validRecord) {
		long count;
		err = AECountItems(&(reply.selection), &count);
		if (err == noErr)
		{
			AEKeyword   theKeyword;
			DescType    actualType;
			Size        actualSize;
			FSSpec		fspec;
				
			// Get a pointer to selected file
			err = AEGetNthPtr(&(reply.selection), 1,
								typeFSS, &theKeyword,
								&actualType, &fspec,
								sizeof(FSSpec),
								&actualSize);
			if (err == noErr) {
				AliasHandle ah;
				RequireNoErrString(NewAlias(NULL, &fspec, &ah), "NewAlias failed");
				return ah;
			}
		}
	}
	return NULL;
}
Exemplo n.º 4
0
Boolean PICloseFileAndMakeAlias (FSSpec& fsSpec,
					 FileHandle fRefNum, Boolean sameNames,
					 Boolean *dirty, AliasHandle *alias, short *result)
{
//	FSSpec			spec;
	OSErr			gotErr;
	
	// Close the file if it is open.
	if (fRefNum != 0)
		(void) TestAndStoreResult (result, FSClose (fRefNum));
		
	// Delete the file if we had an error.	
	 if (*result != noErr)
		 (void) FSpDelete (&fsSpec);
			
	// Flush the volume anyway.
	if (!TestAndStoreResult (result, FlushVol (NULL, fsSpec.vRefNum))) return FALSE;
	
	// Mark the file as clean.
	*dirty = FALSE;
	
	/* create alias for scripting system */
	
	if (sameNames)
	{ // didn't enter new filename, so set filename to nothing
		fsSpec.name[ (fsSpec.name[0] = 0)+1 ] = 0;
	} // otherwise use filename and store entire reference

	gotErr = NewAlias(nil, &fsSpec, alias);

	return (gotErr == noErr);
}
Exemplo n.º 5
0
/********************************************************************************
	Add a parameter of type typeAlias to an AERecord (or AppleEvent) using the provided FSSpec.

	pFSSpec			input:	Pointer to the FSSpec to use.
	pKeyword		input:	The key for the data to be added to the record.
	pAERecord		input:	Pointer to the record (or event) to add the data to.
	
	RESULT CODES
	____________
	noErr			   0	No error	
	paramErr		 -50	The value of target or alias parameter, or of
							both, is NIL, or the alias record is corrupt
	memFullErr		-108	Not enough room in heap zone	
*/
pascal	OSErr	MoreAEOAddAliasParameterFromFSSpec(const FSSpecPtr pFSSpec,
												const DescType pKeyword,
												AERecord *pAERecord )
{
	OSErr			anErr = noErr;
	AliasHandle		tAliasHandle;
	
	anErr = NewAlias( NULL, pFSSpec, &tAliasHandle);
	if ( noErr == anErr  &&  tAliasHandle == NULL )
	{
		anErr = paramErr;
	}
	
	if ( noErr == anErr )
	{
		char	handleState;
		
		handleState = HGetState((Handle) tAliasHandle );
		HLock((Handle) tAliasHandle );
		
		anErr = AEPutParamPtr( pAERecord, pKeyword, typeAlias,
							   *tAliasHandle, (*tAliasHandle)->aliasSize);
		
		HSetState( (Handle)tAliasHandle, handleState );
		DisposeHandle( (Handle)tAliasHandle );
	}
		
	return anErr;
}//end AddAliasParameterFromFSS
Exemplo n.º 6
0
OSErr find_exec_spec(FSSpec *result, FSSpec *myself)
{
  OSErr err;
  CInfoPBRec pbrec;
  short find_position = 0;
  AliasHandle execAlias;
  Boolean aliasChanged;

  // first we try the stored alias.
  
  execAlias = (AliasHandle)GetResource('alis',128);
  
  if (execAlias != NULL) {
    
    err = ResolveAlias(NULL,execAlias,result,&aliasChanged);
  
    if (err == noErr) {
      
      if (aliasChanged) { // need to write it back to disk
        WriteResource((Handle)execAlias);
      }
       	
      return noErr;
    }
  }
    
  // if that doesn't work, drop back and look for the file in the current directory.

  result->vRefNum = myself->vRefNum;
  result->parID = myself->parID;
  
  while (1) {
    pbrec.hFileInfo.ioVRefNum = result->vRefNum;
    pbrec.hFileInfo.ioDirID = result->parID;
    pbrec.hFileInfo.ioFDirIndex = find_position + 1;
    pbrec.hFileInfo.ioNamePtr = result->name;
    if (PBGetCatInfo(&pbrec, 0) || !*result->name)
      break;
    
    find_position++;

    if (pbrec.hFileInfo.ioFlFndrInfo.fdType == 'APPL') {
      if (pbrec.hFileInfo.ioFlFndrInfo.fdCreator == DEST_CREATOR) { 
        // found it!
        Str255 newName = "\pExecutable Location";
        
	if (NewAlias(NULL,result,&execAlias) == noErr) {
	  AddResource((Handle)execAlias,'alis',128,newName);
	  WriteResource((Handle)execAlias);
	} 

	return noErr;
      }
		
    }
  }
Exemplo n.º 7
0
//----------------------------------------------------------------------------------------
void nsPersistentFileDescriptor::operator = (const nsFileSpec& inSpec)
//----------------------------------------------------------------------------------------
{
#if defined(XP_MAC)
    if (inSpec.Error())
        return;
    AliasHandle    aliasH;
    OSErr err = NewAlias(nil, inSpec.GetFSSpecPtr(), &aliasH);
    if (err != noErr)
        return;

    PRUint32 bytes = GetHandleSize((Handle) aliasH);
    HLock((Handle) aliasH);
    char* buf = PL_Base64Encode((const char*)*aliasH, bytes, nsnull);
    DisposeHandle((Handle) aliasH);

    mDescriptorString = buf;
    PR_Free(buf);
#elif  defined(XP_MACOSX)
    if (inSpec.Error())
        return;
    
    FSRef fileRef;
    Boolean isDir;
    OSErr err = ::FSPathMakeRef((const UInt8*)inSpec.GetCString(), &fileRef, &isDir);
    if (err != noErr)
        return;
    
    AliasHandle    aliasH;
    err = ::FSNewAlias(nsnull, &fileRef, &aliasH);
    if (err != noErr)
        return;

    PRUint32 bytes = ::GetHandleSize((Handle) aliasH);
    ::HLock((Handle)aliasH);
    char* buf = PL_Base64Encode((const char*)*aliasH, bytes, nsnull);
    ::DisposeHandle((Handle) aliasH);

    mDescriptorString = buf;
    PR_Free(buf);
#else
    mDescriptorString = inSpec.GetCString();
#endif // XP_MAC
} // nsPersistentFileDescriptor::operator =
Exemplo n.º 8
0
/********************************************************************************
	Create and return an AEDesc of type typeAlias using the provided FSSpec.

	pFSSpec			input:	Pointer to the FSSpec to use.
	pAliasAEDesc	input:	Pointer to null AEDesc.
					output:	an AEDesc of type typeAlias.
	
	RESULT CODES
	____________
	noErr			   0	No error	
	paramErr		 -50	The value of target or alias parameter, or of
							both, is NIL, or the alias record is corrupt
	memFullErr		-108	Not enough room in heap zone	
*/
pascal	OSErr	MoreAEOCreateAliasDescFromFSSpec( const FSSpecPtr pFSSpec,
												  AEDesc *pAliasAEDesc )
{
	OSErr			anErr = noErr;
	AliasHandle		tAliasHandle;
	
	anErr = NewAlias( NULL, pFSSpec, &tAliasHandle);
	if ( noErr == anErr  &&  tAliasHandle == NULL )
	{
		anErr = paramErr;
	}

	if ( noErr == anErr )
	{
		anErr = MoreAEOCreateAliasDesc( tAliasHandle, pAliasAEDesc );
		DisposeHandle( (Handle)tAliasHandle );
	}
		
	return anErr;
}//end MoreAEOCreateAliasDescFromFSSpec
Exemplo n.º 9
0
OSErr FinderLaunch(const char *target)
{
    OSErr err;
    AppleEvent theAEvent, theReply;
    AEAddressDesc fndrAddress;
    AEDescList targetListDesc;
    OSType fndrCreator;
    AliasHandle targetAlias;

    FSSpec fileinfo;
    FSRef privateInfo;

/*
 * FSPathMakeRef needs (UInt8 *) as its first argument, but my current
 * understanding is that this is "just" a string but in an exlicitly
 * 8-bit code. Thus "char *" ought to suffice UNLESS you are compiling in a
 * world where char is a 16-bit item or some other wide-char messing about is
 * happening. The C compiler with 10.3 adjusted things without an explicit
 * cast hear and gave a warning. WIth 10.4 it gives an error.
 *    ACN, August 2005
 */
    err = FSPathMakeRef((const UInt8 *)target, &privateInfo, NULL);
#ifdef DEBUG
    printf("FSPathMakeRef()-> %d\n", err);
#endif
    err = FSGetCatalogInfo(&privateInfo, kFSCatInfoNone,
                           NULL, NULL, &fileinfo, NULL);
#ifdef DEBUG
    printf("FSGetCatalogInfo()-> %d\n",err);
#endif
    /* set up locals  */
    AECreateDesc(typeNull, NULL, 0, &theAEvent);
    AECreateDesc(typeNull, NULL, 0, &fndrAddress);
    AECreateDesc(typeNull, NULL, 0, &theReply);
    AECreateDesc(typeNull, NULL, 0, &targetListDesc);
    targetAlias = NULL;
    fndrCreator = 'MACS';

    /* create an open documents event targeting the finder */
    err = AECreateDesc(typeApplSignature, (Ptr) &fndrCreator,
                       sizeof(fndrCreator), &fndrAddress);
#ifdef DEBUG
    printf("AECreateDesc()-> %d\n",err);
#endif

    if (err == noErr) {
      err = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments,
                               &fndrAddress, kAutoGenerateReturnID,
                               kAnyTransactionID, &theAEvent);
#ifdef DEBUG
      printf("AECreateAppleEvent()-> %d\n",err);
#endif
    }

    if (err == noErr) {
      err = AECreateList(NULL, 0, false, &targetListDesc);
#ifdef DEBUG
      printf("AECreateList()-> %d\n", err);
#endif
    }

    if (err == noErr) {
      err = NewAlias(NULL, &fileinfo, &targetAlias);
#ifdef DEBUG
      printf("NewAlias()-> %d\n",err);
#endif

      if (err == noErr) {
        HLock((Handle) targetAlias);
        err = AEPutPtr(&targetListDesc,
                       1,
                       typeAlias,
                       *targetAlias,
                       GetHandleSize((Handle) targetAlias));
#ifdef DEBUG
        printf("AEPutPtr()-> %d\n",err);
#endif
        HUnlock((Handle) targetAlias);
      }
    }

    /* add the file list to the apple event */
    if( err == noErr ) {
      err = AEPutParamDesc(&theAEvent, keyDirectObject, &targetListDesc);
#ifdef DEBUG
      printf("AEPutParamDesc()-> %d\n",err);
#endif
    }
    if (err == noErr) {
      /* send the event to the Finder */
      err = AESend(&theAEvent, &theReply, kAENoReply,
                   kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
#ifdef DEBUG
      printf("AESend()-> %d\n",err);
#endif
    }

    /* clean up and leave */
    if (targetAlias != NULL) DisposeHandle((Handle) targetAlias);
    AEDisposeDesc(&targetListDesc);
    AEDisposeDesc(&theAEvent);
    AEDisposeDesc(&fndrAddress);
    AEDisposeDesc(&theReply);
    return err;
}
Exemplo n.º 10
0
OSErr FinderLaunch(long nTargets, FSSpec *targetList) {
	OSErr err;
	AppleEvent theAEvent, theReply;
	AEAddressDesc fndrAddress;
	AEDescList targetListDesc;
	OSType fndrCreator;
	Boolean wasChanged;
	AliasHandle targetAlias;
	long index;

		/* verify parameters */
	if ((nTargets == 0) || (targetList == NULL)) return paramErr;

		/* set up locals  */
	AECreateDesc(typeNull, NULL, 0, &theAEvent);
	AECreateDesc(typeNull, NULL, 0, &fndrAddress);
	AECreateDesc(typeNull, NULL, 0, &theReply);
	AECreateDesc(typeNull, NULL, 0, &targetListDesc);
	targetAlias = NULL;
	fndrCreator = 'MACS';

		/* create an open documents event targeting the finder */
	err = AECreateDesc(typeApplSignature, (Ptr) &fndrCreator,
		sizeof(fndrCreator), &fndrAddress);
	if (err != noErr) goto bail;
	err = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments,
		&fndrAddress, kAutoGenerateReturnID,
		kAnyTransactionID, &theAEvent);
	if (err != noErr) goto bail;

		/* create the list of files to open */
	err = AECreateList(NULL, 0, false, &targetListDesc);
	if (err != noErr) goto bail;
	for ( index=0; index < nTargets; index++) {
		if (targetAlias == NULL)
			err = NewAlias(NULL, (targetList + index), &targetAlias);
		else err = UpdateAlias(NULL, (targetList + index), targetAlias, &wasChanged);
		if (err != noErr) goto bail;
		HLock((Handle) targetAlias);
		err = AEPutPtr(&targetListDesc, (index + 1), typeAlias, *targetAlias, GetHandleSize((Handle) targetAlias));
		HUnlock((Handle) targetAlias);
		if (err != noErr) goto bail;
	}

		/* add the file list to the apple event */
	err = AEPutParamDesc(&theAEvent, keyDirectObject, &targetListDesc);
	if (err != noErr) goto bail;

		/* send the event to the Finder */
	err = AESend(&theAEvent, &theReply, kAENoReply,
		kAENormalPriority, kAEDefaultTimeout, NULL, NULL);

		/* clean up and leave */
bail:
	if (targetAlias != NULL) DisposeHandle((Handle) targetAlias);
	AEDisposeDesc(&targetListDesc);
	AEDisposeDesc(&theAEvent);
	AEDisposeDesc(&fndrAddress);
	AEDisposeDesc(&theReply);
	return err;
}
Exemplo n.º 11
0
	static PGPError
sExportProc(
	PFLConstFileSpecRef		ref,
	PGPByte **				dataOut,
	PGPSize *				dataSizeOut )
{
	MyData *			myData;
	PGPError			err				= kPGPError_NoErr;
	AliasHandle			alias			= NULL;
	void				*aliasData		= NULL;
	PGPUInt32			aliasDataSize	= 0;
	PGPByte *			data 			= NULL;
	PGPUInt32			dataSize		= 0;
	
	myData = GetMyData( ref );
	
	if( myData->specIsValid )
	{
		CInfoPBRec	cpb;
		FSSpec		parFolderSpec;
		
		parFolderSpec = myData->spec;
		
		pgpClearMemory( &cpb, sizeof( cpb ) );
		
		cpb.dirInfo.ioVRefNum	= parFolderSpec.vRefNum;
		cpb.dirInfo.ioDrDirID	= parFolderSpec.parID;
		cpb.dirInfo.ioNamePtr	= parFolderSpec.name;
		cpb.dirInfo.ioFDirIndex	= -1;
		
		if( PBGetCatInfoSync( &cpb ) == noErr )
		{
			parFolderSpec.parID	= cpb.dirInfo.ioDrParID;

			if( NewAlias( NULL, &parFolderSpec, &alias ) == noErr )
			{
				HLock( (Handle) alias );
				
				aliasData		= *alias;
				aliasDataSize 	= GetHandleSize( (Handle) alias );
			}
		}
	}
	
	dataSize = sizeof( ExportedFileSpec ) + aliasDataSize;
	
	data = (PGPByte *) PGPNewData( ref->memoryMgr, dataSize, 0 );
	if ( NULL!=(int)( data ) )
	{
		ExportedFileSpec	*exportedData = (ExportedFileSpec *) data;
		
		exportedData->aliasDataSize	= aliasDataSize;
		
		CopyPString( myData->spec.name, exportedData->name );
		
		if( aliasData != NULL )
			pgpCopyMemory( aliasData, &exportedData->aliasData[0], aliasDataSize );
	}
	else
	{
		err	= kPGPError_OutOfMemory;
	}
	
	if( alias != NULL )
		DisposeHandle( (Handle) alias );
		
	*dataOut		= data;
	*dataSizeOut	= dataSize;
	
	return( err );
}