From 2ef848cf16b72491bc54b9d116b1d5b3f3cff807 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 07:38:40 -0500 Subject: [PATCH 1/7] Capture what CreateObjSpecifier makes --- .../Retro68/ObjectSpecifierCapture.c | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 ReferenceTests/Retro68/ObjectSpecifierCapture.c diff --git a/ReferenceTests/Retro68/ObjectSpecifierCapture.c b/ReferenceTests/Retro68/ObjectSpecifierCapture.c new file mode 100644 index 0000000..7dce393 --- /dev/null +++ b/ReferenceTests/Retro68/ObjectSpecifierCapture.c @@ -0,0 +1,122 @@ +/* + * Captures what CreateObjSpecifier makes: the descriptor's type and the bytes + * of its data handle, for the specifier BBEdit Lite 6.1 builds ("every text + * window") and a few others, and what disposing the inputs leaves behind. + * + * It sends nothing. It writes its results as text lines to + * "ObjectSpecifier.txt" in its own folder, and refuses to run if that is + * already there. Each dump is the descriptor's type, its handle's size and the + * handle's bytes. + */ +#include +#include +#include +#include +#include + +/* AEObjects.h, which Multiversal doesn't have. */ +pascal OSErr CreateObjSpecifier(DescType desiredClass, AEDesc *theContainer, DescType keyForm, + AEDesc *keyData, Boolean disposeInputs, AEDesc *objSpecifier); + +static short out; + +static void line(const char *text) +{ + long count = strlen(text); + FSWrite(out, &count, text); + count = 1; + FSWrite(out, &count, "\r"); + FlushVol(0, 0); +} + +static void result(const char *label, OSErr error) +{ + char text[200]; + sprintf(text, "%s -> %d", label, error); + line(text); +} + +static void dump(const char *label, const AEDesc *d) +{ + char text[200]; + DescType type = d->descriptorType; + Size size, i; + int used; + + if (d->dataHandle == NULL) { + sprintf(text, "%s: type %.4s handle nil", label, (const char *)&type); + line(text); + return; + } + size = GetHandleSize((Handle)d->dataHandle); + sprintf(text, "%s: type %.4s size %ld", label, (const char *)&type, (long)size); + line(text); + used = 0; + for (i = 0; i < size && i < 1024; ++i) { + used += sprintf(text + used, "%02x", (unsigned char)(*(Handle)d->dataHandle)[i]); + if (i % 4 == 3) text[used++] = ' '; + if (i % 32 == 31 || i == size - 1) { + text[used] = 0; + line(text); + used = 0; + } + } +} + +int main(void) +{ + static const unsigned char name[] = { 19, 'O','b','j','e','c','t','S','p','e','c','i','f','i','e','r','.','t','x','t' }; + AEDesc nothing, all, first, text, spec, nested, record; + DescType ordinal; + short ref; + long index = 1; + char title[] = "Notes"; + + if (FSOpen(name, 0, &ref) == noErr) { FSClose(ref); return 1; } + if (Create(name, 0, 'Grph', 'TEXT') != noErr) return 2; + if (FSOpen(name, 0, &out) != noErr) return 3; + + nothing.descriptorType = typeNull; + nothing.dataHandle = NULL; + ordinal = 'all '; + result("CreateDesc abso all", AECreateDesc('abso', &ordinal, 4, &all)); + ordinal = 'firs'; + result("CreateDesc abso firs", AECreateDesc('abso', &ordinal, 4, &first)); + result("CreateDesc TEXT", AECreateDesc(typeChar, title, 5, &text)); + dump("null container", ¬hing); + dump("the ordinal", &all); + + /* BBEdit's: every text window of the application. */ + result("CreateObjSpecifier TxtW indx all", CreateObjSpecifier('TxtW', ¬hing, 'indx', &all, false, &spec)); + dump("every text window", &spec); + dump("container afterwards", ¬hing); + dump("key data afterwards", &all); + + result("CreateObjSpecifier cwin name", CreateObjSpecifier('cwin', ¬hing, 'name', &text, false, &nested)); + dump("window by name", &nested); + result("CreateObjSpecifier cha firs in window", CreateObjSpecifier('cha ', &nested, 'indx', &first, false, &record)); + dump("first character of it", &record); + + result("CoerceDesc to reco", AECoerceDesc(&spec, typeAERecord, &record)); + dump("as a record", &record); + { + long count = -1; + result("CountItems on the specifier", AECountItems(&spec, &count)); + result("CountItems on the record", AECountItems(&record, &count)); + result("the record's count", (OSErr)count); + } + + /* Disposing the inputs: what is left in the caller's descriptors. */ + ordinal = 'all '; + AECreateDesc('abso', &ordinal, 4, &all); + AECreateDesc('long', &index, 4, &nested); + result("CreateObjSpecifier disposing", CreateObjSpecifier('cwin', &nested, 'indx', &all, true, &spec)); + dump("disposing: result", &spec); + dump("disposing: container left", &nested); + dump("disposing: key data left", &all); + + line("done"); + FSClose(out); + FlushVol(0, 0); + return 0; +} From c337c672481830a8b03fbe8006c3a1cc4757408e Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 07:38:40 -0500 Subject: [PATCH 2/7] Build the object specifier capture --- ReferenceTests/Retro68/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ReferenceTests/Retro68/CMakeLists.txt b/ReferenceTests/Retro68/CMakeLists.txt index 3f24960..5d49c68 100644 --- a/ReferenceTests/Retro68/CMakeLists.txt +++ b/ReferenceTests/Retro68/CMakeLists.txt @@ -28,3 +28,5 @@ add_application(UtilitiesCapture UtilitiesCapture.c) add_application(TrackingCapture TrackingCapture.c) add_application(AEDescLayoutCapture AEDescLayoutCapture.c) add_application(ControlRecordCapture ControlRecordCapture.c) +add_application(ObjectSpecifierCapture ObjectSpecifierCapture.c) +target_link_libraries(ObjectSpecifierCapture ObjectSupportLib) From 2189c56e1d707e36e32b3d61a4b773cbb4f17522 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 07:38:40 -0500 Subject: [PATCH 3/7] Add the Mac OS 9.2.2 object specifier capture --- ReferenceTests/Retro68/ObjectSpecifier-macos-9.2.2-ppc.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 ReferenceTests/Retro68/ObjectSpecifier-macos-9.2.2-ppc.txt diff --git a/ReferenceTests/Retro68/ObjectSpecifier-macos-9.2.2-ppc.txt b/ReferenceTests/Retro68/ObjectSpecifier-macos-9.2.2-ppc.txt new file mode 100644 index 0000000..7df6d15 --- /dev/null +++ b/ReferenceTests/Retro68/ObjectSpecifier-macos-9.2.2-ppc.txt @@ -0,0 +1 @@ +CreateDesc abso all -> 0 CreateDesc abso firs -> 0 CreateDesc TEXT -> 0 null container: type null handle nil the ordinal: type abso size 4 616c6c20 CreateObjSpecifier TxtW indx all -> 0 every text window: type obj size 68 00000004 00000000 77616e74 74797065 00000004 54787457 66726f6d 6e756c6c 00000000 666f726d 656e756d 00000004 696e6478 73656c64 6162736f 00000004 616c6c20 container afterwards: type null handle nil key data afterwards: type abso size 4 616c6c20 CreateObjSpecifier cwin name -> 0 window by name: type obj size 70 00000004 00000000 77616e74 74797065 00000004 6377696e 66726f6d 6e756c6c 00000000 666f726d 656e756d 00000004 6e616d65 73656c64 54455854 00000005 4e6f7465 7300 CreateObjSpecifier cha firs in window -> 0 first character of it: type obj size 138 00000004 00000000 77616e74 74797065 00000004 63686120 66726f6d 6f626a20 00000046 00000004 00000000 77616e74 74797065 00000004 6377696e 66726f6d 6e756c6c 00000000 666f726d 656e756d 00000004 6e616d65 73656c64 54455854 00000005 4e6f7465 7300666f 726d656e 756d0000 0004696e 64787365 6c646162 736f0000 00046669 7273 CoerceDesc to reco -> 0 as a record: type reco size 84 00000000 ab800010 00000018 6f626a20 00000004 00000000 77616e74 74797065 00000004 54787457 66726f6d 6e756c6c 00000000 666f726d 656e756d 00000004 696e6478 73656c64 6162736f 00000004 616c6c20 CountItems on the specifier -> -1704 CountItems on the record -> 0 the record's count -> 4 CreateObjSpecifier disposing -> 0 disposing: result: type obj size 72 00000004 00000000 77616e74 74797065 00000004 6377696e 66726f6d 6c6f6e67 00000004 00000001 666f726d 656e756d 00000004 696e6478 73656c64 6162736f 00000004 616c6c20 disposing: container left: type long size 4 00000001 disposing: key data left: type null handle nil done \ No newline at end of file From 332b1fd7f8d74442ace679844e6ad46372a4adda Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 07:38:40 -0500 Subject: [PATCH 4/7] Lay out object specifier data as Mac OS 9.2.2 does --- .../DescriptorClassicData.swift | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Sources/GraphiteAutomation/DescriptorClassicData.swift b/Sources/GraphiteAutomation/DescriptorClassicData.swift index 88d6c53..db8a3d5 100644 --- a/Sources/GraphiteAutomation/DescriptorClassicData.swift +++ b/Sources/GraphiteAutomation/DescriptorClassicData.swift @@ -2,19 +2,27 @@ // event (ReferenceTests/Retro68/AEDescLayout-macos-9.2.2-ppc.txt). Programs // that write that data themselves depend on it. The layout's own numbers are // big-endian, and a descriptor's bytes are copied as they are, so one made -// with host numbers goes through toBigEndian() first. +// with host numbers goes through toBigEndian() first. An object specifier's +// handle is a record's without the header: its count, a zero and its items +// (ObjectSpecifier-macos-9.2.2-ppc.txt). import GraphiteCore public extension Descriptor { - /// The data handle's bytes for a list, record or Apple event; + /// The data handle's bytes for a list, record, object specifier or Apple event; /// errAENotAEDesc for another descriptor, and errAEWrongDataType for an /// event inside one, whose layout isn't known. func classicData() throws(MacError) -> [UInt8] { if isAppleEvent { return try classicEventData() } guard isList || isKeyed else { throw .notDescriptor } var data = ClassicData() + if type == DescriptorType.objectSpecifier { + data.long(UInt32(items.count)) + data.long(0) + try data.append(items, keyed: true, depth: 0) + return data.bytes + } data.long(0) data.long(0) // Left over from earlier use on Mac OS. data.long(UInt32(ClassicData.listHeader)) @@ -25,7 +33,7 @@ public extension Descriptor { return data.bytes } - /// A list, record or Apple event from its data handle's bytes; + /// A list, record, object specifier or Apple event from its data handle's bytes; /// errAECorruptData for bytes that don't hold what they say they do. init(type: FourCharCode, classicData bytes: [UInt8]) throws(MacError) { var data = ClassicData(bytes: bytes) @@ -33,6 +41,12 @@ public extension Descriptor { self = try data.event() return } + if type == DescriptorType.objectSpecifier { + let count = try data.long() + _ = try data.long() + self.init(type: type, items: try data.items(count, keyed: true, depth: 0), isKeyed: true) + return + } let isList = type == DescriptorType.list data.position = 8 let start = try data.long() @@ -154,14 +168,15 @@ private struct ClassicData { mutating func descriptor(depth: Int) throws(MacError) -> Descriptor { let type = try code() let data = try value() - guard type == DescriptorType.list || type == DescriptorType.record else { + guard type == DescriptorType.list || type == DescriptorType.record + || type == DescriptorType.objectSpecifier else { return Descriptor(type: type, bytes: data) } guard depth < Self.maximumDepth else { throw MacError(-108) } var inner = ClassicData(bytes: data) let count = try inner.long() _ = try inner.long() - let keyed = type == DescriptorType.record + let keyed = type != DescriptorType.list return Descriptor(type: type, items: try inner.items(count, keyed: keyed, depth: depth + 1), isKeyed: keyed) } From 561e7b8f768ef64ba92d0be78275960f103fc230 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 07:38:40 -0500 Subject: [PATCH 5/7] Add object specifiers --- .../GraphiteAutomation/ObjectSpecifier.swift | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Sources/GraphiteAutomation/ObjectSpecifier.swift diff --git a/Sources/GraphiteAutomation/ObjectSpecifier.swift b/Sources/GraphiteAutomation/ObjectSpecifier.swift new file mode 100644 index 0000000..398ce01 --- /dev/null +++ b/Sources/GraphiteAutomation/ObjectSpecifier.swift @@ -0,0 +1,22 @@ +// What CreateObjSpecifier makes (ReferenceTests/Retro68/ +// ObjectSpecifier-macos-9.2.2-ppc.txt): a record of the desired class, the +// container, the key form and the key data, in that order, retyped 'obj '. + +import GraphiteCore + +public extension Descriptor { + + /// An object specifier, with its codes big-endian as Mac OS keeps them. + static func objectSpecifier(desiredClass: FourCharCode, container: Descriptor, + keyForm: FourCharCode, keyData: Descriptor) -> Descriptor { + func code(_ type: FourCharCode, _ value: FourCharCode) -> Descriptor { + Descriptor(type: type, bytes: withUnsafeBytes(of: value.rawValue.bigEndian) { Array($0) }) + } + return Descriptor(type: DescriptorType.objectSpecifier, items: [ + Item(keyword: "want", descriptor: code(DescriptorType.type, desiredClass)), + Item(keyword: "from", descriptor: container), + Item(keyword: "form", descriptor: code(DescriptorType.enumerated, keyForm)), + Item(keyword: "seld", descriptor: keyData), + ], isKeyed: true) + } +} From ae486547f5c0b2408fab15537790522954821584 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 07:38:40 -0500 Subject: [PATCH 6/7] Test object specifiers against Mac OS 9.2.2 --- .../ObjectSpecifierTests.swift | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Tests/GraphiteAutomationTests/ObjectSpecifierTests.swift diff --git a/Tests/GraphiteAutomationTests/ObjectSpecifierTests.swift b/Tests/GraphiteAutomationTests/ObjectSpecifierTests.swift new file mode 100644 index 0000000..8a6ed97 --- /dev/null +++ b/Tests/GraphiteAutomationTests/ObjectSpecifierTests.swift @@ -0,0 +1,61 @@ +import Testing +import Foundation +import GraphiteCore +import GraphiteAutomation + +/// Object specifiers' data handles, compared byte for byte with what Mac OS +/// 9.2.2 held (ReferenceTests/Retro68, ObjectSpecifierCapture.c). +@Suite struct ObjectSpecifierTests { + + private static let capture: [String] = { + let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent() + .deletingLastPathComponent().deletingLastPathComponent() + let data = try! Data(contentsOf: root.appendingPathComponent("ReferenceTests/Retro68/ObjectSpecifier-macos-9.2.2-ppc.txt")) + return String(decoding: data, as: UTF8.self).split(separator: "\r").map(String.init) + }() + + private func captured(_ label: String, sourceLocation: SourceLocation = #_sourceLocation) -> [UInt8] { + guard let start = Self.capture.firstIndex(where: { $0.hasPrefix(label + ": type obj ") }) else { + Issue.record("no capture for \(label)", sourceLocation: sourceLocation) + return [] + } + var hex = "" + for line in Self.capture[(start + 1)...] { + guard line.allSatisfy({ $0 == " " || $0.isHexDigit }) else { break } + hex += line.filter { $0 != " " } + } + return stride(from: 0, to: hex.count, by: 2).map { UInt8(hex.dropFirst($0).prefix(2), radix: 16)! } + } + + private func check(_ label: String, _ descriptor: Descriptor, sourceLocation: SourceLocation = #_sourceLocation) throws { + let expected = captured(label, sourceLocation: sourceLocation) + #expect(try descriptor.classicData() == expected, "\(label)", sourceLocation: sourceLocation) + let read = try Descriptor(type: DescriptorType.objectSpecifier, classicData: expected) + #expect(read == descriptor, "\(label) read back", sourceLocation: sourceLocation) + } + + private func ordinal(_ code: String) -> Descriptor { Descriptor(type: "abso", bytes: Array(code.utf8)) } + + @Test func specifiersAsMacOSKeepsThem() throws { + let every = Descriptor.objectSpecifier(desiredClass: "TxtW", container: .null, + keyForm: "indx", keyData: ordinal("all ")) + try check("every text window", every) + + let named = Descriptor.objectSpecifier(desiredClass: "cwin", container: .null, keyForm: "name", + keyData: Descriptor(type: "TEXT", bytes: Array("Notes".utf8))) + try check("window by name", named) + + try check("first character of it", .objectSpecifier(desiredClass: "cha ", container: named, + keyForm: "indx", keyData: ordinal("firs"))) + try check("disposing: result", .objectSpecifier(desiredClass: "cwin", + container: Descriptor(type: "long", bytes: [0, 0, 0, 1]), + keyForm: "indx", keyData: ordinal("all "))) + } + + @Test func truncatedDataIsRefused() { + let bytes = captured("every text window") + #expect(throws: MacError.self) { + _ = try Descriptor(type: DescriptorType.objectSpecifier, classicData: Array(bytes.dropLast(6))) + } + } +} From 82be10596f7a73d6f14bb8c718f1e188fa74c573 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 07:38:40 -0500 Subject: [PATCH 7/7] Describe the object specifier capture --- ReferenceTests/Retro68/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ReferenceTests/Retro68/README.md b/ReferenceTests/Retro68/README.md index 7b3ac98..f4f2698 100644 --- a/ReferenceTests/Retro68/README.md +++ b/ReferenceTests/Retro68/README.md @@ -850,6 +850,26 @@ An event (type `aevt`): leftover long and padding byte. The null-target event is not compared: its target type is not meaningful. +## Object specifiers + +`ObjectSpecifierCapture.c` builds object specifiers with `CreateObjSpecifier` +and dumps their data handles; BBEdit Lite 6.1 builds the first one, every text +window. The output is `ObjectSpecifier-macos-9.2.2-ppc.txt` (CR line endings). + +- A specifier is typed `'obj '`. Its data is the number of items, a zero and + the items `want`, `from`, `form` and `seld`, in that order, laid out as a + record's items: a record without its header. A specifier inside another is + the same bytes. +- `form` is typed `'enum'`, and a null container is a `'null'` item of no + length. +- Coercing a specifier to a record gives a record's header that still names + `'obj '`. `AECountItems` refuses the specifier itself with -1704. +- With `disposeInputs` false both inputs are left as they were. With it true, + the key data was disposed of; a container of type `'long'` was left. + +`Descriptor.objectSpecifier(desiredClass:container:keyForm:keyData:)` builds +one, and `ObjectSpecifierTests` compares its bytes with the capture. + ## Control records `ControlRecordCapture.c` makes two scroll bars in a window of its own, the