From: j8takagi Date: Sat, 9 Feb 2019 02:08:19 +0000 (+0900) Subject: ソースの推敲 X-Git-Tag: v0.5p3~10 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8365c3016d2564c0498d2dc21300b1bff57e929b;p=YACASL2.git ソースの推敲 --- diff --git a/src/assemble.c b/src/assemble.c index 901da29..33fd93e 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -389,28 +389,31 @@ void writestr(const char *str, bool literal, PASS pass) assert(*str == '\''); const char *p = str + 1; bool lw = false; - int i; - for(i = 0; p[i] != '\'' || p[i+1] == '\''; i++) { + for(; ;) { /* 閉じ「'」がないまま文字列が終了した場合 */ - if(!p[i]) { + if(!p[0]) { setcerr(123, str); /* unclosed quote */ break; } - if(literal == true && lw == true) { + /* 「'」の場合、次の文字が「'」でない場合は正常終了 */ + if(p[0] == '\'') { + p++; + if(p[0] != '\'') { + break; + } + } else if(literal == true && lw == true) { setcerr(124, str); /* more than one character in literal */ break; } - if(p[i] == '\'') { - i++; - } /*リテラルの場合はリテラル領域に書込 */ if(literal == true) { - writememory(p[i], (asptr->lptr)++, pass); + writememory(p[0], (asptr->lptr)++, pass); lw = true; } else { - writememory(p[i], (asptr->ptr)++, pass); + writememory(p[0], (asptr->ptr)++, pass); } + p++; } } @@ -438,7 +441,7 @@ void assemble_start(const CMDLINE *cmdl, PASS pass) setcerr(106, ""); /* operand count mismatch */ return; } - if(*(cmdl->label) == '\0') { + if(!*(cmdl->label)) { setcerr(107, ""); /* no label in START */ return; } @@ -464,7 +467,7 @@ void assemble_end(const CMDLINE *cmdl, PASS pass) else if(pass == SECOND) { execptr->end = asptr->lptr; } - *(asptr->prog) = '\0'; + strcpy(asptr->prog, ""); } void assemble_ds(const CMDLINE *cmdl, PASS pass) @@ -572,7 +575,7 @@ bool casl2cmd(CMD *cmdtbl, const CMDLINE *cmdl, PASS pass) { int i; void (*cmdptr)(); - for(i = 0; *(cmdtbl[i].name) != '\0'; i++) { + for(i = 0; *(cmdtbl[i].name); i++) { if(strcmp(cmdl->cmd, cmdtbl[i].name) == 0) { cmdptr = cmdtbl[i].ptr; (*cmdptr)(cmdl, pass); @@ -672,7 +675,7 @@ bool assemble_comet2cmd(const CMDLINE *cmdl, PASS pass) bool assembletok(const CMDLINE *cmdl, PASS pass) { /* 命令がない場合 */ - if(*(cmdl->cmd) == '\0') { + if(!*(cmdl->cmd)) { return true; } /* アセンブラ命令またはマクロ命令の書込 */ @@ -697,7 +700,7 @@ bool assembleline(const char *line, PASS pass) stat = (cerr->num == 0) ? true : false; if(cmdl != NULL) { if(stat == true) { - if(pass == FIRST && *(cmdl->label) != '\0') { + if(pass == FIRST && *(cmdl->label)) { stat = addlabel(asptr->prog, cmdl->label, asptr->ptr); } } diff --git a/src/exec.c b/src/exec.c index 048f223..8c9d566 100644 --- a/src/exec.c +++ b/src/exec.c @@ -116,7 +116,7 @@ void svcin() return; } for(i = 0; i < INSIZE; i++) { - if(*(buf + i) == '\0' || *(buf + i) == '\n') { + if(!buf[i] || buf[i] == '\n') { --i; break; } diff --git a/src/hash.c b/src/hash.c index 6436047..f6a4558 100644 --- a/src/hash.c +++ b/src/hash.c @@ -2,19 +2,21 @@ unsigned hash(int keyc, HKEY *keyv[], int tabsize) { - int i; - char *p; + int i, j; unsigned hashval = 0; + enum { + HASHNUM = 31 + }; for(i = 0; i < keyc; i++) { switch(keyv[i]->type) { case CHARS: - for(p = keyv[i]->val.s; *p != '\0'; p++) { - hashval = *p + 31 * hashval; + for(j = 0; keyv[i]->val.s[j]; j++) { + hashval = keyv[i]->val.s[j] + HASHNUM * hashval; } break; case INT: - hashval = keyv[i]->val.i + 31 * hashval; + hashval = keyv[i]->val.i + HASHNUM * hashval; break; default: break; diff --git a/src/label.c b/src/label.c index e88cc90..f69bd45 100644 --- a/src/label.c +++ b/src/label.c @@ -63,7 +63,7 @@ unsigned labelhash(const char *prog, const char *label) int i = 0, j; unsigned h; - if(*prog != '\0') { + if(prog[0]) { keys[i++] = label_hashkey(prog); } keys[i] = label_hashkey(label); @@ -94,7 +94,7 @@ WORD getlabel(const char *prog, const char *label) for(p = labels[labelhash(prog, label)]; p != NULL; p = p->next) { l = p->label; - if((*prog == '\0' || (strcmp(prog, l->prog) == 0)) && + if((!prog[0] || (strcmp(prog, l->prog) == 0)) && strcmp(label, l->label) == 0) { return l->adr; @@ -147,7 +147,7 @@ void printlabel() } qsort(l, s, sizeof(*l), compare_adr); for(i = 0; i < s; i++) { - if(*(l[i]->prog) != '\0') { + if(*(l[i]->prog)) { fprintf(stdout, "%s.", l[i]->prog); } fprintf(stdout, "%s ---> #%04X\n", l[i]->label, l[i]->adr); diff --git a/src/monitor.c b/src/monitor.c index 9fe71f5..831a47a 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -132,7 +132,7 @@ MONARGS *monargstok(const char *str) } sepp = r + strcspn(r, " "); sepc = *sepp; - *sepp = '\0'; + strcpy(sepp, ""); args->argv[++(args->argc)-1] = strdup_chk(q, "args.argv[]"); q = r = sepp + 1; } while(sepc == ' '); @@ -146,7 +146,7 @@ MONCMDLINE *monlinetok(const char *line) long l; MONCMDLINE *moncmdl = NULL; - if(*line == '\n' || *line == '\0') { + if(!line[0] || line[0] == '\n') { return NULL; } p = tokens = strdup_chk(line, "tokens"); @@ -349,7 +349,7 @@ void monitor() buf = malloc_chk(MONINSIZE + 1, "monitor.buf"); fgets(buf, MONINSIZE, stdin); if((p = strchr(buf, '\n')) != NULL) { - *p = '\0'; + strcpy(p, ""); } if((moncmdl = monlinetok(buf)) != NULL) { cmdtype = monitorcmd(moncmdl->cmd, moncmdl->args); diff --git a/src/struct.c b/src/struct.c index cc4d986..a617cec 100644 --- a/src/struct.c +++ b/src/struct.c @@ -64,7 +64,7 @@ static int comet2cmdsize = ARRAYSIZE(comet2cmd); * ハッシュ表のサイズ */ enum { - CMDTABSIZE = 39, + CMDTABSIZE = 41, }; /** diff --git a/src/word.c b/src/word.c index e7b646c..d26438f 100644 --- a/src/word.c +++ b/src/word.c @@ -42,13 +42,13 @@ WORD n2word(const char *str) int n; /* WORD値に変換 */ n = strtol(str, &check, 10); - if(*check != '\0') { + if(check[0]) { setcerr(114, str); /* not integer */ return 0x0; } /* nが-32768から32767の範囲にないときは、その下位16ビットを格納 */ if(n < -32768 || n > 32767) { - n = n & 0xFFFF; + n &= 0xFFFF; } return (WORD)n; } @@ -66,7 +66,7 @@ WORD h2word(const char *str) } /* WORD値に変換 */ w = (WORD)strtol(str, &check, 16); - if(*check != '\0') { + if(check[0]) { setcerr(115, str-1); /* not hex */ return 0x0; } @@ -105,12 +105,12 @@ char *word2n(WORD word) int i = 0, j; do{ - *(p + i++) = word % 10 + '0'; + p[i++] = word % 10 + '0'; } while((word /= 10) > 0); for(j = 0; j < i; j++) { - *(digit + j) = *(p + (i - 1) - j); + digit[j] = p[(i-1)-j]; } - *(digit + j + 1) = '\0'; + digit[j] = '\0'; FREE(p); return digit; } @@ -121,26 +121,26 @@ char *word2bit(const WORD word) MAXLEN = 16, /* WORD値を2進数で表したときの最大桁数 */ }; WORD mask = 0x8000; - char *bit, *p; + char *bit = malloc_chk(MAXLEN + 1, "word2bit.bit"); + int i = 0; - bit = p = malloc_chk(MAXLEN + 1, "word2bit.bit"); do { - *p++ = (word & mask) ? '1' : '0'; + bit[i++] = (word & mask) ? '1' : '0'; } while((mask >>= 1) > 0); - *p = '\0'; + bit[i] = '\0'; return bit; } void print_dumpword(WORD word, bool logicalmode) { - char *b; + char *bit = word2bit(word); if(logicalmode == true) { fprintf(stdout, "%6d", word); } else { fprintf(stdout, "%6d", (signed short)word); } - fprintf(stdout, " = #%04X = %s", word, (b = word2bit(word))); + fprintf(stdout, " = #%04X = %s", word, bit); /* 「文字の組」の符号表に記載された文字と、改行(CR)/タブを表示 */ if(word >= 0x20 && word <= 0x7E) { fprintf(stdout, " = \'%c\'", word); @@ -149,5 +149,5 @@ void print_dumpword(WORD word, bool logicalmode) } else if(word == '\t') { fprintf(stdout, " = \'\\t\'"); } - FREE(b); + FREE(bit); }