#!/usr/bin/perl -w
# $Id$
# This perl script is maintained by Rdiger Beck
# It is Free Software (License GPLv3)
# If you find errors, contact the author
# jeffbeck@web.de  or  jeffbeck@gmx.de



# Bibliotheken
use strict;

print "sopho-man2html: Creating html man pages\n";

my @mandirs=("sophomorix-base","sophomorix-vampire","sophomorix-developer");
my $file="";
my $mandir="";
my $out_path="";
my $lang="";

# Convert German manpages
$lang="de";
&create_manpages();

# Convert English manpages
$lang="en";
&create_manpages();

# Convert other manpages
#$lang="en";
#&create_manpages();


sub create_manpages {
    foreach my $name (@mandirs) {
        my $dirname=$name."/man/"."$lang";
        if (-d $dirname){
            opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
            print "##### Procesing manpages in $dirname ... \n";
            while (defined($file = readdir(DIR))) {
                if ($file eq "." or $file eq ".."){
                    next;
                }
                print "$file\n";
                if ($lang eq "en"){
                    # no language string
                    if ($file=~/^sophomorix-[-a-z]*\.[0-9]?$/){
                    my ($name,$section) = split(/\./, $file);
                    $mandir="man"."$section";
                    $out_path="sophomorix-doc/html/man/$lang/$mandir";
                    system("install -d $out_path");
                    my $html_file = $name.".".$section.".html";
                    my $man_file=$dirname."/".$file;
                    print "   Converting   $man_file\n     to $out_path/$html_file\n";
                    system("man2html -r $man_file > $out_path/$html_file");
                  }
                } else {
                  if ($file eq "." or $file eq ".."){
                       next;
                  }
                  if ($file=~/^sophomorix-[-a-z]*\.$lang\.[0-9]?$/){
                    my ($name,$language,$section) = split(/\./, $file);
                    $mandir="man"."$section";
                    $out_path="sophomorix-doc/html/man/$lang/$mandir";
                    system("install -d $out_path");
                    my $html_file = $name.".".$section.".html";
                    my $man_file=$dirname."/".$file;
                    print "   Converting   $man_file\n     to $out_path/$html_file\n";
                    system("man2html -r $man_file > $out_path/$html_file");
                  }
                }
            }
            closedir(DIR);
        }
    }
}


