Update to file 4.13. Put the contrib files into contrib/file-4 instead
[dragonfly.git] / contrib / file-4 / magic / magic2mime
blobc83ee595cd8e331c0af230a4cd0733f70547bd77
1 #! /usr/local/bin/perl
2 # -*- PERL -*-
3 # $Id: magic2mime,v 1.2 2003/03/23 04:17:27 christos Exp $
4 # Copyright (c) 1996, 1997 vax@linkdead.paranoia.com (VaX#n8)
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.
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
19 @mapping =
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',
55 local($mimetype,$index,$regexp);
56 while (<>)
58 chop;
59 $index = $#mapping - 1;
60 while ($index > -1 && !defined($mimetype))
62 $mimetype = $mapping[$index + 1] if (/$mapping[$index]/);
63 $index -= 2;
65 print "$mimetype\n";
66 undef $mimetype; # hack