|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
book DOM-walk helpers shared across the library's translation units. More...
Go to the source code of this file.
Enumerations | |
| enum | book_container_field_off_t : uint8_t { k_book_cont_off_chunk_bytes = 4U , k_book_cont_off_total = 8U , k_book_cont_off_count = 16U , k_book_cont_off_reserved = 20U } |
| Byte offsets of the fixed "RBKC" container-header fields. More... | |
| enum | book_xhtml_bound_t : uint32_t { k_book_xhtml_stack = 512U , k_book_xhtml_iter_x = 4U } |
| Bounds for the iterative, recursion-free DOM walks (resident + paged). More... | |
Functions | |
| ra8_err_t | priv_book_container_header_fields (const uint8_t *hdr, uint32_t *out_chunk_bytes, uint64_t *out_total, uint32_t *out_count) |
| Parse + validate the fixed 24-byte "RBKC" container header. | |
| uint64_t | priv_book_container_table_entry (const uint8_t *table, uint32_t idx) |
| Decode one uint64 LE chunk-table entry from unaligned container bytes. | |
| uint32_t | priv_book_crc32_extend (uint32_t crc, const uint8_t *data, size_t len) |
| Extend a finalized CRC-32/ISO-HDLC with another byte span. | |
| bool | priv_book_is_block (const char *name) |
| Test whether an element name is a block-level HTML element. | |
| bool | priv_book_emit_text (char *out, size_t cap, size_t *pos, const char *str, bool *at_break) |
| Append a whitespace-collapsed text run to the output buffer. | |
| bool | priv_book_emit_break (char *out, size_t cap, size_t *pos, bool *at_break) |
| Append a paragraph break, collapsing consecutive block-level breaks. | |
book DOM-walk helpers shared across the library's translation units.
Module-private seam between book_xhtml.c (resident XHTML serialiser + text extractor) and book_paged.c (the #163 paged text extractor). The plain-text leaf helpers (whitespace collapse, paragraph break, block-element test) and the shared walk-bound constants are declared here so the paged walk can reuse them verbatim – guaranteeing paged output is byte-identical to the resident walk – without duplicating the logic. Also the seam between book.c (resident container open) and book_chunked.c (demand-paged chunk reader): both parse the "RBKC" container header through one helper so the format has a single in-firmware definition. Not part of the public book API; consumers use book.h / book_paged.h / book_chunked.h.
Definition in file book_internal.h.
| enum book_container_field_off_t : uint8_t |
Byte offsets of the fixed "RBKC" container-header fields.
Mirrors the layout documented on book_container_t; shared by the resident open (book.c) and the demand-paged chunk reader (book_chunked.c) so both parse one definition of the format.
Definition at line 38 of file book_internal.h.
| enum book_xhtml_bound_t : uint32_t |
Bounds for the iterative, recursion-free DOM walks (resident + paged).
| Enumerator | |
|---|---|
| k_book_xhtml_stack | Max pending open/close walk entries. |
| k_book_xhtml_iter_x | Iteration-guard multiplier over node_count. |
Definition at line 136 of file book_internal.h.
| ra8_err_t priv_book_container_header_fields | ( | const uint8_t * | hdr, |
| uint32_t * | out_chunk_bytes, | ||
| uint64_t * | out_total, | ||
| uint32_t * | out_count ) |
Parse + validate the fixed 24-byte "RBKC" container header.
Checks the magic, requires a non-zero chunk size and inflated total, requires the reserved word to be zero, and requires the stored chunk count to equal ceil(inflated_total / chunk_bytes). Field decoding is memcpy-based so the header buffer needs no alignment. Bounds against the file length are each caller's job (the resident open and the chunk reader own different views of the file).
| [in] | hdr | First k_book_container_header_len bytes of the container file. |
| [out] | out_chunk_bytes | Receives the inflated bytes-per-chunk. |
| [out] | out_total | Receives the flat-blob inflated total. |
| [out] | out_count | Receives the chunk count. |
| k_ra8_ok | Header well-formed; outputs populated. |
| k_ra8_err_null_ptr | A pointer argument was NULL. |
| k_ra8_err_invalid_arg | Bad magic, zero chunk size or total, non-zero reserved word, or a chunk count that disagrees with ceil(total / chunk_bytes). |
hdr holds at least k_book_container_header_len readable bytes. hdr, writes only the outputs. Parse + validate the fixed 24-byte "RBKC" container header.
Definition at line 290 of file book.c.
References internal_copy_object(), k_book_cont_off_chunk_bytes, k_book_cont_off_count, k_book_cont_off_reserved, k_book_cont_off_total, k_book_container_magic_len, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_PRIV, and s_tag_book.
Referenced by internal_chunked_open_body(), and internal_container_view().
| uint64_t priv_book_container_table_entry | ( | const uint8_t * | table, |
| uint32_t | idx ) |
Decode one uint64 LE chunk-table entry from unaligned container bytes.
memcpy-based so the table may sit at any alignment (baked MRAM arrays are byte-aligned). Entry idx starts at table + idx * k_book_container_entry_len.
| [in] | table | First byte of the chunk table. |
| [in] | idx | Entry index (<= chunk_count, caller-bounded). |
| 0 | For entry 0 of every well-formed table (offsets are payload-relative and the first stream starts at 0). |
table holds at least (idx + 1) * k_book_container_entry_len bytes. idx was bounds-checked against the validated chunk count. Decode one uint64 LE chunk-table entry from unaligned container bytes.
Definition at line 325 of file book.c.
References internal_copy_object(), k_book_container_entry_len, and RA8_PRIV.
Referenced by internal_container_view(), and internal_inflate_chunks().
| uint32_t priv_book_crc32_extend | ( | uint32_t | crc, |
| const uint8_t * | data, | ||
| size_t | len ) |
Extend a finalized CRC-32/ISO-HDLC with another byte span.
Uses the same reflected polynomial and complement convention as zlib's crc32(): pass 0 for the first span, then feed the returned value into each subsequent call. This lets resident and streaming validators share one wire-integrity definition without retaining the whole RABOOK body.
| [in] | crc | CRC returned for all preceding spans, or 0 for the first. |
| [in] | data | Next readable byte span (non-NULL when len is non-zero). |
| [in] | len | Number of bytes in data. |
| UINT32_C(0) | The concatenated byte stream's finalized CRC is zero. |
| UINT32_MAX | The concatenated byte stream's finalized CRC has every bit set. |
data addresses at least len readable bytes when len is non-zero. crc is zero or a finalized value returned by an earlier call. Extend a finalized CRC-32/ISO-HDLC with another byte span.
Computes a CRC-32/ISO-HDLC (reflected polynomial 0xEDB88320) over the byte array [data, data + len). The algorithm seeds the accumulator with k_book_crc_init, folds each byte through the reflected polynomial, then XORs the final value with k_book_crc_init again. The check value over "123456789" is 0xCBF43926, matching Python zlib.crc32_val.
| [in] | crc | Previous finalized CRC value; use zero for the first span. |
| [in] | data | Pointer to the byte array to checksum; must not be NULL. |
| [in] | len | Number of bytes to process; zero preserves crc. |
crc with data. | 0x00000000 | Returned for an empty first span. |
| 0xCBF43926 | Check value for the ASCII string "123456789". |
data is not NULL when len is greater than 0. len does not exceed the size of the allocation pointed to by data. data nor any external state is modified.Definition at line 86 of file book.c.
References k_book_crc_bits_per_byte, k_book_crc_init, k_book_crc_poly, and RA8_PRIV.
Referenced by internal_crc32(), and internal_validate_crc().
| bool priv_book_emit_break | ( | char * | out, |
| size_t | cap, | ||
| size_t * | pos, | ||
| bool * | at_break ) |
Append a paragraph break, collapsing consecutive block-level breaks.
Trims any trailing spaces already written (decrementing *pos while the last byte is a space), sets *at_break to suppress leading whitespace next, then appends a single '\n' unless the last byte is already '\n' (so nested/adjacent block elements collapse to one blank line).
| [out] | out | Destination character buffer. |
| [in] | cap | Total capacity of out in bytes. |
| [in,out] | pos | Current write offset; may be trimmed, then advanced by 1. |
| [in,out] | at_break | Set true on return; entry value ignored. |
| true | Break emitted (or collapsed into an existing newline). |
| false | Output buffer overflowed while writing the newline byte. |
out is a valid, writable buffer of at least cap bytes. pos is non-null and *pos <= cap on entry. *at_break is true on return. *pos are removed; at most one '\n' added.Trims any trailing space characters already written to out (by decrementing *pos while the last byte is ' '), then sets *at_break to true to suppress leading whitespace in the next text fragment. If the last byte already in out is '\n' no additional newline is written, which collapses runs of breaks produced by consecutive or nested block-level elements (e.g. a p inside a div) into a single blank line. Otherwise a single '\n' is appended via internal_emit.
| [out] | out | Destination character buffer. |
| [in] | cap | Total capacity of out in bytes. |
| [in,out] | pos | Current write offset; may be decremented to trim trailing spaces, then advanced by 1 if a newline is emitted. |
| [in,out] | at_break | Set to true on entry to suppress subsequent leading whitespace; value on entry is ignored. |
| true | Break emitted (or collapsed into an existing newline). |
| false | Output buffer overflowed while writing the newline byte. |
out is a valid, writable buffer of at least cap bytes. pos is non-null and *pos <= cap on entry. *at_break is true on return. out before the current *pos have been removed; at most one '\n' is appended.Definition at line 583 of file book_xhtml.c.
References internal_emit(), and RA8_PRIV.
Referenced by internal_paged_visit_node(), and internal_walk_text().
| bool priv_book_emit_text | ( | char * | out, |
| size_t | cap, | ||
| size_t * | pos, | ||
| const char * | str, | ||
| bool * | at_break ) |
Append a whitespace-collapsed text run to the output buffer.
Folds any run of space / tab / CR / LF into at most a single ASCII space; non-whitespace is forwarded via the raw append. at_break carries inter-call state: when true, leading whitespace in the fragment is dropped (so indentation between inline elements does not leak into prose). It is set true after a collapsed space and false after any non-whitespace byte – so calling this repeatedly over chunks of one logical run yields the same result as one call.
| [out] | out | Destination character buffer. |
| [in] | cap | Total capacity of out in bytes. |
| [in,out] | pos | Current write offset; advanced for each byte written. |
| [in] | str | NUL-terminated text fragment to collapse and append. |
| [in,out] | at_break | Whitespace-collapse carry flag (in: prior state; out: trailing state after this fragment). |
| true | Fragment appended (or it was entirely suppressed whitespace). |
| false | Output buffer overflowed; partial output may have been written. |
out is a valid, writable buffer of at least cap bytes. str is a valid, NUL-terminated C string. str was processed; *pos advanced. *at_break reflects the trailing whitespace state, success or not.Iterates over str character by character applying the HTML whitespace-collapsing rule: any run of space (' '), tab ('\t'), carriage return ('\r'), or newline ('\n') characters is folded into at most a single ASCII space. Non-whitespace characters are passed through unchanged via internal_emit. The at_break flag carries inter-call state: when true any leading whitespace in the current fragment is silently dropped, preventing pretty-print indentation between inline elements from leaking into the rendered prose. at_break is set to true after a whitespace run is emitted and set to false after any non-whitespace character is emitted.
| [out] | out | Destination character buffer. |
| [in] | cap | Total capacity of out in bytes. |
| [in,out] | pos | Current write offset; advanced for each byte written. |
| [in] | str | NUL-terminated text fragment to collapse and append. |
| [in,out] | at_break | On entry: true if the previous output ended with a break or collapsed space that suppresses leading whitespace. On exit: updated to reflect the trailing state of this fragment. |
| true | Text run appended successfully (or was entirely suppressed whitespace). |
| false | Output buffer overflowed; partial output may have been written. |
out is a valid, writable buffer of at least cap bytes. str is a valid, NUL-terminated C string. str has been processed and *pos reflects the bytes appended to out. *at_break accurately reflects the trailing whitespace state after the call, regardless of success or failure.Definition at line 526 of file book_xhtml.c.
References internal_emit().
Referenced by internal_paged_emit_run(), and internal_walk_text().
| bool priv_book_is_block | ( | const char * | name | ) |
Test whether an element name is a block-level HTML element.
Linear search through a fixed table of block-level element names used to decide where to insert paragraph-break newlines during plain-text extraction (p, h1..h6, li, ul, ol, div, br, hr, section, tr, pre, header, blockquote, article, aside, footer, figure, figcaption). The comparison is case-sensitive (DOM names are lower-cased at compile).
| [in] | name | NUL-terminated element name to test (e.g. "p"). |
| true | name is a block-level element; emit a break before it. |
| false | name is an inline element; no break. |
name is a valid, NUL-terminated C string. name contains only lower-case ASCII letters (DOM invariant). name (no side effects).Performs a linear search through a fixed table of block-level element names used to decide where to insert paragraph-break newlines during plain-text extraction. The checked names are: p, h1, h2, h3, h4, h5, h6, li, ul, ol, div, br, hr, section, tr, pre, header, blockquote, article, aside, footer, figure, and figcaption. The comparison is case-sensitive because compiled book DOM names are lower-cased during parsing.
| [in] | name | NUL-terminated element name to test (e.g. "p"). |
| true | name is a block-level element; the text walker should emit a line break before descending into this element. |
| false | name is an inline element; no break is inserted. |
name is a valid, NUL-terminated C string. name contains only lower-case ASCII letters (DOM invariant). name with no side effects.Definition at line 470 of file book_xhtml.c.
References RA8_PRIV, and strcmp().
Referenced by internal_paged_visit_node(), and internal_walk_text().