Using the listings package, you can name your listings to make them share a line counter:
On the other hand you can use firstnumber=auto and name your listings. Listings with identical names (case sensitive!) share a line counter.
However, this only seems to work when the lstlisting environment is used, not when using \lstinputlisting. After a closer examination of the manual, this seems to be documented:
name=<name>names a listing. Displayed environment-listings with the same name share a line counter if firstnumber=auto is in effect.
I was wondering if anyone knows some kind of "trick" to share line counters across \lstinputlistings.
Here is a MWE to demonstrate the issue:
\documentclass{article}
\usepackage{listings}
\lstset{numbers=left,firstnumber=auto}
\begin{document}
\begin{lstlisting}[name=bar]
...
\end{lstlisting}
\begin{lstlisting}[name=bar] %first line number is the last of previous listing + 1
...
\end{lstlisting}
\lstinputlisting[name=foo]{foo.c}
\lstinputlisting[name=foo]{foo.c} %first line number is 1
\end{document}

listingspackage (TeXLive 2011) and it seems that the numbering does not resume in any of the cases. – Peter Grill Apr 8 '12 at 18:08Package Listings Warning: Text dropped after begin of listing on input line 10.in the console though, so perhaps my problem is related to that. – Peter Grill Apr 9 '12 at 14:25