#!/bin/sh
# build graphic filter services for Rhapsody DR2 (axel@uos.de 11/95, 1/97, 2/99)

  Provider=`pwd`/Provider	## requires Provider here
  [ -r "$Provider" ] || { echo Provider\? >&2; exit 1; }

  cd	## creates Library/Services/Netpbm.service below this point

# ------------------------------------------------------------------------ table
# each line describes how one extension is converted to TIFF.
# it consists of three, tab-separated fields: extension script comment.
# the extension must be unique.
# the script receives 'filename' as an argument to replace %@.
# info_item [below] sets PATH=/usr/local/bin:/usr/bin:/bin and runs
#	output through a temporary file because pnmtotiff seeks.

table () {
  sed 's/		*/	/g' << 'EOF'

# ascii	asciitopgm ht wid %@ | pnmtotiff	ASCII char gray values
atk		atktopbm %@ | pnmtotiff		Andrew Toolkit raster
atkras		atktopbm %@ | pnmtotiff
biorad		bioradtopgm %@ | pnmtotiff	Biorad confocal
bm		xbmtopbm %@ | pnmtotiff		X11 bitmap
bmp		bmptoppm %@ | pnmtotiff		MS Windows bitmap
brush		brushtopbm %@ | pnmtotiff	Xerox doodle brush
cmuwm		cmuwmtopbm %@ | pnmtotiff	CMU window manager bitmap
face		fnm=%@; scale=\"`fstopgm \"$fnm\" 2>&1 >/dev/null`\"; if [ \"$scale\" ]; then fstopgm \"$fnm\" | $scale; else fstopgm \"$fnm\"; fi | pgmnorm | pnmtotiff				BUG: sheared
fits		fitstopnm %@ | pnmtotiff	Flexible Image Transport Syst.
fs		fnm=%@; scale=\"`fstopgm \"$fnm\" 2>&1 >/dev/null`\"; if [ \"$scale\" ]; then fstopgm \"$fnm\" | $scale; else fstopgm \"$fnm\"; fi | pgmnorm | pnmtotiff				Usenix FaceSaver(tm)
g3		g3topbm %@ | pnmtotiff		Group 3 fax
gem		gemtopbm %@ | pnmtotiff		GEM .img
# gif		giftopnm %@ | pnmtotiff		CompuServe Graphics Image Fmt
giff		giftopnm %@ | pnmtotiff
gould		gouldtoppm %@ | pnmtotiff	Gould scanner
hips		hipstopgm %@ | pnmtotiff	Human Inf. Processing Systems
hpcd		hpcdtoppm %@ | pnmtotiff	Photo-CD (experimental)
icon		icontopbm %@ | pnmtotiff	SUN Icon and cursor
ilbm		ilbmtoppm %@ | pnmtotiff	Amiga ILBM (multi-format)
img		imgtoppm %@ | pnmtotiff		Img-whatnottoolkit
iris		sgitopnm %@ | pnmtotiff		SGI RGB image
ivb		tgatoppm %@ | pnmtotiff		Truevision Targa image
# jff		djpeg %@ | pnmtotiff		JPEG Group's minimal format
# jfif		djpeg %@ | pnmtotiff
# jpeg		djpeg %@ | pnmtotiff
# jpg		djpeg %@ | pnmtotiff
lispm		lispmtopgm %@ | pnmtotiff	Lisp Machine bitmap
macp		macptopbm %@ | pnmtotiff	Apple MacPaint
macpaint	macptopbm %@ | pnmtotiff
mgr		mgrtopbm %@ | pnmtotiff		MGR bitmap
mpnt		macptopbm %@ | pnmtotiff	Apple MacPaint
mtv		mtvtoppm %@ | pnmtotiff		MTV or PRT ray tracer
pbm		pnmtotiff %@			Portable Bit Map
pcc		pcxtoppm %@ | pnmtotiff		ZSoft IBM PC Paintbrush File
pcx		pcxtoppm %@ | pnmtotiff		ZSoft IBM PC Paintbrush File
pgm		pnmtotiff %@			Portable Gray Map
pi1		pi1toppm %@ | pnmtotiff		Atari Degas .pi1
pi3		pi3topbm %@ | pnmtotiff		Atari Degas .pi3
pict		picttoppm %@ | pnmtotiff	BUG: too picky
pict2		picttoppm %@ | pnmtotiff	BUG: too picky
pj		pjtoppm %@ | pnmtotiff		HP PaintJet
pnm		pnmtotiff %@			Portable aNy Map
pntg		macptopbm %@ | pnmtotiff	Apple MacPaint
ppm		pnmtotiff %@			Portable PixMap
pr		icontopbm %@ | pnmtotiff	SUN icon and cursor
# psid		psidtopgm			PostScript "image" data
qrt		qrttoppm %@ | pnmtotiff		QRT ray tracer
ras		rasttopnm %@ | pnmtotiff	SUN Raster
rast		rasttopnm %@ | pnmtotiff
# raw		rawtoppm WID HT %@ | pnmtotiff	Raw RGB bytes
rf		rasttopnm %@ | pnmtotiff	SUN Raster
rgb		sgitopnm %@ | pnmtotiff		SGI RGB image
rpbm		pnminvert %@ | pnmtotiff	Raw (binary) Portable Bit Map
rpgm		pnmtotiff %@			Raw (binary) Portable Gray Map
rpnm		pnmtotiff %@			Raw (binary) Portable aNy Map
rppm		pnmtotiff %@			Raw (binary) Portable PixMap
scr		rasttopnm %@ | pnmtotiff	SUN Raster
sgi		sgitopnm %@ | pnmtotiff		SGI RGB image
sir		sirtopnm %@ | pnmtotiff		Solitaire Image Recorder
sld		sldtoppm %@ | pnmtotiff		AutoCAD slide
spc		spctoppm %@ | pnmtotiff		Atari compressed Spectrum
spot		spottopgm %@ | pnmtotiff	SPOT satellite images
spu		sputoppm %@ | pnmtotiff		Atari uncompressed Spectrum
sr		rasttopnm %@ | pnmtotiff	SUN Raster
sun		rasttopnm %@ | pnmtotiff	SUN Raster
sunras		rasttopnm %@ | pnmtotiff	SUN Raster
tga		tgatoppm %@ | pnmtotiff		Truevision Targa
vda		tgatoppm %@ | pnmtotiff		Truevision Targa
x11		xwdtopnm %@ | pnmtotiff		X11 window dump
xbm		xbmtopbm %@ | pnmtotiff		X10/X11 bitmap
xim		ximtoppm %@ | pnmtotiff		Xim toolkit
xpm		xpmtoppm %@ | pnmtotiff		X11 pixmap
xwd		xwdtopnm %@ | pnmtotiff		X11 window dump
ybm		ybmtopbm %@ | pnmtotiff		Bennet Yee "face"
# yuv		yuvtoppm wid ht %@ | pnmtotiff	Abekas YUV bytes
zeiss		zeisstopnm %@ | pnmtotiff	Zeiss confocal

EOF
}

