home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / fteo46b5.zip / fteo46b5 / scripts / mkcmds.pl < prev    next >
Perl Script  |  1998-01-31  |  3KB  |  140 lines

  1. #!perl -w
  2.  
  3. print <<EOD;
  4. <HTML>
  5. <HEAD>
  6. <TITLE>Macro Commands</TITLE>
  7. </HEAD>
  8. <BODY>
  9. EOD
  10.  
  11. sub out {
  12.     my $lin = $_[0];
  13.     $lin =~ s/\&/\&./og;
  14.     $lin =~ s/\</\</og;
  15.     $lin =~ s/\>/\>/og;
  16.     return $lin;
  17. }
  18.  
  19. sub out_seealso {
  20.     my $first = 1;
  21.     my $section = $_[0];
  22.     
  23.     print "<P><B>SEE ALSO:</B>\n";
  24.     if ($#see_also >= 0) {
  25.         foreach $see (@see_also) {
  26.             if (!$first) { print ", "; }
  27.             print $see;
  28.             $first = 0;
  29.         }
  30.     }
  31.     if (defined $section) {
  32.         if (!$first) { print ", "; }
  33.         print qq|<A HREF="#$sec_ref{$section}">| . out($section) . "</A>";
  34.         $first = 0;
  35.     } else {
  36.         foreach (@sections) {
  37.             if (!$first) { print ", "; }
  38.             print qq|<A HREF="#$sec_ref{$_}">| . out($_) . "</A>";
  39.             $first = 0;
  40.         }
  41.     }
  42.     if (!$first) { print "."; }
  43.     @see_also = ();
  44. }
  45.  
  46. sub out_contents {
  47.     my $section = $_[0];
  48.  
  49.     print "<UL>\n";
  50.     foreach (@{$contents{$section}}) {
  51.         print qq|<LI><A HREF="#ec.$_">| . $_ . "</A>\n";
  52.     }
  53.     print "</UL>\n";
  54. }
  55.  
  56. sub out_sections {
  57.     print "<UL>\n";
  58.     foreach (@sections) {
  59.         print qq|<LI><A HREF="#$sec_ref{$_}">| . $_ . "</A>\n";
  60.     }
  61.     print "</UL>\n";
  62. }
  63.  
  64. sub new_command {
  65.     if ($newcommand) {
  66.         if ($output) {
  67.             if ($was_section) {
  68.                 out_seealso();
  69.             } else {
  70.                 out_seealso($section);
  71.             }
  72.             print qq|<HR><H2><A NAME="ec.$command">| . out($command) . "</A></H2>\n";
  73.         } else {
  74.             push(@{$contents{$section}}, $command);
  75.         }
  76.         $was_command = 1;
  77.         $newcommand = 0;
  78.         $was_section = 0;
  79.     }
  80. }
  81.  
  82. @file = <>;
  83.  
  84. for ($output = 0; $output <= 1; $output++) {
  85.     out_sections() if $output;
  86.     @see_also = ();
  87.     $was_command = 0;
  88.     foreach (@file) {
  89.         if (m|Ex([A-Za-z]+)\,|) {
  90.             $command = $1;
  91.             $newcommand = 1;
  92.         } elsif (m|///\s*(.*)|) {
  93.             $text = $1;
  94.             new_command();
  95.             if ($output) {
  96.                 if ($text eq '') {
  97.                     print '<P>' unless $was_command || $was_section;
  98.                 } else {
  99.                     print out($text), "\n";
  100.                 }
  101.             }
  102.         } elsif (m|//\\\s*(.*)|) {
  103.             $text = $1;
  104.             new_command();
  105.             if ($output) {
  106.                 if ($text eq '') {
  107.                     print '<BR>' unless $was_command || $was_section;
  108.                 } else {
  109.                     print $text, "\n";
  110.                 }
  111.             }
  112.         } elsif (m|//\&\s*(.*)|) {
  113.             push (@see_also, $1);
  114.         } elsif (m|//<([^>]*)>\s*(.*)|) {
  115.             out_seealso($section) if $was_command && $output;
  116.             $ref = $1;
  117.             $section = $2;
  118.             if ($output) {
  119.                 print qq|<HR><H1><A NAME="$ref">| . out($section) . "</A></H1>\n";
  120.                 out_contents($section);
  121.             } else {
  122.                 $contents{$section} = [];
  123.                 $sec_ref{$section} = $ref;
  124.                 #$ref_sec{$ref} = $section;
  125.                 push(@sections, $section);
  126.             }
  127.             $newcommand = 0;
  128.             $was_section = 1;
  129.             $was_command = 0;
  130.         }
  131.     }
  132. }
  133.  
  134. out_seealso($section);
  135.  
  136. print <<EOD;
  137. </BODY>
  138. </HTML>
  139. EOD
  140.