FAQ-html.pl
上传用户:seven77cht
上传日期:2007-01-04
资源大小:486k
文件大小:2k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. #!/usr/bin/perl
  2. #-*-perl-*-
  3. #
  4. # Copyright Andrew M. Bishop 1996.97,98.
  5. #
  6. # Usage: FAQ-html.pl < FAQ > FAQ.html
  7. #
  8. $_=<STDIN>;
  9. s/^ *//;
  10. s/ *n//;
  11. $first=$_;
  12. print "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">n";
  13. print "<HTML>n";
  14. print "n";
  15. print "<HEAD>n";
  16. print "<TITLE>$first</TITLE>n";
  17. print "</HEAD>n";
  18. print "n";
  19. print "<BODY>n";
  20. print "n";
  21. print "<h1>$first</h1>n";
  22. $questions=0;
  23. $answers=0;
  24. $pre=0;
  25. $blank=1;
  26. while(<STDIN>)
  27.   {
  28.    chop;
  29.    s/&/&amp;/g;
  30.    s/</&lt;/g;
  31.    s/>/&gt;/g;
  32.    s/"/&quot;/g;
  33.    next if(m/^ *=+ *$/);
  34.    next if ($_ eq "--------------------");
  35.    $pre++,$blank=0,next if($pre==1 && $_ eq "");
  36.    $blank=1,next        if($pre!=1 && $_ eq "");
  37.    $pre++ if($pre);
  38.    if ($_ eq "--------------------------------------------------------------------------------")
  39.        {
  40.         $pre=0,print "</pre>n" if($pre);
  41.         print "<hr>n";
  42.         $answers++              if( $answers);
  43.         $questions=0,$answers=1 if( $questions);
  44.         $questions=1            if(!$questions && !$answers);
  45.        }
  46.    elsif (m/^(Section [0-9]+)/)
  47.        {
  48.         $section = $1;
  49.         $section =~ tr/ /-/;
  50.         $pre=0,print "</pre>n" if($pre);
  51.         print "<p><b><a href="#$section">$_</a></b>n" if($questions);
  52.         print "<h2><a name="$section">$_</a></h2>n"       if($answers);
  53.        }
  54.    elsif(m/^(Q [0-9]+.[0-9]+[a-z]*)/)
  55.        {
  56.         $question = $1;
  57.         $question =~ tr/ /-/;
  58.         $blank=0,$pre=0,print "</pre>n" if($pre);
  59.         print "<p><a href="#$question">$_</a>n"  if($questions);
  60.         print "<h3><a name="$question">$_</a></h3>n" if($answers);
  61.         $pre=1,print "<pre>n" if($answers);
  62.        }
  63.    elsif(m/((See Q [0-9]+.[0-9]+[a-z]*))/)
  64.        {
  65.         $question = substr($1,4);
  66.         $question =~ tr/ /-/;
  67.         $href=$1;
  68.         s%$1%<a href="#$question">$href</a>% if($answers);
  69.         print "$_n";
  70.        }
  71.    elsif(m%(^|[^'"])(http://[A-Za-z0-9-_.]+/[/A-Za-z0-9-_.~]*)%)
  72.        {
  73.         $href=$2;
  74.         s%$2%<a href="$href">$href</a>%;
  75.         print "$_n";
  76.        }
  77.    else
  78.        {
  79.         $blank=0,print "n" if($blank);
  80.         print "$_n";
  81.        }
  82.   }
  83. print "</BODY>n";
  84. print "n";
  85. print "</HTML>n";