#! /bin/sh

case `basename $0` in
	gprev*)	show="cat > /tmp/gs$$.ps; gs /tmp/gs$$.ps < /dev/tty; rm -f /tmp/gs$$.ps"; prep="erasepage 20 780 sethome" ;;
	prev*)	show=psh ; prep="erasepage 20 780 sethome" ;;
	pspre*)	show=cat ; prep="12 setfontsize" ;;
	*)	show=lpr ; prep="12 setfontsize" ;;
esac

psatops () {
#	3 further transformations on decomp's output:
#	^M -> ^J : to edit it on unix machines
#	< > -> { } : to make it a PostScript program
#	remove access restriction operators to play around with it in an 
#		interactive PostScript interpreter
	sed -e 'y/
<>/\n{}/' -e 's/executeonly//g' -e 's/noaccess//g' -e 's/readonly//g'
	}

pfbtops () {
	if t1disasm $1
	then true	# t1disasm did the job
	elif decrypt $1 | decomp | psatops
	then true	# decrypt, decomp did the job
	else false	# no one found to do the job
	fi
	}

pfbtopfa () {
	if t1ascii $1
	then true	# t1ascii did the job
	elif pfb2ps < $1
	then true	# one of numerous PD programs could do this simple job
	else	case $1 in
		*.pfb)	fmAdobePCFont $1 ${TMPDIR-/tmp}/$$.pfa ;;
		*.pfe|*.rsrc)	fmAdobeMacFont $1 ${TMPDIR-/tmp}/$$.pfa ;;
		esac
		# this should be found in $FMHOME/bin
		# it runs slower than others
		cat ${TMPDIR-/tmp}/$$.pfa
		/bin/rm ${TMPDIR-/tmp}/$$.pfa
	fi
	}

