X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Ftoken.c;h=2757a7b46ded91501641176b3f3dfc4f9325946e;hp=96ddcaae2445e81ca9eed8265aca604ba3af2d49;hb=2ef92a7c1a848fbe897ac6e14f73fd6dbeef8c84;hpb=24f3ed4394bc3d9bfe2f387f91e0b7f41ec8555e diff --git a/src/token.c b/src/token.c index 96ddcaa..2757a7b 100644 --- a/src/token.c +++ b/src/token.c @@ -6,7 +6,7 @@ OPD *opdtok(const char *str) { OPD *opd = malloc(sizeof(OPD)); char *p, *q, *sepp; - int sepc = ','; + int sepc = ',', len = 0; bool quoting = false; opd->opdc = 0; @@ -24,14 +24,21 @@ 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) { /* 閉じ「'」がないまま文字列が終了した場合 */ if(*q == '\0') { - setcerr(123, str); /* illegal string */ + setcerr(123, str); /* unclosed quote */ break; } q++; @@ -39,12 +46,13 @@ 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(p); + if(len > OPDSIZE) { + setcerr(118, NULL); /* operand length is too long */ break; } opd->opdv[(++opd->opdc)-1] = strdup(p);