#!/usr/local/bin/perl
# $Id$
$VERSION{'PUBLIC'} = '2.000';
$VERSION{__FILE__} = '$Revision$';
#
# >>Title::     PostScript Conversion Utility
#
# >>Copyright::
# Copyright (c) 1992-1997, Ian Clatworthy (ianc@mincom.com).
# You may distribute under the terms specified in the LICENSE file.
#
# >>History::
# -----------------------------------------------------------------------
# Date      Who     Change
# 18-Jul-97 ianc    SDF 2.000
# -----------------------------------------------------------------------
#
# >>Purpose::
# {{CMD:prn2ps}} converts Windows PostScript to Unix PostScript.
# The input to this program is typically generated by printing
# to a PostScript printer connected to the FILE: logical device.
# The output can be converted to Encapsulated PostScript using
# GhostScript's {{CMD:p2epsi}} program.
#
# >>Description::
# !SDF_OPT_STD
#
# For each input file, the output is generated by:
#
# * deleting the {{PageSize}} information
# * deleting the control-D at the end of the file.
#
# >>Limitations::
# If {{CMD:ps2epsi}} doesn't like the output, you may need to
# use another printer driver to generate the input.
# On Windows NT 4.0, the {{Canon PS-IPU Color Laser Copier v52.3}}
# driver works most of the time.
#
# >>Examples::
# To generate an Encapsulated PostScript file from Windows PostScript:
#
# >  prn2ps -ops myfig.prn
# >  ps2epsi myfig.ps
#
# >>Implementation::
#

require "sdf/app.pl";

########## Initialisation ##########

# define configuration
%app_config = (
    'libdir',   'sdf/home',
);

# define options
#push(@app_option, (
#    #'Name|Spec|Help',
#));

# handle options
&AppInit('prn_file ...', "convert Windows PostScript to Unix PostScript",
  'SDF') || &AppExit();

########## Processing ##########

sub argProcess {
    my($ARGV) = @_;
#   my();
    local($_);
    
    # Open the input
    unless (open(FILE, $ARGV)) {
        &AppMsg("abort", "failed to open '$ARGV'");
        return;
    }

    # Generate the output
    my $end = '';
    while (<FILE>) {
        if ($end) {
            $end = '' if /^\Q$end/;
            next;
        }
        elsif (index($_, '%%BeginFeature: *PageSize') == 0) {
            $end = '%%EndFeature';
            next;
        }
        next if /^\004/;    # Ignore the terminating ^D
        print;
    }
    close(FILE);

}

&AppProcess('argProcess');
&AppExit();
