<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.ccarh.org/index.php?action=history&amp;feed=atom&amp;title=Mpg2pag</id>
	<title>Mpg2pag - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.ccarh.org/index.php?action=history&amp;feed=atom&amp;title=Mpg2pag"/>
	<link rel="alternate" type="text/html" href="https://wiki.ccarh.org/index.php?title=Mpg2pag&amp;action=history"/>
	<updated>2026-04-07T21:13:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://wiki.ccarh.org/index.php?title=Mpg2pag&amp;diff=11952&amp;oldid=prev</id>
		<title>Craig: Created page with &quot;&lt;pre&gt; #!/usr/bin/perl # # Programmer:    Craig Stuart Sapp &lt;craig.stanford.edu&gt; # Creation Date: Wed Jan 22 22:48:42 PST 2020 # Last Modified: Wed Jan 22 22:48:45 PST 2020 # F...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.ccarh.org/index.php?title=Mpg2pag&amp;diff=11952&amp;oldid=prev"/>
		<updated>2022-11-03T18:59:24Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;pre&amp;gt; #!/usr/bin/perl # # Programmer:    Craig Stuart Sapp &amp;lt;craig.stanford.edu&amp;gt; # Creation Date: Wed Jan 22 22:48:42 PST 2020 # Last Modified: Wed Jan 22 22:48:45 PST 2020 # F...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/perl&lt;br /&gt;
