rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
log_text.h File Reference

A text file as LOGS shows it: read whole, broken into rows. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "log_csv.h"

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.

Detailed Description

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

Macro Definition Documentation

◆ LOG_TEXT_MARK

#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.

Function Documentation

◆ log_text_free()

void log_text_free ( log_text_t * t)

Free what t holds and empty it.

Parameters
tthe text; nothing happens for NULL

◆ log_text_load()

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.

Parameters
tthe text; nothing happens for NULL
srcthe file, read to its end or to LOG_TEXT_MAX bytes
colscells a row holds, 1 or more
Returns
LOG_OK; LOG_ERR_ARG for no source or 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.

◆ log_text_row()

bool log_text_row ( log_text_t * t,
int i,
char * out,
size_t n )

Row i of the text into out.

Parameters
tthe text
ithe row, 0 to rows - 1
outtakes the row, terminated; cut at n - 1 bytes, between two characters
nbytes of out
Returns
false for a row outside the text, with out empty

◆ log_text_set_allocator()

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.

Parameters
alloc_fnNULL for malloc
free_fnNULL for free