1*ae771770SStanislav Sedov#!/usr/local/bin/python 2*ae771770SStanislav Sedov# -*- coding: iso-8859-1 -*- 3*ae771770SStanislav Sedov 4*ae771770SStanislav Sedov# $Id$ 5*ae771770SStanislav Sedov 6*ae771770SStanislav Sedov# Copyright (c) 2004 Kungliga Tekniska Högskolan 7*ae771770SStanislav Sedov# (Royal Institute of Technology, Stockholm, Sweden). 8*ae771770SStanislav Sedov# All rights reserved. 9*ae771770SStanislav Sedov# 10*ae771770SStanislav Sedov# Redistribution and use in source and binary forms, with or without 11*ae771770SStanislav Sedov# modification, are permitted provided that the following conditions 12*ae771770SStanislav Sedov# are met: 13*ae771770SStanislav Sedov# 14*ae771770SStanislav Sedov# 1. Redistributions of source code must retain the above copyright 15*ae771770SStanislav Sedov# notice, this list of conditions and the following disclaimer. 16*ae771770SStanislav Sedov# 17*ae771770SStanislav Sedov# 2. Redistributions in binary form must reproduce the above copyright 18*ae771770SStanislav Sedov# notice, this list of conditions and the following disclaimer in the 19*ae771770SStanislav Sedov# documentation and/or other materials provided with the distribution. 20*ae771770SStanislav Sedov# 21*ae771770SStanislav Sedov# 3. Neither the name of the Institute nor the names of its contributors 22*ae771770SStanislav Sedov# may be used to endorse or promote products derived from this software 23*ae771770SStanislav Sedov# without specific prior written permission. 24*ae771770SStanislav Sedov# 25*ae771770SStanislav Sedov# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 26*ae771770SStanislav Sedov# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27*ae771770SStanislav Sedov# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28*ae771770SStanislav Sedov# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 29*ae771770SStanislav Sedov# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30*ae771770SStanislav Sedov# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31*ae771770SStanislav Sedov# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32*ae771770SStanislav Sedov# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33*ae771770SStanislav Sedov# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34*ae771770SStanislav Sedov# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35*ae771770SStanislav Sedov# SUCH DAMAGE. 36*ae771770SStanislav Sedov 37*ae771770SStanislav Sedovimport re 38*ae771770SStanislav Sedovimport string 39*ae771770SStanislav Sedovimport sys 40*ae771770SStanislav Sedov 41*ae771770SStanislav Sedovimport generate 42*ae771770SStanislav Sedovimport rfc3454 43*ae771770SStanislav Sedovimport rfc4518 44*ae771770SStanislav Sedovimport stringprep 45*ae771770SStanislav Sedovimport util 46*ae771770SStanislav Sedov 47*ae771770SStanislav Sedovif len(sys.argv) != 3: 48*ae771770SStanislav Sedov print "usage: %s rfc3454.txt out-dir" % sys.argv[0] 49*ae771770SStanislav Sedov sys.exit(1) 50*ae771770SStanislav Sedov 51*ae771770SStanislav Sedovtables = rfc3454.read(sys.argv[1]) 52*ae771770SStanislav Sedovt2 = rfc4518.read() 53*ae771770SStanislav Sedov 54*ae771770SStanislav Sedovfor x in t2.iterkeys(): 55*ae771770SStanislav Sedov tables[x] = t2[x] 56*ae771770SStanislav Sedov 57*ae771770SStanislav Sedovmap_list = stringprep.get_maplist() 58*ae771770SStanislav Sedov 59*ae771770SStanislav Sedovmap_h = generate.Header('%s/map_table.h' % sys.argv[2]) 60*ae771770SStanislav Sedov 61*ae771770SStanislav Sedovmap_c = generate.Implementation('%s/map_table.c' % sys.argv[2]) 62*ae771770SStanislav Sedov 63*ae771770SStanislav Sedovmap_h.file.write( 64*ae771770SStanislav Sedov''' 65*ae771770SStanislav Sedov#include "windlocl.h" 66*ae771770SStanislav Sedov 67*ae771770SStanislav Sedovstruct translation { 68*ae771770SStanislav Sedov uint32_t key; 69*ae771770SStanislav Sedov unsigned short val_len; 70*ae771770SStanislav Sedov unsigned short val_offset; 71*ae771770SStanislav Sedov wind_profile_flags flags; 72*ae771770SStanislav Sedov}; 73*ae771770SStanislav Sedov 74*ae771770SStanislav Sedovextern const struct translation _wind_map_table[]; 75*ae771770SStanislav Sedov 76*ae771770SStanislav Sedovextern const size_t _wind_map_table_size; 77*ae771770SStanislav Sedov 78*ae771770SStanislav Sedovextern const uint32_t _wind_map_table_val[]; 79*ae771770SStanislav Sedov 80*ae771770SStanislav Sedov''') 81*ae771770SStanislav Sedov 82*ae771770SStanislav Sedovmap_c.file.write( 83*ae771770SStanislav Sedov''' 84*ae771770SStanislav Sedov#include "map_table.h" 85*ae771770SStanislav Sedov 86*ae771770SStanislav Sedovconst struct translation _wind_map_table[] = { 87*ae771770SStanislav Sedov''') 88*ae771770SStanislav Sedov 89*ae771770SStanislav Sedovtrans=[] 90*ae771770SStanislav Sedov 91*ae771770SStanislav Sedovfor t in map_list.iterkeys(): 92*ae771770SStanislav Sedov for l in tables[t]: 93*ae771770SStanislav Sedov m = re.search('^ *([0-9A-F]+)-([0-9A-F]+); *([^;]+); *(.*) *$', l) 94*ae771770SStanislav Sedov if m: 95*ae771770SStanislav Sedov start = int(m.group(1), 0x10) 96*ae771770SStanislav Sedov end = int(m.group(2), 0x10) 97*ae771770SStanislav Sedov value = m.group(3) 98*ae771770SStanislav Sedov desc = m.group(4) 99*ae771770SStanislav Sedov for key in xrange(start,end,1): 100*ae771770SStanislav Sedov trans.append((key, value, desc, [t])) 101*ae771770SStanislav Sedov continue 102*ae771770SStanislav Sedov m = re.search('^ *([^;]+); *([^;]+); *(.*) *$', l) 103*ae771770SStanislav Sedov if m: 104*ae771770SStanislav Sedov key = int(m.group(1), 0x10) 105*ae771770SStanislav Sedov value = m.group(2) 106*ae771770SStanislav Sedov desc = m.group(3) 107*ae771770SStanislav Sedov trans.append((key, value, desc, [t])) 108*ae771770SStanislav Sedov continue 109*ae771770SStanislav Sedov 110*ae771770SStanislav SedovvalTable = [] 111*ae771770SStanislav SedovoffsetTable = {} 112*ae771770SStanislav Sedov 113*ae771770SStanislav Sedovtrans = stringprep.sort_merge_trans(trans) 114*ae771770SStanislav Sedov 115*ae771770SStanislav Sedovfor x in trans: 116*ae771770SStanislav Sedov if x[0] == 0xad: 117*ae771770SStanislav Sedov print "fooresult %s" % ",".join(x[3]) 118*ae771770SStanislav Sedov 119*ae771770SStanislav Sedovfor x in trans: 120*ae771770SStanislav Sedov (key, value, description, table) = x 121*ae771770SStanislav Sedov v = value.split() 122*ae771770SStanislav Sedov i = util.subList(valTable, v) 123*ae771770SStanislav Sedov if i: 124*ae771770SStanislav Sedov offsetTable[key] = i 125*ae771770SStanislav Sedov else: 126*ae771770SStanislav Sedov offsetTable[key] = len(valTable) 127*ae771770SStanislav Sedov valTable.extend(v) 128*ae771770SStanislav Sedov 129*ae771770SStanislav Sedovfor x in trans: 130*ae771770SStanislav Sedov (key, value, description, tables) = x 131*ae771770SStanislav Sedov symbols = stringprep.symbols(map_list, tables) 132*ae771770SStanislav Sedov if len(symbols) == 0: 133*ae771770SStanislav Sedov print "no symbol for %s %s (%s)" % (key, description, tables) 134*ae771770SStanislav Sedov sys.exit(1) 135*ae771770SStanislav Sedov v = value.split() 136*ae771770SStanislav Sedov map_c.file.write(" {0x%x, %u, %u, %s}, /* %s: %s */\n" 137*ae771770SStanislav Sedov % (key, len(v), offsetTable[key], symbols, ",".join(tables), description)) 138*ae771770SStanislav Sedov 139*ae771770SStanislav Sedovmap_c.file.write( 140*ae771770SStanislav Sedov''' 141*ae771770SStanislav Sedov}; 142*ae771770SStanislav Sedov 143*ae771770SStanislav Sedov''') 144*ae771770SStanislav Sedov 145*ae771770SStanislav Sedovmap_c.file.write( 146*ae771770SStanislav Sedov "const size_t _wind_map_table_size = %u;\n\n" % len(trans)) 147*ae771770SStanislav Sedov 148*ae771770SStanislav Sedovmap_c.file.write( 149*ae771770SStanislav Sedov "const uint32_t _wind_map_table_val[] = {\n") 150*ae771770SStanislav Sedov 151*ae771770SStanislav Sedovfor x in valTable: 152*ae771770SStanislav Sedov map_c.file.write(" 0x%s,\n" % x) 153*ae771770SStanislav Sedov 154*ae771770SStanislav Sedovmap_c.file.write( 155*ae771770SStanislav Sedov "};\n\n") 156*ae771770SStanislav Sedov 157*ae771770SStanislav Sedovmap_h.close() 158*ae771770SStanislav Sedovmap_c.close() 159