OSDN Git Service

change tadfragment_cursor_getdata argument type.
authorornse01 <ornse01@users.sourceforge.jp>
Sun, 17 Aug 2014 16:27:00 +0000 (16:27 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Sun, 17 Aug 2014 16:27:00 +0000 (16:27 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchanf/trunk@621 20a0b8eb-f62a-4a12-8fe1-b598822500fb

src/control/test_texteditor_characterstate.c
src/control/texteditor_characterstate.c
src/control/texteditor_characterstate.h
src/control/texteditor_textfragment.c
src/tad/tadfragment.c
src/tad/tadfragment.h
src/tad/test_tadfragment.c

index 4c6c2f4..8705cab 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * test_texteditor_characterstate.c
  *
- * Copyright (c) 2013 project bchan
+ * Copyright (c) 2013-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
@@ -37,7 +37,7 @@
 #include    <unittest_driver.h>
 
 typedef struct {
-       tadfragment_cursor_segment input;
+       tadsegment input;
        struct {
                TC *lang;
                W lang_len;
@@ -109,85 +109,58 @@ LOCAL UNITTEST_RESULT test_texteditor_characterstate_common(test_texteditor_char
 LOCAL UNITTEST_RESULT test_texteditor_characterstate_1()
 {
        test_texteditor_characterstate_t testdata[] = {
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x21, 0xFE}, 2},
-                       {(TC[]){0xFE21}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x22, 0xFE}, 2},
-                       {(TC[]){0xFE22}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0xFE, 0xFE, 0x21, 0xFE}, 4},
-                       {(TC[]){0xFEFE, 0xFE21}, 2, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0xFE, 0xFE, 0x21, 0x00}, 4},
-                       {(TC[]){0xFEFE, 0x0021}, 2, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0xFE, 0xFE, 0xFE, 0xFE, 0x21, 0xFE}, 6},
-                       {(TC[]){0xFEFE, 0xFEFE, 0xFE21}, 3, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0xFE, 0xFE, 0xFE, 0xFE, 0x21, 0x00}, 6},
-                       {(TC[]){0xFEFE, 0xFEFE, 0x0021}, 3, False}
-               }
+               { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE21}, 1, False} },
+               { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE22}, 1, False} },
+               { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFEFE, 0xFE21}, 2, False} },
+               { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFEFE, 0x0021}, 2, False} },
+               { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFEFE, 0xFEFE, 0xFE21}, 3, False} },
+               { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFEFE, 0xFEFE, 0x0021}, 3, False} },
        };
+       TCtotadlangcode((TC[]){0xFE21}, 1, &testdata[0].input.value.lang);
+       TCtotadlangcode((TC[]){0xFE22}, 1, &testdata[1].input.value.lang);
+       TCtotadlangcode((TC[]){0xFEFE, 0xFE21}, 2, &testdata[2].input.value.lang);
+       TCtotadlangcode((TC[]){0xFEFE, 0x0021}, 2, &testdata[3].input.value.lang);
+       TCtotadlangcode((TC[]){0xFEFE, 0xFEFE, 0xFE21}, 3, &testdata[4].input.value.lang);
+       TCtotadlangcode((TC[]){0xFEFE, 0xFEFE, 0x0021}, 3, &testdata[5].input.value.lang);
        return test_texteditor_characterstate_common(testdata, 6);
 }
 
 LOCAL UNITTEST_RESULT test_texteditor_characterstate_2()
 {
        test_texteditor_characterstate_t testdata[] = {
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
-                       {(TC[]){0xFE21}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x22, 0xFE}, 2},
-                       {(TC[]){0xFE22}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
-                       {(TC[]){0xFE22}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x21, 0xFE}, 2},
-                       {(TC[]){0xFE21}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
-                       {(TC[]){0xFE21}, 1, False}
-               },
+               { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE21}, 1, False} },
+               { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE22}, 1, False} },
+               { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE22}, 1, False} },
+               { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE21}, 1, False} },
+               { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE21}, 1, False} },
        };
