1156960Sume#!/usr/local/bin/python 2156960Sume# -*- coding: iso-8859-1 -*- 3156960Sume 4156960Sume# $Id$ 51539Srgrimes 61539Srgrimes# Copyright (c) 2004 Kungliga Tekniska H��gskolan 71539Srgrimes# (Royal Institute of Technology, Stockholm, Sweden). 81539Srgrimes# All rights reserved. 91539Srgrimes# 101539Srgrimes# Redistribution and use in source and binary forms, with or without 111539Srgrimes# modification, are permitted provided that the following conditions 121539Srgrimes# are met: 131539Srgrimes# 141539Srgrimes# 1. Redistributions of source code must retain the above copyright 15156960Sume# notice, this list of conditions and the following disclaimer. 16156960Sume# 171539Srgrimes# 2. Redistributions in binary form must reproduce the above copyright 181539Srgrimes# notice, this list of conditions and the following disclaimer in the 191539Srgrimes# documentation and/or other materials provided with the distribution. 20156960Sume# 211539Srgrimes# 3. Neither the name of the Institute nor the names of its contributors 221539Srgrimes# may be used to endorse or promote products derived from this software 231539Srgrimes# without specific prior written permission. 241539Srgrimes# 251539Srgrimes# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 261539Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 271539Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 281539Srgrimes# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 291539Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 301539Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 311539Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3236888Speter# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3336888Speter# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3436888Speter# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35156960Sume# SUCH DAMAGE. 36156960Sume 371539Srgrimesimport re 381539Srgrimesimport string 391539Srgrimesimport sys 4036888Speter 418858Srgrimesimport generate 42156960Sumeimport rfc3454 43156960Sumeimport rfc4518 44156960Sumeimport stringprep 45156960Sume 46156960Sumeif len(sys.argv) != 3: 47156960Sume print "usage: %s rfc3454.txt out-dir" % sys.argv[0] 48156960Sume sys.exit(1) 4936888Speter 5036888Spetertables = rfc3454.read(sys.argv[1]) 5136888Spetert2 = rfc4518.read() 523070Spst 53156960Sumefor x in t2.iterkeys(): 5450473Speter tables[x] = t2[x] 551539Srgrimes 561539Srgrimeserror_list = stringprep.get_errorlist() 571539Srgrimes 581539Srgrimeserrorlist_h = generate.Header('%s/errorlist_table.h' % sys.argv[2]) 591539Srgrimes 603070Spsterrorlist_c = generate.Implementation('%s/errorlist_table.c' % sys.argv[2]) 611539Srgrimes 623070Spsterrorlist_h.file.write( 6355163Sshin''' 643070Spst#include "windlocl.h" 65156960Sume 663070Spststruct error_entry { 671539Srgrimes uint32_t start; 6821055Speter unsigned len; 6921055Speter wind_profile_flags flags; 7021055Speter}; 713070Spst 723070Spstextern const struct error_entry _wind_errorlist_table[]; 733070Spst 743070Spstextern const size_t _wind_errorlist_table_size; 75156960Sume 763070Spst''') 773070Spst 78156960Sumeerrorlist_c.file.write( 79156960Sume''' 80156960Sume#include <stdlib.h> 81156960Sume#include "errorlist_table.h" 82156960Sume 83156960Sumeconst struct error_entry _wind_errorlist_table[] = { 84156960Sume''') 85156960Sume 86156960Sumetrans=[] 87156960Sume 88156960Sumefor t in error_list.iterkeys(): 89156960Sume for l in tables[t]: 90156960Sume m = re.search('^ *([0-9A-F]+)-([0-9A-F]+); *(.*) *$', l) 91156960Sume if m: 92156960Sume start = int(m.group(1), 0x10) 93156960Sume end = int(m.group(2), 0x10) 94156960Sume desc = m.group(3) 95156960Sume trans.append([start, end - start + 1, desc, [t]]) 96156960Sume else: 97156960Sume m = re.search('^ *([0-9A-F]+); *(.*) *$', l) 98156960Sume if m: 99156960Sume trans.append([int(m.group(1), 0x10), 1, m.group(2), [t]]) 100156960Sume 101156960Sumetrans = stringprep.sort_merge_trans(trans) 102156960Sume 1031539Srgrimesfor x in trans: 1041539Srgrimes (start, length, description, tables) = x 105156960Sume symbols = stringprep.symbols(error_list, tables) 1061539Srgrimes if len(symbols) == 0: 1071539Srgrimes print "no symbol for %s" % description 1081539Srgrimes sys.exit(1) 1093070Spst errorlist_c.file.write(" {0x%x, 0x%x, %s}, /* %s: %s */\n" 1101539Srgrimes % (start, length, symbols, ",".join(tables), description)) 1111539Srgrimes 112156960Sumeerrorlist_c.file.write( 113156960Sume'''}; 114156960Sume 115156960Sume''') 116156960Sume 117156960Sumeerrorlist_c.file.write( 118156960Sume "const size_t _wind_errorlist_table_size = %u;\n" % len(trans)) 119156960Sume 120156960Sumeerrorlist_h.close() 121156960Sumeerrorlist_c.close() 122156960Sume