Previous 199869 Revisions Next

r34997 Friday 13th February, 2015 at 12:47:32 UTC by Miodrag Milanović
doh (nw)
[src/build]makelist.py*

trunk/src/build/makelist.py
r0r243509
1#!/usr/bin/python
2
3from __future__ import with_statement
4
5import sys
6import os
7
8drivlist = []
9
10def parse_file(srcfile):
11    try:
12        fp = open(srcfile, 'rb')
13    except IOError:
14        print("Unable to open source file '%s'" % srcfile)
15        return 1
16    in_comment = 0
17    linenum = 0
18    for line in fp.readlines():
19        drivname = ''
20        linenum+=1
21        srcptr = 0
22        while srcptr < len(line):
23            c = line[srcptr]
24            srcptr+=1
25            if c==13 or c==10:
26                if c==13 and line[srcptr]==10:
27                    srcptr+=1
28                continue
29            if c==' ':
30                continue;
31            if in_comment==1 and c=='*' and line[srcptr]=='/' :
32                srcptr+=1
33                in_comment = 0;
34                continue
35            if (in_comment):
36                continue
37            if c=='/' and line[srcptr]=='*' :
38                srcptr+=1
39                in_comment = 1;
40                continue
41            if c=='/' and line[srcptr]=='/' :
42                break
43            drivname += c
44        drivname = drivname.strip()
45        if (len(drivname)>0):
46            if drivname[0]=='#':
47               sys.stderr.write("Importing drivers from '%s'\n" % drivname[1:])
48               parse_file(drivname[1:])
49               continue
50            if not all(((c >='a' and c<='z') or (c>='0' and c<='9') or c=='_') for c in drivname):
51               sys.stderr.write("%s:%d - Invalid character in driver \"%s\"\n" % (srcfile,  linenum,  drivname))
52               return 1
53            else:           
54               drivlist.append(drivname)
55    return 0
56
57
58if (len(sys.argv) < 2) :
59    print('Usage:')
60    print('  makelist <source.lst>')
61    sys.exit(0)
62
63if (parse_file(sys.argv[1])) :
64    sys.exit(1)
65
66# output a count
67if (len(drivlist)==0) :
68    sys.stderr.write("No drivers found\n")
69    sys.exit(1)
70
71sys.stderr.write("%d drivers found\n" % len(drivlist))
72
73# add a reference to the ___empty driver
74drivlist.append("___empty")
75
76# start with a header
77print('#include "emu.h"\n');
78print('#include "drivenum.h"\n');
79
80#output the list of externs first
81for drv in sorted(drivlist):
82   print("GAME_EXTERN(%s);" % drv)
83print("")
84
85# then output the array
86print("const game_driver * const driver_list::s_drivers_sorted[%d] =" % len(drivlist))
87print("{")
88for drv in sorted(drivlist):
89   print("\t&GAME_NAME(%s)," % drv)
90print("};");
91print("");
92
93# also output a global count
94print("int driver_list::s_driver_count = %d;\n" % len(drivlist))


Previous 199869 Revisions Next


© 1997-2024 The MAME Team