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

One pane of the file manager: a folder of the card, the page of its entries on show, and the row selected. More...

#include <stdbool.h>
#include <stdint.h>
#include "fm_io.h"
#include "fm_rules.h"

Go to the source code of this file.

Data Structures

struct  fm_entry_t
 One entry of a page. More...
struct  fm_tree_t
 One pane. The fields are the pane's; read them, change them through the functions. More...

Macros

#define FM_PAGE_MAX   48
 Rows of one page, as LOGS' page (LOG_VIEWER_MAX_FILES).

Enumerations

enum  fm_go_t {
  FM_GO_FIRST = 0 , FM_GO_NEXT , FM_GO_PREV , FM_GO_LAST ,
  FM_GO_SAME
}
 Which page fm_tree_page() reads. More...

Functions

void fm_tree_init (fm_tree_t *tree, const char *dir)
 Start a pane in folder dir, with nothing read yet.
fm_err_t fm_tree_page (fm_tree_t *tree, const fm_io_t *io, const fm_bench_t *bench, fm_go_t go)
 Read a page of the pane's folder.
fm_err_t fm_tree_enter (fm_tree_t *tree, const fm_io_t *io, const fm_bench_t *bench, int row)
 Enter the folder on row row and read its first page.
fm_err_t fm_tree_up (fm_tree_t *tree, const fm_io_t *io, const fm_bench_t *bench)
 Go to the folder above and read its first page, with the folder come from selected when it is on that page.
fm_err_t fm_tree_select (fm_tree_t *tree, int row)
 Select row row, or nothing for -1.
const fm_entry_t * fm_tree_selected (const fm_tree_t *tree)
 The selected entry.
bool fm_tree_has_prev (const fm_tree_t *tree)
 Whether a page stands before the one on show.
bool fm_tree_has_next (const fm_tree_t *tree)
 Whether a page stands after the one on show.
int fm_tree_rank (const void *a, const void *b)
 The pane's order of two entries: folders first, then names with case folded, then their bytes. Strict: zero only for one name.

Detailed Description

One pane of the file manager: a folder of the card, the page of its entries on show, and the row selected.

A page is up to FM_PAGE_MAX entries in the pane's order: folders first, then names with case folded, ascending; two names that differ only in case, which FAT (File Allocation Table) does not hold, follow by their bytes. ".." is not a row. A page is read by one walk of the folder and kept by fm_select.h while the walk runs, so a folder of 999 files costs one walk per page and the memory of one page. NEXT and PREV are named by the entry at the page's edge, not by a number: a page reads on from the one before it after a file came or went.

A name over FM_LIST_NAME_MAX bytes is not listed: the panel's walk cannot hand it over whole, and a cut name opens nothing. The pane counts them, and the entries the walk leaves out (names starting with "."), as unlisted, so the screen can say so.

Every entry carries what the rules say of it (fm_rules.h) when the page was read: its kind, its place and whether the logger writes it. A job asks the rules again when it starts: a page is a picture of the folder, not a promise.

A page is read from one mount (fm_io.h). A walk that found the card gone and another one mounted is walked again once, on the card in the slot; mount says which card the page is of, and a caller that sees it change knows the card was swapped.

Pure C, no ESP-IDF (Espressif Internet-of-Things Development Framework).

SPDX-License-Identifier: MIT

Enumeration Type Documentation

◆ fm_go_t

enum fm_go_t

Which page fm_tree_page() reads.

Enumerator
FM_GO_FIRST 

the folder's first page

FM_GO_NEXT 

the page after the one on show

FM_GO_PREV 

the page before the one on show

FM_GO_LAST 

the folder's last page

FM_GO_SAME 

the page on show again, from its first entry

Function Documentation

◆ fm_tree_enter()

fm_err_t fm_tree_enter ( fm_tree_t * tree,
const fm_io_t * io,
const fm_bench_t * bench,
int row )

Enter the folder on row row and read its first page.

On a failure the pane stays in its folder and reads its page again.

Parameters
treethe pane
iothe card
benchwhat the rules need; may be NULL
rowa row of the page
Returns
FM_OK; FM_ERR_ARG for a row that is not a folder; FM_ERR_NAME for a path fm_path_join() refuses, too long or too deep; what fm_tree_page() answers for the new folder

◆ fm_tree_has_next()

bool fm_tree_has_next ( const fm_tree_t * tree)

Whether a page stands after the one on show.

Parameters
treethe pane
Returns
true when NEXT has somewhere to go

◆ fm_tree_has_prev()

bool fm_tree_has_prev ( const fm_tree_t * tree)

Whether a page stands before the one on show.

Parameters
treethe pane
Returns
true when PREV has somewhere to go

◆ fm_tree_init()

void fm_tree_init ( fm_tree_t * tree,
const char * dir )

Start a pane in folder dir, with nothing read yet.

Parameters
treethe pane
dirthe folder, a path from the root; NULL is the root. A path fm_path_check() refuses is the root.

◆ fm_tree_page()

fm_err_t fm_tree_page ( fm_tree_t * tree,
const fm_io_t * io,
const fm_bench_t * bench,
fm_go_t go )

Read a page of the pane's folder.

The selection stays on its name when the name is on the new page, and is cleared otherwise. A page past the folder's end, which a file deleted at the edge leaves, is the last page.

Parameters
treethe pane
iothe card
benchwhat the rules need; may be NULL
gowhich page
Returns
FM_OK; FM_ERR_NOT_FOUND for a folder not there, with an empty page; FM_ERR_NO_CARD; FM_ERR_CARD_GONE when the card was gone at both walks; FM_ERR_IO; FM_ERR_ARG for a NULL

◆ fm_tree_rank()

int fm_tree_rank ( const void * a,
const void * b )

The pane's order of two entries: folders first, then names with case folded, then their bytes. Strict: zero only for one name.

Parameters
aan fm_entry_t
ban fm_entry_t
Returns
negative when a stands above b

◆ fm_tree_select()

fm_err_t fm_tree_select ( fm_tree_t * tree,
int row )

Select row row, or nothing for -1.

Parameters
treethe pane
rowa row of the page, or -1
Returns
FM_OK; FM_ERR_ARG for a row not on the page

◆ fm_tree_selected()

const fm_entry_t * fm_tree_selected ( const fm_tree_t * tree)

The selected entry.

Parameters
treethe pane
Returns
the entry, or NULL with none selected

◆ fm_tree_up()

fm_err_t fm_tree_up ( fm_tree_t * tree,
const fm_io_t * io,
const fm_bench_t * bench )

Go to the folder above and read its first page, with the folder come from selected when it is on that page.

Parameters
treethe pane
iothe card
benchwhat the rules need; may be NULL
Returns
FM_OK; FM_ERR_ARG in the root; what fm_tree_page() answers