home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / f / filtyp11.zip / FILETYPE.DOC next >
Text File  |  1991-08-19  |  9KB  |  180 lines

  1.  
  2.                          F I L E T Y P E  1 . 1
  3.                          ======================
  4.  
  5.                Free Software by TapirSoft Gisbert W.Selke
  6.                               August 1991
  7.  
  8. This is a utility similar to the Un*x programme named file. It takes
  9. the name of a file of unknown purpose and tries to guess what kind of a
  10. file it is -- a ZIP archive, an LZH archive, an executable, an MS Word
  11. document, a QuattroPro spreadsheet, a Bitstream font, or whatnot. Often,
  12. the purpose of a file can be gleaned from its extension; but sometimes
  13. (e.g., after transmission by E-mail), this extension is lost, and
  14. sometimes it just isn't meaningful. (After all, there are only finitely
  15. many permissible file extensions, but probably uncountably many purposes
  16. to use files for.)
  17.  
  18. FileType does its work by looking at sepcified bytes in the specified
  19. file; it tries to match these against a number of known file signatures.
  20. These signatures are stored in a plain ASCII text file; this signature
  21. file can be extended at will and as need dictates.
  22.  
  23. Naturally, these guesses are not always correct.
  24.  
  25. The simplest way to use FileType is
  26.  
  27.          filetype  <filename>
  28.  
  29. where <filename> is replaced by the name of the file to be examined.
  30. (No wildcards allowed.) Output consists of a header plus a single line.
  31.  
  32. E.g., if you type
  33.  
  34.          filetype filetype.exe
  35.  
  36. you'll get this answer:
  37.  
  38.          filetype.exe: executable (EXE)
  39.  
  40. In order to be able to work, FileType must have access to a file
  41. containing the magic signatures; ordinarily, this file is called
  42. MAGIC.FT and is located in the current directory or in the directory
  43. where FILETYPE.EXE itself is stored. (The latter method works only
  44. under MS-DOS 3.x or later.) You can specify a different magic file, or
  45. an explicit path, with the /m switch:
  46.  
  47.          filetype /mc:\stuff\mymagic.typ foo.bar
  48.  
  49. (Notice no blanks between /m and the file name!).
  50.  
  51. There's another command line switch, /q, which suppresses output of the
  52. header, by the way; and just typing 'filetype' without any arguments
  53. displays usage hints.
  54.  
  55. If you want to check a whole bunch of files, use something like this:
  56.  
  57.          for %f in (*.*) do filetype %f
  58.  
  59. (If you used this inside a batch file, you wouldn't forget to double the
  60. percent characters, would you?)
  61.  
  62. One thing remains to be told: how to extend the magic file? Just take an
  63. editor that stores plain ASCII files (no extraneous word processor
  64. information!) and add, modify, or delete lines at your leisure.
  65. These are the rules: (Advanced topics are marked with an asterisk.)
  66.  
  67.   - Maximum line length is 255 characters. Lines are CRLF-delimited.
  68.     File must be plain (8 bit) ASCII.
  69.   - Each line consists of a file recognizer pattern, then at least one
  70.     blank, then either a name for the file type thusly identified or
  71.     a continuation marker.
  72.   - The recognizer sequence consists of a file offset (optional), a bit
  73.     mask (optional), and a matching sequence (required). These items, if
  74.     present, must be separated by at least one blank each; the ordering
  75.     of these items is required.
  76.   * The file offset starts with @, then an optional -, followed by
  77.     a seqence of hex (!) digits which represent an offset into the file
  78.     at which the matching should occur. (No blanks within the file
  79.     offset sequence!) Start of file is at 0(!). A negative offset
  80.     matches from the end of the file, with the last byte in the file
  81.     pointed to by -1. -- Default for offset is 0.
  82.   * The bit mask starts with & and is followed by a sequence as
  83.     specified for matching sequences (cf. below). This bit mask will be
  84.     ANDed bytewise to the bytes found in the file before matching takes
  85.     place. Thus, masking with DF would make matching of 7-bit ASCII
  86.     characters case-independent. (However, note the use of double quotes
  87.     below.) If the bit mask is shorter than the matching sequence, it is
  88.     extended with FF (functionally equivalent to no masking at all.) --
  89.     Default for the bit mask is all FFs.
  90.   - The matching sequence can be any mixture of pairs of hex digits and
  91.     ASCII strings enclosed in single (') or double (") quotes.
  92.   - Characters in single quotes require an exact match, characters in double
  93.     quotes are matched case-independently. (Cf. note on case-conversion below.)
  94.   - Both subtypes may contain a question mark to stand for any
  95.     character. (And I mean 'character', *not* hex digit!)
  96.   - ASCII strings may contain escaped sequences: \' and \" for
  97.     embedded quotes, \b (backspace), \t (tab), \n (newline), \v
  98.     (vertical tab), \f (form feed), \r (carriage return), \? (question
  99.     mark), \\ (backslash).
  100.   - If a starting sequence in this file is identical to the beginning of
  101.     another one, the longer sequence should come first.
  102.   - Comment lines may start with semicolon or hash mark.
  103.   * For case-independent matchings, FileType knows about the upper-case
  104.     equivalents of standard 7-bit ASCII characters; under DOS 3.30+, it
  105.     can also handle (8-bit) national characters according to your
  106.     country code and code page. You can override this knowledge by
  107.     including a pair of lines starting with v and ^, respectively. These
  108.     lines must not contain any blanks after the line marker and must
  109.     match character by character. The 'v' line contains lower-case
  110.     characters, the '^' line the corresponding upper-case characters.
  111.     You need specify only as many characters as are necessary. These
  112.     lines must occur in Magic.FT before the first recognizer line in
  113.     which they are needed. -- Note that two or more pairs of translator
  114.     lines may be specified, but only the last one used will be in
  115.     effect.
  116.   * If different places of the file need to be checked for pattern
  117.     matching, there are two ways to do so:
  118.     - If the places are close together, specify *one* sequence and a bit
  119.       mask to ignore the irrelevant bytes by ANDing these with 0.
  120.     - Otherwise, use a multi-line matching: specify one recognizer
  121.       pattern, but instead of a file type name, include a slash (/);
  122.       then, on a new line, specify the next recognizer pattern, this
  123.       time using the file type name. (There may be more than one slash-
  124.       delimited line.) This way, all the slash-delimited lines *and*
  125.       the next one are required to match.
  126.   - The first line of the file is taboo.
  127.  
  128. Note that a file offset will rarely have to be used, since most files
  129. can be told from their first few bytes (if at all). You may consider
  130. offsets and masking as advanced topics which are necessary only in very
  131. special circumstances. Multi-line matchings will have to be used even
  132. more rarely. -- In any case, remember that you are invited to extend or
  133. change the magic file to suit your ain needs.
  134.  
  135. That's it. Enjoy. And if you feel I have omitted a really important sort
  136. of files from MAGIC.FT (as distributed) and you know its magic
  137. signature, why not send it to me? I can be reached at
  138.  
  139. TapirSoft
  140. Gisbert W.Selke
  141. Ermekeilstrasse 28
  142. D-5300 Bonn 1
  143. Germany
  144. E-Mail: <s00100@dbnrhrz1.bitnet>
  145.  
  146.  
  147.  
  148. History:
  149. 1.0      01 Aug 1991   It hit the world.
  150. 1.1      19 Aug 1991   AARGH. Wildcard handling was broken, discovered
  151.                        by Richard J. Reiner. Fixed. Added multi-line
  152.                        matching. Added automatic national character
  153.                        uppercasing via country code and code page.
  154.                        Increased I/O buffer sizes. Corrected doc bug.
  155.                        Commented source some (gasp).
  156.  
  157.  
  158.  
  159. Oh, the legal stuff:
  160.  
  161. FileType.Pas contains no material copyrighted by anyone else. I retain
  162. the copyright on FileType; however, there are no restrictions on using
  163. and copying the package, as long as no money is asked for and all files
  164. are distributed unaltered and together. (That is: FILETYPE.PAS,
  165. FILETYPE.EXE, MAGIC.FT, FILETYPE.DOC, suitably archived by your
  166. favourite archiver.) The usual standard disclaimers apply: I cannot be
  167. held responsible for this programme's doing anything at all, or nothing
  168. at all, or not doing what you'd like it to do. (Which, on the other
  169. hand, isn't meant to say that I'd ignore any sufficiently detailed bug
  170. report.)
  171.  
  172.  
  173. Registered trademarks etc. used in this file:
  174.  
  175. Bitstream : Bitstream Inc.
  176. MS DOS, MicroSoft Word: Microsoft Corporation
  177. QuattroPro : Borland International
  178. ZIP : PKWare, Inc.
  179.  
  180.