#!c:\perl\bin\perl
# History :Version       :DATE      :Coder       : Patch No
#         :50-04-28/00-01:2005.09.09:H.Yasukawa  :USE22225809 PORT80 Block

sub chgenv(){
my $envfile, $envfile_bak ;
my @tmp, @buf, $i ;

my($itemno, $env_http) = @_;

$envfile="csv/env.csv";
$envfile_bak="csv/env.bak";
unless(open(ENV,"< $envfile")){
    sleep 1;
    unless(open(ENV,"< $envfile")){
        sleep 1;
        unless(open(ENV,"< $envfile")){
            unless(open(ENV,"< $envfile_bak")){
                {`echo env.csv File Open(for READ) Error. No Change. >log/httpdconf.log`; }
                exit;
            }
        }
    }
}

while(<ENV>){
    chop;
    @tmp=split(/,/);
    foreach $i (0 .. $#tmp){
        $buf[$i]=$tmp[$i];
    }
    last;
}

$buf[$itemno] = $env_http ;

close(ENV);

unless(open(ENV,"> $envfile")){
    sleep 1;
    unless(open(ENV,"> $envfile")){
        sleep 1;
        unless(open(ENV,"> $envfile")){
            {`echo env.csv File Open(for WRITE) Error. No Change. >log/httpdconf.log`; }
       }
    }
}

# $#tmp=>$#buf
foreach $i (0 .. $#buf){
    if($i==$#buf){
        print ENV "$buf[$i]\n";
    }else{
        print ENV "$buf[$i],";
    }
}

close(ENV);

## Backup File for SVP
require "sjs2000.cgi";
&sjs2000( );

##  Backup File for CGI
use File::Copy;
unless(copy("$envfile","$envfile_bak")){
    {`echo env.csv File Backup Error. >log/httpdconf.log`; }
}

}1;
