#!/usr/local/bin/perl
if($#ARGV != 1) { die "$0: 2 args required"; }
($op,$st0) = @ARGV;
$ti0 = &stamp_to_time($st0);
@fv = split(/\n/,`ls *.ram`);
foreach $f (@fv) {
	$url = `cat $f`;
	($head,$st) = ($url =~ /^(.+)\$(.+)$/);
	$ti = &stamp_to_time($st);
	if($op eq 'sub') { $ti -= $ti0; }
	elsif($op eq 'add') { $ti += $ti0; }
	else { die "$0: invalid operator $op"; }
	$ts = join(":", &time_to_stamp($ti));
	$url = "$head\$$ts";
	open(FILE,">$f") || die "$0: cannot open $f";
	print FILE "$url\n";
	close(FILE);
}

sub stamp_to_time {
local($stamp) = @_;
local(@v);
@v = split(/:/,$stamp);
$time = $v[2] + 60*$v[1] + 360*$v[0];
return $time;
}

sub time_to_stamp {
local($time) = @_;
local(@v,$i);

$v[2] = $time % 60; $time = int($time/60);
$v[1] = $time % 60; $time = int($time/60);
$v[0] = $time;
for($i = 0; $i<=2; $i++) {
	if($v[$i] == 0) { $v[$i] = "00"; }
	elsif($v[$i] < 10) { $v[$i] = '0'.$v[$i]; }
}
return @v;
}

