Пример #1
0
void test_hcreateresfile(void)
{
    OSErr err;

    // will 0, 0 work on real macos?

    HDelete(0, 0, fname);
    HCreateResFile(0, 0, fname);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "HCreateResFile failed (File does not exist): %d\n", err);
        exit(1);
    }

    // Verify it doesn't fail if the file/fork already exist.
    HCreateResFile(0, 0, fname);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "HCreateResFile (File/Fork exist) failed: %d\n", err);
        exit(2);
    }

    // Verify it doesn't fail if the file exists w/o a resource fork.
    HDelete(0, 0, fname);
    HCreate(0, 0, fname, 'TEST', 'BINA');
    HCreateResFile(0, 0, fname);
    if ( (err = ResError()) != 0) {
        fprintf(stderr, "HCreateResFile (File exists) failed: %d\n", err);
        exit(2);
    }

    HDelete(0, 0, fname);
}
Пример #2
0
static SInt16 *macDoOpen(const char *fname, SInt8 perm, int createIfMissing)
{
    int created = 0;
    SInt16 *retval = NULL;
    FSSpec spec;
    OSErr err = fnameToFSSpec(fname, &spec);
    BAIL_IF_MACRO((err != noErr) && (err != fnfErr), NULL, NULL);
    if (err == fnfErr)
    {
        BAIL_IF_MACRO(!createIfMissing, ERR_NO_SUCH_FILE, NULL);
        err = HCreate(spec.vRefNum, spec.parID, spec.name,
                      procInfo.processSignature, 'BINA');
        BAIL_IF_MACRO(oserr(err) != noErr, NULL, NULL);
        created = 1;
    } /* if */

    retval = (SInt16 *) malloc(sizeof (SInt16));
    if (retval == NULL)
    {
        if (created)
            HDelete(spec.vRefNum, spec.parID, spec.name);
        BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
    } /* if */

    err = HOpenDF(spec.vRefNum, spec.parID, spec.name, perm, retval);
    if (oserr(err) != noErr)
    {
        free(retval);
        if (created)
            HDelete(spec.vRefNum, spec.parID, spec.name);
        return(NULL);
    } /* if */

    return(retval);
} /* macDoOpen */
Пример #3
0
P4 (PUBLIC pascal trap, OSErr, FSpCreate,
    FSSpecPtr, spec, OSType, creator, OSType, file_type,
    ScriptCode, script)
{
    OSErr retval;

    retval = HCreate (CW (spec->vRefNum), CL (spec->parID), spec->name,
                      creator, file_type);
    return retval;
}
Пример #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
static void
FlushWinFile (void)
{
	short ref;
	long len;

	if (!winFileInit) {
		if (!winFileName [0]) {
			return;
		}
		HCreate (winFileVol, winFileDir, winFileName, MAC_CREATOR, PREF_TYPE);
		HCreateResFile (winFileVol, winFileDir, winFileName);
	}
	if (HOpen (winFileVol, winFileDir, winFileName, fsWrPerm, &ref)) {
		return;
	}
	winFileInit = 1;
	len = sizeof (savePos);
	(void) FSWrite (ref, &len, savePos); /* Don't care about error */
	FSClose (ref);
}
Пример #6
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);
}