<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 utf8;
#use open ":utf8";
use open IN =&gt; ":utf8";
use open OUT =&gt; ":encoding(Shift_JIS)";

require "filereader.pl";

$outDir = "tmp";
$fileEquip = "equipments.txt";
$fileLab = "laboratories.txt";
$fileLabOut = "$outDir/laboratories.txt";
$fileNoUse = "$outDir/notused.txt";

@rooms = ();

$date = $ARGV[0];
chomp($date);
($startYear, $startMonth) = split(/\//, $date, 2);
if(!$startYear || !$startMonth){
    exit(1);
}

$date = $ARGV[1];
chomp($date);
($endYear, $endMonth) = split(/\//, $date, 2);
if(!$endYear || !$endMonth){
    exit(1);
}

@names = ();
@date = ();
$count = $endMonth + ($endYear - $startYear) * 12 - $startMonth;
$count++;
$y = $startYear;
$m = $startMonth;
for($i = 0; $i &lt; $count; $i++){
    $names[$i] = "$y$m";
    $date[$i] = "$y/$m";
    $m++;
    if($m &gt; 12){
	$y++;
	$m = 1;
    }
}

if(system("mkdir $outDir")){
    system("rm -rf $outDir/*");
}

%labs = ();
$oldname = "";
if(open(LAB, "$fileLab")){
    flock(LAB, 1);
    @lines = &lt;LAB&gt;;
    close(LAB);
    $labCount = @lines;
    $out = "";
    for($i = 0; $i &lt; $labCount; $i++){
	($phone, $name, $short) = split(/\t/, $lines[$i], 3);
	$labs{$phone} = $name;
	if($name ne $oldname){
	    $out .= "$name\n";
	}
	$oldname = $name;
    }
    if(open(LABOUT, "&gt; $fileLabOut")){
#	$out .= "荳肴�\n";
	$out =~ s/\n/\r\n/g;
        print LABOUT $out;
        close(LABOUT);
    }
}


filereader::readRoomDirs(\@rooms);
$roomsCnt = @rooms;

if($startMonth &lt; 10){
    $startMonth = '0' . $startMonth;
}
if($endMonth &lt; 10){
    $endMonth = '0' . $endMonth;
}

if(!open(NOUSE, "&gt;$fileNoUse")){
    print "ERROR: Cannot open$fileNoUse\n";
    return 1;
}

for($i = 0; $i &lt; $roomsCnt; $i++){
    @equipDirs = ();
    @equipNames = ();
    filereader::readEquipDirs($i, \@equipDirs, \@equipNames);
    $equipsCnt = @equipDirs;
    for($k = 0; $k &lt; $equipsCnt; $k++){
	$path = "data/$rooms[$i]/$equipDirs[$k]/";
#	$equipNames[$k] =~ s/\s/_/g;
	$equipNames[$k] =~ tr/ ()&amp;\//_�茨ｼ会ｼ�ｼ�/;
	system(Encode::encode_utf8("mkdir $outDir/$equipNames[$k]"));
	$use = 0;
	for($n = 0; $n &lt; $count; $n++){
	    $filePath = $path . $names[$n] . '.txt';
	    if(open(FILE, $filePath)){
		flock(FILE, 1);
		$out = "$equipNames[$k]\n";
		$out .= "譌･莉禄t髢句ｧ区凾髢貼t邨ゆｺ�凾髢貼t菴ｿ逕ｨ譎る俣\t遐皮ｩｶ螳､蜷構t蜷榊燕\t繝代せ繝ｯ繝ｼ繝噂t莠育ｴ�凾蛻ｻ(IP繧｢繝峨Ξ繧ｹ)\t繧ｳ繝｡繝ｳ繝�\n";
		$use = 1;
		$outPath = "$outDir/$equipNames[$k]/$names[$n]" . ".txt";
		while(&lt;FILE&gt;){
		    ($day, $stime, $etime, $phone, $name, $password, $mainte, $other) = split(/\t/, $_, 8);
		    if($day &lt; 0){
			next;
		    }
		    if($mainte &gt; 0){
			next;
		    }
		    $length = ($etime - $stime) / 2;
		    $stime /= 2;
		    $etime /= 2;
		    if(exists($labs{$phone})){
			$labname = $labs{$phone};
		    }
		    else{
			$labname = "??$phone";
		    }
		    $out .= "$day\t$stime\t$etime\t$length\t$labname\t$name\t$password\t$other";
		}
		close(FILE);
		if(open(OUT, "&gt;$outPath")){
		    $out =~ s/\n/\r\n/g;
		    print OUT $out;
		    close(OUT);
		}
	    }
	}
	if(!$use){
	    system(Encode::encode_utf8("rmdir $outDir/$equipNames[$k]"));
	    $out = "$equipNames[$k]\r\n";
	    print NOUSE $out;
	}
    }
}

system("zip -r data$startYear$startMonth-$endYear$endMonth.zip $outDir/*");

close(NOUSE);
</pre></body></html>