|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Emit deterministic fixed-layout EPUB3 chapter containers. More...
#include <limits.h>#include <stdio.h>#include <string.h>#include "mdl_export.h"#include "mdl_export_epub_internal.h"#include "mdl_export_internal.h"#include "mdl_sanitize.h"#include "mdl_urlname.h"#include "miniz.h"#include "ra8_attributes.h"Go to the source code of this file.
Functions | |
| static ra8_err_t | internal_epub_media_type_from_sniff (mdl_storage_t *storage, const char *dir, const char *name, const char **out) |
| Classify one page's image media type from sniffed portable bytes. | |
| static void | internal_epub_media_type_from_suffix (const char *name, const char **out) |
| Classify one page's image media type from its filename suffix. | |
| static ra8_err_t | internal_epub_media_type (mdl_storage_t *storage, const char *dir, const char *name, const char **out) |
| Resolve one page's image media type from portable bytes then suffix. | |
| bool | priv_mdl_epub_str_cat (char *dst, size_t cap, const char *text) |
| Append text to NUL-terminated dst; report whether it fully fit. | |
| bool | priv_mdl_epub_add_str (mz_zip_archive *zip, const char *name, const char *body) |
| Add an in-memory string as a stored ZIP entry. | |
| static ra8_err_t | internal_epub_add_external_cover (mz_zip_archive *zip, mdl_storage_t *storage, const mdl_external_cover_t *cover, char *mani, size_t cap) |
| Store and declare a validated external EPUB cover. | |
| static ra8_err_t | internal_epub_append_frags (char *mani, char *spine, char *nav, size_t cap, const char *esc_name, const char *media, size_t idx, unsigned n, bool is_cover) |
| Append one page's manifest, spine, and navigation fragments. | |
| static bool | internal_epub_page_is_cover (const mdl_export_meta_t *meta, const char *name, size_t idx) |
| Is one exported image the publication's declared cover? | |
| static ra8_err_t | internal_epub_write_page_xhtml (mz_zip_archive *zip, const char *name, unsigned n, char *esc, size_t esc_cap) |
| Escape a page name and write its XHTML wrapper into the ZIP. | |
| static ra8_err_t | internal_epub_add_page (mdl_storage_t *storage, mz_zip_archive *zip, const char *dir, const char *name, size_t idx, char *mani, char *spine, char *nav, size_t cap, const mdl_export_meta_t *meta) |
| Add one fixed-layout EPUB page and its image. | |
| static const mdl_export_meta_t * | internal_epub_page_meta (const mdl_external_cover_t *cover, const mdl_export_meta_t *meta, mdl_export_meta_t *page_meta) |
| Select page metadata after accounting for an external cover. | |
| static ra8_err_t | internal_epub_carve_workspace (mdl_export_workspace_t *ws, size_t cap, char **mani, char **spine, char **nav, char **opf, char **navdoc) |
| Carve the five bounded XML/ZIP accumulators from workspace arena. | |
| static ra8_err_t | internal_epub_finish_writer (mz_zip_archive *zip, bool zip_open, mdl_zip_allocator_t *zip_alloc, ra8_err_t rc, const mdl_export_output_t *output) |
| End the ZIP writer and translate exhaustion/output faults to status. | |
| ra8_err_t | priv_mdl_export_epub (mdl_storage_t *storage, const char *dir, char names[][k_name_max], size_t count, mdl_export_output_t *output, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws) |
| Package chapter pages into a valid fixed-layout EPUB3. | |
Variables | |
| static const char *const | s_epub_container_xml |
| OCF container pointing at the OPF package (fixed). | |
Emit deterministic fixed-layout EPUB3 chapter containers.
Owns EPUB media typing, page XHTML, cover integration, and final ZIP assembly over bounded caller storage. The package document, navigation document, and publication identifier are rendered by mdl_export_epub_meta.c.
[Ring 4 / Domain] {World: NS}
Definition in file mdl_export_epub.c.
|
static |
Store and declare a validated external EPUB cover.
Writes the file under its canonical OEBPS path and appends one cover-image manifest item using byte-derived MIME data.
| [in,out] | zip | Initialized EPUB ZIP writer. |
| [in,out] | storage | Injected portable cover reader. |
| [in] | cover | Prepared cover descriptor. |
| [in,out] | mani | NUL-terminated manifest accumulator. |
| [in] | cap | Capacity of mani. |
| k_ra8_ok | No external cover was requested or it was added. |
| k_ra8_fail | A path, ZIP, or manifest operation failed. |
mani is terminated within cap. Definition at line 207 of file mdl_export_epub.c.
References mdl_external_cover_t::entry, mdl_external_cover_t::external, k_epub_entry_max, k_epub_frag_max, k_ra8_fail, k_ra8_ok, mdl_external_cover_t::mime, priv_mdl_epub_str_cat(), priv_mdl_export_snprintf_fit(), priv_mdl_export_zip_add_file(), RA8_INTERNAL, and mdl_external_cover_t::source.
Referenced by priv_mdl_export_epub().
|
static |
Add one fixed-layout EPUB page and its image.
Escapes the source name, writes page XHTML and stored image members, derives the real MIME where possible, and appends package fragments.
| [in,out] | storage | Injected portable file reader. |
| [in,out] | zip | Initialized EPUB ZIP writer. |
| [in] | dir | Chapter directory. |
| [in] | name | Page filename. |
| [in] | idx | Zero-based page index. |
| [in,out] | mani | Manifest accumulator. |
| [in,out] | spine | Spine accumulator. |
| [in,out] | nav | Navigation accumulator. |
| [in] | cap | Capacity shared by accumulators. |
| [in] | meta | Metadata controlling cover selection, or NULL. |
| k_ra8_ok | Image, XHTML, and fragments were added. |
| k_ra8_fail | Escaping, formatting, ZIP writing, or append failed. |
zip is initialized and accumulator buffers are distinct. Definition at line 405 of file mdl_export_epub.c.
References internal_epub_append_frags(), internal_epub_media_type(), internal_epub_page_is_cover(), internal_epub_write_page_xhtml(), k_epub_entry_max, k_epub_name_esc_max, k_fw_fs_path_cap, k_ra8_err_invalid_size, k_ra8_fail, k_ra8_ok, priv_mdl_export_path_join(), priv_mdl_export_snprintf_fit(), priv_mdl_export_zip_add_file(), and RA8_INTERNAL.
Referenced by priv_mdl_export_epub().
|
static |
Append one page's manifest, spine, and navigation fragments.
Builds all three bounded fragments from an escaped filename and marks the image manifest item when it is the logical cover.
| [in,out] | mani | Manifest accumulator. |
| [in,out] | spine | Spine accumulator. |
| [in,out] | nav | Navigation accumulator. |
| [in] | cap | Capacity shared by all accumulators. |
| [in] | esc_name | XML-escaped image filename. |
| [in] | media | Image MIME string. |
| [in] | idx | Zero-based manifest identifier index. |
| [in] | n | One-based displayed page number. |
| [in] | is_cover | Whether to emit the cover-image property. |
| k_ra8_ok | All fragments fit. |
| k_ra8_fail | Formatting or any accumulator overflowed. |
mani, spine, and nav reference distinct writable buffers. Definition at line 262 of file mdl_export_epub.c.
References k_epub_frag_max, k_ra8_fail, k_ra8_ok, priv_mdl_epub_str_cat(), priv_mdl_export_snprintf_fit(), and RA8_INTERNAL.
Referenced by internal_epub_add_page().
|
static |
Carve the five bounded XML/ZIP accumulators from workspace arena.
Reserves one cap-byte block per accumulator and NUL-terminates the three accumulators the caller builds incrementally.
| [in,out] | ws | Exclusive caller-owned workspace. |
| [in] | cap | Byte capacity reserved for each accumulator. |
| [out] | mani | Receives the manifest accumulator. |
| [out] | spine | Receives the spine accumulator. |
| [out] | nav | Receives the navigation accumulator. |
| [out] | opf | Receives the OPF render buffer. |
| [out] | navdoc | Receives the navigation-document render buffer. |
| k_ra8_ok | All five accumulators were reserved. |
| k_ra8_err_invalid_size | The workspace arena is exhausted. |
ws is exclusive and owns writable arena storage. Definition at line 498 of file mdl_export_epub.c.
References k_ra8_err_invalid_size, k_ra8_ok, mdl_export_workspace_take(), and RA8_INTERNAL.
Referenced by priv_mdl_export_epub().
|
static |
End the ZIP writer and translate exhaustion/output faults to status.
Always ends an opened writer before releasing the workspace allocator, then maps a generic write failure to the more specific exhaustion or captured-output error when one is available.
| [in,out] | zip | ZIP writer to end when zip_open. |
| [in] | zip_open | Whether zip was successfully initialized. |
| [in,out] | zip_alloc | Workspace allocator bound to zip. |
| [in] | rc | Status accumulated by the writer stages. |
| [in] | output | Validated-publication output whose captured error may refine a generic write failure. |
| k_ra8_err_invalid_size | rc was k_ra8_fail and the arena was exhausted. |
| other | rc, or output->error when it refines a generic failure. |
zip_alloc is bound to zip via priv_mdl_zip_workspace_bind. output is the validated-publication output bound to the writer. rc is never refined into a success status. Definition at line 542 of file mdl_export_epub.c.
References mdl_export_output_t::error, mdl_zip_allocator_t::exhausted, k_ra8_err_invalid_size, k_ra8_fail, k_ra8_ok, priv_mdl_zip_workspace_release(), and RA8_INTERNAL.
Referenced by priv_mdl_export_epub().
|
static |
Resolve one page's image media type from portable bytes then suffix.
Prefers recognized image magic read through the injected storage; only a clean unsupported signature falls back to the page suffix.
| [in,out] | storage | Injected portable file reader. |
| [in] | dir | Canonical chapter directory. |
| [in] | name | Bounded page leaf name. |
| [out] | out | Borrowed canonical MIME pointer. |
| k_ra8_ok | A magic-derived or suffix fallback MIME was selected. |
| k_ra8_err_invalid_size | The composed path exceeded its bound. |
| other | A portable open, read, or close failure propagated. |
storage. name is NUL-terminated and fits the exporter filename contract. out to process-lifetime constant storage. Definition at line 150 of file mdl_export_epub.c.
References internal_epub_media_type_from_sniff(), internal_epub_media_type_from_suffix(), k_ra8_err_not_found, k_ra8_ok, and RA8_INTERNAL.
Referenced by internal_epub_add_page().
|
static |
Classify one page's image media type from sniffed portable bytes.
Joins the canonical path and sniffs the file's magic through injected storage. An unrecognized (but cleanly read) signature is reported as k_ra8_err_not_found rather than an error, so the caller can fall back to the suffix classifier.
| [in,out] | storage | Injected portable file reader. |
| [in] | dir | Canonical chapter directory. |
| [in] | name | Bounded page leaf name. |
| [out] | out | Borrowed canonical MIME pointer, valid only on k_ra8_ok. |
| k_ra8_ok | A magic-derived MIME was selected; out is valid. |
| k_ra8_err_not_found | The signature was read cleanly but unrecognized. |
| k_ra8_err_invalid_size | The composed path exceeded its bound. |
| other | A portable open, read, or close failure propagated. |
storage. name is NUL-terminated and fits the exporter filename contract. out unchanged. Definition at line 59 of file mdl_export_epub.c.
References k_fw_fs_path_cap, k_ra8_err_invalid_size, k_ra8_err_not_found, k_ra8_err_validation_failed, k_ra8_ok, mdl_urlname_sniff_file(), priv_mdl_export_path_join(), RA8_INTERNAL, and strcmp().
Referenced by internal_epub_media_type().
|
static |
Classify one page's image media type from its filename suffix.
Falls back to JPEG when no recognized suffix is present, since the exporter must always publish some MIME for a manifest entry.
| [in] | name | Bounded page leaf name. |
| [out] | out | Borrowed canonical MIME pointer. |
name is NUL-terminated. out is non-NULL and addresses one writable pointer. out addresses process-lifetime constant storage. name is unchanged. Definition at line 107 of file mdl_export_epub.c.
References RA8_INTERNAL, strcmp(), and strrchr().
Referenced by internal_epub_media_type().
|
static |
Is one exported image the publication's declared cover?
Matches by declared cover index first, then by declared cover path name, so either identification method marks the same image.
| [in] | meta | Resolved metadata controlling cover selection, or NULL. |
| [in] | name | Image file name being exported. |
| [in] | idx | Zero-based export position of name. |
| true | idx matches the declared cover index, or name matches the declared cover path. |
| false | meta is NULL, or neither identification method matches. |
name is non-NULL and NUL-terminated. meta is NULL or holds a bounded NUL-terminated cover path. Definition at line 321 of file mdl_export_epub.c.
References mdl_export_meta_t::cover_index, mdl_export_meta_t::cover_path, and strcmp().
Referenced by internal_epub_add_page().
|
static |
Select page metadata after accounting for an external cover.
Copies metadata only when the external cover consumes the cover role, clearing the page cover fields without mutating caller input.
| [in] | cover | Prepared canonical cover descriptor. |
| [in] | meta | Resolved caller metadata. |
| [out] | page_meta | Caller-owned adjusted metadata storage. |
| meta | No external cover adjustment is required. |
| page_meta | An adjusted caller-owned copy is ready. |
page_meta does not alias meta or cover. Definition at line 463 of file mdl_export_epub.c.
References mdl_export_meta_t::cover_index, mdl_export_meta_t::cover_path, and mdl_external_cover_t::external.
Referenced by priv_mdl_export_epub().
|
static |
Escape a page name and write its XHTML wrapper into the ZIP.
Escapes the source name for XML use, renders the fixed page markup, and writes it under the page's OEBPS entry name.
| [in,out] | zip | Initialized EPUB ZIP writer. |
| [in] | name | Page filename. |
| [in] | n | One-based page number. |
| [out] | esc | Receives the escaped name for later fragment use. |
| [in] | esc_cap | Capacity of esc. |
| k_ra8_ok | The escaped name and XHTML entry were written. |
| k_ra8_fail | Escaping, formatting, or ZIP writing failed. |
name is a NUL-terminated untrusted filename. esc addresses esc_cap writable bytes. esc holds no usable name. Definition at line 351 of file mdl_export_epub.c.
References k_epub_entry_max, k_epub_xhtml_max, k_ra8_fail, k_ra8_ok, mdl_xml_escape(), priv_mdl_epub_add_str(), priv_mdl_export_snprintf_fit(), and RA8_INTERNAL.
Referenced by internal_epub_add_page().
| bool priv_mdl_epub_add_str | ( | mz_zip_archive * | zip, |
| const char * | name, | ||
| const char * | body ) |
Add an in-memory string as a stored ZIP entry.
Passes the complete string length to miniz without compression.
| [in,out] | zip | Initialized ZIP writer. |
| [in] | name | Safe NUL-terminated member name. |
| [in] | body | NUL-terminated member body. |
| true | The entry was added. |
| false | The ZIP writer rejected it. |
zip remains initialized for writing. Definition at line 179 of file mdl_export_epub.c.
References k_ra8_ok, priv_mdl_export_zip_add_memory(), RA8_PRIV, and strlen().
Referenced by internal_epub_render_meta(), internal_epub_write_page_xhtml(), and priv_mdl_export_epub().
| bool priv_mdl_epub_str_cat | ( | char * | dst, |
| size_t | cap, | ||
| const char * | text ) |
Append text to NUL-terminated dst; report whether it fully fit.
Never truncates: if the append (plus its NUL) would not fit in cap it leaves dst unchanged and returns false, so the caller can fail loudly rather than emit a manifest cut off mid-element.
text was appended, false if it would overrun. | [in,out] | dst | Existing NUL-terminated accumulator. |
| [in] | cap | Total writable capacity of dst. |
| [in] | text | NUL-terminated text to append. |
| true | The complete text and terminator fit. |
| false | Capacity is insufficient and dst is unchanged. |
dst and text are non-NULL and do not overlap. dst is NUL-terminated within cap. Definition at line 168 of file mdl_export_epub.c.
References memcpy(), RA8_PRIV, and strlen().
Referenced by internal_epub_add_external_cover(), internal_epub_append_frags(), and internal_epub_prepare_creators().
| ra8_err_t priv_mdl_export_epub | ( | mdl_storage_t * | storage, |
| const char * | dir, | ||
| char | names[][k_name_max], | ||
| size_t | count, | ||
| mdl_export_output_t * | output, | ||
| const mdl_export_meta_t * | meta, | ||
| mdl_export_workspace_t * | ws ) |
Package chapter pages into a valid fixed-layout EPUB3.
Write a fixed-layout EPUB3 archive.
Carves all XML accumulators from caller storage, adds OCF roots, canonical cover, page members, metadata, and finalizes the staged archive.
| [in,out] | storage | Injected portable file reader. |
| [in] | dir | Chapter directory. |
| [in] | names | Sorted page-name rows. |
| [in] | count | Number of page rows. |
| [in,out] | output | Active validated-publication output. |
| [in] | meta | Metadata to encode, or NULL. |
| [in,out] | ws | Exclusive caller-owned workspace. |
| k_ra8_ok | A complete finalized EPUB was written. |
| k_ra8_err_invalid_size | Workspace or metadata bounds were exceeded. |
| k_ra8_err_validation_failed | External cover validation failed. |
| k_ra8_fail | ZIP, XHTML, or metadata writing failed. |
ws is exclusive and owns writable arena storage. Definition at line 584 of file mdl_export_epub.c.
References internal_epub_add_external_cover(), internal_epub_add_page(), internal_epub_carve_workspace(), internal_epub_finish_writer(), internal_epub_page_meta(), k_epub_base_bytes, k_epub_per_page_bytes, k_name_max, k_ra8_fail, k_ra8_ok, priv_mdl_epub_add_meta(), priv_mdl_epub_add_str(), priv_mdl_export_prepare_cover(), priv_mdl_export_zip_write(), priv_mdl_zip_workspace_bind(), priv_mdl_zip_workspace_error(), RA8_PRIV, and s_epub_container_xml.
Referenced by internal_export_dispatch(), and internal_write_temp_epub().
|
static |
OCF container pointing at the OPF package (fixed).
Definition at line 30 of file mdl_export_epub.c.
Referenced by priv_mdl_export_epub().