+       testdata[0].input.value.ch = 0x2121;
+       TCtotadlangcode((TC[]){0xFE22}, 1, &testdata[1].input.value.lang);
+       testdata[2].input.value.ch = 0x2121;
+       TCtotadlangcode((TC[]){0xFE21}, 1, &testdata[3].input.value.lang);
+       testdata[4].input.value.ch = 0x2121;
        return test_texteditor_characterstate_common(testdata, 5);
 }
 
 LOCAL UNITTEST_RESULT test_texteditor_characterstate_3()
 {
        test_texteditor_characterstate_t testdata[] = {
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00}, 10},
-                       {(TC[]){0xFE21}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01}, 10},
-                       {(TC[]){0xFE21}, 1, True}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00}, 10},
-                       {(TC[]){0xFE21}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01}, 10},
-                       {(TC[]){0xFE21}, 1, True}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x01}, 10},
-                       {(TC[]){0xFE21}, 1, False}
-               },
+               { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, False} },
+               { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, True} },
+               { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, False} },
+               { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, True} },
+               { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, False} },
        };
+       testdata[0].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00};
+       testdata[0].input.value.variable.rawlen = 10;
+       testdata[1].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01};
+       testdata[1].input.value.variable.rawlen = 10;
+       testdata[2].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00};
+       testdata[2].input.value.variable.rawlen = 10;
+       testdata[3].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01};
+       testdata[3].input.value.variable.rawlen = 10;
+       testdata[4].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x01};
+       testdata[4].input.value.variable.rawlen = 10;
        return test_texteditor_characterstate_common(testdata, 5);
 }
 
@@ -195,39 +168,25 @@ LOCAL UNITTEST_RESULT test_texteditor_characterstate_3()
 LOCAL UNITTEST_RESULT test_texteditor_characterstate_4()
 {
        test_texteditor_characterstate_t testdata[] = {
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01}, 10},
-                       {(TC[]){0xFE21}, 1, True}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
-                       {(TC[]){0xFE21}, 1, True}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x22, 0xFE}, 2},
-                       {(TC[]){0xFE22}, 1, True}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
-                       {(TC[]){0xFE22}, 1, True}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00}, 10},
-                       {(TC[]){0xFE22}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
-                       {(TC[]){0xFE22}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x21, 0xFE}, 2},
-                       {(TC[]){0xFE21}, 1, False}
-               },
-               {
-                       {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
-                       {(TC[]){0xFE21}, 1, False}
-               },
+               { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, True} },
+               { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE21}, 1, True} },
+               { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE22}, 1, True} },
+               { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE22}, 1, True} },
+               { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE22}, 1, False} },
+               { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE22}, 1, False} },
+               { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE21}, 1, False} },
+               { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE21}, 1, False} },
        };
+       testdata[0].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01};
+       testdata[0].input.value.variable.rawlen = 10;
+       testdata[1].input.value.ch = 0x2121;
+       TCtotadlangcode((TC[]){0xFE22}, 1, &testdata[2].input.value.lang);
+       testdata[3].input.value.ch = 0x2121;
+       testdata[4].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00};
+       testdata[4].input.value.variable.rawlen = 10;
+       testdata[5].input.value.ch = 0x2121;
+       TCtotadlangcode((TC[]){0xFE21}, 1, &testdata[6].input.value.lang);
+       testdata[7].input.value.ch = 0x2121;
        return test_texteditor_characterstate_common(testdata, 8);
 }
 
index 73f2e0e..5cbb6f7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * texteditor_characterstate.h
  *
- * Copyright (c) 2013 project bchan
+ * Copyright (c) 2013-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
@@ -28,7 +28,7 @@
 
 #include       <bstdio.h>
 
-#include       <tad/tadfragment.h>
+#include       <tad/tadsegment.h>
 #include       <tad/tadlangcode.h>
 
 #ifdef BCHAN_CONFIG_DEBUG
 # define DP_ER(msg, err) /**/
 #endif
 
