home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / bin / anytopnm < prev    next >
Encoding:
Text File  |  2004-06-14  |  5.6 KB  |  265 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 [ $# -gt 1 ] ; then
  15.     echo "Usage: $0 infilename > outfilename.pnm" 1>&2
  16.     echo "       $0 - < infilename > outfilename.pnm" 1>&2
  17.     echo "  This will convert the input file into a PNM file" 1>&2
  18.     echo "  It automatically determines the format of the input file" 1>&2
  19.     echo "    with the 'file' command, and acts accordingly" 1>&2
  20.     echo "  If the infilename is a '-', uses standard input" 1>&2
  21.     exit 1
  22. fi
  23.  
  24. tmpfiles=""
  25.  
  26. # Take out all spaces
  27. # Find the filename extension for last-ditch efforts later
  28. fileextension=`echo "$1" | awk '{gsub(" ","");gsub(".*\\\\.",".");print}'`
  29.  
  30. # Sanitize the filename by making our own temporary files as safely as
  31. # possible.
  32. file="/tmp/atn.stdin.$$"
  33. rm -f "$file"
  34. if [ $# -eq 0 -o "$1" = "-" ] ; then
  35.     cat > "$file"
  36. else
  37.     if [ ! -e "$1" ] ; then
  38.         echo "$0: $1: No such file" 1>&2
  39.         exit 1
  40.     fi
  41.     
  42.     if [ ! -f "$1" ] ; then
  43.         echo "$0: $1: Not a file" 1>&2
  44.         exit 1
  45.     fi
  46.     
  47.     if [ ! -r "$1" ] ; then
  48.         echo "$0: $1: Not a readable file" 1>&2
  49.         exit 1
  50.     fi
  51.     
  52.     if [ -z "$1" ] ; then
  53.         echo "$0: $1: Empty file" 1>&2
  54.         exit 1
  55.     fi
  56.     
  57.     cat < "$1" > "$file"
  58. fi
  59.  
  60. tmpfiles="$tmpfiles $file"
  61.  
  62.  
  63.  
  64. filetype=`file "$file" | cut -d: -f2-`
  65.  
  66. case "$filetype" in
  67.  
  68.     *PBM* | *PGM* | *PPM* )
  69.     cat "$file"
  70.     ;;
  71.  
  72.     *uuencoded* )
  73.     newfile="/tmp/atn.decode.$$"
  74.     rm -f "$newfile"
  75.     (echo begin 600 $newfile; tail +2 < "$file") | uudecode
  76.     tmpfiles="$tmpfiles $newfile"
  77.     anytopnm "$newfile"
  78.     ;;
  79.  
  80.     *bzip2*compressed*data* )
  81.     bzip2 -dk < "$file" | anytopnm -
  82.     ;;
  83.  
  84.     *bzip*compressed*data* )
  85.     bzip -dk < "$file" | anytopnm -
  86.     ;;
  87.  
  88.     *gzip*compressed*data* )
  89.     gzip --decompress --to-stdout < "$file" | anytopnm -
  90.     ;;
  91.  
  92.     *compress* )
  93.     uncompress -c < "$file" | anytopnm -
  94.     ;;
  95.  
  96.     *btoa* )
  97.     atob < "$file" | anytopnm -
  98.     ;;
  99.  
  100.     *Sun* | *rasterfile* )
  101.     rasttopnm "$file"
  102.     ;;
  103.  
  104.     *GIF* )
  105.     giftopnm "$file"
  106.     ;;
  107.  
  108.     *TIFF* )
  109.     tifftopnm "$file"
  110.     ;;
  111.  
  112.     *IFF*ILBM* )
  113.     ilbmtoppm "$file"
  114.     ;;
  115.  
  116.     *Lisp* )
  117.     lispmtopgm "$file"
  118.     ;;
  119.  
  120.     *PC*Paintbrush* )
  121.     pcxtoppm "$file"
  122.     ;;
  123.  
  124.     *Bennet* )
  125.     ybmtopbm "$file"
  126.     ;;
  127.  
  128.     *pixmap*image*text* )
  129.     xpmtoppm < "$file"
  130.     ;;
  131.  
  132.     # This has to come after all other 'text' files, or you may be
  133.     # disappointed.
  134.     *text* )
  135.     pbmtext -builtin fixed < "$file"
  136.     ;;
  137.  
  138.     *JPEG* | *JFIF* )
  139.     jpegtopnm "$file"
  140.     ;;
  141.  
  142.     *PNG* )
  143.     pngtopnm "$file"
  144.     ;;
  145.  
  146.     *MicroDesign* )
  147.     mdatopbm -d -- "$file"
  148.     ;;
  149.  
  150.     *PC*bitmap*data* )
  151.     bmptoppm "$file"
  152.     ;;
  153.     
  154.     * )
  155.     # Can't figure out the file type from the magic number,
  156.     # try the extension.
  157.     case "$fileextension" in
  158.  
  159.         *.pbm | *.pbm.* | *.pgm | *.pgm.* | *.ppm | *.ppm.* )
  160.         cat "$file"
  161.         ;;
  162.         *.x | *.x.* | *.xbm | *.xbm.* | *.x10bm | *.x10bm.* | \
  163.             *.x11bm | *.x11bm.* | *.bitmap | *.bitmap.* )
  164.         xbmtopbm "$file"
  165.         ;;
  166.         *.r | *.r.* | *.rast | *.rast.* )
  167.         rasttopnm "$file"
  168.         ;;
  169.         *.mac | *.mac.* | *.macp | *.macp.* )
  170.         macptopbm "$file"
  171.         ;;
  172.         *.g3 | *.g3.* | *.fax | *.fax.* )
  173.         g3topbm "$file"
  174.         ;;
  175.         *.xwd | *.xwd.* | *.x10wd | *.x10wd.* | *.x11wd | *.x11wd.* )
  176.         xwdtopnm "$file"
  177.         ;;
  178.         *.brush | *.brush.* )
  179.         brushtopbm "$file"
  180.         ;;
  181.         *.img | *.img.* )
  182.         gemtopbm "$file"
  183.         ;;
  184.         *.pcx | *.pcx.* )
  185.         pcxtoppm "$file"
  186.         ;;
  187.         *.pic | *.pic.* | *.pict | *.pict.* | *.pict2 | *.pict2.* )
  188.         picttoppm "$file"
  189.         ;;
  190.         *.tif | *.tif.* | *.tiff | *.tiff.* )
  191.         tifftopnm "$file"
  192.         ;;
  193.         *.fs | *.fs.* | *.face | *.face.* )
  194.         fstopgm "$file"
  195.         ;;
  196.         *.hips | *.hips.* )
  197.         hipstopgm "$file"
  198.         ;;
  199.         *.fits | *.fits.* )
  200.         fitstopnm "$file"
  201.         ;;
  202.         *.gif | *.gif.* )
  203.         giftopnm "$file"
  204.         ;;
  205.         *.iff | *.iff.* | *.ilbm | *.ilbm.* )
  206.         ilbmtoppm "$file"
  207.         ;;
  208.         *.lispm | *.lispm.* )
  209.         lispmtopgm "$file"
  210.         ;;
  211.         *.mtv | *.mtv.* )
  212.         mtvtoppm "$file"
  213.         ;;
  214.         *.qrt | *.qrt.* )
  215.         qrttoppm "$file"
  216.         ;;
  217.         *.tga | *.tga.* | *.targa | *.targa.* )
  218.         tgatoppm "$file"
  219.         ;;
  220.         *.xim | *.xim.* )
  221.         ximtoppm "$file"
  222.         ;;
  223.         *.xpm | *.xpm.* | *.xpm2 | *.xpm2.* )
  224.         xpmtoppm "$file"
  225.         ;;
  226.         *.pi1 | *.pi1.* )
  227.         pi1toppm "$file"
  228.         ;;
  229.         *.pi3 | *.pi3.* )
  230.         pi3topbm "$file"
  231.         ;;
  232.         *.spu | *.spu.* )
  233.         sputoppm "$file"
  234.         ;;
  235.         *.spc | *.spc.* )
  236.         spctoppm "$file"
  237.         ;;
  238.         *.ybm | *.ybm.* | *.face | *.face.* )
  239.         ybmtopbm "$file"
  240.         ;;
  241.         *.JPEG | *.jpeg | *.jpg | *.JPG )
  242.         jpegtopnm "$file"
  243.         ;;
  244.         *.png | *.PNG )
  245.         pngtopnm "$file"
  246.         ;;
  247.         *.mda | *.mdp )
  248.         mdatopbm -d -- "$file"
  249.         ;;
  250.         * )
  251.         echo "$0: unknown file type: $filetype" 1>&2
  252.         exit 1
  253.         ;;
  254.  
  255.     esac
  256.     ;;
  257.  
  258. esac
  259.  
  260.  
  261. if [ "$tmpfiles" ] ; then
  262.     rm -f $tmpfiles
  263. fi
  264. exit 0
  265.