Rip out hideous in-band compression comments

These were a big mistake. Future System 7 compression annotations will
be done using #pragmas.
This commit is contained in:
Elliot Nunn 2019-09-01 16:04:27 +08:00
parent 123cd3294e
commit d121980787
2 changed files with 7 additions and 16 deletions

View File

@ -16,7 +16,6 @@ parser = argparse.ArgumentParser(description='''
parser.add_argument('resourceFile', help='file to be decompiled') parser.add_argument('resourceFile', help='file to be decompiled')
parser.add_argument('-ascii', action='store_true', help='[!] guarantee ASCII output') parser.add_argument('-ascii', action='store_true', help='[!] guarantee ASCII output')
parser.add_argument('-fakehdr', action='store_true', help='[!] save 225b file header as fake resource') parser.add_argument('-fakehdr', action='store_true', help='[!] save 225b file header as fake resource')
parser.add_argument('-compcmt', action='store_true', help='[!] helpfully comment compressed resources')
parser.add_argument('-useDF', action='store_true', help='ignored: data fork is always used') parser.add_argument('-useDF', action='store_true', help='ignored: data fork is always used')
args = parser.parse_args() args = parser.parse_args()
@ -25,7 +24,7 @@ with open(args.resourceFile, 'rb') as f:
resources = macresources.parse_file(f.read(), fake_header_rsrc=args.fakehdr) resources = macresources.parse_file(f.read(), fake_header_rsrc=args.fakehdr)
try: try:
rez = macresources.make_rez_code(resources, ascii_clean=args.ascii, cmt_unsupported_attrib=args.compcmt) rez = macresources.make_rez_code(resources, ascii_clean=args.ascii)
sys.stdout.buffer.write(rez) sys.stdout.buffer.write(rez)
except BrokenPipeError: except BrokenPipeError:
pass # like we get when we pipe into head pass # like we get when we pipe into head

View File

@ -91,13 +91,10 @@ class ResourceAttrs(enum.IntFlag):
_changed = 0x02 # marks a resource that has been changes since loading from file (should not be seen on disk) _changed = 0x02 # marks a resource that has been changes since loading from file (should not be seen on disk)
_compressed = 0x01 # "indicates that the resource data is compressed" (only documented in https://github.com/kreativekorp/ksfl/wiki/Macintosh-Resource-File-Format) _compressed = 0x01 # "indicates that the resource data is compressed" (only documented in https://github.com/kreativekorp/ksfl/wiki/Macintosh-Resource-File-Format)
def _for_derez(self, cmt_unsupported=True): def _for_derez(self):
mylist = [p.name for p in self.__class__ if self & p] for possible in self.__class__:
if any(p.startswith('_') for p in mylist): if not possible.name.startswith('_') and self & possible:
arg = '$%02X' % self yield possible.name
if cmt_unsupported: arg += ' /*%s*/' % ', '.join(mylist)
mylist = [arg]
return mylist
class Resource: class Resource:
@ -188,11 +185,6 @@ def parse_rez_code(from_rezcode):
for line in from_rezcode.split(b'\n'): for line in from_rezcode.split(b'\n'):
line = line.lstrip() line = line.lstrip()
while b'/*' in line:
a, b, c = line.partition(b'/*')
d, e, f = c.partition(b'*/')
line = a + f
if line.startswith(b'data '): if line.startswith(b'data '):
try: try:
yield cur_resource yield cur_resource
@ -337,7 +329,7 @@ def make_file(from_iter, align=1):
return bytes(accum) return bytes(accum)
def make_rez_code(from_iter, ascii_clean=False, cmt_unsupported_attrib=False): def make_rez_code(from_iter, ascii_clean=False):
"""Express an iterator of Resource objects as Rez code (bytes). """Express an iterator of Resource objects as Rez code (bytes).
This will match the output of the deprecated Rez utility, unless the This will match the output of the deprecated Rez utility, unless the
@ -355,7 +347,7 @@ def make_rez_code(from_iter, ascii_clean=False, cmt_unsupported_attrib=False):
args.append(str(resource.id).encode('ascii')) args.append(str(resource.id).encode('ascii'))
if resource.name is not None: if resource.name is not None:
args.append(_rez_escape(resource.name.encode('mac_roman'), singlequote=False, ascii_clean=ascii_clean)) args.append(_rez_escape(resource.name.encode('mac_roman'), singlequote=False, ascii_clean=ascii_clean))
args.extend(x.encode('ascii') for x in resource.attribs._for_derez(cmt_unsupported=cmt_unsupported_attrib)) args.extend(x.encode('ascii') for x in resource.attribs._for_derez())
args = b', '.join(args) args = b', '.join(args)
fourcc = _rez_escape(resource.type, singlequote=True, ascii_clean=ascii_clean) fourcc = _rez_escape(resource.type, singlequote=True, ascii_clean=ascii_clean)