changelog2mediawiki

ChangeLog での日誌がたまったし、Wikiへ転載できるように、変換スクリプトを書いた。
ChangeLogにはキーワードを付けてあるので、それを指定して抜き出す。

Wikiで日誌を付けるのは少々面倒なので、今後はChangeLogメインになるが、移行期間ということで。

#! /usr/bin/perl -w
use strict;

my @keys = qw|segmentation|;
my %keywords;
@keywords{ @keys } = map 1, @keys;
my $regexp_section_head = '^([\d-]+)';
my $output_section_head = sub { "<strike> $_[0] </strike>" };
my $regexp_subsect_head = '^\t\*(.+):';
my $output_subsect_head = sub { "=<strike> $_[0] </strike>=" };
my $regexp_keyword = '('. join('|',@keys) .')';
my $regexp_begin_src = '\[src\]';
my $regexp_end_src = '\[/src\]';

my $showing = 0;
my $insrc = 0;
while ( $_ = <> ) {
  if ( m/$regexp_section_head/ ) {
    print $output_subsect_head->($1)."\n";
    $showing = 0;
  } elsif ( m/$regexp_subsect_head/ ) {
    my $subsect = $1;
    if ( $subsect =~ m/$regexp_keyword/ ) {
      print $output_subsect_head->($subsect)."\n";
      $showing = 1;
    } else {
      $showing = 0;
    }
  } elsif ( m/^(.+)$/) {
    my $text = $1;
    if ( $insrc ) {
      if ( $text =~ m/$regexp_end_src/ ) {
        $text = "$`\n$'";
        $insrc = 0;
      }
      print " $text\n";
    } elsif ($text =~ m/$regexp_begin_src/) {
      $insrc = 1;
    } elsif ( $showing ) {
      $text =~ s/^\s+-/\*/;
      print "$text\n";
    }
  }
}