Description: Add "$Q" key in header for page numbers that don't reset
  abcm2ps supports a "$P" key in header or footer lines that will output
  the current page number and can be reset using "%%newpage". In my
  books of SCD ball sets, I like to include both the page number inside
  the tune and the page number inside the book on every page, so the
  "$Q" adds another page number that is not changeable by the user.
Author: Anselm Lingnau <lingnau@debian.org>
Last-Update: 2009-12-21

Index: abcm2ps-5.9.7/abc2ps.c
===================================================================
--- abcm2ps-5.9.7.orig/abc2ps.c	2009-12-21 10:26:58.000000000 +0100
+++ abcm2ps-5.9.7/abc2ps.c	2009-12-21 10:27:24.000000000 +0100
@@ -54,6 +54,7 @@
 
 int tunenum;			/* number of current tune */
 int pagenum = 1;		/* current page in output file */
+int pagenum_nr = 1;		/* current page (non-resettable) */
 
 int in_page;
 
Index: abcm2ps-5.9.7/abc2ps.h
===================================================================
--- abcm2ps-5.9.7.orig/abc2ps.h	2009-12-21 10:24:52.000000000 +0100
+++ abcm2ps-5.9.7/abc2ps.h	2009-12-21 10:26:48.000000000 +0100
@@ -277,6 +277,7 @@
 extern int outft;		/* last font in the output file */
 extern int tunenum;		/* number of current tune */
 extern int pagenum;		/* current page number */
+extern int pagenum_nr;		/* current page number (non-resettable) */
 extern int nbar;		/* current measure number */
 extern int nbar_rep;		/* last repeat bar number */
 extern int in_page;
Index: abcm2ps-5.9.7/buffer.c
===================================================================
--- abcm2ps-5.9.7.orig/buffer.c	2009-12-21 10:27:50.000000000 +0100
+++ abcm2ps-5.9.7/buffer.c	2009-12-21 10:40:27.000000000 +0100
@@ -259,6 +259,18 @@
 			}
 			fprintf(fout, "%d", pagenum);
 			break;
+		case 'Q':		/* non-resetting page number */
+			if (p[1] == '0') {
+				p++;
+				if (pagenum_nr & 1)
+					break;
+			} else if (p[1] == '1') {
+				p++;
+				if ((pagenum_nr & 1) == 0)
+					break;
+			}
+			fprintf(fout, "%d", pagenum_nr);
+			break;
 		case 'T':		/* tune title */
 			q = &info['T' - 'A']->as.text[2];
 			while (isspace((unsigned char) *q))
@@ -429,6 +441,7 @@
 	if (cfmt.footer != 0)
 		posy -= headfooter(0, pwidth, pheight);
 	pagenum++;
+	pagenum_nr++;
 	outft = -1;
 }
 
