#!/usr/bin/perl -w

# This script checks out corresponding originals from translations.

# based on doc-check 
#
# SYNOPSIS:
#             ./doc-base [-d] [-v] [-V] [lang [subdoc ...]]
#	
#
#	(uses $lang set to "fr" if lang is not given on commandline)
#	(checks all files if no subdoc is specified)
#	(-d option enables to check diff)
#	Make sure to update top few lines when proofreading


use Getopt::Std;
$module = "qref";
# You may set this to your default language code
push @sublangs, ( "de", "fr", "it", "es", "pl", "pt-br", "zh-tw", "zh-cn" );

sub get_old_english
{
	my ($lang, $fname) = (@_);
	my ($xxrev) = getrev($lang, $fname);
	my $s = "cvs checkout -r $xxrev -d en-$lang $module/en/$fname";
	# export does not work, it requires symbolic tag ???? 
	warn "running $s:\n" ;
	system($s);
}

sub getrev
{
	my ($lang, $fn) = (@_);
	my ($xxrev) = ("1.1.1.1"); # Not available, then assume as initial
	my ($langfn) = $lang . "/" . $fn; 

	warn "checking $langfn:\n";
	open FILE, $langfn or die "$langfn: $!";
	while (<FILE>) {
		if (/<!--\s*CVS revision of original english document\s*\"([\d\.]+)\"\s*-->/) {
			$xxrev = $1;
			last;
		}
	}
	return ($xxrev);
}
@subdocs = (); # Intialize
push @subdocs, @ARGV; # take options
if ($#subdocs < 0) {
	# default is for all
	push @subdocs, (
"append",
"copyleft",
"cvs",
"debian",
"edit",
"gateway",
"gnupg",
"install",
"kernel",
"preface",
"program",
"support",
"system",
"tips",
"titletoc",
"tune",
"tutorial",
"woody"
	);
}

foreach $lang (@sublangs) {
foreach $doc (@subdocs) {
	sleep 5;
	my $fname = "$doc" . ".sgml";
	get_old_english($lang, $fname);
}

}
