From: j8takagi Date: Tue, 9 Feb 2010 00:00:58 +0000 (+0900) Subject: 文字定数の長さを取得するときに「''」を1文字とするよう修正 X-Git-Tag: v0.1~56 X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=commitdiff_plain;h=bb9d41081432d335dcb0b3ad8c9d7dd9c6790b6f;ds=sidebyside 文字定数の長さを取得するときに「''」を1文字とするよう修正 --- diff --git a/src/casl2.c b/src/casl2.c index 8e0b94a..8ae3495 100644 --- a/src/casl2.c +++ b/src/casl2.c @@ -52,7 +52,7 @@ CERRARRAY cerr[] = { { 120, "GR0 in operand x" }, { 121, "cannot get operand token" }, { 122, "cannot create hash table" }, - { 123, "illegal string" }, + { 123, "unclosed quote" }, { 124, "more than one character in literal" }, { 125, "not GR in operand x" }, { 201, "execute - out of COMET II memory" }, diff --git a/src/token.c b/src/token.c index 96ddcaa..68ed3a7 100644 --- a/src/token.c +++ b/src/token.c @@ -5,8 +5,8 @@ OPD *opdtok(const char *str) { OPD *opd = malloc(sizeof(OPD)); - char *p, *q, *sepp; - int sepc = ','; + char *p, *q, *r, *sepp; + int sepc = ',', len; bool quoting = false; opd->opdc = 0; @@ -31,7 +31,7 @@ OPD *opdtok(const char *str) if(quoting == true) { /* 閉じ「'」がないまま文字列が終了した場合 */ if(*q == '\0') { - setcerr(123, str); /* illegal string */ + setcerr(123, str); /* unclosed quote */ break; } q++; @@ -39,12 +39,17 @@ OPD *opdtok(const char *str) sepp = q + strcspn(q, ", "); sepc = *sepp; *sepp = '\0'; - if(strlen(p) == 0) { + if(*p == '\0') { setcerr(121, NULL); /* cannot get operand token */ break; } - if(strlen(p) > OPDSIZE + 2) { /* OPDSIZE + 「'」2文字分 */ - setcerr(118, p); /* operand length is too long */ + len = strlen(r = p); + while(*r != '\0' && (r = strstr(r, "''")) != NULL) { + len--; + r += 2; + }; + if(len > OPDSIZE + 2) { /* OPDSIZE + 「'」2文字分 */ + setcerr(118, NULL); /* operand length is too long */ break; } opd->opdv[(++opd->opdc)-1] = strdup(p);