From: j8takagi Date: Tue, 2 Mar 2010 01:11:11 +0000 (+0900) Subject: casl2、comet2コマンドのエラーや使い方表示を変更 X-Git-Tag: v0.1~4 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22dc7e0f6bc6f0a7ebe6c0b998db13d7e6c7cbbc;p=YACASL2.git casl2、comet2コマンドのエラーや使い方表示を変更 --- diff --git a/src/casl2.c b/src/casl2.c index 5ae4825..944ed40 100644 --- a/src/casl2.c +++ b/src/casl2.c @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) WORD beginptr[argc]; char *objfile = NULL; const char *usage = - "Usage: %s [-slLaAtTdh] [-oO] [-M ] [-C ] FILE ...\n"; + "Usage: %s [-slLaAtTdh] [-oO] [-M ] [-C ] FILE ...\n"; while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) { switch(opt) { diff --git a/src/comet2.c b/src/comet2.c index be09f10..bb07c5f 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -18,6 +18,7 @@ static struct option longopts[] = { /* comet2のエラー定義 */ CERRARRAY cerr_comet2[] = { { 201, "Load object file - full of COMET II memory" }, + { 208, "object file is not specified" }, }; bool addcerrlist_comet2() { @@ -27,6 +28,7 @@ bool addcerrlist_comet2() /* 指定されたファイルからアセンブル結果を読込 */ bool loadassemble(char *file) { FILE *fp; + bool status = true; if((fp = fopen(file, "r")) == NULL) { perror(file); @@ -35,17 +37,17 @@ bool loadassemble(char *file) { if((endptr = startptr + fread(memory, sizeof(WORD), memsize-startptr, fp)) == memsize) { setcerr(201, NULL); /* Load object file - full of COMET II memory */ fprintf(stderr, "Execute error - %d: %s\n", cerrno, cerrmsg); - return false; + status = false; } fclose(fp); - return true; + return status; } /* comet2コマンド */ int main(int argc, char *argv[]) { int opt; - const char *usage = "Usage: %s [-tTdh] [-M ] [-C ] FILE\n"; + const char *usage = "Usage: %s [-tTdh] [-M ] [-C ] FILE\n"; addcerrlist_comet2(); while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) { @@ -74,14 +76,21 @@ int main(int argc, char *argv[]) exit(-1); } } + if(argv[optind] == NULL) { + setcerr(208, NULL); /* object file is not specified */ + fprintf(stderr, "comet2 error - %d: %s\n", cerrno, cerrmsg); + goto comet2err; + } reset(); startptr = 0; if(loadassemble(argv[optind]) == true) { exec(); /* プログラム実行 */ } if(cerrno > 0) { - freecerr(); - exit(-1); + goto comet2err; } return 0; +comet2err: + freecerr(); + exit(-1); } diff --git a/test/integration/casl2/opt_h/0.txt b/test/integration/casl2/opt_h/0.txt index bf48477..bf6a3cc 100644 --- a/test/integration/casl2/opt_h/0.txt +++ b/test/integration/casl2/opt_h/0.txt @@ -1,2 +1,2 @@ ../../../../casl2 -saltdh ../../../../as/sum_10.casl -Usage: ../../../../casl2 [-slLaAtTdh] [-oO] [-M ] [-C ] FILE ... +Usage: ../../../../casl2 [-slLaAtTdh] [-oO] [-M ] [-C ] FILE ... diff --git a/test/integration/comet2/err_208/0.txt b/test/integration/comet2/err_208/0.txt new file mode 100644 index 0000000..6daf3f3 --- /dev/null +++ b/test/integration/comet2/err_208/0.txt @@ -0,0 +1,2 @@ +../../../../comet2 -M8 +comet2 error - 208: object file is not specified diff --git a/test/integration/comet2/err_208/Makefile b/test/integration/comet2/err_208/Makefile new file mode 100644 index 0000000..d36146b --- /dev/null +++ b/test/integration/comet2/err_208/Makefile @@ -0,0 +1,8 @@ +include ../CMD.mk # YACASL2DIR, CASL2, COMET2 +ASDIR = $(YACASL2DIR)/as +CASL2LIBDIR = $(YACASL2DIR)/as/casl2lib +ASFILE = $(YACASL2DIR)/as/err/err_207.casl +ASCMD = $(CASL2) -O $(YACASL2DIR)/as/err/err_207.casl +COMET2FLAG = -M8 +EXECCMD = $(COMET2) $(COMET2FLAG) +include ../TEST.mk diff --git a/test/integration/comet2/err_208/a.o b/test/integration/comet2/err_208/a.o new file mode 100644 index 0000000..b03d6df Binary files /dev/null and b/test/integration/comet2/err_208/a.o differ