summaryrefslogtreecommitdiff
path: root/utils/idna-derived-props-gen.pl
blob: 515f62a40eab9e064dba529ea5424a3a6b8d1131 (plain)
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
#!/usr/bin/perl
#
# Copyright 2014 Chris Young <chris@unsatisfactorysoftware.co.uk>
#
# This file is part of NetSurf, http://www.netsurf-browser.org/
#
# NetSurf is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# NetSurf is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# 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;
/* This file is generated by idna-derived-props-gen.pl
 * DO NOT EDIT BY HAND
 */
#ifndef _NETSURF_UTILS_IDNA_PROPS_H_
#define _NETSURF_UTILS_IDNA_PROPS_H_

typedef enum idna_property {
	IDNA_P_PVALID		= 1,
	IDNA_P_CONTEXTJ		= 2,
	IDNA_P_CONTEXTO		= 3,
	IDNA_P_DISALLOWED	= 4,
	IDNA_P_UNASSIGNED	= 5
} idna_property;

typedef enum idna_unicode_jt {
	IDNA_UNICODE_JT_U	= 0,
	IDNA_UNICODE_JT_C	= 1,
	IDNA_UNICODE_JT_D	= 2,
	IDNA_UNICODE_JT_R	= 3,
	IDNA_UNICODE_JT_T	= 4,
	IDNA_UNICODE_JT_L	= 5
} idna_unicode_jt;


typedef struct idna_table {
	int32_t start;
	int32_t end;
	union p {
		idna_property property;
		idna_unicode_jt jt;
	} p;
} 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";
}

close(CSVFILE);

print <<HEADER;
	{ 0, 0, .p.property = 0}
};

idna_table idna_joiningtype[] = {
HEADER


open(TXTFILE, "DerivedJoiningType.txt");

while($line = <TXTFILE>) {
	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";
}

close(TXTFILE);

print <<HEADER;
	{ 0, 0, .p.jt = 0}
};
#endif
HEADER