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++;
}
}
setcerr(106, ""); /* operand count mismatch */
return;
}
- if(*(cmdl->label) == '\0') {
+ if(!*(cmdl->label)) {
setcerr(107, ""); /* no label in START */
return;
}
else if(pass == SECOND) {
execptr->end = asptr->lptr;
}
- *(asptr->prog) = '\0';
+ strcpy(asptr->prog, "");
}
void assemble_ds(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);
bool assembletok(const CMDLINE *cmdl, PASS pass)
{
/* 命令がない場合 */
- if(*(cmdl->cmd) == '\0') {
+ if(!*(cmdl->cmd)) {
return true;
}
/* アセンブラ命令またはマクロ命令の書込 */
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);
}
}
return;
}
for(i = 0; i < INSIZE; i++) {
- if(*(buf + i) == '\0' || *(buf + i) == '\n') {
+ if(!buf[i] || buf[i] == '\n') {
--i;
break;
}
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;
int i = 0, j;
unsigned h;
- if(*prog != '\0') {
+ if(prog[0]) {
keys[i++] = label_hashkey(prog);
}
keys[i] = label_hashkey(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;
}
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);
}
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 == ' ');
long l;
MONCMDLINE *moncmdl = NULL;
- if(*line == '\n' || *line == '\0') {
+ if(!line[0] || line[0] == '\n') {
return NULL;
}
p = tokens = strdup_chk(line, "tokens");
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);
* ハッシュ表のサイズ
*/
enum {
- CMDTABSIZE = 39,
+ CMDTABSIZE = 41,
};
/**
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;
}
}
/* WORD値に変換 */
w = (WORD)strtol(str, &check, 16);
- if(*check != '\0') {
+ if(check[0]) {
setcerr(115, str-1); /* not hex */
return 0x0;
}
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;
}
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);
} else if(word == '\t') {
fprintf(stdout, " = \'\\t\'");
}
- FREE(b);
+ FREE(bit);
}