#! /usr/bin/perl

use Kconv;

$tapeid = '';
$subid = 1;

while (<>) {
    chomp;
    next if /^\(EMPTY\)$/;
    $_ = kconv($_, _EUC);
    if (/^\*(.*)$/) {
	next if ($1 eq 'end');
	$tapeid = sprintf("%02d", $1);
	$subid = 1;
	$kind='8';
	next;
    } elsif (/^\+(.*)$/) {
	next if ($1 eq 'end');
	$tapeid = sprintf("%02d", $1);
	$subid = 1;
	$kind='V';
	next;
    } elsif (/^\s*$/) {
	next;
    }
    ($title, $num, $subtitle, $date, $comment) = split /,/;
    $date = '0000/00/00' if $date eq '';
    $num = '-' if $num eq '';
    print join(",", $title, $num, $subtitle, $date),
    ",", $kind, "-", $tapeid, "-", $subid, ",${comment}\n";
    $subid++;
}
