#! /usr/bin/ruby -w # kern-ps-merge - put vgrind-generated ps files together # Copyright (C) 2003 Ed Cashin # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # usage: # kern-ps-merge {psdir} > /tmp/foo.ps # ... where psdir is the destdir from a kern-ps invocation # # example: # cd /path/to/2.5.70/.. # kern-ps /tmp/ps 2.5.70/include 2.5.70/kernel/fork.c 2.5.70/mm/mmap.c # kern-ps-merge /tmp/ps > /tmp/all.ps # gv /tmp/all.ps # require 'find' require 'tempfile' if not (psdir = ARGV[0]) then STDERR.puts "usage: kern-ps-merge {psdir}" exit 1 end if not test(?r, psdir) then STDERR.puts "#{psdir} unreadable" exit 1 end files = [] Find.find psdir do |f| if test ?f, f then files << f end end cfiles = [] ofiles = [] files.sort! files.each { |f| if f =~ /\.c\.ps$/ then cfiles << f else ofiles << f end } files = cfiles + ofiles header = `sed -n '1,/^%%EndProlog/p' #{files[0]}` tmp = Tempfile.new "kern-ps-merge-pages" pageno = 0 files.each do |f| pages = `sed -e '1,/^%%EndProlog/d' -e '/^%%Trailer/,$d' #{f}` pages = pages.split(/^%%Page: \d+ \d+/) pages.shift if pages[0] == "" pages.each { |p| pageno += 1 tmp.printf "%%%%Page: #{pageno} #{pageno}" tmp.puts p } end tmp.close puts header.sub(/^%%Pages: \d+$/, "%%Pages: #{pageno}") tmp.open while line = tmp.gets do puts line end tmp.close(true) # true => go ahead and delete file here puts <