# -----------------------------------------  Netpbm.service/Resources/Info.plist

info_prolog () {
  echo '{'
  echo '  NSServices = ('
}

info_item () { # extension script
  echo '    { NSFilter = filter;'
  echo '      NSPortName = Netpbm;'
  echo '      NSExecutable = Provider;'
  echo '      NSUserData = "PATH=/usr/local/bin:/usr/bin:/bin; export PATH; '"$2"' >/tmp/netpbm$$; cat /tmp/netpbm$$; rm -f /tmp/netpbm$$";'
  echo '      NSSendTypes = (NSTypedFilenamesPboardType:'$1');'
  echo '      NSReturnTypes = (NSTIFFPboardType);'
  echo '      NSTimeout = 5000;'
  echo '    },'
}

info_epilog () {
  echo '  );'
  echo '}'
}

# ------------------------------------------------------------------------- main

[ -d Library ] || mkdir Library; cd Library
[ -d Services ] || mkdir Services; cd Services
[ -d Netpbm.service ] || mkdir Netpbm.service; cd Netpbm.service
[ -d Resources ] || mkdir Resources

exec 7>Resources/Info.plist

info_prolog >&7

table |
  while IFS='	' read extension script comment; do
    case "$extension"
    in '' | '#'*)	continue
    esac
    info_item "$extension" "$script" >&7
  done

info_epilog >&7

cp $Provider Provider; chmod 755 Provider
make_services -v 2>&1 | fgrep 'User Data:'
