fileutil::magic::rt(3tcl)
fileutil::magic::rt π
okay bestie, this is the fileutil::magic::rt page from the file utilities corner of the manual (that's the 3tcl manual section, iykyk). Sit down, hydrate, we're learning the runtime core for file type recognition engines. π¦
β¨ NAME β¨
fileutil::magic::rt β Runtime core for file type recognition engines written in pure Tcl πΈ
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require fileutil::magic::rt ?2.0?
::fileutil::magic::rt::>
::fileutil::magic::rt::<
::fileutil::magic::rt::new chan named analyze
::fileutil::magic::rt::file_start name
::fileutil::magic::rt::emit msg
::fileutil::magic::rt::O where
::fileutil::magic::rt::R where
::fileutil::magic::rt::Nv type offset compinvert comp expected
::fileutil::magic::rt::N type offset testinvert compinvert mod mand comp
expected
::fileutil::magic::rt::S type offset testinvert mod mand comp val
::fileutil::magic::rt::L newlevel
::fileutil::magic::rt::I offset it ioi ioo iir io
::fileutil::magic::rt::R offset
::fileutil::magic::rt::U fileindex name
β¨ DESCRIPTION β¨
So basically this package is the runtime core for file type recognition engines written in pure Tcl. Which means every other package in this module is lowkey leaning on it β like fileutil::magic::filetype, and the two compiler packages fileutil::magic::cgen and fileutil::magic::cfront. It's giving main character energy, honestly. π
β¨ COMMANDS β¨
::fileutil::magic::rt::>β Increment the level and perform related housekeeping π::fileutil::magic::rt::<β Decrement the level and perform related housekeeping π«Ά::fileutil::magic::rt::new chan named analyzeβ Create a new command which returns one description of the file each time it is called, and a code ofbreakwhen there are no more descriptions.chanis the channel containing the data to describe. The channel configuration is then managed as needed.namedis a dictionary of named tests, as generated byfileutil::magic::cfront::compile.testis a command prefix for a routine composed of the list of commands as returned byfileutil::magic::cfront::compile.::fileutil::magic::rt::file_start nameβ This command marks the start of a magic file when debugging. It returns the empty string as its result. π::fileutil::magic::rt::emit msgβ This command adds the textmsgto the result buffer. The message may contain the following special character sequences. They will be replaced with buffered values before the message is added to the result. The command returns the empty string as its result. β¨\bβ This sequence is removed%sβ Replaced with the last buffered string value.%ldβ Replaced with the last buffered numeric value.%dβ See above.${x:...?...}β Substitute one string if the file is executable, and another string otherwise.
::fileutil::magic::rt::O whereβ Produce an offset fromwhere, relative to the cursor one level up. Produce an offset fromwhere, relative to the offset one level up.::fileutil::magic::rt::Nv type offset compinvert comp expectedβ A limited form of::fileutile::magic::rt::Nthat only checks for equality and can't be told to invert the test. π::fileutil::magic::rt::N type offset testinvert compinvert mod mand comp expectedβ Fetch the numeric value withtypefrom the absolute locationoffset, compare it withexpectedusingcompas the comparision operator, and returns the result.
The argument comp must be one of Tcl's comparison operators.
<comp> <fetched-and-masked-value> <comp> <expected>
The special comparison operator x signals that no comparison should be done, or, in other words, that the fetched value will always match val. π₯
::fileutil::magic::rt::S type offset testinvert mod mand comp valβ Like::fileutil::magic::rt::Nexcept that it fetches and compares string types , not numeric data.::fileutil::magic::rt::L newlevelβ Sets the current level in the calling context tonewlevel. The command returns the empty string as its result.::fileutil::magic::rt::I offset it ioi ioo iir ioβ Calculates an offset based on an initial offset and the provided modifiers.::fileutil::magic::rt::R offsetβ Given an initial offset, calculates an offset relative to the cursor at the next level up. The cursor is the position in the data one character after the data extracted from the file one level up. π::fileutil::magic::rt::U fileindex nameβ Add a level and use a named test script.
β¨ NUMERIC TYPES β¨
ok so these are the types you can throw at the numeric commands, and there are a lot of them. stay with me. π
byteβ 8-bit integershortβ 16-bit integer, stored in native endianessbeshortβ see above, stored in big endianleshortβ see above, stored in small/little endianlongβ 32-bit integer, stored in native endianessbelongβ see above, stored in big endianlelongβ see above, stored in small/little endian
All of the types above exit in an unsigned form as well. The type names are the same, with the character "u" added as prefix. π
dateβ 32-bit integer timestamp, stored in native endianessbedateβ see above, stored in big endianledateβ see above, stored in small/little endianldateβ 32-bit integer timestamp, stored in native endianessbeldateβ see above, stored in big endianleldateβ see above, stored in small/little endian
π BUGS, IDEAS, FEEDBACK π
ngl bestie, this document, and the package it describes, will undoubtedly contain bugs and other problems. π Please report such in the category fileutil :: magic of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation. We want them fr fr. π«Ά
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. π
β¨ SEE ALSO β¨
β¨ KEYWORDS β¨
file recognition, file type, file utilities, mime, type
β¨ CATEGORY β¨
Programming tools
tcllib Β· version 2.0 Β· fileutil::magic::rt(3tcl) β and that's the whole page, bestie. You ate this. Go read some file magic, periodt. πβ¨π
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms