|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
SPDX-License-Identifier: MIT. More...
Data Structures | |
| struct | find_t |
| State of a search for one file name. More... | |
| struct | list_t |
| State of one list: the sorted entries kept so far. More... | |
Macros | |
| #define | PRESET "KST" |
| Prefix of a proposed base name. | |
| #define | PRESET_LEN 3u |
| Length of the prefix, characters. | |
| #define | EXT_LEN (sizeof(KST_STORE_EXT) - 1u) |
| Length of the file extension, characters. | |
| #define | NUMBER_BYTES ((KST_STORE_LAST / 8) + 1) |
| Bytes of a bit set that holds one flag per number 0 to KST_STORE_LAST. | |
Functions | |
| static char | lower (char c) |
| Fold an ASCII capital letter to lower case. | |
| static int | name_cmp (const char *a, const char *b) |
| Order of two names without case; the case decides between names that are equal without it. | |
| static bool | same_name (const char *a, const char *b) |
| Whether two names are equal without case. | |
| static bool | reserved (const char *s, size_t n) |
Whether the first n characters of s are a device name. | |
| static bool | record (const char *s, size_t n) |
Whether the first n characters of s are KST_STORE_RECORD. | |
| static kst_store_name_t | check (const char *base, size_t n) |
| Check a base name of known length. | |
| kst_store_name_t | kst_store_name_check (const char *base) |
Whether base is a base name this layer writes. | |
| bool | kst_store_file_name (const char *base, char *out, size_t out_size) |
The file name of base: the base name and KST_STORE_EXT. | |
| static size_t | base_len (const char *name) |
| Length of the base name in a file name with the extension; 0 when the name does not end with it. | |
| static int | preset_number (const char *name) |
| The number in "KSTnnn.TXT", in any case; 0 for any other name. | |
| static void | mark_number (const char *name, bool is_dir, void *visit_ctx) |
| Set the bit of a directory entry's proposed number. | |
| kst_store_t | kst_store_preset (const kst_store_io_t *io, char *base, size_t base_size) |
| Propose a base name: "KST" and 3 digits, one above the highest number the directory holds. | |
| static void | find_name (const char *name, bool is_dir, void *visit_ctx) |
| Set found when a directory entry has the searched name. | |
| kst_store_t | kst_store_save (const kst_store_io_t *io, const char *base, const char *text, size_t len, kst_store_name_t *why) |
Write len bytes of text as the file of base. | |
| static bool | before_presets (const char *name) |
| Whether a name that is no proposed one stands in front of the proposed names: at or before "KST000.TXT" in the order without case. | |
| static int | list_cmp (const char *a, const char *b) |
| Order of two file names in a list: by name without case, with the proposed names in one run where "KST000.TXT" would stand, the highest number first. | |
| static void | list_name (const char *name, bool is_dir, void *visit_ctx) |
| Insert one directory entry into the sorted list. | |
| kst_store_t | kst_store_list (const kst_store_io_t *io, kst_store_entry_t *entries, size_t cap, size_t *count, size_t *total, size_t *skipped) |
| List the files with KST_STORE_EXT. | |
| kst_store_t | kst_store_list_after (const kst_store_io_t *io, const char *after, kst_store_entry_t *entries, size_t cap, size_t *count, size_t *total, size_t *skipped) |
kst_store_list() from the file behind after on: entries receives the first cap files the order has behind the name after, a file name with its extension that need not exist. | |
| kst_store_t | kst_store_load (const kst_store_io_t *io, const char *name, char *buf, size_t cap, size_t *len) |
Read the file name, a name as kst_store_list() gives it, into buf. len receives the number of bytes. | |
SPDX-License-Identifier: MIT.
|
static |
Length of the base name in a file name with the extension; 0 when the name does not end with it.
| name | The file name, with the extension. |
|
static |
Whether a name that is no proposed one stands in front of the proposed names: at or before "KST000.TXT" in the order without case.
| name | The file name. |
|
static |
Check a base name of known length.
| base | The base name. |
| n | Length of the base name, characters. |
|
static |
Set found when a directory entry has the searched name.
| name | The entry name. |
| is_dir | Whether the entry is a directory; ignored. |
| visit_ctx | The find_t state. |
| bool kst_store_file_name | ( | const char * | base, |
| char * | out, | ||
| size_t | out_size ) |
The file name of base: the base name and KST_STORE_EXT.
False, with an empty string in out, for a base name that fails kst_store_name_check() and for an out_size under KST_STORE_NAME_MAX.
| base | The base name. |
| out | Receives the file name. |
| out_size | Size of out, bytes. |
out holds the file name. | kst_store_t kst_store_list | ( | const kst_store_io_t * | io, |
| kst_store_entry_t * | entries, | ||
| size_t | cap, | ||
| size_t * | count, | ||
| size_t * | total, | ||
| size_t * | skipped ) |
List the files with KST_STORE_EXT.
The order: by name without case. The files named "KST" and 3 digits stand in one run at the place of "KST000", by falling number. kst_store_preset() gives a later file the higher number until KST999 is taken, so the run starts with the latest of them.
entries receives the first cap of them. count is the number written, total the number of files that qualify, skipped the number of files with the extension whose base name fails kst_store_name_check(): those are not listed and not loaded. The file named KST_STORE_RECORD is in none of the 3 numbers. Each of the 3 may be NULL. Directories are not listed. A directory without a file gives KST_STORE_OK and a count of 0.
| io | The card functions. |
| entries | Receives the listed names. |
| cap | Capacity of entries, in entries. |
| count | Receives the number of entries written, or NULL. |
| total | Receives the number of qualifying files, or NULL. |
| skipped | Receives the number of files with a bad name, or NULL. |
| kst_store_t kst_store_list_after | ( | const kst_store_io_t * | io, |
| const char * | after, | ||
| kst_store_entry_t * | entries, | ||
| size_t | cap, | ||
| size_t * | count, | ||
| size_t * | total, | ||
| size_t * | skipped ) |
kst_store_list() from the file behind after on: entries receives the first cap files the order has behind the name after, a file name with its extension that need not exist.
NULL lists from the first file on. total and skipped count the whole directory as kst_store_list() does.
A caller reaches every file of a directory in a buffer of cap entries by passing the last name of one call to the next; each call walks the directory once.
| io | The card functions. |
| after | The file name to list after, or NULL. |
| entries | Receives the listed names. |
| cap | Capacity of entries, in entries. |
| count | Receives the number of entries written, or NULL. |
| total | Receives the number of qualifying files, or NULL. |
| skipped | Receives the number of files with a bad name, or NULL. |
| kst_store_t kst_store_load | ( | const kst_store_io_t * | io, |
| const char * | name, | ||
| char * | buf, | ||
| size_t | cap, | ||
| size_t * | len ) |
Read the file name, a name as kst_store_list() gives it, into buf. len receives the number of bytes.
No terminator is written.
| io | The card functions. |
| name | The file name. |
| buf | Receives the bytes. |
| cap | Capacity of buf, bytes. |
| len | Receives the number of bytes read. |
| kst_store_name_t kst_store_name_check | ( | const char * | base | ) |
Whether base is a base name this layer writes.
| base | The base name, without extension. |
| kst_store_t kst_store_preset | ( | const kst_store_io_t * | io, |
| char * | base, | ||
| size_t | base_size ) |
Propose a base name: "KST" and 3 digits, one above the highest number the directory holds.
A gap below the highest number is not filled, so a higher number is a later file. With KST999 taken the lowest free number is proposed. Files and directories count, in any case; a file with another name counts for nothing.
base_size is KST_STORE_PRESET_MAX or more.
| io | The card functions. |
| base | Receives the proposed base name. |
| base_size | Size of base, bytes. |
| kst_store_t kst_store_save | ( | const kst_store_io_t * | io, |
| const char * | base, | ||
| const char * | text, | ||
| size_t | len, | ||
| kst_store_name_t * | why ) |
Write len bytes of text as the file of base.
KST_STORE_BAD_NAME leaves the reason in why, when not NULL. A name the directory holds, compared without case, gives KST_STORE_EXISTS and the file stays as it is.
| io | The card functions. |
| base | The base name of the file. |
| text | The bytes to write. |
| len | Number of bytes in text. |
| why | Receives the name reason when refused, or NULL. |
|
static |
Order of two file names in a list: by name without case, with the proposed names in one run where "KST000.TXT" would stand, the highest number first.
| a | The first file name. |
| b | The second file name. |
a sorts before, with or after b.
|
static |
Insert one directory entry into the sorted list.
| name | The entry name. |
| is_dir | Whether the entry is a directory; directories are skipped. |
| visit_ctx | The list_t state. |
|
static |
Fold an ASCII capital letter to lower case.
| c | The character. |
|
static |
Set the bit of a directory entry's proposed number.
| name | The entry name. |
| is_dir | Whether the entry is a directory; ignored. |
| visit_ctx | The bit set, NUMBER_BYTES bytes. |
|
static |
Order of two names without case; the case decides between names that are equal without it.
| a | The first name. |
| b | The second name. |
a sorts before, with or after b.
|
static |
The number in "KSTnnn.TXT", in any case; 0 for any other name.
| name | The file name. |
|
static |
Whether the first n characters of s are KST_STORE_RECORD.
| s | The name. |
| n | Number of characters in the base name. |
|
static |
Whether the first n characters of s are a device name.
| s | The name. |
| n | Number of characters to test: 3 or 4. |
|
static |
Whether two names are equal without case.
| a | The first name. |
| b | The second name. |