#!/usr/local/bin/perl

# 
# psorient: Toggle or set PostScript file orientation.
# 
#     [1999/02/22] OSHIRO Naoki.
# 
#     $Log:$
#

require "getopts.pl";
&Getopts("plt"); # p:portrait l:landscape t:toggle(default)

$orient="Portrait" if ($opt_p);
$orient="Landscape" if ($opt_l);
if (!$opt_p && !$opt_l) {
    $opt_t=1;
    $orient="Landscape";
}

while (<>) {
    if (/^%%Orientation: (.+)\s*/) {
	if ($opt_t && $1=~/Landscape/i) {
	    print "%%Orientation: Portrait\n";
	} elsif ($opt_t && $1=~/Portrait/i) {
	    print "%%Orientation: Landscape\n";
	} else {
	    print "%%Orientation: $orient\n";
	}
	last;
    } elsif (/^%%EndComments\s*$/) {
	print "%%Orientation: $orient\n$_\n";
	last;
    }
    print;
}
while (<>) {
    print;
}
