ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
sh_classify.h File Reference

Book-format classification by file extension (long-name aware, #633). More...

#include <stddef.h>
#include <stdint.h>
#include <string.h>
Include dependency graph for sh_classify.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  sh_book_fmt_t : uint8_t {
  k_sh_fmt_rabook = 0U ,
  k_sh_fmt_epub = 1U ,
  k_sh_fmt_cbz = 2U ,
  k_sh_fmt_cbr = 3U ,
  k_sh_fmt_cbt = 4U
}
 Book container format behind a shelf entry / the open book. More...

Functions

static bool sh_fmt_is_comic (sh_book_fmt_t fmt)
 True if fmt is a comic-archive container (CBZ, CBR, or CBT).
static char sh_ascii_lower (char c)
 Fold one ASCII letter to lower case (non-letters returned unchanged).
static bool sh_ext_match (const char *name, const char *ext)
 Case-insensitive test that name ends in the extension ext.
static bool sh_book_classify (const char *name, sh_book_fmt_t *out_fmt)
 Classify a root file name into a book format; true if it is a book.

Detailed Description

Book-format classification by file extension (long-name aware, #633).

The shelf scans the FAT root and decides which files are books and in what container format. Since #600 gave ra8_fs VFAT long-name write, the card carries real extensions (.rabook, .epub) rather than the 8.3 truncations (.RBK, .EPB) the tools used to emit, so the classifier matches BOTH: the long forms and, so existing 8.3-named cards still resolve, the legacy short forms. Matching is case-insensitive because FAT hands back 8.3 names upper-cased while long names keep their authored case.

This header is board-free (string logic only), so sh_sd.c and the host classification test share one implementation instead of a copy.

Since
0.1.0

Definition in file sh_classify.h.

Enumeration Type Documentation

◆ sh_book_fmt_t

enum sh_book_fmt_t : uint8_t

Book container format behind a shelf entry / the open book.

Both text formats render through the same screens via the sh_book.c backend: .rabook is the pre-parsed book blob, demand-paged through the chunked reader (baked or on SD); .epub is parsed on-device by epub (SD only). The three comic containers route through sh_comic.c as image-page readers.

Since
0.1.0
Enumerator
k_sh_fmt_rabook 

book RBKC container (demand-paged chunks).

k_sh_fmt_epub 

EPUB parsed on-device by epub.

k_sh_fmt_cbz 

Comic archive: ZIP of page images (.cbz).

k_sh_fmt_cbr 

Comic archive: RAR of page images (.cbr).

k_sh_fmt_cbt 

Comic archive: tar of page images (.cbt).

Definition at line 37 of file sh_classify.h.

Function Documentation

◆ sh_ascii_lower()

char sh_ascii_lower ( char c)
inlinestatic

Fold one ASCII letter to lower case (non-letters returned unchanged).

Parameters
[in]cByte to fold.
Returns
The lower-case letter, or c unchanged when it is not A..Z.
Return values
charCase-folded byte.
Precondition
c is a single byte.
Postcondition
No state is modified (pure function).
Note
Thread-safe: pure function of its argument.
Since
0.1.0

Definition at line 74 of file sh_classify.h.

Referenced by sh_ext_match().

◆ sh_book_classify()

bool sh_book_classify ( const char * name,
sh_book_fmt_t * out_fmt )
inlinestatic

Classify a root file name into a book format; true if it is a book.

Recognises the long extensions the tools now write (.rabook, .epub) and, so existing 8.3-named cards keep resolving, their legacy 8.3 truncations (.rbk, .epb). Comics already had 3-char extensions, so .cbz / .cbr / .cbt never truncated. Matching is case-insensitive (sh_ext_match).

Parameters
[in]nameNUL-terminated root file name (non-NULL).
[out]out_fmtReceives the container format when name is a book.
Returns
Whether name names a book this shelf can open.
Return values
truename matched a known book extension; *out_fmt is set.
falsename is not a book; *out_fmt is untouched.
Precondition
name and out_fmt are non-NULL.
name is a single root directory entry name.
Postcondition
On true *out_fmt holds the classified sh_book_fmt_t.
On false no output is written.
Note
Thread-safe: writes only out_fmt.
Since
0.1.0

Definition at line 129 of file sh_classify.h.

References k_sh_fmt_cbr, k_sh_fmt_cbt, k_sh_fmt_cbz, k_sh_fmt_epub, k_sh_fmt_rabook, and sh_ext_match().

Referenced by sh_sd_listdir_cb().

◆ sh_ext_match()

bool sh_ext_match ( const char * name,
const char * ext )
inlinestatic

Case-insensitive test that name ends in the extension ext.

Requires at least one character before ext, so a name that is only the extension (e.g. .epub) is not a book. Folds both sides to lower case, so .EPB matches .epb and Book.EPUB matches .epub.

Parameters
[in]nameNUL-terminated file name (non-NULL).
[in]extNUL-terminated extension including its dot, e.g. .rabook.
Returns
Whether name ends in ext with a non-empty stem.
Return values
truename is longer than ext and its tail case-matches ext.
falsename is not longer than ext or the tail differs.
Precondition
name and ext are non-NULL and NUL-terminated.
ext is a file extension leading with ..
Postcondition
No state is modified (pure function).
Note
Thread-safe: pure function over its arguments.
Since
0.1.0

Definition at line 95 of file sh_classify.h.

References sh_ascii_lower(), and strlen().

Referenced by sh_book_classify().

◆ sh_fmt_is_comic()

bool sh_fmt_is_comic ( sh_book_fmt_t fmt)
inlinestatic

True if fmt is a comic-archive container (CBZ, CBR, or CBT).

Both route through sh_comic.c (::comic) rather than the text-book screens, so this predicate is the single dispatch test the shelf/open path branches on.

Parameters
[in]fmtContainer format from a shelf entry / the open book.
Returns
true for k_sh_fmt_cbz, k_sh_fmt_cbr, or k_sh_fmt_cbt.
Return values
truefmt is a comic archive (image-page reader).
falsefmt is a text book (rabook / epub).
Precondition
fmt is a valid sh_book_fmt_t.
Postcondition
No state is modified (pure predicate).
Note
Thread-safe: pure function of its argument.
Since
0.1.0

Definition at line 59 of file sh_classify.h.

References k_sh_fmt_cbr, k_sh_fmt_cbt, and k_sh_fmt_cbz.

Referenced by sh_book_open(), sh_comic_open(), and sh_select_book().