+sub output_one_width_table
+{
+ my ($out, $name, $wpe) = @_;
+ my $start;
+ my $end;
+ my $wp;
+ my $rex;
+
+ print $out "static const struct Interval g_unicode_width_table_${name}[] = {\n";
+
+ $rex = qr/$wpe/;
+
+ for (my $i = 0; $i <= $#eawidths; $i++) {
+ $start = $eawidths[$i]->[0];
+ $end = $eawidths[$i]->[1];
+ $wp = $eawidths[$i]->[2];
+
+ next if ($wp !~ $rex);
+
+ while ($i <= $#eawidths - 1 &&
+ $eawidths[$i + 1]->[0] == $end + 1 &&
+ ($eawidths[$i + 1]->[2] =~ $rex)) {
+ $i++;
+ $end = $eawidths[$i]->[1];
+ }
+
+ printf $out "{0x%04X, 0x%04X},\n", $start, $end;
+ }
+
+ printf $out "};\n\n";
+}
+
+sub output_width_tables
+{
+ my $out = shift;
+
+ @eawidths = sort { $a->[0] <=> $b->[0] } @eawidths;
+
+ print $out <<EOT;
+
+struct Interval
+{
+ gunichar start, end;
+};
+
+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