Use pathlib to get file stem to build D interface filename. Add new DINTFOR and varia...
[scons.git] / site_scons / soe_utils.py
blobdfd605c168a42db5e3166578514dcc3e0d363907
1 import os.path
2 import re
4 from SCons.Script import Builder, Action, Scanner
6 def soelim(target, source, env):
7 """
8 Interpolate files included in [gnt]roff source files using the
9 .so directive.
11 This behaves somewhat like the soelim(1) wrapper around groff, but
12 makes us independent of whether the actual underlying implementation
13 includes an soelim() command or the corresponding command-line option
14 to groff(1). The key behavioral difference is that this doesn't
15 recursively include .so files from the include file. Not yet, anyway.
16 """
17 t = str(target[0])
18 s = str(source[0])
19 dir, f = os.path.split(s)
20 with open(t, 'w') as tfp, open(s, 'r') as sfp:
21 for line in sfp.readlines():
22 if line[:4] in ['.so ', "'so "]:
23 sofile = os.path.join(dir, line[4:-1])
24 with open(sofile, 'r') as f:
25 tfp.write(f.read())
26 else:
27 tfp.write(line)
29 def soscan(node, env, path):
30 c = node.get_text_contents()
31 return re.compile(r"^[.']so\s+(\S+)", re.M).findall(c)
33 soelimbuilder = Builder(action = Action(soelim),
34 source_scanner = Scanner(soscan))