#!/bin/sh
# vi: ts=4 sw=4
set -e
#require fsub gawk pee sponge
PATH="$PATH:scripts"
rm -rf out/*
mkdir -p out
cp -r src/* out
[ -d fonts ] && cp -r fonts out
compile_for_lang() {
sd=src/$1
od=out/$1
case $lang in
en) hlang=en-US ;;
pt) hlang=pt-BR ;;
*) hlang=$1 ;;
esac
xfsub '' src/language-selector.html \
$od/nav-bar.html
sed -i "\\..d" $od/nav-bar.html
mkdir $od/changelog
changelog-dates.sed out/changelog.html >$od/changelog/index.html
find $od -name '*.html' \
| pee cat "xargs -- sed -i '
s|href=/XX|href=/$1|
s|||
'" \
| while read file; do
xfsub '' $od/nav-bar.html $file
xfsub '' $od/euro/coin-nav.html $file
xfsub '' $od/euro/note-nav.html $file
xfsub '' $od/euro/coin-denom-nav.html $file
xfsub '' $od/footer.html $file
xfsub '' $od/table-key.html $file
done
for file in `find $od -name 'index.html'`; do
base=${file#out}
base=${base%/index.html}
sed -Ei "
//,\\| |s| ([^<]*) |
\1
|
" $file
done
sed -Ei '
//,//d
//d
' $od/euro/notes.template.html $od/euro/tnotes.template.html
sed -Ei '
//,//d
//d
' $od/euro/coins.template.html $od/euro/coins-denom.template.html
nod=$od/euro/tn
mkdir -p $nod
cp $od/euro/tnotes.template.html $nod/index.html
sed -Ei '
//,\| |s|([^<]*) |\1
|
' $nod/index.html
gawk -v lang=$1 '
@include "scripts/getcls.awk"
function fmt(n)
{
return lang ~ /(en|ga|mt|nl)/ ? "€" n : n " €"
}
BEGIN {
FS = "\t"
}
$1 == "TN" {
i++
col[i][0] = $2
col[i][1] = $3
col[i][2] = $4
}
END {
for (i = 1; i <= length(col); i++) {
printf \
"%s "\
"%s \n",
fmt(col[i][0]), getcls(col[i][2]), col[i][1]
}
print "MARKER LOL"
}
' data/notes \
| last-of-design.sed \
| xfsub '' - $nod/index.html
for CC in `grep -Eo '^[A-Z]{2}' data/coins | uniq`; do
cc=`echo $CC | tr A-Z a-z`
nod=$od/euro/$cc
mkdir -p $nod
cp $od/euro/coins.template.html $nod/index.html
sed -i "
//,\\| |s|$CC |$CC
|
" $nod/index.html
grep -m1 "^$CC" data/country-info.$1 \
| cut -f2 \
| xfsub '' - $nod/index.html
sed -Ei "
//d
//,//d
//d
//,//d
" $nod/index.html
gawk -v CC=$CC '
@include "scripts/getcls.awk"
$1 == CC && /.. start/ {
sub(/.. start/, "")
printf "%s \n", $0
next
}
$1 == CC {
y = $10
if ($11 != "")
y_ = $11
printf ""
for (i = 2; i <= 9; i++) {
# Greece 2002 needs special handling
if (CC == "GR" && $10 == 2002 && $11 == "MM") {
if (i <= 5)
y_ = "F"
else if (i <= 7)
y_ = "E"
else
y_ = "S"
}
if ($11 != "") {
printf "%s %s ",
getcls($i), y, y_
} else
printf "%s ", getcls($i), y
}
print ""
}
END { print "MARKER LOL" }
' data/coins \
| last-of-design.sed \
| sed -E 's|()[^<]*([^<]* )?( )|\1\ \3|g' \
| xfsub '' - $nod/index.html
gawk -v CC=$CC '
@include "scripts/getcls.awk"
$1 == CC {
split($0, a, "\t")
$0 = a[1]
n = 2
y = $2
if (getcls($3) == "error") {
n = 3
printf "%s %s ", y, $3
} else
printf "%s ", y
for (i = 1; i <= NF - n; i++) {
printf "%s ",
getcls($(i + n)), a[i + 1]
}
print " "
}
END { print "MARKER LOL" }
' data/ccs \
| colspan.sed \
| grep -Fv 'MARKER LOL' \
| xfsub '' - $nod/index.html
done
for denom in `grep -Eo '^[0-9]+' data/notes | uniq`; do
nod=$od/euro/${denom}e
mkdir -p $nod
cp $od/euro/notes.template.html $nod/index.html
sed -Ei "
//,\\| |s|([^<]*) |\\1
|
" $nod/index.html
sed -i "s//$denom/" $nod/index.html
sed -Ei "
//d
//,//d
//d
//,//d
" $nod/index.html
gawk -v denom=$denom -v lang=$1 '
@include "scripts/bilingual_sort.awk"
@include "scripts/getcls.awk"
BEGIN { FS = "\t" }
FILENAME == "data/country-info." lang { cc2name[$1] = $3 }
FILENAME == "data/note-info" && length == 0 { section++; next }
FILENAME == "data/note-info" && section == 0 { cc2c[$1] = $2 }
FILENAME == "data/note-info" && section == 1 { ab2l[$1] = $2 }
FILENAME == "data/notes" && $1 == denom && $2 == "2002" {
i++
col[i][0] = $3
col[i][1] = $4
}
END {
locale = lang == "pt" \
? "pt_BR.UTF-8" \
: lang "_" toupper(lang) ".UTF-8"
CMD = "LC_ALL=" locale " ./bilingual_sort"
asort(col, col, "bilingual_sort")
close(CMD)
for (i = 1; i <= 3; i++) {
if (i == 3 && denom == 5)
break
if (i == 1)
sig = "Wim Duisenberg"
else if (i == 2)
sig = "Jean-Claude Trichet"
else if (i == 3)
sig = "Mario Draghi"
print ""sig" "
c = 1
for (j = 1; j <= length(col); j++) {
split(col[j][1], s, " ")
if (s[i] == "/")
continue
if ((c - 1) % 4 == 0)
printf ""
printf "", getcls(s[i])
printf "%s (%s)", cc2name[col[j][0]], cc2c[col[j][0]]
printf " "
if (c % 4 == 0)
print ""
c++
}
if ((c - 2) % 4 != 3)
print ""
}
print "MARKER LOL"
}
' data/country-info.$1 data/note-info data/notes \
| colspan.sed \
| last-of-design.sed \
| xfsub '' - $nod/index.html
[ $denom -eq 500 ] && continue
gawk -v denom=$denom -v lang=$1 '
@include "scripts/bilingual_sort.awk"
@include "scripts/getcls.awk"
BEGIN { FS = "\t" }
FILENAME == "data/country-info." lang { cc2name[$1] = $3 }
FILENAME == "data/note-info" && length == 0 { section++; next }
FILENAME == "data/note-info" && section == 0 { cc2c[$1] = $2 }
FILENAME == "data/note-info" && section == 1 { ab2l[$1] = $2 }
FILENAME == "data/notes" && $1 == denom && $2 == "Europa" {
i++
col[i][0] = $3
col[i][1] = $4
}
END {
locale = lang == "pt" \
? "pt_BR.UTF-8" \
: lang "_" toupper(lang) ".UTF-8"
CMD = "LC_ALL=" locale " ./bilingual_sort"
asort(col, col, "bilingual_sort")
close(CMD)
for (i = 1; i <= 2; i++) {
if (i == 1)
sig = "Mario Draghi"
else if (i == 2)
sig = "Christine Lagarde"
print ""sig" "
c = 0
for (j = 1; j <= length(col); j++) {
split(col[j][1], s, " ")
if (s[i] == "/")
continue
if (c % 4 == 0)
printf ""
printf "", getcls(s[i])
printf "%s (%s)", cc2name[col[j][0]], cc2c[col[j][0]]
printf " "
if (c % 4 == 3 && j < length(col))
print ""
if (c % 4 != 3 || j != length(col))
c++
}
if ((c - 1) % 4 != 3)
print ""
}
print "MARKER LOL"
}
' data/country-info.$lang data/note-info data/notes \
| colspan.sed \
| last-of-design.sed \
| xfsub '' - $nod/index.html
done
# We will need this later…
{ for CC in `grep -Eo '^[A-Z]{2}' data/coins | uniq`; do
grep "^$CC " data/country-info.$1 | cut -f1,3
done } | sort -k2 >data/tmp-data.$1
for denom in 1 2 5 10 20 50 100 200; do
if [ $denom -eq 100 -o $denom -eq 200 ]; then
denom_=${denom%00}e
else
denom_=${denom}c
fi
nod=$od/euro/$denom_
mkdir -p $nod
cp $od/euro/coins-denom.template.html $nod/index.html
sed -Ei "
//,\\| |s|([^<]*) |\\1
|
" $nod/index.html
if [ $denom -eq 100 -o $denom -eq 200 ]; then
sed -i "s//${denom%00}.00/" $nod/index.html
else
sed -i "s//0.`printf '%02d' $denom`/" $nod/index.html
fi
for CC in `cut -f1 data/tmp-data.$1`; do
gawk -v CC=$CC -v lang=$1 -v denom=$denom '
@include "scripts/getcls.awk"
FILENAME ~ /data\/tmp-data\.[a-z]{2}/ && $1 == CC {
gsub(/^.../, "")
print ""
print ""
print "
"
print "" $0 " "
print ""
}
$1 == CC && /.. start/ {
sub(/.. start/, "")
printf "%s \n", $0
next
}
$1 == CC {
y = $10
if ($11 != "")
y_ = $11
printf ""
if (denom == 1) i = 2
else if (denom == 2) i = 3
else if (denom == 5) i = 4
else if (denom == 10) i = 5
else if (denom == 20) i = 6
else if (denom == 50) i = 7
else if (denom == 100) i = 8
else if (denom == 200) i = 9
# Greece 2002 needs special handling
if (CC == "GR" && $10 == 2002 && $11 == "MM") {
if (i <= 5)
y_ = "F"
else if (i <= 7)
y_ = "E"
else
y_ = "S"
}
if ($i != "/") {
if ($11 != "") {
printf "%s %s ",
getcls($i), y, y_
} else
printf "%s ", getcls($i), y
}
print ""
}
END {
print "MARKER LOL"
print "
"
print "MARKER LMAO"
}
' data/tmp-data.$1 data/coins \
| last-of-design.sed \
| sed -E 's|()[^<]*([^<]* )?( )|\1\3|g' \
| fsub '' - $nod/index.html \
| sed 's/MARKER LMAO//' \
| sponge $nod/index.html
done
done
for file in `find $od -name '*.html'`; do
path=${file#out/??}
path=${path%/*.html}
sed -Ei "s|href=/(..)XYZ>|href=/\1$path>|" $file
done
}
for lang in `find out -mindepth 1 -maxdepth 1 -name '??' -printf '%f\n'`; do
compile_for_lang $lang &
done
wait
find out -name '*.html' -and -not -name 'index.html' -delete
rm data/tmp-data.??
cp -r out/* done