Patch: Elm ME+ 2.5 PLalpha62 -> Elm ME+ 2.5 PLalpha63 [4/7] (6/7)
From
Kari Hurtta@21:1/5 to
All on Wed Jan 3 13:52:11 2024
[continued from previous message]
+ params->stack,params->stack_len,
+ i,
+ stack_enter_auto,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter)) {
+
+ tagfilter_free_stack_item(&
+ (params->stack[i]),
+ params->tagfilter);
+
+ reset_range = 1;
+
+ /* This left holes to stack if
+ all are not closed
+ */
+
+ if (params->stack_len == i+1) {
+ params->stack_len = i;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (new_item) {
+
+ if (TAGFILTER_STACK_ITEM_magic != new_item->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_tag",
+ "Bad magic number (tagfilter_stack_item)");
+
+ params->stack = safe_array_realloc(params->stack,
+ params->stack_len+1,
+ sizeof (params->stack[0]));
+
+ params->stack[params->stack_len] = NULL;
+
+ if (params->stack_len > stack_pos) {
+ size_t i;
+
+ for (i = params->stack_len; i > stack_pos; i--) {
+ params->stack[i] = params->stack[i-1];
+ params->stack[i-1] = NULL;
+ }
+ }
+ params->stack_len++;
+
+ if (NULL != params->stack[stack_pos])
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_tag",
+ "stack_pos not NULL");
+
+ params->stack[stack_pos] = new_item;
+
+ force_eoln = new_item->force_eoln;
+
+ } else if (tag_state) {
+
+ /* Handle case where need push implicit tags to stack -
+ last item is current stack item
+ */
+
+ struct tagfilter_stack_item * item2;
+
+ while (NULL != (item2 =
+ params->tagfilter->
+ push_stack_item(tag_state,
+ params->stack,
+ params->stack_len,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->decode_opt,
+ params->text_charset,
+ params->tagfilter))) {
+
+ if (TAGFILTER_STACK_ITEM_magic != item2->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_tag",
+ "Bad magic number ( tagfilter_stack_item)");
+
+ params->stack = safe_array_realloc(params->stack,
+ params->stack_len+1,
+ sizeof (params->stack[0])); + stack_pos = params->stack_len;
+ params->stack[params->stack_len++] = item2;
+
+ force_eoln = item2->force_eoln;
+
+ if (item2->range) {
+ tag_pg_flags = tagfilter_inherited_pg_flags(params);
+ tag_range = item2->range;
+
+ set_out_state_line_mode(params->state_out,tag_pg_flags,
+ tag_range,force_eoln);
+
+ reset_range = 0;
+ } else {
+ reset_range = 1;
+ }
+
+ new_item = item2;
+ }
+ }
+
+ if (params->stack && params->stack_len > 0) {
+ size_t idx = params->stack_len-1;
+
+ while (idx > 0 && ! params->stack[idx])
+ idx--;
+
+ if (params->stack[idx]) {
+
+ if (TAGFILTER_STACK_ITEM_magic != params->stack[idx]->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_tag",
+ "Bad magic number ( tagfilter_stack_item)");
+ force_eoln = params->stack[idx]->force_eoln;
+ }
+ }
+
+ if (!tag_range || reset_range) {
+
+ tag_pg_flags = tagfilter_inherited_pg_flags(params);
+ tag_range = tagfilter_inherited_pager_range(params);
+
+ set_out_state_line_mode(params->state_out,tag_pg_flags,
+ tag_range,force_eoln);
+ }
+
+ } else if (is_end_tag) { /* Not both is_start_tag and is_end_tag
+ which is <tag/>
+ */
+ int reset_range = 0;
+
+ tag_state =
+ params->tagfilter->
+ locate_stack_item(tag_name,
+ params->stack,params->stack_len,
+ &stack_pos,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+
+ if (tag_state) {
+ if (stack_pos+1 < params->stack_len) {
+ size_t i;
+
+ /* Handle case where need close tags from stack */
+
+ for (i = params->stack_len -1; i > stack_pos; i--) {
+
+ if (params->stack[i]) {
+
+ if (params->tagfilter->
+ close_stack_item(tag_state,
+ params->stack,params->stack_len,
+ i,
+ stack_close_auto,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter)) {
+
+ tagfilter_free_stack_item(&
+ (params->stack[i]),
+ params->tagfilter);
+
+ reset_range = 1;
+
+ /* This left holes to stack if
+ all are not closed
+ */
+
+ if (params->stack_len == i+1) {
+ params->stack_len = i;
+ }
+ }
+ }
+ }
+
+ }
+ }
+
+ if (!tag_range || reset_range) {
+
+ tag_pg_flags = tagfilter_inherited_pg_flags(params);
+ tag_range = tagfilter_inherited_pager_range(params);
+
+ set_out_state_line_mode(params->state_out,tag_pg_flags,
+ tag_range,force_eoln);
+ }
+
+ }
+
+
+ while (current_token_len >= 0) {
+
+ switch(params->current_token->token_class) {
+
+ case tf_tag_atrvalue_error:
+ case tf_tag_param_error:
+ case tf_tag_error:
+ case tf_entity_error:
+
+ /* Fail, if start of stack is seen */
+
+ case tf_start_tag:
+
+ if (0) {
+ case tf_start_endtag:
+ is_end_tag = 1;
+ }
+
+ goto fail_tag;
+
+ case tf_tag_space:
+ if (attribute_state)
+ params->tagfilter->end_attribute(&attribute_state,
+ tag_state,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+ break;
+ case tf_tag_atrname:
+ if (attribute_state) /* Should not happen */
+ params->tagfilter->end_attribute(&attribute_state,
+ tag_state,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+
+ if (tag_state && params->current_token->atr_name)
+ attribute_state =
+ params->tagfilter->
+ start_attribute(params->current_token->atr_name,
+ tag_state,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+ break;
+
+ case tf_tag_atrequal:
+ break;
+ case tf_tag_atrvalue_start:
+ if (tag_state && attribute_state)
+ params->tagfilter->
+ start_end_atrvalue(attribute_state,
+ atrvalue_start,
+ tag_state,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+ break;
+
+ case tf_tag_atrvalue_end:
+ if (tag_state && attribute_state)
+ params->tagfilter->
+ start_end_atrvalue(attribute_state,
+ atrvalue_end,
+ tag_state,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+ break;
+ case tf_tag_atrvalue_segment:
+ if (tag_state && attribute_state &&
+ params->current_token->atr_value_segment)
+ params->tagfilter->
+ atrvalue_seg_string(attribute_state,
+ params->current_token->
+ atr_value_segment,
+ tag_state,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+ break;
+
+ case tf_entity:
+ if (tag_state && attribute_state &&
+ params->current_token->sbuffer &&
+ params->current_token->match_reference) {
+
+ struct out_entity * oe =
+ out_entity_from_match(params->current_token->sbuffer,
+ params->current_token->
+ match_reference,
+ pg_REVERSE);
+ params->tagfilter->
+ atrvalue_seg_ent(attribute_state,oe,
+ tag_state,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+ free_out_entity(&oe);
+ }
+ break;
+
+ case tf_numeric_entity:
+ if (tag_state && attribute_state &&
+ params->current_token->sbuffer) {
+ struct out_entity * oe =
+ new_out_entity(params->current_token->sbuffer,
+ NULL,
+ params->current_token->
+ numeric_reference,
+ pg_REVERSE);
+ params->tagfilter->
+ atrvalue_seg_ent(attribute_state,oe,
+ tag_state,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+ free_out_entity(&oe);
+ }
+ break;
+
+ case tf_whole_tag:
+ case tf_tag_end:
+ tag_ok = 1;
+ tag_end_seen = 1;
+ break;
+
+
+ case tf_whole_endtag:
+ case tf_tag_selfclosed_end:
+ case tf_selfclosed_tag:
+ is_end_tag = 1;
+ tag_ok = 1;
+ tag_end_seen = 1;
+ break;
+
+ default:
+ goto fail_tag;
+ }
+
+ tagfilter_collect_token(params,&collected_tag,&truncated_tag);
+
+ current_token_len =
+ get_new_tagfilter_token(params->current_token,
+ params->tagfilter,
+ params->state_in);
+
+ if (tag_end_seen)
+ goto exit_tag2;
+
+ }
+
+ if (!tag_ok) {
+ int pg_flags;
+
+ /* Error message? */
+
+ fail_tag:
+
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_tag: FAIL current token len = %d, class = %d %s\n",
+ current_token_len,params->current_token->token_class, + token_class_string(params->current_token->token_class)));
+ if (params->current_token->sbuffer) {
+ DEBUG_PRINT_STRING(Debug,20,
+ "tagfilter_handle_tag: current token = ",
+ "tagfilter_handle_tag: current token > ",
+ params->current_token->sbuffer);
+ }
+
+ pg_flags = pg_UNDERLINE;
+
+ set_out_state_line_mode(params->state_out,pg_flags,
+ tag_range,0 );
+
+ if (collected_tag)
+ state_putstring(collected_tag,params->state_out);
+
+ switch (truncated_tag) {
+ case collect_nl_tag:
+ state_putc('\n',params->state_out);
+
+ set_out_state_line_mode(params->state_out,pg_flags,
+ tag_range,0 );
+ break;
+
+ case collect_nl_truncated_tag:
+ state_putc('\n',params->state_out);
+
+ /* FALLTRU */
+ case collect_truncated_tag:
+
+ set_out_state_line_mode(params->state_out,pg_BOLD|pg_flags,
+ tag_range,0 );
+ state_puts(" ... ",params->state_out);
+
+ /* Does not change if not EOLN */
+ set_out_state_line_pg_flags(params->state_out,pg_flags);
+ break;
+ case collect_full_tag:
+ break;
+ }
+
+ while (current_token_len >= 0) {
+
+ switch(params->current_token->token_class) {
+
+ case tf_tag_atrvalue_error:
+ case tf_tag_param_error:
+ case tf_tag_error:
+ case tf_entity_error:
+ case tf_start_tag:
+ case tf_whole_tag:
+ case tf_selfclosed_tag:
+ case tf_start_endtag:
+ case tf_whole_endtag:
+ case tf_entity:
+ case tf_numeric_entity:
+ case tf_tag_space:
+ case tf_tag_atrname:
+ case tf_tag_selfclosed_end:
+ case tf_tag_end:
+ case tf_tag_atrequal:
+ case tf_tag_atrvalue_start:
+ case tf_tag_atrvalue_segment:
+ case tf_tag_atrvalue_end:
+
+ if (tf_whole_tag == params->current_token->token_class || + tf_selfclosed_tag == params->current_token->token_class || + tf_whole_endtag == params->current_token->token_class || + tf_tag_selfclosed_end == params->current_token->token_class ||
+ tf_tag_end == params->current_token->token_class)
+ tag_end_seen = 1;
+
+ tagfilter_dump_token(params,pg_flags);
+
+ current_token_len =
+ get_new_tagfilter_token(params->current_token,
+ params->tagfilter,
+ params->state_in);
+
+
+ if (tag_end_seen)
+ goto exit_tag;
+
+ break;
+ default:
+ goto exit_tag;
+ }
+
+ }
+
+ exit_tag:
+
+ /* Should not cause newline */
+ if (pg_flags || tag_range || tag_pg_flags) {
+ set_out_state_line_mode(params->state_out,tag_pg_flags,
+ tag_range,0 );
+ }
+
+ }
+
+ exit_tag2:
+ if (! is_end_tag && tag_state) {
+ if (TAGFILTER_TAG_STATE_magic != tag_state->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_free_tag_state_common",
+ "Bad magic number (tagfilter_tag_state)");
+
+ is_end_tag = tag_state->no_context;
+ }
+
+
+ if (is_end_tag && stack_pos < params->stack_len && tag_state) {
+
+ if (params->stack[stack_pos]) {
+
+ if (params->tagfilter->
+ close_stack_item(tag_state,
+ params->stack,params->stack_len,
+ stack_pos,
+ stack_pos +1 < params->stack_len ?
+ stack_close_middle : stack_close_end,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter)) {
+
+ tagfilter_free_stack_item(& (params->stack[stack_pos]),
+ params->tagfilter
+ );
+
+ /* This left holes to stack if
+ all are not closed
+ */
+
+ if (params->stack_len == stack_pos+1) {
+ params->stack_len = stack_pos;
+ }
+ }
+ }
+ }
+
+ if (attribute_state) /* Should not happen */
+ params->tagfilter->end_attribute(&attribute_state,
+ tag_state,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+
+ if (tag_state)
+ params->tagfilter->end_tag_state(&tag_state,
+ params->body,
+ params->state_in,
+ params->state_out,
+ params->text_charset,
+ params->tagfilter);
+
+ if (tag_name)
+ free_string(& tag_name);
+
+ if (collected_tag)
+ free_string(& collected_tag);
+
+
+ tag_pg_flags = tagfilter_inherited_pg_flags(params);
+ tag_range = tagfilter_inherited_pager_range(params);
+
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_tag: After tag pg_flags %d %s\n",
+ tag_pg_flags,
+ give_pg_flags(tag_pg_flags)));
+
+ set_out_state_line_mode(params->state_out,tag_pg_flags,
+ tag_range,force_eoln);
+
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_tag: END current token len = %d, class = %d %s\n",
+ current_token_len,params->current_token->token_class,
+ token_class_string(params->current_token->token_class))); + if (params->current_token->sbuffer) {
+ DEBUG_PRINT_STRING(Debug,20,
+ "tagfilter_handle_tag: current token = ",
+ "tagfilter_handle_tag: current token > ",
+ params->current_token->sbuffer);
+ }
+
+
+ return current_token_len;
+ }
+
+
+ /* Returns current_token_len -- */
+
+ static int tagfilter_handle_bcomment P_((struct tagfilter_params *params,
+ int current_token_len));
+
+ static int tagfilter_handle_bcomment(params,current_token_len)
+ struct tagfilter_params * params;
+ int current_token_len;
+ {
+ struct string * collected_tag = NULL;
+ enum collect_truncated truncated_tag = collect_full_tag;
+ int end_seen = 0;
+ int inherit_pg_flags;
+ struct pager_range *inherit;
+ int idx = 0;
+
+ /* Bocus comment */
+
+ if (TAGFILTER_PARAMS_magic != params->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_bcomment",
+ "Bad magic number");
+
+ if (TAGFILTER_SELECTION_magic != params->tagfilter->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_bcomment",
+ "Bad magic number (tagfilter_selection)");
+
+ if (TAGFILTER_TOKEN_magic != params->current_token->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_bcomment",
+ "Bad magic number (tagfilter_token)");
+
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_bcomment: START current token len = %d, class = %d %s\n",
+ current_token_len,params->current_token->token_class,
+ token_class_string(params->current_token->token_class))); + if (params->current_token->sbuffer) {
+ DEBUG_PRINT_STRING(Debug,20,
+ "tagfilter_handle_bcomment: current token = ",
+ "tagfilter_handle_bcomment: current token > ",
+ params->current_token->sbuffer);
+ }
+
+
+ inherit_pg_flags = tagfilter_inherited_pg_flags(params);
+ inherit = tagfilter_inherited_pager_range(params);
+
+ while (current_token_len >= 0) {
+ idx++;
+
+ switch(params->current_token->token_class) {
+ case tf_bcomment_error:
+ goto fail_bcomment;
+
+ case tf_bcomment_start:
+ if (idx > 1)
+ goto fail_bcomment;
+ /* FALLTRU */
+ case tf_bcomment_chunk:
+
+ tagfilter_collect_token(params,&collected_tag,&truncated_tag);
+
+ current_token_len =
+ get_new_tagfilter_token(params->current_token,
+ params->tagfilter,
+ params->state_in);
+ break;
+
+ case tf_bcomment_end:
+ end_seen = 1;
+ tagfilter_collect_token(params,&collected_tag,&truncated_tag);
+
+ current_token_len =
+ get_new_tagfilter_token(params->current_token,
+ params->tagfilter,
+ params->state_in);
+
+
+ goto exit2_bcomment;
+ default:
+ goto fail_bcomment;
+ }
+ }
+
+ if (!end_seen) {
+ int pg_flags;
+
+ /* Error message? */
+ fail_bcomment:
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_bcomment: FAIL current token len = %d, class = %d %s\n",
+ current_token_len,params->current_token->token_class, + token_class_string(params->current_token->token_class)));
+ if (params->current_token->sbuffer) {
+ DEBUG_PRINT_STRING(Debug,20,
+ "tagfilter_handle_bcomment: current token = ",
+ "tagfilter_handle_bcomment: current token > ",
+ params->current_token->sbuffer);
+ }
+
+ pg_flags = pg_UNDERLINE;
+
+ set_out_state_line_mode(params->state_out,pg_flags,
+ inherit,0 );
+
+ if (collected_tag)
+ state_putstring(collected_tag,params->state_out);
+
+ switch (truncated_tag) {
+ case collect_nl_tag:
+ state_putc('\n',params->state_out);
+
+ set_out_state_line_mode(params->state_out,pg_flags,
+ inherit,0 );
+ break;
+
+ case collect_nl_truncated_tag:
+ state_putc('\n',params->state_out);
+
+ /* FALLTRU */
+ case collect_truncated_tag:
+
+ set_out_state_line_mode(params->state_out,pg_BOLD|pg_flags,
+ inherit,0 );
+ state_puts(" ... ",params->state_out);
+
+ /* Does not change if not EOLN */
+ set_out_state_line_pg_flags(params->state_out,pg_flags);
+ break;
+ case collect_full_tag:
+ break;
+ }
+
+ while (current_token_len >= 0) {
+
+ switch(params->current_token->token_class) {
+ case tf_bcomment_end:
+ end_seen = 1;
+ /* FALLTHRU */
+ case tf_bcomment_error:
+ case tf_bcomment_start: /* <? or <! or </ */
+ case tf_bcomment_chunk: /* <? bogus comment chunk */
+
+ tagfilter_dump_token(params,pg_flags);
+
+ current_token_len =
+ get_new_tagfilter_token(params->current_token,
+ params->tagfilter,
+ params->state_in);
+
+
+ if (end_seen)
+ goto exit_bcomment;
+
+ break;
+ default:
+ goto exit_bcomment;
+ }
+ }
+
+ exit_bcomment:
+ /* Should not cause newline */
+ if (pg_flags || inherit || inherit_pg_flags) {
+ set_out_state_line_mode(params->state_out,inherit_pg_flags,
+ inherit,0 );
+ }
+
+ }
+
+ exit2_bcomment:
+ if (collected_tag)
+ free_string(& collected_tag);
+
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_bcomment: END current token len = %d, class = %d %s\n",
+ current_token_len,params->current_token->token_class,
+ token_class_string(params->current_token->token_class))); + if (params->current_token->sbuffer) {
+ DEBUG_PRINT_STRING(Debug,20,
+ "tagfilter_handle_bcomment: current token = ",
+ "tagfilter_handle_bcomment: current token > ",
+ params->current_token->sbuffer);
+ }
+
+ return current_token_len;
+ }
+
+ static int tagfilter_handle_span_nl P_((struct tagfilter_params *params,
+ int current_token_len));
+
+ static int tagfilter_handle_span_nl(params,current_token_len)
+ struct tagfilter_params * params;
+ int current_token_len;
+ {
+ /* text/enriched */
+
+ int inherit_pg_flags;
+ struct pager_range *inherit;
+
+ int text_visible = 1;
+
+ /* Bocus comment */
+
+ if (TAGFILTER_PARAMS_magic != params->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_span_nl",
+ "Bad magic number");
+
+ if (TAGFILTER_SELECTION_magic != params->tagfilter->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_span_nl",
+ "Bad magic number (tagfilter_selection)");
+
+ if (TAGFILTER_TOKEN_magic != params->current_token->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_span_nl",
+ "Bad magic number (tagfilter_token)");
+
+ if (params->stack && params->stack_len > 0) {
+ size_t idx = params->stack_len-1;
+
+ if (TAGFILTER_STACK_ITEM_magic != params->stack[idx]->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_span_nl",
+ "Bad magic number ( tagfilter_stack_item)");
+
+ text_visible = params->stack[idx]->text_visible;
+ }
+
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_span_nl: START current token len = %d, class = %d %s\n",
+ current_token_len,params->current_token->token_class,
+ token_class_string(params->current_token->token_class))); + if (params->current_token->sbuffer) {
+ DEBUG_PRINT_STRING(Debug,20,
+ "tagfilter_handle_span_nl: current token = ",
+ "tagfilter_handle_span_nl: current token > ",
+ params->current_token->sbuffer);
+ }
+
+ inherit_pg_flags = tagfilter_inherited_pg_flags(params);
+ inherit = tagfilter_inherited_pager_range(params);
+
+ /* Reset for newline chunk */
+
+ set_out_state_line_pager_range(params->state_out,NULL);
+
+ while (current_token_len >= 0) {
+
+ if (tf_span_nl != params->current_token->token_class)
+ goto out;
+
+ if (params->current_token->have_nl
+ && text_visible) /* Should not be set */
+ state_putc('\n',params->state_out);
+
+ if (params->current_token->sbuffer) { /* Should include only NL */
+
+ if (text_visible)
+ state_putstring(params->current_token->sbuffer,
+ params->state_out);
+ }
+
+ current_token_len =
+ get_new_tagfilter_token(params->current_token,
+ params->tagfilter,
+ params->state_in);
+ }
+
+ out:
+
+ if (inherit || inherit_pg_flags) {
+ set_out_state_line_mode(params->state_out,inherit_pg_flags,
+ inherit,0 );
+ }
+
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_span_nl: END current token len = %d, class = %d %s\n",
+ current_token_len,params->current_token->token_class,
+ token_class_string(params->current_token->token_class))); + if (params->current_token->sbuffer) {
+ DEBUG_PRINT_STRING(Debug,20,
+ "tagfilter_handle_span_nl: current token = ",
+ "tagfilter_handle_span_nl: current token > ",
+ params->current_token->sbuffer);
+ }
+
+ return current_token_len;
+ }
+
+
+ /* Returns current_token_len -- */
+
+ static int tagfilter_handle_comment P_((struct tagfilter_params *params,
+ int current_token_len));
+
+ static int tagfilter_handle_comment(params,current_token_len)
+ struct tagfilter_params * params;
+ int current_token_len;
+ {
+ struct string * collected_tag = NULL;
+ enum collect_truncated truncated_tag = collect_full_tag;
+ int end_seen = 0;
+ int inherit_pg_flags;
+ struct pager_range *inherit;
+ int idx = 0;
+
+ /* Real comment */
+
+ if (TAGFILTER_PARAMS_magic != params->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_comment",
+ "Bad magic number");
+
+ if (TAGFILTER_SELECTION_magic != params->tagfilter->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_comment",
+ "Bad magic number (tagfilter_selection)");
+
+ if (TAGFILTER_TOKEN_magic != params->current_token->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_handle_comment",
+ "Bad magic number (tagfilter_token)");
+
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_comment: START current token len = %d, class = %d %s\n",
+ current_token_len,params->current_token->token_class,
+ token_class_string(params->current_token->token_class))); + if (params->current_token->sbuffer) {
+ DEBUG_PRINT_STRING(Debug,20,
+ "tagfilter_handle_comment: current token = ",
+ "tagfilter_handle_comment: current token > ",
+ params->current_token->sbuffer);
+ }
+
+ inherit_pg_flags = tagfilter_inherited_pg_flags(params);
+ inherit = tagfilter_inherited_pager_range(params);
+
+ while (current_token_len >= 0) {
+ idx++;
+
+ switch(params->current_token->token_class) {
+ case tf_comment_error :
+ goto fail_comment;
+
+ case tf_comment_start:
+ if (idx > 1)
+ goto fail_comment;
+ /* FALLTRU */
+ case tf_comment_chunk:
+ tagfilter_collect_token(params,&collected_tag,&truncated_tag);
+
+ current_token_len =
+ get_new_tagfilter_token(params->current_token,
+ params->tagfilter,
+ params->state_in);
+ break;
+
+
+ case tf_whole_comment:
+ case tf_comment_end:
+ end_seen = 1;
+ tagfilter_collect_token(params,&collected_tag,&truncated_tag);
+
+ current_token_len =
+ get_new_tagfilter_token(params->current_token,
+ params->tagfilter,
+ params->state_in);
+
+ goto exit2_comment;
+
+ default:
+ goto fail_comment;
+ }
+ }
+
+ if (!end_seen) {
+ int pg_flags;
+
+ /* Error message? */
+ fail_comment:
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_comment: FAIL current token len = %d, class = %d %s\n",
+ current_token_len,params->current_token->token_class, + token_class_string(params->current_token->token_class)));
+ if (params->current_token->sbuffer) {
+ DEBUG_PRINT_STRING(Debug,20,
+ "tagfilter_handle_comment: current token = ",
+ "tagfilter_handle_comment: current token > ",
+ params->current_token->sbuffer);
+ }
+
+ pg_flags = pg_UNDERLINE;
+
+ set_out_state_line_mode(params->state_out,pg_flags,
+ inherit,0 );
+
+ if (collected_tag)
+ state_putstring(collected_tag,params->state_out);
+
+ switch (truncated_tag) {
+ case collect_nl_tag:
+ state_putc('\n',params->state_out);
+
+ set_out_state_line_mode(params->state_out,pg_flags,
+ inherit,0 );
+ break;
+
+ case collect_nl_truncated_tag:
+ state_putc('\n',params->state_out);
+
+ /* FALLTRU */
+ case collect_truncated_tag:
+
+ set_out_state_line_mode(params->state_out,pg_BOLD|pg_flags,
+ inherit,0 );
+ state_puts(" ... ",params->state_out);
+
+ /* Does not change if not EOLN */
+ set_out_state_line_pg_flags(params->state_out,pg_flags);
+ break;
+ case collect_full_tag:
+ break;
+ }
+
+ while (current_token_len >= 0) {
+
+ switch(params->current_token->token_class) {
+ case tf_whole_comment:
+ case tf_comment_end:
+ end_seen = 1;
+ /* FALLTHRU */
+ case tf_comment_error:
+ case tf_comment_start:
+ case tf_comment_chunk:
+ tagfilter_dump_token(params,pg_flags);
+
+ current_token_len =
+ get_new_tagfilter_token(params->current_token,
+ params->tagfilter,
+ params->state_in);
+
+
+ if (end_seen)
+ goto exit_comment;
+
+ break;
+ default:
+ goto exit_comment;
+ }
+ }
+
+ exit_comment:
+ /* Should not cause newline */
+ if (pg_flags || inherit || inherit_pg_flags) {
+ set_out_state_line_mode(params->state_out,inherit_pg_flags,
+ inherit,0 );
+ }
+
+ }
+
+ exit2_comment:
+ if (collected_tag)
+ free_string(& collected_tag);
+
+ DPRINT(Debug,20,(&Debug,
+ "tagfilter_handle_comment: END current token len = %d, class = %d %s\n",
+ current_token_len,params->current_token->token_class,
+ token_class_string(params->current_token->token_class))); + if (params->current_token->sbuffer) {
+ DEBUG_PRINT_STRING(Debug,20,
+ "tagfilter_handle_comment: current token = ",
+ "tagfilter_handle_comment: current token > ",
+ params->current_token->sbuffer);
+ }
+
+ return current_token_len;
+ }
+
+
+ void tagfilter_free_stack_item(item, tagfilter)
+ struct tagfilter_stack_item **item;
+ struct tagfilter_selection * tagfilter;
+ {
+ if (TAGFILTER_STACK_ITEM_magic != (*item)->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_decoder",
+ "Bad magic number ( tagfilter_stack_item)");
+
+ if (TAGFILTER_SELECTION_magic != tagfilter->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_free_stack_item",
+ "Bad magic number (tagfilter_selection)");
+
+
+ tagfilter->stack_item_clear(*item,tagfilter);
+
+ if ((*item)->range)
+ free_pager_range(& ((*item)->range));
+
+ if ((*item)->current_tag)
+ tagfilter_release_cmd(& ((*item)->current_tag));
+
+ (*item)->magic = 0;
+ free(*item);
+ (*item) = NULL;
+ }
+
+
+ void tagfilter_decoder(body,state_in,state_out,decode_opt,text_charset,tagfilter)
+ mime_t * body;
+ struct in_state * state_in;
+ struct out_state * state_out;
+ const struct decode_opts * decode_opt;
+ charset_t text_charset;
+ struct tagfilter_selection * tagfilter;
+ {
+ struct tagfilter_token current_token;
+ int current_token_len = -1; /* -1 on error or failure */
+
+ struct tagfilter_params params;
+ struct tagfilter_global counter;
+
+ int errors2 UNUSED_VAROK;
+ int errors3;
+ int error = 0;
+
+
+ struct tagfilter_stack_item * top_item;
+
+ struct pager_range *filter_message_range = NULL;
+
+
+ /* bzero is defined on hdrs/elm_defs.h */
+ bzero(&counter,sizeof counter);
+ counter = NULL_counter;
+
+ if (MIME_magic != body->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_decoder",
+ "Bad magic number (mime_t)");
+
+ if (TAGFILTER_SELECTION_magic != tagfilter->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_decoder",
+ "Bad magic number (tagfilter_selection)");
+
+ /* bzero is defined hdrs/elm_defs.h */
+ bzero((void *)¶ms,sizeof params);
+
+ tagfilter_token_init(¤t_token,text_charset);
+
+ params.magic = TAGFILTER_PARAMS_magic;
+ params.body = body;
+ params.state_in = state_in;
+ params.state_out = state_out;
+ params.decode_opt = decode_opt;
+ params.text_charset = text_charset;
+ params.tagfilter = tagfilter;
+ params.current_token = ¤t_token;
+ params.error = 0;
+ params.stack = NULL;
+ params.stack_len = 0;
+ params.counter = &counter;
+
+ current_token_len = get_new_tagfilter_token(¤t_token,
+ tagfilter,state_in);
+
+ if (current_token_len >= 0) {
+ struct pager_range *inherit
+ = tagfilter_inherited_pager_range(¶ms);
+
+ filter_message_range =
+ state_add_opcode_pager_range(state_out,
+ pr_opcode_pager_replace
+ /* Replace this on builtin
+ pager
+ */,
+ inherit,PR_MAX_WIDTH|PR_WORD_WRAP,
+ 0,0);
+
+ /* \n resets this */
+ set_out_state_line_mode(state_out,pg_BOLD,
+ filter_message_range,1 /* Newline */);
+
+ state_printf(state_out,
+ CATGETS(elm_msg_cat, MeSet,
+ MeTagFUnsupTagsFiltered,
[continued in next message]
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)