Function Entry: CLAL-FILE-ENCODING
← Prev | ↑ Chapter | Next → | Index | Symbols
Function Entry: CLAL-FILE-ENCODING
Name
clal-file-encoding
Class
clautolisp Extension Function
Syntax
(clal-file-encoding path)
Arguments and Values
path– AutoLISP string. Filename to sniff; resolved against the AutoLISP search path the same wayLOADwould. Need not be a.lspsource file; any file is accepted.
Description
Open path, read up to the first four bytes, and return the
canonical clautolisp encoding implied by the byte-order mark:
| BOM bytes | Returned string |
|---|---|
EF BB BF |
"UTF-8-BOM" |
FF FE |
"UTF-16-LE" |
FE FF |
"UTF-16-BE" |
FF FE 00 00 |
"UTF-32-LE" |
00 00 FE FF |
"UTF-32-BE" |
| no BOM | "ANSI" |
UTF-32-LE and UTF-16-LE share their first two bytes; the sniffer checks UTF-32 first so the two-byte UTF-16 prefix doesn't mask a four-byte UTF-32 BOM.
clal-file-encoding is the clautolisp counterpart to BricsCAD's
vle-file-encoding. Differences:
- Returns canonical clautolisp strings (e.g.
"UTF-16-LE") rather than vendor strings ("UTF-16LE"). - Preserves the UTF-8-BOM / plain-UTF-8 distinction. BricsCAD
reports plain
"UTF-8"in both cases; clautolisp reports"UTF-8-BOM"when the marker is present, letting user code decide between rewriting the BOM and dropping it. - Returns
"ANSI"rather than the bare empty string when no BOM is detected — the file might be ANSI, UTF-8 without BOM, or something else; without a marker the encoding is undetermined and falls back to the host code page.
Return Values
- AutoLISP string when the file exists and is readable.
nilwhen the file cannot be resolved; also setsERRNOto73(same convention asLOAD's missing-file path).
Side Effects
- Opens
pathfor reading and immediately closes it. - Sets
ERRNOto73on resolution failure,0on success.
Affected By
- The AutoLISP search-path used by
LOAD.
Exceptional Situations
- Returns
nilrather than signalling for the common "file not found" case; user code can chainclal-file-encodinginto a presence check.
Examples
;; UTF-8 source with a BOM. (clal-file-encoding "lib/with-bom.lsp") => "UTF-8-BOM" ;; BOMless source (could be anything from US-ASCII to ANSI to ;; UTF-8-without-BOM; we don't speculate). (clal-file-encoding "lib/plain.lsp") => "ANSI" ;; Nonexistent path -> nil + ERRNO 73. (clal-file-encoding "/no/such/file") => nil (getvar "ERRNO") => 73
Availability
- clautolisp: documented (this entry); implemented since clautolisp 1.0.83.
- AutoCAD: NOT present.
- BricsCAD:
vle-file-encodingis the analogue but does not preserve the UTF-8-BOM distinction and uses vendor strings.
Source Notes
- clautolisp-only extension. See encoding-dispatch.issue for the cross-dialect translation table this helper's vocabulary matches.