<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

use strict;
use warnings;
use File::Path;
use File::Spec;
use Fcntl;
use File::Find;
use File::Basename;


#=============================================================================================
# メイン
#=============================================================================================

my $top_dir = "lecture_new";
my ($base, $dir, $ext);
my $file;
my $num=1;

our $style_sheet_apath = q(/home/yamamoto/www_server_yamamoto/www/stylesheet.css);
our $end_process_apath = q(/home/yamamoto/www_server_yamamoto/www/end_process.php);
our $home_page_apath   = q(/home/yamamoto/www_server_yamamoto/www/index.html);
our $self_intro_apath  = q(/home/yamamoto/www_server_yamamoto/www/home/yamamoto_masashi/index.php);

our $style_sheet_rpath;
our $end_process_rpath;
our $home_page_rpath;
our $self_intro_rpath;

our ($HTML_old,       $HTML_new);
our ($HEAD_old,       $HEAD_new);
our ($STYLESHEET_old, $STYLESHEET_new);
our ($mail_old,       $mail_new);
our ($home_page_old,  $home_page_new);
our ($author_old,     $author_new);
our ($BODY_old,       $BODY_new);


&amp;mk_old_line;
find(\&amp;file_process, $top_dir);


#=============================================================================================
# 修正すべき行
#=============================================================================================
sub mk_old_line{
    $HTML_old       = '&lt;HTML&gt;';
    $HEAD_old       = '&lt;HEAD&gt;';
    $STYLESHEET_old = 'http:\/\/www\.akita-nct\.ac\.jp\/~?yamamoto\/stylesheet\.css';
    $mail_old       = 'yamamoto@akita-nct\.ac\.jp';
    $home_page_old  = 'http:\/\/www\.akita-nct\.ac\.jp\/~?yamamoto\/';
    $author_old     = 'http:\/\/akita-nct\.jp\/~?yamamoto\/home\/member\/yamamoto_masashi\/index.php';
    $BODY_old       = '&lt;\/BODY&gt;';
}

#=============================================================================================
# 修正後
#=============================================================================================
sub mk_new_line{

    $HTML_new = '&lt;HTML lang="ja"&gt;';
    $HEAD_new = '
&lt;HEAD&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=euc-jp"&gt;
';
    $STYLESHEET_new = $style_sheet_rpath;
    $mail_new = 'ymm10m34@khaki.plala.or.jp';
    $home_page_new = $home_page_rpath;
    $author_new = $self_intro_rpath;
    $BODY_new       = '
&lt;?PHP
 $show_counter    = FALSE;
 $show_update     = FALSE;
 $isuse_side_main = FALSE;
 include "'.$end_process_rpath.'";
?&gt;

&lt;/BODY&gt; 
';

}

#=============================================================================================
# ファイル毎の処理
#=============================================================================================
sub file_process{
    my $in_google_analystics = 0;
    my $in_javascript = 0;
    my $temp_file = "changed131130.html";
    my $cor_file;
    my $command;

    $file = $File::Find::name;                           # ファイル名の取得
    ($base, $dir, $ext) = fileparse($file, qr/\..+$/);   #　ファイル名, ディレクトリー, 拡張子

    $cor_file = $base.$ext;

    if($ext eq ".html" || $ext eq ".HTML"){
	print $num,"\t", $file, "\n";
	$num++;

	&amp;get_rel_path($dir);
	&amp;mk_new_line;

	open(IN, $cor_file) or die "IN file can not be opened.";
	open(OUT,"&gt;$temp_file") or die "OUT file can not be opened.";

	while(&lt;IN&gt;){

	    #  --- goole-analytics の内外のチェック -----------
	    if(/&lt;script src="http:\/\/www\.google-analytics\.com\/urchin\.js"/){
		$in_google_analystics = 1;
		next;
	    }

	    if($in_google_analystics &amp;&amp; /&lt;\/script&gt;/){
		$in_google_analystics = 0;
		next;
	    }


	    #  --- javascript の内外のチェック -----------
	    if(/&lt;script type="text\/javascript"&gt;/){
		$in_javascript = 1;
		next;
	    }

	    if($in_javascript &amp;&amp; /&lt;\/script&gt;/){
		$in_javascript = 0;
		next;
	    }


	    if($in_google_analystics || $in_javascript){
		next;
	    }

	    s/$HTML_old/$HTML_new/i;
	    s/$HEAD_old/$HEAD_new/i;
	    s/$STYLESHEET_old/$STYLESHEET_new/i;
	    s/$mail_old/$mail_new/i;
	    s/$home_page_old/$home_page_new/i;
	    s/$author_old/$author_new/i;
	    s/$BODY_old/$BODY_new/i;

	    print OUT;

	}

	close(IN);
	close(OUT);

	unlink($cor_file);
	rename("$temp_file",$cor_file);
	$command = sprintf("chmod 644 %s", $cor_file);
	system($command);

    }
}


#=============================================================================================
# 相対パスの取得
#=============================================================================================
sub get_rel_path{

    $style_sheet_rpath = File::Spec-&gt;abs2rel($style_sheet_apath);
    $end_process_rpath = File::Spec-&gt;abs2rel($end_process_apath);
    $home_page_rpath   = File::Spec-&gt;abs2rel($home_page_apath);
    $self_intro_rpath  = File::Spec-&gt;abs2rel($self_intro_apath);

}
</pre></body></html>