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

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>

Functions

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.

Variables

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.

Detailed Description

Making a folder of the card one level at a time, and checking a log folder.

See card_tree.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ 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
inThe folder path to check.
outReceives the path in upper case when accepted, or NULL.
nSize 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
textThe stored folder path.
fallbackThe folder to use when text does not pass.
outReceives the chosen folder path.
nSize of out, bytes.
Returns
out, holding the chosen folder path.

◆ card_make_dirs()

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

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
dirThe folder path, from the card's root.
makeMakes one level.
ctxContext 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
cThe 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
pathThe 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
nameThe name; not NUL-terminated.
lenLength of name, characters.
Returns
true for CON, PRN, AUX, NUL, COM1 to COM9 and LPT1 to LPT9.

Variable Documentation

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