Skip to main content

Module ascmagic

Module ascmagic 

Source
Expand description

Minimal text/data fallback classification, modeled on GNU file’s file_ascmagic (src/ascmagic.c).

When no magic rule produces a usable description – either because no rule matched at all, or because every rule that matched carries no description text (GOTCHAS S13.2) – GNU file never prints a blank line. It falls back to a basic content classification: "empty" for a zero-byte file, "ASCII text" for plain textual content, a Unicode variant for valid non-ASCII UTF-8, and "data" for anything else (binary content).

§Scope

This is a deliberately narrow subset of GNU file’s real charset detection, which additionally distinguishes ISO-8859 variants, UTF-16, line-ending styles, and several “text with X” qualifiers (escape sequences, overstriking, CRLF terminators, byte-order marks, etc. – see src/ascmagic.c and src/encoding.c upstream). Replicating that fully is out of scope for this fallback: the goal here is solely to ensure the CLI never emits a blank description for a readable file (the assembler-source-text and plain-ASCII-text bugs this module fixes), not full charset fidelity. Every classification below is a true subset of what GNU file would print for the same input – e.g. file prints "ASCII text, with CRLF line terminators" for a CRLF-terminated buffer where we print plain "ASCII text" – so differential tests that check for a specific classification (rather than exact byte-for-byte output) still hold.

Functions§

classify_fallback
Classify a buffer using the minimal text/data fallback described in the module doc.