home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 February / PCWorld_2000-02_cd.bin / live / usr / X11R6 / bin / anytopnm < prev    next >
Text File  |  1999-01-26  |  4KB  |  229 lines

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