X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fcasl2.c;h=9753c8361c8cd872e38f5e93d176b52c14452232;hp=c3a555015a77009bb2c56ded13fe22fd7e18d61f;hb=3ea92ba68cb320156d5bc7fe92f5e5fa0c150635;hpb=285d44a446b45fa1a5ac66617b6920bc7ba81fa6 diff --git a/src/casl2.c b/src/casl2.c index c3a5550..9753c83 100644 --- a/src/casl2.c +++ b/src/casl2.c @@ -24,7 +24,7 @@ static struct option longopts[] = { }; /* エラー番号とエラーメッセージ */ -CERRARRAY cerr[] = { +CERRARRAY cerr_casl2[] = { { 101, "label already defined" }, { 102, "label table is full" }, { 103, "label not found" }, @@ -50,6 +50,7 @@ CERRARRAY cerr[] = { { 123, "unclosed quote" }, { 124, "more than one character in literal" }, { 125, "not GR in operand x" }, + { 126, "source file is not specified" }, { 201, "execute - out of COMET II memory" }, { 202, "SVC input - out of Input memory" }, { 203, "SVC output - out of COMET II memory" }, @@ -57,7 +58,6 @@ CERRARRAY cerr[] = { { 205, "Stack Pointer (SP) - cannot allocate stack buffer" }, { 206, "Address - out of COMET II memory" }, { 207, "Stack Pointer (SP) - out of COMET II memory" }, - { 0, NULL }, }; /* 指定されたファイルにアセンブル結果を書込 */ @@ -97,38 +97,38 @@ int main(int argc, char *argv[]) while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) { switch(opt) { case 's': - (&asmode)->src = true; + asmode.src = true; break; case 'l': - (&asmode)->label = true; + asmode.label = true; break; case 'L': - (&asmode)->label = true; - (&asmode)->onlylabel = true; + asmode.label = true; + asmode.onlylabel = true; break; case 'a': - (&asmode)->asdetail = true; + asmode.asdetail = true; break; case 'A': - (&asmode)->asdetail = true; - (&asmode)->onlyassemble = true; + asmode.asdetail = true; + asmode.onlyassemble = true; break; case 'o': objfile = strdup(objfile_name(optarg)); break; case 'O': - (&asmode)->onlyassemble = true; + asmode.onlyassemble = true; objfile = strdup(objfile_name(optarg)); break; case 't': - (&execmode)->trace = true; + execmode.trace = true; break; case 'T': - (&execmode)->trace = true; - (&execmode)->logical = true; + execmode.trace = true; + execmode.logical = true; break; case 'd': - (&execmode)->dump = true; + execmode.dump = true; break; case 'M': memsize = atoi(optarg); @@ -144,15 +144,20 @@ int main(int argc, char *argv[]) exit(-1); } } + /* エラーリストにerr_casl2を追加 */ + addcerrlist(ARRAYSIZE(cerr_casl2), cerr_casl2); /* ソースファイルが指定されていない場合は終了 */ if(argv[optind] == NULL) { - fprintf(stderr, "source file is not specified\n"); - exit(-1); + setcerr(126, NULL); /* source file is not specified */ + goto casl2err; } /* COMET II仮想マシンのリセット */ reset(); /* アセンブル。ラベル表作成のため、2回行う */ for(pass = FIRST; pass <= SECOND; pass++) { + if(pass == FIRST && create_cmdtype_code() == false) { + goto casl2err; + } for(i = optind; i < argc; i++) { /* データの格納開始位置 */ if(pass == FIRST) { @@ -160,24 +165,19 @@ int main(int argc, char *argv[]) } else if(pass == SECOND) { ptr = beginptr[i]; } - if((&execmode)->trace == true || (&execmode)->dump == true || - (&asmode)->src == true || (&asmode)->label == true || - (&asmode)->asdetail == true) + if(execmode.trace == true || execmode.dump == true || asmode.src == true || + asmode.label == true || asmode.asdetail == true) { fprintf(stdout, "\nAssemble %s (%d)\n", argv[i], pass); } if((status = assemble(argv[i], pass)) == false) { - freelabel(); /* ラベル表の解放 */ - if(cerrno > 0) { - freecerr(); /* エラーの解放 */ - } exit(-1); } } - if(pass == FIRST && (&asmode)->label == true) { + if(pass == FIRST && asmode.label == true) { fprintf(stdout, "\nLabel::::\n"); printlabel(); - if((&asmode)->onlylabel == true) { + if(asmode.onlylabel == true) { return 0; } } @@ -187,7 +187,7 @@ int main(int argc, char *argv[]) if(objfile != NULL) { outassemble(objfile); } - if((&asmode)->onlyassemble == false) { + if(asmode.onlyassemble == false) { exec(); /* プログラム実行 */ } } @@ -196,4 +196,7 @@ int main(int argc, char *argv[]) exit(-1); } return 0; +casl2err: + fprintf(stderr, "CASL2 error - %d: %s\n", cerrno, cerrmsg); + exit(-1); }