HP3000-L Archives

February 2001, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Ken Hirsch <[log in to unmask]>
Reply To:
Ken Hirsch <[log in to unmask]>
Date:
Fri, 9 Feb 2001 09:18:27 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (119 lines)
Here is a script that converts spool files to text files, interpreting a few
carriage control characters.  Some people asked in the past about scripts to
do this so they could be then converted to PDF files.  This is barely
tested.  One novelty here is that the CI command file and the Perl script it
calls are in the same file.

Let me know if you find this useful.



PARM SPOOLFILE,TEXTOUT, opts=~A
  if 1 < 0
  ;
=pod
  The 'if' must be lowercase for this trick to work.
  ENDIF

# For example,
#    SPUL2TXT O254833.OUT.HPSPOOL,TEXTOUT
# or SPUL2TXT O254833.OUT.HPSPOOL,TEXTOUT,-b

PURGE SPFTEMP,TEMP  >$null
SETVAR _SPUL2TXT_EOF   FINFO("!SPOOLFILE","EOF")
SETVAR _SPUL2TXT_BYTES FINFO("!SPOOLFILE","BYTEFILESIZE")
BUILD SPFTEMP;TEMP;REC=-1008,,V,ASCII;DISC=![_SPUL2TXT_EOF]
FILE SPFTEMP,OLDTEMP

# With the one spool file I tested, the first page
# came out 1 line too long, so I skip the first record.
# I don't know if this is always a good thing.

FCOPY FROM=!SPOOLFILE;TO=*SPFTEMP;SUBSET=1  >$null

IF "!OPTS" = "~A"
  SETVAR _SPUL2TXT_OPTS ""
ELSE
  SETVAR _SPUL2TXT_OPTS "!OPTS"
ENDIF
SETVAR _SPUL2TXT_BYTES _SPUL2TXT_BYTES + 1000 + 2*_SPUL2TXT_EOF
BUILD !TEXTOUT;REC=-1,,B,ASCII;DISC=!_SPUL2TXT_BYTES
FILE !TEXTOUT,OLD
SETVAR _SPUL2TXT_PROG FINFO(HPFILE,"POSIXFULLFNAME")
PERL.PUB.PERL "!_SPUL2TXT_PROG !_SPUL2TXT_OPTS" <*SPFTEMP >*!TEXTOUT
RESET !TEXTOUT
RESET SPFTEMP
PURGE SPFTEMP,TEMP  >$null
DELETEVAR _SPUL2TXT@
RETURN
=cut
use Getopt::Std;

#
# cctl.pl
# Ken Hirsch <[log in to unmask]>
#

=pod
Crude interpreter of Carriage control characters.
Tries to handle page eject, double space, a few others

Use the '-b' option if the file should be interpreted
as prespacing (COBOL/FORTRAN) instead of postspacing.


The input can't be a spool file because POSIX programs can't
see the CCTL characters in a spool file.  However, you can
copy the spool file to a plain file and use that as input.

The output of this program might be suitable for input to,
say, txt2pdf, but no promises are made.

=cut

our $prespacing = 0;
my %opt;
getopts("b", \%opt);
$prespacing = 1 if defined($opt{b});
binmode(STDOUT);

while (<>) {
  chomp;
  my $cctl = substr($_, 0, 1);

  print interpret($cctl) if $prespacing;

  print substr($_, 1) if length($_) > 1;

  print interpret($cctl) unless $prespacing;
}

sub interpret {
  my $cctl = shift;
  my $result;
  if ($cctl le "\052") {
    $result = "\n";
  } elsif ($cctl eq '0') {
    $result = "\n\n";
  } elsif ($cctl =~ /[123]/) {
    $result = "\f";
  } elsif ($cctl eq '+') {
    $result = "\r";
  } elsif ($cctl eq '-') {
    $result = "\n\n\n";
  } elsif ($cctl gt "\200" && $cctl le "\277") {
    $result = "\n" x (ord($cctl) - 0200);
  } elsif ($cctl =~ /[\400\100]/) {
    $prespacing = 0;
    $result="\n";
  } elsif ($cctl =~ /[\401\101]/) {
    $prespacing = 1;
    $result="";
  } elsif ($cctl eq "") {
    $result="";
  } else {
    $result = "\n";
  }
  return $result;
}

ATOM RSS1 RSS2