trunk/src/build/makelist.py
| r0 | r243509 | |
| 1 | #!/usr/bin/python |
| 2 | |
| 3 | from __future__ import with_statement |
| 4 | |
| 5 | import sys |
| 6 | import os |
| 7 | |
| 8 | drivlist = [] |
| 9 | |
| 10 | def 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 | |
| 58 | if (len(sys.argv) < 2) : |
| 59 | print('Usage:') |
| 60 | print(' makelist <source.lst>') |
| 61 | sys.exit(0) |
| 62 | |
| 63 | if (parse_file(sys.argv[1])) : |
| 64 | sys.exit(1) |
| 65 | |
| 66 | # output a count |
| 67 | if (len(drivlist)==0) : |
| 68 | sys.stderr.write("No drivers found\n") |
| 69 | sys.exit(1) |
| 70 | |
| 71 | sys.stderr.write("%d drivers found\n" % len(drivlist)) |
| 72 | |
| 73 | # add a reference to the ___empty driver |
| 74 | drivlist.append("___empty") |
| 75 | |
| 76 | # start with a header |
| 77 | print('#include "emu.h"\n'); |
| 78 | print('#include "drivenum.h"\n'); |
| 79 | |
| 80 | #output the list of externs first |
| 81 | for drv in sorted(drivlist): |
| 82 | print("GAME_EXTERN(%s);" % drv) |
| 83 | print("") |
| 84 | |
| 85 | # then output the array |
| 86 | print("const game_driver * const driver_list::s_drivers_sorted[%d] =" % len(drivlist)) |
| 87 | print("{") |
| 88 | for drv in sorted(drivlist): |
| 89 | print("\t&GAME_NAME(%s)," % drv) |
| 90 | print("};"); |
| 91 | print(""); |
| 92 | |
| 93 | # also output a global count |
| 94 | print("int driver_list::s_driver_count = %d;\n" % len(drivlist)) |