summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/Makefile20
-rw-r--r--utils/idna-derived-props-gen.pl128
-rw-r--r--utils/idna-tables-properties.csv (renamed from utils/idna-tables-5.2.0-properties.csv)0
3 files changed, 127 insertions, 21 deletions
diff --git a/utils/Makefile b/utils/Makefile
index a6d2f1248..430edf9b4 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -63,6 +63,26 @@ $(TOOLROOT)/convert_image: utils/convert_image.c $(TOOLROOT)/created
# Build too to perform font conversion
+#
$(TOOLROOT)/convert_font: utils/convert_font.c $(TOOLROOT)/created
$(VQ)echo "BUILD CC: $@"
$(Q)$(BUILD_CC) $(BUILD_CFLAGS) -o $@ $<
+
+
+# idna
+#
+IDNA_UNICODE_MAJOR=11
+
+utils/DerivedJoiningType.txt:
+ curl -o $@ "https://www.unicode.org/Public/$(IDNA_UNICODE_MAJOR).0.0/ucd/extracted/DerivedJoiningType.txt"
+
+utils/IdnaMappingTable.txt:
+ curl -o $@ "https://www.unicode.org/Public/idna/$(IDNA_UNICODE_MAJOR).0.0/IdnaMappingTable.txt"
+
+utils/idna-tables-properties.csv:
+ curl -o $@ "https://www.iana.org/assignments/idna-tables-$(IDNA_UNICODE_MAJOR).0.0/idna-tables-properties.csv"
+
+
+utils/idna_props.h: utils/DerivedJoiningType.txt utils/idna-tables-properties.csv
+ $(VQ)echo " IDNA: $@"
+ $(Q)$(PERL) utils/idna-derived-props-gen.pl -o $@ -p utils/idna-tables-properties.csv -j utils/DerivedJoiningType.txt
diff --git a/utils/idna-derived-props-gen.pl b/utils/idna-derived-props-gen.pl
index 515f62a40..a9e9b4b53 100644
--- a/utils/idna-derived-props-gen.pl
+++ b/utils/idna-derived-props-gen.pl
@@ -16,7 +16,88 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-print <<HEADER;
+use strict;
+
+use Getopt::Long ();
+use Fcntl qw( O_CREAT O_EXCL O_WRONLY O_APPEND O_RDONLY O_WRONLY );
+
+use constant GETOPT_OPTS => qw( auto_abbrev no_getopt_compat bundling );
+use constant GETOPT_SPEC =>
+ qw( output|o=s
+ properties|p=s
+ joining|j=s
+ help|h|? );
+
+# default option values:
+my %opt = qw(properties "idna-tables-properties.csv" joining "DerivedJoiningType.txt");
+
+sub usage
+{
+ my @fmt = map { s/::$//; $_ } keys(%{$::{'msgfmt::'}});
+ print(STDERR <<TXT );
+usage:
+ $0 [-o output-file] -p properties-file -j joining-file
+
+ output-file : defaults to standard output
+TXT
+ exit(1);
+}
+
+sub output_stream
+{
+ if( $opt{output} )
+ {
+ my $ofh;
+
+ sysopen( $ofh, $opt{output}, O_CREAT|O_EXCL|O_APPEND|O_WRONLY ) ||
+ die( "$0: Failed to open output file $opt{output}: $!\n" );
+
+ return $ofh;
+ }
+
+ return \*STDOUT;
+}
+
+sub input_stream
+{
+ my $stream = $_[0];
+
+ if( $opt{$stream} )
+ {
+ my $ifh;
+
+ sysopen( $ifh, $opt{$stream}, O_RDONLY ) ||
+ die( "$0: Failed to open input file $stream: $!\n" );
+
+ return $ifh;
+ }
+ die( "$0: No input file for $stream");
+}
+
+sub main
+{
+ my $output;
+ my $properties;
+ my $joining;
+ my $opt_ok;
+
+ # option parsing:
+ Getopt::Long::Configure( GETOPT_OPTS );
+ $opt_ok = Getopt::Long::GetOptions( \%opt, GETOPT_SPEC );
+
+ # double check the options are sane (and we weren't asked for the help)
+ if( !$opt_ok || $opt{help} )
+ {
+ usage();
+ }
+
+ # open the appropriate files
+ $properties = input_stream("properties");
+ $joining = input_stream("joining");
+ $output = output_stream();
+
+
+ print { $output } <<HEADER;
/* This file is generated by idna-derived-props-gen.pl
* DO NOT EDIT BY HAND
*/
@@ -53,19 +134,21 @@ typedef struct idna_table {
idna_table idna_derived[] = {
HEADER
-open(CSVFILE, "idna-tables-5.2.0-properties.csv");
-$line = <CSVFILE>; # discard header line
-while($line = <CSVFILE>) {
- @items = split(/\,/, $line);
- @codepoints = split(/-/, $items[0]);
- if($#codepoints == 0) { $codepoints[1] = $codepoints[0]; }
- print "\t{ 0x" . $codepoints[0] . ", 0x" . $codepoints[1] . ", .p.property = IDNA_P_" . $items[1] . " },\n";
-}
+ my $line = <$properties>; # discard header line
+
+ while($line = <$properties>) {
+ my @items = split(/\,/, $line);
+ my @codepoints = split(/-/, $items[0]);
+ if($#codepoints == 0) {
+ $codepoints[1] = $codepoints[0];
+ }
+ print { $output } "\t{ 0x" . $codepoints[0] . ", 0x" . $codepoints[1] . ", .p.property = IDNA_P_" . $items[1] . " },\n";
+ }
-close(CSVFILE);
+ close($properties);
-print <<HEADER;
+ print { $output } <<HEADER;
{ 0, 0, .p.property = 0}
};
@@ -73,24 +156,27 @@ idna_table idna_joiningtype[] = {
HEADER
-open(TXTFILE, "DerivedJoiningType.txt");
-
-while($line = <TXTFILE>) {
+ while($line = <$joining>) {
chop($line);
if(substr($line, 0, 1) eq '#') {next;}
if(length($line) == 0) {next;}
- @items = split(/;/, $line);
- @codepoints = split(/\./, $items[0]);
- if($#codepoints == 0) { $codepoints[2] = $codepoints[0]; }
- print "\t{ 0x" . $codepoints[0] . ", 0x" . $codepoints[2] . ", .p.jt = IDNA_UNICODE_JT_" . substr($items[1], 1, 1) . " },\n";
-}
+ my @items = split(/;/, $line);
+ my @codepoints = split(/\./, $items[0]);
+ if($#codepoints == 0) {
+ $codepoints[2] = $codepoints[0];
+ }
+ print { $output } "\t{ 0x" . $codepoints[0] . ", 0x" . $codepoints[2] . ", .p.jt = IDNA_UNICODE_JT_" . substr($items[1], 1, 1) . " },\n";
+ }
-close(TXTFILE);
+ close($joining);
-print <<HEADER;
+ print { $output } <<HEADER;
{ 0, 0, .p.jt = 0}
};
#endif
HEADER
+}
+
+main();
diff --git a/utils/idna-tables-5.2.0-properties.csv b/utils/idna-tables-properties.csv
index a74547bc9..a74547bc9 100644
--- a/utils/idna-tables-5.2.0-properties.csv
+++ b/utils/idna-tables-properties.csv