-.\" $File: magic.man,v 1.50 2008/02/18 18:28:51 rrt Exp $
+.\" $File: magic.man,v 1.51 2008/02/18 18:32:31 rrt Exp $
.Dd January 10, 2007
.Dt MAGIC __FSECTION__
.Os
.\" install as magic.4 on USG, magic.5 on V7 or Berkeley systems.
.Sh NAME
.Nm magic
-.Nd file command's magic number file
+.Nd file command's magic pattern file
.Sh DESCRIPTION
This manual page documents the format of the magic file as
used by the
.Xr file __CSECTION__
command identifies the type of a file using,
among other tests,
-a test for whether the file begins with a certain
-.Dq "magic number" .
+a test for whether the file contains certain
+.Dq "magic patterns" .
The file
.Pa __MAGIC__
-specifies what magic numbers are to be tested for, what message or
-MIME type to print if a particular magic number is found,
+specifies what patterns are to be tested for, what message or
+MIME type to print if a particular pattern is found,
and additional information to extract from the file.
.Pp
Each line of the file specifies a test to be performed.
(much like egrep). Regular expressions can easily take exponential
time to process; their use is discouraged. When used in production
environments, their performance should be carefully checked. The type
-specification can be optionally followed by /[c][s]. The
+specification can be optionally followed by
+.Dv /[c][s] .
+The
.Dq c
flag makes the match case insensitive, while the
.Dq s
A literal string search starting at the given offset. The same
modifier flags can be used as for string patterns. The modifier flags
(if any) must be followed by
-.Dv /\*[Lt]number\*[Gt]
-which specifies how many matches shall be attempted (the range).
-This is suitable for searching larger binary expressions with variable
-offsets, using
+.Dv /number
+the range, that is, the number of positions at which the match will be
+attempted, starting from the start offset. This is suitable for
+searching larger binary expressions with variable offsets, using
.Dv \e
escapes for special characters. The offset works as for regex.
.It Dv default
.Dv 0x13
is hexadecimal.
.Pp
-For string values, the byte string from the
-file must match the specified byte string.
+For string values, the string from the
+file must match the specified string.
The operators
.Dv = ,
.Dv \*[Lt]
can be applied to strings.
The length used for matching is that of the string argument
in the magic file.
-This means that a line can match any string, and
-then presumably print that string, by doing
+This means that a line can match any non-empty string (usually used to
+then print the string), with
.Em \*[Gt]\e0
-(because all strings are greater than the null string).
+(because all non-empty strings are greater than the empty string).
.Pp
The special test
.Em x
.Pp
If this indirect offset cannot be used as-is, there are simple calculations
possible: appending
-.Em [+-*/%\*[Am]|^]\*[Lt]number\*[Gt]
+.Em [+-*/%\*[Am]|^]number
inside parentheses allows one to modify
the value read from the file before it is used as an offset:
.Bd -literal -offset indent
.\" the changes I posted to the S5R2 version.
.\"
.\" Modified for Ian Darwin's version of the file command.
-.\" @(#)$Id: magic.man,v 1.51 2008/02/18 18:32:31 rrt Exp $
+.\" @(#)$Id: magic.man,v 1.52 2008/02/28 13:14:26 rrt Exp $