Word Unperfect
public
Read
Owner: themaster
Branch: main
Commits: 0
Git CLI clone URL
git clone https://www.xt-emporium.com/git/word-unperfect.git
Fullscreen desktop URL
Code
Commits
History
Branches
Bug Reports
Discussions
Compare
Settings
word-unperfect
/
rev
/
wp_format_gate.c
File editor
#include "wp_format_gate.h" #include <string.h> static uint8_t wp_gate_selector(const WpLayoutGlobals *wl) { return wl != NULL && wl->scratch_byte_7eae != 0U ? wl->scratch_byte_7eae : 0x20U; } void wp_format_gate_slot_clear(WpFormatGateSlot *slot) { if (slot != NULL) { memset(slot, 0, sizeof(*slot)); } } void wp_format_gate_result_clear(WpFormatGateResult *result) { if (result != NULL) { memset(result, 0, sizeof(*result)); } } void wp_format_gate_result_merge(WpFormatGateResult *dst, const WpFormatGateResult *src) { if (dst == NULL || src == NULL) { return; } dst->new_slot = src->new_slot; dst->new_parser_runtime_flags = src->new_parser_runtime_flags; dst->new_secondary_stream_flags = src->new_secondary_stream_flags; dst->new_runtime_flags = src->new_runtime_flags; dst->new_layout_refcount = src->new_layout_refcount; dst->new_fmt_gate = src->new_fmt_gate; if (src->selector != 0U) { dst->selector = src->selector; } if (src->token != 0U) { dst->token = src->token; } if (src->glyph_request_tag != 0U) { dst->glyph_request_tag = src->glyph_request_tag; } dst->init_calls += src->init_calls; dst->slot_zeroes += src->slot_zeroes; dst->gate_reuses += src->gate_reuses; dst->glyph_rule_calls += src->glyph_rule_calls; dst->glyph_load_setups += src->glyph_load_setups; dst->video_patches += src->video_patches; dst->overlay_polls += src->overlay_polls; dst->aux_clears += src->aux_clears; dst->word_pair_inits += src->word_pair_inits; dst->display_routes += src->display_routes; dst->refcount_increments += src->refcount_increments; dst->counter_resets += src->counter_resets; dst->failfast_hints += src->failfast_hints; dst->high_scratch_gates += src->high_scratch_gates; dst->run_count_increments += src->run_count_increments; dst->word_pair_flag_sets += src->word_pair_flag_sets; dst->set_refcount_f8 += src->set_refcount_f8; dst->repeat_batches += src->repeat_batches; dst->repeat_iterations_requested += src->repeat_iterations_requested; dst->repeat_iterations_simulated += src->repeat_iterations_simulated; dst->parser_busy_skip = dst->parser_busy_skip || src->parser_busy_skip; dst->coalesced_repeat = dst->coalesced_repeat || src->coalesced_repeat; dst->glyph_counter_wrapped = dst->glyph_counter_wrapped || src->glyph_counter_wrapped; dst->gate_char_refcount_path = dst->gate_char_refcount_path || src->gate_char_refcount_path; } static bool wp_format_gate_begin(WpLayoutGlobals *wl, WpFormatGateSlot *slot, WpFormatGateResult *result) { if (result != NULL) { memset(result, 0, sizeof(*result)); } if (wl == NULL || slot == NULL || result == NULL) { return false; } result->old_slot = *slot; result->new_slot = *slot; result->old_parser_runtime_flags = wl->parser_runtime_flags; result->new_parser_runtime_flags = wl->parser_runtime_flags; result->old_secondary_stream_flags = wl->secondary_stream_flags_54a6; result->new_secondary_stream_flags = wl->secondary_stream_flags_54a6; result->old_runtime_flags = wl->runtime_flags; result->new_runtime_flags = wl->runtime_flags; result->old_layout_refcount = (int)wl->layout_refcount_44c6; result->new_layout_refcount = (int)wl->layout_refcount_44c6; result->old_fmt_gate = (uint8_t)(unsigned char)wl->fmt_gate_7ead; result->new_fmt_gate = (uint8_t)(unsigned char)wl->fmt_gate_7ead; return true; } static void wp_format_gate_finish(WpLayoutGlobals *wl, WpFormatGateSlot *slot, WpFormatGateResult *result) { if (wl == NULL || slot == NULL || result == NULL) { return; } result->new_slot = *slot; result->new_parser_runtime_flags = wl->parser_runtime_flags; result->new_secondary_stream_flags = wl->secondary_stream_flags_54a6; result->new_runtime_flags = wl->runtime_flags; result->new_layout_refcount = (int)wl->layout_refcount_44c6; result->new_fmt_gate = (uint8_t)(unsigned char)wl->fmt_gate_7ead; } bool wp_format_gate_init_slot(WpLayoutGlobals *wl, WpFormatGateSlot *slot, uint8_t selector, WpFormatGateResult *out_result) { WpFormatGateResult result; uint8_t chosen; if (!wp_format_gate_begin(wl, slot, &result)) { if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } return false; } chosen = selector != 0U ? selector : wp_gate_selector(wl); result.selector = chosen; result.init_calls = 1U; /* layout_init_fmt_gate_and_refcount zeros the five-byte gate slot only on * the first gate initialization. Later calls merely refresh the active * selector byte used by the formatter. */ if (wl->fmt_gate_7ead == 0) { wl->layout_refcount_44c6 = 0; wl->fmt_gate_7ead = (char)chosen; slot->selector = chosen; slot->lead_byte = 0U; slot->run_count = 0U; slot->age = 0; slot->flags = 0U; slot->payload_tag = 0U; result.slot_zeroes = 1U; } else { slot->selector = chosen; result.gate_reuses = 1U; } wp_format_gate_finish(wl, slot, &result); if (out_result != NULL) { *out_result = result; } return true; } bool wp_format_gate_increment_refcount_if_fmt_gate(WpLayoutGlobals *wl, WpFormatGateSlot *slot, WpFormatGateResult *out_result) { WpFormatGateResult result; WpFormatGateResult init_result; if (!wp_format_gate_begin(wl, slot, &result)) { if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } return false; } if (wl->fmt_gate_7ead != 0) { wl->layout_refcount_44c6++; result.refcount_increments = 1U; if (wp_format_gate_init_slot(wl, slot, wp_gate_selector(wl), &init_result)) { wp_format_gate_result_merge(&result, &init_result); } slot->age = 0; if (slot->run_count != 0U) { slot->run_count = 0U; result.counter_resets = 1U; result.overlay_polls = 1U; } } wp_format_gate_finish(wl, slot, &result); if (out_result != NULL) { *out_result = result; } return true; } bool wp_format_gate_apply_glyph_rules(WpLayoutGlobals *wl, WpFormatGateSlot *slot, WpFormatGateResult *out_result) { WpFormatGateResult result; int8_t next_age; if (!wp_format_gate_begin(wl, slot, &result)) { if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } return false; } result.glyph_rule_calls = 1U; next_age = (int8_t)(slot->age + 1); slot->age = next_age; if (next_age < 0) { result.glyph_counter_wrapped = true; } if (next_age >= 0 || wl->layout_refcount_44c6 != 0) { wp_format_gate_finish(wl, slot, &result); if (out_result != NULL) { *out_result = result; } return true; } if (slot->run_count == 0U) { result.glyph_load_setups = 1U; result.glyph_request_tag = (uint8_t)(wl->scratch_byte_7eae + 0x30U); slot->payload_tag = result.glyph_request_tag; if (wl->scratch_byte_7eae > 0xCFU) { result.high_scratch_gates = 1U; } else { result.video_patches = 1U; } } result.overlay_polls = 1U; if (result.high_scratch_gates == 0U) { slot->run_count = (uint16_t)(slot->run_count + 1U); slot->age = 0; result.run_count_increments = 1U; } else if (wl->gate_char_7eaf != 0) { WpFormatGateResult ref_result; result.gate_char_refcount_path = true; if (wp_format_gate_increment_refcount_if_fmt_gate(wl, slot, &ref_result)) { wp_format_gate_result_merge(&result, &ref_result); } } else { result.failfast_hints = 1U; } wp_format_gate_finish(wl, slot, &result); if (out_result != NULL) { *out_result = result; } return true; } bool wp_format_gate_aux_buffer_clear(WpLayoutGlobals *wl, WpFormatGateSlot *slot, WpFormatGateResult *out_result) { WpFormatGateResult result; WpFormatGateResult child; if (!wp_format_gate_begin(wl, slot, &result)) { if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } return false; } result.aux_clears = 1U; if (wl->layout_refcount_44c6 == 0) { if (wp_format_gate_init_slot(wl, slot, wp_gate_selector(wl), &child)) { wp_format_gate_result_merge(&result, &child); } if (wp_format_gate_apply_glyph_rules(wl, slot, &child)) { wp_format_gate_result_merge(&result, &child); } } wp_format_gate_finish(wl, slot, &result); if (out_result != NULL) { *out_result = result; } return true; } bool wp_format_gate_word_pair_init(WpLayoutGlobals *wl, WpFormatGateSlot *slot, WpFormatGateResult *out_result) { WpFormatGateResult result; WpFormatGateResult child; if (!wp_format_gate_begin(wl, slot, &result)) { if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } return false; } if (wl->layout_refcount_44c6 == 0) { result.word_pair_inits = 1U; if (wp_format_gate_init_slot(wl, slot, wp_gate_selector(wl), &child)) { wp_format_gate_result_merge(&result, &child); } if ((slot->flags & 0x02U) == 0U) { result.word_pair_flag_sets = 1U; } slot->flags |= 0x02U; } wp_format_gate_finish(wl, slot, &result); if (out_result != NULL) { *out_result = result; } return true; } bool wp_format_gate_display_string_or_status(WpLayoutGlobals *wl, WpFormatGateSlot *slot, uint8_t token, WpFormatGateResult *out_result) { WpFormatGateResult result; WpFormatGateResult child; uint8_t selector; if (!wp_format_gate_begin(wl, slot, &result)) { if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } return false; } result.token = token; result.display_routes = 1U; wl->parser_runtime_flags |= 0x08U; wl->secondary_stream_flags_54a6 |= 0x05U; wl->runtime_flags |= 0x08U; if (wl->layout_refcount_44c6 == 0 && (wl->parser_runtime_flags & 0x01U) == 0U) { selector = wp_gate_selector(wl); if (wp_format_gate_init_slot(wl, slot, selector, &child)) { wp_format_gate_result_merge(&result, &child); } if (slot->lead_byte != selector) { if (wp_format_gate_apply_glyph_rules(wl, slot, &child)) { wp_format_gate_result_merge(&result, &child); } } slot->lead_byte = selector; if (token > 0xF7U) { if (wp_format_gate_apply_glyph_rules(wl, slot, &child)) { wp_format_gate_result_merge(&result, &child); } slot->lead_byte = 0xF8U; result.set_refcount_f8 = 1U; } if (wp_format_gate_apply_glyph_rules(wl, slot, &child)) { wp_format_gate_result_merge(&result, &child); } } else if ((wl->parser_runtime_flags & 0x01U) != 0U) { result.parser_busy_skip = true; } wp_format_gate_finish(wl, slot, &result); if (out_result != NULL) { *out_result = result; } return true; } bool wp_format_gate_repeat_batch(WpLayoutGlobals *wl, WpFormatGateSlot *slot, size_t iterations, size_t simulation_limit, WpFormatGateResult *out_result) { WpFormatGateResult result; WpFormatGateResult child; size_t requested; size_t simulated; size_t i; size_t j; if (!wp_format_gate_begin(wl, slot, &result)) { if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } return false; } requested = iterations == 0U ? 1U : iterations; simulated = requested; if (simulation_limit != 0U && simulated > simulation_limit) { simulated = simulation_limit; result.coalesced_repeat = true; } result.repeat_batches = 1U; result.repeat_iterations_requested = requested; result.repeat_iterations_simulated = simulated; for (i = 0U; i < simulated; ++i) { wl->gate_char_7eaf = 1; for (j = 0U; j < 5U; ++j) { if (wp_format_gate_aux_buffer_clear(wl, slot, &child)) { wp_format_gate_result_merge(&result, &child); } } if (wp_format_gate_word_pair_init(wl, slot, &child)) { wp_format_gate_result_merge(&result, &child); } wl->gate_char_7eaf = 0; } wp_format_gate_finish(wl, slot, &result); if (out_result != NULL) { *out_result = result; } return true; }
Commit message
This repository is read-only for this account.
Repository snapshot
Current branch
main
Visibility
public
Your access
Read
Remote
None
File activity
View file history