MAJOR=4
MINOR=53
DEVNAME=tty53
     'ˆÏ�þY³r†RŒŽ:á@çÖ„›mÏÕÀÓ 1    '#!/bin/sh
#
# anytopnm - attempt to convert an unknown type of image file to a P?M file.
#
# Copyright (C) 1991 by Jef Poskanzer.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation.  This software is provided "as is" without express or
# implied warranty.



putInputIntoTempfile() {

    # $1 is the input file specification
    # $2 is the temporary file name
    
    rm -f "$2"
    if [ "$1" = "-" ] ; then
            cat > "$2"
    else
        # We'd like to do a -e here to test the existence of the filesystem
        # object per se, and thus give a more specific error message.  But
        # some systems don't have -e.
        if [ ! -f "$1" ] ; then
            echo "$progname: '$1' does not exist or is not a file" 1>&2
            exit 1
            fi
        
        if [ ! -r "$1" ] ; then
            echo "$progname: '$1' is not readable" 1>&2
            exit 1
            fi
        
        if [ -z "$1" ] ; then
            echo "$progname: '$1' is empty" 1>&2
            exit 1
            fi
        
        cat < "$1" > "$2"
        fi
}



setMimeType() {
#------------------------------------------------------------------------------
# Set variable 'mimeType' to the mime type string (e.g. "application/binary")
#
# If we can't tell, set it to "unknown".
#------------------------------------------------------------------------------
    # $1 is the file name

    # Old versions of 'file' cannot tell us the mime type; they lack any option
    # to do so.
    #
    # Newer ones have a --mime option for that.
    #
    # Still newer ones (ca 2008) have a --mime option, but it does something
    # different - it prints the mime type plus the mime encoding.  And they
    # have --mime-type to print just the mime type.

    file --mime-type /dev/null >/dev/null 2>/dev/null
    if [ $? -eq 0 ]; then
        # Now that we know the --mime-type option exists, use it.
        mimeType=`file --mime-type "$1" | cut -d: -f2- | cut -c2-`
    else
        # file --mime-type failed; we don't know why, but we assume it's
        # because it is an older 'file' program that doesn't have a --mime-type
        # option.
        file --mime /dev/null >/dev/null 2>/dev/null
        if [ $? -eq 0 ]; then
            # Now that we know the --mime option exists, use it.
            mimeType=`file --mime "$1" | cut -d: -f2- | cut -c2-`
        else
            # file --mime failed; we don't know why, but we assume it's because
            # it is an older 'file' program that doesn't have a --mime option.
            mimeType="unknown"
        fi
    fi
}



computeTypeFromMimeType () {

# $1 is the mime type string
    
    case "$1" in

        image/jpeg )
            filetype="jfif"
            ;;
        image/gif )
            filetype="gif"
            ;;
        image/tiff )
            filetype="tiff"
            ;;
        image/bmp )
            filetype="bmp"
            ;;
        image/x-ms-bmp )
            filetype="bmp"
            ;;
        image/png )
            filetype="png"
            ;;
        image/x-portable-bitmap | image/x-portable-pixmap | \
                image/x-portable-greymap)
            filetype="pnm"
            ;;
        image/x-xpm )
            filetype="xpm"
            ;;
        * )
            filetype=unknown
            ;;
        esac
}



computeTypeFromTypeDescription () {

# $1 is the full description from 'file' of the file type

    case "$1" in
    
        *PBM* | *PGM* | *PPM* | *Netpbm*PAM*)
            filetype=pnm
            ;;
    
        *JPEG* | *JFIF* )
            filetype=jfif
            ;;
    
        *PNG* )
            filetype=png
            ;;
    
        *GIF* )
            filetype=gif
            ;;
    
        *TIFF* )
