Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/AEDescLayout-macos-9.2.2-ppc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CreateList list -> 0list empty: type list size 2400000000 64825d33 00000018 6c697374 00000000 00000000 PutPtr long -> 0list long: type list size 3600000000 64825d33 00000018 6c697374 00000001 00000000 6c6f6e67 00000004 11223344 PutPtr TEXT 5 -> 0list long TEXT: type list size 5000000000 64825d33 00000018 6c697374 00000002 00000000 6c6f6e67 00000004 11223344 54455854 00000005 68656c6c 6f00PutPtr TEXT 0 -> 0list long TEXT empty: type list size 5800000000 64825d33 00000018 6c697374 00000003 00000000 6c6f6e67 00000004 11223344 54455854 00000005 68656c6c 6f005445 58540000 0000PutPtr null -> 0list long TEXT empty null: type list size 6600000000 64825d33 00000018 6c697374 00000004 00000000 6c6f6e67 00000004 11223344 54455854 00000005 68656c6c 6f005445 58540000 00006e75 6c6c0000 0000DeleteItem 2 -> 0list after deleting item 2: type list size 5200000000 00000032 00000018 6c697374 00000003 00000000 6c6f6e67 00000004 11223344 54455854 00000000 6e756c6c 00000000 CreateList record -> 0record empty: type reco size 2400000000 fcfcf700 00000018 7265636f 00000000 00000000 PutParamPtr k001 -> 0record k001: type reco size 4000000000 fcfcf700 00000018 7265636f 00000001 00000000 6b303031 6c6f6e67 00000004 00000001 PutParamPtr k002 -> 0record k001 k002: type reco size 5600000000 fcfcf700 00000018 7265636f 00000002 00000000 6b303031 6c6f6e67 00000004 00000001 6b303032 54455854 00000003 68656c6c PutParamPtr k001 again -> 0record k001 replaced: type reco size 5600000000 fcfcf700 00000018 7265636f 00000002 00000000 6b303031 6c6f6e67 00000004 00000002 6b303032 54455854 00000003 68656c6c PutParamDesc list in record -> 0record with a list: type reco size 10400000000 fcfcf700 00000018 7265636f 00000003 00000000 6b303031 6c6f6e67 00000004 00000002 6b303032 54455854 00000003 68656c6c 6c697374 6c697374 00000024 00000003 00000000 6c6f6e67 00000004 11223344 54455854 00000000 6e756c6c 00000000 CreateList inner record -> 0PutParamDesc record in record -> 0record with a list and a record: type reco size 14000000000 fcfcf700 00000018 7265636f 00000004 00000000 6b303031 6c6f6e67 00000004 00000002 6b303032 54455854 00000003 68656c6c 6c697374 6c697374 00000024 00000003 00000000 6c6f6e67 00000004 11223344 54455854 00000000 6e756c6c 00000000 7265636f 7265636f 00000018 00000001 00000000 6b303037 6c6f6e67 00000004 00000007 PutDesc record in list -> 0list with a record: type list size 8400000000 00000032 00000018 6c697374 00000004 00000000 6c6f6e67 00000004 11223344 54455854 00000000 6e756c6c 00000000 7265636f 00000018 00000001 00000000 6b303037 6c6f6e67 00000004 00000007 GetParamDesc list -> 0the list got back: type list size 5200000000 6c697374 00000018 6c697374 00000003 00000000 6c6f6e67 00000004 11223344 54455854 00000000 6e756c6c 00000000 DuplicateDesc record -> 0the duplicate: type reco size 14000000000 fcfcf700 00000018 7265636f 00000004 00000000 6b303031 6c6f6e67 00000004 00000002 6b303032 54455854 00000003 68656c6c 6c697374 6c697374 00000024 00000003 00000000 6c6f6e67 00000004 11223344 54455854 00000000 6e756c6c 00000000 7265636f 7265636f 00000018 00000001 00000000 6b303037 6c6f6e67 00000004 00000007 CreateDesc target -> 0target: type psn size 800000000 00000002 CreateAppleEvent -> 0event empty: type aevt size 10600000000 00000002 0000006a 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000636f 72656372 656c0000 12347073 6e200000 00080000 00000000 00026165 76740001 00017472 616e6c6f 6e670000 00045566 77883b3b 3b3bGetAttributeDesc optk on a new event -> -1701 left type null handle 00000000PutParamPtr key1 -> 0event key1: type aevt size 12200000000 00000002 0000006a 00000001 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000636f 72656372 656c0000 12347073 6e200000 00080000 00000000 00026165 76740001 00017472 616e6c6f 6e670000 00045566 77883b3b 3b3b6b65 79316c6f 6e670000 00040000 000bPutParamPtr key2 -> 0event key1 key2: type aevt size 14000000000 00000002 0000006a 00000001 00000002 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000636f 72656372 656c0000 12347073 6e200000 00080000 00000000 00026165 76740001 00017472 616e6c6f 6e670000 00045566 77883b3b 3b3b6b65 79316c6f 6e670000 00040000 000b6b65 79325445 58540000 00056865 6c6c6f00 CreateList keywords -> 0keyword list: type list size 4800000000 ab00001c 00000018 6c697374 00000002 00000000 6b657977 00000004 6b657931 6b657977 00000004 6b657932 PutAttributeDesc optk -> 0event with optk: type aevt size 18400000000 00000002 00000096 00000002 00000002 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000636f 72656372 656c0000 12347073 6e200000 00080000 00000000 00026165 76740001 00017472 616e6c6f 6e670000 00045566 77886f70 746b6c69 73740000 00200000 00020000 00006b65 79770000 00046b65 79316b65 79770000 00046b65 79323b3b 3b3b6b65 79316c6f 6e670000 00040000 000b6b65 79325445 58540000 00056865 6c6c6f00 GetAttributeDesc optk -> 0optk got back: type list size 4800000000 6f70746b 00000018 6c697374 00000002 00000000 6b657977 00000004 6b657931 6b657977 00000004 6b657932 PutAttributePtr zzzz -> 0event with another attribute: type aevt size 20000000000 00000002 000000a6 00000003 00000002 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000636f 72656372 656c0000 12347073 6e200000 00080000 00000000 00026165 76740001 00017472 616e6c6f 6e670000 00045566 77886f70 746b6c69 73740000 00200000 00020000 00006b65 79770000 00046b65 79316b65 79770000 00046b65 79327a7a 7a7a6c6f 6e670000 00040000 00633b3b 3b3b6b65 79316c6f 6e670000 00040000 000b6b65 79325445 58540000 00056865 6c6c6f00 DeleteParam key1 -> 0event without key1: type aevt size 18400000000 000000b6 000000a6 00000003 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000636f 72656372 656c0000 12347073 6e200000 00080000 00000000 00026165 76740001 00017472 616e6c6f 6e670000 00045566 77886f70 746b6c69 73740000 00200000 00020000 00006b65 79770000 00046b65 79316b65 79770000 00046b65 79327a7a 7a7a6c6f 6e670000 00040000 00633b3b 3b3b6b65 79325445 58540000 00056865 6c6c6f00 DuplicateDesc event -> 0event duplicate: type aevt size 18400000000 000000b6 000000a6 00000003 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000636f 72656372 656c0000 12347073 6e200000 00080000 00000000 00026165 76740001 00017472 616e6c6f 6e670000 00045566 77886f70 746b6c69 73740000 00200000 00020000 00006b65 79770000 00046b65 79316b65 79770000 00046b65 79327a7a 7a7a6c6f 6e670000 00040000 00633b3b 3b3b6b65 79325445 58540000 00056865 6c6c6f00 CreateAppleEvent nil target -> 0event without a target: type aevt size 8200000000 000000b6 00000052 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00004772 70687465 73740000 41a7ffc1 00000000 00006165 76740001 00013b3b 3b3bdone
Expand Down
187 changes: 187 additions & 0 deletions ReferenceTests/Retro68/AEDescLayoutCapture.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* Captures what the Apple Event Manager keeps in a descriptor's data handle:
* lists, records and events, empty and with items, parameters and attributes,
* nested, and after replacing and deleting. Programs that write that data
* themselves (BBEdit Lite 6.1 does) depend on its layout.
*
* It sends nothing. It writes its results as text lines to "AEDescLayout.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 <AppleEvents.h>
#include <Files.h>
#include <MacMemory.h>
#include <Processes.h>
#include <stdio.h>
#include <string.h>

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 pstr(Str255 to, const char *from)
{
int n = 0;
while (from[n] && n < 255) { to[n + 1] = (unsigned char)from[n]; ++n; }
to[0] = (unsigned char)n;
}

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)
{
Str255 name;
short vRef;
ProcessSerialNumber psn;
AEDesc target, event, record, list, inner, got, copy;
long v;
char hello[] = "hello";
DescType keys[2];

pstr(name, "AEDescLayout.txt");
if (FSOpen(name, 0, &vRef) == noErr) { FSClose(vRef); return 1; }
if (Create(name, 0, 'Grph', 'TEXT') != noErr) return 2;
if (FSOpen(name, 0, &out) != noErr) return 3;

/* A list: empty, then one item at a time. */
result("CreateList list", AECreateList(NULL, 0, false, &list));
dump("list empty", &list);
v = 0x11223344;
result("PutPtr long", AEPutPtr(&list, 0, 'long', &v, 4));
dump("list long", &list);
result("PutPtr TEXT 5", AEPutPtr(&list, 0, typeChar, hello, 5));
dump("list long TEXT", &list);
result("PutPtr TEXT 0", AEPutPtr(&list, 0, typeChar, hello, 0));
dump("list long TEXT empty", &list);
result("PutPtr null", AEPutPtr(&list, 0, typeNull, NULL, 0));
dump("list long TEXT empty null", &list);
result("DeleteItem 2", AEDeleteItem(&list, 2));
dump("list after deleting item 2", &list);

/* A record. */
result("CreateList record", AECreateList(NULL, 0, true, &record));
dump("record empty", &record);
v = 1;
result("PutParamPtr k001", AEPutParamPtr(&record, 'k001', 'long', &v, 4));
dump("record k001", &record);
result("PutParamPtr k002", AEPutParamPtr(&record, 'k002', typeChar, hello, 3));
dump("record k001 k002", &record);
v = 2;
result("PutParamPtr k001 again", AEPutParamPtr(&record, 'k001', 'long', &v, 4));
dump("record k001 replaced", &record);

/* Nested: a list and a record in a record, a record in a list. */
result("PutParamDesc list in record", AEPutParamDesc(&record, 'list', &list));
dump("record with a list", &record);
result("CreateList inner record", AECreateList(NULL, 0, true, &inner));
v = 7;
AEPutParamPtr(&inner, 'k007', 'long', &v, 4);
result("PutParamDesc record in record", AEPutParamDesc(&record, 'reco', &inner));
dump("record with a list and a record", &record);
result("PutDesc record in list", AEPutDesc(&list, 0, &inner));
dump("list with a record", &list);
result("GetParamDesc list", AEGetParamDesc(&record, 'list', typeWildCard, &got));
dump("the list got back", &got);
AEDisposeDesc(&got);
result("DuplicateDesc record", AEDuplicateDesc(&record, &copy));
dump("the duplicate", &copy);
AEDisposeDesc(&copy);
AEDisposeDesc(&inner);
AEDisposeDesc(&record);
AEDisposeDesc(&list);

/* An event for this process, with fixed IDs so two runs compare. */
psn.highLongOfPSN = 0;
psn.lowLongOfPSN = kCurrentProcess;
result("CreateDesc target", AECreateDesc(typeProcessSerialNumber, &psn, sizeof psn, &target));
dump("target", &target);
result("CreateAppleEvent", AECreateAppleEvent('core', 'crel', &target, 0x1234, 0x55667788, &event));
dump("event empty", &event);
got.descriptorType = '????';
got.dataHandle = (Handle)0x12345678;
result("GetAttributeDesc optk on a new event", AEGetAttributeDesc(&event, keyOptionalKeywordAttr, typeAEList, &got));
{
char text[100];
DescType type = got.descriptorType;
sprintf(text, " left type %.4s handle %08lx", (const char *)&type, (unsigned long)got.dataHandle);
line(text);
}
v = 11;
result("PutParamPtr key1", AEPutParamPtr(&event, 'key1', 'long', &v, 4));
dump("event key1", &event);
result("PutParamPtr key2", AEPutParamPtr(&event, 'key2', typeChar, hello, 5));
dump("event key1 key2", &event);

/* The optional keywords, as an attribute. */
result("CreateList keywords", AECreateList(NULL, 0, false, &list));
keys[0] = 'key1';
keys[1] = 'key2';
AEPutPtr(&list, 0, 'keyw', &keys[0], 4);
AEPutPtr(&list, 0, 'keyw', &keys[1], 4);
dump("keyword list", &list);
result("PutAttributeDesc optk", AEPutAttributeDesc(&event, keyOptionalKeywordAttr, &list));
dump("event with optk", &event);
AEDisposeDesc(&list);
result("GetAttributeDesc optk", AEGetAttributeDesc(&event, keyOptionalKeywordAttr, typeAEList, &got));
dump("optk got back", &got);
AEDisposeDesc(&got);
v = 99;
result("PutAttributePtr zzzz", AEPutAttributePtr(&event, 'zzzz', 'long', &v, 4));
dump("event with another attribute", &event);
result("DeleteParam key1", AEDeleteParam(&event, 'key1'));
dump("event without key1", &event);
result("DuplicateDesc event", AEDuplicateDesc(&event, &copy));
dump("event duplicate", &copy);
AEDisposeDesc(&copy);
AEDisposeDesc(&event);

/* An event with no target, and the automatic return ID. */
result("CreateAppleEvent nil target", AECreateAppleEvent('Grph', 'test', NULL, kAutoGenerateReturnID, kAnyTransactionID, &event));
dump("event without a target", &event);
AEDisposeDesc(&event);

AEDisposeDesc(&target);
line("done");
FSClose(out);
FlushVol(0, 0);
return 0;
}
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ add_application(TextCapture TextCapture.c TextCapture.r)
add_application(GWorldCapture GWorldCapture.c)
add_application(UtilitiesCapture UtilitiesCapture.c)
add_application(TrackingCapture TrackingCapture.c)
add_application(AEDescLayoutCapture AEDescLayoutCapture.c)
59 changes: 59 additions & 0 deletions ReferenceTests/Retro68/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -790,3 +790,62 @@ quick for Mac OS to follow give a useless capture.

