|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
A text file as LOGS shows it: read whole, broken into rows. More...
Go to the source code of this file.
Data Structures | |
| struct | log_text_t |
| One file's text and its rows. The fields are log_text.c's. More... | |
Macros | |
| #define | LOG_TEXT_MAX ((size_t)32u * 1024u) |
| The most of a file the view holds: 32KiB. | |
| #define | LOG_TEXT_MARK 16 |
| Rows from one mark to the next. | |
Functions | |
| log_err_t | log_text_load (log_text_t *t, log_source_t *src, int cols) |
Read src from its top into t, and count its rows. | |
| void | log_text_free (log_text_t *t) |
Free what t holds and empty it. | |
| bool | log_text_row (log_text_t *t, int i, char *out, size_t n) |
Row i of the text into out. | |
| void | log_text_set_allocator (void *(*alloc_fn)(size_t), void(*free_fn)(void *)) |
| Set the allocator the buffer comes from, for a test that refuses it. | |
A text file as LOGS shows it: read whole, broken into rows.
LOGS opens a report, ATESTnnn.TXT, LIMITnnn.TXT or SERVOnnn.TXT (log_select.h), as text. The file is read once into memory, up to LOG_TEXT_MAX bytes, and its lines are broken into rows of at most a given number of cells (code points, gfx_text_cells()): a line wider than a row breaks at its last space inside the row, and a word wider than a row is cut at the row's end. A line ends at a line feed (LF), at a carriage return (CR), and at a CR LF pair, which is one end; a tab and a NUL byte are a space. A file written on a computer reads as one written by the panel.
The load notes where every LOG_TEXT_MARK'th row starts. A row is found from the last row found when it is up to LOG_TEXT_MARK rows on, and from the mark at or before it otherwise, so a frame of rows reads those rows and at most LOG_TEXT_MARK - 1 rows before them, wherever the text is scrolled to.
Pure C, no ESP-IDF (Espressif Internet-of-Things Development Framework).
SPDX-License-Identifier: MIT
| #define LOG_TEXT_MARK 16 |
Rows from one mark to the next.
A row takes 1 byte at least, so a text holds LOG_TEXT_MAX rows at most and LOG_TEXT_MAX / LOG_TEXT_MARK + 1 marks, 2,049 of 2 bytes, allocated beside the text.
| void log_text_free | ( | log_text_t * | t | ) |
Free what t holds and empty it.
| t | the text; nothing happens for NULL |
| log_err_t log_text_load | ( | log_text_t * | t, |
| log_source_t * | src, | ||
| int | cols ) |
Read src from its top into t, and count its rows.
What t held before is freed first.
| t | the text; nothing happens for NULL |
| src | the file, read to its end or to LOG_TEXT_MAX bytes |
| cols | cells a row holds, 1 or more |
cols under 1; LOG_ERR_MEMORY when the buffers are not given; LOG_ERR_READ when a read fails. t holds nothing after a failure. | bool log_text_row | ( | log_text_t * | t, |
| int | i, | ||
| char * | out, | ||
| size_t | n ) |
Row i of the text into out.
| t | the text |
| i | the row, 0 to rows - 1 |
| out | takes the row, terminated; cut at n - 1 bytes, between two characters |
| n | bytes of out |
out empty | void log_text_set_allocator | ( | void * | alloc_fn (*)(size_t), |
| void(* | free_fn )(void *) ) |
Set the allocator the buffer comes from, for a test that refuses it.
| alloc_fn | NULL for malloc |
| free_fn | NULL for free |