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

One pane of the file manager: its folder, its page and its selection (fm_tree.h). More...

#include "fm_tree.h"
#include <string.h>
#include "fm_select.h"
#include "log_name.h"

Data Structures

struct  pane_walk_t
 One walk of the pane's folder on its way into the page. More...

Functions

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.
static void take (const fm_dirent_t *e, void *vctx)
 Offer one entry of a walk to the page: every name that fits, with what the rules say of it; a longer one is counted.
static void empty_page (fm_tree_t *tree, int total)
 Empty the page, for a folder that could not be read.
static fm_err_t walk_once (fm_tree_t *tree, const fm_io_t *io, const fm_bench_t *bench, fm_page_dir_t side, const fm_entry_t *key)
 One walk of the folder on the mount in the slot, keeping one page.
static fm_err_t walk_twice (fm_tree_t *tree, const fm_io_t *io, const fm_bench_t *bench, fm_page_dir_t side, const fm_entry_t *key)
 One page, walked again once when the walk found the card gone: the second walk is of the card in the slot.
static fm_err_t read_page (fm_tree_t *tree, const fm_io_t *io, const fm_bench_t *bench, fm_page_dir_t side, const fm_entry_t *key)
 Read one page, and fall back to the first or the last page when the page asked for holds nothing of a folder that is not empty. Each walk is walked again once when it found the card gone.
static void reselect (fm_tree_t *tree, const char *name)
 Select the row that holds name, or nothing.
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.

Detailed Description

One pane of the file manager: its folder, its page and its selection (fm_tree.h).

SPDX-License-Identifier: MIT

Function Documentation

◆ empty_page()

void empty_page ( fm_tree_t * tree,
int total )
static

Empty the page, for a folder that could not be read.

Parameters
treethe pane
totalthe count to show: 0 for a folder not there, -1 for no card

◆ 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

◆ read_page()

fm_err_t read_page ( fm_tree_t * tree,
const fm_io_t * io,
const fm_bench_t * bench,
fm_page_dir_t side,
const fm_entry_t * key )
static

Read one page, and fall back to the first or the last page when the page asked for holds nothing of a folder that is not empty. Each walk is walked again once when it found the card gone.

Parameters
treethe pane
iothe card
benchwhat the rules need; may be NULL
sidethe side of key the page holds
keythe entry at the page's edge, the caller's copy; NULL for none
Returns
FM_OK or why not

◆ reselect()

void reselect ( fm_tree_t * tree,
const char * name )
static

Select the row that holds name, or nothing.

Parameters
treethe pane
namethe name to find; "" for none

◆ take()

void take ( const fm_dirent_t * e,
void * vctx )
static

Offer one entry of a walk to the page: every name that fits, with what the rules say of it; a longer one is counted.

Parameters
ethe entry, borrowed for the call
vctxthe walk's pane_walk_t

◆ walk_once()

fm_err_t walk_once ( fm_tree_t * tree,
const fm_io_t * io,
const fm_bench_t * bench,
fm_page_dir_t side,
const fm_entry_t * key )
static

One walk of the folder on the mount in the slot, keeping one page.

Parameters
treethe pane
iothe card
benchwhat the rules need; may be NULL
sidethe side of key the page holds
keythe entry at the page's edge, the caller's copy; NULL for none
Returns
FM_OK or why the walk failed

◆ walk_twice()

fm_err_t walk_twice ( fm_tree_t * tree,
const fm_io_t * io,
const fm_bench_t * bench,
fm_page_dir_t side,
const fm_entry_t * key )
static

One page, walked again once when the walk found the card gone: the second walk is of the card in the slot.

Parameters
treethe pane
iothe card
benchwhat the rules need; may be NULL
sidethe side of key the page holds
keythe entry at the page's edge, the caller's copy; NULL for none
Returns
FM_OK or why not