19typedef enum : uint8_t {
24typedef enum : uint32_t {
135 if ((s ==
nullptr) || (out ==
nullptr) || (s[0] ==
'\0')) {
140 const double v = strtod(s, &end);
141 if ((errno != 0) || (end == s) || (*end !=
'\0') || !isfinite(v)) {
169 const char*
const parts[] = {
"mdl: --",
171 " expects a non-negative integer, got '",
201 const char*
const first[] = {prefix};
207 const char*
const last[] = {suffix};
240 if (text ==
nullptr) {
244 unsigned long candidate = 0UL;
279 if (text ==
nullptr) {
283 uint64_t candidate = 0U;
364 const char*
const parts[] = {
"mdl: --from expects a finite chapter number, got '",
395 if ((raw->
timeout == 0UL) || (raw->
timeout > (
unsigned long)UINT32_MAX)) {
398 if ((raw->
chapters == 0UL) || ((uintmax_t)raw->
chapters > (uintmax_t)SIZE_MAX)) {
400 "mdl: --chapters must be in 1..",
404 if (raw->
max_imgs > (
unsigned long)UINT32_MAX) {
408 const char*
const parts[] = {
"mdl: --max-bytes must be greater than zero\n"};
411 if ((a->
pick !=
nullptr) &&
412 ((raw->
pick == 0UL) || ((uintmax_t)raw->
pick > (uintmax_t)SIZE_MAX))) {
414 "mdl: --pick must be in 1..",
423 if ((a ==
nullptr) || (diagnostic ==
nullptr) || (n ==
nullptr)) {
@ k_cli_dec_base
Decimal conversion radix.
Command-line parsing for the mdl CLI.
Private byte-stream helpers shared by mdl CLI units.
ra8_err_t priv_mdl_cli_put_parts(ra8_io_stream_t *stream, const char *const *parts, size_t count)
Write a bounded ordered vector of NUL-terminated text fragments.
ra8_err_t priv_mdl_cli_reject_parts(ra8_io_stream_t *stream, const char *const *parts, size_t count)
Write a rejection diagnostic and return invalid-argument status.
mdl_cli_timeout_t
Default request time budget when --timeout is absent.
@ k_req_timeout_def
Twenty-five seconds in milliseconds.
static ra8_err_t internal_cli_opt_u64(ra8_io_stream_t *diagnostic, const char *name, const char *text, uint64_t dflt, uint64_t *out)
Parse one optional uint64 option or emit its rejection.
static bool internal_cli_parse_ul(const char *s, unsigned long *out)
Parse one complete unsigned-long decimal value.
static bool internal_cli_parse_u64(const char *s, uint64_t *out)
Parse one complete unsigned 64-bit decimal value.
static bool internal_cli_parse_chapter(const char *s, double *out)
Parse one complete finite decimal chapter number for --from.
static ra8_err_t internal_cli_reject_integer(ra8_io_stream_t *diagnostic, const char *name, const char *value)
Reject one option whose value is not an unsigned decimal integer.
ra8_err_t mdl_cli_parse_nums(const mdl_args_t *a, ra8_io_stream_t *diagnostic, mdl_nums_t *n)
Strictly parse and validate every numeric CLI field.
static ra8_err_t internal_cli_reject_limit(ra8_io_stream_t *diagnostic, const char *prefix, uint64_t value, const char *suffix)
Write a rejection line containing one unsigned limit value.
static ra8_err_t internal_cli_validate_num_ranges(const mdl_args_t *a, ra8_io_stream_t *diagnostic, const mdl_cli_raw_nums_t *raw)
Enforce numeric option ranges after complete spelling conversion.
static ra8_err_t internal_cli_opt_ul(ra8_io_stream_t *diagnostic, const char *name, const char *text, unsigned long dflt, unsigned long *out)
Parse one optional unsigned-long option or emit its rejection.
mdl_cli_parse_t
Radix used by strict unsigned decimal parsing.
static ra8_err_t internal_cli_parse_chapter_pick(const mdl_args_t *a, ra8_io_stream_t *diagnostic, mdl_nums_t *out, mdl_cli_raw_nums_t *raw)
Parse chapter and pick values into the candidate numeric record.
static ra8_err_t internal_cli_parse_num_values(const mdl_args_t *a, ra8_io_stream_t *diagnostic, mdl_nums_t *out, mdl_cli_raw_nums_t *raw)
Parse all numeric spellings into a failure-atomic candidate.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
ra8_err_t ra8_io_stream_put_u64(ra8_io_stream_t *s, uint64_t value)
Write value as unsigned 64-bit decimal ASCII without leading zeros.
Parsed command-line options in string form (converted by main).
const char * chapters
–chapters.
const char * timeout
–timeout.
const char * max_bytes
–max-bytes: per-response size cap.
const char * pick
–pick N: download the Nth discovery hit (1-based).
const char * from
–from: first chapter NUMBER to fetch (not an index).
Native-width numeric candidates retained until range validation.
unsigned long max_imgs
Parsed image cap before uint32 narrowing.
unsigned long chapters
Parsed chapter count before size_t use.
unsigned long timeout
Parsed timeout before uint32 narrowing.
unsigned long pick
Parsed discovery selection before size_t.
uint64_t max_bytes
Parsed response byte cap.
The validated numeric CLI scalars, parsed once before any run mode.
size_t pick
–pick discovery hit (1-based; 0 = list).
bool from_present
Whether –from was supplied.
uint32_t timeout
–timeout ms (default k_req_timeout_def).
size_t chapters
–chapters window (clamped to >= 1).
uint32_t max_imgs
–max page images (0 = all).
uint64_t seed
–seed (default 1).
double from_num
–from chapter number, including decimals.
Caller-allocated byte-stream handle binding a sink to its context.