Path: blob/main/crypto/heimdal/lib/wind/generate.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 datetime37import string38import os3940class GeneratedFile :41"Represents a generated file"42def __init__(self, name) :43"Create a new GeneratedFile with name"44self.name = os.path.basename(name)45self.file = open(name, 'w')46self.file.write('/* ' + name + ' */\n')47self.file.write('/* Automatically generated at ' +48datetime.datetime.now().isoformat() +49' */\n\n')5051def close(self) :52"""End and close the file header"""53self.file.close()545556class Header(GeneratedFile) :57"Represents a generated header file"58guardTrans = string.maketrans('-.', '__')59def makeGuard(self) :60"""Return a name to be used as ifdef guard"""61return string.upper(string.translate(self.name, self.guardTrans))6263def __init__(self, name) :64"Create a new Header with name"65GeneratedFile.__init__(self, name)66self.guard = self.makeGuard()67self.file.write('#ifndef ' + self.guard + '\n')68self.file.write('#define ' + self.guard + ' 1\n')6970def close(self) :71"""End and close the file header"""72self.file.write('#endif /* ' + self.guard + ' */\n')73GeneratedFile.close(self)747576class Implementation(GeneratedFile) :77"Represents a generated implementation file"78def __init__(self, name) :79"Create a new Implementation with name"80GeneratedFile.__init__(self, name)818283