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_document_model.h
File editor
#ifndef WP_DOCUMENT_MODEL_H #define WP_DOCUMENT_MODEL_H #include "wp_file_format.h" #include "wp_record_parser.h" #include <stdbool.h> #include <stddef.h> #include <stdint.h> typedef enum WpDocumentTokenType { WP_DOCUMENT_TOKEN_TEXT, WP_DOCUMENT_TOKEN_SINGLE_BYTE, WP_DOCUMENT_TOKEN_FIXED_RECORD, WP_DOCUMENT_TOKEN_VARIABLE_RECORD, WP_DOCUMENT_TOKEN_RAW_RECORD } WpDocumentTokenType; typedef struct WpDocumentToken { WpDocumentTokenType type; WpCodeType record_type; uint8_t code; uint8_t sub_code; uint8_t *bytes; size_t length; bool complete; bool trailer_matches; } WpDocumentToken; typedef struct WpDocumentModel { WpDocumentToken *tokens; size_t token_count; size_t token_capacity; size_t body_size; } WpDocumentModel; void wp_document_model_init(WpDocumentModel *model); void wp_document_model_free(WpDocumentModel *model); /* Build a lossless token model from the loaded file body. Every token keeps * the original stream bytes, so a model converted back to a body is byte * identical until an edit is applied. */ bool wp_document_model_load(WpDocumentModel *model, WpLoadedFile *file); bool wp_document_model_to_body(const WpDocumentModel *model, uint8_t **out_body, size_t *out_size); bool wp_document_model_apply_to_file(const WpDocumentModel *model, WpLoadedFile *file); /* Insert/delete APIs operate on body byte offsets. Public edit operations are * transactional: the model is changed only if the full edit succeeds. Inserted * ASCII is copied as nonzero bytes below 0x80. Delete refuses ranges crossing * non-text tokens. */ bool wp_document_model_insert_ascii(WpDocumentModel *model, size_t byte_offset, const char *text, size_t text_len); bool wp_document_model_delete_text(WpDocumentModel *model, size_t byte_offset, size_t byte_count); /* Logical text offsets count visible text bytes plus common WP single-byte text * controls: hard/soft returns, hard/soft pages, tabs, and indents. Hidden * formatting/resource packets have zero logical length. When a logical offset * falls next to zero-length packets, it maps to the safe body boundary before * those packets. */ bool wp_document_model_text_length(const WpDocumentModel *model, size_t *out_text_units); bool wp_document_model_body_offset_for_text_offset(const WpDocumentModel *model, size_t text_offset, size_t *out_body_offset); /* Host text insertion translates '\t' to WP [Tab] 0x84, CR/LF/CRLF to hard * return 0x80, and '\f' to hard page 0x82. Other characters must be * printable ASCII 0x20-0x7E or map to a recovered WP extended-character set * and index. */ bool wp_document_model_insert_host_text(WpDocumentModel *model, size_t byte_offset, const char *text, size_t text_len); bool wp_document_model_insert_host_text_at_text_offset(WpDocumentModel *model, size_t text_offset, const char *text, size_t text_len); bool wp_document_model_delete_text_units(WpDocumentModel *model, size_t text_offset, size_t text_units); /* Insert a C3/C4 paired attribute span around host text. The attribute byte is * copied into both mirrored fixed packets: * C3 attr C3 text... C4 attr C4 * The exact user-facing meaning of each attr value is still being recovered; * callers should treat it as a WP attribute/format code byte. */ bool wp_document_model_insert_attribute_span_at_text_offset(WpDocumentModel *model, size_t text_offset, uint8_t attribute_code, const char *text, size_t text_len); #endif
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