Tcl Library Source Code

fileutil::magic::rt - file utilities
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2018 Conference, Houston/TX, US, Oct 15-19
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Aug 20.

[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

fileutil::magic::rt(n) 2.0 tcllib "file utilities"

Name

fileutil::magic::rt - Runtime core for file type recognition engines written in pure Tcl

Description

This package provides the runtime core for file type recognition engines written in pure Tcl and is thus used by all other packages in this module such as fileutil::magic::filetype and the two compiler packages fileutil::magic::cgen and fileutil::magic::cfront.

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 of break when there are no more descriptions. chan is the channel containing the data to describe. The channel configuration is then managed as needed. named is a dictionary of named tests, as generated by fileutil::magic::cfront::compile. test is a command prefix for a routine composed of the list of commands as returned by fileutil::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 text msg to 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 from where, relative to the cursor one level up. Produce an offset from where, relative to the offset one level up.

::fileutil::magic::rt::Nv type offset compinvert comp expected

A limited form of ::fileutile::magic::rt::N that 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 with type from the absolute location offset, compare it with expected using comp as 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::N except that it fetches and compares string types , not numeric data.

::fileutil::magic::rt::L newlevel

Sets the current level in the calling context to newlevel. 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

byte

8-bit integer

short

16-bit integer, stored in native endianess

beshort

see above, stored in big endian

leshort

see above, stored in small/little endian

long

32-bit integer, stored in native endianess

belong

see above, stored in big endian

lelong

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 endianess

bedate

see above, stored in big endian

ledate

see above, stored in small/little endian

ldate

32-bit integer timestamp, stored in native endianess

beldate

see above, stored in big endian

leldate

see above, stored in small/little endian

Bugs, Ideas, Feedback

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. Please also report any ideas for enhancements you may have for either package and/or documentation.

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

file(1), fileutil, magic(5)

Category

Programming tools