1fileutil::magic::rt(n) file utilities fileutil::magic::rt(n)
2
3
4
5______________________________________________________________________________
6
8 fileutil::magic::rt - Runtime core for file type recognition engines
9 written in pure Tcl
10
12 package require Tcl 8.5
13
14 package require fileutil::magic::rt ?2.0?
15
16 ::fileutil::magic::rt::>
17
18 ::fileutil::magic::rt::<
19
20 ::fileutil::magic::rt::new chan named analyze
21
22 ::fileutil::magic::rt::file_start name
23
24 ::fileutil::magic::rt::emit msg
25
26 ::fileutil::magic::rt::O where
27
28 ::fileutil::magic::rt::R where
29
30 ::fileutil::magic::rt::Nv type offset compinvert comp expected
31
32 ::fileutil::magic::rt::N type offset testinvert compinvert mod mand
33 comp expected
34
35 ::fileutil::magic::rt::S type offset testinvert mod mand comp val
36
37 ::fileutil::magic::rt::L newlevel
38
39 ::fileutil::magic::rt::I offset it ioi ioo iir io
40
41 ::fileutil::magic::rt::R offset
42
43 ::fileutil::magic::rt::U fileindex name
44
45______________________________________________________________________________
46
48 This package provides the runtime core for file type recognition en‐
49 gines written in pure Tcl and is thus used by all other packages in
50 this module such as fileutil::magic::filetype and the two compiler
51 packages fileutil::magic::cgen and fileutil::magic::cfront.
52
54 ::fileutil::magic::rt::>
55 Increment the level and perform related housekeeping
56
57 ::fileutil::magic::rt::<
58 Decrement the level and perform related housekeeping
59
60 ::fileutil::magic::rt::new chan named analyze
61 Create a new command which returns one description of the file
62 each time it is called, and a code of break when there are no
63 more descriptions. chan is the channel containing the data to
64 describe. The channel configuration is then managed as needed.
65 named is a dictionary of named tests, as generated by fileu‐
66 til::magic::cfront::compile. test is a command prefix for a
67 routine composed of the list of commands as returned by fileu‐
68 til::magic::cfront::compile.
69
70 ::fileutil::magic::rt::file_start name
71 This command marks the start of a magic file when debugging. It
72 returns the empty string as its result.
73
74 ::fileutil::magic::rt::emit msg
75 This command adds the text msg to the result buffer. The message
76 may contain the following special character sequences. They will
77 be replaced with buffered values before the message is added to
78 the result. The command returns the empty string as its result.
79
80 \b This sequence is removed
81
82 %s Replaced with the last buffered string value.
83
84 %ld Replaced with the last buffered numeric value.
85
86 %d See above.
87
88 ${x:...?...}
89 Substitute one string if the file is executable, and an‐
90 other string otherwise.
91
92 ::fileutil::magic::rt::O where
93 Produce an offset from where, relative to the cursor one level
94 up. Produce an offset from where, relative to the offset one
95 level up.
96
97 ::fileutil::magic::rt::Nv type offset compinvert comp expected
98 A limited form of ::fileutile::magic::rt::N that only checks for
99 equality and can't be told to invert the test.
100
101 ::fileutil::magic::rt::N type offset testinvert compinvert mod mand
102 comp expected
103 Fetch the numeric value with type from the absolute location
104 offset, compare it with expected using comp as the comparision
105 operator, and returns the result.
106
107 The argument comp must be one of Tcl's comparison operators.
108
109
110 <comp> <fetched-and-masked-value> <comp> <expected>
111
112
113 The special comparison operator x signals that no comparison should be
114 done, or, in other words, that the fetched value will always match val.
115
116 ::fileutil::magic::rt::S type offset testinvert mod mand comp val
117 Like ::fileutil::magic::rt::N except that it fetches and com‐
118 pares string types , not numeric data.
119
120 ::fileutil::magic::rt::L newlevel
121 Sets the current level in the calling context to newlevel. The
122 command returns the empty string as its result.
123
124 ::fileutil::magic::rt::I offset it ioi ioo iir io
125 Calculates an offset based on an initial offset and the provided
126 modifiers.
127
128 ::fileutil::magic::rt::R offset
129 Given an initial offset, calculates an offset relative to the
130 cursor at the next level up. The cursor is the position in the
131 data one character after the data extracted from the file one
132 level up.
133
134
135 ::fileutil::magic::rt::U fileindex name
136 Add a level and use a named test script.
137
139 byte 8-bit integer
140
141 short 16-bit integer, stored in native endianess
142
143 beshort
144 see above, stored in big endian
145
146 leshort
147 see above, stored in small/little endian
148
149 long 32-bit integer, stored in native endianess
150
151 belong see above, stored in big endian
152
153 lelong see above, stored in small/little endian
154
155 All of the types above exit in an unsigned form as well. The type names
156 are the same, with the character "u" added as prefix.
157
158 date 32-bit integer timestamp, stored in native endianess
159
160 bedate see above, stored in big endian
161
162 ledate see above, stored in small/little endian
163
164 ldate 32-bit integer timestamp, stored in native endianess
165
166 beldate
167 see above, stored in big endian
168
169 leldate
170 see above, stored in small/little endian
171
173 This document, and the package it describes, will undoubtedly contain
174 bugs and other problems. Please report such in the category fileutil
175 :: magic of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].
176 Please also report any ideas for enhancements you may have for either
177 package and/or documentation.
178
179 When proposing code changes, please provide unified diffs, i.e the out‐
180 put of diff -u.
181
182 Note further that attachments are strongly preferred over inlined
183 patches. Attachments can be made by going to the Edit form of the
184 ticket immediately after its creation, and then using the left-most
185 button in the secondary navigation bar.
186
188 file(1), fileutil, magic(5)
189
191 file recognition, file type, file utilities, mime, type
192
194 Programming tools
195
196
197
198tcllib 2.0 fileutil::magic::rt(n)