%%
%% This is file `pagesel.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% pagesel.dtx  (with options: `package')
%% 
%% This file is part of the package `pagesel' for use with LaTeX2e.
%% 
%% Function: Selecting shipout output pages.
%% 
%% Copyright (C) 1999, 2003 Heiko Oberdiek.
%% 
%% This program may be distributed and/or modified under
%% the conditions of the LaTeX Project Public License,
%% either version 1.2 of this license or (at your option)
%% any later version. The latest version of this license
%% is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions
%% of LaTeX version 1999/12/01 or later.
%% 
%% Please send error reports and suggestions for improvements to
%%   Heiko Oberdiek <oberdiek@uni-freiburg.de>.
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pagesel}
  [2003/06/05 v1.2 Selecting shipout output pages (HO)]
%% \CharacterTable
%%  {Upper-case    \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
%%   Lower-case    \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
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
\@ifundefined{ps@makevoid}{}{%
  \PackageWarningNoLine{pagesel}{Package already loaded.}%
  \endinput
}
\newcommand*{\ps@makevoid}{%
  \global\setbox\@cclv\copy\voidb@x
  \begingroup
    \count@=\deadcycles
    \advance\count@ by -1\relax
    \deadcycles=\count@
  \endgroup
}
\newcommand*\ps@oddpages{0}
\DeclareOption{odd}{\renewcommand*\ps@oddpages{1}}
\DeclareOption{even}{\renewcommand*\ps@oddpages{2}}
\DeclareOption{nofiles}{\let\ps@nofiles\nofiles}
\DeclareOption{nonofiles}{\let\ps@nofiles\@empty}
\DeclareOption{files}{\let\ps@nofiles\@empty}
\ExecuteOptions{nofiles}
\DeclareOption*{%
  \begingroup
    \expandafter\ps@checkoption\CurrentOption-\END
    \edef\x{\endgroup\noexpand\ps@store{\ps@first}{\ps@last}}%
  \x
}
\newcommand\ps@checkoption{}
\def\ps@checkoption#1-#2\END{%
  \ifx\\#2\\%
    \ifx\\#1\\%
      % empty option
      \def\ps@first{\maxdimen}%
      \def\ps@last{\maxdimen}%
    \else
      \edef\ps@first{#1}%
      \edef\ps@last{#1}%
    \fi
  \else
    \ifx\\#1\\%
      \def\ps@first{-\maxdimen}%
    \else
      \edef\ps@first{#1}%
    \fi
    \ps@checklast#2%
  \fi
}
\newcommand\ps@checklast{}
\def\ps@checklast#1-{%
  \ifx\\#1\\%
    \def\ps@last{\maxdimen}%
  \else
    \edef\ps@last{#1}%
  \fi
}
\newcommand*{\ps@store}[2]{%
  \expandafter\def\expandafter\ps@testlist\expandafter{%
    \ps@testlist\ps@pagetest{#1}{#2}%
  }%
}
\newcommand*\ps@testlist{}
\ProcessOptions
\begingroup
  \edef\x{%
    \ifnum\ps@oddpages>0 \relax\fi
    \ifx\ps@testlist\@empty\else\relax\fi
  }%
  \ifx\x\@empty
    \endgroup
    \PackageInfo{pagesel}{Nothing to do}
    \expandafter\endinput
  \fi
\endgroup
\RequirePackage{everyshi}
\ps@nofiles
\newcounter{ps@count}
\setcounter{ps@count}{0}
\long\def\ps@ReturnAfterElseFi#1\else#2\fi{\fi#1}
\long\def\ps@ReturnAfterFi#1\fi{\fi#1}
\newcommand{\ps@ifinset}[4]{%
  \ifnum#1>\value{ps@count}%
    \ps@ReturnAfterElseFi{#4}%
  \else
    \ps@ReturnAfterFi{%
      \ifnum#2<\value{ps@count}%
        \ps@ReturnAfterElseFi{#4}%
      \else
        \ps@ReturnAfterFi{#3}%
      \fi
    }%
  \fi
}
\newcommand*{\ps@pagetest}[2]{%
  \ps@ifinset{#1}{#2}{\let\ps@next\@empty}{}
}
\EveryShipout{%
  \stepcounter{ps@count}%
  \let\ps@next\@empty
  \ifx\ps@testlist\@empty
  \else
    \let\ps@next\ps@makevoid
    \ps@testlist
  \fi
  \ifnum\ps@oddpages=1
    \ifodd\value{ps@count}%
    \else
      \let\ps@next\ps@makevoid
    \fi
  \fi
  \ifnum\ps@oddpages=2
    \ifodd\value{ps@count}%
      \let\ps@next\ps@makevoid
    \else
    \fi
  \fi
  \ps@next
}
\endinput
%%
%% End of file `pagesel.sty'.
