OSDN Git Service

change stackfilter api.
authorornse01 <ornse01@users.sourceforge.jp>
Sat, 1 Nov 2014 14:41:29 +0000 (14:41 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Sat, 1 Nov 2014 14:41:29 +0000 (14:41 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchanf/trunk@634 20a0b8eb-f62a-4a12-8fe1-b598822500fb

src/control/test_texteditor_stackfilter.c
src/control/texteditor_insertfilter.c
src/control/texteditor_stackfilter.c
src/control/texteditor_stackfilter.h

index e994c3a..d4ec362 100644 (file)
@@ -50,6 +50,7 @@ typedef struct {
 LOCAL UNITTEST_RESULT test_texteditor_stackfilter_common(test_texteditor_stackfilter_testdata_t *testdata)
 {
        texteditor_stackfilter_t filter;
+       texteditor_stackfilterresult_t *filter_result;
        taddecoder_t decoder;
        tadsegment segment, *filterd;
        tadfragment_t fragment;
@@ -74,28 +75,18 @@ LOCAL UNITTEST_RESULT test_texteditor_stackfilter_common(test_texteditor_stackfi
                if (cont == False) {
                        break;
                }
-               input_result = texteditor_stackfilter_setinput(&filter, &segment);
-               if (input_result == TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_FULL) {
-                       for (;;) {
-                               cont = texteditor_stackfilter_getoutput(&filter, &filterd);
-                               if (cont == False) {
-                                       break;
-                               }
-                               tadfragment_cursor_insertsegment(&cursor, filterd);
-                       }
-                       input_result = texteditor_stackfilter_setinput(&filter, &segment);
-               }
-               if (input_result != TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_OK) {
+               input_result = texteditor_stackfilter_put(&filter, &segment, &filter_result);
+               if (input_result != TEXTEDITOR_STACKFILTER_PUT_RESULT_OK) {
                        result = UNITTEST_RESULT_FAIL;
                        break;
                }
-       }
-       for (;;) {
-               cont = texteditor_stackfilter_getoutput(&filter, &filterd);
-               if (cont == False) {
-                       break;
+               for (;;) {
+                       cont = texteditor_stackfilterresult_next(filter_result, &filterd);
+                       if (cont == False) {
+                               break;
+                       }
+                       tadfragment_cursor_insertsegment(&cursor, filterd);
                }
-               tadfragment_cursor_insertsegment(&cursor, filterd);
        }
        tadfragment_cursor_finalize(&cursor);
 
index 611d8c4..98c50f0 100644 (file)
@@ -125,13 +125,14 @@ LOCAL W texteditor_insertfilter_put_filtering(texteditor_insertfilter_t *filter,
        tadsegment *result;
        UB segid, subid, *segdata;
        UW seglen;
+       texteditor_stackfilterresult_t *stack_result;
 
-       ret = texteditor_stackfilter_setinput(&filter->stack, segment);
-       if (ret == TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_FORMAT_ERROR) {
+       ret = texteditor_stackfilter_put(&filter->stack, segment, &stack_result);
+       if (ret == TEXTEDITOR_STACKFILTER_PUT_RESULT_FORMAT_ERROR) {
                return TEXTEDITOR_INSERTFILTER_PUT_RESULT_FORMAT_ERROR;
        }
        for(;;) {
-               cont = texteditor_stackfilter_getoutput(&filter->stack, &result);
+               cont = texteditor_stackfilterresult_next(stack_result, &result);
                if (cont == False) {
                        break;
                }
index e5d31c1..763b7f3 100644 (file)
 # define DP_ER(msg, err) /**/
 #endif
 
-IMPORT W texteditor_stackfilter_setinput(texteditor_stackfilter_t *filter, tadsegment *segment)
+IMPORT W texteditor_stackfilter_put(texteditor_stackfilter_t *filter, tadsegment *segment, texteditor_stackfilterresult_t **result)
 {
        W nestlevel, err;
        TADSTACK_DATATYPE type;
-       TADSTACK_RESULT result;
+       TADSTACK_RESULT stack_result;
 
-       if (filter->state == TEXTEDITOR_STACKFILTER_STATE_HAS_RESULT) {
-               return TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_FULL;
-       }
-
-       result = tadstack_inputsegment(&filter->tadstack, segment);
+       stack_result = tadstack_inputsegment(&filter->tadstack, segment);
 
        nestlevel = tadstack_nestlevel(&filter->tadstack);
        if (nestlevel < 0) {
-               return TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_FORMAT_ERROR;
+               return TEXTEDITOR_STACKFILTER_PUT_RESULT_FORMAT_ERROR;
        }
        if (nestlevel > 0) {
-               return TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_OK;
+               return TEXTEDITOR_STACKFILTER_PUT_RESULT_OK;
        }
-       if (result == TADSTACK_RESULT_POP_STACK) {
-               return TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_OK;
+       if (stack_result == TADSTACK_RESULT_POP_STACK) {
+               return TEXTEDITOR_STACKFILTER_PUT_RESULT_OK;
        }
        err = tadstack_currentdata(&filter->tadstack, &type);
        if (err < 0) {
-               return TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_FORMAT_ERROR;
+               return TEXTEDITOR_STACKFILTER_PUT_RESULT_FORMAT_ERROR;
        }
        if (type != TADSTACK_DATATYPE_TEXT) {
-               return TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_OK;
+               return TEXTEDITOR_STACKFILTER_PUT_RESULT_OK;
        }
 
        filter->state = TEXTEDITOR_STACKFILTER_STATE_HAS_RESULT;
@@ -74,23 +70,19 @@ IMPORT W texteditor_stackfilter_setinput(texteditor_stackfilter_t *filter, tadse
        filter->result_buffer.used = 1;
        filter->result_buffer.consumed = 0;
 
-       return TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_OK;
+       *result = &filter->result_buffer;
+
+       return TEXTEDITOR_STACKFILTER_PUT_RESULT_OK;
 }
 
-IMPORT Bool texteditor_stackfilter_getoutput(texteditor_stackfilter_t *filter, tadsegment **segment)
+EXPORT Bool texteditor_stackfilterresult_next(texteditor_stackfilterresult_t *result, tadsegment **segment)
 {
-       if (filter->state == TEXTEDITOR_STACKFILTER_STATE_WAIT_INPUT) {
+       if (result->consumed >= result->used) {
                return False;
        }
 
-       *segment = filter->result_buffer.segs + filter->result_buffer.consumed;
-       filter->result_buffer.consumed++;
-
-       if (filter->result_buffer.consumed >= filter->result_buffer.used) {
-               filter->result_buffer.used = 0;
-               filter->result_buffer.consumed = 0;
-               filter->state = TEXTEDITOR_STACKFILTER_STATE_WAIT_INPUT;
-       }
+       *segment = result->segs + result->consumed;
+       result->consumed++;
 
        return True;
 }
index d9ea556..a45b69c 100644 (file)
 #define __TEXTEDITOR_STACKFILTER_H__
 
 /* Functionality name: texteditor */
+/* Detail name: stackfilterresult */
+struct texteditor_stackfilterresult_t_ {
+       tadsegment segs[1];
+       W used;
+       W consumed;
+};
+typedef struct texteditor_stackfilterresult_t_ texteditor_stackfilterresult_t;
+
+/* Functionality name: texteditor */
 /* Detail name: stackfilter */
 struct texteditor_stackfilter_t_ {
        enum {
@@ -40,20 +49,15 @@ struct texteditor_stackfilter_t_ {
                TEXTEDITOR_STACKFILTER_STATE_HAS_RESULT,
        } state;
        tadstack_t tadstack;
-       struct {
-               tadsegment segs[1];
-               W used;
-               W consumed;
-       } result_buffer;
+       texteditor_stackfilterresult_t result_buffer;
 };
 typedef struct texteditor_stackfilter_t_ texteditor_stackfilter_t;
 
 IMPORT VOID texteditor_stackfilter_initialize(texteditor_stackfilter_t *filter);
 IMPORT VOID texteditor_stackfilter_finalize(texteditor_stackfilter_t *filter);
-IMPORT W texteditor_stackfilter_setinput(texteditor_stackfilter_t *filter, tadsegment *segment);
-#define TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_OK (0)
-#define TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_FULL (1)
-#define TEXTEDITOR_STACKFILTER_SETINPUT_RESULT_FORMAT_ERROR (-1)
-IMPORT Bool texteditor_stackfilter_getoutput(texteditor_stackfilter_t *filter, tadsegment **segment);
+IMPORT W texteditor_stackfilter_put(texteditor_stackfilter_t *filter, tadsegment *segment, texteditor_stackfilterresult_t **result);
+#define TEXTEDITOR_STACKFILTER_PUT_RESULT_OK (0)
+#define TEXTEDITOR_STACKFILTER_PUT_RESULT_FORMAT_ERROR (-1)
+IMPORT Bool texteditor_stackfilterresult_next(texteditor_stackfilterresult_t *filter, tadsegment **segment);
 
 #endif