cvs commit: www/test cl2html.pl

jeroen at linuxfromscratch.org jeroen at linuxfromscratch.org
Fri Aug 22 12:15:35 PDT 2003


jeroen      03/08/22 13:15:35

  Added:       test     cl2html.pl
  Log:
  Add the cl2html.pl script to CVS take 2
  
  Revision  Changes    Path
  1.1                  www/test/cl2html.pl
  
  Index: cl2html.pl
  ===================================================================
  #!/usr/bin/perl
  # cl2html.pl - Convert the XML output of cvs2cl.pl to (X)HTML
  
  # Copyright (C) 2003 Anderson Lizardo
  # 
  # This program is free software; you can redistribute it and/or modify
  # it under the terms of the GNU General Public License as published by
  # the Free Software Foundation; either version 2 of the License, or
  # (at your option) any later version.
  #
  # This program is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  # GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public License
  # along with this program; if not, write to the Free Software
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  
  use strict;
  use warnings;
  use XML::Parser;
  use Getopt::Long;
  use Pod::Usage;
  use POSIX qw(strftime);
  
  my $my_version = "0.1";
  
  # Convert ISO 8601 date (yyyy-mm-dd) to the specified format
  sub isodate2any {
      my ($date, $format) = @_;
      if ($date =~ /(\d{4})-(\d{2})-(\d{2})/) {
          return strftime($format, 0, 0, 0, $3, $2 - 1, $1 - 1900);
      }
      else {
          return undef;
      }
  }
  
  my $help = 0;
  my $man = 0;
  my $version = 0;
  my $infile = "";
  my $with_filename = 0;
  
  GetOptions(
      "help" => \$help,
      "man" => \$man,
      "version" => \$version,
      "infile=s" => \$infile,
      "with-filename", \$with_filename,
  ) or pod2usage(1);
  
  pod2usage(1) if $help;
  pod2usage(-exitstatus => 0, -verbose => 2) if $man;
  
  if ($version) {
      print "cl2html.pl $my_version\n" .
      "Copyright (C) 2003 Anderson Lizardo\n";
      exit 0;
  }
  
  my $date = "";
  my $buffer = "";
  my $author = "";
  my @messages = ();
  my $files = "";
  
  my $parser = new XML::Parser(
      Handlers => {
          Start => \&handle_StartTag,
          End => \&handle_EndTag,
          Char => \&handle_Text,
      },
  );
  
  if ($infile) {
      eval { $parser->parsefile($infile) } or pod2usage("$0: $@");
  }
  else {
      $parser->parse(\*STDIN);
  }
  
  sub handle_StartTag {
      $buffer = "";
  }
  
  sub handle_EndTag {
      my (undef, $tag) = @_;
  
      if ($tag eq "date" and $date ne $buffer) {
          if (@messages and $author and $date) {
              print "<ul>\n\t<li>\n\t\t<h4>" . $author . " - " .
              isodate2any($date, '%Y/%m/%d') . "</h4>\n";
              print "\t\t<ul>\n";
              foreach (@messages) {
                  print "\t\t\t<li>" . $_ . "</li>\n";
              }
              print "\t\t</ul>\n";
              print "\t</li>\n</ul>\n\n";
              @messages = ();
              $date = "";
              $author = "";
          }
          $date = $buffer;
      }
      elsif ($tag eq "author" and $author ne $buffer) {
          $author = $buffer;
      }
      elsif ($tag eq "msg") {
          if ($with_filename) {
              $files =~ s/, $/: /;
              $buffer = $files . $buffer;
              $files = "";
          }
          push @messages, $buffer;
      }
      elsif ($tag eq "name" and $with_filename) {
          $files .= $buffer . ", ";
      }
  }
  
  sub handle_Text {
      my ($expat, $text) = @_;
      $text =~ s/\&/\&/g;
      $text =~ s/</\</g;
      $text =~ s/>/\>/g;
      #$text =~ s/\"/\"/g;
      #$text =~ s/\'/\'/g;
      $buffer .= $text;
  }
  
  __END__
  
  =head1 NAME
  
  cl2html.pl - convert the XML output of cvs2cl.pl to (X)HTML
  
  =head1 SYNOPSIS
  
  cl2html.pl  [--help|--man]  [--with-filename]  [--infile xml_file]
  
      Options:
          --infile          Parse XML from a file
          --with-filename   Prepend filenames to commit messages
          --help            Show brief help message
          --man             Full documentation
          --version         Show program version
  
  =head1 DESCRIPTION
  
  B<cl2html.pl> converts the XML outputted by cvs2cl.pl's C<--xml> option to
  HTML or XHTML code.
  
  =head1 OPTIONS
  
  =over
  
  =item B<--infile xml_file>
  
  Specify which XML file to parse. This file must be the output of cvs2cl.pl's
  C<--xml> option. By default, B<cl2html.pl> reads XML code from standard input.
  
  =item B<--with-filename>
  
  This option prepends filenames to each commit message.
  
  =item B<--help>
  
  Print a brief help message and exits.
  
  =item B<--man>
  
  Print the manual page and exits.
  
  =item B<--version>
  
  Show program version and exits.
  
  =back
  
  =head1 AUTHOR
  
  Copyright (C) 2003 Anderson Lizardo <andersonlizardo at yahoo.com.br>
  
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.
  
  =cut
  
  
  
  



More information about the website mailing list