((cat
echo $prep
if [ "$show" = "psh" ]
then	cat $HOME/ps/emulate.ps - << \*EOP*
%!
% (emulate.ps) run % alternatively to cat-ting it in
/eexec {pop} def
/*definefont /definefont load def
/definefont {dup /FontType get 1 eq
	{dup length 3 add dict copy
	 dup /FontType 3 put
	 dup /Type1EmuDict dup load put
	 dup /BuildChar dup load put
	} if
	1 index registername	% this could be left out if only
			% new fonts (not preloaded into NeWS) are displayed
	*definefont
	} def
/*closefile /closefile load def
/closefile {pop} def % NeWS's closefile crashes
/executeonly {} def
/noaccess {} def
/readonly {} def
*EOP*
fi
for param in $*
do if [ `dirname $param` = / ]
   then echo $param registername
	# take this as explicitly specified fontname instead of filename
   else
	case $param in
	*.pfb|*.pfe|*.rsrc)
		if [ "$show" = "psh" ]
		then	pfbtops $param
		else	pfbtopfa $param
		fi
		echo appendnewfont ;;
	*.pfa)	if [ "$show" = "psh" ]
		then	pfbtops $param
		else	cat $param
		fi
		echo appendnewfont ;;
	*.Z)	zcat $param
		echo appendnewfont ;;
	*.zip)	unzip -p $param
		echo appendnewfont ;;
	*)	cat $param
		echo appendnewfont ;;
	esac
   fi
done ; echo "    " showallfonts showpage quit) | eval $show) << \*EOP*
%! print font samples and character sets
/home {leftborder top moveto} def
/sethome {/top exch def /leftborder exch def} def
/setfontsize {/fontsize exch def} def
/setrightborder {/rightborder exch def} def
40 790 sethome
18 setfontsize
550 setrightborder
/leading 4 def
/nl {currentpoint exch pop leftborder exch fontsize sub leading sub moveto} def

/fontN {fontN} def
/fontB {fontN} def
/fontI {fontB} def
/fontBI {fontB} def
/N {fontN setfont} def
/B {fontB setfont} def
/I {fontI setfont} def
/BI {fontBI setfont} def
/pushfont {/fontBI /fontI load def
	/fontI /fontB load def
	/fontB /fontN load def
	/fontN currentfont def
	} def
/nextfonti 0 def
/setnextfont {[/fontN /fontI /fontB /fontBI] nextfonti get currentfont def
	/nextfonti nextfonti 1 add def
	} def

/namefont {currentfont} def
/showtext {
  N
  (Scoloplos ist eury�k. Er ist in der gesamten borealen Region ) show nl
  (in fast allen marinen Sedimenten zu finden, die einen sandigen ) show nl
  (Anteil aufweisen. Man findet ihn von ) show B (Gr�nland ) show 
	N (bis zum ) show I (Mittelmeer) show N (, ) show nl
  (in der ) show BI (Nordsee) show 
	N (, an der kanadischen K�ste und im Wei�en Meer. ) show nl
  (Er besiedelt sowohl das Eulitoral als auch das Bathyal.) show nl
	} def
/showcset {[cs1 cs2 cs3 cs4 cs5 cs6 cs7] {show nl} forall
	currentfont
	currentpoint
	dup fontsize leading add 3 mul add
		currentfont /FontName get findfont 50 scalefont setfont
		rightborder (Forqen) stringwidth pop sub exch moveto
		(Forqen) show
	moveto
	setfont
	} def
/showcsetbig {
	2 2 scale
	[cs1 cs2 cs3 cs4 cs5 cs6 cs7] {show nl} forall
	.5 .5 scale
	currentfont
	currentpoint
	dup fontsize leading add -2 mul add
		currentfont /FontName get findfont 100 scalefont setfont
		rightborder (Forqen) stringwidth pop sub exch moveto
		(Forqen) show
	moveto
	setfont
	} def
/showname {currentfont namefont setfont
	dup /FontName get dup length string cvs show
	setfont nl
	} def
/showfont { % param: fontname
	fontsize ff
	home
	showtext
	showname
	showcset	% or: showcsetbig
	} def
/showallfonts {
	% if registername was used, replace the automatically generated 
	% fontlist with the explicit one:
	fontlistr length 0 ne {/fontlist fontlistr def} if

	fontlist {fontsize ff setnextfont} forall
	home showtext
	[fontN fontI fontB fontBI] 0 fontlist length getinterval
	{nl setfont (    ) show showname nl
	 showcset	% or: showcsetbig
	} forall
	} def

/findfontISO {dup findfont
	dup maxlength dict begin
	{1 index /FID ne {def} {pop pop } ifelse} forall
	Encoding StandardEncoding eq
	%	pop true
		{/Encoding ISO-Latin-1 def} if
	currentdict end
	definefont
	} def
/ff {exch findfontISO exch dup /fontsize exch def scalefont
	setfont} def

/fontlist [] def
/fontlistr [] def
/FontDirectoryKnown FontDirectory dup length 20 add dict begin
	{def}
	forall
	currentdict end def
/appendnewfont {
	/fontlist [ fontlist aload pop
	FontDirectoryKnown begin
	FontDirectory
	{FontDirectoryKnown 2 index known {pop pop} {2 copy def pop} ifelse
	} forall
	end
	] def
	} def
/registerfont {run appendnewfont} def
/registername {/newfont exch def
	/fontlistr [ fontlistr aload pop newfont ] def
	} def

/=dict { % for debugging
	{2 array astore ==} forall
	} def

/cs1	( !"#$%&'()*+,-./0123456789:;<=>?) def
/cs2	(@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_) def
/cs3	(`abcdefghijklmnopqrstuvwxyz{|}~) def
/cs4	(��������������������������������) def
/cs5	(��������������������������������) def
/cs6	(��������������������������������) def
/cs7	(��������������������������������) def

/ISO-Latin-1 [
/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
/space /exclam /quotedbl /numbersign /dollar /percent /ampersand /quoteright
%							     or: /quotesingle
/parenleft /parenright /asterisk /plus /comma /hyphen /period /slash
/zero /one /two /three /four /five /six /seven
/eight /nine /colon /semicolon /less /equal /greater /question
/at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O
/P /Q /R /S /T /U /V /W
/X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore
/quoteleft /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o
% or: /grave
/p /q /r /s /t /u /v /w
/x /y /z /braceleft /bar /braceright /asciitilde /fraction
% accents not in ISO-Latin-1:
/dotlessi /ring /circumflex /tilde /breve /dotaccent
/grave % see comment below
% FrameMaker characters:
/quotesingle % comment: must have /quoteleft instead of /grave, or
		%	/quoteright instead of /quotesingle, resp.,
		%	depending on which is already present above
/quotesinglbase /quotedblbase /quotedblleft /quotedblright
/guilsinglleft /guilsinglright
/trademark
/caron /hungarumlaut /ogonek
/OE /oe
/fi /fl
/dagger /daggerdbl /ellipsis /emdash /florin /periodcentered /perthousand
% DEC-supplemental (also /OE /oe):
/Ydieresis
% further PostScript chars:
/Lslash /lslash

% this must align with 240 octal
/space /exclamdown /cent /sterling /currency /yen /brokenbar /section
/dieresis /copyright /ordfeminine /guillemotleft /logicalnot /endash /registered /macron
/degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph /bullet
/cedilla /onesuperior /ordmasculine /guillemotright /onequarter /onehalf /threequarters /questiondown
/Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla
/Egrave /Eacute /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis
/Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply
/Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls
/agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla
/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis
/eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis /divide
/oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis
] def

*EOP*