about summary refs log tree commit diff
path: root/converter/other/anytopnm
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-10-31 18:11:36 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-10-31 18:11:36 +0000
commitc6ce346a40129072ced2518963e7006db48b14a8 (patch)
tree0cc6a37279712ff1ea8f6087586f929b70738cab /converter/other/anytopnm
parent125866f73191d541f6c4870aadbafe26db5f4741 (diff)
downloadnetpbm-mirror-c6ce346a40129072ced2518963e7006db48b14a8.tar.gz
netpbm-mirror-c6ce346a40129072ced2518963e7006db48b14a8.tar.xz
netpbm-mirror-c6ce346a40129072ced2518963e7006db48b14a8.zip
Use --mime-type on newer File; recognize 'Netpbm PAM' non-mime output of File
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2653 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/anytopnm')
-rwxr-xr-xconverter/other/anytopnm37
1 files changed, 29 insertions, 8 deletions
diff --git a/converter/other/anytopnm b/converter/other/anytopnm
index f3a00793..397faae5 100755
--- a/converter/other/anytopnm
+++ b/converter/other/anytopnm
@@ -47,18 +47,39 @@ putInputIntoTempfile() {
 
 
 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
 
-    # Christos Zoulas's current 'file' (see Freshmeat) has the --mime option.
+    # 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 /dev/null >/dev/null 2>/dev/null
+    file --mime-type /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-`
+        # Now that we know the --mime-type option exists, use it.
+        mimeType=`file --mime-type "$1" | cut -d: -f2- | cut -c2-`
     else
-        # file --mime failed; we don't know why, but we assume it's because it
-        # is a traditional 'file' program that doesn't have a --mime option.
-    mimeType="unknown"
+        # 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
 }
 
@@ -109,7 +130,7 @@ computeTypeFromTypeDescription () {
 
     case "$1" in
     
-        *PBM* | *PGM* | *PPM* )
+        *PBM* | *PGM* | *PPM* | *Netpbm*PAM*)
             filetype=pnm
             ;;