1fileutil::magic::rt(n)          file utilities          fileutil::magic::rt(n)
2
3
4
5______________________________________________________________________________
6

NAME

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

SYNOPSIS

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::open filename
21
22       ::fileutil::magic::rt::close
23
24       ::fileutil::magic::rt::file_start name
25
26       ::fileutil::magic::rt::result ?msg?
27
28       ::fileutil::magic::rt::resultv ?msg?
29
30       ::fileutil::magic::rt::emit msg
31
32       ::fileutil::magic::rt::offset where
33
34       ::fileutil::magic::rt::Nv type offset ?qual?
35
36       ::fileutil::magic::rt::N type offset comp val ?qual?
37
38       ::fileutil::magic::rt::Nvx type offset ?qual?
39
40       ::fileutil::magic::rt::Nx type offset comp val ?qual?
41
42       ::fileutil::magic::rt::S offset comp val ?qual?
43
44       ::fileutil::magic::rt::Sx offset comp val ?qual?
45
46       ::fileutil::magic::rt::L newlevel
47
48       ::fileutil::magic::rt::I base type delta
49
50       ::fileutil::magic::rt::R offset
51
52       ::fileutil::magic::rt::U fileindex name
53
54______________________________________________________________________________
55

DESCRIPTION

57       This package provides the runtime core for file  type  recognition  en‐
58       gines  written  in  pure  Tcl and is thus used by all other packages in
59       this module, i.e. the two frontend packages  fileutil::magic::mimetypes
60       and  fileutil::magic::filetypes,  and  the two engine compiler packages
61       fileutil::magic::cgen and fileutil::magic::cfront.
62

COMMANDS

64       ::fileutil::magic::rt::>
65              Shorthand for incr level.
66
67       ::fileutil::magic::rt::<
68              Shorthand for incr level -1.
69
70       ::fileutil::magic::rt::open filename
71              This command initializes the runtime and prepares the file file‐
72              name  for  use  by  the  system.  This command has to be invoked
73              first, before any other command of this package.
74
75              The command returns the channel handle of the opened file as its
76              result.
77
78       ::fileutil::magic::rt::close
79              This   command   closes   the  last  file  opened  via  ::fileu‐
80              til::magic::rt::open and shuts the runtime down.   This  command
81              has  to be invoked last, after the file has been dealt with com‐
82              pletely.    Afterward    another    invokation    of    ::fileu‐
83              til::magic::rt::open  is required to process another file.
84
85              This command returns the empty string as its result.
86
87       ::fileutil::magic::rt::file_start name
88              This  command marks the start of a magic file when debugging. It
89              returns the empty string as its result.
90
91       ::fileutil::magic::rt::result ?msg?
92              This command returns the current result and stops processing.
93
94              If msg is specified its text is added to the result before it is
95              returned.  See  ::fileutil::magic::rt::emit for the allowed spe‐
96              cial character sequences.
97
98       ::fileutil::magic::rt::resultv ?msg?
99              This  command  returns  the  current  result.   In  contrast  to
100              ::fileutil::magic::rt::result processing continues.
101
102              If msg is specified its text is added to the result before it is
103              returned. See ::fileutil::magic::rt::emit for the  allowed  spe‐
104              cial character sequences.
105
106       ::fileutil::magic::rt::emit msg
107              This command adds the text msg to the result buffer. The message
108              may contain the following special character sequences. They will
109              be  replaced with buffered values before the message is added to
110              the result. The command returns the empty string as its result.
111
112              \b     This sequence is removed
113
114              %s     Replaced with the last buffered string value.
115
116              %ld    Replaced with the last buffered numeric value.
117
118              %d     See above.
119
120       ::fileutil::magic::rt::Nv type offset ?qual?
121              This command fetches the numeric value with type from the  abso‐
122              lute  location  offset and returns it as its result. The fetched
123              value is further stored in the numeric buffer.
124
125              If qual is specified it is considered to be a mask  and  applied
126              to the fetched value before it is stored and returned. It has to
127              have the form of a partial Tcl bit-wise expression, i.e.
128
129
130                & number
131
132
133              For example:
134
135
136                Nv lelong 0 &0x8080ffff
137
138
139              For the possible types see section NUMERIC TYPES.
140
141       ::fileutil::magic::rt::N type offset comp val ?qual?
142              This command behaves mostly like ::fileutil::magic::rt::Nv,  ex‐
143              cept  that  it compares the fetched and masked value against val
144              as specified with comp and returns the result of  that  compari‐
145              son.
146
147              The  argument comp has to contain one of Tcl's comparison opera‐
148              tors, and the comparison made will be
149
150
151                <val> <comp> <fetched-and-masked-value>
152
153
154       The special comparison operator x signals that no comparison should  be
155       done, or, in other words, that the fetched value will always match val.
156
157       ::fileutil::magic::rt::Nvx type offset ?qual?
158              This command behaves like ::fileutil::magic::rt::Nv, except that
159              it additionally remembers the location in  the  file  after  the
160              fetch  in  the calling context, for the current level, for later
161              use by ::fileutil::magic::rt::R.
162
163       ::fileutil::magic::rt::Nx type offset comp val ?qual?
164              This command behaves like ::fileutil::magic::rt::N, except  that
165              it  additionally  remembers  the  location in the file after the
166              fetch in the calling context, for the current, for later use  by
167              ::fileutil::magic::rt::R.
168
169       ::fileutil::magic::rt::S offset comp val ?qual?
170              This  command behaves like ::fileutil::magic::rt::N, except that
171              it fetches and compares strings, not numeric data.  The  fetched
172              value  is  also  stored in the internal string buffer instead of
173              the numeric buffer.
174
175       ::fileutil::magic::rt::Sx offset comp val ?qual?
176              This command behaves like ::fileutil::magic::rt::S, except  that
177              it  additionally  remembers  the  location in the file after the
178              fetch in the calling context, for the current level,  for  later
179              use by ::fileutil::magic::rt::R.
180
181       ::fileutil::magic::rt::L newlevel
182              This  command  sets  the current level in the calling context to
183              newlevel. The command returns the empty string as its result.
184
185       ::fileutil::magic::rt::I base type delta
186              This command handles base locations specified indirectly through
187              the  contents of the inspected file. It returns the sum of delta
188              and the value of numeric type fetched from the absolute location
189              base.
190
191              For the possible types see section NUMERIC TYPES.
192
193       ::fileutil::magic::rt::R offset
194              This  command  handles  base locations specified relative to the
195              end of the last field one level above.
196
197              In other words, the command computes an absolute location in the
198              file  based on the relative offset and returns it as its result.
199              The base the offset is added to is the last location  remembered
200              for the level in the calling context.
201
202       ::fileutil::magic::rt::U fileindex name
203              Use a named test script at the current level.
204

