diff options
author | Ian C <ianc@noddybox.co.uk> | 2004-08-22 23:05:59 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2004-08-22 23:05:59 +0000 |
commit | bce0956117d53d2a242c4bc4fe354bb5e78e0e5f (patch) | |
tree | f7fe81da192025cd96e805a22eaf48d1f7bd8159 | |
parent | 6cee147b6b1f583a03844978c706a9a75749eef5 (diff) |
Improved number format error handling
-rw-r--r-- | int2tap.c | 26 | ||||
-rw-r--r-- | test/Makefile | 4 |
2 files changed, 26 insertions, 4 deletions
@@ -54,10 +54,28 @@ static void Usage(void) { fprintf(stderr,"%s: usage %s [-b] [-s] [-a addr] [-c addr] " "output-file input-file ... \n",progname,progname); + exit(EXIT_FAILURE); } +static unsigned ToUnsigned(const char *p) +{ + char *end; + unsigned u; + + u=(unsigned)strtoul(p,&end,0); + + if (end==p || *end!=0) + { + fprintf(stderr,"%s: invalid number %s\n",progname,p); + exit(EXIT_FAILURE); + } + + return u; +} + + /* ---------------------------------------- MAIN */ int main(int argc, char *argv[]) @@ -108,6 +126,10 @@ int main(int argc, char *argv[]) { switch(argv[f][1]) { + case 'h': + Usage(); + break; + case 'b': bin_only=TRUE; break; @@ -123,7 +145,7 @@ int main(int argc, char *argv[]) } addr_defined=TRUE; - exec_addr=(unsigned)strtoul(argv[++f],NULL,0); + exec_addr=ToUnsigned(argv[++f]); break; @@ -134,7 +156,7 @@ int main(int argc, char *argv[]) } clear_defined=TRUE; - clear_addr=(unsigned)strtoul(argv[++f],NULL,0); + clear_addr=ToUnsigned(argv[++f]); break; diff --git a/test/Makefile b/test/Makefile index c3ebafb..43a108b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -18,7 +18,7 @@ # # ------------------------------------------------------------------------- # -# $Id: Makefile,v 1.2 2004-08-22 22:51:39 ianc Exp $ +# $Id: Makefile,v 1.3 2004-08-22 23:05:59 ianc Exp $ # # One file with loader test @@ -65,7 +65,7 @@ test7: ../int2tap part1.bin part2.bin # CLEAR test # test8: ../int2tap reset.bin - ../int2tap -c 0x8000 test8.tap reset.bin + ../int2tap -c 0x7fff test8.tap reset.bin fuse test8.tap code.bin: code.asm |