<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/env perl
use strict;
$^W=1;
# pst-geo-uncompress.pl
# Copyright (C) 2009 Heiko Oberdiek.
#
# This work may be distributed and/or modified under the
# conditions of the LaTeX Project Public License, either version 1.3
# of this license or (at your option) any later version.
# The latest version of this license is in
#   http://www.latex-project.org/lppl.txt
# and version 1.3 or later is part of all distributions of LaTeX
# version 2005/12/01 or later.
#
# This work has the LPPL maintenance status `maintained'.
#
# The Current Maintainer of this work is Heiko Oberdiek.
#
# See file "README" for a list of files that belong to this project.
my $file        = "pst-geo-uncompress.pl";
my $program     = uc($&amp;) if $file =~ /^\w+/;
my $version     = "1.0";
my $date        = "2009/07/30";
my $author      = "Heiko Oberdiek";
my $copyright   = "Copyright (c) 2009 by $author.";
# History:
#   2009/07/30 v1.0: First release.
my $title = "$program $version, $date - $copyright\n";
print STDERR $title;
my $prg_gs = "gs";
$prg_gs = "gs386"    if $^O =~ /dos/i;
$prg_gs = "gsos2"    if $^O =~ /os2/i;
$prg_gs = "gswin32c" if $^O =~ /mswin32/i;
$prg_gs = "gswin32c" if $^O =~ /cygwin/i;
$prg_gs = "mgs"      if defined($ENV{"TEXSYSTEM"}) and
                        $ENV{"TEXSYSTEM"} =~ /miktex/i;

$::opt_help = 0;

my $usage = &lt;&lt;"END_OF_USAGE";
Function: Compresses data files for pst-geo
Syntax: $0 &lt;input file&gt; [output file]
If the output file is not given, standard output is used.
Options:                                         (defaults:)
  --help           print usage
  --gscmd &lt;name&gt;   call of ghostscript           ($prg_gs)
END_OF_USAGE
use Getopt::Long;
GetOptions(
  "help!",
  "gscmd=s" =&gt; \$prg_gs
) or die $usage;
!$::opt_help or die $usage;

(@ARGV == 1 or @ARGV == 2) or die $usage;

my $input = $ARGV[0];
my $output = $ARGV[1];

open(IN, '&lt;', $input) or die "!!! Error: Cannot open file `$input'!\n";
my $header = &lt;IN&gt; . &lt;IN&gt;;
$header =~ /^%!PS\s+(.*)currentfile((&lt;&lt;[^&gt;]+&gt;&gt;)?\/[\w\d]+ filter) cvx exec\s*$/s
        or die "!!! Error: Unknown file format of `$input'!\n";
my $decode = $2;
my $pos = tell(IN);
my $ps_input = unpack 'H*', $input;
my $ps_output = '';
my $ps_output = unpack 'H*', $output if $output;

my $ps_code = &lt;&lt;"END_PS_CODE";
%!PS
/buf 10000 string def
&lt;$ps_input&gt; (r) file
dup $pos setfileposition
$decode
END_PS_CODE
$ps_code .= &lt;&lt;"END_PS_CODE" if $output;
&lt;$ps_output&gt; (w) file
exch
END_PS_CODE
$ps_code .= &lt;&lt;"END_PS_CODE";
{ dup buf readstring exch
END_PS_CODE
$ps_code .= &lt;&lt;"END_PS_CODE" unless $output;
  print
END_PS_CODE
$ps_code .= &lt;&lt;"END_PS_CODE" if $output;
  3 index exch writestring
END_PS_CODE
$ps_code .= &lt;&lt;"END_PS_CODE";
  not {exit} if
} loop
closefile
END_PS_CODE
$ps_code .= &lt;&lt;"END_PS_CODE" if $output;
closefile
END_PS_CODE
$ps_code .= &lt;&lt;"END_PS_CODE";
quit
%%EOF
END_PS_CODE
my @cmd = (
    $prg_gs,
    '-q',
    '-sDEVICE=nullpage',
    '-dBATCH',
    '-c',
    $ps_code
);
system @cmd;
if ($? &amp; 127) {
    die sprintf "!!! Error: Ghostscript died with signal %d!\n",
                ($? &amp; 127);
}
elsif ($? != 0) {
    die sprintf "!!! Error: Ghostscript exited with error code %d!\n",
                $? &gt;&gt; 8;
}
print STDERR "* `$output' written.\n" if $output;
__END__
</pre></body></html>