Made check for RAM Disk's name case insensitive.
[tangerine.git] / scripts / config2c.py
blob1a89d4c16b58db02acae483329b1fd4b43b3ab33
1 #!/usr/bin/python
3 # $Id$
5 # Converts config file for shared libraries to a C file
6 # with function prototypes.
7 # A *.conf file is searched in the current directory.
8 # Result is print to STDOUT.
10 import re
11 import glob
12 import sys
14 lvo = 5 # 1st functions has always LVO of 5
15 libtype = "struct Library" # default
16 libvar = "library" # default
17 mode = ""
18 tab = " " # tabulator for identation
19 wrapped = False # set to True if you want wrapping by "#ifdef __AROS__"
21 # regex for splitting line into rettype, retval, args, regs
22 linepatt = re.compile('(.+?)\s*(\w*)\s*\((.*?)\)\s*\((.*?)\)')
24 # regex for splitting arg into rettype and argname
25 argpatt = re.compile('\s*(.*?)\s*(\w+)\s*$')
27 # regex for splitting line into two parts
28 splitpatt = re.compile('([#\w]*?)\s+(.*)\s*$')
30 infiles = glob.glob("*.conf")
31 if len(infiles) != 1:
32 sys.stderr.write("There must be one *.conf in current directory")
33 sys.exit(1)
35 libname = infiles[0].rsplit(".")
36 libname = libname[0].capitalize()
38 infile = open(infiles[0], "r")
40 for line in infile:
41 parts = splitpatt.match(line)
42 if parts and parts.group(1) == "##begin":
43 mode = parts.group(2)
44 elif parts and parts.group(1) == "##end":
45 mode = ""
46 elif mode == "config":
47 if parts and parts.group(1) == "libbasetype":
48 libtype = parts.group(2)
49 elif mode == "functionlist":
50 res = linepatt.match(line)
51 if res:
52 rettype = res.group(1)
53 funcname = res.group(2)
54 args = res.group(3).split(",")
55 regs = res.group(4).split(",")
56 argcnt = len(args)
57 if argcnt == 1 and args[0].strip() == "":
58 argcnt = 0
59 if wrapped:
60 print "#ifdef __AROS__"
61 print "AROS_LH%d(%s, %s, " %(argcnt, rettype, funcname)
62 for i in range(argcnt):
63 argres = argpatt.match(args[i])
64 print "%sAROS_LHA(%s, %s, %s)," %(tab, argres.group(1), argres.group(2), regs[i])
65 print "%s%s *, %s, %d, %s" %(tab, libtype, libvar, lvo, libname)
66 print ")\n{"
67 print "%sAROS_LIBFUNC_INIT" %(tab)
68 if wrapped:
69 print "#else"
70 print "#endif\n"
71 print "#ifdef __AROS__"
72 print "%sAROS_LIBFUNC_EXIT" %(tab)
73 if wrapped:
74 print "#endif"
75 print "}\n"
77 # even empty line increase LVO
78 lvo = lvo + 1
81 infile.close()