summaryrefslogtreecommitdiffhomepage
path: root/build
blob: c881347fe15b52d3e82a1854572b118a61c5031d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
#!/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 '<!-- LANG-SELECTOR -->' src/language-selector.html \
	                               $od/nav-bar.html
	sed -i "\\.<a href=/$1XYZ>.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|<html lang=XX>|<html lang=$1>|
		  '"                                                                    \
		| while read file; do
			  xfsub '<!-- NAV-BAR -->'        $od/nav-bar.html             $file
			  xfsub '<!-- COIN-NAV -->'       $od/euro/coin-nav.html       $file
			  xfsub '<!-- NOTE-NAV -->'       $od/euro/note-nav.html       $file
			  xfsub '<!-- COIN-DENOM-NAV -->' $od/euro/coin-denom-nav.html $file
			  xfsub '<!-- FOOTER -->'         $od/footer.html              $file
			  xfsub '<!-- TABLE-KEY -->'      $od/table-key.html           $file
		  done

	for file in `find $od -name 'index.html'`; do
		base=${file#out}
		base=${base%/index.html}
		sed -Ei "
			/<nav>/,\\|</nav>|s|<a href=$base>([^<]*)</a>|<div class=selected>\1</div>|
		" $file
	done

	sed -Ei '
		/<!-- IF-COINS -->/,/<!-- FI-COINS -->/d
		/<!-- (IF|FI)-NOTES -->/d
	' $od/euro/notes.template.html $od/euro/tnotes.template.html
	sed -Ei '
		/<!-- IF-NOTES -->/,/<!-- FI-NOTES -->/d
		/<!-- (IF|FI)-COINS -->/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 '
		/<nav>/,\|</nav>|s|<a href=/../euro/tn>([^<]*)</a>|<div class=selected>\1</div>|
	' $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 \
					"<trX><td class=missing colspan=1>%s</td>"\
					"<td class=%s colspan=6>%s</td></tr>\n",
					fmt(col[i][0]), getcls(col[i][2]), col[i][1]
			}
			print "MARKER LOL"
		}
	' data/notes                                                                \
		| last-of-design.sed                                                    \
		| xfsub '<!-- TABLE-BODY -->' - $nod/index.html

	grep -Eo '^[A-Z]{2}' data/coins \
		| uniq \
		| gawk -v lang=$1 '
			function bilingual_sort(i1, v1, i2, v2,    f)
			{
				print v1 ":" v2 |& CMD
				CMD |& getline f

				return f == v1 ? -1 : +1
			}

			BEGIN {
				while (getline < ("data/country-info." lang)) {
					split($0, a, "\t")
					map[a[1]] = a[3]
				}
			}

			{ countries[$0] = map[$0] }

			END {
				locale = lang == "pt" \
					? "pt_BR.UTF-8"   \
					: lang "_" toupper(lang) ".UTF-8"

				CMD = "LC_ALL=" locale " ./bilingual_sort"
				PROCINFO["sorted_in"] = "bilingual_sort"

				print "<table class=country-table><tbody>"
				for (code in countries) {
					i++
					if (i % 4 == 1)
						printf "<tr>"
					printf "<td><a href=%s>%s</a></td>", tolower(code),
					       countries[code]
					if (i % 4 == 0)
						print "</tr>"
				}
				print "</tbody></table>"

				close(CMD)
			}
		' \
		| xfsub '<!-- COUNTRY-TABLE -->' - $od/euro/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 "
			/<nav>/,\\|</nav>|s|<a href=/../euro/$cc>$CC</a>|<div class=selected>$CC</div>|
		" $nod/index.html
		grep -m1 "^$CC" data/country-info.$1                                    \
			| cut -f2                                                           \
			| xfsub '<!-- DEMON -->' - $nod/index.html
		sed -Ei "
			/<!-- (IF|FI)-$CC -->/d
			/<!-- IF-!$CC -->/,/<!-- FI-!$CC -->/d
			/<!-- (IF|FI)-![A-Z]+ -->/d
			/<!-- IF-[A-Z]+ -->/,/<!-- FI-[A-Z]+ -->/d
		" $nod/index.html

		gawk -v CC=$CC '
			@include "scripts/getcls.awk"

			FILENAME != "data/coins" {
				split($0, a, "\t")
				en2lang[a[1]] = a[2]
			}

			FILENAME == "data/coins" && $1 == CC && /.. start/ {
				sub(/^.. start/, ""); sub(/^ /, "")
				printf "<tr class=new-design><th colspan=8>%s</th></tr>\n",
				       en2lang[$0]
				next
			}

			FILENAME == "data/coins" && $1 == CC {
				y = $10
				if ($11 != "")
					y_ = $11
				printf "<trX>"
				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 "<td class=%s>%s <sup>%s</sup></td>",
						       getcls($i), y, y_
					} else
						printf "<td class=%s>%s</td>", getcls($i), y
				}
				print "</tr>"
			}

			END { print "MARKER LOL" }
		' data/sections.$1 data/coins                                                   \
			| last-of-design.sed                                                        \
			| sed -E 's|(<td class=not-minted>)[^<]*(<sup>[^<]*</sup>)?(</td>)|\1 \3|g' \
			| xfsub '<!-- SCOIN-TABLE-BODY -->' - $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 "<tr><td class=missing>%s <sup>%s</sup></td>", y, $3
				} else
					printf "<tr><td class=missing>%s</td>", y

				for (i = 1; i <= NF - n; i++) {
					printf "<td colspan=Y class=%s>%s</td>",
					       getcls($(i + n)), a[i + 1]
			   }
				print "</tr>"
			}

			END { print "MARKER LOL" }
		' data/ccs                                                              \
			| colspan.sed                                                       \
			| grep -Fv 'MARKER LOL'                                             \
			| xfsub '<!-- CCOIN-TABLE-BODY -->' - $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 "
			/<nav>/,\\|</nav>|s|<a href=/../euro/${denom}e>([^<]*)</a>|<div class=selected>\\1</div>|
		" $nod/index.html
		sed -i "s/<!-- DENOM -->/$denom/" $nod/index.html

		sed -Ei "
			/<!-- (IF|FI)-$denom -->/d
			/<!-- IF-!$denom -->/,/<!-- FI-!$denom -->/d
			/<!-- (IF|FI)-![0-9]+ -->/d
			/<!-- IF-[0-9]+ -->/,/<!-- FI-[0-9]+ -->/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 "<tr class=new-design><th colspan=12>"sig"</th></tr>"

					c = 1

					for (j = 1; j <= length(col); j++) {
						split(col[j][1], s, " ")
						if (s[i] == "/")
							continue

						if ((c - 1) % 4 == 0)
							printf "<trX>"

						printf "<td colspan=X class=%s>", getcls(s[i])
						printf "%s (%s)", cc2name[col[j][0]], cc2c[col[j][0]]
						printf "</td>"

						if (c % 4 == 0)
							print "</tr>"
						c++
					}
					if ((c - 2) % 4 != 3)
						print "</tr>"
				}
				print "MARKER LOL"
			}
		' data/country-info.$1 data/note-info data/notes                        \
			| colspan.sed                                                       \
			| last-of-design.sed                                                \
			| xfsub '<!-- 2002-TABLE-BODY -->' - $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 "<tr class=new-design><th colspan=12>"sig"</th></tr>"

					c = 0

					for (j = 1; j <= length(col); j++) {
						split(col[j][1], s, " ")
						if (s[i] == "/")
							continue

						if (c % 4 == 0)
							printf "<trX>"

						printf "<td colspan=X class=%s>", getcls(s[i])
						printf "%s (%s)", cc2name[col[j][0]], cc2c[col[j][0]]
						printf "</td>"

						if (c % 4 == 3 && j < length(col))
							print "</tr>"
						if (c % 4 != 3 || j != length(col))
							c++
					}
					if ((c - 1) % 4 != 3)
						print "</tr>"
				}
				print "MARKER LOL"
			}
		' data/country-info.$lang data/note-info data/notes                     \
			| colspan.sed                                                       \
			| last-of-design.sed                                                \
			| xfsub '<!-- EUROPA-TABLE-BODY -->' - $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 "
			/<nav>/,\\|</nav>|s|<a href=/../euro/${denom_}>([^<]*)</a>|<div class=selected>\\1</div>|
		" $nod/index.html
		case $1 in
		en)
			sep=.
			;;
		*)
			sep=,
			;;
		esac
		if [ $denom -eq 100 -o $denom -eq 200 ]; then
			sed -i "s/<!-- DENOM -->/${denom%00}${sep}00/" $nod/index.html
		else
			sed -i "s/<!-- DENOM -->/0$sep`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 "<section class=\"cl-section slant-down\">"
					print "<div>"
					print "<table class=coin-table cellspacing=0>"
					print "<thead><tr><th>" $0 "</th></tr></thead>"
					print "<tbody>"
				}

				$1 == CC && /.. start/ {
					sub(/.. start/, "")
					printf "<tr class=new-design><th>%s</th></tr>\n", $0
					next
				}

				$1 == CC {
					y = $10
					if ($11 != "")
						y_ = $11
					printf "<trX>"

					     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 "<td class=%s>%s <sup>%s</sup></td>",
								   getcls($i), y, y_
						} else
							printf "<td class=%s>%s</td>", getcls($i), y
					}
					print "</tr>"
				}

				END {
					print "MARKER LOL"
					print "</tbody></table></div></section>"
					print "MARKER LMAO"
				}
			' data/tmp-data.$1 data/coins                                                  \
				| last-of-design.sed                                                       \
				| sed -E 's|(<td class=not-minted>)[^<]*(<sup>[^<]*</sup>)?(</td>)|\1\3|g' \
				| fsub '<!-- DENOM-TABLE -->' - $nod/index.html                            \
				| sed 's/MARKER LMAO/<!-- DENOM-TABLE -->/'                                \
				| 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