From: j8takagi Date: Wed, 10 Feb 2010 14:33:04 +0000 (+0900) Subject: Merge branch 'master' into cmd-casl X-Git-Tag: v0.1~47^2~7 X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=commitdiff_plain;h=53f2f21be49965874887e0315eeb325ac6cae242;hp=c1f7164cea1d3e5aebb76dc26543b1de593b92bb Merge branch 'master' into cmd-casl --- diff --git a/src/token.c b/src/token.c index 68ed3a7..54ebf3f 100644 --- a/src/token.c +++ b/src/token.c @@ -5,7 +5,7 @@ OPD *opdtok(const char *str) { OPD *opd = malloc(sizeof(OPD)); - char *p, *q, *r, *sepp; + char *p, *q, *sepp; int sepc = ',', len; bool quoting = false; @@ -15,6 +15,7 @@ OPD *opdtok(const char *str) } p = q = strdup(str); do { + len = 0; /* オペランド数が多すぎる場合はエラー */ if(opd->opdc >= OPDSIZE) { setcerr(117, str); /* operand is too many */ @@ -24,9 +25,16 @@ OPD *opdtok(const char *str) if(*q == '=') { q++; } - /* 「'」で囲まれた文字列の処理。「''」は無視 */ - if(*q == '\'' && *(q+1) != '\'' && !(p < q && *(q-1) == '\'')) { - quoting = !quoting; + /* 「'」の場合 */ + if(*q == '\'') { + /* 「''」以外の場合はquote値を反転 */ + if(*(q+1) != '\'' && !(p < q && *(q-1) == '\'')) { + quoting = !quoting; + } + /* 「'」の分、文字列の長さを小さくする */ + if(*(q+1) != '\'') { + len--; + } } if(quoting == true) { /* 閉じ「'」がないまま文字列が終了した場合 */ @@ -43,12 +51,8 @@ OPD *opdtok(const char *str) setcerr(121, NULL); /* cannot get operand token */ break; } - len = strlen(r = p); - while(*r != '\0' && (r = strstr(r, "''")) != NULL) { - len--; - r += 2; - }; - if(len > OPDSIZE + 2) { /* OPDSIZE + 「'」2文字分 */ + len += strlen(p); + if(len > OPDSIZE) { setcerr(118, NULL); /* operand length is too long */ break; } diff --git a/test/integration/casl2/quoteend_err/0.txt b/test/integration/casl2/quoteend_err/0.txt index fa671ad..8c19446 100644 --- a/test/integration/casl2/quoteend_err/0.txt +++ b/test/integration/casl2/quoteend_err/0.txt @@ -1,6 +1,6 @@ ../../../../casl2 -td ../../../../as/ERR/quoteend_err.casl Assemble ../../../../as/ERR/quoteend_err.casl (0) -Assemble error - 123: 'Hello, World!: illegal string +Assemble error - 123: 'Hello, World!: unclosed quote ../../../../as/ERR/quoteend_err.casl:4: BUF DC 'Hello, World!