%% xyps-ps.tex from $Id: xyps-ps.doc,v 3.7 1999/02/16 15:12:50 krisrose Exp $
%%
%% Xy-pic ``PS-PS'' PostScript support.
%% Copyright (c) 1993-1997 Ross Moore <ross@mpce.mq.edu.au>
%%
%% This file is part of the Xy-pic package for graphs and diagrams in TeX.
%% See the companion README and INSTALL files for further information.
%% Copyright (c) 1991-1997 Kristoffer H. Rose <krisrose@ens-lyon.fr>
%%
%% The Xy-pic package is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by the
%% Free Software Foundation; either version 2 of the License, or (at your
%% option) any later version.
%%
%% The Xy-pic package is distributed in the hope that it will be useful, but
%% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
%% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
%% for more details.
%%
%% You should have received a copy of the GNU General Public License along
%% with this package; if not, write to the Free Software Foundation, Inc.,
%% 675 Mass Ave, Cambridge, MA 02139, USA.
%%
%% As a special exception, you may use this file and all files derived
%% from it without restrictions. This special exception was added with
%% version 3.7 of Xy-pic.
%%
\expandafter\ifx\csname xyps-psloaded\endcsname\empty
 \message{not reloaded}\endinput \fi
\expandafter\let\csname xyps-psloaded\endcsname=\empty \xycatcodes
\xylet@\PSmacro@@=\eat@
\xylet@\PSdict@@=\eat@
\xylet@\PSspecial@@=\eat@
\xylet@\PSread@@=\eat@
\xylet@\PSinclude@@=\eat@
\xylet@\PSraw@@=\eat@
\xylet@\xyPSobeylines@@=\relax
\xylet@\PSspecialdict@@=\eat@
\xydef@\UnloadPSps@{%
 \let\PSmacro@@=\eat@
 \let\PSdict@@=\eat@
 \let\PSspecial@@=\eat@
 \let\PSread@@=\eat@
 \let\PSinclude@@=\eat@
 \let\PSraw@@=\eat@
 \let\xyPSobeylines@@=\relax
 \let\PSspecialdict@@=\eat@
}
\xydef@\UnloadPS@{\UnloadPSps@
 \expandafter\ifx\csname xypsloaded\endcsname\unknown\PSspecials@false
 \else\expandafter\NoPSspecials\fi}
\xylet@\UnloadPS@@=\UnloadPS@
\ifx\undefined\dvitype@\xydef@\dvitype@{null}\fi
\xylet@\xyrealshipout@=\shipout
\xydef@\xyPSshipout@{\setbox9=\copy\voidb@x
 \afterassignment\xyPSshipout@i\setbox9=}
\xydef@\xyPSshipout@i{\ifvoid9 \expandafter\aftergroup\fi\xyPSshipout@ii}
\xydef@\xyPSshipout@ii{\xyrealshipout@\vbox{\XYpredict@@\box9}}
\xydef@\@PSshipout{\global\let\shipout=\xyPSshipout@ }
\xydef@\xyPSshipout@PSii{%
 \ifUsePSdict@@\let\XYshipdict@=\includeXYPSdict@@
 \else\def\XYshipdict@{\XYpredict@@\XYdict@@}\fi
 \xyrealshipout@\vbox{\XYshipdict@\box9}}
\xydef@\firstPS@{%
 \global\let\firstPS@@=\relax \global\let\firstPS@=\relax}
\xylet@\firstPS@@=\firstPS@
\ifx\undefined\dumpPSdict@@ \xylet@\dumpPSdict@@=\relax \fi
\xydef@\installxyps@{%
 \xyinputorelse@{xyps-ps}{\xydrivernoload@{ps-ps}}\xycatcodes
 \installxyps@@ \installxyps@x }
\xylet@\installxyps@@=\relax
\xylet@\setupxyPS@@=\relax
\xywithoption{ps}{\let\setupxyPS@@=\setupxyPS@}
\xydef@\installxyps@x{\dumpPSdict@@ 
 \ifx\xyrealshipout@\undefined \let\xyrealshipout@=\shipout\fi
 \ifx \shipout \xyrealshipout@ 
 \ifUsePSdict@@ \DN@{\includePSmessage@\includeXYPSdict@\message{>}}%
 \else \DN@{\XYdict@\endXYdict@}\fi
 \else \DN@{\let\xyPSshipout@ii=\xyPSshipout@PSii \@PSshipout}\fi
 \let\firstPS@=\relax \next@
 \let\XYpredict@=\relax
 \setupxyPS@@ }
