Path: blob/main/crypto/heimdal/lib/wind/gen-combining.py
34889 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 UnicodeData4243if len(sys.argv) != 3:44print "usage: %s UnicodeData.txt out-dir" % sys.argv[0]45sys.exit(1)4647ud = UnicodeData.read(sys.argv[1])4849trans = {}50for k,v in ud.items():51if int(v[2]) != 0 :52trans[k] = [int(v[2]), v[1]]5354# trans = [(x[0], int(x[3]), x[1]) for x in UnicodeData.read() if int(x[3]) != 0]5556combining_h = generate.Header('%s/combining_table.h' % sys.argv[2])57combining_c = generate.Implementation('%s/combining_table.c' % sys.argv[2])5859combining_h.file.write(60'''61#include <krb5-types.h>6263struct translation {64uint32_t key;65unsigned combining_class;66};6768extern const struct translation _wind_combining_table[];6970extern const size_t _wind_combining_table_size;71''')7273combining_c.file.write(74'''75#include <stdlib.h>76#include "combining_table.h"7778const struct translation _wind_combining_table[] = {79''')8081s = trans.keys()82s.sort()83for k in s:84v = trans[k]85combining_c.file.write("{0x%x, %u}, /* %s */\n"86% (k, v[0], v[1]))878889#trans.sort()90#for x in trans:91# combining_c.file.write("{0x%x, %u}, /* %s */\n"92# % (x[0], x[1], x[2]))9394combining_c.file.write(95'''96};97''')9899combining_c.file.write(100"const size_t _wind_combining_table_size = %u;\n" % len(trans))101102103combining_h.close()104combining_c.close()105106107