#&lt;br /&gt;
# Programmer:    Craig Stuart Sapp &amp;lt;craig.stanford.edu&amp;gt;&lt;br /&gt;
# Creation Date: Wed Jan 22 22:48:42 PST 2020&lt;br /&gt;
# Last Modified: Wed Jan 22 22:48:45 PST 2020&lt;br /&gt;
# Filename:      mpg2pag&lt;br /&gt;
# Syntax:        perl 5&lt;br /&gt;
# vim:           ts=3&lt;br /&gt;
#&lt;br /&gt;
# Description:   Converted the original MPG (single page i-files) for&lt;br /&gt;
#                each part into a single PAG (multi-page i-file).  Recursively&lt;br /&gt;
#                goes through each directory to collages the individual&lt;br /&gt;
#                pages files.  The location of the page file is given at&lt;br /&gt;
#                the start of the file on a line that starts:&lt;br /&gt;
#                   @@@FILE:&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use Getopt::Long;&lt;br /&gt;
&lt;br /&gt;
my @dirs = @ARGV;&lt;br /&gt;
&lt;br /&gt;
my $listQ = 0;&lt;br /&gt;
my $prefix = `pwd`;&lt;br /&gt;
my $prefixb = &amp;quot;vivaldi&amp;quot;;&lt;br /&gt;
chomp $prefix;&lt;br /&gt;
$prefix =~ s/.*\///;&lt;br /&gt;
Getopt::Long::Configure(&amp;quot;bundling&amp;quot;);&lt;br /&gt;
GetOptions (&lt;br /&gt;
   &amp;#039;l|list&amp;#039; =&amp;gt; \$listQ,&lt;br /&gt;
	&amp;#039;b|base=s&amp;#039; =&amp;gt; \$prefix,&lt;br /&gt;
	&amp;#039;p|prefix=s&amp;#039; =&amp;gt; \$prefixb&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
for my $dir (@dirs) {&lt;br /&gt;
	if (!-d $dir) {&lt;br /&gt;
		print STDERR &amp;quot;$dir is not a directory\n&amp;quot;;&lt;br /&gt;
		next;&lt;br /&gt;
	}&lt;br /&gt;
	processDirectory($dir);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
exit(0);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###########################################################################&lt;br /&gt;
&lt;br /&gt;
##############################&lt;br /&gt;
##&lt;br /&gt;
## processDirectory -- Gemerate a PAG file for the specified &lt;br /&gt;
##     directory which represents an instrumental part.&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
sub processDirectory {&lt;br /&gt;
	my ($dir) = @_;&lt;br /&gt;
	my @files = getFileList($dir);&lt;br /&gt;
	for (my $i=0; $i&amp;lt;@files; $i++) {&lt;br /&gt;
		$files[$i] =~ s=\/\/=\/=g;&lt;br /&gt;
	}&lt;br /&gt;
	if ($listQ) {&lt;br /&gt;
		for (my $i=0; $i&amp;lt;@files; $i++) {&lt;br /&gt;
			print &amp;quot;$files[$i]\n&amp;quot;;&lt;br /&gt;
		}&lt;br /&gt;
		return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	for (my $i=0; $i&amp;lt;@files; $i++) {&lt;br /&gt;
		my $name = &amp;quot;$prefixb/$prefix/$files[$i]&amp;quot;;&lt;br /&gt;
		$name =~ s=\/\/=\/=g;&lt;br /&gt;
		$name =~ s=^\/==;&lt;br /&gt;
		print &amp;quot;\@\@\@FILE: $name\n&amp;quot;;&lt;br /&gt;
		open (FILE, $files[$i]) or die &amp;quot;Cannot read $files[$i]\n&amp;quot;;&lt;br /&gt;
		my @contents = &amp;lt;FILE&amp;gt;;&lt;br /&gt;
		close FILE;&lt;br /&gt;
		for (my $j=0; $j&amp;lt;@contents; $j++) {&lt;br /&gt;
			my $line = $contents[$j];&lt;br /&gt;
			chomp $line;&lt;br /&gt;
			$line =~ s/\s+$//;&lt;br /&gt;
			print &amp;quot;$line\n&amp;quot;;&lt;br /&gt;
		}&lt;br /&gt;
		print &amp;quot;P\n&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##############################&lt;br /&gt;
##&lt;br /&gt;
## getFileList -- Return a recursive list of files in the given directory.&lt;br /&gt;
##    The files should be MPG (single page i-files), but this is not&lt;br /&gt;
##    checked (use the -l option to list the files for a basic check).&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
sub getFileList {&lt;br /&gt;
	my ($basedir) = @_;&lt;br /&gt;
	my @output;&lt;br /&gt;
	my @dirs = getDirs(&amp;quot;$basedir&amp;quot;);&lt;br /&gt;
	my @files = getFiles(&amp;quot;$basedir&amp;quot;);&lt;br /&gt;
	for (my $i=0; $i&amp;lt;@files; $i++) {&lt;br /&gt;
		$output[@output] = &amp;quot;$basedir/$files[$i]&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	for (my $i=0; $i&amp;lt;@dirs; $i++) {&lt;br /&gt;
		push(@output, getFileList(&amp;quot;$basedir/$dirs[$i]&amp;quot;));&lt;br /&gt;
	}&lt;br /&gt;
	return @output;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##############################&lt;br /&gt;
##&lt;br /&gt;
## getFiles -- Get a list of the files in the specified directory.&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
sub getFiles {&lt;br /&gt;
	my ($dir) = @_;&lt;br /&gt;
	opendir (DIR, $dir) or die &amp;quot;Cannot open directory $dir\n&amp;quot;;&lt;br /&gt;
	my @output;&lt;br /&gt;
	while (my $file = readdir(DIR)) {&lt;br /&gt;
		next if $file =~ /^\./;&lt;br /&gt;
		next if -d &amp;quot;$dir/$file&amp;quot;;&lt;br /&gt;
		if (-r &amp;quot;$dir/$file&amp;quot;) {&lt;br /&gt;
			$output[@output] = $file;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	closedir(DIR);&lt;br /&gt;
	return sort @output;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##############################&lt;br /&gt;
##&lt;br /&gt;
## getDirs -- Get a list of the directories in the specified directory.&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
sub getDirs {&lt;br /&gt;
	my ($dir) = @_;&lt;br /&gt;
	opendir (DIR, $dir) or die &amp;quot;Cannot open directory $dir\n&amp;quot;;&lt;br /&gt;
	my @output;&lt;br /&gt;
	while (my $file = readdir(DIR)) {&lt;br /&gt;
		next if $file =~ /^\./;&lt;br /&gt;
		if (-d &amp;quot;$dir/$file&amp;quot;) {&lt;br /&gt;
			$output[@output] = $file;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	closedir(DIR);&lt;br /&gt;
	return sort @output;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Craig</name></author>
	</entry>
</feed>