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.
14 lvo
= 5 # 1st functions has always LVO of 5
15 libtype
= "struct Library" # default
16 libvar
= "library" # default
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")
32 sys
.stderr
.write("There must be one *.conf in current directory")
35 libname
= infiles
[0].rsplit(".")
36 libname
= libname
[0].capitalize()
38 infile
= open(infiles
[0], "r")
41 parts
= splitpatt
.match(line
)
42 if parts
and parts
.group(1) == "##begin":
44 elif parts
and parts
.group(1) == "##end":
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
)
52 rettype
= res
.group(1)
53 funcname
= res
.group(2)
54 args
= res
.group(3).split(",")
55 regs
= res
.group(4).split(",")
57 if argcnt
== 1 and args
[0].strip() == "":
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
)
67 print "%sAROS_LIBFUNC_INIT" %(tab)
71 print "#ifdef __AROS__"
72 print "%sAROS_LIBFUNC_EXIT" %(tab)
77 # even empty line increase LVO