X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Ftoken.c;h=d2242af96c9e6f798178801c9874d3fa75d3381e;hp=de29fafdad36fd8e4730a2cfe1af111413c0334c;hb=9a48fd93fe01972f0de42c6349e2e8a8160ec5df;hpb=4a1d361916c660b63611a40520eaf7c78788f123 diff --git a/src/token.c b/src/token.c index de29faf..d2242af 100644 --- a/src/token.c +++ b/src/token.c @@ -50,7 +50,7 @@ OPD *opdtok(const char *str) do { /* オペランド数が多すぎる場合はエラー */ if(opd->opdc >= OPDSIZE) { - setcerr(117, NULL); /* operand is too many */ + setcerr(117, ""); /* operand is too many */ break; } /* 先頭が等号(=)の場合 */ @@ -80,11 +80,11 @@ OPD *opdtok(const char *str) sepc = *sepp; *sepp = '\0'; if(*q == '\0') { - setcerr(121, NULL); /* cannot get operand token */ + setcerr(121, ""); /* cannot get operand token */ break; } if(strlen(q) - rcnt > OPDSIZE) { - setcerr(118, NULL); /* operand length is too long */ + setcerr(118, ""); /* operand length is too long */ break; } opd->opdv[(++opd->opdc)-1] = strdup_chk(q, "opd.opdv[]"); @@ -119,19 +119,20 @@ CMDLINE *linetok(const char *line) break; } } - if(*tokens != '\0') { + if(*tokens != '\n' && *tokens != '\0') { p = tokens; cmdl = malloc_chk(sizeof(CMDLINE), "cmdl"); + cmdl->label = malloc_chk(sizeof(LABELSIZE + 1), "cmdl.label"); /* ラベルの取得。行の先頭が空白またはタブの場合、ラベルは空 */ if((sepp = p + strcspn(p, " \t\n")) == p){ - cmdl->label = NULL; + cmdl->label = '\0'; } else { /* ラベルを取得 */ *sepp = '\0'; /* 文字列が長すぎる場合はエラー */ if(strlen(p) > LABELSIZE) { setcerr(104, p); /* label length is too long */ } - cmdl->label = strdup_chk(p, "cmdl.label"); + strcpy(cmdl->label, p); p = sepp + 1; } /* ラベルと命令の間の空白をスキップ */ @@ -140,9 +141,10 @@ CMDLINE *linetok(const char *line) } /* 命令とオペランドの取得 */ if(*p == '\n' || *p == '\0') { /* 命令がない場合は、終了 */ - if(cmdl->label != NULL) { /* ラベルが定義されていて命令がない場合はエラー */ - setcerr(105, NULL); /* no command in the line */ + if(cmdl->label != '\0') { /* ラベルが定義されていて命令がない場合はエラー */ + setcerr(105, ""); /* no command in the line */ } + FREE(cmdl); } else { /* 命令の取得 */ sepp = p + strcspn(p, " \t\n");