Ejemplo n.º 1
0
OSErr choose_new_file(
	short *file_handle,
	short *reference_number,
	char *file_name,
	char *prompt,
	long creator,
	long file_type)
{
	Point location;
	SFReply reply;
	OSErr error;
	
	SetPt(&location, 40, 60);
	SFPutFile(location, prompt, file_name, (DlgHookProcPtr) NULL, &reply);
	if (reply.good)
	{
		error= Create(reply.fName, reply.vRefNum, creator, file_type);
		if (error==dupFNErr||error==noErr)
		{
			strncpy(file_name, reply.fName, *reply.fName+1);
			*reference_number= reply.vRefNum;
			
			error= FSOpen(reply.fName, reply.vRefNum, file_handle);
		}
	}
	else
	{
		error= userCanceledErr;
	}
	
	return error;
}
Ejemplo n.º 2
0
Archivo: ugView.c Proyecto: rolk/ug
static void SaveToPICT (SFReply *reply)
{
  Rect MyPicFrame ;
  CQDProcs MyPicProcs,*SavePtr ;
  OSErr error ;
  long LongZero, LongCount ;
  short Counter ;
  CGrafPtr theCGrafPort;
  WindowPtr theWindow;
  OpenCPicParams myOpenCPicParams;

  /* get my window */
  theWindow = myWindow.theWindow;
  theCGrafPort = (CGrafPtr) theWindow;

  error = FSOpen(reply->fName, reply->vRefNum, &FileSys_RefNR ) ;
  SetStdCProcs ( &MyPicProcs ) ;
  SavePtr = (CQDProcs *) theWindow->grafProcs;
  theWindow->grafProcs   = (QDProcs *) (&MyPicProcs) ;
  MyPicProcs.putPicProc  = NewQDPutPicProc(MyPutPicData) ;

  LongZero   = 0 ;
  LongCount  = 4 ;

  PicCounter = sizeof(Picture) ;
  for (Counter=1 ; Counter <= 128+sizeof(Picture) ; Counter++ )
    error = FSWrite(FileSys_RefNR, &LongCount, &LongZero );
  error = SetFPos(FileSys_RefNR, fsFromStart, 512+sizeof(Picture)) ;

  SetPort((GrafPtr)(theWindow));
  MyPicFrame = ((GrafPtr)(theWindow))->portRect;
  MyPicFrame.right = MyPicFrame.right-16;
  MyPicFrame.bottom = MyPicFrame.bottom-16;
  MyPicHand  = NULL ;
  myOpenCPicParams.srcRect        = MyPicFrame;
  myOpenCPicParams.hRes           = cHRes;
  myOpenCPicParams.vRes           = cVRes;
  myOpenCPicParams.version        = -2;
  myOpenCPicParams.reserved1      = 0;
  myOpenCPicParams.reserved2      = 0;
  MyPicHand  = OpenCPicture ( &myOpenCPicParams );
  ClipRect(&MyPicFrame);

  /* draw picture */
  RefreshCommand();

  ClosePicture() ;

  /* close File */
  error = SetFPos(FileSys_RefNR, fsFromStart, 512) ;
  LongCount = sizeof(Picture) ;
  error = FSWrite(FileSys_RefNR, &LongCount, (void *) (*MyPicHand) );
  error = FSClose(FileSys_RefNR) ;

  KillPicture(MyPicHand);
  theWindow->grafProcs   = (QDProcs *) SavePtr ;

  return;
}
Ejemplo n.º 3
0
/*
 * Open a TIFF file for read/writing.
 */
