mirror of
https://github.com/michaelcmartin/Ophis.git
synced 2024-11-05 02:04:43 +00:00
Merge catseye's incbin-range enhancement.
Needed a little work to merge cleanly, but no real surprises. This isn't a complete solution yet, but it will work for the basic case. It should allow expressions and gracefully handle non-hardcoded cases (while still efficiently handling hardcoded ones).
This commit is contained in:
commit
86e58efce8
@ -52,11 +52,20 @@ def pragmaRequire(ppt, line, result):
|
||||
def pragmaIncbin(ppt, line, result):
|
||||
"Includes a binary file"
|
||||
filename = line.expect("STRING").value
|
||||
offset = 0
|
||||
size = -1
|
||||
if str(line.lookahead(0)) == ",":
|
||||
line.pop()
|
||||
offset = line.expect("NUM").value
|
||||
if str(line.lookahead(0)) == ",":
|
||||
line.pop()
|
||||
size = line.expect("NUM").value
|
||||
line.expect("EOL")
|
||||
if type(filename) == str:
|
||||
try:
|
||||
f = file(os.path.join(FE.context_directory, filename), "rb")
|
||||
bytes = f.read()
|
||||
f.seek(offset)
|
||||
bytes = f.read(size)
|
||||
f.close()
|
||||
except IOError:
|
||||
Err.log("Could not read " + filename)
|
||||
|
Loading…
Reference in New Issue
Block a user