HP3000-L Archives

July 2000, Week 1

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:
Mark Bixby <[log in to unmask]>
Reply To:
Mark Bixby <[log in to unmask]>
Date:
Wed, 5 Jul 2000 11:13:48 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (220 lines)
Ron Horner wrote:
>
> Is there a freeware program that will convert my HP MPE help text in to
> HTML pages.  Even if it's a script, that is fine.  Please send me the
> script, or program.  I don't have direct Internet access here.

http://www.bixby.org/ftp/pub/mpe/cicat2html.pl is a Perl script that will split
up CICAT.PUB.SYS into multiple HTML files with hyperlinks to each other.

Script follows; ignore all of the old CCCD references.  Use care if doing
cut/paste because this script contains numerous >80 lines that must not be
wrapped:

#!/usr/local/bin/perl -w

# A quick hack of an MPE CICAT to HTML converter.  Extracts all \ENTRY sections
# into their own separate HTML files named entry.html.  Generates anchors for
# \ITEMs, i.e. entry.html#item.  My design goal was to achieve decent results
# for command help; the other non-command sections may look a little strange.
#
# Attempts to generate hot links to other commands, variables, and functions.
#
# Learn Perl and regular expression pattern matching.  It will change your
life!
#
# Send comments, questions, and enhancements to:
#
# Mark Bixby
# [log in to unmask]
# http://www.cccd.edu/~markb/
# +1 714 438-4647
#
# While this is provided as freeware that you can do whatever you want with,
# please leave the first continuous block of comments intact.
#
# Official distribution site:
#
#       http://www.cccd.edu/ftp/pub/mpe/cicat2html.pl
#       http://www.cccd.edu/ftp/pub/mpe/cicat2html.html
#       ftp://ftp.cccd.edu/pub/mpe/cicat2html.pl
#       ftp://ftp.cccd.edu/pub/mpe/cicat2html.html
#
# Change history:
#
# 1.0   March 26, 1997
#
#               Official release.

#
# Configuration variables.
#

# The input catalog.
$catalog = '/SYS/PUB/CICAT';

# The output directory tree.
$destdir = '/APACHE/CCCD/html/mpe/cicat';

#
# No user-serviceable parts below.
#

