Пример #1
0
static toff_t
_tiffSeekProc(thandle_t fd, toff_t off, int whence)
{
	long fpos, size;

	if (GetEOF((short) fd, &size) != noErr)
		return EOF;
	(void) GetFPos((short) fd, &fpos);

	switch (whence) {
	case SEEK_CUR:
		if (off + fpos > size)
			SetEOF((short) fd, off + fpos);
		if (SetFPos((short) fd, fsFromMark, off) != noErr)
			return EOF;
		break;
	case SEEK_END:
		if (off > 0)
			SetEOF((short) fd, off + size);
		if (SetFPos((short) fd, fsFromStart, off + size) != noErr)
			return EOF;
		break;
	case SEEK_SET:
		if (off > size)
			SetEOF((short) fd, off);
		if (SetFPos((short) fd, fsFromStart, off) != noErr)
			return EOF;
		break;
	}

	return (toff_t)(GetFPos((short) fd, &fpos) == noErr ? fpos : EOF);
}
Пример #2
0
	int SetPosition(int iFrame)
	{
		const int iBlock = iFrame / m_iFramesPerBlock;

		m_iBufferUsed = m_iBufferAvail = 0;

		{
			const int iByte = iBlock * m_WavData.m_iBlockAlign;
			if (iByte > m_WavData.m_iDataChunkSize)
			{
				SetEOF();
				return 0;
			}
			m_File.Seek(iByte + m_WavData.m_iDataChunkPos);
		}

		if (!DecodedADPCMBlock())
			return -1;

		const int iRemainingFrame = iFrame - iBlock * m_iFramesPerBlock;
		m_iBufferUsed = iRemainingFrames * m_WavData.m_iChannels * sizeof(int16_t);
		if (m_iBufferUsed > m_iBufferAvail)
		{
			SetEOF();
			return 0;
		}

		return 1;
	}
