Mercurial > emacs
comparison src/mac.c @ 67665:98b67f3d9491
(create_apple_event_from_event_ref): Remove arg `types'.
(do_applescript): Change argument types to Lisp_Object. All uses
changed.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Mon, 19 Dec 2005 08:30:27 +0000 |
parents | 2efa50cbb7cd |
children | c1eaa6ea0192 |
comparison
equal
deleted
inserted
replaced
67664:61bd8643b908 | 67665:98b67f3d9491 |
---|---|
397 return Fcons (make_unibyte_string ((char *) &desc_type, 4), result); | 397 return Fcons (make_unibyte_string ((char *) &desc_type, 4), result); |
398 } | 398 } |
399 | 399 |
400 #if TARGET_API_MAC_CARBON | 400 #if TARGET_API_MAC_CARBON |
401 OSErr | 401 OSErr |
402 create_apple_event_from_event_ref (event, num_params, names, | 402 create_apple_event_from_event_ref (event, num_params, names, types, result) |
403 types, sizes, result) | |
404 EventRef event; | 403 EventRef event; |
405 UInt32 num_params; | 404 UInt32 num_params; |
406 EventParamName *names; | 405 EventParamName *names; |
407 EventParamType *types; | 406 EventParamType *types; |
408 UInt32 *sizes; | |
409 AppleEvent *result; | 407 AppleEvent *result; |
410 { | 408 { |
411 OSErr err; | 409 OSErr err; |
412 static const ProcessSerialNumber psn = {0, kCurrentProcess}; | 410 static const ProcessSerialNumber psn = {0, kCurrentProcess}; |
413 AEAddressDesc address_desc; | 411 AEAddressDesc address_desc; |
414 UInt32 i; | 412 UInt32 i, size; |
415 CFStringRef string; | 413 CFStringRef string; |
416 CFDataRef data; | 414 CFDataRef data; |
417 char *buf; | 415 char *buf; |
418 | 416 |
419 err = AECreateDesc (typeProcessSerialNumber, &psn, | 417 err = AECreateDesc (typeProcessSerialNumber, &psn, |
450 CFRelease (data); | 448 CFRelease (data); |
451 break; | 449 break; |
452 #endif | 450 #endif |
453 | 451 |
454 default: | 452 default: |
455 buf = xmalloc (sizes[i]); | 453 err = GetEventParameter (event, names[i], types[i], NULL, |
454 0, &size, NULL); | |
455 if (err != noErr) | |
456 break; | |
457 buf = xmalloc (size); | |
456 if (buf == NULL) | 458 if (buf == NULL) |
457 break; | 459 break; |
458 err = GetEventParameter (event, names[i], types[i], NULL, | 460 err = GetEventParameter (event, names[i], types[i], NULL, |
459 sizes[i], NULL, buf); | 461 size, NULL, buf); |
460 if (err == noErr) | 462 if (err == noErr) |
461 AEPutParamPtr (result, names[i], types[i], buf, sizes[i]); | 463 AEPutParamPtr (result, names[i], types[i], buf, size); |
462 xfree (buf); | 464 xfree (buf); |
463 break; | 465 break; |
464 } | 466 } |
465 | 467 |
466 return noErr; | 468 return noErr; |
3187 into one message to be passed together with the high level event. | 3189 into one message to be passed together with the high level event. |
3188 Emacs also sometimes starts a subprocess using a shell to perform | 3190 Emacs also sometimes starts a subprocess using a shell to perform |
3189 wildcard filename expansion. Since we don't really have a shell on | 3191 wildcard filename expansion. Since we don't really have a shell on |
3190 the Mac, this case is detected and the starting of the shell is | 3192 the Mac, this case is detected and the starting of the shell is |
3191 by-passed. We really need to add code here to do filename | 3193 by-passed. We really need to add code here to do filename |
3192 expansion to support such functionality. */ | 3194 expansion to support such functionality. |
3195 | |
3196 We can't use this strategy in Carbon because the High Level Event | |
3197 APIs are not available. */ | |
3193 | 3198 |
3194 int | 3199 int |
3195 run_mac_command (argv, workdir, infn, outfn, errfn) | 3200 run_mac_command (argv, workdir, infn, outfn, errfn) |
3196 unsigned char **argv; | 3201 unsigned char **argv; |
3197 const char *workdir; | 3202 const char *workdir; |
3931 } | 3936 } |
3932 | 3937 |
3933 | 3938 |
3934 /* Compile and execute the AppleScript SCRIPT and return the error | 3939 /* Compile and execute the AppleScript SCRIPT and return the error |
3935 status as function value. A zero is returned if compilation and | 3940 status as function value. A zero is returned if compilation and |
3936 execution is successful, in which case RESULT returns a pointer to | 3941 execution is successful, in which case *RESULT is set to a Lisp |
3937 a string containing the resulting script value. Otherwise, the Mac | 3942 string containing the resulting script value. Otherwise, the Mac |
3938 error code is returned and RESULT returns a pointer to an error | 3943 error code is returned and *RESULT is set to an error Lisp string. |
3939 string. In both cases the caller should deallocate the storage | 3944 For documentation on the MacOS scripting architecture, see Inside |
3940 used by the string pointed to by RESULT if it is non-NULL. For | 3945 Macintosh - Interapplication Communications: Scripting |
3941 documentation on the MacOS scripting architecture, see Inside | 3946 Components. */ |
3942 Macintosh - Interapplication Communications: Scripting Components. */ | |
3943 | 3947 |
3944 static long | 3948 static long |
3945 do_applescript (char *script, char **result) | 3949 do_applescript (script, result) |
3946 { | 3950 Lisp_Object script, *result; |
3947 AEDesc script_desc, result_desc, error_desc; | 3951 { |
3952 AEDesc script_desc, result_desc, error_desc, *desc = NULL; | |
3948 OSErr error; | 3953 OSErr error; |
3949 OSAError osaerror; | 3954 OSAError osaerror; |
3950 long length; | 3955 |
3951 | 3956 *result = Qnil; |
3952 *result = 0; | |
3953 | 3957 |
3954 if (!as_scripting_component) | 3958 if (!as_scripting_component) |
3955 initialize_applescript(); | 3959 initialize_applescript(); |
3956 | 3960 |
3957 error = AECreateDesc (typeChar, script, strlen(script), &script_desc); | 3961 error = AECreateDesc (typeChar, SDATA (script), SBYTES (script), |
3962 &script_desc); | |
3958 if (error) | 3963 if (error) |
3959 return error; | 3964 return error; |
3960 | 3965 |
3961 osaerror = OSADoScript (as_scripting_component, &script_desc, kOSANullScript, | 3966 osaerror = OSADoScript (as_scripting_component, &script_desc, kOSANullScript, |
3962 typeChar, kOSAModeNull, &result_desc); | 3967 typeChar, kOSAModeNull, &result_desc); |
3963 | 3968 |
3964 if (osaerror == errOSAScriptError) | 3969 if (osaerror == noErr) |
3965 { | 3970 /* success: retrieve resulting script value */ |
3966 /* error executing AppleScript: retrieve error message */ | 3971 desc = &result_desc; |
3967 if (!OSAScriptError (as_scripting_component, kOSAErrorMessage, typeChar, | 3972 else if (osaerror == errOSAScriptError) |
3968 &error_desc)) | 3973 /* error executing AppleScript: retrieve error message */ |
3969 { | 3974 if (!OSAScriptError (as_scripting_component, kOSAErrorMessage, typeChar, |
3975 &error_desc)) | |
3976 desc = &error_desc; | |
3977 | |
3978 if (desc) | |
3979 { | |
3970 #if TARGET_API_MAC_CARBON | 3980 #if TARGET_API_MAC_CARBON |
3971 length = AEGetDescDataSize (&error_desc); | 3981 *result = make_uninit_string (AEGetDescDataSize (desc)); |
3972 *result = (char *) xmalloc (length + 1); | 3982 AEGetDescData (desc, SDATA (*result), SBYTES (*result)); |
3973 if (*result) | |
3974 { | |
3975 AEGetDescData (&error_desc, *result, length); | |
3976 *(*result + length) = '\0'; | |
3977 } | |
3978 #else /* not TARGET_API_MAC_CARBON */ | 3983 #else /* not TARGET_API_MAC_CARBON */ |
3979 HLock (error_desc.dataHandle); | 3984 *result = make_uninit_string (GetHandleSize (desc->dataHandle)); |
3980 length = GetHandleSize(error_desc.dataHandle); | 3985 memcpy (SDATA (*result), *(desc->dataHandle), SBYTES (*result)); |
3981 *result = (char *) xmalloc (length + 1); | |
3982 if (*result) | |
3983 { | |
3984 memcpy (*result, *(error_desc.dataHandle), length); | |
3985 *(*result + length) = '\0'; | |
3986 } | |
3987 HUnlock (error_desc.dataHandle); | |
3988 #endif /* not TARGET_API_MAC_CARBON */ | 3986 #endif /* not TARGET_API_MAC_CARBON */ |
3989 AEDisposeDesc (&error_desc); | 3987 AEDisposeDesc (desc); |
3990 } | |
3991 } | |
3992 else if (osaerror == noErr) /* success: retrieve resulting script value */ | |
3993 { | |
3994 #if TARGET_API_MAC_CARBON | |
3995 length = AEGetDescDataSize (&result_desc); | |
3996 *result = (char *) xmalloc (length + 1); | |
3997 if (*result) | |
3998 { | |
3999 AEGetDescData (&result_desc, *result, length); | |
4000 *(*result + length) = '\0'; | |
4001 } | |
4002 #else /* not TARGET_API_MAC_CARBON */ | |
4003 HLock (result_desc.dataHandle); | |
4004 length = GetHandleSize(result_desc.dataHandle); | |
4005 *result = (char *) xmalloc (length + 1); | |
4006 if (*result) | |
4007 { | |
4008 memcpy (*result, *(result_desc.dataHandle), length); | |
4009 *(*result + length) = '\0'; | |
4010 } | |
4011 HUnlock (result_desc.dataHandle); | |
4012 #endif /* not TARGET_API_MAC_CARBON */ | |
4013 AEDisposeDesc (&result_desc); | |
4014 } | 3988 } |
4015 | 3989 |
4016 AEDisposeDesc (&script_desc); | 3990 AEDisposeDesc (&script_desc); |
4017 | 3991 |
4018 return osaerror; | 3992 return osaerror; |
4026 displays the error message returned by the AppleScript scripting | 4000 displays the error message returned by the AppleScript scripting |
4027 component. */) | 4001 component. */) |
4028 (script) | 4002 (script) |
4029 Lisp_Object script; | 4003 Lisp_Object script; |
4030 { | 4004 { |
4031 char *result, *temp; | 4005 Lisp_Object result; |
4032 Lisp_Object lisp_result; | |
4033 long status; | 4006 long status; |
4034 | 4007 |
4035 CHECK_STRING (script); | 4008 CHECK_STRING (script); |
4036 | 4009 |
4037 BLOCK_INPUT; | 4010 BLOCK_INPUT; |
4038 status = do_applescript (SDATA (script), &result); | 4011 status = do_applescript (script, &result); |
4039 UNBLOCK_INPUT; | 4012 UNBLOCK_INPUT; |
4040 if (status) | 4013 if (status == 0) |
4041 { | 4014 return result; |
4042 if (!result) | 4015 else if (!STRINGP (result)) |
4043 error ("AppleScript error %d", status); | 4016 error ("AppleScript error %d", status); |
4044 else | 4017 else |
4045 { | 4018 error ("%s", SDATA (result)); |
4046 /* Unfortunately only OSADoScript in do_applescript knows how | |
4047 how large the resulting script value or error message is | |
4048 going to be and therefore as caller memory must be | |
4049 deallocated here. It is necessary to free the error | |
4050 message before calling error to avoid a memory leak. */ | |
4051 temp = (char *) alloca (strlen (result) + 1); | |
4052 strcpy (temp, result); | |
4053 xfree (result); | |
4054 error (temp); | |
4055 } | |
4056 } | |
4057 else | |
4058 { | |
4059 lisp_result = build_string (result); | |
4060 xfree (result); | |
4061 return lisp_result; | |
4062 } | |
4063 } | 4019 } |
4064 | 4020 |
4065 | 4021 |
4066 DEFUN ("mac-file-name-to-posix", Fmac_file_name_to_posix, | 4022 DEFUN ("mac-file-name-to-posix", Fmac_file_name_to_posix, |
4067 Smac_file_name_to_posix, 1, 1, 0, | 4023 Smac_file_name_to_posix, 1, 1, 0, |