ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
12
13#include <stdint.h>
14#include <unistd.h>
15
16#include "alphabet_soup.h"
18#include "ra8_err.h"
19#include "ra8_io_stream.h"
20#include "ra8_io_stream_posix.h"
21
27
33
45int main(int argc, char** argv)
46{
47 static soup_app_storage_t s_app_storage;
48 ra8_io_stream_t out_stream = {};
49 ra8_io_stream_posix_state_t stream_state = {};
50 if (ra8_io_stream_posix_init(&out_stream, &stream_state, STDOUT_FILENO) != k_ra8_ok) {
51 return k_exit_code_error;
52 }
53 if (argc < 2) {
54 (void)ra8_io_stream_puts(&out_stream, "Usage: alphabet_soup <file>\n");
55 (void)ra8_io_stream_flush(&out_stream);
56 return k_exit_code_error;
57 }
58 uint32_t file_size = 0U;
59 ra8_err_t err =
61 s_app_storage.file_buffer,
62 (uint32_t)(sizeof(s_app_storage.file_buffer) - 1U),
63 &file_size);
64 if (err != k_ra8_ok) {
65 (void)ra8_io_stream_puts(&out_stream, "Error: Could not open or read file\n");
66 (void)ra8_io_stream_flush(&out_stream);
67 return k_exit_code_error;
68 }
69 s_app_storage.file_buffer[file_size] = '\0';
70 err = soup_solve(&s_app_storage.solver_ctx,
71 (const char*)s_app_storage.file_buffer,
72 file_size,
73 &out_stream);
74 if (err != k_ra8_ok) {
75 (void)ra8_io_stream_puts(&out_stream, "Error: Failed solving puzzle\n");
76 (void)ra8_io_stream_flush(&out_stream);
77 return k_exit_code_error;
78 }
80}
Word search puzzle solver API and bounded workspace definitions.
@ k_soup_max_file_capacity
Maximum supported puzzle file size.
ra8_err_t soup_solve(soup_context_t *ctx, const char *text, uint32_t text_len, ra8_io_stream_t *out_stream)
Parse board and words from puzzle text and emit solutions to the output stream.
ra8_err_t priv_alphabet_soup_load_file_contents(const char *filepath, uint8_t *out_buf, uint32_t buf_cap, uint32_t *out_len)
Private host-file helpers for the Alphabet Soup CLI wrapper.
void main(void)
Secure fallback main entry point.
Definition main.c:37
file_print_exit_code_t
Process exit codes.
Definition main.c:23
@ k_exit_code_error
Error during argument or file I/O.
Definition main.c:25
@ k_exit_code_success
Puzzle solved and output printed.
Definition main.c:24
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
ra8_io targetable byte-stream facade – one writer, many destinations.
ra8_err_t ra8_io_stream_puts(ra8_io_stream_t *s, const char *str)
Write a NUL-terminated string (without the NUL) to the bound sink.
ra8_err_t ra8_io_stream_flush(ra8_io_stream_t *s)
Flush any sink-side buffering to its destination.
Borrowed raw-descriptor backend for the portable byte-stream facade.
ra8_err_t ra8_io_stream_posix_init(ra8_io_stream_t *stream, ra8_io_stream_posix_state_t *state, int fd)
Bind a borrowed writable descriptor as a byte-stream sink.
Caller-owned state retained by one POSIX stream binding.
Caller-allocated byte-stream handle binding a sink to its context.
Static application workspace allocated in .bss.
Definition main.c:29
soup_context_t solver_ctx
Bounded solver context.
Definition main.c:30
uint8_t file_buffer[k_soup_max_file_capacity]
Bounded file buffer.
Definition main.c:31
Caller-owned bounded workspace for puzzle solving (zero-heap).