1169689Skan#!/usr/local/bin/python 2169689Skan# -*- coding: iso-8859-1 -*- 3171825Skan 4169689Skan# $Id$ 5169689Skan 6169689Skan# Copyright (c) 2004 Kungliga Tekniska H��gskolan 7169689Skan# (Royal Institute of Technology, Stockholm, Sweden). 8169689Skan# All rights reserved. 9169689Skan# 10169689Skan# Redistribution and use in source and binary forms, with or without 11169689Skan# modification, are permitted provided that the following conditions 12169689Skan# are met: 13169689Skan# 14169689Skan# 1. Redistributions of source code must retain the above copyright 15169689Skan# notice, this list of conditions and the following disclaimer. 16169689Skan# 17169689Skan# 2. Redistributions in binary form must reproduce the above copyright 18169689Skan# notice, this list of conditions and the following disclaimer in the 19169689Skan# documentation and/or other materials provided with the distribution. 20169689Skan# 21169689Skan# 3. Neither the name of the Institute nor the names of its contributors 22169689Skan# may be used to endorse or promote products derived from this software 23169689Skan# without specific prior written permission. 24169689Skan# 25169689Skan# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 26169689Skan# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27169689Skan# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28169689Skan# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 29169689Skan# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30169689Skan# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31169689Skan# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32169689Skan# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33169689Skan# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34169689Skan# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35169689Skan# SUCH DAMAGE. 36169689Skan 37169689Skanimport re 38169689Skanimport string 39169689Skanimport sys 40169689Skan 41169689Skanimport generate 42169689Skanimport rfc3454 43169689Skanimport rfc4518 44169689Skanimport stringprep 45169689Skanimport util 46169689Skan 47169689Skanif len(sys.argv) != 3: 48169689Skan print "usage: %s rfc3454.txt out-dir" % sys.argv[0] 49169689Skan sys.exit(1) 50169689Skan 51169689Skantables = rfc3454.read(sys.argv[1]) 52169689Skant2 = rfc4518.read() 53169689Skan 54169689Skanfor x in t2.iterkeys(): 55169689Skan tables[x] = t2[x] 56169689Skan 57169689Skanmap_list = stringprep.get_maplist() 58169689Skan 59169689Skanmap_h = generate.Header('%s/map_table.h' % sys.argv[2]) 60169689Skan 61169689Skanmap_c = generate.Implementation('%s/map_table.c' % sys.argv[2]) 62169689Skan 63169689Skanmap_h.file.write( 64169689Skan''' 65169689Skan#include "windlocl.h" 66169689Skan 67169689Skanstruct translation { 68169689Skan uint32_t key; 69169689Skan unsigned short val_len; 70169689Skan unsigned short val_offset; 71169689Skan wind_profile_flags flags; 72169689Skan}; 73169689Skan 74169689Skanextern const struct translation _wind_map_table[]; 75169689Skan 76169689Skanextern const size_t _wind_map_table_size; 77169689Skan 78169689Skanextern const uint32_t _wind_map_table_val[]; 79169689Skan 80169689Skan''') 81169689Skan 82169689Skanmap_c.file.write( 83169689Skan''' 84169689Skan#include "map_table.h" 85169689Skan 86169689Skanconst struct translation _wind_map_table[] = { 87169689Skan''') 88169689Skan 89169689Skantrans=[] 90169689Skan 91169689Skanfor t in map_list.iterkeys(): 92169689Skan for l in tables[t]: 93169689Skan m = re.search('^ *([0-9A-F]+)-([0-9A-F]+); *([^;]+); *(.*) *$', l) 94169689Skan if m: 95169689Skan start = int(m.group(1), 0x10) 96169689Skan end = int(m.group(2), 0x10) 97169689Skan value = m.group(3) 98169689Skan desc = m.group(4) 99169689Skan for key in xrange(start,end,1): 100169689Skan trans.append((key, value, desc, [t])) 101169689Skan continue 102169689Skan m = re.search('^ *([^;]+); *([^;]+); *(.*) *$', l) 103169689Skan if m: 104169689Skan key = int(m.group(1), 0x10) 105169689Skan value = m.group(2) 106169689Skan desc = m.group(3) 107169689Skan trans.append((key, value, desc, [t])) 108169689Skan continue 109169689Skan 110169689SkanvalTable = [] 111169689SkanoffsetTable = {} 112169689Skan 113169689Skantrans = stringprep.sort_merge_trans(trans) 114169689Skan 115169689Skanfor x in trans: 116169689Skan if x[0] == 0xad: 117169689Skan print "fooresult %s" % ",".join(x[3]) 118169689Skan 119169689Skanfor x in trans: 120169689Skan (key, value, description, table) = x 121169689Skan v = value.split() 122169689Skan i = util.subList(valTable, v) 123169689Skan if i: 124169689Skan offsetTable[key] = i 125169689Skan else: 126169689Skan offsetTable[key] = len(valTable) 127169689Skan valTable.extend(v) 128169689Skan 129169689Skanfor x in trans: 130169689Skan (key, value, description, tables) = x 131169689Skan symbols = stringprep.symbols(map_list, tables) 132169689Skan if len(symbols) == 0: 133169689Skan print "no symbol for %s %s (%s)" % (key, description, tables) 134169689Skan sys.exit(1) 135169689Skan v = value.split() 136169689Skan map_c.file.write(" {0x%x, %u, %u, %s}, /* %s: %s */\n" 137169689Skan % (key, len(v), offsetTable[key], symbols, ",".join(tables), description)) 138169689Skan 139169689Skanmap_c.file.write( 140169689Skan''' 141169689Skan}; 142169689Skan 143169689Skan''') 144169689Skan 145169689Skanmap_c.file.write( 146169689Skan "const size_t _wind_map_table_size = %u;\n\n" % len(trans)) 147169689Skan 148169689Skanmap_c.file.write( 149169689Skan "const uint32_t _wind_map_table_val[] = {\n") 150169689Skan 151169689Skanfor x in valTable: 152169689Skan map_c.file.write(" 0x%s,\n" % x) 153169689Skan 154169689Skanmap_c.file.write( 155169689Skan "};\n\n") 156169689Skan 157169689Skanmap_h.close() 158169689Skanmap_c.close() 159169689Skan