Path: blob/main/crypto/heimdal/lib/wind/gen-bidi.py
34914 views
#!/usr/local/bin/python1# -*- coding: iso-8859-1 -*-23# $Id$45# Copyright (c) 2004 Kungliga Tekniska Högskolan6# (Royal Institute of Technology, Stockholm, Sweden).7# All rights reserved.8#9# Redistribution and use in source and binary forms, with or without10# modification, are permitted provided that the following conditions11# are met:12#13# 1. Redistributions of source code must retain the above copyright14# notice, this list of conditions and the following disclaimer.15#16# 2. Redistributions in binary form must reproduce the above copyright17# notice, this list of conditions and the following disclaimer in the18# documentation and/or other materials provided with the distribution.19#20# 3. Neither the name of the Institute nor the names of its contributors21# may be used to endorse or promote products derived from this software22# without specific prior written permission.23#24# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND25# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE26# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE27# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE28# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL29# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS30# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)31# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT32# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY33# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF34# SUCH DAMAGE.3536import re37import string38import sys3940import generate41import rfc34544243if len(sys.argv) != 3:44print "usage: %s rfc3454.txt outdir" % sys.argv[0]45sys.exit(1)4647tables = rfc3454.read(sys.argv[1])4849bidi_h = generate.Header('%s/bidi_table.h' % sys.argv[2])5051bidi_c = generate.Implementation('%s/bidi_table.c' % sys.argv[2])5253bidi_h.file.write(54'''55#include <krb5-types.h>5657struct range_entry {58uint32_t start;59unsigned len;60};6162extern const struct range_entry _wind_ral_table[];63extern const struct range_entry _wind_l_table[];6465extern const size_t _wind_ral_table_size;66extern const size_t _wind_l_table_size;6768''')6970bidi_c.file.write(71'''72#include <stdlib.h>73#include "bidi_table.h"7475''')7677def printTable(file, table, variable):78"""print table to file named as variable"""79file.write("const struct range_entry %s[] = {\n" % variable)80count = 081for l in tables[table]:82m = re.search('^ *([0-9A-F]+)-([0-9A-F]+) *$', l)83if m:84start = int(m.group(1), 0x10)85end = int(m.group(2), 0x10)86file.write(" {0x%x, 0x%x},\n" % (start, end - start + 1))87count += 188else:89m = re.search('^ *([0-9A-F]+) *$', l)90if m:91v = int(m.group(1), 0x10)92file.write(" {0x%x, 1},\n" % v)93count += 194file.write("};\n\n")95file.write("const size_t %s_size = %u;\n\n" % (variable, count))9697printTable(bidi_c.file, 'D.1', '_wind_ral_table')98printTable(bidi_c.file, 'D.2', '_wind_l_table')99100bidi_h.close()101bidi_c.close()102103104