Пример #3
0
INT64 NCSFileSeek(int hFile,
				  	   INT64 nOffset,
				  	   int origin)
{
#ifdef WIN32

	return((INT64)_lseeki64(hFile, (__int64)nOffset, origin));

#elif defined MACINTOSH
	
	long fpos, size;

	if (GetEOF((short) hFile, &size) != noErr)
		return EOF;
	(void) GetFPos((short) hFile, &fpos);

	switch (origin) {
	case SEEK_CUR:
		if (nOffset + fpos > size)
			SetEOF((short) hFile, nOffset + fpos);
		if (SetFPos((short) hFile, fsFromMark, nOffset) != noErr)
			return EOF;
		break;
	case SEEK_END:
		if (nOffset > 0)
			SetEOF((short) hFile, nOffset + size);
		if (SetFPos((short) hFile, fsFromStart, nOffset + size) != noErr)
			return EOF;
		break;
	case SEEK_SET:
		if (nOffset > size)
			SetEOF((short) hFile, nOffset);
		if (SetFPos((short) hFile, fsFromStart, nOffset) != noErr)
			return EOF;
		break;
	}

	return (INT64)(GetFPos((short) hFile, &fpos) == noErr ? fpos : EOF);
	
#else	/* WIN32 */

#error: NCSFileSeek()
#endif	/* WIN32 */
}
Пример #4
0
void oldsaveMacros(FSSpec *theFile)
{
	SFReply		whereReply;
	short 		refNum,exist;
	FSSpec		macroFile;
	long		junk;
	short 		i;
	char		temp[256], temp2[256];
	Point		where;
	OSErr		err;
	Str255		tempString,tempString2;

	where.h = 100; where.v = 100;

	GetIndString(tempString,MISC_STRINGS,SAVE_MACROS_STRING);
	GetIndString(tempString2,MISC_STRINGS,DEFAULT_MACRO_SET_NAME);

	if (theFile == 0) {
		SFPutFile( where, tempString, tempString2, 0L, &whereReply);

		if (!whereReply.good)
			return;

		BlockMoveData(&whereReply.fName, macroFile.name, (*whereReply.fName)+1); 
		GetWDInfo(whereReply.vRefNum, &macroFile.vRefNum, &macroFile.parID, &junk);
	}
	else
		macroFile = *theFile;

	if ((err = HCreate(macroFile.vRefNum, macroFile.parID, 
			macroFile.name, kNCSACreatorSignature, 'TEXT')) == dupFNErr)
		exist = 1;
	
	err = HOpenDF(macroFile.vRefNum, macroFile.parID, macroFile.name, fsWrPerm, &refNum);

	if (exist) 
		SetEOF(refNum, 0L);

	
	for (i = 0; i < 10; i++)
	{
		oldgetmacro(i, temp, sizeof(temp), 1);
		sprintf(temp2, "key%d = \"", i);
		CStringToFile(refNum,(unsigned char *) temp2);
		if (*temp)
		{
			CStringToFile(refNum,(unsigned char *) temp);
		}
		strcpy(temp2,"\"\015");
		CStringToFile(refNum,(unsigned char *) temp2);

	}
	FSClose(refNum);

}
Пример #5
0
void QTCmpr_PromptUserForDiskFileAndSaveCompressed (Handle theHandle, ImageDescriptionHandle theDesc)
{
	FSSpec				myFile;
	Boolean				myIsSelected = false;
	Boolean				myIsReplacing = false;	
	short				myRefNum = -1;
	StringPtr 			myImagePrompt = QTUtils_ConvertCToPascalString(kQTCSaveImagePrompt);
	StringPtr 			myImageFileName = QTUtils_ConvertCToPascalString(kQTCSaveImageFileName);
	OSErr				myErr = noErr;

	// do a little parameter checking....
	if ((theHandle == NULL) || (theDesc == NULL))
		goto bail;
		
	if ((**theDesc).dataSize > GetHandleSize(theHandle))
		goto bail;

	// prompt the user for a file to put the compressed image into; in theory, the name
	// should have a file extension appropriate to the type of compressed data selected by the user;
	// this is left as an exercise for the reader
	QTFrame_PutFile(myImagePrompt, myImageFileName, &myFile, &myIsSelected, &myIsReplacing);
	if (!myIsSelected)
		goto bail;

	HLock(theHandle);

	// create and open the file
	myErr = FSpCreate(&myFile, kImageFileCreator, (**theDesc).cType, 0);
	
	if (myErr == noErr)
		myErr = FSpOpenDF(&myFile, fsRdWrPerm, &myRefNum);
		
	if (myErr == noErr)
		myErr = SetFPos(myRefNum, fsFromStart, 0);

	// now write the data in theHandle into the file
	if (myErr == noErr)
		myErr = FSWrite(myRefNum, &(**theDesc).dataSize, *theHandle);
	
	if (myErr == noErr)
		myErr = SetFPos(myRefNum, fsFromStart, (**theDesc).dataSize);

	if (myErr == noErr)
		myErr = SetEOF(myRefNum, (**theDesc).dataSize);
				 
	if (myRefNum != -1)
		myErr = FSClose(myRefNum);
		
bail:
	free(myImagePrompt);
	free(myImageFileName);

	HUnlock(theHandle);
}
Пример #6
0
bool    Errf( ftnfile *fcb ) {
//============================

// Determine if an i/o error exists.

    int     err;

    err = Errorf( fcb->fileptr );
    if( err == IO_EOF ) {
        SetEOF();
        err = IO_OK;
    }
    return( err != IO_OK );
}
Пример #7
0
void *__PHYSFS_platformOpenWrite(const char *filename)
{
    SInt16 *retval = macDoOpen(filename, fsRdWrPerm, 1);
    if (retval != NULL)   /* got a file; truncate it. */
    {
        if ((oserr(SetEOF(*retval, 0)) != noErr) ||
            (oserr(SetFPos(*retval, fsFromStart, 0)) != noErr))
        {
            FSClose(*retval);
            return(NULL);
        } /* if */
    } /* if */

    return((void *) retval);
} /* __PHYSFS_platformOpenWrite */
Пример #8
0
UINT file_write(FILEH handle, const void *data, UINT length) {

	if (length) {
		long size = length;
		if (FSWrite(handle, &size, (char *)data) == noErr) {
			return(size);
		}
	}
	else {
		SInt32 pos;
		if (GetFPos(handle, &pos) == noErr) {
			SetEOF(handle, pos);
		}
	}
	return(0);
}
Пример #9
0
/* create icns(icon for MacOS X) with IPIcon */
OSErr MakeXIconWithIPIcon(const FSSpec *theFile,const IPIconRec *ipIcon)
{
	OSErr	err;
	FInfo	fndrInfo;
	short	refNum;
	IconFamilyHandle	iconFamily;
	long	count;
	
	if (!isIconServicesAvailable) return -1;
	
	/* convert IPIcon to icns */
	err=IPIconToIconFamily(ipIcon,&iconFamily);
	if (err!=noErr) return err;
	
	/* create a file */
	err=FSpGetFInfo(theFile,&fndrInfo);
	if (err==fnfErr)
		err=FSpCreate(theFile,kIconPartyCreator,kXIconFileType,smSystemScript);
	if (err!=noErr) return err;
	
	/* open the file */
	err=FSpOpenDF(theFile,fsWrPerm,&refNum);
	if (err!=noErr) return err;
	
	/* save icns */
	HLock((Handle)iconFamily);
	count=GetHandleSize((Handle)iconFamily);
	err=FSWrite(refNum,&count,*iconFamily);
	err=SetEOF(refNum,count);
	HUnlock((Handle)iconFamily);
	DisposeHandle((Handle)iconFamily);
	
	/* close the file */
	err=FSClose(refNum);
	
	return noErr;
}
Пример #10
0
void saveMacros(NewMacroInfo *macrost, FSSpec *theFile)
{
	SFReply		whereReply;
	short 		refNum,exist;
	FSSpec		macroFile;
	long		junk, len, len2;
	short 		i;
	Point		where;
	OSErr		err;
	Str255		tempString,tempString2;
	Handle		macroHandle;
	Ptr			pos;

	if (!macrost->handle) return; // sanity check

	where.h = 100; where.v = 100;

	GetIndString(tempString,MISC_STRINGS,SAVE_MACROS_STRING);
	GetIndString(tempString2,MISC_STRINGS,DEFAULT_MACRO_SET_NAME);

	if (theFile == 0) {
		SFPutFile( where, tempString, tempString2, 0L, &whereReply);

		if (!whereReply.good)
			return;

		BlockMoveData(&whereReply.fName, macroFile.name, (*whereReply.fName)+1); 
		GetWDInfo(whereReply.vRefNum, &macroFile.vRefNum, &macroFile.parID, &junk);
	}
	else
		macroFile = *theFile;

	if ((err = HCreate(macroFile.vRefNum, macroFile.parID, 
			macroFile.name, kNCSACreatorSignature, 'TEXT')) == dupFNErr)
		exist = 1;
	
	err = HOpenDF(macroFile.vRefNum, macroFile.parID, macroFile.name, fsWrPerm, &refNum);

	if (exist) 
		SetEOF(refNum, 0L);

// the new code - RAB BetterTelnet 2.0b5
	macroHandle = macrost->handle;
	HandToHand(&macroHandle);
	HLock(macroHandle);
	pos = *macroHandle;
	len = len2 = GetHandleSize(macroHandle);
	while (len) {
		if (*pos == 0) *pos = 13;
		pos++;
		len--;
	}

	pos = *macroHandle;
	junk = 2;
	FSWrite(refNum, &junk, "!\015");
	FSWrite(refNum, &len2, pos);
	DisposeHandle(macroHandle); // it's a copy anyway, get rid of it!

	FSClose(refNum);
}
Пример #11
0
bool FdoSmPhCfgGrdSchemaReader::ReadNext()
{
    bool                        found = false;
    FdoSchemaMappingsP          mappings = GetManager()->GetConfigMappings();
    FdoFeatureSchemasP          schemas = GetManager()->GetConfigSchemas();
    FdoStringP                  providerName = GetManager()->GetProviderName();
    FdoFeatureSchemaP           schema;
    FdoRdbmsOvSchemaMappingP    mapping;
    FdoRdbmsOvSchemaMappingP    mapping2;
    FdoStringP                  schemaName;
    FdoSmPhGrdMgrP              grdMgr = GetManager().p->SmartCast<FdoSmPhGrdMgr>();

    while ( !IsEOF() && !found ) {
        // Check the next schema override set.
        mIdx++;

        if ( mIdx >= mappings->GetCount() ) {
            SetEOF(true);
            break;
		}

        mapping = (FdoRdbmsOvPhysicalSchemaMapping*) mappings->GetItem(mIdx);
        schemaName = mapping->GetName();
        mapping2 = (FdoRdbmsOvPhysicalSchemaMapping*) mappings->GetItem(
            providerName,
            schemaName
        );
        schema = schemas->FindItem( schemaName );

        if ( mapping2 && FdoRdbmsOvSchemaAutoGenerationP(mapping2->GetAutoGeneration()) && (!schema) ) {
            // Schema has autogeneration directives so make it the current one
            FdoSmPhRowsP rows = GetRows();
            FdoSmPhRowP  row = rows ? rows->GetItem(0) : NULL;

            if ( row ) {
				FdoSmPhFieldsP pFields = row->GetFields();

                // Set some fields from the config document.
                FdoSmPhFieldP field = pFields->GetItem(L"schemaname");
                field->SetFieldValue( schemaName );

                field = pFields->GetItem(L"tablemapping");
                field->SetFieldValue( FdoSmOvTableMappingTypeMapper::Type2String(mapping2->GetTableMapping()) );

                field = pFields->GetItem(L"tablelinkname");
                field->SetFieldValue( grdMgr->GetOverrideDatabase(mapping2) );

                field = pFields->GetItem(L"tableowner");
                field->SetFieldValue( grdMgr->GetOverrideOwner(mapping2) );
            }
            else {
                SetEOF(true);
                break;
            }

            found = true;
            SetBOF(false);
        }
    }

	return(!IsEOF());
}
Пример #12
0
OSErr QTInfo_MakeFilePreview (Movie theMovie, short theRefNum, ICMProgressProcRecordPtr theProgressProc)
{
    unsigned long			myModDate;
    PreviewResourceRecord	myPNOTRecord;
    long					myEOF;
    long					mySize;
    unsigned long			myAtomHeader[2];	// an atom header: size and type
    OSType					myPreviewType;
    OSErr					myErr = noErr;

    //////////
    //
    // determine whether theRefNum is a file reference number of a data fork or a resource fork;
    // if it's a resource fork, then we'll just call the existing ICM function MakeFilePreview
    //
    //////////

    if (QTInfo_IsRefNumOfResourceFork(theRefNum)) {
        myErr = MakeFilePreview(theRefNum, theProgressProc);
        goto bail;
    }

    //////////
    //
    // determine the preview type
    //
    //////////

    // if the movie has a movie preview, use that as the file preview; otherwise use a thumbnail
    // of the movie poster frame as the file preview
    if (QTInfo_MovieHasPreview(theMovie))
        myPreviewType = MovieAID;
    else
        myPreviewType = kQTFileTypePicture;

    //////////
    //
    // construct the 'pnot' atom
    //
    //////////

    // fill in the 'pnot' atom header
    myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + sizeof(myPNOTRecord));
    myAtomHeader[1] = EndianU32_NtoB(ShowFilePreviewComponentType);

    // fill in the 'pnot' atom data
    GetDateTime(&myModDate);

    myPNOTRecord.modDate = EndianU32_NtoB(myModDate);		// the modification time of the preview
    myPNOTRecord.version = EndianS16_NtoB(0);				// version number; must be 0
    myPNOTRecord.resType = EndianU32_NtoB(myPreviewType);	// atom type containing preview
    myPNOTRecord.resID = EndianS16_NtoB(1);					// the 1-based index of the atom of the specified type to use

    //////////
    //
    // write the 'pnot' atom at the end of the data fork
    //
    //////////

    // get the current logical end-of-file and extend it by the desired amount
    myErr = GetEOF(theRefNum, &myEOF);
    if (myErr != noErr)
        goto bail;

    myErr = SetEOF(theRefNum, myEOF + sizeof(myAtomHeader) + sizeof(myPNOTRecord));
    if (myErr != noErr)
        goto bail;

    // set the file mark
    myErr = SetFPos(theRefNum, fsFromStart, myEOF);
    if (myErr != noErr)
        goto bail;

    // write the atom header into the file
    mySize = sizeof(myAtomHeader);
    myErr = FSWrite(theRefNum, &mySize, myAtomHeader);
    if (myErr != noErr)
        goto bail;

    // write the atom data into the file
    mySize = sizeof(myPNOTRecord);
    myErr = FSWrite(theRefNum, &mySize, &myPNOTRecord);
    if (myErr != noErr)
        goto bail;

    //////////
    //
    // write the preview data atom at the end of the data fork
    //
    //////////

    if (myPreviewType == MovieAID) {
        // in theory, we don't need to do anything here, since our 'pnot' atom points
        // to the 'moov' atom; in practice, this doesn't work correctly (it seems like
        // a bug in StandardGetFilePreview)
    }

    if (myPreviewType == kQTFileTypePicture) {
        PicHandle		myPicture = NULL;
        PicHandle		myThumbnail = NULL;

        // get the poster frame picture
        myPicture = GetMoviePosterPict(theMovie);
        if (myPicture != NULL) {

            // create a thumbnail
            myThumbnail = (PicHandle)NewHandleClear(4);
            if (myThumbnail != NULL) {
                myErr = MakeThumbnailFromPicture(myPicture, 0, myThumbnail, theProgressProc);
                if (myErr == noErr) {

                    myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + GetHandleSize((Handle)myThumbnail));
                    myAtomHeader[1] = EndianU32_NtoB(myPreviewType);

                    // write the atom header into the file
                    mySize = sizeof(myAtomHeader);
                    myErr = FSWrite(theRefNum, &mySize, myAtomHeader);
                    if (myErr == noErr) {
                        // write the atom data into the file
                        mySize = GetHandleSize((Handle)myThumbnail);
                        myErr = FSWrite(theRefNum, &mySize, *myThumbnail);
                    }
                }

                KillPicture(myThumbnail);
            }

            KillPicture(myPicture);
        }
    }

