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.4
13
14       package require fileutil::magic::rt  ?1.0?
15
16       ::fileutil::magic::rt::open filename
17
18       ::fileutil::magic::rt::close
19
20       ::fileutil::magic::rt::file_start name
21
22       ::fileutil::magic::rt::result ?msg?
23
24       ::fileutil::magic::rt::resultv ?msg?
25
26       ::fileutil::magic::rt::emit msg
27
28       ::fileutil::magic::rt::offset where
29
30       ::fileutil::magic::rt::Nv type offset ?qual?
31
32       ::fileutil::magic::rt::N type offset comp val ?qual?
33
34       ::fileutil::magic::rt::Nvx atlevel type offset ?qual?
35
36       ::fileutil::magic::rt::Nx atlevel type offset comp val ?qual?
37
38       ::fileutil::magic::rt::S offset comp val ?qual?
39
40       ::fileutil::magic::rt::Sx atlevel offset comp val ?qual?
41
42       ::fileutil::magic::rt::L newlevel
43
44       ::fileutil::magic::rt::I base type delta
45
46       ::fileutil::magic::rt::R offset
47
48_________________________________________________________________
49

DESCRIPTION

51       This package provides  the  runtime  core  for  file  type  recognition
52       engines  written  in pure Tcl and is thus used by all other packages in
53       this module, i.e. the two frontend packages  fileutil::magic::mimetypes
54       and  fileutil::magic::filetypes,  and  the two engine compiler packages
55       fileutil::magic::cgen and fileutil::magic::cfront.
56

COMMANDS

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

NUMERIC TYPES

187       byte   8-bit integer
188
189       short  16-bit integer, stored in native endianess
190
191       beshort
192              see above, stored in big endian
193
194       leshort
195              see above, stored in small/little endian
196
197       long   32-bit integer, stored in native endianess
198
199       belong see above, stored in big endian
200
201       lelong see above, stored in small/little endian
202
203       All of the types above exit in an unsigned form as well. The type names
204       are the same, with the character "u" added as prefix.
205
206       date   32-bit integer timestamp, stored in native endianess
207
208       bedate see above, stored in big endian
209
210       ledate see above, stored in small/little endian
211
212       ldate  32-bit integer timestamp, stored in native endianess
213
214       beldate
215              see above, stored in big endian
216
217       leldate
218              see above, stored in small/little endian
219

BUGS, IDEAS, FEEDBACK

221       This  document,  and the package it describes, will undoubtedly contain
222       bugs and other problems.  Please report such in the  category  fileutil
223       ::    magic    of    the    Tcllib    SF    Trackers    [http://source
224       forge.net/tracker/?group_id=12883].  Please also report any  ideas  for
225       enhancements you may have for either package and/or documentation.
226

SEE ALSO

228       file(1), fileutil, magic(5)
229

KEYWORDS

231       file recognition, file type, file utilities, mime, type
232
233
234
235fumagic                               1.0               fileutil::magic::rt(n)
Impressum