Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / pfe / bin / sed.py
CommitLineData
920dae64
AT
1# ========== Copyright Header Begin ==========================================
2#
3# OpenSPARC T2 Processor File: sed.py
4# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6#
7# The above named program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public
9# License version 2 as published by the Free Software Foundation.
10#
11# The above named program is distributed in the hope that it will be
12# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# General Public License for more details.
15#
16# You should have received a copy of the GNU General Public
17# License along with this work; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19#
20# ========== Copyright Header End ============================================
21#
22# use baseline file to generate a target specific file.
23#
24# usage: sed.py base_file [key1:val1,key2:val2,...] dest_file
25# replace every @-keyX-@ in base_file with valX, and store the final
26# result in dest_file.
27#
28import os, sys
29
30########################
31##### MAIN #####
32########################
33if __name__ == '__main__':
34
35 if len(sys.argv) < 4:
36 sys.stdout.write('usage: python %s base-file [key1:val1,key2:val2,...] dest-file\n' % (sys.argv[0]))
37 sys.exit(1)
38
39 base_file = sys.argv[1]
40 opts = sys.argv[2]
41 dest_file = sys.argv[3]
42
43 i = opts.find('[')
44 if i > -1:
45 opts = opts[i+1:]
46 i = opts.rfind(']')
47 if i > -1:
48 opts = opts[:i]
49
50 options = { }
51 tokens = opts.split(',')
52 for token in tokens:
53 i = token.find(':')
54 key = token[:i]
55 val = token[i+1:]
56 if not options.has_key(key):
57 options[key] = val
58 else:
59 sys.stdout.write('ERROR: %s: duplicate option "%s"\n' % (sys.argv[0], key))
60
61 tmp1 = os.path.basename(dest_file) + '_tmp1'
62 tmp2 = os.path.basename(dest_file) + '_tmp2'
63 os.system('/usr/bin/cp -f %s %s' % (base_file, tmp1))
64 for key in options.keys():
65 cmd = "/usr/bin/sed 's!@-%s-@!%s!g' < %s > %s" % (key, options[key], tmp1, tmp2)
66 os.system(cmd)
67 os.system('/usr/bin/cp -f %s %s' % (tmp2, tmp1))
68
69 os.system('/usr/bin/cp -f %s %s' % (tmp1, dest_file))
70 os.remove(tmp1)
71 os.remove(tmp2)