michaelcmartin / Ophis

A cross-assembler for the 6502 series of microprocessors.
http://michaelcmartin.github.io/Ophis/
Other
96 stars 26 forks source link

Fix misleading error message from .incbin and .charmapbin pragmas #1

Closed catseye closed 12 years ago

catseye commented 12 years ago

Hello,

I've used p65 extensively in the past, to write a C64 game for the Mini Game Competition 2009, and am currently using Ophis to (off-and-on) write another, larger game. While working on it, I noticed that if the file named in a .charmapbin pragma does not exist, Ophis gives a misleading error message, saying the current file (the one containing the .charmapbin pragma) cannot be found. Playing with it some more, I noticed the same was true for the .incbin pragma, and figured out why: the IOError exception is not caught in the pragma code, so it falls through to the try/except that surrounds loading the current source file.

This change adds try/except blocks to those pragmas. I've tested it, and it improves error reporting, by reporting the files that are actually not found.

Some minor unrelated enhancements are also included in this pull request; namely, adding a .gitignore to ignore the generated .pyc files, and a simple Bourne shell driver script (so that I could add the bin directory inside my Ophis clone to my $PATH, to more easily invoke Ophis from the command line.)

Thanks for writing Ophis! -Chris

michaelcmartin commented 12 years ago

This looks pretty good, but the driver shell script uses absolute paths. I haven't found a good, quick solution to this yet, so I'm merging it for now but may fiddle with it later

catseye commented 12 years ago

Whoops. Normally I'm pretty good about reviewing my own submissions and not submitting something like that! I was probably fixated a bit on the bug fix.

I agree; if there's a nice solution to this, I'm not aware of it. The best one I have is to use realpath, like:

SCRIPT=`realpath $0`
SCRIPTDIR=`dirname ${SCRIPT}`
python ${SCRIPTDIR}/../src/ophismain.py $*

Unfortunately realpath isn't standard equipment on all Unix-like systems, but it's usually available in the package system.