#if 0
    // here's how you'd add a text preview; note that the text is hard-coded here....
    if (myPreviewType == kQTFileTypeText) {
        char 	myText[] = "The penguin gradually appears from the mist of the ice floe.";

        myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + strlen(myText));
        myAtomHeader[1] = EndianU32_NtoB(myPreviewType);

        // write the atom header into the file
        mySize = sizeof(myAtomHeader);
        myErr = FSWrite(theRefNum, &mySize, myAtomHeader);
        if (myErr != noErr)
            goto bail;

        // write the atom data into the file
        mySize = strlen(myText);
        myErr = FSWrite(theRefNum, &mySize, myText);
        if (myErr != noErr)
            goto bail;
    }
#endif

#if TARGET_OS_MAC
    if (myErr == noErr) {
        short				myVolNum;

        // flush the volume
        myErr = GetVRefNum(theRefNum, &myVolNum);
        if (myErr != noErr)
            goto bail;

        myErr = FlushVol(NULL, myVolNum);
    }
#endif

bail:
    return(myErr);
}
Пример #13
-1
P0(PUBLIC pascal trap, LONGINT, LoadScrap)
{
    OSErr retval;
    INTEGER f;
    LONGINT l = Cx(ScrapSize);
    
    if (ScrapState == 0) {
        retval = FSOpen(MR(ScrapName), CW (BootDrive), &f);
        if (retval != noErr)
            return(retval);

        HUnlock(MR(ScrapHandle));
        ReallocHandle(MR(ScrapHandle), (Size)Cx(ScrapSize));
	if (MemErr != noErr)
/*-->*/	    return Cx(MemErr);
        HLock(MR(ScrapHandle));
        retval = FSReadAll(f, &l, STARH(MR(ScrapHandle)));
        HUnlock(MR(ScrapHandle));
        if (retval != noErr)
            return(retval);
        SetEOF(f, (LONGINT) 0);
        FSClose(f);
        ScrapState = CWC (1);
    }
    return(Cx(ScrapState) > 0 ? noErr : noScrapErr);
}
Пример #14
-1
A0(PUBLIC, LONGINT, ROMlib_ZeroScrap)
{
    OSErr retval;
    INTEGER f;
    THz saveZone;
    
    if (Cx(ScrapState) < 0) {
        ScrapCount = 0;
	saveZone = TheZone;
	TheZone = SysZone;
        ScrapHandle = RM(NewHandle((Size)0));
	TheZone = saveZone;
        ScrapState = CWC (1);
        ScrapName = RM((StringPtr) "\016Clipboard File");
    } else if (Cx(ScrapState) == 0) {
        retval = cropen(&f);
        if (retval != noErr)
            return retval;
        retval = SetEOF(f, (LONGINT)0);
        if (retval != noErr)
            return retval;
        FSClose(f);
    } else if (Cx(ScrapState) > 0)
        SetHandleSize(MR(ScrapHandle), (Size)0);
    ScrapSize = 0;
    ScrapCount = CW(CW(ScrapCount) + 1);
    return noErr;
}