diff options
Diffstat (limited to 'src/mac.c')
| -rw-r--r-- | src/mac.c | 180 |
1 files changed, 166 insertions, 14 deletions
| @@ -270,6 +270,26 @@ posix_to_mac_pathname (const char *ufn, char *mfn, int mfnbuflen) | |||
| 270 | 270 | ||
| 271 | static Lisp_Object Qundecoded_file_name; | 271 | static Lisp_Object Qundecoded_file_name; |
| 272 | 272 | ||
| 273 | static struct { | ||
| 274 | AEKeyword keyword; | ||
| 275 | char *name; | ||
| 276 | Lisp_Object symbol; | ||
| 277 | } ae_attr_table [] = | ||
| 278 | {{keyTransactionIDAttr, "transaction-id"}, | ||
| 279 | {keyReturnIDAttr, "return-id"}, | ||
| 280 | {keyEventClassAttr, "event-class"}, | ||
| 281 | {keyEventIDAttr, "event-id"}, | ||
| 282 | {keyAddressAttr, "address"}, | ||
| 283 | {keyOptionalKeywordAttr, "optional-keyword"}, | ||
| 284 | {keyTimeoutAttr, "timeout"}, | ||
| 285 | {keyInteractLevelAttr, "interact-level"}, | ||
| 286 | {keyEventSourceAttr, "event-source"}, | ||
| 287 | /* {keyMissedKeywordAttr, "missed-keyword"}, */ | ||
| 288 | {keyOriginalAddressAttr, "original-address"}, | ||
| 289 | {keyReplyRequestedAttr, "reply-requested"}, | ||
| 290 | {KEY_EMACS_SUSPENSION_ID_ATTR, "emacs-suspension-id"} | ||
| 291 | }; | ||
| 292 | |||
| 273 | static Lisp_Object | 293 | static Lisp_Object |
| 274 | mac_aelist_to_lisp (desc_list) | 294 | mac_aelist_to_lisp (desc_list) |
| 275 | const AEDescList *desc_list; | 295 | const AEDescList *desc_list; |
| @@ -281,22 +301,36 @@ mac_aelist_to_lisp (desc_list) | |||
| 281 | Size size; | 301 | Size size; |
| 282 | AEKeyword keyword; | 302 | AEKeyword keyword; |
| 283 | AEDesc desc; | 303 | AEDesc desc; |
| 304 | int attribute_p = 0; | ||
| 284 | 305 | ||
| 285 | err = AECountItems (desc_list, &count); | 306 | err = AECountItems (desc_list, &count); |
| 286 | if (err != noErr) | 307 | if (err != noErr) |
| 287 | return Qnil; | 308 | return Qnil; |
| 288 | result = Qnil; | 309 | result = Qnil; |
| 310 | |||
| 311 | again: | ||
| 289 | while (count > 0) | 312 | while (count > 0) |
| 290 | { | 313 | { |
| 291 | err = AESizeOfNthItem (desc_list, count, &desc_type, &size); | 314 | if (attribute_p) |
| 315 | { | ||
| 316 | keyword = ae_attr_table[count - 1].keyword; | ||
| 317 | err = AESizeOfAttribute (desc_list, keyword, &desc_type, &size); | ||
| 318 | } | ||
| 319 | else | ||
| 320 | err = AESizeOfNthItem (desc_list, count, &desc_type, &size); | ||
| 321 | |||
| 292 | if (err == noErr) | 322 | if (err == noErr) |
| 293 | switch (desc_type) | 323 | switch (desc_type) |
| 294 | { | 324 | { |
| 295 | case typeAEList: | 325 | case typeAEList: |
| 296 | case typeAERecord: | 326 | case typeAERecord: |
| 297 | case typeAppleEvent: | 327 | case typeAppleEvent: |
| 298 | err = AEGetNthDesc (desc_list, count, typeWildCard, | 328 | if (attribute_p) |
| 299 | &keyword, &desc); | 329 | err = AEGetAttributeDesc (desc_list, keyword, typeWildCard, |
| 330 | &desc); | ||
| 331 | else | ||
| 332 | err = AEGetNthDesc (desc_list, count, typeWildCard, | ||
| 333 | &keyword, &desc); | ||
| 300 | if (err != noErr) | 334 | if (err != noErr) |
| 301 | break; | 335 | break; |
| 302 | elem = mac_aelist_to_lisp (&desc); | 336 | elem = mac_aelist_to_lisp (&desc); |
| @@ -309,8 +343,13 @@ mac_aelist_to_lisp (desc_list) | |||
| 309 | else | 343 | else |
| 310 | { | 344 | { |
| 311 | elem = make_uninit_string (size); | 345 | elem = make_uninit_string (size); |
| 312 | err = AEGetNthPtr (desc_list, count, typeWildCard, &keyword, | 346 | if (attribute_p) |
| 313 | &desc_type, SDATA (elem), size, &size); | 347 | err = AEGetAttributePtr (desc_list, keyword, typeWildCard, |
| 348 | &desc_type, SDATA (elem), | ||
| 349 | size, &size); | ||
| 350 | else | ||
| 351 | err = AEGetNthPtr (desc_list, count, typeWildCard, &keyword, | ||
| 352 | &desc_type, SDATA (elem), size, &size); | ||
| 314 | } | 353 | } |
| 315 | if (err != noErr) | 354 | if (err != noErr) |
| 316 | break; | 355 | break; |
| @@ -319,18 +358,35 @@ mac_aelist_to_lisp (desc_list) | |||
| 319 | break; | 358 | break; |
| 320 | } | 359 | } |
| 321 | 360 | ||
| 322 | if (err != noErr) | 361 | if (err == noErr || desc_list->descriptorType == typeAEList) |
| 323 | elem = Qnil; | ||
| 324 | else if (desc_list->descriptorType != typeAEList) | ||
| 325 | { | 362 | { |
| 326 | keyword = EndianU32_NtoB (keyword); | 363 | if (err != noErr) |
| 327 | elem = Fcons (make_unibyte_string ((char *) &keyword, 4), elem); | 364 | elem = Qnil; /* Don't skip elements in AEList. */ |
| 365 | else if (desc_list->descriptorType != typeAEList) | ||
| 366 | { | ||
| 367 | if (attribute_p) | ||
| 368 | elem = Fcons (ae_attr_table[count-1].symbol, elem); | ||
| 369 | else | ||
| 370 | { | ||
| 371 | keyword = EndianU32_NtoB (keyword); | ||
| 372 | elem = Fcons (make_unibyte_string ((char *) &keyword, 4), | ||
| 373 | elem); | ||
| 374 | } | ||
| 375 | } | ||
| 376 | |||
| 377 | result = Fcons (elem, result); | ||
| 328 | } | 378 | } |
| 329 | 379 | ||
| 330 | result = Fcons (elem, result); | ||
| 331 | count--; | 380 | count--; |
| 332 | } | 381 | } |
| 333 | 382 | ||
| 383 | if (desc_list->descriptorType == typeAppleEvent && !attribute_p) | ||
| 384 | { | ||
| 385 | attribute_p = 1; | ||
| 386 | count = sizeof (ae_attr_table) / sizeof (ae_attr_table[0]); | ||
| 387 | goto again; | ||
| 388 | } | ||
| 389 | |||
| 334 | desc_type = EndianU32_NtoB (desc_list->descriptorType); | 390 | desc_type = EndianU32_NtoB (desc_list->descriptorType); |
| 335 | return Fcons (make_unibyte_string ((char *) &desc_type, 4), result); | 391 | return Fcons (make_unibyte_string ((char *) &desc_type, 4), result); |
| 336 | } | 392 | } |
| @@ -403,6 +459,93 @@ mac_aedesc_to_lisp (desc) | |||
| 403 | return Fcons (make_unibyte_string ((char *) &desc_type, 4), result); | 459 | return Fcons (make_unibyte_string ((char *) &desc_type, 4), result); |
| 404 | } | 460 | } |
| 405 | 461 | ||
| 462 | OSErr | ||
| 463 | mac_ae_put_lisp (desc, keyword_or_index, obj) | ||
| 464 | AEDescList *desc; | ||
| 465 | UInt32 keyword_or_index; | ||
| 466 | Lisp_Object obj; | ||
| 467 | { | ||
| 468 | OSErr err; | ||
| 469 | |||
| 470 | if (!(desc->descriptorType == typeAppleEvent | ||
| 471 | || desc->descriptorType == typeAERecord | ||
| 472 | || desc->descriptorType == typeAEList)) | ||
| 473 | return errAEWrongDataType; | ||
| 474 | |||
| 475 | if (CONSP (obj) && STRINGP (XCAR (obj)) && SBYTES (XCAR (obj)) == 4) | ||
| 476 | { | ||
| 477 | DescType desc_type1 = EndianU32_BtoN (*((UInt32 *) SDATA (XCAR (obj)))); | ||
| 478 | Lisp_Object data = XCDR (obj), rest; | ||
| 479 | AEDesc desc1; | ||
| 480 | |||
| 481 | switch (desc_type1) | ||
| 482 | { | ||
| 483 | case typeNull: | ||
| 484 | case typeAppleEvent: | ||
| 485 | break; | ||
| 486 | |||
| 487 | case typeAEList: | ||
| 488 | case typeAERecord: | ||
| 489 | err = AECreateList (NULL, 0, desc_type1 == typeAERecord, &desc1); | ||
| 490 | if (err == noErr) | ||
| 491 | { | ||
| 492 | for (rest = data; CONSP (rest); rest = XCDR (rest)) | ||
| 493 | { | ||
| 494 | UInt32 keyword_or_index1 = 0; | ||
| 495 | Lisp_Object elem = XCAR (rest); | ||
| 496 | |||
| 497 | if (desc_type1 == typeAERecord) | ||
| 498 | { | ||
| 499 | if (CONSP (elem) && STRINGP (XCAR (elem)) | ||
| 500 | && SBYTES (XCAR (elem)) == 4) | ||
| 501 | { | ||
| 502 | keyword_or_index1 = | ||
| 503 | EndianU32_BtoN (*((UInt32 *) | ||
| 504 | SDATA (XCAR (elem)))); | ||
| 505 | elem = XCDR (elem); | ||
| 506 | } | ||
| 507 | else | ||
| 508 | continue; | ||
| 509 | } | ||
| 510 | |||
| 511 | err = mac_ae_put_lisp (&desc1, keyword_or_index1, elem); | ||
| 512 | if (err != noErr) | ||
| 513 | break; | ||
| 514 | } | ||
| 515 | |||
| 516 | if (err == noErr) | ||
| 517 | { | ||
| 518 | if (desc->descriptorType == typeAEList) | ||
| 519 | err = AEPutDesc (desc, keyword_or_index, &desc1); | ||
| 520 | else | ||
| 521 | err = AEPutParamDesc (desc, keyword_or_index, &desc1); | ||
| 522 | } | ||
| 523 | |||
| 524 | AEDisposeDesc (&desc1); | ||
| 525 | } | ||
| 526 | return err; | ||
| 527 | |||
| 528 | default: | ||
| 529 | if (!STRINGP (data)) | ||
| 530 | break; | ||
| 531 | if (desc->descriptorType == typeAEList) | ||
| 532 | err = AEPutPtr (desc, keyword_or_index, desc_type1, | ||
| 533 | SDATA (data), SBYTES (data)); | ||
| 534 | else | ||
| 535 | err = AEPutParamPtr (desc, keyword_or_index, desc_type1, | ||
| 536 | SDATA (data), SBYTES (data)); | ||
| 537 | return err; | ||
| 538 | } | ||
| 539 | } | ||
| 540 | |||
| 541 | if (desc->descriptorType == typeAEList) | ||
| 542 | err = AEPutPtr (desc, keyword_or_index, typeNull, NULL, 0); | ||
| 543 | else | ||
| 544 | err = AEPutParamPtr (desc, keyword_or_index, typeNull, NULL, 0); | ||
| 545 | |||
| 546 | return err; | ||
| 547 | } | ||
| 548 | |||
| 406 | static pascal OSErr | 549 | static pascal OSErr |
| 407 | mac_coerce_file_name_ptr (type_code, data_ptr, data_size, | 550 | mac_coerce_file_name_ptr (type_code, data_ptr, data_size, |
| 408 | to_type, handler_refcon, result) | 551 | to_type, handler_refcon, result) |
| @@ -722,8 +865,7 @@ create_apple_event_from_event_ref (event, num_params, names, types, result) | |||
| 722 | '?'); | 865 | '?'); |
| 723 | if (data == NULL) | 866 | if (data == NULL) |
| 724 | break; | 867 | break; |
| 725 | /* typeUTF8Text is not available on Mac OS X 10.1. */ | 868 | AEPutParamPtr (result, names[i], typeUTF8Text, |
| 726 | AEPutParamPtr (result, names[i], 'utf8', | ||
| 727 | CFDataGetBytePtr (data), CFDataGetLength (data)); | 869 | CFDataGetBytePtr (data), CFDataGetLength (data)); |
| 728 | CFRelease (data); | 870 | CFRelease (data); |
| 729 | break; | 871 | break; |
| @@ -4661,7 +4803,7 @@ cfstring_create_normalized (str, symbol) | |||
| 4661 | } | 4803 | } |
| 4662 | 4804 | ||
| 4663 | if (in_text) | 4805 | if (in_text) |
| 4664 | err = CreateUnicodeToTextInfo(&map, &uni); | 4806 | err = CreateUnicodeToTextInfo (&map, &uni); |
| 4665 | while (err == noErr) | 4807 | while (err == noErr) |
| 4666 | { | 4808 | { |
| 4667 | out_buf = xmalloc (out_size); | 4809 | out_buf = xmalloc (out_size); |
| @@ -5234,6 +5376,16 @@ syms_of_mac () | |||
| 5234 | QHFS_plus_C = intern ("HFS+C"); staticpro (&QHFS_plus_C); | 5376 | QHFS_plus_C = intern ("HFS+C"); staticpro (&QHFS_plus_C); |
| 5235 | #endif | 5377 | #endif |
| 5236 | 5378 | ||
| 5379 | { | ||
| 5380 | int i; | ||
| 5381 | |||
| 5382 | for (i = 0; i < sizeof (ae_attr_table) / sizeof (ae_attr_table[0]); i++) | ||
| 5383 | { | ||
| 5384 | ae_attr_table[i].symbol = intern (ae_attr_table[i].name); | ||
| 5385 | staticpro (&ae_attr_table[i].symbol); | ||
| 5386 | } | ||
| 5387 | } | ||
| 5388 | |||
| 5237 | defsubr (&Smac_coerce_ae_data); | 5389 | defsubr (&Smac_coerce_ae_data); |
| 5238 | #if TARGET_API_MAC_CARBON | 5390 | #if TARGET_API_MAC_CARBON |
| 5239 | defsubr (&Smac_get_preference); | 5391 | defsubr (&Smac_get_preference); |