#!/usr/local/bin/perl

# himekuri.pl, Himekuri Displayer (CGI)
# Created by M. Shibukawa
# Initial 04/08/96
# 04/09/96 Modified for www.ibm.park.org
# 04/10/96 Japan Time adjustment
# 04/11/96 Compensation for the wrong system clock ($monc)
# 04/26/96 Compensation deleted (but daylight saving time GMT+8) V3.2
# 06/03/96 Tuned for the Hayashi servers

# This file has been prepared for the "IBM Small Planet Pavilion Japan" project.
# This file is invoked in the web page "Japan/IBM/planet/home.html".

# This script was adopted from "counter.pl"
# The credit of "counter.pl" was as follow.

# Counter Script		Version 1.1.1
# Created by Matt Wright	mattw@misha.net
# Created on: 10/27/95		Last Modified on: 1/11/96
# Scripts Archive:		http://www.worldwidemart.com/scripts/
# Consult the file README for more information and Installation Instructions.

#########################################################
# Path Assumption

# /cgi-bin/Japan/IBM/himekuri/himekuri.pl
# /cgi-bin/Japan/IBM/himekuri/gif_dir/d01.gif, d02.gif, ... m01.gif, m02.gif, ...
# /cgi-bin/Japan/IBM/himekuri/fly
# /temp/IBM/himekuri/fly_temp.txt

#########################################################
# Define Variables

## Files and Directories

$gifMBase = "m";
$gifDBase = "d";
$gifDir = "gif_dir";
$flyProg = "fly";
$flyTemp = "/tmp/IBM/himekuri/fly_temp.txt";

## Images

$imgW = 69;
$imgH = 69;

$imgMX = "0";
$imgMY = "0";

$imgDX = "0";
$imgDY = "20";


#########################################################

# Get the Date
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time+60*60*8);
$mon++;

if ($sec < 10)  { $sec = "0$sec";   }
if ($min < 10)  { $min = "0$min";   }
if ($hour < 10) { $hour = "0$hour"; }
if ($mday < 10) { $mday = "0$mday"; }
if ($mon < 10)  { $monc = "0$mon";  }
$date = "$hour\:$min\:$sec $mon/$mday/$year";

# Set the paths
$gifM="$gifDir/$gifMBase$monc.gif";
$gifD="$gifDir/$gifDBase$mday.gif";

# Open the In-File
open(FLY,">$flyTemp") || die "Can't Open In File For FLY Commands: $!\n";

print FLY "new\n";
print FLY "size $imgW,$imgH\n";
print FLY "copy $imgMX,$imgMY,-1,-1,-1,-1,$gifM\n";
print FLY "copy $imgDX,$imgDY,-1,-1,-1,-1,$gifD\n";
print FLY "interlace\n";

# Close FLY
close(FLY);

$output = `$flyProg -i $flyTemp`;
print "Content-type: image/gif\n\n";
print "$output";

