From bce0956117d53d2a242c4bc4fe354bb5e78e0e5f Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 22 Aug 2004 23:05:59 +0000 Subject: Improved number format error handling --- int2tap.c | 26 ++++++++++++++++++++++++-- test/Makefile | 4 ++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/int2tap.c b/int2tap.c index ccfce7f..d38b63a 100644 --- a/int2tap.c +++ b/int2tap.c @@ -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 -- cgit v1.2.3