NUMERIC TYPES

206       byte   8-bit integer
207
208       short  16-bit integer, stored in native endianess
209
210       beshort
211              see above, stored in big endian
212
213       leshort
214              see above, stored in small/little endian
215
216       long   32-bit integer, stored in native endianess
217
218       belong see above, stored in big endian
219
220       lelong see above, stored in small/little endian
221
222       All of the types above exit in an unsigned form as well. The type names
223       are the same, with the character "u" added as prefix.
224
225       date   32-bit integer timestamp, stored in native endianess
226
227       bedate see above, stored in big endian
228
229       ledate see above, stored in small/little endian
230
231       ldate  32-bit integer timestamp, stored in native endianess
232
233       beldate
234              see above, stored in big endian
235
236       leldate
237              see above, stored in small/little endian
238

BUGS, IDEAS, FEEDBACK

240       This document, and the package it describes, will  undoubtedly  contain
241       bugs  and  other problems.  Please report such in the category fileutil
242       :: magic of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].
243       Please  also  report any ideas for enhancements you may have for either
244       package and/or documentation.
245
246       When proposing code changes, please provide unified diffs, i.e the out‐
247       put of diff -u.
248
249       Note  further  that  attachments  are  strongly  preferred over inlined
250       patches. Attachments can be made by going  to  the  Edit  form  of  the
251       ticket  immediately  after  its  creation, and then using the left-most
252       button in the secondary navigation bar.
253

SEE ALSO

255       file(1), fileutil, magic(5)
256

KEYWORDS

258       file recognition, file type, file utilities, mime, type
259

CATEGORY

261       Programming tools
262
263
264
265tcllib                                2.0               fileutil::magic::rt(n)
Impressum