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

The file manager's names and paths (fm_name.h). More...

#include "fm_name.h"
#include <string.h>

Functions

static char lower (char c)
 c in lower case, for ASCII.
static bool same3 (const char *s, size_t n, const char *word)
 Whether the n bytes at s, in any case, are the 3 of word.
static bool device (const char *s, size_t n)
 Whether the stem of a name, the n bytes before its first full stop, is a device name.
static size_t name_char (const unsigned char *s)
 Bytes of the character at s a name may hold: printable ASCII but the marks a FAT name cannot hold, or a German letter.
fm_name_t fm_name_check (const char *name)
 Whether a person may give a file or a folder the name name.
bool fm_name_new (const char *name, char *out, size_t n)
 The name a save writes first: name and FM_NEW_SUFFIX.
static bool path_name (const char *s, size_t n)
 Whether the n bytes at s are a name a path may hold: not empty, not "." or "..", and without "/".
fm_path_t fm_path_check (const char *path)
 Whether path is a folder path: "" or names separated by one "/", at most FM_PATH_MAX bytes and FM_DEPTH_MAX folders.
size_t fm_path_depth (const char *path)
 Folders in path.
fm_path_t fm_path_join (const char *dir, const char *name, bool is_dir, char *out, size_t n)
 The path of name in folder dir: "name" in the root, "dir/name" elsewhere.
bool fm_path_up (char *path)
 Take the last name off path, in place: up one folder.
const char * fm_path_base (const char *path)
 The last name of path.

Detailed Description

The file manager's names and paths (fm_name.h).

SPDX-License-Identifier: MIT

Function Documentation

◆ device()

bool device ( const char * s,
size_t n )
static

Whether the stem of a name, the n bytes before its first full stop, is a device name.

Parameters
sThe name.
nBytes of its stem.
Returns
true for CON, PRN, AUX, NUL, COM1 to COM9 and LPT1 to LPT9.

◆ fm_name_check()

fm_name_t fm_name_check ( const char * name)

Whether a person may give a file or a folder the name name.

Parameters
nameThe name, UTF-8.
Returns
FM_NAME_OK, or the first rule it breaks, in the order of fm_name_t.

◆ fm_name_new()

bool fm_name_new ( const char * name,
char * out,
size_t n )

The name a save writes first: name and FM_NEW_SUFFIX.

Parameters
nameThe file's name.
outOut: the name; left as it was when refused.
nRoom in out.
Returns
false for a NULL, an empty name, a name over FM_NAME_MAX bytes or an out without room.

◆ fm_path_base()

const char * fm_path_base ( const char * path)

The last name of path.

Parameters
pathA path.
Returns
Inside path; "" for the root and NULL.

◆ fm_path_check()

fm_path_t fm_path_check ( const char * path)

Whether path is a folder path: "" or names separated by one "/", at most FM_PATH_MAX bytes and FM_DEPTH_MAX folders.

Parameters
pathThe path.
Returns
FM_PATH_OK, or the first fault: ARG, LONG, BAD, DEEP.

◆ fm_path_depth()

size_t fm_path_depth ( const char * path)

Folders in path.

Parameters
pathA path fm_path_check() takes.
Returns
0 for the root and NULL.

◆ fm_path_join()

fm_path_t fm_path_join ( const char * dir,
const char * name,
bool is_dir,
char * out,
size_t n )

The path of name in folder dir: "name" in the root, "dir/name" elsewhere.

out may be dir itself, so a pane goes down into a folder in place. The name may be any name the card lists; fm_name_check() is the rule for names a person types.

Parameters
dirA folder path.
nameA name without "/".
is_dirWhether name is a folder: the path then counts it in its depth.
outOut: the path; left as it was when refused.
nRoom in out.
Returns
FM_PATH_OK, or the first fault: ARG, then dir's, then BAD for the name, LONG, DEEP, and ARG for an out without room.

◆ fm_path_up()

bool fm_path_up ( char * path)

Take the last name off path, in place: up one folder.

Parameters
pathA path fm_path_check() takes.
Returns
false at the root and for NULL; path is unchanged then.

◆ lower()

char lower ( char c)
static

c in lower case, for ASCII.

Parameters
cA character.
Returns
Its lower case; other characters as they are.

◆ name_char()

size_t name_char ( const unsigned char * s)
static

Bytes of the character at s a name may hold: printable ASCII but the marks a FAT name cannot hold, or a German letter.

Parameters
sThe name at the character.
Returns
1 or 2; 0 for a character no name holds.

◆ path_name()

bool path_name ( const char * s,
size_t n )
static

Whether the n bytes at s are a name a path may hold: not empty, not "." or "..", and without "/".

Parameters
sThe name.
nIts bytes.
Returns
true for a name.

◆ same3()

bool same3 ( const char * s,
size_t n,
const char * word )
static

Whether the n bytes at s, in any case, are the 3 of word.

Parameters
sThe bytes.
nTheir count.
word3 lower-case letters.
Returns
true when they are the same.