# HG changeset patch # User Masataka Kohagura # Date 1448538030 -32400 # Node ID 5d29b6a1b50fe002741558e6ea48626422df3896 # Parent 31b0ba0050faf2e3cdcab4747d542b10c8733eff include Word in Node diff -r 31b0ba0050fa -r 5d29b6a1b50f c/regexParser/node.cc --- a/c/regexParser/node.cc Thu Nov 26 17:19:00 2015 +0900 +++ b/c/regexParser/node.cc Thu Nov 26 20:40:30 2015 +0900 @@ -7,11 +7,8 @@ descendTree(n->right, d); d--; } - if (n->tokenType == 'a') { - printf("%*c%s(%lu)\n",d*4, ' ',n->cc->cond->w->word,n->nodeNumber); - } else { - printf("%*c%s\n",d*4, ' ',n->cc->cond->w->word); - } + + printf("%*c%s(%lu)\n",d*4, ' ',n->cc->cond->w->word,n->nodeNumber); if (n->left != NULL) { d++; diff -r 31b0ba0050fa -r 5d29b6a1b50f c/regexParser/regexParser.cc --- a/c/regexParser/regexParser.cc Thu Nov 26 17:19:00 2015 +0900 +++ b/c/regexParser/regexParser.cc Thu Nov 26 20:40:30 2015 +0900 @@ -36,10 +36,10 @@ n->tokenType = ri->tokenType; n->left = left; n->right = right; + n->nodeNumber = ri->nodeNumber; + ri->nodeNumber++; if (ri->tokenType == 'a') { - n->nodeNumber = ri->nodeNumber; - ri->nodeNumber++; ri->tokenType = 0; n->cc->cond->w = getWord(ri->tokenValue); ri->ptr += n->cc->cond->w->length-1; @@ -128,8 +128,6 @@ return; } } - ri->tokenType = 0; - ri->tokenValue = 0; return; } diff -r 31b0ba0050fa -r 5d29b6a1b50f c/regexParser/word.cc --- a/c/regexParser/word.cc Thu Nov 26 17:19:00 2015 +0900 +++ b/c/regexParser/word.cc Thu Nov 26 20:40:30 2015 +0900 @@ -4,32 +4,27 @@ #include #include "word.h" +int getWordLength(unsigned char* w){ + int i = 0; + + for (i=0;isalnum(w[i]);i++); + + return i; +} + WordPtr getWord(unsigned char *string) { WordPtr w = (WordPtr)malloc(sizeof(Word)); - int i = 0; - while (isalnum(string[i])) { - i++; - } - - int allocateWordSize, wordLength; + int i = getWordLength(string); + int wordLength; + int allocateWordSize; - unsigned char *word = NULL; - if (string[i] == '*') { - wordLength = i-1; - allocateWordSize = i; - word = (unsigned char*)malloc(sizeof(unsigned char)*allocateWordSize); - strncpy((char*)word, (char*)string, allocateWordSize); - word[allocateWordSize-1] = '\0'; - } else { - wordLength = i; - allocateWordSize = i+1; - word = (unsigned char*)malloc(sizeof(unsigned char)*allocateWordSize); - strncpy((char*)word, (char*)string, allocateWordSize); - word[allocateWordSize] = '\0'; - } - + wordLength = i; + allocateWordSize = i+1; + unsigned char *word = (unsigned char*)malloc(sizeof(unsigned char)*allocateWordSize); + strncpy((char*)word, (char*)string, allocateWordSize); + word[wordLength] = '\0'; w->word = word; w->length = wordLength; return w; diff -r 31b0ba0050fa -r 5d29b6a1b50f c/regexParser/word.h --- a/c/regexParser/word.h Thu Nov 26 17:19:00 2015 +0900 +++ b/c/regexParser/word.h Thu Nov 26 20:40:30 2015 +0900 @@ -4,3 +4,4 @@ } Word, *WordPtr; WordPtr getWord(unsigned char*); +int getWordLength(unsigned char* w);