-EXPORT W texteditor_charactorstate_input(texteditor_characterstate_t *state, tadfragment_cursor_segment *segment)
+EXPORT W texteditor_charactorstate_input(texteditor_characterstate_t *state, tadsegment *segment)
 {
-       TC *str;
-       W len, err;
        UB segid, subid;
 
-       if (segment->type == TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE) {
-               if (segment->len != 10) {
+       if (segment->type == TADSEGMENT_TYPE_VARIABLE) {
+               if (segment->value.variable.rawlen != 10) {
                        return 0;
                }
-               segid = *(TC*)segment->p & 0xFF;
+               segid = *(TC*)segment->value.variable.raw & 0xFF;
                if (segid != TS_TFONT) {
                        return 0;
                }
-               subid = *(TC*)(segment->p + 4) >> 8;
+               subid = *(TC*)(segment->value.variable.raw + 4) >> 8;
                if (subid != 3) {
                        return 0;
                }
-               state->w_ratio = *(RATIO*)(segment->p + 8);
-       } else if (segment->type == TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE) {
-               str = (TC*)segment->p;
-               len = segment->len / sizeof(TC);
-               err = TCtotadlangcode(str, len, &state->lang);
-               if (err < 0) {
-                       return err;
-               }
+               state->w_ratio = *(RATIO*)(segment->value.variable.raw + 8);
+       } else if (segment->type == TADSEGMENT_TYPE_LANGCODE) {
+               memcpy(&state->lang, &segment->value.lang, sizeof(tadlangcode));
        }
        return 0;
 }
index 6b1942d..7ead10b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * texteditor_characterstate.h
  *
- * Copyright (c) 2013 project bchan
+ * Copyright (c) 2013-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
  */
 
 #include    <basic.h>
+#include       <btron/dp.h>
+#include    <tad.h>
 
-#include       <tad/tadfragment.h>
+#include       <tad/tadsegment.h>
 #include       <tad/tadlangcode.h>
 
 #ifndef __TEXTEDITOR_CHARACTERSTATE_H__
@@ -42,7 +44,7 @@ typedef struct texteditor_characterstate_t_ texteditor_characterstate_t;
 
 IMPORT VOID texteditor_characterstate_initialize(texteditor_characterstate_t *state);
 IMPORT VOID texteditor_characterstate_finalize(texteditor_characterstate_t *state);
-IMPORT W texteditor_charactorstate_input(texteditor_characterstate_t *state, tadfragment_cursor_segment *segment);
+IMPORT W texteditor_charactorstate_input(texteditor_characterstate_t *state, tadsegment *segment);
 IMPORT Bool texteditor_characterstate_ishankaku(texteditor_characterstate_t *state);
 IMPORT W texteditor_characterstate_getlang(texteditor_characterstate_t *state, TC *str, W len);
 IMPORT VOID texteditor_characterstate_getlangcode(texteditor_characterstate_t *state, tadlangcode *lang);
index 71565e8..1ea2218 100644 (file)
@@ -29,6 +29,7 @@
 #include       <bstdio.h>
 
 #include       <tad/tadfragment.h>
+#include       <tad/tadsegment.h>
 #include       "texteditor_characterstate.h"
 #include       "texteditor_insertfilter.h"
 
@@ -70,7 +71,7 @@ EXPORT VOID texteditor_textfragment_finalize(texteditor_textfragment_t *fragment
 LOCAL W texteditor_insertcontext_bufferprepair(tadfragment_cursor_t *src, texteditor_characterstate_t *state, tadfragment_cursor_t *dest, W pos)
 {
        W i, err;
-       tadfragment_cursor_segment segment;
+       tadsegment segment;
 
        i = 0;
        for (; i < pos;) {
@@ -80,11 +81,11 @@ LOCAL W texteditor_insertcontext_bufferprepair(tadfragment_cursor_t *src, texted
                }
                texteditor_charactorstate_input(state, &segment);
 
-               if (segment.type == TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR) {
+               if (segment.type == TADSEGMENT_TYPE_CHARACTOR) {
                        i++;
                }
 
-               err = tadfragment_cursor_insert(dest, segment.p, segment.len);
+               err = tadfragment_cursor_insertsegment(dest, &segment);
                if (err < 0) {
                        break;
                }
@@ -106,7 +107,7 @@ LOCAL W texteditor_insertcontext_bufferappend(texteditor_characterstate_t *state
 {
        texteditor_insertfilter_t filter;
        texteditor_insertfilter_result filter_result;
-       tadfragment_cursor_segment segment;
+       tadsegment segment;
        W err = 0;
        Bool cont;
 
@@ -132,7 +133,7 @@ LOCAL W texteditor_insertcontext_bufferappend(texteditor_characterstate_t *state
 
 LOCAL W texteditor_insertcontext_bufferafterappend(texteditor_characterstate_t *state, tadfragment_cursor_t *src, tadfragment_cursor_t *dest)
 {
-       tadfragment_cursor_segment segment;
+       tadsegment segment;
        W err = 0;
        Bool is_end;
 
@@ -148,7 +149,7 @@ LOCAL W texteditor_insertcontext_bufferafterappend(texteditor_characterstate_t *
                }
                texteditor_charactorstate_input(state, &segment);
 
-               err = tadfragment_cursor_insert(dest, segment.p, segment.len);
+               err = tadfragment_cursor_insertsegment(dest, &segment);
                if (err < 0) {
                        break;
                }
index 1015167..f7d5cfe 100644 (file)
@@ -34,6 +34,7 @@
 #include    <coll/wordarray.h>
 #include    "tadlexer_le.h"
 #include    "tadlangcode.h"
+#include    "tadsegment.h"
 
 #ifdef BCHAN_CONFIG_DEBUG
 # define DP(arg) printf arg
@@ -478,16 +479,30 @@ EXPORT W tadfragment_cursor_insertlang(tadfragment_cursor_t *cursor, tadlangcode
        return err;
 }
 
+EXPORT W tadfragment_cursor_insertsegment(tadfragment_cursor_t *cursor, tadsegment *segment)
+{
+       switch (segment->type) {
+       case TADSEGMENT_TYPE_VARIABLE:
+               return tadfragment_cursor_insert(cursor, segment->value.variable.raw, segment->value.variable.rawlen);
+       case TADSEGMENT_TYPE_CHARACTOR:
+               return tadfragment_cursor_insert(cursor, (UB*)&segment->value.ch, sizeof(TC));
+       case TADSEGMENT_TYPE_LANGCODE:
+               return tadfragment_cursor_insertlang(cursor, &segment->value.lang);
+       }
+       return -1;
+}
+
 EXPORT Bool tadfragment_cursor_isend(tadfragment_cursor_t *cursor)
 {
        return wordarray_cursor_isend(&cursor->base);
 }
 
-EXPORT W tadfragment_cursor_getdata(tadfragment_cursor_t *cursor, tadfragment_cursor_segment *p)
+EXPORT W tadfragment_cursor_getdata(tadfragment_cursor_t *cursor, tadsegment *p)
 {
        Bool end;
-       W offset, offset_next, err;
+       W offset, offset_next, len, err;
        UH ch;
+       TC *buffer;
 
        end = tadfragment_cursor_isend(cursor);
        if (end != False) {
@@ -503,16 +518,27 @@ EXPORT W tadfragment_cursor_getdata(tadfragment_cursor_t *cursor, tadfragment_cu
                return err;
        }
 
-       p->p = bytearray_getbuffer(&cursor->target->rawdata) + offset;
-       p->len = offset_next - offset;
+       buffer = (TC*)(bytearray_getbuffer(&cursor->target->rawdata) + offset);
+       len = (offset_next - offset) / sizeof(TC);
 
-       ch = *(UH*)p->p;
+       if (len < 1) {
+               return -1;
+       }
+
+       ch = buffer[0];
        if ((ch & 0xFF80) == 0xFF80) {
-               p->type = TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE;
+               p->type = TADSEGMENT_TYPE_VARIABLE;
+               p->value.variable.raw = (UB*)buffer;
+               p->value.variable.rawlen = len * sizeof(TC);
        } else if ((ch & 0xFE00) == 0xFE00) {
-               p->type = TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE;
+               err = TCtotadlangcode(buffer, len, &p->value.lang);
+               if (err < 0) {
+                       return err;
+               }
+               p->type = TADSEGMENT_TYPE_LANGCODE;
        } else {
-               p->type = TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR;
+               p->type = TADSEGMENT_TYPE_CHARACTOR;
+               p->value.ch = buffer[0];
        }
 
        return 0;
index 7468ef0..f7b626e 100644 (file)
@@ -35,6 +35,7 @@
 #include    <coll/bytearray.h>
 #include    <coll/wordarray.h>
 #include    "tadlangcode.h"
+#include    "tadsegment.h"
 
 #ifndef __TADFRAGMENT_H__
 #define __TADFRAGMENT_H__
@@ -55,20 +56,6 @@ struct tadfragment_cursor_t_ {
 };
 typedef struct tadfragment_cursor_t_ tadfragment_cursor_t;
 
-/* Functionality name: tadfragment */
-/* Detail name: cursor */
-/* Data structure identifier: segment */
-struct tadfragment_cursor_segment_ {
-       enum TADFRAGMENT_CURSOR_SEGMENTTYPE {
-               TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE,
-               TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR,
-               TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE,
-       } type;
-       UB *p;
-       W len;
-};
-typedef struct tadfragment_cursor_segment_ tadfragment_cursor_segment;
-
 IMPORT W tadfragment_initialize(tadfragment_t *fragment);
 IMPORT VOID tadfragment_finalize(tadfragment_t *fragment);
 IMPORT UB* tadfragment_getbuffer(tadfragment_t *fragment);
@@ -84,7 +71,8 @@ IMPORT W tadfragment_cursor_move(tadfragment_cursor_t *cursor, W diff);
 IMPORT W tadfragment_cursor_erase(tadfragment_cursor_t *cursor, W len);
 IMPORT W tadfragment_cursor_insert(tadfragment_cursor_t *cursor, UB *data, W len);
 IMPORT W tadfragment_cursor_insertlang(tadfragment_cursor_t *cursor, tadlangcode *lang);
+IMPORT W tadfragment_cursor_insertsegment(tadfragment_cursor_t *cursor, tadsegment *segment);
 IMPORT Bool tadfragment_cursor_isend(tadfragment_cursor_t *cursor);
-IMPORT W tadfragment_cursor_getdata(tadfragment_cursor_t *cursor, tadfragment_cursor_segment *p);
+IMPORT W tadfragment_cursor_getdata(tadfragment_cursor_t *cursor, tadsegment *p);
 
 #endif
index 557bc3e..d5efd24 100644 (file)
@@ -34,6 +34,7 @@
 #include       <tcode.h>
 
 #include "tadlangcode.h"
+#include "tadsegment.h"
 
 #include    <unittest_driver.h>
 
@@ -739,7 +740,13 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_insertlang_5()
        return test_tadfragment_cursor_insertlang_common(&testdata);
 }
 
-LOCAL Bool test_tadfragment_common_verify_segment(tadfragment_cursor_segment *segment, tadfragment_cursor_segment *expected)
+typedef struct {
+       W type;
+       TC *data;
+       W len;
+} test_tadsegment_expected_t;
+
+LOCAL Bool test_tadfragment_common_verify_segment(tadsegment *segment, test_tadsegment_expected_t *expected)
 {
        Bool result = True;
 
@@ -747,21 +754,40 @@ LOCAL Bool test_tadfragment_common_verify_segment(tadfragment_cursor_segment *se
                printf("segment type fail: expected = %d, result = %d\n", expected->type, segment->type);
                result = False;
        }
-       if (segment->len != expected->len) {
-               printf("segment length fail: expected = %d, result = %d\n", expected->len, segment->len);
-               result = False;
-       }
-       if (memcmp(segment->p, expected->p, segment->len) != 0) {
-               printf("segment data fail\n");
+       switch (segment->type) {
+       case TADSEGMENT_TYPE_VARIABLE:
+               if (segment->value.variable.rawlen != expected->len * sizeof(TC)) {
+                       printf("segment length fail: expected = %d, result = %d\n", expected->len * sizeof(TC), segment->value.variable.rawlen);
+                       result = False;
+               }
+               if (memcmp(segment->value.variable.raw, expected->data, segment->value.variable.rawlen) != 0) {
+                       printf("segment data fail\n");
+                       result = False;
+               }
+               break;
+       case TADSEGMENT_TYPE_CHARACTOR:
+               if (expected->len != 1) {
+                       printf("charactor length fail\n");
+                       result = False;
+               } else if (segment->value.ch != expected->data[0]) {
+                       printf("charactor ch fail\n");
+                       result = False;
+               }
+               break;
+       case TADSEGMENT_TYPE_LANGCODE:
+               result = tadlangcodecmpTC(expected->data, expected->len, &segment->value.lang);
+               break;
+       default:
                result = False;
+               break;
        }
 
        return result;
 }
 
-LOCAL Bool test_tadfragment_common_verify_segments(tadfragment_cursor_t *cursor, tadfragment_cursor_segment *expected, W expected_len)
+LOCAL Bool test_tadfragment_common_verify_segments(tadfragment_cursor_t *cursor, test_tadsegment_expected_t *expected, W expected_len)
 {
-       tadfragment_cursor_segment segment;
+       tadsegment segment;
        W i, err;
        Bool result = True, verify;
 
@@ -796,7 +822,7 @@ LOCAL Bool test_tadfragment_common_verify_segments(tadfragment_cursor_t *cursor,
 typedef struct {
        TC *input;
        W input_len;
-       tadfragment_cursor_segment *expected;
+       test_tadsegment_expected_t *expected;
        W expected_len;
 } test_tadfragment_cursor_getdata_t;
 
@@ -837,10 +863,10 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_getdata_1()
 {
        TC input[] = {TK_A, TK_B, TK_C};
        W input_len = sizeof(input);
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_B}, 2},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_B}, 1},
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
        };
        W expected_len = 3;
        test_tadfragment_cursor_getdata_t testdata = {
@@ -854,10 +880,10 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_getdata_2()
 {
        TC input[] = {TK_A, 0xFF80, 0x0002, 0x0000, TK_C};
        W input_len = sizeof(input);
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB*)(TC[]){0xFF80, 0x0002, 0x0000}, 6},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+               {TADSEGMENT_TYPE_VARIABLE, (TC[]){0xFF80, 0x0002, 0x0000}, 3},
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
        };
        W expected_len = 3;
        test_tadfragment_cursor_getdata_t testdata = {
@@ -871,10 +897,10 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_getdata_3()
 {
        TC input[] = {TK_A, TK_B, 0xFE21};
        W input_len = sizeof(input);
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_B}, 2},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB*)(TC[]){0xFE21}, 2},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_B}, 1},
+               {TADSEGMENT_TYPE_LANGCODE, (TC[]){0xFE21}, 1},
        };
        W expected_len = 3;
        test_tadfragment_cursor_getdata_t testdata = {
@@ -888,10 +914,10 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_getdata_4()
 {
        TC input[] = {TK_A, 0xFEFE, 0xFE21, TK_C};
        W input_len = sizeof(input);
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB*)(TC[]){0xFEFE, 0xFE21}, 4},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+               {TADSEGMENT_TYPE_LANGCODE, (TC[]){0xFEFE, 0xFE21}, 2},
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
        };
        W expected_len = 3;
        test_tadfragment_cursor_getdata_t testdata = {
@@ -907,8 +933,8 @@ typedef struct {
        W erase_pos;
        W erase_len;
        Bool expected_pos_after_erase_is_end;
-       tadfragment_cursor_segment *expected_pos_after_erase;
-       tadfragment_cursor_segment *expected;
+       test_tadsegment_expected_t *expected_pos_after_erase;
+       test_tadsegment_expected_t *expected;
        W expected_len;
 } test_tadfragment_cursor_erase_t;
 
@@ -916,7 +942,7 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_erase_common(test_tadfragment_curs
 {
        tadfragment_t fragment;
        tadfragment_cursor_t cursor;
-       tadfragment_cursor_segment segment;
+       tadsegment segment;
        W err;
        Bool verify;
        UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
@@ -975,16 +1001,16 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_erase_1()
        TC input[] = {TK_A, 0xFF80, 0x0002, 0x0000, TK_C};
        W input_len = sizeof(input);
        Bool expected_pos_after_erase_is_end = False;
-       tadfragment_cursor_segment expected_pos_after_erase = {
-               TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE,
-               (UB*)(TC[]){0xFF80, 0x0002, 0x0000},
-               6
+       test_tadsegment_expected_t expected_pos_after_erase = {
+               TADSEGMENT_TYPE_VARIABLE,
+               (TC[]){0xFF80, 0x0002, 0x0000},
+               3
        };
        W erase_pos = 0;
        W erase_len = 1;
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB*)(TC[]){0xFF80, 0x0002, 0x0000}, 6},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_VARIABLE, (TC[]){0xFF80, 0x0002, 0x0000}, 3},
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
        };
        W expected_len = 2;
        test_tadfragment_cursor_erase_t testdata = {
@@ -1003,13 +1029,13 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_erase_2()
        W erase_pos = 0;
        W erase_len = 2;
        Bool expected_pos_after_erase_is_end = False;
-       tadfragment_cursor_segment expected_pos_after_erase = {
-               TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR,
-               (UB*)(TC[]){TK_C},
-               2
+       test_tadsegment_expected_t expected_pos_after_erase = {
+               TADSEGMENT_TYPE_CHARACTOR,
+               (TC[]){TK_C},
+               1
        };
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
        };
        W expected_len = 1;
        test_tadfragment_cursor_erase_t testdata = {
@@ -1028,9 +1054,9 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_erase_3()
        W erase_pos = 0;
        W erase_len = 3;
        Bool expected_pos_after_erase_is_end = True;
-       tadfragment_cursor_segment expected_pos_after_erase = {
+       test_tadsegment_expected_t expected_pos_after_erase = {
        };
-       tadfragment_cursor_segment expected[] = {
+       test_tadsegment_expected_t expected[] = {
        };
        W expected_len = 0;
        test_tadfragment_cursor_erase_t testdata = {
@@ -1049,9 +1075,9 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_erase_4()
        W erase_pos = 0;
        W erase_len = 4;
        Bool expected_pos_after_erase_is_end = True;
-       tadfragment_cursor_segment expected_pos_after_erase = {
+       test_tadsegment_expected_t expected_pos_after_erase = {
        };
-       tadfragment_cursor_segment expected[] = {
+       test_tadsegment_expected_t expected[] = {
        };
        W expected_len = 0;
        test_tadfragment_cursor_erase_t testdata = {
@@ -1070,14 +1096,14 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_erase_5()
        W erase_pos = 1;
        W erase_len = 1;
        Bool expected_pos_after_erase_is_end = False;
-       tadfragment_cursor_segment expected_pos_after_erase = {
-               TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR,
-               (UB*)(TC[]){TK_C},
-               2
+       test_tadsegment_expected_t expected_pos_after_erase = {
+               TADSEGMENT_TYPE_CHARACTOR,
+               (TC[]){TK_C},
+               1
        };
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
        };
        W expected_len = 2;
        test_tadfragment_cursor_erase_t testdata = {
@@ -1096,10 +1122,10 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_erase_6()
        W erase_pos = 1;
        W erase_len = 2;
        Bool expected_pos_after_erase_is_end = True;
-       tadfragment_cursor_segment expected_pos_after_erase = {
+       test_tadsegment_expected_t expected_pos_after_erase = {
        };
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
        };
        W expected_len = 1;
        test_tadfragment_cursor_erase_t testdata = {
@@ -1118,10 +1144,10 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_erase_7()
        W erase_pos = 1;
        W erase_len = 3;
        Bool expected_pos_after_erase_is_end = True;
-       tadfragment_cursor_segment expected_pos_after_erase = {
+       test_tadsegment_expected_t expected_pos_after_erase = {
        };
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
        };
        W expected_len = 1;
        test_tadfragment_cursor_erase_t testdata = {
@@ -1140,11 +1166,11 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_erase_8()
        W erase_pos = 2;
        W erase_len = 1;
        Bool expected_pos_after_erase_is_end = True;
-       tadfragment_cursor_segment expected_pos_after_erase = {
+       test_tadsegment_expected_t expected_pos_after_erase = {
        };
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB*)(TC[]){0xFF80, 0x0002, 0x0000}, 6},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+               {TADSEGMENT_TYPE_VARIABLE, (TC[]){0xFF80, 0x0002, 0x0000}, 3},
        };
        W expected_len = 2;
        test_tadfragment_cursor_erase_t testdata = {
@@ -1163,11 +1189,11 @@ LOCAL UNITTEST_RESULT test_tadfragment_cursor_erase_9()
        W erase_pos = 2;
        W erase_len = 2;
        Bool expected_pos_after_erase_is_end = True;
-       tadfragment_cursor_segment expected_pos_after_erase = {
+       test_tadsegment_expected_t expected_pos_after_erase = {
        };
-       tadfragment_cursor_segment expected[] = {
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
-               {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB*)(TC[]){0xFF80, 0x0002, 0x0000}, 6},
+       test_tadsegment_expected_t expected[] = {
+               {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+               {TADSEGMENT_TYPE_VARIABLE, (TC[]){0xFF80, 0x0002, 0x0000}, 3},
        };
        W expected_len = 2;
        test_tadfragment_cursor_erase_t testdata = {