Debian Codegraph @

editor/pnmflip

raw
1 #!/bin/sh
2
3 ##############################################################################
4 # This is essentially a Perl program. We exec the Perl interpreter specifying
5 # this same file as the Perl program and use the -x option to cause the Perl
6 # interpreter to skip down to the Perl code. The reason we do this instead of
7 # just making /usr/bin/perl the script interpreter (instead of /bin/sh) is
8 # that the user may have multiple Perl interpreters and the one he wants to
9 # use is properly located in the PATH. The user's choice of Perl interpreter
10 # may be crucial, such as when the user also has a PERL5LIB environment
11 # variable and it selects modules that work with only a certain main
12 # interpreter program.
13 #
14 # An alternative some people use is to have /usr/bin/env as the script
15 # interpreter. We don't do that because we think the existence and
16 # compatibility of /bin/sh is more reliable.
17 #
18 # Note that we aren't concerned about efficiency because the user who needs
19 # high efficiency can use directly the programs that this program invokes.
20 #
21 ##############################################################################
22
23 exec perl -w -x -S -- "$0" "$@"
24
25 #!/usr/bin/perl
26 #============================================================================
27 # This is a compatibility interface to Pamflip.
28 #
29 # It exists so existing programs and procedures that rely on Pnmflip
30 # syntax continue to work. You should not make new use of Pnmflip and
31 # if you modify an old use, you should upgrade it to use Pamflip.
32 #
33 # The one way that Pamflip is not backward compatible with Pnmflip is
34 # that with Pnmflip, you can do this:
35 #
36 # pnmflip -xy -tb
37 #
38 # and that causes pnmflip to do both transformations (i.e. the same thing
39 # as -r270). With Pamflip, you can't specify multiple (or zero) flip
40 # type options. Instead, you would use the -xform option:
41 #
42 # pamflip -xform=transpose,topbottom
43 #
44 #============================================================================
45
46 use strict;
47 use File::Basename;
48 use Cwd 'abs_path';
49 use IO::Handle;
50
51 sub pm_message($) {
52 STDERR->print("pnmflip: $_[0]\n");
53 }
54
55
56
57 my $xformOpt;
58 my @miscOptions;
59 my $infile;
60
61 $xformOpt = '-xform='; # initial value
62
63 @miscOptions = ();
64
65 foreach (@ARGV) {
66 if (/^-/) {
67 # It's an option
68 if (/^-lr$/ || /^-le.*$/) {
69 $xformOpt .= "leftright,";
70 } elsif (/^-tb$/ || /^-to.*$/) {
71 $xformOpt .= "topbottom,";
72 } elsif (/^-x.*$/ || /^-tr.*$/) {
73 $xformOpt .= "transpose,";
74 } elsif (/^-r9.*$/ || /^-rotate9.*$/ || /^-cc.*$/) {
75 $xformOpt .= "transpose,topbottom,";
76 } elsif (/^-r1.*$/ || /^-rotate1.*$/) {
77 $xformOpt .= "leftright,topbottom,";
78 } elsif (/^-r2.*$/ || /^-rotate2.*$/ || /^-cw$/) {
79 $xformOpt .= "transpose,leftright,";
80 } else {
81 # It's not a transformation option; could be a Netpbm common
82 # option.
83 push(@miscOptions, $_);
84 }
85 } else {
86 # It's a parameter
87 if (defined($infile)) {
88 pm_message("You may specify at most one non-option parameter.");
89 exit(10);
90 } else {
91 $infile = $_;
92 }
93 }
94 }
95
96 # Finish off the -xform option by removing any trailing comma
97
98 $/ = ',';
99 chomp($xformOpt);
100
101 my $infileParm = defined($infile) ? $infile : "-";
102
103 # We want to get Pamflip from the same directory we came from if
104 # it's there. Frequently, the directory containing Netpbm programs is
105 # not in the PATH and we were invoked by absolute path.
106
107 my $my_directory = abs_path(dirname($0));
108 $ENV{"PATH"} = $my_directory . ":" . $ENV{"PATH"};
109
110 exec("pamflip", @miscOptions, $xformOpt, $infileParm);