Making a folder of the card one level at a time, and checking a log folder.
More...
#include "card_tree.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
|
| card_dir_t | card_make_dirs (const char *dir, card_make_fn make, void *ctx) |
| | Make folder dir one level at a time, the shortest first: for "BENCH/KST/CONF", "BENCH", then "BENCH/KST", then "BENCH/KST/CONF".
|
| static bool | folder_char (char c) |
| | Whether a character is allowed in a folder name.
|
| static bool | is_device (const char *name, size_t len) |
| | Whether a folder name is a device name.
|
| static bool | is_bench (const char *path) |
| | Whether path is a bench area folder or one below it.
|
| card_folder_t | card_folder_check (const char *in, char *out, size_t n) |
| | Whether in names a folder the logs can be written to: 1 or 2 folders separated by "/", each 1 to 8 characters of A-Z, 0-9, "_" and "-", lower case taken as upper case.
|
| const char * | card_folder_use (const char *text, const char *fallback, char *out, size_t n) |
| | The folder a log is written to: text in upper case when card_folder_check() takes it, fallback otherwise.
|
|
| static const char *const | k_bench_conf [] |
| | The folders the bench keeps its own files in: the parent of each programmer's CONF folder.
|
|
static const char *const | k_devices [] = { "CON", "PRN", "AUX", "NUL" } |
| | The names FAT (File Allocation Table) volumes on Windows take for a device, with or without an extension.
|
Making a folder of the card one level at a time, and checking a log folder.
See card_tree.h.
SPDX-License-Identifier: MIT
◆ card_folder_check()
| card_folder_t card_folder_check |
( |
const char * | in, |
|
|
char * | out, |
|
|
size_t | n ) |
Whether in names a folder the logs can be written to: 1 or 2 folders separated by "/", each 1 to 8 characters of A-Z, 0-9, "_" and "-", lower case taken as upper case.
A device name is refused in either place, and so is a folder the bench keeps its own files in. Both log folders may be one folder. The first fault from the left is the answer.
On CARD_FOLDER_OK, out (when not NULL) takes the path in upper case; at most 17 characters and the terminator. Otherwise out is left as it was.
- Parameters
-
| in | The folder path to check. |
| out | Receives the path in upper case when accepted, or NULL. |
| n | Size of out, bytes. |
- Returns
- CARD_FOLDER_OK, or the first fault found.
◆ card_folder_use()
| const char * card_folder_use |
( |
const char * | text, |
|
|
const char * | fallback, |
|
|
char * | out, |
|
|
size_t | n ) |
The folder a log is written to: text in upper case when card_folder_check() takes it, fallback otherwise.
Written into out, CARD_DIR_MAX bytes or more, and returned. A stored folder that no longer passes the check is never written to.
- Parameters
-
| text | The stored folder path. |
| fallback | The folder to use when text does not pass. |
| out | Receives the chosen folder path. |
| n | Size of out, bytes. |
- Returns
out, holding the chosen folder path.
◆ card_make_dirs()
Make folder dir one level at a time, the shortest first: for "BENCH/KST/CONF", "BENCH", then "BENCH/KST", then "BENCH/KST/CONF".
The first level that is not a folder afterwards ends it, and its answer is the result. CARD_ROOT makes nothing and is CARD_DIR_OK.
- Parameters
-
| dir | The folder path, from the card's root. |
| make | Makes one level. |
| ctx | Context passed to make. |
- Returns
- The result of the last level made, or CARD_DIR_OK for the root.
◆ folder_char()
| bool folder_char |
( |
char | c | ) |
|
|
static |
Whether a character is allowed in a folder name.
- Parameters
-
| c | The upper-case character. |
- Returns
- true for A-Z, 0-9, "_" and "-".
◆ is_bench()
| bool is_bench |
( |
const char * | path | ) |
|
|
static |
Whether path is a bench area folder or one below it.
- Parameters
-
| path | The upper-case path, folders separated by "/". |
- Returns
- true for BENCH/ESC, BENCH/KST, BENCH/HITEC and below.
◆ is_device()
| bool is_device |
( |
const char * | name, |
|
|
size_t | len ) |
|
static |
Whether a folder name is a device name.
- Parameters
-
| name | The name; not NUL-terminated. |
| len | Length of name, characters. |
- Returns
- true for CON, PRN, AUX, NUL, COM1 to COM9 and LPT1 to LPT9.
◆ k_bench_conf
| const char* const k_bench_conf[] |
|
static |
Initial value: = {
}
#define CARD_KST_CONF
KST and Chaservo servo files, their backups and the write record.
Definition card_tree.h:86
#define CARD_ESC_CONF
ESC profile overrides, <id>.json.
Definition card_tree.h:81
#define CARD_HITEC_CONF
The Hitec programmer's files.
Definition card_tree.h:91
The folders the bench keeps its own files in: the parent of each programmer's CONF folder.
A log folder there, or below, is refused.