completed aete decoded now that I have the docs

This commit is contained in:
Guido van Rossum 1995-02-14 09:47:42 +00:00
parent 4c14a69ff9
commit 872eeebf6d
1 changed files with 137 additions and 64 deletions

View File

@ -25,14 +25,16 @@ def redirect(filename, func, *args):
if f: f.close() if f: f.close()
def realmain(): def realmain():
#list('C:System Folder:Extensions:AppleScript\252')
#list('C:Tao AppleScript:Finder Liaison:Finder Liaison 1.0') #list('C:Tao AppleScript:Finder Liaison:Finder Liaison 1.0')
#list('C:Tao AppleScript:Scriptable Text Editor')
#list('C:Internet:Eudora 1.4.2:Eudora1.4.2') #list('C:Internet:Eudora 1.4.2:Eudora1.4.2')
list('E:Excel 4.0:Microsoft Excel') #list('E:Excel 4.0:Microsoft Excel')
#list('C:Internet:Netscape 1.0N:Netscape 1.0N') #list('C:Internet:Netscape 1.0N:Netscape 1.0N')
#find('C:') #find('C:')
#find('D:') find('D:')
#find('E:') find('E:')
#find('F:') find('F:')
def find(dir, maxlevel = 5): def find(dir, maxlevel = 5):
hits = [] hits = []
@ -52,7 +54,7 @@ def find(dir, maxlevel = 5):
hits = hits + find(fullname, maxlevel-1) hits = hits + find(fullname, maxlevel-1)
else: else:
ctor, type = MacOS.GetCreatorAndType(fullname) ctor, type = MacOS.GetCreatorAndType(fullname)
if type == 'APPL': if type in ('APPL', 'FNDR', 'zsys', 'INIT', 'scri', 'cdev'):
sys.stderr.write(" %s\n" % `fullname`) sys.stderr.write(" %s\n" % `fullname`)
try: try:
rf = OpenRFPerm(fullname, 0, '\1') rf = OpenRFPerm(fullname, 0, '\1')
@ -82,13 +84,14 @@ def list(fullname):
for i in range(Count1Resources('aeut')): for i in range(Count1Resources('aeut')):
res = Get1IndResource('aeut', 1+i) res = Get1IndResource('aeut', 1+i)
resources.append(res) resources.append(res)
print "\nLISTING aete+aeut RESOURCE IN", `fullname` print "\nLISTING aete+aeut RESOURCES IN", `fullname`
for res in resources: for res in resources:
print res.GetResInfo() print "decoding", res.GetResInfo(), "..."
data = res.data data = res.data
try: try:
aete = decode(data) aete = decode(data)
showaete(aete) showaete(aete)
print "Checking putaete..."
f = StringIO.StringIO() f = StringIO.StringIO()
putaete(f, aete) putaete(f, aete)
newdata = f.getvalue() newdata = f.getvalue()
@ -139,6 +142,12 @@ def simplify(item):
# It is presented bottom-up instead of top-down because there are direct # It is presented bottom-up instead of top-down because there are direct
# references to the lower-level part-decoders from the high-level part-decoders. # references to the lower-level part-decoders from the high-level part-decoders.
def getbyte(f, *args):
c = f.read(1)
if not c:
raise EOFError, 'in getbyte' + str(args)
return ord(c)
def getword(f, *args): def getword(f, *args):
getalign(f) getalign(f)
s = f.read(2) s = f.read(2)
@ -181,8 +190,8 @@ def getlist(f, description, getitem):
count = getword(f) count = getword(f)
list = [] list = []
for i in range(count): for i in range(count):
getalign(f)
list.append(generic(getitem, f)) list.append(generic(getitem, f))
getalign(f)
return list return list
def alt_generic(what, f, *args): def alt_generic(what, f, *args):
@ -202,49 +211,100 @@ def generic(what, f, *args):
return record return record
return "BAD GENERIC ARGS: %s" % `what` return "BAD GENERIC ARGS: %s" % `what`
getdata = [(getostype, "type"), (getpstr, "description"), (getword, "flags")] getdata = [
getoptarg = [(getpstr, "name"), (getostype, "keyword"), (getdata, "what")] (getostype, "type"),
getcommand = [(getpstr, "name"), (getpstr, "description"), (getpstr, "description"),
(getostype, "suite code"), (getostype, "command code"), (getword, "flags")
]
getargument = [
(getpstr, "name"),
(getostype, "keyword"),
(getdata, "what")
]
getevent = [
(getpstr, "name"),
(getpstr, "description"),
(getostype, "suite code"),
(getostype, "event code"),
(getdata, "returns"), (getdata, "returns"),
(getdata, "accepts"), (getdata, "accepts"),
(getlist, "optional arguments", getoptarg)] (getlist, "optional arguments", getargument)
getprop = [(getpstr, "name"), (getostype, "code"), (getdata, "what")] ]
getelem = [(getostype, "type"), (getlist, "accessibility", getostype)] getproperty = [
getclass = [(getpstr, "name"), (getostype, "class code"), (getpstr, "description"), (getpstr, "name"),
(getlist, "properties", getprop), (getlist, "elements", getelem)] (getostype, "code"),
getenumitem = [(getpstr, "name"), (getostype, "value"), (getpstr, "description")] (getdata, "what")
getenum = [(getostype, "enumtype"), (getlist, "enumitem", getenumitem)] ]
getsuite = [(getpstr, "name"), (getpstr, "description"), (getostype, "code"), getelement = [
(getword, "flags1"), (getword, "flags2"), (getostype, "type"),
(getlist, "commands", getcommand), (getlist, "keyform", getostype)
]
getclass = [
(getpstr, "name"),
(getostype, "class code"),
(getpstr, "description"),
(getlist, "properties", getproperty),
(getlist, "elements", getelement)
]
getcomparison = [
(getpstr, "operator name"),
(getostype, "operator ID"),
(getpstr, "operator comment"),
]
getenumerator = [
(getpstr, "enumerator name"),
(getostype, "enumerator ID"),
(getpstr, "enumerator comment")
]
getenumeration = [
(getostype, "enumeration ID"),
(getlist, "enumerator", getenumerator)
]
getsuite = [
(getpstr, "suite name"),
(getpstr, "suite description"),
(getostype, "suite ID"),
(getword, "suite level"),
(getword, "suite version"),
(getlist, "events", getevent),
(getlist, "classes", getclass), (getlist, "classes", getclass),
(getword, "count???"), (getlist, "enums", getenum)] (getlist, "comparisons", getcomparison),
getaete = [(getword, "skip1"), (getword, "skip2"), (getword, "skip3"), (getlist, "enumerations", getenumeration)
(getlist, "suites", getsuite)] ]
getaete = [
(getword, "major/minor version in BCD"),
(getword, "language code"),
(getword, "script code"),
(getlist, "suites", getsuite)
]
# Display 'aete' resources in a friendly manner. # Display 'aete' resources in a friendly manner.
# This one's done top-down again... # This one's done top-down again...
def showaete(aete): def showaete(aete):
[flags1, flags2, flags3, suites] = aete [version, language, script, suites] = aete
print "\nGlobal flags: x%x, x%x, x%x\n" % (flags1, flags2, flags3) major, minor = divmod(version, 256)
print "\nVersion %d/%d, language %d, script %d" % \
(major, minor, language, script)
for suite in suites: for suite in suites:
showsuite(suite) showsuite(suite)
def showsuite(suite): def showsuite(suite):
[name, desc, code, flags1, flags2, commands, classes, skip1, enums] = suite [name, desc, code, level, version, events, classes, comps, enums] = suite
print "\nSuite %s -- %s (%s)" % (`name`, `desc`, `code`) print "\nSuite %s -- %s (%s)" % (`name`, `desc`, `code`)
for command in commands: print "Level %d, version %d" % (level, version)
showcommand(command) for event in events:
for classe in classes: showevent(event)
showclass(classe) for cls in classes:
showclass(cls)
for comp in comps:
showcomparison(comp)
for enum in enums: for enum in enums:
showenum(enum) showenumeration(enum)
def showcommand(command): def showevent(event):
[name, desc, code, subcode, returns, accepts, arguments] = command [name, desc, code, subcode, returns, accepts, arguments] = event
print "\n Command %s -- %s (%s, %s)" % (`name`, `desc`, `code`, `subcode`) print "\n Command %s -- %s (%s, %s)" % (`name`, `desc`, `code`, `subcode`)
print " returns", showdata(returns) print " returns", showdata(returns)
print " accepts", showdata(accepts) print " accepts", showdata(accepts)
@ -255,8 +315,8 @@ def showargument(arg):
[name, keyword, what] = arg [name, keyword, what] = arg
print " %s (%s)" % (name, `keyword`), showdata(what) print " %s (%s)" % (name, `keyword`), showdata(what)
def showclass(classe): def showclass(cls):
[name, code, desc, properties, elements] = classe [name, code, desc, properties, elements] = cls
print "\n Class %s (%s) -- %s" % (`name`, `code`, `desc`) print "\n Class %s (%s) -- %s" % (`name`, `code`, `desc`)
for prop in properties: for prop in properties:
showproperty(prop) showproperty(prop)
@ -265,19 +325,23 @@ def showclass(classe):
def showproperty(prop): def showproperty(prop):
[name, code, what] = prop [name, code, what] = prop
print " property %s (%s)" % (name, code), showdata(what) print " property %s (%s)" % (`name`, `code`), showdata(what)
def showelement(elem): def showelement(elem):
[code, accessibility] = elem [code, keyform] = elem
print " element %s" % `code`, "as", accessibility print " element %s" % `code`, "as", keyform
def showenum(enum): def showcomparison(comp):
[name, code, comment] = comp
print " comparison %s (%s) -- %s" % (`name`, `code`, comment)
def showenumeration(enum):
[code, items] = enum [code, items] = enum
print "\n Enum %s" % `code` print "\n Enum %s" % `code`
for item in items: for item in items:
showitem(item) showenumerator(item)
def showitem(item): def showenumerator(item):
[name, code, desc] = item [name, code, desc] = item
print " %s (%s) -- %s" % (`name`, `code`, `desc`) print " %s (%s) -- %s" % (`name`, `code`, `desc`)
@ -285,7 +349,7 @@ def showdata(data):
[type, description, flags] = data [type, description, flags] = data
return "%s -- %s %s" % (`type`, `description`, showdataflags(flags)) return "%s -- %s %s" % (`type`, `description`, showdataflags(flags))
dataflagdict = {15: "optional", 14: "list", 13: "enum", 12: "writable"} dataflagdict = {15: "optional", 14: "list", 13: "enum", 12: "mutable"}
def showdataflags(flags): def showdataflags(flags):
bits = [] bits = []
for i in range(16): for i in range(16):
@ -301,30 +365,30 @@ def showdataflags(flags):
# Closedly modelled after showaete()... # Closedly modelled after showaete()...
def putaete(f, aete): def putaete(f, aete):
[flags1, flags2, flags3, suites] = aete [version, language, script, suites] = aete
putword(f, flags1) putword(f, version)
putword(f, flags2) putword(f, language)
putword(f, flags3) putword(f, script)
putlist(f, suites, putsuite) putlist(f, suites, putsuite)
def putsuite(f, suite): def putsuite(f, suite):
[name, desc, code, flags1, flags2, commands, classes, skip1, enums] = suite [name, desc, code, level, version, events, classes, comps, enums] = suite
putpstr(f, name) putpstr(f, name)
putpstr(f, desc) putpstr(f, desc)
putostype(f, code) putostype(f, code)
putword(f, flags1) putword(f, level)
putword(f, flags2) putword(f, version)
putlist(f, commands, putcommand) putlist(f, events, putevent)
putlist(f, classes, putclass) putlist(f, classes, putclass)
putword(f, skip1) putlist(f, comps, putcomparison)
putlist(f, enums, putenum) putlist(f, enums, putenumeration)
def putcommand(f, command): def putevent(f, event):
[name, desc, code, subcode, returns, accepts, arguments] = command [name, desc, eventclass, eventid, returns, accepts, arguments] = event
putpstr(f, name) putpstr(f, name)
putpstr(f, desc) putpstr(f, desc)
putostype(f, code) putostype(f, eventclass)
putostype(f, subcode) putostype(f, eventid)
putdata(f, returns) putdata(f, returns)
putdata(f, accepts) putdata(f, accepts)
putlist(f, arguments, putargument) putlist(f, arguments, putargument)
@ -335,8 +399,8 @@ def putargument(f, arg):
putostype(f, keyword) putostype(f, keyword)
putdata(f, what) putdata(f, what)
def putclass(f, classe): def putclass(f, cls):
[name, code, desc, properties, elements] = classe [name, code, desc, properties, elements] = cls
putpstr(f, name) putpstr(f, name)
putostype(f, code) putostype(f, code)
putpstr(f, desc) putpstr(f, desc)
@ -350,12 +414,18 @@ def putelement(f, elem):
putostype(f, code) putostype(f, code)
putlist(f, parts, putostype) putlist(f, parts, putostype)
def putenum(f, enum): def putcomparison(f, comp):
[name, id, comment] = comp
putpstr(f, name)
putostype(f, id)
putpstr(f, comment)
def putenumeration(f, enum):
[code, items] = enum [code, items] = enum
putostype(f, code) putostype(f, code)
putlist(f, items, putitem) putlist(f, items, putenumerator)
def putitem(f, item): def putenumerator(f, item):
[name, code, desc] = item [name, code, desc] = item
putpstr(f, name) putpstr(f, name)
putostype(f, code) putostype(f, code)
@ -370,13 +440,16 @@ def putdata(f, data):
def putlist(f, list, putitem): def putlist(f, list, putitem):
putword(f, len(list)) putword(f, len(list))
for item in list: for item in list:
putalign(f)
putitem(f, item) putitem(f, item)
putalign(f)
def putalign(f): def putalign(f):
if f.tell() & 1: if f.tell() & 1:
f.write('\0') f.write('\0')
def putbyte(f, value):
f.write(chr(value))
def putword(f, value): def putword(f, value):
putalign(f) putalign(f)
f.write(chr((value>>8)&0xff)) f.write(chr((value>>8)&0xff))