#! /usr/bin/mawk -f
BEGIN { 

ID    =    "dclpsmerge 0.3"
DATE  =                               "95/03/19(numaguti)" 

EX    =    "merge multi-page dcl.ps into single image"

USAGE =  "% dclpsmerge <file>.."

#----------------------------------------------------------------------------
# NO OPTIONS

	  if (ARGV[1]=="help") { 
	      exithelp=1
	      print "  " ID,DATE
	      print " --- " EX
	      print " usage : " USAGE
              exit
          }
          exithelp=0

          head=1; body=0; page=0

}

/^%%BeginObject: background/ { while ( $0!="%%EndObject" ) getline; next }

/^%%Page:/ 	 { body=1; head=0; page++; 
                   if ( page==1 ) print "%%Page: 1 1"
                   next }
/showpage/       { body=0; next }

	         { if ( head==1 || body == 1) print }

END		 { if(exithelp==0) { 
                     print "showpage"
                     print "%%Trailer"
	             print "%%Pages:", page
	             print "%%EOF"   
                   }
                 }

