#!/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 # markb@cccd.edu # 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]); "$entity" } $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" ) { 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 ''; 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 "$1

$1

$asof


\n";
  } elsif ($line =~ /^\\CONTINUE/) {
    # Just ignore for now.
  } elsif ($line =~ /^\\ITEM=(\w+)$/) {
    #
    # Items result in HTML #anchors.
    #
    $item = lc($1);
    print HTML "\n";
  } elsif (length($line) > 3 && length($line) < 40 && $line =~ /^([-:\/()A-Z\=]+)( [-:\/()A-Z\=]+)*$/) {
    #
    # Smells like a heading.
    #
    print HTML "

$line

\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: $!";