[BACK]Return to magic2mime CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / dist / file / magic

Annotation of src/dist/file/magic/magic2mime, Revision 1.1.1.3

1.1.1.2   pooka       1: #! /usr/bin/env perl
1.1       pooka       2: # -*- PERL -*-
1.1.1.3 ! pooka       3: # $File: magic2mime,v 1.4 2006/11/25 18:36:10 christos Exp $
1.1       pooka       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',
1.1.1.3 ! pooka      45:     '^DICOM medical imaging data', 'application/dicom',
1.1       pooka      46:        # made up by me
                     47:     '^bitmap', 'image/x-bitmap',
                     48:     '^PC bitmap data, Windows 3.x format', 'image/x-msw3bmp',
                     49:     '^FLI', 'video/x-fli',
                     50:     '^FLC', 'video/x-flc',
                     51:     'AVI data', 'video/x-avi',
                     52:     'WAVE', 'audio/x-wav',
                     53:     'VOC', 'audio/x-voc',
                     54: );
                     55:
                     56: local($mimetype,$index,$regexp);
                     57: while (<>)
                     58:   {
                     59:     chop;
                     60:     $index = $#mapping - 1;
                     61:     while ($index > -1 && !defined($mimetype))
                     62:       {
                     63:          $mimetype = $mapping[$index + 1] if (/$mapping[$index]/);
                     64:          $index -= 2;
                     65:       }
                     66:     print "$mimetype\n";
                     67:        undef $mimetype; # hack
                     68:   }
                     69: 0;

CVSweb <webmaster@jp.NetBSD.org>