Comment PFIL_HOOKS since it should not be needed in GENERIC.
[dragonfly.git] / contrib / file / magic2mime
1 #! /usr/local/bin/perl
2 # -*- PERL -*-
3 # $Id: magic2mime,v 1.1 1998/02/15 23:18:53 christos Exp $
4 # Copyright (c) 1996, 1997 vax@linkdead.paranoia.com (VaX#n8)
5 #
6 # Usage: echo 'your-file-output-here' | file_to_ctype.pl
7 #        file -b files... | file_to_ctype.pl
8 # It acts like a filter, reading from STDIN and any files on the command
9 # line, printing to STDOUT.
10
11 ## refs
12 # http://www.faqs.org/faqs/mail/mime-faq/part1/index.html
13 #  comp.mail.mime FAQ
14 # ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/media-types
15 #  assigned content-types
16 # ftp://ftp.uu.net/inet/rfc/rfc-index
17 #  RFC index; search for MIME
18
19 @mapping =
20 (
21         # defaults
22     'data', 'application/octet-stream',
23     'text', 'text/plain',
24         # more specific
25         '^Rich Text Format data', 'text/richtext',
26         '^HTML document text', 'text/html',
27         '^exported SGML document text', 'text/sgml',
28         'mail text', 'message/rfc822',
29         'news text', 'message/news',
30         '^PostScript document text', 'application/postscript',
31         '^BinHex binary text', 'application/mac-binhex40',
32         '^Zip archive data', 'application/zip',
33         '^Microsoft Word', 'application/msword',
34         '^PGP key', 'application/pgp-keys',
35         '^PGP encrypted', 'application/pgp-encrypted',
36         '^PGP armored data signature', 'application/pgp-signature',
37     '^JPEG image', 'image/jpeg',
38     '^GIF image', 'image/gif',
39         '^PNG image', 'image/png',
40     '^TIFF image', 'image/tiff',
41         'Computer Graphics Metafile', 'image/cgf',
42         '^Sun/NeXT audio data', 'audio/basic',
43     '^MPEG', 'video/mpeg',
44     '^Apple QuickTime movie', 'video/quicktime',
45         # made up by me
46     '^bitmap', 'image/x-bitmap',
47     '^PC bitmap data, Windows 3.x format', 'image/x-msw3bmp',
48     '^FLI', 'video/x-fli',
49     '^FLC', 'video/x-flc',
50     'AVI data', 'video/x-avi',
51     'WAVE', 'audio/x-wav',
52     'VOC', 'audio/x-voc',
53 );
54
55 local($mimetype,$index,$regexp);
56 while (<>)
57   {
58     chop;
59     $index = $#mapping - 1;
60     while ($index > -1 && !defined($mimetype))
61       {
62          $mimetype = $mapping[$index + 1] if (/$mapping[$index]/);
63          $index -= 2;
64       }
65     print "$mimetype\n";
66         undef $mimetype; # hack
67   }
68 0;