\makeatletter

\def\@mapcar#1#2{\def\@mapsep{}\@for\@mapitem:=#1\do
                 {\@mapsep #2{\@mapitem}\def\@mapsep{,}}}

\def\@pageprint#1{{\def\c@page{#1}\thepage}}

\newif\if@inrange
\newcount\lastplus@ne
\def\@rangify#1{\lastplus@ne=-1\@inrangefalse
		\def\@mapsep{}
		\@for\@mapitem:=#1\do {\@@rangify\@mapitem\def\@mapsep{,}}%
\if@inrange\@last\fi}

\def\@@rangify#1{\ifnum#1=\lastplus@ne\if@inrange\else\@inrangetrue--\fi\fi
	\ifnum#1>\lastplus@ne\if@inrange\@inrangefalse\@last\fi\@mapsep #1\fi
	\edef\@last{#1}\lastplus@ne=#1\advance\lastplus@ne by 1}

\def\@tempmac{bar}
\write\@auxout{\string\newlabel{foo}{{\@tempmac}{\thepage}}}
\xdef\@gtempa{\write\@auxout{\string\newlabel{baz}{{\@tempmac}{\thepage}}}}\@gtempa

\section{Stuff}
Abc \label{foobar} def
\newpage

\xdef\@gtempa{\write\@auxout{\string
\citationpages{\@rangify{1,2,3,5,6,8,8,10,11,11,11,12,14,14,15,17,18,18}}}}
\@gtempa

\makeatother
