1#!/bin/sh 2# 3# xbm-cmd filename pbmplus-command args... 4# 5# An example filter for use in the xbmbrowser user menus to perform various 6# pbmplus commands directly on both Xbitmap and X pixmap files. This uses 7# the suffix of the icons filename to determine which 8# 9# Anthony Thyssen 16 Dec 1993 anthony@cit.gu.edu.au 10# 11file="$1" # get the filename 12shift # any argument left is the pbmplus command 13 14exec </dev/null # no stdard input please 15 16TMP1=/tmp/xbmcmd$$.1 # temporary files 17TMP2=/tmp/xbmcmd$$.2 18trap "rm -f $TMP1 $TMP2; exit 0" 0 # remove temps on exit 19 20# on any failure exit 21set -e "$@" 22 23if [ ! -r "$file" ]; then 24 echo >&2 "xbm-cmd: Unable to read \"$i\"" 25 exit 10; 26fi 27if [ ! -w "$file" ]; then 28 echo >&2 "xbm-cmd: Unable to write \"$i\"" 29 exit 10; 30fi 31 32# --- extract the file suffix --- 33suffix="`basename $file`" 34suffix="`expr "$suffix" : '.*\.\([^.]*\)'`" 35 36# --- convert to PbmPlus format --- 37case "$suffix" in 38 xbm) xbmtopbm > $TMP1 ;; 39 xpm) xpmtoppm > $TMP1 ;; 40 *) echo >&2 "Unknown suffix for \"$file\"" 41 exit 0 ;; 42esac 43 44# --- execute the command given --- 45"$@" < $TMP1 > $TMP2 46 47if [ ! -f $TMP2 -o ! -s $TMP2 ]; then 48 echo >&2 "Command failed for \"$file\"" 49 exit 0; 50fi 51 52# --- convert back --- 53case "$suffix" in 54 xbm) pbmtoxbm < $TMP2 > "$file" ;; 55 xpm) ppmtoxpm < $TMP2 > "$file" 2>/dev/null ;; # this command is noisy 56esac 2>/dev/null 57 58exit 0 59 60