home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netpbma.zip / pnm / anytopnm next >
Text File  |  1993-10-04  |  3KB  |  188 lines

  1. #!/bin/sh
  2. #
  3. # anytopnm - attempt to convert an unknown type of image file to a P?M file.
  4. #
  5. # Copyright (C) 1991 by Jef Poskanzer.
  6. #
  7. # Permission to use, copy, modify, and distribute this software and its
  8. # documentation for any purpose and without fee is hereby granted, provided
  9. # that the above copyright notice appear in all copies and that both that
  10. # copyright notice and this permission notice appear in supporting
  11. # documentation.  This software is provided "as is" without express or
  12. # implied warranty.
  13.  
  14. if [ ! $# = 1 ] ; then
  15.     echo "usage: $0 <file>" 1>&2
  16.     exit 1
  17. fi
  18.  
  19. origfile="$1"
  20. file="$origfile"
  21. tmpfiles=""
  22.  
  23. while true ; do
  24.  
  25.     filetype=`file "$file"`
  26.  
  27.     case "$filetype" in
  28.  
  29.     *PBM* | *PGM* | *PPM* )
  30.     cat "$file"
  31.     break
  32.     ;;
  33.  
  34.     *compress* )
  35.     newfile="/tmp/atn.comp.$origfile"
  36.     rm -f "$newfile"
  37.     zcat < "$file" > "$newfile"
  38.     file="$newfile"
  39.     tmpfiles="$tmpfiles $newfile"
  40.     ;;
  41.  
  42.     *btoa* )
  43.     newfile="/tmp/atn.btoa.$origfile"
  44.     rm -f "$newfile"
  45.     atob < "$file" > "$newfile"
  46.     file="$newfile"
  47.     tmpfiles="$tmpfiles $newfile"
  48.     ;;
  49.  
  50.     *Sun* | *rasterfile* )
  51.     rasttopnm "$file"
  52.     break
  53.     ;;
  54.  
  55.     *GIF* )
  56.     giftoppm "$file"
  57.     break
  58.     ;;
  59.  
  60.     *TIFF* )
  61.     tifftopnm "$file"
  62.     break
  63.     ;;
  64.  
  65.     *IFF*ILBM* )
  66.     ilbmtoppm "$file"
  67.     break
  68.     ;;
  69.  
  70.     *Lisp* )
  71.     lispmtopgm "$file"
  72.     break
  73.     ;;
  74.  
  75.     *PC*Paintbrush* )
  76.     pcxtoppm "$file"
  77.     break
  78.     ;;
  79.  
  80.     *Bennet* )
  81.     ybmtopbm "$file"
  82.     break
  83.     ;;
  84.  
  85.     * )
  86.     # Can't figure out the file type from the magic number,
  87.     # try the extension.
  88.     case "$file" in
  89.  
  90.         *.pbm | *.pbm.* | *.pgm | *.pgm.* | *.ppm | *.ppm.* )
  91.         cat "$file"
  92.         ;;
  93.         *.x | *.x.* | *.xbm | *.xbm.* | *.x10bm | *.x10bm.* | *.x11bm | *.x11bm.* | *.bitmap | *.bitmap.* )
  94.         xbmtopbm "$file"
  95.         ;;
  96.         *.r | *.r.* | *.rast | *.rast.* )
  97.         rasttopnm "$file"
  98.         ;;
  99.         *.mac | *.mac.* | *.macp | *.macp.* )
  100.         macptopbm "$file"
  101.         ;;
  102.         *.g3 | *.g3.* | *.fax | *.fax.* )
  103.         g3topbm "$file"
  104.         ;;
  105.         *.xwd | *.xwd.* | *.x10wd | *.x10wd.* | *.x11wd | *.x11wd.* )
  106.         xwdtopnm "$file"
  107.         ;;
  108.         *.brush | *.brush.* )
  109.         brushtopbm "$file"
  110.         ;;
  111.         *.img | *.img.* )
  112.         gemtopbm "$file"
  113.         ;;
  114.         *.pcx | *.pcx.* )
  115.         pcxtoppm "$file"
  116.         ;;
  117.         *.pic | *.pic.* | *.pict | *.pict.* | *.pict2 | *.pict2.* )
  118.         picttoppm "$file"
  119.         ;;
  120.         *.tif | *.tif.* | *.tiff | *.tiff.* )
  121.         tifftopnm "$file"
  122.         ;;
  123.         *.fs | *.fs.* | *.face | *.face.* )
  124.         fstopgm "$file"
  125.         ;;
  126.         *.hips | *.hips.* )
  127.         hipstopgm "$file"
  128.         ;;
  129.         *.fits | *.fits.* )
  130.         fitstopgm "$file"
  131.         ;;
  132.         *.gif | *.gif.* )
  133.         giftoppm "$file"
  134.         ;;
  135.         *.iff | *.iff.* | *.ilbm | *.ilbm.* )
  136.         ilbmtoppm "$file"
  137.         ;;
  138.         *.lispm | *.lispm.* )
  139.         lispmtopgm "$file"
  140.         ;;
  141.         *.mtv | *.mtv.* )
  142.         mtvtoppm "$file"
  143.         ;;
  144.         *.qrt | *.qrt.* )
  145.         qrttoppm "$file"
  146.         ;;
  147.         *.tga | *.tga.* | *.targa | *.targa.* )
  148.         tgatoppm "$file"
  149.         ;;
  150.         *.xim | *.xim.* )
  151.         ximtoppm "$file"
  152.         ;;
  153.         *.xpm | *.xpm.* | *.xpm2 | *.xpm2.* )
  154.         xpmtoppm "$file"
  155.         ;;
  156.         *.pi1 | *.pi1.* )
  157.         pi1toppm "$file"
  158.         ;;
  159.         *.pi3 | *.pi3.* )
  160.         pi3topbm "$file"
  161.         ;;
  162.         *.spu | *.spu.* )
  163.         sputoppm "$file"
  164.         ;;
  165.         *.spc | *.spc.* )
  166.         spctoppm "$file"
  167.         ;;
  168.         *.ybm | *.ybm.* | *.face | *.face.* )
  169.         ybmtopbm "$file"
  170.         ;;
  171.         * )
  172.         echo "$0: unknown file type" 1>&2
  173.         exit 1
  174.         ;;
  175.  
  176.     esac
  177.     break
  178.     ;;
  179.  
  180.     esac
  181.  
  182. done
  183.  
  184. if [ "$tmpfiles" ] ; then
  185.     rm -f $tmpfiles
  186. fi
  187. exit 0
  188.