Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / pfe / bin / sed.py
# ========== Copyright Header Begin ==========================================
#
# OpenSPARC T2 Processor File: sed.py
# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
#
# The above named program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License version 2 as published by the Free Software Foundation.
#
# The above named program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this work; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ========== Copyright Header End ============================================
#
# use baseline file to generate a target specific file.
#
# usage: sed.py base_file [key1:val1,key2:val2,...] dest_file
# replace every @-keyX-@ in base_file with valX, and store the final
# result in dest_file.
#
import os, sys
########################
##### MAIN #####
########################
if __name__ == '__main__':
if len(sys.argv) < 4:
sys.stdout.write('usage: python %s base-file [key1:val1,key2:val2,...] dest-file\n' % (sys.argv[0]))
sys.exit(1)
base_file = sys.argv[1]
opts = sys.argv[2]
dest_file = sys.argv[3]
i = opts.find('[')
if i > -1:
opts = opts[i+1:]
i = opts.rfind(']')
if i > -1:
opts = opts[:i]
options = { }
tokens = opts.split(',')
for token in tokens:
i = token.find(':')
key = token[:i]
val = token[i+1:]
if not options.has_key(key):
options[key] = val
else:
sys.stdout.write('ERROR: %s: duplicate option "%s"\n' % (sys.argv[0], key))
tmp1 = os.path.basename(dest_file) + '_tmp1'
tmp2 = os.path.basename(dest_file) + '_tmp2'
os.system('/usr/bin/cp -f %s %s' % (base_file, tmp1))
for key in options.keys():
cmd = "/usr/bin/sed 's!@-%s-@!%s!g' < %s > %s" % (key, options[key], tmp1, tmp2)
os.system(cmd)
os.system('/usr/bin/cp -f %s %s' % (tmp2, tmp1))
os.system('/usr/bin/cp -f %s %s' % (tmp1, dest_file))
os.remove(tmp1)
os.remove(tmp2)