TIFF*
TIFFOpen(const char* name, const char* mode)
{
	static const char module[] = "TIFFOpen";
	Str255 pname;
	FInfo finfo;
	short fref;
	OSErr err;

	strcpy((char*) pname, name);
	CtoPstr((char*) pname);

	switch (_TIFFgetMode(mode, module)) {
	default:
		return ((TIFF*) 0);
	case O_RDWR | O_CREAT | O_TRUNC:
		if (GetFInfo(pname, 0, &finfo) == noErr)
			FSDelete(pname, 0);
		/* fall through */
	case O_RDWR | O_CREAT:
		if ((err = GetFInfo(pname, 0, &finfo)) == fnfErr) {
			if (Create(pname, 0, '    ', 'TIFF') != noErr)
				goto badCreate;
			if (FSOpen(pname, 0, &fref) != noErr)
				goto badOpen;
		} else if (err == noErr) {
			if (FSOpen(pname, 0, &fref) != noErr)
				goto badOpen;
		} else
			goto badOpen;
		break;
	case O_RDONLY:
	case O_RDWR:
		if (FSOpen(pname, 0, &fref) != noErr)
			goto badOpen;
		break;
	}
	return (TIFFFdOpen((int) fref, name, mode));
badCreate:
	TIFFError(module, "%s: Cannot create", name);
	return ((TIFF*) 0);
badOpen:
	TIFFError(module, "%s: Cannot open", name);
	return ((TIFF*) 0);
}
Ejemplo n.º 4
0
PicHandle OpenPICTFile(
	short 	vRefNum, 
	Str255 	fName)
{
	short		fRefNum;
	OSErr		err;
	long		curEOF;
	PicHandle	myPic;
	long 		count;
	Ptr 		buffer;
	
	/* open PICT file */
	err = FSOpen(fName, vRefNum, &fRefNum);
	if (err != 0) {
		/*printf("Error - cannot open file\n"); */
		exit(-1);
	}
	
	/* get size of file */
	err = GetEOF(fRefNum, &curEOF);
	if (err != 0) {
		/*printf("Error - cannot get EOF\n"); */
		exit(-2);
	}
	
	/* move the file mark to 512 */
	err = SetFPos(fRefNum, SEEK_SET, 512L);
	if (err != 0) {
		/*printf("Error - cannot seek 512\n"); */
		exit(-3);
	}

	/* size of data to read */
	count = curEOF - 512;
	
	/* create the PicHandle */
	myPic = (PicHandle)NewHandle(count);
	HLock((Handle)myPic);
	
	/* read the PICT info */
	buffer = (Ptr)(*myPic);
	err = FSRead(fRefNum, &count, buffer);
	if (err != 0) {
		/*printf("Error - cannot read\n");*/
		exit(-4);
	}
	HUnlock((Handle)myPic);
	
	/* release the file */
	err = FSClose(fRefNum);
	if (err != 0) {
		/*printf("Error - cannot close file \n"); */
		exit(-5);
	}
	
	return (myPic);
}
Ejemplo n.º 5
0
P3(PUBLIC pascal trap, LONGINT, PutScrap, LONGINT, len, ResType, rest, Ptr, p)
{
    OSErr retval;
    LONGINT l, swappedlen;
    INTEGER f;

    LONGINT *lp;

    if (Cx(ScrapState) < 0) {
        retval = ZeroScrap();
	if (retval != noErr)
/*-->*/	    return(retval);
    }
#if defined(X) || defined(NEXTSTEP) || defined (SDL)
    PutScrapX(rest, len, (char *) p, CW (ScrapCount));
#endif /* defined(X) */
    if (Cx(ScrapState) == 0) {
        retval = FSOpen(MR(ScrapName), CW (BootDrive), &f);
        if (retval != noErr)
/*-->*/     return(retval);
        SetFPos(f, fsFromStart, (LONGINT)Cx(ScrapSize));
        l = 4;
	rest = CL(rest);
        FSWriteAll(f, &l, (Ptr) &rest);
        l = 4;
	swappedlen = CL(len);
        FSWriteAll(f, &l, (Ptr) &swappedlen);
        l = len = (len + 1) & -2L;
        FSWriteAll(f, &len, p);
        FSClose(f);
    } else {
        SetHandleSize(MR(ScrapHandle), (Size)Cx(ScrapSize) + 8);
	if (MemErr != noErr)
/*-->*/	    return CW(MemErr);
	/* alignment stuff */
        lp = (LONGINT *)((char *)STARH(MR(ScrapHandle)) + Cx(ScrapSize));
        *lp++ = CL(rest);
        *lp++ = CL(len);
        len = (len + 1) & -2L;
        PtrAndHand(p, MR(ScrapHandle), (Size)len);
    }
    ScrapSize = CL(CL(ScrapSize) + 8 + len);
    return noErr;
}
Ejemplo n.º 6
0
OSErr choose_and_open_file(
	short *file_handle,
	short *reference_number,
	char *file_name,
	long spec1,
	long spec2,
	long spec3,
	long spec4)
{
	Point location;
	SFTypeList filetypes;
	SFReply reply;
	OSErr error;
	short count;

	filetypes[0]= spec1, filetypes[1]= spec2, filetypes[2]= spec3, filetypes[3]= spec4;
	for (count=0;count<4;++count)
	{
		if (!filetypes[count])
		{
			break;
		}
	}
	
	SetPt(&location, 40, 60);
	SFGetFile(location, (char *) NULL, NULL, count, filetypes, NULL, &reply);

	if (reply.good)
	{
		strncpy(file_name, reply.fName, reply.fName[0]+1);
		*reference_number= reply.vRefNum;

		error= FSOpen(reply.fName, reply.vRefNum, file_handle);
	}
	else
	{
		error= userCanceledErr;
	}
	
	return error;
}
Ejemplo n.º 7
0
/////////////////////////////////////
// Name:	CmdExecFile
// Purpose:	execute commands from file
// Output:	stuff executed
// Return:	TRUE if success
/////////////////////////////////////
s32 CmdExecFile(const tCHAR *filename)
{
	hFILE fp = FSOpen(filename, L"rt");

	if(!fp)
		return FALSE;

	tCHAR buff[MAXCHARBUFF];

	while(!FSEOF(fp))
	{
		ParserReadStringFile(fp, buff, MAXCHARBUFF, 0, '\n');
		
		if(buff[0] != 0)
			CmdCallStr(buff);
	}

	//in case we had 'wait' commands in the file, which we should not
	g_postWait = FALSE;

	return TRUE;
}
Ejemplo n.º 8
0
NCSError NCSFileOpen(const NCSTChar *szFilename, int iFlags, NCS_FILE_HANDLE *phFile)
{
#ifdef WIN32
	DWORD dwMode = GENERIC_READ;
	DWORD dwCreate = OPEN_EXISTING;

	if(iFlags & NCS_FILE_READ) dwMode = GENERIC_READ;
	if(iFlags & NCS_FILE_READ_WRITE) dwMode = GENERIC_READ|GENERIC_WRITE;
	if(iFlags & NCS_FILE_CREATE) dwCreate = CREATE_ALWAYS;
	if(iFlags & NCS_FILE_CREATE_UNIQUE) dwCreate = CREATE_NEW;
	if(iFlags & NCS_FILE_APPEND) dwCreate = OPEN_ALWAYS;

	*phFile = CreateFile(szFilename,			        // file name
						 dwMode,						// Generic read mode 
						 FILE_SHARE_READ,				// Let anyone access and share the file
						 NULL,							// No security info (so can't be inherited by child process)
						 dwCreate,						// File must exist to be opened
						 FILE_FLAG_RANDOM_ACCESS,		// Going to be doing lots of random access
						 NULL);							// And no template file for attributes
	if( *phFile == INVALID_HANDLE_VALUE ) {
		return( NCS_FILE_OPEN_FAILED );
	} else {
		return( NCS_SUCCESS );
	}

#elif defined MACINTOSH
#if __POWERPC__
	
	int i,length, result;
	Str255		pascalString;
	FSSpec		fileSpec;
		//	We have a C string, we need a PASCAL string.
	length = strlen(szFilename) + 1;
	for(i = 1; i < length; ++i)
		pascalString[i] = szFilename[i - 1];
	pascalString[0] = strlen(szFilename);
			
	//	Create a File Specification Record, then create a File
	result = FSMakeFSSpec(0,0,pascalString,&fileSpec);	// return is meaningless, since the only possible error doesn't effect processing in this case
			
	switch(result) {
		case noErr:
				// we could dRes pFile here, but we are the only user
				result =FSpOpenDF(&fileSpec, fsRdPerm, (short *)phFile);
				if(result) return NCS_FILE_OPEN_FAILED;
				else return NCS_SUCCESS;
			break;
		default:
			    return NCS_SUCCESS;
		    break;
	}

#else	/* __POWERPC__ */

	int i,length, result;
	Str255		pascalString;
	//	We have a C string, we need a PASCAL string.
	length = strlen(szFilename) + 1;
	for(i = 1; i < length; ++i)
		pascalString[i] = szFilename[i - 1];
	pascalString[0] = strlen(szFilename);
		
	result =FSOpen(pascalString, 0, (short *)phFile);
	if(result) return TRUE;
	else return FALSE;

#endif	/* __POWERPC__ */
#elif defined PALM

	NCS_FILE_HANDLE hFile;
	Err eErr;
	UInt32 nMode = 0;
	
	if(hFile = (NCS_FILE_HANDLE)NCSMalloc(sizeof(NCS_FILE_HANDLE_STRUCT), TRUE)) {
		hFile->dbID = DmFindDatabase(0, szFilename);
		
		if(hFile->dbID) {
	   		Char nameP[dmDBNameLength];
	   		UInt16 attributes;
	   		UInt16 version;
	   		UInt32 crDate;
	   		UInt32 modDate;
	   		UInt32 bckUpDate;
	   		UInt32 modNum;
	   		LocalID appInfoID;
	   		LocalID sortInfoID;
	   		UInt32 type;
	   		UInt32 creator;
					
	   		DmDatabaseInfo(0, hFile->dbID, nameP,
	   					   &attributes, 
	   					   &version,
	   					   &crDate,
	   					   &modDate,
	   					   &bckUpDate,
	   					   &modNum,
	   					   &appInfoID,
	   					   &sortInfoID,
	   					   &type,
	   					   &creator);
	   					   
	   		if(creator == NCS_PALM_CREATOR_ID) {
	   			if(hFile->dbRef = DmOpenDatabase(0, hFile->dbID, dmModeReadOnly|dmModeShowSecret)) {
	   				UInt32 nRecords;
	   				UInt32 nTotalBytes;
	   				UInt32 nDataBytes;
	   				
	   				eErr = DmDatabaseSize(0, hFile->dbID, &nRecords, &nTotalBytes, &nDataBytes);
	   				
	   				if(eErr == errNone) {
	   					MemHandle hRecord;
	   					
	   					hFile->nRecords = nRecords;
	   					hFile->nDBSize = nDataBytes;
#ifdef NOTDEF	   					
	   					if(hRecord = DmGetRecord(hFile->dbRef, 0)) {
	   						MemPtr pData;
	   						
							if(pData = MemHandleLock(hRecord)) {
								hFile->nRecordSize = ((UINT16*)pData)[0];
							
								MemHandleUnlock(hRecord);
							}
							DmReleaseRecord(hFile->dbRef, 0, false);
						}
#endif
						*phFile = hFile;
						return(NCS_SUCCESS);
	   				}
	   				DmCloseDatabase(hFile->dbRef);
	   				return(NCSPalmGetNCSError(eErr));
	   			}
	   		}
		}
	} else {
		return(NCS_COULDNT_ALLOC_MEMORY);
	}
/*	
	if(iFlags & NCS_FILE_READ) nMode = fileModeReadOnly|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_READ_WRITE) nMode = fileModeUpdate|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_CREATE) nMode = fileModeReadWrite|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_CREATE_UNIQUE) nMode = fileModeReadWrite|fileModeDontOverwrite|fileModeAnyTypeCreator;
	if(iFlags & NCS_FILE_APPEND) nMode = fileModeAppend|fileModeAnyTypeCreator;
	
	*phFile = FileOpen(0, (char*)szFilename, 0, 0, nMode, &eErr);
	
	return(NCSPalmGetNCSError(eErr));			   
*/					
#elif defined(POSIX)

	int flags = O_RDONLY;

	if(iFlags & NCS_FILE_READ) flags = O_RDONLY;
	if(iFlags & NCS_FILE_READ_WRITE) flags = O_RDWR;
	if(iFlags & NCS_FILE_CREATE) flags |= O_CREAT;
	if(iFlags & NCS_FILE_CREATE_UNIQUE) flags |= O_CREAT|O_EXCL;
	if(iFlags & NCS_FILE_APPEND) flags |= O_APPEND;

#if defined SOLARIS || (defined(HPUX) && !defined(__LP64__))
	// Enable 64bit!
	flags |= O_LARGEFILE;
#endif

#ifdef HPUX
	*phFile = open64((const char*)CHAR_STRING(szFilename), (int)flags);

#ifdef NOTDEF
	if (*phFile < 0) {
		fprintf(stderr, "Error opening file : %ld\n", errno); 
		if (errno == EOVERFLOW) {
			fprintf(stderr, "The named file is a regular file and the size "
                          "of the file cannot be represented correctly in an object of "
                          "size off_t.");
		}
	}
#endif

#else
	*phFile = open((const char*)CHAR_STRING(szFilename), (int)flags, S_IRUSR|S_IWUSR);
#endif
	if(*phFile != -1) {
		return(NCS_SUCCESS);
	} else {
		return(NCS_FILE_OPEN_FAILED);
	}

#else	/* SOLARIS||IRIX */
#error ERROR  EcwFileCreate() routine is not defined for this platform
#endif	/* WIN32 */
}
Ejemplo n.º 9
0
P3(PUBLIC pascal trap, LONGINT, GetScrap, Handle, h, ResType, rest,
								LONGINT *, off)
{
    OSErr retval;
    LONGINT l = 0, incr, s, ltoread, restlen[2];
    unsigned char *p;
    int found;
    INTEGER f;
    Handle temph;

#if !defined (LETGCCWAIL)
    s = 0;
#endif /* LETGCCWAIL */
    if (h)
	temph = 0;
    else {
	temph = NewHandle((Size) 0);
	h = temph;
    }
    
#if defined(X) || defined(NEXTSTEP) || defined (SDL)
    s = GetScrapX(rest, (char **) h);
    if (s >= 0) {
        *off = 0;	/* ack... could mess people up */
/*-->*/ RETURN(s);
    }
#endif /* defined(X) */
    if (Cx(ScrapState) < 0) {
        retval = ZeroScrap();
	if (retval != noErr)
/*-->*/	    RETURN(retval);
    }
    if (ScrapState == 0) {
        retval = FSOpen(MR(ScrapName), CW (BootDrive), &f);
        if (retval != noErr)
/*-->*/     RETURN(retval);
        found = FALSE;
        while (l < Cx(ScrapSize)  && !found) {
            ltoread = 8;
            FSReadAll(f, &ltoread, (Ptr) restlen);
	    s = CL(restlen[1]);
            if (rest == CL(restlen[0]))
                found = TRUE;
            else {
                incr = (8 + s + 1) & ~1L;
                l += incr;
                SetFPos(f, fsFromMark, incr);
            }
        }
        if (l >= Cx(ScrapSize)) {
            FSClose(f);
/*-->*/     RETURN(noTypeErr);
        }
        ReallocHandle(h, s);
	if (MemErr != noErr)
/*-->*/	    RETURN(CW(MemErr));
        HLock(h);
        ltoread = s;
        FSReadAll(f, &ltoread, STARH(h));
        HUnlock(h);
        FSClose(f);
    } else {
        HLock(MR(ScrapHandle));
        p = MR(*(unsigned char **)MR(ScrapHandle));
#if 1 || !defined(QUADALIGN)
        while (l < Cx(ScrapSize) && rest != CL(*(LONGINT *)p))
	  {
	    s = CL (*((LONGINT *) p + 1));
            incr = (8 + s + 1) & ~1L;
            l += incr;
            p += incr;
	  }
        if (l >= Cx(ScrapSize))
	  {
	    HUnlock(MR(ScrapHandle));
/*-->*/     RETURN(noTypeErr);
	  }
	s = CL (*((LONGINT *)p + 1));
#else /* QUADALIGN */
        while (l < Cx(ScrapSize) && rest != SNAGLONG(p)) {
            incr = 8 + ((s = SNAGLONG(p + sizeof(LONGINT))) + 1) & -2L;
            l += incr;
            p += incr;
        }
        if (l >= Cx(ScrapSize))
	  {
	    HUnlock(MR(ScrapHandle));
/*-->*/     RETURN(noTypeErr);
	  }
	s = *((LONGINT *)p + 1);
#endif /* QUADALIGN */
        PtrToXHand((Ptr) (p+8), h, s);
        HUnlock(MR(ScrapHandle));
    }
    *off = CL(l+8);
    RETURN(s);
}
Ejemplo n.º 10
-1
A1(PRIVATE, OSErr, cropen, INTEGER *, fp)
{
    OSErr retval;
    
    retval = FSOpen(MR(ScrapName), CW (BootDrive), fp);
    if (retval == fnfErr) {
        retval = Create(MR(ScrapName), CW (BootDrive), TICK("MACS"), TICK("CLIP"));
        if (retval != noErr)
            return(retval);
        return(FSOpen(MR(ScrapName), CW (BootDrive), fp));
    }
    return(retval);
}
Ejemplo n.º 11
-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);
}