From 176a22fd90e39acf9b4bdae260d71b8d31be6db0 Mon Sep 17 00:00:00 2001 From: j8takagi Date: Thu, 28 Apr 2011 00:22:24 +0900 Subject: [PATCH] =?utf8?q?prog=E3=81=8C=E8=A8=AD=E5=AE=9A=E3=81=95?= =?utf8?q?=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88?= =?utf8?q?=E3=80=81=E5=A4=89=E6=95=B0=E3=81=ABNULL=E3=81=A7=E3=81=AF?= =?utf8?q?=E3=81=AA=E3=81=8F'\0'=E3=82=92=E8=A8=AD=E5=AE=9A=E3=81=97?= =?utf8?q?=E3=81=A6=E5=88=A4=E5=AE=9A=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?utf8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/assemble.c | 10 +++++----- src/casl2.c | 4 +++- src/label.c | 18 +++++------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/assemble.c b/src/assemble.c index 989173f..c53ad5b 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -128,8 +128,8 @@ WORD getadr(const char *prog, const char *str, PASS pass) } else if(isdigit(*str) || *str == '-' || *str == '#') { adr = nh2word(str); } else { - if(pass == SECOND && (adr = getlabel(prog, str)) == 0xFFFF) { - if(prog != NULL) { + if(pass == SECOND) { + if((adr = getlabel(prog, str)) == 0xFFFF) { setcerr(103, str); /* label not found */ } } @@ -263,7 +263,7 @@ void assemble_start(const CMDLINE *cmdl, PASS pass) return; } /* プログラム名の設定 */ - asptr->prog = strdup_chk(cmdl->label, "asptr.prog"); + strcpy(asptr->prog, cmdl->label); /* オペランドがある場合、実行開始アドレスを設定 */ if(pass == SECOND && cmdl->opd->opdv[0] != NULL) { if((execptr->start = getlabel(asptr->prog, cmdl->opd->opdv[0])) == 0xFFFF) { @@ -290,7 +290,7 @@ void assemble_end(const CMDLINE *cmdl, PASS pass) else if(pass == SECOND) { execptr->end = asptr->lptr; } - FREE(asptr->prog); + *(asptr->prog) = '\0'; } /** @@ -558,7 +558,7 @@ bool assemble_comet2cmd(const CMDLINE *cmdl, PASS pass) /* CALL以外の命令の場合と、プログラムの入口名を取得できない場合は、 */ /* 同一プログラム内のラベルを取得 */ if(pass == SECOND && cmd == 0x8000) { /* CALL命令 */ - adr = getlabel(NULL, cmdl->opd->opdv[0]); + adr = getlabel("", cmdl->opd->opdv[0]); } if(cmd != 0x8000 || (pass == SECOND && adr == 0xFFFF)) { adr = getadr(asptr->prog, cmdl->opd->opdv[0], pass); diff --git a/src/casl2.c b/src/casl2.c index d510e9f..b1430ff 100644 --- a/src/casl2.c +++ b/src/casl2.c @@ -65,6 +65,7 @@ void assemble(int filec, char *filev[]) create_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を作成 */ asptr = malloc_chk(sizeof(ASPTR), "asptr"); /* アセンブル時のプロパティ用の領域確保 */ + asptr->prog = malloc_chk(sizeof(LABELSIZE + 1), "asptr.prog"); asptr->ptr = 0; /* アセンブル。ラベル表作成のため、2回行う */ for(pass = FIRST; pass <= SECOND; pass++) { @@ -96,7 +97,8 @@ void assemble(int filec, char *filev[]) asfin: freelabel(); /* ラベルハッシュ表を解放 */ free_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を解放 */ - FREE(asptr); /* アセンブル時のプロパティを解放 */ + FREE(asptr->prog); /* アセンブル時のプロパティを解放 */ + FREE(asptr); } /** diff --git a/src/label.c b/src/label.c index 85fb172..5650a1f 100644 --- a/src/label.c +++ b/src/label.c @@ -37,7 +37,7 @@ unsigned labelhash(const char *prog, const char *label) int i = 0, j; unsigned h; - if(prog != NULL) { + if(*prog != '\0') { keys[i] = malloc_chk(sizeof(HKEY), "labelhash.key"); keys[i]->type = CHARS; keys[i]->val.s = strdup_chk(prog, "labelhash.key.val"); @@ -63,7 +63,7 @@ WORD getlabel(const char *prog, const char *label) LABELTAB *p; for(p = labels[labelhash(prog, label)]; p != NULL; p = p->next) { - if((prog == NULL || (p->prog != NULL && strcmp(prog, p->prog) == 0)) && + if((*prog == '\0' || (strcmp(prog, p->prog) == 0)) && strcmp(label, p->label) == 0) { return p->adr; @@ -89,11 +89,7 @@ bool addlabel(const char *prog, const char *label, WORD adr) /* メモリを確保 */ p = malloc_chk(sizeof(LABELTAB), "labels.next"); /* プログラム名を設定 */ - if(prog == NULL) { - p->prog = NULL; - } else { - p->prog = strdup_chk(prog, "labels.prog"); - } + p->prog = strdup_chk(prog, "labels.prog"); /* ラベルを設定 */ p->label = strdup_chk(label, "labels.label"); /* アドレスを設定 */ @@ -129,18 +125,14 @@ void printlabel() for(p = labels[i]; p != NULL; p = p->next) { assert(p->label != NULL); l[s] = malloc_chk(sizeof(LABELARRAY), "lables"); - if(p->prog == NULL) { - l[s]->prog = NULL; - } else { - l[s]->prog = strdup_chk(p->prog, "labels.prog"); - } + l[s]->prog = strdup_chk(p->prog, "labels.prog"); l[s]->label = strdup_chk(p->label, "labels.label"); l[s++]->adr = p->adr; } } qsort(l, s, sizeof(*l), compare_adr); for(i = 0; i < s; i++) { - if(l[i]->prog != NULL) { + if(*(l[i]->prog) != '\0') { fprintf(stdout, "%s.", l[i]->prog); } fprintf(stdout, "%s ---> #%04X\n", l[i]->label, l[i]->adr); -- 2.18.0