-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgen-stringprep-tables.pl
150 lines (122 loc) · 4.34 KB
/
gen-stringprep-tables.pl
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
#! /usr/bin/perl -w
# Copyright (C) 2002 Simon Josefsson
# This program 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; either version 2, or (at your option)
# any later version.
# This program 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
# I consider the output of this program to be unrestricted. Use it as
# you will.
# translation to C# output by Joe Hildebrand
use strict;
my ($tab) = 59;
my ($intable) = 0;
my ($tablename);
my ($varname);
my ($starheader, $header);
my ($profile) = "RFC3454";
my ($filename) = "${profile}.cs";
my ($line, $start, $end, @map);
open(FH, ">$filename") or die "cannot open $filename for writing";
print FH <<EOF;
/* This file is auto-generated. DO NOT EDIT! */
using System;
namespace stringprep
{
/// <summary>
/// Constants from RFC 3454, Stringprep.
/// </summary>
public class RFC3454
{
EOF
while(<>) {
s/^ (.*)/$1/g; # for rfc
$line = $_;
die "already in table" if $intable && m,^----- Start Table (.*) -----,;
die "not in table" if !$intable && m,^----- End Table (.*) -----,;
if ($intable && m,^----- End Table (.*) -----,) {
die "table error" unless $1 eq $tablename ||
($1 eq "C.1.2" && $tablename eq "C.1.1"); # Typo in draft
$intable = 0;
print FH " };\n\n";
}
if (m,^[A-Z],) {
$header = $line;
} elsif (!m,^[ -],) {
$header .= $line;
}
next unless ($intable || m,^----- Start Table (.*) -----,);
if ($intable) {
$_ = $line;
chop $line;
next if m,^$,;
next if m,^Hoffman & Blanchet Standards Track \[Page [0-9]+\]$,;
next if m,^$,;
next if m,RFC 3454 Preparation of Internationalized Strings December 2002,;
die "regexp failed on line: $line" unless
m,^([0-9A-F]+)(-([0-9A-F]+))?(; ([0-9A-F]+)( ([0-9A-F]+))?( ([0-9A-F]+))?( ([0-9A-F]+))?;)?,;
die "too many mapping targets on line: $line" if $12;
$start = $1;
$end = $3;
$map[0] = $5;
$map[1] = $7;
$map[2] = $9;
$map[3] = $11;
die "tables tried to map a range" if $end && $map[0];
if (length($start) > 4) {
# do nothing
} elsif ($map[3]) {
printf FH " \"\\x%04s\\x%04s\\x%04s\\x%04s\\x%04s\", %*s/* %s */\n",
$start, $map[0], $map[1], $map[2], $map[3], $tab-length($line)-13, " ", $line;
} elsif ($map[2]) {
printf FH " \"\\x%04s\\x%04s\\x%04s\\x%04s\", %*s/* %s */\n",
$start, $map[0], $map[1], $map[2], $tab-length($line)-20, " ", $line;
} elsif ($map[1]) {
printf FH " \"\\x%04s\\x%04s\\x%04s\", %*s/* %s */\n",
$start, $map[0], $map[1], $tab-length($line)-19, " ", $line,
} elsif ($map[0]) {
printf FH " \"\\x%04s\\x%04s\",%*s/* %s */\n",
$start, $map[0], $tab-length($line)-17, " ", $line;
} elsif ($end) {
printf FH " new char[] {'\\x%04s', '\\x%04s'},%*s/* %s */\n",
$start, $end, $tab-length($line)-46, " ", $line;
} else {
if ($varname =~ /^B/) {
printf FH " \"\\x%04s\",%*s/* %s */\n",
$start, $tab-length($line)-11, " ", $line;
} else {
printf FH " new char[] {'\\x%04s', '\\x0000'},%*s/* %s */\n",
$start, $tab-length($line)-51, " ", $line;
}
}
} else {
$intable = 1 if !$intable;
$tablename = $1;
($varname = $tablename) =~ tr/./_/;
$header =~ s/\n/\n \/\/\/ /s;
print FH "\n /// <summary>\n /// $header /// </summary>\n";
if ($varname =~ /^B/) {
print FH " public static readonly string[] ${varname} = new string[]\n {\n";
} else {
print FH " public static readonly char[][] ${varname} = new char[][]\n {\n";
}
}
}
print FH <<EOF;
}
}
EOF
close FH or die "cannot close $filename";
unlink "temp.dll";
unlink "$profile.resx";
system "csc /out:temp.dll /t:library $filename" and die;
system "../ResTool/bin/Debug/ResTool.exe temp.dll $profile.resx";
unlink "temp.dll";
#unlink $filename;