home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFPRC1
/
MEDIATYP.SRF
< prev
next >
Wrap
Text File
|
1996-12-21
|
2KB
|
80 lines
/* ----------------------------------------------------------------------- */
/* MEDIATYPE: Return the media type of a file, based on its extension. */
/* ----------------------------------------------------------------------- */
sref_mediatype:
parse arg aa,daport
/* First get the extension; this assumes filenames have at least one '.' */
???=translate(substr(arg(1), lastpos('.',arg(1))+1))
/* Fastpath very common types [add your own favourites] */
if ???='HTM' then return 'text/html'
if ???='HTML' then return 'text/html'
if ???='GIF' then return 'image/gif'
if ???='SHT' then return 'text/html'
if ???='SHTML' then return 'text/html'
/* special cases */
/* Set up the table of all types that we are interested in */
known. ='application/octet-stream' /* default type */
known.ps ='application/postscript'
known.pdf='application/pdf'
known.zip='application/zip'
known.au ='audio/basic'
known.snd='audio/basic'
known.wav='audio/x-wav'
known.mid='audio/x-midi'
known.gif='image/gif'
known.bmp='image/bmp'
known.jpg='image/jpeg'; known.jpeg='image/jpeg'
known.tif='image/tiff'; known.tiff='image/tiff'
known.htm='text/html' ; known.html='text/html'
known.sht='text/html' ; known.shtml='text/html'
tmp1='HTML-SSI'
known.tmp1='text/html'
known.txt='text/plain'
known.lst='text/plain'
known.me='text/plain'
known.log='text/plain'
known.cmd='text/plain'
known.doc='text/plain'
known.in='text/plain'
known.faq='text/plain'
known.mpg='video/mpeg'; known.mpeg='video/mpeg'
known.avi='video/x-msvideo'
if known.???='application/octet-stream' then do /* try user default list */
foo1=daport
if daport="" then foo1=extract('serverport')
foo2='SREF_'||foo1||'_SERVDIR'
foo3=strip(value(foo2,,'os2environment'),'t','\')||'\MEDIATYP.RXX'
foo1=stream(foo3,'c','query exists')
if foo1=' ' then do
return known.???
end
else do
/*else, check user specified mediatype list */
signal on error name oy1 ; signal on syntax name oy1
foo1=charin(foo3,1,chars(foo3)); foo2=stream(foo3,'c','close')
foo1=translate(foo1,' ; ','000d0a'x)
interpret foo1
end
end
/* Now it's trivial... */
oy1: nop
signal off error ; signal off syntax ;
return known.???