1226031Sstas#!/usr/local/bin/python 2226031Sstas# -*- coding: iso-8859-1 -*- 3226031Sstas 4226031Sstas# $Id$ 5226031Sstas 6226031Sstas# Copyright (c) 2004 Kungliga Tekniska H��gskolan 7226031Sstas# (Royal Institute of Technology, Stockholm, Sweden). 8226031Sstas# All rights reserved. 9226031Sstas# 10226031Sstas# Redistribution and use in source and binary forms, with or without 11226031Sstas# modification, are permitted provided that the following conditions 12226031Sstas# are met: 13226031Sstas# 14226031Sstas# 1. Redistributions of source code must retain the above copyright 15226031Sstas# notice, this list of conditions and the following disclaimer. 16226031Sstas# 17226031Sstas# 2. Redistributions in binary form must reproduce the above copyright 18226031Sstas# notice, this list of conditions and the following disclaimer in the 19226031Sstas# documentation and/or other materials provided with the distribution. 20226031Sstas# 21226031Sstas# 3. Neither the name of the Institute nor the names of its contributors 22226031Sstas# may be used to endorse or promote products derived from this software 23226031Sstas# without specific prior written permission. 24226031Sstas# 25226031Sstas# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 26226031Sstas# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27226031Sstas# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28226031Sstas# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 29226031Sstas# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30226031Sstas# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31226031Sstas# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32226031Sstas# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33226031Sstas# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34226031Sstas# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35226031Sstas# SUCH DAMAGE. 36226031Sstas 37226031Sstasimport re 38226031Sstasimport string 39226031Sstasimport sys 40226031Sstas 41226031Sstasimport generate 42226031Sstasimport rfc3454 43226031Sstasimport rfc4518 44226031Sstasimport stringprep 45226031Sstas 46226031Sstasif len(sys.argv) != 3: 47226031Sstas print "usage: %s rfc3454.txt out-dir" % sys.argv[0] 48226031Sstas sys.exit(1) 49226031Sstas 50226031Sstastables = rfc3454.read(sys.argv[1]) 51226031Sstast2 = rfc4518.read() 52226031Sstas 53226031Sstasfor x in t2.iterkeys(): 54226031Sstas tables[x] = t2[x] 55226031Sstas 56226031Sstaserror_list = stringprep.get_errorlist() 57226031Sstas 58226031Sstaserrorlist_h = generate.Header('%s/errorlist_table.h' % sys.argv[2]) 59226031Sstas 60226031Sstaserrorlist_c = generate.Implementation('%s/errorlist_table.c' % sys.argv[2]) 61226031Sstas 62226031Sstaserrorlist_h.file.write( 63226031Sstas''' 64226031Sstas#include "windlocl.h" 65226031Sstas 66226031Sstasstruct error_entry { 67226031Sstas uint32_t start; 68226031Sstas unsigned len; 69226031Sstas wind_profile_flags flags; 70226031Sstas}; 71226031Sstas 72226031Sstasextern const struct error_entry _wind_errorlist_table[]; 73226031Sstas 74226031Sstasextern const size_t _wind_errorlist_table_size; 75226031Sstas 76226031Sstas''') 77226031Sstas 78226031Sstaserrorlist_c.file.write( 79226031Sstas''' 80226031Sstas#include <stdlib.h> 81226031Sstas#include "errorlist_table.h" 82226031Sstas 83226031Sstasconst struct error_entry _wind_errorlist_table[] = { 84226031Sstas''') 85226031Sstas 86226031Sstastrans=[] 87226031Sstas 88226031Sstasfor t in error_list.iterkeys(): 89226031Sstas for l in tables[t]: 90226031Sstas m = re.search('^ *([0-9A-F]+)-([0-9A-F]+); *(.*) *$', l) 91226031Sstas if m: 92226031Sstas start = int(m.group(1), 0x10) 93226031Sstas end = int(m.group(2), 0x10) 94226031Sstas desc = m.group(3) 95226031Sstas trans.append([start, end - start + 1, desc, [t]]) 96226031Sstas else: 97226031Sstas m = re.search('^ *([0-9A-F]+); *(.*) *$', l) 98226031Sstas if m: 99226031Sstas trans.append([int(m.group(1), 0x10), 1, m.group(2), [t]]) 100226031Sstas 101226031Sstastrans = stringprep.sort_merge_trans(trans) 102226031Sstas 103226031Sstasfor x in trans: 104226031Sstas (start, length, description, tables) = x 105226031Sstas symbols = stringprep.symbols(error_list, tables) 106226031Sstas if len(symbols) == 0: 107226031Sstas print "no symbol for %s" % description 108226031Sstas sys.exit(1) 109226031Sstas errorlist_c.file.write(" {0x%x, 0x%x, %s}, /* %s: %s */\n" 110226031Sstas % (start, length, symbols, ",".join(tables), description)) 111226031Sstas 112226031Sstaserrorlist_c.file.write( 113226031Sstas'''}; 114226031Sstas 115226031Sstas''') 116226031Sstas 117226031Sstaserrorlist_c.file.write( 118226031Sstas "const size_t _wind_errorlist_table_size = %u;\n" % len(trans)) 119226031Sstas 120226031Sstaserrorlist_h.close() 121226031Sstaserrorlist_c.close() 122