예제 #1
0
void init_AE(void)
{
	PyObject *m;
	PyObject *d;



		upp_AEIdleProc = NewAEIdleUPP(AEIdleProc);
		upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
		upp_GenericCoercionHandler = NewAECoerceDescUPP(GenericCoercionHandler);
		
		PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
		PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_NewBorrowed);
		PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);


	m = Py_InitModule("_AE", AE_methods);
	d = PyModule_GetDict(m);
	AE_Error = PyMac_GetOSErrException();
	if (AE_Error == NULL ||
	    PyDict_SetItemString(d, "Error", AE_Error) != 0)
		return;
	AEDesc_Type.ob_type = &PyType_Type;
	if (PyType_Ready(&AEDesc_Type) < 0) return;
	Py_INCREF(&AEDesc_Type);
	PyModule_AddObject(m, "AEDesc", (PyObject *)&AEDesc_Type);
	/* Backward-compatible name */
	Py_INCREF(&AEDesc_Type);
	PyModule_AddObject(m, "AEDescType", (PyObject *)&AEDesc_Type);
}
예제 #2
0
void init_AE(void)
{
	PyObject *m;
	PyObject *d;



		upp_AEIdleProc = NewAEIdleUPP(AEIdleProc);
		upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
		upp_GenericCoercionHandler = NewAECoerceDescUPP(GenericCoercionHandler);

	

	m = Py_InitModule("_AE", AE_methods);
	d = PyModule_GetDict(m);
	AE_Error = PyMac_GetOSErrException();
	if (AE_Error == NULL ||
	    PyDict_SetItemString(d, "Error", AE_Error) != 0)
		return;
	AEDesc_Type.ob_type = &PyType_Type;
	if (PyType_Ready(&AEDesc_Type) < 0) return;
	Py_INCREF(&AEDesc_Type);
	PyModule_AddObject(m, "AEDesc", (PyObject *)&AEDesc_Type);
	/* Backward-compatible name */
	Py_INCREF(&AEDesc_Type);
	PyModule_AddObject(m, "AEDescType", (PyObject *)&AEDesc_Type);

	PyObject *aeAPIObj = PyCObject_FromVoidPtr((void *)&aeAPI, NULL);
	PyModule_AddObject(m, "aeAPI", aeAPIObj);
}
예제 #3
0
파일: main.c 프로젝트: specious/osxutils
static void PrintOSXComment (char *path)
{
	OSErr	err = noErr;
    FSRef	fileRef;
    FSSpec	fileSpec;
	Str255	comment = "\p";
	char	cStrCmt[255] = "\0";
	AEIdleUPP inIdleProc = NewAEIdleUPP(&MyAEIdleCallback);

    ///////////// Make sure we can do as we please :) /////////////

            //see if the file in question exists and we can write it
            if (access(path, R_OK|F_OK) == -1)
            {
				perror(path);
                return;
            }

            //get file reference from path
            err = FSPathMakeRef(path, &fileRef, NULL);
            if (err != noErr)
            {
				fprintf(stderr, "FSPathMakeRef: Error %d for file %s\n", err, path);
                return;
            }

            //retrieve filespec from file ref
            err = FSGetCatalogInfo (&fileRef, NULL, NULL, NULL, &fileSpec, NULL);
            if (err != noErr)
            {
				fprintf(stderr, "FSGetCatalogInfo(): Error %d getting file spec for %s\n", err, path);
                return;
            }


    ///////////// oK, now we can go about getting the comment /////////////

	// call the apple event routine. I'm not going to pretend I understand what's going on
	// in all those horribly kludgy functions, but at least it works.
	err = MoreFEGetComment(&fileRef, &fileSpec, comment, inIdleProc);
	if (err)
	{
		fprintf(stderr, "Error %d getting comment for '%s'\n", err, path);
		if (err == -600)
			fprintf(stderr, "Finder is not running\n", err);//requires Finder to be running
		return;
	}
	//convert pascal string to c string
	strncpy((char *)&cStrCmt, (unsigned char *)&comment+1, comment[0]);
	//if there is no comment, we don't print out anything
	if (!strlen((char *)&cStrCmt))
		return;

	//print out the comment
	if (!printFileName)
			printf("%s\n", (char *)&cStrCmt);
		else
			printf("Comment for '%s':\n%s\n", path, (char *)&cStrCmt);
}
예제 #4
0
파일: osx.cpp 프로젝트: r0ssar00/platform
std::string GetFileComment(std::string spath) {
	const char *path = spath.c_str();
	OSErr err = noErr;
	FSRef fileRef;
	FSSpec fileSpec;
	unsigned char *comment;
	char cStrCmt[ 255 ] = "\0";
	AEIdleUPP inIdleProc = NewAEIdleUPP(&MyAEIdleCallback);

	// see if the file in question exists and we can write it
	if (access(path, R_OK | F_OK) == - 1) {
		return "";
	}

	// get file reference from path
	err = FSPathMakeRef( (const UInt8 *) path, &fileRef, NULL);
	if (err != noErr) {
		return "";
	}

	// retrieve filespec from file ref
	err = FSGetCatalogInfo(&fileRef, NULL, NULL, NULL, &fileSpec, NULL);
	if (err != noErr) {
		return "";
	}

	// call the apple event routine. I'm not going to pretend I understand what's going on
	// in all those horribly kludgy functions, but at least it works.
	err = MoreFEGetComment(&fileSpec, comment, inIdleProc);
	if (err) {
		return "";
	}
	// convert pascal string to c string
	// strncpy((char *)&cStrCmt, (unsigned char *)&comment+1, comment[0]);
	// comment=(unsigned char *)p2cstr((unsigned char *)&cStrCmt);
	CopyPascalStringToC(comment, cStrCmt);

	// if there is no comment, we don't print out anything
	if (!strlen( (char *) &cStrCmt) )
		return "";

	// print out the comment
	if (!false)
		return std::string( (const char *) &cStrCmt);
	else
		return std::string( (const char *) &cStrCmt);
}
예제 #5
0
파일: iacapps.c 프로젝트: dvincent/frontier
Boolean IACinit (void) {
	
	/*
	returns true if the machine we're running on has Apple events, and if we are
	able to install our coercion handlers. it may do more in future versions.
	
	call this routine before using any of the other iac.c routines. disable your
	Apple event support if we return false.
	
	8/23/92 DW: only initialize once, no matter how many times we're called.
	*/
	
	static Boolean fl = false; 
	
	if (fl) 
		return (true);
		
	fl = true;
	
	if (!IAChaveappleevents ())
		return (false);
		
	if (!IACinstallcoercionhandler (typeProcessSerialNumber, typeType, (ProcPtr) &CoercePSNToType))
		return (false);
		
	if (!IACinstallcoercionhandler (typeTargetID, typeType, (ProcPtr) &CoerceTargetIDToType))
		return (false);
	
	#if TARGET_API_MAC_CARBON == 1
	
		IACwaitroutineUPP = NewAEIdleUPP ((AEIdleProcPtr) &IACwaitroutine);
	
	#else

		IACwaitroutineUPP = NewAEIdleProc (IACwaitroutine);
	
	#endif
	
	IACglobals.idprocess = IACgetprocesscreator ();

	IACglobals.waitroutine = nil;
	
	IACglobals.nextparamoptional = false;
		
	return (true);
	} /*IACinit*/