From b40e4e96056df0ad2c248a3b6e58a8f4910f879e Mon Sep 17 00:00:00 2001 From: j8takagi Date: Mon, 8 Feb 2010 00:59:48 +0900 Subject: [PATCH] =?utf8?q?'=20'=E4=B8=AD=E3=81=AB;=E3=81=8C=E5=90=AB?= =?utf8?q?=E3=81=BE=E3=82=8C=E3=82=8B=E8=A1=8C=E3=82=92=E6=AD=A3=E3=81=97?= =?utf8?q?=E3=81=8F=E5=87=A6=E7=90=86=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84?= =?utf8?q?=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/token.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/token.c b/src/token.c index aa0a620..96ddcaa 100644 --- a/src/token.c +++ b/src/token.c @@ -57,19 +57,28 @@ OPD *opdtok(const char *str) /* 空白またはタブで区切られた1行から、トークンを取得 */ CMDLINE *linetok(const char *line) { - char *tokens, *p, *q, *sepp; + char *tokens, *p, *sepp; + bool quoting = false; CMDLINE *cmdl = malloc(sizeof(CMDLINE)); + if(line == NULL || strlen(line) == 0) { return NULL; } - tokens = p = strdup(line); + tokens = strdup(line); /* コメントを削除 */ - if((q = strchr(tokens, ';')) != NULL) { - *q = '\0'; + for(p = tokens; *p != '\0'; p++) { + /* 「'」で囲まれた文字列の処理。「''」は無視 */ + if(*p == '\'' && *(p+1) != '\'' && !(p > tokens && *(p-1) == '\'')) { + quoting = !quoting; + } else if(quoting == false && *p == ';') { + *p = '\0'; + break; + } } - if(*p == '\0') { + if(*tokens == '\0') { return NULL; } + p = tokens; /* 行の先頭が空白またはタブの場合、ラベルは空 */ if((sepp = p + strcspn(p, " \t\n")) == p){ cmdl->label = NULL; -- 2.18.0