OSDN Git Service

add function for tadsegment stucture.
authorornse01 <ornse01@users.sourceforge.jp>
Wed, 20 Aug 2014 17:40:31 +0000 (17:40 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Wed, 20 Aug 2014 17:40:31 +0000 (17:40 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchanf/trunk@627 20a0b8eb-f62a-4a12-8fe1-b598822500fb

src/tad/tadstack.c
src/tad/tadstack.h
src/tad/test_tadstack.c

index 341b90c..6dcc44d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * tadstack.c
  *
- * Copyright (c) 2012 project bchan
+ * Copyright (c) 2012-2014 project bchan
  *
  * This software is provided 'as-is', without any express or implied
  * warranty. In no event will the authors be held liable for any damages
@@ -242,6 +242,25 @@ EXPORT TADSTACK_RESULT tadstack_inputvsegment(tadstack_t *stack, UH segid, UB *b
        return ret;
 }
 
+EXPORT TADSTACK_RESULT tadstack_inputsegment(tadstack_t *stack, tadsegment *segment)
+{
+       UB segid;
+       UB *segdata;
+       W seglen;
+
+       switch (segment->type) {
+       case TADSEGMENT_TYPE_VARIABLE:
+               tadsegment_getvariable(segment, &segid, &seglen, &segdata);
+               return tadstack_inputvsegment(stack, segid, segdata, seglen);
+       case TADSEGMENT_TYPE_CHARACTOR:
+               return tadstack_inputcharactor(stack, segment->value.ch);
+       case TADSEGMENT_TYPE_LANGCODE:
+               /* TODO */
+               return TADSTACK_RESULT_LANGUAGE_CHANGE;
+       }
+       return TADSTACK_RESULT_FORMAT_ERROR;
+}
+
 EXPORT VOID tadstack_initialize(tadstack_t *stack)
 {
        stack->state = TADSTACK_STATE_START;
index 29388b5..0dd47ad 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * tadstack.h
  *
- * Copyright (c) 2012 project bchan
+ * Copyright (c) 2012-2014 project bchan
  *
  * This software is provided 'as-is', without any express or implied
  * warranty. In no event will the authors be held liable for any damages
@@ -32,6 +32,9 @@
 #include       <btron/dp.h>
 #include    <tad.h>
 
+#include       "tadsegment.h"
+#include       "tadlangcode.h"
+
 #ifndef __TADSTACK_H__
 #define __TADSTACK_H__
 
@@ -84,6 +87,7 @@ IMPORT VOID tadstack_initialize(tadstack_t *stack);
 IMPORT VOID tadstack_finalize(tadstack_t *stack);
 IMPORT TADSTACK_RESULT tadstack_inputcharactor(tadstack_t *stack, TC ch);
 IMPORT TADSTACK_RESULT tadstack_inputvsegment(tadstack_t *stack, UH segid, UB *bin, W len);
+IMPORT TADSTACK_RESULT tadstack_inputsegment(tadstack_t *stack, tadsegment *segment);
 IMPORT W tadstack_nestlevel(tadstack_t *stack);
 IMPORT VOID tadstack_currentlang(tadstack_t *stack, TC **lang, W *len);
 IMPORT TADSTACK_DATATYPE tadstack_currentdata(tadstack_t *stack);
index f65662c..5bf519a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * test_tadstack.c
  *
- * Copyright (c) 2012 project bchan
+ * Copyright (c) 2012-2014 project bchan
  *
  * This software is provided 'as-is', without any express or implied
  * warranty. In no event will the authors be held liable for any damages
@@ -34,6 +34,7 @@
 #include       <bstring.h>
 
 #include "taditerator.h"
+#include "taddecoder.h"
 
 #include    <unittest_driver.h>
 
@@ -111,7 +112,39 @@ LOCAL UNITTEST_RESULT test_tadstack_1()
        return ok;
 }
 
+LOCAL UNITTEST_RESULT test_tadstack_2()
+{
+       tadstack_t stack;
+       taddecoder_t decoder;
+       tadsegment segment;
+       Bool cont;
+       TADSTACK_RESULT stk_result;
+       UNITTEST_RESULT ok = UNITTEST_RESULT_PASS;
+
+       tadstack_initialize(&stack);
+       taddecoder_initialize(&decoder, (TC*)test_tadstack_testdata01, sizeof(test_tadstack_testdata01)/sizeof(TC));
+
+       for (;;) {
+               cont = taddecoder_next(&decoder, &segment);
+               if (cont == False) {
+                       break;
+               }
+                       
+               stk_result = tadstack_inputsegment(&stack, &segment);
+               if (stk_result == TADSTACK_RESULT_FORMAT_ERROR) {
+                       printf("format error\n");
+                       ok = UNITTEST_RESULT_FAIL;
+               }
+       }
+
+       taddecoder_finalize(&decoder);
+       tadstack_finalize(&stack);
+
+       return ok;
+}
+
 EXPORT VOID test_tadstack_main(unittest_driver_t *driver)
 {
        UNITTEST_DRIVER_REGIST(driver, test_tadstack_1);
+       UNITTEST_DRIVER_REGIST(driver, test_tadstack_2);
 }