sub cicatlink ($;$) {
my $entity = $_[0];
my $link = lc($#_ ? $_[1] : $_[0]);
"<A HREF=\"$link.html\">$entity</A>" }

$entry = '';
$commands = '';

#
# Make a hash of all HP variables known by :SHOWVAR HP@
#

($hpvars = `callci showvar hp@`) =~ s/(^HP.*?) .*/$1\n$1/gm;
@hpvarl = split("\n",$hpvars);
%hpvarh = @hpvarl;

# Manually add variables that only exist for jobs.

$hpvarh{'HPLASTSPID'} = 'HPLASTSPID';
$hpvarh{'HPSPOOLID'} = 'HPSPOOLID';

# Make a manual hash of all alphabetic HP operators, i.e. arg1 op arg2.
# Note that we intentionally omit AND and OR so we don't mangle ordinary
# English sentences.

%hpoprh = (
  'BAND','BAND',
  'BNOT','BNOT',
  'BOR','BOR',
  'BXOR','BXOR',
  'CSL','CSL',
  'CSR','CSR',
  'LSL','LSL',
  'LSR','LSR',
  'MOD','MOD',
  'XOR','XOR');

# Make a hash of all HP functions, i.e. func(arg1,arg2), known by
# :HELP FUNCTIONS.  This code will certainly break if HP changes the format
# of this particular :HELP entry.

($hpfuns = `callci "help functions" </dev/null`) =~ s/^(.*?)\s*$/$1/m;
$hpfuns =~ s/^.*\nFunction\s+Description\n\n(.*?)\n\n.*/$1/s;

foreach $function (split("\n",$hpfuns)) {
  $hpfunh{$1} = $1 if $function =~ /^([A-Z]+)/ && !($hpoprh{$1})
}

# Manually tweak functions whose \ENTRY is different than their name.

$hpfunh{'INPUT'} = 'INPUTFN';
$hpfunh{'SETVAR'} = 'SETVARFN';

# Open the catalog and obtain the last modification time.

open(MPE,"<$catalog") || die "Unable to open $catalog: $!";

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
= stat(MPE);

$asof = "Generated from $ENV{'HPRELVERSION'} $catalog last modified on
".localtime($mtime);

# Read the catalog and break it apart.

while (<MPE>) {
  chop;
  ($line = $_) =~ s/(^.*?)\s*\d{8}$/$1/;

  if ($line =~ /^\\ENTRY=(\w+)/) {
    #
    # Start of a new main section.
    #
    $commands = '';
    if ($entry) {
      #
      # Terminate the previous main section.
      #
      print HTML '</PRE></BODY></HTML>';
      close(HTML) || die "Unable to close $destdir/$entry.html: $!";
    };
    $entry = lc($1);
    print "ENTRY=$entry\n";
    #
    # Create HTML file and standard header stuff.
    #
    open(HTML,">$destdir/$entry.html") || die "Unable to open
$destdir/$entry.html: $!";
    print HTML
"<HTML><HEAD><TITLE>$1</TITLE></HEAD><BODY><H1>$1</H1><P><I>$asof</I></P><HR><PRE>\n";
  } elsif ($line =~ /^\\CONTINUE/) {
    # Just ignore for now.
  } elsif ($line =~ /^\\ITEM=(\w+)$/) {
    #
    # Items result in HTML #anchors.
    #
    $item = lc($1);
    print HTML "<A NAME=\"$item\"></A>\n";
  } elsif (length($line) > 3 && length($line) < 40 && $line =~
/^([-:\/()A-Z\=]+)( [-:\/()A-Z\=]+)*$/) {
    #
    # Smells like a heading.
    #
    print HTML "</PRE><H2>$line</H2><PRE>\n";
  } elsif ($line =~ /Commands\s*:/i && $line =~ /:\s+.*?[A-Z]{2,}/) {
    #
    # Start of list of other command names.
    #
    ($commands = $line) =~ s/(.*?:\s+)(.*)/$2/;
    print HTML $1;
    $commands =~ s/([A-Z]{2,})/cicatlink($1)/eg;
    print HTML "$commands\n";
  } elsif ($commands) {
    #
    # Continuation of list of other command names.
    #
    if ($line) {
      ($commands = $line) =~ s/([A-Z]{2,})/cicatlink($1)/eg;
      print HTML "$commands\n";
    } else {
      $commands = '';
      print HTML "\n";
    };
  } else {
    #
    # Unknown.  Deal with random command, variable, and function names.
    #
    # Commands.
    #
    ($random = $line) =~ s/^:([A-Z]{2,})/':'.cicatlink($1)/ie;
    $random =~ s/( +:)([A-Z]{2,})/$1.cicatlink($2)/ieg;
    #
    # Variables.
    #
    $random =~ s/(HP[_A-Z]{3,})/$hpvarh{uc($1)} ? cicatlink($1) : $1/ieg;
    $random =~ s/(CIERROR)/cicatlink($1)/ieg;
    $random =~ s/(\W)(JCW)(s*\W)/$1.cicatlink($2).$3/ieg;
    $random =~ s/^(JCW)(s*)(\W)/cicatlink($1)."$2$3"/ie;
    #
    # Functions.
    #
    $random =~ s/([A-Z]{2,})(\s*\()/$hpfunh{uc($1)} ?
cicatlink($1,$hpfunh{uc($1)}).$2 : "$1$2"/ieg;
    $random =~ s/([A-Z]{2,})/$hpfunh{$1} ? cicatlink($1,$hpfunh{$1}) : $1/eg if
$entry eq 'functions';
    #
    # Operators.
    #
    $random =~ s/(\s)([A-Z]{2,})(\s)/$hpoprh{uc($2)} ?
$1.cicatlink($2,$hpoprh{uc($2)}).$3 : "$1$2$3"/ieg;
    $random =~ s/([A-Z]{2,})/$hpoprh{$1} ? cicatlink($1,$hpoprh{$1}) : $1/eg if
$entry eq 'functions';
    print HTML "$random\n";
  };
};

close(MPE) || die "Unable to close $catalog: $!";

ATOM RSS1 RSS2