#!/usr/bin/perl

# Création automatique des années pour http://fr.wikipedia.org
# (c) Yann Forget
# Release under GPL, see http://www.gnu.org/

use Lingua::FR::Numbers qw(number_to_fr);

@centuries=(3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);

@deceny=(0,1,2,3,4,5,6,7,8,9);

@romains=
(
    "",  # Pour indice 0
    "I",
    "II",
    "III",
    "IV",
    "V",
    "VI",
    "VII",
    "VIII",
    "IX",
    "X",
    "XI",
    "XII",
    "XIII",
    "XIV",
    "XV",
    "XVI",
    "XVII",
    "XVIII",
    "XIX",
    "XX",
    "XXI",
    "XXII",
    "XXIII",
    "XXIV",
    "XXV",
    "XXVI",
    "XXVII",
    "XXVIII",
    "XXIX",
    "XXX"
);

sub main() {
foreach $century (@centuries) {				# centuries: IIIe au XXe

	$format_century="<center>\n";
	$format_century.="[[$romains[$century-1]e siècle|$romains[$century-1]<sup>e</sup> siècle]] | \n";
	$format_century.="<b>[[$romains[$century]e siècle|$romains[$century]<sup>e</sup> siècle]]</b> | \n";
	$format_century.="[[$romains[$century+1]e siècle|$romains[$century+1]<sup>e</sup> siècle]]\n";
	$format_century.="</center>\n\n";

	#print $century," ",$format_century;
	foreach $deceny (@deceny) {

		foreach $year (@deceny) {			# Years
			$dec=$century.$deceny."0";
			$format_dec="<center>\n";
			$format_dec.="[[Années ".($dec-20)."]] | [[Années ".($dec-10)."]] | <b>[[Années ";
			$format_dec.=$dec."]]</b> | [[Années ".($dec+10)."]] | [[Années ".($dec+20)."]]\n";
			$format_dec.="</center>\n\n";

			$y=$century.$deceny.$year;
			&format_year;

			$file="$century$deceny$year.txt";
#			print $format_dec;
#			print $format_years;
			
			&print_file;
		} # End year
	} # End deceny
} # End century
} # End main

# Ier siècle
sub Ier() {
$format_century="<center>\n";
$format_century.="[[Ier siècle av. J.-C.|I<sup>er</sup> siècle av. J.-C.]] | \n";
$format_century.="<b>[[Ier siècle|I<sup>er</sup> siècle]]</b> | \n";
$format_century.="[[IIe siècle|II<sup>e</sup> siècle]]\n";
$format_century.="</center>\n\n";

foreach $deceny (@deceny) {

	foreach $year (@deceny) {			# Years
		$century="";
		$dec=$century.$deceny."0";
		$format_dec="<center>\n";
		$format_dec.="[[Années ".($dec-20)."]] | [[Années ".($dec-10)."]] | <b>[[Années ";
		$format_dec.=$dec."]]</b> | [[Années ".($dec+10)."]] | [[Années ".($dec+20)."]]\n";
		$format_dec.="</center>\n\n";

		$y=$century.$deceny.$year;
		&format_year;

		$file="$century$deceny$year.txt";

		&print_file;
	}
}
} # End Ier

# IIe siècle
sub IIe() {
$format_century="<center>\n";
$format_century.="[[Ier siècle|I<sup>er</sup> siècle]] | \n";
$format_century.="<b>[[IIe siècle|II<sup>e</sup> siècle]]</b> | \n";
$format_century.="[[IIIe siècle|III<sup>e</sup> siècle]]\n";
$format_century.="</center>\n\n";

foreach $deceny (@deceny) {

	foreach $year (@deceny) {			# Years
		$century="1";
		$dec=$century.$deceny."0";
		$format_dec;

		$y=$century.$deceny.$year;
		&format_year;

		$file="$century$deceny$year.txt";

		&print_file;
	}
}
} # End IIe

