simplify whatnow.c/main() function
[mmh] / uip / print-mimetype.sh
1 #!/bin/sh
2 #
3 # print mime type of file, depending on file name extension
4
5 if [ $# -eq 0 ] ; then
6         echo "Usage: $0 FILE..." >&2
7         exit 1
8 fi
9
10 for i do
11
12 case "$i" in
13 *.xls)  type=application/excel;;
14 *.ppt)  type=application/mspowerpoint;;
15 *.doc)  type=application/msword;;
16 *.pdf)  type=application/pdf;;
17 *.deb)  type=application/x-debian-package;;
18 *.tar)  type=application/x-tar;;
19 *.[1-9])        type=application/x-troff-man;;
20 *.zip)  type=application/zip;;
21 *.au)   type=audio/basic;;
22 *.gif)  type=image/gif;;
23 *.jpg|*.jpeg)   type=image/jpeg;;
24 *.png)  type=image/png;;
25 *.ps)   type=application/postscript;;
26 *.eps)  type=image/eps;;
27 *.tif|*.tiff)   type=image/tiff;;
28 *.ico)  type=image/x-icon;;
29 *.bmp)  type=image/x-ms-bmp;;
30 *.pnm)  type=image/x-portable-anymap;;
31 *.pbm)  type=image/x-portable-bitmap;;
32 *.pgm)  type=image/x-portable-graymap;;
33 *.ppm)  type=image/x-portable-pixmap;;
34 *.xbm)  type=image/x-xbitmap;;
35 *.xpm)  type=image/x-xpixmap;;
36 *.xwd)  type=image/x-xwindowdump;;
37 *.eml)  type=message/rfc822;;
38 *.rtf)  type=text/richtext;;
39 *.html|*.htm)   type=text/html;;
40 *.txt)  type=text/plain;;
41 *.mpg|*.mpeg)   video/mpeg;;
42 *)
43         if file "$i" | grep -q ' text$' ; then
44                 type=text/plain
45         else
46                 type=application/octet-stream
47         fi
48 esac
49 echo "$type"
50
51 done
52