\let\realinstallxyps@x=\installxyps@x
\ifx\undefined\AfterBeginDocument
 \def\installxyps@x{\xysetup@@{\realinstallxyps@x}}%
\else
 \def\installxyps@x{\AfterBeginDocument{\realinstallxyps@x}}%
\fi
\xydef@\xydefaultdriver@{dvips}
\xydef@\xyPSdriver#1{\def\xydefaultdriver@{#1}}
\xydef@\installxyps@orig{\DN@{}%
 \ifx\xydriversselected@@\empty
 \DN@{\expandafter\defaultinstallps@\expandafter{\xydefaultdriver@}}%
 \else \def\do##1{%
 \expandafter\ifx\csname##1@xy@ps\endcsname\relax
 \DN@{\defaultinstallps@{##1}}}%
 \xydriversselected@@ 
 \else \DN@##1{}\fi\fi \next@ }
\xydef@\defaultinstallps@#1#2{%
 \xywarning@{no driver specified, using #1 }%
 \xyrequire{#1}\csname #1@xy@ps\endcsname{}}
\xydef@\null@xy@ps{\installxyps@}
\xydefcsname@{shape [!...]}#1{%
 \expandafter\ifx\csname xyps-sloaded\endcsname\empty \DN@{\xyPSescapestyle@{#1}@@}%
 \else\ifxyPSshapes@\DN@{\xyPSshapechar@{#1}@@}%
 \else \DN@{\xyPScharwarning@}\fi\fi \next@ }
\xydefcsname@{shape [psxy]}{\ifxyPSshapes@\DN@{\xyPSpsxy@}%
 \else \DN@{\xyPScharwarning@}\fi \next@ }
\xydef@\xyPSpsxy@{%
 \setboxz@h{\dimen@=\L@p \advance\dimen@-\R@p 
 \dimen@ii=-\U@p \raise\dimen@ii\hbox to\z@{%
 \kern\dimen@\xyPScurrpt@\kern-\dimen@}\boxz@}}%
\xydef@\xyPScurrpt@{\ifxyPSshapes@\expandafter\xyPScurrpt@@\fi}
\xydef@\xyPScurrpt@@@{\PSspecial@@{xyi}\PSraw@@{userdict begin xyx end}}
\ifx\undefined\xyPScurrpt@@ \xylet@\xyPScurrpt@@=\xyPScurrpt@@@ \fi
\xywarnifdefined\xyPSshapechar@
\xywarnifdefined\xyPSsplitshape@
{\xyuncatcodes \catcode`@=11
 \gdef\xyPSshapechar@#1@@{\xyPSsplitshape@#1<><>@@}%
 \gdef\xyPSsplitshape@#1<>#2<>#3@@{\xyPSsplitPS@{#1}{#2}}}
\xydef@\xyPSrawA@#1{\expandafter\xyPSrawAA@ #1{}}%
\xydef@\xyPSrawAA@#1#2{\PSraw@@{{pu #1}xyg #2}%
 \PSmessage{{pu #1}xyg #2}}%
\xydef@\xyPSrawZ@#1{\PSraw@@{{#1 pp}xyf}\PSmessage{{#1 pp}xyf}}%
\xydef@\modPSboxz@{%
 \expandafter\DN@\expandafter{\xyPSpre@{}}\ifx\next@\empty\else
 \setboxz@h{\expandafter\xyPSrawA@\expandafter{\xyPSpre@{}}\boxz@
 \expandafter\xyPSrawZ@\expandafter{\xyPSpost@}}\DN@{}\fi}%
\xydef@\modPSdrop@{%
 \expandafter\DNii@\expandafter{%
 \expandafter\xyPSrawA@\expandafter{\xyPSpre@{}}}%
 \DN@##1{\expandafter\def\expandafter\tmp@\expandafter{\nextii@ ##1}}%
 \expandafter\next@\expandafter{\Drop@@}%
 \expandafter\DNii@\expandafter{%
 \expandafter\xyPSrawZ@\expandafter{\xyPSpost@}}%
 \DN@##1{\expandafter\def\expandafter\Drop@@\expandafter{\tmp@ ##1}}%
 \expandafter\next@\expandafter{\nextii@}}%
\xydef@\modPSconnect@{%
 \expandafter\DNii@\expandafter{%
 \expandafter\xyPSrawA@\expandafter{\xyPSpre@{}}}%
 \DN@##1{\expandafter\def\expandafter\tmp@\expandafter{\nextii@ ##1}}%
 \expandafter\next@\expandafter{\Connect@@}%
 \expandafter\DNii@\expandafter{%
 \expandafter\xyPSrawZ@\expandafter{\xyPSpost@}}%
 \DN@##1{\expandafter\def\expandafter\Connect@@\expandafter{\tmp@ ##1}}%
 \expandafter\next@\expandafter{\nextii@}}%
\xydef@\xyPSpre@{{}{}}
\xydef@\xyPSpost@{}
\xydef@\PSmessage@#1{\W@{PS: #1, direction=\the\Direction}}
\xydef@\PSignore@#1{}%
\xydef@\showPSmessages{\let\PSmessage=\PSmessage@}
\xydef@\hidePSmessages{\let\PSmessage=\PSignore@}
\xylet@\PStracing=\showPSmessages
\hidePSmessages
\xydef@\PSmacro@#1{\PSmacro@@{#1}\PSmessage{#1}}
\xydef@\includeXYPSdict@@{%
 \expandafter\PSinclude@@\expandafter{\xyPSdictname}}
\xydef@\includeXYPSdict@r{\message{PS: includeXYPSdict}\includeXYPSdict@@
 \let\includeXYPSdict@=\relax}
\xylet@\includeXYPSdict@\includeXYPSdict@r
\xydef@\endXYdict@{}
\xydef@\includePSmessage@@{\message{<xyps: including \xyPSdictname}}
\xylet@\includePSmessage@=\includePSmessage@@ 
\xydef@\xyPSdictknown@{%
 \immediate\closein\xyread@
 \xywarning@{File \xyPSdictname\space already exists}
 \message{ Do you wish to overwrite it \string? y/n }%
 \read16 to \next
 \DNii@{\xywarning@{You did not type Y or N -- try again please}%
 \xyPSdictknown@}%
 \DN@{Y }\ifx\next@\next \DNii@{\writePSdict@@}%
 \else\DN@{y }\ifx\next@\next \DNii@{\writePSdict@@}%
 \else\DN@{n }\ifx\next@\next \DNii@{\cancelPSdict@}%
 \else\DN@{N }\ifx\next@\next \DNii@{\cancelPSdict@}%
 \fi\fi\fi\fi \nextii@ }
\xydef@\cancelPSdict@{%
 \xywarning@{cancelling dump of PostScript dictionary}}
\xydef@\noDictmessage@{%
 \xywarning@{\dvitype@\space does not support the use of a header file}}
\DN@{\csname newif\endcsname\ifUsePSdict@@\DN@{}}
 \ifx\undefined\UsePSdict@@true\else\DN@{}\fi \next@
\ifx\undefined\xyPSdefaultdict
 \xydef@\xyPSdefaultdict{%
 \DN@##1.##2.##3@{\gdef\xyPSdictname{xy##1##2dict.pro}}%
 \expandafter\next@\xyversion.@}%
\fi
\ifx\undefined\UsePSheader@
 \xydef@\UsePSheader@#1{%
 \DN@{#1}\ifx\next@\empty
 \else \gdef\xyPSdictname{#1}\fi
 \ifx\xyPSdictname\undefined\xyPSdefaultdict\fi
 \gdef\xyHeaderMessage@{%
 It includes a reference to the PostScript file \xyPSdictname.^^J}%
 \UsePSdict@@true}%
 \let\UsePSheader=\UsePSheader@
\fi
\xywarnifdefined\xyPS@@
\xywarnifdefined\xyPS@@@
{\catcode`|=14 \catcode`\%=12 \catcode`\<=1 \catcode`\>=2 |
 \gdef\xyPS@@<%%>\gdef\xyPS@@@<%!>}
\xydef@\writePSdict@@{\message{PS: writePSdict@@}\writePSdict@ 
 \def\writePSdict@@{\message{write PS relaxed}}}
{\catcode`|=14 \catcode`\%=12 
 \gdef\writePSdict@{{\begingroup|
 \immediate\openout\xywrite@=\xyPSdictname \relax
 \message{<xyps: dumping \xyPSdictname}|
 \def\PSdict@@@##1{\immediate\write\xywrite@{##1}}|
 \let\xyPSobeylines@@=\obeyoutlines@
 \let\firstPS@@=\relax
 \let\endXYdict@=\relax
 \PSdict@@@{\xyPS@@@ PS-Adobe-3.0 Resource-procset}|
 \PSdict@@@{\xyPS@@ Title: \xyPSdictname}|
 \PSdict@@@{\xyPS@@ Version: 3.7}|
 \PSdict@@@{\xyPS@@ Creator: Xy-ps backend to Xy-pic}|
 \PSdict@@@{\xyPS@@ DocumentSuppliedProcSets: XYdict}|
 \ifx\dvitype@\undefined
 \PSdict@@@{\xyPS@@ For: use with Xy-pic}\else
 \PSdict@@@{\xyPS@@ For: \dvitype@ use of Xy-pic}\fi
 \PSdict@@@{\xyPS@@ BeginResource: procset XYdict}|
 \def\PSspecialdict@@##1{\PSdict@@@{##1^^J}}|
 \let\PSdict@@=\PSdict@@@ \let\xy@begindvi=\literal@|
 \UsePSdict@@false\XYpredict@@|
 \XYdict@@|
 \PSdict@@@{\xyPS@@ EndResource}|
 \immediate\closeout\xywrite@
 \message{>}|
 \endgroup}}}
\xywarnifdefined\obeyoutlines@
{\catcode`\^^M=\active%
 \gdef\obeyoutlines@{\catcode`\^^M=\active \def^^M{^^J}%
 \newlinechar=`\^^J\obeyspaces}}
\xydef@\XYpredict@@{\ifUsePSdict@@\DN@{}\else
 \DN@{\xy@begindvi{\xyinputorelse@{xyps-pro}%
 {\xyerror@{Could not load xyps-pro}{}}\xyuncatcodes}}%
 \next@
 \DN@{\xy@begindvi{\xyinputorelse@{xypspatt}%
 {\xyerror@{Could not load xypspatt}{}}\xyuncatcodes}}\fi
 \next@ }
\xydef@\XYpredict@r{\XYpredict@@ \let\XYpredict@=\relax \installxyps@}
\xylet@\XYpredict@\XYpredict@r
\xydef@\XYdict@{\XYdict@@\def\XYdict@{\message{PS relaxed}}}%
\xydef@\XYdict@@{\DN@{\xyinputorelse@{xypsdict}%
 {\xyerror@{Could not load xypsdict}{}}\xyuncatcodes}%
 \expandafter\xy@begindvi\expandafter{\next@}}
\xydef@\forceload@XYdict{%
 \let\includeXYPSdict@=\includeXYPSdict@r
 \let\XYpredict@=\XYpredict@r
 \let\XYdict@=\XYdict@@ \expandafter\installxyps@ }
\xynew@{if}\ifxyPSshapes@ \xyPSshapes@true 
\xydef@\xyPScharwarning@@{\xyPScharmessage@
 \gdef\xyPScharwarning@@{\xyPScharmessage@
 \xywarning@{...no further PostScript warnings will be given}%
 \global\let\xyPScharwarning@@=\relax }}
\xydef@\xyPScharmessage@{\xywarning@{%
 the current <driver> does not fully support PostScript effects}}%
\xydef@\newxyshape#1#2#3{%
 \DN@{#3}\ifx\next@\empty
 \xydefcsname@{shape [#1]}{\csname xyshape@#1@\endcsname}%
 \else \expandafter\def\csname shape [#1]\endcsname{%
 \csname xyshape@#1@\endcsname}\fi
 \DN@{#2}\ifx\next@\empty
 \expandafter\def\csname xyshape@#1@\endcsname{%
 \xyundefinedEffect@{#1}{}@@}%
 \else \expandafter\def\csname xyshape@#1@\endcsname{#2}\fi }
\xydef@\xyundefinedEffect@#1#2@@{%
 \xywarning@{The #1 #2 effect is not implemented with the current driver}}%
\xydef@\newxyPSshape#1#2{%
 \expandafter\DN@\expandafter{\csname shape [#1]\endcsname}%
 \DNii@{\relax}\ifx\next@\nextii@ \newxyshape{#1}{}\relax\fi
 \expandafter\DNii@\expandafter{\csname xyPSshape@#1@\endcsname}%
 \expandafter\def\nextii@{#2}%
 \ifx\nextii@\empty\expandafter\def\next@{\xyPSnotimplemented@@`#1'@@}%
 \else
 \edef\tmp@{\noexpand\let\expandafter\noexpand\next@
 \expandafter\noexpand\nextii@}%
 \expandafter\tmp@\fi }
\xydef@\xyPSnotimplemented@@#1@@{%
 \xywarning@{This PostScript effect is not implemented yet}}%
\xydef@\xyPSnotfinished@@{%
 \xywarning@{This effect is not reliable yet; box sizes may be wrong}}%
\endinput