# Ier siècle av. J.-C.
sub Ier_av_JC() {
$format_century="<center>\n";
$format_century.="[[IIe siècle av. J.-C.|II<sup>e</sup> siècle av. J.-C.]] | \n";
$format_century.="<b>[[Ier siècle av. J.-C.|I<sup>er</sup> siècle av. J.-C.]]</b> | \n";
$format_century.="[[Ier siècle|I<sup>er</sup> siècle]]\n";
$format_century.="</center>\n\n";

foreach $deceny (@deceny) {

	foreach $year (@deceny) {			# Years
		$century="-";
		$dec=$century.$deceny."0";
		&format_dec;

		$y=$century.$deceny.$year;
		&format_year;

		$file="$century$deceny$year.txt";

		&print_file;
	}
}
} # End Ier av JC

sub decenie() {

foreach $century (@centuries)  {
	foreach $deceny (@deceny) {

		$format_century="<center>\n";
		$format_century.="[[$romains[$century-1]e siècle|$romains[$century-1]<sup>e</sup> siècle]] | \n";
		$format_century.="<b>[[$romains[$century]e siècle|$romains[$century]<sup>e</sup> siècle]]</b> | \n";
		$format_century.="[[$romains[$century+1]e siècle|$romains[$century+1]<sup>e</sup> siècle]]\n";
		$format_century.="</center>\n\n";

		$dec=($century-1).$deceny."0";
		$format_dec="<center>\n";
		$format_dec.="[[Années ".($dec-20)."]] | [[Années ".($dec-10)."]] | <b>Années ";
		$format_dec.=$dec."</b> | [[Années ".($dec+10)."]] | [[Années ".($dec+20)."]]\n";
		$format_dec.="</center>\n\n";

		$y=$dec;
		$format_years="<center>\n";
		$format_years.="[[".($y)."]] | [[".($y+1)."]] | [[".($y+2)."]] | [[".($y+3)."]] | [[";
		$format_years.=($y+4)."]] | [[".($y+5)."]] | [[".($y+6)."]] | [[".($y+7)."]] | [[".($y+8);
		$format_years.="]] | [[".($y+9)."]]\n";
		$format_years.="</center>\n\n";

		$file="an-".$dec.".txt";

		&print_file;
		}
	}
} # End decenie

sub print_file() {
	print $file,"\n";
	open YEAR, ">$file" or die "Can't create $file: $!";

	print YEAR $format_century;
	print YEAR $format_dec;
	print YEAR $format_years;

	print YEAR "----\n";
	print YEAR "<i>Cette page concerne l'année ".$y." du [[calendrier grégorien]]. ";
	print YEAR "Pour le nombre, voyez [[".number_to_fr($y)."]].</i>\n\n";

	print YEAR "=== Événements ===\n\n";
	print YEAR "*\n\n";
	print YEAR "=== Naissances ===\n\n";
	print YEAR "*\n\n";
	print YEAR "=== Décès ===\n\n";
	print YEAR "*\n";
			
	close YEAR;
}

sub format_year() {
	$format_years="<center>\n";
	$format_years.="[[".($y-5)."]] | [[".($y-4)."]] | [[".($y-3)."]] | [[".($y-2)."]] | [[";
	$format_years.=($y-1)."]] | <b>".$y."</b> | [[".($y+1)."]] | [[".($y+2)."]] | [[".($y+3);
	$format_years.="]] | [[".($y+4)."]] | [[".($y+5)."]]\n";
	$format_years.="</center>\n\n";
}

sub format_dec() {
	$format_dec="<center>\n";
	$format_dec.="[[Années ".($dec-20)."]] | [[Années ".($dec-10)."]] | <b>[[Années ";
	$format_dec.=$dec."]]</b> | [[Années ".($dec+10)."]] | [[Années ".($dec+20)."]]\n";
	$format_dec.="</center>\n\n";
}

#&decenie;
#&Ier_av_JC;
#&Ier;
#&IIe;
&main;

print "OK\n";

