Add warning in comment.
[libidn.git] / lib / gen-stringprep-tables.pl
blob20be731dc7898165a5fcbdfcd8da2cb8a4c89536
1 #! /usr/bin/perl -w
3 # Copyright (C) 2002, 2003 Simon Josefsson
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 # 02111-1307, USA.
20 # I consider the output of this program to be unrestricted. Use it as
21 # you will.
23 use strict;
25 my ($tab) = 59;
26 my ($intable) = 0;
27 my ($tablename);
28 my ($varname);
29 my ($starheader, $header);
30 my ($profile) = "rfc3454";
31 my ($filename) = "$profile.c";
32 my ($line, $start, $end, @map);
34 open(FH, ">$filename") or die "cannot open $filename for writing";
36 print FH "/* This file is automatically generated. DO NOT EDIT!\n";
37 print FH " Instead, edit gen-stringprep-tables.pl and re-run. */\n\n";
39 print FH "#include \"stringprep.h\"\n";
41 while(<>) {
42 s/^ (.*)/$1/g; # for rfc
43 $line = $_;
45 die "already in table" if $intable && m,^----- Start Table (.*) -----,;
46 die "not in table" if !$intable && m,^----- End Table (.*) -----,;
48 if ($intable && m,^----- End Table (.*) -----,) {
49 die "table error" unless $1 eq $tablename ||
50 ($1 eq "C.1.2" && $tablename eq "C.1.1"); # Typo in draft
51 $intable = 0;
52 print FH " { 0 },\n";
53 print FH "};\n\n";
56 if (m,^[A-Z],) {
57 $header = $line;
58 } elsif (!m,^[ -],) {
59 $header .= $line;
62 next unless ($intable || m,^----- Start Table (.*) -----,);
64 if ($intable) {
65 $_ = $line;
66 chop $line;
68 next if m,^$,;
69 next if m,^Hoffman & Blanchet Standards Track \[Page [0-9]+\]$,;
70 next if m,^\f$,;
71 next if m,RFC 3454 Preparation of Internationalized Strings December 2002,;
73 die "regexp failed on line: $line" unless
74 m,^([0-9A-F]+)(-([0-9A-F]+))?(; ([0-9A-F]+)( ([0-9A-F]+))?( ([0-9A-F]+))?( ([0-9A-F]+))?;)?,;
76 die "too many mapping targets on line: $line" if $12;
78 $start = $1;
79 $end = $3;
80 $map[0] = $5;
81 $map[1] = $7;
82 $map[2] = $9;
83 $map[3] = $11;
85 die "tables tried to map a range" if $end && $map[0];
87 if ($map[3]) {
88 printf FH " { 0x%06s, 0, { 0x%06s,%*s/* %s */\n 0x%06s, 0x%06s, 0x%06s }},\n",
89 $start, $map[0], $tab-length($line)-13, " ", $line,
90 $map[1], $map[2], $map[3];
91 } elsif ($map[2]) {
92 printf FH " { 0x%06s, 0, { 0x%06s,%*s/* %s */\n 0x%06s, 0x%06s }},\n",
93 $start, $map[0], $tab-length($line)-14, " ", $line,
94 $map[1], $map[2];
95 } elsif ($map[1]) {
96 printf FH " { 0x%06s, 0, { 0x%06s,%*s/* %s */\n 0x%06s }},\n",
97 $start, $map[0], $tab-length($line)-14, " ", $line,
98 $map[1];
99 } elsif ($map[0]) {
100 printf FH " { 0x%06s, 0, { 0x%06s }},%*s/* %s */\n",
101 $start, $map[0], $tab-length($line)-17, " ", $line;
102 } elsif ($end) {
103 printf FH " { 0x%06s, 0x%06s },%*s/* %s */\n",
104 $start, $end, $tab-length($line)-11, " ", $line;
105 } else {
106 printf FH " { 0x%06s },%*s/* %s */\n",
107 $start, $tab-length($line)-11, " ", $line;
109 } else {
110 $intable = 1 if !$intable;
111 $tablename = $1;
113 ($varname = $tablename) =~ tr/./_/;
114 $header =~ s/\n/\n * /s;
116 print FH "\n/*\n * $header */\n\n";
117 print FH "const Stringprep_table_element stringprep_${profile}_${varname}\[\] = {\n";
121 close FH or die "cannot close $filename";