#!/usr/bin/perl # # Copyright (C) 2001 USUDA Hisashi # # $Id: combi.pl,v 1.5 2002/01/17 18:03:42 usuda Exp $ # # Redistribution for non-commercial purpose, with or without # modification, is granted as long as all copyright notices are # retained. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' # AND ANY EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED. # $NKF = "/usr/bin/nkf"; $DATAFILE = "html.dat"; sub modtime { my($fname) = @_; my(@res, $ret); @res = stat($fname); $ret = localtime($res[9]); $ret; } sub maketranstable { my(%table); my $line = 1; local *DAT; $table{"hoteagle"} = "http://www.hoteagle.org/"; # uum... if(! open(DAT, $DATAFILE)) { print STDERR "$DATAFILE: cannot open.\n"; return %table; } for(; ; $line++) { chop; next if /^#/; if(/^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+\"([^\"]*)\"\s+(.*)$/) { next if $2 ne "index.html"; if($1 eq "root") { $table{"$1"} = "/index.html"; } else { $table{"$1"} = "/$1/index.html"; } } } close DAT; %table; } sub getindex { my($dir, $prefix) = @_; my($total, $line) = ("\n"; } sub translate { my($templ, $conts, $title, $jtitle, $url) = @_; my %trans_table = &maketranstable; my $line = 1; local *TEMP; if(! open(TEMP, $templ)) { print STDERR "$templ: cannot open.\n"; return; } for($line=1; ; $line++) { chop; while(/^(.*)<\%\%([^\%]+)\%\%>(.*)$/) { my($front, $tag, $tail) = ($1, $2, $3); # print "#DBG:$line $front / $tag / $tail\n"; if($tag eq "TITLE") { $_ = $front . $title . $tail; } elsif($tag eq "JTITLE") { $_ = $front . $jtitle . $tail; } elsif($tag eq "TIME") { $_ = $front . &modtime($conts) . $tail; } elsif($tag eq "CONTENTS") { print $front . "\n\n"; # `./combi.pl $conts \'\' \'\' \'\' $url`; &translate($conts, "", $title, $jtitle, $url); $_ = "\n\n" . $tail; } elsif($tag =~ /^INDEX:([^:]*):([^:]*)$/) { $_ = $front . &getindex($1, $2) . $tail; } elsif($tag =~ /^LINK:(.*)$/) { $tag = $1; foreach $k (keys %trans_table) { if($tag =~ /^$k:(.+)$/) { # print STDERR "$trans_table{$k} : $url\n"; if($trans_table{$k} eq $url) { $_ = $front . $1 . $tail; } else { $_ = $front . "$1" . $tail; } } } } else { print STDERR "Warning: unknown tag ($tag) in line $line.\n"; $_ = $front . "" . $tail; } } print "$_\n"; } } ####### if($#ARGV != 4) { print STDERR "Usage: combi.pl template contents title jtitle url.\n"; exit 999; } $templ = shift; $conts = shift; $title = shift; $jtitle = shift; $url = shift; $jtitle = `echo $jtitle|$NKF -s 2>&1`; chop $jtitle; &translate($templ, $conts, $title, $jtitle, $url);