% Copyright (C) 2012 Peter Breitenlohner <tex-live@tug.org>
% You may freely use, modify and/or distribute this file.
%
%% copied from plain.tex {{
\catcode`\{=1 % left brace is begin-group character
\catcode`\}=2 % right brace is end-group character
\catcode`\$=3 % dollar sign is math shift
\catcode`\&=4 % ampersand is alignment tab
\catcode`\#=6 % hash mark is macro parameter character
\catcode`\^=7 \catcode`\^^K=7 % circumflex and uparrow are for superscripts
% \catcode`\_=8 \catcode`\^^A=8 % underline and downarrow are for subscripts
\catcode`\^^I=10 % ascii tab is a blank space
\chardef\active=13 \catcode`\~=\active % tilde is active
\catcode`\^^L=\active \outer\def^^L{\par} % ascii form-feed is "\outer\par"
\parfillskip=0pt plus 1fil
\def\loop#1\repeat{\def\body{#1}\iterate}
\def\iterate{\body \let\next\iterate \else\let\next\relax\fi \next}
\let\repeat=\fi % this makes \loop...\if...\repeat skippable
%% }}

\everyjob={\expandafter\doIt\jobname ---\relax}

\def\doIt #1-#2-#3-#4-#5-#6\relax {
  \if A#6A
    \includeImage #1 #2 #3
  \else
    \includeImage #1-#2-#3 #4 #5
  \fi
  \end
}
\def\includeImage #1 #2 #3 {
    \count1=0  
    \count2=#2
    \count3=#3
    \loop
        \shipout\vbox{
            \count0=0
            \hsize=20cm
            \noindent
            \loop
                \immediate\pdfximage width 1cm height 1cm {#1}
                \hbox{\pdfrefximage\pdflastximage}
                \hskip 0pt plus \hsize
                \advance\count0 1
            \ifnum\count0 < \count2 \repeat
        }
        \advance\count1 1
    \ifnum\count1 < \count3 \repeat
}
\pdfoutput=1
\errorstopmode
\dump
