#!/bin/sh # # icon2xbm - convert SunView icons to X11 bitmaps # # Original :- Jonathan Bowen, Oxford University, June 1988. # bowen@prg.oxford.ac.uk # Rewritten :- Anthony Thyssen, Griffith University, April 1992. # anthony@cit.gu.edu.au # PATH=/usr/ucb:/usr/bin:/usr/bin/X11 PROGNAME=`basename $0` TMP=/tmp/$PROGNAME$$ VERBOSE=false Usage() { echo "Usage: $PROGNAME [-v] file..." echo " -v enable verbose messages" exit 0 } trap "/bin/rm -f $TMP; exit 1" 1 2 3 15 while getopts v i do case "$i" in v) VERBOSE=true ;; # be verbose in actions \?) Usage ;; esac done shift `expr $OPTIND - 1` case $# in 0) Usage ;; *) FILES=$* ;; esac for FILE in $FILES do # Check for standard extensions if [ ! -r $FILE ]; then FILE=$FILE.icon fi if [ ! -r $FILE ]; then echo "$PROGNAME: can't read $FILE" 1>&2 else case "$FILE" in *.icon) BASENAME="`basename $FILE .icon`" ;; *.iconmask) BASENAME="`basename $FILE .iconmask`_mask" ;; *) BASENAME="$FILE" ;; esac # Read SunView icon, detect width and height, # convert from 16-bit words to 8-bit bytes, reverse bits in bytes and # split into lines with four entries on each line. # # Typical first two lines: # /* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16 # */ ( # stdout redirection sub-shell # read header and output X version eval `sed -n \ 's/^.*Width=\([0-9]*\).*Height=\([0-9]*\).*$/width=\1;height=\2/p' \ $FILE` $VERBOSE && echo "$PROGNAME: processing $FILE (${width}x${height})" 1>&2 cat - <<-HEADER_END #define ${BASENAME}_width $width #define ${BASENAME}_height $height static char ${BASENAME}_bits[] = { HEADER_END sed \ '1,2 d /0x/ { s|^[ ]||g s|\(0x....,0x....,0x....,0x....\),\(.\)|\1:\2| s|0x||g; s|,||g s|0|----|g s|1|---#|g s|2|--#-|g s|3|--##|g s|4|-#--|g s|5|-#-#|g s|6|-##-|g s|7|-###|g s|8|#---|g s|9|#--#|g s|[aA]|#-#-|g s|[bB]|#-##|g s|[cC]|##--|g s|[dD]|##-#|g s|[eE]|###-|g s|[fF]|####|g }' $FILE |\ tr ':' '\012' | atobm -name $BASENAME |\ sed '1,/bits/d' ) | cat > ${BASENAME}.xbm fi done /bin/rm -f $TMP exit 0