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_record_merge.c
File editor
#include "wp_record_merge.h" #include <string.h> static uint16_t wp_add_u16_with_carry(uint *low, uint *high, uint16_t amount, bool *carry_out) { uint16_t lo0; uint16_t lo1; bool carry; if (low == NULL || high == NULL) { if (carry_out != NULL) { *carry_out = false; } return 0; } lo0 = (uint16_t)(*low & 0xffffU); lo1 = (uint16_t)(lo0 + amount); carry = lo1 < lo0; *low = (uint)(uint16_t)lo1; *high = (uint)(uint16_t)((uint16_t)(*high & 0xffffU) + (carry ? 1U : 0U)); if (carry_out != NULL) { *carry_out = carry; } return lo1; } static uint16_t wp_sub_u16_with_borrow(uint *low, uint *high, uint16_t amount, bool *borrow_out) { uint16_t lo0; uint16_t lo1; bool borrow; if (low == NULL || high == NULL) { if (borrow_out != NULL) { *borrow_out = false; } return 0; } lo0 = (uint16_t)(*low & 0xffffU); lo1 = (uint16_t)(lo0 - amount); borrow = lo0 < amount; *low = (uint)(uint16_t)lo1; *high = (uint)(uint16_t)((uint16_t)(*high & 0xffffU) - (borrow ? 1U : 0U)); if (borrow_out != NULL) { *borrow_out = borrow; } return lo1; } static uint16_t wp_read_le16_unaligned(const uint8_t *p) { if (p == NULL) { return 0; } return (uint16_t)((uint16_t)p[0] | ((uint16_t)p[1] << 8)); } void wp_record_merge_result_clear(WpRecordMergeResult *result) { if (result != NULL) { memset(result, 0, sizeof(*result)); } } static bool wp_layout_merge_is_blocked(const WpLayoutGlobals *wl, WpRecordMergeResult *result) { if (wl == NULL) { return true; } if ((wl->emit_flags & 0x16U) != 0U) { if (result != NULL) { result->merge_skipped_emit_flags++; } return true; } if (wl->postprocess_mode > 0 && ((uint8_t)wl->postprocess_mode & 0x20U) == 0U) { if (result != NULL) { result->merge_skipped_postprocess++; } return true; } return false; } static uint8_t wp_metric_table_limit(const WpLayoutGlobals *wl, const uint8_t **table_out) { const uint8_t *table; if (table_out != NULL) { *table_out = NULL; } if (wl == NULL || wl->status_stream_gate_4987 == -1) { return 0; } if ((uintptr_t)wl->decode_slot_0002.word == (uintptr_t)0xffffU) { return 0; } table = (const uint8_t *)wl->decode_slot_0002.word; if (table == NULL) { return 0; } if (table_out != NULL) { *table_out = table; } return table[0]; } static uint16_t wp_metric_table_delta(const WpLayoutGlobals *wl, const uint8_t *table, uint8_t code_minus_space, WpRecordMergeResult *result) { uint16_t delta; if (table == NULL) { return (uint16_t)wl->span_metric_delta_4bda; } if (wl->decode_slot_0000.word == 0) { delta = (uint16_t)table[(size_t)code_minus_space + 1U]; if (result != NULL) { result->merge_table_byte_steps++; } } else { const uint8_t *entry = table + (((size_t)code_minus_space + 1U) * 2U); delta = wp_read_le16_unaligned(entry); if (result != NULL) { result->merge_table_word_steps++; } } return delta; } bool wp_record_merge_secondary_into_primary_cursor(WpLayoutGlobals *wl, WpRecordMergeResult *result) { uint8_t *src; uint8_t *dst; uint8_t table_limit; const uint8_t *table; uint16_t moved = 0; uint16_t remaining; uint16_t cursor; bool carry; if (result != NULL) { result->merge_calls++; } if (wp_layout_merge_is_blocked(wl, result)) { return false; } if (wl->secondary_record_used_bytes <= 0 || wl->secondary_record.as_secondary_p == NULL || wl->primary_record.as_record_p == NULL) { return false; } table_limit = wp_metric_table_limit(wl, &table); src = wl->secondary_record.as_secondary_p; dst = (uint8_t *)wl->primary_record.as_record_p; remaining = (uint16_t)wl->secondary_record_used_bytes; cursor = (uint16_t)wl->cursor; while (remaining != 0U) { uint8_t ch = *src; uint8_t code_minus_space; if (ch == 0U) { if (result != NULL) { result->merge_zero_stops++; } break; } code_minus_space = (uint8_t)(ch - 0x20U); if (code_minus_space == 0U) { uint16_t relative = (uint16_t)(cursor - (uint16_t)wl->line_start); if ((wl->update_depth == 0 && relative <= (uint16_t)wl->cursor_window) || (uint16_t)wl->measure_extent_bound_50c6 <= cursor) { if (result != NULL) { if ((uint16_t)wl->measure_extent_bound_50c6 <= cursor) { result->merge_extent_stops++; } else { result->merge_space_window_stops++; } } break; } cursor = (uint16_t)(cursor + (uint16_t)wl->span_metric_delta_4bd8); wl->processed_segments = (int)(wl->processed_segments + 1); wl->update_depth = (char)(wl->update_depth + 1); if (result != NULL) { result->merge_spaces_committed++; result->merge_last_metric = (uint16_t)wl->span_metric_delta_4bd8; } } else if (table_limit == 0U || table_limit < code_minus_space) { cursor = (uint16_t)(cursor + (uint16_t)wl->span_metric_delta_4bda); if (result != NULL) { result->merge_plain_metric_steps++; result->merge_last_metric = (uint16_t)wl->span_metric_delta_4bda; } } else { uint16_t delta = wp_metric_table_delta(wl, table, code_minus_space, result); cursor = (uint16_t)(cursor + (uint16_t)wl->span_table_ofs_4bdc + delta); if (result != NULL) { result->merge_last_metric = delta; } } *dst++ = ch; ++src; --remaining; ++moved; if (result != NULL) { result->merge_last_code = ch; } } if (moved == 0U) { return false; } wl->record_aux_4b34 += moved; wl->span_aux_word_53f6 = (uint16_t)(wl->span_aux_word_53f6 + moved); wl->cursor = cursor; wl->primary_record.as_record_p = (uint16_t *)dst; wl->secondary_record.as_secondary_p = src; wl->secondary_record_used_bytes -= moved; wl->record_used_bytes += moved; wp_add_u16_with_carry(&wl->position_gate_remaining_low, &wl->position_gate_remaining_high, moved, &carry); if (result != NULL) { result->merge_bytes += moved; result->merge_last_cursor = cursor; result->position_gate_increments += moved; if (carry) { result->position_gate_increment_carries++; } } return true; } bool wp_record_position_gate_advance_primary_to_secondary(WpLayoutGlobals *wl, WpRecordMergeResult *result) { uint8_t *src; uint8_t *dst; uint16_t remaining; uint16_t moved = 0; bool borrow; if (result != NULL) { result->advance_calls++; } if (wl == NULL || wl->record_used_bytes <= 0 || wl->primary_record.as_record_p == NULL || wl->secondary_record.as_secondary_p == NULL) { return false; } wl->runtime_flags |= 4U; if (result != NULL) { result->advance_runtime_flag_sets++; } src = (uint8_t *)wl->primary_record.as_record_p - 1; dst = wl->secondary_record.as_secondary_p - 1; remaining = (uint16_t)wl->record_used_bytes; while (remaining != 0U) { uint8_t ch = *src; if (ch == 0U) { if (result != NULL) { result->advance_zero_stops++; result->advance_last_code = ch; } break; } *dst = ch; if (result != NULL) { result->advance_last_code = ch; } ++moved; --remaining; --src; --dst; } if (moved == 0U) { return false; } wl->primary_record.as_record_p = (uint16_t *)((uint8_t *)wl->primary_record.as_record_p - moved); wl->secondary_record.as_secondary_p -= moved; wl->record_used_bytes -= moved; wl->secondary_record_used_bytes += moved; wp_sub_u16_with_borrow(&wl->position_gate_remaining_low, &wl->position_gate_remaining_high, moved, &borrow); if (result != NULL) { result->advance_bytes += moved; result->position_gate_decrements += moved; if (borrow) { result->position_gate_decrement_borrows++; } } return true; } uint32_t __cdecl16near layout_merge_secondary_into_primary_cursor(WpLayoutGlobals *wl) { (void)wp_record_merge_secondary_into_primary_cursor(wl, NULL); return 0; } void __cdecl16near layout_position_gate_advance_helper(WpLayoutGlobals *wl) { (void)wp_record_position_gate_advance_primary_to_secondary(wl, NULL); }
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