changeset 120:5d29b6a1b50f testcode

include Word in Node
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Thu, 26 Nov 2015 20:40:30 +0900
parents 31b0ba0050fa
children aa266a4db47c 584f32e18398
files c/regexParser/node.cc c/regexParser/regexParser.cc c/regexParser/word.cc c/regexParser/word.h
diffstat 4 files changed, 21 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- 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++;
--- 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;
 }
 
--- 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 <stdlib.h>
 #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;
--- 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);