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

File: [cvs.NetBSD.org] / src / dist / file / magic / Attic / magic2mime (download)

Revision 1.1.1.3 (vendor branch), Sun Mar 4 14:54:53 2007 UTC (15 years, 5 months ago) by pooka
Branch: CHRISTOS
CVS Tags: yamt-pf42-baseX, yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, yamt-pf42-base, yamt-pf42, wrstuden-revivesa-base-1, wrstuden-revivesa-base, matt-mips64-base, matt-mips64, matt-armv6-prevmlocking, matt-armv6-nbase, matt-armv6-base, matt-armv6, keiichi-mipv6-base, keiichi-mipv6, hpcarm-cleanup-nbase, hpcarm-cleanup-base, hpcarm-cleanup, cube-autoconf-base, cube-autoconf, FILE4_21, FILE4_20
Branch point for: wrstuden-revivesa
Changes since 1.1.1.2: +2 -1 lines

file 4.20, contains fixes to the magic parser, new syntax and a
buffer overflow fix

#! /usr/bin/env perl
# -*- PERL -*-
# $File: magic2mime,v 1.4 2006/11/25 18:36:10 christos Exp $
# Copyright (c) 1996, 1997 vax@linkdead.paranoia.com (VaX#n8)
#
# Usage: echo 'your-file-output-here' | file_to_ctype.pl
#        file -b files... | file_to_ctype.pl
# It acts like a filter, reading from STDIN and any files on the command
# line, printing to STDOUT.

## refs
# http://www.faqs.org/faqs/mail/mime-faq/part1/index.html
#  comp.mail.mime FAQ
# ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/media-types
#  assigned content-types
# ftp://ftp.uu.net/inet/rfc/rfc-index
#  RFC index; search for MIME

@mapping =
(
	# defaults
    'data', 'application/octet-stream',
    'text', 'text/plain',
	# more specific
	'^Rich Text Format data', 'text/richtext',
	'^HTML document text', 'text/html',
	'^exported SGML document text', 'text/sgml',
	'mail text', 'message/rfc822',
	'news text', 'message/news',
	'^PostScript document text', 'application/postscript',
	'^BinHex binary text', 'application/mac-binhex40',
	'^Zip archive data', 'application/zip',
	'^Microsoft Word', 'application/msword',
	'^PGP key', 'application/pgp-keys',
	'^PGP encrypted', 'application/pgp-encrypted',
	'^PGP armored data signature', 'application/pgp-signature',
    '^JPEG image', 'image/jpeg',
    '^GIF image', 'image/gif',
	'^PNG image', 'image/png',
    '^TIFF image', 'image/tiff',
	'Computer Graphics Metafile', 'image/cgf',
	'^Sun/NeXT audio data', 'audio/basic',
    '^MPEG', 'video/mpeg',
    '^Apple QuickTime movie', 'video/quicktime',
    '^DICOM medical imaging data', 'application/dicom',
	# made up by me
    '^bitmap', 'image/x-bitmap',
    '^PC bitmap data, Windows 3.x format', 'image/x-msw3bmp',
    '^FLI', 'video/x-fli',
    '^FLC', 'video/x-flc',
    'AVI data', 'video/x-avi',
    'WAVE', 'audio/x-wav',
    'VOC', 'audio/x-voc',
);

local($mimetype,$index,$regexp);
while (<>)
  {
    chop;
    $index = $#mapping - 1;
    while ($index > -1 && !defined($mimetype))
      {
         $mimetype = $mapping[$index + 1] if (/$mapping[$index]/);
         $index -= 2;
      }
    print "$mimetype\n";
	undef $mimetype; # hack
  }
0;