Not captured: a drag at the limit's edges, a rear window released outside the
limit (Graphite selects it), a drag with the Command key, and submenus.

## Apple event data

`AEDescLayoutCapture.c` dumps what the Apple Event Manager keeps in a
descriptor's data handle: lists, records and events, empty and filled, nested,
and after replacing and deleting. Programs that write that data themselves
depend on it; BBEdit Lite 6.1 builds the event that opens its untitled window
this way. It sends nothing, and writes `AEDescLayout.txt`. The output on Mac OS
9.2.2 is `AEDescLayout-macos-9.2.2-ppc.txt` (CR line endings). All values are
big-endian, and an item's data is padded to an even length that its size
doesn't count; the padding byte is whatever followed the data copied.

A list or record (type `list` or `reco`):

| Offset | Size | Contents |
|---|---|---|
| 0 | 4 | 0 |
| 4 | 4 | varies between runs of the same calls; leftover |
| 8 | 4 | offset of the first item, 24 |
| 12 | 4 | the descriptor's type (`optk` for an attribute got back) |
| 16 | 4 | item count |
| 20 | 4 | 0 |
| 24 | | items |

A list's item is its type, size and data; a record's is its keyword, type, size
and data. A list or record inside another is its count, a zero long and its
items: the outer 16 bytes are left out.

An event (type `aevt`):

| Offset | Size | Contents |
|---|---|---|
| 0 | 4 | 0 |
| 4 | 4 | leftover |
| 8 | 4 | offset of the first parameter |
| 12 | 4 | count of the attributes in the attribute list below |
| 16 | 4 | parameter count |
| 20 | 30 | zero, through offset 49 |
| 50 | 4 | event class |
| 54 | 4 | event ID |
| 58 | 4 | return ID |
| 62 | | target address: type, size, data |
| | 4 | `aevt` |
| | 4 | the words 1 and 1 |
| | | attributes: keyword, type, size, data |
| | 4 | `;;;;` |
| | | parameters: keyword, type, size, data |

- The transaction ID is a listed attribute, and is left out when it is
`kAnyTransactionID`. With no target, the address has size 0 and a type that
is not meaningful.
- `AEGetAttributeDesc` for a keyword that isn't there gave -1701 and left the
result typeNull with a nil handle.
- A duplicate has the same bytes.

`DescriptorClassicDataTests` builds the same lists, records and events with
`Descriptor.classicData()` and compares them byte for byte, apart from the
leftover long and padding byte. The null-target event is not compared: its
target type is not meaningful.
Loading
Loading