diff options
Diffstat (limited to 'src/mac.c')
| -rw-r--r-- | src/mac.c | 221 |
1 files changed, 90 insertions, 131 deletions
| @@ -411,91 +411,73 @@ mac_coerce_file_name_ptr (type_code, data_ptr, data_size, | |||
| 411 | { | 411 | { |
| 412 | OSErr err; | 412 | OSErr err; |
| 413 | 413 | ||
| 414 | if (type_code == TYPE_FILE_NAME) | 414 | if (type_code == typeNull) |
| 415 | err = errAECoercionFail; | ||
| 416 | else if (type_code == to_type || to_type == typeWildCard) | ||
| 417 | err = AECreateDesc (TYPE_FILE_NAME, data_ptr, data_size, result); | ||
| 418 | else if (type_code == TYPE_FILE_NAME) | ||
| 415 | /* Coercion from undecoded file name. */ | 419 | /* Coercion from undecoded file name. */ |
| 416 | switch (to_type) | 420 | { |
| 417 | { | ||
| 418 | case typeAlias: | ||
| 419 | case typeFSS: | ||
| 420 | case typeFSRef: | ||
| 421 | #ifdef MAC_OSX | ||
| 422 | case typeFileURL: | ||
| 423 | #endif | ||
| 424 | { | ||
| 425 | #ifdef MAC_OSX | 421 | #ifdef MAC_OSX |
| 426 | CFStringRef str; | 422 | CFStringRef str; |
| 427 | CFURLRef url = NULL; | 423 | CFURLRef url = NULL; |
| 428 | CFDataRef data = NULL; | 424 | CFDataRef data = NULL; |
| 429 | 425 | ||
| 430 | str = CFStringCreateWithBytes (NULL, data_ptr, data_size, | 426 | str = CFStringCreateWithBytes (NULL, data_ptr, data_size, |
| 431 | kCFStringEncodingUTF8, false); | 427 | kCFStringEncodingUTF8, false); |
| 432 | if (str) | 428 | if (str) |
| 433 | { | 429 | { |
| 434 | url = CFURLCreateWithFileSystemPath (NULL, str, | 430 | url = CFURLCreateWithFileSystemPath (NULL, str, |
| 435 | kCFURLPOSIXPathStyle, false); | 431 | kCFURLPOSIXPathStyle, false); |
| 436 | CFRelease (str); | 432 | CFRelease (str); |
| 437 | } | 433 | } |
| 438 | if (url) | 434 | if (url) |
| 439 | { | 435 | { |
| 440 | data = CFURLCreateData (NULL, url, kCFStringEncodingUTF8, true); | 436 | data = CFURLCreateData (NULL, url, kCFStringEncodingUTF8, true); |
| 441 | CFRelease (url); | 437 | CFRelease (url); |
| 442 | } | 438 | } |
| 443 | if (data) | 439 | if (data) |
| 444 | { | 440 | { |
| 445 | err = AECoercePtr (typeFileURL, CFDataGetBytePtr (data), | 441 | err = AECoercePtr (typeFileURL, CFDataGetBytePtr (data), |
| 446 | CFDataGetLength (data), to_type, result); | 442 | CFDataGetLength (data), to_type, result); |
| 447 | CFRelease (data); | 443 | CFRelease (data); |
| 448 | } | 444 | } |
| 449 | else | 445 | else |
| 450 | err = memFullErr; | 446 | err = memFullErr; |
| 451 | #else | 447 | #else |
| 452 | FSSpec fs; | 448 | FSSpec fs; |
| 453 | char *buf; | 449 | char *buf; |
| 454 | 450 | ||
| 455 | buf = xmalloc (data_size + 1); | 451 | buf = xmalloc (data_size + 1); |
| 456 | if (buf) | 452 | if (buf) |
| 457 | { | 453 | { |
| 458 | memcpy (buf, data_ptr, data_size); | 454 | memcpy (buf, data_ptr, data_size); |
| 459 | buf[data_size] = '\0'; | 455 | buf[data_size] = '\0'; |
| 460 | err = posix_pathname_to_fsspec (buf, &fs); | 456 | err = posix_pathname_to_fsspec (buf, &fs); |
| 461 | xfree (buf); | 457 | xfree (buf); |
| 462 | } | ||
| 463 | else | ||
| 464 | err = memFullErr; | ||
| 465 | if (err == noErr) | ||
| 466 | err = AECoercePtr (typeFSS, &fs, sizeof (FSSpec), | ||
| 467 | to_type, result); | ||
| 468 | #endif | ||
| 469 | } | 458 | } |
| 470 | break; | 459 | else |
| 471 | 460 | err = memFullErr; | |
| 472 | case TYPE_FILE_NAME: | 461 | if (err == noErr) |
| 473 | case typeWildCard: | 462 | err = AECoercePtr (typeFSS, &fs, sizeof (FSSpec), to_type, result); |
| 474 | err = AECreateDesc (TYPE_FILE_NAME, data_ptr, data_size, result); | 463 | #endif |
| 475 | break; | 464 | } |
| 476 | |||
| 477 | default: | ||
| 478 | err = errAECoercionFail; | ||
| 479 | break; | ||
| 480 | } | ||
| 481 | else if (to_type == TYPE_FILE_NAME) | 465 | else if (to_type == TYPE_FILE_NAME) |
| 482 | /* Coercion to undecoded file name. */ | 466 | /* Coercion to undecoded file name. */ |
| 483 | switch (type_code) | 467 | { |
| 484 | { | ||
| 485 | case typeAlias: | ||
| 486 | case typeFSS: | ||
| 487 | case typeFSRef: | ||
| 488 | #ifdef MAC_OSX | 468 | #ifdef MAC_OSX |
| 489 | case typeFileURL: | 469 | CFURLRef url = NULL; |
| 490 | #endif | 470 | CFStringRef str = NULL; |
| 471 | CFDataRef data = NULL; | ||
| 472 | |||
| 473 | if (type_code == typeFileURL) | ||
| 474 | url = CFURLCreateWithBytes (NULL, data_ptr, data_size, | ||
| 475 | kCFStringEncodingUTF8, NULL); | ||
| 476 | else | ||
| 491 | { | 477 | { |
| 492 | AEDesc desc; | 478 | AEDesc desc; |
| 493 | #ifdef MAC_OSX | ||
| 494 | Size size; | 479 | Size size; |
| 495 | char *buf; | 480 | char *buf; |
| 496 | CFURLRef url = NULL; | ||
| 497 | CFStringRef str = NULL; | ||
| 498 | CFDataRef data = NULL; | ||
| 499 | 481 | ||
| 500 | err = AECoercePtr (type_code, data_ptr, data_size, | 482 | err = AECoercePtr (type_code, data_ptr, data_size, |
| 501 | typeFileURL, &desc); | 483 | typeFileURL, &desc); |
| @@ -513,33 +495,37 @@ mac_coerce_file_name_ptr (type_code, data_ptr, data_size, | |||
| 513 | } | 495 | } |
| 514 | AEDisposeDesc (&desc); | 496 | AEDisposeDesc (&desc); |
| 515 | } | 497 | } |
| 516 | if (url) | 498 | } |
| 517 | { | 499 | if (url) |
| 518 | str = CFURLCopyFileSystemPath (url, kCFURLPOSIXPathStyle); | 500 | { |
| 519 | CFRelease (url); | 501 | str = CFURLCopyFileSystemPath (url, kCFURLPOSIXPathStyle); |
| 520 | } | 502 | CFRelease (url); |
| 521 | if (str) | 503 | } |
| 522 | { | 504 | if (str) |
| 523 | data = | 505 | { |
| 524 | CFStringCreateExternalRepresentation (NULL, str, | 506 | data = CFStringCreateExternalRepresentation (NULL, str, |
| 525 | kCFStringEncodingUTF8, | 507 | kCFStringEncodingUTF8, |
| 526 | '\0'); | 508 | '\0'); |
| 527 | CFRelease (str); | 509 | CFRelease (str); |
| 528 | } | 510 | } |
| 529 | if (data) | 511 | if (data) |
| 530 | { | 512 | { |
| 531 | err = AECreateDesc (TYPE_FILE_NAME, CFDataGetBytePtr (data), | 513 | err = AECreateDesc (TYPE_FILE_NAME, CFDataGetBytePtr (data), |
| 532 | CFDataGetLength (data), result); | 514 | CFDataGetLength (data), result); |
| 533 | CFRelease (data); | 515 | CFRelease (data); |
| 534 | } | 516 | } |
| 535 | else | ||
| 536 | err = memFullErr; | ||
| 537 | #else | 517 | #else |
| 518 | char file_name[MAXPATHLEN]; | ||
| 519 | |||
| 520 | if (type_code == typeFSS && data_size == sizeof (FSSpec)) | ||
| 521 | err = fsspec_to_posix_pathname (data_ptr, file_name, | ||
| 522 | sizeof (file_name) - 1); | ||
| 523 | else | ||
| 524 | { | ||
| 525 | AEDesc desc; | ||
| 538 | FSSpec fs; | 526 | FSSpec fs; |
| 539 | char file_name[MAXPATHLEN]; | ||
| 540 | 527 | ||
| 541 | err = AECoercePtr (type_code, data_ptr, data_size, | 528 | err = AECoercePtr (type_code, data_ptr, data_size, typeFSS, &desc); |
| 542 | typeFSS, &desc); | ||
| 543 | if (err == noErr) | 529 | if (err == noErr) |
| 544 | { | 530 | { |
| 545 | #if TARGET_API_MAC_CARBON | 531 | #if TARGET_API_MAC_CARBON |
| @@ -550,19 +536,14 @@ mac_coerce_file_name_ptr (type_code, data_ptr, data_size, | |||
| 550 | if (err == noErr) | 536 | if (err == noErr) |
| 551 | err = fsspec_to_posix_pathname (&fs, file_name, | 537 | err = fsspec_to_posix_pathname (&fs, file_name, |
| 552 | sizeof (file_name) - 1); | 538 | sizeof (file_name) - 1); |
| 553 | if (err == noErr) | ||
| 554 | err = AECreateDesc (TYPE_FILE_NAME, file_name, | ||
| 555 | strlen (file_name), result); | ||
| 556 | AEDisposeDesc (&desc); | 539 | AEDisposeDesc (&desc); |
| 557 | } | 540 | } |
| 558 | #endif | ||
| 559 | } | 541 | } |
| 560 | break; | 542 | if (err == noErr) |
| 561 | 543 | err = AECreateDesc (TYPE_FILE_NAME, file_name, | |
| 562 | default: | 544 | strlen (file_name), result); |
| 563 | err = errAECoercionFail; | 545 | #endif |
| 564 | break; | 546 | } |
| 565 | } | ||
| 566 | else | 547 | else |
| 567 | abort (); | 548 | abort (); |
| 568 | 549 | ||
| @@ -581,31 +562,9 @@ mac_coerce_file_name_desc (from_desc, to_type, handler_refcon, result) | |||
| 581 | OSErr err = noErr; | 562 | OSErr err = noErr; |
| 582 | DescType from_type = from_desc->descriptorType; | 563 | DescType from_type = from_desc->descriptorType; |
| 583 | 564 | ||
| 584 | if (from_type == TYPE_FILE_NAME) | 565 | if (from_type == typeNull) |
| 585 | { | 566 | err = errAECoercionFail; |
| 586 | if (to_type != TYPE_FILE_NAME && to_type != typeWildCard | 567 | else if (from_type == to_type || to_type == typeWildCard) |
| 587 | && to_type != typeAlias && to_type != typeFSS | ||
| 588 | && to_type != typeFSRef | ||
| 589 | #ifdef MAC_OSX | ||
| 590 | && to_type != typeFileURL | ||
| 591 | #endif | ||
| 592 | ) | ||
| 593 | return errAECoercionFail; | ||
| 594 | } | ||
| 595 | else if (to_type == TYPE_FILE_NAME) | ||
| 596 | { | ||
| 597 | if (from_type != typeAlias && from_type != typeFSS | ||
| 598 | && from_type != typeFSRef | ||
| 599 | #ifdef MAC_OSX | ||
| 600 | && from_type != typeFileURL | ||
| 601 | #endif | ||
| 602 | ) | ||
| 603 | return errAECoercionFail; | ||
| 604 | } | ||
| 605 | else | ||
| 606 | abort (); | ||
| 607 | |||
| 608 | if (from_type == to_type || to_type == typeWildCard) | ||
| 609 | err = AEDuplicateDesc (from_desc, result); | 568 | err = AEDuplicateDesc (from_desc, result); |
| 610 | else | 569 | else |
| 611 | { | 570 | { |