home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / SREFPRC1 / MEDIATYP.SRF < prev    next >
Text File  |  1996-12-21  |  2KB  |  80 lines

  1. /* ----------------------------------------------------------------------- */
  2. /* MEDIATYPE: Return the media type of a file, based on its extension.     */
  3. /* ----------------------------------------------------------------------- */
  4. sref_mediatype:
  5. parse arg aa,daport
  6.   /* First get the extension; this assumes filenames have at least one '.' */
  7.   ???=translate(substr(arg(1), lastpos('.',arg(1))+1))
  8.  
  9.  
  10.   /* Fastpath very common types [add your own favourites] */
  11.   if ???='HTM' then return 'text/html'
  12.   if ???='HTML' then return 'text/html'
  13.   if ???='GIF' then return 'image/gif'
  14.   if ???='SHT' then return 'text/html'
  15.   if ???='SHTML' then return 'text/html'
  16.  
  17.  
  18.  
  19. /* special cases */
  20.  
  21.   
  22.   /* Set up the table of all types that we are interested in */
  23.   known.   ='application/octet-stream'  /* default type */
  24.   known.ps ='application/postscript'
  25.   known.pdf='application/pdf'
  26.   known.zip='application/zip'
  27.   known.au ='audio/basic'
  28.   known.snd='audio/basic'
  29.   known.wav='audio/x-wav'
  30.   known.mid='audio/x-midi'
  31.   known.gif='image/gif'
  32.   known.bmp='image/bmp'
  33.   known.jpg='image/jpeg';  known.jpeg='image/jpeg'
  34.   known.tif='image/tiff';  known.tiff='image/tiff'
  35.   known.htm='text/html' ;  known.html='text/html'
  36.   known.sht='text/html' ;  known.shtml='text/html'
  37.   tmp1='HTML-SSI'           
  38.   known.tmp1='text/html'   
  39.  
  40.   known.txt='text/plain'
  41.   known.lst='text/plain'
  42.   known.me='text/plain'
  43.   known.log='text/plain'
  44.   known.cmd='text/plain'
  45.   known.doc='text/plain'
  46.   known.in='text/plain'
  47.   known.faq='text/plain'
  48.   known.mpg='video/mpeg';  known.mpeg='video/mpeg'
  49.   known.avi='video/x-msvideo'
  50.  
  51.   if known.???='application/octet-stream' then do  /* try user default list */
  52.    foo1=daport
  53.    if daport=""  then   foo1=extract('serverport')
  54.     foo2='SREF_'||foo1||'_SERVDIR'
  55.     foo3=strip(value(foo2,,'os2environment'),'t','\')||'\MEDIATYP.RXX'
  56.     foo1=stream(foo3,'c','query exists')
  57.     if foo1=' ' then  do
  58.        return known.???
  59.     end
  60.     else do
  61. /*else, check user specified mediatype list */
  62.        signal on error name oy1 ; signal on syntax name oy1
  63.        foo1=charin(foo3,1,chars(foo3)); foo2=stream(foo3,'c','close')
  64.        foo1=translate(foo1,' ; ','000d0a'x)
  65.        interpret foo1
  66.     end
  67.    end
  68.  
  69.   /* Now it's trivial... */
  70.  
  71. oy1: nop
  72.  
  73. signal off error ; signal off syntax ;
  74.  
  75.   return known.???
  76.  
  77.  
  78.  
  79.  
  80.