Catch IOError in .incbin and .charmapbin pragmas.

This commit is contained in:
Cat's Eye Technologies 2011-12-09 14:24:12 -06:00
parent 5392f4c2d4
commit a1cc6db760
1 changed files with 14 additions and 6 deletions

View File

@ -43,9 +43,13 @@ def pragmaIncbin(ppt, line, result):
filename = line.expect("STRING").value
line.expect("EOL")
if type(filename)==str:
f = file(filename, "rb")
bytes = f.read()
f.close()
try:
f = file(filename, "rb")
bytes = f.read()
f.close()
except IOError:
Err.log ("Could not read "+filename)
return
bytes = [IR.ConstantExpr(ord(x)) for x in bytes]
result.append(IR.Node(ppt, "Byte", *bytes))
@ -72,9 +76,13 @@ def pragmaCharmapbin(ppt, line, result):
filename = line.expect("STRING").value
line.expect("EOL")
if type(filename)==str:
f = file(filename, "rb")
bytes = f.read()
f.close()
try:
f = file(filename, "rb")
bytes = f.read()
f.close()
except IOError:
Err.log ("Could not read "+filename)
return
if len(bytes)==256:
currentcharmap = bytes
else: