+EOT
+
+ &output_one_width_table ($out,"wide", "[FW]");
+ &output_one_width_table ($out, "ambiguous", "[A]");
+}
+
+sub print_scripts
+{
+ my $start;
+ my $end;
+ my $script;
+ my $easy_range;
+ my $i;
+
+ print STDERR "Writing gscripttable.h\n";
+
+ open OUT, ">gscripttable.h" or die "Cannot open gscripttable.h: $!\n";
+
+ print OUT<<EOT;
+/* This file is automatically generated. DO NOT EDIT!
+ Instead, edit gen-unicode-tables.pl and re-run. */
+
+#ifndef SCRIPTTABLES_H
+#define SCRIPTTABLES_H
+
+EOT
+
+ @scripts = sort { $a->[0] <=> $b->[0] } @scripts;
+
+ $easy_range = 0x2000;
+
+ print OUT<<EOT;
+#define G_EASY_SCRIPTS_RANGE $easy_range
+
+static const guchar g_script_easy_table[$easy_range] = {
+EOT
+
+ $i = 0;
+ $end = -1;
+
+ for (my $c = 0; $c < $easy_range; $c++) {
+
+ if ($c % 3 == 0) {
+ printf OUT "\n ";
+ }
+
+ if ($c > $end) {
+ $start = $scripts[$i]->[0];
+ $end = $scripts[$i]->[1];
+ $script = $scripts[$i]->[2];
+ $i++;
+ }
+
+ if ($c < $start) {
+ printf OUT " G_UNICODE_SCRIPT_UNKNOWN,";
+ } else {
+ printf OUT " G_UNICODE_SCRIPT_%s,", $script;
+ }
+ }
+
+ if ($end >= $easy_range) {
+ $i--;
+ $scripts[$i]->[0] = $easy_range;
+ }
+
+ print OUT<<EOT;
+
+};
+
+static const struct {
+ gunichar start;
+ guint16 chars;
+ guint16 script;
+} g_script_table[] = {
+EOT
+
+ for (; $i <= $#scripts; $i++) {
+ $start = $scripts[$i]->[0];
+ $end = $scripts[$i]->[1];
+ $script = $scripts[$i]->[2];
+
+ while ($i <= $#scripts - 1 &&
+ $scripts[$i + 1]->[0] == $end + 1 &&
+ $scripts[$i + 1]->[2] eq $script) {
+ $i++;
+ $end = $scripts[$i]->[1];
+ }
+ printf OUT " { %#06x, %5d, G_UNICODE_SCRIPT_%s },\n", $start, $end - $start + 1, $script;
+ }
+
+ printf OUT<<EOT;
+};
+
+#endif /* SCRIPTTABLES_H */
+EOT
+
+ close OUT;
+}