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;
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);
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;
}
# 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;
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;
}
#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 {
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